malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void require(bool cond, const string& message =  Runtime error ) {     if (!cond) {       cerr << message << endl;       assert(false);     }   }   void readData() {}   long long mina, maxa;   void solve(long long x, long long n) {     long long m = n / x;     for (long long y = 1; y * y <= m; ++y) {       if (m % y) continue;       long long z = m / y;       long long nn = (x + 1) * (y + 2) * (z + 2);       if (mina == -1) mina = nn - n;       mina = min(mina, nn - n);       maxa = max(maxa, nn - n);     }   }   void solve() {     long long n;     cin >> n;     mina = -1;     maxa = 1;     for (long long x = 1; x * x <= n; ++x) {       if (n % x) continue;       solve(x, n);       solve(n / x, n);     }     cout << mina <<     << maxa << endl;   }   int main() {     ios_base::sync_with_stdio(false);     readData();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[1005];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < n; i++) {         cin >> arr[i];       }       long long left = 1;       long long right = n - 1;       long long cnt = 1;       long long leftSum, rightSum;       leftSum = rightSum = 0;       leftSum = arr[0];       long long turn = 1;       long long prevSum = arr[0];       while (left <= right) {         if (turn == 0) {           long long currSum = 0;           while (currSum <= prevSum) {             currSum += arr[left];             left++;             if (left > right) break;           }           prevSum = currSum;           leftSum += currSum;           turn = 1;         } else {           long long currSum = 0;           while (currSum <= prevSum) {             currSum += arr[right];             right--;             if (left > right) break;           }           prevSum = currSum;           rightSum += currSum;           turn = 0;         }         cnt++;       }       cout << cnt <<     << leftSum <<     << rightSum <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MXN = 100100;   const int QQ = 500;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const int mod = 1000000007;   set<pair<int, int> > eds;   int x[MXN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int a, b;     for (int i = 0; i < (m); i++) {       scanf( %d%d , &a, &b);       eds.insert(make_pair(a, b));       eds.insert(make_pair(b, a));     }     for (int i = 0; i < (n); i++) x[i] = i + 1;     for (int i = 0; i < (QQ); i++) {       random_shuffle(x, x + n);       bool bad = false;       for (int i = 0; i < (m); i++)         if (eds.find(make_pair(x[i % n], x[(i + 1) % n])) != eds.end()) {           bad = true;           break;         }       if (bad) continue;       for (int i = 0; i < (m); i++) {         printf( %d %d n , x[i % n], x[(i + 1) % n]);       }       return 0;     }     printf( -1 );   }
#include <bits/stdc++.h>   using namespace std;   long double a[1001][1001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, t, m, w, b;     cout.precision(12);     cin >> w >> b;     for (int i = 0; i <= w; i++) {       for (int j = 0; j <= b; j++) {         if (!i && !j) continue;         long double x = i * 1.0;         long double y = j * 1.0;         a[i][j] = (x / (x + y));         long double z = (y - 2) / (x + y - 2);         if ((i >= 0) && ((j - 3) >= 0)) {           a[i][j] += (a[i][j - 3] * z * (y / (x + y)) * ((y - 1) / (x + y - 1)));         }         if (((i - 1) >= 0) && ((j - 2) >= 0)) {           a[i][j] += (a[i - 1][j - 2] * (1 - z) * (y / (x + y)) *                       ((y - 1) / (x + y - 1)));         }       }     }     cout << fixed << a[w][b];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(long long a, long long b) {     if (a > b)       return true;     else       return false;   }   int isP(long long n) {     if (n == 1) return 0;     if (n == 2 || n == 3) return 1;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t, n, k, va;     bool ha;     cin >> t;     while (t--) {       cin >> n >> k;       if (n == 0)         ha = false;       else if (n == 1 || n == 2)         ha = true;       else if (n == 3) {         if (k == 3)           ha = true;         else           ha = false;       } else {         if (k % 3 != 0) {           va = n % 3;           if (va == 0)             ha = false;           else             ha = true;         } else {           n %= (k + 1);           if (n % 3 == 0)             ha = false;           else             ha = true;           if (n == k) ha = true;         }       }       if (ha)         cout <<  Alice n ;       else         cout <<  Bob n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int how_many(string s, vector<string>& deleted) {     int res = 0;     for (auto i : deleted)       for (int j = 0; j < s.size(); j++) {         if (i[j] != s[j]) break;         if (j == s.size() - 1) res++;       }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> deleted(n);       for (int i = 0; i < n; i++) cin >> deleted[i];       string res =   ;       long long curr = ((1LL << m) + 1 - n) / 2;       for (int i = 0; i < m; i++) {         long long x = (1LL << (m - i - 1)) - how_many(res +  0 , deleted);         if (x >= curr)           res.push_back( 0 );         else {           res.push_back( 1 );           curr -= x;         }       }       cout << res <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, m, w[2010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &w[i]);     }     for (int i = 1, a, b; i <= m; i++) {       scanf( %d%d , &a, &b);       ans += min(w[a], w[b]);     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> g;   bool can;   int n, i;   char s[100][5];   void find(int x) {     char temp[10];     string ss;     int j;     if (x == 1) {       can = true;       return;     }     if ((s[x][0] == s[x - 1][0]) || (s[x][1] == s[x - 1][1])) {       strcpy(temp, s[x - 1]);       strcpy(s[x - 1], s[x]);       ss.clear();       for (j = 1; j <= x - 1; j++) ss = ss + s[j];       if (g[ss] == 0) {         g[ss] = 1;         find(x - 1);       }       strcpy(s[x - 1], temp);     }     if (x > 3)       if ((s[x][0] == s[x - 3][0]) || s[x][1] == s[x - 3][1]) {         strcpy(temp, s[x - 3]);         strcpy(s[x - 3], s[x]);         for (j = 1; j <= x - 1; j++) ss = ss + s[j];         if (g[ss] == 0) {           g[ss] = 1;           find(x - 1);         }         strcpy(s[x - 3], temp);       }   }   int main() {     can = false;     cin >> n;     g.clear();     memset(s, 0, sizeof(s));     for (i = 1; i <= n; i++) scanf( %s , s[i]);     find(n);     if (can)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, n, p[30], ans;     cin >> m >> n;     for (__typeof(0) i = 0; i <= n - 1; i++) {       cout <<  1 n ;       fflush(stdout);       cin >> ans;       if (ans == 0) return 0;       if (ans == -1)         p[i] = 0;       else         p[i] = 1;     }     long long low = 1, high = m, mid, i = 0;     while (low <= high) {       mid = (low + high) / 2;       cout << mid <<   n ;       fflush(stdout);       cin >> ans;       if (p[i] == 0) ans *= -1;       i = (i + 1) % n;       if (ans == 0 || ans == -2 || ans == 2) return 0;       if (ans == -1)         high = mid - 1;       else if (ans == 1)         low = mid + 1;       else         return 0;     }     return 0;   }
#include <bits/stdc++.h>   inline int Abs(int x) { return x < 0 ? -x : x; }   inline int Sgn(int x) { return x < 0 ? -1 : 1; }   const int MN = 100005, Sig = 26;   const int ML = 100005;   const int MQ = 100005;   const int T = 400;   const int B = 400;   int N, Id[MN], Len[MN];   char str[ML];   int nxt[ML][Sig], faz[ML], fail[ML], Num[ML], cnt;   int que[ML], l, r;   std::vector<int> G[ML];   inline int Ins(char *S) {     int now = 0;     for (; *S; ++S) {       int j = *S -  a ;       if (!nxt[now][j]) nxt[now][j] = ++cnt, faz[cnt] = now;       now = nxt[now][j];     }     return now;   }   inline void BuildAC() {     fail[0] = faz[0] = -1;     que[l = r = 1] = 0;     while (l <= r) {       int u = que[l++];       for (int j = 0; j < Sig; ++j) {         if (nxt[u][j]) {           fail[nxt[u][j]] = u ? nxt[fail[u]][j] : 0;           G[fail[nxt[u][j]]].push_back(nxt[u][j]);           que[++r] = nxt[u][j];         } else           nxt[u][j] = u ? nxt[fail[u]][j] : 0;       }     }   }   int ldf[ML], rdf[ML], dfc;   void DFS(int u) {     ldf[u] = ++dfc;     for (auto v : G[u]) DFS(v);     rdf[u] = dfc;   }   int blk[ML], add[ML], tag[ML / B + 10];   inline void Add(int ql, int qr) {     if (blk[ql] == blk[qr])       for (int i = ql; i <= qr; ++i) ++add[i];     else {       for (int i = ql; blk[i] == blk[ql]; ++i) ++add[i];       for (int i = qr; blk[i] == blk[qr]; --i) ++add[i];       for (int i = blk[ql] + 1; i < blk[qr]; ++i) ++tag[i];     }   }   inline int Qur(int p) { return add[p] + tag[blk[p]]; }   int Q, ql[MQ], qr[MQ], qk[MQ];   long long Ans[MQ];   std::vector<std::pair<int, int>> C0[MN], C1[MN];   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1; i <= N; ++i) {       scanf( %s , str);       Len[i] = strlen(str);       Id[i] = Ins(str);     }     BuildAC();     DFS(0);     for (int i = 1; i <= dfc; ++i) blk[i] = (i - 1) / B + 1;     for (int i = 1; i <= Q; ++i) {       scanf( %d%d%d , &ql[i], &qr[i], &qk[i]);       if (ql[i] > 1) C0[ql[i] - 1].push_back({qk[i], -i});       C0[qr[i]].push_back({qk[i], i});     }     for (int i = 1; i <= N; ++i) {       Add(ldf[Id[i]], rdf[Id[i]]);       for (auto j : C0[i]) {         if (Len[j.first] > T)           C1[j.first].push_back({i, j.second});         else {           int k = j.first;           long long Sum = 0;           for (int x = Id[k]; x != -1; x = faz[x]) Sum += Qur(ldf[x]);           Ans[Abs(j.second)] += Sgn(j.second) * Sum;         }       }     }     for (int i = 1; i <= N; ++i)       if (Len[i] > T) {         for (int x = Id[i]; x != -1; x = faz[x]) ++Num[x];         for (int j = r; j > 1; --j) Num[fail[que[j]]] += Num[que[j]];         int p = 0;         long long Sum = 0;         for (auto x : C1[i]) {           while (p < x.first) Sum += Num[Id[++p]];           Ans[Abs(x.second)] += Sgn(x.second) * Sum;         }         for (int j = 0; j <= cnt; ++j) Num[j] = 0;       }     for (int i = 1; i <= Q; ++i) printf( %lld n , Ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2 * 100 * 1000 + 100;   int n, dp[MAXN], d[MAXN], mark[MAXN], ans[MAXN], D = 0, MIN = MAXN;   pair<int, int> par[MAXN];   vector<pair<int, int> > g[MAXN];   vector<int> q, depth[MAXN], res;   void bfs() {     for (int i = 0; i < q.size(); i++) {       int v = q[i];       for (int j = 0; j < g[v].size(); j++) {         int u = g[v][j].first;         if (!mark[u]) {           mark[u] = true;           par[u] = make_pair(v, (g[v][j].second + 1) % 2);           d[u] = d[v] + 1;           D = max(D, d[u]);           depth[d[u]].push_back(u);           q.push_back(u);         }       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(make_pair(y, 0));       g[y].push_back(make_pair(x, 1));     }     d[0] = 0;     mark[0] = true;     q.push_back(0);     depth[0].push_back(0);     bfs();     for (int i = D - 1; i >= 0; i--) {       for (int j = 0; j < depth[i].size(); j++) {         int v = depth[i][j];         for (int z = 0; z < g[v].size(); z++) {           int u = g[v][z].first;           if (u != par[v].first) dp[v] += dp[u] + g[v][z].second;         }       }     }     ans[0] = dp[0];     MIN = ans[0];     for (int i = 1; i <= D; i++) {       for (int j = 0; j < depth[i].size(); j++) {         int v = depth[i][j];         int p = par[v].first;         ans[v] = ans[p];         if (par[v].second == 0)           ans[v] -= 1;         else           ans[v] += 1;         MIN = min(ans[v], MIN);       }     }     cout << MIN << endl;     for (int i = 0; i < n; i++)       if (ans[i] == MIN) cout << i + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   const int INF = 0x3f3f3f3f3f, mod = 1e9 + 7;   const double eps = 1e-6, PI = acos(-1);   template <typename T>   inline void read(T &x) {     x = 0;     T f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1;     } while (ch <  0  || ch >  9 );     do x = x * 10 + ch -  0 , ch = getchar();     while (ch <=  9  && ch >=  0 );     x *= f;   }   long long n, m;   int main() {     read(n), read(m);     long long min1 = max(0LL, n - m * 2);     if (m == 0) {       printf( %lld %lld n , n, n);       return 0;     }     long long max1 = 0;     for (int i = 2; i <= n; i++) {       long long now = 1LL * i * (i - 1) / 2;       if (m <= now) {         max1 = n - i;         break;       }     }     printf( %lld %lld n , min1, max1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INF = 100000000;   int n, m, x, y;   char ch;   long long int pre[2][(int)1e3 + 5], dp[2][(int)1e3 + 5];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> x >> y;     memset(pre, 0, sizeof(pre));     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> ch;         if (ch ==  . )           pre[1][j]++;         else           pre[0][j]++;       }     }     for (int i = 1; i <= m; i++) {       pre[0][i] += pre[0][i - 1];       pre[1][i] += pre[1][i - 1];     }     for (int i = 1; i <= m; i++) {       dp[0][i] = INT_MAX;       dp[1][i] = INT_MAX;       for (int j = x; j <= y; j++) {         if (i - j < 0) {           break;         }         dp[0][i] = min(dp[0][i], dp[1][i - j] + pre[0][i] - pre[0][i - j]);         dp[1][i] = min(dp[1][i], dp[0][i - j] + pre[1][i] - pre[1][i - j]);       }     }     cout << min(dp[0][m], dp[1][m]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100007, INF = 1000000007;   int main() {     int n, m, k, cnt = 0;     long long d[MAXN], d1[MAXN];     vector<pair<int, int> > G[MAXN];     pair<long long, int> used[MAXN];     set<pair<long long, int> > S;     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i < (n); ++i) d[i] = d1[i] = 1LL * INF * INF;     for (int i = (0); i < (m); ++i) {       int u, v, x;       scanf( %d%d%d , &u, &v, &x);       --u;       --v;       G[u].push_back(make_pair(v, x));       G[v].push_back(make_pair(u, x));     }     for (int i = (0); i < (k); ++i) {       int s, ys;       scanf( %d%d , &s, &ys);       --s;       d[s] = min(d[s], 1LL * ys);     }     d1[0] = d[0] = 0;     for (int i = (0); i < (n); ++i) S.insert(make_pair(d[i], i));     for (int j = (0); j < (n); ++j) {       int v = S.begin()->second, to;       for (int i = (0); i < (((int)(G[v]).size())); ++i) {         to = G[v][i].first;         if (S.count(make_pair(d[to], to)) && d[v] + G[v][i].second < d[to]) {           S.erase(make_pair(d[to], to));           d[to] = d[v] + G[v][i].second;           S.insert(make_pair(d[to], to));         }       }       S.erase(S.begin());       used[j] = make_pair(d[v], v);     }     sort(used, used + n);     for (int i = (0); i < (n); ++i) {       int v = used[i].second, to;       for (int j = (0); j < (((int)(G[v]).size())); ++j) {         to = G[v][j].first;         d1[v] = min(d1[v], d1[to] + G[v][j].second);       }       if (d1[v] != d[v]) ++cnt;       d1[v] = d[v];     }     printf( %d , k - cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long powerFunction(long long x, long long y) {     long long res = 1;     long long p = 1000000007;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool prime[10000001];   long long P = 1000000007 - 2;   long long fact[10000001] = {0};   void sieveFunction(long long maxLimit) {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (long long i = 2; maxLimit >= i; i++) {       if (prime[i]) {         for (long long j = 2 * i; maxLimit >= j; j += i) prime[j] = false;       }     }   }   void factorialFunction(long long maxLimit) {     fact[0] = 1;     for (long long i = 1; i <= maxLimit; i++)       fact[i] = (fact[i - 1] * i) % 1000000007;     return;   }   long long nCr(long long n, long long r) {     long long a = fact[n];     long long b = powerFunction(fact[n - r], 1000000007 - 2);     long long c = powerFunction(fact[r], 1000000007 - 2);     return (a * (b % 1000000007 * c % 1000000007) % 1000000007) % 1000000007;   }   signed main() {     long long n;     cin >> n;     vector<pair<long long, long long>> adj[n + 1];     long long vis[n + 1];     long long ind;     long long f;     for (long long i = 0; i < n - 1; i++) {       vis[i] = -1;       long long u, v;       cin >> u >> v;       adj[u].push_back({i, v});       adj[v].push_back({i, u});     }     long long p = 0;     for (long long i = 1; i < n + 1; i++) {       if ((long long)adj[i].size() < 3)         continue;       else {         for (auto it : adj[i]) {           if (vis[it.first] == -1) {             vis[it.first] = p;             p++;           }         }       }     }     for (long long i = 0; i < n - 1; i++) {       if (vis[i] == -1) {         vis[i] = p;         p++;       }       cout << vis[i] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> edge;   int n, m;   int parent[100000];   int size[100000];   int visited[100000];   int finished[100000];   int has_loop[100000];   int find_root(int v) {     if (parent[v] == -1) {       return v;     }     return parent[v] = find_root(parent[v]);   }   void merge(int u, int v) {     u = find_root(u), v = find_root(v);     if (u == v) {       return;     }     if (size[u] < size[v]) {       merge(v, u);       return;     }     parent[v] = u;     size[u] += size[v];   }   void dfs(int here) {     visited[here] = true;     for (int there : edge[here]) {       if (finished[there]) {         continue;       } else if (visited[there]) {         has_loop[find_root(here)] = 1;       } else {         dfs(there);       }     }     finished[here] = true;   }   void loop_check() {     for (int i = 0; i < n; i++) {       if (!visited[i]) {         dfs(i);       }     }   }   int main() {     cin >> n >> m;     edge = vector<vector<int>>(n, vector<int>());     for (int i = 0; i < n; i++) {       parent[i] = -1;       size[i] = 1;     }     for (int i = 0; i < m; i++) {       int from, to;       cin >> from >> to;       edge[from - 1].push_back(to - 1);       merge(from - 1, to - 1);     }     vector<int> wcc_list;     for (int i = 0; i < n; i++) {       if (find_root(i) == i) {         wcc_list.push_back(i);       }     }     loop_check();     int ans = 0;     for (int wcc : wcc_list) {       ans += size[wcc] - 1;       if (has_loop[wcc]) {         ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int T, a[4], ans;   inline bool cmp(int x, int y) { return x > y; }   int main() {     scanf( %d , &T);     while (T--) {       ans = 0;       scanf( %d%d%d , &a[1], &a[2], &a[3]);       sort(a + 1, a + 3 + 1, cmp);       for (int i = 1; i <= 3; ++i) {         if (a[i]) a[i]--, ans++;       }       for (int i = 1; i <= 2; ++i) {         for (int j = i + 1; j <= 3; ++j) {           if (a[i] && a[j]) ans++, a[i]--, a[j]--;         }       }       if (a[1] && a[2] && a[3]) ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1001001][2];   vector<int> G[1001001];   int ans[1001001] = {};   int ma[1001001] = {};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (2); ++j) dp[i][j] = 0;     for (int i = (n)-1; i >= 0; --i) {       if (i == n - 1) {         if (s[i] ==  0 ) {           dp[i][0] = 1;         } else if (s[i] ==  1 ) {           dp[i][1] = 1;         } else {           dp[i][0] = 1;           dp[i][1] = 1;         }       } else {         if (s[i] ==  0 ) {           dp[i][0] = dp[i + 1][0] + 1;         } else if (s[i] ==  1 ) {           dp[i][1] = dp[i + 1][1] + 1;         } else {           dp[i][0] = dp[i + 1][0] + 1;           dp[i][1] = dp[i + 1][1] + 1;         }       }       ma[i] = max(dp[i][0], dp[i][1]);       if (i > 0) {         if (s[i - 1] ==  0  && s[i] !=  0 ) {           for (int j = 0; j < (dp[i][1]); ++j) {             G[j + 1].push_back(i);           }         }         if (s[i - 1] ==  1  && s[i] !=  1 ) {           for (int j = 0; j < (dp[i][0]); ++j) {             G[j + 1].push_back(i);           }         }       }     }     set<int> se;     for (int i = 0; i < (n + 1); ++i) {       sort(G[i].begin(), G[i].end());     }     for (int i = (n + 1) - 1; i >= 0; --i) {       if (i <= 20) break;       if (i == 0) break;       int now = 0;       int ite = 0;       int m = G[i].size();       while (now < n) {         if (ma[now] >= i) {           ans[i]++;           now += i;         } else {           while (ite < m) {             if (G[i][ite] >= now) {               break;             }             ite++;           }           if (ite == m) break;           ans[i]++;           now = G[i][ite] + i;         }       }     }     for (int i = 1; i < 21; ++i) {       if (i > n) break;       int now = 0;       while (now < n) {         if (ma[now] >= i) {           ans[i]++;           now += i;         } else {           now++;         }       }     }     for (int i = 1; i < n + 1; ++i) printf( %d  , ans[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   long long f[2001], dp[2001][2001], m = 998244353;   long long fun(long long i, long long j) {     if (i == 0)       return (f[j]);     else       return (f[j] - f[i - 1]);   }   long long fpow(long long a, long long p) {     if (p == 0) return (1);     long long b = fpow(a, p / 2);     if (p % 2 == 0)       return ((b * b) % m);     else       return ((((b * b) % m) * a) % m);   }   int main() {     string s;     cin >> s;     if (s[0] ==  ? ) f[0] = 1;     for (long long i = 1; i < s.length(); i++) {       if (s[i] ==  ? ) f[i] += 1;       f[i] += f[i - 1];     }     for (long long i = 2; i <= s.length(); i++) {       for (long long j = 0; j <= (s.length() - i); j++) {         if (s[j] !=  ( )           dp[j][j + i - 1] = (dp[j][j + i - 1] + dp[j + 1][j + i - 1]) % m;         if (s[j + i - 1] !=  ) )           dp[j][j + i - 1] = (dp[j][j + i - 1] + dp[j][j + i - 2]) % m;         if ((s[j] !=  ( ) && (s[j + i - 1] !=  ) ))           dp[j][j + i - 1] = (dp[j][j + i - 1] - dp[j + 1][j + i - 2] + m) % m;         if ((s[j] !=  ) ) && (s[j + i - 1] !=  ( ))           dp[j][j + i - 1] = (dp[j][j + i - 1] + dp[j + 1][j + i - 2] +                               (long long)fpow(2, fun(j + 1, j + i - 2))) %                              m;       }     }     cout << dp[0][s.length() - 1];   }