malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using matrix = vector<vector<long long>>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int x, l, n, q;     cin >> x >> l >> n >> q;     int log_n = 0;     while ((1 << log_n) <= n) {       ++log_n;     }     vector<int> c(l + 1);     for (int i = 1; i <= l; ++i) {       cin >> c[i];     }     map<int, int> stones;     vector<int> stops = {n - x};     for (int i = 0; i < q; ++i) {       int p, w;       cin >> p >> w;       stones[p] = w;       for (int j = 1; j <= l; ++j) {         stops.push_back(p - j);       }     }     sort(stops.begin(), stops.end());     while (stops.back() > n - x) {       stops.pop_back();     }     vector<matrix> pow_matrix(log_n);     pow_matrix[0].assign(1 << l, vector<long long>(1 << l, LLONG_MAX / 2));     for (int i = 0; i < (1 << l); ++i) {       if ((i & 1) == 0) {         pow_matrix[0][i][i >> 1] = 0;       } else {         for (int j = 1; j <= l; ++j) {           if ((i & (1 << j)) == 0) {             pow_matrix[0][i][(i ^ (1 << j)) >> 1] = c[j];           }         }       }     }     auto mul = [](const matrix& a, const matrix& b) -> matrix {       int n = a.size();       matrix c(n, vector<long long>(n, LLONG_MAX / 2));       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           for (int k = 0; k < n; ++k) {             c[i][k] = min(c[i][k], a[i][j] + b[j][k]);           }         }       }       return c;     };     for (int i = 1; i < log_n; ++i) {       pow_matrix[i] = mul(pow_matrix[i - 1], pow_matrix[i - 1]);     }     auto mul_vector = [](const matrix& a,                          const vector<long long>& b) -> vector<long long> {       int n = a.size();       vector<long long> c(n, LLONG_MAX / 2);       for (int i = 0; i < n; ++i) {         for (int j = 0; j < n; ++j) {           c[j] = min(c[j], a[i][j] + b[i]);         }       }       return c;     };     vector<long long> dp(1 << l, LLONG_MAX / 2);     dp[(1 << x) - 1] = 0;     int pos = 1;     for (auto i : stops) {       if (i < pos) {         continue;       }       for (int j = log_n - 1; j >= 0; --j) {         if (pos + (1 << j) <= i) {           dp = mul_vector(pow_matrix[j], dp);           pos += 1 << j;         }       }       vector<long long> dp_new(1 << l, LLONG_MAX / 2);       for (int j = 0; j < (1 << l); ++j) {         if ((j & 1) == 0) {           dp_new[j >> 1] = min(dp_new[j >> 1], dp[j]);         } else {           for (int k = 1; k <= l; ++k) {             if ((j & (1 << k)) == 0) {               long long cost = dp[j] + c[k];               if (stones.count(pos + k)) {                 cost += stones[pos + k];               }               int mask = (j ^ (1 << k)) >> 1;               dp_new[mask] = min(dp_new[mask], cost);             }           }         }       }       dp = dp_new;       ++pos;     }     cout << dp[(1 << x) - 1] <<   n ;   }
#include <bits/stdc++.h>   double eps = 1e-6;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n;     long long p, a[100010], b[100010];     long long sum = 0;     cin >> n >> p;     for (int i = 0; i < n; ++i) {       cin >> a[i] >> b[i];       sum += a[i];     }     if (p >= sum) {       cout << -1 << endl;       return 0;     }     double lo = 0;     double hi = 1e17;     double mx = 0;     for (int var = 0; var < 100; ++var) {       mx = lo + (hi - lo) / 2;       double need = 0;       for (int i = 0; i < n; ++i) {         need += max(mx * a[i] - b[i], 0 * 1.0);       }       if (p * mx >= need) {         lo = mx + eps;       } else {         hi = mx - eps;       }     }     printf( %.9f n , lo);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, f[1050000], a[1050000], b[1050000], mp[21][100005], ans;   void fwt(long long a[], long long n, long long f) {     for (long long i = 1; i < 1 << n; i <<= 1) {       for (long long t = 0; t < 1 << n; t++) {         if (i & t) {           long long x = a[t - i], y = a[t];           a[t - i] = x + y;           a[t] = x - y;         }       }     }     if (f == -1) {       for (long long i = 0; i < 1 << n; i++) a[i] = a[i] / (1 << n);     }   }   long long get(long long x) {     long long num = 0;     while (x) {       if (x % 2 == 1) num++;       x /= 2;     }     return num;   }   int main() {     scanf( %lld%lld , &n, &m);     ans = n * m;     f[1] = 1;     for (long long i = 2; i <= n; i++) {       f[i] = f[i - 1] * 2;     }     for (long long i = 1; i <= n; i++) {       for (long long t = 1; t <= m; t++) {         char s;         cin >> s;         if (s ==  1 )           mp[i][t] = 1;         else           mp[i][t] = 0;       }     }     for (long long i = 1; i <= m; i++) {       long long x = 0;       for (long long t = 1; t <= n; t++) {         if (mp[t][i] == 1) x += f[t];       }       a[x]++;     }     for (long long i = 0; i < 1 << n; i++) {       long long x = get(i);       b[i] = min(x, n - x);     }     fwt(a, n, 1);     fwt(b, n, 1);     for (long long i = 0; i < 1 << n; i++) {       a[i] = a[i] * b[i];     }     fwt(a, n, -1);     for (long long i = 0; i < 1 << n; i++) {       ans = min(ans, a[i]);     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, sum = 0;     while (cin >> n) {       for (int i = 0; i < (n); ++i) {         int x;         cin >> x;         sum += x;       }       if (sum % n)         cout << n - 1 <<   n ;       else         cout << n <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, t, n;     cin >> t;     while (t--) {       cin >> n;       long long arr[n];       for (i = 0; i < n; i++) {         cin >> arr[i];       }       reverse(arr, arr + n);       for (i = 0; i < n - 1; i++) {         cout << arr[i] <<    ;       }       cout << arr[n - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int mxm = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n], i;       set<long long int> x;       for (i = 0; i < n; i++) {         cin >> a[i];         x.insert(i + 1);       }       sort(a, a + n);       for (i = 0; i < n; i++) {         if (x.count(a[i])) {           x.erase(a[i]);           a[i] = 0;         }       }       long long int ans = 0;       sort(a, a + n);       for (i = 0; i < n; i++) {         if (a[i] > 0) {           if (2 * (*x.begin()) < a[i]) {             x.erase(x.begin());             ans++;           } else {             ans = -1;             break;           }         }       }       cout << (ans) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     while (cin >> n >> d) {       int A[n], ans = 0;       for (int i = 0; i < n; i++) cin >> A[i];       for (int i = 1; i < n; i++) {         if (A[i] <= A[i - 1]) {           int rest = A[i - 1] - A[i], cnt = (rest / d) + 1;           A[i] += cnt * d;           ans += cnt;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long INF = (long long)5e18;   const int MOD = 998244353;   int add(int x, int y) {     x += y;     return x >= MOD ? x - MOD : x;   }   int sub(int x, int y) {     x -= y;     return x < 0 ? x + MOD : x;   }   int qpow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = (long long)(ret) * (x) % MOD;       x = (long long)(x) * (x) % MOD;       y >>= 1;     }     return ret;   }   void checkmin(int &x, int y) {     if (x > y) x = y;   }   void checkmax(int &x, int y) {     if (x < y) x = y;   }   void checkmin(long long &x, long long y) {     if (x > y) x = y;   }   void checkmax(long long &x, long long y) {     if (x < y) x = y;   }   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   const int N = 5005;   int n, a[N], dp[N];   int fac[N], ifac[N], lim[N];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (long long)(fac[i - 1]) * (i) % MOD;     ifac[n] = qpow(fac[n], MOD - 2);     for (int i = n - 1; i >= 0; i--)       ifac[i] = (long long)(ifac[i + 1]) * (i + 1) % MOD;     for (int i = 1; i <= n; i++) {       for (int j = i - 1; j >= 1; j--) {         if (a[j] * 2 <= a[i]) {           lim[i] = j;           break;         }       }     }   }   void solve() {     dp[0] = 1;     if (a[n] < a[n - 1] * 2) {       puts( 0 );       return;     }     for (int i = 1; i <= n; i++) {       for (int j = lim[i]; j >= 0; j--) {         int delta = lim[i] - lim[j] - 1, rest = n - lim[j] - 2;         if (j == 0) delta++, rest++;         dp[i] =             add(dp[i], (long long)(dp[j]) *                            ((long long)(fac[rest]) * (ifac[rest - delta]) % MOD) %                            MOD);       }     }     cout << dp[n] << endl;   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, a, b;     cin >> k >> a >> b;     if (a / k + b / k && a % k <= (b / k) * (k - 1) && b % k <= (a / k) * (k - 1))       cout << a / k + b / k <<   n ;     else       cout <<  -1 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 1, sum = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * f;   }   const int MAXN = 155;   int f[MAXN][55][55][55], nxt[MAXN][3];   char s[MAXN];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     nxt[n + 1][0] = nxt[n + 1][1] = nxt[n + 1][2] = n + 1;     for (int i = n; i >= 1; i--) {       nxt[i][0] = nxt[i + 1][0];       nxt[i][1] = nxt[i + 1][1];       nxt[i][2] = nxt[i + 1][2];       nxt[i][s[i] -  a ] = i;     }     int ans = 0;     f[1][0][0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int a = 0; a <= (n + 2) / 3; a++)         for (int b = 0; b <= (n + 2) / 3; b++)           for (int c = 0; c <= (n + 2) / 3; c++) {             if (a + b + c == n && abs(a - b) <= 1 && abs(a - c) <= 1 &&                 abs(b - c) <= 1) {               ans += f[i][a][b][c], ans %= 51123987;               continue;             }             if (nxt[i][0] <= n)               (f[nxt[i][0]][a + 1][b][c] += f[i][a][b][c]) %= 51123987;             if (nxt[i][1] <= n)               (f[nxt[i][1]][a][b + 1][c] += f[i][a][b][c]) %= 51123987;             if (nxt[i][2] <= n)               (f[nxt[i][2]][a][b][c + 1] += f[i][a][b][c]) %= 51123987;           }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int dp[N];   int pdp[2 * N];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int c, n;     cin >> c >> n;     ++n;     pair<pair<int, int>, int> a[n];     a[0] = {{1, 1}, 0};     for (int i = 1; i < n; i++)       cin >> a[i].second >> a[i].first.first >> a[i].first.second;     memset(dp, 0, sizeof dp);     memset(pdp, 0, sizeof pdp);     dp[n - 1] = 1;     pdp[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       dp[i] = i != 0;       for (int j = i + 1; j < min(n, i + 1005); j++) {         int taken = abs(a[i].first.first - a[j].first.first) +                     abs(a[i].first.second - a[j].first.second);         int can = a[j].second - a[i].second;         if (taken <= can) {           dp[i] = max(dp[i], dp[j] + (i != 0));         }       }       dp[i] = max(dp[i], pdp[i + 1004] + (i != 0));       pdp[i] = max(dp[i], pdp[i + 1]);     }     cout << dp[0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const int N = 3e5 + 10;   int a[N];   int b[N];   long long solve(long long x, int n) {     long long tmp = 0;     for (int i = 1; i <= n; i++) {       tmp += a[i] * x / b[i];     }     return tmp + n;   }   int main() {     int n, c;     cin >> n >> c;     for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];     int l = 1, r = inf;     int lans = inf, rans = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (solve(mid, n) >= c)         lans = mid, r = mid - 1;       else         l = mid + 1;     }     l = 1, r = inf;     while (l <= r) {       int mid = (l + r) / 2;       if (solve(mid, n) <= c)         rans = mid, l = mid + 1;       else         r = mid - 1;     }     if (solve(lans, n) != c || solve(rans, n) != c)       cout << 0 << endl;     else       cout << max(0, rans - lans + 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(register T& t) {     register T f = 1;     register char ch = getchar();     t = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) t = t * 10 + ch -  0 , ch = getchar();     t *= f;     return t;   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   const long long p = 998244353;   inline long long power(register long long x, register long long k = p - 2) {     register long long re = 1;     for (; k; k >>= 1, x = x * x % p)       if (k & 1) re = re * x % p;     return re;   }   long long n, m;   long long a[300005];   long long g[300005], f[300005];   long long ans;   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]), m += a[i];     g[0] = n - 1;     for (int i = 1; i < m; i++)       g[i] =           (m * (n - 1) % p + g[i - 1] * (n - 1) % p * i % p) * power(m - i) % p;     f[m] = 0;     for (int i = m - 1; i >= 0; i--) f[i] = (f[i + 1] + g[i]) % p;     ans = (p - f[0] * (n - 1) % p) % p;     for (int i = 1; i <= n; i++) ans = (ans + f[a[i]]) % p;     printf( %lld n , ans * power(n) % p);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     std::vector<int> v;     for (int i = 0; i < n / 2; i++) {       v.push_back(2);     }     if (n % 2 != 0) {       v.pop_back();       v.push_back(3);     }     cout << v.size() << endl;     for (auto a : v) cout << a <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   inline void Max(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   inline void Min(T &a, U b) {     if (a > b) a = b;   }   inline void add(int &a, int b) {     a += b;     while (a >= 1000000007) a -= 1000000007;   }   inline int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = ans * (long long)a % 1000000007;       a = (long long)a * a % 1000000007;       b >>= 1;     }     return ans;   }   int a[200005], b[200005], q[200005];   int main() {     int j, k, i, T, ca = 0, K = 0, m, n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) scanf( %d , &b[i]), b[i]++;     a[n] = 1000000007;     b[n] = a[n] + 1;     long long ans = 0;     int sum = 0, p;     for (int i = 0; i < n; i++) {       int l = max(a[i], a[i + 1]), r = min(b[i], b[i + 1]);       if (l < r) {         p = 1LL * (b[i] - a[i]) * (b[i + 1] - a[i + 1]) % 1000000007;         p = pow(p, 1000000007 - 2);         K = 1LL * (r - l) * p % 1000000007;       } else         K = 0;       K = (1 - K + 1000000007) % 1000000007;       q[i] = K;       ans += K;       ans += 2LL * K * sum % 1000000007;       if (i) add(sum, q[i - 1]);     }     ans %= 1000000007;     for (int i = 0; i < n - 1; i++) {       K = (1 - (1 - q[i]) - (1 - q[i + 1])) % 1000000007;       int l = max(a[i], a[i + 1]), r = min(b[i], b[i + 1]);       Max(l, a[i + 2]), Min(r, b[i + 2]);       if (l < r) {         p = 1LL * (b[i] - a[i]) * (b[i + 1] - a[i + 1]) % 1000000007 *             (b[i + 2] - a[i + 2]) % 1000000007;         p = pow(p, 1000000007 - 2);         p = 1LL * (r - l) * p % 1000000007;         K = (K + p) % 1000000007;       }       ans += 2LL * K;     }     ans %= 1000000007;     if (ans < 0) ans += 1000000007;     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vi[200200];   int dp[200200];   int dfs(int now, int prev) {     dp[now] = 1;     for (auto x : vi[now]) {       if (x == prev) continue;       dp[now] += dfs(x, now);     }     return dp[now];   }   long long int rose = 0;   int n;   void rec(int now, int prev, long long int sum) {     rose = max(rose, sum);     for (auto x : vi[now]) {       if (x == prev) continue;       rec(x, now, sum - dp[x] + (n - dp[x]));     }   }   int main() {     int i, j, k, x, y, ans, curr, temp, m;     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d %d , &x, &y);       vi[x].push_back(y);       vi[y].push_back(x);     }     dfs(1, 0);     for (i = 1; i <= n; i++) rose += dp[i];     rec(1, 0, rose);     printf( %lld n , rose);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, k, ans = 0, flag = -1, p = 0, sum = 0;     cin >> n >> k;     long long a[n], i, b[n];     map<long long, long long> m;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + n);     reverse(a, a + n);     for (i = 0; i < k; i++) {       ans += a[i];       m[a[i]]++;     }     cout << ans << endl;     sum = n;     flag = 0;     for (i = 0; i < n; i++) {       p++;       if (k == 1) break;       if (m[b[i]] > 0) {         cout << p <<    ;         sum -= p;         k--;         p = 0;         m[b[i]]--;       }     }     if (sum) cout << sum;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, d, m;   long long lin;   long long a[100007], b[100007], la, lb;   long long pa[100007], pb[100007];   long long ans;   void go(long long l, long long r, long long k) {     if (l > r) return;     long long mid = (l + r) / 2;     long long yu = min(n - ((mid - 1) * (d + 1) + 1), la);     long long now = pa[yu] + pb[mid];     if (now > ans) {       ans = now;       go(l, mid - 1, 2);       go(mid + 1, r, 1);     } else {       if (k == 1) {         go(l, mid - 1, 1);       } else {         go(mid + 1, r, 2);       }     }   }   int main() {     la = 0, lb = 0;     scanf( %lld%lld%lld , &n, &d, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &lin);       if (lin <= m) {         a[++la] = lin;       } else {         b[++lb] = lin;       }     }     sort(a + 1, a + 1 + la, greater<int>());     sort(b + 1, b + 1 + lb, greater<int>());     for (int i = 1; i <= la; i++) {       pa[i] = pa[i - 1] + a[i];     }     for (int i = 1; i <= lb; i++) {       pb[i] = pb[i - 1] + b[i];     }     long long l = 0, r = min((n - 1) / (d + 1) + 1, lb);     ans = 0;     go(l, r, 0);     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   map<long long int, long long int> m;   map<long long int, long long int> m1, m2;   int main() {     ios_base::sync_with_stdio(0);     ;     long long int n, k;     cin >> n >> k;     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       if ((x / k) * k == x) {         ans += m2[x / k];         m2[x] += m1[x / k];       }       m1[x]++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define pb push_back   #define mp make_pair   #define mt make_tuple   #define ff first   #define ss second   #define pii pair <int,int>   #define pll pair <ll,ll>   #define testcase() int t; cin>>t; while(t--)   #define forn(i,n) for(int i=0;i<n;i++)   #define forn1(i,n) for(int i=1;i<=n;i++)   #define vll vector <ll>   #define vi vector <int>   #define all(v) v.begin(),v.end()      ll M = 1e9 + 7;   double pi = acos(-1.0);   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }   ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }   ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}      int main() {        //ifstream cin( input.txt );    //ofstream cout( output.txt );    ios_base::sync_with_stdio(false);        cin.tie(NULL);         ll n,k,x; cin >> n >> k >> x;       vll a(n);       forn(i,n) cin >> a[i];       sort(all(a));       ll grp = 1;       vll diffs;       for(int i=1;i<n;i++)       {           if( a[i] - a[i-1] <= x ) continue;           grp++;           diffs.pb( (a[i]-a[i-1]-1)/x );       }       sort(all(diffs));       int id = 0;       // cout << grp << endl;       while(id<diffs.size())       {           if( diffs[id] > k ) break;           k -= diffs[id];           grp--;           id++;       }       cout << grp <<   n ;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, t, min = -1, flag = 0;     cin >> n;     string s;     cin >> s;     long long int a[n];     for (int i = 0; i < n; i++) {       cin >> t;       a[i] = t;     }     for (int i = 1; i < n; i++) {       if ((s[i] ==  L  && s[i - 1] ==  R )) {         t = (a[i] - a[i - 1]) / 2;         if (t < min || min == -1) min = t;         flag = 1;       }     }     if (flag == 0)       cout << -1;     else       cout << min;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   const int MAXN = 2e5 + 10;   const int INF = 2e9 + 5;   int n, m, vec[MAXN], ans[MAXN], qu[MAXN], sz;   vector<array<int, 4>> g[MAXN];   void solve() {     cin >> n >> m;     memset(ans, -1, 4 * m);     for (int i = 0, u, v, w; i < m; i++) {       cin >> u >> v >> w;       --u, --v;       g[u].push_back({v, w, i, 0});       g[v].push_back({u, w, i, 1});       vec[u] += w;       vec[v] += w;     }     for (int i = 1; i < n - 1; i++) {       vec[i] /= 2;     }     vec[0] = 0;     vec[n - 1] = INF;     qu[sz++] = 0;     for (int i = 0; i < sz; i++) {       int u = qu[i];       for (auto [v, w, j, dir] : g[u]) {         if (~ans[j]) continue;         vec[v] -= w;         ans[j] = dir;         if (vec[v] == 0 && v != n - 1) qu[sz++] = v;       }     }     for (int i = 0; i < m; i++) {       assert(~ans[i]);       cout << ans[i] <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int SZ = 2000 + 10;   LL g_n, g_k, g_p;   LL a[SZ], b[SZ];   void prete() {}   void input() {     for (int i = 0; i < g_n; ++i) {       scanf(  %I64d , a + i);     }     for (int i = 0; i < g_k; ++i) {       scanf(  %I64d , b + i);     }   }   void solve() {     LL ans = LLONG_MAX;     sort(a, a + g_n);     sort(b, b + g_k);     for (int i = 0; i <= g_k - g_n; ++i) {       LL t = LLONG_MIN;       for (int j = 0; j < g_n; ++j) {         t = max(t, abs(a[j] - b[i + j]) + abs(b[i + j] - g_p));       }       ans = min(ans, t);     }     cout << ans << endl;   }   int main() {     prete();     while (cin >> g_n >> g_k >> g_p) {       input();       solve();     }     return 0;   }