手芸王

  • タグ:
  • タグはありません
#include <iostream>
#include <string>
using namespace std;

int check(const int n, const string str){
	if(n % 2 == 0) return -1;
	int p1 = n / 2, p2 = p1;
	for(int i = 0; i <= n / 2; ++i){
		switch(i % 3){
		case 0:
			if((str[p1] != 'b') || (str[p2] != 'b')) return -1;
			break;
		case 1:
			if((str[p1] != 'a') || (str[p2] != 'c')) return -1;
			break;
		case 2:
			if((str[p1] != 'c') || (str[p2] != 'a')) return -1;
			break;
		}
		--p1; ++p2;
	}
	return n / 2;
}

int main(){
	int n;
	string str;
	cin >> n >>str;
	cout << check(n, str) << "\n";
}