malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int X[4] = {0, 0, -1, 1};   const int Y[4] = {-1, 1, 0, 0};   int dp[1001][1001], Vis[1001][1001];   char c[1001][1001];   int vis[1001][1001], i, j, m, n, p, k, ans;   bool check(int x, int y, int xx, int yy) {     if (x < 0 || y < 0 || x > n || y >= m) return false;     if (c[x][y] ==  D  && c[xx][yy] ==  A ) return true;     if (c[x][y] ==  I  && c[xx][yy] ==  D ) return true;     if (c[x][y] ==  M  && c[xx][yy] ==  I ) return true;     if (c[x][y] ==  A  && c[xx][yy] ==  M ) return true;     return false;   }   int dfs(int x, int y) {     if (Vis[x][y]) return dp[x][y];     if (vis[x][y]) {       printf( Poor Inna! n );       exit(0);     }     vis[x][y] = 1;     int i;     for (i = 0; i < 4; i++)       if (check(x + X[i], y + Y[i], x, y))         dp[x][y] = max(dp[x][y], dfs(x + X[i], y + Y[i]));     if (c[x][y] ==  A ) dp[x][y]++;     vis[x][y] = 0;     Vis[x][y] = 1;     return dp[x][y];   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %s , &c[i]);     for (i = 1; i <= n; i++)       for (j = 0; j < m; j++)         if (c[i][j] ==  D ) ans = max(ans, dfs(i, j));     if (!ans)       printf( Poor Dima! n );     else       printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6 + 5;   struct comp {     bool operator()(pair<int, int> &a, pair<int, int> &b) {       if (a.first == b.first) return (a.second < b.second);       return (a.first > b.first);     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<pair<int, int>> ed(m);     map<pair<int, int>, queue<int>> pos;     priority_queue<pair<int, int>, vector<pair<int, int>>, comp> p;     for (int i = 0; i < m; i++) {       cin >> ed[i].first >> ed[i].second;       p.push(ed[i]);       pos[ed[i]].push(i);     }     vector<int> q;     int i = 1, x = 2;     queue<int> avl;     q.push_back(i++);     int s = q.size();     vector<pair<int, int>> res(m);     bool check = true;     while (!p.empty()) {       pair<int, int> v = p.top();       p.pop();       int j = pos[v].front();       pos[v].pop();       if (v.second) {         res[j] = {q.back(), i};         q.push_back(i++);         if (q.size() > 2) avl.push(q.size() - 1);       } else if (!avl.empty()) {         int t = avl.front();         if (t - x >= 0) {           res[j] = {q[t], q[t - x]};           x++;         } else if (avl.size() == 1) {           check = false;           break;         } else {           avl.pop();           t = avl.front();           x = 2;           res[j] = {q[t], q[t - x]};           x++;         }       } else {         check = false;         break;       }     }     if (check) {       for (pair<int, int> t : res) cout << t.first <<     << t.second <<   n ;     } else       cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, m, a[N], b[N];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       Q;   long long ans;   int solve(int x) {     ans = 0;     int num = 0;     for (int i = (int)(1); i <= (int)(n); i++) {       Q.push(pair<long long, long long>(a[i], 0));       long long t = Q.top().first, now = b[i] - x;       if (now + t < 0) {         ans += now + t;         Q.pop();         Q.push(pair<long long, long long>(-now, 1));       }     }     for (; !Q.empty(); num += Q.top().second, Q.pop())       ;     return num;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (int)(1); i <= (int)(n); i++) scanf( %d , &a[i]);     for (int i = (int)(1); i <= (int)(n); i++) scanf( %d , &b[i]);     long long l = 0, r = 2e9;     while (l <= r) {       long long mid = (l + r) / 2;       int sum = solve(mid);       if (sum == m) {         printf( %lld n , ans + 1ll * m * mid);         return 0;       }       if (sum < m)         l = mid + 1;       else         r = mid - 1;     }   }
#include <bits/stdc++.h>   using namespace std;   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   pair<int, int> P[200050];   int A[200050];   stack<int> Stack;   int main() {     int d = getnum(), tot = getnum(), n = getnum() + 2;     P[1] = make_pair(0, 0);     P[2] = make_pair(d, 0);     for (int i = 3; i <= n; i++) {       int x = getnum(), y = getnum();       P[i] = make_pair(x, y);     }     sort(P + 1, P + n + 1);     Stack.push(n);     for (int i = n - 1; i >= 1; i--) {       while (P[Stack.top()].second > P[i].second) Stack.pop();       A[i] = Stack.top();       Stack.push(i);     }     long long ans = 0;     int cur = 0;     for (int i = 1; i <= n - 1; i++) {       int x = 0, y = A[i];       int to = P[y].first - P[i].first;       if (to > cur) {         int a = to - cur;         if (a + cur > tot) a = (tot - cur);         ans += (long long)a * P[i].second;         cur += a;       }       cur -= (P[i + 1].first - P[i].first);       if (cur < 0) {         puts( -1 );         return -0;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int z[N];   void computeZ(char s[]) {     int n = strlen(s), L = 0, R = 0;     for (int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L;         R--;       } else {         int k = i - L;         if (z[k] < R - i + 1)           z[i] = z[k];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L;           R--;         }       }     }   }   char s[N + 1];   int suffix[N + 1], size;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> s;     computeZ(s);     int n = strlen(s), mx = 0;     int size = 0;     for (int i = 1; i < n; ++i)       if (z[i] == n - i) suffix[z[i]]++;     for (int i = 1; i < n; ++i) {       if (suffix[i])         suffix[i] = i;       else         suffix[i] = suffix[i - 1];     }     for (int i = 1; i < n; ++i) {       int len = z[i] - (z[i] == n - i);       mx = max(mx, suffix[len]);     }     if (mx == 0)       cout <<  Just a legend  << endl;     else {       s[mx] =   0 ;       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<vector<int>> v;   void sit(int x, int y) {     while (1) {       int u = max(1, x - v[x][y]), d = min(n, x + v[x][y]);       for (; u <= d; ++u) {         if (y - v[x][y] + abs(u - x) > 0) {           if (v[u][y - v[x][y] + abs(u - x)] == 0) {             cout << u <<     << y - v[x][y] + abs(u - x) <<   n ;             ++v[u][y - v[x][y] + abs(u - x)];             return;           } else if (v[x][y] < v[u][y - v[x][y] + abs(u - x)] - v[x][y]) {             v[x][y] = v[u][y - v[x][y] + abs(u - x)] - v[x][y];             break;           }         }         if (y + v[x][y] - abs(u - x) <= m) {           if (v[u][y + v[x][y] - abs(u - x)] == 0) {             cout << u <<     << y + v[x][y] - abs(u - x) <<   n ;             ++v[u][y + v[x][y] - abs(u - x)];             return;           } else if (v[x][y] < v[u][y + v[x][y] - abs(u - x)] - v[x][y]) {             v[x][y] = v[u][y + v[x][y] - abs(u - x)] - v[x][y];             break;           }         }       }       if (u > d) ++v[x][y];     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     v.resize(n + 1, vector<int>(m + 1, 0));     while (k--) {       int a, b;       cin >> a >> b;       sit(a, b);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)(1e9 + 7);   const long long N = (long long)(1e5 + 7);   long long p[N];   long long h[N];   int n, m;   bool fun(long long dist) {     queue<long long> q;     for (int i = 0; i < m; i++) {       q.push(p[i]);     }     for (int i = 0; i < n; i++) {       if (q.empty()) {         return true;       }       if (q.front() >= h[i]) {         while (!q.empty() && q.front() <= h[i] + dist) {           q.pop();         }       } else {         long long x = h[i] - q.front();         if (x > dist) {           return false;         }         long long y = max(dist - (2 * x), (dist - x) / 2);         y = max(y, (long long)0);         while (!q.empty() && q.front() <= h[i]) {           q.pop();         }         while (!q.empty() && q.front() - h[i] <= y) {           q.pop();         }       }     }     if (q.empty()) {       return true;     } else {       return false;     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> h[i];     }     for (int i = 0; i < m; i++) {       cin >> p[i];     }     sort(h, h + n);     sort(p, p + m);     long long l = 0;     long long r = 20000000007;     long long ans = -1;     while (l <= r) {       long long dist = (l + r) / 2;       if (fun(dist)) {         ans = dist;         r = dist - 1;       } else {         l = dist + 1;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long maxm = -1e18;   long long minm = 1e18;   bool isP(long long n) {     if (n == 2LL) return 1;     if (n % 2LL == 0LL)       return 0;     else if (n == 1)       return 0;     for (long long i = 3; i * i <= n; ++i)       if (n % i == 0) return 0;     return 1;   }   void solve() {     int n;     cin >> n;     string res;     while (n > 0) {       if (n == 3) {         res = res +  7 ;         n -= 3;       } else {         res = res +  1 ;         n -= 2;       }     }     string result;     for (int i = res.length() - 1; i >= 0; i--) {       result = result + res[i];     }     cout << result << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[5005][5005];   deque<int> dq[5005];   int a[5005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k, x;     cin >> n >> k >> x;     for (int i = 1; i <= n; i++) cin >> a[i];     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     dq[0].push_back(0);     for (int i = 1; i <= n; i++) {       for (int l = x - 1; l >= 0; l--) {         while (!dq[l].empty() && i - dq[l].front() > k) dq[l].pop_front();         if (dq[l].empty()) continue;         dp[i][l + 1] = max(dp[i][l + 1], dp[dq[l].front()][l] + a[i]);         while (!dq[l + 1].empty() && dp[dq[l + 1].back()][l + 1] <= dp[i][l + 1])           dq[l + 1].pop_back();         dq[l + 1].push_back(i);       }     }     long long ans = -1;     for (int i = n; i >= n - k + 1; i--) ans = max(ans, dp[i][x]);     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int t, f, w;     bool operator<(const edge& e) const { return w > e.w; }     edge(int from, int to, int weight) {       t = to;       f = from;       w = weight;     }   };   const double EPS = (1e-5);   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   int findXOR(int n) {     switch (n % 4) {       case 0:         return n;       case 1:         return 1;       case 2:         return n + 1;       case 3:         return 0;     }   }   int rangeXOR(int l, int r) { return (findXOR(l - 1) ^ findXOR(r)); }   int getbit(int mask, int bit) { return (mask & (1 << bit)); }   void setbit(int& mask, int bit, int val) {     if (val)       mask |= (1 << bit);     else       mask &= ~(1 << bit);   }   const int N = 100 + 10;   const int M = 101;   const long long INF = 1000 * 1e9 + 1;   void solve() {     int x;     cin >> x;     if (x == 3) {       cout << 5 <<   n ;       return;     }     if (x == 1) {       cout << 1 <<   n ;       return;     }     int i = 1;     while (x > i * i / 2 + 1) {       i += 2;     }     cout << i <<   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>   char st[300][100], sy[10000], ss[1000000];   int main() {     long a, i, j, len, po, k;     strcpy(st[ > ],  1000 );     strcpy(st[ < ],  1001 );     strcpy(st[ + ],  1010 );     strcpy(st[ - ],  1011 );     strcpy(st[ . ],  1100 );     strcpy(st[ , ],  1101 );     strcpy(st[ [ ],  1110 );     strcpy(st[ ] ],  1111 );     while (gets(sy)) {       ss[0] = 0;       len = strlen(sy);       for (i = 0; i < len; i++) {         strcat(ss, st[sy[i]]);       }       j = a = 0;       len = strlen(ss);       for (i = len - 1; i >= 0; i--) {         po = 1;         for (k = 0; k < j; k++) {           po = po * 2;           po = po % 1000003;         }         a += (ss[i] - 48) * po;         j++;         a = a % 1000003;       }       printf( %ld n , a);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, a, b, c;     cin >> n >> m;     vector<int> ans(n, 0);     set<int> s;     for (int i = 1; i <= n; ++i) {       s.insert(i);     }     while (m--) {       cin >> a >> b >> c;       auto lt = s.lower_bound(a), ht = prev(s.upper_bound(b));       auto ct = lt;       while (ct != next(ht)) {         if (*ct != c) {           ans[*ct - 1] = c;         }         ct = next(ct);       }       s.erase(lt, next(ht));       s.insert(c);     }     for (int x : ans) cout << x <<    ;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long q[500009];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long sum = 0;     long long mini = 0;     for (long long i = 1; i < n; i++) {       cin >> q[i];       sum += q[i];       if (sum < mini) mini = sum;     }     bool ok = 1;     long long p1 = 1 - mini;     set<long long> vis;     vector<long long> p;     p.push_back(p1);     vis.insert(p1);     long long prev = p1;     for (long long i = 1; i < n; i++) {       long long x = prev + q[i];       if (x < 1 or x > n or vis.count(x)) {         ok = 0;         break;       }       p.push_back(x);       vis.insert(x);       prev = x;     }     if (p[0] > n or p[0] < 1) ok = 0;     if (!ok) {       cout <<  -1 n ;       return 0;     }     for (auto i : p) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e3 + 100;   struct node {     int a, b, c;   } p[N];   int nex[N];   vector<int> pre[N];   int dp[N][N];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     int sum = k;     for (int i = 1; i <= n; ++i)       scanf( %d %d %d , &p[i].a, &p[i].b, &p[i].c), sum += p[i].b;     for (int i = 1; i <= n; ++i) nex[i] = i;     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       nex[v] = max(nex[v], u);     }     for (int i = 1; i <= n; ++i) {       pre[nex[i]].push_back(p[i].c);     }     memset(dp, -0x3f3f3f3f, sizeof(dp));     dp[1][k] = 0;     for (int i = 1; i <= n; ++i) {       for (int j = p[i].a; j <= 5000; ++j) {         int nj = j + p[i].b;         if (dp[i][j] >= 0) dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j]);       }       for (int k = 0; k < pre[i].size(); ++k) {         int x = pre[i][k];         for (int j = 0; j <= 5000; ++j) {           dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j + 1] + x);         }       }     }     int ans = -1;     for (int i = 0; i <= sum; ++i) ans = max(ans, dp[n + 1][i]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     if (n == 1)       cout << 0;     else if (n == 2)       cout << m;     else       cout << 2 * m;     puts(  );   }   int main() {     int q;     for (cin >> q; q--;) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   } a[5], b[5];   int ans;   int dis(int i, int j) {     int res = (a[i].x - a[j].x) * (a[i].x - a[j].x);     return res + (a[i].y - a[j].y) * (a[i].y - a[j].y);   }   int ok() {     map<int, int> mp;     for (int i = 1; i < 4; i++)       for (int j = i + 1; j <= 4; j++) mp[dis(i, j)]++;     if (mp.size() != 2) return 0;     int t;     for (auto tmp : mp) {       if (tmp.first == 0) return 0;       t = tmp.second;     }     if (t == 4 || t == 2) return 1;     return 0;   }   void Rotate(int p) {     int x = a[p].x - b[p].x, y = a[p].y - b[p].y;     a[p].x = -y + b[p].x;     a[p].y = x + b[p].y;   }   void dfs(int p, int step) {     if (p == 5) {       if (ok()) ans = min(ans, step);       return;     }     dfs(p + 1, step);     for (int i = 1; i < 4; i++) {       Rotate(p);       dfs(p + 1, step + i);     }     Rotate(p);   }   int main() {     int T;     cin >> T;     while (T--) {       ans = 100;       for (int i = 1; i <= 4; i++) cin >> a[i].x >> a[i].y >> b[i].x >> b[i].y;       dfs(1, 0);       if (ans == 100)         puts( -1 );       else         cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, u, v, w;   unordered_map<long long, vector<long long>> m;   struct Key {     long long N, p;     bool operator==(const Key& other) const {       return (N == other.N && p == other.p);     }   };   struct KeyHasher {     size_t operator()(const Key& k) const { return k.N * 59 + k.p * 61; }   };   set<pair<long long, long long>, greater<pair<long long, long long>>> sp[100010];   unordered_map<Key, long long, KeyHasher> done, wt, val;   long long dfs(long long i, vector<bool>& vis) {     vis[i] = 1;     long long mx = 0;     for (auto it : m[i]) {       if (vis[it] == 0) {         long long v = dfs(it, vis);         long long jk = val[{it, i}] = v + wt[{it, i}];         sp[i].insert({jk, it});         mx = max(mx, val[{it, i}]);       }     }     return mx;   }   void dfs2(long long i, vector<bool>& vis) {     vis[i] = 1;     for (auto it : m[i]) {       if (vis[it] == 0) {         long long mx = 0;         for (auto pt : sp[i]) {           if (it != pt.second) {             mx = pt.first;             break;           }         }         long long jk = val[{i, it}] = mx + wt[{i, it}];         sp[it].insert({jk, i});         dfs2(it, vis);       }     }   }   int main() {     cin >> n >> k;     for (long long i = 1; i < n; i++) {       cin >> u >> v >> w;       m[u].push_back(v);       m[v].push_back(u);       wt[{u, v}] = wt[{v, u}] = w;     }     vector<bool> vis(n + 1, 0);     vector<bool> vis2(n + 1, 0);     dfs(1, vis);     dfs2(1, vis2);     long long mn = LLONG_MAX, ind;     for (auto it : m) {       long long mx = 0;       for (auto i : it.second) mx = max(mx, val[{i, it.first}]);       if (mn > mx) {         mn = mx;         ind = it.first;       }     }     k--;     vector<long long> v;     v.push_back(ind);     long long s = ind, e = ind;     while (k) {       long long mx = 0, in, f = 0, first = 0;       for (auto it : m[s]) {         if (done[{it, s}] == 0) {           first = 1;           if (mx < val[{it, s}]) {             mx = val[{it, s}];             in = it;           }         }       }       if (s != e) {         for (auto it : m[e]) {           if (done[{it, e}] == 0) {             first = 1;             if (mx < val[{it, e}]) {               f = 1;               mx = val[{it, e}];               in = it;             }           }         }       }       if (first == 0) break;       if (f) {         done[{e, in}] = done[{in, e}] = 1;         e = in;       } else {         done[{s, in}] = done[{in, s}] = 1;         s = in;       }       v.push_back(in);       k--;     }     long long mx = 0;     for (auto it : v) {       for (auto i : m[it]) {         if (done[{it, i}] == 0) mx = max(mx, val[{i, it}]);       }     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char gride[5010];   vector<vector<char> > grid;   vector<vector<int> > pesq, pesq2;   vector<vector<int> > pdir, pdir2;   vector<vector<int> > pcima, pcima2;   vector<vector<int> > pbaxo, pbaxo2;   void apaga(int i, int j) {     if (pesq2[i][j] != -1) pdir2[i][pesq2[i][j]] = pdir2[i][j];     if (pdir2[i][j] != -1) pesq2[i][pdir2[i][j]] = pesq2[i][j];     if (pcima2[i][j] != -1) pbaxo2[pcima2[i][j]][j] = pbaxo2[i][j];     if (pbaxo2[i][j] != -1) pcima2[pbaxo2[i][j]][j] = pcima2[i][j];   }   int simula(int i, int j) {     if (grid[i][j] ==  U ) {       int k = pcima2[i][j];       if (k == -1) return 1;       apaga(i, j);       return 1 + simula(k, j);     }     if (grid[i][j] ==  D ) {       int k = pbaxo2[i][j];       if (k == -1) return 1;       apaga(i, j);       return 1 + simula(k, j);     }     if (grid[i][j] ==  L ) {       int k = pesq2[i][j];       if (k == -1) return 1;       apaga(i, j);       return 1 + simula(i, k);     }     if (grid[i][j] ==  R ) {       int k = pdir2[i][j];       if (k == -1) return 1;       apaga(i, j);       return 1 + simula(i, k);     }     return 0;   }   int main() {     scanf( %d %d , &n, &m);     grid.resize(n);     for (int i = 0; i < n; i++) {       scanf( %s , gride);       grid[i].resize(m);       for (int j = 0; j < m; j++) grid[i][j] = gride[j];     }     pesq.resize(n);     pdir.resize(n);     pcima.resize(n);     pbaxo.resize(n);     for (int i = 0; i < n; i++) {       pesq[i].resize(m);       pdir[i].resize(m);       pcima[i].resize(m);       pbaxo[i].resize(m);       int atu = -1;       for (int j = 0; j < m; j++)         if (grid[i][j] !=  . ) {           pesq[i][j] = atu;           atu = j;         }       atu = -1;       for (int j = m - 1; j >= 0; j--)         if (grid[i][j] !=  . ) {           pdir[i][j] = atu;           atu = j;         }     }     for (int j = 0; j < m; j++) {       int atu = -1;       for (int i = 0; i < n; i++)         if (grid[i][j] !=  . ) {           pcima[i][j] = atu;           atu = i;         }       atu = -1;       for (int i = n - 1; i >= 0; i--)         if (grid[i][j] !=  . ) {           pbaxo[i][j] = atu;           atu = i;         }     }     int best = 0;     int qts = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (grid[i][j] !=  . ) {           pcima2 = pcima;           pbaxo2 = pbaxo;           pesq2 = pesq;           pdir2 = pdir;           int t = simula(i, j);           if (t == best)             qts++;           else if (t > best) {             best = t;             qts = 1;           }         }     printf( %d %d n , best, qts);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3, INF = 1e9;   int main() {     ios ::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);     long long n, last = 0, id = 0, ans = 0, i = 0;     cin >> n;     vector<pair<int, int> > v(n);     for (auto &t : v) cin >> t.first >> t.second;     for (; i <= N; ++i) {       if (last) last--;       if (v[id].first == i) {         last += v[id].second;         id++;       }       ans = max(ans, last);       if (id == v.size()) {         break;       }     }     ans = max(ans, last);     cout << i + last <<     << ans << endl;     return 0;   }