#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using lint = long long; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector& vec, const V& val, int len) { vec.assign(len, val); } template void ndarray(vector& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); } template bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; } template bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; } int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template vector sort_unique(vector vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template int arglb(const std::vector &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); } template int argub(const std::vector &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); } template istream &operator>>(istream &is, vector &vec) { for (auto &v : vec) is >> v; return is; } template ostream &operator<<(ostream &os, const vector &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; } template ostream &operator<<(ostream &os, const array &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; } #if __cplusplus >= 201703L template istream &operator>>(istream &is, tuple &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; } template ostream &operator<<(ostream &os, const tuple &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; } #endif template ostream &operator<<(ostream &os, const deque &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; } template ostream &operator<<(ostream &os, const set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const pair &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; } template ostream &operator<<(ostream &os, const map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } #ifdef HITONANODE_LOCAL const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m"; #define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl #define dbgif(cond, x) ((cond) ? cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl : cerr) #else #define dbg(x) (x) #define dbgif(cond, x) 0 #endif // UnionFind Tree (0-indexed), based on size of each disjoint set struct UnionFind { std::vector par, cou; UnionFind(int N = 0) : par(N), cou(N, 1) { iota(par.begin(), par.end(), 0); } int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return false; if (cou[x] < cou[y]) std::swap(x, y); par[y] = x, cou[x] += cou[y]; return true; } int count(int x) { return cou[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } vector hash() { map> mp; REP(i, par.size()) mp[find(i)].push_back(i); vector ret(par.size(), -1); for (auto [r, vs] : mp) { int lo = par.size(); for (auto x : vs) chmin(lo, x); for (auto x : vs) ret[x] = lo; } return ret; } }; struct rand_int_ { using lint = long long; mt19937 mt; rand_int_() : mt(chrono::steady_clock::now().time_since_epoch().count()) {} lint operator()(lint x) { return this->operator()(0, x); } // [0, x) lint operator()(lint l, lint r) { uniform_int_distribution d(l, r - 1); return d(mt); } } rnd; int exp2(int N) { vector> states; UnionFind uf(N); set> visited; states.push_back(uf.hash()); visited.insert(uf.hash()); int cur = 0; while (cur < int(states.size())) { const auto hash = states[cur]; // dbg(hash); FOR(i, 1, N) { if (__gcd(i, N) != 1) continue; UnionFind current(N); current.par = hash; REP(x, N) current.unite(x, i * x % N); auto ch = current.hash(); if (ch != hash and !visited.count(ch)) { visited.insert(ch); states.push_back(ch); } } cur++; } states = sort_unique(states); // dbg(states); vector> to(states.size()); REP(now, states.size()) { FOR(i, 1, N) { if (__gcd(i, N) != 1) continue; UnionFind current(N); current.par = states[now]; REP(x, N) current.unite(x, i * x % N); int nxt = arglb(states, current.hash()); if (now != nxt) to[now].push_back(nxt); } } vector grundy(states.size(), -1); int start = arglb(states, UnionFind(N).hash()); auto rec = [&](auto &&self, int now) -> void { vector em; for (auto nxt : to[now]) { if (grundy[nxt] < 0) self(self, nxt); em.push_back(grundy[nxt]); } em = sort_unique(em); int cur = 0; while (cur < int(em.size()) and em[cur] == cur) ++cur; grundy[now] = cur; }; rec(rec, start); dbg(make_pair(N, grundy.at(start))); return grundy.at(start); } void experiment() { REP(t, 1000) { int N = rnd(5, 1001); UnionFind uf(N); vector gs{N}; REP(t, 1000) { int g = 0; while (__gcd(g, N) != 1) { g = rnd(1, N); } bool join = false; REP(i, N) join |= uf.unite(i, i * g % N); if (join) gs.push_back(g); if (uf.count(0) == N) break; } vector roots; REP(i, N) roots.push_back(uf.find(i)); gs.push_back(sort_unique(roots).size()); dbg(gs); } } int main() { // vector tmp; // FOR(n, 1, 200) tmp.push_back(exp2(n)); // dbg(tmp); vector grundy{0,0,1,1,2,1,2,0,2,2,2,0,3,2,3,3,4,2,3,3,3,2,2,1,3,3,3,3,3,3,3,4,3,4,4,3,4,3,4,2,4,3,3,3,4,2,2,2,3,3,5,4,3,3,4,2,4,3,2,2,4,3,0,5,1,3,3,5,3,4,3,2,5,4,4,4,4,4,3,1,4,4,2,2,6,3,4,2,4,4,1,3,4,2,5,5,6,3,4,4,4,5,3,5,5,3,2,4,5,4,5,5,5,4,4,4,1,2,6,3,3,4,5,4,4,0,4,6,4,1,3,2,1,3,5,6,4,3,3,5,3,3,5,5,1,5,4,5,3,4,4,5,6,4,5,5,4,3,4,6,4,4,5,5,5,2,2,3,4,6,1,4,3,4,5,5,3,4,2,5,5,1,5,2,6,4,6,3,1,5,3,6,7,6,6,4,4,4,4}; int N; cin >> N; vector A(N); cin >> A; int ax = 0; for (auto a : A) ax ^= grundy.at(a - 1); cout << (ax ? "Y" : "X") << '\n'; }