malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long a, b, p, q, ay, by, tx, g, l, ty, x, y, n = 15, d, m, tot, last, lst2;   map<int, int> wow;   long long shob[104];   vector<int> all;   char c;   int setbit(int n, int pos) { return n | (1 << (pos)); }   int isbit(int n, int pos) { return n & (1 << (pos)); }   int how(int a, long long &x) {     int ret = 0, boom = 1, wow = 0;     while (a > 0) {       ret++;       int md = a % 7;       wow = boom * md + wow;       boom *= 10;       a /= 7;     }     x = wow;     return ret;   }   int Bboom(int n, int len, int mask, int A) {     if (len > b) {       return 0;     }     int now = n, ans = 0;     for (int i = 0; i < 7; i++) {       if (isbit(mask, i) == 0) {         now = n * 10 + i;         if (len == b && now <= y) {           ans++;         } else if (len < b && now <= y && isbit(mask, i) == 0) {           ans += Bboom(now, len + 1, setbit(mask, i), A);         }       }     }     return ans;   }   int Aboom(int n, int len, int mask) {     if (len > a) {       return 0;     }     int now = n, ans = 0;     for (int i = 0; i < 7; i++) {       if (isbit(mask, i) == 0) {         now = n * 10 + i;         if (len == a && now <= x) {           ans += Bboom(0, 1, setbit(mask, i), now);         } else if (len < a && now <= x) {           ans += Aboom(now, len + 1, setbit(mask, i));         }       }     }     return ans;   }   int main() {     cin >> n >> m;     n--;     m--;     a = max(how(n, x), 1);     b = max(how(m, y), 1);     if (a + b > 7) {       cout << 0 << endl;     } else {       n = a + b;       p = x;       q = y;       cout << Aboom(0, 1, 0);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = (long long)1e9 + 7;   const long long inf = (long long)1e16;   const long double eps = 1e-12;   const long long N = (int)1e5 + 5;   const long long LOGN = 19;   const long double PI = 3.14159265358979323846;   inline long long mul(long long a, long long b, long long m = mod) {     return (long long)(a * b) % m;   }   inline long long add(long long a, long long b, long long m = mod) {     a += b;     if (a >= m) a -= m;     if (a < 0) a += m;     return a;   }   inline long long power(long long a, long long b, long long m = mod) {     if (b == 0) return 1;     if (b == 1) return (a % m);     long long x = power(a, b / 2, m);     x = mul(x, x, m);     if (b % 2) x = mul(x, a, m);     return x;   }   bool check(string& k) {     int l = 0, r = k.size() - 1;     while (l < r) {       if (k[l] != k[r]) {         return false;       }       l++;       r--;     }     return true;   }   bool poss(string& k) {     map<char, int> mp;     int num = 0;     for (int i = 0; i < k.length(); i++) {       if (mp.find(k[i]) == mp.end()) {         mp[k[i]]++;         num++;       }     }     if (num == 1) return false;     return true;   }   int rec(string& s) {     int n = s.length();     if (!poss(s)) return -1;     if (!check(s)) return 0;     string k;     for (int i = 0; i < n / 2; i++) {       k += s[i];     }     bool ok = check(k);     if (!ok) {       if (n & 1) return 2;       return 1;     }     int ret = rec(k);     if (ret == -2) {       if (n & 1) return 2;       return 1;     }     if (ret == -1) {       if (n & 1) return -2;       return -1;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     if (0) {       freopen( C:  Users  Dishant  Desktop  Collection-DEV c++  input.txt ,  r ,               stdin);       freopen( C:  Users  Dishant  Desktop  Collection-DEV c++  output.txt ,  w ,               stdout);     }     string s;     cin >> s;     int n = s.length();     int ans = rec(s);     if (ans <= -1) {       cout <<  Impossible ;     } else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int maxx(int fd, int sd) { return (fd > sd) ? fd : sd; }   int minn(int fd, int sd) { return (fd < sd) ? fd : sd; }   long long nod(long long a, long long b) {     if (a < b) {       return nod(b, a);     }     if (b == 0) {       return a;     }     return nod(b, a % b);   }   long long nok(long a, long b) {     long long result = (long long)a * (long long)b;     result = result / nod(a, b);     return result;   }   int main() {     long long n, k;     long long overallNOK = 1LL;     scanf( %I64d %I64d , &n, &k);     for (int i = 0; i < n; ++i) {       long long c;       scanf( %I64d , &c);       overallNOK = nok(nod(k, c), overallNOK);     }     printf( %s , (overallNOK % k == 0) ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int maxx = 10005;   const int INF = 0x3f3f3f3f;   int n, m, k;   int vis[maxx];   int ans = 0, cnt = 0, pos = 0;   int l = 0, r = 0;   string a, b;   string s1, s2;   int main() {     scanf( %d%d , &n, &m);     cin >> a >> b;     if (n > m + 1) {       printf( NO n );       return 0;     }     int fk = 0;     int tag = 0;     for (int i = 0; i < n; i++) {       if (a[i] ==  * ) {         tag = 1;         continue;       }       if (tag == 0)         s1.push_back(a[i]);       else         s2.push_back(a[i]);     }     if (tag) {       fk = 0;       for (int i = 0; i < ((int)(s1).size()); i++) {         if (b[i] != s1[i]) fk = 1;       }       for (int i = ((int)(s2).size()) - 1; i >= 0; i--) {         if (b[m - ((int)(s2).size()) + i] != s2[i]) {           fk = 1;         }       }     } else {       if (n != m)         fk = 1;       else {         for (int i = 0; i < n; i++) {           if (a[i] != b[i]) {             fk = 1;             break;           }         }       }     }     if (a ==  * ) fk = 0;     if (fk)       printf( NO n );     else       printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int b;     bool x;     edge *next;   } E[100010], *rt[100010];   int o = 0;   int mi = 100000000;   int N;   void addedge(int a, int b) {     edge *p = &E[o++];     p->b = b;     p->x = false;     p->next = rt[a];     rt[a] = p;     p = &E[o++];     p->b = a;     p->x = true;     p->next = rt[b];     rt[b] = p;   }   int S[10010];   bool jud[10010];   void init() {     for (int i = 1; i <= N; i++) {       jud[i] = false;       S[i] = 0;     }   }   void pdfs(int n) {     jud[n] = true;     for (edge *p = rt[n]; p != NULL; p = p->next) {       int b = p->b;       if (!jud[b]) {         pdfs(b);         S[n] += S[b];         if (p->x) S[n]++;       }     }   }   void dfs(int n, int s0, int s1) {     jud[n] = true;     int b, s, t0, t1;     for (edge *p = rt[n]; p != NULL; p = p->next) {       b = p->b;       if (!jud[b]) {         s = S[n];         mi = min(mi, s + s0);         t0 = s + s0 - S[b];         if (p->x)           s = S[n] - 1;         else           s = S[n] + 1;         mi = min(mi, s + s1);         t1 = s + s1 - S[b];         s = S[n] - (p->x == true);         mi = min(mi, s + s0);         t1 = min(t1, s + s0 - S[b]);         dfs(b, t0, t1);       }     }   }   int main() {     o = 0;     int i, j, k;     int a, b, s;     scanf( %d , &N);     if (N == 1) {       printf( 0 n );       return 0;     }     for (i = 0; i <= N; i++) {       rt[i] = NULL;     }     for (i = 1; i < N; i++) {       scanf( %d%d , &a, &b);       addedge(a, b);     }     for (i = 1; i <= N; i++) {       init();       pdfs(i);       for (j = 0; j <= N; j++) jud[j] = false;       dfs(i, 0, 0);     }     printf( %d n , mi);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long h[100000], ans[100000];     cin >> n;     for (int i = 0; i < n; i++) cin >> h[i];     ans[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) {       if (h[i] <= h[i + 1])         ans[i] = h[i + 1] - h[i] + 1;       else         ans[i] = 0;       h[i] = max(h[i], h[i + 1]);     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   int inp() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   int root[1000010];   struct President_Tree {     int lc[10000000], rc[10000000];     long long k[10000000], b[10000000];     int cnt;     void push_up(int cur) {       k[cur] = k[lc[cur]] + k[rc[cur]];       b[cur] = b[lc[cur]] + b[rc[cur]];     }     void insert(int &cur, int last, int x, int kc, int bc, int l, int r) {       cur = ++cnt;       if (l == r) {         k[cur] = k[last] + kc;         b[cur] = b[last] + bc;         return;       }       int mid = (l + r) >> 1;       if (x <= mid) {         insert(lc[cur], lc[last], x, kc, bc, l, mid);         rc[cur] = rc[last];       } else {         lc[cur] = lc[last];         insert(rc[cur], rc[last], x, kc, bc, mid + 1, r);       }       push_up(cur);     }     long long query(int cur, int last, int ql, int qr, long long x, int l,                     int r) {       if (l > qr || r < ql) return 0;       if (l >= ql && r <= qr) return x * (k[cur] - k[last]) + (b[cur] - b[last]);       int mid = (l + r) >> 1;       return query(lc[cur], lc[last], ql, qr, x, l, mid) +              query(rc[cur], rc[last], ql, qr, x, mid + 1, r);     }   } t;   int main() {     int n = inp();     for (int i = 1; i <= n; i++) {       int xl = inp();       int xr = inp();       int yl = inp();       int k = inp();       int b = inp();       int yr = inp();       t.insert(root[i], root[i - 1], 0, 0, yl, 0, 1e9);       t.insert(root[i], root[i], xl + 1, k, b - yl, 0, 1e9);       t.insert(root[i], root[i], xr + 1, -k, yr - b, 0, 1e9);     }     int m = inp();     long long lastans = 0;     while (m--) {       int l = inp();       int r = inp();       int x = (inp() + lastans) % 1000000000;       lastans = t.query(root[r], root[l - 1], 0, x, x, 0, 1e9);       printf( %lld n , lastans);     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b) {       int temp = b;       b = a % b;       a = temp;     }     return a;   }   int main() {     int a, b, n, counting = 0, GCD;     scanf( %d %d %d , &a, &b, &n);     while (1) {       counting++;       GCD = gcd(a, n);       if (n < GCD) break;       n = n - GCD;       counting++;       GCD = gcd(b, n);       if (n < GCD) break;       n = n - GCD;     }     printf( %d n , counting % 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long date(int y, int m, int d) {     if (m < 3) y--, m += 12;     return (long long)365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 +            d - 306;   }   int main() {     int y1, y2, m1, m2, d1, d2;     scanf( %d:%d:%d , &y1, &m1, &d1);     scanf( %d:%d:%d , &y2, &m2, &d2);     printf( %lld n , llabs(date(y1, m1, d1) - date(y2, m2, d2)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 Rand(time(0));   long long rnd(long long a) { return Rand() % a; }   long long rnd(long long a, long long b) { return Rand() % (b - a + 1) + a; }   double rnd_01d() { return (double)Rand() / (1ll << 32); }   double rnd_d(double r) { return rnd_01d() * r; }   const long long inf = 1e9 + 7;   void run() {     long long n;     cin >> n;     vector<long long> h(n);     for (long long i = 0; i < n; ++i) cin >> h[i];     long long l = -1, r = 1e9 + 3;     while (r - l > 1) {       long long mid = (l + r) / 2;       vector<long long> b;       copy(begin(h), end(h), back_inserter(b));       bool bad = false;       for (long long i = n - 1; i >= 2; --i) {         if (b[i] < mid) bad = true;         long long d = min(b[i] - mid, h[i]) / 3;         b[i - 1] += d;         b[i - 2] += 2 * d;       }       if (b[1] < mid || b[0] < mid || bad)         r = mid;       else         l = mid;     }     cout << l << endl;   }   signed main() {     cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);     cout.precision(5);     long long t = 1;     cin >> t;     while (t--) {       run();     }   }
#include <bits/stdc++.h>   using namespace std;   int minimum(int x, int y) { return (x < y ? x : y); }   template <typename type>   struct even {     bool operator()(const type &x, const type &y) const { return x % 2 == 0; }   };   template <typename type>   struct odd {     bool operator()(const type &x, const type &y) const { return x % 2 != 0; }   };   bool flusher(int x) {     string s;     cout << x << endl;     fflush(stdout);     cin >> s;     return s ==  yes ;   }   long long int magic(string s) {     long long int sum = 0;     for (int i = 0; i < s.size(); i++) {       sum += s[i] -  0 ;     }     return sum;   }   long long int binaryToInt(string s) {     long long int n = s.length();     long long int res = 0;     long long int base = 1;     for (long long int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         res += base;       }       base *= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     int length = n * 2 + 1;     int res = 0;     int x[length];     for (int i = 0; i < length; i++) {       cin >> x[i];     }     for (int i = 1; i < length; i += 2) {       if (x[i] - 1 > x[i - 1] && x[i] - 1 > x[i + 1]) {         x[i]--;         res++;       }       if (res == k) {         break;       }     }     for (int i = 0; i < length; i++) {       cout << x[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 50;   long long kol, sum, id, ans;   string s;   vector<long long> a;   int main() {     cin >> s;     ans = 0;     sum = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  v ) {         id += 1;         if (i == s.size() - 1) {           sum += id - 1;         }       } else {         if (id != 0) {           sum += id - 1;           id = 0;         }         a.push_back(sum);         kol += 1;       }     }     if (a.size() == 0) {       cout << 0;       return 0;     }     for (int i = 0; i < a.size(); i++) {       ans += a[i] * (sum - a[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(NULL);     int n, x;     cin >> n;     while (n--) {       cin >> x;       if (x < 3 || x == 4 || x == 5 || x == 8 || x == 11)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     int ans = 0;     cin >> n >> m >> k;     int t;     for (int i = 0; i < n; ++i) {       cin >> t;       if (t == 1) {         if (m == 0)           ++ans;         else           --m;       } else {         if (m + k == 0)           ++ans;         else {           if (k)             --k;           else             --m;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   const int MAXINT = 1073741823;   vector<int> neighbors[MAXN];   int a[MAXN];   int greater_right[MAXN];   int greater_left[MAXN];   int less_right[MAXN];   int less_left[MAXN];   int dp[MAXN];   stack<int> s;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       while (!s.empty() && a[s.top()] < a[i]) s.pop();       greater_left[i] = (s.empty() ? -1 : s.top());       s.push(i);     }     stack<int>().swap(s);     for (int i = 0; i < n; i++) {       while (!s.empty() && a[s.top()] > a[i]) s.pop();       less_left[i] = (s.empty() ? -1 : s.top());       s.push(i);     }     stack<int>().swap(s);     for (int i = n - 1; i >= 0; i--) {       while (!s.empty() && a[s.top()] < a[i]) s.pop();       greater_right[i] = (s.empty() ? -1 : s.top());       s.push(i);     }     stack<int>().swap(s);     for (int i = n - 1; i >= 0; i--) {       while (!s.empty() && a[s.top()] > a[i]) s.pop();       less_right[i] = (s.empty() ? -1 : s.top());       s.push(i);     }     for (int i = 0; i < n; i++) {       if (greater_left[i] != -1) neighbors[greater_left[i]].push_back(i);       if (greater_right[i] != -1) neighbors[i].push_back(greater_right[i]);       if (less_left[i] != -1) neighbors[less_left[i]].push_back(i);       if (less_right[i] != -1) neighbors[i].push_back(less_right[i]);     }     fill(dp, dp + n, MAXINT);     dp[0] = 0;     for (int i = 0; i < n; i++)       for (int j : neighbors[i]) dp[j] = min(dp[j], dp[i] + 1);     cout << dp[n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int N = 2e5 + 5;   int n;   vector<int> adj[N];   int root;   int degree[N], removed[N], level[N];   void dfs(int u, int p) {     for (auto v : adj[u]) {       if (v == p) continue;       level[v] = level[u] + 1;       dfs(v, u);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 0) {         root = i;         continue;       }       adj[x].push_back(i);       adj[i].push_back(x);       degree[i]++, degree[x]++;     }     if (n % 2 == 0) {       cout <<  NO n ;       return 0;     }     dfs(root, 0);     set<pair<int, int> > s;     for (int i = 1; i <= n; i++) {       if (degree[i] % 2 == 0) s.insert({level[i], i});     }     vector<int> ans;     while (!s.empty()) {       auto top = *s.rbegin();       s.erase(prev(s.end()));       int node = top.second;       for (auto v : adj[node]) {         if (removed[v]) continue;         degree[v]--;         if (degree[v] % 2 == 1) {           s.erase(s.find({level[v], v}));         } else {           s.insert({level[v], v});         }       }       ans.push_back(node);       removed[node] = 1;     }     if (ans.size() == n) {       cout <<  YES n ;       for (auto i : ans) cout << i <<   n ;     } else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using namespace std;   const int N = 2e5 + 2, mod = 998244353;   int n, m, d[N][20];   pair<int, int> dist[N][2];   vector<int> g[2][N];   struct State {     int d, ver, B;     bool operator<(const State& oth) const { return d > oth.d; }   };   struct State1 {     int B, A, ver;     bool operator<(const State1& oth) const {       return B > oth.B || (B == oth.B && A > oth.A);     }   };   void solve1() {     priority_queue<State1> pq;     for (int i = (1); i <= (n); ++i) dist[i][0] = dist[i][1] = {1e9, 1e9};     dist[1][0] = {0, 0};     pq.push({0, 0, 1});     while (!pq.empty()) {       State1 cur = pq.top();       pq.pop();       int side = cur.B & 1;       if (pair<int, int>(cur.B, cur.A) != dist[cur.ver][side]) continue;       for (int v : g[side][cur.ver])         if (dist[v][side].first > cur.B ||             (dist[v][side].first == cur.B && dist[v][side].second > cur.A + 1)) {           dist[v][side] = {cur.B, cur.A + 1};           pq.push({cur.B, cur.A + 1, v});         }       if (dist[cur.ver][side ^ 1].first > cur.B + 1 ||           (dist[cur.ver][side ^ 1].first == cur.B + 1 &&            dist[cur.ver][side ^ 1].second > cur.A)) {         dist[cur.ver][side ^ 1] = {cur.B + 1, cur.A};         pq.push({cur.B + 1, cur.A, cur.ver});       }     }     pair<int, int> ans = dist[n][0];     if (dist[n][1].first < ans.first ||         (dist[n][1].first == ans.first && dist[n][1].second < ans.second))       ans = dist[n][1];     assert(ans.first != 1e9 && ans.second != 1e9);     int res = 1;     for (int i = (1); i <= (ans.first); ++i) res = res * 2LL % mod;     cout << (res + ans.second - 1) % mod;   }   void solve() {     int LG = 32 - __builtin_clz(m);     assert(LG <= 19);     priority_queue<State> pq;     pq.push({0, 1, 0});     for (int i = (1); i <= (n); ++i)       for (int j = (0); j <= (19); ++j) d[i][j] = 1e9;     d[1][0] = 0;     while (!pq.empty()) {       State cur = pq.top();       pq.pop();       if (cur.d != d[cur.ver][cur.B]) continue;       for (int v : g[cur.B & 1][cur.ver])         if (d[v][cur.B] > cur.d + 1) {           d[v][cur.B] = cur.d + 1;           pq.push({d[v][cur.B], v, cur.B});         }       if (cur.B < LG) {         if (d[cur.ver][cur.B + 1] > cur.d + (1 << cur.B)) {           d[cur.ver][cur.B + 1] = cur.d + (1 << cur.B);           pq.push({d[cur.ver][cur.B + 1], cur.ver, cur.B + 1});         }       }     }     int ans = 1e9;     for (int i = (0); i <= (LG); ++i)       if (ans > d[n][i]) ans = d[n][i];     if (ans == 1e9)       solve1();     else       cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     for (int i = (1); i <= (m); ++i) {       int u, v;       cin >> u >> v;       g[0][u].emplace_back(v);       g[1][v].emplace_back(u);     }     solve();     return 0;   }
#include <iostream>   #include <algorithm>   #include <cassert>   #include <fstream>      using ll = long long;   const int maxn = 5007;   ll t, n, S[maxn], ans[maxn];   ll res;      int main(int argc, char *argv[]) {      std::ios::sync_with_stdio(false);    std::cin.tie(0);     std::cin >> t;    while (t--) {     res = 0;     std::cin >> n;     for (ll i = 0; i < n; i++) {      std::cin >> S[i];      ans[i] = 0;     }     for (ll i = 0; i < n; i++) {      ll temp = ans[i];      if (temp < S[i]-1){       res += S[i] - 1 - temp;       temp += S[i] - 1 - temp;      }      ans[i+1] += temp - S[i] + 1;      if (i+2 < n) {       for (int j = i+2; j < std::min(n,i+S[i]+1); j++) {        ans[j]++;       }      }      }     std::cout << res <<   n ;    }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, pos;   long long a[200005], sum[200005], ans;   vector<long long> vec;   int main() {     cin.tie(0), ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum[i] = a[i];       sum[i] += sum[i - 1];       if (a[i] > 1) vec.push_back(i);     }     a[n + 1] = 1;     vec.push_back(n + 1);     for (int i = 1; i <= n; i++) {       pos = i;       long long tich = a[i];       while (1) {         int it = lower_bound(vec.begin(), vec.end(), pos + 1) - vec.begin();         int l = pos, r = vec[it] - 1, mid;         if (tich % k == 0) {           long long val = tich / k;           while (l < r) {             mid = (l + r) / 2;             if (sum[mid] - sum[i - 1] >= val)               r = mid;             else               l = mid + 1;           }           if (l >= pos && sum[l] - sum[i - 1] == val) {             ans++;           }         }         long long amount = LLONG_MAX / a[vec[it]];         if (tich >= amount) break;         tich *= a[vec[it]];         pos = vec[it];         if (pos == n + 1) break;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int a[300000];   int ans[300000];   map<int, int> m;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n * n; i++) {       scanf( %d , &a[i]);       m[a[i]]++;     }     sort(a, a + n * n);     int k = 0;     for (int i = n * n - 1; i >= 0; i--) {       if (m[a[i]] > 0) {         ans[k++] = a[i];         for (int j = 0; j < k; j++) {           m[gcd(a[i], ans[j])] -= 2;         }       }     }     for (int i = 0; i < k - 1; i++) {       printf( %d  , ans[i]);     }     printf( %d , ans[k - 1]);     cout << endl;     return 0;   }