malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 87;   int n, pa[N], de[N], f[N], dp[N], cc[N];   vector<int> g[N];   pair<int, int> md;   void dfs(int p, int u, int d) {     md = max(md, pair<int, int>(d, u));     pa[u] = p;     de[u] = d;     if (d == md.first) {       dp[u] = 1;       cc[u] = u;     } else {       dp[u] = 0;       cc[u] = 0;     }     for (int v : g[u])       if (v != p) {         dfs(u, v, d + 1);         dp[u] += dp[v];         cc[u] = max(cc[u], cc[v]);       }   }   bool ok(int p, int u, int d) {     if (f[d] == 0)       f[d] = g[u].size();     else if (f[d] != g[u].size())       return 0;     for (int v : g[u])       if (v != p && !ok(u, v, d + 1)) return 0;     return 1;   }   void test(int u) {     memset(f, 0, sizeof f);     if (ok(u, u, 0)) {       cout << u << endl;       exit(0);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     if (n <= 3) {       cout <<  1 n ;       return 0;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     md = {0, 0};     dfs(0, 1, 0);     int a = md.second;     md = {0, 0};     dfs(0, a, 0);     int b = md.second;     int d = md.first;     if (d % 2) {       test(a);       test(b);     } else {       int k = d / 2;       int c = b;       for (int i = 0; i < k; ++i) c = pa[c];       md = {k, a};       test(c);       dfs(0, c, 0);       for (int i = 1; i <= n; ++i)         if (g[i].size() == 1 && de[i] < k) {           test(i);           break;         }       for (int v : g[c])         if (dp[v] == 1) {           test(cc[v]);           break;         }     }     cout <<  -1 n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = int(1e9 + 7), maxK = 23, maxN = 107;   vector<int> a[maxN];   int n, k;   int f[maxN][maxK][maxK], g[2][maxK][maxK];   inline void add(int &a, long long b) { a = (a + b) % MOD; }   void calculate(int u, int par) {     memset(g, 0, sizeof g);     bool first = true;     int G = 1, nj, np, cur = 1, prev = 0;     memset(g[cur], 0, sizeof g[cur]);     g[cur][k + 1][1] = 1;     for (int v : a[u])       if (v != par) {         int sg = 0;         swap(cur, prev);         memset(g[cur], 0, sizeof g[cur]);         for (int j = 0; j <= k + 1; j++)           for (int p = 0; p <= k + 1; p++) {             if (p <= k) add(sg, f[v][j][p]);             for (int jj = 0; jj <= k + 1; jj++)               for (int pp = 0; pp <= k + 1; pp++) {                 nj = min(j, jj + 1);                 if (jj + p > k)                   np = p;                 else                   np = 0;                 if (j + pp > k && pp > 0) np = max(np, pp + 1);                 add(g[cur][nj][np], 1LL * g[prev][j][p] * f[v][jj][pp]);               }           }         G = (1LL * G * sg) % MOD;       }     g[cur][0][0] = G;     for (int j = 0; j <= k + 1; j++)       for (int p = 0; p <= k + 1; p++) {         f[u][j][p] = g[cur][j][p];       }   }   void visit(int u, int par = -1) {     for (int v : a[u])       if (v != par) {         visit(v, u);       }     calculate(u, par);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       a[u].push_back(v);       a[v].push_back(u);     }     memset(f, 0, sizeof f);     visit(1, -1);     int res = 0;     for (int j = 0; j <= k + 1; j++) add(res, f[1][j][0]);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pos, ans, a[20], b[20], cnt[12];   bool check(int pos, bool Ls, bool Rs) {     if (pos == 0) return true;     if (!Ls && !Rs) return true;     int l = Ls ? a[pos] : 0, r = Rs ? b[pos] : 9;     for (int i = l; i <= r; i++)       if (cnt[i]) {         cnt[i]--;         if (check(pos - 1, Ls && i == l, Rs && i == r)) {           cnt[i]++;           return true;         }         cnt[i]++;       }     return false;   }   void dfs(int cur, int total) {     if (cur == 9) {       cnt[cur] = total;       ans += check(pos, 1, 1);       return;     }     for (int i = 0; i <= total; i++) {       cnt[cur] = i;       dfs(cur + 1, total - i);       cnt[cur] = 0;     }   }   int digit(long long x, int d[]) {     register int pos = 0;     if (x == 0) d[++pos] = 0;     while (x) {       d[++pos] = x % 10;       x /= 10;     }     return pos;   }   int main() {     long long l, r;     cin >> l >> r;     digit(l, a);     pos = digit(r, b);     ans = 0;     dfs(0, pos);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long int n, m, a, b;     cin >> n >> m >> a >> b;     if (n % m == 0) {       cout <<  0 ;       return 0;     } else if (n > m) {       unsigned long long int p = (n / m) + 1;       unsigned long long int c = (m * p - n) * a;       unsigned long long int d = (n % m) * b;       cout << min(c, d) << endl;       return 0;     } else if (m > n) {       unsigned long long int c = (m - n) * a;       unsigned long long int d = n * b;       cout << min(c, d) << endl;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 5;   const long long MAX_N = 1e5 + 5;   const long long MODD = 1e9 + 7;   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   double max(double a, double b) { return a > b ? a : b; }   double min(double a, double b) { return a < b ? a : b; }   long long modd(long long a) {     if (a < 0LL) return a * -1LL;     return a;   }   double modd(double a) {     if (a < 0.0) return a * -1.0;     return a;   }   long long modulo(long long a) { return (a + MODD) % MODD; }   long long power(long long k, long long p) {     if (p == 0) return 1LL;     long long P = power(k, p / 2LL);     P = (P * P) % MODD;     if (p % 2 == 1) P = (P * k) % MODD;     return P;   }   struct p_str {     long long a, b;   };   void solve() {     long long v[3];     for (long long i = 0; i < 3; i++) {       cin >> v[i];     }     sort(v, v + 3);     long long ans = INF;     for (long long i = v[0] - 1; i <= v[0] + 1; i++) {       for (long long j = v[1] - 1; j <= v[1] + 1; j++) {         for (long long k = v[2] - 1; k <= v[2] + 1; k++) {           if (i <= j && j <= k) {             long long t = j - i;             t += k - j;             t += k - i;             ans = min(ans, t);           }         }       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename TP>   inline bool rd(TP& r) {     r = 0;     char tmp = getchar();     while (tmp <  0  || tmp >  9 ) {       if (tmp == EOF) return 0;       tmp = getchar();     }     while ( 0  <= tmp && tmp <=  9 ) {       r = (r << 3) + (r << 1) + tmp -  0 ;       tmp = getchar();     }     return 1;   }   struct edge {     int u, v, bl;     long long w;     edge(int uu = 0, int vv = 0, long long ww = 0, int belon = 0) {       u = uu, v = vv, w = ww;       bl = belon;     }     friend bool operator<(edge a, edge b) {       if (a.w != b.w) return a.w < b.w;       return a.bl < b.bl;     }   } e[500100], qe[500100];   int n, m, q;   int ac[500100], sz[500100];   int get(int x) {     if (ac[x] == x) return x;     ac[x] = get(ac[x]);     return ac[x];   }   int ask(int x) {     if (ac[x] == x) return x;     return ask(ac[x]);   }   int chg[500100 * 2], tp;   void merge(int a, int b) {     a = ask(a), b = ask(b);     if (sz[a] < sz[b]) swap(a, b);     ac[b] = a;     chg[++tp] = b;     sz[a] += sz[b];   }   bool fail[500100];   int main() {     int mxw = 0;     rd(n), rd(m);     int u, v;     int w;     for (int i = 1; i <= m; i++) {       rd(u), rd(v);       rd(w);       e[i] = edge(u, v, w);       mxw = max(mxw, w);     }     rd(q);     int k, tot = 0, a;     for (int i = 1; i <= q; i++) {       rd(k);       for (int j = 1; j <= k; j++) {         rd(a);         qe[++tot] = e[a];         qe[tot].bl = i;       }     }     sort(qe + 1, qe + tot + 1);     sort(e + 1, e + m + 1);     for (int i = 1; i <= n; i++) {       ac[i] = i;       sz[i] = 1;     }     int now = 1, bl, po = 1;     for (w = 1; w <= mxw; w++) {       for (; now <= tot;) {         if (w != qe[now].w) break;         bl = qe[now].bl;         for (; now <= tot; now++) {           if (qe[now].bl != bl || qe[now].w != w) break;           if (ask(qe[now].u) == ask(qe[now].v))             fail[qe[now].bl] = 1;           else             merge(qe[now].u, qe[now].v);         }         while (tp) {           sz[ac[chg[tp]]] -= sz[chg[tp]];           ac[chg[tp]] = chg[tp];           tp--;         }       }       for (; po <= m; po++) {         if (e[po].w != w) break;         if (get(e[po].u) != get(e[po].v)) merge(e[po].u, e[po].v);       }       tp = 0;     }     for (int i = 1; i <= q; i++)       if (fail[i])         printf( NO n );       else         printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n + 1];       for (int i = 0; i < n; i++) cin >> a[i];       map<int, int> mp;       if (n & 1) {         cout << -1 << endl;         continue;       }       for (int i = 0; i < n; i++)         for (int j = i + 1; j < n; j++) mp[a[i] ^ a[j]]++;       int ans = -1;       for (auto it = mp.begin(); it != mp.end(); it++) {         if (it->second == (n / 2)) {           ans = it->first;           break;         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long base = 1e9 + 7;   const long long MAX_N = 2e5 + 7;   long long dd2[MAX_N];   void Solves() {     long long n, k;     cin >> n >> k;     long long l[n + 1];     long long r[n + 1];     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> > >         pq1;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq2;     vector<pair<long long, long long> > dd[MAX_N];     for (int i = 1; i <= n; i++) {       cin >> l[i] >> r[i];       dd[l[i]].push_back(pair<long long, long long>(r[i], i));     }     int countt = 0;     int sum = 0;     vector<pair<long long, long long> > ans;     for (int i = 1; i <= 2e5; i++) {       for (auto j : dd[i]) {         pq1.push(j);         pq2.push(j);         sum++;       }       while (!pq2.empty()) {         pair<long long, long long> gg = pq2.top();         if (gg.first < i) {           pq2.pop();           if (dd2[gg.second] == 0) countt++;           dd2[gg.second]++;         } else           break;       }       while (sum - countt > k) {         pair<long long, long long> gg = pq1.top();         pq1.pop();         if (dd2[gg.second] == 0) countt++;         dd2[gg.second]++;         ans.push_back(gg);       }     }     cout << ans.size() <<   n ;     for (auto j : ans) cout << j.second <<    ;   }   int main() { Solves(); }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int sz, val;     Node *left, *right;     Node() : left(NULL), right(NULL), sz(0), val(-1) {}     ~Node() {       delete left;       delete right;     }   };   int A[200000];   void insert(Node*& curr, int i, int x) {     if (curr == NULL) curr = new Node();     if (i == -1)       curr->val = x;     else {       if ((1 << i) & A[x])         insert(curr->left, i - 1, x);       else         insert(curr->right, i - 1, x);     }     curr->sz += 1;     return;   }   int find(Node* curr) {     if (curr == NULL) return 0;     if (curr->val > -1) return 1;     if (curr->left == NULL) return find(curr->right);     if (curr->left->sz == 1) return 1 + find(curr->right);     if (curr->right == NULL) return find(curr->left);     if (curr->right->sz == 1) return 1 + find(curr->left);     return 1 + max(find(curr->left), find(curr->right));   }   int main() {     int n;     cin >> n;     Node* root = NULL;     for (int i = 0; i < n; ++i) {       cin >> A[i];       insert(root, 31, i);     }     cout << n - find(root);     delete root;     return 0;   }
#include <bits/stdc++.h>   struct IO {     static const int L = 1000000;     char a[L], b[L], *s, *t, *p, c;     IO() : p(b) {}     ~IO() { fwrite(b, 1, p - b, stdout); }     char gc() {       if (s == t) t = (s = a) + fread(a, 1, L, stdin);       return *s++;     }     void gs(char* st) {       for (c = gc(); !isgraph(c); c = gc())         ;       *st++ = c;       for (c = gc(); isgraph(c); c = gc()) *st++ = c;       *st++ = 0;     }     template <class T>     operator T() {       static T x;       static bool neg;       for (c = gc(); c !=  -  && !isdigit(c); c = gc())         ;       if ((neg = c ==  - )) c = gc();       x = c -  0 ;       for (c = gc(); isdigit(c); c = gc()) x = x * 10 + (c -  0 );       return neg ? -x : x;     }     void pc(const char ch) {       if (p == b + L) fwrite(p = b, 1, L, stdout);       *p++ = ch;     }     template <class T>     void print(T x, const char end =   n ) {       static char cs[30], *q;       static T y;       if (x == 0)         pc( 0 );       else {         if (x < 0) pc( - ), x = -x;         for (q = cs; x; x = y) y = x / 10, *q++ = x - y * 10 +  0 ;         while (q != cs) pc(*--q);       }       if (end) pc(end);     }     void ps(const char* st, const char end =   n ) {       while (*st) pc(*st++);       if (end) pc(end);     }   } io;   int main() {     static int i, n;     static char a[200], r[3];     io.gs(a + 1);     n = strlen(a + 1);     for ((i) = (2); (i) < (n); ++(i)) {       r[0] = a[i - 1];       r[1] = a[i];       r[2] = a[i + 1];       std::sort(r, r + 3);       if (r[0] ==  A  && r[1] ==  B  && r[2] ==  C ) {         io.ps( Yes );         return 0;       }     }     io.ps( No );     return 0;   }
#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int MAXN = 1e6 + 5;   template <typename _T>   void read(_T &x) {     x = 0;     char s = getchar();     int f = 1;     while (s <  0  ||  9  < s) {       f = 1;       if (s ==  - ) f = -1;       s = getchar();     }     while ( 0  <= s && s <=  9 ) {       x = (x << 3) + (x << 1) + s -  0 , s = getchar();     }     x *= f;   }   template <typename _T>   void write(_T x) {     if (x < 0) {       putchar( - ), x = -x;     }     if (9 < x) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   int g[MAXN], f[MAXN], slink[MAXN], dif[MAXN];   int ch[MAXN][26], fa[MAXN], len[MAXN];   char Snat[MAXN], S[MAXN];   int N, lst, siz;   int main() {     scanf( %s , Snat + 1);     N = strlen(Snat + 1);     for (int i = 1; i <= N >> 1; i++) S[(i << 1) - 1] = Snat[i];     for (int i = (N >> 1) + 1; i <= N; i++) S[(N - i + 1) << 1] = Snat[i];     int x, p, cur;     f[0] = 1;     fa[0] = ++siz, len[1] = -1;     for (int i = 1; i <= N; i++) {       x = S[i] -  a ;       while (S[i] ^ S[i - len[lst] - 1]) lst = fa[lst];       if (!ch[lst][x]) {         cur = ++siz, p = fa[lst];         len[cur] = len[lst] + 2;         while (S[i] ^ S[i - len[p] - 1]) p = fa[p];         fa[cur] = ch[p][x], ch[lst][x] = cur;         dif[cur] = len[cur] - len[fa[cur]],         slink[cur] = (dif[cur] == dif[fa[cur]]) ? slink[fa[cur]] : fa[cur];       }       lst = ch[lst][x];       for (p = lst; p; p = slink[p]) {         g[p] = f[i - len[slink[p]] - dif[p]];         if (slink[p] ^ fa[p]) g[p] = (g[p] + g[fa[p]]) % mod;         if (!(i & 1)) f[i] = (f[i] + g[p]) % mod;       }     }     write(f[N]), putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans[1000001];   int main() {     int n;     cin >> n;     string s;     cin >> s;     int rr = 0, num = 0;     long long v = 1, v2 = 1;     for (int i = 0; i < n; i++) {       num++;       v -= i;       while (rr < n && num > 0) {         if (s[rr] ==  D ) {           v += 2 * rr;           num--;         }         rr++;       }       if (num) break;       ans[i] = v;       v -= i;     }     for (int i = 0; i < n; i++) {       if (s[i] ==  U )         s[i] =  D ;       else         s[i] =  U ;     }     rr = 0;     num = 0;     v = 1;     v2 = 1;     for (int i = 0; i < n; i++) {       num++;       v -= i;       while (rr < n && num > 0) {         if (s[s.size() - rr - 1] ==  D ) {           v += 2 * rr;           num--;         }         rr++;       }       if (num) break;       ans[n - 1 - i] = v;       v -= i;     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 1e3;   string s, sq;   int z1[maxn + 10], z2[maxn + 10], pref[1010], suff[1010], rez;   void calc(string ss, int z[]) {     int l = -1;     int r = -1;     for (int i = 1; i < ss.size(); i++) {       if (i > r) {         l = i;         r = l - 1;         while (r + 1 < ss.size() && ss[r + 1] == ss[r + 1 - l]) r++;         z[i] = r - l + 1;       } else {         if (i + z[i - l] - 1 < r)           z[i] = z[i - l];         else {           l = i;           while (r + 1 < ss.size() && ss[r + 1] == ss[r + 1 - l]) r++;           z[i] = r - l + 1;         }       }     }   }   int main() {     cin >> s;     int q;     scanf( %d , &q);     for (int qi = 1; qi <= q; qi++) {       cin >> sq;       if (sq.size() == 1) continue;       string pom = sq +  $  + s;       calc(pom, z1);       reverse(s.begin(), s.end());       reverse(sq.begin(), sq.end());       pom = sq +  $  + s;       calc(pom, z2);       reverse(s.begin(), s.end());       for (int i = 0; i < s.size(); i++) z1[i] = z1[i + sq.size() + 1];       for (int i = 0; i < pom.size() / 2; i++)         swap(z2[i], z2[pom.size() - 1 - i]);       fill(pref, pref + 1001, 1000000000);       fill(suff, suff + 1001, -1);       int e = 0;       for (int i = 0; i < s.size(); i++) {         int id = z1[i];         if (id == sq.size()) {           rez++;           e = 1;           break;         }         if (pref[id] == 1000000000) pref[id] = i;         id = z2[i];         if (id == sq.size()) {           rez++;           e = 1;           break;         }         suff[id] = i;       }       for (int i = sq.size() - 1; i >= 1; i--) {         pref[i] = min(pref[i], pref[i + 1]);         suff[i] = max(suff[i], suff[i + 1]);       }       if (e == 1) continue;       for (int i = 1; i < sq.size(); i++) {         if (pref[i] == -1 || suff[sq.size() - i] == -1) continue;         if (pref[i] + i - 1 < suff[sq.size() - i] - (sq.size() - i) + 1) {           rez++;           break;         }       }     }     printf( %d n , rez);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 10;   const int maxE = 2000000 + 10;   const int DEBUG = 0;   int n, m;   bitset<maxn> val[maxn];   char S[maxn];   struct anode {     int u, v, w;     anode() {}     anode(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {}   } a[maxE];   int h[maxn], ecnt, sfa[maxn];   struct enode {     int v, n;     enode() {}     enode(int _v, int _n) : v(_v), n(_n) {}   } e[maxE << 1];   inline void addedge(int u, int v) {     ecnt++;     e[ecnt] = enode(v, h[u]);     h[u] = ecnt;   }   int findfa(int u) { return (sfa[u] == u) ? (u) : (sfa[u] = findfa(sfa[u])); }   inline bool cmp(anode a, anode b) { return a.w > b.w; }   int flag, vis[maxn][maxn], all;   void dfs(int u, int fa, int k) {     if (vis[k][u]) all++;     vis[k][u] = 0;     for (int i = h[u]; ~i; i = e[i].n) {       int v = e[i].v;       if (v == fa) continue;       if (!vis[k][v]) continue;       dfs(v, u, k);     }   }   void dfs_ans(int u, int fa) {     for (int i = h[u]; ~i; i = e[i].n) {       int v = e[i].v;       if (v == fa) continue;       printf( %d %d n , u, v);       dfs_ans(v, u);     }   }   inline void solve() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) val[i].reset();     for (int i = 1; i <= m; i++) {       scanf( %s , S + 1);       int cnt = 0;       for (int j = 1; j <= n; j++)         if (S[j] ==  1 ) cnt++;       for (int j = 1; j <= n; j++) vis[i][j] = 0;       if (cnt <= 1) continue;       for (int j = 1; j <= n; j++)         if (S[j] ==  1 ) {           val[j][i] = 1;           vis[i][j] = 1;         }     }     int tot = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int w = (val[i] & val[j]).count();         a[++tot] = anode(i, j, w);       }     }     sort(a + 1, a + tot + 1, cmp);     for (int i = 1; i <= n; i++) sfa[i] = i, h[i] = -1;     ecnt = 0;     for (int i = 1; i <= tot; i++) {       int u = a[i].u, v = a[i].v;       int f1 = findfa(u), f2 = findfa(v);       if (f1 == f2) continue;       if (DEBUG) printf( %d %d %d n , u, v, a[i].w);       addedge(u, v);       addedge(v, u);       sfa[f1] = f2;     }     flag = 1;     for (int i = 1; i <= m; i++) {       all = 0;       int now = 0;       for (int j = 1; j <= n; j++)         if (vis[i][j]) now++;       for (int j = 1; j <= n; j++)         if (vis[i][j]) {           dfs(j, 0, i);           break;         }       if (now != all) flag = 0;     }     if (flag) {       puts( YES );       dfs_ans(1, 0);       return;     }     puts( NO );   }   int main() {     int cas;     scanf( %d , &cas);     while (cas--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double probabilitate[150];   double MAX;   int N, i, limita;   double calcul(int N) {     double first = 1.0, second = 0.0;     int i;     for (i = 0; i < limita; ++i) {       second =           first * probabilitate[N + i] + second * (1.0 - probabilitate[N + i]);       first *= 1.0 - probabilitate[N + i];     }     return second;   }   int main() {     scanf( %d , &N);     for (i = 0; i < N; i++) scanf( %lf , &probabilitate[i]);     sort(probabilitate, probabilitate + N);     for (limita = 1; limita <= N; ++limita)       for (i = 0; i <= N - limita; ++i) MAX = max(MAX, calcul(i));     printf( %.15lf n , MAX);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 100;   string s;   int f(int id) {     string t;     for (int j = id; j < s.size(); j++) {       t.push_back(s[j]);     }     t.push_back( # );     for (int j = 0; j < id; j++) {       t.push_back(s[j]);     }     int mx = 0;     vector<int> z(t.size() + 1);     for (int i = 1, l = 0, r = 0; i < t.size(); i++) {       if (i <= r) {         z[i] = min(r - i + 1, z[i - l]);       }       while (i + z[i] < t.size() && t[z[i]] == t[i + z[i]]) {         z[i]++;       }       if (i + z[i] - 1 > r) {         l = i, r = i + z[i] - 1;       }     }     for (int i = t.find( # ) + 1; i < t.size(); i++) {       mx = max(mx, z[i]);     }     return mx;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, a, b;     cin >> n >> a >> b >> s;     vector<int> maxLen(n);     for (int i = 1; i < n; i++) {       maxLen[i] = f(i);     }     vector<int> dp(n);     dp[0] = a;     for (int i = 1; i < n; i++) {       dp[i] = dp[i - 1] + a;       int min = 1e9;       for (int j = 1; j <= i; j++) {         int len = maxLen[j];         if (i <= j + len - 1 && dp[i] > dp[j - 1] + b) {           dp[i] = dp[j - 1] + b;         }       }     }     cout << dp.back();     return 0;   }