Language: C++

#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef __int128 Hash;

const Hash A=1e9+7;
const Hash MOD=1e18+9;


void reg(Hash &x){x=(x%MOD+MOD)%MOD;}

void debug(Hash val){
  cout<<static_cast<long long int>(val)<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int m;
  cin>>m;
  vector<string> x(m);
  vector<string> y(m);
  unordered_map<int,vector<int>> xx;
  unordered_map<int,vector<int>> yy;
  set<int> xy_set;
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
    xy_set.insert(x[i].size());
    xy_set.insert(y[i].size());
    xx[x[i].size()].push_back(i);
    yy[y[i].size()].push_back(i);
  }
  map<char,Hash> dic;
  dic['a']=3344227;
  for(char x='b';x<='z';x++){
    dic[x]=dic[x-1]*A+1e10-9;;
    reg(dic[x]);;
  }

  vector<Hash> pow_A(s.size()+1);
  pow_A[0]=1;
  for(int i=1;i<=s.size();i++){
    pow_A[i]=pow_A[i-1]*A;
    reg(pow_A[i]);
  }
  
  vector<Hash> hash(s.size()+1); //hash[i] = hash(s[0,i))
  hash[0]=0;
  for(int i=0;i<s.size();i++){
    hash[i+1]=hash[i]*A;
    reg(hash[i+1]);
    hash[i+1]+=dic[s[i]];
    reg(hash[i+1]);
  }


  auto get_hash=[&dic](const string &x){
    Hash res=0;
    for(int i=0;i<x.size();i++){
      res*=A;
      reg(res);
      Hash val=dic[x[i]];
      res+=val;
      reg(res);
    }
    return res;
  };


  vector<int> ll(m,10000000);
  vector<int> rr(m,-1);
  for(auto it=xy_set.begin();it!=xy_set.end();it++){
    int len=*it;
    unordered_map<Hash,int> min_index;
    unorederd_map<Hash,int> max_index;
    for(int i=0;i<s.size();i++){
      //hash(s[i,i+len))
      if(i+len>s.size()) break;
      Hash val=hash[i+len];
      Hash head=hash[i];
      head*=pow_A[len];
      reg(head);
      val-=head;
      reg(val);

      if(min_index.count(val)){
	min_index[val]=min(i,min_index[val]);
	max_index[val]=max(i,max_index[val]);
      }
      else{
	min_index[val]=i;
	max_index[val]=i;
      }
    }
    if(xx.count(len)){
      for(auto it=xx[len].begin();it!=xx[len].end();it++){
	  Hash xval=get_hash(x[*it]);
	  int lside;
	  if(min_index.count(xval)){
	    lside=min_index[xval];
	  }
	  else{
	    lside=s.size()+1;
	  }
	  ll[*it]=lside;
      }
    }
    if(yy.count(len)){
      for(auto it=yy[len].begin();it!=yy[len].end();it++){	
	  Hash yval=get_hash(y[*it]);
	  int rside;
	  if(max_index.count(yval)){
	    rside=max_index[yval]+len;
	  }
	  else{
	    rside=-1;
	  }
	  rr[*it]=rside;
      }
    }
  }
  
  for(int i=0;i<m;i++){
    int lside=ll[i];
    int rside=rr[i];
    if(lside<rside&& lside+x[i].size()<=rside && lside<=rside-y[i].size()){
      cout<<rside-lside<<endl;
    }
    else{
      cout<<0<<endl;
    }
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:77:5: error: 'unorederd_map' was not declared in this scope
   77 |     unorederd_map<Hash,int> max_index;
      |     ^~~~~~~~~~~~~
a.cc:77:23: error: expected primary-expression before ',' token
   77 |     unorederd_map<Hash,int> max_index;
      |                       ^
a.cc:77:24: error: expected primary-expression before 'int'
   77 |     unorederd_map<Hash,int> max_index;
      |                        ^~~
a.cc:90:9: error: 'max_index' was not declared in this scope; did you mean 'min_index'?
   90 |         max_index[val]=max(i,max_index[val]);
      |         ^~~~~~~~~
      |         min_index
a.cc:94:9: error: 'max_index' was not declared in this scope; did you mean 'min_index'?
   94 |         max_index[val]=i;
      |         ^~~~~~~~~
      |         min_index
a.cc:114:14: error: 'max_index' was not declared in this scope; did you mean 'min_index'?
  114 |           if(max_index.count(yval)){
      |              ^~~~~~~~~
      |              min_index