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
3
3
3
1
1
1
1
3
3
3
3
1
2
3
1
2
2
2
3
3
2
1
3
3
1
2
3
1
1
1
2
2
2
3
1
1
1
1
1
1
3
2
2
2
2
2
2
3
1
2
2
2
2
2
3
3
2
1
1
 3
3
2
2
 3
3
2
3
 2
3
3
 3
2
2
1
 5
1
1
2
2
3
 3
1
3
1
 3
1
1
3

YES
 NO
 NO
 NO
 YES
 NO
 YES
 YES
 NO
 NO
 NO
 YES
 NO
 NO
 YES
 YES
 YES
 NO
 YES
 YES
 NO
 NO
 NO
 NO
 NO
 YES
 YES
 YES
 NO
 NO
 NO
 YES
 NO
 NO
 NO

#include <bits/stdc++.h>
int main() {
  int n, *a, *b, cnt;
  scanf("%d", &n);
  a = new int[n];
  b = new int[n + 1];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (a[0] == 1)
    b[1] = 2;
  else
    b[1] = 1;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] == 1 && b[i] == 2) {
      if (a[i] == 1)
        b[i + 1] = 3;
      else
        b[i + 1] = 1;
    } else if (a[i - 1] == 1 && b[i] == 3) {
      if (a[i] == 1)
        b[i + 1] = 2;
      else
        b[i + 1] = 1;
    } else if (a[i - 1] == 2 && b[i] == 1) {
      if (a[i] == 2)
        b[i + 1] = 3;
      else
        b[i + 1] = 2;
    } else if (a[i - 1] == 2 && b[i] == 3) {
      if (a[i] == 2)
        b[i + 1] = 1;
      else
        b[i + 1] = 2;
    } else if (a[i - 1] == 3 && b[i] == 1) {
      if (a[i] == 3)
        b[i + 1] = 2;
      else
        b[i + 1] = 3;
    } else if (a[i - 1] == 3 && b[i] == 2) {
      if (a[i] == 3)
        b[i + 1] = 1;
      else
        b[i + 1] = 3;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) cnt++;
  }
  if (cnt == n)
    printf("YES");
  else
    printf("NO");
}
