#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
struct ufind {
  vector<int> par;
  vector<int> rank;
  vector<int> count;
  ufind(int n) {
    par.resize(n);
    rank.resize(n);
    count.resize(n);
    for (lli i = 0; i < (n); i++) {
      par[i] = i;
      rank[i] = 0;
      count[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
lli color[3], c[3], count[3];
vector<int> f, g;
bool flag = false;
void check(int d) {
  if (d == g.size()) {
    lli ll[3] = {};
    for (lli i = 0; i < (g.size()); i++) {
      ll[color[i]] += g[i];
    }
    for (lli i = 0; i < (f.size()); i++) {
      if (ll[i] != f[i]) return;
    }
    flag = true;
    return;
  }
  for (lli i = 0; i < (f.size()); i++) {
    color[d] = i;
    check(d + 1);
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m, fuga;
  ufind uf(n);
  for (lli i = 0; i < (n); i++) {
    cin >> a[i];
    fuga[a[i]]++;
    uf.unite(i, (i + n - 3) % n);
    uf.unite(i, (i + 3) % n);
  }
  for (auto s : fuga) f.push_back(s.second);
  for (lli i = 0; i < (n); i++) {
    m[uf.find(i)]++;
  }
  for (auto s : m) g.push_back(s.second);
  sort(f.begin(), f.end());
  sort(g.begin(), g.end());
  check(0);
  cout << (flag ? "Yes" : "No") << endl;
}
