//download 1 billion digits of pi here:
//https://stuff.mit.edu/afs/sipb/contrib/pi/pi-billion.txt
import java.io.*;
import java.util.*;
//_____________________________________________________________
public class skip
{ 
   byte[] file2 = getBytes("pi-billion.txt");
   String[] gen11 = "BRAJYO BRA ALHYM AO HJMYM VAO HARE".split(" ");
   String show = "";
//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   skip bnk = new skip();
   bnk.start3(args);
   bnk.start();
   bnk.start2(args);
}
//_____________________________________________________________
skip() throws Exception 
{
}

//___________________________________________________________________________
void start3(String[] args)
{
   if (args.length == 0) args = gen11;
   for (int i = 0; i < args.length; i++)
   {
      String valstr = "";
      String plastr = "";
      int val = value(args[i]);
      int pla = place(args[i]);
      String shw = name(args[i]);
      System.out.print("\r\n" + adjust(shw) + "\t");
      for (int j = 0; j < args[i].length(); j++)
      {
         String s = args[i].substring(j,j+1);
         int val2 = value(s); 
         int pla2 = place(s);
         if (j > 0) 
         {
            valstr += "+";
            plastr += "+";
         }
         valstr += val2;
         plastr += pla2;
         
      }
      valstr += "=" + val;
      plastr += "=" + pla;
      System.out.print(adjust(valstr) + "\t");     
      System.out.print(plastr + "\r\n");
   }
   System.out.println("");
}
//___________________________________________________________________________
String adjust(String str)
{
   String blank = "                              ";
   str = str + blank.substring(str.length());
   return(str);
}
//___________________________________________________________________________
void start2(String[] args)
{
   StringBuffer ans = new StringBuffer();
   StringBuffer ans2 = new StringBuffer();
   StringBuffer buf = new StringBuffer();
   if (args.length == 0) args = gen11;
   StringBuffer bufnum = new StringBuffer();
   StringBuffer bufnum2 = new StringBuffer();
   for (int i = 0; i < args.length; i++)
   {
      int val = value(args[i]);
      int pla = place(args[i]);
      int digval1 = digits(val);
      String showval = show;
      int digval2 = digits(digval1);
      showval += show;
      int digpla1 = digits(pla);
      String showpla = show;
      int digpla2 = digits(digpla1);
      showpla += show;
      bufnum.append(Integer.toString(digval2));
      bufnum2.append(args[i].length() + " ");
      buf.append(val + "\t" + showval + "\t" + digval2 + "\t" + pla + "\t" + showpla + "\t" + digpla2 + "\r\n");
   }
   System.out.println(buf.toString());
   int valnum2 = Integer.parseInt(bufnum.toString());
   int cnt = 0;
   for (int j = 0; j < 9 * valnum2; j += valnum2)
   {
      StringBuffer buf2 = new StringBuffer();
      for (int k = 0; k < 20; k++)
      {
         if (j+k-20 >= 0)
         {
            buf2.append((char)file2[j+k-20]);
         }
         else buf2.append(" ");
      }
      buf2.append(" ");
      for (int k = 0; k < 1; k++)
      {
         if (j+k-0 >= 0)
         {
            buf2.append((char)file2[j+k-0]);
            ans.append((char)file2[j+k-0]);
         }
         else buf2.append(" ");
      }
      buf2.append(" ");
      for (int k = 0; k < 20; k++)
      {
         buf2.append((char)file2[j+k+1]);
      }
      System.out.print(buf2.toString());
      System.out.println(" offset = " + cnt + " times " + bufnum.toString());
      cnt++;
   }



   String ansstr = ans.toString();
   int ansval = Integer.parseInt(ansstr);
   int dig1 = digits(ansval);
   System.out.println("");
   System.out.println(ansstr);
   System.out.println("");
   System.out.println(reverse(ansstr) + " " + dig1);
   System.out.println("");
   System.out.println("Digits 1 to 3 are the value of the first word.");
   System.out.println("Digits 4 to 5 are the place of the first word.");
   System.out.println("Digit 6 is for the 2 ways, value and place, that the first word is found.");
   System.out.println("Digits 7 to 9 are the number of fish Jesus caused to be caught.");
   System.out.println("The digits add up to 37, God's prime pair.");

   System.out.println("---------------------------");
   System.out.println("Length of each word.");
   System.out.println(bufnum2.toString());
   String thenum = bufnum2.toString().replace(" ","");
   System.out.println(thenum);
   int valnum = Integer.parseInt(thenum);
   cnt = 0;
   for (int j = 0; j < 20 * valnum; j += valnum)
   {
      
      StringBuffer buf2 = new StringBuffer();
      for (int k = 0; k < 20; k++)
      {
         if (j+k-20 >= 0)
         {
            buf2.append((char)file2[j+k-20]);
         }
         else buf2.append(" ");
      }
      buf2.append(" ");
      for (int k = 0; k < 1; k++)
      {
         if (j+k-0 >= 0)
         {
            buf2.append((char)file2[j+k-0]);
            ans2.append((char)file2[j+k-0]);
         }
         else buf2.append(" ");
      }
      buf2.append(" ");
      for (int k = 0; k < 20; k++)
      {
         buf2.append((char)file2[j+k+1]);
      }
      System.out.print(buf2.toString());
      System.out.println(" offset = " +  cnt + " times " + thenum);
      cnt++;
   }
   System.out.println("\r\n" + ans2 + "\r\n");
   System.out.println("Digits 1 to 3 are the value of the middle noun.");
   System.out.println("Digits 8 to 10 and 17 to 20 are the place of the middle noun forward and  backward.");
   System.out.println("Digit 4, 2, is for place and value, 2 ways of finding the middle noun.");
   System.out.println("Digits 5 to 8 are the value of the sentence plus divine perfection, 7, backwards.");
   System.out.println("Digits 11 to 13 is the value of the second word with the first digit doubled and the third digit halved.");
   System.out.println("Digits 14 to 15 is the sequence of position from the first to third noun.");
}
//___________________________________________________________________________
void start()
{
   int cnt = 0;
//   int k = 4555828;
   String out = "";
   for (int i = 1; i < file2.length / 9; i++)
   {
      StringBuffer buf = new StringBuffer();
      for (int j = 0; j < 9 * i; j += i)
      {
         buf.append((char)file2[j]);
      }
      String str = buf.toString();
      str = reverse(str);
      String str2 = str.substring(5,9);
      if (str2.equals("2153"))
      {
         int dig = digits(Integer.parseInt(str));
         String str3 = str.substring(2,4);
         int val3 = Integer.parseInt(str3);
         if (dig == val3)
         {
            int val4 = Integer.parseInt(str.substring(0,3));
            int val5 = Integer.parseInt(str.substring(3,5));
            if (digits(val4) == digits(val5))
            {
               String str6 = Integer.toString(i);
               String str7 = str6.substring(0,1);
               int val7 = Integer.parseInt(str7);
               if (val7 == digits(digits(val4)))
               {
                  if (str6.length() == 7)
                  {
                     String s2 = str6.substring(1,2);
                     String s3 = str6.substring(2,3);
                     String s4 = str6.substring(3,4);
                     if (s2.equals(s3) & s2.equals(s4))
                     {
                        System.out.println(++cnt + " " + i + " " + str + " " + dig);
                     }
                  }
               }
            }
         }
      }
   }
}
//___________________________________________________________________________
String reverse(String str)
{
   String out = "";
   for (int i = str.length() - 1; i >= 0; i--)
   {
      String s = str.substring(i,i+1);
      out += s;
   }
   return(out);
}
//___________________________________________________________________________
int digits(int val)
{
   show = "=";
   String str = Integer.toString(val);
   int total = 0;
   for (int i = 0; i < str.length(); i++)
   {
      if (i > 0) show += "+";
      String s = str.substring(i,i+1);
      show += s;
      total += Integer.parseInt(s);
   }
   show += "=" + Integer.toString(total);
   return(total);
}
//___________________________________________________________________________
String getFile2(String file) 
{
   StringBuffer buf=new StringBuffer();
   String str;
  try
  {
   BufferedReader in = new BufferedReader (new FileReader (file));
   while((str=in.readLine())!=null)
   {
      buf.append(str);
   }
   in.close();
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
   return (buf.toString());
}
//___________________________________________________________________________
byte[] getBytes(String name) 
{
   byte[] b = new byte[0];
  try
  {
   File file = new File(name);
   b = new byte[(int) file.length()];
   FileInputStream fileInputStream = new FileInputStream(file);
   fileInputStream.read(b);
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
   return(b);
}
//__________________________________________________
int value(String str)
{
   int total = 0;
   for (int i = 0; i < str.length(); i++)
   {
      int v = 0;
      String st2 = str.substring(i,i+1);
      byte[] st3 = st2.getBytes();
      byte st = st3[0];
      if (st == 'a') v = 1;
      else if (st == 'b') v = 2;
      else if (st == 'c') v = 3;
      else if (st == 'd') v = 4;
      else if (st == 'e') v = 5;
      else if (st == 'f') v = 6;
      else if (st == 'g') v = 7;
      else if (st == 'h') v = 8;
      else if (st == 'i') v = 9;
      else if (st == 'j') v = 10;
      else if (st == 'k') v = 20;
      else if (st == 'l') v = 30;    
      else if (st == 'm') v = 40;
      else if (st == 'n') v = 50;
      else if (st == 'o') v = 60;
      else if (st == 'p') v = 70;
      else if (st == 'q') v = 80;
      else if (st == 'r') v = 90;
      else if (st == 's') v = 100;
      else if (st == 't') v = 200;
      else if (st == 'u') v = 300;
      else if (st == 'v') v = 400;
      else if (st == 'w') v = 500;
      else if (st == 'x') v = 600;
      else if (st == 'y') v = 700;
      else if (st == 'z') v = 800;
      else if (st == 'A') v = 1;
      else if (st == 'B') v = 2;
      else if (st == 'G') v = 3;
      else if (st == 'D') v = 4;
      else if (st == 'H') v = 5;
      else if (st == 'V') v = 6;
      else if (st == 'Z') v = 7;
      else if (st == 'C') v = 8;
      else if (st == 'T') v = 9;
      else if (st == 'Y') v = 10;
      else if (st == 'K') v = 20;
      else if (st == 'L') v = 30;
      else if (st == 'M') v = 40;
      else if (st == 'N') v = 50;
      else if (st == 'S') v = 60;
      else if (st == 'I') v = 70;
      else if (st == 'F') v = 80;
      else if (st == 'E') v = 90;
      else if (st == 'Q') v = 100;
      else if (st == 'R') v = 200;
      else if (st == 'J') v = 300;
      else if (st == 'O') v = 400;
      total += v;
   }
   return(total);
}
//__________________________________________________
int place(String str)
{
   int total = 0;
   for (int i = 0; i < str.length(); i++)
   {
      int v = 0;
      String st2 = str.substring(i,i+1);
      byte[] st3 = st2.getBytes();
      byte st = st3[0];
      if (st == 'a') v = 1;
      else if (st == 'b') v = 2;
      else if (st == 'c') v = 3;
      else if (st == 'd') v = 4;
      else if (st == 'e') v = 5;
      else if (st == 'f') v = 6;
      else if (st == 'g') v = 7;
      else if (st == 'h') v = 8;
      else if (st == 'i') v = 9;
      else if (st == 'j') v = 10;
      else if (st == 'k') v = 11;
      else if (st == 'l') v = 12;    
      else if (st == 'm') v = 13;
      else if (st == 'n') v = 14;
      else if (st == 'o') v = 15;
      else if (st == 'p') v = 16;
      else if (st == 'q') v = 17;
      else if (st == 'r') v = 18;
      else if (st == 's') v = 19;
      else if (st == 't') v = 20;
      else if (st == 'u') v = 21;
      else if (st == 'v') v = 22;
      else if (st == 'w') v = 23;
      else if (st == 'x') v = 24;
      else if (st == 'y') v = 25;
      else if (st == 'z') v = 26;
      else if (st == 'A') v = 1;
      else if (st == 'B') v = 2;
      else if (st == 'G') v = 3;
      else if (st == 'D') v = 4;
      else if (st == 'H') v = 5;
      else if (st == 'V') v = 6;
      else if (st == 'Z') v = 7;
      else if (st == 'C') v = 8;
      else if (st == 'T') v = 9;
      else if (st == 'Y') v = 10;
      else if (st == 'K') v = 11;
      else if (st == 'L') v = 12;
      else if (st == 'M') v = 13;
      else if (st == 'N') v = 14;
      else if (st == 'S') v = 15;
      else if (st == 'I') v = 16;
      else if (st == 'F') v = 17;
      else if (st == 'E') v = 18;
      else if (st == 'Q') v = 19;
      else if (st == 'R') v = 20;
      else if (st == 'J') v = 21;
      else if (st == 'O') v = 22;
      total += v;
   }
   return(total);
}
//__________________________________________________
String name(String str)
{
   int total = 0;
   String out = "";
   for (int i = 0; i < str.length(); i++)
   {
      String v = "";
      String st2 = str.substring(i,i+1);
      byte[] st3 = st2.getBytes();
      byte st = st3[0];
      if (st == 'a') v = "a";
      else if (st == 'b') v = "b";
      else if (st == 'c') v = "c";
      else if (st == 'd') v = "d";
      else if (st == 'e') v = "e";
      else if (st == 'f') v = "f";
      else if (st == 'g') v = "g";
      else if (st == 'h') v = "h";
      else if (st == 'i') v = "i";
      else if (st == 'j') v = "j";
      else if (st == 'k') v = "k";
      else if (st == 'l') v = "l";    
      else if (st == 'm') v = "m";
      else if (st == 'n') v = "n";
      else if (st == 'o') v = "o";
      else if (st == 'p') v = "p";
      else if (st == 'q') v = "q";
      else if (st == 'r') v = "r";
      else if (st == 's') v = "s";
      else if (st == 't') v = "t";
      else if (st == 'u') v = "u";
      else if (st == 'v') v = "v";
      else if (st == 'w') v = "w";
      else if (st == 'x') v = "x";
      else if (st == 'y') v = "y";
      else if (st == 'z') v = "z";
      else if (st == 'A') v = "Alef";
      else if (st == 'B') v = "Beit";
      else if (st == 'G') v = "Gimel";
      else if (st == 'D') v = "Dalet";
      else if (st == 'H') v = "Hei";
      else if (st == 'V') v = "Vav";
      else if (st == 'Z') v = "Zayin";
      else if (st == 'C') v = "Cheit";
      else if (st == 'T') v = "Teit";
      else if (st == 'Y') v = "Yod";
      else if (st == 'K') v = "Khaf";
      else if (st == 'L') v = "Lamed";
      else if (st == 'M') v = "Mem";
      else if (st == 'N') v = "Nun";
      else if (st == 'S') v = "Samekh";
      else if (st == 'I') v = "Ayin";
      else if (st == 'F') v = "Fe";
      else if (st == 'E') v = "Tzadei";
      else if (st == 'Q') v = "Qof";
      else if (st == 'R') v = "Reish";
      else if (st == 'J') v = "Shin";
      else if (st == 'O') v = "Tav";
      out += v + " ";
   }
   return(out);
}
}//__________________________________________________________________________
