<s> from time import clock <EOL> from runtime import * <EOL> DEFAULT_ARG = <NUM_LIT:9> <EOL> def main ( ) : <EOL> times = [ ] <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> t0 = clock ( ) <EOL> res = fannkuch ( DEFAULT_ARG ) <EOL> tk = clock ( ) <EOL> times . append ( tk - t0 ) <EOL> avg = sum ( times ) / len ( times ) <EOL> print ( avg ) <EOL> def fannkuch ( n ) : <EOL> count = list ( range ( <NUM_LIT:1> , n + <NUM_LIT:1> ) ) <EOL> perm1 = list ( range ( n ) ) <EOL> perm = list ( range ( n ) ) <EOL> max_flips = <NUM_LIT:0> <EOL> m = n - <NUM_LIT:1> <EOL> r = n <EOL> check = <NUM_LIT:0> <EOL> while True : <EOL> if check < <NUM_LIT:30> : <EOL> check += <NUM_LIT:1> <EOL> while r != <NUM_LIT:1> : <EOL> count [ r - <NUM_LIT:1> ] = r <EOL> r -= <NUM_LIT:1> <EOL> if perm1 [ <NUM_LIT:0> ] != <NUM_LIT:0> and perm1 [ m ] != m : <EOL> perm = perm1 [ : ] <EOL> flips_count = <NUM_LIT:0> <EOL> k = perm [ <NUM_LIT:0> ] <EOL> while k != <NUM_LIT:0> : <EOL> perm [ : k + <NUM_LIT:1> ] = perm [ k : : - <NUM_LIT:1> ] <EOL> flips_count += <NUM_LIT:1> <EOL> k = perm [ <NUM_LIT:0> ] <EOL> if flips_count > max_flips : <EOL> max_flips = flips_count <EOL> do_return = True <EOL> while r != n : <EOL> perm1 . insert ( r , perm1 . pop ( <NUM_LIT:0> ) ) <EOL> count [ r ] -= <NUM_LIT:1> <EOL> if count [ r ] > <NUM_LIT:0> : <EOL> do_return = False <EOL> break <EOL> r += <NUM_LIT:1> <EOL> if do_return : <EOL> return max_flips <EOL> main ( ) </s>
