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 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 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


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 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


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 ( ) ; } }


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 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


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 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 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


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 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 ( ) ; } }

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


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 ; } }


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


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 ; } }

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


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 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 ( ) ; } }

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


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 ( ) ; } }


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 ( ) ; } }

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


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 ( ) ; } }


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 ( ) ; } } }

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