fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.math.*;
  4. import java.io.*;
  5.  
  6. import static java.lang.Math.*;
  7. import static java.util.Arrays.*;
  8.  
  9. public class B{
  10. Scanner sc=new Scanner(System.in);
  11.  
  12. int INF=1<<28;
  13. double EPS=1e-9;
  14.  
  15. void run(){
  16. String s=sc.next();
  17. String start=sc.next();
  18. String end=sc.next();
  19.  
  20. int n=s.length();
  21.  
  22. long[] coes=new long[n];
  23. coes[n-1]=1;
  24. for(int i=n-2; i>=0; i--){
  25. coes[i]=coes[i+1]*31;
  26. }
  27.  
  28. long[] hashes=new long[n*n];
  29. int k=0;
  30.  
  31. LinkedList<Integer> ss=new LinkedList<Integer>();
  32. LinkedList<Integer> es=new LinkedList<Integer>();
  33. for(int i=s.indexOf(start); i>=0; i=s.indexOf(start, i+1)){
  34. ss.add(i);
  35. }
  36. for(int i=s.indexOf(end); i>=0; i=s.indexOf(end, i+1)){
  37. es.add(i);
  38. }
  39.  
  40. for(int ks : ss){
  41. int i=ks;
  42. long hash=0;
  43. for(int ke : es){
  44. if(ks<=ke&&ks+start.length()<=ke+end.length()){
  45. for(; i<ke+end.length(); i++){
  46. hash+=(s.charAt(i))*coes[i-ks];
  47. }
  48. hashes[k++]=hash;
  49. }
  50. }
  51. }
  52.  
  53. sort(hashes);
  54. long ph=hashes[0]+1;
  55. int ans=0;
  56. for(long h : hashes){
  57. if(h!=ph){
  58. ans++;
  59. }
  60. ph=h;
  61. }
  62. ans--;
  63. println(ans+"");
  64. }
  65.  
  66. void println(String s){
  67. System.out.println(s);
  68. }
  69.  
  70. void print(String s){
  71. System.out.print(s);
  72. }
  73.  
  74. void debug(Object... os){
  75. System.err.println(Arrays.deepToString(os));
  76. }
  77.  
  78. public static void main(String[] args){
  79. new B().run();
  80. }
  81. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty