Problem:
I: Palindrome Compliment
問題文
小池くんはチームメイトをよく褒めます。
彼はチームメイトである松崎くんを文字列 $S$ で褒めます。その形式は以下の条件を満たします。
$Hoge, Zaki, O$ は小文字アルファベットのみからなる文字列
$S = Hoge + Zaki + Hoge + O$ ($+$ は文字列の結合を表す)
$S$ は回文
小池くんは$Hoge$の長さを$N$としたときに、松崎くんの褒め方が何通りあるのか気になりました。
3人目のチームメンバーにしてred coderであるあなたは小池くんの代わりに答えを計算することになりました。
文字列 $Zaki, O$ と 整数 $N$ が与えられるので、ありえる組み合わせの数を求めてください．
なお、答えは非常に大きくなる可能性があるので、$10^9 + 7$ で割った 余りを出力してください。
制約
$Zaki$ と $O$ は小文字アルファベットからなる文字列
$1 \leq |Zaki| \leq 10^5$
$1 \leq |O| \leq 10^5$
$1 \leq  N  \leq 10^9$
入力
入力は以下の形式で標準入力から与えられます。
$Zaki$
$O$
$N$
出力
答えを1行に出力してください。
入出力例
入力例1
zaki
o
4
出力例1
0
入力例2
aab
aa
3
出力例2
26
入力例3
aaa
aaaa
3
出力例3
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

constexpr int mod = 1e9 + 7;

ll modpow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    string z, o;
    ll n;
    cin >> z >> o >> n;

    const int z_len = z.size(), o_len = o.size();
    const ll tot = n * 2 + z.size() + o.size();
    const int o_start = n * 2 + z.size();
    const int z_start = n;

    bool ng = false;
    map<int, char> ch;
    for(ll i = z_start; i < z_start + z_len; ++i) { // check on zaki
        const ll cor = tot - i - 1;
        const char c = z[i - z_start];
        if(cor < n) { // on H
            if(ch.count(cor) == 1) {
                if(ch[cor] != c) {
                    ng = true;
                }
                ch[cor] = c;
            } else {
                ch[cor] = c;
            }
        } else if(cor < n + z_len) { // on Z
            if(c != z[cor - n]) {
                ng = true;
            }
        } else if(cor < n + z_len + n) { // on H
            const ll idx = cor - (n + z_len);
            if(ch.count(idx) == 1) {
                if(ch[idx] != c) {
                    ng = true;
                }
                ch[idx] = c;
            } else {
                ch[idx] = c;
            }
        } else { // on O
            if(z[i - z_start] != o[cor - (n + z_len + n)]) {
                ng = true;
            }
        }
    }
    for(ll i = o_start; i < tot; ++i) { // check on O
        const ll cor = tot - i - 1;
        const char c = o[i - o_start];
        if(cor < n) { // on H
            if(ch.count(cor) == 1) {
                if(ch[cor] != c) {
                    ng = true;
                }
                ch[cor] = c;
            } else {
                ch[cor] = c;
            }
        } else if(cor < n + z_len) { // on Z
            if(o[i - o_start] != z[cor - n]) {
                ng = true;
            }
        } else if(cor < n + z_len + n) { // on H
            const ll idx = cor - (n + z_len);
            if(ch.count(idx) == 1) {
                if(ch[idx] != c) {
                    ng = true;
                }
                ch[idx] = c;
            } else {
                ch[idx] = c;
            }
        } else { // on O
            if(o[i - o_start] != o[cor - (n + z_len + n)]) {
                ng = true;
            }
        }
    }

    if(ng) {
        cout << 0 << endl;
        return 0;
    }

    // calc overlap H
    const ll len = n - o.size();
    cout << modpow(26, n - ch.size() - max(0LL, len / 2)) << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 8268
final_rank: 4

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// #ifndef ONLINE_JUDGE
// #define _GLIBCXX_DEBUG // 配列外参照のエラー
// #endif

// スタンダードライブラリ
#include <bits/stdc++.h>
using namespace std;

// 型関連
using ll = long long;
using lint = long long;
using pll = pair<ll, ll>;
using plll = tuple<ll, ll, ll>;
using pii = pair<int, int>;
using piii = tuple<ll, ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vvvvl = vector<vector<vector<vector<ll>>>>;

template <class T> using prique = priority_queue<T>;
template<class T> void chmin(T& a, T b){ if(a > b) a = b; }
template<class T> void chmax(T& a, T b){ if(a < b) a = b; }


#define all(v) v.begin(), v.end()

// 型定数
constexpr ll mod = 998244353;
constexpr ll MOD = 1000000007;
int INF32 = 2e9;
ll INF64 = 9e18;
#define endl '\n';

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

/////////////////////////// print関連
template <typename T> void print(vector<T> A);
void print();
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail);
void print(string S);
template <typename T> void print(vector<vector<T>> &F);

inline void Yes(bool f);


///////////////////ここから//////////////////////
struct UnionFind {
  public:
    UnionFind(int n) : par(n, -1), rank(n, 0), siz(n, 1) {}

    int root(int a) {
        if(par[a] == -1) return a;
        else return par[a] = root(par[a]);
    }

    bool same(int a, int b) {
        return root(a) == root(b);
    }

