malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool used[1001];   char c[1001][3][3], z;   string s, sr, st;   set<char> second;   pair<int, string> pr[100001];   vector<long long> v, vc;   map<string, int> mp;   long long d[1000001];   long long ar[1000001];   long long n, m, b, a, cnt = 1, ans, mn = 99999999999;   bool check(int x, int y) {     bool mon = 0;     if (c[x][1][1] == c[y][1][1] && c[x][1][2] == c[y][1][2] &&         c[x][2][1] == c[y][2][1] && c[x][2][2] == c[y][2][2])       mon = 1;     if (c[x][1][1] == c[y][1][2] && c[x][1][2] == c[y][2][2] &&         c[x][2][2] == c[y][2][1] && c[x][2][1] == c[y][1][1])       mon = 1;     if (c[x][1][1] == c[y][2][2] && c[x][1][2] == c[y][2][1] &&         c[x][2][1] == c[y][1][2] && c[x][2][2] == c[y][1][1])       mon = 1;     if (c[x][1][1] == c[y][2][1] && c[x][2][1] == c[y][2][2] &&         c[x][2][2] == c[y][1][2] && c[x][1][2] == c[y][1][1])       mon = 1;     return mon;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> c[i][1][1] >> c[i][1][2];       cin >> c[i][2][1] >> c[i][2][2];       if (i != n) cin >> z >> z;     }     for (int i = 1; i <= n; i++) {       if (used[i] == 1) continue;       used[i] = 1;       ans++;       for (int j = 1; j <= n; j++) {         if (check(i, j) == 1 && used[j] == 0) used[j] = 1;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long int fibonocci(unsigned long long int n) {     unsigned long long int f, f1, f2, i;     f1 = 1;     f2 = 2;     i = 2;     while (1) {       f = f1 + f2;       if (f > n) {         return i - 1;       }       f1 = f2;       f2 = f;       i++;     }   }   int main() {     unsigned long long int n, i, x;     cin >> n;     if (n == 2) {       cout << 1;       return 0;     }     x = fibonocci(n);     cout << x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int s = 0, f = 0;     register char ch = getchar();     while (!isdigit(ch)) {       f |= (ch ==  - );       ch = getchar();     }     while (isdigit(ch)) {       s = (s << 1) + (s << 3) + (ch ^ 48);       ch = getchar();     }     return f ? -s : s;   }   inline void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   long long a[1005], n, ans;   signed main() {     cin >> n;     for (auto i = 1; i <= n; i += 1) {       cin >> a[i];     }     for (auto i = 1; i <= n; i += 2) {       long long sum = 0;       long long mn = a[i] - 1;       for (auto j = i + 1; j <= n; j += 2) {         sum += a[j - 1];         sum -= a[j];         if (sum < 0) {           ans += min(a[j] + sum + 1, mn + 1);           break;         } else {           ans += min(a[j], max(0LL, mn - sum + 1));           if (j == i + 1) {             mn = min(a[i], sum);           } else {             mn = min(mn, sum);           }         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int h[15][15];   int dist[15][15];   double expect[15][15];   unordered_map<int, pair<int, int> > dist2pos;   int main() {     for (int i = 0; i < 10; i++)       for (int j = 0; j < 10; ++j) cin >> h[i][j];     for (int i = 0; i < 10; ++i)       for (int j = 0; j < 10; ++j) {         if (i % 2 == 0) {           dist[i][j] = i + j + 9 * i;         } else {           dist[i][j] = i + 9 - j + 9 * i;         }         dist2pos[dist[i][j]] = make_pair(i, j);       }     bool left = true;     expect[0][0] = 0.0;     int x = 0, y = 1;     while (true) {       double e = 0.0;       if (dist[x][y] < 6) {         for (int dice = 1; dice <= dist[x][y]; ++dice) {           int xx = dist2pos[dist[x][y] - dice].first;           int yy = dist2pos[dist[x][y] - dice].second;           e += (1.0 / 6.0) * (expect[xx][yy] + 1);         }         e += (6 - dist[x][y]) / 6.0;         e /= (dist[x][y] / 6.0);         expect[x][y] = e;       } else {         for (int dice = 1; dice <= min(6, dist[x][y]); ++dice) {           int xx = dist2pos[dist[x][y] - dice].first;           int yy = dist2pos[dist[x][y] - dice].second;           double next_e;           if (h[xx][yy] == 0) {             next_e = expect[xx][yy];           } else {             int xxx = xx - h[xx][yy];             int yyy = yy;             next_e = min(expect[xx][yy], expect[xxx][yyy]);           }           e = e + (1.0 / 6.0) * next_e;         }         e += 1.0;         expect[x][y] = e;       }       if (x == 9 && y == 0) break;       auto p = dist2pos[dist[x][y] + 1];       x = p.first;       y = p.second;     }     cout << fixed << setprecision(6) << expect[9][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, sum = 0;       cin >> n;       string arr;       string brr;       cin >> arr >> brr;       for (int i = 0; i < n; i++) {         if (brr[i] ==  0 ) {           continue;         }         if (arr[i] ==  0 ) {           sum++;           arr[i] =  2 ;           continue;         }         if (i == 0 && arr[1] ==  1 ) {           sum++;           arr[1] =  2 ;           continue;         }         if (i == 0 && arr[1] !=  1 ) {           continue;         }         if (arr[i - 1] ==  1 ) {           sum++;           arr[i - 1] =  2 ;           continue;         }         if (i == n - 1) {           break;         }         if (arr[i + 1] ==  1 ) {           sum++;           arr[i + 1] =  2 ;         }       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nums[200];   int arr[200][200];   int counter;   int line;   int main() {     int n;     cin >> n;     line = 0;     counter = 0;     int sum = 0;     int nums[200];     int arr[200][200];     memset(arr, 0, sizeof arr);     memset(nums, 0, sizeof nums);     while (sum + (++counter) <= n) {       sum += counter;     }     cout << counter << endl;     counter--;     int i;     int ct = counter;     int j;     arr[0][0] = 1;     arr[1][0] = 1;     for (i = 1; i <= counter; i++) {       arr[i][i] = arr[i - 1][i - 1] + ct;       ct = ct - 1;       arr[i + 1][i] = arr[i][i];     }     for (i = 0; i <= counter; i++) {       for (int j = i + 1; j < counter; j++) {         arr[i][j] = arr[i][j - 1] + 1;         arr[j + 1][i] = arr[i][j];       }     }     for (i = 0; i <= counter; i++) {       for (j = 0; j < counter; j++) {         cout << arr[i][j] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> A[300005];   long long B[300005];   int main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; ++i) {       scanf( %lld , &A[i].first);       A[i].second = i;     }     sort(A + 1, A + n + 1);     long long val = 1;     for (long long i = 1; i <= n; ++i) {       val = max(val, A[i].first);       B[A[i].second] = val;       val++;     }     for (long long i = 1; i <= n; ++i) {       printf( %lld  , B[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T, n;     cin >> T;     while (T--) {       cin >> n;       long long ans = 0;       for (int i = 1; i <= n / 2; i++) {         ans += i * 1ll * i;       }       cout << ans * 8 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   #pragma GCC optimize( O3 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1000000007LL * 1000000007LL;   const long double EPS = 1e-9;   const int SIZE = 3010;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   struct fenwick {     int n;     vector<int> a;     fenwick() {}     fenwick(int n_) {       n = n_;       a.resize(n, 0);     }     int query(int r) {       if (r < 0) return 0;       int sum = 0;       for (int i = r; i >= 0; i = (i & (i + 1)) - 1) sum += a[i];       return sum;     }     int query(int l, int r) { return query(r) - query(l - 1); }     void increase(int ind, int val = 1) {       for (int i = ind; i < n; i = i | (i + 1)) a[i] += val;     }   };   int a[SIZE][SIZE], n, m;   int zl[SIZE][SIZE], zr[SIZE][SIZE], zld[SIZE][SIZE];   int get_num_diag(int i, int j) {     int num = i + j;     return num;   }   vector<vector<pair<int, int> > > endColumn;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> n >> m;     endColumn.resize(n + m + 10);     for (int i = 1; i <= n; ++i) {       cin >> s;       for (int j = 1; j <= m; ++j) {         a[i][j] = s[j - 1] ==  z ;         if (a[i][j]) zl[i][j] = a[i][j] + zl[i][j - 1];       }     }     for (int i = n; i >= 1; --i) {       for (int j = m; j >= 1; --j) {         if (a[i][j]) {           zr[i][j] = a[i][j] + zr[i][j + 1];           zld[i][j] = a[i][j] + zld[i + 1][j - 1];           endColumn[j + zr[i][j] - 1].push_back({i, j});         }       }     }     vector<fenwick> f(n + m + 10, fenwick(n + 10));     long long ans = 0;     for (int j = m; j >= 1; --j) {       for (auto& j : endColumn[j]) {         int i2 = j.first, j2 = j.second;         f[i2 + j2].increase(i2);       }       for (int i = 1; i <= n; ++i) {         if (!a[i][j]) continue;         int len = min(zl[i][j], zld[i][j]) - 1;         long long rs = f[i + j].query(i, i + len);         ans += rs;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   std::string input() {     static char buf[1000];     scanf( %s , buf);     return std::string(buf);   }   int main() {     int inv[5] = {0, 1, 3, 2, 4};     int n, m;     std::cin >> n >> m;     static int a[500][1000];     for (int i = 0; i < m; i++) {       a[i][i + n] = 1;     }     for (int i = 0; i < n; i++) {       std::string s = input();       for (int j = 0; j < m; j++) {         a[j][i] = s[j] -  a ;       }     }     const int h = m;     const int w = n + m;     int r = 0;     for (int j = 0; j < n && r < h; j++) {       int p = r;       for (int i = r; i < h; i++) {         if (a[i][j] != 0) {           p = i;           break;         }       }       std::swap(a[p], a[r]);       if (a[r][j] == 0) continue;       for (int jj = j + 1; jj < w; jj++) {         a[r][jj] = a[r][jj] * inv[a[r][j]] % 5;       }       a[r][j] = 1;       for (int ii = 0; ii < h; ii++) {         if (ii != r) {           for (int jj = j + 1; jj < w; jj++) {             a[ii][jj] += 2500 - a[ii][j] * a[r][jj];             a[ii][jj] %= 5;           }           a[ii][j] = 0;         }       }       r++;     }     int q;     std::cin >> q;     while (q--) {       std::string b = input();       std::vector<int> v(m);       for (int i = 0; i < m; i++) {         v[i] = b[i] -  a ;       }       std::vector<int> u(m);       for (int i = 0; i < m; i++) {         for (int j = 0; j < m; j++) {           u[i] += a[i][n + j] * v[j];         }         u[i] %= 5;       }       bool any = false;       for (int i = r; i < m; i++) {         if (u[i] != 0) {           any = true;         }       }       constexpr long long MOD2 = 1e9 + 7;       long long ans = 1;       for (int i = r; i < n; i++) {         ans *= 5;         ans %= MOD2;       }       if (any) {         puts( 0 );         continue;       }       printf( %d n , (int)ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const int mod = 1000000007;   const int sze = 100005;   int main() {     long long n;     char ch;     scanf( %I64d%c , &n, &ch);     bool flag = true;     long long term;     if (((n + 3) % 4) == 0) {       term = (n + 3) / 4;     } else if (((n + 2) % 4) == 0) {       term = (n + 2) / 4;       flag = false;     } else if (((n + 1) % 4) == 0) {       term = (n + 1) / 4;     } else if (((n) % 4) == 0) {       term = (n) / 4;       flag = false;     }     long long ans;     ans = (term - 1) * 16;     if (flag == false) {       ans = ans + 7;     }     if (ch ==  f ) {       ans = ans + 1;     } else if (ch ==  e ) {       ans = ans + 2;     } else if (ch ==  d ) {       ans = ans + 3;     } else if (ch ==  a ) {       ans = ans + 4;     } else if (ch ==  b ) {       ans = ans + 5;     } else {       ans = ans + 6;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using ll = long long int;   using namespace std;   int main() {     ll t;     cin >> t;     while (t--) {       ll p, q;       cin >> p >> q;       if (p % q != 0)         cout << p <<   n ;       else {         ll x = 1;         for (ll i = 1; i <= sqrt(q); i++) {           if (q % i == 0) {             ll pnew = p;             while (i != 1 && pnew % i == 0) {               pnew = pnew / i;               if (pnew % q != 0) {                 x = max(x, pnew);                 break;               }             }             pnew = p;             while (pnew % (q / i) == 0) {               pnew = pnew / (q / i);               if (pnew % q != 0) {                 x = max(x, pnew);                 break;               }             }           }         }         cout << x <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   char a[105][105];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         cin >> a[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int k = 1; k <= 2; k++) {         for (int j = 1; j <= m; j++) {           cout << a[j][i] << a[j][i];         }         cout << endl;       }     }     return 0;   }
// Problem: A. Puzzle From the Future   // Contest: Codeforces - Codeforces Round #696 (Div. 2)   // URL: https://codeforces.ml/contest/1474/problem/A   // Memory Limit: 256 MB   // Time Limit: 1000 ms   //    // Powered by CP Editor (https://cpeditor.org)      #define _CRT_SECURE_NO_WARNINGS   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define forn(i,x,n) for(int i = x;i <= n;++i)       const int N = 1e5+7;   char s[N],ans[N];      int main()   {       int T;scanf( %d ,&T);       while(T--)       {     int n;scanf( %d ,&n);     scanf( %s ,s + 1);     int last = -1;     forn(i,1,n)     {      int c = s[i] -  0 ;      if(c + 1 == last) ans[i] =  0 ,last = c;      else ans[i] =  1 ,last = c + 1;     }     forn(i,1,n) printf( %c ,ans[i]);     puts(  );       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Q = 100100, rt = 223, inf = 1 << 29;   int ans[Q], todo[Q];   pair<int, int> look[Q];   int a[Q], b[Q];   string s;   unordered_map<int, unordered_set<int>> post;   map<pair<int, int>, int> ans2;   unordered_map<int, vector<int>> matches;   int f(int x, int xs, int y, int ys) { return max(x + xs, y + ys) - min(x, y); }   int S[100000][5];   map<string, int> intern;   int interned_size[500000];   int cnt = 1;   int get(const string& s) {     auto it = intern.find(s);     if (it == end(intern)) {       interned_size[cnt] = s.size();       return intern[s] = cnt++;     }     return it->second;   }   int brute(int a, int b) {     int res = inf;     vector<int>&ma = matches[a], &mb = matches[b];     for (int i = 0; i < ma.size(); ++i) {       int j = lower_bound(begin(mb), end(mb), ma[i]) - begin(mb);       if (j < mb.size())         res = min(res, f(ma[i], interned_size[a], mb[j], interned_size[b]));     }     return res;   }   int main() {     cin >> s;     for (int i = 0; i < s.size(); ++i) {       for (int w = 1; w <= 4; ++w) {         S[i][w] = get(s.substr(i, w));         matches[S[i][w]].push_back(i);       }     }     int q;     cin >> q;     fill(ans, ans + q, inf);     for (int i = 0; i < q; ++i) {       string as, bs;       cin >> as >> bs;       int a = get(as), b = get(bs);       if (max(matches[a].size(), matches[b].size()) < rt) {         ans[i] = min(brute(a, b), brute(b, a));       } else {         if (matches[a].size() < matches[b].size()) swap(a, b);         post[a].insert(b);         look[i] = make_pair(a, b);         todo[i] = 1;       }     }     for (auto& it : post) {       const int a = it.first;       auto& m = it.second;       int last = matches[a][0];       for (int i = last; i < s.size(); ++i) {         for (int w = 1; w <= 4; ++w)           if (S[i][w] == a) last = i;         for (int w = 1; w <= 4; ++w) {           int b = S[i][w];           if (m.find(b) == end(m)) continue;           auto st = make_pair(a, b);           int sol = f(last, interned_size[a], i, interned_size[b]);           auto fi = ans2.find(st);           if (fi == end(ans2) || sol < fi->second) ans2[st] = sol;         }       }       last = matches[a].back();       for (int i = last; i >= 0; --i) {         for (int w = 1; w <= 4; ++w)           if (S[i][w] == a) last = i;         for (int w = 1; w <= 4; ++w) {           int b = S[i][w];           if (m.find(b) == end(m)) continue;           auto st = make_pair(a, b);           int sol = f(last, interned_size[a], i, interned_size[b]);           auto fi = ans2.find(st);           if (fi == end(ans2) || sol < fi->second) ans2[st] = sol;         }       }     }     for (int i = 0; i < q; ++i) {       if (todo[i]) ans[i] = ans2.find(look[i]) != end(ans2) ? ans2[look[i]] : inf;       cout << (ans[i] == inf ? -1 : ans[i]) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 7E5 + 10;   const int BASE = 1E6 + 3;   int n, p;   long long f[MAX];   long long power(int x, int n) {     if (n == 0) return 1;     long long tmp = power(x, n / 2);     tmp = tmp * tmp;     if (n % 2) tmp = tmp * x;     tmp %= BASE;     return tmp;   }   long long C(int k, int n) {     return f[n] * power((f[n - k] * f[k]) % BASE, BASE - 2);   }   void init() {     f[0] = 1;     for (int i = 1; i < n + p; i++) f[i] = (f[i - 1] * i) % BASE;   }   int main() {     scanf( %d%d , &n, &p);     init();     long long res = 0;     for (int i = 1; i <= n; i++) res = (res + C(p - 1, i + p - 1)) % BASE;     printf( %I64d , res);   }
#include <bits/stdc++.h>   using namespace std;   long long int diff(long long int x, long long int y) {     if (x > y) {       return x - y;     } else {       return y - x;     }   }   int main() {     long long int n;     cin >> n;     long long int arr[n];     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }     long long int count = 0;     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       if (arr[i] == 1) {         count++;         if (count > ans) {           ans = count;         }       } else {         count = 0;       }     }     if (count != 0) {       for (int i = 0; i < n; i++) {         if (arr[i] == 1) {           count++;           if (count > ans) {             ans = count;           }         } else {           break;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<unsigned int> black[33], white[33];   unsigned int masks[33];   string parseipB(unsigned int x, int mask) {     string s =   ;     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < 8; ++j) {         s += to_string(1 & x >> 8 * i + j);       }       if (i != 3) s +=  . ;     }     s +=  /  + to_string(mask);     return s;   }   string parseip(unsigned int x, int mask) {     string s =   ;     for (int i = 0; i < 4; ++i) {       int val = 0;       for (int j = 7; j >= 0; --j) {         val += (1 & x >> 8 * i + j) << 7 - j;       }       s += to_string(val);       if (i != 3) s +=  . ;     }     s +=  /  + to_string(mask);     return s;   }   int main() {     masks[0] = 0;     for (int i = 1; i < 33; ++i) {       masks[i] = masks[i - 1] | (1 << (i - 1));     }     int n;     scanf( %d n , &n);     bool hasblacks = false, haswhites = false;     for (int i = 0; i < n; ++i) {       char sign, sub;       int arr[4];       int mask;       scanf( %c%d.%d.%d.%d , &sign, &arr[0], &arr[1], &arr[2], &arr[3]);       scanf( %c , &sub);       if (sub ==  / ) {         scanf( %d n , &mask);       } else {         mask = 32;       }       unsigned int val = 0;       for (int j = 0; j < 4; ++j) {         unsigned int oct = 0;         for (int k = 7; k >= 0; --k) {           oct += (1 & arr[j] >> 7 - k) << k;         }         val += (oct << (8 * j));       }       if (sign ==  - ) {         hasblacks = true;         black[mask].insert(val);       } else {         haswhites = true;         white[mask].insert(val);       }     }     if (hasblacks && !haswhites) {       cout <<  1 n0.0.0.0/0 n ;       return 0;     }     if (!hasblacks && haswhites) {       cout <<  0 n ;       return 0;     }     bool ok = true;     for (int i = 32; i >= 0; --i) {       for (unsigned int x : white[i]) {         for (int j = 32; j >= 0; --j) {           if (black[j].count(masks[j] & x) != 0) {             ok = false;             break;           }         }       }       for (unsigned int x : black[i]) {         for (int j = 32; j >= 0; --j) {           if (white[j].count(masks[j] & x) != 0) {             ok = false;             break;           }         }       }     }     if (!ok) {       cout <<  -1 n ;       return 0;     }     vector<pair<unsigned int, unsigned int> > ans;     for (int i = 32; i > 0; --i) {       for (unsigned int x : white[i]) {         white[i - 1].insert(masks[i - 1] & x);       }       for (unsigned int x : black[i]) {         bool shift = white[i].count(x ^ (1 << i - 1)) == 0;         if (shift) {           black[i - 1].insert(masks[i - 1] & x);         } else {           ans.push_back(pair<unsigned int, unsigned int>(x, i));         }       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); ++i) {       unsigned int val = ans[i].first;       int mask = ans[i].second;       cout << parseip(val, mask) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 1e6 + 9;   int n, m, k;   long long tr[sz], tr_sum, tr_cnt;   long long ret[sz], ret_sum, ret_cnt;   int d, first, t, c;   vector<pair<pair<int, int>, pair<int, int>>> v;   vector<pair<long long, long long>> home;   long long home_ans[sz];   long long ans = 1e18;   int days[sz];   int main() {     cin >> n >> m >> k;     for (int i = 0; i < m; ++i) {       cin >> d >> first >> t >> c;       v.push_back(make_pair(make_pair(d, first), make_pair(t, c)));     }     sort(v.begin(), v.end());     for (int i = v.size() - 1; i >= 0; i--) {       d = v[i].first.first;       first = v[i].first.second;       t = v[i].second.first;       c = v[i].second.second;       if (first) continue;       if (!ret[t]) {         ret[t] = c;         ret_sum += c;         ret_cnt++;       } else if (ret[t] > c) {         ret_sum -= ret[t];         ret[t] = c;         ret_sum += c;       }       if (ret_cnt == n) home.push_back(make_pair(d, ret_sum));     }     sort(home.begin(), home.end());     int tmp = 0;     for (auto u : home) days[tmp++] = u.first;     for (int i = home.size() - 1; i >= 0; i--) {       if (i == home.size() - 1)         home_ans[i] = home[i].second;       else         home_ans[i] = min(home_ans[i + 1], home[i].second);     }     for (int i = 0; i < v.size(); ++i) {       d = v[i].first.first;       first = v[i].first.second;       t = v[i].second.first;       c = v[i].second.second;       if (t) continue;       if (!tr[first]) {         tr[first] = c;         tr_sum += c;         tr_cnt++;       } else if (tr[first] > c) {         tr_sum -= tr[first];         tr[first] = c;         tr_sum += c;       }       if (tr_cnt == n) {         int pos = lower_bound(days, days + home.size(), d + 1 + k) - days;         if (pos >= home.size()) continue;         ans = min(ans, tr_sum + home_ans[pos]);       }     }     if (ans == 1e18)       cout << -1;     else       cout << ans;     return 0;   }