import java.io.*;
import java.util.*;
import java.net.*;
import java.math.*;
//_____________________________________________________________
public class john_1_1
{ 
   String gen = "BRAJYO BRA ALHYM AO HJMYM VAO HARE";

//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   john_1_1 bnk = new john_1_1();
   bnk.start();
}
//_____________________________________________________________
john_1_1() throws Exception 
{
}
//___________________________________________________________________________
void start()
{
   StringBuffer buf = new StringBuffer();
   int letters = 0;
   BigInteger totalletters = new BigInteger("1");
   BigInteger totalwords = new BigInteger("1");
   String[] file = getFile("john_1_1.txt").split("\r\n");
   for (int i = 0; i < file.length; i++)
   {
      String[] words = file[i].split(" ");
      letters += words.length;
      long sumwords = 0;
      long prodwords = 1;
      for (int j = 0; j < words.length; j++)
      {
         int val = Integer.parseInt(words[j]);
         sumwords += val;
         prodwords *= val;
      }
      String strsumwords = Long.toString(sumwords);
      String strprodwords = Long.toString(prodwords);
      BigInteger ts = new BigInteger(strsumwords);
      BigInteger tp = new BigInteger(strprodwords);
      totalletters = totalletters.multiply(tp);
      totalwords = totalwords.multiply(ts);
      System.out.println(file[i] + " | " + sumwords + " | " + prodwords);
   }
   int words = file.length;
   System.out.println(letters + " " + totalletters + "\r\n" + words + " " + totalwords);
   System.out.println("");
   buf.append(letters + " " + totalletters + "<br>\r\n" + words + " " + totalwords + "<br><br>\r\n");
   BigInteger bgwords = new BigInteger(Integer.toString(words));
   BigInteger bgletters = new BigInteger(Integer.toString(letters));
   BigInteger totwords = totalwords.multiply(bgwords);
   BigInteger totletters = totalletters.multiply(bgletters);
   System.out.println(totletters + "\r\n" + totwords);
   buf.append(totletters + "<br>\r\n" + totwords + "<br><br>\r\n");
   BigInteger ans = totletters.divide(totwords);
   System.out.println("");
   System.out.println(ans);
   buf.append(ans + "<br><br>\r\n");
   StringBuffer buf1 = new StringBuffer();
   StringBuffer buf2 = new StringBuffer();
   StringBuffer buf3 = new StringBuffer();
   StringBuffer buf4 = new StringBuffer();
   buf1.append(totalletters);
   buf2.append(totalwords);
   buf3.append(totletters);
   buf4.append(totwords);  
   System.out.println(digits(buf1.toString(),999));
   System.out.println(digits(buf2.toString(),999));
   System.out.println(digits(buf3.toString(),999));
   System.out.println(digits(buf4.toString(),999));
   buf.append(digits(buf1.toString(),27) + "<br>\r\n");
   buf.append(digits(buf2.toString(),27) + "<br>\r\n");
   buf.append(digits(buf3.toString(),27) + "<br>\r\n");
   buf.append(digits(buf4.toString(),27) + "<br>\r\n");
   saveFile("john_1_1.htm",buf.toString(),false);

}
//___________________________________________________________________________
String digits(String str, int hl)
{
   int total = 0;
   for (int i = 0; i < str.length(); i++)
   {
      String s = str.substring(i,i+1);
      int v = Integer.parseInt(s);
      total += v;
   }
   String out = showfactors(total,hl);
   return(out);
}
//___________________________________________________________________________
public static String getFile(String file) 
{
   StringBuffer buf=new StringBuffer();String str;
  try
  {
   BufferedReader in = new BufferedReader (new FileReader (file));
   while((str=in.readLine())!=null)
   {
      buf.append(str+"\r\n");
   }
   in.close();
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
   return (buf.toString());
}
//___________________________________________________________________________
public static 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);
  }
}
//___________________________________________________________________________
public static String showfactors(int myval, int hl)
{
   StringBuffer buf = new StringBuffer();
   double myvald = (double)myval;
   for (int i = 1; i <= myval; i++)
   {
      double id = (double)i;
      double val1 = myvald / id;
      int val2 = (int)val1;
      if (val1 == val2)
      {
         if (i == hl) buf.append("<font size='5' color='red'>");
         buf.append(i);
         if (i == hl) buf.append("</font>");
         buf.append(" ");
      }  
   }
   return(buf.toString().trim());
}
}//__________________________________________________________________________
