malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int t, n, p, c;   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &p), c = 2 * n + p;       for (int i = 1; i <= n; ++i)         for (int j = i + 1; j <= n; ++j)           if (c) printf( %d %d n , i, j), --c;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[500100];   long long f[500100][2];   int n, k;   void dfs(int u, int fa) {     vector<long long> d;     d.clear();     f[u][0] = f[u][1] = 0;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i].first, w = g[u][i].second;       if (v == fa) continue;       dfs(v, u);       f[u][0] += f[v][1];       f[u][1] += f[v][1];       d.push_back(-(w + f[v][0] - f[v][1]));     }     sort(d.begin(), d.end());     for (int i = 0; i < d.size() && i < k; i++) {       long long D = -d[i];       if (D <= 0) break;       if (i < k - 1) f[u][0] += D;       f[u][1] += D;     }   }   void ae(int x, int y, int z) { g[x].push_back(make_pair(y, z)); }   void solve() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) g[i].clear();     int x, y, z;     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &x, &y, &z);       ae(x, y, z);       ae(y, x, z);     }     dfs(1, 0);     printf( %lld n , f[1][1]);   }   int main() {     int tc;     scanf( %d , &tc);     while (tc--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int a[MAXN], b[MAXN], f[260], n, k;   int main(void) {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     memset(f, -1, sizeof f);     for (int i = 1; i <= n; ++i) {       if (f[a[i]] == -1) {         int low = -1;         for (int j = a[i]; j >= a[i] - k + 1 && j >= 0; --j) {           if (f[j] != -1) {             if (f[j] >= a[i] - k + 1) low = f[j];             break;           }           low = j;         }         for (int j = low; j <= a[i]; ++j) {           f[j] = low;         }       }       b[i] = f[a[i]];     }     for (int i = 1; i <= n; ++i) {       cout << b[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100005];   int n, a[100005], ans[100005];   inline bool find() {     int i = 1, j = n;     while (i <= j) {       if (a[i] == a[j]) {         i++;         j--;       } else if (a[i] == a[j] + 10) {         a[j - 1]--;         a[j] += 10;       } else if ((a[i] == a[j] + 1) || (a[i] == a[j] + 11)) {         a[i]--;         a[i + 1] += 10;       } else         return false;     }     if ((i - 1 == j + 1) &&         ((a[i - 1] > 18) || (a[i - 1] < 0) || (a[i - 1] % 2 == 1)))       return false;     if (a[1] == 0) return false;     i--;     j++;     while (i) {       if ((a[i] > 18) || (a[i] < 0)) return false;       ans[i] = (a[i] + 1) / 2;       ans[j] = a[i] - ans[i];       i--;       j++;     }     for (int i = 1; i <= n; i++) printf( %d , ans[i]);     printf(  n );     return true;   }   int main() {     scanf( %s , s + 1);     for (int i = 1; i <= strlen(s + 1); i++) a[i] = s[i] -  0 ;     n = strlen(s + 1);     if (find()) return 0;     if ((s[1] !=  1 ) || (n == 1)) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= n; i++) a[i - 1] = s[i] -  0 ;     a[1] += 10;     n--;     if (find()) return 0;     printf( 0 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ben[11];   int n, k;   int mem[505][505 * 11];   int arr[505 * 505];   int freqFav[100005];   int freqCards[100005];   int solve(int num, int rem) {     if (rem == 0 || num == 0) return 0;     int &ret = mem[num][rem];     if (~ret) return ret;     for (int i = 0; i < min(k, rem); i++) {       ret = max(ret, ben[i] + solve(num - 1, rem - i - 1));     }     return ret;   }   int main() {     memset(mem, -1, sizeof(mem));     scanf( %d %d , &n, &k);     for (int i = 0; i < k * n; i++) {       scanf( %d , arr + i);       freqCards[arr[i]]++;     }     for (int i = 0; i < n; i++) {       int fav;       scanf( %d , &fav);       freqFav[fav]++;     }     for (int i = 0; i < k; i++) {       scanf( %d , ben + i);     }     int res = 0;     for (int i = 0; i < 100005; i++) {       res += solve(freqFav[i], freqCards[i]);     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 4e6 + 50;   int n, m;   string str;   int s[sz], e[sz], four[sz], seven[sz], non_dec[sz], non_inc[sz];   vector<bool> lazy(sz, 0);   void calculate(int node) {     int lc = node * 2;     int rc = lc + 1;     int f1 = four[lc], s1 = seven[lc], nd1 = non_dec[lc], ni1 = non_inc[lc];     int f2 = four[rc], s2 = seven[rc], nd2 = non_dec[rc], ni2 = non_inc[rc];     if (lazy[lc]) {       swap(f1, s1);       swap(nd1, ni1);     }     if (lazy[rc]) {       swap(f2, s2);       swap(nd2, ni2);     }     four[node] = f1 + f2;     seven[node] = s1 + s2;     non_dec[node] = max(f1 + nd2, nd1 + s2);     non_inc[node] = max(s1 + ni2, ni1 + f2);   }   void modify(int node) {     int lc = node * 2;     int rc = lc + 1;     four[node] = four[lc] + four[rc];     seven[node] = seven[lc] + seven[rc];     non_dec[node] = max(four[lc] + non_dec[rc], non_dec[lc] + seven[rc]);     non_inc[node] = max(seven[lc] + non_inc[rc], non_inc[lc] + four[rc]);   }   void lazyPropagation(int node) {     if (lazy[node]) {       lazy[2 * node] = !lazy[2 * node];       lazy[2 * node + 1] = !lazy[2 * node + 1];     }     lazy[node] = 0;   }   void build(int node, int l, int r) {     s[node] = l;     e[node] = r;     if (l == r) {       if (str[l] ==  4 ) {         four[node] = 1;         seven[node] = 0;         non_dec[node] = 1;         non_inc[node] = 1;       } else {         four[node] = 0;         seven[node] = 1;         non_dec[node] = 1;         non_inc[node] = 1;       }       return;     }     int mid = (l + r) / 2;     build(2 * node, l, mid);     build(2 * node + 1, mid + 1, r);     modify(node);   }   void update(int node, int l, int r) {     if (s[node] > r || e[node] < l) return;     if (l <= s[node] && e[node] <= r) {       lazy[node] = !lazy[node];       return;     }     lazyPropagation(node);     update(2 * node, l, r);     update(2 * node + 1, l, r);     calculate(node);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string tt;     int x, y;     cin >> n >> m;     cin >> str;     str =  0  + str;     build(1, 1, n);     while (m--) {       cin >> tt;       if (tt[0] ==  c ) {         if (!lazy[1])           cout << non_dec[1] <<   n ;         else           cout << non_inc[1] <<   n ;       } else {         cin >> x >> y;         update(1, x, y);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int rnd(int l, int r) { return l + rng() % (r - l + 1); }   const int N = 200010;   int n;   long long ret;   int a[N], lz[N], b[N];   int f[N][25];   int que(int i, int j) {     int t = lz[j - i + 1];     return max(f[i][t], f[j - (1 << t) + 1][t]);   }   void dnc(int l, int r) {     if (l >= r) return;     int x = que(l, r);     int p = b[x];     if (p - l < r - p)       for (int i = l, _c = p - 1; i <= _c; ++i)         ret += r >= b[x - a[i]] && b[x - a[i]] > p;     else       for (int i = p + 1, _c = r; i <= _c; ++i)         ret += l <= b[x - a[i]] && b[x - a[i]] < p;     dnc(l, p - 1);     dnc(p + 1, r);   }   int main() {     n = ({       int x = 0;       int c = getchar(), n = 0;       for (; !isdigit(c); c = getchar()) n = (c ==  - );       for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;       n ? -x : x;     });     for (int i = 1, _c = n; i <= _c; ++i)       a[i] = f[i][0] = ({         int x = 0;         int c = getchar(), n = 0;         for (; !isdigit(c); c = getchar()) n = (c ==  - );         for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;         n ? -x : x;       }),       b[a[i]] = i, lz[i] = log2(i);     for (int j = 1, _c = 20; j <= _c; ++j)       for (int i = 1, _c = n; i <= _c; ++i) {         if (i + (1 << j - 1) > n) break;         f[i][j] = max(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);       }     dnc(1, n);     cout << ret;   }
#include <bits/stdc++.h>   using namespace std;   int arr[3010][3010], height[3010][3010];   deque<pair<int, int> > mdq;   void push(int val, int pos) {     while (!mdq.empty() && mdq.back().first > val) mdq.pop_back();     mdq.push_back(make_pair(val, pos));   }   int front(int lim) {     while (!mdq.empty() && mdq.front().second < lim) mdq.pop_front();     return mdq.front().first;   }   void clear() { mdq.clear(); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int row, column, r1, c1;     long long int g0, x, y, z;     cin >> row >> column >> r1 >> c1;     cin >> g0 >> x >> y >> z;     long long int g = g0;     for (int i = 0; i < row; i++) {       for (int j = 0; j < column; j++) {         arr[i][j] = g;         g = (g * x + y) % z;       }     }     for (int i = 0; i < row; i++) {       clear();       for (int j = 0; j < c1; j++) push(arr[i][j], j);       for (int j = 0; j + c1 <= column; j++) {         height[i][j] = front(j);         if (j + c1 < column) push(arr[i][j + c1], j + c1);       }     }     for (int j = 0; j + c1 <= column; j++) {       clear();       for (int i = 0; i < r1; i++) push(height[i][j], i);       for (int i = 0; i + r1 <= row; i++) {         height[i][j] = front(i);         if (i + r1 < row) push(height[i + r1][j], i + r1);       }     }     long long int ans = 0;     for (int i = 0; i + r1 <= row; i++)       for (int j = 0; j + c1 <= column; j++) ans += height[i][j];     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   double ans;   int n, cnt, C;   int head, tail;   int q[3005], d[3005], d2[3005];   bool vis[3005];   vector<int> e[3005];   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < e[x].size(); i++)       if (!vis[e[x][i]]) {         d2[e[x][i]] = d2[x] + 1;         if (!d[e[x][i]]) {           d[e[x][i]] = d[x] + 1;           ans += 1.0 / d[e[x][i]];         } else           ans =               ans + 1.0 / d2[e[x][i]] - 2.0 / (d[e[x][i]] + d2[e[x][i]] + C - 2);         dfs(e[x][i]);       }     vis[x] = 0;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       int u = read(), v = read();       u++;       v++;       e[u].push_back(v);       e[v].push_back(u);       d[u]++;       d[v]++;     }     for (int i = 1; i <= n; i++)       if (d[i] == 1) q[tail++] = i;     while (head != tail) {       int now = q[head];       head++;       for (int i = 0; i < e[now].size(); i++) {         d[e[now][i]]--;         if (d[e[now][i]] == 1) q[tail++] = e[now][i];       }     }     C = n - tail;     for (int i = 1; i <= n; i++) {       memset(d, 0, sizeof(d));       memset(d2, 0, sizeof(d2));       d[i] = d2[i] = 1;       dfs(i);     }     printf( %.10lf n , ans + n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& num) {     bool start = false, neg = false;     char c;     num = 0;     while ((c = getchar()) != EOF) {       if (c ==  - )         start = neg = true;       else if (c >=  0  && c <=  9 ) {         start = true;         num = num * 10 + c -  0 ;       } else if (start)         break;     }     if (neg) num = -num;   }   inline int Q(int x, int y) {     printf( 0 %d %d n , x, y);     fflush(stdout);     scanf( %d , &x);     return x;   }   set<int> c;   void dfs(int l, int r) {     if (l > r) return;     int mid = l + (r - l) / 2;     int d = Q(mid, mid);     if (!d) c.insert(mid), d++;     dfs(l, mid - d);     dfs(mid + d, r);   }   set<int> V, H;   int main() {     int n = 0, m = 0;     int mx = (int)(1e8);     dfs(-mx, mx);     int s = mx;     for (; c.count(s); s--)       ;     for (set<int>::iterator it = c.begin(); it != c.end(); it++) {       int x = (*it);       if (!Q(x, s)) V.insert(x), ++n;       if (!Q(s, x)) H.insert(x), ++m;     }     printf( 1 %d %d n , n, m);     for (set<int>::iterator it = V.begin(); it != V.end(); it++)       printf( %d  , (*it));     putchar(  n );     for (set<int>::iterator it = H.begin(); it != H.end(); it++)       printf( %d  , (*it));     putchar(  n );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000 + 5];   int b[1000000 + 5];   int main() {     ios_base::sync_with_stdio(false);     int i, j, n, k;     queue<pair<int, int> > q;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     for (i = 1; i <= n; i++) {       if (a[i] != b[i]) {         for (j = i + 1; j <= n; j++) {           if (a[i] == b[j]) {             k = j;             break;           }         }         for (j = k; j > i; j--) {           q.push(make_pair(j - 1, j));           int t = b[j];           b[j] = b[j - 1];           b[j - 1] = t;         }       }     }     cout << q.size() << endl;     while (q.empty() != 1) {       cout << q.front().first <<     << q.front().second << endl;       q.pop();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, MSQ = 1010, SQ = 10, inf = 2e9;   pair<pair<int, int>, int> p[maxn];   map<int, vector<int> > mp;   vector<int> vec, vec2;   int n, k, sm[maxn], l[maxn], r[maxn];   long long ans;   void add(int ind, int val) {     while (ind < maxn) {       sm[ind] += val;       ind += (ind & -ind);     }   }   int ask(int ind) {     int ans = 0;     while (ind > 0) {       ans += sm[ind];       ind -= (ind & -ind);     }     return ans;   }   void Add(int id, int val) {     if (val == 1) ans += ask(r[id]) - ask(l[id]);     add(id + 1, val);   }   bool CMP(int a, int b) { return p[a].first.second > p[b].first.second; }   void Add(vector<int>& vec) {     sort(vec.begin(), vec.end(), CMP);     for (int id : vec) Add(id, 1);     for (int id : vec) Add(id, -1);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d%d%d , &p[i].first.first, &p[i].first.second, &p[i].second);       vec.push_back(p[i].second);     }     sort(p, p + n);     for (int i = 0; i < n; i++) {       pair<pair<int, int>, int> PP1 = {{p[i].first.first - p[i].first.second, -1},                                        -1},                                 PP2 = {                                     {p[i].first.first + p[i].first.second, inf},                                     inf};       l[i] = lower_bound(p, p + n, PP1) - p;       r[i] = upper_bound(p, p + n, PP2) - p;     }     for (int i = 0; i < n; i++) {       mp[p[i].second].push_back(i);     }     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     for (int i = 0; i < int((vec).size()); i++) {       long long bf = ans;       Add(mp[vec[i]]);       vec2.push_back(ans - bf);     }     for (int i = 0; i < int((vec).size()); i++) {       for (int j = i + 1; j < int((vec).size()) && vec[j] - vec[i] <= k; j++) {         vector<int> vv(int((mp[vec[i]]).size()) + int((mp[vec[j]]).size())),             v1 = mp[vec[i]], v2 = mp[vec[j]];         merge(v1.begin(), v1.end(), v2.begin(), v2.end(), vv.begin());         Add(vv);         ans -= vec2[i] + vec2[j];       }     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long x, y, p, q;       cin >> x >> y >> p >> q;       if (p == q && x == y) {         printf( 0 n );         continue;       }       if (p == 0 && x == 0) {         printf( 0 n );         continue;       }       if (p == q || p == 0 || q == 0) {         printf( -1 n );         continue;       }       long long i = max(           (x - p * ((y + q - 1) / q) + p - 1) / p,           (p * ((y + q - 1) / q) - (x + ((y + q - 1) / q) * q - y) + q - p - 1) /               (q - p));       printf( %lld n , i * q + ((y + q - 1) / q) * q - y);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double sq = 1.73205080757;   int main() {     long long k, k1;     cin >> k;     k1 = k * 2;     k *= 2;     k1 -= k1 % 3;     k1++;     if (k1 > k) k1 -= 3;     long long h = 1, h1, an = 0;     while (k1 > 0) {       while (k1 * k1 + 3LL * h * h <= k * k &&              (k1 + 1) * (k1 + 1) + 3LL * (h - 1) * (h - 1) <= k * k)         h++;       h--;       if ((k1 - 1) % 6 == 0)         h1 = max(h - (h % 2 == 0), 0LL);       else         h1 = h - h % 2;       an += h1;       k1 -= 3;     }     cout << an * 2 - h1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast();     long long int t = 1;     while (t--) {       long long int n, m;       cin >> n >> m;       long long int a[n][m], b[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> b[i][j];         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] > b[i][j]) {             a[i][j] = b[i][j] + a[i][j];             b[i][j] = a[i][j] - b[i][j];             a[i][j] = a[i][j] - b[i][j];           }         }       }       bool ans = 1;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m - 1; j++) {           if (a[i][j] >= a[i][j + 1]) {             ans = 0;             break;           }           if (b[i][j] >= b[i][j + 1]) {             ans = 0;             break;           }         }       }       for (int i = 0; i < n - 1; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] >= a[i + 1][j]) {             ans = 0;             break;           }           if (b[i][j] >= b[i + 1][j]) {             ans = 0;             break;           }         }       }       if (!ans)         cout <<  Impossible ;       else         cout <<  Possible ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const double eps = 1e-10;   const long long INF = (1LL << 60);   int main() {     int a, b;     scanf( %d%d , &a, &b);     if (a == b) {       printf( %d n , a);       return 0;     }     double ans = -1;     if (a >= b) {       int k = (int)floor((a * 1.0 / b - 1) / 2);       ans = (a - b) * 1.0 / (2 * k);       ans = min(ans, (a + b) * 1.0 / (2 * k + 2));     }     printf( %0.12f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000 + 10];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       long long k;       cin >> k;       for (int i = 1; i <= k; i++) cin >> a[i];       sort(a + 1, a + k + 1);       int ans = 1;       for (int i = 1; i < k; i++) {         if (a[i] != a[i + 1]) {           ans++;           continue;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     long long n, m, k;     cin >> n >> m >> k;     long long x, s;     cin >> x >> s;     pair<long long, long long> a[m];     for (int i = 0; i < m; i++) cin >> a[i].second;     for (int i = 0; i < m; i++) cin >> a[i].first;     sort(a, a + m);     pair<long long, long long> c[k];     for (int i = 0; i < k; i++) cin >> c[i].first;     for (int i = 0; i < k; i++) cin >> c[i].second;     long long mn[m];     mn[0] = a[0].second;     for (int i = 1; i < m; i++) {       mn[i] = min(mn[i - 1], a[i].second);     }     long long ans = n * x;     for (int i = 0; i < m; i++) {       if (a[i].first <= s) ans = min(ans, n * a[i].second);     }     for (int i = 0; i < k; i++) {       if (c[i].second > s) break;       int t = c[i].first;       int k =           upper_bound(a, a + m,                       pair<long long, long long>(s - c[i].second, 1LL << 60)) -           a;       k--;       if (k >= 0) {         ans = min(ans, (n - t) * min(x, mn[k]));       }       ans = min(ans, (n - t) * x);     }     ans = max(ans, 0LL);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 2e5 + 10;   using namespace std;   int T, N, cmp;   int p[MAXN], c[MAXN];   vector<int> comp[MAXN];   bool vis[MAXN];   void dfs(int x) {     vis[x] = true;     comp[cmp].push_back(c[x]);     if (!vis[p[x]]) dfs(p[x]);   }   int min_ans(int idx_comp) {     int n_comp = (int)(comp[idx_comp].size());     vector<int> div;     for (long long i = 1; i * i <= 1LL * n_comp; i++)       if (n_comp % i == 0) {         div.push_back((int)i);         if (i * i != 1LL * n_comp) div.push_back((int)(n_comp / i));       }     sort(div.begin(), div.end());     for (int d : div)       for (int i = 0; i < d; i++) {         int g = (i + d) % n_comp;         bool found = true;         while (g != i) {           if (comp[idx_comp][g] != comp[idx_comp][i]) found = false;           g = (g + d) % n_comp;         }         if (found) return d;       }   }   inline void init() {     cmp = 0;     for (int i = 1; i < N + 1; i++) {       vis[i] = false;       comp[i].clear();     }   }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &N);       init();       for (int i = 1; i < N + 1; i++) scanf( %d , &p[i]);       for (int i = 1; i < N + 1; i++) scanf( %d , &c[i]);       for (int i = 1; i < N + 1; i++)         if (!vis[i]) {           cmp++;           dfs(i);         }       int mn = N;       for (int i = 1; i < cmp + 1; i++) mn = min(mn, min_ans(i));       printf( %d n , mn);     }   }
#include <bits/stdc++.h>   using namespace std;   bool st[1000000];   int main() {     int N, K;     cin >> N >> K;     for (int i = 0; i < 1000000; i++) st[i] = false;     int cnt = 0;     for (int i = 0; i < N; i++) {       int te1, te2;       cin >> te1 >> te2;       te1 += 100000, te2 += 100000;       for (int j = te1; j <= te2; j++) {         if (!st[j]) {           st[j] = true;           cnt++;         }       }     }     cout << ((cnt + K - 1) / K) * K - cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 1;   template <class T>   bool get_max(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <class T>   bool get_min(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   int main() {     int f[21];     int a, b, c;     cin >> a >> b >> c;     f[0] = a;     f[1] = b;     for (int i = 2; i < 21; i++) f[i] = f[i - 1] + f[i - 2];     cout << f[c] << endl;     return 0;   }