import java.io.PrintStream; import java.util.Scanner; /** * Solution to Dihedral Group. * * @author vanb */ public class dihedral_vanb { /** Input. */ private static Scanner sc; /** Output. */ private static PrintStream ps; /** * Compare the test to the dihedral group. * * @param dihedral the dihedral group * @param test the test sequence * @param index the index where test[0] occurs in dihedral * @param increment the increment, either 1 or n-1 (which is essentially -1) * @return true, if successful */ private boolean compare( int dihedral[], int test[], int index, int increment ) { boolean ok = true; for( int i=0; i=0 ) // Fail if we can't find test[0] { if( compare( dihedral, test, start, 1 ) ) result = 1; // Forwards else if( compare( dihedral, test, start, n-1 )) result = 1; // Backwards } ps.println( result ); } /** * Main. * * @param args unused * @throws Exception the exception */ public static void main( String[] args ) throws Exception { sc = new Scanner( System.in ); ps = System.out; new dihedral_vanb().doit(); } }