malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline long long Calc(const int &x) {     long long res = 0;     for (long long i = 1; i <= x; i *= 10) res += x - i + 1;     return res;   }   inline long long CalcSum(const int &x) {     long long res = 0;     for (long long i = 1; i <= x; i *= 10)       res += 1ll * (x - i + 1) * (x - i + 2) / 2;     return res;   }   inline int Pos(const int &x, const int &k) {     stringstream ss;     ss << x;     string s;     ss >> s;     return s[k - 1] -  0 ;   }   inline int Solve(long long k) {     int l = 1, r = 1000000000;     while (l <= r) {       int mid = (l + r) / 2;       if (CalcSum(mid) >= k)         r = mid - 1;       else         l = mid + 1;     }     k = k - CalcSum(r);     int block = l;     l = 1;     r = block;     while (l <= r) {       int mid = (l + r) / 2;       if (Calc(mid) >= k)         r = mid - 1;       else         l = mid + 1;     }     return Pos(l, k - Calc(r));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q;     cin >> q;     while (q--) {       long long k;       cin >> k;       cout << Solve(k) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int INF = 1e9;   using namespace std;   void dfs(int v, int p, vector<vector<int> > &graph, vector<int> &sz) {     sz[v] = 1;     for (auto u : graph[v])       if (u != p) {         dfs(u, v, graph, sz);         sz[v] += sz[u];       }   }   void dfs(int v, int p, vector<vector<int> > &graph, vector<int> &c, int C) {     c[v] = C;     for (auto u : graph[v])       if (u != p) {         dfs(u, v, graph, c, C);       }   }   signed main() {     int n;     cin >> n;     vector<vector<int> > graph(n);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       graph[a].push_back(b);       graph[b].push_back(a);     }     vector<int> sz(n);     dfs(0, 0, graph, sz);     vector<int> cen;     long long ans = 0;     for (int i = 0; i < n; i++) {       if ((n - sz[i]) * 2 <= n) {         int t = 1;         for (auto u : graph[i]) {           if (sz[u] < sz[i]) {             if (2 * sz[u] <= n) continue;             t = 0;           }         }         if (t) cen.push_back(i);       }     }     for (int i = 0; i < n; i++) {       ans += 2 * min(sz[i], n - sz[i]);     }     cout << ans <<   n ;     if (cen.size() == 2) {       int v = cen[0], u = cen[1];       vector<int> c(n);       dfs(v, u, graph, c, 0);       dfs(u, v, graph, c, 1);       vector<int> p0, p1;       for (int i = 0; i < n; i++) {         if (c[i] == 0) p0.push_back(i);         if (c[i] == 1) p1.push_back(i);       }       vector<int> ans(n);       for (int i = 0; i < n / 2; i++) {         ans[p0[i]] = p1[i];         ans[p1[i]] = p0[i];       }       for (int i = 0; i < n; i++) {         cout << ans[i] + 1 <<    ;       }       return 0;     } else {       dfs(cen[0], cen[0], graph, sz);       int C = 0, idC = 0;       vector<int> c(n);       c[cen[0]] = -1;       int maxsz = 0;       for (auto u : graph[cen[0]]) {         dfs(u, cen[0], graph, c, C);         maxsz = max(maxsz, sz[u]);         if (maxsz == sz[u]) idC = C;         C++;       }       vector<pair<int, int> > q;       for (int i = 0; i < n; i++) {         if (i != cen[0] && c[i] != idC) q.push_back({c[i], i});       }       for (int i = 0; i < n; i++) {         if (i != cen[0] && c[i] == idC) q.push_back({INF, i});       }       q.push_back({INF + 1, cen[0]});       sort((q).begin(), (q).end());       vector<int> ans(n);       for (int i = 0; i < n; i++) {         ans[q[i].second] = q[(i + maxsz) % q.size()].second;       }       for (int i = 0; i < n; i++) {         assert(c[ans[i]] != c[i]);         cout << ans[i] + 1 <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   int n;   double a[MAXN], b[4], t;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     b[3] = 1;     for (int i = 1; i <= n; i++) {       cin >> t;       b[0] += t;       b[1]++;       if (b[1] * b[2] <= b[0] * b[3]) b[2] = b[0], b[3] = b[1];     }     cout << fixed << setprecision(10) << b[2] / b[3] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[101][1001];   int n, m;   int g[101][101];   vector<int> col[1001];   set<int> row[101];   bool ans[101][101];   int main() {     scanf( %d , &n), scanf( %d , &m);     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d , &x), scanf( %d , &y);       g[x][y] = g[y][x] = 1;     }     for (int i = 1; i <= n; ++i) g[i][i] = true;     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (g[i][j] && !ans[i][j]) {           for (int k = 0; k < 1001; ++k)             if (col[k].size() == 0) {               arr[i][k] = i;               arr[j][k] = j;               col[k].push_back(i), col[k].push_back(j);               break;             } else {               bool ok = true;               for (int l = 0; l < col[k].size(); ++l) {                 int cur = col[k][l];                 if (!g[cur][i] || !g[cur][j]) {                   ok = false;                   break;                 }               }               if (ok) {                 arr[i][k] = i;                 arr[j][k] = j;                 for (int l = 0; l < col[k].size(); ++l) {                   int cur = col[k][l];                   ans[cur][i] = ans[i][cur] = ans[j][cur] = ans[cur][j] = true;                 }                 col[k].push_back(i), col[k].push_back(j);                 break;               }             }           ans[i][j] = true;           ans[j][i] = true;         }       }     }     for (int i = 0; i < 1001; ++i)       for (int j = 0; j < col[i].size(); ++j) row[col[i][j]].insert(i);     for (int i = 1; i < 101; ++i)       if (row[i].size() == 0) {         for (int j = 0; j < 1001; ++j)           if (col[j].size() == 0) {             col[j].push_back(i);             row[i].insert(j);             break;           }       }     for (int i = 1; i <= n; ++i) {       printf( %d n , row[i].size());       for (set<int>::iterator it = row[i].begin(); it != row[i].end(); ++it)         printf( %d %d n , i, (*it) + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p1, p2;     cin >> n;     cin >> p1;     int a1[p1];     for (int i = 0; i < p1; i++) cin >> a1[i];     cin >> p2;     int a2[p2];     for (int i = 0; i < p2; i++) cin >> a2[i];     sort(a1, a1 + p1);     sort(a2, a2 + p2);     vector<int>::iterator it;     vector<int> res(100);     it = set_union(a1, a1 + p1, a2, a2 + p2, res.begin());     res.resize(it - res.begin());     if (res.size() == n)       cout <<  I become the guy. ;     else       cout <<  Oh, my keyboard! ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int v[5], p[5];   int cnt[5], add[5];   int getMaxScr(int acc, int tot) {     int MaxScr;     for (int i = 0; i < 6; i++) {       int t = 1 << i;       if (tot >= t * acc) MaxScr = (i + 1) * 500;     }     return MaxScr;   }   bool ok(int m) {     int vScr = 0, pScr = 0;     for (int i = 0; i < 5; i++) {       int MaxScr = getMaxScr(cnt[i] + m * add[i], n + m);       if (v[i] != -1) vScr += MaxScr / 250 * (250 - v[i]);       if (p[i] != -1) pScr += MaxScr / 250 * (250 - p[i]);     }     return vScr > pScr;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) {         int t;         cin >> t;         if (i == 0) v[j] = t;         if (i == 1) p[j] = t;         if (t != -1) cnt[j]++;       }     }     for (int i = 0; i < 5; i++)       if (v[i] != -1 && p[i] != -1 && p[i] < v[i]) add[i] = 1;     int ans = 0;     while (!ok(ans) && ans < 100000) ans++;     cout << (ans == 100000 ? -1 : ans) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long big = 1000000007;   unsigned long long gcd(unsigned long long a, unsigned long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   string getbin(unsigned long long x) {     if (x == 0) return  0 ;     string ret =   ;     while (x != 0) {       ret = (char)( 0  + x % 2) + ret;       x /= 2;     }     return ret;   }   unsigned long long getdec(string b) {     unsigned long long ret = 0;     for (int i = 0; i < b.size(); i += 1) {       ret *= 2;       ret += b[i] -  0 ;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long s = 0;       vector<int> a(n);       for (int i = 0; i < n; i += 1) cin >> a[i], s += a[i];       bool b = false;       for (int i = 0; !b && i < n; i += 1) {         if (a[i] > s / 2) b = true;       }       if (b)         cout <<  T ;       else if (s % 2 == 0)         cout <<  HL ;       else         cout <<  T ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int d[10];     d[0] = 1;     d[1] = 5;     d[2] = 10;     d[3] = 25;     d[4] = 50;     d[5] = 100;     d[6] = 500;     d[7] = 1000;     d[8] = 5000;     d[9] = 10000;     int a[1000009];     a[0] = 1;     for (int j = 0; j < 10; j++) {       for (int i = 1; i <= 1000000; i++) {         if (i - d[j] >= 0) {           a[i] += a[i - d[j]];         }         if (a[i] == n) {           printf( %d %d n , i, j + 1);           for (int k = 0; k <= j; k++) {             printf( %d  , d[k]);           }           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 0;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar()) f ^= (ch ==  - );     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   const long long maxn = 200050;   long long n, head[maxn], cnt = 0, siz[maxn], dep[maxn];   long long ans = 0, qwq = 0;   struct node {     long long to, nxt;   } e[maxn * 2];   inline void add(long long u, long long v) {     e[++cnt].to = v;     e[cnt].nxt = head[u];     head[u] = cnt;   }   void dfs(long long u, long long f, long long d) {     siz[u] = 1;     dep[u] = d;     for (long long i = head[u]; i; i = e[i].nxt) {       long long v = e[i].to;       if (v == f) continue;       dfs(v, u, d + 1);       siz[u] += siz[v];     }   }   signed main() {     n = read();     for (long long i = 1, a, b; i < n; ++i) {       a = read();       b = read();       add(a, b);       add(b, a);     }     dfs(1, 0, 0);     for (long long i = 1; i <= n; ++i) {       ans += siz[i] * (n - siz[i]);       if (dep[i] & 1) ++qwq;     }     ans += qwq * (n - qwq);     printf( %lld n , ans / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long double p[N], k[N];   int par[N];   vector<int> v[N];   bool vstd[N];   void dfs(int node) {     if (vstd[node]) return;     vstd[node] = true;     for (auto u : v[node]) {       if (u != par[node]) {         k[node] += p[u];         par[u] = node;         dfs(u);       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(6);     int n;     cin >> n;     long double tmp = 0.0;     for (int i = 0; i < n; i++) {       cin >> p[i];       p[i] = 1.0 - p[i];       tmp += p[i];     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     long double pmt = 0.0;     dfs(0);     for (int i = 0; i < n; i++) pmt += k[i] * p[i];     int q;     cin >> q;     while (q--) {       int node;       cin >> node;       tmp -= p[node];       pmt -= k[node] * p[node];       if (node) {         pmt -= k[par[node]] * p[par[node]];         k[par[node]] -= p[node];       }       cin >> p[node];       p[node] = 1.0 - p[node];       tmp += p[node];       if (node) k[par[node]] += p[node];       pmt += k[node] * p[node];       if (node) pmt += k[par[node]] * p[par[node]];       cout << tmp - pmt <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char next;     long long int neg = 0, pos = 0;     cin >> next;     bool estado = false;     string orden =   ;     while (next !=  = ) {       if (next ==    ) {         cin >> next;       }       if (next ==  - ) {         estado = true;         cin >> next;       }       if (next ==  + ) {         estado = false;         cin >> next;       }       if (next ==  ? ) {         if (estado) {           orden +=  - ;           neg++;         } else {           orden +=  + ;           pos++;         }       }       cin >> next;     }     long long int num;     cin >> num;     long long int coefs[neg + pos];     if ((neg > ((pos - 1) * num)) || ((pos - neg * num) > num)) {       cout <<  Impossible ;       return 0;     }     long long int valpos = 0, valneg = 0;     cout <<  Possible  << endl;     if (neg == 0) {       long long int cv = trunc(num / pos);       long long int sum = 0;       for (int i = 0; i < pos; i++) {         coefs[i] = cv;       }       sum = cv * pos - num;       if (sum != 0) {         for (int i = 0; i < pos; i++) {           coefs[i]++;           sum++;           if (sum == 0) break;         }       }       cout << coefs[0];       for (int i = 1; i < pos; i++) {         cout <<   +   << coefs[i];       }       cout <<   =   << num;       return 0;     }     if (pos - 1 > neg) {       valpos = 1;       valneg = trunc((pos - 1) / neg);     } else {       valneg = 1;       valpos = trunc(neg / (pos - 1));     }     int ref;     for (int i = 0; i < orden.size(); i++) {       if (orden[i] ==  - ) {         coefs[i] = -valneg;       } else         coefs[i] = valpos;     }     coefs[0] = num;     long long int suma = 0;     for (int i = 0; i < neg + pos; i++) {       suma += coefs[i];     }     suma -= num;     if (suma < 0) {       for (int i = 1; i < neg + pos; i++) {         if (coefs[i] > 0 && (abs(coefs[i]) < num)) {           coefs[i]++;           suma++;         }         if (suma == 0) break;       }     }     if (suma > 0) {       for (int i = 1; i < neg + pos; i++) {         if (coefs[i] < 0 && (abs(coefs[i]) < num)) {           coefs[i]--;           suma--;         }         if (suma == 0) break;       }     }     for (int i = 1; i < neg + pos; i++) {       if (abs(coefs[i]) > num) {         if (coefs[i] < 0) {           suma += -num - coefs[i];           coefs[i] = -num;         } else {           suma += num - coefs[i];           coefs[i] = num;         }       }     }     if (suma > 0) {       coefs[0] -= suma;       suma -= suma;     }     if (suma < 0) {       coefs[0] += suma;       suma -= suma;     }     cout << coefs[0];     for (int i = 1; i < pos + neg; i++) {       if (coefs[i] < 0)         cout <<   -   << abs(coefs[i]);       else         cout <<   +   << coefs[i];     }     cout <<   =   << suma + num;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, large = 2000000000, small = -2000000000;     string s1, s2;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s1 >> x >> s2;       if ((s1 ==  >  && s2 ==  Y ) || (s1 ==  <=  && s2 ==  N )) {         if (x >= small) {           small = x + 1;         }       } else if ((s1 ==  <  && s2 ==  Y ) || (s1 ==  >=  && s2 ==  N )) {         if (x <= large) {           large = x - 1;         }       } else if ((s1 ==  >=  && s2 ==  Y ) || (s1 ==  <  && s2 ==  N )) {         if (x >= small) {           small = x;         }       } else {         if (x <= large) {           large = x;         }       }     }     if (small > large) {       cout <<  Impossible ;     } else {       cout << small;     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 405;   char mp[30], s[N], a[5], b[5];   int L, n, m, e[N][N], nxd[30], nxs[30], flg[30], lim[N], tmp[N], mx[2];   vector<int> ans;   bool chk(int pos, int v, int x, bool ff) {     if (lim[pos] != -1 && lim[pos] != flg[v]) return 0;     for (int i = 1; i <= n; i++)       if (e[x][i] && e[x][i + n]) return 0;     for (int i = 1; i <= n; i++) tmp[i] = (e[x][i] ? 0 : (e[x][i + n] ? 1 : -1));     if (ff) {       for (int i = 1; i <= n; i++) {         if (pos + i > n) break;         int t = max(lim[pos + i], tmp[pos + i]);         if (t == -1) break;         if (mx[t] < s[pos + i] -  a  + 1) return 0;         if (mx[t] > s[pos + i] -  a  + 1) break;       }     }     for (int i = 1; i <= n; i++) {       lim[i] = max(lim[i], tmp[i]);     }     return 1;   }   int main() {     scanf( %s , mp + 1);     L = strlen(mp + 1);     memset(lim, -1, sizeof(lim));     memset(mx, -1, sizeof(mx));     for (int i = 1; i <= L; i++) {       flg[i] = mp[i] ==  V ;       mx[flg[i]] = i;     }     for (int i = 1; i <= L; i++)       for (int j = i + 1; j <= L; j++)         if (flg[i] != flg[j]) {           nxd[i] = j;           break;         }     for (int i = 1; i <= L; i++)       for (int j = i + 1; j <= L; j++)         if (flg[i] == flg[j]) {           nxs[i] = j;           break;         }     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%s%d%s , &x, a, &y, b);       int a1 = a[0] ==  V , b1 = b[0] ==  V ;       e[x + a1 * n][y + b1 * n] = 1;       e[y + !b1 * n][x + !a1 * n] = 1;     }     scanf( %s , s + 1);     for (int k = 1; k <= n * 2; k++)       for (int i = 1; i <= n * 2; i++)         for (int j = 1; j <= n * 2; j++) e[i][j] |= (e[i][k] & e[k][j]);     bool ff = 1;     for (int i = 1; i <= n; i++) {       int mn = ff ? s[i] -  a  + 1 : 1;       if (chk(i, mn, i + flg[mn] * n, ff)) {         ans.push_back(mn);       } else if (mn < L && flg[mn] == flg[mn + 1] &&                  chk(i, mn + 1, i + flg[mn + 1] * n, 0)) {         ans.push_back(mn + 1), ff = 0;       } else if (nxd[mn] && chk(i, nxd[mn], i + flg[nxd[mn]] * n, 0)) {         ans.push_back(nxd[mn]), ff = 0;       } else if (nxs[mn] && nxs[mn] > nxd[mn] &&                  chk(i, nxs[mn], i + flg[nxs[mn]] * n, 0)) {         ans.push_back(nxs[mn]), ff = 0;       } else {         return puts( -1 ), 0;       }     }     for (int i = 0; i <= n - 1; i++) printf( %c , ans[i] +  a  - 1);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps(1e-8);   char s[1000010];   int n, m, a, b;   vector<int> vec[1000010];   vector<int> p[1000010];   int x[1000010], y[1000010], sum[1000010], ans[1000010];   int Lowbit(int x) { return x & (-x); }   void Update(int pos, int val) {     while (pos > 0) {       sum[pos] += val;       pos -= Lowbit(pos);     }   }   int Query(int pos) {     int ret = 0;     while (pos <= n) {       ret += sum[pos];       pos += Lowbit(pos);     }     return ret;   }   void Add(int l, int r, int val) {     Update(r, val);     Update(l - 1, -val);   }   int main() {     scanf( %s , s + 1);     for (n = 1; s[n]; n++)       ;     n--;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a, &b);       vec[b].push_back(a);       p[b].push_back(i);     }     int len = 0;     for (int i = 1; i <= n; i++) {       len++;       if (s[i] ==  ( )         x[len] = 0;       else         x[len] = 1;       y[len] = i;       if (len >= 2 && x[len] == 1 && x[len - 1] == 0) {         Add(1, y[len - 1], 2);         len -= 2;       }       for (int j = 0; j < (int)vec[i].size(); j++) {         int tmp = vec[i][j];         ans[p[i][j]] = Query(tmp);       }     }     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, min_cost, min_a, min_b, min_c;       cin >> a >> b >> c;       if (b % a == 0 && c % b == 0) {         cout << 0 << endl;         cout << a <<     << b <<     << c << endl;       } else {         min_cost = 10000000;         int max = 2 * c;         for (int i = 1; i < max; i++)           for (int j = i; j < max; j += i)             for (int k = j; k < max; k += j)               if (k % j == 0 && j % i == 0) {                 int cost = abs(a - i) + abs(b - j) + abs(c - k);                 if (cost < min_cost) {                   min_cost = cost;                   min_a = i;                   min_b = j;                   min_c = k;                 }               }         cout << min_cost << endl;         cout << min_a <<     << min_b <<     << min_c << endl;       }     }   }
#include<bits/stdc++.h>   using namespace std;   int dp[510][127010],mod,c[510][510],s[127010],jc[510];   int sol(int n){    s[0]=dp[n-1][0];    for(int i=1;i<=n*(n-1)/2;i++)s[i]=(s[i-1]+dp[n-1][i])%mod;    int ans=0;    for(int i=1;i<n;i++)for(int j=i+1;j<=n*(n-1)/2;j++)(ans+=1ll*(n-i)*dp[n-1][j]%mod*s[j-(i+1)]%mod)%=mod;    return ans;   }   int main(){    int n;    scanf( %d%d ,&n,&mod);    jc[0]=1;    for(int i=1;i<=n;i++)jc[i]=1ll*jc[i-1]*i%mod;    c[0][0]=dp[1][0]=1;    for(int i=2;i<=n;i++)for(int j=0;j<=i*(i+1)/2;j++){     if(!j)dp[i][j]=1;     else dp[i][j]=(dp[i][j-1]+(dp[i-1][j]-((j>=i)?dp[i-1][j-i]:0))%mod)%mod;    }    for(int i=1;i<=n;i++){     c[i][0]=1;     for(int j=1;j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;    }    int ans=0;    for(int i=0;i<n;i++)(ans+=1ll*c[n][i]*jc[i]%mod*sol(n-i)%mod)%=mod;    return printf( %d ,(ans+mod)%mod),0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   vector<pair<long long, int>> adj[10 * MAXN];   long long dist[10 * MAXN];   int par[10 * MAXN];   int go1(int idx, int l, int r, int ds) {     if (idx > 1) {       int par = idx / 2;       adj[par + ds].push_back({0, idx + ds});     }     if (l == r) {       adj[idx + ds].push_back({0, l});       return idx;     }     int m = (l + r) / 2;     int ret =         max(idx, max(go1(2 * idx, l, m, ds), go1(2 * idx + 1, m + 1, r, ds)));     return ret;   }   void go2(int idx, int l, int r, int ds) {     for (int i = l; i < (r + 1); ++i) {       adj[i].push_back({0, idx + ds});     }     if (r > l) {       int m = (l + r) / 2;       go2(2 * idx, l, m, ds);       go2(2 * idx + 1, m + 1, r, ds);     }   }   void go3(int idx, int x, int y, int l, int r, function<void(int)> f) {     if (y < l || x > r) return;     if (x >= l && y <= r) {       f(idx);       return;     }     int m = (x + y) / 2;     go3(2 * idx, x, m, l, r, f);     go3(2 * idx + 1, m + 1, y, l, r, f);   }   void dijsktra(int src) {     memset(dist, 0x3f3f3f3f, sizeof(dist));     dist[src] = 0;     par[src] = src;     priority_queue<pair<long long, int>, vector<pair<long long, int>>,                    greater<pair<long long, int>>>         pq;     pq.push({dist[src], src});     while (!pq.empty()) {       int u = pq.top().second;       long long l = pq.top().first;       pq.pop();       if (dist[u] == l) {         for (auto p : adj[u]) {           long long ndist = l + p.first;           if (ndist < dist[p.second]) {             dist[p.second] = ndist;             par[p.second] = u;             pq.push({dist[p.second], p.second});           }         }       }     }   }   int main() {     int n, m, src;     scanf(  %d %d , &(n), &(m));     scanf(  %d , &(src));     --src;     int ds1 = n - 1 + 5;     int ds2 = go1(1, 0, n - 1, ds1) + ds1 + 5;     go2(1, 0, n - 1, ds2);     while (m--) {       int tp;       scanf(  %d , &(tp));       if (tp == 1) {         int u, v, w;         scanf(  %d %d , &(u), &(v));         scanf(  %d , &(w));         adj[u - 1].push_back({w, v - 1});       } else {         int vtx, l, r, w;         scanf(  %d %d , &(vtx), &(l));         scanf(  %d %d , &(r), &(w));         --l;         --r;         --vtx;         go3(1, 0, n - 1, l, r, [ds1, ds2, tp, w, vtx](int idx) {           if (tp == 2) {             adj[vtx].push_back({w, idx + ds1});           } else {             adj[idx + ds2].push_back({w, vtx});           }         });       }     }     dijsktra(src);     for (int i = 0; i < (n); ++i)       printf( %lld%c , (dist[i] == 0x3f3f3f3f3f3f3f3fll ? -1 : dist[i]),                 n [i == n - 1]);     return 0;   }