malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n, m, q;   int a[210000];   int nxt[210000][20];   int loc[210000];   int p[210000];   int rp[210000];   int ans[210000];   pair<pair<int, int>, int> queries[210000];   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;       rp[p[i]] = i;     }     for (int i = 0; i < m; i++) {       scanf( %d , &a[i]);       a[i]--;       a[i] = rp[a[i]];     }     for (int i = 0; i < q; i++) {       int l, r;       scanf( %d %d , &l, &r);       r--;       l--;       queries[i] = {{r, l}, i};     }     memset(loc, -1, sizeof(loc));     for (int i = 0; i < m; i++) {       int prev = (a[i] + n - 1) % n;       nxt[i][0] = loc[prev];       loc[a[i]] = i;     }     for (int lvl = 1; lvl < 20; lvl++) {       for (int i = 0; i < m; i++) {         if (nxt[i][lvl - 1] == -1)           nxt[i][lvl] = -1;         else           nxt[i][lvl] = nxt[nxt[i][lvl - 1]][lvl - 1];       }     }     sort(queries, queries + q);     int cur_query = 0;     int best = -1;     for (int i = 0; i < m; i++) {       int cur = i;       for (int lvl = 0; lvl < 20; lvl++)         if ((1 << lvl) & (n - 1)) cur = nxt[cur][lvl];       best = max(best, cur);       for (; cur_query < q && queries[cur_query].first.first == i; cur_query++) {         ans[queries[cur_query].second] =             (best >= queries[cur_query].first.second);       }     }     for (int i = 0; i < q; i++) {       printf( %d , ans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, p = 1e9 + 7;   map<int, int> mp;   char s[N];   inline void A(int &x, int y) { x = (x + y >= p ? x + y - p : x + y); }   inline void Append(int w) {     int v1 = 0, v2 = 0;     map<int, int>::iterator it;     for (it = mp.begin(); it != mp.end() && it->first <= w; ++it) {       A(v1, it->second);       v2 = (v2 + 1ll * it->second * (w - it->first + 1)) % p;     }     mp.erase(mp.begin(), it);     A(mp[w + 1], v1);     mp[0] = v2;   }   int main() {     scanf( %s , s + 1);     int ln = 1, rn = strlen(s + 1);     int time_l = 1, time_r = 1;     while (s[ln] ==  0 ) ++time_l, ++ln;     if (ln > rn) {       printf( %d n , rn);       return 0;     }     while (s[rn] ==  0 ) ++time_r, --rn;     mp[0] = 1;     while (ln != rn) {       ++ln;       int w = 0;       while (s[ln] ==  0 ) ++ln, ++w;       Append(w);     }     int ans = 0;     for (auto x : mp) A(ans, x.second);     printf( %lld n , 1ll * ans * time_l % p * time_r % p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> odd, even;   int main() {     int cnt1 = 0, cnt2 = 0, tem = -1;     int n, k, p, x;     scanf( %d%d%d , &n, &k, &p);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (x % 2 == 0) {         cnt2++;         even.push_back(x);       } else {         if (cnt1 >= k - p) {           if (tem == -1)             tem = x;           else {             even.push_back(tem);             even.push_back(x);             cnt2++;             tem = -1;           }         } else {           cnt1++;           odd.push_back(x);         }       }     }     if (cnt1 < k - p || cnt2 < p || tem != -1)       printf( NO n );     else {       printf( YES n );       if (p == 0) {         for (int i = 0; i < k - p - 1; i++) printf( %d %d n , 1, odd[i]);         printf( %d , n - (k - p - 1));         for (int i = 0; i < even.size(); i++) printf(  %d , even[i]);         printf(  %d n , odd[k - p - 1]);         return 0;       }       for (int i = 0; i < k - p; i++) printf( %d %d n , 1, odd[i]);       int tem2 = 0, cur = 0;       while (tem2 < p - 1) {         if (even[cur] % 2 == 0) {           printf( %d %d n , 1, even[cur]);           cur++;         } else {           printf( %d %d %d n , 2, even[cur], even[cur + 1]);           cur++;           cur++;         }         tem2++;       }       if (even.size() > cur) printf( %d , even.size() - cur);       for (int i = cur; i < even.size(); i++) printf(  %d , even[i]);     }     return 0;   }
#include<iostream>   #include<stdio.h>   using namespace std;    int main()   {long int max,x,y,t;   cin>>t;       while(t--)   {   cin>>x>>y;       if(x==y)       {cout<<2*x<<endl;       continue;                                }       max=x;              if(x<y)       {           max=y;       }       cout<<2*max-1<<endl;          }       return 0;      }
#include <bits/stdc++.h>   using namespace std;   unsigned long xor128() {     static unsigned long x = time(NULL), y = 362436069, z = 521288629,                          w = 88675123;     unsigned long t = (x ^ (x << 11));     x = y;     y = z;     z = w;     return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));   }   double dot(complex<double> a, complex<double> b) {     return a.real() * b.real() + a.imag() * b.imag();   }   double gyaku_dot(complex<double> a, complex<double> b) {     return a.real() * b.imag() - a.imag() * b.real();   }   double leng(complex<double> a) {     return sqrt(a.real() * a.real() + a.imag() * a.imag());   }   double angles(complex<double> a, complex<double> b) {     double cosine = dot(a, b) / (leng(a) * leng(b));     double sine = gyaku_dot(a, b) / (leng(a) * leng(b));     double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));     if (sine <= 0) {       kaku = 2 * 3.141592653589793 - kaku;     }     return kaku;   }   vector<int> convex_hull(vector<complex<double>> a) {     vector<int> ans;     double now_minnest = a[0].real();     int now_itr = 0;     for (long long i = 0; i < a.size(); ++i) {       if (now_minnest > a[i].real()) {         now_minnest = a[i].real();         now_itr = i;       }     }     ans.push_back(now_itr);     complex<double> ba(0, 1);     while (true) {       int now_go = 0;       double now_min = 0;       double now_length = 0;       int starter = ans[ans.size() - 1];       for (int i = 0; i < a.size(); ++i) {         if (i != starter) {           double goa = angles(ba, a[i] - a[starter]);           if (goa - now_min >= 1e-5 ||               (abs(goa - now_min) <= 1e-5 &&                (abs(a[i] - a[starter]) - now_length) >= 1e-5)) {             now_min = goa;             now_go = i;             now_length = abs(a[i] - a[starter]);           }         }       }       if (now_go == ans[0]) break;       ans.push_back(now_go);       ba = complex<double>(a[now_go] - a[starter]);     }     return ans;   }   int ruiseki[1000000];   int main() {     int test_case;     cin >> test_case;     for (long long i = 0; i < test_case; ++i) {       string s;       cin >> s;       int ans = 0;       ruiseki[0] = 0;       for (int i = 0; i < s.length(); ++i) {         if (i != 0) ruiseki[i] = ruiseki[i - 1];         if (s[i] ==  1 ) {           ruiseki[i]++;         }       }       for (int i = 0; i < s.length(); ++i) {         int now = 0;         for (int q = i; q >= 0; --q) {           if (i - q > 25) {             int now_back = i - now + 1;             int now_front = q;             if (now_back > now_front) break;             if (now_back < 0) break;             int hoge = ruiseki[now_front];             if (now_back != 0) {               hoge -= ruiseki[now_back - 1];             }             if (hoge == 0) ans++;             break;           }           if (s[q] ==  1 ) {             now += (1 << (i - q));           }           if (now == i - q + 1) ans++;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[212345];   int cnts[212345];   int lft[212345];   int rght[212345];   int cumsum[212345];   int get_right_ans(int i) { return cumsum[rght[i]] - cumsum[i]; }   int get_left_ans(int i) {     if (lft[i]) return cumsum[i - 1] - cumsum[lft[i] - 1];     return cumsum[i - 1];   }   void print_ans(int fin_ans, int slope) {     if (cnts[fin_ans] < 1) {       return;     }     if (cnts[fin_ans] < 2) {       cnts[fin_ans] -= 1;       printf( %d  , fin_ans);       return;     }     printf( %d  , fin_ans);     cnts[fin_ans] -= 1;     print_ans(fin_ans + slope, slope);     while (cnts[fin_ans]) {       printf( %d  , fin_ans);       cnts[fin_ans]--;     }   }   int main() {     int n, tmp, fnd;     scanf( %d , &n);     ;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       ;       cnts[a[i]] += 1;     }     int lst_val = -1;     for (int i = 0; i < 212345; i++) {       lft[i] = lst_val;       if (cnts[i] < 2) lst_val = i;     }     lst_val = 212345;     for (int i = 212345 - 1; i >= 0; i--) {       rght[i] = lst_val;       if (cnts[i] < 2) lst_val = i;     }     for (int i = 1; i < 212345; i++) cumsum[i] = cumsum[i - 1] + cnts[i];     int maxi = 0;     int fin_ans = -1;     for (int i = 1; i < 212345; i++) {       if (cnts[i] == 1) {         if (1 + max(get_right_ans(i), get_left_ans(i)) > maxi) {           maxi = max(maxi, 1 + max(get_right_ans(i), get_left_ans(i)));           fin_ans = i;         }       } else if (cnts[i] > 1) {         if (cnts[i] + get_right_ans(i) + get_left_ans(i) > maxi) {           maxi = max(maxi, cnts[i] + get_right_ans(i) + get_left_ans(i));           fin_ans = i;         }       }     }     printf( %d n , maxi);     if (cnts[fin_ans] == 1) {       printf( %d  , fin_ans);       if (get_left_ans(fin_ans) > get_right_ans(fin_ans))         print_ans(fin_ans - 1, -1);       else         print_ans(fin_ans + 1, +1);     } else {       if (get_left_ans(fin_ans)) {         printf( %d  , fin_ans);         print_ans(fin_ans - 1, -1);         cnts[fin_ans] -= 1;       }       if (get_right_ans(fin_ans)) {         printf( %d  , fin_ans);         print_ans(fin_ans + 1, 1);         cnts[fin_ans] -= 1;       }       while (cnts[fin_ans]) {         printf( %d  , fin_ans);         cnts[fin_ans]--;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e10;   template <typename T>   void cmax(T &a, T b) {     a = max(a, b);   }   template <typename T>   void cmin(T &a, T b) {     a = min(a, b);   }   signed main() {     string s;     cin >> s;     long long a[5555] = {};     long long b[5555] = {};     for (long long i = 0; i < (s.size()); i++) {       a[i + 1] += a[i];       b[i + 1] += b[i];       if (s[i] ==  a )         a[i + 1]++;       else         b[i + 1]++;     }     long long ans = 0;     for (long long i = 0; i < (s.size() + 1); i++)       for (long long j = (i); j < (s.size() + 1); j++)         cmax(ans, a[s.size()] - a[j] + b[j] - b[i] + a[i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve(double S, double a, double b, double c, double* result) {     if ((a == 0) && (b == 0) && (c == 0)) {       result[0] = S;     } else if ((a == 0) && (b == 0) && (c > 0)) {       result[2] = S;     } else if ((a == 0) && (b > 0) && (c == 0)) {       result[1] = S;     } else if ((a > 0) && (b == 0) && (c == 0)) {       result[0] = S;     } else if ((a == 0) && (b > 0) && (c > 0)) {       result[1] = S * b / (b + c);       result[2] = S * c / (b + c);     } else if ((a > 0) && (b == 0) && (c > 0)) {       result[0] = S * a / (a + c);       result[2] = S * c / (a + c);     } else if ((a > 0) && (b > 0) && (c == 0)) {       result[0] = S * a / (a + b);       result[1] = S * b / (a + b);     } else if ((a > 0) && (b > 0) && (c > 0)) {       result[0] = S * (a * (a + b)) / ((a + b) * (a + b + c));       result[1] = S * (b * (a + b)) / ((a + b) * (a + b + c));       result[2] = S * c / (a + b + c);     }   }   int main() {     unsigned int S(0), a(0), b(0), c(0);     double result[3] = {0.0, 0.0, 0.0};     cin >> S;     cin >> a;     cin >> b;     cin >> c;     solve((double)S, (double)a, (double)b, (double)c, result);     cout << std::fixed << std::setprecision(10) << result[0] <<     << result[1]          <<     << result[2];   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) return 0;     return gcd(b % a, a) + b / a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     while (n--) {       int a, b;       cin >> a >> b;       cout << gcd(a, b) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long p, ans, num;   int n;   string s[500000];   int main() {     cin >> n >> p;     p /= 2;     for (int i = 1; i <= n; ++i) {       cin >> s[i];     }     for (int i = n; i >= 1; --i) {       num *= 2;       if (s[i] ==  halfplus ) num++;       ans += num;     }     cout << ans * p << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename G1, typename G2 = G1, typename G3 = G1>   struct triple {     G1 first;     G2 second;     G3 T;   };   const long double eps = 1e-12;   int sign(long double x) { return x < -eps ? -1 : x > eps; }   int dblcmp(long double x, long double y) { return sign(x - y); }   long double dot(complex<long double> a, complex<long double> b) {     return real(conj(a) * b);   }   long double cross(complex<long double> a, complex<long double> b) {     return imag(conj(a) * b);   }   struct Point {     complex<long double> p;     int id;     long double operator*(const Point o) const { return cross(this->p, o.p); }     Point operator-(const Point o) const { return {p - o.p}; }     bool operator<(const Point o) const {       if (dblcmp(p.real(), o.p.real()) == 0)         return dblcmp(p.imag(), o.p.imag()) < 0;       return dblcmp(p.real(), o.p.real()) < 0;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<vector<int>> mp1(n);     map<pair<long long, long long>, int> mp2;     vector<Point> v;     int c = 0;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (mp2.count({x, y}) == 0) {         v.push_back({{10000.0 / x, 10000.0 / y}, c});         mp2[{x, y}] = c++;       }       mp1[mp2[{x, y}]].push_back(i + 1);     }     sort(v.begin(), v.end());     vector<Point> hull;     for (int i = 0; i < c; i++) {       while (hull.size() > 1 &&              dblcmp((hull.end()[-1] - hull.end()[-2]) * (v[i] - hull.end()[-1]),                     0) < 0)         hull.pop_back();       hull.push_back(v[i]);     }     while (hull.size() > 1 &&            dblcmp(hull.end()[-2].p.imag(), hull.end()[-1].p.imag()) <= 0)       hull.pop_back();     vector<int> ans;     for (auto &i : hull)       for (auto j : mp1[i.id]) ans.push_back(j);     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++)       cout << ans[i] <<    n [i == ans.size() - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   long long powmodM(long long a, long long b, long long c = M) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % M;       a = (a * a) % M;       b /= 2;     }     return res;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a);       a = (a * a);       b /= 2;     }     return res;   }   long long gcd(long long a, long long b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   long long lcm(long long a, long long b) {     return (max(a, b) / gcd(a, b)) * min(a, b);   }   vector<long long int> sieve(long long int n) {     vector<long long int> ans, prime(2 * 1e6);     prime[0] = false;     prime[1] = false;     for (long long int p = 2; p * p <= n; p++)       if (prime[p])         for (long long int i = p * p; i <= n; i += p) prime[i] = 0;     for (long long p = (2); p <= (n); ++p)       if (prime[p]) ans.push_back(p);     return ans;   }   long long modInverse(long long n, long long p = M) {     return powmodM(n, p - 2, p);   }   long long nCrModP(long long n, long long r, long long p = M) {     if (r == 0) return 1;     long long fac[n + 1];     fac[0] = 1;     for (long long i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * i % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   double pie = 3.14159265358979323846264338;   const long long int INF = 0x3f3f3f3f;   class l {    public:     char data;     l *next;     l *prev;     l(char a) {       data = a;       prev = NULL;       next = NULL;     }   };   map<long long int, long long int> fre;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     vector<long long int> arr(n);     for (long long i = (0); i <= (n - 1); ++i) cin >> arr[i];     if (m == arr[0]) {       cout << -1;       return 0;     }     long long int ma = 0;     fre[arr[ma]] = 1;     bool ok = 1;     long long int uski = 0;     for (long long i = (1); i <= (n - 1); ++i) {       if (arr[i] == m) {         uski++;         vector<long long int> re;         for (auto u : fre) {           if (u.second < uski) re.push_back(u.first);         }         for (auto u : re) {           fre.erase(u);         }         if (!fre.size()) {           cout << -1;           return 0;         }       }       if (!uski)         fre[arr[i]]++;       else if (fre[arr[i]]) {         fre[arr[i]]++;       }     }     vector<long long int> re;     for (auto u : fre) {       if (u.second < uski) re.push_back(u.first);     }     for (auto u : re) {       fre.erase(u);     }     if (!fre.size()) {       cout << -1;       return 0;     }     if (fre.size()) {       cout << fre.begin()->first;     } else {       cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> temp(100005);   vector<int> v(100005);   int fn(int l, int h, int x) {     while (h - l > 1) {       int mid = (h + l) / 2;       if (temp[mid] >= x) {         h = mid;       } else {         l = mid;       }     }     if (temp[h] > x)       return h;     else       return l;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int len = 1;     temp[0] = v[0];     for (int i = 1; i < n; i++) {       if (temp[0] > v[i]) {         temp[0] = v[i];       } else if (v[i] > temp[len - 1]) {         temp[len] = v[i];         len++;       } else {         int index = fn(0, len - 1, v[i]);         temp[index] = v[i];       }     }     cout << len;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   long long fastpower(long long x, long long n, long long M) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return fastpower((x * x) % M, n / 2, M);     else       return (x * fastpower((x * x) % M, (n - 1) / 2, M)) % M;   }   long long GCD(long long A, long long B) {     if (B == 0)       return A;     else       return GCD(B, A % B);   }   bool vowl(char c) {     return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ;   }   long long modInverse(long long A, long long M) {     return fastpower(A, M - 2, M);   }   void sieve(long long N) {     bool isPrime[N + 1];     for (long long i = 0; i <= N; ++i) {       isPrime[i] = true;     }     isPrime[0] = false;     isPrime[1] = false;     for (long long i = 2; i * i <= N; ++i) {       if (isPrime[i] == true) {         for (long long j = i * i; j <= N; j += i) isPrime[j] = false;       }     }   }   vector<long long> factorize(long long n) {     vector<long long> res;     for (long long i = 2; i * i <= n; ++i) {       while (n % i == 0) {         res.push_back(i);         n /= i;       }     }     if (n != 1) {       res.push_back(n);     }     return res;   }   long long dp[300000][20];   long long n, m, k;   long long arr[20];   long long cost[20][20];   long long cal(string s) {     reverse(s.begin(), s.end());     long long ans = 0;     for (long long i = 0; i < s.length(); i++) {       if (s[i] ==  1 ) ans += (1 << i);     }     return ans;   }   long long solve(string &s, int prev) {     int p = 0;     int a = 0;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         a++;         p += (1 << (n - i - 1));       }     }     if (a == m) return 0;     if (dp[p][prev] != -1) return dp[p][prev];     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  0 ) {         s[i] =  1 ;         ans = max(ans, arr[i + 1] + cost[prev][i + 1] + solve(s, i + 1));         s[i] =  0 ;       }     }     return dp[p][prev] = ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     string s =   ;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];       s +=  0 ;     }     for (long long i = 0; i < k; i++) {       long long x, y, c;       cin >> x >> y >> c;       cost[x][y] = c;     }     memset(dp, -1, sizeof(dp));     cout << solve(s, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     if (a == 0 && b == 0 && c == 0 && d == 0) {       printf( 1 n );     } else if (a == 0 && d == 0 && c != 0) {       printf( 0 n );     } else if (a != d) {       printf( 0 n );     } else {       printf( 1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     long long n, a[5001], cnt = 1, maxn = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n - 1; i++) {       if (a[i] == a[i + 1]) cnt++;       if (a[i] != a[i + 1]) cnt = 1;       maxn = max(maxn, cnt);     }     maxn = max(maxn, cnt);     cout << maxn;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, ans, s1;     cin >> s;     s1 = s;     int l = s.length(), i;     int j = l - 1, flag = 0;     while (i < j) {       if (s[i] != s[j]) {         flag = 1;         break;       }       i++;       j--;     }     if (flag) {       reverse(s1.begin(), s1.end());       ans = s + s1;       cout << ans;     } else       cout << s;     return 0;   }
#include <bits/stdc++.h>   const long long md = 1e9 + 7;   const int Inf = 1e9;   const long long Inf64 = 1e18;   const long long MaxN = 1e6 + 100;   const long double eps = 1e-15;   using namespace std;   long long Tree[4 * MaxN];   long long getSum(long long l, long long r, long long x, long long y,                    long long id) {     if (l == x && r == y) {       return Tree[id];     } else {       long long mid = (l + r) / 2;       if (mid >= y) {         return getSum(l, mid, x, y, 2 * id + 1);       } else if (mid + 1 <= x) {         return getSum(mid + 1, r, x, y, 2 * id + 2);       } else {         return getSum(l, mid, x, mid, 2 * id + 1) +                getSum(mid + 1, r, mid + 1, y, 2 * id + 2);       }     }   }   void edit(long long l, long long r, long long x, long long id) {     if (l == r) {       Tree[id]++;     } else {       long long mid = (l + r) / 2;       if (mid >= x) {         edit(l, mid, x, 2 * id + 1);         Tree[id] = Tree[2 * id + 1] + Tree[2 * id + 2];       } else {         edit(mid + 1, r, x, 2 * id + 2);         Tree[id] = Tree[2 * id + 1] + Tree[2 * id + 2];       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long N;     cin >> N;     vector<pair<long long, long long> > Zip(N);     for (int i = 0; i < N; i++) {       long long a;       cin >> a;       Zip[i] = {a, i};     }     sort(Zip.begin(), Zip.end());     vector<long long> Ans(N);     for (int i = 0; i < N; i++) {       long long t = getSum(0, N - 1, Zip[i].second, N - 1, 0);       Ans[Zip[i].second] = t;       edit(0, N - 1, Zip[i].second, 0);     }     fill(Tree, Tree + 4 * MaxN, 0);     reverse(Zip.begin(), Zip.end());     long long Res = 0;     for (int i = 0; i < N; i++) {       long long t = getSum(0, N - 1, 0, Zip[i].second, 0);       Res += Ans[Zip[i].second] * t;       edit(0, N - 1, Zip[i].second, 0);     }     cout << Res;     cerr <<   n           <<  Time execute:   << clock() / (double)CLOCKS_PER_SEC <<   sec           <<   n ;     return 0;   }