malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int INF = 1e9 + 7;   const int N = 1010;   const double pi = 3.1415926;   int n;   int t[110], d[110], p[110], pre[2010], now[2010], sum[2010], good[2010];   int dp[2010];   vector<int> v[2010];   struct node {     int t;     int d;     int p;     int id;   } e[110];   bool cmp(node a, node b) { return a.d < b.d; }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < 2010; i++) v[i].clear();       for (int i = 0; i < n; i++) {         scanf( %d%d%d , &e[i].t, &e[i].d, &e[i].p);         e[i].id = i + 1;       }       sort(e, e + n, cmp);       memset(dp, 0, sizeof(dp));       ;       memset(sum, 0, sizeof(sum));       ;       memset(now, 0, sizeof(now));       ;       memset(pre, 0, sizeof(pre));       ;       int ans = 0, idx = 0, s1 = 0, s2 = 0;       for (int i = 0; i < n; i++) {         for (int j = e[i].d; j > e[i].t; j--) {           s1 = 0;           if (dp[j - e[i].t] + e[i].p > dp[j]) {             dp[j] = dp[j - e[i].t] + e[i].p;             sum[j] = sum[j - e[i].t] + 1;             v[j] = v[j - e[i].t];             v[j].push_back(e[i].id);           }           if (dp[j] > ans) {             idx = j;             ans = dp[j];           }         }       }       printf( %d n , ans);       printf( %d n , sum[idx]);       for (int i = 0; i < v[idx].size(); i++) {         printf( %d  , v[idx][i]);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     ios::sync_with_stdio(0);     solve();     return 0;   }   pair<pair<double, double>, pair<double, double> > rects[100];   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> rects[i].first.first >> rects[i].first.second >>           rects[i].second.first >> rects[i].second.second;       if (rects[i].first.first > rects[i].second.first)         swap(rects[i].first.first, rects[i].second.first);       if (rects[i].first.second > rects[i].second.second)         swap(rects[i].first.second, rects[i].second.second);       for (int j = 0; j < i; j++) {         double cx = 0, cy = 0, m = 0;         for (int k = j + 1; k <= i; k++) {           double l = fabs(rects[k].first.first - rects[k].second.first);           double lll = l * l * l;           m += lll;           double x = (rects[k].first.first + rects[k].second.first) / 2.0;           double y = (rects[k].first.second + rects[k].second.second) / 2.0;           cx += lll * x;           cy += lll * y;         }         cx /= m;         cy /= m;         if (rects[j].first.first > cx || rects[j].first.second > cy ||             rects[j].second.first < cx || rects[j].second.second < cy) {           cout << i;           return;         }       }     }     cout << n;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 8e5 + 1000;   long long re[maxn];   vector<long long> v;   int sum[maxn];   struct node {     long long l, r;   } a[maxn];   long long ans[maxn];   int getid(long long x) {     return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &a[i].l, &a[i].r);       v.push_back(a[i].l);       v.push_back(a[i].r);       v.push_back(a[i].l + 1);       v.push_back(a[i].r + 1);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     int sz = v.size();     for (int i = 0; i < v.size(); i++) {       re[i + 1] = v[i];     }     for (int i = 0; i < n; i++) {       int l = getid(a[i].l);       int r = getid(a[i].r);       sum[l]++;       sum[r + 1]--;     }     for (int i = 1; i <= sz; i++) {       sum[i] = sum[i - 1] + sum[i];     }     for (int i = 1; i < sz; i++) {       ans[sum[i]] += re[i + 1] - re[i];     }     for (int i = 1; i <= n; i++) {       printf( %lld  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, H[300005], d, ant[300005];   vector<int> v[300005], st, L;   void dfs(int nod) {     int ok = 0;     st.push_back(nod);     H[nod] = st.size();     if (H[nod] >= d) {       cout <<  PATH n ;       cout << st.size() <<   n ;       for (auto it : st) cout << it <<    ;       exit(0);     }     for (auto it : v[nod])       if (!H[it]) {         ant[it] = nod;         dfs(it);         ok = 1;       }     if (!ok) L.push_back(nod);     st.pop_back();   }   bool _try(int a, int b) {     if (H[a] < H[b]) swap(a, b);     if (H[a] - H[b] + 1 >= 3 && (H[a] - H[b] + 1) % 3 != 0) {       cout << H[a] - H[b] + 1 <<   n ;       int crt = a;       while (crt != b) {         cout << crt <<    ;         crt = ant[crt];       }       cout << crt <<   n ;       return 1;     }     return 0;   }   bool _try2(int a, int b, int c) {     if (H[a] < H[b]) swap(a, b);     if (H[a] - H[b] + 2 >= 3 && (H[a] - H[b] + 2) % 3 != 0) {       cout << H[a] - H[b] + 2 <<   n ;       int crt = a;       while (crt != b) {         cout << crt <<    ;         crt = ant[crt];       }       cout << crt <<     << c <<   n ;       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     d = n / k + (n % k != 0);     for (int i = 1; i <= m; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1);     cout <<  CYCLES n ;     for (auto it : L) {       if (k == 0) break;       k--;       if (_try(it, v[it][0])) continue;       if (_try(it, v[it][1])) continue;       if (_try(it, v[it][2])) continue;       if (_try2(v[it][0], v[it][1], it)) continue;       if (_try2(v[it][0], v[it][2], it)) continue;       if (_try2(v[it][1], v[it][2], it)) continue;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int b[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + n);     int left = 0, right = 0;     for (int i = 0; i < n; i++) {       if (b[i] != a[i]) {         left = i;         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (b[i] != a[i]) {         right = i;         break;       }     }     int i = left;     int j = right;     while (left < right) {       swap(b[left], b[right]);       left++;       right--;     }     int flag = 1;     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         flag = 0;         break;       }     }     if (flag) {       cout <<  yes  << endl;       cout << i + 1 <<     << j + 1;     } else       cout <<  no ;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     if (a == 1 || b == 0) return 1;     long long c = power(a, b / 2);     long long res = 1;     res = c * c;     if (res >= 1000000007) res %= 1000000007;     if (b % 2) res *= a;     if (res >= 1000000007) res %= 1000000007;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     string s;     cin >> s;     map<char, long long> count;     for (long long i = 0; i < n; i++) {       count[s[i]]++;     }     vector<long long> v;     for (auto &i : count) {       v.push_back(i.second);     }     long long ans = 0;     sort(v.begin(), v.end(), greater<long long>());     for (long long i = 0; i < v.size(); i++) {       if (v[i] == v[0]) ans++;     }     cout << power(ans, n);   }
#include <bits/stdc++.h>   using namespace std;   long long N, K, dp[501][501];   long long p2[501];   void pre() {     long long i;     p2[0] = 1;     for (i = 1; i < 501; ++i) p2[i] = (p2[i - 1] * 2) % 1000000007;   }   long long rec(long long maxinc, long long cur) {     if (maxinc > K) return 0;     if (cur > N) return (maxinc == K);     long long last = cur - 1;     long long &ret = dp[maxinc][cur];     if (ret != -1) return ret;     long long temp, mul = 1;     ret = 0;     long long cc = cur;     for (; cur <= N; ++cur) {       mul = (mul * p2[last]) % 1000000007;       temp = (rec(maxinc + 1, cur + 1) * (p2[cur - last] - 1)) % 1000000007;       ret = (ret + (temp * mul) % 1000000007) % 1000000007;     }     if (maxinc == K) ret = (ret + mul) % 1000000007;     return ret;   }   int main() {     pre();     while (scanf( %I64d %I64d , &N, &K) != EOF) {       memset(dp, -1, sizeof(dp));       printf( %I64d n , rec(0, 1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   namespace ModCalculator {   const int MOD = 998244353;   inline void Inc(int &x, int y) {     x += y;     if (x >= MOD) x -= MOD;   }   inline void Dec(int &x, int y) {     x -= y;     if (x < 0) x += MOD;   }   inline int Add(int x, int y) {     Inc(x, y);     return x;   }   inline int Sub(int x, int y) {     Dec(x, y);     return x;   }   inline int Mul(int x, int y) { return 1LL * x * y % MOD; }   inline int Ksm(int x, int k) {     int ret = 1;     for (; k; k >>= 1) {       if (k & 1) ret = Mul(ret, x);       x = Mul(x, x);     }     return ret;   }   inline int Inv(int x) { return Ksm(x, MOD - 2); }   }  // namespace ModCalculator   using namespace ModCalculator;   int n, fac[N], finv[N], E[N][N];   void init() {     read(n);     fac[0] = 1;     for (int i = 1; i <= n; ++i) {       fac[i] = Mul(fac[i - 1], i);     }     finv[n] = Inv(fac[n]);     for (int i = n; i >= 1; --i) {       finv[i - 1] = Mul(finv[i], i);     }     E[0][0] = 1;     for (int i = 1; i <= n; ++i) {       E[i][0] = 1;       for (int j = 1; j <= i; ++j) {         E[i][j] = Add(Mul(E[i - 1][j], j + 1), Mul(E[i - 1][j - 1], i - j));       }     }   }   void solve() {     for (int i = 1; i <= n; ++i) {       int ans = 0;       for (int j = i; j <= n; ++j) {         Inc(ans, Mul(E[j][i - 1], Mul(fac[n], finv[j])));       }       printf( %d  , ans);     }   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265389793238462643383279502884197169;   const long long MOD = 1e9 + 7;   const long long MOD1 = 998244353;   const long long MODo = 1e9;   const int MAXN = 2e5 + 2;   const int oo = 1e9;   const long long oo15 = 1e15;   const long long oo18 = 1e18 + 3;   const long long oooo = 9223372036854775807;   void solve() {     int n, dem1 = 0, dem0 = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 1)         dem1++;       else if (x == 0)         dem0++;     }     long long res = 1;     for (int i = 1; i <= dem0; i++) res *= 2;     cout << dem1 * res <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int testcase = 1;     cin >> testcase;     while (testcase--) solve();   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<long long, pair<long long, long long> > &a,                  const pair<long long, pair<long long, long long> > &b) {     return (a.second.first < b.second.first);   }   bool sortbyth(const pair<long long, pair<long long, long long> > &a,                 const pair<long long, pair<long long, long long> > &b) {     return (a.second.second < b.second.second);   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long max3(long long a, long long b, long long c) {     return max(max(a, b), c);   }   long long max4(long long a, long long b, long long c, long long d) {     return max(max(a, b), max(c, d));   }   long long min3(long long a, long long b, long long c) {     return min(min(a, b), c);   }   long long min4(long long a, long long b, long long c, long long d) {     return min(min(a, b), min(c, d));   }   long long po(long long x, long long n, long long mod = 1000000007) {     if (n == 0) {       return 1;     }     long long m = po(x, n / 2, mod);     m *= m;     m %= mod;     if (n % 2) {       m *= x;       m %= mod;     }     return m;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     clock_t startTime = clock();     cout << fixed << setprecision(12);     long long n;     cin >> n;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     set<long long> ans, s;     for (long long i = 0; i < n; i++) {       set<long long> temp;       temp.insert(v[i]);       auto it = s.begin();       while (it != s.end()) {         temp.insert(*it | v[i]);         it++;       }       ans.insert(temp.begin(), temp.end());       s = temp;     }     cout << ans.size() <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool sortcol(const vector<int>& v1, const vector<int>& v2) {     return v1[0] < v2[0];   }   int main() {     int n;     cin >> n;     vector<vector<long long> > yr;     long long max = 0, count = 0, year = 0;     for (int a = 0; a < n; a++) {       long long x, y;       cin >> x >> y;       yr.push_back({x, 1});       yr.push_back({y, -1});     }     sort(yr.begin(), yr.end());     for (int a = 0; a < 2 * n; a++) {       count += yr[a][1];       if (yr[a][1] == 1 && count > max) {         max = count;         year = yr[a][0];       }     }     cout << year <<     << max << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[100010];   int tot[200010];   int dis[200010];   int main() {     queue<int> q;     scanf( %d%d , &n, &k);     for (int i = 0; i <= 4000; ++i) dis[i] = 1e9;     for (int i = 1; i <= k; ++i) {       scanf( %d , &a[i]);       a[i] -= n;       ++tot[a[i] + 2000];       if (dis[tot[a[i] + 2000]] == 1e9) q.push(a[i]);       dis[a[i] + 2000] = 1;     }     while (!q.empty()) {       int now = q.front();       q.pop();       for (int i = -2000; i <= 2000; ++i) {         if (dis[i + 2000] == 1 && dis[i + now + 2000] == 1e9) {           dis[i + now + 2000] = dis[now + 2000] + 1;           q.push(i + now);         }       }     }     if (dis[2000] == 1e9) dis[2000] = -1;     printf( %d n , dis[2000]);   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 2 * acos(0);   int rev(int num, int lg_n) {     int res = 0;     for (int i = 0; i < lg_n; ++i)       if (num & (1 << i)) res |= 1 << (lg_n - 1 - i);     return res;   }   void fft(vector<complex<double>>& a, bool invert) {     int n = (int)a.size();     int lg_n = 0;     while ((1 << lg_n) < n) ++lg_n;     for (int i = 0; i < n; ++i)       if (i < rev(i, lg_n)) swap(a[i], a[rev(i, lg_n)]);     for (int len = 2; len <= n; len <<= 1) {       double ang = 2 * PI / len * (invert ? -1 : 1);       complex<double> wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         complex<double> w(1);         for (int j = 0; j < len / 2; ++j) {           complex<double> u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   vector<int> mult(vector<int> a, vector<int> b) {     int logn = 0;     while ((1 << logn) < max(a.size(), b.size())) logn++;     while (a.size() < (1 << logn)) a.push_back(0);     while (b.size() < (1 << logn)) b.push_back(0);     vector<complex<double>> A((1 << logn)), B((1 << logn));     for (int i = 0; i < (1 << logn); ++i) {       A[i] = a[i];       B[i] = b[i];     }     fft(A, 0);     fft(B, 0);     for (int i = 0; i < (1 << logn); ++i) {       A[i] *= B[i];     }     fft(A, 1);     vector<int> ans((1 << logn));     for (int i = 0; i < (1 << logn); ++i) {       ans[i] = (int)(A[i].real() + 0.5);     }     return ans;   }   void dfs(int v, vector<int>& used, vector<vector<int>>& g) {     used[v] = 1;     for (auto u : g[v]) {       if (!used[u]) {         dfs(u, used, g);       }     }   }   void solve() {     string s, t;     cin >> s >> t;     int n = s.size(), m = t.size();     int N =  f  -  a  + 1;     vector<vector<vector<int>>> G(n - m + 1, vector<vector<int>>(N));     for (char c1 =  a ; c1 <=  f ; ++c1) {       for (int c2 =  a ; c2 <=  f ; ++c2) {         vector<int> a(n), b(m);         for (int i = 0; i < n; ++i) {           a[i] = (c1 == s[i]);         }         for (int j = 0; j < m; ++j) {           b[j] = (c2 == t[j]);         }         reverse(b.begin(), b.end());         vector<int> res = mult(a, b);         for (int k = m - 1; k < m - 1 + n - m + 1; ++k) {           if (res[k]) {             G[k - m + 1][c1 -  a ].push_back(c2 -  a );             G[k - m + 1][c2 -  a ].push_back(c1 -  a );           }         }       }     }     for (int p = 0; p < n - m + 1; ++p) {       vector<int> used(N);       int comp = 0;       for (int i = 0; i < N; ++i) {         if (!used[i]) {           dfs(i, used, G[p]);           comp++;         }       }       cout << N - comp <<    ;     }   }   int32_t main() {     std::ios_base::sync_with_stdio(0);     std::cin.tie(0);     std::cout.tie(0);     int tt = 1;     while (tt--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2;   int ar[200001];   int n;   int n2;   bool possible(int check) {     int posi[200001] = {0};     for (int i = 0; i < check + 1; i++) {       posi[ar[i]]++;     }     int start1 = 0;     int start2 = 0;     while (start1 < n && start2 < n2) {       if (posi[start1]) {         start1++;         continue;       }       if (s1[start1] == s2[start2]) {         start1++;         start2++;       } else         start1++;     }     if (start2 == n2) {       return true;     }     return false;   }   int main() {     cin >> s1 >> s2;     n = s1.length();     n2 = s2.length();     for (int i = 0; i < n; i++) {       scanf( %d , &ar[i]);       ar[i]--;     }     int start = 0;     int end = n;     int ans = -1;     while (start < end) {       int mid = (start + end) / 2;       if (possible(mid)) {         ans = mid;         start = mid + 1;       } else {         end = mid;       }     }     cout << ans + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void fmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void fmin(T &a, T b) {     if (a > b) a = b;   }   const int N = 1e5 * 3 + 10;   int a[N][3], c[N], n, m, w[N];   queue<int> Q;   int main() {     cin >> n >> m;     for (int i = (int)1; i <= (int)n; i++) w[i] = -1;     for (int i = 0; i < (int)m; i++) {       int x, y;       cin >> x >> y;       a[x][c[x]++] = y;       a[y][c[y]++] = x;     }     for (int z = (int)1; z <= (int)n; z++)       if (-1 == w[z]) {         Q.push(z);         int cnt = 0;         while (!Q.empty()) {           cnt++;           if (cnt > n * 20) {             cout << -1 << endl;             return 0;           }           int i = Q.front();           Q.pop();           int t[2] = {0, 0};           for (int j = 0; j < (int)c[i]; j++)             if (-1 != w[a[i][j]]) t[w[a[i][j]]]++;           if (w[i] == (t[0] > t[1])) continue;           w[i] = (t[0] > t[1]);           for (int j = 0; j < (int)c[i]; j++) Q.push(a[i][j]);         }       }     for (int i = (int)1; i <= (int)n; i++) cout << w[i];     cout << endl;   }
#include <iostream>   #include <vector>   #include  <numeric>   #include<cstdlib>   #include <algorithm>    // std::random_shuffle   #define MODD 998244353   #define ll long long   using namespace std;      ll modpow(ll x, ll y) {       ll xs = x;       ll answer = 1;       while(y) {           if (y&1) {               answer = (answer * xs) % MODD;           }           y >>= 1;           xs = (xs * xs) % MODD ;       }       return answer;   }         ll D[22][55555];      char buf[58000000];      int pos;   ll readint() {       while(buf[pos]< 0  || buf[pos]> 9 )           pos++;       ll m=0;       while(buf[pos]>= 0  && buf[pos]<= 9 ) {           m=m*10+buf[pos]- 0 ;           pos++;       }       return m;   }         int main() {       fread(buf, 1, 51000100, stdin);       pos=0;       int n,m;       n=readint();       m=readint();       for(int i=1;i<=n;i++) {           for(int j=1;j<=m;j++) {               D[i][j]=readint();           }       }          ll fact = 1;       for(ll i=1;i<=n;i++) {           fact = (fact*i)%MODD;       }          ll factinv = modpow(fact, MODD-2);          ll counts[22];       ll ans = 0;       for(int j=1;j<=m;j++) {           for(int step=1;step<=n;step++) {               // number of cities with distance >= step+1               counts[step]=0;               for(int i=1;i<=n;i++) {                   counts[step]+=(D[i][j]>=step+1);               }           }           counts[n+1]=0;           ll prod = 1;           for(int step=n;step>=1;step--) {               prod = (prod * (counts[step]-(n-step)))%MODD;           }           prod = (prod * factinv)%MODD;              ll prob_selected = (1-prod+MODD)%MODD;           ans += prob_selected;           ans %= MODD;       }          ans = (ans + MODD)%MODD;          cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, sum = 1;     cin >> n >> a >> b;     if (n == 1) {       puts( 1 );       return 0;     }     if (b == 0 && a == n - 1) {       puts( -1 );       return 0;     }     bool fl = (b == 0);     int now = 1;     vector<long long> ans(n, 1);     while (now < ans.size() && b > 0) {       ans[now] = sum + 1;       sum += ans[now];       b--;       now++;     }     while (now < ans.size() && a > 0) {       ans[now] = ans[now - 1] + 1;       a--;       now++;     }     if (fl && ans.size() >= 2) {       sum = ans.back();       ans.insert(ans.begin(), sum);       ans.pop_back();     }     for (int i = 0; i < ans.size(); i++) {       if (ans[i] > 50000) {         puts( -1 );         return 0;       }     }     for (int i = 0; i < ans.size(); i++) {       printf( %lld  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long nega = 1;     while (!isdigit(ch)) {       if (ch ==  - ) nega = -1;       ch = getchar();     }     long long ans = 0;     while (isdigit(ch)) {       ans = ans * 10 + ch - 48;       ch = getchar();     }     if (nega == -1) return -ans;     return ans;   }   inline long long min(long long x, long long y, long long z) {     return min(x, min(y, z));   }   inline long long max(long long x, long long y, long long z) {     return max(x, max(y, z));   }   inline long long add(long long x, long long y) {     return x + y >= 998244353 ? x + y - 998244353 : x + y;   }   inline long long add(long long x, long long y, long long z) {     return add(add(x, y), z);   }   inline long long sub(long long x, long long y) {     return x - y < 0 ? x - y + 998244353 : x - y;   }   inline long long mul(long long x, long long y) {     return 1LL * x * y % 998244353;   }   inline long long mul(long long x, long long y, long long z) {     return mul(mul(x, y), z);   }   signed main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long ans = 0;     for (long long i = c; i <= d; i++) {       long long m = i - b + 1;       if (m >= a && c - b + 1 > 0) {         long long l = max(a, i - c);         long long d = c - i + l, e = c - i + min(b, m);         if (e >= d) ans += (e + d) * (e - d + 1) / 2;       }       long long L = b - max(m, a - 1);       if (c - b + 1 >= 0 && b > m) ans += L * (c - b + 1);     }     cout << ans << endl;     return 0;   }