malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void IO(T &x) {     char c = getchar();     T sgn = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     x = 0;     while (c >=  0  && c <=  9 ) {       x = (T)(x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     x *= sgn;   }   template <class T>   T POW(T b, T push) {     T res = 1;     while (push > 0) {       if (push & 1) res *= b;       push >>= (1ll), b *= b;     }     return res;   }   template <class T>   T bMOD(T a, T push, T m) {     if (push == 0) return (T)1;     if (!(push & 1)) {       T temp = bMOD(a, push / 2, m);       return ((temp % m) * (temp % m)) % m;     }     return ((a % m) * (bMOD(a, push - 1, m) % m)) % m;   }   template <class T>   T inMOD(T a, T m) {     return bMOD(a, m - 2, m);   }   template <class T>   bool isPrime(T n) {     for (T i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   template <class T>   string toString(T n) {     stringstream second;     string num;     second << n;     second >> num;     return num;   }   template <class T>   T sq(T n) {     return (n * n);   }   template <class T>   T gcd(T a, T b) {     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   bool iseq(double a, double b) { return fabs(a - b) < 1e-9; }   template <class T>   T toDeg(T x) {     return (180.0 * x) / ((T)acos(-1.0));   }   template <class T>   T toReg(T x) {     return (x * (T)acos(-1.0)) / (180.0);   }   template <class T>   double _distance(T x1, T y1, T x2, T y2) {     return 1.0 * sqrt(sq(x1 - x2) + sq(y1 - y2));   }   int kx[] = {-2, -2, +2, +2, +1, -1, +1, -1};   int ky[] = {+1, -1, +1, -1, -2, -2, +2, +2};   int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};   int dy[] = {+1, -1, +0, +0, -1, +1, +1, -1};   int x[] = {+0, +0, +1, -1};   int y[] = {+1, -1, +0, +0};   int main() {     int h1, m1, h2, m2;     scanf( %d:%d , &h1, &m1);     scanf( %d:%d , &h2, &m2);     int hour = h1 * 60 + h2 * 60 + m1 + m2;     hour /= 2;     int hm = hour / 60;     int mm = hour % 60;     if (hm < 10) {       printf( 0%d: , hm);     } else {       printf( %d: , hm);     }     if (mm < 10) {       printf( 0%d n , mm);     } else {       printf( %d n , mm);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   pair<int, int> A[N];   int factorial[N];   int twos[N];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = (int)0; i < (int)2 * n; i++) {       cin >> A[i].first;       A[i].second = i % n;     }     sort(A, A + 2 * n);     int MOD;     cin >> MOD;     factorial[0] = 1;     twos[0] = 0;     for (int i = (int)1; i < (int)2 * n + 1; i++) {       if (i % 2 == 0)         twos[i] = 1 + twos[i / 2];       else         twos[i] = 0;       int ti = i;       while (ti % 2 == 0) ti /= 2;       factorial[i] = (ti * (long long int)factorial[i - 1]) % MOD;     }     for (int i = (int)0; i < (int)2 * n; i++) twos[i + 1] += twos[i];     n *= 2;     int ans = 1;     for (int i = 0; i < n;) {       int endi = i;       while (endi < n and A[endi].first == A[i].first) endi++;       int numduplicates = 0;       for (int j = (int)i; j < (int)endi; j++)         if (j + 1 < endi and A[j].second == A[j + 1].second) numduplicates++;       int len = endi - i;       ans = (ans * (long long int)factorial[len]) % MOD;       int ntwos = twos[len] - numduplicates;       for (int x = (int)0; x < (int)ntwos; x++) {         ans = (ans * 2) % MOD;       }       i = endi;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     if (b == 0) return 1;     long long int p = power(a, b / 2);     if (b % 2 == 0)       return p * p;     else       return a * p * p;   }   long int gcd(long int a, long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     std::ios_base::sync_with_stdio(false);     long long int n, i, j, k, c = 0;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     vector<long int> fac;     for (i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (i > 2) fac.push_back(i);         if (n != i * i) fac.push_back(n / i);       }     }     for (i = 0; i < fac.size(); i++) {       for (j = 0; j < n / fac[i]; j++) {         c = 0;         for (k = j; k < n; k += n / fac[i]) {           if (a[k] != 1)             break;           else             c++;         }         if (c == fac[i]) break;       }       if (j != n / fac[i]) break;     }     if (i != fac.size())       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   int N, M, A, B;   char table[60][60];   int rows[60];   int cols[60];   int solve() {     scanf( %d%d%d%d , &N, &M, &A, &B);     if (A * N != B * M) {       puts( NO );       return 0;     }     memset(table, 0, sizeof(table));     memset(rows, 0, sizeof(rows));     memset(cols, 0, sizeof(cols));     std::vector<std::pair<int, int>> sorted_cols;     for (int i = 0; i < N; ++i) {       for (int j = 0; j < M; ++j) {         table[i][j] =  0 ;       }       sorted_cols.clear();       for (int j = 0; j < M; ++j) {         sorted_cols.push_back(std::make_pair(cols[j], j));       }       std::sort(sorted_cols.begin(), sorted_cols.end());       for (int j = 0; j < A; ++j) {         int col_index = sorted_cols[j].second;         int col_value = sorted_cols[j].first;         if (col_value >= B) {           puts( NO );           return 0;         }         table[i][col_index] =  1 ;         ++rows[i];         ++cols[col_index];       }     }     puts( YES );     for (int i = 0; i != N; ++i) {       puts(table[i]);     }     return 0;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main(int argc, char const *argv[]) {     string a;     cin >> a;     long long n = a.length();     char p[n];     p[0] = a[0];     long long i;     for (i = 1; i < n; i++) p[i] = (p[i - 1] > a[i]) ? a[i] : p[i - 1];     for (int i = 0; i < int(n); i++) {       if (a[i] > p[i])         cout <<  Ann  << endl;       else         cout <<  Mike  << endl;     }   }
#include <bits/stdc++.h>   const double pi = acos(-1.0);   const int maxn = (5e2 + 10);   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   using namespace std;   map<long long, long long> ys;   long long a[200010];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n;     long double ans = 0, sum = 0;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];       ys[a[i]] += 1;     }     for (long long i = 1; i <= n; i++) {       ans += sum - (long double)(n - i + 1) * (long double)a[i];       ans += ys[a[i] - 1] - ys[a[i] + 1];       sum -= a[i];       ys[a[i]] -= 1;     }     cout << fixed << setprecision(0) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct query {     int id, n;   };   vector<query> ql[101000];   query now;   int m, len, n, ans[101000], sum[101000], qm, fac[201000], inv[201000],       ex[110000];   char str[101000];   const int mod = 1e9 + 7;   int power(int a, int n) {     if (n == 0) return 1;     int res = power(a, n / 2);     res = (int)((long long)res * (long long)res % mod);     if (n % 2) res = (int)((long long)res * (long long)a % mod);     return res;   }   int main() {     int i, j, s, p, q, flag, sz = 0, tmp;     qm = (int)((long long)25 * (long long)power(26, mod - 2) % mod);     for (i = 0; i <= 100000; i++) {       if (i == 0)         ex[i] = 1;       else         ex[i] = (int)((long long)ex[i - 1] * (long long)qm % mod);     }     for (i = 0; i <= 200000; i++) {       if (i == 0)         fac[i] = 1;       else         fac[i] = (int)((long long)fac[i - 1] * (long long)i % mod);     }     inv[200000] = power(fac[200000], mod - 2);     for (i = 199999; i >= 0; i--)       inv[i] = (int)((long long)(i + 1) * (long long)inv[i + 1] % mod);     scanf( %d%s , &m, str);     len = strlen(str);     while (m--) {       scanf( %d , &flag);       if (flag == 1) {         scanf( %s , str);         len = strlen(str);       } else {         scanf( %d , &n);         now.id = sz++;         now.n = n;         ql[len].push_back(now);       }     }     for (i = 1; i <= 100000; i++) {       int ax = 0;       for (j = 0; j < ql[i].size(); j++) {         if (ax < ql[i][j].n) ax = ql[i][j].n;       }       for (j = 0; j <= ax - i; j++) {         tmp = (int)((long long)fac[j + i - 1] * (long long)inv[j] % mod);         tmp = (int)((long long)tmp * (long long)inv[i - 1] % mod);         tmp = (int)((long long)tmp * (long long)ex[j] % mod);         if (j > 0)           sum[j] = (sum[j - 1] + tmp) % mod;         else           sum[j] = tmp;       }       for (j = 0; j < ql[i].size(); j++) {         if (ql[i][j].n < i)           ans[ql[i][j].id] = 0;         else           ans[ql[i][j].id] = (int)((long long)power(26, ql[i][j].n - i) *                                    (long long)sum[ql[i][j].n - i] % mod);       }     }     for (i = 0; i < sz; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INF = 1000000007;   string s;   int n, k, c, v, ans;   int fat[1000100], siz[1000100];   vector<int> edge[1000100];   struct node {     int l, r, xo;     node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {}     int get() { return min(l, r); }     void operator+=(node th) {       l += th.l;       r += th.r;       if (l > INF) l = INF;       if (r > INF) r = INF;     }   } val[1000100];   pair<int, int> uu, vv;   pair<int, int> trace(int x) {     if (fat[x] < 0) return make_pair(x, 0);     pair<int, int> pp = trace(fat[x]);     fat[x] = pp.first;     val[x].xo ^= pp.second;     return make_pair(fat[x], val[x].xo);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k >> s;     s =  ?  + s;     for (int i = 1; i <= k; i++) {       fat[i] = -1;       siz[i] = 1;       val[i] = node(1, 0, 0);       cin >> c;       for (int j = 1; j <= c; j++) {         cin >> v;         edge[v].push_back(i);       }     }     int ans = 0;     int id;     for (int i = 1; i <= n; i++) {       int tp = (s[i] -  0 ) ^ 1;       if (edge[i].size() == 1) {         id = edge[i][0];         uu = trace(id);         ans -= val[uu.first].get();         val[uu.first] += node((tp == uu.second) * INF, (tp != uu.second) * INF);         ans += val[uu.first].get();       } else if (edge[i].size() == 2) {         id = edge[i][0];         uu = trace(id);         id = edge[i][1];         vv = trace(id);         if (uu.first != vv.first) {           ans -= (val[uu.first].get() + val[vv.first].get());           if (siz[uu.first] > siz[vv.first]) swap(uu, vv);           if (uu.second ^ vv.second ^ tp) {             swap(val[vv.first].l, val[vv.first].r);             val[vv.first].xo = 1;           }           siz[uu.first] += siz[vv.first];           fat[vv.first] = uu.first;           val[uu.first] += val[vv.first];           ans += val[uu.first].get();         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     reverse(a.begin(), a.end());     reverse(b.begin(), b.end());     vector<long long> v(n, 0), u(m, 0);     for (long long i = 0; i < n; i++) {       if (a[i] ==  1 ) {         v[i] = 1;       }     }     for (long long i = 0; i < m; i++) {       if (b[i] ==  1 ) {         u[i] = 1;       }     }     for (long long i = m - 2; i >= 0; i--) {       u[i] += u[i + 1];     }     map<long long, long long> mp;     mp[0] = 1;     for (long long i = 1; i < 2 * pow(10, 5) + 4; i++) {       mp[i] = mp[i - 1] * 2 % 998244353;     }     long long ans = 0;     for (long long i = 0; i < min(v.size(), u.size()); i++) {       if (v[i] == 1) {         long long x = (mp[i] % 998244353 * u[i] % 998244353) % 998244353;         ans = (ans + x) % 998244353;       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long test = 1;     while (test--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s1 = 0, s2 = 0;     cin >> n;     vector<int> v1(n);     for (int i = 0; i < n; i++) cin >> v1[i];     cin >> m;     vector<int> v2(m);     for (int i = 0; i < m; i++) cin >> v2[i];     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     int res = 0;     while (s1 < n && s2 < m) {       if (abs(v1[s1] - v2[s2]) <= 1) {         res++;         s1++;         s2++;       } else if (v1[s1] > v2[s2])         s2++;       else         s1++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int N = 1500 + 5, lg = 27, mod = 5e4 + 7;   bool check(int a, int b, int c, int d) {     double k = 1.0 * (a + b + c + d) / 4;     double k1 = 1.0 * (b + c) / 2;     double k2 = d - a;     return k == k1 && k1 == k2 && a > 0 && b > 0 && c > 0 && d > 0;   }   void solve() {     int n;     cin >> n;     vector<int> v(4, 1e6 + 5);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     sort(v.begin(), v.end());     if (!n) {       cout <<  YES n             <<  1 n1 n3 n3 ;     } else {       if (n == 4) {         if (check(v[0], v[1], v[2], v[3])) {           cout <<  YES n ;         } else {           cout <<  NO ;         }       } else if (n == 1) {         cout <<  YES n ;         int x = v[0];         cout << x <<   n  << 3 * x <<   n  << 3 * x;       } else if (n == 2) {         v[3] = v[0] * 3;         v[2] = v[0] * 4 - v[1];         if (check(v[0], v[1], v[2], v[3])) {           cout <<  YES n ;           cout << v[2] <<   n  << v[3];         } else {           cout <<  NO n ;         }       } else {         for (int i = 1; i < 1505; i++) {           vector<int> k = v;           k.push_back(i);           sort(k.begin(), k.end());           if (check(k[0], k[1], k[2], k[3])) {             cout <<  YES n ;             cout << i;             return;           }         }         cout <<  NO ;       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     int testCases = 1;     while (testCases--) {       solve();     }   }
#include <bits/stdc++.h>   const int Maxn = 100000;   const int Maxv = 100000;   int n;   struct Node {     int x, y;     Node(int _x = 0, int _y = 0) { x = _x, y = _y; }     friend Node operator+(Node a, Node b) { return Node(a.x + b.x, a.y + b.y); }     friend Node operator-(Node a, Node b) { return Node(a.x - b.x, a.y - b.y); }     friend long long operator/(Node a, Node b) {       return 1ll * a.x * b.y - 1ll * a.y * b.x;     }     long long find_len() { return 1ll * x * x + 1ll * y * y; }   } a[Maxn * 6 + 5];   Node S;   bool cmp_1_less(Node a, Node b) {     if (a.x == b.x) {       return a.y < b.y;     }     return a.x < b.x;   }   bool cmp_1_equal(Node a, Node b) { return a.x == b.x && a.y == b.y; }   bool cmp_2(Node a, Node b) {     if ((a - S) / (b - S) == 0) {       return (a - S).find_len() < (b - S).find_len();     }     return (a - S) / (b - S) > 0;   }   int len;   int st[Maxn * 6 + 5], st_top;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y, v;       scanf( %d%d%d , &x, &y, &v);       if (x < v) {         a[++len] = Node(0, std::max(y - v + x, 0));         a[++len] = Node(0, std::min(y + v - x, Maxv));       } else {         a[++len] = Node(x - v, y);       }       if (x + v > Maxv) {         a[++len] = Node(Maxv, std::max(y - v + (Maxv - x), 0));         a[++len] = Node(Maxv, std::min(y + v - (Maxv - x), Maxv));       } else {         a[++len] = Node(x + v, y);       }       if (y < v) {         a[++len] = Node(std::max(x - v + y, 0), 0);         a[++len] = Node(std::min(x + v - y, Maxv), 0);       } else {         a[++len] = Node(x, y - v);       }       if (y + v > Maxv) {         a[++len] = Node(std::max(x - v + (Maxv - y), 0), Maxv);         a[++len] = Node(std::min(x + v - (Maxv - y), Maxv), Maxv);       } else {         a[++len] = Node(x, y + v);       }     }     std::sort(a + 1, a + 1 + len, cmp_1_less);     len = std::unique(a + 1, a + 1 + len, cmp_1_equal) - a - 1;     S = a[1];     std::sort(a + 2, a + 1 + len, cmp_2);     st[++st_top] = 1;     for (int i = 2; i <= len; i++) {       while (st_top > 1 &&              (a[i] - a[st[st_top]]) / (a[st[st_top]] - a[st[st_top - 1]]) >= 0) {         st_top--;       }       st[++st_top] = i;     }     st[0] = st[st_top], st[st_top + 1] = st[1];     int pos = -1;     double ans = 0;     for (int i = 1; i <= st_top; i++) {       Node e_a = a[st[i]] - a[st[i - 1]], e_b = a[st[i + 1]] - a[st[i]],            e_c = a[st[i + 1]] - a[st[i - 1]];       double tmp = sqrt(e_a.find_len()) * sqrt(e_b.find_len()) *                    sqrt(e_c.find_len()) / (std::abs(e_a / e_b));       if (tmp > ans) {         pos = i;         ans = tmp;       }     }     printf( %d %d n , a[st[pos - 1]].x, a[st[pos - 1]].y);     printf( %d %d n , a[st[pos]].x, a[st[pos]].y);     printf( %d %d n , a[st[pos + 1]].x, a[st[pos + 1]].y);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n > 6 + 10 + 14) {         if (n - (6 + 10 + 14) != 6 && n - (6 + 10 + 14) != 10 &&             n - (6 + 10 + 14) != 14) {           cout <<  YES  << endl;           cout << 6 <<     << 10 <<     << 14 <<     << n - 6 - 10 - 14 << endl;         } else if (n > 6 + 10 + 15) {           cout <<  YES  << endl;           cout << 6 <<     << 10 <<     << 15 <<     << n - 6 - 10 - 15 << endl;         } else {           cout <<  NO  << endl;         }       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<vector<int>> a(n, vector<int>(m));       map<int, vector<int>> raws;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }         raws[a[i][0]] = a[i];       }       for (int j = 0; j < m; j++) {         for (int i = 0; i < n; i++) {           cin >> a[i][j];         }         if (raws.find(a[0][j]) != raws.end()) {           for (int i = 0; i < n; i++) {             for (int x : raws[a[i][j]]) {               cout << x <<    ;             }             cout <<   n ;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   template <class T>   T addmod(T a, T b, T c) {     return (T)mod((long long)a + b, (long long)c);   }   template <class T>   T mulmod(T a, T b, T c) {     return (T)mod((long long)a * b, (long long)c);   }   template <class T>   T powmod(T a, T b, T c) {     return (T)mod(         b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c),                    (b & 1LL) ? a : 1LL, (long long)c)           : 1LL,         (long long)c);   }   template <class T>   void maxe(T &a, T b) {     a = max(a, b);   }   template <class T>   void mine(T &a, T b) {     a = min(a, b);   }   template <class T>   void mode(T &a, T b) {     a = mod(a, b);   }   template <class T>   void addmode(T &a, T b, T c) {     a = addmod(a, b, c);   }   template <class T>   void mulmode(T &a, T b, T c) {     a = mulmod(a, b, c);   }   template <class T>   void powmode(T &a, T b, T c) {     a = powmod(a, b, c);   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void geti(T &a) {     a = 0;     int b = 1, c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 1111;   int test;   int n, m, k, ans;   char s[N][N];   void work100() {     s[0][0] =  > ;     for (int i = 1; i < 100; i++) s[i][0] =  ^ ;     for (int i = 0; i < 100; i += 2) {       for (int j = 1; j < 49; j++) s[i][j] =  > ;       for (int j = 49; j < 98; j += 2) {         s[i][j] =  > ;         s[i][j + 1] =  . ;       }       s[i][99] =  v ;     }     for (int i = 1; i < 100; i += 2) {       for (int j = 1; j < 49; j++) s[i][100 - j] =  < ;       for (int j = 49; j < 98; j += 2) {         s[i][100 - j] =  < ;         s[i][99 - j] =  . ;       }       s[i][1] =  v ;     }     s[99][1] =  . ;     for (int i = 0; i < 100; i++) printf( %s n , s[i]);     puts( 1 1 );   }   int main() {     scanf( %d%d , &n, &m);     if (n == 3 || n == 5) {       if (n == 3)         printf( >vv n^<. n^.< n1 3 n );       else         printf( >...v nv.<.. n..^.. n>.... n..^.< n1 1 n );     } else       work100();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;   long long n;   int main() {     while (~scanf( %lld , &n)) {       for (long long i = 3;; i *= 3) {         if (n % i != 0) {           long long ans = n / i + 1;           printf( %lld n , ans);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void swap(int* a, int* b) {     int t = *a;     *a = *b;     *b = t;   }   int partition(int arr[], int arr2[], int arr3[], int arr4[], int arr5[],                 int low, int high) {     int pivot = arr[high];     int i = (low - 1);     for (int j = low; j <= high - 1; j++) {       if (arr[j] < pivot) {         i++;         swap(&arr[i], &arr[j]);         swap(&arr2[i], &arr2[j]);         swap(&arr3[i], &arr3[j]);         swap(&arr4[i], &arr4[j]);         swap(&arr5[i], &arr5[j]);       }     }     swap(&arr[i + 1], &arr[high]);     swap(&arr2[i + 1], &arr2[high]);     swap(&arr3[i + 1], &arr3[high]);     swap(&arr4[i + 1], &arr4[high]);     swap(&arr5[i + 1], &arr5[high]);     return (i + 1);   }   void quickSort(int arr[], int arr2[], int arr3[], int arr4[], int arr5[],                  int low, int high) {     if (low < high) {       int pi = partition(arr, arr2, arr3, arr4, arr5, low, high);       quickSort(arr, arr2, arr3, arr4, arr5, low, pi - 1);       quickSort(arr, arr2, arr3, arr4, arr5, pi + 1, high);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int a[n], b[n], c[n], cost[n], d[n];     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i] >> c[i] >> cost[i];       d[i] = i + 1;     }     quickSort(cost, a, b, c, d, 0, n - 1);     int index = -1;     bool found = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (a[i] < a[j] and b[i] < b[j] and c[i] < c[j]) {           found = false;           break;         }       }       if (found) {         index = d[i];         break;       }       found = true;     }     cout << index << endl;     return 0;   }