malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, k, sum1, sum2;   string a;   int f[300011];   void solve() {     scanf( %d%d , &n, &k);     cin >> a;     memset(f, -1, sizeof(f));     for (int i = 0; i < n; i++) {       if (a[i] !=  ? ) {         if (f[i % k] == -1)           f[i % k] = a[i] -  0 ;         else if (f[i % k] != (int)(a[i] -  0 )) {           cout <<  NO  << endl;           return;         }       }     }     sum1 = sum2 = 0;     for (int i = 0; i < k; i++) {       sum1 += (f[i] == 0);       sum2 += (f[i] == 1);     }     if (sum1 > k / 2 || sum2 > k / 2)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }   int main() {     int T;     scanf( %d , &T);     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct tree {     int maxv[650001];     void set(int x, int d, int o, int l, int r) {       if (l == r) {         maxv[o] = d;         return;       }       int m = (l + r) / 2;       if (x <= m)         set(x, d, o * 2, l, m);       else         set(x, d, o * 2 + 1, m + 1, r);       maxv[o] = max(maxv[o * 2], maxv[o * 2 + 1]);     }     int query(int x, int y, int o, int l, int r) {       if (x <= l && r <= y) return maxv[o];       int m = (l + r) / 2, ans = 0;       if (x <= m) ans = max(ans, query(x, y, o * 2, l, m));       if (y > m) ans = max(ans, query(x, y, o * 2 + 1, m + 1, r));       return ans;     }   } Tx, Ty;   int n, m;   map<int, int> h, pos;   void modify(int x, int y, int val) {     Tx.set(x, val, 1, 1, n);     Ty.set(y, val, 1, 1, m + 20);   }   void remove_all(map<int, int>::iterator del) {     modify(del->first, del->second, 0);     pos.erase(pos.lower_bound(del->second));     h.erase(del);   }   int main() {     scanf( %d%d , &n, &m);     for (int T = 1; T <= m; T++) {       int op, p, v;       scanf( %d%d , &op, &p);       if (op == 1) {         scanf( %d , &v);         v += m - T;         h[p] = v;         pos[v] = p;         auto it = pos.lower_bound(v), it2 = it;         for (;; it2--) {           modify(it2->second, it2->first, 0);           if (it2 == pos.begin()) break;         }         for (;; it--) {           int x = it->second, y = it->first, val = Tx.query(x, n, 1, 1, n) + 1;           modify(x, y, val);           if (it == pos.begin()) break;         }       } else {         auto del = h.begin();         for (int i = 1; i < p; i++) del++;         if (del == h.begin())           remove_all(del);         else {           auto it = del, it2 = --it;           remove_all(del);           for (;; it2--) {             modify(it2->first, it2->second, 0);             if (it2 == h.begin()) break;           }           for (;; it--) {             int x = it->first, y = it->second,                 val = Ty.query(y + 1, m + 20, 1, 1, m + 20) + 1;             modify(x, y, val);             if (it == h.begin()) break;           }         }       }       printf( %d n , Tx.query(1, n, 1, 1, n));     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, d = 0;     long long x, amount;     char sign;     int quantity;     cin >> n >> amount;     for (int i = 0; i < n; i++) {       cin >> sign >> quantity;       if (sign ==  + )         amount += quantity;       else if (amount < quantity)         d++;       else         amount -= quantity;     }     cout << amount <<     << d;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dir[8][2] = {{1, 0},  {0, 1},  {1, 1},   {1, -1},                          {-1, 0}, {0, -1}, {-1, -1}, {-1, 1}};   int n, m, cnt[1000 + 5][1000 + 5];   char a[1000 + 5][1000 + 5];   void work(int x, int y) {     bool flag = true;     for (int i = 0; i < 8; i++) {       int nx = x + dir[i][0], ny = y + dir[i][1];       if (a[nx][ny] ==  . ) flag = false;     }     if (flag)       for (int i = 0; i < 8; i++) {         int nx = x + dir[i][0], ny = y + dir[i][1];         cnt[nx][ny]++;       }   }   bool judge() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] ==  #  && cnt[i][j] == 0) return false;     return true;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 2; i <= n - 1; i++)       for (int j = 2; j <= m - 1; j++) work(i, j);     if (judge())       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   int n, m, i, j, vis[100005], ve[100005], dep[100005];   long long a[100005], px[100005], py[100005], res[100005];   vector<int> e[100005];   void dfs1(int x) {     vis[x] = 1;     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       if (!ve[*it]) {         int y = px[*it] ^ py[*it] ^ x;         if (!vis[y]) {           ve[*it] = 1;           dep[y] = dep[x] + 1;           dfs1(y);           res[*it] += a[y];           a[x] -= a[y];           a[y] = 0;         }       }     }   }   int main() {     read(n);     read(m);     for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]);     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       int x, y;       read(x);       read(y);       px[i] = x;       py[i] = y;       e[x].push_back(i);       e[y].push_back(i);     }     dfs1(1);     for (((i)) = (1); ((i)) <= ((m)); ((i))++)       if (!ve[i]) {         if (!((dep[px[i]] ^ dep[py[i]]) & 1)) {           if (dep[px[i]] & 1)             res[i] -= a[1] / 2;           else             res[i] = +a[1] / 2;           a[px[i]] -= res[i];           a[py[i]] -= res[i];           break;         }       }     memset(vis, 0, sizeof(vis));     memset(ve, 0, sizeof(ve));     dfs1(1);     if (a[1]) {       puts( NO );       return 0;     }     puts( YES );     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       printf( %lld n , res[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int t, o, c;   };   char s[4000010];   int n, o[4000010], c[4000010], t[4000010];   void build(int id, int l, int r) {     if (r - l < 1) {       if (s[r] ==  ( )         o[id] = 1;       else         c[id] = 1;       return;     }     int mid = (l + r) / 2;     build(2 * id, l, mid);     build(2 * id + 1, mid + 1, r);     int temp = min(o[2 * id], c[2 * id + 1]);     t[id] = t[2 * id] + t[2 * id + 1] + temp;     o[id] = o[2 * id] + o[2 * id + 1] - temp;     c[id] = c[2 * id] + c[2 * id + 1] - temp;   }   node query(int x, int y, int l, int r, int id) {     if (y < l || x > r || r < l) return {0, 0, 0};     if (r - l < 1) {       if (s[r] ==  ( )         return {0, 1, 0};       else         return {0, 0, 1};     }     if (x <= l && y >= r) return {t[id], o[id], c[id]};     node na, nb;     na = query(x, y, l, (l + r) / 2, 2 * id);     nb = query(x, y, (l + r) / 2 + 1, r, 2 * id + 1);     int t = min(na.o, nb.c);     return {na.t + nb.t + t, na.o + nb.o - t, na.c + nb.c - t};   }   int main() {     int i, x, y, j, num, k, m, w, l, r, p;     scanf( %s , s);     n = strlen(s);     build(1, 0, n - 1);     scanf( %d , &m);     for (i = (1); i <= (m); i++) {       scanf( %d%d , &l, &r);       node nd = query(l - 1, r - 1, 1 - 1, n - 1, 1);       printf( %d n , 2 * nd.t);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     stack<char> s;     int n, count = 0;     char c;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c;       if (s.empty())         s.push(c);       else if (s.top() == c) {         s.pop();         s.push(c);         count++;       } else         s.push(c);     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j;   int main() {     string str;     int b = 0, e = 0, a = 0, r = 0, s = 0;     cin >> str;     if (str.size() >= 4)       for (i = 0; i < str.size() - 3; i++) {         for (j = i; j < str.size(); j++) {           if (str[j] ==  b  && str[j + 1] ==  e  && str[j + 2] ==  a  &&               str[j + 3] ==  r ) {             s = s + str.size() - j - 3;             break;           }         }       }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   bool debug = 1;   const int N = 1e5 + 10;   bool vis[N];   int g[N];   int dfs(int i) {     vis[i] = 1;     if (!vis[g[i]]) {       return 1 + dfs(g[i]);     }     return 1;   }   int main() {     int n, x;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       x--;       g[i] = x;     }     vector<int> vc;     for (int i = 0; i < n; i++) {       if (!vis[i]) vc.push_back(dfs(i));     }     long long tot = 0;     sort(vc.begin(), vc.end(), greater<int>());     for (int i = 0; i < min((int)vc.size(), 2); i++) {       tot += vc[i];     }     tot = tot * tot;     for (int i = 2; i <= vc.size() - 1; i++) {       tot += 1ll * vc[i] * vc[i];     }     cout << tot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   inline string get() {     char ch[2000010];     scanf( %s , ch);     return ch;   }   inline void read(long long *a, long long n) {     for (long long i = 0; i < n; i++) a[i] = in();   }   template <class blank>   inline void out(blank x) {     cout << x <<   n ;     exit(0);   }   const long long maxn = 1e5 + 10;   const long long maxm = 1e6 + 10;   const long long maxlg = 21;   const long long base = 29;   const long long mod = 1e9 + 7;   const long long INF = 1e18 + 10;   const long long SQ = 317 + 5;   vector<long long> g[maxn];   long long h[maxn], st[maxn], root[maxn][maxlg], cur;   struct cmp {     inline bool operator()(const long long &a, const long long &b) const {       return st[a] < st[b];     }   };   set<long long, cmp> SET;   inline void dfs(long long node, long long fa = 0) {     h[node] = fa == 0 ? 0 : h[fa] + 1;     root[node][0] = fa;     st[node] = cur++;     for (long long i = 1; i < maxlg; i++)       root[node][i] = root[root[node][i - 1]][i - 1];     for (auto u : g[node])       if (u - fa) dfs(u, node);   }   inline long long lca(long long p, long long q) {     if (h[p] < h[q]) swap(p, q);     for (long long i = maxlg - 1; i >= 0; i--)       if (h[p] - (1 << i) >= h[q]) p = root[p][i];     if (p == q) return p;     for (long long i = maxlg - 1; i >= 0; i--)       if (root[p][i] != root[q][i]) p = root[p][i], q = root[q][i];     return root[p][0];   }   inline long long dis(long long v, long long u) {     return h[v] + h[u] - 2 * h[lca(v, u)];   }   inline long long add(long long x, long long fl = 0, long long tp = 0) {     if (SET.empty() || (SET.size() == 1 && tp == 1)) {       if (fl) {         if (tp == 0)           SET.insert(x);         else           SET.erase(x);       }       return 1 * (tp == 0 ? 1 : -1);     }     long long pre, nxt;     set<long long>::iterator it, it2;     it = it2 = SET.upper_bound(x);     if (it == SET.end()) it = SET.begin();     if (it2 == SET.begin()) it2 = SET.end();     it2--;     if (*it2 == x) {       if (it2 == SET.begin()) it2 = SET.end();       it2--;     }     pre = *it2, nxt = *it;     if (fl) {       if (tp == 0)         SET.insert(x);       else         SET.erase(x);     }     return (dis(x, pre) + dis(x, nxt) - dis(pre, nxt)) / 2 * (tp == 0 ? 1 : -1);   }   long long tot;   long long res;   int32_t main() {     long long n = in(), k = in();     for (long long i = 0; i < n - 1; i++) {       long long v = in(), u = in();       g[v].push_back(u);       g[u].push_back(v);     }     dfs(1);     long long r = 1;     for (long long i = 1; i <= n; i++) {       while (r <= n && add(r) + tot <= k) tot += add(r++, 1);       res = max(res, r - i);       if (r == i) r++;       tot += add(i, 1, 1);     }     cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   FILE *outt, *inn;   const int N = 3e5 + 10;   int n, a[N], res[N], ans, c, l, r;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     ans = -1;     for (int i = 0; i < n; i++) {       l = r = i;       while (l > 0 && a[l - 1] % a[i] == 0) l--;       while (r < n - 1 && a[r + 1] % a[i] == 0) r++;       if ((r - l) > ans) ans = r - l, c = 0;       if ((r - l) == ans) res[c++] = l;       i = r;     }     printf( %d %d n , c, ans);     for (int i = 0; i < c; i++) {       printf( %d  , res[i] + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int test, i, j, count, flag = 0, n, o1 = 0, o2 = 0, b1, x, y, m, l,                                      z, max1, x1, y1, x2, y2, z1, k, sum, f, r,                                      ans1, min1;     cin >> n;     long long int a[n];     if (n == 1) {       cin >> x;       cout <<  1  n  << x;       return 0;     }     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     vector<long long int> a1;     vector<long long int> a2;     flag = 0;     for (i = 0; i < n; i++) {       if (a1.size() == 0) {         a1.push_back(a[i]);       } else {         if (a2.size() == 0) {           a2.push_back(a[i]);         } else {           if (a2.back() != a[i]) {             a2.push_back(a[i]);           } else {             if (a1.back() != a[i]) {               a1.push_back(a[i]);             }           }         }       }     }     if (a1.size() >= 1 && a2.size() >= 1) {       if (a1.back() == a2.back()) {         a1.pop_back();       }     }     cout << a1.size() + a2.size() <<   n ;     for (i = 0; i < a1.size(); i++) {       cout << a1[i] <<    ;     }     for (i = a2.size() - 1; i >= 0; i--) {       cout << a2[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, h, p[N], q[N], bit[N];   void update(int x, int v) {     for (; x < n; x += (x + 1) & -(x + 1)) bit[x] += v;   }   int sum(int x) {     int res = 0;     for (; x >= 0; x -= (x + 1) & -(x + 1)) res += bit[x];     return res;   }   void solve() {     fill(bit, bit + n, 0);     for (int i = n - 1; i >= 0; i--) {       int x = sum(p[i] - 1);       update(p[i], 1);       p[i] = x;     }     fill(bit, bit + n, 0);     for (int i = n - 1; i >= 0; i--) {       int x = sum(q[i] - 1);       update(q[i], 1);       q[i] = x;     }     for (int i = n - 1; i >= 0; i--) {       int c = (p[i] + q[i]) / (n - i);       p[i] = (p[i] + q[i]) % (n - i);       if (i > 0) {         p[i - 1] += c;       }     }     fill(bit, bit + n, 0);     for (int i = 0; i < n; i++) update(i, 1);     for (int i = 0; i < n; i++) {       if (i) printf(   );       int lo = 0, hi = n;       while (lo < hi) {         int m = lo + (hi - lo) / 2;         if (p[i] + 1 <= sum(m))           hi = m;         else           lo = m + 1;       }       printf( %d , lo);       update(lo, -1);     }     printf(  n );   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , p + i);     for (int i = 0; i < n; i++) scanf( %d , q + i);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ara[400005], csum1[400005], csum2[400005];   int main() {     int n;     scanf( %d , &n);     long long sum = 0;     for (int i = 0; i < n; i++)       scanf( %lld , &ara[i]), sum += ara[i], csum1[ara[i]] += ara[i],           csum2[ara[i]]++;     for (int i = 1; i <= 400000; i++)       csum1[i] += csum1[i - 1], csum2[i] += csum2[i - 1];     sort(ara, ara + n);     long long res = 0, lft = 0;     for (int i = 0; i < n; i++) {       long long s = 0;       int x = ara[i];       while (i < n && ara[i] == x) s += ara[i], i++;       i--;       long long temp = 0;       for (int j = x; j <= 200000; j += x)         temp += (csum1[j + x - 1] - csum1[j]) - (csum2[j + x - 1] - csum2[j]) * j;       res = max(res, sum - temp - lft);       lft += s;     }     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   int mod = 1000000007;   db pie = 3.1415926535;   int spf[5000005];   int mm = 5000000;   int pre[5000005];   void help() {     int i;     for (i = 1; i <= mm; i++) {       spf[i] = i;     }     for (i = 2; i <= mm; i += 2) {       spf[i] = 2;     }     int j;     for (i = 3; i * i <= mm; i += 2) {       if (spf[i] == i) {         for (j = i * i; j <= mm; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }     pre[0] = 0;     pre[1] = 0;     for (i = 2; i <= mm; i++) {       int m = i;       int cnt = 0;       while (m > 1) {         cnt++;         m = m / spf[m];       }       pre[i] = cnt;       pre[i] += pre[i - 1];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     help();     while (t--) {       int a, b;       cin >> a >> b;       int ans = pre[a] - pre[b];       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Query {     int left;     int right;     int index;     bool operator<(const Query &other) const { return right < other.right; }   };   const int N = 1e6 + 100;   int a[N];   int xorSum[N];   Query q[N];   int ans[N];   struct FenwickTree {     FenwickTree() { fill(array, array + N, 0); }     int lowbit(int a) { return a & -a; }     void update(int i, int value) {       while (i <= n) {         array[i] ^= value;         i += lowbit(i);       }     }     int query(int i) {       int res = 0;       while (i > 0) {         res ^= array[i];         i -= lowbit(i);       }       return res;     }     int n;     int array[N];   } tr;   int main() {     int n, m, i, j;     scanf( %d , &n);     tr.n = n;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     scanf( %d , &m);     for (i = 1; i <= m; i++) {       scanf( %d%d , &q[i].left, &q[i].right);       q[i].index = i;     }     sort(q + 1, q + 1 + m);     map<int, int> last;     for (i = 1, j = 1; i <= n; i++) {       int &lastTmp = last[a[i]];       if (lastTmp > 0) {         tr.update(lastTmp, a[i]);       }       lastTmp = i;       tr.update(i, a[i]);       xorSum[i] = xorSum[i - 1] ^ a[i];       for (; j <= m && q[j].right == i; j++) {         ans[q[j].index] = xorSum[i] ^ xorSum[q[j].left - 1] ^                           tr.query(q[j].right) ^ tr.query(q[j].left - 1);       }     }     for (i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long expr(long long n, long long e) {     if (e == 0) return 1;     if (e & 1) {       return n * expr(n, e ^ 1);     } else       return expr(n, e >> 1) * expr(n, e >> 1);   }   int main() {     long long n, l, r;     scanf( %lld %lld %lld , &n, &l, &r);     long long count = 0;     long long root = 0.000001 + pow((double)r, 1.0 / ((double)n - 1.0));     if (n == 1) {       printf( %lld n , r - l + 1);       return 0;     }     if (n == 2) {       printf( %lld n , (r - l + 1) * (r - l));       return 0;     };     for (long long i = 1; i <= root; i++) {       for (long long j = i + 1; j <= root; j++) {         if (gcd(i, j) == 1) {           long long maxb = r / expr(j, n - 1);           long long minb = ceil((double)l / (double)expr(i, n - 1));           ;           count += max(0ll, maxb - minb + 1);         }       }     }     printf( %lld n , 2 * count);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100009;   const long long MOD = 1e9 + 7;   int dX[] = {0, 0, 1, -1};   int dY[] = {1, -1, 0, 0};   long long GCD(long long num, long long ones) {     return !ones ? num : GCD(ones, num % ones);   }   string s;   map<int, int> mp;   long long ans, sum;   int arr[4040];   int main() {     scanf( %lld , &sum);     cin >> s;     int n = (s.size());     for (int i = 0; i < n; ++i) arr[i + 1] = s[i] -  0 , arr[i + 1] += arr[i];     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j <= n; ++j) {         mp[arr[j] - arr[i]]++;       }     }     if (sum == 0) {       if (mp.count(0))         cout << mp[0] * (n * 1LL * n - mp[0] + n);       else         puts( 0 );       return 0;     }     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {       if (!it->first) continue;       if (sum % it->first == 0 && mp.count(sum / it->first))         ans += mp[sum / it->first] * 1LL * it->second;     }     cout << ans;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   #define int ll   typedef pair<int, int> P;   ll gcd(ll a, ll b){return b? gcd(b, a % b): a;}   ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;}   // head      const int N = 2e3 + 5, inf = 1e18;   int n, m, w, mat[N][N];   int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};      void bfs(int x0, int y0, vector<vector<int>> &d) {    d.resize(n + 1, vector<int> (m + 1, inf));    queue<pair<int, int>> quu;    quu.push(make_pair(x0, y0));    d[x0][y0] = 0;    while (!quu.empty()) {     int px = quu.front().first, py = quu.front().second;     quu.pop();     for (int i = 0; i < 4; i++) {      int nx = px + dx[i], ny = py + dy[i];      if (1 <= nx && nx <= n && 1 <= ny && ny <= m && mat[nx][ny] != -1 && d[nx][ny] == inf) {       d[nx][ny] = d[px][py] + w;       quu.push(make_pair(nx, ny));      }     }    }   }      void show(vector<vector<int>> &vt) {    for (int i = 1; i <= n; i++) {     for (int j = 1; j <= m; j++) {      cout << vt[i][j] <<    ;     }     cout << endl;    }   }      signed main(void){    ios::sync_with_stdio(false);    cin.tie(0);    cin >> n >> m >> w;    for (int i = 1; i <= n; i++) {     for (int j = 1; j <= m; j++) {      cin >> mat[i][j];     }    }    vector<vector<int>> d1, d2;    bfs(1, 1, d1);    bfs(n, m, d2);    int ans = d1[n][m];    int mn1 = inf;    for (int i = 1; i <= n; i++) {     for (int j = 1; j <= m; j++) {      if (mat[i][j] <= 0) continue;      mn1 = min(mn1, d1[i][j] + mat[i][j]);     }    }    int mn2 = inf;    for (int i = 1; i <= n; i++) {     for (int j = 1; j <= m; j++) {      if (mat[i][j] <= 0) continue;      mn2 = min(mn2, d2[i][j] + mat[i][j]);     }    }    ans = min(ans, mn1 + mn2);    if (ans == inf) {     cout << -1 << endl;    }    else {     cout << ans << endl;    }    return 0;   }