malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long pred[300005];   long long suffc[300005];   long long ans[300005];   int main() {     int n, m;     scanf( %d %d , &n, &m);     pair<int, int> ara[n];     vector<pair<int, int> > vt(n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &ara[i].first, &ara[i].second);       vt[i] = {ara[i].second - ara[i].first, i};     }     sort(vt.begin(), vt.end());     pred[0] = ara[vt[0].second].second;     for (int i = 1; i < n; i++) {       pred[i] = pred[i - 1] + ara[vt[i].second].second;     }     suffc[n - 1] = ara[vt[n - 1].second].first;     for (int i = n - 2; i >= 0; i--) {       suffc[i] = suffc[i + 1] + ara[vt[i].second].first;     }     for (int i = 0; i < n; i++) {       int pos = upper_bound(vt.begin(), vt.end(),                             make_pair(ara[i].second - ara[i].first, n + 1)) -                 vt.begin();       ans[i] += 1ll * suffc[pos] + 1ll * (n - pos) * ara[i].second;       pos--;       if (pos >= 0)         ans[i] += 1ll * pred[pos] + 1ll * (pos + 1) * ara[i].first,             ans[i] -= ara[i].first + ara[i].second;       if (i == 0) {       }     }     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--, v--;       ans[u] -= min(ara[u].first + ara[v].second, ara[u].second + ara[v].first);       ans[v] -= min(ara[u].first + ara[v].second, ara[u].second + ara[v].first);     }     for (int i = 0; i < n; i++) printf( %lld  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     long long int n, i, p = 1, k, x = 0, s = 0;     scanf( %lld , &n);     k = n;     while (k != 0) {       k = k / 10;       x++;     }     for (i = 1; i <= x - 1; i++) {       p = p * 10;     }     while (x != 0) {       s = s + (n - p + 1) * x;       n = p - 1;       p = p / 10;       x--;     }     printf( %lld , s);   }
#include <bits/stdc++.h>   using namespace std;   deque<int> d[100005];   int v[100005];   int p[100005];   pair<int, int> q[100005];   int ans = 0;   int prog = 0;   int as[100005];   unordered_map<int, int> possible[100005];   bool cmp(int a, int b) {     if (q[a].first / 300 != q[b].first / 300)       return q[a].first / 300 < q[b].first / 300;     return q[a].second < q[b].second;   }   void update(int val, int pos, int u, int c) {     if (c == -1) {       prog -= possible[val].size() <= 1;       if (u == 1) {         int cnt = d[val].front();         d[val].pop_front();         if (d[val].empty())           --ans;         else {           --possible[val][d[val].front() - cnt];           if (!possible[val][d[val].front() - cnt])             possible[val].erase(d[val].front() - cnt);         }       } else {         int cnt = d[val].back();         d[val].pop_back();         if (d[val].empty())           --ans;         else {           --possible[val][cnt - d[val].back()];           if (!possible[val][cnt - d[val].back()])             possible[val].erase(cnt - d[val].back());         }       }       if (!d[val].empty()) prog += possible[val].size() <= 1;     } else {       if (d[val].empty())         ++ans;       else         prog -= possible[val].size() <= 1;       if (u == 1) {         if (d[val].empty()) {           d[val].push_front(pos);         } else {           int cnt = d[val].front();           d[val].push_front(pos);           ++possible[val][cnt - pos];         }       } else {         if (d[val].empty()) {           d[val].push_back(pos);         } else {           int cnt = d[val].back();           d[val].push_back(pos);           ++possible[val][pos - cnt];         }       }       if (possible[val].size() <= 1) ++prog;     }   }   int main(void) {     int n, m;     ios_base ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> v[i];     cin >> m;     for (int i = 1; i <= m; ++i) cin >> q[i].first >> q[i].second, p[i] = i;     sort(p + 1, p + 1 + m, cmp);     for (int i = q[p[1]].first; i <= q[p[1]].second; ++i) update(v[i], i, 1, 1);     as[p[1]] = ans + !prog;     int l = q[p[1]].first, r = q[p[1]].second;     for (int i = 2; i <= m; ++i) {       while (l > q[p[i]].first) --l, update(v[l], l, -1, 1);       while (r < q[p[i]].second) ++r, update(v[r], r, 1, 1);       while (l < q[p[i]].first) update(v[l], l, -1, -1), ++l;       while (r > q[p[i]].second) update(v[r], r, 1, -1), --r;       as[p[i]] = ans + !prog;     }     for (int i = 1; i <= m; ++i) cout << as[i] <<   n ;     return cout <<   n , 0;   }
#include <bits/stdc++.h>   using namespace std;   struct tc {     int cnt, count;     long long p[5001];   } q[5001];   struct sc {     int id;     long long num;   } anss[200010], s[200010];   void merge(int l, int mid, int r) {     int i = l, j = mid + 1;     int cc = l;     while (i <= mid && j <= r) {       if (anss[i].num <= anss[j].num) {         s[cc].id = anss[i].id;         s[cc++].num = anss[i++].num;       } else {         s[cc].id = anss[j].id;         s[cc++].num = anss[j++].num;       }     }     while (i <= mid) {       s[cc].id = anss[i].id;       s[cc++].num = anss[i++].num;     }     while (j <= r) {       s[cc].id = anss[j].id;       s[cc++].num = anss[j++].num;     }     for (i = l; i < cc; i++) {       anss[i].id = s[i].id;       anss[i].num = s[i].num;     }     return;   }   void mergesort(int x, int y) {     if (x < y) {       int mid = (x + y) / 2;       mergesort(x, mid);       mergesort(mid + 1, y);       merge(x, mid, y);     }     return;   }   int main() {     int i, j;     long long n, a, x, y, m;     int ans = -1, k, sum, l = 0;     cin >> n;     for (i = 0; i < n; i++) {       scanf( %d %I64d %I64d %I64d %I64d , &k, &a, &x, &y, &m);       sum = 0;       l += k;       q[i].cnt = 1;       q[i].count = k;       q[i].p[1] = a;       for (j = 2; j <= k; j++) {         q[i].p[j] = (x * q[i].p[j - 1] + y) % m;         if (q[i].p[j] < q[i].p[j - 1]) sum++;       }       ans = max(ans, sum);     }     printf( %d n , ans);     int st = 0, end = 0;     if (l <= 2e5) {       while (end < l) {         for (i = 0; i < n; i++) {           for (j = q[i].cnt; j <= q[i].count; j++) {             if (j != q[i].cnt && q[i].p[j] < q[i].p[j - 1]) {               q[i].cnt = j;               break;             }             anss[end].id = i;             anss[end++].num = q[i].p[j];           }           if (j > q[i].count) q[i].cnt = j;         }         mergesort(st, end - 1);         st = end;       }       for (i = 0; i < l; i++) printf( %I64d %d n , anss[i].num, anss[i].id + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> p(n), m(n);       vector<vector<long long>> v(n + 1);       for (long long i = 0; i < n; i++) {         cin >> m[i] >> p[i];         v[m[i]].push_back(i);       }       vector<long long> sum(n + 1);       sum[0] = v[0].size();       for (long long i = 1; i < n + 1; i++) {         sum[i] = sum[i - 1] + v[i].size();       }       long long kol = 0;       long long ans = 0;       multiset<long long> st;       for (long long i = n; i > 0; i--) {         for (long long j = 0; j < v[i].size(); j++) {           st.insert(p[v[i][j]]);         }         while (kol + sum[i - 1] < i) {           ans += *st.begin();           ++kol;           st.erase(st.begin());         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool check(int x, int n, vector<int>& a) {     vector<int> temp;     int i = 0, j = x;     int cnt = 0;     bool ok = false;     while (cnt < n) {       if (ok)         temp.push_back(a[i]), i++, ok = false;       else         temp.push_back(a[j]), j++, ok = true;       cnt++;     }     cnt = 0;     return cnt == x;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int cnt = 0;     vector<int> ans(n);     for (int i = 1; i < n; i += 2) {       ans[i] = a[cnt++];     }     for (int i = 0; i < n; i += 2) ans[i] = a[cnt++];     cnt = 0;     for (int i = 1; i < n - 1; i++) {       if (ans[i] < ans[i - 1] && ans[i] < ans[i + 1]) cnt++;     }     cout << cnt <<   n ;     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       int n, i, z = -1, o = -1, s = 0, max = -1;       scanf( %d , &n);       char ss[n + 5], at[2];       scanf( %s , ss);       int a[n], b[n], zero[n], one[n];       for (i = 0; i < n; i++) {         at[0] = ss[i];         at[1] =   0 ;         a[i] = atoi(at);       }       for (i = 0; i < n; i++) {         if (!a[i]) {           if (o >= 0) {             zero[++z] = one[o--];             b[i] = zero[z];           } else {             zero[++z] = ++s;             b[i] = zero[z];           }         }         if (a[i]) {           if (z >= 0) {             one[++o] = zero[z--];             b[i] = one[o];           } else {             one[++o] = ++s;             b[i] = one[o];           }         }         if (max < b[i]) max = b[i];       }       printf( %d n , max);       for (i = 0; i < n; i++) printf( %d  , b[i]);       printf(  n );     }   }
#include <algorithm>   #include <iostream>   #include <cstdlib>   #include <cassert>   #include <cstring>   #include <iomanip>   #include <cstdio>   #include <limits>   #include <string>   #include <vector>   #include <cmath>   #include <deque>   #include <queue>   #include <stack>   #include <map>   #include <set>   using namespace std;      typedef long long LL;   typedef long long ll;   typedef long double LD;   typedef vector<int> vi;   typedef pair<LL,LL> PLL;   typedef pair<LL,int> PLI;   typedef pair<int,int> PII;   typedef pair<int,int> pii;   typedef vector<vector<LL>> VVL;      #define rep(i, a, b) for(int i = a; i < (b); ++i)   #define trav(a, x) for(auto& a : x)   #define all(x) begin(x), end(x)   #define sz(x) (int)(x).size()   #define popf pop_front   #define pf push_front   #define popb pop_back   #define mp make_pair   #define pb push_back   #define remove erase   #define fi first   #define se second      #define endl   n       const int INF = 1061109567;   const LL LINF = 4557430888798830399LL;   const LL MOD = 1000000007;   const int dx[8] = {0,0,1,-1,1,-1,1,-1};   const int dy[8] = {1,-1,0,0,1,-1,-1,1};   const char dch[4] = { R , L , D , U };   // const string ds[8] = { E , W , S , N , SE , NW , SW , NE };   inline void fasterios(){       ios_base::sync_with_stdio(0);       cin.tie(0); cout.tie(0);   }         // Don t forget to read all the inputs before returning!!!   int solve(){     int n; cin >> n;     vector <PII> arr(n);     rep(i,0,n){       cin >> arr[i].fi;       arr[i].se = i;     }     sort(all(arr));     vector <int> tmp[2];     rep(i,0,n) if(abs(arr[i].se - i) % 2 == 1) tmp[i%2].pb(arr[i].fi);     sort(all(tmp[0]));     sort(all(tmp[1]));     if(sz(tmp[0]) != sz(tmp[1])){       cout <<  NO  << endl;       return 0;     }     for(int i = 0;i < sz(tmp[0]);i++){       if(tmp[0][i] != tmp[1][i]){         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }      int main(){     fasterios();     int testCases; cin >> testCases; int tc = 0;     while(++tc <= testCases){       // cout <<  Case #  << tc <<  :  ;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   long long a, b, n, dv[N], l, r, sz;   long long bs(long long l, long long r) {     long long bas = 0;     long long son = sz + 1;     while (bas + 1 < son) {       long long orta = bas + son >> 1;       if (dv[orta] < l)         bas = orta;       else if (dv[orta] > r)         son = orta;       else if (dv[orta] <= r and dv[orta] >= l)         bas = orta;     }     return (dv[bas] < l or dv[bas] > r) ? -1 : dv[bas];   }   int main() {     cin >> a >> b >> n;     for (long long i = 1; i * i <= max(a, b); i++) {       if (a % i == 0 and b % i == 0) {         dv[++sz] = i;         if (b % (a / i) == 0 and i * i != max(a, b)) dv[++sz] = a / i;         if (a % (b / i) == 0) dv[++sz] = b / i;       } else if (a % (b / i) == 0 and b % i == 0)         dv[++sz] = b / i;       else if (b % (a / i) == 0 and a % i == 0)         dv[++sz] = a / i;     }     sort(dv + 1, dv + sz + 1);     for (long long i = 1; i <= n; i++) {       cin >> l >> r;       cout << bs(l, r) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, ans, i, j, k;     cin >> t;     for (i = 0; i < t; i++) {       cin >> n;       int x[2 * n];       for (j = 0; j < 2 * n; j++) cin >> x[j];       sort(x, x + 2 * n);       ans = x[n] - x[n - 1];       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int INF = 1e9 + 7;   int ds[100];   int hs[100];   int solve() {     int N, X;     scanf( %d %d , &N, &X);     for (int i = 0; i < N; i++) {       scanf( %d %d , &ds[i], &hs[i]);     }     int last = *std::max_element(ds, ds + N);     if (last >= X) return 1;     int dec = 0;     for (int i = 0; i < N; i++) {       dec = std::max(dec, ds[i] - hs[i]);     }     if (dec == 0) return -1;     return (X - last + dec - 1) / dec + 1;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       printf( %d n , solve());     }   }
#include <bits/stdc++.h>   using namespace std;   struct s_ix {     long long ix;     long long val;   };   bool operator<(s_ix aa, s_ix bb) { return aa.val - aa.ix < bb.val - bb.ix; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, k, nc[200200], sum, nbw, maxnbw;       s_ix nb[200200];       string s[200200];       cin >> n;       for (int j = 0; j < n; j++) cin >> s[j];       maxnbw = 0;       for (int l = 0; l < 26; l++) {         nbw = 0;         for (int j = 0; j < n; j++) {           nb[j].val = 0;           nb[j].ix = 0;           for (int jj = 0; jj < s[j].length(); jj++) {             if ((int)(s[j][jj] -  a ) == l)               nb[j].val++;             else               nb[j].ix++;           }         }         sort(nb, nb + n);         reverse(nb, nb + n);         long long nl = 0;         nl = nb[0].val - nb[0].ix;         int j = 0;         while (nl > 0 and j < n) {           j++;           nl += nb[j].val - nb[j].ix;           nbw++;         }         maxnbw = max(maxnbw, nbw);       }       cout << maxnbw << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s1 = 0, s2 = 0, s3 = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i % 3 == 0)         s1 += a[i];       else if (i % 3 == 1)         s2 += a[i];       else         s3 += a[i];     }     if (s1 >= s2 && s1 >= s3)       cout <<  chest n ;     else if (s2 >= s3 && s2 >= s1)       cout <<  biceps n ;     else       cout <<  back n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long strL[200005], patL[200005], n, m, pref[200005], ans, tempL[200005];   char strC[200005], tempC[200005];   vector<long long> endings;   string patC =   ;   long long lenP, lenS;   void calcPrefixFunction() {     for (long long i = 1, k = 0; i < m - 2; i++) {       while (k > 0 && (patC[k] != patC[i] || patL[k] != patL[i])) k = pref[k - 1];       if (patC[k] == patC[i] && patL[i] == patL[k])         pref[i] = ++k;       else         pref[i] = k;     }   }   void kmp() {     for (long long i = 0, k = 0; i < n; i++) {       while (k > 0 && (strL[i] != patL[k] || strC[i] != patC[k])) k = pref[k - 1];       if (strL[i] == patL[k] && strC[i] == patC[k]) k++;       if (k == m - 2) {         endings.push_back(i);         k = pref[k - 1];       }     }   }   long long tempSolve1() {     long long ret = 0;     for (long long i = 0; i < n; i++)       if (tempL[0] <= strL[i] && strC[i] == tempC[0])         ret += strL[i] - tempL[0] + 1;     return ret;   }   long long tempSolve2() {     long long ret = 0;     for (long long i = 0; i < n - 1; i++)       if (tempL[0] <= strL[i] && strC[i] == tempC[0])         if (tempL[1] <= strL[i + 1] && strC[i + 1] == tempC[1]) ret++;     return ret;   }   void solve() {     if (lenP > lenS) {       puts( 0 );       return;     }     if (m == 1) {       printf( %I64d , tempSolve1());       return;     }     if (m == 2) {       printf( %d , tempSolve2());       return;     }     calcPrefixFunction();     kmp();     for (long long i = 0; i < endings.size(); i++) {       long long start, end;       end = endings[i] + 1;       start = end - m + 1;       if (end >= n || start < 0) continue;       if (strC[start] == tempC[0] && strL[start] >= tempL[0])         if (strC[end] == tempC[m - 1] && strL[end] >= tempL[m - 1]) ans++;     }     printf( %d , ans);   }   void input() {     scanf( %d %d , &n, &m);     for (long long i = 0; i < n; i++) {       scanf( %d-%c , &strL[i], &strC[i]);       if (i && strC[i] == strC[i - 1]) {         strL[i - 1] += strL[i];         n--;         i--;       }       lenS += strL[i];     }     for (long long i = 0; i < m; i++) {       scanf( %d-%c , &tempL[i], &tempC[i]);       lenP += tempL[i];       if (i && tempC[i] == tempC[i - 1]) {         tempL[i - 1] += tempL[i];         if (i - 2 >= 0) patL[i - 2] = tempL[i - 1];         i--;         m--;       } else if (i && i < m - 1)         patC += tempC[i], patL[i - 1] = tempL[i];     }   }   int main() {     input();     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, g;     cin >> n >> g;     g %= 4 * n;     long long xx, yy;     cin >> xx >> yy;     long long x[n], y[n];     for (int(i) = int(0); i < int(n); ++i) cin >> x[i] >> y[i];     for (int(i) = int(1); i < int(g + 1); ++i) {       long long dx = xx - x[(i - 1) % n];       long long dy = yy - y[(i - 1) % n];       xx -= 2 * dx;       yy -= 2 * dy;     }     cout << xx <<     << yy << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct dat {     long long a;     long long n;   };   bool comp(struct dat a, struct dat b) { return a.a < b.a; }   int main() {     ios::sync_with_stdio(false);     long long a, b, c, i, j, k, l, m, t, x, y, n, z;     vector<long long> a1;     string s;     cin >> n;     vector<vector<long long> > arr(n, vector<long long>(2));     struct dat arr1[n];     for (i = 0; i < n; i++) {       cin >> arr[i][0];       arr[i][1] = i;       arr1[i].a = arr[i][0];       arr1[i].n = i;     }     sort(arr1, arr1 + n, comp);     for (i = 0; i < n; i++) {       arr[arr1[i].n][1] = i;     }     vector<vector<long long> > ans;     int arr3[n];     for (i = 0; i < n; i++) {       arr3[i] = 0;     }     for (i = 0; i < n; i++) {       if (arr3[i] == 1)         continue;       else {         j = i;         vector<long long> q1;         while (arr3[j] == 0) {           arr3[j] = 1;           q1.push_back(j);           j = arr[j][1];         }         sort(q1.begin(), q1.end());         ans.push_back(q1);       }     }     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++) {       cout << ans[i].size() <<    ;       for (j = 0; j < ans[i].size(); j++) {         cout << ans[i][j] + 1 <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const long long N = 5e3 + 5;   long long a[N];   long long pre[N];   long long dp[N][N];   long long n, m, k;   long long check = 0;   long long go(long long pos, long long kk) {     if (kk == k) return 0;     if (pos == n + 1) return -1e15;     long long &ans = dp[pos][kk];     if (ans != -1) return ans;     ans = go(pos + 1, kk);     if (pos + m - 1 <= n) {       ans = max(ans, pre[pos + m - 1] - pre[pos - 1] + go(pos + m, kk + 1));     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       pre[i] = pre[i - 1] + a[i];     }     memset(dp, -1, sizeof(dp));     cout << go(1, 0) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string str;   int main() {     cin >> n >> str;     for (int i = 0; i < str.size(); i++) {       if (n % (i + 1) == 0) {         for (int j = 0; j <= i / 2; j++) {           swap(str[j], str[i - j]);         }       }     }     cout << str;   }
#include <bits/stdc++.h>   using namespace std;   bool deb = false;   int i, k, n;   const int N = 500011;   int a[N];   bool f1(long long int x) {     int i;     long long int inc = 0, dec = 0;     for (i = 0; i < n; ++i) {       if (a[i] > x)         dec += (a[i] - x);       else         inc += (x - a[i]);     }     if (dec <= inc && dec <= k) return 1;     return 0;   }   bool f2(long long int x) {     int i;     long long int inc = 0, dec = 0;     for (i = 0; i < n; ++i) {       if (a[i] > x)         dec += (a[i] - x);       else         inc += (x - a[i]);     }     if (dec >= inc && inc <= k) return 1;     return 0;   }   long long int min_max(long long int lo, long long int hi) {     while (lo < hi) {       long long int mid = lo + (hi - lo) / 2;       if (f1(mid)) {         hi = mid;       } else         lo = mid + 1;     }     return hi;   }   long long int max_min(long long int lo, long long int hi) {     while (lo < hi) {       long long int mid = lo + (hi - lo) / 2;       if (f2(mid)) {         lo = mid + 1;       } else         hi = mid;     }     return lo - 1;   }   int main() {     int i, j;     scanf( %d , &n), scanf( %d , &k);     for (i = 0; i < n; ++i) scanf( %d , &a[i]);     int mx = min_max(1, 1000000007);     int mn = max_min(1, 1000000007);     printf( %d n , mx - mn);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     string s;     map<string, int> mp;     for (int i = 0; i < n; ++i) {       cin >> s;       mp[s]++;     }     int ans = 0;     for (auto ss : mp) {       ans = max(ans, ss.second);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const int mx = 2002;   const int inf = 1000 * 1000 * 1000;   using namespace std;   vector<int> adj[mx];   vector<long long> w[mx];   set<pair<long long, int> > s;   long long dist[mx];   bool mrk[mx];   void dijkstra() {     while (s.size()) {       pair<long long, int> p = *s.begin();       s.erase(s.begin());       int v = p.second;       mrk[v] = 1;       for (int i = 0; i < adj[v].size(); i++) {         int u = adj[v][i];         if (!mrk[u]) {           pair<long long, int> p1 = make_pair(dist[u], u);           s.erase(p1);           dist[u] = min(dist[u], w[v][i] + dist[v]);           s.insert(make_pair(dist[u], u));         }       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, cnt = 0;     long long mn = inf;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         long long k;         cin >> k;         w[i].push_back(k);         w[j].push_back(k);         adj[i].push_back(j);         adj[j].push_back(i);         cnt++;         mn = min(mn, k);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < w[i].size(); j++) {         w[i][j] -= mn;       }     }     for (int i = 0; i < n; i++) {       long long ww = inf;       for (int j = 0; j < adj[i].size(); j++) {         ww = min(ww, w[i][j]);       }       dist[i] = 2 * ww;       s.insert(make_pair(dist[i], i));     }     dijkstra();     for (int i = 0; i < n; i++) {       cout << dist[i] + (n - 1) * mn << endl;     }   }