#include using namespace std; int main() { // 1. 入力情報取得. int N; string S; cin >> N >> S; // 2. S[i, j] = S[j + 1, j + (j + 1 - i)] を満たすものが存在するか? // 文字列S に, "00", "11", "0101", "1010" のいずれかが含まれれば, "YES", // それ以外は, "NO" と 推定. bool ans = false; S += "###"; // 番兵. for(int i = 0; i < N; i++){ string s2 = S.substr(i, 2); string s4 = S.substr(i, 4); if(s2 == "00" || s2 == "11") ans = true; if(s4 == "0101" || s4 == "1010") ans = true; // cout << s2 << " " << s4 << endl; if(ans) break; } // 3. 後処理. if(ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; }