malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   struct Question {     int x, l, r, dat;     inline Question(int tmp1 = 0, int tmp2 = 0, int tmp3 = 0, int tmp4 = 0) {       x = tmp1, l = tmp2, r = tmp3, dat = tmp4;     }     inline int operator<(const Question &a) const { return x < a.x; }   } opt[100010];   int k;   inline int lowbit(int l, int r) {     int res = 0;     --l;     for (int i = 1; i <= k; i <<= 1)       res |= (((r / i - l / i) -                (((i << 1) <= k) ? (r / (i << 1) - l / (i << 1)) : (0))) &               1) *              i;     return res;   }   struct SegmentTree {     int tot = 0, rot = 0;     int L[100010 * 30], R[100010 * 30], tag[100010 * 30], val[100010 * 30],         low[100010 * 30];     inline void upd(int k) {       if (tag[k])         val[k] = low[k];       else         val[k] = val[L[k]] ^ val[R[k]];     }     inline void Mod(int &k, int l, int r, int x, int y, int dat) {       if (y < l || r < x) return;       if (!k) k = ++tot, low[k] = lowbit(l, r);       if (x <= l && r <= y) return tag[k] += dat, upd(k);       Mod(L[k], l, ((l + r) >> 1), x, y, dat),           Mod(R[k], ((l + r) >> 1) + 1, r, x, y, dat), upd(k);     }   } T;   int main() {     int n = read(), m = read(), ans = 0;     k = read();     int lim = 1, cnt = 0;     for (; lim < k; lim <<= 1)       ;     while (m--) {       int xl = read(), yl = read();       int xr = read(), yr = read();       opt[++cnt] = Question(xl, yl, yr, 1);       opt[++cnt] = Question(xr + 1, yl, yr, -1);     }     sort(opt + 1, opt + cnt + 1);     for (int i = 1; i <= cnt; i++) {       if (opt[i].x != opt[i - 1].x) {         int x = lowbit(opt[i - 1].x, opt[i].x - 1), y = T.val[T.rot];         int a = 0, b = 0, sum = 0;         for (int j = lim; j; j >>= 1) {           sum = -a * b, a += (x & j) > 0, b += (y & j) > 0, sum += a * b;           if (sum & 1) ans ^= j;         }       }       T.Mod(T.rot, 1, n, opt[i].l, opt[i].r, opt[i].dat);     }     if (ans)       puts( Hamed );     else       puts( Malek );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, s, a, b, c, d;     cin >> n >> s;     d = s;     for (int i = 0; i < n; i++) {       cin >> a >> b;       c = a + b;       d = max(c, d);     }     cout << d;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   long long Time;   int Free;   multiset<long long> Working;   int main() {     scanf( %d%d , &N, &K);     Free = K;     Time = 0;     long long S, M;     for (int i = 0; i < N; ++i) {       scanf( %I64d%I64d , &S, &M);       S = max(S, Time);       if (Free > 0) {         --Free;         printf( %I64d n , S + M);         Working.insert(S + M);         Time = S;       } else {         Time = *Working.begin();         Time = max(Time, S);         printf( %I64d n , Time + M);         Working.erase(Working.begin());         Working.insert(Time + M);       }       while ((not Working.empty()) and ((*Working.begin()) <= Time)) {         ++Free;         Working.erase(Working.begin());       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 2e5 + 1;   vector<long long int> a[N];   vector<long long int> order, pos(N);   bool topsort(long long int n) {     order.clear();     queue<long long int> q;     vector<long long int> indeg(n + 1, 0);     for (long long int i = 1; i <= n; i++)       for (auto &it : a[i]) indeg[it]++;     for (long long int i = 1; i <= n; i++)       if (!indeg[i]) q.push(i);     long long int idx = 0;     while (!q.empty()) {       int v = q.front();       q.pop();       order.push_back(v);       idx++;       pos[v] = idx;       for (auto &u : a[v]) {         indeg[u]--;         if (!indeg[u]) q.push(u);       }     }     return (order.size() == n);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     vector<long long int> a1(n + 1), b(n + 1), c;     for (long long int i = 1; i <= n; i++) cin >> a1[i];     for (long long int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i] != -1) a[i].push_back(b[i]);     }     topsort(n);     vector<long long int> ans, tmp;     long long int sum1 = 0, k = 0;     for (long long int i = 0; i < order.size(); i++) {       long long int pos = order[i];       sum1 += a1[pos];       if (b[pos] != -1 && a1[pos] < 0)         tmp.push_back(pos);       else {         if (b[pos] != -1) a1[b[pos]] += a1[pos];         ans.push_back(pos);       }     }     reverse(tmp.begin(), tmp.end());     for (long long int i = 0; i < tmp.size(); i++) ans.push_back(tmp[i]);     cout << sum1 <<   n ;     for (long long int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double optN(long long m, int k) {     long double ret = 1;     m *= k;     long long nowC = k;     for (int i = 1; i <= k; ++i) {       if (m < nowC * i) {         ret += m / i;         return ret;       }       ret += nowC;       m -= nowC * i;       if (m / (i + 1.) / nowC <= (k - i) / (i + 1.)) return ret + m / (i + 1);       nowC *= k - i;       nowC /= (i + 1);     }     return ret;   };   int main() {     int CASE;     cin >> CASE;     for (int TCASE = 1; TCASE <= CASE; ++TCASE) {       long long n, m;       cin >> n >> m;       long long l = 0, r = (0x3f3f3f3f);       while (l < r) {         long long mid = l + r >> 1;         if (optN(m, mid) >= n)           r = mid;         else           l = mid + 1;       }       cout << l << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const int INF = 1 << 28;   const long long INFL = 1LL << 62;   int toi(string x) {     int z;     istringstream iss(x);     iss >> z;     return z;   }   string str[] = { YES ,  NO };   int modulo(int m, int n) { return m >= 0 ? m % n : (n - abs(m % n)) % n; }   using namespace std;   int arr[101] = {0}, n, m;   int main() {     cin >> n >> m;     for (int i = 1, a, b, c; i <= m; i++) {       cin >> a >> b >> c;       arr[a] -= c;       arr[b] += c;     }     int sum = 0;     for (int i = 1; i <= n; i++)       if (arr[i] > 0) sum += arr[i];     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, b[100005], a[200005];   void solve() {     cin >> n;     for (long long i = 1; i < n / 2 + 1; i++) cin >> b[i];     a[1] = 0;     a[n] = b[1];     for (long long i = 2; i < n / 2 + 1; i++) {       a[i] = max(a[i - 1], b[i] - a[n - i + 2]);       a[n - i + 1] = b[i] - a[i];     }     for (long long i = 1; i < n + 1; i++) cout << a[i] <<    ;     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, x1, x2, y1, y2, i, sum = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x1 >> y1 >> x2 >> y2;       sum += ((x2 - x1) + 1) * ((y2 - y1) + 1);     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int Inf = (int)1e9;   const long long InfL = (long long)1e18;   const int MaxN = (int)2e5 + 5;   vector<int> adj[MaxN], ans;   int n, a, deg[MaxN], dead[MaxN];   void dfs2(int x, int p) {     dead[x] = true;     ans.push_back(x);     for (auto u : adj[x]) --deg[u];     for (auto u : adj[x])       if (u != p && !dead[u]) dfs2(u, x);   }   void dfs1(int x, int p) {     for (auto u : adj[x])       if (u != p) dfs1(u, x);     if (!(deg[x] & 1)) dfs2(x, p);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (!a) continue;       adj[i].push_back(a);       deg[i]++;       adj[a].push_back(i);       deg[a]++;     }     dfs1(1, 0);     if (ans.size() == n) {       cout <<  YES  <<   n ;       for (int i = 0; i < n; i++) cout << ans[i] <<   n ;     } else {       cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int mod = 1000000007;   const int M = INT_MAX;   using namespace std;   int powb(int x, int y) {     int res = 1;     x = x % M;     while (y > 0) {       if (y % 2) res = (res * x) % M;       y /= 2;       x = (x * x) % M;     }     return res;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int solve() {     int n, t, s = 0, x, s1 = 0, i, j;     cin >> n >> t;     vector<int> v(2 * n);     for (i = 0; i < n; i++) {       cin >> x;       s1 += x;       v[i] = x;       v[i + n] = x;     }     if (s1 <= t) return n;     int max = 0;     x = 0;     for (i = 0; i < 2 * n; i++) {       s += v[i];       if (s > t) {         s -= v[i];         break;       }       x++;       if (x > max) max = x;     }     for (i = 1; i < n; i++) {       s -= v[i - 1];       x--;       for (j = i + x; j < n; j++) {         s += v[j];         if (s > t) {           s -= v[j];           break;         }         x++;         if (x > max) max = x;       }       if (j == n - 1) break;     }     return max;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read(int &val) {     int x = 0;     int bz = 1;     char c;     for (c = getchar(); (c <  0  || c >  9 ) && c !=  - ; c = getchar())       ;     if (c ==  - ) {       bz = -1;       c = getchar();     }     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48;     val = x * bz;   }   const int INF = 0x3f3f3f3f;   const int maxn = 1e6 + 100;   const int mod = 998244353;   long long a[maxn], b[maxn];   int n, k;   long long sum[maxn], tim[maxn];   struct node {     int id;     bool operator<(const node bb) const { return tim[id] > tim[bb.id]; }   };   bool check(long long mid) {     priority_queue<node> q;     for (int i = 1; i <= n; i++) {       tim[i] = a[i] / b[i];       sum[i] = a[i];       q.push(node{i});     }     for (int i = 0; i <= k - 1; i++) {       node top = q.top();       q.pop();       int xx = top.id;       if (tim[xx] < i) return false;       if (tim[xx] >= k) return true;       sum[xx] += mid;       tim[xx] = sum[xx] / b[xx];       if (tim[xx] < i) return false;       q.push(node{xx});     }     return true;   }   int main() {     read(n);     read(k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++) scanf( %lld , &b[i]);     long long ans = -1, l = 0, r = 1e13;     while (l <= r) {       long long mid = l + r >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int socks[n + 1];     memset(socks, 0, sizeof(socks));     int maxi = -1;     int brc = 0;     for (int i = 1; i <= 2 * n; i++) {       int x;       cin >> x;       if (socks[x] == 0) {         socks[x]++;         brc++;       } else {         socks[x]++;         brc--;       }       if (maxi < brc) {         maxi = brc;       }     }     cout << maxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void Freopen() {     freopen(          title           .in ,          r , stdin);     freopen(          title           .out ,          w , stdout);   }   int read() {     int g = 0, f = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       g = g * 10 + ch -  0 ;       ch = getchar();     }     return g * f;   }   const int N = 1e5 + 5;   const int INF = 1e9 + 1;   struct Seg {     int tag[N << 2], mx[N << 2], cx[N << 2], size[N << 2], ok[N << 2];     long long su[N << 2];     void updata(int v, int w) {       su[v] -= 1ll * ok[v] * size[v] * mx[v];       tag[v] = min(tag[v], w);       mx[v] = min(mx[v], w);       su[v] += 1ll * (ok[v] = 1) * size[v] * mx[v];     }     void down(int v) {       if (!(tag[v] ^ INF)) return void();       updata(v << 1, tag[v]), updata(v << 1 | 1, tag[v]), tag[v] = INF;     }     void up(int v) {       ok[v] = ok[v << 1] & ok[v << 1 | 1];       su[v] = su[v << 1] + su[v << 1 | 1];       mx[v] = max(mx[v << 1], mx[v << 1 | 1]);       cx[v] = max(cx[v << 1], cx[v << 1 | 1]);       if (mx[v << 1] > mx[v << 1 | 1]) cx[v] = max(cx[v], mx[v << 1 | 1]);       if (mx[v << 1] < mx[v << 1 | 1]) cx[v] = max(cx[v], mx[v << 1]);       size[v] = size[v << 1] * (mx[v << 1] == mx[v]) +                 size[v << 1 | 1] * (mx[v << 1 | 1] == mx[v]);     }     void build(int v, int l, int r) {       mx[v] = INF, size[v] = r - l + 1, tag[v] = INF, cx[v] = -INF;       if (l == r) return void();       int mid = l + r >> 1;       build(v << 1, l, mid), build(v << 1 | 1, mid + 1, r);     }     void change(int v, int l, int r, int ql, int qr, int w) {       if (ql <= l && r <= qr) {         if (mx[v] <= w)           return void();         else if (w >= cx[v])           return updata(v, w), void();       }       int mid = l + r >> 1;       down(v);       if (ql <= mid) change(v << 1, l, mid, ql, qr, w);       if (qr > mid) change(v << 1 | 1, mid + 1, r, ql, qr, w);       up(v);     }   } seg[2];   long long query(int v, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       if (seg[0].ok[v] && seg[1].ok[v])         return seg[0].su[v] + seg[1].su[v];       else if (l == r || !seg[0].su[v] || !seg[1].su[v])         return 0;     }     int mid = l + r >> 1;     seg[0].down(v), seg[1].down(v);     if (qr <= mid) return query(v << 1, l, mid, ql, qr);     if (ql > mid) return query(v << 1 | 1, mid + 1, r, ql, qr);     return query(v << 1, l, mid, ql, qr) + query(v << 1 | 1, mid + 1, r, ql, qr);   }   signed main() {     int n = 1e5;     seg[0].build(1, 1, n), seg[1].build(1, 1, n);     for (int T = read(); T--;) {       int opt = read(), l = read(), r = read() - 1, x;       if (opt == 1)         x = read(), seg[x > 0].change(1, 1, n, l, r, abs(x));       else         cout << query(1, 1, n, l, r) <<   n ;     }     return signed();   }
#include <bits/stdc++.h>   using namespace std;   int prime[1000000];   bool status[1000100];   int pos;   void sieve() {     int i, j;     for (i = 0; i < 1000100; i++) {       status[i] = false;     }     int sq = sqrt(1000100);     for (i = 4; i <= 1000100; i += 2) {       status[i] = true;     }     for (i = 3; i <= sq; i += 2) {       if (status[i] == false) {         for (j = 2 * i; j <= 1000100; j += i) {           status[j] = true;         }       }     }     status[1] = true;     pos = 1;     for (int z = 1; z <= 1000100; z++) {       if (status[z] == false) {         prime[pos++] = z;       }     }   }   int main() {     sieve();     long long n;     while (cin >> n) {       long long ans = 1;       for (int i = 1; i < pos; i++) {         if (n == 1) break;         bool f = false;         while (n % prime[i] == 0) {           f = true;           n /= prime[i];         }         if (f) ans *= prime[i];       }       if (n > 1) ans *= n;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<pair<int, int>> res;     string s2;     int n2 = n - 2 * (k - 1);     for (int i = 0; i < 2 * (k - 1); ++i) {       if (i % 2) {         s2.push_back( ) );       } else {         s2.push_back( ( );       }     }     for (int i = 0; i < n2; ++i) {       if (i < n2 / 2) {         s2.push_back( ( );       } else {         s2.push_back( ) );       }     }     for (int i = 0; i < n; ++i) {       if (s[i] != s2[i]) {         for (int j = i + 1; j < n; ++j) {           if (s[j] == s2[i]) {             reverse(s.begin() + i, s.begin() + j + 1);             res.push_back({i, j});             break;           }         }       }     }     cout << res.size() <<   n ;     for (const auto &p : res) {       cout << p.first + 1 <<     << p.second + 1 <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long i, j, k, l, n, m, a, b, u;     cin >> n;     vector<long long> v(n);     map<long long, long long> mp;     long long ans = 0LL;     priority_queue<pair<long long, long long>> pq;     for (i = 0; i < n; i++) {       cin >> v[i];       mp[v[i]]++;     }     unordered_set<long long> st;     for (auto it : mp) {       pq.push({it.second, it.first});     }     map<long long, long long> mp2;     while (!pq.empty()) {       auto p = pq.top();       pq.pop();       if (p.first == 0) continue;       if (st.find(p.first) == st.end()) {         st.insert(p.first);         ans += p.first;       } else {         pq.push({p.first - 1, p.second});       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   int main() {     int m, n;     scanf( %d %d , &n, &m);     if (n == 1) {       if (m == 2) {         printf( 0 n );         printf( 1 1 n );         printf( 1 2 n );         printf( 1 1 n );         return 0;       } else {         printf( 1 n );         printf( 1 %d 1 1 n , m);         for (int i = 1; i <= m; ++i) printf( 1 %d n , i);         printf( 1 1 n );       }     } else if (m == 1) {       if (n == 2) {         printf( 0 n );         printf( 1 1 n );         printf( 2 1 n );         printf( 1 1 n );         return 0;       } else {         printf( 1 n );         printf( %d 1 1 1 n , n);         for (int i = 1; i <= n; ++i) printf( %d 1 n , i);         printf( 1 1 n );       }     } else if (n % 2 == 0) {       printf( 0 n );       for (int i = 1; i <= n; ++i) printf( %d 1 n , i);       bool direita = true;       for (int lin = n; lin >= 1; --lin) {         if (direita) {           for (int j = 2; j <= m; ++j) printf( %d %d n , lin, j);         } else {           for (int j = m; j > 1; --j) printf( %d %d n , lin, j);         }         direita = !direita;       }       printf( 1 1 n );     } else if (m % 2 == 0) {       printf( 0 n );       for (int j = 1; j <= m; ++j) printf( 1 %d n , j);       bool baixo = true;       for (int col = m; col >= 1; --col) {         if (baixo) {           for (int i = 2; i <= n; ++i) printf( %d %d n , i, col);         } else {           for (int i = n; i > 1; --i) printf( %d %d n , i, col);         }         baixo = !baixo;       }       printf( 1 1 n );     } else {       printf( 1 n );       printf( %d %d 1 1 n , n, m);       bool direita = true;       for (int i = 1; i <= n; ++i) {         if (direita) {           for (int j = 1; j <= m; ++j) printf( %d %d n , i, j);         } else {           for (int j = m; j >= 1; --j) printf( %d %d n , i, j);         }         direita = !direita;       }       printf( 1 1 n );     }   }
#include<bits/stdc++.h>   #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL) ;cout.tie(NULL)   using namespace std;      #define ll long long int   #define pb push_back   #define endn   n    #define mp make_pair   #define ss second   #define ff first   #define deb(x) cout << #x <<     << x << endl   #define deb1(x,y) cout<<#x<<   <<x<<  ,  <<#y<<   <<y<<endl   #define deb2(x,y,z) cout<<#x<<   <<x<<  ,  <<#y<<   <<y<<  ,  <<#z<<   <<z<<endl   const long long INF = 1e18;      int small = INT_MIN;   int large = INT_MAX;      void solve() {    int n, k;    cin >> n >> k;    int a[n];    int i = 2, j = n;    a[0] = 1;    int t = 1;       while (k-- && t < n - 1) {     a[t] = j;     t++;     j--;     a[t] = i;     t++;     i++;    }       if (k != -1) {     cout << -1;    }    else {     while (i <= j) {      a[t] = i;      t++;      i++;     }     for (int x : a) {      cout << x <<    ;     }    }    cout << endn;      }      int main() {       fast_cin();       ll T = 1;    cin >> T;    while (T--) solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0;     char s = getchar();     bool w = 0;     while (s <  0  || s >  9 ) {       w |= s ==  - ;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     return w ? -x : x;   }   const long long inf = 1e18;   long long n, m, sx, sy, tim;   struct edge {     long long ne, to, dis;   } e[2100], E[2100000];   struct node {     long long t, c;   } a[2100];   long long head[2100], head1[2100000], tot, num, dis[1100];   bool vis[1100];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       q;   inline void add(long long fr, long long to, long long dis) {     e[++tot].ne = head[fr];     e[tot].to = to;     e[tot].dis = dis;     head[fr] = tot;   }   inline void Add(long long fr, long long to, long long dis) {     E[++num].ne = head1[fr];     E[num].to = to;     E[num].dis = dis;     head1[fr] = num;   }   inline void Dij1(long long s) {     for (long long i = 1; i <= n; i++) {       dis[i] = inf;       vis[i] = 0;     }     dis[s] = 0;     q.push(make_pair(dis[s], s));     while (!q.empty()) {       long long u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (long long i = head[u]; i; i = e[i].ne) {         long long v = e[i].to;         if (dis[v] > dis[u] + e[i].dis && dis[u] + e[i].dis <= a[s].t) {           dis[v] = dis[u] + e[i].dis;           Add(s, v, a[s].c);           if (!vis[v]) q.push(make_pair(dis[v], v));         }       }     }   }   inline void Dij2(long long s) {     for (long long i = 1; i <= n; i++) {       dis[i] = inf;       vis[i] = 0;     }     dis[s] = 0;     q.push(make_pair(dis[s], s));     while (!q.empty()) {       long long u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (long long i = head1[u]; i; i = E[i].ne) {         long long v = E[i].to;         if (dis[v] > dis[u] + E[i].dis) {           dis[v] = dis[u] + E[i].dis;           if (!vis[v]) q.push(make_pair(dis[v], v));         }       }     }   }   signed main() {     n = read();     m = read();     sx = read();     sy = read();     for (long long i = 1; i <= m; i++) {       long long u, v, w;       u = read();       v = read();       w = read();       add(u, v, w);       add(v, u, w);     }     for (long long i = 1; i <= n; i++) a[i].t = read(), a[i].c = read();     for (long long i = 1; i <= n; i++) Dij1(i);     Dij2(sx);     if (dis[sy] != inf)       printf( %I64d n , dis[sy]);     else       printf( -1 n );     return 0;   }