malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> v(n + 1);     for (int i = 1; i <= n; ++i) cin >> v[i];     int x, y;     scanf( %d %d , &x, &y);     for (int i = 1; i <= n; ++i) {       int a = 0, b = 0;       for (int j = 1; j <= n; ++j) {         if (j < i)           a += v[j];         else           b += v[j];       }       if (x <= a and a <= y and x <= b and b <= y) return !printf( %d n , i);     }     puts( 0 );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     long long int a[n], k = 0, sum = 0;     for (int x = 0; x < n; x++) {       cin >> a[x];     }     sort(a, a + n);     for (int x = 0; x < m; x++) {       if (a[x] < 0) {         sum += a[x];       }     }     cout << -sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, d[1010][101][2], ans, nf, p[1010];   int main() {     cin >> n >> k >> m;     p[0] = 1;     for (int i = 1; i <= n; i++) p[i] = p[i - 1] * 10 % k;     d[0][0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int x = (i == n); x < 10; x++)         for (int f = 0; f < k; f++) {           nf = (f + p[i - 1] * x) % k;           d[i][nf][1] += d[i - 1][f][1];           if (nf == 0 && x)             d[i][nf][1] += d[i - 1][f][0];           else             d[i][nf][0] += d[i - 1][f][0];           d[i][nf][0] %= m;           d[i][nf][1] %= m;         }     }     for (int i = 0; i < k; i++) ans = (ans + d[n][i][1]) % m;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool check(long n, long k) {     long dem = 0;     while (n > 0) {       long x = n % 10;       n /= 10;       (x == 4 || x == 7) ? dem++ : dem = dem;     }     if (dem <= k) return 1;     return 0;   }   int main() {     long n, k, dem = 0;     cin >> n >> k;     long a[n];     for (long i = 0; i < n; i++) {       cin >> a[i];       if (check(a[i], k) == 1) dem++;     }     cout << dem;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, i, j, k;     scanf( %d%d , &n, &m);     vector<int> A;     for (i = 0; i < n; i++) A.push_back(i + 1);     int M = 0;     do {       int s = 0;       for (i = 0; i < n; i++) {         for (j = i + 1; j < n + 1; j++) {           int s1 = 1000;           for (k = i; k < j; k++) s1 = min(s1, A[k]);           s += s1;         }       }       M = max(M, s);     } while (next_permutation(A.begin(), A.end()));     do {       int s = 0;       for (i = 0; i < n; i++) {         for (j = i + 1; j < n + 1; j++) {           int s1 = 1000;           for (k = i; k < j; k++) s1 = min(s1, A[k]);           s += s1;         }       }       if (s == M) {         m--;         if (m == 0) {           for (i = 0; i < n; i++) printf( %d  , A[i]);           return 0;         }       }     } while (next_permutation(A.begin(), A.end()));     printf( %d n , m);   }
#include <bits/stdc++.h>   using namespace std;   int n, num, k;   pair<int, int> a[200005];   bool comp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       cin >> n >> k;       unordered_map<int, int> mp;       int color = 1;       for (int i = 0; i < n; i++) {         cin >> a[i].first;         a[i].second = i;       }       sort(a, a + n);       for (int i = 0; i < n; i++) {         mp[a[i].first]++;         if (mp[a[i].first] > k)           a[i].first = 0;         else {           a[i].first = color;           if (color == k)             color = 1;           else             color++;         }       }       color--;       for (int i = n - 1; i >= 0; i--) {         if (a[i].first == color) {           a[i].first = 0;           color--;         }       }       sort(a, a + n, comp);       for (int i = 0; i < n; i++) cout << a[i].first <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1001];   int main() {     int n, t, i, j, k, m;     cin >> t;     while (t--) {       cin >> n >> m;       for (i = 0; i < n; i++) cin >> a[i];       int ans = a[0];       for (i = 1; i < n; i++) {         if (ans + a[i] <= m)           ans += a[i];         else {           ans = m;           break;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (long long &i : v) cin >> i;     sort(v.begin(), v.end(), [](long long a, long long b) { return a > b; });     vector<long long> sm(n);     sm[0] = v[0];     for (long long i = 1; i < n; ++i) {       sm[i] = sm[i - 1] + v[i];     }     long long num, cnt = 0;     for (long long i = 0; i < n; ++i) {       long long l = i, r = n;       while (r - l > 1) {         long long m = (l + r) / 2;         if ((m - i) * v[i] - (sm[m] - sm[i]) <= k)           l = m;         else           r = m;       }       if (l - i + 1 >= cnt) {         cnt = l - i + 1;         num = v[i];       }     }     cout << cnt <<     << num;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   struct C {     double x, y, r;   } base[3050];   double Ans;   int i, j, k;   long long dp[3050][2][2];   int N, mark[3050], fa[3050];   inline double dist(C A, C B) {     return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));   }   inline double get_S(C A) { return Pi * A.r * A.r; }   inline bool check_in(C A, C B) { return A.r + B.r > dist(A, B); }   namespace DP {   struct Edge {     int next, to;   } E[3050 << 1];   int head[3050], cnt;   inline void Add(int u, int v) {     E[++cnt].to = v, E[cnt].next = head[u], head[u] = cnt;     E[++cnt].to = u, E[cnt].next = head[v], head[v] = cnt;   }   void do_dp(int u, int faa) {     long long f[2][2];     memset(f, 0, sizeof(f));     for (int k = head[u]; k; k = E[k].next) {       if (E[k].to == faa) continue;       do_dp(E[k].to, u);       for (int ii = 0; ii <= 1; ++ii)         for (int jj = 0; jj <= 1; ++jj) f[ii][jj] += dp[E[k].to][ii][jj];     }     for (int ii = 0; ii <= 1; ++ii)       for (int jj = 0; jj <= 1; ++jj)         dp[u][ii][jj] =             max(f[ii ^ 1][jj] + (1ll * (ii ? -1 : 1) * base[u].r * base[u].r),                 f[ii][jj ^ 1] + (1ll * (jj ? -1 : 1) * base[u].r * base[u].r));   }   inline bool Comp(C A, C B) { return A.r > B.r; }   void solve1() {     sort(base + 1, base + N + 1, Comp);     for (i = 1; i <= N; ++i)       for (j = i + 1; j <= N; ++j)         if (check_in(base[i], base[j]))           if (!fa[j] || base[fa[j]].r > base[i].r) fa[j] = i;     for (i = 1; i <= N; ++i)       if (fa[i]) Add(i, fa[i]);     for (i = 1; i <= N; ++i)       if (!fa[i]) do_dp(i, 0), Ans += dp[i][0][0];     printf( %.8lf , Ans * Pi);   }   }  // namespace DP   namespace Greedy {   inline bool Comp(C A, C B) { return A.r > B.r; }   void solve2() {     sort(base + 1, base + N + 1, Comp);     for (i = 1; i <= N; ++i)       for (j = i + 1; j <= N; ++j)         if (check_in(base[i], base[j])) ++mark[j];     for (i = 1; i <= N; ++i)       if (!mark[i] || (mark[i] & 1))         Ans += get_S(base[i]);       else         Ans -= get_S(base[i]);     printf( %.8lf , Ans);   }   }  // namespace Greedy   int main() {     cin >> N;     for (i = 1; i <= N; ++i)       scanf( %lf%lf%lf , &base[i].x, &base[i].y, &base[i].r);     if (N >= 500)       DP ::solve1();     else       Greedy ::solve2();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   const long long inf64 = ((long long)1 << 62) - 1;   const long double pi = 3.1415926535897932384626433832795;   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   const int nmax = 15000;   int n, k;   int a[nmax], pos[nmax];   int main() {     cin >> n >> k;     for (int i = 0; i < (int)(n); i++) {       a[i] = 1;       pos[i] = i + 1;     }     a[n - 1] = 0;     pos[n - 1] = n - 1;     for (int i = 0; i < (int)(k); i++) {       for (int j = 0; j < (int)(n); j++) {         while (a[j] + a[pos[j]] > n - j - 1) pos[j]++;         printf( %d  , pos[j] + 1);         a[j] += a[pos[j]];       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 2;   const int MOD = 1 << 30;   const double pi = acos(-1);   struct line {     double a, b, c;   };   struct point {     double x, y;   };   void pointsToLine(point p1, point p2, line &l) {     if (fabs(p1.x - p2.x) < 1e-2) {       l.a = 1.0;       l.b = 0.0;       l.c = -p1.x;     } else {       l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);       l.b = 1.0;       l.c = -(double)(l.a * p1.x) - p1.y;     }   }   bool areParallel(line l1, line l2) {     return ((fabs(l1.a - l2.a) < 1e-2) && (fabs(l2.b - l2.b) < 1e-2));   }   bool areSame(line l1, line l2) {     return (areParallel(l1, l2) && (fabs(l1.c - l2.c) < 1e-2));   }   bool areIntersect(line l1, line l2, point &p) {     if (areParallel(l1, l2)) return false;     p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);     if (fabs(l1.b) > 1e-2)       p.y = -(l1.a * p.x + l1.c);     else       p.y = -(l2.a * p.x + l2.c);     return true;   }   vector<pair<int, int> > AdjList[N];   int n, m;   int vis[N];   void dfs(int u, int c) {     vis[u] = true;     for (int i = 0; i < (int)AdjList[u].size(); ++i) {       pair<int, int> v = AdjList[u][i];       if (!vis[v.first]) {         if (v.second == c) dfs(v.first, v.second);       }     }   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v, w;       cin >> u >> v >> w;       AdjList[u].push_back({v, w});       AdjList[v].push_back({u, w});     }     int q;     cin >> q;     while (q--) {       int u, v;       cin >> u >> v;       int ans = 0;       for (int i = 1; i <= m; ++i) {         memset(vis, false, sizeof vis);         dfs(u, i);         if (vis[v]) ans++;       }       cout << ans <<   n ;     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 1;     while (tc--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int MIN = 1e3 + 2;   const int MXN = 1e6 + 3;   const int INF = 1e9 + 7;   const long long LINF = 1e18 + 15;   const double EPS = 1e-9;   int s, x1, x2;   int t1, t2;   int p, d;   int main() {     cin >> s >> x1 >> x2;     cin >> t1 >> t2;     cin >> p >> d;     if (x1 <= x2) {       if (p <= x1) {         if (d == 1) {           cout << min((x2 - x1) * t2, (x2 - p) * t1);           cerr <<     << 1;           return 0;         }         cout << min((x2 - x1) * t2, (x2 + p) * t1);         cerr <<     << 2;         return 0;       }       if (d == 1) {         cout << min((x2 - x1) * t2, (s - p + s + x2) * t1);         cerr <<     << 3;         return 0;       }       cout << min((x2 - x1) * t2, (x2 + p) * t1);       cerr <<     << 4;       return 0;     }     if (p >= x1) {       if (d == 1) {         cout << min((x1 - x2) * t2, (s - x2 + s - p) * t1);         cerr <<     << 5;         return 0;       }       cout << min((x1 - x2) * t2, (p - x2) * t1);       cerr <<     << 6;       return 0;     }     if (d == 1) {       cout << min((x1 - x2) * t2, (s - x2 + s - p) * t1);       cerr <<     << 7;       return 0;     }     cout << min((x1 - x2) * t2, (s + p + s - x2) * t1);     cerr <<     << 8;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct vec {     long long x, y;   };   bool operator==(const vec& a, const vec& b) {     return a.x == b.x and a.y == b.y;   }   bool operator!=(const vec& a, const vec& b) { return not(a == b); }   bool operator<(const vec& a, const vec& b) {     return make_pair(a.x, a.y) < make_pair(b.x, b.y);   }   vec operator+(const vec& a, const vec& b) {     return (vec){a.x + b.x, a.y + b.y};   }   int main() {     ios_base::sync_with_stdio(false);     long long n, m;     vec d;     cin >> n >> m >> d.x >> d.y;     vector<vec> apple(m);     for (int i = 0; i < (m); ++i) cin >> apple[i].x >> apple[i].y;     sort(apple.begin(), apple.end());     vector<int> x2y(n);     {       vec p = d;       while (p != (vec){0, 0}) {         x2y[p.x] = p.y;         p = p + d;         p.x %= n;         p.y %= n;       }     }     vector<int> bucket(n);     {       int i = 0;       for (int x = 0; x < (n); ++x) {         for (; i < m and apple[i].x <= x; ++i) {           bucket[(apple[i].y - x2y[x] + n) % n] += 1;         }       }     }     {       int ix;       int sz = -1;       for (int i = 0; i < (n); ++i)         if (sz < bucket[i]) {           sz = bucket[i];           ix = i;         }       cout << 0 <<     << ix << endl;     }     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1.0), eps = 1e-9;   const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};   const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};   const int MO = (int)(1e9 + 7);   using namespace std;   struct Tcmp {     bool operator()(const pair<int, int>& A, const pair<int, int>& B) {       int lenA = A.second - A.first + 1, lenB = B.second - B.first + 1;       lenA = lenA + 1 >> 1;       lenB = lenB + 1 >> 1;       if (lenA == lenB)         return A.first < B.first;       else         return lenA > lenB;     }   };   set<int> s;   set<pair<int, int>, Tcmp> heap;   int n, m;   int where[2000001];   int findnext(int t) {     set<int>::iterator sit = s.upper_bound(t);     if (sit == s.end()) return -1;     return *sit;   }   int findpre(int t) {     set<int>::iterator sit = s.lower_bound(t);     if (sit == s.begin()) return -1;     --sit;     return *sit;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       if (i == 8) {         int t = 1;         ++t;       }       int kind, id;       scanf( %d%d , &kind, &id);       if (kind == 1) {         pair<int, int> ans = make_pair(0, 0);         if (s.size() == 0) {           s.insert(1);           puts( 1 );           where[id] = 1;           continue;         }         if (s.count(1) == 0) {           pair<int, int> temp = make_pair(-(findnext(1) - 1), 1);           if (temp < ans) ans = temp;         }         if (s.count(n) == 0) {           pair<int, int> temp = make_pair(-(n - findpre(n)), n);           if (temp < ans) ans = temp;         }         if (heap.size()) {           pair<int, int> now = *heap.begin();           pair<int, int> temp = make_pair(-(now.second - now.first + 2 >> 1), 0);           temp.second = now.first - 1 - temp.first;           if (temp < ans) {             ans = temp;             heap.erase(heap.begin());           }         }         s.insert(ans.second);         int t = findpre(ans.second);         if (t != -1 && t != ans.second - 1)           heap.insert(make_pair(t + 1, ans.second - 1));         t = findnext(ans.second);         if (t != -1 && t != ans.second + 1)           heap.insert(make_pair(ans.second + 1, t - 1));         where[id] = ans.second;         printf( %d n , ans.second);       } else {         s.erase(where[id]);         int l = findpre(where[id]), r = findnext(where[id]);         if (l != -1) heap.erase(make_pair(l + 1, where[id] - 1));         if (r != -1) heap.erase(make_pair(where[id] + 1, r - 1));         if (l != -1 && r != -1) heap.insert(make_pair(l + 1, r - 1));       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct segtree {     vector<long long> t;     segtree(long long _n) { t.resize(4 * _n); }     void update(long long id, long long l, long long r, long long pos,                 long long val) {       if (l == r) {         t[id] = val;         return;       }       long long mid = (l + r) / 2;       if (pos <= mid) {         update(2 * id, l, mid, pos, val);       } else {         update(2 * id + 1, mid + 1, r, pos, val);       }       t[id] = t[2 * id] + t[2 * id + 1];     }     long long query(long long id, long long l, long long r, long long lq,                     long long rq) {       if (lq > r || l > rq) return 0;       if (lq <= l && r <= rq) return t[id];       long long mid = (l + r) / 2;       long long L = query(2 * id, l, mid, lq, rq);       long long R = query(2 * id + 1, mid + 1, r, lq, rq);       return L + R;     }   };   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long N;     cin >> N;     vector<long long> A(N);     for (auto& a : A) cin >> a;     segtree t1(N), t2(N);     for (long long i = 0; i < N; i++) {       if (i % 2) {         t1.update(1, 0, N - 1, i, A[i]);       } else {         t2.update(1, 0, N - 1, i, A[i]);       }     }     long long best = A[0];     for (long long i = 0; i + 1 < N; i++) {       long long foo = A[i] + A[i + 1];       long long from = i + 3, to = N - 1;       if (to >= from) {         if (i % 2) {           foo += t2.query(1, 0, N - 1, from, to);         } else {           foo += t1.query(1, 0, N - 1, from, to);         }       }       from = 0;       to = i - 2;       if (to >= from) {         long long z = to - from + 1;         if (z % 2) {           foo += t2.query(1, 0, N - 1, from, to);         } else {           foo += t1.query(1, 0, N - 1, from, to);         }       }       best = max(best, foo);     }     long long foo = 0;     if (N > 1) {       foo = A[0] + A[N - 1];       for (long long i = 2; i <= N - 3; i += 2) foo += A[i];     }     cout << max(best, foo) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long N, P;   long long L[100001];   long long R[100001];   long long getAc(long long l, long long r, long long p) {     if ((l + p - 1) / p * p > r) return 0;     return (r - (l + p - 1) / p * p) / p + 1;   }   int main() {     scanf( %lld%lld , &N, &P);     for (int i = 0; i < N; i++) scanf( %lld%lld , &L[i], &R[i]);     double ans = 0;     for (int i = 0; i < N; i++) {       long long a = getAc(L[i], R[i], P);       long long b = getAc(L[(i + 1) % N], R[(i + 1) % N], P);       long long cur = (R[i] - L[i] + 1) * b;       cur += (R[(i + 1) % N] - L[(i + 1) % N] + 1) * a;       cur -= a * b;       ans += (double)cur * 2000 / (R[i] - L[i] + 1) /              (R[(i + 1) % N] - L[(i + 1) % N] + 1);     }     printf( %.8f , (double)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[200010], w[200010], f[3010][3010], g[3010][3010], inv[3010 * 2],       sum[3];   const int mod = 998244353;   int getInverse(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = (long long)ret * x % mod;       x = (long long)x * x % mod;       y >>= 1;     }     return ret;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) {       cin >> w[i];       sum[a[i]] += w[i];       sum[2] += w[i];     }     for (int i = max(0, m - sum[0]); i <= 2 * m; ++i)       inv[i] = getInverse(sum[2] + i - m, mod - 2);     for (int i = m; i >= 0; --i) {       f[i][m - i] = g[i][m - i] = 1;       for (int j = min(m - i - 1, sum[0]); j >= 0; --j) {         f[i][j] = ((long long)(sum[1] + i + 1) * f[i + 1][j] +                    (long long)(sum[0] - j) * f[i][j + 1]) %                   mod * inv[i - j + m] % mod;         g[i][j] = ((long long)(sum[1] + i) * g[i + 1][j] +                    (long long)(sum[0] - j - 1) * g[i][j + 1]) %                   mod * inv[i - j + m] % mod;       }     }     for (int i = 1; i <= n; ++i)       cout << ((long long)w[i] * (a[i] ? f[0][0] : g[0][0])) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a;   int main() {     cin >> a;     if (a == string(a.size(),  a )) {       cout << string(a.size() - 1,  a ) <<  z  << endl;     } else {       for (int i = 0; i < a.size(); i++) {         if (a[i] !=  a ) {           int x = i;           while (x < a.size() && a[x] !=  a ) {             a[x++]--;           }           break;         }       }       cout << a << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int n, m;   long long minb[100010];   long long maxg[100010];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %lld , minb + i);     }     sort(minb, minb + n);     for (int i = 0; i < m; i++) {       scanf( %lld , maxg + i);     }     sort(maxg, maxg + m);     long long ans = 0;     if (minb[n - 1] > maxg[0]) {       cout << -1 << endl;       return 0;     }     if (m == 1) {       if (minb[n - 1] != maxg[0]) {         cout << -1 << endl;         return 0;       } else {         for (int i = 0; i < n; i++) {           ans += minb[i];         }         cout << ans << endl;         return 0;       }     }     for (int i = 0; i < n - 1; i++) {       ans += minb[i] * m;     }     for (int i = 1; i < m; i++) {       ans += maxg[i];     }     if (minb[n - 1] == maxg[0]) {       ans += minb[n - 1];     } else {       if (n == 1) {         cout << -1 << endl;         return 0;       } else {         ans += minb[n - 1] + maxg[0] - minb[n - 2];       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 550;   struct DDF {     int n;     int v[maxn];     int dp[maxn][maxn];     int dfs(int l, int r) {       if (l >= r) return dp[l][r] = 1;       if (~dp[l][r]) return dp[l][r];       long long ans = dfs(l + 1, r);       for (int i = l + 1; i <= r; i++) {         if (v[l + 1] < v[i + 1]) {           ans += 1LL * dfs(l + 1, i - 1) * (dfs(i, r));           ans %= mod;         }       }       return dp[l][r] = ans;     }     void solve() {       memset(dp, -1, sizeof dp);       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %d , &v[i]);       printf( %d n , dfs(1, n));     }   } solver;   int main() {     solver.solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int ac = 1e6 + 5;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       cout << n <<   n ;       string s;       cin >> s;       int p = 0;       for (int i = 0; i < n / 2 - k + 1; i++) {         int j = p;         while (s[j] !=  ( ) j++;         cout << p + 1 <<     << j + 1 <<   n ;         reverse(s.begin() + p, s.begin() + j + 1);         p++;       }       for (int i = 0; i < n / 2 - k + 1; i++) {         int j = p;         while (s[j] !=  ) ) j++;         cout << p + 1 <<     << j + 1 <<   n ;         reverse(s.begin() + p, s.begin() + j + 1);         p++;       }       for (int i = 0; i < (k - 1) * 2; i++) {         if (i % 2 == 0) {           int j = p;           while (s[j] !=  ( ) j++;           cout << p + 1 <<     << j + 1 <<   n ;           reverse(s.begin() + p, s.begin() + j + 1);           p++;         } else {           int j = p;           while (s[j] !=  ) ) j++;           cout << p + 1 <<     << j + 1 <<   n ;           reverse(s.begin() + p, s.begin() + j + 1);           p++;         }       }     }   }
#include <bits/stdc++.h>   const int N = 50;   int i, j, tot, n;   bool left[N][N], down[N][N];   int main() {     long long T;     scanf( %I64d , &T);     for (i = 0; T; T /= 3, i++) {       int x = T % 3;       if (i) {         tot += 2;         down[i][i + 3] = left[i + 3][i] = 1;         if (T >= 3) tot += 2, left[i][i + 4] = down[i + 4][i] = 1;       }       if (x < 2) tot++, left[i + 1][i + 3] = 1;       if (x < 1) tot++, down[i + 3][i + 1] = 1;     }     left[i + 1][i + 2] = left[i + 2][i + 2] = 1;     down[i + 2][i + 1] = down[i + 2][i + 2] = 1;     n = i + 3;     printf( %d %d n%d n , n, n, tot + 4);     for (i = 1; i < n; i++)       for (j = 1; j < n; j++) {         if (left[i][j]) printf( %d %d %d %d n , i, j, i, j + 1);         if (down[i][j]) printf( %d %d %d %d n , i, j, i + 1, j);       }   }