// shiran#include<bits/stdc++.h>usingnamespace std;#definerep(i, a, n)for(int i = a; i < n; i++)#defineper(i, n, a)for(int i = n -1; i >= a; i--)#definesz(x)(int)size(x)#definefifirst#definesesecond#defineall(x) x.begin(), x.end()#definepbpush_backtypedeflonglong ll;typedef pair<int,int> PII;constint mod =998244353;constint N =300010, M =300010;int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};intmain(){
ios::sync_with_stdio(0);
cin.tie(0);int T;// T = 1;
cin>>T;while(T--){
string s;
cin >> s;int n =sz(s), res =0, res2 =0;for(auto& c : s)
res += c -'a'+1;if(n %2==0){printf("Alice %d\n", res);}else{int l = s[0]-'a'+1, r = s[n -1]-'a'+1;
res2 =min(l, r);
res -= res2;if(res2 > res)printf("Bob %d\n", res2 - res);elseprintf("Alice %d\n", res - res2);}}return0;}
B. A Perfectly Balanced String?
// shiran#include<bits/stdc++.h>usingnamespace std;#definerep(i, a, n)for(int i = a; i < n; i++)#defineper(i, n, a)for(int i = n -1; i >= a; i--)#definesz(x)(int)size(x)#definefifirst#definesesecond#defineall(x) x.begin(), x.end()#definepbpush_backtypedeflonglong ll;typedef pair<int,int> PII;constint mod =998244353;constint N =300010, M =300010;int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};intmain(){
ios::sync_with_stdio(0);
cin.tie(0);int T;// T = 1;
cin>>T;while(T--){
string s;
cin >> s;int n =sz(s), res =0;
set<char> S;for(auto& c : s)
S.insert(c);
map<char,int> mp;bool flag =true;rep(i,0, n){if(!mp.count(s[i])){
mp[s[i]]= i;}else{if(i - mp[s[i]]< S.size()){
flag =false;break;}
mp[s[i]]= i;}}if(flag)puts("Yes");elseputs("No");}return0;}
C. Palindrome Basis
// shiran#include<bits/stdc++.h>usingnamespace std;#definerep(i, a, n)for(int i = a; i < n; i++)#defineper(i, n, a)for(int i = n -1; i >= a; i--)#definesz(x)(int)size(x)#definefifirst#definesesecond#defineall(x) x.begin(), x.end()#definepbpush_backtypedeflonglong ll;typedef pair<int,int> PII;constint mod =1e9+7;constint N =40010, M =300010;int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};int a[N];voidinit(){memset(a,0,sizeof a);
a[0]=1;rep(i,1, N){ string s =to_string(i);
string rs = s;reverse(all(rs));if(s != rs)continue;rep(j, i, N){
a[j]=((ll)a[j]+ a[j - i])% mod;}}}intmain(){
ios::sync_with_stdio(0);
cin.tie(0);int T;// T = 1;
cin>>T;init();while(T--){int n;
cin >> n;
cout << a[n]<< endl;}return0;}
D. Lost Arithmetic Progression
// shiran#include<bits/stdc++.h>usingnamespace std;#definerep(i, a, n)for(int i = a; i < n; i++)#defineper(i, n, a)for(int i = n -1; i >= a; i--)#definesz(x)(int)size(x)#definefifirst#definesesecond#defineall(x) x.begin(), x.end()#definepbpush_back#definemkmake_mairtypedeflonglong ll;typedef pair<int,int> PII;constint mod =1e9+7;constint N =200010, M =300010;int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};
ll stb, stc, db, dc, nb, nc;voidsolve(){
cin >> stb >> db >> nb;
cin >> stc >> dc >> nc;
ll edb = stb +(nb -1)* db;
ll edc = stc +(nc -1)* dc;if(edc > edb || stc < stb || dc % db ||(stc - stb)% db){
cout <<0<< endl;return;}if(stc - dc < stb || edc + dc > edb){
cout <<-1<< endl;return;}
set<ll> S;
ll ans =0;for(int i =1; i * i <= dc; i ++){if(dc % i ==0){
S.insert(i);
S.insert(dc / i);}}for(auto& da : S){if(da * db /gcd(da, db)!= dc)continue;
ans =(ans +(dc / da)*(dc / da)% mod)% mod;}
cout << ans << endl;}intmain(){
ios::sync_with_stdio(0);
cin.tie(0);int T;
cin>>T;while(T --){solve();}return0;}