import java.util.ArrayList;

   class TallyProcessor {
      private static java.util.Random rn = new java.util.Random();
      private static int nextId = 1;
      private static int BalID = 0;
      private int id = nextId++;
      public TallyProcessor next;
      private ArrayList<Integer>Count = new ArrayList<Integer>();
      private ArrayList<Integer>NoCount = new ArrayList<Integer>();
      private boolean CountInit = false;
      
      public void add( TallyProcessor nextP ) {
         if (next != null) next.add( nextP );
         else next = nextP;
      }
         
      public void handle( Ballot B, int index, boolean flag ) {
    	  
    	  
    	 
    		  
    		Ballot ThisBallot ;
    	  int   j=0;
    	  if(flag == true)
    	  {
    		  ThisBallot  =  (Ballot) B.getIssues().get(index);	
    		  index++;
    		  j=ThisBallot.getIssues().size();
    		  
    	  }
    	  
    	  else
    	  {
    		  int i;
    		 
    		   ThisBallot = B;  
    		  for(i = 0; i < B.getIssues().size(); i++ )
    		  {
    			 AbsBallot TempBallot = (AbsBallot) B.getIssues().get(i);
    			 if(TempBallot.getIdentifier().equals("issue"))
    			  j++;
    			 
    			 
    				 
    			 
    			  
    		  }
    		  
    		  index = j;
    	  }
    	  
    	  if(!CountInit)
    	  { 
	    	for(int i = 0; i < j; i++ )
	          {
	    		Count.add(i, 0);
	    		NoCount.add(i,0);
	          }
	    	CountInit = true;
    	  }
		  
    	  Count(j, ThisBallot);
    	  
    	  if(index<B.getIssues().size())  
    	  {
    	  next.handle(B, index, true);
    		  
    	  } 
      }  
      
      public void Count(int j, Ballot ThisBallot)
      {
    	  for(int i = 0; i < j; i++ )
          {
    		  Issue QuesBallot =  (Issue)ThisBallot.getIssues().get(i);
    		  if(QuesBallot.getVote())
    			  YesCounter(i);
    		  else
    			  NoCounter(i);
          }	
    	  
      }
      
      
      public void YesCounter(int i)
      {
    	  Count.set(i,  Count.get(i)+1);
    	  
      }
      
      public void NoCounter(int i)
      {
    	  NoCount.set(i,  Count.get(i)+1);
    	  
      }

      public void PrintVote()
      {
    	  for(int i = 0; i < Count.size(); i++)
    		  System.out.println(Count.get(i));
    	  System.out.println("\n");
    	  
      }
      

   static public TallyProcessor setUpChain(int num) {
      TallyProcessor root = new TallyProcessor();
      for (int i=0; i < num-1; i++)
    	  	root.add( new TallyProcessor() );
      return root;
   }
   
   

}