malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string s;   bool vis[26];   int main() {     cin >> s;     long long ans = 1;     int cnt1 = 0;     int cnt2 = 0;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ? )         cnt2++;       else if (s[i] >=  A  && s[i] <=  Z ) {         if (vis[s[i] -  A ] == 1)           continue;         else           vis[s[i] -  A ] = 1, cnt1++;       }     }     if (cnt1)       if (s[0] >=  A  && s[0] <=  Z )         ans = 9;       else         ans = 10;     for (int i = 9; i > 9 - cnt1 + 1; i--) ans *= i;     if (cnt2)       if (s[0] ==  ? )         ans *= 9;       else         ans *= 10;     for (int i = 1; i < cnt2; i++) ans *= 10;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   const long long INF = 1e9 + 19;   const int LOG = 11;   int n, m;   int a[N][N];   int b[N][N];   int pref[N][N];   short table[LOG][LOG][N][N];   int deg[N];   void read() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);   }   int getSum(int x1, int y1, int x2, int y2) {     return pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];   }   bool isSquare(int x1, int y1, int x2, int y2) {     return (x2 - x1) * (y2 - y1) == getSum(x1, y1, x2, y2);   }   int getMax(int x1, int y1, int x2, int y2) {     int szX = x2 - x1;     int szY = y2 - y1;     int dx = deg[szX];     int dy = deg[szY];     int tmp = max(max(table[dx][dy][x1][y1], table[dx][dy][x2 - (1 << dx)][y1]),                   max(table[dx][dy][x1][y2 - (1 << dy)],                       table[dx][dy][x2 - (1 << dx)][y2 - (1 << dy)]));     return tmp;   }   void solve() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         pref[i + 1][j + 1] =             pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int l = 0;         int r = min(n - i, m - j) + 1;         while (r - l > 1) {           int mid = (l + r) / 2;           if (isSquare(i, j, i + mid, j + mid))             l = mid;           else             r = mid;         }         b[i][j] = l;       }     for (int i = 2; i <= max(n, m); i++) deg[i] = deg[i / 2] + 1;     for (int dx = 0; dx <= 10; dx++)       for (int dy = 0; dy <= 10; dy++)         for (int i = 0; i + (1 << dx) <= n; i++)           for (int j = 0; j + (1 << dy) <= m; j++) {             if (dx == 0 && dy == 0) {               table[0][0][i][j] = b[i][j];             } else if (dx != 0) {               table[dx][dy][i][j] =                   max(table[dx - 1][dy][i][j],                       table[dx - 1][dy][i + (1 << (dx - 1))][j]);             } else               table[dx][dy][i][j] =                   max(table[dx][dy - 1][i][j],                       table[dx][dy - 1][i][j + (1 << (dy - 1))]);           }     int t;     scanf( %d , &t);     for (int it = 0; it < t; it++) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       x1--;       y1--;       int l = 0;       int r = min(x2 - x1, y2 - y1) + 1;       while (r - l > 1) {         int mid = (l + r) / 2;         if (getMax(x1, y1, x2 - mid + 1, y2 - mid + 1) >= mid)           l = mid;         else           r = mid;       }       printf( %d n , l);     }   }   void stress() {}   int main() {     if (1) {       int k = 1;       for (int tt = 0; tt < k; tt++) {         read();         solve();       }     } else {       stress();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Computational_Geometry {    public:     void init();     void solve();     Computational_Geometry() {       EPS = 1e-10;       Pi = acos(-1.0);     }       private:     struct node {       long long x, y;     } point[100010], line[100010];     struct inter {       double x, y;     } q[100010], p[100010];     int n, m;     double EPS, Pi;     friend bool operator==(const node &, const node &);     friend node operator-(const node &, const node &);     friend long long operator*(const node &, const node &);   };   bool operator==(const Computational_Geometry::node &a,                   const Computational_Geometry::node &b) {     return (a.x == b.x && a.y == b.y);   }   Computational_Geometry::node operator-(const Computational_Geometry::node &a,                                          const Computational_Geometry::node &b) {     Computational_Geometry::node d;     d.x = a.x - b.x;     d.y = a.y - b.y;     return d;   }   long long operator*(const Computational_Geometry::node &a,                       const Computational_Geometry::node &b) {     return a.x * b.y - a.y * b.x;   }   void Computational_Geometry::init() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> point[i].x >> point[i].y;     for (int i = 2; i <= n; i++) line[i] = point[i] - point[1];   }   void Computational_Geometry::solve() {     bool flag = true;     cin >> m;     for (int i = 1; i <= m; i++) {       if (!flag) continue;       node p, now;       cin >> p.x >> p.y;       now = p - point[1];       if (now * line[2] <= 0 || now * line[n] >= 0) flag = false;       int l = 2, r = n - 1;       while (l <= r) {         int mid = (l + r) / 2;         if (now * line[mid + 1] <= 0)           r = mid - 1;         else           l = mid + 1;       }       if ((p - point[l]) * (point[l + 1] - point[l]) <= 0) flag = false;     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(false);     Computational_Geometry ans;     ans.init();     ans.solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int N = 1000090, M = 1000000007;   int B[N];   void up(int i, int v) {     for (; i < N; i += (i & (-i))) B[i] += v;   }   int sm(int i) {     int s = 0;     for (; i > 0; i -= (i & (-i))) s += B[i];     return s;   }   int main() {     int q, x, n;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &x), up(x, 1);     for (int Q = 0; Q < q; ++Q) {       scanf( %d , &x);       if (x > 0)         up(x, 1), n++;       else {         int b = 0, e = N;         x = -1 * x;         while (b < e) {           int bw = (b + e) / 2;           int z = sm(bw);           if (z >= x)             e = bw;           else             b = bw + 1;         }         up(b, -1);         n--;       }     }     int ans = sm(N);     if (!ans)       printf( 0 );     else {       for (int i = 1; i < N; ++i)         if (sm(i) > 0) return cout << i, 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<vector<int>> v(200001, vector<int>(32));     for (int i = 0; i < 2e5 + 1; i++) {       for (int j = 0; j < 32; j++) {         if (i & (1 << j)) v[i][j] = 1;       }     }     for (int i = 1; i < 2e5 + 1; i++) {       for (int j = 0; j < 32; j++) {         v[i][j] += v[i - 1][j];       }     }     while (t--) {       int l, r;       cin >> l >> r;       int ans = 1e9;       for (int i = 0; i < 32; i++) {         if ((1 << i) <= r) {           ans = min(ans, r - v[r][i] - l + 1 + v[l - 1][i]);         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long, int> mm;   long long Abs(long long a) {     if (a < 0) a = -a;     return a;   }   int main() {     int q, l, m, a;     long long b;     scanf( %lld%d%d%d , &b, &q, &l, &m);     for (int i = 0; i < m; i++) {       scanf( %d , &a);       mm[a] = 1;     }     int cur = b, cnt = 0;     if (Abs(b) > l) {       printf( 0 n );       return 0;     }     if (q == 1) {       if (mm[b] == 0)         printf( inf n );       else         printf( 0 n );       return 0;     }     if (q == -1) {       if (mm[b] && mm[-b])         printf( 0 n );       else         printf( inf n );       return 0;     }     if (q == 0 && b != 0) {       if (mm[b] && mm[0])         printf( 0 n );       else if (mm[0] == 0)         printf( inf n );       else if (mm[b] == 0)         printf( 1 n );       return 0;     }     if (b == 0) {       if (mm[0] == 1)         printf( 0 n );       else         printf( inf n );       return 0;     }     while (Abs(b) <= l) {       if (mm[b] == 0) cnt++;       b = b * q;     }     printf( %d n , cnt);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxn = 200100;   map<int, long long> m1;   map<int, long long> m2;   int a[maxn];   int main() {     m1.clear();     m2.clear();     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     long long sum = 0;     for (int i = n; i >= 1; i--) {       if ((long long)a[i] * k <= 1e9 && (long long)a[i] * k >= -1e9) {         sum += m2[a[i] * k];         m2[a[i]] += m1[a[i] * k];       }       m1[a[i]]++;     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = (1 << 29);   const int N = 1024;   int indeg[N], outdeg[N];   int dis[N][N];   int net[N][N];   bool vis[N];   int n, m;   int tmp;   void dfs(int sta, int u) {     vis[u] = true;     for (int i = 1; i <= n; i++) {       if (!vis[i] && net[u][i]) {         tmp = min(tmp, net[u][i]);         dfs(sta, i);       }     }     dis[sta][u] = tmp;   }   int main() {     while (scanf( %d %d , &n, &m) == 2) {       if (n == 1) {         printf( 0 n );         continue;       }       memset(indeg, 0, sizeof(indeg));       memset(outdeg, 0, sizeof(outdeg));       memset(vis, false, sizeof(vis));       memset(net, 0, sizeof(net));       fill(dis[0], dis[0] + N * N, oo);       for (int i = 1; i <= m; i++) {         int u, v, w;         scanf( %d %d %d , &u, &v, &w);         net[u][v] = w;         outdeg[u]++;         indeg[v]++;       }       for (int i = 1; i <= n; i++) {         if (!vis[i] && !indeg[i]) {           tmp = oo;           dfs(i, i);         }       }       int ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (indeg[i] == 0 && outdeg[j] == 0) {             if (dis[i][j] != oo) {               ans++;             }           }         }       }       printf( %d n , ans);       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (indeg[i] == 0 && outdeg[j] == 0) {             if (dis[i][j] != oo) {               printf( %d %d %d n , i, j, dis[i][j]);             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>      using namespace std;   typedef long long ll;      int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int>> a(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cin >> a[i][j];     }     vector<vector<int>> b(n, vector<int>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cin >> b[i][j];     }     vector<vector<int>> bb;     for (int i = 0; i < n; ++i) bb.push_back(b[i]);     sort(bb.begin(), bb.end());     bb.erase(unique(bb.begin(), bb.end()), bb.end());     vector<vector<int>> who_a(bb.size());     vector<vector<int>> who_b(bb.size());     for (int i = 0; i < n; ++i) {       int ind = lower_bound(bb.begin(), bb.end(), a[i]) - bb.begin();       if (ind == (int)bb.size() || bb[ind] != a[i]) {         cout << -1 << endl;         return 0;       }       who_a[ind].push_back(i);       ind = lower_bound(bb.begin(), bb.end(), b[i]) - bb.begin();       who_b[ind].push_back(i);     }     vector<int> p(n);     for (int i = 0; i < (int)bb.size(); ++i) {       if (who_a[i].size() != who_b[i].size()) {         cout << -1 << endl;         return 0;       }       for (int j = 0; j < (int)who_a[i].size(); ++j) {         p[who_a[i][j]] = who_b[i][j];       }     }     vector<int> q(n);     for (int i = 0; i < n; ++i) q[p[i]] = i;     vector<bool> good(n, 0);     vector<int> cnt_bad(m, 0), cnt_kek(m, 0);     for (int j = 0; j < m; ++j) {       for (int i = 0; i < n - 1; ++i) {         if (a[q[i]][j] < a[q[i + 1]][j]) ++cnt_kek[j];         if (a[q[i]][j] > a[q[i + 1]][j]) ++cnt_bad[j];       }     }     vector<int> ans;     while (true) {       bool ok = true;       for (int i = 0; i < n - 1; ++i) ok &= good[i] || q[i] < q[i + 1];       if (ok) break;       int col = -1;       for (int j = 0; j < m; ++j) {         if (cnt_bad[j] == 0 && cnt_kek[j] > 0) {           col = j;           break;         }       }       if (col == -1) break;       ans.push_back(col);       for (int i = 0; i < n - 1; ++i) {         if (!good[i] && a[q[i]][col] < a[q[i + 1]][col]) {           good[i] = true;           for (int j = 0; j < m; ++j) {               if (a[q[i]][j] < a[q[i + 1]][j]) --cnt_kek[j];               if (a[q[i]][j] > a[q[i + 1]][j]) --cnt_bad[j];           }         }       }     }     bool ok = true;     for (int i = 0; i < n - 1; ++i) ok &= good[i] || q[i] < q[i + 1];     if (ok) {       cout << (int)ans.size() << endl;       reverse(ans.begin(), ans.end());       for (int i : ans) cout << i + 1 <<    ;       cout << endl;     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     int a, b = 0;     cin >> n;     cin >> s;     int ans = 2000000000;     for (int i = 0; i < n; i++) {       a = b;       cin >> b;       if (i) {         if (s[i] ==  L  && s[i - 1] ==  R ) ans = min(ans, (b - a) / 2);       }     }     if (ans == 2000000000) ans = -1;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, f[1000010][4][4], m;   int a[1000010], b[1000010];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[a[i]]++;     }     for (int i = 1; i <= m; i++)       for (int j = 0; j <= 2; j++)         for (int k = 0; k <= 2; k++) f[i][j][k] = -0x7fffffff;     f[1][0][0] = 0;     for (int i = 2; i <= m + 1; i++)       for (int j = 0; j <= 2; j++)         for (int k = 0; k <= 2; k++)           for (int l = 0; l <= 2; l++) {             int rem = b[i - 1] - j - k - l;             if (rem >= 0)               f[i][j][k] = max(f[i][j][k], f[i - 1][k][l] + l + rem / 3);           }     cout << f[m + 1][0][0];   }
#include <bits/stdc++.h>   using namespace std;   int n;   int cost[2005];   bool have[2005][3];   int dp[2003][10];   int solve(int i, int vits) {     if (i >= n) {       if (vits == 7) return 0;       return 1e9;     }     int &ret = dp[i][vits];     if (ret + 1) return ret;     int sol1 = 0, sol2 = 0;     sol1 = solve(i + 1, vits);     sol2 = cost[i] + solve(i + 1, vits | (have[i][0] | (2 * have[i][1]) |                                           (4 * have[i][2])));     return ret = min(sol1, sol2);   }   int main() {     ios_base::sync_with_stdio(false);     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 0; i < n; i++) {       cin >> cost[i];       string s;       cin >> s;       for (auto x : s) {         if (x ==  A ) have[i][0] = true;         if (x ==  B ) have[i][1] = true;         if (x ==  C ) have[i][2] = true;       }     }     int res = solve(0, 0);     if (res > 7e8) res = -1;     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using namespace std;   int n;   void solve() {     cin >> n;     if (n % 2 == 0) {       cout <<  NO ;       return;     }     cout <<  YES n ;     vector<int> v(2 * n + 1);     for (int i = 1; i <= n; i++) {       if (i % 2) {         v[i] = 2 * i - 1;         v[i + n] = 2 * i;       } else {         v[i] = 2 * i;         v[i + n] = 2 * i - 1;       }     }     for (int i = 1; i <= 2 * n; i++) cout << v[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int b, h, a;     long long int count = 0;     cin >> b >> h;     for (int i = h - 1; i >= 0; i = i - 2) {       for (int j = b - 1; j >= 0; j = j - 2) {         a = j * i;         count += a;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     long long n, p, d, w;     cin >> n >> p >> w >> d;     for (register int y = (0); y <= (w); ++y) {       long long x = (p - y * d) / w;       if (x < 0) continue;       if (x * w + y * d != p) continue;       if (x + y <= n) {         cout << x <<     << y <<     << n - x - y <<   n ;         return 0;       }     }     cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num[2005];   int sum[2005];   bool cmp(int a, int b) { return a > b; }   int main() {     int n, i, j, t;     int temp;     while (cin >> n) {       memset(num, 0, sizeof(num));       for (i = 0; i < n; i++) {         cin >> temp;         num[temp]++;       }       cin >> t;       memset(sum, 0, sizeof(sum));       for (i = 0; i <= t; i++) {         sum[0] += num[i];       }       for (i = 1; i < 1001; i++) {         sum[i] = sum[i - 1] - num[i - 1] + num[i + t];       }       sort(sum, sum + 1001, cmp);       cout << sum[0] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int ABS(long long int a) {     if (a < 0) return (-a);     return a;   }   void input() {}   int main() {     long long int n, t;     int f = 0;     scanf( %llu , &n);     scanf( %llu , &t);     long long int x[n];     for (int i = (1); i < (n); ++i) {       scanf( %llu , &x[i]);     }     long long int i = 1;     while (i <= t) {       if (i == t) f = 1;       i += x[i];       if (i == t) f = 1;       if (f) break;     }     if (f)       printf( YES );     else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1000000000 )   static char s[1000][1000];   static int dp[2][505][505];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, res = 0, d1, d2;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> s[i];     dp[0][0][n - 1] = 1;     for (int d = 0; (n + m - 2 - d) >= d; ++d) {       d1 = d & 1;       d2 = 1 - d1;       memset(dp[d2], 0, sizeof(dp[d2]));       for (int x = 0; x <= min(d, n - 1); ++x)         for (int x1 = n - 1; x1 >= 0 && (n + m - 2 - d) - x1 < m; --x1) {           if (s[x][d - x] != s[x1][(n + m - 2 - d) - x1]) dp[d1][x][x1] = 0;           if (d == (n + m - 2 - d) && x == x1)             res = (res + dp[d1][x][x1]) % (long long)1000000007;           if (d == (n + m - 2 - d) - 1 && abs(x - x1) < 2 &&               abs((d - x) - (d + 1 - x1)) < 2)             res = (res + dp[d1][x][x1]) % (long long)1000000007;           if (x1) {             dp[d2][x + 1][x1 - 1] =                 (dp[d2][x + 1][x1 - 1] + dp[d1][x][x1]) % (long long)1000000007;             dp[d2][x][x1 - 1] =                 (dp[d2][x][x1 - 1] + dp[d1][x][x1]) % (long long)1000000007;           }           dp[d2][x + 1][x1] =               (dp[d2][x + 1][x1] + dp[d1][x][x1]) % (long long)1000000007;           dp[d2][x][x1] = (dp[d2][x][x1] + dp[d1][x][x1]) % (long long)1000000007;         }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   vector<T> &operator+=(vector<T> &v, T x) {     v.push_back(x);     return v;   }   void solve() {     int n;     cin >> n;     int a[n], b[n];     int cash = 1, t = 0;     for (int i = (0), _b_ = (n); i < _b_; i++) {       cin >> a[i] >> b[i];       if (i > 0) {         if (a[i] == a[i - 1] && b[i] == b[i - 1]) {           t++;         } else {           cash = max(cash, t + 1);           t = 0;         }       }     }     cout << max(cash, t + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 500005;   int tot, head[maxn << 1], n, m, a[maxn << 1], b, maxdep, xzynb, son[maxn << 1],       size, ans[maxn << 1];   template <typename Tp>   inline void read(Tp& o) {     o = 0;     register int f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       o = (o << 1) + (o << 3) + (c ^ 48);       c = getchar();     }     o *= f;   }   inline void print(int x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) {       print(x / 10);     }     putchar(x % 10 + 48);   }   struct qwq {     int to;     int next;   } s[maxn << 1];   inline void add(int x, int y) {     tot++;     s[tot].to = y;     s[tot].next = head[x];     head[x] = tot;   }   inline void dfs(int x, int fa) {     son[x] = 1;     ans[x] = x;     int res = 0;     for (register int i = head[x]; i; i = s[i].next) {       if (s[i].to != fa) {         dfs(s[i].to, x);         son[x] += son[s[i].to];         if (son[s[i].to] > son[res]) res = s[i].to;       }     }     if ((son[res] << 1) > son[x]) {       int temp = ans[res];       while (((son[x] - son[temp]) << 1) > son[x]) {         temp = a[temp];       }       ans[x] = temp;     }   }   int main() {     read(n), read(m);     for (register int i = 2; i <= n; ++i) {       read(a[i]);       add(i, a[i]), add(a[i], i);     }     dfs(1, 0);     for (register int i = 1; i <= m; ++i) {       read(b);       print(ans[b]), puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct atom {     int x, y;   } x[110000];   int A[800], f[2][800], n, m;   int compare(atom k1, atom k2) { return k1.y < k2.y; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &x[i].x, &x[i].y);     sort(x + 1, x + m + 1, compare);     memset(f, 0x00, sizeof f);     int now = 0, lim = 780;     for (int i = 1; i <= n; i++) {       memset(A, 0x00, sizeof A);       memset(f[now ^ 1], 0x3f, sizeof f[now ^ 1]);       while (m && x[m].y == n - i + 1) {         A[min(n - x[m].x + 1, lim + 1)]++;         m--;       }       for (int j = lim; j; j--) A[j] += A[j + 1];       for (int j = min(lim, i); j >= 0; j--)         f[now ^ 1][j] = f[now][max(j - 1, 0)] + A[j + 1] * 3;       for (int j = 0; j <= min(i, lim); j++)         f[now ^ 1][0] =             min(f[now ^ 1][0],                 f[now][max(j - 1, 0)] + j * (j + 1) / 2 + 2 + A[j + 1] * 3);       for (int j = 1; j <= min(i, lim); j++)         f[now ^ 1][j] = min(f[now ^ 1][j], f[now ^ 1][j - 1]);       now ^= 1;     }     cout << f[now][0] << endl;     return 0;   }