    bool unite(int a, int b) {
        int ra = root(a), rb = root(b);
        if(ra == rb) return false;
        if(rank[ra] < rank[rb]) swap(ra, rb);
        par[rb] = ra;
        if(rank[ra] == rank[rb]) rank[ra]++;
        siz[ra] += siz[rb];
        return true;
    }

    int size(int a) {
        return siz[root(a)];
    }

  private:
    vector<int> par, rank, siz;
};

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    string Z, O;
    int N;
    cin >> Z >> O >> N;
    string H0(N,'.');

    string S = H0 + Z + H0 + O;

    int n = S.size();

    UnionFind unf(n);
    for (int i = 0; i < N; i++) {
        unf.unite(i,i+N+Z.size());
    }
    for (int i = 0; i < n; i++) {
        unf.unite(i,n-1-i);
    }
    map<int, vi> root_has;
    for (int i = 0; i < n; i++) {
        int r = unf.root(i);
        if (root_has.count(r) == 0) {
            root_has[r]=vector<int>(0);
        }
        root_has[r].push_back(i);
    }

    ll ans=1;
    for (auto [key, V] : root_has) {
        unordered_set<char> C;
        for (auto v : V) {
            if (S[v] != '.')
                C.insert(S[v]);
        }
        if (C.size() > 1)
            ans *= 0;
        if (C.size() == 0) {
            ans *= 26;
            ans%=MOD;
        }
    }
    print(ans);


    
}

////////////////////print/////////////////////////
// 1次元ベクトルを出力する
template <typename T> void print(vector<T> A) {
    if (A.size() == 0) {
        return;
    }
    for (size_t i = 0; i < A.size() - 1; i++) {
        cout << A[i] << ' ';
    }
    cout << A[A.size() - 1] << endl;
    return;
}

// 2次元ベクトルを出力する
template <typename T> void print(vector<vector<T>> &F) {
    for (size_t i = 0; i < F.size(); i++) {
        for (size_t j = 0; j < F[i].size(); j++) {
            cout << F[i][j];
            if (j < F[i].size() - 1) {
                cout << ' ';
            }
        }
        cout << endl;
    }
}

// 空白行を出力するprint
void print() { cout << endl; }

// 数値・文字列を空白区切りで出力する. print(a,b)など
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

void print(string S) { cout << S << endl; }

//////////////出力関連

inline void Yes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
accuracy: 0.2857142857142857
time_ms: 60
memory_kb: 19712
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

string Z,O,T;
ll N,ZN,L;
vector<ll> f(ll n){
    if(n<N)return{n,n+N+ZN,L-n-1,L-n-1-N-ZN};
    else return{n,n-N-ZN,L-n-1,L-n-1+N+ZN};
}
vector<ll> g(ll n){return{n,L-n-1};}

