A - Alternately Editorial by en_translator

For beginners
  • If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
  • Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
  • 競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
  • C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.

As described in the Problem Statement, the answer is No if the same character occurs consecutively twice in \(S\), and Yes otherwise. A possible clear implementation would be like this: once it founds such consecutive occurrences of the same character in \(S\), immediately print No and exit the program. Note the range of the index.

Sample code (C++)

using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0;i<n-1;i++){
			cout << "No" << endl;
			return 0;
	cout << "Yes" << endl;

Sample code (Python)

for i in range(N-1):
  if S[i]==S[i+1]:

last update: