#include using namespace std; //* #define INCLUDE_MODINT //*/ #ifdef INCLUDE_MODINT #include using namespace atcoder; using mint = modint998244353; // using mint = modint1000000007; // using mint = modint; #endif namespace mytemplate { using ll = long long; using dbl = double; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using pll = pair; using tlll = tuple; using tllll = tuple; using vl = vector; using vpll = vector; using vtlll = vector; using vtllll = vector; using vstr = vector; using vvl = vector>; #ifdef __SIZEOF_INT128__ using i128 = __int128_t; i128 stoi128(string s) { i128 res = 0; if (s.front() == '-') { for (int i = 1; i < (int)s.size(); i++) res = 10 * res + s[i] - '0'; res = -res; } else { for (auto c : s) res = 10 * res + c - '0'; } return res; } string i128tos(i128 x) { string sign = "", res = ""; if (x < 0) x = -x, sign = "-"; while (x > 0) { res += '0' + x % 10; x /= 10; } reverse(res.begin(), res.end()); if (res == "") return "0"; return sign + res; } istream &operator>>(istream &is, i128 &a) { string s; is >> s; a = stoi128(s); return is; } ostream &operator<<(ostream &os, const i128 &a) { os << i128tos(a); return os; } #endif #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(i, n) for (ll i = 0; i < ll(n); i++) #define rep2(i, l, r) for (ll i = ll(l); i < ll(r); i++) #define rep3(i, l, r, d) for (ll i = ll(l); (d) > 0 ? i < ll(r) : i > ll(r); i += d) #define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define ALL(a) (a).begin(), (a).end() const ll INF = 4'000'000'000'000'000'037; bool chmin(auto &a, const auto &b) { return a > b ? a = b, true : false; } bool chmax(auto &a, const auto &b) { return a < b ? a = b, true : false; } template T1 safemod(auto a, auto m) { T1 res = a % m; if (res < 0) res += m; return res; } template T1 divfloor(auto a, auto b) { if (b < 0) a = -a, b = -b; return (a - safemod(a, b)) / b; } template T1 divceil(auto a, auto b) { if (b < 0) a = -a, b = -b; return divfloor(a + b - 1, b); } template T1 pow_ll(auto a, auto b) { if (a == 0) return b == 0 ? 1 : 0; if (a == 1) return a; if (a == -1) return b & 1 ? -1 : 1; ll res = 1; rep(_, b) res *= a; return res; } template T1 mul_limited(auto a, auto b, T1 m = INF) { return b == 0 ? 0 : a > m / b ? m : a * b; } template T1 pow_limited(auto a, auto b, T1 m = INF) { if (a == 0) return b == 0 ? 1 : 0; if (a == 1) return a; ll res = 1; rep(_, b) { if (res > m / a) return m; res *= a; } return res; } template vector b_ary(T1 x, int b) { vector a; while (x > 0) { a.emplace_back(x % b); x /= b; } reverse(a.begin(), a.end()); return a; } template vector b_ary(T1 x, int b, int n) { vector a(n); rep(i, n) { a[i] = x % b; x /= b; } reverse(a.begin(), a.end()); return a; } template string b_ary_str(T1 x, int b) { auto a = b_ary(x, b); string s = ""; for (auto &&ai : a) s += (ai < 10 ? '0' + ai : 'A' + (ai - 10)); return s; } template string b_ary_str(T1 x, int b, int n) { auto a = b_ary(x, b, n); string s = ""; for (auto &&ai : a) s += (ai < 10 ? '0' + ai : 'A' + (ai - 10)); return s; } template vector> iprod(const vector &a) { vector> res; vector tmp(a.size()); auto dfs = [&](auto self, int i) { if (i == (int)a.size()) { res.emplace_back(tmp); return; } rep(j, a[i]) { tmp[i] = j; self(self, i + 1); } }; dfs(dfs, 0); return res; } template struct max_op { T operator()(const T &a, const T &b) const { return max(a, b); } }; template struct min_op { T operator()(const T &a, const T &b) const { return min(a, b); } }; template struct const_fn { T operator()() const { return val; } }; using max_e = const_fn; using min_e = const_fn; using zero_fn = const_fn; template vector digitvec(const string &s) { int n = s.size(); vector a(n); rep(i, n) a[i] = s[i] - '0'; return a; } template auto make_vec(const auto (&sz)[d], const T &init) { if constexpr (i < d) return vector(sz[i], make_vec(sz, init)); else return init; } template vector permid(int n, int base_index = 0) { vector p(n); rep(i, n) p[i] = i + base_index; return p; } template vector perminv(const vector &p) { vector q(p.size()); rep(i, p.size()) q[p[i]] = i; return q; } template vector combid(int n, int k) { vector p(n, 0); fill(p.rbegin(), p.rbegin() + k, 1); return p; } template auto gen_vec(int n, const F &f) { using T = decltype(f(0)); vector res(n); rep(i, n) res[i] = f(i); return res; } // res[i] = op[0, i) for 0 <= i < n+1 template ())> vector cuml(vector v, const F &op = plus<>(), const T &e = 0) { v.emplace_back(e); exclusive_scan(v.begin(), v.end(), v.begin(), e, op); return v; } // res[i] = op[i, n) for 0 <= i < n+1 template ())> vector cumr(vector v, const F &op = plus<>(), const T &e = 0) { v.insert(v.begin(), e); exclusive_scan(v.rbegin(), v.rend(), v.rbegin(), e, op); return v; } // res[i] = v[i] - v[i-1] for 0 <= i < n+1 template vector adjd(vector v) { v.emplace_back(0); adjacent_difference(v.begin(), v.end(), v.begin()); return v; } template vector cumlmax(const vector &v) { return cuml(v, max_op(), max_e()()); } template vector cumrmax(const vector &v) { return cumr(v, max_op(), max_e()()); } template vector cumlmin(const vector &v) { return cuml(v, min_op(), min_e()()); } template vector cumrmin(const vector &v) { return cumr(v, min_op(), min_e()()); } template vector sorted(vector v) { sort(v.begin(), v.end()); return v; } template vector reversed(const vector &v) { return {v.rbegin(), v.rend()}; } template void unique(vector &v) { v.erase(unique(v.begin(), v.end()), v.end()); } template vector uniqued(vector v) { v.erase(unique(v.begin(), v.end()), v.end()); return v; } template void sortunique(vector &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } template vector sortuniqued(vector v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v; } template void rotate(vector &v, int k) { rotate(v.begin(), v.begin() + k, v.end()); } template vector rotated(vector v, int k) { rotate(v.begin(), v.begin() + k, v.end()); return v; } string sorted(string s) { sort(s.begin(), s.end()); return s; } string reversed(const string &s) { return {s.rbegin(), s.rend()}; } void unique(string &s) { s.erase(unique(s.begin(), s.end()), s.end()); } string uniqued(string s) { s.erase(unique(s.begin(), s.end()), s.end()); return s; } void sortunique(string &s) { sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); } string sortuniqued(string s) { sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); return s; } void rotate(string &s, int k) { rotate(s.begin(), s.begin() + k, s.end()); } string rotated(string s, int k) { rotate(s.begin(), s.begin() + k, s.end()); return s; } template vector> top(const vector> &a) { if (a.empty()) return {}; const size_t n = a.size(), m = a[0].size(); vector> b(m, vector(n)); for (size_t i = 0; i < n; i++) for (size_t j = 0; j < m; j++) b[j][i] = a[i].at(j); return b; } vstr top(const vstr &a) { if (a.empty()) return {}; const size_t n = a.size(), m = a[0].size(); vstr b(m, string(n, 0)); for (size_t i = 0; i < n; i++) for (size_t j = 0; j < m; j++) b[j][i] = a[i].at(j); return b; } template vector> rot90(const vector> &a) { if (a.empty()) return {}; const size_t n = a.size(), m = a[0].size(); vector> b(m, vector(n)); for (size_t i = 0; i < n; i++) for (size_t j = 0; j < m; j++) b[j][n - 1 - i] = a[i][j]; return b; } vstr rot90(const vstr &a) { if (a.empty()) return {}; const size_t n = a.size(), m = a[0].size(); vstr b(m, string(n, 0)); for (size_t i = 0; i < n; i++) for (size_t j = 0; j < m; j++) b[j][n - 1 - i] = a[i][j]; return b; } #if __cplusplus < 202002L ull bit_ceil(ull x) { ull y = 1; while (y < x) y <<= 1; return y; } ull bit_floor(ull x) { ull y = 1; while (y <= x) y <<= 1; return y >> 1; } ull bit_width(ull x) { ull y = 1, z = 0; while (y <= x) y <<= 1, z++; return z; } ull countr_zero(ull x) { return __builtin_ctzll(x); } ull popcount(ull x) { return __builtin_popcountll(x); } ull has_single_bit(ull x) { return popcount(x) == 1; } #endif ull lsb_pos(ull x) { assert(x != 0); return countr_zero(x); } ull msb_pos(ull x) { assert(x != 0); return bit_width(x) - 1; } ull lsb_mask(ull x) { assert(x != 0); return x & -x; } ull msb_mask(ull x) { assert(x != 0); return bit_floor(x); } bool btest(ull x, uint k) { return (x >> k) & 1; } template void bset(T &x, uint k, bool b = 1) { b ? x |= (1ULL << k) : x &= ~(1ULL << k); } template void bflip(T &x, uint k) { x ^= (1ULL << k); } bool bsubset(ull x, ull y) { return (x & y) == x; } template vector> bsubsets(T x) { vector> res; for (T y = x; y > 0; y = (y - 1) & x) res.emplace_back(make_pair(y, x & ~y)); res.emplace_back(make_pair(0, x)); return res; } template Tuple tuple_add(Tuple &a, const Tuple &b, const index_sequence) { ((get(a) += get(b)), ...); return a; } template Tuple operator+=(Tuple &a, const Tuple &b) { return tuple_add(a, b, make_index_sequence>{}); } template Tuple operator+(Tuple a, const Tuple &b) { return a += b; } template void offset(vector &v, U add) { for (auto &vi : v) vi += add; } template void offset(vector> &v, U add) { for (auto &vi : v) for (auto &vij : vi) vij += add; } template array, m> top(const vector> &a) { const size_t n = a.size(); array, m> b; b.fill(vector(n)); for (size_t i = 0; i < n; i++) for (size_t j = 0; j < m; j++) b[j][i] = a[i][j]; return b; } template vector> top(const array, n> &a) { if (a.empty()) return {}; const size_t m = a[0].size(); vector> b(m); for (size_t i = 0; i < n; i++) for (size_t j = 0; j < m; j++) b[j][i] = a[i].at(j); return b; } template pair, vector> top(const vector> &a) { const size_t n = a.size(); vector b(n); vector c(n); for (size_t i = 0; i < n; i++) tie(b[i], c[i]) = a[i]; return make_pair(b, c); } template vector> top(const pair, vector> &a) { const size_t n = a.first.size(); vector> b(n); for (size_t i = 0; i < n; i++) b[i] = make_pair(a.first[i], a.second.at(i)); return b; } template tuple, vector, vector> top(const vector> &a) { const size_t n = a.size(); vector b(n); vector c(n); vector d(n); for (size_t i = 0; i < n; i++) tie(b[i], c[i], d[i]) = a[i]; return make_tuple(b, c, d); } template vector> top(const tuple, vector, vector> &a) { const size_t n = get<0>(a).size(); vector> b(n); for (size_t i = 0; i < n; i++) b[i] = make_tuple(get<0>(a)[i], get<1>(a).at(i), get<2>(a).at(i)); return b; } template tuple, vector, vector, vector> top(const vector> &a) { const size_t n = a.size(); vector b(n); vector c(n); vector d(n); vector e(n); for (size_t i = 0; i < n; i++) tie(b[i], c[i], d[i], e[i]) = a[i]; return make_tuple(b, c, d, e); } template vector> top(const tuple, vector, vector, vector> &a) { const size_t n = get<0>(a).size(); vector> b(n); for (size_t i = 0; i < n; i++) b[i] = make_tuple(get<0>(a)[i], get<1>(a).at(i), get<2>(a).at(i), get<3>(a).at(i)); return b; } #ifdef INCLUDE_MODINT using namespace atcoder; template * = nullptr> istream &operator>>(istream &is, T &a) { ll v; is >> v; a = v; return is; } template * = nullptr> ostream &operator<<(ostream &os, const T &a) { os << a.val(); return os; } #define MINT(...) mint __VA_ARGS__; INPUT(__VA_ARGS__) #endif template ::value == true> * = nullptr> istream &operator>>(istream &is, Tuple &t) { apply([&](auto&... a){ (is >> ... >> a); }, t); return is; } template void INPUT(T&... a) { (cin >> ... >> a); } template void INPUTVEC(int n, vector &v) { v.resize(n); rep(i, n) cin >> v[i]; } template void INPUTVEC(int n, vector& v, vector&... vs) { INPUTVEC(n, v); INPUTVEC(n, vs...); } template void INPUTVEC2(int n, int m, vector> &v) { v.assign(n, vector(m)); rep(i, n) rep(j, m) cin >> v[i][j]; } template void INPUTVEC2(int n, int m, vector& v, vector&... vs) { INPUTVEC2(n, m, v); INPUTVEC2(n, m, vs...); } #define INT(...) int __VA_ARGS__; INPUT(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; INPUT(__VA_ARGS__) #define STR(...) string __VA_ARGS__; INPUT(__VA_ARGS__) #define ARR(T, n, ...) array __VA_ARGS__; INPUT(__VA_ARGS__) #define VEC(T, n, ...) vector __VA_ARGS__; INPUTVEC(n, __VA_ARGS__) #define VEC2(T, n, m, ...) vector> __VA_ARGS__; INPUTVEC2(n, m, __VA_ARGS__) template void PRINT(const T &a) { cout << a << '\n'; } template void PRINT(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template void PRINTVEC(const vector &v) { int n = v.size(); rep(i, n) cout << v[i] << (i == n - 1 ? "" : " "); cout << '\n'; } template void PRINTVECT(const vector &v) { for (auto &vi : v) cout << vi << '\n';} template void PRINTVEC2(const vector> &v) { for (auto &vi : v) PRINTVEC(vi); } #define PRINTEXIT(...) do { PRINT(__VA_ARGS__); exit(0); } while (false) #define PRINTRETURN(...) do { PRINT(__VA_ARGS__); return; } while (false) #ifdef LOCAL // ttps://zenn.dev/sassan/articles/19db660e4da0a4 #include "/Users/Shared/cpp-dump-main/dump.hpp" #define dump(...) cpp_dump(__VA_ARGS__) #ifdef INCLUDE_MODINT CPP_DUMP_DEFINE_EXPORT_OBJECT(mint, val()); CPP_DUMP_DEFINE_DANGEROUS_EXPORT_OBJECT(val()); #endif #else #define dump(...) #endif } using namespace mytemplate; // 区間は [left, right) template struct rle_info { T val; int len, left, right; }; template vector> calc_rle(const vector &a) { vector> res; for (int i = 0; i < (int)a.size(); i++) { if (res.empty() || res.back().val != a[i]) res.emplace_back(rle_info(a[i], 1, i, i + 1)); else res.back().len++, res.back().right++; } return res; } vector> calc_rle(const string &s) { vector a(s.begin(), s.end()); return calc_rle(a); } void main2() { LL(N); VEC(ll, N, A); A.insert(A.begin(), 0); A.insert(A.end(), 0); auto B = calc_rle(A); rep(i, (ll)B.size() - 1) { if (abs(B.at(i).val - abs(B.at(i + 1).val)) != 1) PRINTRETURN("No"); } PRINT("Yes"); } void test() { /* mt19937 mt; #ifdef LOCAL rep(t, 100000) { dump(t); // ----- generate cases ----- ll N = 3 + rand() % 6; vl P = permid(N); shuffle(ALL(P), mt); // -------------------------- // ------ check output ------ ll god = naive(P); ll ans = solve(P); if (god != ans) { dump(N, P); dump(god, ans); exit(0); } // -------------------------- } dump("ok"); #endif //*/ } int main() { //* #ifndef LOCAL cin.tie(0); ios::sync_with_stdio(false); #endif //*/ cout << fixed << setprecision(20); test(); int T = 1; /* cin >> T; //*/ while (T--) { main2(); } }