int main() {
    
    cin>>Z>>O>>N;
    ZN=Z.size(),L=2*N+ZN+O.size();

    unordered_map<ll,char> M;
    for(int k=0;k<2;k++){
        T=(k?O:Z);
        for(int i=0;i<T.size();i++){
            ll n=i+N+k*(N+ZN),m=L-1-n;
            for(auto j:((m<N)||(N+ZN<=m&&m<N*2+ZN)?f(m):g(m))){
                if(!M.count(j))M[j]=T[i];
                if(M[j]!=T[i]){
                    cout<<0<<endl;
                    return 0;
                }
            }
        }
    }
    ll p=(L-M.size()+2)/4,an=1,b=26,mod=1e9+7;
    while(p>0){
        if(p%2)an=(an*b)%mod;
        b=(b*b)%mod;
        p/=2;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 19416
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

string Z,O,T;
ll N,ZN,L;
vector<ll> f(ll n){
    if(n<N)return{n,n+N+ZN,L-n-1,L-n-1-N-ZN};
    else return{n,n-N-ZN,L-n-1,L-n-1+N+ZN};
}
vector<ll> g(ll n){return{n,L-n-1};}

int main() {
    
    cin>>Z>>O>>N;
    ZN=Z.size(),L=2*N+ZN+O.size();

    map<ll,char> M;
    for(int k=0;k<2;k++){
        T=(k?O:Z);
        for(int i=0;i<T.size();i++){
            ll n=i+N+k*(N+ZN),m=L-1-n;
            for(auto j:((m<N)||(N+ZN<=m&&m<N*2+ZN)?f(m):g(m))){
                if(!M.count(j))M[j]=T[i];
                if(M[j]!=T[i]){
                    cout<<0<<endl;
                    return 0;
                }
            }
        }
    }
    ll p=(L-M.size()+2)/4,an=1,b=26,mod=1e9+7;
    while(p>0){
        if(p%2)an=(an*b)%mod;
        b=(b*b)%mod;
        p/=2;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 290
memory_kb: 28660
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

string Z,O;
ll N,ZN,ON,L;
vector<ll> f(ll n){
    if(n<N)return{n,n+N+ZN,L-n-1,L-n-1-N-ZN};
    else return{n,n-N-ZN,L-n-1,L-n-1+N+ZN};
}
vector<ll> g(ll n){return{n,L-n-1};}

int main() {
    
    cin>>Z>>O>>N;
    ZN=Z.size(),ON=O.size(),L=2*N+ZN+ON;

    map<ll,char> M;
    for(int k=0;k<2;k++){
        string T=(k?O:Z);
        for(int i=0;i<T.size();i++){
            ll n=i+N+k*(N+ZN),m=L-1-n;
            for(auto j:((m<N)||(N+ZN<=m&&m<N*2+ZN)?f(m):g(m))){
                if(!M.count(j))M[j]=T[i];
                if(M[j]!=T[i]){
                    cout<<0<<endl;
                    return 0;
                }
            }
        }
    }
    ll p=(L-M.size()+2)/4,an=1,b=26,mod=1e9+7;
    while(p>0){
        if(p%2)an=(an*b)%mod;
        b=(b*b)%mod;
        p/=2;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 290
memory_kb: 28752
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

string Z,O;
ll N,ZN,ON,L;
vector<ll> f(ll n){
    if(n<N)return{n,n+N+ZN,L-n-1,L-n-1-N-ZN};
    else return{n,n-N-ZN,L-n-1,L-n-1+N+ZN};
}
bool ch(ll n){return (n<N)||(N+ZN<=n&&n<N*2+ZN);}

bool add(map<ll,char> &M,ll n,ll c){
    if(!M.count(n))M[n]=c;
    return M[n]==c;
}

int main() {
    
    cin>>Z>>O>>N;
    ZN=Z.size(),ON=O.size(),L=2*N+ZN+ON;

    map<ll,char> M;
    for(int i=0;i<ZN;i++)M[i+N]=Z[i];
    for(int i=0;i<ON;i++)M[i+N*2+ZN]=O[i];
    for(int k=0;k<2;k++){
        string T=(k?O:Z);
        for(int i=0;i<T.size();i++){
            ll n=i+N+k*(N+ZN),m=L-1-n;
            if(ch(m))for(auto j:f(m)){
                if(ch(j)&&!add(M,j,T[i])){
                    cout<<0<<endl;
                    return 0;
                }
            }
            else if(M[m]!=T[i]){
                cout<<0<<endl;
                return 0;
            }
        }
    }

    ll p=(L-M.size()+2)/4,an=1,b=26,mod=1e9+7;
    while(p>0){
        if(p%2)an=(an*b)%mod;
        b=(b*b)%mod;
        p/=2;
    }

    cout<<an<<endl;
}
accuracy: 1
time_ms: 160
memory_kb: 28684
final_rank: 8

code_snippet: #include <iostream>
#include <set>
#include <map>
using namespace std;
const long long MOD = 1000000007;


long long uPow(long long r,long long x){//r^x
  long long nw = r;
  long long ret = 1;
  while(x){
    if(x%2){
      ret = (ret * nw)%MOD;
    }
    nw = (nw*nw)%MOD;
    x/=2;
  }
  return ret;

}

int main(){
  string s,o;
  map<int,char> X;
  set<int> Z;
  long long n;cin>>s>>o>>n;
  for(int i = 0; o.size() > i; i++){
    if(s.size()+2*n <= i){
      if(o[i-(s.size()+2*n)] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
    }else if(s.size()+n <= i){
      if(Z.count(i-(s.size()+n)) && X[i-(s.size()+n)] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "?" << i-(s.size()+n) << " " << o[o.size()-i-1] << endl;
      X[i-(s.size()+n)] = o[o.size()-i-1];
      Z.insert(i-(s.size()+n));
    }else if(n <= i){
      if(s[i-n] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
    }else{
      if(Z.count(i) && X[i] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "!" << i << " " << o[o.size()-i-1] << endl;
      X[i] = o[o.size()-i-1];
      Z.insert(i);
    }
  }
  long long len = 2*n+s.size()+o.size();
  long long ce = len/2;
  for(int i = 0; s.size() > i; i++){

    long long x = 2*ce-(n+i);
    //cout << x << endl;
    //cout << ce << " " << n << " " << i << endl;
    //cout << i << " " << x << endl;
    if(len%2 == 0){
      x--;
    }
    if(2*n+s.size() <= x){
      //cout << i << " " << x-(2*n+s.size()) << " " << x << endl;
      if(s[i] != o[x-(2*n+s.size())]){
        cout << 0 << endl;
        return 0;
      }
    }else if(n+s.size() <= x){
      if(Z.count(x-(s.size()+n)) && X[x-(s.size()+n)] != s[i]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "!!" << x-(int)(s.size()+n) << " " << s[i] << endl;
      X[x-(s.size()+n)] = s[i];
      Z.insert(x-(s.size()+n));
    }else{
      if(s[i] != s[x-n]){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << uPow(26,(n-Z.size())) << endl;
}
accuracy: 0.2619047619047619
time_ms: 40
memory_kb: 12352
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

int power(int x, int n){
  int ans = 1;
  
  while(n > 0){
    if(n&1) ans *= x;
    x *= x;
    x %= MOD;
    ans %= MOD;
    n >>= 1;
  }
  
  return ans;
}

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + (int)zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+(int)zaki.size(), len - (N*2+(int)zaki.size()+(int)i) - 1ll);
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int ans = 1;
  
  if(N+zaki.size() < (len+1)/2 && (len+1)/2 <= N*2+(int)zaki.size()-1) {
    int y = max(N+(int)zaki.size(), len - (N*2+(int)zaki.size()-1) - 1ll);
    int lena = (len+1)/2 - y, lenb = lena * 2 - len%2;
    
    // set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first;
      // if(i < lenb) {
        // z.insert(min(i, lenb-i-1));
      // }
      
      if(i < lena) {
        if(mp.count(i) && mp.count(lenb-i-1)) {
          if(mp[i] != mp[lenb-i-1]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(lenb-i-1)) {
          if(mp[i] != mp[lenb-i-1]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    // for(int i = 0; i < lena - z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
  }
  
  // if((len+1)/2 <= N*2+zaki.size()-1 && len - (N*2+zaki.size()-1) - 1 < N) {
  if((len)/2 <= N*2+(int)zaki.size()-1 && len - (N*2+(int)zaki.size()-1) - 1 < N) {
    int a = len - (N*2+(int)zaki.size()-1) - 1, b = N-1;
    int lenb = b - a + 1, lena = (lenb+1)/2;
    
    vector<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first-a;
      if(0 <= i && i < lenb) {
        z.push_back(min(i, lenb-i-1));
      }
      if(i < lena) {
        if(mp.count(i) && mp.count(lenb-i-1)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(lenb-i-1)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    
    // for(int i = 0; i < lena - (int)z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
    ans *= power(26, lena - (int)z.size());
    ans %= MOD;
  }
  for(const pair<int, char> &&p : mp){
    {
      int i = p.first;
      if(i < N) {
        int j = min(i+N+(int)zaki.size(), len - (N+(int)zaki.size()+i) - 1ll);
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    {
      int i = p.first - N - zaki.size();
      if(0 <= i && i < N+zaki.size()+N) {
        int j = p.first;
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    {
      int i = (len+1)/2 - p.first - 1;
      if(i + o.size() < (len+1)/2) {
        // int j = i + (len+1)/2 - N - zaki.size();
        int j = i + (len)/2- N - zaki.size();
        if(mp.count(p.first) && mp.count(j)) {
          if(mp[p.first] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 16160
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

int power(int x, int n){
  int ans = 1;
  
  while(n > 0){
    if(n&1) ans *= x;
    x *= x;
    x %= MOD;
    ans %= MOD;
    n >>= 1;
  }
  
  return ans;
}

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + (int)zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+(int)zaki.size(), len - (N*2+(int)zaki.size()+(int)i) - 1ll);
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int ans = 1;
  
  if(N+zaki.size() < (len+1)/2 && (len+1)/2 <= N*2+(int)zaki.size()-1) {
    int y = max(N+(int)zaki.size(), len - (N*2+(int)zaki.size()-1) - 1ll);
    int lena = (len+1)/2 - y, lenb = lena * 2 - len%2;
    
    // set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first;
      // if(i < lenb) {
        // z.insert(min(i, lenb-i-1));
      // }
      
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    // for(int i = 0; i < lena - z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
  }
  
  // if((len+1)/2 <= N*2+zaki.size()-1 && len - (N*2+zaki.size()-1) - 1 < N) {
  if((len)/2 <= N*2+(int)zaki.size()-1 && len - (N*2+(int)zaki.size()-1) - 1 < N) {
    int a = len - (N*2+(int)zaki.size()-1) - 1, b = N-1;
    int lenb = b - a + 1, lena = (lenb+1)/2;
    
    vector<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first-a;
      if(0 <= i && i < lenb) {
        z.push_back(min(i, lenb-i-1));
      }
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    
    // for(int i = 0; i < lena - (int)z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
    ans *= power(26, lena - (int)z.size());
    ans %= MOD;
  }
  for(const pair<int, char> &&p : mp){
    {
      int i = p.first;
      if(i < N) {
        int j = min(i+N+(int)zaki.size(), len - (N+(int)zaki.size()+i) - 1ll);
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    {
      int i = p.first - N - zaki.size();
      if(0 <= i && i < N+zaki.size()+N) {
        int j = p.first;
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    {
      int i = (len+1)/2 - p.first - 1;
      if(i + o.size() <= (len+1)/2) {
        // int j = i + (len+1)/2 - N - zaki.size();
        int j = i + (len+1)/2 - 1 - N - zaki.size();
        if(mp.count(p.first) && mp.count(j)) {
          if(mp[p.first] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}
accuracy: 0.2857142857142857
time_ms: 90
memory_kb: 16064
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

int power(int x, int n){
  int ans = 1;
  
  while(n > 0){
    if(n&1) ans *= x;
    x *= x;
    x %= MOD;
    ans %= MOD;
    n >>= 1;
  }
  
  return ans;
}

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + (int)zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+(int)zaki.size(), len - (N*2+(int)zaki.size()+(int)i) - 1ll);
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int ans = 1;
  
  if(N+zaki.size() < (len+1)/2 && (len+1)/2 <= N*2+(int)zaki.size()-1) {
    int y = max(N+(int)zaki.size(), len - (N*2+(int)zaki.size()-1) - 1ll);
    int lena = (len+1)/2 - y, lenb = lena * 2 - len%2;
    
    // set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first;
      // if(i < lenb) {
        // z.insert(min(i, lenb-i-1));
      // }
      
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    // for(int i = 0; i < lena - z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
  }
  
  // if((len+1)/2 <= N*2+zaki.size()-1 && len - (N*2+zaki.size()-1) - 1 < N) {
  if((len)/2 <= N*2+(int)zaki.size()-1 && len - (N*2+(int)zaki.size()-1) - 1 < N) {
    int a = len - (N*2+(int)zaki.size()-1) - 1, b = N-1;
    int lenb = b - a + 1, lena = (lenb+1)/2;
    
    vector<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first-a;
      if(0 <= i && i < lenb) {
        z.push_back(min(i, lenb-i-1));
      }
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    
    // for(int i = 0; i < lena - (int)z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
    ans *= power(26, lena - (int)z.size());
    ans %= MOD;
  }
  for(const pair<int, char> &&p : mp){
    {
      int i = p.first;
      if(i < N) {
        int j = min(i+N+(int)zaki.size(), len - (N+(int)zaki.size()+i) - 1ll);
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    {
      int i = p.first - N - zaki.size();
      if(0 <= i && i < N+zaki.size()+N) {
        int j = p.first;
        if(mp.count(p.first) && mp.count(j)) {
          if(mp[p.first] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    {
      int i = (len+1)/2 - p.first - 1;
      if(i + o.size() <= (len+1)/2) {
        // int j = i + (len+1)/2 - N - zaki.size();
        int j = i + (len+1)/2 - 1 - N - zaki.size();
        if(mp.count(p.first) && mp.count(j)) {
          if(mp[p.first] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}
accuracy: 0.2857142857142857
time_ms: 90
memory_kb: 16156
final_rank: 13

code_snippet: #include <iostream>
#include <set>
#include <map>
using namespace std;
const long long MOD = 1000000007;


long long uPow(long long r,long long x){//r^x
  long long nw = r;
  long long ret = 1;
  while(x){
    if(x%2){
      ret = (ret * nw)%MOD;
    }
    nw = (nw*nw)%MOD;
    x/=2;
  }
  return ret;

}

int main(){
  string s,o;
  map<int,char> X;
  set<int> Z;
  long long n;cin>>s>>o>>n;
  for(int i = 0; o.size() > i; i++){
    if(s.size()+2*n <= i){
      if(o[i-(s.size()+2*n)] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
    }else if(s.size()+n <= i){
      if(Z.count(i-(s.size()+n)) && X[i-(s.size()+n)] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "?" << i-(s.size()+n) << endl;
      X[i-(s.size()+n)] = o[o.size()-i-1];
      Z.insert(i-s.size()-n);
    }else if(n <= i){
      if(s[i-n] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
    }else{
      if(Z.count(i) && X[i] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "!" << i << endl;
      X[i] = o[o.size()-i-1];
      Z.insert(i);
    }
  }
  int len = 2*n+s.size()+o.size();
  int ce = len/2;
  for(int i = 0; s.size() > i; i++){

    int x = 2*ce-(n+i);
    //cout << x << endl;
    //cout << ce << " " << n << " " << i << endl;
    //cout << i << " " << x << endl;
    if(len%2 == 0){
      x--;
    }
    if(2*n+s.size() <= x){
      //cout << i << " " << x-(2*n+s.size()) << " " << x << endl;
      if(s[i] != o[x-(2*n+s.size())]){
        cout << 0 << endl;
        return 0;
      }
    }else if(n+s.size() <= x){
      if(Z.count(x-(s.size()+n)) && X[x-(s.size()+n)] != s[i]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "!!" << x-(int)(s.size()+n) << endl;
      X[x-(s.size()+n)] = s[i];
      Z.insert(x-(s.size()+n));
    }else{
      if(s[i] != s[x-n]){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << uPow(26,(n-Z.size())) << endl;
}
accuracy: 0.2619047619047619
time_ms: 50
memory_kb: 12320
final_rank: 15

code_snippet: #include <iostream>
#include <set>
#include <map>
using namespace std;
const long long MOD = 1000000007;


long long uPow(long long r,long long x){//r^x
  long long nw = r;
  long long ret = 1;
  while(x){
    if(x%2){
      ret = (ret * nw)%MOD;
    }
    nw = (nw*nw)%MOD;
    x/=2;
  }
  return ret;

}

int main(){
  string s,o;
  map<int,char> X;
  set<int> Z;
  long long n;cin>>s>>o>>n;
  for(int i = 0; o.size() > i; i++){
    if(s.size()+2*n <= i){
      if(o[i-(s.size()+2*n)] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
    }else if(s.size()+n <= i){
      if(Z.count(i-(s.size()+n)) && X[i-(s.size()+n)] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "?" << i-(s.size()+n) << endl;
      X[i-(s.size()+n)] = o[o.size()-i-1];
      Z.insert(i-s.size()-n);
    }else if(n <= i){
      if(s[i-n] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
    }else{
      if(Z.count(i) && X[i] != o[o.size()-i-1]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "!" << i << endl;
      X[i] = o[o.size()-i-1];
      Z.insert(i);
    }
  }
  int len = 2*n+s.size()+o.size();
  int ce = len/2;
  for(int i = 0; s.size() > i; i++){

    int x = 2*ce-(n+i);
    //cout << ce << " " << n << " " << i << endl;
    //cout << i << " " << x << endl;
    if(len%2 == 0){
      x++;
    }
    if(2*n+s.size() <= x){
      if(s[i] != o[x-(2*n+s.size())]){
        cout << 0 << endl;
        return 0;
      }
    }else if(n+s.size() <= x){
      if(Z.count(x-(s.size()+n)) && X[x-(s.size()+n)] != s[i]){
        cout << 0 << endl;
        return 0;
      }
      //cout << "!!" << x-(int)(s.size()+n) << endl;
      X[x-(s.size()+n)] = s[i];
      Z.insert(x-(s.size()+n));
    }else{
      if(s[i] != s[x-n]){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << uPow(26,(n-Z.size())) << endl;
}
accuracy: 0.19047619047619047
time_ms: 50
memory_kb: 12292
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+zaki.size(), len - (N*2+zaki.size()+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int ans = 1;
  
  if(N+zaki.size() < (len+1)/2 && (len+1)/2 <= N*2+zaki.size()-1) {
    int y = max(N+zaki.size(), len - (N*2+zaki.size()-1) - 1);
    int lena = (len+1)/2 - y, lenb = lena * 2 - len%2;
    
    set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first;
      if(i < lenb) {
        z.insert(min(i, lenb-i-1));
      }
      
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    // for(int i = 0; i < lena - z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
  }
  
  if((len+1)/2 <= N*2+zaki.size()-1 && len - (N*2+zaki.size()-1) - 1 < N) {
    int a = len - (N*2+zaki.size()-1) - 1, b = N-1;
    int lenb = b - a + 1, lena = (lenb+1)/2;
    
    set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first-a;
      if(0 <= i && i < lenb) {
        z.insert(min(i, lenb-i-1));
      }
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    for(int i = 0; i < lena - (int)z.size(); i++){
      ans *= 26;
      ans %= MOD;
    }
  }
  for(const pair<int, char> &&p : mp){
    {
      int i = p.first;
      if(i < N) {
        int j = min(i+N+zaki.size(), len - (N+zaki.size()+i) - 1);
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    {
      int i = p.first - N - zaki.size();
      if(0 <= i && i < N+zaki.size()+N) {
        int j = p.first;
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    {
      int i = (len+1)/2 - p.first - 1;
      if(i + o.size() <= (len+1)/2) {
        int j = i + (len+1)/2 - N - zaki.size();
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}
accuracy: 0.19047619047619047
time_ms: 90
memory_kb: 16068
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+zaki.size(), len - (N*2+zaki.size()+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int ans = 1;
  
  if(N+zaki.size() < (len+1)/2 && (len+1)/2 <= N*2+zaki.size()-1) {
    int y = max(N+zaki.size(), len - (N*2+zaki.size()-1) - 1);
    int lena = (len+1)/2 - y, lenb = lena * 2 - len%2;
    
    set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first;
      if(i < lenb) {
        z.insert(min(i, lenb-i-1));
      }
      
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    // for(int i = 0; i < lena - z.size(); i++){
      // ans *= 26;
      // ans %= MOD;
    // }
  }
  
  if((len+1)/2 <= N*2+zaki.size()-1 && len - (N*2+zaki.size()-1) - 1 < N) {
    int a = len - (N*2+zaki.size()-1) - 1, b = N-1;
    int lenb = b - a + 1, lena = (lenb+1)/2;
    
    set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first-a;
      if(0 <= i && i < lenb) {
        z.insert(min(i, lenb-i-1));
      }
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    for(int i = 0; i < lena - (int)z.size(); i++){
      ans *= 26;
      ans %= MOD;
    }
  }
  for(const pair<int, char> &&p : mp){
    {
      int i = p.first;
      if(i < N) {
        int j = min(i+N+zaki.size(), len - (N+zaki.size()+i) - 1);
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    {
      int i = p.first - N - zaki.size();
      if(0 <= i && i < N+zaki.size()+N) {
        int j = p.first;
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    {
      int i = (len+1)/2 - p.first + 1;
      if(i + o.size() <= (len+1)/2) {
        int j = i + (len+1)/2 - N - zaki.size();
        if(mp.count(i) && mp.count(j)) {
          if(mp[i] != mp[j]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}
accuracy: 0.19047619047619047
time_ms: 80
memory_kb: 16156
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+zaki.size(), len - (N*2+zaki.size()+i) - 1);
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int ans = 1;
  
  if(N+zaki.size() < (len+1)/2 && (len+1)/2 <= N*2+zaki.size()-1) {
    int y = max(N+zaki.size(), len - (N*2+zaki.size()-1) - 1);
    int lena = (len+1)/2 - y, lenb = lena * 2 - len%2;
    
    set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first;
      if(i < lenb) {
        z.insert(min(i, lenb-i-1));
      }
      
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    
    for(int i = 0; i < lena - z.size(); i++){
      ans *= 26;
      ans %= MOD;
    }
  }
  
  if((len+1)/2 <= N*2+zaki.size()-1 && len - (N*2+zaki.size()-1) - 1 < N) {
    int a = len - (N*2+zaki.size()-1) - 1, b = N-1;
    int lenb = b - a + 1, lena = (lenb+1)/2;
    
    set<int> z;
    
    for(const pair<int, char> &&p : mp){
      int i = p.first-a;
      if(0 <= i && i < lenb) {
        z.insert(min(i, lenb-i-1));
      }
      if(i < lena) {
        if(mp.count(i) && mp.count(lena+i)) {
          if(mp[i] != mp[lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      } else if(lena <= i < lenb) {
        if(mp.count(i) && mp.count(-lena+i)) {
          if(mp[i] != mp[-lena+i]) {
            cout<<0<<endl;
            return 0;
          }
        }
      }
    }
    for(int i = 0; i < lena - (int)z.size(); i++){
      ans *= 26;
      ans %= MOD;
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}
accuracy: 0.14285714285714285
time_ms: 60
memory_kb: 15916
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
constexpr int MOD = 1e9+7;

signed main(){
  map<int, char> mp;
  string zaki, o;
  int N, len;
  
  cin>>zaki>>o>>N;
  
  len = N * 2 + zaki.size() + o.size();
  
  for(int i = 0; i < zaki.size(); i++){
    int ind = min(N+i, len - (N+i) - 1);
    // cout<<"<> "<<ind<<endl;
    if(mp.count(ind) == 0) {
      mp[ind] = zaki[i];
    } else {
      if(mp[ind] != zaki[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  for(int i = 0; i < o.size(); i++){
    int ind = min(i+N*2+zaki.size(), len - (N*2+zaki.size()+i) - 1);
    // cout<<"[] "<<ind<<endl;
    if(mp.count(ind) == 0) {
      mp[ind] = o[i];
    } else {
      if(mp[ind] != o[i]) {
        cout<<0<<endl;
        return 0;
      }
    }
  }
  
  int con = 0;
  vector<int> v;
  
  for(const pair<int, char> &&p : mp){
    int i = p.first;
    // cout<<"i = "<<i<<endl;
    int ind = min(i, len - (i) - 1);
    int ind2 = min(i+N+zaki.size(), len - (i+N+zaki.size()) - 1);
    
    if(mp.count(ind) && mp.count(ind2)) {
      if(mp[ind] != mp[ind2]) {
        cout<<0<<endl;
        return 0;
      }
    } else if(mp.count(ind) || mp.count(ind2)){
      con++;
      // cout<<ind<<" "<<ind2<<endl;
      if(mp.count(ind)) {
        v.push_back(ind2);
      } else if(mp.count(ind2)) {
        v.push_back(ind);
      }
    }
  }
  
  for(int i = 0; i < v.size(); i++){
    mp[v[i]] = '_';
    // cout<<"v = "<<v[i]<<endl;
  }
  
  int l = 0, r = N, m;
  
  while(l+1 < r){
    m = (l+r)/2;
    
    if(m <= min(m+N+zaki.size(), len - (N+zaki.size()+m) - 1)) {
      l = m;
    } else {
      r = m;
    }
  }
  
  int ans = 1;
  
  if(len%2 && mp.count((len+1)/2)) {
    if(mp[(len+1)/2] == '_') ans *= 26;
  }
  
  if(l == len - (N+zaki.size()+l) - 1) {
    // cout<<"l = "<<l<<endl;
    if(mp.count(l) == 0 || mp[l] == '_') {
      ans *= 26;
      mp[l] = '_';
    }
  }
  
  ans %= MOD;
  
  // cout<<"len = "<<(len+1)/2<<" mp = "<<mp.size()<<endl;
  
  for(int i = 0; i < (len+1)/2-(int)mp.size();i++){
    ans *= 26;
    ans %= MOD;
  }
  
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.2619047619047619
time_ms: 60
memory_kb: 15988
final_rank: 16

code_snippet: #include<iostream>
#include<algorithm>
#include<map>
using namespace std;

#define inRange(x,a,b) (a <= x && x < b)

typedef long long ll;

const ll mod = 1e9+7;
ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

bool isPalindrome(string s){
    int n = s.length();
    for(int i = 0; i < n; i++){
        if(s[i] != s[n-1-i])    return false;
    }
    return true;
}

void ng(){
    cout << 0 << endl;
    exit(0);
}

int main(){
    string zaki, o;
    int n;
    cin >> zaki >> o >> n;

    if(n <= o.length()){
        string hoge = o.substr(o.length()-n);
        reverse(hoge.begin(), hoge.end());
        string s = hoge + zaki + hoge + o;
        cout << isPalindrome(s) << endl;
        return 0;
    }

    map<int, char> ind;
    for(int i = 0; i < o.length(); i++) ind[i] = o[o.length()-1-i];

    ll len = n + zaki.length() + n + o.length();

    for(int i = 0; i < zaki.length(); i++){
        ll index = n + i;
        ll inv = len - 1 - index;
        if(inRange(inv, n, n+zaki.length()) && zaki[inv-n] != zaki[i]){
            ng();
        }else if(inRange(inv, n+zaki.length(), n+zaki.length()+n)){
            if(ind.count(inv-n-zaki.length()) == 1 && ind[inv-n-zaki.length()] != zaki[i]){
                ng();
            }
            ind[inv-n-zaki.length()] = zaki[i];
        }
    }

    ll ret = modpow(26, (n-ind.size()+1)/2);
    cout << ret << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7996
final_rank: 3

code_snippet: #include <iostream>
#include <algorithm>
#include <string>

using Int = long long int;
using std::string;

constexpr Int MOD = 1000000007;

Int ipow(Int x, Int n) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x) %= MOD;
        n >>= 1;
        (x *= x) %= MOD;
    }
    return ret;
}

void fail() {
    std::cout << 0 << std::endl;
    std::exit(0);
}

bool ispali(string s) {
    int l = s.length();
    for (int i = 0; i < l; ++i) {
        if (s[i] != s[l - i - 1]) return false;
    }
    return true;
}

int main() {
    int n;
    string t, u;
    std::cin >> t >> u >> n;

    if (n > u.length()) {
        std::reverse(u.begin(), u.end());
        Int ans = ipow(26LL, (n - u.length() + 1) / 2);

        std::cout << (ispali(t + u) ? ans
                                    : 0)
                  << std::endl;
    } else {
        std::reverse(u.begin(), u.end());
        string s = u.substr(0, n);
        std::reverse(u.begin(), u.end());

        std::cout << (ispali(s + t + s + u) ? 1
                                            : 0)
                  << std::endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3692
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define MAX_N 10000000
struct UnionFind{
	int par[MAX_N+100];
	void init(){
		for(int i=0;i<MAX_N+5;i++){
			par[i] = i;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		par[x] = y;
		return;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
}uf;
const ll mod = 1000000007ll;

ll mypow(ll x, ll n) {
	if (n == 0ll) return 1ll;
	if (n == 1ll) return x % mod;
	if (n % 2ll == 0ll) {
		return mypow(x * x % mod, n / 2ll);
	} else {
		return mypow(x, n - 1ll) * x % mod;
	}
}
string O,Z;
string rO,rZ;
int N;
bool pali(string s){
	string t = s;
	reverse(all(t));
	return (s==t);
}
bool is_pre(string& s,string& t){
	return (s==t.substr(0,s.size()));
}
string suf(string s,int n){
	return s.substr(s.size()-n);
}
bool check(){
	if(Z.size()>=O.size()){
		if(!is_pre(O,Z))return false;
		if(!pali(suf(Z,Z.size()-O.size())))return false;
	}else{
		if(!is_pre(Z,O))return false;
		if(!pali(suf(O,O.size()-Z.size())))return false;
	}
	return true;
}	
struct node{
	char x;
	int id;
	node(){}
};
node str[MAX_N*2+200100];
char pos[MAX_N+100];
int main(){
	uf.init();
	cin >> Z;
	cin >> O;
	cin >> N;
	rO = O;
	reverse(all(rO));
	rZ = Z;
	reverse(all(rZ));
	if(N<=1000000){
		for(int i=0;i<N;i++){
			pos[i] = '$';
		}
		int offset = 0;
		for(int i=0;i<N;i++){
			str[offset+i].id = i;
		}
		offset += N;
		for(int i=0;i<Z.size();i++){
			str[offset+i].id = -1;
			str[offset+i].x = Z[i];
		}
		offset += Z.size();
		for(int i=0;i<N;i++){
			str[offset+i].id = i;
		}
		offset += N;
		for(int i=0;i<O.size();i++){
			str[offset+i].id = -1;
			str[offset+i].x = O[i];
		}
		offset += O.size();
		for(int i=0;i<offset/2;i++){
			int j = offset-1-i;
			if(str[i].id==-1&&str[j].id==-1){
				if(str[i].x!=str[j].x){
					cout << 0 << endl;
					return 0;
				}
			}else if(str[i].id==-1){
				int id = str[j].id;
				id = uf.find(id);
				if(pos[id]=='$'){
					pos[id] = str[i].x;
				}else{
					if(str[i].x!=pos[id]){
						cout << 0 << endl;
						return 0;
					}
				}
			}else if(str[j].id==-1){
				int id = str[i].id;
				id = uf.find(id);
				if(pos[id]=='$'){
					pos[id] = str[j].x;
				}else{
					if(str[j].x!=pos[id]){
						cout << 0 << endl;
						return 0;
					}
				}
			}else{
				int I = str[i].id;
				int J = str[j].id;
				I = uf.find(I);
				J = uf.find(J);
				if(pos[I]=='$'||pos[J]=='$'){
					if(pos[I]!='$')pos[J]=pos[I];
					if(pos[J]!='$')pos[I]=pos[J];
					uf.unite(I,J);
				}else{
					if(pos[I]!=pos[J]){
						cout << 0 << endl;
						return 0;
					}
					uf.unite(I,J);
				}
			}
		}
		ll ans = 1ll;
		for(int i=0;i<N;i++){
			if(uf.find(i)!=i)continue;
			if(pos[i]=='$'){
				ans = (ans*26ll)%mod;
			}
		}
		cout << ans << endl;
	}else{
		if(!check()){
			cout << 0 << endl;
			return 0;
		}
		if(Z.size()>=O.size()){
			cout << mypow(26ll,(N-O.size()+1)/2) << endl;
		}else{
			cout << mypow(26ll,(N-O.size()+1)/2) << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 45716
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 1e9+7;

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

struct UnionFind {
    vector<int> par;
    vector<int> sz;
    vector<int> ch;

    UnionFind(int n=0){
        if(n>0) initialize(n);
    }

    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        ch.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sz[find(x)];
    }
};

int main(){
    string S, T;
    int N;
    cin >> S >> T >> N;
    int A = S.size(), B = T.size();
    int64_t ans = 1;
    if(N > B){
        ans = power_mod(26, (N-B+1)/2);
        N = B;
    }
    int L = A+B+2*N;
    UnionFind uf(N+26);
    for(int i=0; i<L; i++){
        int j = L-i-1;
        if(i >= j) continue;
        vector<int> num;
        for(int p : {i, j}){
            if(p < N){
                num.push_back(p);
            }else if(p < N+A){
                num.push_back(N + S[p-N] - 'a');
            }else if(p < 2*N+A){
                num.push_back(p-N-A);
            }else{
                num.push_back(N + T[p-2*N-A] - 'a');
            }
        }
        uf.unite(num[0], num[1]);
    }
    for(int i=0; i<26; i++) for(int j=0; j<26; j++) if(i!=j && uf.same(N+i, N+j)) ans = 0;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4524
final_rank: 2