malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long tu[2000001], tu1[2000001];   int main() {     long long n, m;     cin >> n;     long long q;     map<long long, long long> wp;     for (long long a = 1; a <= n; a++) {       scanf( %I64d , &q);       wp[q]++;     }     cin >> m;     for (long long a = 1; a <= m; a++) scanf( %I64d , &tu[a]);     for (long long a = 1; a <= m; a++) scanf( %I64d , &tu1[a]);     long long gx = -1, my = -1;     long long zuobiao = -1;     for (long long a = 1; a <= m; a++) {       if (wp[tu[a]] > gx || wp[tu[a]] == gx && wp[tu1[a]] >= my) {         gx = wp[tu[a]];         zuobiao = a;         my = wp[tu1[a]];       }     }     cout << zuobiao << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, i;     cin >> t;     while (t--) {       cin >> n;       if (n == 1) {         cout <<  -1 n ;         continue;       }       cout <<  2 ;       for (i = 2; i <= n; i++) {         cout <<  9 ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   const long long INF = 1e9 + 7;   const long long maxn = 2e5 + 7;   using namespace std;   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long ans = 0;     for (long long z = c; z < d + 1; z++) {       long long r1 = z - c + 1;       long long r2 = z - b + 1;       if (r1 > b) continue;       long long sStart = 1;       if (r2 < b) {         sStart += (b - r2);       }       r2 = max(r2, b);       long long numTerms = c - r2 + 1;       long long whichTermGreater = b - a + 2 - sStart;       long long numGreater = max(min(numTerms - whichTermGreater, numTerms), 0LL);       ans += numGreater * (b - a + 1);       numTerms -= numGreater;       long long finalTerm = sStart + numTerms - 1;       long long summn = (numTerms) * (sStart + finalTerm);       summn /= 2;       ans += summn;     }     cout << ans <<   n ;   }   int main(int argc, char** argv) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5, mod = 1e9 + 7;   int koszt[31], tmp[31];   int main() {     int a, b, c, d, e, f, g, z, k, n, m, q;     scanf( %d , &n);     for (a = 1; a <= 30; a++) koszt[a] = 1000000000;     while (n--) {       scanf( %d , &a);       if (a == 1000) {         for (b = 0; b <= 30; b++) tmp[b] = 1000000000;         for (b = 1; b <= 30; b++) tmp[b] = koszt[b - 1] + 1000;         for (b = 0; b <= 30; b++)           for (c = b + 1; c <= 30 && c - b <= 10; c++)             tmp[b] = min(tmp[b], koszt[c] + 1000 - (c - b) * 100);       } else {         for (b = 0; b <= 30; b++) tmp[b] = 1000000000;         for (b = 2; b <= 30; b++) tmp[b] = koszt[b - 2] + 2000;         for (b = 0; b <= 30; b++)           for (c = b + 1; c <= 30 && c - b <= 20; c++)             tmp[b] = min(tmp[b], koszt[c] + 2000 - (c - b) * 100);       }       for (b = 0; b <= 30; b++) koszt[b] = tmp[b];     }     b = koszt[0];     for (a = 1; a <= 30; a++) b = min(b, koszt[a]);     printf( %d , b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> m;   int main() {     int long long n;     cin >> n;     int long long arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     int long long a = 0, b = 0;     if (arr[0] == arr[n - 1]) {       cout << 0 <<     << n * (n - 1) / 2 << endl;     } else {       for (int i = 0; i < n; i++) {         if (arr[i] == arr[0]) a++;         if (arr[i] == arr[n - 1]) b++;       }       cout << arr[n - 1] - arr[0] <<     << a * b << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> xi;   vector<long long int> hi;   int main() {     long long int n, x, h, ans = 1, temp, temp1, curr, i;     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld %lld , &x, &h);       xi.push_back(x);       hi.push_back(h);     }     curr = xi[0];     for (i = 1; i < n; i++) {       temp = xi[i] - hi[i];       temp1 = xi[i] + hi[i];       if (temp > curr) {         ans++;         curr = xi[i];       } else {         if (i + 1 < n && temp1 < xi[i + 1]) {           ans++;           curr = temp1;         } else {           if (i + 1 == n) ans++;           curr = xi[i];         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void preKmp(char *src, int m, int *rule) {     int i = 0, j = -1;     rule[0] = j;     while (i < m) {       while (j != -1 && src[j] != src[i]) j = rule[j];       i++, j++;       if (j >= m)         rule[i] = rule[j - 1];       else         rule[i] = j;     }   }   int recount = 0;   void kmp(char *src, int m, char *dest, int n) {     int rule[10005];     preKmp(src, m, rule);     int i = 0, j = 0;     while (i < n) {       while (j != -1 && src[j] != dest[i]) {         j = rule[j];       }       i++, j++;       if (j == m) {         recount++;         j = rule[j];       }     }   }   char Reg[10005], ori[1000005];   char os[100][300], a[500], temp[500];   int l[100], r[100], n, len, le[100];   int main() {     set<string> now;     set<string>::iterator iter;     bool flag;     int ans = 0, i, j, k;     while (scanf( %s , a) != EOF) {       now.clear();       scanf( %d , &n);       for (i = 1; i <= n; i++) {         scanf( %s%d%d , os[i], &l[i], &r[i]);         le[i] = strlen(os[i]);       }       len = strlen(a);       ans = 0;       for (i = 0; i < len; i++)         for (j = i; j < len; j++) {           flag = true;           for (k = 1; k <= n; k++) {             recount = 0;             kmp(a + i, j - i + 1, os[k], le[k]);             if (recount < l[k] || recount > r[k]) {               flag = false;               break;             }           }           if (flag) {             for (k = i; k <= j; k++) temp[k - i] = a[k];             temp[k - i] =   0 ;             string wc = temp;             iter = now.find(wc);             if (iter == now.end()) {               now.insert(wc);               ans++;             }           }         }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   int n, a[N], vis[N];   int main() {     scanf( %d , &n);     int64_t ans = 0;     int f = 0, g = 1, pos = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ans += abs(a[i] - i);       if (a[i] == 1) continue;       if (a[i] > i)         ++f, ++vis[a[i] - i];       else         ++g, ++vis[a[i] - i + n];     }     int64_t ret = ans;     for (int k = 1; k < n; ++k) {       ret -= abs(n + 1 - a[n - k + 1]);       ret += abs(1 - a[n - k + 1]);       ret += -f + g;       if (a[n - k + 1] != 1) ++f, --g;       f -= vis[k];       g += vis[k];       if (ret < ans) ans = ret, pos = k;     }     printf( %lld %d n , ans, pos);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a[1010], maxx = -1, res[1010], ans = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (res[a[i]] > 0)         res[a[i]]++;       else         res[a[i]] = 1;       maxx = max(maxx, res[a[i]]);     }     maxx = maxx + ((k - (maxx % k)) % k);     for (int i = 1; i < 101; i++) {       if (res[i] > 100 || res[i] < 1) continue;       ans += (maxx - res[i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long a, b, sum = 0;       cin >> a >> b;       while (a > 0 && b > 0) {         if (a < b) swap(a, b);         sum += a / b;         a = a - b * (a / b);       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     int a[n + 1];     a[0] = 0;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     if (n == 2) {       cout <<  NO ;       return 0;     }     for (i = 1; i <= n; i++) {       int x;       x = a[i];       x = a[x];       x = a[x];       if (x == i) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   std::ostream& operator<<(std::ostream& str, const std::vector<T>& v) {     str <<  [ ;     for (auto n : v) str << n <<  ,  ;     str <<  ] ;     return str;   }   template <typename K, typename V>   std::ostream& operator<<(std::ostream& str, const std::unordered_map<K, V>& m) {     str <<  [ ;     for (auto n : m) str << n.first <<   =>   << n.second <<  ,  ;     str <<  ] ;     return str;   }   void gen(int i, string c, vector<string>& r) {     if (i == 0) {       r.push_back(c);       return;     }     gen(i - 1, c +  4 , r);     gen(i - 1, c +  7 , r);   }   int main() {     cin.sync_with_stdio(false);     cout.sync_with_stdio(false);     int input;     cin >> input;     std::vector<string> all_n;     for (int i = 1; i <= 10; i++) {       gen(i - 1,  4 , all_n);       gen(i - 1,  7 , all_n);     }     stringstream ss;     ss << input;     string inp_string = ss.str();     for (int i = 0; i < all_n.size(); i++) {       if (all_n[i] == inp_string) {         cout << i + 1 << endl;         return 0;       }     }     cout <<  all_n           <<  :   << all_n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, x, y;     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &n, &x, &y);       int d, dif = y - x;       for (int i = 1; i <= dif; i++) {         if (dif % i == 0 && (dif / i <= n - 1)) {           d = i;           break;         }       }       printf( %d , y);       n--;       int val = y - d;       while (val > 0 && n > 0) {         n--;         printf(  %d , val);         val -= d;       }       val = y + d;       while (n > 0) {         n--;         printf(  %d , val);         val += d;       }       printf(  n );     }   }
#include <bits/stdc++.h>   const int inf = 0x7f7f7f7f;   inline void gettime() { ; }   inline int read() {     static char c;     static int x;     int flag = 1;     while (c = getchar(), !isdigit(c))       if (c ==  - ) flag = -1;     x = c -  0 ;     while (c = getchar(), isdigit(c)) x = (x << 1) + (x << 3) + c -  0 ;     return x * flag;   }   inline char achar() {     static char c;     while (c = getchar(), !isdigit(c))       ;     return c;   }   int n, ones;   char s[200200];   std::queue<int> ns[200200];   std::queue<int> ps[2];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; ++i) ones += s[i] ==  1 ;     int k = (n - ones) - ones;     if (k <= 0) return puts( -1 ), 0;     for (int i = 1; i <= k; ++i) ps[0].push(i);     for (int i = 1; i <= n; ++i) {       int cur = s[i] ==  1 ;       if (ps[cur].empty()) return puts( -1 ), 0;       ns[ps[cur].front()].push(i);       ps[cur ^ 1].push(ps[cur].front());       ps[cur].pop();     }     if (!ps[0].empty()) return puts( -1 ), 0;     printf( %d n , k);     for (int i = 1; i <= k; ++i) {       printf( %d  , ns[i].size());       for (; !ns[i].empty(); ns[i].pop()) printf( %d  , ns[i].front());       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e6;   long long n, m;   long long a[N];   long long read(void) {     long long s = 0, w = 0;     char c = getchar();     while (c <  0  || c >  9 ) w |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 ) s = s * 10 + c - 48, c = getchar();     return w ? -s : s;   }   long long point(long long x) {     if (x % 2 == 1) return x * (x - 1) / 2 + 1;     if (x % 2 == 0) return x * (x - 1) / 2 + x / 2;   }   signed main(void) {     n = read(), m = read();     for (long long i = 1; i <= m; ++i) {       long long q = read();       a[i] = read();     }     sort(a + 1, a + m + 1);     reverse(a + 1, a + m + 1);     long long sum = 0;     for (long long i = 1; i <= m; ++i) {       if (point(i) > n) return cout << sum, 0;       sum += a[i];     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7, P = 1e7 + 19;   const int N = 200005;   int nt = 1, k, n, Q, x, y, tot, op;   long long pm(long long x, long long p) {     long long res = 1;     while (p) {       if (p & 1) res = res * x % M;       p >>= 1;       x = x * x % M;     }     return res;   }   struct node {     int l, r, v, w;   } q[N << 2];   int qc[N];   vector<int> a;   long long f[50][2000];   void cdq(int l, int r, int d, vector<int> a) {     if (d > 1) {       for (int i = 1; i <= k; i++) f[d][i] = f[d - 1][i];     }     for (int i = 0; i < (int)a.size(); ++i)       if (q[a[i]].l <= l && r <= q[a[i]].r) {         for (int j = k; j >= q[a[i]].w; j--) {           f[d][j] = max(f[d][j], f[d][j - q[a[i]].w] + q[a[i]].v);         }       }     if (l == r) {       long long res = 0;       for (int i = k; i >= 1; i--) {         res = (res * P + f[d][i]) % M;       }       for (int i = 1; i <= qc[l]; i++) {         printf( %I64d n , res);       }       return;     }     int mid = l + r >> 1;     vector<int> la, ra;     for (int i = 0; i < (int)a.size(); ++i) {       if (q[a[i]].l <= l && r <= q[a[i]].r) continue;       if (q[a[i]].r <= mid) {         la.push_back(a[i]);       } else if (q[a[i]].l > mid) {         ra.push_back(a[i]);       } else {         la.push_back(a[i]);         ra.push_back(a[i]);       }     }     cdq(l, mid, d + 1, la);     cdq(mid + 1, r, d + 1, ra);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       q[++tot] = (node){1, 0, x, y};     }     scanf( %d , &Q);     while (Q--) {       scanf( %d , &op);       if (op == 1) {         ++tot;         ++nt;         scanf( %d%d , &x, &y);         q[tot] = (node){nt, 0, x, y};       } else if (op == 2) {         scanf( %d , &x);         q[x].r = nt;         ++nt;       } else {         qc[nt]++;       }     }     for (int i = 1; i <= tot; i++) {       a.push_back(i);       if (q[i].r == 0) q[i].r = nt;     }     cdq(1, nt, 1, a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch -  0 ;     x *= f;   }   int t, n;   const int maxn = 1e5 + 10;   int a[maxn];   map<int, bool> taked;   int main() {     read(t);     while (t--) {       bool flag = true;       taked.clear();       read(n);       int cnt = 0;       for (register int i = 0; i < n; i++) {         read(a[i]);         int c = ((a[i] + cnt) % n + n) % n;         if (taked[c]) flag = false;         taked[c] = true;         cnt++;       }       if (flag)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[5] = {0};     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       arr[tmp]++;     }     int ret = arr[4];     ret += min(arr[1], arr[3]);     ret += arr[2] / 2;     if (arr[3] > arr[1]) {       ret += arr[3] - arr[1];       ret += (arr[2] % 2) ? 1 : 0;     } else {       int tmp = arr[1] - arr[3];       ret += tmp / 4;       if (arr[2] % 2) {         if (tmp % 4 <= 2)           ret += 1;         else           ret += 2;       } else {         ret += (tmp % 4) ? 1 : 0;       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 2e5 + 10;   int T;   int n, m;   int cnt[1000][2], mz[40][40];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       memset(cnt, 0, sizeof(cnt));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           scanf( %d , &mz[i][j]);           int a = abs(i - 1) + abs(j - 1);           int b = abs(i - n) + abs(j - m);           cnt[min(a, b)][mz[i][j]]++;         }       }       int ans = 0;       for (int i = 0; i <= (n - 1 + m - 1 - 1) / 2; i++) {         ans += min(cnt[i][1], cnt[i][0]);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   int N, M, dx, dy;   int xidx[MAXN];   int cnt[MAXN];   int ans[MAXN][2];   int main() {     cin >> N >> M >> dx >> dy;     for (int i = 0; i < N; i++) xidx[((long long)i * dx) % N] = i;     for (int i = 0; i < M; i++) {       int x, y;       cin >> x >> y;       int val = (y - (long long)xidx[x] * dy) % N;       if (val < 0) val += N;       cnt[val]++;       ans[val][0] = x, ans[val][1] = y;     }     int best = 0;     for (int i = 1; i < N; i++)       if (cnt[best] < cnt[i]) best = i;     cout << ans[best][0] <<     << ans[best][1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     int idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  ,  ;     dbs(str.substr(idx + 1), s...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   void code() {     long long n;     cin >> n;     vector<long long> cnt(4);     long long a, b, c;     a = b = c = 0;     for (long long i = 0; i < (long long)(n); ++i) {       string s;       cin >> s;       if (s ==  M ) a++;       if (s ==  S ) b++;       if (s ==  L )         c++;       else if (s ==  XS )         cnt[1]++;       else if (s ==  XXS )         cnt[2]++;       else if (s ==  XXXS )         cnt[3]++;     }     for (long long i = 0; i < (long long)(n); ++i) {       string s;       cin >> s;       if (s ==  M ) a--;       if (s ==  S ) b--;       if (s ==  L )         c--;       else if (s ==  XS )         cnt[1]--;       else if (s ==  XXS )         cnt[2]--;       else if (s ==  XXXS )         cnt[3]--;     }     long long ans = 0;     ans += abs(a) + abs(b) + abs(c);     ans /= 2;     ans += abs(cnt[1]) + abs(cnt[2]) + abs(cnt[3]);     cout << ans;   }   int main() {     int t = 1;     for (auto i = (1); i != (t + 1); i++) {       code();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 99009000;   const long long MOD = 1000000007;   const int N = 100001;   int main() {     {       ios::sync_with_stdio(false);       cin.tie(nullptr);     };     long long a, b, w, x, c;     cin >> a >> b >> w >> x >> c;     long long A = a * w + b;     long long B = w * c;     long long dif = B - A;     if (dif <= 0)       cout << 0 <<   n ;     else       cout << (dif + w - x - 1) / (w - x) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 5;   long long res = 0, mx = 0;   long long sub[MAX_N];   int custo[MAX_N];   vector<vector<int> > g(MAX_N);   void dfs(int node, int p = -1, int d = 0) {     res += 1LL * d * custo[node];     sub[node] = custo[node];     for (auto to : g[node]) {       if (to != p) {         dfs(to, node, d + 1);         sub[node] += sub[to];       }     }   }   void root(int node, int p = -1) {     mx = max(mx, res);     for (auto to : g[node]) {       if (to != p) {         long long old_res = res;         long long old_node = sub[node];         long long old_to = sub[to];         res -= sub[to];         sub[node] -= sub[to];         res += sub[node];         sub[to] += sub[node];         root(to, node);         res = old_res;         sub[node] = old_node;         sub[to] = old_to;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> custo[i];     for (int i = 0; i < n - 1; i++) {       int st, et;       cin >> st >> et;       --st;       --et;       g[st].emplace_back(et);       g[et].emplace_back(st);     }     dfs(0);     root(0);     cout << mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, deg[8010], type[8010], in[8010];   long long ans = 0;   bool e[8010][8010];   char s[8010];   queue<int> q;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= n / 4; j++) {         int k = (s[j] <=  9  && s[j] >=  0 ) ? s[j] -  0  : s[j] -  A  + 10;         for (int l = 0; l < 4; l++) e[i][j * 4 - l] = (k >> l) & 1;       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (e[i][j]) deg[j]++;     for (int i = 1; i <= n; i++)       if (!deg[i]) q.push(i);     int tmp = n;     while (!q.empty()) {       int now = q.front();       q.pop();       tmp--;       type[now] = 3;       ans += (614ll * n + 1) * tmp;       for (int i = 1; i <= n; i++)         if (e[now][i]) {           deg[i]--;           if (!deg[i]) q.push(i);         }     }     if (!tmp) return printf( %lld n , ans), 0;     int pos = -1, mx = 0;     for (int i = 1; i <= n; i++)       if (deg[i] > mx) mx = deg[i], pos = i;     for (int i = 1; i <= n; i++)       if (type[i] != 3) type[i] = (i == pos || e[i][pos]) ? 1 : 2;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j && type[i] != 3 && type[j] != 3 && type[i] != type[j] &&             e[i][j])           in[j]++;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (type[i] != 3 && type[j] != 3)           ans += 3 + (type[i] == type[j] && in[i] == in[j]);     printf( %lld n , ans);   }