malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int k;     cin >> n;     cin >> k;     int array[n];     for (int i = 0; i < n; i++) {       cin >> array[i];     }     int e;     int s;     int a = 0;     for (int i = 0; i < k; i++) {       e = 0;       s = 0;       for (int j = 0; j < n; j++) {         if (array[j] == 1 && j % k != i) {           e++;         }         if (array[j] == -1 && j % k != i) {           s++;         }       }       if (abs(e - s) > a) {         a = abs(e - s);       }     }     cout << a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200 + 5;   int a[maxn], b[maxn];   int n, m, k, x;   int getloc(int x) {     for (int i = 1; i <= k; i++) {       if (a[i] == x) return i;     }   }   void update(int x) {     int pos = 0;     for (int i = 1; i <= k; i++) {       if (a[i] == x) pos = i;     }     b[1] = a[pos];     int t = 2;     for (int i = 1; i <= k; i++) {       if (i != pos) b[t++] = a[i];     }     for (int i = 1; i <= k; i++) {       a[i] = b[i];     }   }   int main() {     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (int i = 1; i <= k; i++) scanf( %d , &a[i]);       int ans = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           scanf( %d , &x);           ans += getloc(x);           update(x);         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e6 + 3;   long long quickpow(long long a, long long x) {     long long ans = 1;     while (x) {       if (x & 1) ans = ans * a % mod;       x >>= 1;       a = a * a % mod;     }     return ans;   }   int main() {     long long n, k, x = 0, m = 0;     cin >> n >> k;     while ((1ll << x) < k) x++;     if (x > n) {       cout <<  1 1  << endl;       return 0;     }     for (long long i = 2; i < k; i <<= 1) m += (k - 1) / i;     long long p = quickpow(2, mod - 1 - m % (mod - 1));     long long ans = (quickpow(quickpow(2, n), k - 1) * p) % mod;     if (mod <= k - 1)       cout << ans <<     << ans << endl;     else {       long long ans1 = 1, ori = quickpow(2, n);       for (long long i = 1; i < k; i++) ans1 = (ans1 * (ori - i)) % mod;       ans1 = ans1 * p % mod;       cout << ((ans - ans1) % mod + mod) % mod <<     << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 * 1000 + 10;   pair<int, long double> song[maxn];   int n;   long double ans, sum;   inline bool cmp(const pair<int, long double> &a,                   const pair<int, long double> &b) {     return ((long double)1 - a.second) * b.second * b.first <            ((long double)1 - b.second) * a.second * a.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> song[i].first >> song[i].second;       song[i].second *= (long double)0.01;     }     sort(song, song + n, cmp);     for (int i = 0; i < n; i++) {       ans += song[i].first;       ans += ((long double)1 - song[i].second) * sum;       sum += song[i].second * (long double)song[i].first;     }     cout << setprecision(12) << fixed << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<long long, pair<long long, long long> > &a,                  const pair<long long, pair<long long, long long> > &b) {     return (a.second.first < b.second.first);   }   bool sortbyth(const pair<long long, pair<long long, long long> > &a,                 const pair<long long, pair<long long, long long> > &b) {     return (a.second.second < b.second.second);   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long min(long long a, long long b) { return a < b ? a : b; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long max3(long long a, long long b, long long c) {     return max(max(a, b), c);   }   long long max4(long long a, long long b, long long c, long long d) {     return max(max(a, b), max(c, d));   }   long long min3(long long a, long long b, long long c) {     return min(min(a, b), c);   }   long long min4(long long a, long long b, long long c, long long d) {     return min(min(a, b), min(c, d));   }   long long po(long long x, long long n, long long mod = 998244353) {     if (n == 0) {       return 1;     }     long long m = po(x, n / 2, mod);     m *= m;     m %= mod;     if (n % 2) {       m *= x;       m %= mod;     }     return m;   }   long long n, m, x, y;   long long col[2][1005];   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     clock_t startTime = clock();     cin >> n >> m >> x >> y;     char a[1005][1005];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (long long i = 0; i < m; i++) {       long long c = 0;       for (long long j = 0; j < n; j++) {         if (a[j][i] ==  # ) {           c++;         }       }       col[0][i] = c;       col[1][i] = n - c;     }     long long dp[2][2][1005] = {};     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < 1005; j++) {         if (j >= x || j == 0) {           dp[1][i][j] = 0;         } else {           dp[1][i][j] = INT_MAX;         }       }     }     for (long long index = m - 1; index >= 0; index--) {       for (long long last = y - 1; last >= 0; last--) {         for (long long color = 0; color < 2; color++) {           if (last == y - 1) {             dp[0][color][last] = dp[1][1 ^ color][0] + col[color][index];           } else if (last < x - 1) {             dp[0][color][last] = dp[1][color][last + 1] + col[color][index];           } else {             dp[0][color][last] =                 min(dp[1][color][last + 1], dp[1][1 ^ color][0]) +                 col[color][index];           }         }       }       for (long long last = y - 1; last >= 0; last--) {         for (long long color = 0; color < 2; color++) {           dp[1][color][last] = dp[0][color][last];         }       }     }     cout << min(dp[0][0][0], dp[0][1][0]) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int sgn(long long v) { return v > 0 ? 1 : 0; }   int main(void) {     long long p, q, r, s;     cin >> p >> q >> r >> s;     int n;     int res = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       long long temp1 = (a * p + b * q + c);       long long temp2 = a * r + b * s + c;       res = (sgn(temp1) == sgn(temp2)) ? res : res + 1;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     long long ans = 0;     long long ca = 0, cab = 0, cabc = 0, slen = 1;     for (char c : s) {       if (c ==  a )         ca = (slen + ca) % mod;       else if (c ==  b )         cab = (ca + cab) % mod;       else if (c ==  c )         cabc = (cabc + cab) % mod;       else {         cabc = (3 * cabc + cab) % mod;         cab = (ca + 3 * cab) % mod;         ca = (slen + 3 * ca) % mod;         slen = (3 * slen) % mod;       }     }     cout << cabc <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = (1 << 7);   const int mod = 1e9 + 7;   long long dp[N][M];   struct node {     int v, s[8];   } a[N];   bool cmp(node b, node d) { return b.v > d.v; }   int n, p, k;   int main() {     scanf( %d%d%d , &n, &p, &k);     int st = 1 << p;     for (int i = 1; i <= n; i++) scanf( %d , &a[i].v);     for (int i = 1; i <= n; i++)       for (int j = 0; j < p; j++) scanf( %d , &a[i].s[j]);     sort(1 + a, 1 + a + n, cmp);     for (int i = 0; i <= n; i++)       for (int j = 1; j < st; j++) dp[i][j] = -1e18;     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < st; j++) {         for (int k = 0; k < p; k++)           if (j & (1 << k))             dp[i][j] = max(dp[i - 1][j - (1 << k)] + a[i].s[k], dp[i][j]);         int p = __builtin_popcount(j);         if ((i - 1) - p >= k)           dp[i][j] = max(dp[i][j], dp[i - 1][j]);         else           dp[i][j] = max(dp[i][j], dp[i - 1][j] + a[i].v);       }     }     printf( %lld n , dp[n][st - 1]);   }
#include <bits/stdc++.h>   using namespace std;   const int logsize = 18;   int n, m, q, rt = 1, t, sc, vis[100005], dfn[100005], low[100005], sid[100005],                sz[100005], dep[100005], pr[100005][logsize], w[100005],                mod = 1e9 + 7;   stack<int> s;   vector<int> g[100005], ng[100005];   int inline read() {     int res = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       ;     for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar())       ;     return res;   }   void tarjan(int u, int p) {     dfn[u] = low[u] = ++t;     vis[u] = 1;     s.push(u);     for (int v : g[u]) {       if (v == p || vis[v] == 2) continue;       if (!vis[v]) {         tarjan(v, u);       }       low[u] = min(low[u], low[v]);     }     if (dfn[u] == low[u]) {       ++sc;       for (;;) {         int v = s.top();         s.pop();         vis[v] = 2;         sid[v] = sc;         ++sz[sc];         if (u == v) break;       }     }   }   void dfs(int u, int p) {     dep[u] = u == rt ? 0 : dep[p] + 1;     w[u] = u == rt ? sz[u] > 1 : w[p] + (sz[u] > 1);     pr[u][0] = p;     for (int v : ng[u]) {       if (v == p) continue;       dfs(v, u);     }   }   void inline init() {     dfs(rt, -1);     for (int i = 1; i <= logsize - 1; ++i) {       for (int u = 1; u <= sc; ++u) {         int p = pr[u][i - 1];         if (p == -1) {           pr[u][i] = -1;         } else {           pr[u][i] = pr[p][i - 1];         }       }     }   }   int inline lca(int u, int v) {     if (dep[u] > dep[v]) {       swap(u, v);     }     for (int i = 0; i < logsize; ++i) {       if ((dep[v] - dep[u]) >> i & 1) {         v = pr[v][i];       }     }     if (u == v) return u;     for (int i = logsize - 1; i >= 0; --i) {       if (pr[u][i] != pr[v][i]) {         u = pr[u][i];         v = pr[v][i];       }     }     return pr[u][0];   }   int qpow(long long a, int p) {     long long res = 1;     while (p) {       if (p & 1) {         res *= a;         res %= mod;       }       a *= a;       a %= mod;       p >>= 1;     }     return res % mod;   }   int main() {     ios_base::sync_with_stdio(0);     n = read();     m = read();     for (int i = 1; i <= m; ++i) {       int u = read(), v = read();       g[u].push_back(v);       g[v].push_back(u);     }     for (int u = 1; u <= n; ++u) {       if (!vis[u]) {         tarjan(u, -1);       }     }     for (int u = 1; u <= n; ++u) {       for (int v : g[u]) {         int su = sid[u], sv = sid[v];         if (su == sv) continue;         ng[su].push_back(sv);       }     }     init();     q = read();     for (int i = 1; i <= q; ++i) {       int u = read(), v = read(), su = sid[u], sv = sid[v], sp = lca(su, sv);       int d = w[su] + w[sv] - w[sp] * 2 + (sz[sp] > 1);       cout << qpow(2, d) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const long long int Mod = 998244353;   vector<int> adj[maxn];   long long int dp[maxn], pd[maxn], alone[maxn];   int n;   void dfs(int u, int p = -1) {     dp[u] = pd[u] = 0;     alone[u] = 1;     for (auto v : adj[u])       if (v ^ p) {         dfs(v, u);         dp[u] = ((dp[u] * (2 * dp[v] + alone[v]) % Mod) +                  ((alone[u] + pd[u]) * (alone[v] + pd[v]) % Mod)) %                 Mod;         pd[u] = (pd[u] * (dp[v] * 2 + alone[v]) + alone[u] * dp[v]) % Mod;         alone[u] = (alone[u] * (alone[v] + dp[v])) % Mod;       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int fi, se;       cin >> fi >> se;       fi--, se--;       adj[fi].push_back(se);       adj[se].push_back(fi);     }     dfs(0);     cout << (dp[0] + alone[0]) % Mod << endl;     return 0;   }
#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, j, temp, cnt = 0;       cin >> n;       string s;       cin >> s;       for (int i = 0; i < n; i++) {         temp = 0;         for (int j = 0; j < n - 1; j++) {           if (s[j] ==  A  && s[j + 1] ==  P ) {             s[j + 1] =  A ;             j++;             temp = 1;           }         }         if (temp == 1) {           cnt++;         } else           break;       }       cout << cnt << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<vector<int> > g(n);       vector<int> deg(n);       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         --x;         --y;         g[x].push_back(y);         g[y].push_back(x);         deg[x]++;         deg[y]++;       }       for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end());       vector<bool> used(n), vis(n);       vector<int> q(n);       int top = 0;       vector<int> vert(k);       bool f = 0;       for (int i = 0; i < n; i++) {         used[i] = vis[i] = 0;         if (deg[i] < k) {           vis[i] = 1;           q[top++] = i;         }       }       for (int i = 0; i < top; i++) {         int u = q[i];         vis[u] = 0;         used[u] = 1;         if (deg[u] < k - 1) {           for (auto j : g[u]) {             if (!used[j]) --m;             deg[j]--;             if (!vis[j] and !used[j] and deg[j] < k) {               vis[j] = 1;               q[top++] = j;             }           }           continue;         } else if (deg[u] == k - 1) {           if ((long long)k * (k - 1) <= 2 * (long long)m) {             int r = 0;             for (auto p : g[u]) {               if (!used[p]) vert[r++] = p;             }             bool ff = 1;             for (int x = 0; x < r; x++) {               if (!ff) break;               for (int y = x + 1; y < r; y++) {                 int pp =                     lower_bound(g[vert[x]].begin(), g[vert[x]].end(), vert[y]) -                     g[vert[x]].begin();                 if (pp == g[vert[x]].size() or g[vert[x]][pp] != vert[y]) {                   ff = 0;                   break;                 }               }             }             if (ff) {               f = 1;               cout <<  2 n  << u + 1 <<    ;               for (int c = 0; c < r; c++) cout << vert[c] + 1 <<    ;               cout <<   n ;               break;             }           }         }         for (auto j : g[u]) {           deg[j]--;           if (!used[j]) --m;           if (!vis[j] and !used[j] and deg[j] < k) {             vis[j] = 1;             q[top++] = j;           }         }       }       if (f) continue;       vector<int> ff;       for (int i = 0; i < n; i++)         if (!used[i]) ff.push_back(i);       if (!ff.empty()) {         cout <<  1   << ff.size() <<   n ;         for (auto c : ff) {           c++;           cout << c <<    ;         }         cout <<   n ;       } else         cout <<  -1 n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, n, *a, t, j, flag;     long m;     scanf( %d , &n);     scanf( %ld , &m);     a = (int*)calloc(n, sizeof(int));     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++)       for (j = 0; j < n - i - 1; j++)         if (a[j + 1] > a[j]) {           t = a[j + 1];           a[j + 1] = a[j];           a[j] = t;         }     flag = 1;     for (i = 0; i < n && flag; i++) {       m = m - a[i];       if (m <= 0) flag = 0;     }     printf( %d , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int i32INF = 1 << 30;   const long long i64INF = 1LL << 60;   const double mINF = 1e100;   const double EPS = 1e-9;   int nextint() {     int a;     scanf( %d , &a);     return a;   }   int n;   vector<int> v;   int difs[23][23];   bool isGood[1 << 23];   bool solveIsGood(int mask) {     int id = n;     while ((mask & (1 << (id - 1))) == 0) id--;     for (int i = 0; i < n; i++)       if (mask & (1 << i) && mask & difs[id][i]) return true;     return false;   }   int dp[1 << 23];   int main() {     n = nextint();     v.resize(n);     for (int i = 0; i < n; i++) v[i] = nextint();     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j)           for (int k = 0; k < n; k++)             if (v[i] - v[j] == v[k]) difs[i][j] |= (1 << k);     isGood[0] = 1;     for (int mask = 1; mask < (1 << (n - 1)); mask++)       isGood[mask] = solveIsGood(mask);     fill(dp, dp + (1 << n), 1024);     dp[1] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j < (1 << (i - 1)); j++) {         int jj = j | (1 << (i - 1));         if (isGood[jj]) {           int cr = dp[jj];           jj |= 1 << i;           dp[jj] = min(dp[jj], cr + 1);           for (int k = 0; k < i; k++)             if (jj & (1 << k))               dp[jj & (~(1 << k))] = min(dp[jj & (~(1 << k))], cr);         }       }     }     int res = 1024;     for (int mask = 0; mask < (1 << (n - 1)); mask++)       res = min(res, dp[mask | (1 << (n - 1))]);     if (res == 1024) res = -1;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, h, t, x, y;   vector<int> s[100100];   int a[100100], b[100100];   bool bj[100100][2];   void out(int u, int v) {     int su = s[u].size(), sv = s[v].size();     int same = 0, i = 0, j = 0;     while (i < su && j < sv) {       if (s[u][i] == s[v][j])         same++, bj[i][0] = 1, bj[j][1] = 1, i++, j++;       else if (s[u][i] > s[v][j])         j++;       else         i++;     }     printf( YES n%d %d n , u, v);     for (int i = 0; i < su; i++)       if (s[u][i] != v) {         if (!h) break;         if (!bj[i][0]) {           printf( %d  , s[u][i]);           h--;         }       }     for (int i = 0; i < su; i++)       if (s[u][i] != v) {         if (!h) break;         if (bj[i][0]) {           printf( %d  , s[u][i]);           h--;         }       }     puts(  );     for (int i = 0; i < sv; i++)       if (s[v][i] != u) {         if (!t) break;         if (!bj[i][1]) {           printf( %d  , s[v][i]);           t--;         }       }     for (int i = sv - 1; i >= 0; i--)       if (s[v][i] != u) {         if (!t) break;         if (bj[i][1]) {           printf( %d  , s[v][i]);           t--;         }       }     puts(  );   }   bool found(int u, int v) {     int su = s[u].size(), sv = s[v].size();     if (su - 1 < h || sv - 1 < t) return 0;     int same = 0, i = 0, j = 0;     while (i < su && j < sv) {       if (s[u][i] == s[v][j])         same++, i++, j++;       else if (s[u][i] > s[v][j])         j++;       else         i++;     }     if (su + sv - same - 2 >= h + t) {       out(u, v);       return 1;     }     return 0;   }   int main() {     scanf( %d%d%d%d , &n, &m, &h, &t);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       s[x].push_back(y);       s[y].push_back(x);       a[i] = x, b[i] = y;     }     for (int i = 1; i <= n; i++) sort(s[i].begin(), s[i].end());     for (int i = 1; i <= m; i++) {       if (found(a[i], b[i])) return 0;       if (found(b[i], a[i])) return 0;     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> pr;   vector<bool> used(1000001, false);   vector<int> d(1000001, 0);   void sieve() {     for (long long i = 2; i <= 1000000; i++) {       for (long long k = i * i; k <= 1000000; k += i) used[k] = true;     }     for (int i = 2; i <= 1000000; i++)       if (!used[i]) pr.push_back(i);   }   int main() {     sieve();     d[1] = 1;     for (int i = 2; i <= 1000000; i++) {       d[i] = d[i - 1];       int k = lower_bound(pr.begin(), pr.end(), i) - pr.begin();       int k1 = upper_bound(pr.begin(), pr.end(), i) - pr.begin();       if (k1 - k > 0) {         d[i]++;         continue;       }       int x = sqrt(i);       if (x * x == i) {         k = lower_bound(pr.begin(), pr.end(), x) - pr.begin();         k1 = upper_bound(pr.begin(), pr.end(), x) - pr.begin();         if (k1 - k > 0) {           d[i]--;         }       }     }     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       printf( %d n , d[n]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 4;   const int oo = 1e8 + 7;   int n, a[maxn], cc, p;   long long s[maxn];   int main() {     cin >> n;     a[1] = 1;     a[2] = 2 * n;     a[n + 1] = 2;     a[n + 2] = 2 * n - 1;     int cc = 3;     for (int i = 3; i <= (n); ++i) {       if (i % 2) {         a[i] = cc;         a[i + n] = cc + 1;         cc += 2;       } else {         a[i + n] = cc;         a[i] = cc + 1;         cc += 2;       }     }     long long k = 0;     for (int i = 1; i <= (2 * n); ++i) k += i;     for (int i = 2 * n + 1; i <= (4 * n); ++i) a[i] = a[i - 2 * n];     for (int i = 1; i <= (4 * n); ++i) s[i] = s[i - 1] + a[i];     k = k / 2;     k++;     for (int i = 1; i <= (3 * n); ++i) {       long long x = s[i + n - 1] - s[i - 1];       if (abs(x - k) > 1) {         cout <<  NO ;         return 0;       }     }     cout <<  YES n ;     for (int i = 1; i <= (2 * n); ++i) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n, c[N], k = 1e5;   char a[N], b[N];   void solve(int p, int coef) {     if (a[p - 1] + coef <  0  || a[p - 1] + coef >  9 ) {       solve(p - 1, -coef);     }     a[p - 1] += coef;     a[p] += coef;     printf( %d %d n , p - 1, coef);     if (!--k) {       exit(0);     }   }   int main() {     scanf( %d%s%s , &n, a + 1, b + 1);     copy(a + 1, a + 1 + n, c + 1);     long long answer = 0;     for (int i = 1; i < n; ++i) {       if (c[i] != b[i]) {         answer += abs(c[i] - (int)b[i]);         c[i + 1] += (int)b[i] - c[i];       }     }     if (c[n] != b[n]) {       return puts( -1 );     } else {       printf( %lld n , answer);       if (answer < k) {         k = answer;       }       for (int i = n; i; --i) {         for (; a[i] != b[i]; solve(i, a[i] < b[i] ? 1 : -1))           ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void print_ans(int x1, int y1, int x2, int y2) {     long long int ans;     ans = (x1 - x2) * (y1 - y2);     if (ans < 0) ans = -ans;     cout << ans;     return;   }   int main() {     int n, x[4], y[4], i;     cin >> n;     if (n < 2)       cout <<  -1 ;     else {       for (i = 0; i < n; i++) cin >> x[i] >> y[i];       if (n == 2) {         if (x[0] == x[1] || y[0] == y[1])           cout <<  -1 ;         else           print_ans(x[0], y[0], x[1], y[1]);       } else {         if (x[0] != x[1] && y[0] != y[1])           print_ans(x[0], y[0], x[1], y[1]);         else if (x[1] != x[2] && y[1] != y[2])           print_ans(x[1], y[1], x[2], y[2]);         else           print_ans(x[0], y[0], x[2], y[2]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vv[2000][2000];   int main() {     int n;     string s;     cin >> s;     long long left[2000], right[2000];     for (int i = 0; i < s.length(); i++) {       vv[i][i] = true;     }     int sm = 1, cp = s.length() - 1;     for (; sm < s.length(); sm++) {       for (int i = sm, j = 0; i < s.length(); i++, j++) {         if (s[j] == s[j + sm] && (sm == 1 || vv[j + 1][j + sm - 1])) {           vv[j][j + sm] = true;         } else {           vv[j][j + sm] = false;         }       }     }     for (int i = 0; i < s.length(); i++) {       left[i] = 1;       right[i] = 1;       for (int j = 0; j < i; j++) {         if (vv[j][i]) left[i]++;         if (vv[s.length() - (i + 1)][s.length() - (j + 1)]) right[i]++;       }     }     long long res = 0, right_sum = 0;     for (int i = 0; i < s.length() - 1; i++) right_sum += right[i];     for (int i = 0; i < s.length() - 1; i++) {       res += left[i] * right_sum;       right_sum -= right[s.length() - (i + 2)];     }     cout << res << endl;     return 0;   }