malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 4005;   int tk[N][2];   int n, m;   bool r[N][N];   int deg[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     int a, b;     for (int i = 1; i <= n; ++i) {       deg[i] = -2;       ;       for (int j = 1; j <= n; ++j) r[i][j] = false;     }     for (int i = 1; i <= m; ++i) {       cin >> a >> b;       tk[i][0] = a;       tk[i][1] = b;       r[a][b] = true;       r[b][a] = true;       ++deg[a];       ++deg[b];     }     int res = 1000000000;     int c, d;     for (int i = 1; i < m; ++i) {       for (int j = i + 1; j <= m; ++j) {         a = tk[i][0];         b = tk[i][1];         c = tk[j][0];         d = tk[j][1];         if (a == c) {           if (r[b][d]) {             res = min(res, deg[a] + deg[b] + deg[d]);           }         }         if (b == c) {           if (r[a][d]) {             res = min(res, deg[a] + deg[b] + deg[d]);           }         }         if (a == d) {           if (r[b][c]) {             res = min(res, deg[a] + deg[b] + deg[c]);           }         }         if (b == d) {           if (r[a][c]) {             res = min(res, deg[a] + deg[b] + deg[c]);           }         }       }     }     if (res == 1000000000)       cout <<  -1 n ;     else       cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;   const ll inf = 1LL << 60;   vector<ll> dv;   void divisor(ll n) {     for (ll i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (i == n / i) {           dv.push_back(i);         } else {           dv.push_back(i);           dv.push_back(n / i);         }       }     }   }   ll gcd(ll a, ll b) {     if (a == 0 || b == 0) return 0;     if (a % b == 0) return b;     return gcd(b, a % b);   }   int main() {     ll l, r, x, y;     cin >> l >> r >> x >> y;     if (y % x != 0)       cout << 0 << endl;     else {       ll tmp = y / x;       divisor(tmp);       ll ans = 0;       for (auto &z : dv) {         ll a = z;         ll b = tmp / z;         if (gcd(a, b) == 1) {           if (l <= x * a && x * a <= r && l <= x * b && x * b <= r) ans++;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   struct SegmentTree {     vector<multimap<int, int>> T;     SegmentTree(int n) : T(n + 1) {}     set<int> available;     void Insert(int l, int r, int idx) {       for (++l; l > 0; l -= (l & (-l))) T[l].emplace(r, idx);       available.insert(idx);     }     int Query(int l, int r) {       for (++l; l < (int)T.size(); l += (l & (-l))) {         while (true) {           if (T[l].empty() or T[l].begin()->first > r) break;           auto now = (*T[l].begin());           T[l].erase(T[l].begin());           if (available.count(now.second)) {             available.erase(now.second);             return now.second;           }         }       }       return -1;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<tuple<int, int, int, int, int>> events;     vector<int> all;     for (int i = 0; i < n; ++i) {       int s, f, t;       cin >> s >> f >> t;       events.emplace_back(t, 1, s, f, i);       all.push_back(s);     }     for (int i = 0; i < m; ++i) {       int l, r, b;       cin >> l >> r >> b;       events.emplace_back(b, 0, l, r, i);       all.push_back(l);     }     sort(events.begin(), events.end());     sort(all.begin(), all.end());     all.erase(unique(all.begin(), all.end()), all.end());     SegmentTree st(all.size());     vector<int> ans(m, -2);     for (auto itr : events) {       int tp, l, r, idx;       tie(ignore, tp, l, r, idx) = itr;       l = distance(all.begin(), lower_bound(all.begin(), all.end(), l));       if (tp == 0) {         st.Insert(l, r, idx);       } else {         while (true) {           int now = st.Query(l, r);           if (now == -1) break;           ans[now] = idx;         }       }     }     for (auto x : ans) cout << x + 1 <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     vector<int> a(n), b(n);     for (int i = (0); i < (m); i++) {       int x, y;       cin >> x >> y;       --x;       --y;       y = (y - x + n) % n;       b[x] = a[x]++ ? min(b[x], y) : y;     }     for (int i = (0); i < (n); i++)       if (a[i]) {         a[i] = a[i] * n + b[i] + i;         b[i] = a[i] - n;       }     for (int i = (0); i < (n); i++)       if (i) a[i] = max(a[i], a[i - 1]);     for (int i = (n); i-- > (0);)       if (i < n - 1) b[i] = max(b[i], b[i + 1]);     for (int i = (0); i < (n); i++)       cout << max(i ? a[i - 1] : 0, b[i]) - i <<    ;   }
#include <iostream>   #include <vector>   #include <string>   #include <queue>   #include <algorithm>   #include <cmath>   #include <map>   #include <set>   #include <unistd.h>   #define rep(i,a,n) for(int i = a;i < n;i++)   #define fi first   #define se second   typedef long long ll;   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 1e4 + 3;   const int mod = 1e9 + 7;    ll quick_pow(ll a, ll b){ll ans = 1;while(b){if(b & 1){ans = (ans * a) % mod;}a = (a * a) % mod;b >>= 1;}return ans;}      ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a % b));}      struct cmp   {    bool operator() (pair<int,pair<int,int>> a1,pair<int,pair<int,int>> a2){     return a1.first > a2.first;    }   };            int main(){       ios::sync_with_stdio(false);       //freopen( in.txt , r , stdin);    int t;    cin  >> t;    while(t--){     ll n;     cin >> n;     if(n / 2050 * 2050 == n){      ll x = n / 2050;      int cnt = 0;      while(x){       cnt += x % 10;       x /= 10;      }      cout << cnt << endl;     }else{      cout << -1 << endl;     }    }          }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 1e5 + 10, mod = 1e9 + 7;   long long a[maxn], d[maxn];   bool mark[maxn];   long long dfs(int v, int p) {     mark[v] = 1;     if (v == p) return 0;     if (mark[a[v]]) return -1;     int k = dfs(a[v], p);     return (k == -1 ? -1 : k + 1);   }   int main() {     ios::sync_with_stdio(0);     long long n, s, t;     cin >> n >> s >> t;     for (int i = 1; i <= n; i++) cin >> a[i];     cout << dfs(s, t) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     string s, t, p =   ;     cin >> s >> t;     int n = s.size();     int c = 0;     for (int i = 0; i < n; i++)       if (s[i] != t[i]) c++;     if (c % 2) {       cout <<  impossible ;       return 0;     }     for (int i = 0; i < n; i++) {       if (s[i] == t[i]) {         p += s[i];         continue;       }       if (c)         p += s[i], c -= 2;       else         p += t[i];     }     cout << p << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> A, B;     for (int i = 1; i <= n; i++) A.push_back(i);     long long sum = 0;     for (int i = 2; i < n; i++) sum += i * (i + 1);     cout << sum <<   n ;   }
#include <iostream>   #include <vector>      #define int long long      const int DEN = 100000;   const int INF = 100000000000000000;      int ceild(int x) {     if(x%DEN != 0) {       x += DEN-x%DEN;     }     return x/DEN;   }      signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);        int n, m;     std::cin >> n >> m;        std::vector<int> poss[n+1];     for(int i = 0; i <= m; i++)       poss[0].push_back(i==0);        for(int i = 1; i <= n; i++) {       poss[i] = poss[i-1];       int t, x, y;       std::cin >> t >> x >> y;          if(t == 2) {         for(int j = 0; j <= m; j++) {           if(!poss[i-1][j])             continue;           int next = j;           int count = 0;           while(next <= m && count <= y) {             poss[i][next] = 1;             next *= x;             next = ceild(next);             if(next <= m && poss[i-1][next])               break;             count++;           }         }       }       else {         x = ceild(x);         std::vector<int> next(m+1, -INF);         for(int j = 0; j <= m; j++) {           if(j-x >= 0)             next[j] = next[j-x];           if(poss[i-1][j])             next[j] = j;           if(j-next[j] <= y*x)             poss[i][j] = 1;         }       }        }        std::vector<int> answer(m+1, -1);     for(int i = n; i > 0; i--) {       for(int j = 1; j <= m; j++)         if(poss[i][j])           answer[j] = i;     }        for(int j = 1; j <= m; j++)       std::cout << answer[j] <<    ;     std::cout << std::endl;        return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, r;     int y1, y2, yw, x, y;     scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &r);     y2 = b;     if (b - a < r) {       printf( -1 n );       return 0;     }     y1 = a + r;     yw = c - r;     y = 2 * yw - y;     double k = (1.0) * (y - y1) / x;     double ans = (yw - y1) / k;     double dis = (y2 - y1) / sqrt(k * k + 1);     if (dis < r)       printf( -1 n );     else       printf( %.10f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int cont = 0;     for (int i = 0; i < n && s[i] ==  < ; i++, cont++)       ;     for (int i = n - 1; i >= 0 && s[i] ==  > ; i--, cont++)       ;     cout << cont << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, m;   int a[MAXN];   int w[MAXN], h[MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &w[i], &h[i]);     }     long long lasth = 0;     for (int i = 1; i <= m; i++) {       long long int x = lasth + 1;       if (a[w[i]] > x) x = a[w[i]];       printf( %I64d n , x);       lasth = x + h[i] - 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, k, m, d;   int main() {     std::ios::sync_with_stdio(false);     long long int best = -1;     cin >> n >> k >> m >> d;     int x;     long long int pre = m;     long long int ans = 0;     for (int cycles = 1; cycles <= d; cycles++) {       long long int peeps = (cycles - 1) * k + 1;       long long int eachCandy = min(m, n / peeps);       if (eachCandy == 0) break;       ans = max(ans, eachCandy * cycles);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   const int N = 2e5 + 10;   const ll inf = 1e15 + 42;   vector<vector<int> > g(100007);   int flg, root, cnt;   vector<int> ans;   void dfs(int u, int par) {     if (flg) return;     int val = 0;     for (int v : g[u]) {       if (v != par) {         val++;         dfs(v, u);       }     }     if (val == 2 && u == 1) {       return;     }     if (val > 1 && cnt == 0) {       cnt++;       root = u;     } else if (val > 1) {       flg = 1;     }   }   void dfs1(int u, int par) {     int ok = 1;     for (int v : g[u]) {       if (v != par) {         ok = 0;         dfs1(v, u);       }     }     if (ok) ans.push_back(u);   }   void testCase() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, -1);     if (flg == 1) {       cout <<  No             <<   n ;       return;     }     if (root == 0) root = 1;     dfs1(root, -1);     cout <<  Yes           <<   n ;     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << root <<     << ans[i] <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     testCase();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int nofQs;     cin >> nofQs;     int minSec = INT_MAX;     vector<int> custs(nofQs);     for (int i = 0; i < nofQs; i++) {       cin >> custs[i];     }     for (int i = 0; i < nofQs; i++) {       int tAmt = 0;       for (int j = 0; j < custs[i]; j++) {         int nofItems;         cin >> nofItems;         tAmt += (nofItems * 5);         tAmt += 15;       }       minSec = min(tAmt, minSec);     }     cout << minSec;   }
#include <bits/stdc++.h>   using namespace std;   int f[(1 << 20)], cnt[(1 << 20)], n, m;   string s;   int main() {     cin >> n >> m >> s;     fill(f + 1, f + (1 << m), INT_MAX);     for (int i = 1; i < n; i++) {       int a = s[i - 1] -  a , b = s[i] -  a ;       if (a != b) cnt[(1 << a) | (1 << b)]++;     }     for (int i = 0; i < (1 << m); i++) {       int c = m - __builtin_popcount(i);       for (int j = 0; j < m; j++) {         if ((i & (1 << j)) == 0) {           int num = f[i];           for (int k = 0; k < m; k++) {             int flag = 1;             if (i & (1 << k)) flag = -1;             num += flag * cnt[(1 << k) | (1 << j)] * c;           }           f[i | (1 << j)] = min(f[i | (1 << j)], num);         }       }     }     cout << f[(1 << m) - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;      #define     F       first   #define     S       second   typedef pair<int, int>  pi;   typedef long long       ll;   const ll big = 1e6 + 9;   ll GCD(ll a,ll b)   {       if(!b)           return a;       return GCD(b, a % b);   }   ll LCM(ll a,ll b)   {       return a*b/GCD(a,b);   }      int main()   {ios_base::sync_with_stdio(0);       cin.tie(0);cout.tie(0);          ll t;       cin >> t;       while(t--)       {           string s, t;           cin >> s >> t;           ll n1 = s.size(), n2 = t.size();           ll lcm = LCM(n1,n2);           ll k1 = lcm/n1, k2 = lcm/n2;           k1--,k2--;              string s1 = s, t1 = t;           while(k1--)               s += s1;           while(k2--)               t += t1;           if(s == t)               cout << s <<   n ;           else               cout <<  -1 n ;       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {     return (a.second < b.second);   }   long long int modpower(long long int a, long long int b, long long int c) {     long long int res = 1;     while (b) {       if (b & 1LL) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   using namespace std;   const int INF = 987654321;   const int MOD = 1000000007;   const int N = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[N], b[N];       for (int i = 1; i <= 1000; i++) {         a[i] = 0;       }       for (int i = 0; i < n; i++) {         int x;         cin >> x;         a[x]++;       }       int j = -1;       for (int i = 0; i < m; i++) {         cin >> b[i];         if (a[b[i]]) {           j = b[i];         }       }       if (j > 0)         cout <<  YES  <<   n  <<  1   << j <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     if (y == 0)       return 1;     else {       long long result = power(x, y / 2) % 1000000007;       if (y % 2 == 0)         return (result % 1000000007 * result % 1000000007) % 1000000007;       else         return (result % 1000000007 * result % 1000000007 * x % 1000000007) %                1000000007;     }   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     long long start = -1;     long long sum = 0;     long long div = n / k;     long long minsum = INT_MAX;     for (long long i = 0; i < k; i++) {       sum = 0;       for (long long j = i; j < n; j = j + k) {         sum = sum + v[j];       }       if (sum < minsum) {         minsum = sum;         start = i + 1;       }     }     cout << start;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, i, count = 0;     cin >> n;     double a[n], j, ans = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = n - 1; i >= 0; i--) {       if (count % 2 == 0) {         ans += 3.1415926536 * a[i] * a[i];         count++;       } else {         ans -= 3.1415926536 * a[i] * a[i];         count++;       }     }     cout << fixed << setprecision(9) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   template <typename T>   void read(T& x) {     x = 0;     int flag = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) flag = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= flag;   }   using namespace std;   const int maxn = 200010;   int n, q, f[maxn], sz[maxn], tp;   pair<int, int> sta[maxn], a[maxn];   bool ok[maxn];   struct info {     int l, r, u, v;     info() {}     info(int a, int b, int c, int d) { l = a, r = b, u = c, v = d; }   };   vector<info> seg;   int find(int x) { return f[x] == x ? f[x] : find(f[x]); }   bool check(int x) { return find(x) == find(x + n); }   void link(int u, int v) {     int r1 = find(u), r2 = find(v);     if (r1 == r2) return;     if (sz[r1] > sz[r2]) swap(r1, r2);     f[r1] = r2, sz[r2] += sz[r1], sta[++tp] = make_pair(r1, r2);   }   void cut(pair<int, int> t) {     int u = t.first, v = t.second;     if (f[v] == u) swap(u, v);     f[u] = u;     while (f[v] != v) sz[v] -= sz[u], v = f[v];     sz[v] -= sz[u];   }   map<pair<int, int>, int> mp;   vector<pair<int, int> > edge[maxn << 2];   void modify(int p, int l, int r, int ql, int qr, int u, int v) {     if (ql <= l && r <= qr) {       edge[p].push_back(make_pair(u, v));       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify(p << 1, l, mid, ql, qr, u, v);     if (qr > mid) modify(p << 1 | 1, mid + 1, r, ql, qr, u, v);   }   void dfs(int p, int l, int r, bool flag) {     int mid = (l + r) >> 1, cur = tp;     for (int i = 0; i <= (int)edge[p].size() - 1; i++) {       if (!flag) continue;       int u = edge[p][i].first, v = edge[p][i].second;       link(u, v + n), link(v, u + n);       if (check(u) || check(v)) flag = 0;     }     if (l == r) {       puts(flag ?  YES  :  NO );       while (tp > cur) cut(sta[tp--]);       return;     }     dfs(p << 1, l, mid, flag), dfs(p << 1 | 1, mid + 1, r, flag);     while (tp > cur) cut(sta[tp--]);   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= (int)2 * n; i++) f[i] = i, sz[i] = 1;     for (int i = 1; i <= (int)q; i++) {       scanf( %d %d , &a[i].first, &a[i].second);       int tmp = mp[a[i]];       if (!tmp)         mp[a[i]] = i;       else {         ok[tmp] = ok[i] = 1, mp[a[i]] = 0;         seg.push_back(info(tmp, i - 1, a[i].first, a[i].second));       }     }     for (int i = 1; i <= (int)q; i++)       if (!ok[i]) seg.push_back(info(mp[a[i]], q, a[i].first, a[i].second));     for (int i = 0; i <= (int)seg.size() - 1; i++)       modify(1, 1, q, seg[i].l, seg[i].r, seg[i].u, seg[i].v);     dfs(1, 1, q, 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int IINF = INT_MAX;   const long long LLINF = LLONG_MAX;   inline bool LT(double a, double b) {     return !(fabs((a) - (b)) < (1e-8)) && a < b;   }   inline bool LTE(double a, double b) {     return (fabs((a) - (b)) < (1e-8)) || a < b;   }   void compute() {}   int main() {     string s;     cin >> s;     deque<char> deq;     int cnt = 0;     int n = s.size();     for (int i = 0; i < n; ++i) {       if (deq.empty()) {         deq.push_back(s[i]);       } else {         if (deq.back() == s[i]) {           deq.pop_back();           ++cnt;         } else {           deq.push_back(s[i]);         }       }     }     if (cnt % 2 == 0)       puts( No );     else       puts( Yes );     compute();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     scanf( %d , &n);     printf( %d  , n);     int idx = 0;     for (int i = 2; i <= n; i++) {       while (n % i == 0) {         n = n / i;         printf( %d  , n);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 500 + 5;   int board[M][M], dp[M][M];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) {         board[i + 1][j + 1] = s[j] -  0  + 0;       }     }     for (int row = 1; row <= n; row++) {       for (int col = 1; col <= m; col++) {         int num = 0;         num = num + (board[row][col] == 1);         num = num + (col - 1 >= 1 && col - 1 <= m && board[row][col - 1] == 1);         num = num + (col + 1 >= 1 && col + 1 <= m && board[row][col + 1] == 1);         num = num + (row + 1 >= 1 && row + 1 <= n && board[row + 1][col] == 1);         num = num + (row - 1 >= 1 && row - 1 <= n && board[row - 1][col] == 1);         dp[row][col] = dp[row][col - 1] + (num == 5);       }     }     long long int ans = 0;     for (int col1 = 1; col1 <= m; col1++) {       for (int col2 = col1 + 2; col2 <= m; col2++) {         int p1 = 1;         int p2 = 3;         int numstar = dp[p2 - 1][col2 - 1] - dp[p2 - 1][col1];         while (p2 <= n) {           while (p2 <= n && numstar < k) {             p2++;             numstar = numstar + dp[p2 - 1][col2 - 1] - dp[p2 - 1][col1];           }           if (p2 <= n && numstar >= k) {             ans = ans + n - p2 + 1;             numstar = numstar - (dp[p1 + 1][col2 - 1] - dp[p1 + 1][col1]);             p1++;             while (p1 + 2 <= p2 && numstar >= k) {               numstar = numstar - (dp[p1 + 1][col2 - 1] - dp[p1 + 1][col1]);               p1++;               ans = ans + n - p2 + 1;               if (p1 + 2 > p2) {                 break;               }             }           }         }       }     }     cout << ans << endl;     return 0;   }