malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, sum = 0;     string s;     cin >> x;     while (x--) {       cin >> s;       if (s[0] ==  T ) sum += 4;       if (s[0] ==  C ) sum += 6;       if (s[0] ==  O ) sum += 8;       if (s[0] ==  D ) sum += 12;       if (s[0] ==  I ) sum += 20;     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   string Levelcheck(vector<vector<int> > vec) {     int n;     n = vec.size();     if (vec[0][0] < vec[0][1]) {       return  NO ;     }     for (int i = 1; i < n; i++) {       if (vec[i][0] < vec[i][1]) {         return  NO ;       }       if (vec[i][0] < vec[i - 1][0]) {         return  NO ;       }       if (vec[i][1] < vec[i - 1][1]) {         return  NO ;       }       if ((vec[i][0] - vec[i - 1][0]) < (vec[i][1] - vec[i - 1][1])) {         return  NO ;       }     }     return  YES ;   }   int main() {     int t;     cin >> t;     vector<vector<int> > vec;     vector<int> vec1;     vector<string> vec2;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       for (int j = 0; j < n; j++) {         int a;         int b;         cin >> a >> b;         vec1.push_back(a);         vec1.push_back(b);         vec.push_back(vec1);         vec1.clear();       }       string result = Levelcheck(vec);       vec2.push_back(result);       vec.clear();     }     for (int i = 0; i < t; i++) {       cout << vec2[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n{0};     cin >> n;     bool flag = false;     bool flag1 = false;     long long int i{0}, x{0}, rem{0};     for (i = 1; i <= 1000000; i++) {       if (n >= 4 * i && n <= 7 * i) {         x = 4 * i;         rem = n - x;         if ((rem % 3) != 0) {           x = 0;           rem = 0;         } else if (rem % 3 == 0) {           break;         }       }     }     if (x == 0 && rem == 0) i = 0;     if (x == 0) {       cout <<  -1  << endl;     } else {       long long int div = rem / 3;       for (long long int j = 1; j <= i - div; j++) {         cout <<  4 ;       }       for (long long int i = 1; i <= div; i++) {         cout <<  7 ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int r, c, ans = 0;     cin >> r >> c;     vector<vector<long long int> > A(r + 2, vector<long long int>(c + 2));     for (long long int i = 1; i <= r; i++)       for (long long int j = 1; j <= c; j++) cin >> A[i][j];     vector<vector<long long int> > left(A), right(A), up(A), down(A);     for (long long int i = 1; i <= r; i++)       for (long long int j = 1; j <= c; j++) left[i][j] += left[i][j - 1];     for (long long int i = 1; i <= r; i++)       for (long long int j = c; j >= 1; j--) right[i][j] += right[i][j + 1];     for (long long int j = 1; j <= c; j++)       for (long long int i = 1; i <= r; i++) up[i][j] += up[i - 1][j];     for (long long int j = 1; j <= c; j++)       for (long long int i = r; i >= 1; i--) down[i][j] += down[i + 1][j];     for (long long int i = 1; i <= r; i++)       for (long long int j = 1; j <= c; j++)         if (A[i][j] == 0)           ans += (left[i][j - 1] != 0) + (right[i][j + 1] != 0) +                  (up[i - 1][j] != 0) + (down[i + 1][j] != 0);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 100, inf = 1e15;   long long dis[N][N][6], clr[6][6], ans = inf;   queue<pair<int, int> > q[3];   char a[N][N];   bool mark[N][N][6];   pair<int, int> k;   int ki, kj, n, m, x, y;   int xx[] = {0, 1, 0, -1}, yy[] = {1, 0, -1, 0};   bool is_vallid(int x, int y) {     if (x >= 0 && x < n && y >= 0 && y < m) return 1;     return 0;   }   void init() {     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) clr[i][j] = inf;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int c = 0; c < 4; c++) dis[i][j][c] = inf;   }   void bfs(int b) {     while (!q[b].empty()) {       k = q[b].front();       ki = k.first, kj = k.second;       if (a[ki][kj] -  1  != b && a[ki][kj] !=  #  && a[ki][kj] !=  . )         clr[b][a[ki][kj] -  1 ] = min(dis[ki][kj][b], clr[b][a[ki][kj] -  1 ]);       for (int i = 0; i < 4; i++) {         x = ki + xx[i], y = kj + yy[i];         if (is_vallid(x, y) && a[x][y] !=  #  && !mark[x][y][b]) {           q[b].push({x, y});           dis[x][y][b] = dis[ki][kj][b] + 1;           mark[x][y][b] = 1;         }       }       q[b].pop();     }   }   int main() {     init();     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] !=  .  && a[i][j] !=  # ) {           q[a[i][j] -  1 ].push({i, j});           mark[i][j][a[i][j] -  1 ] = 1;           dis[i][j][a[i][j] -  1 ] = 0;         }       }     for (int i = 0; i < 3; i++) bfs(i);     ans = min(min(clr[0][1] + clr[0][2], clr[1][0] + clr[1][2]),               clr[2][0] + clr[2][1]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         ans = min(ans, dis[i][j][0] + dis[i][j][1] + dis[i][j][2]);     if (ans >= inf) {       cout << -1;       return 0;     }     cout << ans - 2;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const long long llINF = 9223372036854775807;   const int INF = 2147483647;   const int maxn = 1e3 + 7;   const int maxm = 1e5 + 7;   const int mod = 1e9 + 7;   int n, m;   int c[maxn], a[maxn];   int main(int argc, char const *argv[]) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     int p = 1, cnt = 0;     for (int i = 1; i <= n; i++) {       if (a[p] >= c[i]) {         cnt++;         p++;       }     }     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   const int N = 100000 + 10;   long long A[N], B[N], L[N];   int n, m, a, b;   std::set<std::pair<long long, int> > dic;   double ans = 1e100;   int ansx, ansy;   double sqr(long long x) { return (double)x * x; }   void Cal(int idx) {     double dis;     long long x = B[idx] * a / b;     std::set<std::pair<long long, int> >::iterator u;     u = dic.lower_bound(std::pair<long long, int>(x, 0));     dis = L[idx];     dis += sqrt(sqr(u->first) + sqr(a));     dis += sqrt(sqr(u->first - B[idx]) + sqr(b - a));     if (dis < ans) {       ans = dis;       ansx = u->second;       ansy = idx;     }     if (u != dic.begin()) {       --u;       dis = L[idx];       dis += sqrt(sqr(u->first) + sqr(a));       dis += sqrt(sqr(u->first - B[idx]) + sqr(b - a));       if (dis < ans) {         ans = dis;         ansx = u->second;         ansy = idx;       }     }     u = dic.upper_bound(std::pair<long long, int>(x, 0));     if (u == dic.end()) return;     dis = L[idx];     dis += sqrt(sqr(u->first) + sqr(a));     dis += sqrt(sqr(u->first - B[idx]) + sqr(b - a));     if (dis < ans) {       ans = dis;       ansx = u->second;       ansy = idx;     }     if (++u != dic.end()) {       dis = L[idx];       dis += sqrt(sqr(u->first) + sqr(a));       dis += sqrt(sqr(u->first - B[idx]) + sqr(b - a));       if (dis < ans) {         ans = dis;         ansx = u->second;         ansy = idx;       }     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 0; i < n; ++i) {       scanf( %I64d , &A[i]);       dic.insert(std::pair<long long, int>(A[i], i + 1));     }     for (int i = 0; i < m; ++i) scanf( %I64d , &B[i]);     for (int i = 0; i < m; ++i) scanf( %I64d , &L[i]);     for (int i = 0; i < m; ++i) Cal(i);     printf( %d %d n , ansx, ansy + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, sum[3] = {0}, j, yo;     cin >> n;     for (i = 0; i < 3; ++i)       for (j = 0; j < n - i; ++j) {         cin >> yo;         sum[i] += yo;       }     cout << sum[0] - sum[1] << endl;     cout << sum[1] - sum[2];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1000001;   bool vis[NMAX];   int p[NMAX];   int go(int u) {     vis[u] = true;     if (vis[p[u]]) return 1;     return 1 + go(p[u]);   }   int sizes[NMAX];   int cap[NMAX];   bitset<NMAX> knp;   int main() {     vector<int> v;     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , p + i);     for (int i = 1; i <= n; i++)       if (!vis[i]) v.push_back(go(i));     int one = 0, two = 0;     for (int c : v) {       if (c % 2 == 0) {         two += c / 2;       } else {         one++;         two += c / 2;       }     }     int s = 0;     if (one + two <= k)       s = n;     else {       if (k <= two)         s = 2 * k;       else         s = 2 * two + (k - two);     }     for (int c : v) sizes[c]++;     const int T = 100;     knp[0] = true;     for (int i = 1; i <= T; i++)       if (sizes[i]) {         memset(cap, -1, sizeof(cap));         for (int j = 0; j <= k; j++)           if (knp[j]) cap[j] = 0;         for (int j = i; j <= k; j++)           if (cap[j] < 0 && cap[j - i] >= 0) cap[j] = cap[j - i] + 1;         for (int j = i; j <= k; j++)           if (cap[j] > 0 && cap[j] <= sizes[i]) knp[j] = true;       }     for (int i = T + 1; i <= k; i++)       for (int j = 0; j < sizes[i]; j++) {         knp |= (knp << i);       }     printf( %d %d , knp[k] ? k : k + 1, s);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 205;   const int MAXM = 55;   struct Point {     int x, y;     double k;     Point(int _x = 0, int _y = 0) { x = _x, y = _y; }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     bool operator<(const Point &b) const { return k < b.k; }     long long operator*(const Point &b) const {       return 1LL * x * b.y - 1LL * y * b.x;     }   } a[MAXN], p[MAXN];   int n, m;   long long ans, mx[MAXM], f[MAXN][MAXN][MAXM];   vector<int> adj[MAXN], rev[MAXN];   queue<int> q[MAXN];   bool Onleft(Point a, Point b, Point c) { return (b - a) * (c - b) > 0; }   void Add(int x, int y) {     while (!q[x].empty() && Onleft(p[q[x].front()], p[x], p[y]))       Add(q[x].front(), y), q[x].pop();     rev[x].push_back(y);     adj[y].push_back(x);     q[y].push(x);   }   void Init(int n) {     for (int i = 1; i <= n; i++) {       adj[i].clear(), rev[i].clear();       while (!q[i].empty()) q[i].pop();     }     for (int i = 1; i < n; i++) Add(i, i + 1);   }   void Dp(int n) {     memset(f, 0, sizeof(f));     for (int i = n; i; i--) {       for (int j = 0; j < m; j++) mx[j] = 0;       reverse(adj[i].begin(), adj[i].end());       int cur = rev[i].size() - 1;       for (auto j : adj[i]) {         f[j][i][1] = p[j] * p[i];         for (int k = 2; k <= m; k++)           if (mx[k - 1]) f[j][i][k] = mx[k - 1] + p[j] * p[i];         for (; ~cur && Onleft(p[j], p[i], p[rev[i][cur]]); cur--)           for (int k = 1; k < m; k++)             if (mx[k] < f[i][rev[i][cur]][k])               mx[k] = f[i][rev[i][cur]][k], f[j][i][k + 1] = mx[k] + p[j] * p[i];       }     }     for (int i = 1; i <= n; i++)       for (auto j : rev[i]) ans = max(ans, f[i][j][m - 2]);   }   void Solve(int idx) {     int cnt = 0;     for (int i = 1; i <= n; i++)       if (i ^ idx)         if (a[i].x > a[idx].x || (a[i].x == a[idx].x && a[i].y > a[idx].y))           p[++cnt] = a[i] - a[idx], p[cnt].k = atan2(p[cnt].y, p[cnt].x);     sort(p + 1, p + cnt + 1);     Init(cnt);     Dp(cnt);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].y);     for (int i = 1; i <= n; i++) Solve(i);     cout << ans / 2 <<  .  << (ans & 1 ?  50  :  00 ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INF = 1000 * 1000 * 1000;   vector<vector<pair<int, int>>> adj;   int mem[80][80][80][80];   int dp(int cur, int closestLeft, int closestRight, int remainingMoves) {     if (remainingMoves == 0) return 0;     if (mem[cur][closestLeft][closestRight][remainingMoves] != -1) {       return mem[cur][closestLeft][closestRight][remainingMoves];     }     int res = INF;     for (auto& nxt : adj[cur])       if (nxt.first != cur) {         if (nxt.first >= closestLeft && nxt.first <= closestRight) {           int newClosestLeft = closestLeft;           if (nxt.first > cur) newClosestLeft = cur + 1;           int newClosestRight = closestRight;           if (nxt.first < cur) newClosestRight = cur - 1;           res = min(res, nxt.second + dp(nxt.first, newClosestLeft,                                          newClosestRight, remainingMoves - 1));         }       }     return mem[cur][closestLeft][closestRight][remainingMoves] = res;   }   int main() {     int n, k, m;     cin >> n >> k >> m;     memset(mem, -1, sizeof(mem));     adj.resize(n);     for (int i = 0; i < m; i++) {       int u;       cin >> u;       u--;       int v;       cin >> v;       v--;       int c;       cin >> c;       adj[u].push_back(make_pair(v, c));     }     int res = INF;     for (int start = 0; start < n; start++) {       int temp = dp(start, 0, n - 1, k - 1);       res = min(res, temp);     }     if (res >= INF)       cout << -1 << endl;     else       cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   void DFS(long long n, long long p, long long d,            vector<pair<long long, long long>> &D, vector<long long> &Pa,            vector<vector<long long>> &G) {     for (long long nn : G[n]) {       if (nn == p) continue;       D.emplace_back(d + 1, nn);       Pa[nn] = n;       DFS(nn, n, d + 1, D, Pa, G);     }   }   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> P(n), H(n);     for (int i = 0; i < n; i++) cin >> P[i];     for (int i = 0; i < n; i++) cin >> H[i];     vector<vector<long long>> G(n, vector<long long>());     vector<long long> Eg(n, 0), Eb(n, 0);     vector<long long> Pa(n, 0);     vector<pair<long long, long long>> D;     for (int i = 0; i < n - 1; i++) {       long long u, v;       cin >> u >> v;       u--;       v--;       G[u].push_back(v);       G[v].push_back(u);     }     DFS(0, -1, 0, D, Pa, G);     sort(D.begin(), D.end());     reverse(D.begin(), D.end());     D.emplace_back(0, 0);     for (const auto &p : D) {       long long node = p.second;       Eb[node] += P[node];       long long h = H[node];       if ((Eg[node] - Eb[node] > h) ||           (abs(Eg[node] - Eb[node]) % 2 != abs(h) % 2) ||           (Eg[node] + Eb[node] < abs(h))) {         cout <<  NO n ;         return;       }       long long x = h - (Eg[node] - Eb[node]);       long long Ag = Eg[node] + x / 2;       long long Ab = Eb[node] - x / 2;       if (Ab < 0) {         cout <<  NO n ;         return;       }       if (node == 0 && Ag + Ab != m) {         cout <<  NO n ;         return;       }       Eg[Pa[node]] += Ag;       Eb[Pa[node]] += Ab;     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   int m1[200010] = {0}, m2[200010] = {0};   map<int, int> pp;   bool d[200010];   int e[100000];   int main() {     int n;     cin >> n;     long long x;     int p = 2;     int tt = 0;     for (int i = 2; i <= 200005; i++) {       m1[i] = m2[i] = 1000000000;     }     for (int i = 1; i <= n; i++) {       cin >> x;       for (int uu = 2; uu * uu <= x; uu++)         if (x % uu == 0) {           int k = 0;           while (x % uu == 0) {             x = x / uu;             k++;           }           if (k != 0) {             if (k < m1[uu]) {               m2[uu] = m1[uu];               m1[uu] = k;             } else if (k < m2[uu]) {               m2[uu] = k;             }             pp[uu]++;           }         }       if (x > 1) {         pp[x]++;         if (1 < m1[x]) {           m2[x] = m1[x];           m1[x] = 1;         } else if (1 < m2[x]) {           m2[x] = 1;         }       }     }     long long sum = 1;     int uu = 1;     while (uu < 200000) {       uu++;       if (pp[uu] < n - 1) continue;       if (pp[uu] == n - 1) {         sum = sum * pow(uu, m1[uu]);       } else         sum = sum * pow(uu, m2[uu]);     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2410;   int n, l, r, a[N];   vector<int> p;   tuple<int, int, int> tmp[2];   vector<tuple<int, int, int>> ans;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1, x; i <= 3 * n; i++) cin >> x, a[x] = 1;     for (int i = 1; i <= 6 * n; i++) p.push_back(i);     for (int i = 1; i <= 2 * n; i++) {       l = 0, r = p.size() - 1;       while (l < r && a[p[l]] == a[p[l + 1]] && a[p[l]] == a[p[l + 2]])         tmp[a[p[l]]] = {p[l], p[l + 1], p[l + 2]}, l += 3;       while (l < r && a[p[r]] == a[p[r - 1]] && a[p[r]] == a[p[r - 2]])         tmp[a[p[r]]] = {p[r - 2], p[r - 1], p[r]}, r -= 3;       if (l < r) {         for (int j = l; j + 2 <= r; j++)           if ((i & 1) == a[p[j]] && (i & 1) == a[p[j + 1]] &&               (i & 1) == a[p[j + 2]]) {             ans.push_back({p[j], p[j + 1], p[j + 2]});             goto next;           }       }       ans.push_back(tmp[i & 1]);     next:       p.erase(find(p.begin(), p.end(), get<0>(ans.back())));       p.erase(find(p.begin(), p.end(), get<1>(ans.back())));       p.erase(find(p.begin(), p.end(), get<2>(ans.back())));     }     for (const auto &it : ans)       cout << get<0>(it) <<     << get<1>(it) <<     << get<2>(it) << endl;   }
#include <bits/stdc++.h>   using namespace std;   string s;   bool atted, dotted, goned;   int cntu, cnth = -1, cntr = -1, cntd = -1;   int main() {     cin >> s;     for (int i = 0; i < ((int)(s).size()); i++) {       if (!atted && s[i] ==  @ )         atted = 1;       else if (atted && !goned && s[i] ==  .  && s[i - 1] !=  .  &&                s[i - 1] !=  @  && cntd <= 16)         dotted = 1, cntd = -1;       else if (atted && !goned && s[i] ==  / )         goned = 1;       else if ((!atted || goned) && s[i] ==  . )         return puts( NO ), 0;       else if (!isalnum(s[i]) && s[i] !=  _ )         return puts( NO ), 0;       if (!atted)         cntu++;       else if (!goned)         cnth++, cntd++;       else         cntr++;     }     if (cntd == 0) return puts( NO ), 0;     if (cntu < 1 || cntu > 16 || cnth < 1 || cnth > 32 || goned && cntr < 1 ||         cntr > 32)       return puts( NO ), 0;     return puts( YES ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long dd[200000], h[200000];   int a, b;   int aaa[100000], bbb[100000];   long long d[200000];   long long mmin[200000][18], mmax[200000][18];   long long xxx(int x) { return h[x] - d[x]; }   long long yyy(int y) { return h[y] + d[y]; }   long long xval(int aa, int bb) {     int llog = 0;     while ((bb + 1 - aa) >= (1 << llog)) {       llog++;     }     llog--;     if (xxx(mmax[aa][llog]) >= xxx(mmax[bb + 1 - (1 << llog)][llog])) {       return mmax[aa][llog];     } else {       return mmax[bb + 1 - (1 << llog)][llog];     }   }   long long yval(int aa, int bb) {     int llog = 0;     while ((bb + 1 - aa) >= (1 << llog)) {       llog++;     }     llog--;     if (yyy(mmin[aa][llog]) >= yyy(mmin[bb + 1 - (1 << llog)][llog])) {       return mmin[aa][llog];     } else {       return mmin[bb + 1 - (1 << llog)][llog];     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> dd[i];     }     for (int i = 0; i < n; i++) {       cin >> h[i];       h[i] *= 2;     }     d[0] = dd[n - 1];     for (int i = 0; i < n - 1; i++) {       d[i + 1] = d[i] + dd[i];     }     for (int i = 0; i < n; i++) {       d[i + n] = d[i] + d[n - 1];       h[i + n] = h[i];     }     n *= 2;     for (int i = 0; i < n; i++) {       mmax[i][0] = i;       mmin[i][0] = i;     }     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 0; i < n; i++) {         mmin[i][j] = mmin[i][j - 1];         if ((i + (1 << (j - 1)) < n) &&             (yyy(mmin[i + (1 << (j - 1))][j - 1]) > yyy(mmin[i][j - 1])))           mmin[i][j] = mmin[i + (1 << (j - 1))][j - 1];         mmax[i][j] = mmax[i][j - 1];         if ((i + (1 << (j - 1)) < n) &&             (xxx(mmax[i + (1 << (j - 1))][j - 1]) > xxx(mmax[i][j - 1])))           mmax[i][j] = mmax[i + (1 << (j - 1))][j - 1];       }     }     for (int i = 0; i < m; i++) {       cin >> aaa[i] >> bbb[i];     }     for (int i = 0; i < m; i++) {       b = aaa[i];       a = bbb[i];       a--;       b--;       a = (a + 1) % (n / 2);       b = (b + n - 1) % (n / 2);       if (a > b) {         b += n / 2;       }       long long r1 = -(1ll << 60);       int xx = xval(a, b);       int yy;       if (xx < b) {         yy = yval(xx + 1, b);         r1 = yyy(yy) + xxx(xx);       }       yy = yval(a, b);       long long r2 = -(1ll << 60);       if (yy > a) {         xx = xval(a, yy - 1);         r2 = yyy(yy) + xxx(xx);       }       cout << max(r1, r2) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int main() {     int n, k, m, t, i, c[N];     scanf( %d%d , &n, &k);     int ans = 0;     while (k--) {       scanf( %d , &m);       for (i = 0; i < m; i++) {         scanf( %d , &c[i]);       }       if (c[0] == 1) {         for (i = 0; i < m; i++) {           if (c[i] != i + 1) break;         }         ans += m - i;         t = i;       } else if (c[0] != 1)         ans += m - 1;     }     ans += n - t;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long res, n, k, d = 0, f, s, moy, mx;   long long t[300003];   bool b = true;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> t[i];     reverse(t, t + n);     f = k - 1;     while (d <= f) {       b = true;       moy = (d + f) / 2;       mx = k - 1;       for (long long i = 0; i < n; i++) {         if (t[i] <= mx)           mx = min(mx, t[i] + moy);         else if ((t[i] + moy) >= k)           mx = min(mx, t[i] + moy - k);         else {           b = false;           break;         }       }       if (b) {         res = moy;         f = moy - 1;       } else         d = moy + 1;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 200000 + 10;   int n, m, k, nv;   vector<pair<int, pair<int, int> > > edge;   vector<pair<int, int> > e[maxn];   int f[maxn];   bool vis[maxn];   long long dis[maxn];   vector<long long> q;   void print(int a[], int n, int st = 0) {     for (int i = 0; i < n; i++) {       if (i != 0) printf(   );       printf( %d , a[i + st]);     }     printf(  n );   }   void init() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       edge.push_back(make_pair(w, make_pair(min(u, v), max(u, v))));     }   }   void doit() {     sort(edge.begin(), edge.end());     memset(f, -1, sizeof(f));     nv = 0;     for (int i = 0; i < min(k, m); i++) {       int u = edge[i].second.first, v = edge[i].second.second, w = edge[i].first;       if (f[u] == -1) f[u] = nv++;       u = f[u];       if (f[v] == -1) f[v] = nv++;       v = f[v];       e[u].push_back(make_pair(v, w));       e[v].push_back(make_pair(u, w));     }     for (int st = 0; st < nv; st++) {       for (int i = 0; i < nv; i++) vis[i] = false;       vis[st] = true;       for (int i = 0; i < nv; i++) dis[i] = -1;       dis[st] = 0;       int cur = st;       while (1) {         for (int i = 0; i < e[cur].size(); i++) {           int v = e[cur][i].first, w = e[cur][i].second;           if (!vis[v] && (dis[v] == -1 || dis[v] > dis[cur] + w)) {             dis[v] = dis[cur] + w;           }         }         long long mn = -1;         for (int i = 0; i < nv; i++) {           if (!vis[i] && (dis[i] != -1 && (mn == -1 || dis[i] < mn))) {             mn = dis[i];             cur = i;           }         }         if (vis[cur]) break;         vis[cur] = true;       }       for (int i = st + 1; i < nv; i++) {         if (vis[i]) q.push_back(dis[i]);       }     }     sort(q.begin(), q.end());     printf( %lld n , q[k - 1]);   }   int main() {     init();     doit();     return 0;   }