malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int X = 0;     register char ch = 0;     while (ch < 48 || ch > 57) ch = getchar();     while (ch >= 48 && ch <= 57) X = X * 10 + (ch ^ 48), ch = getchar();     return X;   }   long long powM(long long a, int t = 998244353 - 2) {     long long ans = 1;     while (t) {       if (t & 1) ans = ans * a % 998244353;       a = a * a % 998244353;       t >>= 1;     }     return ans;   }   int r[135000 << 2];   long long invG = powM(3), fac[135000], inv[135000];   void NTT(long long *f, bool op, int n) {     for (int i = 0; i < n; i++)       if (r[i] < i) swap(f[r[i]], f[i]);     for (int len = 1; len < n; len <<= 1) {       int w = powM(op == 1 ? 3 : invG, (998244353 - 1) / len / 2);       for (int p = 0; p < n; p += len + len) {         long long buf = 1;         for (int i = p; i < p + len; i++) {           int sav = f[i + len] * buf % 998244353;           f[i + len] = f[i] - sav;           if (f[i + len] < 0) f[i + len] += 998244353;           f[i] = f[i] + sav;           if (f[i] >= 998244353) f[i] -= 998244353;           buf = buf * w % 998244353;         }       }     }   }   long long g[135000 << 1];   void times(long long *f, long long *gg, int len, int lim) {     int m = len + len, n;     for (int i = 0; i < len; i++) g[i] = gg[i];     for (n = 1; n < m; n <<= 1)       ;     for (int i = len; i < n; i++) g[i] = 0;     for (int i = 0; i < n; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) ? n >> 1 : 0);     NTT(f, 1, n);     NTT(g, 1, n);     for (int i = 0; i < n; ++i) f[i] = f[i] * g[i] % 998244353;     NTT(f, 0, n);     long long invn = powM(n);     for (int i = 0; i < lim; ++i) f[i] = f[i] * invn % 998244353;     for (int i = lim; i < n; ++i) f[i] = 0;   }   long long f[135000 << 1], p[135000 << 1], m;   int n;   int main() {     n = read() + 1;     scanf( %I64d , &m);     m %= (998244353 - 1);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % 998244353;     inv[n] = powM(fac[n]);     for (int i = n; i; i--) inv[i - 1] = inv[i] * i % 998244353;     for (int i = 0; i < n; i++) f[i] = read();     for (int i = 0; i < n; i++) p[n - i - 1] = f[i] * fac[i] % 998244353;     for (int i = 0; i < n; i++) f[i] = inv[i] % 998244353;     times(p, f, n, n);     for (int i = 0; i < n; i++) f[n - i - 1] = p[i] * inv[n - i - 1] % 998244353;     for (int i = 0; i < n; i++)       f[i] = f[i] * powM(i + 1, 998244353 - 1 - m) % 998244353;     for (int i = 0; i < n; i++)       if (i & 1)         p[n - i - 1] = 998244353 - (f[i] * fac[i] % 998244353);       else         p[n - i - 1] = f[i] * fac[i] % 998244353;     for (int i = 0; i < n; i++) f[i] = inv[i] % 998244353;     times(p, f, n, n);     for (int i = 0; i < n; i++) f[n - i - 1] = p[i] * inv[n - i - 1] % 998244353;     for (int i = 0; i < n; i++)       printf( %I64d  , (i & 1) ? (998244353 - f[i]) % 998244353 : f[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 20071027;   const double pi = acos(1.0 * (-1));   int p[1001111];   long long fun(long long x) {     long long dt = 1 + 8 * x;     long long t = sqrt(dt * 1.0) + 0.0000001;     if (t * t != dt) return -1;     return (1 + t) / 2;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n00, n01, n10, n11;     cin >> n00 >> n01 >> n10 >> n11;     long long n1, n0;     n1 = fun(n11);     n0 = fun(n00);     if (n00 + n01 + n10 + n11 == 0) {       cout <<  1 ;       return 0;     }     if (n1 == -1 || n0 == -1) {       cout <<  Impossible ;       return 0;     }     if (n01 + n10 == 0) {       if (n0 == 1)         for (int i = 0; i < n1; i++) cout <<  1 ;       else if (n1 == 1)         for (int i = 0; i < n0; i++) cout <<  0 ;       else         cout <<  Impossible ;       return 0;     }     if (n01 + n10 != n0 * n1) {       cout <<  Impossible ;       return 0;     }     if (n01 > n0) {       p[n0] = n01 / n0;       n01 -= n0 * p[n0];       n1 -= p[n0];     }     if (n1) {       p[n01]++;       n1--;     }     p[0] += n1;     for (int i = 0; i < n0; i++) {       for (int j = 0; j < p[i]; j++) cout <<  1 ;       cout <<  0 ;     }     for (int i = 0; i < p[n0]; i++) cout <<  1 ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       long long a[n + 5], m = 0;       vector<int> idx;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       long long ans = 0;       for (int i = 0; i < n - 1; i++) {         ans = max(ans, a[i] * a[i + 1]);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 300003;   int h[4][4];   bool res[4][MX];   int len;   int calc(int i) {     if (h[0][i] <= h[0][1]) {       int x = h[0][1] - h[0][i];       if ((h[1][i] < x) || (h[1][i] - x) % 2) return -1;       int k = (h[1][i] - x) / 2;       if (k > h[0][i]) return -1;       return h[0][i] - k;     } else {       int x = h[0][i] - h[0][1];       if (h[1][i] < x || (h[1][i] - x) % 2) return -1;       int k = (h[1][i] - x) / 2;       if (k > h[0][1]) return -1;       return h[0][1] - k;     }   }   bool solve() {     for (int j = 0; j < h[0][1]; ++j) res[1][j] = 1;     int a = calc(2);     int c = calc(3);     if (a == -1 || c == -1) return false;     int b = h[0][2] - a;     int d = h[0][3] - c;     int x1, y1;     if (a >= c) {       x1 = a - c;       y1 = a;       h[2][3] -= a - c;       for (int i = 0; i < a; ++i) res[2][i] = 1;       for (int i = a - c; i < a; ++i) res[3][i] = 1;     } else {       x1 = c - a;       y1 = c;       h[2][3] -= c - a;       for (int i = c - a; i < c; ++i) res[2][i] = 1;       for (int i = 0; i < c; ++i) res[3][i] = 1;     }     int x2, y2;     if (b >= d) {       x2 = h[0][1] + b - d;       y2 = h[0][1] + b;       h[2][3] -= b - d;       for (int i = h[0][1]; i < h[0][1] + b; ++i) res[2][i] = 1;       for (int i = h[0][1] + b - d; i < h[0][1] + b; ++i) res[3][i] = 1;     } else {       x2 = h[0][1] + d - b;       y2 = h[0][1] + d;       h[2][3] -= d - b;       for (int i = h[0][1] + d - b; i < h[0][1] + d; ++i) res[2][i] = 1;       for (int i = h[0][1]; i < h[0][1] + d; ++i) res[3][i] = 1;     }     if (h[2][3] < 0 || h[2][3] % 2) return false;     int py = y1;     while (y1 < h[0][1] && x1 < py && h[2][3] > 0) {       swap(res[2][x1], res[2][y1]);       ++x1;       ++y1;       h[2][3] -= 2;     }     len = y2;     py = y2;     while (x2 < py && h[2][3] > 0) {       swap(res[2][x2], res[2][y2]);       ++x2;       ++y2;       ++len;       h[2][3] -= 2;     }     return h[2][3] == 0;   }   int main() {     for (int i = 0; i < 4; ++i)       for (int j = i + 1; j < 4; ++j) scanf( %d , h[i] + j);     if (solve()) {       printf( %d n , len);       for (int i = 0; i < 4; ++i) {         for (int j = 0; j < len; ++j) printf( %c ,  a  + res[i][j]);         printf(  n );       }     } else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int b, k, a[100005], sum, tmp;   int main() {     cin >> b >> k;     for (int i = 1; i <= k; ++i) {       scanf( %d , &a[i]);       a[i] %= 2;     }     tmp = 1;     for (int i = k; i >= 1; --i) {       sum = (sum + tmp * a[i]) % 2;       tmp = tmp * b % 2;     }     if (sum & 1) {       cout <<  odd  << endl;     } else {       cout <<  even  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m), ++n;     long long ans = 0;     for (int a = m + 1; a <= n / 2; ++a) {       int tmp = 0;       for (int b = m + 1, c = n - m - 1; b < n - m && c > m; ++b) {         while (c > m && a * ((a << 1) + b - (n << 1) - c) >= -c * (n + b)) --c;         tmp += c - m;       }       if (a != n - a) tmp *= 2;       ans += tmp;     }     cout << ans * 3 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int c[1200000], save[5500];   bool flag[1200000];   int main() {     int n, k;     while (scanf( %d%d , &n, &k) != EOF) {       for (int i = 1; i <= n; i++) scanf( %d , &save[i]);       sort(save + 1, save + n + 1);       memset(c, 0, sizeof(c));       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++) {           save[j] > save[i] ? c[save[j] - save[i]]++ : c[save[i] - save[j]]++;         }       int K = k * (k + 1) / 2;       for (int i = 1; i <= save[n] + 1; i++) {         int temp = 0;         for (int j = i; j <= save[n] + 1; j += i) {           temp += c[j];           if (temp > K) break;         }         if (temp <= K) {           int cnt = 0;           memset(flag, 0, sizeof(flag));           for (int j = 1; j <= n; j++) {             int tt = save[j] % i;             if (flag[tt]) {               cnt++;               if (cnt > k) break;             }             flag[tt] = 1;           }           if (cnt <= k) {             printf( %d n , i);             break;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using VI = vector<int>;   using VI2 = vector<VI>;   using UM = unordered_map<int, int>;   using UM2 = unordered_map<int, UM>;   using M = map<int, int>;   using M2 = map<int, M>;   using u64 = unsigned long long;   using i64 = long long;   using u32 = unsigned int;   using USI = unordered_set<int>;   using USS = unordered_set<string>;   using VUS = vector<USI>;   int main() {     int n, m;     cin >> n >> m;     VI a(n, 1);     for (int j = 0; j < m; j++) {       int ind = -1;       int ind2 = -1;       bool f = false;       for (int i = 0; i < n; i++) {         if (!a[i]) continue;         ind2 = i;         int ip1 = (i + 1) % n;         int im1 = !i ? n - 1 : i - 1;         int sc = 0;         if (a[ip1]) sc++;         if (a[im1]) sc++;         if (sc == 2) {           a[i] = 0;           f = true;           break;         }         if (ind >= 0 && sc == 1) {           ind = i;           break;         }       }       if (ind >= 0) {         a[ind] = 0;         continue;       }       if (!f && ind2 < 0) {         cout <<  0 n ;         return 0;       }       if (!f) a[ind2] = 0;     }     int mgn = 1;     if (a[0]) a[0] = mgn++;     for (int i = 1; i < n; i++) {       if (!a[i]) continue;       if (a[i - 1])         a[i] = a[i - 1];       else         a[i] = mgn++;     }     mgn--;     if (a[0] && a[n - 1] && a[0] != a[n - 1]) {       mgn--;     }     cout << mgn <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, tmp = 1;   int sum(int a) {     int res = 0;     while (a) {       res += a % 10;       a /= 10;     }     return res;   }   int main() {     cin >> n >> m;     if (2 * n > 2220) {       int nn = n / 2 + n % 2;       for (int i = 1; i <= nn; ++i) {         cout << 2;       }       cout << endl;       for (int i = 1; i <= nn - 1; ++i) {         cout << 7;       }       cout << 8 << endl;       return 0;     }     for (int i = 1; i <= n; ++i) {       cout << 1;     }     cout << endl;     for (int i = 1; i <= n - 1; ++i) {       cout << 8;     }     cout << 9 << endl;   }
#include <bits/stdc++.h>   using lli = long long int;   using li = long int;   using namespace std;   const lli MOD{1000000007};   const lli INF{(false ? (INT_MAX - 1) / 2 : (lli)1e18 + 5)};   const lli N{200005};   int main() {     cout << setprecision(15);     cin.tie(nullptr)->sync_with_stdio(false);     li T{1};     cin >> T;     while (T--) {       lli n{}, x{}, y{};       cin >> n >> x >> y;       lli z{x + y - 1};       lli done{n - z};       if (done > 0)         cout << 1 <<    ;       else         cout << min(2 - done, n) <<    ;       done = max((lli)0, done);       cout << n - done <<   n ;       if (z <= n) done -= n - z + 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fnc() {     int n;     cin >> n;     cout << n << endl;     for (int i = 0; i < n; i++) cout << i + 1 <<    ;     cout << endl;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) fnc();   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   template <class T>   inline void chkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void chkmax(T &a, T b) {     if (a < b) a = b;   }   int main() {     int n, m;     cin >> n >> m;     --n;     int l = 1, r = 1000;     for (int i = 0; i < m; ++i) {       int k, first;       cin >> k >> first;       chkmax(l, (k + first - 1) / first);       if (first != 1) chkmin(r, (k - 1) / (first - 1));     }     int f1 = n / l + 1;     int f2 = n / r + 1;     if (f1 != f2)       cout <<  -1 n ;     else       cout << f1 <<   n ;   }
#include <bits/stdc++.h>   int main() {     int N, gre[101], res[100][101], n, i, j;     scanf( %d , &N);     for (i = 0; i < N; i++) {       for (j = 0; j < N; j++) {         scanf( %d , &res[i][j]);       }       gre[i] = 1;     }     n = 0;     for (i = 0; i < N; i++) {       for (j = i; j < N; j++) {         if (res[i][j] == 0) {           continue;         }         if (res[i][j] == 1) {           gre[i] = 0;         }         if (res[i][j] == 2) {           gre[j] = 0;         }         if (res[i][j] == 3) {           gre[i] = gre[j] = 0;         }       }       if (gre[i]) {         n++;       }     }     j = 0;     printf( %d n , n);     for (i = 0; j < n; i++) {       if (gre[i]) {         printf( %d%c , i + 1, j++ == n - 1 ?   n  :    );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t[500005], mid;   long long l[500005], r[500005], h[500005];   struct st {     long long h, cnt;   };   stack<st> q;   int main() {     cin.sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> t[i];     q.push({-1, 1});     for (int i = 1; i <= n; i++) {       long long c = 0, h = 0;       while (q.top().h >= t[i]) {         c += q.top().cnt;         h += q.top().cnt * q.top().h;         q.pop();       }       l[i] = l[i - 1] - h + (t[i] * (c + 1));       q.push({t[i], c + 1});     }     while (q.size()) q.pop();     q.push({0, 1});     for (int i = n; i > 0; i--) {       long long c = 0, h = 0;       while (q.top().h >= t[i]) {         c += q.top().cnt;         h += q.top().cnt * q.top().h;         q.pop();       }       r[i] = r[i + 1] - h + (t[i] * (c + 1));       q.push({t[i], c + 1});     }     while (q.size()) q.pop();     long long ms = 0;     for (int i = 1; i <= n; i++)       if (l[i] + r[i] - t[i] > ms) ms = l[i] + r[i] - t[i], mid = i;     h[mid] = t[mid];     for (int i = mid + 1; i <= n; i++) {       h[i] = min(h[i - 1], t[i]);     }     for (int i = mid - 1; i > 0; i--) {       h[i] = min(h[i + 1], t[i]);     }     for (int i = 1; i <= n; i++) cout << h[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, t;   void read_input() { cin >> a >> b; }   void solve() {     int res = abs(a - b);     int ans = res / 5;     res = res % 5;     ans += res / 2;     res %= 2;     ans += res;     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) read_input(), solve();     return 0;   }
#include<bits/stdc++.h>   using namespace std;   long long a[1000010];   bool cmp(long long a,long long b)   {    return a>b;   }   int main() {       long long m,n,i,j,x,y,suma=0,sumb=0;    cin>>n;    while(n--)    {     cin>>m;     for(i=0;i<m;i++)     cin>>a[i];     sort(a,a+m,cmp);     for(i=0;i<m;)     {     if(a[i]%2==0)     suma+=a[i];     i++;     if(a[i]%2!=0)     sumb+=a[i];     i++;         }     if(sumb==suma)     cout<< Tie <<endl;     if(suma>sumb)     cout<< Alice <<endl;     if(suma<sumb)     cout<< Bob <<endl;     suma=0;     sumb=0;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ar[n + 2], tr1[n + 2], tr2[n + 2], kl[k + 2][102];     memset(kl, 0, sizeof(kl));     vector<pair<int, int>> vec;     for (int i = 0; i < n; i++) {       cin >> ar[i];       tr1[i] = ar[i];       tr2[i] = ar[i];     }     sort(ar, ar + n);     sort(tr1, tr1 + n);     if (ar[n - 1] - ar[0] > k) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     int mn = 101;     for (int i = 0; i < k; i++) {       int j = 0;       for (; j < n; j++) {         if (ar[j] > 0) {           mn = ar[j];           break;         }       }       for (; j < n; j++) {         if (i == 0) {           kl[i][j] = min(mn + 1, ar[j]);           ar[j] -= min(mn + 1, ar[j]);         } else {           kl[i][j] = 1;           ar[j] -= 1;         }       }     }     for (int i = 0; i < n; i++) {       int f = tr2[i];       int zz;       for (int z = 0; z < n; z++) {         if (tr1[z] == f) {           zz = z;           break;         }       }       for (int j = 0; j < k; j++) {         if (kl[j][zz] == 0) {           continue;         }         for (int l = 0; l < kl[j][zz]; l++) {           cout << j + 1 <<    ;         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sol();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     long long ml = 1, ans = 0;     vector<int> ls(n);     map<long long, int> pre, mp;     mp[0] = 1;     vector<long long> an;     while (ml < 1e15) {       if (!pre[ml])         an.push_back(ml), pre[ml] = 1;       else         break;       ml *= k;       if ((ml > 1e15 || -ml > 1e15) || (ml % k != 0)) break;     }     for (int &x : ls) cin >> x;     long long sm = 0ll;     for (int x : ls) {       sm += x;       for (long long y : an)         if (mp[sm - y]) ans += mp[sm - y];       mp[sm]++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int n, bin[35], f[35][35][2];   void updata(int &x, int y) {     x += y;     x -= x >= MOD ? MOD : 0;   }   int main() {     scanf( %d , &n);     bin[0] = 1;     for (int i = 1; i <= 30; i++) bin[i] = bin[i - 1] * 2;     for (int i = 30; i >= 0; i--)       if (n & bin[i]) {         f[i][1][1] = f[i][0][0] = 1;         break;       }     for (int i = 30; i >= 1; i--)       for (int j = 0; j <= 30; j++) {         if (f[i][j][0]) {           updata(f[i - 1][j + 1][0], f[i][j][0]);           updata(f[i - 1][j][0], (long long)f[i][j][0] * bin[j] % MOD);         }         if (f[i][j][1]) {           if (n & bin[i - 1]) {             updata(f[i - 1][j + 1][1], f[i][j][1]);             updata(f[i - 1][j][0], (long long)f[i][j][1] * bin[j - 1] % MOD);             updata(f[i - 1][j][1], (long long)f[i][j][1] * bin[j - 1] % MOD);           } else             updata(f[i - 1][j][1], (long long)f[i][j][1] * bin[j - 1] % MOD);         }       }     int ans = 0;     if (!n) ans++;     for (int i = 0; i <= 30; i++)       updata(ans, f[0][i][0]), updata(ans, f[0][i][1]);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void redondear(string &s, int pto, int idx) {     if (idx == (int)(s.size())) {       cout << s << endl;       return;     }     s.resize(idx);     bool unoAdelante = false;     for (int i = (idx)-1; i >= (int)(0); i--) {       if (i == pto) {         continue;       }       if (i == 0 && s[i] ==  9 ) {         s[i] =  0 ;         unoAdelante = true;         continue;       }       if (s[i] ==  9 ) {         s[i] =  0 ;       } else {         s[i]++;         break;       }     }     if (unoAdelante) cout <<  1 ;     if (s[s.size() - 1] ==  . ) {       s.resize(s.size() - 1);     }     cout << s << endl;   }   int main() {     int largo, segundos;     cin >> largo >> segundos;     string nota;     cin >> nota;     int punto = 0;     for (int i = (0); i < (int)(nota.size()); i++) {       if (nota[i] ==  . ) {         punto = i;         break;       }     }     int minimoIndice = largo;     int turnosUsados = 0;     for (int i = (largo)-1; i >= (int)(punto + 1); i--) {       if (nota[i] >=  5 ) {         minimoIndice = i;         turnosUsados = 1;       } else if (nota[i] ==  4  && turnosUsados < segundos && turnosUsados > 0) {         minimoIndice = i;         turnosUsados++;       } else {         turnosUsados = 0;       }     }     redondear(nota, punto, minimoIndice);   }
#include <bits/stdc++.h>   using namespace std;   int n;   int l, r;   void did(int &x, int y) {     printf( ? %d n , y);     fflush(stdout);     scanf( %d , &x);   }   int main() {     scanf( %d , &n);     if ((n / 2) & 1) {       printf( ! -1 );       fflush(stdout);       return 0;     }     while (1) {       printf( ? 1 n );       fflush(stdout);       int x, y;       int l = 1, r = n / 2;       scanf( %d , &x);       printf( ? %d n , n / 2 + 1);       fflush(stdout);       scanf( %d , &y);       if (x == y) {         printf( ! %d n , 1);         fflush(stdout);         return 0;       }       int xx = x, yy = y;       while (l <= r) {         int mid = (l + r) / 2;         did(xx, mid);         did(yy, mid + n / 2);         if (xx == yy) {           printf( ! %d n , mid);           fflush(stdout);           return 0;         }         if ((xx < yy) == (x < y))           l = mid + 1;         else           r = mid - 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 3010;   int n, x[M];   char d[M][6];   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};   vector<long long> X, Y;   int g[M][M], fw1, fw2;   queue<pair<int, int> > Q;   const long long INF = 20000000005LL, MINF = -INF;   struct point {     long long lasx, lasy, nowx, nowy;     point() {}     point(int _lasx, int _lasy, int _nowx, int _nowy)         : lasx(_lasx), lasy(_lasy), nowx(_nowx), nowy(_nowy) {}   } ways[M];   inline int renumber(int x, vector<long long> _find) {     return find(_find.begin(), _find.end(), x) - _find.begin();   }   inline void BFS() {     while (!Q.empty()) Q.pop();     Q.push(make_pair(0, 0));     g[0][0] = 2;     fw1 = X.size(), fw2 = Y.size();     while (!Q.empty()) {       pair<int, int> top = Q.front();       Q.pop();       for (int i = 0; i < 4; ++i) {         pair<int, int> x;         x.first = top.first + dx[i], x.second = top.second + dy[i];         if (x.first >= 0 && x.first < fw1 && x.second >= 0 && x.second < fw2 &&             g[x.first][x.second] == 0) {           g[x.first][x.second] = 2;           Q.push(x);         }       }     }   }   int main() {     scanf( %d , &n);     long long nowx, nowy;     nowx = nowy = 0;     X.push_back(MINF);     X.push_back(INF);     Y.push_back(MINF);     Y.push_back(INF);     for (int i = 1; i <= n; ++i) {       int face;       long long tx, ty;       scanf( %s%d , d[i], &x[i]);       if (d[i][0] ==  R ) face = 0;       if (d[i][0] ==  L ) face = 1;       if (d[i][0] ==  D ) face = 2;       if (d[i][0] ==  U ) face = 3;       tx = nowx + dx[face] * x[i];       ty = nowy + dy[face] * x[i];       int Xmin = min(nowx, tx), Xmax = max(nowx, tx) + 1;       int Ymin = min(nowy, ty), Ymax = max(nowy, ty) + 1;       X.push_back(Xmin);       X.push_back(Xmax);       Y.push_back(Ymin);       Y.push_back(Ymax);       ways[i] = point(Xmin, Ymin, Xmax, Ymax);       nowx = tx, nowy = ty;     }     sort(X.begin(), X.end());     sort(Y.begin(), Y.end());     X.resize(unique(X.begin(), X.end()) - X.begin());     Y.resize(unique(Y.begin(), Y.end()) - Y.begin());     for (int i = 1; i <= n; ++i) {       int tx1 = renumber(ways[i].lasx, X), tx2 = renumber(ways[i].nowx, X),           ty1 = renumber(ways[i].lasy, Y), ty2 = renumber(ways[i].nowy, Y);       for (int j = tx1; j < tx2; ++j)         for (int k = ty1; k < ty2; ++k) g[j][k] = 1;     }     BFS();     long long ans = 0;     for (int i = 0; i <= fw1 - 2; ++i)       for (int j = 0; j <= fw2 - 2; ++j)         if (g[i][j] != 2)           ans = ans + (long long)(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]);     cout << ans << endl;     return 0;   }