malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   char a[5];   char s1[3], s2[3];   void solve() {     int i, vt, kq1, kq2;     scanf( %d , &n);     n = n % 4;     a[0] =  v ;     a[1] =  < ;     a[2] =  ^ ;     a[3] =  > ;     for (i = 0; i < 4; i++)       if (a[i] == s1[0]) vt = i;     kq1 = 0;     kq2 = 0;     if (a[(vt + n) % 4] == s2[0]) kq1 = 1;     if (a[(vt - n + 4) % 4] == s2[0]) kq2 = 1;     if (kq1 == 1 && kq2 == 0) printf( cw n );     if (kq1 == 0 && kq2 == 1) printf( ccw n );     if ((kq1 == 0 && kq2 == 0) || (kq1 == 1 && kq2 == 1)) printf( undefined n );   }   int main() {     while (scanf( %s %s , &s1, &s2) > 0) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     scanf( %d%d , &a, &b);     for (int i = b + 1; i <= a + b + 1; i++) printf( %d  , i);     for (int i = b; i >= 1; i--) printf( %d  , i);     return 0;   }
#include<iostream>   #include<math.h>   #include<bits/stdc++.h>   #include <string>    #include <vector>    using namespace std;   #define pi (2*acos(0.0))   #define ll long long int    #define ull unsigned long long int    #define lp(i , start , n) for(int i = start ; i < n; i++)         int main(){       ios::sync_with_stdio(false);       cin.tie(0);        int t; cin>>t;       while(t--){           int n; cin>>n;           if(n==2) cout<<-1<<endl;           else{               int a[n][n];               bool odd = true;               int oddnum= 1;               int evennum=1;               int cnt = 0;                  for(int i = 0 ; i < n ; i++){                   for(int j = 0 ; j < n ; j++){                       if(odd){                           a[i][j]=2*oddnum-1;                           oddnum++;                           cnt++;                           if(cnt>=(n*n+1)/2){                               odd=false;                           }                       }                       else{                           a[i][j]=2*evennum;                           evennum++;                       }                   }               }                  for(int i = 0 ; i < n ; i++){                   for(int j = 0 ; j < n ; j++){                       cout<<a[i][j]<<   ;                   }                   cout<<endl;               }                 }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10000000], b[10010000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     int p = 0;     sort(a, a + n);     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) p++;     }     if (p > 2)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_INT = INT32_MAX;   const long long MAX_LL = INT64_MAX;   const long long mod = 1e9 + 7;   const int N = 1;   bool primes[N + 1];   int npr(int n, int r) {     int res = 1;     for (auto i = n - r + 1; i <= n; i++) res *= i;     return res;   }   int ncr(int n, int r) {     int res = 1;     int rFact = 1;     for (auto i = n - r + 1; i <= n; i++) {       res *= i;       if (res % rFact == 0 && rFact <= r) res /= rFact, rFact++;     }     return res;   }   void sieve() {     memset(primes, true, sizeof(primes));     primes[0] = primes[1] = false;     for (int i = 2; i * i <= N; i++) {       if (primes[i]) {         for (int j = i * i; j <= N; j += i) primes[j] = false;       }     }   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n == 2) return true;     for (auto i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   set<long long> getDivisors(long long val) {     set<long long> st;     for (auto i = 1; i <= sqrt(val); i++)       if (val % i == 0) st.insert(i), st.insert(val / i);     return st;   }   long long fastPow(long long base, long long power) {     long long res = 1;     while (power > 0) {       if (power % 2 != 0) res = (res * base) % mod;       base = (base * base) % mod;       power /= 2;     }     return res;   }   bool palindrome(string s) {     string reversedS = s;     reverse(reversedS.begin(), reversedS.end());     if (s == reversedS)       return true;     else       return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<long long> v(n), A, B;     int winner = -1;     long long mxA = -1, mxB = -1;     bool lexi = false;     long long sum = 0;     for (auto i = 0; i < n; i++) {       cin >> v[i];       sum += v[i];       if (v[i] > 0)         A.push_back(v[i]);       else         B.push_back(abs(v[i]));     }     for (auto i = 0; i < min(A.size(), B.size()); i++) {       if (A[i] > B[i]) {         lexi = true;         winner = 0;         break;       } else if (B[i] > A[i]) {         lexi = true;         winner = 1;         break;       }     }     if (sum == 0) {       if (lexi)         cout << ((winner == 0) ?  first  :  second );       else         cout << ((v.back() > 0) ?  first  :  second );     } else       cout << ((sum > 0) ?  first  :  second );     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s, k;     cin >> s;     map<string, int> m;     for (int i = 0; i < s.size() - 9; i++) {       if (s[i] !=  -  && s[i + 1] !=  -  && s[i + 2] ==  -  && s[i + 3] !=  -  &&           s[i + 4] !=  -  && s[i + 5] ==  -  && s[i + 6] !=  -  &&           s[i + 7] !=  -  && s[i + 8] !=  -  && s[i + 9] !=  - ) {         if (s[i + 6] ==  2  && s[i + 7] ==  0  && s[i + 8] ==  1  &&             s[i + 9] >=  3  && s[i + 9] <=  5 ) {           if ((s[i + 3] ==  0  &&                (s[i + 4] ==  1  || s[i + 4] ==  8  || s[i + 4] ==  7  ||                 s[i + 4] ==  5  || s[i + 4] ==  3 )) ||               (s[i + 3] ==  1  && (s[i + 4] ==  0  || s[i + 4] ==  2 ))) {             if ((s[i] ==  0  && s[i + 1] >  0 ) || (s[i] <  3  && s[i] >  0 ) ||                 (s[i] ==  3  && (s[i + 1] ==  1  || s[i + 1] ==  0 ))) {               k = s[i];               k += s[i + 1];               k += s[i + 2];               k += s[i + 3];               k += s[i + 4];               k += s[i + 5];               k += s[i + 6];               k += s[i + 7];               k += s[i + 8];               k += s[i + 9];               m[k]++;             }           } else if ((s[i + 3] ==  0  &&                       (s[i + 4] ==  4  || s[i + 4] ==  6  || s[i + 4] ==  9 )) ||                      (s[i + 3] ==  1  && (s[i + 4] ==  1 ))) {             if ((s[i] ==  0  && s[i + 1] >  0 ) || (s[i] <  3  && s[i] >  0 ) ||                 (s[i] ==  3  && (s[i + 1] ==  0 ))) {               k = s[i];               k += s[i + 1];               k += s[i + 2];               k += s[i + 3];               k += s[i + 4];               k += s[i + 5];               k += s[i + 6];               k += s[i + 7];               k += s[i + 8];               k += s[i + 9];               m[k]++;             }           } else if (s[i + 3] ==  0  && s[i + 4] ==  2 ) {             if ((s[i] ==  0  && s[i + 1] >  0 ) || (s[i] <  2  && s[i] >  0 ) ||                 (s[i] ==  2  && (s[i + 1] >=  0  && s[i + 1] <=  8 ))) {               k = s[i];               k += s[i + 1];               k += s[i + 2];               k += s[i + 3];               k += s[i + 4];               k += s[i + 5];               k += s[i + 6];               k += s[i + 7];               k += s[i + 8];               k += s[i + 9];               m[k]++;             }           }         }       }     }     map<string, int>::iterator it = m.begin();     int maxx = -1;     for (; it != m.end(); it++) {       if (maxx < it->second) {         maxx = it->second;         s = it->first;       }     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   FILE* in = stdin;   FILE* out = stdout;   const int MAX = 100001;   const int INF = 1000000001;   int n;   int dist[MAX];   long long a[MAX];   int main(void) {     fscanf(in,  %d , &n);     for (int i = 0; i < n; i++) fscanf(in,  %lld , &a[i]);     sort(a, a + n);     reverse(a, a + n);     while (n > 0 && a[n - 1] == 0) n--;     for (int bit = 0; bit < 60; bit++) {       int cnt = 0;       for (int i = 0; i < n; i++)         if (a[i] & (1LL << bit)) cnt++;       if (cnt >= 3) {         fprintf(out,  3 n );         return 0;       }     }     int ans = INF;     for (int origin = 0; origin < n; origin++) {       if (ans <= 3) break;       memset(dist, 63, sizeof(dist));       queue<int> q;       q.push(origin);       dist[origin] = 0;       int curDist = 0;       while (!q.empty()) {         curDist++;         vector<int> nnodes;         vector<int> cnt(n, 0);         while (!q.empty()) {           int node = q.front();           q.pop();           for (int i = 0; i < n; i++) {             if (dist[i] > INF && (a[node] & a[i])) {               dist[i] = curDist;               nnodes.push_back(i);             }             if (dist[i] == curDist && (a[node] & a[i])) cnt[i]++;           }         }         for (int i = 0; i < n; i++) {           if (cnt[i] >= 2) {             ans = min(ans, curDist + curDist);           }         }         for (int i1 = 0; i1 < (int)nnodes.size(); i1++) {           if (ans <= 3) break;           for (int i2 = i1 + 1; i2 < (int)nnodes.size(); i2++) {             if (a[nnodes[i1]] & a[nnodes[i2]]) {               ans = min(ans, curDist + curDist + 1);             }           }         }         for (int i = 0; i < (int)nnodes.size(); i++) {           q.push(nnodes[i]);         }       }     }     fprintf(out,  %d n , ans >= INF ? -1 : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int sum1, sum2;   inline void in(long long int &_8) {     long long int _6 = 1;     char _0;     while (((_0 = getchar()) <  0  || _0 >  9 ) && _0 !=  - )       ;     _0 ==  -  ? (_6 = -1, _8 = 0) : (_8 = _0 -  0 );     while ((_0 = getchar()) >=  0  && _0 <=  9 ) _8 = _8 * 10 + _0 -  0 ;     _8 *= _6;   }   int main() {     long long int digit, base, tmp, sum;     in(digit);     in(base);     for (int i = 1; i <= digit; i++) {       in(tmp);       sum1 = sum1 * base + tmp;     }     in(digit);     in(base);     for (int i = 1; i <= digit; i++) {       in(tmp);       sum2 = sum2 * base + tmp;     }     sum1 == sum2 ? putchar( = ) : sum1 > sum2 ? putchar( > ) : putchar( < );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int n;     scanf( %d , &n);     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       --a[i];     }     for (int i = 0; i < n; ++i) {       scanf( %d , &b[i]);       --b[i];     }     vector<int> posa(n), posb(n);     for (int i = 0; i < n; ++i) {       posa[a[i]] = i;       posb[b[i]] = i;     }     multiset<int> left, right;     for (int i = 0; i < n; ++i) {       if (posb[i] < posa[i]) {         left.insert(posa[i] - posb[i]);       } else {         right.insert(posb[i] - posa[i]);       }     }     int x = 0;     vector<int> r;     while (x < n) {       int ans = n + 10;       if (!left.empty()) {         ans = min(ans, *left.begin() - x);       }       if (!right.empty()) {         ans = min(ans, *right.begin() + x);       }       r.push_back(ans);       x++;       if (x == n) {         break;       }       while (!left.empty() && *left.begin() - x == 0) {         left.erase(left.begin());         right.insert(-x);       }       int e = b[n - x];       if (posb[e] + x < posa[e]) {         left.erase(left.find(posa[e] - posb[e]));       } else {         right.erase(right.find(posb[e] - posa[e]));       }       if ((posb[e] + x) % n < posa[e]) {         left.insert(posa[e] - (posb[e] + x) % n + x);       } else {         right.insert((posb[e] + x) % n - posa[e] - x);       }     }     reverse(r.begin() + 1, r.end());     for (int x : r) {       printf( %d n , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, f[2][30], a[100005], b[100005];   string s;   int main() {     scanf( %d , &n);     int now = 1, pre = 0;     for (int i = 1; i <= n; i++, swap(now, pre)) {       cin >> s;       int len = s.length();       memset(f[now], 0, sizeof f[now]);       for (int j = 0; j < len; j++)         a[j] = (j == 0             ? 1                 : s[j - 1] == s[j] ? a[j - 1] + 1                                    : 1),         b[len - j - 1] =             (len - j - 1 == len - 1                 ? 1              : s[len - j - 1 + 1] == s[len - j - 1] ? b[len - j - 1 + 1] + 1                                                     : 1),         f[now][s[j] -  a ] = max(f[now][s[j] -  a ], a[j]);       for (int j = 0; j < 26; j++) {         f[now][j] = max(f[now][j], (f[pre][j] > 0) + (s[0] -  a  == j) * b[0]),         f[now][j] = max(f[now][j],                         (f[pre][j] > 0) + (s[len - 1] -  a  == j) * a[len - 1]);         if (a[len - 1] == len && s[0] -  a  == j)           f[now][j] = max(f[now][j], f[pre][j] + len * (f[pre][j] + 1));         else           f[now][j] = max(f[now][j], (f[pre][j] > 0) + (s[0] -  a  == j) * b[0] +                                          (s[len - 1] -  a  == j) * a[len - 1]);       }     }     int ans = 0;     for (int i = 0; i < 26; i++) ans = max(ans, f[pre][i]);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> v;     set<long long> myset;     set<long long>::iterator it;     long long n, k, q, t;     map<long long, int> mp;     cin >> n >> k;     for (long long i = 0; i < n; i++) {       scanf( %I64d , &t);       v.push_back(t);       myset.insert(t);       mp[t]++;     }     sort(v.begin(), v.end());     if (v.size() == myset.size()) {       if (k % n != 0 && n < k) {         long long m = k / n;         long long p = m * n;         long long u = v[m];         long long x = 0;         for (long long i = p + 1; i <= k; i++) {           q = v[x];           ++x;         }         cout << u <<     << q << endl;         return 0;       }       if (k % n == 0 && n <= k) {         cout << v[(k / n) - 1] <<     << v[n - 1] << endl;         return 0;       }       if (k < n) {         cout << v[0] <<     << v[k - 1] << endl;         return 0;       }     } else {       long long sum = 0, b;       for (it = myset.begin(); it != myset.end(); ++it) {         sum += (mp[*it] * n);         if (k <= sum) {           b = *it;           sum -= (mp[*it] * n);           break;         }       }       long long cnt = sum;       for (long long i = 0; i < n; i++) {         cnt += mp[b];         if (cnt >= k) {           cout << b <<     << v[i] << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int nmax = 2e5 + 42;   int n, k;   int main() {     cin >> n >> k;     int d = (n - k) / 2;     int cycle = d + 1;     for (int i = 1; i <= n; i++)       if (i % cycle == 0)         cout <<  1 ;       else         cout <<  0 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[105];   int main() {     int n;     cin >> n;     cin >> s;     int flag = 0;     for (int i = 1; i < n; i++) {       if (s[i] !=  ?  && s[i] == s[i - 1]) {         flag = 1;         break;       }     }     if (flag)       cout <<  No  << endl;     else {       if (s[0] ==  ?  || s[n - 1] ==  ? )         flag = 1;       else {         for (int i = 1; i < n - 1; i++) {           if (s[i] ==  ?  && s[i - 1] ==  ?  ||               s[i] ==  ?  && s[i + 1] == s[i - 1])             flag = 1;         }       }       if (flag)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 6, m = 8;     vector<string> a(n);     vector<vector<int>> u;     vector<int> loc(m);     loc = {3, 3, -1, 4, 4, -1, 3, 3};     u.push_back(loc);     u.push_back(loc);     loc = {2, 2, -1, 3, 3, -1, 2, 2};     u.push_back(loc);     u.push_back(loc);     loc = {1, 1, -1, 2, 2, -1, 1, 1};     u.push_back(loc);     u.push_back(loc);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int max = 0, x, y;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  .  && u[i][j] > max) {           x = i;           y = j;           max = u[i][j];         }       }     }     a[x][y] =  P ;     for (auto i : a) {       cout << i <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool SortbySecDesc(const pair<long long, long long> &a,                      const pair<long long, long long> &b) {     return a.second > b.second;   }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     ;     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       long long low = 1, high = 1e18, ans;       while (low <= high) {         long long mid = (low + high) / 2;         long long vag = mid / a;         long long baki = mid - vag;         if (baki >= b) {           ans = mid;           high = mid - 1;         } else {           low = mid + 1;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int k, tk;     long long n, ck, a;     scanf( %I64d %d , &n, &k);     long long menor = n;     scanf( %I64d , &a);     tk = 1;     ck = n / a;     menor = n % a;     for (int i = 1; i < k; i++) {       scanf( %I64d , &a);       if (n % a < menor) {         tk = i + 1;         ck = n / a;         menor = n % a;       }     }     printf( %d %I64d , tk, ck);   }
#include <bits/stdc++.h>   std::vector<std::vector<int>> ad;   std::vector<int> fm;   std::vector<bool> tmp;   int f(int x) {     if (fm[x] >= 0) return fm[x];     for (int y : ad[x]) f(y);     for (int y : ad[x]) tmp[fm[y]] = true;     fm[x] = int(std::find(begin(tmp), end(tmp), false) - begin(tmp));     for (int y : ad[x]) {       tmp[fm[y]] = false;     }     return fm[x];   }   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     int n, m;     std::cin >> n >> m;     std::vector<int> h(n);     for (int& x : h) std::cin >> x;     ad.resize(n);     for (int z = m; z--;) {       int u, v;       std::cin >> u >> v;       --u;       --v;       ad[u].push_back(v);     }     std::vector<int> val(n);     fm.assign(n, -1);     tmp.resize(n);     for (int i = n; i--;) val[f(i)] ^= h[i];     while (!val.empty() && val.back() == 0) val.pop_back();     if (val.empty()) {       std::cout <<  LOSE n ;       return 0;     }     std::cout <<  WIN n ;     int i = 0;     while (fm[i] != val.size() - 1 || (h[i] ^ val.back()) > h[i]) {       ++i;     }     h[i] ^= val.back();     std::vector<bool> ok(val.size() - 1);     for (int j : ad[i])       if ((unsigned)fm[j] < ok.size() && !ok[fm[j]]) {         ok[fm[j]] = true;         h[j] ^= val[fm[j]];       }     for (auto x : h) std::cout << x <<    ;     std::cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, i;     long long h, k, a[100005], cnt = 0;     cin >> n >> h >> k;     for (i = 0; i < n; i++) cin >> a[i];     long long carry = 0;     for (i = 0; i < n; i++) {       if (carry + a[i] <= h) {         carry += a[i];       } else {         cnt += 1;         carry = a[i];       }       cnt += (carry / k);       carry %= k;     }     cnt += carry / k;     carry %= k;     cnt += (carry > 0);     cout << cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int L = 50500, C = 27, N = 11, root = 0, None = -987958798;   const char END =  { ;   struct node {     int s[C], b[N], par, val;   } t[L * 22] = {};   char ch[L * 22] = {};   int n, l = 0, tot = 0, x[N] = {}, y[N] = {}, d[N] = {}, in[L * 22] = {},          q[L * 22] = {}, head = 0, tail = 0;   long long ans = 0;   void add(int p, int c) {     int np = ++tot;     t[np].val = t[p].val + 1;     while (p != None && t[p].s[c] == 0) t[p].s[c] = np, p = t[p].par;     if (p == None)       t[np].par = root;     else {       int q = t[p].s[c];       if (t[p].val + 1 == t[q].val)         t[np].par = q;       else {         int nq = ++tot;         t[nq] = t[q];         t[nq].val = t[p].val + 1;         t[q].par = t[np].par = nq;         for (int i = p; i != None && t[i].s[c] == q; i = t[i].par) t[i].s[c] = nq;       }     }   }   int main() {     t[root].par = None;     d[0] = ++l;     cin >> (ch + d[0]) >> n;     l += strlen(ch + d[0]);     for (int i = 1; i <= n; ++i) {       ch[l] = END;       d[i] = ++l;       cin >> (ch + d[i]) >> x[i] >> y[i];       l += strlen(ch + d[i]);     }     ch[l] = END;     for (int i = 1, p = root; i < l; p = t[p].s[ch[i++] -  a ])       add(p, ch[i] -  a );     for (int i = 0; i <= n; ++i)       for (int j = d[i], p = t[root].s[ch[j] -  a ]; ch[j] != END;            p = t[p].s[ch[++j] -  a ])         ++t[p].b[i];     for (int i = 1; i <= tot; ++i) ++in[t[i].par];     for (int i = 1; i <= tot; ++i)       if (!in[i]) q[++tail] = i;     for (int tmp = 1; tmp <= tot; ++tmp) {       int s = q[++head];       bool flag = t[s].b[0];       for (int i = 1; i <= n; ++i) flag &= x[i] <= t[s].b[i] && t[s].b[i] <= y[i];       if (flag) ans += t[s].val - t[t[s].par].val;       for (int i = 0; i <= n; ++i) t[t[s].par].b[i] += t[s].b[i];       if ((--in[t[s].par]) == 0) q[++tail] = t[s].par;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int co, key;   } num[1010];   int seven;   char str[1010 * 100];   int init;   bool cmp(node x, node y) { return x.co < y.co; }   int main() {     scanf( %d , &init);     scanf( %s , str);     seven = 1;     int cnt = 1;     int length = strlen(str);     int now = 0;     int pre = -1;     for (int i = 1; i <= 1000; i++) num[i].co = 1;     while (now < length) {       if (str[now] ==  - ) {         seven = -1;         now++;       } else if (str[now] ==  *  || str[now] ==  + )         now++;       else if (str[now] ==  a ) {         if (now - 2 > pre && str[now - 1] ==  +  && str[now - 2] ==  + ) {           pre = now;           num[cnt].co *= seven;           num[cnt].key = 0;           cnt++;           now++;         } else {           pre = now + 2;           num[cnt].co *= seven;           num[cnt].key = 1;           cnt++;           now += 3;         }         seven = 1;       } else {         int sum = 0;         while (str[now] >=  0  && str[now] <=  9 ) {           sum = sum * 10 + (str[now] -  0 );           now++;         }         num[cnt].co = sum;       }     }     cnt--;     sort(num + 1, num + 1 + cnt, cmp);     int ans = 0;     for (int i = 1; i <= cnt; i++) {       if (!num[i].key) {         init++;         ans += (num[i].co * init);       } else {         ans += (num[i].co * init);         init++;       }     }     printf( %d n , ans);     return 0;   }