title: Timeout occurs. 2s Available only
body: <p>You are given two strings X and Y, both of equal length and contains only lower case Latin characters ('a'-'z'). String Y will be lexicographically greater than or equal to string X. You have to output the total number of strings which are lexicographically greater than or equal to string X and lexicographically less than or equal to string Y, has length same as string X and contains only lower case latin characters ('a'-'z'). As such strings can be large in number, output your answer modulo 109+7.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;math.h&gt;
  #include &lt;stdlib.h&gt;
  unsigned long long l=1000000007;
  
  unsigned long long p(int z){
  unsigned long long s=1;
  for(int k=1;k&lt;=z;k++)
      s=(s*26)%l;
      return s;
  }
  
  int main() {
  
  int n,i,j,k;
  unsigned long long sum=0;
  scanf("%d",&amp;n);
  char X[1000001];
  char Y[1000001];
  scanf(" %[^\t\n]s",X);
  scanf(" %[^\t\n]s",Y);
  for(i=0;i&lt;n;i++){
      if(X[i]!=Y[i]){
          sum=p(n-i);
          for(j=i;j&lt;n;j++){
              sum=(sum-p(n-j-1)*(X[j]-97)-p(n-j-1)*(122-Y[j])+100*l)%l;
          }
          break;
      }
  }
  
  printf("%llu",sum);
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>Why timeout occurs and how to make the program run under 2s for large inputs?</p>