/* The Great Win32 Language Shootout http://dada.perl.it/shootout/ 
   contributed by Isaac Gouy (Nice novice)

To compile:	
   nicec --sourcepath=.. -d=. -a lists.jar lists

To run:
   java -jar lists.jar 16
*/


import ackermann; // reuse toSingleInt


void main(String[] args){
   var n = toSingleInt(args);

   let nSize = 10000;
   int L1Count = 0;

   while (n-- > 0){
      // initialize L1
      ArrayList L1 = new ArrayList(nSize);
      for (var j = 1; j <= nSize; j++) L1.add(j);

      // copy L1 to L2
      ArrayList L2 = L1.clone();

      // remove from left of L2 add to right of L3
      ArrayList L3 = new ArrayList(nSize);
      while (L2.size() > 0) 
         L3.add( L2.removeAt(0) ); 

      // remove from right of L3 add to right of L2
      int index;
      while ( (index = L3.size()) > 0) 
         L2.add( L3.removeAt(index - 1) );

      // reverse L1
      Collections.reverse(L1);

      // check that first item is now SIZE
      // NOTE: no Object to int type cast needed

      if (L1[0] != nSize) println("First item of L1 != SIZE");

      // check that L1 == L2
      if ( !L1.equals(L2) ) println("L1 != L2");
      L1Count = L1.size();
      }

   println(L1Count);
}