malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   inline long long Pow(long long a, long long k) {     long long s = 1;     for (; k; k >>= 1) {       k& 1 ? s = 1LL * s * a % MOD : 0;       a = 1LL * a * a % MOD;     }     return s;   }   const long long N = 1e6 + 7;   void input() {}   void preprocess() {}   void debug() {     if (true) {     }   }   void solve() {     preprocess();     long long n, m;     cin >> n >> m;     long long a[n];     for (long long i = (0); i < (n); i++) {       cin >> a[i];     }     for (long long i = (0); i < (m); i++) {       long long L, R, x;       cin >> L >> R >> x;       L--;       x--;       long long y = L;       for (long long j = (L); j < (R); j++) {         if (a[j] < a[x]) {           y++;         }       }       cout << (y == x ?  Yes  :  No ) << endl;     }   }   void output() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[500005];   vector<pair<long long, long long>> vc[500005];   string s;   bool ans[500005], hv[500005];   long long level[500005], sz[500005], heavy[500005], cnt[500005], col[500005];   void dfs(long long u, long long p, long long l = 1) {     sz[u] = 1, heavy[u] = -1, level[u] = l;     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (v == p) continue;       dfs(v, u, l + 1);       sz[u] += sz[v];       if (heavy[u] == -1 || sz[v] > sz[heavy[u]]) heavy[u] = v;     }   }   void Add(long long u, long long p) {     cnt[level[u]] ^= (1 << col[u]);     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (v == p || hv[v]) continue;       Add(v, u);     }   }   void dsu(long long u, long long p, bool flg) {     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (v == p || v == heavy[u]) continue;       dsu(v, u, 0);     }     if (~heavy[u]) dsu(heavy[u], u, 1), hv[heavy[u]] = 1;     Add(u, p);     for (auto v : vc[u]) {       long long ht = v.first;       long long id = v.second;       if (__builtin_popcountll(cnt[ht]) <= 1) ans[id] = 1;     }     if (~heavy[u]) hv[heavy[u]] = 0;     if (flg == 0) Add(u, p);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long i, j, k, p, q, m, n;     cin >> n >> m;     for (i = 2; i <= n; i++) {       cin >> p;       adj[p].push_back(i);       adj[i].push_back(p);     }     cin >> s;     for (i = 0; i < s.size(); i++) {       col[i + 1] = s[i] -  a ;     }     for (i = 1; i <= m; i++) {       cin >> p >> q;       vc[p].push_back({q, i});     }     dfs(1, -1);     dsu(1, -1, 0);     for (i = 1; i <= m; i++) {       if (ans[i])         cout <<  Yes               <<   n ;       else         cout <<  No               <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using llu = unsigned long long;   using ld = long double;   const double PI = acos(-1.0), g = 9.80665;   const int unseen = -1;   const ll inf = 1e18 + 505, ninf = -1e18 - 505;   const int MOD = 1000000007;   void solve(void) {     int n, p;     cin >> n >> p;     int vrtc = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         cout << i <<     << j <<   n ;         vrtc++;         if (vrtc == (2 * n + p)) return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int testcase = 1;     cin >> testcase;     for (int tc = 1; tc <= testcase; tc++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     x *= f;   }   void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (!x) return;     print(x / 10), putchar(x % 10 + 48);   }   void write(int x) {     if (!x)       putchar( 0 );     else       print(x);     putchar(  n );   }   const int maxn = 1e6 + 10;   const int inf = 1e9;   const double eps = 1e-8;   const int mod = 1e9 + 7;   char s[maxn];   vector<vector<int> > v;   stack<int> a, b;   int n;   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++)       if (s[i] ==  1 ) {         if (a.empty()) return puts( -1 ), 0;         int x = a.top();         a.pop();         v[x].push_back(i);         b.push(x);       } else {         if (b.empty())           v.push_back(vector<int>{i}), a.push(v.size() - 1);         else {           int x = b.top();           b.pop();           v[x].push_back(i);           a.push(x);         }       }     if (b.size()) return puts( -1 ), 0;     write(v.size());     for (auto x : v) {       printf( %d  , x.size());       for (auto a : x) printf( %d  , a);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:640000000 )   using namespace std;   const long long INF = (1e15) + 4;   const int N = 1e6 + 5;   const int K = 26;   int a[N];   int t[N];   int n;   int nxt[N];   int c[N];   int sum(int r) {     int result = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) result ^= t[r];     return result;   }   void inc(int i, int d) {     for (; i < n; i = (i | (i + 1))) t[i] ^= d;   }   vector<pair<int, int>> z[N];   int answer[N];   int get_ans(int l, int r) {     int answer1 = c[r];     if (l > 0) answer1 ^= c[l - 1];     int answer2 = sum(r);     return (answer1 ^ answer2);   }   int main() {     scanf( %d , &n);     map<int, int> b;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       nxt[i] = -1;       c[i] = a[i];       if (i) c[i] ^= c[i - 1];     }     for (int i = n - 1; i >= 0; i--) {       if (b.count(a[i])) nxt[i] = b[a[i]];       b[a[i]] = i;     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d %d , &l, &r);       l--;       r--;       z[l].push_back(make_pair(r, i));     }     set<int> s;     for (int i = 0; i < n; i++) {       if (s.count(a[i]) == 0) inc(i, a[i]);       s.insert(a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < z[i].size(); j++) {         answer[z[i][j].second] = get_ans(i, z[i][j].first);       }       inc(i, a[i]);       if (nxt[i] != -1) inc(nxt[i], a[i]);     }     for (int i = 0; i < m; i++) {       printf( %d n , answer[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace Flandle_Scarlet {   int n;   int a[51][51];   char tmp[51];   int s[51][51];   void Input() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %s , tmp);       for (int j = 1; j <= n; ++j) {         if (tmp[j - 1] ==  # )           a[i][j] = 1;         else           a[i][j] = 0;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + a[i][j];       }     }   }   int RSum(int a1, int b1, int a2, int b2) {     return s[a2][b2] - s[a1 - 1][b2] - s[a2][b1 - 1] + s[a1 - 1][b1 - 1];   }   int dp[51][51][51][51];   int DFS(int a1, int b1, int a2, int b2) {     if (dp[a1][b1][a2][b2]) {       return dp[a1][b1][a2][b2];     }     if (a1 == a2 and b1 == b2) {       dp[a1][b1][a2][b2] = a[a1][b1];       return dp[a1][b1][a2][b2];     }     if (RSum(a1, b1, a2, b2) == 0) {       return (dp[a1][b1][a2][b2] = 0);     }     dp[a1][b1][a2][b2] = max(a2 - a1 + 1, b2 - b1 + 1);     for (int i = a1; i < a2; ++i) {       int newans = DFS(a1, b1, i, b2) + DFS(i + 1, b1, a2, b2);       dp[a1][b1][a2][b2] = min(dp[a1][b1][a2][b2], newans);     }     for (int i = b1; i < b2; ++i) {       int newans = DFS(a1, b1, a2, i) + DFS(a1, i + 1, a2, b2);       dp[a1][b1][a2][b2] = min(dp[a1][b1][a2][b2], newans);     }     return dp[a1][b1][a2][b2];   }   void Soviet() {     DFS(1, 1, n, n);     printf( %d n , dp[1][1][n][n]);   }   void IsMyWife() {     if (0) {       freopen(  ,  r , stdin);       freopen(  ,  w , stdout);     }     Input();     Soviet();   }   };  // namespace Flandle_Scarlet   int main() {     Flandle_Scarlet::IsMyWife();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   const long long inf = 1e18 + 5;   long long n, m, x;   long long a[maxn], b[maxn];   long long ma[maxn * maxn], mb[maxn * maxn];   void input() {     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       a[i] += a[i - 1];       ma[i] = inf;     }     for (long long i = 1; i <= m; ++i) {       cin >> b[i];       b[i] += b[i - 1];       mb[i] = inf;     }     cin >> x;   }   void slove() {     for (long long i = 1; i <= n; ++i) {       for (long long j = 0; j < i; ++j) {         ma[i - j] = min(ma[i - j], a[i] - a[j]);       }     }     for (long long i = 1; i <= m; ++i) {       for (long long j = 0; j < i; ++j) {         mb[i - j] = min(mb[i - j], b[i] - b[j]);       }     }     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       for (long long j = 1; j <= m; ++j) {         if (ma[i] * mb[j] <= x) {           ans = max(ans, i * j);         }       }     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     input();     slove();     return 0;   }
#include <bits/stdc++.h>   const int mod = 1000000007;   const int inf = 1000000009;   const long long INF = 1000000000000000009;   const long long big = 1000000000000000;   const long double eps = 1e-9;   using namespace std;   struct odcinek {     int l, x, r, nr;   };   int suma = 1;   odcinek T[100005];   int D[1100005], M[1100005], S[1100005];   bool cmp(odcinek a, odcinek b) { return a.x < b.x; }   void lazy(int u) {     if (2 * u + 1 <= suma) {       D[2 * u] += D[u];       D[2 * u + 1] += D[u];     }     M[u] += D[u];     D[u] = 0;   }   void dodaj(int a, int b, int lo, int hi, int u, int c) {     if (b <= a) return;     lazy(u);     if (a == lo && b == hi) {       D[u] += c;       return;     }     int mid = (lo + hi) / 2;     dodaj(a, min(b, mid), lo, mid, 2 * u, c);     dodaj(max(a, mid), b, mid, hi, 2 * u + 1, c);     if (M[2 * u] + D[2 * u] >= M[2 * u + 1] + D[2 * u + 1]) {       M[u] = M[2 * u] + D[2 * u];       S[u] = S[2 * u];     } else {       M[u] = M[2 * u + 1] + D[2 * u + 1];       S[u] = S[2 * u + 1];     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int n;     cin >> n;     while (suma < 300000) suma *= 2;     suma *= 2;     suma--;     for (int i = suma / 2 + 1; i <= suma; i++) S[i] = i - suma / 2;     for (int i = suma / 2; i >= 1; i--) S[i] = S[2 * i];     for (int i = 1; i <= n; i++) {       int a, b, c;       cin >> a >> b >> c;       T[i] = {a, b, c, i};     }     sort(T + 1, T + n + 1, cmp);     priority_queue<pair<int, int> > Q;     int wynik = 0;     pair<int, int> skad;     for (int i = 1; i <= n; i++) {       while (!Q.empty() && -Q.top().first < T[i].x) {         pair<int, int> x = Q.top();         dodaj(T[x.second].l, T[x.second].x + 1, 1, suma / 2 + 2, 1, -1);         Q.pop();       }       dodaj(T[i].l, T[i].x + 1, 1, suma / 2 + 2, 1, 1);       lazy(1);       if (M[1] > wynik) {         wynik = M[1];         skad = make_pair(S[1], T[i].x);       }       Q.push(make_pair(-T[i].r, i));     }     cout << wynik <<   n ;     for (int i = 1; i <= n; i++) {       if (T[i].l <= skad.first && T[i].r >= skad.second && T[i].x >= skad.first &&           T[i].x <= skad.second)         cout << T[i].nr <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int c = 0;     int a[2 * m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2 * m; j++) cin >> a[j];       for (int j = 0; j < 2 * m - 1; j += 2) {         if (a[j] == 1 || a[j + 1] == 1) c++;       }     }     cout << c << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n = 0, ans = 0, mod = 1000000009LL;     scanf( %I64d , &n);     if (n >= 5) {       vector<long long> lev(n + 1, 0);       if (n >= 3) lev[3] = 1;       if (n >= 4) lev[4] = 1;       if (n >= 5) lev[5] = 5;       for (int i = 6; i <= n; i++)         if (i % 2 == 0)           lev[i] = 1;         else           lev[i] = (2 * lev[i - 2] + 3) % mod;       long long dob = 1;       for (int i = 5; i <= n; i++)         if (lev[i] > 1) {           dob = (dob * lev[i]) % mod;           ans = (ans + 4 * dob) % mod;         }       ans = (ans + 6) % mod;       ans = (ans * ans) % mod;       ans = (ans + mod - 4) % mod;       ans = (2 * ans) % mod;       ans = (ans + 10) % mod;       printf( %I64d n , ans);     }     if (n == 1) printf( 2 n );     if (n == 2) printf( 10 n );     if (n == 3) printf( 34 n );     if (n == 4) printf( 74 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long b, long long y) { return b > 0 ? gcd(y % b, b) : y; }   long long lcm(long long b, long long y) { return b * y / gcd(b, y); }   double dis(double x1, double x2, double y1, double y2) {     double ans = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     return sqrt(ans);   }   double random(double start, double en) {     return start + (en - start) * rand() / (RAND_MAX + 1.0);   }   map<int, vector<int> > a;   map<int, int> b;   map<int, vector<int> >::iterator it;   void dfs(int x) {     if (b[x]) return;     b[x] = 1;     cout << x <<    ;     for (int i = 0; i < a[x].size(); i++) {       dfs(a[x][i]);     }     return;   }   int main() {     int n;     while (cin >> n) {       for (int i = 1; i <= n; i++) {         int x, y;         cin >> x >> y;         a[x].push_back(y);         a[y].push_back(x);       }       int t;       for (it = a.begin(); it != a.end(); it++) {         if (it->second.size() == 1) {           t = it->first;           break;         }       }       dfs(t);     }   }
#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string first;     while (getline(ss, first, c)) v.emplace_back(first);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << a <<    ;     err(++it, args...);   }   const int M = 5000100, mod = 1000000007;   struct segment_tree {     pair<int, int> T[M];     segment_tree() {}     pair<int, int> find_min(pair<int, int> a, pair<int, int> b) {       return a.first < b.first ? a : b;     }     void build(int* A, int i, int l, int r) {       if (l == r)         T[i] = make_pair(A[l], l);       else {         int m = (l + r) / 2;         build(A, 2 * i, l, m);         build(A, 2 * i + 1, m + 1, r);         T[i] = find_min(T[2 * i], T[2 * i + 1]);       }     }     void update(int i, int l, int r, int first) {       if (l == r && r == first)         T[i] = make_pair(1111111111, l);       else if (first >= l && first <= r) {         int m = (l + r) / 2;         update(2 * i, l, m, first);         update(2 * i + 1, m + 1, r, first);         T[i] = find_min(T[2 * i], T[2 * i + 1]);       }     }     pair<int, int> query(int i, int l, int r, int st, int ed) {       if (l >= st && r <= ed)         return T[i];       else if (l > ed || r < st)         return make_pair(1111111111, -1);       else {         int m = (l + r) / 2;         return find_min(query(2 * i, l, m, st, ed),                         query(2 * i + 1, m + 1, r, st, ed));       }     }   };   struct BIT {     vector<int> tree;     BIT(int n) { tree.resize(n); }     void update(int idx, int val) {       while (idx < tree.size()) {         tree[idx] += val;         idx += idx & (-idx);       }     }     int query(int idx) {       int sum = 0;       while (idx > 0) {         sum += tree[idx];         idx -= idx & (-idx);       }       return sum;     }   };   int A[M], spec[M], n;   segment_tree tree;   BIT bit(M);   long long solve(int l, int r) {     long long sum = 0;     while (l <= r) {       pair<int, int> temp = tree.query(1, 1, n, l, r);       if (temp.first == 1111111111)         break;       else if (spec[temp.first]) {         tree.update(1, 1, n, temp.second);         bit.update(temp.second, -1);         sum += solve(l, temp.second - 1);         sum += solve(temp.second + 1, r);         break;       } else {         sum += bit.query(r) - bit.query(l - 1);         tree.update(1, 1, n, temp.second);         bit.update(temp.second, -1);       }     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     int i, j, k, m;     memset((spec), (false), sizeof(spec));     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d , &A[i]);     for (j = 1; j <= m; j++) scanf( %d , &k), spec[k] = true;     tree.build(A, 1, 1, n);     for (i = 1; i <= n; i++) bit.update(i, 1);     cout << solve(1, n) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a[6];     set<long long> s;     for (int i = 0; i < 6; i++) {       cin >> a[i];     }     sort(a, a + 6);     if ((a[0] == a[1] && a[0] == a[2] && a[0] == a[3] && a[4] == a[5]) ||         (a[1] == a[4] && a[1] == a[2] && a[1] == a[3] && a[0] == a[5]) ||         (a[2] == a[3] && a[2] == a[4] && a[2] == a[5] && a[0] == a[1]))       cout <<  Elephant  << endl;     else if ((a[0] == a[1] && a[0] == a[2] && a[0] == a[3] && a[4] < a[5]) ||              (a[1] == a[4] && a[1] == a[2] && a[1] == a[3] && a[0] < a[5]) ||              (a[2] == a[3] && a[2] == a[4] && a[2] == a[5] && a[0] < a[1]))       cout <<  Bear  << endl;     else       cout <<  Alien  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long solve(long long h, long long n, bool left) {     if (h == 1) return left ? n : 3 - n;     long long p = 1ll << (h - 1);     if (left) {       if (n > p)         return ((long long)1 << h) + solve(h - 1, n - p, left);       else         return 1 + solve(h - 1, n, false);     } else {       if (n > p)         return 1 + solve(h - 1, n - p, true);       else         return ((long long)1 << h) + solve(h - 1, n, false);     }     return -1;   }   int main() {     int h;     cin >> h;     long long n;     cin >> n;     cout << solve(h, n, true) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 233;   int a[N][N];   int main() {     ios::sync_with_stdio(false);     int m, n, q, p, x, y, b;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> a[i][0];     p = a[0][0];     for (int i = 0; i < m; ++i) cin >> a[0][i];     q = a[0][0];     x = y = b = 0;     for (int i = 1; i < n; ++i) x ^= a[i][0];     for (int i = 1; i < m; ++i) y ^= a[0][i];     if ((y ^ p) != (x ^ q)) {       printf( NO n );       return 0;     } else {       b = y ^ p;       a[0][0] = b;       printf( YES n );       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) printf( %d  , a[i][j]);         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   void Letter() {     char str[100000 + 1];     int Left[100000 + 1], Right[100000 + 1];     int i, j;     int Len;     scanf( %s , str);     Len = strlen(str);     Left[0] = Right[Len - 1] = 0;     for (i = 1; i < Len; i++)       if (str[i - 1] <=  z  && str[i - 1] >=  a )         Left[i] = Left[i - 1] + 1;       else         Left[i] = Left[i - 1];     for (i = Len - 2; i >= 0; i--)       if (str[i + 1] <=  Z  && str[i + 1] >=  A )         Right[i] = Right[i + 1] + 1;       else         Right[i] = Right[i + 1];     int min = INT_MAX;     for (i = 0; i < Len; i++)       if (min > Left[i] + Right[i]) min = Left[i] + Right[i];     printf( %d n , min);   }   int main() {     Letter();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt;   int po[999994], cr[14];   map<int, int> mert;   void calc(int L) {     int x = 0;     for (int i = 1; i <= L; i++) x = x * 10 + cr[i];     if (x == 0)       return;     else if (!mert.count(x)) {       mert[x] = 1;       po[++cnt] = x;     }   }   void dfs(int cur, int limit) {     if (cur > limit)       calc(limit);     else       for (int i = 0; i <= 1; i++) {         cr[cur] = i;         dfs(cur + 1, limit);       }   }   int main() {     cin >> n;     for (int i = 1; i <= 10; i++) dfs(1, i);     sort(po + 1, po + cnt + 1);     int i = 0;     for (i = 1; po[i] <= n; i++)       ;     cout << i - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, count(0);     cin >> n >> m;     for (int a = 0; a * a <= n; a++) {       for (int b = 0; b * b <= m; b++) {         if (a * a + b == n && a + b * b == m) count++;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const int N = 405;   const int MOD = 1000000007;   int T, lim, n, k, l, p, cnt, id[N];   long long C[N][N], a[N], dp[N][N], fac[N] = {1};   vector<int> G[N];   bool Judge(long long x) {     long long k = sqrt(x);     return k * k == x;   }   void init() {     C[0][0] = 1LL;     for (int i = 1; i <= 350; i++) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;       fac[i] = fac[i - 1] * i % MOD;     }     id[1] = cnt = 1, G[1].push_back(1);     for (int i = 2; i <= n; i++) {       bool flag = true;       for (int j = i - 1; j >= 1; j--)         if (Judge(a[j] * a[i])) {           G[id[j]].push_back(i);           id[i] = id[j];           flag = false;           break;         }       if (flag) {         id[i] = ++cnt;         G[cnt].push_back(i);       }     }   }   signed main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , a + i);     init();     dp[1][(int)G[1].size() - 1] = 1;     lim = (int)G[1].size();     for (int i = 2; i <= cnt; i++) {       int sz = G[i].size();       for (int k = 0; k < sz; k++)         for (int j = 0; j < lim; j++)           for (int p = 0; p <= min(j, k + 1); p++) {             dp[i][j + sz - k - 1 - p] += dp[i - 1][j] * C[sz - 1][k] % MOD *                                          C[j][p] % MOD *                                          C[lim + 1 - j][k + 1 - p] % MOD;             dp[i][j + sz - k - 1 - p] %= MOD;           }       lim += sz;     }     long long res = dp[cnt][0];     for (int i = 1; i <= cnt; i++) res = res * fac[(int)G[i].size()] % MOD;     printf( %lld n , res);     return 0;   }