malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int c[N], ctr[N] = {0};   vector<pair<int, int> > candidates, edges;   int main() {     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       edges.push_back({u, v});     }     for (int i = 1; i <= n; ++i) cin >> c[i];     for (auto &i : edges) {       if (c[i.first] != c[i.second]) candidates.push_back(i);     }     if (candidates.empty()) {       cout <<  YES n1 ;       return 0;     }     int m = candidates.size();     for (auto &i : candidates) {       ctr[i.first]++;       ctr[i.second]++;     }     for (int i = 1; i <= n; ++i) {       if (ctr[i] == m) {         cout <<  YES n  << i;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2;   set<char> st;   vector<int> t[300];   int bin_search(char k, int ind) {     int l = 0, r = t[k].size() - 1, m;     while (l < r) {       m = (l + r) / 2;       if (ind == t[k][m]) return t[k][m];       if (ind < t[k][m])         r = m;       else         l = m + 1;     }     if (l && t[k][l - 1] == ind) return t[k][l - 1];     return t[k][l];   }   int main() {     cin >> s1 >> s2;     for (int i = 0; i < s1.size(); i++) t[s1[i]].push_back(i);     for (int j = 0; j < s2.size(); j++)       if (!t[s2[j]].size()) {         cout <<  -1 ;         return 0;       }     int ans = 1, j = 0;     for (int i = 0; i < s2.size(); i++) {       int p = bin_search(s2[i], j);       if (p < j) {         ans++;         j = bin_search(s2[i], 0) + 1;       } else {         j = p + 1;       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 300;   int main() {     string s;     int h;     cin >> h;     cin >> s;     int ans = s.size();     for (int i = 1; s[i]; i++) {       if ((s[i] ==  U  && s[i - 1] ==  R ) || (s[i] ==  R  && s[i - 1] ==  U )) {         s[i] =  p ;         --ans;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 300010;   vector<long long> arr[MAXN];   vector<pair<long long, long long>> holdqs[MAXN];   bool visited[MAXN];   long long answer[MAXN];   long long temp[MAXN];   long long n;   void dfs(long long curr, long long par, long long level, long long ans) {     for (auto x : holdqs[curr]) {       long long lb = level;       long long rb = level + 1 + x.first;       temp[lb] += x.second;       if (rb <= n) {         temp[rb] -= x.second;       }     }     ans += temp[level];     answer[curr] = ans;     for (auto x : arr[curr]) {       if (x != par) {         dfs(x, curr, level + 1, ans);       }     }     for (auto x : holdqs[curr]) {       long long lb = level;       long long rb = level + 1 + x.first;       temp[lb] -= x.second;       if (rb <= n) {         temp[rb] += x.second;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       arr[x].push_back(y);       arr[y].push_back(x);     }     long long q;     cin >> q;     while (q--) {       long long v, d, x;       cin >> v >> d >> x;       holdqs[v].push_back(make_pair(d, x));     }     dfs(1, 1, 1, 0);     for (long long i = 1; i <= n; i++) {       std::cout << answer[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   char a[25][25];   int dp[40][1 << 20], n;   bool vis[40][1 << 20];   int f(int xx, int st) {     if (vis[xx][st]) return dp[xx][st];     int &res = dp[xx][st];     vis[xx][st] = true;     if (xx == n * 2 - 2) {       res = 0;     } else {       if (xx & 1)         res = -0x3f3f3f3f;       else         res = 0x3f3f3f3f;       int mask[30];       memset(mask, 0, sizeof(mask));       int cnt = 0;       for (int j = 0; j <= xx + 1; ++j) {         int x = xx + 1 - j;         int y = j;         if (x >= n || y >= n) continue;         mask[a[x][y] -  a ] |= (1 << cnt);         cnt++;       }       for (int i = 0; i < 26; ++i) {         if (mask[i]) {           int xt;           if (xx + 1 < n)             xt = (st | (st << 1)) & mask[i];           else             xt = (st | (st >> 1)) & mask[i];           if (xt == 0) continue;           int tmp = 0;           if (i == 0)             tmp = 1;           else if (i == 1)             tmp = -1;           if (xx & 1)             res = max(res, tmp + f(xx + 1, xt));           else             res = min(res, tmp + f(xx + 1, xt));         }       }     }     if (xx == 0) {       if (a[0][0] ==  a )         res += 1;       else if (a[0][0] ==  b )         res -= 1;     }     return res;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; ++i) scanf( %s , a[i]);       memset(vis, 0, sizeof(vis));       int res = f(0, 1);       if (res == 0)         printf( DRAW n );       else if (res > 0)         printf( FIRST n );       else         printf( SECOND n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const long long MAXN = 500010;   const long long Mod = 1000000007LL;   struct data {     long long x, y;     inline void ModT() { x %= Mod, y %= Mod; }   } a[MAXN + 1], pre[MAXN + 1];   inline data md(long long x, long long y) {     data xxx;     xxx.x = x, xxx.y = y;     return xxx;   }   inline long long operator*(const data &a, const data &b) {     return a.x * b.y - b.x * a.y;   }   inline data operator+(const data &a, const data &b) {     return md(a.x + b.x, a.y + b.y);   }   inline data operator-(const data &a, const data &b) {     return md(a.x - b.x, a.y - b.y);   }   long long N, tmp, Sum0[MAXN + 1], Sum1[MAXN + 1], ans;   int main() {     N = read();     for (long long i = 1; i <= N; i++) {       long long x = read(), y = read();       a[i] = md(x, y);       pre[i] = pre[i - 1] + a[i], pre[i].ModT();     }     for (int i = 2; i <= N; i++) {       tmp = a[i - 1] * a[i];       Sum0[i] = Sum0[i - 1] + tmp;       Sum1[i] = (Sum1[i - 1] + Sum0[i]) % Mod;     }     long long Now = abs(Sum0[N + 1] = Sum0[N] + a[N] * a[1]);     long long j = 1;     for (long long i = 3; i <= N; i++) {       for (; j < i - 1 && abs(Sum0[i] - Sum0[j] + a[i] * a[j]) > Now / 2.0; ++j)         ;       ans = (ans + Sum0[i] % Mod * (i - 1 - j) - (Sum1[i - 2] - Sum1[j - 1]) +              a[i] * (pre[i - 2] - pre[j - 1])) %             Mod;       ans = (ans + Sum1[j - 1] + pre[j - 1] * a[i] +              (Sum0[N + 1] - Sum0[i]) % Mod * (j - 1)) %             Mod;     }     ans = ((Now % Mod * (Mod + 1 >> 2) % Mod * N % Mod * (N - 3) % Mod + ans) %                Mod +            Mod) *           2LL % Mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 Rand(time(0));   const int maxn = 5e2 + 5;   const long long maxc = 1e9 + 7;   int n, m;   vector<int> adj[maxn];   int d[maxn][maxn];   pair<int, int> trace[maxn][maxn];   vector<int> resOne, resN;   void bfs() {     queue<pair<int, int> > q;     q.push(make_pair(1, n));     memset(d, (-1), sizeof(d));     d[1][n] = 0;     while (!q.empty()) {       int s = q.front().first;       int t = q.front().second;       q.pop();       for (auto u : adj[s]) {         for (auto v : adj[t]) {           if (d[u][v] != -1 || u == v) continue;           trace[u][v] = make_pair(s, t);           d[u][v] = d[s][t] + 1;           q.push(make_pair(u, v));         }       }     }     cout << d[n][1] <<   n ;     if (d[n][1] == -1) return;     int s = 1, t = n;     while (t != 0) {       resOne.push_back(t);       resN.push_back(s);       pair<int, int> cur = trace[t][s];       t = cur.first, s = cur.second;     }     reverse((resOne).begin(), (resOne).end());     reverse((resN).begin(), (resN).end());     for (auto u : resOne) cout << u <<    ;     cout <<   n ;     for (auto u : resN) cout << u <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     bfs();     return 0;   }
#include <bits/stdc++.h>   int b[1010];   double dp[1010][1010];   int main() {     int n, m, i, j, x, y;     double ans = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &b[i]);     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (b[i] > b[j])           dp[i][j] = 1;         else           dp[i][j] = 0;       }     }     while (m--) {       scanf( %d%d , &x, &y);       x--;       y--;       dp[x][y] = dp[y][x] = 0.5;       for (i = 0; i < n; i++) {         if (x == i || y == i) continue;         dp[x][i] = (dp[x][i] + dp[y][i]) * 0.5;         dp[y][i] = dp[x][i];         dp[i][x] = 1 - dp[x][i];         dp[i][y] = dp[i][x];       }     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         ans += dp[i][j];       }     }     printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   int m, n, s;   int main() {     scanf( %d%d , &n, &m);     int ans = 0;     for (int i = 0; i <= 40; i++)       for (int j = 0; j <= 40; j++) {         if (i * i + j == n && j * j + i == m) ans++;       }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   int n;   long long x1, x2;   struct sss {     long long val;     int num;   } a[maxn];   bool cmp(const sss &a, const sss &b) { return a.val > b.val; }   void scanff() {     scanf( %d%I64d%I64d , &n, &x1, &x2);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i].val);       a[i].num = i;     }     sort(a + 1, a + n + 1, cmp);   }   void work() {     int now1, now2;     bool flag = false;     if (x1 < x2) {       swap(x1, x2);       flag = true;     }     for (now1 = 1; now1 <= n; now1++) {       if (a[now1].val * now1 >= x1) break;     }     if (now1 > n) {       printf( No n );       return;     }     for (now2 = now1 + 1; now2 <= n; now2++) {       if (a[now2].val * (now2 - now1) >= x2) break;     }     if (now2 > n) {       int head = 1, tail = now1;       for (;;) {         if (tail + 1 <= n) {           if (a[tail + 1].val * (tail - head + 1) >= x1) {             tail++;             head++;             if (a[head - 1].val * (head - 1) >= x2) {               printf( Yes n );               if (!flag) {                 printf( %d %d n , tail - head + 1, head - 1);                 for (int i = head; i <= tail; i++) {                   printf( %d  , a[i].num);                 }                 printf(  n );                 for (int i = 1; i <= head - 1; i++) {                   printf( %d  , a[i].num);                 }                 return;               } else {                 printf( %d %d n , head - 1, tail - head + 1);                 for (int i = 1; i <= head - 1; i++) {                   printf( %d  , a[i].num);                 }                 printf(  n );                 for (int i = head; i <= tail; i++) {                   printf( %d  , a[i].num);                 }                 return;               }             }           } else {             tail++;           }         } else           break;       }       printf( No n );       return;     }     printf( Yes n );     if (!flag) {       printf( %d %d n , now1, now2 - now1);       for (int i = 1; i <= now1; i++) {         printf( %d  , a[i].num);       }       printf(  n );       for (int i = now1 + 1; i <= now2; i++) {         printf( %d  , a[i].num);       }     } else {       printf( %d %d n , now2 - now1, now1);       for (int i = now1 + 1; i <= now2; i++) {         printf( %d  , a[i].num);       }       printf(  n );       for (int i = 1; i <= now1; i++) {         printf( %d  , a[i].num);       }     }   }   int main() {     scanff();     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct state {     int i, j, dp, cp;   };   int di[] = {0, 1, 0, -1};   int dj[] = {1, 0, -1, 0};   state n[50][50][4][2];   state current;   char b[50][51];   int r, c;   int moves;   void read() {     cin >> r >> moves;     for (int i = 0; i < r; i++) {       cin >> b[i];     }     c = strlen(b[0]);   }   void write() { cout << b[current.i][current.j] <<   n ; }   inline bool valid(int i, int j) {     return i > -1 && i < r && j > -1 && j < c && b[i][j] !=  0 ;   }   void preprocess(int i, int j, int dp, int cp) {     int ni = i, nj = j;     while (valid(ni, nj) && b[ni][nj] == b[i][j]) {       ni += di[dp];       nj += dj[dp];     }     ni -= di[dp];     nj -= dj[dp];     int p = (dp + (cp ? +1 : -1) + 4) % 4;     while (valid(ni, nj) && b[ni][nj] == b[i][j]) {       ni += di[p];       nj += dj[p];     }     ni -= di[p];     nj -= dj[p];     ni += di[dp];     nj += dj[dp];     if (valid(ni, nj)) {       n[i][j][dp][cp].i = ni;       n[i][j][dp][cp].j = nj;       n[i][j][dp][cp].dp = dp;       n[i][j][dp][cp].cp = cp;     } else {       n[i][j][dp][cp].i = i;       n[i][j][dp][cp].j = j;       n[i][j][dp][cp].dp = !cp ? dp : (dp + 1) % 4;       n[i][j][dp][cp].cp = !cp;     }   }   void preprocess() {     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         for (int dp = 0; dp < 4; dp++) {           for (int cp = 0; cp < 2; cp++) {             preprocess(i, j, dp, cp);           }         }       }     }   }   void move() {     for (int i = 0; i < moves; i++) {       current = n[current.i][current.j][current.dp][current.cp];     }   }   int main() {     current.i = current.j = current.dp = current.cp = 0;     read();     preprocess();     move();     write();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize  Ofast,omit-frame-pointer,inline    using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int mx = -INT_MAX;     multiset<int> vs;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       mx = max(mx, x);       vs.insert(x);     }     mx += m;     while (m--) {       int p = *vs.begin();       vs.insert(p + 1);       vs.erase(vs.begin());     }     cout << (*vs.rbegin()) <<     << mx << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int main() {     int n, m, t;     cin >> n >> m >> t;     int total = (n - 2) * (n - 1) / 2 + 1;     if (total >= m && m >= n - 1) {       m = m - n + 1;       int cant = 0;       if (t != 1)         cant = 1;       else         cant = n;       printf( %d %d n , t, cant);       for (int i = 1; i < n; i++) {         if (i != cant && i + 1 != cant) printf( %d %d n , i, i + 1);       }       for (int i = 1; i <= n && m; i++) {         if (t - i == 1 || i - t == 1 || t == i || i == cant) continue;         printf( %d %d n , i, t);         m--;       }       for (int i = 1; i <= n && m; i++) {         if (i == t || i == cant) continue;         for (int j = i + 2; j <= n && m; j++) {           if (j == t || j == cant) continue;           printf( %d %d n , i, j);           m--;         }       }     } else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e6;   const long long MOD = 1e9 + 7;   const long long N = 1e6 + 7;   const long long N_N = 1e3;   const int INF = 1e9 + 228;   const long double eps = 1e-12;   long long n, a[N], ans, l, ans1;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 2; i <= n; ++i) {       if (a[i - 1] > a[i]) {         ans++;         ans1 = i;       }     }     if (ans > 1) {       cout << -1;     }     if (ans == 0) {       cout << 0;     }     if (ans == 1) {       if (a[1] >= a[ans1] && a[1] >= a[n]) {         cout << n - ans1 + 1;       } else         cout << -1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 2e6 + 5;   const int oo = 1e9 + 7;   int lp[N + 1];   vector<int> pr;   void sieve() {     for (int i = 2; i <= N; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)         lp[i * pr[j]] = pr[j];     }   }   int n;   int a[N];   bool isp[N];   int cnt(int x) { return upper_bound(a, a + n, x) - lower_bound(a, a + n, x); }   int chk() {     for (int i = upper_bound(a, a + n, 1) - a; i < n; i++) {       if (isp[a[i] + 1]) return a[i];     }     return 0;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     sieve();     for (int i : pr) isp[i] = 1;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int y = chk();     int x = cnt(1) + (y > 0);     if (x >= 2) {       cout << x <<   n ;       if (y) {         cout << y <<    ;         x--;       }       for (int i = 1; i <= x; i++) cout <<  1  ;       cout <<   n ;     } else {       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           if (isp[a[i] + a[j]]) {             cout <<  2 n ;             cout << a[i] <<     << a[j] << endl;             return 0;           }         }       }       cout <<  1 n ;       cout << a[0] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   const int maxn = 16;   char tp[maxn];   int r[maxn], b[maxn];   int dp[1 << maxn][2][16 * 16 * 1];   int inf = (int)(1e9);   int go(int msk, int R, int B, int x, int y) {     x = min(x, n * n);     y = min(y, n * n);     if (msk == (1 << n) - 1) return 0;     int &res = dp[msk][y == 0][max(x, y)];     if (res != -1) return res;     res = inf;     for (int i = 0; i < n; i++) {       if (msk & (1 << i)) continue;       int costr = max(0, r[i] - R);       int costb = max(0, b[i] - B);       int needr = max(0, costr - x);       int needb = max(0, costb - y);       int t = max(needr, needb);       res = min(res, t + go(msk | (1 << i), R + (tp[i] ==  R ),                             B + (tp[i] ==  B ), x + t - costr, y + t - costb));     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tp[i] >> r[i] >> b[i];     }     int needr = 0, needb = 0;     for (int i = 0; i < n; i++) {       needr += max(0, r[i] - n);       needb += max(0, b[i] - n);       r[i] = min(r[i], n);       b[i] = min(b[i], n);     }     int t = max(needr, needb);     memset(dp, -1, sizeof(dp));     cout << n + t + go(0, 0, 0, t - needr, t - needb) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int solve(int i, int a, int b, int c) {     if (i == 0) return a + b + c;     if (i == 1) return max((a + b) * c, a + b * c);     if (i == 2) return max(a * (b + c), a * b + c);     return a * b * c;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int a, b, c;     cin >> a >> b >> c;     int ans = 0;     for (int i = 0; i < 4; ++i) {       ans = max(ans, solve(i, a, b, c));       ans = max(ans, solve(i, c, b, a));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k;   string s;   vector<string> ans;   bool all[26];   int main() {     ios_base::sync_with_stdio(0);     cin >> k >> s;     string build =   ;     for (int i = 0; i < s.size(); ++i)       if (!all[s[i] -  a ]) {         if (!build.empty()) ans.push_back(build);         build = s[i];         all[s[i] -  a ] = 1;       } else         build += s[i];     ans.push_back(build);     if (ans.size() < k)       cout <<  NO ;     else {       cout <<  YES             <<   n ;       while (ans.size() > k) {         int last = ans.size() - 1;         string s1 = ans[last], s2 = ans[last - 1];         ans.pop_back();         ans.pop_back();         ans.push_back(s2 + s1);       }       for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const int mxn = 21;   long long n, res;   int m;   struct Node {     long long a;     int b;     bool operator<(const Node& c) const { return b > c.b; }   } nodes[mxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> nodes[i].a >> nodes[i].b;     }     sort(nodes + 1, nodes + 1 + m);     for (int i = 1; i <= m; ++i) {       if (n >= nodes[i].a) {         res += nodes[i].a * nodes[i].b;         n -= nodes[i].a;       } else {         res += n * nodes[i].b;         break;       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n;   vector<pair<int, int> > g[3005];   pair<int, int> es[3005];   int dfs(int v, int p) {     int res = 0;     for (int i = 0; i < g[v].size(); ++i) {       pair<int, int>& e = g[v][i];       if (e.first == p) continue;       res += e.second + dfs(e.first, v);     }     return res;   }   int move(int v, int p, int val) {     int res = val;     for (int i = 0; i < g[v].size(); ++i) {       pair<int, int>& e = g[v][i];       if (e.first == p) continue;       res = min(res, move(e.first, v, val + 1 - e.second * 2));     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(make_pair(b, 0));       g[b].push_back(make_pair(a, 1));       es[i] = make_pair(a, b);     }     int ans = INF;     if (n <= 2) ans = 0;     for (int i = 0; i < n - 1; ++i) {       int A, B;       A = es[i].first;       B = es[i].second;       int sum1 = dfs(A, B), sum2 = dfs(B, A);       ans = min(ans, move(A, B, sum1) + move(B, A, sum2));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[500005], b[500005], dp[500005], t;   vector<long long> c;   void poisk_del(long long z) {     for (int del = 2; del * del <= z; del++) {       if (z % del == 0) c.push_back(del);       while (z % del == 0) {         z /= del;       }     }     if (z != 1) c.push_back(z);   }   void add(int s) {     for (long long mask = 1; mask < (1 << s); mask++) {       long long proz = 1;       int kol = 0;       for (int j = 0; j < s; j++) {         if ((mask & (1 << j)) > 0) {           proz *= c[j];           kol++;         }       }       if (kol % 2 == 1) {         t += dp[proz];         dp[proz]++;       } else {         t -= dp[proz];         dp[proz]++;       }     }   }   void delet(int s) {     for (long long mask = 1; mask < (1 << s); mask++) {       long long proz = 1;       int kol = 0;       for (int j = 0; j < s; j++) {         if ((mask & (1 << j)) > 0) {           proz *= c[j];           kol++;         }       }       if (kol % 2 == 1) {         dp[proz]--;         t -= dp[proz];       } else {         dp[proz]--;         t += dp[proz];       }     }   }   int main() {     long long n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     n = 0;     for (int i = 0; i < q; i++) {       int x;       cin >> x;       x--;       c.clear();       if (b[x] == 0) {         n++;         b[x] = 1;         poisk_del(a[x]);         int s = c.size();         long long ans = (n * (n + 1) / 2) - n;         add(s);         cout << ans - t << endl;       } else {         n--;         b[x] = 0;         poisk_del(a[x]);         int s = c.size();         long long ans = (n * (n + 1) / 2) - n;         delet(s);         cout << ans - t << endl;       }     }   }