malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   long long k, x;   long long a[200010];   int main() {     int n;     while (cin >> n >> k >> x) {       int negative = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] < 0) ++negative;       }       if (negative % 2 == 0) {         int minId = 0;         for (int i = 1; i < n; i++) {           if (abs(a[i]) < abs(a[minId])) minId = i;         }         long long num = abs(a[minId]) / x + 1;         if (a[minId] >= 0)           a[minId] -= min(num, k) * x;         else           a[minId] += min(num, k) * x;         k = max(k - num, 0LL);       }       priority_queue<pair<long long, int>, vector<pair<long long, int> >,                      greater<pair<long long, int> > >           que;       for (int i = 0; i < n; i++) {         que.push(make_pair(abs(a[i]), i));       }       while (k--) {         pair<int, int> cur = que.top();         que.pop();         int id = cur.second;         if (a[id] >= 0)           a[id] += x;         else           a[id] -= x;         que.push(make_pair(abs(a[id]), id));       }       for (int i = 0; i < n; i++) {         if (i != n - 1)           cout << a[i] <<    ;         else           cout << a[i] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double PI = acos(-1.0);   using namespace std;   double dp[1005][1005];   int main(void) {     int n, m;     scanf( %d %d , &n, &m);     if (n == 1) {       puts( 1.0000000 );       return 0;     }     dp[0][0] = 1;     for (int i = 1; i <= n - 1; i++) {       dp[i][0] = dp[i - 1][0] * (1 - (m - 1.0) / (n * m - i));       for (int j = 1; j <= i && j <= m; j++) {         dp[i][j] = dp[i - 1][j - 1] * (m - j + 0.0) / (n * m - i) +                    dp[i - 1][j] * (1 - (m - j - 1.0) / (n * m - i));       }     }     double ans = 0;     for (int i = 0; i <= n - 1; i++) {       ans += dp[n - 1][i] * (i + 1.0) / n;     }     printf( %.10lf n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     std::vector<std::pair<int, int> > a(n + 1);     for (int p = 0; p < n; p++) {       int x;       scanf( %d , &x);       a[p] = std::make_pair(x, p + 1);     }     sort(++a.begin(), a.end(), std::greater<std::pair<int, int> >());     int ind(0);     std::vector<std::pair<int, int> > comm;     for (int p = 0; p < n; p++) {       for (int q = ind + 1; q <= ind + a[p].first; q++) {         if (q >= n) {           break;         }         comm.push_back(std::make_pair(a[p].second, a[q].second));       }       ind += a[p].first;       if (ind <= p) {         break;       }     }     if (comm.size() < n - 1) {       puts( -1 );     } else {       printf( %d n , n - 1);       for (int p = 0; p < comm.size(); p++) {         printf( %d %d n , comm[p].first, comm[p].second);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200005;   int main() {     long long n, z, x, y;     cin >> n;     z = (n * (n - 1) * (n - 2) * (n - 3) * (n - 4)) / 120;     x = (z * (n - 5)) / 6;     y = (x * (n - 6)) / 7;     cout << z + x + y <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   int main(int argc, char* argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     int n;     cin >> n;     auto g = vector<vector<ll>>(n, vector<ll>(n, 2000000000));     for (int i = 0; i < (n - 1); ++i)       for (int j = 0; j < (n - i - 1); ++j) {         int d;         cin >> d;         g[i][i + j + 1] = g[i + j + 1][i] = d;       }     auto min_adj = vector<ll>(n);     for (int i = 0; i < (n); ++i)       min_adj[i] = *min_element((g[i]).begin(), (g[i]).end());     auto smallest = *min_element((min_adj).begin(), (min_adj).end());     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (n); ++j) g[i][j] -= smallest;     auto dist = move(min_adj);     for (int i = 0; i < (n); ++i) dist[i] = 2 * (dist[i] - smallest);     auto done = vector<char>(n, false);     for (int _ = 0; _ < (n); ++_) {       int v = -1;       for (int i = 0; i < (n); ++i)         if (!done[i] && (v == -1 || dist[i] < dist[v])) v = i;       done[v] = true;       for (int i = 0; i < (n); ++i) dist[i] = min(dist[i], dist[v] + g[i][v]);     }     for (int i = 0; i < (n); ++i) cout << dist[i] + (n - 1) * smallest <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 99;   int n, m, pre[maxn], nxt[maxn], vst[maxn], flag[maxn];   vector<int> G[maxn];   void del(int i) {     nxt[pre[i]] = nxt[i];     if (~nxt[i]) pre[nxt[i]] = pre[i];   }   void bfs(int id) {     queue<int> que;     que.push(id);     while (!que.empty()) {       int now = que.front();       que.pop();       for (int x : G[now])         if (!vst[x]) flag[x] = 1;       for (int i = nxt[0]; ~i; i = nxt[i]) {         if (flag[i])           flag[i] = 0;         else           vst[i] = 1, que.push(i), del(i);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     nxt[0] = 1;     nxt[n] = -1;     for (int i = 1; i < n; i++) pre[i + 1] = i, nxt[i] = i + 1;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (vst[i]) continue;       ans++;       bfs(i);     }     cout << ans - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t[200001];   int main() {     memset(t, 0x3f, sizeof(t));     int n, k;     string str;     cin >> n >> k >> str;     for (int x = 0; x < n; x++)       if (str[x] == str[(x + 1) % n] || str[x] == str[(x - 1 + n) % n]) t[x] = 0;     for (int x = 0; x < 2 * n; x++)       t[x % n] = min(t[x % n], t[(x - 1 + n) % n] + 1);     for (int x = 2 * n - 1; x >= 0; x--)       t[x % n] = min(t[x % n], t[(x + 1) % n] + 1);     for (int x = 0; x < n; x++)       if (min(t[x], k) % 2) str[x] = 153 - str[x];     cout << str << endl;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1000000];   int main() {     int n;     while (scanf( %d , &n) != -1) {       if (n == 1) {         printf( 1 n );         continue;       }       if ((n & 1) && (n - 1) % 4) {         printf( -1 n );         continue;       }       if (!(n & 1) && n % 4) {         printf( -1 n );         continue;       }       for (int i = 1; i + i <= n; i += 2)         arr[i] = i + 1, arr[i + 1] = n - i + 1, arr[n - i + 1] = n - i,         arr[n - i] = i;       if (n % 2) arr[n / 2 + 1] = n / 2 + 1;       for (int i = 1; i <= n; ++i) printf(i > 1 ?   %d  :  %d , arr[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int INF = 1e9;   const long long mod = 1e9 + 7;   bool dp[105][55][2][2][205];   string s;   int n, sz, realans;   int offset(int x) { return x + 100; }   bool f(int idx, int sisa, bool flip, bool arah, int ans) {     if (idx == sz + 1) {       if (sisa == 0) {         realans = max(realans, abs(ans));       }       return 1;     }     bool &res = dp[idx][sisa][flip][arah][offset(ans)];     if (res == 1) return res;     char now = s[idx - 1];     if (flip) {       if (now ==  F )         now =  T ;       else         now =  F ;     }     if (now ==  F ) {       res = f(idx + 1, sisa, 0, arah, ans + (arah ? 1 : -1));       if (sisa) res = f(idx, sisa - 1, !flip, arah, ans);     } else if (now ==  T ) {       res = f(idx + 1, sisa, 0, !arah, ans);       if (sisa) res = f(idx, sisa - 1, !flip, arah, ans);     }     return res = 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     cin >> n;     sz = s.size();     f(1, n, 0, 1, 0);     cout << realans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[500005], tot, s[500005], c[500005], tmp[1500005], num;   priority_queue<int> q;   bool cmp(int x, int y) { return x > y; }   int main() {     long long ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i];     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) {       if (i == 1 || a[i] != a[i - 1])         s[++tot] = a[i], c[tot]++;       else         c[tot]++;     }     int sum = 0;     for (int i = 1; i <= tot; i++) {       int pt = min((int)(sum - (int)2 * q.size()), c[i]);       int rst = min(c[i] - pt, sum - pt);       num = 0;       for (int j = 1; j <= pt; j++) tmp[++num] = s[i];       for (int j = 1; j <= rst; j += 2) {         int k = -q.top();         q.pop();         if (k < s[i]) {           tmp[++num] = s[i];           if (j < rst) tmp[++num] = s[i];         } else {           tmp[++num] = k;           if (j < rst) tmp[++num] = 2 * s[i] - k;         }       }       for (int j = 1; j <= num; j++)         if (tmp[j] >= 0) q.push(-tmp[j]);       sum += c[i];     }     while (!q.empty()) ans += q.top(), q.pop();     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int ar[2111111], br[2111111], cr[2111111], dr[2111111];   int main() {     cin.sync_with_stdio(false);     int n, i, j, x, y, pos, m;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> ar[i];       if (ar[i] == 0) pos = i;     }     for (i = n + 1; i < n + n; i++) ar[i] = ar[i - n];     for (j = 1, i = pos + 1; i <= pos + n - 1; i++, j++) cr[j] = ar[i];     m = j - 1;     for (i = m + 1; i <= m + m; i++) cr[i] = cr[i - m];     for (i = 1; i <= n; i++) {       cin >> br[i];       if (br[i] == 0) pos = i;     }     for (i = n + 1; i < n + n; i++) br[i] = br[i - n];     for (j = 1, i = pos + 1; i <= pos + n - 1; i++, j++) dr[j] = br[i];     for (i = 1; i <= m + m; i++)       if (cr[i] == dr[1]) {         pos = i;         break;       }     bool cond = true;     for (j = 1, i = pos; i <= pos + m - 1 && cond; i++, j++)       if (cr[i] != dr[j]) cond = false;     if (cond)       puts( YES );     else       puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;   template <class T1, class T2>   inline void gadd(T1 &a, T2 b) {     a = (a + b) % Z;   }   int casenum, casei;   int D, n, m;   int lft[N], rgt[N], bot[N], top[N];   struct A {     int l, r, t, b;   } a[N];   int main() {     while (~scanf( %d%d%d , &D, &n, &m)) {       memset(lft, 0, sizeof(lft));       memset(rgt, 0, sizeof(rgt));       memset(top, 0, sizeof(top));       memset(bot, 0, sizeof(bot));       int x1, y1, x2, y2;       for (int i = 1; i <= D; ++i) {         scanf( %d%d%d%d , &x1, &y1, &x2, &y2);         if (x1 > x2) swap(x1, x2);         if (y1 > y2) swap(y1, y2);         a[i] = {x1, x2, y2, y1};         ++lft[x1];         ++rgt[x2];         ++bot[y1];         ++top[y2];       }       for (int i = 1; i <= n + 1; ++i) {         lft[i] += lft[i - 1];       }       for (int i = 1; i <= m + 1; ++i) {         bot[i] += bot[i - 1];       }       for (int i = n; i >= 0; --i) {         rgt[i] += rgt[i + 1];       }       for (int i = m; i >= 0; --i) {         top[i] += top[i + 1];       }       int L, R, T, B;       scanf( %d%d%d%d , &L, &R, &T, &B);       int ans = -1;       for (int i = 1; i <= D; ++i) {         int lr = (a[i].r > a[i].l);         int tb = (a[i].t > a[i].b);         if (lft[a[i].r - 1] - lr == L && rgt[a[i].l + 1] - lr == R &&             top[a[i].b + 1] - tb == B && bot[a[i].t - 1] - tb == T) {           ans = i;           break;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   int n, m, c[256];   int main() {     int a, j;     scanf( %d%d , &n, &m);     memset(c, -1, sizeof(c));     for (int i = 0; i < n; ++i) {       scanf( %d , &a);       if (~c[a])         printf( %d  , c[a]);       else {         j = a;         while (j && !~c[j - 1] && j > a - m + 1) --j;         if (j && ~c[j - 1] && a - c[j - 1] < m)           c[j] = c[j - 1];         else           c[j] = j;         for (int k = j + 1; k <= a; ++k) c[k] = c[j];         printf( %d  , c[j]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   long long a[200000 + 5];   int main() {     long long i, j, k, l;     long long n, m;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     a[n] = 2000000009;     long long maxn = 0;     k = 0;     for (i = 1; i <= n; i++) {       if (a[i] > a[i - 1] * 2) {         maxn = max(maxn, i - k);         k = i;       }     }     cout << maxn << endl;   }
#include <bits/stdc++.h>   const double pi = 3.141592653589793238462643383279;   using namespace std;   long long GCD(long long a, long long b) {     if (b == 0) return a;     return GCD(b, a % b);   }   int arr[1000010];   int rev[1000010];   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cout << fixed << setprecision(10);     int n;     cin >> n;     string s;     cin >> s;     if (s[0] ==  )  && s[s.size() - 1] ==  ( ) {       cout << 0 << endl;       return 0;     } else if (s[0] ==  ) ) {       arr[0]++;       arr[1] += arr[0];       bool f = true;       for (int i = 1; i < s.size(); i++) {         if (s[i] ==  ( )           arr[i]++;         else           arr[i]--;         arr[i + 1] += arr[i];         if (arr[i] < 0) f = false;       }       if (f && arr[s.size() - 1] == 0)         cout << 1 << endl;       else         cout << 0 << endl;       return 0;     } else if (s[s.size() - 1] ==  ( ) {       bool f = true;       for (int i = 0; i < s.size() - 1; i++) {         if (s[i] ==  ( )           arr[i]++;         else           arr[i]--;         arr[i + 1] += arr[i];         if (arr[i] < 0) f = false;       }       arr[s.size() - 1]--;       if (f && arr[s.size() - 1] == 0)         cout << 1 << endl;       else         cout << 0 << endl;       return 0;     }     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ( ) {         arr[i]++;       } else {         arr[i]--;       }       arr[i + 1] += arr[i];     }     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  ( ) {         rev[i]++;       } else {         rev[i]--;       }       rev[i] += rev[i + 1];     }     if (arr[s.size() - 1] == 2) {       int ans = 0;       for (int i = 0; i < s.size(); i++) {         if (arr[i] < 0) {           cout << 0 << endl;           return 0;         }       }       for (int i = s.size() - 1; i >= 0; i--) {         if (arr[i] <= 1) break;         if (s[i] ==  ( ) ans++;       }       cout << ans << endl;     } else if (arr[s.size() - 1] == -2) {       int ans = 0;       for (int i = 0; i < s.size(); i++) {         if (arr[i] <= -3) {           cout << 0 << endl;           return 0;         }       }       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  ) ) {           ans++;           if (arr[i] < 0) {             break;           }         }       }       cout << ans << endl;     } else {       cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000210;   inline int scan() {     char c = getchar();     int x = 0;     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x;   }   long long int n, m;   long long int a[N];   long long int parent[N];   long long int sz[N];   void reset() {     for (long long int i = 0; i <= n; i++) parent[i] = i, sz[i] = 1;   }   long long int findparent(long long int x) {     if (x != parent[x]) return findparent(parent[x]);     return parent[x];   }   void merge(long long int x, long long int y) {     x = findparent(x);     y = findparent(y);     if (sz[x] < sz[y]) swap(x, y);     sz[x] += sz[y];     parent[y] = x;   }   vector<long long int> g[N];   vector<long long int> l[N];   bool comp1(long long int x, long long int y) { return x < y; }   bool comp2(long long int x, long long int y) { return x > y; }   long long int minparent = INT_MAX, maxparent = INT_MIN;   int main() {     scanf( %lld %lld , &n, &m);     for (long long int i = 1; i <= n; i++) scanf( %lld , &a[i]);     reset();     while (m--) {       long long int a, b;       scanf( %lld %lld , &a, &b);       merge(a, b);     }     for (long long int i = 1; i <= n; i++) {       g[findparent(i)].push_back(i);       l[findparent(i)].push_back(a[i]);       minparent = min(minparent, parent[i]);       maxparent = max(maxparent, parent[i]);     }     for (long long int i = 1; i <= n; i++) {       if (findparent(i) == i) {         sort(l[i].begin(), l[i].end(), comp2);         sort(g[i].begin(), g[i].end(), comp1);         for (long long int j = 0; j < g[i].size(); j++) {           a[g[i][j]] = l[i][j];         }       }     }     for (long long int i = 1; i <= n; i++) printf( %lld  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MAXN = 200000;   using namespace std;   void RI() {}   template <typename... T>   void RI(int& head, T&... tail) {     scanf( %d , &head);     RI(tail...);   }   int a[200000];   vector<pair<double, double> > lines;   double intersection(pair<double, double> a, pair<double, double> b) {     double x = (a.second - b.second) / (a.first - b.first);     double y = (a.first * x) - a.second;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     RI(n);     for (int i = 0; i < int(n); i++) RI(a[i]);     double c = 0;     lines.push_back(make_pair(0, 0));     for (int i = 0; i < int(n); i++) {       c = c + a[i];       lines.push_back(make_pair(i + 1, c));     }     vector<int> s1;     vector<int> s2;     s1.push_back(n);     s1.push_back(n - 1);     for (int j = n - 2; j >= 0; j--) {       while (1) {         if (s1.size() == 1) {           break;         }         if (intersection(lines[s1[s1.size() - 2]], lines[j]) >=             intersection(lines[s1[s1.size() - 2]], lines[s1[s1.size() - 1]])) {           s1.pop_back();         } else {           break;         }       }       s1.push_back(j);     }     s2.push_back(0);     s2.push_back(1);     for (int j = 2; j <= n; j++) {       while (1) {         if (s2.size() == 1) {           break;         }         if (intersection(lines[s2[s2.size() - 2]], lines[j]) >=             intersection(lines[s2[s2.size() - 2]], lines[s2[s2.size() - 1]])) {           s2.pop_back();         } else {           break;         }       }       s2.push_back(j);     }     int curr_line = 0;     double ans = 1000000000.0;     for (int j = 0; j < s2.size() - 1; j++) {       double inter1 = intersection(lines[s2[j]], lines[s2[j + 1]]);       while (1) {         if (curr_line >= s1.size() - 1) {           break;         }         double inter =             intersection(lines[s1[curr_line]], lines[s1[curr_line + 1]]);         if (inter <= inter1) {           break;         } else {           curr_line++;         }       }       double y1 = (lines[s2[j]].first * inter1) - lines[s2[j]].second;       double y2 =           (lines[s1[curr_line]].first * inter1) - lines[s1[curr_line]].second;       ans = min(abs(y2 - y1), ans);     }     curr_line = 0;     for (int j = 0; j < s1.size() - 1; j++) {       double inter1 = intersection(lines[s1[j]], lines[s1[j + 1]]);       while (1) {         if (curr_line >= s2.size() - 1) {           break;         }         double inter =             intersection(lines[s2[curr_line]], lines[s2[curr_line + 1]]);         if (inter <= inter1) {           break;         } else {           curr_line++;         }       }       double y1 = (lines[s1[j]].first * inter1) - lines[s1[j]].second;       double y2 =           (lines[s2[curr_line]].first * inter1) - lines[s2[curr_line]].second;       ans = min(abs(y2 - y1), ans);     }     printf( %.12f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool judge(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  || c ==  y )       return false;     else       return true;   }   int main() {     char a[110];     int n, m = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       if (judge(a[i])) {         cout << a[i];         m = 0;       } else if (m == 1)         continue;       else if (!judge(a[i]))         cout << a[i], m = 1;     }   }
#include <bits/stdc++.h>   using namespace std;   char s[55][55];   int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, 1, -1}, n, vis[55][55];   bool check(int x, int y) {     for (int i = 0; i < 4; i++) {       int tx = x + dx[i], ty = y + dy[i];       if (tx < 1 || tx > n || ty < 1 || ty > n || s[tx][ty] ==  #  || vis[tx][ty])         return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (vis[i][j] || s[i][j] ==  # ) continue;         if (check(i, j)) {           vis[i][j] = 1;           for (int k = 0; k < 4; k++) vis[i + dx[k]][j + dy[k]] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (vis[i][j])           continue;         else if (s[i][j] ==  # )           continue;         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool notis[30] = {false}, mayis[30] = {false};   string str;   int main() {     int n, flag = 0, cnt = 0, tem, i, j;     char p;     std::ios::sync_with_stdio(false);     cin >> n;     for (i = 0; i < n; i++) {       cin >> p >> str;       if (flag && (p ==  !  || p ==  ? ))         cnt++;       else {         tem = str.length();         if (p ==  ! ) {           for (j = 0; j < tem; j++) mayis[str[j] -  a ] = true;           for (j = 0; j < 26; j++) {             if (!mayis[j]) notis[j] = true;             mayis[j] = false;           }         } else           for (j = 0; j < tem; j++) notis[str[j] -  a ] = true;         for (tem = j = 0; j < 26; j++)           if (!notis[j]) tem++;         if (tem == 1) flag = 1;       }     }     printf( %d , cnt > 0 ? (cnt - 1) : 0);   }
#include <bits/stdc++.h>   using namespace std;   long long dp[2005][2005];   string s;   long long cnt[2005];   long long powr[2005];   long long solve(int l, int r) {     if (dp[l][r] != -1) {       return dp[l][r];     }     if (l >= r) return 0;     dp[l][r] = 0;     if (s[l] ==  ) ) {       dp[l][r] += solve(l + 1, r);     }     if (s[r] ==  ( ) {       dp[l][r] += solve(l, r - 1);     }     if (s[l] ==  )  && s[r] ==  ( ) {       dp[l][r] -= solve(l + 1, r - 1);     }     if (s[l] ==  (  && s[r] ==  ) ) {       dp[l][r] += solve(l + 1, r - 1) + powr[cnt[r] - cnt[l + 1]];     }     if (s[l] ==  ?  && s[r] ==  ? ) {       dp[l][r] += solve(l + 1, r) + solve(l, r - 1) + powr[cnt[r] - cnt[l + 1]];     }     if (s[l] ==  ?  && s[r] ==  ) ) {       dp[l][r] +=           solve(l + 1, r - 1) + solve(l + 1, r) + powr[cnt[r] - cnt[l + 1]];     }     if (s[r] ==  ?  && s[l] ==  ( ) {       dp[l][r] +=           solve(l + 1, r - 1) + solve(l, r - 1) + powr[cnt[r] - cnt[l + 1]];     }     return (dp[l][r] + 2LL * 998244353) % 998244353;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  ? ) {           cnt[i + 1] = cnt[i] + 1;         } else           cnt[i + 1] = cnt[i];       }       powr[0] = 1;       for (int i = 1; i < 2005; i++) {         powr[i] = powr[i - 1] * 2 % 998244353;       }       memset(dp, -1, sizeof(dp));       cout << solve(0, s.size() - 1);     }     return 0;   }