#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n % 3) {
    int p = 1;
    for (int i = 1; i < n; i++) {
      if (a[i] != a[i - 1]) p = 0;
    }
    if (p)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    int p = 0, q = 0;
    int x = 0;
    int k = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 0)
        p++;
      else {
        if (x) {
          if (x == a[i]) q++;
        } else {
          x = a[i];
          q++;
        }
      }
    }
    if (k == 0 && 2 * p == q)
      cout << "Yes" << endl;
    else {
      int x = a[0], y = -1, z = -1;
      int p = 1, q = 1, r = 1;
      for (int i = 1; i < n; i++) {
        if (a[i] == x)
          p++;
        else if (y == -1)
          y = a[i];
        else if (a[i] == y)
          q++;
        else if (z == -1)
          z = a[i];
        else if (a[i] == z)
          r++;
      }
      if (p == q && q == r)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
}
