malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int m, n, a[100009], b[100009];   long long sa, sb;   long long proca() {     long long ans = 0;     ans += sa;     for (int(x) = (1); (x) < (n); ++(x)) {       ans += min(sa, (long long)b[x]);     }     return ans;   }   long long procb() {     long long ans = 0;     ans += sb;     for (int(x) = (1); (x) < (m); ++(x)) ans += min(sb, (long long)a[x]);     return ans;   }   int main() {     while (scanf( %d%d , &m, &n) == 2) {       sa = sb = 0;       for (int(x) = (0); (x) < (m); ++(x)) {         scanf( %d , &a[x]);         sa += a[x];       }       for (int(x) = (0); (x) < (n); ++(x)) {         scanf( %d , &b[x]);         sb += b[x];       }       sort(a, a + m);       reverse(a, a + m);       sort(b, b + n);       reverse(b, b + n);       cout << min(proca(), procb()) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int t, v, next;     Edge() {}     Edge(int a, int b, int c) : t(a), v(b), next(c) {}   };   Edge e[600005];   int head[300005];   long long dis[300005];   int p[300005];   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       q;   void dijkstra(int k) {     memset(dis, 0x3f, sizeof(dis));     dis[1] = 0;     q.push(pair<long long, int>(0, 1));     int cnt = 0;     while (!q.empty()) {       pair<long long, int> t = q.top();       q.pop();       if (dis[t.second] < t.first) continue;       int a = t.second;       long long b = t.first;       if (p[a] && cnt < k) {         printf( %d  , p[a]);         cnt++;       }       for (int i = head[a]; i; i = e[i].next)         if (b + e[i].v < dis[e[i].t]) {           int u = e[i].t;           dis[u] = b + e[i].v;           p[u] = ((i + 1) >> 1);           q.push(pair<long long, int>(dis[u], u));         }     }     printf(  n );   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     k = min(k, n - 1);     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       e[2 * i - 1] = Edge(y, z, head[x]);       head[x] = 2 * i - 1;       e[2 * i] = Edge(x, z, head[y]);       head[y] = 2 * i;     }     printf( %d n , k);     dijkstra(k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j;     char s[101];     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> s;       for (j = 0; j < m; j++) {         if (s[j] ==  . ) s[j] = ((i + j) % 2 == 0) ?  B  :  W ;       }       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     srand(1598743157);     int v[4];     for (int i = 0; i < 4; i++) scanf( %d , &v[i]);     while (v[0] != 1 || v[1] != 1 || v[2] != 1 || v[3] != 1) {       bool ok = true;       bool was = false;       while (ok) {         ok = false;         for (int i = 0; i < 4; i++)           if (v[i] % 2 == 0 && v[(i + 1) % 4] % 2 == 0) {             printf( /%d n , i + 1);             v[i] /= 2;             v[(i + 1) % 4] /= 2;             ok = true;             was = true;           }       }       if (was) continue;       int i = rand() % 4;       printf( +%d n , i + 1);       v[i]++;       v[(i + 1) % 4]++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[2][100010];   long long MOD = 1000000007;   int main() {     string s1, s2;     int k;     while (cin >> s1 >> s2 >> k) {       s1 = s1 + s1;       int cntS = 0, cntD = 0;       for (int i = 0; i < s2.size(); ++i)         if (s1.substr(i, s2.size()) == s2)           cntS++;         else           cntD++;       if (s1.substr(0, s2.size()) == s2)         dp[0][0] = 1, dp[1][0] = 0;       else         dp[0][0] = 0, dp[1][0] = 1;       for (int i = 1; i <= k; ++i) {         dp[0][i] = dp[0][i - 1] * (cntS - 1) + dp[1][i - 1] * (cntS);         dp[1][i] = dp[0][i - 1] * (cntD) + dp[1][i - 1] * (cntD - 1);         dp[0][i] %= MOD;         dp[1][i] %= MOD;       }       cout << dp[0][k] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10;   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     string s;     cin >> s;     s +=  _ ;     int ln = 0, lng = 0, imin = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ( ) {         imin = 1;         ln = 0;       } else if (s[i] ==  ) ) {         imin = 0;         ln = 0;       } else if (!imin) {         if (s[i] !=  _ ) {           ln++;           lng = max(lng, ln);         } else           ln = 0;       } else         ln = 0;     }     cout << lng <<    ;     imin = 0, ln = 0;     int cnt = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ( ) {         imin = 1;         ln = 0;       } else if (s[i] ==  ) ) {         imin = 0;         if (ln) cnt++;         ln = 0;       } else if (imin) {         if (s[i] !=  _ )           ln++;         else {           if (ln) cnt++;           ln = 0;         }       } else         ln = 0;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K;     cin >> N >> K;     using arr2 = array<int, 2>;     vector<arr2> binTrie;     const int w = 30;     binTrie.push_back({-1, -1});     vector<int> sz(1, 0);     auto add = [&](int x) {       int v = 0;       for (int i = w - 1; i >= 0; --i) {         int b = (x >> i) & 1;         ++sz[v];         if (binTrie[v][b] >= 0) {           v = binTrie[v][b];           continue;         }         int v_ = binTrie.size();         binTrie[v][b] = v_;         binTrie.push_back({-1, -1});         sz.push_back(0);         v = v_;       }       ++sz[v];     };     auto xor_lower_bound_size = [&](int x, int k) {       int v = 0, ret = 0;       for (int i = w - 1; i >= 0; --i) {         int b = ((x ^ k) >> i) & 1;         int t = (k >> i) & 1;         if ((!t) and binTrie[v][b ^ 1] >= 0) ret += sz[binTrie[v][b ^ 1]];         if (binTrie[v][b] < 0) {           v = -1;           break;         }         v = binTrie[v][b];       }       if (v >= 0) ret += sz[v];       return ret;     };     vector<int> A(N + 1);     for (int i = 0; i < N; ++i) {       cin >> A[i + 1];       A[i + 1] ^= A[i];     }     long long ans = 0;     for (int i = 0; i <= N; ++i) {       ans += xor_lower_bound_size(A[i], K);       add(A[i]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k > n) {         cout <<  NO n ;         continue;       }       if (n % 2 == 0 && k % 2 == 1 && k > n / 2) {         cout <<  NO n ;         continue;       }       if (n % 2 != 0 && k % 2 == 0) {         cout <<  NO n ;         continue;       }       if (k % 2 != n % 2) {         cout <<  YES n ;         cout << n - 2 * (k - 1) <<    ;         for (long long i = 0; i < k - 1; i++) cout << 2 <<    ;         cout << endl;         continue;       }       if (n % 2 == k % 2) {         cout <<  YES n ;         cout << n - (k - 1) <<    ;         for (long long i = 0; i < k - 1; i++) cout << 1 <<    ;         cout << endl;         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     while ((a = a % b) != 0) {       swap(a, b);     }     return b;   }   long long mpow(long long x, long long y, long long m) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x % m;       y = y >> 1;       x = x * x % m;     }     return res;   }   long long ncr(long long n, long long r) {     if (r > n) return 0;     long long res = 1;     for (long long i = (1); i < (r + 1); i++) res = res * (n - r + i) / i;     return res;   }   long long *sieve(long long n) {     long long *lpf = new long long[n + 1];     for (long long i = 1; i <= n; i++) lpf[i] = i;     long long rt = (long long)floor(sqrt(n)) + 1;     for (long long i = (2); i < (rt); i++) {       if (lpf[i] != i) continue;       for (long long j = i * i; j <= n; j += i) {         if (lpf[j] == j) lpf[j] = i;       }     }     return lpf;   }   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = (0); i < (n); i++) cin >> a[i];     long long mx = *max_element(a, a + n), mn = *min_element(a, a + n);     if (mx == mn) {       if (mx != 0)         cout <<  NO ;       else {         cout <<  YES n ;         for (long long i = (0); i < (n); i++) cout <<  1  ;       }       return;     }     long long k;     for (long long i = (0); i < (n); i++) {       long long prev = i - 1;       if (prev == -1) prev = n - 1;       if (a[i] == mx && a[prev] != mx) {         k = i;         break;       }     }     long long pt = k;     long long b[n];     b[pt] = mx;     pt--;     if (pt == -1) pt = n - 1;     if (a[pt] == 0)       b[pt] = mx * 2;     else       b[pt] = mx + a[pt];     pt--;     if (pt == -1) pt = n - 1;     while (pt != k) {       b[pt] = b[(pt + 1) % n] + a[pt];       pt--;       if (pt == -1) pt = n - 1;     }     cout <<  YES n ;     for (long long i = (0); i < (n); i++) cout << b[i] <<    ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = (1); i < (t + 1); i++) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     vector<pair<int, int>> a, b;     a.resize(n);     for (int i = 0; i < n; ++i) {       a[i].second = i;       cin >> a[i].first;     }     sort(a.begin(), a.end());     b.resize(n);     for (int i = 0; i < n; ++i) {       b[i].second = i;       cin >> b[i].first;     }     sort(b.begin(), b.end());     vector<long long> sum;     sum.resize(n * 2 + 1);     for (int i = 0; i < n * 2 + 1; ++i) {       sum[i] = 0;     }     for (int i = 0, p0 = 0, p1 = 0, p2 = 0; i < n; ++i) {       while (p0 < n && b[p0].first < a[i].first - 1.0 * m / 2) {         ++p0;       }       while (p1 < n && b[p1].first < a[i].first) {         ++p1;       }       while (p2 < n && b[p2].first < a[i].first + 1.0 * m / 2) {         ++p2;       }       int beg = n - i;       sum[beg + 0] += m - a[i].first;       sum[beg + p0] -= m - a[i].first;       sum[beg + p0] += a[i].first;       sum[beg + p1] -= a[i].first;       sum[beg + p1] += -a[i].first;       sum[beg + p2] -= -a[i].first;       sum[beg + p2] += m + a[i].first;       sum[beg + n] -= m + a[i].first;     }     for (int i = 1; i < n * 2; ++i) {       sum[i] += sum[i - 1];     }     for (int i = 0; i < n; ++i) {       sum[i] += sum[i + n];     }     vector<long long> rsum;     rsum.resize(n * 2 + 1);     for (int i = 0; i < n * 2 + 1; ++i) {       rsum[i] = 0;     }     for (int i = 0, p0 = 0, p1 = 0, p2 = 0; i < n; ++i) {       while (p0 < n && a[p0].first <= b[i].first - 1.0 * m / 2) {         ++p0;       }       while (p1 < n && a[p1].first <= b[i].first) {         ++p1;       }       while (p2 < n && a[p2].first <= b[i].first + 1.0 * m / 2) {         ++p2;       }       int beg = n - i - 1;       rsum[beg + 0] += -b[i].first;       rsum[beg + p0] -= -b[i].first;       rsum[beg + p0] += b[i].first;       rsum[beg + p1] -= b[i].first;       rsum[beg + p1] += -b[i].first;       rsum[beg + p2] -= -b[i].first;       rsum[beg + p2] += b[i].first;       rsum[beg + n] -= b[i].first;     }     for (int i = 1; i < n * 2; ++i) {       rsum[i] += rsum[i - 1];     }     for (int i = 0; i < n; ++i) {       rsum[i] += rsum[i + n];     }     vector<long long> cost;     cost.resize(n);     for (int i = 0; i < n; ++i) {       cost[i] = sum[i] + rsum[n - 1 - i];     }     long long cur = (long long)(1e18);     int pos;     for (int i = 0; i < n; ++i) {       if (cost[i] < cur) {         cur = cost[i];         pos = i;       }     }     cout << cur << endl;     vector<int> at;     at.resize(n);     for (int i = 0; i < n; ++i) {       at[a[i].second] = b[(i + pos) % n].second;     }     for (int i = 0; i < n; ++i) {       cout << at[i] + 1 <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getFldsFromLine(char *line, std::vector<char *> &res,                       const char *sep =    t n v f r );   int main(int argc, char **argv) {     FILE *infile = stdin;     char *line;     line = (char *)calloc(5000000, sizeof(char));     if (line == NULL) {       fprintf(stderr,  Couldn t allocate space for  %s  nBye! n ,  line );       exit(-1);     };     std::vector<char *> flds;     int numFlds, numCases, caseNum = 0;     fgets(line, 5000000, infile);     numFlds = getFldsFromLine(line, flds);     numCases = atoi(flds[0]);     bool isGood = false;     for (caseNum = 1; caseNum <= numCases; ++caseNum) {       fgets(line, 5000000, infile);       numFlds = getFldsFromLine(line, flds);       int num1 = atoi(flds[1]), num2 = atoi(flds[2]);       if ((num1 >= 2400) && (num2 > num1)) isGood = true;     }     if (isGood)       printf( YES n );     else       printf( NO n );     return (0);   }   int getFldsFromLine(char *line, std::vector<char *> &res, const char *sep) {     res.clear();     char *tok = strtok(line, sep);     while (tok) {       res.push_back(tok);       tok = strtok(0, sep);     }     return res.size();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, j, i, l, r, ans = 0, x, y, minimum;     scanf( %d , &n);     scanf( %d , &k);     int count_a[n], count_b[n];     char str[n + 1], ch;     scanf( %s , str);     for (i = 0; i < n; i++) {       count_a[i] = 0;       count_b[i] = 0;     }     for (i = 0; i < n; i++) {       if (str[i] ==  a ) count_a[i]++;       if (str[i] ==  b ) count_b[i]++;     }     for (i = 1; i < n; i++) {       count_a[i] += count_a[i - 1];       count_b[i] += count_b[i - 1];     }     l = 0;     r = 0;     while (r < n) {       if (l == 0) {         x = count_a[r];         y = count_b[r];       } else {         x = count_a[r] - count_a[l - 1];         y = count_b[r] - count_b[l - 1];       }       minimum = min(x, y);       if (k >= minimum) {         ans = max(ans, r - l + 1);         r++;       } else         l++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n, q, a, b, blo, arr[N];   struct node {     int a, b, id;   } qq[N];   long long ans[N], dp[N];   bool cmp(node a, node b) {     if (a.b != b.b) return a.b > b.b;     return a.a < b.a;   }   int main() {     scanf( %d , &n);     blo = sqrt(n);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &qq[i].a, &qq[i].b);       qq[i].id = i;     }     sort(qq + 1, qq + q + 1, cmp);     int n_b = -1;     for (int i = 1; i <= q; i++) {       node nn = qq[i];       if (nn.b >= blo) {         for (int i = nn.a; i <= n; i += nn.b) ans[nn.id] += arr[i];       } else {         if (nn.b != n_b || dp[nn.a] == 0) {           for (int j = n; j >= 1; j--) {             if (j + nn.b > n)               dp[j] = arr[j];             else               dp[j] = dp[j + nn.b] + arr[j];           }           n_b = nn.b;         }         ans[nn.id] = dp[nn.a];       }     }     for (int i = 1; i <= q; i++) {       printf( %I64d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool possible(int smaller, int bigger) { return (bigger <= smaller * 3 + 1); }   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int b, w;       cin >> b >> w;       if ((b < w && !possible(b, w)) || (w < b && !possible(w, b))) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       int offset = (b < w) ? 1 : 0;       if (b < w) swap(b, w);       int column = 1;       while (w + 1 < b) {         cout << column <<     << (2 + offset) << endl;         column++;         cout << column <<     << (1 + offset) << endl;         cout << column <<     << (2 + offset) << endl;         cout << column <<     << (3 + offset) << endl;         column++;         w -= 1;         b -= 3;       }       if (w < b) {         cout << column <<     << (2 + offset) << endl;         b--;         column++;       }       for (; 0 < b; b--) {         cout << column <<     << (1 + offset) << endl;         cout << column <<     << (2 + offset) << endl;         column++;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int man = 0, ans = 0, n, m;     int a[1000];     while (cin >> n >> m) {       ans = 0;       if (n > m) {         printf( %d n , n - m);       } else {         while (n < m) {           if (m % 2 != 0) {             m++;             ans++;           }           m /= 2;           ans++;         }         ans += n - m;         printf( %d n , ans);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double pi = acos(-1);   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 1000000 + 10;   int n, arr[nax];   int main() {     ios::sync_with_stdio(0);     cin >> n;     if (n % 10 == 0) {       cout << n;       return 0;     }     if (n <= 5)       cout << 0;     else {       int div = (n + 10 - 1) / 10;       int ans = 10 * div;       int rem = (n % 10);       if (rem <= 5) ans -= 10;       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     if (k > (n * n + 1) / 2) {       printf( NO );       return 0;     }     int i, j, count = 0;     printf( YES n );     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if ((i + j) % 2 == 0 and count < k) {           count++;           printf( L );         } else           printf( S );       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 36;   long long dp[maxn][maxn];   int main() {     long long n, h;     cin >> n >> h;     for (long long i = 0; i <= n; i++) dp[0][i] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++)         for (long long k = 0; k < i; k++) {           dp[i][j] += dp[k][j - 1] * dp[i - 1 - k][j - 1];         }     cout << dp[n][n] - dp[n][h - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string ans1, ans2;     string s1, s2, ss1, ss2;     int a, b;     cin >> s1 >> s2;     a = atoi(s1.c_str()) + atoi(s2.c_str());     stringstream ss;     ss << a;     ss >> ans1;     for (int i = 0; i < s1.length(); ++i) {       if (s1[i] !=  0 ) {         ss1 += s1[i];       }     }     for (int i = 0; i < ans1.length(); ++i) {       if (ans1[i] !=  0 ) {         ans2 += ans1[i];       }     }     for (int i = 0; i < s2.length(); ++i) {       if (s2[i] !=  0 ) {         ss2 += s2[i];       }     }     b = atoi(ss1.c_str()) + atoi(ss2.c_str());     stringstream sss;     sss << b;     sss >> ans1;     if (ans1 == ans2) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long mod, dp[18][250005];   unsigned long long fac[250005], inv[250005];   unsigned long long n, k;   inline unsigned long long qpow(unsigned long long a, unsigned long long b) {     unsigned long long res = 1ll, tp = a;     while (b) {       if (b & 1ll) {         res *= tp;         res %= mod;       }       tp *= tp;       tp %= mod;       b >>= 1ll;     }     return res;   }   inline unsigned long long cal(int a, int b) {     return (((fac[a] * inv[b]) % mod) * inv[a - b]) % mod;   }   inline unsigned long long calc() {     int i, j, l;     fac[0] = 1ll;     for (i = 1; i <= n; i++)       fac[i] = fac[i - 1] * ((unsigned long long)(i)) % mod;     inv[n] = qpow(fac[n], mod - 2ll);     for (i = n - 1; i >= 0; i--)       inv[i] = inv[i + 1] * ((unsigned long long)(i + 1)) % mod;     for (i = 1; i <= n; i++) {       dp[1][i] = inv[i];     }     unsigned long long ans = dp[1][n] * cal(k, 1) % mod;     int t = min(17, ((int)(k)));     for (i = 2; i <= t; i++) {       for (j = 1; j <= n; j++) {         if ((j & n) != j) {           continue;         }         int cnt = 0;         for (l = j; l; l = (l - 1) & j) {           dp[i][j] += dp[i - 1][j ^ l] * inv[l];           cnt++;           if (cnt == 18) {             cnt = 0;             dp[i][j] %= mod;           }         }         dp[i][j] %= mod;       }       ans += dp[i][n] * cal(k, i);       ans %= mod;     }     ans *= fac[n];     ans %= mod;     return ans;   }   int main() {     cin >> n >> k >> mod;     unsigned long long ans = qpow(k, n);     if (n & 1) {       cout << ans << endl;       return 0;     }     ans = (ans - calc() + mod) % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   static const long long maxn = 2005;   long long M[maxn][maxn];   long long MyM[maxn][maxn];   vector<vector<long long>*> graph;   long long dsu[maxn];   bool PreCheck() {     for (long long i = 0; i < n; i++) {       if (M[i][i] != 0) return false;     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         if (M[i][j] != M[j][i]) return false;       }     return true;   }   long long edge_count = 0;   struct edge {     long long u;     long long v;     long long d;     bool operator<(const edge& rhs) const { return d < rhs.d; }   };   long long dsu_root(long long i) {     while (dsu[i] != i) {       dsu[i] = dsu[dsu[i]];       i = dsu[i];     }     return i;   }   bool dsu_connected(long long i, long long j) {     return dsu_root(i) == dsu_root(j);   }   void dsu_join(long long i, long long j) {     long long r = rand() % 2;     if (r)       dsu[dsu_root(i)] = j;     else       dsu[dsu_root(j)] = i;   }   void init() {     for (long long i = 0; i < n; i++) {       dsu[i] = i;       vector<long long>* v = new vector<long long>();       graph.push_back(v);     }   }   bool dfs_visited[maxn];   void dfs(long long i, long long root, long long curr) {     if (dfs_visited[i]) return;     dfs_visited[i] = true;     for (auto it : *graph[i]) {       if (dfs_visited[it])         continue;       else {         long long d = curr + M[i][it];         MyM[root][it] = d;         MyM[it][root] = d;         dfs(it, root, d);       }     }   }   bool FinalCheck() {     for (long long i = 1; i < n; i++) {       if (!dsu_connected(i, 0)) return false;     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < i; j++) {         if (M[i][j] != MyM[i][j]) return false;       }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     init();     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         cin >> M[i][j];         MyM[i][j] = 0;       }     if (!PreCheck()) {       cout <<  NO  << endl;       return 0;     }     vector<edge> edges;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < i; j++) {         edge curr;         curr.u = i;         curr.v = j;         curr.d = M[i][j];         if (curr.d > 0) edges.push_back(curr);       }     sort(edges.begin(), edges.end());     for (auto it : edges) {       if (!dsu_connected(it.u, it.v)) {         edge_count++;         graph[it.u]->push_back(it.v);         graph[it.v]->push_back(it.u);         dsu_join(it.u, it.v);       }     }     if (edge_count != n - 1) {       cout <<  NO  << endl;       return 0;     }     for (long long i = 0; i < n; i++) {       memset(dfs_visited, 0, sizeof(dfs_visited));       dfs(i, i, 0);     }     if (FinalCheck()) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }