malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long nx2(long long n) {     long long p = 1;     if (n && !(n & (n - 1))) return n;     while (p < n) p <<= 1;     return p;   }   namespace Debug {   void dout() { cerr <<   n ; }   template <typename Head, typename... Tail>   void dout(Head H, Tail... T) {     cerr <<     << H;     dout(T...);   }   template <typename T>   void douta(const T *a, int n) {     cerr <<   n[ ;     for (int i = 0; i < n; i++) {       cerr <<     << a[i];     }     cerr <<   ] n ;   }   template <typename T>   void doutaa(T **b, int r, int c) {     for (int i = 0; i < r; i++) {       cerr <<  [ ;       for (int j = 0; j < c; j++) {         cerr <<     << b[i][j];       }       cerr <<   ] n ;     }   }   template <typename T>   void dout(const vector<T> v) {     cerr <<   n[ ;     for (T i : v) {       cerr <<     << i;     }     cerr <<   ] n ;   }   template <typename T>   void dout(const vector<vector<T>> v) {     cerr <<   n ;     for (vector<T> u : v) {       cerr <<  [ ;       for (T i : u) {         cerr <<     << i;       }       cerr <<   ] n ;     }   }   template <typename F, typename S>   void dout(const vector<pair<F, S>> u) {     cerr <<   n ;     for (pair<F, S> v : u) {       cerr <<  [   << v.first <<     << v.second <<   ] n ;     }   }   }  // namespace Debug   using namespace Debug;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     vector<vector<vector<long long>>> adj(n);     vector<long long> si(k);     for (long long i = 0; i < m + k; i++) {       if (i < m) {         long long u, v, x;         cin >> u >> v >> x, --u, --v;         adj[u].push_back({v, x, i});         adj[v].push_back({u, x, i});       } else {         long long s, y;         cin >> s >> y, --s;         si[i - m] = s;         adj[0].push_back({s, y, i});         adj[s].push_back({0, y, i});       }     }     vector<long long> vis(n), vis1(n), dist(n, INT_MAX);     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         pq;     dist[0] = 0;     pq.push({dist[0], 0});     vis[0] = 0;     while (!pq.empty()) {       long long u = pq.top().second;       pq.pop();       if (vis1[u]) {         continue;       }       vis1[u] = 1;       for (auto vwi : adj[u]) {         long long v = vwi[0], w = vwi[1], i = vwi[2];         if (v == 0) {           continue;         }         if (dist[v] > dist[u] + w) {           vis[v] = i;           dist[v] = dist[u] + w;           pq.push({dist[v], v});         } else if (dist[v] == dist[u] + w && vis[v] >= m && i < m) {           vis[v] = i;           pq.push({dist[v], v});         }       }     }     long long res = 0;     for (long long i = 0; i < k; i++) {       res += (vis[si[i]] != i + m);     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long x, y, u = 0, v = 0;   vector<pair<long long, long long> > visited;   void move(char c) {     if (c ==  U )       v++;     else if (c ==  D )       v--;     else if (c ==  L )       u--;     else       u++;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> x >> y;     if (x == 0 && y == 0) {       cout <<  Yes ;       return 0;     }     string s;     cin >> s;     for (long long i = 0; i < (long long)s.size(); ++i) {       move(s[i]);       if (u == x && v == y) {         cout <<  Yes ;         return 0;       }       visited.push_back(make_pair(u, v));     }     if (u == 0 && v == 0) {       cout <<  No ;       return 0;     }     long long h_shift = u, v_shift = v;     for (long long i = 0; i < (long long)s.size(); ++i) {       move(s[i]);       if (u == x && v == y) {         cout <<  Yes ;         return 0;       }       long long u_ref = x - visited[i].first;       long long v_ref = y - visited[i].second;       long long p = (h_shift ? u_ref % h_shift : u_ref);       long long q = (v_shift ? v_ref % v_shift : v_ref);       if (((u_ref < 0 && h_shift > 0) || (u_ref > 0 && h_shift < 0)) ||           ((v_ref < 0 && v_shift > 0) || (v_ref > 0 && v_shift < 0)))         continue;       if (p == 0 && q == 0 && (u_ref * v_shift == v_ref * h_shift)) {         cout <<  Yes ;         return 0;       }     }     cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)5e5 + 123, inf = 1e9, mod = 1e9 + 7, M = 511;   const long long INF = (long long)1e18;   int n, m, k, x, y, d, t, e;   long long A[M][M], a[2][M][M];   vector<pair<int, int> > ex[M][M], ey[M][M];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);     cin >> n >> m >> k;     for (int i = 1; i <= k; ++i) {       cin >> x >> y >> d >> t >> e;       if (x + y >= t && ((x + y) - t) % 4 == 0) {         A[x][y] += e;         if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) {           ex[x + d][y].push_back(make_pair(d, e));         }         if (x + y + d >= t && ((x + y + d) - t) % 4 == 3) {           ey[x][y + d].push_back(make_pair(d, e));         }       }       if (x + d + y - d >= t && ((x + d + y - d) - t) % 4 == 1) {         A[x + d][y - d] += e;         if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) {           ey[x + d][y].push_back(make_pair(d, e));         }       }       if (x + d + y >= t && ((x + d + y) - t) % 4 == 2) {         A[x + d][y] += e;       }       if (x + y + d >= t && ((x + y + d) - t) % 4 == 3) {         A[x][y + d] += e;       }     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) a[0][i][j] = a[1][i][j] = INF;     a[0][0][0] = a[1][0][0] = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         sort(ex[i][j].begin(), ex[i][j].end());         sort(ey[i][j].begin(), ey[i][j].end());       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         long long cost = a[0][i][j];         for (int k = 1; k + i < n; ++k) {           cost += A[i + k][j];           for (int w = 0; w < (int)ex[i + k][j].size(); ++w) {             if (i + k - ex[i + k][j][w].first >= i)               cost -= ex[i + k][j][w].second;             else               break;           }           a[1][i + k][j] = min(a[1][i + k][j], cost);         }         cost = a[1][i][j];         for (int k = 1; k + j < m; ++k) {           cost += A[i][j + k];           for (int w = 0; w < (int)ey[i][j + k].size(); ++w) {             if (j + k - ey[i][j + k][w].first >= j)               cost -= ey[i][j + k][w].second;             else               break;           }           a[0][i][j + k] = min(a[0][i][j + k], cost);         }       }     cout << min(a[0][n - 1][m - 1], a[1][n - 1][m - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pt {     double x, y;     pt(const double &_x = 0.0, const double &_y = 0.0) : x(_x), y(_y) {}   };   pt operator+(const pt &a, const pt &b) { return pt(a.x + b.x, a.y + b.y); }   int n, m, id[102][5];   pt verts[500], radius, pent[2][5], centre;   const double PI = 3.141592653589793L;   const double D2R = PI / 180.0L;   inline int vertid(const int &i, const int &j) { return id[i][j] + 1; }   inline int addvert(const pt &p) {     verts[m] = p;     return m++;   }   int main() {     scanf( %d , &n);     double radius = 10.0L * sinl(54.0L * D2R) / sinl(72.0L * D2R);     for (int i = 0; i < (5); ++i) {       double theta = i * 2.0L * 3.141592653589793L / 5.0L;       pent[0][i].x = radius * cosl(theta);       pent[0][i].y = radius * sinl(theta);       pent[1][i].x = -pent[0][i].x;       pent[1][i].y = pent[0][i].y;     }     memset(id, -1, sizeof id);     for (int i = 0; i < (n); ++i) {       bool odd = i & 1;       if (i) centre = centre + pent[!odd][0] + pent[!odd][1];       for (int j = 0; j < (5); ++j)         if (id[i][j] == -1) {           id[i][j] = addvert(centre + pent[odd][j]);           if (j == 0) id[i + 1][4] = id[i][j];           if (j == 1) id[i + 1][0] = id[i + 2][4] = id[i][j];         }     }     printf( %d n , m);     for (int i = 0; i < (m); ++i)       printf( %.15lf %.15lf n , verts[i].x, verts[i].y);     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (5); ++j)         printf( %d%c , vertid(i, j), (j < 4) ?     :   n );     printf( %d , vertid(0, 4));     for (int i = 0; i < (n); ++i)       printf(  %d %d %d , vertid(i, 1), vertid(i, 3), vertid(i, 0));     for (int i = (n)-1; i >= 0; --i) printf(  %d %d , vertid(i, 2), vertid(i, 4));     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pi = pair<int, int>;   using pll = pair<ll, ll>;   vector<ll> primes = {       2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,  43,       47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, 103, 107,       109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,       191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,       269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,       353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,       439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,       523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613,       617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,       709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,       811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,       907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};   const ll XMAX = 1e9;   const ll QMAX = XMAX * XMAX;   const ll MAX_QUERIES = 22;   int i = 0;   int queries = 0;   ll query(ll Q) {     queries++;     cout <<  ?   << Q << endl;     ll g;     cin >> g;     return g;   }   vector<ll> find_factors() {     if (queries == MAX_QUERIES) return {};     ll Q = 1;     int j = i;     for (; j < (int)primes.size() && Q <= QMAX / primes[j]; j++) Q *= primes[j];     ll g = query(Q);     vector<ll> ans;     for (int k = i; k < j; k++)       if (g % primes[k] == 0) ans.push_back(primes[k]);     i = j;     return ans;   }   ll max_power(ll p) {     ll ans = 1;     while (ans <= XMAX / p) ans *= p;     return ans;   }   ll count_power(ll n, ll p) {     ll ans = 0;     for (; n % p == 0; n /= p) ans++;     return ans;   }   ll count_divisors(vector<ll>& factors) {     if (factors.empty()) return 1;     ll ans = 1;     for (int k = 0; k < (int)factors.size() && queries < MAX_QUERIES; k += 2) {       ll Q = max_power(factors[k]);       if (k + 1 < (int)factors.size()) Q *= max_power(factors[k + 1]);       ll g = query(Q);       ans *= 1 + count_power(g, factors[k]);       if (k + 1 < (int)factors.size()) ans *= 1 + count_power(g, factors[k + 1]);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cout << setprecision(12);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       i = 0;       queries = 0;       ll divisors = 1;       while (i < (int)primes.size() && queries < MAX_QUERIES) {         vector<ll> factors = find_factors();         divisors *= count_divisors(factors);       }       cout <<  !   << max(divisors * 2, divisors + 7) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     vector<int> v[30];     for (int i = 0; i < n; i++) {       v[s[i] - 96].push_back(i);     }     int m;     cin >> m;     while (m--) {       string a;       cin >> a;       int h[30] = {0};       for (int i = 0; i < a.size(); i++) {         h[a[i] - 96]++;       }       int ma = -1;       for (int i = 1; i <= 26; i++) {         if (h[i] != 0) {           ma = max(ma, v[i][h[i] - 1]);         }       }       cout << ma + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     string s, t;     cin >> s >> t;     int count = 0;     int i = s.length() - 1;     int j = t.length() - 1;     while (s[i] == t[j] && i >= 0 && j >= 0) {       i -= 1;       j -= 1;       count += 1;     }     cout << (s.length() + t.length() - 2 * count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1010];   int main() {     int n, i;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int ans = 0;     int x;     for (int i = 0; i < n; i++) {       x = 1;       if (a[i] >= 0) {         ans++;         for (int j = i + 1; j < n; j++) {           if (a[j] >= x) {             x++;             a[j] = -1;           }         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long tmp[1000005];   long long n;   void get_tmp() {     tmp[1] = -1;     for (int i = 1; i <= n; i++) tmp[i + 1] = (tmp[i] + 1) * i % mod;   }   long long a[1000005];   int main() {     cin >> n;     get_tmp();     a[1] = 1;     for (int i = 1; i <= n; i++) a[i + 1] = (a[i] * (i + 1) % mod + tmp[i]) % mod;     cout << a[n] * n % mod << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops )   using namespace std;   const int max_n = 100011, inf = 1000111222;   const int mod = 1000000007;   int n, m, fenv[333][333];   map<int, vector<pair<int, int>>> mp;   pair<int, int> a[max_n];   int sum(int tt[], int r) {     int result = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) result += tt[r];     return result;   }   void inc(int t[], int i, int delta) {     for (; i < m; i = (i | (i + 1))) t[i] += delta;   }   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.second == b.second) {       return a.first > b.first;     }     return a.second < b.second;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> m;       mp.clear();       for (int i = 0; i < n; ++i) {         for (int q = 0; q < m; ++q) {           fenv[i][q] = 0;         }       }       for (int i = 0; i < n * m; ++i) {         cin >> a[i].first;         a[i].second = i;       }       sort(a, a + n * m);       int pos = 0;       for (int i = 0; i < n * m; ++i) {         mp[a[i].first].push_back({pos % m, pos / m});         ++pos;         swap(a[i].first, a[i].second);       }       for (auto& a : mp) {         sort(a.second.begin(), a.second.end(), cmp);         reverse(a.second.begin(), a.second.end());       }       sort(a, a + n * m);       int ans = 0;       for (int i = 0; i < n * m; ++i) {         int x = mp[a[i].second].back().second;         int y = mp[a[i].second].back().first;         mp[a[i].second].pop_back();         ans += sum(fenv[x], y);         inc(fenv[x], y, 1);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int64_t inf = (int64_t)1e18;   vector<int64_t> a[2], g[2];   void dfs(int obj, int idx, int64_t cur) {     if (idx == a[obj].size()) {       g[obj].push_back(cur);       return;     }     dfs(obj, idx + 1, cur);     while (a[obj][idx] <= inf / cur) cur *= a[obj][idx], dfs(obj, idx + 1, cur);   }   int order(int64_t x) {     int res = 0;     int i = g[0].size() - 1, j = 0;     for (; i >= 0; i--) {       for (; j < g[1].size() && g[1][j] <= x / g[0][i]; j++)         ;       res += j;     }     return res;   }   int main(void) {     int n, k;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int p;       scanf( %d , &p);       a[i & 1].push_back(p);     }     scanf( %d , &k);     dfs(0, 0, 1LL);     sort(g[0].begin(), g[0].end());     dfs(1, 0, 1LL);     sort(g[1].begin(), g[1].end());     int64_t low = 0LL;     int64_t high = inf;     while (low <= high) {       int64_t mid = (low + high) / 2;       int ord = order(mid);       if (ord < k)         low = mid + 1;       else         high = mid - 1;     }     printf( %I64d n , low);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ans;   pair<int, int> ar1[2100];   int ar2[2100];   int n, x;   long long anss = 0;   void findPlace(int i);   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       ar1[i].first = x;     }     for (int i = 1; i <= n; i++) {       cin >> ar2[i];       for (int j = 1; j <= n; j++)         if (ar1[j].first == ar2[i]) {           ar1[j].second = i;           break;         }     }     for (int i = 1; i <= n; i++)       while (ar1[i].first != ar2[i]) findPlace(i);     cout << anss << endl;     cout << ans.size() << endl;     for (vector<pair<int, int> >::iterator i = ans.begin(); i != ans.end(); i++)       printf( %d %d n , (*i).first, (*i).second);     cin >> n;     return 0;   }   void findPlace(int pos) {     int dest = ar1[pos].second, curPos = pos;     for (int i = pos + 1; i <= dest; i++) {       if (ar1[i].second <= curPos) {         swap(ar1[i], ar1[curPos]);         ans.push_back(make_pair(i, curPos));         anss += (i - curPos);         curPos = i;       } else if (ar1[i].second > i) {         findPlace(i);         i--;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     char a[n][n];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) a[i][j] =  * ;     int begin, end;     begin = end = n / 2;     for (int i = 0; i <= n / 2; i++) {       for (int j = begin; j <= end; j++) a[i][j] =  D ;       begin--;       end++;     }     begin += 2;     end -= 2;     for (int i = n / 2 + 1; i < n; i++) {       for (int j = begin; j <= end; j++) a[i][j] =  D ;       begin++;       end--;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) printf( %c , a[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c = 0, x;     int max, min;     cin >> n >> m >> min >> max;     for (int i = 0; i < m; i++) {       cin >> x;       if (x > min && x < max) c++;       if (x < min || x > max) return cout <<  Incorrect , 0;     }     if (c + 2 <= n)       cout <<  Correct ;     else       cout <<  Incorrect ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans, ansIndex, n, s, x, val, res = 2000000006;   int main() {     scanf( %d%d%d , &n, &s, &x);     int nxt = s, m = min(800, n);     for (int i = 0; i < m; i++) {       printf( ? %d n , (rand() * 107 + rand()) % n + 1);       fflush(stdout);       scanf( %d %d , &val, &nxt);       if (val < x && val > ans) {         ans = val;         ansIndex = nxt;       }     }     nxt = ansIndex == 0 ? s : ansIndex, val = -1;     while (nxt != -1 && val < x) {       printf( ? %d n , nxt);       fflush(stdout);       scanf( %d %d , &val, &nxt);       if (val >= x) res = min(res, val);     }     printf( ! %d n , 2000000006 == res ? -1 : res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool life[100005];   int num[100005];   int pre[100005];   int main() {     int now = 0, temp = 0;     int n;     long long ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       pre[i] = now;       now = i;       while (num[i] + 1 > temp) {         temp++;         life[now] = 1;         now = pre[now];       }     }     temp = 0;     for (int i = 1; i <= n; i++) {       if (life[i]) temp++;       ans += temp - 1 - num[i];     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool func(char a, char b) {     if (a + 1 == b - 1) return true;     if (a + 1 == b + 1) return true;     if (a - 1 == b - 1) return true;     if (a - 1 == b + 1) return true;     return false;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       for (int i = 0, j = s.size() - 1; i < j; i++, j--) {         if (!func(s[i], s[j])) goto label;       }       cout <<  YES  << endl;       continue;     label:       cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   template <class T>   typename T::value_type arr_sum(const T& v, int n) {     typename T::value_type sum = 0;     for (int i = (0); i < (n); ++i) sum += v[i];     return sum;   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 0;       return 0;     }     list<int> a;     a.push_back(0);     for (int i = (0); i < (n); ++i) {       int x;       cin >> x;       a.push_back(x);     }     a.push_back(0);     auto i = a.begin();     auto j = i;     ++j;     auto k = j;     ++k;     long long res = 0;     while (k != a.end()) {       if (*i >= *j && *j <= *k) {         res += min(*i, *k);         a.erase(j);         j = i;         --i;       } else {         ++i;         ++j;         ++k;       }     }     i = a.begin();     j = i;     ++j;     k = j;     ++k;     a.pop_back();     a.pop_front();     while (a.size() >= 3) {       if (a.front() < a.back()) {         res += a.front();         a.pop_front();       } else {         res += a.back();         a.pop_back();       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int base = 13331;   const int MOD = 1e9 + 7;   const int MOD1 = 998244353;   const int mod = 65536;   const long long INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int N = 1e6 + 10, M = 20000010;   const int NN = 3e5 + 10;   inline long long read() {     char ch = getchar();     long long f = 1, x = 0;     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, k, idx = 0;   int c[N], ex[N], ey[N];   bool vis[N];   map<pair<int, int>, int> mp;   vector<int> ve[N];   struct Undo_Dsu {     stack<pair<int, int> > st;     int fa[N], siz[N];     void init() {       while (!st.empty()) st.pop();       for (int i = 1; i <= 2 * n + 1; i++) fa[i] = i, siz[i] = 1;     }     int getrt(int x) { return x == fa[x] ? x : getrt(fa[x]); }     bool merge(int u, int v) {       int fax = getrt(u), fay = getrt(v);       if (fax == fay) return false;       if (siz[fax] > siz[fay]) swap(fax, fay), swap(u, v);       fa[fax] = fay, siz[fay] += siz[fax];       st.push({fax, fay});       return true;     }     void undo() {       pair<int, int> no = st.top();       fa[no.first] = no.first;       siz[no.second] -= siz[no.first];       st.pop();     }   } dsu;   int main() {     n = read(), m = read(), k = read();     dsu.init();     for (int i = 1; i <= n; i++) c[i] = read();     int u, v;     long long cnt = k;     for (int i = 1; i <= m; i++) {       u = read(), v = read();       ex[i] = u, ey[i] = v;       if (c[u] == c[v]) {         int fx = dsu.getrt(u);         int fy = dsu.getrt(v);         if (fx == fy) {           if (!vis[c[u]]) {             vis[c[u]] = 1;             --cnt;           }         } else           dsu.merge(u, v + n), dsu.merge(v, u + n);       }     }     long long ans = cnt * (cnt - 1) / 2;     for (int i = 1; i <= m; i++) {       if (c[ex[i]] != c[ey[i]] && !vis[c[ex[i]]] && !vis[c[ey[i]]]) {         int lc = c[ex[i]], rc = c[ey[i]];         if (lc > rc) swap(lc, rc);         int id = mp[make_pair(lc, rc)];         if (!id) id = mp[make_pair(lc, rc)] = ++idx;         ve[id].push_back(i);       }     }     for (auto in : mp) {       int w = in.second;       int now = dsu.st.size();       for (auto v : ve[w]) {         int uid = ex[v], vid = ey[v];         int fu = dsu.getrt(uid), fv = dsu.getrt(vid);         if (fu == fv) {           --ans;           break;         }         dsu.merge(uid, vid + n);         dsu.merge(vid, uid + n);       }       while (dsu.st.size() > now) dsu.undo();     }     printf( %lld n , ans);     return 0;   }