malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool setmax(T &_a, T _b) {     if (_b > _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   bool setmin(T &_a, T _b) {     if (_b < _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   T gcd(T _a, T _b) {     return _b == 0 ? _a : gcd(_b, _a % _b);   }   const int MAXN = 1010;   bool vis[MAXN];   vector<int> es[MAXN];   int n;   int que[MAXN], lst[MAXN], d[MAXN], ss, tt;   void bfs(int start) {     ss = tt = 1;     que[1] = start;     vis[start] = true;     d[start] = 0;     while (ss <= tt) {       int x = que[ss++];       for (int y : es[x])         if (!vis[y]) {           vis[y] = true;           d[y] = d[x] + 1;           que[++tt] = y;         }     }   }   int solve_component(int start) {     bfs(start);     int len = tt;     for (int i = int(1); i <= int(len); ++i) lst[i] = que[i];     int ans = -1;     for (int k = int(1); k <= int(len); ++k) {       for (int i = int(1); i <= int(len); ++i) vis[lst[i]] = false;       bfs(lst[k]);       bool ok = true;       for (int i = int(1); i <= int(tt); ++i) {         int x = que[i];         for (int y : es[x])           if (abs(d[x] - d[y]) != 1) ok = false;       }       if (ok) setmax(ans, d[que[tt]]);     }     return ans;   }   int main() {     int m;     scanf( %d%d , &n, &m);     for (int i = int(1); i <= int(n); ++i) es[i].clear();     for (int i = int(1); i <= int(m); ++i) {       int x, y;       scanf( %d%d , &x, &y);       es[x].push_back(y), es[y].push_back(x);     }     memset(vis, false, sizeof(vis));     int ans = 0;     for (int i = int(1); i <= int(n); ++i)       if (!vis[i]) {         int tmp = solve_component(i);         if (tmp < 0) {           ans = -1;           break;         }         ans += tmp;       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       int n, e;       set<int> v;       map<int, int> m;       cin >> n;       for (long long int i = 0; i < n; i++) {         cin >> e;         m[e]++;         if (m[e] == 1) v.insert(e);       }       int np = 0, ps = 0;       while (!v.empty()) {         ps = 0;         for (map<int, int>::iterator itm = m.begin(); itm != m.end(); itm++) {           while (itm->second != 0 && itm->first >= ps) {             itm->second -= 1;             ps += 1;           }           if (itm->second == 0) v.erase(itm->first);         }         np++;       }       cout << np;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<pair<long long, long long> > S;   set<pair<long long, long long> >::iterator it;   set<pair<long long, long long> >::iterator it2;   pair<long long, long long> temp;   void intersect_yes(long long s, long long e) {     if (S.empty()) return;     for (it = S.begin(); it != S.end();) {       if (it->first < s && it->second < s)         S.erase(it++);       else         break;     }     if (S.empty()) return;     bool finish = 0;     for (it = --S.end(); !finish;) {       if (it == S.begin()) finish = true;       if (it->first > e)         S.erase(it--);       else         break;     }     if (S.empty()) return;     temp = *S.begin();     S.erase(temp);     temp.first = max(s, temp.first);     S.insert(temp);     temp = *(--S.end());     S.erase(temp);     temp.second = min(temp.second, e);     S.insert(temp);   }   const long long big = 1LL << 55;   void intersect_no(long long s, long long e) {     it = S.lower_bound(make_pair(s, big));     if (it != S.begin()) it--;     it2 = S.upper_bound(make_pair(e, big));     while (it != it2) {       if (it->second < s)         it++;       else if (it->first < s) {         if (it->second >= s && it->second <= e) {           temp = *it;           it++;           S.erase(temp);           S.insert(make_pair(temp.first, s - 1));         } else if (it->second > e) {           temp = *it;           it++;           S.erase(temp);           S.insert(make_pair(temp.first, s - 1));           S.insert(make_pair(e + 1, temp.second));         }       } else if (it->first >= s && it->first <= e) {         if (it->second <= e) {           S.erase(it++);         } else if (it->second > e) {           temp = *it;           it++;           S.erase(temp);           S.insert(make_pair(e + 1, temp.second));         }       }     }   }   int main() {     int h, q, lvl, ans;     long long l, r;     scanf( %d%d , &h, &q);     long long begining = 1LL << (h - 1), ending = (1LL << h) - 1;     S.insert(make_pair(begining, ending));     for (int i = 0; i < q; i++) {       scanf( %d%I64d%I64d%d , &lvl, &l, &r, &ans);       long long left = l * (1LL << (h - lvl)),                 right = (r + 1) * (1LL << (h - lvl)) - 1;       if (S.empty()) {         printf( Game cheated! n );         return 0;       }       if (ans)         intersect_yes(left, right);       else         intersect_no(left, right);     }     if (S.empty())       printf( Game cheated! n );     else if (S.size() == 1 && (*S.begin()).first == (*S.begin()).second)       printf( %I64d n , (*S.begin()).first);     else       printf( Data not sufficient! n );   }
#include<stdio.h>   #include<bits/stdc++.h>      typedef long long ll;      using namespace std;         int main()   {       ll deva;       cin>>deva;       for(ll ol=0;ol<deva;ol++)       {           int n;           cin>>n;           string s;           cin>>s;           int a[26]={0};           int flag=1;           a[s[0]- A ]+=1;           for(int i=1;i<n;i++)           {               if(a[s[i]- A ]>0 && s[i]!=s[i-1])               {                   flag=0;                   break;               }               a[s[i]- A ]+=1;           }           if(flag)               cout<< YES <<endl;           else                   cout<< NO <<endl;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100500];   int sp[2005];   int f[100500], l[100500];   int n, m;   int ns[2 * 100500];   int ps[2 * 100500];   int used[2 * 100500];   int lp[100500];   int rp[100500];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= m; ++i) {       scanf( %d , sp + i);       used[sp[i]] = true;       ns[sp[i]] = sp[i];       ps[sp[i]] = sp[i];     }     for (int i = n; i >= 1; --i) {       if (i != n && a[i] == a[i + 1] - 1) {         rp[i] = rp[i + 1];       } else {         rp[i] = i;       }     }     for (int i = 1; i <= n; ++i) {       if (i != 1 && a[i] == a[i - 1] + 1) {         lp[i] = lp[i - 1];       } else {         lp[i] = i;       }     }     for (int i = 2 * 100500 - 2; i >= 0; --i) {       if (ns[i] == 0) {         ns[i] = ns[i + 1];       }     }     for (int i = 1; i < 2 * 100500; ++i) {       if (ps[i] == 0) {         ps[i] = ps[i - 1];       }     }     sort(sp + 1, sp + m + 1);     f[0] = 0, l[0] = 0;     for (int i = 1; i <= n; ++i) {       int df = a[i] - i;       for (int cp = a[i], cnt = used[a[i]]; cp && df < cp;            ++cnt, cp = ps[cp - 1]) {         l[i] = max(l[i], f[lp[i - a[i] + cp] - 1] + cnt);       }       f[i] = max(f[i], l[i]);       df = n - i + a[i];       for (int cp = a[i], cnt = used[a[i]]; cp && df >= cp;            ++cnt, cp = ns[cp + 1]) {         f[rp[i + cp - a[i]]] = max(f[rp[i + cp - a[i]]], l[i] + cnt - used[a[i]]);       }     }     int res = *max_element(f + 1, f + n + 1);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INF = 1000000007;   string FILENAME =  input ;   string FILEINPUT = FILENAME;   void writeln(int a) { printf( %d n , a); }   void writeln(int a, int b) { printf( %d %d n , a, b); }   void writeln(int a, int b, int c) { printf( %d %d %d n , a, b, c); }   void writeln(int a, int b, int c, int d) {     printf( %d %d %d %d n , a, b, c, d);   }   void write(int a) { printf( %d , a); }   void write(int a, int b) { printf( %d %d , a, b); }   void write(int a, int b, int c) { printf( %d %d %d , a, b, c); }   void write(int a, int b, int c, int d) { printf( %d %d %d %d , a, b, c, d); }   void read(int &a) { scanf( %d , &a); }   void read(int &a, int &b) { scanf( %d %d , &a, &b); }   void read(int &a, int &b, int &c) { scanf( %d %d %d , &a, &b, &c); }   void read(int &a, int &b, int &c, int &d) {     scanf( %d %d %d %d , &a, &b, &c, &d);   }   void readln(int &a) { scanf( %d n , &a); }   void readln(int &a, int &b) { scanf( %d %d n , &a, &b); }   void readln(int &a, int &b, int &c) { scanf( %d %d %d n , &a, &b, &c); }   void readln(int &a, int &b, int &c, int &d) {     scanf( %d %d %d %d n , &a, &b, &c, &d);   }   void readln(vector<int> &f, int n) {     int x;     for (int i = 1; i <= n; i++) {       read(x);       f.push_back(x);     }   }   void writeln(vector<int> &f) {     for (int i = 0; i < f.size(); i++)       printf( %d%c , f[i], i == f.size() - 1 ?   n  :    );   }   void run() {     int n;     vector<int> a;     read(n);     readln(a, n);     sort(a.begin(), a.end());     int i = -1, j = 0, t, mx = 0;     read(t);     while (j != n) {       i++;       while (j < n && a[j] - a[i] <= t) j++;       mx = max(mx, j - i);     }     writeln(mx);   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[110];   int r;   void solve(int x) {     r = 0;     while (x) {       a[r++] = x % 3;       x /= 3;     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       memset(a, 0, sizeof a);       int n;       scanf( %d , &n);       solve(n);       a[r] = 0;       for (int i = r; i >= 0; i--) {         if (a[i] == 2) {           for (int j = i + 1; j <= r; j++) {             if (a[j] == 1)               a[j] = 0;             else if (a[j] == 0) {               a[j] = 1;               break;             }           }           for (int k = i; k >= 0; k--) a[k] = 0;           break;         }       }       int ans = 0;       for (int i = r; i >= 0; i--) {         ans += a[i] * pow(3, i);       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   int main() {     int n, m1, m2, m3, min1, min2, min3, max1, max2, max3;     scanf( %d%d%d%d%d%d%d , &n, &min1, &max1, &min2, &max2, &min3, &max3);     m1 = n - min2 - min3;     if (m1 <= max1)       printf( %6d %6d %6d , m1, min2, min3);     else {       m2 = min2 + m1 - max1;       if (m2 < max2)         printf( %6d %6d %6d , max1, m2, min3);       else {         m3 = n - max1 - max2;         printf( %6d %6d %6d , max1, max2, m3);       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx2 )   using namespace std;   const long long MAX = -1000000000000000000;   const long long MIN = 1000000000000000000;   const long long inf = 1000000000;   const long long KOK = 100000;   const long long LOG = 30;   const long long li = 500005;   const long long mod = 1000000007;   int n, m, b[li], a[li], k, flag, t, fa[li], si[li], vis[li], visit[li], x[li],       y[li], use[li];   int cev;   queue<int> q;   set<pair<long long, long long> > st;   string s;   vector<int> v[li], vec;   inline int dsu(int x) {     if (x == fa[x]) return x;     return fa[x] = dsu(fa[x]);   }   int main(void) {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= k; i++) {       scanf( %d %d , &x[i], &y[i]);       use[x[i]]++;       use[y[i]]++;       v[x[i]].push_back(i);       v[y[i]].push_back(i);     }     for (int i = 1; i <= k; i++) {       if (use[x[i]] <= a[x[i]] || use[y[i]] <= a[y[i]]) q.push(i);     }     while (q.size()) {       int node = q.front();       q.pop();       if (vis[node]) continue;       vis[node] = 1;       vec.push_back(node);       use[x[node]]--;       use[y[node]]--;       int nodee = node;       node = x[node];       for (int i = 0; i < (int)v[node].size(); i++) {         if ((use[x[v[node][i]]] <= a[x[v[node][i]]] ||              use[y[v[node][i]]] <= a[y[v[node][i]]]) &&             vis[v[node][i]] == 0)           q.push(v[node][i]);       }       node = y[nodee];       for (int i = 0; i < (int)v[node].size(); i++) {         if ((use[x[v[node][i]]] <= a[x[v[node][i]]] ||              use[y[v[node][i]]] <= a[y[v[node][i]]]) &&             vis[v[node][i]] == 0)           q.push(v[node][i]);       }     }     if ((int)vec.size() != k) {       printf( DEAD n );       return 0;     }     printf( ALIVE n );     reverse(vec.begin(), vec.end());     for (int i = 0; i < (int)vec.size(); i++) {       printf( %d  , vec[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MXN = 1e6 + 1;   const long long MNN = 1e3 + 1;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long long MAGIC = 1000;   const long double EPS = 1e-9;   const long double PI = 3.1415926536;   const string TIME =  rovno_ushten_push_ketti ;   long long n;   long long cnt[MXN];   set<long long> s;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       s.insert(x);       ++cnt[x];     }     if (s.size() == 2) {       long long x = *s.begin();       s.erase(s.begin());       long long y = *s.begin();       if (cnt[x] == cnt[y]) {         cout <<  YES n ;         cout << x <<     << y;       } else {         cout <<  NO ;       }     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, ns, ne, v, i;     cin >> n >> m >> ns >> ne >> v;     vector<long long int> s(ns), e(ne);     for (i = 0; i < ns; i++) cin >> s[i];     for (i = 0; i < ne; i++) cin >> e[i];     long long int q;     cin >> q;     while (q--) {       long long int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x1 == x2) {         cout << abs(y1 - y2) << endl;         continue;       }       long long int ans = INT_MAX, tmp, c;       c = lower_bound(s.begin(), s.end(), y1) - s.begin();       if (c < s.size()) {         tmp = abs(y1 - s[c]) + abs(x1 - x2) + abs(s[c] - y2);         ans = min(tmp, ans);       }       if (c >= 1) {         c -= 1;         tmp = abs(y1 - s[c]) + abs(x1 - x2) + abs(s[c] - y2);         ans = min(tmp, ans);       }       c = lower_bound(e.begin(), e.end(), y1) - e.begin();       if (c < e.size()) {         tmp = abs(y1 - e[c]) + (abs(x1 - x2) + v - 1) / v + abs(e[c] - y2);         ans = min(tmp, ans);       }       if (c >= 1) {         c -= 1;         tmp = abs(y1 - e[c]) + (abs(x1 - x2) + v - 1) / v + abs(e[c] - y2);         ans = min(tmp, ans);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, long long> mp;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       a--;       b--;       mp[{a, b}] = 1;       mp[{b, a}] = 1;     }     if (n < 7) {       cout << m << endl;     } else {       long long ans = m;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) {           long long ctr = 0;           for (long long k = 0; k < n; k++) {             if (mp[{i, k}] == 1 and mp[{j, k}]) {               ctr++;             }           }           ans = min(ans, ctr);         }       }       cout << m - ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long getres(long long n) {     if (n == 0) {       return 0;     }     vector<long long> now;     for (long long i = 0;; i++) {       long long t = pow(2, i);       if (t <= n) {         n -= t;         now.push_back(t);         if (n == 0) {           break;         }       } else {         now.push_back(n);         break;       }     }     long long even = 0, odd = 0;     for (long long i = 0; i < now.size(); i++) {       if (i % 2) {         even = (even + now[i]) % mod;       } else {         odd = (odd + now[i]) % mod;       }     }     long long odd_sum = (((odd) % mod) * (odd % mod)) % mod;     long long even_sum = (((even) % mod) * ((even + 1) % mod)) % mod;     long long res = (odd_sum + even_sum) % mod;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     long long l, r;     cin >> l >> r;     long long ans = (getres(r) - getres(l - 1) + mod) % mod;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct zero {     int nxt, to;   } edge[200000 << 1];   int head[200000], tot = 0;   void add_edge(int a, int b) {     edge[++tot] = (zero){head[a], b};     head[a] = tot;   }   int n, m, plk, poi, d1, d2, dep[200000], kl[200000], d[200000], op[200000],       h[200000];   bool flag;   void aux(int x, int fa) {     if (dep[x] > plk) plk = dep[x], poi = x;     for (int i = head[x]; i; i = edge[i].nxt) {       int to = edge[i].to;       if (to == fa) continue;       dep[to] = dep[x] + 1;       kl[to] = x;       aux(to, x);     }   }   bool cmp(int a, int b) { return h[a] < h[b]; }   void solve(int x, int fa) {     vector<int> v;     for (int i = head[x]; i; i = edge[i].nxt) {       int to = edge[i].to;       if (to == fa) continue;       v.push_back(to);     }     op[x] = 0;     if (v.size() == 0)       h[x] = op[x] = 0;     else if (v.size() == 1) {       int to = v[0];       solve(to, x);       if (op[to] || h[to]) flag = 0;       op[x] = x, h[x] = h[v[0]] + 1;     } else if (v.size() == 2) {       solve(v[0], x), solve(v[1], x);       if ((op[v[0]] && op[v[1]]) || h[v[0]] != h[v[1]])         flag = 0;       else if (op[v[0]] || op[v[1]])         op[x] = op[v[0]] + op[v[1]];       h[x] = h[v[0]] + 1;     } else if (v.size() == 3) {       solve(v[0], x), solve(v[1], x), solve(v[2], x);       sort(v.begin(), v.end(), cmp);       if (op[v[0]] || op[v[1]] || op[v[2]]) flag = 0;       if (!(h[v[1]] == h[v[0]] && h[v[2]] == h[v[0]] + 1)) flag = 0;       op[x] = x, h[x] = h[v[2]] + 1;     } else       flag = 0;   }   int main() {     scanf( %d , &n);     m = (1 << n) - 2;     for (int i = 1; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       add_edge(a, b), add_edge(b, a);       d[a]++, d[b]++;     }     poi = plk = dep[1] = 0;     aux(1, 0);     d1 = poi;     poi = plk = dep[d1] = kl[d1] = 0;     aux(d1, 0);     d2 = poi;     int poss = d2;     vector<int> syk;     while (poss) {       if (abs(2 * dep[poss] - dep[d2]) <= 1) {         flag = 1;         solve(poss, 0);         if (op[poss] && flag && h[poss] == n - 1) syk.push_back(op[poss]);       }       poss = kl[poss];     }     cout << syk.size() << endl;     sort(syk.begin(), syk.end());     for (int i = 0; i < syk.size(); i++) cout << syk[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> fibton;   void Fib(int n) {     int x = 0, y = 1, z = 0;     fibton.push_back(0);     for (int i = 0; i <= n; i++) {       z = x + y;       fibton.push_back(z);       if (fibton[fibton.size() - 1] >= n) {         break;       }       x = y;       y = z;     }   }   int main() {     int n;     cin >> n;     Fib(n);     for (int i = 0; i < fibton.size(); i++) {       for (int j = i; j < fibton.size(); j++) {         for (int k = j; k < fibton.size(); k++) {           if ((fibton[i] + fibton[j] + fibton[k]) == n) {             cout << fibton[i] <<     << fibton[j] <<     << fibton[k];             return 0;           }         }       }     }     return 0;   }
#include <iostream>   #include <iomanip>   #include <cstdio>   #include <vector>   #include <algorithm>   #include <cmath>   #include <cstring>   #include <cassert>   #include <string>   #include <set>   #include <map>   #include <random>   #include <bitset>   #include <string>   #include <unordered_set>   #include <unordered_map>   #include <deque>   #include <queue>   #define rep(i, n) for (int i = 0; i < (n); i++)   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()      using namespace std;   using ll = long long;   using ul = unsigned long long;   using ld = long double;      int main() {     ios_base::sync_with_stdio(0); cin.tie(0);     int k;     string s;     cin >> k >> s;     int n = 1 << k, pos = 0;     vector<int> a(n * 2, 1), num(n * 2), rn(n);     for (int i = k - 1; i >= 0; --i)       rep(j, 1 << i) {         num[(1 << i) + j] = pos;         rn[pos] = (1 << i) + j;         ++pos;       }     auto rel = [&](int v, char c) {       if (c ==  0 )         a[v] = a[v * 2];       else if (c ==  1 )         a[v] = a[v * 2 + 1];       else         a[v] = a[v * 2] + a[v * 2 + 1];     };     for (int i = n - 1; i; --i)       rel(i, s[num[i]]);     int q;     cin >> q;     while (q--) {       int v;       char c;       cin >> v >> c;       --v;       s[v] = c;       v = rn[v];       while (v > 0) {         rel(v, s[num[v]]);         v /= 2;       }       cout << a[1] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int lim;   char c[1000];   int g[1000][1000];   int f[1000][1000], pre[1000][1000];   void back(int v, int k) {     int p = pre[v][k];     if (p) {       back(p, k - 1);       printf( + );     }     int i1 = p + 1;     int j1 = v;     for (; i1 < j1; i1++, j1--)       if (c[i1 - 1] != c[j1 - 1]) c[j1 - 1] = c[i1 - 1];     for (int i = p + 1; i <= v; i++) printf( %c , c[i - 1]);   }   int main() {     scanf( %s , c);     scanf( %d , &lim);     for (int i = 1; i < strlen(c); i++)       for (int j = i + 1; j <= strlen(c); j++) {         int i1 = i;         int j1 = j;         for (; i1 < j1; i1++, j1--)           if (c[i1 - 1] != c[j1 - 1]) g[i][j]++;       }     memset(f, 127, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= strlen(c); i++)       for (int j = 0; j < i; j++)         for (int k = 0; k < lim && k <= j; k++)           if (f[j][k] + g[j + 1][i] < f[i][k + 1])             f[i][k + 1] = f[j][k] + g[j + 1][i], pre[i][k + 1] = j;     int min = 2000000000;     int pos = lim + 1;     for (int i = 0; i <= lim; i++)       if (f[strlen(c)][i] < min) {         min = f[strlen(c)][i], pos = i;       }     printf( %d n , min);     back(strlen(c), pos);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int mm = 500050;   int n, ss, tt, kk, m;   int c[1001001], v[1001001];   int g[1001001];   int xx[1001001], yy[1001001], minvv = 0, initi = 0;   long long sum[500500], ti[500500];   vector<int> num[500500];   inline void solve() {     int i = 0;     while (i <= m) {       if (initi - ti[i] <= tt) break;       initi -= ti[i];       minvv += mm;       ++i;     }     memset(xx, 0, sizeof(xx));     int j = 0;     while (j < num[i].size()) {       int vv = num[i][j];       ++xx[1];       --xx[vv + 1];       ++j;     }     int now = i;     i = 1;     while (i <= mm) {       xx[i] += xx[i - 1];       ++i;     }     i = 1;     while (i <= mm) {       ++minvv;       if (initi - xx[i] - sum[now] <= tt) break;       initi -= xx[i] + sum[now];       ++i;     }   }   int main() {     scanf( %d%d%d%d , &n, &kk, &ss, &tt);     int i = 1;     while (i <= n) {       scanf( %d%d , &c[i], &v[i]);       ++i;     }     g[0] = 0;     i = 1;     while (i <= kk) {       scanf( %d , &g[i]);       ++i;     }     g[kk + 1] = ss;     ++kk;     sort(g + 1, g + kk + 1);     i = 1;     while (i <= kk) {       minvv = max(minvv, g[i] - g[i - 1]);       ++i;     }     i = 1;     while (i <= kk) {       int x = minvv - (g[i] - g[i - 1]), y = 2 * (g[i] - g[i - 1]) - minvv;       if (y <= 0) {         initi += g[i] - g[i - 1];       } else {         initi += x + 2 * y;         num[y / mm].push_back(y % mm);         ti[y / mm] += y % mm;         ;       }       ++i;     }     m = 2000000000 / mm;     sum[m + 1] = 0;     i = m;     while (i >= 0) {       sum[i] = sum[i + 1] + num[i + 1].size();       ti[i] += 1ll * sum[i] * mm;       --i;     }     if (initi > tt) solve();     int ans = 2000000000;     i = 1;     while (i <= n) {       if (v[i] >= minvv) ans = min(ans, c[i]);       ++i;     }     if (ans == 2000000000) ans = -1;     printf( %d n , ans);     return 0;   }