import java.util.*;
import java.io.*;
import java.net.*;
import java.util.zip.*;
//_____________________________________________________________
public class subsets
{ 
   //pseudo Genesis 1:1 "BRAJYO BRA ALHYM AO HJMYM VAO HARE";
   String gen11  = "BRAJYOBRAALHYMAOHJMYMVAOHARE";
   int[] plax = new int[gen11.length()];
   int[] valx = new int[gen11.length()];
   int totalcnt = 0;
   int totalvalminuspla = 0;
   int factor = 73;
   int mill = 0;
   Random rand = new Random(0);
   static String out = "";
//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   subsets bnk = new subsets();
   bnk.start(args);
}
//___________________________________________________________________________
void start(String[] args)
{
   System.out.println("This proves pattern 77.");
   startit(args);
   for (int i = 000; i < 1000; i++)
   {
      totalcnt = 0;
      totalvalminuspla = 0;
      rand = new Random(i);
      gen11 = randomstr(gen11.length());
      startit(args);
   }
}
//___________________________________________________________________________
void startit(String[] args)
{
   long t1 = System.nanoTime();
   System.out.println(gen11);
   int lk = 28;
   if (args.length > 0) lk = Integer.parseInt(args[0]);
   if (args.length > 1) factor = Integer.parseInt(args[1]);
   for (int i = 0; i < gen11.length(); i++)
   {
      String s = gen11.substring(i,i+1);
      plax[i] = place(s);
      valx[i] = value(s);
   }
   double ans = getsubset(lk);
   long t2 = System.nanoTime();
   System.out.println("seconds = " + ((t2-t1)/1e9));
   StringBuffer buf = new StringBuffer();
   buf.append(gen11 + " " + ans + "\r\n");
   saveFile("output.txt",buf.toString(),true);
}
//___________________________________________________________________________
double getsubset(int len)
{
   subit(len, 0, "");
   System.out.println("\r\n" + totalcnt + " " + (totalcnt / factor));
   double exp = (double)totalcnt / 73.0;
   double vv = (double)totalvalminuspla / exp;
   System.out.println(vv);
   return(vv);
}
//___________________________________________________________________________
void subit(int val, int start, String str)
{
   for (int i = start; i < val; i++)
   {
      mill++;
      if (mill >= 1000000)
      {
         System.out.print(".");
         mill = 0;
      }
      String str2 = str + Integer.toString(i) + ",";
      String[] pos = str2.split(",");
      int ttlpla = 0;
      int ttlval = 0;
      for (int j = 0; j < pos.length; j++)
      {
         int ps = Integer.parseInt(pos[j]);
         ttlpla += plax[ps];
         ttlval += valx[ps];
      }
      if ((ttlval - ttlpla) % factor == 0) totalvalminuspla++;
      totalcnt++;
      subit(val, i+1, str2);
   }
}
//___________________________________________________________________________
String randomstr(int len)
{
   String alphabet = "ABGDHVZCTYKLMNSIFEQRJO";
   StringBuffer buf = new StringBuffer();
   for (int i = 0; i < len; i++)
   {
      int pos = rand.nextInt(22);
      String s = alphabet.substring(pos,pos+1);
      buf.append(s);
   }
   return(buf.toString());
}
//__________________________________________________
public static int value(String str)
{
   int total = 0;
   out = "";
   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;
      if (i > 0) out += " + ";
      out += Integer.toString(v);
   }
   return(total);
}
//__________________________________________________
public static int place(String str)
{
   int total = 0;
   out = "";
   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;
      if (i > 0) out += " + ";
      out += Integer.toString(v);
   }
   return(total);
}
//___________________________________________________________________________
void saveFile(String file, String str, boolean append) 
{
  try
  {
   BufferedWriter out = new BufferedWriter(new FileWriter(file, append));
   out.write(str);
   out.close();
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
}
}//__________________________________________________________________________
