malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};   const int mod[2] = {1000000007, 1000000009};   const int p[2] = {29, 31};   const int maxn = 3000;   int add(int a, int b, int k) {     return a + b >= mod[k] ? a + b - mod[k] : a + b;   }   int mul(int a, int b, int k) { return 1LL * a * b % mod[k]; }   int sub(int a, int b, int k) { return a < b ? a - b + mod[k] : a - b; }   int pwr(int a, int k, int i) {     int res = 1;     while (k) {       if (k % 2) res = mul(res, a, i);       a = mul(a, a, i);       k /= 2;     }     return res;   }   int invmod(int a, int k) { return pwr(a, mod[k] - 2, k); }   int H[2][maxn], pinv[2][maxn];   pair<int, int> hsb, hse;   string t, sb, se;   pair<int, int> h(string a) {     for (int k = 0; k < 2; ++k) {       int pp = 1;       for (int i = 0; i < a.size(); ++i) {         H[k][i] = mul(a[i] -  a  + 1, pp, k), pp = mul(pp, p[k], k);         if (i) H[k][i] = add(H[k][i - 1], H[k][i], k);       }     }     return {H[0][a.size() - 1], H[1][a.size() - 1]};   }   pair<int, int> f(int i, int j) {     return {mul(pinv[0][i], i ? sub(H[0][j], H[0][i - 1], 0) : H[0][j], 0),             mul(pinv[1][i], i ? sub(H[1][j], H[1][i - 1], 1) : H[1][j], 1)};   }   vector<int> x, y;   vector<pair<int, int> > M;   int main() {     for (int k = 0; k < 2; ++k) {       pinv[k][0] = 1;       pinv[k][1] = invmod(p[k], k);       for (int i = 2; i < maxn; ++i)         pinv[k][i] = mul(pinv[k][i - 1], pinv[k][1], k);     }     cin >> t >> sb >> se;     hsb = h(sb);     hse = h(se);     h(t);     int cnt = 0, a = sb.size(), b = se.size(), c = t.size();     for (int i = 0; i + a - 1 < c; ++i)       if (hsb == f(i, i + a - 1)) x.push_back(i);     for (int i = 0; i + b - 1 < c; ++i)       if (hse == f(i, i + b - 1)) y.push_back(i);     for (int i : x)       for (int j : y)         if (i <= j && i + a <= j + b) M.push_back(f(i, j + b - 1));     sort(M.begin(), M.end());     int res = M.size() != 0;     for (int i = 1; i < M.size(); ++i) res += (M[i] != M[i - 1]);     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int n;   long long int dn[6010], dinamik2[6010];   int main() {     string ar;     string ar2;     cin >> ar;     cin >> ar2;     n = ((int)(ar2.size()));     long long res = 0;     for (int k = 0; k < ((int)(ar.size())); k++) {       for (int j = 0; j < ((int)(ar2.size())); j++) {         if (ar2[j] == ar[k]) dinamik2[j] = (dinamik2[j] + dn[j - 1] + 1) % MOD;         dinamik2[j + 1] = (dinamik2[j + 1] + dinamik2[j]) % MOD;       }       res = (res + dinamik2[n]) % MOD;       for (int j = 0; j < ((int)(ar2.size())); j++) dn[j] = dinamik2[j];       memset(dinamik2, 0, sizeof dinamik2);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     set<string> l;     int ans = 0;     while (getline(cin, s)) {       if (s ==   ) break;       if (s[0] ==  + ) {         l.insert(s.substr(1));       } else if (s[0] ==  - ) {         l.erase(s.substr(1));       } else {         int i = 0;         while (s[i] !=  : ) i++;         ans += ((int)s.size() - i - 1) * l.size();       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int pb, mb, bb, m;     cin >> pb >> mb >> bb >> m;     int s1 = 2 * pb;     int temp = 2 * m;     if (2 * m >= s1) {       cout << -1 << endl;       return 0;     }     int s2 = 2 * mb;     if (2 * m >= s2) {       cout << -1 << endl;       return 0;     }     int s3 = 2 * bb, c = 0;     for (int i = bb; i <= s3; i++) {       if (m <= i && temp >= i) {         s3 = i;         c = 1;         break;       }     }     if (c == 0) {       cout << -1 << endl;       return 0;     }     cout << s1 << endl;     cout << s2 << endl;     cout << s3 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, b;   struct node {     int x, y;   };   vector<node> ans;   void rua() {     ans.clear();     int n;     scanf( %d , &n);     cin >> a >> b;     for (int i = 0; i < n; i++)       if (a[i] != b[i])         for (int j = i + 1; j < n; j++) {           if (a[i] == a[j]) {             swap(a[j], b[i]);             ans.push_back({j, i});             break;           }           if (a[i] == b[j]) {             swap(a[j], b[j]);             ans.push_back({j, j});             swap(a[j], b[i]);             ans.push_back({j, i});             break;           }         }     if (a != b) {       printf( NO n );       return;     }     printf( YES n%d n , (int)ans.size());     for (auto i : ans) printf( %d %d n , i.x + 1, i.y + 1);   }   int main() {     int t;     scanf( %d , &t);     while (t--) rua();     return 0;   }
#include <bits/stdc++.h>   const int N = 100100;   struct Edge {     int weight, type;     int x, y;     int num;     bool operator<(const Edge& other) const {       return weight == other.weight ? type > other.type : weight < other.weight;     }   } edges[N];   int n, m;   int x[N], y[N];   bool b[N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &edges[i].weight, &edges[i].type);       edges[i].num = i;     }     std::sort(edges, edges + m);     int k = 0;     int ptrX = 0, ptrY = 2;     for (int i = 0; i < m; ++i) {       if (edges[i].type == 0) {         if (b[ptrX] && b[ptrY]) {           edges[i].x = ptrX;           edges[i].y = ptrY;           if (ptrX + 2 < ptrY)             ++ptrX;           else {             ptrX = 0;             ++ptrY;           }         } else {           puts( -1 );           return 0;         }       } else {         edges[i].x = k;         edges[i].y = k + 1;         b[k] = true;         b[k + 1] = true;         ++k;       }     }     for (int i = 0; i < m; ++i) {       int num = edges[i].num;       x[num] = edges[i].x;       y[num] = edges[i].y;     }     for (int i = 0; i < m; ++i) printf( %d %d n , x[i] + 1, y[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool fun(int n) {     if (n == 1) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int main() {     int n;     scanf( %d , &n);     if (fun(n))       printf( 1 n );     else if (n & 1) {       if (fun(n - 2)) {         printf( 2 n );       } else         printf( 3 n );     } else       printf( 2 n );   }
#include <bits/stdc++.h>   using namespace std;   bool jolmetsz(long long a, long long b, long long c, long long x1, long long y1,                 long long x2, long long y2) {     return -c - a * x1 < b * y1 && -c - a * x2 > b * y2;   }   int main() {     long long x1, x2, y1, y2, n, db = 0;     cin >> x1 >> y1 >> x2 >> y2 >> n;     if (y2 < y1) {       swap(y1, y2);       swap(x1, x2);     }     int lep = 0;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       if (jolmetsz(a, b, c, x1, y1, x2, y2) || jolmetsz(a, b, c, x2, y2, x1, y1))         db++;     }     cout << db << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     string str;     cin >> str;     bool flag = 0;     int start = 0;     set<int> s;     for (int i = 0; i < str.length(); i++) {       if (!flag && str[i] ==  0  && a[i] != i + 1) {         cout <<  NO  << endl;         return 0;       }       if (flag && str[i] ==  0 ) {         s.insert(a[i]);         for (int j = start; j <= i + 1; j++) {           if (s.find(j) == s.end()) {             cout <<  NO  << endl;             return 0;           }         }         s.clear();         flag = 0;       }       if (str[i] ==  1 ) {         s.insert(a[i]);         if (!flag) {           start = i + 1;         }         flag = 1;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<int> s;   int main() {     int x;     cin >> x;     s.insert(x);     for (;;) {       x++;       while (x % 10 == 0) x /= 10;       int sz = s.size();       s.insert(x);       if (sz == s.size()) {         printf( %d , s.size());         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int main() {     int n;     cin >> n;     int maxn = 0;     int x, y;     while (n--) {       scanf( %d %d , &x, &y);       maxn = max(maxn, x + y);     }     cout << maxn << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, w;     string s;     cin >> t;     while (t--) {       cin >> n >> s;       bool flag = 0;       if (n % 2) {         for (int i = 0; i < n; i += 2) {           if ((s[i] -  0 ) % 2) {             flag = 1;             break;           }         }         w = flag ? 1 : 2;         cout << w << endl;       } else {         for (int i = 1; i < n; i += 2) {           if ((s[i] -  0 ) % 2 == 0) {             flag = 1;             break;           }         }         w = flag ? 2 : 1;         cout << w << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int a[1111], x, n, s, y, o, oo;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (x == 0 || x == 100)         a[s++] = x;       else if (x < 10 && o == 0)         a[s++] = x, o = 1;       else if (x % 10 == 0 && oo == 0)         a[s++] = x, oo = 1;       else         y = x;     }     if (o == 0 && oo == 0 && y != 0) a[s++] = y;     cout << s << endl;     for (int i = 0; i < s; i++) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   double dist(long long x, long long y) { return sqrt(x * x + y * y); }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int test;     std::cin >> test;     double inf = 1000.0 * 1000.0 * 1000.0;     while (test--) {       long long w, h;       std::cin >> w >> h;       long long x1, y1, x2, y2;       std::cin >> x1 >> y1 >> x2 >> y2;       long long ww, hh;       std::cin >> ww >> hh;       double min_ans = inf;       int x_intersect = std::max(0ll, ww - x1);       int y_intersect = std::max(0ll, hh - y1);       if (x2 + x_intersect <= w) {         min_ans = std::min(min_ans, dist(x_intersect, 0ll));       }       if (y2 + y_intersect <= h) {         min_ans = std::min(min_ans, dist(y_intersect, 0ll));       }       x_intersect = std::max(0ll, ww - x1);       y_intersect = std::max(0ll, y2 - (h - hh));       if (x2 + x_intersect <= w) {         min_ans = std::min(min_ans, dist(x_intersect, 0ll));       }       if (y1 - y_intersect >= 0) {         min_ans = std::min(min_ans, dist(y_intersect, 0ll));       }       x_intersect = std::max(0ll, x2 - (w - ww));       y_intersect = std::max(0ll, hh - y1);       if (x1 - x_intersect >= 0) {         min_ans = std::min(min_ans, dist(x_intersect, 0ll));       }       if (y2 + y_intersect <= h) {         min_ans = std::min(min_ans, dist(y_intersect, 0ll));       }       x_intersect = std::max(0ll, x2 - (w - ww));       y_intersect = std::max(0ll, y2 - (h - hh));       if (x1 - x_intersect >= 0) {         min_ans = std::min(min_ans, dist(x_intersect, 0ll));       }       if (y1 - y_intersect >= 0) {         min_ans = std::min(min_ans, dist(y_intersect, 0ll));       }       std::cout.precision(20);       if (min_ans == inf) {         std::cout <<  -1 n ;       } else {         std::cout << min_ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 rnd(time(0));   ifstream in;   ofstream out;   const long long INF = LLONG_MAX;   const long double EPS = 1e-9;   const long double pi = 3.141592653589793238462643383279502884;   long long n;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     srand(time(0));     cin >> n;     long long l = 0;     long long r = 1e9;     long long k = 2;     cout <<  0 2  << endl;     cout.flush();     string x;     cin >> x;     if (x[0] ==  b ) swap(l, r);     for (long long i = 0; i < n - 1; i++) {       long long m = (l + r) >> 1;       cout << m <<     << k << endl;       cout.flush();       string x;       cin >> x;       if (x[0] ==  w )         l = m;       else         r = m;     }     cout << l <<     << k - 1 <<     << r <<     << k + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[2][501][501];   int main() {     int n, m, b, mod;     scanf( %d%d%d%d , &n, &m, &b, &mod);     int a[n + 1];     for (long i = 1; i <= n; i++) scanf( %d , &a[i]);     memset(c, 0, sizeof(c));     c[0][0][0] = 1;     for (long i = 1; i <= n; i++)       for (long j = 0; j <= m; j++)         for (long k = 0; k <= b; k++) {           c[(i & 1)][j][k] = c[(i & 1) ^ 1][j][k];           if (k >= a[i] && j > 0) c[(i & 1)][j][k] += c[(i & 1)][j - 1][k - a[i]];           c[(i & 1)][j][k] = c[(i & 1)][j][k] % mod;         }     int ans = 0;     for (int i = 0; i <= b; i++) {       ans += c[n & 1][m][i];       ans = ans % mod;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int N;     cin >> N;     long long int A[N];     for (long long int i = 0; i < N; i++) cin >> A[i];     map<long long int, long long int> M;     for (long long int i = 0; i < N; i++) {       if (A[i] != 0) M[A[i]]++;     }     cout << M.size() << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[10000], x[5], z1[10000], z2[10000], z3[10000], a = 0, b = 0, c = 0;     x[0] = {0}, x[1] = {0}, x[2] = {0};     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     for (int i = 1; i <= n; i++) {       if (arr[i] == 1) {         x[0] += 1;         z1[a] = i;         a++;       } else if (arr[i] == 2) {         x[1] += 1;         z2[b] = i;         b++;       } else if (arr[i] == 3) {         x[2] += 1;         z3[c] = i;         c++;       }     }     if (x[0] == 0 || x[1] == 0 || x[2] == 0) {       cout <<  0  << endl;       goto m;     }     sort(x, x + 3);     cout << x[0] << endl;     for (int i = 0; i < x[0]; i++) {       cout << z1[i] <<     << z2[i] <<     << z3[i] << endl;     }   m:     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 10;   struct pos {     double x, y;   } p[maxn];   int n;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf%lf , &p[i].x, &p[i].y);     double ans = 0x3f3f3f3f;     for (int i = 0; i < n; i++) {       pos a = p[i];       pos b = p[(i + 1) % n];       pos c = p[(i + 2) % n];       double dis = (double)(c.x - a.x) * (b.y - c.y) - (c.y - a.y) * (b.x - c.x);       if (dis < 0) dis = -dis;       dis = dis / (sqrt((c.x - a.x) * (c.x - a.x) + (c.y - a.y) * (c.y - a.y)));       dis = dis / 2;       ans = min(ans, dis);     }     printf( %f , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j, k, x, MOD = 1000000007, ans, a1, a2, b1, b2, a, b;     string s1, s2;     cin >> n >> s1 >> s2;     vector<vector<long long>> dp(n + 1, vector<long long>(4, 0));     dp[0][0] = 1;     for (i = 0; i < n; i++) {       for (j = 0; j < 4; j++) {         if (s1[i] ==  ? )           a1 = 0, a2 = 9;         else           a1 = s1[i] -  0 , a2 = a1;         if (s2[i] ==  ? )           b1 = 0, b2 = 9;         else           b1 = s2[i] -  0 , b2 = b1;         for (a = a1; a <= a2; a++) {           for (b = b1; b <= b2; b++) {             x = j;             if (a < b)               x |= 1;             else if (a > b)               x |= 2;             dp[i + 1][x] = (dp[i + 1][x] + dp[i][j]) % MOD;           }         }       }     }     ans = dp[n][3];     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   char a[55][55];   int u[55][55][4][2];   int d[] = {0, 1, 1, 0, 0, -1, -1, 0}, dp, cp = -1;   int ls[50010000];   int lsk;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %s , a[i] + 1);     m = strlen(a[1] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) a[i][j] -=  0 ;     int x = 1, y = 1;     for (int K = 0; K <= k - 1; K++) {       if (u[x][y][dp][cp == 1]) {         int pl = K - u[x][y][dp][cp == 1] + 1;         while (K < k) K += pl;         K -= pl;       }       u[x][y][dp][cp == 1] = K + 1;       int dx = x, dy = y;       while (a[dx][dy] == a[x][y]) dx += d[dp * 2], dy += d[dp * 2 + 1];       dx -= d[dp * 2], dy -= d[dp * 2 + 1];       int dcp = (dp + cp + 4) % 4;       while (a[dx][dy] == a[x][y]) dx += d[dcp * 2], dy += d[dcp * 2 + 1];       dx -= d[dcp * 2], dy -= d[dcp * 2 + 1];       if (a[dx + d[dp * 2]][dy + d[dp * 2 + 1]] > 0)         x = dx + d[dp * 2], y = dy + d[dp * 2 + 1];       else if (cp == -1)         cp = 1;       else         cp = -1, dp = (dp + 1) % 4;     }     printf( %d n , a[x][y]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   template <typename first, typename second>   ostream &operator<<(ostream &os, const pair<first, second> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const map<first, second> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   void faltu() { cerr <<   n ; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     while (n--) {       int m;       cin >> m;       vector<int> v(m);       for (int i = 0; i < m; i++) cin >> v[i];       while (!v.empty() && v.back() == 0) v.pop_back();       reverse((v).begin(), (v).end());       while (!v.empty() && v.back() == 0) v.pop_back();       int y = (int)v.size();       int ans = 0;       if (y == 1)         cout << 0 <<   n ;       else {         for (int i = 0; i < y; i++) {           if (v[i] == 0) ans++;         }         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, i, j, ii, jj, zx, xc, qw[200009], we[200009], pas, pi,       k[200009];   pair<pair<long long, long long>, long long> p[600009];   bool bo[200009], rko[200009];   vector<long long> v[200009];   deque<long long> de;   void dfsst(long long q, long long w, long long rr) {     if (rr > xc) {       xc = rr;       zx = q;     }     for (vector<long long>::iterator it = v[q].begin(); it != v[q].end(); it++) {       if ((*it) == w) continue;       dfsst((*it), q, rr + 1);     }   }   void dfsst2(long long q, long long w, long long rr) {     if (rr > xc) {       xc = rr;       zx = q;     }     for (vector<long long>::iterator it = v[q].begin(); it != v[q].end(); it++) {       if ((*it) == w) continue;       dfsst2((*it), q, rr + 1);     }   }   void dfs(long long q, long long w, long long rr) {     qw[q] = rr - 1;     for (vector<long long>::iterator it = v[q].begin(); it != v[q].end(); it++) {       if ((*it) == w) continue;       dfs((*it), q, rr + 1);     }   }   void dfs2(long long q, long long w, long long rr) {     if (d == 0) bo[q] = 1;     if (q == e) d = 1;     we[q] = rr - 1;     for (vector<long long>::iterator it = v[q].begin(); it != v[q].end(); it++) {       if ((*it) == w) continue;       dfs2((*it), q, rr + 1);     }     if (d == 0) bo[q] = 0;   }   void dfs3(long long q, long long w) {     if (q == zx) return;     pi++;     p[pi].first.first = q;     p[pi].first.second = zx;     p[pi].second = q;     for (vector<long long>::iterator it = v[q].begin(); it != v[q].end(); it++) {       if ((*it) == w) continue;       if (bo[(*it)] == 1) {         dfs3((*it), q);         return;       }     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a;     for (i = 1; i < a; i++) {       cin >> c >> d;       v[c].push_back(d);       v[d].push_back(c);       k[c]++;       k[d]++;     }     zx = 0;     xc = 0;     dfsst(1, 0, 1);     e = zx;     zx = 0;     xc = 0;     dfsst2(e, 0, 1);     dfs(e, 0, 1);     d = 0;     dfs2(zx, 0, 1);     for (i = 1; i <= a; i++) {       if (bo[i] == 0 && v[i].size() == 1) {         de.push_back(i);         rko[i] = 1;       }     }     while (de.size() != 0) {       c = de.front();       de.pop_front();       pas += max(qw[c], we[c]);       pi++;       if (qw[c] >= we[c]) {         p[pi].first.first = e;         p[pi].first.second = c;         p[pi].second = c;       } else {         p[pi].first.first = zx;         p[pi].first.second = c;         p[pi].second = c;       }       d = 0;       for (vector<long long>::iterator it = v[c].begin(); it != v[c].end();            it++) {         if (rko[(*it)] == 1) continue;         d = (*it);         break;       }       k[d]--;       if (d != 0 && bo[d] == 0 && k[d] == 1) {         de.push_back(d);         rko[d] = 1;       }     }     pas += qw[zx] * (qw[zx] + 1) / 2;     dfs3(e, 0);     cout << pas << endl;     for (i = 1; i <= pi; i++)       cout << p[i].first.first <<     << p[i].first.second <<     << p[i].second            << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool mysort(const pair<double, int> &a, const pair<double, int> &b) {     if (a.first == b.first)       return a.second < b.second;     else       return a.first > b.first;   }   int main() {     int n, t1, t2, k, a, b, i;     double h1, h2;     vector<pair<double, int> > vec;     cin >> n >> t1 >> t2 >> k;     for (i = 1; i <= n; i++) {       cin >> a >> b;       h1 = (1.0 * a * t1 * (100 - k) / 100) + b * t2;       h2 = (1.0 * b * t1 * (100 - k) / 100) + a * t1;       h1 = a * t1 * (1 - (k * 1.0) / 100) + b * t2;       h2 = b * t1 * (1 - (k * 1.0) / 100) + a * t2;       vec.push_back(make_pair(max(h1, h2), i));     }     sort(vec.begin(), vec.end(), mysort);     for (i = 0; i < vec.size(); i++)       cout << vec[i].second <<     << fixed << setprecision(2) << vec[i].first            << endl;   }
#include <bits/stdc++.h>   using namespace std;   int c[1000001];   int b[1000001];   int main() {     int n, i, l, r, m, kq = 1, a;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       cin >> a;       c[a] = i;       b[i] = 0;     }     cin >> a;     b[1] = c[a];     for (i = 2; i <= n; i++) {       cin >> a;       a = c[a];       l = 1;       r = i;       while (l < r) {         m = (l + r) / 2;         if (b[m] > a)           l = m + 1;         else           r = m;       }       b[r] = a;       if (kq < r) kq = r;     }     cout << kq;     return 0;   }