id
stringlengths
13
20
java
sequence
python
sequence
atcoder_abc034_D
[ "import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] w = new int [ n ] ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = sc . nextInt ( ) ; p [ i ] = sc . nextInt ( ) ; } double max = 100 , min = 0 , mid = 0 ; for ( int i = 0 ; i < 40 ; i ++ ) { double [ ] d = new double [ n ] ; double sum = 0 ; mid = ( max + min ) / 2 ; for ( int j = 0 ; j < n ; j ++ ) { d [ j ] = ( p [ j ] - mid ) * w [ j ] ; } Arrays . sort ( d ) ; for ( int j = 1 ; j <= k ; j ++ ) { sum += d [ n - j ] ; } if ( sum >= 0 ) { min = mid ; } else { max = mid ; } } out . println ( mid ) ; } }", "import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskD solver = new TaskD ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskD { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; int [ ] w = new int [ n ] ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = in . nextInt ( ) ; p [ i ] = in . nextInt ( ) ; } double max = 100 ; double min = 0 ; for ( int i = 0 ; i < 200 ; i ++ ) { double target = ( max + min ) / 2 ; double [ ] score = new double [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { score [ j ] = w [ j ] * ( ( ( double ) p [ j ] / 100 ) - ( target / 100 ) ) ; } Arrays . sort ( score ) ; double sum = 0 ; for ( int j = n - k ; j < n ; j ++ ) { sum += score [ j ] ; } if ( sum > 0 ) min = target ; else max = target ; } out . println ( min ) ; } } }", "import java . io . * ; import java . util . * ; import static java . lang . System . in ; class Main { static double [ ] [ ] rec ; public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , K = sc . nextInt ( ) ; rec = new double [ n ] [ 2 ] ; double sum = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { double w = sc . nextDouble ( ) , p = sc . nextDouble ( ) / 100.0 ; rec [ i ] [ 0 ] = w ; rec [ i ] [ 1 ] = p ; sum += p ; } if ( sum < 0.0001 ) { System . out . println ( 0 ) ; return ; } double lo = 0 , hi = 1 ; for ( int i = 0 ; i < 33 ; i ++ ) { double mid = ( lo + hi ) / 2 ; if ( check ( mid , K , n ) ) lo = mid ; else hi = mid ; } System . out . println ( lo * 100 ) ; } static boolean check ( double target , int K , int n ) { myC mc = new myC ( target ) ; Arrays . sort ( rec , mc ) ; double w = 0 , q = 0 ; for ( int i = n - 1 ; i >= n - K ; i -- ) { w += rec [ i ] [ 0 ] ; q += rec [ i ] [ 1 ] * rec [ i ] [ 0 ] ; } return q / w >= target ; } static class myC implements Comparator < double [ ] > { double target ; public myC ( double t ) { this . target = t ; } public int compare ( double [ ] a , double [ ] b ) { return Double . compare ( a [ 0 ] * ( a [ 1 ] - target ) , b [ 0 ] * ( b [ 1 ] - target ) ) ; } } }", "import java . util . * ; import java . io . * ; public class Main { static int N ; static int K ; static double [ ] w ; static double [ ] v ; static double [ ] y ; static boolean calc ( double x ) { for ( int i = 0 ; i < N ; i ++ ) { y [ i ] = v [ i ] - w [ i ] * x ; } Arrays . sort ( y ) ; double sum = 0.0 ; for ( int i = 0 ; i < K ; i ++ ) { sum += y [ N - i - 1 ] ; } if ( sum >= 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; K = sc . nextInt ( ) ; w = new double [ N ] ; v = new double [ N ] ; y = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; int p = sc . nextInt ( ) ; v [ i ] = w [ i ] * p / 100.0 ; } double lb = 0.0 ; double ub = 1000.0 ; for ( int loop = 0 ; loop < 100 ; loop ++ ) { double mid = ( lb + ub ) / 2 ; if ( calc ( mid ) ) lb = mid ; else ub = mid ; } System . out . println ( lb * 100.0 ) ; } }", "import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double [ ] w = new double [ n ] ; double [ ] p = new double [ n ] ; double pmax = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = sc . nextDouble ( ) ; p [ i ] = sc . nextDouble ( ) ; pmax = Math . max ( pmax , p [ i ] ) ; } double low = 0 ; double upp = pmax ; double x = ( low + upp ) / 2 ; while ( upp - low > 0.00000001 ) { double [ ] c = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = w [ i ] * ( p [ i ] - x ) ; } Arrays . sort ( c ) ; double sum = 0 ; for ( int i = n - 1 ; i >= n - k ; i -- ) { sum += c [ i ] ; } if ( sum > 0 ) { low = x ; x = ( low + upp ) / 2 ; } else { upp = x ; x = ( low + upp ) / 2 ; } } System . out . println ( x ) ; } }" ]
[ "N , K = map ( int , input ( ) . split ( ) ) NEW_LINE WP = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE MIN = 0 NEW_LINE MAX = 100 NEW_LINE while MAX - MIN > 10 ** ( - 8 ) : NEW_LINE INDENT x = ( MAX + MIN ) / 2 NEW_LINE NEEDLIST = [ WP [ i ] [ 0 ] * x - WP [ i ] [ 0 ] * WP [ i ] [ 1 ] for i in range ( N ) ] NEW_LINE NEEDLIST . sort ( ) NEW_LINE if sum ( NEEDLIST [ : K ] ) >= 0 : NEW_LINE INDENT MAX = x NEW_LINE DEDENT else : NEW_LINE INDENT MIN = x NEW_LINE DEDENT DEDENT print ( ( MAX + MIN ) / 2 ) NEW_LINE", "def salt_solution ( N : int , K : int , solutions : list ) -> float : NEW_LINE INDENT l , r = 0.0 , 100.0 NEW_LINE e = 10 ** ( - 10 ) NEW_LINE def check ( goal : float ) -> bool : NEW_LINE INDENT A = sorted ( ( - w * ( p - goal ) , w , p ) for w , p in solutions ) NEW_LINE cw , cp = 0 , 0 NEW_LINE for _ , w , p in A [ : K ] : NEW_LINE INDENT cp = ( cw * cp + w * p ) / ( cw + w ) NEW_LINE cw = w + cw NEW_LINE DEDENT return cp >= goal NEW_LINE DEDENT while r - l > e : NEW_LINE INDENT m = ( r + l ) / 2 NEW_LINE if check ( m ) : NEW_LINE INDENT l = m NEW_LINE DEDENT else : NEW_LINE INDENT r = m NEW_LINE DEDENT DEDENT return l NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT N = 0 NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE solutions = [ tuple ( int ( s ) for s in input ( ) . split ( ) ) for _ in range ( N ) ] NEW_LINE ans = salt_solution ( N , K , solutions ) NEW_LINE print ( ans ) NEW_LINE DEDENT", "def calculate ( a ) : NEW_LINE INDENT salt = 0 NEW_LINE tot = 0 NEW_LINE for w , p in a : NEW_LINE INDENT salt += w * p NEW_LINE tot += w NEW_LINE DEDENT return salt / tot NEW_LINE DEDENT def prioritize ( a , target ) : NEW_LINE INDENT return sorted ( a , key = lambda x : x [ 0 ] * ( x [ 1 ] - target ) , reverse = True ) NEW_LINE DEDENT def search ( a , K ) : NEW_LINE INDENT ng = 100 NEW_LINE ok = 0 NEW_LINE mid = ( ok + ng ) / 2 NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT prev = mid NEW_LINE a = prioritize ( a , mid ) NEW_LINE rho = calculate ( a [ : K ] ) NEW_LINE if rho >= mid : NEW_LINE INDENT ok = mid NEW_LINE DEDENT else : NEW_LINE INDENT ng = mid NEW_LINE DEDENT mid = ( ok + ng ) / 2 NEW_LINE if abs ( mid - prev ) < 1e-9 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return a [ : K ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N , K = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE a = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT w , p = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE a . append ( ( w , p ) ) NEW_LINE DEDENT aa = search ( a , K ) NEW_LINE print ( calculate ( aa ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "n , k = map ( int , input ( ) . split ( ) ) NEW_LINE info = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( n ) ] NEW_LINE used = [ False ] * n NEW_LINE ans_solution_g = 0 NEW_LINE ans_salt_g = 0 NEW_LINE for j in range ( k ) : NEW_LINE INDENT tmp_salution_g = 0 NEW_LINE tmp_salt_g = 0 NEW_LINE tmp_solution_p = 0 NEW_LINE tmp_i = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if used [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT new_solution_g = ans_solution_g + info [ i ] [ 0 ] NEW_LINE new_salt_g = ans_salt_g + ( info [ i ] [ 0 ] * info [ i ] [ 1 ] ) / 100 NEW_LINE new_solution_p = ( new_salt_g / new_solution_g ) * 100 NEW_LINE if new_solution_p > tmp_solution_p : NEW_LINE INDENT tmp_solution_g = new_solution_g NEW_LINE tmp_salt_g = new_salt_g NEW_LINE tmp_solution_p = new_solution_p NEW_LINE tmp_i = i NEW_LINE DEDENT DEDENT DEDENT used [ tmp_i ] = True NEW_LINE ans_solution_g = tmp_solution_g NEW_LINE ans_salt_g = tmp_salt_g NEW_LINE DEDENT print ( ans_salt_g / ans_solution_g * 100 ) NEW_LINE", "import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE item = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT w , p = map ( int , input ( ) . split ( ) ) NEW_LINE item . append ( [ p * w , w ] ) NEW_LINE DEDENT def check ( x ) : NEW_LINE INDENT y = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT y [ i ] = item [ i ] [ 0 ] - item [ i ] [ 1 ] * x NEW_LINE DEDENT y = sorted ( y , reverse = True ) NEW_LINE if sum ( y [ : K ] ) >= 0 : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def solve ( ) : NEW_LINE INDENT low = 0 NEW_LINE up = 10 ** 10 NEW_LINE e = 10 ** ( - 8 ) NEW_LINE while up - low >= e : NEW_LINE INDENT mid = ( low + up ) / 2 NEW_LINE if check ( mid ) : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT up = mid NEW_LINE DEDENT DEDENT print ( up ) NEW_LINE DEDENT solve ( ) NEW_LINE" ]
atcoder_arc006_C
[ "import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N ; N = Integer . parseInt ( reader . readLine ( ) ) ; List < Integer > result = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int value = Integer . parseInt ( reader . readLine ( ) ) ; int minIndex = - 1 , min = Integer . MAX_VALUE ; for ( int j = 0 ; j < result . size ( ) ; j ++ ) { if ( value <= result . get ( j ) ) { if ( result . get ( j ) - value < min ) { min = result . get ( j ) - value ; minIndex = j ; } } } if ( minIndex == - 1 ) { result . add ( value ) ; } else { result . set ( minIndex , value ) ; } } System . out . println ( result . size ( ) ) ; } }", "import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int ans = 0 ; int tmp [ ] = new int [ n ] ; Arrays . fill ( tmp , 100_001 ) ; for ( int i = 0 ; i < n ; i ++ ) { Arrays . sort ( tmp ) ; int w = sc . nextInt ( ) ; boolean canStack = false ; for ( int j = 0 ; j < ans ; j ++ ) { if ( tmp [ j ] >= w ) { canStack = true ; tmp [ j ] = w ; break ; } } if ( ! canStack ) { tmp [ ans ++ ] = w ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { new Main ( ) . main ( sc ) ; } catch ( Exception e ) { throw e ; } } }", "import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try ( CustomReader in = new CustomReader ( ) ) { new Main ( ) . execute ( in ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public void execute ( CustomReader in ) throws IOException { final int N = Integer . parseInt ( in . readLine ( ) ) ; int [ ] mountain = new int [ N ] ; int count = 0 ; Arrays . fill ( mountain , Integer . MAX_VALUE ) ; for ( int i = 0 ; i < N ; i ++ ) { int w = Integer . parseInt ( in . readLine ( ) ) ; int target = - 1 ; for ( int j = 0 ; j < count ; j ++ ) { if ( mountain [ j ] >= w ) { if ( target == - 1 || mountain [ target ] > mountain [ j ] ) { target = j ; } } } if ( target == - 1 ) { mountain [ count ++ ] = w ; } else { mountain [ target ] = w ; } } System . out . println ( count ) ; } static class CustomReader extends BufferedReader { private static final int DEFAULT_BUF_SIZE = 2048 ; public CustomReader ( ) throws IOException { super ( new InputStreamReader ( System . in ) , DEFAULT_BUF_SIZE ) ; } public int [ ] readLineAsIntArray ( ) throws IOException { String [ ] strArray = this . readLine ( ) . split ( \" ▁ \" ) ; int [ ] intArray = new int [ strArray . length ] ; for ( int i = 0 , n = strArray . length ; i < n ; i ++ ) { intArray [ i ] = Integer . parseInt ( strArray [ i ] ) ; } return intArray ; } public int [ ] [ ] readAsIntMatrix ( int rows , int columns ) throws IOException { int [ ] [ ] matrix = new int [ rows ] [ columns ] ; for ( int i = 0 ; i < rows ; i ++ ) { String [ ] r = this . readLine ( ) . split ( \" ▁ \" ) ; for ( int j = 0 ; j < columns ; j ++ ) { matrix [ i ] [ j ] = Integer . parseInt ( r [ j ] ) ; } } return matrix ; } } }", "import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; int arr [ ] = new int [ 55 ] ; while ( n -- != 0 ) { int w = sc . nextInt ( ) ; int yes = 0 ; int mid = 100005 , j = - 1 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == w ) { yes = 1 ; break ; } if ( arr [ i ] > w ) { if ( arr [ i ] - w < mid ) { mid = arr [ i ] - w ; j = i ; } } if ( arr [ i ] == 0 ) break ; } if ( yes == 0 && j != - 1 ) { arr [ j ] = w ; } if ( yes == 0 && j == - 1 ) { for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == 0 ) { arr [ i ] = w ; ans ++ ; break ; } } } } System . out . println ( ans ) ; } }", "import java . util . * ; import java . io . InputStreamReader ; import java . io . BufferedReader ; import java . util . Arrays ; import java . util . List ; import java . util . ArrayList ; import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; List < Integer > boxes = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) { boxes . add ( Integer . parseInt ( br . readLine ( ) ) ) ; } List < Integer > mtns = new ArrayList ( ) ; for ( Integer box : boxes ) { int min = 100000 ; int index = - 1 ; for ( int i = 0 ; i < mtns . size ( ) ; i ++ ) { int diff = mtns . get ( i ) - box ; if ( diff >= 0 && diff < min ) { min = diff ; index = i ; } } if ( min == 100000 ) { mtns . add ( box ) ; } else mtns . set ( index , box ) ; } System . out . println ( mtns . size ( ) ) ; } } class Box { int w ; int h ; public Box ( int w , int h ) { this . w = w ; this . h = h ; } } class BoxComparator1 implements Comparator < Box > { public int compare ( Box b1 , Box b2 ) { return b1 . w - b2 . w ; } } class BoxComparator2 implements Comparator < Box > { public int compare ( Box b1 , Box b2 ) { return b1 . h - b2 . h ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details ." ]
[ "n = int ( input ( ) ) NEW_LINE L = [ ] NEW_LINE L . append ( int ( input ( ) ) ) NEW_LINE ans = 1 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT L . sort ( ) NEW_LINE a = int ( input ( ) ) NEW_LINE y = 0 NEW_LINE for j in range ( len ( L ) ) : NEW_LINE INDENT if L [ j ] >= a : NEW_LINE INDENT L [ j ] = a NEW_LINE y = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if y == 0 : NEW_LINE INDENT ans += 1 NEW_LINE L . append ( a ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE", "import bisect NEW_LINE N = int ( input ( ) ) NEW_LINE W = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE ds = [ W [ 0 ] ] NEW_LINE for w in W [ 1 : ] : NEW_LINE INDENT i = bisect . bisect_left ( ds , w ) NEW_LINE if i == len ( ds ) : NEW_LINE INDENT ds . append ( w ) NEW_LINE DEDENT else : NEW_LINE INDENT ds [ i ] = w NEW_LINE DEDENT DEDENT print ( len ( ds ) ) NEW_LINE", "if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT box_count = int ( input ( ) ) NEW_LINE boxes = [ ] NEW_LINE box_towers = [ ] NEW_LINE for i in range ( box_count ) : NEW_LINE INDENT boxes . append ( int ( input ( ) ) ) NEW_LINE DEDENT for box in boxes : NEW_LINE INDENT is_stacked = False NEW_LINE for tower in box_towers : NEW_LINE INDENT if tower [ - 1 ] >= box : NEW_LINE INDENT tower . append ( box ) NEW_LINE is_stacked = True NEW_LINE break NEW_LINE DEDENT DEDENT if not is_stacked : NEW_LINE INDENT box_towers . append ( [ box ] ) NEW_LINE DEDENT DEDENT print ( len ( box_towers ) ) NEW_LINE DEDENT", "import bisect NEW_LINE def bump ( T , x ) : NEW_LINE INDENT if T == [ ] : NEW_LINE INDENT return [ [ x ] ] NEW_LINE DEDENT else : NEW_LINE INDENT i = bisect . bisect_right ( T [ 0 ] , x ) NEW_LINE if i == len ( T [ 0 ] ) : NEW_LINE INDENT return [ T [ 0 ] + [ x ] ] + T [ 1 : ] NEW_LINE DEDENT else : NEW_LINE INDENT y = T [ 0 ] [ i ] NEW_LINE T [ 0 ] [ i ] = x NEW_LINE return [ T [ 0 ] ] + bump ( T [ 1 : ] , y ) NEW_LINE DEDENT DEDENT DEDENT N = int ( input ( ) ) NEW_LINE w = [ None for i in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT w [ i ] = int ( input ( ) ) NEW_LINE DEDENT T = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT T = bump ( T , w [ N - 1 - i ] ) NEW_LINE DEDENT print ( len ( T ) ) NEW_LINE", "N = int ( input ( ) ) NEW_LINE upper_nums = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT new_num = int ( input ( ) ) NEW_LINE if len ( upper_nums ) == 0 : NEW_LINE INDENT upper_nums . append ( new_num ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( len ( upper_nums ) ) : NEW_LINE INDENT if upper_nums [ i ] >= new_num : NEW_LINE INDENT upper_nums [ i ] = new_num NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT upper_nums . append ( new_num ) NEW_LINE DEDENT DEDENT upper_nums . sort ( ) NEW_LINE DEDENT print ( len ( upper_nums ) ) NEW_LINE" ]
codejam_16_11
[ "import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numCases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; caseNum ++ ) { String S = sc . next ( ) ; char ch = S . charAt ( 0 ) ; Deque < Character > chars = new ArrayDeque < > ( ) ; chars . addLast ( S . charAt ( 0 ) ) ; for ( int i = 1 ; i < S . length ( ) ; i ++ ) { char next = S . charAt ( i ) ; if ( next >= chars . getFirst ( ) ) { chars . addFirst ( next ) ; } else { chars . addLast ( next ) ; } } System . out . print ( \" Case ▁ # \" + caseNum + \" : ▁ \" ) ; for ( Character c : chars ) { System . out . print ( c ) ; } System . out . println ( ) ; } } }", "package cj2016 . r1a ; import java . io . * ; import java . util . * ; public class A { Scanner sc ; PrintWriter pw ; char [ ] S ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : \" A - large \" ; try { new A ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + \" . in \" ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + \" . out \" ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; System . out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; solve ( ) ; } System . out . println ( \" Finished . \" ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { S = sc . next ( ) . toCharArray ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } public void solve ( ) { String ans = \" \" ; for ( char c : S ) { String s1 = ans + c ; String s2 = c + ans ; ans = s1 . compareTo ( s2 ) < 0 ? s2 : s1 ; } println ( ans ) ; } }", "package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static String solve ( String s , int x ) { if ( s . equals ( \" . \" ) ) { return \" \" ; } String t = \" \" ; char c = ' Z ' ; c -= x ; String [ ] u = s . split ( Character . toString ( c ) ) ; for ( int i = 0 ; i < u . length - 1 ; i ++ ) { t += c ; } for ( int i = 0 ; i < u . length ; i ++ ) { if ( i == 0 ) { t += solve ( u [ i ] , x + 1 ) ; } else { t += remove ( u [ i ] ) ; } } return t ; } public static String remove ( String s ) { String t = \" \" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) != ' . ' ) { t += s . charAt ( i ) ; } } return t ; } public static String interlace ( String s ) { String t = \" . \" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { t += s . charAt ( i ) ; t += \" . \" ; } return t ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = Integer . parseInt ( in . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . next ( ) ; s = interlace ( s ) ; System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + solve ( s , 0 ) ) ; } } }", "import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; public class Round1A { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( \" A . txt \" ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int c = 1 ; c <= T ; c ++ ) { String s = in . readLine ( ) ; int [ ] fl = new int [ s . length ( ) ] ; int nfl = 0 ; while ( nfl < s . length ( ) ) { char last = ( char ) ( ' A ' - 1 ) ; int firstL = - 1 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 0 && s . charAt ( i ) > last ) { last = s . charAt ( i ) ; firstL = i ; } } for ( int i = firstL ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 0 ) { nfl ++ ; if ( s . charAt ( i ) == last ) { fl [ i ] = 1 ; } else fl [ i ] = - 1 ; } } } String ans = \" \" ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 1 ) { ans = s . charAt ( i ) + ans ; } else if ( fl [ i ] == - 1 ) { ans = ans + s . charAt ( i ) ; } } pw . println ( \" Case ▁ # \" + c + \" : ▁ \" + ans ) ; } pw . close ( ) ; } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class a { public static void main ( String [ ] Args ) throws Exception { FS sc = new FS ( new File ( \" A - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( new File ( \" a . out \" ) ) ) ) ; int cc = 0 ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { out . printf ( \" Case ▁ # % d : ▁ \" , ++ cc ) ; String s = sc . next ( ) ; out . printf ( \" % s \" , foo ( s ) ) ; out . println ( \" \" ) ; } out . close ( ) ; } public static String foo ( String s ) throws Exception { if ( s . length ( ) == 0 ) return \" \" ; int last = ' A ' ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { last = Math . max ( last , s . charAt ( i ) ) ; } for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { if ( s . charAt ( i ) == last ) { return ( char ) ( last ) + foo ( s . substring ( 0 , i ) ) + s . substring ( i + 1 ) ; } } throw new Exception ( \" BANANAS \" ) ; } public static class FS { BufferedReader br ; StringTokenizer st ; FS ( InputStream in ) throws Exception { br = new BufferedReader ( new InputStreamReader ( in ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; } FS ( File in ) throws Exception { br = new BufferedReader ( new FileReader ( in ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; } String next ( ) throws Exception { if ( st . hasMoreTokens ( ) ) return st . nextToken ( ) ; st = new StringTokenizer ( br . readLine ( ) ) ; return next ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( next ( ) ) ; } } }" ]
[ "tt = int ( raw_input ( ) ) NEW_LINE for t in xrange ( 1 , tt + 1 ) : NEW_LINE INDENT s = raw_input ( ) . strip ( ) NEW_LINE ans = s [ 0 ] NEW_LINE signat = [ s [ 0 ] + s [ 0 ] ] NEW_LINE for i in xrange ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] < signat [ i - 1 ] [ 0 ] : NEW_LINE INDENT ans = ans + s [ i ] NEW_LINE signat . append ( signat [ i - 1 ] ) NEW_LINE DEDENT elif s [ i ] > signat [ i - 1 ] [ 0 ] : NEW_LINE INDENT ans = s [ i ] + ans NEW_LINE signat . append ( s [ i ] + signat [ i - 1 ] [ 0 ] ) NEW_LINE DEDENT elif s [ i ] < signat [ i - 1 ] [ 1 ] : NEW_LINE INDENT ans = ans + s [ i ] NEW_LINE signat . append ( signat [ i - 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = s [ i ] + ans NEW_LINE signat . append ( signat [ i - 1 ] ) NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( t , ans ) NEW_LINE DEDENT", "class Case : NEW_LINE INDENT def __init__ ( self , fin , fout , n ) : NEW_LINE INDENT self . _fin = fin NEW_LINE self . _fout = fout NEW_LINE self . _n = n NEW_LINE self . _line = None NEW_LINE DEDENT def readInt ( self ) : NEW_LINE INDENT if self . _line is None : NEW_LINE INDENT self . _line = self . _fin . readline ( ) . split ( \" ▁ \" ) NEW_LINE DEDENT result = int ( self . _line . pop ( 0 ) ) NEW_LINE if len ( self . _line ) == 0 : NEW_LINE INDENT self . _line = None NEW_LINE DEDENT return result NEW_LINE DEDENT def readLine ( self ) : NEW_LINE INDENT line = self . _fin . readline ( ) NEW_LINE if line [ - 1 ] == \" \\n \" : NEW_LINE INDENT return line [ : - 1 ] NEW_LINE DEDENT return line NEW_LINE DEDENT def output ( self , s ) : NEW_LINE INDENT if s is None : NEW_LINE INDENT return NEW_LINE DEDENT s = str ( s ) NEW_LINE if \" \\n \" in s : NEW_LINE INDENT self . _fout . write ( \" Case ▁ # % d : % s \" % ( self . _n , s ) ) NEW_LINE DEDENT else : NEW_LINE INDENT self . _fout . write ( \" Case ▁ # % d : ▁ % s \\n \" % ( self . _n , s ) ) NEW_LINE DEDENT DEDENT DEDENT def run ( fileName , solve ) : NEW_LINE INDENT fin = open ( fileName ) NEW_LINE fout = open ( fileName + \" . out \" , \" w \" ) NEW_LINE caseCount = int ( fin . readline ( ) ) NEW_LINE for i in range ( caseCount ) : NEW_LINE INDENT case = Case ( fin , fout , i + 1 ) NEW_LINE case . output ( solve ( case ) ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE def compute ( S ) : NEW_LINE INDENT if S == ' ' : NEW_LINE INDENT return ' ' NEW_LINE DEDENT x = max ( S ) NEW_LINE p = S . find ( x ) NEW_LINE y = compute ( S [ : p ] ) NEW_LINE z = filter ( lambda c : c != x , S [ p : ] ) NEW_LINE return ( x * ( len ( S ) - p - len ( z ) ) ) + y + z NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT S = sys . stdin . readline ( ) . strip ( ) NEW_LINE return S , NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE count = 1 NEW_LINE part = 0 NEW_LINE if len ( sys . argv ) == 3 : NEW_LINE INDENT part = int ( sys . argv [ 1 ] ) NEW_LINE count = int ( sys . argv [ 2 ] ) NEW_LINE DEDENT for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE if i * count >= part * T and i * count < ( part + 1 ) * T : NEW_LINE INDENT result = compute ( * data ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT DEDENT", "from sys import stdin , stdout NEW_LINE def solve ( test_id ) : NEW_LINE INDENT s = stdin . readline ( ) . strip ( ) NEW_LINE r = ' ' NEW_LINE for a in s : NEW_LINE INDENT if len ( r ) > 0 and r [ 0 ] <= a : NEW_LINE INDENT r = a + r NEW_LINE DEDENT else : NEW_LINE INDENT r = r + a NEW_LINE DEDENT DEDENT print ( \" Case ▁ # { } : ▁ { } \" . format ( test_id , r ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT t = int ( stdin . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT solve ( i + 1 ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "import sys NEW_LINE import itertools NEW_LINE def ans ( S ) : NEW_LINE INDENT ans = \" \" NEW_LINE for x in S : NEW_LINE INDENT if ( x + ans ) > ( ans + x ) : NEW_LINE INDENT ans = x + ans NEW_LINE DEDENT else : NEW_LINE INDENT ans = ans + x NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT s = sys . stdin . readline ( ) NEW_LINE T = int ( s ) NEW_LINE for i in xrange ( 0 , T ) : NEW_LINE INDENT S = sys . stdin . readline ( ) NEW_LINE print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( i + 1 , ans ( S . strip ( ) ) ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_16_32
[ "import java . util . * ; public class B { static Scanner in ; public static void main ( String [ ] args ) { in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . println ( \" Case ▁ # \" + C + \" : ▁ \" + solve ( ) ) ; } } public static String solve ( ) { String out = \" \" ; int B = in . nextInt ( ) ; long M = in . nextLong ( ) - 1 ; String binary = \" \" ; while ( M > 0 ) { binary += M % 2 ; M = M / 2 ; } System . err . println ( binary ) ; if ( binary . length ( ) > B - 2 ) { out = \" IMPOSSIBLE \" ; } else { out = \" POSSIBLE \" ; for ( int i = 0 ; i < B ; i ++ ) { String line = \" \" ; for ( int j = 0 ; j <= i ; j ++ ) { line += \"0\" ; } for ( int j = 0 ; j < B - 2 - i ; j ++ ) { line += \"1\" ; } if ( i < B - 1 ) { if ( i == 0 ) { line += \"1\" ; } else if ( i - 1 < binary . length ( ) ) { line += binary . charAt ( i - 1 ) ; } else { line += \"0\" ; } } out += \" \\n \" + line ; } } return out ; } }", "import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scanner = new Scanner ( System . in ) ; int t = scanner . nextInt ( ) ; for ( int x = 1 ; x <= t ; ++ x ) { int b = scanner . nextInt ( ) ; long m = scanner . nextLong ( ) ; System . out . print ( \" Case ▁ # \" + x + \" : ▁ \" ) ; if ( m > Math . pow ( 2 , b - 2 ) ) { System . out . print ( \" IMPOSSIBLE \\n \" ) ; continue ; } else System . out . print ( \" POSSIBLE \\n \" ) ; int [ ] [ ] slides = new int [ b ] [ b ] ; for ( int i = 0 ; i < b ; ++ i ) { for ( int j = i + 1 ; j < b ; ++ j ) { slides [ i ] [ j ] = 1 ; } } String str = Long . toBinaryString ( m - 1 ) + \" \" ; if ( str . equals ( \"0\" ) ) str = \" \" ; while ( str . length ( ) < b - 1 ) { str = \"0\" + str ; } str += \"1\" ; System . out . println ( str ) ; for ( int i = 1 ; i < b ; ++ i ) { for ( int j = 0 ; j < b ; ++ j ) { System . out . print ( slides [ i ] [ j ] ) ; } System . out . print ( \" \\n \" ) ; } } } }", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class B { public static void main ( String [ ] args ) { new B ( ) . run ( ) ; } BufferedReader br ; StringTokenizer in ; PrintWriter out ; public String nextToken ( ) throws IOException { while ( in == null || ! in . hasMoreTokens ( ) ) { in = new StringTokenizer ( br . readLine ( ) ) ; } return in . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } public void solve ( ) throws IOException { int n = nextInt ( ) ; long b = nextLong ( ) ; if ( b > 1L << ( n - 2 ) ) { out . println ( \" IMPOSSIBLE \" ) ; return ; } int [ ] [ ] a = new int [ n ] [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { a [ i ] [ j ] = 1 ; } } b -- ; a [ 0 ] [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( b % 2 == 1 ) { a [ 0 ] [ i ] = 1 ; } b /= 2 ; } out . println ( \" POSSIBLE \" ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { out . print ( a [ i ] [ j ] ) ; } out . println ( ) ; } } public void run ( ) { try { br = new BufferedReader ( new FileReader ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int t = nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { out . print ( String . format ( \" Case ▁ # % d : ▁ \" , i + 1 ) ) ; solve ( ) ; } out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }", "import java . util . * ; import java . io . * ; public class B { static int N ; static int ans ; public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { int B = input . nextInt ( ) ; long M = input . nextLong ( ) ; if ( M > ( 1L << ( B - 2 ) ) ) { System . out . printf ( \" Case ▁ # % d : ▁ IMPOSSIBLE \\n \" , n + 1 ) ; continue ; } boolean [ ] [ ] slides = new boolean [ B ] [ B ] ; if ( M == ( 1L << ( B - 2 ) ) ) { for ( int i = 0 ; i < B ; i ++ ) for ( int j = i + 1 ; j < B ; j ++ ) slides [ i ] [ j ] = true ; } for ( int i = 0 ; i + 1 < B ; i ++ ) for ( int j = i + 1 ; j + 1 < B ; j ++ ) slides [ i ] [ j ] = true ; for ( int i = 0 ; i + 2 < B ; i ++ ) if ( ( M & ( 1L << i ) ) > 0 ) slides [ i + 1 ] [ B - 1 ] = true ; System . out . printf ( \" Case ▁ # % d : ▁ POSSIBLE \\n \" , n + 1 ) ; for ( int i = 0 ; i < B ; i ++ ) { for ( int j = 0 ; j < B ; j ++ ) System . out . print ( slides [ i ] [ j ] ? '1' : '0' ) ; System . out . println ( ) ; } } } }", "package Round1 ; import java . io . * ; public class B { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" / Users / chao / Downloads / B - large . in \" ) ) ; FileWriter out = new FileWriter ( \" / Users / chao / Desktop / B - large . txt \" ) ; String s = in . readLine ( ) ; int m = Integer . parseInt ( s ) ; for ( int cases = 1 ; cases <= m ; cases ++ ) { String [ ] ss = in . readLine ( ) . split ( \" ▁ \" ) ; int B = Integer . parseInt ( ss [ 0 ] ) ; long M = Long . parseLong ( ss [ 1 ] ) ; out . write ( \" Case ▁ # \" + cases + \" : ▁ \" ) ; int n = B ; long max = pow ( B - 2 ) ; if ( max >= M ) { out . write ( \" POSSIBLE \\n \" ) ; int [ ] [ ] map = new int [ n ] [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { map [ i ] [ j ] = 1 ; } } for ( int k = 1 ; k < n ; k ++ ) { if ( k != n - 1 ) max = max / 2 ; if ( max <= M ) { M -= max ; map [ 0 ] [ k ] = 1 ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { out . write ( \" \" + map [ i ] [ j ] ) ; } out . write ( \" \\n \" ) ; } } else { out . write ( \" IMPOSSIBLE \\n \" ) ; } } in . close ( ) ; out . flush ( ) ; out . close ( ) ; } private static long pow ( int n ) { long x = 1 ; for ( int i = 0 ; i < n ; i ++ ) { x *= 2 ; } return x ; } }" ]
[ "from sys import stdin NEW_LINE from string import zfill NEW_LINE def each_case ( B , M ) : NEW_LINE INDENT if M < 2 ** ( B - 2 ) : NEW_LINE INDENT print zfill ( bin ( M ) [ 2 : ] , B - 1 ) + '0' NEW_LINE for i in xrange ( B - 1 ) : NEW_LINE INDENT print '0' * ( i + 2 ) + '1' * ( B - i - 2 ) NEW_LINE DEDENT DEDENT elif M == 2 ** ( B - 2 ) : NEW_LINE INDENT print '0' + '1' * ( B - 1 ) NEW_LINE for i in xrange ( B - 1 ) : NEW_LINE INDENT print '0' * ( i + 2 ) + '1' * ( B - i - 2 ) NEW_LINE DEDENT DEDENT DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT B , M = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( t , ' POSSIBLE ' if ( M <= 2 ** ( B - 2 ) ) else ' IMPOSSIBLE ' ) NEW_LINE each_case ( B , M ) NEW_LINE DEDENT", "def solve ( b , m ) : NEW_LINE INDENT if m > 2 ** ( b - 2 ) : NEW_LINE INDENT print ( \" IMPOSSIBLE \" ) NEW_LINE return NEW_LINE DEDENT print ( \" POSSIBLE \" ) NEW_LINE if m == 2 ** ( b - 2 ) : NEW_LINE INDENT print ( \"0\" + \"1\" * ( b - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT l = [ ( m >> i ) & 1 for i in range ( b - 2 ) ] NEW_LINE print ( \"0\" + \" \" . join ( map ( str , reversed ( l ) ) ) + \"0\" ) NEW_LINE DEDENT for i in range ( 1 , b ) : NEW_LINE INDENT print ( \"0\" * ( i + 1 ) + \"1\" * ( b - i - 1 ) ) NEW_LINE DEDENT DEDENT t = int ( input ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT print ( \" Case ▁ # \" + str ( i + 1 ) + \" : \" , end = \" ▁ \" ) NEW_LINE b , m = map ( int , input ( ) . split ( ) ) NEW_LINE solve ( b , m ) NEW_LINE DEDENT", "import sys NEW_LINE def solve_test ( inp ) : NEW_LINE INDENT B , M = map ( int , inp . readline ( ) . split ( ) ) NEW_LINE if M > 2 ** ( B - 2 ) : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT if M == 2 ** ( B - 2 ) : NEW_LINE INDENT first = '0' + '1' * ( B - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT first = '0' + bin ( M ) [ 2 : ] . zfill ( B - 2 ) + '0' NEW_LINE DEDENT print ( bin ( M ) , bin ( M ) [ 2 : ] . zfill ( B - 2 ) ) NEW_LINE lines = [ '0' * i + '1' * ( B - i ) for i in range ( 2 , B + 1 ) ] NEW_LINE return ' POSSIBLE \\n ' + ' \\n ' . join ( [ first ] + lines ) NEW_LINE DEDENT def solve_dumb ( inp ) : NEW_LINE INDENT return '1' NEW_LINE DEDENT inp = open ( sys . argv [ 1 ] ) NEW_LINE inp_dumb = open ( sys . argv [ 1 ] ) NEW_LINE out = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . out ' , ' w ' ) NEW_LINE out_dumb = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . dumb . out ' , ' w ' ) NEW_LINE n_tests = int ( inp . readline ( ) ) NEW_LINE for i in range ( n_tests ) : NEW_LINE INDENT ans = solve_test ( inp ) NEW_LINE print ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) + ans , file = out ) NEW_LINE ans_dumb = solve_dumb ( inp_dumb ) NEW_LINE print ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) + ans_dumb , file = out_dumb ) NEW_LINE if ans != ans_dumb : NEW_LINE INDENT print ( ' Wrong ' , i + 1 , file = sys . stderr ) NEW_LINE DEDENT DEDENT out . close ( ) NEW_LINE", "f = open ( ' large2 . in ' ) NEW_LINE T = int ( f . readline ( ) . strip ( ) ) NEW_LINE for k in range ( T ) : NEW_LINE INDENT case = f . readline ( ) . split ( ) NEW_LINE B = int ( case [ 0 ] ) NEW_LINE M = int ( case [ 1 ] ) NEW_LINE if ( M > ( 2 ** ( B - 2 ) ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ IMPOSSIBLE \" % ( k + 1 ) NEW_LINE continue NEW_LINE DEDENT print \" Case ▁ # % d : ▁ POSSIBLE \" % ( k + 1 ) NEW_LINE matrix = [ ] NEW_LINE for i in range ( B ) : NEW_LINE INDENT oneLine = [ ] NEW_LINE for j in range ( B ) : NEW_LINE INDENT oneLine . append ( \"0\" ) NEW_LINE DEDENT matrix . append ( oneLine ) NEW_LINE DEDENT if ( M > 0 ) : NEW_LINE INDENT M -= 1 NEW_LINE matrix [ 0 ] [ B - 1 ] = \"1\" NEW_LINE DEDENT totalPossible = 1 NEW_LINE lastIdx = 1 NEW_LINE for i in range ( B - 2 ) : NEW_LINE INDENT currentIdx = B - i - 2 NEW_LINE if ( M == 0 ) : NEW_LINE INDENT lastIdx = currentIdx + 1 NEW_LINE break NEW_LINE DEDENT if ( M >= totalPossible ) : NEW_LINE INDENT M -= totalPossible NEW_LINE totalPossible *= 2 NEW_LINE otherIdx = currentIdx NEW_LINE while ( otherIdx < B - 1 ) : NEW_LINE INDENT otherIdx += 1 NEW_LINE matrix [ currentIdx ] [ otherIdx ] = \"1\" NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT otherIdx = currentIdx NEW_LINE while ( otherIdx < B - 1 ) : NEW_LINE INDENT otherIdx += 1 NEW_LINE totalPossible /= 2 NEW_LINE if ( totalPossible == 0 ) : NEW_LINE INDENT totalPossible = 1 NEW_LINE DEDENT if ( M >= totalPossible ) : NEW_LINE INDENT M -= totalPossible NEW_LINE matrix [ currentIdx ] [ otherIdx ] = \"1\" NEW_LINE DEDENT DEDENT lastIdx = currentIdx NEW_LINE break NEW_LINE DEDENT DEDENT while ( lastIdx < B - 1 ) : NEW_LINE INDENT matrix [ 0 ] [ lastIdx ] = \"1\" NEW_LINE lastIdx += 1 NEW_LINE DEDENT for line in matrix : NEW_LINE INDENT print \" \" . join ( line ) NEW_LINE DEDENT DEDENT", "def f ( b , m ) : NEW_LINE INDENT if m > ( 1 << ( b - 2 ) ) : NEW_LINE INDENT return [ ] NEW_LINE DEDENT x = [ [ 1 if ( ( i > j ) and ( i < ( b - 1 ) ) ) else 0 for i in xrange ( b ) ] for j in xrange ( b ) ] NEW_LINE m -= 1 NEW_LINE x [ 0 ] [ b - 1 ] = 1 NEW_LINE for i in xrange ( 1 , b - 1 ) : NEW_LINE INDENT if ( m >> ( i - 1 ) ) & 1 : NEW_LINE INDENT x [ i ] [ b - 1 ] = 1 NEW_LINE DEDENT DEDENT return x NEW_LINE DEDENT from sys import stdin NEW_LINE def getint ( ) : NEW_LINE INDENT return int ( stdin . readline ( ) ) NEW_LINE DEDENT def getints ( ) : NEW_LINE INDENT return tuple ( int ( z ) for z in stdin . readline ( ) . split ( ) ) NEW_LINE DEDENT for cn in xrange ( 1 , 1 + getint ( ) ) : NEW_LINE INDENT ( b , m ) = getints ( ) NEW_LINE sol = f ( b , m ) NEW_LINE if len ( sol ) == 0 : NEW_LINE INDENT output = \" IMPOSSIBLE \" NEW_LINE DEDENT else : NEW_LINE INDENT output = \" POSSIBLE \\n \" + \" \\n \" . join ( \" \" . join ( str ( k ) for k in row ) for row in sol ) NEW_LINE DEDENT print \" Case ▁ # { } : ▁ { } \" . format ( cn , output ) NEW_LINE DEDENT" ]
codejam_16_51
[ "import java . io . * ; import java . util . * ; public class teachingassistant { private static InputReader in ; private static PrintWriter out ; public static boolean SUBMIT = true ; public static final String NAME = \" A - large \" ; private static void main2 ( ) throws IOException { char [ ] c = in . next ( ) . toCharArray ( ) ; int n = c . length ; char [ ] stack = new char [ n ] ; int idx = 0 ; int need = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( idx > 0 && stack [ idx - 1 ] == c [ i ] ) { idx -- ; continue ; } if ( i + idx >= n ) { need ++ ; idx -- ; } else { stack [ idx ++ ] = c [ i ] ; } } out . println ( ( n - need ) * 5 ) ; } public static void main ( String [ ] args ) throws IOException { if ( SUBMIT ) { in = new InputReader ( new FileInputStream ( new File ( NAME + \" . in \" ) ) ) ; out = new PrintWriter ( new BufferedWriter ( new FileWriter ( NAME + \" . out \" ) ) ) ; } else { in = new InputReader ( System . in ) ; out = new PrintWriter ( System . out , true ) ; } int numCases = in . nextInt ( ) ; for ( int test = 1 ; test <= numCases ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; main2 ( ) ; } out . close ( ) ; System . exit ( 0 ) ; } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }", "package cj2016 . r3 ; import java . io . * ; import java . util . * ; public class A { Scanner sc ; PrintWriter pw ; char [ ] c ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : \" A - large \" ; try { new A ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + \" . in \" ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + \" . out \" ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; System . out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; solve ( ) ; } System . out . println ( \" Finished . \" ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { c = sc . next ( ) . toCharArray ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } void solve ( ) { int N = c . length ; int score = 0 ; LinkedList < Character > stack = new LinkedList < Character > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! stack . isEmpty ( ) && stack . peek ( ) == c [ i ] ) { stack . pop ( ) ; score += 10 ; } else { stack . push ( c [ i ] ) ; } } println ( score + stack . size ( ) / 2 * 5 ) ; } }", "import java . io . OutputStream ; import java . io . FilenameFilter ; import java . util . Locale ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . FileInputStream ; import java . io . File ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . LinkedList ; public class Main { public static void main ( String [ ] args ) { Locale . setDefault ( Locale . US ) ; InputStream inputStream ; try { final String regex = \" A - ( small | large ) . * [ . ] in \" ; File directory = new File ( \" . \" ) ; File [ ] candidates = directory . listFiles ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return name . matches ( regex ) ; } } ) ; File toRun = null ; for ( File candidate : candidates ) { if ( toRun == null || candidate . lastModified ( ) > toRun . lastModified ( ) ) toRun = candidate ; } inputStream = new FileInputStream ( toRun ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } OutputStream outputStream ; try { outputStream = new FileOutputStream ( \" a . out \" ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; int testCount = Integer . parseInt ( in . next ( ) ) ; for ( int i = 1 ; i <= testCount ; i ++ ) solver . solve ( i , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String s = in . next ( ) ; int pairs = 0 ; LinkedList < Character > list = new LinkedList < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char next = s . charAt ( i ) ; char last = list . size ( ) > 0 ? list . peekLast ( ) : ' x ' ; if ( last == next ) { pairs ++ ; list . pollLast ( ) ; } else { list . add ( next ) ; } } out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , testNumber , pairs * 10 + 5 * list . size ( ) / 2 ) ; } } }", "import java . io . * ; import java . util . * ; public class Assistant { public void solve ( ) { String s = in . nextToken ( ) ; char [ ] stack = new char [ s . length ( ) ] ; int size = 0 ; for ( char c : s . toCharArray ( ) ) { if ( size > 0 && c == stack [ size - 1 ] ) { size -- ; } else { stack [ size ++ ] = c ; } } out . println ( 5 * ( size / 2 ) + 10 * ( s . length ( ) - size ) / 2 ) ; } public void run ( ) { try { in = new FastScanner ( \" input . txt \" ) ; out = new PrintWriter ( \" output . txt \" ) ; int tests = in . nextInt ( ) ; for ( int i = 1 ; i <= tests ; i ++ ) { long time = System . currentTimeMillis ( ) ; out . printf ( \" Case ▁ # % d : ▁ \" , i ) ; solve ( ) ; System . err . printf ( \" Solved ▁ case ▁ # % d ▁ in ▁ % d ▁ ms \\n \" , i , System . currentTimeMillis ( ) - time ) ; } out . close ( ) ; } catch ( FileNotFoundException e ) { } } FastScanner in ; PrintWriter out ; class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner ( String fileName ) { try { br = new BufferedReader ( new FileReader ( fileName ) ) ; } catch ( FileNotFoundException e ) { } } String nextToken ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } } public static void main ( String [ ] args ) { new Assistant ( ) . run ( ) ; } }", "package gcj . gcj2016 . round3 ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . Stack ; public class A { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int t = in . nextInt ( ) ; for ( int cs = 1 ; cs <= t ; cs ++ ) { char [ ] c = in . next ( ) . toCharArray ( ) ; out . println ( String . format ( \" Case ▁ # % d : ▁ % d \" , cs , solve ( c ) ) ) ; } out . flush ( ) ; } private static int solve ( char [ ] mood ) { int n = mood . length ; int score = 0 ; int code = 0 ; int jam = 0 ; Stack < Character > stk = new Stack < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( stk . size ( ) == 0 ) { stk . push ( mood [ i ] ) ; } else { if ( stk . peek ( ) == mood [ i ] ) { stk . pop ( ) ; score += 10 ; } else { int pool = stk . size ( ) ; int left = n - i ; if ( pool + 1 <= left - 1 ) { stk . push ( mood [ i ] ) ; } else { stk . pop ( ) ; score += 5 ; } } } } return score ; } }" ]
[ "def solve ( seq ) : NEW_LINE INDENT memo = { } NEW_LINE def opt ( lo , hi ) : NEW_LINE INDENT if ( lo , hi ) in memo : NEW_LINE INDENT return memo [ lo , hi ] NEW_LINE DEDENT if lo == hi : NEW_LINE INDENT result = 0 NEW_LINE DEDENT else : NEW_LINE INDENT best = None NEW_LINE if hi == len ( seq ) : NEW_LINE INDENT o1 = opt ( lo + 1 , hi ) NEW_LINE if o1 is not None : NEW_LINE INDENT best = max ( best , o1 ) NEW_LINE DEDENT DEDENT for i in xrange ( lo + 1 , hi ) : NEW_LINE INDENT o1 = opt ( lo + 1 , i ) NEW_LINE o2 = opt ( i + 1 , hi ) NEW_LINE if o1 is not None and o2 is not None : NEW_LINE INDENT best = max ( best , o1 + ( 10 if seq [ lo ] == seq [ i ] else 5 ) + o2 ) NEW_LINE DEDENT DEDENT result = best NEW_LINE DEDENT memo [ lo , hi ] = result NEW_LINE return result NEW_LINE DEDENT return opt ( 0 , len ( seq ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE fp = open ( sys . argv [ 1 ] ) NEW_LINE def readline ( ) : NEW_LINE INDENT return fp . readline ( ) . strip ( ) NEW_LINE DEDENT num_cases = int ( readline ( ) ) NEW_LINE for i in xrange ( num_cases ) : NEW_LINE INDENT seq = readline ( ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , solve ( seq ) ) NEW_LINE DEDENT DEDENT", "import sys , math , random , operator NEW_LINE from string import ascii_lowercase NEW_LINE from string import ascii_uppercase NEW_LINE from fractions import Fraction , gcd NEW_LINE from decimal import Decimal , getcontext NEW_LINE from itertools import product , permutations , combinations NEW_LINE from Queue import Queue , PriorityQueue NEW_LINE from collections import deque , defaultdict , Counter NEW_LINE getcontext ( ) . prec = 100 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE INF = float ( \" + inf \" ) NEW_LINE if sys . subversion [ 0 ] != \" CPython \" : NEW_LINE INDENT raw_input = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE DEDENT pr = lambda * args : sys . stdout . write ( \" ▁ \" . join ( str ( x ) for x in args ) + \" \\n \" ) NEW_LINE epr = lambda * args : sys . stderr . write ( \" ▁ \" . join ( str ( x ) for x in args ) + \" \\n \" ) NEW_LINE die = lambda * args : pr ( * args ) ^ exit ( 0 ) NEW_LINE read_str = raw_input NEW_LINE read_strs = lambda : raw_input ( ) . split ( ) NEW_LINE read_int = lambda : int ( raw_input ( ) ) NEW_LINE read_ints = lambda : map ( int , raw_input ( ) . split ( ) ) NEW_LINE read_float = lambda : float ( raw_input ( ) ) NEW_LINE read_floats = lambda : map ( float , raw_input ( ) . split ( ) ) NEW_LINE def solve_brute ( ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT def solve_fast ( s ) : NEW_LINE INDENT st = [ ] NEW_LINE ans = 0 NEW_LINE for c in s : NEW_LINE INDENT if st and st [ - 1 ] == c : NEW_LINE INDENT st . pop ( ) NEW_LINE ans += 10 NEW_LINE DEDENT else : NEW_LINE INDENT st . append ( c ) NEW_LINE DEDENT DEDENT ans += ( len ( st ) // 2 ) * 5 NEW_LINE return ans NEW_LINE DEDENT t = read_int ( ) NEW_LINE for t in xrange ( 1 , t + 1 ) : NEW_LINE INDENT s = read_str ( ) NEW_LINE ans_fast = solve_fast ( s ) NEW_LINE if 0 : NEW_LINE INDENT ans_brute = solve_brute ( s ) NEW_LINE if ans_fast != ans_brute : NEW_LINE INDENT print \" BAD \" , ans_brute , ans_fast NEW_LINE quit ( ) NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( t , ans_fast ) NEW_LINE DEDENT", "import os , inspect NEW_LINE problemName = ' A ' NEW_LINE testCase = ' large ' NEW_LINE attempt = 0 NEW_LINE def solution ( preferences ) : NEW_LINE INDENT totalTaken = 0 NEW_LINE holding = [ ] NEW_LINE points = 0 NEW_LINE for c in preferences : NEW_LINE INDENT if len ( holding ) == 0 or holding [ - 1 ] != c : NEW_LINE INDENT if totalTaken == len ( preferences ) / 2 : NEW_LINE INDENT holding . pop ( ) NEW_LINE points += 5 NEW_LINE DEDENT else : NEW_LINE INDENT holding . append ( c ) NEW_LINE totalTaken += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT holding . pop ( ) NEW_LINE points += 10 NEW_LINE DEDENT DEDENT return points NEW_LINE DEDENT currentDir = os . path . dirname ( os . path . abspath ( inspect . getfile ( inspect . currentframe ( ) ) ) ) NEW_LINE if testCase in [ ' large ' , ' example ' ] : NEW_LINE INDENT inputString = problemName + ( ' - % s ' % testCase ) NEW_LINE outputString = problemName + ( ' - % s ' % testCase ) NEW_LINE DEDENT else : NEW_LINE INDENT inputString = problemName + ( ' - % s - attempt % d ' % ( testCase , attempt ) ) NEW_LINE outputString = problemName + ( ' - % s ' % testCase ) NEW_LINE DEDENT inFile = os . path . join ( currentDir , ' inputfiles ' , ' % s . in ' % inputString ) NEW_LINE outFile = os . path . join ( currentDir , ' outputfiles ' , ' % s . out ' % outputString ) NEW_LINE if os . path . exists ( outFile ) : NEW_LINE INDENT os . remove ( outFile ) NEW_LINE DEDENT with open ( inFile , ' r ' ) as inputfile : NEW_LINE INDENT numberOfCases = int ( inputfile . readline ( ) ) NEW_LINE for case in xrange ( 1 , numberOfCases + 1 ) : NEW_LINE INDENT result = solution ( inputfile . readline ( ) . strip ( ) ) NEW_LINE with open ( outFile , ' a ' ) as f : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ % d \\n ' % ( case , result ) ) NEW_LINE DEDENT DEDENT DEDENT", "def initialize_solver ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT def solve_testcase ( ) : NEW_LINE INDENT s = read ( False , str ) NEW_LINE c1 = 0 NEW_LINE c2 = 0 NEW_LINE j1 = 0 NEW_LINE j2 = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT if s [ i ] == \" C \" : NEW_LINE INDENT c1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT j1 += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if s [ i ] == \" C \" : NEW_LINE INDENT c2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT j2 += 1 NEW_LINE DEDENT DEDENT DEDENT return 10 * ( min ( [ c1 , c2 ] ) + min ( [ j1 , j2 ] ) ) + 5 * abs ( c1 - c2 ) NEW_LINE DEDENT output_format = \" Case ▁ # % d : ▁ \" NEW_LINE filename = input ( ) . strip ( ) NEW_LINE sfile = None NEW_LINE tfile = None NEW_LINE if filename != \" \" : NEW_LINE INDENT sfile = open ( filename + \" . in \" , \" r \" ) NEW_LINE sfile . seek ( 0 ) NEW_LINE tfile = open ( filename + \" . out \" , \" w \" ) NEW_LINE DEDENT def read ( split = True , rettype = int ) : NEW_LINE INDENT if sfile : NEW_LINE INDENT input_line = sfile . readline ( ) . strip ( ) NEW_LINE DEDENT else : NEW_LINE INDENT input_line = input ( ) . strip ( ) NEW_LINE DEDENT if split : NEW_LINE INDENT return list ( map ( rettype , input_line . split ( ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return rettype ( input_line ) NEW_LINE DEDENT DEDENT def write ( s = \" \\n \" ) : NEW_LINE INDENT if s is None : s = \" \" NEW_LINE if isinstance ( s , list ) : s = \" ▁ \" . join ( map ( str , s ) ) NEW_LINE s = str ( s ) NEW_LINE if tfile : NEW_LINE INDENT tfile . write ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s , end = \" \" ) NEW_LINE DEDENT DEDENT if output_format == 0 : NEW_LINE INDENT solve_testcase ( ) NEW_LINE DEDENT else : NEW_LINE INDENT initialize_solver ( ) NEW_LINE total_cases = read ( split = False ) NEW_LINE for case_number in range ( 1 , total_cases + 1 ) : NEW_LINE INDENT write ( output_format . replace ( \" % d \" , str ( case_number ) ) ) NEW_LINE write ( solve_testcase ( ) ) NEW_LINE write ( \" \\n \" ) NEW_LINE DEDENT DEDENT if tfile is not None : tfile . close ( ) NEW_LINE", "T = input ( ) NEW_LINE from collections import defaultdict NEW_LINE def solve ( S ) : NEW_LINE INDENT dp = [ { ' ' : 0 } ] NEW_LINE for i , ch in enumerate ( S ) : NEW_LINE INDENT last = dp [ - 1 ] NEW_LINE nxt = defaultdict ( int ) NEW_LINE for pre , val in last . iteritems ( ) : NEW_LINE INDENT if not ( len ( S ) - i < len ( pre ) ) : NEW_LINE INDENT st = pre + ch NEW_LINE nxt [ st ] = max ( nxt [ st ] , val ) NEW_LINE DEDENT if pre : NEW_LINE INDENT sc = val + ( 10 if ch == pre [ - 1 ] else 5 ) NEW_LINE st = pre [ : - 1 ] NEW_LINE nxt [ st ] = max ( nxt [ st ] , sc ) NEW_LINE DEDENT DEDENT dp . append ( nxt ) NEW_LINE DEDENT return max ( dp [ - 1 ] . values ( ) ) NEW_LINE DEDENT for i in range ( 1 , T + 1 ) : NEW_LINE INDENT S = raw_input ( ) . strip ( ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( i , solve ( S ) ) NEW_LINE DEDENT" ]
codejam_15_22
[ "import java . util . * ; public class Main { public static void main ( String args [ ] ) { ( new Main ( ) ) . solve ( ) ; } void solve ( ) { Scanner cin = new Scanner ( System . in ) ; int T = cin . nextInt ( ) ; for ( int C = 1 ; C <= T ; ++ C ) { int Row = cin . nextInt ( ) ; int Col = cin . nextInt ( ) ; int Num = cin . nextInt ( ) ; System . out . println ( \" Case ▁ # \" + C + \" : ▁ \" + solve ( Row , Col , Num ) ) ; } } int solve ( int R , int C , int N ) { List < Integer > all = new ArrayList < Integer > ( ) ; List < Integer > all2 = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < R ; ++ i ) { for ( int j = 0 ; j < C ; ++ j ) { int wall = 0 ; if ( i > 0 ) { ++ wall ; } if ( j > 0 ) { ++ wall ; } if ( i + 1 < R ) { ++ wall ; } if ( j + 1 < C ) { ++ wall ; } if ( ( i + j ) % 2 == 0 ) { all . add ( wall ) ; } else { all2 . add ( wall ) ; } } } int ret = 0 ; Collections . sort ( all ) ; for ( int i = 0 ; i < all . size ( ) - ( R * C - N ) ; ++ i ) { ret += all . get ( i ) ; } int ret2 = 0 ; Collections . sort ( all2 ) ; for ( int i = 0 ; i < all2 . size ( ) - ( R * C - N ) ; ++ i ) { ret2 += all2 . get ( i ) ; } return Math . min ( ret , ret2 ) ; } }", "import java . util . * ; public class B { String solve ( Scanner sc ) { int R = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < 1 << ( R * C ) ; i ++ ) { if ( Integer . bitCount ( i ) == N ) { int s = 0 ; boolean [ ] [ ] b = new boolean [ R ] [ C ] ; for ( int r = 0 ; r < R ; r ++ ) { for ( int c = 0 ; c < C ; c ++ ) { b [ r ] [ c ] = ( i & ( 1 << ( r * C + c ) ) ) != 0 ; if ( b [ r ] [ c ] ) { if ( r > 0 && b [ r - 1 ] [ c ] ) { s ++ ; } if ( c > 0 && b [ r ] [ c - 1 ] ) { s ++ ; } } } } min = Math . min ( min , s ) ; } } return \" \" + min ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int cs = 1 ; cs <= T ; cs ++ ) { String res = new B ( ) . solve ( sc ) ; System . out . println ( \" Case ▁ # \" + cs + \" : ▁ \" + res ) ; } sc . close ( ) ; } }", "import java . util . * ; public class NN { static Scanner sc = new Scanner ( System . in ) ; static int k ; { k = sc . nextInt ( ) ; for ( int kk = 1 ; kk <= k ; kk ++ ) { System . out . print ( \" Case ▁ # \" + kk + \" : ▁ \" ) ; int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int a = val ( r , c , n ) ; System . out . println ( val ( r , c , n ) ) ; } } static int thing ( int r , int c , int n , int basegood , int corn , int edg ) { if ( n <= basegood ) return 0 ; n -= basegood ; if ( n <= corn ) return 2 * n ; int result = 2 * corn ; n -= corn ; if ( n <= edg ) return result + 3 * n ; result += 3 * edg ; n -= edg ; return result + 4 * n ; } static int special ( int size , int n ) { if ( size % 2 == 0 ) { if ( n <= size / 2 ) return 0 ; return 2 * ( n - size / 2 ) - 1 ; } else { if ( n <= size / 2 + 1 ) return 0 ; return 2 * ( n - size / 2 - 1 ) ; } } static int val ( int r , int c , int n ) { if ( r == 1 ) return special ( c , n ) ; if ( c == 1 ) return special ( r , n ) ; if ( ( r * c ) % 2 == 0 ) return thing ( r , c , n , r * c / 2 , 2 , r + c - 4 ) ; else return Math . min ( thing ( r , c , n , r * c / 2 + 1 , 0 , r + c - 2 ) , thing ( r , c , n , r * c / 2 , 4 , r + c - 6 ) ) ; } public static void main ( String [ ] args ) { new NN ( ) ; } }" ]
[ "from sys import stdin , stderr NEW_LINE from math import log10 NEW_LINE def solve ( R , C , N ) : NEW_LINE INDENT if R == 1 or C == 1 : NEW_LINE INDENT L = R * C NEW_LINE if L % 2 == 1 : NEW_LINE INDENT return max ( N - L / 2 - 1 , 0 ) * 2 NEW_LINE DEDENT else : NEW_LINE INDENT if N <= L / 2 : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 + ( N - L / 2 - 1 ) * 2 NEW_LINE DEDENT DEDENT DEDENT if ( R * C ) % 2 == 0 : NEW_LINE INDENT if N <= R * C / 2 : return 0 NEW_LINE inner = ( R - 2 ) * ( C - 2 ) / 2 NEW_LINE edge = R + C - 4 NEW_LINE conner = 2 NEW_LINE DEDENT else : NEW_LINE INDENT if N <= ( R * C + 1 ) / 2 : return 0 NEW_LINE if N <= ( R * C + 1 ) / 2 + 1 : return 3 NEW_LINE inner = ( ( R - 2 ) * ( C - 2 ) + 1 ) / 2 NEW_LINE edge = R + C - 6 NEW_LINE conner = 4 NEW_LINE pass NEW_LINE DEDENT ret = ( R - 1 ) * C + ( C - 1 ) * R NEW_LINE n = R * C - N NEW_LINE if n <= inner : return ret - n * 4 NEW_LINE ret -= inner * 4 NEW_LINE n -= inner NEW_LINE if n <= edge : return ret - n * 3 NEW_LINE ret -= edge * 3 NEW_LINE n -= edge NEW_LINE return ret - n * 2 NEW_LINE DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT R , C , N = ( int ( wd ) for wd in stdin . readline ( ) . split ( ) ) NEW_LINE print \" Case ▁ # % i : \" % ( t + 1 ) , NEW_LINE print solve ( R , C , N ) NEW_LINE DEDENT", "import sys NEW_LINE infile = None NEW_LINE outfile = None NEW_LINE def readline ( ) : NEW_LINE INDENT x = infile . readline ( ) NEW_LINE if len ( x ) > 0 and x [ - 1 ] == ' \\n ' : NEW_LINE INDENT return x [ : - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return x NEW_LINE DEDENT DEDENT def readint ( ) : NEW_LINE INDENT return int ( readline ( ) ) NEW_LINE DEDENT def readfloat ( ) : NEW_LINE INDENT return float ( readline ( ) ) NEW_LINE DEDENT def readints ( ) : NEW_LINE INDENT return [ int ( x ) for x in readline ( ) . split ( ) ] NEW_LINE DEDENT def readfloats ( ) : NEW_LINE INDENT return [ float ( x ) for x in readline ( ) . split ( ) ] NEW_LINE DEDENT def writeline ( x ) : NEW_LINE INDENT outfile . write ( x + ' \\n ' ) NEW_LINE DEDENT def writecase ( casenum , answer ) : NEW_LINE INDENT outfile . write ( ' Case ▁ # { : d } : ▁ { } \\n ' . format ( casenum , answer ) ) NEW_LINE DEDENT def run ( main ) : NEW_LINE INDENT global infile , outfile NEW_LINE args = sys . argv NEW_LINE infile = sys . stdin NEW_LINE outfile = sys . stdout NEW_LINE if len ( args ) == 2 : NEW_LINE INDENT if args [ 1 ] != ' - ' : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE if args [ 1 ] . endswith ( ' . in ' ) : NEW_LINE INDENT outfile = open ( args [ 1 ] [ : - 3 ] + ' . out ' , ' w ' ) NEW_LINE DEDENT DEDENT DEDENT elif len ( args ) == 3 : NEW_LINE INDENT if args [ 1 ] != ' - ' : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE DEDENT if args [ 2 ] != ' - ' : NEW_LINE INDENT outfile = open ( args [ 2 ] , ' w ' ) NEW_LINE DEDENT DEDENT elif len ( args ) > 3 : NEW_LINE INDENT print ( \" Expected ▁ 0 , ▁ 1 , ▁ or ▁ 2 ▁ arguments , ▁ not ▁ { } \" . format ( len ( args ) - 1 ) ) NEW_LINE print ( args ) NEW_LINE return NEW_LINE DEDENT t = readint ( ) NEW_LINE for casenum in range ( 1 , t + 1 ) : NEW_LINE INDENT main ( casenum ) NEW_LINE DEDENT if infile is not sys . stdin : NEW_LINE INDENT infile . close ( ) NEW_LINE DEDENT if outfile is not sys . stdout : NEW_LINE INDENT outfile . close ( ) NEW_LINE DEDENT DEDENT", "def run ( x , r , c , k ) : NEW_LINE INDENT a = [ [ 0 ] * c for i in range ( r ) ] NEW_LINE for i in range ( r ) : NEW_LINE INDENT for j in range ( ( i & 1 ) ^ x , c , 2 ) : NEW_LINE INDENT if i > 0 : NEW_LINE INDENT a [ i - 1 ] [ j ] += 1 NEW_LINE DEDENT if j > 0 : NEW_LINE INDENT a [ i ] [ j - 1 ] += 1 NEW_LINE DEDENT if i + 1 < r : NEW_LINE INDENT a [ i + 1 ] [ j ] += 1 NEW_LINE DEDENT if j + 1 < c : NEW_LINE INDENT a [ i ] [ j + 1 ] += 1 NEW_LINE DEDENT DEDENT DEDENT b = [ j for i in a for j in i ] NEW_LINE b . sort ( ) NEW_LINE return sum ( b [ : k ] ) NEW_LINE DEDENT n = input ( ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT r , c , k = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE ans = min ( run ( 0 , r , c , k ) , run ( 1 , r , c , k ) ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i , ans ) NEW_LINE DEDENT", "from functools import * NEW_LINE inf = open ( ' B - large . in ' ) NEW_LINE ouf = open ( ' B - large . out ' , ' w ' ) NEW_LINE input = lambda : inf . readline ( ) . strip ( ) NEW_LINE print = partial ( print , file = ouf ) NEW_LINE def solve ( ) : NEW_LINE INDENT r , c , n = map ( int , input ( ) . split ( ) ) NEW_LINE if r > c : NEW_LINE INDENT r , c = c , r NEW_LINE DEDENT if n <= ( r * c ) // 2 + ( r * c ) % 2 : NEW_LINE INDENT print ( 0 ) NEW_LINE return NEW_LINE DEDENT free = r * c - n NEW_LINE cur = ( r - 1 ) * c + ( c - 1 ) * r NEW_LINE if r == 1 : NEW_LINE INDENT if c % 2 == 0 : NEW_LINE INDENT ways = [ [ 2 ] * ( c // 2 - 1 ) + [ 1 ] ] NEW_LINE DEDENT else : NEW_LINE INDENT ways = [ [ 2 ] * ( c // 2 ) , [ 2 ] * ( c // 2 - 1 ) + [ 1 , 1 ] ] NEW_LINE DEDENT DEDENT elif r * c % 2 == 0 : NEW_LINE INDENT ways = [ [ 4 ] * ( ( r - 2 ) * ( c - 2 ) // 2 ) + [ 3 ] * ( r - 2 + c - 2 ) + [ 2 , 2 ] ] NEW_LINE DEDENT else : NEW_LINE INDENT ways = [ [ 4 ] * ( ( r - 2 ) * ( c - 2 ) // 2 + 1 ) + [ 3 ] * ( r - 3 + c - 3 ) + [ 2 ] * 4 , [ 4 ] * ( ( r - 2 ) * ( c - 2 ) // 2 ) + [ 3 ] * ( r - 1 + c - 1 ) , ] NEW_LINE DEDENT print ( cur - max ( sum ( way [ : free ] ) for way in ways ) ) NEW_LINE DEDENT tests = int ( input ( ) ) NEW_LINE for z in range ( tests ) : NEW_LINE INDENT print ( \" Case ▁ # { } : ▁ \" . format ( z + 1 ) , end = ' ' ) NEW_LINE solve ( ) NEW_LINE DEDENT ouf . close ( ) NEW_LINE", "import sys NEW_LINE def debug ( * args ) : NEW_LINE INDENT print ( * args , file = sys . stderr ) NEW_LINE DEDENT def permutations ( n , k ) : NEW_LINE INDENT if k == 0 : NEW_LINE INDENT yield [ False ] * n NEW_LINE return NEW_LINE DEDENT for p in permutations ( n - 1 , k - 1 ) : NEW_LINE INDENT yield p + [ True ] NEW_LINE DEDENT if n > k : NEW_LINE INDENT for p in permutations ( n - 1 , k ) : NEW_LINE INDENT yield p + [ False ] NEW_LINE DEDENT DEDENT DEDENT def cost ( p , r , c ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( r ) : NEW_LINE INDENT for j in range ( c - 1 ) : NEW_LINE INDENT if p [ i * c + j ] and p [ i * c + j + 1 ] : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( r - 1 ) : NEW_LINE INDENT for j in range ( c ) : NEW_LINE INDENT if p [ i * c + j ] and p [ i * c + j + c ] : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT fin = sys . stdin NEW_LINE T = int ( fin . readline ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT R , C , N = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE best = R * C * 10 NEW_LINE for p in permutations ( R * C , N ) : NEW_LINE INDENT best = min ( best , cost ( p , R , C ) ) NEW_LINE DEDENT result = best NEW_LINE print ( \" Case ▁ # % d : ▁ % s \" % ( case , result ) ) NEW_LINE DEDENT" ]
codejam_17_02
[ "import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . Scanner ; public class b { public static void main ( String [ ] Args ) throws Exception { Scanner sc = new Scanner ( new File ( \" B - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( new File ( \" b . out \" ) ) ) ) ; int cc = 0 ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { String x = sc . next ( ) ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) for ( int j = 0 ; j + 1 < x . length ( ) ; j ++ ) if ( x . charAt ( j ) > x . charAt ( j + 1 ) ) { String nx = x . substring ( 0 , j ) ; nx = nx + ( char ) ( x . charAt ( j ) - 1 ) ; while ( nx . length ( ) < x . length ( ) ) nx = nx + \"9\" ; x = nx ; } while ( x . length ( ) > 1 && x . charAt ( 0 ) == '0' ) x = x . substring ( 1 ) ; out . printf ( \" Case ▁ # % d : ▁ % s % n \" , ++ cc , x ) ; } out . close ( ) ; } }", "import java . io . * ; import java . util . StringTokenizer ; public class B { private String solveTest ( ) throws IOException { String s = next ( ) ; int i = 0 ; while ( i < s . length ( ) - 1 && s . charAt ( i + 1 ) >= s . charAt ( i ) ) { i ++ ; } if ( i == s . length ( ) - 1 ) return s ; while ( i > 0 && s . charAt ( i - 1 ) == s . charAt ( i ) ) i -- ; String res = \" \" ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { res += j < i ? s . charAt ( j ) : j == i ? ( char ) ( s . charAt ( j ) - 1 ) : '9' ; } if ( res . charAt ( 0 ) == '0' ) res = res . substring ( 1 ) ; return res ; } private void solve ( ) throws IOException { int n = nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String res = solveTest ( ) ; System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + res ) ; out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + res ) ; } } BufferedReader br ; StringTokenizer st ; PrintWriter out ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new B ( ) . run ( ) ; } private void run ( ) throws FileNotFoundException { br = new BufferedReader ( new FileReader ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + \" . in \" ) ) ; out = new PrintWriter ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + \" . out \" ) ; try { solve ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } out . close ( ) ; } }", "package qualification ; import java . io . * ; import java . util . * ; public class B_TidyNumbers { private static final String FILENAME = \" B - large \" ; private static final boolean STANDARD_OUTPUT = false ; public static void main ( String [ ] args ) throws Throwable { try ( BufferedReader in = new BufferedReader ( new FileReader ( FILENAME + \" . in \" ) ) ) { try ( PrintStream out = ! STANDARD_OUTPUT ? new PrintStream ( FILENAME + \" . out \" ) : System . out ) { for ( int t = 1 , T = Integer . parseInt ( in . readLine ( ) ) ; t <= T ; t ++ ) { char [ ] N = in . readLine ( ) . toCharArray ( ) ; int i = 1 , k = 0 ; for ( i = 1 ; i < N . length && N [ i ] >= N [ i - 1 ] ; i ++ ) { } if ( i < N . length ) { for ( k = i - 1 ; k >= 0 && N [ k ] == N [ i - 1 ] ; k -- ) { } N [ ++ k ] -- ; Arrays . fill ( N , k + 1 , N . length , '9' ) ; k = k == 0 && N [ 0 ] == '0' ? 1 : 0 ; } out . println ( \" Case ▁ # \" + t + \" : ▁ \" + new String ( N , k , N . length - k ) ) ; } } } } }", "package com . company ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . PrintStream ; import java . util . Arrays ; import java . util . Scanner ; public class ProbB { private Scanner scanner = new Scanner ( System . in ) ; public void main ( ) { reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { long ans = run ( ) ; System . out . println ( \" Case ▁ # \" + cas + \" : ▁ \" + ans ) ; } } private long run ( ) { long input = scanner . nextLong ( ) ; char [ ] arr = Long . valueOf ( input ) . toString ( ) . toCharArray ( ) ; int x = arr . length ; for ( int i = 0 ; i < arr . length - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) { x = i + 1 ; break ; } } if ( x == arr . length ) { return input ; } int y = x - 1 ; while ( y > 0 && arr [ y ] == arr [ y - 1 ] ) y -- ; arr [ y ] -- ; for ( int i = y + 1 ; i < arr . length ; i ++ ) { arr [ i ] = '9' ; } return Long . valueOf ( new String ( arr ) ) ; } private void reDirect ( ) { try { FileInputStream fileInputStream = new FileInputStream ( \" B - large . in \" ) ; scanner = new Scanner ( fileInputStream ) ; PrintStream ps = new PrintStream ( new FileOutputStream ( \" bout - large . txt \" ) ) ; System . setOut ( ps ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } } }", "package qualifier ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class BTidyNumbers { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ) { int tests = sc . nextInt ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { int [ ] digits = sc . next ( ) . chars ( ) . map ( i -> i - '0' ) . toArray ( ) ; for ( int x = 0 ; x < digits . length - 1 ; x ++ ) { if ( digits [ x ] > digits [ x + 1 ] ) { digits [ x ] -- ; for ( int y = x + 1 ; y < digits . length ; y ++ ) digits [ y ] = 9 ; while ( digits [ x ] < 0 || ( x > 0 && digits [ x ] < digits [ x - 1 ] ) ) { digits [ x ] = 9 ; digits [ x - 1 ] -- ; x -- ; } break ; } } int start = 0 ; while ( digits [ start ] == 0 ) start ++ ; StringBuilder sb = new StringBuilder ( ) ; for ( int x = start ; x < digits . length ; x ++ ) sb . append ( ( char ) ( digits [ x ] + '0' ) ) ; System . out . printf ( \" Case ▁ # % d : ▁ % s % n \" , t , sb . toString ( ) ) ; } } } }" ]
[ "def tidy ( N ) : NEW_LINE INDENT return list ( N ) == sorted ( N ) NEW_LINE DEDENT def solve ( N ) : NEW_LINE INDENT if N == '0' : NEW_LINE INDENT return ' ' NEW_LINE DEDENT if tidy ( N ) or len ( N ) <= 1 : NEW_LINE INDENT return N NEW_LINE DEDENT return solve ( str ( int ( N [ : - 1 ] ) - 1 ) ) + '9' NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for case_number in range ( 1 , T + 1 ) : NEW_LINE INDENT N = input ( ) NEW_LINE print ( ' Case ▁ # % d : ' % case_number , solve ( N ) ) NEW_LINE DEDENT", "infilecode = \" BLI \" NEW_LINE import sys NEW_LINE mapping = { \" A \" : \" A \" , \" B \" : \" B \" , \" C \" : \" C \" , \" D \" : \" D \" , \" E \" : \" E \" , \" X \" : \" example \" , \" S \" : \" - small \" , \" L \" : \" - large \" , \" P \" : \" - practice \" , \"0\" : \" - attempt0\" , \"1\" : \" - attempt1\" , \"2\" : \" - attempt2\" , \" I \" : \" . in \" , \" T \" : \" . txt \" } NEW_LINE infile = \" \" . join ( mapping [ c ] for c in infilecode ) NEW_LINE outfile = infile . replace ( \" . in \" , \" \" ) + \" . out . txt \" NEW_LINE sys . stdin = open ( infile , ' r ' ) NEW_LINE output = open ( outfile , ' w ' ) NEW_LINE T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE print ( N ) NEW_LINE a = str ( N ) NEW_LINE l = len ( a ) NEW_LINE for i in range ( l - 1 , 0 , - 1 ) : NEW_LINE INDENT if a [ i ] >= a [ i - 1 ] : NEW_LINE INDENT continue NEW_LINE DEDENT a = a [ : i ] + \"0\" * ( l - i ) NEW_LINE N = int ( a ) - 1 NEW_LINE a = str ( N ) NEW_LINE DEDENT answer = a NEW_LINE print ( \" Case ▁ # % d : \" % case , answer ) NEW_LINE print ( \" Case ▁ # % d : \" % case , answer , file = output ) NEW_LINE DEDENT", "def solve ( n ) : NEW_LINE INDENT digits = [ ] NEW_LINE while n : NEW_LINE INDENT digits . append ( n % 10 ) NEW_LINE n //= 10 NEW_LINE DEDENT digits = list ( reversed ( digits ) ) NEW_LINE ans = None NEW_LINE for i in range ( len ( digits ) ) : NEW_LINE INDENT if i and digits [ i ] < digits [ i - 1 ] : NEW_LINE INDENT break NEW_LINE DEDENT if i == 0 or digits [ i ] - 1 >= digits [ i - 1 ] : NEW_LINE INDENT if digits [ i ] - 1 == 0 : NEW_LINE INDENT ans = [ 9 ] * ( len ( digits ) - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = digits [ : i ] + [ digits [ i ] - 1 ] + [ 9 ] * ( len ( digits ) - i - 1 ) NEW_LINE DEDENT DEDENT if i == len ( digits ) - 1 : NEW_LINE INDENT ans = digits NEW_LINE DEDENT DEDENT return ' ' . join ( map ( str , ans ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT ntest = int ( input ( ) ) NEW_LINE for i in range ( ntest ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE ans = solve ( n ) NEW_LINE print ( \" Case ▁ # % d : ▁ % s \" % ( i + 1 , ans ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE NEW_LINE DEDENT", "IN = open ( ' input . txt ' , ' r ' ) NEW_LINE OUT = open ( ' output . txt ' , ' w ' ) NEW_LINE NUM_TESTS = int ( IN . readline ( ) ) NEW_LINE for test in xrange ( NUM_TESTS ) : NEW_LINE INDENT N = int ( IN . readline ( ) ) NEW_LINE while True : NEW_LINE INDENT l = [ int ( c ) for c in str ( N ) ] NEW_LINE for i in xrange ( len ( l ) - 1 ) : NEW_LINE INDENT if l [ i ] > l [ i + 1 ] : NEW_LINE INDENT N = int ( str ( N ) [ : i + 1 ] + '0' * ( len ( l ) - i - 1 ) ) - 1 NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT OUT . write ( ' Case ▁ # { } : ▁ { } \\n ' . format ( test + 1 , N ) ) NEW_LINE print test + 1 , N NEW_LINE DEDENT IN . close ( ) NEW_LINE OUT . close ( ) NEW_LINE", "from __future__ import print_function NEW_LINE import sys NEW_LINE from sys import stdin NEW_LINE def eprint ( * args , ** kwargs ) : NEW_LINE INDENT print ( * args , file = sys . stderr , ** kwargs ) NEW_LINE DEDENT def ln ( f = int ) : NEW_LINE INDENT return list ( map ( f , stdin . readline ( ) . strip ( ) . split ( ) ) ) NEW_LINE DEDENT T , = ln ( ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE for test in range ( T ) : NEW_LINE INDENT s , = ln ( str ) NEW_LINE s = list ( map ( int , list ( s ) ) ) NEW_LINE prev = 9 NEW_LINE res = \" \" NEW_LINE ind = None NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] < s [ i - 1 ] : NEW_LINE INDENT ind = i NEW_LINE break NEW_LINE DEDENT DEDENT if ind != None : NEW_LINE INDENT for i in range ( ind + 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = 9 NEW_LINE DEDENT while ind != 0 and s [ ind ] < s [ ind - 1 ] : NEW_LINE INDENT s [ ind - 1 ] -= 1 NEW_LINE s [ ind ] = 9 NEW_LINE ind -= 1 NEW_LINE DEDENT DEDENT res = int ( \" \" . join ( list ( map ( str , s ) ) ) ) NEW_LINE print ( \" Case ▁ # \" + str ( test + 1 ) + \" : ▁ \" + str ( res ) ) NEW_LINE DEDENT" ]
codejam_13_42
[ "import java . util . Scanner ; public class B { static Scanner sc = new Scanner ( System . in ) ; static int N ; static long P ; public static void main ( String [ ] args ) throws Exception { int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; ++ t ) { N = sc . nextInt ( ) ; P = sc . nextLong ( ) ; System . out . println ( \" Case ▁ # \" + t + \" : ▁ \" + ( solveGuarantee ( 1L << N , P ) - 1 ) + \" ▁ \" + ( solveCould ( 1L << N , P ) - 1 ) ) ; } } static long solveGuarantee ( long n , long p ) { if ( p == n ) return n ; if ( p <= n / 2 ) return 1 ; return solveGuarantee ( n / 2 , p - n / 2 ) * 2 + 1 ; } static long solveCould ( long n , long p ) { if ( p == n ) return n ; if ( p >= n / 2 ) return n - 1 ; long c = solveCould ( n / 2 , p ) ; return c + c - 1 ; } }", "package contest ; import java . util . * ; import java . io . * ; public class ManyPrizes { final static String PROBLEM_NAME = \" mprizes \" ; final static String WORK_DIR = \" D : \\\\ Gcj\\ \\\" + PROBLEM_NAME + \" \\ \\\" ; void solve ( Scanner sc , PrintWriter pw ) { int N = sc . nextInt ( ) ; long P = sc . nextLong ( ) ; long ans1 = - 1 ; long sum = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { sum += ( 1L << i ) ; if ( P <= sum ) { ans1 = ( 1L << ( N - i ) ) - 1 ; break ; } } if ( ans1 == - 1 ) ans1 = ( 1L << N ) ; long ans2 = - 1 ; int needWins = 0 ; while ( ( 1L << ( N - needWins ) ) > P ) needWins ++ ; ans2 = ( 1L << N ) - ( 1L << needWins ) + 1 ; ans1 -- ; ans2 -- ; pw . println ( ans1 + \" ▁ \" + ans2 ) ; } public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( new FileReader ( WORK_DIR + \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( WORK_DIR + \" output . txt \" ) ) ; int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { System . out . println ( \" Processing ▁ test ▁ case ▁ \" + ( caseNum + 1 ) ) ; pw . print ( \" Case ▁ # \" + ( caseNum + 1 ) + \" : ▁ \" ) ; new ManyPrizes ( ) . solve ( sc , pw ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } }", "import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class B { void solve ( ) throws IOException { int t = nextInt ( ) ; for ( int testCase = 0 ; testCase < t ; testCase ++ ) { long n = nextInt ( ) ; long p = nextLong ( ) ; long max = 1l << n ; long a1 = 0 , a2 = max - 2 ; if ( p == 1 ) { a1 = a2 = 0 ; } else if ( p == max ) { a1 = a2 = max - 1 ; } else { long x = max >> 1l ; long y = x >> 1l ; long z = 2 ; while ( p > x ) { a1 += z ; z <<= 1l ; x |= y ; y >>= 1l ; } x = max >> 1l ; z = 2 ; while ( p < x ) { a2 -= z ; z <<= 1l ; x >>= 1l ; } } out . printf ( \" Case ▁ # % d : ▁ % d ▁ % d \\n \" , testCase + 1 , a1 , a2 ) ; } } public static void main ( String [ ] args ) throws IOException { new B ( ) . run ( ) ; } void run ( ) throws IOException { reader = new BufferedReader ( new FileReader ( \" input . txt \" ) ) ; out = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; tokenizer = null ; solve ( ) ; reader . close ( ) ; out . flush ( ) ; } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter out ; int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; } String nextToken ( ) throws IOException { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } }", "import java . math . BigInteger ; import java . util . * ; public class B { static BigInteger B ( long n ) { return BigInteger . valueOf ( n ) ; } static BigInteger A ( BigInteger A , BigInteger B ) { return A . add ( B ) ; } static BigInteger M ( BigInteger A , BigInteger B ) { return A . multiply ( B ) ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { int n = in . nextInt ( ) ; BigInteger P = new BigInteger ( in . next ( ) ) ; BigInteger last_pos = B ( 2 ) . pow ( n ) . subtract ( P ) ; int min_ones = 0 ; for ( min_ones = 0 ; min_ones <= n ; min_ones ++ ) { BigInteger val = B ( 0 ) ; for ( int i = 0 ; i < min_ones ; i ++ ) val = A ( val , B ( 2 ) . pow ( n - 1 - i ) ) ; if ( val . compareTo ( last_pos ) >= 0 ) break ; } BigInteger last_win = B ( 2 ) . pow ( n ) . subtract ( B ( 2 ) . pow ( min_ones ) ) ; int min_zeroes = 0 ; for ( min_zeroes = 0 ; min_zeroes <= n ; min_zeroes ++ ) { BigInteger val = B ( 2 ) . pow ( n ) . subtract ( B ( 1 ) ) ; for ( int i = 0 ; i < min_zeroes ; i ++ ) val = val . subtract ( B ( 2 ) . pow ( n - 1 - i ) ) ; if ( val . compareTo ( last_pos ) < 0 ) break ; } BigInteger last_guarantee = B ( 2 ) . pow ( min_zeroes ) . subtract ( B ( 2 ) ) ; if ( last_pos . equals ( B ( 0 ) ) ) last_guarantee = B ( 2 ) . pow ( n ) . subtract ( B ( 1 ) ) ; System . out . printf ( \" Case ▁ # % d : ▁ % s ▁ % s \\n \" , cas , last_guarantee , last_win ) ; } } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( B . class . getSimpleName ( ) + \" . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( B . class . getSimpleName ( ) + \" . out \" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new B ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; long p = in . nextLong ( ) ; p -- ; long b = 1 ; if ( p == ( ( 1L << n ) - 1 ) ) { b = ( ( 1L << n ) - 1 ) + 2 ; } else { long pp = ( 1L << n ) - 1 - ( p + 1 ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ( ( pp >> i ) & 1 ) == 0 ) { b *= 2 ; } else { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( ( ( pp >> j ) & 1 ) == 0 ) { b *= 2 ; break ; } } break ; } } } long pp = ( 1L << n ) - 1 - p ; long c = 1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ( ( pp >> i ) & 1 ) == 1 ) { c *= 2 ; } else { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( ( ( pp >> j ) & 1 ) == 1 ) { c *= 2 ; break ; } } break ; } } return ( b - 2 ) + \" ▁ \" + ( ( 1L << n ) - c ) ; } }" ]
[ "def lpos ( N , L ) : NEW_LINE INDENT return 2 ** N - 2 ** ( N - L ) NEW_LINE DEDENT def wpos ( N , W ) : NEW_LINE INDENT return 2 ** ( N - W ) - 1 NEW_LINE DEDENT def hforl ( N , L ) : NEW_LINE INDENT r = 0 NEW_LINE for i in xrange ( L ) : NEW_LINE INDENT r = 2 * r + 2 NEW_LINE DEDENT return min ( 2 ** N - 1 , r ) NEW_LINE DEDENT def hforw ( N , W ) : NEW_LINE INDENT r = 0 NEW_LINE for i in xrange ( W ) : NEW_LINE INDENT r = 2 * r + 1 NEW_LINE DEDENT return max ( 0 , 2 ** N - r - 1 ) NEW_LINE DEDENT def solve ( N , P ) : NEW_LINE INDENT maxl = 0 NEW_LINE while maxl <= N and lpos ( N , maxl ) < P : maxl += 1 NEW_LINE maxl -= 1 NEW_LINE guaranteed = hforl ( N , maxl ) NEW_LINE minw = N NEW_LINE while minw >= 0 and wpos ( N , minw ) < P : minw -= 1 NEW_LINE minw += 1 NEW_LINE could = hforw ( N , minw ) NEW_LINE return ( guaranteed , could ) NEW_LINE DEDENT T = input ( ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , P = map ( int , raw_input ( ) . split ( ) ) NEW_LINE s = solve ( N , P ) NEW_LINE print ' Case ▁ # % s : ▁ % s ▁ % s ' % ( t + 1 , s [ 0 ] , s [ 1 ] ) NEW_LINE DEDENT", "code = \" B - large \" NEW_LINE infile = code + \" . in \" NEW_LINE outfile = code + \" . out \" NEW_LINE def willwin ( n , s ) : NEW_LINE INDENT pos = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if s > 0 : NEW_LINE INDENT pos += 2 ** ( n - i - 1 ) NEW_LINE s = ( s - 1 ) // 2 NEW_LINE DEDENT DEDENT return pos NEW_LINE DEDENT def maywin ( n , w ) : NEW_LINE INDENT pos = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if w > 0 : NEW_LINE INDENT w = ( w - 1 ) // 2 NEW_LINE DEDENT else : NEW_LINE INDENT pos += 2 ** ( n - i - 1 ) NEW_LINE DEDENT DEDENT return pos NEW_LINE DEDENT def solve ( n , p ) : NEW_LINE INDENT if p == 2 ** n : NEW_LINE INDENT return p - 1 , p - 1 NEW_LINE DEDENT low , high = 0 , 2 ** n - 1 NEW_LINE while high - low > 1 : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if willwin ( n , mid ) < p : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT will = low NEW_LINE low , high = 0 , 2 ** n - 1 NEW_LINE while high - low > 1 : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if maywin ( n , 2 ** n - mid - 1 ) < p : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT may = low NEW_LINE return will , may NEW_LINE DEDENT lines = [ s . strip ( ) for s in open ( infile ) ] NEW_LINE c = int ( lines [ 0 ] ) NEW_LINE f = open ( outfile , \" w \" ) NEW_LINE lineno = 1 NEW_LINE for i in range ( 1 , c + 1 ) : NEW_LINE INDENT n , p = map ( int , lines [ lineno ] . split ( ) ) NEW_LINE r = solve ( n , p ) NEW_LINE lineno += 1 NEW_LINE msg = \" Case ▁ # { 0 } : ▁ { 1[0 ] } ▁ { 1[1 ] } \" . format ( i , r ) NEW_LINE print msg NEW_LINE print >> f , msg NEW_LINE DEDENT f . close ( ) NEW_LINE", "import sys NEW_LINE import re NEW_LINE import math NEW_LINE import string NEW_LINE f = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE num = int ( f . readline ( ) ) NEW_LINE for i in xrange ( num ) : NEW_LINE INDENT l = f . readline ( ) NEW_LINE N , P = [ int ( x ) for x in l . split ( ) ] NEW_LINE if 2 ** N == P : NEW_LINE INDENT print ' Case ▁ # { } : ' . format ( i + 1 ) , 2 ** N - 1 , 2 ** N - 1 NEW_LINE continue NEW_LINE DEDENT j = 0 NEW_LINE while P >= 2 ** j : NEW_LINE INDENT j += 1 NEW_LINE DEDENT j -= 1 NEW_LINE k = 1 NEW_LINE while P > 2 ** N - 2 ** ( N - k ) : NEW_LINE INDENT k += 1 NEW_LINE DEDENT print ' Case ▁ # { } : ' . format ( i + 1 ) , 2 ** k - 2 , 2 ** N - 2 ** ( N - j ) NEW_LINE DEDENT", "from sys import * NEW_LINE from heapq import * NEW_LINE import math NEW_LINE def write ( msg ) : NEW_LINE INDENT stdout . write ( msg ) NEW_LINE fo . write ( msg ) NEW_LINE DEDENT def writeln ( msg ) : NEW_LINE INDENT write ( str ( msg ) + ' \\n ' ) NEW_LINE DEDENT def readint ( ) : NEW_LINE INDENT return int ( fi . readline ( ) ) NEW_LINE DEDENT def readints ( ) : NEW_LINE INDENT return [ int ( X ) for X in fi . readline ( ) . split ( ) ] NEW_LINE DEDENT def readstr ( ) : NEW_LINE INDENT return fi . readline ( ) . rstrip ( ) NEW_LINE DEDENT fni = \" % s - % s - % s . in \" % ( argv [ 1 ] , argv [ 2 ] , argv [ 3 ] ) NEW_LINE fno = \" % s - % s - % s . out \" % ( argv [ 1 ] , argv [ 2 ] , argv [ 3 ] ) NEW_LINE fi = open ( fni , ' r ' ) NEW_LINE fo = open ( fno , ' w ' ) NEW_LINE def ffail ( start , step , num , prizes ) : NEW_LINE INDENT if prizes >= num : NEW_LINE INDENT return start + step * ( num - 1 ) + 1 NEW_LINE DEDENT if prizes <= 0 : NEW_LINE INDENT return start NEW_LINE DEDENT if 2 * prizes <= num : NEW_LINE INDENT return start + step NEW_LINE DEDENT return ffail ( start + step , step * 2 , num / 2 , prizes - num / 2 ) NEW_LINE DEDENT def wwin ( start , step , num , prizes ) : NEW_LINE INDENT if prizes >= num : NEW_LINE INDENT return start + step * ( num - 1 ) NEW_LINE DEDENT if prizes <= 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return wwin ( start , step * 2 , num / 2 , prizes ) NEW_LINE DEDENT num_cases = readint ( ) NEW_LINE for case in range ( 1 , 1 + num_cases ) : NEW_LINE INDENT ( N , P ) = readints ( ) NEW_LINE g = ffail ( 0 , 1 , 2 ** N , P ) - 1 NEW_LINE w = wwin ( 0 , 1 , 2 ** N , P ) NEW_LINE writeln ( \" Case ▁ # % d : ▁ % d ▁ % d \" % ( case , g , w ) ) NEW_LINE DEDENT", "def reader ( inFile ) : NEW_LINE INDENT return tuple ( inFile . getInts ( ) ) NEW_LINE DEDENT def solver ( ( N , p ) ) : NEW_LINE INDENT wins = [ ( ( ( p - 1 ) >> i ) & 1 ) == 0 for i in xrange ( N ) ] [ : : - 1 ] NEW_LINE a1 = 0 NEW_LINE for win in wins : NEW_LINE INDENT if not win : NEW_LINE INDENT a1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT a1 = ( ( 1 << ( a1 + 1 ) ) - 2 ) if ( a1 < N ) else ( ( 1 << N ) - 1 ) NEW_LINE a2 = 0 NEW_LINE for win in wins : NEW_LINE INDENT if win : NEW_LINE INDENT a2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( a2 == len ( [ win for win in wins if win ] ) ) : NEW_LINE INDENT a2 -= 1 NEW_LINE DEDENT a2 = ( 1 << N ) - ( 1 << ( a2 + 1 ) ) NEW_LINE return \" % d ▁ % d \" % ( a1 , a2 ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , \" / Users / lpebody / gcj / 2013_2 / b / \" , \" b \" ) . run ( ) NEW_LINE DEDENT" ]
codejam_12_12
[ "import java . util . * ; import static java . lang . Math . * ; public class B { static void p ( Object ... o ) { System . out . println ( Arrays . deepToString ( o ) ) ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { int N = in . nextInt ( ) ; int [ ] A = new int [ N ] ; int [ ] B = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = in . nextInt ( ) ; B [ i ] = in . nextInt ( ) ; } int [ ] have = new int [ N ] ; int stars = 0 ; int ans = 0 ; next : while ( stars < 2 * N ) { int best = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( have [ i ] == 2 ) continue ; if ( stars >= B [ i ] ) { stars += 2 - have [ i ] ; have [ i ] = 2 ; ans ++ ; continue next ; } if ( have [ i ] == 1 ) continue ; if ( stars < A [ i ] ) continue ; if ( best == - 1 || B [ i ] > B [ best ] ) { best = i ; } } if ( best == - 1 ) break ; have [ best ] = 1 ; ans ++ ; stars ++ ; } if ( stars == 2 * N ) System . out . format ( \" Case ▁ # % d : ▁ % d \\n \" , zz , ans ) ; else System . out . format ( \" Case ▁ # % d : ▁ Too ▁ Bad \\n \" , zz , ans ) ; } } }", "import java . io . File ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class B { static int [ ] visit = new int [ 1024 ] ; static int [ ] a = new int [ 1024 ] ; static int [ ] b = new int [ 1024 ] ; public static void main ( String [ ] args ) throws Exception { Scanner s = new Scanner ( new File ( \" B . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" B . out \" ) ) ; int T = s . nextInt ( ) ; for ( int tc = 1 ; tc <= T ; tc ++ ) { out . print ( \" Case ▁ # \" + tc + \" : ▁ \" ) ; int N = s . nextInt ( ) ; Arrays . fill ( visit , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = s . nextInt ( ) ; b [ i ] = s . nextInt ( ) ; } int ans = 0 ; int stars = 0 ; boolean progress = true ; outer : while ( progress ) { if ( stars == 2 * N ) break ; ans ++ ; progress = false ; for ( int i = 0 ; i < N ; i ++ ) { if ( visit [ i ] == 0 && b [ i ] <= stars ) { progress = true ; stars += 2 ; visit [ i ] = 2 ; continue outer ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( visit [ i ] == 1 && b [ i ] <= stars ) { progress = true ; stars += 1 ; visit [ i ] = 2 ; continue outer ; } } int bestb = 0 ; int besti = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( visit [ i ] == 0 && a [ i ] <= stars ) { progress = true ; if ( bestb < b [ i ] ) { bestb = b [ i ] ; besti = i ; } } } if ( progress ) { visit [ besti ] = 1 ; stars += 1 ; } } if ( stars == 2 * N ) out . println ( ans ) ; else out . println ( \" Too ▁ Bad \" ) ; } out . close ( ) ; } }", "import java . util . Comparator ; import java . util . HashSet ; import java . util . Scanner ; import java . util . TreeSet ; public class b { Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new b ( ) . go ( ) ; } private void go ( ) { int numc = in . nextInt ( ) ; IN : for ( int cnum = 0 ; cnum < numc ; cnum ++ ) { int n = in . nextInt ( ) ; int [ ] [ ] q = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { q [ i ] [ 0 ] = in . nextInt ( ) ; q [ i ] [ 1 ] = in . nextInt ( ) ; } int min = 0 , stars = 0 ; HashSet < Integer > chose1 = new HashSet < Integer > ( ) , chose2 = new HashSet < Integer > ( ) ; OUT : for ( int i = 0 ; i < 2 * n ; i ++ ) { if ( stars == 2 * n ) break ; int max = 0 , maxIndex = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ! chose2 . contains ( j ) ) { if ( ! chose1 . contains ( j ) ) { if ( q [ j ] [ 1 ] <= stars ) { stars += 2 ; min ++ ; chose2 . add ( j ) ; continue OUT ; } if ( q [ j ] [ 0 ] <= stars && q [ j ] [ 1 ] > max ) { max = q [ j ] [ 1 ] ; maxIndex = j ; } } if ( q [ j ] [ 1 ] <= stars ) { stars += 1 ; min ++ ; chose2 . add ( j ) ; chose1 . remove ( j ) ; continue OUT ; } } } if ( maxIndex == - 1 ) { System . out . printf ( \" Case ▁ # % d : ▁ Too ▁ Bad \\n \" , cnum + 1 ) ; continue IN ; } chose1 . add ( maxIndex ) ; min ++ ; stars += 1 ; } System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , cnum + 1 , min ) ; } } }", "import java . util . * ; import java . math . * ; public class Main { static class Level implements Comparable < Level > { public int low ; public int high ; public Level ( int low , int high ) { this . low = low ; this . high = high ; } @ Override public int compareTo ( Level o ) { return high - o . high ; } } public static void main ( String [ ] args ) throws Exception { Scanner scan = new Scanner ( System . in ) ; int task = scan . nextInt ( ) ; int current = 1 ; while ( task -- > 0 ) { int N = scan . nextInt ( ) ; Level [ ] arr = new Level [ N ] ; int [ ] status = new int [ N ] ; int finished = 0 ; int star = 0 ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = new Level ( scan . nextInt ( ) , scan . nextInt ( ) ) ; } Arrays . sort ( arr ) ; int result = 0 ; while ( finished < N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] == 2 ) { continue ; } if ( star >= arr [ i ] . high ) { star += 2 - status [ i ] ; status [ i ] = 2 ; finished ++ ; result ++ ; } } if ( finished == N ) { break ; } int select = - 1 ; int max = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] >= 1 ) { continue ; } if ( star >= arr [ i ] . low ) { if ( arr [ i ] . high > max ) { select = i ; max = arr [ i ] . high ; } } } if ( select == - 1 ) { result = - 1 ; break ; } else { result ++ ; status [ select ] = 1 ; star ++ ; } } System . out . println ( \" Case ▁ # \" + current + \" : ▁ \" + ( result == - 1 ? \" Too ▁ Bad \" : result ) ) ; current ++ ; } } }", "import java . util . Scanner ; public class B { private static Scanner sc ; public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int i = 0 ; i < t ; i ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , i + 1 , exec ( ) ) ; } } public static String exec ( ) { int n = sc . nextInt ( ) ; int [ ] s1 = new int [ n ] ; int [ ] s2 = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s1 [ i ] = sc . nextInt ( ) ; s2 [ i ] = sc . nextInt ( ) ; } int stars = 0 ; int goal = n * 2 ; int [ ] obtained = new int [ n ] ; int plays = 0 ; loop : while ( stars < goal ) { for ( int i = 0 ; i < n ; i ++ ) { if ( s2 [ i ] > stars ) continue ; if ( obtained [ i ] == 2 ) continue ; stars += 2 - obtained [ i ] ; obtained [ i ] = 2 ; plays ++ ; continue loop ; } int s2OfWinner = - 1 ; int idxOfWinner = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( obtained [ i ] != 0 ) continue ; if ( s1 [ i ] > stars ) continue ; if ( s2 [ i ] < s2OfWinner ) continue ; s2OfWinner = s2 [ i ] ; idxOfWinner = i ; } if ( s2OfWinner == - 1 ) return \" Too ▁ Bad \" ; stars ++ ; obtained [ idxOfWinner ] = 1 ; plays ++ ; } return String . valueOf ( plays ) ; } }" ]
[ "import heapq NEW_LINE def alphabet ( n , z ) : NEW_LINE INDENT coins = 0 NEW_LINE turns = 0 NEW_LINE coined = [ 0 ] * n NEW_LINE while coins < 2 * n : NEW_LINE INDENT won = False NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if z [ i ] [ 1 ] <= coins and coined [ i ] < 2 : NEW_LINE INDENT won = True NEW_LINE coins += 2 - coined [ i ] NEW_LINE coined [ i ] = 2 NEW_LINE turns += 1 NEW_LINE DEDENT DEDENT if not won : NEW_LINE INDENT maxi = - 1 NEW_LINE maxm = - 1 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if coined [ i ] == 0 and z [ i ] [ 0 ] <= coins and z [ i ] [ 1 ] > maxm : NEW_LINE INDENT maxm = z [ i ] [ 1 ] NEW_LINE maxi = i NEW_LINE DEDENT DEDENT if maxm == - 1 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT coined [ maxi ] = 1 NEW_LINE coins += 1 NEW_LINE turns += 1 NEW_LINE DEDENT DEDENT DEDENT return turns NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT fn = open ( \" B - large . in \" , \" r \" ) NEW_LINE tcase = int ( fn . readline ( ) ) NEW_LINE for x in range ( tcase ) : NEW_LINE INDENT a = int ( fn . readline ( ) ) NEW_LINE l = [ ] NEW_LINE for i in xrange ( a ) : NEW_LINE INDENT kk = fn . readline ( ) . split ( ) NEW_LINE l . append ( ( int ( kk [ 0 ] ) , int ( kk [ 1 ] ) ) ) NEW_LINE DEDENT yy = alphabet ( a , l ) NEW_LINE if yy == - 1 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ Too ▁ Bad \" % ( x + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( x + 1 , yy ) NEW_LINE DEDENT DEDENT DEDENT", "for t in range ( int ( raw_input ( ) ) ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE levels = [ ] NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT levels . append ( map ( int , raw_input ( ) . split ( ) ) ) NEW_LINE DEDENT r = 0 NEW_LINE s = 0 NEW_LINE while True : NEW_LINE INDENT c = False NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT if levels [ i ] [ 1 ] != - 1 and levels [ i ] [ 1 ] <= s : NEW_LINE INDENT if levels [ i ] [ 0 ] != - 1 : NEW_LINE INDENT s += 1 NEW_LINE DEDENT s += 1 NEW_LINE r += 1 NEW_LINE levels [ i ] = ( - 1 , - 1 ) NEW_LINE c = True NEW_LINE break NEW_LINE DEDENT DEDENT if c : NEW_LINE INDENT continue NEW_LINE DEDENT max_2v = - 1 NEW_LINE max_2i = - 1 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT if levels [ i ] [ 0 ] != - 1 and levels [ i ] [ 0 ] <= s : NEW_LINE INDENT if levels [ i ] [ 1 ] > max_2v : NEW_LINE INDENT max_2v = levels [ i ] [ 1 ] NEW_LINE max_2i = i NEW_LINE DEDENT DEDENT DEDENT if max_2v != - 1 : NEW_LINE INDENT r += 1 NEW_LINE s += 1 NEW_LINE levels [ max_2i ] [ 0 ] = - 1 NEW_LINE continue NEW_LINE DEDENT break NEW_LINE DEDENT if s == N * 2 : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % d ' % ( t + 1 , r ) NEW_LINE DEDENT else : NEW_LINE INDENT print ' Case ▁ # % d : ▁ Too ▁ Bad ' % ( t + 1 ) NEW_LINE DEDENT DEDENT", "import sys , re , string , math , fractions , itertools NEW_LINE from fractions import Fraction NEW_LINE ssr = sys . stdin . readline NEW_LINE ssw = sys . stdout . write NEW_LINE def rdline ( ) : return ssr ( ) . strip ( ) NEW_LINE def rdstrs ( ) : return ssr . split ( ) NEW_LINE def rdints ( ) : return map ( int , ssr ( ) . split ( ) ) NEW_LINE def do_one_case ( cnum ) : NEW_LINE INDENT ( N , ) = rdints ( ) NEW_LINE abi = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT ( a , b ) = rdints ( ) NEW_LINE abi . append ( ( a , b , i ) ) NEW_LINE DEDENT d = N * [ 0 ] NEW_LINE s = 0 NEW_LINE n = 0 NEW_LINE while s < 2 * N : NEW_LINE INDENT ( b , i ) = min ( [ ( b , i ) for ( a , b , i ) in abi if d [ i ] < 2 ] ) NEW_LINE if b <= s : NEW_LINE INDENT s += 2 - d [ i ] NEW_LINE d [ i ] = 2 NEW_LINE n += 1 NEW_LINE continue NEW_LINE DEDENT bai = [ ( b , a , i ) for ( a , b , i ) in abi if d [ i ] == 0 and a <= s ] NEW_LINE if not bai : NEW_LINE INDENT print \" Case ▁ # % d : ▁ Too ▁ Bad \" % ( cnum , ) NEW_LINE return NEW_LINE DEDENT ( b , a , i ) = max ( bai ) NEW_LINE s += 1 NEW_LINE d [ i ] = 1 NEW_LINE n += 1 NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( cnum , n ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N = int ( rdline ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT do_one_case ( i + 1 ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "def input ( ) : NEW_LINE INDENT with open ( ' b . in ' ) as file : NEW_LINE INDENT tests_count = int ( file . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( tests_count ) : NEW_LINE INDENT levels_count = int ( file . readline ( ) . strip ( ) ) NEW_LINE levels_requirements = [ ] NEW_LINE for j in xrange ( levels_count ) : NEW_LINE INDENT levels_requirements . append ( tuple ( int ( n ) for n in file . readline ( ) . strip ( ) . split ( ) ) ) NEW_LINE DEDENT yield levels_requirements NEW_LINE DEDENT DEDENT DEDENT def output ( answers ) : NEW_LINE INDENT with open ( ' b . out ' , ' w ' ) as file : NEW_LINE INDENT for i , answer in enumerate ( answers ) : NEW_LINE INDENT file . write ( ' Case ▁ # % s : ▁ % s \\n ' % ( i + 1 , answer ) ) NEW_LINE DEDENT DEDENT DEDENT def choose_level ( levels_requirements , levels_solved , stars_earned ) : NEW_LINE INDENT for i in xrange ( len ( levels_requirements ) ) : NEW_LINE INDENT result = levels_solved [ i ] NEW_LINE if result < 2 : NEW_LINE INDENT if levels_requirements [ i ] [ 1 ] <= stars_earned : NEW_LINE INDENT levels_solved [ i ] = 2 NEW_LINE return 2 - result NEW_LINE DEDENT DEDENT DEDENT candidate_i = - 1 NEW_LINE maximum_2_stars = - 1 NEW_LINE for i in xrange ( len ( levels_requirements ) ) : NEW_LINE INDENT result = levels_solved [ i ] NEW_LINE if result == 0 : NEW_LINE INDENT if levels_requirements [ i ] [ 0 ] <= stars_earned : NEW_LINE INDENT if levels_requirements [ i ] [ 1 ] > maximum_2_stars : NEW_LINE INDENT maximum_2_stars = levels_requirements [ i ] [ 1 ] NEW_LINE candidate_i = i NEW_LINE DEDENT DEDENT DEDENT DEDENT if candidate_i == - 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT levels_solved [ candidate_i ] = 1 NEW_LINE return 1 NEW_LINE DEDENT def solve ( levels_requirements ) : NEW_LINE INDENT levels_solved = [ 0 ] * len ( levels_requirements ) NEW_LINE stars_earned = 0 NEW_LINE games_played = 0 NEW_LINE while True : NEW_LINE INDENT if all ( l == 2 for l in levels_solved ) : NEW_LINE INDENT return games_played NEW_LINE DEDENT new_stars = choose_level ( levels_requirements , levels_solved , stars_earned ) NEW_LINE if not new_stars : NEW_LINE INDENT return ' Too ▁ Bad ' NEW_LINE DEDENT else : NEW_LINE INDENT stars_earned += new_stars NEW_LINE games_played += 1 NEW_LINE DEDENT DEDENT DEDENT def main ( ) : NEW_LINE INDENT answers = ( solve ( levels_requirements ) for levels_requirements in input ( ) ) NEW_LINE output ( answers ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "from Queue import PriorityQueue NEW_LINE with open ( ' B - large . in ' , ' r ' ) as fin : NEW_LINE INDENT with open ( ' output . txt ' , ' w ' ) as fout : NEW_LINE INDENT numcases = int ( fin . readline ( ) ) NEW_LINE for i in range ( 1 , numcases + 1 ) : NEW_LINE INDENT line = [ int ( j ) for j in fin . readline ( ) . split ( ) ] NEW_LINE numlevels = line [ 0 ] NEW_LINE doables = [ ] NEW_LINE levels = PriorityQueue ( ) NEW_LINE for j in range ( numlevels ) : NEW_LINE INDENT line = [ int ( k ) for k in fin . readline ( ) . split ( ) ] NEW_LINE levels . put ( ( line [ 0 ] , line [ 1 ] ) ) NEW_LINE DEDENT stars = 0 NEW_LINE played = 0 NEW_LINE while True : NEW_LINE INDENT while not levels . empty ( ) : NEW_LINE INDENT nextlevel = levels . get ( ) NEW_LINE if nextlevel [ 0 ] <= stars : NEW_LINE INDENT if nextlevel [ 1 ] == None : NEW_LINE INDENT played += 1 NEW_LINE stars += 1 NEW_LINE DEDENT else : NEW_LINE INDENT doables . append ( nextlevel [ 1 ] ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT levels . put ( nextlevel ) NEW_LINE break NEW_LINE DEDENT DEDENT doables . sort ( ) NEW_LINE if len ( doables ) == 0 : NEW_LINE INDENT if not levels . empty ( ) : NEW_LINE INDENT played = - 1 NEW_LINE DEDENT break NEW_LINE DEDENT else : NEW_LINE INDENT lowlevel = doables [ 0 ] NEW_LINE played += 1 NEW_LINE if lowlevel <= stars : NEW_LINE INDENT stars += 2 NEW_LINE doables = doables [ 1 : ] NEW_LINE DEDENT else : NEW_LINE INDENT stars += 1 NEW_LINE levels . put ( ( doables [ - 1 ] , None ) ) NEW_LINE del doables [ - 1 ] NEW_LINE DEDENT DEDENT DEDENT fout . write ( \" Case ▁ # \" ) NEW_LINE fout . write ( str ( i ) ) NEW_LINE fout . write ( \" : ▁ \" ) NEW_LINE if ( played >= 0 ) : NEW_LINE INDENT fout . write ( str ( played ) ) NEW_LINE DEDENT else : NEW_LINE INDENT fout . write ( \" Too ▁ Bad \" ) NEW_LINE DEDENT fout . write ( ' \\n ' ) NEW_LINE print ( i ) NEW_LINE DEDENT DEDENT DEDENT" ]
codejam_12_11
[ "import java . util . * ; import java . io . * ; import java . math . * ; import java . awt . * ; import static java . lang . Math . * ; import static java . lang . Integer . parseInt ; import static java . lang . Double . parseDouble ; import static java . lang . Long . parseLong ; import static java . lang . System . * ; import static java . util . Arrays . * ; import static java . util . Collection . * ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; int T = parseInt ( br . readLine ( ) ) ; for ( int t = 0 ; t ++ < T ; ) { String [ ] line = br . readLine ( ) . split ( \" ▁ \" ) ; int A = parseInt ( line [ 0 ] ) , B = parseInt ( line [ 1 ] ) ; line = br . readLine ( ) . split ( \" ▁ \" ) ; double [ ] P = new double [ A + 1 ] ; P [ 0 ] = 1 ; for ( int a = 0 ; a < A ; a ++ ) P [ a + 1 ] = parseDouble ( line [ a ] ) * P [ a ] ; double best = 2 + B ; for ( int a = 0 ; a <= A ; a ++ ) best = min ( best , 2 * a + ( B - A ) + 1 + ( 1 - P [ A - a ] ) * ( B + 1 ) ) ; out . println ( \" Case ▁ # \" + t + \" : ▁ \" + best ) ; } } }", "import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int inputs = in . nextInt ( ) ; Q : for ( int _ = 1 ; _ <= inputs ; _ ++ ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; double exp = 2 + b ; double [ ] prob = new double [ a + 1 ] ; prob [ 0 ] = 1 ; for ( int i = 0 ; i < a ; i ++ ) { prob [ i + 1 ] = prob [ i ] * ( in . nextDouble ( ) ) ; } double exp2 = prob [ a ] * ( b - a + 1 ) + ( 1 - prob [ a ] ) * ( 2 * b - a + 2 ) ; if ( exp2 < exp ) exp = exp2 ; exp2 = 0 ; for ( int i = 0 ; i < a ; i ++ ) { exp2 = prob [ i ] * ( 2 * ( a - i ) + ( b - a ) + 1 ) + ( 1 - prob [ i ] ) * ( ( 2 * ( a - i ) + ( b - a ) + 1 ) + b + 1 ) ; if ( exp2 < exp ) exp = exp2 ; } System . out . printf ( \" Case ▁ # \" + _ + \" : ▁ % .6f \\n \" , exp ) ; } } }", "import java . io . * ; import java . util . * ; public class PasswordProblem { void solve ( ) throws Exception { int a = nextInt ( ) ; int b = nextInt ( ) ; double [ ] p = new double [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { p [ i ] = nextDouble ( ) ; } double [ ] prob = p . clone ( ) ; for ( int i = 1 ; i < a ; i ++ ) { prob [ i ] = prob [ i - 1 ] * prob [ i ] ; } double ans = b + 2 ; for ( int i = a - 1 ; i >= 0 ; i -- ) { double curAns = ( a - i - 1 ) + ( b - i - 1 ) + 1 + ( 1 - prob [ i ] ) * ( b + 1 ) ; ans = Math . min ( ans , curAns ) ; } out . println ( ans ) ; } void run ( ) { try { in = new BufferedReader ( new FileReader ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int tests = nextInt ( ) ; for ( int i = 0 ; i < tests ; i ++ ) { out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; solve ( ) ; } out . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } BufferedReader in ; StringTokenizer st ; PrintWriter out ; final String filename = new String ( \" PasswordProblem \" ) . toLowerCase ( ) ; String nextToken ( ) throws Exception { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( in . readLine ( ) ) ; return st . nextToken ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) throws Exception { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) throws Exception { return Double . parseDouble ( nextToken ( ) ) ; } public static void main ( String [ ] args ) { new PasswordProblem ( ) . run ( ) ; } }", "import java . math . BigDecimal ; import java . math . MathContext ; import java . math . RoundingMode ; import java . util . Arrays ; import java . util . Scanner ; public class A { private static Scanner sc ; private static long start ; public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int i = 0 ; i < t ; i ++ ) { start = System . currentTimeMillis ( ) ; System . out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , i + 1 , exec ( ) ) ; long end = System . currentTimeMillis ( ) ; } } private static final MathContext ROUND_CONTEXT = new MathContext ( 8 , RoundingMode . HALF_EVEN ) ; public static String exec ( ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; BigDecimal [ ] bd = new BigDecimal [ a ] ; for ( int i = 0 ; i < a ; i ++ ) bd [ i ] = new BigDecimal ( sc . next ( ) ) ; BigDecimal [ ] rs = new BigDecimal [ a + 2 ] ; rs [ 0 ] = new BigDecimal ( b + 2 ) ; int backspacesNeeded = a ; double runningChance = 1.0 ; for ( int i = 0 ; i < a ; i ++ ) { int charsNeededOnSuccess = backspacesNeeded + b - i + 1 ; int charsNeededOnFail = charsNeededOnSuccess + b + 1 ; double onSuccess = runningChance * charsNeededOnSuccess ; double onFail = ( 1.0 - runningChance ) * charsNeededOnFail ; rs [ i + 1 ] = new BigDecimal ( onSuccess + onFail ) ; runningChance *= bd [ i ] . doubleValue ( ) ; backspacesNeeded -- ; } rs [ a + 1 ] = new BigDecimal ( ( runningChance * ( b - a + 1 ) ) + ( ( 1.0 - runningChance ) * ( b - a + 1 + b + 1 ) ) ) ; Arrays . sort ( rs ) ; BigDecimal result = rs [ 0 ] ; return String . format ( \" % .06f \" , result ) ; } }", "import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; public class A { static double [ ] logP = new double [ 1 << 17 ] ; public static void main ( String [ ] args ) throws Exception { Scanner s = new Scanner ( new File ( \" A . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" A . out \" ) ) ; int T = s . nextInt ( ) ; for ( int tc = 1 ; tc <= T ; tc ++ ) { out . print ( \" Case ▁ # \" + tc + \" : ▁ \" ) ; int A = s . nextInt ( ) , B = s . nextInt ( ) ; double best = A + B + 1 ; logP [ 0 ] = Math . log ( s . nextDouble ( ) ) ; best = Math . min ( best , ( 2 * ( A - 1 ) + ( B - A ) + 1 ) + ( B + 1 ) - ( B + 1 ) * Math . exp ( logP [ 0 ] ) ) ; for ( int i = 1 ; i < A ; i ++ ) { logP [ i ] = logP [ i - 1 ] + Math . log ( s . nextDouble ( ) ) ; best = Math . min ( best , ( 2 * ( A - 1 - i ) + ( B - A ) + 1 ) + ( B + 1 ) - ( B + 1 ) * Math . exp ( logP [ i ] ) ) ; } best = Math . min ( best , B + 2 ) ; out . println ( best ) ; } out . close ( ) ; } }" ]
[ "import sys NEW_LINE def compute ( A , B , p ) : NEW_LINE INDENT q = 1.0 NEW_LINE smin = B + 2.0 NEW_LINE for i in xrange ( len ( p ) ) : NEW_LINE INDENT q *= p [ i ] NEW_LINE s = ( A - i - 1 ) + q * ( B - i ) + ( 1.0 - q ) * ( B - i + B + 1 ) NEW_LINE if s < smin : NEW_LINE INDENT smin = s NEW_LINE DEDENT DEDENT return \" % f \" % smin NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT A , B = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ' ▁ ' ) ) NEW_LINE p = map ( float , sys . stdin . readline ( ) . strip ( ) . split ( ' ▁ ' ) ) NEW_LINE return ( A , B , p ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE result = compute ( * data ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE import logging NEW_LINE if len ( sys . argv ) > 1 : NEW_LINE INDENT sampledata = False NEW_LINE infname = sys . argv [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT sampledata = True NEW_LINE scriptname = sys . argv [ 0 ] NEW_LINE problemletter = scriptname [ : scriptname . index ( ' . ' ) ] NEW_LINE infname = problemletter + ' - example . in ' NEW_LINE DEDENT outfname = infname [ : infname . index ( ' . ' ) ] + ' . out ' NEW_LINE with open ( infname ) as f : NEW_LINE INDENT text = f . read ( ) NEW_LINE DEDENT lines = text . splitlines ( ) NEW_LINE linesiter = iter ( lines ) NEW_LINE nextline = linesiter . next NEW_LINE ofile = open ( outfname , ' w ' ) NEW_LINE sys . stdout = ofile NEW_LINE T = int ( nextline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT A , B = map ( int , nextline ( ) . split ( ) ) NEW_LINE ps = map ( float , nextline ( ) . split ( ) ) NEW_LINE best = 1 + B + 1 NEW_LINE pcorr = 1.0 NEW_LINE for i , p in enumerate ( ps ) : NEW_LINE INDENT pcorr *= p NEW_LINE ncorr = ( B - A ) + 2 * ( A - i - 1 ) + 1 NEW_LINE pwr = 1 - pcorr NEW_LINE nwr = ncorr + B + 1 NEW_LINE exp = pcorr * ncorr + pwr * nwr NEW_LINE best = min ( best , exp ) NEW_LINE DEDENT print ' Case ▁ # % s : ' % t , best NEW_LINE DEDENT sys . stdout = sys . __stdout__ NEW_LINE ofile . close ( ) NEW_LINE if sampledata : NEW_LINE INDENT base = problemletter + ' - example . ' NEW_LINE outfile = base + ' out ' NEW_LINE rightfile = base + ' right ' NEW_LINE out = open ( outfile ) . read ( ) NEW_LINE right = open ( rightfile ) . read ( ) NEW_LINE if out == right : NEW_LINE INDENT print ' Congrats , ▁ your ▁ output ▁ matches ▁ sample ▁ output ' NEW_LINE DEDENT else : NEW_LINE INDENT print ' OUTPUT ▁ MISMATCH ' NEW_LINE import os NEW_LINE os . system ( ' diff ▁ % s ▁ % s ' % ( outfile , rightfile ) ) NEW_LINE DEDENT DEDENT", "import os , sys , math NEW_LINE def prod ( probs ) : NEW_LINE INDENT x = 1.0 NEW_LINE for p in probs : NEW_LINE INDENT x *= p NEW_LINE DEDENT return x NEW_LINE DEDENT def calcFinish ( A , B , probs ) : NEW_LINE INDENT probRight = prod ( probs ) NEW_LINE return ( ( probRight * ( B - A + 1 ) ) + ( ( 1.0 - probRight ) * ( B - A + 1 + B + 1 ) ) ) NEW_LINE DEDENT def calcEnter ( A , B , probs ) : NEW_LINE INDENT return 1 + B + 1 NEW_LINE DEDENT def calcBackspaces ( A , B , n , probs ) : NEW_LINE INDENT afterBackspace = calcFinish ( A - n , B , probs [ : A - n ] ) NEW_LINE return n + afterBackspace NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT caseStr = fileLines [ index ] [ : - 1 ] NEW_LINE index += 1 NEW_LINE nums = [ int ( x ) for x in caseStr . split ( ' ▁ ' ) ] NEW_LINE A = nums [ 0 ] NEW_LINE B = nums [ 1 ] NEW_LINE caseStr = fileLines [ index ] [ : - 1 ] NEW_LINE index += 1 NEW_LINE probs = [ float ( x ) for x in caseStr . split ( ' ▁ ' ) ] NEW_LINE if len ( probs ) != A : NEW_LINE INDENT print \" WRONG ▁ LENGTH \" NEW_LINE sys . exit ( 1 ) NEW_LINE DEDENT finishStrokes = calcFinish ( A , B , probs ) NEW_LINE enterStrokes = calcEnter ( A , B , probs ) NEW_LINE numBackspaces = [ calcBackspaces ( A , B , n , probs ) for n in range ( 1 , A ) ] NEW_LINE if len ( numBackspaces ) == 0 : NEW_LINE INDENT answer = min ( finishStrokes , enterStrokes ) NEW_LINE DEDENT else : NEW_LINE INDENT answer = min ( finishStrokes , enterStrokes , min ( numBackspaces ) ) NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % f \" % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT", "with open ( ' A - large . in ' , ' r ' ) as fin : NEW_LINE INDENT with open ( ' output . txt ' , ' w ' ) as fout : NEW_LINE INDENT numcases = int ( fin . readline ( ) ) NEW_LINE for i in range ( 1 , numcases + 1 ) : NEW_LINE INDENT line = [ int ( j ) for j in fin . readline ( ) . split ( ) ] NEW_LINE charstyped = line [ 0 ] NEW_LINE numchars = line [ 1 ] NEW_LINE line = [ float ( j ) for j in fin . readline ( ) . split ( ) ] NEW_LINE bestcost = numchars + 2 NEW_LINE correctprob = 1 NEW_LINE for idx in range ( charstyped ) : NEW_LINE INDENT correctprob = correctprob * line [ idx ] NEW_LINE currcost = ( numchars + 1 ) * ( 1 - correctprob ) + ( charstyped - idx - 1 ) + ( numchars - idx - 1 ) + 1 NEW_LINE if currcost < bestcost : NEW_LINE INDENT bestcost = currcost NEW_LINE DEDENT DEDENT fout . write ( \" Case ▁ # \" ) NEW_LINE fout . write ( str ( i ) ) NEW_LINE fout . write ( \" : ▁ \" ) NEW_LINE fout . write ( str ( bestcost ) ) NEW_LINE fout . write ( ' \\n ' ) NEW_LINE print ( i ) NEW_LINE DEDENT DEDENT DEDENT", "testCount = int ( raw_input ( ) ) NEW_LINE for testIndex in range ( testCount ) : NEW_LINE INDENT ans = \" Case ▁ # \" + str ( testIndex + 1 ) + \" : ▁ \" NEW_LINE n , m = [ int ( x ) for x in raw_input ( ) . split ( \" ▁ \" ) ] NEW_LINE p = [ float ( x ) for x in raw_input ( ) . split ( \" ▁ \" ) ] NEW_LINE minType = m + 1.0 NEW_LINE p1 = reduce ( lambda x , y : x * y , p , 1.0 ) NEW_LINE type = ( m - n ) * p1 + ( m - n + 1 + m ) * ( 1 - p1 ) NEW_LINE minType = min ( type , minType ) NEW_LINE p1 = 1.0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT p1 *= p [ i - 1 ] NEW_LINE type = ( n - i + m - i ) * p1 + ( n - i + m - i + 1 + m ) * ( 1 - p1 ) NEW_LINE minType = min ( type , minType ) NEW_LINE DEDENT print ( ans + str ( minType + 1.0 ) ) NEW_LINE DEDENT" ]
codejam_14_01
[ "import java . util . * ; import java . io . * ; public class A { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" A - small - attempt0 . in \" ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( new File ( \" A - small . out \" ) ) ) ; int t = in . nextInt ( ) ; for ( int x = 0 ; x < t ; x ++ ) { int row1 = in . nextInt ( ) - 1 ; HashSet < Integer > cards = new HashSet < Integer > ( ) ; for ( int y = 0 ; y < 4 ; y ++ ) { for ( int z = 0 ; z < 4 ; z ++ ) { int card = in . nextInt ( ) ; if ( y == row1 ) { cards . add ( card ) ; } } } int row2 = in . nextInt ( ) - 1 ; int chosen = - 1 ; int count = 0 ; for ( int a = 0 ; a < 4 ; a ++ ) { for ( int b = 0 ; b < 4 ; b ++ ) { int card = in . nextInt ( ) ; if ( a == row2 && cards . contains ( card ) ) { chosen = card ; count ++ ; } } } out . print ( \" Case ▁ # \" + ( x + 1 ) + \" : ▁ \" ) ; if ( count == 1 ) { out . println ( chosen ) ; } else if ( count == 0 ) { out . println ( \" Volunteer ▁ cheated ! \" ) ; } else { out . println ( \" Bad ▁ magician ! \" ) ; } } out . close ( ) ; } }", "import java . util . Scanner ; public class A { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int cases = in . nextInt ( ) ; for ( int i = 1 ; i <= cases ; i ++ ) { int poss = 0 ; int ans = - 1 ; int a = in . nextInt ( ) - 1 ; int [ ] [ ] first = new int [ 4 ] [ 4 ] ; int [ ] [ ] second = new int [ 4 ] [ 4 ] ; for ( int j = 0 ; j < 4 ; j ++ ) { for ( int k = 0 ; k < 4 ; k ++ ) { first [ j ] [ k ] = in . nextInt ( ) ; } } int b = in . nextInt ( ) - 1 ; for ( int j = 0 ; j < 4 ; j ++ ) { for ( int k = 0 ; k < 4 ; k ++ ) { second [ j ] [ k ] = in . nextInt ( ) ; } } for ( int j = 0 ; j < 4 ; j ++ ) { for ( int k = 0 ; k < 4 ; k ++ ) { if ( first [ a ] [ k ] == second [ b ] [ j ] ) { ans = first [ a ] [ k ] ; poss ++ ; } } } if ( poss > 1 ) { System . out . printf ( \" Case ▁ # % d : ▁ Bad ▁ magician ! \\n \" , i ) ; } else if ( poss == 1 ) { System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , i , ans ) ; } else { System . out . printf ( \" Case ▁ # % d : ▁ Volunteer ▁ cheated ! \\n \" , i ) ; } } } }", "import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Scanner ; public class MagicTrick { public void magic ( ) throws IOException { Scanner sc = new Scanner ( new FileReader ( \" jam . in \" ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( \" jam . out \" ) ) ; int cases ; cases = sc . nextInt ( ) ; for ( int z = 1 ; z <= cases ; z ++ ) { int [ ] [ ] map1 = new int [ 4 ] [ 4 ] ; int [ ] [ ] map2 = new int [ 4 ] [ 4 ] ; int i , j ; int r1 , r2 ; r1 = sc . nextInt ( ) - 1 ; for ( i = 0 ; i < 4 ; i ++ ) for ( j = 0 ; j < 4 ; j ++ ) map1 [ i ] [ j ] = sc . nextInt ( ) ; r2 = sc . nextInt ( ) - 1 ; for ( i = 0 ; i < 4 ; i ++ ) for ( j = 0 ; j < 4 ; j ++ ) map2 [ i ] [ j ] = sc . nextInt ( ) ; int ans = 0 ; int sameNum = 0 ; for ( i = 0 ; i < 4 ; i ++ ) for ( j = 0 ; j < 4 ; j ++ ) if ( map1 [ r1 ] [ i ] == map2 [ r2 ] [ j ] ) { sameNum ++ ; ans = map1 [ r1 ] [ i ] ; } bw . write ( \" Case ▁ # \" + z + \" : ▁ \" ) ; if ( sameNum == 0 ) bw . write ( \" Volunteer ▁ cheated ! \" ) ; else if ( sameNum == 1 ) bw . write ( \" \" + ans ) ; else bw . write ( \" Bad ▁ magician ! \" ) ; bw . write ( \" \\n \" ) ; } bw . close ( ) ; sc . close ( ) ; } }", "package con2014Q ; import java . io . * ; import java . util . * ; public class A { private static final String fileName = \" results / con2014Q / \" + A . class . getSimpleName ( ) . toLowerCase ( ) ; private static final String inputFileName = fileName + \" . in \" ; private static final String outputFileName = fileName + \" . out \" ; private static Scanner in ; private static PrintWriter out ; static final String BAD = \" Bad ▁ magician ! \" , CHEAT = \" Volunteer ▁ cheated ! \" ; private void solve ( ) { int R1 = in . nextInt ( ) ; int possible = 0 ; for ( int i = 1 ; i <= 4 ; i ++ ) { for ( int j = 1 ; j <= 4 ; j ++ ) { int n = in . nextInt ( ) ; if ( i == R1 ) { possible |= ( 1 << n ) ; } } } { R1 = in . nextInt ( ) ; int possible2 = 0 ; for ( int i = 1 ; i <= 4 ; i ++ ) { for ( int j = 1 ; j <= 4 ; j ++ ) { int n = in . nextInt ( ) ; if ( i == R1 ) { possible2 |= ( 1 << n ) ; } } } possible &= possible2 ; } if ( possible == 0 ) { out . println ( CHEAT ) ; } else { int res = - 1 ; for ( int i = 0 ; i <= 16 ; i ++ ) { if ( ( possible & ( 1 << i ) ) == 0 ) continue ; if ( res != - 1 ) { out . println ( BAD ) ; return ; } res = i ; } out . println ( res ) ; } } public static void main ( String [ ] args ) throws IOException { long start = System . currentTimeMillis ( ) ; in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; new A ( ) . solve ( ) ; System . out . println ( \" Case ▁ # \" + t + \" : ▁ solved \" ) ; } in . close ( ) ; out . close ( ) ; long stop = System . currentTimeMillis ( ) ; System . out . println ( stop - start + \" ▁ ms \" ) ; } }", "import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class ProblemA { public static void main ( String [ ] args ) throws Exception { System . setIn ( new FileInputStream ( \" A - small - attempt0 . in \" ) ) ; System . setOut ( new PrintStream ( new FileOutputStream ( \" A - small - attempt0 . out \" ) ) ) ; Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= T ; caseNum ++ ) { int [ ] counts = new int [ 17 ] ; for ( int turn = 0 ; turn < 2 ; turn ++ ) { int row = in . nextInt ( ) - 1 ; for ( int r = 0 ; r < 4 ; r ++ ) { for ( int c = 0 ; c < 4 ; c ++ ) { int n = in . nextInt ( ) ; if ( r == row ) { counts [ n ] ++ ; } } } } int res = - 2 ; for ( int i = 1 ; i <= 16 ; i ++ ) { if ( counts [ i ] == 2 ) { if ( res == - 2 ) { res = i ; } else { res = - 1 ; } } } if ( res > 0 ) { System . out . printf ( \" Case ▁ # % d : ▁ % d % n \" , caseNum , res ) ; } else { System . out . printf ( \" Case ▁ # % d : ▁ % s % n \" , caseNum , ( res == - 2 ) ? \" Volunteer ▁ cheated ! \" : \" Bad ▁ magician ! \" ) ; } } } }" ]
[ "import sys NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( sys . argv [ 1 ] ) NEW_LINE T = int ( f . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT row1 = getRow ( f ) NEW_LINE row2 = getRow ( f ) NEW_LINE cards = list ( row1 & row2 ) NEW_LINE if len ( cards ) == 1 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i , cards [ 0 ] ) NEW_LINE DEDENT elif len ( cards ) > 1 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ Bad ▁ magician ! \" % i NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ Volunteer ▁ cheated ! \" % i NEW_LINE DEDENT DEDENT DEDENT def getRow ( f ) : NEW_LINE INDENT n = int ( f . readline ( ) . strip ( ) ) NEW_LINE row = [ ] NEW_LINE for i in range ( 1 , 5 ) : NEW_LINE INDENT l = f . readline ( ) NEW_LINE if n == i : NEW_LINE INDENT row = set ( l . strip ( ) . split ( ) ) NEW_LINE DEDENT DEDENT return row NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "import math NEW_LINE import sys NEW_LINE def findsol ( C1 , C2 ) : NEW_LINE INDENT a = set ( C1 ) . intersection ( set ( C2 ) ) NEW_LINE if len ( a ) == 0 : NEW_LINE INDENT b = ' Volunteer ▁ cheated ! ' NEW_LINE DEDENT if len ( a ) == 1 : NEW_LINE INDENT b = str ( a . pop ( ) ) NEW_LINE DEDENT if len ( a ) > 1 : NEW_LINE INDENT b = ' Bad ▁ magician ! ' NEW_LINE DEDENT return b NEW_LINE DEDENT def convertnums ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE ii = 0 NEW_LINE for jj in range ( len ( s ) ) : NEW_LINE INDENT if s [ jj ] == ' ▁ ' : NEW_LINE INDENT if ( ii < jj ) : NEW_LINE INDENT a . append ( int ( s [ ii : jj ] ) ) NEW_LINE ii = jj + 1 NEW_LINE DEDENT DEDENT DEDENT a . append ( int ( s [ ii : jj ] ) ) NEW_LINE return a NEW_LINE DEDENT fidi = open ( ' A - small - attempt0 . in ' , ' r ' ) NEW_LINE fido = open ( ' a . out ' , ' w ' ) NEW_LINE T = fidi . readline ( ) NEW_LINE T = int ( T ) NEW_LINE for ii in range ( 1 , T + 1 ) : NEW_LINE INDENT R1 = fidi . readline ( ) NEW_LINE R1 = int ( R1 ) NEW_LINE for jj in range ( 4 ) : NEW_LINE INDENT C = fidi . readline ( ) NEW_LINE if ( jj == R1 - 1 ) : NEW_LINE INDENT C1 = convertnums ( C ) NEW_LINE DEDENT DEDENT R2 = fidi . readline ( ) NEW_LINE R2 = int ( R2 ) NEW_LINE for jj in range ( 4 ) : NEW_LINE INDENT C = fidi . readline ( ) NEW_LINE if ( jj == R2 - 1 ) : NEW_LINE INDENT C2 = convertnums ( C ) NEW_LINE DEDENT DEDENT a = findsol ( C1 , C2 ) NEW_LINE fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + str ( a ) + ' \\n ' ) NEW_LINE print ( ' Case ▁ # ' , str ( ii ) , ' : ▁ ' , str ( a ) ) NEW_LINE DEDENT fidi . close ( ) NEW_LINE fido . close ( ) NEW_LINE", "from collections import deque , defaultdict NEW_LINE E = 0.0 NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( ' A . in ' , ' r ' ) NEW_LINE fout = open ( ' A . out ' , ' w ' ) NEW_LINE T = int ( f . readline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT print ' Case ▁ # ' + str ( t ) + ' : ' , NEW_LINE r1 = int ( f . readline ( ) ) NEW_LINE s1 = getSet ( f , r1 ) NEW_LINE r2 = int ( f . readline ( ) ) NEW_LINE s2 = getSet ( f , r2 ) NEW_LINE res = s1 & s2 NEW_LINE if ( len ( res ) == 1 ) : NEW_LINE INDENT print list ( res ) [ 0 ] NEW_LINE DEDENT elif ( len ( res ) > 1 ) : NEW_LINE INDENT print ' Bad ▁ magician ! ' NEW_LINE DEDENT else : NEW_LINE INDENT print ' Volunteer ▁ cheated ! ' NEW_LINE DEDENT DEDENT DEDENT def getSet ( f , r ) : NEW_LINE INDENT s = set ( ) NEW_LINE for i in range ( 1 , 4 + 1 ) : NEW_LINE INDENT cards = f . readline ( ) . split ( ) NEW_LINE if i == r : NEW_LINE INDENT for card in cards : NEW_LINE INDENT s . add ( card ) NEW_LINE DEDENT DEDENT DEDENT return s NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "import fileinput NEW_LINE import sys NEW_LINE import math NEW_LINE def read_cases ( ) : NEW_LINE INDENT fh = fileinput . input ( ) NEW_LINE T = int ( fh . readline ( ) . strip ( ) ) NEW_LINE cases = [ ] NEW_LINE for t in range ( T ) : NEW_LINE INDENT case = { } NEW_LINE case [ \"1\" ] = { } NEW_LINE case [ \"1\" ] [ \" r \" ] = map ( int , fh . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) [ 0 ] NEW_LINE case [ \"1\" ] [ \" d \" ] = [ ] NEW_LINE for i in range ( 4 ) : NEW_LINE INDENT case [ \"1\" ] [ \" d \" ] += [ map ( int , fh . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) ] NEW_LINE DEDENT case [ \"2\" ] = { } NEW_LINE case [ \"2\" ] [ \" r \" ] = map ( int , fh . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) [ 0 ] NEW_LINE case [ \"2\" ] [ \" d \" ] = [ ] NEW_LINE for i in range ( 4 ) : NEW_LINE INDENT case [ \"2\" ] [ \" d \" ] += [ map ( int , fh . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) ] NEW_LINE DEDENT cases += [ case ] NEW_LINE DEDENT if fh . readline ( ) . strip ( ) != \" \" : NEW_LINE INDENT raise Exception NEW_LINE DEDENT return cases NEW_LINE DEDENT def process_case ( case ) : NEW_LINE INDENT t1 = case [ \"1\" ] [ \" d \" ] [ case [ \"1\" ] [ \" r \" ] - 1 ] NEW_LINE t2 = case [ \"2\" ] [ \" d \" ] [ case [ \"2\" ] [ \" r \" ] - 1 ] NEW_LINE p = set ( t1 ) & set ( t2 ) NEW_LINE if len ( p ) == 1 : NEW_LINE INDENT return list ( p ) [ 0 ] NEW_LINE DEDENT if len ( p ) : NEW_LINE INDENT return \" Bad ▁ magician ! \" NEW_LINE DEDENT return \" Volunteer ▁ cheated ! \" NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT cases = read_cases ( ) NEW_LINE for i , case in enumerate ( cases [ : ] ) : NEW_LINE INDENT result = process_case ( case ) NEW_LINE print \" Case ▁ # % s : \" % ( i + 1 , ) , result NEW_LINE DEDENT DEDENT", "from collections import * NEW_LINE from sys import argv , stdin , stdout , stderr NEW_LINE Case = namedtuple ( ' Case ' , ' selection , ▁ array ' ) NEW_LINE def readcase ( f ) : NEW_LINE INDENT selection = [ int ( next ( f ) ) ] NEW_LINE array = [ [ readints ( f ) for _ in range ( 4 ) ] ] NEW_LINE selection . append ( int ( next ( f ) ) ) NEW_LINE array . append ( [ readints ( f ) for _ in range ( 4 ) ] ) NEW_LINE return Case ( selection , array ) NEW_LINE DEDENT def solvecase ( case ) : NEW_LINE INDENT sets = [ set ( arr [ sel - 1 ] ) for sel , arr in zip ( * case ) ] NEW_LINE possible = sets [ 0 ] & sets [ 1 ] NEW_LINE if not possible : NEW_LINE INDENT return \" Volunteer ▁ cheated ! \" NEW_LINE DEDENT elif len ( possible ) > 1 : NEW_LINE INDENT return ' Bad ▁ magician ! ' NEW_LINE DEDENT else : NEW_LINE INDENT return str ( possible . pop ( ) ) NEW_LINE DEDENT DEDENT def readints ( f ) : NEW_LINE INDENT return list ( map ( int , next ( f ) . split ( ' ▁ ' ) ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT with open ( argv [ 1 ] ) as f , open ( argv [ 2 ] , ' w ' ) as out : NEW_LINE INDENT cases = int ( next ( f ) ) NEW_LINE for case in range ( 1 , cases + 1 ) : NEW_LINE INDENT print ( ' Case ▁ # % d : ▁ % s ' % ( case , solvecase ( readcase ( f ) ) ) , file = out ) NEW_LINE DEDENT DEDENT DEDENT main ( ) NEW_LINE" ]
codejam_12_21
[ "import java . util . Scanner ; public class A { static Scanner in = new Scanner ( System . in ) ; void solve ( ) { int N = in . nextInt ( ) ; int [ ] s = new int [ N ] ; int X = 0 ; for ( int i = 0 ; i < N ; ++ i ) { s [ i ] = in . nextInt ( ) ; X += s [ i ] ; } for ( int i = 0 ; i < N ; ++ i ) { double a = 0.0 ; double b = 1.0 ; for ( int q = 0 ; q < 100 ; ++ q ) { double c = ( a + b ) / 2 ; double val = s [ i ] + c * X ; double used = c * X ; for ( int j = 0 ; j < N ; ++ j ) { if ( i == j ) continue ; if ( s [ j ] >= val ) continue ; used += val - s [ j ] ; } if ( used >= X ) { b = c ; } else { a = c ; } } System . out . print ( String . format ( \" ▁ % .6f \" , 100 * a ) . replace ( \" , \" , \" . \" ) ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int T = in . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( \" Case ▁ # \" + i + \" : \" ) ; new A ( ) . solve ( ) ; } } }", "import java . io . * ; import java . util . * ; public class A implements Runnable { private String IFILE = \" A - large . in \" ; private Scanner in ; private PrintWriter out ; public void Run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int ntest = in . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int n = in . nextInt ( ) ; int [ ] mas = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) mas [ i ] = in . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += mas [ i ] ; double [ ] f = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) f [ i ] = ( mas [ i ] + 0.0 ) / sum ; for ( int i = 0 ; i < n ; i ++ ) { double min = 0.0 ; double max = 1.0 ; while ( max - min > 1e-14 ) { double v = ( min + max ) / 2.0 ; double cv = f [ i ] + v ; double q = 0.0 ; for ( int j = 0 ; j < n ; j ++ ) if ( i != j ) q += Math . max ( cv - f [ j ] , 0 ) ; if ( q < 1.0 - v ) min = v ; else max = v ; } out . print ( \" ▁ \" + 100.0 * max ) ; } out . println ( ) ; } in . close ( ) ; out . close ( ) ; } public void run ( ) { try { Run ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) throws IOException { new A ( ) . Run ( ) ; } }", "package round1 ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { Kattio io ; io = new Kattio ( new FileInputStream ( \" src / round1 / A - large - 0 . in \" ) , new FileOutputStream ( \" src / round1 / A - large - 0 . out \" ) ) ; int cases = io . getInt ( ) ; for ( int i = 1 ; i <= cases ; i ++ ) { io . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; new A ( ) . solve ( io ) ; } io . close ( ) ; } private void solve ( Kattio io ) { int n = io . getInt ( ) , sum = 0 ; int s [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = io . getInt ( ) ; sum += s [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { double lo = 0.0 , hi = 1.0 ; for ( int j = 0 ; j < 200 ; j ++ ) { double x = ( lo + hi ) / 2 ; double isc = s [ i ] + sum * x ; double left = 1 - x ; for ( int k = 0 ; k < n ; k ++ ) { if ( k == i || s [ k ] > isc ) continue ; double y = ( isc - s [ k ] ) / sum ; left -= y ; } if ( left < 0 ) { hi = x ; } else { lo = x ; } } if ( i > 0 ) { io . print ( ' ▁ ' ) ; } io . print ( lo * 100.0 ) ; } io . println ( ) ; } }", "import static java . lang . Math . max ; import java . io . * ; import java . util . * ; public class SafetyInNumbers { public static void main ( String [ ] args ) throws Throwable { Scanner in = new Scanner ( new File ( \" safety . in \" ) ) ; PrintWriter out = new PrintWriter ( \" safety . out \" ) ; int testCount = Integer . parseInt ( in . nextLine ( ) . trim ( ) ) ; for ( int i = 0 ; i < testCount ; i ++ ) { out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : \" ) ; solve ( in , out ) ; } out . close ( ) ; } static void solve ( Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; double [ ] answer = new double [ n ] ; int sum = 0 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; sum += a [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { double l = 0 ; double r = 1 ; for ( int j = 0 ; j < 100 ; j ++ ) { double m = ( l + r ) * .5 ; double currentMan = a [ i ] + m * sum ; double all = m ; for ( int k = 0 ; k < n ; k ++ ) { if ( k == i ) { continue ; } all += max ( 0 , ( currentMan - a [ k ] ) / sum ) ; } if ( all > 1 ) { r = m ; } else { l = m ; } } answer [ i ] = ( l + r ) * 50 ; } for ( double e : answer ) { out . print ( \" ▁ \" + e ) ; } out . println ( ) ; } }", "import java . io . * ; import java . text . DecimalFormat ; import java . util . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { in = new Scanner ( new InputStreamReader ( new FileInputStream ( \" a _ in . txt \" ) ) ) ; out = new PrintStream ( new BufferedOutputStream ( new FileOutputStream ( \" a _ out . txt \" ) ) ) ; int n = in . nextInt ( ) ; in . nextLine ( ) ; int t = 1 ; while ( n -- > 0 ) new A ( ) . solveProblem ( t ++ ) ; out . close ( ) ; } static Scanner in = new Scanner ( new InputStreamReader ( System . in ) ) ; static PrintStream out = new PrintStream ( new BufferedOutputStream ( System . out ) ) ; public void solveProblem ( int nr ) { out . print ( \" Case ▁ # \" + nr + \" : ▁ \" ) ; int n = in . nextInt ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) p [ i ] = in . nextInt ( ) ; double som = 0 ; for ( double pp : p ) som += ( double ) pp ; for ( int i = 0 ; i < n ; i ++ ) { double lo = 0.0 ; double hi = 1. ; for ( int l = 0 ; l < 500 ; l ++ ) { double mid = ( lo + hi ) / 2.0 ; double eind = p [ i ] + mid * som ; double tot = mid ; for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) continue ; if ( p [ j ] >= eind - eps ) continue ; tot += ( eind - p [ j ] ) / som ; } if ( tot > 1.0 ) hi = mid ; else lo = mid ; } double ou = ( 100.0 * lo ) ; if ( ou < eps ) ou = 0.0 ; out . print ( ou ) ; if ( i == n - 1 ) out . println ( ) ; else out . print ( \" ▁ \" ) ; } System . err . println ( \" Case ▁ # \" + nr + \" ▁ solved \" ) ; } double eps = 1e-9 ; }" ]
[ "import sys NEW_LINE import bisect NEW_LINE f = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE T = int ( f . readline ( ) ) NEW_LINE for case in range ( 0 , T ) : NEW_LINE INDENT line = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE ( N , s ) = line [ 0 ] , line [ 1 : ] NEW_LINE total_points = sum ( s ) NEW_LINE temp = s [ : ] NEW_LINE temp . sort ( ) NEW_LINE while total_points > 0 : NEW_LINE INDENT val = temp . pop ( 0 ) NEW_LINE count = 1 NEW_LINE while temp and val == temp [ 0 ] : NEW_LINE INDENT temp . pop ( 0 ) NEW_LINE count += 1 NEW_LINE DEDENT if total_points >= count : NEW_LINE INDENT val += 1 NEW_LINE total_points -= count NEW_LINE DEDENT else : NEW_LINE INDENT val += float ( total_points ) / count NEW_LINE total_points = 0 NEW_LINE DEDENT for i in range ( 0 , count ) : NEW_LINE INDENT bisect . insort ( temp , val ) NEW_LINE DEDENT DEDENT needed = temp [ 0 ] NEW_LINE total_points = sum ( s ) NEW_LINE for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT s [ i ] = max ( 0 , 100 * float ( needed - s [ i ] ) / total_points ) NEW_LINE DEDENT formatted_values = \" ▁ \" . join ( [ \" % 6f \" % value for value in s ] ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( case + 1 , formatted_values ) NEW_LINE DEDENT", "import sys , math , time NEW_LINE filename = \" B \" NEW_LINE inputFilename = filename + \" - large . in \" NEW_LINE outputFilename = filename + \" . txt \" NEW_LINE inputFile = open ( inputFilename , \" r \" ) NEW_LINE outputFile = open ( outputFilename , \" w \" ) NEW_LINE startTime = time . time ( ) NEW_LINE testcases = int ( inputFile . readline ( ) ) NEW_LINE for testcase in range ( testcases ) : NEW_LINE INDENT outputStringHeader = \" Case ▁ # \" + str ( testcase + 1 ) + \" : ▁ \" NEW_LINE outputFile . write ( outputStringHeader ) NEW_LINE print \" Case ▁ # \" , str ( testcase + 1 ) + \" : ▁ \" NEW_LINE inputInts = map ( int , inputFile . readline ( ) . split ( ) ) NEW_LINE N = inputInts [ 0 ] NEW_LINE scores = inputInts [ 1 : ] NEW_LINE solutions = [ None ] * len ( scores ) NEW_LINE X = sum ( scores ) NEW_LINE avgP = 1.0 / float ( len ( scores ) ) NEW_LINE avgS = float ( X ) / float ( len ( scores ) ) NEW_LINE prunedScores = [ ] NEW_LINE prunedCount = 0 NEW_LINE for i in range ( len ( scores ) ) : NEW_LINE INDENT if ( avgP + ( avgS - scores [ i ] ) * ( 1.0 / float ( X ) ) ) >= 0 : NEW_LINE INDENT prunedScores . append ( scores [ i ] ) NEW_LINE solutions [ i ] = 0 NEW_LINE DEDENT else : NEW_LINE INDENT prunedScores . append ( - 1 ) NEW_LINE prunedCount += 1 NEW_LINE DEDENT DEDENT avgP = 1.0 / float ( len ( prunedScores ) - prunedCount ) NEW_LINE avgS = float ( sum ( prunedScores ) + prunedCount ) / float ( len ( prunedScores ) - prunedCount ) NEW_LINE for i in range ( len ( prunedScores ) ) : NEW_LINE INDENT if prunedScores [ i ] != - 1 : NEW_LINE INDENT solutions [ i ] = ( 100 * ( avgP + ( avgS - prunedScores [ i ] ) * ( 1.0 / float ( X ) ) ) ) NEW_LINE DEDENT DEDENT for solution in solutions : NEW_LINE INDENT if solution < 0 : NEW_LINE INDENT solution = 0.0 NEW_LINE DEDENT outputFile . write ( \" % 1.8f ▁ \" % solution ) NEW_LINE DEDENT outputFile . write ( \" \\n \" ) NEW_LINE DEDENT outputFile . close ( ) NEW_LINE inputFile . close ( ) NEW_LINE print time . time ( ) - startTime NEW_LINE", "EPSILON = 0.00000001 NEW_LINE def solve ( N , * votes ) : NEW_LINE INDENT X = sum ( votes ) NEW_LINE def score ( ( i , w ) ) : NEW_LINE INDENT return votes [ i ] + X * w NEW_LINE DEDENT def rebalance ( weights , rem = 1 ) : NEW_LINE INDENT if rem <= EPSILON : NEW_LINE INDENT return weights NEW_LINE DEDENT sorted_pairs = sorted ( enumerate ( weights ) , key = score ) NEW_LINE scores = map ( score , sorted_pairs ) NEW_LINE t = float ( \" inf \" ) NEW_LINE imax = N NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT if scores [ i + 1 ] - scores [ i ] > EPSILON : NEW_LINE INDENT t = scores [ i + 1 ] NEW_LINE imax = i + 1 NEW_LINE break NEW_LINE DEDENT DEDENT if imax * ( t - scores [ 0 ] ) > ( rem * X ) : NEW_LINE INDENT ret = weights [ : ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if i < imax : NEW_LINE INDENT ret [ sorted_pairs [ i ] [ 0 ] ] += rem / float ( imax ) NEW_LINE DEDENT DEDENT return ret NEW_LINE DEDENT new_weights = weights [ : ] NEW_LINE new_rem = rem NEW_LINE w = ( t - scores [ 0 ] ) / float ( X ) NEW_LINE for i in range ( imax ) : NEW_LINE INDENT new_weights [ sorted_pairs [ i ] [ 0 ] ] += w NEW_LINE new_rem -= w NEW_LINE DEDENT return rebalance ( new_weights , new_rem ) NEW_LINE DEDENT return ' ▁ ' . join ( map ( lambda a : str ( 100 * a ) , rebalance ( [ 0 ] * N ) ) ) NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT print \" Case ▁ # % i : ▁ % s \" % ( i + 1 , solve ( * ( int ( s ) for s in raw_input ( ) . split ( ' ▁ ' ) ) ) ) NEW_LINE DEDENT", "import sys NEW_LINE import string NEW_LINE from itertools import combinations NEW_LINE def lowest ( line ) : NEW_LINE INDENT X = sum ( line ) NEW_LINE srted = sorted ( line ) NEW_LINE out = [ 0 ] * len ( line ) NEW_LINE ptsRemaining = X NEW_LINE linecopy = line NEW_LINE best = 0 NEW_LINE for n in srted : NEW_LINE INDENT if sum ( [ max ( n - l , 0 ) for l in line ] ) <= X : NEW_LINE INDENT best = n NEW_LINE DEDENT DEDENT lower = [ best - l for l in line if best - l >= 0 ] NEW_LINE diff = sum ( lower ) NEW_LINE ptsRemaining = X - diff NEW_LINE distPts = ptsRemaining / float ( len ( lower ) ) NEW_LINE linecopy = list ( line ) NEW_LINE for i in range ( len ( linecopy ) ) : NEW_LINE INDENT if linecopy [ i ] < best + distPts : NEW_LINE INDENT linecopy [ i ] = best + distPts NEW_LINE DEDENT DEDENT for i in range ( len ( linecopy ) ) : NEW_LINE INDENT if linecopy [ i ] > line [ i ] : NEW_LINE INDENT out [ i ] = 100 * ( linecopy [ i ] - line [ i ] ) / float ( X ) NEW_LINE DEDENT DEDENT return out NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT infile = open ( sys . argv [ 1 ] ) NEW_LINE lines = [ ] NEW_LINE output = [ ] NEW_LINE infile . readline ( ) NEW_LINE for line in infile : NEW_LINE INDENT lines . append ( [ int ( p ) for p in line . split ( ) [ 1 : ] ] ) NEW_LINE DEDENT caseNum = 1 NEW_LINE for line in lines : NEW_LINE INDENT print caseNum NEW_LINE output . append ( \" Case ▁ # \" + str ( caseNum ) + \" : ▁ \" + ' ▁ ' . join ( [ str ( l ) for l in lowest ( line ) ] ) ) NEW_LINE caseNum += 1 NEW_LINE DEDENT out = open ( ' out . out ' , ' w ' ) NEW_LINE for line in output : NEW_LINE INDENT out . write ( line + ' \\n ' ) NEW_LINE DEDENT DEDENT", "def readline_ints ( ) : NEW_LINE INDENT return [ int ( num ) for num in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT from collections import Counter NEW_LINE def tideline ( scores , X ) : NEW_LINE INDENT cc = Counter ( scores ) NEW_LINE floating = 0 NEW_LINE for score in range ( max ( scores ) + 1 ) : NEW_LINE INDENT floating += cc [ score ] NEW_LINE if floating > X : NEW_LINE INDENT break NEW_LINE DEDENT X -= floating NEW_LINE DEDENT else : NEW_LINE INDENT score += 1 NEW_LINE DEDENT return score + X / floating NEW_LINE DEDENT def find_min_vote_proportions ( scores ) : NEW_LINE INDENT X = sum ( scores ) NEW_LINE points_limit = tideline ( scores , X ) NEW_LINE print ( points_limit ) NEW_LINE proportions_needed = [ ] NEW_LINE for s in scores : NEW_LINE INDENT if s >= points_limit : NEW_LINE INDENT proportions_needed . append ( 0.0 ) NEW_LINE DEDENT else : NEW_LINE INDENT points_needed = points_limit - s NEW_LINE proportions_needed . append ( 100 * points_needed / X ) NEW_LINE DEDENT DEDENT return proportions_needed NEW_LINE DEDENT fname = \" A - large \" NEW_LINE with open ( fname + \" . in \" , \" r \" ) as fin , open ( fname + \" . out \" , \" w \" ) as fout : NEW_LINE INDENT numcases = readline_ints ( ) [ 0 ] NEW_LINE print ( numcases , \" cases \" ) NEW_LINE for caseno in range ( 1 , numcases + 1 ) : NEW_LINE INDENT N , * scores = readline_ints ( ) NEW_LINE result = find_min_vote_proportions ( scores ) NEW_LINE result_str = \" ▁ \" . join ( \" % f \" % p for p in result ) NEW_LINE outstr = \" Case ▁ # % d : ▁ % s \" % ( caseno , result_str ) NEW_LINE fout . write ( outstr + \" \\n \" ) NEW_LINE print ( outstr ) NEW_LINE DEDENT DEDENT" ]
codejam_17_42
[ "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . util . Scanner ; public class RollerCoasterScheduling { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner cin = new Scanner ( new File ( \" B - large . in \" ) ) ; PrintStream cout = new PrintStream ( \" B - large . out \" ) ; int _case = 0 ; for ( int T = cin . nextInt ( ) ; T > 0 ; T -- ) { _case ++ ; int N = cin . nextInt ( ) ; int C = cin . nextInt ( ) ; int M = cin . nextInt ( ) ; int [ ] [ ] a = new int [ C + 1 ] [ N + 1 ] ; for ( int i = 0 ; i < M ; i ++ ) { int p = cin . nextInt ( ) ; int b = cin . nextInt ( ) ; a [ b ] [ p ] ++ ; } int totalTrains = 0 ; for ( int i = 1 ; i <= C ; i ++ ) { int sum = 0 ; for ( int j = 1 ; j <= N ; j ++ ) sum += a [ i ] [ j ] ; totalTrains = Math . max ( totalTrains , sum ) ; } int prefixColSum = 0 ; for ( int j = 1 ; j <= N ; j ++ ) { for ( int i = 1 ; i <= C ; i ++ ) prefixColSum += a [ i ] [ j ] ; totalTrains = Math . max ( totalTrains , ( prefixColSum + j - 1 ) / j ) ; } int promotion = 0 ; for ( int j = N ; j >= 1 ; j -- ) { int sum = 0 ; for ( int i = 1 ; i <= C ; i ++ ) sum += a [ i ] [ j ] ; int extra = Math . max ( 0 , sum - totalTrains ) ; promotion += extra ; } String ans = \" \" + totalTrains + \" ▁ \" + promotion ; cout . printf ( \" Case ▁ # % d : ▁ % s % n \" , _case , ans ) ; } cin . close ( ) ; cout . close ( ) ; } }", "import java . util . * ; public class cjB { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cas = sc . nextInt ( ) ; for ( int cass = 1 ; cass <= cas ; cass ++ ) { System . out . print ( \" Case ▁ # \" + cass + \" : ▁ \" ) ; int seats = sc . nextInt ( ) ; int customers = sc . nextInt ( ) ; int tickets = sc . nextInt ( ) ; int [ ] perCust = new int [ customers ] ; int [ ] perSeat = new int [ seats ] ; int maxPerCust = 0 ; for ( int ttt = 0 ; ttt < tickets ; ttt ++ ) { int ssss = sc . nextInt ( ) - 1 ; int cccc = sc . nextInt ( ) - 1 ; perCust [ cccc ] ++ ; perSeat [ ssss ] ++ ; if ( perCust [ cccc ] > maxPerCust ) { maxPerCust = perCust [ cccc ] ; } } int tt = tickets ; int minCoast = 0 ; while ( tt > 0 ) { minCoast ++ ; tt -= seats ; } if ( minCoast < maxPerCust ) minCoast = maxPerCust ; int tot = 0 ; for ( int qw = 0 ; qw < seats ; qw ++ ) { tot += perSeat [ qw ] ; while ( ( minCoast * ( qw + 1 ) < tot ) ) { minCoast ++ ; } } int promo = 0 ; for ( int qq = 0 ; qq < seats ; qq ++ ) { if ( perSeat [ qq ] > minCoast ) { promo += ( perSeat [ qq ] - minCoast ) ; } } System . out . println ( minCoast + \" ▁ \" + promo ) ; } } }", "package round2 ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int N = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] seats = new int [ N ] ; int [ ] clients = new int [ C ] ; for ( int i = 0 ; i < M ; i ++ ) { int pos = sc . nextInt ( ) - 1 ; int client = sc . nextInt ( ) - 1 ; seats [ pos ] ++ ; clients [ client ] ++ ; } int ansA = 0 ; for ( int i = 0 ; i < clients . length ; i ++ ) { int client = clients [ i ] ; ansA = Math . max ( ansA , client ) ; } int acum = 0 ; for ( int i = 0 ; i < seats . length ; i ++ ) { int seat = seats [ i ] ; acum += seat ; ansA = Math . max ( ansA , ( acum + i ) / ( i + 1 ) ) ; } int ansB = 0 ; for ( int i = 0 ; i < seats . length ; i ++ ) { int seat = seats [ i ] ; if ( seat > ansA ) ansB += seat - ansA ; } System . out . println ( \" Case ▁ # \" + caze + \" : ▁ \" + ansA + \" ▁ \" + ansB ) ; } } }", "import java . util . * ; class B { public static void main ( String [ ] arg ) { Scanner sc = new Scanner ( System . in ) ; int TT = sc . nextInt ( ) ; for ( int ii = 1 ; ii <= TT ; ++ ii ) { int N = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] COUNT = new int [ C + 1 ] ; int [ ] coast = new int [ N + 1 ] ; for ( int i = 0 ; i < M ; ++ i ) { int pos = sc . nextInt ( ) ; int buyer = sc . nextInt ( ) ; COUNT [ buyer ] ++ ; coast [ pos ] ++ ; } int min = 0 ; for ( int i = 0 ; i < COUNT . length ; ++ i ) { if ( COUNT [ i ] > min ) min = COUNT [ i ] ; } min = Math . max ( min , coast [ 1 ] ) ; int max = M ; while ( min < max ) { int piv = ( min + max ) / 2 ; int promotions = canDo ( coast , piv ) ; if ( promotions >= 0 ) { if ( max == piv ) System . err . println ( \" whoops \" ) ; max = piv ; } else { min = piv + 1 ; } } if ( min != max ) System . err . println ( \" never \" ) ; int ans = canDo ( coast , max ) ; System . out . printf ( \" Case ▁ # % d : ▁ % d ▁ % d \\n \" , ii , max , ans ) ; } } public static int canDo ( int [ ] coast , int R ) { int slots_available = 0 ; int promotions = 0 ; for ( int i = 1 ; i < coast . length ; ++ i ) { if ( coast [ i ] > R ) { if ( coast [ i ] - R > slots_available ) { return - 1 ; } int p = ( coast [ i ] - R ) ; slots_available -= p ; promotions += p ; } else if ( coast [ i ] == R ) { } else { slots_available += R - coast [ i ] ; } } return promotions ; } }" ]
[ "import numpy as np NEW_LINE import math NEW_LINE inname = \" input . txt \" NEW_LINE outname = \" output . txt \" NEW_LINE with open ( inname , ' r ' ) as f : NEW_LINE INDENT cases = int ( f . readline ( ) ) NEW_LINE for tc in range ( 1 , cases + 1 ) : NEW_LINE INDENT line = f . readline ( ) . strip ( ) . split ( ' ▁ ' ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE C = int ( line [ 1 ] ) NEW_LINE M = int ( line [ 2 ] ) NEW_LINE Cnum = [ 0 ] * C NEW_LINE Nnum = [ 0 ] * N NEW_LINE for i in range ( M ) : NEW_LINE INDENT line = f . readline ( ) . strip ( ) . split ( ' ▁ ' ) NEW_LINE p = int ( line [ 0 ] ) NEW_LINE b = int ( line [ 1 ] ) NEW_LINE Nnum [ p - 1 ] += 1 NEW_LINE Cnum [ b - 1 ] += 1 NEW_LINE DEDENT Nsum = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT Nsum [ i + 1 ] = Nsum [ i ] + Nnum [ i ] NEW_LINE DEDENT y = 0 NEW_LINE for i in range ( C ) : NEW_LINE INDENT if Cnum [ i ] > y : NEW_LINE INDENT y = Cnum [ i ] NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT a = math . ceil ( Nsum [ i + 1 ] / ( i + 1 ) ) NEW_LINE if a > y : NEW_LINE INDENT y = a NEW_LINE DEDENT DEDENT z = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if Nnum [ i ] > y : NEW_LINE INDENT z += Nnum [ i ] - y NEW_LINE DEDENT DEDENT print ( \" Case ▁ # % d : ▁ % d ▁ % d \" % ( tc , y , z ) ) NEW_LINE DEDENT DEDENT", "def optimalResult ( N , C , positionsByPerson ) : NEW_LINE INDENT fewestRides = 0 NEW_LINE for position in xrange ( 1 , N + 1 ) : NEW_LINE INDENT totalRides = 0 NEW_LINE for B in positionsByPerson : NEW_LINE INDENT rides = 0 NEW_LINE for P in positionsByPerson [ B ] : NEW_LINE INDENT if P <= position : NEW_LINE INDENT rides += 1 NEW_LINE DEDENT DEDENT fewestRides = max ( rides , fewestRides ) NEW_LINE totalRides += rides NEW_LINE DEDENT fewestRides = max ( fewestRides , ( totalRides + position - 1 ) / position ) NEW_LINE DEDENT upgrades = 0 NEW_LINE for position in xrange ( 1 , N + 1 ) : NEW_LINE INDENT frequency = 0 NEW_LINE for B in positionsByPerson : NEW_LINE INDENT for P in positionsByPerson [ B ] : NEW_LINE INDENT if P == position : NEW_LINE INDENT frequency += 1 NEW_LINE DEDENT DEDENT DEDENT upgrades += max ( 0 , frequency - fewestRides ) NEW_LINE DEDENT return ' ▁ ' . join ( map ( str , [ fewestRides , upgrades ] ) ) NEW_LINE DEDENT with open ( ' . . / inputs / B - large . in ' ) as infile : NEW_LINE INDENT with open ( ' . . / outputs / B - large . out ' , ' wb ' ) as outfile : NEW_LINE INDENT cases = int ( infile . readline ( ) ) NEW_LINE for i in xrange ( cases ) : NEW_LINE INDENT [ N , C , M ] = map ( int , infile . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE positionsByPerson = { } NEW_LINE for _ in xrange ( M ) : NEW_LINE INDENT [ P , B ] = map ( int , infile . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE positionsByPerson [ B ] = positionsByPerson . get ( B , [ ] ) + [ P ] NEW_LINE DEDENT for B in positionsByPerson : NEW_LINE INDENT positionsByPerson [ B ] = sorted ( positionsByPerson [ B ] ) NEW_LINE DEDENT outfile . write ( ' Case ▁ # ' + str ( i + 1 ) + ' : ▁ ' ) NEW_LINE outfile . write ( optimalResult ( N , C , positionsByPerson ) ) NEW_LINE outfile . write ( ' \\n ' ) NEW_LINE DEDENT DEDENT DEDENT", "from collections import defaultdict NEW_LINE def solve ( N , C , M , A ) : NEW_LINE INDENT num_bought = defaultdict ( int ) NEW_LINE for p , b in A : NEW_LINE INDENT num_bought [ b ] += 1 NEW_LINE DEDENT tickets = defaultdict ( list ) NEW_LINE for p , b in A : NEW_LINE INDENT tickets [ p ] . append ( b ) NEW_LINE DEDENT for k , v in tickets . iteritems ( ) : NEW_LINE INDENT v . sort ( key = lambda x : num_bought [ x ] ) NEW_LINE DEDENT R = max ( num_bought . values ( ) ) NEW_LINE tickets_sold = len ( A ) NEW_LINE for num_rides in xrange ( R , tickets_sold + 1 ) : NEW_LINE INDENT promos = 0 NEW_LINE awaiting_seat = 0 NEW_LINE for seat in xrange ( N , 0 , - 1 ) : NEW_LINE INDENT new = len ( tickets [ seat ] ) NEW_LINE if awaiting_seat + new <= num_rides : NEW_LINE INDENT awaiting_seat = 0 NEW_LINE DEDENT else : NEW_LINE INDENT if new <= num_rides : NEW_LINE INDENT rem = num_rides - new NEW_LINE awaiting_seat -= rem NEW_LINE awaiting_seat = max ( awaiting_seat , 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT awaiting_seat += ( new - num_rides ) NEW_LINE promos += new - num_rides NEW_LINE DEDENT DEDENT DEDENT if not awaiting_seat : NEW_LINE INDENT return \" { } ▁ { } \" . format ( num_rides , promos ) NEW_LINE DEDENT DEDENT DEDENT def main ( ) : NEW_LINE INDENT with open ( ' in . txt ' , ' r ' ) as fi , open ( ' out . txt ' , ' w ' ) as fo : NEW_LINE INDENT rr = lambda : fi . readline ( ) . strip ( ) NEW_LINE rrM = lambda : map ( int , rr ( ) . split ( ) ) NEW_LINE for tc in xrange ( 1 , 1 + int ( rr ( ) ) ) : NEW_LINE INDENT N , C , M = rrM ( ) NEW_LINE A = [ rrM ( ) for _ in xrange ( M ) ] NEW_LINE zeta = solve ( N , C , M , A ) NEW_LINE outstr = \" Case ▁ # % i : ▁ \" % tc + str ( zeta ) NEW_LINE print outstr NEW_LINE fo . write ( outstr + ' \\n ' ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : main ( ) NEW_LINE", "import numpy as np NEW_LINE LINES_PARAM = 2 NEW_LINE INPUT_FILE_NAME = ' B - large . in ' NEW_LINE OUTPUT_FILE_NAME = ' B - large . out ' NEW_LINE def do_case ( parsed ) : NEW_LINE INDENT n = parsed [ 0 ] [ 0 ] NEW_LINE c = parsed [ 0 ] [ 1 ] NEW_LINE seat = [ 0 for i in range ( n ) ] NEW_LINE rider = [ 0 for i in range ( c ) ] NEW_LINE for l in parsed [ 1 : ] : NEW_LINE INDENT rider [ l [ 1 ] - 1 ] += 1 NEW_LINE seat [ l [ 0 ] - 1 ] += 1 NEW_LINE DEDENT s = np . cumsum ( seat ) NEW_LINE m = max ( rider ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT m = max ( m , ( s [ i ] + i ) // ( i + 1 ) ) NEW_LINE DEDENT pr = sum ( [ max ( 0 , se - m ) for se in seat ] ) NEW_LINE return str ( m ) + ' ▁ ' + str ( pr ) NEW_LINE DEDENT def do_parse ( input ) : NEW_LINE INDENT return [ [ int ( num ) for num in line . rstrip ( ) . split ( \" ▁ \" ) ] for line in input ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT input_f = open ( INPUT_FILE_NAME , ' r ' ) NEW_LINE output = [ ] NEW_LINE num_of_test_cases = int ( input_f . readline ( ) , 10 ) NEW_LINE temp = input_f . readlines ( ) NEW_LINE index = 0 NEW_LINE for test_case in range ( num_of_test_cases ) : NEW_LINE INDENT lines = int ( temp [ index ] . rstrip ( ) . split ( \" ▁ \" ) [ LINES_PARAM ] ) NEW_LINE parsed_input = do_parse ( temp [ index : index + lines + 1 ] ) NEW_LINE index = index + 1 + lines NEW_LINE output . append ( ' Case ▁ # ' + str ( test_case + 1 ) + ' : ▁ ' + do_case ( parsed_input ) ) NEW_LINE DEDENT output_f = open ( OUTPUT_FILE_NAME , ' w ' ) NEW_LINE output_f . write ( ' \\n ' . join ( output ) ) NEW_LINE input_f . close ( ) NEW_LINE output_f . close ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "numInputs = int ( input ( ) ) NEW_LINE for i in range ( numInputs ) : NEW_LINE INDENT N , C , M = [ int ( num ) for num in input ( ) . split ( \" ▁ \" ) ] NEW_LINE custSeats = [ { } , { } ] NEW_LINE seatsBought = set ( ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT seatNum , custNum = [ int ( num ) for num in input ( ) . split ( \" ▁ \" ) ] NEW_LINE seatsBought . add ( seatNum ) NEW_LINE if seatNum in custSeats [ custNum - 1 ] . keys ( ) : NEW_LINE INDENT custSeats [ custNum - 1 ] [ seatNum ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT custSeats [ custNum - 1 ] [ seatNum ] = 1 NEW_LINE DEDENT DEDENT numTicketsBought = [ 0 , 0 ] NEW_LINE for custNum in range ( 2 ) : NEW_LINE INDENT for seatNum in custSeats [ custNum ] . keys ( ) : NEW_LINE INDENT numTicketsBought [ custNum ] += custSeats [ custNum ] [ seatNum ] NEW_LINE DEDENT DEDENT larger = max ( numTicketsBought ) NEW_LINE smaller = min ( numTicketsBought ) NEW_LINE numRides = larger NEW_LINE numPromotions = 0 NEW_LINE for seatNum in seatsBought : NEW_LINE INDENT if seatNum not in custSeats [ 0 ] . keys ( ) or seatNum not in custSeats [ 1 ] . keys ( ) : NEW_LINE INDENT continue NEW_LINE DEDENT if custSeats [ 0 ] [ seatNum ] + custSeats [ 1 ] [ seatNum ] <= larger : NEW_LINE INDENT continue NEW_LINE DEDENT if seatNum == 1 : NEW_LINE INDENT numRides = custSeats [ 0 ] [ seatNum ] + custSeats [ 1 ] [ seatNum ] NEW_LINE DEDENT else : NEW_LINE INDENT numPromotions += custSeats [ 0 ] [ seatNum ] + custSeats [ 1 ] [ seatNum ] - larger NEW_LINE DEDENT DEDENT print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( numRides ) + \" ▁ \" + str ( numPromotions ) ) NEW_LINE DEDENT" ]
codejam_12_01
[ "import java . io . * ; import java . util . * ; public class Googlerese { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String dict = \" yhesocvxduiglbkrztnwjpfmaq \" ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = in . readLine ( ) ; String ans = \" \" ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( j ) < 97 || s . charAt ( j ) > 122 ) { ans += s . charAt ( j ) ; } else { ans += dict . charAt ( s . charAt ( j ) - 97 ) ; } } System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + ans ) ; } } }", "package j2012qualifier ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class A { public static String inputDirectory = \" src / j2012qualifier / \" ; public static String inputFile = \" A . in \" ; public static String outputFile = \" A . out \" ; public static PrintWriter output ; public static void main ( String [ ] args ) throws FileNotFoundException { Scanner s = new Scanner ( new File ( inputDirectory + inputFile ) ) ; output = new PrintWriter ( new File ( inputDirectory + outputFile ) ) ; Map < Character , Character > codeMap = new HashMap < Character , Character > ( ) ; String source = \" qzejp ▁ mysljylc ▁ kd ▁ kxveddknmc ▁ re ▁ jsicpdrysi ▁ rbcpc ▁ ypc ▁ rtcsra ▁ dkh ▁ wyfrepkym ▁ veddknkmkrkcd ▁ de ▁ kr ▁ kd ▁ eoya ▁ kw ▁ aej ▁ tysr ▁ re ▁ ujdr ▁ lkgc ▁ jv \" ; String result = \" zqour ▁ language ▁ is ▁ impossible ▁ to ▁ understand ▁ there ▁ are ▁ twenty ▁ six ▁ factorial ▁ possibilities ▁ so ▁ it ▁ is ▁ okay ▁ if ▁ you ▁ want ▁ to ▁ just ▁ give ▁ up \" ; for ( int i = 0 ; i < source . length ( ) ; i ++ ) { codeMap . put ( source . charAt ( i ) , result . charAt ( i ) ) ; } int cases = s . nextInt ( ) ; s . nextLine ( ) ; for ( int Case = 1 ; Case <= cases ; Case ++ ) { String code = s . nextLine ( ) ; char [ ] uncoded = new char [ code . length ( ) ] ; for ( int i = 0 ; i < uncoded . length ; i ++ ) { uncoded [ i ] = codeMap . get ( code . charAt ( i ) ) ; } String answer = String . valueOf ( uncoded ) ; out ( \" Case ▁ # \" + Case + \" : ▁ \" + answer ) ; } output . flush ( ) ; } public static void out ( String s ) { output . println ( s ) ; } }", "package google . codejam2012 . qualification ; import java . io . BufferedReader ; import java . io . InputStreamReader ; public class SpeakingInTongues { private static String TRANSLATER = \" yhesocvxduiglbkrztnwjpfmaq \" ; private static char translate ( char ch ) { if ( ' a ' <= ch & ch <= ' z ' ) return TRANSLATER . charAt ( ch - ' a ' ) ; else return ch ; } private static String translate ( String s ) { int l = s . length ( ) ; StringBuilder translated = new StringBuilder ( l ) ; for ( int i = 0 ; i < l ; i ++ ) { translated . append ( translate ( s . charAt ( i ) ) ) ; } return translated . toString ( ) ; } public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) , 64 << 10 ) ; int testsNumber = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; for ( int test = 1 ; test <= testsNumber ; test ++ ) { System . out . println ( \" Case ▁ # \" + test + \" : \" + translate ( br . readLine ( ) ) ) ; } } catch ( Exception e ) { System . err . println ( \" Error : \" + e . getMessage ( ) ) ; } } }", "import java . util . Scanner ; import java . io . PrintStream ; import java . io . OutputStream ; import java . io . IOException ; import java . io . FileOutputStream ; import java . util . Arrays ; import java . io . PrintWriter ; import java . io . FileInputStream ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream ; try { inputStream = new FileInputStream ( \" gcj1 . in \" ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } OutputStream outputStream ; try { outputStream = new FileOutputStream ( \" gcj1 . out \" ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; GCJ1 solver = new GCJ1 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } } class GCJ1 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { char [ ] map = { ' y ' , ' h ' , ' e ' , ' s ' , ' o ' , ' c ' , ' v ' , ' x ' , ' d ' , ' u ' , ' i ' , ' g ' , ' l ' , ' b ' , ' k ' , ' r ' , ' z ' , ' t ' , ' n ' , ' w ' , ' j ' , ' p ' , ' f ' , ' m ' , ' a ' , ' q ' } ; int cases = in . nextInt ( ) ; in . nextLine ( ) ; for ( int i = 0 ; i < cases ; i ++ ) { String input = in . nextLine ( ) ; char [ ] output = new char [ input . length ( ) ] ; for ( int j = 0 ; j < output . length ; j ++ ) { if ( input . charAt ( j ) == ' ▁ ' ) output [ j ] = ' ▁ ' ; else output [ j ] = map [ input . charAt ( j ) - ' a ' ] ; } out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new String ( output ) ) ; } } }", "import java . util . * ; import java . io . * ; import java . math . * ; import java . awt . * ; import static java . lang . Math . * ; import static java . lang . Integer . parseInt ; import static java . lang . Double . parseDouble ; import static java . lang . Long . parseLong ; import static java . lang . System . * ; import static java . util . Arrays . * ; import static java . util . Collection . * ; public class A { static char [ ] Cipher = new char [ 256 ] ; public static void train ( ) { String in = \" ejpmysljylckdkxveddknmcrejsicpdrysirbcpcypcrtcsradkhwyfrepkymveddknkmkrkcddekrkdeoyakwaejtysrreujdrlkgcjvyeq \" , out = \" ourlanguageisimpossibletounderstandtherearetwentysixfactorialpossibilitiessoitisokayifyouwanttojustgiveupaoz \" ; fill ( Cipher , ( char ) 0 ) ; for ( int i = 0 ; i < in . length ( ) ; ++ i ) Cipher [ in . charAt ( i ) ] = out . charAt ( i ) ; for ( char i = ' a ' ; i <= ' z ' ; ++ i ) { if ( Cipher [ i ] == 0 ) { char j , k ; for ( j = ' a ' ; j <= ' z ' ; ++ j ) { for ( k = ' a ' ; k <= ' z ' ; ++ k ) if ( Cipher [ k ] == j ) break ; if ( k > ' z ' ) break ; } Cipher [ i ] = j ; } } for ( int i = ' a ' ; i <= ' z ' ; ++ i ) if ( Cipher [ i ] != 0 ) Cipher [ i - ' a ' + ' A ' ] = ( char ) ( i + ( ' A ' - ' a ' ) ) ; } public static void main ( String [ ] args ) throws IOException { train ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( in ) ) ; int T = parseInt ( br . readLine ( ) ) ; for ( int t = 0 ; t ++ < T ; ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; for ( char c : br . readLine ( ) . toCharArray ( ) ) out . print ( Cipher [ c ] == 0 ? c : Cipher [ c ] ) ; out . println ( ) ; } } }" ]
[ "import sys NEW_LINE m = { ' \\n ' : ' ' , ' ▁ ' : ' ▁ ' , ' a ' : ' y ' , ' b ' : ' h ' , ' c ' : ' e ' , ' d ' : ' s ' , ' e ' : ' o ' , ' f ' : ' c ' , ' g ' : ' v ' , ' h ' : ' x ' , ' i ' : ' d ' , ' j ' : ' u ' , ' k ' : ' i ' , ' l ' : ' g ' , ' n ' : ' b ' , ' m ' : ' l ' , ' o ' : ' k ' , ' p ' : ' r ' , ' q ' : ' z ' , ' r ' : ' t ' , ' s ' : ' n ' , ' t ' : ' w ' , ' u ' : ' j ' , ' v ' : ' p ' , ' w ' : ' f ' , ' x ' : ' m ' , ' y ' : ' a ' , ' z ' : ' q ' } NEW_LINE n = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT s = sys . stdin . readline ( ) NEW_LINE print ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) , end = ' ' ) NEW_LINE print ( ' ' . join ( [ m . get ( x , ' [ FAIL : % s ] ' % x ) for x in s ] ) ) NEW_LINE DEDENT", "import sys NEW_LINE def makemap ( ) : NEW_LINE INDENT ALPHA = ' abcdefghijklmnopqrstuvwxyz ' NEW_LINE M = { ' y ' : ' a ' , ' e ' : ' o ' , ' q ' : ' z ' , } NEW_LINE G = ''' ejp ▁ mysljylc ▁ kd ▁ kxveddknmc ▁ re ▁ jsicpdrysi STRNEWLINE rbcpc ▁ ypc ▁ rtcsra ▁ dkh ▁ wyfrepkym ▁ veddknkmkrkcd STRNEWLINE de ▁ kr ▁ kd ▁ eoya ▁ kw ▁ aej ▁ tysr ▁ re ▁ ujdr ▁ lkgc ▁ jv ''' NEW_LINE E = ''' our ▁ language ▁ is ▁ impossible ▁ to ▁ understand STRNEWLINE there ▁ are ▁ twenty ▁ six ▁ factorial ▁ possibilities STRNEWLINE so ▁ it ▁ is ▁ okay ▁ if ▁ you ▁ want ▁ to ▁ just ▁ give ▁ up ''' NEW_LINE assert ( len ( G ) == len ( E ) ) NEW_LINE for i in range ( len ( G ) ) : NEW_LINE INDENT g = G [ i ] NEW_LINE e = E [ i ] NEW_LINE if g in ALPHA : NEW_LINE INDENT assert ( e in ALPHA ) NEW_LINE if g not in M : NEW_LINE INDENT M [ g ] = e NEW_LINE DEDENT else : NEW_LINE INDENT assert ( M [ g ] == e ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT assert ( e not in ALPHA ) NEW_LINE DEDENT DEDENT assert ( len ( M ) == 25 or len ( M ) == 26 ) NEW_LINE assert ( len ( M ) == len ( set ( M . values ( ) ) ) ) NEW_LINE if len ( M ) == 25 : NEW_LINE INDENT g = ' ' . join ( c for c in ALPHA if c not in M ) NEW_LINE e = ' ' . join ( c for c in ALPHA if c not in M . values ( ) ) NEW_LINE M [ g ] = e NEW_LINE DEDENT assert ( len ( M ) == len ( set ( M . values ( ) ) ) ) NEW_LINE assert ( set ( M ) == set ( ALPHA ) ) NEW_LINE return M NEW_LINE DEDENT def trans ( s , M ) : NEW_LINE INDENT return ' ' . join ( M . get ( c , c ) for c in s ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT M = makemap ( ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT s = sys . stdin . readline ( ) NEW_LINE s = trans ( s , M ) NEW_LINE sys . stdout . write ( ' Case ▁ # { } : ▁ ' . format ( i + 1 ) ) NEW_LINE sys . stdout . write ( s ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "dictionary = { ' a ' : ' y ' , ' b ' : ' h ' , ' c ' : ' e ' , ' d ' : ' s ' , ' e ' : ' o ' , ' f ' : ' c ' , ' g ' : ' v ' , ' h ' : ' x ' , ' i ' : ' d ' , ' j ' : ' u ' , ' k ' : ' i ' , ' l ' : ' g ' , ' m ' : ' l ' , ' n ' : ' b ' , ' o ' : ' k ' , ' p ' : ' r ' , ' q ' : ' z ' , ' r ' : ' t ' , ' s ' : ' n ' , ' t ' : ' w ' , ' u ' : ' j ' , ' v ' : ' p ' , ' w ' : ' f ' , ' x ' : ' m ' , ' y ' : ' a ' , ' z ' : ' q ' } NEW_LINE def process_file ( file ) : NEW_LINE INDENT fsock = open ( file ) NEW_LINE text = fsock . read ( ) NEW_LINE fsock . close ( ) NEW_LINE lines = text . split ( ' \\n ' ) NEW_LINE return lines NEW_LINE DEDENT def process_lines ( lines ) : NEW_LINE INDENT ans = [ ] NEW_LINE first = True NEW_LINE for line in lines : NEW_LINE INDENT if first == True : NEW_LINE INDENT first = False NEW_LINE DEDENT else : NEW_LINE INDENT trans = ' ' NEW_LINE for char in line : NEW_LINE INDENT if char in dictionary : NEW_LINE INDENT trans += dictionary [ char ] NEW_LINE DEDENT else : NEW_LINE INDENT trans += char NEW_LINE DEDENT DEDENT if trans != ' ' : NEW_LINE INDENT ans . append ( trans ) NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT import sys NEW_LINE filename = sys . argv [ 1 ] NEW_LINE lines = process_file ( filename ) NEW_LINE res = process_lines ( lines ) NEW_LINE c = 0 NEW_LINE for line in res : NEW_LINE INDENT c += 1 NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( c , line ) NEW_LINE DEDENT DEDENT", "import numpy as N NEW_LINE from string import translate , maketrans NEW_LINE case = 1 NEW_LINE problem = \" A \" NEW_LINE practice = False NEW_LINE if practice : NEW_LINE INDENT practice = \" - practice \" NEW_LINE DEDENT else : NEW_LINE INDENT practice = \" - attempt0\" NEW_LINE DEDENT if case == 0 : NEW_LINE INDENT infile = open ( \" % s - % s % s . in \" % ( problem , \" sample \" , practice ) , ' r ' ) NEW_LINE outfile = open ( \" % s - % s % s . out \" % ( problem , \" sample \" , practice ) , ' w ' ) NEW_LINE DEDENT elif case == 1 : NEW_LINE INDENT infile = open ( \" % s - % s % s . in \" % ( problem , \" small \" , practice ) , ' r ' ) NEW_LINE outfile = open ( \" % s - % s % s . out \" % ( problem , \" small \" , practice ) , ' w ' ) NEW_LINE DEDENT elif case == 2 : NEW_LINE INDENT infile = open ( \" % s - % s % s . in \" % ( problem , \" large \" , practice ) , ' r ' ) NEW_LINE outfile = open ( \" % s - % s % s . out \" % ( problem , \" large \" , practice ) , ' w ' ) NEW_LINE DEDENT else : NEW_LINE INDENT raise ValueError , ' Invalid ▁ case ' NEW_LINE DEDENT alpha = ' abcdefghijklmnopqrstuvwxyz ▁ ' NEW_LINE trans = ' ynficwlbkuomxsevzpdrjgthaq ▁ ' NEW_LINE table = maketrans ( trans , alpha ) NEW_LINE cases = int ( infile . readline ( ) . strip ( ' \\n ' ) ) NEW_LINE for i in range ( cases ) : NEW_LINE INDENT instr = infile . readline ( ) . strip ( ' \\n ' ) NEW_LINE output = translate ( instr , table ) NEW_LINE outfile . write ( ' Case ▁ # % i : ▁ % s \\n ' % ( i + 1 , output ) ) NEW_LINE DEDENT infile . close ( ) NEW_LINE outfile . close ( ) NEW_LINE", "translator = { ' y ' : ' a ' , ' n ' : ' b ' , ' f ' : ' c ' , ' i ' : ' d ' , ' c ' : ' e ' , ' w ' : ' f ' , ' l ' : ' g ' , ' b ' : ' h ' , ' k ' : ' i ' , ' u ' : ' j ' , ' o ' : ' k ' , ' m ' : ' l ' , ' x ' : ' m ' , ' s ' : ' n ' , ' e ' : ' o ' , ' v ' : ' p ' , ' z ' : ' q ' , ' p ' : ' r ' , ' d ' : ' s ' , ' r ' : ' t ' , ' j ' : ' u ' , ' g ' : ' v ' , ' t ' : ' w ' , ' h ' : ' x ' , ' a ' : ' y ' , ' q ' : ' z ' } NEW_LINE with open ( ' A - small - attempt0 . in ' , ' r ' ) as fin : NEW_LINE INDENT with open ( ' output . txt ' , ' w ' ) as fout : NEW_LINE INDENT numcases = int ( fin . readline ( ) ) NEW_LINE for i in range ( 1 , numcases + 1 ) : NEW_LINE INDENT fout . write ( \" Case ▁ # \" ) NEW_LINE fout . write ( str ( i ) ) NEW_LINE fout . write ( \" : ▁ \" ) NEW_LINE line = fin . readline ( ) NEW_LINE for k in line : NEW_LINE INDENT if k in translator : NEW_LINE INDENT fout . write ( translator [ k ] ) NEW_LINE DEDENT elif k . isupper ( ) and k . lower ( ) in translator : NEW_LINE INDENT print \" Hit ▁ upper \" NEW_LINE fout . write ( translator [ k . lower ( ) ] . upper ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT fout . write ( k ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT" ]
codejam_16_13
[ "import java . util . * ; public class C { private static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int C = in . nextInt ( ) ; for ( int thisCase = 1 ; thisCase <= C ; thisCase ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ % d % n \" , thisCase , largestCircle ( ) ) ; } } private static int largestCircle ( ) { int N = in . nextInt ( ) ; int bff [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { bff [ i ] = in . nextInt ( ) - 1 ; } int status [ ] = new int [ N ] ; int chainLength [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { status [ i ] = - 2 ; chainLength [ i ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( bff [ bff [ i ] ] == i ) { status [ i ] = - 1 ; } } int maxLoopSize = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] != - 1 ) { int current = bff [ i ] ; status [ i ] = i ; int steps = 1 ; boolean done = false ; while ( ! done ) { if ( current == i ) { if ( steps > maxLoopSize ) { maxLoopSize = steps ; } done = true ; } else if ( status [ current ] == i ) { done = true ; } else if ( status [ current ] == - 1 ) { if ( steps > chainLength [ current ] ) { chainLength [ current ] = steps ; } done = true ; } else { steps ++ ; status [ current ] = i ; current = bff [ current ] ; } } } } int frankenCircle = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( status [ i ] == - 1 ) { frankenCircle += ( chainLength [ i ] + 1 ) ; } } return Math . max ( frankenCircle , maxLoopSize ) ; } }", "import java . io . * ; import java . util . * ; public class C { int solveOne ( Scanner in ) { int n = in . nextInt ( ) ; int f [ ] = new int [ 1 + n ] ; for ( int i = 1 ; i <= n ; i ++ ) { f [ i ] = in . nextInt ( ) ; } boolean inPair [ ] = new boolean [ 1 + n ] ; for ( int i = 1 ; i <= n ; i ++ ) { if ( f [ f [ i ] ] == i ) { inPair [ i ] = true ; } } int chainLen [ ] = new int [ 1 + n ] ; boolean used [ ] = new boolean [ 1 + n ] ; int maxCircleLen = 0 ; for ( int first = 1 ; first <= n ; first ++ ) { if ( inPair [ first ] ) { continue ; } Arrays . fill ( used , false ) ; used [ first ] = true ; int cur = first ; int len = 1 ; while ( true ) { int next = f [ cur ] ; if ( inPair [ next ] ) { chainLen [ next ] = Math . max ( chainLen [ next ] , len ) ; break ; } if ( next == first ) { maxCircleLen = Math . max ( maxCircleLen , len ) ; break ; } if ( used [ next ] ) { break ; } used [ next ] = true ; len ++ ; cur = next ; } } int joinLen = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( inPair [ i ] ) { joinLen += 1 + chainLen [ i ] ; } } return Math . max ( maxCircleLen , joinLen ) ; } void solve ( Scanner in , PrintWriter out ) { int nTests = in . nextInt ( ) ; for ( int iTest = 1 ; iTest <= nTests ; iTest ++ ) { out . printf ( \" Case ▁ # % d : ▁ % d % n \" , iTest , solveOne ( in ) ) ; } } void run ( ) { try ( Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; ) { solve ( in , out ) ; } } public static void main ( String args [ ] ) { new C ( ) . run ( ) ; } }", "package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = Integer . parseInt ( in . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { boolean is = false ; int m = Integer . parseInt ( in . next ( ) ) ; int [ ] k = new int [ m ] ; int [ ] h = new int [ m ] ; int min = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { h [ j ] = 0 ; k [ j ] = Integer . parseInt ( in . next ( ) ) - 1 ; } System . out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; int fullcounter = 0 ; ArrayList < Integer > q = new ArrayList < > ( ) ; for ( int j = 0 ; j < m ; j ++ ) { int p = j ; for ( int z = 0 ; z < m + 2 ; z ++ ) { if ( k [ k [ p ] ] == p ) { if ( z > h [ p ] || ! q . contains ( p ) ) { fullcounter -= h [ p ] ; fullcounter += z ; if ( ! q . contains ( p ) ) { q . add ( p ) ; fullcounter ++ ; } h [ p ] = z ; } if ( min < fullcounter ) { min = fullcounter ; } z = m + 1 ; continue ; } p = k [ p ] ; if ( z > 0 && p == k [ j ] ) { if ( min < z ) { min = z ; } z = m + 1 ; } } } System . out . println ( min ) ; } } }", "package Round1A2016 ; import java . lang . reflect . Array ; import java . util . Arrays ; import java . util . Scanner ; public class C { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int testCase = 1 ; testCase <= T ; ++ testCase ) { final int n = sc . nextInt ( ) ; int [ ] bff = new int [ n ] ; boolean [ ] hasIncoming = new boolean [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { bff [ i ] = sc . nextInt ( ) - 1 ; hasIncoming [ bff [ i ] ] = true ; } int [ ] loop = new int [ n ] ; int maxPeriod = 0 ; for ( int i = 0 ; i < n ; ++ i ) { boolean [ ] visited = new boolean [ n ] ; int cur = 0 ; int [ ] index = new int [ n ] ; int j = i ; while ( ! visited [ j ] ) { visited [ j ] = true ; index [ j ] = cur ++ ; j = bff [ j ] ; } final int period = cur - index [ j ] ; for ( int k = 0 ; k < period ; ++ k ) { loop [ j ] = period ; j = bff [ j ] ; } maxPeriod = Math . max ( maxPeriod , period ) ; } int [ ] maxChain = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { if ( hasIncoming [ i ] ) continue ; int j = i ; int chain = 0 ; while ( loop [ j ] == 0 ) { ++ chain ; j = bff [ j ] ; } maxChain [ j ] = Math . max ( maxChain [ j ] , chain ) ; } int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( loop [ i ] == 2 ) { sum += 1 + maxChain [ i ] ; } } System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , testCase , Math . max ( sum , maxPeriod ) ) ; } } }", "import java . util . * ; class C { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int tcc = sc . nextInt ( ) ; for ( int tc = 1 ; tc <= tcc ; ++ tc ) { int n = sc . nextInt ( ) ; Kid [ ] kids = new Kid [ n ] ; for ( int i = 0 ; i < n ; ++ i ) kids [ i ] = new Kid ( i + 1 ) ; for ( int i = 0 ; i < n ; ++ i ) kids [ i ] . bff = kids [ sc . nextInt ( ) - 1 ] ; int maxCycle = 0 ; for ( Kid first : kids ) { Set < Kid > set = new HashSet < Kid > ( ) ; Kid k = first ; for ( ; ; ) { if ( set . contains ( k ) ) { if ( k == first ) { first . cycle = set . size ( ) ; maxCycle = Math . max ( maxCycle , first . cycle ) ; } break ; } set . add ( k ) ; k = k . bff ; } } for ( Kid first : kids ) { Set < Kid > set = new HashSet < Kid > ( ) ; Kid k = first ; for ( ; ; ) { if ( set . contains ( k ) ) { if ( k . cycle == 2 ) { k . brings = Math . max ( k . brings , set . size ( ) - 1 ) ; } break ; } set . add ( k ) ; k = k . bff ; } } int brings = 0 ; for ( Kid k : kids ) if ( k . cycle == 2 ) brings += k . brings ; System . out . printf ( \" Case ▁ # % d : ▁ % d % n \" , tc , Math . max ( maxCycle , brings ) ) ; } } } class Kid { public Kid bff ; public int index ; public int cycle = 0 ; public int brings = 0 ; public Kid ( int index ) { this . index = index ; } public String toString ( ) { return this . index + \" ( \" + this . cycle + \" , \" + this . brings + \" ) \" ; } }" ]
[ "def chain ( b , x ) : NEW_LINE INDENT sz = 1 NEW_LINE for i in range ( len ( b ) ) : NEW_LINE INDENT if b [ i ] == x and b [ x ] != i : NEW_LINE INDENT sz = max ( sz , 1 + chain ( b , i ) ) NEW_LINE DEDENT DEDENT return sz NEW_LINE DEDENT def solve ( b ) : NEW_LINE INDENT mx = 0 NEW_LINE for i in range ( len ( b ) ) : NEW_LINE INDENT seen = [ 0 ] * len ( b ) NEW_LINE seen [ i ] = 1 NEW_LINE cur = i NEW_LINE while seen [ b [ cur ] ] == 0 : NEW_LINE INDENT seen [ b [ cur ] ] = seen [ cur ] + 1 NEW_LINE cur = b [ cur ] NEW_LINE DEDENT mx = max ( seen [ cur ] - seen [ b [ cur ] ] + 1 , mx ) NEW_LINE DEDENT c = 0 NEW_LINE for i in range ( len ( b ) ) : NEW_LINE INDENT if b [ b [ i ] ] == i : NEW_LINE INDENT c += chain ( b , i ) + chain ( b , b [ i ] ) NEW_LINE DEDENT DEDENT return max ( c / 2 , mx ) NEW_LINE DEDENT T_max = int ( raw_input ( ) ) NEW_LINE for T in range ( T_max ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE bffs = map ( int , raw_input ( ) . split ( \" ▁ \" ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT bffs [ i ] -= 1 NEW_LINE DEDENT out = \" Case ▁ # \" + str ( T + 1 ) + \" : ▁ \" + str ( solve ( bffs ) ) NEW_LINE print out NEW_LINE DEDENT", "task = ' C ' NEW_LINE type = 2 NEW_LINE if type == 0 : NEW_LINE INDENT inp = open ( ' sample . in ' , ' r ' ) NEW_LINE DEDENT elif type == 1 : NEW_LINE INDENT inp = open ( ' % s - small . in ' % ( task , ) ) NEW_LINE DEDENT else : NEW_LINE INDENT inp = open ( ' % s - large . in ' % ( task ) , ) NEW_LINE DEDENT outp = open ( ' % s . out ' % ( task , ) , ' w ' ) NEW_LINE T = int ( inp . readline ( ) [ : - 1 ] ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT N = int ( inp . readline ( ) [ : - 1 ] ) NEW_LINE edges = [ - 1 for i in range ( N ) ] NEW_LINE revedges = [ list ( ) for i in range ( N ) ] NEW_LINE st = inp . readline ( ) [ : - 1 ] . split ( ) NEW_LINE def dfs ( v ) : NEW_LINE INDENT anses = [ 0 ] NEW_LINE for v2 in revedges [ v ] : NEW_LINE INDENT anses . append ( dfs ( v2 ) + 1 ) NEW_LINE DEDENT return max ( anses ) NEW_LINE DEDENT for j , a in zip ( range ( N ) , st ) : NEW_LINE INDENT a = int ( a ) - 1 NEW_LINE edges [ j ] = a NEW_LINE revedges [ a ] . append ( j ) NEW_LINE DEDENT pairs = set ( ) NEW_LINE loncyc = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT used = [ - 1 for i in range ( N ) ] NEW_LINE cur = i NEW_LINE curs = 0 NEW_LINE while used [ cur ] == - 1 : NEW_LINE INDENT used [ cur ] = curs NEW_LINE curs += 1 NEW_LINE cur = edges [ cur ] NEW_LINE DEDENT if curs - used [ cur ] == 2 : NEW_LINE INDENT pairs . add ( cur ) NEW_LINE DEDENT loncyc = max ( loncyc , curs - used [ cur ] ) NEW_LINE DEDENT pairtokens_sum = 0 NEW_LINE while len ( pairs ) > 0 : NEW_LINE INDENT cur1 = pairs . pop ( ) NEW_LINE cur2 = edges [ cur1 ] NEW_LINE revedges [ cur1 ] . remove ( cur2 ) NEW_LINE revedges [ cur2 ] . remove ( cur1 ) NEW_LINE pairs . remove ( cur2 ) NEW_LINE curs = 2 + dfs ( cur1 ) + dfs ( cur2 ) NEW_LINE pairtokens_sum += curs NEW_LINE DEDENT ans = max ( pairtokens_sum , loncyc ) NEW_LINE outp . write ( \" Case ▁ # % s : ▁ % s \\n \" % ( t + 1 , ans ) ) NEW_LINE DEDENT", "import sys NEW_LINE sys . stdin = open ( \" data . txt \" ) NEW_LINE sys . stdout = open ( \" out . txt \" , \" w \" ) NEW_LINE input = sys . stdin . readline NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE g = [ ] NEW_LINE friend = [ ] NEW_LINE def dfs ( u , n ) : NEW_LINE INDENT v = u NEW_LINE for i in range ( 1 , n + 2 ) : NEW_LINE INDENT v = friend [ v ] NEW_LINE if u == v : return i NEW_LINE DEDENT else : NEW_LINE INDENT return 1 NEW_LINE DEDENT DEDENT def depth ( u , bad ) : NEW_LINE INDENT out = 0 NEW_LINE for v in g [ u ] : NEW_LINE INDENT if v != bad : NEW_LINE INDENT out = max ( out , depth ( v , bad ) ) NEW_LINE DEDENT DEDENT return out + 1 NEW_LINE DEDENT def getpairs ( ) : NEW_LINE INDENT out = 0 NEW_LINE for i in range ( len ( g ) ) : NEW_LINE INDENT if friend [ friend [ i ] ] == i : NEW_LINE INDENT out += depth ( i , friend [ i ] ) + depth ( friend [ i ] , i ) NEW_LINE DEDENT DEDENT return out // 2 NEW_LINE DEDENT for c in range ( int ( input ( ) ) ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE friend = list ( map ( lambda s : int ( s ) - 1 , input ( ) . split ( ) ) ) NEW_LINE ans = 0 NEW_LINE g = [ [ ] for _ in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT g [ friend [ i ] ] . append ( i ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT ans = max ( ans , dfs ( i , n ) ) NEW_LINE DEDENT ans = max ( ans , getpairs ( ) ) NEW_LINE print ( \" Case ▁ # % s : ▁ % s \" % ( c + 1 , ans ) ) NEW_LINE DEDENT", "import sys NEW_LINE fin = open ( sys . argv [ 1 ] , \" r \" ) NEW_LINE fout = open ( \" p3 . out \" , \" w \" ) NEW_LINE T = int ( fin . readline ( ) ) NEW_LINE for tt in xrange ( T ) : NEW_LINE INDENT N = int ( fin . readline ( ) ) NEW_LINE out = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE out = map ( lambda x : x - 1 , out ) NEW_LINE ans = 0 NEW_LINE best = [ 0 for j in xrange ( N ) ] NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT cur = i NEW_LINE vis = [ 0 for j in xrange ( N ) ] NEW_LINE vis [ cur ] = 1 NEW_LINE while vis [ out [ cur ] ] == 0 : NEW_LINE INDENT vis [ out [ cur ] ] = 1 NEW_LINE cur = out [ cur ] NEW_LINE DEDENT if out [ cur ] == i : NEW_LINE INDENT ans = max ( ans , sum ( vis ) ) NEW_LINE DEDENT if out [ out [ cur ] ] == cur : NEW_LINE INDENT best [ cur ] = max ( best [ cur ] , sum ( vis ) ) NEW_LINE DEDENT DEDENT tot = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT if out [ out [ i ] ] == i : NEW_LINE INDENT tot += best [ i ] + best [ out [ i ] ] - 2 NEW_LINE DEDENT DEDENT tot /= 2 NEW_LINE ans = max ( ans , tot ) NEW_LINE fout . write ( \" Case ▁ # \" + str ( tt + 1 ) + \" : ▁ \" + str ( ans ) + \" \\n \" ) NEW_LINE DEDENT", "def longestdfs ( inedges , start , seen ) : NEW_LINE INDENT seen . add ( start ) NEW_LINE if not inedges [ start ] : NEW_LINE INDENT return 1 NEW_LINE DEDENT candidates = [ ] NEW_LINE for inedge in inedges [ start ] : NEW_LINE INDENT candidates . append ( longestdfs ( inedges , inedge , seen ) ) NEW_LINE DEDENT return max ( candidates ) + 1 NEW_LINE DEDENT cases = int ( input ( ) ) NEW_LINE for case in range ( cases ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE toedges = [ int ( x ) - 1 for x in input ( ) . split ( ) ] NEW_LINE inedges = [ [ ] for x in toedges ] NEW_LINE for i , to in enumerate ( toedges ) : NEW_LINE INDENT inedges [ to ] . append ( i ) NEW_LINE DEDENT mutuals = [ ] NEW_LINE for i , to in enumerate ( toedges ) : NEW_LINE INDENT if toedges [ to ] == i and to > i : NEW_LINE INDENT mutuals . append ( ( to , i ) ) NEW_LINE inedges [ to ] . remove ( i ) NEW_LINE inedges [ i ] . remove ( to ) NEW_LINE DEDENT DEDENT mdepths = [ ] NEW_LINE seen = set ( ) NEW_LINE for a , b in mutuals : NEW_LINE INDENT mdepths . append ( longestdfs ( inedges , a , seen ) + longestdfs ( inedges , b , seen ) ) NEW_LINE DEDENT cyclemax = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i in seen : NEW_LINE INDENT continue NEW_LINE DEDENT seen . add ( i ) NEW_LINE length = 1 NEW_LINE tempi = toedges [ i ] NEW_LINE path = [ i , tempi ] NEW_LINE while tempi != i : NEW_LINE INDENT if tempi in seen : NEW_LINE INDENT length -= path . index ( tempi ) NEW_LINE break NEW_LINE DEDENT seen . add ( tempi ) NEW_LINE length += 1 NEW_LINE tempi = toedges [ tempi ] NEW_LINE path . append ( tempi ) NEW_LINE DEDENT cyclemax = max ( length , cyclemax ) NEW_LINE DEDENT ans = max ( sum ( mdepths ) , cyclemax ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } \" . format ( case + 1 , ans ) ) NEW_LINE DEDENT" ]
codejam_11_04
[ "import java . io . * ; import java . util . * ; public class Goro { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new FileReader ( \" D - large . in \" ) ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output \" ) ) ; for ( int I = 1 ; I <= T ; I ++ ) { int N = Integer . parseInt ( br . readLine ( ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) , \" ▁ \" , false ) ; int ret = N ; for ( int i = 0 ; i < N ; i ++ ) { int k = Integer . parseInt ( st . nextToken ( ) ) ; if ( k == i + 1 ) ret -- ; } pw . println ( \" Case ▁ # \" + I + \" : ▁ \" + ret + \" . 000000\" ) ; } br . close ( ) ; pw . flush ( ) ; pw . close ( ) ; } catch ( IOException ie ) { ie . printStackTrace ( ) ; } } }", "import java . util . * ; import java . io . * ; public class Solution { public void doIt ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; final int MAX = 1000 ; double [ ] invFact = new double [ MAX + 1 ] ; invFact [ 0 ] = 1.0 ; for ( int i = 1 ; i <= MAX ; i ++ ) invFact [ i ] = invFact [ i - 1 ] / ( double ) i ; double [ ] derang = new double [ MAX + 1 ] ; derang [ 0 ] = invFact [ 0 ] ; for ( int i = 1 ; i <= MAX ; i ++ ) derang [ i ] = derang [ i - 1 ] + ( i % 2 == 1 ? - 1 : 1 ) * invFact [ i ] ; double [ ] avgTime = new double [ MAX + 1 ] ; avgTime [ 0 ] = 0.0 ; for ( int i = 1 ; i <= MAX ; i ++ ) { double sum = 1.0 ; for ( int j = 1 ; j <= i ; j ++ ) sum += avgTime [ i - j ] * invFact [ j ] * derang [ i - j ] ; avgTime [ i ] = sum / ( 1 - invFact [ 0 ] * derang [ i ] ) ; } int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { int N = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int x = sc . nextInt ( ) ; if ( x != i ) ans ++ ; } pw . println ( \" Case ▁ # \" + ( caseNum + 1 ) + \" : ▁ \" + ans ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) throws Exception { new Solution ( ) . doIt ( ) ; } }", "import java . util . * ; public class d { static double [ ] memo = new double [ 1010 ] ; static double [ ] [ ] memoo = new double [ 1010 ] [ 1010 ] ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int n = in . nextInt ( ) ; int k = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( i != in . nextInt ( ) ) k ++ ; System . out . printf ( \" Case ▁ # % d : ▁ % f % n \" , t , ( double ) k ) ; } } public static double f ( int k , int j ) { if ( j < 0 || j > k ) return 0 ; if ( k == 0 && j == 0 ) return 1 ; if ( memoo [ k ] [ j ] != 0 ) return memoo [ k ] [ j ] ; double ans = f ( k - 1 , j - 1 ) + f ( k - 1 , j ) * ( k - 1 - j ) + f ( k - 1 , j + 1 ) * ( j + 1 ) ; ans /= k ; return memoo [ k ] [ j ] = ans ; } public static double go ( int k ) { if ( k == 0 ) return 0 ; if ( memo [ k ] != 0 ) return memo [ k ] ; double total = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { total += f ( k , i ) * go ( k - i ) ; } total /= ( 1 - f ( k , 0 ) ) ; return memo [ k ] = total ; } }", "import java . io . * ; import java . util . * ; import java . math . * ; public class Main implements Runnable { String file = \" D - large \" ; private void solve ( ) throws IOException { int tn = nextInt ( ) ; for ( int testN = 1 ; testN <= tn ; ++ testN ) { int n = nextInt ( ) ; int ans = n ; for ( int i = 0 ; i < n ; ++ i ) { if ( nextInt ( ) == i + 1 ) { -- ans ; } } out . printf ( \" Case ▁ # % d : ▁ % d . 000000 \\n \" , testN , ans ) ; } } public static void main ( String [ ] args ) { new Thread ( new Main ( ) ) . start ( ) ; } StringTokenizer tok ; PrintWriter out ; BufferedReader br ; @ Override public void run ( ) { try { Locale . setDefault ( Locale . US ) ; out = new PrintWriter ( new FileWriter ( file + \" . out \" ) ) ; br = new BufferedReader ( new FileReader ( file + \" . in \" ) ) ; tok = new StringTokenizer ( \" \" ) ; while ( hasNext ( ) ) { solve ( ) ; } out . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } boolean hasNext ( ) throws IOException { while ( ! tok . hasMoreElements ( ) ) { String line = br . readLine ( ) ; if ( line == null ) { return false ; } tok = new StringTokenizer ( line ) ; } return true ; } String next ( ) throws IOException { if ( hasNext ( ) ) { return tok . nextToken ( ) ; } throw new IOException ( \" No ▁ more ▁ tokens \" ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) throws IOException { if ( hasNext ( ) ) { return tok . nextToken ( \" \\n \" ) ; } throw new IOException ( \" No ▁ more ▁ tokens \" ) ; } }", "import java . io . File ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class D { static double [ ] dpc = new double [ 1024 ] ; static double [ ] dpa = new double [ 1024 ] ; public static void main ( String [ ] args ) throws Exception { Scanner s = new Scanner ( new File ( \" D . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" D . out \" ) ) ; dpc [ 1 ] = 0 ; dpc [ 2 ] = 2 ; dpa [ 1 ] = 0 ; dpa [ 2 ] = 1 ; for ( int i = 3 ; i <= 1000 ; i ++ ) { dpc [ i ] = 1 ; for ( int j = 1 ; j < i ; j ++ ) { dpc [ i ] += ( dpc [ j ] + dpa [ i - j ] ) / i ; } dpc [ i ] *= ( ( double ) i ) / ( i - 1 ) ; dpa [ i ] = dpc [ i ] - 1 ; } int T = s . nextInt ( ) ; int [ ] arr = new int [ 1024 ] ; boolean [ ] mark = new boolean [ 1024 ] ; for ( int tc = 1 ; tc <= T ; tc ++ ) { out . print ( \" Case ▁ # \" + tc + \" : ▁ \" ) ; int N = s . nextInt ( ) ; for ( int i = 1 ; i <= N ; i ++ ) arr [ i ] = s . nextInt ( ) ; double answer = 0 ; Arrays . fill ( mark , false ) ; for ( int i = 1 ; i <= N ; i ++ ) { int cycleLength = 0 ; int cur = i ; while ( ! mark [ cur ] ) { mark [ cur ] = true ; cur = arr [ cur ] ; cycleLength ++ ; } answer += dpc [ cycleLength ] ; } out . println ( answer ) ; } out . close ( ) ; System . out . println ( dpc [ 1000 ] ) ; } }" ]
[ "import sys NEW_LINE def c ( ) : NEW_LINE INDENT t = int ( sys . stdin . readline ( ) ) NEW_LINE for i in xrange ( t ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE arr = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE arr = [ x - 1 for x in arr ] NEW_LINE assert len ( arr ) == n NEW_LINE count = 0 NEW_LINE seen = [ False for _ in xrange ( n ) ] NEW_LINE for ix , x in enumerate ( arr ) : NEW_LINE INDENT if x == ix : NEW_LINE INDENT continue NEW_LINE DEDENT while not seen [ x ] : NEW_LINE INDENT seen [ x ] = True NEW_LINE x = arr [ x ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , count ) NEW_LINE DEDENT DEDENT c ( ) NEW_LINE", "def get_permutation ( L1 , L2 ) : NEW_LINE INDENT if sorted ( L1 ) != sorted ( L2 ) : NEW_LINE INDENT raise ValueError ( \" L2 ▁ must ▁ be ▁ permutation ▁ of ▁ L1 ▁ ( % s , ▁ % s ) \" % ( L1 , L2 ) ) NEW_LINE DEDENT permutation = map ( dict ( ( v , i ) for i , v in enumerate ( L1 ) ) . get , L2 ) NEW_LINE assert [ L1 [ p ] for p in permutation ] == L2 NEW_LINE return permutation NEW_LINE DEDENT def get_cycles ( permutation ) : NEW_LINE INDENT nswaps = 0 NEW_LINE seen = set ( ) NEW_LINE cycles = [ ] NEW_LINE for i in xrange ( len ( permutation ) ) : NEW_LINE INDENT if i not in seen : NEW_LINE INDENT j = i NEW_LINE cycles . append ( [ i + 1 ] ) NEW_LINE while permutation [ j ] != i : NEW_LINE INDENT j = permutation [ j ] NEW_LINE seen . add ( j ) NEW_LINE nswaps += 1 NEW_LINE cycles [ - 1 ] . append ( j + 1 ) NEW_LINE DEDENT DEDENT DEDENT return cycles NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT f = open ( \" input . txt \" ) NEW_LINE testlen = int ( f . readline ( ) . strip ( ) ) NEW_LINE tests = [ ] NEW_LINE i = 0 NEW_LINE for line in f : NEW_LINE INDENT if i % 2 : NEW_LINE INDENT tests . append ( line . strip ( ) ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT tests = tests [ : testlen ] NEW_LINE for test , i in zip ( tests , range ( testlen ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , solve ( parse ( test ) ) ) NEW_LINE DEDENT DEDENT def parse ( test ) : NEW_LINE INDENT return map ( int , test . split ( \" ▁ \" ) ) NEW_LINE DEDENT def solve ( test ) : NEW_LINE INDENT perm = get_permutation ( test , sorted ( test ) ) NEW_LINE cycles = get_cycles ( perm ) NEW_LINE v = 0 NEW_LINE for cy in cycles : NEW_LINE INDENT if len ( cy ) > 1 : NEW_LINE INDENT v += len ( cy ) NEW_LINE DEDENT DEDENT return \" % d . 000000\" % ( v ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "import sys NEW_LINE def process ( num , fin , fout ) : NEW_LINE INDENT n = int ( fin . readline ( ) ) NEW_LINE data = [ int ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE unmatched = 0 NEW_LINE for i in xrange ( len ( data ) ) : NEW_LINE INDENT if data [ i ] != i + 1 : NEW_LINE INDENT unmatched += 1 NEW_LINE DEDENT DEDENT fout . write ( str ( unmatched ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT if len ( sys . argv ) != 3 : NEW_LINE INDENT print \" Please ▁ indicate ▁ input ▁ and ▁ output \" NEW_LINE exit ( 0 ) NEW_LINE DEDENT fin = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE fout = open ( sys . argv [ 2 ] , ' w ' ) NEW_LINE times = int ( fin . readline ( ) ) NEW_LINE for i in xrange ( times ) : NEW_LINE INDENT fout . write ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) ) NEW_LINE process ( i , fin , fout ) NEW_LINE fout . write ( \" \\n \" ) NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE DEDENT", "infile = \" D - large . in \" NEW_LINE debug = False NEW_LINE def find_subsets ( L ) : NEW_LINE INDENT used = [ False ] * len ( L ) NEW_LINE subsets = [ ] NEW_LINE for ix in xrange ( len ( L ) ) : NEW_LINE INDENT if used [ ix ] : NEW_LINE INDENT continue NEW_LINE DEDENT used [ ix ] = True NEW_LINE ix_subset = [ ix ] NEW_LINE next_ix = L [ ix ] - 1 NEW_LINE while next_ix != ix : NEW_LINE INDENT ix_subset . append ( next_ix ) NEW_LINE used [ next_ix ] = True NEW_LINE next_ix = L [ next_ix ] - 1 NEW_LINE DEDENT subsets . append ( ix_subset ) NEW_LINE DEDENT assert False not in used NEW_LINE assert sum ( map ( len , subsets ) ) == len ( L ) NEW_LINE return subsets NEW_LINE DEDENT def how_many ( set_size ) : NEW_LINE INDENT if set_size == 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return set_size NEW_LINE DEDENT DEDENT def solve ( nstr , data ) : NEW_LINE INDENT N = int ( nstr ) NEW_LINE data = map ( int , data . split ( ) ) NEW_LINE assert len ( data ) == N NEW_LINE subsets = find_subsets ( data ) NEW_LINE if debug : NEW_LINE INDENT print subsets NEW_LINE print map ( len , subsets ) NEW_LINE DEDENT avg = 0.0 NEW_LINE for subset in subsets : NEW_LINE INDENT avg += how_many ( len ( subset ) ) NEW_LINE DEDENT return \" % .7f \" % avg NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT i = file ( infile ) NEW_LINE N = int ( i . readline ( ) ) NEW_LINE for n in xrange ( N ) : NEW_LINE INDENT soln = solve ( i . readline ( ) , i . readline ( ) ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( n + 1 , soln ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "data = [ l . strip ( ) for l in open ( \" infile \" , \" r \" ) . readlines ( ) ] NEW_LINE out = open ( \" outfile \" , \" w \" ) NEW_LINE ncases = int ( data . pop ( 0 ) ) NEW_LINE for case in range ( ncases ) : NEW_LINE INDENT numelements = int ( data . pop ( 0 ) ) NEW_LINE elements = [ int ( s ) for s in data . pop ( 0 ) . split ( ' ▁ ' ) ] NEW_LINE inwrongplace = 0 NEW_LINE for i in range ( len ( elements ) ) : NEW_LINE INDENT if elements [ i ] != i + 1 : NEW_LINE INDENT inwrongplace += 1 NEW_LINE DEDENT DEDENT out . write ( \" Case ▁ # \" + str ( case + 1 ) + \" : ▁ \" + str ( \" % .6f \" % inwrongplace ) + \" \\n \" ) NEW_LINE DEDENT" ]
codejam_10_12
[ "import java . util . * ; public class Smooth { static Scanner sc = new Scanner ( System . in ) ; static int [ ] [ ] memo = new int [ 100 ] [ 257 ] ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { System . out . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; solveCase ( ) ; } } static final int SPC = 256 ; static void solveCase ( ) { del = sc . nextInt ( ) ; ins = sc . nextInt ( ) ; maxDist = sc . nextInt ( ) ; n = sc . nextInt ( ) ; arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = sc . nextInt ( ) ; for ( int [ ] arr : memo ) Arrays . fill ( arr , - 1 ) ; System . out . println ( solve ( 0 , SPC ) ) ; } static int del , ins , maxDist , n ; static int [ ] arr ; static int solve ( int index , int prev ) { if ( index >= n ) return 0 ; if ( memo [ index ] [ prev ] == - 1 ) { int res = del + solve ( index + 1 , prev ) ; for ( int val = 0 ; val < SPC ; val ++ ) { res = Math . min ( res , Math . abs ( arr [ index ] - val ) + insCost ( val , prev ) + solve ( index + 1 , val ) ) ; } memo [ index ] [ prev ] = res ; } return memo [ index ] [ prev ] ; } static int insCost ( int cur , int prev ) { if ( prev == SPC || cur == prev ) return 0 ; if ( maxDist == 0 ) return 100000000 ; return ins * ( ( Math . abs ( cur - prev ) + maxDist - 1 ) / maxDist - 1 ) ; } }", "import java . util . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int D = sc . nextInt ( ) ; int I = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = sc . nextInt ( ) ; int [ ] DP = new int [ 256 ] ; Arrays . fill ( DP , 0 ) ; int [ ] CUR = new int [ 256 ] ; for ( int at = N - 1 ; at >= 0 ; at -- ) { for ( int i = 0 ; i < 1000 ; i ++ ) { int prev ; if ( i % 2 == 0 ) prev = A [ at ] + i / 2 ; else prev = A [ at ] - ( i + 1 ) / 2 ; if ( prev < 0 || prev >= 256 ) continue ; int cost = DP [ prev ] + D ; for ( int j = 0 ; j < 256 ; j ++ ) { if ( abs ( j - prev ) <= M || prev == - 1 ) cost = min ( cost , DP [ j ] + abs ( j - A [ at ] ) ) ; if ( abs ( j - A [ at ] ) < abs ( A [ at ] - prev ) && ( prev == - 1 || abs ( j - prev ) <= M ) ) cost = min ( cost , CUR [ j ] + I ) ; } CUR [ prev ] = cost ; } for ( int j = 0 ; j < 256 ; j ++ ) DP [ j ] = CUR [ j ] ; Arrays . fill ( CUR , 0 ) ; } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < DP . length ; i ++ ) ans = min ( ans , DP [ i ] ) ; System . out . format ( \" Case ▁ # % d : ▁ % d \\n \" , t , ans ) ; } } }" ]
[ "import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return [ foo ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE def doit ( p , last ) : NEW_LINE INDENT if ( p , last ) in mem : return mem [ ( p , last ) ] NEW_LINE if ( p == N ) : return 0 NEW_LINE res = doit ( p + 1 , last ) + D NEW_LINE for i in xrange ( 256 ) : NEW_LINE INDENT if last == - 1 : NEW_LINE INDENT res = min ( res , doit ( p + 1 , i ) + abs ( a [ p ] - i ) ) NEW_LINE continue NEW_LINE DEDENT diff = abs ( last - i ) NEW_LINE if M == 0 and diff > 0 : continue NEW_LINE insertcost = ( ( diff - 1 ) / M ) * I if ( diff > 0 and I > 0 ) else 0 NEW_LINE editcost = abs ( a [ p ] - i ) NEW_LINE res = min ( res , doit ( p + 1 , i ) + editcost + insertcost ) NEW_LINE DEDENT mem [ ( p , last ) ] = res NEW_LINE return res NEW_LINE DEDENT def run_test ( test ) : NEW_LINE INDENT global D , I , M , N , a , mem NEW_LINE ( D , I , M , N ) = readarray ( int ) NEW_LINE a = readarray ( int ) NEW_LINE mem = { } NEW_LINE res = doit ( 0 , - 1 ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( test + 1 , res ) NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( \" Test ▁ % d \\n \" % ( test + 1 ) ) NEW_LINE run_test ( test ) NEW_LINE DEDENT", "from __future__ import division NEW_LINE import collections NEW_LINE import itertools NEW_LINE import sys NEW_LINE class gcj : NEW_LINE INDENT IN = sys . stdin NEW_LINE number = 0 NEW_LINE @ classmethod NEW_LINE def case ( cls ) : NEW_LINE INDENT cls . number += 1 NEW_LINE return ' Case ▁ # % d : ' % cls . number NEW_LINE DEDENT @ classmethod NEW_LINE def line ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return type ( line . strip ( ' \\n ' ) ) NEW_LINE DEDENT @ classmethod NEW_LINE def splitline ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return [ type ( x ) for x in line . split ( ) ] NEW_LINE DEDENT DEDENT def go ( ) : NEW_LINE INDENT t = gcj . line ( int ) NEW_LINE for _ in xrange ( t ) : NEW_LINE INDENT D , I , m , n = gcj . splitline ( int ) NEW_LINE data = gcj . splitline ( int ) NEW_LINE assert len ( data ) == n NEW_LINE print gcj . case ( ) , solve ( D , I , m , data ) NEW_LINE DEDENT DEDENT def solve ( D , I , m , data ) : NEW_LINE INDENT n = len ( data ) NEW_LINE tab = [ 0 ] * 256 NEW_LINE otab = [ 0 ] * 256 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT otab , tab = tab , otab NEW_LINE for j in xrange ( 256 ) : NEW_LINE INDENT cur = otab [ j ] + D NEW_LINE base = abs ( data [ i ] - j ) NEW_LINE if cur > base : NEW_LINE INDENT for k in xrange ( 256 ) : NEW_LINE INDENT if m == 0 and k != j : NEW_LINE INDENT continue NEW_LINE DEDENT new = otab [ k ] NEW_LINE if k < j : NEW_LINE INDENT new += ( j - k - 1 ) // m * I NEW_LINE DEDENT elif k > j : NEW_LINE INDENT new += ( k - j - 1 ) // m * I NEW_LINE DEDENT if cur > base + new : NEW_LINE INDENT cur = base + new NEW_LINE DEDENT DEDENT DEDENT tab [ j ] = cur NEW_LINE DEDENT DEDENT return min ( tab [ i ] for i in xrange ( 256 ) ) NEW_LINE DEDENT go ( ) NEW_LINE", "from sys import stdin NEW_LINE N = 256 NEW_LINE def main ( ) : NEW_LINE INDENT dd , ii , mm , n = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE A = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE x = [ 0 ] * N NEW_LINE for a in A : NEW_LINE INDENT y = [ ] NEW_LINE for v in x : NEW_LINE INDENT y . append ( v + dd ) NEW_LINE DEDENT for i in xrange ( N ) : NEW_LINE INDENT y [ i ] = min ( y [ i ] , min ( x [ max ( 0 , i - mm ) : min ( i + mm + 1 , N ) ] ) + abs ( i - a ) ) NEW_LINE DEDENT for i in xrange ( N ) : NEW_LINE INDENT for j in xrange ( i + 1 , min ( N , i + mm + 1 ) ) : NEW_LINE INDENT y [ j ] = min ( y [ j ] , y [ i ] + ii ) NEW_LINE DEDENT DEDENT for i in xrange ( N ) : NEW_LINE INDENT for j in xrange ( i + 1 , min ( N , i + mm + 1 ) ) : NEW_LINE INDENT y [ N - 1 - j ] = min ( y [ N - 1 - j ] , y [ N - 1 - i ] + ii ) NEW_LINE DEDENT DEDENT x = y NEW_LINE DEDENT return str ( min ( x ) ) NEW_LINE DEDENT tno = int ( stdin . readline ( ) ) NEW_LINE for i in xrange ( 0 , tno ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , main ( ) ) NEW_LINE DEDENT", "import os NEW_LINE import sys NEW_LINE def debug ( * x , ** a ) : NEW_LINE INDENT print \" DEBUG : ▁ % s \" % \" ▁ \" . join ( [ repr ( v ) for v in x ] + [ \" % s = % s \" % ( k , repr ( v ) ) for ( k , v ) in a . iteritems ( ) ] ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT def read_ints ( ) : NEW_LINE INDENT return [ int ( x ) for x in raw_input ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT [ N_CASES ] = read_ints ( ) NEW_LINE for case in xrange ( 1 , N_CASES + 1 ) : NEW_LINE INDENT [ D , I , M , N ] = read_ints ( ) NEW_LINE A = read_ints ( ) NEW_LINE minA = min ( A ) NEW_LINE A = [ x - minA for x in A ] NEW_LINE Z = max ( A ) + 1 NEW_LINE def insertions ( a , b ) : NEW_LINE INDENT if abs ( a - b ) <= M : NEW_LINE INDENT return 0 NEW_LINE DEDENT if M == 0 : NEW_LINE INDENT return 1000000 NEW_LINE DEDENT return ( abs ( a - b ) - 1 ) // M * I NEW_LINE DEDENT c = [ 0 ] * Z NEW_LINE for a in A : NEW_LINE INDENT cc = [ 0 ] * Z NEW_LINE for j in xrange ( Z ) : NEW_LINE INDENT cost = c [ j ] + D NEW_LINE for k in xrange ( Z ) : NEW_LINE INDENT if j == a : NEW_LINE INDENT cost = min ( cost , c [ k ] + insertions ( k , a ) ) NEW_LINE DEDENT else : NEW_LINE INDENT cost = min ( cost , c [ k ] + insertions ( k , a ) + insertions ( a , j ) + I ) NEW_LINE cost = min ( cost , c [ k ] + abs ( j - a ) + insertions ( k , j ) ) NEW_LINE DEDENT DEDENT cc [ j ] = cost NEW_LINE DEDENT c = cc NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( case , min ( c ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "def read ( ) : NEW_LINE INDENT D , I , M , nVal = map ( int , raw_input ( ) . split ( ) ) NEW_LINE val = map ( int , raw_input ( ) . split ( ) ) NEW_LINE return D , I , M , val NEW_LINE DEDENT def rec ( lastV , idx , D , I , M , val , dp ) : NEW_LINE INDENT if idx == len ( val ) : return 0 NEW_LINE ret = dp [ lastV ] [ idx ] NEW_LINE if ret != - 1 : return ret NEW_LINE ret = 1 << 30 NEW_LINE if lastV != 256 and abs ( lastV - val [ idx ] ) > M and M != 0 : NEW_LINE INDENT absV = abs ( lastV - val [ idx ] ) NEW_LINE ret = min ( ret , rec ( val [ idx ] , idx + 1 , D , I , M , val , dp ) + max ( 0 , ( absV / M - ( absV % M == 0 ) ) * I ) ) NEW_LINE DEDENT ret = min ( ret , rec ( lastV , idx + 1 , D , I , M , val , dp ) + D ) NEW_LINE if lastV == 256 : NEW_LINE INDENT for i in range ( 0 , 256 ) : NEW_LINE INDENT ret = min ( ret , rec ( i , idx + 1 , D , I , M , val , dp ) + abs ( val [ idx ] - i ) ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 0 , 256 ) : NEW_LINE INDENT if abs ( lastV - i ) <= M : NEW_LINE INDENT ret = min ( ret , rec ( i , idx + 1 , D , I , M , val , dp ) + abs ( val [ idx ] - i ) ) NEW_LINE DEDENT DEDENT DEDENT dp [ lastV ] [ idx ] = ret NEW_LINE return ret NEW_LINE DEDENT def work ( cases , ( D , I , M , val ) ) : NEW_LINE INDENT dp = [ [ - 1 for j in range ( len ( val ) ) ] for i in range ( 257 ) ] NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( cases , rec ( 256 , 0 , D , I , M , val , dp ) ) NEW_LINE DEDENT for i in range ( int ( raw_input ( ) ) ) : NEW_LINE INDENT work ( i + 1 , read ( ) ) NEW_LINE DEDENT" ]
codejam_08_23
[ "import java . util . * ; public class C { public static void main ( String args [ ] ) { ( new C ( ) ) . exec ( ) ; } void exec ( ) { Scanner cin = new Scanner ( System . in ) ; int t = cin . nextInt ( ) ; for ( int z = 0 ; z < t ; ++ z ) { int k = cin . nextInt ( ) ; int value [ ] = new int [ k ] ; boolean used [ ] = new boolean [ k ] ; int count = 0 ; int cur = 0 ; while ( count < k ) { for ( int i = 0 ; i < k ; ++ i ) { if ( used [ i ] ) { continue ; } if ( cur == count ) { value [ i ] = ++ count ; cur = 0 ; used [ i ] = true ; } else { ++ cur ; } } } System . out . print ( \" Case ▁ # \" + ( z + 1 ) + \" : \" ) ; int n = cin . nextInt ( ) ; for ( int i = 0 ; i < n ; ++ i ) { System . out . print ( \" ▁ \" + value [ cin . nextInt ( ) - 1 ] ) ; } System . out . println ( ) ; } } }", "import java . io . * ; import java . util . * ; public class TaskC implements Runnable { private String IFILE = \" C - large . in \" ; private Scanner in ; private PrintWriter out ; public void Run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int ntest = in . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : \" ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int [ ] mas = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { int v = in . nextInt ( ) - 1 ; int count = n ; for ( int j = 0 ; j < n ; j ++ ) { int pos = j % count ; if ( pos == v ) { out . print ( \" ▁ \" + ( j + 1 ) ) ; break ; } if ( pos > v ) { v += count - pos - 1 ; } else { v = v - pos - 1 ; } count -- ; } } out . println ( ) ; } in . close ( ) ; out . close ( ) ; } public void run ( ) { try { Run ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) throws IOException { new TaskC ( ) . Run ( ) ; } }", "package common ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; public class Helper { public static String [ ] getAllFileContentAsArray ( String filename ) throws Exception { BufferedReader in = new BufferedReader ( new FileReader ( filename ) ) ; List < String > all = new ArrayList < String > ( ) ; String s = in . readLine ( ) ; while ( s != null ) { all . add ( s ) ; s = in . readLine ( ) ; } in . close ( ) ; return all . toArray ( new String [ 0 ] ) ; } public static void writeToFile ( String [ ] cont , String filename ) throws Exception { File file = new File ( filename ) ; file . delete ( ) ; FileWriter w = null ; try { w = new FileWriter ( file , true ) ; for ( String s : cont ) { w . write ( s + \" \\n \" ) ; } } finally { if ( w != null ) { w . close ( ) ; } } } public static int [ ] getIntegersFromString ( String s ) throws Exception { List < Integer > a = new ArrayList < Integer > ( ) ; for ( String se : s . split ( \" ▁ \" ) ) { try { Integer x = Integer . parseInt ( se ) ; a . add ( x ) ; } catch ( Exception e ) { } } int [ ] ret = new int [ a . size ( ) ] ; for ( int i = 0 ; i < a . size ( ) ; ++ i ) { ret [ i ] = a . get ( i ) . intValue ( ) ; } return ret ; } private Helper ( ) { } }", "import java . io . * ; import java . util . * ; public class C { public static void main ( String args [ ] ) throws IOException { new C ( ) . solve ( ) ; } void solve ( ) throws IOException { br = new BufferedReader ( new FileReader ( \" C - small - attempt0 . in \" ) ) ; pw = new PrintWriter ( \" C - small . out \" ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int c = 1 ; c <= T ; ++ c ) { System . out . println ( c ) ; int K = Integer . parseInt ( br . readLine ( ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { d [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; } int [ ] v = new int [ K ] ; int s = 0 ; for ( int k = 1 ; k <= K ; ++ k ) { for ( int p = 1 ; p < k ; ++ p ) { s ++ ; if ( s == K ) s = 0 ; while ( v [ s ] != 0 ) { s ++ ; if ( s == K ) s = 0 ; } } v [ s ] = k ; if ( k < K ) { s ++ ; if ( s == K ) s = 0 ; while ( v [ s ] != 0 ) { s ++ ; if ( s == K ) s = 0 ; } } } pw . print ( \" Case ▁ # \" + c + \" : \" ) ; for ( int i = 0 ; i < n ; ++ i ) { pw . print ( \" ▁ \" + v [ d [ i ] - 1 ] ) ; } pw . println ( ) ; } pw . close ( ) ; } BufferedReader br ; PrintWriter pw ; }", "import java . util . * ; public class CSmall { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= T ; caseID ++ ) { int K = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] ds = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ds [ i ] = sc . nextInt ( ) ; } boolean [ ] visited = new boolean [ K ] ; int [ ] cards = new int [ K ] ; int iter = 0 ; for ( int i = 1 ; i <= K ; i ++ ) { int cnt = 0 ; int next = ( i - 1 ) % ( K - i + 1 ) ; while ( true ) { if ( iter == K ) iter = 0 ; if ( ! visited [ iter ] ) { if ( cnt == next ) { visited [ iter ] = true ; cards [ iter ] = i ; cnt ++ ; iter ++ ; break ; } else { cnt ++ ; iter ++ ; } } else { iter ++ ; } } } System . out . printf ( \" Case ▁ # % d : \" , caseID ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . printf ( \" ▁ % d \" , cards [ ds [ i ] - 1 ] ) ; } System . out . printf ( \" % n \" ) ; } } }" ]
[ "import sys NEW_LINE def readdata ( ) : NEW_LINE INDENT def rl ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) . strip ( ) . split ( ' ▁ ' ) NEW_LINE DEDENT n = int ( rl ( ) [ 0 ] ) NEW_LINE cases = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT K = int ( rl ( ) [ 0 ] ) NEW_LINE il = [ int ( x ) for x in rl ( ) ] NEW_LINE case = ( K , il [ 1 : il [ 0 ] + 1 ] ) NEW_LINE cases . append ( case ) NEW_LINE DEDENT return cases NEW_LINE DEDENT case_number = 1 NEW_LINE for case in readdata ( ) : NEW_LINE INDENT sc = case [ 0 ] NEW_LINE si = range ( sc ) NEW_LINE sv = [ 0 ] * sc NEW_LINE cv = 1 NEW_LINE ci = 0 NEW_LINE for z in xrange ( sc ) : NEW_LINE INDENT ci += z NEW_LINE ci = ci % len ( si ) NEW_LINE sv [ si [ ci ] ] = z + 1 NEW_LINE si . remove ( si [ ci ] ) NEW_LINE DEDENT print ' Case ▁ # ' + str ( case_number ) + ' : ' , ' ▁ ' . join ( [ str ( sv [ x - 1 ] ) for x in case [ 1 ] ] ) NEW_LINE case_number += 1 NEW_LINE DEDENT", "inp_file = file ( \" C - small . in \" ) NEW_LINE out_file = file ( \" C - small . out \" , \" w \" ) NEW_LINE def solve ( line ) : NEW_LINE INDENT line = [ int ( c1 ) for c1 in line . split ( \" ▁ \" ) ] NEW_LINE card_num , indices = line [ : 2 ] NEW_LINE line = line [ 2 : ] NEW_LINE positions = range ( card_num ) NEW_LINE result = [ 0 for c1 in range ( card_num ) ] NEW_LINE c1 = 1 NEW_LINE c2 = 0 NEW_LINE while c1 < card_num : NEW_LINE INDENT result [ positions [ c2 ] ] = c1 NEW_LINE positions . pop ( c2 ) NEW_LINE c2 = ( c2 + c1 ) % len ( positions ) NEW_LINE c1 += 1 NEW_LINE DEDENT result [ result . index ( 0 ) ] = card_num NEW_LINE return \" ▁ \" . join ( [ str ( result [ c1 - 1 ] ) for c1 in line ] ) NEW_LINE DEDENT num = int ( inp_file . readline ( ) ) NEW_LINE for case in range ( num ) : NEW_LINE INDENT line = inp_file . readline ( ) [ : - 1 ] + \" ▁ \" + inp_file . readline ( ) [ : - 1 ] NEW_LINE out_file . write ( \" Case ▁ # % s : ▁ \" % ( case + 1 ) + solve ( line ) + \" \\n \" ) NEW_LINE DEDENT inp_file . close ( ) NEW_LINE out_file . close ( ) NEW_LINE", "import sys NEW_LINE filename = sys . argv [ 1 ] NEW_LINE inputfile = file ( filename , ' r ' ) NEW_LINE numcases = int ( inputfile . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , numcases + 1 ) : NEW_LINE INDENT K = int ( inputfile . readline ( ) . strip ( ) ) NEW_LINE data = map ( int , inputfile . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE n = data [ 0 ] NEW_LINE dis = data [ 1 : ] NEW_LINE cards = range ( K ) NEW_LINE remainingcards = range ( K ) NEW_LINE remainingcardpos = 0 NEW_LINE for cardvalue in range ( K ) : NEW_LINE INDENT remainingcardpos = ( cardvalue + remainingcardpos ) % len ( remainingcards ) NEW_LINE card = remainingcards [ remainingcardpos ] NEW_LINE cards [ card ] = cardvalue + 1 NEW_LINE del remainingcards [ remainingcardpos ] NEW_LINE DEDENT sys . stdout . write ( \" Case ▁ # % d : \" % case ) NEW_LINE for di in dis : NEW_LINE INDENT sys . stdout . write ( \" ▁ % d \" % cards [ di - 1 ] ) NEW_LINE DEDENT sys . stdout . write ( \" \\n \" ) NEW_LINE DEDENT", "import sys , itertools NEW_LINE data = filter ( None , map ( lambda x : x . strip ( ) , open ( sys . argv [ 1 ] ) . readlines ( ) ) ) NEW_LINE def pop_int ( data ) : NEW_LINE INDENT return int ( data . pop ( 0 ) ) NEW_LINE DEDENT def pop_ints ( data ) : NEW_LINE INDENT return map ( int , data . pop ( 0 ) . split ( ) ) NEW_LINE DEDENT def pop_rows ( data , num_rows ) : NEW_LINE INDENT result = data [ : num_rows ] NEW_LINE for i in range ( num_rows ) : NEW_LINE INDENT data . pop ( 0 ) NEW_LINE DEDENT return result NEW_LINE DEDENT def pop_case ( data ) : NEW_LINE INDENT num_cards = pop_int ( data ) NEW_LINE indices = pop_ints ( data ) [ 1 : ] NEW_LINE return num_cards , indices NEW_LINE DEDENT def make_deck ( num_cards ) : NEW_LINE INDENT deck = [ None for i in range ( num_cards ) ] NEW_LINE indices_open = range ( num_cards ) NEW_LINE last_ii = 0 NEW_LINE for i in range ( 1 , num_cards + 1 ) : NEW_LINE INDENT last_ii = index_index = ( i + last_ii - 1 ) % len ( indices_open ) NEW_LINE position = indices_open [ index_index ] NEW_LINE assert ( deck [ position ] is None ) NEW_LINE deck [ position ] = i NEW_LINE indices_open . remove ( position ) NEW_LINE DEDENT return deck NEW_LINE DEDENT def solve ( num_cards , indices ) : NEW_LINE INDENT solution = make_deck ( num_cards ) NEW_LINE answer = ' ▁ ' . join ( str ( solution [ i - 1 ] ) for i in indices ) NEW_LINE return answer NEW_LINE DEDENT num_cases = pop_int ( data ) NEW_LINE for case_num in range ( 1 , num_cases + 1 ) : NEW_LINE INDENT num_cards , indices = pop_case ( data ) NEW_LINE answer = solve ( num_cards , indices ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( case_num , answer ) NEW_LINE DEDENT", "case = \" small - attempt0\" NEW_LINE input_file = \" C - % s . in \" % case NEW_LINE output_file = \" C - % s . out \" % case NEW_LINE fin = open ( input_file ) NEW_LINE fout = open ( output_file , \" w \" ) NEW_LINE ncase = int ( fin . readline ( ) . strip ( ) ) NEW_LINE for z in xrange ( 1 , ncase + 1 ) : NEW_LINE INDENT print >> fout , \" Case ▁ # % d : \" % z , NEW_LINE k = int ( fin . readline ( ) . strip ( ) ) NEW_LINE d = [ int ( x ) - 1 for x in fin . readline ( ) . strip ( ) . split ( ) [ 1 : ] ] NEW_LINE for dd in d : NEW_LINE INDENT n , p , r , i = k , dd , 0 , 1 NEW_LINE while p != r : NEW_LINE INDENT n -= 1 NEW_LINE if p > r : NEW_LINE INDENT p -= 1 NEW_LINE DEDENT r = ( r + i ) % n NEW_LINE i += 1 NEW_LINE DEDENT print >> fout , i , NEW_LINE DEDENT print >> fout NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE" ]
codejam_08_91
[ "import java . util . * ; import java . io . * ; public class x { static class Pt implements Comparable < Pt > { int x , y , z ; Pt ( int xx , int yy , int zz ) { x = xx ; y = yy ; z = zz ; } ; public int compareTo ( Pt a ) { if ( y != a . y ) return y - a . y ; if ( x != a . x ) return x - a . x ; if ( z != a . z ) return z - a . z ; return 0 ; } ; } ; public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int tcnt = in . nextInt ( ) ; for ( int i = 1 ; i <= tcnt ; i ++ ) { int n = in . nextInt ( ) ; Pt [ ] p = new Pt [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; p [ j ] = new Pt ( a , b , c ) ; } ; Arrays . sort ( p ) ; int mx = 0 ; for ( int x = 0 ; x <= 10000 ; x ++ ) { int [ ] T = new int [ 10002 ] ; for ( int j = 0 ; j < n ; j ++ ) { if ( p [ j ] . x <= x ) { int z = 10000 - p [ j ] . y - x ; for ( int k = 1 + p [ j ] . z ; k <= 10001 ; k += k & - k ) T [ k ] ++ ; if ( z >= 0 ) { int sum = 0 ; for ( int k = 1 + Math . max ( 0 , z ) ; k > 0 ; k -= k & - k ) sum += T [ k ] ; mx = Math . max ( mx , sum ) ; } ; } ; } ; } ; out . println ( \" Case ▁ # \" + i + \" : ▁ \" + mx ) ; } ; out . close ( ) ; } ; } ;", "import java . io . * ; import java . util . * ; public class Main { Scanner in ; PrintWriter out ; public void solve ( ) throws Exception { int n = in . nextInt ( ) ; int [ ] x = new int [ n ] ; int [ ] y = new int [ n ] ; int [ ] z = new int [ n ] ; int M = 10000 ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = in . nextInt ( ) ; y [ i ] = in . nextInt ( ) ; z [ i ] = in . nextInt ( ) ; } int [ ] k = new int [ M + 2 ] ; int best = 0 ; for ( int u = 0 ; u <= M ; u ++ ) { Arrays . fill ( k , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) if ( x [ i ] <= u ) if ( y [ i ] <= M - u - z [ i ] + 1 ) { k [ y [ i ] ] ++ ; k [ M - u - z [ i ] + 1 ] -- ; } int bb = 0 ; int b = 0 ; for ( int i = 0 ; i <= M ; i ++ ) { bb += k [ i ] ; if ( b < bb ) b = bb ; } if ( best < b ) { best = b ; } } out . println ( best ) ; } public void run ( ) throws Exception { in = new Scanner ( new File ( \" input . txt \" ) ) ; out = new PrintWriter ( new FileWriter ( new File ( \" output . txt \" ) ) ) ; int _ = in . nextInt ( ) ; for ( int __ = 0 ; __ < _ ; __ ++ ) { out . print ( \" Case ▁ # \" + ( __ + 1 ) + \" : ▁ \" ) ; solve ( ) ; } } public void close ( ) { out . close ( ) ; } public static void main ( String [ ] args ) { new Thread ( ) { public void run ( ) { try { Main a = new Main ( ) ; a . run ( ) ; a . close ( ) ; } catch ( Exception E ) { throw new RuntimeException ( E ) ; } } } . start ( ) ; } }", "import java . util . * ; import java . io . * ; import java . math . * ; import static java . lang . Math . * ; public class A { static final int TOTAL = 10000 ; static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int caseNum = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseNum ; caseID ++ ) { new A ( ) . solveDataSet ( caseID ) ; } } int N ; ArrayList < Int3D > [ ] x2Points ; void solveDataSet ( int caseID ) { N = sc . nextInt ( ) ; x2Points = ( ArrayList < Int3D > [ ] ) ( new ArrayList < ? > [ TOTAL + 1 ] ) ; for ( int x = 0 ; x <= TOTAL ; x ++ ) { x2Points [ x ] = new ArrayList < Int3D > ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int z = sc . nextInt ( ) ; x2Points [ x ] . add ( new Int3D ( x , y , z ) ) ; } int ans = 0 ; for ( int z = 0 ; z <= TOTAL ; z ++ ) { int cnt = 0 ; int [ ] yCnt = new int [ TOTAL - z + 1 ] ; for ( int x = 0 ; x <= TOTAL - z ; x ++ ) { if ( x > 0 ) { cnt -= yCnt [ TOTAL - z - ( x - 1 ) ] ; } for ( Int3D p : x2Points [ x ] ) { if ( p . z <= z && p . y <= TOTAL - z - x ) { yCnt [ p . y ] ++ ; cnt ++ ; } } ans = Math . max ( cnt , ans ) ; } } System . err . printf ( \" Case ▁ # % d : % n \" , caseID ) ; System . out . printf ( \" Case ▁ # % d : ▁ % d % n \" , caseID , ans ) ; } } class Int3D { int x , y , z ; public Int3D ( int x , int y , int z ) { super ( ) ; this . x = x ; this . y = y ; this . z = z ; } }", "import java . util . * ; import java . io . * ; import java . math . * ; public class A { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new InputStreamReader ( System . in ) ) ; int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int N = sc . nextInt ( ) ; int [ ] [ ] nums = new int [ N ] [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) nums [ i ] [ j ] = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { Vector < Integer > low = new Vector < Integer > ( ) ; Vector < Integer > high = new Vector < Integer > ( ) ; int cur = 0 ; int A = nums [ i ] [ 0 ] ; for ( int j = 0 ; j < N ; j ++ ) { if ( A < nums [ j ] [ 0 ] ) continue ; if ( nums [ j ] [ 1 ] <= 10000 - A - nums [ j ] [ 2 ] ) { low . add ( nums [ j ] [ 1 ] ) ; high . add ( 10000 - A - nums [ j ] [ 2 ] ) ; } } if ( low . size ( ) == 0 ) continue ; Collections . sort ( low ) ; Collections . sort ( high ) ; int lc = 0 , hc = 0 , lcur = low . get ( 0 ) , hcur = high . get ( 0 ) ; while ( lc < low . size ( ) ) { if ( lcur <= hcur ) { cur ++ ; ans = Math . max ( ans , cur ) ; lc ++ ; if ( lc < low . size ( ) ) lcur = low . get ( lc ) ; } else { cur -- ; hc ++ ; if ( hc < high . size ( ) ) hcur = high . get ( hc ) ; } } } System . out . println ( \" Case ▁ # \" + t + \" : ▁ \" + ans ) ; } } }" ]
[ "import sys NEW_LINE def isset ( n , i ) : return ( n >> i ) & 1 != 0 NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return map ( foo , raw_input ( ) . split ( ) ) NEW_LINE for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( \" Test ▁ % d \\n \" % ( test + 1 ) ) NEW_LINE n = readint ( ) NEW_LINE data = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT ( a , b , c ) = readarray ( int ) NEW_LINE data . append ( ( a , b , c ) ) NEW_LINE DEDENT res = 0 NEW_LINE for A in xrange ( 10001 ) : NEW_LINE INDENT q = [ ] NEW_LINE for ( a , b , c ) in data : NEW_LINE INDENT if ( a > A ) : continue NEW_LINE if ( A + b > 10000 ) : continue NEW_LINE minb = b NEW_LINE maxb = 10000 - A - c NEW_LINE if ( maxb < minb ) : continue NEW_LINE q . append ( ( minb , 0 ) ) NEW_LINE q . append ( ( maxb , 1 ) ) NEW_LINE DEDENT q . sort ( ) NEW_LINE r = 0 NEW_LINE for ( t , d ) in q : NEW_LINE INDENT if d == 0 : NEW_LINE INDENT r += 1 NEW_LINE res = max ( res , r ) NEW_LINE DEDENT else : NEW_LINE INDENT r -= 1 NEW_LINE DEDENT DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( test + 1 , res ) NEW_LINE DEDENT" ]
codejam_14_21
[ "import java . io . * ; import java . util . * ; class A { static int calc ( int [ ] q ) { int res = 1234567 ; for ( int a = 0 ; a <= 100 ; a ++ ) { int cur = 0 ; for ( int i = 0 ; i < q . length ; i ++ ) cur += Math . abs ( q [ i ] - a ) ; res = Math . min ( res , cur ) ; } return res ; } public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int numTests = sc . nextInt ( ) ; for ( int test = 1 ; test <= numTests ; test ++ ) { int n = sc . nextInt ( ) ; String must = \" \" ; int [ ] [ ] q = new int [ 111 ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) + \" ? \" ; String t = \" \" ; int ind = 0 ; char c = ' ? ' ; int cnt = 1 ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( j ) == c ) cnt ++ ; else { t += c ; q [ ind ] [ i ] = cnt ; cnt = 0 ; ind ++ ; c = s . charAt ( j ) ; } } if ( i == 0 ) must = t ; else if ( ! must . equals ( t ) ) must = \" ? \" ; } String lost = \" Fegla ▁ Won \" ; if ( must . equals ( \" ? \" ) ) { System . out . println ( \" Case ▁ # \" + test + \" : ▁ \" + lost ) ; } else { int res = 0 ; for ( int i = 0 ; i < 111 ; i ++ ) res += calc ( q [ i ] ) ; System . out . println ( \" Case ▁ # \" + test + \" : ▁ \" + res ) ; } } } }", "import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , i , solve ( ) ) ; } } static String solve ( ) { int N = sc . nextInt ( ) ; String [ ] str = new String [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { str [ i ] = sc . next ( ) ; } int [ ] [ ] count = new int [ N ] [ 101 ] ; int [ ] pos = new int [ N ] ; for ( int i = 0 ; pos [ 0 ] < str [ 0 ] . length ( ) ; ++ i ) { char c = str [ 0 ] . charAt ( pos [ 0 ] ) ; for ( int j = 0 ; j < N ; ++ j ) { if ( pos [ j ] >= str [ j ] . length ( ) || str [ j ] . charAt ( pos [ j ] ) != c ) { return \" Fegla ▁ Won \" ; } while ( pos [ j ] < str [ j ] . length ( ) && str [ j ] . charAt ( pos [ j ] ) == c ) { ++ pos [ j ] ; ++ count [ j ] [ i ] ; } } } for ( int i = 0 ; i < N ; ++ i ) { if ( pos [ i ] != str [ i ] . length ( ) ) { return \" Fegla ▁ Won \" ; } } int ans = 0 ; for ( int i = 0 ; count [ 0 ] [ i ] > 0 ; ++ i ) { int min = 1 << 30 ; for ( int j = 1 ; j <= 100 ; ++ j ) { int sum = 0 ; for ( int k = 0 ; k < N ; ++ k ) { sum += Math . abs ( count [ k ] [ i ] - j ) ; } min = Math . min ( min , sum ) ; } ans += min ; } return \" \" + ans ; } }" ]
[ "import sys NEW_LINE from itertools import zip_longest as zip NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE def cost ( v ) : NEW_LINE INDENT v . sort ( ) NEW_LINE m = v [ len ( v ) // 2 ] NEW_LINE return sum ( abs ( i - m ) for i in v ) NEW_LINE DEDENT def partition ( s ) : NEW_LINE INDENT i = 0 NEW_LINE while i < len ( s ) : NEW_LINE INDENT j = i + 1 NEW_LINE while j < len ( s ) and s [ i ] == s [ j ] : NEW_LINE INDENT j += 1 NEW_LINE DEDENT yield ( s [ i ] , j - i ) NEW_LINE i = j NEW_LINE DEDENT DEDENT for t in range ( T ) : NEW_LINE INDENT N = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE ss = list ( sys . stdin . readline ( ) . strip ( ) for _ in range ( N ) ) NEW_LINE res = 0 NEW_LINE for items in zip ( * list ( partition ( s ) for s in ss ) ) : NEW_LINE INDENT if any ( i is None for i in items ) : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ Fegla ▁ Won \" % ( t + 1 ) ) NEW_LINE break NEW_LINE DEDENT if any ( a != items [ 0 ] [ 0 ] for a , _ in items [ 1 : ] ) : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ Fegla ▁ Won \" % ( t + 1 ) ) NEW_LINE break NEW_LINE DEDENT res += cost ( list ( b for _ , b in items ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ % d \" % ( t + 1 , res ) ) NEW_LINE DEDENT DEDENT", "T = input ( ) NEW_LINE def encode ( input_string ) : NEW_LINE INDENT count = 1 NEW_LINE prev = ' ' NEW_LINE lst = [ ] NEW_LINE for character in input_string : NEW_LINE INDENT if character != prev : NEW_LINE INDENT if prev : NEW_LINE INDENT entry = ( prev , count ) NEW_LINE lst . append ( entry ) NEW_LINE DEDENT count = 1 NEW_LINE prev = character NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT entry = ( character , count ) NEW_LINE lst . append ( entry ) NEW_LINE DEDENT return lst NEW_LINE DEDENT def moves ( l ) : NEW_LINE INDENT m = 100000000 NEW_LINE for i in range ( 200 ) : NEW_LINE INDENT m = min ( m , sum ( abs ( x - i ) for x in l ) ) NEW_LINE DEDENT return m NEW_LINE DEDENT for case in range ( 1 , T + 1 ) : NEW_LINE INDENT N = input ( ) NEW_LINE strs = [ raw_input ( ) for i in range ( N ) ] NEW_LINE uniq = set ( ' ' . join ( x [ 0 ] for x in encode ( s ) ) for s in strs ) NEW_LINE enc = [ [ x [ 1 ] for x in encode ( s ) ] for s in strs ] NEW_LINE ans = ' Fegla ▁ Won ' NEW_LINE if len ( uniq ) == 1 : NEW_LINE INDENT bypos = [ [ l [ i ] for l in enc ] for i in range ( len ( enc [ 0 ] ) ) ] NEW_LINE ans = sum ( moves ( l ) for l in bypos ) NEW_LINE DEDENT print \" Case ▁ # % d : \" % case , ans NEW_LINE DEDENT", "file_in = open ( ' a . in ' , ' r ' ) NEW_LINE file_out = open ( ' a . out ' , ' w ' ) NEW_LINE n_case = int ( file_in . readline ( ) ) NEW_LINE class Word : NEW_LINE INDENT def __init__ ( self , s ) : NEW_LINE INDENT char = '0' NEW_LINE self . chars = [ ] NEW_LINE self . counts = [ ] NEW_LINE for c in s : NEW_LINE INDENT if c != char : NEW_LINE INDENT self . chars . append ( c ) NEW_LINE self . counts . append ( 1 ) NEW_LINE char = c NEW_LINE DEDENT else : NEW_LINE INDENT self . counts [ - 1 ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for i_case in range ( n_case ) : NEW_LINE INDENT N = int ( file_in . readline ( ) ) NEW_LINE words = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT words . append ( Word ( file_in . readline ( ) . strip ( ) ) ) NEW_LINE DEDENT chars = words [ 0 ] . chars NEW_LINE def check_equal ( ) : NEW_LINE INDENT for word in words : NEW_LINE INDENT if word . chars != chars : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if not check_equal ( ) : NEW_LINE INDENT file_out . write ( \" Case ▁ # % d : ▁ % s \\n \" % ( i_case + 1 , \" Fegla ▁ Won \" ) ) NEW_LINE continue NEW_LINE DEDENT def median ( arr ) : NEW_LINE INDENT s = sorted ( arr ) NEW_LINE return s [ len ( s ) / 2 ] NEW_LINE DEDENT def actions_needed ( arr ) : NEW_LINE INDENT count = 0 NEW_LINE med = median ( arr ) NEW_LINE for a in arr : NEW_LINE INDENT count += abs ( med - a ) NEW_LINE DEDENT return count NEW_LINE DEDENT actions = 0 NEW_LINE for i_char in range ( len ( chars ) ) : NEW_LINE INDENT arr = [ ] NEW_LINE for word in words : NEW_LINE INDENT arr . append ( word . counts [ i_char ] ) NEW_LINE DEDENT actions += actions_needed ( arr ) NEW_LINE DEDENT file_out . write ( \" Case ▁ # % d : ▁ % s \\n \" % ( i_case + 1 , str ( actions ) ) ) NEW_LINE DEDENT file_in . close ( ) NEW_LINE file_out . close ( ) NEW_LINE", "import sys NEW_LINE infile = None NEW_LINE outfile = None NEW_LINE def readline ( ) : NEW_LINE INDENT x = infile . readline ( ) NEW_LINE if len ( x ) > 0 : NEW_LINE INDENT return x [ : - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return x NEW_LINE DEDENT DEDENT def readint ( ) : NEW_LINE INDENT return int ( readline ( ) ) NEW_LINE DEDENT def readfloat ( ) : NEW_LINE INDENT return float ( readline ( ) ) NEW_LINE DEDENT def readints ( ) : NEW_LINE INDENT xs = readline ( ) . split ( ) NEW_LINE return [ int ( x ) for x in xs ] NEW_LINE DEDENT def readfloats ( ) : NEW_LINE INDENT xs = readline ( ) . split ( ) NEW_LINE return [ float ( x ) for x in xs ] NEW_LINE DEDENT def writeline ( x ) : NEW_LINE INDENT outfile . write ( x + ' \\n ' ) NEW_LINE DEDENT def run ( main ) : NEW_LINE INDENT global infile , outfile NEW_LINE args = sys . argv NEW_LINE if len ( args ) == 1 : NEW_LINE INDENT infile = sys . stdin NEW_LINE outfile = sys . stdout NEW_LINE DEDENT elif len ( args ) == 2 : NEW_LINE INDENT if args [ 1 ] == ' - ' : NEW_LINE INDENT infile = sys . stdin NEW_LINE DEDENT else : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE DEDENT if args [ 1 ] . endswith ( ' . in ' ) : NEW_LINE INDENT outfile = open ( args [ 1 ] [ : - 3 ] + ' . out ' , ' w ' ) NEW_LINE DEDENT else : NEW_LINE INDENT outfile = sys . stdout NEW_LINE DEDENT DEDENT elif len ( args ) == 3 : NEW_LINE INDENT if args [ 1 ] == ' - ' : NEW_LINE INDENT infile = sys . stdin NEW_LINE DEDENT else : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE DEDENT if args [ 2 ] == ' - ' : NEW_LINE INDENT outfile = sys . stdout NEW_LINE DEDENT else : NEW_LINE INDENT outfile = open ( args [ 2 ] , ' w ' ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( \" Expected ▁ 0 , ▁ 1 , ▁ or ▁ 2 ▁ args , ▁ not ▁ { : d } \" . format ( len ( args ) - 1 ) ) NEW_LINE print ( args ) NEW_LINE return NEW_LINE DEDENT t = readint ( ) NEW_LINE for casenum in range ( 1 , t + 1 ) : NEW_LINE INDENT main ( casenum ) NEW_LINE DEDENT if infile is not sys . stdin : NEW_LINE INDENT infile . close ( ) NEW_LINE DEDENT if outfile is not sys . stdout : NEW_LINE INDENT outfile . close ( ) NEW_LINE DEDENT DEDENT", "def minify ( s ) : NEW_LINE INDENT r = \" \" NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i == 0 or s [ i - 1 ] != s [ i ] : NEW_LINE INDENT r += s [ i ] NEW_LINE DEDENT DEDENT return r NEW_LINE DEDENT def toarray ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i == 0 or s [ i - 1 ] != s [ i ] : NEW_LINE INDENT a += [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT a [ - 1 ] += 1 NEW_LINE DEDENT DEDENT return a NEW_LINE DEDENT def solve ( S ) : NEW_LINE INDENT if len ( set ( minify ( s ) for s in S ) ) > 1 : NEW_LINE INDENT return \" Fegla ▁ Won \" NEW_LINE DEDENT A = [ toarray ( s ) for s in S ] NEW_LINE ans = 0 NEW_LINE for p in range ( len ( A [ 0 ] ) ) : NEW_LINE INDENT a = 99999999 NEW_LINE for x in range ( min ( a [ p ] for a in A ) , max ( a [ p ] for a in A ) + 1 ) : NEW_LINE INDENT a = min ( a , sum ( abs ( a [ p ] - x ) for a in A ) ) NEW_LINE DEDENT ans += a NEW_LINE DEDENT return ans NEW_LINE DEDENT for i in range ( input ( ) ) : NEW_LINE INDENT N = input ( ) NEW_LINE S = [ raw_input ( ) for _ in range ( N ) ] NEW_LINE a = solve ( S ) NEW_LINE print \" Case ▁ # % s : ▁ % s \" % ( i + 1 , a ) NEW_LINE DEDENT" ]
codejam_10_01
[ "package code10 . qualification ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; public class A { public static String solve ( int N , long K , int [ ] times ) { String result = \" \" ; int time = times [ N ] ; if ( K < time ) { result = \" OFF \" ; } else if ( K == time ) { result = \" ON \" ; } else { long remain = K - time ; if ( remain % ( time + 1 ) == 0 ) { result = \" ON \" ; } else { result = \" OFF \" ; } } return result ; } public static void initTimes ( int [ ] times ) { times [ 1 ] = 1 ; for ( int i = 2 ; i < times . length ; i ++ ) { times [ i ] = times [ i - 1 ] * 2 + 1 ; } } public static void main ( String [ ] args ) throws Exception { String fileName = \" A - large \" ; File inputFile = new File ( fileName + \" . in \" ) ; File outputFile = new File ( fileName + \" . out \" ) ; FileReader reader = new FileReader ( inputFile ) ; FileWriter writer = new FileWriter ( outputFile ) ; StringBuilder inputLine = new StringBuilder ( ) ; String [ ] inputPart ; int totalCase ; char c = 0 ; int N = 0 ; long K = 0 ; int [ ] times = new int [ 31 ] ; initTimes ( times ) ; while ( ( c = ( char ) reader . read ( ) ) != ' \\n ' ) { inputLine . append ( c ) ; } totalCase = Integer . parseInt ( inputLine . toString ( ) ) ; for ( int caseIndex = 1 ; caseIndex <= totalCase ; caseIndex ++ ) { inputLine = new StringBuilder ( ) ; while ( ( c = ( char ) reader . read ( ) ) != ' \\n ' ) { inputLine . append ( c ) ; } inputPart = inputLine . toString ( ) . split ( \" ▁ \" ) ; N = Integer . parseInt ( inputPart [ 0 ] ) ; K = Long . parseLong ( inputPart [ 1 ] ) ; String output = \" Case ▁ # \" + caseIndex + \" : ▁ \" + solve ( N , K , times ) ; System . out . println ( output ) ; writer . write ( output + \" \\n \" ) ; } reader . close ( ) ; writer . close ( ) ; } }", "import java . io . * ; import java . util . * ; import java . text . * ; public class SnapperChain { public PrintStream out = System . out ; public PrintStream err = System . err ; public Scanner in = new Scanner ( System . in ) ; public DecimalFormat fmt = new DecimalFormat ( \"0.000000000\" ) ; public void main ( ) { try { int TCase , cc ; TCase = in . nextInt ( ) ; for ( cc = 1 ; cc <= TCase ; ++ cc ) { long n , K , L ; n = in . nextLong ( ) ; K = in . nextLong ( ) ; L = ( 1L << n ) ; out . println ( \" Case ▁ # \" + cc + \" : ▁ \" + ( ( K % ( L ) == ( L ) - 1 ) ? \" ON \" : \" OFF \" ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } public int iInt ( ) { return in . nextInt ( ) ; } public long iLong ( ) { return in . nextLong ( ) ; } public String iToken ( ) { return in . next ( ) ; } public String iLine ( ) { return in . nextLine ( ) ; } public static void main ( String [ ] args ) { long startTime = System . currentTimeMillis ( ) ; ( new SnapperChain ( ) ) . main ( ) ; long endTime = System . currentTimeMillis ( ) ; long ms = endTime - startTime ; long sec = ms / 1000 ; ms = ms % 1000 ; long min = sec / 60 ; sec = sec % 60 ; System . err . println ( \" Time ▁ Spent : ▁ \" + min + \" ▁ minute ( s ) ▁ \" + sec + \" ▁ second ( s ) ▁ \" + ms + \" ▁ ( ms ) \" ) ; } }", "import java . util . * ; import java . io . * ; public class AChain { public static void main ( String [ ] args ) { if ( args . length < 1 ) { System . out . println ( \" Usage : ▁ < fnIn > \" ) ; } String fn = args [ 0 ] ; String fnOut = toFnOut ( fn ) ; try { BufferedReader br = new BufferedReader ( new FileReader ( fn ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( fnOut ) ) ; String line = null ; int NCase = Integer . valueOf ( br . readLine ( ) . trim ( ) ) ; long stime = System . currentTimeMillis ( ) ; for ( int icase = 0 ; icase < NCase ; icase ++ ) { int [ ] a = toIntArray ( br . readLine ( ) ) ; String buf = process ( a [ 0 ] , a [ 1 ] ) ; String out = \" Case ▁ # \" + ( icase + 1 ) + \" : ▁ \" + buf ; bw . write ( out , 0 , out . length ( ) ) ; bw . newLine ( ) ; long ctime = System . currentTimeMillis ( ) ; System . out . println ( String . format ( \" - - - ▁ Done : ▁ # %2d , %3.0fs , ▁ ends ▁ in : %2.1fm \" , ( icase + 1 ) , ( ctime - stime ) * 0.001 , ( ctime - stime ) * 0.001 / 60 * NCase / ( icase + 1 ) ) ) ; } br . close ( ) ; bw . close ( ) ; } catch ( IOException ex ) { System . out . println ( ex ) ; } } static String process ( int N , int K ) { int x = ( 1 << N ) ; while ( K >= x ) { K %= x ; } if ( K == x - 1 ) return \" ON \" ; return \" OFF \" ; } static int [ ] toIntArray ( String line ) { String [ ] p = line . trim ( ) . split ( \" \\\\ s + \" ) ; int [ ] out = new int [ p . length ] ; for ( int i = 0 ; i < out . length ; i ++ ) out [ i ] = Integer . valueOf ( p [ i ] ) ; return out ; } static String toFnOut ( String fn ) { if ( fn . lastIndexOf ( ' . ' ) != - 1 ) { return fn . substring ( 0 , fn . lastIndexOf ( ' . ' ) ) + \" . out \" ; } else return fn + \" . out \" ; } }", "package codejam2010 . qualification ; import java . io . BufferedReader ; import java . io . Closeable ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; public class ProblemA { public static void main ( String [ ] args ) { BufferedReader reader = null ; PrintWriter writer = null ; try { String fileName = \" A - large \" ; File folder = new File ( new File ( \" files \" , \" codejam2010\" ) , \" qualification \" ) ; File inputFile = new File ( folder , fileName + \" . in \" ) ; File outputFile = new File ( folder , fileName + \" . out \" ) ; reader = new BufferedReader ( new FileReader ( inputFile ) ) ; writer = new PrintWriter ( new FileWriter ( outputFile ) ) ; int count = Integer . parseInt ( reader . readLine ( ) ) ; for ( int i = 0 ; i < count ; i ++ ) { String [ ] parameters = reader . readLine ( ) . split ( \" \\\\ s \" ) ; writer . printf ( \" Case ▁ # % d : ▁ % s \\n \" , i + 1 , solveIt ( Integer . parseInt ( parameters [ 0 ] ) , Integer . parseInt ( parameters [ 1 ] ) ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { close ( reader ) ; close ( writer ) ; } System . out . println ( \" Done . \" ) ; } private static String solveIt ( int n , int k ) { int allOn = ( 1 << n ) - 1 ; return ( ( allOn & k ) == allOn ) ? \" ON \" : \" OFF \" ; } private static void close ( Closeable file ) { if ( file != null ) { try { file . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class A extends SolutionT { public static void main ( String [ ] args ) { ( new A ( ) ) . run ( ) ; } @ Override void runOneTest ( Scanner input , PrintWriter output ) { int n = input . nextInt ( ) ; int k = input . nextInt ( ) ; k = k % ( 1 << n ) ; if ( ( k + 1 ) == ( 1 << n ) ) { output . println ( \" ON \" ) ; } else { output . println ( \" OFF \" ) ; } } } abstract class Solution implements Runnable { abstract void runOneTest ( Scanner input , PrintWriter output ) ; public void run ( ) { Scanner input = null ; PrintWriter output = null ; try { input = new Scanner ( new File ( \" input . txt \" ) ) ; output = new PrintWriter ( new File ( \" output . txt \" ) ) ; } catch ( FileNotFoundException e ) { } int testCount = input . nextInt ( ) ; for ( int test = 1 ; test <= testCount ; test ++ ) { output . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; runOneTest ( input , output ) ; } input . close ( ) ; output . close ( ) ; } }" ]
[ "import sys NEW_LINE import time NEW_LINE import re NEW_LINE try : NEW_LINE INDENT import psyco NEW_LINE psyco . full ( ) NEW_LINE DEDENT except ImportError : NEW_LINE INDENT pass NEW_LINE DEDENT class tee : NEW_LINE INDENT def __init__ ( self , * fds ) : NEW_LINE INDENT self . _fds = fds NEW_LINE DEDENT def write ( self , data ) : NEW_LINE INDENT for fd in self . _fds : NEW_LINE INDENT fd . write ( data ) NEW_LINE DEDENT DEDENT def flush ( self ) : NEW_LINE INDENT for fd in self . _fds : NEW_LINE INDENT fd . flush ( ) NEW_LINE DEDENT DEDENT def close ( self ) : NEW_LINE INDENT for fd in self . _fds : NEW_LINE INDENT fd . close ( ) NEW_LINE DEDENT DEDENT DEDENT def fileCaseReader ( source ) : NEW_LINE INDENT entryCount = int ( source . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , entryCount + 1 ) : NEW_LINE INDENT yield i NEW_LINE DEDENT DEDENT def readLines ( source ) : NEW_LINE INDENT entryCount = int ( source . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 0 , entryCount ) : NEW_LINE INDENT yield source . readline ( ) NEW_LINE DEDENT DEDENT def readLineOfInts ( f ) : NEW_LINE INDENT return map ( int , f . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE DEDENT def runCase ( f ) : NEW_LINE INDENT n , k = readLineOfInts ( f ) NEW_LINE if ( k + 1 ) % 2 ** n == 0 : NEW_LINE INDENT print \" ON \" NEW_LINE DEDENT else : NEW_LINE INDENT print \" OFF \" NEW_LINE DEDENT DEDENT def timerWrap ( f ) : NEW_LINE INDENT def __inner ( * args , ** kwargs ) : NEW_LINE INDENT start = time . time ( ) NEW_LINE try : NEW_LINE INDENT return f ( * args , ** kwargs ) NEW_LINE DEDENT finally : NEW_LINE INDENT print >> sys . stderr , \" Runtime : ▁ % .3f ▁ sec \" % ( time . time ( ) - start ) NEW_LINE DEDENT DEDENT return __inner NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT f = file ( \" snapper . in \" , \" r \" ) ; NEW_LINE sys . stdout = tee ( sys . stdout , file ( \" snapper . out \" , \" w \" ) ) NEW_LINE for index in fileCaseReader ( f ) : NEW_LINE INDENT print \" Case ▁ # % d : \" % index , NEW_LINE runCase ( f ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT inFile = open ( \" A - large . in \" , \" r \" ) NEW_LINE outFile = open ( \" realtest . out \" , \" w \" ) NEW_LINE caseNum = int ( inFile . readline ( ) ) NEW_LINE for i in range ( 1 , caseNum + 1 ) : NEW_LINE INDENT items = inFile . readline ( ) . replace ( \" \\n \" , \" \" ) . split ( \" ▁ \" ) NEW_LINE N = int ( items [ 0 ] ) NEW_LINE K = int ( items [ 1 ] ) NEW_LINE lightFlag = 1 NEW_LINE for j in range ( N ) : NEW_LINE INDENT if K % 2 == 0 : NEW_LINE INDENT lightFlag = 0 NEW_LINE break ; NEW_LINE DEDENT else : NEW_LINE INDENT K /= 2 NEW_LINE DEDENT DEDENT if lightFlag == 1 : NEW_LINE INDENT outFile . write ( \" Case ▁ # % d : ▁ ON \\n \" % ( i , ) ) NEW_LINE DEDENT else : NEW_LINE INDENT outFile . write ( \" Case ▁ # % d : ▁ OFF \\n \" % ( i , ) ) NEW_LINE DEDENT DEDENT outFile . close ( ) NEW_LINE inFile . close ( ) NEW_LINE DEDENT", "m = { 0 : \" OFF \" , 1 : \" ON \" } NEW_LINE def f ( n , k ) : NEW_LINE INDENT return m [ int ( ( ( k + 1 ) % ( 2 ** n ) ) == 0 ) ] NEW_LINE DEDENT import sys NEW_LINE t = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT a = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE assert len ( a ) == 2 NEW_LINE ( n , k ) = a NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i , f ( n , k ) ) NEW_LINE DEDENT", "tn = int ( raw_input ( ) ) NEW_LINE for loop in xrange ( tn ) : NEW_LINE INDENT n , k = raw_input ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE k = int ( k ) NEW_LINE x = 2 ** n NEW_LINE on = False NEW_LINE if k % x == x - 1 : NEW_LINE INDENT on = True NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( loop + 1 , [ ' OFF ' , ' ON ' ] [ on ] ) NEW_LINE DEDENT", "import sys , re NEW_LINE getline = lambda f : f . readline ( ) . strip ( ) NEW_LINE gettoken = lambda f : re . split ( \" \\s + \" , getline ( f ) ) NEW_LINE getint = lambda f : int ( getline ( f ) ) NEW_LINE getints = lambda f : map ( int , gettoken ( f ) ) NEW_LINE product = lambda l : reduce ( lambda x , y : x * y , l ) if l else 1 NEW_LINE factorial = lambda n : product ( xrange ( n , 1 , - 1 ) ) NEW_LINE nPr = lambda n , r : product ( xrange ( n , n - r , - 1 ) ) NEW_LINE nCr = lambda n , r : nPr ( n , r ) / factorial ( r ) NEW_LINE nMr = lambda l : factorial ( sum ( l ) ) / product ( map ( factorial , l ) ) NEW_LINE gcd = lambda x , y : gcd ( y , x % y ) if y != 0 else x NEW_LINE lcm = lambda x , y : x * y / gcd ( x , y ) NEW_LINE def gcd2 ( a , b ) : NEW_LINE INDENT if b == 0 : return ( a , 1 , 0 ) NEW_LINE ( d , x , y ) = gcd2 ( b , a % b ) NEW_LINE return ( d , y , x - a / b * y ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT f = open ( sys . argv [ 1 ] ) NEW_LINE [ N ] = getints ( f ) NEW_LINE for cases in xrange ( 0 , N ) : NEW_LINE INDENT ans = 0 NEW_LINE n , k = getints ( f ) NEW_LINE M = ( 1 << n ) NEW_LINE s = \" OFF \" NEW_LINE if k % M == ( M - 1 ) : s = \" ON \" NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( cases + 1 , s ) NEW_LINE DEDENT DEDENT" ]
codejam_09_13
[ "import java . util . * ; import static java . lang . Math . * ; public class C { void p ( String s ) { System . out . println ( s ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { C = sc . nextInt ( ) ; N = sc . nextInt ( ) ; dp = new double [ C + 1 ] ; Arrays . fill ( dp , - 1.0 ) ; System . out . println ( \" Case ▁ # \" + zz + \" : ▁ \" + dp ( 0 ) ) ; } } static int C , N ; static double [ ] dp ; public static double dp ( int numDiff ) { if ( numDiff >= C ) return 0.0 ; if ( dp [ numDiff ] != - 1.0 ) return dp [ numDiff ] ; double pr0 = ( ( double ) choose ( numDiff , N ) ) / choose ( C , N ) ; double ev = 0.0 ; for ( int i = 1 ; i <= N ; i ++ ) { ev += ( 1.0 + dp ( numDiff + i ) ) * ( ( ( double ) choose ( numDiff , N - i ) * choose ( C - numDiff , i ) ) ) / ( choose ( C , N ) ) ; } double ans = ( pr0 + ev ) / ( 1 - pr0 ) ; dp [ numDiff ] = ans ; return ans ; } public static long choose ( int n , int k ) { long ans = 1 ; ArrayList < Integer > toDiv = new ArrayList < Integer > ( ) ; for ( int i = 2 ; i <= k ; i ++ ) toDiv . add ( i ) ; for ( int i = n ; i >= n - k + 1 ; i -- ) { ans *= i ; for ( int j = 0 ; j < toDiv . size ( ) ; j ++ ) { if ( ans % toDiv . get ( j ) == 0 ) { ans /= toDiv . get ( j ) ; toDiv . remove ( j ) ; j -- ; } } } return ans ; } }", "import java . util . * ; import java . io . * ; import java . math . * ; public class x { public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; long [ ] [ ] C = new long [ 41 ] [ 41 ] ; for ( int i = 0 ; i <= 40 ; i ++ ) { C [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j <= i ; j ++ ) C [ i ] [ j ] = C [ i - 1 ] [ j ] + C [ i - 1 ] [ j - 1 ] ; } MathContext mc = new MathContext ( 50 , RoundingMode . HALF_EVEN ) ; for ( int tt = 1 ; tt <= t ; tt ++ ) { int A = in . nextInt ( ) , N = in . nextInt ( ) ; BigDecimal [ ] E = new BigDecimal [ A + 1 ] ; E [ A ] = new BigDecimal ( 0 , mc ) ; for ( int i = A - 1 ; i >= 0 ; i -- ) { E [ i ] = new BigDecimal ( C [ A ] [ N ] , mc ) ; for ( int j = i + 1 ; j <= Math . min ( A , i + N ) ; j ++ ) { BigDecimal P = new BigDecimal ( C [ A - i ] [ j - i ] , mc ) ; P = P . multiply ( new BigDecimal ( C [ i ] [ N - j + i ] , mc ) , mc ) ; E [ i ] = E [ i ] . add ( P . multiply ( E [ j ] , mc ) , mc ) ; } BigDecimal D = new BigDecimal ( C [ A ] [ N ] , mc ) . subtract ( new BigDecimal ( C [ i ] [ N ] , mc ) , mc ) ; E [ i ] = E [ i ] . divide ( D , mc ) ; } System . out . println ( \" Case ▁ # \" + tt + \" : ▁ \" + E [ 0 ] ) ; } ; } ; } ;", "import java . util . Arrays ; import java . util . Scanner ; public class C { public static void main ( String [ ] args ) throws Exception { new C ( ) ; } final int oo = ( int ) 1e9 ; double [ ] [ ] choose = new double [ 50 ] [ 50 ] ; int N , C ; double D ; double [ ] memo = new double [ 50 ] ; C ( ) throws Exception { for ( double [ ] c : choose ) Arrays . fill ( c , - 1 ) ; Scanner in = new Scanner ( System . in ) ; for ( int T = in . nextInt ( ) , ds = 1 ; T -- > 0 ; ++ ds ) { C = in . nextInt ( ) ; N = in . nextInt ( ) ; D = choose ( C , N ) ; Arrays . fill ( memo , - 1 ) ; System . out . printf ( \" Case ▁ # % d : ▁ % .9f % n \" , ds , go ( 0 ) ) ; } } double go ( int X ) { if ( X == C ) return 0 ; if ( memo [ X ] > - 0.5 ) return memo [ X ] ; double exp = 1 ; for ( int i = 1 ; i <= N ; ++ i ) { if ( X + i > C ) break ; exp += choose ( X , N - i ) * choose ( C - X , i ) / D * go ( X + i ) ; } exp /= ( 1 - choose ( X , N ) * choose ( C - X , 0 ) / D ) ; return memo [ X ] = exp ; } double choose ( int n , int k ) { if ( k == 0 || n == k ) return 1 ; if ( n < k ) return 0 ; if ( choose [ n ] [ k ] > - 0.5 ) return choose [ n ] [ k ] ; return choose [ n ] [ k ] = choose ( n - 1 , k - 1 ) + choose ( n - 1 , k ) ; } }", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . PrintStream ; import java . util . Scanner ; public class C { private static String PNAME = \" C - large \" ; public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( PNAME + \" . in \" ) ) ; PrintStream out = new PrintStream ( PNAME + \" . out \" ) ; Scanner in = new Scanner ( br ) ; int TC = in . nextInt ( ) ; for ( int tc = 1 ; tc <= TC ; tc ++ ) { int c = in . nextInt ( ) ; int n = in . nextInt ( ) ; out . println ( \" Case ▁ # \" + tc + \" : ▁ \" + solve ( c , n ) ) ; } br . close ( ) ; out . close ( ) ; } private static double solve ( int c , int n ) { for ( int i = 0 ; i < memo . length ; i ++ ) memo [ i ] = - 1 ; return calc ( c , n , c ) ; } private static double calc ( int c , int n , int need ) { if ( need == 0 ) return 0 ; if ( memo [ need ] != - 1 ) return memo [ need ] ; double ret = 1 ; int have = c - need ; for ( int good = 1 ; good <= Math . min ( n , need ) ; good ++ ) { int bad = n - good ; double p = choose ( need , good ) ; p *= choose ( have , bad ) ; p /= choose ( c , n ) ; ret += p * calc ( c , n , need - good ) ; } if ( have >= n ) { double p = choose ( have , n ) * 1.0 / choose ( c , n ) ; ret /= 1 - p ; } memo [ need ] = ret ; return ret ; } private static long choose ( int n , int k ) { long ret = 1 ; for ( int i = 0 ; i < k ; i ++ ) { ret *= n - i ; ret /= i + 1 ; } return ret ; } static double [ ] memo = new double [ 64 ] ; }" ]
[ "import os , sys NEW_LINE import operator NEW_LINE def choose ( n , c ) : NEW_LINE INDENT if c == 0 or c == n : NEW_LINE INDENT return 1 NEW_LINE DEDENT return reduce ( operator . mul , range ( n , n - c , - 1 ) ) / reduce ( operator . mul , range ( 1 , c + 1 ) ) NEW_LINE DEDENT def buildCardsTable ( cards , numNeeded , numPerPack ) : NEW_LINE INDENT table = [ ] NEW_LINE possiblePacks = 1.0 * choose ( cards , numPerPack ) NEW_LINE for entry in range ( 0 , numNeeded + 1 ) : NEW_LINE INDENT if entry == 0 : NEW_LINE INDENT table . append ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT a = 0 NEW_LINE b = 0 NEW_LINE for numInThisPack in range ( numPerPack + 1 ) : NEW_LINE INDENT if ( numInThisPack <= entry ) : NEW_LINE INDENT frac = ( choose ( entry , numInThisPack ) * choose ( cards - entry , numPerPack - numInThisPack ) ) NEW_LINE if ( numInThisPack != 0 ) : NEW_LINE INDENT b += frac * ( 1 + table [ entry - numInThisPack ] ) NEW_LINE DEDENT else : NEW_LINE INDENT a += frac NEW_LINE b += frac NEW_LINE DEDENT DEDENT DEDENT table . append ( b / ( possiblePacks - a ) ) NEW_LINE DEDENT DEDENT return table [ numNeeded ] NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE words = [ ] NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT [ cards , numPerPack ] = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE numNeeded = cards - numPerPack NEW_LINE expected = buildCardsTable ( cards , numNeeded , numPerPack ) NEW_LINE index += 1 NEW_LINE print \" Case ▁ # % d : ▁ % .9f \" % ( caseNum + 1 , 1.0 + expected ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT", "from __future__ import division NEW_LINE def memoize ( f ) : NEW_LINE INDENT d = { } NEW_LINE def g ( * args ) : NEW_LINE INDENT if args not in d : NEW_LINE INDENT d [ args ] = f ( * args ) NEW_LINE DEDENT return d [ args ] NEW_LINE DEDENT return g NEW_LINE DEDENT def ints ( ) : NEW_LINE INDENT return map ( int , raw_input ( ) . split ( ) ) NEW_LINE DEDENT @ memoize NEW_LINE def p ( get , have , packsize , total ) : NEW_LINE INDENT if get < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif get < packsize - have : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif get > total - have : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif packsize == 0 : NEW_LINE INDENT if get == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return have / total * p ( get , have - 1 , packsize - 1 , total - 1 ) + ( total - have ) / total * p ( get - 1 , have , packsize - 1 , total - 1 ) NEW_LINE DEDENT DEDENT @ memoize NEW_LINE def E ( obtain , have , packsize , total ) : NEW_LINE INDENT if obtain == have : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return ( 1 + sum ( E ( obtain , have + get , packsize , total ) * p ( get , have , packsize , total ) for get in xrange ( 1 , min ( packsize , total - have ) + 1 ) ) ) / ( 1 - p ( 0 , have , packsize , total ) ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT T , = ints ( ) NEW_LINE for case in xrange ( T ) : NEW_LINE INDENT total , packsize = ints ( ) NEW_LINE print \" Case ▁ # % s : ▁ % s \" % ( ( case + 1 ) , E ( total , 0 , packsize , total ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "filename = ' C - large ' NEW_LINE f = open ( filename + ' . in ' , ' r ' ) NEW_LINE lines = f . readlines ( ) NEW_LINE f . close ( ) NEW_LINE MAX = 41 NEW_LINE FACT = [ 0.0 ] * MAX NEW_LINE def fact ( n ) : NEW_LINE INDENT if FACT [ n ] != 0 : NEW_LINE INDENT return FACT [ n ] NEW_LINE DEDENT tot = 1.0 NEW_LINE for x in xrange ( 1 , n + 1 ) : NEW_LINE INDENT tot *= x NEW_LINE DEDENT FACT [ n ] = tot NEW_LINE return tot NEW_LINE DEDENT def choose ( N , k ) : NEW_LINE INDENT if k > N : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT return fact ( N ) / fact ( k ) / fact ( N - k ) NEW_LINE DEDENT print choose ( 5 , 0 ) , choose ( 5 , 1 ) , choose ( 5 , 5 ) , choose ( 5 , 7 ) NEW_LINE CACHE = { } NEW_LINE def get_exp_num ( C , N , S ) : NEW_LINE INDENT if S in CACHE : NEW_LINE INDENT return CACHE [ S ] NEW_LINE DEDENT if S >= C : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT tot_num = choose ( C , N ) NEW_LINE self_fact = choose ( C - S , 0 ) * choose ( S , N ) / tot_num NEW_LINE ans = 0.0 NEW_LINE ans += 1.0 * self_fact NEW_LINE for k in xrange ( 1 , N + 1 ) : NEW_LINE INDENT prob = choose ( C - S , k ) * choose ( S , N - k ) / tot_num NEW_LINE ans += prob * ( 1.0 + get_exp_num ( C , N , S + k ) ) NEW_LINE DEDENT ans = ans / ( 1.0 - self_fact ) NEW_LINE CACHE [ S ] = ans NEW_LINE return ans NEW_LINE DEDENT out = open ( filename + ' . out ' , ' w ' ) NEW_LINE T = int ( lines [ 0 ] . strip ( ) ) NEW_LINE case = 1 NEW_LINE for line in lines [ 1 : ] : NEW_LINE INDENT C , N = [ int ( x ) for x in line . strip ( ) . split ( ' ▁ ' ) ] NEW_LINE CACHE = { } NEW_LINE ans = get_exp_num ( C , N , 0 ) NEW_LINE print ' Case ▁ # % d : ▁ % 0.6f ' % ( case , ans ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % 0.6f \\n ' % ( case , ans ) ) NEW_LINE case += 1 NEW_LINE DEDENT out . close ( ) NEW_LINE", "from scipy . special import gammaln , exp NEW_LINE from scipy import comb NEW_LINE import sys NEW_LINE def factln ( n ) : NEW_LINE INDENT return gammaln ( n + 1 ) NEW_LINE DEDENT def prob_old ( c , n , j , k ) : NEW_LINE INDENT pi = k - j NEW_LINE po = c - pi NEW_LINE lnp = factln ( n - c ) + factln ( j ) + factln ( n - j ) NEW_LINE lnp -= factln ( n ) + factln ( j - po ) + factln ( n - j - pi ) NEW_LINE p = exp ( lnp ) NEW_LINE return p NEW_LINE DEDENT def prob ( c , n , j , k ) : NEW_LINE INDENT pi = k - j NEW_LINE po = c - pi NEW_LINE old_count = j NEW_LINE new_count = n - j NEW_LINE return comb ( old_count , po ) * comb ( new_count , pi ) / comb ( n , c ) NEW_LINE DEDENT def solve ( c , n ) : NEW_LINE INDENT p0 = [ 0 for x in range ( n + 1 ) ] NEW_LINE p0 [ 0 ] = 1.0 NEW_LINE p1 = [ 0.0 for x in range ( n + 1 ) ] NEW_LINE sum = 0.0 NEW_LINE nstep = 0 NEW_LINE prob_prev = 0.0 NEW_LINE while p0 [ n ] < 0.999999 : NEW_LINE INDENT for j in range ( n + 1 ) : p1 [ j ] = 0.0 NEW_LINE for j in range ( n + 1 ) : NEW_LINE INDENT for k in range ( j , n + 1 ) : NEW_LINE INDENT if k - j > c : break NEW_LINE p = prob ( c , n , j , k ) NEW_LINE p1 [ k ] += p0 [ j ] * p NEW_LINE DEDENT DEDENT for j in range ( n + 1 ) : p0 [ j ] = p1 [ j ] NEW_LINE nstep += 1 NEW_LINE sum += ( p0 [ n ] - prob_prev ) * ( nstep ) NEW_LINE prob_prev = p0 [ n ] NEW_LINE DEDENT return sum NEW_LINE DEDENT fn = sys . argv [ 1 ] NEW_LINE f = open ( fn , ' r ' ) NEW_LINE t = int ( f . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT n , c = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE s = solve ( c , n ) NEW_LINE print \" Case ▁ # % d : ▁ % .8f \" % ( i + 1 , s ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT", "import sys NEW_LINE import psyco NEW_LINE from numpy import linalg NEW_LINE psyco . full ( ) NEW_LINE def p ( a , b ) : NEW_LINE INDENT if b < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if a < b : NEW_LINE INDENT return 0 NEW_LINE DEDENT if b * 2 > a : NEW_LINE INDENT return p ( a , a - b ) NEW_LINE DEDENT res = 1 NEW_LINE for i in range ( b ) : NEW_LINE INDENT res *= a - i NEW_LINE DEDENT for i in range ( b ) : NEW_LINE INDENT res //= ( i + 1 ) NEW_LINE DEDENT return res NEW_LINE DEDENT def foo ( ifile ) : NEW_LINE INDENT n , c = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] NEW_LINE pnc = p ( n , c ) NEW_LINE res = [ ] NEW_LINE for i in range ( c , n ) : NEW_LINE INDENT t = [ 0.0 ] * ( n + 1 ) NEW_LINE for j in range ( i , n + 1 ) : NEW_LINE INDENT ii = n - i NEW_LINE jj = j - i NEW_LINE t [ j ] = ( p ( ii , jj ) * p ( i , c - jj ) + 0.0 ) / pnc NEW_LINE DEDENT t [ i ] -= 1.0 NEW_LINE t = t [ c : ] NEW_LINE res . append ( t ) NEW_LINE DEDENT t = [ 0 ] * ( n + 1 - c ) NEW_LINE t [ 0 ] = 1 NEW_LINE res . append ( t ) NEW_LINE t2 = [ 1.0 ] * ( n + 1 - c ) NEW_LINE return ' % .7f ' % linalg . solve ( res , t2 ) [ - 1 ] NEW_LINE DEDENT def main ( ifile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % s ' % ( i + 1 , foo ( ifile ) ) NEW_LINE DEDENT DEDENT main ( sys . stdin ) NEW_LINE" ]
codejam_15_63
[ "import java . io . * ; import java . util . StringTokenizer ; public class C { private int solveTest ( ) throws IOException { int n = nextInt ( ) ; double f = Double . parseDouble ( next ( ) ) ; int [ ] a = new int [ n ] ; String s = next ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s . charAt ( i ) - '0' ; } double best = 1e100 ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int k = 0 ; for ( int j = i ; j < n ; j ++ ) { int l = j - i + 1 ; k += a [ j ] ; double x = 1.0 * k / l ; double dif = Math . abs ( x - f ) ; if ( dif < best - 1e-9 ) { best = dif ; res = i ; } } } return res ; } private void solve ( ) throws IOException { int n = nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int res = solveTest ( ) ; System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + res ) ; out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + res ) ; } } BufferedReader br ; StringTokenizer st ; PrintWriter out ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new C ( ) . run ( ) ; } private void run ( ) throws FileNotFoundException { br = new BufferedReader ( new FileReader ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + \" . in \" ) ) ; out = new PrintWriter ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + \" . out \" ) ; try { solve ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } out . close ( ) ; } }" ]
[ "from fractions import Fraction NEW_LINE def reader ( inFile ) : NEW_LINE INDENT ( N , F ) = inFile . getWords ( ) NEW_LINE N = int ( N ) NEW_LINE F = Fraction ( F ) NEW_LINE return ( N , F , inFile . readline ( ) ) NEW_LINE DEDENT def solver ( ( N , F , word ) ) : NEW_LINE INDENT t = [ 0 ] * ( N + 1 ) NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT t [ i + 1 ] = t [ i ] + int ( word [ i ] ) NEW_LINE DEDENT rec = ( 2 , 0 ) NEW_LINE for j in xrange ( 1 , N + 1 ) : NEW_LINE INDENT for i in xrange ( j ) : NEW_LINE INDENT ratio = Fraction ( t [ j ] - t [ i ] , j - i ) NEW_LINE scr = ( abs ( ratio - F ) , i ) NEW_LINE if scr < rec : NEW_LINE INDENT rec = scr NEW_LINE DEDENT DEDENT DEDENT return rec [ 1 ] NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , r \" C : \\gcj\\finals\\c \" , \" c \" ) . run ( ) NEW_LINE DEDENT" ]
codejam_14_02
[ "import java . util . * ; import java . io . * ; public class B { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" B - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( new File ( \" B - large . out \" ) ) ) ; int t = in . nextInt ( ) ; for ( int y = 0 ; y < t ; y ++ ) { double c = in . nextDouble ( ) ; double f = in . nextDouble ( ) ; double x = in . nextDouble ( ) ; long low = 0 ; long high = ( long ) 1E6 ; while ( low + 2 < high ) { long mid1 = low + ( high - low ) / 3 ; long mid2 = low + 2 * ( high - low ) / 3 ; if ( getTime ( mid1 , c , f , x ) < getTime ( mid2 , c , f , x ) ) { high = mid2 - 1 ; } else { low = mid1 ; } } double result = Double . POSITIVE_INFINITY ; for ( long z = low ; z <= high ; z ++ ) { result = Math . min ( result , getTime ( z , c , f , x ) ) ; } out . printf ( \" Case ▁ # % d : ▁ % .7f \\n \" , y + 1 , result ) ; } out . close ( ) ; } public static double getTime ( long buildings , double c , double f , double x ) { double time = 0 ; double rate = 2 ; for ( int i = 0 ; i < buildings ; i ++ ) { time += c / rate ; rate += f ; } return time + ( x / rate ) ; } }", "import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . text . DecimalFormat ; import java . util . Scanner ; public class Cookie { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new FileReader ( \" jam . in \" ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( \" jam . out \" ) ) ; int cases ; cases = sc . nextInt ( ) ; for ( int z = 1 ; z <= cases ; z ++ ) { double C = sc . nextDouble ( ) ; double F = sc . nextDouble ( ) ; double X = sc . nextDouble ( ) ; double product = 2 ; double ans = 0 ; while ( X / ( product + F ) + C / product < X / product ) { ans += C / product ; product += F ; } ans += X / product ; bw . write ( \" Case ▁ # \" + z + \" : ▁ \" ) ; DecimalFormat df = new DecimalFormat ( \"0.00000000\" ) ; bw . write ( \" \" + df . format ( ans ) + \" \\n \" ) ; } sc . close ( ) ; bw . close ( ) ; } }", "package con2014Q ; import java . io . * ; import java . util . * ; public class B { private static final String islarge = \" - large \" ; private static final String fileName = \" results / con2014Q / \" + B . class . getSimpleName ( ) . toLowerCase ( ) + islarge ; private static final String inputFileName = fileName + \" . in \" ; private static final String outputFileName = fileName + \" . out \" ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { double C = Double . parseDouble ( in . next ( ) ) , F = Double . parseDouble ( in . next ( ) ) , X = Double . parseDouble ( in . next ( ) ) ; double best = X / 2 ; double cur = 0 ; int a_farms = 0 ; while ( cur < best ) { cur += C / ( 2 + ( a_farms * F ) ) ; a_farms ++ ; best = Math . min ( best , cur + ( X / ( 2 + ( a_farms * F ) ) ) ) ; } out . format ( \" % .7f % n \" , best ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; long start = System . currentTimeMillis ( ) ; in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; new B ( ) . solve ( ) ; System . out . println ( \" Case ▁ # \" + t + \" : ▁ solved \" ) ; } in . close ( ) ; out . close ( ) ; long stop = System . currentTimeMillis ( ) ; System . out . println ( stop - start + \" ▁ ms \" ) ; } }", "import java . io . File ; import java . io . PrintStream ; import java . util . Scanner ; public class B { static final Boolean SAMPLE = false ; static final String PROBLEM = \" B \" ; static final String INPUT = \" large \" ; static final String ID = \"0\" ; static final String PATH = \" F : \\\\ software ▁ installation \\\\ codejam - commandline - 1.2 - beta1 \\\\ source\\ \\\" ; public static void main ( String args [ ] ) throws Throwable { Scanner in = SAMPLE ? new Scanner ( System . in ) : new Scanner ( new File ( PATH + PROBLEM + \" - \" + INPUT + \" - \" + ID + \" . in \" ) ) ; PrintStream out = SAMPLE ? System . out : new PrintStream ( PATH + PROBLEM + \" - \" + INPUT + \" - \" + ID + \" . out \" ) ; int test = in . nextInt ( ) ; for ( int t = 1 ; t <= test ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; double C = in . nextDouble ( ) ; double F = in . nextDouble ( ) ; double X = in . nextDouble ( ) ; double time = 0 ; double speed = 2 ; while ( X / speed > C / speed + X / ( speed + F ) ) { time += C / speed ; speed += F ; } time += X / speed ; out . println ( time ) ; } out . close ( ) ; in . close ( ) ; System . out . println ( \" finish ! \" ) ; } }", "package exoB ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoB { public static void main ( String [ ] args ) { String base = \" / home / jean / gcj2014 / q / ExoB / \" ; String input = base + \" b1 . in \" ; String output = base + \" b1 . out \" ; try { Scanner sc = new Scanner ( new FileReader ( input ) ) ; PrintWriter pw = new PrintWriter ( output ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( \" Test ▁ case ▁ \" + ( c + 1 ) + \" . . . \" ) ; pw . print ( \" Case ▁ # \" + ( c + 1 ) + \" : ▁ \" ) ; test ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( FileNotFoundException ex ) { Logger . getLogger ( ExoB . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test ( Scanner sc , PrintWriter pw ) { double C = sc . nextDouble ( ) ; double F = sc . nextDouble ( ) ; double X = sc . nextDouble ( ) ; double r = 2.0 ; double t = 0.0 ; while ( X / r > C / r + X / ( r + F ) ) { t = t + C / r ; r += F ; } t = t + X / r ; pw . print ( t ) ; } }" ]
[ "def bestCookieTime ( c , f , x ) : NEW_LINE INDENT zero_time = cookieTime ( c , f , x , 0 ) NEW_LINE best_time = zero_time NEW_LINE total_farms = 1000 NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 1000 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT total_farms -= 1900 NEW_LINE if total_farms < 10 : NEW_LINE INDENT total_farms = 10 NEW_LINE DEDENT best_time = zero_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 100 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT total_farms -= 190 NEW_LINE if total_farms < 10 : NEW_LINE INDENT total_farms = 10 NEW_LINE DEDENT best_time = zero_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 10 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT total_farms -= 19 NEW_LINE if total_farms < 1 : NEW_LINE INDENT total_farms = 1 NEW_LINE DEDENT best_time = zero_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 1 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT return str ( best_time ) NEW_LINE DEDENT def cookieTime ( c , f , x , total_farms ) : NEW_LINE INDENT if x < c : NEW_LINE INDENT return x / 2 NEW_LINE DEDENT farms = 0 NEW_LINE time = 0 NEW_LINE cookie_rate = 2 NEW_LINE while farms < total_farms : NEW_LINE INDENT time += c / cookie_rate NEW_LINE cookie_rate += f NEW_LINE farms += 1 NEW_LINE DEDENT return time + x / cookie_rate NEW_LINE DEDENT input_text = open ( \" input . in \" ) NEW_LINE lines = input_text . readlines ( ) NEW_LINE input_text . close ( ) NEW_LINE with open ( \" output \" , \" a \" ) as outputfile : NEW_LINE INDENT for num in range ( 0 , int ( lines [ 0 ] ) ) : NEW_LINE INDENT line = lines [ num + 1 ] . split ( \" ▁ \" ) NEW_LINE outputfile . write ( \" Case ▁ # \" + str ( num + 1 ) + \" : ▁ \" + bestCookieTime ( float ( line [ 0 ] ) , float ( line [ 1 ] ) , float ( line [ 2 ] ) ) + \" \\n \" ) NEW_LINE DEDENT DEDENT", "import fileinput NEW_LINE import sys NEW_LINE import math NEW_LINE def read_cases ( ) : NEW_LINE INDENT fh = fileinput . input ( ) NEW_LINE T = int ( fh . readline ( ) . strip ( ) ) NEW_LINE cases = [ ] NEW_LINE for t in range ( T ) : NEW_LINE INDENT case = { } NEW_LINE case [ \" C \" ] , case [ \" F \" ] , case [ \" X \" ] = map ( float , fh . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE cases += [ case ] NEW_LINE DEDENT if fh . readline ( ) . strip ( ) != \" \" : NEW_LINE INDENT raise Exception NEW_LINE DEDENT return cases NEW_LINE DEDENT def process_case ( case ) : NEW_LINE INDENT cps = [ 2.0 ] NEW_LINE C , F , X = case [ \" C \" ] , case [ \" F \" ] , case [ \" X \" ] NEW_LINE factories2timecomplete = [ X / cps [ 0 ] ] NEW_LINE elapsed2factory = [ 0.0 ] NEW_LINE factory_count = 0 NEW_LINE while True : NEW_LINE INDENT elapsed2factory += [ elapsed2factory [ - 1 ] + C / cps [ - 1 ] ] NEW_LINE factory_count += 1 NEW_LINE cps += [ cps [ - 1 ] + F ] NEW_LINE factories2timecomplete += [ elapsed2factory [ - 1 ] + X / cps [ - 1 ] ] NEW_LINE if factories2timecomplete [ - 1 ] > factories2timecomplete [ - 2 ] : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return factories2timecomplete [ - 2 ] NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT cases = read_cases ( ) NEW_LINE for i , case in enumerate ( cases [ : ] ) : NEW_LINE INDENT result = process_case ( case ) NEW_LINE print \" Case ▁ # % s : \" % ( i + 1 , ) , result NEW_LINE DEDENT DEDENT", "import math NEW_LINE input_file_name = ' . / B - large . in ' NEW_LINE output_file_name = ' . / B - large . out ' NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT input_file = open ( input_file_name , ' r ' ) NEW_LINE output_file = open ( output_file_name , ' w ' ) NEW_LINE file_line = input_file . readline ( ) NEW_LINE file_line = file_line . replace ( ' \\n ' , ' ' ) NEW_LINE num_cases = int ( file_line ) NEW_LINE case_num = 1 NEW_LINE while True : NEW_LINE INDENT file_line = input_file . readline ( ) NEW_LINE if file_line == ' ' or file_line == ' \\n ' : NEW_LINE INDENT input_file . close ( ) NEW_LINE break NEW_LINE DEDENT file_line = file_line . replace ( ' \\n ' , ' ' ) NEW_LINE file_line_list = file_line . split ( ) NEW_LINE C = float ( file_line_list [ 0 ] ) NEW_LINE F = float ( file_line_list [ 1 ] ) NEW_LINE X = float ( file_line_list [ 2 ] ) NEW_LINE if C >= X : NEW_LINE INDENT total_time = X / 2.0 NEW_LINE DEDENT else : NEW_LINE INDENT n = max ( 0.0 , float ( math . floor ( ( F * X - 2.0 * C ) / ( C * F ) ) ) ) NEW_LINE total_time = 0.0 NEW_LINE for n_i in range ( int ( n ) ) : NEW_LINE INDENT total_time += C / ( 2.0 + n_i * F ) NEW_LINE DEDENT total_time += X / ( 2.0 + n * F ) NEW_LINE DEDENT output_file . write ( ' Case ▁ # ' + str ( case_num ) + ' : ▁ % 0.7f \\n ' % total_time ) NEW_LINE print ( case_num ) NEW_LINE case_num += 1 NEW_LINE DEDENT output_file . close ( ) NEW_LINE DEDENT", "import sys , numpy NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( sys . argv [ 1 ] ) NEW_LINE T = int ( f . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT ( C , F , X ) = f . readline ( ) . strip ( ) . split ( ) NEW_LINE print \" Case ▁ # % d : ▁ % .7f \" % ( i , minTime ( float ( C ) , float ( F ) , float ( X ) ) ) NEW_LINE DEDENT DEDENT def minTime ( C , F , X ) : NEW_LINE INDENT C = numpy . longdouble ( C ) NEW_LINE F = numpy . longdouble ( F ) NEW_LINE X = numpy . longdouble ( X ) NEW_LINE n = numpy . longdouble ( 0.0 ) NEW_LINE two = numpy . longdouble ( 2.0 ) NEW_LINE prevTime = X / two ; NEW_LINE farmBuildTime = numpy . longdouble ( 0.0 ) ; NEW_LINE while True : NEW_LINE INDENT farmBuildTime += C / ( two + n * F ) NEW_LINE n += 1.0 NEW_LINE time = numpy . longdouble ( farmBuildTime + X / ( two + n * F ) ) NEW_LINE if time > prevTime : NEW_LINE INDENT return prevTime NEW_LINE DEDENT prevTime = time NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) ; NEW_LINE DEDENT", "import math NEW_LINE import sys NEW_LINE def findsol ( C , F , X ) : NEW_LINE INDENT t = 0.0 NEW_LINE tmax = X / 2 NEW_LINE N = 0 NEW_LINE while 1 : NEW_LINE INDENT t += C / ( 2 + N * F ) NEW_LINE if ( t > tmax ) : NEW_LINE INDENT return str ( tmax ) NEW_LINE DEDENT N += 1 NEW_LINE t2 = t + X / ( 2 + N * F ) NEW_LINE if ( t2 < tmax ) : NEW_LINE INDENT tmax = t2 NEW_LINE DEDENT DEDENT return b NEW_LINE DEDENT def convertreals ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE ii = 0 NEW_LINE for jj in range ( len ( s ) ) : NEW_LINE INDENT if s [ jj ] == ' ▁ ' : NEW_LINE INDENT if ( ii < jj ) : NEW_LINE INDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE ii = jj + 1 NEW_LINE DEDENT DEDENT DEDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE return a NEW_LINE DEDENT fidi = open ( ' B - large . in ' , ' r ' ) NEW_LINE fido = open ( ' a . out ' , ' w ' ) NEW_LINE T = fidi . readline ( ) NEW_LINE T = int ( T ) NEW_LINE for ii in range ( 1 , T + 1 ) : NEW_LINE INDENT R = fidi . readline ( ) NEW_LINE R = convertreals ( R ) NEW_LINE C = R [ 0 ] NEW_LINE F = R [ 1 ] NEW_LINE X = R [ 2 ] NEW_LINE a = findsol ( C , F , X ) NEW_LINE fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + str ( a ) + ' \\n ' ) NEW_LINE print ( ' Case ▁ # ' , str ( ii ) , ' : ▁ ' , str ( a ) ) NEW_LINE DEDENT fidi . close ( ) NEW_LINE fido . close ( ) NEW_LINE" ]
codejam_15_54
[ "package round3 ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class D { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int P = sc . nextInt ( ) ; long [ ] vals = new long [ P ] , freqs = new long [ P ] ; Map < Long , Integer > pos = new HashMap < Long , Integer > ( ) ; for ( int i = 0 ; i < vals . length ; i ++ ) { vals [ i ] = sc . nextLong ( ) ; pos . put ( vals [ i ] , i ) ; } long total = 0 ; for ( int i = 0 ; i < vals . length ; i ++ ) { freqs [ i ] = sc . nextLong ( ) ; total += freqs [ i ] ; } int cant = 0 ; long tmp = total ; while ( tmp > 1 ) { tmp /= 2 ; cant ++ ; } long [ ] ans = new long [ cant ] ; int sumIdx = 0 , setIdx = 0 ; for ( setIdx = 0 ; setIdx < cant ; setIdx ++ ) { for ( int m = 0 ; m < ( 1 << setIdx ) ; m ++ ) { if ( setIdx != 0 && ( m & ( 1 << ( setIdx - 1 ) ) ) == 0 ) continue ; long val = 0 ; for ( int i = 0 ; i < setIdx ; i ++ ) if ( ( m & ( 1 << i ) ) != 0 ) val += ans [ i ] ; freqs [ pos . get ( val ) ] -- ; } while ( freqs [ sumIdx ] == 0 ) { sumIdx ++ ; } ans [ setIdx ] = vals [ sumIdx ] ; } System . out . print ( \" Case ▁ # \" + caze + \" : \" ) ; for ( int i = 0 ; i < ans . length ; i ++ ) { System . out . print ( \" ▁ \" + ans [ i ] ) ; } System . out . println ( ) ; } } }", "import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; public class D { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numCases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; caseNum ++ ) { int P = sc . nextInt ( ) ; int [ ] E = new int [ P ] ; int [ ] F = new int [ P ] ; for ( int i = 0 ; i < P ; i ++ ) { E [ i ] = sc . nextInt ( ) ; } int total = 0 ; for ( int i = 0 ; i < P ; i ++ ) { F [ i ] = sc . nextInt ( ) ; total += F [ i ] ; } int numElems = ( int ) ( Math . log ( total ) / Math . log ( 2 ) + 0.5 ) ; List < Integer > S = new ArrayList < > ( ) ; Map < Integer , Integer > frequencies = new HashMap < > ( ) ; frequencies . put ( 0 , 1 ) ; for ( int i = 0 ; i < P ; i ++ ) { if ( ! frequencies . containsKey ( E [ i ] ) ) { frequencies . put ( E [ i ] , 0 ) ; } while ( frequencies . get ( E [ i ] ) < F [ i ] ) { S . add ( E [ i ] ) ; Map < Integer , Integer > temp = new HashMap < > ( frequencies ) ; for ( Map . Entry < Integer , Integer > entry : frequencies . entrySet ( ) ) { int sum = entry . getKey ( ) + E [ i ] ; if ( temp . containsKey ( sum ) ) { temp . put ( sum , entry . getValue ( ) + frequencies . get ( sum ) ) ; } else { temp . put ( sum , entry . getValue ( ) ) ; } } frequencies = temp ; } } System . out . print ( \" Case ▁ # \" + caseNum + \" : \" ) ; for ( int i : S ) { System . out . print ( \" ▁ \" + i ) ; } System . out . println ( ) ; } } }" ]
[ "import sys NEW_LINE def simplify ( ef , d ) : NEW_LINE INDENT ef2 = [ ] NEW_LINE for i in xrange ( len ( ef ) ) : NEW_LINE INDENT e = ef [ i ] [ 0 ] NEW_LINE f = ef [ i ] [ 1 ] NEW_LINE if f == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT ef2 . append ( ef [ i ] ) NEW_LINE for x in ef : NEW_LINE INDENT if x [ 0 ] != e + d : NEW_LINE INDENT continue NEW_LINE DEDENT x [ 1 ] -= f NEW_LINE DEDENT DEDENT return ef2 NEW_LINE DEDENT def compute ( N , E , F ) : NEW_LINE INDENT ef = sorted ( [ [ E [ i ] , F [ i ] ] for i in xrange ( len ( E ) ) ] ) NEW_LINE res = [ ] NEW_LINE a = ef [ - 1 ] [ 1 ] NEW_LINE while a > 1 : NEW_LINE INDENT res . append ( 0 ) NEW_LINE a /= 2 NEW_LINE DEDENT for i in xrange ( len ( ef ) ) : NEW_LINE INDENT ef [ i ] [ 1 ] /= ef [ - 1 ] [ 1 ] NEW_LINE DEDENT while len ( ef ) > 1 : NEW_LINE INDENT d = ef [ - 1 ] [ 0 ] - ef [ - 2 ] [ 0 ] NEW_LINE res . append ( d ) NEW_LINE ef = simplify ( ef , d ) NEW_LINE DEDENT return ' ▁ ' . join ( map ( str , sorted ( res ) ) ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT N = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE E = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE F = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE return N , E , F NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE result = compute ( * data ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT", "from collections import Counter NEW_LINE T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT P , = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE E = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE F = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE neg = min ( E ) NEW_LINE E = [ i - neg for i in E ] NEW_LINE c = Counter ( dict ( zip ( E , F ) ) ) NEW_LINE ans = [ ] NEW_LINE while c [ 0 ] > 1 : NEW_LINE INDENT ans . append ( 0 ) NEW_LINE d = Counter ( ) NEW_LINE for k in c : NEW_LINE INDENT d [ k ] = c [ k ] // 2 NEW_LINE DEDENT c = d NEW_LINE DEDENT del c [ 0 ] NEW_LINE while c : NEW_LINE INDENT e = min ( c ) NEW_LINE ans . append ( e ) NEW_LINE c [ e ] -= 1 NEW_LINE d = Counter ( ) NEW_LINE for k in sorted ( c . keys ( ) ) : NEW_LINE INDENT if c [ k ] > 0 : NEW_LINE INDENT d [ k ] = c [ k ] NEW_LINE assert k + e in c NEW_LINE c [ k + e ] -= c [ k ] NEW_LINE DEDENT DEDENT c = d NEW_LINE DEDENT while neg : NEW_LINE INDENT t = max ( i for i in ans if i <= - neg ) NEW_LINE del ans [ ans . index ( t ) ] NEW_LINE ans . append ( - t ) NEW_LINE neg += t NEW_LINE DEDENT ans . sort ( ) NEW_LINE ans = ' ▁ ' . join ( map ( str , ans ) ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } \" . format ( case , ans ) ) NEW_LINE DEDENT", "from collections import defaultdict NEW_LINE from math import log NEW_LINE def solve ( ) : NEW_LINE INDENT n = int ( raw_input ( ) ) NEW_LINE e = map ( int , raw_input ( ) . split ( ) ) NEW_LINE f = map ( int , raw_input ( ) . split ( ) ) NEW_LINE zeroes = int ( log ( f [ 0 ] , 2 ) ) NEW_LINE res = [ 0 ] * zeroes NEW_LINE sums = defaultdict ( int ) NEW_LINE for i in xrange ( 1 , n ) : NEW_LINE INDENT a = e [ i ] NEW_LINE freq = f [ i ] / ( 2 ** zeroes ) NEW_LINE for j in xrange ( freq - sums [ a ] ) : NEW_LINE INDENT res . append ( a ) NEW_LINE new_sums = defaultdict ( int ) NEW_LINE new_sums [ a ] = 1 NEW_LINE for k , v in sums . iteritems ( ) : NEW_LINE INDENT new_sums [ k ] += v NEW_LINE new_sums [ k + a ] += v NEW_LINE DEDENT sums = new_sums NEW_LINE DEDENT DEDENT return ' ▁ ' . join ( map ( str , res ) ) NEW_LINE DEDENT for i in xrange ( input ( ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , solve ( ) ) NEW_LINE DEDENT", "from itertools import * NEW_LINE from bisect import bisect NEW_LINE from math import log NEW_LINE import sys NEW_LINE facts = [ 1 ] NEW_LINE for i in xrange ( 1 , 100 ) : NEW_LINE INDENT facts . append ( facts [ - 1 ] * i ) NEW_LINE DEDENT def choose ( n , k ) : NEW_LINE INDENT return facts [ n ] / facts [ k ] / facts [ n - k ] NEW_LINE DEDENT lines = open ( \" c . in \" ) . read ( ) . split ( \" \\n \" ) NEW_LINE T = int ( lines [ 0 ] ) NEW_LINE def f ( P , E , F ) : NEW_LINE INDENT elements = [ [ int ( i ) , int ( j ) ] for i , j in izip ( E , F ) ] NEW_LINE total_elts = sum ( f for e , f in elements ) NEW_LINE accounted_for = [ ] NEW_LINE accounted_for_sums = { 0 : 1 } NEW_LINE unaccounted_for_elts = dict ( [ int ( i ) , int ( j ) ] for i , j in izip ( E , F ) ) NEW_LINE unaccounted_for_elts [ 0 ] -= 1 NEW_LINE while unaccounted_for_elts : NEW_LINE INDENT elt = min ( unaccounted_for_elts ) NEW_LINE freq = 1 NEW_LINE if unaccounted_for_elts [ elt ] == 0 : NEW_LINE INDENT del unaccounted_for_elts [ elt ] NEW_LINE continue NEW_LINE DEDENT new_d = dict ( accounted_for_sums . iteritems ( ) ) NEW_LINE for i in xrange ( freq ) : NEW_LINE INDENT accounted_for . append ( elt ) NEW_LINE new_e = ( i + 1 ) * elt NEW_LINE new_f = choose ( freq , i + 1 ) NEW_LINE for e , f in accounted_for_sums . iteritems ( ) : NEW_LINE INDENT total_e = new_e + e NEW_LINE total_f = new_f * f NEW_LINE new_d [ total_e ] = new_d . get ( total_e , 0 ) + total_f NEW_LINE unaccounted_for_elts [ total_e ] = unaccounted_for_elts . get ( total_e , 0 ) - total_f NEW_LINE DEDENT DEDENT accounted_for_sums = new_d NEW_LINE DEDENT return ' ▁ ' . join ( str ( s ) for s in sorted ( accounted_for ) ) NEW_LINE DEDENT curr_i = 1 NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT P = int ( lines [ curr_i ] ) NEW_LINE curr_i += 1 NEW_LINE out = f ( P , lines [ curr_i ] . split ( ' ▁ ' ) , lines [ curr_i + 1 ] . split ( ' ▁ ' ) ) NEW_LINE curr_i += 2 NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i , out ) NEW_LINE DEDENT", "import math , collections , itertools NEW_LINE import sys NEW_LINE NCASE = int ( sys . stdin . readline ( ) ) NEW_LINE for case in range ( 1 , NCASE + 1 ) : NEW_LINE INDENT P = map ( int , sys . stdin . readline ( ) . split ( ) ) [ 0 ] NEW_LINE E = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE F = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE count = dict ( ( e , f ) for ( e , f ) in zip ( E , F ) ) NEW_LINE ans = [ ] NEW_LINE if count [ 0 ] > 1 : NEW_LINE INDENT while count [ 0 ] > 1 : NEW_LINE INDENT ans . append ( 0 ) NEW_LINE count [ 0 ] /= 2 NEW_LINE DEDENT m = 1 << len ( ans ) NEW_LINE for k in count : NEW_LINE INDENT if k != 0 : NEW_LINE INDENT count [ k ] /= m NEW_LINE DEDENT DEDENT DEDENT keys = sorted ( count . keys ( ) ) NEW_LINE while len ( keys ) > 1 : NEW_LINE INDENT key = keys [ 1 ] NEW_LINE ans . append ( key ) NEW_LINE nc = { } NEW_LINE nkeys = [ ] NEW_LINE for k in reversed ( keys ) : NEW_LINE INDENT if count [ k ] > 0 : NEW_LINE INDENT count [ k - key ] -= count [ k ] NEW_LINE nc [ k - key ] = count [ k ] NEW_LINE DEDENT DEDENT count = nc NEW_LINE keys = sorted ( nc . keys ( ) ) NEW_LINE DEDENT ans = ' ▁ ' . join ( map ( str , sorted ( ans ) ) ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( case , ans ) NEW_LINE DEDENT" ]
codejam_10_23
[ "import java . io . * ; import java . math . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" Main . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" Main . out \" ) ) ; int tests = in . nextInt ( ) ; final int MOD = 100003 ; int [ ] [ ] f = new int [ 512 ] [ 512 ] ; for ( int m = 0 ; m < 512 ; m ++ ) f [ 0 ] [ m ] = 1 ; for ( int n = 1 ; n < 512 ; n ++ ) { for ( int m = 1 ; m <= n ; m ++ ) { f [ n ] [ m ] = 0 ; for ( int k = 1 ; k <= m ; k ++ ) { f [ n ] [ m ] = ( f [ n ] [ m ] + f [ n - k ] [ m ] ) % MOD ; } } } for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) System . out . print ( f [ i ] [ j ] + \" ▁ \" ) ; System . out . println ( ) ; } for ( int test = 1 ; test <= tests ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int n = in . nextInt ( ) ; int ans = 0 ; for ( int h = 2 ; h <= n ; h ++ ) ans = ( ans + f [ n - 1 ] [ h - 1 ] ) % MOD ; out . println ( ans ) ; } out . close ( ) ; } }", "import java . util . * ; import java . io . * ; public class x { static final int MOD = 100003 ; static final int MAXN = 500 ; public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; int [ ] [ ] C = new int [ MAXN + 1 ] [ MAXN + 1 ] ; for ( int i = 0 ; i <= MAXN ; i ++ ) { C [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j <= i ; j ++ ) { C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) % MOD ; } } int [ ] [ ] D = new int [ MAXN + 1 ] [ MAXN + 1 ] ; int [ ] A = new int [ MAXN + 1 ] ; D [ 1 ] [ 0 ] = 1 ; for ( int i = 2 ; i <= MAXN ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) { for ( int k = 0 ; k < j ; k ++ ) if ( j - k - 1 >= 0 && j - k - 1 <= i - j - 1 ) { long cur = D [ j ] [ k ] ; cur = ( D [ i ] [ j ] + cur * C [ i - j - 1 ] [ j - k - 1 ] ) % MOD ; D [ i ] [ j ] = ( int ) cur ; } A [ i ] = ( A [ i ] + D [ i ] [ j ] ) % MOD ; } } for ( int tt = 1 ; tt <= t ; tt ++ ) { int n = in . nextInt ( ) ; System . out . println ( \" Case ▁ # \" + tt + \" : ▁ \" + A [ n ] ) ; } ; } ; } ;", "import java . io . BufferedInputStream ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintStream ; import java . io . FileOutputStream ; public class Main { public static void main ( String [ ] args ) { try { File file = new File ( \" C - large . in \" ) ; FileInputStream fis = new FileInputStream ( file ) ; BufferedInputStream bis = new BufferedInputStream ( fis ) ; BufferedReader dis = new BufferedReader ( new InputStreamReader ( bis ) ) ; File ofile = new File ( \" C - large . out \" ) ; if ( ! ofile . exists ( ) ) { ofile . createNewFile ( ) ; } PrintStream out = new PrintStream ( new FileOutputStream ( ofile ) ) ; int [ ] [ ] f = new int [ 501 ] [ 501 ] ; for ( int i = 0 ; i < 501 ; i ++ ) { for ( int j = 0 ; j < 501 ; j ++ ) { if ( i == 0 ) { f [ i ] [ j ] = 1 ; } else { for ( int k = 1 ; k <= j ; k ++ ) { if ( k > i ) break ; f [ i ] [ j ] += f [ i - k ] [ j ] ; } f [ i ] [ j ] %= 100003 ; } } } int [ ] f2 = new int [ 501 ] ; for ( int i = 1 ; i < 501 ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { f2 [ i ] += f [ j ] [ i - j ] ; f2 [ i ] %= 100003 ; } } int T = Integer . parseInt ( dis . readLine ( ) ) ; int c = 0 ; while ( c ++ < T ) { out . print ( \" Case ▁ # \" + c + \" : ▁ \" ) ; out . println ( f2 [ Integer . parseInt ( dis . readLine ( ) ) - 1 ] ) ; } fis . close ( ) ; bis . close ( ) ; dis . close ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }", "import java . io . * ; import java . math . * ; import java . util . * ; public class C { public static void main ( String [ ] args ) { BigInteger [ ] [ ] combine = new BigInteger [ 512 ] [ 512 ] ; BigInteger [ ] [ ] a = new BigInteger [ 512 ] [ 512 ] ; BigInteger [ ] s = new BigInteger [ 512 ] ; for ( int i = 0 ; i < 512 ; i ++ ) { combine [ i ] [ 0 ] = BigInteger . ONE ; combine [ i ] [ i ] = BigInteger . ONE ; for ( int j = 1 ; j < i ; j ++ ) { combine [ i ] [ j ] = combine [ i - 1 ] [ j ] . add ( combine [ i - 1 ] [ j - 1 ] ) ; } for ( int j = 0 ; j < 512 ; j ++ ) a [ i ] [ j ] = BigInteger . ZERO ; s [ i ] = BigInteger . ZERO ; } for ( int n = 2 ; n < 512 ; n ++ ) { a [ n ] [ 1 ] = BigInteger . ONE ; for ( int m = 2 ; m < n ; m ++ ) { a [ n ] [ m ] = BigInteger . ZERO ; for ( int k = 1 ; k < m ; k ++ ) { int N = n - m - 1 ; int M = m - k - 1 ; if ( M >= 0 && M <= N ) { a [ n ] [ m ] = a [ n ] [ m ] . add ( combine [ N ] [ M ] . multiply ( a [ m ] [ k ] ) ) ; } } } for ( int m = 1 ; m < n ; m ++ ) { s [ n ] = s [ n ] . add ( a [ n ] [ m ] ) ; } } Scanner sc = new Scanner ( System . in ) ; int tests = sc . nextInt ( ) ; for ( int cas = 1 ; cas <= tests ; cas ++ ) { int n = sc . nextInt ( ) ; System . out . println ( \" Case ▁ # \" + cas + \" : ▁ \" + ( s [ n ] . mod ( BigInteger . valueOf ( 100003 ) ) ) ) ; } } }", "import java . io . * ; import java . util . * ; public class C implements Runnable { private String IFILE = \" C - large . in \" ; private Scanner in ; private PrintWriter out ; private int MOD = 100003 ; public void Run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int ntest = in . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int n = in . nextInt ( ) ; long [ ] [ ] c = new long [ n + 1 ] [ n + 1 ] ; c [ 0 ] [ 0 ] = 1 ; for ( int j = 1 ; j <= n ; j ++ ) { c [ 0 ] [ j ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) c [ i ] [ j ] = ( c [ i - 1 ] [ j - 1 ] + c [ i ] [ j - 1 ] ) % MOD ; } long [ ] [ ] mas = new long [ n + 1 ] [ n + 1 ] ; for ( int j = 2 ; j <= n ; j ++ ) mas [ 1 ] [ j ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) for ( int j = i + 1 ; j <= n ; j ++ ) { for ( int k = 1 ; k < i ; k ++ ) { mas [ i ] [ j ] = ( mas [ i ] [ j ] + mas [ k ] [ i ] * c [ j - i - 1 ] [ i - k - 1 ] ) % MOD ; } } long result = 0 ; for ( int i = 1 ; i <= n ; i ++ ) result = ( result + mas [ i ] [ n ] ) % MOD ; out . println ( result ) ; } in . close ( ) ; out . close ( ) ; } public void run ( ) { try { Run ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) throws IOException { new C ( ) . Run ( ) ; } }" ]
[ "from sys import stdin , stdout NEW_LINE nCk = [ [ int ( ) ] * 501 for i in range ( 501 ) ] NEW_LINE for n in range ( 0 , 501 ) : NEW_LINE INDENT nCk [ n ] [ 0 ] = 1 NEW_LINE for k in range ( 1 , n + 1 ) : NEW_LINE INDENT nCk [ n ] [ k ] = nCk [ n ] [ k - 1 ] * ( n + 1 - k ) / k NEW_LINE DEDENT DEDENT for n in range ( 0 , 501 ) : NEW_LINE INDENT for k in range ( 1 , n + 1 ) : NEW_LINE INDENT nCk [ n ] [ k ] %= 100003 NEW_LINE DEDENT DEDENT Y = [ [ int ( ) ] * 501 for i in range ( 501 ) ] NEW_LINE y = [ int ( ) ] * 501 NEW_LINE for i in range ( 2 , 501 ) : NEW_LINE INDENT Y [ i ] [ 1 ] = 1 NEW_LINE y [ i ] = 1 NEW_LINE for j in range ( 2 , i ) : NEW_LINE INDENT for k in range ( 1 , j ) : NEW_LINE INDENT Y [ i ] [ j ] += Y [ j ] [ k ] * nCk [ i - j - 1 ] [ j - k - 1 ] NEW_LINE DEDENT y [ i ] += Y [ i ] [ j ] NEW_LINE DEDENT y [ i ] %= 100003 NEW_LINE DEDENT for x in range ( 1 , int ( stdin . readline ( ) ) + 1 ) : NEW_LINE INDENT n = int ( stdin . readline ( ) ) NEW_LINE stdout . write ( ' Case ▁ # % i : ▁ % i \\n ' % ( x , y [ n ] ) ) NEW_LINE DEDENT", "import pickle NEW_LINE import os NEW_LINE modulo = 100003 NEW_LINE combtable = { } NEW_LINE for i in xrange ( 0 , 1000 ) : NEW_LINE INDENT for j in xrange ( 0 , i + 1 ) : NEW_LINE INDENT if j == 0 or i == j : NEW_LINE INDENT combtable [ ( i , j ) ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT combtable [ ( i , j ) ] = ( combtable [ ( i - 1 , j - 1 ) ] + combtable [ ( i - 1 , j ) ] ) % modulo NEW_LINE DEDENT DEDENT DEDENT D = { } NEW_LINE if os . path . exists ( ' cached ' ) : NEW_LINE INDENT D = pickle . loads ( file ( ' cached ' , ' rb ' ) . read ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT for n in xrange ( 2 , 501 ) : NEW_LINE INDENT for l in xrange ( 1 , n ) : NEW_LINE INDENT if l == 1 : NEW_LINE INDENT D [ ( n , l ) ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT result = 0 NEW_LINE for m in xrange ( 1 , l ) : NEW_LINE INDENT bucket = ( n - 1 ) - ( l + 1 ) + 1 NEW_LINE pick = ( l - 1 ) - ( m + 1 ) + 1 NEW_LINE if bucket >= pick : NEW_LINE INDENT result += D [ ( l , m ) ] * combtable [ ( n - l - 1 , l - m - 1 ) ] NEW_LINE DEDENT DEDENT D [ ( n , l ) ] = result % modulo NEW_LINE DEDENT DEDENT DEDENT file ( ' cached ' , ' wb ' ) . write ( pickle . dumps ( D ) ) NEW_LINE DEDENT c = raw_input ( ) NEW_LINE for cs in xrange ( 1 , int ( c ) + 1 ) : NEW_LINE INDENT n = int ( raw_input ( ) ) NEW_LINE result = 0 NEW_LINE for l in xrange ( 1 , n ) : NEW_LINE INDENT result += D [ ( n , l ) ] NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( cs , result % modulo ) NEW_LINE DEDENT", "import fileinput NEW_LINE memo = { } NEW_LINE def f ( n , m ) : NEW_LINE INDENT if n < 0 : return 0 NEW_LINE if n == 0 : return 1 NEW_LINE if n in memo and m in memo [ n ] : return memo [ n ] [ m ] NEW_LINE s = 0 NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT s += f ( n - i , m ) NEW_LINE DEDENT if n not in memo : memo [ n ] = { } NEW_LINE memo [ n ] [ m ] = s NEW_LINE return s NEW_LINE DEDENT def a079500 ( n ) : NEW_LINE INDENT s = 0 NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT s += f ( i , n - i ) NEW_LINE DEDENT return s NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT reader = fileinput . input ( ) NEW_LINE trials = int ( reader . next ( ) ) NEW_LINE for t in range ( 1 , trials + 1 ) : NEW_LINE INDENT result = trial ( reader ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( t , result ) NEW_LINE DEDENT DEDENT def trial ( reader ) : NEW_LINE INDENT n = int ( reader . next ( ) ) NEW_LINE return a079500 ( n - 1 ) % 100003 NEW_LINE DEDENT main ( ) NEW_LINE", "import sys NEW_LINE def line ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) [ : - 1 ] NEW_LINE DEDENT def readList ( ) : NEW_LINE INDENT return map ( eval , line ( ) . split ( ) ) NEW_LINE DEDENT modulo = 100003 NEW_LINE chooses = dict ( ) NEW_LINE def choose ( n , m ) : NEW_LINE INDENT if ( n , m ) not in chooses : NEW_LINE INDENT if ( n < m ) : NEW_LINE INDENT chooses [ ( n , m ) ] = 0 NEW_LINE DEDENT else : NEW_LINE INDENT chooses [ ( n , m ) ] = ( factorial ( n ) / ( factorial ( n - m ) * factorial ( m ) ) ) % modulo NEW_LINE DEDENT DEDENT return chooses [ ( n , m ) ] NEW_LINE DEDENT factorials = dict ( ) NEW_LINE factorials [ 1 ] = 1 NEW_LINE factorials [ 0 ] = 1 NEW_LINE def factorial ( n ) : NEW_LINE INDENT if n not in factorials : NEW_LINE INDENT i = n NEW_LINE factorials [ n ] = 1 NEW_LINE while i >= 2 : NEW_LINE INDENT factorials [ n ] *= i NEW_LINE i -= 1 NEW_LINE DEDENT DEDENT return factorials [ n ] NEW_LINE DEDENT def buildTable ( N ) : NEW_LINE INDENT table = dict ( ) NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT table [ ( n , 1 ) ] = 1 NEW_LINE for pos in range ( 2 , n ) : NEW_LINE INDENT table [ ( n , pos ) ] = sum ( [ table [ ( pos , i ) ] * choose ( n - pos - 1 , pos - i - 1 ) % modulo for i in range ( 1 , pos ) ] ) % modulo NEW_LINE DEDENT DEDENT return table NEW_LINE DEDENT def ways ( n , table ) : NEW_LINE INDENT return sum ( [ table [ n , pos ] for pos in range ( 1 , n ) ] ) % modulo NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT numberOfCases = eval ( line ( ) ) NEW_LINE table = buildTable ( 500 ) NEW_LINE for caseNumber in range ( numberOfCases ) : NEW_LINE INDENT n = eval ( line ( ) ) NEW_LINE answer = ways ( n , table ) NEW_LINE print \" Case ▁ # \" + str ( caseNumber + 1 ) + \" : ▁ \" + str ( answer % 100003 ) NEW_LINE DEDENT DEDENT", "def doit ( i , j ) : NEW_LINE INDENT if i == 0 or j == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if j == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if j >= i : NEW_LINE INDENT return 0 NEW_LINE DEDENT aux = 0 NEW_LINE for x in xrange ( 1 , j ) : NEW_LINE INDENT aux += A [ j ] [ x ] * C [ i - j - 1 ] [ j - x - 1 ] NEW_LINE aux %= MOD NEW_LINE DEDENT return aux NEW_LINE DEDENT def comb ( i , j ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT if j > i : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) % MOD NEW_LINE DEDENT f = open ( ' c . in ' , ' r ' ) NEW_LINE MOD = 100003 NEW_LINE nmax = 512 NEW_LINE A = [ [ 0 ] * nmax for i in range ( nmax ) ] NEW_LINE C = [ [ 0 ] * nmax for i in range ( nmax ) ] NEW_LINE for i in range ( 0 , nmax ) : NEW_LINE INDENT for j in range ( 0 , nmax ) : NEW_LINE INDENT C [ i ] [ j ] = comb ( i , j ) NEW_LINE A [ i ] [ j ] = doit ( i , j ) NEW_LINE DEDENT DEDENT T = int ( f . readline ( ) ) NEW_LINE for t_no in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( f . readline ( ) ) NEW_LINE sol = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT sol += A [ N ] [ i ] NEW_LINE sol %= MOD NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( t_no , sol ) NEW_LINE DEDENT" ]
codejam_09_01
[ "package gcj2009 . qual ; import java . io . * ; import java . util . * ; import static java . lang . Math . * ; public class A { static final int INF = 1 << 20 ; static char [ ] [ ] css ; public void run ( ) { char [ ] key = sc . next ( ) . toCharArray ( ) ; boolean [ ] [ ] b = new boolean [ L ] [ 127 ] ; for ( int i = 0 , j = 0 ; i < key . length ; i ++ , j ++ ) if ( key [ i ] == ' ( ' ) while ( key [ ++ i ] != ' ) ' ) b [ j ] [ key [ i ] ] = true ; else b [ j ] [ key [ i ] ] = true ; int ans = 0 ; loop : for ( char [ ] cs : css ) { for ( int i = 0 ; i < L ; i ++ ) if ( ! b [ i ] [ cs [ i ] ] ) continue loop ; ans ++ ; } System . out . println ( ans ) ; } public static void main ( String ... args ) { try { System . setIn ( new FileInputStream ( \" A - large . in \" ) ) ; System . setOut ( new PrintStream ( \" A - large . out \" ) ) ; } catch ( Exception e ) { } sc = new Scanner ( System . in ) ; L = sc . nextInt ( ) ; D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; css = new char [ D ] [ ] ; for ( int i = 0 ; i < D ; i ++ ) css [ i ] = sc . next ( ) . toCharArray ( ) ; for ( int n = 1 ; n <= N ; n ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ \" , n ) ; new A ( ) . run ( ) ; } } static int L , D ; static Scanner sc ; }", "package de . measite . gcj ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . LineNumberReader ; import java . util . regex . Pattern ; public class Main1 { public static void main ( String [ ] args ) { try { LineNumberReader lnr = new LineNumberReader ( new InputStreamReader ( System . in ) ) ; String line [ ] = lnr . readLine ( ) . trim ( ) . split ( \" ▁ \" ) ; final int d = Integer . parseInt ( line [ 1 ] ) ; final int n = Integer . parseInt ( line [ 2 ] ) ; String word [ ] = new String [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { word [ i ] = lnr . readLine ( ) . trim ( ) ; } for ( int i = 1 ; i <= n ; i ++ ) { String m = lnr . readLine ( ) . trim ( ) . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) ; Pattern pattern = Pattern . compile ( m ) ; int count = 0 ; for ( String w : word ) { if ( pattern . matcher ( w ) . matches ( ) ) { count ++ ; } } System . out . println ( \" Case ▁ # \" + i + \" : ▁ \" + count ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } }", "import java . io . * ; import java . util . * ; public class Solution { public static BufferedReader cin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static StringTokenizer tok = null ; public static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( cin . readLine ( ) ) ; } return tok . nextToken ( ) ; } public static int nextInt ( ) throws NumberFormatException , IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws NumberFormatException , IOException { int L = nextInt ( ) ; int D = nextInt ( ) ; int N = nextInt ( ) ; String [ ] dict = new String [ D ] ; for ( int i = 0 ; i < D ; i ++ ) dict [ i ] = cin . readLine ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String pat = cin . readLine ( ) ; TreeSet [ ] st = new TreeSet [ L ] ; for ( int j = 0 ; j < L ; j ++ ) { st [ j ] = new TreeSet ( ) ; } int k = 0 ; for ( int j = 0 ; j < pat . length ( ) ; j ++ ) { if ( pat . charAt ( j ) != ' ( ' ) { st [ k ] . add ( Character . valueOf ( pat . charAt ( j ) ) ) ; k ++ ; } else { j ++ ; while ( pat . charAt ( j ) != ' ) ' ) { st [ k ] . add ( Character . valueOf ( pat . charAt ( j ) ) ) ; j ++ ; } k ++ ; } } int ans = 0 ; for ( int j = 0 ; j < D ; j ++ ) { boolean ok = true ; for ( int t = 0 ; t < L ; t ++ ) { if ( ! st [ t ] . contains ( Character . valueOf ( dict [ j ] . charAt ( t ) ) ) ) { ok = false ; break ; } } if ( ok ) ans ++ ; } System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + ans ) ; } } }", "import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader buffer = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String entrada = buffer . readLine ( ) ; String ns [ ] = entrada . split ( \" ▁ \" ) ; int l = Integer . parseInt ( ns [ 0 ] ) ; int d = Integer . parseInt ( ns [ 1 ] ) ; int n = Integer . parseInt ( ns [ 2 ] ) ; String palavras [ ] = new String [ d + 1 ] ; for ( int i = 0 ; i < d ; i ++ ) { palavras [ i ] = buffer . readLine ( ) ; } for ( int k = 1 ; k <= n ; k ++ ) { List < Set < Character > > conjuntosAceitaveis = new ArrayList < Set < Character > > ( ) ; for ( int i = 0 ; i < l ; i ++ ) { conjuntosAceitaveis . add ( new HashSet < Character > ( ) ) ; } String expressao = buffer . readLine ( ) ; int pt = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( expressao . charAt ( pt ) == ' ( ' ) { for ( pt ++ ; expressao . charAt ( pt ) != ' ) ' ; pt ++ ) { conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ; } pt ++ ; } else { conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ; pt ++ ; } } int cont = 0 ; for ( int i = 0 ; i < d ; i ++ ) { boolean pode = true ; for ( int j = 0 ; j < l ; j ++ ) { if ( ! conjuntosAceitaveis . get ( j ) . contains ( palavras [ i ] . charAt ( j ) ) ) { pode = false ; break ; } } if ( pode ) cont ++ ; } System . out . println ( \" Case ▁ # \" + k + \" : ▁ \" + cont ) ; } } }", "package gcj2009 . qualification ; import java . io . File ; import java . io . PrintWriter ; import java . text . SimpleDateFormat ; import java . util . Date ; import java . util . Scanner ; import java . util . regex . Pattern ; public class A_Alien_Language { private static boolean SMALL = false ; private static String PROBLEM = \" A \" ; public static void main ( String [ ] args ) { try { Scanner scan = new Scanner ( new File ( String . format ( \" % s - % s . in \" , PROBLEM , ( SMALL ? \" small \" : \" large \" ) ) ) ) ; PrintWriter pw = new PrintWriter ( new File ( String . format ( \" % s - % s . out \" , PROBLEM , ( SMALL ? \" small \" : \" large \" ) ) ) ) ; int L = scan . nextInt ( ) , D = scan . nextInt ( ) , N = scan . nextInt ( ) ; scan . nextLine ( ) ; String [ ] dictionary = new String [ D ] ; for ( int i = 0 ; i < D ; ++ i ) dictionary [ i ] = scan . nextLine ( ) ; System . out . println ( String . format ( \" % d ▁ test ▁ cases : \" , N ) ) ; long start = System . currentTimeMillis ( ) , t1 , left ; for ( int CASE = 1 ; CASE <= N ; ++ CASE ) { t1 = System . currentTimeMillis ( ) ; System . out . print ( String . format ( \" % d . [ % s ] ▁ \" , CASE , new SimpleDateFormat ( \" HH : mm : ss . SSS \" ) . format ( new Date ( t1 ) ) ) ) ; String pattern = scan . nextLine ( ) ; pattern = pattern . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) ; Pattern p = Pattern . compile ( pattern ) ; int cnt = 0 ; for ( int i = 0 ; i < D ; ++ i ) if ( p . matcher ( dictionary [ i ] ) . matches ( ) ) cnt ++ ; String res = String . valueOf ( cnt ) ; pw . println ( String . format ( \" Case ▁ # % d : ▁ % s \" , CASE , res ) ) ; left = ( System . currentTimeMillis ( ) - start ) * ( N - CASE ) / CASE ; System . out . println ( String . format ( \" % s ▁ ( % dms , ▁ ~ % dms ▁ left ) \" , res , ( System . currentTimeMillis ( ) - t1 ) , left ) ) ; } pw . close ( ) ; scan . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }" ]
[ "import re NEW_LINE import sys NEW_LINE r = re . compile ( r ' ( \\ ( [ a - z ] * \\ ) | [ a - z ] ) ' ) NEW_LINE def main ( ) : NEW_LINE INDENT [ l , d , n ] = [ int ( x ) for x in raw_input ( ) . strip ( ) . split ( ) ] NEW_LINE words = [ ] NEW_LINE for _ in range ( d ) : NEW_LINE INDENT words . append ( raw_input ( ) . strip ( ) ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT q = raw_input ( ) . strip ( ) NEW_LINE q = [ c for c in r . split ( q ) if c ] NEW_LINE w = words NEW_LINE for qq in q : NEW_LINE INDENT w = [ x [ 1 : ] for x in w if x [ 0 ] in qq ] NEW_LINE DEDENT sys . stdout . write ( \" Case ▁ # % d : ▁ % d \\n \" % ( i + 1 , len ( w ) ) ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "from __future__ import division NEW_LINE import sys NEW_LINE import itertools NEW_LINE def parse_pattern ( pattern ) : NEW_LINE INDENT res = [ ] NEW_LINE while pattern : NEW_LINE INDENT if pattern [ 0 ] == ' ( ' : NEW_LINE INDENT i = pattern . find ( ' ) ' ) NEW_LINE res . append ( set ( pattern [ 1 : i ] ) ) NEW_LINE pattern = pattern [ i + 1 : ] NEW_LINE DEDENT else : NEW_LINE INDENT res . append ( set ( pattern [ 0 ] ) ) NEW_LINE pattern = pattern [ 1 : ] NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def matches_pattern ( pattern , word ) : NEW_LINE INDENT for p , w in itertools . izip ( pattern , word ) : NEW_LINE INDENT if w not in p : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def solve ( pattern , words ) : NEW_LINE INDENT p = parse_pattern ( pattern ) NEW_LINE res = 0 NEW_LINE for w in words : NEW_LINE INDENT if matches_pattern ( p , w ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def go ( ) : NEW_LINE INDENT l , d , n = [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE words = [ ] NEW_LINE for i in xrange ( d ) : NEW_LINE INDENT word = sys . stdin . readline ( ) . strip ( ) NEW_LINE words . append ( word ) NEW_LINE DEDENT for i in xrange ( n ) : NEW_LINE INDENT pattern = sys . stdin . readline ( ) . strip ( ) NEW_LINE print ' Case ▁ # % d : ▁ % d ' % ( i + 1 , solve ( pattern , words ) ) NEW_LINE DEDENT DEDENT go ( ) NEW_LINE", "from StringIO import StringIO NEW_LINE import re NEW_LINE def process ( f , out = None ) : NEW_LINE INDENT if isinstance ( f , str ) : NEW_LINE INDENT if not out : NEW_LINE INDENT out = open ( f + ' . out . txt ' , ' wb ' ) NEW_LINE DEDENT f = open ( f , ' rb ' ) NEW_LINE DEDENT else : NEW_LINE INDENT if not out : NEW_LINE INDENT out = StringIO ( ) NEW_LINE DEDENT DEDENT l , d , n = map ( int , f . readline ( ) . strip ( ) . split ( ) ) NEW_LINE words = [ ] NEW_LINE for i in range ( d ) : NEW_LINE INDENT words . append ( f . readline ( ) . strip ( ) ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT pattern = f . readline ( ) . strip ( ) NEW_LINE pattern = pattern . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) NEW_LINE expr = re . compile ( ' ^ ' + pattern + ' $ ' ) NEW_LINE count = len ( filter ( lambda x : expr . match ( x ) , words ) ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( i + 1 , count ) ) NEW_LINE DEDENT if isinstance ( out , StringIO ) : NEW_LINE INDENT return out . getvalue ( ) NEW_LINE DEDENT DEDENT TEST_DATA = ( \"\"\" 3 ▁ 5 ▁ 4 STRNEWLINE abc STRNEWLINE bca STRNEWLINE dac STRNEWLINE dbc STRNEWLINE cba STRNEWLINE ( ab ) ( bc ) ( ca ) STRNEWLINE abc STRNEWLINE ( abc ) ( abc ) ( abc ) STRNEWLINE ( zyx ) bc \"\"\" , \"\"\" Case ▁ # 1 : ▁ 2 STRNEWLINE Case ▁ # 2 : ▁ 1 STRNEWLINE Case ▁ # 3 : ▁ 3 STRNEWLINE Case ▁ # 4 : ▁ 0 STRNEWLINE \"\"\" ) NEW_LINE def go ( ) : NEW_LINE INDENT assert process ( StringIO ( TEST_DATA [ 0 ] ) ) == TEST_DATA [ 1 ] NEW_LINE for x in [ ' A - large . in . txt ' ] : NEW_LINE INDENT process ( x ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT go ( ) NEW_LINE DEDENT", "import sys , string NEW_LINE from subprocess import Popen , PIPE NEW_LINE input = sys . stdin . readlines ( ) NEW_LINE specs = [ int ( num ) for num in input [ 0 ] . split ( ) ] NEW_LINE L = specs [ 0 ] NEW_LINE D = specs [ 1 ] NEW_LINE N = specs [ 2 ] NEW_LINE words = input [ 1 : 1 + D ] NEW_LINE table = string . maketrans ( ' ( ) ' , ' [ ] ' ) NEW_LINE case = 1 NEW_LINE for exp in input [ 1 + D : ] : NEW_LINE INDENT exp = ' ^ ' + exp . strip ( ) . translate ( table ) + ' $ ' NEW_LINE cmd = \" grep ▁ ' % s ' \" % exp NEW_LINE p = Popen ( cmd , shell = True , bufsize = 4096 , stdin = PIPE , stdout = PIPE , close_fds = True ) NEW_LINE ( child_stdin , child_stdout ) = ( p . stdin , p . stdout ) NEW_LINE for word in words : NEW_LINE INDENT print >> child_stdin , word NEW_LINE DEDENT child_stdin . close ( ) NEW_LINE count = 0 NEW_LINE for line in child_stdout : NEW_LINE INDENT count += 1 NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , count ) NEW_LINE child_stdout . close ( ) NEW_LINE case += 1 NEW_LINE DEDENT", "import os , sys NEW_LINE def processCase ( caseStr , letterData , wordlength ) : NEW_LINE INDENT casePos = 0 NEW_LINE allowedWords = set ( ) NEW_LINE for letterPos in range ( wordlength ) : NEW_LINE INDENT allowedLetters = [ ] NEW_LINE if caseStr [ casePos ] == ' ( ' : NEW_LINE INDENT casePos += 1 NEW_LINE while ( caseStr [ casePos ] != ' ) ' ) : NEW_LINE INDENT allowedLetters . append ( caseStr [ casePos ] ) NEW_LINE casePos += 1 NEW_LINE DEDENT casePos += 1 NEW_LINE DEDENT else : NEW_LINE INDENT allowedLetters . append ( caseStr [ casePos ] ) NEW_LINE casePos += 1 NEW_LINE DEDENT tempWords = set ( ) NEW_LINE for l in allowedLetters : NEW_LINE INDENT if l in letterData [ letterPos ] : NEW_LINE INDENT tempWords . update ( letterData [ letterPos ] [ l ] ) NEW_LINE DEDENT DEDENT if letterPos == 0 : NEW_LINE INDENT allowedWords = tempWords NEW_LINE DEDENT else : NEW_LINE INDENT allowedWords . intersection_update ( tempWords ) NEW_LINE DEDENT DEDENT return len ( allowedWords ) NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE words = [ ] NEW_LINE [ wordlength , numdict , numcases ] = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE letterPosToWords = [ { } for x in range ( wordlength ) ] NEW_LINE index += 1 NEW_LINE for i in range ( numdict ) : NEW_LINE INDENT word = fileLines [ index ] [ : - 1 ] NEW_LINE index += 1 NEW_LINE for j in range ( wordlength ) : NEW_LINE INDENT c = word [ j ] NEW_LINE if ( not ( c in letterPosToWords [ j ] ) ) : NEW_LINE INDENT letterPosToWords [ j ] [ c ] = set ( ) NEW_LINE DEDENT letterPosToWords [ j ] [ c ] . add ( word ) NEW_LINE DEDENT words . append ( word ) NEW_LINE DEDENT for i in range ( numcases ) : NEW_LINE INDENT case = fileLines [ index ] [ : - 1 ] NEW_LINE index += 1 NEW_LINE numWords = processCase ( case , letterPosToWords , wordlength ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , numWords ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT" ]
codejam_08_33
[ "import java . io . * ; import java . util . * ; import java . math . * ; public class Problem3 { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( \" Problem3 . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( \" Problem3 . out \" ) ) ) ; int c = in . nextInt ( ) ; for ( int cn = 0 ; cn < c ; cn ++ ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; long x = in . nextInt ( ) ; long y = in . nextInt ( ) ; long z = in . nextInt ( ) ; long sub [ ] = new long [ n ] ; BigInteger ans [ ] = new BigInteger [ n ] ; long array [ ] = new long [ m ] ; for ( int i = 0 ; i < m ; i ++ ) array [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sub [ i ] = array [ i % m ] ; array [ i % m ] = ( x * array [ i % m ] + y * ( i + 1 ) ) % z ; } Arrays . fill ( ans , BigInteger . ONE ) ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) { if ( sub [ j ] < sub [ i ] ) ans [ i ] = ans [ i ] . add ( ans [ j ] ) ; } BigInteger sum = BigInteger . ZERO ; for ( int i = 0 ; i < n ; i ++ ) sum = sum . add ( ans [ i ] ) ; sum = sum . remainder ( new BigInteger ( \"1000000007\" ) ) ; out . write ( \" Case ▁ # \" + ( cn + 1 ) + \" : ▁ \" + sum . toString ( ) + \" \\n \" ) ; } in . close ( ) ; out . close ( ) ; } }", "package Andra ; import java . util . * ; public class CumulativeTable { public static final long MOD = 1000000007 ; private long [ ] sum ; private int [ ] degreeTwo ; private int n ; public CumulativeTable ( int n ) { this . n = n ; this . sum = new long [ n + 1 ] ; this . degreeTwo = new int [ n + 1 ] ; calculateDegrees ( ) ; } private void calculateDegrees ( ) { degreeTwo [ 0 ] = 1 ; degreeTwo [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { if ( ( i & 1 ) == 0 ) degreeTwo [ i ] = degreeTwo [ i >> 1 ] * 2 ; else degreeTwo [ i ] = 1 ; } } public void reset ( ) { for ( int i = 0 ; i < n ; i ++ ) sum [ i ] = 0 ; } public void add ( int index , long value ) { int i = index ; while ( i <= n ) { sum [ i ] = ( sum [ i ] + value ) % MOD ; i = i + degreeTwo [ i ] ; } } public long count ( int index ) { int i = index ; long toReturn = 0 ; while ( i >= 0 ) { toReturn = ( toReturn + sum [ i ] ) % MOD ; i = i - degreeTwo [ i ] ; } return toReturn ; } public static void main ( String [ ] args ) { Random rnd = new Random ( ) ; int n = 100 ; int [ ] a = new int [ n ] ; CumulativeTable ct = new CumulativeTable ( n ) ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { int index = rnd . nextInt ( n ) ; int value = rnd . nextInt ( 1000 ) ; a [ index ] = a [ index ] + value ; ct . add ( index , value ) ; int sum = 0 ; for ( int j = 0 ; j <= index ; j ++ ) sum += a [ j ] ; System . out . println ( sum ) ; System . out . println ( ct . count ( index ) ) ; } } }", "package codejam2c ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( \" c - small . in \" ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( \" c - small - out . out \" ) ) ; final long M = 1000000007 ; int T = in . nextInt ( ) ; for ( int x = 1 ; x <= T ; x ++ ) { int n = in . nextInt ( ) , m = in . nextInt ( ) , X = in . nextInt ( ) , Y = in . nextInt ( ) , Z = in . nextInt ( ) ; int i , j ; int [ ] a = new int [ n ] , A = new int [ m ] ; long [ ] nr = new long [ n ] ; long S = 0 ; for ( i = 0 ; i < m ; i ++ ) { A [ i ] = in . nextInt ( ) ; } for ( i = 0 ; i < n ; i ++ ) { a [ i ] = A [ i % m ] ; A [ i % m ] = ( int ) ( ( ( long ) ( ( long ) X * A [ i % m ] + ( long ) Y * ( i + 1 ) ) ) % ( long ) Z ) ; } nr [ 0 ] = 1 ; S = 1 ; for ( i = 1 ; i < n ; i ++ ) { nr [ i ] = 1 ; for ( j = 0 ; j < i ; j ++ ) if ( a [ j ] < a [ i ] ) { nr [ i ] += nr [ j ] ; nr [ i ] %= M ; } S += nr [ i ] ; S %= M ; } out . printf ( \" Case ▁ # % d : ▁ % d % n \" , x , S ) ; } in . close ( ) ; out . close ( ) ; } }", "import java . util . Scanner ; public class ProblemC { public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final int cases = sc . nextInt ( ) ; for ( int cc = 1 ; cc <= cases ; cc ++ ) { final int n = sc . nextInt ( ) ; final int m = sc . nextInt ( ) ; final long x = sc . nextLong ( ) , y = sc . nextLong ( ) , z = sc . nextLong ( ) ; final int [ ] h = new int [ n ] ; final int [ ] a = new int [ n ] ; for ( int i = 0 ; i < m ; i ++ ) h [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = h [ i % m ] ; h [ i % m ] = ( int ) ( ( x * h [ i % m ] + y * ( i + 1 ) ) % z ) ; } final int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = 1 ; for ( int j = 0 ; j < i ; j ++ ) if ( a [ j ] < a [ i ] ) s [ i ] = ( s [ i ] + s [ j ] ) % 1000000007 ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) count = ( count + s [ i ] ) % 1000000007 ; System . out . printf ( \" Case ▁ # % s : ▁ % s \\n \" , cc , count ) ; } System . out . flush ( ) ; } }", "import java . io . * ; import java . util . * ; public class Main { Scanner in ; PrintWriter out ; String IFILE = \" c - small - attempt0 . in \" ; String OFILE = \" c - small - attempt0 . out \" ; final long MOD = 1000000007 ; public void run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( OFILE ) ; int nt = in . nextInt ( ) ; for ( int it = 0 ; it < nt ; it ++ ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; long x = in . nextInt ( ) ; long y = in . nextInt ( ) ; long z = in . nextInt ( ) ; long [ ] a = new long [ m ] ; for ( int i = 0 ; i < m ; i ++ ) a [ i ] = in . nextLong ( ) ; long [ ] mas = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { mas [ i ] = a [ i % m ] ; a [ i % m ] = ( x * a [ i % m ] + y * ( i + 1 ) ) % z ; } long [ ] f = new long [ n ] ; Arrays . fill ( f , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( mas [ j ] < mas [ i ] ) f [ i ] = ( f [ i ] + f [ j ] ) % MOD ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans = ( ans + f [ i ] ) % MOD ; out . println ( \" Case ▁ # \" + ( it + 1 ) + \" : ▁ \" + ans ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } }" ]
[ "import sys NEW_LINE def genseq ( n , m , X , Y , Z , A ) : NEW_LINE INDENT s = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT s . append ( A [ i % m ] ) NEW_LINE A [ i % m ] = ( X * A [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT return s NEW_LINE DEDENT def go_seq ( seq ) : NEW_LINE INDENT s = [ 0 for x in range ( len ( seq ) ) ] NEW_LINE for i in range ( len ( seq ) ) : NEW_LINE INDENT s [ i ] = 1 NEW_LINE for j in range ( i ) : NEW_LINE INDENT if seq [ i ] > seq [ j ] : NEW_LINE INDENT s [ i ] += s [ j ] NEW_LINE DEDENT DEDENT DEDENT return sum ( s ) NEW_LINE DEDENT def go ( name ) : NEW_LINE INDENT f = file ( name ) NEW_LINE line = f . readline ( ) . strip ( ) NEW_LINE total = int ( line ) NEW_LINE for i in range ( total ) : NEW_LINE INDENT n , m , X , Y , Z = [ int ( x ) for x in f . readline ( ) . strip ( ) . split ( ) ] NEW_LINE A = [ ] NEW_LINE for j in range ( m ) : NEW_LINE INDENT A . append ( int ( f . readline ( ) . strip ( ) ) ) NEW_LINE DEDENT seq = genseq ( n , m , X , Y , Z , A ) NEW_LINE r = go_seq ( seq ) % 1000000007 NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , r ) NEW_LINE DEDENT f . close ( ) NEW_LINE DEDENT try : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE DEDENT except : NEW_LINE INDENT print \" Usage : \\n \" , \" python \" , sys . argv [ 0 ] + \" ▁ input _ file _ name \" NEW_LINE sys . exit ( 1 ) NEW_LINE DEDENT go ( fn ) NEW_LINE", "import os NEW_LINE import sys NEW_LINE sys . stdin = open ( ' C - small - attempt0 . in ' , ' r ' ) NEW_LINE sys . stdout = open ( ' C - small - attempt0 . out ' , ' w ' ) NEW_LINE DEBUG = 1 or os . getenv ( \" DEBUG \" ) == '1' NEW_LINE if DEBUG : NEW_LINE INDENT sys . stderr = open ( ' log ' , ' w ' ) NEW_LINE DEDENT def debug ( * what ) : NEW_LINE INDENT if DEBUG : NEW_LINE INDENT sys . stderr . write ( \" [ DEBUG ] ▁ \" + \" ▁ \" . join ( map ( str , what ) ) + \" \\n \" ) NEW_LINE DEDENT DEDENT L = 1000000007 NEW_LINE for case in xrange ( input ( ) ) : NEW_LINE INDENT debug ( ) NEW_LINE debug ( \" Case ▁ # % d : \" % ( case + 1 ) ) NEW_LINE n , m , X , Y , Z = map ( int , raw_input ( ) . split ( ) ) NEW_LINE A = [ ] NEW_LINE for i in xrange ( m ) : NEW_LINE INDENT A . append ( input ( ) ) NEW_LINE DEDENT debug ( ' n ▁ m ▁ X ▁ Y ▁ Z ' , n , m , X , Y , Z , ' A ' , A ) NEW_LINE S = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT S . append ( A [ i % m ] ) NEW_LINE A [ i % m ] = ( X * A [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT debug ( ' S ' , S ) NEW_LINE c = [ 1 ] * n NEW_LINE r = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT debug ( ' i ' , i ) NEW_LINE for j in xrange ( i ) : NEW_LINE INDENT if S [ j ] < S [ i ] : NEW_LINE INDENT c [ i ] += c [ j ] ; c [ i ] %= L NEW_LINE DEDENT DEDENT r += c [ i ] ; r %= L NEW_LINE debug ( ' c ' , c ) NEW_LINE debug ( ' r ' , r ) NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( case + 1 , r ) NEW_LINE DEDENT", "import sys NEW_LINE import math NEW_LINE input = open ( sys . argv [ 1 ] , \" r \" ) NEW_LINE output = open ( \" speed . out \" , \" w \" ) NEW_LINE caseN = 0 NEW_LINE case = 0 NEW_LINE n = 0 NEW_LINE m = 0 NEW_LINE X = 0 NEW_LINE Y = 0 NEW_LINE Z = 0 NEW_LINE acc = 0 NEW_LINE A = [ ] NEW_LINE B = [ ] NEW_LINE C = [ ] NEW_LINE MODNUM = 1000000007 NEW_LINE for line in input : NEW_LINE INDENT if caseN == 0 : NEW_LINE INDENT caseN = int ( line ) NEW_LINE continue NEW_LINE DEDENT elif n == 0 : NEW_LINE INDENT intLine = map ( int , line . split ( ' ▁ ' ) ) NEW_LINE n = intLine [ 0 ] NEW_LINE m = intLine [ 1 ] NEW_LINE X = intLine [ 2 ] NEW_LINE Y = intLine [ 3 ] NEW_LINE Z = intLine [ 4 ] NEW_LINE acc = m - 1 NEW_LINE DEDENT elif acc > 0 : NEW_LINE INDENT acc -= 1 NEW_LINE A += [ int ( line ) ] NEW_LINE DEDENT else : NEW_LINE INDENT A += [ int ( line ) ] NEW_LINE ans = 0 NEW_LINE B = [ 0 for x in range ( n ) ] NEW_LINE C = [ 0 for x in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT B [ i ] = int ( A [ i % m ] ) NEW_LINE A [ i % m ] = ( X * A [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT loopNums = range ( n ) NEW_LINE loopNums . reverse ( ) NEW_LINE for i in loopNums : NEW_LINE INDENT seqNum = 1 NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT if B [ j ] > B [ i ] : NEW_LINE INDENT seqNum += C [ j ] NEW_LINE seqNum %= MODNUM NEW_LINE DEDENT DEDENT C [ i ] = seqNum NEW_LINE C [ i ] %= MODNUM NEW_LINE ans += seqNum NEW_LINE ans %= MODNUM NEW_LINE DEDENT case += 1 NEW_LINE output . write ( \" Case ▁ # \" + str ( case ) + \" : ▁ \" + str ( ans ) + \" \\n \" ) NEW_LINE n = 0 NEW_LINE A = [ ] NEW_LINE DEDENT DEDENT input . close ( ) NEW_LINE output . close ( ) NEW_LINE", "fd = open ( \" input . in \" ) NEW_LINE num_cases = int ( fd . readline ( ) ) NEW_LINE for i in range ( 0 , num_cases ) : NEW_LINE INDENT ( n , m , X , Y , Z ) = [ int ( item ) for item in fd . readline ( ) . split ( \" ▁ \" ) ] NEW_LINE A = [ 0 ] * n NEW_LINE for j in range ( 0 , m ) : NEW_LINE INDENT A [ j ] = int ( fd . readline ( ) ) NEW_LINE DEDENT speeds = [ ] NEW_LINE for j in range ( 0 , n ) : NEW_LINE INDENT speeds . append ( A [ j % m ] ) NEW_LINE A [ j % m ] = ( X * A [ j % m ] + Y * ( j + 1 ) ) % Z NEW_LINE DEDENT num_sets = [ 1 ] * len ( speeds ) NEW_LINE for j in range ( len ( speeds ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT for k in range ( j + 1 , len ( speeds ) ) : NEW_LINE INDENT if speeds [ k ] > speeds [ j ] : NEW_LINE INDENT num_sets [ j ] += num_sets [ k ] NEW_LINE DEDENT DEDENT DEDENT tot_sets = 0 NEW_LINE for j in range ( 0 , len ( speeds ) ) : NEW_LINE INDENT tot_sets += num_sets [ j ] NEW_LINE DEDENT print \" Case ▁ # % d : \" % ( i + 1 ) , tot_sets % 1000000007 NEW_LINE DEDENT", "import sys NEW_LINE FILE_NAME = ' C - small - attempt0' NEW_LINE INPUT_FILE = FILE_NAME + ' . in ' NEW_LINE OUTPUT_FILE = FILE_NAME + ' . out ' NEW_LINE def process ( case , n , m , X , Y , Z , B ) : NEW_LINE INDENT A = [ 0 ] * n NEW_LINE S = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT A [ i ] = int ( B [ i % m ] ) NEW_LINE B [ i % m ] = ( X * B [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT S [ i ] = 1 NEW_LINE for j in range ( i ) : NEW_LINE INDENT if A [ j ] < A [ i ] : NEW_LINE INDENT S [ i ] = S [ i ] + S [ j ] NEW_LINE DEDENT DEDENT DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , sum ( S ) % 1000000007 ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT fp_in = open ( INPUT_FILE , ' r ' ) NEW_LINE fp_out = open ( OUTPUT_FILE , ' w ' ) NEW_LINE sys . stdin = fp_in NEW_LINE sys . stdout = fp_out NEW_LINE num_cases = int ( input ( ) ) NEW_LINE for case in range ( 1 , num_cases + 1 ) : NEW_LINE INDENT n , m , X , Y , Z = map ( int , raw_input ( ) . split ( ) ) NEW_LINE B = [ 0 ] * m NEW_LINE for i in range ( m ) : NEW_LINE INDENT B [ i ] = input ( ) NEW_LINE DEDENT process ( case , n , m , X , Y , Z , B ) NEW_LINE DEDENT fp_in . close ( ) NEW_LINE fp_out . close ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_17_33
[ "import java . util . Arrays ; import java . util . Scanner ; public class ProblemC { public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { int cases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= cases ; caseNum ++ ) { solve ( sc , caseNum ) ; } } } static void solve ( Scanner sc , int caseNum ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; double U = sc . nextDouble ( ) ; double [ ] P = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = sc . nextDouble ( ) ; } Arrays . sort ( P ) ; double eps = 1e-8 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { double add = P [ i + 1 ] - P [ i ] ; if ( add * ( i + 1 ) > U + eps ) { for ( int j = 0 ; j <= i ; j ++ ) { P [ j ] += U / ( i + 1 ) ; } U = 0 ; break ; } else { for ( int j = 0 ; j <= i ; j ++ ) { P [ j ] += add ; } U -= add * ( i + 1 ) ; } } if ( U > 0 ) { for ( int j = 0 ; j < N ; j ++ ) { P [ j ] += U / N ; } } double res = 1 ; for ( int j = 0 ; j < N ; j ++ ) { res *= P [ j ] ; } System . out . printf ( \" Case ▁ # % d : ▁ % .8f \\n \" , caseNum , res ) ; } }", "package round1c ; import java . util . Arrays ; public class ProbC extends Prob { void setup ( ) { bin = true ; bout = true ; in = \" C - small - 1 - attempt0 . in \" ; out = \" cout . txt \" ; } @ Override public void main ( ) { setup ( ) ; reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { double ans = run ( ) ; System . out . println ( String . format ( \" Case ▁ # % d : ▁ % f \" , cas , ans ) ) ; } } double run ( ) { int n = scanner . nextInt ( ) ; int k = scanner . nextInt ( ) ; double u = scanner . nextDouble ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = scanner . nextDouble ( ) ; } Arrays . sort ( p ) ; double limit = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == n - 1 || ( p [ i + 1 ] - p [ i ] ) * ( i + 1 ) > u ) { limit = u / ( i + 1 ) + p [ i ] ; break ; } else { u -= ( p [ i + 1 ] - p [ i ] ) * ( i + 1 ) ; } } double poss = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] < limit ) poss *= limit ; else poss *= p [ i ] ; } return poss ; } }", "package gcj2017 . r1c ; import java . io . * ; import java . util . Arrays ; import java . util . Scanner ; public class Training { static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { String name = \" gcj2017 / r1c / C - small - 1\" ; Scanner s = new Scanner ( new File ( name + \" . in \" ) ) ; int count = s . nextInt ( ) ; out = new PrintWriter ( new BufferedWriter ( new FileWriter ( name + \" . out \" ) ) ) ; for ( int ii = 1 ; ii <= count ; ii ++ ) { out . print ( \" Case ▁ # \" + ii + \" : ▁ \" ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; double u = s . nextDouble ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = s . nextDouble ( ) ; } double res = solve ( n , k , u , p ) ; out . print ( String . format ( \" % .8f \" , res ) ) ; out . println ( ) ; } out . close ( ) ; } static double solve ( int n , int k , double u , double [ ] p ) { Arrays . sort ( p ) ; while ( u > 0.000000001 ) { double min = p [ 0 ] ; int ni = n ; double np = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( p [ i ] == min ) { continue ; } np = p [ i ] ; ni = i ; break ; } if ( ni * ( np - min ) <= u ) { for ( int i = 0 ; i < ni ; i ++ ) { p [ i ] = np ; } u -= ni * ( np - min ) ; } else { double d = u / ni ; for ( int i = 0 ; i < ni ; i ++ ) { p [ i ] += d ; } u = 0 ; } } double res = 1 ; for ( int i = 0 ; i < n ; i ++ ) { res *= p [ i ] ; } return res ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( new File ( \" output . txt \" ) ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; double budget = in . nextDouble ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = in . nextDouble ( ) ; } out . println ( \" Case ▁ # \" + t + \" : ▁ \" + calc ( p , budget ) ) ; } out . close ( ) ; } static double calc ( double [ ] p , double budget ) { double ans = 1.0 ; int n = p . length ; Arrays . sort ( p ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { double d = p [ i + 1 ] - p [ i ] ; double need = d * ( i + 1 ) ; if ( budget < need ) { double minP = p [ i ] + budget / ( i + 1 ) ; for ( int j = 0 ; j <= i ; j ++ ) { ans *= minP ; } for ( int j = i + 1 ; j < n ; j ++ ) { ans *= p [ j ] ; } return ans ; } budget -= need ; } double minP = p [ n - 1 ] + budget / n ; return Math . pow ( minP , n ) ; } }", "import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( \" C - small - 1 - attempt2 . in \" ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( \" solve . txt \" ) ) ; int T = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; StringTokenizer s ; for ( int t = 1 ; t <= T ; t ++ ) { s = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; int N = Integer . parseInt ( s . nextToken ( ) ) ; int K = Integer . parseInt ( s . nextToken ( ) ) ; double [ ] arr = new double [ N ] ; double U = Double . parseDouble ( br . readLine ( ) . trim ( ) ) ; s = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = Double . parseDouble ( s . nextToken ( ) ) ; } Arrays . sort ( arr ) ; double pro = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i != N - 1 ) { if ( U > ( ( i + 1 ) * ( arr [ i + 1 ] - arr [ i ] ) ) ) { U -= ( ( i + 1 ) * ( arr [ i + 1 ] - arr [ i ] ) ) ; } else { pro = Math . pow ( ( arr [ i ] + ( U / ( i + 1 ) ) ) , i + 1 ) ; for ( int j = i + 1 ; j < N ; j ++ ) { pro *= arr [ j ] ; } break ; } } else { pro = Math . pow ( ( U / N ) + arr [ i ] , N ) ; } } bw . write ( \" Case ▁ # \" + t + \" : ▁ \" ) ; bw . write ( String . format ( \" % .6f \\n \" , pro ) ) ; } br . close ( ) ; bw . close ( ) ; return ; } }" ]
[ "def check ( V , U , P ) : NEW_LINE INDENT return sum ( V - x for x in P if x < V ) <= U NEW_LINE DEDENT def solve ( N , K , U , P ) : NEW_LINE INDENT L , R = 0.0 , 1.0 NEW_LINE if ( check ( R , U , P ) ) : NEW_LINE INDENT return R NEW_LINE DEDENT while R - L > 1e-10 : NEW_LINE INDENT M = ( L + R ) / 2.0 NEW_LINE if check ( M , U , P ) : NEW_LINE INDENT L = M NEW_LINE DEDENT else : NEW_LINE INDENT R = M NEW_LINE DEDENT DEDENT res = 1.0 NEW_LINE for x in P : NEW_LINE INDENT res *= max ( x , L ) NEW_LINE DEDENT return res NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , K = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE U = float ( raw_input ( ) ) NEW_LINE P = map ( float , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE res = solve ( N , K , U , P ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( t + 1 , res ) NEW_LINE DEDENT", "import sys NEW_LINE import math NEW_LINE from functools import reduce NEW_LINE lines = [ l . strip ( ) for l in sys . stdin . readlines ( ) ] NEW_LINE T = int ( lines [ 0 ] ) NEW_LINE i = 1 NEW_LINE for t in range ( T ) : NEW_LINE INDENT N , K = map ( int , lines [ i ] . split ( ' ▁ ' ) ) NEW_LINE i += 1 NEW_LINE U = float ( lines [ i ] ) NEW_LINE i += 1 NEW_LINE P = list ( map ( float , lines [ i ] . split ( ' ▁ ' ) ) ) NEW_LINE i += 1 NEW_LINE P . sort ( ) NEW_LINE j = 0 NEW_LINE while j < N and U > 0.000000000001 : NEW_LINE INDENT while j < N - 1 and P [ j ] == P [ j + 1 ] : NEW_LINE INDENT j += 1 NEW_LINE DEDENT target = P [ j + 1 ] if j < N - 1 else 1 NEW_LINE required = ( target - P [ j ] ) * ( j + 1 ) NEW_LINE if required <= U : NEW_LINE INDENT U -= required NEW_LINE P [ 0 : j + 1 ] = [ target ] * ( j + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT target = P [ j ] + U / ( j + 1 ) NEW_LINE U = 0 NEW_LINE P [ 0 : j + 1 ] = [ target ] * ( j + 1 ) NEW_LINE DEDENT DEDENT print ( \" Case ▁ # % d : ▁ % f \" % ( t + 1 , reduce ( lambda x , y : x * y , P , 1.0 ) ) ) NEW_LINE DEDENT", "import math NEW_LINE CONVERT = 10000 NEW_LINE def f ( nums , power , k ) : NEW_LINE INDENT for i in range ( power ) : NEW_LINE INDENT nums [ nums . index ( min ( nums ) ) ] += 1 NEW_LINE DEDENT ans = 1 NEW_LINE for n in nums : NEW_LINE INDENT ans *= n / CONVERT NEW_LINE DEDENT return ans NEW_LINE DEDENT def logs ( x ) : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return - 100000 NEW_LINE DEDENT return math . log ( x ) NEW_LINE DEDENT def logadd ( a , b ) : NEW_LINE INDENT if a < b : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT return a + logs ( 1 + math . exp ( b - a ) ) NEW_LINE DEDENT def p ( nums , K ) : NEW_LINE INDENT store = [ ] NEW_LINE for i in range ( K + 1 ) : NEW_LINE INDENT store . append ( [ 0 ] * len ( nums ) ) NEW_LINE DEDENT for k in range ( K + 1 ) : NEW_LINE INDENT for i in range ( len ( nums ) ) : NEW_LINE INDENT if k == 0 : NEW_LINE INDENT store [ k ] [ i ] = 0 NEW_LINE DEDENT elif i == 0 : NEW_LINE INDENT store [ k ] [ i ] = - 100000 NEW_LINE DEDENT else : NEW_LINE INDENT store [ k ] [ i ] = logadd ( store [ k - 1 ] [ i - 1 ] + logs ( nums [ i ] ) , store [ k ] [ i - 1 ] + logs ( 1 - nums [ i ] ) ) NEW_LINE DEDENT DEDENT DEDENT return store [ K ] [ len ( nums ) - 1 ] NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE power = float ( input ( ) ) NEW_LINE power *= CONVERT NEW_LINE power = round ( power ) NEW_LINE starts = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE for i in range ( len ( starts ) ) : NEW_LINE INDENT starts [ i ] = round ( starts [ i ] * CONVERT ) NEW_LINE DEDENT ans = f ( starts , power , k ) NEW_LINE print ( \" Case ▁ # % s : ▁ % s \" % ( case , ans ) ) NEW_LINE DEDENT", "with open ( ' C - small - 1 - attempt0 . in ' ) as infile : NEW_LINE INDENT with open ( ' C - small - 1 - attempt0 . out ' , ' w ' ) as outfile : NEW_LINE INDENT cases = int ( next ( infile ) ) NEW_LINE for case in range ( 1 , cases + 1 ) : NEW_LINE INDENT n , k = map ( int , next ( infile ) . split ( ) ) NEW_LINE u = round ( float ( next ( infile ) ) * 10000 ) NEW_LINE p = list ( map ( lambda x : round ( float ( x ) * 10000 ) , next ( infile ) . split ( ) ) ) NEW_LINE p . sort ( ) NEW_LINE p . append ( 10000 ) NEW_LINE i = 0 NEW_LINE while u > 0 and i < len ( p ) : NEW_LINE INDENT while i < len ( p ) and p [ i ] == p [ i + 1 ] : NEW_LINE INDENT i += 1 NEW_LINE DEDENT x = min ( ( p [ i + 1 ] - p [ i ] ) * ( i + 1 ) , u ) NEW_LINE for j in range ( i + 1 ) : NEW_LINE INDENT p [ j ] += x / ( i + 1 ) NEW_LINE DEDENT u -= x NEW_LINE DEDENT product = 1 NEW_LINE for x in p : NEW_LINE INDENT product *= x / 10000 NEW_LINE DEDENT print ( case , product ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } \" . format ( case , product ) , file = outfile ) NEW_LINE DEDENT DEDENT DEDENT", "import sys NEW_LINE def problem ( success , units , cores ) : NEW_LINE INDENT cores . sort ( ) NEW_LINE cores . append ( 1.0 ) NEW_LINE spent = 0.0 NEW_LINE min_prob = 0.0 NEW_LINE for i , core in enumerate ( cores ) : NEW_LINE INDENT if core == 1.0 : NEW_LINE INDENT min_prob = 1.0 NEW_LINE break NEW_LINE DEDENT plan = ( cores [ i + 1 ] - cores [ i ] ) * ( i + 1 ) NEW_LINE if plan > units - spent : NEW_LINE INDENT min_prob = core + ( units - spent ) / ( i + 1 ) NEW_LINE break NEW_LINE DEDENT spent += plan NEW_LINE DEDENT prob = 1.0 NEW_LINE for n in cores : NEW_LINE INDENT prob *= max ( min_prob , n ) NEW_LINE DEDENT return prob NEW_LINE DEDENT def nextline ( input_file ) : NEW_LINE INDENT data = \" \" NEW_LINE while not data : NEW_LINE INDENT data = input_file . readline ( ) NEW_LINE DEDENT return data [ : - 1 ] NEW_LINE DEDENT def intsplit ( s ) : NEW_LINE INDENT return [ int ( x ) for x in s . split ( \" ▁ \" ) ] NEW_LINE DEDENT def floatsplit ( s ) : NEW_LINE INDENT return [ float ( x ) for x in s . split ( \" ▁ \" ) ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT result = \" \" NEW_LINE with sys . stdin if len ( sys . argv ) == 1 else open ( sys . argv [ 1 ] , ' r ' ) as infile : NEW_LINE INDENT number = int ( nextline ( infile ) ) NEW_LINE for run in range ( number ) : NEW_LINE INDENT case = nextline ( infile ) NEW_LINE total , success = intsplit ( case ) NEW_LINE units = float ( nextline ( infile ) ) NEW_LINE cores = floatsplit ( nextline ( infile ) ) NEW_LINE result += ' Case ▁ # { } : ▁ { } \\n ' . format ( 1 + run , problem ( success , units , cores ) ) NEW_LINE DEDENT DEDENT if len ( sys . argv ) == 1 : NEW_LINE INDENT print ( result , end = ' ' ) NEW_LINE DEDENT else : NEW_LINE INDENT with open ( sys . argv [ 1 ] . replace ( ' in ' , ' sol ' ) , ' w ' ) as result_file : NEW_LINE INDENT result_file . write ( result ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_11_33
[ "import java . io . * ; import java . util . * ; import java . math . * ; public class C { private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private void solve ( ) throws IOException { int tests = nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int N = nextInt ( ) ; long L = nextLong ( ) ; long H = nextLong ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = nextLong ( ) ; } long result = - 1 ; for ( long C = L ; C <= H ; C ++ ) { boolean ok = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( C % A [ i ] != 0 && A [ i ] % C != 0 ) { ok = false ; break ; } } if ( ok ) { result = C ; break ; } } if ( result == - 1 ) { out . println ( \" NO \" ) ; } else { out . println ( result ) ; } } } public static void main ( String [ ] args ) { new C ( ) . run ( ) ; } public void run ( ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ; st = null ; solve ( ) ; in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } private String nextToken ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( in . readLine ( ) ) ; } return st . nextToken ( ) ; } private int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } private long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } private double nextDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; } }", "package CodeJam ; import java . util . * ; import java . io . * ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . lang . ArrayUtils ; import java . lang . Math . * ; import java . math . BigInteger ; import static helper . Print . * ; public class B { private static String inFilename = \" C - small - attempt0 . in \" ; public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( \" src / CodeJam / \" + inFilename ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( \" src / CodeJam / output . txt \" ) ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { String result = \" NO \" ; int N = in . nextInt ( ) ; int L = in . nextInt ( ) ; int H = in . nextInt ( ) ; int [ ] f = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { f [ i ] = in . nextInt ( ) ; } loop : for ( int i = L ; i <= H ; i ++ ) { int j = 0 ; for ( ; j < N ; j ++ ) { if ( ! ( f [ j ] % i == 0 || i % f [ j ] == 0 ) ) { continue loop ; } } if ( j == N ) { result = String . valueOf ( i ) ; break ; } } out . print ( \" Case ▁ # \" + ( t + 1 ) + \" : ▁ \" + result + \" \\n \" ) ; } in . close ( ) ; out . close ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class PerfectHarmony { public static void main ( String args [ ] ) throws FileNotFoundException { new PerfectHarmony ( ) ; } public PerfectHarmony ( ) throws FileNotFoundException { Scanner scanner = new Scanner ( System . in ) ; PrintWriter writer = new PrintWriter ( new File ( \" C : / res . txt \" ) ) ; int COUNT = scanner . nextInt ( ) ; for ( int y = 1 ; y <= COUNT ; y ++ ) { int N = scanner . nextInt ( ) , L = scanner . nextInt ( ) , H = scanner . nextInt ( ) ; int nums [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) nums [ i ] = scanner . nextInt ( ) ; boolean result = false ; loop : for ( int i = L ; i <= H ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) if ( i % nums [ j ] != 0 && nums [ j ] % i != 0 ) continue loop ; writer . write ( String . format ( \" Case ▁ # % d : ▁ % d \\n \" , y , i ) ) ; result = true ; break loop ; } if ( ! result ) { writer . write ( String . format ( \" Case ▁ # % d : ▁ NO \\n \" , y ) ) ; } } writer . close ( ) ; } }", "import java . io . * ; import java . util . * ; public class Main { Scanner in ; PrintWriter out ; static final String problem = \" C - small \" ; static void asserT ( boolean e ) { if ( ! e ) { throw new Error ( ) ; } } void solveOne ( ) { int nPlayers = in . nextInt ( ) ; int low = in . nextInt ( ) ; int high = in . nextInt ( ) ; int freq [ ] = new int [ nPlayers ] ; for ( int i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = in . nextInt ( ) ; } for ( int f = low ; f <= high ; f ++ ) { boolean fail = false ; for ( int other : freq ) { if ( other % f != 0 && f % other != 0 ) { fail = true ; break ; } } if ( ! fail ) { out . println ( f ) ; return ; } } out . println ( \" NO \" ) ; } void solve ( ) { int nTests = in . nextInt ( ) ; for ( int i = 0 ; i < nTests ; i ++ ) { out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; solveOne ( ) ; } } void run ( ) { try { in = new Scanner ( new FileReader ( \" C : \\ \\r oundC\\ \\\" + problem + \" . in \" ) ) ; out = new PrintWriter ( new FileWriter ( \" C : \\ \\r oundC\\ \\\" + problem + \" . out \" ) ) ; } catch ( IOException e ) { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; } try { solve ( ) ; } finally { out . close ( ) ; } } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } }", "import java . io . * ; import java . math . * ; import java . util . * ; import java . text . * ; import java . util . regex . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; import static java . lang . Integer . * ; import static java . lang . Double . * ; import static java . lang . Character . * ; public class C { Object solve ( ) { int N = sc . nextInt ( ) ; long L = sc . nextLong ( ) ; long H = sc . nextLong ( ) ; long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextLong ( ) ; loop : for ( long m = L ; m <= H ; m ++ ) { for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] % m != 0 && m % a [ i ] != 0 ) continue loop ; } return m ; } return \" NO \" ; } private static Scanner sc ; private static PrintWriter fw ; public static void main ( String [ ] args ) throws Exception { String inFile ; inFile = \" C - small - attempt0 . in \" ; sc = new Scanner ( new FileInputStream ( inFile ) ) ; fw = new PrintWriter ( new FileWriter ( \" output . txt \" , false ) ) ; int N = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int cas = 1 ; cas <= N ; cas ++ ) { fw . print ( \" Case ▁ # \" + cas + \" : ▁ \" ) ; Object res = new C ( ) . solve ( ) ; if ( res instanceof Double ) fw . printf ( \" % .10f \\n \" , res ) ; else fw . printf ( \" % s \\n \" , res ) ; fw . flush ( ) ; } fw . close ( ) ; sc . close ( ) ; } }" ]
[ "class streamreader : NEW_LINE INDENT def __init__ ( _ , s ) : _ . t = ( t for t in s . read ( ) . split ( ) ) NEW_LINE def __div__ ( _ , t ) : return ( t ) ( _ . t . next ( ) ) NEW_LINE DEDENT import sys NEW_LINE sr = streamreader ( sys . stdin ) NEW_LINE for tc in xrange ( sr / int ) : NEW_LINE INDENT n , l , h = sr / int , sr / int , sr / int NEW_LINE fr = [ sr / int for i in xrange ( n ) ] NEW_LINE answer = ' NO ' NEW_LINE for x in xrange ( l , h + 1 ) : NEW_LINE INDENT ok = True NEW_LINE for f in fr : NEW_LINE INDENT if f % x != 0 and x % f != 0 : NEW_LINE INDENT ok = False NEW_LINE break NEW_LINE DEDENT DEDENT if ok : NEW_LINE INDENT answer = x NEW_LINE break NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ' % ( tc + 1 ) , answer NEW_LINE DEDENT", "import math NEW_LINE import sys NEW_LINE def printe ( * st ) : NEW_LINE INDENT return True NEW_LINE sys . stderr . write ( \" , \" . join ( [ str ( x ) for x in st ] ) + \" \\n \" ) NEW_LINE DEDENT def generator ( N , l ) : NEW_LINE INDENT a = 0 NEW_LINE i = 0 NEW_LINE while a < N : NEW_LINE INDENT yield l [ i ] NEW_LINE i += 1 NEW_LINE if i == len ( l ) : NEW_LINE INDENT i = 0 NEW_LINE DEDENT a += 1 NEW_LINE DEDENT DEDENT def simulate ( ) : NEW_LINE INDENT [ n , l , h ] = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE orchestra = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE notes = [ ] NEW_LINE for i in range ( l , h + 1 ) : NEW_LINE INDENT notes . append ( i ) NEW_LINE DEDENT for l in orchestra : NEW_LINE INDENT i = 0 NEW_LINE while i < len ( notes ) : NEW_LINE INDENT if notes [ i ] % l == 0 or l % notes [ i ] == 0 : NEW_LINE INDENT i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT notes . pop ( i ) NEW_LINE DEDENT DEDENT printe ( notes ) NEW_LINE DEDENT if len ( notes ) == 0 : NEW_LINE INDENT return \" NO \" NEW_LINE DEDENT else : NEW_LINE INDENT return notes [ 0 ] NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT print ( \" Case ▁ # { } : ▁ { } \" . format ( i + 1 , simulate ( ) ) ) NEW_LINE DEDENT DEDENT", "f = open ( ' C - small - attempt0 . in ' , ' r ' ) NEW_LINE x = f . readlines ( ) NEW_LINE x = x [ 1 : ] NEW_LINE for i in range ( len ( x ) / 2 ) : NEW_LINE INDENT a = 2 * i NEW_LINE x [ a ] = x [ a ] . strip ( ) . split ( ) NEW_LINE x [ a + 1 ] = x [ a + 1 ] . strip ( ) . split ( ) NEW_LINE n = x [ a ] [ 0 ] NEW_LINE l = int ( x [ a ] [ 1 ] ) NEW_LINE h = int ( x [ a ] [ 2 ] ) NEW_LINE ans = 0 NEW_LINE for z in range ( l , h + 1 ) : NEW_LINE INDENT cou = 0 NEW_LINE for c in x [ a + 1 ] : NEW_LINE INDENT if z % int ( c ) == 0 or int ( c ) % z == 0 : NEW_LINE INDENT cou += 1 NEW_LINE DEDENT DEDENT if cou == len ( x [ a + 1 ] ) : NEW_LINE INDENT ans = z NEW_LINE break NEW_LINE DEDENT DEDENT if ans == 0 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ NO \" % ( i + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , ans ) NEW_LINE DEDENT DEDENT", "filename = \" C - small - attempt1 . in \" NEW_LINE outputname = filename + \" out . txt \" NEW_LINE inFile = open ( filename , ' r ' ) NEW_LINE outFile = open ( outputname , ' w ' ) NEW_LINE numCases = int ( inFile . readline ( ) ) NEW_LINE for i in range ( numCases ) : NEW_LINE INDENT print i NEW_LINE nextLine = inFile . readline ( ) . split ( ) NEW_LINE numPlayers = int ( nextLine [ 0 ] ) NEW_LINE low = int ( nextLine [ 1 ] ) NEW_LINE high = int ( nextLine [ 2 ] ) NEW_LINE players = [ ] NEW_LINE playerLine = inFile . readline ( ) . split ( ) NEW_LINE for j in range ( numPlayers ) : NEW_LINE INDENT players += [ float ( playerLine [ j ] ) ] NEW_LINE DEDENT minFreq = min ( players ) NEW_LINE possFreqs = [ minFreq * j for j in range ( 1 , int ( high / minFreq ) + 1 ) ] NEW_LINE for j in range ( 1 , int ( minFreq ) ) : NEW_LINE INDENT if ( minFreq / j ) % 1 == 0 : NEW_LINE INDENT possFreqs += [ j ] NEW_LINE DEDENT DEDENT for player in players : NEW_LINE INDENT j = len ( possFreqs ) - 1 NEW_LINE while j >= 0 : NEW_LINE INDENT if ( player / possFreqs [ j ] ) % 1 == 0 or ( possFreqs [ j ] / player ) % 1 == 0 : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT possFreqs . pop ( j ) NEW_LINE j -= 1 NEW_LINE DEDENT DEDENT DEDENT finals = [ ] NEW_LINE for freq in possFreqs : NEW_LINE INDENT if freq >= low and freq <= high : NEW_LINE INDENT finals += [ freq ] NEW_LINE DEDENT DEDENT finals . sort ( ) NEW_LINE if len ( finals ) == 0 : NEW_LINE INDENT outFile . write ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ NO \\n \" ) NEW_LINE DEDENT else : NEW_LINE INDENT outFile . write ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( int ( finals [ 0 ] ) ) + \" \\n \" ) NEW_LINE DEDENT DEDENT inFile . close ( ) NEW_LINE outFile . close ( ) NEW_LINE", "from collections import defaultdict NEW_LINE from random import shuffle NEW_LINE import sys NEW_LINE def go ( filename ) : NEW_LINE INDENT with open ( filename ) as f : NEW_LINE INDENT with open ( \" out . txt \" , \" w \" ) as output : NEW_LINE INDENT for case in range ( 1 , int ( f . readline ( ) ) + 1 ) : NEW_LINE INDENT output . write ( \" Case ▁ # % s : ▁ \" % case ) NEW_LINE in1 = [ int ( v ) for v in f . readline ( ) . split ( ) ] NEW_LINE l , h = in1 [ 1 ] , in1 [ 2 ] NEW_LINE jeff = [ ] NEW_LINE for i in range ( l , h + 1 ) : NEW_LINE INDENT jeff . append ( i ) NEW_LINE DEDENT players = [ int ( v ) for v in f . readline ( ) . split ( ) ] NEW_LINE for p in players : NEW_LINE INDENT nj = [ ] NEW_LINE for j in jeff : NEW_LINE INDENT if ( j >= p and j % p == 0 ) or ( j < p and p % j == 0 ) : NEW_LINE INDENT nj . append ( j ) NEW_LINE DEDENT DEDENT jeff = nj NEW_LINE if not jeff : NEW_LINE INDENT output . write ( \" NO \\n \" ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT output . write ( \" % s \\n \" % jeff [ 0 ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT def main ( ) : NEW_LINE INDENT if len ( sys . argv ) < 1 : NEW_LINE INDENT print \" Usage : ▁ % s ▁ < filename > \" % os . path . basename ( sys . argv [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT go ( sys . argv [ 1 ] ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_11_54
[ "import java . util . * ; import static java . lang . Math . * ; public class D { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { String S = in . next ( ) ; long v = 0 ; long nv = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int at = S . length ( ) - i - 1 ; if ( S . charAt ( i ) == ' ? ' ) { nv |= 1L << at ; } else if ( S . charAt ( i ) == '1' ) { v |= 1L << at ; } } long ans = 0 ; for ( long c = nv ; ; c = ( c - 1 ) & nv ) { long test = v + c ; if ( issquare ( test ) ) { ans = test ; break ; } if ( c == 0 ) break ; } System . out . format ( \" Case ▁ # % d : ▁ % s \\n \" , zz , Long . toBinaryString ( ans ) ) ; } } private static boolean issquare ( long t ) { long low = 1 ; long high = Integer . MAX_VALUE ; while ( low <= high ) { long mid = ( low + high ) / 2 ; long v = mid * mid ; if ( v == t ) { return true ; } if ( v < t ) { low = mid + 1 ; } else { high = mid - 1 ; } } return false ; } }", "import java . io . * ; import java . util . * ; public class D { private static String fileName = D . class . getSimpleName ( ) . replaceFirst ( \" _ . * \" , \" \" ) . toLowerCase ( ) ; private static String inputFileName = fileName + \" . in \" ; private static String outputFileName = fileName + \" . out \" ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { String s = in . next ( ) ; int n = s . length ( ) ; int [ ] a = new int [ n ] ; int q = 0 ; for ( int i = 0 ; i < n ; i ++ ) { switch ( s . charAt ( i ) ) { case '0' : a [ i ] = 0 ; break ; case '1' : a [ i ] = 1 ; break ; case ' ? ' : a [ i ] = 2 ; q ++ ; break ; } } for ( int mask = 0 ; mask < ( 1 << q ) ; mask ++ ) { long v = 0 ; for ( int i = 0 , j = 0 ; i < n ; i ++ ) { int c = a [ i ] ; if ( c == 2 ) { c = ( mask >> j ) & 1 ; j ++ ; } v = 2 * v + c ; } long u = Math . round ( Math . sqrt ( v ) ) ; if ( u * u == v ) { out . println ( Long . toBinaryString ( v ) ) ; return ; } } throw new RuntimeException ( ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; if ( args . length >= 2 ) { inputFileName = args [ 0 ] ; outputFileName = args [ 1 ] ; } in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; new D ( ) . solve ( ) ; System . out . println ( \" Case ▁ # \" + t + \" : ▁ solved \" ) ; } in . close ( ) ; out . close ( ) ; } }", "import static java . lang . Math . * ; import static java . util . Arrays . * ; import java . io . * ; import java . util . * ; public class D { Scanner sc = new Scanner ( System . in ) ; void solve ( ) { char [ ] cs = sc . next ( ) . toCharArray ( ) ; int m = 0 ; for ( char c : cs ) if ( c == ' ? ' ) m ++ ; for ( int i = 0 ; i < 1 << m ; i ++ ) { char [ ] ds = cs . clone ( ) ; int p = 0 ; for ( int j = 0 ; j < cs . length ; j ++ ) if ( cs [ j ] == ' ? ' ) { ds [ j ] = ( char ) ( '0' + ( i >> p & 1 ) ) ; p ++ ; } long v = 0 ; for ( char c : ds ) v = v * 2 + c - '0' ; long a = ( long ) sqrt ( v ) ; while ( a * a < v ) a ++ ; while ( a * a > v ) a -- ; if ( a * a == v ) { System . out . println ( Long . toBinaryString ( v ) ) ; return ; } } } void run ( ) { int caseN = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseN ; caseID ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ \" , caseID ) ; solve ( ) ; System . out . flush ( ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { try { System . setIn ( new BufferedInputStream ( new FileInputStream ( args . length > 0 ? args [ 0 ] : ( D . class . getName ( ) + \" . in \" ) ) ) ) ; } catch ( Exception e ) { } new D ( ) . run ( ) ; } }", "package round3 ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class D { static long [ ] stepeni = new long [ 62 ] ; static { stepeni [ 0 ] = 1 ; for ( int i = 1 ; i < stepeni . length ; i ++ ) stepeni [ i ] = 2 * stepeni [ i - 1 ] ; } static boolean jePotpunKvadrat ( long a ) { long koren = Math . round ( Math . sqrt ( a ) ) ; return koren * koren == a ; } static long resi ( String s , long value , int position ) { if ( jePotpunKvadrat ( value ) ) return value ; if ( position == s . length ( ) ) return - 1 ; if ( s . charAt ( position ) == ' ? ' ) { long res = resi ( s , value , position + 1 ) ; if ( res != - 1 ) return res ; return resi ( s , value + stepeni [ s . length ( ) - position - 1 ] , position + 1 ) ; } else return resi ( s , value , position + 1 ) ; } public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( \" D . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" D . out \" ) ) ; int tt = in . nextInt ( ) ; for ( int ttt = 1 ; ttt <= tt ; ttt ++ ) { String s = in . next ( ) ; long min = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( s . length ( ) - i - 1 ) == '1' ) min += stepeni [ i ] ; long res = resi ( s , min , 0 ) ; out . printf ( \" Case ▁ # % d : ▁ % s \" , ttt , Long . toBinaryString ( res ) ) ; out . println ( ) ; } out . flush ( ) ; out . close ( ) ; in . close ( ) ; } }", "import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class Main { public StringBuffer s ; public boolean ok ; public String ans ; public void rec ( ) { if ( ok ) return ; int pos = - 1 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i ) == ' ? ' ) { pos = i ; break ; } if ( pos == - 1 ) { BigInteger b = BigInteger . ZERO ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i ) == '1' ) b = b . add ( BigInteger . ONE . shiftLeft ( s . length ( ) - 1 - i ) ) ; BigInteger l = BigInteger . ONE , r = BigInteger . TEN . pow ( 25 ) ; while ( l . compareTo ( r ) != 0 ) { BigInteger x = l . add ( r ) . shiftRight ( 1 ) ; BigInteger xx = x . multiply ( x ) ; if ( xx . compareTo ( b ) >= 0 ) r = x ; else l = x . add ( BigInteger . ONE ) ; } BigInteger test = l . multiply ( l ) ; if ( test . compareTo ( b ) == 0 ) { ok = true ; ans = test . toString ( 2 ) ; } } else { s . setCharAt ( pos , '0' ) ; rec ( ) ; s . setCharAt ( pos , '1' ) ; rec ( ) ; s . setCharAt ( pos , ' ? ' ) ; } } public void run ( ) throws IOException { Scanner in = new Scanner ( new File ( \" D . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" D . out \" ) ) ; int T = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; String ss = in . nextLine ( ) ; s = new StringBuffer ( ss ) ; ok = false ; rec ( ) ; out . println ( ans ) ; out . flush ( ) ; } } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } }" ]
[ "import sys NEW_LINE from fractions import Fraction NEW_LINE from fractions import gcd NEW_LINE from collections import defaultdict NEW_LINE import copy NEW_LINE import multiprocessing NEW_LINE cin = sys . stdin . readline NEW_LINE def nrt ( n ) : NEW_LINE INDENT op = n NEW_LINE res = 0 NEW_LINE one = 1 NEW_LINE while one * 4 <= op : NEW_LINE INDENT one *= 4 NEW_LINE DEDENT while one != 0 : NEW_LINE INDENT if op >= res + one : NEW_LINE INDENT op -= res + one NEW_LINE res = ( res >> 1 ) + one NEW_LINE DEDENT else : NEW_LINE INDENT res >>= 1 NEW_LINE DEDENT one >>= 2 NEW_LINE DEDENT return op NEW_LINE DEDENT def solve ( s ) : NEW_LINE INDENT out = 0 NEW_LINE unknown = 0 NEW_LINE S = len ( s ) NEW_LINE bits = list ( ) NEW_LINE for e , i in enumerate ( s ) : NEW_LINE INDENT out *= 2 NEW_LINE unknown *= 2 NEW_LINE if i == '1' : NEW_LINE INDENT out += 1 NEW_LINE DEDENT elif i == ' ? ' : NEW_LINE INDENT unknown += 1 NEW_LINE bits . append ( ( 1 << ( S - e - 1 ) ) ) NEW_LINE DEDENT DEDENT answer = ( out | unknown ) NEW_LINE x = nrt ( answer ) NEW_LINE while x != 0 : NEW_LINE INDENT answer -= x NEW_LINE new_answer = out NEW_LINE for num in bits : NEW_LINE INDENT if ( new_answer | num ) <= answer : NEW_LINE INDENT new_answer |= num NEW_LINE DEDENT DEDENT answer = new_answer NEW_LINE x = nrt ( answer ) NEW_LINE DEDENT return bin ( answer ) [ 2 : ] NEW_LINE DEDENT def procfunc ( tup ) : NEW_LINE INDENT x = solve ( * tup [ 1 : ] ) NEW_LINE print >> sys . stderr , \" SOLVE \" , tup [ 0 ] NEW_LINE return x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT T = int ( cin ( ) ) NEW_LINE inputs = [ ] NEW_LINE for cnum in xrange ( T ) : NEW_LINE INDENT arr = cin ( ) . strip ( ) NEW_LINE inputs . append ( ( cnum , arr ) ) NEW_LINE DEDENT if False : NEW_LINE INDENT pool = multiprocessing . Pool ( ) NEW_LINE output = pool . map_async ( procfunc , inputs , 1 ) . get ( 999999 ) NEW_LINE DEDENT else : NEW_LINE INDENT output = list ( procfunc ( x ) for x in inputs ) NEW_LINE DEDENT for i , out in enumerate ( output ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , out ) NEW_LINE DEDENT DEDENT", "from math import sqrt NEW_LINE T = int ( raw_input ( ) ) NEW_LINE def is_square ( x ) : NEW_LINE INDENT y = int ( sqrt ( x ) + 0.1 ) NEW_LINE return y * y == x NEW_LINE DEDENT def try_it ( s , i ) : NEW_LINE INDENT global poss NEW_LINE if i >= len ( poss ) : NEW_LINE INDENT return s if is_square ( s ) else 0 NEW_LINE DEDENT else : NEW_LINE INDENT p = poss [ i ] NEW_LINE x = try_it ( s , i + 1 ) NEW_LINE if x : NEW_LINE INDENT return x NEW_LINE DEDENT return try_it ( s + p , i + 1 ) NEW_LINE DEDENT DEDENT for case_num in xrange ( 1 , T + 1 ) : NEW_LINE INDENT S = raw_input ( ) . strip ( ) NEW_LINE N = len ( S ) NEW_LINE poss = [ ] NEW_LINE s = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT c = S [ i ] NEW_LINE power = N - 1 - i NEW_LINE if c == '1' : NEW_LINE INDENT s += 2 ** power NEW_LINE DEDENT elif c == ' ? ' : NEW_LINE INDENT poss . append ( 2 ** power ) NEW_LINE DEDENT DEDENT res = try_it ( s , 0 ) NEW_LINE output = ' ' NEW_LINE while res : NEW_LINE INDENT output = str ( res % 2 ) + output NEW_LINE res /= 2 NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % s \" % ( case_num , output ) NEW_LINE DEDENT", "def run ( ) : NEW_LINE INDENT s = raw_input ( ) NEW_LINE q = [ ] NEW_LINE a = 0 NEW_LINE for ( i , b ) in enumerate ( reversed ( s ) ) : NEW_LINE INDENT if ( b == ' ? ' ) : q . append ( i ) NEW_LINE if ( b == '1' ) : a += 1 << i NEW_LINE DEDENT if not q : return s NEW_LINE for i in xrange ( 1 << len ( q ) ) : NEW_LINE INDENT r = a NEW_LINE for ( j , b ) in enumerate ( q ) : NEW_LINE INDENT if ( ( ( i >> j ) & 1 ) == 0 ) : continue NEW_LINE r += 1 << b NEW_LINE DEDENT if r == int ( r ** 0.5 ) ** 2 : NEW_LINE INDENT res = list ( s ) NEW_LINE for ( j , b ) in enumerate ( q ) : NEW_LINE INDENT res [ - b - 1 ] = '0' if ( ( i >> j ) & 1 ) == 0 else '1' NEW_LINE DEDENT return ' ' . join ( res ) NEW_LINE DEDENT DEDENT assert False NEW_LINE DEDENT for test in xrange ( input ( ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( test + 1 , run ( ) ) NEW_LINE DEDENT", "import sys , collections NEW_LINE infile = sys . stdin NEW_LINE def find_square ( S ) : NEW_LINE INDENT qpos = [ i for i , ch in enumerate ( S ) if ch == ' ? ' ] NEW_LINE ns = len ( S ) NEW_LINE nq = len ( qpos ) NEW_LINE baseval = int ( S . replace ( ' ? ' , '0' ) , 2 ) NEW_LINE for i in xrange ( 1 << len ( qpos ) ) : NEW_LINE INDENT val = baseval NEW_LINE for j in xrange ( nq ) : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT p = 1 << ( ns - qpos [ j ] - 1 ) NEW_LINE val += p NEW_LINE DEDENT DEDENT r = int ( val ** 0.5 ) NEW_LINE if ( r * r == val ) : NEW_LINE INDENT return bin ( val ) [ 2 : ] NEW_LINE DEDENT DEDENT DEDENT T = int ( infile . readline ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT S = infile . readline ( ) . strip ( ) NEW_LINE result = find_square ( S ) NEW_LINE print ( \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) ) NEW_LINE DEDENT", "import sys NEW_LINE def foo2 ( word , idx , n ) : NEW_LINE INDENT word = word [ : ] NEW_LINE for i in range ( len ( idx ) ) : NEW_LINE INDENT word [ idx [ i ] ] = n % 2 NEW_LINE n //= 2 NEW_LINE DEDENT res = 0 NEW_LINE for x in word : NEW_LINE INDENT res = res * 2 + x NEW_LINE DEDENT t = int ( res ** 0.5 ) NEW_LINE if t * t == res : NEW_LINE INDENT return ' ' . join ( str ( x ) for x in word ) NEW_LINE DEDENT DEDENT def foo ( ifile ) : NEW_LINE INDENT word = list ( ifile . readline ( ) . strip ( ) ) NEW_LINE idx = [ ] NEW_LINE n = 0 NEW_LINE for i in range ( len ( word ) ) : NEW_LINE INDENT if word [ i ] == ' ? ' : NEW_LINE INDENT idx . append ( i ) NEW_LINE word [ i ] = None NEW_LINE DEDENT else : NEW_LINE INDENT word [ i ] = int ( word [ i ] ) NEW_LINE DEDENT DEDENT n = len ( idx ) NEW_LINE if n == 0 : NEW_LINE INDENT return ' ' . join ( str ( x ) for x in word ) NEW_LINE DEDENT for i in range ( 2 ** n ) : NEW_LINE INDENT t = foo2 ( word , idx , i ) NEW_LINE if t is not None : NEW_LINE INDENT return t NEW_LINE DEDENT DEDENT DEDENT def main ( ifile , ofile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT ofile . write ( \" Case ▁ # % s : ▁ % s \\n \" % ( i + 1 , foo ( ifile ) ) ) NEW_LINE ofile . flush ( ) NEW_LINE DEDENT DEDENT main ( sys . stdin , sys . stdout ) NEW_LINE" ]
codejam_14_11
[ "package round1a ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; Set < Long > need = new HashSet < Long > ( ) , have = new HashSet < Long > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String tmp = sc . next ( ) ; long tmp2 = 0 ; for ( int j = 0 ; j < L ; j ++ ) if ( tmp . charAt ( j ) == '1' ) tmp2 |= ( 1L << j ) ; have . add ( tmp2 ) ; } long lastNeeded = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String tmp = sc . next ( ) ; long tmp2 = 0 ; for ( int j = 0 ; j < L ; j ++ ) if ( tmp . charAt ( j ) == '1' ) tmp2 |= ( 1L << j ) ; need . add ( tmp2 ) ; lastNeeded = tmp2 ; } int ans = L + 1 ; for ( Long elem : have ) { long flip = lastNeeded ^ elem ; Set < Long > got = new HashSet < Long > ( ) ; for ( Long e : need ) { got . add ( e ^ flip ) ; } if ( got . equals ( have ) ) { ans = Math . min ( ans , Long . bitCount ( flip ) ) ; } } System . out . println ( \" Case ▁ # \" + caze + \" : ▁ \" + ( ans > L ? \" NOT ▁ POSSIBLE \" : ans ) ) ; } } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Scanner ; public class ChargingChaos { public static void main ( String [ ] Args ) throws FileNotFoundException { Scanner sc = new Scanner ( new File ( \" A - large ▁ ( 1 ) . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" things . out \" ) ) ; int t = sc . nextInt ( ) , cc = 0 ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; long [ ] things = new long [ n ] ; long [ ] things2 = new long [ n ] ; HashSet < Long > hs = new HashSet < Long > ( ) ; for ( int k = 0 ; k < n ; k ++ ) things [ k ] = make ( sc . next ( ) ) ; for ( int k = 0 ; k < n ; k ++ ) { things2 [ k ] = make ( sc . next ( ) ) ; hs . add ( things2 [ k ] ) ; } int ans = l + 1 ; for ( int k = 0 ; k < n ; k ++ ) { long swit = things [ 0 ] ^ things2 [ k ] ; boolean good = true ; for ( int j = 0 ; good && j < n ; j ++ ) if ( ! hs . contains ( things [ j ] ^ swit ) ) good = false ; if ( good ) ans = Math . min ( Long . bitCount ( swit ) , ans ) ; } if ( ans != l + 1 ) out . printf ( \" Case ▁ # % d : ▁ % d % n \" , ++ cc , ans ) ; else out . printf ( \" Case ▁ # % d : ▁ NOT ▁ POSSIBLE % n \" , ++ cc ) ; } out . close ( ) ; } private static long make ( String s ) { return Long . parseLong ( s , 2 ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Ae { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" A . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" A . out \" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new Ae ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; int l = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( in . next ( ) , 2 ) ; } int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = Integer . parseInt ( in . next ( ) , 2 ) ; } int res = l + 1 ; Arrays . sort ( a ) ; for ( int m = 0 ; m < ( 1 << l ) ; m ++ ) { for ( int i = 0 ; i < n ; i ++ ) { b [ i ] ^= m ; } Arrays . sort ( b ) ; boolean ok = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { ok = false ; break ; } } if ( ok ) { res = Math . min ( res , Integer . bitCount ( m ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] ^= m ; } } return res > l ? \" NOT ▁ POSSIBLE \" : ( \" \" + res ) ; } }" ]
[ "import sys NEW_LINE def countBit ( x ) : NEW_LINE INDENT return 0 if x == 0 else ( x & 1 ) + countBit ( x >> 1 ) NEW_LINE DEDENT def trans ( s , m ) : NEW_LINE INDENT return ' ' . join ( [ chr ( ord ( c ) ^ ( ( m >> i ) & 1 ) ) for ( i , c ) in enumerate ( s ) ] ) NEW_LINE DEDENT TT = int ( sys . stdin . readline ( ) ) NEW_LINE for T in xrange ( 1 , TT + 1 ) : NEW_LINE INDENT N , L = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE A = sys . stdin . readline ( ) . split ( ) NEW_LINE B = sys . stdin . readline ( ) . split ( ) NEW_LINE ans = L + 1 NEW_LINE for m in xrange ( 1 << L ) : NEW_LINE INDENT cnt = countBit ( m ) NEW_LINE if cnt >= ans : continue NEW_LINE A2 = [ trans ( s , m ) for s in A ] NEW_LINE if set ( A2 ) == set ( B ) : NEW_LINE INDENT ans = cnt NEW_LINE DEDENT DEDENT anss = \" NOT ▁ POSSIBLE \" if ans == L + 1 else str ( ans ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( T , anss ) NEW_LINE DEDENT", "def reader ( f ) : NEW_LINE INDENT f = open ( f ) NEW_LINE for line in f : NEW_LINE INDENT yield line . strip ( ) NEW_LINE DEDENT f . close ( ) NEW_LINE DEDENT def write ( f , lst ) : NEW_LINE INDENT for i in xrange ( len ( lst ) ) : NEW_LINE INDENT lst [ i ] = \" Case ▁ # % s : ▁ % s \" % ( i + 1 , lst [ i ] ) NEW_LINE DEDENT f = open ( f , ' w ' ) NEW_LINE f . write ( ' \\n ' . join ( lst ) ) NEW_LINE f . close ( ) NEW_LINE DEDENT", "T = int ( raw_input ( ) ) NEW_LINE def flipTheFlip ( groups , l ) : NEW_LINE INDENT if l == 0 : return 0 NEW_LINE notFlip = True NEW_LINE flip = True NEW_LINE nfgr = [ ] NEW_LINE fgr = [ ] NEW_LINE for outs , targs in groups : NEW_LINE INDENT targ1 = [ x [ 1 : ] for x in targs if x [ 0 ] == '1' ] NEW_LINE targ0 = [ x [ 1 : ] for x in targs if x [ 0 ] == '0' ] NEW_LINE outs0 = [ x [ 1 : ] for x in outs if x [ 0 ] == '0' ] NEW_LINE outs1 = [ x [ 1 : ] for x in outs if x [ 0 ] == '1' ] NEW_LINE if len ( outs0 ) != len ( targ0 ) : notFlip = False NEW_LINE else : NEW_LINE INDENT if outs0 : nfgr . append ( ( outs0 , targ0 ) ) NEW_LINE if outs1 : nfgr . append ( ( outs1 , targ1 ) ) NEW_LINE DEDENT if len ( outs1 ) != len ( targ0 ) : flip = False NEW_LINE else : NEW_LINE INDENT if outs1 : fgr . append ( ( outs1 , targ0 ) ) NEW_LINE if outs0 : fgr . append ( ( outs0 , targ1 ) ) NEW_LINE DEDENT DEDENT resp = 1000000 NEW_LINE if notFlip : NEW_LINE INDENT resp = min ( resp , flipTheFlip ( nfgr , l - 1 ) ) NEW_LINE DEDENT if flip : NEW_LINE INDENT resp = min ( resp , 1 + flipTheFlip ( fgr , l - 1 ) ) NEW_LINE DEDENT return resp NEW_LINE DEDENT for t in xrange ( T ) : NEW_LINE INDENT print \" Case ▁ # % d : \" % ( t + 1 ) , NEW_LINE N , L = map ( int , raw_input ( ) . split ( ) ) NEW_LINE outlets = raw_input ( ) . split ( ) NEW_LINE targets = raw_input ( ) . split ( ) NEW_LINE flips = flipTheFlip ( [ ( outlets , targets ) ] , L ) NEW_LINE print flips if flips <= L else \" NOT ▁ POSSIBLE \" NEW_LINE DEDENT", "fin = open ( ' A - large . in ' , ' r ' ) NEW_LINE fout = open ( ' out . txt ' , ' w ' ) NEW_LINE t = int ( fin . readline ( ) ) NEW_LINE for casecount in range ( 1 , t + 1 ) : NEW_LINE INDENT n , l = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE outlet = [ list ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE device = [ list ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE device . sort ( ) NEW_LINE smallest = 41 NEW_LINE for func in range ( 0 , n ) : NEW_LINE INDENT switch = [ ] NEW_LINE for i in range ( 0 , l ) : NEW_LINE INDENT if outlet [ 0 ] [ i ] != device [ func ] [ i ] : NEW_LINE INDENT switch . append ( i ) NEW_LINE DEDENT DEDENT output = [ ] NEW_LINE for x in outlet : NEW_LINE INDENT x1 = x . copy ( ) NEW_LINE for y in switch : NEW_LINE INDENT if x1 [ y ] == '0' : NEW_LINE INDENT x1 [ y ] = '1' NEW_LINE DEDENT else : NEW_LINE INDENT x1 [ y ] = '0' NEW_LINE DEDENT DEDENT output . append ( x1 ) NEW_LINE DEDENT output . sort ( ) NEW_LINE if smallest > len ( switch ) and output == device : NEW_LINE INDENT smallest = len ( switch ) NEW_LINE DEDENT DEDENT fout . write ( ' Case ▁ # % d : ▁ ' % casecount ) NEW_LINE if smallest == 41 : NEW_LINE INDENT fout . write ( ' NOT ▁ POSSIBLE \\n ' ) NEW_LINE DEDENT else : NEW_LINE INDENT fout . write ( ' % d \\n ' % smallest ) NEW_LINE DEDENT DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE", "import sys NEW_LINE def F ( s ) : NEW_LINE INDENT re = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT re += ( ord ( s [ i ] ) - ord ( '0' ) ) << i NEW_LINE DEDENT return re NEW_LINE DEDENT def C ( x ) : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return x % 2 + C ( x / 2 ) NEW_LINE DEDENT t = input ( ) NEW_LINE for tt in range ( t ) : NEW_LINE INDENT print >> sys . stderr , \" ? ? ? \" , tt NEW_LINE n , l = map ( int , raw_input ( ) . split ( ) ) NEW_LINE a = map ( F , raw_input ( ) . split ( ) ) NEW_LINE b = map ( F , raw_input ( ) . split ( ) ) NEW_LINE ans = 2 * l NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT A = [ ] NEW_LINE B = [ ] NEW_LINE for k in range ( n ) : NEW_LINE INDENT A . append ( a [ k ] ^ a [ i ] ) NEW_LINE B . append ( b [ k ] ^ b [ j ] ) NEW_LINE DEDENT A = sorted ( A ) NEW_LINE B = sorted ( B ) NEW_LINE if A == B : NEW_LINE INDENT ans = min ( ans , C ( a [ i ] ^ b [ j ] ) ) NEW_LINE DEDENT DEDENT DEDENT print \" Case ▁ # % d : \" % ( tt + 1 ) , NEW_LINE if ans == 2 * l : NEW_LINE INDENT print \" NOT ▁ POSSIBLE \" NEW_LINE DEDENT else : NEW_LINE INDENT print ans NEW_LINE DEDENT DEDENT" ]
codejam_08_31
[ "import java . io . File ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class TaskA { private static final String TEST_NAME = \" A - large \" ; private static final String INPUT_FILE = TEST_NAME + \" . in \" ; private static final String OUTPUT_FILE = TEST_NAME + \" . out \" ; private static Scanner in ; private static PrintWriter out ; public static void main ( String [ ] args ) throws Exception { in = new Scanner ( new File ( INPUT_FILE ) ) ; out = new PrintWriter ( OUTPUT_FILE ) ; int testCasesNum = in . nextInt ( ) ; for ( int i = 0 ; i < testCasesNum ; ++ i ) { solveTestCase ( i + 1 ) ; } in . close ( ) ; out . close ( ) ; } private static void reverse ( int [ ] a ) { int med = a . length / 2 ; int len = a . length ; for ( int i = 0 ; i < med ; ++ i ) { int t = a [ i ] ; a [ i ] = a [ len - 1 - i ] ; a [ len - 1 - i ] = t ; } } private static void solveTestCase ( int testCaseID ) { int P = in . nextInt ( ) ; int K = in . nextInt ( ) ; int L = in . nextInt ( ) ; int [ ] freq = new int [ L ] ; for ( int i = 0 ; i < L ; ++ i ) { freq [ i ] = in . nextInt ( ) ; } Arrays . sort ( freq ) ; reverse ( freq ) ; int [ ] keys = new int [ K ] ; int curKey = - 1 ; long result = 0 ; for ( int i = 0 ; i < L ; ++ i ) { curKey = ( curKey + 1 ) % K ; keys [ curKey ] += 1 ; result += keys [ curKey ] * freq [ i ] ; } out . println ( String . format ( \" Case ▁ # % d : ▁ % d \" , testCaseID , result ) ) ; } }", "import java . io . * ; import java . util . * ; public class a { a ( ) { try { File f = new File ( \" A - large . in \" ) ; BufferedReader input = new BufferedReader ( new FileReader ( f ) ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( \" large . out \" ) ) ; int nrtests = Integer . parseInt ( input . readLine ( ) ) ; for ( int nrt = 0 ; nrt < nrtests ; nrt ++ ) { String [ ] spl = input . readLine ( ) . split ( \" ▁ \" ) ; long p = Integer . parseInt ( spl [ 0 ] ) ; long k = Integer . parseInt ( spl [ 1 ] ) ; long l = Integer . parseInt ( spl [ 2 ] ) ; spl = input . readLine ( ) . split ( \" ▁ \" ) ; int n = spl . length ; long [ ] v = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) v [ i ] = Long . parseLong ( spl [ i ] ) ; Arrays . sort ( v ) ; String ans = \" Impossible \" ; if ( p * k >= l ) { long rez = 0 ; for ( long pas = 0 , poz = n - 1 ; pas < p ; pas ++ ) for ( long j = 0 ; j < k ; j ++ , poz -- ) if ( poz >= 0 ) rez += ( long ) ( pas + 1 ) * ( long ) v [ ( int ) poz ] ; ans = \" \" + rez ; } out . write ( \" Case ▁ # \" + ( nrt + 1 ) + \" : ▁ \" + ans + \" \\n \" ) ; } out . close ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) { new a ( ) ; } }", "import java . io . FileOutputStream ; import java . io . PrintWriter ; import java . io . IOException ; import java . util . Set ; import java . util . HashSet ; import java . util . Collections ; import java . util . Arrays ; public class A { public static void main ( String [ ] args ) { try { Scanner scanner = new Scanner ( \" c : / input . txt \" ) ; FileOutputStream out = new FileOutputStream ( \" c : / output . txt \" ) ; int numberOfCases ; numberOfCases = scanner . nextInt ( ) ; PrintWriter wr = new PrintWriter ( out ) ; for ( int i = 0 ; i < numberOfCases ; i ++ ) { doCase ( i + 1 , scanner , wr ) ; } wr . close ( ) ; out . close ( ) ; } catch ( IOException e ) { System . out . println ( \" Error : ▁ \" + e ) ; } } private static void doCase ( int caseNumber , Scanner sc , PrintWriter wr ) throws IOException { int P , K , L ; P = sc . nextInt ( ) ; K = sc . nextInt ( ) ; L = sc . nextInt ( ) ; int [ ] freq = new int [ L ] ; for ( int i = 0 ; i < L ; i ++ ) { freq [ i ] = sc . nextInt ( ) ; } Arrays . sort ( freq ) ; long result = 0 ; int keyPress = 1 ; int keyCounter = 0 ; for ( int i = L - 1 ; i >= 0 ; i -- ) { if ( ++ keyCounter > K ) { keyCounter = 1 ; keyPress ++ ; } result += freq [ i ] * keyPress ; } wr . println ( \" Case ▁ # \" + caseNumber + \" : ▁ \" + result ) ; System . out . println ( \" Case ▁ # \" + caseNumber + \" : ▁ \" + result ) ; } }", "package indy . codejam ; import java . io . * ; import java . text . DecimalFormat ; import java . text . DecimalFormatSymbols ; import java . util . * ; import java . math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; import static java . lang . Math . * ; import static java . lang . Double . parseDouble ; import static java . lang . Float . parseFloat ; import static java . lang . Long . parseLong ; import static java . lang . Integer . parseInt ; public class TextMessagingOutrage { public static void main ( String [ ] args ) throws Exception { String name = \" A - large \" ; String path = \" C : / codejam / \" ; Scanner sc = new Scanner ( new File ( path + name + \" . in \" ) ) ; PrintWriter pw = new PrintWriter ( path + name + \" . out \" ) ; int N = sc . nextInt ( ) ; for ( int z = 1 ; z <= N ; z ++ ) { int P = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; long [ ] f = new long [ L ] ; for ( int i = 0 ; i < L ; i ++ ) { f [ i ] = sc . nextLong ( ) ; } sort ( f ) ; long res = 0 ; for ( int i = 0 ; i < L ; i ++ ) { long r = i / K + 1 ; res += f [ L - 1 - i ] * r ; } pw . print ( \" Case ▁ # \" + z + \" : ▁ \" + res ) ; pw . println ( ) ; pw . flush ( ) ; } pw . close ( ) ; } }", "package gcj ; import java . io . BufferedReader ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class MainA { public static void reverse ( int [ ] p ) { int i = 0 , j = p . length - 1 ; while ( i < j ) { int a = p [ i ] ; p [ i ] = p [ j ] ; p [ j ] = a ; i ++ ; j -- ; } } public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader cin = new BufferedReader ( new InputStreamReader ( new FileInputStream ( \" D : \\\\ topcoder \\\\ eclipse - workspace \\\\ ACM \\\\ gcj \\\\ A - small . in \" ) ) ) ; PrintWriter out = new PrintWriter ( \" D : \\\\ topcoder \\\\ eclipse - workspace \\\\ ACM \\\\ gcj \\\\ Aout . txt \" ) ; int testcase = Integer . parseInt ( cin . readLine ( ) ) ; for ( int tst = 1 ; tst <= testcase ; tst ++ ) { int P , K , L ; StringTokenizer st = new StringTokenizer ( cin . readLine ( ) ) ; P = Integer . parseInt ( st . nextToken ( ) ) ; K = Integer . parseInt ( st . nextToken ( ) ) ; L = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] hits = new int [ L ] ; st = new StringTokenizer ( cin . readLine ( ) ) ; for ( int i = 0 ; i < L ; i ++ ) hits [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; Arrays . sort ( hits ) ; reverse ( hits ) ; long res = 0 ; for ( int i = 0 ; i < hits . length ; i ++ ) { res += ( i / K + 1 ) * hits [ i ] ; } out . println ( \" Case ▁ # \" + tst + \" : ▁ \" + res ) ; } out . close ( ) ; } }" ]
[ "import math NEW_LINE for case in range ( input ( ) ) : NEW_LINE INDENT P , K , L = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE V = sorted ( map ( int , raw_input ( ) . split ( ' ▁ ' ) ) , reverse = True ) NEW_LINE t = 0 NEW_LINE m = 1 NEW_LINE count = 0 NEW_LINE for i in V : NEW_LINE INDENT count += m * i NEW_LINE t += 1 NEW_LINE if t == K : NEW_LINE INDENT m += 1 NEW_LINE t = 0 NEW_LINE DEDENT DEDENT print ' Case ▁ # % s : ▁ % d ' % ( case + 1 , count ) NEW_LINE DEDENT", "def keys ( num_per_key , num_keys , num_letters , frequencies ) : NEW_LINE INDENT frequencies . sort ( ) NEW_LINE iterations = 0 NEW_LINE answer = 0 NEW_LINE while len ( frequencies ) > 0 and iterations < num_per_key : NEW_LINE INDENT iterations += 1 NEW_LINE for i in range ( 0 , min ( len ( frequencies ) , num_keys ) ) : NEW_LINE INDENT answer += frequencies . pop ( ) * iterations NEW_LINE DEDENT DEDENT if len ( frequencies ) > 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return answer NEW_LINE DEDENT DEDENT N = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT per , key , let = raw_input ( ) . split ( ' ▁ ' ) NEW_LINE freq = raw_input ( ) . split ( ' ▁ ' ) NEW_LINE freq = map ( int , freq ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i , keys ( int ( per ) , int ( key ) , int ( let ) , freq ) ) NEW_LINE DEDENT", "import sys NEW_LINE iFName = \" d : \\\\projekty\\\\google - jam\\unda - 1 - b\\\\a\\\\A - large . in \" NEW_LINE outFN = \" d : \\\\projekty\\\\google - jam\\unda - 1 - b\\\\a\\\\out - large . txt \" NEW_LINE verbose = False NEW_LINE iFile = open ( iFName , \" r \" ) NEW_LINE outF = open ( outFN , \" w \" ) NEW_LINE N = int ( iFile . readline ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if verbose : NEW_LINE INDENT print i NEW_LINE DEDENT S = iFile . readline ( ) NEW_LINE S = S . split ( ) NEW_LINE P = int ( S [ 0 ] ) NEW_LINE K = int ( S [ 1 ] ) NEW_LINE L = int ( S [ 2 ] ) NEW_LINE if verbose : NEW_LINE INDENT print P , K , L NEW_LINE DEDENT S = iFile . readline ( ) NEW_LINE if P * K < L : NEW_LINE INDENT totalCnt = - 1 NEW_LINE DEDENT else : NEW_LINE INDENT S = S . split ( ) NEW_LINE for j in range ( len ( S ) ) : NEW_LINE INDENT S [ j ] = long ( S [ j ] ) NEW_LINE DEDENT if verbose : NEW_LINE INDENT print S NEW_LINE DEDENT S . sort ( reverse = True ) NEW_LINE if verbose : NEW_LINE INDENT print S NEW_LINE DEDENT currCost = 1 NEW_LINE totalCnt = 0 NEW_LINE keysLeft = K NEW_LINE for s in S : NEW_LINE INDENT if keysLeft == 0 : NEW_LINE INDENT currCost = currCost + 1 NEW_LINE keysLeft = K NEW_LINE DEDENT totalCnt = totalCnt + s * currCost NEW_LINE keysLeft = keysLeft - 1 NEW_LINE DEDENT DEDENT if totalCnt == - 1 : NEW_LINE INDENT print >> outF , \" Case ▁ # % ( c ) d : ▁ Impossible \" % { ' c ' : i + 1 } NEW_LINE DEDENT else : NEW_LINE INDENT print >> outF , \" Case ▁ # % ( c ) d : ▁ % ( cnt ) d \" % { ' c ' : i + 1 , ' cnt ' : totalCnt } NEW_LINE DEDENT DEDENT iFile . close ( ) NEW_LINE outF . close ( ) NEW_LINE", "B = 1000000007 NEW_LINE def process_old ( seq ) : NEW_LINE INDENT table = [ ] NEW_LINE for i in xrange ( len ( seq ) ) : NEW_LINE INDENT num = 1 NEW_LINE for j in xrange ( i ) : NEW_LINE INDENT if seq [ j ] < seq [ i ] : num += table [ j ] NEW_LINE DEDENT table . append ( num % B ) NEW_LINE DEDENT return sum ( table ) % B NEW_LINE DEDENT def process ( seq ) : NEW_LINE INDENT invorder = range ( len ( seq ) ) NEW_LINE invorder . sort ( key = lambda i : seq [ i ] ) NEW_LINE order = [ None ] * len ( seq ) NEW_LINE for i in xrange ( len ( seq ) ) : order [ invorder [ i ] ] = i NEW_LINE table = [ ] NEW_LINE for i in xrange ( len ( seq ) ) : NEW_LINE INDENT num = 1 NEW_LINE for j in xrange ( i ) : NEW_LINE INDENT if seq [ j ] < seq [ i ] : num += table [ j ] NEW_LINE DEDENT table . append ( num % B ) NEW_LINE DEDENT return sum ( table ) % B NEW_LINE DEDENT import sys , time NEW_LINE next = iter ( sys . stdin ) . next NEW_LINE ncases = int ( next ( ) ) NEW_LINE for i in xrange ( ncases ) : NEW_LINE INDENT n , m , x , y , z = map ( int , next ( ) . split ( ) ) NEW_LINE seq = [ int ( next ( ) ) for j in xrange ( m ) ] NEW_LINE realseq = [ ] NEW_LINE for j in xrange ( n ) : NEW_LINE INDENT realseq . append ( seq [ j % m ] ) NEW_LINE seq [ j % m ] = int ( ( x * seq [ j % m ] + y * ( j + 1 ) ) % z ) NEW_LINE DEDENT numsubseqs = process ( realseq ) NEW_LINE print ' Case ▁ # % d : ▁ % d ' % ( i + 1 , numsubseqs ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT", "import sys NEW_LINE FILE_NAME = ' A - large ' NEW_LINE INPUT_FILE = FILE_NAME + ' . in ' NEW_LINE OUTPUT_FILE = FILE_NAME + ' . out ' NEW_LINE def process ( case , p , k , l , f ) : NEW_LINE INDENT slots = [ [ ] for i in range ( k ) ] NEW_LINE f . sort ( reverse = True ) NEW_LINE total = 0 NEW_LINE for i , cnt in enumerate ( f ) : NEW_LINE INDENT total = total + cnt * ( i / k + 1 ) NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , total ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT fp_in = open ( INPUT_FILE , ' r ' ) NEW_LINE fp_out = open ( OUTPUT_FILE , ' w ' ) NEW_LINE sys . stdin = fp_in NEW_LINE sys . stdout = fp_out NEW_LINE num_cases = int ( input ( ) ) NEW_LINE for case in range ( 1 , num_cases + 1 ) : NEW_LINE INDENT p , k , l = map ( int , raw_input ( ) . split ( ) ) NEW_LINE f = map ( int , raw_input ( ) . split ( ) ) NEW_LINE process ( case , p , k , l , f ) NEW_LINE DEDENT fp_in . close ( ) NEW_LINE fp_out . close ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_11_43
[ "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class C { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" input . txt \" ) ) ; PrintWriter out = new PrintWriter ( \" output . txt \" ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new C ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { long N = in . nextLong ( ) ; int m = 0 ; while ( 1l * m * m <= N ) m ++ ; boolean [ ] p = new boolean [ m ] ; Arrays . fill ( p , true ) ; int res = 0 ; for ( int x = 2 ; x < m ; x ++ ) { if ( p [ x ] ) { for ( int y = x + x ; y < m ; y += x ) { p [ y ] = false ; } int t = 0 ; long n = N ; while ( n >= x ) { n /= x ; t ++ ; } res += t - 1 ; } } if ( N > 1 ) res ++ ; return \" \" + res ; } }", "# include < math . h > # include < stdio . h > typedef unsigned int uint ; typedef long long ll ; bool primepow2 ( ll n ) { ll ubound = ( long long ) ceil ( sqrt ( ( long double ) n ) ) ; for ( ll i = 2 ; i <= ubound ; i ++ ) { if ( n % i == 0 ) { n /= i ; if ( n == 1 ) return false ; while ( n % i == 0 ) { n /= i ; } if ( n != 1 ) return false ; return true ; } } return false ; } int solve ( ) { long long n ; scanf ( \" % Ld \" , & n ) ; if ( n == 1 ) { return 0 ; } uint count = 1 ; for ( ll i = 2 ; i <= n ; i ++ ) { if ( primepow2 ( i ) ) count ++ ; } return count ; } int main ( ) { int c ; scanf ( \" % d \" , & c ) ; for ( int i = 0 ; i < c ; i ++ ) printf ( \" Case ▁ # % d : ▁ % d \\n \" , i + 1 , solve ( ) ) ; }", "import java . io . * ; import java . util . * ; public class Main { static StreamTokenizer in ; static long next ( ) throws Exception { in . nextToken ( ) ; return ( long ) in . nval ; } static PrintWriter out ; static String NAME = \" c \" ; public static void main ( String [ ] args ) throws Exception { out = new PrintWriter ( new File ( NAME + \" . out \" ) ) ; in = new StreamTokenizer ( new BufferedReader ( new FileReader ( new File ( NAME + \" . in \" ) ) ) ) ; int tests = ( int ) next ( ) ; int n = 1000005 ; int [ ] p = new int [ n ] ; boolean [ ] pr = new boolean [ n ] ; Arrays . fill ( pr , true ) ; pr [ 0 ] = pr [ 1 ] = false ; int ind = 0 ; for ( int i = 2 ; i < n ; i ++ ) if ( pr [ i ] ) { p [ ind ++ ] = i ; for ( int j = 2 * i ; j < n ; j += i ) pr [ j ] = false ; } for ( int test = 1 ; test <= tests ; test ++ ) { long k = next ( ) ; if ( k == 1 ) { out . println ( \" Case ▁ # \" + test + \" : ▁ 0\" ) ; continue ; } int answ = 1 ; for ( int i = 0 ; i < ind && p [ i ] <= k ; i ++ ) { long t = 1 ; answ -- ; while ( t * p [ i ] <= k ) { t *= p [ i ] ; answ ++ ; } } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + answ ) ; } out . close ( ) ; } }", "import static java . lang . Math . * ; import static java . math . BigInteger . * ; import static java . util . Arrays . * ; import java . io . * ; import java . math . * ; import java . util . * ; public class C { Scanner sc = new Scanner ( System . in ) ; int M = 1000010 ; void solve ( ) { long N = sc . nextLong ( ) ; if ( N == 1 ) { System . out . println ( 0 ) ; return ; } boolean [ ] isPrime = new boolean [ M ] ; for ( int i = 3 ; i < M ; i += 2 ) isPrime [ i ] = true ; isPrime [ 2 ] = true ; for ( int i = 3 ; i * i < M ; i += 2 ) if ( isPrime [ i ] ) { for ( int j = i * i , k = i * 2 ; j < M ; j += k ) { isPrime [ j ] = false ; } } long res = 1 ; for ( long i = 2 ; i * i <= N ; i ++ ) if ( isPrime [ ( int ) i ] ) { int num = 2 ; long j = i * i ; while ( j * i <= N ) { j *= i ; num ++ ; } res += num - 1 ; } System . out . println ( res ) ; } void run ( ) { int caseN = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseN ; caseID ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ \" , caseID ) ; solve ( ) ; System . out . flush ( ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { try { System . setIn ( new BufferedInputStream ( new FileInputStream ( args . length > 0 ? args [ 0 ] : ( C . class . getName ( ) + \" . in \" ) ) ) ) ; } catch ( Exception e ) { } new C ( ) . run ( ) ; } }", "import java . io . * ; import java . util . * ; public class ExpensiveDinner { void solve ( ) throws Exception { long n = nextLong ( ) ; if ( n == 1 ) { out . println ( 0 ) ; return ; } ArrayList < Long > primes = new ArrayList < Long > ( ) ; int sqrt = ( int ) Math . sqrt ( n ) + 10 ; boolean [ ] a = new boolean [ sqrt + 1 ] ; for ( int i = 2 ; i <= sqrt ; i ++ ) { if ( ! a [ i ] ) { primes . add ( ( long ) i ) ; for ( int j = 2 * i ; j <= sqrt ; j += i ) a [ j ] = true ; } } long ans1 = 0 ; long ans2 = 1 ; for ( long i : primes ) { if ( i > n ) break ; ans1 ++ ; long j = i ; while ( j <= n ) { ans2 ++ ; j *= i ; } } out . println ( ans2 - ans1 ) ; } void run ( ) { try { in = new BufferedReader ( new FileReader ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int tests = nextInt ( ) ; for ( int i = 0 ; i < tests ; i ++ ) { out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; solve ( ) ; } out . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } BufferedReader in ; StringTokenizer st ; PrintWriter out ; final String filename = new String ( \" ExpensiveDinner \" ) . toLowerCase ( ) ; String nextToken ( ) throws Exception { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( in . readLine ( ) ) ; return st . nextToken ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) throws Exception { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) throws Exception { return Double . parseDouble ( nextToken ( ) ) ; } public static void main ( String [ ] args ) { new ExpensiveDinner ( ) . run ( ) ; } }" ]
[ "from numpy import * NEW_LINE def Worst ( n ) : NEW_LINE INDENT Cost = 1 ; NEW_LINE Time = 1 ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if Cost == 0 or Cost % i != 0 : NEW_LINE INDENT k = Cost ; NEW_LINE while ( Cost % i != 0 ) : NEW_LINE INDENT Cost += k ; NEW_LINE DEDENT Time += 1 ; NEW_LINE DEDENT DEDENT return Time NEW_LINE DEDENT P = [ 2 ] ; NEW_LINE k = 3 ; NEW_LINE while ( k < 1000 ) : NEW_LINE INDENT isP = True ; NEW_LINE for p in P : NEW_LINE INDENT if k % p == 0 : NEW_LINE INDENT isP = False ; NEW_LINE DEDENT DEDENT if isP : NEW_LINE INDENT P . append ( k ) ; NEW_LINE DEDENT k += 2 ; NEW_LINE DEDENT def Best ( n ) : NEW_LINE INDENT Time = 0 ; NEW_LINE for p in P : NEW_LINE INDENT if p <= n : NEW_LINE INDENT Time += 1 ; NEW_LINE DEDENT DEDENT return Time NEW_LINE DEDENT T = int ( raw_input ( ) ) ; NEW_LINE for i in range ( T ) : NEW_LINE INDENT print \" Case ▁ # % d : \" % ( i + 1 ) , ; NEW_LINE N = int ( raw_input ( ) ) ; NEW_LINE Bad = Worst ( N ) ; NEW_LINE if N == 1 : NEW_LINE INDENT print 0 ; NEW_LINE DEDENT else : NEW_LINE INDENT print Worst ( N ) - Best ( N ) NEW_LINE DEDENT DEDENT", "def primelist ( N ) : NEW_LINE INDENT ps = [ 2 ] NEW_LINE cur = 3 NEW_LINE for cur in range ( 3 , N ) : NEW_LINE INDENT for prime in ps : NEW_LINE INDENT if prime * prime > cur : NEW_LINE INDENT ps . append ( cur ) NEW_LINE break NEW_LINE DEDENT if cur % prime == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return ps NEW_LINE DEDENT def run ( plist ) : NEW_LINE INDENT f = open ( \" input . in \" ) NEW_LINE g = open ( \" out . txt \" , ' w ' ) NEW_LINE num = int ( f . readline ( ) ) NEW_LINE for i in range ( num ) : NEW_LINE INDENT g . write ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) ) NEW_LINE n = int ( f . readline ( ) ) NEW_LINE times = [ ] NEW_LINE for p in plist : NEW_LINE INDENT if p ^ 2 > n : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE m = n / p NEW_LINE while m >= p : NEW_LINE INDENT m = m / p NEW_LINE count = count + 1 NEW_LINE DEDENT if count > 0 : NEW_LINE INDENT times . append ( count ) NEW_LINE DEDENT DEDENT DEDENT if times : NEW_LINE INDENT g . write ( \" % d \\n \" % ( sum ( times ) + 1 ) ) NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT g . write ( \"0 \\n \" ) NEW_LINE DEDENT else : NEW_LINE INDENT g . write ( \"1 \\n \" ) NEW_LINE DEDENT DEDENT f . close ( ) NEW_LINE g . close ( ) NEW_LINE DEDENT", "import sys NEW_LINE from fractions import gcd NEW_LINE import multiprocessing NEW_LINE cin = sys . stdin . readline NEW_LINE isp = [ 1 ] * 1000500 NEW_LINE isp [ 0 ] = isp [ 1 ] = 0 NEW_LINE LL = len ( isp ) NEW_LINE prims = [ ] NEW_LINE for i in xrange ( 2 , LL ) : NEW_LINE INDENT if not isp [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT prims . append ( i ) NEW_LINE j = i * i NEW_LINE while j < LL : NEW_LINE INDENT isp [ j ] = 0 NEW_LINE j += i NEW_LINE DEDENT DEDENT def solve ( N ) : NEW_LINE INDENT if ( N == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT pp = [ ] NEW_LINE high = 1 NEW_LINE for prim in prims : NEW_LINE INDENT if prim > N : NEW_LINE INDENT break NEW_LINE DEDENT p = 1 NEW_LINE q = prim NEW_LINE while q * prim <= N : NEW_LINE INDENT p += 1 NEW_LINE q *= prim NEW_LINE DEDENT high += p NEW_LINE pp . append ( q ) NEW_LINE DEDENT pp . sort ( ) NEW_LINE pp = pp [ : : - 1 ] NEW_LINE at = 0 NEW_LINE LE = len ( pp ) NEW_LINE while at < LE : NEW_LINE INDENT q = pp [ at ] NEW_LINE while at + 1 < LE and q * pp [ at + 1 ] <= N : NEW_LINE INDENT at += 1 NEW_LINE q *= pp [ at + 1 ] NEW_LINE DEDENT high -= 1 NEW_LINE at += 1 NEW_LINE DEDENT return high NEW_LINE DEDENT def procfunc ( tup ) : NEW_LINE INDENT x = solve ( * tup [ 1 : ] ) NEW_LINE print >> sys . stderr , \" SOLVE \" , tup [ 0 ] NEW_LINE return x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT T = int ( cin ( ) ) NEW_LINE inputs = [ ] NEW_LINE for cnum in xrange ( T ) : NEW_LINE INDENT N = int ( cin ( ) ) NEW_LINE inputs . append ( ( cnum , N ) ) NEW_LINE DEDENT if True : NEW_LINE INDENT pool = multiprocessing . Pool ( ) NEW_LINE output = pool . map_async ( procfunc , inputs , 1 ) . get ( 999999 ) NEW_LINE DEDENT else : NEW_LINE INDENT output = list ( procfunc ( x ) for x in inputs ) NEW_LINE DEDENT for i , out in enumerate ( output ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , out ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE from math import * NEW_LINE def lg ( a ) : NEW_LINE INDENT sys . stderr . write ( str ( a ) + \" \\n \" ) NEW_LINE DEDENT def sieve ( n ) : NEW_LINE INDENT sqrtn = int ( n ** 0.5 ) NEW_LINE sieve = [ True ] * ( n + 1 ) NEW_LINE sieve [ 0 ] = False NEW_LINE sieve [ 1 ] = False NEW_LINE for i in range ( 2 , sqrtn + 1 ) : NEW_LINE INDENT if sieve [ i ] : NEW_LINE INDENT m = n // i - i NEW_LINE sieve [ i * i : n + 1 : i ] = [ False ] * ( m + 1 ) NEW_LINE DEDENT DEDENT sieve = [ i for i in range ( n + 1 ) if sieve [ i ] ] NEW_LINE return sieve NEW_LINE DEDENT import math NEW_LINE s = sieve ( 1000001 ) NEW_LINE t = int ( sys . stdin . readline ( ) ) NEW_LINE for testNr in range ( 1 , t + 1 ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE sqrtn = int ( n ** 0.5 ) NEW_LINE print \" Case ▁ # % d : \" % testNr , NEW_LINE if n == 1 : NEW_LINE INDENT print 0 NEW_LINE continue NEW_LINE DEDENT sum = 1 NEW_LINE for p in s : NEW_LINE INDENT if p * p > n : NEW_LINE INDENT break NEW_LINE DEDENT q = p * p NEW_LINE while q <= n : NEW_LINE INDENT sum += 1 NEW_LINE q *= p NEW_LINE DEDENT DEDENT print sum NEW_LINE DEDENT", "def memoized ( func ) : NEW_LINE INDENT mem = { } NEW_LINE def wrapped ( * args ) : NEW_LINE INDENT if args not in mem : NEW_LINE INDENT mem [ args ] = func ( * args ) NEW_LINE DEDENT return mem [ args ] NEW_LINE DEDENT return wrapped NEW_LINE DEDENT TASK = \" C \" NEW_LINE print ( \" Precalculation . . . \" ) NEW_LINE import math NEW_LINE def isprime ( num , primes ) : NEW_LINE INDENT s = math . sqrt ( num ) NEW_LINE for p in primes : NEW_LINE INDENT if p > s : NEW_LINE INDENT return True NEW_LINE DEDENT if num % p == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT primes = [ ] NEW_LINE for i in xrange ( 2 , 10 ** 6 + 1 ) : NEW_LINE INDENT if isprime ( i , primes ) : NEW_LINE INDENT primes . append ( i ) NEW_LINE DEDENT DEDENT print ( \" Precalculation ▁ done . \" ) NEW_LINE print ( \" Calculation . . . \" ) NEW_LINE with open ( TASK + \" . in \" ) as infile : NEW_LINE INDENT with open ( TASK + \" . out \" , mode = \" wt \" ) as outfile : NEW_LINE INDENT cases = int ( infile . readline ( ) ) NEW_LINE for ncase in range ( cases ) : NEW_LINE INDENT N = int ( infile . readline ( ) ) NEW_LINE s = math . sqrt ( N ) NEW_LINE ans = 0 NEW_LINE for p in primes : NEW_LINE INDENT if p > s : break NEW_LINE ans += int ( math . log ( N , p ) ) - 1 NEW_LINE DEDENT if N > 1 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT outfile . write ( \" Case ▁ # { nc } : ▁ { data } \\n \" . format ( nc = ncase + 1 , data = ans ) ) NEW_LINE DEDENT DEDENT DEDENT print ( \" Calculation ▁ done . \" ) NEW_LINE" ]
codejam_14_33
[ "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . StringTokenizer ; public class Enclosure { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( new File ( \" in \" ) ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( new File ( \" out \" ) ) ) ; StringTokenizer st ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int cn = 1 ; cn <= T ; cn ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int M = Integer . parseInt ( st . nextToken ( ) ) ; int K = Integer . parseInt ( st . nextToken ( ) ) ; int ans = K ; for ( int i = 3 ; i <= N ; i ++ ) { for ( int j = 3 ; j <= M ; j ++ ) { int stones = 2 * ( i - 2 ) + 2 * ( j - 2 ) ; int covered = i * j - 4 ; if ( K <= covered ) ans = Math . min ( ans , stones ) ; for ( int k = 1 ; k <= 4 ; k ++ ) if ( K <= covered + k ) ans = Math . min ( ans , stones + k ) ; if ( i < N || j < M ) if ( K <= covered + 2 ) ans = Math . min ( ans , stones + 1 ) ; } } System . out . println ( N + \" ▁ \" + M + \" ▁ \" + K + \" ▁ \" + ans ) ; bw . append ( \" Case ▁ # \" + cn + \" : ▁ \" ) ; bw . append ( ans + \" \\n \" ) ; } bw . flush ( ) ; } }", "package codejam ; import java . io . * ; import java . util . Scanner ; public abstract class Task { protected abstract String getName ( ) ; protected abstract void runOne ( Scanner input , PrintWriter output ) ; void run ( InputStream input , OutputStream output ) { Scanner in = new Scanner ( input ) ; PrintWriter out = new PrintWriter ( output ) ; int testsCount = in . nextInt ( ) ; in . nextLine ( ) ; for ( int test = 1 ; test <= testsCount ; test ++ ) { System . out . println ( \" solving ▁ \" + test ) ; out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; runOne ( in , out ) ; out . flush ( ) ; } } public static void runConsole ( Task task ) { task . run ( System . in , System . out ) ; } public static void runSmall ( Task task , int num ) throws IOException { runFiles ( task , new File ( \" . / \" + task . getName ( ) + \" - small - attempt \" + num + \" . in \" ) , new File ( \" . / \" + task . getName ( ) + \" - small - attempt \" + num + \" . out \" ) ) ; } public static void runLarge ( Task task ) throws IOException { runFiles ( task , new File ( \" . / \" + task . getName ( ) + \" - large . in \" ) , new File ( \" . / \" + task . getName ( ) + \" - large . out \" ) ) ; } private static void runFiles ( Task task , File input , File output ) throws IOException { InputStream is = new BufferedInputStream ( new FileInputStream ( input ) ) ; OutputStream os = new BufferedOutputStream ( new FileOutputStream ( output ) ) ; task . run ( is , os ) ; is . close ( ) ; os . close ( ) ; } }", "import java . util . Scanner ; public class C2 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= cases ; caseNum ++ ) { int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; if ( N == 1 || M == 1 ) { System . out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + K ) ; continue ; } int answer = 2 * N + 2 * M - 4 ; for ( int stones = 2 * N + 2 * M - 5 ; stones > 0 ; stones -- ) { int newEnclosed = Math . max ( temp ( M , N , stones ) , temp ( N , M , stones ) ) ; if ( newEnclosed >= K ) { answer = stones ; } else { break ; } } System . out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + answer ) ; } } private static int temp ( int N , int M , int stones ) { int diff = 2 * N + 2 * M - 4 - stones ; int d1 = diff / 4 ; int d2 = ( diff + 1 ) / 4 ; int d3 = ( diff + 2 ) / 4 ; int d4 = ( diff + 3 ) / 4 ; int newEnclosed = 0 ; for ( int n = 0 ; n < N ; n ++ ) { for ( int m = 0 ; m < M ; m ++ ) { if ( n + m >= d1 && n + ( M - 1 - m ) >= d2 && ( N - 1 - n ) + ( M - 1 - m ) >= d3 && ( N - 1 - n ) + m >= d4 ) { newEnclosed ++ ; } } } return newEnclosed ; } }" ]
[ "import sys NEW_LINE iFile = open ( sys . argv [ 1 ] , \" r \" ) NEW_LINE size = int ( iFile . readline ( ) . strip ( ) ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT line = iFile . readline ( ) . strip ( ) . split ( ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE M = int ( line [ 1 ] ) NEW_LINE K = int ( line [ 2 ] ) NEW_LINE stones = 0 NEW_LINE if K <= 4 : NEW_LINE INDENT stones = K NEW_LINE DEDENT elif min ( N , M ) <= 2 : NEW_LINE INDENT stones = K NEW_LINE DEDENT elif min ( N , M ) == 3 : NEW_LINE INDENT enclosed = int ( ( K - 2 ) / 3 ) NEW_LINE enclosed = min ( enclosed , max ( N , M ) - 2 ) NEW_LINE stones = K - enclosed NEW_LINE DEDENT else : NEW_LINE INDENT if K < 8 : NEW_LINE INDENT enclosed = 1 NEW_LINE DEDENT elif K < 10 : NEW_LINE INDENT enclosed = 2 NEW_LINE DEDENT elif K < 12 : NEW_LINE INDENT enclosed = 3 NEW_LINE DEDENT elif K < 14 or max ( N , M ) == 4 : NEW_LINE INDENT enclosed = 4 NEW_LINE DEDENT elif K < 16 : NEW_LINE INDENT enclosed = 5 NEW_LINE DEDENT else : NEW_LINE INDENT enclosed = 6 NEW_LINE DEDENT stones = K - enclosed NEW_LINE DEDENT output = str ( stones ) NEW_LINE print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + output ) NEW_LINE DEDENT", "nR = int ( input ( ) ) NEW_LINE for run in range ( nR ) : NEW_LINE INDENT data = input ( ) . split ( ) NEW_LINE N = int ( data [ 0 ] ) NEW_LINE M = int ( data [ 1 ] ) NEW_LINE K = int ( data [ 2 ] ) NEW_LINE mini = K NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( 2 , M + 1 ) : NEW_LINE INDENT loss = 0 NEW_LINE rm = 0 NEW_LINE for k in range ( min ( i , j ) // 2 ) : NEW_LINE INDENT for m in range ( 5 ) : NEW_LINE INDENT if 2 * k == min ( i , j ) and m > 2 : NEW_LINE INDENT break NEW_LINE DEDENT if i * j - loss < K : NEW_LINE INDENT break NEW_LINE DEDENT if 2 * ( i + j ) - 4 - rm < mini : NEW_LINE INDENT mini = 2 * ( i + j ) - 4 - rm NEW_LINE DEDENT loss += ( k + 1 ) NEW_LINE rm += 1 NEW_LINE DEDENT if i * j - loss < K : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( \" Case ▁ # \" + str ( run + 1 ) + \" : ▁ \" + str ( mini ) ) NEW_LINE DEDENT", "N = None NEW_LINE M = None NEW_LINE K = None NEW_LINE def BT ( stone , inter , width , height ) : NEW_LINE INDENT global N NEW_LINE global M NEW_LINE global K NEW_LINE if inter >= K : NEW_LINE INDENT return stone NEW_LINE DEDENT ret = None NEW_LINE if K - inter <= 4 : NEW_LINE INDENT ret = stone + K - inter NEW_LINE DEDENT if width + 1 <= N : NEW_LINE INDENT if not ret : NEW_LINE INDENT ret = BT ( stone + 2 , inter + height / 2 + 2 , width + 1 , height ) NEW_LINE DEDENT else : NEW_LINE INDENT ret = min ( ret , BT ( stone + 2 , inter + height / 2 + 2 , width + 1 , height ) ) NEW_LINE DEDENT DEDENT if height + 1 <= M : NEW_LINE INDENT if not ret : NEW_LINE INDENT ret = BT ( stone + 2 , inter + width / 2 + 2 , width , height + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ret = min ( ret , BT ( stone + 2 , inter + width / 2 + 2 , width , height + 1 ) ) NEW_LINE DEDENT DEDENT if width + 1 <= N and height > 3 and inter + 2 >= K : NEW_LINE INDENT ret = min ( ret , stone + 1 ) NEW_LINE DEDENT if height + 1 <= M and width > 3 and inter + 2 >= K : NEW_LINE INDENT ret = min ( ret , stone + 1 ) NEW_LINE DEDENT return ret NEW_LINE DEDENT T = input ( ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , M , K = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE if N < 3 or M < 3 or K <= 4 : NEW_LINE INDENT print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( t + 1 , K ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( t + 1 , BT ( 4 , 5 , 3 , 3 ) ) NEW_LINE DEDENT DEDENT", "def reader ( inFile ) : NEW_LINE INDENT return tuple ( inFile . getInts ( ) ) NEW_LINE DEDENT from itertools import combinations NEW_LINE def solver ( ( N , M , K ) ) : NEW_LINE INDENT points = [ ( i , j ) for i in xrange ( N ) for j in xrange ( M ) ] NEW_LINE rec = 0 NEW_LINE for sets in combinations ( points , K ) : NEW_LINE INDENT v = set ( sets ) NEW_LINE scr = len ( [ z for z in v if len ( [ 1 for ( a , b ) in [ ( - 1 , 0 ) , ( 1 , 0 ) , ( 0 , - 1 ) , ( 0 , 1 ) ] if ( z [ 0 ] + a , z [ 1 ] + b ) in v ] ) == 4 ] ) NEW_LINE if scr > rec : NEW_LINE INDENT rec = scr NEW_LINE DEDENT DEDENT return K - rec NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , \" / Users / luke / gcj / 2014/1c / c \" , \" c \" ) . run ( ) NEW_LINE DEDENT", "from cmath import sqrt NEW_LINE import math NEW_LINE T = int ( input ( ) ) NEW_LINE test = 1 NEW_LINE while test <= T : NEW_LINE INDENT print ( \" Case ▁ # \" + str ( test ) + \" : ▁ \" , end = \" \" ) NEW_LINE test += 1 NEW_LINE mnk = input ( ) . split ( ) NEW_LINE m = int ( mnk [ 0 ] ) NEW_LINE n = int ( mnk [ 1 ] ) NEW_LINE k = int ( mnk [ 2 ] ) NEW_LINE if m > n : NEW_LINE INDENT tmp = n NEW_LINE n = m NEW_LINE m = tmp NEW_LINE DEDENT if m <= 2 : NEW_LINE INDENT print ( k ) NEW_LINE continue NEW_LINE DEDENT if m * n - k <= 4 : NEW_LINE INDENT print ( ( m + n - 4 ) * 2 - m * n + k + 4 ) NEW_LINE continue NEW_LINE DEDENT size = math . ceil ( sqrt ( k + 4 ) . real ) NEW_LINE w = 0 NEW_LINE if size > m : NEW_LINE INDENT w = m NEW_LINE DEDENT else : NEW_LINE INDENT w = size NEW_LINE DEDENT h = size - 1 NEW_LINE while w * h - 4 < k : NEW_LINE INDENT h += 1 NEW_LINE DEDENT ans = ( w + h - 4 ) * 2 NEW_LINE if h > w : NEW_LINE INDENT tmp = h NEW_LINE h = w NEW_LINE w = tmp NEW_LINE DEDENT if ( w * h - 4 ) - k >= 2 and m > 3 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT if ( w - 1 ) * h - 3 >= k : NEW_LINE INDENT ans = min ( ( w + h - 5 ) * 2 + 1 , ans ) NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT" ]
codejam_10_52
[ "import java . util . * ; import java . io . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { int tests ; Scanner scanner = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; tests = scanner . nextInt ( ) ; for ( int z = 1 ; z <= tests ; z ++ ) { BigInteger L = scanner . nextBigInteger ( ) ; int ile = scanner . nextInt ( ) ; Vector < Integer > roznice = new Vector < Integer > ( ) ; while ( ile -- > 0 ) { roznice . add ( scanner . nextInt ( ) ) ; } Collections . sort ( roznice ) ; int last = roznice . lastElement ( ) ; roznice . removeElement ( last ) ; Vector < Integer > minodl = new Vector < Integer > ( last ) ; minodl . setSize ( last ) ; for ( int i = 0 ; i < minodl . size ( ) ; i ++ ) minodl . setElementAt ( Integer . MAX_VALUE , i ) ; Queue < Integer > q = new LinkedList < Integer > ( ) ; minodl . setElementAt ( 0 , 0 ) ; q . add ( 0 ) ; while ( q . isEmpty ( ) == false ) { Integer x = q . remove ( ) ; for ( Integer i : roznice ) { int newx = x + i ; int odl = minodl . elementAt ( x ) + 1 ; while ( newx >= last ) { newx -= last ; odl -- ; } if ( minodl . elementAt ( newx ) > odl ) { minodl . setElementAt ( odl , newx ) ; q . add ( newx ) ; } } } System . out . printf ( \" Case ▁ # % d : ▁ \" , z ) ; BigInteger odleglosc = BigInteger . valueOf ( last ) ; BigInteger wynik = L . divide ( odleglosc ) ; Integer indeks = L . mod ( odleglosc ) . intValue ( ) ; BigInteger ileKoniec = BigInteger . valueOf ( minodl . elementAt ( indeks ) ) ; if ( ileKoniec . compareTo ( BigInteger . valueOf ( Integer . MAX_VALUE ) ) >= 0 ) { System . out . println ( \" IMPOSSIBLE \" ) ; } else { wynik = wynik . add ( ileKoniec ) ; System . out . println ( wynik ) ; } } } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class B { public void solve ( ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" B - small - attempt0 . in \" ) ) ; PrintWriter out = new PrintWriter ( \" B - small - attempt0 . out \" ) ; int testN = in . nextInt ( ) ; for ( int test = 1 ; test <= testN ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; long l = in . nextLong ( ) ; int k = in . nextInt ( ) ; int [ ] b = new int [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { b [ i ] = in . nextInt ( ) ; } Arrays . sort ( b ) ; int z = b [ b . length - 1 ] ; int [ ] a = new int [ z * z ] ; Arrays . fill ( a , Integer . MAX_VALUE ) ; a [ 0 ] = 0 ; for ( int i = 0 ; i < b . length ; i ++ ) { for ( int j = 0 ; j < a . length - b [ i ] ; j ++ ) { if ( a [ j ] != Integer . MAX_VALUE ) { a [ j + b [ i ] ] = Math . min ( a [ j + b [ i ] ] , a [ j ] + 1 ) ; } } } long ans = Long . MAX_VALUE ; for ( int i = 0 ; i < b . length ; i ++ ) { long u = ( l - z * z ) / b [ i ] + 1 ; int r = ( int ) ( l - u * b [ i ] ) ; if ( a [ r ] != Integer . MAX_VALUE ) { long v = u + a [ r ] ; if ( v < ans ) { ans = v ; } } } if ( ans == Long . MAX_VALUE ) { out . println ( \" IMPOSSIBLE \" ) ; } else { out . println ( ans ) ; } } in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new B ( ) . solve ( ) ; } }" ]
[ "import sys NEW_LINE b = [ ] NEW_LINE def calcb ( a ) : NEW_LINE INDENT res = [ ] NEW_LINE last = 0 NEW_LINE for i in range ( len ( a ) - 1 ) : NEW_LINE INDENT res . append ( last + a [ i ] * ( a [ i + 1 ] - 1 ) ) NEW_LINE last = res [ - 1 ] NEW_LINE DEDENT b [ : ] = res NEW_LINE DEDENT def foo ( ifile ) : NEW_LINE INDENT L , N = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] NEW_LINE a = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] NEW_LINE a . sort ( ) NEW_LINE calcb ( a ) NEW_LINE res = { } NEW_LINE res [ 0 ] = ( 0 , 0 ) NEW_LINE n = len ( a ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT res2 = { } NEW_LINE for k , v in res . iteritems ( ) : NEW_LINE INDENT for j in range ( v [ 1 ] , v [ 1 ] + a [ i + 1 ] ) : NEW_LINE INDENT t1 = k + a [ i ] * j NEW_LINE t2 = t1 // a [ i + 1 ] NEW_LINE t3 = t1 % a [ i + 1 ] NEW_LINE t4 = v [ 0 ] + j - t2 NEW_LINE t5 = ( t4 , t2 ) NEW_LINE if t3 not in res2 : NEW_LINE INDENT res2 [ t3 ] = t5 NEW_LINE DEDENT else : NEW_LINE INDENT res2 [ t3 ] = min ( res2 [ t3 ] , t5 ) NEW_LINE DEDENT DEDENT DEDENT res = res2 NEW_LINE DEDENT t = L % a [ - 1 ] NEW_LINE if t not in res : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT else : NEW_LINE INDENT return L // a [ - 1 ] + res [ t ] [ 0 ] NEW_LINE DEDENT DEDENT def main ( ifile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ' Case ▁ # % s : ▁ % s ' % ( i + 1 , foo ( ifile ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . stdin ) NEW_LINE DEDENT", "for casenum in xrange ( 1 , 1 + int ( raw_input ( ) ) ) : NEW_LINE INDENT [ L , N ] = [ int ( z ) for z in raw_input ( ) . split ( ) ] NEW_LINE Bs = [ int ( z ) for z in raw_input ( ) . split ( ) ] NEW_LINE maxB = max ( Bs ) NEW_LINE Bs = [ z for z in Bs if z != maxB ] NEW_LINE nu = [ 10 ** 200 ] * maxB NEW_LINE nu [ 0 ] = 0 NEW_LINE q = [ [ 0 , 0 ] ] NEW_LINE while ( len ( q ) > 0 ) : NEW_LINE INDENT qe = q [ 0 ] NEW_LINE q = q [ 1 : ] NEW_LINE if ( nu [ qe [ 0 ] ] == qe [ 1 ] ) : NEW_LINE INDENT for b in Bs : NEW_LINE INDENT if ( qe [ 0 ] + b < maxB ) : NEW_LINE INDENT qf = [ qe [ 0 ] + b , qe [ 1 ] + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT qf = [ qe [ 0 ] + b - maxB , qe [ 1 ] ] NEW_LINE DEDENT if qf [ 1 ] < nu [ qf [ 0 ] ] : NEW_LINE INDENT nu [ qf [ 0 ] ] = qf [ 1 ] NEW_LINE q += [ qf ] NEW_LINE DEDENT DEDENT DEDENT DEDENT if ( nu [ L % maxB ] != ( 10 ** 200 ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( casenum , nu [ L % maxB ] + ( L / maxB ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ IMPOSSIBLE \" % casenum NEW_LINE DEDENT DEDENT", "import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return [ foo ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE def run_test ( test ) : NEW_LINE INDENT global mem , a NEW_LINE ( L , N ) = readarray ( int ) NEW_LINE INF = L + 1 NEW_LINE a = readarray ( int ) NEW_LINE m = max ( a ) NEW_LINE dp = dict ( [ ( x , 1 ) for x in a ] ) NEW_LINE K = 50000 NEW_LINE for i in xrange ( K + 1000 ) : NEW_LINE INDENT r = dp [ i ] if i in dp else INF NEW_LINE for x in a : NEW_LINE INDENT if ( i - x ) in dp : NEW_LINE INDENT r = min ( r , dp [ i - x ] + 1 ) NEW_LINE DEDENT DEDENT if r < INF : NEW_LINE INDENT dp [ i ] = r NEW_LINE DEDENT DEDENT div = int ( ( L - K ) / m ) NEW_LINE res = div NEW_LINE left = L - div * m NEW_LINE return res + dp [ left ] if left in dp else \" IMPOSSIBLE \" NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( \" Test ▁ % d \\n \" % ( test + 1 ) ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( test + 1 , run_test ( test ) ) NEW_LINE DEDENT" ]
codejam_17_01
[ "import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; int testCount = Integer . parseInt ( in . next ( ) ) ; for ( int i = 1 ; i <= testCount ; i ++ ) solver . solve ( i , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , InputReader in , PrintWriter out ) { char [ ] s = in . next ( ) . toCharArray ( ) ; int k = in . nextInt ( ) ; int n = s . length ; int ret = 0 ; for ( int i = 0 ; i + k <= n ; i ++ ) { if ( s [ i ] == ' - ' ) { ++ ret ; for ( int j = 0 ; j < k ; j ++ ) { s [ i + j ] = ( char ) ( ' + ' + ' - ' - s [ i + j ] ) ; } } } out . printf ( \" Case ▁ # % d : ▁ \" , testNumber ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] != ' + ' ) { out . println ( \" IMPOSSIBLE \" ) ; return ; } } out . println ( ret ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }", "import java . util . * ; class A { static int solve ( ) { int [ ] str = in . next ( ) . chars ( ) . map ( ( i ) -> i == ' + ' ? 0 : 1 ) . toArray ( ) ; int size = in . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < str . length - size + 1 ; ++ i ) { if ( str [ i ] != 0 ) { count ++ ; for ( int j = i ; j < i + size ; ++ j ) { str [ j ] = str [ j ] == 1 ? 0 : 1 ; } } } for ( int i = str . length - size + 1 ; i < str . length ; ++ i ) { if ( str [ i ] != 0 ) return - 1 ; } return count ; } static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; ++ t ) { int c = solve ( ) ; System . out . printf ( \" Case ▁ # % d : ▁ % s % n \" , t + 1 , c >= 0 ? Integer . toString ( c ) : \" IMPOSSIBLE \" ) ; } } }", "package rayker . gcj2017 ; import java . io . PrintWriter ; import java . util . TreeSet ; import java . util . stream . Collectors ; public class Solver { public void solve ( InputReader in , PrintWriter out ) { int nTests = in . nextInt ( ) ; for ( int t = 1 ; t <= nTests ; t ++ ) { String v = in . next ( ) ; int k = in . nextInt ( ) ; print ( t , out , find ( v , k ) ) ; } } private long find ( String line , int k ) { Boolean [ ] b = line . chars ( ) . mapToObj ( c -> c == ' + ' ) . toArray ( Boolean [ ] :: new ) ; int count = 0 ; for ( int i = 0 ; i < b . length ; i ++ ) { if ( b [ i ] ) continue ; count ++ ; for ( int j = 0 ; j < k ; j ++ ) { if ( i + j >= b . length ) return - 1 ; b [ i + j ] = ! b [ i + j ] ; } } return count ; } private void print ( int t , PrintWriter out , long v ) { if ( v == - 1 ) { out . printf ( \" Case ▁ # % d : ▁ IMPOSSIBLE % n \" , t ) ; } else { out . printf ( \" Case ▁ # % d : ▁ % d % n \" , t , v ) ; } } }", "package com . company ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Main { private static Scanner scanner = new Scanner ( System . in ) ; static private void reDirect ( ) { try { FileInputStream fileInputStream = new FileInputStream ( \" A - large . in \" ) ; scanner = new Scanner ( fileInputStream ) ; PrintStream ps = new PrintStream ( new FileOutputStream ( \" a - out - large . txt \" ) ) ; System . setOut ( ps ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } } public static void main ( String [ ] args ) { reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { int ans = run ( ) ; System . out . println ( \" Case ▁ # \" + cas + \" : ▁ \" + ( ans < 0 ? \" IMPOSSIBLE \" : ans ) ) ; } } static private int run ( ) { String s = scanner . next ( ) ; int k = scanner . nextInt ( ) ; char [ ] arr = s . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == ' - ' ) { if ( i + k > arr . length ) { return - 1 ; } count ++ ; for ( int j = i ; j < i + k ; j ++ ) { arr [ j ] = ( arr [ j ] == ' + ' ? ' - ' : ' + ' ) ; } } } return count ; } }", "package qualifier ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . LinkedList ; import java . util . List ; import java . util . Scanner ; public class AOversizedPancakeFlipper { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ) { int tests = sc . nextInt ( ) ; outer : for ( int t = 1 ; t <= tests ; t ++ ) { char [ ] happyChars = sc . next ( ) . toCharArray ( ) ; int spatWidth = sc . nextInt ( ) ; boolean [ ] happy = new boolean [ happyChars . length ] ; for ( int x = 0 ; x < happy . length ; x ++ ) happy [ x ] = happyChars [ x ] == ' + ' ; List < Integer > flipPoints = new LinkedList < Integer > ( ) ; int flipCount = 0 ; boolean flipped = false ; for ( int x = 0 ; x <= happy . length - spatWidth ; x ++ ) { if ( ! flipPoints . isEmpty ( ) && flipPoints . get ( 0 ) == x ) { flipPoints . remove ( 0 ) ; flipped = ! flipped ; } boolean current = happy [ x ] != flipped ; if ( ! current ) { flipped = ! flipped ; flipCount ++ ; flipPoints . add ( x + spatWidth ) ; } } for ( int x = happy . length - spatWidth + 1 ; x < happy . length ; x ++ ) { if ( ! flipPoints . isEmpty ( ) && flipPoints . get ( 0 ) == x ) { flipPoints . remove ( 0 ) ; flipped = ! flipped ; } if ( happy [ x ] == flipped ) { System . out . printf ( \" Case ▁ # % d : ▁ IMPOSSIBLE % n \" , t ) ; continue outer ; } } System . out . printf ( \" Case ▁ # % d : ▁ % d % n \" , t , flipCount ) ; } } } }" ]
[ "import sys NEW_LINE if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT f = sys . stdin NEW_LINE if len ( sys . argv ) >= 2 : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE if fn != ' - ' : NEW_LINE INDENT f = open ( fn ) NEW_LINE DEDENT DEDENT T = int ( f . readline ( ) ) NEW_LINE for _T in xrange ( T ) : NEW_LINE INDENT s , K = f . readline ( ) . split ( ) NEW_LINE K = int ( K ) NEW_LINE l = [ c == ' + ' for c in s ] NEW_LINE flips = 0 NEW_LINE for i in xrange ( len ( s ) - K + 1 ) : NEW_LINE INDENT if not l [ i ] : NEW_LINE INDENT flips += 1 NEW_LINE for j in xrange ( i , i + K ) : NEW_LINE INDENT l [ j ] = not l [ j ] NEW_LINE DEDENT DEDENT DEDENT if not all ( l ) : NEW_LINE INDENT ans = \" IMPOSSIBLE \" NEW_LINE DEDENT else : NEW_LINE INDENT ans = flips NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % s \" % ( _T + 1 , ans ) NEW_LINE DEDENT DEDENT", "def solve ( pancake_str , k ) : NEW_LINE INDENT pancakes = list ( pancake_str ) NEW_LINE flip_count = 0 NEW_LINE for i in range ( len ( pancakes ) ) : NEW_LINE INDENT if pancakes [ i ] == ' - ' : NEW_LINE INDENT flip_count += 1 NEW_LINE for j in range ( i , i + k ) : NEW_LINE INDENT if j >= len ( pancakes ) : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT pancakes [ j ] = ' + ' if pancakes [ j ] == ' - ' else ' - ' NEW_LINE DEDENT DEDENT DEDENT return str ( flip_count ) NEW_LINE DEDENT case_count = input ( ) NEW_LINE for i in range ( 1 , case_count + 1 ) : NEW_LINE INDENT s , k = raw_input ( ) . split ( ' ▁ ' ) NEW_LINE k = int ( k ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( i , solve ( s , k ) ) NEW_LINE DEDENT", "import sys NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE def solve ( data , k ) : NEW_LINE INDENT l = len ( data ) NEW_LINE if l == k : NEW_LINE INDENT if data == [ \" + \" ] * k : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif data == [ \" - \" ] * k : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT if l < k : NEW_LINE INDENT if data == [ \" + \" ] * l : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT flips = 0 NEW_LINE if data [ 0 ] == ' - ' : NEW_LINE INDENT for i in range ( 0 , k ) : NEW_LINE INDENT if data [ i ] == \" + \" : NEW_LINE INDENT data [ i ] = \" - \" NEW_LINE DEDENT else : NEW_LINE INDENT data [ i ] = \" + \" NEW_LINE DEDENT DEDENT flips = 1 NEW_LINE DEDENT result = solve ( data [ 1 : ] , k ) NEW_LINE if result < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return result + flips NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT n , m = [ s for s in raw_input ( ) . split ( \" ▁ \" ) ] NEW_LINE data = list ( str ( n ) ) NEW_LINE k = int ( m ) NEW_LINE result = solve ( data , k ) NEW_LINE if result == - 1 : NEW_LINE INDENT result = \" IMPOSSIBLE \" NEW_LINE DEDENT print ( \" Case ▁ # { } : ▁ { } \" . format ( i , result ) ) NEW_LINE DEDENT", "import sys NEW_LINE import numpy as np NEW_LINE if len ( sys . argv ) != 2 : NEW_LINE INDENT print \" usage : ▁ . / a . py ▁ < input _ file _ name > \" NEW_LINE exit ( ) NEW_LINE DEDENT input_file_name = sys . argv [ 1 ] NEW_LINE if input_file_name [ - 3 : ] == \" . in \" : NEW_LINE INDENT output_file_name = input_file_name [ : - 3 ] + \" . out \" NEW_LINE DEDENT else : NEW_LINE INDENT output_file_name = input_file_name + \" . out \" NEW_LINE DEDENT results = [ ] NEW_LINE with open ( input_file_name , ' r ' ) as f : NEW_LINE INDENT T = int ( f . readline ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT line = f . readline ( ) NEW_LINE S , K = line . split ( ' ▁ ' ) NEW_LINE S = list ( S ) NEW_LINE K = int ( K ) NEW_LINE ret = 0 NEW_LINE for j in xrange ( len ( S ) - K + 1 ) : NEW_LINE INDENT if S [ j ] == ' - ' : NEW_LINE INDENT for k in xrange ( K ) : NEW_LINE INDENT if S [ j + k ] == ' - ' : NEW_LINE INDENT S [ j + k ] = ' + ' NEW_LINE DEDENT else : NEW_LINE INDENT S [ j + k ] = ' - ' NEW_LINE DEDENT DEDENT ret += 1 NEW_LINE DEDENT DEDENT ret = str ( ret ) NEW_LINE for s in S : NEW_LINE INDENT if s == ' - ' : NEW_LINE INDENT ret = ' IMPOSSIBLE ' NEW_LINE break NEW_LINE DEDENT DEDENT results . append ( ret ) NEW_LINE DEDENT DEDENT with open ( output_file_name , ' w ' ) as f : NEW_LINE INDENT for i in range ( len ( results ) ) : NEW_LINE INDENT output_string = \" Case ▁ # % d : ▁ % s \\n \" % ( i + 1 , results [ i ] ) NEW_LINE print output_string [ : - 1 ] NEW_LINE f . write ( output_string ) NEW_LINE DEDENT DEDENT", "for cas in xrange ( 1 , 1 + input ( ) ) : NEW_LINE INDENT s , k = raw_input ( ) . strip ( ) . split ( ) NEW_LINE k = int ( k ) NEW_LINE s = [ v != ' + ' for v in s ] NEW_LINE f = [ 0 ] * ( len ( s ) + 1 ) NEW_LINE m = 0 NEW_LINE for i in xrange ( len ( s ) ) : NEW_LINE INDENT if i + k <= len ( s ) and ( s [ i ] ^ f [ i ] ) : NEW_LINE INDENT f [ i ] ^= 1 NEW_LINE f [ i + k ] ^= 1 NEW_LINE m += 1 NEW_LINE DEDENT s [ i ] ^= f [ i ] NEW_LINE f [ i + 1 ] ^= f [ i ] NEW_LINE DEDENT print \" Case ▁ # % s : ▁ % s \" % ( cas , ' IMPOSSIBLE ' if any ( s ) else m ) NEW_LINE DEDENT" ]
codejam_16_31
[ "import java . util . * ; public class A { static Scanner in ; public static void main ( String [ ] args ) { in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . println ( \" Case ▁ # \" + C + \" : \" + solve ( ) ) ; } } public static String solve ( ) { String out = \" \" ; int n = in . nextInt ( ) ; int [ ] count = new int [ n ] ; int remaining = 0 ; for ( int i = 0 ; i < n ; i ++ ) { count [ i ] = in . nextInt ( ) ; remaining += count [ i ] ; } while ( remaining > 0 ) { out += \" ▁ \" ; int maxIdx = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ i ] > 0 && ( maxIdx == - 1 || count [ i ] > count [ maxIdx ] ) ) { maxIdx = i ; } } out += ( char ) ( maxIdx + ' A ' ) ; count [ maxIdx ] -- ; remaining -- ; if ( remaining <= 0 ) break ; maxIdx = - 1 ; int gT0 = 0 ; boolean tie = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ i ] > 0 ) { gT0 ++ ; } if ( count [ i ] > 0 && ( maxIdx == - 1 || count [ i ] > count [ maxIdx ] ) ) { maxIdx = i ; } else if ( count [ i ] > 0 && gT0 == 2 && count [ i ] == count [ maxIdx ] ) { tie = true ; } } boolean skip = tie && gT0 == 2 ; if ( ! skip ) { out += ( char ) ( maxIdx + ' A ' ) ; count [ maxIdx ] -- ; remaining -- ; } } return out ; } }", "import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { new Main ( ) ; } public Main ( ) throws IOException { Scanner sc = new Scanner ( new File ( \" A - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" A - large . out \" ) ) ; int amountOfTasks = sc . nextInt ( ) ; for ( int task = 1 ; task <= amountOfTasks ; task ++ ) { int amount = sc . nextInt ( ) ; int [ ] counts = new int [ amount ] ; int sum = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { counts [ i ] = sc . nextInt ( ) ; sum += counts [ i ] ; } String sol = \" \" ; if ( sum % 2 == 1 ) { int max1 = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { if ( counts [ i ] > counts [ max1 ] ) { max1 = i ; } } counts [ max1 ] -- ; char first = ( char ) ( max1 + ' A ' ) ; sol += first ; sum -- ; } while ( sum > 0 ) { int max1 = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { if ( counts [ i ] > counts [ max1 ] ) { max1 = i ; } } counts [ max1 ] -- ; int max2 = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { if ( counts [ i ] > counts [ max2 ] ) { max2 = i ; } } counts [ max2 ] -- ; char first = ( char ) ( max1 + ' A ' ) ; char second = ( char ) ( max2 + ' A ' ) ; if ( sol . length ( ) > 0 ) { sol += \" ▁ \" ; } sol += first ; sol += second ; sum -= 2 ; } String solution = \" Case ▁ # \" + task + \" : ▁ \" + sol ; System . out . println ( solution ) ; out . println ( solution ) ; } out . close ( ) ; sc . close ( ) ; } }", "package com . mavtushenko . Gcj1C ; import java . io . * ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class TaskA { public static void main ( String [ ] args ) { String fileName = \" A - large . in \" ; try ( BufferedReader br = new BufferedReader ( new FileReader ( fileName ) ) ) { try ( BufferedWriter bw = new BufferedWriter ( new FileWriter ( fileName + \" . out \" ) ) ) { int tests = Integer . valueOf ( br . readLine ( ) ) ; for ( int test = 1 ; test <= tests ; ++ test ) { int n = new Scanner ( br . readLine ( ) ) . nextInt ( ) ; Scanner scanner = new Scanner ( br . readLine ( ) ) ; int s [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) s [ i ] = scanner . nextInt ( ) ; bw . write ( \" Case ▁ # \" + test + \" : ▁ \" ) ; while ( true ) { int max = 0 ; for ( int ss : s ) max = Math . max ( max , ss ) ; if ( max == 0 ) break ; ArrayList < Integer > pos = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( s [ i ] == max ) pos . add ( i ) ; } int ps = pos . size ( ) ; if ( pos . size ( ) % 2 == 1 ) { ps -- ; int cur = pos . get ( pos . size ( ) - 1 ) ; s [ cur ] -- ; bw . write ( \" \" + ( char ) ( ' A ' + cur ) + \" ▁ \" ) ; } for ( int i = 0 ; i < ps ; i += 2 ) { int c1 = pos . get ( i ) ; int c2 = pos . get ( i + 1 ) ; s [ c1 ] -- ; s [ c2 ] -- ; bw . write ( \" \" + ( char ) ( ' A ' + c1 ) + ( char ) ( ' A ' + c2 ) + \" ▁ \" ) ; } } bw . write ( \" \\n \" ) ; } bw . close ( ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } }", "package Round1 ; import java . io . * ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" / Users / chao / Downloads / A - large . in \" ) ) ; FileWriter out = new FileWriter ( \" / Users / chao / Desktop / A - large . txt \" ) ; String s = in . readLine ( ) ; int m = Integer . parseInt ( s ) ; int [ ] a = new int [ 26 ] ; for ( int cases = 1 ; cases <= m ; cases ++ ) { int n = Integer . parseInt ( in . readLine ( ) ) ; int cnt = n ; String [ ] ss = in . readLine ( ) . split ( \" ▁ \" ) ; for ( int i = 0 ; i < ss . length ; i ++ ) { a [ i ] = Integer . parseInt ( ss [ i ] ) ; } out . write ( \" Case ▁ # \" + cases + \" : \" ) ; while ( cnt > 2 ) { int k = findMaxIndex ( a , n ) ; out . write ( \" ▁ \" + ( char ) ( ' A ' + k ) ) ; if ( -- a [ k ] == 0 ) cnt -- ; } while ( cnt > 0 ) { int k = findMaxIndex ( a , n ) ; out . write ( \" ▁ \" + ( char ) ( ' A ' + k ) ) ; if ( -- a [ k ] == 0 ) cnt -- ; k = findMaxIndex ( a , n ) ; out . write ( ( char ) ( ' A ' + k ) ) ; if ( -- a [ k ] == 0 ) cnt -- ; } out . write ( \" \\n \" ) ; } in . close ( ) ; out . flush ( ) ; out . close ( ) ; } private static int findMaxIndex ( int [ ] a , int n ) { int num = - 1 ; int k = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > num ) { num = a [ i ] ; k = i ; } } return k ; } }", "import java . util . * ; import java . io . * ; public class A { static int N ; static int ans ; public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { N = input . nextInt ( ) ; int [ ] nums = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { nums [ i ] = input . nextInt ( ) ; sum += nums [ i ] ; } List < String > steps = new ArrayList < String > ( ) ; while ( sum > 0 ) { String s = \" \" ; s += add ( nums , false ) ; s += add ( nums , true ) ; steps . add ( s ) ; sum -= s . length ( ) ; } System . out . printf ( \" Case ▁ # % d : \" , n + 1 ) ; for ( String s : steps ) System . out . print ( \" ▁ \" + s ) ; System . out . println ( ) ; } } static String add ( int [ ] nums , boolean check ) { int most = 0 ; for ( int i = 0 ; i < nums . length ; i ++ ) if ( nums [ i ] > nums [ most ] ) most = i ; nums [ most ] -- ; int sum = 0 ; for ( int num : nums ) sum += num ; if ( check ) for ( int num : nums ) if ( num > sum / 2 ) { nums [ most ] ++ ; return \" \" ; } return ( char ) ( ' A ' + most ) + \" \" ; } }" ]
[ "from __future__ import print_function NEW_LINE import numpy NEW_LINE import string NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT print ( \" Case ▁ # % d : \" % i , end = ' ' ) NEW_LINE n = int ( raw_input ( ) ) NEW_LINE p = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE while True : NEW_LINE INDENT pp = [ x for x in range ( len ( p ) ) if p [ x ] != 0 ] NEW_LINE if len ( pp ) == 0 : NEW_LINE INDENT break NEW_LINE DEDENT elif len ( pp ) == 2 and p [ pp [ 0 ] ] == p [ pp [ 1 ] ] : NEW_LINE INDENT print ( ' ▁ ' , end = ' ' ) NEW_LINE print ( string . uppercase [ pp [ 0 ] ] , end = ' ' ) NEW_LINE print ( string . uppercase [ pp [ 1 ] ] , end = ' ' ) NEW_LINE p [ pp [ 0 ] ] -= 1 NEW_LINE p [ pp [ 1 ] ] -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT q = numpy . argmax ( p ) NEW_LINE print ( ' ▁ ' , end = ' ' ) NEW_LINE print ( string . uppercase [ q ] , end = ' ' ) NEW_LINE p [ q ] -= 1 NEW_LINE DEDENT DEDENT print ( ' ' ) NEW_LINE DEDENT", "from sys import stdin NEW_LINE def each_case ( N , P ) : NEW_LINE INDENT max , max2 , argmax , argmax2 = - 1 , P [ 0 ] , 0 , 0 NEW_LINE for i , p in enumerate ( P ) : NEW_LINE INDENT if max < p : NEW_LINE INDENT max2 = max NEW_LINE max = p NEW_LINE argmax2 = argmax NEW_LINE argmax = i NEW_LINE DEDENT elif max2 < p : NEW_LINE INDENT max2 = p NEW_LINE argmax2 = i NEW_LINE DEDENT DEDENT max_party , max2_party = chr ( argmax + 65 ) , chr ( argmax2 + 65 ) NEW_LINE plan = [ ] NEW_LINE for i in xrange ( ( max - max2 ) / 2 ) : NEW_LINE INDENT plan . append ( max_party * 2 ) NEW_LINE DEDENT if ( max - max2 ) % 2 : NEW_LINE INDENT plan . append ( max_party ) NEW_LINE DEDENT for i , p in enumerate ( P ) : NEW_LINE INDENT if i != argmax and i != argmax2 : NEW_LINE INDENT plan . extend ( [ chr ( i + 65 ) ] * p ) NEW_LINE DEDENT DEDENT for i in xrange ( max2 ) : NEW_LINE INDENT plan . append ( max_party + max2_party ) NEW_LINE DEDENT return ' ▁ ' . join ( plan ) NEW_LINE DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( stdin . readline ( ) ) NEW_LINE P = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( t , each_case ( N , P ) ) NEW_LINE DEDENT", "f = ' a - sample . in ' NEW_LINE f = ' A - small - attempt0 . in ' NEW_LINE f = ' A - large . in ' NEW_LINE inp = map ( str . strip , list ( open ( f ) ) [ 1 : ] ) NEW_LINE let = lambda n : chr ( ord ( ' A ' ) + n - 1 ) NEW_LINE def solve ( vals ) : NEW_LINE INDENT vals = zip ( map ( int , vals ) , range ( 1 , len ( vals ) + 1 ) ) NEW_LINE vals . sort ( reverse = True ) NEW_LINE evac = ( vals [ 0 ] [ 0 ] - vals [ 1 ] [ 0 ] ) * [ let ( vals [ 0 ] [ 1 ] ) ] NEW_LINE evac += [ let ( p ) for x , p in vals [ 2 : ] for i in range ( x ) ] NEW_LINE evac += [ let ( vals [ 0 ] [ 1 ] ) + let ( vals [ 1 ] [ 1 ] ) ] * vals [ 1 ] [ 0 ] NEW_LINE return ' ▁ ' . join ( evac ) NEW_LINE DEDENT t = 1 NEW_LINE while inp : NEW_LINE INDENT N = int ( inp . pop ( 0 ) ) NEW_LINE vals = tuple ( inp . pop ( 0 ) . split ( ) ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( t , solve ( vals ) ) NEW_LINE t += 1 NEW_LINE DEDENT", "def executer_calcul ( entrees ) : NEW_LINE INDENT N = entrees [ 0 ] NEW_LINE parties = entrees [ 1 ] NEW_LINE Case = entrees [ 2 ] NEW_LINE result = ' ' NEW_LINE while ( sum ( parties ) > 0 ) : NEW_LINE INDENT evac1 = maximum ( parties ) NEW_LINE parties [ evac1 ] = parties [ evac1 ] - 1 NEW_LINE evac2 = maximum ( parties ) NEW_LINE if ( 2 * parties [ evac2 ] > sum ( parties ) ) : NEW_LINE INDENT parties [ evac2 ] = parties [ evac2 ] - 1 NEW_LINE result = result + ' ▁ ' + chr ( evac1 + 65 ) + chr ( evac2 + 65 ) NEW_LINE DEDENT else : NEW_LINE INDENT result = result + ' ▁ ' + chr ( evac1 + 65 ) NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT def maximum ( liste ) : NEW_LINE INDENT maximum = 0 NEW_LINE for i in range ( len ( liste ) ) : NEW_LINE INDENT if ( liste [ i ] > liste [ maximum ] ) : maximum = i NEW_LINE DEDENT return maximum NEW_LINE DEDENT multiprocessed = False NEW_LINE if ( multiprocessed ) : from multiprocessing import Pool NEW_LINE else : output = open ( ' Output . txt ' , ' w ' ) NEW_LINE if ( ( not multiprocessed ) or __name__ == ' _ _ main _ _ ' ) : NEW_LINE INDENT with open ( \" Input . txt \" , \" r \" ) as input : NEW_LINE INDENT lines = input . readlines ( ) NEW_LINE DEDENT T = int ( lines [ 0 ] ) NEW_LINE line = 1 NEW_LINE Case = 1 NEW_LINE calculs = [ ] NEW_LINE while ( line < len ( lines ) ) : NEW_LINE INDENT N = int ( lines [ line ] ) NEW_LINE line = line + 1 NEW_LINE parties = list ( map ( int , lines [ line ] . split ( ' ▁ ' ) ) ) NEW_LINE line = line + 1 NEW_LINE entrees = [ N , parties , Case ] NEW_LINE if ( not multiprocessed ) : output . write ( ' Case ▁ # ' + str ( Case ) + ' : ' + executer_calcul ( entrees ) + ' \\n ' ) NEW_LINE else : calculs . append ( entrees ) NEW_LINE Case = Case + 1 NEW_LINE DEDENT if ( multiprocessed ) : NEW_LINE INDENT pool = Pool ( 3 ) NEW_LINE results = pool . map ( executer_calcul , calculs ) NEW_LINE output = open ( ' Output . txt ' , ' w ' ) NEW_LINE for case in range ( len ( results ) ) : NEW_LINE INDENT output . write ( ' Case ▁ # ' + str ( case + 1 ) + ' : ▁ ' + results [ case ] + ' \\n ' ) NEW_LINE DEDENT DEDENT output . close ( ) NEW_LINE DEDENT", "import sys NEW_LINE def letter ( x ) : NEW_LINE INDENT return chr ( ord ( ' A ' ) + x ) NEW_LINE DEDENT def solve_test ( inp ) : NEW_LINE INDENT n = int ( inp . readline ( ) ) NEW_LINE ans = [ ] NEW_LINE counts = [ int ( x ) for x in inp . readline ( ) . split ( ) ] NEW_LINE total = sum ( counts ) NEW_LINE if total % 2 == 1 : NEW_LINE INDENT winner = counts . index ( max ( counts ) ) NEW_LINE ans . append ( letter ( winner ) ) NEW_LINE counts [ winner ] -= 1 NEW_LINE DEDENT while sum ( counts ) > 0 : NEW_LINE INDENT winner1 = counts . index ( max ( counts ) ) NEW_LINE counts [ winner1 ] -= 1 NEW_LINE winner2 = counts . index ( max ( counts ) ) NEW_LINE counts [ winner2 ] -= 1 NEW_LINE ans . append ( letter ( winner1 ) + letter ( winner2 ) ) NEW_LINE DEDENT return ' ▁ ' . join ( ans ) NEW_LINE DEDENT def solve_dumb ( inp ) : NEW_LINE INDENT return '1' NEW_LINE DEDENT inp = open ( sys . argv [ 1 ] ) NEW_LINE inp_dumb = open ( sys . argv [ 1 ] ) NEW_LINE out = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . out ' , ' w ' ) NEW_LINE out_dumb = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . dumb . out ' , ' w ' ) NEW_LINE n_tests = int ( inp . readline ( ) ) NEW_LINE for i in range ( n_tests ) : NEW_LINE INDENT ans = solve_test ( inp ) NEW_LINE print ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) + ans , file = out ) NEW_LINE ans_dumb = solve_dumb ( inp_dumb ) NEW_LINE print ( \" Case ▁ # % d : ▁ \" % ( i + 1 ) + ans_dumb , file = out_dumb ) NEW_LINE if ans != ans_dumb : NEW_LINE INDENT print ( ' Wrong ' , i + 1 , file = sys . stderr ) NEW_LINE DEDENT DEDENT out . close ( ) NEW_LINE" ]
codejam_12_41
[ "package gcj ; import java . util . * ; import java . io . * ; public class Swinging { final static String PROBLEM_NAME = \" swing \" ; final static String WORK_DIR = \" D : \\\\ Gcj\\ \\\" + PROBLEM_NAME + \" \\ \\\" ; static void preprocess ( ) { } void solve ( Scanner sc , PrintWriter pw ) { int N = sc . nextInt ( ) ; int [ ] dist = new int [ N ] ; int [ ] len = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { dist [ i ] = sc . nextInt ( ) ; len [ i ] = sc . nextInt ( ) ; } int D = sc . nextInt ( ) ; int [ ] maxH = new int [ N ] ; Arrays . fill ( maxH , - 1 ) ; maxH [ 0 ] = dist [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( maxH [ i ] == - 1 ) continue ; if ( D - dist [ i ] <= maxH [ i ] ) { pw . println ( \" YES \" ) ; return ; } for ( int j = i + 1 ; j < N ; j ++ ) if ( dist [ j ] - dist [ i ] <= maxH [ i ] ) maxH [ j ] = Math . max ( maxH [ j ] , Math . min ( len [ j ] , dist [ j ] - dist [ i ] ) ) ; } pw . println ( \" NO \" ) ; } public static void main ( String [ ] args ) throws Exception { preprocess ( ) ; Scanner sc = new Scanner ( new FileReader ( WORK_DIR + \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( WORK_DIR + \" output . txt \" ) ) ; int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { System . out . println ( \" Processing ▁ test ▁ case ▁ \" + ( caseNum + 1 ) ) ; pw . print ( \" Case ▁ # \" + ( caseNum + 1 ) + \" : ▁ \" ) ; new Swinging ( ) . solve ( sc , pw ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( A . class . getSimpleName ( ) + \" . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( A . class . getSimpleName ( ) + \" . out \" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new A ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; int [ ] d = new int [ n + 1 ] ; int [ ] l = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = in . nextInt ( ) ; l [ i ] = in . nextInt ( ) ; } d [ n ] = in . nextInt ( ) ; int [ ] z = new int [ n + 1 ] ; z [ 0 ] = d [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { z [ i ] = Math . min ( z [ i ] , l [ i ] ) ; for ( int j = i + 1 ; j <= n ; j ++ ) { if ( d [ j ] <= d [ i ] + z [ i ] ) { z [ j ] = Math . max ( z [ j ] , d [ j ] - d [ i ] ) ; } } } return z [ n ] > 0 ? \" YES \" : \" NO \" ; } }", "import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class A { Scanner in ; PrintWriter out ; void doit ( int tnum ) { int n = in . nextInt ( ) ; long [ ] d = new long [ n ] ; long [ ] l = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { d [ i ] = in . nextLong ( ) ; l [ i ] = in . nextLong ( ) ; } long D = in . nextLong ( ) ; long [ ] ans = new long [ n ] ; ans [ 0 ] = d [ 0 ] ; boolean ok = false ; for ( int i = 1 ; i < n ; ++ i ) ans [ i ] = - 1 ; for ( int i = 0 ; i < n ; ++ i ) { if ( D - d [ i ] <= ans [ i ] ) ok = true ; for ( int j = i + 1 ; j < n ; ++ j ) { if ( ( d [ j ] - d [ i ] ) <= ans [ i ] ) { long attempt = Math . min ( l [ j ] , d [ j ] - d [ i ] ) ; if ( ans [ j ] == - 1 ) ans [ j ] = attempt ; if ( ans [ j ] < attempt ) ans [ j ] = attempt ; } } } out . println ( \" Case ▁ # \" + tnum + \" : ▁ \" + ( ok ? \" YES \" : \" NO \" ) ) ; System . err . println ( \" Case ▁ # \" + tnum + \" : ▁ \" + ( ok ? \" YES \" : \" NO \" ) ) ; } public void doit ( ) throws IOException { out = new PrintWriter ( new FileOutputStream ( \" output . txt \" ) ) ; in = new Scanner ( new FileInputStream ( \" A - large . in \" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; ++ i ) { doit ( i + 1 ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new A ( ) . doit ( ) ; } }", "import java . util . Arrays ; import java . util . Scanner ; public class A { static int n ; static long [ ] D ; static long [ ] L ; static int [ ] P ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { n = in . nextInt ( ) ; D = new long [ n + 2 ] ; L = new long [ n + 2 ] ; P = new int [ n + 2 ] ; D [ 0 ] = 0 ; L [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { D [ i + 1 ] = in . nextLong ( ) ; L [ i + 1 ] = in . nextLong ( ) ; } D [ n + 1 ] = in . nextLong ( ) ; L [ n + 1 ] = 0 ; for ( int i = 0 ; i < n + 2 ; i ++ ) P [ i ] = n + 10 ; P [ 1 ] = 0 ; for ( int c = 1 ; c < n + 2 ; c ++ ) { if ( P [ c ] == n + 10 ) continue ; long my_len = Math . min ( L [ c ] , D [ c ] - D [ P [ c ] ] ) ; for ( int nxt = c + 1 ; nxt < n + 2 && D [ nxt ] - D [ c ] <= my_len ; nxt ++ ) { P [ nxt ] = Math . min ( P [ nxt ] , c ) ; } } System . out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , cas , P [ n + 1 ] == n + 10 ? \" NO \" : \" YES \" ) ; } } }", "import java . util . Arrays ; import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; static class Solver { int N ; int [ ] ds ; int [ ] ls ; int D ; boolean solve ( ) { N = sc . nextInt ( ) ; ds = new int [ N ] ; ls = new int [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { ds [ i ] = sc . nextInt ( ) ; ls [ i ] = sc . nextInt ( ) ; } D = sc . nextInt ( ) ; int [ ] reach = new int [ N ] ; Arrays . fill ( reach , - 1 ) ; if ( ds [ 0 ] > ls [ 0 ] ) return false ; reach [ 0 ] = ds [ 0 ] ; for ( int i = 0 ; i < N ; ++ i ) { if ( reach [ i ] < 0 ) continue ; if ( reach [ i ] >= D - ds [ i ] ) return true ; for ( int j = i + 1 ; j < N ; ++ j ) { if ( reach [ j ] >= 0 ) continue ; if ( ds [ j ] > ds [ i ] + reach [ i ] ) break ; reach [ j ] = Math . min ( ds [ j ] - ds [ i ] , ls [ j ] ) ; } } return false ; } } public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; Solver solver = new Solver ( ) ; System . out . println ( solver . solve ( ) ? \" YES \" : \" NO \" ) ; } } }" ]
[ "import heapq NEW_LINE for test_case in xrange ( 1 , int ( raw_input ( ) ) + 1 ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE D = [ 0 ] * ( N + 1 ) NEW_LINE L = [ 0 ] * ( N + 1 ) NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT D [ i ] , L [ i ] = map ( int , raw_input ( ) . split ( ) ) NEW_LINE DEDENT D [ N ] = int ( raw_input ( ) ) NEW_LINE earliest = [ - 1 ] * ( N + 1 ) NEW_LINE earliest [ 0 ] = 0 NEW_LINE heap = [ ] NEW_LINE heapq . heappush ( heap , ( D [ 0 ] , D [ 0 ] + min ( D [ 0 ] - earliest [ 0 ] , L [ 0 ] ) ) ) NEW_LINE for i in xrange ( 1 , N + 1 ) : NEW_LINE INDENT while heap and heap [ 0 ] [ 1 ] < D [ i ] : NEW_LINE INDENT heapq . heappop ( heap ) NEW_LINE DEDENT if heap : NEW_LINE INDENT earliest [ i ] = heap [ 0 ] [ 0 ] NEW_LINE heapq . heappush ( heap , ( D [ i ] , D [ i ] + min ( D [ i ] - earliest [ i ] , L [ i ] ) ) ) NEW_LINE DEDENT DEDENT print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( test_case , \" YES \" if earliest [ N ] != - 1 else \" NO \" ) NEW_LINE DEDENT", "import sys NEW_LINE if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT f = sys . stdin NEW_LINE if len ( sys . argv ) >= 2 : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE if fn != ' - ' : NEW_LINE INDENT f = open ( fn ) NEW_LINE DEDENT DEDENT t = int ( f . readline ( ) ) NEW_LINE for _t in xrange ( t ) : NEW_LINE INDENT n = int ( f . readline ( ) ) NEW_LINE dists = [ ] NEW_LINE lengths = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT d , l = map ( int , f . readline ( ) . split ( ) ) NEW_LINE dists . append ( d ) NEW_LINE lengths . append ( l ) NEW_LINE DEDENT D = int ( f . readline ( ) ) NEW_LINE dists . append ( D ) NEW_LINE lengths . append ( 0 ) NEW_LINE n += 1 NEW_LINE max_swing = [ - 1 ] * n NEW_LINE assert lengths [ 0 ] >= dists [ 0 ] NEW_LINE max_swing [ 0 ] = dists [ 0 ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT for j in xrange ( i + 1 , n ) : NEW_LINE INDENT if dists [ j ] - dists [ i ] > max_swing [ i ] : NEW_LINE INDENT break NEW_LINE DEDENT swing = min ( lengths [ j ] , dists [ j ] - dists [ i ] ) NEW_LINE max_swing [ j ] = max ( max_swing [ j ] , swing ) NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % s \" % ( _t + 1 , \" NO \" if max_swing [ - 1 ] == - 1 else \" YES \" ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE def get_ints ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield int ( word ) NEW_LINE DEDENT DEDENT return NEW_LINE DEDENT ints = get_ints ( ) NEW_LINE def get_floats ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield float ( word ) NEW_LINE DEDENT DEDENT return NEW_LINE DEDENT floats = get_floats ( ) NEW_LINE def up ( a ) : NEW_LINE INDENT i = 1 NEW_LINE while i < a : NEW_LINE INDENT i *= 2 NEW_LINE DEDENT return 2 * i NEW_LINE DEDENT T = next ( ints ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT def solve ( ) : NEW_LINE INDENT N = next ( ints ) NEW_LINE D = ( N + 1 ) * [ 0 ] NEW_LINE L = ( N + 1 ) * [ 0 ] NEW_LINE K = ( N + 1 ) * [ 0 ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT D [ i ] = next ( ints ) NEW_LINE L [ i ] = next ( ints ) NEW_LINE DEDENT D [ N ] = next ( ints ) NEW_LINE K [ 0 ] = D [ 0 ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT j = i + 1 NEW_LINE while j <= N and D [ j ] - D [ i ] <= K [ i ] : NEW_LINE INDENT if j == N : return True NEW_LINE K [ j ] = max ( K [ j ] , min ( D [ j ] - D [ i ] , L [ j ] ) ) NEW_LINE j += 1 NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if solve ( ) : NEW_LINE INDENT print ( \" Case ▁ # \" , t + 1 , \" : ▁ YES \" , sep = ' ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" Case ▁ # \" , t + 1 , \" : ▁ NO \" , sep = ' ' ) NEW_LINE DEDENT DEDENT", "rl = lambda : map ( int , raw_input ( ) . split ( ) ) NEW_LINE def solve ( ) : NEW_LINE INDENT n = input ( ) NEW_LINE a = [ rl ( ) for _ in xrange ( n ) ] NEW_LINE d , l = zip ( * a ) NEW_LINE D = input ( ) NEW_LINE s = [ 100000000 ] * n NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT r = D - d [ i ] NEW_LINE if r > l [ i ] : continue NEW_LINE s [ i ] = r NEW_LINE DEDENT for i in xrange ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT for j in xrange ( i + 1 , n ) : NEW_LINE INDENT if s [ j ] > l [ j ] : continue NEW_LINE dd = d [ j ] - d [ i ] NEW_LINE if dd > l [ i ] : break NEW_LINE if dd < s [ j ] : continue NEW_LINE s [ i ] = min ( s [ i ] , dd ) NEW_LINE DEDENT DEDENT return \" YES \" if s [ 0 ] <= d [ 0 ] else \" NO \" NEW_LINE DEDENT t = input ( ) NEW_LINE for i in xrange ( t ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , solve ( ) ) NEW_LINE DEDENT", "import sys NEW_LINE import logging NEW_LINE if len ( sys . argv ) > 1 : NEW_LINE INDENT sampledata = False NEW_LINE infname = sys . argv [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT sampledata = True NEW_LINE scriptname = sys . argv [ 0 ] NEW_LINE problemletter = scriptname [ : scriptname . index ( ' . ' ) ] NEW_LINE infname = problemletter + ' - example . in ' NEW_LINE DEDENT outfname = infname [ : infname . index ( ' . ' ) ] + ' . out ' NEW_LINE with open ( infname ) as f : NEW_LINE INDENT text = f . read ( ) NEW_LINE DEDENT lines = text . splitlines ( ) NEW_LINE linesiter = iter ( lines ) NEW_LINE nextline = linesiter . next NEW_LINE ofile = open ( outfname , ' w ' ) NEW_LINE sys . stdout = ofile NEW_LINE T = int ( nextline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( nextline ( ) ) NEW_LINE vs = [ map ( int , nextline ( ) . split ( ) ) + [ 0 ] for _ in xrange ( N ) ] NEW_LINE dst = int ( nextline ( ) ) NEW_LINE reach = 0 NEW_LINE vs [ 0 ] [ 2 ] = vs [ 0 ] [ 0 ] NEW_LINE while vs : NEW_LINE INDENT v = vs . pop ( 0 ) NEW_LINE l = min ( v [ 1 ] , v [ 2 ] ) NEW_LINE reach = max ( reach , v [ 0 ] + l ) NEW_LINE for ov in vs : NEW_LINE INDENT if ov [ 0 ] <= v [ 0 ] + l : NEW_LINE INDENT ov [ 2 ] = max ( ov [ 2 ] , ov [ 0 ] - v [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print ' Case ▁ # % s : ' % t , ' YES ' if reach >= dst else ' NO ' NEW_LINE DEDENT sys . stdout = sys . __stdout__ NEW_LINE ofile . close ( ) NEW_LINE if sampledata : NEW_LINE INDENT base = problemletter + ' - example . ' NEW_LINE outfile = base + ' out ' NEW_LINE rightfile = base + ' right ' NEW_LINE out = open ( outfile ) . read ( ) NEW_LINE right = open ( rightfile ) . read ( ) NEW_LINE if out == right : NEW_LINE INDENT print ' Congrats , ▁ your ▁ output ▁ matches ▁ sample ▁ output ' NEW_LINE DEDENT else : NEW_LINE INDENT print ' OUTPUT ▁ MISMATCH ' NEW_LINE import os NEW_LINE os . system ( ' diff ▁ % s ▁ % s ' % ( outfile , rightfile ) ) NEW_LINE DEDENT DEDENT" ]
codejam_12_23
[ "package round1 ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Kattio extends PrintWriter { public Kattio ( InputStream i ) { super ( new BufferedOutputStream ( System . out ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public Kattio ( InputStream i , OutputStream o ) { super ( new BufferedOutputStream ( o ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public boolean hasMoreTokens ( ) { return peekToken ( ) != null ; } public int getInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public double getDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } public long getLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } public String getWord ( ) { return nextToken ( ) ; } private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken ( ) { if ( token == null ) try { while ( st == null || ! st . hasMoreTokens ( ) ) { line = r . readLine ( ) ; if ( line == null ) return null ; st = new StringTokenizer ( line ) ; } token = st . nextToken ( ) ; } catch ( IOException e ) { } return token ; } private String nextToken ( ) { String ans = peekToken ( ) ; token = null ; return ans ; } }", "import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . HashMap ; import java . util . Map ; import java . util . Random ; import java . util . Scanner ; public class EqualSums2 { public static void main ( final String ... args ) throws IOException { final String fname = \" C - large \" ; final Scanner sc = new Scanner ( new File ( fname + \" . in \" ) ) ; final PrintWriter pw = new PrintWriter ( fname + \" . out \" ) ; final int t = sc . nextInt ( ) ; for ( int i = 1 ; i <= t ; ++ i ) { System . out . println ( i ) ; final int n = sc . nextInt ( ) ; final long [ ] a = new long [ n ] ; for ( int j = 0 ; j < n ; ++ j ) { a [ j ] = sc . nextLong ( ) ; } final Random rnd = new Random ( ) ; final Map < Long , Long > m = new HashMap < Long , Long > ( ) ; long s1 = - 1 ; long s2 = - 1 ; while ( true ) { long j = rnd . nextLong ( ) ; if ( j < 0 ) { continue ; } long x = j ; int k = 0 ; long s = 0 ; while ( x > 0 ) { if ( ( x & 1 ) != 0 ) { s += a [ k ] ; } x >>= 1 ; ++ k ; } final Long b = m . get ( s ) ; if ( b == null ) { m . put ( s , j ) ; } else if ( b != j ) { s1 = b ; s2 = j ; break ; } } pw . println ( \" Case ▁ # \" + i + \" : \" ) ; int k = 0 ; while ( s1 > 0 ) { if ( ( s1 & 1 ) != 0 ) { pw . print ( a [ k ] + \" ▁ \" ) ; } s1 >>= 1 ; ++ k ; } pw . println ( ) ; k = 0 ; while ( s2 > 0 ) { if ( ( s2 & 1 ) != 0 ) { pw . print ( a [ k ] + \" ▁ \" ) ; } s2 >>= 1 ; ++ k ; } pw . println ( ) ; } pw . close ( ) ; } }", "import java . io . * ; import java . util . * ; public class C implements Runnable { private final int MAX_VALUE = 100000 * 20 + 10 ; private String IFILE = \" C - small - attempt0 . in \" ; private Scanner in ; private PrintWriter out ; public void Run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int ntest = in . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { out . println ( \" Case ▁ # \" + test + \" : \" ) ; int n = in . nextInt ( ) ; int [ ] mas = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) mas [ i ] = in . nextInt ( ) ; Arrays . sort ( mas ) ; int [ ] f = new int [ MAX_VALUE ] ; Arrays . fill ( f , - 1 ) ; f [ 0 ] = 0 ; boolean ok = false ; for ( int i = 0 ; i < n ; i ++ ) { for ( int d = MAX_VALUE - 1 ; d >= 0 ; d -- ) { if ( f [ d ] == - 1 ) continue ; int dd = d + mas [ i ] ; if ( f [ dd ] != - 1 ) { ok = true ; int z = dd ; while ( z != 0 ) { if ( z != dd ) out . print ( \" ▁ \" ) ; out . print ( mas [ f [ z ] ] ) ; z -= mas [ f [ z ] ] ; } out . println ( ) ; out . print ( mas [ i ] ) ; z = d ; while ( z != 0 ) { out . print ( \" ▁ \" + mas [ f [ z ] ] ) ; z -= mas [ f [ z ] ] ; } out . println ( ) ; break ; } else f [ dd ] = i ; } if ( ok ) break ; } if ( ! ok ) out . println ( \" Impossible \" ) ; } in . close ( ) ; out . close ( ) ; } public void run ( ) { try { Run ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) throws IOException { new C ( ) . Run ( ) ; } }" ]
[ "import sys NEW_LINE from itertools import * NEW_LINE def allThe ( S ) : NEW_LINE INDENT yield set ( ) , set ( ) , S NEW_LINE for s in S : NEW_LINE INDENT SS = S - set ( [ s ] ) NEW_LINE for A , B , rem in allThe ( SS ) : NEW_LINE INDENT yield A | set ( [ s ] ) , B , rem NEW_LINE yield A , B | set ( [ s ] ) , rem NEW_LINE DEDENT DEDENT DEDENT def formatted ( A , B ) : NEW_LINE INDENT return ' \\n ' + ' ▁ ' . join ( map ( str , A ) ) + ' \\n ' + ' ▁ ' . join ( map ( str , B ) ) NEW_LINE DEDENT def solve ( S ) : NEW_LINE INDENT allSums = { } NEW_LINE for i in range ( 1 , len ( S ) ) : NEW_LINE INDENT for SS in combinations ( S , i ) : NEW_LINE INDENT ss = sum ( SS ) NEW_LINE if ss in allSums : NEW_LINE INDENT return formatted ( list ( SS ) , allSums [ ss ] ) NEW_LINE DEDENT allSums [ ss ] = list ( SS ) NEW_LINE DEDENT DEDENT return ' \\n Impossible ' NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT s = set ( int ( s ) for s in raw_input ( ) . split ( ' ▁ ' ) [ 1 : ] ) NEW_LINE print \" Case ▁ # % i : ▁ % s \" % ( i + 1 , solve ( s ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT", "class Solver ( object ) : NEW_LINE INDENT @ classmethod NEW_LINE def setup ( cls , infile ) : NEW_LINE INDENT cls . data = { } NEW_LINE DEDENT def __init__ ( self , infile , tc ) : NEW_LINE INDENT self . tc = tc NEW_LINE self . I = I = map ( int , infile . next ( ) . split ( ) ) NEW_LINE DEDENT def solve ( self ) : NEW_LINE INDENT import itertools as it NEW_LINE S = self . I [ 1 : ] NEW_LINE seen = { } NEW_LINE for n in xrange ( 1 , 4 ) : NEW_LINE INDENT for s in it . combinations ( S , n ) : NEW_LINE INDENT ss = sum ( s ) NEW_LINE if ss in seen : NEW_LINE INDENT return ' Case ▁ # % s : \\n % s \\n % s \\n ' % ( self . tc , ' ▁ ' . join ( ' % d ' % i for i in s ) , ' ▁ ' . join ( ' % d ' % i for i in seen [ ss ] ) , ) NEW_LINE DEDENT seen [ ss ] = s NEW_LINE DEDENT DEDENT return ' Case ▁ # % s : ▁ Impossible \\n ' % ( self . tc , ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE T = int ( sys . stdin . next ( ) ) NEW_LINE Solver . setup ( sys . stdin ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT sys . stdout . write ( Solver ( sys . stdin , t ) . solve ( ) ) NEW_LINE DEDENT DEDENT", "from itertools import combinations NEW_LINE from random import randint NEW_LINE from collections import defaultdict NEW_LINE from time import time NEW_LINE def solve ( numbers ) : NEW_LINE INDENT nnum = len ( numbers ) NEW_LINE sums = defaultdict ( list ) NEW_LINE t0 = time ( ) NEW_LINE for i in range ( 2 , nnum ) : NEW_LINE INDENT for subset in combinations ( numbers , i ) : NEW_LINE INDENT if time ( ) - t0 > 30 : return None NEW_LINE s = set ( subset ) NEW_LINE s_sum = sum ( s ) NEW_LINE for other in sums [ s_sum ] : NEW_LINE INDENT if len ( s & other ) == 0 : NEW_LINE INDENT return s , other NEW_LINE DEDENT DEDENT sums [ s_sum ] . append ( s ) NEW_LINE DEDENT DEDENT return None NEW_LINE DEDENT def test ( ) : NEW_LINE INDENT nums = set ( ) NEW_LINE while len ( nums ) < 500 : NEW_LINE INDENT draw = 500 - len ( nums ) NEW_LINE [ nums . add ( randint ( 1 , 10 ** 12 ) ) for i in range ( draw ) ] NEW_LINE DEDENT result = solve ( nums ) NEW_LINE print result NEW_LINE print sum ( result [ 0 ] ) , sum ( result [ 1 ] ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT import sys NEW_LINE data = file ( sys . argv [ 1 ] + ' . in ' ) . readlines ( ) NEW_LINE with open ( sys . argv [ 1 ] + ' . out ' , ' w ' ) as out : NEW_LINE INDENT for i , line in enumerate ( data [ 1 : ] ) : NEW_LINE INDENT nums = map ( int , line . strip ( ) . split ( ) ) NEW_LINE answer = solve ( nums [ 1 : ] ) NEW_LINE if answer is not None : NEW_LINE INDENT a1 = ' ▁ ' . join ( map ( str , answer [ 0 ] ) ) NEW_LINE a2 = ' ▁ ' . join ( map ( str , answer [ 1 ] ) ) NEW_LINE response = \" Case ▁ # % i : \\n % s \\n % s \\n \" % ( i + 1 , a1 , a2 ) NEW_LINE DEDENT else : NEW_LINE INDENT response = \" Case ▁ # % i : \\n Impossible \\n \" % ( i + 1 ) NEW_LINE DEDENT print response NEW_LINE out . write ( response ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE NEW_LINE DEDENT", "import sys , math , time , itertools NEW_LINE filename = \" C \" NEW_LINE inputFilename = filename + \" - large . in \" NEW_LINE outputFilename = filename + \" . txt \" NEW_LINE inputFile = open ( inputFilename , \" r \" ) NEW_LINE outputFile = open ( outputFilename , \" w \" ) NEW_LINE startTime = time . time ( ) NEW_LINE testcases = int ( inputFile . readline ( ) ) NEW_LINE for testcase in range ( testcases ) : NEW_LINE INDENT outputStringHeader = \" Case ▁ # \" + str ( testcase + 1 ) + \" : \\n \" NEW_LINE outputFile . write ( outputStringHeader ) NEW_LINE print \" Case ▁ # \" , str ( testcase + 1 ) + \" : ▁ \" NEW_LINE inputList = map ( int , inputFile . readline ( ) . split ( ) ) NEW_LINE inputList = inputList [ 1 : ] NEW_LINE sums = { } NEW_LINE solutionKey = None NEW_LINE for i in range ( 1 , 151 ) : NEW_LINE INDENT subsets = list ( itertools . combinations ( inputList , i ) ) NEW_LINE for subset in subsets : NEW_LINE INDENT sumOfSet = sum ( subset ) NEW_LINE if sumOfSet in sums : NEW_LINE INDENT sums [ sumOfSet ] . append ( subset ) NEW_LINE solutionKey = sumOfSet NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT sums [ sumOfSet ] = [ subset ] NEW_LINE DEDENT DEDENT if solutionKey : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if solutionKey : NEW_LINE INDENT for subset in sums [ solutionKey ] : NEW_LINE INDENT for value in subset : NEW_LINE INDENT outputFile . write ( \" % d ▁ \" % value ) NEW_LINE DEDENT outputFile . write ( \" \\n \" ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT outputFile . write ( \" Impossible \\n \" ) NEW_LINE DEDENT DEDENT outputFile . close ( ) NEW_LINE inputFile . close ( ) NEW_LINE print time . time ( ) - startTime NEW_LINE", "def readline_ints ( ) : NEW_LINE INDENT return [ int ( num ) for num in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT import itertools NEW_LINE def ordered_subsets_sums ( S ) : NEW_LINE INDENT lim = sum ( S ) // 2 NEW_LINE for i in range ( 1 , len ( S ) ) : NEW_LINE INDENT for subset in itertools . combinations ( S , i ) : NEW_LINE INDENT sub_sum = sum ( subset ) NEW_LINE if sub_sum > lim : NEW_LINE INDENT break NEW_LINE DEDENT yield subset , sub_sum NEW_LINE DEDENT DEDENT DEDENT def find_collision ( S ) : NEW_LINE INDENT sums = { } NEW_LINE for sub , sub_sum in ordered_subsets_sums ( S ) : NEW_LINE INDENT if sub_sum in sums : NEW_LINE INDENT return sums [ sub_sum ] , sub NEW_LINE DEDENT sums [ sub_sum ] = sub NEW_LINE DEDENT DEDENT fname = \" C - large \" NEW_LINE with open ( fname + \" . in \" , \" r \" ) as fin , open ( fname + \" . out \" , \" w \" ) as fout : NEW_LINE INDENT numcases = readline_ints ( ) [ 0 ] NEW_LINE print ( numcases , \" cases \" ) NEW_LINE for caseno in range ( 1 , numcases + 1 ) : NEW_LINE INDENT N , * S = readline_ints ( ) NEW_LINE S . sort ( ) NEW_LINE coll = find_collision ( S ) NEW_LINE if coll is None : NEW_LINE INDENT result = \" Impossible \" NEW_LINE DEDENT else : NEW_LINE INDENT s1 , s2 = coll NEW_LINE result = \" ▁ \" . join ( str ( n ) for n in sorted ( s1 ) ) + \" \\n \" + \" ▁ \" . join ( str ( n ) for n in sorted ( s2 ) ) NEW_LINE DEDENT outstr = \" Case ▁ # % d : \\n % s \" % ( caseno , result ) NEW_LINE fout . write ( outstr + \" \\n \" ) NEW_LINE print ( outstr ) NEW_LINE DEDENT DEDENT" ]
codejam_16_42
[ "import java . util . * ; import java . io . * ; public class B { static int N ; static double ans ; public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { N = input . nextInt ( ) ; int K = input . nextInt ( ) ; double [ ] ps = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) ps [ i ] = input . nextDouble ( ) ; ans = 0 ; solve ( new ArrayList < Double > ( ) , ps , K , 0 ) ; System . out . printf ( \" Case ▁ # % d : ▁ \" , n + 1 ) ; System . out . println ( ans ) ; } } static void solve ( List < Double > keep , double [ ] ps , int K , int index ) { if ( index == ps . length ) { if ( keep . size ( ) == K ) check ( keep , K ) ; return ; } solve ( keep , ps , K , index + 1 ) ; keep . add ( ps [ index ] ) ; solve ( keep , ps , K , index + 1 ) ; keep . remove ( keep . size ( ) - 1 ) ; } static void check ( List < Double > keep , int K ) { double [ ] [ ] table = new double [ K + 1 ] [ K + 1 ] ; table [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= K ; i ++ ) for ( int yes = 0 ; yes <= i ; yes ++ ) { table [ i ] [ yes ] = table [ i - 1 ] [ yes ] * ( 1 - keep . get ( i - 1 ) ) ; if ( yes > 0 ) table [ i ] [ yes ] += table [ i - 1 ] [ yes - 1 ] * keep . get ( i - 1 ) ; } if ( table [ K ] [ K / 2 ] > ans ) ans = table [ K ] [ K / 2 ] ; } }", "import java . util . Arrays ; import java . util . Scanner ; public class B { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; System . out . printf ( \" % .9f \\n \" , solve ( ) ) ; } } static double solve ( ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; double [ ] Pt = new double [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { Pt [ i ] = sc . nextDouble ( ) ; } Arrays . sort ( Pt ) ; double [ ] P = new double [ K ] ; double ans = 0 ; for ( int u = 0 ; u <= K ; ++ u ) { for ( int i = 0 ; i < u ; ++ i ) { P [ i ] = Pt [ i ] ; } for ( int i = u ; i < K ; ++ i ) { P [ i ] = Pt [ N - 1 - ( i - u ) ] ; } double [ ] [ ] dp = new double [ K + 1 ] [ K + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= K ; ++ i ) { for ( int j = 0 ; j <= i ; ++ j ) { if ( j == 0 ) { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] * ( 1 - P [ i - 1 ] ) ) ; } else { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] * ( 1 - P [ i - 1 ] ) + dp [ i - 1 ] [ j - 1 ] * P [ i - 1 ] ) ; } } } ans = Math . max ( ans , dp [ K ] [ K / 2 ] ) ; } return ans ; } }" ]
[ "T = input ( ) NEW_LINE from itertools import combinations NEW_LINE def pp ( a ) : NEW_LINE INDENT r = 1 NEW_LINE for x in a : NEW_LINE INDENT r *= x NEW_LINE DEDENT return r NEW_LINE DEDENT def pfor ( c ) : NEW_LINE INDENT K = len ( c ) NEW_LINE dp = [ [ 0 for i in range ( K / 2 + 1 ) ] for j in range ( K + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE cp = 0 NEW_LINE for i in range ( K ) : NEW_LINE INDENT for y in range ( 0 , K / 2 + 1 ) : NEW_LINE INDENT dp [ i + 1 ] [ y ] = dp [ i ] [ y - 1 ] * c [ i ] + dp [ i ] [ y ] * ( 1 - c [ i ] ) NEW_LINE DEDENT DEDENT return dp [ K ] [ K / 2 ] NEW_LINE DEDENT def slidebw ( P , K ) : NEW_LINE INDENT for i in range ( K ) : NEW_LINE INDENT yield P [ : i ] + P [ - ( K - i ) : ] , i NEW_LINE DEDENT yield P [ : K ] , K NEW_LINE DEDENT def solve ( N , K , P ) : NEW_LINE INDENT bp , bm , bj = - 1 , None , None NEW_LINE for c , j in slidebw ( sorted ( P ) , K ) : NEW_LINE INDENT cp = pfor ( c ) NEW_LINE if cp > bp : NEW_LINE INDENT bp , bm , bj = cp , c , j NEW_LINE DEDENT DEDENT return ' { : . 9f } ' . format ( bp ) NEW_LINE DEDENT for i in range ( 1 , T + 1 ) : NEW_LINE INDENT N , K = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE P = map ( float , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( i , solve ( N , K , P ) ) NEW_LINE DEDENT", "import sys NEW_LINE import numpy as np NEW_LINE in_file = open ( ' b - large . in ' , ' r ' ) NEW_LINE out_file = open ( ' b . out ' , ' w ' ) NEW_LINE sys . stdin = in_file NEW_LINE sys . stdout = out_file NEW_LINE def calc ( a ) : NEW_LINE INDENT n = len ( a ) NEW_LINE f = np . zeros ( shape = ( n + 1 , n + 1 ) ) NEW_LINE f [ 0 ] [ 0 ] = 1 NEW_LINE for i in xrange ( 1 , n + 1 ) : NEW_LINE INDENT for j in xrange ( n + 1 ) : NEW_LINE INDENT f [ i ] [ j ] += f [ i - 1 ] [ j ] * a [ i - 1 ] NEW_LINE if j > 0 : NEW_LINE INDENT f [ i ] [ j ] += f [ i - 1 ] [ j - 1 ] * ( 1 - a [ i - 1 ] ) NEW_LINE DEDENT DEDENT DEDENT return f [ n ] [ n / 2 ] NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT n , m = map ( int , raw_input ( ) . split ( ) ) NEW_LINE a = map ( float , raw_input ( ) . split ( ) ) NEW_LINE a . sort ( ) NEW_LINE ans = 0 NEW_LINE for i in xrange ( m + 1 ) : NEW_LINE INDENT b = a [ : m - i ] + a [ n - i : ] NEW_LINE assert len ( b ) == m NEW_LINE ans = max ( ans , calc ( b ) ) NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % .10f ' % ( t + 1 , ans ) NEW_LINE DEDENT in_file . close ( ) NEW_LINE out_file . close ( ) NEW_LINE", "def m ( p ) : NEW_LINE INDENT return lambda x : x * p NEW_LINE DEDENT def aa ( u , v ) : NEW_LINE INDENT for x , y in zip ( u , v ) : NEW_LINE INDENT yield x + y NEW_LINE DEDENT DEDENT def get_p ( a ) : NEW_LINE INDENT u = [ 1 ] NEW_LINE for x in a : NEW_LINE INDENT u = list ( aa ( [ 0 , 0 ] + list ( map ( m ( x ) , u ) ) , list ( map ( m ( 1 - x ) , u ) ) + [ 0 , 0 ] ) ) NEW_LINE DEDENT return u [ len ( u ) >> 1 ] NEW_LINE DEDENT for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE p = sorted ( list ( map ( float , input ( ) . split ( ) ) ) ) NEW_LINE r = 0 NEW_LINE for j in range ( k + 1 ) : NEW_LINE INDENT v = p [ : j ] + p [ : : - 1 ] [ : k - j ] NEW_LINE assert ( len ( v ) == k ) NEW_LINE r = max ( r , get_p ( v ) ) NEW_LINE DEDENT print ( \" Case ▁ # % d : ▁ % .12f \" % ( i + 1 , r ) ) NEW_LINE DEDENT", "from multiprocessing import Pool NEW_LINE from pprint import pprint NEW_LINE import sys NEW_LINE def calcprob ( p ) : NEW_LINE INDENT prob = { } NEW_LINE k = len ( p ) NEW_LINE assert k % 2 == 0 NEW_LINE for j in range ( k // 2 + 1 ) : NEW_LINE INDENT prob [ ( 0 , j ) ] = 0 NEW_LINE DEDENT prob [ ( 0 , 0 ) ] = 1 NEW_LINE i = 0 NEW_LINE for pp in p : NEW_LINE INDENT i += 1 NEW_LINE for j in range ( k // 2 + 1 ) : NEW_LINE INDENT res = prob [ ( i - 1 , j ) ] * ( 1 - pp ) NEW_LINE if j > 0 : NEW_LINE INDENT res = res + prob [ ( i - 1 , j - 1 ) ] * pp NEW_LINE DEDENT prob [ ( i , j ) ] = res NEW_LINE DEDENT DEDENT return prob [ ( i , k // 2 ) ] NEW_LINE DEDENT def solve_test ( data ) : NEW_LINE INDENT n , k , p = data NEW_LINE p = sorted ( p ) NEW_LINE ans = - 1 NEW_LINE for i in range ( k + 1 ) : NEW_LINE INDENT left = i NEW_LINE right = k - i NEW_LINE pp = p [ : i ] + p [ n - right : ] NEW_LINE assert len ( pp ) == k NEW_LINE prob = calcprob ( pp ) NEW_LINE if prob > ans : NEW_LINE INDENT ans = prob NEW_LINE DEDENT DEDENT sys . stderr . write ( ' . ' ) NEW_LINE return ans NEW_LINE DEDENT tests = int ( input ( ) ) NEW_LINE data = [ ] NEW_LINE for test in range ( tests ) : NEW_LINE INDENT sys . stderr . write ( str ( test ) ) NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE p = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE data . append ( ( n , k , p ) ) NEW_LINE DEDENT with Pool ( 6 ) as p : NEW_LINE INDENT res = p . map ( solve_test , data ) NEW_LINE DEDENT for test in range ( tests ) : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ % 0.8f \" % ( test + 1 , res [ test ] ) ) NEW_LINE DEDENT", "from itertools import * NEW_LINE def test ( k ) : NEW_LINE INDENT assert ( len ( k ) == K ) NEW_LINE F = [ 0.0 ] * ( K // 2 + 1 ) NEW_LINE F [ 0 ] = 1.0 NEW_LINE for p in k : NEW_LINE INDENT G = [ 0.0 ] * ( K // 2 + 1 ) NEW_LINE for j in range ( K // 2 ) : NEW_LINE INDENT G [ j ] += F [ j ] * p NEW_LINE G [ j + 1 ] += F [ j ] * ( 1 - p ) NEW_LINE DEDENT G [ K // 2 ] += F [ K // 2 ] * p NEW_LINE F = G NEW_LINE DEDENT return F [ K // 2 ] NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE F = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE F . sort ( ) NEW_LINE ans = 0.0 NEW_LINE ans = max ( test ( F [ : K ] ) , test ( F [ - K : ] ) ) NEW_LINE for i in range ( 1 , K ) : NEW_LINE INDENT ans = max ( ans , test ( F [ : i ] + F [ - ( K - i ) : ] ) ) NEW_LINE DEDENT for i in range ( N - K ) : NEW_LINE INDENT ans = max ( ans , test ( F [ i : i + K ] ) ) NEW_LINE DEDENT print ( \" Case ▁ # % d : ▁ % .20f \" % ( t + 1 , ans ) ) NEW_LINE DEDENT" ]
codejam_16_23
[ "package round1b ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Kattio extends PrintWriter { public Kattio ( InputStream i ) { super ( new BufferedOutputStream ( System . out ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public Kattio ( InputStream i , OutputStream o ) { super ( new BufferedOutputStream ( o ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public boolean hasMoreTokens ( ) { return peekToken ( ) != null ; } public int getInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public double getDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } public long getLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } public String getWord ( ) { return nextToken ( ) ; } private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken ( ) { if ( token == null ) try { while ( st == null || ! st . hasMoreTokens ( ) ) { line = r . readLine ( ) ; if ( line == null ) return null ; st = new StringTokenizer ( line ) ; } token = st . nextToken ( ) ; } catch ( IOException e ) { } return token ; } private String nextToken ( ) { String ans = peekToken ( ) ; token = null ; return ans ; } }", "package round1B ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Locale ; import java . util . Scanner ; import round1B . PushRelabelNodeEdge . Node ; public class ProblemC { public static void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; HashMap < String , Node > map1 = new HashMap < > ( ) ; HashMap < String , Node > map2 = new HashMap < > ( ) ; Node start = new Node ( \" start \" ) ; Node end = new Node ( \" end \" ) ; for ( int i = 0 ; i < n ; i ++ ) { String firstWord = sc . next ( ) ; String secondWord = sc . next ( ) ; if ( ! map1 . containsKey ( firstWord ) ) { Node node = new Node ( firstWord ) ; map1 . put ( firstWord , node ) ; PushRelabelNodeEdge . addDirectedEdge ( start , node , 1 ) ; } if ( ! map2 . containsKey ( secondWord ) ) { Node node = new Node ( secondWord ) ; map2 . put ( secondWord , node ) ; PushRelabelNodeEdge . addDirectedEdge ( node , end , 1 ) ; } PushRelabelNodeEdge . addDirectedEdge ( map1 . get ( firstWord ) , map2 . get ( secondWord ) , 1 ) ; } ArrayList < Node > nodes = new ArrayList < > ( ) ; nodes . add ( start ) ; nodes . add ( end ) ; nodes . addAll ( map1 . values ( ) ) ; nodes . addAll ( map2 . values ( ) ) ; int flow = PushRelabelNodeEdge . getMaxFlow ( nodes , start , end ) ; int greedy = nodes . size ( ) - 2 - 2 * flow ; System . out . println ( n - flow - greedy ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( new File ( \" C - large . in \" ) ) ; sc . useLocale ( Locale . US ) ; int cases = sc . nextInt ( ) ; for ( int i = 1 ; i <= cases ; i ++ ) { System . out . format ( Locale . US , \" Case ▁ # % d : ▁ \" , i ) ; solve ( sc ) ; } sc . close ( ) ; } }" ]
[ "import sys NEW_LINE import random NEW_LINE import re NEW_LINE from itertools import permutations NEW_LINE import networkx as nx NEW_LINE def solve ( ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE topics = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT topics . append ( sys . stdin . readline ( ) . split ( ) ) NEW_LINE DEDENT left = set ( ) NEW_LINE right = set ( ) NEW_LINE for a , b in topics : NEW_LINE INDENT left . add ( a ) NEW_LINE right . add ( b ) NEW_LINE DEDENT G = nx . DiGraph ( ) NEW_LINE for a , b in topics : NEW_LINE INDENT G . add_edges_from ( [ ( ( a , 0 ) , ( b , 1 ) , { ' capacity ' : 1 , ' weight ' : 1 } ) ] ) NEW_LINE DEDENT for a in left : NEW_LINE INDENT G . add_edges_from ( [ ( 0 , ( a , 0 ) , { ' capacity ' : 1 , ' weight ' : 0 } ) ] ) NEW_LINE DEDENT for b in right : NEW_LINE INDENT G . add_edges_from ( [ ( ( b , 1 ) , 1 , { ' capacity ' : 1 , ' weight ' : 0 } ) ] ) NEW_LINE DEDENT mincostFlow = nx . max_flow_min_cost ( G , 0 , 1 ) NEW_LINE mincost = nx . cost_of_flow ( G , mincostFlow ) NEW_LINE needed_arcs = len ( left ) + len ( right ) - mincost NEW_LINE faked = len ( topics ) - needed_arcs NEW_LINE print faked NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT t = int ( sys . stdin . readline ( ) ) NEW_LINE for i in xrange ( t ) : NEW_LINE INDENT print \" Case ▁ # % d : \" % ( i + 1 ) , NEW_LINE solve ( ) NEW_LINE DEDENT DEDENT", "from __future__ import division NEW_LINE from gcj import * NEW_LINE FLAGS = ' ' NEW_LINE def case ( ) : NEW_LINE INDENT N , = ints ( ) NEW_LINE titles = [ line ( ) . split ( ) for i in range ( N ) ] NEW_LINE for t in titles : NEW_LINE INDENT a , b = t NEW_LINE t [ : ] = [ ' a : ' + a , ' b : ' + b ] NEW_LINE DEDENT pprint ( titles ) NEW_LINE source = 0 NEW_LINE sink = 1 NEW_LINE node2id = dict ( source = source , sink = sink ) NEW_LINE wordcounts = { } NEW_LINE for a , b in titles : NEW_LINE INDENT for x in a , b : NEW_LINE INDENT node2id . setdefault ( x , len ( node2id ) ) NEW_LINE wordcounts . setdefault ( x , 0 ) NEW_LINE wordcounts [ x ] += 1 NEW_LINE DEDENT DEDENT pprint ( node2id ) NEW_LINE pprint ( wordcounts ) NEW_LINE N = len ( node2id ) NEW_LINE capacity = [ [ 0 ] * N for i in range ( N ) ] NEW_LINE for word , count in wordcounts . items ( ) : NEW_LINE INDENT if word . startswith ( ' a ' ) : NEW_LINE INDENT capacity [ source ] [ node2id [ word ] ] = count - 1 NEW_LINE DEDENT else : NEW_LINE INDENT capacity [ node2id [ word ] ] [ sink ] = count - 1 NEW_LINE DEDENT DEDENT for a , b in titles : NEW_LINE INDENT assert capacity [ node2id [ a ] ] [ node2id [ b ] ] == 0 NEW_LINE capacity [ node2id [ a ] ] [ node2id [ b ] ] = 1 NEW_LINE DEDENT def dfs ( pos , visited ) : NEW_LINE INDENT if pos == sink : NEW_LINE INDENT return True NEW_LINE DEDENT for t in range ( N ) : NEW_LINE INDENT if capacity [ pos ] [ t ] : NEW_LINE INDENT if t in visited : continue NEW_LINE visited . add ( t ) NEW_LINE capacity [ pos ] [ t ] -= 1 NEW_LINE capacity [ t ] [ pos ] += 1 NEW_LINE res = dfs ( t , visited ) NEW_LINE if res : NEW_LINE INDENT return res NEW_LINE DEDENT capacity [ t ] [ pos ] -= 1 NEW_LINE capacity [ pos ] [ t ] += 1 NEW_LINE DEDENT DEDENT DEDENT n = 0 NEW_LINE while True : NEW_LINE INDENT res = dfs ( source , set ( ) ) NEW_LINE if not res : break NEW_LINE n += 1 NEW_LINE DEDENT return n NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "first = { } NEW_LINE second = { } NEW_LINE np = 0 NEW_LINE em = [ ] NEW_LINE match = [ ] NEW_LINE def ToNo ( x , isFirst = True ) : NEW_LINE INDENT global np , em NEW_LINE ws = first if isFirst else second NEW_LINE if x not in ws : NEW_LINE INDENT ws [ x ] = np NEW_LINE np += 1 NEW_LINE em += [ set ( ) ] NEW_LINE DEDENT return ws [ x ] NEW_LINE DEDENT def dfs ( x ) : NEW_LINE INDENT v [ x ] = True NEW_LINE for y in em [ x ] : NEW_LINE INDENT if match [ y ] == - 1 or ( not v [ match [ y ] ] and dfs ( match [ y ] ) ) : NEW_LINE INDENT match [ y ] = x NEW_LINE return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT for case in range ( 1 , int ( raw_input ( ) ) + 1 ) : NEW_LINE INDENT print \" Case ▁ # % d : \" % case , NEW_LINE np = 0 NEW_LINE first = { } NEW_LINE second = { } NEW_LINE em = [ ] NEW_LINE n = int ( raw_input ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT a , b = raw_input ( ) . split ( ) NEW_LINE em [ ToNo ( a ) ] . add ( ToNo ( b , False ) ) NEW_LINE em [ ToNo ( b , False ) ] . add ( ToNo ( a ) ) NEW_LINE DEDENT match = [ - 1 ] * np NEW_LINE ans = 0 NEW_LINE for x in first : NEW_LINE INDENT no = ToNo ( x ) NEW_LINE v = [ False ] * np NEW_LINE if dfs ( no ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print n - ( np - ans ) NEW_LINE DEDENT", "import sys NEW_LINE import re NEW_LINE import bipartite_matching NEW_LINE input_file = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE nb_tests = int ( input_file . readline ( ) ) NEW_LINE for i in range ( nb_tests ) : NEW_LINE INDENT nb_titles = int ( input_file . readline ( ) ) NEW_LINE titles = { } NEW_LINE first_titles = set ( { } ) NEW_LINE second_titles = set ( { } ) NEW_LINE for j in range ( nb_titles ) : NEW_LINE INDENT title = input_file . readline ( ) [ : - 1 ] . split ( ' ▁ ' ) NEW_LINE first_titles = first_titles | { title [ 0 ] } NEW_LINE second_titles = second_titles | { title [ 1 ] } NEW_LINE if title [ 0 ] in titles : NEW_LINE INDENT titles [ title [ 0 ] ] . append ( title [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT titles [ title [ 0 ] ] = [ title [ 1 ] ] NEW_LINE DEDENT DEDENT matching = bipartite_matching . bipartiteMatch ( titles ) [ 0 ] NEW_LINE len_m = len ( matching ) NEW_LINE len_f = len ( first_titles ) NEW_LINE len_s = len ( second_titles ) NEW_LINE cover = len_f + len_s - len_m NEW_LINE print ( ' Case ▁ # ' , i + 1 , ' : ▁ ' , nb_titles - cover , sep = ' ' ) NEW_LINE DEDENT", "def dfs ( e , ma , u , v ) : NEW_LINE INDENT if v in u : NEW_LINE INDENT return False NEW_LINE DEDENT u [ v ] = True NEW_LINE for x in e [ v ] : NEW_LINE INDENT if ( not x in ma ) or dfs ( e , ma , u , ma [ x ] ) : NEW_LINE INDENT ma [ x ] = v NEW_LINE return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE e = { } NEW_LINE av = { } NEW_LINE bv = { } NEW_LINE ac = 0 NEW_LINE bc = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT a , b = list ( input ( ) . split ( ) ) NEW_LINE if not a in e : NEW_LINE INDENT e [ a ] = [ ] NEW_LINE DEDENT e [ a ] . append ( b ) NEW_LINE if not a in av : NEW_LINE INDENT av [ a ] = True NEW_LINE ac += 1 NEW_LINE DEDENT if not b in bv : NEW_LINE INDENT bv [ b ] = True NEW_LINE bc += 1 NEW_LINE DEDENT DEDENT m = 0 NEW_LINE ma = { } NEW_LINE for a in av : NEW_LINE INDENT u = { } NEW_LINE if dfs ( e , ma , u , a ) : NEW_LINE INDENT m += 1 NEW_LINE DEDENT DEDENT return str ( n - ( ac + bc - m ) ) NEW_LINE DEDENT nt = int ( input ( ) ) NEW_LINE for tt in range ( nt ) : NEW_LINE INDENT print ( ' Case ▁ # ' + str ( tt + 1 ) + ' : ▁ ' + str ( solve ( ) ) ) NEW_LINE DEDENT" ]
codejam_12_51
[ "import java . io . * ; import java . util . Arrays ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( \" A - small - attempt0 ▁ ( 1 ) . in \" ) ) ; PrintWriter out = new PrintWriter ( \" a . out \" ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int n = in . nextInt ( ) ; Lev [ ] ls = new Lev [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ls [ i ] = new Lev ( ) ; ls [ i ] . i = i ; ls [ i ] . l = in . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { ls [ i ] . p = in . nextInt ( ) ; } Arrays . sort ( ls ) ; StringBuilder buf = new StringBuilder ( ) ; for ( Lev l : ls ) { buf . append ( \" ▁ \" ) . append ( l . i ) ; } out . println ( \" Case ▁ # \" + t + \" : \" + buf ) ; } out . close ( ) ; in . close ( ) ; } private static class Lev implements Comparable < Lev > { public int l , p , i ; public int compareTo ( Lev o ) { double q1 = Math . log ( ( 100. - p ) * 0.01 ) / l ; double q2 = Math . log ( ( 100. - o . p ) * 0.01 ) / o . l ; return Double . compare ( q1 , q2 ) ; } } }", "import java . io . * ; import java . util . Arrays ; import java . util . Locale ; import java . util . StringTokenizer ; public class A { BufferedReader in ; StringTokenizer str ; PrintWriter out ; String SK ; String next ( ) throws IOException { while ( ( str == null ) || ( ! str . hasMoreTokens ( ) ) ) { SK = in . readLine ( ) ; if ( SK == null ) return null ; str = new StringTokenizer ( SK ) ; } return str . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } class Sob implements Comparable < Sob > { int t ; int p ; int num ; public int compareTo ( Sob o ) { return o . p * t - p * o . t ; } } void solve ( ) throws IOException { int n = nextInt ( ) ; Sob [ ] a = new Sob [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = new Sob ( ) ; a [ i ] . num = i ; } for ( int i = 0 ; i < n ; i ++ ) { a [ i ] . t = nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { a [ i ] . p = nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = 0 ; i < n ; i ++ ) { out . print ( \" ▁ \" + a [ i ] . num ) ; } out . println ( ) ; } void run ( ) throws IOException { in = new BufferedReader ( new FileReader ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int t = nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : \" ) ; solve ( ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new A ( ) . run ( ) ; } }", "import java . util . * ; import java . io . * ; import java . math . * ; import java . awt . * ; public class A { public static Comparator < Point > cmp = new Comparator < Point > ( ) { public int compare ( Point a , Point b ) { if ( a . y > b . y ) return - 1 ; if ( a . y < b . y ) return 1 ; return a . x - b . x ; } } ; public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int T = scan . nextInt ( ) ; for ( int ca = 1 ; ca <= T ; ca ++ ) { int n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) scan . nextInt ( ) ; Point [ ] a = new Point [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = new Point ( i , scan . nextInt ( ) ) ; Arrays . sort ( a , cmp ) ; System . out . print ( \" Case ▁ # \" + ca + \" : \" ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( \" ▁ \" + a [ i ] . x ) ; System . out . println ( ) ; } } }", "import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main implements Runnable { public static void main ( String [ ] args ) throws IOException { new Thread ( new Main ( ) ) . start ( ) ; } public void run ( ) { try { run1 ( ) ; } catch ( IOException e ) { throw new RuntimeException ( ) ; } } public void run1 ( ) throws IOException { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; int tN = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int tn = 0 ; tn < tN ; tn ++ ) { int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; int [ ] len = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { len [ i ] = sc . nextInt ( ) ; } boolean [ ] oppa = new boolean [ n ] ; pw . print ( \" Case ▁ # \" + ( tn + 1 ) + \" : \" ) ; c : for ( int i = 0 ; i < n ; i ++ ) { int be = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ! oppa [ j ] ) { if ( be == - 1 || len [ j ] * p [ be ] > len [ be ] * p [ j ] ) { be = j ; } } } oppa [ be ] = true ; pw . print ( \" ▁ \" + be ) ; } pw . println ( ) ; } pw . close ( ) ; } }", "import java . util . Arrays ; import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; static class Solver { int N ; int [ ] L , P ; void solve ( ) { N = sc . nextInt ( ) ; L = new int [ N ] ; P = new int [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { L [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; ++ i ) { P [ i ] = sc . nextInt ( ) ; } Stage [ ] stages = new Stage [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { stages [ i ] = new Stage ( L [ i ] , P [ i ] , i ) ; } Arrays . sort ( stages ) ; for ( int i = 0 ; i < N ; ++ i ) { System . out . print ( stages [ i ] . idx ) ; if ( i != N - 1 ) { System . out . print ( \" ▁ \" ) ; } } System . out . println ( ) ; } } static class Stage implements Comparable < Stage > { int l , p , idx ; Stage ( int l , int p , int idx ) { this . l = l ; this . p = p ; this . idx = idx ; } public int compareTo ( Stage o ) { return o . l * o . p - this . l * this . p ; } } public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; Solver solver = new Solver ( ) ; solver . solve ( ) ; } } }" ]
[ "import sys NEW_LINE T = int ( sys . stdin . readline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE L = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE P = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE l = [ ] NEW_LINE for i , p in enumerate ( P ) : NEW_LINE INDENT if p != 0 : NEW_LINE INDENT l . append ( ( float ( L [ i ] ) / p , i ) ) ; NEW_LINE DEDENT else : NEW_LINE INDENT l . append ( ( 1E30 , i ) ) ; NEW_LINE DEDENT DEDENT l . sort ( ) NEW_LINE print ' Case ▁ # % d : ▁ ' % t , NEW_LINE for p , i in l : NEW_LINE INDENT print i , NEW_LINE DEDENT print ' ' NEW_LINE DEDENT", "import sys NEW_LINE def cmp_fn ( x1 , x2 ) : NEW_LINE INDENT L1 , q1 = x1 [ 1 ] , x1 [ 2 ] NEW_LINE L2 , q2 = x2 [ 1 ] , x2 [ 2 ] NEW_LINE if q1 == 100 and q2 == 100 : NEW_LINE INDENT return x1 [ 0 ] - x1 [ 1 ] NEW_LINE DEDENT if q1 == 100 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if q2 == 100 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if L1 * q2 != L2 * q1 : NEW_LINE INDENT return L2 * q1 - L1 * q2 NEW_LINE DEDENT return x1 [ 0 ] - x1 [ 1 ] NEW_LINE DEDENT def compute ( L , P ) : NEW_LINE INDENT x = [ ( i , L [ i ] , 100 - P [ i ] ) for i in xrange ( len ( L ) ) ] NEW_LINE x = sorted ( x , cmp = cmp_fn ) NEW_LINE return \" ▁ \" . join ( [ ( ' % d ' % x [ i ] [ 0 ] ) for i in xrange ( len ( x ) ) ] ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT N = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE L = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE P = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE return L , P NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE count = 1 NEW_LINE part = 0 NEW_LINE if len ( sys . argv ) == 3 : NEW_LINE INDENT part = int ( sys . argv [ 1 ] ) NEW_LINE count = int ( sys . argv [ 2 ] ) NEW_LINE DEDENT for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE if i * count >= part * T and i * count < ( part + 1 ) * T : NEW_LINE INDENT result = compute ( * data ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT DEDENT", "from __future__ import division NEW_LINE import os NEW_LINE import sys NEW_LINE import operator NEW_LINE import string NEW_LINE import re NEW_LINE import time NEW_LINE from os . path import splitext NEW_LINE from copy import copy NEW_LINE from math import * NEW_LINE from operator import * NEW_LINE from collections import * NEW_LINE from itertools import * NEW_LINE from functools import * NEW_LINE try : NEW_LINE INDENT from do import report_working_on NEW_LINE DEDENT except ImportError : NEW_LINE INDENT report_working_on = lambda a , b : None NEW_LINE DEDENT if len ( sys . argv ) > 1 : NEW_LINE INDENT fin = file ( sys . argv [ 1 ] , ' r ' ) NEW_LINE fout = file ( splitext ( sys . argv [ 1 ] ) [ 0 ] + ' . out ' , ' w + ' ) NEW_LINE DEDENT else : NEW_LINE INDENT fin = sys . stdin NEW_LINE fout = sys . stdout NEW_LINE DEDENT def dorun ( ) : NEW_LINE INDENT cases = int ( fin . next ( ) ) NEW_LINE for case in xrange ( cases ) : NEW_LINE INDENT report_working_on ( case , cases ) NEW_LINE print >> fout , ' Case ▁ # % d : ▁ % s ' % ( 1 + case , solve ( fin ) ) NEW_LINE DEDENT else : NEW_LINE INDENT report_working_on ( 0 , 0 ) NEW_LINE DEDENT DEDENT def solve ( fin ) : NEW_LINE INDENT N = int ( fin . next ( ) . strip ( ) ) NEW_LINE Lx = map ( int , fin . next ( ) . split ( ) ) NEW_LINE Px = map ( int , fin . next ( ) . split ( ) ) NEW_LINE LL = list ( enumerate ( Px ) ) NEW_LINE LL . sort ( key = lambda a : - a [ 1 ] ) NEW_LINE return ' ▁ ' . join ( str ( a [ 0 ] ) for a in LL ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : dorun ( ) NEW_LINE", "fin = open ( \" A - small - attempt0 . in \" , \" r \" ) NEW_LINE fout = open ( \" A . out \" , \" w \" ) NEW_LINE numcases = int ( fin . readline ( ) ) NEW_LINE numcases += 1 NEW_LINE for cas in xrange ( 1 , numcases ) : NEW_LINE INDENT fout . write ( \" Case ▁ # \" + str ( cas ) + \" : \" ) NEW_LINE n = int ( fin . readline ( ) ) NEW_LINE l = map ( float , fin . readline ( ) . split ( ) ) NEW_LINE p = map ( float , fin . readline ( ) . split ( ) ) NEW_LINE q = [ p [ i ] / l [ i ] for i in xrange ( n ) ] NEW_LINE r = [ ( q [ i ] , - i ) for i in xrange ( n ) ] NEW_LINE r . sort ( ) NEW_LINE r . reverse ( ) NEW_LINE for i in r : NEW_LINE INDENT fout . write ( \" ▁ \" + str ( - i [ 1 ] ) ) NEW_LINE DEDENT fout . write ( \" \\n \" ) NEW_LINE DEDENT", "import sys NEW_LINE stdin = sys . stdin NEW_LINE def computeEtries ( p ) : NEW_LINE INDENT pr = p / 100.0 NEW_LINE re = 1 NEW_LINE running = pr NEW_LINE multiplier = 2 NEW_LINE while multiplier < 10000 or multiplier * running > 1e-9 : NEW_LINE INDENT re += multiplier * running NEW_LINE running *= pr NEW_LINE multiplier += 1 NEW_LINE DEDENT return ( 1 - pr ) * re NEW_LINE DEDENT ets = [ computeEtries ( p ) for p in range ( 100 ) ] NEW_LINE T = int ( stdin . readline ( ) ) NEW_LINE for tcase in range ( T ) : NEW_LINE INDENT N = int ( stdin . readline ( ) ) NEW_LINE Ls = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE Ps = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE etries = [ ets [ p ] for p in Ps ] NEW_LINE seq = [ ( index , Ls [ index ] , etries [ index ] ) for index in range ( N ) ] NEW_LINE for k in range ( N ) : NEW_LINE INDENT best = k NEW_LINE for s in range ( k + 1 , N ) : NEW_LINE INDENT in1 = seq [ best ] [ 0 ] NEW_LINE L1 = seq [ best ] [ 1 ] NEW_LINE E1 = seq [ best ] [ 2 ] NEW_LINE in2 = seq [ s ] [ 0 ] NEW_LINE L2 = seq [ s ] [ 1 ] NEW_LINE E2 = seq [ s ] [ 2 ] NEW_LINE extra_if_1_goes_first = ( E2 - 1 ) * E1 * L1 NEW_LINE extra_if_2_goes = ( E1 - 1 ) * E2 * L2 NEW_LINE if abs ( extra_if_1_goes_first - extra_if_2_goes ) < 1e-9 : NEW_LINE INDENT if in2 < in1 : NEW_LINE INDENT best = s NEW_LINE DEDENT DEDENT elif extra_if_2_goes < extra_if_1_goes_first : NEW_LINE INDENT best = s NEW_LINE DEDENT DEDENT swap = seq [ best ] NEW_LINE seq [ best ] = seq [ k ] NEW_LINE seq [ k ] = swap NEW_LINE DEDENT print \" Case ▁ # % d : \" % ( tcase + 1 ) , NEW_LINE print ' ▁ ' . join ( map ( str , [ seq [ i ] [ 0 ] for i in range ( N ) ] ) ) NEW_LINE DEDENT" ]
codejam_17_21
[ "import java . io . * ; import java . util . * ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( \" in . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" out . txt \" ) ) ; int N = Integer . parseInt ( br . readLine ( ) ) ; for ( int pp = 0 ; pp < N ; pp ++ ) { String [ ] ss = br . readLine ( ) . split ( \" ▁ \" ) ; int d = Integer . parseInt ( ss [ 0 ] ) ; int n = Integer . parseInt ( ss [ 1 ] ) ; double max = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { ss = br . readLine ( ) . split ( \" ▁ \" ) ; int k = Integer . parseInt ( ss [ 0 ] ) ; int s = Integer . parseInt ( ss [ 1 ] ) ; double time = ( d - k ) / ( ( double ) s ) ; System . out . println ( d + \" ▁ \" + k + \" ▁ \" + s + \" ▁ \" + time ) ; max = Math . max ( max , time ) ; } double ret = d / max ; pw . println ( \" Case ▁ # \" + ( pp + 1 ) + \" : ▁ \" + ret ) ; } pw . flush ( ) ; pw . close ( ) ; } }", "package year2017 . round1b ; import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; public class CruiseControl { public static void main ( String [ ] args ) throws Exception { File inputFile = new File ( \" A - large . in \" ) ; Scanner in = new Scanner ( inputFile ) ; File outputFile = new File ( \" output . txt \" ) ; PrintWriter out = new PrintWriter ( outputFile ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { double D = in . nextDouble ( ) ; int N = in . nextInt ( ) ; double maxTime = 0 ; for ( int n = 0 ; n < N ; n ++ ) { double K = in . nextDouble ( ) ; double S = in . nextDouble ( ) ; double time = ( D - K ) / S ; maxTime = Math . max ( time , maxTime ) ; } double speed = D / maxTime ; out . println ( \" Case ▁ # \" + ( t + 1 ) + \" : ▁ \" + speed ) ; } out . close ( ) ; } }", "import static java . lang . Double . parseDouble ; import static java . lang . Integer . parseInt ; import static java . lang . Long . parseLong ; import static java . lang . Math . max ; import static java . lang . System . exit ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . util . Locale ; import java . util . StringTokenizer ; public class A { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static int test ; static void solve ( ) throws Exception { int d = nextInt ( ) ; int n = nextInt ( ) ; double ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int k = nextInt ( ) ; int s = nextInt ( ) ; ans = max ( ans , ( double ) ( d - k ) / s ) ; } printCase ( ) ; out . printf ( Locale . US , \" % .9f \\n \" , d / ans ) ; } static void printCase ( ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; } static void printlnCase ( ) { out . println ( \" Case ▁ # \" + test + \" : \" ) ; } static int nextInt ( ) throws IOException { return parseInt ( next ( ) ) ; } static long nextLong ( ) throws IOException { return parseLong ( next ( ) ) ; } static double nextDouble ( ) throws IOException { return parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } public static void main ( String [ ] args ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int tests = nextInt ( ) ; for ( test = 1 ; test <= tests ; test ++ ) { solve ( ) ; } in . close ( ) ; out . close ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; exit ( 1 ) ; } } }", "package codejam ; import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . nio . file . Files ; import java . nio . file . Paths ; public class Horse { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( \" src / codejam / A - large . in \" ) ) ; StringBuilder sb = new StringBuilder ( ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int t_i = 1 ; t_i <= T ; t_i ++ ) { String [ ] split = br . readLine ( ) . split ( \" ▁ \" ) ; int D = Integer . parseInt ( split [ 0 ] ) ; int N = Integer . parseInt ( split [ 1 ] ) ; int [ ] k = new int [ N ] ; int [ ] s = new int [ N ] ; double latest = 0 ; for ( int n_i = 0 ; n_i < N ; n_i ++ ) { split = br . readLine ( ) . split ( \" ▁ \" ) ; k [ n_i ] = Integer . parseInt ( split [ 0 ] ) ; s [ n_i ] = Integer . parseInt ( split [ 1 ] ) ; double time = 1. * ( D - k [ n_i ] ) / s [ n_i ] ; if ( time > latest ) latest = time ; } sb . append ( \" Case ▁ # \" ) . append ( t_i ) . append ( \" : ▁ \" ) . append ( D / latest ) . append ( \" \\n \" ) ; } Files . write ( Paths . get ( \" src / codejam / horse . out \" ) , sb . toString ( ) . getBytes ( ) ) ; System . out . println ( sb . toString ( ) ) ; } }", "package Y2017 . r1b ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . io . UnsupportedEncodingException ; import java . util . Scanner ; public class CruiseControl { public static void main ( String [ ] args ) throws FileNotFoundException , UnsupportedEncodingException { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; scanner . nextLine ( ) ; try ( PrintWriter writer = new PrintWriter ( \" solution . txt \" , \" UTF - 8\" ) ) { for ( int i = 1 ; i <= n ; ++ i ) { writer . print ( String . format ( \" Case ▁ # % d : ▁ \" , i ) ) ; solve ( scanner , writer ) ; } } } public static void solve ( Scanner scanner , PrintWriter writer ) { int D = scanner . nextInt ( ) ; int N = scanner . nextInt ( ) ; double duration = 0 ; for ( int i = 0 ; i < N ; ++ i ) { int K = scanner . nextInt ( ) ; int S = scanner . nextInt ( ) ; double d = ( D - K ) / ( ( double ) S ) ; duration = Math . max ( duration , d ) ; } writer . println ( D / duration ) ; } }" ]
[ "def solve ( ) : NEW_LINE INDENT d , n = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 10 ** 100 NEW_LINE for i in range ( n ) : NEW_LINE INDENT k , s = map ( int , input ( ) . split ( ) ) NEW_LINE ans = min ( ans , d * s / ( d - k ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT t = int ( input ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ % .20f \" % ( i + 1 , solve ( ) ) ) NEW_LINE DEDENT", "def initialize_solver ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT def solve_testcase ( ) : NEW_LINE INDENT d , n = read ( ) NEW_LINE mx = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT k , s = read ( ) NEW_LINE mx = max ( ( d - k ) / s , mx ) NEW_LINE DEDENT return str ( d / mx ) NEW_LINE DEDENT def read ( callback = int , split = True ) : NEW_LINE INDENT if sfile : NEW_LINE INDENT input_line = sfile . readline ( ) . strip ( ) NEW_LINE DEDENT else : NEW_LINE INDENT input_line = input ( ) . strip ( ) NEW_LINE DEDENT if split : NEW_LINE INDENT return list ( map ( callback , input_line . split ( ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return callback ( input_line ) NEW_LINE DEDENT DEDENT def write ( value = \" \\n \" ) : NEW_LINE INDENT if value is None : return NEW_LINE try : NEW_LINE INDENT if not isinstance ( value , str ) : NEW_LINE INDENT value = \" ▁ \" . join ( map ( str , value ) ) NEW_LINE DEDENT DEDENT except : NEW_LINE INDENT pass NEW_LINE DEDENT if tfile : NEW_LINE INDENT tfile . write ( value ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( value , end = \" \" ) NEW_LINE DEDENT DEDENT output_format = \" Case ▁ # % d : ▁ \" NEW_LINE filename = input ( ) . strip ( ) NEW_LINE sfile = None NEW_LINE tfile = None NEW_LINE if filename != \" \" : NEW_LINE INDENT sfile = open ( filename + \" . in \" , \" r \" ) NEW_LINE sfile . seek ( 0 ) NEW_LINE tfile = open ( filename + \" . out \" , \" w \" ) NEW_LINE DEDENT if output_format == None : NEW_LINE INDENT solve_testcase ( ) NEW_LINE DEDENT else : NEW_LINE INDENT initialize_solver ( ) NEW_LINE total_cases , = read ( ) NEW_LINE for case_number in range ( 1 , total_cases + 1 ) : NEW_LINE INDENT write ( output_format . replace ( \" % d \" , str ( case_number ) ) ) NEW_LINE write ( solve_testcase ( ) ) NEW_LINE write ( ) NEW_LINE DEDENT DEDENT if tfile is not None : tfile . close ( ) NEW_LINE", "TEST = ' large ' NEW_LINE IN = ' A - { } . in ' . format ( TEST ) NEW_LINE OUT = ' A - { } . out ' . format ( TEST ) NEW_LINE def run ( d , h ) : NEW_LINE INDENT t = max ( ( d - k ) / s for k , s in h ) NEW_LINE return d / t NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT with open ( IN ) as fin , open ( OUT , ' w ' ) as fout : NEW_LINE INDENT t = int ( fin . readline ( ) . strip ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT d , n = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE h = [ tuple ( map ( int , fin . readline ( ) . split ( ) ) ) for i in range ( n ) ] NEW_LINE res = run ( d , h ) NEW_LINE print ( ' Case ▁ # { } : ▁ { } ' . format ( i + 1 , res ) , file = fout ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "from sys import stdin NEW_LINE for cn in xrange ( 1 , 1 + int ( stdin . readline ( ) ) ) : NEW_LINE INDENT ( D , N ) = tuple ( int ( z ) for z in stdin . readline ( ) . split ( ) ) NEW_LINE slowest = 0 NEW_LINE for h in xrange ( N ) : NEW_LINE INDENT ( K , S ) = tuple ( int ( z ) for z in stdin . readline ( ) . split ( ) ) NEW_LINE time = float ( D - K ) / S NEW_LINE slowest = max ( slowest , time ) NEW_LINE DEDENT speed = D / slowest NEW_LINE print \" Case ▁ # { } : ▁ { } \" . format ( cn , speed ) NEW_LINE DEDENT", "with open ( ' A - large . in ' , ' r ' ) as f , open ( ' out . txt ' , ' w ' ) as fout : NEW_LINE INDENT t = int ( f . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , t + 1 ) : NEW_LINE INDENT d , n = [ int ( s ) for s in f . readline ( ) . strip ( ) . split ( ) ] NEW_LINE last_arrive = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT ki , si = [ int ( s ) for s in f . readline ( ) . strip ( ) . split ( ) ] NEW_LINE last_arrive = max ( last_arrive , ( ( d - ki ) / si ) ) NEW_LINE DEDENT print ( ' Case ▁ # % d : ▁ % .6f ' % ( case , d / last_arrive ) , file = fout ) NEW_LINE DEDENT DEDENT" ]
codejam_16_02
[ "import java . io . * ; import java . util . * ; public class Round0B { int cases ; int count ( String stack ) { int flips = 0 ; for ( int n = 1 ; n < stack . length ( ) ; n ++ ) { if ( stack . charAt ( n - 1 ) != stack . charAt ( n ) ) flips ++ ; } return flips ; } void process ( Scanner scanner , PrintStream out ) throws IOException { cases = scanner . nextInt ( ) ; scanner . nextLine ( ) ; for ( int curCase = 0 ; curCase < cases ; curCase ++ ) { String stack = scanner . nextLine ( ) . trim ( ) ; out . println ( \" Case ▁ # \" + ( curCase + 1 ) + \" : ▁ \" + count ( stack + \" + \" ) ) ; } } Round0B ( ) throws IOException { Scanner in = new Scanner ( new File ( \" C : \\\\ Users \\\\ Olaf \\\\ Downloads \\\\ B - large . in \" ) ) ; PrintStream out = new PrintStream ( \" out - B - large . txt \" ) ; process ( in , out ) ; in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new Round0B ( ) ; } }", "package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; Scanner sin = new Scanner ( System . in ) ; int n = Integer . parseInt ( sin . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sin . next ( ) ; s += ' + ' ; int counter = 0 ; for ( int j = 0 ; j < s . length ( ) - 1 ; j ++ ) { if ( s . charAt ( j ) != s . charAt ( j + 1 ) ) { counter ++ ; } } System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + counter ) ; } } }", "package gcj2016 . qualif ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoB { public static void main ( final String [ ] args ) { final String base = \" / home / jfortin / workspace - gcj / Codejam2016 / q / ExoB / \" ; final String input = base + \" b1 . in \" ; final String output = base + \" b1 . out \" ; try { final Scanner sc = new Scanner ( new FileReader ( input ) ) ; final PrintWriter pw = new PrintWriter ( output ) ; final int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( \" Test ▁ case ▁ \" + ( c + 1 ) + \" . . . \" ) ; pw . print ( \" Case ▁ # \" + ( c + 1 ) + \" : ▁ \" ) ; test ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( final FileNotFoundException ex ) { Logger . getLogger ( ExoB . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test ( final Scanner sc , final PrintWriter pw ) { String in = sc . next ( ) ; System . out . println ( in ) ; int i = count ( in , in . length ( ) , ' + ' ) ; pw . print ( i ) ; } private static int count ( final String in , final int length , final char c ) { if ( length == 0 ) { return 0 ; } if ( in . charAt ( length - 1 ) == c ) { return count ( in , length - 1 , c ) ; } else { return 1 + count ( in , length - 1 , c == ' + ' ? ' - ' : ' + ' ) ; } } }", "import java . awt . * ; import java . awt . event . * ; import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . text . * ; import java . util . * ; import java . util . concurrent . * ; public class B { static BufferedReader br ; static StringTokenizer st ; static PrintWriter pw ; public static void main ( String [ ] args ) throws Exception { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; pw = new PrintWriter ( new BufferedWriter ( new FileWriter ( \" b . out \" ) ) ) ; final int MAX_CASES = readInt ( ) ; for ( int casenum = 1 ; casenum <= MAX_CASES ; casenum ++ ) { pw . printf ( \" Case ▁ # % d : ▁ \" , casenum ) ; String s = nextToken ( ) ; boolean [ ] good = new boolean [ s . length ( ) ] ; int ret = 0 ; boolean last = true ; for ( int i = 0 ; i < good . length ; i ++ ) { good [ i ] = s . charAt ( i ) == ' + ' ; if ( i > 0 && last != good [ i ] ) { ret ++ ; } last = good [ i ] ; } if ( ! last ) ret ++ ; pw . println ( ret ) ; } pw . close ( ) ; } public static int readInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public static long readLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } public static double readDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } public static String nextToken ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { if ( ! br . ready ( ) ) { pw . close ( ) ; System . exit ( 0 ) ; } st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { System . err . println ( e ) ; System . exit ( 1 ) ; } } return st . nextToken ( ) ; } public static String readLine ( ) { st = null ; try { return br . readLine ( ) ; } catch ( IOException e ) { System . err . println ( e ) ; System . exit ( 1 ) ; return null ; } } }", "import java . io . * ; import java . util . * ; public class revengepancake { private static InputReader in ; private static PrintWriter out ; public static boolean SUBMIT = true ; public static final String NAME = \" B - large \" ; private static void main2 ( ) throws IOException { char [ ] s = in . next ( ) . toCharArray ( ) ; int n = s . length ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) count ++ ; } if ( s [ n - 1 ] == ' - ' ) count ++ ; out . println ( count ) ; } public static void main ( String [ ] args ) throws IOException { if ( SUBMIT ) { in = new InputReader ( new FileInputStream ( new File ( NAME + \" . in \" ) ) ) ; out = new PrintWriter ( new BufferedWriter ( new FileWriter ( NAME + \" . out \" ) ) ) ; } else { in = new InputReader ( System . in ) ; out = new PrintWriter ( System . out , true ) ; } int numCases = in . nextInt ( ) ; for ( int test = 1 ; test <= numCases ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; main2 ( ) ; } out . close ( ) ; System . exit ( 0 ) ; } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }" ]
[ "import sys NEW_LINE with open ( sys . argv [ 1 ] ) as f : NEW_LINE INDENT lines = f . readlines ( ) NEW_LINE DEDENT T = int ( lines [ 0 ] , 10 ) NEW_LINE for tt , l in enumerate ( lines [ 1 : ] ) : NEW_LINE INDENT pancakes = l . strip ( ) NEW_LINE done = False NEW_LINE flips = 0 NEW_LINE while 1 : NEW_LINE INDENT index = pancakes . rfind ( \" - \" ) NEW_LINE if index == - 1 : NEW_LINE INDENT break NEW_LINE DEDENT flips += 1 NEW_LINE new_cakes = \" \" NEW_LINE for i in xrange ( index + 1 ) : NEW_LINE INDENT if pancakes [ i ] == \" + \" : NEW_LINE INDENT new_cakes += \" - \" NEW_LINE DEDENT elif pancakes [ i ] == \" - \" : NEW_LINE INDENT new_cakes += \" + \" NEW_LINE DEDENT else : NEW_LINE INDENT raise Exception ( \" wtf \" ) NEW_LINE DEDENT DEDENT pancakes = new_cakes + pancakes [ index + 1 : ] NEW_LINE DEDENT print ( \" Case ▁ # % d : \" % ( tt + 1 ) ) , flips NEW_LINE DEDENT", "f = open ( ' C : \\\\Users\\\\djspence\\\\Downloads\\\\B - large . in ' , ' r ' ) NEW_LINE tries = int ( f . readline ( ) ) NEW_LINE for i in range ( 0 , tries ) : NEW_LINE INDENT pans = f . readline ( ) . strip ( ) NEW_LINE flips = 0 NEW_LINE for j in range ( 1 , len ( pans ) ) : NEW_LINE INDENT if pans [ j ] != pans [ j - 1 ] : NEW_LINE INDENT flips += 1 NEW_LINE DEDENT DEDENT if pans [ len ( pans ) - 1 ] == \" - \" : NEW_LINE INDENT flips += 1 NEW_LINE DEDENT print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( flips ) ) NEW_LINE DEDENT", "with open ( ' / home / gauravjs / Documents / Google ▁ Code ▁ Jam / 2016Q / B - large . in ' , ' r ' ) as f : NEW_LINE INDENT cases = int ( f . readline ( ) ) NEW_LINE lines = f . readlines ( ) NEW_LINE DEDENT for i in range ( cases ) : NEW_LINE INDENT n = 0 NEW_LINE if lines [ i ] [ - 2 ] == ' - ' : NEW_LINE INDENT n += 1 NEW_LINE DEDENT s = lines [ i ] [ - 2 ] NEW_LINE for j in range ( len ( lines [ i ] ) - 3 , - 1 , - 1 ) : NEW_LINE INDENT if lines [ i ] [ j ] != s : NEW_LINE INDENT s = lines [ i ] [ j ] NEW_LINE n += 1 NEW_LINE DEDENT DEDENT print \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( n ) NEW_LINE DEDENT", "import math NEW_LINE import itertools NEW_LINE import numpy as np NEW_LINE import devtools NEW_LINE def read_case ( f ) : NEW_LINE INDENT return read_letters ( f ) NEW_LINE DEDENT def solve_small ( case ) : NEW_LINE INDENT S = case NEW_LINE S . append ( ' + ' ) NEW_LINE return sum ( S [ i ] != S [ i + 1 ] for i in range ( len ( S ) - 1 ) ) NEW_LINE DEDENT def solve_large ( case ) : NEW_LINE INDENT return solve_small ( case ) NEW_LINE DEDENT def write_case ( f , i , res ) : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ ' % i ) NEW_LINE f . write ( ' % s ' % res ) NEW_LINE f . write ( ' \\n ' ) NEW_LINE DEDENT def read_word ( f ) : NEW_LINE INDENT return next ( f ) . strip ( ) NEW_LINE DEDENT def read_int ( f , b = 10 ) : NEW_LINE INDENT return int ( read_word ( f ) , b ) NEW_LINE DEDENT def read_letters ( f ) : NEW_LINE INDENT return list ( read_word ( f ) ) NEW_LINE DEDENT def read_digits ( f , b = 10 ) : NEW_LINE INDENT return [ int ( x , b ) for x in read_letters ( f ) ] NEW_LINE DEDENT def read_words ( f , d = ' ▁ ' ) : NEW_LINE INDENT return read_word ( f ) . split ( d ) NEW_LINE DEDENT def read_ints ( f , b = 10 , d = ' ▁ ' ) : NEW_LINE INDENT return [ int ( x , b ) for x in read_words ( f , d ) ] NEW_LINE DEDENT def read_floats ( f , d = ' ▁ ' ) : NEW_LINE INDENT return [ float ( x ) for x in read_words ( f , d ) ] NEW_LINE DEDENT def read_arr ( f , R , reader = read_ints , * args , ** kwargs ) : NEW_LINE INDENT return [ reader ( f , * args , ** kwargs ) for i in range ( R ) ] NEW_LINE DEDENT def solve ( solver , fn , out_fn = None ) : NEW_LINE INDENT in_fn = fn + ' . in ' NEW_LINE if out_fn is None : NEW_LINE INDENT out_fn = fn + ' . out ' NEW_LINE DEDENT with open ( in_fn , ' r ' ) as fi : NEW_LINE INDENT with open ( out_fn , ' w ' ) as fo : NEW_LINE INDENT T = read_int ( fi ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT case = read_case ( fi ) NEW_LINE res = solver ( case ) NEW_LINE write_case ( fo , i , res ) NEW_LINE DEDENT DEDENT DEDENT DEDENT from run import * NEW_LINE", "import collections NEW_LINE import math NEW_LINE import re NEW_LINE import sys NEW_LINE INPUT = \" tiny \" NEW_LINE INPUT = \" B - large . in \" NEW_LINE def debug ( * args ) : NEW_LINE INDENT return NEW_LINE sys . stderr . write ( str ( args ) + \" \\n \" ) NEW_LINE DEDENT def do_trial ( s ) : NEW_LINE INDENT count = 0 NEW_LINE last = \" + \" NEW_LINE for c in reversed ( s ) : NEW_LINE INDENT if c != last : NEW_LINE INDENT count += 1 NEW_LINE DEDENT last = c NEW_LINE DEDENT return count NEW_LINE DEDENT f = file ( INPUT ) NEW_LINE T = int ( f . readline ( ) [ : - 1 ] ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT s = f . readline ( ) [ : - 1 ] NEW_LINE v = do_trial ( s ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , v ) NEW_LINE DEDENT" ]
codejam_13_02
[ "import java . util . * ; class Lawnmower { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; int tests = sc . nextInt ( ) ; for ( int test = 1 ; test <= tests ; ++ test ) { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] lawn = new int [ n ] [ m ] ; int [ ] rowMaxes = new int [ n ] ; int [ ] colMaxes = new int [ m ] ; boolean possible = true ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { int a = sc . nextInt ( ) ; lawn [ i ] [ j ] = a ; rowMaxes [ i ] = Math . max ( a , rowMaxes [ i ] ) ; colMaxes [ j ] = Math . max ( a , colMaxes [ j ] ) ; if ( a > 100 ) { possible = false ; } } } for ( int i = 0 ; i < n & possible ; ++ i ) { for ( int j = 0 ; j < m & possible ; ++ j ) { if ( lawn [ i ] [ j ] < rowMaxes [ i ] && lawn [ i ] [ j ] < colMaxes [ j ] ) { possible = false ; } } } System . out . println ( \" Case ▁ # \" + test + \" : ▁ \" + ( possible ? \" YES \" : \" NO \" ) ) ; } } }", "package lawnmower ; public class Lawnmower { public static String [ ] execute ( String [ ] input ) { String [ ] words = { \" NO \" , \" YES \" } ; String [ ] out ; String [ ] splitted ; int n , m ; int [ ] [ ] board ; int result ; int test = 1 ; int ntests ; ntests = Integer . parseInt ( input [ 0 ] ) ; out = new String [ ntests ] ; for ( int i = 1 ; test < 1 + ntests ; ) { splitted = input [ i ++ ] . split ( \" \\\\ s \" ) ; n = Integer . parseInt ( splitted [ 0 ] ) ; m = Integer . parseInt ( splitted [ 1 ] ) ; board = new int [ n ] [ m ] ; for ( int j = 0 ; j < n ; j ++ ) { splitted = input [ i ++ ] . split ( \" \\\\ s \" ) ; for ( int k = 0 ; k < m ; k ++ ) { board [ j ] [ k ] = Integer . parseInt ( splitted [ k ] ) ; } } result = isFeasible ( board , n , m ) ; out [ test - 1 ] = \" Case ▁ # \" + test + \" : ▁ \" + words [ result ] ; System . out . println ( out [ test - 1 ] ) ; test ++ ; } return out ; } private static int isFeasible ( int [ ] [ ] board , int n , int m ) { int [ ] maxrow = new int [ n ] ; int [ ] maxcol = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( board [ i ] [ j ] > maxrow [ i ] ) maxrow [ i ] = board [ i ] [ j ] ; if ( board [ i ] [ j ] > maxcol [ j ] ) maxcol [ j ] = board [ i ] [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( board [ i ] [ j ] < maxrow [ i ] ) if ( board [ i ] [ j ] < maxcol [ j ] ) return 0 ; } } return 1 ; } }", "import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Lawnmower { public static boolean check ( int [ ] [ ] map , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { boolean flag = true , flag2 = true ; for ( int k = 0 ; k < N ; k ++ ) { if ( map [ k ] [ j ] > map [ i ] [ j ] ) { flag = false ; break ; } } for ( int k = 0 ; k < M ; k ++ ) { if ( map [ i ] [ k ] > map [ i ] [ j ] ) { flag2 = false ; break ; } } if ( ! flag && ! flag2 ) return false ; } } return true ; } public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( new FileInputStream ( \" B - large . in \" ) ) ; PrintWriter writer = new PrintWriter ( new FileOutputStream ( \" B - large . out \" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int [ ] [ ] map = new int [ N ] [ M ] ; for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < M ; k ++ ) { map [ j ] [ k ] = in . nextInt ( ) ; } } boolean result = check ( map , N , M ) ; writer . write ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; writer . println ( result ? \" YES \" : \" NO \" ) ; } in . close ( ) ; writer . close ( ) ; } }", "import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class ProblemB { static final String YES = \" YES \" ; static final String NO = \" NO \" ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int T = in . nextInt ( ) ; for ( int cn = 1 ; cn <= T ; cn ++ ) { int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int [ ] [ ] a = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { a [ i ] [ j ] = in . nextInt ( ) ; } } out . println ( String . format ( \" Case ▁ # % d : ▁ % s \" , cn , ( solve ( a ) ? YES : NO ) ) ) ; } out . flush ( ) ; } private static boolean solve ( int [ ] [ ] board ) { int N = board . length ; int M = board [ 0 ] . length ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int a = board [ i ] [ j ] ; int rmax = 0 , cmax = 0 ; for ( int x = 0 ; x < M ; x ++ ) { if ( x != j ) { rmax = Math . max ( rmax , board [ i ] [ x ] ) ; } } for ( int y = 0 ; y < N ; y ++ ) { if ( y != i ) { cmax = Math . max ( cmax , board [ y ] [ j ] ) ; } } if ( rmax > a && cmax > a ) { return false ; } } } return true ; } public static void debug ( Object ... o ) { System . err . println ( Arrays . deepToString ( o ) ) ; } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . StringTokenizer ; public class Lawnmower { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( new File ( \" in \" ) ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( new File ( \" out \" ) ) ) ; StringTokenizer st ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int cn = 1 ; cn <= T ; cn ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int M = Integer . parseInt ( st . nextToken ( ) ) ; int arr [ ] [ ] = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; for ( int j = 0 ; j < M ; j ++ ) { arr [ i ] [ j ] = Integer . parseInt ( st . nextToken ( ) ) ; } } boolean okay = true ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int h = arr [ i ] [ j ] ; boolean ok1 = true ; for ( int k = 0 ; k < N ; k ++ ) ok1 &= arr [ k ] [ j ] <= h ; boolean ok2 = true ; for ( int k = 0 ; k < M ; k ++ ) ok2 &= arr [ i ] [ k ] <= h ; if ( ! ( ok1 || ok2 ) ) okay = false ; } } if ( okay ) bw . append ( \" Case ▁ # \" + cn + \" : ▁ YES \\n \" ) ; else bw . append ( \" Case ▁ # \" + cn + \" : ▁ NO \\n \" ) ; } bw . flush ( ) ; } }" ]
[ "def setup ( infile ) : NEW_LINE INDENT return locals ( ) NEW_LINE DEDENT def reader ( testcase , infile , ** ignore ) : NEW_LINE INDENT P = map ( int , infile . next ( ) . split ( ) ) NEW_LINE S = [ map ( int , infile . next ( ) . split ( ) ) for i in range ( P [ 0 ] ) ] NEW_LINE return locals ( ) NEW_LINE DEDENT def solver ( infile , testcase , N = None , P = None , I = None , T = None , S = None , C = None , ** ignore ) : NEW_LINE INDENT import numpypy as np NEW_LINE S = np . array ( S ) NEW_LINE done = np . zeros ( P , dtype = int ) NEW_LINE for row in range ( P [ 0 ] ) : NEW_LINE INDENT m = S [ row ] . max ( ) NEW_LINE done [ row ] [ S [ row ] == m ] = 1 NEW_LINE DEDENT for col in range ( P [ 1 ] ) : NEW_LINE INDENT m = S [ : , col ] . max ( ) NEW_LINE done [ : , col ] [ S [ : , col ] == m ] = 1 NEW_LINE DEDENT res = ' YES ' if done . sum ( ) == P [ 0 ] * P [ 1 ] else ' NO ' NEW_LINE return ' Case ▁ # % s : ▁ % s \\n ' % ( testcase , res ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE T = int ( sys . stdin . next ( ) ) NEW_LINE common = setup ( sys . stdin ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT sys . stdout . write ( solver ( ** reader ( t , ** common ) ) ) NEW_LINE DEDENT DEDENT", "n = int ( raw_input ( ) ) NEW_LINE for v in range ( n ) : NEW_LINE INDENT board = [ ] NEW_LINE inpline = raw_input ( ) . split ( ' ▁ ' ) NEW_LINE m = int ( inpline [ 0 ] ) NEW_LINE n = int ( inpline [ 1 ] ) NEW_LINE [ board . append ( [ int ( x ) for x in raw_input ( ) . split ( ' ▁ ' ) ] ) for i in range ( m ) ] NEW_LINE bs = sorted ( [ ( i , j ) for i in range ( m ) for j in range ( n ) ] , key = lambda ( i , j ) : board [ i ] [ j ] ) NEW_LINE good = True NEW_LINE for ( i , j ) in bs : NEW_LINE INDENT if board [ i ] [ j ] == ' X ' : continue NEW_LINE if all ( board [ i2 ] [ j ] in [ board [ i ] [ j ] , ' X ' ] for i2 in range ( m ) ) : NEW_LINE INDENT for i2 in range ( m ) : board [ i2 ] [ j ] = ' X ' NEW_LINE DEDENT elif all ( board [ i ] [ j2 ] in [ board [ i ] [ j ] , ' X ' ] for j2 in range ( n ) ) : NEW_LINE INDENT for j2 in range ( n ) : board [ i ] [ j2 ] = ' X ' NEW_LINE DEDENT else : NEW_LINE INDENT good = False NEW_LINE break NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( v + 1 , ' YES ' if good else ' NO ' ) NEW_LINE DEDENT", "import sys NEW_LINE import time NEW_LINE timeit = 1 NEW_LINE debugv = 0 NEW_LINE def main ( ) : NEW_LINE INDENT T = int ( sys . stdin . readline ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT doCase ( case ) NEW_LINE DEDENT DEDENT def doCase ( case ) : NEW_LINE INDENT N , M = [ int ( n ) for n in sys . stdin . readline ( ) . split ( ) ] NEW_LINE lawn = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT row = [ int ( n ) for n in sys . stdin . readline ( ) . split ( ) ] NEW_LINE if len ( row ) != M : NEW_LINE INDENT raise Exception ( \" incorrect ▁ line ▁ length \" ) NEW_LINE DEDENT lawn . append ( row ) NEW_LINE DEDENT lawn_possible = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT row_possible = 1 NEW_LINE for k in range ( N ) : NEW_LINE INDENT if lawn [ k ] [ j ] > lawn [ i ] [ j ] : NEW_LINE INDENT row_possible = 0 NEW_LINE DEDENT DEDENT col_possible = 1 NEW_LINE for k in range ( M ) : NEW_LINE INDENT if lawn [ i ] [ k ] > lawn [ i ] [ j ] : NEW_LINE INDENT col_possible = 0 NEW_LINE DEDENT DEDENT if not ( row_possible or col_possible ) : NEW_LINE INDENT lawn_possible = 0 NEW_LINE DEDENT DEDENT DEDENT result = ' YES ' if lawn_possible else ' NO ' NEW_LINE debug ( \" { } \\n \" . format ( result ) ) NEW_LINE sys . stdout . write ( \" Case ▁ # { } : ▁ { } \\n \" . format ( case , result ) ) NEW_LINE DEDENT def debug ( m ) : NEW_LINE INDENT if debugv : NEW_LINE INDENT sys . stderr . write ( m ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT startTime = time . clock ( ) NEW_LINE main ( ) NEW_LINE if timeit : NEW_LINE INDENT sys . stderr . write ( \" Completed ▁ in ▁ { } ▁ seconds . \\n \" . format ( time . clock ( ) - startTime ) ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE from collections import defaultdict NEW_LINE def readline ( ) : NEW_LINE INDENT s = raw_input ( ) . strip ( ) NEW_LINE while s == \" \" : NEW_LINE INDENT s = raw_input ( ) . strip ( ) NEW_LINE DEDENT return s NEW_LINE DEDENT def readvals ( ) : NEW_LINE INDENT return map ( int , readline ( ) . split ( ) ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT r , c = readvals ( ) NEW_LINE grid = tuple ( readvals ( ) for i in range ( r ) ) NEW_LINE row_min = tuple ( map ( max , grid ) ) NEW_LINE col_min = tuple ( map ( max , zip ( * grid ) ) ) NEW_LINE for y in range ( r ) : NEW_LINE INDENT for x in range ( c ) : NEW_LINE INDENT if grid [ y ] [ x ] != min ( row_min [ y ] , col_min [ x ] ) : NEW_LINE INDENT return \" NO \" NEW_LINE DEDENT DEDENT DEDENT return \" YES \" NEW_LINE DEDENT N = int ( readline ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT sol = solve ( ) NEW_LINE print ( \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( i + 1 , sol ) ) NEW_LINE DEDENT", "filename = ' B - large . in ' NEW_LINE def getCol ( array , c ) : NEW_LINE INDENT return [ row [ c ] for row in array ] NEW_LINE DEDENT def mowable ( array ) : NEW_LINE INDENT for i , line in enumerate ( array ) : NEW_LINE INDENT for j , col in enumerate ( line ) : NEW_LINE INDENT if ( array [ i ] [ j ] < max ( array [ i ] ) ) and ( array [ i ] [ j ] < max ( getCol ( array , j ) ) ) : NEW_LINE INDENT return ' NO ' NEW_LINE DEDENT DEDENT DEDENT return ' YES ' NEW_LINE DEDENT FILE = open ( filename ) NEW_LINE T = int ( FILE . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT rawLine = FILE . readline ( ) . split ( ' ▁ ' ) NEW_LINE rows , cols = int ( rawLine [ 0 ] ) , int ( rawLine [ 1 ] ) NEW_LINE array = [ 0 ] * rows NEW_LINE for r in range ( 0 , rows ) : NEW_LINE INDENT array [ r ] = [ int ( x ) for x in FILE . readline ( ) . split ( ' ▁ ' ) ] NEW_LINE DEDENT print ( ' Case ▁ # ' + str ( i ) + ' : ▁ ' + mowable ( array ) ) NEW_LINE DEDENT" ]
codejam_12_31
[ "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . * ; public class Diamond implements Runnable { final Scanner in ; final PrintWriter out ; public Diamond ( ) throws FileNotFoundException { out = new PrintWriter ( getClass ( ) . getName ( ) . toLowerCase ( ) + \" . out \" ) ; in = new Scanner ( new File ( getClass ( ) . getName ( ) . toLowerCase ( ) + \" . in \" ) ) ; } public static void main ( String [ ] args ) { try { new Diamond ( ) . run ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } } public void run ( ) { int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int testcase = 1 ; testcase <= tests ; testcase ++ ) { int n = in . nextInt ( ) ; List < List < Integer > > edges = new ArrayList < List < Integer > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { List < Integer > cur = new ArrayList < Integer > ( ) ; int mi = in . nextInt ( ) ; for ( int x = 0 ; x < mi ; x ++ ) { cur . add ( in . nextInt ( ) - 1 ) ; } edges . add ( cur ) ; } boolean path = false ; for ( int st = 0 ; st < n ; st ++ ) { Queue < Integer > q = new ArrayDeque < Integer > ( ) ; Set < Integer > v = new HashSet < Integer > ( ) ; v . add ( st ) ; for ( q . offer ( st ) ; ! q . isEmpty ( ) ; q . poll ( ) ) { int c = q . peek ( ) ; for ( int d : edges . get ( c ) ) { if ( v . contains ( d ) ) { path = true ; continue ; } v . add ( d ) ; q . offer ( d ) ; } } } out . println ( \" Case ▁ # \" + testcase + \" : ▁ \" + ( path ? \" Yes \" : \" No \" ) ) ; } out . close ( ) ; in . close ( ) ; } }", "import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class R1CC { static boolean [ ] g ; static int [ ] [ ] p ; static int [ ] d ; public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( new File ( \" A - large . in \" ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( new File ( \" output . out \" ) ) ) ; int t = sc . nextInt ( ) ; X : for ( int i = 0 ; i < t ; i ++ ) { bw . write ( \" Case ▁ # \" + String . valueOf ( i + 1 ) + \" : ▁ \" ) ; int r = 0 ; int n = sc . nextInt ( ) ; d = new int [ n ] ; p = new int [ n ] [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { d [ j ] = sc . nextInt ( ) ; for ( int k = 0 ; k < d [ j ] ; k ++ ) p [ j ] [ k ] = sc . nextInt ( ) - 1 ; } for ( int j = 0 ; j < n ; j ++ ) { g = new boolean [ n ] ; if ( traverse ( j ) ) { bw . write ( \" Yes \" ) ; bw . newLine ( ) ; bw . flush ( ) ; continue X ; } } bw . write ( \" No \" ) ; bw . newLine ( ) ; bw . flush ( ) ; } bw . close ( ) ; } catch ( Exception ex ) { Logger . getLogger ( QA . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } static boolean traverse ( int h ) { for ( int i = 0 ; i < d [ h ] ; i ++ ) { if ( g [ p [ h ] [ i ] ] ) return true ; else g [ p [ h ] [ i ] ] = true ; if ( traverse ( p [ h ] [ i ] ) ) return true ; } return false ; } }", "package codejam . round1c_2012 ; import java . io . File ; import java . io . PrintStream ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Deque ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; import java . util . Set ; public class MainA { static char [ ] mapping = new char [ 256 ] ; static List < Set < Integer > > defs ; public static void main ( String [ ] args ) throws Exception { String f = \" / home / floris / dev / java / Test / src / codejam / round1c _ 2012 / A - large . in \" ; Scanner sc = new Scanner ( new File ( f ) ) ; System . setOut ( new PrintStream ( new File ( f + \" . out \" ) ) ) ; int T = sc . nextInt ( ) ; for ( int i = 1 ; T -- > 0 ; i ++ ) { defs = new ArrayList < Set < Integer > > ( ) ; int classCount = sc . nextInt ( ) ; for ( int j = 0 ; j < classCount ; j ++ ) { Set < Integer > cur = new HashSet < Integer > ( ) ; int ic = sc . nextInt ( ) ; for ( int k = 0 ; k < ic ; k ++ ) cur . add ( sc . nextInt ( ) - 1 ) ; defs . add ( cur ) ; } System . out . printf ( \" Case ▁ # % d : ▁ % s % n \" , i , solve ( ) ) ; } } private static String solve ( ) { for ( int i = 0 ; i < defs . size ( ) ; i ++ ) { List < Integer > contained = new ArrayList < Integer > ( ) ; Deque < Integer > d = new ArrayDeque ( ) ; d . addAll ( defs . get ( i ) ) ; contained . addAll ( defs . get ( i ) ) ; contained . add ( i ) ; while ( ! d . isEmpty ( ) ) { int v = d . remove ( ) ; for ( int k : defs . get ( v ) ) { if ( contained . contains ( k ) ) return \" Yes \" ; d . add ( k ) ; contained . add ( k ) ; } } } return \" No \" ; } }", "import java . io . * ; import java . util . * ; public class A { public static void main ( String args [ ] ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" A - small - attempt0 . in \" ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( \" A - small . out \" ) ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < T ; i ++ ) { boolean adj [ ] [ ] = new boolean [ 1005 ] [ 1005 ] ; int N ; String s = in . readLine ( ) ; StringTokenizer st = new StringTokenizer ( s ) ; N = Integer . parseInt ( st . nextToken ( ) ) ; for ( int r = 0 ; r < N ; r ++ ) { s = in . readLine ( ) ; st = new StringTokenizer ( s ) ; int M = Integer . parseInt ( st . nextToken ( ) ) ; for ( int c = 0 ; c < M ; c ++ ) { int d = Integer . parseInt ( st . nextToken ( ) ) - 1 ; adj [ r ] [ d ] = true ; } } boolean ans = false ; for ( int n = 0 ; n < N ; n ++ ) { LinkedList < Integer > q = new LinkedList < Integer > ( ) ; q . add ( n ) ; boolean v [ ] = new boolean [ N ] ; while ( ! q . isEmpty ( ) ) { int x = q . pollFirst ( ) ; if ( v [ x ] ) { ans = true ; break ; } v [ x ] = true ; for ( int m = 0 ; m < N ; m ++ ) { if ( adj [ x ] [ m ] ) { q . addFirst ( m ) ; } } } } out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + ( ans ? \" Yes \" : \" No \" ) ) ; } out . close ( ) ; } }", "import java . util . ArrayList ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Scanner ; import java . util . Set ; public class Q1 { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int numTests = s . nextInt ( ) ; for ( int test = 0 ; test < numTests ; test ++ ) { System . out . println ( \" Case ▁ # \" + ( test + 1 ) + \" : ▁ \" + getResult ( s ) ) ; } } private static String getResult ( Scanner s ) { int numNodes = s . nextInt ( ) ; List < GraphNode > nodes = new ArrayList < GraphNode > ( numNodes ) ; for ( int i = 0 ; i < numNodes ; i ++ ) { nodes . add ( new GraphNode ( ) ) ; } for ( int i = 0 ; i < numNodes ; i ++ ) { int numChildren = s . nextInt ( ) ; for ( int j = 0 ; j < numChildren ; j ++ ) { int child = s . nextInt ( ) ; nodes . get ( child - 1 ) . childNodes . add ( nodes . get ( i ) ) ; } } for ( GraphNode node : nodes ) { if ( node . childNodes . size ( ) > 1 && node . hasDiamond ( ) ) { return \" Yes \" ; } } return \" No \" ; } public static class GraphNode { public List < GraphNode > childNodes = new LinkedList < GraphNode > ( ) ; public boolean hasDiamond ( ) { List < GraphNode > foundSoFar = new LinkedList < GraphNode > ( ) ; Set < GraphNode > fastLookup = new HashSet < GraphNode > ( ) ; foundSoFar . add ( this ) ; fastLookup . add ( this ) ; while ( foundSoFar . size ( ) > 0 ) { GraphNode node = foundSoFar . remove ( 0 ) ; for ( GraphNode child : node . childNodes ) { if ( fastLookup . contains ( child ) ) return true ; foundSoFar . add ( child ) ; fastLookup . add ( child ) ; } } return false ; } } }" ]
[ "import operator NEW_LINE import itertools NEW_LINE import functools NEW_LINE import math NEW_LINE from collections import deque NEW_LINE def bfs ( i ) : NEW_LINE INDENT res = False NEW_LINE visited = [ 0 ] * ( N + 1 ) NEW_LINE q = deque ( [ node [ i ] ] ) NEW_LINE while len ( q ) : NEW_LINE INDENT n = q . popleft ( ) NEW_LINE if visited [ n [ 0 ] ] : NEW_LINE INDENT res = True NEW_LINE return res NEW_LINE DEDENT else : NEW_LINE INDENT visited [ n [ 0 ] ] = 1 NEW_LINE DEDENT for x in n [ 1 : ] : NEW_LINE INDENT q . append ( node [ x ] ) NEW_LINE DEDENT DEDENT DEDENT fn = open ( '1 . in ' ) NEW_LINE ofn = open ( '1 . out ' , ' w ' ) NEW_LINE TC = int ( fn . readline ( ) ) NEW_LINE for tc in range ( TC ) : NEW_LINE INDENT N = int ( fn . readline ( ) . strip ( ) ) NEW_LINE node = [ None ] * ( N + 1 ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT r = map ( int , fn . readline ( ) . strip ( ) . split ( ) ) NEW_LINE node [ i ] = [ i ] + r [ 1 : ] NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if bfs ( i ) : NEW_LINE INDENT print >> ofn , ' Case ▁ # { } : ▁ { } ' . format ( tc + 1 , ' Yes ' ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print >> ofn , ' Case ▁ # { } : ▁ { } ' . format ( tc + 1 , ' No ' ) NEW_LINE DEDENT DEDENT", "import string NEW_LINE def FindAncestorsDiamond ( i , Parents , Ancestors ) : NEW_LINE INDENT PofI = Parents [ i ] NEW_LINE anI = PofI NEW_LINE for p in PofI : NEW_LINE INDENT if p not in Ancestors : NEW_LINE INDENT if FindAncestorsDiamond ( p , Parents , Ancestors ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if len ( anI & Ancestors [ p ] ) > 0 : NEW_LINE INDENT return True NEW_LINE DEDENT anI = anI | Ancestors [ p ] NEW_LINE DEDENT Ancestors [ i ] = anI NEW_LINE return False NEW_LINE DEDENT def A ( inpfile ) : NEW_LINE INDENT fin = open ( inpfile , ' r ' ) NEW_LINE fout = open ( inpfile + ' . out ' , ' w ' ) NEW_LINE CNT = int ( fin . readline ( ) ) NEW_LINE for iCNT in xrange ( CNT ) : NEW_LINE INDENT Parents = [ ] NEW_LINE N = int ( fin . readline ( ) ) NEW_LINE for iC in xrange ( 1 , N + 1 ) : NEW_LINE INDENT Parents . append ( set ( map ( lambda x : int ( x ) - 1 , fin . readline ( ) . split ( ) [ 1 : ] ) ) ) NEW_LINE DEDENT Ancestors = { } NEW_LINE Answer = False NEW_LINE for iC in xrange ( N ) : NEW_LINE INDENT if FindAncestorsDiamond ( iC , Parents , Ancestors ) : NEW_LINE INDENT Answer = True NEW_LINE break NEW_LINE DEDENT DEDENT text = ' Case ▁ # ' + str ( iCNT + 1 ) + ' : ▁ ' + ( Answer and ' Yes ' or ' No ' ) NEW_LINE print text NEW_LINE fout . write ( text + ' \\n ' ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT A ( ' . . \\\\test\\\\A - large . in ' ) ; NEW_LINE DEDENT", "import itertools NEW_LINE class DiamondFound ( Exception ) : NEW_LINE INDENT pass NEW_LINE DEDENT def find_ancestors ( class_num , inheritance , ancestors ) : NEW_LINE INDENT if ancestors [ class_num ] : NEW_LINE INDENT return NEW_LINE DEDENT direct_fathers = inheritance [ class_num ] NEW_LINE ancestors [ class_num ] . update ( direct_fathers ) NEW_LINE for direct_father in direct_fathers : NEW_LINE INDENT find_ancestors ( direct_father , inheritance , ancestors ) NEW_LINE ancestors_of_direct_father = ancestors [ direct_father ] NEW_LINE before = len ( ancestors [ class_num ] ) NEW_LINE ancestors [ class_num ] . update ( ancestors_of_direct_father ) NEW_LINE after = len ( ancestors [ class_num ] ) NEW_LINE if after - before != len ( ancestors_of_direct_father ) : NEW_LINE INDENT raise DiamondFound ( ) NEW_LINE DEDENT DEDENT DEDENT def solve ( num_of_classes , inheritance ) : NEW_LINE INDENT ancestors = dict ( ( i , set ( ) ) for i in xrange ( 1 , num_of_classes + 1 ) ) NEW_LINE for class_num in inheritance : NEW_LINE INDENT try : NEW_LINE INDENT find_ancestors ( class_num , inheritance , ancestors ) NEW_LINE DEDENT except DiamondFound : NEW_LINE INDENT return ' Yes ' NEW_LINE DEDENT DEDENT return ' No ' NEW_LINE DEDENT def process_files ( in_file , out_file ) : NEW_LINE INDENT num_of_test_cases = int ( in_file . next ( ) . strip ( ) ) NEW_LINE for test_number in xrange ( num_of_test_cases ) : NEW_LINE INDENT num_of_classes = int ( in_file . next ( ) . strip ( ) ) NEW_LINE inheritance = { } NEW_LINE for class_num in xrange ( 1 , num_of_classes + 1 ) : NEW_LINE INDENT params = in_file . next ( ) . strip ( ) . split ( ) NEW_LINE assert len ( params ) - 1 == int ( params [ 0 ] ) NEW_LINE inheritance [ class_num ] = [ int ( i ) for i in params [ 1 : ] ] NEW_LINE DEDENT result = solve ( num_of_classes , inheritance ) NEW_LINE out_file . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( test_number + 1 , result ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT with open ( ' A - large . in ' , ' rb ' ) as in_file : NEW_LINE INDENT with open ( ' A - large . out ' , ' wb ' ) as out_file : NEW_LINE INDENT process_files ( in_file , out_file ) NEW_LINE DEDENT DEDENT DEDENT", "import sys NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE def get ( n , graph ) : NEW_LINE INDENT visited = [ False ] * n NEW_LINE order = [ ] NEW_LINE def dfs ( now ) : NEW_LINE INDENT if visited [ now ] : return NEW_LINE visited [ now ] = True NEW_LINE for x in graph [ now ] : NEW_LINE INDENT dfs ( x ) NEW_LINE DEDENT order . append ( now ) NEW_LINE DEDENT for x in xrange ( n ) : NEW_LINE INDENT dfs ( x ) NEW_LINE DEDENT def check ( now ) : NEW_LINE INDENT checked [ now ] = True NEW_LINE if visited [ now ] : return True NEW_LINE visited [ now ] = True NEW_LINE for x in graph [ now ] : NEW_LINE INDENT if check ( x ) : return True NEW_LINE DEDENT return False NEW_LINE DEDENT checked = [ False ] * n NEW_LINE for x in reversed ( order ) : NEW_LINE INDENT visited = [ False ] * n NEW_LINE if not checked [ x ] and check ( x ) : return ' Yes ' NEW_LINE DEDENT return ' No ' NEW_LINE DEDENT t = input ( ) NEW_LINE for x in xrange ( t ) : NEW_LINE INDENT n = input ( ) NEW_LINE graph = [ [ ] for i in xrange ( n ) ] NEW_LINE for y in xrange ( n ) : NEW_LINE INDENT nums = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE for z in nums [ 1 : ] : NEW_LINE INDENT graph [ y ] . append ( z - 1 ) NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( x + 1 , get ( n , graph ) ) NEW_LINE DEDENT", "def iterative_dfs ( graph , start , path = [ ] ) : NEW_LINE INDENT q = [ start ] NEW_LINE while q : NEW_LINE INDENT v = q . pop ( 0 ) NEW_LINE if v not in path : NEW_LINE INDENT path = path + [ v ] NEW_LINE q = graph [ v ] + q NEW_LINE DEDENT DEDENT return path NEW_LINE DEDENT def iterative_bfs ( graph , start , path = [ ] ) : NEW_LINE INDENT q = [ start ] NEW_LINE while q : NEW_LINE INDENT v = q . pop ( 0 ) NEW_LINE if not v in path : NEW_LINE INDENT path = path + [ v ] NEW_LINE q = q + graph [ v ] NEW_LINE DEDENT DEDENT return path NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE G = dict ( ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT G [ i ] = [ ] NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT line = map ( int , raw_input ( ) . split ( ) ) [ 1 : ] NEW_LINE for j in line : NEW_LINE INDENT G [ i ] . append ( j ) NEW_LINE DEDENT DEDENT parents = dict ( ) NEW_LINE for i in G : NEW_LINE INDENT parents [ i ] = set ( iterative_bfs ( G , i , [ ] ) ) NEW_LINE DEDENT diamond = False NEW_LINE for node in G : NEW_LINE INDENT if diamond : NEW_LINE INDENT break NEW_LINE DEDENT visited = set ( ) NEW_LINE for par in G [ node ] : NEW_LINE INDENT if diamond : NEW_LINE INDENT break NEW_LINE DEDENT for x in parents [ par ] : NEW_LINE INDENT if x in visited : NEW_LINE INDENT diamond = True NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT visited . add ( x ) NEW_LINE DEDENT DEDENT DEDENT DEDENT print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( t , \" Yes \" if diamond else \" No \" ) NEW_LINE DEDENT" ]
codejam_12_32
[ "import java . util . Scanner ; public class iCode2012OutofGas { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int index = 1 ; index <= T ; index ++ ) { System . out . println ( \" Case ▁ # \" + index + \" : \" ) ; double D = in . nextDouble ( ) ; int N = in . nextInt ( ) ; int A = in . nextInt ( ) ; double [ ] time = new double [ N + 1 ] ; double [ ] pos = new double [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { time [ i ] = in . nextDouble ( ) ; pos [ i ] = in . nextDouble ( ) ; } for ( int acc = 0 ; acc < A ; acc ++ ) { double a = in . nextDouble ( ) ; double startmovingat = 0 ; for ( int i = 1 ; i < N ; i ++ ) { startmovingat = Math . max ( startmovingat , time [ i ] - Math . sqrt ( 2 * pos [ i ] / a ) ) ; } double effectivetime = time [ N - 1 ] + ( time [ N ] - time [ N - 1 ] ) / ( pos [ N ] - pos [ N - 1 ] ) * ( D - pos [ N - 1 ] ) ; startmovingat = Math . max ( startmovingat , effectivetime - Math . sqrt ( 2 * D / a ) ) ; System . out . println ( Math . max ( effectivetime , startmovingat + Math . sqrt ( 2 * D / a ) ) ) ; } } } }", "import java . util . Scanner ; public class Gas { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . printf ( \" Case ▁ # % d : \\n \" , C ) ; double D = sc . nextDouble ( ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; if ( N == 1 ) { sc . nextDouble ( ) ; sc . nextDouble ( ) ; for ( int i = 0 ; i < A ; i ++ ) { double a = sc . nextDouble ( ) ; System . out . println ( Math . sqrt ( 2 * D / a ) ) ; } continue ; } double t1 = sc . nextDouble ( ) ; double d1 = sc . nextDouble ( ) ; double t2 = sc . nextDouble ( ) ; double d2 = sc . nextDouble ( ) ; double v = ( d2 - d1 ) / t2 ; for ( int i = 0 ; i < A ; i ++ ) { double a = sc . nextDouble ( ) ; double t_meet = ( v + Math . sqrt ( v * v + 2 * a * d1 ) ) / a ; double d_meet = d1 + v * t_meet ; if ( d_meet >= D ) { System . out . println ( Math . sqrt ( 2 * D / a ) ) ; } else { System . out . println ( t_meet + ( D - d_meet ) / v ) ; } } } } }", "package round1c ; import java . util . Locale ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Locale . setDefault ( Locale . ENGLISH ) ; Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { double d = sc . nextDouble ( ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; double times [ ] = new double [ n ] ; double positions [ ] = new double [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { times [ j ] = sc . nextDouble ( ) ; positions [ j ] = sc . nextDouble ( ) ; } System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : \" ) ; for ( int j = 0 ; j < a ; j ++ ) { double acc = sc . nextDouble ( ) ; double otherTime = n == 1 ? 0 : ( d - positions [ 0 ] ) / ( positions [ 1 ] - positions [ 0 ] ) * ( times [ 1 ] - times [ 0 ] ) + times [ 0 ] ; double myTime = Math . sqrt ( d * 2 / acc ) ; System . out . println ( \" \" + Math . max ( otherTime , myTime ) ) ; } } } }", "import java . util . * ; import java . io . * ; public class B { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; double D ; int N , A ; for ( int caseNo = 1 ; caseNo <= T ; caseNo ++ ) { D = in . nextDouble ( ) ; N = in . nextInt ( ) ; A = in . nextInt ( ) ; double anotherVelocity ; double [ ] t = new double [ N ] ; double [ ] x = new double [ N ] ; double minTime = 0 ; for ( int i = 0 ; i < N ; i ++ ) { t [ i ] = in . nextDouble ( ) ; x [ i ] = in . nextDouble ( ) ; } if ( N == 2 ) { anotherVelocity = ( x [ 1 ] - x [ 0 ] ) / ( t [ 1 ] - t [ 0 ] ) ; minTime = ( D - x [ 0 ] ) / anotherVelocity + t [ 0 ] ; } System . out . println ( \" Case ▁ # \" + caseNo + \" : \" ) ; for ( int i = 0 ; i < A ; i ++ ) { double a = in . nextDouble ( ) ; if ( N == 1 ) { System . out . printf ( \" % .7f \\n \" , Math . sqrt ( 2 * D / a ) ) ; } else { System . out . printf ( \" % .7f \\n \" , Math . max ( Math . sqrt ( 2 * D / a ) , minTime ) ) ; } } } } }" ]
[ "import os , sys , math NEW_LINE inFile = None NEW_LINE outFile = None NEW_LINE def printAnswer ( case , answer ) : NEW_LINE INDENT outFile . write ( ' Case ▁ # { 0 } : ▁ { 1 } \\n ' . format ( case + 1 , answer ) ) NEW_LINE DEDENT def solveSimple ( tc , a , d ) : NEW_LINE INDENT t = math . sqrt ( 2.0 * d / a ) NEW_LINE if t < tc : NEW_LINE INDENT t = tc NEW_LINE DEDENT outFile . write ( ' { 0 } \\n ' . format ( t ) ) NEW_LINE DEDENT def solveCase ( caseNo ) : NEW_LINE INDENT ( d , n , a ) = inFile . readline ( ) . strip ( ) . split ( ) NEW_LINE d = float ( d ) NEW_LINE n = int ( n ) NEW_LINE a = int ( a ) NEW_LINE printAnswer ( caseNo , ' ' ) NEW_LINE xc = d + 100.0 NEW_LINE tc = 0 NEW_LINE if n == 1 : NEW_LINE INDENT ( t0 , x0 ) = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE if x0 > d + ( 0.00000001 ) : NEW_LINE INDENT tc = 0 NEW_LINE DEDENT else : NEW_LINE INDENT tc = t0 NEW_LINE print tc NEW_LINE DEDENT DEDENT if n == 2 : NEW_LINE INDENT ( t0 , x0 ) = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE ( t1 , x1 ) = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE vc = ( x1 - x0 ) / ( t1 - t0 ) NEW_LINE if x1 > d : NEW_LINE INDENT tc = t0 + ( d - x0 ) / vc NEW_LINE DEDENT else : NEW_LINE INDENT tc = t1 NEW_LINE DEDENT DEDENT av = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE for a in av : NEW_LINE INDENT solveSimple ( tc , a , d ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT cases = int ( inFile . readline ( ) . strip ( ) ) NEW_LINE for case in range ( cases ) : NEW_LINE INDENT solveCase ( case ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT inFile = open ( ' in . txt ' , ' rt ' ) NEW_LINE outFile = open ( ' out . txt ' , ' wt ' ) NEW_LINE main ( ) NEW_LINE DEDENT", "from math import * NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for tInput in xrange ( 1 , T + 1 ) : NEW_LINE INDENT line = raw_input ( ) . split ( ) NEW_LINE D = float ( line [ 0 ] ) NEW_LINE N , A = int ( line [ 1 ] ) , int ( line [ 2 ] ) NEW_LINE ts = [ 0 ] * N NEW_LINE xs = [ 0 ] * N NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT line = raw_input ( ) . split ( ) NEW_LINE ts [ i ] , xs [ i ] = float ( line [ 0 ] ) , float ( line [ 1 ] ) NEW_LINE DEDENT accelerations = map ( float , raw_input ( ) . split ( ) ) NEW_LINE print \" Case ▁ # % d : \" % tInput NEW_LINE c = xs [ 0 ] NEW_LINE if N == 1 : v0 = 0 NEW_LINE else : v0 = ( xs [ 1 ] - xs [ 0 ] ) / ( ts [ 1 ] - ts [ 0 ] ) NEW_LINE if v0 == 0 : NEW_LINE INDENT for a in accelerations : NEW_LINE INDENT print sqrt ( 2 * D / a ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT t2 = ( D - c ) / v0 ; NEW_LINE for a in accelerations : NEW_LINE INDENT t2star = ( v0 + sqrt ( v0 * v0 + 2 * a * c ) ) / a NEW_LINE if a < ( 2 * t2 * v0 + 2 * c ) / ( t2 * t2 ) or v0 > a * t2 : print sqrt ( 2 * D / a ) NEW_LINE else : print t2 NEW_LINE DEDENT DEDENT DEDENT", "inp = open ( ' . / B - large . in ' , ' r ' ) NEW_LINE outp = open ( ' . / B . out ' , ' w ' ) NEW_LINE T = int ( inp . readline ( ) ) NEW_LINE def solve ( i ) : NEW_LINE INDENT I = inp . readline ( ) . replace ( ' \\n ' , ' ' ) . split ( ' ▁ ' ) NEW_LINE D = float ( I [ 0 ] ) NEW_LINE N = int ( I [ 1 ] ) NEW_LINE A = int ( I [ 2 ] ) NEW_LINE Ns = [ ] NEW_LINE for n in range ( N ) : NEW_LINE INDENT Ns . append ( [ float ( x ) for x in inp . readline ( ) . replace ( ' \\n ' , ' ' ) . split ( ' ▁ ' ) ] ) NEW_LINE if Ns [ n ] [ 1 ] > D : NEW_LINE INDENT if n != 0 : Ns [ n ] [ 0 ] = Ns [ n - 1 ] [ 0 ] + ( D - Ns [ n - 1 ] [ 1 ] ) / ( Ns [ n ] [ 1 ] - Ns [ n - 1 ] [ 1 ] ) * ( Ns [ n ] [ 0 ] - Ns [ n - 1 ] [ 0 ] ) NEW_LINE Ns [ n ] [ 1 ] = D NEW_LINE DEDENT DEDENT As = [ float ( x ) for x in inp . readline ( ) . replace ( ' \\n ' , ' ' ) . split ( ' ▁ ' ) ] NEW_LINE Mx = [ 0 ] * A NEW_LINE for n in range ( N ) : NEW_LINE INDENT for a in range ( A ) : NEW_LINE INDENT Mx [ a ] = max ( Mx [ a ] , Ns [ n ] [ 0 ] - ( 2 * Ns [ n ] [ 1 ] / As [ a ] ) ** 0.5 ) NEW_LINE DEDENT DEDENT outp . write ( ' Case ▁ # ' + str ( i ) + ' : \\n ' ) NEW_LINE for a in range ( A ) : NEW_LINE INDENT x = ( 2 * D / As [ a ] ) ** 0.5 + Mx [ a ] NEW_LINE outp . write ( str ( x ) + ' \\n ' ) NEW_LINE DEDENT DEDENT for k in range ( T ) : NEW_LINE INDENT solve ( k + 1 ) NEW_LINE DEDENT inp . close ( ) NEW_LINE outp . close ( ) NEW_LINE", "import sys NEW_LINE from fractions import Fraction NEW_LINE from math import sqrt NEW_LINE line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == 1 NEW_LINE ntc = int ( fields [ 0 ] ) NEW_LINE def solve ( d , a , other_car ) : NEW_LINE INDENT wait_time = Fraction ( 0 ) NEW_LINE first = True NEW_LINE for time , distance in other_car : NEW_LINE INDENT if distance > d : NEW_LINE INDENT if first : NEW_LINE INDENT break NEW_LINE DEDENT time = last_time + ( time - last_time ) * ( d - last_distance ) / ( distance - last_distance ) NEW_LINE distance = d NEW_LINE DEDENT first = False NEW_LINE arrival_time = sqrt ( 2 * distance / a ) NEW_LINE if arrival_time < time : NEW_LINE INDENT cur_wait_time = time - arrival_time NEW_LINE DEDENT else : NEW_LINE INDENT cur_wait_time = Fraction ( 0 ) NEW_LINE DEDENT if cur_wait_time > wait_time : NEW_LINE INDENT wait_time = cur_wait_time NEW_LINE DEDENT last_time , last_distance = time , distance NEW_LINE DEDENT arrival_time = sqrt ( 2 * d / a ) NEW_LINE return wait_time + arrival_time NEW_LINE DEDENT for tc in range ( 1 , ntc + 1 ) : NEW_LINE INDENT line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == 3 NEW_LINE d = Fraction ( fields [ 0 ] ) NEW_LINE n = int ( fields [ 1 ] ) NEW_LINE a = int ( fields [ 2 ] ) NEW_LINE other_car = [ ] NEW_LINE for _ in range ( n ) : NEW_LINE INDENT line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == 2 NEW_LINE time = Fraction ( fields [ 0 ] ) NEW_LINE distance = Fraction ( fields [ 1 ] ) NEW_LINE other_car . append ( ( time , distance ) ) NEW_LINE DEDENT line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == a NEW_LINE print ( ' Case ▁ # { 0 } : ' . format ( tc ) ) NEW_LINE for i in range ( a ) : NEW_LINE INDENT accel = Fraction ( fields [ i ] ) NEW_LINE ans = solve ( d , accel , other_car ) NEW_LINE print ( ans ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE import re NEW_LINE import math NEW_LINE import fractions NEW_LINE f = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE num = int ( f . readline ( ) ) NEW_LINE for z in range ( num ) : NEW_LINE INDENT d , n , m = f . readline ( ) . split ( ) NEW_LINE d = float ( d ) NEW_LINE n = int ( n ) NEW_LINE m = int ( m ) NEW_LINE tx = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT tx . append ( [ float ( x ) for x in f . readline ( ) . split ( ) ] ) NEW_LINE DEDENT tx . sort ( ) NEW_LINE a = [ float ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE if len ( tx ) > 1 : NEW_LINE INDENT tf = tx [ 0 ] [ 0 ] + ( d - tx [ 0 ] [ 1 ] ) * ( tx [ 1 ] [ 0 ] - tx [ 0 ] [ 0 ] ) / ( tx [ 1 ] [ 1 ] - tx [ 0 ] [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT tf = 0 NEW_LINE DEDENT print ' Case ▁ # { } : ' . format ( z + 1 ) NEW_LINE for x in a : NEW_LINE INDENT print max ( math . sqrt ( 2 * d / x ) , tf ) NEW_LINE DEDENT sys . stdout . flush ( ) NEW_LINE DEDENT" ]
codejam_17_41
[ "package round2 ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int N = sc . nextInt ( ) ; int P = sc . nextInt ( ) ; int [ ] cant = new int [ P ] ; for ( int i = 0 ; i < N ; i ++ ) { cant [ sc . nextInt ( ) % P ] ++ ; } int ans = cant [ 0 ] ; if ( P == 2 ) { ans += ( cant [ 1 ] + 1 ) / 2 ; } else if ( P == 3 ) { ans += Math . min ( cant [ 1 ] , cant [ 2 ] ) ; int left = Math . max ( cant [ 1 ] , cant [ 2 ] ) - Math . min ( cant [ 1 ] , cant [ 2 ] ) ; ans += ( left + 2 ) / 3 ; } else { ans += Math . min ( cant [ 1 ] , cant [ 3 ] ) ; int left = Math . max ( cant [ 1 ] , cant [ 3 ] ) - Math . min ( cant [ 1 ] , cant [ 3 ] ) ; ans += cant [ 2 ] / 2 ; boolean extra2 = cant [ 2 ] % 2 == 1 ; if ( left >= 2 && extra2 ) { ans ++ ; left -= 2 ; extra2 = false ; } if ( extra2 ) left ++ ; ans += ( left + 3 ) / 4 ; } System . out . println ( \" Case ▁ # \" + caze + \" : ▁ \" + ans ) ; } } }", "import java . util . * ; class A { public static void main ( String [ ] arg ) { Scanner sc = new Scanner ( System . in ) ; int TT = sc . nextInt ( ) ; for ( int ii = 1 ; ii <= TT ; ++ ii ) { int N = sc . nextInt ( ) ; int P = sc . nextInt ( ) ; int [ ] M = new int [ 5 ] ; for ( int i = 0 ; i < N ; ++ i ) { int G = sc . nextInt ( ) ; M [ G % P ] ++ ; } int ans = 1 + M [ 0 ] ; if ( P == 2 ) { ans += M [ 1 ] / 2 ; if ( M [ 1 ] % 2 == 0 ) ans -- ; } else if ( P == 3 ) { int min = Math . min ( M [ 1 ] , M [ 2 ] ) ; int left = Math . max ( M [ 1 ] , M [ 2 ] ) - min ; if ( left % 3 == 0 ) ans -- ; left /= 3 ; ans += min + left ; } else if ( P == 4 ) { while ( M [ 2 ] >= 2 ) { ans ++ ; M [ 2 ] -= 2 ; } while ( M [ 1 ] > 0 && M [ 3 ] > 0 ) { ans ++ ; M [ 1 ] -- ; M [ 3 ] -- ; } if ( M [ 2 ] == 1 ) { if ( M [ 1 ] % 4 >= 2 ) { ans ++ ; M [ 1 ] -= 2 ; M [ 2 ] -- ; } else if ( M [ 3 ] % 4 >= 2 ) { ans ++ ; M [ 3 ] -= 2 ; M [ 2 ] -- ; } } int threes = M [ 3 ] / 4 ; int ones = M [ 1 ] / 4 ; ans += threes + ones ; if ( M [ 1 ] % 4 == 0 && M [ 3 ] % 4 == 0 && M [ 2 ] % 2 == 0 ) { ans -- ; } } System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , ii , ans ) ; } } }", "import java . util . * ; public class Main { public static void main ( String args [ ] ) { ( new Main ( ) ) . solve ( ) ; } void solve ( ) { Scanner cin = new Scanner ( System . in ) ; int T = cin . nextInt ( ) ; for ( int C = 1 ; C <= T ; ++ C ) { int N = cin . nextInt ( ) ; int P = cin . nextInt ( ) ; int count [ ] = new int [ P ] ; for ( int i = 0 ; i < N ; ++ i ) { ++ count [ cin . nextInt ( ) % P ] ; } int ret = count [ 0 ] ; count [ 0 ] = 0 ; if ( P == 2 ) { ret += ( count [ 1 ] + 1 ) / 2 ; } else if ( P == 3 ) { int min = Math . min ( count [ 1 ] , count [ 2 ] ) ; ret += min ; count [ 1 ] -= min ; count [ 2 ] -= min ; ret += ( count [ 1 ] + 2 ) / 3 ; ret += ( count [ 2 ] + 2 ) / 3 ; } else if ( P == 4 ) { { int two = Math . min ( count [ 1 ] , count [ 3 ] ) ; ret += two ; count [ 1 ] -= two ; count [ 3 ] -= two ; } { int two = count [ 2 ] / 2 ; ret += two ; count [ 2 ] -= two * 2 ; } { int three = Math . min ( count [ 2 ] , Math . max ( count [ 1 ] / 2 , count [ 3 ] / 2 ) ) ; ret += three ; count [ 2 ] -= three ; if ( count [ 1 ] > 0 ) { count [ 1 ] -= three * 2 ; } if ( count [ 3 ] > 0 ) { count [ 3 ] -= three * 2 ; } } { if ( count [ 1 ] > 0 || count [ 2 ] > 0 || count [ 3 ] > 0 ) { ++ ret ; } } } System . out . println ( \" Case ▁ # \" + C + \" : ▁ \" + ret ) ; } cin . close ( ) ; } }" ]
[ "import numpy as np NEW_LINE inname = \" input . txt \" NEW_LINE outname = \" output . txt \" NEW_LINE with open ( inname , ' r ' ) as f : NEW_LINE INDENT cases = int ( f . readline ( ) ) NEW_LINE for tc in range ( 1 , cases + 1 ) : NEW_LINE INDENT line = f . readline ( ) . strip ( ) . split ( ' ▁ ' ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE P = int ( line [ 1 ] ) NEW_LINE Pi = [ ] NEW_LINE R = [ 0 ] * P NEW_LINE line = f . readline ( ) . strip ( ) . split ( ' ▁ ' ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT Pi . append ( int ( line [ i ] ) ) NEW_LINE R [ Pi [ i ] % P ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE if P == 2 : NEW_LINE INDENT ans = R [ 0 ] + ( R [ 1 ] + 1 ) // 2 NEW_LINE DEDENT elif P == 3 : NEW_LINE INDENT ans = R [ 0 ] NEW_LINE if R [ 1 ] < R [ 2 ] : NEW_LINE INDENT a = R [ 1 ] NEW_LINE b = R [ 2 ] NEW_LINE DEDENT else : NEW_LINE INDENT a = R [ 2 ] NEW_LINE b = R [ 1 ] NEW_LINE DEDENT ans += a NEW_LINE b -= a NEW_LINE ans += ( b + 2 ) // 3 NEW_LINE DEDENT else : NEW_LINE INDENT ans = R [ 0 ] NEW_LINE if R [ 1 ] < R [ 3 ] : NEW_LINE INDENT a = R [ 1 ] NEW_LINE b = R [ 3 ] NEW_LINE DEDENT else : NEW_LINE INDENT a = R [ 3 ] NEW_LINE b = R [ 1 ] NEW_LINE DEDENT c = R [ 2 ] NEW_LINE ans += c // 2 NEW_LINE c %= 2 NEW_LINE ans += a NEW_LINE b -= a NEW_LINE if c == 1 and b >= 2 : NEW_LINE INDENT c -= 1 NEW_LINE b -= 2 NEW_LINE ans += 1 NEW_LINE DEDENT ans += b // 4 NEW_LINE b %= 4 NEW_LINE if c + b > 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( \" Case ▁ # % d : ▁ % d \" % ( tc , ans ) ) NEW_LINE DEDENT DEDENT", "def maximizeFreshChocolate ( N , P , groups ) : NEW_LINE INDENT remainingGroups = groups NEW_LINE result = 0 NEW_LINE while len ( remainingGroups ) > 0 : NEW_LINE INDENT optimalSets = { } NEW_LINE optimalCounts = { } NEW_LINE for index in xrange ( len ( remainingGroups ) ) : NEW_LINE INDENT tempOptimalSets = { } NEW_LINE tempOptimalCounts = { } NEW_LINE for remainder in optimalCounts : NEW_LINE INDENT possibleRemainder = ( remainder + remainingGroups [ index ] ) % P NEW_LINE if optimalCounts [ remainder ] + 1 < tempOptimalCounts . get ( possibleRemainder , 10 ** 18 ) : NEW_LINE INDENT tempOptimalSets [ possibleRemainder ] = optimalSets [ remainder ] + [ index ] NEW_LINE tempOptimalCounts [ possibleRemainder ] = optimalCounts [ remainder ] + 1 NEW_LINE DEDENT DEDENT tempOptimalSets [ remainingGroups [ index ] % P ] = [ index ] NEW_LINE tempOptimalCounts [ remainingGroups [ index ] % P ] = 1 NEW_LINE for remainder in tempOptimalCounts : NEW_LINE INDENT if tempOptimalCounts [ remainder ] < optimalCounts . get ( remainder , 10 ** 18 ) : NEW_LINE INDENT optimalSets [ remainder ] = tempOptimalSets [ remainder ] NEW_LINE optimalCounts [ remainder ] = tempOptimalCounts [ remainder ] NEW_LINE DEDENT DEDENT DEDENT if 0 in optimalCounts : NEW_LINE INDENT result += 1 NEW_LINE remainingGroups = [ remainingGroups [ i ] for i in xrange ( len ( remainingGroups ) ) if i not in optimalSets [ 0 ] ] NEW_LINE DEDENT else : NEW_LINE INDENT return result + 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT with open ( ' . . / inputs / A - large . in ' ) as infile : NEW_LINE INDENT with open ( ' . . / outputs / A - large . out ' , ' wb ' ) as outfile : NEW_LINE INDENT cases = int ( infile . readline ( ) ) NEW_LINE for i in xrange ( cases ) : NEW_LINE INDENT [ N , P ] = map ( int , infile . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE groups = map ( int , infile . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE outfile . write ( ' Case ▁ # ' + str ( i + 1 ) + ' : ▁ ' ) NEW_LINE outfile . write ( str ( maximizeFreshChocolate ( N , P , groups ) ) ) NEW_LINE outfile . write ( ' \\n ' ) NEW_LINE DEDENT DEDENT DEDENT", "inputF = open ( ' A - large . in ' , ' r ' ) NEW_LINE output = open ( ' A - large . out ' , ' w ' ) NEW_LINE numCases = int ( inputF . readline ( ) ) NEW_LINE def getFreshGroups ( groups , p ) : NEW_LINE INDENT count = 0 NEW_LINE groups = [ i % p for i in groups ] NEW_LINE count += groups . count ( 0 ) NEW_LINE groups = [ g for g in groups if g != 0 ] NEW_LINE if p == 2 and len ( groups ) > 0 : NEW_LINE INDENT count += ( len ( groups ) + 1 ) / 2 NEW_LINE DEDENT elif p == 3 and len ( groups ) > 0 : NEW_LINE INDENT minMod = min ( groups . count ( 1 ) , groups . count ( 2 ) ) NEW_LINE count += minMod NEW_LINE remaining = max ( groups . count ( 1 ) , groups . count ( 2 ) ) - min ( groups . count ( 1 ) , groups . count ( 2 ) ) NEW_LINE count += ( remaining + 2 ) / 3 NEW_LINE DEDENT elif p == 4 and len ( groups ) > 0 : NEW_LINE INDENT count += ( groups . count ( 2 ) ) / 2 NEW_LINE extraTwo = ( ( groups . count ( 2 ) % 2 ) == 1 ) NEW_LINE minMod = min ( groups . count ( 1 ) , groups . count ( 3 ) ) NEW_LINE count += minMod NEW_LINE remaining = max ( groups . count ( 1 ) , groups . count ( 3 ) ) - min ( groups . count ( 1 ) , groups . count ( 3 ) ) NEW_LINE if extraTwo : NEW_LINE INDENT count += 1 + ( remaining + 1 ) / 4 NEW_LINE DEDENT else : NEW_LINE INDENT count += ( remaining + 3 ) / 4 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT for i in range ( numCases ) : NEW_LINE INDENT n , p = inputF . readline ( ) . split ( ) NEW_LINE groups = [ int ( j ) for j in inputF . readline ( ) . split ( ) ] NEW_LINE numFresh = getFreshGroups ( groups , int ( p ) ) NEW_LINE output . write ( ' Case ▁ # ' + str ( i + 1 ) + ' : ▁ ' + str ( numFresh ) + ' \\n ' ) NEW_LINE DEDENT inputF . close ( ) NEW_LINE output . close ( ) NEW_LINE", "from itertools import * NEW_LINE from collections import * NEW_LINE from functools import * NEW_LINE from operator import floordiv , mul , sub NEW_LINE strategies = { 2 : [ ( 1 , ( 1 , 0 ) ) , ( 1 , ( 0 , 2 ) ) ] , 3 : [ ( 1 , ( 1 , 0 , 0 ) ) , ( 1 , ( 0 , 1 , 1 ) ) , ( 1 , ( 0 , 3 , 0 ) ) , ( 1 , ( 0 , 0 , 3 ) ) ] , 4 : [ ( 1 , ( 1 , 0 , 0 , 0 ) ) , ( 1 , ( 0 , 1 , 0 , 1 ) ) , ( 1 , ( 0 , 0 , 2 , 0 ) ) , ( 1 , ( 0 , 2 , 1 , 0 ) ) , ( 1 , ( 0 , 0 , 1 , 2 ) ) , ( 1 , ( 0 , 4 , 0 , 0 ) ) , ( 1 , ( 0 , 0 , 0 , 4 ) ) , ] } NEW_LINE T = int ( input ( ) . strip ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT print ( \" Case ▁ # { } : ▁ \" . format ( t + 1 ) , end = \" \" ) NEW_LINE ngroups , packsize = map ( int , input ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE groups = map ( int , input ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE strategy = strategies [ packsize ] NEW_LINE modgroups = list ( repeat ( 0 , packsize ) ) NEW_LINE for i in groups : NEW_LINE INDENT modgroups [ i % packsize ] += 1 NEW_LINE DEDENT score = 0 NEW_LINE for value , operation in strategy : NEW_LINE INDENT repetitions = min ( map ( lambda a , b : a // b if b != 0 else float ( ' inf ' ) , modgroups , operation ) ) NEW_LINE modgroups = list ( map ( sub , modgroups , map ( mul , operation , repeat ( repetitions ) ) ) ) NEW_LINE score += value * repetitions NEW_LINE DEDENT if sum ( modgroups ) > 0 : NEW_LINE INDENT score += 1 NEW_LINE DEDENT print ( score ) NEW_LINE DEDENT", "from math import ceil , floor NEW_LINE numInputs = int ( input ( ) ) NEW_LINE for i in range ( numInputs ) : NEW_LINE INDENT N , P = [ int ( num ) for num in input ( ) . split ( \" ▁ \" ) ] NEW_LINE G = [ int ( num ) for num in input ( ) . split ( \" ▁ \" ) ] NEW_LINE numsMod = { } NEW_LINE for j in range ( P ) : NEW_LINE INDENT numsMod [ j ] = 0 NEW_LINE DEDENT for g in G : NEW_LINE INDENT numsMod [ g % P ] += 1 NEW_LINE DEDENT if P == 2 : NEW_LINE INDENT print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( numsMod [ 0 ] + ceil ( numsMod [ 1 ] / 2.0 ) ) ) NEW_LINE continue NEW_LINE DEDENT if P == 3 : NEW_LINE INDENT smaller = min ( numsMod [ 1 ] , numsMod [ 2 ] ) NEW_LINE larger = max ( numsMod [ 1 ] , numsMod [ 2 ] ) NEW_LINE diff = larger - smaller NEW_LINE print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( numsMod [ 0 ] + smaller + ceil ( diff / 3.0 ) ) ) NEW_LINE continue NEW_LINE DEDENT total = numsMod [ 0 ] NEW_LINE total += floor ( numsMod [ 2 ] / 2.0 ) NEW_LINE smaller = min ( numsMod [ 1 ] , numsMod [ 3 ] ) NEW_LINE larger = max ( numsMod [ 1 ] , numsMod [ 3 ] ) NEW_LINE diff = larger - smaller NEW_LINE total += smaller NEW_LINE if numsMod [ 2 ] % 2 == 1 : NEW_LINE INDENT total += 1 NEW_LINE if diff > 2 : NEW_LINE INDENT total += ceil ( ( diff - 2 ) / 4.0 ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT total += ceil ( diff / 4.0 ) NEW_LINE DEDENT print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( total ) ) NEW_LINE DEDENT" ]
codejam_10_53
[ "import java . io . File ; import java . util . Arrays ; import java . util . Scanner ; public class C { public static void main ( String [ ] args ) throws Exception { int [ ] arr = new int [ 1 << 22 ] ; long [ ] cost = new long [ 1 << 20 ] ; for ( int i = 1 ; i < ( 1 << 20 ) ; i ++ ) { cost [ i ] = cost [ i - 1 ] + i * i ; } Scanner s = new Scanner ( new File ( \" C . in \" ) ) ; int T = s . nextInt ( ) ; for ( int tc = 1 ; tc <= T ; tc ++ ) { int C = s . nextInt ( ) ; Arrays . fill ( arr , 0 ) ; for ( int i = 0 ; i < C ; i ++ ) arr [ s . nextInt ( ) + 2000000 ] = s . nextInt ( ) ; long ans = 0 ; boolean ok = false ; while ( ! ok ) { ok = true ; for ( int i = 0 ; i < 4000000 ; i ++ ) { if ( arr [ i ] > 1 ) { ok = false ; int j = i ; while ( arr [ j ] >= arr [ i ] ) j ++ ; j -- ; if ( ( j - i ) % 2 == 1 ) j -- ; int v = arr [ i ] ; int val = v * ( j - i + 1 ) ; int loc = ( i + j ) / 2 ; ans -= v * cost [ ( j - i + 1 ) / 2 ] ; ans += cost [ val / 2 ] ; for ( int k = i ; k <= j ; k ++ ) arr [ k ] -= v ; for ( int shift = 0 ; shift <= val / 2 ; shift ++ ) { if ( shift == 0 && val % 2 == 1 ) arr [ loc ] ++ ; if ( shift > 0 ) { arr [ loc + shift ] ++ ; arr [ loc - shift ] ++ ; } } } } } System . out . println ( \" Case ▁ # \" + tc + \" : ▁ \" + ans ) ; } } }", "import java . util . * ; import java . io . * ; import java . math . * ; public class Sol_slow { public void doMain ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; int caseCnt = sc . nextInt ( ) ; long time = System . currentTimeMillis ( ) ; for ( int caseNum = 1 ; caseNum <= caseCnt ; caseNum ++ ) { pw . print ( \" Case ▁ # \" + caseNum + \" : ▁ \" ) ; int C = sc . nextInt ( ) ; int [ ] A = new int [ C ] ; int [ ] B = new int [ C ] ; int N = 0 ; for ( int i = 0 ; i < C ; i ++ ) { A [ i ] = sc . nextInt ( ) ; B [ i ] = sc . nextInt ( ) ; N += B [ i ] ; } int [ ] x = new int [ N ] ; int pos = 0 ; for ( int i = 0 ; i < C ; i ++ ) for ( int j = 0 ; j < B [ i ] ; j ++ ) x [ pos ++ ] = A [ i ] ; int cnt = 0 ; while ( true ) { boolean find = false ; Arrays . sort ( x ) ; for ( int i = 0 ; i + 1 < N ; i ++ ) if ( x [ i ] == x [ i + 1 ] ) { x [ i ] -- ; x [ i + 1 ] ++ ; find = true ; cnt ++ ; break ; } if ( ! find ) break ; } pw . println ( cnt ) ; System . out . println ( \" Finished ▁ testcase ▁ \" + caseNum + \" , ▁ time ▁ = ▁ \" + ( System . currentTimeMillis ( ) - time ) ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) throws Exception { ( new Sol_slow ( ) ) . doMain ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . TreeSet ; public class C { public void solve ( ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" C - small - attempt1 . in \" ) ) ; PrintWriter out = new PrintWriter ( \" C - small - attempt1 . out \" ) ; int testN = in . nextInt ( ) ; for ( int test = 1 ; test <= testN ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int c = in . nextInt ( ) ; int [ ] a = new int [ 4000000 ] ; TreeSet < Integer > pos = new TreeSet < Integer > ( ) ; for ( int i = 0 ; i < c ; i ++ ) { int p = in . nextInt ( ) + 2000000 ; int v = in . nextInt ( ) ; a [ p ] += v ; if ( v > 1 ) { pos . add ( p ) ; } } int r = 0 ; while ( pos . size ( ) != 0 ) { int q = pos . pollFirst ( ) ; a [ q ] -= 2 ; a [ q - 1 ] ++ ; if ( a [ q - 1 ] == 2 ) { pos . add ( q - 1 ) ; } a [ q + 1 ] ++ ; if ( a [ q + 1 ] == 2 ) { pos . add ( q + 1 ) ; } if ( a [ q ] >= 2 ) { pos . add ( q ) ; } r ++ ; } out . println ( r ) ; } in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new C ( ) . solve ( ) ; } }", "package y2010 . round3 . c ; import java . util . Scanner ; public class C { Scanner in ; public C ( ) { int CASE = 1 ; String [ ] name = { \" sample \" , \" small \" , \" large \" } ; System . setIn ( this . getClass ( ) . getResourceAsStream ( name [ CASE ] + \" . in \" ) ) ; in = new Scanner ( System . in ) ; int _t = in . nextInt ( ) ; for ( int _l = 1 ; _l <= _t ; _l ++ ) { int [ ] x = new int [ 3000001 ] ; int min = 3000001 ; int c = in . nextInt ( ) ; for ( int i = 0 ; i < c ; i ++ ) { int p = in . nextInt ( ) + 1500000 ; int v = in . nextInt ( ) ; x [ p ] = v ; min = Math . min ( min , p ) ; } int times = 0 ; while ( true ) { boolean finish = true ; for ( int i = min ; i < x . length ; i ++ ) { if ( x [ i ] > 1 ) { finish = false ; x [ i - 1 ] += 1 ; x [ i + 1 ] += 1 ; x [ i ] -= 2 ; times ++ ; if ( x [ i - 1 ] > 1 ) min = i - 1 ; break ; } } if ( finish ) break ; } String ans = \" \" + times ; System . out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , _l , ans ) ; } } public static void main ( String [ ] args ) { new C ( ) ; } }" ]
[ "import sys NEW_LINE f = open ( sys . argv [ 1 ] ) NEW_LINE casenum = int ( f . readline ( ) ) NEW_LINE for casei in xrange ( casenum ) : NEW_LINE INDENT res = 0 NEW_LINE C = int ( f . readline ( ) ) NEW_LINE corners = { } NEW_LINE for z in xrange ( C ) : NEW_LINE INDENT _ = f . readline ( ) . splitlines ( ) [ 0 ] . split ( ) NEW_LINE x , n = ( int ( x ) for x in _ ) NEW_LINE corners [ x ] = n NEW_LINE DEDENT while corners . values ( ) . count ( 1 ) != len ( corners ) : NEW_LINE INDENT needmoves = [ k for k , v in corners . iteritems ( ) if v > 1 ] NEW_LINE for x in needmoves : NEW_LINE INDENT n = corners [ x ] NEW_LINE if n == 2 : NEW_LINE INDENT del corners [ x ] NEW_LINE DEDENT else : NEW_LINE INDENT corners [ x ] = n - 2 NEW_LINE DEDENT corners [ x - 1 ] = corners . get ( x - 1 , 0 ) + 1 NEW_LINE corners [ x + 1 ] = corners . get ( x + 1 , 0 ) + 1 NEW_LINE res += 1 NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( casei + 1 , res ) NEW_LINE DEDENT", "infile = open ( \" C - small . in \" , \" r \" ) NEW_LINE T = int ( infile . readline ( ) . strip ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT C = int ( infile . readline ( ) . strip ( ) ) NEW_LINE corners = { } NEW_LINE needs_moves = False NEW_LINE for c in range ( C ) : NEW_LINE INDENT line = infile . readline ( ) . strip ( ) NEW_LINE P = int ( line . split ( ' ▁ ' ) [ 0 ] ) NEW_LINE V = int ( line . split ( ' ▁ ' ) [ 1 ] ) NEW_LINE corners [ P ] = V NEW_LINE if ( V > 1 ) : NEW_LINE INDENT needs_moves = True NEW_LINE DEDENT DEDENT total_moves = 0 NEW_LINE while needs_moves : NEW_LINE INDENT newcorners = { } NEW_LINE needs_moves = False NEW_LINE for key , value in sorted ( corners . items ( ) ) : NEW_LINE INDENT if value == 1 : NEW_LINE INDENT if not newcorners . has_key ( key ) : NEW_LINE INDENT newcorners [ key ] = 0 NEW_LINE DEDENT newcorners [ key ] += 1 NEW_LINE DEDENT elif value > 1 : NEW_LINE INDENT needs_moves = True NEW_LINE moves = int ( value / 2 ) NEW_LINE total_moves += moves NEW_LINE if not newcorners . has_key ( key - 1 ) : NEW_LINE INDENT newcorners [ key - 1 ] = 0 NEW_LINE DEDENT if newcorners . has_key ( key + 1 ) : NEW_LINE INDENT assert False NEW_LINE DEDENT newcorners [ key - 1 ] += moves NEW_LINE newcorners [ key + 1 ] = moves NEW_LINE if value > moves * 2 : NEW_LINE INDENT if not newcorners . has_key ( key ) : NEW_LINE INDENT newcorners [ key ] = 0 NEW_LINE DEDENT newcorners [ key ] += 1 NEW_LINE DEDENT DEDENT DEDENT corners = newcorners NEW_LINE DEDENT print \" Case ▁ # \" + str ( t + 1 ) + \" : ▁ \" + str ( total_moves ) NEW_LINE DEDENT", "for casenum in xrange ( 1 , 1 + int ( raw_input ( ) ) ) : NEW_LINE INDENT C = int ( raw_input ( ) ) NEW_LINE vs = [ [ int ( z ) for z in raw_input ( ) . split ( ) ] for j in xrange ( C ) ] NEW_LINE ve = { } NEW_LINE for v in vs : NEW_LINE INDENT ve [ v [ 0 ] ] = v [ 1 ] NEW_LINE DEDENT v = ve NEW_LINE switches = 0 NEW_LINE v1 = [ z for z in ve . keys ( ) if v [ z ] > 1 ] NEW_LINE while ( len ( v1 ) > 0 ) : NEW_LINE INDENT for loc in v1 : NEW_LINE INDENT if not ( v . has_key ( loc - 1 ) ) : NEW_LINE INDENT v [ loc - 1 ] = 0 NEW_LINE DEDENT if not ( v . has_key ( loc + 1 ) ) : NEW_LINE INDENT v [ loc + 1 ] = 0 NEW_LINE DEDENT v [ loc - 1 ] += v [ loc ] >> 1 NEW_LINE v [ loc + 1 ] += v [ loc ] >> 1 NEW_LINE switches += v [ loc ] >> 1 NEW_LINE v [ loc ] &= 1 NEW_LINE DEDENT v1 = [ z for z in ve . keys ( ) if v [ z ] > 1 ] NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( casenum , switches ) NEW_LINE DEDENT", "from collections import defaultdict NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT for case in xrange ( input ( ) ) : NEW_LINE INDENT cnt = defaultdict ( int ) NEW_LINE C = int ( raw_input ( ) ) NEW_LINE for _ in xrange ( C ) : NEW_LINE INDENT p , v = [ int ( s ) for s in raw_input ( ) . split ( ) ] NEW_LINE cnt [ p ] = v NEW_LINE DEDENT res = 0 NEW_LINE while True : NEW_LINE INDENT found = None NEW_LINE for p in cnt : NEW_LINE INDENT if cnt [ p ] > 1 : NEW_LINE INDENT found = p NEW_LINE break NEW_LINE DEDENT DEDENT if found is None : NEW_LINE INDENT break NEW_LINE DEDENT cnt [ p ] -= 2 NEW_LINE if cnt [ p ] == 0 : NEW_LINE INDENT del cnt [ p ] NEW_LINE DEDENT cnt [ p - 1 ] += 1 NEW_LINE cnt [ p + 1 ] += 1 NEW_LINE res += 1 NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case + 1 , res ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return [ foo ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE def run_test ( test ) : NEW_LINE INDENT C = readint ( ) NEW_LINE a = dict ( [ readarray ( int ) for i in xrange ( C ) ] ) NEW_LINE done = False NEW_LINE res = 0 NEW_LINE while not done : NEW_LINE INDENT done = True NEW_LINE a2 = { } NEW_LINE for k in a . keys ( ) : NEW_LINE INDENT v = a [ k ] NEW_LINE if v == 1 : NEW_LINE INDENT a2 [ k ] = ( a2 [ k ] + 1 ) if ( k in a2 ) else 1 NEW_LINE continue NEW_LINE DEDENT done = False NEW_LINE a2 [ k - 1 ] = ( a2 [ k - 1 ] + v / 2 ) if ( k - 1 in a2 ) else v / 2 NEW_LINE a2 [ k + 1 ] = ( a2 [ k + 1 ] + v / 2 ) if ( k + 1 in a2 ) else v / 2 NEW_LINE res += v / 2 NEW_LINE if v % 2 == 1 : NEW_LINE INDENT a2 [ k ] = ( a2 [ k ] + 1 ) if ( k in a2 ) else 1 NEW_LINE DEDENT DEDENT a = a2 NEW_LINE DEDENT return res NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( \" Test ▁ % d \\n \" % ( test + 1 ) ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( test + 1 , run_test ( test ) ) NEW_LINE DEDENT" ]
codejam_09_22
[ "import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class Number { private static boolean run ( final char [ ] s , final int [ ] d1 , final int [ ] d , final int k ) { if ( k == s . length ) { for ( int i = 1 ; i < 10 ; ++ i ) { if ( d1 [ i ] != d [ i ] ) { return false ; } } return true ; } while ( true ) { char c = s [ k ] ; if ( c > '9' ) { s [ k ] = '0' ; return false ; } int x = c - '0' ; if ( d1 [ x ] < d [ x ] ) { ++ d1 [ x ] ; if ( run ( s , d1 , d , k + 1 ) ) { return true ; } -- d1 [ x ] ; } ++ s [ k ] ; } } public static void main ( final String ... args ) throws IOException { final String fname = \" B - large \" ; final Scanner sc = new Scanner ( new File ( fname + \" . in \" ) ) ; final PrintWriter pw = new PrintWriter ( fname + \" . out \" ) ; final int t = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int i = 0 ; i < t ; ++ i ) { final char [ ] s = ( '0' + sc . nextLine ( ) ) . toCharArray ( ) ; final int [ ] d = new int [ 10 ] ; for ( char c : s ) { d [ c - '0' ] ++ ; } ++ s [ s . length - 1 ] ; final int [ ] d1 = new int [ 10 ] ; if ( ! run ( s , d1 , d , 0 ) ) { throw new RuntimeException ( ) ; } final String r = String . valueOf ( s ) ; pw . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + ( s [ 0 ] == '0' ? r . substring ( 1 ) : r ) ) ; } pw . close ( ) ; } }", "import java . util . Scanner ; import java . util . Arrays ; import java . io . File ; import java . io . PrintWriter ; import java . io . FileNotFoundException ; public class B { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" B . in \" ) ) ; PrintWriter out = new PrintWriter ( \" B . out \" ) ; int t = in . nextInt ( ) ; in . nextLine ( ) ; for ( int tn = 0 ; tn < t ; tn ++ ) { out . println ( \" Case ▁ # \" + ( tn + 1 ) + \" : ▁ \" + solve ( in ) ) ; } out . close ( ) ; } private static String solve ( Scanner in ) { String s = in . nextLine ( ) . trim ( ) ; if ( s . length ( ) == 1 ) return s + \"0\" ; char [ ] a = s . toCharArray ( ) ; int i = s . length ( ) - 2 ; while ( i > - 1 && a [ i ] >= a [ i + 1 ] ) i -- ; if ( i == - 1 ) { Arrays . sort ( a ) ; i = 0 ; while ( a [ i ] == '0' ) i ++ ; char p = a [ i ] ; a [ i ] = '0' ; return p + new String ( a ) ; } else { int j = s . length ( ) - 1 ; while ( a [ j ] <= a [ i ] ) j -- ; char t = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = t ; Arrays . sort ( a , i + 1 , a . length ) ; return new String ( a ) ; } } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . Arrays ; public class B { public static final String FILE_NAME = \" B - large \" ; public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new FileReader ( FILE_NAME + \" . in \" ) ) ; BufferedWriter output = new BufferedWriter ( new FileWriter ( FILE_NAME + \" . out \" ) ) ; final int T = Integer . parseInt ( input . readLine ( ) ) ; for ( int t = 0 ; t < T ; t ++ ) { output . append ( \" Case ▁ # \" + ( t + 1 ) + \" : ▁ \" ) ; char [ ] chars = input . readLine ( ) . trim ( ) . toCharArray ( ) ; int k = chars . length - 1 ; while ( k > 0 && chars [ k ] <= chars [ k - 1 ] ) k -- ; if ( k > 0 ) { int p = k ; char min = '9' + 1 ; for ( int q = k ; q < chars . length ; q ++ ) { if ( chars [ q ] > chars [ k - 1 ] && chars [ q ] < min ) { min = chars [ q ] ; p = q ; } } char c = chars [ p ] ; chars [ p ] = chars [ k - 1 ] ; chars [ k - 1 ] = c ; Arrays . sort ( chars , k , chars . length ) ; for ( int x = 0 ; x < chars . length ; x ++ ) output . append ( chars [ x ] ) ; } else { Arrays . sort ( chars ) ; int j = 0 ; while ( chars [ j ] == '0' ) j ++ ; output . append ( chars [ j ] ) ; for ( int x = 0 ; x < j + 1 ; x ++ ) output . append ( '0' ) ; for ( int x = j + 1 ; x < chars . length ; x ++ ) output . append ( chars [ x ] ) ; } output . append ( ' \\n ' ) ; } output . close ( ) ; } }", "import java . io . BufferedReader ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . StringTokenizer ; public class B { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; public static void main ( String args [ ] ) throws Exception { in = new BufferedReader ( new InputStreamReader ( new FileInputStream ( \" b . in \" ) ) ) ; out = new PrintWriter ( new OutputStreamWriter ( new FileOutputStream ( \" b . out \" ) ) ) ; int T = nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { String n = \"0\" + next ( ) ; int cnts [ ] = new int [ 10 ] ; String ans ; PLoop : for ( int p = n . length ( ) - 1 ; ; p -- ) { int c = n . charAt ( p ) - '0' ; ++ cnts [ c ] ; for ( int nc = c + 1 ; nc < 10 ; ++ nc ) { if ( cnts [ nc ] > 0 ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( n . substring ( 0 , p ) ) ; sb . append ( ( char ) ( '0' + nc ) ) ; -- cnts [ nc ] ; for ( int i = 0 ; i < 10 ; ++ i ) { while ( cnts [ i ] > 0 ) { sb . append ( ( char ) ( '0' + i ) ) ; -- cnts [ i ] ; } } ans = sb . toString ( ) ; break PLoop ; } } if ( p == 0 ) { throw new AssertionError ( ) ; } } out . println ( \" Case ▁ # \" + ( t + 1 ) + \" : ▁ \" + new BigInteger ( ans ) . toString ( ) ) ; } in . close ( ) ; out . close ( ) ; } static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } }", "import java . io . BufferedReader ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . StringTokenizer ; public class B { String test ( ) { char [ ] s = ( \"0\" + nextToken ( ) ) . toCharArray ( ) ; int [ ] cnt = new int [ 128 ] ; fori : for ( int i = s . length - 1 ; i >= 0 ; i -- ) { cnt [ s [ i ] ] ++ ; for ( char j = ( char ) ( s [ i ] + 1 ) ; j <= '9' ; j ++ ) { if ( cnt [ j ] > 0 ) { s [ i ] = j ; cnt [ j ] -- ; for ( int k = i + 1 ; k < cnt . length ; k ++ ) { for ( char d = '0' ; d <= '9' ; d ++ ) { if ( cnt [ d ] > 0 ) { s [ k ] = d ; cnt [ d ] -- ; break ; } } } break fori ; } } } return new BigInteger ( new String ( s ) ) . toString ( ) ; } private void solve ( ) { int n = nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + test ( ) ) ; } } PrintWriter out ; BufferedReader br ; StringTokenizer st ; private void run ( ) { try { br = new BufferedReader ( new FileReader ( \" B - large . in \" ) ) ; out = new PrintWriter ( \" B - large . out \" ) ; solve ( ) ; out . close ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } String nextToken ( ) { try { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } catch ( IOException e ) { return \" \" ; } } int nextInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public static void main ( String [ ] args ) { new B ( ) . run ( ) ; } }" ]
[ "import sys NEW_LINE def m ( tab , i ) : NEW_LINE INDENT m = '9' NEW_LINE for x in tab : NEW_LINE INDENT if x > i : NEW_LINE INDENT m = min ( m , x ) NEW_LINE DEDENT DEDENT return m NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT def next_line ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) NEW_LINE DEDENT n = int ( next_line ( ) ) NEW_LINE for nr in range ( 1 , n + 1 ) : NEW_LINE INDENT line = next_line ( ) NEW_LINE t = [ '0' ] + list ( line ) [ : - 1 ] NEW_LINE rev = t [ : : - 1 ] NEW_LINE prev = rev [ 0 ] NEW_LINE for pos , i in enumerate ( rev [ 1 : ] ) : NEW_LINE INDENT p = pos + 2 NEW_LINE if prev > i : NEW_LINE INDENT subtab = rev [ : p ] NEW_LINE x = m ( subtab , i ) NEW_LINE subtab . remove ( x ) NEW_LINE ret = sorted ( subtab , reverse = True ) + [ x ] + rev [ p : ] NEW_LINE break NEW_LINE DEDENT prev = i NEW_LINE DEDENT ret = \" \" . join ( ret [ : : - 1 ] ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( nr , int ( ret ) ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "from skynet . math . numbers import digits NEW_LINE def dijkstra_next_perm ( iterable ) : NEW_LINE INDENT iterable = list ( iterable ) NEW_LINE N = len ( iterable ) NEW_LINE i = len ( iterable ) - 1 NEW_LINE while iterable [ i - 1 ] >= iterable [ i ] : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT j = N NEW_LINE while iterable [ j - 1 ] <= iterable [ i - 1 ] : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT iterable [ i - 1 ] , iterable [ j - 1 ] = iterable [ j - 1 ] , iterable [ i - 1 ] NEW_LINE i += 1 NEW_LINE j = N NEW_LINE while i < j : NEW_LINE INDENT iterable [ i - 1 ] , iterable [ j - 1 ] = iterable [ j - 1 ] , iterable [ i - 1 ] NEW_LINE i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT return iterable NEW_LINE DEDENT def next_number ( n ) : NEW_LINE INDENT p = str ( n ) NEW_LINE try : NEW_LINE INDENT m = int ( ' ' . join ( dijkstra_next_perm ( p ) ) ) NEW_LINE DEDENT except IndexError : NEW_LINE INDENT return int ( ' ' . join ( dijkstra_next_perm ( p + '0' ) ) ) NEW_LINE DEDENT if m <= n : NEW_LINE INDENT return int ( ' ' . join ( dijkstra_next_perm ( p + '0' ) ) ) NEW_LINE DEDENT return m NEW_LINE DEDENT with open ( ' B - large . in ' ) as file : NEW_LINE INDENT t = int ( file . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT n = int ( file . readline ( ) ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } \" . format ( i + 1 , next_number ( n ) ) ) NEW_LINE DEDENT DEDENT", "inp = open ( \" d : \\\\incoming\\\\b - large . in \" ) NEW_LINE outp = open ( \" b - large . out \" , \" w \" ) NEW_LINE def next_permutation ( seq , pred = cmp ) : NEW_LINE INDENT def reverse ( seq , start , end ) : NEW_LINE INDENT end -= 1 NEW_LINE if end <= start : NEW_LINE INDENT return NEW_LINE DEDENT while True : NEW_LINE INDENT seq [ start ] , seq [ end ] = seq [ end ] , seq [ start ] NEW_LINE if start == end or start + 1 == end : NEW_LINE INDENT return NEW_LINE DEDENT start += 1 NEW_LINE end -= 1 NEW_LINE DEDENT DEDENT if not seq : return [ ] NEW_LINE try : NEW_LINE INDENT seq [ 0 ] NEW_LINE DEDENT except TypeError : NEW_LINE INDENT raise TypeError ( \" seq ▁ must ▁ allow ▁ random ▁ access . \" ) NEW_LINE DEDENT first = 0 NEW_LINE last = len ( seq ) NEW_LINE seq = seq [ : ] NEW_LINE if last == 1 : return [ ] NEW_LINE while True : NEW_LINE INDENT next = last - 1 NEW_LINE while True : NEW_LINE INDENT next1 = next NEW_LINE next -= 1 NEW_LINE if pred ( seq [ next ] , seq [ next1 ] ) < 0 : NEW_LINE INDENT mid = last - 1 NEW_LINE while not ( pred ( seq [ next ] , seq [ mid ] ) < 0 ) : NEW_LINE INDENT mid -= 1 NEW_LINE DEDENT seq [ next ] , seq [ mid ] = seq [ mid ] , seq [ next ] NEW_LINE reverse ( seq , next1 , last ) NEW_LINE return seq [ : ] NEW_LINE DEDENT if next == first : NEW_LINE INDENT return [ ] NEW_LINE DEDENT DEDENT DEDENT return [ ] NEW_LINE DEDENT cases = int ( inp . readline ( ) ) NEW_LINE for cc in xrange ( cases ) : NEW_LINE INDENT n = list ( inp . readline ( ) . strip ( ) ) NEW_LINE m = \" \" . join ( next_permutation ( n ) ) NEW_LINE if m == \" \" : NEW_LINE INDENT n . sort ( ) NEW_LINE lz = 0 NEW_LINE while lz < len ( n ) and n [ lz ] == \"0\" : NEW_LINE INDENT lz += 1 NEW_LINE DEDENT ret = str ( n [ lz ] ) + \" \" . join ( [ \"0\" ] * ( lz + 1 ) + n [ lz + 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT ret = \" \" . join ( m ) NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % s \" % ( cc + 1 , ret ) NEW_LINE outp . write ( \" Case ▁ # % d : ▁ % s \\n \" % ( cc + 1 , ret ) ) NEW_LINE DEDENT outp . close ( ) NEW_LINE", "import collections NEW_LINE rl = raw_input NEW_LINE T = int ( rl ( ) ) NEW_LINE for cas in xrange ( 1 , T + 1 ) : NEW_LINE INDENT n = rl ( ) . strip ( ) . lstrip ( \"0\" ) [ : : - 1 ] NEW_LINE cnt = { } NEW_LINE need = { } NEW_LINE for i in \"0123456789\" : NEW_LINE INDENT cnt [ i ] = 0 NEW_LINE need [ i ] = 0 NEW_LINE DEDENT for char in n : NEW_LINE INDENT cnt [ char ] += 1 NEW_LINE DEDENT used = \" \" . join ( i for i in \"0123456789\" if cnt [ i ] > 0 ) NEW_LINE ans = \" Blah \" NEW_LINE for i in xrange ( len ( n ) ) : NEW_LINE INDENT if ans != \" Blah \" : break NEW_LINE cnt [ n [ i ] ] -= 1 NEW_LINE need [ n [ i ] ] += 1 NEW_LINE j = used . find ( n [ i ] ) + 1 NEW_LINE while j < len ( used ) : NEW_LINE INDENT if need [ used [ j ] ] >= 1 : NEW_LINE INDENT c = used [ j ] NEW_LINE need [ c ] -= 1 NEW_LINE if sum ( need . values ( ) ) <= i : NEW_LINE INDENT ans = n [ : i : - 1 ] + c + \"0\" * ( i - sum ( need . values ( ) ) ) NEW_LINE for v in \"0123456789\" : NEW_LINE INDENT ans += v * need [ v ] NEW_LINE DEDENT break NEW_LINE DEDENT need [ c ] += 1 NEW_LINE DEDENT j += 1 NEW_LINE DEDENT DEDENT if ans == \" Blah \" : NEW_LINE INDENT if used [ 0 ] == \"0\" : NEW_LINE INDENT used = used [ 1 : ] NEW_LINE DEDENT ans = used [ 0 ] + \"0\" * ( len ( n ) - sum ( need . values ( ) ) + 1 ) NEW_LINE need [ used [ 0 ] ] -= 1 NEW_LINE for v in \"0123456789\" : NEW_LINE INDENT ans += v * need [ v ] NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : \" % cas , ans NEW_LINE DEDENT", "def next_number ( digits ) : NEW_LINE INDENT if len ( digits ) == 1 : NEW_LINE INDENT return None NEW_LINE DEDENT if len ( digits ) == 2 : NEW_LINE INDENT return ( digits [ 1 ] , digits [ 0 ] ) if digits [ 1 ] > digits [ 0 ] else None NEW_LINE DEDENT rearrange = next_number ( digits [ 1 : ] ) NEW_LINE if rearrange is not None : NEW_LINE INDENT digits [ 1 : ] = rearrange NEW_LINE return digits NEW_LINE DEDENT larger = [ d for d in digits if d > digits [ 0 ] ] NEW_LINE if larger : NEW_LINE INDENT min_larger = min ( larger ) NEW_LINE taildigits = delone ( digits [ : ] , min_larger ) NEW_LINE taildigits . sort ( ) NEW_LINE taildigits . insert ( 0 , min_larger ) NEW_LINE return taildigits NEW_LINE DEDENT return None NEW_LINE DEDENT def delone ( taildigits , n ) : NEW_LINE INDENT for i in range ( len ( taildigits ) ) : NEW_LINE INDENT if taildigits [ i ] == n : NEW_LINE INDENT del taildigits [ i ] NEW_LINE break NEW_LINE DEDENT DEDENT return taildigits NEW_LINE DEDENT with open ( ' B - large . in ' ) as f : NEW_LINE INDENT o = open ( ' bnumberout . txt ' , ' w ' ) NEW_LINE cases = int ( f . next ( ) ) NEW_LINE for i in range ( 1 , cases + 1 ) : NEW_LINE INDENT o . write ( ' Case ▁ # % d : ▁ ' % i ) NEW_LINE strn = f . next ( ) . strip ( ) NEW_LINE digits = [ int ( d ) for d in strn ] NEW_LINE nextdigits = next_number ( digits ) NEW_LINE if nextdigits is None : NEW_LINE INDENT leader = min ( [ d for d in digits if d > 0 ] ) NEW_LINE digits = delone ( digits , leader ) NEW_LINE digits . sort ( ) NEW_LINE nextdigits = [ leader , 0 ] + digits NEW_LINE DEDENT nextnumber = ' ' . join ( [ str ( d ) for d in nextdigits ] ) NEW_LINE o . write ( nextnumber + ' \\n ' ) NEW_LINE DEDENT o . close ( ) NEW_LINE DEDENT" ]
codejam_15_01
[ "package codejam15 ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( new FileReader ( new File ( \" a . in \" ) ) ) ; PrintWriter pw = new PrintWriter ( \" a . out \" ) ; int tc = sc . nextInt ( ) ; for ( int t = 1 ; t <= tc ; t ++ ) { int l = sc . nextInt ( ) ; String s = sc . nextLine ( ) ; int cnt = 0 ; int added = 0 ; for ( int i = 0 ; i <= l ; i ++ ) { if ( i > cnt ) { int need = i - cnt ; added += need ; cnt += need ; } cnt += s . charAt ( i + 1 ) - '0' ; } pw . printf ( \" Case ▁ # % d : ▁ % d \\n \" , t , added ) ; } sc . close ( ) ; pw . close ( ) ; } }", "import java . io . * ; import java . util . * ; import java . util . concurrent . * ; public class A { int n ; String s ; String solve ( ) { int up = 0 ; int ans = 0 ; for ( int i = 0 ; i <= n ; i ++ ) { int count = s . charAt ( i ) - '0' ; if ( count == 0 ) { continue ; } if ( up < i ) { ans += i - up ; up = i ; } up += count ; } return \" \" + ans ; } public A ( Scanner in ) { n = in . nextInt ( ) ; s = in . next ( ) ; } private static String fileName = A . class . getSimpleName ( ) . replaceFirst ( \" _ . * \" , \" \" ) . toLowerCase ( ) ; private static String inputFileName = fileName + \" . in \" ; private static String outputFileName = fileName + \" . out \" ; public static void main ( String [ ] args ) throws IOException , InterruptedException , ExecutionException { ExecutorService executor = Executors . newFixedThreadPool ( 4 ) ; Locale . setDefault ( Locale . US ) ; Scanner in = new Scanner ( new File ( inputFileName ) ) ; PrintWriter out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; @ SuppressWarnings ( \" unchecked \" ) Future < String > [ ] outputs = new Future [ tests ] ; for ( int t = 0 ; t < tests ; t ++ ) { final A testCase = new A ( in ) ; final int testCaseNumber = t ; outputs [ t ] = executor . submit ( new Callable < String > ( ) { @ Override public String call ( ) { String answer = testCase . solve ( ) ; String printed = \" Case ▁ # \" + ( testCaseNumber + 1 ) + \" : ▁ \" + answer ; System . out . println ( printed ) ; return printed ; } } ) ; } for ( int t = 0 ; t < tests ; t ++ ) { out . println ( outputs [ t ] . get ( ) ) ; } in . close ( ) ; out . close ( ) ; executor . shutdown ( ) ; } }", "import java . util . * ; import java . io . * ; public class StandingOvation { static final String filename = \" C : / Users / Kevin / algs4 / CodeJam / StandingOvation / A - large . in \" ; static final String output = \" largefinaloutput . txt \" ; public static int numOfFriends ( int [ ] shylevels ) { int total = 0 ; int ret = 0 ; for ( int i = 0 ; i < shylevels . length ; ++ i ) { ret = Math . max ( ret , i - total ) ; total += shylevels [ i ] ; } return ret ; } public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( new FileInputStream ( new File ( filename ) ) ) ; int no_of_times = sc . nextInt ( ) ; for ( int i = 0 ; i < no_of_times ; ++ i ) { sc . nextInt ( ) ; char [ ] shylevelchars = sc . nextLine ( ) . toCharArray ( ) ; int [ ] shylevels = new int [ shylevelchars . length - 1 ] ; for ( int j = 1 ; j < shylevelchars . length ; ++ j ) { shylevels [ j - 1 ] = Integer . parseInt ( ( ( Character ) shylevelchars [ j ] ) . toString ( ) ) ; } FileOutputStream fos = new FileOutputStream ( output , true ) ; fos . write ( ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + numOfFriends ( shylevels ) + \" \\n \" ) . getBytes ( ) ) ; fos . close ( ) ; } sc . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }", "package round0 ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; public class StandingOvation { private static FileWriter writer ; public static void main ( String [ ] args ) throws IOException { File file = new File ( \" round0 / A - large . in \" ) ; BufferedReader reader = new BufferedReader ( new FileReader ( file ) ) ; File outputFile = new File ( \" round0 / output - ovation . txt \" ) ; writer = new FileWriter ( outputFile ) ; int numberOfPerformances = Integer . parseInt ( reader . readLine ( ) ) ; for ( int show = 1 ; show <= numberOfPerformances ; show ++ ) { String [ ] split = reader . readLine ( ) . split ( \" ▁ \" ) ; int length = Integer . parseInt ( split [ 0 ] ) ; char [ ] audience = split [ 1 ] . toCharArray ( ) ; generateOutput ( \" Case ▁ # \" + show + \" : ▁ \" + invitedFriends ( length , audience ) ) ; } reader . close ( ) ; writer . close ( ) ; } private static int invitedFriends ( int length , char [ ] audience ) { int friends = 0 ; int totalStanding = 0 ; for ( int i = 0 ; i < length + 1 ; i ++ ) { totalStanding += Integer . parseInt ( \" \" + audience [ i ] ) ; if ( totalStanding < i + 1 ) { friends ++ ; totalStanding ++ ; } } return friends ; } private static void generateOutput ( String line ) throws IOException { System . out . println ( line ) ; writer . write ( line + \" \\n \" ) ; } }", "package gcj2015 . qualif ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoA { public static void main ( final String [ ] args ) { final String base = \" / home / jean / gcj2015 / q / ExoA / \" ; final String input = base + \" b1 . in \" ; final String output = base + \" b1 . out \" ; try { final Scanner sc = new Scanner ( new FileReader ( input ) ) ; final PrintWriter pw = new PrintWriter ( output ) ; final int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( \" Test ▁ case ▁ \" + ( c + 1 ) + \" . . . \" ) ; pw . print ( \" Case ▁ # \" + ( c + 1 ) + \" : ▁ \" ) ; test ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( final FileNotFoundException ex ) { Logger . getLogger ( ExoA . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test ( final Scanner sc , final PrintWriter pw ) { final int Smax = sc . nextInt ( ) ; final String levels = sc . next ( ) ; final int [ ] ls = new int [ levels . length ( ) ] ; int ts = 0 ; int toAdd = 0 ; for ( int i = 0 ; i < levels . length ( ) ; i ++ ) { if ( ts < i ) { toAdd += ( i - ts ) ; ts = i ; } ls [ i ] = levels . charAt ( i ) - '0' ; ts += ls [ i ] ; } pw . print ( toAdd ) ; } }" ]
[ "import sys NEW_LINE def load_case ( path ) : NEW_LINE INDENT case_list = [ ] NEW_LINE with open ( path , ' r ' ) as fh : NEW_LINE INDENT case_num = int ( fh . readline ( ) . strip ( \" \\n \" ) ) NEW_LINE for k in range ( 0 , case_num ) : NEW_LINE INDENT case = [ ] NEW_LINE s_max , digits = filter ( None , fh . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE s_max = int ( s_max ) NEW_LINE for j in range ( 0 , s_max + 1 ) : NEW_LINE INDENT case . append ( ord ( digits [ j ] ) - ord ( '0' ) ) NEW_LINE DEDENT case_list . append ( case ) NEW_LINE DEDENT DEDENT return case_list NEW_LINE DEDENT def calculate_case ( case ) : NEW_LINE INDENT people_num = 0 NEW_LINE num_to_invite = 0 NEW_LINE for k in range ( 0 , len ( case ) ) : NEW_LINE INDENT new_invite = k - people_num NEW_LINE new_invite = new_invite if new_invite > 0 else 0 NEW_LINE num_to_invite += new_invite NEW_LINE people_num += ( case [ k ] + new_invite ) NEW_LINE DEDENT return num_to_invite NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT if len ( sys . argv ) != 3 : NEW_LINE INDENT print ' Usage : ▁ q1 ▁ input ▁ output ' NEW_LINE sys . exit ( ) NEW_LINE DEDENT input_file = sys . argv [ 1 ] NEW_LINE output_file = sys . argv [ 2 ] NEW_LINE case_list = load_case ( input_file ) NEW_LINE with open ( output_file , ' w ' ) as fh : NEW_LINE INDENT for k in range ( 0 , len ( case_list ) ) : NEW_LINE INDENT num = calculate_case ( case_list [ k ] ) NEW_LINE fh . write ( \" Case ▁ # % d : ▁ % d \\n \" % ( k + 1 , num ) ) NEW_LINE DEDENT DEDENT DEDENT", "DESCRIPTION = \"\"\" STRNEWLINE \"\"\" NEW_LINE import os NEW_LINE import sys NEW_LINE import argparse NEW_LINE def perr ( msg ) : NEW_LINE INDENT sys . stderr . write ( \" % s \" % msg ) NEW_LINE sys . stderr . flush ( ) NEW_LINE DEDENT def pinfo ( msg ) : NEW_LINE INDENT sys . stdout . write ( \" % s \" % msg ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT def runcmd ( cmd ) : NEW_LINE INDENT perr ( \" % s \\n \" % cmd ) NEW_LINE os . system ( cmd ) NEW_LINE DEDENT def getargs ( ) : NEW_LINE INDENT parser = argparse . ArgumentParser ( description = DESCRIPTION , formatter_class = argparse . RawTextHelpFormatter ) NEW_LINE parser . add_argument ( ' infile ' , type = str , help = ' input ▁ file ' ) NEW_LINE parser . add_argument ( ' outfile ' , type = str , nargs = ' ? ' , default = None , help = ' output ▁ file ' ) NEW_LINE return parser . parse_args ( ) NEW_LINE DEDENT def solve ( Smax , Scnt ) : NEW_LINE INDENT ret = 0 NEW_LINE acc = Scnt [ 0 ] NEW_LINE for i in range ( 1 , len ( Scnt ) ) : NEW_LINE INDENT rest = i - acc NEW_LINE if rest > 0 : NEW_LINE INDENT ret += rest NEW_LINE acc += rest NEW_LINE DEDENT acc += Scnt [ i ] NEW_LINE DEDENT return ret NEW_LINE DEDENT def main ( args ) : NEW_LINE INDENT if None == args . outfile : NEW_LINE INDENT outfile = sys . stdout NEW_LINE DEDENT else : NEW_LINE INDENT outfile = open ( args . outfile , \" w \" ) NEW_LINE DEDENT with open ( args . infile ) as infile : NEW_LINE INDENT T = int ( infile . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT [ Smax , Scnt ] = infile . readline ( ) . split ( ) NEW_LINE Smax = int ( Smax ) NEW_LINE Scnt = [ int ( cnt ) for cnt in list ( Scnt ) ] NEW_LINE outfile . write ( \" Case ▁ # % d : ▁ % d \\n \" % ( i , solve ( Smax , Scnt ) ) ) NEW_LINE DEDENT DEDENT if None != args . outfile : NEW_LINE INDENT outfile . close ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( getargs ( ) ) NEW_LINE DEDENT", "f_in = open ( ' file . in ' ) NEW_LINE f_out = open ( ' file . out ' , ' w ' ) NEW_LINE cases = int ( f_in . readline ( ) ) NEW_LINE for i in range ( 1 , cases + 1 ) : NEW_LINE INDENT shynesses = f_in . readline ( ) . split ( ) [ 1 ] NEW_LINE shynesses = [ int ( i ) for i in list ( shynesses ) ] NEW_LINE friends = 0 NEW_LINE current = 0 NEW_LINE for j in range ( 0 , len ( shynesses ) ) : NEW_LINE INDENT if current < j and shynesses [ j ] != 0 : NEW_LINE INDENT friends += j - current NEW_LINE current += j - current NEW_LINE DEDENT current += shynesses [ j ] NEW_LINE DEDENT f_out . write ( \" Case ▁ # \" + str ( i ) + \" : ▁ \" + str ( friends ) + \" \\n \" ) NEW_LINE DEDENT", "def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readarray ( f ) : return map ( f , raw_input ( ) . split ( ) ) NEW_LINE _T = readint ( ) NEW_LINE for _t in range ( _T ) : NEW_LINE INDENT N , S = raw_input ( ) . split ( ) NEW_LINE N = int ( N ) NEW_LINE res = 0 NEW_LINE cur = 0 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT if i > cur : NEW_LINE INDENT res += i - cur NEW_LINE cur = i NEW_LINE DEDENT cur += int ( S [ i ] ) NEW_LINE DEDENT print ' Case ▁ # % i : ' % ( _t + 1 ) , res NEW_LINE DEDENT", "import math NEW_LINE import sys NEW_LINE def findsol ( S , Smax ) : NEW_LINE INDENT b = 0 NEW_LINE c = 0 NEW_LINE for ii in range ( len ( S ) ) : NEW_LINE INDENT c += S [ ii ] NEW_LINE if ( ii - c + 1 > b ) : NEW_LINE INDENT b = ii - c + 1 NEW_LINE DEDENT DEDENT return b NEW_LINE DEDENT def convertnums ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE ii = 0 NEW_LINE for jj in range ( len ( s ) ) : NEW_LINE INDENT if s [ jj ] == ' ▁ ' : NEW_LINE INDENT if ( ii < jj ) : NEW_LINE INDENT a . append ( int ( s [ ii : jj ] ) ) NEW_LINE ii = jj + 1 NEW_LINE DEDENT DEDENT DEDENT a . append ( int ( s [ ii : jj ] ) ) NEW_LINE return a NEW_LINE DEDENT fidi = open ( ' A - large . in ' , ' r ' ) NEW_LINE fido = open ( ' a . out ' , ' w ' ) NEW_LINE T = fidi . readline ( ) NEW_LINE T = int ( T ) NEW_LINE for ii in range ( 1 , T + 1 ) : NEW_LINE INDENT tmp = fidi . readline ( ) NEW_LINE jj = tmp . find ( ' ▁ ' ) NEW_LINE Smax = int ( tmp [ 0 : jj ] ) NEW_LINE S = [ ] NEW_LINE for kk in range ( jj + 1 , len ( tmp ) ) : NEW_LINE INDENT try : NEW_LINE INDENT S . append ( int ( tmp [ kk ] ) ) NEW_LINE DEDENT except : NEW_LINE INDENT print ( ' ' ) NEW_LINE DEDENT DEDENT a = findsol ( S , Smax ) NEW_LINE fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + str ( a ) + ' \\n ' ) NEW_LINE print ( ' Case ▁ # ' , str ( ii ) , ' : ▁ ' , str ( a ) ) NEW_LINE DEDENT fidi . close ( ) NEW_LINE fido . close ( ) NEW_LINE" ]
codejam_11_31
[ "import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . StringTokenizer ; public class SquareTiles { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" input . txt \" ) ) ; PrintWriter out = new PrintWriter ( \" output . txt \" ) ; int test = Integer . parseInt ( in . nextLine ( ) ) ; for ( int t = 1 ; t <= test ; t ++ ) { String nums = in . nextLine ( ) ; StringTokenizer st = new StringTokenizer ( nums ) ; int r = Integer . parseInt ( st . nextToken ( ) ) ; int c = Integer . parseInt ( st . nextToken ( ) ) ; char [ ] [ ] map = new char [ r ] [ c ] ; for ( int i = 0 ; i < r ; i ++ ) { String row = in . nextLine ( ) ; map [ i ] = row . toCharArray ( ) ; } for ( int i = 0 ; i < r - 1 ; i ++ ) { for ( int j = 0 ; j < c - 1 ; j ++ ) { if ( map [ i ] [ j ] == ' # ' && map [ i ] [ j + 1 ] == ' # ' && map [ i + 1 ] [ j ] == ' # ' && map [ i + 1 ] [ j + 1 ] == ' # ' ) { map [ i ] [ j ] = ' / ' ; map [ i + 1 ] [ j + 1 ] = ' / ' ; map [ i ] [ j + 1 ] = ' \\ \\' ; map [ i + 1 ] [ j ] = ' \\ \\' ; } } } boolean ok = true ; for ( int i = 0 ; i < r ; i ++ ) for ( int j = 0 ; j < c ; j ++ ) if ( map [ i ] [ j ] == ' # ' ) ok = false ; out . println ( \" Case ▁ # \" + t + \" : \" ) ; if ( ! ok ) out . println ( \" Impossible \" ) ; else { for ( int i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) out . print ( map [ i ] [ j ] ) ; out . println ( ) ; } } } out . close ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . * ; public class SquareTiles { public static void main ( String args [ ] ) throws FileNotFoundException { new SquareTiles ( ) ; } public SquareTiles ( ) throws FileNotFoundException { Scanner scanner = new Scanner ( System . in ) ; PrintWriter writer = new PrintWriter ( new File ( \" C : / res . txt \" ) ) ; int COUNT = scanner . nextInt ( ) ; for ( int y = 1 ; y <= COUNT ; y ++ ) { int N = scanner . nextInt ( ) , M = scanner . nextInt ( ) ; char matrix [ ] [ ] = new char [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { String t = scanner . next ( ) ; for ( int j = 0 ; j < M ; j ++ ) matrix [ i ] [ j ] = t . charAt ( j ) ; } boolean impossible = false ; loop : for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( matrix [ i ] [ j ] == ' # ' ) { if ( i < N - 1 && j < M - 1 && matrix [ i ] [ j ] == ' # ' && matrix [ i ] [ j + 1 ] == ' # ' && matrix [ i + 1 ] [ j ] == ' # ' && matrix [ i + 1 ] [ j + 1 ] == ' # ' ) { matrix [ i ] [ j ] = ' / ' ; matrix [ i ] [ j + 1 ] = ' \\ \\' ; matrix [ i + 1 ] [ j ] = ' \\ \\' ; matrix [ i + 1 ] [ j + 1 ] = ' / ' ; } else { impossible = true ; break loop ; } } } } writer . write ( String . format ( \" Case ▁ # % d : \\n \" , y ) ) ; if ( impossible ) writer . write ( \" Impossible \\n \" ) ; else { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) writer . write ( matrix [ i ] [ j ] ) ; writer . write ( \" \\n \" ) ; } } } writer . close ( ) ; } }", "import java . util . Scanner ; public class Problem { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { char [ ] [ ] map = new char [ 55 ] [ 55 ] ; int R = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; for ( int j = 1 ; j <= R ; j ++ ) { String line = sc . next ( ) ; for ( int k = 1 ; k <= C ; k ++ ) { map [ j ] [ k ] = line . charAt ( k - 1 ) ; } } boolean possible = true ; for ( int j = 1 ; j <= R ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { if ( map [ j ] [ k ] == ' # ' ) { map [ j ] [ k ] = ' / ' ; if ( map [ j ] [ k + 1 ] == ' # ' && map [ j + 1 ] [ k + 1 ] == ' # ' && map [ j + 1 ] [ k + 1 ] == ' # ' ) { map [ j ] [ k + 1 ] = ' \\ \\' ; map [ j + 1 ] [ k ] = ' \\ \\' ; map [ j + 1 ] [ k + 1 ] = ' / ' ; } else { possible = false ; } } } } if ( ! possible ) { System . out . format ( \" Case ▁ # % d : \\n \" , i ) ; System . out . println ( \" Impossible \" ) ; } else { System . out . format ( \" Case ▁ # % d : \\n \" , i ) ; for ( int j = 1 ; j <= R ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { System . out . print ( map [ j ] [ k ] ) ; } System . out . println ( ) ; } } } } }", "import java . util . * ; import java . io . * ; public class Solution { public void doMain ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; int T = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= T ; caseNum ++ ) { int R = sc . nextInt ( ) , C = sc . nextInt ( ) ; char [ ] [ ] data = new char [ R ] [ C ] ; for ( int i = 0 ; i < R ; i ++ ) { data [ i ] = sc . next ( ) . toCharArray ( ) ; } boolean ok = true ; for ( int i = 0 ; i < R && ok ; i ++ ) for ( int j = 0 ; j < C && ok ; j ++ ) if ( data [ i ] [ j ] == ' # ' ) { if ( i + 1 < R && j + 1 < C && data [ i + 1 ] [ j ] == ' # ' && data [ i ] [ j + 1 ] == ' # ' && data [ i + 1 ] [ j + 1 ] == ' # ' ) { data [ i ] [ j ] = data [ i + 1 ] [ j + 1 ] = ' / ' ; data [ i + 1 ] [ j ] = data [ i ] [ j + 1 ] = ' \\ \\' ; } else ok = false ; } pw . println ( \" Case ▁ # \" + caseNum + \" : \" ) ; if ( ok ) { for ( int i = 0 ; i < R ; i ++ ) pw . println ( new String ( data [ i ] ) ) ; } else pw . println ( \" Impossible \" ) ; } sc . close ( ) ; pw . flush ( ) ; pw . close ( ) ; } public static void main ( String [ ] args ) throws Exception { ( new Solution ( ) ) . doMain ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class R1CA { public static void main ( String [ ] args ) { try { new R1CA ( ) . solve ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; throw new IllegalStateException ( ) ; } } private void solve ( ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" A - large . in \" ) ) ; PrintWriter out = new PrintWriter ( \" A - large . out \" ) ; int testCount = in . nextInt ( ) ; for ( int test = 1 ; test <= testCount ; ++ test ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; char [ ] [ ] a = new char [ n ] [ ] ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = in . next ( ) . toCharArray ( ) ; } for ( int i = 0 ; i < n - 1 ; ++ i ) { for ( int j = 0 ; j < m - 1 ; ++ j ) { if ( a [ i ] [ j ] == ' # ' && a [ i + 1 ] [ j ] == ' # ' && a [ i ] [ j + 1 ] == ' # ' && a [ i + 1 ] [ j + 1 ] == ' # ' ) { for ( int di = 0 ; di < 2 ; ++ di ) { for ( int dj = 0 ; dj < 2 ; ++ dj ) { a [ i + di ] [ j + dj ] = ( ( di + dj ) % 2 == 0 ) ? ' / ' : ' \\ \\' ; } } } } } boolean bad = false ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { if ( a [ i ] [ j ] == ' # ' ) { bad = true ; } } } out . printf ( \" Case ▁ # % d : \\n \" , test ) ; if ( bad ) { out . printf ( \" Impossible \\n \" ) ; } else { for ( int i = 0 ; i < n ; ++ i ) { out . println ( a [ i ] ) ; } } } out . flush ( ) ; } }" ]
[ "import math NEW_LINE import sys NEW_LINE def printe ( * st ) : NEW_LINE INDENT return True NEW_LINE DEDENT def replace ( st , pos , char ) : NEW_LINE INDENT return st [ 0 : pos ] + char + st [ pos + 1 : ] NEW_LINE DEDENT def simulate ( ) : NEW_LINE INDENT [ r , c ] = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE t = [ ] NEW_LINE for b in range ( r ) : NEW_LINE INDENT t . append ( input ( ) ) NEW_LINE DEDENT printe ( t ) NEW_LINE for y in range ( r - 1 ) : NEW_LINE INDENT x = 0 NEW_LINE while ( x < c - 1 ) : NEW_LINE INDENT if t [ y ] [ x ] == ' # ' : NEW_LINE INDENT if t [ y ] [ x + 1 ] == ' # ' and t [ y + 1 ] [ x ] == ' # ' and t [ y + 1 ] [ x + 1 ] == ' # ' : NEW_LINE INDENT t [ y ] = replace ( t [ y ] , x , ' / ' ) NEW_LINE t [ y ] = replace ( t [ y ] , x + 1 , \" X \" ) NEW_LINE t [ y + 1 ] = replace ( t [ y + 1 ] , x , ' X ' ) NEW_LINE t [ y + 1 ] = replace ( t [ y + 1 ] , x + 1 , ' / ' ) NEW_LINE x += 1 NEW_LINE DEDENT else : NEW_LINE INDENT return \" Impossible \" NEW_LINE DEDENT DEDENT x += 1 NEW_LINE DEDENT DEDENT for y in range ( r ) : NEW_LINE INDENT if t [ y ] [ c - 1 ] == ' # ' : NEW_LINE INDENT return \" Impossible \" NEW_LINE DEDENT DEDENT for x in range ( c ) : NEW_LINE INDENT if t [ r - 1 ] [ x ] == ' # ' : NEW_LINE INDENT return \" Impossible \" NEW_LINE DEDENT DEDENT for y in range ( r ) : NEW_LINE INDENT t [ y ] = t [ y ] . replace ( \" X \" , \" \\\\ \" ) NEW_LINE DEDENT return \" \\n \" . join ( t ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT print ( \" Case ▁ # { } : \\n { } \" . format ( i + 1 , simulate ( ) ) ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE from itertools import islice NEW_LINE def solve ( pic ) : NEW_LINE INDENT for r in xrange ( len ( pic ) - 1 ) : NEW_LINE INDENT for c in xrange ( len ( pic [ 0 ] ) - 1 ) : NEW_LINE INDENT if pic [ r ] [ c ] == ' # ' and pic [ r ] [ c + 1 ] == ' # ' and pic [ r + 1 ] [ c ] == ' # ' and pic [ r + 1 ] [ c + 1 ] == ' # ' : NEW_LINE INDENT pic [ r ] [ c ] = ' / ' NEW_LINE pic [ r ] [ c + 1 ] = ' \\\\ ' NEW_LINE pic [ r + 1 ] [ c ] = ' \\\\ ' NEW_LINE pic [ r + 1 ] [ c + 1 ] = r ' / ' NEW_LINE DEDENT DEDENT DEDENT has_blue = sum ( 1 for row in pic for cell in row if cell == ' # ' ) NEW_LINE if has_blue : NEW_LINE INDENT return None NEW_LINE DEDENT else : NEW_LINE INDENT return pic NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT T = int ( next ( sys . stdin ) ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT R , C = map ( int , next ( sys . stdin ) . split ( ) ) NEW_LINE pic = list ( list ( row . strip ( ) ) for row in islice ( sys . stdin , R ) ) NEW_LINE newpic = solve ( pic ) NEW_LINE print \" Case ▁ # % s : \" % ( t , ) NEW_LINE if not newpic : NEW_LINE INDENT print \" Impossible \" NEW_LINE DEDENT else : NEW_LINE INDENT for row in newpic : NEW_LINE INDENT print \" \" . join ( row ) NEW_LINE DEDENT DEDENT DEDENT DEDENT main ( ) NEW_LINE", "from __future__ import division NEW_LINE import sys NEW_LINE def calc ( numLines , line ) : NEW_LINE INDENT ok = True NEW_LINE while ok : NEW_LINE INDENT ok = False NEW_LINE for i in range ( len ( line ) ) : NEW_LINE INDENT f = line [ i ] . find ( \" # \" ) NEW_LINE if f >= 0 : NEW_LINE INDENT if i == len ( line ) - 1 or f == len ( line [ i ] ) - 1 or line [ i ] [ f : f + 2 ] != \" # # \" or line [ i + 1 ] [ f : f + 2 ] != \" # # \" : NEW_LINE INDENT print \" Impossible \" NEW_LINE return NEW_LINE DEDENT line [ i ] = line [ i ] [ : f ] + \" / \\\\ \" + line [ i ] [ f + 2 : ] NEW_LINE line [ i + 1 ] = line [ i + 1 ] [ : f ] + \" \\\\ / \" + line [ i + 1 ] [ f + 2 : ] NEW_LINE ok = True NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT for l in line : NEW_LINE INDENT print l NEW_LINE DEDENT DEDENT def getints ( ) : NEW_LINE INDENT return [ int ( x ) for x in sys . stdin . readline ( ) . strip ( ) . split ( \" ▁ \" ) ] NEW_LINE DEDENT numTestCases = getints ( ) [ 0 ] NEW_LINE for i in range ( numTestCases ) : NEW_LINE INDENT numLines = getints ( ) NEW_LINE print ( \" Case ▁ # % d : \" % ( i + 1 ) ) NEW_LINE result = calc ( numLines , [ sys . stdin . readline ( ) . strip ( ) for x in range ( numLines [ 0 ] ) ] ) NEW_LINE DEDENT", "import sys NEW_LINE def readInput ( ) : NEW_LINE INDENT file = open ( sys . argv [ 1 ] ) NEW_LINE testCaseCount = int ( file . readline ( ) ) NEW_LINE testCases = [ ] NEW_LINE for x in xrange ( testCaseCount ) : NEW_LINE INDENT R , C = [ int ( x ) for x in file . readline ( ) . split ( ) ] NEW_LINE picture = [ [ a for a in file . readline ( ) . rstrip ( ) ] for x in xrange ( R ) ] NEW_LINE testCases . append ( ( R , C , picture ) ) NEW_LINE DEDENT return testCases NEW_LINE DEDENT def solve ( ( R , C , picture ) ) : NEW_LINE INDENT for row in xrange ( R ) : NEW_LINE INDENT for column in xrange ( C ) : NEW_LINE INDENT if picture [ row ] [ column ] != ' # ' : NEW_LINE INDENT continue NEW_LINE DEDENT if row == R - 1 or column == C - 1 or picture [ row ] [ column + 1 ] != ' # ' or picture [ row + 1 ] [ column ] != ' # ' or picture [ row + 1 ] [ column + 1 ] != ' # ' : NEW_LINE INDENT return [ ' Impossible ' ] NEW_LINE DEDENT picture [ row ] [ column ] = ' / ' NEW_LINE picture [ row ] [ column + 1 ] = ' \\\\ ' NEW_LINE picture [ row + 1 ] [ column ] = ' \\\\ ' NEW_LINE picture [ row + 1 ] [ column + 1 ] = ' / ' NEW_LINE DEDENT DEDENT return [ ' ' . join ( x ) for x in picture ] NEW_LINE DEDENT testCases = readInput ( ) NEW_LINE testCaseNr = 1 NEW_LINE for testCase in testCases : NEW_LINE INDENT print ' Case ▁ # % d : ▁ \\n % s ' % ( testCaseNr , ' \\n ' . join ( solve ( testCase ) ) ) NEW_LINE testCaseNr += 1 NEW_LINE DEDENT", "import math NEW_LINE inf = open ( \" in . txt \" , \" r \" ) NEW_LINE ouf = open ( ' out . txt ' , ' w ' ) NEW_LINE def close_files ( ) : NEW_LINE INDENT inf . close NEW_LINE ouf . close NEW_LINE DEDENT def precount ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT printcounter = 0 NEW_LINE def printstr ( a ) : NEW_LINE INDENT global printcounter NEW_LINE printcounter += 1 NEW_LINE print >> ouf , ' Case ▁ # % d : ▁ % s ' % ( printcounter , a ) NEW_LINE DEDENT def solvetest ( ) : NEW_LINE INDENT global printcounter NEW_LINE [ r , c ] = inf . readline ( ) . split ( ) NEW_LINE r , c = int ( r ) , int ( c ) NEW_LINE a = [ ] NEW_LINE for i in xrange ( r ) : NEW_LINE INDENT a . append ( list ( inf . readline ( ) . strip ( ) ) ) NEW_LINE DEDENT bad = 0 NEW_LINE for i in xrange ( r ) : NEW_LINE INDENT for j in xrange ( c ) : NEW_LINE INDENT if a [ i ] [ j ] == ' # ' : NEW_LINE INDENT if i == r - 1 or j == c - 1 : NEW_LINE INDENT bad = 1 NEW_LINE break NEW_LINE DEDENT if a [ i + 1 ] [ j ] != ' # ' or a [ i ] [ j + 1 ] != ' # ' or a [ i + 1 ] [ j + 1 ] != ' # ' : NEW_LINE INDENT bad = 1 NEW_LINE break NEW_LINE DEDENT a [ i ] [ j ] = ' / ' NEW_LINE a [ i + 1 ] [ j ] = ' \\\\ ' NEW_LINE a [ i ] [ j + 1 ] = ' \\\\ ' NEW_LINE a [ i + 1 ] [ j + 1 ] = ' / ' NEW_LINE DEDENT DEDENT if bad : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT printcounter += 1 NEW_LINE print >> ouf , ' Case ▁ # % d : ' % ( printcounter ) NEW_LINE if bad : NEW_LINE INDENT print >> ouf , ' Impossible ' NEW_LINE DEDENT else : NEW_LINE INDENT for i in xrange ( r ) : NEW_LINE INDENT s = ' ' NEW_LINE for j in xrange ( c ) : NEW_LINE INDENT s = s + a [ i ] [ j ] NEW_LINE DEDENT print >> ouf , s NEW_LINE DEDENT DEDENT DEDENT precount ( ) NEW_LINE testnum = int ( inf . readline ( ) ) NEW_LINE for test in xrange ( testnum ) : NEW_LINE INDENT solvetest ( ) NEW_LINE DEDENT close_files ( ) NEW_LINE" ]
codejam_13_13
[ "import java . io . * ; import java . util . Scanner ; public class c { public static void main ( String [ ] args ) throws IOException { Scanner input = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( new File ( \" c . txt \" ) ) ; int T = input . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { out . print ( \" Case ▁ # \" + ( t + 1 ) + \" : ▁ \\n \" ) ; int r = input . nextInt ( ) , n = input . nextInt ( ) , m = input . nextInt ( ) , k = input . nextInt ( ) ; for ( int rr = 0 ; rr < r ; rr ++ ) { int twopow = 0 , threepow = 0 , fivepow = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int p = input . nextInt ( ) ; int fives = 0 ; while ( p % 5 == 0 && p > 0 ) { p /= 5 ; fives ++ ; } fivepow = Math . max ( fives , fivepow ) ; int twos = 0 ; while ( p % 2 == 0 && p > 0 ) { p /= 2 ; twos ++ ; } twopow = Math . max ( twos , twopow ) ; int threes = 0 ; while ( p % 3 == 0 && p > 0 ) { p /= 3 ; threes ++ ; } threepow = Math . max ( threes , threepow ) ; } int used = 0 ; while ( fivepow > 0 ) { used ++ ; fivepow -- ; out . print ( 5 ) ; } while ( threepow > 0 ) { used ++ ; threepow -- ; out . print ( 3 ) ; } while ( twopow > n - used ) { twopow -= 2 ; used ++ ; out . print ( 4 ) ; } while ( used < n ) { used ++ ; out . print ( 2 ) ; } out . println ( ) ; } } out . close ( ) ; } }", "package codejam2013 ; import java . io . IOException ; abstract public class CodeJam2013 { abstract public void solveCases ( String inputSize ) throws IOException ; public static void main ( String [ ] args ) { String inputSize = \" s1\" ; Round1AC . main ( inputSize ) ; } }", "import java . util . * ; public class Luck1 { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int numCases = in . nextInt ( ) ; int numRows = in . nextInt ( ) ; int setSize = in . nextInt ( ) ; int setLimit = in . nextInt ( ) ; int numProducts = in . nextInt ( ) ; long [ ] products = new long [ numProducts ] ; StringBuilder output = new StringBuilder ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; ++ caseNum ) { output . append ( String . format ( \" Case ▁ # % d : \\n \" , caseNum ) ) ; for ( int curRow = 0 ; curRow < numRows ; ++ curRow ) { for ( int i = 0 ; i < numProducts ; ++ i ) products [ i ] = in . nextLong ( ) ; int [ ] best = new int [ setSize ] ; Arrays . fill ( best , 2 ) ; double bestProb = 0.0 ; for ( int e1 = 2 ; e1 <= setLimit ; ++ e1 ) { for ( int e2 = 2 ; e2 <= setLimit ; ++ e2 ) { for ( int e3 = 2 ; e3 <= setLimit ; ++ e3 ) { int [ ] tempSet = new int [ ] { e1 , e2 , e3 } ; double checkProb = 1.0 ; for ( int pCheck = 0 ; pCheck < products . length ; ++ pCheck ) { int counter = 0 ; for ( int bitMask = 0 ; bitMask < ( 1 << tempSet . length ) ; ++ bitMask ) { int checkProduct = 1 ; for ( int bit = 1 , idx = 0 ; bit <= bitMask ; bit <<= 1 , ++ idx ) { if ( ( bit & bitMask ) != 0 ) { checkProduct *= tempSet [ idx ] ; } } if ( checkProduct == products [ pCheck ] ) { ++ counter ; } } checkProb *= ( counter / 8.0 ) ; } if ( checkProb > bestProb ) { best = tempSet ; bestProb = checkProb ; } } } } output . append ( best [ 0 ] ) ; output . append ( best [ 1 ] ) ; output . append ( best [ 2 ] ) ; output . append ( ' \\n ' ) ; } } System . out . print ( output ) ; } }", "import java . io . File ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class C { public static void main ( String [ ] args ) throws Exception { String path = \" D : \\\\ C - small - 1 - attempt0\" ; Scanner sc = new Scanner ( new File ( path + \" . in \" ) ) ; PrintWriter pw = new PrintWriter ( path + \" . out \" ) ; int testCases = sc . nextInt ( ) ; for ( int testCase = 1 ; testCase <= testCases ; testCase ++ ) { int R = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; pw . println ( \" Case ▁ # \" + testCase + \" : \" ) ; for ( int i = 0 ; i < R ; i ++ ) { Set < Integer > s = new HashSet < Integer > ( ) ; for ( int j = 0 ; j < K ; j ++ ) { s . add ( sc . nextInt ( ) ) ; } int [ ] b = new int [ N + 1 ] ; Arrays . fill ( b , 2 ) ; while ( b [ N ] == 2 ) { Set < Integer > s1 = new HashSet < Integer > ( s ) ; for ( int mask = 0 ; mask < 1 << N ; mask ++ ) { int p = 1 ; for ( int j = 0 ; j < N ; j ++ ) { if ( ( mask & ( 1 << j ) ) != 0 ) { p *= b [ j ] ; } } s1 . remove ( p ) ; } if ( s1 . isEmpty ( ) ) { break ; } ++ b [ 0 ] ; for ( int j = 0 ; j < N ; j ++ ) { if ( b [ j ] > M ) { b [ j ] = 2 ; ++ b [ j + 1 ] ; } } } for ( int j = 0 ; j < N ; j ++ ) { pw . print ( b [ j ] ) ; } pw . println ( ) ; pw . flush ( ) ; } } pw . close ( ) ; } }", "import java . util . Scanner ; public class C { private static int [ ] SET = { 4 , 5 , 3 , 2 , 1 } ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int cases = scan . nextInt ( ) ; int r , n , m , k , count ; int [ ] res ; long lcmAll ; for ( int c = 1 ; c <= cases ; c ++ ) { r = scan . nextInt ( ) ; n = scan . nextInt ( ) ; m = scan . nextInt ( ) ; k = scan . nextInt ( ) ; res = new int [ n ] ; System . out . println ( \" Case ▁ # \" + c + \" : ▁ \" ) ; for ( int i = 0 ; i < r ; i ++ ) { lcmAll = 1 ; for ( int j = 0 ; j < k ; j ++ ) lcmAll = lcm ( lcmAll , scan . nextInt ( ) ) ; count = 0 ; for ( int j : SET ) { while ( count < n && ( lcmAll % j ) == 0 ) { lcmAll /= j ; res [ count ] = j ; count ++ ; } } if ( res [ 0 ] == 4 && res [ n - 1 ] == 1 ) { res [ 0 ] = 2 ; res [ n - 1 ] = 2 ; } for ( int j : res ) System . out . print ( j == 1 ? 2 : j ) ; System . out . println ( ) ; } } } private static long gcd ( long a , long b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } private static long lcm ( long a , long b ) { return a / gcd ( a , b ) * b ; } }" ]
[ "import sys , os NEW_LINE in_file = None NEW_LINE out_file = None NEW_LINE def run_main ( main ) : NEW_LINE INDENT name = sys . argv [ 0 ] [ : - 3 ] NEW_LINE in_file_name = name + \" . in \" NEW_LINE out_file_name = name + \" . out \" NEW_LINE if len ( sys . argv ) == 2 : NEW_LINE INDENT in_file_name = sys . argv [ 1 ] NEW_LINE out_file_name = in_file_name [ : - 3 ] + \" . out \" NEW_LINE DEDENT if len ( sys . argv ) == 3 : NEW_LINE INDENT if sys . argv [ 1 ] : NEW_LINE INDENT in_file_name = sys . argv [ 1 ] NEW_LINE DEDENT if sys . argv [ 2 ] : NEW_LINE INDENT out_file_name = sys . argv [ 2 ] NEW_LINE DEDENT DEDENT global in_file NEW_LINE global out_file NEW_LINE if in_file_name == ' - ' : NEW_LINE INDENT in_file = sys . stdin NEW_LINE DEDENT else : NEW_LINE INDENT in_file = open ( in_file_name , ' r ' ) NEW_LINE DEDENT if out_file_name == ' - ' : NEW_LINE INDENT out_file = sys . stdout NEW_LINE DEDENT else : NEW_LINE INDENT out_file = open ( out_file_name , ' w ' ) NEW_LINE DEDENT main ( in_file , out_file ) NEW_LINE out_file . close ( ) NEW_LINE in_file . close ( ) NEW_LINE DEDENT def run_tests ( do_testcase ) : NEW_LINE INDENT def main ( in_file , out_file ) : NEW_LINE INDENT t = readinteger ( ) NEW_LINE for x in range ( t ) : NEW_LINE INDENT do_testcase ( x + 1 ) NEW_LINE DEDENT DEDENT run_main ( main ) NEW_LINE DEDENT def readline ( ) : NEW_LINE INDENT return in_file . readline ( ) [ : - 1 ] NEW_LINE DEDENT def writeline ( s ) : NEW_LINE INDENT out_file . write ( \" % s \\n \" % s ) NEW_LINE DEDENT def readinteger ( ) : NEW_LINE INDENT return int ( readline ( ) ) NEW_LINE DEDENT def readintegers ( ) : NEW_LINE INDENT integers = readline ( ) . split ( ) NEW_LINE for i in range ( len ( integers ) ) : NEW_LINE INDENT integers [ i ] = int ( integers [ i ] ) NEW_LINE DEDENT return integers NEW_LINE DEDENT", "from collections import defaultdict NEW_LINE T = int ( input ( ) ) NEW_LINE for tc in range ( T ) : NEW_LINE INDENT R , N , M , K = map ( int , input ( ) . split ( ) ) NEW_LINE def factor ( p ) : NEW_LINE INDENT fac = defaultdict ( int ) NEW_LINE for d in range ( 2 , M + 1 ) : NEW_LINE INDENT while p % d == 0 : NEW_LINE INDENT p /= d NEW_LINE fac [ d ] += 1 NEW_LINE DEDENT DEDENT return fac NEW_LINE DEDENT print ( \" Case ▁ # { } : \" . format ( tc + 1 ) ) NEW_LINE for r in range ( R ) : NEW_LINE INDENT prod = map ( int , input ( ) . split ( ) ) NEW_LINE factors = [ factor ( p ) for p in prod ] NEW_LINE numtimes = defaultdict ( int ) NEW_LINE for k in range ( K ) : NEW_LINE INDENT for d in range ( 2 , M + 1 ) : NEW_LINE INDENT numtimes [ d ] = max ( numtimes [ d ] , factors [ k ] [ d ] ) NEW_LINE DEDENT DEDENT ans = \" \" NEW_LINE ans += '3' * numtimes [ 3 ] + '5' * numtimes [ 5 ] NEW_LINE if 3 - len ( ans ) == 1 : NEW_LINE INDENT if numtimes [ 2 ] == 1 : NEW_LINE INDENT ans += '2' NEW_LINE DEDENT else : NEW_LINE INDENT ans += '4' NEW_LINE DEDENT DEDENT elif 3 - len ( ans ) == 2 : NEW_LINE INDENT if numtimes [ 2 ] == 4 : NEW_LINE INDENT ans += '44' NEW_LINE DEDENT elif numtimes [ 2 ] == 3 : NEW_LINE INDENT ans += '42' NEW_LINE DEDENT else : NEW_LINE INDENT ans += '22' NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT has2 = any ( factors [ k ] [ 2 ] % 2 == 1 for k in range ( K ) ) NEW_LINE if has2 : NEW_LINE INDENT ans += '2' NEW_LINE numtimes [ 2 ] -= 1 NEW_LINE DEDENT num4 = numtimes [ 2 ] // 2 NEW_LINE if numtimes [ 2 ] % 2 == 1 : NEW_LINE INDENT ans += '2' NEW_LINE DEDENT ans += '4' * num4 NEW_LINE DEDENT ans += '2' * ( 3 - len ( ans ) ) NEW_LINE print ( ans ) NEW_LINE DEDENT DEDENT", "def readline ( ) : NEW_LINE INDENT return [ int ( x ) for x in raw_input ( ) . split ( ' ▁ ' ) ] NEW_LINE DEDENT def prod ( l ) : NEW_LINE INDENT m = 1 NEW_LINE for i in l : m *= i NEW_LINE return m NEW_LINE DEDENT readline ( ) NEW_LINE r , n , m , k = readline ( ) NEW_LINE xs = [ [ ] ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT xs = [ y + [ j ] for j in range ( 2 , m + 1 ) for y in xs ] NEW_LINE DEDENT ks = { } NEW_LINE kxs = [ { } for x in xs ] NEW_LINE j = 0 NEW_LINE for x in xs : NEW_LINE INDENT vals = [ [ ] ] NEW_LINE for i in x : NEW_LINE INDENT vals = [ y + [ i ] for y in vals ] + vals NEW_LINE DEDENT for val in vals : NEW_LINE INDENT k = prod ( val ) NEW_LINE if k in ks : NEW_LINE INDENT ks [ k ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ks [ k ] = 1 NEW_LINE DEDENT if k in kxs [ j ] : NEW_LINE INDENT kxs [ j ] [ k ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT kxs [ j ] [ k ] = 1 NEW_LINE DEDENT DEDENT j += 1 NEW_LINE DEDENT print \" Case ▁ # 1 : \" NEW_LINE for _ in range ( r ) : NEW_LINE INDENT prob = [ 1.0 ] * len ( xs ) NEW_LINE given = readline ( ) NEW_LINE for k in given : NEW_LINE INDENT for i in range ( len ( xs ) ) : NEW_LINE INDENT prob [ i ] *= kxs [ i ] [ k ] if k in kxs [ i ] else 0 NEW_LINE prob [ i ] /= ks [ k ] if k in ks else 0 NEW_LINE DEDENT DEDENT m = 0.0 NEW_LINE mi = 0 NEW_LINE for i in range ( len ( xs ) ) : NEW_LINE INDENT if prob [ i ] > m : NEW_LINE INDENT m = prob [ i ] NEW_LINE mi = i NEW_LINE DEDENT DEDENT print ' ' . join ( str ( y ) for y in xs [ mi ] ) NEW_LINE DEDENT", "from itertools import product NEW_LINE from collections import Counter , defaultdict NEW_LINE N = 3 NEW_LINE M = 5 NEW_LINE K = 7 NEW_LINE problist = None NEW_LINE def make_problist ( ) : NEW_LINE INDENT global problist NEW_LINE problist = defaultdict ( Counter ) NEW_LINE for t in product ( range ( 2 , M + 1 ) , repeat = N ) : NEW_LINE INDENT t = tuple ( sorted ( t ) ) NEW_LINE for k in product ( ( 0 , 1 ) , repeat = N ) : NEW_LINE INDENT p = 1 NEW_LINE for kk , tt in zip ( k , t ) : NEW_LINE INDENT if kk : NEW_LINE INDENT p *= tt NEW_LINE DEDENT DEDENT problist [ p ] [ t ] += 1 NEW_LINE DEDENT DEDENT DEDENT make_problist ( ) NEW_LINE def main ( ) : NEW_LINE INDENT import sys NEW_LINE sys . stdin . readline ( ) NEW_LINE sys . stdin . readline ( ) NEW_LINE print \" Case ▁ # 1 : \" NEW_LINE for _ in range ( 100 ) : NEW_LINE INDENT ps = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE P = problist [ 1 ] . viewkeys ( ) NEW_LINE for p in ps : NEW_LINE INDENT P &= problist [ p ] . viewkeys ( ) NEW_LINE DEDENT P = { p : 1 for p in P } NEW_LINE for p in ps : NEW_LINE INDENT for pp in P : NEW_LINE INDENT P [ pp ] *= problist [ p ] [ pp ] NEW_LINE DEDENT DEDENT result = max ( P . items ( ) , key = lambda x : x [ 1 ] ) [ 0 ] NEW_LINE print ' ' . join ( str ( x ) for x in result ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "import numpy as np NEW_LINE R = 100 NEW_LINE N = 3 NEW_LINE M = 5 NEW_LINE K = 7 NEW_LINE db = { } NEW_LINE for i in range ( 2 , M + 1 ) : NEW_LINE INDENT for j in range ( 2 , M + 1 ) : NEW_LINE INDENT for k in range ( 2 , M + 1 ) : NEW_LINE INDENT p = { } NEW_LINE for n1 in range ( 2 ) : NEW_LINE INDENT for n2 in range ( 2 ) : NEW_LINE INDENT for n3 in range ( 2 ) : NEW_LINE INDENT num = i ** n1 * j ** n2 * k ** n3 NEW_LINE if num not in p : NEW_LINE INDENT p [ num ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT p [ num ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT db [ ( i , j , k ) ] = p NEW_LINE DEDENT DEDENT DEDENT f = open ( ' small . in ' ) NEW_LINE t = int ( f . readline ( ) ) NEW_LINE ( int ( x ) for x in f . readline ( ) . split ( ) ) NEW_LINE print R , N , M , K NEW_LINE print ' Case ▁ # 1 : ' NEW_LINE for T in range ( R ) : NEW_LINE INDENT products = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE m = 0 NEW_LINE ans = ( 0 , 0 , 0 ) NEW_LINE for i in range ( 2 , M + 1 ) : NEW_LINE INDENT for j in range ( 2 , M + 1 ) : NEW_LINE INDENT for k in range ( 2 , M + 1 ) : NEW_LINE INDENT l = 1 NEW_LINE for product in products : NEW_LINE INDENT if product in db [ ( i , j , k ) ] : NEW_LINE INDENT l *= db [ ( i , j , k ) ] [ product ] NEW_LINE DEDENT else : l = 0 NEW_LINE DEDENT if l > m : NEW_LINE INDENT m = l NEW_LINE ans = ( i , j , k ) NEW_LINE DEDENT DEDENT DEDENT DEDENT print ' % d % d % d ' % ( ans [ 0 ] , ans [ 1 ] , ans [ 2 ] ) NEW_LINE DEDENT" ]
codejam_08_03
[ "package fly ; public class Point { public double x ; public double y ; public Point ( double x , double y ) { this . x = x ; this . y = y ; } }" ]
[ "import sys NEW_LINE from random import random NEW_LINE from math import floor , pi , sqrt NEW_LINE infile = open ( sys . argv [ 1 ] , ' rb ' ) NEW_LINE numcases = int ( infile . readline ( ) ) NEW_LINE for case in xrange ( 1 , numcases + 1 ) : NEW_LINE INDENT vals = infile . readline ( ) . split ( ) NEW_LINE fly_r , outer_r , thickness , string_r , gap = float ( vals [ 0 ] ) , float ( vals [ 1 ] ) , float ( vals [ 2 ] ) , float ( vals [ 3 ] ) , float ( vals [ 4 ] ) NEW_LINE outer_r2 = outer_r * outer_r NEW_LINE total_area = pi * outer_r2 / 4.0 NEW_LINE rim_hit2 = pow ( outer_r - thickness - fly_r , 2 ) NEW_LINE space = gap + 2 * string_r NEW_LINE x = string_r + fly_r NEW_LINE eff_gap = gap - 2 * fly_r NEW_LINE if eff_gap <= 0 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ 1.000000\" % ( case ) NEW_LINE continue NEW_LINE DEDENT interval = eff_gap / 200 NEW_LINE holes = 0.0 NEW_LINE while x < outer_r - fly_r - thickness : NEW_LINE INDENT y = string_r + fly_r NEW_LINE while y < outer_r - fly_r - thickness : NEW_LINE INDENT irad = x * x + y * y NEW_LINE if irad < rim_hit2 : NEW_LINE INDENT orad = ( x + eff_gap ) * ( x + eff_gap ) + ( y + eff_gap ) * ( y + eff_gap ) NEW_LINE if orad <= rim_hit2 : NEW_LINE INDENT holes += eff_gap * eff_gap NEW_LINE DEDENT else : NEW_LINE INDENT ymax = y + eff_gap NEW_LINE xcurr = x + interval / 2.0 NEW_LINE while xcurr < x + eff_gap and xcurr < outer_r - fly_r - thickness : NEW_LINE INDENT ycalc = sqrt ( rim_hit2 - xcurr * xcurr ) NEW_LINE if ycalc < ymax : NEW_LINE INDENT if ycalc > y : NEW_LINE INDENT holes += interval * ( ycalc - y ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT holes += interval * eff_gap NEW_LINE DEDENT xcurr += interval NEW_LINE DEDENT DEDENT DEDENT y += space NEW_LINE DEDENT x += space NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % .6f \" % ( case , 1 - holes / total_area ) NEW_LINE DEDENT", "from sys import stdin as input_file NEW_LINE from sys import stdout as output_file NEW_LINE from math import pi , sqrt NEW_LINE num_segments = 1000000 NEW_LINE def readline ( file ) : NEW_LINE INDENT return file . readline ( ) . rstrip ( ' \\n ' ) NEW_LINE DEDENT def hit_probability ( fly_radius , racquet_outer_radius , racquet_thickness , string_radius , string_gap ) : NEW_LINE INDENT racquet_thickness += fly_radius NEW_LINE string_radius += fly_radius NEW_LINE string_gap -= 2 * fly_radius NEW_LINE if string_gap <= 0.0 : NEW_LINE INDENT probability = 1.0 NEW_LINE DEDENT else : NEW_LINE INDENT hit_area = 0.0 NEW_LINE delta = racquet_outer_radius / num_segments NEW_LINE string_diameter = 2 * string_radius NEW_LINE unit = string_diameter + string_gap NEW_LINE lower = string_radius NEW_LINE upper = string_radius + string_gap NEW_LINE outer_square = racquet_outer_radius ** 2 NEW_LINE inner_square = ( racquet_outer_radius - racquet_thickness ) ** 2 NEW_LINE for i in xrange ( num_segments ) : NEW_LINE INDENT x = ( i + 0.5 ) / num_segments * racquet_outer_radius NEW_LINE x_square = x * x NEW_LINE difference = inner_square - x_square NEW_LINE x_div , x_mod = divmod ( x , unit ) NEW_LINE hit_length = sqrt ( outer_square - x_square ) NEW_LINE if ( difference > 0 ) and ( x_mod > lower ) and ( x_mod < upper ) : NEW_LINE INDENT sqrt_difference = sqrt ( difference ) NEW_LINE hit_length -= sqrt_difference NEW_LINE y_div , y_mod = divmod ( sqrt_difference , unit ) NEW_LINE hit_length += y_div * string_diameter NEW_LINE if y_mod < lower : NEW_LINE INDENT hit_length += y_mod NEW_LINE DEDENT elif y_mod < upper : NEW_LINE INDENT hit_length += string_radius NEW_LINE DEDENT else : NEW_LINE INDENT hit_length += y_mod - string_gap NEW_LINE DEDENT DEDENT hit_area += hit_length * delta NEW_LINE DEDENT probability = hit_area / ( pi / 4 * racquet_outer_radius ** 2 ) NEW_LINE DEDENT return probability NEW_LINE DEDENT num_cases = int ( readline ( input_file ) ) NEW_LINE for case_num in xrange ( num_cases ) : NEW_LINE INDENT entries = readline ( input_file ) . split ( ) NEW_LINE fly_radius = float ( entries [ 0 ] ) NEW_LINE racquet_outer_radius = float ( entries [ 1 ] ) NEW_LINE racquet_thickness = float ( entries [ 2 ] ) NEW_LINE string_radius = float ( entries [ 3 ] ) NEW_LINE string_gap = float ( entries [ 4 ] ) NEW_LINE probability = hit_probability ( fly_radius , racquet_outer_radius , racquet_thickness , string_radius , string_gap ) NEW_LINE output_file . write ( ' Case ▁ # % d : ▁ % f \\n ' % ( case_num + 1 , probability ) ) NEW_LINE DEDENT" ]
codejam_14_52
[ "import java . util . * ; public class Main { public static void main ( String args [ ] ) { ( new Main ( ) ) . solve ( ) ; } void solve ( ) { Scanner cin = new Scanner ( System . in ) ; int T = cin . nextInt ( ) ; for ( int C = 1 ; C <= T ; ++ C ) { int P = cin . nextInt ( ) ; int Q = cin . nextInt ( ) ; int N = cin . nextInt ( ) ; int HP [ ] = new int [ N ] ; int GOLD [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { HP [ i ] = cin . nextInt ( ) ; GOLD [ i ] = cin . nextInt ( ) ; } System . out . println ( \" Case ▁ # \" + C + \" : ▁ \" + solve ( P , Q , HP , GOLD , N ) ) ; } } int solve ( int P , int Q , int HP [ ] , int GOLD [ ] , int N ) { int SIZE = N * 10 + 100 ; int score [ ] = new int [ SIZE ] ; score [ 1 ] = 1 ; for ( int i = 0 ; i < N ; ++ i ) { int next [ ] = new int [ SIZE ] ; int turn = HP [ i ] / Q ; int rest = HP [ i ] - Q * turn ; if ( rest == 0 ) { rest = Q ; -- turn ; } int req = ( rest + P - 1 ) / P ; for ( int j = 0 ; j < SIZE ; ++ j ) { if ( score [ j ] == 0 ) { continue ; } int index = j + turn + 1 ; next [ index ] = Math . max ( next [ index ] , score [ j ] ) ; if ( req <= j + turn ) { int index2 = j + turn - req ; next [ index2 ] = Math . max ( next [ index2 ] , score [ j ] + GOLD [ i ] ) ; } } score = next ; } int ret = 0 ; for ( int i = 0 ; i < SIZE ; ++ i ) { ret = Math . max ( ret , score [ i ] ) ; } return ret - 1 ; } }", "package round3 ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; public class B { public static void main ( String [ ] args ) throws FileNotFoundException { Kattio io ; io = new Kattio ( new FileInputStream ( \" round3 / B - large - 0 . in \" ) , new FileOutputStream ( \" round3 / B - large - 0 . out \" ) ) ; int cases = io . getInt ( ) ; for ( int i = 1 ; i <= cases ; i ++ ) { io . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; System . err . println ( i ) ; new B ( ) . solve ( io ) ; } io . close ( ) ; } int myPower , towerPower ; int health [ ] , gold [ ] ; private void solve ( Kattio io ) { myPower = io . getInt ( ) ; towerPower = io . getInt ( ) ; int n = io . getInt ( ) ; health = new int [ n ] ; gold = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { health [ i ] = io . getInt ( ) ; gold [ i ] = io . getInt ( ) ; } memo = new int [ n ] [ 201 * n + 10 ] ; io . println ( go ( 0 , 1 ) ) ; } int memo [ ] [ ] ; private int go ( int monster , int savedTurns ) { if ( monster == health . length ) return 0 ; int orgSavedTurns = savedTurns ; if ( memo [ monster ] [ savedTurns ] > 0 ) return memo [ monster ] [ savedTurns ] - 1 ; int towerShots = ( health [ monster ] + towerPower - 1 ) / towerPower ; int best = go ( monster + 1 , savedTurns + towerShots ) ; int h = health [ monster ] % towerPower ; if ( h == 0 ) h = towerPower ; int shotsReq = ( h + myPower - 1 ) / myPower ; savedTurns += towerShots - 1 ; if ( shotsReq <= savedTurns ) { best = Math . max ( best , gold [ monster ] + go ( monster + 1 , savedTurns - shotsReq ) ) ; } memo [ monster ] [ orgSavedTurns ] = best + 1 ; return best ; } }" ]
[ "import sys NEW_LINE def get_best ( P , Q , H , G , buf , pos , free ) : NEW_LINE INDENT if buf [ pos ] [ free ] >= 0 : NEW_LINE INDENT return buf [ pos ] [ free ] NEW_LINE DEDENT if pos == len ( H ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT n = ( H [ pos ] + Q - 1 ) // Q NEW_LINE a = get_best ( P , Q , H , G , buf , pos + 1 , free + n ) NEW_LINE m = ( H [ pos ] - 1 ) // Q NEW_LINE remaining = H [ pos ] - m * Q NEW_LINE b = 0 NEW_LINE if ( free + m ) * P >= remaining : NEW_LINE INDENT n = ( remaining + P - 1 ) // P NEW_LINE b = G [ pos ] + get_best ( P , Q , H , G , buf , pos + 1 , free + m - n ) NEW_LINE DEDENT buf [ pos ] [ free ] = max ( a , b ) NEW_LINE return buf [ pos ] [ free ] NEW_LINE DEDENT def compute ( P , Q , N , H , G ) : NEW_LINE INDENT buf = [ [ - 1 ] * 10010 for i in xrange ( 200 ) ] NEW_LINE return get_best ( P , Q , H , G , buf , 0 , 1 ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT P , Q , N = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE H = [ ] NEW_LINE G = [ ] NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT h , g = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE H . append ( h ) NEW_LINE G . append ( g ) NEW_LINE DEDENT return P , Q , N , H , G NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE result = compute ( * data ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT", "def reader ( inFile ) : NEW_LINE INDENT ( P , Q , N ) = inFile . getInts ( ) NEW_LINE return ( P , Q , [ tuple ( inFile . getInts ( ) ) for i in xrange ( N ) ] ) NEW_LINE DEDENT from fractions import gcd NEW_LINE def solver ( ( P , Q , monsters ) ) : NEW_LINE INDENT n = len ( monsters ) NEW_LINE poss = set ( [ ( tuple ( [ z [ 0 ] for z in monsters ] ) , 0 ) ] ) NEW_LINE while True : NEW_LINE INDENT if set ( [ a for b in poss for a in b [ 0 ] ] ) == set ( [ 0 ] ) : NEW_LINE INDENT break NEW_LINE DEDENT poss = set ( [ ( tuple ( [ max ( i [ k ] - P , 0 ) if k == j else i [ k ] for k in xrange ( n ) ] ) , g + ( monsters [ j ] [ 1 ] if ( j < n ) and ( i [ j ] <= P ) else 0 ) ) for ( i , g ) in poss for j in xrange ( n + 1 ) if ( j == n ) or ( i [ j ] > 0 ) ] ) NEW_LINE poss = set ( [ ( tuple ( [ max ( i [ k ] - Q , 0 ) if k == j else i [ k ] for k in xrange ( n ) ] ) , g ) for ( i , g ) in poss for j in [ min ( [ j2 for j2 in xrange ( n + 1 ) if ( j2 == n ) or ( i [ j2 ] > 0 ) ] ) ] ] ) NEW_LINE DEDENT return max ( [ z [ 1 ] for z in poss ] ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , \" / Users / luke / gcj / 2014/3 / b / \" , \" b \" ) . run ( ) NEW_LINE DEDENT", "for ti in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT p , q , n = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE bests = [ ( 0 , 1 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT h , g = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE towershots = ( h + q - 1 ) // q NEW_LINE bestdiff = 100 NEW_LINE for j in range ( towershots ) : NEW_LINE INDENT k = ( h - q * j + p - 1 ) // p NEW_LINE if k - j < bestdiff : NEW_LINE INDENT bestdiff = k - j NEW_LINE DEDENT DEDENT newbests = [ ] NEW_LINE for best in bests : NEW_LINE INDENT newbests . append ( ( best [ 0 ] , best [ 1 ] + towershots ) ) NEW_LINE if best [ 1 ] >= bestdiff : NEW_LINE INDENT newbests . append ( ( best [ 0 ] + g , best [ 1 ] - bestdiff ) ) NEW_LINE DEDENT DEDENT newbests = sorted ( newbests ) NEW_LINE last = newbests [ - 1 ] NEW_LINE bests = [ last ] NEW_LINE for i in reversed ( range ( 0 , len ( newbests ) - 1 ) ) : NEW_LINE INDENT if newbests [ i ] [ 0 ] > last [ 0 ] or newbests [ i ] [ 1 ] > last [ 1 ] : NEW_LINE INDENT bests . append ( newbests [ i ] ) NEW_LINE last = newbests [ i ] NEW_LINE DEDENT DEDENT DEDENT print ( ' Case ▁ # ' + str ( ti ) + ' : ' , bests [ 0 ] [ 0 ] ) NEW_LINE DEDENT", "def claim_differ ( hp , mydmg , twrdmg ) : NEW_LINE INDENT towShots = hp / twrdmg NEW_LINE hp %= twrdmg NEW_LINE if hp == 0 : NEW_LINE INDENT towShots -= 1 NEW_LINE hp += twrdmg NEW_LINE DEDENT myShots = hp / mydmg NEW_LINE hp %= mydmg NEW_LINE if hp > 0 : NEW_LINE INDENT myShots += 1 NEW_LINE hp = 0 NEW_LINE DEDENT return towShots - myShots NEW_LINE DEDENT def leave_differ ( hp , twrdmg ) : NEW_LINE INDENT towShots = hp / twrdmg NEW_LINE hp %= twrdmg NEW_LINE if hp > 0 : NEW_LINE INDENT towShots += 1 NEW_LINE hp = 0 NEW_LINE DEDENT return towShots NEW_LINE DEDENT INF = 10 ** 12 NEW_LINE def max_gain ( mem , hps , glds , mydmg , twrdmg , mstr , extra_shots ) : NEW_LINE INDENT if extra_shots < 0 : NEW_LINE INDENT return - INF NEW_LINE DEDENT if len ( hps ) == mstr : NEW_LINE INDENT return 0 NEW_LINE DEDENT key = ( mstr , extra_shots ) NEW_LINE if key in mem : NEW_LINE INDENT return mem [ key ] NEW_LINE DEDENT cd = claim_differ ( hps [ mstr ] , mydmg , twrdmg ) NEW_LINE res1 = glds [ mstr ] + max_gain ( mem , hps , glds , mydmg , twrdmg , mstr + 1 , extra_shots + cd ) NEW_LINE ld = leave_differ ( hps [ mstr ] , twrdmg ) NEW_LINE res2 = max_gain ( mem , hps , glds , mydmg , twrdmg , mstr + 1 , extra_shots + ld ) NEW_LINE best = max ( res1 , res2 ) NEW_LINE mem [ key ] = best NEW_LINE return best NEW_LINE DEDENT import sys NEW_LINE infname = sys . argv [ 1 ] NEW_LINE with open ( infname ) as inf : NEW_LINE INDENT with open ( infname . replace ( ' . in ' , ' . out ' ) , ' w ' ) as outf : NEW_LINE INDENT T = int ( inf . readline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT mydmg , twrdmg , N = map ( int , inf . readline ( ) . split ( ) ) NEW_LINE hps , glds = [ ] , [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT hp , gld = map ( int , inf . readline ( ) . split ( ) ) NEW_LINE hps . append ( hp ) NEW_LINE glds . append ( gld ) NEW_LINE DEDENT outf . write ( ' Case ▁ # { } : ▁ { } \\n ' . format ( t , max_gain ( { } , hps , glds , mydmg , twrdmg , 0 , 1 ) ) ) NEW_LINE DEDENT DEDENT DEDENT", "def solve ( m , p ) : NEW_LINE INDENT global H NEW_LINE if max ( H ) <= 0 : NEW_LINE INDENT return m NEW_LINE DEDENT r = 0 NEW_LINE C = range ( p , N + 1 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if H [ i ] > 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if i < p and H [ i ] - P <= 0 : NEW_LINE INDENT C = [ i ] + C NEW_LINE DEDENT for i in C : NEW_LINE INDENT if i == N or H [ i ] > 0 : NEW_LINE INDENT t = m NEW_LINE if i < N : NEW_LINE INDENT H [ i ] -= P NEW_LINE if H [ i ] <= 0 : NEW_LINE INDENT t += G [ i ] NEW_LINE DEDENT DEDENT j = 0 NEW_LINE while j < N : NEW_LINE INDENT if H [ j ] > 0 : NEW_LINE INDENT break NEW_LINE DEDENT j += 1 NEW_LINE DEDENT if j < N : NEW_LINE INDENT H [ j ] -= Q NEW_LINE DEDENT r = max ( r , solve ( t , i ) ) NEW_LINE if j < N : NEW_LINE INDENT H [ j ] += Q NEW_LINE DEDENT if i < N : NEW_LINE INDENT H [ i ] += P NEW_LINE DEDENT DEDENT DEDENT return r NEW_LINE DEDENT for test in range ( input ( ) ) : NEW_LINE INDENT global P , Q , N , H , G NEW_LINE P , Q , N = map ( int , raw_input ( ) . split ( ) ) NEW_LINE H , G = [ ] , [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT h , g = map ( int , raw_input ( ) . split ( ) ) NEW_LINE H += [ h ] NEW_LINE G += [ g ] NEW_LINE DEDENT print \" Case ▁ # % s : ▁ % s \" % ( test + 1 , solve ( 0 , 0 ) ) NEW_LINE DEDENT" ]
codejam_13_11
[ "import java . util . * ; import java . io . * ; import java . math . * ; public class a { static InputReader in ; static PrintWriter out ; public static void main ( String args [ ] ) { in = new InputReader ( System . in ) ; out = new PrintWriter ( System . out ) ; int n = Integer . valueOf ( in . next ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , i , solve ( ) ) ; } out . close ( ) ; } static BigInteger solve ( ) { BigInteger r = new BigInteger ( in . next ( ) ) ; BigInteger t = new BigInteger ( in . next ( ) ) ; BigInteger x = new BigInteger ( \"0\" ) ; BigInteger y = new BigInteger ( \"2000000000000000000\" ) ; BigInteger ans = new BigInteger ( \"0\" ) ; while ( x . compareTo ( y ) != 1 ) { BigInteger m = x . add ( y ) . shiftRight ( 1 ) ; BigInteger tmp = m . multiply ( r ) . shiftLeft ( 1 ) . add ( m . multiply ( m . multiply ( m ) . shiftLeft ( 2 ) . subtract ( BigInteger . ONE ) ) . divide ( new BigInteger ( \"3\" ) ) ) . subtract ( m . subtract ( BigInteger . ONE ) . shiftLeft ( 1 ) . multiply ( m ) . multiply ( m . shiftLeft ( 1 ) . subtract ( BigInteger . ONE ) ) . divide ( new BigInteger ( \"3\" ) ) ) ; if ( tmp . compareTo ( t ) != 1 ) { ans = m ; x = m . add ( BigInteger . ONE ) ; } else y = m . subtract ( BigInteger . ONE ) ; } return ans ; } } class InputReader { StringTokenizer tokenizer ; BufferedReader reader ; public InputReader ( InputStream stream ) { tokenizer = null ; reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException E ) { throw new RuntimeException ( E ) ; } } return tokenizer . nextToken ( ) ; } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; public class R1A { public static void main ( String [ ] args ) { String prblm = \" A \" ; boolean fl = true ; String filein = prblm + \" - \" + ( ( fl ) ? \" large \" : \" small \" ) + \" . in . txt \" ; String fileout = prblm + \" - \" + ( ( fl ) ? \" large \" : \" small \" ) + \" . out . txt \" ; try { BufferedReader fr = new BufferedReader ( new FileReader ( filein ) ) ; BufferedWriter fw = new BufferedWriter ( new FileWriter ( fileout ) ) ; String s = fr . readLine ( ) ; int T = Integer . parseInt ( s ) ; for ( int i = 1 ; i <= T ; i ++ ) { s = fr . readLine ( ) ; String [ ] tok = s . split ( \" ▁ \" ) ; long r = Long . parseLong ( tok [ 0 ] ) ; long t = Long . parseLong ( tok [ 1 ] ) ; long mn = 0 , mx = 2000000000l ; while ( mx - mn > 0 ) { long v = ( mn + mx + 1 ) / 2 ; if ( Long . MAX_VALUE / ( 2 * r + 2 * v - 1 ) < v || v * ( 2 * r + 2 * v - 1 ) > t ) mx = v - 1 ; else mn = v ; } System . out . println ( mn ) ; fw . write ( \" Case ▁ # \" + i + \" : ▁ \" + mn + \" \\n \" ) ; } fr . close ( ) ; fw . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }", "import java . math . BigInteger ; import java . util . Scanner ; public class A { static BigInteger B ( long x ) { return BigInteger . valueOf ( x ) ; } static BigInteger r ; static BigInteger f ( long guess ) { BigInteger x = B ( guess ) ; BigInteger two_x_minus_one = x . multiply ( B ( 2 ) ) . subtract ( B ( 1 ) ) ; return B ( 2 ) . multiply ( x ) . multiply ( r ) . add ( x . multiply ( two_x_minus_one ) ) ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { r = BigInteger . valueOf ( in . nextLong ( ) ) ; BigInteger t = BigInteger . valueOf ( in . nextLong ( ) ) ; long lo = 0 ; long hi = t . longValue ( ) ; while ( lo < hi ) { long mid = ( lo + hi + 1 ) / 2 ; BigInteger score = f ( mid ) ; if ( score . compareTo ( t ) > 0 ) hi = mid - 1 ; else lo = mid ; } System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , cas , lo ) ; } } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . math . BigInteger ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner scan = new Scanner ( System . in ) ; BigInteger TWO = BigInteger . valueOf ( 2 ) ; BigInteger FOUR = BigInteger . valueOf ( 4 ) ; int cases = scan . nextInt ( ) ; BigInteger r , t , res ; PrintStream outfile = new PrintStream ( \" C - large . out . txt \" ) ; for ( int c = 1 ; c <= cases ; c ++ ) { r = scan . nextBigInteger ( ) ; t = scan . nextBigInteger ( ) ; res = r . multiply ( r ) . subtract ( r ) ; res = res . add ( t . multiply ( TWO ) ) ; res = res . multiply ( FOUR ) . add ( BigInteger . ONE ) ; res = bigIntSqRootFloor ( res ) ; res = res . subtract ( r . mod ( TWO ) . equals ( BigInteger . ZERO ) ? BigInteger . valueOf ( 3 ) : BigInteger . valueOf ( 5 ) ) ; res = res . divide ( FOUR ) ; res = res . subtract ( r . divide ( TWO ) ) . add ( BigInteger . ONE ) ; outfile . println ( \" Case ▁ # \" + c + \" : ▁ \" + res . toString ( ) ) ; } } public static BigInteger bigIntSqRootFloor ( BigInteger x ) throws IllegalArgumentException { if ( x . compareTo ( BigInteger . ZERO ) < 0 ) { throw new IllegalArgumentException ( \" Negative ▁ argument . \" ) ; } if ( x == BigInteger . ZERO || x == BigInteger . ONE ) { return x ; } BigInteger two = BigInteger . valueOf ( 2L ) ; BigInteger y ; for ( y = x . divide ( two ) ; y . compareTo ( x . divide ( y ) ) > 0 ; y = ( ( x . divide ( y ) ) . add ( y ) ) . divide ( two ) ) ; return y ; } }", "import java . util . * ; import java . lang . * ; import java . math . * ; import java . io . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; public class A { Scanner sc = new Scanner ( System . in ) ; int INF = 1 << 28 ; double EPS = 1e-9 ; int caze , T ; long r , t ; void run ( ) { T = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( caze = 1 ; caze <= T ; caze ++ ) { r = sc . nextLong ( ) ; t = sc . nextLong ( ) ; solveSmall ( ) ; } } void solveSmall ( ) { long left = 0 , right = ( long ) 1e18 ; for ( ; right - left > 1 ; ) { long mid = ( left + right ) / 2 ; boolean ok = ( 2 * mid + 2 * r - 1 ) <= t / mid ; if ( ok ) { left = mid ; } else { right = mid ; } } answer ( \" \" + left ) ; } void solveLarge ( ) { } void answer ( String s ) { println ( \" Case ▁ # \" + caze + \" : ▁ \" + s ) ; } void println ( String s ) { System . out . println ( s ) ; } void print ( String s ) { System . out . print ( s ) ; } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new A ( ) . run ( ) ; } }" ]
[ "def check ( R , t , n ) : NEW_LINE INDENT a1 = R * 2 - 1 NEW_LINE an = a1 + 4 * ( n - 1 ) NEW_LINE return ( a1 + an ) * n <= t * 2 NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT R , t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE R += 1 NEW_LINE l = 1 NEW_LINE r = 10 ** 18 NEW_LINE while l + 1 < r : NEW_LINE INDENT m = ( l + r ) / 2 NEW_LINE if check ( R , t , m ) : NEW_LINE INDENT l = m NEW_LINE DEDENT else : NEW_LINE INDENT r = m NEW_LINE DEDENT DEDENT return l NEW_LINE DEDENT for i in xrange ( input ( ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , solve ( ) ) NEW_LINE DEDENT", "import sys NEW_LINE lc = 0 NEW_LINE for line in sys . stdin : NEW_LINE INDENT tok = line . split ( ) NEW_LINE if len ( tok ) == 1 : continue NEW_LINE lc += 1 NEW_LINE r , t = map ( int , tok ) NEW_LINE lo = 0 NEW_LINE hi = t NEW_LINE while hi - lo > 1 : NEW_LINE INDENT m = ( lo + hi ) / 2 ; NEW_LINE if 2 * m * r + ( 1 + 4 * m - 3 ) / 2 * m <= t : lo = m NEW_LINE else : hi = m NEW_LINE DEDENT print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( lc , lo ) NEW_LINE DEDENT", "import os , sys , math NEW_LINE def solve_slow ( r , t ) : NEW_LINE INDENT rings = 0 NEW_LINE while True : NEW_LINE INDENT t -= ( 2 * r + 1 ) NEW_LINE if t < 0 : NEW_LINE INDENT return rings NEW_LINE DEDENT rings += 1 NEW_LINE if t == 0 : NEW_LINE INDENT return rings NEW_LINE DEDENT r += 2 NEW_LINE DEDENT return rings NEW_LINE DEDENT def paint_needed ( r , n ) : NEW_LINE INDENT return 2 * n * n + ( 2 * r - 1 ) * n NEW_LINE DEDENT def solve_fast ( r , t ) : NEW_LINE INDENT n = math . floor ( ( - 1 * ( 2 * r - 1 ) + math . sqrt ( ( 2 * r - 1 ) * ( 2 * r - 1 ) + 4 * 2 * t ) ) / 4 ) NEW_LINE n = int ( n ) NEW_LINE if paint_needed ( r , n ) > t : NEW_LINE INDENT return n - 1 NEW_LINE DEDENT return n NEW_LINE DEDENT def solve_bin_search ( r , t ) : NEW_LINE INDENT lower_bound = 1 NEW_LINE upper_bound = t NEW_LINE while ( lower_bound + 1 ) < upper_bound : NEW_LINE INDENT mid = int ( ( lower_bound + upper_bound ) / 2 ) NEW_LINE if paint_needed ( r , mid ) > t : NEW_LINE INDENT upper_bound = mid NEW_LINE DEDENT else : NEW_LINE INDENT lower_bound = mid NEW_LINE DEDENT DEDENT return lower_bound NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT ( r , t ) = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE answer = solve_bin_search ( r , t ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT", "T = int ( raw_input ( ) ) NEW_LINE def area ( r , ncircle ) : NEW_LINE INDENT return ( ( 2 * r + 1 ) + ( 2 * r + 4 * ( ncircle ) - 3 ) ) * ncircle / 2 NEW_LINE DEDENT for case in xrange ( T ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % ( case + 1 ) , NEW_LINE r , t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE low = 1 NEW_LINE high = 10000000000000000 NEW_LINE while high - low > 1 : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if area ( r , mid ) <= t : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT print low NEW_LINE DEDENT", "from functools import * NEW_LINE inf = open ( ' A - large . in ' ) NEW_LINE ouf = open ( ' output . txt ' , ' w ' ) NEW_LINE input = lambda : inf . readline ( ) . strip ( ) NEW_LINE print = partial ( print , file = ouf ) NEW_LINE def solve ( ) : NEW_LINE INDENT r , t = map ( int , input ( ) . split ( ) ) NEW_LINE le = 1 NEW_LINE ri = 10 ** 18 NEW_LINE while le + 1 < ri : NEW_LINE INDENT m = ( le + ri ) // 2 NEW_LINE if ( 2 * r + 1 ) * m + 2 * ( m - 1 ) * m <= t : NEW_LINE INDENT le = m NEW_LINE DEDENT else : NEW_LINE INDENT ri = m NEW_LINE DEDENT DEDENT print ( le ) NEW_LINE DEDENT tests = int ( input ( ) ) NEW_LINE for z in range ( tests ) : NEW_LINE INDENT print ( \" Case ▁ # { } : ▁ \" . format ( z + 1 ) , end = ' ' ) NEW_LINE solve ( ) NEW_LINE DEDENT ouf . close ( ) NEW_LINE" ]
codejam_16_54
[ "import java . util . Arrays ; import java . util . Scanner ; public class D { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . println ( \" Case ▁ # \" + i + \" : ▁ \" + solve ( ) ) ; } } static String solve ( ) { int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; String [ ] G = new String [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { G [ i ] = sc . next ( ) ; } String B = sc . next ( ) ; for ( int i = 0 ; i < N ; ++ i ) { if ( G [ i ] . equals ( B ) ) { return \" IMPOSSIBLE \" ; } } if ( L == 1 ) { return \" ? ▁ 0\" ; } char [ ] p1 = new char [ L - 1 ] ; Arrays . fill ( p1 , ' ? ' ) ; StringBuilder p2 = new StringBuilder ( ) ; for ( int i = 0 ; i < 49 ; ++ i ) { p2 . append ( ( char ) ( '0' + i % 2 ) ) ; } p2 . append ( ' ? ' ) ; for ( int i = 0 ; i < 49 ; ++ i ) { p2 . append ( ( char ) ( '0' + ( i + 1 ) % 2 ) ) ; } return String . valueOf ( p1 ) + \" ▁ \" + p2 . toString ( ) ; } }", "import java . util . * ; import java . io . * ; import static lib . Util . * ; public class D { static int ans ; public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { int N = input . nextInt ( ) ; int L = input . nextInt ( ) ; String [ ] Gs = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) Gs [ i ] = input . next ( ) ; String B = input . next ( ) ; boolean bad = false ; for ( String G : Gs ) if ( G . equals ( B ) ) bad = true ; if ( bad ) { System . out . printf ( \" Case ▁ # % d : ▁ IMPOSSIBLE \\n \" , n + 1 ) ; continue ; } if ( L == 1 ) { System . out . printf ( \" Case ▁ # % d : ▁ 0 ▁ ? \\n \" , n + 1 ) ; continue ; } StringBuilder p1 = new StringBuilder ( ) ; StringBuilder p2 = new StringBuilder ( ) ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == L - 1 ) { if ( i % 2 == 0 ) p2 . append ( \" ? 1\" ) ; else p1 . append ( \" ? 1\" ) ; } else if ( i % 2 == 0 ) { p1 . append ( \"10\" ) ; p2 . append ( \" ? \" ) ; } else { p1 . append ( \" ? \" ) ; p2 . append ( \"10\" ) ; } } System . out . printf ( \" Case ▁ # % d : ▁ % s ▁ % s \\n \" , n + 1 , p1 , p2 ) ; } } }", "import java . io . * ; import java . util . * ; public class D { String solveOne ( Scanner in ) { int size = in . nextInt ( ) ; int len = in . nextInt ( ) ; String g [ ] = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { g [ i ] = in . next ( ) ; } String bad = in . next ( ) ; if ( bad . contains ( \"0\" ) ) { throw new Error ( ) ; } for ( String s : g ) { if ( ! s . contains ( \"0\" ) ) { return \" IMPOSSIBLE \" ; } } String ans = \"0\" ; for ( int i = 1 ; i < len ; i ++ ) { ans += \"1\" ; } ans += \" ▁ \" ; for ( int i = 0 ; i < len ; i ++ ) { ans += \"0 ? \" ; } return ans ; } void solve ( Scanner in , PrintWriter out ) { int nTests = in . nextInt ( ) ; for ( int iTest = 1 ; iTest <= nTests ; iTest ++ ) { out . printf ( \" Case ▁ # % d : ▁ % s % n \" , iTest , solveOne ( in ) ) ; } } void run ( ) { try ( Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; ) { solve ( in , out ) ; } } public static void main ( String args [ ] ) { new D ( ) . run ( ) ; } }", "import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . PrintWriter ; import java . io . StreamTokenizer ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Go implements Runnable { private static final String NAME = \" go \" ; private StreamTokenizer in ; int nextInt ( ) throws Exception { in . nextToken ( ) ; return ( int ) in . nval ; } long nextLong ( ) throws Exception { in . nextToken ( ) ; return ( long ) in . nval ; } @ Override public void run ( ) { try { Scanner in = new Scanner ( new File ( NAME + \" . in \" ) ) ; PrintWriter out = new PrintWriter ( NAME + \" . out \" ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { int n = in . nextInt ( ) ; int l = in . nextInt ( ) ; Set < String > s = new HashSet < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { s . add ( in . next ( ) ) ; } String b = in . next ( ) ; if ( b . contains ( \"0\" ) ) { throw new IllegalStateException ( ) ; } if ( s . contains ( b ) ) { out . println ( \" Case ▁ # \" + test + \" : ▁ IMPOSSIBLE \" ) ; } else { String r1 = \" \" ; String r2 = \" \" ; for ( int i = 0 ; i < l ; i ++ ) { r1 += \"0 ? \" ; } r2 += \"0\" ; for ( int i = 0 ; i < l - 1 ; i ++ ) { r2 += \"01\" ; } r2 += \"0\" ; out . println ( \" Case ▁ # \" + test + \" : ▁ \" + r1 + \" ▁ \" + r2 ) ; } } out . close ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public static void main ( String [ ] args ) { new Thread ( new Go ( ) ) . start ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . util . Arrays ; import java . util . Scanner ; public class GoPlusPlus { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner cin = new Scanner ( new File ( \" D - small - attempt0 . in \" ) ) ; PrintStream cout = new PrintStream ( \" D - small - attempt0 . out \" ) ; int _case = 0 ; for ( int T = cin . nextInt ( ) ; T > 0 ; T -- ) { _case ++ ; StringBuilder ans = new StringBuilder ( ) ; int N = cin . nextInt ( ) ; int L = cin . nextInt ( ) ; String [ ] a = new String [ N ] ; boolean impossible = false ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = cin . next ( ) ; String shit = cin . next ( ) ; for ( String each : a ) if ( each . equals ( shit ) ) impossible = true ; if ( impossible ) ans . append ( \" IMPOSSIBLE \" ) ; else { String one = \"0\" ; for ( int i = 0 ; i < L - 1 ; i ++ ) one += \"1\" ; String two = \" \" ; for ( int i = 0 ; i < L ; i ++ ) two += \"0 ? \" ; ans . append ( one ) ; ans . append ( \" ▁ \" ) ; ans . append ( two ) ; } cout . printf ( \" Case ▁ # % d : ▁ % s % n \" , _case , ans . toString ( ) ) ; } cin . close ( ) ; cout . close ( ) ; } }" ]
[ "def solve ( n , l , gs , b ) : NEW_LINE INDENT if b in gs : NEW_LINE INDENT return \" IMPOSSIBLE \" NEW_LINE DEDENT if l == 1 : NEW_LINE INDENT return \"0 ▁ ? \" NEW_LINE DEDENT return \" ? \" * ( l - 1 ) + \" ▁ \" + \"1\" * ( l - 1 ) + \"0 ? \" + \"01\" * ( l - 1 ) NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for cas in xrange ( 1 , t + 1 ) : NEW_LINE INDENT n , l = map ( int , raw_input ( ) . split ( ) ) NEW_LINE gs = raw_input ( ) . split ( ) NEW_LINE b = raw_input ( ) NEW_LINE ans = solve ( n , l , gs , b ) NEW_LINE print \" Case ▁ # { } : ▁ { } \" . format ( cas , ans ) NEW_LINE DEDENT", "T = int ( raw_input ( ) ) NEW_LINE for TK in xrange ( T ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % ( TK + 1 ) , NEW_LINE N , L = map ( int , raw_input ( ) . split ( ) ) NEW_LINE G = raw_input ( ) . split ( ) NEW_LINE B = raw_input ( ) NEW_LINE if '1' * L in G : NEW_LINE INDENT print ' IMPOSSIBLE ' NEW_LINE continue NEW_LINE DEDENT if L == 1 : NEW_LINE INDENT print '0 ▁ 0 ? ' NEW_LINE DEDENT else : NEW_LINE INDENT a = ' ? ' * ( L - 1 ) NEW_LINE b = '10?1' + ( '01' * L ) NEW_LINE print a , b NEW_LINE DEDENT DEDENT", "import io , sys NEW_LINE import datetime NEW_LINE import random NEW_LINE fin = None NEW_LINE def solve ( ) : NEW_LINE INDENT n , l = nums ( ) NEW_LINE good = strs ( ) NEW_LINE bad = sstrip ( ) NEW_LINE if '1' * l in good : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT if l == 1 : NEW_LINE INDENT return '0 ▁ ? ' NEW_LINE DEDENT return '0 % s ? % s ▁ % s ' % ( '10' * l , '1' * ( l - 1 ) , ' ? ' * ( l - 1 ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT fname = ' test . in ' NEW_LINE if len ( sys . argv ) > 1 : NEW_LINE INDENT fname = sys . argv [ 1 ] NEW_LINE DEDENT global fin NEW_LINE fin = io . open ( fname ) NEW_LINE fout = io . open ( fname + ' . out ' , ' w ' ) NEW_LINE t0 = datetime . datetime . now ( ) NEW_LINE t = int ( fin . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT fout . write ( ' Case ▁ # % d : ▁ ' % ( i + 1 ) ) NEW_LINE fout . write ( ' % s \\n ' % str ( solve ( ) ) ) NEW_LINE DEDENT print ( ' Time ▁ = ▁ % s ' % str ( datetime . datetime . now ( ) - t0 ) ) NEW_LINE fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE DEDENT def nums ( ) : NEW_LINE INDENT return [ int ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE DEDENT def fnums ( ) : NEW_LINE INDENT return [ float ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE DEDENT def num ( ) : NEW_LINE INDENT return int ( fin . readline ( ) ) NEW_LINE DEDENT def sstrip ( ) : NEW_LINE INDENT return fin . readline ( ) . strip ( ) NEW_LINE DEDENT def strs ( ) : NEW_LINE INDENT return fin . readline ( ) . split ( ) NEW_LINE DEDENT def arrstr ( a , sep = ' ▁ ' ) : NEW_LINE INDENT return sep . join ( [ str ( x ) for x in a ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "t = int ( input ( ) ) NEW_LINE def inverse ( s ) : NEW_LINE INDENT return \" \" . join ( chr ( ord ( u ) ^ 1 ) for u in s ) NEW_LINE DEDENT def chapeau ( s ) : NEW_LINE INDENT if len ( s ) == 0 : NEW_LINE INDENT return \" \" NEW_LINE DEDENT u = 0 NEW_LINE while u < len ( s ) and s [ u ] == s [ 0 ] : NEW_LINE INDENT u += 1 NEW_LINE DEDENT if u == len ( s ) : NEW_LINE INDENT return s [ 0 ] * ( u - 1 ) NEW_LINE DEDENT rem = s [ u : ] NEW_LINE return s [ 0 ] * ( u - 1 ) + inverse ( s [ 0 ] ) + s [ 0 ] + chapeau ( rem ) NEW_LINE DEDENT for i in range ( t ) : NEW_LINE INDENT print ( \" Case ▁ # % d : \" % ( i + 1 ) , end = \" ▁ \" ) NEW_LINE n , l = map ( int , input ( ) . split ( ) ) NEW_LINE good = input ( ) . strip ( ) . split ( ) NEW_LINE bad = input ( ) . strip ( ) NEW_LINE if bad in good : NEW_LINE INDENT print ( \" IMPOSSIBLE \" ) NEW_LINE DEDENT else : NEW_LINE INDENT if l == 1 : NEW_LINE INDENT print ( inverse ( bad [ 0 ] ) + \" ? ▁ \" + inverse ( bad [ 0 ] ) ) NEW_LINE continue NEW_LINE DEDENT z = inverse ( bad ) NEW_LINE u = chapeau ( bad ) NEW_LINE v = \" \" . join ( c + \" ? \" for c in z ) NEW_LINE assert ( len ( u ) + len ( v ) <= 200 ) NEW_LINE print ( u + \" ▁ \" + v ) NEW_LINE DEDENT DEDENT", "def initialize_solver ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT def solve_testcase ( ) : NEW_LINE INDENT n , l = read ( ) NEW_LINE g = read ( rettype = str ) NEW_LINE b = read ( False , str ) NEW_LINE if b in g : NEW_LINE INDENT return \" IMPOSSIBLE \" NEW_LINE DEDENT return [ \" ? 0\" * l , \"1\" * ( l - 1 ) + \"0\" ] NEW_LINE DEDENT output_format = \" Case ▁ # % d : ▁ \" NEW_LINE filename = input ( ) . strip ( ) NEW_LINE sfile = None NEW_LINE tfile = None NEW_LINE if filename != \" \" : NEW_LINE INDENT sfile = open ( filename + \" . in \" , \" r \" ) NEW_LINE sfile . seek ( 0 ) NEW_LINE tfile = open ( filename + \" . out \" , \" w \" ) NEW_LINE DEDENT def read ( split = True , rettype = int ) : NEW_LINE INDENT if sfile : NEW_LINE INDENT input_line = sfile . readline ( ) . strip ( ) NEW_LINE DEDENT else : NEW_LINE INDENT input_line = input ( ) . strip ( ) NEW_LINE DEDENT if split : NEW_LINE INDENT return list ( map ( rettype , input_line . split ( ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return rettype ( input_line ) NEW_LINE DEDENT DEDENT def write ( s = \" \\n \" ) : NEW_LINE INDENT if s is None : s = \" \" NEW_LINE if isinstance ( s , list ) : s = \" ▁ \" . join ( map ( str , s ) ) NEW_LINE s = str ( s ) NEW_LINE if tfile : NEW_LINE INDENT tfile . write ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s , end = \" \" ) NEW_LINE DEDENT DEDENT if output_format == 0 : NEW_LINE INDENT solve_testcase ( ) NEW_LINE DEDENT else : NEW_LINE INDENT initialize_solver ( ) NEW_LINE total_cases = read ( split = False ) NEW_LINE for case_number in range ( 1 , total_cases + 1 ) : NEW_LINE INDENT write ( output_format . replace ( \" % d \" , str ( case_number ) ) ) NEW_LINE write ( solve_testcase ( ) ) NEW_LINE write ( \" \\n \" ) NEW_LINE DEDENT DEDENT if tfile is not None : tfile . close ( ) NEW_LINE" ]
codejam_11_03
[ "import java . io . * ; import java . util . * ; public class CandySplit { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new FileReader ( \" C - large ▁ ( 1 ) . in \" ) ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output \" ) ) ; for ( int I = 1 ; I <= T ; I ++ ) { int N = Integer . parseInt ( br . readLine ( ) ) ; int small = Integer . MAX_VALUE , tot = 0 , xor = 0 ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) , \" ▁ \" , false ) ; for ( int i = 0 ; i < N ; i ++ ) { int k = Integer . parseInt ( st . nextToken ( ) ) ; if ( k < small ) small = k ; tot += k ; xor = xor ^ k ; } if ( xor != 0 ) pw . println ( \" Case ▁ # \" + I + \" : ▁ NO \" ) ; else pw . println ( \" Case ▁ # \" + I + \" : ▁ \" + ( tot - small ) ) ; } br . close ( ) ; pw . flush ( ) ; pw . close ( ) ; } catch ( IOException ie ) { ie . printStackTrace ( ) ; } } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Arrays ; public class C { public String solve ( int [ ] a ) { Arrays . sort ( a ) ; int n = a . length ; int total = 0 ; int xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xor ^= a [ i ] ; total += a [ i ] ; } if ( xor != 0 ) { return \" NO \\n \" ; } total -= a [ 0 ] ; return total + \" \\n \" ; } public String runInput ( BufferedReader br ) throws IOException { int n = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; String [ ] items = br . readLine ( ) . trim ( ) . split ( \" \\\\ s + \" ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( items [ i ] ) ; } return solve ( a ) ; } public static void main ( String [ ] args ) { C c = new C ( ) ; try { c . parseFile ( \" C - sample \" ) ; c . parseFile ( \" C - small - attempt0\" ) ; c . parseFile ( \" C - large \" ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public void parseFile ( String filePrefix ) throws IOException { String fileIn = filePrefix + \" . in \" ; String fileOut = filePrefix + \" . out \" ; BufferedReader br = new BufferedReader ( new FileReader ( fileIn ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( fileOut ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { String ret = \" Case ▁ # \" + i + \" : ▁ \" ; ret += runInput ( br ) ; System . out . print ( ret ) ; bw . write ( ret ) ; } br . close ( ) ; bw . close ( ) ; } }", "import java . util . Scanner ; public class C { private static Scanner sc ; public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) System . out . printf ( \" Case ▁ # % d : ▁ % s \\n \" , i + 1 , exec ( ) ) ; } private static String exec ( ) { int n = sc . nextInt ( ) ; int [ ] candy = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) candy [ i ] = sc . nextInt ( ) ; return calc ( candy ) ; } private static String calc ( int [ ] candy ) { int xor = 0 ; int smallest = Integer . MAX_VALUE ; int sum = 0 ; for ( int c : candy ) { if ( smallest > c ) smallest = c ; xor ^= c ; sum += c ; } if ( xor != 0 ) return \" NO \" ; return \" \" + ( sum - smallest ) ; } }", "import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . util . * ; import java . util . regex . * ; import static java . lang . Math . * ; public class C_small { public static void main ( String [ ] args ) throws Exception { new C_small ( ) ; } public C_small ( ) throws Exception { line = br . readLine ( ) ; st = new StringTokenizer ( line ) ; int caseCount = Integer . parseInt ( st . nextToken ( ) ) ; for ( int caseNum = 1 ; caseNum <= caseCount ; caseNum ++ ) { String ans = null ; int N = Integer . parseInt ( br . readLine ( ) ) ; int total = 0 ; int xor = 0 ; int min = 1 << 30 ; line = br . readLine ( ) ; st = new StringTokenizer ( line ) ; for ( int i = 0 ; i < N ; i ++ ) { int v = Integer . parseInt ( st . nextToken ( ) ) ; xor ^= v ; total += v ; min = min ( min , v ) ; } if ( xor != 0 ) ans = \" NO \" ; else { ans = total - min + \" \" ; } buf . append ( String . format ( \" Case ▁ # % d : ▁ % s \\n \" , caseNum , ans ) ) ; } System . out . print ( buf ) ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line ; StringTokenizer st ; StringBuilder buf = new StringBuilder ( ) ; public static void debug ( Object ... arr ) { System . err . println ( Arrays . deepToString ( arr ) ) ; } }", "import java . io . * ; import java . util . * ; public class C { private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; C ( ) throws IOException { in = new BufferedReader ( new FileReader ( \" C . large . in \" ) ) ; out = new PrintWriter ( \" C . large . out \" ) ; eat ( \" \" ) ; int T = nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int N = nextInt ( ) , xor = 0 , sum = 0 , m = 1000001 , c ; for ( int i = 0 ; i < N ; i ++ ) { c = nextInt ( ) ; xor ^= c ; sum += c ; m = Math . min ( m , c ) ; } out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; if ( xor != 0 ) { out . println ( \" NO \" ) ; } else { out . println ( sum - m ) ; } } in . close ( ) ; out . close ( ) ; } private void eat ( String str ) { st = new StringTokenizer ( str ) ; } String next ( ) throws IOException { while ( ! st . hasMoreTokens ( ) ) { String line = in . readLine ( ) ; if ( line == null ) { return null ; } eat ( line ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public static void main ( String [ ] args ) throws IOException { new C ( ) ; } }" ]
[ "from math import * NEW_LINE fin = open ( \" c - large . in \" ) NEW_LINE fout = open ( \" c - large . out \" , \" w \" ) NEW_LINE cases = int ( fin . readline ( ) . split ( ) [ 0 ] ) NEW_LINE case = 0 NEW_LINE def answer ( x ) : NEW_LINE INDENT global case , cases NEW_LINE case += 1 NEW_LINE print >> fout , \" Case ▁ # \" + str ( case ) + \" : ▁ \" + str ( x ) NEW_LINE print \" Case ▁ # \" + str ( case ) + \" : ▁ \" + str ( x ) NEW_LINE DEDENT def nim ( x ) : NEW_LINE INDENT aux = 0 NEW_LINE for i in x : NEW_LINE INDENT aux = aux ^ i NEW_LINE DEDENT return aux NEW_LINE DEDENT for test in xrange ( cases ) : NEW_LINE INDENT n = int ( fin . readline ( ) . split ( ) [ 0 ] ) NEW_LINE bag = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE if nim ( bag ) == 0 : NEW_LINE INDENT answer ( str ( sum ( bag ) - min ( bag ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT answer ( \" NO \" ) NEW_LINE DEDENT DEDENT", "xsum = lambda x : reduce ( lambda v , s : v ^ s , x ) NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( \" input . txt \" ) NEW_LINE testlen = int ( f . readline ( ) . strip ( ) ) NEW_LINE tests = [ ] NEW_LINE i = 0 NEW_LINE for line in f : NEW_LINE INDENT if i % 2 : NEW_LINE INDENT tests . append ( line . strip ( ) ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT tests = tests [ : testlen ] NEW_LINE for test , i in zip ( tests , range ( testlen ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , solve ( parse ( test ) ) ) NEW_LINE DEDENT DEDENT def parse ( test ) : NEW_LINE INDENT return map ( int , test . split ( \" ▁ \" ) ) NEW_LINE DEDENT def solve ( test ) : NEW_LINE INDENT if xsum ( test ) != 0 : NEW_LINE INDENT return \" NO \" NEW_LINE DEDENT else : NEW_LINE INDENT return str ( sum ( test ) - min ( test ) ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "import sys NEW_LINE def read_values ( ) : NEW_LINE INDENT return map ( int , raw_input ( ) . split ( ) ) NEW_LINE DEDENT for case_index in range ( 1 , 1 + input ( ) ) : NEW_LINE INDENT sys . stderr . write ( str ( case_index ) + ' ▁ ' ) NEW_LINE n = input ( ) NEW_LINE t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE t . sort ( ) NEW_LINE s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT s = s ^ t [ i ] NEW_LINE DEDENT if s == 0 : NEW_LINE INDENT res = sum ( t [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT res = ' NO ' NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( case_index , res ) NEW_LINE DEDENT sys . stderr . write ( ' \\n ' ) NEW_LINE", "import os , sys , collections NEW_LINE def bits ( xs ) : NEW_LINE INDENT i = 0 NEW_LINE toReturn = [ [ 0 ] * 32 for x in xs ] NEW_LINE cur2 = 1 NEW_LINE while i < 32 : NEW_LINE INDENT for ( j , x ) in enumerate ( xs ) : NEW_LINE INDENT if x % 2 == 1 : NEW_LINE INDENT toReturn [ j ] [ i ] = 1 NEW_LINE xs [ j ] -= 1 NEW_LINE DEDENT xs [ j ] /= 2 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT toReturn = [ x [ : : - 1 ] for x in toReturn ] NEW_LINE return toReturn NEW_LINE DEDENT def findBigCandy ( candies ) : NEW_LINE INDENT candies . sort ( ) NEW_LINE origCandies = candies [ : ] NEW_LINE candyBits = bits ( candies ) NEW_LINE for i in range ( 32 ) : NEW_LINE INDENT totalBit = sum ( [ candyBits [ x ] [ i ] for x in range ( len ( candyBits ) ) ] ) NEW_LINE if totalBit % 2 == 1 : NEW_LINE INDENT return ' NO ' NEW_LINE DEDENT DEDENT return sum ( origCandies [ 1 : ] ) NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT numCandies = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE candies = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE answer = findBigCandy ( candies ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT", "lines = open ( \" c2 . in \" , \" r \" ) . readlines ( ) NEW_LINE num_cases = int ( lines [ 0 ] . strip ( ) ) NEW_LINE for case_no in range ( num_cases ) : NEW_LINE INDENT n = int ( lines [ case_no * 2 + 1 ] . strip ( ) ) NEW_LINE items = lines [ case_no * 2 + 2 ] . strip ( ) . split ( \" ▁ \" ) NEW_LINE a = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT a . append ( int ( items [ i ] ) ) NEW_LINE DEDENT sum = 0 NEW_LINE total = 0 NEW_LINE min = a [ 0 ] NEW_LINE for i in a : NEW_LINE INDENT sum = sum ^ i NEW_LINE if ( i < min ) : min = i NEW_LINE total = total + i NEW_LINE DEDENT if sum == 0 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( case_no + 1 , total - min ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ NO \" % ( case_no + 1 ) NEW_LINE DEDENT DEDENT" ]
codejam_15_52
[ "import java . util . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; long [ ] sum = new long [ N - K + 1 ] ; for ( int i = 0 ; i < sum . length ; i ++ ) sum [ i ] = in . nextInt ( ) ; long [ ] diff = new long [ N ] ; long [ ] A = new long [ K ] ; long [ ] B = new long [ K ] ; for ( int i = 0 ; i + 1 < sum . length ; i ++ ) { long d = sum [ i + 1 ] - sum [ i ] ; diff [ i + K ] = diff [ i ] + d ; A [ i % K ] = min ( A [ i % K ] , diff [ i + K ] ) ; B [ i % K ] = max ( B [ i % K ] , diff [ i + K ] ) ; } long total = 0 ; for ( int i = 0 ; i < K ; i ++ ) { total -= A [ i ] ; B [ i ] -= A [ i ] ; A [ i ] = 0 ; } Arrays . sort ( B ) ; long d = sum [ 0 ] - total ; d = ( ( d % K ) + K ) % K ; if ( d < 0 || d >= K ) throw new RuntimeException ( ) ; for ( long ans = B [ K - 1 ] ; ; ans ++ ) { long less = 0 ; for ( long b : B ) less += ans - b ; if ( less >= d ) { System . out . format ( \" Case ▁ # % d : ▁ % d \\n \" , zz , ans ) ; break ; } } } } }", "package round3 ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] sums = new int [ N - K + 1 ] ; for ( int i = 0 ; i < sums . length ; i ++ ) { sums [ i ] = sc . nextInt ( ) ; } int [ ] min = new int [ K ] , max = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) { int val = 0 ; for ( int j = i ; j + 1 < sums . length ; j += K ) { val += sums [ j + 1 ] - sums [ j ] ; min [ i ] = Math . min ( min [ i ] , val ) ; max [ i ] = Math . max ( max [ i ] , val ) ; } } int sumModulo = 0 , maxInterval = 0 , canUse = 0 ; for ( int i = 0 ; i < K ; i ++ ) { sumModulo -= min [ i ] ; maxInterval = Math . max ( maxInterval , max [ i ] - min [ i ] ) ; } for ( int i = 0 ; i < K ; i ++ ) { canUse += maxInterval - ( max [ i ] - min [ i ] ) ; } boolean can = false ; for ( int i = 0 ; i <= canUse ; i ++ ) { if ( ( sumModulo + i - sums [ 0 ] ) % K == 0 ) { can = true ; break ; } } if ( ! can ) maxInterval ++ ; System . out . println ( \" Case ▁ # \" + caze + \" : ▁ \" + maxInterval ) ; } } }", "import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numCases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; caseNum ++ ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] sums = new int [ N - K + 1 ] ; for ( int i = 0 ; i < N - K + 1 ; i ++ ) { sums [ i ] = sc . nextInt ( ) ; } int [ ] maxDiff = new int [ K ] ; int [ ] minDiff = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) { int totalDiff = 0 ; for ( int j = i ; j < N - K ; j += K ) { totalDiff += sums [ j + 1 ] - sums [ j ] ; maxDiff [ i ] = Math . max ( maxDiff [ i ] , totalDiff ) ; minDiff [ i ] = Math . min ( minDiff [ i ] , totalDiff ) ; } } long min = 0 ; long max = Integer . MAX_VALUE ; while ( min < max ) { long mid = ( min + max ) / 2 ; boolean possible = true ; long minSum = 0 , maxSum = 0 ; for ( int i = 0 ; i < K ; i ++ ) { if ( maxDiff [ i ] - minDiff [ i ] > mid ) { possible = false ; break ; } long minValue = - minDiff [ i ] , maxValue = mid - maxDiff [ i ] ; minSum += minValue ; maxSum += maxValue ; } long target = ( ( sums [ 0 ] - minSum ) % K + K ) % K + minSum ; if ( possible && target <= maxSum ) { max = mid ; } else { min = mid + 1 ; } } System . out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + min ) ; } } }", "import java . util . * ; import java . io . * ; public class B { public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { int N = input . nextInt ( ) ; int K = input . nextInt ( ) ; int [ ] sums = new int [ N - K + 1 ] ; for ( int i = 0 ; i < N - K + 1 ; i ++ ) sums [ i ] = input . nextInt ( ) ; int [ ] maxdiffs = new int [ K ] ; int [ ] mindiffs = new int [ K ] ; int [ ] currdiff = new int [ K ] ; for ( int i = K ; i < N ; i ++ ) { currdiff [ i % K ] += sums [ i - K + 1 ] - sums [ i - K ] ; if ( currdiff [ i % K ] > maxdiffs [ i % K ] ) maxdiffs [ i % K ] = currdiff [ i % K ] ; if ( currdiff [ i % K ] < mindiffs [ i % K ] ) mindiffs [ i % K ] = currdiff [ i % K ] ; } int [ ] diffdiffs = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) diffdiffs [ i ] = maxdiffs [ i ] - mindiffs [ i ] ; int maxdiffdiff = 0 ; for ( int i = 0 ; i < K ; i ++ ) if ( diffdiffs [ i ] > maxdiffdiff ) maxdiffdiff = diffdiffs [ i ] ; int highBound = 0 ; for ( int i = 0 ; i < K ; i ++ ) highBound += maxdiffdiff - diffdiffs [ i ] ; int target = sums [ 0 ] ; for ( int i = 0 ; i < K ; i ++ ) target += mindiffs [ i ] ; target = ( target % K + K ) % K ; int ans = maxdiffdiff + ( target <= highBound ? 0 : 1 ) ; System . out . printf ( \" Case ▁ # % d : ▁ \" , n + 1 ) ; System . out . println ( ans ) ; } } }" ]
[ "from itertools import * NEW_LINE from bisect import bisect NEW_LINE import sys NEW_LINE lines = open ( \" b . in \" ) . read ( ) . split ( \" \\n \" ) NEW_LINE T = int ( lines [ 0 ] ) NEW_LINE def f ( N , K , sum_i ) : NEW_LINE INDENT min_diff = [ 0 ] * K NEW_LINE max_diff = [ 0 ] * K NEW_LINE curr_diff = [ 0 ] * K NEW_LINE first_sum = int ( sum_i [ 0 ] ) NEW_LINE last_thing = first_sum NEW_LINE for i , a in enumerate ( sum_i [ 1 : ] ) : NEW_LINE INDENT curr_diff [ i % K ] += int ( a ) - last_thing NEW_LINE last_thing = int ( a ) NEW_LINE max_diff [ i % K ] = max ( curr_diff [ i % K ] , max_diff [ i % K ] ) NEW_LINE min_diff [ i % K ] = min ( curr_diff [ i % K ] , min_diff [ i % K ] ) NEW_LINE DEDENT diff = list ( x - n for x , n in izip ( max_diff , min_diff ) ) NEW_LINE worst_diff = max ( diff ) NEW_LINE move_up_min = 0 NEW_LINE move_up_max = 0 NEW_LINE move_down_min = 0 NEW_LINE move_down_max = 0 NEW_LINE for i in xrange ( K ) : NEW_LINE INDENT if min_diff [ i ] < 0 : NEW_LINE INDENT move_up_min += - min_diff [ i ] NEW_LINE move_up_max += worst_diff - max_diff [ i ] NEW_LINE DEDENT elif max_diff [ i ] > worst_diff : NEW_LINE INDENT move_down_min += max_diff [ i ] - worst_diff NEW_LINE move_down_max += min_diff [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT move_up_max += worst_diff - max_diff [ i ] NEW_LINE move_down_max += min_diff [ i ] NEW_LINE DEDENT DEDENT move_up_d = move_up_max - move_up_min NEW_LINE move_down_d = move_down_max - move_down_min NEW_LINE move_min = move_up_min - move_down_max NEW_LINE move_d = move_down_d + move_up_d NEW_LINE move_min %= ( K ) NEW_LINE move_amt = first_sum % ( K ) NEW_LINE if move_amt < move_min : NEW_LINE INDENT move_min -= K NEW_LINE DEDENT if move_min + move_d >= move_amt : NEW_LINE INDENT return worst_diff NEW_LINE DEDENT return worst_diff + 1 NEW_LINE DEDENT curr_i = 1 NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT N , K = tuple ( int ( j ) for j in lines [ curr_i ] . split ( ' ▁ ' ) ) NEW_LINE curr_i += 1 NEW_LINE out = f ( N , K , lines [ curr_i ] . split ( ' ▁ ' ) ) NEW_LINE curr_i += 1 NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i , out ) NEW_LINE DEDENT", "def solve ( ) : NEW_LINE INDENT n , k = map ( int , raw_input ( ) . split ( ) ) NEW_LINE s = map ( int , raw_input ( ) . split ( ) ) NEW_LINE sizes = [ ] NEW_LINE summin = 0 NEW_LINE for i in xrange ( k ) : NEW_LINE INDENT a = 0 if i != k - 1 else s [ 0 ] NEW_LINE seq = [ a ] NEW_LINE for j in xrange ( i , n - k , k ) : NEW_LINE INDENT a += s [ j + 1 ] - s [ j ] NEW_LINE seq . append ( a ) NEW_LINE DEDENT m = min ( seq ) NEW_LINE sizes . append ( max ( seq ) - m ) NEW_LINE summin += m NEW_LINE DEDENT sizes . sort ( ) NEW_LINE left = summin % k NEW_LINE res = sizes [ - 1 ] NEW_LINE for i in xrange ( k ) : NEW_LINE INDENT left -= res - sizes [ i ] NEW_LINE DEDENT if left > 0 : res += 1 NEW_LINE return res NEW_LINE DEDENT for i in xrange ( input ( ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , solve ( ) ) NEW_LINE DEDENT", "import sys NEW_LINE def run ( N , K , sums ) : NEW_LINE INDENT diffs = [ ] NEW_LINE for i in range ( K ) : NEW_LINE INDENT cmin = 0 NEW_LINE cmax = 0 NEW_LINE ctemp = 0 NEW_LINE for j in range ( i , N - K , K ) : NEW_LINE INDENT ctemp += sums [ j + 1 ] - sums [ j ] NEW_LINE cmin = min ( cmin , ctemp ) NEW_LINE cmax = max ( cmax , ctemp ) NEW_LINE DEDENT diffs . append ( [ cmax - cmin , cmin , cmax ] ) NEW_LINE DEDENT diffs . sort ( ) NEW_LINE diff2 = [ ] NEW_LINE offset = 0 NEW_LINE for d in diffs : NEW_LINE INDENT if d [ 1 ] < diffs [ - 1 ] [ 1 ] : NEW_LINE INDENT offset += diffs [ - 1 ] [ 1 ] - d [ 1 ] NEW_LINE diff2 . append ( [ d [ 0 ] , diffs [ - 1 ] [ 1 ] , d [ 2 ] + diffs [ - 1 ] [ 1 ] - d [ 1 ] ] ) NEW_LINE DEDENT else : NEW_LINE INDENT diff2 . append ( d ) NEW_LINE DEDENT DEDENT totminus = sum ( r [ 1 ] - diff2 [ - 1 ] [ 1 ] for r in diff2 ) NEW_LINE totplus = sum ( diff2 [ - 1 ] [ 2 ] - r [ 2 ] for r in diff2 ) NEW_LINE needplus = ( sums [ 0 ] - offset ) % K NEW_LINE needminus = ( offset - sums [ 0 ] ) % K NEW_LINE if totminus >= needminus or totplus >= needplus : NEW_LINE INDENT return diff2 [ - 1 ] [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT return diff2 [ - 1 ] [ 0 ] + 1 NEW_LINE DEDENT DEDENT fin = open ( sys . argv [ 1 ] ) NEW_LINE T = int ( fin . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT N , K = [ int ( x ) for x in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE sums = [ int ( x ) for x in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE ans = run ( N , K , sums ) NEW_LINE print ( ' Case ▁ # % d : ▁ % s ' % ( i , ans ) ) NEW_LINE DEDENT", "import math , collections , itertools NEW_LINE import sys NEW_LINE NCASE = int ( sys . stdin . readline ( ) ) NEW_LINE for case in range ( 1 , NCASE + 1 ) : NEW_LINE INDENT N , K = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE SUM = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE A = [ 0 ] * N NEW_LINE mxd , mnd = [ 0 ] * K , [ 0 ] * K NEW_LINE for i in xrange ( 0 , len ( SUM ) - 1 ) : NEW_LINE INDENT d = SUM [ i + 1 ] - SUM [ i ] NEW_LINE A [ i + K ] = A [ i ] + d NEW_LINE k = i % K NEW_LINE mxd [ k ] = max ( A [ i + K ] , mxd [ k ] ) NEW_LINE mnd [ k ] = min ( A [ i + K ] , mnd [ k ] ) NEW_LINE DEDENT mxrng = max ( mxd [ i ] - mnd [ i ] for i in xrange ( K ) ) NEW_LINE r = next ( i for i in xrange ( K ) if mxd [ i ] - mnd [ i ] == mxrng ) NEW_LINE smn = sum ( mnd [ r ] - d for d in mnd ) NEW_LINE smx = sum ( mxd [ r ] - d for d in mxd ) NEW_LINE if ( SUM [ 0 ] - smn ) % K <= smx - smn : NEW_LINE INDENT ans = mxrng NEW_LINE DEDENT else : NEW_LINE INDENT ans = mxrng + 1 NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , ans ) NEW_LINE DEDENT", "for x in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE sums = tuple ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = [ 0 ] * K NEW_LINE t = sums [ 0 ] NEW_LINE for i in range ( K ) : NEW_LINE INDENT b = 0 NEW_LINE c = 0 NEW_LINE for j in range ( i , N - K , K ) : NEW_LINE INDENT c += sums [ j + 1 ] - sums [ j ] NEW_LINE if c > a [ i ] : NEW_LINE INDENT a [ i ] = c NEW_LINE DEDENT elif c < b : NEW_LINE INDENT b = c NEW_LINE DEDENT DEDENT a [ i ] -= b NEW_LINE t += b NEW_LINE DEDENT t %= K NEW_LINE for i in range ( t ) : NEW_LINE INDENT bestj = 0 NEW_LINE for j in range ( 1 , K ) : NEW_LINE INDENT if a [ j ] < a [ bestj ] : NEW_LINE INDENT bestj = j NEW_LINE DEDENT DEDENT a [ bestj ] += 1 NEW_LINE DEDENT y = max ( a ) NEW_LINE print ( ' Case ▁ # ' + str ( x ) + ' : ' , y ) NEW_LINE DEDENT" ]
codejam_13_12
[ "import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) throws Exception { String path = \" D : \\\\ B - large \" ; Scanner sc = new Scanner ( new File ( path + \" . in \" ) ) ; PrintWriter pw = new PrintWriter ( path + \" . out \" ) ; int testCases = sc . nextInt ( ) ; for ( int testCase = 1 ; testCase <= testCases ; testCase ++ ) { long E = sc . nextInt ( ) ; long R = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; long [ ] v = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = sc . nextInt ( ) ; } long res = 0 ; long energy = E ; for ( int i = 0 ; i < n ; i ++ ) { long cur = energy ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( v [ j ] > v [ i ] ) { long d = j - i ; long regeneration = d * R ; long y = regeneration - ( E - energy ) ; cur = Math . min ( y , energy ) ; cur = Math . max ( cur , 0 ) ; break ; } } res += cur * v [ i ] ; energy = Math . min ( energy - cur + R , E ) ; } pw . println ( \" Case ▁ # \" + testCase + \" : ▁ \" + res ) ; pw . flush ( ) ; } pw . close ( ) ; } }", "import java . util . * ; public class Energy { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; StringBuilder out = new StringBuilder ( ) ; int numCases = in . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; ++ caseNum ) { out . append ( String . format ( \" Case ▁ # % d : ▁ \" , caseNum ) ) ; long maxEnergy = in . nextLong ( ) ; long currentEnergy = maxEnergy ; long regen = in . nextLong ( ) ; int numEvents = in . nextInt ( ) ; long [ ] values = new long [ numEvents ] ; for ( int i = 0 ; i < values . length ; ++ i ) values [ i ] = in . nextLong ( ) ; int curEvent = 0 ; long totalValue = 0 ; while ( curEvent != numEvents ) { int nextEvent = curEvent + 1 ; while ( nextEvent != numEvents && values [ nextEvent ] <= values [ curEvent ] ) ++ nextEvent ; if ( nextEvent == numEvents ) { totalValue += values [ curEvent ] * currentEnergy ; currentEnergy = 0 ; } else { long energyToLeave = Math . max ( maxEnergy - regen * ( nextEvent - curEvent ) , 0L ) ; if ( energyToLeave >= currentEnergy ) { } else { long energyToSpend = currentEnergy - energyToLeave ; totalValue += values [ curEvent ] * energyToSpend ; currentEnergy = energyToLeave ; } } currentEnergy += regen ; currentEnergy = Math . min ( currentEnergy , maxEnergy ) ; ++ curEvent ; } out . append ( totalValue ) ; out . append ( ' \\n ' ) ; } System . out . print ( out ) ; } }", "import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int cases = scan . nextInt ( ) ; int e , r , n ; long result ; int [ ] maxE , minE ; ArrayList < Activity > activities = new ArrayList < Activity > ( ) ; for ( int c = 1 ; c <= cases ; c ++ ) { e = scan . nextInt ( ) ; r = scan . nextInt ( ) ; if ( r > e ) r = e ; n = scan . nextInt ( ) ; activities . clear ( ) ; for ( int i = 0 ; i < n ; i ++ ) activities . add ( new Activity ( i , scan . nextInt ( ) ) ) ; Collections . sort ( activities ) ; maxE = new int [ n ] ; minE = new int [ n ] ; Arrays . fill ( maxE , e ) ; Arrays . fill ( minE , 0 ) ; result = 0 ; for ( Activity act : activities ) { result += ( maxE [ act . i ] - minE [ act . i ] ) * ( long ) act . v ; for ( int i = act . i + 1 , rNext = minE [ act . i ] + r ; i < n && rNext < maxE [ i ] ; i ++ , rNext += r ) maxE [ i ] = rNext ; for ( int i = act . i - 1 , rNext = maxE [ act . i ] - r ; i >= 0 && rNext >= minE [ i ] ; i -- , rNext -= r ) minE [ i ] = rNext ; } System . out . println ( \" Case ▁ # \" + c + \" : ▁ \" + result ) ; } } private static class Activity implements Comparable < Activity > { public final int i , v ; public Activity ( int i , int v ) { this . i = i ; this . v = v ; } public int compareTo ( Activity other ) { return - 1 * ( ( Integer ) v ) . compareTo ( other . v ) ; } } }" ]
[ "def solve ( e , r , n , v ) : NEW_LINE INDENT before = [ e ] * n NEW_LINE after = [ 0 ] * n NEW_LINE finish = [ 0 ] * n NEW_LINE gain = 0 NEW_LINE vv = list ( enumerate ( v ) ) NEW_LINE vv . sort ( key = lambda v : v [ 1 ] , reverse = True ) NEW_LINE for i , v in vv : NEW_LINE INDENT finish [ i ] = 1 NEW_LINE B = before [ i ] NEW_LINE A = after [ i ] NEW_LINE gain += v * ( B - A ) NEW_LINE a = B NEW_LINE for ii in xrange ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT if finish [ ii ] : NEW_LINE INDENT break NEW_LINE DEDENT a -= r NEW_LINE if a < 0 : NEW_LINE INDENT break NEW_LINE DEDENT after [ ii ] = a NEW_LINE DEDENT b = A NEW_LINE for ii in xrange ( i + 1 , n ) : NEW_LINE INDENT if finish [ ii ] : NEW_LINE INDENT break NEW_LINE DEDENT b += r NEW_LINE if b > e : NEW_LINE INDENT break NEW_LINE DEDENT before [ ii ] = b NEW_LINE DEDENT DEDENT return gain NEW_LINE DEDENT import sys NEW_LINE T = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT e , r , n = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE vs = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i , solve ( e , r , n , vs ) ) NEW_LINE DEDENT", "from sys import * NEW_LINE z = input ( ) NEW_LINE from functools import wraps NEW_LINE def memoize ( function ) : NEW_LINE INDENT memo = { } NEW_LINE @ wraps ( function ) NEW_LINE def f ( * args , ** kwargs ) : NEW_LINE INDENT key = args , tuple ( sorted ( kwargs . items ( ) ) ) NEW_LINE if key not in memo : NEW_LINE INDENT memo [ key ] = function ( * args , ** kwargs ) NEW_LINE DEDENT return memo [ key ] NEW_LINE DEDENT f . memo = memo NEW_LINE return f NEW_LINE DEDENT for cas in xrange ( 1 , z + 1 ) : NEW_LINE INDENT e , r , n = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE v = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE @ memoize NEW_LINE def f ( E , N ) : NEW_LINE INDENT if N == n : NEW_LINE INDENT return 0 NEW_LINE DEDENT s = 0 NEW_LINE for t in xrange ( E + 1 ) : NEW_LINE INDENT w = f ( min ( e , E - t + r ) , N + 1 ) + t * v [ N ] NEW_LINE s = max ( s , w ) NEW_LINE DEDENT return s NEW_LINE DEDENT f . memo . clear ( ) NEW_LINE ans = f ( e , 0 ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( cas , ans ) NEW_LINE DEDENT", "import math NEW_LINE def solve ( activities , E , R ) : NEW_LINE INDENT def find_waste_points ( a , i , e ) : NEW_LINE INDENT rec = R NEW_LINE i += 1 NEW_LINE while a > activities [ i ] : NEW_LINE INDENT rec += R NEW_LINE i += 1 NEW_LINE DEDENT return max ( 0 , min ( e , e + rec - E ) ) NEW_LINE DEDENT window = int ( math . ceil ( float ( E ) / R ) ) + 1 NEW_LINE gain = 0 NEW_LINE e = E NEW_LINE for i , a in enumerate ( activities ) : NEW_LINE INDENT m = max ( activities [ i : i + window ] ) NEW_LINE if m == a : NEW_LINE INDENT gain += a * e NEW_LINE e = 0 NEW_LINE DEDENT else : NEW_LINE INDENT wp = find_waste_points ( a , i , e ) NEW_LINE gain += wp * a NEW_LINE e -= wp NEW_LINE DEDENT e += R NEW_LINE if e > E : NEW_LINE INDENT e = E NEW_LINE DEDENT DEDENT return gain NEW_LINE DEDENT tcases = int ( raw_input ( ) ) NEW_LINE for d in xrange ( 1 , tcases + 1 ) : NEW_LINE INDENT E , R , N = map ( int , raw_input ( ) . split ( ) ) NEW_LINE activities = map ( int , raw_input ( ) . split ( ) ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( d , solve ( activities , E , R ) ) NEW_LINE DEDENT", "import os , sys , math NEW_LINE def max_energy ( max_e , e , r , values , i ) : NEW_LINE INDENT if ( i == ( len ( values ) - 1 ) ) : NEW_LINE INDENT return ( e * values [ i ] , 0 ) NEW_LINE DEDENT best = 0 NEW_LINE best_index = - 1 NEW_LINE possible_energies = [ 0 , e ] NEW_LINE if ( e + r > max_e ) : NEW_LINE INDENT possible_energies [ 0 ] = min ( e , e + r - max_e ) NEW_LINE DEDENT next_highest = 1 NEW_LINE while ( i + next_highest ) < len ( values ) and values [ i + next_highest ] < values [ i ] : NEW_LINE INDENT next_highest += 1 NEW_LINE DEDENT if ( i + next_highest ) == len ( values ) : NEW_LINE INDENT possible_energies = [ e ] NEW_LINE DEDENT else : NEW_LINE INDENT possible_energies = [ min ( e , max ( possible_energies [ 0 ] , ( e + next_highest * r ) - max_e ) ) ] NEW_LINE DEDENT energy_to_use = possible_energies [ 0 ] NEW_LINE energy_for_next_step = min ( e - energy_to_use + r , max_e ) NEW_LINE return ( energy_to_use * values [ i ] , energy_for_next_step ) NEW_LINE DEDENT def solve ( e , r , values ) : NEW_LINE INDENT global best_matrix NEW_LINE best_matrix = { } NEW_LINE best = 0 NEW_LINE max_e = e NEW_LINE for i in range ( len ( values ) ) : NEW_LINE INDENT ( new_energy , e ) = max_energy ( max_e , e , r , values , i ) NEW_LINE best += new_energy NEW_LINE DEDENT return best NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT ( e , r , n ) = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE values = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE answer = solve ( e , r , values ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT", "def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readarray ( f ) : return map ( f , raw_input ( ) . split ( ) ) NEW_LINE E = 0 NEW_LINE R = 0 NEW_LINE def update ( maybe , must , i , D ) : NEW_LINE INDENT j = i - 1 NEW_LINE m = maybe [ i ] NEW_LINE while j >= 0 : NEW_LINE INDENT m -= R NEW_LINE if m < must [ j ] : NEW_LINE INDENT break NEW_LINE DEDENT must [ j ] = m NEW_LINE j -= 1 NEW_LINE DEDENT j = i + 1 NEW_LINE m = must [ i ] NEW_LINE while j < len ( maybe ) : NEW_LINE INDENT m += R NEW_LINE if m > maybe [ j ] : NEW_LINE INDENT break NEW_LINE DEDENT maybe [ j ] = m NEW_LINE j += 1 NEW_LINE DEDENT DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT print ' Case ▁ # % i : ' % ( test + 1 ) , NEW_LINE E , R , N = readarray ( int ) NEW_LINE V = readarray ( int ) NEW_LINE D = [ - 1 ] * N NEW_LINE maybe = [ E ] * N NEW_LINE must = [ 0 ] * N NEW_LINE tasks = list ( reversed ( sorted ( [ ( V [ i ] , i ) for i in range ( N ) ] ) ) ) NEW_LINE best = 0 NEW_LINE for v , i in tasks : NEW_LINE INDENT best += v * ( maybe [ i ] - must [ i ] ) NEW_LINE D [ i ] = maybe [ i ] - must [ i ] NEW_LINE update ( maybe , must , i , D ) NEW_LINE DEDENT print best NEW_LINE DEDENT" ]
codejam_10_13
[ "import java . io . * ; import java . util . * ; import java . text . * ; public class CS { public PrintStream out = System . out ; public PrintStream err = System . err ; public Scanner in = new Scanner ( System . in ) ; public DecimalFormat fmt = new DecimalFormat ( \"0.000000000\" ) ; public int Amin , Amax , Bmin , Bmax ; public void main ( ) { try { int TCase , cc ; int i , j , k ; int A , B ; TCase = in . nextInt ( ) ; for ( cc = 1 ; cc <= TCase ; ++ cc ) { Amin = in . nextInt ( ) ; Amax = in . nextInt ( ) ; Bmin = in . nextInt ( ) ; Bmax = in . nextInt ( ) ; int res = 0 ; for ( A = Amin ; A <= Amax ; ++ A ) for ( B = Bmin ; B <= Bmax ; ++ B ) { res += sim ( A , B ) ; } out . println ( \" Case ▁ # \" + cc + \" : ▁ \" + res ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } public int sim ( int A , int B ) { if ( A == B ) return 0 ; if ( A < B ) return sim ( B , A ) ; if ( A >= 2 * B ) return 1 ; return 1 - sim ( B , A - B ) ; } public static void main ( String [ ] args ) { long startTime = System . currentTimeMillis ( ) ; ( new CS ( ) ) . main ( ) ; long endTime = System . currentTimeMillis ( ) ; long ms = endTime - startTime ; long sec = ms / 1000 ; ms = ms % 1000 ; long min = sec / 60 ; sec = sec % 60 ; System . err . println ( \" Time ▁ Spent : ▁ \" + min + \" ▁ minute ( s ) ▁ \" + sec + \" ▁ second ( s ) ▁ \" + ms + \" ▁ ( ms ) \" ) ; } }", "import java . math . * ; import java . util . * ; public class C { public static int [ ] a ; public static int find ( int k , int x ) { int low = 1 ; int up = k ; while ( low < up ) { int mid = ( low + up ) / 2 ; if ( a [ mid ] <= x ) low = mid + 1 ; else up = mid ; } return low ; } public static void main ( String args [ ] ) { a = new int [ 1000001 ] ; a [ 1 ] = 2 ; a [ 2 ] = 4 ; for ( int i = 3 ; i <= 1000000 ; ++ i ) a [ i ] = find ( i - 1 , i ) + i ; Scanner scanner = new Scanner ( System . in ) ; int caseNumber = scanner . nextInt ( ) ; for ( int cases = 0 ; cases < caseNumber ; ++ cases ) { int a1 = scanner . nextInt ( ) ; int a2 = scanner . nextInt ( ) ; int b1 = scanner . nextInt ( ) ; int b2 = scanner . nextInt ( ) ; BigInteger ans = new BigInteger ( \"0\" ) ; for ( int i = a1 ; i <= a2 ; ++ i ) { int up = b2 ; int low = a [ i ] ; if ( b1 > low ) low = b1 ; if ( low > up ) continue ; ans = ans . add ( new BigInteger ( Integer . toString ( up - low + 1 ) ) ) ; } for ( int i = b1 ; i <= b2 ; ++ i ) { int up = a2 ; int low = a [ i ] ; if ( a1 > low ) low = a1 ; if ( low > up ) continue ; ans = ans . add ( new BigInteger ( Integer . toString ( up - low + 1 ) ) ) ; } System . out . println ( \" Case ▁ # \" + ( cases + 1 ) + \" : ▁ \" + ans ) ; } } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class NumberGame { public static void main ( String args [ ] ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" C - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( \" C . out \" ) ) ) ; long alow , ahigh , blow , bhigh , cases ; cases = Integer . parseInt ( in . readLine ( ) ) ; double gold = ( 1 + Math . sqrt ( 5 ) ) / 2 ; for ( int i = 1 ; i <= cases ; i ++ ) { StringTokenizer st = new StringTokenizer ( in . readLine ( ) ) ; alow = Integer . parseInt ( st . nextToken ( ) ) ; ahigh = Integer . parseInt ( st . nextToken ( ) ) ; blow = Integer . parseInt ( st . nextToken ( ) ) ; bhigh = Integer . parseInt ( st . nextToken ( ) ) ; long count = ( ahigh - alow + 1 ) * ( bhigh - blow + 1 ) ; for ( long a = alow ; a <= ahigh ; a ++ ) { long low = Math . max ( ( long ) ( a / gold + 1 ) , blow ) ; long high = Math . min ( bhigh , ( long ) ( a * gold ) ) ; if ( low <= bhigh && high >= blow ) count -= high - low + 1 ; } out . println ( \" Case ▁ # \" + i + \" : ▁ \" + count ) ; } out . close ( ) ; } }", "import static java . lang . Math . * ; import static java . util . Arrays . * ; import java . util . * ; public class C { boolean TIME = false ; Scanner sc ; void solve ( ) { int A1 = sc . nextInt ( ) , A2 = sc . nextInt ( ) ; int B1 = sc . nextInt ( ) , B2 = sc . nextInt ( ) ; long res = 0 ; for ( int b = B1 ; b <= B2 ; b ++ ) { int min = ( int ) ( ceil ( 1.0 / R * b ) ) ; int max = ( int ) ( floor ( R * b ) ) ; min = max ( min , A1 ) ; max = min ( max , A2 ) ; res += A2 - A1 + 1 ; if ( min <= max ) { res -= max - min + 1 ; } } System . out . println ( res ) ; } double R = ( sqrt ( 5 ) + 1 ) / 2 ; void run ( ) { long time = System . currentTimeMillis ( ) ; sc = new Scanner ( System . in ) ; int on = sc . nextInt ( ) ; for ( int o = 1 ; o <= on ; o ++ ) { double t = ( System . currentTimeMillis ( ) - time ) * 1e-3 ; if ( TIME ) System . err . printf ( \" % 03d / %03d ▁ % .3f / % . 3f % n \" , o , on , t , t / ( o - 1 ) * on ) ; System . out . printf ( \" Case ▁ # % d : ▁ \" , o ) ; solve ( ) ; System . out . flush ( ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new C ( ) . run ( ) ; } }", "import java . io . FileInputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Number { private Scanner fin ; private PrintStream fout ; public Number ( String in , String out ) { try { fin = new Scanner ( new FileInputStream ( in ) ) ; fout = new PrintStream ( out ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } private void run ( ) { int cas = fin . nextInt ( ) ; for ( int t = 1 ; t <= cas ; ++ t ) { fout . println ( \" Case ▁ # \" + t + \" : ▁ \" + process ( ) ) ; } } private int startpos [ ] ; private long process ( ) { int a1 , a2 , b1 , b2 ; a1 = fin . nextInt ( ) ; a2 = fin . nextInt ( ) ; b1 = fin . nextInt ( ) ; b2 = fin . nextInt ( ) ; startpos = new int [ a2 + 1 ] ; if ( a2 >= 1 ) startpos [ 1 ] = 1 ; if ( a2 >= 2 ) startpos [ 2 ] = 2 ; int k = 1 ; for ( int i = 3 ; i <= a2 ; ++ i ) { while ( i >= startpos [ k ] + k ) k ++ ; startpos [ i ] = k ; } long res = 0 ; for ( int i = a1 ; i <= a2 ; ++ i ) { res += count ( i , b1 , b2 ) ; } return res ; } private long count ( int id , int b1 , int b2 ) { long res = b2 - b1 + 1 ; if ( b1 < startpos [ id ] ) { if ( b2 < startpos [ id ] ) return res ; else if ( b2 < startpos [ id ] + id ) { return res - ( b2 - startpos [ id ] + 1 ) ; } else { return res - id ; } } else if ( b1 < startpos [ id ] + id ) { if ( b2 < startpos [ id ] + id ) { return 0 ; } else { return b2 - ( startpos [ id ] + id ) + 1 ; } } else { return res ; } } public static void main ( String [ ] args ) { new Number ( \" c . in \" , \" c . out \" ) . run ( ) ; } }" ]
[ "import math NEW_LINE phi = ( 1 + math . sqrt ( 5 ) ) / 2 NEW_LINE for t in xrange ( int ( raw_input ( ) ) ) : NEW_LINE INDENT A1 , A2 , B1 , B2 = map ( int , raw_input ( ) . split ( \" ▁ \" ) ) NEW_LINE c = 0 NEW_LINE for a in xrange ( A1 , A2 + 1 ) : NEW_LINE INDENT start = int ( math . ceil ( a / phi ) ) NEW_LINE end = int ( math . floor ( a * phi ) ) + 1 NEW_LINE istart = max ( B1 , start ) NEW_LINE iend = min ( B2 + 1 , end ) NEW_LINE dist = iend - istart NEW_LINE c += dist if dist > 0 else 0 NEW_LINE DEDENT c = ( A2 - A1 + 1 ) * ( B2 - B1 + 1 ) - c NEW_LINE print \" Case ▁ # % i : ▁ % i \" % ( t + 1 , c ) NEW_LINE DEDENT", "import sys NEW_LINE def solve ( a , b ) : NEW_LINE INDENT if a == 0 or b == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if a == b : NEW_LINE INDENT return 0 NEW_LINE DEDENT if a < b : NEW_LINE INDENT return solve ( b , a ) NEW_LINE DEDENT if a >= 2 * b : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 - solve ( a % b , b ) NEW_LINE DEDENT DEDENT def num ( a , b1 , b2 ) : NEW_LINE INDENT low = 0 NEW_LINE high = a - 1 NEW_LINE far = 0 NEW_LINE while low <= high : NEW_LINE INDENT mid = ( low + high ) / 2 NEW_LINE if solve ( a , mid ) == 1 : NEW_LINE INDENT low = mid + 1 NEW_LINE far = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid - 1 NEW_LINE DEDENT DEDENT add = 0 NEW_LINE if b1 <= far : NEW_LINE INDENT add = min ( b2 , far ) - b1 + 1 NEW_LINE DEDENT actual = 0 NEW_LINE for b in range ( b1 , b2 + 1 ) : NEW_LINE INDENT if b < a and solve ( a , b ) == 1 : NEW_LINE INDENT actual += 1 NEW_LINE DEDENT DEDENT if add != actual : NEW_LINE INDENT print \" ERRROR ! ▁ % d ▁ % d ▁ % d ▁ % d \" % ( a , add , actual , far ) NEW_LINE DEDENT return add NEW_LINE DEDENT T = int ( sys . stdin . readline ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT s = sys . stdin . readline ( ) . split ( ) NEW_LINE a1 = int ( s [ 0 ] ) NEW_LINE a2 = int ( s [ 1 ] ) NEW_LINE b1 = int ( s [ 2 ] ) NEW_LINE b2 = int ( s [ 3 ] ) NEW_LINE ans = 0 NEW_LINE for a in range ( a1 , a2 + 1 ) : NEW_LINE INDENT ans += num ( a , b1 , b2 ) NEW_LINE DEDENT for b in range ( b1 , b2 + 1 ) : NEW_LINE INDENT ans += num ( b , a1 , a2 ) NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( t + 1 , ans ) NEW_LINE DEDENT", "import sys , itertools NEW_LINE fst = [ 1 , 1 ] NEW_LINE def pre ( ) : NEW_LINE INDENT global fst NEW_LINE for i in xrange ( 2 , 1000001 ) : NEW_LINE INDENT fst . append ( i + 1 - fst [ fst [ i - 1 ] ] ) NEW_LINE DEDENT DEDENT def solve ( X ) : NEW_LINE INDENT global fst NEW_LINE A1 , A2 , B1 , B2 = ( int ( i ) for i in raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE for i in xrange ( A1 , A2 + 1 ) : NEW_LINE INDENT f , l = fst [ i ] , fst [ i ] + i - 1 NEW_LINE if B2 < f or B1 > l : NEW_LINE INDENT ans += ( B2 - B1 + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT if B1 >= f and B2 <= l : NEW_LINE INDENT pass NEW_LINE DEDENT elif B1 <= f and B2 >= l : NEW_LINE INDENT ans += ( B2 - B1 + 1 ) - ( l - f + 1 ) NEW_LINE DEDENT elif B1 > f : NEW_LINE INDENT ans += ( B2 - l ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += ( f - B1 ) NEW_LINE DEDENT DEDENT DEDENT print \" Case ▁ # % d : \" % ( X , ) , ans NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT pre ( ) NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT solve ( i ) NEW_LINE DEDENT DEDENT", "filename = \" C - small . in \" NEW_LINE ll = - 1 NEW_LINE for line in open ( filename , \" r \" ) : NEW_LINE INDENT ll += 1 NEW_LINE if ll == 0 : continue NEW_LINE data = map ( lambda x : long ( x ) , line . rstrip ( ) . split ( ) ) NEW_LINE ret = 0 NEW_LINE for a in range ( data [ 0 ] , data [ 1 ] + 1 ) : NEW_LINE INDENT b_min = max ( ( a + 1 ) / 2 , data [ 2 ] ) NEW_LINE b_max = min ( a * 2 , data [ 3 ] ) NEW_LINE if b_min > b_max : NEW_LINE INDENT ret += data [ 3 ] - data [ 2 ] + 1 NEW_LINE continue NEW_LINE DEDENT ret += b_min - data [ 2 ] + data [ 3 ] - b_max NEW_LINE bs = range ( b_min , b_max + 1 ) NEW_LINE for b in bs : NEW_LINE INDENT atmp = a NEW_LINE turn = 1 NEW_LINE while True : NEW_LINE INDENT if atmp > b : NEW_LINE INDENT if ( atmp - 1 ) / b >= 2 : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT atmp -= b NEW_LINE DEDENT DEDENT elif atmp == b : NEW_LINE INDENT turn += 1 NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT if ( b - 1 ) / atmp >= 2 : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT b -= atmp NEW_LINE DEDENT DEDENT turn += 1 NEW_LINE DEDENT if turn % 2 == 1 : NEW_LINE INDENT ret += 1 NEW_LINE DEDENT DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( ll , ret ) NEW_LINE DEDENT", "import sys NEW_LINE import re NEW_LINE import os NEW_LINE import time NEW_LINE from math import * NEW_LINE from itertools import * NEW_LINE from pprint import pprint NEW_LINE if len ( sys . argv ) != 2 : NEW_LINE INDENT print ' specify ▁ input ▁ file ' NEW_LINE exit ( ) NEW_LINE DEDENT startTime = time . clock ( ) NEW_LINE fin = open ( sys . argv [ 1 ] ) NEW_LINE fout = open ( os . path . splitext ( sys . argv [ 1 ] ) [ 0 ] + ' . out ' , ' w ' ) NEW_LINE phi = 0.5 * ( sqrt ( 5 ) + 1 ) NEW_LINE def loosing ( a , b ) : NEW_LINE INDENT return a <= b <= int ( phi * a ) or b <= a <= int ( phi * b ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT a1 , a2 , b1 , b2 = map ( int , next ( fin ) . split ( ) ) NEW_LINE n = 0 NEW_LINE for a in range ( a1 , a2 + 1 ) : NEW_LINE INDENT for b in range ( b1 , b2 + 1 ) : NEW_LINE INDENT if not loosing ( a , b ) : NEW_LINE INDENT n += 1 NEW_LINE DEDENT DEDENT DEDENT print >> fout , n NEW_LINE DEDENT numCases = int ( next ( fin ) ) NEW_LINE for caseNo in range ( numCases ) : NEW_LINE INDENT print ' \\b ' * 10 , 100 * caseNo / numCases , ' % ' , NEW_LINE print >> fout , ' Case ▁ # % s : ' % ( caseNo + 1 ) , NEW_LINE solve ( ) NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE print ' \\b ' * 10 + ' it ▁ took ▁ % .1fs ' % ( time . clock ( ) - startTime ) NEW_LINE" ]
codejam_17_03
[ "import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . Scanner ; public class c { public static void main ( String [ ] Args ) throws Exception { Scanner sc = new Scanner ( new File ( \" C - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( new File ( \" c . out \" ) ) ) ) ; int cc = 0 ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { long n = sc . nextLong ( ) ; long pos = sc . nextLong ( ) ; int dep = 0 ; long v = 0 ; while ( pos > ( ( v << 1 ) | 1 ) ) { v = ( ( v << 1 ) | 1 ) ; dep ++ ; } n -= v ; pos -= v + 1 ; v ++ ; if ( n % v > pos ) n = n / v + 1 ; else n = n / v ; out . printf ( \" Case ▁ # % d : ▁ % d ▁ % d % n \" , ++ cc , n >> 1 , ( n - 1 ) >> 1 ) ; } out . close ( ) ; } }", "import java . math . BigInteger ; import java . util . * ; import java . io . * ; public class Main { private static BigInteger solve ( BigInteger n , BigInteger m ) { if ( m . equals ( BigInteger . ONE ) ) return n ; n = n . subtract ( BigInteger . ONE ) ; m = m . subtract ( BigInteger . ONE ) ; BigInteger x , y , sumX , sumY ; y = n . shiftRight ( 1 ) ; x = n . subtract ( y ) ; sumX = sumY = BigInteger . ONE ; for ( ; m . compareTo ( sumX . add ( sumY ) ) > 0 ; ) { m = m . subtract ( sumX . add ( sumY ) ) ; x = x . subtract ( BigInteger . ONE ) ; y = y . subtract ( BigInteger . ONE ) ; BigInteger tx , ty , tSumX = sumX , tSumY = sumY ; tx = x . shiftRight ( 1 ) ; x = x . subtract ( tx ) ; ty = y . subtract ( y . shiftRight ( 1 ) ) ; y = y . shiftRight ( 1 ) ; if ( tx . equals ( x ) ) { sumX = sumX . add ( tSumX ) ; } else { sumY = sumY . add ( tSumX ) ; } if ( ty . equals ( x ) ) { sumX = sumX . add ( tSumY ) ; } else { sumY = sumY . add ( tSumY ) ; } } return m . compareTo ( sumX ) <= 0 ? x : y ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int t = in . nextInt ( ) ; for ( int i = 1 ; i <= t ; ++ i ) { BigInteger n = in . nextBigInteger ( ) ; BigInteger m = in . nextBigInteger ( ) ; BigInteger sum = solve ( n , m ) ; sum = sum . subtract ( BigInteger . ONE ) ; BigInteger div = sum . shiftRight ( 1 ) ; System . out . println ( \" Case ▁ # \" + i + \" : ▁ \" + sum . subtract ( div ) + \" ▁ \" + div ) ; } } }", "package zhang00000 ; import com . sun . tools . javac . jvm . Code ; import org . apache . commons . math3 . complex . Complex ; import java . io . * ; import java . util . * ; import java . util . stream . * ; import static java . util . stream . Collectors . * ; public class App { final int di [ ] = { 1 , - 1 , 0 , 0 , 1 , - 1 , 1 , - 1 } ; final int dj [ ] = { 0 , 0 , 1 , - 1 , 1 , - 1 , - 1 , 1 } ; final int diK [ ] = { - 2 , - 2 , - 1 , 1 , 2 , 2 , 1 , - 1 } ; final int djK [ ] = { - 1 , 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 } ; public static void main ( String [ ] args ) { if ( args . length == 1 ) { String filename = \" src / main / java / zhang00000 / \" + args [ 0 ] + \" . in \" ; if ( ! filename . isEmpty ( ) ) try { System . setIn ( new FileInputStream ( filename ) ) ; } catch ( FileNotFoundException e ) { System . out . println ( e . getMessage ( ) ) ; System . exit ( 1 ) ; } } Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int t = Integer . valueOf ( in . nextLine ( ) ) ; for ( int number = 1 ; number <= t ; number ++ ) { long n = in . nextLong ( ) ; long k = in . nextLong ( ) ; int d = Long . toBinaryString ( k ) . length ( ) - 1 ; long prev = ( n - k + Long . highestOneBit ( k ) ) >> d ; long max = prev / 2 ; long min = ( prev - 1 ) / 2 ; System . out . println ( \" Case ▁ # \" + number + \" : ▁ \" + max + \" ▁ \" + min ) ; } } }", "import java . util . * ; import java . io . * ; public class Main { public static long [ ] solve ( long N , long K ) { if ( K == 1 ) { long [ ] arr = new long [ 2 ] ; arr [ 0 ] = N / 2 ; arr [ 1 ] = ( N - 1 ) / 2 ; return arr ; } if ( K % 2 == 0 ) { return solve ( N / 2 , K / 2 ) ; } return solve ( ( N - 1 ) / 2 , K / 2 ) ; } public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( \" C - large . in \" ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( \" solve . txt \" ) ) ; int T = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; StringTokenizer s ; for ( int i = 1 ; i <= T ; i ++ ) { bw . write ( \" Case ▁ # \" + i + \" : ▁ \" ) ; s = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; long N = Long . parseLong ( s . nextToken ( ) ) ; long K = Long . parseLong ( s . nextToken ( ) ) ; long [ ] arr = solve ( N , K ) ; bw . write ( arr [ 0 ] + \" ▁ \" + arr [ 1 ] + \" \\n \" ) ; } br . close ( ) ; bw . close ( ) ; return ; } }", "import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int testCount = in . nextInt ( ) ; for ( int testNo = 1 ; testNo <= testCount ; testNo ++ ) { solve ( testNo , in ) ; } } private static void solve ( int testNo , Scanner in ) { long n = in . nextLong ( ) ; long k = in . nextLong ( ) ; System . out . println ( \" Case ▁ # \" + testNo + \" : ▁ \" + calc ( n , k ) ) ; } private static String calc ( long n , long k ) { TreeMap < Long , Long > treeMap = new TreeMap < > ( ) ; treeMap . put ( n , 1L ) ; while ( k > 0 ) { Map . Entry < Long , Long > entry = treeMap . lastEntry ( ) ; treeMap . remove ( entry . getKey ( ) ) ; if ( k <= entry . getValue ( ) ) { return entry . getKey ( ) / 2 + \" ▁ \" + ( entry . getKey ( ) - 1 ) / 2 ; } else { k -= entry . getValue ( ) ; if ( entry . getKey ( ) / 2 > 0 ) { long key = entry . getKey ( ) / 2 ; treeMap . put ( key , treeMap . getOrDefault ( key , 0L ) + entry . getValue ( ) ) ; } if ( ( entry . getKey ( ) - 1 ) / 2 > 0 ) { long key = ( entry . getKey ( ) - 1 ) / 2 ; treeMap . put ( key , treeMap . getOrDefault ( key , 0L ) + entry . getValue ( ) ) ; } } } throw new RuntimeException ( ) ; } }" ]
[ "for tc in range ( input ( ) ) : NEW_LINE INDENT N , K = map ( int , raw_input ( ) . split ( ) ) NEW_LINE s = 1 NEW_LINE x = N NEW_LINE lc = 1 NEW_LINE sc = 0 NEW_LINE while K > s : NEW_LINE INDENT if x % 2 == 0 : NEW_LINE INDENT lc , sc = lc , lc + 2 * sc NEW_LINE DEDENT else : NEW_LINE INDENT lc , sc = 2 * lc + sc , sc NEW_LINE DEDENT x = x / 2 NEW_LINE K = K - s NEW_LINE s = s * 2 NEW_LINE DEDENT x = x if K <= lc else x - 1 NEW_LINE if x % 2 == 0 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d ▁ % d \" % ( tc + 1 , x / 2 , x / 2 - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d ▁ % d \" % ( tc + 1 , x / 2 , x / 2 ) NEW_LINE DEDENT DEDENT", "from itertools import groupby NEW_LINE def solve ( ) : NEW_LINE INDENT n , k = [ int ( w ) for w in input ( ) . split ( ) ] NEW_LINE a = [ ( n , 1 ) ] NEW_LINE while True : NEW_LINE INDENT b = [ ] NEW_LINE for d , cnt in a : NEW_LINE INDENT if cnt < k : NEW_LINE INDENT k -= cnt NEW_LINE b . append ( ( ( d - 1 ) // 2 , cnt ) ) NEW_LINE b . append ( ( d // 2 , cnt ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return \" { } ▁ { } \" . format ( d // 2 , ( d - 1 ) // 2 ) NEW_LINE DEDENT DEDENT a = [ ( f , sum ( s for _ , s in g ) ) for f , g in groupby ( sorted ( b ) , key = lambda t : t [ 0 ] ) ] NEW_LINE a = list ( reversed ( [ x for x in a if x [ 0 ] > 0 ] ) ) NEW_LINE DEDENT DEDENT def prepare_input ( ) : NEW_LINE INDENT local = False NEW_LINE task = ' C ' NEW_LINE attempt = - 1 NEW_LINE import sys NEW_LINE if local : NEW_LINE INDENT sys . stdin = open ( \" . . / input . txt \" , \" r \" ) NEW_LINE DEDENT else : NEW_LINE INDENT filename = \" . . / { } - small - 2 - attempt { } \" . format ( task , attempt ) if attempt >= 0 else \" . . / { } - large \" . format ( task ) NEW_LINE sys . stdin = open ( filename + \" . in \" , \" r \" ) NEW_LINE sys . stdout = open ( filename + \" . out \" , \" w \" ) NEW_LINE print ( \" filename : \" , filename [ 3 : ] , file = sys . stderr ) NEW_LINE DEDENT DEDENT prepare_input ( ) NEW_LINE tests = int ( input ( ) ) NEW_LINE for test in range ( 1 , tests + 1 ) : NEW_LINE INDENT res = solve ( ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } \" . format ( test , res ) ) NEW_LINE DEDENT", "import sys NEW_LINE import numpy as np NEW_LINE import heapq NEW_LINE def solve ( n , k ) : NEW_LINE INDENT intervals = { n : 1 } NEW_LINE lens = [ - n ] NEW_LINE ls = 0 NEW_LINE rs = 0 NEW_LINE while k > 0 : NEW_LINE INDENT val = - heapq . heappop ( lens ) NEW_LINE num = intervals [ val ] NEW_LINE del intervals [ val ] NEW_LINE k = k - num NEW_LINE ls = int ( ( val - 1 ) / 2 ) NEW_LINE rs = val - ls - 1 NEW_LINE if not ls in intervals : NEW_LINE INDENT intervals [ ls ] = 0 NEW_LINE heapq . heappush ( lens , - ls ) NEW_LINE DEDENT if not rs in intervals : NEW_LINE INDENT intervals [ rs ] = 0 NEW_LINE heapq . heappush ( lens , - rs ) NEW_LINE DEDENT intervals [ rs ] = intervals [ rs ] + num NEW_LINE intervals [ ls ] = intervals [ ls ] + num NEW_LINE DEDENT return ( max ( ls , rs ) , min ( ls , rs ) ) NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT n , m = [ s for s in raw_input ( ) . split ( \" ▁ \" ) ] NEW_LINE data = [ int ( a ) for a in list ( str ( n ) ) ] NEW_LINE result = solve ( int ( n ) , int ( m ) ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } ▁ { } \" . format ( i , result [ 0 ] , result [ 1 ] ) ) NEW_LINE DEDENT", "from collections import defaultdict NEW_LINE IN = open ( ' input . txt ' , ' r ' ) NEW_LINE OUT = open ( ' output . txt ' , ' w ' ) NEW_LINE NUM_TESTS = int ( IN . readline ( ) ) NEW_LINE for test in xrange ( NUM_TESTS ) : NEW_LINE INDENT N , K = map ( int , IN . readline ( ) . split ( ) ) NEW_LINE queue = defaultdict ( int ) NEW_LINE queue [ N ] = 1 NEW_LINE sizes = [ ] NEW_LINE binN = ' { : b } ' . format ( N ) NEW_LINE for i in xrange ( 1 , len ( binN ) + 1 ) : NEW_LINE INDENT sizes . append ( int ( binN [ : i ] , 2 ) - 1 ) NEW_LINE sizes . append ( int ( binN [ : i ] , 2 ) ) NEW_LINE DEDENT sizes = sizes [ : : - 1 ] NEW_LINE for chunkSize in sizes : NEW_LINE INDENT chunkNum = queue [ chunkSize ] NEW_LINE minNext = ( chunkSize - 1 ) / 2 NEW_LINE maxNext = ( chunkSize - 1 ) - minNext NEW_LINE if K <= chunkNum : NEW_LINE INDENT answer = ( maxNext , minNext ) NEW_LINE break NEW_LINE DEDENT K -= chunkNum NEW_LINE if maxNext == minNext : NEW_LINE INDENT queue [ maxNext ] += 2 * chunkNum NEW_LINE DEDENT else : NEW_LINE INDENT queue [ maxNext ] += chunkNum NEW_LINE queue [ minNext ] += chunkNum NEW_LINE DEDENT DEDENT OUT . write ( ' Case ▁ # { } : ▁ { } ▁ { } \\n ' . format ( test + 1 , answer [ 0 ] , answer [ 1 ] ) ) NEW_LINE print test + 1 , answer NEW_LINE DEDENT IN . close ( ) NEW_LINE OUT . close ( ) NEW_LINE", "infilecode = \" CLI \" NEW_LINE import sys NEW_LINE mapping = { \" A \" : \" A \" , \" B \" : \" B \" , \" C \" : \" C \" , \" D \" : \" D \" , \" E \" : \" E \" , \" X \" : \" example \" , \" S \" : \" - small \" , \" L \" : \" - large \" , \" P \" : \" - practice \" , \"0\" : \" - attempt0\" , \"1\" : \" - attempt1\" , \"2\" : \" - attempt2\" , \" z \" : \" - 1\" , \" Z \" : \" - 2\" , \" I \" : \" . in \" , \" T \" : \" . txt \" } NEW_LINE infile = \" \" . join ( mapping [ c ] for c in infilecode ) NEW_LINE outfile = infile . replace ( \" . in \" , \" \" ) + \" . out . txt \" NEW_LINE sys . stdin = open ( infile , ' r ' ) NEW_LINE output = open ( outfile , ' w ' ) NEW_LINE T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE print ( N , K ) NEW_LINE sizes = [ N , N + 1 ] NEW_LINE num = [ 1 , 0 ] NEW_LINE while K > sum ( num ) : NEW_LINE INDENT a , b = sizes NEW_LINE K -= sum ( num ) NEW_LINE sizes = [ ( a - 1 ) // 2 , b // 2 ] NEW_LINE if a % 2 == 0 : NEW_LINE INDENT num = [ num [ 0 ] , num [ 0 ] + num [ 1 ] * 2 ] NEW_LINE DEDENT else : NEW_LINE INDENT num = [ num [ 0 ] * 2 + num [ 1 ] , num [ 1 ] ] NEW_LINE DEDENT print ( sizes , num , K ) NEW_LINE DEDENT if K <= num [ 1 ] : NEW_LINE INDENT size = sizes [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT size = sizes [ 0 ] NEW_LINE DEDENT R = size // 2 NEW_LINE L = ( size - 1 ) // 2 NEW_LINE answer = str ( R ) + \" ▁ \" + str ( L ) NEW_LINE print ( \" Case ▁ # % d : \" % case , answer ) NEW_LINE print ( \" Case ▁ # % d : \" % case , answer , file = output ) NEW_LINE DEDENT" ]
codejam_10_02
[ "import java . util . * ; import java . math . * ; public class B { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; int caseN = cin . nextInt ( ) ; for ( int caseI = 1 ; caseI <= caseN ; caseI ++ ) { int n = cin . nextInt ( ) ; BigInteger [ ] times = new BigInteger [ n ] ; for ( int i = 0 ; i < n ; i ++ ) times [ i ] = new BigInteger ( cin . next ( ) ) ; BigInteger ans = times [ 0 ] . subtract ( times [ 1 ] ) . abs ( ) ; for ( int i = 2 ; i < n ; i ++ ) ans = ans . gcd ( times [ i ] . subtract ( times [ i - 1 ] ) . abs ( ) ) ; ans = ans . subtract ( times [ 0 ] . mod ( ans ) ) . mod ( ans ) ; System . out . printf ( \" Case ▁ # % d : ▁ % s \" , caseI , ans . toString ( ) ) ; System . out . println ( ) ; } } }", "import java . math . BigInteger ; import java . util . * ; public class Main { Scanner in = new Scanner ( System . in ) ; BigInteger [ ] data ; BigInteger solve ( ) { int N = in . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) data [ i ] = in . nextBigInteger ( ) ; Arrays . sort ( data , 0 , N ) ; BigInteger g = data [ 1 ] . subtract ( data [ 0 ] ) ; for ( int i = 2 ; i < N ; i ++ ) g = g . gcd ( data [ i ] . subtract ( data [ i - 1 ] ) ) ; return g . subtract ( data [ 0 ] . remainder ( g ) ) . remainder ( g ) ; } void cases ( ) { data = new BigInteger [ 1000 ] ; int T = in . nextInt ( ) ; for ( int c = 1 ; c <= T ; c ++ ) System . out . println ( \" Case ▁ # \" + c + \" : ▁ \" + solve ( ) ) ; } public static void main ( String [ ] args ) throws Exception { ( new Main ( ) ) . cases ( ) ; } }", "import java . io . * ; import java . math . * ; import java . util . * ; public class Main { Scanner in ; BufferedReader br ; PrintWriter out ; public void run ( ) throws Exception { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { TreeSet < BigInteger > hs = new TreeSet < BigInteger > ( ) ; int nnn = in . nextInt ( ) ; for ( int i = 0 ; i < nnn ; i ++ ) hs . add ( in . nextBigInteger ( ) ) ; int n = hs . size ( ) ; BigInteger [ ] a = new BigInteger [ n ] ; nnn = 0 ; for ( BigInteger x : hs ) a [ nnn ++ ] = x ; BigInteger g = a [ 1 ] . subtract ( a [ 0 ] ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { g = g . gcd ( a [ j ] . subtract ( a [ i ] ) ) ; } } BigInteger mn = BigInteger . valueOf ( 10 ) . pow ( 100 ) ; BigInteger g1 = g . subtract ( BigInteger . ONE ) ; for ( int i = 0 ; i < n ; i ++ ) { BigInteger cur = a [ i ] . add ( g1 ) . divide ( g ) . multiply ( g ) . subtract ( a [ i ] ) ; mn = mn . min ( cur ) ; } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + mn ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws Exception { new Main ( ) . run ( ) ; } }", "import java . io . * ; import java . util . * ; import java . math . * ; public class Main implements Runnable { static Scanner scanner ; static BufferedReader input ; static PrintWriter pw ; public static void main ( String [ ] args ) throws Exception { new Thread ( new Main ( ) ) . start ( ) ; } public void run ( ) { try { input = new BufferedReader ( new FileReader ( \" input . txt \" ) ) ; scanner = new Scanner ( input ) ; pw = new PrintWriter ( new File ( \" output . txt \" ) ) ; solve ( ) ; pw . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } public void solve ( ) throws Exception { int qq = scanner . nextInt ( ) ; for ( int ii = 0 ; ii < qq ; ii ++ ) { int n = scanner . nextInt ( ) ; BigInteger [ ] a = new BigInteger [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scanner . nextBigInteger ( ) ; } BigInteger x = BigInteger . ZERO ; for ( int i = 1 ; i < n ; i ++ ) { x = x . gcd ( a [ i ] . subtract ( a [ 0 ] ) ) ; } BigInteger ans = ( x . subtract ( a [ 0 ] . mod ( x ) ) ) . mod ( x ) ; pw . println ( \" Case ▁ # \" + ( ii + 1 ) + \" : ▁ \" + ans ) ; } } }", "import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class B { public static void main ( String args [ ] ) throws Exception { String inFile = \" B - large . in \" ; String outFile = inFile + \" . out \" ; LineNumberReader lin = new LineNumberReader ( new InputStreamReader ( new FileInputStream ( inFile ) ) ) ; PrintWriter out = new PrintWriter ( new File ( outFile ) ) ; int NCASE = Integer . parseInt ( lin . readLine ( ) ) ; for ( int CASE = 1 ; CASE <= NCASE ; CASE ++ ) { out . print ( \" Case ▁ # \" + CASE + \" : ▁ \" ) ; String l = lin . readLine ( ) ; String ll [ ] = l . split ( \" ▁ \" ) ; int N = Integer . parseInt ( ll [ 0 ] ) ; BigInteger t [ ] = new BigInteger [ N ] ; for ( int i = 0 ; i < N ; i ++ ) t [ i ] = new BigInteger ( ll [ i + 1 ] ) ; BigInteger T = null ; for ( int a = 0 ; a < N ; a ++ ) for ( int b = a ; ++ b < N ; ) { BigInteger d = t [ a ] . subtract ( t [ b ] ) . abs ( ) ; if ( T == null ) T = d ; else T = T . gcd ( d ) ; } BigInteger y = t [ 0 ] . mod ( T ) ; if ( ! y . equals ( BigInteger . ZERO ) ) y = T . subtract ( y ) ; out . println ( y ) ; } lin . close ( ) ; out . close ( ) ; } }" ]
[ "C = int ( raw_input ( ) ) NEW_LINE from fractions import gcd NEW_LINE for case in xrange ( 1 , C + 1 ) : NEW_LINE INDENT ts = [ int ( t ) for t in raw_input ( ) . split ( ) [ 1 : ] ] NEW_LINE m = min ( ts ) NEW_LINE td = [ t - m for t in ts ] NEW_LINE T = reduce ( gcd , td ) NEW_LINE print \" Case ▁ # \" + str ( case ) + \" : \" , ( T - m ) % T NEW_LINE DEDENT", "import sys NEW_LINE def readline ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) [ : - 1 ] NEW_LINE DEDENT def readnlines ( n ) : NEW_LINE INDENT l = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT l . append ( readline ( ) ) NEW_LINE DEDENT DEDENT def gcd ( a , b ) : NEW_LINE INDENT if a >= b : NEW_LINE INDENT m = a % b NEW_LINE if m == 0 : NEW_LINE INDENT return b NEW_LINE DEDENT else : NEW_LINE INDENT return gcd ( b , m ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return gcd ( b , a ) NEW_LINE DEDENT DEDENT def truc ( x0 , x ) : NEW_LINE INDENT y = abs ( x0 - x ) NEW_LINE if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return y NEW_LINE DEDENT DEDENT for curcase in range ( 1 , int ( readline ( ) ) + 1 ) : NEW_LINE INDENT l = map ( int , readline ( ) . split ( ) ) NEW_LINE n = l [ 0 ] NEW_LINE l = l [ 1 : ] NEW_LINE x0 = l [ 0 ] NEW_LINE diff = map ( lambda x : abs ( x0 - x ) , l [ 1 : ] ) NEW_LINE cur = diff [ 0 ] NEW_LINE for i in range ( 1 , len ( diff ) ) : NEW_LINE INDENT if cur == 0 : NEW_LINE INDENT cur = diff [ i ] NEW_LINE DEDENT if diff [ i ] != 0 : NEW_LINE INDENT cur = gcd ( cur , diff [ i ] ) NEW_LINE DEDENT DEDENT todo = x0 % cur NEW_LINE if todo == 0 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( curcase , 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( curcase , cur - todo ) NEW_LINE DEDENT DEDENT", "from __future__ import division NEW_LINE import collections NEW_LINE import itertools NEW_LINE import sys NEW_LINE class gcj : NEW_LINE INDENT IN = sys . stdin NEW_LINE number = 0 NEW_LINE @ classmethod NEW_LINE def case ( cls ) : NEW_LINE INDENT cls . number += 1 NEW_LINE return ' Case ▁ # % d : ' % cls . number NEW_LINE DEDENT @ classmethod NEW_LINE def line ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return type ( line . strip ( ' \\n ' ) ) NEW_LINE DEDENT @ classmethod NEW_LINE def splitline ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return [ type ( x ) for x in line . split ( ) ] NEW_LINE DEDENT DEDENT def go ( ) : NEW_LINE INDENT c = gcj . line ( int ) NEW_LINE for _ in xrange ( c ) : NEW_LINE INDENT events = gcj . splitline ( int ) [ 1 : ] NEW_LINE print gcj . case ( ) , solve ( events ) NEW_LINE DEDENT DEDENT def gcd ( a , b ) : NEW_LINE INDENT while a != 0 : NEW_LINE INDENT a , b = b % a , a NEW_LINE DEDENT return b NEW_LINE DEDENT def mgcd ( l ) : NEW_LINE INDENT l = iter ( l ) NEW_LINE res = l . next ( ) NEW_LINE for x in l : NEW_LINE INDENT res = gcd ( res , x ) NEW_LINE if res == 1 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def solve ( events ) : NEW_LINE INDENT T = mgcd ( x - y for x in events for y in events if x > y ) NEW_LINE return ( - min ( events ) ) % T NEW_LINE DEDENT go ( ) NEW_LINE", "import sys NEW_LINE def GCD ( x , y ) : NEW_LINE INDENT if x < 0 : x = - x NEW_LINE if y < 0 : y = - y NEW_LINE if x + y > 0 : NEW_LINE INDENT g = y NEW_LINE while x > 0 : NEW_LINE INDENT g = x NEW_LINE x = y % x NEW_LINE y = g NEW_LINE DEDENT return g NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def f ( a ) : NEW_LINE INDENT xx = a [ - 1 ] NEW_LINE x = xx NEW_LINE a = a [ : - 1 ] NEW_LINE for i in range ( len ( a ) ) : NEW_LINE INDENT a [ i ] = a [ i ] - x NEW_LINE DEDENT g = a [ 0 ] NEW_LINE for x in a [ 1 : ] : NEW_LINE INDENT g = GCD ( g , x ) NEW_LINE DEDENT g = abs ( g ) NEW_LINE return ( g - xx ) % g NEW_LINE DEDENT c = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( 1 , c + 1 ) : NEW_LINE INDENT a = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = a [ 0 ] NEW_LINE a = a [ 1 : ] NEW_LINE assert len ( a ) == n NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i , f ( a ) ) NEW_LINE DEDENT", "def debug ( ** a ) : NEW_LINE INDENT print \" ▁ \" . join ( \" % s = % s \" % ( k , v ) for ( k , v ) in a . iteritems ( ) ) NEW_LINE DEDENT def read_ints ( ) : NEW_LINE INDENT return [ int ( x ) for x in raw_input ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def gcd2 ( a , b ) : NEW_LINE INDENT if a < b : NEW_LINE INDENT return gcd2 ( b , a ) NEW_LINE DEDENT elif b == 0 : NEW_LINE INDENT return a NEW_LINE DEDENT else : NEW_LINE INDENT return gcd2 ( b , a % b ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT [ C ] = read_ints ( ) NEW_LINE for c in xrange ( 1 , C + 1 ) : NEW_LINE INDENT t = read_ints ( ) [ 1 : ] NEW_LINE T = abs ( t [ 0 ] - t [ 1 ] ) NEW_LINE for i in xrange ( len ( t ) ) : NEW_LINE INDENT for j in xrange ( i + 1 , len ( t ) ) : NEW_LINE INDENT T = gcd2 ( T , abs ( t [ i ] - t [ j ] ) ) NEW_LINE DEDENT DEDENT y = - t [ 0 ] % T NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( c , y ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_09_41
[ "import java . util . * ; import java . io . * ; public class Main implements Runnable { public Scanner in ; public PrintWriter out ; Main ( ) throws IOException { in = new Scanner ( new File ( \" in \" ) ) ; out = new PrintWriter ( new File ( \" out \" ) ) ; } void close ( ) throws IOException { out . close ( ) ; } public void run ( ) { int tn = in . nextInt ( ) ; for ( int test = 1 ; test <= tn ; test ++ ) { int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . next ( ) ; a [ i ] = s . lastIndexOf ( \"1\" ) ; } int r = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int j = i ; while ( a [ j ] > i ) { j ++ ; } r += j - i ; int t = a [ j ] ; while ( j > i ) { a [ j ] = a [ j - 1 ] ; j -- ; } a [ i ] = t ; } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + r ) ; } try { close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public static void main ( String [ ] args ) throws IOException { new Thread ( new Main ( ) ) . start ( ) ; } }", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . PrintWriter ; public class A implements Runnable { public static void main ( String [ ] args ) { new Thread ( new A ( ) ) . start ( ) ; } public void run ( ) { try { solve ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } private void solve ( ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( \" a . in \" ) ) ; PrintWriter pw = new PrintWriter ( \" a . out \" ) ; int tests = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; for ( int test = 1 ; test <= tests ; test ++ ) { int n = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; String [ ] s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = br . readLine ( ) . trim ( ) ; } int result = 0 ; for ( int row = 0 ; row < n ; row ++ ) { for ( int i = row ; i < n ; i ++ ) { boolean can = true ; for ( int k = row + 1 ; k < n ; k ++ ) { if ( s [ i ] . charAt ( k ) == '1' ) { can = false ; break ; } } if ( can ) { for ( int k = i - 1 ; k >= row ; k -- ) { String str = s [ k + 1 ] ; s [ k + 1 ] = s [ k ] ; s [ k ] = str ; result ++ ; } break ; } } } pw . println ( \" Case ▁ # \" + test + \" : ▁ \" + result ) ; } br . close ( ) ; pw . close ( ) ; } }", "import java . io . BufferedReader ; import java . io . FileOutputStream ; import java . io . FileReader ; import java . io . IOException ; import java . io . PrintStream ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( \" A - large . in \" ) ) ; PrintStream ps = new PrintStream ( new FileOutputStream ( \" A - large . out \" ) ) ; int cases = Integer . parseInt ( br . readLine ( ) ) ; for ( int itr = 1 ; itr <= cases ; itr ++ ) { int size = Integer . parseInt ( br . readLine ( ) ) ; int [ ] board = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { String s = br . readLine ( ) ; for ( int j = 0 ; j < size ; j ++ ) if ( s . charAt ( j ) == '1' ) board [ i ] = j ; } int out = 0 ; boolean done = false ; while ( ! done ) { done = true ; for ( int i = 0 ; i < size ; i ++ ) { if ( board [ i ] > i ) { done = false ; int s = 0 ; for ( int j = i + 1 ; j < size ; j ++ ) if ( board [ j ] <= i ) { s = j ; break ; } for ( int j = s ; j > i ; j -- ) { int t = board [ j ] ; board [ j ] = board [ j - 1 ] ; board [ j - 1 ] = t ; out ++ ; } } } } ps . println ( \" Case ▁ # \" + itr + \" : ▁ \" + out ) ; } br . close ( ) ; ps . close ( ) ; } }", "import java . io . * ; import java . util . * ; public class A implements Runnable { private static String fileName = A . class . getSimpleName ( ) . replaceFirst ( \" _ . * \" , \" \" ) ; private static String inputFileName = fileName + \" . in \" ; private static String outputFileName = fileName + \" . out \" ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . next ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( s . charAt ( j ) == '1' ) { a [ i ] = j ; } } } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = i ; ; j ++ ) { if ( a [ j ] <= i ) break ; } for ( int k = j ; k > i ; k -- ) { ans ++ ; int t = a [ k ] ; a [ k ] = a [ k - 1 ] ; a [ k - 1 ] = t ; } } out . println ( ans ) ; } public void run ( ) { int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; solve ( ) ; } } public static void main ( String [ ] args ) throws IOException , InterruptedException { Locale . setDefault ( Locale . US ) ; if ( args . length >= 2 ) { inputFileName = args [ 0 ] ; outputFileName = args [ 1 ] ; } in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; Thread thread = new Thread ( new A ( ) ) ; thread . start ( ) ; thread . join ( ) ; in . close ( ) ; out . close ( ) ; } }", "import java . util . Scanner ; import java . io . File ; import java . io . PrintWriter ; import java . io . FileNotFoundException ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" A . in \" ) ) ; PrintWriter out = new PrintWriter ( \" A . out \" ) ; int t = in . nextInt ( ) ; in . nextLine ( ) ; for ( int tn = 0 ; tn < t ; tn ++ ) { out . println ( \" Case ▁ # \" + ( tn + 1 ) + \" : ▁ \" + solve ( in ) ) ; } out . close ( ) ; } private static String solve ( Scanner in ) { int n = in . nextInt ( ) ; in . nextLine ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . nextLine ( ) ; int j = n - 1 ; while ( s . charAt ( j ) == '0' && j > 0 ) j -- ; a [ i ] = j ; } int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j = i ; while ( a [ j ] > i ) j ++ ; int t = a [ j ] ; for ( int k = j ; k > i ; k -- ) a [ k ] = a [ k - 1 ] ; a [ i ] = t ; res += ( j - i ) ; } return \" \" + res ; } }" ]
[ "import sys NEW_LINE def max1 ( r ) : NEW_LINE INDENT z = [ i for i in range ( len ( r ) ) if r [ i ] == 1 ] NEW_LINE if ( z == [ ] ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return max ( z ) NEW_LINE DEDENT DEDENT def solve ( inp ) : NEW_LINE INDENT inp = [ max1 ( s ) for s in inp ] NEW_LINE ans = 0 NEW_LINE for i in range ( len ( inp ) ) : NEW_LINE INDENT z = min ( [ q for q in range ( len ( inp ) ) if q >= i and inp [ q ] <= i ] ) NEW_LINE r = list ( range ( i , z ) ) NEW_LINE r . reverse ( ) NEW_LINE for j in r : NEW_LINE INDENT inp [ j ] , inp [ j + 1 ] = inp [ j + 1 ] , inp [ j ] NEW_LINE ans += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT rdln = sys . stdin . readline NEW_LINE T = int ( rdln ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT N = int ( rdln ( ) ) NEW_LINE print ( \" Case ▁ # \" , t + 1 , \" : ▁ \" , solve ( [ [ int ( c ) for c in rdln ( ) . strip ( ) ] for w in range ( N ) ] ) , sep = \" \" ) NEW_LINE DEDENT", "def can ( line , idx ) : NEW_LINE INDENT return line [ idx + 1 : ] . find ( '1' ) == - 1 NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT T = int ( raw_input ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % t , NEW_LINE N = int ( raw_input ( ) ) NEW_LINE A = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A . append ( raw_input ( ) ) NEW_LINE DEDENT P = [ ] NEW_LINE U = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if not U [ j ] and can ( A [ i ] , j ) : NEW_LINE INDENT P . append ( j ) NEW_LINE U [ j ] = 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT result = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT result += P [ i ] > P [ j ] NEW_LINE DEDENT DEDENT print result NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "from __future__ import division NEW_LINE import collections NEW_LINE import itertools NEW_LINE import sys NEW_LINE class gcj : NEW_LINE INDENT IN = sys . stdin NEW_LINE number = 0 NEW_LINE @ classmethod NEW_LINE def case ( cls ) : NEW_LINE INDENT cls . number += 1 NEW_LINE return ' Case ▁ # % d : ' % cls . number NEW_LINE DEDENT @ classmethod NEW_LINE def line ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return type ( line . strip ( ' \\n ' ) ) NEW_LINE DEDENT @ classmethod NEW_LINE def splitline ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return [ type ( x ) for x in line . split ( ) ] NEW_LINE DEDENT DEDENT def go ( ) : NEW_LINE INDENT t = gcj . line ( int ) NEW_LINE for _ in xrange ( t ) : NEW_LINE INDENT n = gcj . line ( int ) NEW_LINE data = [ ] NEW_LINE for _ in xrange ( n ) : NEW_LINE INDENT data . append ( [ int ( x ) for x in gcj . line ( ) ] ) NEW_LINE assert len ( data [ - 1 ] ) == n NEW_LINE DEDENT print gcj . case ( ) , solve ( data ) NEW_LINE DEDENT DEDENT def solve ( data ) : NEW_LINE INDENT res = 0 NEW_LINE n = len ( data ) NEW_LINE gdzie = [ 0 ] * n NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT row = data [ i ] NEW_LINE x = n - 1 NEW_LINE while x >= 0 and row [ x ] == 0 : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT gdzie [ i ] = x NEW_LINE DEDENT for i in xrange ( n ) : NEW_LINE INDENT j = min ( j for j in xrange ( i , n ) if gdzie [ j ] <= i ) NEW_LINE for k in xrange ( j , i , - 1 ) : NEW_LINE INDENT gdzie [ k ] , gdzie [ k - 1 ] = gdzie [ k - 1 ] , gdzie [ k ] NEW_LINE res += 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT go ( ) NEW_LINE", "import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( N , foo ) : return [ foo ( ) for i in xrange ( N ) ] NEW_LINE def readlinearray ( foo ) : return map ( foo , raw_input ( ) . split ( ) ) NEW_LINE def dig ( c ) : NEW_LINE INDENT c = ord ( c ) NEW_LINE if c >= 97 : NEW_LINE INDENT return c - 87 NEW_LINE DEDENT return c - 48 NEW_LINE DEDENT def run_test ( test ) : NEW_LINE INDENT n = readint ( ) NEW_LINE a = readarray ( n , raw_input ) NEW_LINE maxpos = [ 0 ] * n NEW_LINE used = [ False ] * n NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT for j in xrange ( n ) : NEW_LINE INDENT if ( a [ i ] [ j ] == \"1\" ) : NEW_LINE INDENT maxpos [ i ] = j NEW_LINE DEDENT DEDENT DEDENT res = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT for j in xrange ( i , n ) : NEW_LINE INDENT if ( maxpos [ j ] > i ) : continue NEW_LINE for k in xrange ( j , i , - 1 ) : NEW_LINE INDENT ( maxpos [ k ] , maxpos [ k - 1 ] ) = ( maxpos [ k - 1 ] , maxpos [ k ] ) NEW_LINE res += 1 NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % s \" % ( test + 1 , str ( res ) ) NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( \" test ▁ % d \\n \" % test ) NEW_LINE run_test ( test ) NEW_LINE DEDENT", "def readInput ( ) : NEW_LINE INDENT file = open ( \" A - large . in \" ) NEW_LINE testCaseCount = int ( file . readline ( ) . rstrip ( ) ) NEW_LINE testCases = [ ] NEW_LINE for i in range ( 0 , testCaseCount ) : NEW_LINE INDENT lineCount = int ( file . readline ( ) . strip ( ) ) NEW_LINE lines = [ len ( file . readline ( ) . strip ( ) . rstrip ( '0' ) ) for j in range ( 0 , lineCount ) ] NEW_LINE testCases . append ( lines ) NEW_LINE DEDENT return testCases NEW_LINE DEDENT def numberOfSortSteps ( testCase ) : NEW_LINE INDENT steps = 0 NEW_LINE stop = False NEW_LINE for lineNr in range ( 0 , len ( testCase ) ) : NEW_LINE INDENT for targetLineNr in range ( lineNr , len ( testCase ) ) : NEW_LINE INDENT if testCase [ targetLineNr ] <= lineNr + 1 : NEW_LINE INDENT testCase . insert ( lineNr , testCase . pop ( targetLineNr ) ) NEW_LINE steps += targetLineNr - lineNr NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return steps NEW_LINE DEDENT testCases = readInput ( ) NEW_LINE testCaseNr = 1 NEW_LINE for testCase in testCases : NEW_LINE INDENT print ' Case ▁ # % s : ▁ % s ' % ( testCaseNr , numberOfSortSteps ( testCase ) ) NEW_LINE testCaseNr += 1 NEW_LINE DEDENT" ]
codejam_11_01
[ "import java . io . * ; import java . util . * ; public class BotTrust { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new FileReader ( \" A - large . in \" ) ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output \" ) ) ; for ( int I = 1 ; I <= T ; I ++ ) { StringTokenizer st = new StringTokenizer ( br . readLine ( ) , \" ▁ \\n \\t \" , false ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int Opos = 1 , Bpos = 1 ; int Oextra = 0 , Bextra = 0 ; int ret = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int nextBot = ( st . nextToken ( ) . equals ( \" O \" ) ? 0 : 1 ) ; int button = Integer . parseInt ( st . nextToken ( ) ) ; if ( nextBot == 0 ) { int dist = Math . abs ( Opos - button ) ; if ( Oextra >= dist ) dist = 0 ; else dist -= Oextra ; ret += dist + 1 ; Bextra += dist + 1 ; Oextra = 0 ; Opos = button ; } else { int dist = Math . abs ( Bpos - button ) ; if ( Bextra >= dist ) dist = 0 ; else dist -= Bextra ; ret += dist + 1 ; Oextra += dist + 1 ; Bextra = 0 ; Bpos = button ; } } pw . println ( \" Case ▁ # \" + I + \" : ▁ \" + ret ) ; } br . close ( ) ; pw . flush ( ) ; pw . close ( ) ; } catch ( IOException ie ) { ie . printStackTrace ( ) ; } } }", "import java . util . Scanner ; public class bottrust { public static void main ( String [ ] args ) { Scanner ins = new Scanner ( System . in ) ; int cc ; int ntc = ins . nextInt ( ) ; for ( cc = 1 ; cc <= ntc ; cc ++ ) { int pos [ ] = { 1 , 1 } , time [ ] = { 0 , 0 } ; int cnt = ins . nextInt ( ) ; for ( int i = 0 ; i < cnt ; i ++ ) { String s = ins . next ( ) ; int r = 0 ; if ( s . equals ( \" B \" ) ) r = 1 ; int p = ins . nextInt ( ) ; int mtime = p - pos [ r ] ; if ( mtime < 0 ) mtime = - mtime ; mtime += time [ r ] + 1 ; if ( mtime <= time [ 1 - r ] ) mtime = time [ 1 - r ] + 1 ; time [ r ] = mtime ; pos [ r ] = p ; } int maxtime = time [ 0 ] ; if ( time [ 1 ] > maxtime ) maxtime = time [ 1 ] ; System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , cc , maxtime ) ; } } }", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . util . Iterator ; public class InputFileParser implements Iterable < String [ ] > { private final int linesPerCase ; private final int totalCases ; private BufferedReader reader ; private int casesExtracted = 0 ; public InputFileParser ( int linesPerCase , String fileName ) { this . linesPerCase = linesPerCase ; try { FileReader fileReader = new FileReader ( fileName ) ; this . reader = new BufferedReader ( fileReader ) ; String line = this . reader . readLine ( ) ; this . totalCases = Integer . parseInt ( line ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } } private String readLine ( ) { try { return this . reader . readLine ( ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } } @ Override public Iterator < String [ ] > iterator ( ) { return new Iterator < String [ ] > ( ) { @ Override public boolean hasNext ( ) { return casesExtracted < totalCases ; } @ Override public String [ ] next ( ) { String [ ] caseLines = new String [ linesPerCase ] ; for ( int i = 0 ; i < linesPerCase ; i ++ ) { caseLines [ i ] = readLine ( ) ; } casesExtracted ++ ; return caseLines ; } @ Override public void remove ( ) { } } ; } }", "import java . io . * ; import java . util . * ; import java . util . regex . Pattern ; public class GCJ2011QualA { void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int testCase = 1 ; testCase <= T ; testCase ++ ) { int N = sc . nextInt ( ) ; int oT = 0 , bT = 0 ; int oP = 1 , bP = 1 ; for ( int i = 0 ; i < N ; i ++ ) { char [ ] c = sc . next ( ) . toCharArray ( ) ; int pos = sc . nextInt ( ) ; if ( c [ 0 ] == ' O ' ) { oT = Math . max ( oT + Math . abs ( pos - oP ) , bT ) + 1 ; oP = pos ; } else { bT = Math . max ( bT + Math . abs ( pos - bP ) , oT ) + 1 ; bP = pos ; } } System . out . println ( \" Case ▁ # \" + testCase + \" : ▁ \" + Math . max ( bT , oT ) ) ; } } public static void main ( String args [ ] ) { new GCJ2011QualA ( ) . solve ( ) ; } }", "import java . util . * ; import java . io . * ; public class Solution { public void doMain ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { pw . print ( \" Case ▁ # \" + ( caseNum + 1 ) + \" : ▁ \" ) ; int curO = 1 , spareStepsO = 0 , curB = 1 , spareStepsB = 0 ; int N = sc . nextInt ( ) ; int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String who = sc . next ( ) ; if ( who . equals ( \" O \" ) ) { int pos = sc . nextInt ( ) ; int dist = Math . abs ( curO - pos ) + 1 ; dist -= Math . min ( spareStepsO , dist - 1 ) ; res += dist ; spareStepsB += dist ; spareStepsO = 0 ; curO = pos ; } else { int pos = sc . nextInt ( ) ; int dist = Math . abs ( curB - pos ) + 1 ; dist -= Math . min ( spareStepsB , dist - 1 ) ; res += dist ; spareStepsO += dist ; spareStepsB = 0 ; curB = pos ; } } pw . println ( res ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) throws Exception { new Solution ( ) . doMain ( ) ; } }" ]
[ "import sys NEW_LINE import os NEW_LINE def myabs ( a ) : NEW_LINE INDENT if ( a < 0 ) : return - a NEW_LINE else : return a NEW_LINE DEDENT lines = open ( \" a2 . in \" , \" r \" ) . readlines ( ) NEW_LINE t = int ( lines [ 0 ] . strip ( ) ) NEW_LINE for ti in range ( 1 , t + 1 ) : NEW_LINE INDENT items = lines [ ti ] . strip ( ) . split ( \" ▁ \" ) NEW_LINE n = int ( items [ 0 ] ) NEW_LINE o = 1 NEW_LINE b = 1 NEW_LINE o_t = 0 NEW_LINE b_t = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT order_k = items [ i * 2 + 1 ] NEW_LINE order_i = int ( items [ i * 2 + 2 ] ) NEW_LINE if ( order_k == \" O \" ) : NEW_LINE INDENT o_t += myabs ( o - order_i ) NEW_LINE o = order_i NEW_LINE if ( o_t < b_t ) : o_t = b_t NEW_LINE o_t = o_t + 1 NEW_LINE DEDENT else : NEW_LINE INDENT b_t += myabs ( b - order_i ) NEW_LINE b = order_i NEW_LINE if ( b_t < o_t ) : b_t = o_t NEW_LINE b_t = b_t + 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE if ( o_t > b_t ) : ans = o_t NEW_LINE else : ans = b_t NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( ti , ans ) NEW_LINE DEDENT", "num_cases = int ( raw_input ( ) ) NEW_LINE for case_num in xrange ( 1 , num_cases + 1 ) : NEW_LINE INDENT line = raw_input ( ) . split ( ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE colors = [ ] NEW_LINE moves = { ' O ' : [ ] , ' B ' : [ ] } NEW_LINE positions = { ' O ' : 1 , ' B ' : 1 } NEW_LINE count = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT r , p = line [ 2 * i + 1 ] , int ( line [ 2 * i + 2 ] ) NEW_LINE colors . append ( r ) NEW_LINE moves [ r ] . append ( p ) NEW_LINE DEDENT colors = colors [ : : - 1 ] NEW_LINE moves [ ' O ' ] = moves [ ' O ' ] [ : : - 1 ] NEW_LINE moves [ ' B ' ] = moves [ ' B ' ] [ : : - 1 ] NEW_LINE while colors : NEW_LINE INDENT color = colors . pop ( ) NEW_LINE other_color = ' O ' if color == ' B ' else ' B ' NEW_LINE current = positions [ color ] NEW_LINE other_current = positions [ other_color ] NEW_LINE target = moves [ color ] . pop ( ) NEW_LINE if moves [ other_color ] : NEW_LINE INDENT other_target = moves [ other_color ] [ - 1 ] NEW_LINE DEDENT time_to_push = abs ( target - current ) + 1 NEW_LINE count += time_to_push NEW_LINE positions [ color ] = target NEW_LINE delta = other_target - other_current NEW_LINE if abs ( delta ) <= time_to_push : NEW_LINE INDENT positions [ other_color ] = other_target NEW_LINE DEDENT else : NEW_LINE INDENT sign = - 1 if delta < 0 else 1 NEW_LINE positions [ other_color ] += sign * time_to_push NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( case_num , count ) NEW_LINE DEDENT", "import sys NEW_LINE data = [ l . strip ( ) for l in open ( \" infile \" , \" r \" ) . readlines ( ) ] NEW_LINE out = open ( \" outfile \" , \" w \" ) NEW_LINE class robot : NEW_LINE INDENT def __init__ ( self , col , casedata ) : NEW_LINE INDENT self . color = col NEW_LINE self . pos = 1 NEW_LINE self . cindex = - 2 NEW_LINE self . nextgoal = ' START ' NEW_LINE self . findnextgoal ( casedata ) NEW_LINE DEDENT def movetowardgoal ( self ) : NEW_LINE INDENT if self . nextgoal == ' DONE ' : NEW_LINE INDENT pass NEW_LINE DEDENT elif self . pos < self . nextgoal : NEW_LINE INDENT self . pos += 1 NEW_LINE DEDENT elif self . pos > self . nextgoal : NEW_LINE INDENT self . pos -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT pass NEW_LINE DEDENT DEDENT def findnextgoal ( self , casedata ) : NEW_LINE INDENT self . cindex += 2 NEW_LINE while self . cindex < len ( casedata ) and casedata [ self . cindex ] != self . color : NEW_LINE INDENT self . cindex += 2 NEW_LINE DEDENT try : NEW_LINE INDENT self . nextgoal = int ( casedata [ 1 + self . cindex ] ) NEW_LINE DEDENT except : NEW_LINE INDENT self . nextgoal = ' DONE ' NEW_LINE DEDENT DEDENT DEDENT ncases = int ( data . pop ( 0 ) ) NEW_LINE for case in range ( ncases ) : NEW_LINE INDENT casedata = data . pop ( 0 ) . split ( ' ▁ ' ) NEW_LINE numreqs = casedata . pop ( 0 ) NEW_LINE timetaken = 0 NEW_LINE orange = robot ( ' O ' , casedata ) NEW_LINE blue = robot ( ' B ' , casedata ) NEW_LINE while ( orange . nextgoal != ' DONE ' or blue . nextgoal != ' DONE ' ) : NEW_LINE INDENT timetaken += 1 NEW_LINE if orange . cindex < blue . cindex : NEW_LINE INDENT if orange . nextgoal == orange . pos : NEW_LINE INDENT orange . findnextgoal ( casedata ) NEW_LINE DEDENT else : NEW_LINE INDENT orange . movetowardgoal ( ) NEW_LINE DEDENT blue . movetowardgoal ( ) NEW_LINE DEDENT elif blue . cindex < orange . cindex : NEW_LINE INDENT if blue . nextgoal == blue . pos : NEW_LINE INDENT blue . findnextgoal ( casedata ) NEW_LINE DEDENT else : NEW_LINE INDENT blue . movetowardgoal ( ) NEW_LINE DEDENT orange . movetowardgoal ( ) NEW_LINE DEDENT else : NEW_LINE INDENT sys . exit ( ) NEW_LINE DEDENT DEDENT out . write ( \" Case ▁ # \" + str ( case + 1 ) + \" : ▁ \" + str ( timetaken ) + \" \\n \" ) NEW_LINE DEDENT", "other = { \" B \" : \" O \" , \" O \" : \" B \" } NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( \" input . txt \" ) NEW_LINE testlen = int ( f . readline ( ) . strip ( ) ) NEW_LINE tests = [ ] NEW_LINE for line in f : NEW_LINE INDENT tests . append ( line . strip ( ) ) NEW_LINE DEDENT tests = tests [ : testlen ] NEW_LINE for test , i in zip ( tests , range ( testlen ) ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , solve ( parse ( test ) ) ) NEW_LINE DEDENT DEDENT def parse ( test ) : NEW_LINE INDENT test = test . split ( \" ▁ \" ) NEW_LINE return zip ( test [ 1 : : 2 ] , map ( int , test [ 2 : : 2 ] ) ) NEW_LINE DEDENT def solve ( test ) : NEW_LINE INDENT time = { \" B \" : 0 , \" O \" : 0 } NEW_LINE pos = { \" B \" : 0 , \" O \" : 0 } NEW_LINE total = 0 NEW_LINE for nc , np in test : NEW_LINE INDENT d = max ( abs ( pos [ nc ] - np ) - time [ nc ] , 0 ) + 1 NEW_LINE time [ nc ] = 0 NEW_LINE total += d NEW_LINE time [ other [ nc ] ] += d NEW_LINE pos [ nc ] = np NEW_LINE DEDENT return total - 1 NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "def run_command ( commands ) : NEW_LINE INDENT bPos = oPos = 1 NEW_LINE bTime = oTime = 0 NEW_LINE time = 0 NEW_LINE for c in commands : NEW_LINE INDENT if c [ 0 ] == ' O ' : NEW_LINE INDENT minTime = abs ( oPos - c [ 1 ] ) - time + oTime NEW_LINE time += max ( minTime , 0 ) + 1 NEW_LINE oTime = time NEW_LINE oPos = c [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT minTime = abs ( bPos - c [ 1 ] ) - time + bTime NEW_LINE time += max ( minTime , 0 ) + 1 NEW_LINE bTime = time NEW_LINE bPos = c [ 1 ] NEW_LINE DEDENT DEDENT return time NEW_LINE DEDENT def read_input ( ) : NEW_LINE INDENT line = raw_input ( ) . split ( ) [ 1 : ] NEW_LINE commands = [ ( line [ 2 * i ] , int ( line [ 2 * i + 1 ] ) ) for i in range ( len ( line ) // 2 ) ] NEW_LINE return run_command ( commands ) NEW_LINE DEDENT numCases = input ( ) NEW_LINE for i in range ( 1 , numCases + 1 ) : NEW_LINE INDENT output = read_input ( ) NEW_LINE print \" Case ▁ # % d : \" % i , output NEW_LINE DEDENT" ]
codejam_15_13
[ "import java . util . * ; import java . io . * ; public class C { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" C - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( new File ( \" C - large . out \" ) ) ) ; int t = in . nextInt ( ) ; for ( int x = 0 ; x < t ; x ++ ) { int n = in . nextInt ( ) ; int [ ] xs = new int [ n ] ; int [ ] ys = new int [ n ] ; for ( int y = 0 ; y < n ; y ++ ) { xs [ y ] = in . nextInt ( ) ; ys [ y ] = in . nextInt ( ) ; } out . println ( \" Case ▁ # \" + ( x + 1 ) + \" : \" ) ; for ( int z = 0 ; z < xs . length ; z ++ ) { ArrayList < Double > angles = new ArrayList < Double > ( ) ; for ( int a = 0 ; a < xs . length ; a ++ ) { if ( a != z ) { double current = Math . atan2 ( ys [ a ] - ys [ z ] , xs [ a ] - xs [ z ] ) ; angles . add ( current ) ; angles . add ( current + 2.0 * Math . PI ) ; } } Collections . sort ( angles ) ; int index = 0 ; int result = n ; for ( int b = 0 ; b < n ; b ++ ) { while ( index < angles . size ( ) && angles . get ( index ) < angles . get ( b ) + Math . PI + 1E-12 ) { index ++ ; } result = Math . min ( result , n - ( index - b ) - 1 ) ; } if ( n == 1 ) { out . println ( 0 ) ; } else { out . println ( result ) ; } } } out . close ( ) ; } }" ]
[ "import heapq NEW_LINE def ReadIn ( ) : NEW_LINE INDENT t = int ( input ( ) ) NEW_LINE for c in range ( 1 , t + 1 ) : NEW_LINE INDENT m , n = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE a = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE yield c , n , a NEW_LINE DEDENT DEDENT def OK ( n , a , guess ) : NEW_LINE INDENT return sum ( [ guess // x + 1 for x in a ] ) >= n NEW_LINE DEDENT def Solve ( n , a ) : NEW_LINE INDENT if n <= len ( a ) : return n NEW_LINE lower = 0 NEW_LINE upper = max ( a ) * n NEW_LINE while lower < upper : NEW_LINE INDENT guess = ( lower + upper + 1 ) // 2 NEW_LINE if OK ( n , a , guess ) : upper = guess - 1 NEW_LINE else : lower = guess NEW_LINE DEDENT guess = lower NEW_LINE heap = [ ] NEW_LINE remain = n NEW_LINE for i , x in enumerate ( a ) : NEW_LINE INDENT num = guess // x + 1 NEW_LINE remain -= num NEW_LINE heapq . heappush ( heap , ( num * x - guess , i ) ) NEW_LINE DEDENT ret = heap [ 0 ] [ 1 ] NEW_LINE for r in range ( remain ) : NEW_LINE INDENT t , i = heapq . heappop ( heap ) NEW_LINE heapq . heappush ( heap , ( t + a [ i ] , i ) ) NEW_LINE ret = i NEW_LINE DEDENT return ret + 1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT for c , n , a in ReadIn ( ) : NEW_LINE INDENT print ( ' Case ▁ # % d : ▁ % d ' % ( c , Solve ( n , a ) ) ) NEW_LINE DEDENT DEDENT", "import math NEW_LINE cases = int ( raw_input ( ) ) NEW_LINE for c in xrange ( cases ) : NEW_LINE INDENT tree_count = int ( raw_input ( ) ) NEW_LINE dims = [ ] NEW_LINE for t in xrange ( tree_count ) : NEW_LINE INDENT dims . append ( map ( int , raw_input ( ) . split ( ) ) ) NEW_LINE DEDENT print \" Case ▁ # { } : \" . format ( c + 1 ) NEW_LINE for i , p in enumerate ( dims ) : NEW_LINE INDENT rest = [ d for d in dims if d [ 0 ] != p [ 0 ] or d [ 1 ] != p [ 1 ] ] NEW_LINE angles = [ math . atan2 ( r [ 1 ] - p [ 1 ] , r [ 0 ] - p [ 0 ] ) for r in rest ] NEW_LINE angles = angles + [ a + 2 * math . pi for a in angles ] + [ a + 4 * math . pi for a in angles ] NEW_LINE angles . sort ( ) NEW_LINE end = 0 NEW_LINE min_remove = 999999999 NEW_LINE for start in xrange ( len ( angles ) / 2 ) : NEW_LINE INDENT while angles [ end ] < ( angles [ start ] + math . pi - 1e-12 ) : NEW_LINE INDENT end += 1 NEW_LINE DEDENT min_remove = min ( min_remove , end - start - 1 ) NEW_LINE DEDENT if min_remove == 999999999 : NEW_LINE INDENT min_remove = 0 NEW_LINE DEDENT print min_remove NEW_LINE DEDENT DEDENT", "from __future__ import division NEW_LINE import bisect NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for test in xrange ( T ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE trees = [ ] NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT x , y = map ( int , raw_input ( ) . split ( ) ) NEW_LINE trees . append ( ( x , y ) ) NEW_LINE DEDENT print \" Case ▁ # { } : \" . format ( test + 1 ) NEW_LINE for x0 , y0 in trees : NEW_LINE INDENT left = [ ] NEW_LINE right = [ ] NEW_LINE up = 0 NEW_LINE down = 0 NEW_LINE for x1 , y1 in trees : NEW_LINE INDENT x = x1 - x0 NEW_LINE y = y1 - y0 NEW_LINE if x > 0 : NEW_LINE INDENT right . append ( y / x ) NEW_LINE DEDENT elif x < 0 : NEW_LINE INDENT left . append ( y / x ) NEW_LINE DEDENT elif y > 0 : NEW_LINE INDENT up += 1 NEW_LINE DEDENT elif y < 0 : NEW_LINE INDENT down += 1 NEW_LINE DEDENT DEDENT left . sort ( ) NEW_LINE right . sort ( ) NEW_LINE ans = min ( len ( left ) , len ( right ) ) NEW_LINE for i , angle in enumerate ( left ) : NEW_LINE INDENT cut_after = down + len ( left ) - 1 - i + bisect . bisect_left ( right , angle ) NEW_LINE cut_before = up + i + len ( right ) - bisect . bisect_right ( right , angle ) NEW_LINE cut = min ( cut_after , cut_before ) NEW_LINE ans = min ( ans , cut ) NEW_LINE DEDENT print ans NEW_LINE DEDENT DEDENT", "from math import atan , pi NEW_LINE if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT testcases = input ( ) NEW_LINE for case in xrange ( 1 , testcases + 1 ) : NEW_LINE INDENT num_trees = int ( raw_input ( ) ) NEW_LINE trees = [ [ int ( n ) for n in raw_input ( ) . split ( ) ] for _ in range ( num_trees ) ] NEW_LINE print ( \" Case ▁ # % i : \" % ( case ) ) NEW_LINE for i in range ( num_trees ) : NEW_LINE INDENT r_angles , l_angles = [ ] , [ ] NEW_LINE for j in range ( num_trees ) : NEW_LINE INDENT if j == i : NEW_LINE INDENT continue NEW_LINE DEDENT d_x , d_y = trees [ j ] [ 0 ] - trees [ i ] [ 0 ] , trees [ j ] [ 1 ] - trees [ i ] [ 1 ] NEW_LINE if d_x > 0 : NEW_LINE INDENT r_angles . append ( atan ( float ( d_y ) / float ( d_x ) ) ) NEW_LINE DEDENT elif d_x < 0 : NEW_LINE INDENT l_angles . append ( atan ( float ( d_y ) / float ( d_x ) ) ) NEW_LINE DEDENT elif d_y < 0 : NEW_LINE INDENT l_angles . append ( pi ) NEW_LINE DEDENT else : NEW_LINE INDENT r_angles . append ( pi ) NEW_LINE DEDENT DEDENT r_angles = sorted ( r_angles ) NEW_LINE l_angles = sorted ( l_angles ) NEW_LINE n_r , n_l = len ( r_angles ) , len ( l_angles ) NEW_LINE min_r , min_l = n_r , n_l NEW_LINE while len ( r_angles ) > 0 or len ( l_angles ) > 0 : NEW_LINE INDENT if len ( r_angles ) > 0 and len ( l_angles ) > 0 : NEW_LINE INDENT next_val = min ( r_angles [ 0 ] , l_angles [ 0 ] ) NEW_LINE DEDENT elif len ( r_angles ) > 0 : NEW_LINE INDENT next_val = r_angles [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT next_val = l_angles [ 0 ] NEW_LINE DEDENT from_r , from_l = 0 , 0 NEW_LINE while r_angles and r_angles [ 0 ] == next_val : NEW_LINE INDENT r_angles . pop ( 0 ) NEW_LINE from_r += 1 NEW_LINE DEDENT while l_angles and l_angles [ 0 ] == next_val : NEW_LINE INDENT l_angles . pop ( 0 ) NEW_LINE from_l += 1 NEW_LINE DEDENT n_r -= from_r NEW_LINE n_l -= from_l NEW_LINE min_r = min ( min_r , n_r ) NEW_LINE min_l = min ( min_l , n_l ) NEW_LINE n_r += from_l NEW_LINE n_l += from_r NEW_LINE DEDENT print min ( min_r , min_l ) NEW_LINE DEDENT DEDENT DEDENT", "import imp , sys NEW_LINE sys . modules [ \" utils \" ] = __mod = imp . new_module ( \" utils \" ) NEW_LINE exec \"\"\" # ! / usr / bin / python STRNEWLINE STRNEWLINE from ▁ itertools ▁ import ▁ chain , ▁ repeat , ▁ izip STRNEWLINE STRNEWLINE def ▁ line ( * args ) : STRNEWLINE TABSYMBOL L ▁ = ▁ raw _ input ( ) . strip ( ) . split ( ) STRNEWLINE TABSYMBOL L ▁ = ▁ izip ( ▁ L , ▁ chain ( ▁ args , ▁ repeat ( str ) ▁ ) ▁ ) STRNEWLINE TABSYMBOL return ▁ [ ▁ type ( data ) ▁ for ▁ data , ▁ type ▁ in ▁ L ▁ ] TABSYMBOL STRNEWLINE TABSYMBOL STRNEWLINE def ▁ iline ( ) : ▁ return ▁ map ( ▁ int , ▁ raw _ input ( ) . strip ( ) . split ( ) ▁ ) STRNEWLINE def ▁ fline ( ) : ▁ return ▁ map ( ▁ float , ▁ raw _ input ( ) . strip ( ) . split ( ) ▁ ) \"\"\" in vars ( __mod ) NEW_LINE from utils import iline NEW_LINE from math import atan2 , pi NEW_LINE import sys NEW_LINE def test ( ) : NEW_LINE INDENT N , = iline ( ) NEW_LINE P = [ iline ( ) for i in xrange ( N ) ] NEW_LINE def solve ( ) : NEW_LINE INDENT print NEW_LINE for px , py in P : NEW_LINE INDENT Q = [ ( atan2 ( qy - py , qx - px ) , ( qx - px , qy - py ) ) for qx , qy in P if px != qx or py != qy ] NEW_LINE N = len ( Q ) NEW_LINE Q . sort ( ) NEW_LINE Q . extend ( [ ( q + 2 * pi , pos ) for q , pos in Q ] ) NEW_LINE a = 0 NEW_LINE ans = N NEW_LINE for b in xrange ( N , len ( Q ) ) : NEW_LINE INDENT a = max ( a , b - N ) NEW_LINE while a < b and Q [ b ] [ 1 ] [ 0 ] * Q [ a ] [ 1 ] [ 1 ] - Q [ b ] [ 1 ] [ 1 ] * Q [ a ] [ 1 ] [ 0 ] >= 0 : NEW_LINE INDENT a += 1 NEW_LINE DEDENT ans = min ( ans , b - a ) NEW_LINE DEDENT print ans NEW_LINE DEDENT DEDENT return solve NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT T = input ( ) NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % i , NEW_LINE test ( ) ( ) NEW_LINE DEDENT DEDENT" ]
codejam_17_31
[ "import java . math . BigDecimal ; import java . util . Arrays ; import java . util . Scanner ; public class ProblemA { public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { int cases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= cases ; caseNum ++ ) { solve ( sc , caseNum ) ; } } } static void solve ( Scanner sc , int caseNum ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; P [ ] ps = new P [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { ps [ i ] = new P ( sc . nextInt ( ) , sc . nextInt ( ) ) ; } Arrays . sort ( ps ) ; double max = - 1 ; for ( int i = 0 ; i < N - K + 1 ; i ++ ) { P [ ] ps2 = Arrays . copyOfRange ( ps , i + 1 , N ) ; Arrays . sort ( ps2 , ( p1 , p2 ) -> ( Long . compare ( p2 . H * p2 . R , p1 . H * p1 . R ) ) ) ; double area = Math . PI * ps [ i ] . R * ps [ i ] . R ; area += Math . PI * ps [ i ] . H * ps [ i ] . R * 2 ; for ( int j = 0 ; j < K - 1 ; j ++ ) { area += Math . PI * ps2 [ j ] . H * ps2 [ j ] . R * 2 ; } max = Math . max ( area , max ) ; } System . out . printf ( \" Case ▁ # % d : ▁ % .8f \\n \" , caseNum , max ) ; } static class P implements Comparable < P > { long R , H ; public P ( long r , long h ) { super ( ) ; R = r ; H = h ; } @ Override public int compareTo ( P arg0 ) { return Long . compare ( arg0 . R , R ) ; } } }", "package round1c ; import java . util . ArrayList ; import java . util . List ; public class ProbA extends Prob { void setup ( ) { bin = true ; bout = true ; in = \" A - large . in \" ; out = \" aout - large . txt \" ; } @ Override public void main ( ) { setup ( ) ; reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { double ans = run ( ) ; System . out . println ( String . format ( \" Case ▁ # % d : ▁ % .9f \" , cas , ans ) ) ; } } double run ( ) { int n = scanner . nextInt ( ) ; int k = scanner . nextInt ( ) ; int [ ] [ ] pancake = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { pancake [ i ] [ 0 ] = scanner . nextInt ( ) ; pancake [ i ] [ 1 ] = scanner . nextInt ( ) ; } double ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double curr = calcSide ( pancake [ i ] ) + calcArea ( pancake [ i ] [ 0 ] ) ; List < Double > arr = new ArrayList < > ( ) ; for ( int j = 0 ; j < n ; j ++ ) if ( j != i ) { if ( pancake [ j ] [ 0 ] <= pancake [ i ] [ 0 ] ) { arr . add ( calcSide ( pancake [ j ] ) ) ; } } if ( arr . size ( ) < k - 1 ) { continue ; } arr . sort ( ( a , b ) -> - Double . compare ( a , b ) ) ; for ( int j = 0 ; j < k - 1 ; j ++ ) { curr += arr . get ( j ) ; } if ( curr > ans ) { ans = curr ; } } return ans ; } private double calcSide ( int [ ] pancake ) { double r = ( double ) pancake [ 0 ] ; double h = ( double ) pancake [ 1 ] ; return 2.0 * r * h * Math . PI ; } private double calcArea ( int r ) { return Math . PI * ( double ) r * ( double ) r ; } }", "import java . io . File ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Scanner ; public class A { static Pancake [ ] p ; static Double [ ] [ ] memo ; public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( new File ( \" A . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" A . out \" ) ) ; int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; memo = new Double [ N + 1 ] [ K + 1 ] ; p = new Pancake [ N ] ; for ( int a = 0 ; a < N ; a ++ ) { p [ a ] = new Pancake ( sc . nextInt ( ) , sc . nextInt ( ) ) ; } Arrays . sort ( p ) ; double ans = DP ( N - 1 , K ) ; System . out . printf ( \" Case ▁ # % d : ▁ % .12f % n \" , t , ans ) ; out . printf ( \" Case ▁ # % d : ▁ % .12f % n \" , t , ans ) ; } out . close ( ) ; } private static double DP ( int i , int k ) { if ( i < 0 || k <= 0 ) return 0 ; if ( memo [ i ] [ k ] != null ) return memo [ i ] [ k ] ; double ans = DP ( i - 1 , k - 1 ) ; if ( k == 1 ) { ans += Math . PI * p [ i ] . R * p [ i ] . R ; } ans += 2.0 * Math . PI * p [ i ] . R * p [ i ] . H ; ans = Math . max ( ans , DP ( i - 1 , k ) ) ; return memo [ i ] [ k ] = ans ; } static class Pancake implements Comparable < Pancake > { int R , H ; Pancake ( int a , int b ) { R = a ; H = b ; } @ Override public int compareTo ( Pancake that ) { return ( that . R - this . R ) ; } } }" ]
[ "import math NEW_LINE class pannukakku : NEW_LINE INDENT radius = 0 NEW_LINE height = 0 NEW_LINE size_h = 0 NEW_LINE size_r = 0 NEW_LINE def size ( self , current_r ) : NEW_LINE INDENT if ( self . radius > current_r ) : NEW_LINE INDENT return self . size_h + self . size_r - math . pi * current_r * current_r ; NEW_LINE DEDENT return self . size_h ; NEW_LINE DEDENT DEDENT def poista_isoin ( kakut , current_r ) : NEW_LINE INDENT isoin_index = 0 ; NEW_LINE isoin_size = kakut [ 0 ] . size ( current_r ) ; NEW_LINE for p in range ( 1 , len ( kakut ) ) : NEW_LINE INDENT if ( kakut [ p ] . size ( current_r ) > isoin_size ) : NEW_LINE INDENT isoin_index = p ; NEW_LINE isoin_size = kakut [ p ] . size ( current_r ) ; NEW_LINE DEDENT DEDENT return kakut . pop ( isoin_index ) ; NEW_LINE DEDENT t = int ( input ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT pannukakkuja , tilauksen_koko = [ int ( s ) for s in input ( ) . split ( \" ▁ \" ) ] ; NEW_LINE radiuses = [ 0 for h in range ( pannukakkuja ) ] NEW_LINE heigths = [ 0 for h in range ( pannukakkuja ) ] NEW_LINE sizes = [ 0 for h in range ( pannukakkuja ) ] NEW_LINE kakut = [ pannukakku ( ) for h in range ( pannukakkuja ) ] NEW_LINE for h in range ( 0 , pannukakkuja ) : NEW_LINE INDENT r , s = [ int ( s ) for s in input ( ) . split ( \" ▁ \" ) ] ; NEW_LINE kakut [ h ] . radius = r ; NEW_LINE kakut [ h ] . heigth = s ; NEW_LINE kakut [ h ] . size_h = math . pi * 2 * r * s ; NEW_LINE kakut [ h ] . size_r = math . pi * r * r ; NEW_LINE DEDENT total = 0 ; NEW_LINE current_r = 0 ; NEW_LINE for p in range ( tilauksen_koko ) : NEW_LINE INDENT isoin = poista_isoin ( kakut , current_r ) ; NEW_LINE total += isoin . size ( current_r ) ; NEW_LINE current_r = max ( current_r , isoin . radius ) ; NEW_LINE DEDENT print ( \" Case ▁ # { 0 : . 0f } : ▁ { 1 : . 6f } \" . format ( i , total ) ) ; NEW_LINE DEDENT", "import argparse NEW_LINE import math NEW_LINE def max_sides ( pancakes , k ) : NEW_LINE INDENT p2 = pancakes NEW_LINE base = p2 [ 0 ] NEW_LINE p2 = p2 [ 1 : ] NEW_LINE sorted_p2 = sorted ( p2 , key = lambda p : p [ 1 ] , reverse = True ) NEW_LINE ps = sorted_p2 [ : k - 1 ] + [ base ] NEW_LINE sum = 0 NEW_LINE for p in ps : NEW_LINE INDENT sum += p [ 1 ] NEW_LINE DEDENT return sum NEW_LINE DEDENT def main ( f_in , f_out ) : NEW_LINE INDENT num_cases = int ( f_in . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , num_cases + 1 ) : NEW_LINE INDENT n , k = f_in . readline ( ) . strip ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE k = int ( k ) NEW_LINE pancakes = [ ] NEW_LINE for pancake in range ( n ) : NEW_LINE INDENT r , h = f_in . readline ( ) . strip ( ) . split ( ) NEW_LINE r = int ( r ) NEW_LINE h = int ( h ) NEW_LINE pancakes += [ ( r , 2 * math . pi * r * h ) ] NEW_LINE DEDENT sorted_pancakes = sorted ( pancakes , key = lambda p : p [ 0 ] , reverse = True ) NEW_LINE best_total = 0 NEW_LINE for start_pancake in range ( 0 , n - k + 1 ) : NEW_LINE INDENT s = max_sides ( sorted_pancakes [ start_pancake : ] , k ) NEW_LINE r = sorted_pancakes [ start_pancake ] [ 0 ] NEW_LINE top = math . pi * r * r NEW_LINE best_total = max ( best_total , s + top ) NEW_LINE DEDENT f_out . write ( ' Case ▁ # { } : ▁ { : . 8f } \\n ' . format ( case , best_total ) ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT parser = argparse . ArgumentParser ( ) NEW_LINE parser . add_argument ( ' infile ' ) NEW_LINE opts = parser . parse_args ( ) NEW_LINE infile = opts . infile NEW_LINE outfile = infile . split ( ' . ' ) [ 0 ] + ' . out ' NEW_LINE print \" Solving ! ▁ in : ▁ { } ▁ - > ▁ out : ▁ { } \" . format ( infile , outfile ) NEW_LINE with open ( infile , ' r ' ) as f_in : NEW_LINE INDENT with open ( outfile , ' w ' ) as f_out : NEW_LINE INDENT main ( f_in , f_out ) NEW_LINE DEDENT DEDENT DEDENT", "import functools NEW_LINE import math NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 5000 ) NEW_LINE def f ( pancakes , k ) : NEW_LINE INDENT @ functools . lru_cache ( maxsize = None ) NEW_LINE def recurse ( index , left ) : NEW_LINE INDENT if left == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if index == len ( pancakes ) : NEW_LINE INDENT return - ( 10 ** 50 ) NEW_LINE DEDENT case1 = recurse ( index + 1 , left ) NEW_LINE case2 = 2 * pancakes [ index ] [ 0 ] * pancakes [ index ] [ 1 ] + recurse ( index + 1 , left - 1 ) NEW_LINE if left == k : NEW_LINE INDENT case2 += pancakes [ index ] [ 0 ] ** 2 NEW_LINE DEDENT return max ( ( case1 , case2 ) ) NEW_LINE DEDENT return math . pi * recurse ( 0 , k ) NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE pancakes = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT pancakes . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE DEDENT pancakes = list ( reversed ( sorted ( pancakes ) ) ) NEW_LINE ans = f ( pancakes , k ) NEW_LINE print ( \" Case ▁ # % s : ▁ % s \" % ( case , ans ) ) NEW_LINE DEDENT", "import math NEW_LINE fin = open ( \"1 . in \" , \" r \" ) NEW_LINE fout = open ( \"1 . out \" , \" w \" ) NEW_LINE T = int ( fin . readline ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT print str ( t + 1 ) NEW_LINE N , K = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE P = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT r , h = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE P . append ( ( r , h , 2 * h * r ) ) NEW_LINE DEDENT P . sort ( ) NEW_LINE print P NEW_LINE ans = 0 NEW_LINE for j in range ( N - 1 , K - 2 , - 1 ) : NEW_LINE INDENT max_radius = P [ j ] [ 0 ] NEW_LINE area = P [ j ] [ 2 ] + max_radius * max_radius NEW_LINE del P [ j ] NEW_LINE filtered = [ hr for ( r , h , hr ) in P if r <= max_radius ] NEW_LINE filtered . sort ( ) NEW_LINE print filtered NEW_LINE for i in range ( 1 , K ) : NEW_LINE INDENT area += filtered [ - i ] NEW_LINE DEDENT ans = max ( ans , area ) NEW_LINE DEDENT ans *= math . pi NEW_LINE ans = ' { 0 : . 6f } ' . format ( ans ) NEW_LINE fout . write ( \" Case ▁ # \" + str ( t + 1 ) + \" : ▁ \" + ans + \" \\n \" ) NEW_LINE DEDENT", "import sys NEW_LINE import math NEW_LINE def problem ( pancakes , order_size ) : NEW_LINE INDENT pancakes . sort ( key = lambda x : 2 * math . pi * x [ 0 ] * x [ 1 ] , reverse = True ) NEW_LINE take = pancakes [ : order_size - 1 ] NEW_LINE if len ( take ) != 0 : NEW_LINE INDENT max_radius = max ( x [ 0 ] for x in take ) NEW_LINE DEDENT else : NEW_LINE INDENT max_radius = 0 NEW_LINE DEDENT outsides = sum ( 2 * math . pi * x [ 0 ] * x [ 1 ] for x in take ) NEW_LINE best = 0 NEW_LINE for n in pancakes [ order_size - 1 : ] : NEW_LINE INDENT radius = max ( max_radius , n [ 0 ] ) NEW_LINE size = outsides + 2 * math . pi * n [ 0 ] * n [ 1 ] + math . pi * radius * radius NEW_LINE best = max ( best , size ) NEW_LINE DEDENT return best NEW_LINE DEDENT def nextline ( input_file ) : NEW_LINE INDENT data = \" \" NEW_LINE while not data : NEW_LINE INDENT data = input_file . readline ( ) NEW_LINE DEDENT return data [ : - 1 ] NEW_LINE DEDENT def intsplit ( s ) : NEW_LINE INDENT return [ int ( x ) for x in s . split ( \" ▁ \" ) ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT result = \" \" NEW_LINE with sys . stdin if len ( sys . argv ) == 1 else open ( sys . argv [ 1 ] , ' r ' ) as infile : NEW_LINE INDENT number = int ( nextline ( infile ) ) NEW_LINE for run in range ( number ) : NEW_LINE INDENT case = nextline ( infile ) NEW_LINE size , order_size = intsplit ( case ) NEW_LINE pancakes = [ ] NEW_LINE for _ in range ( size ) : NEW_LINE INDENT pancakes . append ( intsplit ( nextline ( infile ) ) ) NEW_LINE DEDENT result += ' Case ▁ # { } : ▁ { } \\n ' . format ( 1 + run , problem ( pancakes , order_size ) ) NEW_LINE DEDENT DEDENT if len ( sys . argv ) == 1 : NEW_LINE INDENT print ( result , end = ' ' ) NEW_LINE DEDENT else : NEW_LINE INDENT with open ( sys . argv [ 1 ] . replace ( ' in ' , ' sol ' ) , ' w ' ) as result_file : NEW_LINE INDENT result_file . write ( result ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_08_92
[ "import java . util . * ; import java . math . * ; public class PingPongEasy { static final Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int cases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= cases ; caseNum ++ ) { System . out . print ( \" Case ▁ # \" + caseNum + \" : ▁ \" ) ; int X = sc . nextInt ( ) , Y = sc . nextInt ( ) ; boolean [ ] [ ] vis = new boolean [ X ] [ Y ] ; int [ ] [ ] dis = new int [ 2 ] [ 2 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { dis [ i ] [ 0 ] = sc . nextInt ( ) ; dis [ i ] [ 1 ] = sc . nextInt ( ) ; } int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; System . out . println ( recurse ( x , y , vis , dis ) ) ; } } private static int recurse ( int x , int y , boolean [ ] [ ] vis , int [ ] [ ] dis ) { if ( x < 0 || x >= vis . length || y < 0 || y >= vis [ x ] . length || vis [ x ] [ y ] ) return 0 ; vis [ x ] [ y ] = true ; int res = 1 ; for ( int i = 0 ; i < 2 ; i ++ ) res += recurse ( x + dis [ i ] [ 0 ] , y + dis [ i ] [ 1 ] , vis , dis ) ; return res ; } }" ]
[ "import sys NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return map ( foo , raw_input ( ) . split ( ) ) NEW_LINE res = 0 NEW_LINE used = { } NEW_LINE q = [ ] NEW_LINE qh , qt = ( 0 , 0 ) NEW_LINE dx1 , dy1 , dx2 , dy2 = ( 0 , 0 , 0 , 0 ) NEW_LINE w , h = ( 0 , 0 ) NEW_LINE def doit ( x , y ) : NEW_LINE INDENT global res NEW_LINE if x < 0 or x >= w : return NEW_LINE if y < 0 or y >= h : return NEW_LINE if ( x , y ) in used : return NEW_LINE res += 1 NEW_LINE used [ ( x , y ) ] = True NEW_LINE global q , qh , qt NEW_LINE q . append ( ( x + dx1 , y + dy1 ) ) NEW_LINE q . append ( ( x + dx2 , y + dy2 ) ) NEW_LINE qt += 2 NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( \" Test ▁ % d \\n \" % ( test + 1 ) ) NEW_LINE ( w , h ) = readarray ( int ) NEW_LINE ( dx1 , dy1 ) = readarray ( int ) NEW_LINE ( dx2 , dy2 ) = readarray ( int ) NEW_LINE ( x0 , y0 ) = readarray ( int ) NEW_LINE res = 0 NEW_LINE used = { } NEW_LINE q = [ ( x0 , y0 ) ] NEW_LINE qh = 0 NEW_LINE qt = 1 NEW_LINE while qh < qt : NEW_LINE INDENT ( x , y ) = q [ qh ] NEW_LINE doit ( x , y ) NEW_LINE qh += 1 NEW_LINE DEDENT print \" Case ▁ # % d : ▁ % d \" % ( test + 1 , res ) NEW_LINE DEDENT" ]
codejam_13_54
[ "import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . SortedSet ; import java . util . TreeSet ; public class ObservationWheel { static Scanner sc ; static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { sc = new Scanner ( new FileReader ( \" D - small - attempt0 . in \" ) ) ; out = new PrintWriter ( new FileWriter ( \" D - small - attempt0 . out \" ) ) ; int testCases = sc . nextInt ( ) ; for ( int testCase = 1 ; testCase <= testCases ; testCase ++ ) { out . println ( String . format ( \" Case ▁ # % s : ▁ % s \" , testCase , solveCase ( ) ) ) ; } out . close ( ) ; } static double solveCase ( ) { String bits = sc . next ( ) ; N = bits . length ( ) ; memo = new double [ 1 << N ] ; Arrays . fill ( memo , - 1.0 ) ; int init = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( bits . charAt ( i ) == ' X ' ) init |= 1 << i ; return solve ( init ) ; } static double solve ( int mask ) { if ( mask == ( 1 << N ) - 1 ) { return 0 ; } if ( memo [ mask ] < - 0.5 ) { double res = 0.0 ; for ( int index = 0 ; index < N ; index ++ ) { for ( int wait = 0 ; wait < N ; wait ++ ) { int exactIndex = ( index + wait ) % N ; if ( ( mask >> exactIndex & 1 ) == 0 ) { res += ( N - wait + solve ( mask | 1 << exactIndex ) ) / N ; break ; } } } memo [ mask ] = res ; } return memo [ mask ] ; } static double [ ] memo ; static int N ; }", "import java . util . * ; public class D { static boolean bit_set ( int set , int bit ) { return ( ( set >>> bit ) & 1 ) == 1 ; } static Double [ ] [ ] DP = new Double [ 21 ] [ 1 << 20 ] ; static double f ( int n , int used ) { if ( used == ( 1 << n ) - 1 ) return 0 ; if ( DP [ n ] [ used ] != null ) return DP [ n ] [ used ] ; double ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int nxt = i ; int money = n ; while ( bit_set ( used , nxt ) ) { nxt = ( nxt + 1 ) % n ; money -- ; } ans += 1.0 / n * ( money + f ( n , used | 1 << nxt ) ) ; } return DP [ n ] [ used ] = ans ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { char [ ] S = in . next ( ) . toCharArray ( ) ; int used = 0 ; for ( int i = 0 ; i < S . length ; i ++ ) if ( S [ i ] == ' X ' ) used |= 1 << i ; System . out . printf ( \" Case ▁ # % d : ▁ % .10f \\n \" , cas , f ( S . length , used ) ) ; } } }", "import java . io . * ; import java . util . * ; public class D { private static String fileName = D . class . getSimpleName ( ) . replaceFirst ( \" _ . * \" , \" \" ) . toLowerCase ( ) ; private static String inputFileName = fileName + \" . in \" ; private static String outputFileName = fileName + \" . out \" ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { String s = in . next ( ) ; int n = s . length ( ) ; int init = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' . ' ) { init |= 1 << i ; } } double [ ] a = new double [ 1 << n ] ; for ( int mask = 1 ; mask <= init ; mask ++ ) { for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; int k = i ; for ( ; ; ) { if ( ( ( mask >> k ) & 1 ) == 1 ) { break ; } j ++ ; k ++ ; if ( k == n ) { k = 0 ; } } int nm = mask ^ ( 1 << k ) ; a [ mask ] += ( n - j + a [ nm ] ) / n ; } } out . println ( a [ init ] ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; if ( args . length >= 2 ) { inputFileName = args [ 0 ] ; outputFileName = args [ 1 ] ; } in = new Scanner ( new File ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; new D ( ) . solve ( ) ; System . out . println ( \" Case ▁ # \" + t + \" : ▁ solved \" ) ; } in . close ( ) ; out . close ( ) ; } }", "import static java . lang . Math . * ; import static java . util . Arrays . * ; import java . io . * ; import java . util . * ; public class D { Scanner sc = new Scanner ( System . in ) ; int N ; char [ ] oc ; void read ( ) { oc = sc . next ( ) . toCharArray ( ) ; N = oc . length ; } void solve ( ) { double [ ] dp = new double [ 1 << N ] ; for ( int i = ( 1 << N ) - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) if ( ( i >> ( ( j + k ) % N ) & 1 ) == 0 ) { dp [ i ] += ( dp [ i | 1 << ( ( j + k ) % N ) ] + N - k ) / N ; break ; } } } int r = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( oc [ i ] == ' X ' ) r |= 1 << i ; System . out . printf ( \" % .10f % n \" , dp [ r ] ) ; } void run ( ) { int caseN = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseN ; caseID ++ ) { read ( ) ; System . out . printf ( \" Case ▁ # % d : ▁ \" , caseID ) ; solve ( ) ; System . out . flush ( ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { try { System . setIn ( new BufferedInputStream ( new FileInputStream ( args . length > 0 ? args [ 0 ] : ( D . class . getName ( ) + \" . in \" ) ) ) ) ; } catch ( Exception e ) { } new D ( ) . run ( ) ; } }", "import java . util . * ; import static java . lang . Math . * ; import java . io . * ; public class D { public static void p ( Object ... args ) { System . out . println ( Arrays . deepToString ( args ) ) ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { String start = in . next ( ) ; N = start . length ( ) ; int st = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( start . charAt ( i ) == ' X ' ) st |= 1 << i ; } DP = new double [ 1 << N ] ; Arrays . fill ( DP , - 1 ) ; DP [ ( 1 << N ) - 1 ] = 0 ; System . out . format ( \" Case ▁ # % d : ▁ % .12f \\n \" , zz , compute ( st ) ) ; } } static int N ; static double [ ] DP ; static double compute ( int at ) { if ( DP [ at ] != - 1 ) return DP [ at ] ; double ans = 0.0 ; for ( int i = 0 ; i < N ; i ++ ) { int cost = N ; int j = i ; while ( get ( at , j ) ) { j ++ ; cost -- ; if ( j == N ) j = 0 ; } ans += cost + compute ( at | ( 1 << j ) ) ; } ans /= N ; DP [ at ] = ans ; return ans ; } static boolean get ( int num , int bit ) { return ( num & ( 1 << bit ) ) != 0 ; } }" ]
[ "from sys import stdin NEW_LINE memo = [ [ - 1 ] * ( 1 << n ) for n in xrange ( 21 ) ] NEW_LINE for n in xrange ( 21 ) : NEW_LINE INDENT memo [ n ] [ 0 ] = 0.0 NEW_LINE for ss in xrange ( 1 , 1 << n ) : NEW_LINE INDENT if memo [ n ] [ ss ] != - 1 : NEW_LINE INDENT continue NEW_LINE DEDENT s = bin ( ss ) [ 2 : ] . zfill ( n ) NEW_LINE m = [ ] NEW_LINE for k in xrange ( n ) : NEW_LINE INDENT if ss >> k & 1 : NEW_LINE INDENT m . append ( memo [ n ] [ ss ^ ( 1 << k ) ] ) NEW_LINE DEDENT else : NEW_LINE INDENT m . append ( 0.0 ) NEW_LINE DEDENT DEDENT m . reverse ( ) NEW_LINE d = [ 0.0 ] * n NEW_LINE t = s + s NEW_LINE i = n + n - 1 NEW_LINE while t [ i ] == '0' : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT while i >= 0 : NEW_LINE INDENT if t [ i ] == '1' : NEW_LINE INDENT x = m [ i % n ] NEW_LINE d [ i % n ] = n + x NEW_LINE j = i - 1 NEW_LINE while j >= 0 and t [ j ] == '0' : NEW_LINE INDENT d [ j % n ] = n - ( i - j ) + x NEW_LINE j -= 1 NEW_LINE DEDENT i = j NEW_LINE DEDENT DEDENT f = sum ( d ) / n NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT memo [ n ] [ int ( s , 2 ) ] = f NEW_LINE s = s [ - 1 ] + s [ : - 1 ] NEW_LINE DEDENT DEDENT DEDENT def solve ( ) : NEW_LINE INDENT x = stdin . readline ( ) . strip ( ) NEW_LINE n = len ( x ) NEW_LINE t = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if x [ i ] == ' . ' : NEW_LINE INDENT t += 1 << ( n - 1 - i ) NEW_LINE DEDENT DEDENT return memo [ n ] [ t ] NEW_LINE DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT print \" Case ▁ # % d : ▁ % .12f \" % ( i + 1 , solve ( ) ) NEW_LINE DEDENT", "def reader ( inFile ) : NEW_LINE INDENT return inFile . readline ( ) NEW_LINE DEDENT from sys import stderr NEW_LINE def solver ( gonds ) : NEW_LINE INDENT n = len ( gonds ) NEW_LINE k = sum ( [ 1 << i for i in xrange ( n ) if gonds [ i ] == \" X \" ] ) NEW_LINE exps = [ 0.0 ] * ( 1 << n ) NEW_LINE for i in xrange ( ( 1 << n ) - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( i & k ) == k : NEW_LINE INDENT tot = 0 NEW_LINE for j in xrange ( n ) : NEW_LINE INDENT pay = n NEW_LINE w = j NEW_LINE while ( ( i >> w ) & 1 ) == 1 : NEW_LINE INDENT w = ( w + 1 ) % n NEW_LINE pay -= 1 NEW_LINE DEDENT tot += ( pay + exps [ i + ( 1 << w ) ] ) NEW_LINE DEDENT exps [ i ] = tot / n NEW_LINE DEDENT DEDENT return exps [ k ] NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , \" / Users / lpebody / gcj / 2013_3 / d / \" , \" d \" ) . run ( ) NEW_LINE DEDENT", "F = None NEW_LINE def f ( s , n ) : NEW_LINE INDENT global F NEW_LINE if s in F : NEW_LINE INDENT return F [ s ] NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT s_ = s [ i : ] + s [ : i ] NEW_LINE if s_ in F : NEW_LINE INDENT return F [ s_ ] NEW_LINE DEDENT DEDENT ans = 0.0 NEW_LINE if len ( [ 1 for c in list ( s ) if c == ' . ' ] ) == 0 : NEW_LINE INDENT F [ s ] = ans NEW_LINE return ans NEW_LINE DEDENT ts = s * 2 NEW_LINE dist = 0 NEW_LINE last = 2 * n NEW_LINE for i in reversed ( range ( 2 * n ) ) : NEW_LINE INDENT if ts [ i ] == ' . ' : NEW_LINE INDENT dist = 0 NEW_LINE last = i NEW_LINE DEDENT else : NEW_LINE INDENT dist += 1 NEW_LINE DEDENT if i < n : NEW_LINE INDENT ps = last if last < n else last - n NEW_LINE ns = s [ : ps ] + ' X ' + s [ ps + 1 : ] NEW_LINE ans += n - ( last - i ) + f ( ns , n ) NEW_LINE DEDENT DEDENT ans /= n NEW_LINE F [ s ] = ans NEW_LINE return ans NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT global F NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT s = raw_input ( ) . strip ( ' \\n ' ) NEW_LINE n = len ( s ) NEW_LINE F = dict ( ) NEW_LINE ans = f ( s , n ) NEW_LINE print \" Case ▁ # % d : ▁ % .10f \" % ( t , ans ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "import sys NEW_LINE sys . path . insert ( 0 , ' / home / rishig / codejam / ' ) NEW_LINE from library import * NEW_LINE d = { } NEW_LINE def ecase ( st , n ) : NEW_LINE INDENT if st [ - 1 ] == ' . ' : NEW_LINE INDENT s = st NEW_LINE DEDENT else : NEW_LINE INDENT f = st . find ( ' . ' ) NEW_LINE if f == - 1 : return 0 NEW_LINE s = st [ f + 1 : ] + st [ : f + 1 ] NEW_LINE DEDENT if s in d : NEW_LINE INDENT return d [ s ] NEW_LINE DEDENT assert s [ - 1 ] == ' . ' NEW_LINE arr = [ ] NEW_LINE count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if s [ i ] == ' . ' : NEW_LINE INDENT arr . append ( ( count + 1 , s [ : i ] + ' X ' + s [ i + 1 : ] ) ) NEW_LINE count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT total = n - 1. * sum ( c * ( c - 1 ) / 2 for c , s in arr ) / n NEW_LINE newtot = total + 1. / n * sum ( c * ecase ( s , n ) for c , s in arr ) NEW_LINE d [ s ] = newtot NEW_LINE return newtot NEW_LINE DEDENT def solvecase ( case ) : NEW_LINE INDENT S = f . readline ( ) . strip ( ) NEW_LINE n = len ( S ) NEW_LINE return ecase ( S , n ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT f = file ( sys . argv [ 1 ] ) NEW_LINE T = readint ( f ) NEW_LINE sys . stderr . write ( strftime ( \" % H : % M : % S \\n \" ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT ans = solvecase ( case ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( case , ans ) NEW_LINE if T <= 15 or case == 1 or case % max ( ( T // 10 ) , 5 ) == 0 : NEW_LINE INDENT sys . stderr . write ( ' completed ▁ case ▁ % d , ▁ ' % case ) NEW_LINE sys . stderr . write ( strftime ( \" % H : % M : % S \\n \" ) ) NEW_LINE DEDENT DEDENT DEDENT", "rl = raw_input NEW_LINE cases = int ( rl ( ) ) NEW_LINE cache = { } NEW_LINE def go ( n , status ) : NEW_LINE INDENT if status == ( 2 ** n ) - 1 : return 0.0 NEW_LINE key = ( n , status ) NEW_LINE if key in cache : return cache [ key ] NEW_LINE ret = 0.0 NEW_LINE for arr in xrange ( n ) : NEW_LINE INDENT wait = 0 NEW_LINE while status & ( 2 ** ( ( arr + wait ) % n ) ) : NEW_LINE INDENT wait += 1 NEW_LINE DEDENT ret += ( n - wait ) + go ( n , status + ( 2 ** ( ( arr + wait ) % n ) ) ) NEW_LINE DEDENT cache [ key ] = ret / n NEW_LINE return ret / n NEW_LINE DEDENT for cc in xrange ( cases ) : NEW_LINE INDENT occupied = rl ( ) . strip ( ) NEW_LINE n = len ( occupied ) NEW_LINE status = sum ( [ 2 ** i for i in xrange ( n ) if occupied [ i ] == ' X ' ] ) NEW_LINE print ' Case ▁ # % d : ▁ % .10lf ' % ( cc + 1 , go ( n , status ) ) NEW_LINE DEDENT" ]
codejam_11_52
[ "import java . util . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { int N = in . nextInt ( ) ; int [ ] MC = new int [ 10000 ] ; for ( int i = 0 ; i < N ; i ++ ) { MC [ in . nextInt ( ) - 1 ] ++ ; } int ans = 0 ; int [ ] C = new int [ 10000 ] ; int [ ] E = new int [ 10000 ] ; for ( int i = 1 ; i <= N ; i ++ ) { boolean good = true ; for ( int j = 0 ; j < 10000 ; j ++ ) C [ j ] = MC [ j ] ; Arrays . fill ( E , 0 ) ; for ( int j = 0 ; j < 10000 ; j ++ ) { while ( C [ j ] > 0 ) { boolean legal = true ; if ( j + i > 10000 ) { legal = false ; } else { for ( int k = 0 ; k < i ; k ++ ) if ( C [ j + k ] == 0 ) legal = false ; } if ( legal ) { for ( int k = 0 ; k < i ; k ++ ) C [ j + k ] -- ; if ( j + i < 10000 ) E [ j + i ] ++ ; } else { if ( E [ j ] > 0 ) { E [ j ] -- ; C [ j ] -- ; if ( j + 1 < 10000 ) E [ j + 1 ] ++ ; } else { good = false ; break ; } } } } if ( good ) { ans = i ; } } System . out . format ( \" Case ▁ # % d : ▁ % d \\n \" , zz , ans ) ; } } }", "import java . util . * ; import java . io . * ; class B_as { Scanner in ; PrintWriter out ; public void solve ( ) throws IOException { int testNo = in . nextInt ( ) ; for ( int test = 1 ; test <= testNo ; test ++ ) { int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; } Arrays . sort ( a ) ; int m = 0 ; int [ ] last = new int [ n ] ; int [ ] len = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int blen = Integer . MAX_VALUE ; int best = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( last [ j ] == a [ i ] - 1 && len [ j ] < blen ) { best = j ; blen = len [ j ] ; } } if ( best == - 1 ) { last [ m ] = a [ i ] ; len [ m ] = 1 ; m ++ ; } else { last [ best ] = a [ i ] ; len [ best ] = len [ best ] + 1 ; } } int blen = Integer . MAX_VALUE ; for ( int i = 0 ; i < m ; i ++ ) { if ( len [ i ] < blen ) { blen = len [ i ] ; } } if ( blen == Integer . MAX_VALUE ) { blen = 0 ; } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + blen ) ; } } public void run ( ) { try { in = new Scanner ( new File ( \" B - large . in \" ) ) ; out = new PrintWriter ( new File ( \" B - large . out \" ) ) ; solve ( ) ; in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public static void main ( String [ ] arg ) { Locale . setDefault ( Locale . US ) ; new B_as ( ) . run ( ) ; } }", "package round3 ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Scanner ; public class B { static class Niz { int zadnji , duzina ; Niz ( int element ) { duzina = 1 ; zadnji = element ; } } public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( \" B . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" B . out \" ) ) ; int tt = in . nextInt ( ) ; for ( int ttt = 1 ; ttt <= tt ; ttt ++ ) { int n = in . nextInt ( ) ; int [ ] t = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) t [ i ] = in . nextInt ( ) ; int res = 0 ; if ( n > 0 ) { Arrays . sort ( t ) ; ArrayList < Niz > nizovi = new ArrayList < B . Niz > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Niz a = null ; for ( Niz niz : nizovi ) if ( niz . zadnji == t [ i ] - 1 && ( a == null || a . duzina > niz . duzina ) ) a = niz ; if ( a == null ) nizovi . add ( new Niz ( t [ i ] ) ) ; else { a . duzina ++ ; a . zadnji = t [ i ] ; } } res = n ; for ( Niz niz : nizovi ) if ( niz . duzina < res ) res = niz . duzina ; } out . printf ( \" Case ▁ # % d : ▁ % d \" , ttt , res ) ; out . println ( ) ; } out . flush ( ) ; out . close ( ) ; in . close ( ) ; } }", "import java . io . * ; import java . util . * ; import java . math . * ; public class Main { static StreamTokenizer in ; static int next ( ) throws Exception { in . nextToken ( ) ; return ( int ) in . nval ; } ; static PrintWriter out ; static String NAME = \" b \" ; public static void main ( String [ ] args ) throws Exception { in = new StreamTokenizer ( new BufferedReader ( new FileReader ( new File ( NAME + \" . in \" ) ) ) ) ; out = new PrintWriter ( new File ( NAME + \" . out \" ) ) ; int tests = next ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { int n = next ( ) ; if ( n == 0 ) { out . println ( \" Case ▁ # \" + test + \" : ▁ 0\" ) ; continue ; } int m = 10005 ; int [ ] k = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) k [ next ( ) ] ++ ; int answ = 100000 ; int start = 0 ; int end = 0 ; while ( true ) { while ( start < m && k [ start ] == 0 ) start ++ ; if ( start == m ) break ; end = start ; while ( k [ end ] != 0 ) end ++ ; ArrayList < Integer > s = new ArrayList < Integer > ( ) ; ArrayList < Integer > e = new ArrayList < Integer > ( ) ; for ( int i = start ; i <= end ; i ++ ) { if ( k [ i ] > k [ i - 1 ] ) for ( int j = 0 ; j < k [ i ] - k [ i - 1 ] ; j ++ ) s . add ( i ) ; if ( k [ i ] < k [ i - 1 ] ) for ( int j = 0 ; j < k [ i - 1 ] - k [ i ] ; j ++ ) e . add ( i ) ; } for ( int i = 0 ; i < s . size ( ) ; i ++ ) answ = Math . min ( answ , e . get ( i ) - s . get ( i ) ) ; start = end ; } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + answ ) ; } out . close ( ) ; } }", "import sun . java2d . pipe . OutlineTextRenderer ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class B { private static final int MAX = 20000 ; private String solve ( Scanner in ) { int n = in . nextInt ( ) ; if ( n == 0 ) { return \"0\" ; } int [ ] a = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ in . nextInt ( ) - 1 ] ++ ; } int l = 1 ; int r = n + 1 ; main : while ( r > l + 1 ) { int m = ( l + r ) / 2 ; int [ ] aa = a . clone ( ) ; int [ ] b = new int [ MAX + 1 ] ; for ( int i = 0 ; i < MAX ; i ++ ) { while ( aa [ i ] > 0 ) { if ( i > 0 && b [ i - 1 ] > 0 ) { b [ i - 1 ] -- ; b [ i ] ++ ; aa [ i ] -- ; } else { boolean ok = true ; for ( int j = i ; j < i + m ; j ++ ) { if ( aa [ j ] == 0 ) ok = false ; aa [ j ] -- ; } if ( ! ok ) { r = m ; continue main ; } b [ i + m - 1 ] ++ ; } } } l = m ; } return \" \" + l ; } public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" input . txt \" ) ) ; PrintWriter out = new PrintWriter ( \" output . txt \" ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new B ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } }" ]
[ "def solve ( a ) : NEW_LINE INDENT if len ( a ) == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT b = [ ] NEW_LINE cur = a [ 0 ] - 1 NEW_LINE cnt = 0 NEW_LINE for x in a : NEW_LINE INDENT if x == cur : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT b . append ( cnt ) NEW_LINE cnt = 1 NEW_LINE cur = x NEW_LINE DEDENT DEDENT b . append ( cnt ) NEW_LINE res = 100000 NEW_LINE Q = [ ] NEW_LINE b . append ( 0 ) NEW_LINE for i in range ( 1 , len ( b ) ) : NEW_LINE INDENT while b [ i ] > b [ i - 1 ] : NEW_LINE INDENT Q . append ( i ) NEW_LINE b [ i - 1 ] += 1 NEW_LINE DEDENT while b [ i ] < b [ i - 1 ] : NEW_LINE INDENT x = Q . pop ( 0 ) NEW_LINE b [ i - 1 ] -= 1 NEW_LINE res = min ( res , i - x ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT fi = open ( \" input . txt \" ) NEW_LINE for turn in range ( int ( fi . readline ( ) ) ) : NEW_LINE INDENT a = map ( int , fi . readline ( ) . split ( ) ) NEW_LINE n = a . pop ( 0 ) NEW_LINE assert n == len ( a ) NEW_LINE a . sort ( ) NEW_LINE res = 100000 NEW_LINE i = 0 NEW_LINE for j in range ( 1 , len ( a ) ) : NEW_LINE INDENT if a [ j ] > a [ j - 1 ] + 1 : NEW_LINE INDENT res = min ( res , solve ( a [ i : j ] ) ) NEW_LINE i = j NEW_LINE DEDENT DEDENT res = min ( res , solve ( a [ i : len ( a ) ] ) ) NEW_LINE print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( turn + 1 , res ) NEW_LINE DEDENT", "from __future__ import division NEW_LINE from __future__ import with_statement NEW_LINE from __future__ import print_function NEW_LINE def memoized ( func ) : NEW_LINE INDENT mem = { } NEW_LINE def wrapped ( * args ) : NEW_LINE INDENT if args not in mem : NEW_LINE INDENT mem [ args ] = func ( * args ) NEW_LINE DEDENT return mem [ args ] NEW_LINE DEDENT return wrapped NEW_LINE DEDENT TASK = \" B \" NEW_LINE from collections import Counter NEW_LINE from bisect import insort NEW_LINE print ( \" Calculation . . . \" ) NEW_LINE with open ( TASK + \" . in \" ) as infile : NEW_LINE INDENT with open ( TASK + \" . out \" , mode = \" wt \" ) as outfile : NEW_LINE INDENT cases = int ( infile . readline ( ) ) NEW_LINE for ncase in range ( cases ) : NEW_LINE INDENT print ( \" Case ▁ # { nc } \" . format ( nc = ncase + 1 ) ) NEW_LINE cards = [ int ( s ) for s in infile . readline ( ) . split ( ) ] [ 1 : ] NEW_LINE values = Counter ( cards ) NEW_LINE nums = [ values [ i ] for i in xrange ( 0 , 10002 ) ] NEW_LINE starts = [ ] NEW_LINE shortest = 100000 NEW_LINE c = 0 NEW_LINE for i , n in enumerate ( nums ) : NEW_LINE INDENT if n > c : NEW_LINE INDENT starts += [ i ] * ( n - c ) NEW_LINE DEDENT if c > n : NEW_LINE INDENT shortest = min ( shortest , i - starts [ c - n - 1 ] ) NEW_LINE starts = starts [ c - n : ] NEW_LINE DEDENT c = n NEW_LINE DEDENT if len ( cards ) == 0 : NEW_LINE INDENT shortest = 0 NEW_LINE DEDENT outfile . write ( \" Case ▁ # { nc } : ▁ { data } \\n \" . format ( nc = ncase + 1 , data = shortest ) ) NEW_LINE DEDENT DEDENT DEDENT print ( \" Calculation ▁ done . \" ) NEW_LINE", "import sys NEW_LINE def foo ( ifile ) : NEW_LINE INDENT a = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] [ 1 : ] NEW_LINE a . sort ( ) NEW_LINE if len ( a ) == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT bb = { } NEW_LINE for item in a : NEW_LINE INDENT t = 0 NEW_LINE if item - 1 in bb : NEW_LINE INDENT t = bb [ item - 1 ] [ 0 ] NEW_LINE bb [ item - 1 ] = bb [ item - 1 ] [ 1 : ] NEW_LINE if len ( bb [ item - 1 ] ) == 0 : NEW_LINE INDENT del bb [ item - 1 ] NEW_LINE DEDENT DEDENT if item not in bb : NEW_LINE INDENT bb [ item ] = [ ] NEW_LINE DEDENT bb [ item ] . append ( t + 1 ) NEW_LINE bb [ item ] . sort ( ) NEW_LINE DEDENT res = len ( a ) NEW_LINE for k , v in bb . items ( ) : NEW_LINE INDENT res = min ( res , min ( v ) ) NEW_LINE DEDENT return res NEW_LINE DEDENT def main ( ifile , ofile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT ofile . write ( \" Case ▁ # % s : ▁ % s \\n \" % ( i + 1 , foo ( ifile ) ) ) NEW_LINE DEDENT DEDENT main ( sys . stdin , sys . stdout ) NEW_LINE", "def check ( n , a ) : NEW_LINE INDENT cnt = 0 NEW_LINE b = [ 0 ] * 1010 NEW_LINE f = [ 0 ] * 1010 NEW_LINE len = [ 0 ] * 1010 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT j = 0 NEW_LINE for k in range ( 1 , cnt + 1 ) : NEW_LINE INDENT if ( b [ k ] + 1 == a [ i ] ) and ( j == 0 or len [ k ] < len [ j ] ) : NEW_LINE INDENT j = k NEW_LINE DEDENT DEDENT if j == 0 : NEW_LINE INDENT cnt += 1 NEW_LINE j = cnt NEW_LINE DEDENT b [ j ] = a [ i ] NEW_LINE len [ j ] += 1 NEW_LINE DEDENT ans = 100000000 NEW_LINE for i in range ( 1 , cnt + 1 ) : NEW_LINE INDENT ans = min ( ans , len [ i ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT for c in range ( input ( ) ) : NEW_LINE INDENT a = map ( int , raw_input ( ) . split ( ) ) NEW_LINE n = a [ 0 ] NEW_LINE a = a [ 1 : ] NEW_LINE b = [ 0 ] NEW_LINE a . sort ( ) ; NEW_LINE b . extend ( a ) NEW_LINE ans = check ( n , b ) NEW_LINE if ans == 100000000 : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT print \" Case ▁ # \" + str ( c + 1 ) + \" : ▁ \" + str ( ans ) NEW_LINE DEDENT", "import sys NEW_LINE from collections import * NEW_LINE def solve ( ) : NEW_LINE INDENT data = map ( int , sys . stdin . readline ( ) . split ( ) ) [ 1 : ] NEW_LINE if not data : NEW_LINE INDENT return 0 NEW_LINE DEDENT c = Counter ( data ) NEW_LINE q = deque ( ) NEW_LINE BIG = 2000 NEW_LINE ret = BIG NEW_LINE it = sorted ( c . iteritems ( ) ) NEW_LINE it . append ( [ it [ - 1 ] [ 0 ] + 1 , 0 ] ) NEW_LINE i_ = it [ 0 ] [ 0 ] - 1 NEW_LINE for i , n in it : NEW_LINE INDENT if i != i_ + 1 : NEW_LINE INDENT ret = min ( ret , min ( [ i_ + 1 - j for j in q ] ) ) NEW_LINE q . clear ( ) NEW_LINE DEDENT while n > len ( q ) : NEW_LINE INDENT q . append ( i ) NEW_LINE DEDENT while len ( q ) > n : NEW_LINE INDENT ret = min ( ret , i - q . popleft ( ) ) NEW_LINE DEDENT i_ = i NEW_LINE DEDENT return ret NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT T = int ( sys . stdin . readline ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT print \" Case ▁ # { } : ▁ { } \" . format ( t + 1 , solve ( ) ) NEW_LINE DEDENT DEDENT" ]
codejam_16_33
[ "import java . util . * ; public class C { static Scanner in ; public static void main ( String [ ] args ) { in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . println ( \" Case ▁ # \" + C + \" : ▁ \" + solve ( ) ) ; } } public static String solve ( ) { String out = \" \" ; int a = in . nextInt ( ) , b = in . nextInt ( ) , c = in . nextInt ( ) , limit = in . nextInt ( ) ; int [ ] abT = new int [ 201 ] ; int [ ] bcT = new int [ 201 ] ; int [ ] acT = new int [ 201 ] ; int count = 0 ; for ( int i = a ; i >= 1 ; i -- ) { for ( int j = b ; j >= 1 ; j -- ) { for ( int kk = c ; kk >= 1 ; kk -- ) { int k = ( kk + ( i ) + ( j ) ) % c ; k ++ ; int ab = i * 15 + j ; int ac = i * 15 + k ; int bc = j * 15 + k ; if ( abT [ ab ] < limit && bcT [ bc ] < limit && acT [ ac ] < limit ) { out += \" \\n \" + i + \" ▁ \" + j + \" ▁ \" + k ; count ++ ; abT [ ab ] ++ ; bcT [ bc ] ++ ; acT [ ac ] ++ ; } else { } } } } System . err . println ( count ) ; return count + \" \" + out ; } }", "package gcj2016r1c ; import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . StringTokenizer ; public class ProblemC { public static void main ( String [ ] args ) throws Exception { String fileName = args [ 0 ] ; ProblemC obj = new ProblemC ( ) ; obj . solve ( fileName ) ; } public void solve ( String fileName ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( fileName ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( fileName + \" . out \" ) ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < T ; i ++ ) { String str = br . readLine ( ) ; StringTokenizer token = new StringTokenizer ( str , \" ▁ \" ) ; int J = Integer . parseInt ( token . nextToken ( ) ) ; int P = Integer . parseInt ( token . nextToken ( ) ) ; int S = Integer . parseInt ( token . nextToken ( ) ) ; int K = Integer . parseInt ( token . nextToken ( ) ) ; ArrayList < int [ ] > list = new ArrayList < > ( ) ; int [ ] chk = new int [ P ] ; int s = 0 ; for ( int j = 0 ; j < J ; j ++ ) { for ( int p = 0 ; p < P ; p ++ ) { if ( j != 0 ) { s = chk [ p ] ; } for ( int k = 0 ; k < Math . min ( K , S ) ; k ++ ) { list . add ( new int [ ] { j + 1 , p + 1 , s + 1 } ) ; s = ( s + 1 ) % S ; chk [ p ] = s ; } } } bw . write ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + list . size ( ) ) ; bw . write ( \" \\r \\n \" ) ; for ( int [ ] e : list ) { bw . write ( e [ 0 ] + \" ▁ \" + e [ 1 ] + \" ▁ \" + e [ 2 ] ) ; bw . write ( \" \\r \\n \" ) ; } } bw . close ( ) ; br . close ( ) ; } }", "import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; public class R1CQ3 { public static void main ( String [ ] args ) { try { String fileName = \" C - large \" ; Scanner in = new Scanner ( new File ( fileName + \" . in \" ) ) ; PrintWriter out = new PrintWriter ( fileName + \" . out \" ) ; int numberOfTestCases = in . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numberOfTestCases ; caseNum ++ ) { int J = in . nextInt ( ) ; int P = in . nextInt ( ) ; int S = in . nextInt ( ) ; int k = in . nextInt ( ) ; int dayCount = 0 ; String result = \" \" ; for ( int j = 1 ; j <= J ; j ++ ) { for ( int p = 1 ; p <= P ; p ++ ) { for ( int i = 0 ; i < S && i < k ; i ++ ) { dayCount ++ ; int a = ( ( ( i + p + j ) % S ) + 1 ) ; result += j + \" ▁ \" + p + \" ▁ \" + a + \" \\n \" ; } } } out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + dayCount + \" \\n \" + result . substring ( 0 , result . length ( ) - 1 ) ) ; } in . close ( ) ; out . close ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } }", "package codejamquestion ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class CodeJamQuestion { public static void main ( String [ ] args ) { try { Scanner in = new Scanner ( new File ( \" C - large . in \" ) ) ; PrintWriter out = new PrintWriter ( \" C - large . out \" ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { String answer = \" Case ▁ # \" + test + \" : ▁ \" ; String outfits = \" \" ; int days = 0 ; int J = in . nextInt ( ) ; int P = in . nextInt ( ) ; int S = in . nextInt ( ) ; int k = in . nextInt ( ) ; for ( int j = 1 ; j <= J ; j ++ ) { for ( int p = 1 ; p <= P ; p ++ ) { for ( int i = 0 ; i < S && i < k ; i ++ ) { outfits += j + \" ▁ \" + p + \" ▁ \" + ( ( ( i + p + j ) % S ) + 1 ) + \" \\n \" ; days ++ ; } } } answer += days + \" \\n \" + outfits ; out . println ( answer ) ; } in . close ( ) ; out . close ( ) ; } catch ( FileNotFoundException ex ) { System . out . println ( \" ERROR \" ) ; } } }", "package Round1 ; import java . io . * ; public class C { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" / Users / chao / Downloads / C - large . in \" ) ) ; FileWriter out = new FileWriter ( \" / Users / chao / Desktop / C - large . txt \" ) ; String s = in . readLine ( ) ; int m = Integer . parseInt ( s ) ; int [ ] a = new int [ 3 ] ; for ( int cases = 1 ; cases <= m ; cases ++ ) { String [ ] ss = in . readLine ( ) . split ( \" ▁ \" ) ; for ( int i = 0 ; i < 3 ; i ++ ) { a [ i ] = Integer . parseInt ( ss [ i ] ) ; } int k = Integer . parseInt ( ss [ 3 ] ) ; k = Math . min ( k , a [ 2 ] ) ; int ans = a [ 0 ] * a [ 1 ] * k ; out . write ( \" Case ▁ # \" + cases + \" : ▁ \" + ans + \" \\n \" ) ; for ( int i = 1 ; i <= a [ 0 ] ; i ++ ) { for ( int j = 1 ; j <= a [ 1 ] ; j ++ ) { for ( int x = 0 ; x < k ; x ++ ) { int val = ( i + j + x - 2 ) % a [ 2 ] + 1 ; out . write ( i + \" ▁ \" + j + \" ▁ \" + val + \" \\n \" ) ; } } } } in . close ( ) ; out . flush ( ) ; out . close ( ) ; } }" ]
[ "T = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT j , p , s , k = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE print \" Case ▁ # % d : \" % i , j * p * min ( s , k ) NEW_LINE ans = [ ( x , y ) for x in range ( 1 , j + 1 ) for y in range ( 1 , p + 1 ) for t in range ( min ( s , k ) ) ] NEW_LINE now = 0 NEW_LINE last = - 1 NEW_LINE for i in ans : NEW_LINE INDENT if i [ 0 ] != last : NEW_LINE INDENT now = i [ 0 ] - 1 NEW_LINE last = i [ 0 ] NEW_LINE DEDENT print i [ 0 ] , i [ 1 ] , now % s + 1 NEW_LINE now += 1 NEW_LINE DEDENT DEDENT", "from itertools import product NEW_LINE from itertools import combinations NEW_LINE F = open ( ' C - large . in ' ) NEW_LINE O = open ( ' C - large . out ' , ' w ' ) NEW_LINE T = int ( F . readline ( ) ) NEW_LINE print T NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT J , P , S , K = map ( int , F . readline ( ) . rstrip ( ) . split ( ) ) NEW_LINE x = combinations ( list ( str ( i ) for i in range ( 1 , S + 1 ) ) , min ( S , K ) ) NEW_LINE t = [ ] NEW_LINE for i in x : NEW_LINE INDENT t . append ( i ) NEW_LINE DEDENT q = len ( t ) NEW_LINE ans = J * P * min ( S , K ) NEW_LINE O . write ( \" Case ▁ # % d : ▁ % d \\n \" % ( case , ans ) ) NEW_LINE for j in range ( 1 , J + 1 ) : NEW_LINE INDENT for p in range ( 1 , P + 1 ) : NEW_LINE INDENT for s in range ( 1 , min ( S , K ) + 1 ) : NEW_LINE INDENT string = str ( j ) + ' ▁ ' + str ( p ) + ' ▁ ' + str ( ( s + j - 1 + p - 1 ) % S + 1 ) NEW_LINE O . write ( \" % s \\n \" % ( string ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT F . close ( ) NEW_LINE O . close ( ) NEW_LINE", "import pulp NEW_LINE def solve ( J , P , S , K , Case ) : NEW_LINE INDENT Js = range ( J ) NEW_LINE Ps = range ( P ) NEW_LINE Ss = range ( S ) NEW_LINE prob = pulp . LpProblem ( \" Sudoku ▁ Problem \" , pulp . LpMaximize ) NEW_LINE x = pulp . LpVariable . dicts ( \" x \" , ( Js , Ps , Ss ) , 0 , 1 , pulp . LpInteger ) NEW_LINE for j in Js : NEW_LINE INDENT for p in Ps : NEW_LINE INDENT prob += pulp . lpSum ( [ x [ j ] [ p ] [ s ] for s in Ss ] ) <= K , \" \" NEW_LINE DEDENT DEDENT for s in Ss : NEW_LINE INDENT for p in Ps : NEW_LINE INDENT prob += pulp . lpSum ( [ x [ j ] [ p ] [ s ] for j in Js ] ) <= K , \" \" NEW_LINE DEDENT DEDENT for s in Ss : NEW_LINE INDENT for j in Js : NEW_LINE INDENT prob += pulp . lpSum ( [ x [ j ] [ p ] [ s ] for p in Ps ] ) <= K , \" \" NEW_LINE DEDENT DEDENT prob += pulp . lpSum ( [ x [ j ] [ p ] [ s ] for j in Js for p in Ps for s in Ss ] ) , \" Arbitrary ▁ Objective ▁ Function . ▁ We ▁ solve ▁ feasibility ▁ problem \" NEW_LINE prob . solve ( ) NEW_LINE obj = pulp . value ( prob . objective ) NEW_LINE print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( Case , int ( obj ) ) NEW_LINE for j in Js : NEW_LINE INDENT for p in Ps : NEW_LINE INDENT for s in Ss : NEW_LINE INDENT val = pulp . value ( x [ j ] [ p ] [ s ] ) NEW_LINE if val == 1 : NEW_LINE INDENT print j + 1 , p + 1 , s + 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return obj NEW_LINE DEDENT T = int ( raw_input ( ) ) + 1 NEW_LINE for tc in xrange ( 1 , T ) : NEW_LINE INDENT J , P , S , K = map ( int , raw_input ( ) . split ( ) ) NEW_LINE solve ( J , P , S , K , tc ) NEW_LINE DEDENT", "f = ' c - sample . in ' NEW_LINE f = ' C - small - attempt0 . in ' NEW_LINE f = ' C - large . in ' NEW_LINE inp = map ( str . strip , list ( open ( f ) ) [ 1 : ] ) NEW_LINE def solve ( J , P , S , K ) : NEW_LINE INDENT options = [ ] NEW_LINE for j in range ( J ) : NEW_LINE INDENT for p in range ( P ) : NEW_LINE INDENT for k in range ( min ( S , K ) ) : NEW_LINE INDENT options . append ( [ j , p , ( j + p + k ) % S ] ) NEW_LINE DEDENT DEDENT DEDENT N = J * P * min ( S , K ) NEW_LINE return str ( N ) + ' \\n ' + ' \\n ' . join ( ' ▁ ' . join ( str ( x + 1 ) for x in op ) for op in options ) NEW_LINE DEDENT t = 1 NEW_LINE while inp : NEW_LINE INDENT vals = map ( int , inp . pop ( 0 ) . split ( ) ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( t , solve ( * vals ) ) NEW_LINE t += 1 NEW_LINE DEDENT", "from collections import * NEW_LINE def solve ( J , P , S , K ) : NEW_LINE INDENT Q = set ( ) NEW_LINE A = defaultdict ( int ) NEW_LINE B = defaultdict ( int ) NEW_LINE C = defaultdict ( int ) NEW_LINE for j in range ( J ) : NEW_LINE INDENT for p in range ( P ) : NEW_LINE INDENT for s in range ( min ( S , K ) ) : NEW_LINE INDENT d = ( j + p + s ) % S NEW_LINE Q . add ( ( j , p , d ) ) NEW_LINE A [ ( j , p ) ] += 1 NEW_LINE B [ ( p , d ) ] += 1 NEW_LINE C [ ( d , j ) ] += 1 NEW_LINE DEDENT DEDENT DEDENT assert ( max ( A . values ( ) ) <= K ) NEW_LINE assert ( max ( B . values ( ) ) <= K ) NEW_LINE assert ( max ( C . values ( ) ) <= K ) NEW_LINE assert ( len ( Q ) == J * P * min ( S , K ) ) NEW_LINE return Q NEW_LINE DEDENT def test ( ) : NEW_LINE INDENT for k in range ( 1 , 11 ) : NEW_LINE INDENT for s in range ( 1 , 11 ) : NEW_LINE INDENT for p in range ( 1 , s + 1 ) : NEW_LINE INDENT for j in range ( 1 , p + 1 ) : NEW_LINE INDENT solve ( j , p , s , k ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT T = int ( input ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT J , P , S , K = map ( int , input ( ) . split ( ) ) NEW_LINE Q = solve ( J , P , S , K ) NEW_LINE print ( \" Case ▁ # % d : ▁ % d \" % ( t + 1 , len ( Q ) ) ) NEW_LINE for q in Q : NEW_LINE INDENT print ( q [ 0 ] + 1 , q [ 1 ] + 1 , q [ 2 ] + 1 ) NEW_LINE DEDENT DEDENT" ]
codejam_08_11
[ "import java . io . * ; import java . util . StringTokenizer ; import java . util . Arrays ; public class A { private String solve ( ) throws IOException { int n = nextInt ( ) ; long [ ] x = new long [ n ] ; long [ ] y = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { y [ i ] = nextInt ( ) ; } Arrays . sort ( x ) ; Arrays . sort ( y ) ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += x [ i ] * y [ n - 1 - i ] ; } return \" \" + ans ; } private BufferedReader reader ; private StringTokenizer tt = new StringTokenizer ( \" \" ) ; private String nextToken ( ) throws IOException { while ( ! tt . hasMoreTokens ( ) ) { tt = new StringTokenizer ( reader . readLine ( ) ) ; } return tt . nextToken ( ) ; } private int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } private void run ( ) throws IOException { reader = new BufferedReader ( new FileReader ( \" A - large . in \" ) ) ; PrintWriter writer = new PrintWriter ( new File ( \" A - large . out \" ) ) ; try { int n = nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { writer . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; writer . print ( solve ( ) ) ; writer . println ( ) ; } } finally { reader . close ( ) ; writer . close ( ) ; } } public static void main ( String [ ] args ) { try { new A ( ) . run ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; public class P1 { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( \" p1 . in \" ) ) ; String line = \" \" ; int t = Integer . parseInt ( br . readLine ( ) ) ; FileWriter out = new FileWriter ( \" p1 . out \" ) ; for ( int i = 0 ; i < t ; i ++ ) { int n = Integer . parseInt ( br . readLine ( ) ) ; String v1 = br . readLine ( ) ; String v2 = br . readLine ( ) ; String [ ] vv1 = v1 . split ( \" \\\\ s + \" ) ; String [ ] vv2 = v2 . split ( \" \\\\ s + \" ) ; List < Long > iv1 = s2l ( vv1 ) ; List < Long > iv2 = s2l ( vv2 ) ; Collections . sort ( iv1 ) ; Collections . sort ( iv2 ) ; if ( iv1 . size ( ) != iv2 . size ( ) ) System . out . println ( \" Oops ! \" ) ; long res = 0 ; for ( int j = 0 ; j < iv1 . size ( ) ; j ++ ) { System . out . println ( iv1 . get ( j ) + \" ▁ * ▁ \" + iv2 . get ( iv1 . size ( ) - 1 - j ) ) ; res += iv1 . get ( j ) * iv2 . get ( iv1 . size ( ) - 1 - j ) ; } out . write ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + res + \" \\n \" ) ; System . out . println ( res ) ; } br . close ( ) ; out . close ( ) ; } private static List < Long > s2l ( String [ ] vv1 ) { List < Long > ret = new ArrayList < Long > ( vv1 . length ) ; for ( int i = 0 ; i < vv1 . length ; i ++ ) ret . add ( Long . parseLong ( vv1 [ i ] ) ) ; return ret ; } }", "import java . io . * ; import java . util . * ; public class SolutionA implements Runnable { public static void main ( String [ ] args ) { new Thread ( new SolutionA ( ) ) . run ( ) ; } public void run ( ) { try { Locale . setDefault ( Locale . US ) ; br = new BufferedReader ( new FileReader ( FILENAME + \" . in \" ) ) ; out = new PrintWriter ( FILENAME + \" . out \" ) ; solve ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } BufferedReader br ; PrintWriter out ; StringTokenizer st ; boolean eof ; String nextToken ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) { eof = true ; return \"0\" ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } private static final String FILENAME = \" A - large \" ; public void solve ( ) throws IOException { int testsn = nextInt ( ) ; for ( int test = 0 ; test < testsn ; test ++ ) { out . print ( \" Case ▁ # \" + ( test + 1 ) + \" : ▁ \" ) ; int n = nextInt ( ) ; long [ ] a = new long [ n ] ; long [ ] b = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = nextLong ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = nextLong ( ) ; } Arrays . sort ( a ) ; Arrays . sort ( b ) ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += a [ i ] * b [ n - 1 - i ] ; } out . println ( ans ) ; } } }", "import java . util . * ; public class MinimumProduct { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int numCases = in . nextInt ( ) ; for ( int i = 0 ; i < numCases ; i ++ ) doCase ( i + 1 , in ) ; } private static void doCase ( int caseNum , Scanner in ) { int dims = in . nextInt ( ) ; List < Integer > v1 = new ArrayList < Integer > ( dims ) ; for ( int i = 0 ; i < dims ; i ++ ) v1 . add ( in . nextInt ( ) ) ; Collections . sort ( v1 ) ; List < Integer > v2 = new ArrayList < Integer > ( dims ) ; for ( int i = 0 ; i < dims ; i ++ ) v2 . add ( in . nextInt ( ) ) ; Collections . sort ( v2 , new Comparator < Integer > ( ) { @ Override public int compare ( Integer o1 , Integer o2 ) { return - o1 . compareTo ( o2 ) ; } } ) ; long prod = 0 ; for ( int i = 0 ; i < dims ; i ++ ) prod += v1 . get ( i ) * ( long ) v2 . get ( i ) ; System . out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + prod ) ; } }", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Solution implements Runnable { private static final String INPUT_FILE_NAME = \" a . big . in . txt \" ; private static final String OUTPUT_FILE_NAME = \" a . big . out . txt \" ; private BufferedReader rd ; private PrintWriter wr ; public static void main ( String [ ] args ) { new Thread ( new Solution ( ) ) . start ( ) ; } public void run ( ) { try { solve ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } void solve ( ) throws IOException { rd = new BufferedReader ( new FileReader ( Solution . INPUT_FILE_NAME ) ) ; wr = new PrintWriter ( Solution . OUTPUT_FILE_NAME ) ; String line = rd . readLine ( ) ; StringTokenizer st = new StringTokenizer ( line ) ; int nn = Integer . parseInt ( st . nextToken ( ) ) ; for ( int ii = 0 ; ii < nn ; ++ ii ) { subSolve ( ii ) ; } rd . close ( ) ; wr . close ( ) ; } private void subSolve ( int ii ) throws IOException { String line = rd . readLine ( ) ; StringTokenizer st = new StringTokenizer ( line ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; long [ ] a = new long [ n ] ; long [ ] b = new long [ n ] ; line = rd . readLine ( ) ; st = new StringTokenizer ( line ) ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = Long . parseLong ( st . nextToken ( ) ) ; } line = rd . readLine ( ) ; st = new StringTokenizer ( line ) ; for ( int i = 0 ; i < n ; ++ i ) { b [ i ] = Long . parseLong ( st . nextToken ( ) ) ; } Arrays . sort ( a ) ; Arrays . sort ( b ) ; long result = 0 ; for ( int i = 0 ; i < n ; ++ i ) { result += ( a [ i ] * b [ n - i - 1 ] ) ; } wr . println ( String . format ( \" Case ▁ # % d : ▁ % d \" , ii + 1 , result ) ) ; } }" ]
[ "import re , sys NEW_LINE def solve ( v1 , v2 ) : NEW_LINE INDENT v1 . sort ( ) NEW_LINE v2 . sort ( reverse = True ) NEW_LINE prods = [ a * b for a , b in zip ( v1 , v2 ) ] NEW_LINE sum = 0 NEW_LINE for p in prods : NEW_LINE INDENT sum += p NEW_LINE DEDENT return sum NEW_LINE DEDENT def parse_input ( ) : NEW_LINE INDENT if len ( sys . argv ) < 2 : NEW_LINE INDENT print \" Enter ▁ an ▁ input ▁ filename ▁ please \" NEW_LINE return NEW_LINE DEDENT inp = open ( sys . argv [ 1 ] ) NEW_LINE lines = [ re . sub ( r ' [ \\n ] ' , ' ' , l ) for l in inp . readlines ( ) ] NEW_LINE num_cases = int ( lines [ 0 ] ) NEW_LINE line_num = 1 NEW_LINE for case in xrange ( num_cases ) : NEW_LINE INDENT n = int ( lines [ line_num ] ) NEW_LINE v1 = [ int ( i ) for i in lines [ line_num + 1 ] . split ( ) ] NEW_LINE v2 = [ int ( i ) for i in lines [ line_num + 2 ] . split ( ) ] NEW_LINE line_num += 3 NEW_LINE soln = solve ( v1 , v2 ) NEW_LINE print \" Case ▁ # \" + str ( case + 1 ) + \" : \" , soln NEW_LINE DEDENT DEDENT parse_input ( ) NEW_LINE", "f = open ( r ' C : \\goog\\A - large . in ' ) NEW_LINE numcases = int ( f . readline ( ) ) NEW_LINE for case in range ( numcases ) : NEW_LINE INDENT line = f . readline ( ) . strip ( ) NEW_LINE n = int ( line ) NEW_LINE line = f . readline ( ) . strip ( ) NEW_LINE vect1 = map ( int , line . split ( ' ▁ ' ) ) NEW_LINE line = f . readline ( ) . strip ( ) NEW_LINE vect2 = map ( int , line . split ( ' ▁ ' ) ) NEW_LINE if n != len ( vect1 ) or n != len ( vect2 ) : raise NEW_LINE vect1 . sort ( ) NEW_LINE vect2 . sort ( ) NEW_LINE vect2 . reverse ( ) NEW_LINE total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT total += vect1 [ i ] * vect2 [ i ] NEW_LINE DEDENT print \" Case ▁ # \" + str ( case + 1 ) + \" : ▁ \" + str ( total ) NEW_LINE DEDENT", "filename = \" A - large . in \" NEW_LINE f = open ( filename , ' r ' ) NEW_LINE of = open ( \" A - large . out \" , ' w ' ) NEW_LINE N = int ( f . readline ( ) ) NEW_LINE for x in xrange ( N ) : NEW_LINE INDENT n = int ( f . readline ( ) ) NEW_LINE a = f . readline ( ) . split ( ' ▁ ' ) NEW_LINE b = f . readline ( ) . split ( ' ▁ ' ) NEW_LINE a = [ int ( y ) for y in a ] NEW_LINE b = [ int ( y ) for y in b ] NEW_LINE a . sort ( ) NEW_LINE b . sort ( reverse = True ) NEW_LINE s = 0 NEW_LINE for y in xrange ( len ( a ) ) : NEW_LINE INDENT s += a [ y ] * b [ y ] NEW_LINE DEDENT print >> of , \" Case ▁ # % d : ▁ % d \" % ( x + 1 , s ) NEW_LINE DEDENT f . close ( ) NEW_LINE of . close ( ) NEW_LINE", "import sys NEW_LINE def debug ( * msg ) : NEW_LINE INDENT DEBUG = not True NEW_LINE if DEBUG : NEW_LINE INDENT for x in msg [ : - 1 ] : NEW_LINE INDENT print x , NEW_LINE DEDENT print msg [ - 1 ] NEW_LINE DEDENT DEDENT def read_int_line ( f ) : NEW_LINE INDENT return int ( f . readline ( ) . rstrip ( ) ) NEW_LINE DEDENT def read_vector ( f ) : NEW_LINE INDENT v = f . readline ( ) . rstrip ( ) . split ( ) NEW_LINE return [ int ( x ) for x in v ] NEW_LINE DEDENT def print_result ( case_num , result ) : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % s ' % ( case_num , result ) NEW_LINE DEDENT def do_test_case ( f , case_num ) : NEW_LINE INDENT n = read_int_line ( f ) NEW_LINE x = read_vector ( f ) NEW_LINE debug ( x ) NEW_LINE y = read_vector ( f ) NEW_LINE debug ( y ) NEW_LINE x . sort ( ) NEW_LINE y . sort ( ) NEW_LINE y . reverse ( ) NEW_LINE s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT s += x [ i ] * y [ i ] NEW_LINE DEDENT print_result ( case_num , ' % d ' % s ) NEW_LINE DEDENT def main ( input ) : NEW_LINE INDENT f = file ( input ) NEW_LINE n = read_int_line ( f ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT do_test_case ( f , i + 1 ) NEW_LINE DEDENT f . close ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT if len ( sys . argv ) < 2 : NEW_LINE INDENT print ' usage : ▁ % s ▁ < input > ' % sys . argv [ 0 ] NEW_LINE sys . exit ( 1 ) NEW_LINE DEDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT", "import sys NEW_LINE _TYPE = { ' d ' : int , ' l ' : long , ' f ' : float , ' s ' : str } NEW_LINE _buffer = [ ] NEW_LINE def next_token ( ) : NEW_LINE INDENT if not _buffer : NEW_LINE INDENT line = sys . stdin . readline ( ) NEW_LINE _buffer . extend ( line . split ( ) ) NEW_LINE DEDENT return _buffer . pop ( 0 ) NEW_LINE DEDENT def scanf ( format ) : NEW_LINE INDENT if len ( format ) % 2 != 0 : NEW_LINE INDENT raise ValueError NEW_LINE DEDENT for i in xrange ( 0 , len ( format ) , 2 ) : NEW_LINE INDENT if format [ i ] != ' % ' : NEW_LINE INDENT raise ValueError NEW_LINE DEDENT if format [ i + 1 ] not in ' dfs ' : NEW_LINE INDENT raise ValueError NEW_LINE DEDENT DEDENT result = [ ] NEW_LINE for i in xrange ( 1 , len ( format ) , 2 ) : NEW_LINE INDENT token = next_token ( ) NEW_LINE value = _TYPE [ format [ i ] ] ( token ) NEW_LINE result . append ( value ) NEW_LINE DEDENT return tuple ( result ) NEW_LINE DEDENT def printf ( format , * args ) : NEW_LINE INDENT message = format % args NEW_LINE sys . stdout . write ( message ) NEW_LINE return len ( message ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT n , = scanf ( ' % d ' ) NEW_LINE v1 = list ( scanf ( ' % d ' * n ) ) NEW_LINE v2 = list ( scanf ( ' % d ' * n ) ) NEW_LINE v1 . sort ( ) NEW_LINE v2 . sort ( ) NEW_LINE msp = sum ( x * y for x , y in zip ( v1 , v2 [ : : - 1 ] ) ) NEW_LINE return msp NEW_LINE DEDENT num_cases , = scanf ( ' % d ' ) NEW_LINE for case_num in xrange ( num_cases ) : NEW_LINE INDENT result = solve ( ) NEW_LINE printf ( ' Case ▁ # % d : ▁ % s \\n ' , case_num + 1 , result ) NEW_LINE DEDENT" ]
codejam_10_21
[ "import java . io . * ; import java . math . * ; import java . util . * ; public class Main { static class Tree { final String name ; final ArrayList < Tree > a = new ArrayList < Tree > ( ) ; Tree ( String name ) { this . name = name ; } int size ( ) { if ( a . size ( ) == 0 ) return 1 ; int ans = 1 ; for ( Tree t : a ) ans += t . size ( ) ; return ans ; } void out ( String s ) { System . out . println ( s + name ) ; for ( Tree t : a ) t . out ( s + \" ▁ ▁ \" ) ; } void out ( ) { out ( \" \" ) ; } } static void add ( Tree t , String d ) { String [ ] ss = d . substring ( 1 ) . split ( \" / \" ) ; for ( String s : ss ) { Tree w = null ; for ( Tree r : t . a ) if ( r . name . equals ( s ) ) { w = r ; break ; } if ( w == null ) { w = new Tree ( s ) ; t . a . add ( w ) ; } t = w ; } } public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" Main . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" Main . out \" ) ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; in . nextLine ( ) ; Tree t = new Tree ( \" \" ) ; for ( int i = 0 ; i < n ; i ++ ) { String d = in . nextLine ( ) ; add ( t , d ) ; } int was = t . size ( ) ; for ( int i = 0 ; i < m ; i ++ ) { String d = in . nextLine ( ) ; add ( t , d ) ; } out . println ( t . size ( ) - was ) ; } out . close ( ) ; } }", "import java . util . * ; import java . io . * ; import java . math . * ; public class Solution { class Tree { Map < String , Tree > mp = new HashMap < String , Tree > ( ) ; public Tree ( ) { } } Tree root ; int res ; void process ( String s , boolean add ) { s = s . substring ( 1 ) ; String [ ] items = s . split ( \" / \" ) ; Tree cur = root ; for ( int i = 0 ; i < items . length ; i ++ ) { if ( ! cur . mp . containsKey ( items [ i ] ) ) { cur . mp . put ( items [ i ] , new Tree ( ) ) ; if ( add ) res ++ ; } cur = cur . mp . get ( items [ i ] ) ; } } public void doMain ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; int caseCnt = sc . nextInt ( ) ; long time = System . currentTimeMillis ( ) ; for ( int caseNum = 1 ; caseNum <= caseCnt ; caseNum ++ ) { int have = sc . nextInt ( ) , next = sc . nextInt ( ) ; root = new Tree ( ) ; res = 0 ; for ( int i = 0 ; i < have ; i ++ ) { process ( sc . next ( ) , false ) ; } for ( int i = 0 ; i < next ; i ++ ) process ( sc . next ( ) , true ) ; pw . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + res ) ; System . out . println ( \" Finished ▁ testcase ▁ \" + caseNum + \" , ▁ time ▁ = ▁ \" + ( System . currentTimeMillis ( ) - time ) ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) throws Exception { ( new Solution ( ) ) . doMain ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . * ; public class A { public void solve ( ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( \" A - large . in \" ) ) ; PrintWriter out = new PrintWriter ( \" A - large . out \" ) ; int testN = in . nextInt ( ) ; for ( int test = 1 ; test <= testN ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; String [ ] exists = new String [ n ] ; String [ ] create = new String [ m ] ; Set < String > ex = new HashSet < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { exists [ i ] = in . next ( ) ; String [ ] t = exists [ i ] . split ( \" / \" ) ; String r = \" \" ; for ( int j = 1 ; j < t . length ; j ++ ) { r = r + \" / \" + t [ j ] ; ex . add ( r ) ; } } Set < String > need = new TreeSet < String > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { create [ i ] = in . next ( ) ; String [ ] t = create [ i ] . split ( \" / \" ) ; String r = \" \" ; for ( int j = 1 ; j < t . length ; j ++ ) { r = r + \" / \" + t [ j ] ; need . add ( r ) ; } } int res = 0 ; for ( String s : need ) { if ( ! ex . contains ( s ) ) { res ++ ; ex . add ( s ) ; } } out . println ( res ) ; } in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new A ( ) . solve ( ) ; } }", "import java . util . * ; import java . io . * ; public class Main implements Runnable { public Scanner in ; public PrintWriter out ; Main ( ) throws IOException { in = new Scanner ( new File ( \" in \" ) ) ; out = new PrintWriter ( new File ( \" out \" ) ) ; } void close ( ) throws IOException { out . close ( ) ; } void check ( boolean f , String msg ) { if ( ! f ) { out . close ( ) ; throw new RuntimeException ( msg ) ; } } public void run ( ) { int tn = in . nextInt ( ) ; for ( int test = 1 ; test <= tn ; test ++ ) { int old = in . nextInt ( ) ; int create = in . nextInt ( ) ; in . nextLine ( ) ; Node root = new Node ( ) ; for ( int i = 0 ; i < old ; i ++ ) { add ( root , in . nextLine ( ) . split ( \" / \" ) , 1 ) ; } int r = 0 ; for ( int i = 0 ; i < create ; i ++ ) { r += add ( root , in . nextLine ( ) . split ( \" / \" ) , 1 ) ; } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + r ) ; } try { close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } int add ( Node node , String [ ] tokens , int p ) { if ( p >= tokens . length ) { return 0 ; } int r = 0 ; if ( node . children . get ( tokens [ p ] ) == null ) { node . children . put ( tokens [ p ] , new Node ( ) ) ; r = 1 ; } return r + add ( node . children . get ( tokens [ p ] ) , tokens , p + 1 ) ; } public class Node { Map < String , Node > children ; Node ( ) { children = new TreeMap < String , Node > ( ) ; } } public static void main ( String [ ] args ) throws IOException { new Thread ( new Main ( ) ) . start ( ) ; } }", "import java . util . * ; import java . io . * ; public class x { static class Directory { int st ; HashMap < String , Directory > h ; Directory ( int cst ) { h = new HashMap < String , Directory > ( ) ; st = cst ; } Directory create ( String name , int sst ) { Directory c = h . get ( name ) ; if ( c != null ) return c ; c = new Directory ( sst ) ; h . put ( name , c ) ; return c ; } int count ( int lst ) { int cur = 0 ; if ( st > lst ) ++ cur ; for ( Directory z : h . values ( ) ) cur += z . count ( lst ) ; return cur ; } } public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; for ( int tt = 1 ; tt <= t ; tt ++ ) { Directory r = new Directory ( 0 ) ; int n = in . nextInt ( ) , m = in . nextInt ( ) ; for ( int i = 1 ; i <= n + m ; i ++ ) { String [ ] a = in . next ( ) . split ( \" / \" ) ; Directory c = r ; for ( int j = 1 ; j < a . length ; j ++ ) { c = c . create ( a [ j ] , i ) ; } } System . out . println ( \" Case ▁ # \" + tt + \" : ▁ \" + r . count ( n ) ) ; } ; } ; } ;" ]
[ "import sys NEW_LINE import os NEW_LINE f = open ( sys . argv [ 1 ] ) NEW_LINE def fun ( cs ) : NEW_LINE INDENT dt = [ x . strip ( ) for x in f . readline ( ) . split ( \" ▁ \" ) ] NEW_LINE n = int ( dt [ 0 ] ) NEW_LINE m = int ( dt [ 1 ] ) NEW_LINE got = set ( ' / ' ) NEW_LINE res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT line = f . readline ( ) . strip ( ) NEW_LINE ps = line . split ( \" / \" ) NEW_LINE cur = \" \" NEW_LINE for t in ps : NEW_LINE INDENT cur = cur + \" / \" + t NEW_LINE if cur not in got : NEW_LINE INDENT got . add ( cur ) NEW_LINE DEDENT DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT line = f . readline ( ) . strip ( ) NEW_LINE ps = line . split ( \" / \" ) NEW_LINE cur = \" \" NEW_LINE for t in ps : NEW_LINE INDENT cur = cur + \" / \" + t NEW_LINE if cur not in got : NEW_LINE INDENT got . add ( cur ) NEW_LINE res += 1 NEW_LINE DEDENT DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( cs , res ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT T = int ( f . readline ( ) . strip ( ) ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT fun ( i + 1 ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "ntests = int ( input ( ) ) NEW_LINE for tt in range ( 1 , ntests + 1 ) : NEW_LINE INDENT [ N , M ] = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE dirs = set ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT p = input ( ) + \" / \" NEW_LINE for z in range ( len ( p ) - 1 ) : NEW_LINE INDENT if ( p [ z + 1 ] == ' / ' ) : NEW_LINE INDENT dirs . add ( p [ : ( z + 1 ) ] ) NEW_LINE DEDENT DEDENT DEDENT k = len ( dirs ) NEW_LINE for i in range ( M ) : NEW_LINE INDENT p = input ( ) + \" / \" NEW_LINE for z in range ( len ( p ) - 1 ) : NEW_LINE INDENT if ( p [ z + 1 ] == ' / ' ) : NEW_LINE INDENT dirs . add ( p [ : ( z + 1 ) ] ) NEW_LINE DEDENT DEDENT DEDENT print ( \" Case ▁ # \" + str ( tt ) + \" : ▁ \" + str ( len ( dirs ) - k ) ) NEW_LINE DEDENT", "from scanf import * NEW_LINE opers = 0 NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . children = { } NEW_LINE DEDENT def addPath ( self , path ) : NEW_LINE INDENT if len ( path ) == 0 : return NEW_LINE if not path [ 0 ] in self . children : NEW_LINE INDENT global opers NEW_LINE opers += 1 NEW_LINE self . children [ path [ 0 ] ] = Node ( ) NEW_LINE DEDENT self . children [ path [ 0 ] ] . addPath ( path [ 1 : ] ) NEW_LINE DEDENT DEDENT def solveCase ( cas ) : NEW_LINE INDENT global opers NEW_LINE n , m = scanf ( \" % d % d \" ) NEW_LINE root = Node ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT root . addPath ( scanf ( \" % s \" ) [ 0 ] . split ( \" / \" ) [ 1 : ] ) NEW_LINE DEDENT opers = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT root . addPath ( scanf ( \" % s \" ) [ 0 ] . split ( \" / \" ) [ 1 : ] ) NEW_LINE DEDENT print ( \" Case ▁ # \" + str ( cas ) + \" : ▁ \" + str ( opers ) ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT tests = scanf ( \" % d \" ) [ 0 ] NEW_LINE for i in range ( tests ) : NEW_LINE INDENT solveCase ( i + 1 ) NEW_LINE DEDENT DEDENT", "def add_folder ( s ) : NEW_LINE INDENT folder = ' / ' NEW_LINE aux = 0 NEW_LINE idx = 1 NEW_LINE for word in s . split ( ' / ' ) [ 1 : ] : NEW_LINE INDENT folder += word + ' / ' NEW_LINE if folder not in dirs : NEW_LINE INDENT dirs . add ( folder ) NEW_LINE aux += 1 NEW_LINE DEDENT DEDENT return aux NEW_LINE DEDENT f = open ( ' a . in ' , ' r ' ) NEW_LINE T = int ( f . readline ( ) ) NEW_LINE for t_no in range ( 1 , T + 1 ) : NEW_LINE INDENT dirs = set ( ) NEW_LINE N , M = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT s = f . readline ( ) [ : - 1 ] NEW_LINE add_folder ( s ) NEW_LINE DEDENT sol = 0 NEW_LINE for i in range ( M ) : NEW_LINE INDENT s = f . readline ( ) [ : - 1 ] NEW_LINE sol += add_folder ( s ) NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( t_no , sol ) NEW_LINE DEDENT", "import sys NEW_LINE T = int ( raw_input ( ) ) NEW_LINE def components ( path ) : NEW_LINE INDENT parts = path . split ( ' / ' ) [ 1 : ] NEW_LINE for i in xrange ( len ( parts ) ) : NEW_LINE INDENT yield ' / ' . join ( parts [ : i + 1 ] ) NEW_LINE DEDENT DEDENT for testCase in xrange ( 1 , T + 1 ) : NEW_LINE INDENT N , M = raw_input ( ) . split ( ) NEW_LINE N , M = int ( N ) , int ( M ) NEW_LINE tree = set ( ) NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT dir = raw_input ( ) NEW_LINE for p in components ( dir ) : NEW_LINE INDENT tree . add ( p ) NEW_LINE DEDENT DEDENT added = 0 NEW_LINE for j in xrange ( M ) : NEW_LINE INDENT dir = raw_input ( ) NEW_LINE for p in components ( dir ) : NEW_LINE INDENT if p not in tree : NEW_LINE INDENT added += 1 NEW_LINE DEDENT tree . add ( p ) NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( testCase , added ) NEW_LINE DEDENT" ]
codejam_11_22
[ "import java . io . * ; import java . util . * ; public class B { private static String fileName = B . class . getSimpleName ( ) . replaceFirst ( \" _ . * \" , \" \" ) ; private static String inputFileName = fileName + \" . in \" ; private static String outputFileName = fileName + \" . out \" ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { int points = in . nextInt ( ) ; int d = in . nextInt ( ) ; List < Integer > xs = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < points ; i ++ ) { int x = in . nextInt ( ) ; int amount = in . nextInt ( ) ; for ( int j = 0 ; j < amount ; j ++ ) { xs . add ( x ) ; } } Collections . sort ( xs ) ; double left = 0 ; double right = 1e12 ; binsearch : while ( left + 0.5e-6 < right ) { System . out . println ( right - left ) ; double time = ( left + right ) / 2 ; double p = - 1e15 ; for ( int x : xs ) { double pp = Math . max ( x - time , p + d ) ; if ( pp > x + time ) { if ( left == time ) { break ; } left = time ; continue binsearch ; } p = pp ; } if ( right == time ) { break ; } right = time ; } out . println ( right ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; if ( args . length >= 2 ) { inputFileName = args [ 0 ] ; outputFileName = args [ 1 ] ; } in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; new B ( ) . solve ( ) ; System . out . println ( \" Case ▁ # \" + t + \" : ▁ solved \" ) ; } in . close ( ) ; out . close ( ) ; } }", "package round1 ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class HotDogs { static class Point { int position , total ; public Point ( int position , int total ) { this . position = position ; this . total = total ; } } static final double eps = 0.0000000001 ; public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( \" hotDog . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" hotDog . out \" ) ) ; int tt = in . nextInt ( ) ; for ( int t = 1 ; t <= tt ; t ++ ) { System . out . println ( t ) ; int c = in . nextInt ( ) ; double d = in . nextInt ( ) ; Point [ ] p = new Point [ c ] ; for ( int i = 0 ; i < c ; i ++ ) { int position = in . nextInt ( ) ; int total = in . nextInt ( ) ; p [ i ] = new Point ( position , total ) ; } double lg = 0 , dg = 1000000000 ; dg *= dg ; int count = 0 ; while ( dg - lg > eps && count < 100000 ) { count ++ ; double s = ( dg + lg ) / 2 ; boolean moze = true ; double tmin = - 1000000000000000000.0 ; for ( int i = 0 ; moze && i < c ; i ++ ) { double t1 = Math . max ( tmin , p [ i ] . position - s ) ; double tlast = t1 + ( double ) ( p [ i ] . total - 1 ) * ( double ) d ; if ( tlast - p [ i ] . position > s + eps ) moze = false ; else tmin = tlast + ( double ) d ; } if ( moze ) dg = s ; else lg = s ; } System . out . println ( dg + \" ▁ \" + lg ) ; out . printf ( \" Case ▁ # % d : ▁ % .10f \" , t , ( lg + dg ) / 2 ) ; out . println ( ) ; } out . flush ( ) ; out . close ( ) ; } }", "package round1b ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . util . ArrayList ; import java . util . Collections ; import qual2011 . Kattio ; public class B { public static void main ( String [ ] args ) throws FileNotFoundException { Kattio io ; io = new Kattio ( new FileInputStream ( \" src / round1b / B - large - 0 . in \" ) , new FileOutputStream ( \" src / round1b / B - large - 0 . out \" ) ) ; int cases = io . getInt ( ) ; for ( int i = 1 ; i <= cases ; i ++ ) { io . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; new B ( ) . solve ( io ) ; } io . close ( ) ; } private void solve ( Kattio io ) { int C = io . getInt ( ) , D = io . getInt ( ) ; ArrayList < Long > vendor = new ArrayList < Long > ( ) ; for ( int i = 0 ; i < C ; i ++ ) { int P = io . getInt ( ) , V = io . getInt ( ) ; for ( int j = 0 ; j < V ; j ++ ) { vendor . add ( ( long ) P * 2 ) ; } } D *= 2 ; Collections . sort ( vendor ) ; long lo = 0 , hi = 2000000000000L ; int iter = 0 ; long best = hi ; while ( hi > lo ) { long x = ( hi + lo ) / 2 ; long allowed = vendor . get ( 0 ) - x ; boolean ok = true ; for ( Long v : vendor ) { long t = Math . max ( allowed , v - x ) ; if ( Math . abs ( t - v ) > x ) { ok = false ; break ; } allowed = t + D ; } if ( ok ) { hi = x ; best = x ; } else { lo = x + 1 ; } iter ++ ; } io . println ( best / 2.0 ) ; } }", "import java . util . * ; import java . io . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) throws Exception { new B ( ) . run ( ) ; } final double EPS = 1e-9 ; void run ( ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int o = 1 ; o <= T ; o ++ ) { int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; ArrayList < Integer > ps = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < C ; i ++ ) { int P = sc . nextInt ( ) ; int V = sc . nextInt ( ) ; for ( int j = 0 ; j < V ; j ++ ) ps . add ( P ) ; } Collections . sort ( ps ) ; double left = 0 , right = 1e13 ; double ans = right * 2 ; for ( int e = 0 ; e < 200 ; e ++ ) { double m = ( left + right ) / 2 ; if ( ok ( ps , D , m ) ) { right = m ; ans = min ( m , ans ) ; } else { left = m ; } } System . out . printf ( \" Case ▁ # % d : ▁ % f \\n \" , o , ans ) ; } } boolean ok ( ArrayList < Integer > ps , int D , double len ) { double last = ps . get ( 0 ) - len ; for ( int i = 1 ; i < ps . size ( ) ; i ++ ) { double p = ps . get ( i ) ; if ( p - last + len < D + EPS ) return false ; if ( p - last - len > D - EPS ) { last = p - len ; } else { last += D ; } } return true ; } } class CL implements Comparable < CL > { int pos ; int num ; CL ( int p , int v ) { pos = p ; num = v ; } public int compareTo ( CL cl ) { return this . pos - cl . pos ; } }", "import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class B implements Runnable { public void solve ( ) throws IOException { int tn = in . nextInt ( ) ; for ( int test = 1 ; test <= tn ; test ++ ) { int n = in . nextInt ( ) ; int d = in . nextInt ( ) ; int [ ] v = new int [ n ] ; int [ ] x = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = in . nextInt ( ) ; v [ i ] = in . nextInt ( ) ; } double l = 0.0 ; double r = 1E14 ; while ( r - l > 0.1 ) { double t = 0.5 * ( l + r ) ; double X = Double . NEGATIVE_INFINITY ; boolean ok = true ; for ( int i = 0 ; i < n ; i ++ ) { X = Math . max ( X + d , x [ i ] - t ) + ( v [ i ] - 1 ) * 1.0 * d ; if ( Math . abs ( X - x [ i ] ) > t ) { ok = false ; break ; } } if ( ok ) { r = t ; } else { l = t ; } } out . println ( \" Case ▁ # \" + test + \" : ▁ \" + Math . round ( l + r ) * 0.5 ) ; } } public Scanner in ; public PrintWriter out ; B ( ) throws IOException { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; } void close ( ) throws IOException { out . close ( ) ; } void check ( boolean f , String msg ) { if ( ! f ) { out . close ( ) ; throw new RuntimeException ( msg ) ; } } public void run ( ) { try { solve ( ) ; close ( ) ; } catch ( Exception e ) { e . printStackTrace ( out ) ; out . flush ( ) ; throw new RuntimeException ( e ) ; } } public static void main ( String [ ] args ) throws IOException { new Thread ( new B ( ) ) . start ( ) ; } }" ]
[ "fp = open ( ' B - large . in ' , ' r ' ) NEW_LINE n = int ( fp . next ( ) ) NEW_LINE def max_sum_subsequence ( seq ) : NEW_LINE INDENT maxsofar = 0 NEW_LINE maxendinghere = 0 NEW_LINE for s in seq : NEW_LINE INDENT maxendinghere = max ( maxendinghere + s , 0 ) NEW_LINE maxsofar = max ( maxsofar , maxendinghere ) NEW_LINE DEDENT return maxsofar NEW_LINE DEDENT case = 1 NEW_LINE for line in fp : NEW_LINE INDENT result = 0 NEW_LINE npoints , dist = [ int ( x ) for x in line . strip ( ) . split ( ) ] NEW_LINE points = [ ] NEW_LINE nvend = 0 NEW_LINE for x in range ( npoints ) : NEW_LINE INDENT line = [ int ( x ) for x in fp . next ( ) . strip ( ) . split ( ) ] NEW_LINE nvend += line [ 1 ] NEW_LINE for y in range ( line [ 1 ] ) : NEW_LINE INDENT points . append ( line [ 0 ] ) NEW_LINE DEDENT DEDENT totaldist = dist * ( nvend - 1 ) NEW_LINE points . sort ( ) NEW_LINE dists = [ ] NEW_LINE for x in range ( len ( points ) - 1 ) : NEW_LINE INDENT dists . append ( dist - ( points [ x + 1 ] - points [ x ] ) ) NEW_LINE DEDENT result = max_sum_subsequence ( dists ) / 2. NEW_LINE print ' Case ▁ # % d : ▁ % .6f ' % ( case , result ) NEW_LINE case += 1 NEW_LINE DEDENT", "import sys NEW_LINE NAME = None NEW_LINE def ok ( points , time , D ) : NEW_LINE INDENT prev = None NEW_LINE for p in points : NEW_LINE INDENT x , cnt = p [ 0 ] , p [ 1 ] NEW_LINE minX = x - time NEW_LINE if prev is not None : NEW_LINE INDENT minX = max ( minX , prev + D ) NEW_LINE DEDENT next = minX + D * ( cnt - 1 ) NEW_LINE if abs ( x - next ) > time : NEW_LINE INDENT return False NEW_LINE DEDENT prev = next NEW_LINE DEDENT return True NEW_LINE DEDENT def getMagicWord ( ) : NEW_LINE INDENT numPoints = nextToken ( int ) NEW_LINE D = nextToken ( int ) * 2 NEW_LINE p = [ ] NEW_LINE pMin = 1000000 NEW_LINE pMax = - pMin NEW_LINE n = 0 NEW_LINE for i in range ( numPoints ) : NEW_LINE INDENT x = nextToken ( int ) * 2 NEW_LINE cnt = nextToken ( int ) NEW_LINE p . append ( ( x , cnt ) ) NEW_LINE DEDENT p . sort ( key = lambda x : x [ 0 ] ) NEW_LINE L , R = - 1 , 10 ** 14 NEW_LINE while R - L > 1 : NEW_LINE INDENT K = ( L + R ) // 2 NEW_LINE if ok ( p , K , D ) : NEW_LINE INDENT R = K NEW_LINE DEDENT else : NEW_LINE INDENT L = K NEW_LINE DEDENT DEDENT return \" % .1f \" % ( R / 2 ) NEW_LINE DEDENT def nextToken ( func = None ) : NEW_LINE INDENT res = \" \" NEW_LINE while fin : NEW_LINE INDENT c = fin . read ( 1 ) NEW_LINE if c . isspace ( ) : NEW_LINE INDENT break NEW_LINE DEDENT res += c NEW_LINE DEDENT if func : NEW_LINE INDENT return func ( res ) NEW_LINE DEDENT else : NEW_LINE INDENT return res NEW_LINE DEDENT DEDENT def nextLine ( ) : NEW_LINE INDENT if fin : NEW_LINE INDENT return fin . readline ( ) NEW_LINE DEDENT else : NEW_LINE INDENT return \" \" NEW_LINE DEDENT DEDENT if NAME : NEW_LINE INDENT fin , fout = open ( NAME + \" . in \" , \" r \" ) , open ( NAME + \" . out \" , \" w \" ) NEW_LINE DEDENT else : NEW_LINE INDENT fin , fout = sys . stdin , sys . stdout NEW_LINE DEDENT for testNum in range ( nextToken ( int ) ) : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ % s \" % ( testNum + 1 , getMagicWord ( ) ) ) NEW_LINE DEDENT", "from string import split NEW_LINE import sys NEW_LINE infile = open ( \" large _ input . txt \" , \" r \" ) NEW_LINE outfile = open ( \" large _ output . txt \" , \" w \" ) NEW_LINE trials = int ( infile . readline ( ) ) NEW_LINE for i in xrange ( trials ) : NEW_LINE INDENT nums = [ int ( x ) for x in split ( infile . readline ( ) ) ] NEW_LINE C = nums [ 0 ] NEW_LINE D = nums [ 1 ] NEW_LINE Locs = [ ] NEW_LINE V = [ ] NEW_LINE for j in xrange ( C ) : NEW_LINE INDENT nums = [ int ( x ) for x in split ( infile . readline ( ) ) ] NEW_LINE Locs . append ( nums [ 0 ] ) NEW_LINE V . append ( nums [ 1 ] ) NEW_LINE DEDENT sums = [ [ 0 for x in xrange ( C ) ] for y in xrange ( C ) ] NEW_LINE for x in xrange ( C ) : NEW_LINE INDENT sums [ x ] [ x ] = V [ x ] NEW_LINE DEDENT for j in xrange ( C ) : NEW_LINE INDENT for k in xrange ( j + 1 , C ) : NEW_LINE INDENT sums [ j ] [ k ] = sums [ j ] [ k - 1 ] + sums [ k ] [ k ] NEW_LINE DEDENT DEDENT best = - 1 NEW_LINE for j in xrange ( C ) : NEW_LINE INDENT for k in xrange ( j , C ) : NEW_LINE INDENT vendors = sums [ j ] [ k ] NEW_LINE minspread = ( vendors - 1.0 ) * D NEW_LINE currspread = float ( Locs [ k ] - Locs [ j ] ) NEW_LINE maxtime = ( minspread - currspread ) / 2.0 NEW_LINE if maxtime > best : NEW_LINE INDENT best = maxtime NEW_LINE DEDENT DEDENT DEDENT s = \" Case ▁ # % d : ▁ % f \\n \" % ( ( i + 1 ) , best ) NEW_LINE outfile . write ( s ) NEW_LINE print s NEW_LINE DEDENT infile . close ( ) NEW_LINE outfile . close ( ) NEW_LINE", "class empty : pass ; NEW_LINE def check ( C , D , V , t ) : NEW_LINE INDENT p = - ( 10 ** 100 ) NEW_LINE for v in V : NEW_LINE INDENT w = D * v . V NEW_LINE r = t - D * ( v . V - 1 ) / 2 NEW_LINE if r < 0 or p + w / 2 - v . P > r : NEW_LINE INDENT return False NEW_LINE DEDENT p = max ( v . P - r + w / 2 , p + w ) NEW_LINE DEDENT return True NEW_LINE DEDENT T = input ( ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT C , D = map ( int , raw_input ( ) . split ( ) ) NEW_LINE D *= 2 NEW_LINE V = [ ] NEW_LINE for i in range ( C ) : NEW_LINE INDENT t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE V += [ empty ( ) ] NEW_LINE V [ - 1 ] . P = t [ 0 ] * 2 NEW_LINE V [ - 1 ] . V = t [ 1 ] NEW_LINE DEDENT l = 0 NEW_LINE r = 10 ** 100 NEW_LINE while ( r - l > 1 ) : NEW_LINE INDENT m = ( l + r ) / 2 NEW_LINE if check ( C , D , V , m ) : NEW_LINE INDENT r = m NEW_LINE DEDENT else : NEW_LINE INDENT l = m NEW_LINE DEDENT DEDENT if check ( C , D , V , 0 ) : NEW_LINE INDENT r = 0 NEW_LINE DEDENT print \" Case ▁ # % s : ▁ % .1f \" % ( case , r * 0.5 ) NEW_LINE DEDENT", "import sys , re , string , math NEW_LINE ssr = sys . stdin . readline NEW_LINE ssw = sys . stdout . write NEW_LINE D = - 99 NEW_LINE def comb ( L , x ) : NEW_LINE INDENT if not L : NEW_LINE INDENT return [ x ] NEW_LINE DEDENT ( p1 , v1 , t1 ) = L [ - 1 ] NEW_LINE ( p2 , v2 , t2 ) = x NEW_LINE v3 = v1 + v2 NEW_LINE if ( p2 - p1 ) < 0.5 * D * v3 : NEW_LINE INDENT m = 0.5 * D * v3 - ( p2 - p1 ) NEW_LINE if t1 < t2 : NEW_LINE INDENT d = t2 - t1 NEW_LINE mm = max ( 0 , 0.5 * ( m - d ) ) NEW_LINE t3 = t2 + mm NEW_LINE p3 = p2 + mm - 0.5 * D * v1 NEW_LINE DEDENT else : NEW_LINE INDENT d = t1 - t2 NEW_LINE mm = max ( 0 , 0.5 * ( m - d ) ) NEW_LINE t3 = t1 + mm NEW_LINE p3 = p1 - mm + 0.5 * D * v2 NEW_LINE DEDENT L [ - 1 ] = ( p3 , v3 , t3 ) NEW_LINE DEDENT else : NEW_LINE INDENT L . append ( x ) NEW_LINE DEDENT return L NEW_LINE DEDENT def do_one_case ( cnum ) : NEW_LINE INDENT global D NEW_LINE ( C , D ) = map ( int , ssr ( ) . split ( ) ) NEW_LINE L = [ ] ; NEW_LINE for i in range ( C ) : NEW_LINE INDENT ( P , V ) = map ( int , ssr ( ) . split ( ) ) NEW_LINE t = 0.5 * D * ( V - 1 ) NEW_LINE L . append ( ( 1.0 * P , V , t ) ) NEW_LINE DEDENT n = C + 1 NEW_LINE while len ( L ) < n : NEW_LINE INDENT n = len ( L ) NEW_LINE L = reduce ( comb , L , [ ] ) NEW_LINE DEDENT t = max ( [ t for ( P , V , t ) in L ] ) NEW_LINE print \" Case ▁ # % d : ▁ % .14g \" % ( cnum , t ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N = int ( ssr ( ) . strip ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT do_one_case ( i + 1 ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_10_22
[ "import java . io . * ; import java . math . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( \" Main . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( \" Main . out \" ) ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; int B = in . nextInt ( ) ; int T = in . nextInt ( ) ; int [ ] x = new int [ n ] ; int [ ] v = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) x [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) v [ i ] = in . nextInt ( ) ; boolean [ ] can = new boolean [ n ] ; int z = 0 ; for ( int i = 0 ; i < n ; i ++ ) { can [ i ] = x [ i ] + v [ i ] * T >= B ; if ( can [ i ] ) z ++ ; } if ( z < k ) { out . println ( \" IMPOSSIBLE \" ) ; continue ; } int ans = 0 ; z = 0 ; for ( int i = n - 1 ; i >= 0 && k > 0 ; i -- ) if ( can [ i ] ) { ans += z ; k -- ; } else z ++ ; out . println ( ans ) ; } out . close ( ) ; } }", "import java . io . File ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . PrintStream ; import java . util . Scanner ; public class B extends AbstractCodeJamSolver { int n , k , b , t ; int [ ] x = new int [ 50 ] ; int [ ] v = new int [ 50 ] ; void input ( ) { n = in . nextInt ( ) ; k = in . nextInt ( ) ; b = in . nextInt ( ) ; t = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) x [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) v [ i ] = in . nextInt ( ) ; } public void solve ( ) { int casen = in . nextInt ( ) ; for ( int casei = 1 ; casei <= casen ; casei ++ ) { input ( ) ; int pass = 0 ; int nopass = 0 ; int swap = 0 ; for ( int i = n - 1 ; i >= 0 && pass < k ; i -- ) { if ( v [ i ] * t >= b - x [ i ] ) { pass ++ ; swap += nopass ; } else { nopass ++ ; } } out . print ( \" Case ▁ # \" + casei + \" : ▁ \" ) ; if ( pass >= k ) { out . println ( swap ) ; } else { out . println ( \" IMPOSSIBLE \" ) ; } } } static public void main ( String [ ] args ) throws IOException { new B ( ) . launch ( \" B . txt \" ) ; } } abstract class AbstractCodeJamSolver { protected Scanner in ; protected PrintStream out = System . out ; abstract public void solve ( ) ; protected void print ( Object o ) { out . print ( o ) ; } protected void println ( ) { out . println ( ) ; } protected void println ( Object o ) { out . println ( o ) ; } protected void printf ( String f , Object ... o ) { out . format ( f , o ) ; } final public void launch ( String inputFileName ) throws FileNotFoundException { in = new Scanner ( new File ( inputFileName ) ) ; solve ( ) ; } }", "import java . util . * ; import java . io . * ; public class R1B { public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( new File ( \" B - large . in \" ) ) ; PrintStream out = new PrintStream ( new File ( \" B - large . out \" ) ) ; int cas = in . nextInt ( ) ; for ( int iii = 0 ; iii < cas ; iii ++ ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int B = in . nextInt ( ) ; int T = in . nextInt ( ) ; int pos [ ] = new int [ N ] ; int speed [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) pos [ i ] = B - in . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) speed [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) pos [ i ] = ( ( pos [ i ] - 1 ) / speed [ i ] ) + 1 ; int count = 0 ; int seen = 0 ; int done = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( pos [ i ] > T ) { seen ++ ; } else { count += seen ; done ++ ; if ( done == K ) break ; } } out . println ( \" Case ▁ # \" + ( iii + 1 ) + \" : ▁ \" + ( done >= K ? \" \" + count : \" IMPOSSIBLE \" ) ) ; } out . close ( ) ; } }", "import java . util . * ; import java . io . * ; import java . math . * ; public class Solution { public void doMain ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( \" input . txt \" ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( \" output . txt \" ) ) ; int caseCnt = sc . nextInt ( ) ; long time = System . currentTimeMillis ( ) ; for ( int caseNum = 1 ; caseNum <= caseCnt ; caseNum ++ ) { pw . print ( \" Case ▁ # \" + caseNum + \" : ▁ \" ) ; int N = sc . nextInt ( ) , K = sc . nextInt ( ) ; long B = sc . nextLong ( ) , T = sc . nextInt ( ) ; long [ ] X = new long [ N ] ; long [ ] V = new long [ N ] ; boolean [ ] can = new boolean [ N ] ; for ( int i = 0 ; i < N ; i ++ ) X [ i ] = sc . nextLong ( ) ; for ( int i = 0 ; i < N ; i ++ ) { V [ i ] = sc . nextLong ( ) ; can [ i ] = X [ i ] + T * V [ i ] >= B ; } int good = 0 ; int swaps = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) if ( can [ i ] && good < K ) { good ++ ; for ( int j = i + 1 ; j < N ; j ++ ) if ( ! can [ j ] ) swaps ++ ; } if ( good < K ) pw . println ( \" IMPOSSIBLE \" ) ; else pw . println ( swaps ) ; System . out . println ( \" Finished ▁ testcase ▁ \" + caseNum + \" , ▁ time ▁ = ▁ \" + ( System . currentTimeMillis ( ) - time ) ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) throws Exception { ( new Solution ( ) ) . doMain ( ) ; } }", "package round1 ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( B . class . getSimpleName ( ) + \" . in \" ) ) ; PrintWriter out = new PrintWriter ( new File ( B . class . getSimpleName ( ) + \" . out \" ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new B ( ) . solve ( in ) ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; int b = in . nextInt ( ) ; int t = in . nextInt ( ) ; int [ ] x = new int [ n ] ; int [ ] v = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = in . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = in . nextInt ( ) ; } boolean [ ] z = new boolean [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { z [ i ] = x [ i ] + v [ i ] * t >= b ; } int [ ] q = new int [ n ] ; int m = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( z [ i ] ) { q [ m ++ ] = i ; } } if ( m < k ) return \" IMPOSSIBLE \" ; int s = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int j = n - i - 1 ; s += ( j - q [ i ] ) ; } return \" \" + s ; } }" ]
[ "import sys NEW_LINE C = int ( sys . stdin . readline ( ) ) NEW_LINE for c in xrange ( C ) : NEW_LINE INDENT N , K , B , T = [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE X = [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE V = [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE if K == 0 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ 0\" % ( c + 1 ) NEW_LINE continue NEW_LINE DEDENT good = [ ] NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT if V [ i ] * T >= B - X [ i ] : NEW_LINE INDENT good . append ( i ) NEW_LINE DEDENT DEDENT if len ( good ) < K : NEW_LINE INDENT print \" Case ▁ # % d : ▁ IMPOSSIBLE \" % ( c + 1 ) NEW_LINE continue NEW_LINE DEDENT good = good [ len ( good ) - K : ] NEW_LINE G = 0 NEW_LINE for g in xrange ( 1 , len ( good ) ) : NEW_LINE INDENT G += g * ( good [ g ] - good [ g - 1 ] - 1 ) NEW_LINE DEDENT G += ( N - good [ - 1 ] - 1 ) * len ( good ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( c + 1 , G ) NEW_LINE DEDENT", "import sys NEW_LINE def line ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) [ : - 1 ] NEW_LINE DEDENT def readList ( ) : NEW_LINE INDENT return map ( eval , line ( ) . split ( ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT numberOfCases = eval ( line ( ) ) NEW_LINE for caseNumber in range ( numberOfCases ) : NEW_LINE INDENT N , K , B , T = readList ( ) NEW_LINE X = readList ( ) NEW_LINE V = readList ( ) NEW_LINE makesIt = [ ( B - X [ i ] + V [ i ] - 1 ) / V [ i ] <= T for i in range ( N ) ] NEW_LINE alreadyThere = 0 NEW_LINE while len ( makesIt ) > 0 and makesIt [ - 1 ] : NEW_LINE INDENT alreadyThere += 1 NEW_LINE makesIt . pop ( - 1 ) NEW_LINE DEDENT needed = 0 NEW_LINE i = len ( makesIt ) - 1 NEW_LINE while i >= 0 and alreadyThere < K : NEW_LINE INDENT if makesIt [ i ] : NEW_LINE INDENT needed += len ( makesIt ) - i - 1 NEW_LINE makesIt . pop ( i ) NEW_LINE alreadyThere += 1 NEW_LINE DEDENT else : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT DEDENT print \" Case ▁ # \" + str ( caseNumber + 1 ) + \" : ▁ \" + ( str ( needed ) . replace ( ' L ' , ' ' ) if alreadyThere >= K else ' IMPOSSIBLE ' ) NEW_LINE DEDENT DEDENT", "def B ( inpfile ) : NEW_LINE INDENT fin = open ( inpfile , ' r ' ) NEW_LINE fout = open ( inpfile + ' . out ' , ' w ' ) NEW_LINE CNT = int ( fin . readline ( ) ) NEW_LINE for iCNT in range ( CNT ) : NEW_LINE INDENT numbers = map ( int , fin . readline ( ) . rstrip ( ' \\n ' ) . split ( ' ▁ ' ) ) NEW_LINE N = numbers [ 0 ] NEW_LINE K = numbers [ 1 ] NEW_LINE B = numbers [ 2 ] NEW_LINE T = numbers [ 3 ] NEW_LINE X = map ( int , fin . readline ( ) . rstrip ( ' \\n ' ) . split ( ' ▁ ' ) ) NEW_LINE V = map ( int , fin . readline ( ) . rstrip ( ' \\n ' ) . split ( ' ▁ ' ) ) NEW_LINE X . reverse ( ) NEW_LINE V . reverse ( ) NEW_LINE OnTime = 0 NEW_LINE Switches = 0 NEW_LINE Obstacles = 0 NEW_LINE for iN in xrange ( N ) : NEW_LINE INDENT if B - X [ iN ] <= V [ iN ] * T : NEW_LINE INDENT OnTime += 1 NEW_LINE Switches += Obstacles NEW_LINE DEDENT else : NEW_LINE INDENT Obstacles += 1 NEW_LINE DEDENT if OnTime == K : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( OnTime < K ) : NEW_LINE INDENT result = ' IMPOSSIBLE ' NEW_LINE DEDENT else : NEW_LINE INDENT result = str ( Switches ) NEW_LINE DEDENT text = ' Case ▁ # ' + str ( iCNT + 1 ) + ' : ▁ ' + result NEW_LINE print text NEW_LINE fout . write ( text + ' \\n ' ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT B ( ' . . \\\\test\\\\B - large . in ' ) ; NEW_LINE DEDENT", "import fileinput NEW_LINE def main ( ) : NEW_LINE INDENT reader = fileinput . input ( ) NEW_LINE trials = int ( reader . next ( ) ) NEW_LINE for t in range ( 1 , trials + 1 ) : NEW_LINE INDENT result = trial ( reader ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( t , result ) NEW_LINE DEDENT DEDENT def ints ( reader ) : NEW_LINE INDENT return [ int ( k ) for k in reader . next ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def trial ( reader ) : NEW_LINE INDENT n , k , b , t = ints ( reader ) NEW_LINE x = ints ( reader ) NEW_LINE v = ints ( reader ) NEW_LINE times = [ 0 ] * len ( x ) NEW_LINE for i in range ( len ( x ) ) : NEW_LINE INDENT times [ i ] = ( b - x [ i ] ) / float ( v [ i ] ) - t NEW_LINE DEDENT ok , n = swaps ( times , k ) NEW_LINE return n if ok else ' IMPOSSIBLE ' NEW_LINE DEDENT def swaps ( times , k ) : NEW_LINE INDENT if k == 0 : return True , 0 NEW_LINE i = lastfinisher ( times ) NEW_LINE if i < 0 : return False , 0 NEW_LINE cut = times [ : i ] + times [ i + 1 : ] NEW_LINE ok , n = swaps ( cut , k - 1 ) NEW_LINE return ok , n + len ( times ) - i - 1 NEW_LINE DEDENT def lastfinisher ( times ) : NEW_LINE INDENT for i in reversed ( range ( len ( times ) ) ) : NEW_LINE INDENT if times [ i ] <= 0 : return i NEW_LINE DEDENT return - 1 NEW_LINE DEDENT main ( ) NEW_LINE", "tn = int ( raw_input ( ) ) NEW_LINE def solve ( a , k ) : NEW_LINE INDENT cnt = 0 NEW_LINE for x in reversed ( a ) : NEW_LINE INDENT if x == 1 : NEW_LINE INDENT k -= 1 NEW_LINE if k == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT cnt += k NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT for loop in xrange ( tn ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % ( loop + 1 ) , NEW_LINE N , K , B , T = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE X = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE V = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE C = [ ] NEW_LINE cnt = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT if X [ i ] + V [ i ] * T >= B : NEW_LINE INDENT cnt += 1 NEW_LINE C . append ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT C . append ( 0 ) NEW_LINE DEDENT DEDENT if cnt >= K : NEW_LINE INDENT print solve ( C , K ) NEW_LINE DEDENT else : NEW_LINE INDENT print ' IMPOSSIBLE ' NEW_LINE DEDENT DEDENT" ]
codejam_12_43
[ "import java . util . Random ; import java . util . Scanner ; public class C { static Scanner sc = new Scanner ( System . in ) ; static class Solver { int N ; int [ ] x ; void solve ( ) { N = sc . nextInt ( ) ; x = new int [ N - 1 ] ; for ( int i = 0 ; i < N - 1 ; ++ i ) { x [ i ] = sc . nextInt ( ) - 1 ; } for ( int i = 0 ; i < N - 1 ; ++ i ) { for ( int j = 0 ; j < i ; ++ j ) { if ( x [ j ] > i && x [ j ] < x [ i ] ) { System . out . println ( \" Impossible \" ) ; return ; } } } int [ ] h = new int [ N ] ; Random rand = new Random ( ) ; while ( true ) { for ( int i = 0 ; i < N ; ++ i ) { h [ i ] = rand . nextInt ( 100000000 + 1 ) ; } boolean success = true ; for ( int i = 0 ; i < N - 1 ; ++ i ) { double slopeMax = Integer . MIN_VALUE ; double mi = 0 ; for ( int j = i + 1 ; j < N ; ++ j ) { double slope = 1.0 * ( h [ j ] - h [ i ] ) / ( j - i ) ; if ( slope > slopeMax ) { slopeMax = slope ; mi = j ; } } if ( mi != x [ i ] ) { success = false ; break ; } } if ( success ) { for ( int i = 0 ; i < N ; ++ i ) { System . out . print ( h [ i ] ) ; if ( i != N - 1 ) { System . out . print ( \" ▁ \" ) ; } } System . out . println ( ) ; return ; } } } } public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; Solver solver = new Solver ( ) ; solver . solve ( ) ; } } }", "import java . util . * ; import java . awt . * ; import java . math . * ; public class C { public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int T = scan . nextInt ( ) ; for ( int ca = 1 ; ca <= T ; ca ++ ) { boolean rtn = false ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n - 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) a [ i ] = scan . nextInt ( ) - 1 ; int TRIALS = 10000000 ; int [ ] h = new int [ n ] ; while ( TRIALS -- > 0 ) { boolean good = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) { double m = - 999999999 ; int max = - 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { double tm = ( double ) ( h [ j ] - h [ i ] ) / ( j - i ) ; if ( tm > m ) { m = tm ; max = j ; } } if ( max != a [ i ] ) { good = false ; h [ a [ i ] ] ++ ; break ; } } if ( good ) break ; } System . out . print ( \" Case ▁ # \" + ca + \" : \" ) ; if ( TRIALS <= 0 ) System . out . println ( \" ▁ Impossible \" ) ; else { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( \" ▁ \" + h [ i ] ) ; System . out . println ( ) ; } } } }" ]
[ "import math NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 3000 ) NEW_LINE testcases = int ( raw_input ( ) ) NEW_LINE n = None NEW_LINE h = None NEW_LINE output = None NEW_LINE def recurse ( a , b , i , incl ) : NEW_LINE INDENT if a == b : NEW_LINE INDENT return True NEW_LINE DEDENT cont = 1 NEW_LINE j = a NEW_LINE for k in range ( a , b ) : NEW_LINE INDENT if h [ k ] <= k or h [ k ] > b : NEW_LINE INDENT return False NEW_LINE DEDENT if h [ k ] == b : NEW_LINE INDENT output [ k ] = int ( output [ b ] - math . ceil ( incl * ( b - k ) ) - cont ) NEW_LINE cont += 1 NEW_LINE if not recurse ( j , k , i + 1 , float ( output [ b ] - output [ k ] ) / ( b - k ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT j = k + 1 NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT for tc in range ( 1 , testcases + 1 ) : NEW_LINE INDENT n = int ( raw_input ( ) ) NEW_LINE h = map ( lambda a : int ( a ) - 1 , raw_input ( ) . split ( ) ) NEW_LINE output = [ 0 ] * n NEW_LINE output [ n - 1 ] = 1000000000 NEW_LINE if recurse ( 0 , n - 1 , 1 , 0 ) : NEW_LINE INDENT mini = min ( output ) NEW_LINE output = map ( lambda a : a - mini , output ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( tc , ' ▁ ' . join ( map ( str , output ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print \" Case ▁ # % d : ▁ Impossible \" % tc NEW_LINE DEDENT DEDENT", "testCount = int ( raw_input ( ) ) NEW_LINE for testIndex in range ( testCount ) : NEW_LINE INDENT ans = \" Case ▁ # \" + str ( testIndex + 1 ) + \" : ▁ \" NEW_LINE n = int ( raw_input ( ) ) NEW_LINE see = [ int ( x ) - 1 for x in raw_input ( ) . split ( \" ▁ \" ) ] NEW_LINE m = [ n - 1 ] * n NEW_LINE cm = 0 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if i >= m [ cm ] : NEW_LINE INDENT cm -= 1 NEW_LINE DEDENT if see [ i ] > m [ cm ] : NEW_LINE INDENT ans += \" Impossible \" NEW_LINE break NEW_LINE DEDENT if see [ i ] < m [ cm ] : NEW_LINE INDENT cm += 1 NEW_LINE m [ cm ] = see [ i ] NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT height = [ 0 ] * n NEW_LINE count = [ - 1 ] * n NEW_LINE for i in see : NEW_LINE INDENT count [ i ] += 1 NEW_LINE DEDENT angle = [ 0 ] * n NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT angle [ i ] = count [ see [ i ] ] + angle [ see [ i ] ] NEW_LINE count [ see [ i ] ] -= 1 NEW_LINE height [ i ] = ( see [ i ] - i ) * angle [ i ] + height [ see [ i ] ] NEW_LINE DEDENT m = max ( height ) NEW_LINE for i in height : NEW_LINE INDENT ans += str ( m - i ) + \" ▁ \" NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT", "import random NEW_LINE def check ( heights , hf ) : NEW_LINE INDENT for i in range ( len ( hf ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( hf ) + 1 ) : NEW_LINE INDENT akt = hf [ i ] - 1 NEW_LINE if j != akt : NEW_LINE INDENT x1 = j - i NEW_LINE y1 = heights [ j ] - heights [ i ] NEW_LINE x2 = akt - i NEW_LINE y2 = heights [ akt ] - heights [ i ] NEW_LINE if x1 * y2 - x2 * y1 <= 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT DEDENT return True NEW_LINE DEDENT def generate ( n ) : NEW_LINE INDENT return [ random . randint ( 0 , 400 ) for i in range ( n ) ] NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for tt in range ( 1 , t + 1 ) : NEW_LINE INDENT n = int ( raw_input ( ) ) NEW_LINE line = raw_input ( ) NEW_LINE highest_from = [ int ( i ) for i in line . strip ( ) . split ( ) ] NEW_LINE w = False NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , highest_from [ i ] - 1 ) : NEW_LINE INDENT if highest_from [ j ] > highest_from [ i ] : NEW_LINE INDENT w = True NEW_LINE DEDENT DEDENT DEDENT if w : NEW_LINE INDENT print \" Case ▁ # { } : ▁ Impossible \" . format ( tt ) NEW_LINE DEDENT else : NEW_LINE INDENT w = False NEW_LINE heights = [ ] NEW_LINE while not w : NEW_LINE INDENT heights = generate ( n ) NEW_LINE w = check ( heights , highest_from ) NEW_LINE DEDENT res = \" Case ▁ # { } : ▁ \" . format ( tt ) NEW_LINE for i in heights : NEW_LINE INDENT res += str ( i ) + \" ▁ \" NEW_LINE DEDENT print res NEW_LINE DEDENT DEDENT", "import sys NEW_LINE import random NEW_LINE sys . setrecursionlimit ( 3000 ) NEW_LINE def bar ( a , nx , x ) : NEW_LINE INDENT return [ y - nx for y in a [ nx : x ] ] NEW_LINE DEDENT def foo2 ( a , level , height ) : NEW_LINE INDENT picks = [ 0 ] NEW_LINE i = 0 NEW_LINE n = len ( a ) NEW_LINE while True : NEW_LINE INDENT if a [ i ] == n : NEW_LINE INDENT break NEW_LINE DEDENT if a [ i ] > n : NEW_LINE INDENT return None NEW_LINE DEDENT picks . append ( a [ i ] ) NEW_LINE i = a [ i ] NEW_LINE DEDENT picks . append ( n ) NEW_LINE res = [ ] NEW_LINE nx = 0 NEW_LINE for x in picks : NEW_LINE INDENT if x == nx : NEW_LINE INDENT res . append ( height - level * ( n - x ) ) NEW_LINE DEDENT else : NEW_LINE INDENT t = foo2 ( bar ( a , nx , x ) , level + 1 , height - level * ( n - x ) ) NEW_LINE if t is None : NEW_LINE INDENT return None NEW_LINE DEDENT res += t NEW_LINE DEDENT nx = x + 1 NEW_LINE DEDENT return res NEW_LINE DEDENT def foo ( ifile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE a = [ int ( x ) - 1 for x in ifile . readline ( ) . split ( ) ] NEW_LINE level = 0 NEW_LINE height = 1000000 NEW_LINE res = foo2 ( a , level , height ) NEW_LINE if res is None : NEW_LINE INDENT return \" Impossible \" NEW_LINE DEDENT else : NEW_LINE INDENT return \" ▁ \" . join ( [ str ( x ) for x in res ] ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT ifile = sys . stdin NEW_LINE n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % s ' % ( i + 1 , foo ( ifile ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "from sys import stdin NEW_LINE import numpy as np NEW_LINE ntest = input ( ) NEW_LINE for test in range ( ntest ) : NEW_LINE INDENT n = input ( ) NEW_LINE x = np . array ( [ int ( i ) - 1 for i in stdin . readline ( ) . strip ( ) . split ( ) ] ) NEW_LINE y = np . zeros ( n , np . int ) NEW_LINE fixed = np . zeros ( n , np . bool ) NEW_LINE possible = True NEW_LINE for i in xrange ( n - 1 ) : NEW_LINE INDENT fixed [ x [ i ] ] = True NEW_LINE if True in fixed [ i + 1 : x [ i ] ] : NEW_LINE INDENT possible = False NEW_LINE break NEW_LINE DEDENT for j in xrange ( i + 1 , x [ i ] ) : NEW_LINE INDENT y [ j ] = y [ j ] - x [ i ] + j NEW_LINE DEDENT DEDENT y = y - y . min ( ) NEW_LINE result = ' ▁ ' . join ( [ ' % d ' % i for i in y ] ) if possible else ' Impossible ' NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( test + 1 , result ) NEW_LINE DEDENT" ]
codejam_15_04
[ "package cj2015 . qr ; import java . io . * ; import java . util . * ; public class D { Scanner sc ; PrintWriter pw ; int X , R , C ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : \" D - large \" ; try { new D ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + \" . in \" ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + \" . out \" ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; System . out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; solve ( ) ; } System . out . println ( \" Finished . \" ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { X = sc . nextInt ( ) ; R = sc . nextInt ( ) ; C = sc . nextInt ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } public void solve ( ) { if ( canFill ( X , R , C ) ) println ( \" GABRIEL \" ) ; else println ( \" RICHARD \" ) ; } public boolean canFill ( int x , int r , int c ) { if ( r > c ) { int temp = r ; r = c ; c = temp ; } if ( x >= 7 ) return false ; if ( ( r * c ) % x != 0 ) return false ; if ( x > c || ( x + 1 ) / 2 > r ) return false ; if ( x <= 3 ) return true ; if ( ( x + 1 ) / 2 == r ) if ( x == 4 || x == 6 || ( x == 5 && c == 5 ) ) return false ; return true ; } }", "import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Scanner ; public class D { static final String FILENAME = \" D - large \" ; static final String IN = FILENAME + \" . in \" ; static final String OUT = FILENAME + \" . out \" ; Scanner sc ; BufferedWriter out ; private void solve ( ) throws IOException { int x = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; if ( x >= 7 || x > Math . max ( r , c ) || ( x + 1 ) / 2 > Math . min ( r , c ) || ( r * c ) % x != 0 || ( ( x + 1 ) / 2 == Math . min ( r , c ) && ( x == 4 || ( x == 5 && Math . max ( r , c ) < 6 ) || x == 6 ) ) ) { out . write ( \" RICHARD \" ) ; } else { out . write ( \" GABRIEL \" ) ; } out . newLine ( ) ; out . flush ( ) ; } private void run ( ) throws IOException { sc = new Scanner ( new File ( IN ) ) ; out = new BufferedWriter ( new FileWriter ( OUT ) ) ; int t = sc . nextInt ( ) ; for ( int i = 1 ; i <= t ; i ++ ) { out . write ( \" Case ▁ # \" + i + \" : ▁ \" ) ; solve ( ) ; } sc . close ( ) ; out . close ( ) ; } public static void main ( String args [ ] ) throws Exception { new D ( ) . run ( ) ; } }", "import java . io . File ; import java . io . PrintStream ; import java . util . Scanner ; public class D_Large { static final Boolean SAMPLE = false ; static final String PROBLEM = \" D \" ; static final String INPUT = \" large \" ; static final String ID = \"0\" ; static final String PATH = \" / Users / wangkai / Documents / codejam - commandline - 1.2 - beta1 / source / \" ; public static void main ( String [ ] args ) throws Throwable { Scanner in = SAMPLE ? new Scanner ( System . in ) : new Scanner ( new File ( PATH + PROBLEM + \" - \" + INPUT + \" - \" + ID + \" . in \" ) ) ; PrintStream out = SAMPLE ? System . out : new PrintStream ( PATH + PROBLEM + \" - \" + INPUT + \" - \" + ID + \" . out \" ) ; int test = in . nextInt ( ) ; for ( int t = 1 ; t <= test ; t ++ ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; int omino = in . nextInt ( ) ; int row = in . nextInt ( ) ; int col = in . nextInt ( ) ; boolean firstPlayerWin ; if ( row * col % omino != 0 ) { firstPlayerWin = true ; } else { int minSide = Math . min ( row , col ) ; int maxSide = Math . max ( row , col ) ; if ( omino == 1 ) { firstPlayerWin = false ; } else if ( omino == 2 ) { firstPlayerWin = false ; } else if ( omino == 3 ) { if ( minSide == 1 ) { firstPlayerWin = true ; } else { firstPlayerWin = false ; } } else if ( omino == 4 ) { if ( minSide <= 2 ) { firstPlayerWin = true ; } else { firstPlayerWin = false ; } } else if ( omino == 5 ) { if ( minSide <= 2 ) { firstPlayerWin = true ; } else if ( minSide == 3 ) { if ( maxSide == 5 ) { firstPlayerWin = true ; } else { firstPlayerWin = false ; } } else { firstPlayerWin = false ; } } else if ( omino == 6 ) { if ( minSide <= 2 ) { firstPlayerWin = true ; } else if ( minSide == 3 ) { firstPlayerWin = true ; } else { firstPlayerWin = false ; } } else { firstPlayerWin = true ; } } out . println ( firstPlayerWin ? \" RICHARD \" : \" GABRIEL \" ) ; } out . close ( ) ; in . close ( ) ; System . out . println ( \" finish ! \" ) ; } }", "package gcj2015 . qualif ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoD { public static void main ( final String [ ] args ) { final String base = \" / home / jean / gcj2015 / q / ExoD / \" ; final String input = base + \" b1 . in \" ; final String output = base + \" b1 . out \" ; try { final Scanner sc = new Scanner ( new FileReader ( input ) ) ; final PrintWriter pw = new PrintWriter ( output ) ; final int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( \" Test ▁ case ▁ \" + ( c + 1 ) + \" . . . \" ) ; pw . print ( \" Case ▁ # \" + ( c + 1 ) + \" : ▁ \" ) ; test ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( final FileNotFoundException ex ) { Logger . getLogger ( ExoD . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test ( final Scanner sc , final PrintWriter pw ) { final int X = sc . nextInt ( ) ; final int R = sc . nextInt ( ) ; final int C = sc . nextInt ( ) ; if ( X >= 7 || ( R * C ) % X != 0 ) { pw . print ( \" RICHARD \" ) ; } else { if ( X == 1 || X == 2 || ( X == 3 && ( R != 1 && C != 1 ) ) || ( X == 4 && ( R >= 4 && C > 2 || C >= 4 && R > 2 ) ) || ( X == 5 && ( ( R >= 4 && C >= 4 ) || ( R == 3 && C >= 10 || R >= 10 && C == 3 ) ) ) || ( X == 6 && ( R >= 4 && C >= 4 && ( R >= 6 || C >= 6 ) ) ) ) { pw . print ( \" GABRIEL \" ) ; } else { pw . print ( \" RICHARD \" ) ; } } } }", "import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . util . * ; import java . util . regex . * ; import static java . lang . Math . * ; import static java . lang . System . * ; public class D { boolean solve ( int caseNum ) { int x = in . nextInt ( ) ; int r = in . nextInt ( ) ; int c = in . nextInt ( ) ; int max = max ( r , c ) ; int min = min ( r , c ) ; if ( x >= 7 ) return false ; if ( r * c % x != 0 ) return false ; if ( x > max ) return false ; if ( x > min * 2 ) return false ; if ( x < min * 2 - 1 ) return true ; if ( x <= 2 ) return true ; if ( x == 3 ) { if ( min != 2 ) { debug ( \" x ▁ = = ▁ 3 ▁ & & ▁ min ▁ ! = ▁ 2\" ) ; } return true ; } if ( x == 4 ) { if ( min != 2 ) { debug ( \" x ▁ = = ▁ 4 ▁ & & ▁ min ▁ ! = ▁ 2\" ) ; } return false ; } if ( x == 5 ) { if ( min != 3 ) { debug ( \" x ▁ = = ▁ 5 ▁ & & ▁ min ▁ ! = ▁ 3\" ) ; } return max > 5 ; } if ( x == 6 ) { if ( min != 3 ) { debug ( \" x ▁ = = ▁ 6 ▁ & & ▁ min ▁ ! = ▁ 3\" ) ; } return false ; } debug ( \" never ▁ reach \" ) ; return true ; } Scanner in = new Scanner ( System . in ) ; public D ( ) throws Exception { int caseCount = in . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= caseCount ; caseNum ++ ) { out . printf ( \" Case ▁ # % d : ▁ \" , caseNum ) ; if ( solve ( caseNum ) ) { out . println ( \" GABRIEL \" ) ; } else { out . println ( \" RICHARD \" ) ; } } } public static void main ( String [ ] args ) throws Exception { new D ( ) ; } public static void debug ( Object ... arr ) { System . err . println ( Arrays . deepToString ( arr ) ) ; } }" ]
[ "def winner ( X , S , L ) : NEW_LINE INDENT if S * L % X : return ' RICHARD ' NEW_LINE if X <= 2 : return ' GABRIEL ' NEW_LINE if X >= 7 : return ' RICHARD ' NEW_LINE if L < X : return ' RICHARD ' NEW_LINE if 2 * S <= X : return ' RICHARD ' NEW_LINE if ( X , S , L ) == ( 5 , 3 , 5 ) : NEW_LINE INDENT return ' RICHARD ' NEW_LINE DEDENT return ' GABRIEL ' NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT X , R , C = map ( int , input ( ) . split ( ) ) NEW_LINE print ( \" Case ▁ # { } : ▁ { } \" . format ( case , winner ( X , min ( R , C ) , max ( R , C ) ) ) ) NEW_LINE DEDENT", "import sys NEW_LINE def load_cases ( path ) : NEW_LINE INDENT case_list = [ ] NEW_LINE with open ( path , ' r ' ) as fh : NEW_LINE INDENT case_num = int ( fh . readline ( ) . strip ( \" \\n \" ) ) NEW_LINE for i in range ( 0 , case_num ) : NEW_LINE INDENT case = filter ( None , fh . readline ( ) . strip ( \" \\n \" ) . split ( \" ▁ \" ) ) NEW_LINE case_list . append ( [ int ( item ) for item in case ] ) NEW_LINE DEDENT DEDENT return case_list NEW_LINE DEDENT def calculate_case ( case ) : NEW_LINE INDENT X = case [ 0 ] NEW_LINE R = case [ 1 ] NEW_LINE C = case [ 2 ] NEW_LINE if R > C : NEW_LINE INDENT R = case [ 2 ] NEW_LINE C = case [ 1 ] NEW_LINE DEDENT if ( R * C ) % X != 0 or X >= 7 : NEW_LINE INDENT return False NEW_LINE DEDENT elif X == 1 or X == 2 : NEW_LINE INDENT return True NEW_LINE DEDENT elif X == 3 : NEW_LINE INDENT if R == 1 : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT elif X == 4 : NEW_LINE INDENT if R < 3 : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT elif X == 5 : NEW_LINE INDENT if R < 3 : NEW_LINE INDENT return False NEW_LINE DEDENT elif R == 3 : NEW_LINE INDENT if C == 5 : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT elif X == 6 : NEW_LINE INDENT if R < 4 : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT if len ( sys . argv ) != 3 : NEW_LINE INDENT print ' Usage : ▁ q2 . py ▁ input _ file ▁ output _ file ' NEW_LINE sys . exit ( ) NEW_LINE DEDENT input_file = sys . argv [ 1 ] NEW_LINE output_file = sys . argv [ 2 ] NEW_LINE case_list = load_cases ( input_file ) NEW_LINE with open ( output_file , ' w ' ) as fh : NEW_LINE INDENT case_id = 1 NEW_LINE for case in case_list : NEW_LINE INDENT G_win = calculate_case ( case ) NEW_LINE fh . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( case_id , ' GABRIEL ' if G_win == True else ' RICHARD ' ) ) NEW_LINE case_id += 1 NEW_LINE DEDENT DEDENT DEDENT", "def solve ( X , R , C ) : NEW_LINE INDENT if ( R * C ) % X > 0 : NEW_LINE INDENT return True NEW_LINE DEDENT big = max ( R , C ) NEW_LINE small = min ( R , C ) NEW_LINE if X >= 7 : NEW_LINE INDENT return True NEW_LINE DEDENT if X > big : NEW_LINE INDENT return True NEW_LINE DEDENT if X > 2 * small : NEW_LINE INDENT return True NEW_LINE DEDENT if big == small : NEW_LINE INDENT return False NEW_LINE DEDENT if big == small + 1 : NEW_LINE INDENT return False NEW_LINE DEDENT if big >= small + 2 : NEW_LINE INDENT if X < 2 * small - 1 : NEW_LINE INDENT return False NEW_LINE DEDENT if X == 2 * small - 1 : NEW_LINE INDENT if X == 1 : NEW_LINE INDENT return False NEW_LINE DEDENT if X == 3 : NEW_LINE INDENT return False NEW_LINE DEDENT if X == 5 : NEW_LINE INDENT return big <= 5 NEW_LINE DEDENT DEDENT if X == 2 * small : NEW_LINE INDENT if X == 2 : NEW_LINE INDENT return False NEW_LINE DEDENT if X == 4 : NEW_LINE INDENT return True NEW_LINE DEDENT if X == 6 : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT raise AssertionError ( ) NEW_LINE DEDENT T = input ( ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT ( X , R , C ) = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE s = solve ( X , R , C ) NEW_LINE winner = \" RICHARD \" if s else \" GABRIEL \" NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( t , winner ) NEW_LINE DEDENT", "__author__ = ' Reuben ' NEW_LINE def solution ( dom_size , width , height ) : NEW_LINE INDENT if dom_size >= 7 or width * height % dom_size != 0 or dom_size > max ( width , height ) : NEW_LINE INDENT return \" RICHARD \" NEW_LINE DEDENT if dom_size == 1 or dom_size == 2 : NEW_LINE INDENT return \" GABRIEL \" NEW_LINE DEDENT if dom_size == 3 : NEW_LINE INDENT if height == 1 or width == 1 : NEW_LINE INDENT return \" RICHARD \" NEW_LINE DEDENT else : NEW_LINE INDENT return \" GABRIEL \" NEW_LINE DEDENT DEDENT if dom_size == 4 : NEW_LINE INDENT if ( height <= 2 or width <= 2 ) : NEW_LINE INDENT return \" RICHARD \" NEW_LINE DEDENT else : NEW_LINE INDENT return \" GABRIEL \" NEW_LINE DEDENT DEDENT if dom_size == 5 : NEW_LINE INDENT if ( height <= 2 or width <= 2 ) or ( width == 3 and ( height < 10 or height % 5 != 0 ) ) or ( height == 3 and ( width < 10 or width % 5 != 0 ) ) : NEW_LINE INDENT return \" RICHARD \" NEW_LINE DEDENT else : NEW_LINE INDENT return \" GABRIEL \" NEW_LINE DEDENT DEDENT if dom_size == 6 : NEW_LINE INDENT if ( height <= 3 or width <= 3 ) : NEW_LINE INDENT return \" RICHARD \" NEW_LINE DEDENT else : NEW_LINE INDENT return \" GABRIEL \" NEW_LINE DEDENT DEDENT DEDENT f_in = open ( ' file . in ' ) NEW_LINE f_out = open ( ' file . out ' , ' w ' ) NEW_LINE cases = int ( f_in . readline ( ) ) NEW_LINE for i in range ( 1 , cases + 1 ) : NEW_LINE INDENT line = f_in . readline ( ) . split ( ) NEW_LINE dom_size = int ( line [ 0 ] ) NEW_LINE width = int ( line [ 1 ] ) NEW_LINE height = int ( line [ 2 ] ) NEW_LINE s = solution ( dom_size , width , height ) NEW_LINE f_out . write ( \" Case ▁ # \" + str ( i ) + \" : ▁ \" + s + \" \\n \" ) NEW_LINE DEDENT", "import sys NEW_LINE def solve ( x , r , c ) : NEW_LINE INDENT if ( r * c ) % x != 0 : NEW_LINE INDENT return True NEW_LINE DEDENT if ( r < x ) and ( c < x ) : NEW_LINE INDENT return True NEW_LINE DEDENT if min ( r , c ) * 2 + 1 <= x : NEW_LINE INDENT return True NEW_LINE DEDENT if x < 4 : NEW_LINE INDENT return False NEW_LINE DEDENT if x > 6 : NEW_LINE INDENT return True NEW_LINE DEDENT if x == 4 : NEW_LINE INDENT if min ( r , c ) <= 2 : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if x == 5 : NEW_LINE INDENT if ( min ( r , c ) == 3 ) and ( max ( r , c ) == 5 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if x == 6 : NEW_LINE INDENT if min ( r , c ) == 3 : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT t = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT x , r , c = sys . stdin . readline ( ) . strip ( ) . split ( ) NEW_LINE x = int ( x ) NEW_LINE r = int ( r ) NEW_LINE c = int ( c ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , \" RICHARD \" if solve ( x , r , c ) else \" GABRIEL \" ) NEW_LINE DEDENT" ]
codejam_16_41
[ "import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; static char [ ] cs = { ' P ' , ' R ' , ' S ' } ; static String [ ] [ ] dp = new String [ 3 ] [ 13 ] ; public static void main ( String [ ] args ) { dp [ 0 ] [ 0 ] = \" P \" ; dp [ 1 ] [ 0 ] = \" R \" ; dp [ 2 ] [ 0 ] = \" S \" ; for ( int i = 1 ; i < dp [ 0 ] . length ; ++ i ) { for ( int j = 0 ; j < 3 ; ++ j ) { dp [ j ] [ i ] = dp [ j ] [ i - 1 ] + dp [ ( j + 1 ) % 3 ] [ i - 1 ] ; String o = dp [ ( j + 1 ) % 3 ] [ i - 1 ] + dp [ j ] [ i - 1 ] ; if ( o . compareTo ( dp [ j ] [ i ] ) < 0 ) dp [ j ] [ i ] = o ; } } int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( \" Case ▁ # \" + i + \" : ▁ \" ) ; System . out . println ( solve ( ) ) ; } } static String solve ( ) { int N = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; int P = sc . nextInt ( ) ; int S = sc . nextInt ( ) ; String ret = null ; for ( int i = 0 ; i < 3 ; ++ i ) { int [ ] c = new int [ 3 ] ; for ( char ch : dp [ i ] [ N ] . toCharArray ( ) ) { if ( ch == ' P ' ) c [ 0 ] ++ ; if ( ch == ' R ' ) c [ 1 ] ++ ; if ( ch == ' S ' ) c [ 2 ] ++ ; } if ( c [ 0 ] == P && c [ 1 ] == R && c [ 2 ] == S ) { ret = dp [ i ] [ N ] ; } } return ret == null ? \" IMPOSSIBLE \" : ret ; } }" ]
[ "def solve ( n , r , p , s ) : NEW_LINE INDENT poss = [ ] NEW_LINE for i in \" RPS \" : NEW_LINE INDENT m = lex ( i , n ) NEW_LINE cr = cp = cs = 0 NEW_LINE for j in m : NEW_LINE INDENT if j == ' R ' : NEW_LINE INDENT cr += 1 NEW_LINE DEDENT if j == ' S ' : NEW_LINE INDENT cs += 1 NEW_LINE DEDENT if j == ' P ' : NEW_LINE INDENT cp += 1 NEW_LINE DEDENT DEDENT if ( cr == r and cs == s and cp == p ) : NEW_LINE INDENT poss . append ( m ) NEW_LINE DEDENT DEDENT if ( len ( poss ) == 0 ) : NEW_LINE INDENT return \" IMPOSSIBLE \" NEW_LINE DEDENT return min ( poss ) NEW_LINE DEDENT beats = { \" R \" : \" S \" , \" S \" : \" P \" , \" P \" : \" R \" } NEW_LINE def lex ( c , n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return c NEW_LINE DEDENT p1 = lex ( c , n - 1 ) NEW_LINE p2 = lex ( beats [ c ] , n - 1 ) NEW_LINE if p1 < p2 : NEW_LINE INDENT return p1 + p2 NEW_LINE DEDENT return p2 + p1 NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for cas in xrange ( 1 , t + 1 ) : NEW_LINE INDENT ans = solve ( * map ( int , raw_input ( ) . split ( ) ) ) NEW_LINE print \" Case ▁ # { } : ▁ { } \" . format ( cas , ans ) NEW_LINE DEDENT", "def make ( i , n , cur ) : NEW_LINE INDENT if i == n : NEW_LINE INDENT return cur NEW_LINE DEDENT ret = ' ' NEW_LINE for c in cur : NEW_LINE INDENT a , b = None , None NEW_LINE if c == ' P ' : NEW_LINE INDENT a , b = ' P ' , ' R ' NEW_LINE DEDENT elif c == ' R ' : NEW_LINE INDENT a , b = ' R ' , ' S ' NEW_LINE DEDENT elif c == ' S ' : NEW_LINE INDENT a , b = ' P ' , ' S ' NEW_LINE DEDENT l1 = make ( i + 1 , n , a ) NEW_LINE l2 = make ( i + 1 , n , b ) NEW_LINE if l1 < l2 : NEW_LINE INDENT ret += l1 NEW_LINE ret += l2 NEW_LINE DEDENT else : NEW_LINE INDENT ret += l2 NEW_LINE ret += l1 NEW_LINE DEDENT DEDENT return ret NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , R , P , S = map ( int , raw_input ( ) . split ( ) ) NEW_LINE opt = ' IMPOSSIBLE ' NEW_LINE answers = [ make ( 0 , N , ' R ' ) , make ( 0 , N , ' P ' ) , make ( 0 , N , ' S ' ) , ] NEW_LINE for ans in answers : NEW_LINE INDENT if ans . count ( ' P ' ) == P and ans . count ( ' R ' ) == R and ans . count ( ' S ' ) == S : NEW_LINE INDENT opt = ans NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( t + 1 , opt ) NEW_LINE DEDENT", "import sys NEW_LINE in_file = open ( ' a - large . in ' , ' r ' ) NEW_LINE out_file = open ( ' a . out ' , ' w ' ) NEW_LINE sys . stdin = in_file NEW_LINE sys . stdout = out_file NEW_LINE def calc ( winner ) : NEW_LINE INDENT if winner == ' R ' : NEW_LINE INDENT return ' S ' NEW_LINE DEDENT if winner == ' S ' : NEW_LINE INDENT return ' P ' NEW_LINE DEDENT if winner == ' P ' : NEW_LINE INDENT return ' R ' NEW_LINE DEDENT assert False NEW_LINE DEDENT def check ( n , winner ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return winner NEW_LINE DEDENT other = calc ( winner ) NEW_LINE l = check ( n - 1 , winner ) NEW_LINE r = check ( n - 1 , calc ( winner ) ) NEW_LINE if l < r : NEW_LINE INDENT return l + r NEW_LINE DEDENT else : NEW_LINE INDENT return r + l NEW_LINE DEDENT DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT n , R , P , S = map ( int , raw_input ( ) . split ( ) ) NEW_LINE ans = None NEW_LINE for win in ( ' R ' , ' P ' , ' S ' ) : NEW_LINE INDENT best = check ( n , win ) NEW_LINE if best . count ( ' R ' ) != R or best . count ( ' P ' ) != P or best . count ( ' S ' ) != S : NEW_LINE INDENT continue NEW_LINE DEDENT if ans == None or best < ans : NEW_LINE INDENT ans = best NEW_LINE DEDENT DEDENT if ans == None : NEW_LINE INDENT ans = ' IMPOSSIBLE ' NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % s ' % ( t + 1 , ans ) NEW_LINE DEDENT in_file . close ( ) NEW_LINE out_file . close ( ) NEW_LINE", "def invalid ( n , r , p , s ) : NEW_LINE INDENT N = 1 << n NEW_LINE if max ( r , p , s ) > ( N + 2 ) / 3 : return True NEW_LINE if min ( r , p , s ) < N / 3 : return True NEW_LINE return False NEW_LINE DEDENT def build ( n , r , p , s ) : NEW_LINE INDENT assert not invalid ( n , r , p , s ) NEW_LINE if n == 1 : NEW_LINE INDENT if p > 0 and r > 0 : return ' PR ' NEW_LINE if p > 0 and s > 0 : return ' PS ' NEW_LINE return ' RS ' NEW_LINE DEDENT if p == r > s : NEW_LINE INDENT pl , rl , sl = ( p + 1 ) / 2 , r / 2 , s / 2 NEW_LINE DEDENT elif p == s > r : NEW_LINE INDENT pl , rl , sl = ( p + 1 ) / 2 , r / 2 , s / 2 NEW_LINE DEDENT elif p > r == s : NEW_LINE INDENT pl , rl , sl = p / 2 , ( r + 1 ) / 2 , s / 2 NEW_LINE DEDENT elif r == s > p : NEW_LINE INDENT pl , rl , sl = p / 2 , ( r + 1 ) / 2 , s / 2 NEW_LINE DEDENT elif r > s == p : NEW_LINE INDENT pl , rl , sl = ( p + 1 ) / 2 , r / 2 , s / 2 NEW_LINE DEDENT elif s > r == p : NEW_LINE INDENT pl , rl , sl = ( p + 1 ) / 2 , r / 2 , s / 2 NEW_LINE DEDENT else : NEW_LINE INDENT assert False NEW_LINE DEDENT return build ( n - 1 , rl , pl , sl ) + build ( n - 1 , r - rl , p - pl , s - sl ) NEW_LINE DEDENT _T = int ( raw_input ( ) ) NEW_LINE for _t in range ( 1 , _T + 1 ) : NEW_LINE INDENT n , R , P , S = map ( int , raw_input ( ) . split ( ) ) NEW_LINE if invalid ( n , R , P , S ) : NEW_LINE INDENT res = ' IMPOSSIBLE ' NEW_LINE DEDENT else : NEW_LINE INDENT res = build ( n , R , P , S ) NEW_LINE DEDENT print ' Case ▁ # { } : ▁ { } ' . format ( _t , res ) NEW_LINE DEDENT", "players = { ' R ' : ' RS ' , ' S ' : ' SP ' , ' P ' : ' RP ' } NEW_LINE memo = { } NEW_LINE def gen_tourney ( n , winner ) : NEW_LINE INDENT if ( n , winner ) in memo : NEW_LINE INDENT return memo [ n , winner ] NEW_LINE DEDENT if n == 0 : NEW_LINE INDENT result = winner NEW_LINE DEDENT else : NEW_LINE INDENT t1 = gen_tourney ( n - 1 , players [ winner ] [ 0 ] ) NEW_LINE t2 = gen_tourney ( n - 1 , players [ winner ] [ 1 ] ) NEW_LINE if t1 < t2 : NEW_LINE INDENT result = t1 + t2 NEW_LINE DEDENT else : NEW_LINE INDENT result = t2 + t1 NEW_LINE DEDENT DEDENT memo [ n , winner ] = result NEW_LINE return result NEW_LINE DEDENT from collections import Counter NEW_LINE def solve ( n , r , p , s ) : NEW_LINE INDENT desired_hist = Counter ( { ' R ' : r , ' P ' : p , ' S ' : s } ) NEW_LINE for winner in ' RPS ' : NEW_LINE INDENT t = gen_tourney ( n , winner ) NEW_LINE hist = Counter ( t ) NEW_LINE if all ( hist [ c ] == desired_hist [ c ] for c in ' RPS ' ) : NEW_LINE INDENT return t NEW_LINE DEDENT DEDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE fp = open ( sys . argv [ 1 ] ) NEW_LINE def readline ( ) : NEW_LINE INDENT return fp . readline ( ) . strip ( ) NEW_LINE DEDENT num_cases = int ( readline ( ) ) NEW_LINE for i in xrange ( num_cases ) : NEW_LINE INDENT n , r , p , s = [ int ( x ) for x in readline ( ) . split ( ) ] NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , solve ( n , r , p , s ) ) NEW_LINE DEDENT DEDENT" ]
codejam_08_43
[ "package round2 ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Scanner ; public class GCJProblemC { static String input = \" C - small - attempt0 . in \" , output = \" c . out \" ; public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new File ( input ) ) ; BufferedWriter ps = new BufferedWriter ( new FileWriter ( new File ( output ) ) ) ; int tc = sc . nextInt ( ) ; for ( int test = 1 ; test <= tc ; test ++ ) { int n = sc . nextInt ( ) ; int [ ] x1 = new int [ n ] , x2 = new int [ n ] , x3 = new int [ n ] , p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x1 [ i ] = sc . nextInt ( ) ; x2 [ i ] = sc . nextInt ( ) ; x3 [ i ] = sc . nextInt ( ) ; p [ i ] = sc . nextInt ( ) ; } double smin = 0.000000 , smax = 1000000 ; while ( smax - smin > 1e-8 ) { double mid = smax + smin ; mid /= 2 ; boolean can = true ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) { int dist = Math . abs ( x1 [ i ] - x1 [ j ] ) + Math . abs ( x2 [ i ] - x2 [ j ] ) + Math . abs ( x3 [ i ] - x3 [ j ] ) ; if ( ! ( ( p [ i ] + p [ j ] ) * mid > dist ) ) can = false ; } if ( can ) smax = mid ; else smin = mid ; } String result = \" \" + smin ; ps . write ( \" Case ▁ # \" + test + \" : ▁ \" + result + \" \\n \" ) ; } sc . close ( ) ; ps . close ( ) ; } }", "import java . io . * ; import java . util . Locale ; import java . util . StringTokenizer ; public class C { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new FileReader ( \" C - large . in \" ) ) ; PrintWriter out = new PrintWriter ( \" c . out \" ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 1 ; i <= T ; i ++ ) { int n = Integer . parseInt ( in . readLine ( ) ) ; double [ ] x = new double [ n ] ; double [ ] y = new double [ n ] ; double [ ] z = new double [ n ] ; double [ ] p = new double [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { StringTokenizer tz = new StringTokenizer ( in . readLine ( ) ) ; x [ j ] = Integer . parseInt ( tz . nextToken ( ) ) ; y [ j ] = Integer . parseInt ( tz . nextToken ( ) ) ; z [ j ] = Integer . parseInt ( tz . nextToken ( ) ) ; p [ j ] = Integer . parseInt ( tz . nextToken ( ) ) ; } double l = 0 ; double r = 1e8 ; while ( r > l + 1e-7 ) { double pp = ( l + r ) / 2 ; boolean can = true ; outer : for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { double d = Math . abs ( x [ k ] - x [ j ] ) + Math . abs ( y [ k ] - y [ j ] ) + Math . abs ( z [ k ] - z [ j ] ) ; if ( d > pp * ( p [ k ] + p [ j ] ) ) { can = false ; break outer ; } } } if ( can ) { r = pp ; } else { l = pp ; } } double rr = ( l + r ) / 2 ; out . printf ( Locale . US , \" Case ▁ # % d : ▁ % .6f \\n \" , i , rr ) ; } in . close ( ) ; out . close ( ) ; } }", "import java . io . PrintWriter ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Scanner ; import java . util . Arrays ; public class C { static Scanner in ; static PrintWriter out ; public static void main ( String [ ] args ) throws FileNotFoundException { in = new Scanner ( new File ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new C ( ) . solve ( ) ) ; } out . close ( ) ; } private Object solve ( ) { int n = in . nextInt ( ) ; double [ ] [ ] c = new double [ 3 ] [ n ] ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { c [ j ] [ i ] = in . nextInt ( ) ; } p [ i ] = in . nextInt ( ) ; } double l = 0 ; double r = 1e100 ; while ( r > l + 1e-9 ) { double m = ( l + r ) / 2 ; double [ ] q = new double [ 8 ] ; Arrays . fill ( q , 1e100 ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 8 ; j ++ ) { double qq = m * p [ i ] ; for ( int k = 0 ; k < 3 ; k ++ ) { if ( ( j & ( 1 << k ) ) > 0 ) { qq += c [ k ] [ i ] ; } else { qq -= c [ k ] [ i ] ; } } q [ j ] = Math . min ( q [ j ] , qq ) ; } } boolean b = true ; for ( int i = 0 ; i < 8 ; i ++ ) { if ( q [ i ] < - q [ i ^ 7 ] ) b = false ; } if ( b ) r = m ; else l = m ; } return \" \" + r ; } }" ]
[ "inFile = open ( \" C - large . in \" , \" r \" ) NEW_LINE outFile = open ( \" C - large - out . out \" , \" w \" ) NEW_LINE cases = int ( inFile . readline ( ) ) NEW_LINE for caseNum in range ( 1 , cases + 1 ) : NEW_LINE INDENT shipCount = int ( inFile . readline ( ) ) NEW_LINE shipList = [ ] NEW_LINE for i in range ( shipCount ) : NEW_LINE INDENT ship = inFile . readline ( ) . rstrip ( ) NEW_LINE ship = ship . split ( \" ▁ \" ) NEW_LINE ship = map ( float , ship ) NEW_LINE shipList . append ( ship ) NEW_LINE DEDENT maxPower = 0.0 NEW_LINE for i in range ( shipCount ) : NEW_LINE INDENT for j in range ( i + 1 , shipCount ) : NEW_LINE INDENT taxiDist = abs ( shipList [ i ] [ 0 ] - shipList [ j ] [ 0 ] ) + abs ( shipList [ i ] [ 1 ] - shipList [ j ] [ 1 ] ) + abs ( shipList [ i ] [ 2 ] - shipList [ j ] [ 2 ] ) NEW_LINE powerSum = shipList [ i ] [ 3 ] + shipList [ j ] [ 3 ] NEW_LINE power = taxiDist / powerSum NEW_LINE if power > maxPower : NEW_LINE INDENT maxPower = power NEW_LINE DEDENT DEDENT DEDENT outputString = \" Case ▁ # \" + str ( caseNum ) + \" : ▁ \" + str ( maxPower ) + \" \\n \" NEW_LINE print outputString . rstrip ( ) NEW_LINE outFile . write ( outputString ) NEW_LINE DEDENT inFile . close ( ) NEW_LINE outFile . close ( ) NEW_LINE", "from math import fabs NEW_LINE cases = int ( raw_input ( ) ) NEW_LINE for c in xrange ( 1 , cases + 1 ) : NEW_LINE INDENT ns = int ( raw_input ( ) ) NEW_LINE x = [ ] NEW_LINE y = [ ] NEW_LINE z = [ ] NEW_LINE p = [ ] NEW_LINE min_value = 0 NEW_LINE ship1 = - 1 NEW_LINE ship2 = - 1 NEW_LINE if ns == 1 : NEW_LINE INDENT print \" Case ▁ # % d : ▁ 0.000000\" % c NEW_LINE continue NEW_LINE DEDENT for i in xrange ( ns ) : NEW_LINE INDENT xs , ys , zs , ps = raw_input ( ) . split ( ) NEW_LINE xa = int ( xs ) NEW_LINE ya = int ( ys ) NEW_LINE za = int ( zs ) NEW_LINE pa = int ( ps ) NEW_LINE x . append ( int ( xs ) ) NEW_LINE y . append ( int ( ys ) ) NEW_LINE z . append ( int ( zs ) ) NEW_LINE p . append ( int ( ps ) ) NEW_LINE for j in xrange ( i + 1 ) : NEW_LINE INDENT xb = x [ j ] NEW_LINE yb = y [ j ] NEW_LINE zb = z [ j ] NEW_LINE pb = p [ j ] NEW_LINE value = ( fabs ( xb - xa ) + fabs ( yb - ya ) + fabs ( zb - za ) ) / float ( ( pa + pb ) ) NEW_LINE if value > min_value : NEW_LINE INDENT min_value = value NEW_LINE ship1 = i NEW_LINE ship2 = j NEW_LINE DEDENT DEDENT DEDENT totalpf = float ( p [ ship1 ] ) + float ( p [ ship2 ] ) NEW_LINE scale = float ( p [ ship1 ] ) / float ( totalpf ) NEW_LINE cruiserx = ( x [ ship2 ] - x [ ship1 ] ) * scale + x [ ship1 ] NEW_LINE cruisery = ( y [ ship2 ] - y [ ship1 ] ) * scale + y [ ship1 ] NEW_LINE cruiserz = ( z [ ship2 ] - z [ ship1 ] ) * scale + z [ ship1 ] NEW_LINE power = ( fabs ( x [ ship2 ] - cruiserx ) + fabs ( y [ ship2 ] - cruisery ) + fabs ( z [ ship2 ] - cruiserz ) ) / p [ ship2 ] NEW_LINE print \" Case ▁ # % d : ▁ % 8.6f \" % ( c , power ) NEW_LINE DEDENT" ]
codejam_15_02
[ "package cj2015 . qr ; import java . io . * ; import java . util . * ; public class B { Scanner sc ; PrintWriter pw ; int D ; int [ ] P ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : \" B - large \" ; try { new B ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + \" . in \" ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + \" . out \" ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; System . out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; solve ( ) ; } System . out . println ( \" Finished . \" ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { D = sc . nextInt ( ) ; P = new int [ D ] ; for ( int i = 0 ; i < D ; i ++ ) P [ i ] = sc . nextInt ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } public void solve ( ) { final int INF = 1000000 ; int min = INF ; for ( int x = 1 ; x <= 1000 ; x ++ ) { int time = 0 ; for ( int i = 0 ; i < D ; i ++ ) time += ( P [ i ] + x - 1 ) / x - 1 ; min = Math . min ( min , time + x ) ; } println ( min ) ; } }", "import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Scanner ; public class B { static final String FILENAME = \" B - large \" ; static final String IN = FILENAME + \" . in \" ; static final String OUT = FILENAME + \" . out \" ; Scanner sc ; BufferedWriter out ; static final int MAXP = 1000 ; private int divideTime ( int [ ] num , int limit ) { int time = 0 ; for ( int i = limit + 1 ; i <= MAXP ; i ++ ) { time += num [ i ] * ( ( i - 1 ) / limit ) ; } return time ; } private void solve ( ) throws IOException { int ans = Integer . MAX_VALUE ; int d = sc . nextInt ( ) ; int [ ] num = new int [ MAXP + 1 ] ; for ( int i = 0 ; i < d ; i ++ ) { num [ sc . nextInt ( ) ] ++ ; } for ( int limit = 1 ; limit <= MAXP ; limit ++ ) { int cur = divideTime ( num , limit ) + limit ; if ( ans > cur ) { ans = cur ; } } out . write ( Integer . toString ( ans ) ) ; out . newLine ( ) ; out . flush ( ) ; } private void run ( ) throws IOException { sc = new Scanner ( new File ( IN ) ) ; out = new BufferedWriter ( new FileWriter ( OUT ) ) ; int t = sc . nextInt ( ) ; for ( int i = 1 ; i <= t ; i ++ ) { out . write ( \" Case ▁ # \" + i + \" : ▁ \" ) ; solve ( ) ; } sc . close ( ) ; out . close ( ) ; } public static void main ( String args [ ] ) throws Exception { new B ( ) . run ( ) ; } }", "import java . io . * ; import java . util . * ; import java . util . concurrent . * ; public class B { int n ; int [ ] a ; String solve ( ) { Arrays . sort ( a ) ; int m = a [ n - 1 ] ; int ans = m ; for ( int k = 1 ; k <= m ; k ++ ) { int divs = 0 ; for ( int x : a ) { divs += ( x - 1 ) / k ; } ans = Math . min ( ans , k + divs ) ; } return \" \" + ans ; } public B ( Scanner in ) { n = in . nextInt ( ) ; a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; } } private static String fileName = B . class . getSimpleName ( ) . replaceFirst ( \" _ . * \" , \" \" ) . toLowerCase ( ) ; private static String inputFileName = fileName + \" . in \" ; private static String outputFileName = fileName + \" . out \" ; public static void main ( String [ ] args ) throws IOException , InterruptedException , ExecutionException { ExecutorService executor = Executors . newFixedThreadPool ( 4 ) ; Locale . setDefault ( Locale . US ) ; Scanner in = new Scanner ( new File ( inputFileName ) ) ; PrintWriter out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; @ SuppressWarnings ( \" unchecked \" ) Future < String > [ ] outputs = new Future [ tests ] ; for ( int t = 0 ; t < tests ; t ++ ) { final B testCase = new B ( in ) ; final int testCaseNumber = t ; outputs [ t ] = executor . submit ( new Callable < String > ( ) { @ Override public String call ( ) { String answer = testCase . solve ( ) ; String printed = \" Case ▁ # \" + ( testCaseNumber + 1 ) + \" : ▁ \" + answer ; System . out . println ( printed ) ; return printed ; } } ) ; } for ( int t = 0 ; t < tests ; t ++ ) { out . println ( outputs [ t ] . get ( ) ) ; } in . close ( ) ; out . close ( ) ; executor . shutdown ( ) ; } }", "import java . util . * ; import java . io . * ; public class InfinitePancakes { static final String filename = \" C : / Users / Kevin / algs4 / CodeJam / InfinitePancakes / B - large . in \" ; static final String output = \" largeoutput . txt \" ; public static int howLong ( int [ ] cakecounts ) { if ( cakecounts . length < 4 ) return cakecounts . length - 1 ; int ret = Integer . MAX_VALUE ; for ( int maxsize = 2 ; maxsize < cakecounts . length ; ++ maxsize ) { int [ ] cakes = Arrays . copyOf ( cakecounts , cakecounts . length ) ; int numspec = 0 ; int maxstack = cakecounts . length - 1 ; while ( maxstack > maxsize ) { while ( cakes [ maxstack ] > 0 ) { cakes [ maxstack ] -- ; cakes [ maxstack - maxsize ] ++ ; cakes [ maxsize ] ++ ; numspec ++ ; } maxstack -- ; } ret = Math . min ( ret , maxsize + numspec ) ; } return ret ; } public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( new FileInputStream ( new File ( filename ) ) ) ; int no_of_times = sc . nextInt ( ) ; for ( int i = 0 ; i < no_of_times ; ++ i ) { int D = sc . nextInt ( ) ; int [ ] platenumbers = new int [ D ] ; int maxnumber = 0 ; for ( int j = 0 ; j < D ; ++ j ) { platenumbers [ j ] = sc . nextInt ( ) ; maxnumber = Math . max ( maxnumber , platenumbers [ j ] ) ; } int [ ] cakecounts = new int [ maxnumber + 1 ] ; for ( int j = 0 ; j < D ; ++ j ) { cakecounts [ platenumbers [ j ] ] ++ ; } FileOutputStream fos = new FileOutputStream ( output , true ) ; fos . write ( ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + howLong ( cakecounts ) + \" \\n \" ) . getBytes ( ) ) ; fos . close ( ) ; } sc . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }", "package gcj2015 . qualif ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoB { public static void main ( final String [ ] args ) { final String base = \" / home / jean / gcj2015 / q / ExoB / \" ; final String input = base + \" b1 . in \" ; final String output = base + \" b2 . out \" ; try { final Scanner sc = new Scanner ( new FileReader ( input ) ) ; final PrintWriter pw = new PrintWriter ( output ) ; final int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( \" Test ▁ case ▁ \" + ( c + 1 ) + \" . . . \" ) ; pw . print ( \" Case ▁ # \" + ( c + 1 ) + \" : ▁ \" ) ; test3 ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( final FileNotFoundException ex ) { Logger . getLogger ( ExoB . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test3 ( final Scanner sc , final PrintWriter pw ) { final int D = sc . nextInt ( ) ; List < Integer > nums = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < D ; i ++ ) { nums . add ( sc . nextInt ( ) ) ; } int max = Collections . max ( nums ) ; int bt = max ; for ( int m = 1 ; m <= max ; m ++ ) { System . out . println ( \" for ▁ m ▁ = ▁ \" + m ) ; int t = m ; for ( int k : nums ) { if ( k != 0 ) t += ( k % m == 0 ) ? ( k / m ) - 1 : k / m ; } System . out . println ( \" t ▁ = ▁ \" + t ) ; if ( t < bt ) { bt = t ; } } pw . print ( bt ) ; } }" ]
[ "MAXP = 1001 NEW_LINE def solve ( P ) : NEW_LINE INDENT best = MAXP NEW_LINE for level in range ( 1 , MAXP ) : NEW_LINE INDENT moves = 0 NEW_LINE for p in P : NEW_LINE INDENT moves += ( p - 1 ) / level NEW_LINE DEDENT if moves + level < best : NEW_LINE INDENT best = moves + level NEW_LINE DEDENT DEDENT return best NEW_LINE DEDENT T = input ( ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT D = input ( ) NEW_LINE P = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE s = solve ( P ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( t , s ) NEW_LINE DEDENT", "import math NEW_LINE def numberofsteps ( lst , bites ) : NEW_LINE INDENT output = bites NEW_LINE for item in lst : NEW_LINE INDENT output += ( int ( math . ceil ( item / bites ) ) - 1 ) NEW_LINE DEDENT return output NEW_LINE DEDENT def process ( lst ) : NEW_LINE INDENT m = max ( lst ) NEW_LINE return min ( [ numberofsteps ( lst , x ) for x in range ( 1 , m + 1 ) ] ) NEW_LINE DEDENT import sys NEW_LINE with open ( sys . argv [ 1 ] , \" r \" ) as fileIN : NEW_LINE INDENT inputLines = fileIN . readlines ( ) NEW_LINE DEDENT inputLines = [ line . strip ( ) for line in inputLines ] NEW_LINE with open ( sys . argv [ 2 ] , \" w \" ) as fileOUT : NEW_LINE INDENT numberOfCases = int ( inputLines . pop ( 0 ) ) NEW_LINE for num in range ( numberOfCases ) : NEW_LINE INDENT numberofplates = int ( inputLines . pop ( 0 ) ) NEW_LINE inputlist = [ int ( x ) for x in inputLines . pop ( 0 ) . rstrip ( ) . split ( ' ▁ ' ) ] NEW_LINE fileOUT . write ( ' Case ▁ # ' + str ( num + 1 ) + ' : ▁ ' + str ( process ( inputlist ) ) + ' \\n ' ) NEW_LINE DEDENT DEDENT", "import math NEW_LINE f_in = open ( ' file . in ' ) NEW_LINE f_out = open ( ' file . out ' , ' w ' ) NEW_LINE def solution ( plates ) : NEW_LINE INDENT min = max ( plates ) NEW_LINE for i in range ( 1 , max ( plates ) ) : NEW_LINE INDENT candidate = i + sum ( [ math . ceil ( plate / i ) - 1 for plate in plates ] ) NEW_LINE if candidate < min : NEW_LINE INDENT min = candidate NEW_LINE DEDENT DEDENT return min NEW_LINE DEDENT cases = int ( f_in . readline ( ) ) NEW_LINE for i in range ( 1 , cases + 1 ) : NEW_LINE INDENT f_in . readline ( ) NEW_LINE plates = [ int ( i ) for i in f_in . readline ( ) . split ( ) ] NEW_LINE f_out . write ( \" Case ▁ # \" + str ( i ) + \" : ▁ \" + str ( solution ( plates ) ) + \" \\n \" ) NEW_LINE DEDENT", "DESCRIPTION = \"\"\" STRNEWLINE \"\"\" NEW_LINE import os NEW_LINE import sys NEW_LINE import argparse NEW_LINE def perr ( msg ) : NEW_LINE INDENT sys . stderr . write ( \" % s \" % msg ) NEW_LINE sys . stderr . flush ( ) NEW_LINE DEDENT def pinfo ( msg ) : NEW_LINE INDENT sys . stdout . write ( \" % s \" % msg ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT def runcmd ( cmd ) : NEW_LINE INDENT perr ( \" % s \\n \" % cmd ) NEW_LINE os . system ( cmd ) NEW_LINE DEDENT def getargs ( ) : NEW_LINE INDENT parser = argparse . ArgumentParser ( description = DESCRIPTION , formatter_class = argparse . RawTextHelpFormatter ) NEW_LINE parser . add_argument ( ' infile ' , type = str , help = ' input ▁ file ' ) NEW_LINE parser . add_argument ( ' outfile ' , type = str , nargs = ' ? ' , default = None , help = ' output ▁ file ' ) NEW_LINE return parser . parse_args ( ) NEW_LINE DEDENT def steps_to_get_Pmax_eq_p ( P , Pmax ) : NEW_LINE INDENT nstep = 0 NEW_LINE for p in P : NEW_LINE INDENT nstep += ( ( p - 1 ) / Pmax ) NEW_LINE DEDENT return nstep NEW_LINE DEDENT def solve ( D , P ) : NEW_LINE INDENT min_costs = max ( P ) NEW_LINE for Pmax in range ( 1 , max ( P ) + 1 ) : NEW_LINE INDENT N = steps_to_get_Pmax_eq_p ( P , Pmax ) NEW_LINE costs = N + Pmax NEW_LINE if costs < min_costs : NEW_LINE INDENT min_costs = costs NEW_LINE DEDENT DEDENT return min_costs NEW_LINE DEDENT def main ( args ) : NEW_LINE INDENT if None == args . outfile : NEW_LINE INDENT outfile = sys . stdout NEW_LINE DEDENT else : NEW_LINE INDENT outfile = open ( args . outfile , \" w \" ) NEW_LINE DEDENT with open ( args . infile ) as infile : NEW_LINE INDENT T = int ( infile . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT D = int ( infile . readline ( ) ) NEW_LINE P = [ int ( p ) for p in infile . readline ( ) . split ( ) ] NEW_LINE outfile . write ( \" Case ▁ # % d : ▁ % d \\n \" % ( i , solve ( D , P ) ) ) NEW_LINE DEDENT DEDENT if None != args . outfile : NEW_LINE INDENT outfile . close ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( getargs ( ) ) NEW_LINE DEDENT", "import sys NEW_LINE import math NEW_LINE def load_cases ( path ) : NEW_LINE INDENT case_list = [ ] NEW_LINE with open ( path , ' r ' ) as fh : NEW_LINE INDENT case_num = int ( fh . readline ( ) . strip ( \" \\n \" ) ) NEW_LINE for i in range ( 0 , case_num ) : NEW_LINE INDENT D = int ( fh . readline ( ) . strip ( \" \\n \" ) ) NEW_LINE P = filter ( None , fh . readline ( ) . strip ( \" \\n \" ) . split ( \" ▁ \" ) ) NEW_LINE if D != len ( P ) : NEW_LINE INDENT print ' incorrect ▁ file ▁ at ▁ case ▁ % d ' % i NEW_LINE sys . exit ( ) NEW_LINE DEDENT case_list . append ( [ int ( item ) for item in P ] ) NEW_LINE DEDENT DEDENT return case_list NEW_LINE DEDENT def calculate_case ( P ) : NEW_LINE INDENT max_num = max ( P ) NEW_LINE return min ( sum ( [ int ( ( num - 0.5 ) / m ) for num in P ] ) + m for m in range ( max_num , 0 , - 1 ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT if len ( sys . argv ) != 3 : NEW_LINE INDENT print ' Usage : ▁ q2 . py ▁ input _ file ▁ output _ file ' NEW_LINE sys . exit ( ) NEW_LINE DEDENT input_file = sys . argv [ 1 ] NEW_LINE output_file = sys . argv [ 2 ] NEW_LINE case_list = load_cases ( input_file ) NEW_LINE with open ( output_file , ' w ' ) as fh : NEW_LINE INDENT case_id = 1 NEW_LINE for case in case_list : NEW_LINE INDENT time = calculate_case ( case ) NEW_LINE fh . write ( ' Case ▁ # % d : ▁ % d \\n ' % ( case_id , time ) ) NEW_LINE case_id += 1 NEW_LINE DEDENT DEDENT DEDENT" ]
codejam_08_71
[ "import java . io . * ; import java . util . * ; public class A { PrintWriter out ; Scanner in ; public static void main ( String [ ] args ) throws Exception { new A ( ) . solve ( ) ; } Map < String , Integer > nums = new HashMap ( ) ; String [ ] names = new String [ 1010 ] ; List < String > [ ] ing = new List [ 1010 ] ; int go ( String name ) { int ind = nums . get ( name ) ; List < Integer > deps = new ArrayList ( ) ; for ( String dep : ing [ ind ] ) { if ( Character . isLowerCase ( dep . charAt ( 0 ) ) ) { } else { deps . add ( go ( dep ) ) ; } } Collections . sort ( deps ) ; int ans = 0 ; for ( int i = deps . size ( ) - 1 ; i >= 0 ; -- i ) { int have = deps . size ( ) - i - 1 ; have += deps . get ( i ) ; if ( have > ans ) { ans = have ; } } ans = Math . max ( ans , deps . size ( ) + 1 ) ; return ans ; } void solve ( ) throws Exception { Locale . setDefault ( Locale . ENGLISH ) ; out = new PrintWriter ( new FileOutputStream ( \" a . out \" ) ) ; in = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( \" a . in \" ) ) ) ) ; int N = in . nextInt ( ) ; for ( int t = 1 ; t <= N ; ++ t ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; ++ i ) { String s = in . next ( ) ; int m = in . nextInt ( ) ; names [ i ] = s ; nums . put ( s , i ) ; ing [ i ] = new ArrayList ( ) ; for ( int j = 0 ; j < m ; ++ j ) { ing [ i ] . add ( in . next ( ) ) ; } } out . println ( go ( names [ 0 ] ) ) ; } out . close ( ) ; } }", "import java . util . * ; public class A { static HashMap < String , Integer > hm = new HashMap ( ) ; static int X ; static int id ( String s ) { if ( s . matches ( \" [ a - z ] + \" ) ) return - 1 ; if ( hm . containsKey ( s ) ) return hm . get ( s ) ; else hm . put ( s , X ) ; return X ++ ; } static int [ ] [ ] ls ; static int go ( int id ) { if ( id == - 1 ) return - 1000000 ; int [ ] cnt = new int [ ls [ id ] . length ] ; int mixes = 0 ; for ( int i = 0 ; i < cnt . length ; i ++ ) { if ( ls [ id ] [ i ] >= 0 ) mixes ++ ; cnt [ i ] = go ( ls [ id ] [ i ] ) ; } Arrays . sort ( cnt ) ; int ret = 1 ; for ( int i = 0 ; i < cnt . length ; i ++ ) { ret = Math . max ( ret , cnt [ i ] + cnt . length - i - 1 ) ; } return Math . max ( ret , mixes + 1 ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int C = sc . nextInt ( ) ; String s ; for ( int i = 0 ; i < C ; i ++ ) { hm = new HashMap ( ) ; X = 0 ; int N = sc . nextInt ( ) ; ls = new int [ N ] [ ] ; for ( int j = 0 ; j < N ; j ++ ) { int id1 = id ( sc . next ( ) ) ; ls [ id1 ] = new int [ sc . nextInt ( ) ] ; for ( int k = 0 ; k < ls [ id1 ] . length ; k ++ ) { ls [ id1 ] [ k ] = id ( s = sc . next ( ) ) ; } Arrays . sort ( ls [ id1 ] ) ; } int req = go ( 0 ) ; System . out . printf ( \" Case ▁ # % d : ▁ % d \\n \" , i + 1 , req ) ; } } }" ]
[ "from __future__ import with_statement NEW_LINE import re , heapq NEW_LINE import sys NEW_LINE def addlBowlsFor ( mixture , mixtures , unusedBowls = 0 , p = False ) : NEW_LINE INDENT if mixture . islower ( ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT ingreds = mixtures [ mixture ] NEW_LINE ingredLeastUse = sorted ( ingreds , None , lambda x : addlBowlsFor ( x , mixtures , unusedBowls ) ) NEW_LINE bowlsINeed = 0 NEW_LINE big = 0 NEW_LINE for ingred in reversed ( ingredLeastUse ) : NEW_LINE INDENT if ingred . isupper ( ) : NEW_LINE INDENT addlBowls = addlBowlsFor ( ingred , mixtures , unusedBowls , p ) NEW_LINE unusedBowls += addlBowls - 1 NEW_LINE bowlsINeed += addlBowls NEW_LINE DEDENT DEDENT if unusedBowls == 0 : NEW_LINE INDENT bowlsINeed += 1 NEW_LINE DEDENT return bowlsINeed NEW_LINE DEDENT def doWork ( first , mixtures ) : NEW_LINE INDENT return addlBowlsFor ( first , mixtures , 0 , True ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT with open ( sys . argv [ 1 ] ) as f : NEW_LINE INDENT cases = int ( f . readline ( ) ) NEW_LINE for i in xrange ( cases ) : NEW_LINE INDENT mixtureCount = int ( f . readline ( ) ) NEW_LINE first = None NEW_LINE mixtures = { } NEW_LINE for mi in xrange ( mixtureCount ) : NEW_LINE INDENT data = f . readline ( ) . strip ( ) NEW_LINE data = re . split ( r ' \\s + ' , data ) NEW_LINE if not first : NEW_LINE INDENT first = data [ 0 ] NEW_LINE DEDENT mixtures [ data [ 0 ] ] = data [ 2 : ] NEW_LINE DEDENT result = doWork ( first , mixtures ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT DEDENT main ( ) NEW_LINE" ]
codejam_13_31
[ "import java . io . * ; import java . util . * ; public class A { static class Assert { static void check ( boolean e ) { if ( ! e ) { throw new Error ( ) ; } } } Scanner in ; PrintWriter out ; boolean isCons ( char c ) { return c != ' a ' && c != ' e ' && c != ' i ' && c != ' o ' && c != ' u ' ; } int getPos ( String word , int n , int from ) { int count = 0 ; for ( int i = from ; i < word . length ( ) ; i ++ ) { if ( isCons ( word . charAt ( i ) ) ) { count ++ ; if ( count == n ) { return i ; } } else { count = 0 ; } } return - 1 ; } long solveOne ( String word , int n ) { long count = 0 ; int pos = getPos ( word , n , 0 ) ; if ( pos == - 1 ) { return count ; } count += word . length ( ) - pos ; for ( int start = 1 ; start < word . length ( ) ; start ++ ) { if ( pos - start + 1 >= n ) { } else { Assert . check ( pos - start + 1 == n - 1 ) ; if ( pos == word . length ( ) - 1 ) { return count ; } if ( isCons ( word . charAt ( pos + 1 ) ) ) { pos ++ ; } else { pos = getPos ( word , n , pos + 2 ) ; if ( pos == - 1 ) { return count ; } } } count += word . length ( ) - pos ; } return count ; } void solve ( ) { int nTests = in . nextInt ( ) ; for ( int i = 1 ; i <= nTests ; i ++ ) { out . printf ( \" Case ▁ # % d : ▁ % d % n \" , i , solveOne ( in . next ( ) , in . nextInt ( ) ) ) ; } } void run ( ) { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; try { solve ( ) ; } finally { out . close ( ) ; } } public static void main ( String args [ ] ) { new A ( ) . run ( ) ; } }", "import java . io . File ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . Scanner ; public class GCJ_2013_C1 { public static long solve ( String s , long n ) { long bef_cont = 0 ; long bef_noncont = 0 ; long endpart = 0 ; System . out . println ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { long bef_cont_prev = bef_cont ; long bef_noncont_prev = bef_noncont ; char c = s . charAt ( i ) ; boolean cns = ! ( ( c == ' a ' ) || ( c == ' e ' ) || ( c == ' i ' ) || ( c == ' o ' ) || ( c == ' u ' ) ) ; bef_noncont = bef_noncont_prev + bef_cont_prev ; if ( cns ) { endpart ++ ; if ( endpart >= n ) { bef_cont = ( i - n + 2 ) ; } else { bef_cont = bef_cont_prev ; } } else { bef_cont = bef_cont_prev ; endpart = 0 ; } } return bef_cont + bef_noncont ; } public static void main ( String [ ] args ) throws Exception { String fname = \" A _ large \" ; File file = new File ( fname + \" _ in . txt \" ) ; Scanner scanner = new Scanner ( file ) ; FileWriter outFile = new FileWriter ( fname + \" _ out . txt \" ) ; PrintWriter outp = new PrintWriter ( outFile ) ; int T = scanner . nextInt ( ) ; scanner . nextLine ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { String s = scanner . nextLine ( ) ; String sin = s . split ( \" ▁ \" ) [ 0 ] ; int n = Integer . parseInt ( s . split ( \" ▁ \" ) [ 1 ] ) ; outp . printf ( \" Case ▁ # % d : ▁ % d \\n \" , i , solve ( sin , n ) ) ; } outp . close ( ) ; } }", "import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . LineNumberReader ; public class A { static long result ( String name , int n ) { int len = name . length ( ) ; boolean hasPrev = false ; int curr = 0 ; int prevStart = 0 ; long res = 0 ; int pos = 0 ; while ( pos < len ) { boolean is = \" aeiou \" . indexOf ( name . charAt ( pos ++ ) ) < 0 ; if ( is ) { curr ++ ; if ( curr >= n ) { hasPrev = true ; prevStart = pos - n ; res += 1 + pos - n ; continue ; } } else { curr = 0 ; } if ( hasPrev ) { res += 1 + prevStart ; } } return res ; } static void go ( String inputFile ) throws Exception { LineNumberReader in = new LineNumberReader ( new FileReader ( inputFile ) ) ; FileWriter out = new FileWriter ( inputFile + \" . out \" ) ; int nCases = Integer . parseInt ( in . readLine ( ) ) ; for ( int c = 1 ; c <= nCases ; c ++ ) { String [ ] tmp = in . readLine ( ) . split ( \" ▁ \" ) ; long res = result ( tmp [ 0 ] , Integer . parseInt ( tmp [ 1 ] ) ) ; String line = \" Case ▁ # \" + c + \" : ▁ \" + res ; System . out . println ( line ) ; out . write ( line + \" \\n \" ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws Exception { LineNumberReader sysIn = new LineNumberReader ( new InputStreamReader ( System . in ) ) ; String line ; while ( ( line = sysIn . readLine ( ) ) != null ) { go ( line . trim ( ) ) ; } } }", "import java . io . * ; import java . util . * ; public class Round1C_2013_A { private static void jam ( String inFile , String outFile ) throws Exception { BufferedReader brIn = new BufferedReader ( new FileReader ( inFile ) ) ; BufferedWriter bwOut = new BufferedWriter ( new FileWriter ( outFile ) ) ; String sLine ; int ca = 1 ; brIn . readLine ( ) ; int [ ] starts = new int [ 1000000 ] ; int [ ] ends = new int [ 1000000 ] ; while ( ( sLine = brIn . readLine ( ) ) != null ) { String [ ] fields = sLine . split ( \" ▁ \" ) ; if ( fields . length != 2 ) { System . out . println ( \" skipping ▁ mis - parse : ▁ \" + sLine ) ; continue ; } String s = fields [ 0 ] ; int n = Integer . parseInt ( fields [ 1 ] ) ; int numSets = 0 ; int seqNum = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( c != ' a ' && c != ' e ' && c != ' i ' && c != ' o ' && c != ' u ' ) { seqNum ++ ; if ( seqNum >= n ) { starts [ numSets ] = i + 1 - n ; ends [ numSets ] = i + 1 ; numSets ++ ; } } else { seqNum = 0 ; } } int lastStart = - 1 ; long sum = 0 ; for ( int i = 0 ; i < numSets ; i ++ ) { int choicesLeft = starts [ i ] - lastStart ; int choicesRight = 1 + s . length ( ) - ends [ i ] ; sum += ( long ) choicesLeft * ( long ) choicesRight ; lastStart = starts [ i ] ; } String msg = \" \" + sum ; System . out . println ( \" \" + s . length ( ) ) ; bwOut . write ( \" Case ▁ # \" + ca + \" : ▁ \" + msg + \" \\r \\n \" ) ; ca ++ ; } brIn . close ( ) ; bwOut . close ( ) ; } public static void main ( String [ ] args ) throws Exception { jam ( args [ 0 ] , args [ 1 ] ) ; } }", "import java . awt . * ; import java . awt . event . * ; import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . text . * ; import java . util . * ; public class A { static BufferedReader br ; static StringTokenizer st ; static PrintWriter pw ; public static void main ( String [ ] args ) throws IOException { br = new BufferedReader ( new FileReader ( \" a . in \" ) ) ; pw = new PrintWriter ( new BufferedWriter ( new FileWriter ( \" a . out \" ) ) ) ; final int MAX_CASES = readInt ( ) ; String vowel = \" aeiou \" ; for ( int casenum = 1 ; casenum <= MAX_CASES ; casenum ++ ) { pw . printf ( \" Case ▁ # % d : ▁ \" , casenum ) ; String str = nextToken ( ) ; int count = readInt ( ) ; long ret = 0 ; int curr = 0 ; int lastStart = - 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( vowel . indexOf ( str . charAt ( i ) + \" \" ) == - 1 ) { curr ++ ; } else { curr = 0 ; } if ( curr >= count ) { int begin = i - count + 1 ; int goAfter = i ; ret += ( begin - lastStart ) * 1L * ( str . length ( ) - goAfter ) ; lastStart = begin ; } } pw . println ( ret ) ; } pw . close ( ) ; } public static int readInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } public static long readLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } public static double readDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; } public static String nextToken ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { if ( ! br . ready ( ) ) { pw . close ( ) ; System . exit ( 0 ) ; } st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } public static String readLine ( ) throws IOException { st = null ; return br . readLine ( ) ; } }" ]
[ "from collections import Counter NEW_LINE vowels = [ ' a ' , ' e ' , ' i ' , ' o ' , ' u ' ] NEW_LINE def solve ( s , n ) : NEW_LINE INDENT total = 0 NEW_LINE is_first = True NEW_LINE cont = 0 NEW_LINE arr = [ 0 for i in range ( len ( s ) ) ] NEW_LINE if s [ 0 ] not in vowels : NEW_LINE INDENT cont = 1 NEW_LINE if n == 1 : NEW_LINE INDENT is_first = False NEW_LINE last_cont = 0 NEW_LINE arr [ 0 ] = 1 NEW_LINE DEDENT DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] in vowels : NEW_LINE INDENT cont = 0 NEW_LINE arr [ i ] = arr [ i - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT cont += 1 NEW_LINE if cont < n : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] NEW_LINE DEDENT elif cont == n : NEW_LINE INDENT if is_first : NEW_LINE INDENT is_first = False NEW_LINE arr [ i ] = i + 2 - n NEW_LINE last_cont = i NEW_LINE DEDENT else : NEW_LINE INDENT arr [ i ] = i - last_cont + arr [ i - 1 ] NEW_LINE last_cont = i NEW_LINE DEDENT DEDENT elif cont > n : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] + 1 NEW_LINE last_cont = i NEW_LINE DEDENT else : raise Exception ( ' wo ' ) NEW_LINE DEDENT DEDENT print arr NEW_LINE return sum ( arr ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE input_file = sys . argv [ 1 ] NEW_LINE output_file = input_file [ : ] . replace ( ' . in ' , ' . out ' ) NEW_LINE f_in = open ( input_file , ' r ' ) NEW_LINE f_out = open ( output_file , ' w ' ) NEW_LINE T , = [ int ( x ) for x in f_in . readline ( ) . split ( ) ] NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT print NEW_LINE print ' = = = = = = = = = = = = = = = = = = = = = ' NEW_LINE print ' ▁ ▁ ▁ ▁ ' + str ( case ) NEW_LINE print ' = = = = = = = = = = = = = = = = = = = = = ' NEW_LINE s , n = [ x for x in f_in . readline ( ) . split ( ) ] NEW_LINE n = int ( n ) NEW_LINE ans = solve ( s , n ) NEW_LINE print ans NEW_LINE f_out . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( case , ans ) ) NEW_LINE DEDENT DEDENT", "import argparse NEW_LINE import collections NEW_LINE import fractions NEW_LINE import functools NEW_LINE import itertools NEW_LINE import math NEW_LINE import operator NEW_LINE from sys import exit , stdin NEW_LINE from multiprocessing import Pool NEW_LINE def solve_star ( args ) : NEW_LINE INDENT return solve ( * args ) NEW_LINE DEDENT def read_int ( ) : NEW_LINE INDENT return int ( stdin . readline ( ) . strip ( ) ) NEW_LINE DEDENT def read_ints ( ) : NEW_LINE INDENT return [ int ( n ) for n in stdin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def read_words ( ) : NEW_LINE INDENT return stdin . readline ( ) . strip ( ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT name , n = read_words ( ) . split ( ) NEW_LINE return [ name , int ( n ) ] NEW_LINE DEDENT def solve ( name , n ) : NEW_LINE INDENT vowels = [ \" a \" , \" e \" , \" i \" , \" o \" , \" u \" ] NEW_LINE count = 0 NEW_LINE last = 0 NEW_LINE total = 0 NEW_LINE for e , c in enumerate ( name ) : NEW_LINE INDENT if c in vowels : NEW_LINE INDENT count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE if count == n : NEW_LINE INDENT this_string_starts = e - ( n - 1 ) NEW_LINE total += ( this_string_starts - last + 1 ) * ( len ( name ) - e ) NEW_LINE last = this_string_starts + 1 NEW_LINE count -= 1 NEW_LINE DEDENT DEDENT DEDENT return total NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT parser = argparse . ArgumentParser ( ) NEW_LINE parser . add_argument ( \" - m \" , \" - - multi \" , help = \" turn ▁ on ▁ multiprocessing \" , action = \" store _ true \" ) NEW_LINE args = parser . parse_args ( ) NEW_LINE with open ( \" out . txt \" , \" w \" ) as f : NEW_LINE INDENT if args . multi : NEW_LINE INDENT pool = Pool ( ) NEW_LINE iter = pool . imap ( solve_star , ( parse ( ) for i in range ( read_int ( ) ) ) ) NEW_LINE for i , result in enumerate ( iter ) : NEW_LINE INDENT s = \" Case ▁ # { } : ▁ { } \" . format ( i + 1 , result ) NEW_LINE print ( s ) NEW_LINE f . write ( s + \" \\n \" ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( read_int ( ) ) : NEW_LINE INDENT s = \" Case ▁ # { } : ▁ { } \" . format ( i + 1 , solve ( * parse ( ) ) ) NEW_LINE print ( s ) NEW_LINE f . write ( s + \" \\n \" ) NEW_LINE DEDENT DEDENT DEDENT DEDENT", "import sys NEW_LINE import math NEW_LINE import itertools NEW_LINE for testcase in xrange ( 1 , int ( sys . stdin . readline ( ) ) + 1 ) : NEW_LINE INDENT name , n = [ str ( w ) for w in sys . stdin . readline ( ) . split ( ) ] NEW_LINE n = int ( n ) NEW_LINE starting_points = { } NEW_LINE enough_consants = False NEW_LINE num_consecutive = 0 NEW_LINE for index in xrange ( len ( name ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if name [ index ] in ' aeiou ' : NEW_LINE INDENT num_consecutive = 0 NEW_LINE DEDENT else : NEW_LINE INDENT num_consecutive += 1 NEW_LINE DEDENT if num_consecutive >= n : NEW_LINE INDENT starting_points [ index ] = 1 NEW_LINE DEDENT DEDENT if 0 in starting_points : NEW_LINE INDENT count = 1 NEW_LINE last_used = 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE last_used = 0 NEW_LINE DEDENT for index in xrange ( n , len ( name ) ) : NEW_LINE INDENT index_minus = index - n + 1 NEW_LINE if index_minus in starting_points : NEW_LINE INDENT count = count + index_minus + 1 NEW_LINE last_used = index_minus + 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + last_used NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % d ' % ( testcase , count ) NEW_LINE NEW_LINE DEDENT", "import math , os , sys , random NEW_LINE vowels = ' aeiou ' NEW_LINE consonants = ' bcdfghjklmnpqrstvwxyz ' NEW_LINE vowels_set = frozenset ( vowels ) NEW_LINE consonants_set = frozenset ( consonants ) NEW_LINE def single_test ( IN , OUT ) : NEW_LINE INDENT name , n = IN . readline ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE L = len ( name ) NEW_LINE data = ' ' NEW_LINE for l in name : data += ' v ' if l in vowels_set else ' c ' NEW_LINE starts = [ ] NEW_LINE count = 0 NEW_LINE for i , l in enumerate ( data ) : NEW_LINE INDENT if l == ' v ' : NEW_LINE INDENT count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE if count >= n : NEW_LINE INDENT starts . append ( i + 1 - n ) NEW_LINE DEDENT DEDENT DEDENT freespaces = [ ] NEW_LINE cs = 0 NEW_LINE for i in range ( L ) : NEW_LINE INDENT while cs != - 1 and cs < len ( starts ) and i > starts [ cs ] : NEW_LINE INDENT cs += 1 NEW_LINE DEDENT if cs == len ( starts ) : NEW_LINE INDENT cs = - 1 NEW_LINE DEDENT if cs == - 1 : NEW_LINE INDENT if i < L : freespaces . append ( ( i , L - i ) ) NEW_LINE DEDENT else : NEW_LINE INDENT if starts [ cs ] + n - 1 > i : freespaces . append ( ( i , starts [ cs ] + n - 1 - i ) ) NEW_LINE DEDENT DEDENT result = ( L * ( L + 1 ) ) // 2 NEW_LINE for f in freespaces : NEW_LINE INDENT result -= f [ 1 ] NEW_LINE DEDENT return result NEW_LINE DEDENT def main ( IN , OUT ) : NEW_LINE INDENT T = int ( IN . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT OUT . write ( ' Case ▁ # % d : ▁ % d \\n ' % ( i , single_test ( IN , OUT ) ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT assert len ( sys . argv ) == 2 NEW_LINE IN = open ( sys . argv [ 1 ] , ' rt ' ) NEW_LINE OUT = open ( ' % s . out ' % sys . argv [ 1 ] [ : - 3 ] , ' wt ' ) NEW_LINE main ( IN , OUT ) NEW_LINE OUT . close ( ) NEW_LINE IN . close ( ) NEW_LINE DEDENT", "def puts ( s ) : NEW_LINE INDENT print ( s , end = ' ' ) NEW_LINE DEDENT vowels = \" aeiou \" NEW_LINE def solve ( case ) : NEW_LINE INDENT S , n = input ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE streak = 0 NEW_LINE cons = [ ] NEW_LINE for c in S : NEW_LINE INDENT if c in vowels : NEW_LINE INDENT streak = 0 NEW_LINE DEDENT else : NEW_LINE INDENT streak += 1 NEW_LINE DEDENT cons += [ streak ] NEW_LINE DEDENT count = 0 NEW_LINE m = 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if cons [ i ] >= n : NEW_LINE INDENT m = i + 2 - n NEW_LINE DEDENT count += m NEW_LINE DEDENT print ( count ) NEW_LINE DEDENT for case in range ( 1 , 1 + int ( input ( ) ) ) : NEW_LINE INDENT puts ( \" Case ▁ # \" + str ( case ) + \" : ▁ \" ) NEW_LINE solve ( case ) NEW_LINE DEDENT" ]
codejam_08_42
[ "import java . io . * ; import java . util . StringTokenizer ; public class B { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" B - large . in \" ) ) ; PrintWriter out = new PrintWriter ( \" b . out \" ) ; int C = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 1 ; i <= C ; i ++ ) { StringTokenizer tz = new StringTokenizer ( in . readLine ( ) ) ; int N = Integer . parseInt ( tz . nextToken ( ) ) ; int M = Integer . parseInt ( tz . nextToken ( ) ) ; int A = Integer . parseInt ( tz . nextToken ( ) ) ; String ans ; if ( A > N * M ) { ans = \" IMPOSSIBLE \" ; } else { int a = A / M ; int b , c = 1 , d = M ; if ( a * M == A ) { b = 0 ; } else { a ++ ; b = a * d - A ; } ans = \"0 ▁ 0 ▁ \" + a + \" ▁ \" + b + \" ▁ \" + c + \" ▁ \" + d ; } out . println ( \" Case ▁ # \" + i + \" : ▁ \" + ans ) ; } in . close ( ) ; out . close ( ) ; } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . Locale ; public class B implements Runnable { static final String NAME = \" b - large \" ; public void solve ( ) throws Exception { int ntest = Integer . parseInt ( readWord ( ) ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { long n = Long . parseLong ( readWord ( ) ) ; long m = Long . parseLong ( readWord ( ) ) ; long a = Long . parseLong ( readWord ( ) ) ; if ( a > n * m ) { stdout . write ( \" Case ▁ # \" + test + \" : ▁ \" + \" IMPOSSIBLE \\n \" ) ; continue ; } long s = a % n ; if ( s == 0 ) { stdout . write ( \" Case ▁ # \" + test + \" : ▁ \" + \"0 ▁ 0 ▁ \" + n + \" ▁ \" + 0 + \" ▁ \" + n + \" ▁ \" + ( a / n ) + \" \\n \" ) ; } else { stdout . write ( \" Case ▁ # \" + test + \" : ▁ \" + \"0 ▁ 0 ▁ \" + n + \" ▁ \" + 1 + \" ▁ \" + ( n - s ) + \" ▁ \" + ( a / n + 1 ) + \" \\n \" ) ; } } } static BufferedReader stdin ; static BufferedWriter stdout ; String readWord ( ) throws Exception { StringBuilder b = new StringBuilder ( ) ; int c ; while ( true ) { c = stdin . read ( ) ; if ( c < 0 ) { return \" \" ; } if ( c > 32 ) { break ; } } while ( true ) { b . append ( ( char ) c ) ; c = stdin . read ( ) ; if ( c <= 32 ) { break ; } } return b . toString ( ) ; } public void run ( ) { try { stdin = new BufferedReader ( new FileReader ( NAME + \" . in \" ) ) ; stdout = new BufferedWriter ( new FileWriter ( NAME + \" . out \" ) ) ; solve ( ) ; stdout . close ( ) ; stdin . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } public static void main ( String [ ] args ) { try { Locale . setDefault ( Locale . US ) ; } catch ( Throwable e ) { } new Thread ( new B ( ) ) . start ( ) ; } }", "import java . io . PrintWriter ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Scanner ; public class B { static Scanner in ; static PrintWriter out ; public static void main ( String [ ] args ) throws FileNotFoundException { in = new Scanner ( new File ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new B ( ) . solve ( ) ) ; } out . close ( ) ; } private Object solve ( ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int a = in . nextInt ( ) ; boolean [ ] q = new boolean [ n * m + 1 ] ; int [ ] xx = new int [ n * m + 1 ] ; int [ ] yy = new int [ n * m + 1 ] ; for ( int x = 0 ; x <= n ; x ++ ) { for ( int y = 0 ; y <= m ; y ++ ) { int z = ( x * y ) ; q [ z ] = true ; xx [ z ] = x ; yy [ z ] = y ; } } for ( int i = 0 ; i <= ( n * m - a ) ; i ++ ) { if ( q [ i ] && q [ i + a ] ) { return \"0 ▁ 0 ▁ \" + xx [ i ] + \" ▁ \" + yy [ i + a ] + \" ▁ \" + xx [ i + a ] + \" ▁ \" + yy [ i ] ; } } return \" IMPOSSIBLE \" ; } }", "import java . io . * ; import java . util . * ; public class B implements Runnable { private Scanner in ; private PrintWriter out ; private void solve ( int testCase ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int a = in . nextInt ( ) ; if ( a > n * m ) { out . println ( \" Case ▁ # \" + testCase + \" : ▁ IMPOSSIBLE \" ) ; return ; } int p = a - a % n ; if ( p < a ) p += n ; int y3 = p / n ; int x3 = p - a ; out . println ( \" Case ▁ # \" + testCase + \" : ▁ 0 ▁ 0 ▁ \" + n + \" ▁ 1 ▁ \" + x3 + \" ▁ \" + y3 ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; new Thread ( new B ( ) ) . start ( ) ; } public void run ( ) { try { in = new Scanner ( new FileReader ( \" b . in \" ) ) ; out = new PrintWriter ( \" b . out \" ) ; int n = in . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) solve ( i ) ; in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } }", "import java . io . BufferedInputStream ; import java . io . FileInputStream ; import java . io . InputStream ; import java . util . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . lang . Integer . * ; import static java . lang . Character . * ; public class B { Scanner scan ; InputStream in ; int intLine ( ) { return parseInt ( scan . nextLine ( ) ) ; } String find ( long A , long B , long area ) { for ( long a = 1 ; a <= A ; a ++ ) for ( long b = 1 ; b <= B ; b ++ ) { for ( long x = 0 ; x <= b ; x ++ ) for ( long y = 0 ; y <= a ; y ++ ) { long r = x * a + y * b - x * y ; if ( r == area ) { return String . format ( \" % d ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d \" , 0 , x , y , 0 , a , b ) ; } } } return null ; } String solve ( ) { long res = 0 ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; long area = scan . nextLong ( ) ; if ( find ( A , B , area ) != null ) return find ( A , B , area ) ; return \" IMPOSSIBLE \" ; } void solveAll ( ) { int N = parseInt ( scan . nextLine ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { String r = solve ( ) ; System . out . format ( \" Case ▁ # % d : ▁ % s \\n \" , i + 1 , r ) ; } } B ( ) throws Exception { in = new BufferedInputStream ( new FileInputStream ( \" B - small - attempt0 . in \" ) ) ; scan = new Scanner ( in ) ; } public static void main ( String [ ] args ) throws Exception { Locale . setDefault ( Locale . US ) ; new B ( ) . solveAll ( ) ; } }" ]
[ "import psyco NEW_LINE psyco . full ( ) NEW_LINE def solve ( N , M , A ) : NEW_LINE INDENT for x1 in range ( N + 1 ) : NEW_LINE INDENT for y1 in range ( M + 1 ) : NEW_LINE INDENT for x2 in range ( N + 1 ) : NEW_LINE INDENT for y2 in range ( M + 1 ) : NEW_LINE INDENT S = abs ( x1 * y2 - x2 * y1 ) NEW_LINE if S == A : NEW_LINE INDENT return \" % d ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d \" % ( 0 , 0 , x1 , y1 , x2 , y2 ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT return \" IMPOSSIBLE \" NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT C = input ( ) NEW_LINE for case in range ( C ) : NEW_LINE INDENT N , M , A = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE print \" Case ▁ # % d : \" % ( case + 1 ) , solve ( N , M , A ) NEW_LINE DEDENT DEDENT", "def process ( n , m , a ) : NEW_LINE INDENT if n * m < a : return None NEW_LINE for x1 in xrange ( n + 1 ) : NEW_LINE INDENT for y1 in xrange ( m + 1 ) : NEW_LINE INDENT for x2 in xrange ( max ( x1 - n , - n ) , min ( x1 + n , n ) + 1 ) : NEW_LINE INDENT for y2 in xrange ( max ( y1 - m , - m ) , min ( y1 + m , m ) + 1 ) : NEW_LINE INDENT if abs ( x2 * y1 - y2 * x1 ) == a : NEW_LINE INDENT xmin = - min ( 0 , x1 , x2 ) NEW_LINE ymin = - min ( 0 , y1 , y2 ) NEW_LINE return ( ( xmin , ymin ) , ( x1 + xmin , y1 + ymin ) , ( x2 + xmin , y2 + ymin ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT return None NEW_LINE DEDENT import sys NEW_LINE next = iter ( sys . stdin ) . next NEW_LINE ncases = int ( next ( ) ) NEW_LINE for i in xrange ( ncases ) : NEW_LINE INDENT n , m , a = map ( int , next ( ) . split ( ) ) NEW_LINE coords = process ( n , m , a ) NEW_LINE if coords is None : NEW_LINE INDENT print ' Case ▁ # % d : ▁ IMPOSSIBLE ' % ( i + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT assert abs ( ( coords [ 2 ] [ 0 ] - coords [ 0 ] [ 0 ] ) * ( coords [ 1 ] [ 1 ] - coords [ 0 ] [ 1 ] ) - ( coords [ 1 ] [ 0 ] - coords [ 0 ] [ 0 ] ) * ( coords [ 2 ] [ 1 ] - coords [ 0 ] [ 1 ] ) ) == a NEW_LINE print ' Case ▁ # % d : ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d ' % ( i + 1 , coords [ 0 ] [ 0 ] , coords [ 0 ] [ 1 ] , coords [ 1 ] [ 0 ] , coords [ 1 ] [ 1 ] , coords [ 2 ] [ 0 ] , coords [ 2 ] [ 1 ] ) NEW_LINE DEDENT sys . stdout . flush ( ) NEW_LINE DEDENT", "import psyco NEW_LINE import sys NEW_LINE psyco . profile ( ) NEW_LINE def main ( ) : NEW_LINE INDENT rl = sys . stdin . readline NEW_LINE for t in xrange ( int ( rl ( ) ) ) : NEW_LINE INDENT n , m , a = [ int ( x ) for x in rl ( ) . strip ( ) . split ( ) ] NEW_LINE ans = False NEW_LINE val = { } NEW_LINE for x in xrange ( 0 , n + 1 ) : NEW_LINE INDENT for y in xrange ( 0 , m + 1 ) : NEW_LINE INDENT if x * y not in val : NEW_LINE INDENT val [ x * y ] = ( x , y ) NEW_LINE DEDENT DEDENT DEDENT for x in xrange ( 1 , n + 1 ) : NEW_LINE INDENT for y in xrange ( a / x , m + 1 ) : NEW_LINE INDENT if x * y < a : NEW_LINE INDENT continue NEW_LINE DEDENT if x * y - a in val : NEW_LINE INDENT v = val [ x * y - a ] NEW_LINE ans = ( 0 , 0 , x , v [ 1 ] , v [ 0 ] , y ) NEW_LINE break NEW_LINE DEDENT DEDENT if ans : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ' % ( t + 1 ) , NEW_LINE if ans : NEW_LINE INDENT for i in ans : NEW_LINE INDENT print i , NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ' IMPOSSIBLE ' , NEW_LINE DEDENT print NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "FI = ' B - large . in ' NEW_LINE def case ( fi , fo , num ) : NEW_LINE INDENT N , M , A = map ( int , fi . readline ( ) . split ( ) ) NEW_LINE for X in xrange ( 1 , N + 1 ) : NEW_LINE INDENT for Y in xrange ( A / X , M + 1 ) : NEW_LINE INDENT for x in xrange ( 1 , X + 1 ) : NEW_LINE INDENT y = ( X * Y - A ) / x NEW_LINE if y >= 0 and A == X * Y - x * y : NEW_LINE INDENT fo . write ( ' Case ▁ # % d : ▁ 0 ▁ 0 ▁ % d ▁ % d ▁ % d ▁ % d \\n ' % ( num , x , Y , X , y ) ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT DEDENT fo . write ( ' Case ▁ # % d : ▁ IMPOSSIBLE \\n ' % num ) NEW_LINE DEDENT def rl ( f , n ) : NEW_LINE INDENT return [ f . readline ( ) for i in xrange ( n ) ] NEW_LINE DEDENT def zw ( fs , es ) : NEW_LINE INDENT return [ f ( e ) for f , e in zip ( fs , es ) ] NEW_LINE DEDENT def cases ( fi , fo ) : NEW_LINE INDENT for i in xrange ( int ( fi . readline ( ) ) ) : NEW_LINE INDENT case ( fi , fo , i + 1 ) NEW_LINE DEDENT DEDENT fi = open ( FI ) NEW_LINE fo = open ( ' out . txt ' , ' w ' ) NEW_LINE cases ( fi , fo ) NEW_LINE fi . close ( ) NEW_LINE fo . close ( ) NEW_LINE f = open ( ' out . txt ' ) NEW_LINE print f . read ( ) NEW_LINE", "import sys NEW_LINE import math NEW_LINE def do_test ( input ) : NEW_LINE INDENT line = input . readline ( ) . split ( ' ▁ ' ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE M = int ( line [ 1 ] ) NEW_LINE A = int ( line [ 2 ] ) NEW_LINE flipped = False NEW_LINE if M > N : NEW_LINE INDENT z = M NEW_LINE M = N NEW_LINE N = z NEW_LINE flipped = True NEW_LINE DEDENT if A > M * N : NEW_LINE INDENT return \" IMPOSSIBLE \" NEW_LINE DEDENT beta = - ( ( - A ) % M ) NEW_LINE alpha = ( A - beta ) // M + beta NEW_LINE a = M NEW_LINE b = M - 1 NEW_LINE x2 = 0 NEW_LINE x1 = alpha - beta NEW_LINE x3 = - beta NEW_LINE y3 = 0 NEW_LINE y1 = b NEW_LINE y2 = a NEW_LINE if not flipped : NEW_LINE INDENT return str ( x1 ) + ' ▁ ' + str ( y1 ) + ' ▁ ' + str ( x2 ) + ' ▁ ' + str ( y2 ) + ' ▁ ' + str ( x3 ) + ' ▁ ' + str ( y3 ) NEW_LINE DEDENT else : NEW_LINE INDENT return str ( y1 ) + ' ▁ ' + str ( x1 ) + ' ▁ ' + str ( y2 ) + ' ▁ ' + str ( x2 ) + ' ▁ ' + str ( y3 ) + ' ▁ ' + str ( x3 ) NEW_LINE DEDENT DEDENT input = sys . stdin NEW_LINE N = int ( input . readline ( ) ) NEW_LINE for test in range ( N ) : NEW_LINE INDENT answer = do_test ( input ) NEW_LINE print ' Case ▁ # % ( case ) d : ▁ % ( answer ) s ' % { ' case ' : test + 1 , ' answer ' : answer } NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT" ]
codejam_08_54
[ "import java . util . Scanner ; public class EndlessKnight { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int numCases = in . nextInt ( ) ; for ( int i = 0 ; i < numCases ; i ++ ) doCase ( i + 1 , in ) ; } private static void doCase ( int caseNum , Scanner in ) { int H = in . nextInt ( ) ; int W = in . nextInt ( ) ; int R = in . nextInt ( ) ; int [ ] [ ] memoized = new int [ W ] [ H ] ; for ( int [ ] arr : memoized ) for ( int i = 0 ; i < arr . length ; i ++ ) arr [ i ] = - 1 ; for ( int i = 0 ; i < R ; i ++ ) { int rockY = in . nextInt ( ) ; int rockX = in . nextInt ( ) ; memoized [ W - rockX ] [ H - rockY ] = 0 ; } int total = findMoves ( W - 1 , H - 1 , memoized ) ; System . out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + total ) ; } private static int findMoves ( int i , int j , int [ ] [ ] memoized ) { if ( i == 0 && j == 0 ) return 1 ; if ( i < 1 || j < 1 ) return 0 ; if ( memoized [ i ] [ j ] != - 1 ) return memoized [ i ] [ j ] ; memoized [ i ] [ j ] = ( findMoves ( i - 1 , j - 2 , memoized ) + findMoves ( i - 2 , j - 1 , memoized ) ) % 10007 ; return memoized [ i ] [ j ] ; } }", "import java . util . * ; public class DSmall { static final int P = 10007 ; public static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= N ; caseID ++ ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; boolean [ ] [ ] rock = new boolean [ H ] [ W ] ; for ( int i = 0 ; i < R ; i ++ ) { int r = sc . nextInt ( ) - 1 ; int c = sc . nextInt ( ) - 1 ; rock [ r ] [ c ] = true ; } int [ ] [ ] count = new int [ H + 2 ] [ W + 2 ] ; count [ 0 ] [ 0 ] = 1 ; for ( int y = 0 ; y < H ; y ++ ) { for ( int x = 0 ; x < W ; x ++ ) { if ( rock [ y ] [ x ] ) continue ; count [ y + 2 ] [ x + 1 ] += count [ y ] [ x ] ; count [ y + 2 ] [ x + 1 ] %= P ; count [ y + 1 ] [ x + 2 ] += count [ y ] [ x ] ; count [ y + 1 ] [ x + 2 ] %= P ; } } System . out . printf ( \" Case ▁ # % d : ▁ % d % n \" , caseID , count [ H - 1 ] [ W - 1 ] ) ; } } }", "import static java . lang . Math . * ; import static java . math . BigInteger . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; import java . math . * ; import java . util . * ; public class D { public static void main ( String [ ] args ) { new D ( ) . run ( ) ; } long M = 10007 ; static final int [ ] di = { 1 , 2 } , dj = { 2 , 1 } ; void run ( ) { Scanner sc = new Scanner ( System . in ) ; int on = sc . nextInt ( ) ; for ( int o = 1 ; o <= on ; o ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ \" , o ) ; int h = sc . nextInt ( ) , w = sc . nextInt ( ) , r = sc . nextInt ( ) ; boolean [ ] [ ] bs = new boolean [ h ] [ w ] ; for ( int i = 0 ; i < r ; i ++ ) bs [ sc . nextInt ( ) - 1 ] [ sc . nextInt ( ) - 1 ] = true ; long [ ] [ ] dp = new long [ h ] [ w ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) if ( ! bs [ i ] [ j ] ) { for ( int k = 0 ; k < 2 ; k ++ ) { int ii = i + di [ k ] , jj = j + dj [ k ] ; if ( ii < h && jj < w ) dp [ ii ] [ jj ] = ( dp [ ii ] [ jj ] + dp [ i ] [ j ] ) % M ; } } } System . out . println ( dp [ h - 1 ] [ w - 1 ] ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } }", "import java . io . PrintWriter ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Scanner ; public class D { static Scanner in ; static PrintWriter out ; public static void main ( String [ ] args ) throws FileNotFoundException { in = new Scanner ( new File ( \" input . txt \" ) ) ; out = new PrintWriter ( \" output . txt \" ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + new D ( ) . solve ( ) ) ; } out . close ( ) ; } private Object solve ( ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int r = in . nextInt ( ) ; boolean [ ] [ ] a = new boolean [ n ] [ m ] ; for ( int i = 0 ; i < r ; i ++ ) { a [ in . nextInt ( ) - 1 ] [ in . nextInt ( ) - 1 ] = true ; } int [ ] [ ] d = new int [ n ] [ m ] ; d [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < m ; j ++ ) if ( ! a [ i ] [ j ] ) { if ( i > 1 ) { d [ i ] [ j ] += d [ i - 2 ] [ j - 1 ] ; } if ( j > 1 ) { d [ i ] [ j ] += d [ i - 1 ] [ j - 2 ] ; } d [ i ] [ j ] %= 10007 ; } } return d [ n - 1 ] [ m - 1 ] ; } }", "import java . util . * ; import java . io . * ; public class x { static int fla ( int p , int q ) { int ti = 2 * q - p ; int tj = 2 * p - q ; if ( ti % 3 != 0 || tj % 3 != 0 ) return 0 ; ti /= 3 ; tj /= 3 ; return 0 ; } ; public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; for ( int tt = 1 ; tt <= t ; tt ++ ) { int h = in . nextInt ( ) ; int w = in . nextInt ( ) ; int r = in . nextInt ( ) ; int [ ] a = new int [ r ] , b = new int [ r ] ; boolean [ ] [ ] f = new boolean [ h + 1 ] [ w + 1 ] ; for ( int i = 0 ; i < r ; i ++ ) { a [ i ] = in . nextInt ( ) ; b [ i ] = in . nextInt ( ) ; f [ a [ i ] ] [ b [ i ] ] = true ; } ; int [ ] [ ] D = new int [ h + 1 ] [ w + 1 ] ; D [ 1 ] [ 1 ] = 1 ; for ( int i = 2 ; i <= h ; i ++ ) for ( int j = 2 ; j <= w ; j ++ ) if ( ! f [ i ] [ j ] ) D [ i ] [ j ] += ( D [ i - 2 ] [ j - 1 ] + D [ i - 1 ] [ j - 2 ] ) % 10007 ; System . out . println ( \" Case ▁ # \" + tt + \" : ▁ \" + D [ h ] [ w ] ) ; } ; } ; } ;" ]
[ "rocks = { } NEW_LINE num_ways = { } NEW_LINE mod = 10007 NEW_LINE def num_u_ways ( r , c , H , W ) : NEW_LINE INDENT if ( r >= H or c >= W ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( ( r , c ) in rocks ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( r == H - 1 and c == W - 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( ( r , c ) in num_ways ) : NEW_LINE INDENT return num_ways [ ( r , c ) ] NEW_LINE DEDENT a = num_u_ways ( r + 2 , c + 1 , H , W ) NEW_LINE b = num_u_ways ( r + 1 , c + 2 , H , W ) NEW_LINE num_ways [ ( r , c ) ] = ( a + b ) % mod NEW_LINE return num_ways [ ( r , c ) ] NEW_LINE DEDENT filename = \" D - small - attempt0 . in \" NEW_LINE f = open ( filename , ' r ' ) NEW_LINE of = open ( \" D - small . out \" , ' w ' ) NEW_LINE N = int ( f . readline ( ) ) NEW_LINE for x in xrange ( N ) : NEW_LINE INDENT l = f . readline ( ) . split ( ' ▁ ' ) NEW_LINE H = int ( l [ 0 ] ) NEW_LINE W = int ( l [ 1 ] ) NEW_LINE R = int ( l [ 2 ] ) NEW_LINE rocks = { } NEW_LINE for y in xrange ( R ) : NEW_LINE INDENT l = f . readline ( ) . split ( ' ▁ ' ) NEW_LINE rocks [ ( int ( l [ 0 ] ) - 1 , int ( l [ 1 ] ) - 1 ) ] = True NEW_LINE DEDENT num_ways = { } NEW_LINE ans = num_u_ways ( 0 , 0 , H , W ) NEW_LINE print >> of , \" Case ▁ # % d : ▁ % d \" % ( x + 1 , ans ) NEW_LINE DEDENT", "import sys NEW_LINE def isrock ( i , j ) : NEW_LINE INDENT global rocks NEW_LINE for r , c in rocks : NEW_LINE INDENT if r == i and c == j : return True NEW_LINE DEDENT return False NEW_LINE DEDENT filename = sys . argv [ 1 ] NEW_LINE inputfile = file ( filename , ' r ' ) NEW_LINE numcases = int ( inputfile . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , numcases + 1 ) : NEW_LINE INDENT H , W , R = map ( long , inputfile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE rocks = [ ] NEW_LINE for k in range ( R ) : NEW_LINE INDENT r , c = map ( long , inputfile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE rocks . append ( ( r - 1 , c - 1 ) ) NEW_LINE DEDENT F = [ [ 0 ] * W for i in range ( H ) ] NEW_LINE F [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , H ) : NEW_LINE INDENT for j in range ( 1 , W ) : NEW_LINE INDENT n = 0 NEW_LINE if i > 0 and j > 1 and not isrock ( i - 1 , j - 2 ) : NEW_LINE INDENT n += F [ i - 1 ] [ j - 2 ] NEW_LINE DEDENT if i > 1 and j > 0 and not isrock ( i - 2 , j - 1 ) : NEW_LINE INDENT n += F [ i - 2 ] [ j - 1 ] NEW_LINE DEDENT F [ i ] [ j ] = n NEW_LINE DEDENT DEDENT M = F [ H - 1 ] [ W - 1 ] NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( case , M % 10007 ) NEW_LINE DEDENT", "import sys NEW_LINE CACHE = { } NEW_LINE def do_count ( x , y , rooks , h , w ) : NEW_LINE INDENT k = ( x , y , rooks , h , w ) NEW_LINE p = ( x , y ) NEW_LINE if CACHE . has_key ( k ) : return CACHE [ k ] NEW_LINE if p in rooks : return 0 NEW_LINE if x > h or y > w : return 0 NEW_LINE if x == h and y == w : return 1 NEW_LINE count = 0 NEW_LINE count = count + do_count ( x + 2 , y + 1 , rooks , h , w ) NEW_LINE count = count + do_count ( x + 1 , y + 2 , rooks , h , w ) NEW_LINE count %= 10007 NEW_LINE CACHE [ k ] = count NEW_LINE return count NEW_LINE DEDENT def do_trial ( f ) : NEW_LINE INDENT H , W , R = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE rooks = set ( ) NEW_LINE for i in range ( R ) : NEW_LINE INDENT rooks . add ( tuple ( [ int ( x ) for x in f . readline ( ) . split ( ) ] ) ) NEW_LINE DEDENT rooks = frozenset ( rooks ) NEW_LINE global CACHE NEW_LINE CACHE = { } NEW_LINE return do_count ( 1 , 1 , rooks , H , W ) NEW_LINE DEDENT f = sys . stdin NEW_LINE count = int ( f . readline ( ) ) NEW_LINE for i in range ( count ) : NEW_LINE INDENT r = do_trial ( f ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , r ) NEW_LINE DEDENT", "def waysToReachExit ( r , c ) : NEW_LINE INDENT if c == W and r == H : NEW_LINE INDENT return 1 NEW_LINE DEDENT if c > W or r > H : NEW_LINE INDENT return 0 NEW_LINE DEDENT isRock = False NEW_LINE for rock in rocks : NEW_LINE INDENT if rock [ 0 ] == r and rock [ 1 ] == c : NEW_LINE INDENT isRock = True NEW_LINE DEDENT DEDENT if isRock == True : NEW_LINE INDENT return 0 NEW_LINE DEDENT if squareData . has_key ( ( r , c ) ) : NEW_LINE INDENT result = squareData [ ( r , c ) ] NEW_LINE return result NEW_LINE DEDENT else : NEW_LINE INDENT result = waysToReachExit ( r + 1 , c + 2 ) + waysToReachExit ( r + 2 , c + 1 ) NEW_LINE squareData [ r , c ] = result NEW_LINE return result NEW_LINE DEDENT DEDENT inFile = open ( \" D - small - attempt0 . in \" , \" r \" ) NEW_LINE outFile = open ( \" D - small - out . out \" , \" w \" ) NEW_LINE cases = int ( inFile . readline ( ) ) NEW_LINE for caseNum in range ( 1 , cases + 1 ) : NEW_LINE INDENT params = inFile . readline ( ) . rstrip ( ) NEW_LINE params = params . split ( \" ▁ \" ) NEW_LINE params = map ( int , params ) NEW_LINE H = params [ 0 ] NEW_LINE W = params [ 1 ] NEW_LINE R = params [ 2 ] NEW_LINE rocks = [ ] NEW_LINE for i in range ( R ) : NEW_LINE INDENT rock = inFile . readline ( ) . rstrip ( ) NEW_LINE rock = rock . split ( \" ▁ \" ) NEW_LINE rock = map ( int , rock ) NEW_LINE rocks . append ( rock ) NEW_LINE DEDENT squareData = { } NEW_LINE answer = waysToReachExit ( 1 , 1 ) NEW_LINE answer = answer % 10007 NEW_LINE outString = \" Case ▁ # \" + str ( caseNum ) + \" : ▁ \" + str ( answer ) + \" \\n \" NEW_LINE print outString . rstrip ( ) NEW_LINE outFile . write ( outString ) NEW_LINE DEDENT inFile . close ( ) NEW_LINE outFile . close ( ) NEW_LINE", "import sys NEW_LINE import re NEW_LINE from Numeric import * NEW_LINE sys . setcheckinterval ( 10000 ) NEW_LINE PI = arccos ( - 1 ) NEW_LINE PI_2 = arccos ( - 1 ) / 2 NEW_LINE cache = { } NEW_LINE r = { } NEW_LINE def solveR ( x , y , H , W ) : NEW_LINE INDENT if x == W and y == H : return 1 NEW_LINE if globals ( ) [ \" cache \" ] . has_key ( ( x , y ) ) : return globals ( ) [ \" cache \" ] [ ( x , y ) ] NEW_LINE total = 0 NEW_LINE if x + 2 <= W and y + 1 <= H and ( not r . has_key ( ( x + 2 , y + 1 ) ) ) : total += solveR ( x + 2 , y + 1 , H , W ) NEW_LINE if x + 1 <= W and y + 2 <= H and ( not r . has_key ( ( x + 1 , y + 2 ) ) ) : total += solveR ( x + 1 , y + 2 , H , W ) NEW_LINE total = total % 10007 NEW_LINE globals ( ) [ \" cache \" ] [ ( x , y ) ] = total NEW_LINE return total NEW_LINE DEDENT def solve ( caseNum ) : NEW_LINE INDENT H , W , R = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE globals ( ) [ \" r \" ] = { } NEW_LINE for i in range ( R ) : NEW_LINE INDENT tmp = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( \" ▁ \" ) ) NEW_LINE globals ( ) [ \" r \" ] [ ( tmp [ 1 ] , tmp [ 0 ] ) ] = 1 NEW_LINE DEDENT globals ( ) [ \" cache \" ] = { } NEW_LINE total = solveR ( 1 , 1 , H , W ) NEW_LINE sys . stdout . write ( \" Case ▁ # % d : ▁ % s \" % ( caseNum , total ) ) NEW_LINE DEDENT casesCount = int ( re . findall ( r ' [ \\d ] + ' , sys . stdin . readline ( ) ) [ 0 ] ) NEW_LINE first = True NEW_LINE for case in range ( 1 , casesCount + 1 ) : NEW_LINE INDENT if ( first ) : NEW_LINE INDENT first = False NEW_LINE DEDENT else : NEW_LINE INDENT print \" \" NEW_LINE DEDENT solve ( case ) NEW_LINE DEDENT" ]
codejam_16_04
[ "import java . io . * ; import java . util . * ; public class Round0D { int cases ; void process ( Scanner scanner , PrintStream out ) throws IOException { cases = scanner . nextInt ( ) ; scanner . nextLine ( ) ; for ( int curCase = 0 ; curCase < cases ; curCase ++ ) { long K = scanner . nextLong ( ) ; long C = scanner . nextLong ( ) ; long S = scanner . nextLong ( ) ; if ( C * S < K ) { out . println ( \" Case ▁ # \" + ( curCase + 1 ) + \" : ▁ IMPOSSIBLE \" ) ; } else { out . print ( \" Case ▁ # \" + ( curCase + 1 ) + \" : \" ) ; long k = 0 ; for ( long s = 0 ; s < S && k < K ; s ++ ) { long num = 0 ; for ( int i = 0 ; i < C ; i ++ ) { num = num * K + ( k % K ) ; k ++ ; } out . print ( ' ▁ ' ) ; out . print ( num + 1 ) ; } out . println ( ) ; } } } Round0D ( ) throws IOException { Scanner in = new Scanner ( new File ( \" C : \\\\ Users \\\\ Olaf \\\\ Downloads \\\\ D - large . in \" ) ) ; PrintStream out = new PrintStream ( \" out - D - large . txt \" ) ; process ( in , out ) ; in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new Round0D ( ) ; } }", "package qualification ; import java . io . * ; import java . math . * ; import java . util . * ; public class D_Fractiles { private static final String FILENAME = \" data / qualification / D - large \" ; private static final boolean STANDARD_OUTPUT = false ; private static BufferedReader in = null ; private static PrintStream out = null ; public static void main ( String [ ] args ) throws Throwable { try ( BufferedReader reader = in = new BufferedReader ( new FileReader ( FILENAME + \" . in \" ) ) ) { try ( PrintStream writer = out = ! STANDARD_OUTPUT ? new PrintStream ( FILENAME + \" . out \" ) : System . out ) { process ( ) ; } } } private static void process ( ) throws Throwable { for ( int caseNumber = 1 , T = Integer . parseInt ( in . readLine ( ) ) ; caseNumber <= T ; caseNumber ++ ) { StringTokenizer tokenizer = new StringTokenizer ( in . readLine ( ) ) ; K = Integer . parseInt ( tokenizer . nextToken ( ) ) ; C = Integer . parseInt ( tokenizer . nextToken ( ) ) ; S = Integer . parseInt ( tokenizer . nextToken ( ) ) ; positions = new ArrayList < > ( ) ; visited = new HashSet < > ( ) ; f ( BigInteger . ZERO , 0 ) ; out . print ( \" Case ▁ # \" + caseNumber + \" : \" ) ; if ( positions . size ( ) <= S ) { for ( BigInteger position : positions ) { out . print ( \" ▁ \" + position . add ( BigInteger . ONE ) ) ; } out . println ( ) ; } else { out . println ( \" ▁ IMPOSSIBLE \" ) ; } } } static int K , C , S ; static List < BigInteger > positions ; static Set < Integer > visited ; static void f ( BigInteger start , int c ) { if ( c == C || visited . size ( ) == K ) { positions . add ( start ) ; } else { BigInteger childSize = BigInteger . valueOf ( K ) . pow ( C - c - 1 ) ; for ( int i = 0 ; i < K ; i ++ ) { if ( ! visited . contains ( i ) ) { visited . add ( i ) ; f ( start . add ( childSize . multiply ( BigInteger . valueOf ( i ) ) ) , c + 1 ) ; if ( c > 0 ) break ; } } } } }", "package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long k = in . nextInt ( ) ; long c = in . nextInt ( ) ; int s = in . nextInt ( ) ; System . out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; if ( c * s < k ) { System . out . println ( \" IMPOSSIBLE \" ) ; } else { long val = 0 ; while ( s > 0 ) { long exp = 1 ; long total = 0 ; while ( exp < Math . pow ( k , c ) ) { total += val * exp ; exp *= k ; if ( val < k - 1 ) { val ++ ; } } s -- ; System . out . print ( total + 1 ) ; if ( total + 1 == Math . pow ( k , c ) ) { s = 0 ; } if ( s != 0 ) { System . out . print ( \" ▁ \" ) ; } else { System . out . println ( ) ; } } } } } }", "package cj2016 . qr ; import java . io . * ; import java . util . * ; public class D { Scanner sc ; PrintWriter pw ; int K , C , S ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : \" D - large \" ; try { new D ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + \" . in \" ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + \" . out \" ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; System . out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; solve ( ) ; } System . out . println ( \" Finished . \" ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { K = sc . nextInt ( ) ; C = sc . nextInt ( ) ; S = sc . nextInt ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } public void solve ( ) { if ( C * S < K ) { println ( \" IMPOSSIBLE \" ) ; return ; } int M = ( K + C - 1 ) / C ; long [ ] pos = new long [ M ] ; for ( int i = 0 ; i < K ; i ++ ) { pos [ i / C ] += pow ( K , i % C ) * i ; } for ( int i = 0 ; i < M ; i ++ ) print ( ( pos [ i ] + 1 ) + ( i == M - 1 ? \" \\n \" : \" ▁ \" ) ) ; } long pow ( long a , int b ) { long ans = 1 ; for ( int i = 0 ; i < b ; i ++ ) ans *= a ; return ans ; } }", "import java . io . * ; import java . util . * ; public class D { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( \" src / D - large . in \" ) ) ) ) ; String output = \" \" ; int t = sc . nextInt ( ) ; for ( int i = 1 ; i <= t ; i ++ ) { int k = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; if ( s * c < k ) { output += \" Case ▁ # \" + i + \" : ▁ IMPOSSIBLE \\n \" ; continue ; } ArrayList < Long > nums = new ArrayList < Long > ( ) ; for ( int j = 0 ; j < s ; j ++ ) { if ( j * c >= k ) break ; long next = 0 ; long mult = 1 ; for ( int m = 0 ; m < c ; m ++ ) { if ( j * c + m >= k ) break ; next += ( j * c + m ) * mult ; mult *= k ; } next ++ ; nums . add ( next ) ; } String toAdd = \" \" ; for ( int j = 0 ; j < nums . size ( ) ; j ++ ) { toAdd += \" ▁ \" + nums . get ( j ) ; } output += \" Case ▁ # \" + i + \" : \" + toAdd + \" \\n \" ; } BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( \" src / D - large . out \" ) , \" utf - 8\" ) ) ; bw . write ( output ) ; bw . close ( ) ; } }" ]
[ "import sys NEW_LINE def fract ( K , C , S ) : NEW_LINE INDENT if S * C < K : return \" IMPOSSIBLE \" NEW_LINE l = [ ] NEW_LINE for c in range ( 0 , K , C ) : NEW_LINE INDENT t = 0 NEW_LINE for i in range ( C ) : t = t * K + min ( c + i , K - 1 ) NEW_LINE l . append ( t ) NEW_LINE DEDENT return ' ▁ ' . join ( [ str ( i + 1 ) for i in l ] ) NEW_LINE DEDENT case = 0 NEW_LINE for x in sys . stdin : NEW_LINE INDENT if case > 0 : NEW_LINE INDENT [ K , C , S ] = [ int ( y ) for y in x . strip ( ) . split ( ) ] NEW_LINE print \" Case ▁ # % d : \" % case , fract ( K , C , S ) NEW_LINE DEDENT case += 1 NEW_LINE DEDENT", "t = int ( input ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT k , c , s = map ( int , input ( ) . split ( ) ) NEW_LINE if c * s < k : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ IMPOSSIBLE \" % ( i + 1 ) ) NEW_LINE continue NEW_LINE DEDENT pos = [ ] NEW_LINE x = 0 NEW_LINE while x < k : NEW_LINE INDENT a = 0 NEW_LINE for _ in range ( c ) : NEW_LINE INDENT a *= k NEW_LINE a += min ( x , k - 1 ) NEW_LINE if x < k : NEW_LINE INDENT x += 1 NEW_LINE DEDENT DEDENT pos . append ( str ( a + 1 ) ) NEW_LINE DEDENT print ( \" Case ▁ # % d : ▁ % s \" % ( i + 1 , \" ▁ \" . join ( pos ) ) ) NEW_LINE DEDENT", "import os , inspect NEW_LINE problemName = ' fractiles ' NEW_LINE runOnRealData = True NEW_LINE def solution ( K , C , S ) : NEW_LINE INDENT necessaryTiles = ( K + C - 1 ) / C NEW_LINE if S < necessaryTiles : NEW_LINE INDENT return [ ' IMPOSSIBLE ' ] NEW_LINE DEDENT result = [ ] NEW_LINE k = 0 NEW_LINE level = 0 NEW_LINE tile = 0 NEW_LINE while len ( result ) < necessaryTiles : NEW_LINE INDENT tile = ( tile * K ) + min ( k , K - 1 ) NEW_LINE level += 1 NEW_LINE k += 1 NEW_LINE if level == C : NEW_LINE INDENT result . append ( tile + 1 ) NEW_LINE level = 0 NEW_LINE tile = 0 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT currentDir = os . path . dirname ( os . path . abspath ( inspect . getfile ( inspect . currentframe ( ) ) ) ) NEW_LINE inputString = ' D - large . in ' NEW_LINE outputString = problemName + ( ' _ example _ output ' if not runOnRealData else ' _ output ' ) NEW_LINE inFile = os . path . join ( currentDir , ' inputfiles ' , inputString ) NEW_LINE outFile = os . path . join ( currentDir , ' outputfiles ' , ' % s . txt ' % outputString ) NEW_LINE if os . path . exists ( outFile ) : NEW_LINE INDENT os . remove ( outFile ) NEW_LINE DEDENT with open ( inFile , ' r ' ) as inputfile : NEW_LINE INDENT numberOfCases = int ( inputfile . readline ( ) ) NEW_LINE for case in xrange ( 1 , numberOfCases + 1 ) : NEW_LINE INDENT [ K , C , S ] = map ( int , inputfile . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE result = solution ( K , C , S ) NEW_LINE with open ( outFile , ' a ' ) as f : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( case , ' ▁ ' . join ( map ( str , result ) ) ) ) NEW_LINE DEDENT DEDENT DEDENT", "import math NEW_LINE import sys NEW_LINE def findsol ( K , C , S ) : NEW_LINE INDENT if C * S < K : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT a = [ ] NEW_LINE flag = 0 NEW_LINE for ii in range ( S ) : NEW_LINE INDENT tmp = [ ] NEW_LINE for jj in range ( C ) : NEW_LINE INDENT x = ii * C + jj NEW_LINE if ( x >= K ) : NEW_LINE INDENT x = K - 1 NEW_LINE flag = 1 NEW_LINE DEDENT tmp . append ( x ) NEW_LINE DEDENT tmp2 = 0 NEW_LINE for jj in tmp : NEW_LINE INDENT tmp2 = K * tmp2 + jj NEW_LINE DEDENT a . append ( tmp2 + 1 ) NEW_LINE if ( flag == 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return a NEW_LINE DEDENT def convertnums ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE ii = 0 NEW_LINE for jj in range ( len ( s ) ) : NEW_LINE INDENT if s [ jj ] == ' ▁ ' : NEW_LINE INDENT if ( ii < jj ) : NEW_LINE INDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE ii = jj + 1 NEW_LINE DEDENT DEDENT DEDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE return a NEW_LINE DEDENT fidi = open ( ' D - large . in ' , ' r ' ) NEW_LINE fido = open ( ' a . out ' , ' w ' ) NEW_LINE T = fidi . readline ( ) NEW_LINE T = int ( T ) NEW_LINE for ii in range ( 1 , T + 1 ) : NEW_LINE INDENT tmp = fidi . readline ( ) NEW_LINE tmp = convertnums ( tmp ) NEW_LINE K = int ( tmp [ 0 ] ) NEW_LINE C = int ( tmp [ 1 ] ) NEW_LINE S = int ( tmp [ 2 ] ) NEW_LINE a = findsol ( K , C , S ) NEW_LINE if ( a [ 0 ] == ' I ' ) : NEW_LINE INDENT fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + a + ' \\n ' ) NEW_LINE print ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + a ) NEW_LINE DEDENT else : NEW_LINE INDENT fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' ) NEW_LINE for jj in a : NEW_LINE INDENT fido . write ( str ( jj ) + ' ▁ ' ) NEW_LINE DEDENT fido . write ( ' \\n ' ) NEW_LINE print ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' , str ( a ) ) NEW_LINE DEDENT DEDENT fidi . close ( ) NEW_LINE fido . close ( ) NEW_LINE", "import os , sys , ljqpy , time NEW_LINE time . clock ( ) NEW_LINE def RunSmall ( v ) : NEW_LINE INDENT k , c , s = map ( int , v . split ( ) ) NEW_LINE ans = [ ( i + 1 ) * k ** ( c - 1 ) for i in range ( k ) ] NEW_LINE return ' ▁ ' . join ( str ( x ) for x in ans ) NEW_LINE DEDENT def Run ( v ) : NEW_LINE INDENT k , c , s = map ( int , v . split ( ) ) NEW_LINE if s * c < k : return ' IMPOSSIBLE ' NEW_LINE ans = [ ] NEW_LINE for ii in range ( 1 , k + 1 , c ) : NEW_LINE INDENT z = 1 NEW_LINE for jj in range ( ii , min ( [ ii + c , k + 1 ] ) ) : NEW_LINE INDENT z += ( jj - 1 ) * ( k ** ( c - ( jj - ii ) - 1 ) ) NEW_LINE DEDENT ans . append ( z ) NEW_LINE DEDENT return ' ▁ ' . join ( str ( x ) for x in ans ) NEW_LINE DEDENT lst = ljqpy . LoadList ( ' D - large . in ' ) NEW_LINE outf = ' D - large . out ' NEW_LINE with open ( outf , ' w ' ) as fout : NEW_LINE INDENT for k , v in enumerate ( lst [ 1 : ] ) : NEW_LINE INDENT fout . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( 1 + k , Run ( v ) ) ) NEW_LINE DEDENT DEDENT os . system ( outf ) NEW_LINE print ( ' completed ' ) NEW_LINE" ]
codejam_09_03
[ "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Welcome { public static void main ( String [ ] args ) throws Exception { int i , j , k , p ; char c ; int res ; String score ; String line ; String sentence ; String original = \" welcome ▁ to ▁ code ▁ jam \" ; int N , M ; BufferedReader br = new BufferedReader ( new FileReader ( \" C - large . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( \" C - large . out \" ) ) ) ; StringTokenizer st ; line = br . readLine ( ) ; N = Integer . parseInt ( line ) ; for ( k = 1 ; k <= N ; k ++ ) { sentence = br . readLine ( ) ; M = sentence . length ( ) ; int opt [ ] [ ] = new int [ M ] [ 19 ] ; for ( i = 0 ; i < M ; i ++ ) { c = sentence . charAt ( i ) ; if ( c == ' w ' ) { opt [ i ] [ 0 ] = 1 ; } for ( j = 1 ; j < 19 ; j ++ ) { if ( c == original . charAt ( j ) ) { for ( p = 0 ; p < i ; p ++ ) { opt [ i ] [ j ] = ( opt [ i ] [ j ] + opt [ p ] [ j - 1 ] ) % 10000 ; } } } } res = 0 ; for ( i = 0 ; i < M ; i ++ ) { res = ( res + opt [ i ] [ 18 ] ) % 10000 ; } score = Integer . toString ( res ) ; while ( score . length ( ) < 4 ) { score = '0' + score ; } out . println ( \" Case ▁ # \" + k + \" : ▁ \" + score ) ; } out . close ( ) ; System . exit ( 0 ) ; } }", "package gcj2009 . qual ; import java . io . * ; import java . util . * ; import static java . lang . Math . * ; public class C { static final int INF = 1 << 20 ; static final int [ ] di = { - 1 , 0 , 0 , 1 } ; static final int [ ] dj = { 0 , - 1 , 1 , 0 } ; static final char [ ] key = \" welcome ▁ to ▁ code ▁ jam \" . toCharArray ( ) ; static final int mod = 10000 ; public void run ( ) { char [ ] input = sc . nextLine ( ) . toCharArray ( ) ; int [ ] dp = new int [ key . length + 1 ] ; dp [ 0 ] = 1 ; for ( char c : input ) for ( int i = key . length - 1 ; i >= 0 ; i -- ) if ( key [ i ] == c ) dp [ i + 1 ] = ( dp [ i + 1 ] + dp [ i ] ) % mod ; System . out . printf ( \" % 04d % n \" , dp [ key . length ] ) ; } public static void main ( String ... args ) { try { System . setIn ( new FileInputStream ( \" C - large . in \" ) ) ; System . setOut ( new PrintStream ( \" C - large . out \" ) ) ; } catch ( Exception e ) { } sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ \" , t ) ; new C ( ) . run ( ) ; } } static Scanner sc ; }", "package qualifiers ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; public class WelcomeToCodeJam { private char [ ] input ; private char [ ] target ; private BigInteger [ ] [ ] memo ; private BigInteger solve ( int inputIdx , int targetIdx ) { if ( memo [ inputIdx ] [ targetIdx ] != null ) return memo [ inputIdx ] [ targetIdx ] ; else { BigInteger ret = BigInteger . ZERO ; if ( inputIdx >= input . length ) { if ( targetIdx >= target . length ) { ret = BigInteger . ONE ; } else ret = BigInteger . ZERO ; } else { if ( targetIdx < target . length ) { char c1 = target [ targetIdx ] ; char c2 = input [ inputIdx ] ; if ( c1 == c2 ) ret = ret . add ( solve ( inputIdx + 1 , targetIdx + 1 ) ) ; } ret = ret . add ( solve ( inputIdx + 1 , targetIdx ) ) ; } memo [ inputIdx ] [ targetIdx ] = ret ; return ret ; } } public String getWelcome ( String inp , String target ) { this . input = inp . toCharArray ( ) ; this . target = target . toCharArray ( ) ; this . memo = new BigInteger [ input . length + 1 ] [ this . target . length + 1 ] ; BigInteger val = solve ( 0 , 0 ) ; String ret = val . toString ( ) ; if ( ret . length ( ) < 4 ) { for ( int i = ret . length ( ) ; i < 4 ; ++ i ) ret = \"0\" + ret ; } else ret = ret . substring ( ret . length ( ) - 4 ) ; return ret ; } public static void main ( String [ ] args ) throws NumberFormatException , IOException { WelcomeToCodeJam obj = new WelcomeToCodeJam ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . valueOf ( br . readLine ( ) ) ; String target = \" welcome ▁ to ▁ code ▁ jam \" ; for ( int i = 1 ; i <= N ; ++ i ) { String inp = br . readLine ( ) ; String ret = obj . getWelcome ( inp , target ) ; System . out . println ( \" Case ▁ # \" + i + \" : ▁ \" + ret ) ; } } }", "import java . io . * ; public class Welcome { static int current [ ] ; static void inc ( int index ) { current [ index ] = ( current [ index ] + 1 ) % 10000 ; } static void move ( int index ) { current [ index + 1 ] = ( current [ index ] + current [ index + 1 ] ) % 10000 ; } private static int solve ( String line ) { String wel = \" welcome ▁ to ▁ code ▁ jam \" ; int length = wel . length ( ) ; current = new int [ length ] ; int i , j ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; for ( j = 0 ; j < length ; j ++ ) { if ( c == wel . charAt ( j ) ) { if ( j > 0 ) { move ( j - 1 ) ; } else { inc ( j ) ; } } } } return current [ length - 1 ] ; } public static void main ( String args [ ] ) { try { BufferedReader reader = new BufferedReader ( new FileReader ( \" src / C - large . in \" ) ) ; BufferedWriter writer = new BufferedWriter ( new FileWriter ( \" output \" ) ) ; int n = Integer . parseInt ( reader . readLine ( ) ) ; int i ; for ( i = 0 ; i < n ; i ++ ) { String line = reader . readLine ( ) ; int result = solve ( line ) ; writer . write ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; if ( result < 1000 ) { writer . write ( \"0\" ) ; } if ( result < 100 ) { writer . write ( \"0\" ) ; } if ( result < 10 ) { writer . write ( \"0\" ) ; } writer . write ( result + \" \" ) ; writer . newLine ( ) ; } reader . close ( ) ; writer . close ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } }", "package gcj ; import java . io . BufferedReader ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . StringTokenizer ; import java . util . regex . Pattern ; public class QR_Q3 { public static void main ( String [ ] args ) throws Exception { new QR_Q3 ( ) . run ( ) ; } int N ; int [ ] map = new int [ 256 ] ; int mod = 10000 ; void run ( ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( \" C - large . in \" ) ) ; PrintWriter pw = new PrintWriter ( \" QR _ Q3 . out \" ) ; N = Integer . parseInt ( br . readLine ( ) ) ; String ph = \" welcome ▁ to ▁ code ▁ jam \" ; int l = ph . length ( ) ; digest ( ph ) ; for ( int n_case = 1 ; n_case <= N ; n_case ++ ) { String line = br . readLine ( ) ; int [ ] result = new int [ l + 1 ] ; result [ 0 ] = 1 ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; int amap = map [ c ] ; for ( int i_p = 0 ; i_p < l ; i_p ++ ) { if ( ( amap & 1 << i_p ) == 0 ) { } else { result [ i_p + 1 ] = ( result [ i_p ] + result [ i_p + 1 ] ) % mod ; } } } pw . printf ( \" Case ▁ # % d : ▁ % 04d \" , n_case , result [ l ] ) ; pw . println ( ) ; } pw . close ( ) ; } private void digest ( String ph ) { for ( int i = 0 ; i < ph . length ( ) ; i ++ ) { char c = ph . charAt ( i ) ; map [ c ] |= 1 << i ; } } }" ]
[ "import sys NEW_LINE S = \" welcome ▁ to ▁ code ▁ jam \" NEW_LINE LS = len ( S ) NEW_LINE def main ( ) : NEW_LINE INDENT n = int ( raw_input ( ) . strip ( ) ) NEW_LINE for I in range ( n ) : NEW_LINE INDENT L = raw_input ( ) . strip ( ) NEW_LINE LL = len ( L ) NEW_LINE t = [ [ 0 ] * ( LL + 1 ) for _ in range ( LS + 1 ) ] NEW_LINE for j in range ( LL + 1 ) : NEW_LINE INDENT t [ 0 ] [ j ] = 1 NEW_LINE DEDENT for i in range ( 1 , LS + 1 ) : NEW_LINE INDENT for j in range ( 1 , LL + 1 ) : NEW_LINE INDENT if S [ i - 1 ] == L [ j - 1 ] : NEW_LINE INDENT t [ i ] [ j ] = t [ i ] [ j - 1 ] + t [ i - 1 ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT t [ i ] [ j ] = t [ i ] [ j - 1 ] NEW_LINE DEDENT DEDENT DEDENT sys . stdout . write ( \" Case ▁ # % d : ▁ % 04d \\n \" % ( I + 1 , t [ LS ] [ LL ] % 10000 ) ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "text = [ line . strip ( \" \\n \" ) for line in open ( \" C . in \" , \" rt \" ) . readlines ( ) ] NEW_LINE outfile = open ( \" C . out \" , \" wt \" ) NEW_LINE MOD = 10000 NEW_LINE searched_string = \" welcome ▁ to ▁ code ▁ jam \" NEW_LINE tests = int ( text [ 0 ] ) NEW_LINE offset = 1 NEW_LINE for test in range ( 1 , tests + 1 ) : NEW_LINE INDENT line = text [ offset ] NEW_LINE print line NEW_LINE line = \" # \" + line NEW_LINE found = { } NEW_LINE for x in range ( len ( line ) ) : NEW_LINE INDENT found [ x ] = [ 0 ] * ( len ( searched_string ) + 1 ) NEW_LINE if x == 0 : NEW_LINE INDENT found [ x ] [ 0 ] = 1 NEW_LINE DEDENT for found_idx in range ( 0 , len ( searched_string ) ) : NEW_LINE INDENT if line [ x ] == searched_string [ found_idx ] : NEW_LINE INDENT for y in range ( x ) : NEW_LINE INDENT found [ x ] [ found_idx + 1 ] += found [ y ] [ found_idx ] NEW_LINE found [ x ] [ found_idx + 1 ] %= MOD NEW_LINE DEDENT DEDENT DEDENT DEDENT ans = str ( ( sum ( line [ - 1 ] for line in found . values ( ) ) ) % MOD ) NEW_LINE ans = \"0\" * ( 4 - len ( ans ) ) + ans NEW_LINE assert ( len ( ans ) == 4 ) NEW_LINE print \" Case ▁ # % s : ▁ % s \" % ( test , ans ) NEW_LINE outfile . write ( \" Case ▁ # % s : ▁ % s \\n \" % ( test , ans ) ) NEW_LINE offset += 1 NEW_LINE DEDENT", "import heapq NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE def memoize ( function ) : NEW_LINE INDENT cache = { } NEW_LINE def decorated_function ( * args ) : NEW_LINE INDENT if args in cache : NEW_LINE INDENT return cache [ args ] NEW_LINE DEDENT else : NEW_LINE INDENT val = function ( * args ) NEW_LINE cache [ args ] = val NEW_LINE return val NEW_LINE DEDENT DEDENT return decorated_function NEW_LINE DEDENT class Case : NEW_LINE INDENT def __init__ ( self , s , caseNum ) : NEW_LINE INDENT self . caseNum = caseNum NEW_LINE self . string = s . read ( ) NEW_LINE DEDENT def solve ( self ) : NEW_LINE INDENT return \" % 04d \" % ( self . count_find ( \" welcome ▁ to ▁ code ▁ jam \" , self . string ) % 10000 ) NEW_LINE DEDENT @ memoize NEW_LINE def count_find ( self , sub , string ) : NEW_LINE INDENT if len ( sub ) == 0 or len ( sub ) > len ( string ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if len ( sub ) == 1 : NEW_LINE INDENT return string . count ( sub ) NEW_LINE DEDENT raw = self . count_find ( sub , string [ 1 : ] ) % 10000 NEW_LINE if sub [ 0 ] != string [ 0 ] : NEW_LINE INDENT return raw NEW_LINE DEDENT return ( raw + self . count_find ( sub [ 1 : ] , string [ 1 : ] ) ) % 10000 NEW_LINE DEDENT def __repr__ ( self ) : NEW_LINE INDENT return \" Problem ▁ C ▁ Case ▁ % d \" % self . caseNum NEW_LINE DEDENT DEDENT class Contents : NEW_LINE INDENT def __init__ ( self , f ) : NEW_LINE INDENT self . data = [ line . strip ( ) for line in f ] NEW_LINE self . i = 0 NEW_LINE DEDENT def read ( self ) : NEW_LINE INDENT return self . readList ( 1 ) [ 0 ] NEW_LINE DEDENT def readList ( self , len ) : NEW_LINE INDENT result = self . data [ self . i : self . i + len ] NEW_LINE self . i += len NEW_LINE return result NEW_LINE DEDENT DEDENT def run ( ) : NEW_LINE INDENT import sys NEW_LINE f = file ( sys . argv [ 1 ] ) NEW_LINE s = Contents ( f ) NEW_LINE numCases = int ( s . read ( ) ) NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT case = Case ( s , caseNum ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( caseNum + 1 , case . solve ( ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT run ( ) NEW_LINE DEDENT", "from sys import stdin NEW_LINE from sys import stdout NEW_LINE pattern = ' welcome ▁ to ▁ code ▁ jam ' NEW_LINE ip = { } NEW_LINE for i , c in enumerate ( pattern ) : NEW_LINE INDENT ip . setdefault ( c , [ ] ) . append ( i ) NEW_LINE DEDENT n = len ( pattern ) NEW_LINE N = int ( stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( 1 , N + 1 ) : NEW_LINE INDENT line = stdin . readline ( ) . strip ( ) NEW_LINE ans = [ ] NEW_LINE for p , c in enumerate ( line ) : NEW_LINE INDENT val = [ 0 ] * n NEW_LINE if c in ip : NEW_LINE INDENT for j in ip [ c ] : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT val [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT for k in xrange ( p ) : NEW_LINE INDENT val [ j ] += ans [ k ] [ j - 1 ] NEW_LINE DEDENT val [ j ] %= 10000 NEW_LINE DEDENT DEDENT DEDENT ans . append ( val ) NEW_LINE DEDENT total = 0 NEW_LINE for val in ans : NEW_LINE INDENT total += val [ n - 1 ] NEW_LINE DEDENT stdout . write ( ' Case ▁ # % d : ▁ % 04d \\n ' % ( i , total % 10000 ) ) NEW_LINE DEDENT", "import numpy NEW_LINE import scipy NEW_LINE import sys NEW_LINE import csv NEW_LINE from numpy import ones NEW_LINE from numpy import size NEW_LINE import math NEW_LINE def __main__ ( ) : NEW_LINE INDENT input = sys . argv [ 1 ] NEW_LINE r = csv . reader ( open ( input ) , delimiter = ' \\n ' , quoting = csv . QUOTE_NONE ) NEW_LINE n = int ( r . next ( ) [ 0 ] ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT [ text ] = r . next ( ) NEW_LINE print \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + solve ( text ) NEW_LINE DEDENT DEDENT def solve ( text ) : NEW_LINE INDENT welcome = ' welcome ▁ to ▁ code ▁ jam ' NEW_LINE row = len ( welcome ) NEW_LINE col = len ( text ) NEW_LINE m = ones ( [ row , col ] , dtype = int ) * ( - 1 ) NEW_LINE n = dp ( m , welcome , text , 0 , 0 ) NEW_LINE strn = str_n ( n ) NEW_LINE return ( strn ) NEW_LINE DEDENT def dp ( m , welcome , text , x , y ) : NEW_LINE INDENT if ( x == len ( welcome ) ) : NEW_LINE INDENT return ( 1 ) NEW_LINE DEDENT elif ( y == len ( text ) ) : NEW_LINE INDENT return ( 0 ) NEW_LINE DEDENT elif ( m [ x , y ] != - 1 ) : NEW_LINE INDENT return ( m [ x , y ] ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( welcome [ x ] == text [ y ] ) : NEW_LINE INDENT m [ x , y ] = ( dp ( m , welcome , text , x + 1 , y + 1 ) + dp ( m , welcome , text , x , y + 1 ) ) % 10000 NEW_LINE DEDENT else : NEW_LINE INDENT m [ x , y ] = dp ( m , welcome , text , x , y + 1 ) NEW_LINE DEDENT return ( m [ x , y ] ) NEW_LINE DEDENT DEDENT def str_n ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return ( '0000' ) NEW_LINE DEDENT m = int ( 4 - ( math . floor ( math . log10 ( n ) ) + 1 ) ) NEW_LINE strn = str ( n ) NEW_LINE for i in range ( 0 , m ) : NEW_LINE INDENT strn = '0' + strn NEW_LINE DEDENT return ( strn ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : __main__ ( ) NEW_LINE" ]
codejam_14_51
[ "import java . util . * ; public class a { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int T = input . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { System . out . printf ( \" Case ▁ # % d : ▁ \" , t + 1 ) ; int n = input . nextInt ( ) ; int p = input . nextInt ( ) , q = input . nextInt ( ) , r = input . nextInt ( ) , s = input . nextInt ( ) ; int [ ] data = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { data [ i ] = ( int ) ( ( ( long ) i * p + q ) % r + s ) ; } long lo = 1 , hi = ( long ) 1e13 ; while ( lo < hi - 1 ) { long mid = ( lo + hi ) / 2 ; if ( canDo ( data , mid ) ) hi = mid ; else lo = mid ; } if ( ! canDo ( data , lo ) ) lo ++ ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += data [ i ] ; double res = 1. * lo / sum ; System . out . printf ( \" % .9f \\n \" , 1 - res ) ; } } static boolean canDo ( int [ ] data , long max ) { long count = 1 , sum = 0 ; int n = data . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( data [ i ] > max ) return false ; sum += data [ i ] ; if ( sum > max ) { count ++ ; sum = data [ i ] ; if ( count > 3 ) return false ; } } return count <= 3 ; } }" ]
[ "n = int ( raw_input ( ) ) NEW_LINE for testcase in range ( n ) : NEW_LINE INDENT [ N , p , q , r , s ] = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE transistors = [ ( i * p + q ) % r + s for i in range ( N ) ] NEW_LINE transistorsum = sum ( transistors ) NEW_LINE first = 0 NEW_LINE last = N NEW_LINE firstsum = 0 NEW_LINE lastsum = 0 NEW_LINE minimax = transistorsum NEW_LINE while last - first != 1 : NEW_LINE INDENT nextfirstsum = firstsum + transistors [ first ] NEW_LINE nextlastsum = lastsum + transistors [ last - 1 ] NEW_LINE if nextfirstsum < nextlastsum : NEW_LINE INDENT firstsum += transistors [ first ] NEW_LINE first += 1 NEW_LINE DEDENT else : NEW_LINE INDENT last -= 1 NEW_LINE lastsum += transistors [ last ] NEW_LINE DEDENT currentmax = max ( [ firstsum , lastsum , transistorsum - firstsum - lastsum ] ) NEW_LINE minimax = min ( currentmax , minimax ) NEW_LINE DEDENT answer = float ( transistorsum - minimax ) / float ( transistorsum ) NEW_LINE print \" Case ▁ # % d : ▁ % .10f \" % ( testcase + 1 , answer ) NEW_LINE DEDENT", "from sys import stdin NEW_LINE from numpy import * NEW_LINE T = int ( stdin . readline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT N , p , q , r , s = [ int ( word ) for word in stdin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE NT = ( arange ( N , dtype = int64 ) * p + q ) % r + s NEW_LINE PS = array ( [ 0 ] + list ( cumsum ( NT ) ) , dtype = int64 ) NEW_LINE S = PS [ - 1 ] NEW_LINE minmax = S NEW_LINE for a in range ( N ) : NEW_LINE INDENT s1 = PS [ a ] NEW_LINE b0 = searchsorted ( PS , s1 + ( S - s1 ) / 2.0 ) NEW_LINE assert b0 >= a NEW_LINE for b in ( b0 - 1 , b0 ) : NEW_LINE INDENT if 0 < b and b <= N : NEW_LINE INDENT mx = max ( s1 , PS [ b ] - PS [ a ] , S - PS [ b ] ) NEW_LINE if mx < minmax : NEW_LINE INDENT minmax = mx NEW_LINE DEDENT DEDENT DEDENT DEDENT print \" Case ▁ # \" + str ( t ) + \" : \" , float ( S - minmax ) / S NEW_LINE DEDENT", "import collections NEW_LINE import sys NEW_LINE if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT f = sys . stdin NEW_LINE if len ( sys . argv ) >= 2 : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE if fn != ' - ' : NEW_LINE INDENT f = open ( fn ) NEW_LINE DEDENT DEDENT T = int ( f . readline ( ) ) NEW_LINE for _T in xrange ( T ) : NEW_LINE INDENT N , p , q , r , s = map ( int , f . readline ( ) . split ( ) ) NEW_LINE transistors = [ ( i * p + q ) % r + s for i in xrange ( N ) ] NEW_LINE total = sum ( transistors ) NEW_LINE sums = [ ] NEW_LINE t = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT sums . append ( t ) NEW_LINE t += transistors [ i ] NEW_LINE DEDENT sums . append ( t ) NEW_LINE assert t == total NEW_LINE def can3 ( p ) : NEW_LINE INDENT needed = ( 1 - p ) * total NEW_LINE for i in xrange ( N - 1 , 0 , - 1 ) : NEW_LINE INDENT if sums [ i ] <= needed : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT for j in xrange ( N - 1 , i - 1 , - 1 ) : NEW_LINE INDENT if sums [ j + 1 ] - sums [ i ] <= needed : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT if total - sums [ j + 1 ] <= needed : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def can2 ( p ) : NEW_LINE INDENT needed = ( 1 - p ) * total NEW_LINE for i in xrange ( N - 1 , 0 , - 1 ) : NEW_LINE INDENT if sums [ i ] <= needed : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT if total - sums [ i ] <= needed : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT low = 0.0 NEW_LINE high = 1.0 NEW_LINE for i in xrange ( 40 ) : NEW_LINE INDENT g = ( low + high ) * 0.5 NEW_LINE if can3 ( g ) or can2 ( g ) : NEW_LINE INDENT low = g NEW_LINE DEDENT else : NEW_LINE INDENT high = g NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % .10f \" % ( _T + 1 , low ) NEW_LINE DEDENT DEDENT", "import sys NEW_LINE import bisect NEW_LINE def compute ( N , p , q , r , s ) : NEW_LINE INDENT a = [ 0 ] NEW_LINE last = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT x = ( i * p + q ) % r + s NEW_LINE last += 2 * x NEW_LINE a . append ( last ) NEW_LINE DEDENT best = 0.0 NEW_LINE if a [ - 1 ] == 0 : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT q = ( 0 , 0 , 0 ) NEW_LINE for i in xrange ( len ( a ) ) : NEW_LINE INDENT first = a [ i ] NEW_LINE need = first + ( a [ - 1 ] - first ) / 2 NEW_LINE pos = bisect . bisect_left ( a , need ) NEW_LINE second = a [ pos ] - first NEW_LINE third = a [ - 1 ] - first - second NEW_LINE m = a [ - 1 ] - max ( first , second , third ) NEW_LINE if float ( m ) / float ( a [ - 1 ] ) > best : NEW_LINE INDENT q = ( i , pos ) NEW_LINE best = float ( m ) / float ( a [ - 1 ] ) NEW_LINE DEDENT if pos - 1 > i : NEW_LINE INDENT second = a [ pos - 1 ] - first NEW_LINE third = a [ - 1 ] - first - second NEW_LINE m = a [ - 1 ] - max ( first , second , third ) NEW_LINE if float ( m ) / float ( a [ - 1 ] ) > best : NEW_LINE INDENT best = float ( m ) / float ( a [ - 1 ] ) NEW_LINE q = ( i , pos - 1 ) NEW_LINE DEDENT DEDENT DEDENT return best NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT N , p , q , r , s = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE return N , p , q , r , s NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE result = compute ( * data ) NEW_LINE print \" Case ▁ # % d : ▁ % s \" % ( i + 1 , result ) NEW_LINE DEDENT DEDENT", "num_trials = int ( input ( ) ) NEW_LINE def in_range ( a , b , S ) : NEW_LINE INDENT return S [ b + 1 ] - S [ a ] NEW_LINE DEDENT def compute ( ) : NEW_LINE INDENT N , p , q , r , s = map ( int , input ( ) . split ( ) ) NEW_LINE S = [ 0 ] * ( N + 1 ) NEW_LINE S [ 0 ] = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT S [ i + 1 ] = ( p * i + q ) % r + s + S [ i ] NEW_LINE DEDENT a_lo = 0 NEW_LINE a_hi = N - 1 NEW_LINE min_solveig_score = S [ N ] + 1 NEW_LINE while a_lo <= a_hi : NEW_LINE INDENT a_try = ( a_lo + a_hi ) // 2 NEW_LINE lo_range = S [ a_try ] NEW_LINE b_lo = a_try NEW_LINE b_hi = N - 1 NEW_LINE min_max_mid_hi = S [ N ] + 1 NEW_LINE while b_lo <= b_hi : NEW_LINE INDENT b_try = ( b_lo + b_hi ) // 2 NEW_LINE mid_range = S [ b_try + 1 ] - S [ a_try ] NEW_LINE hi_range = S [ N ] - S [ b_try + 1 ] NEW_LINE min_max_mid_hi = min ( min_max_mid_hi , max ( mid_range , hi_range ) ) NEW_LINE if mid_range > hi_range : NEW_LINE INDENT b_hi = b_try - 1 NEW_LINE DEDENT elif mid_range < hi_range : NEW_LINE INDENT b_lo = b_try + 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT min_solveig_score = min ( min_solveig_score , max ( lo_range , min_max_mid_hi ) ) NEW_LINE if lo_range > min_max_mid_hi : NEW_LINE INDENT a_hi = a_try - 1 NEW_LINE DEDENT elif lo_range < min_max_mid_hi : NEW_LINE INDENT a_lo = a_try + 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return ( \" % 1.10f \" % ( 1 - min_solveig_score / S [ N ] ) ) NEW_LINE DEDENT for i in range ( 0 , num_trials ) : NEW_LINE INDENT print ( \" Case ▁ # \" + str ( i + 1 ) + \" : ▁ \" + str ( compute ( ) ) ) NEW_LINE DEDENT" ]
codejam_12_02
[ "import java . io . * ; import java . util . * ; public class Dancing { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < T ; i ++ ) { StringTokenizer st = new StringTokenizer ( in . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int S = Integer . parseInt ( st . nextToken ( ) ) ; int p = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] scores = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { scores [ j ] = Integer . parseInt ( st . nextToken ( ) ) ; } int ans = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( p == 0 ) { ans ++ ; continue ; } if ( scores [ j ] == 0 ) continue ; if ( scores [ j ] / 3 >= p ) { ans ++ ; } else if ( scores [ j ] / 3 == p - 1 && scores [ j ] % 3 > 0 ) { ans ++ ; } else if ( scores [ j ] / 3 == p - 1 && scores [ j ] % 3 == 0 && S > 0 ) { ans ++ ; S -- ; } else if ( scores [ j ] / 3 == p - 2 && scores [ j ] % 3 == 2 && S > 0 ) { ans ++ ; S -- ; } } System . out . println ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + ans ) ; } } }", "package j2012qualifier ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class B { public static String inputDirectory = \" src / j2012qualifier / \" ; public static String inputFile = \" B . in \" ; public static String outputFile = \" B . out \" ; public static PrintWriter output ; public static void main ( String [ ] args ) throws FileNotFoundException { Scanner s = new Scanner ( new File ( inputDirectory + inputFile ) ) ; output = new PrintWriter ( new File ( inputDirectory + outputFile ) ) ; int cases = s . nextInt ( ) ; for ( int Case = 1 ; Case <= cases ; Case ++ ) { s . nextLine ( ) ; int googlers = s . nextInt ( ) ; int maxSupriseScores = s . nextInt ( ) ; int targetScore = s . nextInt ( ) ; int normalScores = 0 ; int surpriseScores = 0 ; for ( int i = 0 ; i < googlers ; i ++ ) { int score = s . nextInt ( ) ; if ( targetScore > score ) { continue ; } int otherScore = ( score - targetScore ) / 2 ; if ( otherScore >= targetScore - 1 ) { normalScores ++ ; } else if ( otherScore >= targetScore - 2 ) { surpriseScores ++ ; } } int answer = normalScores + Math . min ( surpriseScores , maxSupriseScores ) ; out ( \" Case ▁ # \" + Case + \" : ▁ \" + answer ) ; } output . flush ( ) ; } public static void out ( String s ) { output . println ( s ) ; } }", "import java . io . * ; import java . util . * ; public class CodeJam2012_Q_B { public int calc ( int N , int S , int p , int [ ] score ) { int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( score [ i ] >= p + Math . max ( p - 1 , 0 ) * 2 ) { cnt ++ ; } else if ( score [ i ] >= p + Math . max ( p - 2 , 0 ) * 2 && S > 0 ) { cnt ++ ; S -- ; } } return cnt ; } public static void main ( String [ ] args ) { try { ( new CodeJam2012_Q_B ( ) ) . exec ( \" B - large . in \" , \"2012 _ Q _ B - large . out \" ) ; } catch ( Exception ex ) { } } public final void exec ( String inFileName , String outFileName ) throws Exception { BufferedReader inReader = new BufferedReader ( new FileReader ( inFileName ) ) ; PrintWriter outWriter = new PrintWriter ( new BufferedWriter ( new FileWriter ( outFileName ) ) ) ; int caseNums = 0 ; caseNums = Integer . parseInt ( inReader . readLine ( ) ) ; for ( int i = 0 ; i < caseNums ; i ++ ) { String [ ] input = inReader . readLine ( ) . split ( \" ▁ \" ) ; int N = Integer . valueOf ( input [ 0 ] ) ; int S = Integer . valueOf ( input [ 1 ] ) ; int p = Integer . valueOf ( input [ 2 ] ) ; int [ ] score = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) score [ j ] = Integer . valueOf ( input [ j + 3 ] ) ; int outStr = calc ( N , S , p , score ) ; String fmtOutStr = \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" + outStr ; outWriter . println ( fmtOutStr ) ; System . out . println ( fmtOutStr ) ; } System . out . println ( caseNums + \" ▁ cases ▁ complete \" ) ; outWriter . close ( ) ; inReader . close ( ) ; } }", "import static java . lang . Double . parseDouble ; import static java . lang . Integer . parseInt ; import static java . lang . Long . parseLong ; import static java . lang . System . exit ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class B { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static int test ; static void solve ( ) throws Exception { int n = nextInt ( ) ; int s = nextInt ( ) ; int p = nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int t = nextInt ( ) ; if ( ( t + 2 ) / 3 >= p ) { ++ ans ; } else if ( s > 0 && t > 0 && ( t + 4 ) / 3 >= p ) { -- s ; ++ ans ; } } printCase ( ) ; out . println ( ans ) ; } static void printCase ( ) { out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; } static void printlnCase ( ) { out . println ( \" Case ▁ # \" + test + \" : \" ) ; } static int nextInt ( ) throws IOException { return parseInt ( next ( ) ) ; } static long nextLong ( ) throws IOException { return parseLong ( next ( ) ) ; } static double nextDouble ( ) throws IOException { return parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } public static void main ( String [ ] args ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int tests = nextInt ( ) ; for ( test = 1 ; test <= tests ; test ++ ) { solve ( ) ; } in . close ( ) ; out . close ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; exit ( 1 ) ; } } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; public class codejamp2 { public static char [ ] map ; public static void main ( String [ ] args ) throws IOException { readFile ( ) ; } public static String getResult ( String input ) { int resultInt = 0 ; String [ ] splitResult = input . split ( \" ▁ \" ) ; int dancerCount = Integer . parseInt ( splitResult [ 0 ] ) ; int suprising = Integer . parseInt ( splitResult [ 1 ] ) ; int max = Integer . parseInt ( splitResult [ 2 ] ) ; for ( int i = 3 ; i < dancerCount + 3 ; i ++ ) { int current = Integer . parseInt ( splitResult [ i ] ) ; int ave = current / 3 ; int remain = current - 3 * ave ; int currentmax = ave + remain ; if ( remain == 0 && ( max - currentmax == 1 ) && current != 0 ) { if ( suprising > 0 ) { suprising -- ; resultInt ++ ; } } if ( currentmax >= max ) { if ( remain <= 1 ) { resultInt ++ ; } else if ( remain == 2 ) { if ( max - ave <= 1 ) { resultInt ++ ; } else if ( suprising > 0 ) { suprising -- ; resultInt ++ ; } } } } return \" \" + resultInt ; } public static void readFile ( ) throws IOException { FileWriter fstream = new FileWriter ( \" out . txt \" ) ; BufferedWriter out = new BufferedWriter ( fstream ) ; FileReader input = new FileReader ( \" in . txt \" ) ; BufferedReader bufRead = new BufferedReader ( input ) ; String line = bufRead . readLine ( ) ; String current = getResult ( line ) ; int i = 1 ; out . write ( \" Case ▁ # \" + i + \" : ▁ \" + current ) ; line = bufRead . readLine ( ) ; while ( line != null ) { i ++ ; System . out . println ( \" Case ▁ # \" + i + \" : ▁ \" + getResult ( line ) ) ; out . write ( ' \\n ' + \" Case ▁ # \" + i + \" : ▁ \" + getResult ( line ) ) ; line = bufRead . readLine ( ) ; } bufRead . close ( ) ; out . close ( ) ; } }" ]
[ "import sys NEW_LINE L = 30 NEW_LINE normal = [ 0 , 1 ] NEW_LINE surprise = [ 0 , 1 ] NEW_LINE for i in range ( 2 , L + 1 ) : NEW_LINE INDENT normal . append ( i / 3 + ( ( i % 3 ) > 0 ) ) NEW_LINE surprise . append ( 2 + ( i - 2 ) / 3 ) NEW_LINE DEDENT for case_index in range ( 1 , 1 + input ( ) ) : NEW_LINE INDENT sys . stderr . write ( str ( case_index ) + ' ▁ ' ) NEW_LINE v = map ( int , raw_input ( ) . split ( ) ) NEW_LINE N = v . pop ( 0 ) NEW_LINE S = v . pop ( 0 ) NEW_LINE p = v . pop ( 0 ) NEW_LINE res = 0 NEW_LINE a = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if p <= normal [ v [ i ] ] : NEW_LINE INDENT res += 1 NEW_LINE DEDENT elif surprise [ v [ i ] ] == p : NEW_LINE INDENT a += 1 NEW_LINE DEDENT DEDENT if S < a : NEW_LINE INDENT a = S NEW_LINE DEDENT res += a NEW_LINE print ' Case ▁ # % s : ▁ % s ' % ( case_index , res ) NEW_LINE DEDENT sys . stderr . write ( ' \\n ' ) NEW_LINE", "dull_modifiers = [ ( 0 , 0 , 0 ) , ( 0 , 0 , 1 ) , ( 0 , 1 , 1 ) ] NEW_LINE surp_modifiers = [ ( - 1 , 0 , 1 ) , ( - 1 , 1 , 1 ) , ( 0 , 0 , 2 ) ] NEW_LINE def solvecase ( target , surprising , values ) : NEW_LINE INDENT total_dull_count = 0 NEW_LINE surp_deltas = [ ] NEW_LINE for v in values : NEW_LINE INDENT dull_scores = [ ( v // 3 ) + m for m in dull_modifiers [ v % 3 ] ] NEW_LINE surp_scores = [ ( v // 3 ) + m for m in surp_modifiers [ v % 3 ] ] NEW_LINE dull_count = int ( bool ( len ( [ s for s in dull_scores if s >= target ] ) ) ) NEW_LINE surp_count = int ( bool ( len ( [ s for s in surp_scores if s >= target ] ) ) ) NEW_LINE total_dull_count += dull_count NEW_LINE if any ( ( score < 0 ) or ( score > 10 ) for score in surp_scores ) : NEW_LINE INDENT continue NEW_LINE DEDENT surp_deltas . append ( surp_count - dull_count ) NEW_LINE DEDENT surp_deltas . sort ( ) NEW_LINE count = total_dull_count + ( sum ( surp_deltas [ - surprising : ] ) if surprising > 0 else 0 ) NEW_LINE return count NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT cases = int ( raw_input ( ) ) NEW_LINE for c in range ( cases ) : NEW_LINE INDENT values = map ( int , raw_input ( ) . split ( ) ) NEW_LINE surprising = values [ 1 ] NEW_LINE target = values [ 2 ] NEW_LINE totals = values [ 3 : ] NEW_LINE count = solvecase ( target , surprising , totals ) NEW_LINE print \" Case ▁ # { 0 } : ▁ { 1 } \" . format ( c + 1 , count ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE", "import sys , re , string , math , fractions , itertools NEW_LINE from fractions import Fraction NEW_LINE ssr = sys . stdin . readline NEW_LINE ssw = sys . stdout . write NEW_LINE def rdline ( ) : return ssr ( ) . strip ( ) NEW_LINE def rdstrs ( ) : return ssr . split ( ) NEW_LINE def rdints ( ) : return map ( int , ssr ( ) . split ( ) ) NEW_LINE def do_one_case ( cnum ) : NEW_LINE INDENT v = rdints ( ) NEW_LINE ( N , S , p ) = v [ : 3 ] NEW_LINE t = v [ 3 : ] NEW_LINE assert len ( t ) == N NEW_LINE nums = 0 NEW_LINE numns = 0 NEW_LINE for x in t : NEW_LINE INDENT mn = max ( 0 , x / 3 - 1 ) NEW_LINE mx = min ( 10 , ( x + 2 ) / 3 + 1 ) NEW_LINE r = range ( mn , mx + 1 ) NEW_LINE tplx = [ ( s1 , s2 , s3 ) for s1 in r for s2 in r for s3 in r if s1 + s2 + s3 == x ] NEW_LINE tpls = [ tt for tt in tplx if max ( tt ) - min ( tt ) <= 2 ] NEW_LINE tplns = [ tt for tt in tpls if max ( tt ) - min ( tt ) < 2 ] NEW_LINE maxs = max ( [ - 99 ] + [ max ( tt ) for tt in tpls ] ) NEW_LINE maxns = max ( [ - 99 ] + [ max ( tt ) for tt in tplns ] ) NEW_LINE if maxs >= p : nums += 1 NEW_LINE if maxns >= p : numns += 1 NEW_LINE DEDENT nn = min ( nums , numns + S ) NEW_LINE print \" Case ▁ # % d : ▁ % d \" % ( cnum , nn ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N = int ( rdline ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT do_one_case ( i + 1 ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "with open ( ' B - large . in ' , ' r ' ) as fin : NEW_LINE INDENT with open ( ' output . txt ' , ' w ' ) as fout : NEW_LINE INDENT numcases = int ( fin . readline ( ) ) NEW_LINE for i in range ( 1 , numcases + 1 ) : NEW_LINE INDENT line = [ int ( j ) for j in fin . readline ( ) . split ( ) ] NEW_LINE surprising = line [ 1 ] NEW_LINE minscore = line [ 2 ] NEW_LINE oknum = 0 NEW_LINE needsSurprising = 0 NEW_LINE for j in line [ 3 : ] : NEW_LINE INDENT d = j / 3 NEW_LINE m = j % 3 NEW_LINE if m == 0 : NEW_LINE INDENT if d >= minscore : NEW_LINE INDENT oknum += 1 NEW_LINE DEDENT elif d >= minscore - 1 and d > 0 : NEW_LINE INDENT needsSurprising += 1 NEW_LINE DEDENT DEDENT elif m == 1 : NEW_LINE INDENT if d >= minscore - 1 : NEW_LINE INDENT oknum += 1 NEW_LINE DEDENT DEDENT elif m == 2 : NEW_LINE INDENT if d >= minscore - 1 : NEW_LINE INDENT oknum += 1 NEW_LINE DEDENT elif d >= minscore - 2 : NEW_LINE INDENT needsSurprising += 1 NEW_LINE DEDENT DEDENT DEDENT fout . write ( \" Case ▁ # \" ) NEW_LINE fout . write ( str ( i ) ) NEW_LINE fout . write ( \" : ▁ \" ) NEW_LINE fout . write ( str ( oknum + min ( surprising , needsSurprising ) ) ) NEW_LINE fout . write ( ' \\n ' ) NEW_LINE DEDENT DEDENT DEDENT", "T = input ( ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT inp = raw_input ( ) . split ( ) NEW_LINE [ N , S , p ] = [ int ( s ) for s in inp [ 0 : 3 ] ] NEW_LINE ts = [ int ( s ) for s in inp [ 3 : ] ] NEW_LINE min_without_surprise = p + 2 * max ( p - 1 , 0 ) NEW_LINE min_with_surprise = p + 2 * max ( p - 2 , 0 ) NEW_LINE without_surprise = 0 NEW_LINE with_surprise = 0 NEW_LINE for ti in ts : NEW_LINE INDENT if ti >= min_without_surprise : NEW_LINE INDENT without_surprise += 1 NEW_LINE DEDENT elif ti >= min_with_surprise : NEW_LINE INDENT with_surprise += 1 NEW_LINE DEDENT DEDENT answer = without_surprise + min ( with_surprise , S ) NEW_LINE print \" Case ▁ # \" + str ( t ) + \" : ▁ \" + str ( answer ) NEW_LINE DEDENT" ]
codejam_09_31
[ "import java . io . * ; import java . math . * ; public class a { public static void main ( String [ ] args ) { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { int cases = Integer . valueOf ( input . readLine ( ) ) ; for ( int cas = 1 ; cas <= cases ; cas ++ ) { String line = input . readLine ( ) ; int digit [ ] = new int [ 256 ] ; int base = 0 , i ; BigInteger num = new BigInteger ( \"0\" ) ; for ( i = 0 ; i < 256 ; i ++ ) digit [ i ] = - 1 ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { if ( ( line . charAt ( i ) < '0' || line . charAt ( i ) > '9' ) && ( line . charAt ( i ) < ' a ' || line . charAt ( i ) > ' z ' ) ) continue ; if ( digit [ line . charAt ( i ) ] == - 1 ) { if ( base == 0 ) digit [ line . charAt ( i ) ] = 1 ; else if ( base == 1 ) digit [ line . charAt ( i ) ] = 0 ; else digit [ line . charAt ( i ) ] = base ; base ++ ; } } if ( base < 2 ) base = 2 ; int cnt = 0 ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { if ( ( line . charAt ( i ) < '0' || line . charAt ( i ) > '9' ) && ( line . charAt ( i ) < ' a ' || line . charAt ( i ) > ' z ' ) ) continue ; num = num . multiply ( BigInteger . valueOf ( base ) ) ; num = num . add ( BigInteger . valueOf ( digit [ line . charAt ( i ) ] ) ) ; } System . out . printf ( \" Case ▁ # % d : ▁ \" , cas ) ; System . out . println ( num ) ; } } catch ( java . io . IOException e ) { } } } ;", "package allyourbase ; import java . io . IOException ; public class Main extends Base { String alien ; char app [ ] ; int apos ; public static void main ( String [ ] args ) throws IOException { Main m = new Main ( ) ; m . run ( \" A \" , \" large \" ) ; } @ Override void init ( ) { } @ Override void load ( ) { } void insert ( char ch ) { int i = 0 ; while ( i < apos && app [ i ] != ch ) i ++ ; if ( i < apos ) return ; app [ apos ] = ch ; apos ++ ; } @ Override void solve ( ) throws IOException { System . out . println ( \" Case ▁ \" + caseId ) ; alien = br . readLine ( ) ; System . out . println ( alien ) ; app = new char [ alien . length ( ) ] ; apos = 0 ; for ( int i = 0 ; i < alien . length ( ) ; i ++ ) { insert ( alien . charAt ( i ) ) ; } long base = apos ; if ( base == 1 ) base ++ ; long res [ ] = new long [ alien . length ( ) ] ; for ( int i = 0 ; i < apos ; i ++ ) { int digit = i ; if ( digit == 0 ) digit = 1 ; else if ( digit == 1 ) digit = 0 ; for ( int j = 0 ; j < alien . length ( ) ; j ++ ) { if ( app [ i ] == alien . charAt ( j ) ) { res [ j ] = digit ; } } } for ( int i = 0 ; i < alien . length ( ) ; i ++ ) { System . out . print ( res [ i ] + \" ▁ \" ) ; } System . out . println ( ) ; long result = 0 ; long cur = 1 ; for ( int j = res . length - 1 ; j >= 0 ; j -- ) { result = result + cur * res [ j ] ; cur = cur * base ; } printResult ( \" \" + result ) ; } }", "import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . math . BigInteger ; import java . util . HashMap ; import java . util . Scanner ; public class AllYourBase { public static void main ( String [ ] args ) { try { BufferedReader in = new BufferedReader ( new FileReader ( \" A - small . in \" ) ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( \" x . txt \" ) ) ; Scanner scan = new Scanner ( in ) ; int T = scan . nextInt ( ) ; scan . nextLine ( ) ; for ( int ii = 0 ; ii < T ; ii ++ ) { String str = scan . nextLine ( ) ; HashMap < Character , Integer > hm = new HashMap < Character , Integer > ( ) ; hm . put ( str . charAt ( 0 ) , 1 ) ; int count = 1 ; while ( count < str . length ( ) ) { char c = str . charAt ( count ) ; if ( ! hm . containsKey ( c ) ) { hm . put ( c , 0 ) ; break ; } count ++ ; } count ++ ; int val = 2 ; while ( count < str . length ( ) ) { char c = str . charAt ( count ) ; if ( ! hm . containsKey ( c ) ) { hm . put ( c , val ++ ) ; } count ++ ; } String tgt = \" \" ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { tgt += hm . get ( str . charAt ( i ) ) ; } BigInteger x = new BigInteger ( tgt , val ) ; out . write ( \" Case ▁ # \" + ( ii + 1 ) + \" : ▁ \" + x . toString ( ) + \" \\n \" ) ; } in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }", "import java . io . * ; import java . util . * ; public class A { PrintWriter out ; Scanner in ; String testCase = \" a2\" ; public static void main ( String [ ] args ) throws Exception { new A ( ) . solve ( ) ; } void solve ( ) throws Exception { Locale . setDefault ( Locale . ENGLISH ) ; out = new PrintWriter ( new FileOutputStream ( testCase + \" . out \" ) ) ; in = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( testCase + \" . in \" ) ) ) ) ; int N = in . nextInt ( ) ; for ( int t = 1 ; t <= N ; ++ t ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; String num = in . next ( ) ; Map < Character , Integer > map = new HashMap < Character , Integer > ( ) ; for ( char c : num . toCharArray ( ) ) { if ( map . containsKey ( c ) ) { continue ; } if ( map . size ( ) == 0 ) { map . put ( c , 1 ) ; } else if ( map . size ( ) == 1 ) { map . put ( c , 0 ) ; } else { map . put ( c , map . size ( ) ) ; } } long result = 0 ; int base = map . size ( ) ; if ( base == 1 ) { base = 2 ; } for ( char c : num . toCharArray ( ) ) { result = result * base + map . get ( c ) ; } out . println ( result ) ; } out . close ( ) ; } }", "import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Scanner ; public class P1 { public static void main ( String args [ ] ) throws FileNotFoundException { Scanner s = new Scanner ( new FileInputStream ( \" A - large . in \" ) ) ; int cnt = s . nextInt ( ) ; for ( int cases = 0 ; cases < cnt ; cases ++ ) { String buf = s . next ( ) ; long num = 0 ; int bb = - 1 ; int [ ] ar = new int [ buf . length ( ) ] ; HashMap < String , Integer > set = new HashMap < String , Integer > ( ) ; set . put ( buf . substring ( 0 , 1 ) , 1 ) ; for ( int i = 0 ; i < buf . length ( ) ; i ++ ) { if ( set . containsKey ( buf . substring ( i , i + 1 ) ) ) { ar [ i ] = set . get ( buf . substring ( i , i + 1 ) ) ; } else { bb ++ ; if ( bb == 1 ) { bb = 2 ; } set . put ( buf . substring ( i , i + 1 ) , bb ) ; ar [ i ] = bb ; } } bb ++ ; if ( bb < 2 ) { bb = 2 ; } for ( int i = 0 ; i < buf . length ( ) ; i ++ ) { long temp = 1 ; for ( int j = 0 ; j < buf . length ( ) - i - 1 ; j ++ ) { temp = temp * ( long ) bb ; } num += ( long ) ar [ i ] * temp ; } System . out . println ( \" Case ▁ # \" + ( cases + 1 ) + \" : ▁ \" + num ) ; } } }" ]
[ "T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT string = raw_input ( ) NEW_LINE base = len ( set ( string ) ) NEW_LINE if base == 1 : base = 2 NEW_LINE ans = 1 NEW_LINE d = { string [ 0 ] : 1 } NEW_LINE next = 0 NEW_LINE for digit in string [ 1 : ] : NEW_LINE INDENT ans *= base NEW_LINE if digit in d : NEW_LINE INDENT ans += d [ digit ] NEW_LINE DEDENT else : NEW_LINE INDENT ans += next NEW_LINE d [ digit ] = next NEW_LINE next = 2 if next == 0 else next + 1 NEW_LINE DEDENT DEDENT print \" Case ▁ # % d : ▁ % d \" % ( t + 1 , ans ) NEW_LINE DEDENT", "def get_base ( digits ) : NEW_LINE INDENT return len ( set ( list ( str ( digits ) ) ) ) NEW_LINE DEDENT def minsecond ( digits ) : NEW_LINE INDENT digits = list ( digits ) NEW_LINE new_digits = list ( ) NEW_LINE count = 1 NEW_LINE letter2digit = { } NEW_LINE tmp = digits . pop ( 0 ) NEW_LINE letter2digit [ tmp ] = str ( count ) NEW_LINE count = 0 NEW_LINE new_digits . append ( letter2digit [ tmp ] ) NEW_LINE while digits : NEW_LINE INDENT tmp = digits . pop ( 0 ) NEW_LINE if tmp in letter2digit : NEW_LINE INDENT new_digits . append ( letter2digit [ tmp ] ) NEW_LINE DEDENT else : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT letter2digit [ tmp ] = str ( count ) NEW_LINE new_digits . append ( letter2digit [ tmp ] ) NEW_LINE count = 2 NEW_LINE DEDENT else : NEW_LINE INDENT letter2digit [ tmp ] = str ( count ) NEW_LINE new_digits . append ( letter2digit [ tmp ] ) NEW_LINE count += 1 NEW_LINE DEDENT DEDENT DEDENT new_digits = int ( ' ' . join ( new_digits ) ) NEW_LINE second = cal_base ( new_digits , count ) NEW_LINE return second NEW_LINE DEDENT def cal_base ( d , base ) : NEW_LINE INDENT if base <= 1 : NEW_LINE INDENT base = 2 NEW_LINE DEDENT d = list ( str ( d ) ) NEW_LINE count = 0 NEW_LINE res = 0 NEW_LINE while d : NEW_LINE INDENT t = int ( d . pop ( ) ) NEW_LINE res += t * base ** count NEW_LINE count += 1 NEW_LINE DEDENT return res NEW_LINE DEDENT def main ( filename , result = ' result . txt ' ) : NEW_LINE INDENT rfile = open ( filename ) NEW_LINE rfile . readline ( ) NEW_LINE case = 1 NEW_LINE wfile = open ( result , ' w ' ) NEW_LINE for line in rfile : NEW_LINE INDENT d = line . strip ( ) NEW_LINE n = minsecond ( d ) NEW_LINE wfile . write ( ' Case ▁ # ' + str ( case ) + ' : ▁ ' + str ( n ) + ' \\n ' ) NEW_LINE case += 1 NEW_LINE print case NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE in_file = sys . argv [ 1 ] NEW_LINE main ( in_file ) NEW_LINE DEDENT", "class Gcjt ( object ) : NEW_LINE INDENT class Testcase ( object ) : NEW_LINE INDENT def __init__ ( self , num , gcjt ) : NEW_LINE INDENT self . num = num NEW_LINE self . gcjt = gcjt NEW_LINE DEDENT def answer ( self , answer ) : NEW_LINE INDENT self . gcjt . outs . write ( ' Case ▁ # { num } : ▁ { ans } ' . format ( num = self . num , ans = answer ) + ' \\n ' ) NEW_LINE DEDENT def ws ( self , string ) : NEW_LINE INDENT self . gcjt . outs . write ( string ) NEW_LINE DEDENT def rl ( self ) : NEW_LINE INDENT return self . gcjt . ins . readline ( ) NEW_LINE DEDENT def ri ( self ) : NEW_LINE INDENT return ( int ( s ) for s in self . rl ( ) . split ( ) ) NEW_LINE DEDENT DEDENT def __init__ ( self ) : NEW_LINE INDENT filename = input ( ' file ▁ name ▁ : ▁ ' ) NEW_LINE self . fin = filename + ' . in ' NEW_LINE self . fout = filename + ' . out ' NEW_LINE DEDENT def __enter__ ( self ) : NEW_LINE INDENT self . ins = open ( self . fin ) NEW_LINE self . outs = open ( self . fout , ' w ' ) NEW_LINE DEDENT def __exit__ ( self , errtype = None , errvalu = None , errtrace = None ) : NEW_LINE INDENT self . ins . close ( ) NEW_LINE self . outs . close ( ) NEW_LINE DEDENT def tests ( self , num = None ) : NEW_LINE INDENT with self : NEW_LINE INDENT if num is None : num = int ( self . ins . readline ( ) ) NEW_LINE for t in range ( num ) : NEW_LINE INDENT yield self . Testcase ( t + 1 , self ) NEW_LINE DEDENT DEDENT DEDENT DEDENT def array ( * dim ) : NEW_LINE INDENT if len ( dim ) == 1 : return [ None ] * ( dim [ 0 ] ) NEW_LINE else : return [ array ( * dim [ 1 : ] ) for i in range ( dim [ 0 ] ) ] NEW_LINE DEDENT def tests ( ) : NEW_LINE INDENT return Gcjt ( ) . tests ( ) NEW_LINE DEDENT", "import sys NEW_LINE def decode ( s , base ) : NEW_LINE INDENT c2v = { } NEW_LINE res = 0 NEW_LINE next = 1 NEW_LINE for c in s : NEW_LINE INDENT if not c in c2v : NEW_LINE INDENT if len ( c2v ) < base : NEW_LINE INDENT c2v [ c ] = next NEW_LINE if next == 1 : NEW_LINE INDENT next = 0 NEW_LINE DEDENT elif next == 0 : NEW_LINE INDENT next = 2 NEW_LINE DEDENT else : NEW_LINE INDENT next += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return ( False , ) NEW_LINE DEDENT DEDENT dig = c2v [ c ] NEW_LINE res = base * res + dig NEW_LINE DEDENT return ( True , res ) NEW_LINE DEDENT sIn = \" A - large ( 2 ) . in \" ; sOut = \" A - large ( 2 ) . out \" NEW_LINE fIn = open ( sIn , \" r \" ) NEW_LINE fOut = open ( sOut , \" w \" ) NEW_LINE nT = int ( fIn . readline ( ) . strip ( ) ) NEW_LINE for t in xrange ( nT ) : NEW_LINE INDENT inp = fIn . readline ( ) . strip ( ) NEW_LINE mn = - 1 NEW_LINE for base in xrange ( 2 , 100 ) : NEW_LINE INDENT dRes = decode ( inp , base ) NEW_LINE if dRes [ 0 ] : NEW_LINE INDENT if mn == - 1 or mn > dRes [ 1 ] : NEW_LINE INDENT mn = dRes [ 1 ] NEW_LINE DEDENT DEDENT DEDENT print >> fOut , \" Case ▁ # % d : ▁ % d \" % ( t + 1 , mn ) NEW_LINE DEDENT", "def solve ( message ) : NEW_LINE INDENT time = 0 NEW_LINE base = max ( 2 , len ( set ( message ) ) ) NEW_LINE digits = range ( base ) NEW_LINE digits . remove ( 1 ) NEW_LINE digits . reverse ( ) NEW_LINE symbols = { message [ 0 ] : 1 } NEW_LINE for symbol in message : NEW_LINE INDENT time *= base NEW_LINE if symbol not in symbols : NEW_LINE INDENT symbols [ symbol ] = digits . pop ( ) NEW_LINE DEDENT time += symbols [ symbol ] NEW_LINE DEDENT return time NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT T = int ( raw_input ( ) ) NEW_LINE for case in xrange ( T ) : NEW_LINE INDENT message = raw_input ( ) NEW_LINE print ' Case ▁ # % d : ▁ % d ' % ( case + 1 , solve ( message ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_09_32
[ "package r1c ; import java . io . FileReader ; import java . util . Scanner ; public class B { public static void answer ( Scanner in ) { double sx , sy , sz , svx , svy , svz ; sx = 0 ; sy = 0 ; sz = 0 ; svx = 0 ; svy = 0 ; svz = 0 ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sx += in . nextDouble ( ) ; sy += in . nextDouble ( ) ; sz += in . nextDouble ( ) ; svx += in . nextDouble ( ) ; svy += in . nextDouble ( ) ; svz += in . nextDouble ( ) ; } double a , b , c ; a = svx * svx + svy * svy + svz * svz ; b = 2 * ( sx * svx + sy * svy + sz * svz ) ; c = sx * sx + sy * sy + sz * sz ; double outT ; if ( a != 0 ) { outT = - b / ( 2 * a ) ; if ( outT < 0 ) { outT = 0 ; } } else { outT = 0 ; } double outD = a * outT * outT + b * outT + c ; if ( outD < 0 ) { outD = 0 ; } outD = Math . sqrt ( outD ) / n ; System . out . println ( outD + \" ▁ \" + outT ) ; } public static void main ( String [ ] args ) { try { Scanner infile = new Scanner ( new FileReader ( args [ 0 ] ) ) ; int t = infile . nextInt ( ) ; infile . nextLine ( ) ; for ( int i = 0 ; i < t ; i ++ ) { System . out . print ( \" Case ▁ # \" + ( i + 1 ) + \" : ▁ \" ) ; answer ( infile ) ; } infile . close ( ) ; } catch ( Exception e ) { System . out . println ( \" Exception ▁ occured , ▁ stacktrace ▁ to ▁ follow . \" ) ; e . printStackTrace ( ) ; } } }", "import java . util . * ; import java . math . * ; class Main { public static void main ( String [ ] argv ) { Scanner sc = new Scanner ( System . in ) ; int tests = sc . nextInt ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { int n = sc . nextInt ( ) ; double x = 0. , y = 0 , z = 0 , dx = 0 , dy = 0 , dz = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x += sc . nextDouble ( ) ; y += sc . nextDouble ( ) ; z += sc . nextDouble ( ) ; dx += sc . nextDouble ( ) ; dy += sc . nextDouble ( ) ; dz += sc . nextDouble ( ) ; } x /= n ; y /= n ; z /= n ; dx /= n ; dy /= n ; dz /= n ; double a = dx * dx + dy * dy + dz * dz ; double b = 2 * ( dx * x + dy * y + dz * z ) ; double c = x * x + y * y + z * z ; double s ; if ( a == 0 && b == 0 ) { s = 0 ; } else if ( a == 0 && b / c > 0 ) { s = 0 ; } else if ( a == 0 ) { s = - c / b ; } else if ( b / a > 0 ) { s = 0 ; } else { s = - b / a / 2 ; } double v = a * s * s + b * s + c ; if ( v < 0 ) { v = 0 ; } v = Math . sqrt ( v ) ; System . err . println ( t ) ; System . out . printf ( \" Case ▁ # % d : ▁ % .08f ▁ % .08f \\n \" , t , v , s ) ; } } }", "import java . io . * ; import java . util . * ; public class B { PrintWriter out ; Scanner in ; String testCase = \" b2\" ; public static void main ( String [ ] args ) throws Exception { new B ( ) . solve ( ) ; } long sqr ( long a ) { return a * a ; } double sqrt ( double a ) { if ( a < 1E-8 ) { return 0 ; } else { return Math . sqrt ( a ) ; } } void solve ( ) throws Exception { Locale . setDefault ( Locale . ENGLISH ) ; out = new PrintWriter ( new FileOutputStream ( testCase + \" . out \" ) ) ; in = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( testCase + \" . in \" ) ) ) ) ; int N = in . nextInt ( ) ; for ( int t = 1 ; t <= N ; ++ t ) { out . print ( \" Case ▁ # \" + t + \" : ▁ \" ) ; int n = in . nextInt ( ) ; long x = 0 , y = 0 , z = 0 , vx = 0 , vy = 0 , vz = 0 ; for ( int i = 0 ; i < n ; ++ i ) { x += in . nextInt ( ) ; y += in . nextInt ( ) ; z += in . nextInt ( ) ; vx += in . nextInt ( ) ; vy += in . nextInt ( ) ; vz += in . nextInt ( ) ; } long a = sqr ( vx ) + sqr ( vy ) + sqr ( vz ) ; long b = 2 * ( x * vx + y * vy + z * vz ) ; long c = sqr ( x ) + sqr ( y ) + sqr ( z ) ; double time ; if ( a != 0 ) { time = - b / ( 2.0 * a ) ; } else { time = 0 ; } if ( time < 0 ) { time = 0 ; } double d = sqrt ( ( a * time * time + b * time + c ) ) / n ; out . println ( d + \" ▁ \" + time ) ; } out . close ( ) ; } }", "import java . io . * ; import java . util . * ; public class CenterOfMass { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( \" B . in \" ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( \" B . out \" ) ) ) ; StringTokenizer st ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int caseNum = 1 ; caseNum <= T ; caseNum ++ ) { int N = Integer . parseInt ( in . readLine ( ) ) ; double xPos = 0.0 ; double yPos = 0.0 ; double zPos = 0.0 ; double xVel = 0.0 ; double yVel = 0.0 ; double zVel = 0.0 ; double time ; double distance ; for ( int i = 0 ; i < N ; i ++ ) { st = new StringTokenizer ( in . readLine ( ) ) ; xPos += Double . parseDouble ( st . nextToken ( ) ) ; yPos += Double . parseDouble ( st . nextToken ( ) ) ; zPos += Double . parseDouble ( st . nextToken ( ) ) ; xVel += Double . parseDouble ( st . nextToken ( ) ) ; yVel += Double . parseDouble ( st . nextToken ( ) ) ; zVel += Double . parseDouble ( st . nextToken ( ) ) ; } xPos /= ( double ) N ; yPos /= ( double ) N ; zPos /= ( double ) N ; xVel /= ( double ) N ; yVel /= ( double ) N ; zVel /= ( double ) N ; if ( xVel == 0.0 && yVel == 0.0 && zVel == 0.0 ) { time = 0 ; distance = Math . sqrt ( xPos * xPos + yPos * yPos + zPos * zPos ) ; } else { time = - ( xPos * xVel + yPos * yVel + zPos * zVel ) / ( xVel * xVel + yVel * yVel + zVel * zVel ) ; if ( time < 0 ) time = 0 ; double xNew = xPos + time * xVel ; double yNew = yPos + time * yVel ; double zNew = zPos + time * zVel ; distance = Math . sqrt ( xNew * xNew + yNew * yNew + zNew * zNew ) ; } out . println ( \" Case ▁ # \" + caseNum + \" : ▁ \" + distance + \" ▁ \" + time ) ; } in . close ( ) ; out . close ( ) ; System . exit ( 0 ) ; } }" ]
[ "from __future__ import division NEW_LINE from math import sqrt NEW_LINE filein = \" B . in \" NEW_LINE fileout = \" B . out \" NEW_LINE def solve ( caseid , flydata ) : NEW_LINE INDENT num = len ( flydata ) NEW_LINE X = Y = Z = DX = DY = DZ = 0 NEW_LINE for i in range ( num ) : NEW_LINE INDENT x , y , z , dx , dy , dz = map ( float , flydata [ i ] . split ( ' ▁ ' ) ) NEW_LINE X += x NEW_LINE Y += y NEW_LINE Z += z NEW_LINE DX += dx NEW_LINE DY += dy NEW_LINE DZ += dz NEW_LINE DEDENT X = X / num NEW_LINE Y = Y / num NEW_LINE Z = Z / num NEW_LINE DX = DX / num NEW_LINE DY = DY / num NEW_LINE DZ = DZ / num NEW_LINE try : NEW_LINE INDENT t = max ( 0 , - ( X * DX + Y * DY + Z * DZ ) / ( DX * DX + DY * DY + DZ * DZ ) ) NEW_LINE DEDENT except : NEW_LINE INDENT print DX , DY , DZ NEW_LINE t = 0 NEW_LINE DEDENT px , py , pz = ( X + t * DX , Y + t * DY , Z + t * DZ ) NEW_LINE minD = sqrt ( px ** 2 + py ** 2 + pz ** 2 ) NEW_LINE return ' Case ▁ # % d : ▁ % .8f ▁ % .8f ' % ( caseid , minD , t ) NEW_LINE DEDENT datain = \"\"\" STRNEWLINE 3 STRNEWLINE 3 STRNEWLINE 3 ▁ 0 ▁ - 4 ▁ 0 ▁ 0 ▁ 3 STRNEWLINE - 3 ▁ - 2 ▁ - 1 ▁ 3 ▁ 0 ▁ 0 STRNEWLINE - 3 ▁ - 1 ▁ 2 ▁ 0 ▁ 3 ▁ 0 STRNEWLINE 3 STRNEWLINE - 5 ▁ 0 ▁ 0 ▁ 1 ▁ 0 ▁ 0 STRNEWLINE - 7 ▁ 0 ▁ 0 ▁ 1 ▁ 0 ▁ 0 STRNEWLINE - 6 ▁ 3 ▁ 0 ▁ 1 ▁ 0 ▁ 0 STRNEWLINE 4 STRNEWLINE 1 ▁ 2 ▁ 3 ▁ 1 ▁ 2 ▁ 3 STRNEWLINE 3 ▁ 2 ▁ 1 ▁ 3 ▁ 2 ▁ 1 STRNEWLINE 1 ▁ 0 ▁ 0 ▁ 0 ▁ 0 ▁ - 1 STRNEWLINE 0 ▁ 10 ▁ 0 ▁ 0 ▁ - 10 ▁ - 1 STRNEWLINE \"\"\" NEW_LINE datain = open ( filein ) . read ( ) NEW_LINE dataout = open ( fileout , \" w \" ) NEW_LINE data = [ x for x in datain . split ( ' \\n ' ) if x ] NEW_LINE N = int ( data [ 0 ] ) NEW_LINE atrow = 1 NEW_LINE for case in range ( N ) : NEW_LINE INDENT flies = int ( data [ atrow ] ) NEW_LINE flydata = data [ atrow + 1 : atrow + flies + 1 ] NEW_LINE text = str ( solve ( case + 1 , flydata ) ) NEW_LINE print text NEW_LINE dataout . write ( text + ' \\n ' ) NEW_LINE atrow += flies + 1 NEW_LINE DEDENT dataout . close ( ) NEW_LINE print \" Wrote ▁ % s \" % fileout NEW_LINE", "import euclid NEW_LINE def main ( ) : NEW_LINE INDENT T = int ( raw_input ( ) ) NEW_LINE for case in xrange ( T ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE position = euclid . Vector3 ( ) NEW_LINE velocity = euclid . Vector3 ( ) NEW_LINE for _ in xrange ( N ) : NEW_LINE INDENT x , y , z , vx , vy , vz = map ( float , raw_input ( ) . split ( ) ) NEW_LINE position += euclid . Vector3 ( x , y , z ) NEW_LINE velocity += euclid . Vector3 ( vx , vy , vz ) NEW_LINE DEDENT position /= N NEW_LINE velocity /= N NEW_LINE if velocity == euclid . Vector3 ( ) : NEW_LINE INDENT d_min = abs ( position - euclid . Point3 ( ) ) NEW_LINE t_min = 0. NEW_LINE DEDENT else : NEW_LINE INDENT position = euclid . Point3 ( position . x , position . y , position . z ) NEW_LINE ray = euclid . Ray3 ( position , velocity ) NEW_LINE connection = ray . connect ( euclid . Point3 ( ) ) NEW_LINE d_min = abs ( connection ) NEW_LINE t_min = abs ( connection . p1 - position ) / abs ( velocity ) NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % 1.8f ▁ % 1.8f ' % ( case + 1 , d_min , t_min ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT", "from sys import stdin NEW_LINE import math NEW_LINE def vecAdd ( v1 , v2 ) : NEW_LINE INDENT return [ x1 + x2 for x1 , x2 in zip ( v1 , v2 ) ] NEW_LINE DEDENT def vecSub ( v1 , v2 ) : NEW_LINE INDENT return [ x1 - x2 for x1 , x2 in zip ( v1 , v2 ) ] NEW_LINE DEDENT def vecDot ( v1 , v2 ) : NEW_LINE INDENT return sum ( [ x1 * x2 for x1 , x2 in zip ( v1 , v2 ) ] ) NEW_LINE DEDENT def vecScale ( v , s ) : NEW_LINE INDENT return [ x * s for x in v ] NEW_LINE DEDENT def compute ( flies ) : NEW_LINE INDENT vecAvg = [ 0 , 0 , 0 , 0 , 0 , 0 ] NEW_LINE for vec in flies : NEW_LINE INDENT vecAvg = [ x + y for x , y in zip ( vecAvg , vec ) ] NEW_LINE DEDENT flyCount = len ( flies ) NEW_LINE vecAvg = [ float ( x ) / float ( flyCount ) for x in vecAvg ] NEW_LINE x1 = vecAvg [ 0 : 3 ] NEW_LINE x2 = vecAvg [ 3 : ] NEW_LINE speedSqr = vecDot ( x2 , x2 ) NEW_LINE if speedSqr == 0 : NEW_LINE INDENT t = 0 NEW_LINE DEDENT else : NEW_LINE INDENT t = - vecDot ( x1 , x2 ) / vecDot ( x2 , x2 ) NEW_LINE DEDENT if t < 0 : NEW_LINE INDENT t = 0 NEW_LINE DEDENT diffv = vecAdd ( x1 , vecScale ( x2 , t ) ) NEW_LINE d = math . sqrt ( vecDot ( diffv , diffv ) ) NEW_LINE return ( d , t ) NEW_LINE DEDENT cases = int ( stdin . readline ( ) ) NEW_LINE for caseNo in xrange ( 1 , cases + 1 ) : NEW_LINE INDENT flyCount = int ( stdin . readline ( ) ) NEW_LINE flies = [ ] NEW_LINE for flyNo in xrange ( 0 , flyCount ) : NEW_LINE INDENT flies . append ( [ int ( x ) for x in stdin . readline ( ) . strip ( ) . split ( ) ] ) NEW_LINE DEDENT d , t = compute ( flies ) NEW_LINE print \" Case ▁ # % d : ▁ % .8f ▁ % .8f \" % ( caseNo , d , t ) NEW_LINE DEDENT", "for ii in range ( 1 , int ( raw_input ( ) ) + 1 ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE f = [ [ int ( a ) for a in raw_input ( ) . split ( ) ] for j in range ( N ) ] NEW_LINE g = [ sum ( [ z [ i ] for z in f ] ) for i in range ( 6 ) ] NEW_LINE x = g [ : 3 ] NEW_LINE d = g [ 3 : ] NEW_LINE t = 0 NEW_LINE if ( d != [ 0 , 0 , 0 ] and sum ( [ x [ i ] * d [ i ] for i in range ( 3 ) ] ) < 0 ) : NEW_LINE INDENT t = - ( 0.0 + sum ( [ x [ i ] * d [ i ] for i in range ( 3 ) ] ) ) / sum ( [ d [ i ] * d [ i ] for i in range ( 3 ) ] ) NEW_LINE DEDENT x = [ float ( x [ i ] + t * d [ i ] ) / N for i in range ( 3 ) ] NEW_LINE x = ( x [ 0 ] * x [ 0 ] + x [ 1 ] * x [ 1 ] + x [ 2 ] * x [ 2 ] ) ** 0.5 NEW_LINE print \" Case ▁ # % d : ▁ % .8f ▁ % .8f \" % ( ii , x , t ) NEW_LINE DEDENT", "from math import sqrt NEW_LINE def dot ( a , b ) : NEW_LINE INDENT return a [ 0 ] * b [ 0 ] + a [ 1 ] * b [ 1 ] + a [ 2 ] * b [ 2 ] NEW_LINE DEDENT def sub ( a , b ) : NEW_LINE INDENT return ( a [ 0 ] - b [ 0 ] , a [ 1 ] - b [ 1 ] , a [ 2 ] - b [ 2 ] ) NEW_LINE DEDENT def add ( a , b ) : NEW_LINE INDENT return ( a [ 0 ] + b [ 0 ] , a [ 1 ] + b [ 1 ] , a [ 2 ] + b [ 2 ] ) NEW_LINE DEDENT def mul ( a , f ) : NEW_LINE INDENT return ( a [ 0 ] * f , a [ 1 ] * f , a [ 2 ] * f ) NEW_LINE DEDENT def norm22 ( a ) : NEW_LINE INDENT return dot ( a , a ) NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT x , y , z = 0 , 0 , 0 NEW_LINE vx , vy , vz = 0 , 0 , 0 NEW_LINE n = int ( raw_input ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT xi , yi , zi , vxi , vyi , vzi = map ( int , raw_input ( ) . split ( ) ) NEW_LINE x = x + xi NEW_LINE y = y + yi NEW_LINE z = z + zi NEW_LINE vx = vx + vxi NEW_LINE vy = vy + vyi NEW_LINE vz = vz + vzi NEW_LINE DEDENT c = mul ( ( x , y , z ) , 1. / n ) NEW_LINE v = mul ( ( vx , vy , vz ) , 1. / n ) NEW_LINE b = dot ( v , v ) NEW_LINE if b == 0 : NEW_LINE INDENT tmin = 0 NEW_LINE DEDENT else : NEW_LINE INDENT tmin = - dot ( c , v ) / b NEW_LINE if tmin < 0 : NEW_LINE INDENT tmin = 0 NEW_LINE DEDENT DEDENT d2 = norm22 ( add ( c , mul ( v , tmin ) ) ) NEW_LINE print \" Case ▁ # % i : \" % ( t + 1 ) , sqrt ( d2 ) , tmin NEW_LINE DEDENT" ]
codejam_15_31
[ "import java . io . * ; import java . util . * ; public class A { MyScanner in ; PrintWriter out ; final static String FILENAME = \" a \" ; public static void main ( String [ ] args ) throws Exception { new A ( ) . run ( ) ; } public void run ( ) throws Exception { in = new MyScanner ( FILENAME + \" . in \" ) ; out = new PrintWriter ( FILENAME + \" . out \" ) ; int tests = in . nextInt ( ) ; for ( int test = 0 ; test < tests ; test ++ ) { out . println ( \" Case ▁ # \" + ( test + 1 ) + \" : ▁ \" + solve ( ) ) ; } out . close ( ) ; } public long solve ( ) throws Exception { int r = in . nextInt ( ) ; int c = in . nextInt ( ) ; int w = in . nextInt ( ) ; return r * ( c / w + w + ( c % w == 0 ? - 1 : 0 ) ) ; } class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( String file ) throws Exception { br = new BufferedReader ( new FileReader ( file ) ) ; } String next ( ) throws Exception { while ( ( st == null ) || ( ! st . hasMoreTokens ( ) ) ) { String t = br . readLine ( ) ; if ( t == null ) { return null ; } st = new StringTokenizer ( t ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( next ( ) ) ; } double nextDouble ( ) throws Exception { return Double . parseDouble ( next ( ) ) ; } boolean nextBoolean ( ) throws Exception { return Boolean . parseBoolean ( next ( ) ) ; } long nextLong ( ) throws Exception { return Long . parseLong ( next ( ) ) ; } } }", "package com . archieve ; import java . io . BufferedInputStream ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; import static java . util . Arrays . deepToString ; public class codejam2015_1C_A { static PrintWriter out = null ; static FileInputStream in = null ; Scanner sc ; int N ; Integer R , C , W ; void read ( ) { R = sc . nextInt ( ) ; C = sc . nextInt ( ) ; W = sc . nextInt ( ) ; } void solve ( ) { long solution = 0 ; solution += ( R - 1 ) * ( C / W ) ; solution += ( C - 1 ) / W ; solution += W ; out . println ( solution ) ; System . out . println ( solution ) ; } void output ( long a ) { out . println ( a ) ; System . out . println ( a ) ; } void run ( ) { try { in = new FileInputStream ( \" src / com / resources / smallInput . txt \" ) ; out = new PrintWriter ( \" src / com / resources / output . txt \" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } sc = new Scanner ( in ) ; int caseN = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseN ; caseID ++ ) { read ( ) ; out . printf ( \" Case ▁ # % d : ▁ \" , caseID ) ; System . out . printf ( \" Case ▁ # % d : ▁ \" , caseID ) ; solve ( ) ; System . out . flush ( ) ; } out . close ( ) ; } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { try { System . setIn ( new BufferedInputStream ( new FileInputStream ( args . length > 0 ? args [ 0 ] : ( codejam2015_1C_A . class . getName ( ) + \" . in \" ) ) ) ) ; } catch ( Exception e ) { } new codejam2015_1C_A ( ) . run ( ) ; } }", "import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class ProblemA { public static void main ( String [ ] args ) throws IOException { ProblemA solver = new ProblemA ( ) ; solver . init ( ) ; solver . solve ( ) ; } void init ( ) { } private void solve ( ) throws IOException { Reader in = new Reader ( System . in ) ; PrintWriter out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int R = in . nextInt ( ) ; int C = in . nextInt ( ) ; int W = in . nextInt ( ) ; int r = ( C / W ) * R ; r += ( W - 1 ) ; if ( ( C % W ) > 0 ) r ++ ; out . println ( \" Case ▁ # \" + t + \" : ▁ \" + r ) ; } out . flush ( ) ; out . close ( ) ; } private static class Reader { BufferedReader reader ; StringTokenizer tokenizer ; Reader ( InputStream input ) { reader = new BufferedReader ( new InputStreamReader ( input ) ) ; tokenizer = new StringTokenizer ( \" \" ) ; } public void skipLine ( ) throws IOException { reader . readLine ( ) ; } public String next ( ) throws IOException { while ( ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } } }", "import java . util . Scanner ; public final class A { public static void main ( final String ... args ) { final Scanner sc = new Scanner ( System . in ) ; final int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; ++ i ) { System . out . println ( String . format ( \" Case ▁ # % d : ▁ % d \" , i + 1 , testcase ( sc ) ) ) ; } } private static int testcase ( final Scanner sc ) { final int r = sc . nextInt ( ) ; final int c = sc . nextInt ( ) ; final int w = sc . nextInt ( ) ; return ( c / w ) * r + ( w - 1 ) + ( c % w == 0 ? 0 : 1 ) ; } }", "import java . io . * ; import java . util . StringTokenizer ; public class Main { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . printf ( \" Case ▁ # % d : ▁ \" , testNumber ) ; int r = in . nextInt ( ) ; int c = in . nextInt ( ) ; int w = in . nextInt ( ) ; int addRow = c / w * ( r - 1 ) ; int inRow = c / w + w ; if ( c % w == 0 ) inRow -- ; out . println ( addRow + inRow ) ; } public static void main ( String [ ] args ) throws IOException { FastScanner in = new FastScanner ( new FileInputStream ( \" input . txt \" ) ) ; PrintWriter out = new PrintWriter ( \" output . txt \" ) ; int t = in . nextInt ( ) ; for ( int test = 1 ; test <= t ; test ++ ) new Main ( ) . solve ( test , in , out ) ; in . close ( ) ; out . close ( ) ; } } class FastScanner { private StringTokenizer tokenizer ; private BufferedReader reader ; public FastScanner ( InputStream inputStream ) { reader = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { String line ; try { line = reader . readLine ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } if ( line == null ) return null ; tokenizer = new StringTokenizer ( line ) ; } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } public String nextLine ( ) { String line ; try { line = reader . readLine ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } tokenizer = null ; return line ; } public void close ( ) { try { reader . close ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } }" ]
[ "testSum = input ( ) NEW_LINE for test in xrange ( testSum ) : NEW_LINE INDENT x , y , w = map ( int , raw_input ( ) . split ( ) ) NEW_LINE ans = x * ( ( y - 1 ) / w + 1 ) + w - 1 NEW_LINE print \" Case ▁ # \" + str ( test + 1 ) + \" : \" , ans NEW_LINE DEDENT", "def check ( R , C , W , B ) : NEW_LINE INDENT c = sum ( b . count ( 1 ) for b in B ) NEW_LINE for y in range ( R ) : NEW_LINE INDENT for x in range ( C - W + 1 ) : NEW_LINE INDENT if B [ y ] [ x : x + W ] . count ( 1 ) == c and B [ y ] [ x : x + W ] . count ( - 1 ) == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT def BT ( R , C , W , B ) : NEW_LINE INDENT Bt = tuple ( tuple ( b ) for b in B ) NEW_LINE if Bt in memo : NEW_LINE INDENT return memo [ Bt ] NEW_LINE DEDENT ans = 9999 NEW_LINE for y in range ( R ) : NEW_LINE INDENT for x in range ( C ) : NEW_LINE INDENT if B [ y ] [ x ] == 0 : NEW_LINE INDENT ans2 = 0 NEW_LINE B [ y ] [ x ] = 1 NEW_LINE if check ( R , C , W , B ) : NEW_LINE INDENT if sum ( b . count ( 1 ) for b in B ) == W : NEW_LINE INDENT ans2 = max ( ans2 , 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans2 = max ( ans2 , BT ( R , C , W , B ) + 1 ) NEW_LINE DEDENT DEDENT B [ y ] [ x ] = 0 NEW_LINE B [ y ] [ x ] = - 1 NEW_LINE if check ( R , C , W , B ) : NEW_LINE INDENT ans2 = max ( ans2 , BT ( R , C , W , B ) + 1 ) NEW_LINE DEDENT B [ y ] [ x ] = 0 NEW_LINE ans = min ( ans , ans2 ) NEW_LINE DEDENT DEDENT DEDENT memo [ Bt ] = ans NEW_LINE return ans NEW_LINE DEDENT def solve ( R , C , W ) : NEW_LINE INDENT global memo NEW_LINE B = [ [ 0 ] * C for _ in range ( R ) ] NEW_LINE memo = { } NEW_LINE return BT ( R , C , W , B ) NEW_LINE DEDENT for t in range ( input ( ) ) : NEW_LINE INDENT R , C , W = map ( int , raw_input ( ) . split ( ) ) NEW_LINE print \" Case ▁ # % s : ▁ % s \" % ( t + 1 , solve ( R , C , W ) ) NEW_LINE DEDENT", "import math NEW_LINE import itertools NEW_LINE import numpy as NP NEW_LINE def read_case ( f ) : NEW_LINE INDENT return read_ints ( f ) NEW_LINE DEDENT def solve_small ( case ) : NEW_LINE INDENT R , C , W = case NEW_LINE return ( C // W ) * R + W - ( 1 if C % W == 0 else 0 ) NEW_LINE DEDENT def solve_large ( case ) : NEW_LINE INDENT return solve_small ( case ) NEW_LINE DEDENT def write_case ( f , i , res ) : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ ' % i ) NEW_LINE f . write ( ' % s ' % res ) NEW_LINE f . write ( ' \\n ' ) NEW_LINE DEDENT def read_word ( f ) : NEW_LINE INDENT return next ( f ) . strip ( ) NEW_LINE DEDENT def read_int ( f , b = 10 ) : NEW_LINE INDENT return int ( read_word ( f ) , b ) NEW_LINE DEDENT def read_letters ( f ) : NEW_LINE INDENT return list ( read_word ( f ) ) NEW_LINE DEDENT def read_digits ( f , b = 10 ) : NEW_LINE INDENT return [ int ( x , b ) for x in read_letters ( f ) ] NEW_LINE DEDENT def read_words ( f , d = ' ▁ ' ) : NEW_LINE INDENT return read_word ( f ) . split ( d ) NEW_LINE DEDENT def read_ints ( f , b = 10 , d = ' ▁ ' ) : NEW_LINE INDENT return [ int ( x , b ) for x in read_words ( f , d ) ] NEW_LINE DEDENT def read_floats ( f , d = ' ▁ ' ) : NEW_LINE INDENT return [ float ( x ) for x in read_words ( f , d ) ] NEW_LINE DEDENT def read_arr ( f , R , reader = read_ints , * args , ** kwargs ) : NEW_LINE INDENT return [ reader ( f , * args , ** kwargs ) for i in range ( R ) ] NEW_LINE DEDENT def solve ( solver , fn , out_fn = None ) : NEW_LINE INDENT in_fn = fn + ' . in ' NEW_LINE if out_fn is None : NEW_LINE INDENT out_fn = fn + ' . out ' NEW_LINE DEDENT with open ( in_fn , ' r ' ) as fi : NEW_LINE INDENT with open ( out_fn , ' w ' ) as fo : NEW_LINE INDENT T = read_int ( fi ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT case = read_case ( fi ) NEW_LINE res = solver ( case ) NEW_LINE write_case ( fo , i , res ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEBUG = ' i ' NEW_LINE from run import * NEW_LINE", "import os NEW_LINE import sys NEW_LINE from collections import defaultdict NEW_LINE problem_id = ' A ' NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input_path = ' % s . in ' % problem_id NEW_LINE output_path = ' % s . out ' % problem_id NEW_LINE def read_line ( ) : NEW_LINE INDENT line = ' ' NEW_LINE while len ( line ) == 0 : NEW_LINE INDENT line = input_file . readline ( ) . strip ( ) NEW_LINE DEDENT return line NEW_LINE DEDENT def write_line ( line ) : NEW_LINE INDENT print line NEW_LINE return output_file . write ( line + os . linesep ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT r , c , w = map ( int , read_line ( ) . split ( ' ▁ ' ) ) NEW_LINE nc = ( c / w ) * r + ( w - 1 ) NEW_LINE if c % w : NEW_LINE INDENT nc += 1 NEW_LINE DEDENT return ' % s ' % nc NEW_LINE DEDENT input_file = open ( input_path , \" r \" ) NEW_LINE output_file = open ( output_path , \" w + \" ) NEW_LINE T = int ( read_line ( ) ) NEW_LINE for case_id in xrange ( 1 , T + 1 ) : NEW_LINE INDENT write_line ( \" Case ▁ # % d : ▁ % s \" % ( case_id , solve ( ) ) ) NEW_LINE DEDENT input_file . close ( ) NEW_LINE output_file . close ( ) NEW_LINE", "FILE_NAME_BASE = ' A - large ' NEW_LINE NUM_PROCESSES = 0 NEW_LINE MEM_LIMIT_GB = 1.5 NEW_LINE RECURSION_LIMIT = 1000 NEW_LINE def parse ( inp ) : NEW_LINE INDENT rows , cols , size = ( int ( x ) for x in inp . readline ( ) . split ( ) ) NEW_LINE return rows , cols , size NEW_LINE DEDENT def solve ( rows , cols , size ) : NEW_LINE INDENT toHit = cols / size NEW_LINE hitFlex = cols % size NEW_LINE toSink = size - 1 if hitFlex == 0 else size NEW_LINE return rows * toHit + toSink NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT import sys NEW_LINE sys . setrecursionlimit ( RECURSION_LIMIT ) NEW_LINE import resource NEW_LINE soft , hard = resource . getrlimit ( resource . RLIMIT_AS ) NEW_LINE resource . setrlimit ( resource . RLIMIT_AS , ( MEM_LIMIT_GB * 1024 ** 3 , hard ) ) NEW_LINE with open ( FILE_NAME_BASE + ' . in ' , ' r ' ) as inp : NEW_LINE INDENT numCases = int ( inp . readline ( ) ) NEW_LINE inputs = [ parse ( inp ) for _ in xrange ( numCases ) ] NEW_LINE DEDENT if NUM_PROCESSES == 0 : NEW_LINE INDENT runners = [ lambda inp = inp : apply ( solve , inp ) for inp in inputs ] NEW_LINE DEDENT else : NEW_LINE INDENT from multiprocessing import Pool NEW_LINE from signal import SIGINT , SIG_IGN , signal NEW_LINE pool = Pool ( NUM_PROCESSES , signal , ( SIGINT , SIG_IGN ) ) NEW_LINE runners = [ pool . apply_async ( solve , inp ) . get for inp in inputs ] NEW_LINE pool . close ( ) NEW_LINE DEDENT caseFmt = ' % ' + str ( len ( str ( numCases ) ) ) + ' d ' NEW_LINE progressFmt = ' [ % s / % s ] ▁ % % s \\n ' % ( caseFmt , caseFmt ) NEW_LINE with open ( FILE_NAME_BASE + ' . out ' , ' w ' ) as out : NEW_LINE INDENT for case , runner in enumerate ( runners , 1 ) : NEW_LINE INDENT result = runner ( ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % s \\n ' % ( case , result ) ) NEW_LINE out . flush ( ) NEW_LINE sys . stderr . write ( progressFmt % ( case , numCases , result ) ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT" ]
codejam_13_22
[ "import gcj . GCJ ; import java . util . Scanner ; public class FallingDiamonds { public static void main ( String [ ] args ) { Scanner s = GCJ . createScanner ( ' B ' , true ) ; int T = s . nextInt ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { int n = s . nextInt ( ) ; int x = s . nextInt ( ) ; int y = s . nextInt ( ) ; double p = 0 ; int nn = 1 ; int total = 1 ; while ( total + nn + 1 + nn + 2 <= n ) { total += nn + 1 + nn + 2 ; nn += 2 ; } int xy = Math . abs ( x ) + y ; if ( xy < nn ) { p = 1 ; } else if ( xy >= nn + 2 ) { p = 0 ; } else { int left = n - total ; if ( left < y + 1 ) { p = 0 ; } else { nn ++ ; double [ ] [ ] cand = new double [ nn + 1 ] [ nn + 1 ] ; cand [ 0 ] [ 0 ] = 1 ; for ( int w = 1 ; w <= left ; w ++ ) { for ( int u = 0 ; u < w && u <= nn ; u ++ ) { int v = w - u - 1 ; if ( v > nn ) { continue ; } if ( u == nn ) { cand [ u ] [ v + 1 ] += cand [ u ] [ v ] ; } else if ( v == nn ) { cand [ u + 1 ] [ v ] += cand [ u ] [ v ] ; } else { cand [ u + 1 ] [ v ] += cand [ u ] [ v ] / 2 ; cand [ u ] [ v + 1 ] += cand [ u ] [ v ] / 2 ; } } } p = 0 ; for ( int u = y + 1 ; u <= left && u <= nn ; u ++ ) { int v = left - u ; if ( v > nn ) { continue ; } p += cand [ u ] [ v ] ; } } } GCJ . out ( i , Double . toString ( p ) ) ; } } }", "import java . io . * ; import java . util . * ; public class Main { static PrintWriter out ; static StreamTokenizer in ; static int next ( ) throws Exception { in . nextToken ( ) ; return ( int ) in . nval ; } public static void main ( String [ ] args ) throws Exception { out = new PrintWriter ( System . out ) ; in = new StreamTokenizer ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int tests = next ( ) ; int m = 11000 ; double [ ] [ ] c = new double [ m ] [ m ] ; c [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i < m ; i ++ ) { c [ i ] [ 0 ] = c [ i ] [ i ] = c [ i - 1 ] [ 0 ] / 2 ; for ( int j = 1 ; j < i ; j ++ ) c [ i ] [ j ] = ( c [ i - 1 ] [ j ] + c [ i - 1 ] [ j - 1 ] ) / 2 ; } for ( int test = 1 ; test <= tests ; test ++ ) { int n = next ( ) ; int x = Math . abs ( next ( ) ) ; int y = Math . abs ( next ( ) ) ; int level = ( x + y ) / 2 ; int sum = 0 ; int lev = 0 ; for ( ; ; lev ++ ) { sum += 4 * lev + 1 ; if ( sum >= n ) break ; } int kol = n - sum + 4 * lev + 1 ; double answ = 0 ; if ( level == lev ) { if ( x == 0 ) { if ( kol == 4 * lev + 1 ) answ = 1 ; } else { for ( int i = 0 ; i <= kol ; i ++ ) if ( i + Math . max ( 0 , kol - i - 2 * lev ) > y ) { answ += c [ kol ] [ i ] ; } } } else if ( level < lev ) answ = 1 ; out . print ( \" Case ▁ # \" + test + \" : ▁ \" ) ; out . println ( answ ) ; } out . close ( ) ; } }" ]
[ "import math NEW_LINE def C ( k , a ) : NEW_LINE INDENT if a == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return math . factorial ( k ) / ( math . factorial ( a ) * math . factorial ( k - a ) ) NEW_LINE DEDENT def Cal ( k , a ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( a , k + 1 ) : NEW_LINE INDENT sum += C ( k , i ) NEW_LINE DEDENT return sum * 1.0 / 2 ** k NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT input = raw_input ( ) NEW_LINE b = input . split ( \" ▁ \" ) NEW_LINE c = [ int ( e ) for e in b ] NEW_LINE N = c [ 0 ] NEW_LINE X = c [ 1 ] NEW_LINE Y = c [ 2 ] NEW_LINE if X < 0 : NEW_LINE INDENT X = - X NEW_LINE DEDENT if ( X + Y ) % 2 == 1 : NEW_LINE INDENT p = 0 NEW_LINE DEDENT elif X + Y == 0 : NEW_LINE INDENT p = 1 NEW_LINE DEDENT elif X == 0 : NEW_LINE INDENT level = Y / 2 + 2 NEW_LINE btm = ( 2 * level - 3 ) * ( level - 1 ) NEW_LINE if N >= btm : NEW_LINE INDENT p = 1 NEW_LINE DEDENT else : NEW_LINE INDENT p = 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT level = ( X + Y ) / 2 + 1 NEW_LINE btm = ( 2 * level - 3 ) * ( level - 1 ) + Y + 1 NEW_LINE level2 = level + 1 NEW_LINE upper = ( 2 * level2 - 3 ) * ( level2 - 1 ) - X NEW_LINE if N < btm : NEW_LINE INDENT p = 0 NEW_LINE DEDENT elif N >= upper : NEW_LINE INDENT p = 1 NEW_LINE DEDENT else : NEW_LINE INDENT left = N - ( 2 * level - 3 ) * ( level - 1 ) ; NEW_LINE a = Y + 1 NEW_LINE p = Cal ( left , a ) NEW_LINE DEDENT DEDENT print ( \" Case ▁ # \" + str ( i ) + \" : ▁ \" + str ( p ) ) NEW_LINE DEDENT", "import numpy as np NEW_LINE def pyramid_size ( n ) : NEW_LINE INDENT return 2 * n ** 2 - n NEW_LINE DEDENT def pyramid_coordinates ( x , y ) : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return y / 2 + 1 , 0 NEW_LINE DEDENT return ( y + abs ( x ) ) / 2 , y + 1 NEW_LINE DEDENT def prob ( level , rem , h ) : NEW_LINE INDENT p = np . zeros ( ( 2 * level + 1 , 2 * level + 1 ) ) NEW_LINE p [ 0 , 0 ] = 1.0 NEW_LINE s = 0.0 NEW_LINE for l in xrange ( 0 , 4 * level + 1 ) : NEW_LINE INDENT for x in xrange ( 0 , 2 * level + 1 ) : NEW_LINE INDENT y = l - x NEW_LINE if y < 0 or y > 2 * level : NEW_LINE INDENT continue NEW_LINE DEDENT if x + y == rem and x >= h : NEW_LINE INDENT s += p [ x , y ] NEW_LINE DEDENT if x < 2 * level and y < 2 * level : NEW_LINE INDENT p [ x + 1 , y ] += 0.5 * p [ x , y ] NEW_LINE p [ x , y + 1 ] += 0.5 * p [ x , y ] NEW_LINE DEDENT elif x < 2 * level and y == 2 * level : NEW_LINE INDENT p [ x + 1 , y ] += p [ x , y ] NEW_LINE DEDENT elif x == 2 * level and y < 2 * level : NEW_LINE INDENT p [ x , y + 1 ] += p [ x , y ] NEW_LINE DEDENT DEDENT DEDENT return s NEW_LINE DEDENT def solve ( n , x , y ) : NEW_LINE INDENT level , h = pyramid_coordinates ( x , y ) NEW_LINE if pyramid_size ( level ) + h > n : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT if pyramid_size ( level + 1 ) <= n : NEW_LINE INDENT return 1.0 NEW_LINE DEDENT return prob ( level , n - pyramid_size ( level ) , h ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT ncases = int ( raw_input ( ) ) NEW_LINE for ncase in xrange ( 1 , ncases + 1 ) : NEW_LINE INDENT n , x , y = map ( int , raw_input ( ) . split ( ) ) NEW_LINE print \" Case ▁ # % d : ▁ % .8lf \" % ( ncase , solve ( n , x , y ) ) NEW_LINE DEDENT DEDENT", "tcs = int ( input ( ) ) NEW_LINE binom = [ [ 1 ] ] NEW_LINE for i in range ( 1 , 5001 ) : NEW_LINE INDENT binom . append ( [ ] ) NEW_LINE binom [ - 1 ] . append ( binom [ - 2 ] [ 0 ] / 2 ) NEW_LINE for j in range ( 1 , i ) : NEW_LINE INDENT binom [ - 1 ] . append ( ( binom [ - 2 ] [ j - 1 ] + binom [ - 2 ] [ j ] ) / 2 ) NEW_LINE DEDENT binom [ - 1 ] . append ( binom [ - 2 ] [ - 1 ] / 2 ) NEW_LINE DEDENT for i in range ( len ( binom ) ) : NEW_LINE INDENT assert ( len ( binom [ i ] ) == i + 1 ) NEW_LINE for j in range ( 1 , len ( binom [ i ] ) ) : NEW_LINE INDENT binom [ i ] [ j ] += binom [ i ] [ j - 1 ] ; NEW_LINE DEDENT DEDENT for tc in range ( 1 , tcs + 1 ) : NEW_LINE INDENT n , x , y = ( int ( i ) for i in input ( ) . split ( ' ▁ ' ) ) NEW_LINE level = ( abs ( x ) + y ) // 2 NEW_LINE l = 0 NEW_LINE while n > 0 : NEW_LINE INDENT k = 4 * l + 1 NEW_LINE if n >= k : NEW_LINE INDENT if level == l : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ 1.0\" % tc ) NEW_LINE break NEW_LINE DEDENT n -= k NEW_LINE DEDENT else : NEW_LINE INDENT if level == l : NEW_LINE INDENT if y <= n - 1 - 2 * l : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ 1.0\" % tc ) NEW_LINE DEDENT elif y >= min ( 2 * l , n ) : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ 0.0\" % tc ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ % .15f \" % ( tc , 1 - binom [ n ] [ y ] ) ) NEW_LINE DEDENT break NEW_LINE DEDENT n = 0 NEW_LINE DEDENT l += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" Case ▁ # % d : ▁ 0.0\" % tc ) NEW_LINE DEDENT DEDENT", "def parse ( inFile ) : NEW_LINE INDENT return tuple ( inFile . getInts ( ) ) NEW_LINE DEDENT import sys NEW_LINE sys . setrecursionlimit ( 2000 ) NEW_LINE a_cache = { } NEW_LINE def ans ( r , num ) : NEW_LINE INDENT if not a_cache . has_key ( ( r , num ) ) : NEW_LINE INDENT if ( num == 0 ) : NEW_LINE INDENT return 1.0 NEW_LINE DEDENT if ( num == r ) : NEW_LINE INDENT return 1.0 / ( 1 << r ) NEW_LINE DEDENT a_cache [ ( r , num ) ] = ( ans ( r - 1 , num - 1 ) + ans ( r - 1 , num ) ) / 2 NEW_LINE DEDENT return a_cache [ ( r , num ) ] NEW_LINE DEDENT def solve ( ( N , X , Y ) ) : NEW_LINE INDENT if ( X <= 0 ) : NEW_LINE INDENT X = - X NEW_LINE DEDENT lvl = ( X + Y ) / 2 NEW_LINE if ( N >= 2 * lvl * lvl + 3 * lvl + 1 ) : NEW_LINE INDENT return \"1\" NEW_LINE DEDENT if ( N <= 2 * ( lvl - 1 ) * ( lvl - 1 ) + 3 * ( lvl - 1 ) + 1 ) : NEW_LINE INDENT return \"0\" NEW_LINE DEDENT if ( X == 0 ) : NEW_LINE INDENT return \"0\" NEW_LINE DEDENT r = N - ( 2 * ( lvl - 1 ) * ( lvl - 1 ) + 3 * ( lvl - 1 ) + 1 ) NEW_LINE if ( r <= Y ) : NEW_LINE INDENT return \"0\" NEW_LINE DEDENT if ( r >= Y + 2 * lvl + 1 ) : NEW_LINE INDENT return \"1\" NEW_LINE DEDENT return str ( ans ( r , Y + 1 ) ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( parse , solve , \" / Users / lpebody / gcj / 2013_1b / b \" , \" B \" ) . run ( ) NEW_LINE DEDENT", "from __future__ import division NEW_LINE import sys NEW_LINE vstup = map ( int , sys . stdin . read ( ) . split ( ) ) NEW_LINE t = vstup . pop ( 0 ) NEW_LINE def level ( x , y ) : NEW_LINE INDENT return ( y + abs ( x ) ) // 2 + 1 NEW_LINE DEDENT def findout ( n , x , y ) : NEW_LINE INDENT x = abs ( x ) NEW_LINE numfull = 0 NEW_LINE fullsize = 1 NEW_LINE while fullsize <= n : NEW_LINE INDENT numfull += 1 NEW_LINE n -= fullsize NEW_LINE fullsize += 4 NEW_LINE DEDENT if level ( x , y ) <= numfull : NEW_LINE INDENT return 1.0 NEW_LINE DEDENT if n == 0 : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT if level ( x , y ) != numfull + 1 or x == 0 : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT fullsize -= 1 NEW_LINE half = fullsize // 2 NEW_LINE want = y + 1 NEW_LINE dp = [ [ 0.0 ] * ( half + 1 ) , None ] NEW_LINE dp [ 0 ] [ 0 ] = 1.0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT oi = i % 2 NEW_LINE ni = 1 - oi NEW_LINE dp [ ni ] = [ 0.0 ] * ( half + 1 ) NEW_LINE for on in xrange ( half + 1 ) : NEW_LINE INDENT off = i - on NEW_LINE if on == half : dp [ ni ] [ on ] += dp [ oi ] [ on ] NEW_LINE elif off == half : dp [ ni ] [ on + 1 ] += dp [ oi ] [ on ] NEW_LINE else : NEW_LINE INDENT dp [ ni ] [ on ] += dp [ oi ] [ on ] / 2 NEW_LINE dp [ ni ] [ on + 1 ] += dp [ oi ] [ on ] / 2 NEW_LINE DEDENT DEDENT DEDENT res = 0.0 NEW_LINE for on in xrange ( half + 1 ) : NEW_LINE INDENT if on >= want : res += dp [ n % 2 ] [ on ] NEW_LINE DEDENT return res NEW_LINE DEDENT for tc in xrange ( t ) : NEW_LINE INDENT n = vstup . pop ( 0 ) NEW_LINE x = vstup . pop ( 0 ) NEW_LINE y = vstup . pop ( 0 ) NEW_LINE print \" Case ▁ # { } : ▁ { : . 9f } \" . format ( tc + 1 , findout ( n , x , y ) ) NEW_LINE DEDENT" ]
codeforces_330_B
[ "import java . io . * ; import java . util . * ;   public class RoadConstruction { public static void main ( String [ ] args ) { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) { Set < Integer > notAllowed = new HashSet < > ( ) ; int [ ] nm = Arrays . stream ( reader . readLine ( ) . split ( \" ▁ \" ) ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ; for ( int i = 0 ; i < nm [ 1 ] ; i ++ ) { int [ ] uv = Arrays . stream ( reader . readLine ( ) . split ( \" ▁ \" ) ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ; notAllowed . add ( uv [ 0 ] ) ; notAllowed . add ( uv [ 1 ] ) ; } for ( int i = 1 ; i <= nm [ 0 ] ; i ++ ) { if ( ! notAllowed . contains ( i ) ) { writer . write ( ( nm [ 0 ] - 1 ) + \" \\n \" ) ; for ( int j = 1 ; j <= nm [ 0 ] ; j ++ ) { if ( j != i ) { writer . write ( i + \" ▁ \" + j + \" \\n \" ) ; } } break ; }   }   } catch ( IOException e ) { } }   }", "import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; import java . lang . Math ; public class Account { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] path = new int [ n + 1 ] [ n + 1 ] ;", "import java . util . * ; import java . lang . * ; import java . io . * ;   public class FastIO { BufferedReader br ; StringTokenizer st ; public FastIO ( ) {", "import java . util . * ;   public class RoadConstruction_B {   public static void main ( String [ ] args ) {" ]
[ "n , m = map ( int , input ( ) . split ( ) ) L = [ 0 ] * nfor i in range ( m ) : a , b = map ( int , input ( ) . split ( ) ) L [ a - 1 ] = - 1 L [ b - 1 ] = - 1 central = 0 for i in range ( n ) : if L [ i ] == 0 : central = i + 1 breakprint ( n - 1 ) for i in range ( 1 , n + 1 ) : if i != central : print ( central , i ) NEW_LINE", "n , m = map ( int , input ( ) . split ( ) ) g = [ set ( ) for i in range ( n ) ] for i in range ( m ) : a , b = map ( int , input ( ) . split ( ) ) a -= 1 b -= 1 g [ a ] . add ( b ) g [ b ] . add ( a ) for i in range ( n ) : ok = True for j in range ( n ) : if i == j : continue if i in g [ j ] : ok = False break if ok : print ( n - 1 ) for j in range ( n ) : if i != j : print ( i + 1 , j + 1 ) quit ( ) NEW_LINE", "R = lambda : map ( int , input ( ) . split ( ) ) n , m = R ( ) a = set ( range ( 1 , n + 1 ) ) for i in range ( m ) : a = a - set ( R ( ) ) a = list ( a ) [ 0 ] print ( n - 1 ) for i in range ( 1 , n + 1 ) : if i != a : print ( a , i ) NEW_LINE", "n , m = map ( int , input ( ) . split ( ) ) g = [ 0 ] * ( n + 1 ) for k in range ( m ) : a , b = map ( int , input ( ) . split ( ) ) g [ a ] = 1 g [ b ] = 1   c = 0 for k in range ( 1 , len ( g ) ) : if g [ k ] == 0 : c = k break   print ( n - 1 ) for k in range ( 1 , len ( g ) ) : if k == c : continue print ( c , k ) NEW_LINE", "import sys   input = sys . stdin . readline   n , m = map ( int , input ( ) . split ( ) )     f = [ - 1 ] * ( n + 1 )     u = { }   for j in range ( m ) : a , b = map ( int , input ( ) . split ( ) )   u [ a ] = 1 u [ b ] = 1   f [ a ] = b f [ b ] = a   x = - 1 for j in range ( 1 , n + 1 ) :   if j not in u : x = j break   d = [ ]   for j in range ( 1 , n + 1 ) : if j != x : d . append ( [ x , j ] )   print ( len ( d ) )   for j in d : print ( * j ) NEW_LINE" ]
codeforces_140_B
[ "import java . io . * ; import java . util . StringTokenizer ;   public class _140B implements Runnable { private BufferedReader in ; private StringTokenizer tok ;   private Object solve ( ) throws IOException { int n = nextInt ( ) ; int [ ] [ ] rs = new int [ n ] [ n ] ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { rs [ i ] [ j ] = nextInt ( ) ; } } for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = nextInt ( ) ; } int [ ] z = new int [ n + 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( p [ j ] < p [ i ] ) { if ( z [ p [ i ] ] == 0 ) { z [ p [ i ] ] = p [ j ] ; } else { z [ p [ i ] ] = - 1 ; break ; } } } } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( rs [ i ] [ j ] != i + 1 && ( z [ rs [ i ] [ j ] ] == 0 || z [ rs [ i ] [ j ] ] == i + 1 ) ) { sb . append ( rs [ i ] [ j ] ) ; if ( i < n - 1 ) { sb . append ( ' ▁ ' ) ; } break ; } } } return sb ; }  " ]
[ "n = int ( input ( ) )   frnd = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] ara = list ( map ( int , input ( ) . split ( ) ) )   pref = [ 0 ] * ( n + 1 ) ans = [ 0 ] * n   for i in range ( n ) : pref [ ara [ i ] ] = i     def ok ( val , row ) : for x in ara : if x - 1 == row : continue if x < val : return 0 if x == val : return 1     for ro in range ( n ) : for x in frnd [ ro ] : if x - 1 == ro : continue if ok ( x , ro ) : ans [ ro ] = x break   for i in range ( n ) : print ( ans [ i ] , end = ' ▁ ' ) print ( )     NEW_LINE", "import sysfrom itertools import * from math import * def solve ( ) : n = int ( input ( ) ) tab = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] alex = list ( map ( int , input ( ) . split ( ) ) ) willget = [ [ 0 ] * n for _ in range ( n ) ] has = list ( ) for row in range ( n ) : hasrow = list ( ) for val in alex : if val <= row + 1 : hasrow . append ( val ) has . append ( hasrow ) NEW_LINE", "import sysfrom itertools import * from math import * def solve ( ) : n = int ( input ( ) ) tab = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] alex = list ( map ( int , input ( ) . split ( ) ) ) has = list ( ) for row in range ( n ) : hasrow = list ( ) for val in alex : if val <= row + 1 : hasrow . append ( val ) has . append ( hasrow ) for friend in range ( 1 , n + 1 ) : NEW_LINE", "def f ( ) : t = [ 0 ] * n for i , j in enumerate ( input ( ) . split ( ) ) : t [ int ( j ) - 1 ] = i return tn = int ( input ( ) ) p = [ f ( ) for i in range ( n ) ] s = f ( ) for x , t in enumerate ( p ) : i = j = x < 1 for y in range ( n ) : if x != y and s [ y ] < s [ i ] : i = y if t [ i ] < t [ j ] : j = i print ( j + 1 ) NEW_LINE", "n = int ( input ( ) ) arr = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n + 1 ) ] res = [ 0 ] * nfor i in range ( n ) : p = [ 0 ] * ( n + 1 ) for j in range ( n ) : p [ arr [ i ] [ j ] ] = j u , t , b = 0 , int ( 1e5 ) , int ( 1e5 ) for x in arr [ n ] : if x != i + 1 and x < b : if p [ x ] < t : u , t = x , p [ x ] b = x res [ i ] = uprint ( * res ) NEW_LINE" ]
codeforces_1027_A
[ "import java . util . Scanner ;   public class Palindromic_Twist { public static void main ( String [ ] args ) { Scanner obj = new Scanner ( System . in ) ; int T ; String t = \" \" ; t = obj . nextLine ( ) ; T = Integer . parseInt ( t ) ; while ( T > 0 ) { String z = obj . nextLine ( ) ; int n = Integer . parseInt ( z ) ; String s = obj . nextLine ( ) ; int i = 0 ; int j = s . length ( ) - 1 ; while ( i < j && i < s . length ( ) && j < s . length ( ) ) { if ( s . charAt ( i ) == s . charAt ( j ) ) { i ++ ; j -- ; } else { if ( s . charAt ( i ) + 1 == s . charAt ( j ) + 1 || s . charAt ( i ) - 1 == s . charAt ( j ) - 1 || s . charAt ( i ) + 1 == s . charAt ( j ) - 1 || s . charAt ( i ) - 1 == s . charAt ( j ) + 1 ) { i ++ ; j -- ; } else i = j + 5 ;   } } if ( n % 2 != 0 ) if ( i == j ) System . out . println ( \" YES \" ) ; else System . out . println ( \" NO \" ) ; else if ( i == j + 1 ) System . out . println ( \" YES \" ) ; else System . out . println ( \" NO \" ) ; T -- ; } } }", "import java . util . * ;   public class Test { public static void main ( String [ ] args ) {   Scanner input = new Scanner ( System . in ) ; int t = input . nextInt ( ) ;   while ( t -- > 0 ) { int n = input . nextInt ( ) ; char [ ] s = input . next ( ) . toCharArray ( ) ;   int l = ( ( n & 1 ) == 1 ) ? n / 2 : n / 2 - 1 ; int r = n / 2 ; boolean res = true ;   while ( l >= 0 ) { int temp = Math . abs ( ( int ) s [ l ] - ( int ) s [ r ] ) ; if ( temp != 2 && temp != 0 ) { res = false ; break ; } l -- ; r ++ ; } System . out . println ( res ? \" YES \" : \" NO \" ) ; } } }", "import java . util . * ; import java . lang . Math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . nextLine ( ) ; int t = Integer . parseInt ( a ) ; while ( t > 0 ) { String b = sc . nextLine ( ) ; int n = Integer . parseInt ( b ) ; String s = sc . nextLine ( ) ; int c = 0 ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) { if ( ( Math . abs ( s . charAt ( i ) - s . charAt ( s . length ( ) - 1 - i ) ) != 0 ) && ( Math . abs ( s . charAt ( i ) - s . charAt ( s . length ( ) - 1 - i ) ) != 2 ) ) { c = 1 ; break ; } } if ( c == 1 ) { System . out . println ( \" NO \" ) ; } else { System . out . println ( \" YES \" ) ; } t -- ; } } }", "import java . util . * ; import java . io . * ; public class Main { public static int mod = 1000000007 ; public static void solve ( InputReader in ) { int n = in . readInt ( ) ; char s [ ] = in . readString ( ) . toCharArray ( ) ; int left = 0 ; int right = n - 1 ; for ( ; left + 1 <= right ; left ++ , right -- ) { if ( s [ left ] == s [ right ] ) continue ; if ( s [ left ] == ' a ' ) { if ( s [ left ] + 1 != s [ right ] - 1 ) { System . out . println ( \" NO \" ) ; return ; } } if ( s [ left ] == ' z ' ) { if ( s [ left ] - 1 != s [ right ] + 1 ) { System . out . println ( \" NO \" ) ; return ; } } if ( s [ left ] > s [ right ] ) { if ( s [ left ] - 1 != s [ right ] + 1 ) { System . out . println ( \" NO \" ) ; return ; } } else if ( s [ left ] < s [ right ] ) { if ( s [ left ] + 1 != s [ right ] - 1 ) { System . out . println ( \" NO \" ) ; return ; } } } System . out . println ( \" YES \" ) ; } public static void main ( String [ ] args ) {", "import java . util . Scanner ;   public class _0689PalindromicTwist {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; while ( cases > 0 ) { int n = sc . nextInt ( ) ; sc . nextLine ( ) ; String input = sc . nextLine ( ) ; boolean flag = true ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int first = input . charAt ( i ) ; int last = input . charAt ( n - 1 - i ) ; if ( first == last ) { continue ; } else if ( Math . abs ( first - last ) == 1 ) { flag = false ; break ; } else if ( Math . abs ( first - last ) == 2 ) { continue ; } else { flag = false ; break ; } } if ( flag ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } cases -- ; } }   }" ]
[ "t = int ( input ( ) ) for _ in range ( t ) : n = int ( input ( ) ) s = str ( input ( ) ) flag = True for i in range ( n ) : c1 = ord ( s [ i ] ) - ord ( ' a ' ) c2 = ord ( s [ n - 1 - i ] ) - ord ( ' a ' ) if c1 == c2 or abs ( c1 - c2 ) == 2 : pass else : flag = False break if flag : print ( ' YES ' ) else : print ( ' NO ' ) NEW_LINE", "for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) s = input ( ) if n == 0 : print ( \" YES \" ) else : count = 0 for i in range ( n // 2 ) : if ord ( s [ i ] ) - ord ( s [ n - 1 - i ] ) == 2 or s [ i ] == s [ n - 1 - i ] or ord ( s [ i ] ) - ord ( s [ n - 1 - i ] ) == - 2 : count += 1 if ( count == ( n // 2 ) ) : print ( \" YES \" ) else : print ( \" NO \" ) NEW_LINE", "t = int ( input ( ) ) for _ in range ( t ) : n = int ( input ( ) ) s = input ( ) i , j = 0 , n - 1 ans = ' YES ' while i < j : if abs ( ord ( s [ i ] ) - ord ( s [ j ] ) ) not in [ 0 , 2 ] : ans = ' NO ' break i += 1 j -= 1 print ( ans ) NEW_LINE", "from __future__ import division , print_functionfrom collections import * from math import * from itertools import * from time import timeimport osimport sysfrom io import BytesIO , IOBase   if sys . version_info [ 0 ] < 3 : from __builtin__ import xrange as range from future_builtins import ascii , filter , hex , map , oct , zip   ''' Notes : n ▁ = ▁ number ▁ of ▁ ballsk ▁ = ▁ attract ▁ powerni ▁ = ▁ ball ' s ▁ coords '''   def main ( ) : n = int ( input ( ) ) s = input ( ) if s == s [ : : - 1 ] : print ( ' YES ' ) return opposite = s [ : : - 1 ] for i in range ( n // 2 ) : first = ord ( s [ i ] ) second = ord ( opposite [ i ] ) if first == second : continue if first - 1 == second + 1 : continue if first + 1 == second - 1 : continue else : print ( ' NO ' ) return print ( ' YES ' )             NEW_LINE" ]
codeforces_891_B
[ "import java . util . * ; import java . io . * ; public class MainClass { public static void main ( String [ ] args ) throws IOException { Reader in = new Reader ( ) ; int n = in . nextInt ( ) ; Game [ ] A = new Game [ n ] ; for ( int i = 0 ; i < n ; i ++ ) A [ i ] = new Game ( in . nextInt ( ) , i ) ; Arrays . sort ( A ) ; int [ ] ans = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) ans [ A [ i ] . idx ] = A [ i - 1 ] . val ; ans [ A [ 0 ] . idx ] = A [ n - 1 ] . val ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( ans [ i ] + \" ▁ \" ) ; } } class Game implements Comparable < Game > { int val ; int idx ;   public Game ( int val , int idx ) { this . val = val ; this . idx = idx ; }   @ Override public int compareTo ( Game game ) { return this . val - game . val ; } } class Reader { final private int BUFFER_SIZE = 1 << 16 ; private DataInputStream din ; private byte [ ] buffer ; private int bufferPointer , bytesRead ;   public Reader ( ) { din = new DataInputStream ( System . in ) ; buffer = new byte [ BUFFER_SIZE ] ; bufferPointer = bytesRead = 0 ; }   public Reader ( String file_name ) throws IOException { din = new DataInputStream ( new FileInputStream ( file_name ) ) ; buffer = new byte [ BUFFER_SIZE ] ; bufferPointer = bytesRead = 0 ; }   public String readLine ( ) throws IOException { byte [ ] buf = new byte [ 64 ] ;", "import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . io . Reader ; import java . util . Arrays ; import java . util . Comparator ; import java . util . StringTokenizer ;   public class B {   static final long MODULO = ( long ) ( 1e9 + 7 ) ;   public static void main ( String [ ] args ) { BufferedScanner scanner = new BufferedScanner ( ) ; PrintWriter writer = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ;   int t = 1 ;", "import java . io . * ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . StringTokenizer ; import java . util . List ; import java . util . * ; public class realfast implements Runnable { private static final int INF = ( int ) 1e9 ; long in = ( long ) Math . pow ( 10 , 9 ) + 7 ; long fac [ ] = new long [ 3000 ] ; public void solve ( ) throws IOException { int n = readInt ( ) ; int a [ ] = new int [ n ] ; int b [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = readInt ( ) ; b [ i ] = a [ i ] ; } Arrays . sort ( b ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == b [ n - 1 ] ) { out . print ( b [ 0 ] + \" ▁ \" ) ; } else {   for ( int j = 0 ; j < n ; j ++ ) { if ( b [ j ] > a [ i ] ) { out . print ( b [ j ] + \" ▁ \" ) ; break ; } }   } } } public int gcd ( int a , int b ) { if ( a < b ) { int t = a ; a = b ; b = t ; } if ( a % b == 0 ) return b ; return gcd ( b , a % b ) ; } public long pow ( long n , long p , long m ) { if ( p == 0 ) return 1 ; long val = pow ( n , p / 2 , m ) ; ; val = ( val * val ) % m ; if ( p % 2 == 0 ) return val ; else return ( val * n ) % m ; }", "import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayDeque ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Random ; import java . util . StringTokenizer ; import java . util . TreeSet ;   public class Solution { public static void main ( String [ ] args ) throws IOException { FastScanner fs = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int tt = 1 ; while ( tt -- > 0 ) { int n = fs . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] [ 0 ] = fs . nextInt ( ) ; a [ i ] [ 1 ] = i ; } Arrays . sort ( a , ( x , y ) -> x [ 0 ] - y [ 0 ] ) ; int [ ] ans = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { ans [ a [ i - 1 ] [ 1 ] ] = a [ i ] [ 0 ] ; } ans [ a [ n - 1 ] [ 1 ] ] = a [ 0 ] [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { out . print ( ans [ i ] + \" ▁ \" ) ; } out . println ( ) ; } out . close ( ) ; } static final Random random = new Random ( ) ; static < T > void shuffle ( T [ ] arr ) { int n = arr . length ; for ( int i = 0 ; i < n ; i ++ ) { int k = random . nextInt ( n ) ; T temp = arr [ k ] ; arr [ k ] = arr [ i ] ; arr [ i ] = temp ; } } static void ruffleSort ( int [ ] a ) { int n = a . length ;" ]
[ "input ( ) t = list ( map ( int , input ( ) . split ( ) ) ) s = sorted ( t ) for q in t : print ( s [ s . index ( q ) - 1 ] ) NEW_LINE", "from collections import defaultdict , dequeimport sysimport bisectinput = sys . stdin . readline     n = int ( input ( ) ) a = [ int ( i ) for i in input ( ) . split ( ) if i != ' \\n ' ] ind = defaultdict ( int ) for i in range ( n ) : ind [ a [ i ] ] = ia . sort ( ) ans = [ 0 ] * ( n ) for i in range ( n ) : index = ind [ a [ ( i + 1 ) % n ] ] ans [ index ] = a [ i ] print ( * ans ) NEW_LINE", "n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) arr = sorted ( a , reverse = True ) ans = [ None for x in range ( n ) ] for i in range ( n - 1 ) : pos = a . index ( arr [ i ] ) ans [ pos ] = arr [ i + 1 ] for i in range ( n ) : if ans [ i ] == None : ans [ i ] = arr [ 0 ] print ( * ans ) NEW_LINE", "input ( ) t = list ( map ( int , input ( ) . split ( ) ) ) s = sorted ( t ) for q in t : print ( s [ s . index ( q ) - 1 ] ) NEW_LINE" ]
codeforces_821_B
[ "import java . util . Scanner ;   public class B821 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long M = in . nextInt ( ) ; long B = in . nextInt ( ) ; long max = 0 ; for ( long y = B ; y >= 0 ; y -- ) { long x = ( B - y ) * M ; long current = y * ( y + 1 ) / 2 * ( x + 1 ) + x * ( x + 1 ) / 2 * ( y + 1 ) ; max = Math . max ( max , current ) ; } System . out . println ( max ) ; }   }", "import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ;   public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; BOkabeIBananovieDerevya solver = new BOkabeIBananovieDerevya ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; }   static class BOkabeIBananovieDerevya { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int m , b ; m = in . nextInt ( ) ; b = in . nextInt ( ) ; long best = 0 ; for ( int y = b ; y >= 0 ; -- y ) { long x = m * ( b - y ) ; long t = 0 ; t += ( x + 1 ) * sum ( y ) + ( y + 1 ) * sum ( x ) ; best = Math . max ( best , t ) ; } out . println ( best ) ; }   long sum ( long k ) { return k * ( k + 1 ) / 2 ; }   }   static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ;   public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; }   public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; }   public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   } }  ", "import java . io . * ; import java . util . * ;   public class Codeforces {   public static void main ( String ... args ) { InputReader sc = new InputReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; Thread th = new Thread ( null , new Runnable ( ) { public void run ( ) { new Solver ( ) . solve ( sc , out ) ; } } , \" Solver \" , 1 << 24 ) ; try { th . start ( ) ; th . join ( ) ; } catch ( InterruptedException e ) { } out . close ( ) ; } }   class Solver {   public long getSum ( long x ) { if ( x == - 1 ) return 0 ; return x * ( x + 1 ) / 2 ; }   public void solve ( InputReader sc , PrintWriter out ) { long m = sc . nextInt ( ) ; long b = sc . nextInt ( ) ; long ans = 0 ; for ( long i = 0 ; i < b ; i ++ ) { long j = m * ( b - i ) ; long sum = 0 ; for ( long k = i ; k >= 0 ; k -- ) { sum += ( getSum ( k + j ) - getSum ( k - 1 ) ) ; } ans = Math . max ( ans , sum ) ; } ans = Math . max ( ans , getSum ( b - 1 ) ) ; out . println ( ans ) ; } }  ", "import java . util . * ; import java . io . * ;   public class tr0 { static PrintWriter out ; static StringBuilder sb ; static int mod = 998244353 ; static int inf = ( int ) 1e18 ; static int [ ] col ; static int n , m ; static ArrayList < Integer > [ ] ad ; static long [ ] memo , cnt [ ] ; static ArrayList < Integer > h ; static int [ ] pos , ones ; static char [ ] [ ] g ; static boolean [ ] [ ] vis ; static boolean f ;   public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; int m = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; long ans = 0 ; for ( int i = 0 ; i <= b ; i ++ ) { int y = ( b - i ) * m ; long tem = y * 1l * ( i + 1 ) * ( y + 1 ) / 2 ; tem += ( y + 1 ) * 1l * i * ( i + 1 ) / 2 ; ans = Math . max ( ans , tem ) ;" ]
[ "ans = [ ] m , b = map ( int , input ( ) . split ( ) ) for x in range ( m * b + 1 ) : y = - x / m + b if y . is_integer ( ) : y = - x // m + b start = ( 0 + x ) * ( x + 1 ) // 2 end = ( start + y * ( x + 1 ) ) ans . append ( int ( ( start + end ) * ( y + 1 ) // 2 ) ) print ( max ( ans ) ) NEW_LINE", "m , b = list ( map ( int , input ( ) . split ( ) ) )             u = 0 for j in range ( b - 1 , - 1 , - 1 ) : y = j x = m * ( b - j )   s = x * ( x + 1 ) // 2 t = y * ( y + 1 ) // 2 p = t + s + ( s ) * y + t * x if p > u : u = p   print ( u ) NEW_LINE", "  def get ( i , j ) : return ( i + 1 ) * ( j + 1 ) * ( i + j ) // 2   m , b = map ( int , input ( ) . split ( ) ) res = - 1 for y in range ( b ) : x = ( b - y ) * m res = max ( get ( x , y ) , res ) print ( res ) NEW_LINE", "import math , sys , bisect , heapqfrom collections import defaultdict , Counter , dequefrom itertools import groupby , accumulate NEW_LINE" ]
codeforces_229_B
[ "import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . * ;     public class Planets {   public static void main ( String [ ] args ) {   InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader sc = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Solver solver = new Solver ( ) ;", "import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; import java . io . * ; public class codeforces { static class Student { int x ; long y ;" ]
[ "from sys import stdin , stdoutfrom collections import defaultdictfrom heapq import heapify , heappop , heappushnmbr = lambda : int ( stdin . readline ( ) ) lst = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) PI = float ( ' inf ' ) def dijsktra ( ) : dist = [ PI ] * ( 1 + n ) dist [ 1 ] = 0 NEW_LINE", "from heapq import * from sys import stdin , stdoutinput = stdin . readlinedef BinSearch ( li , x , len ) : i = 1 j = len while i < j : m = int ( ( i + j ) / 2 ) if x > li [ m ] : i = m + 1 else : j = m if li [ j ] == x : return j else : return None n , m = map ( int , input ( ) . split ( ) )   dist = [ 10 ** 20 for i in range ( n + 1 ) ] G = [ [ ] for i in range ( n + 1 ) ] T = [ [ None ] ]   for i in range ( m ) : u , v , w = map ( int , input ( ) . split ( ) ) G [ u ] . append ( ( v , w ) ) G [ v ] . append ( ( u , w ) ) for i in range ( n ) : x = list ( map ( int , input ( ) . split ( ) ) ) T . append ( x ) unused = [ ( 0 , 1 ) ] parent = [ - 1 for i in range ( n + 1 ) ] dist [ 1 ] = 0 min_dist = 0 nex = 1   while unused : t , nex = heappop ( unused ) if T [ nex ] [ 0 ] != 0 : j = BinSearch ( T [ nex ] , t , T [ nex ] [ 0 ] ) if j != None : while j <= T [ nex ] [ 0 ] and t == T [ nex ] [ j ] : t += 1 j += 1 for edge in G [ nex ] : to = edge [ 0 ] wt = edge [ 1 ] if t + wt < dist [ to ] : dist [ to ] = t + wt NEW_LINE", "from heapq import * from sys import stdin , stdoutinput = stdin . readlinedef BinSearch ( li , x , len ) : i = 1 j = len while i < j : m = int ( ( i + j ) / 2 ) if x > li [ m ] : i = m + 1 else : j = m if li [ j ] == x : return j else : return None n , m = map ( int , input ( ) . split ( ) )   dist = [ 10 ** 20 for i in range ( n + 1 ) ] G = [ [ ] for i in range ( n + 1 ) ] T = [ [ None ] ]   for i in range ( m ) : u , v , w = map ( int , input ( ) . split ( ) ) G [ u ] . append ( ( v , w ) ) G [ v ] . append ( ( u , w ) ) for i in range ( n ) : x = list ( map ( int , input ( ) . split ( ) ) ) T . append ( x ) unused = [ ( 0 , 1 ) ] parent = [ - 1 for i in range ( n + 1 ) ] dist [ 1 ] = 0 min_dist = 0 nex = 1   while unused : t , nex = heappop ( unused ) if T [ nex ] [ 0 ] != 0 : j = BinSearch ( T [ nex ] , t , T [ nex ] [ 0 ] ) if j != None : while j <= T [ nex ] [ 0 ] and t == T [ nex ] [ j ] : t += 1 j += 1 for edge in G [ nex ] : to = edge [ 0 ] wt = edge [ 1 ] if t + wt < dist [ to ] : dist [ to ] = t + wt NEW_LINE", "from sys import stdin , stdoutfrom collections import defaultdictfrom heapq import heapify , heappop , heappushnmbr = lambda : int ( stdin . readline ( ) ) lst = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) PI = float ( ' inf ' ) def dijsktra ( ) : dist = [ PI ] * ( 1 + n ) dist [ 1 ] = 0 vis = [ 0 ] * ( 1 + n ) hp = [ ] heapify ( hp ) heappush ( hp , ( 0 , 1 ) ) while hp : curDis , curNode = heappop ( hp ) if vis [ curNode ] : continue vis [ curNode ] = 1 for neigh , wt in g [ curNode ] : if vis [ neigh ] : continue eff_wt = wt if curDis in t [ curNode ] : eff_wt += t [ curNode ] [ curDis ] - curDis if curDis + eff_wt < dist [ neigh ] : dist [ neigh ] = curDis + eff_wt heappush ( hp , ( curDis + eff_wt , neigh ) ) NEW_LINE", "from sys import stdin , stdoutfrom collections import defaultdictfrom heapq import heapify , heappop , heappushnmbr = lambda : int ( stdin . readline ( ) ) lst = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) PI = float ( ' inf ' ) def dijsktra ( ) : dist = [ PI ] * ( 1 + n ) dist [ 1 ] = 0 vis = [ 0 ] * ( 1 + n ) hp = [ ] heappush ( hp , ( 0 , 1 ) ) while hp : curDis , curNode = heappop ( hp ) if vis [ curNode ] : continue vis [ curNode ] = 1 for neigh , wt in g [ curNode ] : if vis [ neigh ] : continue eff_wt = wt if curDis in t [ curNode ] : eff_wt += t [ curNode ] [ curDis ] - curDis if curDis + eff_wt < dist [ neigh ] : dist [ neigh ] = curDis + eff_wt heappush ( hp , ( curDis + eff_wt , neigh ) ) NEW_LINE" ]
codeforces_849_A
[ "import java . util . Scanner ;   public class P849A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } System . out . println ( a [ 0 ] % 2 != 0 && a [ n - 1 ] % 2 != 0 && n % 2 != 0 ? \" Yes \" : \" No \" ) ; } }", "import java . io . * ; import java . util . * ;   public class Composite { static final Random random = new Random ( ) ; static PrintWriter out = new PrintWriter ( ( System . out ) ) ; static Reader sc = new Reader ( ) ;   public static void main ( String args [ ] ) throws IOException { int n = sc . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; boolean f = false ; int c = 0 ; if ( n % 2 == 0 ) { System . out . println ( \" no \" ) ; f = true ; }   else if ( a [ 0 ] % 2 != 0 && a [ n - 1 ] % 2 != 0 ) { f = true ; System . out . println ( \" yes \" ) ; }   else { for ( int i = 0 ; i < n ; i ++ ) { if ( a [ 0 ] % 2 == 0 ) { f = true ; System . out . println ( \" no \" ) ; break ; } else if ( a [ i ] % 2 == 0 ) { c ++ ;   if ( c >= 1 ) { f = true ; System . out . println ( \" No \" ) ; break ; }   } else continue ; }   } if ( f == false ) System . out . println ( \" yes \" ) ; }  ", "  import java . io . * ; import java . util . * ; public class Solution { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int arr [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } if ( arr [ 0 ] % 2 != 0 && arr [ n - 1 ] % 2 != 0 && arr . length % 2 != 0 ) { System . out . println ( \" Yes \" ) ; } else { System . out . println ( \" No \" ) ; } } }" ]
[ "n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) if n % 2 == 0 or a [ 0 ] % 2 == 0 or a [ - 1 ] % 2 == 0 : print ( ' No ' ) else : print ( ' Yes ' ) NEW_LINE", "n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) if n % 2 == 0 or a [ 0 ] % 2 == 0 or a [ - 1 ] % 2 == 0 : print ( \" NO \" ) else : print ( \" YES \" ) NEW_LINE", "n = int ( input ( ) ) g = list ( map ( int , input ( ) . split ( ) ) )   if len ( g ) % 2 == 1 and g [ 0 ] % 2 == 1 and g [ - 1 ] % 2 == 1 : print ( \" YES \" ) else : print ( \" NO \" ) NEW_LINE", "n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) if n % 2 == 1 and l [ 0 ] % 2 == 1 and l [ n - 1 ] % 2 == 1 : print ( ' Yes ' ) else : print ( ' No ' ) NEW_LINE", "n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) if n % 2 == 0 : print ( ' No ' ) else : if a [ 0 ] % 2 == 0 or a [ - 1 ] % 2 == 0 : print ( ' No ' ) else : print ( ' Yes ' ) NEW_LINE" ]