malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, l, r, l1 = 0, r1 = 1e9, l2 = 0, r2 = 1e9;     cin >> n;     for (i = 0; i < n; i++) {       cin >> l >> r;       l1 = max(l1, l);       r1 = min(r1, r);     }     cin >> n;     for (i = 0; i < n; i++) {       cin >> l >> r;       l2 = max(l2, l);       r2 = min(r2, r);     }     cout << max(l1 - r2, max(l2 - r1, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char A[200];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; 4 * j <= n; j++) {         if (A[i] ==  * )           if (A[i] == A[i + j])             if (A[i + j] == A[i + 2 * j])               if (A[i + 2 * j] == A[i + 3 * j])                 if (A[i + 3 * j] == A[i + 4 * j]) {                   cout <<  yes ;                   return 0;                 }       }     }     cout <<  no ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n = 4;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (max(a[2], a[3]) - 1 > min(a[2], a[3])) {       cout << -1;       return 0;     }     string ans =   ;     vector<int> cnt(2, 0);     if (a[2] > a[3]) {       for (int i = 0; i < a[2]; i++) {         ans +=  47 ;       }     } else {       if (a[2] == a[3]) {         if (a[0] > a[2]) {           for (int i = 0; i < a[2]; i++) {             ans +=  47 ;           }           ans +=  4 ;         } else {           if (a[1] > a[3]) {             ans +=  7 ;             for (int i = 0; i < a[2]; i++) {               ans +=  47 ;             }           } else {             cout << -1 <<   n ;             return 0;           }         }       } else {         for (int i = 0; i < a[3]; i++) {           ans +=  74 ;         }       }     }     cnt[0] = cnt[1] = 0;     for (char c : ans) {       if (c ==  4 ) cnt[0]++;       if (c ==  7 ) cnt[1]++;     }     if (cnt[0] > a[0] || cnt[1] > a[1]) {       cout << -1 <<   n ;       return 0;     }     a[0] -= cnt[0];     a[1] -= cnt[1];     for (int i = 0; i < (int)ans.size(); i++) {       if (ans[i] ==  4  && a[0] > 0) {         string nans =   ;         for (int j = 0; j <= i; j++) {           nans += ans[j];         }         for (int j = 0; j < a[0]; j++) {           nans +=  4 ;         }         for (int j = i + 1; j < (int)ans.size(); j++) {           nans += ans[j];         }         swap(ans, nans);         break;       }     }     for (int i = (int)ans.size() - 1; i >= 0; i--) {       if (ans[i] ==  7  && a[1] > 0) {         string nans =   ;         for (int j = 0; j <= i; j++) {           nans += ans[j];         }         for (int j = 0; j < a[1]; j++) {           nans +=  7 ;         }         for (int j = i + 1; j < (int)ans.size(); j++) {           nans += ans[j];         }         swap(ans, nans);         break;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long n, q;     cin >> n >> q;     long long* m = (long long*)malloc((n + 2) * sizeof(long long));     for (int i = 0; i < n + 2; i++) {       m[i] = 0;     }     long long* num = (long long*)malloc(n * sizeof(long long));     for (int i = 0; i < n; i++) cin >> num[i];     while (q--) {       long long a, b;       cin >> a >> b;       b++;       m[a]++;       m[b]--;     }     for (int i = 1; i < n + 2; i++) m[i] += m[i - 1];     sort(num, num + n);     sort(m + 1, m + n + 1);     long long answer = 0;     for (int i = 0; i < n; i++) {       answer += num[i] * m[i + 1];     }     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > days;   vector<int> visited;   int main() {     int k, n;     pair<int, int> temp;     cin >> n >> k;     for (int i = 0; i < n; i++) {       temp.first = i + 1;       cin >> temp.second;       days.push_back(temp);     }     for (int i = 0; i < (n - 1); i++) {       for (int j = 0; j < (n - i - 1); j++) {         if (days[j].second > days[j + 1].second) swap(days[j], days[j + 1]);       }     }     int total = 0;     for (int i = 0; i < n; i++) {       if ((total + days[i].second) <= k) {         total += days[i].second;         visited.push_back(days[i].first);       }     }     int sz = visited.size();     for (int i = 0; i < (sz - 1); i++) {       for (int j = 0; j < (sz - i - 1); j++) {         if (visited[j] > visited[j + 1]) swap(visited[j], visited[j + 1]);       }     }     cout << sz << endl;     for (int i = 0; i < sz; i++) cout << visited[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int PASSED_POINT = 0;   void Duxar() {}   void read_int(int &value) {     int sign = 1;     char ch;     value = 0;     while (!isdigit(ch = getchar())) {       (ch ==  - ) && (sign = -1);     }     do {       value = value * 10 + (ch -  0 );     } while (isdigit(ch = getchar()));     value *= sign;   }   int N, M;   vector<int> hero, state;   vector<pair<int, int> > actionTeam;   int nr_bits(int x) {     int ans = 0;     while (x) {       ans += (x & 1);       x >>= 1;     }     return ans;   }   int main() {     int i, mask, act;     string s;     read_int(N);     hero.resize(N);     for (i = 0; i < N; ++i) {       read_int(hero[i]);     }     sort((hero).rbegin(), (hero).rend());     read_int(M);     state.resize((1 << M) - 1);     actionTeam.resize(M);     for (i = 0; i < M; ++i) {       cin >> s >> actionTeam[i].second;       actionTeam[i].first = 0;       if (s[0] ==  p ) actionTeam[i].first = 1;     }     state[(1 << M) - 1] = 0;     for (mask = (1 << M) - 2; mask >= 0; --mask) {       act = nr_bits(mask);       if (actionTeam[act].second == 1) {         state[mask] = -1000000007;         for (i = 0; i < M; ++i) {           if ((mask & (1 << i)) == 0) {             state[mask] = max(state[mask], state[mask | (1 << i)] +                                                actionTeam[act].first * hero[i]);           }         }       } else {         state[mask] = 1000000007;         for (i = 0; i < M; ++i) {           if ((mask & (1 << i)) == 0) {             state[mask] = min(state[mask], state[mask | (1 << i)] -                                                actionTeam[act].first * hero[i]);           }         }       }     }     printf( %d n , state[0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 8e5 + 5, B = 20;   char s[N];   int n, fa[N], len[N], sz[N], a[N], cc[N], np = 1, cnt = 1;   map<int, int> c[N];   int poi[N];   vector<int> e[N];   int st[B][N << 1], dfn[N], pos[N], tim;   int qq[N << 1], pre[N], za[N], zb[N], siz;   bool cmp(int a, int b) { return dfn[a] < dfn[b]; }   void dfs(int u) {     dfn[u] = ++tim;     pos[tim] = u;     st[0][tim] = dfn[u];     for (auto v : e[u]) dfs(v), st[0][++tim] = dfn[u];   }   void bui_st() {     for (int i = 1; i <= B - 1; ++i)       for (int j = 1; j + (1 << i) - 1 <= tim; ++j)         st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);   }   int lca(int a, int b) {     if ((a = dfn[a]) > (b = dfn[b])) swap(a, b);     int d = floor(log2(b - a + 1));     return pos[min(st[d][a], st[d][b - (1 << d) + 1])];   }   void append(int x) {     int p = np;     np = ++cnt;     len[np] = len[p] + 1;     sz[np] = 1;     for (; p && !c[p][x]; p = fa[p]) c[p][x] = np;     if (!p)       fa[np] = 1;     else {       int q = c[p][x];       if (len[q] == len[p] + 1)         fa[np] = q;       else {         int nq = ++cnt;         len[nq] = len[p] + 1;         c[nq] = c[q];         fa[nq] = fa[q];         fa[q] = fa[np] = nq;         for (; c[p][x] == q; p = fa[p]) c[p][x] = nq;       }     }   }   void get_edge() {     for (int i = 1; i <= cnt; ++i) e[fa[i]].push_back(i);   }   void ini2() {     while (siz) za[qq[siz]] = zb[qq[siz]] = 0, --siz;     int la, lb, x;     scanf( %d%d , &la, &lb);     for (int i = 1; i <= la; ++i)       scanf( %d , &x), ++za[qq[++siz] = poi[n + 1 - x]];     for (int i = 1; i <= lb; ++i)       scanf( %d , &x), ++zb[qq[++siz] = poi[n + 1 - x]];     sort(qq + 1, qq + siz + 1, cmp);     for (int i = siz; i >= 2; --i) qq[++siz] = lca(qq[i], qq[i - 1]);     sort(qq + 1, qq + siz + 1, cmp);     siz = unique(qq + 1, qq + siz + 1) - qq - 1;     stack<int> Q;     Q.push(qq[1]);     pre[qq[1]] = 0;     for (int i = 2; i <= siz; ++i) {       for (int t; t = Q.top(), lca(t, qq[i]) != t;) Q.pop();       pre[qq[i]] = Q.top();       Q.push(qq[i]);     }   }   long long solve() {     long long re = 0;     for (int i = siz; i >= 1; --i) {       int x = qq[i];       re += 1ll * za[x] * zb[x] * (len[x] - len[pre[x]]);       za[pre[x]] += za[x];       zb[pre[x]] += zb[x];     }     return re;   }   int main() {     int q;     scanf( %d%d%s , &n, &q, s + 1);     reverse(s + 1, s + n + 1);     for (int i = 1; i <= n; ++i) append(s[i] -  a ), poi[i] = np;     get_edge();     dfs(1);     bui_st();     while (q--) {       ini2();       printf( %lld n , solve());     }   }
#include <bits/stdc++.h>   using namespace std;   inline int Max(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ b; }   inline int Min(int a, int b) { return (((b - a) >> (32 - 1)) & (a ^ b)) ^ a; }   string s;   long long num[2][1000005], len[2][1000005];   long long rnum[2][1000005];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     while (cin >> n) {       cin >> s;       memset(num, 0, sizeof(num));       memset(rnum, 0, sizeof(rnum));       memset(len, 0, sizeof(len));       for (int i = (1); i <= (n); i++) {         for (int j = (0); j <= (1); j++) {           num[j][i] = num[j][i - 1];           len[j][i] = len[j][i - 1];         }         if (s[i - 1] ==  U ) {           num[0][i]++;           len[0][i] += i;           rnum[0][num[0][i]] = i;         } else {           num[1][i]++;           len[1][i] += i;           rnum[1][num[1][i]] = i;         }       }       for (int i = (1); i <= (n); i++) {         long long ret = 0;         int a = num[1][n] - num[1][i];         int b = num[0][i - 1];         if (s[i - 1] ==  U ) {           if (a <= b) {             int ps = rnum[0][b - a];             ret = 2 * ((len[1][n] - len[1][i]) - (len[0][i - 1] - len[0][ps])) +                   n - i + 1;           } else {             int ps = rnum[1][num[1][i] + b + 1];             ret = 2 * ((len[1][ps] - len[1][i]) - len[0][i - 1]) - i;           }         } else {           if (a < b) {             int ps = rnum[0][b - a - 1];             ret = 2 * ((len[1][n] - len[1][i]) - (len[0][i - 1] - len[0][ps])) +                   n + i + 1;           } else {             int ps = rnum[1][num[1][i] + b];             ret = 2 * ((len[1][ps] - len[1][i]) - len[0][i - 1]) + i;           }         }         cout << ret <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 1;   const long long int mod2 = 1e9 + 9;   const long long int maxn = 1e6 + 1;   const int root = 1e7 + 5;   const long long inf = 1e18 + 18;   double pie4 = 3.1415926535;   long long int visit[maxn], a[maxn];   void die() {     cout <<  INFINITE ;     exit(0);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, i, pos;     string s;     cin >> n;     cin >> s;     for (i = 0; i < n; i++) cin >> a[i];     pos = 0;     visit[0] = 0;     while (1) {       if (s[pos] ==  > ) {         pos += a[pos];         if (pos >= n || pos < 0) {           cout <<  FINITE ;           return 0;         }         if (visit[pos]) die();         visit[pos] = 1;       } else {         pos -= a[pos];         if (pos >= n || pos < 0) {           cout <<  FINITE ;           return 0;         }         if (visit[pos]) die();         visit[pos] = 1;       }       if (pos >= n || pos < 0) {         cout <<  FINITE ;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long flag = 0, temp;     temp = b - a % b;     for (long long i = temp; (i + a) <= c; i += b) {       cout << i <<    ;       flag = 1;     }     if (!flag) cout <<  -1 ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   ll ara[300005], ans_ara[300005];   set<ll> st;   vector<pair<ll, ll> > vv;   int main() {     ll n, k, i, j, ans = 0;     scanf( %I64d %I64d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %I64d , &ara[i]);       ans -= (ara[i] * i);       st.insert(i + k);       vv.push_back({ara[i], i});     }     sort(vv.rbegin(), vv.rend());     for (pair<ll, ll> u : vv) {       ll num = *st.lower_bound(u.second);       ans += (num * u.first);       st.erase(st.lower_bound(u.second));       ans_ara[u.second] = num;     }     printf( %I64d n , ans);     for (i = 1; i <= n; i++) {       printf( %I64d  , ans_ara[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   int Abs(int x) { return x < 0 ? -x : x; }   int main() {     int i, N, ans = 0, sum = 0, c = 0, d = 0;     double p;     scanf( %d , &N);     for (i = 0; i < 2 * N; i++) {       scanf( %lf , &p);       int t = ((int)(p * 1000 + 0.1)) % 1000;       if (!t) c++;       sum += t;     }     ans = 1000 * N - sum;     int q = Abs(ans);     for (i = 1; i <= c; i++) {       if (q > Abs(ans - i * 1000)) q = Abs(ans - i * 1000);     }     printf( %d.%03d n , q / 1000, q % 1000);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v(4);     for (int i = 0; i < 4; i++) {       cin >> v[i];     }     if (v[3] > v[2] * 2) {       cout <<  -1 ;       return 0;     }     if (v[2] > v[3] * 2) {       cout <<  -1 ;       return 0;     }     vector<int> s(3);     for (int i = 0; i < 2; i++) {       if (v[i] == v[3]) {         cout <<  -1 ;         return 0;       }       if (v[i] < v[3])         s[i] = v[i];       else         s[i] = v[i] * 2;     }     if (v[2] > v[3])       s[2] = v[2];     else       s[2] = v[3];     for (int i = 0; i < 3; i++) {       cout << s[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   struct Edge {     int u, v, next;   } edge[100000];   int head[105], num[105];   bool visited[105];   int en, cnt, tt;   void add_edge(int u, int v) {     edge[en].u = u;     edge[en].v = v;     edge[en].next = head[u];     head[u] = en++;   }   void DFS1(int u) {     int v;     visited[u] = true;     for (int id = head[u]; id != -1; id = edge[id].next) {       v = edge[id].v;       if (!visited[v]) DFS1(v);     }   }   void DFS2(int u, int p) {     int v;     num[u] = tt++;     visited[u] = true;     for (int id = head[u]; id != -1; id = edge[id].next) {       v = edge[id].v;       if (v == p) continue;       if (!visited[v])         DFS2(v, u);       else if (num[v] < num[u])         cnt++;     }   }   int main() {     int n, m, u, v;     en = 0;     memset(head, 0xff, sizeof head);     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       add_edge(u, v);       add_edge(v, u);     }     memset(visited, false, sizeof visited);     DFS1(1);     cnt = 0;     for (int i = 1; i <= n; i++)       if (!visited[i]) cnt++;     if (cnt)       puts( NO );     else {       memset(visited, false, sizeof visited);       cnt = tt = 0;       DFS2(1, -1);       if (cnt == 1)         puts( FHTAGN! );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     vector<long long> q(n);     for (long long i = 0; i < k; i++) q[k - 1] += a[i];     for (long long i = k; i < n; i++) q[i] = q[i - 1] + a[i] - a[i - k];     vector<pair<long long, long long>> left(n);     left[0] = {q[0], 0};     for (long long i = 1; i < n; i++) {       if (q[i] > left[i - 1].first)         left[i] = {q[i], i};       else         left[i] = left[i - 1];     }     long long ans = 0, l = 0, r = 0;     for (long long i = 2 * k - 1; i < n; i++) {       long long first_ans = q[i];       pair<long long, long long> second_ans = left[i - k];       if (first_ans + second_ans.first > ans) {         ans = first_ans + second_ans.first;         l = second_ans.second;         r = i;       }     }     l++, l++, r++, r++;     l -= k, r -= k;     cout << l <<     << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fun() {     int n, k;     cin >> n >> k;     map<string, int> m;     string s;     string a[n];     for (int i = 0; i < n; i++) {       cin >> s;       a[i] = s;       m[s]++;     }     int c = 0;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         s =   ;         for (int p = 0; p < k; p++) {           if (a[i][p] == a[j][p])             s += a[i][p];           else             s += (char)( S  +  E  +  T  - a[i][p] - a[j][p]);         }         c += m[s];       }     cout << c / 3 << endl;   }   int main() {     { fun(); }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     vector<long long> v;     long long h = 1, m;     while (h <= 25820) {       m = ((3 * h + 1) * h) / 2;       v.push_back(m);       h++;     }     for (long long j = 0; j < t; j++) {       long long n, pos = 0;       cin >> n;       for (long long i = 0; i < v.size(); i++) {         if (n <= v[i]) {           pos = i;           break;         }       }       long long ans = 0;       while (n > 0 && pos >= 0) {         ans += (n / v[pos]);         n %= v[pos];         pos--;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 111;   int op[123456], val[123456], b[123456];   vector<int> x;   vector<int>::iterator it;   long long sum[333][5];   int k[333], sumk;   map<int, int> ma;   char s[5];   int main(void) {     int i, j, n;     int no, ni;     long long res;     scanf( %d , &n);     x.clear();     for (i = 0; i < n; i++) {       scanf(  %s , s);       if (s[0] ==  a )         op[i] = 1;       else if (s[0] ==  d )         op[i] = 2;       else         op[i] = 3;       if (op[i] < 3) {         scanf( %d , &val[i]);         x.push_back(val[i]);       }     }     sort(x.begin(), x.end());     it = unique(x.begin(), x.end());     x.resize(it - x.begin());     for (i = 0; i < x.size(); i++) ma[x[i]] = i;     memset(sum, 0, sizeof(sum));     memset(k, 0, sizeof(k));     memset(b, 0, sizeof(b));     for (i = 0; i < n; i++) {       if (op[i] == 1) {         b[ma[val[i]]]++;         no = ma[val[i]] / 320;         k[no]++;         for (j = 0; j < 5; j++) sum[no][j] = 0;         j = 0;         for (ni = 0; ni < 320; ni++) {           if (b[no * 320 + ni]) {             sum[no][j] = sum[no][j] + x[no * 320 + ni];             j++;             if (j == 5) j = 0;           }         }       } else if (op[i] == 2) {         b[ma[val[i]]]--;         no = ma[val[i]] / 320;         k[no]--;         for (j = 0; j < 5; j++) sum[no][j] = 0;         j = 0;         for (ni = 0; ni < 320; ni++) {           if (b[no * 320 + ni]) {             sum[no][j] = sum[no][j] + x[no * 320 + ni];             j++;             if (j == 5) j = 0;           }         }       } else if (op[i] == 3) {         res = 0;         sumk = 2;         for (no = 0; no < 320; no++) {           res += sum[no][4 - sumk % 5];           sumk += k[no];         }         printf( %I64d n , res);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a;     int n, t;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t;       a.push_back(t);     }     sort(a.begin(), a.end());     for (int i = 0; i < n / 2; i++) cout << a[i] <<     << a[n - i - 1] <<    ;     if (n % 2 == 1) cout << a[n / 2];     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000000];   int main() {     long long i, num, res = 0, n, k, rem, fl = 0;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 1; i < n; i++) {       if ((a[i] - a[0]) % k != 0) {         fl = 1;         break;       } else {         rem = (a[i] - a[0]) / k;         res += rem;       }     }     if (fl) {       cout << -1 << endl;     } else       cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[101], piller;   int main() {     cin >> n;     for (auto i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (auto i = 0; i < n; i++) {       if (piller * a[i] + piller <= i) piller++;     }     cout << piller;   }
#include <bits/stdc++.h>   using namespace std;   int t[3000];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       t[s[i]] += 1;     }     int lk = t[ A ];     for (char c =  A ; c <  A  + k; c++) {       if (t[c] < lk) {         lk = t[c];       }     }     cout << lk * k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, A[100005];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     int mid = n / 2;     long long res = 0;     for (int i = 0; i < mid; i++) {       res = (res + A[i] * A[n - 1 - i] * 2) % 10007;     }     if (n & 1) res = (res + A[mid] * A[mid]) % 10007;     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, next;   } a[1010000];   int len, last[510000];   inline void ins(int x, int y) {     len++;     a[len].x = x;     a[len].y = y;     a[len].next = last[x];     last[x] = len;   }   int tt[510000];   int col[510000];   int cnt, belong[510000];   bool dfs(int x, int c) {     if (col[x] != -1) return col[x] == c;     col[x] = c;     belong[x] = cnt;     for (int k = last[x]; k > 0; k = a[k].next) {       int y = a[k].y;       if (tt[x] != tt[y]) continue;       if (!dfs(y, 1 - c)) return false;     }     return true;   }   bool b[510000];   int tg[510000];   struct edge {     int x, y, c, next;     bool bk;   } e[1010000];   map<int, map<int, int>> east;   inline void ins(int x, int y, int c) {     len++;     e[len].x = x;     e[len].y = y;     e[len].c = c;     e[len].next = east[x][tg[y]];     east[x][tg[y]] = len;     e[len].bk = true;   }   int Al, Be, Ga;   bool De;   void color(int x, int c) {     if (col[x] < Ga) {       col[x] = c;       int ty = tg[x] == Al ? Be : Al;       for (int k = east[x][ty]; k > 0; k = e[k].next) {         int y = e[k].y;         e[k].bk = false;         color(y, c ^ e[k].c);       }     } else if (col[x] == (c ^ 1))       De = false;   }   set<pair<int, int>> S;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &tt[i]);     len = 0;     memset(last, 0, sizeof(last));     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       ins(x, y);       ins(y, x);     }     memset(col, -1, sizeof(col));     memset(b, true, sizeof(b));     cnt = 0;     for (int i = 1; i <= n; i++) {       if (col[i] == -1 && b[tt[i]]) {         cnt++;         if (!dfs(i, 0)) {           k--;           b[tt[i]] = false;         }       }     }     for (int i = 1; i <= n; i++) tg[belong[i]] = tt[i];     len = 0;     for (int i = 1; i <= m; i++) {       int x = a[i * 2].x, y = a[i * 2].y;       if (b[tt[x]] && b[tt[y]] && tt[x] != tt[y]) {         ins(belong[x], belong[y], col[x] ^ col[y]);         ins(belong[y], belong[x], col[x] ^ col[y]);       }     }     memset(col, -1, sizeof(col));     Ga = 0;     for (int i = 1; i <= len; i += 2) {       int x = e[i].x, y = e[i].y;       if (tg[x] > tg[y]) x ^= y ^= x ^= y;       if (e[i].bk) {         Al = tg[x];         Be = tg[y];         De = true;         color(x, Ga);         if (!De) S.insert({tg[x], tg[y]});         Ga += 2;       }     }     printf( %lld n , 1ll * k * (k - 1) / 2 - S.size());     return 0;   }