malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   typedef struct node {     struct node* b[3];     int flag[3];   } node;   node* root;   vector<int> ans;   int bit[32], bit_n[32];   void calc(int u) {     memset(bit_n, 0, sizeof(bit_n));     memset(bit, 0, sizeof(bit));     int j = 0, num;     for (num = u; num > 0; num = num / 2) bit_n[j++] = num % 2;     for (int i = 0; i < 32; i++) bit[i] = bit_n[31 - i];   }   void insert(int u) {     node* head;     head = root;     calc(u);     for (int i = 0; i < 32; i++) {       if (head->b[bit[i]] == NULL) {         node* temp;         temp = (node*)malloc(sizeof(node));         for (int j = 0; j < 3; j++) temp->b[j] = NULL, temp->flag[j] = 0;         head->b[bit[i]] = temp;       }       head->flag[bit[i]]++;       head = head->b[bit[i]];     }     return;   }   void del(int u) {     node* head;     head = root;     calc(u);     for (int i = 0; i < 32; i++) {       head->flag[bit[i]]--;       head = head->b[bit[i]];     }     return;   }   void search(int u) {     calc(u);     node* head;     head = root;     for (int i = 0; i < 32; i++) {       if (bit[i] == 1) {         if (head->flag[0])           ans.push_back(1), head = head->b[0];         else           ans.push_back(0), head = head->b[1];       } else {         if (head->flag[1])           ans.push_back(1), head = head->b[1];         else           ans.push_back(0), head = head->b[0];       }     }   }   int main() {     root = (node*)malloc(sizeof(node));     for (int i = 0; i < 3; i++) root->b[i] = NULL, root->flag[i] = 0;     int n;     cin >> n;     insert(0);     char a;     int num;     for (int i = 0; i < n; i++) {       int calc = 0;       cin >> a >> num;       if (a ==  + )         insert(num);       else if (a ==  - )         del(num);       else {         ans.clear();         search(num);         for (int i = 0; i < ans.size(); i++) calc += (pow(2, 31 - i) * ans[i]);         cout << calc <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   int n, k, a[201010];   long long f[201010][2];   long long power(long long x, long long p) {     long long res = 1;     while (p) {       if (p & 1) res = res * x % 998244353;       x = x * x % 998244353;       p >>= 1;     }     return res;   }   long long dp(int l, int r, int len) {     if (len == 0) {       if (l == r && l != 0 && r != 0) return 0;       return 1;     }     if (r == 0) {       return (l == 0 ? k : (k - 1)) * power(k - 1, len - 1) % 998244353;     }     for (int i = 0; i <= len; i++) f[i][0] = f[i][1] = 0;     if (l == 0)       f[0][0] = k - 1, f[0][1] = 1, len--;     else if (l == r)       f[0][1] = 1;     else       f[0][0] = 1;     for (int i = 1; i <= len; i++) {       f[i][0] =           (f[i][0] + f[i - 1][0] * (k - 2) + f[i - 1][1] * (k - 1)) % 998244353;       f[i][1] = f[i - 1][0];     }     return f[len][0];   }   int main() {     n = read(), k = read();     long long ans = 1;     for (int i = 1; i <= n; i++) a[i] = read();     int lst = -1;     for (int i = 1; i <= n + 2; i += 2)       if (a[i] != -1)         ans = ans * dp(a[lst], a[i], (i - lst) / 2 - 1) % 998244353, lst = i;     lst = 0;     for (int i = 2; i <= n + 2; i += 2)       if (a[i] != -1)         ans = ans * dp(a[lst], a[i], (i - lst) / 2 - 1) % 998244353, lst = i;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 10;   const long long mod = 1e9 + 7;   struct Dsu {     long long fa[N << 1], d[N << 1];     struct Tmp {       long long x, y, add;     };     stack<Tmp> s;     long long find(long long x) {       while (x != fa[x]) x = fa[x];       return x;     }     void init(long long n) {       while (!s.empty()) s.pop();       for (long long i = 1; i <= n; i++) fa[i] = i, d[i] = 0;     }     void merge(long long x, long long y) {       long long xx = find(x);       long long yy = find(y);       if (xx == yy) return;       if (d[xx] > d[yy]) swap(xx, yy);       s.push((Tmp){xx, yy, d[xx] == d[yy]});       fa[xx] = yy;       d[yy] += (d[xx] == d[yy]);     }     void ret(long long o) {       while (s.size() > o) {         Tmp x = s.top();         fa[x.x] = x.x;         d[x.y] -= x.add;         s.pop();       }     }   } t;   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar();     return x * f;   }   long long c[N];   map<pair<long long, long long>, vector<pair<long long, long long>>> mp;   int main() {     long long n = read(), m = read(), k = read();     for (long long i = 1; i <= n; i++) c[i] = read();     vector<pair<long long, long long>> e(m + 1);     t.init(2 * n);     for (long long i = 1; i <= m; i++) e[i].first = read(), e[i].second = read();     vector<long long> z(k + 1);     for (long long i = 1; i <= m; i++) {       long long u = e[i].first, v = e[i].second;       if (c[u] == c[v]) {         long long x = t.find(u);         long long y = t.find(v);         if (x == y) {           z[c[u]] = 1;         } else {           t.merge(u, v + n);           t.merge(u + n, v);         }       } else {         pair<long long, long long> tmp = {min(c[u], c[v]), max(c[v], c[u])};         mp[tmp].push_back({u, v});       }     }     long long res = 1ll * k * (k - 1) / 2;     long long gg = 0;     for (long long i = 1; i <= k; i++)       if (z[i] == 1) gg++;     res -= (gg) * (gg - 1) / 2 + gg * (k - gg);     for (auto now : mp) {       if (z[now.first.first] || z[now.first.second]) continue;       auto tmp = now.second;       long long o = t.s.size();       for (pair<long long, long long> qwq : tmp) {         long long u = qwq.first;         long long v = qwq.second;         long long x = t.find(u);         long long y = t.find(v);         if (x == y) {           res -= 1;           break;         } else {           t.merge(u, v + n);           t.merge(u + n, v);         }       }       t.ret(o);     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ed[26][26] = {}, pos[26][26] = {};     static char s[200100], t[200100];     scanf( %d%s%s , &n, s, t);     int ans = 0;     for (int i = 0; i < (n); ++i) {       ans += s[i] != t[i];       ed[s[i] -  a ][t[i] -  a ] += 1;       pos[s[i] -  a ][t[i] -  a ] = i + 1;     }     for (int i = 0; i < (26); ++i) {       for (int j = 0; j < (i); ++j) {         if (ed[j][i] && ed[i][j]) {           printf( %d n%d %d n , ans - 2, pos[j][i], pos[i][j]);           return 0;         }       }     }     for (int i = 0; i < (26); ++i) {       for (int j = 0; j < (26); ++j) {         if (j == i) continue;         if (!ed[i][j]) continue;         for (int k = 0; k < (26); ++k) {           if (k != j && ed[j][k]) {             printf( %d n%d %d n , ans - 1, pos[i][j], pos[j][k]);             return 0;           }         }       }     }     printf( %d n%d %d n , ans, -1, -1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int readInt() {     int a;     scanf( %d , &a);     return a;   }   long long readLong() {     long long a;     scanf( %lld , &a);     return a;   }   void readString(char *s) { scanf(  %s , s); }   const int N = 100005;   char s[N];   vector<pair<int, int>> comp;   int f[26];   int dp[N];   void solve() {     int n = readInt();     int m = readInt();     readString(s + 1);     int last = 1;     for (int i = (1); i <= (n); ++i) {       if (s[i] != s[i + 1]) {         comp.emplace_back(s[i] -  a , i - last + 1);         last = i + 1;       }       f[s[i] -  a ]++;     }     long long ans = (int)(comp).size() * (n * 1ll * m - n);     dp[1] = 1;     for (int i = (2); i <= (n); ++i) {       if (s[i] != s[i - 1] && s[i] == s[i - 2])         dp[i] = 1 + dp[i - 1];       else if (s[i] != s[i - 1])         dp[i] = 2;       else         dp[i] = 1;       ans -= dp[i] - 1;     }     printf( %lld , ans);   }   int main() {     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, d;     long long t, v;     double prev = 0;     scanf( %I64d%I64d%I64d , &n, &a, &d);     for (int i = 1; i <= n; i++) {       scanf( %I64d%I64d , &t, &v);       double tt = sqrt((2 * d) / (a * 1.0));       if (tt * a > v) {         tt = v / (a * 1.0) + (d - v * v / (2 * a * 1.0)) / v;       }       tt += t;       if (tt < prev) tt = prev;       printf( %.8lf n , tt);       prev = tt;     }   }
#include <bits/stdc++.h>   using namespace std;   long double x1, x2, y, y2, r1, r2, ab, s = 0, al, be;   const long double pi = acos(-1);   void inp() {     cin >> x1 >> y >> r1;     cin >> x2 >> y2 >> r2;     ab = sqrt((x1 - x2) * (x1 - x2) + (y - y2) * (y - y2));   }   void out() {     if (ab >= (r1 + r2)) {       cout << fixed << setprecision(20) << s;     } else if (ab <= abs(r1 - r2)) {       if (r1 < r2) {         cout << fixed << setprecision(20) << r1 * r1 * pi;       } else {         cout << fixed << setprecision(20) << r2 * r2 * pi;       }     } else {       al = 2.0 * acos((ab * ab - r1 * r1 + r2 * r2) / (2.0 * ab * r2));       be = 2.0 * acos((ab * ab - r2 * r2 + r1 * r1) / (2.0 * ab * r1));       s = be * r1 * r1 - r1 * r1 * sin(be) + al * r2 * r2 - r2 * r2 * sin(al);       s = s / 2.0;       cout << fixed << setprecision(20) << s;     }   }   int main() {     inp();     out();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[2][100100];   int visit[100100];   int v[100100];   int main() {     int i, j;     int n, m;     while (scanf( %d %d , &n, &m) != EOF) {       memset(dp, 0, sizeof(dp));       for (i = 1; i <= n; i++) {         scanf( %d , &v[i]);         if (v[i] < 0) {           dp[0][-v[i]]++;           dp[0][0]++;         } else {           dp[1][v[i]]++;           dp[1][0]++;         }       }       memset(visit, 0, sizeof(visit));       int flag = 0;       for (i = 1; i <= n; i++) {         if (dp[1][i] + dp[0][0] - dp[0][i] == m) {           visit[i] += 1;           flag++;         }       }       for (i = 1; i <= n; i++) {         int now = v[i];         if (now < 0) now = 0 - now;         if (v[i] > 0) {           if (visit[v[i]] != 1)             printf( Lie n );           else if (flag == 1)             printf( Truth n );           else             printf( Not defined n );         } else {           if (visit[-v[i]] == 0)             printf( Truth n );           else if (flag == 1)             printf( Lie n );           else             printf( Not defined n );         }       }     }     return 0;   }
#include <bits/stdc++.h>   int n, a[500005], L[500005], f[500005][22], g[500005][22];   long long ans;   int get(int x, int y) {     if (x < 0) return 0;     int k = (int)log2(y - x + 1);     return L[f[x][k]] <= L[f[y + 1 - (1 << k)][k]] ? f[x][k]                                                    : f[y + 1 - (1 << k)][k];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]), a[n + i] = a[i];     for (int i = 0; i < n + n; i++) L[i] = i - a[i], f[i][0] = i;     for (int j = 0; j < 19; j++)       for (int i = 0; i < n + n - (1 << j); i++)         f[i][j + 1] =             L[f[i][j]] <= L[f[i + (1 << j)][j]] ? f[i][j] : f[i + (1 << j)][j];     for (int i = 0; i < n + n; i++) g[i][0] = get(L[i], i);     for (int j = 0; j < 19; j++)       for (int i = 0; i < n + n; i++) g[i][j + 1] = g[g[i][j]][j];     for (int i = 0; i < n + n; i++)       if (i >= n) {         int x = i;         ans += 1 + (L[i] > i - n + 1);         for (int j = 19; j >= 0; j--)           if (L[g[x][j]] > i - n + 1) x = g[x][j], ans += 1 << j;       }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 4;   int n, q, A[N], P[N], R[N], res[N], S[N * 2];   map<int, int> M;   vector<int> Q[N];   inline void Add(int le, int ri, int val) {     le--;     ri--;     for (le += n, ri += n; le < ri; le >>= 1, ri >>= 1) {       if (le & 1) S[le++] ^= val;       if (ri & 1) S[--ri] ^= val;     }   }   inline int Get(int i) {     int ret = 0;     for (i--, i += n; i; i >>= 1) ret ^= S[i];     return (ret);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]), P[i] = (P[i - 1] ^ A[i]);     scanf( %d , &q);     for (int i = 1, l; i <= q; i++)       scanf( %d%d , &l, &R[i]), Q[l].push_back(i), res[i] = (P[R[i]] ^ P[l - 1]);     for (int i = 1; i <= n; i++) M[A[i]] = n + 1;     for (int i = n; i; i--) {       Add(i, M[A[i]], A[i]);       for (int &id : Q[i]) res[id] ^= Get(R[id]);       M[A[i]] = i;     }     for (int i = 1; i <= q; i++) printf( %d n , res[i]);     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, l, x, y;     set<long long> Set;     while (cin >> n >> l >> x >> y) {       for (int i = 1; i <= n; ++i) {         long long t;         scanf( %I64d , &t);         Set.insert(t);       }       bool checkx = 0;       bool checky = 0;       for (set<long long>::iterator it = Set.begin(); it != Set.end(); it++) {         if (Set.find(*it + x) != Set.end()) {           checkx = 1;         }         if (Set.find(*it + y) != Set.end()) {           checky = 1;         }         if (checkx && checky) {           break;         }       }       if (checkx && checky) {         cout << 0 << endl;         break;       }       if (checkx) {         cout << 1 << endl;         cout << y << endl;         break;       }       if (checky) {         cout << 1 << endl;         cout << x << endl;         break;       }       bool find = 0;       long long ans = 0;       for (set<long long>::iterator it = Set.begin(); it != Set.end(); it++) {         if ((*it + x <= l) && Set.find(*it + x + y) != Set.end()) {           find = 1;           ans = *it + x;           break;         }         if ((*it + x <= l) && Set.find(*it + x - y) != Set.end()) {           find = 1;           ans = *it + x;           break;         }         if ((*it - x >= 0) && Set.find(*it - x + y) != Set.end()) {           find = 1;           ans = *it - x;           break;         }         if ((*it - x >= 0) && Set.find(*it - x - y) != Set.end()) {           find = 1;           ans = *it - x;           break;         }       }       if (find) {         cout << 1 << endl;         cout << ans << endl;         break;       }       cout << 2 << endl;       cout << x <<     << y << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   constexpr long long MOD = 1000000007LL;   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int N, M, K, S;     cin >> N >> M >> K >> S;     vector<pair<long long, long long> > A(N), B(N), C, D;     for (int i = 0; i < (N); ++i) cin >> A[i].first;     for (int i = 0; i < (N); ++i) cin >> B[i].first;     for (int i = 0; i < (M); ++i) {       int com, c;       cin >> com >> c;       if (com == 1)         C.emplace_back(c, i);       else         D.emplace_back(c, i);     }     for (int i = 0; i < (N); ++i) A[i].second = B[i].second = i;     sort((C).begin(), (C).end());     sort((D).begin(), (D).end());     int P = C.size();     int Q = D.size();     vector<long long> E(P + 1), F(Q + 1);     for (int i = 0; i < (P); ++i) {       E[i + 1] = E[i] + C[i].first;     }     for (int i = 0; i < (Q); ++i) {       F[i + 1] = F[i] + D[i].first;     }     vector<pair<long long, long long> > G(N), H(N);     pair<long long, long long> p = {1e9, 1e9}, q = {1e9, 1e9};     for (int i = 0; i < (N); ++i) {       chmin(p, A[i]);       chmin(q, B[i]);       G[i] = p;       H[i] = q;     }     int ng = -1;     int ok = N;     while (ok - ng > 1) {       int mid = (ng + ok) / 2;       long long r = G[mid].first;       long long s = H[mid].first;       bool check = false;       for (int i = 0; i <= K; ++i) {         if (i > P || K - i > Q) continue;         if (E[i] * r + F[K - i] * s <= S) check = true;       }       if (check)         ok = mid;       else         ng = mid;     }     if (ok == N)       cout << -1 <<   n ;     else {       cout << ok + 1 <<   n ;       long long r = G[ok].first;       long long s = H[ok].first;       for (int i = 0; i <= K; ++i) {         if (i > P || K - i > Q) continue;         if (E[i] * r + F[K - i] * s <= S) {           for (int j = 0; j < (i); ++j) {             cout << C[j].second + 1 <<     << G[ok].second + 1 <<   n ;           }           for (int j = 0; j < (K - i); ++j) {             cout << D[j].second + 1 <<     << H[ok].second + 1 <<   n ;           }           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500, INF = 1 << 30;   int nxt[N], a[N][N], n, x, Rank[N][N], now;   char s[10];   queue<int> q;   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     puts( B );     fflush(stdout);     scanf( %s , s);     if (s[0] ==  I ) {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) a[i][j] = -a[i][j];     }     scanf( %d , &x);     if (x > n)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) a[i][j] = -a[i][j];   }   bool cmp(int x, int y) { return a[now][x - n] > a[now][y - n]; }   void prework() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) Rank[i][j] = j + n;       now = i;       sort(Rank[i] + 1, Rank[i] + 1 + n, cmp);       q.push(i);     }     for (int i = 1; i <= n; i++) a[0][i] = a[i][0] = INF;     for (int i = 1; i <= n; i++) nxt[i] = nxt[i + n] = Rank[i][0] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       if (x == 0) continue;       while (nxt[x] == 0) {         int girl = Rank[x][++*Rank[x]];         if (a[x][girl - n] < a[nxt[girl]][girl - n])           nxt[nxt[girl]] = 0, q.push(nxt[girl]), nxt[girl] = x, nxt[x] = girl;       }     }   }   void work() {     prework();     for (int i = 1;; i++) {       if (x == -1 || x == -2) return;       printf( %d n , nxt[x]);       fflush(stdout);       scanf( %d , &x);     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       init();       work();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       int mid = sqrt(n + 0.5);       vector<int> ans;       ans.push_back(0);       for (int i = 1; i <= mid; i++) {         ans.push_back(i);         ans.push_back(n / i);       }       sort(ans.begin(), ans.end());       n = unique(ans.begin(), ans.end()) - ans.begin();       cout << n << endl;       for (int i = 0; i < n; i++) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, n, a, b;     cin >> x >> y >> n;     long double d = 10000000000, t, q;     t = (long double)x / y;     for (int i = 1; i <= n; i++) {       q = abs(t - floor(t * i) / i);       if (q < d) {         a = floor(t * i);         b = i;         d = q;       }       q = abs(t - ceil(t * i) / i);       if (q < d) {         a = ceil(t * i);         b = i;         d = q;       }     }     cout << a <<  /  << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct state {     int x, y, d;     state(){};     state(int _x, int _y, int _d) { x = _x, y = _y, d = _d; };   };   int main() {     int r, c;     int dx[4] = {1, 0, -1, 0};     int dy[4] = {0, 1, 0, -1};     while (cin >> r >> c) {       char temp;       int map[1010][1010];       vector<state> opp;       pair<int, int> start, end;       for (int i = 0; i < r; i++)         for (int j = 0; j < c; j++) {           cin >> temp;           if (temp >  0  && temp <=  9 ) opp.push_back(state(i, j, temp -  0 ));           if (temp ==  S ) start = pair<int, int>(i, j);           if (temp ==  E ) end = pair<int, int>(i, j);           if (temp ==  T )             map[i][j] = -1;           else             map[i][j] = 1222333444;         }       map[end.first][end.second] = 0;       queue<pair<int, int> > next;       next.push(end);       while (!next.empty()) {         pair<int, int> now = next.front();         next.pop();         for (int j = 0; j < 4; j++) {           int tempx = now.first + dx[j];           int tempy = now.second + dy[j];           if (tempx < 0 || tempx > r - 1 || tempy < 0 || tempy > c - 1) continue;           if (map[tempx][tempy] == -1) continue;           if (map[tempx][tempy] == 1222333444) {             map[tempx][tempy] = map[now.first][now.second] + 1;             next.push(pair<int, int>(tempx, tempy));           }         }       }       int sum = 0;       for (int i = 0; i < opp.size(); i++) {         int tempx = opp[i].x;         int tempy = opp[i].y;         if (map[tempx][tempy] <= map[start.first][start.second]) sum += opp[i].d;       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INPUT_MAXCHARS = 1 << 16;   char buffer[INPUT_MAXCHARS];   struct FastReader {     char *p;     FastReader() {       fread(buffer, 1, sizeof buffer, stdin);       p = buffer;     }     int next() {       int remchars = INPUT_MAXCHARS - (p - buffer);       if (remchars < 25) {         memcpy(buffer, p, remchars);         size_t cnt = fread(buffer + remchars, 1, sizeof buffer - remchars, stdin);         if (remchars + cnt < sizeof buffer) {           buffer[remchars + cnt] = 0;         }         p = buffer;       }       while (*p <  0 ) {         ++p;       }       int val = 0;       while (*p >=  0 ) {         val = val * 10 + (*p -  0 );         ++p;       }       return val;     }   };   const int inf = 1234567890;   const int MAXN = 100000;   vector<int> arrivals[MAXN];   int arr_idx[MAXN];   vector<pair<int, int> > adj[MAXN];   int best[MAXN];   bool done[MAXN];   int main() {     FastReader reader;     int n = reader.next();     int m = reader.next();     for (int i = 0; i < m; ++i) {       int a = reader.next();       int b = reader.next();       int c = reader.next();       adj[a - 1].push_back(make_pair(b - 1, c));       adj[b - 1].push_back(make_pair(a - 1, c));     }     for (int i = 0; i < n; ++i) {       int k = reader.next();       arrivals[i].reserve(k + 1);       for (int j = 0; j < k; ++j) {         int t = reader.next();         arrivals[i].push_back(t);       }       arrivals[i].push_back(inf);     }     for (int i = 0; i < n; ++i) {       best[i] = inf;     }     priority_queue<pair<int, int> > PQ;     PQ.push(make_pair(0, 0));     best[0] = 0;     while (!PQ.empty()) {       const pair<int, int> tmp = PQ.top();       PQ.pop();       int t = -tmp.first;       int at = tmp.second;       if (done[at] || best[at] < t) {         continue;       }       done[at] = true;       if (at == n - 1) {         printf( %d n , t);         return 0;       }       while (arrivals[at][arr_idx[at]] < t) {         ++arr_idx[at];       }       if (arrivals[at][arr_idx[at]] == t) {         done[at] = false;         best[at] = t + 1;         PQ.push(make_pair(-t - 1, at));       } else {         for (int i = 0; i < (int)adj[at].size(); ++i) {           const pair<int, int> e = adj[at][i];           if (t + e.second < best[e.first]) {             best[e.first] = t + e.second;             PQ.push(make_pair(-best[e.first], e.first));           }         }       }     }     puts( -1 );     return 0;   }