malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int a, b, c, l;   long long Ans;   int main() {     cin >> a >> b >> c >> l;     for (int i = 0; i <= l; i++) {       long long lim = (a + b + c + i - 1) / 2;       if (a <= lim && b <= lim && c <= lim) {         Ans += (long long)(i + 2) * (i + 1) / 2;         if (a + i > lim) {           Ans -= (long long)(i + a - lim + 1) * (i + a - lim) / 2;         }         if (b + i > lim) {           Ans -= (long long)(i + b - lim + 1) * (i + b - lim) / 2;         }         if (c + i > lim) {           Ans -= (long long)(i + c - lim + 1) * (i + c - lim) / 2;         }       }     }     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char n[1000100];   char b[1000100];   int main() {     long long result, last, i, B, c, BB[10];     int re, C;     while (scanf( %s %s %d , b, n, &C) != EOF) {       c = C;       B = 0;       for (i = 0; b[i]; i++) B = (B * 10 + b[i] -  0 ) % c;       if (B == 0) B = c;       BB[0] = 1;       for (i = 1; i < 10; i++) BB[i] = (BB[i - 1] * B) % c;       for (i = strlen(n) - 1; i >= 0; i--)         if (n[i] !=  0 ) break;       n[i]--;       for (i++; n[i]; i++) n[i] =  9 ;       result = 1;       for (i = 0; n[i]; i++) {         last = result;         result = (result * result) % c;         result = (result * result) % c;         result = (result * result) % c;         result = (result * last) % c;         result = (result * last) % c;         result = (result * BB[n[i] -  0 ]) % c;       }       result = (result * (B - 1)) % c;       if (result == 0) result = c;       re = result;       printf( %d n , re);     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int N = 100005;   int i, n, k, x, y, lvl[N];   vector<int> g[N];   queue<int> q;   int main() {     ios_base::sync_with_stdio(0);     memset(lvl, -1, sizeof(lvl));     cin >> n >> k;     for (i = 1; i < n; ++i) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (i = 1; i <= n; ++i)       if (g[i].size() == 1) q.push(i), lvl[i] = 0;     for (; !q.empty(); q.pop()) {       x = q.front();       if (lvl[x] == k) continue;       vector<int> now;       for (int to : g[x])         if (lvl[to] == -1 || lvl[to] == lvl[x] + 1) now.push_back(to);       if (now.size() > 1) return cout <<  No n , 0;       if (!now.size()) return cout <<  No n , 0;       if (g[now[0]].size() < 4 - (lvl[x] + 1 == k)) return cout <<  No n , 0;       if (lvl[now[0]] == -1) lvl[now[0]] = lvl[x] + 1, q.push(now[0]);     }     int cnt = 0;     for (i = 1; i <= n; ++i) {       if (lvl[i] > k) return cout <<  No n , 0;       if (lvl[i] == k) ++cnt;       if (cnt > 1) return cout <<  No n , 0;     }     cout << (!cnt ?  No  :  Yes ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double ans = 0.0F;   int n, d, m[101] = {0}, r[101] = {0};   int tmp = 0;   int main(int argc, char** argv, char** env) {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> m[i];     }     for (int i = 1; i <= n; ++i) {       cin >> r[i];     }     for (int i = 0; i < (int)1e6; ++i) {       for (int j = 1; j <= n; ++j) {         if (i % m[j] == r[j]) {           tmp++;           break;         }       }     }     ans = tmp * 1.0F / 1e6;     cout << fixed << setprecision(6) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x[200001], y[200001], tag[200001], fi[200001 << 1], nt[200001 << 1],       go[200001 << 1], root;   int cnt, top, low[200001], dfn[200001], id[200001], deg[200001], st[200001],       ans, cntx, sum, maxx;   void add(int u, int v) {     nt[++cnt] = fi[u];     fi[u] = cnt;     go[cnt] = v;   }   void tarjan(int u, int fa) {     dfn[u] = ++cnt;     low[u] = dfn[u];     st[++top] = u;     int t = 0;     for (int i = fi[u]; i; i = nt[i]) {       int v = go[i];       if (v == fa && !t) {         t++;         continue;       }       if (dfn[v]) {         low[u] = min(low[u], low[v]);         continue;       }       tarjan(v, u);       low[u] = min(low[u], low[v]);     }     if (low[u] == dfn[u]) {       int y;       while (y = st[top--]) {         tag[y] = u;         if (y == u) break;       }     }   }   void dfs1(int u, int dep) {     dfn[u] = 1;     for (int i = fi[u]; i; i = nt[i]) {       int v = go[i];       if (dfn[v]) continue;       dfs1(v, dep + 1);     }     if (dep > maxx) root = u, maxx = dep;   }   void dfs2(int u, int dep, int fa) {     for (int i = fi[u]; i; i = nt[i]) {       int v = go[i];       if (v == fa) continue;       dfs2(v, dep + 1, u);     }     if (dep >= maxx) maxx = dep;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x[i], &y[i]);       add(x[i], y[i]);       add(y[i], x[i]);     }     for (int i = 1; i <= n; i++) {       top = 0;       cnt = 0;       if (!dfn[i]) tarjan(i, 0);     }     memset(fi, 0, sizeof fi);     cnt = 0;     top = 0;     for (int i = 1; i <= n; i++)       if (tag[i] == i) id[i] = ++top;     for (int i = 1; i <= m; i++) {       if (tag[x[i]] != tag[y[i]]) {         add(id[tag[x[i]]], id[tag[y[i]]]), add(id[tag[y[i]]], id[tag[x[i]]]);         deg[id[tag[x[i]]]]++;         deg[id[tag[y[i]]]]++;       }     }     for (int i = 1; i <= top; i++) {       if (deg[i] == 1) ans++;     }     memset(dfn, 0, sizeof dfn);     for (int i = 1; i <= top; i++) {       if (!dfn[i] && deg[i] == 0) sum++, ans++;       if (!dfn[i] && deg[i] != 0) {         sum++;         dfs1(i, 1), dfs2(root, 1, 0);         root = 0;         ans += maxx - 2;         maxx = 0;       }     }     sum--;     ans = sum + n - ans;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool cmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool cmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const int MaxN = 205;   unsigned int n, d, M, c[MaxN][MaxN], f[MaxN][MaxN], g[MaxN];   int main() {     cin >> n >> d >> M;     c[0][0] = 1;     for (int i = 1; i <= n; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;     }     f[1][0] = 1;     for (int i = 2; i <= n; i++) {       for (int k = 0; k < d; k++) (g[i - 1] += f[i - 1][k]) %= M;       for (int j = 1; j < i; j++)         for (int k = 0; k < d; k++)           f[i][k + 1] = (f[i][k + 1] +                          (long long)f[i - j][k] * g[j] % M * c[i - 2][j - 1]) %                         M;     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j <= d; j++)         for (int k = 0; j + k <= d; k++) {           if (k == 1) continue;           ans = (ans + (long long)f[i + 1][j] * f[n - i][k]) % M;         }     ans = (long long)ans * 2 * n * (n - 1) % M;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, i, j;     cin >> n >> a >> b;     for (i = 0; i <= 10000000; i++) {       if (n - a * i >= 0) {         if ((n - a * i) % b == 0) {           cout <<  YES                 <<   n ;           cout << i <<     << (n - a * i) / b;           return 0;         }       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   int N, M, K;   int A[MAXN];   long long P, H;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> P;       A[i] = A[i - 1] + __builtin_popcountll(P);       M = 0;       for (int j = i - 1; j >= 0; j--) {         if (A[i] - A[j] >= 118) {           break;         }         M = max(M, A[j + 1] - A[j]);         if ((A[i] - A[j]) & 1) {           continue;         }         if (A[i] - A[j] < 2 * M) {           H--;         }       }       if (A[i] & 1) {         H += K;         K++;       } else {         H += i - K;       }     }     cout << H <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }   long long n, k;   string s;   long long dp[1005][2005];   int zero = 1002;   int main(void) {     ios::sync_with_stdio(0);     cin >> n >> k >> s;     s =  #  + s;     for (long long(i) = (0); (i) <= (n); (i)++)       for (long long(j) = (-k); (j) <= (k); (j)++) dp[i][zero + j] = -1e18;     dp[0][zero + 0] = 0;     for (long long(i) = (0); (i) <= (n - 1); (i)++) {       for (long long(j) = (-k); (j) <= (k); (j)++) {         for (long long(l) = (-1); (l) <= (1); (l)++) {           if (dp[i][zero + j] < -1e18 / 2) continue;           if (s[i + 1] !=  ? ) {             if (s[i + 1] !=  W  && l == 1) continue;             if (s[i + 1] !=  L  && l == -1) continue;             if (s[i + 1] !=  D  && l == 0) continue;           }           long long nj = j + l;           if (abs(nj) > k) continue;           if (i + 1 != n && abs(nj) == k) continue;           dp[i + 1][zero + nj] = j;         }       }     }     long long p = -1e18;     if (dp[n][zero + k] > -1e18 / 2) p = k;     if (dp[n][zero - k] > -1e18 / 2) p = -k;     if (p < -1e18 / 2) {       cout <<  NO  << endl;       return 0;     }     for (int i = n; i >= 1; i--) {       if (dp[i][zero + p] == p) s[i] =  D ;       if (dp[i][zero + p] < p) s[i] =  W ;       if (dp[i][zero + p] > p) s[i] =  L ;       p = dp[i][zero + p];     }     cout << s.substr(1) << endl;     return 0;   }
#include <bits/stdc++.h>   const long long pinf = ((long long)2e18);   const long long ninf = ((long long)-2e18);   const long long mod = 1000000007;   using namespace std;   long long power(long long x, long long n, long long M) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return power((x * x) % M, n / 2, M);     else       return (x * power((x * x) % M, (n - 1) / 2, M)) % M;   }   bool vowel(char c) {     return (c ==  a  or c ==  e  or c ==  i  or c ==  o  or c ==  u  or             c ==  A  or c ==  E  or c ==  I  or c ==  U  or c ==  O );   }   int32_t main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n), b(n);       map<long long, long long> make_pair;       for (long long i = 0; i < n; i++) {         cin >> a[i];         make_pair[a[i]]++;         b[i] = a[i];       }       sort(b.begin(), b.end());       long long p = 0;       long long ans = 0;       long long l = 0, r = n - 1;       while (l < r) {         if (make_pair[b[p]]) {           if (a[l] == b[p]) {             make_pair[a[l]]--;             p++;             l++;           } else if (a[r] == b[p]) {             make_pair[a[r]]--;             r--;             p++;           } else {             make_pair[a[l]]--;             l++;             ans = l;           }         } else {           p++;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x0FFFFFFF;   const long long INFLL = 0x0FFFFFFFFFFFFFFFll;   const int MAXN = 300005;   int n, m, x, y;   vector<int> g[MAXN];   int ans[MAXN];   int getenemies(int i) {     int c = 0;     for (size_t j = 0; j < g[i].size(); j++)       if (ans[g[i][j]] == ans[i]) c++;     return c;   }   void solve(int p) {     if (getenemies(p) > 1) {       ans[p] = 1 - ans[p];       for (size_t j = 0; j < g[p].size(); j++) solve(g[p][j]);     }   }   int main() {     cin >> n >> m;     while (m--) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= n; i++) solve(i);     for (int i = 1; i <= n; i++) cout << ans[i];     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 10105;   int n, b, q, st, ed;   int First[maxn], cnt, dis[maxn];   struct edge {     int to, Next, flow, c;   } Tree[maxn * 100];   void init() {     cnt = 0;     memset(First, -1, sizeof(First));   }   void addedge(int from, int to, int flow) {     Tree[cnt].to = to;     Tree[cnt].Next = First[from];     Tree[cnt].flow = flow;     First[from] = cnt++;     Tree[cnt].to = from;     Tree[cnt].Next = First[to];     Tree[cnt].flow = 0;     First[to] = cnt++;   }   bool bfs(int st, int ed) {     memset(dis, 0, sizeof(dis));     queue<int> Q;     dis[st] = 1;     Q.push(st);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = First[u]; i != -1; i = Tree[i].Next) {         int v = Tree[i].to;         int flow = Tree[i].flow;         if (flow && !dis[v]) {           dis[v] = dis[u] + 1;           if (v == ed) return true;           Q.push(v);         }       }     }     return false;   }   int dfs(int u, int minf) {     if (u == ed) {       return minf;     }     if (minf == 0) return minf;     int f = 0;     for (int i = First[u]; i != -1; i = Tree[i].Next) {       int v = Tree[i].to;       if (Tree[i].flow && dis[v] == dis[u] + 1) {         int tmp = dfs(v, min(Tree[i].flow, minf));         Tree[i].flow -= tmp;         Tree[i ^ 1].flow += tmp;         f += tmp;         minf -= tmp;         if (minf == 0) return f;       }     }     return f;   }   int dinic(int st, int ed) {     int res = 0;     while (bfs(st, ed)) res += dfs(st, INF);     return res;   }   struct node {     int up, num;     bool operator<(const node& A) const {       if (A.up != up) return A.up > up;       return A.num > num;     }   } ax[10005];   int sum[10];   int main() {     init();     scanf( %d%d%d , &n, &b, &q);     st = 0, ed = q + 5 + 10;     for (int i = 1; i <= q; i++) scanf( %d%d , &ax[i].up, &ax[i].num);     sort(ax + 1, ax + 1 + q);     ax[q + 1].up = b, ax[q + 1].num = n;     for (int i = 1; i <= q + 1; i++) {       int nowv = ax[i].up - ax[i - 1].up;       int nowb = ax[i].num - ax[i - 1].num;       if (ax[i].num > n || nowb > nowv || nowb < 0) {         puts( unfair );         return 0;       }       for (int j = ax[i - 1].up + 1; j <= ax[i].up; j++) {         sum[j % 5]++;       }       for (int j = 0; j < 5; j++) addedge(i, q + j + 2, sum[j]);       addedge(st, i, nowb);       memset(sum, 0, sizeof(sum));     }     for (int i = 1; i <= 5; i++) addedge(q + i + 1, ed, n / 5);     int max1 = dinic(st, ed);     if (max1 == n)       puts( fair );     else       puts( unfair );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[10000001];   int main() {     long long d = 1;     arr[0] = 0;     for (int i = 1; i < 10000001; i++) {       arr[i] = arr[i - 1] + d;       d += 2;     }     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n, k;       cin >> n >> k;       if (n % 2 == 0 && k % 2 != 0) {         cout <<  NO  << endl;         continue;       }       if (n % 2 != 0 && k % 2 == 0) {         cout <<  NO  << endl;         continue;       }       long long x = arr[k];       if (n >= x)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long i;     long long n;     cin >> n;     cin >> s;     long long arr[27];     for (i = 0; i < 26; i++) {       arr[i] = 0;     }     for (i = 0; i < s.length(); i++) {       arr[s[i] -  a ]++;     }     long long cnt = 0;     if (n == 1) {       cout <<  YES ;       return 0;     }     for (i = 0; i < 26; i++) {       if (arr[i] > 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long dp[511][511];   long long tol[511];   int main() {     int n, k, i, j, p;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; ++i) dp[0][i] = 1;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         for (p = max(i - j, 0); p <= i - 1; ++p) {           dp[i][j] = dp[i][j] + dp[p][j];           dp[i][j] %= mod;         }       }     }     for (i = 1; i <= n; ++i) {       tol[i] = dp[n][i] - dp[n][i - 1];     }     long long ans = 0;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         if (i * j < k) {           ans += tol[i] * tol[j];           ans %= mod;         }       }     }     ans *= 2;     cout << (ans % mod + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   int main(int argc, const char* argv[]) {     int n;     std::cin >> n;     int step = 0;     int prev = 0;     int first = 0, second = 0;     bool prog = true;     int x = 0;     for (int i = 0; i < n; i++) {       std::cin >> x;       if (i == 0)         first = x;       else if (i == 1) {         second = x;         step = second - first;         prev = x;       } else {         if ((x - prev) != step) prog = false;         prev = x;       }     }     if (prog)       std::cout << x + step;     else       std::cout << x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, W;     cin >> N >> W;     long long lowest = 0, highest = W;     long long current = 0, sum = 0;     while (N--) {       cin >> current;       sum += current;       lowest = max(lowest, -sum);       highest = min(highest, W - sum);     }     cout << max(0ll, highest - lowest + 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class team {    public:     int x, y, z;   };   int search(team *, int, int);   int main() {     int m, n, t;     cin >> n >> m;     int *arr1, *arr2;     arr1 = new int[m];     arr2 = new int[m];     for (int i = 0; i < m; i++) cin >> arr1[i] >> arr2[i];     team *res = new team[n / 3];     for (int i = 0; i < n / 3; i++) {       res[i].x = 0;       res[i].y = 0;       res[i].z = 0;     }     bool *tak = new bool[n + 1];     bool resf = false;     for (int i = 0; i < n + 1; i++) tak[i] = false;     tak[0] = true;     for (int i = 0; i < m; i++) {       if ((!tak[arr1[i]]) && (!tak[arr2[i]])) {         bool f = true;         for (int j = 0; j < n / 3; j++) {           if (res[j].x == 0) {             res[j].x = arr1[i];             res[j].y = arr2[i];             tak[arr1[i]] = true;             tak[arr2[i]] = true;             f = false;             break;           }         }         if (f) {           resf = true;           goto End;         }       } else if (tak[arr1[i]] && tak[arr2[i]]) {         if (search(res, arr1[i], n / 3) == search(res, arr2[i], n / 3))           continue;         else {           resf = true;           goto End;         }       } else if (tak[arr1[i]]) {         t = search(res, arr1[i], n / 3);         if (res[t].z == 0) {           res[t].z = arr2[i];           tak[arr2[i]] = true;         } else {           resf = true;           goto End;         }       } else if (tak[arr2[i]]) {         t = search(res, arr2[i], n / 3);         if (res[t].z == 0) {           res[t].z = arr1[i];           tak[arr1[i]] = true;         } else {           resf = true;           goto End;         }       }     }     for (int i = 0; i < n / 3; i++) {       if (res[i].x == 0) {         for (int j = 1; j < n + 1; j++)           if (!tak[j]) {             res[i].x = j;             tak[j] = true;             break;           }       }       if (res[i].y == 0) {         for (int j = 1; j < n + 1; j++)           if (!tak[j]) {             res[i].y = j;             tak[j] = true;             break;           }       }       if (res[i].z == 0) {         for (int j = 1; j < n + 1; j++)           if (!tak[j]) {             res[i].z = j;             tak[j] = true;             break;           }       }     }   End:     if (resf)       cout << -1;     else {       for (int i = 0; i < n / 3; i++)         cout << res[i].x <<     << res[i].y <<     << res[i].z << endl;     }     return 0;   }   int search(team *input, int val, int size) {     for (int i = 0; i < size; i++) {       if (input[i].x == val) return i;       if (input[i].y == val) return i;       if (input[i].z == val) return i;     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n, k;     cin >> n >> k;     vector<long long> a(n);     vector<long long> b(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     long long cntZero = 0;     vector<long long> cnt(k);     for (long long i = 0; i < n; i++) {       cnt[a[i]]++;     }     for (long long i = 0; i < k; i++) {       if (cnt[i] == 0) cntZero++;     }     set<pair<long long, long long>> s;     for (long long i = 0; i < n; i++) {       s.insert({b[i], i});     }     long long ans = 0;     while (cntZero) {       auto pp = *s.begin();       s.erase(s.begin());       if (cnt[a[pp.second]] > 1) {         cntZero--;         cnt[a[pp.second]]--;         ans += pp.first;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   char str[30];   char a[3][30];   int main(void) {     int i, j, k, p1, p2;     scanf( %s , str + 1);     for (p1 = 1; p1 <= 27; p1++) {       for (p2 = p1 + 1; p2 <= 27; p2++)         if (str[p1] == str[p2]) break;       if (p2 <= 27) break;     }     if (p1 + 1 == p2) {       cout <<  Impossible ;       return 0;     }     memset(a, 0, sizeof(a));     if ((p2 - p1 - 1) % 2) {       k = 13 - (p2 - p1 - 1) / 2;       a[1][k] = str[p1];       i = p1 + 1;       for (j = k; j <= 13; j++) {         a[2][j] = str[i];         i = i % 27 + 1;       }       for (j = 13; j >= 1; j--) {         a[1][j] = str[i];         i = i % 27 + 1;       }       for (j = 1; j < k; j++) {         a[2][j] = str[i];         i = i % 27 + 1;       }     } else {       k = 13 - (p2 - p1 - 1) / 2;       a[1][k] = str[p1];       i = p1 + 1;       for (j = k + 1; j <= 13; j++) {         a[2][j] = str[i];         i = i % 27 + 1;       }       for (j = 13; j >= 1; j--) {         a[1][j] = str[i];         i = i % 27 + 1;       }       for (j = 1; j <= k; j++) {         a[2][j] = str[i];         i = i % 27 + 1;       }     }     cout << a[1] + 1 << endl << a[2] + 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l1, r1, l2, r2, k, ans;   int main() {     cin >> l1 >> r1 >> l2 >> r2 >> k;     if (r1 < l2 || r2 < l1) {       ans = 0;     } else {       long long r = min(r1, r2), l = max(l1, l2);       ans = r - l + 1;       if (k >= l && k <= r) ans--;     }     cout << ans << endl;     return 0;   }