malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   int l[200000], r[200000], p[200001];   vector<int> beg[200001], ed[200001];   map<unsigned long long, unsigned long long> cnt, sum;   unsigned long long h[200000], all;   mt19937_64 mt(time(0));   int main() {     scanf( %d%d , &n, &m);     all = 0;     for (int i = 0; i < (int)(n); ++i) {       scanf( %d%d , l + i, r + i);       --l[i], --r[i];       ++p[l[i]];       --p[r[i] + 1];       beg[l[i]].push_back(i);       ed[r[i] + 1].push_back(i);       h[i] = mt();       all ^= h[i];     }     unsigned long long mask = 0, bmask = all, emask = 0, change = 0, ans = 0;     for (int i = 0; i < (int)(m + 1); ++i) {       for (int x : ed[i]) {         emask ^= h[x];       }       mask ^= change;       ans += cnt[mask ^ all ^ bmask] * i - sum[mask ^ all ^ bmask];       ++cnt[mask ^ emask];       sum[mask ^ emask] += i;       for (int x : beg[i]) {         change ^= h[x];         bmask ^= h[x];       }       for (int x : ed[i]) {         change ^= h[x];       }     }     int t = 0, c = 0;     for (int i = 0; i < (int)(m); ++i) {       t += p[i];       if (t > 0) {         c = 0;       } else {         ++c;         ans -= (unsigned long long)c * (c + 1) / 2;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string str;     cin >> str;     for (int i = 0;; i += 2) {       if (i >= str.length() - 1) break;       if (str[i] == str[i + 1]) {         str.erase(str.begin() + i);         i -= 2;       }     }     if (str.length() % 2) str.erase(str.end() - 1);     cout << n - str.length() << endl;     cout << str << endl;   }
#include <bits/stdc++.h>   using namespace std;   int Map[15][15] = {0}, ro[15] = {0}, co[15] = {0};   int main() {     int r, c, n, k, r1, c1, i, j, l1, l2, l3, l4, ans = 0, sum = 0;     scanf( %d%d%d%d , &r, &c, &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d%d , &r1, &c1);       Map[r1][c1] = 1;     }     for (i = 1; i <= r; i++) {       for (j = i; j <= r; j++) {         for (l1 = 1; l1 <= c; l1++) {           for (l2 = l1; l2 <= c; l2++) {             for (l3 = i; l3 <= j; l3++) {               for (l4 = l1; l4 <= l2; l4++) {                 sum += Map[l3][l4];               }             }             if (sum >= k) {               ans++;             }             sum = 0;           }         }       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 60;   long long fib[MAXN];   int main() {     int n;     long long k;     cin >> n >> k;     fib[0] = 1;     fib[1] = 1;     for (int i = 2; i <= n; i++) fib[i] = fib[i - 1] + fib[i - 2];     int i = 0;     while (i < n) {       if (fib[n - i - 1] < k) {         k -= fib[n - i - 1];         cout << i + 2 <<     << i + 1 <<    ;         i += 2;       } else {         cout << i + 1 <<    ;         i++;       }     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int cnt;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> k;       cnt = 0;       if (k == 1 || k == 2 || k == 3 || k == 5 || k == 7 || k == 11) {         cout << -1 << endl;       } else {         if (k % 4 == 3) {           k = k - 15;           cnt = 2;         } else if (k % 4 == 2) {           k = k - 6;           cnt = 1;         } else if (k % 4 == 1) {           k = k - 9;           cnt = 1;         }         cnt = cnt + (k / 4);         cout << cnt << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string S;   int MOD;   int len;   long long dp[1 << 18][100];   int cnt[1 << 18];   int bits[1 << 18];   int DMASKS[1 << 18];   int powers[20];   int orig;   long long solve(int mask, int mod) {     if (mask == 0) {       return mod == 0;     }     long long &ret = dp[mask][mod];     if (ret != -1) return ret;     ret = 0;     int pos = len - cnt[mask];     int dMask = pos == 0;     int m = mask;     while (m > 0) {       int b = m & -m;       if (!(dMask & (1 << (S[bits[b]] -  0 )))) {         ret += solve(mask ^ b,                      (mod + powers[len - pos - 1] * (S[bits[b]] -  0 )) % MOD);         dMask |= 1 << (S[bits[b]] -  0 );       }       m -= b;     }     return ret;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> S >> MOD;     len = S.size();     powers[0] = 1;     powers[0] %= MOD;     for (int i = 1; i < 20; i++) {       powers[i] = powers[i - 1] * 10;       powers[i] %= MOD;     }     for (int i = 0; i < 18; i++) {       bits[1 << i] = i;     }     for (int i = 0, to = 1 << 18; i < to; i++) {       cnt[i] = __builtin_popcount(i);     }     orig = (1 << len) - 1;     cout << solve(orig, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 220000;   vector<int> e1[M], e2[M];   int p[M], dis[M];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       e1[u].push_back(v);       e2[v].push_back(u);     }     int k;     cin >> k;     for (int i = 0; i < k; i++) cin >> p[i];     queue<int> q;     q.push(p[k - 1]);     dis[p[k - 1]] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : e2[u]) {         if (dis[v] == 0) {           dis[v] = dis[u] + 1;           q.push(v);         }       }     }     int mi = 0, mx = 0;     for (int i = 0; i < k - 1; i++) {       if (dis[p[i]] != dis[p[i + 1]] + 1) ++mi;       for (int v : e1[p[i]]) {         if (v != p[i + 1] && dis[v] == dis[p[i]] - 1) {           ++mx;           break;         }       }     }     cout << mi <<     << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     if (n == 1 || n == 2) {       cout << n <<   n ;       return 0;     }     int ans = 2, temp = 2;     for (int i = 2; i < n; i++) {       if (a[i] == a[i - 1] + a[i - 2]) {         temp++;         ans = max(ans, temp);       } else {         temp = 2;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double Pi = 3.14159265358979323;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     double x0, y0, v, T, n, x, y, r;     vector<tuple<double, double> > c;     cin >> x0 >> y0 >> v >> T;     T = v * T * 1.0;     cin >> n;     while (n--) {       cin >> x >> y >> r;       double angulo, d, adiff;       d = sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));       if (d * d <= r * r || (x == x0 && y == y0)) {         cout <<  1.000 n ;         return 0;       }       if (r == 0) continue;       if (d * d >= ((r + T) * (r + T))) continue;       angulo = atan2(y - y0, x - x0);       if (angulo < 0) {         angulo += 2 * Pi;       }       if (sqrt(d * d - r * r) <= T) {         adiff = asin(r / d);       } else {         adiff = acos((-r * r + T * T + d * d) / (2 * T * d));       }       double x1 = angulo - adiff;       if (x1 < 0) x1 = 2 * Pi + x1;       c.push_back(make_tuple(x1, 1));       x1 = angulo + adiff;       if (x1 > 2 * Pi) x1 -= 2 * Pi;       c.push_back(make_tuple(x1, -1));     }     sort(c.begin(), c.end());     double s = 0.0;     int in = 0, fin = -1;     vector<int> sweep(c.size(), 0);     while (in != fin && c.size() != 0) {       double angulo, con;       if (fin == -1 && in == 0) fin = 0;       tie(angulo, con) = c[in];       if (con == -1 && s == 0) fin = in;       if (con == -1 && s > 0)         s--;       else if (con == 1)         s++;       sweep[in] += s;       in++;       in %= c.size();     }     in = -1;     for (int i = 0; i < c.size(); i++) {       if (sweep[i] == 0) {         in = i;         in++;         in %= c.size();         break;       }     }     if (in == -1 && c.size() != 0) {       cout <<  1.00 ;       return 0;     }     fin = -1;     double sum = 0.0, an = -1;     while (c.size() != 0 && in != fin) {       if (fin == -1) fin = in;       if (sweep[in] == 1 && an == -1) an = get<0>(c[in]);       if (sweep[in] == 0) {         if (get<0>(c[in]) < an)           sum += get<0>(c[in]) - an + 2 * Pi;         else           sum += get<0>(c[in]) - an;         an = -1;       }       in++;       in %= c.size();     }     cout << setprecision(20) << (sum / (2 * Pi)) <<   n ;     return 0;   }
#include<bits/stdc++.h>   // #include <ext/pb_ds/assoc_container.hpp>   // #include <ext/pb_ds/tree_policy.hpp>   // using namespace __gnu_pbds;   using namespace std;   // typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   #define ll long long    #define scn(n) scanf( %d ,&n)   #define lscn(n) scanf( %lld ,&n)   #define lpri(n) printf( %lld ,n)   #define pri(n) printf( %d ,n)   #define pln() printf(  n )   #define priln(n) printf( %d n ,n)   #define lpriln(n) printf( %lld n ,n)   #define rep(i,init,n) for(int i=init;i<n;i++)   #define pb push_back        #define mp make_pair   #define F first   #define S second   #define gcd __gcd   #define inf INT_MAX   #define ninf INT_MIN      #define inf INT_MAX   #define linf LLONG_MAX   #define lninf LLONG_MIN      const int mod = 1e9 + 7;   const int N = 2e5 + 4;      int solve()   {    int n; scn(n);       string s; cin >> s;       vector<int> pre(n + 1, 0), suf(n + 1, 0);       rep(i, 1, n + 1)    {     pre[i] = 1;        if(i - 2 >= 0 and s[i - 1] != s[i - 2])     pre[i] += pre[i - 1];    }       for(int i = n; i >= 1; i--)    {     suf[i] = 1;        if(i < n and s[i - 1] != s[i])     suf[i] += suf[i + 1];    }       rep(i, 0, n + 1)    {     if(i == 0)     {      if(s[i] ==  R )      printf( %d  , suf[i + 1] + 1);      else      printf( 1  );     }     else if(i == n)     {      if(s[i - 1] ==  L )      printf( %d  , pre[i] + 1);      else      printf( 1  );     }     else     {      int ans = 1;         if(s[i] ==  R )      ans += suf[i + 1];         if(s[i - 1] ==  L )      ans += pre[i];         printf( %d  , ans);     }    }       return 0;   }      int main()                     {    int t = 1; scn(t);       while(t--)    {     solve();    }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[200005];   int cnt[400005];   int cv[400005];   int main() {     int t;     scanf( %d , &t);     while (t--) {       memset(cnt, 0, sizeof(cnt));       memset(cv, 0, sizeof(cv));       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i * 2 <= n; i++) {         cnt[a[i] + a[n - i + 1]]++;         cv[min(a[i], a[n - i + 1]) + 1]++, cv[max(a[i], a[n - i + 1]) + k + 1]--;       }       for (int i = 3; i <= 2 * k; i++) cv[i] += cv[i - 1];       int ans = 200005;       for (int x = 2; x <= 2 * k; x++) {         ans = min(ans, n - cnt[x] - cv[x]);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000];   vector<int> adjNos[100001];   vector<long long int> diff;   int main() {     int n;     int m;     long long int sum = 0;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       if (i < m - 1) {         if (a[i] != a[i + 1]) {           adjNos[a[i]].push_back(a[i + 1]);           adjNos[a[i + 1]].push_back(a[i]);         }       }     }     long long int beforeSum;     long long int afterSum;     int vlen;     int median;     for (int i = 1; i <= n; i++) {       vlen = adjNos[i].size();       if (vlen == 0) {         continue;       }       sort(adjNos[i].begin(), adjNos[i].end());       median = adjNos[i][vlen / 2];       beforeSum = 0;       afterSum = 0;       for (int j = 0; j < vlen; j++) {         beforeSum += abs(i - adjNos[i][j]);         afterSum += abs(median - adjNos[i][j]);       }       diff.push_back(beforeSum - afterSum);       sum += beforeSum;     }     sum /= 2;     if (diff.size() != 0) {       sum -= *max_element(diff.begin(), diff.end());     }     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct node_t {     int l, r, k, id;     friend bool operator<(const node_t& a, const node_t& b) {       if (a.r == b.r) return a.l > b.l;       return a.r < b.r;     }     void print() { printf( l = %d, r = %d, k = %d, id = %d n , l, r, k, id); }   } node_t;   const int maxn = 1e5 + 5;   node_t Q[maxn], P[maxn];   int ans[maxn];   int main() {     ios::sync_with_stdio(false);     int n, m;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d , &Q[i].l, &Q[i].r);       Q[i].id = i;     }     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       scanf( %d %d %d , &P[i].l, &P[i].r, &P[i].k);       P[i].id = i + 1;     }     sort(Q, Q + n);     sort(P, P + m);     set<pair<int, int> > st;     set<pair<int, int> >::iterator iter, titer;     int i, j, k;     i = 0;     for (j = 0; j < m; ++j) {       while (i < n && Q[i].r <= P[j].r) {         st.insert(make_pair(Q[i].l, Q[i].id));         ++i;       }       iter = st.lower_bound(make_pair(P[j].l, -1));       while (iter != st.end() && P[j].k-- > 0) {         ans[iter->second] = P[j].id;         titer = iter;         iter++;         st.erase(titer);       }     }     if (i < n || st.size() > 0) {       puts( NO );     } else {       puts( YES );       for (int i = 0; i < n; ++i) {         printf( %d  , ans[i]);       }       putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   long long SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   long long SIZE(const T &t) {     return t.size();   }   string to_string(const string s, long long x1 = 0, long long x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(const bool b) { return (b ?  true  :  false ); }   string to_string(const char c) { return string({c}); }   template <size_t N>   string to_string(const bitset<N> &b, long long x1 = 0, long long x2 = 1e9) {     string t =   ;     for (long long __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(const A(&v), long long x1 = 0, long long x2 = 1e9,                    C... coords);   long long l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(const pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(const A(&v), long long x1, long long x2, C... coords) {     long long rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgm() { ; }   template <typename Heads, typename... Tails>   void dbgm(Heads H, Tails... T) {     cerr << to_string(H) <<   |  ;     dbgm(T...);   }   void FIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long N = 2e5 + 6;   int32_t main() {     FIO();     long long tc;     cin >> tc;     while (tc--) {       long long n, m;       cin >> m >> n;       vector<vector<long long> > a(m, vector<long long>(n));       vector<long long> v(n, -1);       for (long long i = 0; i < m; i++) {         for (long long j = 0; j < n; j++) {           cin >> a[i][j];           v[j] = max(v[j], a[i][j]);         }       }       long long ans = 1e18;       for (long long i = 0; i < n; i++) ans = min(ans, v[i]);       if (n <= m) {         long long val = -1;         for (long long i = 0; i < m; i++) {           sort(a[i].begin(), a[i].end());           val = max(val, a[i][n - 2]);         }         ans = min(ans, val);       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 7;   const int base = 19260817;   int a[mx];   int n;   unsigned long long hs[mx * 2];   void init() {     hs[0] = 1;     for (int i = 1; i <= 2 * n; i++) hs[i] = hs[i - 1] * base;   }   int main() {     int m, x;     scanf( %d , &n);     init();     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     scanf( %d , &m);     unsigned long long ans = 0, cur = 0;     long long sum = 0;     int p = 1, go = 1;     for (int i = 1; i <= m; i++) {       scanf( %d , &x);       ans += hs[x - 1];     }     if (m == 1) {       printf( 0 n );       return 0;     }     int pre = 0;     for (int i = 1; i <= m; i++) {       sum += (i == 1 ? 0 : abs(a[p] - a[pre]));       cur += hs[p - 1];       pre = p;       p += go;       if (p == n)         go = -1;       else if (p == 1)         go = 1;     }     set<long long> s;     if (cur == ans) s.insert(sum);     for (int i = 2; i <= 2 * n - 2; i++) {       cur -= i > n ? hs[2 * n - i] : hs[i - 2];       int end = i + (m - 1) % (2 * n - 2);       while (end > 2 * n - 2) end -= 2 * n - 2;       cur += end > n ? hs[2 * n - end - 1] : hs[end - 1];       sum -= abs(i <= n ? a[i] - a[i - 1] : a[2 * n - i] - a[2 * n - i + 1]);       sum += abs(end <= n ? (end == 1 ? a[2] - a[1] : a[end] - a[end - 1])                           : a[2 * n - end] - a[2 * n - end + 1]);       if (cur == ans) {         s.insert(sum);       }     }     if (s.size() != 1)       printf( -1 n );     else       printf( %lld n , *s.begin());     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   void rot(int n, int *x, int *y, int rx, int ry);   int xy2d(int n, int x, int y) {     int rx, ry, s, d = 0;     for (s = n / 2; s > 0; s /= 2) {       rx = (x & s) > 0;       ry = (y & s) > 0;       d += s * s * ((3 * rx) ^ ry);       rot(s, &x, &y, rx, ry);     }     return d;   }   void d2xy(int n, int d, int *x, int *y) {     int rx, ry, s, t = d;     *x = *y = 0;     for (s = 1; s < n; s *= 2) {       rx = 1 & (t / 2);       ry = 1 & (t ^ rx);       rot(s, x, y, rx, ry);       *x += s * rx;       *y += s * ry;       t /= 4;     }   }   void rot(int n, int *x, int *y, int rx, int ry) {     int t;     if (ry == 0) {       if (rx == 1) {         *x = n - 1 - *x;         *y = n - 1 - *y;       }       t = *x;       *x = *y;       *y = t;     }   }   int main() {     int a, b;     cin >> a >> b;     int x, y;     d2xy(1 << a, b, &x, &y);     cout << x <<     << y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s[60];     while (scanf( %s , s) == 1) {       int k = strlen(s);       int sum = 0;       for (int i = 0; i < k / 2; i++) {         if (s[i] == s[k - i - 1]) sum++;       }       int ans = k;       if (sum == k / 2) ans -= 1;       int t = 0;       if (ans == k - 1) {         for (int i = 1; i <= (k - 1) / 2; i++) {           if (s[i] == s[k - i]) t++;         }         if (t == (k - 1) / 2) ans = 0;       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   unsigned seed = chrono::system_clock::now().time_since_epoch().count();   mt19937 eng(seed);   long long random2() { return (1ll << 31ll) * eng() + eng(); }   long long n, m, k, q, T;   const long long big = 1000000007;   const long long big2 = 1000000009;   const long long mod = 998244353;   const int MAXN = 300001;   long long PATH[401][401] = {0};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long a, b, c, d, e;     cin >> k;     for (int c1 = 0; c1 < (401); ++c1) {       for (int c2 = 0; c2 < (401); ++c2) {         if (c1 == 0 && c2 == 1) PATH[c1][c2] = 1;         if (c2 == 0) PATH[c1][c2] = 1;       }     }     for (int i = 1; i < (k); ++i) {       for (long long r = 1; r < k + 1; r++) {         for (int x = 0; x < (r + 2); ++x) {           if (x < r)             PATH[i][r] += (PATH[i - 1][x] * PATH[i - 1][r - 1 - x]) % big;           if (x < r + 1)             PATH[i][r] +=                 (1 + 2 * r) * ((PATH[i - 1][x] * PATH[i - 1][r - x]) % big);           PATH[i][r] %= big;           PATH[i][r] +=               r * (r + 1) * ((PATH[i - 1][x] * PATH[i - 1][r - x + 1]) % big);           PATH[i][r] %= big;         }       }     }     cout << PATH[k - 1][1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9, maxn = (int)1e5 + 1;   const double eps = (double)1e-8;   const int mod = (int)1000000007;   int c[200009], a[200009], t, k, f, n;   vector<int> b[200009], o;   int main() {     cin >> n;     memset((c), 0, sizeof(c));     ;     for (int i = (1); i <= (n); i++) {       scanf( %d , &(a[i]));       b[a[i]].push_back(i);     }     k = 0;     t = 1;     for (int i = 1; i <= n && t; i++) {       if (b[k].size() == c[k]) {         t = 0;         break;       }       o.push_back(b[k][c[k]]);       c[k]++;       if (k - 2 < 0 || b[k - 2].size() == c[k - 2] ||           b[k - 1].size() == c[k - 1] || b[k].size() == c[k]) {         k++;         continue;       }       k -= 2;     }     if (t) {       cout <<  Possible  << endl;       for (int i = 0; i < o.size(); i++) {         cout << o[i] <<    ;       }       return 0;     }     k--;     for (int i = n; i >= 0; i--) {       if ((b[i].size() != c[i] && i >= k) || (b[i].size() > c[i] + 1)) {         cout <<  Impossible ;         return 0;       }       if (b[i].size() == c[i] + 1 && (i == 0 || b[i - 1].size() == c[i - 1])) {         if ((k - i + 1) % 3 != 0) {           cout <<  Impossible ;           return 0;         }         k = i;         o.push_back(b[i][c[i]]);         if (b[i + 1].size() != c[i + 1]) {           o.push_back(b[i + 1][c[i + 1]]);           k = i + 1;         }       }     }     cout <<  Possible  << endl;     for (int i = 0; i < o.size(); i++) {       cout << o[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     ios::sync_with_stdio(false);     long long int n, m, i, j, k, ans = 0;     cin >> n >> m;     long long int A[n], B[m];     string str(500,  0 );     for (i = 0; i < n; i++) cin >> A[i];     for (i = 0; i < m; i++) {       cin >> k;       k--;       B[i] = k;     }     for (i = 0; i < m; i++) {       j = i - 1;       str = string(500,  0 );       while (j >= 0 && B[j] != B[i]) {         if (str[B[j]] !=  1 ) {           ans += A[B[j]];           str[B[j]] =  1 ;         }         j--;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   static const int MAXN = 2e5 + 4;   static const int MAXK = 2e5 + 3;   static int n, k;   static std::pair<int, int> p[MAXN];   static int idx[MAXN];   static std::vector<int> q[MAXN];   static int ans[MAXN];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %d , &p[i].first);       p[i].second = i;     }     for (int i = 0, u, v; i < k; ++i) {       scanf( %d%d , &u, &v);       --u, --v;       q[u].push_back(v);       q[v].push_back(u);     }     std::sort(p, p + n);     for (int i = 0; i < n; ++i) idx[p[i].second] = i;     for (int i = 0, j; i < n;) {       for (j = i + 1; j < n && p[j].first == p[i].first; ++j)         ;       for (int count = i; i < j; ++i) {         int r = count;         for (int t : q[p[i].second])           if (p[idx[t]].first < p[i].first) --r;         ans[p[i].second] = r;       }     }     for (int i = 0; i < n; ++i) printf( %d%c , ans[i], i == n - 1 ?   n  :    );     return 0;   }