#include<iostream> #include<cstring> #include<algorithm> #define maxn 10000010 #define INF 100000000000000000ll #define ll long long usingnamespacestd;
int n, a, b;
char s[maxn];
int nxt[maxn]; voidinit_nxt(char *s, int n){ int k = 0; nxt[1] = 0; for (int i = 2; i <= n; ++i) { while (k && s[i] != s[k + 1]) k = nxt[k]; if (s[i] == s[k + 1]) ++k; nxt[i] = k; } }
cin >> a >> b >> s + 1; n = strlen(s + 1); reverse(s + 1, s + n + 1); while (s[n] != '.') --n; s[n--] = 0; init_nxt(s, n); ll ans = -INF; for (int i = 1; i <= n; ++i) ans = max(ans, 1ll * a * i - 1ll * b * (i - nxt[i])); cout << ans << "\n"; return0; }