malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010;   int n;   long long w[maxn], ma[maxn][2], ans;   vector<int> a[maxn];   vector<long long> c[maxn];   bool visited[maxn];   void dfs(int u) {     visited[u] = true;     for (int i = 0; i < (int)a[u].size(); ++i) {       int v = a[u][i];       if (visited[v]) continue;       dfs(v);       long long vC = ma[v][0] - c[u][i];       if (vC > ma[u][0]) {         ma[u][1] = ma[u][0];         ma[u][0] = vC;       } else {         if (vC > ma[u][1]) {           ma[u][1] = vC;         }       }     }     ans = max(ans, ma[u][0] + ma[u][1] + w[u]);     ma[u][0] += w[u];     ma[u][1] += w[u];   }   int main(int argc, const char* argv[]) {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> w[i];     }     for (int i = 1; i < n; ++i) {       int u, v, C;       cin >> u >> v >> C;       a[u].push_back(v);       c[u].push_back(C);       a[v].push_back(u);       c[v].push_back(C);     }     dfs(1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 9;   int a[N], b[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) cin >> b[i];       int ok = 1;       if (a[1] != b[1]) ok = 0;       map<int, int> cnt;       cnt[a[1]]++;       for (int i = 2; i <= n; i++) {         if (a[i] < b[i] && cnt[1] == 0) ok = 0;         if (a[i] > b[i] && cnt[-1] == 0) ok = 0;         cnt[a[i]] = 1;       }       if (ok)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void read_file(bool outToFile = true) {}   int A[500 + 9];   int n, m, b, mod;   int dp[2][500 + 9 + 2][500 + 9 + 1];   int build() {     int p = 0;     for (int c = 0; c <= b; c++) dp[p][0][c] = dp[!p][0][c] = 1;     for (int c = 0; c <= b; c++)       for (int r = 1; r <= m; r++) dp[p][r][c] = 0;     for (int i = n - 1; i >= 0; i--) {       p = !p;       for (int r = 1; r <= m; r++)         for (int c = b; c >= 0; c--)           if (A[i] + c <= b)             dp[p][r][c] = (dp[!p][r][c] + dp[p][r - 1][c + A[i]]) % mod;           else             dp[p][r][c] = dp[!p][r][c];     }     return dp[p][m][0];   }   int main() {     read_file(false);     while (cin >> n >> m >> b >> mod) {       for (int i = 0; i < n; i++) cin >> A[i];       cout << build() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }   const int MAXN = 100010;   int fst[MAXN], sec[MAXN];   int ans[MAXN];   int N, K;   int cmp(const int &a, const int &b) { return a > b; }   int main() {     while (scanf( %d%d , &N, &K) != EOF) {       for (int i = 1; i <= N; i++) scanf( %d , &fst[i]);       for (int i = 1; i <= N; i++) scanf( %d , &sec[i]);       sort(fst + 1, fst + 1 + N, cmp);       sort(sec + 1, sec + 1 + N, cmp);       int pos = N;       int cnt = 0, stepl = 1, stepr = N;       while (cnt < N && stepl <= N && stepr >= 1) {         if (fst[stepl] + sec[stepr] >= K) {           ans[cnt++] = fst[stepl] + sec[stepr];           stepl++;           stepr--;         } else {           stepr--;         }       }       int tot = 0;       for (int i = 0; i < N; i++)         if (ans[i] >= K) tot++;       printf( 1 %d n , min(tot, pos));     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000 )   using namespace std;   template <class T>   T inline sqr(T x) {     return x * x;   }   const double pi = 3.1415926535897932384626433832795;   const double eps = 1e-8;   long long ans = 0;   bool f(long long x, long long y, long long n) {     long long s = x + y;     long long ch = -n / (x * y) + x + y;     long long zn = 2;     long long w = ch / zn;     if (ch == w * zn)       if (1 <= w && w < x && w < y) {         long long k1 = x - w, k2 = y - w, k3 = w;         if (k3 < k2) return true;         if (k1 == k2) {           if (k2 == k3)             ans++;           else             ans += 3;         } else {           if (k2 == k3)             ans += 3;           else             ans += 6;         }       }     return false;   }   int main() {     long long n;     cin >> n;     if (n % 3 != 0) {       cout <<  0 ;       return 0;     }     vector<long long> a, b;     for (long long i = 1; i * i <= n; i++)       if (n % i == 0) {         if (i > 0) a.push_back(i);         if (i * i != n) b.push_back(n / i);       }     for (int i = b.size() - 1; i >= 0; i--) a.push_back(b[i]);     cerr << a.size() << endl;     n /= 3;     int Q = 0;     for (int i = 0; i < a.size(); i++)       if (n % a[i] == 0) {         long long d = n / a[i];         int x = lower_bound(a.begin(), a.end(), d) - a.begin();         for (int j = x; j >= i; j--)           if (d % a[j] == 0) {             if (f(a[i], a[j], n)) break;           }       }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, s, vis[100005], cy;   long long t;   int nex(int x, int y) {     if (x < m)       return (x + y) % n;     else       return (x - y + n) % n;   }   int main() {     scanf( %d %d , &n, &m);     scanf( %d %lld , &s, &t);     --s;     while (t % n != 0) {       s = nex(s, t % n);       --t;     }     t /= n;     while (t && (!vis[s])) {       vis[s] = ++cy;       for (int y = n - 1; y > 0; --y) s = nex(s, y);       --t;     }     if (!t) {       cout << s + 1;       return 0;     }     t %= (cy + 1 - vis[s]);     while (t) {       for (int y = n - 1; y > 0; --y) s = nex(s, y);       --t;     }     cout << s + 1;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   static ostream& operator<<(ostream& stream, const vector<T>& t);   template <typename T>   static istream& read(T, T, istream& = cin);   template <typename T>   static istream& operator>>(istream& stream, vector<T>& t) {     return read((t).begin(), (t).end(), stream);   }   template <typename T>   static istream& read(T b, T e, istream& stream) {     for (T it = b; it != e; ++it) stream >> *it;     return stream;   }   template <typename T>   static void print(T x, string end =   n ) {     cout << x << end;   }   template <typename T>   static ostream& print(T b, T e, string sep =    , ostream& stream = cout) {     for (T it = b; it != e; ++it) {       stream << *it;       if (it + 1 != e) stream << sep;     }     return stream;   }   template <typename T>   static void print(vector<T> arr, string sep =    ) {     if (arr.empty()) {       return;     }     print(arr.begin(), arr.end(), sep);     cout <<   n ;   }   void _() {     int n;     cin >> n;     vector<int> arr(n);     cin >> arr;     vector<int> tmp(1, n + 1);     vector<string> ans(n + 1, string(n,  0 ));     for (int j = 0; j <= n - 1; ++j) {       int l = 0;       vector<int> n_tmp;       int ones = arr[j], zeros = n + 1 - arr[j];       for (int x : tmp) {         int take_zeros = min(zeros, x - (ones > 0));         int take_ones = x - take_zeros;         if (x == 1) {           if (ones > zeros)             take_ones = 1, take_zeros = 0;           else             take_ones = 0, take_zeros = 1;         }         zeros -= take_zeros;         ones -= take_ones;         for (int i = l; i <= l + take_zeros - 1; ++i) ans[i][j] =  0 ;         l += take_zeros;         for (int i = l; i <= l + take_ones - 1; ++i) ans[i][j] =  1 ;         l += take_ones;         if (take_zeros) n_tmp.push_back(take_zeros);         if (take_ones) n_tmp.push_back(take_ones);       }       tmp = n_tmp;     }     print(n + 1);     print(ans,   n );   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(15);     _();   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     vector<int> dem(1000);     int maxx = INT_MIN;     for (int i = 0; i < n; ++i) {       int u;       cin >> u;       dem[--u]++;       maxx = max(maxx, dem[u]);     }     if (n - maxx < maxx - 1)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10];   int main() {     int n;     while (~scanf( %d , &n)) {       memset(a, 0, sizeof(a));       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       sort(a + 1, a + n + 1);       printf( %d n , a[(1 + n) / 2]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 5005;   int n;   string strs[MAX];   string strp[MAX];   int anspos = 0;   int strlens[MAX];   int vis[MAX];   int change[MAX][2];   string ansa, ansb;   bool cal(int pos) {     int len = strs[pos].size();     strlens[pos] = len;     int l = -1, r = len;     while (l < len && strs[pos][++l] == strp[pos][l])       ;     while (r > 0 && strs[pos][--r] == strp[pos][r])       ;     if (l > r) return 1;     string cnt = strs[pos].substr(l, r - l + 1);     string cnt2 = strp[pos].substr(l, r - l + 1);     if (ansa.size() == 0 && ansb.size() == 0) {       anspos = pos;       ansa = cnt;       ansb = cnt2;     }     if (cnt != ansa || cnt2 != ansb) {       return 0;     }     vis[pos] = 1;     change[pos][0] = l, change[pos][1] = r;     return 1;   }   bool myfinds(string &ps) {     int nowcntlen = ps.size();     for (int i = 0; i < n; i++) {       auto pos = strs[i].find(ps);       if (pos != string::npos) {         string rester =             strs[i].substr(0, pos) + ansb + strs[i].substr(pos + ansb.size());         if (rester != strp[i]) {           return 1;         }       }     }     return 0;   }   int addl, addr;   string pre;   bool check(int len) {     addl = 0, addr = 0;     while (change[anspos][0] > 0) {       int flag = 1;       for (int i = 0; i < n; i++) {         if (i == anspos) continue;         if (!vis[i]) continue;         if (change[i][0] > 0 &&             strs[anspos][change[anspos][0] - 1] == strs[i][change[i][0] - 1]) {           change[i][0]--;         } else {           flag = 0;           break;         }       }       if (flag) {         change[anspos][0]--;         addl++;       } else {         break;       }     }     while (change[anspos][1] < len - 1) {       int flag = 1;       for (int i = 0; i < n; i++) {         if (i == anspos) continue;         if (!vis[i]) continue;         if (change[i][1] < strlens[i] - 1 &&             strs[anspos][change[anspos][1] + 1] == strs[i][change[i][1] + 1]) {           change[i][1]++;         } else {           flag = 0;           break;         }       }       if (flag) {         change[anspos][1]++;         addr++;       } else {         break;       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     ansa.clear(), ansb.clear();     for (int i = 0; i < n; i++) {       cin >> strs[i];     }     for (int i = 0; i < n; i++) {       cin >> strp[i];     }     for (int i = 0; i < n; i++) {       if (!cal(i)) {         cout <<  NO n ;         return 0;       }     }     int nowl = change[anspos][0], nowr = change[anspos][1];     check(strs[anspos].size());     if (addl) {       ansa = strs[anspos].substr(nowl - addl, addl) + ansa;       ansb = strs[anspos].substr(nowl - addl, addl) + ansb;     }     if (addr) {       ansa += strs[anspos].substr(nowr + 1, addr);       ansb += strs[anspos].substr(nowr + 1, addr);     }     if (myfinds(ansa)) {       cout <<  NO n ;     } else {       cout <<  YES n ;       cout << ansa <<   n  << ansb << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > E[1010];   int deg[1010], vis[1010];   vector<pair<int, pair<int, int> > > ans;   int N, P;   int main() {     int u, v, d;     while (~scanf( %d%d , &N, &P)) {       for (int i = 0; i < N; i++) deg[i] = 0, E[i].clear();       for (int i = 0; i < P; i++)         scanf( %d%d%d , &u, &v, &d), u--, v--, deg[v]++,             E[u].push_back(make_pair(v, d));       ans.clear();       for (int i = 0; i < N; i++)         if (deg[i] == 0) {           int dd = 1 << 30, u = i;           for (u = i; E[u].size() > 0; u = E[u][0].first)             dd = min(dd, E[u][0].second);           if (dd < (1 << 30)) ans.push_back(make_pair(i, make_pair(u, dd)));         }       sort(ans.begin(), ans.end());       printf( %d n , ans.size());       for (int i = 0; i < ans.size(); i++)         printf( %d %d %d n , ans[i].first + 1, ans[i].second.first + 1,                ans[i].second.second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[55], b[55];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) scanf( %d , b + i);     long long ans = 1ll << 62;     for (int x = 1; x <= n; x++) {       long long maxv = -(1ll << 62);       for (int y = 1; y <= n; y++) {         if (x == y) continue;         for (int z = 1; z <= m; z++) {           maxv = max(maxv, (long long)a[y] * b[z]);         }       }       ans = min(ans, maxv);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 1E9 + 7;   const int N = 200100;   const double ep = 0.0000001;   int n;   long long x[N], y[N];   long long cx = 0, cy = 0;   void fail() {     cout <<  NO ;     exit(0);   }   bool symmetric(int i, int j) {     long long x1 = cx - x[i] * n;     long long y1 = cy - y[i] * n;     long long x2 = cx - x[j] * n;     long long y2 = cy - y[j] * n;     return (x1 == -x2) && (y1 == -y2);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       cx += x[i];       cy += y[i];     }     if (n % 2 == 1) fail();     int j = 0;     for (j = 1; j < n; j++)       if (symmetric(0, j)) break;     for (int i = 0; i < n; i++, j++) {       if (j == n) j = 0;       if (!symmetric(i, j)) fail();     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   int compare(char *s, char *t, int l) {     int i;     for (i = 0; i < l; i++) {       char a = toupper(s[i]), b = toupper(t[i]);       if (a != b) return a - b;     }     return 0;   }   int main() {     static char ss[100][100 + 1], cc[100 + 1], lucky[100];     static int ll[100];     int n, m, i, j;     char c, c_, a, a_;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %s , ss[i]);       ll[i] = strlen(ss[i]);     }     scanf( %s n%c , cc, &c), m = strlen(cc);     c_ = toupper(c);     a = c ==  a  ?  b  :  a ;     a_ = toupper(a);     for (j = 0; j < m; j++)       for (i = 0; i < n; i++)         if (m - j >= ll[i] && compare(cc + j, ss[i], ll[i]) == 0)           memset(lucky + j, 1, ll[i]);     for (j = 0; j < m; j++)       if (lucky[j]) {         if (tolower(cc[j]) == c)           cc[j] = isupper(cc[j]) ? a_ : a;         else           cc[j] = isupper(cc[j]) ? c_ : c;       }     printf( %s n , cc);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string p[105] = {  };   int cts[105] = {0};   string pass;   int main(int argc, char const *argv[]) {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> p[i];       int xx = p[i].length();       cts[xx]++;     }     for (int i = 1; i <= 100; i++) {       cts[i] += cts[i - 1];     }     cin >> pass;     int plen = pass.length();     int mans = cts[plen - 1];     mans += 5 * (mans / k);     mans++;     cout << mans <<    ;     int maxans = cts[plen] - 1;     maxans += 5 * (maxans / k);     maxans++;     cout << maxans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI =       3.141592653589793238462643383279502884197169399375105820974944592307816406286;   double d, h, v, e;   int main() {     scanf( %lf%lf%lf%lf , &d, &h, &v, &e);     if (4 * v - d * d * PI * e <= 0)       printf( NO n );     else       printf( YES n%.12f n , (PI * h * d * d) / (4 * v - d * d * PI * e));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int sum = 0;       for (int i = 0; i < n; i++) {         int a;         cin >> a;         sum += a;       }       if (sum == m) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N_ = 100500;   int N, M;   vector<int> gph[N_], rev[N_], bth[N_];   int outdg[N_], indg[N_];   bool visited[N_];   vector<int> ord;   void dfs(int u) {     visited[u] = true;     for (int i = 0; i < gph[u].size(); i++) {       int v = gph[u][i];       if (!visited[v]) dfs(v);     }     ord.push_back(u);   }   queue<int> que;   int grp[N_], gn;   int c1[N_], c2[N_];   void dfs2(int u) {     visited[u] = true;     ++c1[gn];     grp[u] = gn;     for (int i = 0; i < bth[u].size(); i++) {       int v = bth[u][i];       if (!visited[v]) dfs2(v);     }   }   int cnt3;   void dfs3(int u) {     visited[u] = true;     ++cnt3;     for (int i = 0; i < rev[u].size(); i++) {       int v = rev[u][i];       if (!visited[v]) dfs3(v);     }   }   int main() {     scanf( %d%d , &N, &M);     for (int e = 1; e <= M; e++) {       int u, v;       scanf( %d%d , &u, &v);       gph[u].push_back(v);       rev[v].push_back(u);       bth[u].push_back(v);       bth[v].push_back(u);       ++outdg[u];       ++indg[v];     }     memset(visited, 0, sizeof visited);     for (int i = 1; i <= N; i++)       if (!visited[i]) dfs(i);     memset(visited, 0, sizeof visited);     for (int i = 1; i <= N; i++)       if (!visited[i]) {         ++gn;         dfs2(i);       }     memset(visited, 0, sizeof visited);     for (int i = ord.size(); i--;) {       int u = ord[i];       if (!visited[u]) {         cnt3 = 0;         dfs3(u);         if (cnt3 >= 2) c2[grp[u]] += 1;       }     }     int ans = 0;     for (int g = 1; g <= gn; g++) {       c2[g] += c1[g] - 1;       ans += min(c1[g], c2[g]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, t;     cin >> n >> t;     string s1, s2;     getline(cin, s1);     getline(cin, s1,  . );     getline(cin, s2);     long a = -1, count = 0;     for (int i = 0; i < s2.length(); i++)       if (s2[i] >=  5 ) {         a = i;         break;       }     if (a == -1) {       cout << s1 <<  .  << s2;       return 0;     }     if (a == 0) {       int c = s1.length() - 1;       while (s1[c] ==  9  && c >= 0) c--;       if (c == -1) {         cout <<  1 ;         for (int i = 0; i < s1.length(); i++) cout <<  0 ;         return 0;       }       s1[c]++;       for (c++; c < s1.length(); c++) s1[c] =  0 ;       cout << s1;       return 0;     }     long b = a - 1;     while (s2[b] ==  4  && b >= 0 && b >= a - t + 1) {       b--;     }     if (b == -1) {       int c = s1.length() - 1;       while (s1[c] ==  9  && c >= 0) c--;       if (c == -1) {         cout <<  1 ;         for (int i = 0; i < s1.length(); i++) cout <<  0 ;         return 0;       }       s1[c]++;       for (c++; c < s1.length(); c++) s1[c] =  0 ;       cout << s1;       return 0;     } else {       s2[b]++;       cout << s1 <<  . ;       for (int i = 0; i <= b; i++) cout << s2[i];       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 400000;   const double EPS = 1e-9;   int mods(int a, int b) { return (b + (a % b)) % b; }   int n, m, k, x, ans, p[105], s[105], strongest[105];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) {       cin >> s[i];       strongest[s[i]] = max(strongest[s[i]], p[i]);     }     for (int i = 0; i < k; i++) {       cin >> x;       if (strongest[s[x - 1]] != p[x - 1]) ans++;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const int N = 3e5 + 5;   struct node {     node* next[2] = {0};   } ns[19 * N];   int cnt = 1;   node* create() {     if (cnt < 19 * N)       return ns + cnt++;     else       return new node();   }   void insert(int x) {     node* tmp = ns;     for (int i = 19; i >= 0; i--) {       int k = x >> i & 1;       if (!tmp->next[k]) tmp->next[k] = create();       tmp = tmp->next[k];     }   }   int query(int x) {     node* tmp = ns;     int ans = 0;     for (int i = 19; i >= 0; i--) {       int k = x >> i & 1;       if (tmp->next[k]) {         tmp = tmp->next[k];       } else {         ans += (1 << i);         tmp = tmp->next[!k];       }     }     return ans;   }   void solve() {     set<int> s;     for (int i = 0; i < 1 << 19; i++) {       s.insert(i);     }     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       s.erase(x);     }     for (int x : s) {       insert(x);     }     int prev = 0;     for (int i = 0; i < m; i++) {       int q;       cin >> q;       prev ^= q;       cout << query(prev) <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using bigint = long long int;   using vi = vector<int>;   using vll = vector<long long int>;   int cnt[200001];   int main() {     int N, A;     cin >> N >> A;     for (int i = 0; i < N; i++) {       int x;       cin >> x;       cnt[x]++;     }     int ans = 0;     if (cnt[A] == 0) {       ans++;       cnt[A] = 1;     }     int left = 0, right = 0;     for (int i = 1; i < A; i++) left += cnt[i];     for (int i = A + 1; i < 100001; i++) right += cnt[i];     if (left == right) {       cout << ans <<   n ;       return 0;     }     if (left > right) {       if (right + cnt[A] - 1 >= left)         cout << ans <<   n ;       else         cout << ans + left - (right + cnt[A] - 1) <<   n ;     } else if (right > left) {       if (left + cnt[A] - 1 >= right - 1)         cout << ans <<   n ;       else         cout << ans + (right - 1) - (left + cnt[A] - 1) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int H, W, K;     cin >> H >> W >> K;     vector<string> photo(H);     for (int h = 0; h < int(H); ++h) cin >> photo[h];     vector<vector<char> > star(H, vector<char>(W, 0));     for (int r = 1; r < int(H - 1); ++r)       for (int c = 1; c < int(W - 1); ++c) {         if (photo[r][c] ==  1  && photo[r - 1][c] ==  1  &&             photo[r][c - 1] ==  1  && photo[r + 1][c] ==  1  &&             photo[r][c + 1] ==  1 ) {           star[r][c] = 1;         }       }     long long res = 0;     for (int c1 = 0; c1 < int(W); ++c1) {       vector<int> row_stars(H, 0);       for (int c2 = c1 + 3; c2 <= int(W); ++c2) {         for (int r = 0; r < int(H); ++r) row_stars[r] += star[r][c2 - 2];         int r1 = 0, stars = 0;         for (int r2 = r1 + 3; r2 <= int(H); ++r2) {           stars += row_stars[r2 - 2];           while (stars - row_stars[r1 + 1] >= K) {             stars -= row_stars[r1 + 1];             ++r1;           }           if (stars >= K) res += r1 + 1;         }       }     }     cout << res << endl;   }