malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, x = 0, m, num;     cin >> n >> k;     map<int, int> mp;     int arr[1000000];     for (i = 0; (i < n) && (x < k); i++) {       cin >> num;       if (mp[num] == 0) {         arr[x] = num;         mp[num] = 1;         x++;       }     }     int j = 0;     for (m = i; m <= (n - 1); m++) {       cin >> num;       if (mp[num] == 1) {         continue;       } else if ((mp[num] == 0) && ((x - j) != k)) {         arr[x] = num;         mp[num] = 1;         x++;       } else {         mp[arr[j]] = 0;         j++;         arr[x] = num;         x++;         mp[num] = 1;       }     }     cout << x - j <<   n ;     for (m = x - 1; m >= j; m--) {       cout << arr[m] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, q;   vector<int> style;   vector<vector<int> > place;   vector<int> base;   vector<vector<int> > t;   void read() {     cin >> n >> k;     style.resize(n + 1);     place.resize(100001);     base.resize(n + 1);     t.resize(n * 4 + 4);     for (int i = 1; i < n + 1; i++) cin >> style[i];     cin >> q;   }   void build(int v, int tl, int tr) {     if (tl == tr) {       t[v] = vector<int>(1, base[tl]);     } else {       int tm = (tl + tr) / 2;       build(v * 2, tl, tm);       build(v * 2 + 1, tm + 1, tr);       merge(t[v * 2].begin(), t[v * 2].end(), t[v * 2 + 1].begin(),             t[v * 2 + 1].end(), back_inserter(t[v]));     }   }   int query(int v, int tl, int tr, int l, int r, int x) {     if (l > r) return 0;     if (tl == l && tr == r) {       vector<int>::iterator pos = lower_bound(t[v].begin(), t[v].end(), x);       return pos - t[v].begin();     } else {       int tm = (tl + tr) / 2;       return (query(v * 2, tl, tm, l, min(tm, r), x) +               query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x));     }   }   int main() {     int x, y, last = 0;     int l, r;     read();     for (int i = 1; i < n + 1; i++) place[style[i]].push_back(i);     for (int i = 1; i < 100001; i++) {       for (int j = 0; j < place[i].size(); j++) {         if (j >= k)           base[place[i][j]] = place[i][j - k];         else           base[place[i][j]] = -1;       }     }     place.clear();     style.clear();     build(1, 1, n);     while (q--) {       cin >> x >> y;       l = ((x + last) % n) + 1;       r = ((y + last) % n) + 1;       if (l > r) swap(l, r);       last = query(1, 1, n, l, r, l);       cout << last << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     char a;     int k = 0;     vector<int> s;     while (1) {       cin >> a >> a;       k++;       if (a ==  + )         s.push_back(1);       else if (a ==  - )         s.push_back(-1);       else         break;     }     int n;     cin >> n;     int plus = 0, minus = 0;     for (int i = 0; i < k - 1; i++) {       if (s[i] == 1)         plus++;       else         minus++;     }     if (minus > n * plus || plus + 1 > n * (minus + 1)) {       cout <<  Impossible  << endl;       return 0;     }     if (plus + 1 > n + minus) {       cout <<  Possible  << endl;       int x = n + n * minus - plus - 1;       if (x > n - 1) {         cout << n;         x -= (n - 1);       } else {         cout << x + 1;         x = 0;       }       for (int i = 0; i < k - 1; i++) {         if (s[i] == 1) {           cout <<   +  ;           if (x > n - 1) {             cout << n;             x -= (n - 1);           } else {             cout << x + 1;             x = 0;           }         } else {           cout <<   -   << n;         }       }       cout <<   =   << n << endl;       return 0;     }     cout <<  Possible  << endl;     int x = n + minus - plus - 1;     if (x > n - 1) {       cout << n;       x -= (n - 1);     } else {       cout << x + 1;       x = 0;     }     for (int i = 0; i < k - 1; i++) {       if (s[i] == 1) {         cout <<   +  ;         if (x > n - 1) {           cout << n;           x -= (n - 1);         } else {           cout << x + 1;           x = 0;         }       } else {         cout <<   - 1 ;       }     }     cout <<   =   << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 545;   int a[MAX_N];   int main() {     int n, minus = 0;     cin >> n;     int sum = 0;     for (int i = (0); i < (int)(2 * n - 1); ++i) {       cin >> a[i];       if (a[i] < 0) {         a[i] = abs(a[i]);         minus++;       }       sum += a[i];     }     sort(a, a + (2 * n) - 1);     if (n % 2 == 0 && minus % 2) sum -= (a[0] * 2);     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, i, ans, arr[100005];     ans = 0;     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 1; i < n; i++) {       if (arr[i] < arr[i - 1]) ans += arr[i - 1] - arr[i];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N_MAX = 1123;   const long long MOD = 998244353;   long long w;   long long h;   long long result = 1;   int main() {     ios_base::sync_with_stdio(0);     cin >> w;     cin >> h;     for (long long i = 1; i <= w; i++) {       for (long long j = 1; j <= h; j++) {         if (i == 1 && j == 1) {           result *= 4;         } else if (i == 1) {           result *= 2;         } else if (j == 1) {           result *= 2;         }         result %= MOD;       }     }     cout << result <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100005];   bool vis[100005];   long long min_val;   void dfs(int v, long long* arr) {     min_val = min(arr[v], min_val);     vis[v] = true;     for (int i = 0; i < g[v].size(); i++) {       int neig = g[v][i];       if (!vis[neig]) {         dfs(neig, arr);       }     }   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n, m, x, y;     cin >> n >> m;     long long* v = new long long[n + 1]();     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     for (int i = 0; i < m; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     long long ans = 0;     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         min_val = LONG_MAX;         dfs(i, v);         ans += min_val;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int ans, n, m, k, a[12];   struct Edge {     int to, t;     Edge() { to = t = 0; }     Edge(int _to, int _t) {       to = _to;       t = _t;     }     bool operator<(const Edge &z) const { return t < z.t; }   };   vector<Edge> vec[N];   int d[N][12][12];   bool vis[12][12][12][12];   inline void dfs(int x) {     if (k + 1 == x) {       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++)           if (vis[i][a[i]][j][a[j]]) return;       ans++;       return;     }     for (int i = 1; i <= x; i++) a[x] = i, dfs(x + 1);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int s, e, t;     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &s, &e, &t), vec[s].push_back(Edge(e, t));     for (int i = 1; i <= n; i++) {       sort(vec[i].begin(), vec[i].end());       for (int j = 0; j < vec[i].size(); j++)         d[vec[i][j].to][vec[i].size()][j + 1]++;     }     for (int i = 1; i <= n; i++)       for (int j = 0; j < vec[i].size(); j++)         for (int t = 1; t <= k; t++)           for (int l = 1; l <= k; l++)             if (d[vec[i][j].to][t][l]) {               if (t ^ vec[i].size())                 vis[vec[i].size()][j + 1][t][l] = 1;               else if (d[vec[i][j].to][t][l] > 1)                 vis[vec[i].size()][j + 1][t][l] = 1;             }     dfs(1);     return printf( %d n , ans), 0;   }
#include <bits/stdc++.h>   using namespace std;   int g[20] = {0,         1, 0,         18, 0,         1800, 0,         670320, 0,                734832000, 0, 890786230, 0,  695720788, 0,    150347555, 0};   int main() {     int n;     cin >> n;     cout << g[n] << endl;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, int> > a;   priority_queue<pair<int, int> > b;   vector<pair<int, int> > A;   vector<pair<int, int> > B;   int main() {     int n, x;     scanf( %d%d , &n, &x);     int x0 = x;     for (int i = 0; i < n; i++) {       int t;       int h, m;       scanf( %d%d%d , &t, &h, &m);       if (t == 0)         A.push_back(pair<int, int>(h, m));       else         B.push_back(pair<int, int>(h, m));     }     int pa = 0, push_back = 0;     sort(A.begin(), A.end());     sort(B.begin(), B.end());     int ans = 0;     while (pa < A.size() && A[pa].first <= x)       a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;     while (push_back < B.size() && B[push_back].first <= x)       b.push(pair<int, int>(B[push_back].second, B[push_back].first)),           push_back++;     int nn = 0;     int cur = 0;     while (nn < 2) {       pair<int, int> k;       if (cur == 0) {         if (a.size() == 0) {           nn++;           continue;         }         k = a.top();         a.pop();       }       if (cur == 1) {         if (b.size() == 0) {           nn++;           continue;         }         k = b.top();         b.pop();       }       x += k.first;       ans++;       while (pa < A.size() && A[pa].first <= x)         a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;       while (push_back < B.size() && B[push_back].first <= x)         b.push(pair<int, int>(B[push_back].second, B[push_back].first)),             push_back++;       cur ^= 1;       nn = 0;     }     int ans2 = 0;     cur = 1;     nn = 0;     while (a.size()) a.pop();     while (b.size()) b.pop();     pa = push_back = 0;     x = x0;     while (pa < A.size() && A[pa].first <= x)       a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;     while (push_back < B.size() && B[push_back].first <= x)       b.push(pair<int, int>(B[push_back].second, B[push_back].first)),           push_back++;     while (nn < 2) {       pair<int, int> k;       if (cur == 0) {         if (a.size() == 0) {           nn++;           continue;         }         k = a.top();         a.pop();       }       if (cur == 1) {         if (b.size() == 0) {           nn++;           continue;         }         k = b.top();         b.pop();       }       x += k.first;       ans2++;       while (pa < A.size() && A[pa].first <= x)         a.push(pair<int, int>(A[pa].second, A[pa].first)), pa++;       while (push_back < B.size() && B[push_back].first <= x)         b.push(pair<int, int>(B[push_back].second, B[push_back].first)),             push_back++;       cur ^= 1;       nn = 0;     }     printf( %d n , max(ans, ans2));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, q, num;     cin >> n >> q;     vector<int> a(n), b(n), c(n);     for (int i = 0; i < n; ++i) cin >> a[i];     b[0] = a[0];     for (int i = 1; i < n; ++i) {       b[i] = max(a[i], b[i - 1]);       if (b[i] == a[i])         c[i - 1] = b[i - 1];       else         c[i - 1] = a[i];     }     while (q--) {       cin >> num;       if (num < n)         cout << b[num - 1] <<     << a[num] << endl;       else         cout << b[n - 1] <<     << c[(num - 1) % (n - 1)] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using uint = unsigned int;   using ll = long long;   using ull = unsigned long long;   template <class T = ll>   constexpr T TEN(int n) {     return (n == 0) ? 1 : 10 * TEN<T>(n - 1);   }   ll calc(string s) {     int n = int(s.size());     if (n == 1) {       if (s[0] ==  9 ) {         return 1989;       } else {         return 1990 + s[0] -  0 ;       }     }     ll u = calc(s.substr(1));     u += TEN(n - 1);     while (true) {       if (u / TEN(n - 1) % 10 == s[0] -  0 ) break;       u += TEN(n - 1);     }     return u;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       s = s.substr(4);       cout << calc(s) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int mn = 0;       for (int i = 1; i <= n; i++) {         long long int temp;         cin >> temp;         mn = max(mn, (temp - i));       }       cout << mn << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int k, a[N], b[N];   char s[N], t[N];   int main() {     cin >> k;     scanf( %s , s + 1);     scanf( %s , t + 1);     for (int i = k; i; i--) {       a[i] = t[i] - s[i];       if (a[i] < 0) {         a[i] += 26;         t[i - 1]--;       }     }     for (int i = 1; i <= k; i++) {       a[i + 1] += (a[i] % 2) * 26;       a[i] /= 2;     }     for (int i = k; i; i--) {       b[i] += s[i] -  a  + a[i];       b[i - 1] += b[i] / 26;       b[i] %= 26;     }     for (int i = 1; i <= k; i++) printf( %c ,  a  + b[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool myfunction(int i, int j) { return (i < j); }   int main() {     int n, a, b, h;     cin >> n >> a >> b;     vector<int> myvector(n);     for (int i = 0; i < n; ++i) {       cin >> h;       myvector.at(i) = h;     }     sort(myvector.begin(), myvector.end(), myfunction);     cout << myvector.at(b) - myvector.at(b - 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 5005;   deque<deque<int> > Painter(mxN);   vector<bool> Painted(mxN);   vector<vector<int> > cnt(mxN, vector<int>(mxN, 0));   int main() {     int n, q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       int l, r;       cin >> l >> r;       for (int j = l; j <= r; j++) {         if ((int)Painter[j].size() < 3) {           Painter[j].push_back(i);         }         Painted[j] = true;       }     }     int total_sections = 0;     for (int i = 1; i <= n; i++) {       total_sections += (Painted[i] == true);     }     for (int i = 1; i <= n; i++) {       if ((int)Painter[i].size() == 3 || (int)Painter[i].size() == 0) {         continue;       }       assert((int)Painter[i].size() < 3);       if ((int)Painter[i].size() == 1) {         for (int j = 0; j < q; j++) {           if (j == Painter[i].back()) {             continue;           }           cnt[Painter[i].back()][j]++;           cnt[j][Painter[i].back()]++;         }       } else {         cnt[Painter[i].back()][Painter[i].front()]++;         cnt[Painter[i].front()][Painter[i].back()]++;       }     }     int Min = 1e9;     for (int i = 0; i < q; i++) {       for (int j = i + 1; j < q; j++) {         Min = min(Min, cnt[i][j]);       }     }     assert(Min != 1e9);     cout << total_sections - Min <<   n ;     return 0;   }
#include <bits/stdc++.h>   const long long int INF = (1e9 + 12312), MOD = 1e9 + 7;   const long double EPS = 0.0000000001;   using namespace std;   vector<pair<long long int, long long int> > a;   pair<long long int, pair<long long int, long long int> > l(long long int x,                                                              long long int y) {     long long int x1, x2, y1, y2;     x1 = a[x].first;     x2 = a[y].first;     y1 = a[x].second;     y2 = a[y].second;     long long int a = y2 - y1;     long long int b = x1 - x2;     long long int c = x2 * y1 - x1 * y2;     return make_pair(a, make_pair(b, c));   }   bool can(long long int x, long long int y) {     auto ff = l(x, y);     long long int a1, b1, c1;     a1 = ff.first;     b1 = ff.second.first;     c1 = ff.second.second;     vector<long long int> rer;     for (long long int i = 0; i < (long long int)a.size(); i++) {       if (a1 * a[i].first + b1 * a[i].second + c1 != 0) {         rer.push_back(i);       }     }     if ((long long int)rer.size() < 3) {       return 1;     }     auto f2 = l(rer[0], rer[1]);     long long int a2, b2, c2;     a2 = f2.first;     b2 = f2.second.first;     c2 = f2.second.second;     for (long long int i = 0; i < (long long int)a.size(); i++) {       if (a1 * a[i].first + b1 * a[i].second + c1 != 0) {         if (a2 * a[i].first + b2 * a[i].second + c2 != 0) {           return 0;         }       }     }     return 1;   }   int main() {     long long int n;     cin >> n;     if (n < 3) {       cout <<  YES n ;       return 0;     }     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       a.push_back(make_pair(x, y));     }     if (can(0, 1)) {       cout <<  YES n ;       return 0;     }     if (can(1, 2)) {       cout <<  YES n ;       return 0;     }     if (can(0, 2)) {       cout <<  YES n ;       return 0;     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 1e18;   vector<char> ops;   void solve(vector<long long> a, int pos) {     if (pos == 3) {       ans = min(ans, a[0]);       return;     }     for (int i = 0; i < (int)(a).size(); ++i) {       for (int j = i + 1; j < (int)(a).size(); ++j) {         long long val = a[i];         if (ops[pos] ==  * ) {           val *= a[j];         } else {           val += a[j];         }         vector<long long> b;         for (int k = 0; k < (int)(a).size(); ++k) {           if (i == k || j == k) {             continue;           }           b.push_back(a[k]);         }         b.push_back(val);         solve(b, pos + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     vector<long long> a(4);     for (int i = 0; i < 4; ++i) {       cin >> a[i];     }     for (int i = 0; i < 3; ++i) {       char c;       cin >> c;       ops.push_back(c);     }     solve(a, 0);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long INF = 9999999999;   double EPSILON = 0.00000001;   int sint(string s) {     int num = 0;     istringstream myStream(s);     (myStream >> num);     return num;   }   string str(int num) {     ostringstream oss;     oss << num;     return oss.str();   }   vector<string> split(string s) {     vector<string> tokens;     stringstream os(s);     string temp;     while (os >> temp) {       tokens.push_back(temp);     }     return tokens;   }   int maxv(vector<int> v) {     int m = -9999999;     for (int i = 0; i < v.size(); i++) m = max(m, v[i]);     return m;   }   int minv(vector<int> v) {     int m = 9999999;     for (int i = 0; i < v.size(); i++) m = min(m, v[i]);     return m;   }   int main() {     long long n;     cin >> n;     long long s = 0;     while (n != 1) {       s += n;       long long root = sqrt(n);       bool found = false;       for (long long r = 2; r <= root; r++) {         if (n % r == 0) {           n /= r;           found = true;           break;         }       }       if (not found) n = 1;     }     cout << s + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[100005];   char notValid[15] = { B ,  C ,  D ,  E ,  F ,  G ,  J ,  K ,                         L ,  N ,  P ,  Q ,  R ,  S ,  Z };   bool valid(char c) {     static int i;     for (i = 0; i < 15; ++i)       if (c == notValid[i]) return false;     return true;   }   bool check(char *s) {     int i;     int len = strlen(s);     int lend2 = len / 2;     for (i = 0; i < lend2; ++i) {       if (!valid(s[i]) || !valid(s[len - i - 1]) || (s[i] != s[len - i - 1]))         return false;     }     if (len & 1) return valid(s[lend2]);     return true;   }   int main(void) {     int i;     while (scanf( %s , str) == 1) {       printf( %s n , check(str) ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mv4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const int mv8[8][2] = {{0, 1}, {0, -1}, {1, 0},  {-1, 0},                          {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   const int inf = (int)1e9;   const char *boo[2] = { NO ,  YES };   const char *inv =  Impossible ;   inline void term(string msg = inv) {     cout << msg << endl;     exit(0);   }   const char *in =  in.txt ;   const char *out =  out.txt ;   struct Point {     long long y, x;     Point(long long y = 0, long long x = 0) : y(y), x(x) {}     Point operator-(const Point &a) { return Point(y - a.y, x - a.x); }   };   inline unsigned long long sq(long long d) { return d * d; }   inline unsigned long long sqdist(const Point &a, const Point &b) {     return sq(a.x - b.x) + sq(a.y - b.y);   }   inline long long dot(const Point &a, const Point &b) {     return a.x * b.x + a.y * b.y;   }   const int MAX = 1000;   int main() {     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     int n;     unsigned long long r = 0;     cin >> n;     vector<Point> v(n);     unordered_map<int, int> dup, ddown;     for (int i = 0; i < n; i++) {       cin >> v[i].x >> v[i].y;       dup[v[i].y - v[i].x]++;       ddown[v[i].y + v[i].x]++;     }     for (auto e : dup) {       unsigned long long t = (e.second * (e.second - 1)) / 2;       r += t;     }     for (auto e : ddown) {       unsigned long long t = (e.second * (e.second - 1)) / 2;       r += t;     }     cout << r <<   n ;     exit(0);   }
#include <bits/stdc++.h>   bool commonDigits(long a, long b) {     bool digits[10] = {0};     bool output(0);     while (a > 0) {       digits[a % 10] = 1;       a /= 10;     }     while (b > 0) {       if (digits[b % 10]) {         output = 1;         break;       };       b /= 10;     }     return output;   }   int main() {     long n(0);     scanf( %ld , &n);     long total(0);     std::vector<long> divisors;     for (long k = 1; k <= sqrt(n); k++) {       if (n % k == 0) {         divisors.push_back(k);         if (n / k > k) {           divisors.push_back(n / k);         }       }     }     for (long k = 0; k < divisors.size(); k++) {       if (commonDigits(n, divisors[k])) {         ++total;       }     }     printf( %ld n , total);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000002;   long long memo[MAXN];   long long cost[MAXN];   int tin[MAXN];   int low[MAXN];   bool in_stack[MAXN];   int Stack[MAXN];   int comp[MAXN];   vector<pair<int, int> > g[MAXN];   vector<pair<int, int> > t[MAXN];   int n, m, s;   int u, v, w;   int SCC, T, top;   void fast_io() {     ios::sync_with_stdio(false);     cin.tie(NULL);   }   long long contrib(int o) {     int lo = 0, hi = o;     int n = -1;     while (lo <= hi) {       int mid = (lo + hi) >> 1;       if (1LL * mid * (mid + 1) <= (o << 1))         n = mid, lo = mid + 1;       else         hi = mid - 1;     }     return 1LL * o * (n + 1) - 1LL * n * (n + 1) * (n + 2) / 6;   }   void tarjan(int u) {     low[u] = tin[u] = ++T;     Stack[top++] = u, in_stack[u] = 1;     for (auto v : g[u]) {       if (!tin[v.first]) tarjan(v.first);       if (in_stack[v.first]) low[u] = min(low[u], low[v.first]);     }     if (tin[u] == low[u]) {       ++SCC;       while (top) {         int v = Stack[--top];         in_stack[v] = 0, comp[v] = SCC;         if (u == v) break;       }     }   }   long long solve(int u) {     if (memo[u] != -1) return memo[u];     long long res = cost[u];     for (auto v : t[u]) {       res = max(res, cost[u] + v.second + solve(v.first));     }     return memo[u] = res;   }   int main() {     fast_io();     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       g[u].push_back(make_pair(v, w));     }     cin >> s;     tarjan(s);     for (int i = 1; i <= n; i++) {       if (!tin[i]) continue;       int u = comp[i];       for (auto v : g[i]) {         int to = comp[v.first];         if (u != to)           t[u].push_back(make_pair(to, v.second));         else           cost[u] += contrib(v.second);       }     }     memset(memo, -1, sizeof(memo));     printf( %lld n , solve(comp[s]));     return 0;   }