inlineboolcheck(int l, int r){ for (int i = 0; i < 26; ++ i) if (cnt[r][i] - cnt[l - 1][i] != standard[i]) returnfalse; returntrue; }
intmain(){ scanf("%s", s); n = strlen(s); for (int i = 0; i < n; ++ i) ++ cnt[i + 1][s[i] - 'a']; for (int i = 1; i <= n; ++ i) for (int j = 0; j < 26; ++ j) cnt[i][j] += cnt[i - 1][j]; for (int l = 1; l <= n >> 1; ++ l) if (!(n % l)) { int is_answer = true; for (int i = 0; i < 26; ++ i) standard[i] = cnt[l][i]; for (int i = l + 1; i <= n; i += l) if (!check(i, i + l - 1)) { is_answer = false; break; } if (is_answer) { for (int i = 0; i < l; ++ i) putchar(s[i]); return0; } } puts("-1"); return0; }
constint N = 100010; const ll MOD = 1e9 + 7; constint INF = 0x3fffffff;
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int n, k; ll C[N][55], a[N], ans;
inlinevoidinit_C(int x, int y){ for (int i = 0; i <= x; ++ i) C[i][0] = 1; for (int i = 1; i <= x; ++ i) for (int j = 1; j <= i && j <= y; ++ j) { if (j == i) {C[i][j] = 1; break;} C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD; } }
intmain(){ read(n); read(k); init_C(n, k); for (int i = 1; i <= n; ++ i) read(a[i]); sort(a + 1, a + n + 1); for (int i = k; i <= n; ++ i) (ans += C[i - 1][k - 1] * a[i] % MOD) %= MOD; printf("%lld", ans); return0; }
const ll MOD = 1e9; constint N = 2000010; constint INF = 0x3fffffff;
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int n, npr[N][2], cnt; ll f[N][21];
ll gcd(ll x, ll y){return y ? gcd(y, x % y) : x;}
intmain(){ read(n); for (int i = 1; i < n; ++ i) for (int j = i + 1; j <= n; ++ j) if (gcd(i, j) == 1) npr[++ cnt][0] = i, npr[cnt][1] = j; f[0][1] = 1; for (int i = 1; i <= cnt; ++ i) for (int j = 1; j <= n; ++ j) { f[i][j] = (f[i][j] + f[i - 1][j]) % MOD; if (npr[i][0] <= j) (f[i][max(npr[i][1], j)] += f[i - 1][j]) %= MOD; } printf("%lld", f[cnt][n]); return0; }
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int dfn[N], endp[N], ch[N][30], cnt = 1; int hash_val1[N], hash_val2[N], T;
vector <pii > h[N]; /*the hash values of each string belong the node.*/ vector <pair <pii, int> > v; /*the list of all hash values with dfn.*/
/*Insert a new string, and add the hash values of the suffixes to the list of corresponding node.*/ voidinsert(char *s){ int len = strlen(s), p = 1; hash_val1[len] = hash_val2[len] = 0; /*Get the hash value of each suffix.*/ for (int i = len - 1; ~i; -- i) hash_val1[i] = (1ll * hash_val1[i + 1] * BAS1 % MOD1 + s[i] - 96) % MOD1, hash_val2[i] = (1ll * hash_val2[i + 1] * BAS2 % MOD2 + s[i] - 96) % MOD2; h[p].push_back(mkp(hash_val1[0], hash_val2[0])); /*Insert string and add the hash values.*/ for (int i = 0; i < len; ++ i) { int k = s[i] - 96; if (!ch[p][k]) {ch[p][k] = ++ cnt;} p = ch[p][k]; h[p].push_back(mkp(hash_val1[i + 1], hash_val2[i + 1])); } }
/*Get the dfn of each node, and add the hash values with dfn to the list at the same time.*/ voiddfs(int x){ dfn[x] = ++ T; for (auto i : h[x]) v.push_back(mkp(mkp(i.first, i.second), T)); for (int i = 1; i <= 26; ++ i) if (ch[x][i]) dfs(ch[x][i]); endp[x] = T; }
int n, m; char a[N];
intmain(){ read(n); read(m); for (int i = 1; i <= n; ++ i) scanf("%s", a), insert(a); dfs(1); sort(v.begin(), v.end()); while (m --) { scanf("%s", a); int l = strlen(a), p = 1, q = 0; /*Get into the end node of T1.*/ while (q < l && a[q] != '*') p = ch[p][a[q] - 96], ++ q; /*Get the hash value of T_2.*/ int hv1 = 0, hv2 = 0; for (int i = l - 1; i > q; -- i) hv1 = (1ll * hv1 * BAS1 % MOD1 + a[i] - 96) % MOD1, hv2 = (1ll * hv2 * BAS2 % MOD2 + a[i] - 96) % MOD2; printf("%d\n", ub(mkp(mkp(hv1, hv2), endp[p])) - lb(mkp(mkp(hv1, hv2), dfn[p]))); } return0; }