text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int ara[100 + 7];
int main() {
int n;
scanf("%d", &n);
int d;
int c = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &ara[i]);
}
bool ans(1);
if (ara[1] == 3) {
ans = 0;
}
if (ans) {
int reserve = ((ara[1] == 1) ? 2 : 1);
int won = ara[1];
for (int i = 2; i <= n; i++) {
if (reserve == ara[i]) {
ans = 0;
break;
}
if (won == ara[i]) {
reserve = ((won != 1 and reserve != 1) ? 1
: (won != 2 and reserve != 2) ? 2
: 3);
} else if (won != ara[i]) {
reserve = won;
won = ara[i];
}
}
}
if (ans) {
cout << "YES";
} else {
cout << "NO";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a = 1, b = 2;
while (n--) {
int c;
cin >> c;
if (c == a) {
b = 6 - (a + b);
} else if (c == b) {
a = 6 - (a + b);
} else {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, l, n, m = 0;
cin >> n;
long long int a[4] = {0};
for (i = 0; i < n; i++) {
cin >> l;
if (i == 0) {
if (l == 3) {
cout << "NO";
return 0;
} else
k = l;
j = 3;
a[k] = 1;
a[j] = 1;
} else {
if (l == k || l == j) {
k = l;
for (m = 1; m <= 3; m++)
if (a[m] == 0) {
j = m;
}
} else {
cout << "NO";
return 0;
}
}
a[1] = a[2] = a[3] = 0;
a[k] = 1;
a[j] = 1;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, c, x, v;
cin >> n;
a = 1;
b = 2;
c = 3;
while (n > 0) {
cin >> x;
if (x == c) {
cout << "NO";
return 0;
}
if (x == a) {
v = b;
b = c;
c = v;
}
if (x == b) {
v = a;
a = c;
c = v;
}
n--;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long N, A[100];
int main(void) {
cin >> N;
for (long long i = ((long long)0); i < ((long long)N); i++) cin >> A[i];
bool ans = true;
long long p1 = 1, p2 = 2, s = 3;
for (long long i = ((long long)0); i < ((long long)N); i++) {
if (A[i] == p1) {
swap(p2, s);
} else if (A[i] == p2) {
swap(p1, s);
} else {
ans = false;
break;
}
}
cout << (ans ? "YES" : "NO") << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
void NITRO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
const long long N = 1e+5 * 2 + 22;
const long long M = 998244353;
const long long INF = 1e+18;
void SOLVE() {
int n;
cin >> n;
int wh = 3;
while (n--) {
int num;
cin >> num;
if (num == wh) {
cout << "NO";
return;
}
if (num == 1) {
wh == 2 ? wh = 3 : wh = 2;
} else if (num == 2) {
wh == 1 ? wh = 3 : wh = 1;
} else {
wh == 2 ? wh = 1 : wh = 2;
}
}
cout << "YES";
}
int main() {
NITRO();
int t = 1;
while (t--) {
SOLVE();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, o, l, p, ans, a, b, c;
int main() {
cin >> n;
c = 3;
for (i = 1; i <= n; i++) {
cin >> a;
if (a == c) {
cout << "NO";
return 0;
}
if (a == 1 && c == 2)
c = 3;
else if (a == 1 && c == 3)
c = 2;
else if (a == 2 && c == 1)
c = 3;
else if (a == 2 && c == 3)
c = 1;
else if (a == 3 && c == 1)
c = 2;
else if (a == 3 && c == 2)
c = 1;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int a[4] = {0, 1, 1, 0};
int main() {
int n;
cin >> n;
int i, x;
for (i = 0; i < n; i++) {
cin >> x;
if (a[x]) {
for (int j = 1; j <= 3; j++) {
if (j != x) {
if (a[j]) {
a[j] = 0;
} else {
a[j] = 1;
}
}
}
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
int www;
using namespace std;
int main() {
int n, a;
cin >> n;
int pl1 = 1, pl2 = 2, win, dorsok = 3;
cin >> a;
if (a == 1) {
win = 1;
pl1 = 1, pl2 = 3;
dorsok = 2;
}
if (a == 2) {
win = 2;
pl1 = 2, pl2 = 3;
dorsok = 1;
}
if (a == 3) win = 3;
int ck = 1;
if (win == 3) ck = 0;
n--;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
if ((a != pl1 && a != pl2)) {
ck = 0;
continue;
}
if (a == 1) {
win = 1;
if (pl1 != 1 && pl2 != 1) dorsok = 1;
if (pl1 != 2 && pl2 != 2) dorsok = 2;
if (pl1 != 3 && pl2 != 3) dorsok = 3;
pl2 = dorsok;
pl1 = win;
}
if (a == 2) {
win = 2;
if (pl1 != 1 && pl2 != 1) dorsok = 1;
if (pl1 != 2 && pl2 != 2) dorsok = 2;
if (pl1 != 3 && pl2 != 3) dorsok = 3;
pl2 = dorsok;
pl1 = win;
}
if (a == 3) {
win = 3;
if (pl1 != 1 && pl2 != 1) dorsok = 1;
if (pl1 != 2 && pl2 != 2) dorsok = 2;
if (pl1 != 3 && pl2 != 3) dorsok = 3;
pl2 = dorsok;
pl1 = win;
}
}
if (ck)
printf("YES\n");
else
printf("NO\n");
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
int c = 1;
pair<int, char> ch;
cin >> n;
int flag = 0;
ch = make_pair(1, 2);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (ch.first == 1 && ch.second == 2 || ch.first == 2 && ch.second == 1) {
if (x == 1) {
ch = make_pair(1, 3);
} else if (x == 2) {
ch = make_pair(2, 3);
} else {
cout << "NO";
c = 0;
break;
}
} else if (ch.first == 1 && ch.second == 3 ||
ch.first == 3 && ch.second == 1) {
if (x == 1) {
ch = make_pair(1, 2);
} else if (x == 3) {
ch = make_pair(3, 2);
} else {
cout << "NO";
c = 0;
break;
}
} else if (ch.first == 2 && ch.second == 3 ||
ch.first == 3 && ch.second == 2) {
if (x == 2) {
ch = make_pair(1, 2);
} else if (x == 3) {
ch = make_pair(3, 1);
} else {
cout << "NO";
c = 0;
break;
}
}
flag = 1;
}
if (flag == 1 && c == 1) {
cout << "YES";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int p1 = 1, p2 = 2, spec = 3;
while (n--) {
int x;
cin >> x;
if (x == spec) {
cout << "NO";
return 0;
}
if (p1 != x)
p2 = spec, spec = p1, p1 = x;
else
p1 = spec, spec = p2, p2 = x;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s = 3;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a == s) {
cout << "NO" << endl;
return 0;
}
s = 6 - a - s;
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t1, t2;
int n;
cin >> n;
t1 = 1;
t2 = 2;
int bra = 3;
int a;
for (int i = 0; i < n; ++i) {
cin >> a;
if (a != t1 && a != t2) {
cout << "NO" << endl;
return 0;
}
if (a == t1)
swap(t2, bra);
else
swap(t1, bra);
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
int main(void) {
int n;
scanf("%d", &n);
int p1 = 1, p2 = 2, s = 3;
bool isit = true;
for (int i = 0; i != n; i++) {
int x;
scanf("%d", &x);
if (x == p1) {
int tmp = p2;
p2 = s;
s = tmp;
} else if (x == p2) {
int tmp = p1;
p1 = s;
s = tmp;
} else {
isit = false;
}
}
if (isit)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 555;
void solve(int TC) {
int n;
cin >> n;
int x = 1, y = 2, z = 3;
while (n--) {
int k;
cin >> k;
if (k == x) {
swap(y, z);
} else if (k == y) {
swap(x, z);
} else {
cout << "NO";
return;
}
}
cout << "YES";
}
int main() {
startTime = clock();
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
bool llololcal = false;
int TC = 1;
for (int test = 1; test <= TC; test++) {
42;
solve(test);
}
if (llololcal)
cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i = 0, n = 0;
cin >> n;
cin >> i;
int a[3] = {1, 2, 3};
if (i == a[2]) {
cout << "NO";
return 0;
}
if (a[0] == i) {
swap(a[1], a[2]);
} else {
swap(a[0], a[2]);
}
n--;
while (n) {
cin >> i;
if (i == a[2]) {
cout << "NO";
return 0;
}
if (a[0] == i) {
swap(a[1], a[2]);
} else {
swap(a[0], a[2]);
}
n--;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void chess(int *p1, int *p2, int *sp, int sol) {
int tem;
if (sol == *p1) {
tem = *p2;
*p2 = *sp;
*sp = tem;
} else {
tem = *p1;
*p1 = *sp;
*sp = tem;
}
}
int main() {
int n, i = 0, p1 = 1, p2 = 2, sp = 3, a[100];
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] == 3) {
cout << "NO";
return 0;
}
i = 0;
while (i < n) {
chess(&p1, &p2, &sp, a[i]);
i++;
if (a[i] == sp) {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, x, a = 1, b = 2, c = 3;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == a)
swap(b, c);
else if (x == b)
swap(a, c);
else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c;
cin >> n;
int x = 1;
int y = 2;
int z = 3;
bool res = true;
for (int i = 0; i < n; i++) {
int q;
cin >> q;
if (q != x && q != y)
res = false;
else if (q == x)
swap(y, z);
else
swap(x, z);
}
(res) ? cout << "YES" : cout << "NO";
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 1, b = 2, v = 3, n, pr, p;
int p1 = a, p2 = b, na = v;
bool t = true;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p;
if (p == na) {
t = false;
break;
} else {
if (p == p1) {
p1 = p;
pr = p2;
p2 = na;
na = pr;
} else {
p2 = p;
pr = p1;
p1 = na;
na = pr;
}
}
}
if (t == true)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int t, n;
int a[maxn], b[maxn];
int gd[2005][2005];
int main() {
int cnt = 0;
scanf("%d", &n);
int a = 1, b = 2, c = 3, x, f = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (f == 1) continue;
if (a == x)
swap(b, c);
else if (b == x)
swap(a, c);
else
f = 1;
}
if (f == 0)
puts("YES");
else
puts("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> results(N);
for (int i = 0; i < N; i++) {
cin >> results[i];
}
int spec = 3;
int canWork = true;
for (int i = 0; i < N; i++) {
if (results[i] == spec) {
canWork = false;
} else {
spec = 6 - spec - results[i];
}
}
if (canWork) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int update(long long int x, long long int y) {
if (x + y == 3)
return 3;
else if (x + y == 5)
return 1;
else
return 2;
}
void func() {
long long int n, spec = 3;
cin >> n;
for (long long int i = 0; i < n; i++) {
long long int x;
cin >> x;
if (spec == x) {
cout << "NO";
return;
}
spec = update(x, spec);
}
cout << "YES";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
t = 1;
while (t--) {
func();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
cin >> n;
int log[n];
for (i = 0; i < n; i++) cin >> log[i];
int w, l, s, p[2];
i = 0;
p[0] = 1;
p[1] = 2;
w = log[0];
if (w != 1 && w != 2) {
cout << "NO";
return 0;
}
l = p[0] + p[1] - w;
s = 6 - w - l;
i++;
while (i < n) {
p[0] = w;
p[1] = s;
if (log[i] == w || log[i] == s) {
l = p[0] + p[1] - log[i];
w = log[i];
s = 6 - l - w;
} else {
cout << "NO";
return 0;
}
i++;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using lll = long long;
int main() {
int n = 0;
int mas[101];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> mas[i];
}
int sled = mas[2];
int ig = 0;
{
int nach = n;
int a = 1, b = 2, c = 3;
for (int i = 1; i <= n; i++)
if (mas[i] == a)
swap(b, c);
else if (mas[i] == b)
swap(a, c);
else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a = 1, b = 2, c = 3;
int flag = 1;
while (n--) {
int i;
cin >> i;
if (i != a && i != b) {
cout << "NO" << endl;
return 0;
}
if (i == a) {
int temp = c;
c = b;
b = temp;
}
if (i == b) {
int temp = c;
c = a;
a = temp;
}
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
istream &in = cin;
int n;
bool flag = true;
in >> n;
int p[3] = {1, 2, 3};
int tmp;
for (int i = 0; i < n; ++i) {
in >> tmp;
if (tmp == p[0]) {
swap(p[1], p[2]);
} else if (tmp == p[1]) {
swap(p[0], p[2]);
} else {
flag = false;
break;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
cin >> n;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 1000000007, BIG = 0x3f3f3f3f;
int ct = 0;
int n, a[N];
bool Read() {
cin >> n;
if (cin.eof()) return 0;
for (int i = 0; i < n; i++) cin >> a[i];
return 1;
}
int Next(int winner, int spec) {
set<int> S = {1, 2, 3};
S.erase(winner);
S.erase(spec);
int loser = *S.begin();
return loser;
}
void Process() {
int s = 3;
for (int i = 0; i < n; i++) {
if (a[i] == s) {
cout << "NO\n";
return;
} else
s = Next(a[i], s);
}
cout << "YES\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while (Read()) Process();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a = 1, b = 2, c = 3, n, w;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> w;
if (w == a) {
swap(b, c);
continue;
}
if (w == b) {
swap(a, c);
continue;
}
cout << "NO";
return 0;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > players;
int main() {
int n, w;
cin >> n;
pair<int, int> p = make_pair(1, 2);
players.push_back(p);
for (int i = 0; i < n; i++) {
cin >> w;
if (w != players[i].first && w != players[i].second) {
cout << "NO" << endl;
break;
} else {
for (int j = 1; j < 4; j++) {
if (j != players[i].first && j != players[i].second) {
int s = j;
pair<int, int> pp = make_pair(j, w);
players.push_back(pp);
}
}
}
if (i == n - 1) {
cout << "YES" << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int main() {
int n;
cin >> n;
int a = 1, b = 2, c = 3;
bool ok = 1;
while (n--) {
int x;
cin >> x;
if (x != a && x != b) ok = 0;
if (x == a) swap(b, c);
if (x == b) swap(a, c);
}
if (ok)
cout << "YES";
else
cout << "NO";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
bool flag = 1;
int forbidden = 3;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x == forbidden) flag = 0;
int soso = 1;
while (soso == x || soso == forbidden) ++soso;
forbidden = soso;
}
if (flag)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, e, b = 1, c = 1, d = 0, f = 0;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> e;
if (e == 1 && b == 1) {
if (c == 1) {
d = 1;
c = 0;
continue;
}
if (d == 1) {
d = 0;
c = 1;
continue;
}
}
if (e == 1 && b == 0) f = 1;
if (e == 2 && c == 1) {
if (b == 1) {
b = 0;
d = 1;
continue;
}
if (d == 1) {
d = 0;
b = 1;
continue;
}
}
if (e == 2 && c == 0) f = 1;
if (e == 3 && d == 1) {
if (b == 1) {
b = 0;
c = 1;
continue;
}
if (c == 1) {
c = 0;
b = 1;
continue;
}
}
if (e == 3 && d == 0) f = 1;
}
if (f == 1) {
cout << "NO";
return 0;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int f(int a, int v, int b) {
if (a == v) {
return b;
} else {
return a;
}
}
int main() {
int n, a = 1, b = 2, c = 3, v, t;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v;
if (v == c) {
cout << "NO";
return 0;
}
t = f(a, v, b);
b = c;
a = v;
c = t;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N;
int main(void) {
while (scanf("%d", &N) != EOF) {
int p1, p2, s;
p1 = 1;
p2 = 2;
s = 3;
int winner;
bool right = true;
for (int i = 0; i < N; i++) {
scanf("%d", &winner);
if (right) {
if (winner != s) {
if (winner == p1) {
int temp = p2;
p2 = s;
s = temp;
} else {
int temp = p1;
p1 = s;
s = temp;
}
} else {
right = false;
}
}
}
if (right) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const long long linf = 1e18;
const int MAXN = 1e2 + 10;
const int MAXM = 4e5 + 10;
const double E = 2.718281828;
const double pi = acos(-1.0);
int a[MAXN], player[3];
int main() {
int n;
scanf("%d", &n);
bool flag = 1;
player[0] = 1;
player[1] = 2;
player[2] = 3;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
if (i == 0 && a[i] == 3) flag = 0;
if (i == 0) {
if (player[0] == a[i]) {
swap(player[1], player[2]);
} else
swap(player[0], player[2]);
} else {
if (a[i] == player[2]) {
flag = 0;
} else {
if (player[0] == a[i]) {
swap(player[1], player[2]);
} else
swap(player[0], player[2]);
}
}
}
puts(flag ? "YES" : "NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int tmp = 3;
int x = 1, y = 2;
int n;
cin >> n;
bool flag = true;
for (int i = 1; i <= n; i++) {
int q;
cin >> q;
if (q == tmp) {
flag = false;
}
if (q == x)
swap(tmp, y);
else
swap(tmp, x);
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, a, b, spec;
spec = 3;
a = 1;
b = 2;
scanf("%d", &n);
bool ans = true;
while (n--) {
scanf("%d", &i);
if (i == spec) {
ans = false;
}
if (i == a) {
j = spec;
spec = b;
b = j;
} else {
j = spec;
spec = a;
a = j;
}
}
if (ans) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int A[100005];
int n;
int c[5];
int main() {
scanf("%d", &n);
memset(c, 0, sizeof c);
c[3] = 1;
bool chk = true;
for (int i = 1; i <= n; i++) {
scanf("%d", &A[i]);
if (c[A[i]]) {
chk = false;
}
int tmp1, tmp2;
tmp1 = A[i];
for (int j = 1; j <= 3; j++)
if (c[j]) tmp2 = j;
memset(c, 0, sizeof c);
for (int j = 1; j <= 3; j++)
if (j != tmp1 && j != tmp2) c[j] = true;
}
if (chk) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dop(int i1, int i2) {
for (int i = 1; i <= 3; i++)
if ((i != i1) && (i != i2)) return i;
return 0;
}
int main() {
int n, A[100];
int i;
cin >> n;
for (i = 1; i <= n; i++) cin >> A[i - 1];
int i1 = 1;
int i2 = 2;
for (i = 1; i <= n; i++) {
int k = A[i - 1];
if (k == i1)
i2 = dop(i1, i2);
else if (k == i2)
i1 = dop(i1, i2);
else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int nQ;
bool inPlay[3] = {true, true, false};
int sp = 2, tmp;
bool bisa = true;
scanf("%d", &nQ);
while (nQ--) {
scanf("%d", &tmp);
tmp--;
if (tmp == sp) {
bisa = false;
break;
}
for (int i = 0; i < 3; i++) {
inPlay[i] = false;
}
inPlay[tmp] = true;
inPlay[sp] = true;
for (int i = 0; i < 3; i++) {
if (inPlay[i] == false) {
sp = i;
}
}
}
if (bisa) {
printf("YES\n");
} else {
printf("NO\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a = 1, b = 2, s = 3;
int k;
for (int i = 0; i < n; i++) {
cin >> k;
if (k == s) {
cout << "NO" << endl;
return 0;
}
if (k == a) {
swap(b, s);
} else {
swap(a, s);
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' || c < '0') && c != '-')
;
for ((c == '-' ? sg = 1, c = getchar() : 0), first = 0; c >= '0' && c <= '9';
c = getchar())
first = (first << 1) + (first << 3) + c - '0';
if (sg) first = -first;
}
template <class T, class T1>
inline void gn(T &first, T1 &second) {
gn(first);
gn(second);
}
template <class T, class T1, class T2>
inline void gn(T &first, T1 &second, T2 &z) {
gn(first);
gn(second);
gn(z);
}
template <class T>
inline void print(T first) {
if (first < 0) {
putchar('-');
return print(-first);
}
if (first < 10) {
putchar('0' + first);
return;
}
print(first / 10);
putchar(first % 10 + '0');
}
template <class T>
inline void printsp(T first) {
print(first);
putchar(' ');
}
template <class T>
inline void println(T first) {
print(first);
putchar('\n');
}
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1) ans = 1LL * ans * a % m;
return ans;
}
int main() {
int n, u;
int a, b, c;
cin >> n;
a = 1, b = 2, c = 3;
for (int i = 0; i < n; i++) {
gn(u);
if (u == a) {
u = b;
b = c;
c = u;
continue;
}
if (u == b) {
u = a;
a = c;
c = u;
continue;
}
puts("NO");
return 0;
}
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, player1, player2, watcher = 3;
cin >> n;
int *a = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[0] == 3) {
cout << "NO";
return 0;
}
if (i != 0) {
player1 = a[i - 1];
player2 = watcher;
watcher = 6 - player1 - player2;
if (watcher == a[i]) {
cout << "NO";
return 0;
}
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, v, sp;
bool ill;
scanf("%d", &n);
ill = false;
for (sp = 3; n--;) {
scanf("%d", &v);
if (v == sp) {
ill = true;
break;
}
sp = 6 - sp - v;
}
if (ill)
printf("NO\n");
else
printf("YES\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if ((ll)(name).size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
void solve() {
ll n;
cin >> n;
ll spec[4] = {0};
spec[3] = 1;
for (ll i = 0; i < n; i++) {
ll winner;
cin >> winner;
if (spec[winner]) {
cout << "NO\n";
return;
}
ll other = -1, sp = -1;
for (ll p = 1; p <= 3; p++) {
if (p != winner && !spec[p]) {
other = p;
}
if (p != winner && spec[p]) {
sp = p;
}
}
if (other == -1 || sp == -1) {
cout << "NO\n";
return;
}
spec[other] = 1;
spec[sp] = 0;
}
cout << "YES\n";
}
signed main() {
setIO();
ll t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
bool game[4];
scanf("%d", &N);
int aux;
game[1] = true;
game[2] = true;
game[3] = false;
for (int i = 0; i < N; i++) {
scanf("%d", &aux);
if (!game[aux]) {
printf("NO\n");
return 0;
} else {
game[1] = !game[1];
game[2] = !game[2];
game[3] = !game[3];
game[aux] = true;
}
}
printf("YES\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d", &N);
int player1 = 1;
int player2 = 2;
int spec = 3;
while (N--) {
int w;
scanf("%d", &w);
if (w != player1 && w != player2) {
printf("NO\n");
return 0;
}
if (w == player1) {
swap(player2, spec);
} else {
swap(player1, spec);
}
}
printf("YES\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, a1 = 1, a2 = 2;
scanf("%d", &n);
int a[3] = {1, 2, 3};
for (i = 0; i < n; i++) {
int bil;
scanf("%d", &bil);
if (bil == a1 || bil == a2) {
int yangBelum;
for (j = 0; j < 3; j++) {
if (a[j] != a1 && a[j] != a2) {
yangBelum = a[j];
break;
}
}
if (bil == a1) {
a2 = yangBelum;
} else {
a1 = yangBelum;
}
} else {
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
};
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int sp = 3, x, flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
if (x == sp) {
flag = 1;
}
sp = 6 - (x + sp);
}
printf("%s", flag ? "NO\n" : "YES\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int input() {
int32_t x;
scanf("%d", &x);
return x;
}
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int32_t main() {
int n = in();
int preLooser = -1;
int playing[2] = {1, 2};
for (int i = 0; i < n; i++) {
int winner = in();
if (winner == preLooser || (winner != playing[0] && winner != playing[1]))
return cout << "NO" << endl, 0;
int newPlayer = 1 ^ 2 ^ 3 ^ playing[0] ^ playing[1];
if (winner == playing[0]) {
preLooser = playing[1];
playing[1] = newPlayer;
} else
preLooser = playing[0], playing[0] = newPlayer;
}
cout << "YES\n";
}
|
#include <bits/stdc++.h>
using namespace std;
long long unsigned int countDivisors(long long unsigned int n) {
long long unsigned int cnt = 0;
for (long long unsigned int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i)
++cnt;
else
cnt += 2;
}
}
return cnt;
}
int findFirst(const std::vector<int> &array, int key, int low, int high) {
int ans = -1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (key == array[mid]) {
ans = mid;
high = mid - 1;
} else if (key > array[mid])
low = mid + 1;
else
high = mid - 1;
}
return ans;
}
int findLast(const std::vector<int> &array, int key, int low, int high) {
int ans = -1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (key == array[mid]) {
ans = mid;
low = mid + 1;
} else if (key > array[mid])
low = mid + 1;
else
high = mid - 1;
}
return ans;
}
int d, x, y;
void extendedEuclid(int a, int b) {
if (b == 0) {
d = 1;
x = 1;
y = 0;
} else {
extendedEuclid(b, a % b);
int temp = x;
x = y;
y = temp - (a / b) * y;
}
}
long long unsigned int ModPow(int x, long long unsigned int y, int p) {
long long unsigned int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int a, b, s, n;
a = 1;
b = 2;
s = 3;
cin >> n;
vector<int> arr(n);
for (int i1 = 0; i1 < n; i1++) cin >> arr[i1];
for (int i = 0; i < n; i++) {
if (arr[i] == a) {
swap(s, b);
} else if (arr[i] == b) {
swap(s, a);
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void re_curse() {
long long int n;
cin >> n;
vector<long long int> arr(n);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
long long int o = 3;
if (arr[0] == o) {
cout << "NO" << endl;
return;
}
for (int i = 0; i < n - 1; ++i) {
if (arr[i + 1] == 6 - (arr[i] + o)) {
cout << "NO" << endl;
return;
}
o = 6 - (arr[i] + o);
}
cout << "YES" << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
for (int i = 1; i <= t; ++i) {
re_curse();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int mod = 1e9 + 7;
int main() {
int n;
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int y = 3;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x == y) return cout << "NO", 0;
y ^= x;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1010];
int main() {
cin >> n;
for (int i = 0; i != n; ++i) cin >> a[i];
int l = 1, r = 2, flag = 0;
for (int i = 0; i != n; ++i) {
if (flag) break;
if (a[i] != l && a[i] != r)
flag = 1;
else
for (int j = 1; j <= 3; ++j) {
if (j != l && j != r) {
if (a[i] == l)
r = j;
else
l = j;
break;
}
}
}
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, c = 3;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == c) {
cout << "NO";
return 0;
}
c = 6 - c - x;
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, x;
int main() {
int loser = 0;
cin >> n;
cin >> x;
if (x == 1)
loser = 2;
else if (x == 2)
loser = 1;
else {
cout << "NO\n";
return 0;
}
for (int i = 1; i < n; i++) {
cin >> x;
if (x == loser) {
cout << "NO\n";
return 0;
}
if ((loser == 1 && x == 2) || (loser == 2 && x == 1))
loser = 3;
else if ((loser == 1 && x == 3) || (loser == 3 && x == 1))
loser = 2;
else if ((loser == 2 && x == 3) || (loser == 3 && x == 2))
loser = 1;
}
cout << "YES\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
bool f = true;
scanf("%lld", &n);
long long p1 = 1, p2 = 2, s = 3;
while (n--) {
long long w;
scanf("%lld", &w);
if (w == s) {
f = false;
} else if (w == p1) {
long long temp = p2;
p2 = s;
s = temp;
} else {
long long temp = p1;
p1 = s;
s = temp;
}
}
if (f)
printf("YES");
else
printf("NO");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
int main() {
int n;
cin >> n;
vector<int> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i];
}
int p1, p2, wat;
p1 = 1;
p2 = 2;
wat = 3;
bool c = true;
for (int i = 0; i < n; i++) {
if (w[i] != p1 && w[i] != p2) {
c = false;
}
if (p1 == w[i]) {
swap(p2, wat);
}
if (p2 == w[i]) {
swap(p1, wat);
}
}
if (c == true) {
cout << "YES";
} else {
cout << "NO";
}
}
|
#include <bits/stdc++.h>
using namespace std;
void switch_players(int *players, int winner) {
if (winner == 0) {
if (players[1] == 0) {
players[1] = 1;
players[2] = 0;
} else {
players[1] = 0;
players[2] = 1;
}
} else if (winner == 1) {
if (players[0] == 0) {
players[0] = 1;
players[2] = 0;
} else {
players[0] = 0;
players[2] = 1;
}
} else if (winner == 2) {
if (players[0] == 0) {
players[0] = 1;
players[1] = 0;
} else {
players[0] = 0;
players[1] = 1;
}
}
}
int main() {
int games, cur, players[3] = {1, 1, 0}, error = false;
cin >> games;
for (int i = 0; i < games; i++) {
cin >> cur;
if (players[cur - 1] != 0) {
switch_players(players, cur - 1);
} else {
error = true;
}
}
(error == true ? cout << "NO" : cout << "YES");
}
|
#include <bits/stdc++.h>
using namespace std;
bool solve(long long int n) {
long long int s1 = 1, s2 = 1, s3 = 0, x;
vector<long long int> v;
for (long long int i = 0; i < n; i++) {
cin >> x, v.push_back(x);
}
long long int i = 0;
while (i < n) {
x = v[i];
i++;
if (s1 == 0 && x == 1) return false;
if (s2 == 0 && x == 2) return false;
if (s3 == 0 && x == 3) return false;
if (s1 == 1 && s2 == 1) {
if (x == 1)
s2 = 0, s3 = 1;
else {
s1 = 0;
s3 = 1;
}
} else if (s2 == 1 && s3 == 1) {
if (x == 2)
s3 = 0, s1 = 1;
else {
s1 = 1;
s2 = 0;
}
} else {
if (x == 3)
s1 = 0, s2 = 1;
else {
s2 = 1;
s3 = 0;
}
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
if (solve(n))
cout << "YES\n";
else {
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int x;
int a = 1, b = 2, c = 3;
bool valid = true;
for (int i = 0; i < n; ++i) {
cin >> x;
if (x == c)
valid = false;
else {
a = x;
b = c;
c = 6 - (a + b);
}
}
if (valid)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
}
|
#include <bits/stdc++.h>
long power(long int x, long int y) {
int temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
using namespace std;
int main() {
bool arr[5] = {false, true, true, false};
int n, i, j, k = 1;
scanf("%d", &(n));
int rs[n + 3];
for (i = 0; i < n; i++) scanf("%d", &(rs[i]));
for (i = 0; i < n; i++) {
if (arr[rs[i]] == false) {
cout << "NO" << endl;
return 0;
} else {
if (rs[i] == 1)
swap(arr[2], arr[3]);
else if (rs[i] == 2)
swap(arr[1], arr[3]);
else if (rs[i] == 3)
swap(arr[1], arr[2]);
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++) cin >> arr[i];
pair<int, int>* result = new pair<int, int>[n];
result[0].first = arr[0];
if (arr[0] == 1) {
result[0].second = 2;
} else {
result[0].second = 1;
}
if (arr[0] == 3) {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i < n; i++) {
if (i == 1) {
if (arr[i] == result[i - 1].second) {
cout << "NO" << endl;
return 0;
}
result[i].first = arr[i];
if (arr[i] == result[i - 1].first) {
result[i].second = 3;
} else {
result[i].second = result[i - 1].first;
}
} else {
if (arr[i] == result[i - 1].second) {
cout << "NO" << endl;
return 0;
}
result[i].first = arr[i];
if (arr[i] == result[i - 1].first) {
result[i].second = result[i - 2].second;
} else {
result[i].second = result[i - 1].first;
}
}
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d = 1, k, m = 0, y, a = 1, b = 2, c = 3;
string s;
cin >> n;
int aa[n];
for (int i = 0; i < n; i++) cin >> aa[i];
for (int i = 0; i < n; i++) {
if (aa[i] == c) {
cout << "NO" << endl;
return 0;
}
if (aa[i] == a)
swap(b, c);
else
swap(a, c);
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int c1 = 1, c2 = 2, s = 3;
bool ans = true;
for (int i = 1; i <= n; i++) {
int w;
scanf("%d", &w);
if (w != c1 && w != c2) {
ans = false;
break;
} else if (w == c1)
swap(s, c2);
else if (w == c2)
swap(s, c1);
}
if (ans)
printf("YES");
else
printf("NO");
}
|
#include <bits/stdc++.h>
using namespace std;
int get(int a, int b) {
if (a > b) swap(a, b);
if (a == 2) return 1;
if (b == 3) return 2;
return 3;
}
int main() {
int n;
cin >> n;
int a = 1, b = 2, c;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
if (a == t || b == t) {
a = get(a, b);
b = t;
} else {
cout << "NO" << '\n';
return 0;
}
}
cout << "YES" << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int fun(int a, int bb) {
if (a == 1 && bb == 2 || a == 2 && bb == 1) return 3;
if (a == 1 && bb == 3 || a == 3 && bb == 1) return 2;
if (a == 3 && bb == 2 || a == 2 && bb == 3) return 1;
}
int main() {
int n;
cin >> n;
int P1 = 1, P2 = 2;
int tt;
bool flag = true;
for (int i = 0; i < n; i++) {
cin >> tt;
if (P1 == tt || P2 == tt) {
if (P1 == tt) {
P2 = fun(P1, P2);
} else {
P1 = fun(P1, P2);
}
} else {
flag = false;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int no(int x, int y) {
for (int i = 1; i <= 3; i++) {
if (i != x && i != y) return i;
}
}
int main() {
int n;
cin >> n;
int a;
int x = 1, y = 2;
bool ok = 1;
while (n--) {
cin >> a;
if (x != a && y != a) {
ok = 0;
}
if (x == a)
y = no(x, y);
else
x = no(x, y);
}
if (ok)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[109], sol = 1;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int winner, loser, spect;
for (int i = 0; i < n; i++) {
if (i == 0) {
winner = a[i];
if (winner == 1) {
loser = 2;
spect = 3;
} else if (winner == 2) {
loser = 1;
spect = 3;
} else {
sol = 0;
break;
}
continue;
}
if (a[i] == loser) {
sol = 0;
break;
}
if (spect == a[i])
loser = winner;
else
loser = spect;
winner = a[i];
if (winner != 1 && loser != 1) spect = 1;
if (winner != 2 && loser != 2) spect = 2;
if (winner != 3 && loser != 3) spect = 3;
}
if (sol == 0)
cout << "NO";
else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int p[2] = {1, 2};
int other = 3;
int won, aux;
bool no = false;
for (int i = 0; i < n; ++i) {
cin >> won;
if (no) continue;
if (won == other) {
no = true;
continue;
}
int idx = 1;
if (won != p[0]) idx = 0;
aux = other;
other = p[idx];
p[idx] = aux;
}
if (no)
cout << "NO";
else
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void JIZZ() {
cout << "";
exit(0);
}
const long double PI = 3.14159265358979323846264338327950288;
const long double eps = 1e-13;
const long long mod = 1e9 + 7;
int main() {
int n;
cin >> n;
int sp = 3;
while (n--) {
int t;
cin >> t;
if (t == sp) return cout << "NO" << endl, 0;
set<int> s;
s.insert(t);
s.insert(sp);
if (s.find(1) == s.end()) sp = 1;
if (s.find(2) == s.end()) sp = 2;
if (s.find(3) == s.end()) sp = 3;
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
const double pi = acos(-1);
const long long mod = 1e9 + 7;
const int N = 2e5 + 5, M = 505;
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n];
int p1 = 1, p2 = 2, sp = 3;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool yes = 1;
for (int i = 0; i < n; i++) {
if (a[i] != p1 && a[i] != p2) {
yes = 0;
break;
}
if (a[i] == 1) {
if (p1 != 1) {
swap(p1, sp);
} else if (p2 != 1) {
swap(p2, sp);
}
} else if (a[i] == 2) {
if (p1 != 2) {
swap(p1, sp);
} else if (p2 != 2) {
swap(p2, sp);
}
} else if (a[i] == 3) {
if (p1 != 3) {
swap(p1, sp);
} else if (p2 != 3) {
swap(p2, sp);
}
}
}
if (yes)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void setprime(bool isprime[], long long n);
long long BinarySearch(long long arr[], long long first, long long last,
long long search);
long long choose(long long n, long long k);
void showArray(long long a[], long long n);
long long gcd(long long a, long long b);
long double len(long double x1, long double y1, long double x2, long double y2);
long double gcd_ld(long double x, long double y);
long long power(long long x, long long n);
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cout << fixed;
cout << setprecision(6);
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
if (a[0] == 3) {
cout << "NO";
return 0;
}
long long cp1 = 1, cp2 = 2, sp = 3;
for (long long i = 0; i < n; i++) {
if (a[i] == cp1 || a[i] == cp2) {
if (a[i] == cp1) {
long long tmp = sp;
sp = cp2;
cp2 = tmp;
} else {
long long tmp = sp;
sp = cp1;
cp1 = tmp;
}
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
void setprime(bool isprime[], long long n) {
for (long long i = 0; i < n; i++) isprime[i] = true;
isprime[0] = false;
isprime[1] = false;
for (long long i = 2; i < n; i++) {
for (long long j = 2; i * j < n; j++) isprime[i * j] = false;
}
}
long long BinarySearch(long long arr[], long long first, long long last,
long long search) {
long long middle = (first + last) / 2;
while (first <= last) {
if (arr[middle] < search) {
first = middle + 1;
} else if (arr[middle] == search) {
return middle;
} else {
last = middle - 1;
}
middle = (first + last) / 2;
}
if (first > last) {
return -1;
}
}
long long choose(long long n, long long k) {
if (k == 0) return 1;
return (n * choose(n - 1, k - 1)) / k;
}
void showArray(long long a[], long long n) {
for (long long i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << endl;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long double len(long double x1, long double y1, long double x2,
long double y2) {
return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));
}
long double gcd_ld(long double x, long double y) {
long double eps = 0.0001;
while (fabs(x) > eps && fabs(y) > eps) {
if (x > y)
x -= floor(x / y) * y;
else
y -= floor(y / x) * x;
}
return x + y;
}
long long power(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return power(x * x, n / 2);
else
return x * power(x * x, (n - 1) / 2);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
cin >> n;
long long l = 1, r = 2, left = 3;
long long ab;
for (i = 0; i < n; i++) {
cin >> ab;
if (ab == l) {
l = ab;
long long temp;
temp = r;
r = left;
left = temp;
} else if (ab == r) {
r = ab;
long long temp;
temp = l;
l = left;
left = temp;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a = 1, b = 2, c = 3;
vector<int> w;
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
w.push_back(x);
}
if (w[0] == 1) {
a = 1;
b = c;
c = 2;
} else if (w[0] == 2) {
a = 2;
b = c;
c = 1;
} else {
cout << "NO";
return 0;
}
for (int i = 1; i < n; i++) {
if (w[i] != a && w[i] != b) {
cout << "NO";
return 0;
} else {
a = w[i];
b = c;
if (a == 1 && b == 2) {
c = 3;
} else if (a == 2 && b == 1) {
c = 3;
} else if (a == 3 && b == 2) {
c = 1;
} else if (a == 2 && b == 3) {
c = 1;
} else {
c = 2;
}
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int w;
int s = 3;
int p1 = 1, p2 = 2;
int l;
bool flag = true;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w;
if (w == p1) {
l = p2;
p1 = w;
p2 = s;
s = l;
} else if (w == p2) {
l = p1;
p1 = w;
p2 = s;
s = l;
} else {
flag = false;
}
}
if (flag == true) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
inline void gn(long long &first) {
int sg = 1;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
c == '-' ? (sg = -1, first = 0) : (first = c - '0');
while ((c = getchar()) >= '0' && c <= '9') first = first * 10 + c - '0';
first *= sg;
}
inline void gn(int &first) {
long long t;
gn(t);
first = t;
}
inline void gn(unsigned long long &first) {
long long t;
gn(t);
first = t;
}
inline void gn(double &first) {
double t;
scanf("%lf", &t);
first = t;
}
inline void gn(long double &first) {
double t;
scanf("%lf", &t);
first = t;
}
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1) ans = 1LL * ans * a % m;
return ans;
}
int p[110];
int main() {
int n, a = 1, b = 2, c = 3;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", p + i);
for (int i = 0; i < n; i++) {
if (p[i] == a) {
swap(b, c);
continue;
}
if (p[i] == b) {
swap(a, c);
continue;
}
puts("NO");
return 0;
}
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y);
long long gcd(long long a, long long b);
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long cp1 = 1, cp2 = 2, cs = 3, f = 0;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
if (a == cp1) {
swap(cp2, cs);
} else if (a == cp2) {
swap(cp1, cs);
} else
f = 1;
}
if (f == 1)
cout << "NO\n";
else
cout << "YES\n";
}
long long power(long long x, long long y) {
long long res = 1;
x %= 998244353;
while (y > 0) {
if (y & 1) res = (res * x) % 998244353;
y = y >> 1;
x = (x * x) % 998244353;
}
return res % 998244353;
}
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n;
cin >> n;
vector<long long> a(n);
vector<long long> sl(n + 1);
for (long long i = 0; i < n; ++i) cin >> a[i];
sl[0] = 3;
for (long long i = 0; i < n; ++i) {
if (a[i] == sl[i]) {
cout << "NO";
return 0;
} else {
set<long long> s;
s.insert(1);
s.insert(2);
s.insert(3);
s.erase(a[i]);
s.erase(sl[i]);
sl[i + 1] = *s.begin();
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 51;
int n, cur, x;
inline int read() {
register int num = 0, neg = 1;
register char ch = getchar();
while (!isdigit(ch) && ch != '-') {
ch = getchar();
}
if (ch == '-') {
neg = -1;
ch = getchar();
}
while (isdigit(ch)) {
num = (num << 3) + (num << 1) + (ch - '0');
ch = getchar();
}
return num * neg;
}
int main() {
n = read(), cur = 3;
for (register int i = 1; i <= n; i++) {
x = read();
if (x == cur) {
return puts("NO"), 0;
}
cur ^= x;
}
puts("YES");
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
int n, a[1 << 17];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
bool b = 1;
int spec = vec[2];
for (int i = 1; i <= n; i++) {
if (spec == a[i])
b = 0;
else {
if (spec == 1 && a[i] == 2)
spec = 3;
else if (spec == 1 && a[i] == 3)
spec = 2;
else if (spec == 2 && a[i] == 3)
spec = 1;
else if (spec == 2 && a[i] == 1)
spec = 3;
else if (spec == 3 && a[i] == 1)
spec = 2;
else if (spec == 3 && a[i] == 2)
spec = 1;
}
}
if (b) return cout << "YES", 0;
return cout << "NO", 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
inline void gn(long long &first) {
int sg = 1;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
c == '-' ? (sg = -1, first = 0) : (first = c - '0');
while ((c = getchar()) >= '0' && c <= '9') first = first * 10 + c - '0';
first *= sg;
}
inline void gn(int &first) {
long long t;
gn(t);
first = t;
}
inline void gn(unsigned long long &first) {
long long t;
gn(t);
first = t;
}
inline void gn(double &first) {
double t;
scanf("%lf", &t);
first = t;
}
inline void gn(long double &first) {
double t;
scanf("%lf", &t);
first = t;
}
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1) ans = 1LL * ans * a % m;
return ans;
}
int N, a[110], f;
void calc(int u, int v, int tot) {
if (tot > N) return;
if (a[tot] != u && a[tot] != v) {
f = 1;
return;
}
if (a[tot] == u)
calc(u, 6 - u - v, tot + 1);
else if (a[tot] == v)
calc(v, 6 - u - v, tot + 1);
return;
}
int main() {
gn(N);
for (int i = 1; i <= N; i++) gn(a[i]);
calc(1, 2, 1);
if (f)
puts("NO");
else
puts("YES");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a = 1, b = 2, c = 3, flag = 0;
cin >> n;
while (n--) {
int t;
cin >> t;
if (t == c) flag = 1;
if (t == a) swap(&b, &c);
if (t == b) swap(&a, &c);
}
if (flag)
cout << "NO\n";
else
cout << "YES\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num;
int a1 = 1, a2 = 2, a3 = 3;
cin >> num;
int n[num];
int win, lose;
int jam = 1;
for (int i = 1; i <= num; i++) {
cin >> n[i];
}
for (int i = 1; i <= num; i++) {
if (i == 1) {
if (n[1] == a1) {
win = n[i];
lose = a2;
} else if (n[1] == a2) {
win = n[i];
lose = a1;
} else {
jam = 0;
break;
}
} else if (i == 2) {
if (n[i] == win) {
win = n[i];
lose = a3;
} else if (n[i] == a3) {
int m = win;
win = n[i];
lose = m;
} else {
jam = 0;
break;
}
} else {
if (n[i] == win) {
win = n[i];
lose = 6 - win - lose;
} else if (n[i] != win && n[i] != lose) {
int m = win;
win = n[i];
lose = m;
} else {
jam = 0;
break;
}
}
}
if (jam == 0) {
cout << "NO";
} else {
cout << "YES";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n][2];
for (int i = 0; i < n; i++) cin >> a[i];
if (a[0] == 3) {
cout << "NO";
return 0;
}
b[0][0] = a[0];
if (b[0][0] == 1)
b[0][1] = 2;
else
b[0][1] = 1;
for (int i = 1; i < n; i++) {
b[i][0] = a[i];
if (b[i][0] != b[i - 1][0])
b[i][1] = b[i - 1][0];
else if ((b[i][0] == 1 && b[i - 1][1] == 2) ||
((b[i][0] == 2 && b[i - 1][1] == 1)))
b[i][1] = 3;
else if ((b[i][0] == 1 && b[i - 1][1] == 3) ||
((b[i][0] == 3 && b[i - 1][1] == 1)))
b[i][1] = 2;
else if ((b[i][0] == 3 && b[i - 1][1] == 2) ||
((b[i][0] == 2 && b[i - 1][1] == 3)))
b[i][1] = 1;
}
for (int i = 0; i < n; i++)
if (b[i][0] == b[i - 1][1]) {
cout << "NO";
return 0;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, spect = 3, flag = 1, loser;
cin >> n;
int win[n];
for (int i = 0; i < n; i++) cin >> win[i];
int i = 0;
if (win[0] == 3)
flag = 0;
else {
while (n--) {
loser = 6 - win[i] - spect;
if (loser == win[i + 1]) {
flag = 0;
break;
}
spect = loser;
i++;
}
}
if (flag)
cout << "YES";
else
cout << "NO";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, pres;
cin >> n;
int a[n];
int har, spec = 3;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool flg = false;
for (int i = 0; i < n; i++) {
if (i == 0) {
spec = 3;
a[i] == 1 ? har = 2 : har = 1;
}
if (flg == false) {
if (i == 0) {
if (a[i] == spec) flg = true;
} else {
if (a[i] == a[i - 1]) {
swap(har, spec);
} else {
if (a[i] == har)
flg = true;
else {
spec = har;
har = a[i - 1];
}
}
}
}
}
flg == true ? cout << "NO" : cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, a[101], cnt[31], cur;
string s;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int cur1 = 0, cur2 = 0, cur3 = -1;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) {
if (cur1 == -1) {
cout << "NO";
return 0;
}
swap(cur2, cur3);
}
if (a[i] == 2) {
if (cur2 == -1) {
cout << "NO";
return 0;
}
swap(cur1, cur3);
}
if (a[i] == 3) {
if (cur3 == -1) {
cout << "NO";
return 0;
}
swap(cur1, cur2);
}
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 7, INF = INT_MAX;
int main() {
int n;
scanf("%d", &n);
int pl1 = 1, pl2 = 2, sld = 3;
while (n--) {
int q;
scanf("%d", &q);
if (q == sld) {
cout << "NO";
return 0;
}
if (q == pl1) {
swap(pl2, sld);
} else {
swap(pl1, sld);
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void marmot0814() {
int n;
cin >> n;
int p1 = 1, p2 = 2, p3 = 3;
while (n--) {
int v;
cin >> v;
if (v == p3) {
cout << "NO\n";
return;
} else if (v == p1) {
swap(p2, p3);
} else {
swap(p1, p3);
}
}
cout << "YES\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1, kase = 0;
while (t--) {
marmot0814();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, arr[105];
int cek[5];
int main() {
scanf("%d", &n);
for (int x = 1; x <= n; x++) {
scanf("%d", &arr[x]);
}
int a = 1;
int b = 2;
for (int x = 1; x <= n; x++) {
cek[1] = 0;
cek[2] = 0;
cek[3] = 0;
cek[a] = 1;
cek[b] = 1;
if (arr[x] == b) {
if (cek[1] == 0)
a = 1;
else if (cek[2] == 0)
a = 2;
else if (cek[3] == 0)
a = 3;
} else if (arr[x] == a) {
if (cek[1] == 0)
b = 1;
else if (cek[2] == 0)
b = 2;
else if (cek[3] == 0)
b = 3;
} else {
printf("NO\n");
return 0;
}
}
printf("YES\n");
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
int spec = 3;
while (n--) {
int win, lose;
cin >> win;
if (win == spec) {
cout << "NO";
return 0;
}
lose = 6 - win - spec;
spec = lose;
}
cout << "YES";
}
|
#include <bits/stdc++.h>
using namespace std;
int find_spec(int spec, int y) {
switch (spec) {
case 1:
if (y == 2)
return 3;
else
return 2;
case 2:
if (y == 1)
return 3;
else
return 1;
case 3:
if (y == 1)
return 2;
else
return 1;
}
}
int n, a[105], spec;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
if (a[0] == 3)
printf("NO\n");
else {
if (a[0] == 1)
spec = 2;
else
spec = 1;
int i;
for (i = 1; i < n; i++) {
if (spec == a[i]) break;
spec = find_spec(a[i], spec);
}
if (i == n)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N;
cin >> N;
int p1 = 1, p2 = 2, extra = 3, x;
for (int i = 0; i < N; i++) {
cin >> x;
if (x != p1 && x != p2) {
cout << "NO" << '\n';
return 0;
} else {
if (x == p1) {
swap(p2, extra);
} else {
swap(p1, extra);
}
}
}
cout << "YES" << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[110];
while (~scanf("%d", &n)) {
int l, r;
l = 1, r = 2;
bool flag = true;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] == l)
r = 6 - l - r;
else if (a[i] == r) {
int t = r;
r = 6 - l - r;
l = t;
} else
flag = false;
}
if (flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
const long long mod = 1000 * 1000 * 1000 + 7;
const long long mod1 = 998244353;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (long long)(res * x);
y = y >> 1;
if (x <= 100000000) x = (long long)(x * x);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long T;
cin >> T;
long long p = 1, q = 2, r = 3;
while (T--) {
long long win;
cin >> win;
if (win == r) {
cout << "NO";
return 0;
} else {
if (win == p) {
swap(q, r);
} else {
swap(p, r);
}
}
}
cout << "YES";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
const int M = 2e6 + 9;
const int INF = 1e9 + 7;
int main() {
int n;
int a[22222];
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
int m;
m = 3;
int flag = 0;
for (int i = 0; i < n; ++i) {
if (a[i] == m) {
flag = 1;
break;
} else {
for (int j = 1; j <= 3; ++j) {
if (a[i] != j && m != j) {
m = j;
break;
}
}
}
}
if (!flag)
printf("YES\n");
else
printf("NO\n");
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5, inf = 0x3f3f3f3f;
int a[N], mk[10];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
mk[1] = mk[2] = 1;
bool flag = true;
for (int i = 1; i <= n; i++) {
int p2, p3;
if (!mk[a[i]]) flag = false;
for (int j = 1; j <= 3; j++) {
if (mk[j] && a[i] != j) p3 = j;
}
for (int j = 1; j <= 3; j++)
if (!mk[j]) p2 = j;
mk[p2] = 1;
mk[p3] = 0;
}
if (flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, n, m;
cin >> n;
m = 3;
l = 2;
j = 1;
for (i = 1; i <= n; i++) {
cin >> k;
if (m == k) {
cout << "NO";
exit(0);
}
m = 6 - k - m;
}
cout << "YES";
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.