import java . io . * ; import java . util . * ; public class ExpensiveDinner { void solve ( ) throws Exception { long n = nextLong ( ) ; if ( n == 1 ) { out . println ( 0 ) ; return ; } ArrayList < Long > primes = new ArrayList < Long > ( ) ; int sqrt = ( int ) Math . sqrt ( n ) + 10 ; boolean [ ] a = new boolean [ sqrt + 1 ] ; for ( int i = 2 ; i <= sqrt ; i ++ ) { if ( ! a [ i ] ) { primes . add ( ( long ) i ) ; for ( int j = 2 * i ; j <= sqrt ; j += i ) a [ j ] = true ; } } long ans1 = 0 ; long ans2 = 1 ; for ( long i : primes ) { if ( i > n ) break ; ans1 ++ ; long j = i ; while ( j <= n ) { ans2 ++ ; j *= i ; } } out . println ( ans2 - ans1 ) ; } void run ( ) { try { in = new BufferedReader ( new FileReader ( " input . txt " ) ) ; out = new PrintWriter ( " output . txt " ) ; int tests = nextInt ( ) ; for ( int i = 0 ; i < tests ; i ++ ) { out . print ( " Case ▁ # " + ( i + 1 ) + " : ▁ " ) ; solve ( ) ; } out . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } BufferedReader in ; StringTokenizer st ; PrintWriter out ; final String filename = new String ( " ExpensiveDinner " ) . toLowerCase ( ) ; String nextToken ( ) throws Exception { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( in . readLine ( ) ) ; return st . nextToken ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) throws Exception { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) throws Exception { return Double . parseDouble ( nextToken ( ) ) ; } public static void main ( String [ ] args ) { new ExpensiveDinner ( ) . run ( ) ; } }


def primelist ( N ) : NEW_LINE INDENT ps = [ 2 ] NEW_LINE cur = 3 NEW_LINE for cur in range ( 3 , N ) : NEW_LINE INDENT for prime in ps : NEW_LINE INDENT if prime * prime > cur : NEW_LINE INDENT ps . append ( cur ) NEW_LINE break NEW_LINE DEDENT if cur % prime == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return ps NEW_LINE DEDENT def run ( plist ) : NEW_LINE INDENT f = open ( " input . in " ) NEW_LINE g = open ( " out . txt " , ' w ' ) NEW_LINE num = int ( f . readline ( ) ) NEW_LINE for i in range ( num ) : NEW_LINE INDENT g . write ( " Case ▁ # % d : ▁ " % ( i + 1 ) ) NEW_LINE n = int ( f . readline ( ) ) NEW_LINE times = [ ] NEW_LINE for p in plist : NEW_LINE INDENT if p ^ 2 > n : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE m = n / p NEW_LINE while m >= p : NEW_LINE INDENT m = m / p NEW_LINE count = count + 1 NEW_LINE DEDENT if count > 0 : NEW_LINE INDENT times . append ( count ) NEW_LINE DEDENT DEDENT DEDENT if times : NEW_LINE INDENT g . write ( " % d \n " % ( sum ( times ) + 1 ) ) NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT g . write ( "0 \n " ) NEW_LINE DEDENT else : NEW_LINE INDENT g . write ( "1 \n " ) NEW_LINE DEDENT DEDENT f . close ( ) NEW_LINE g . close ( ) NEW_LINE DEDENT


import sys NEW_LINE from fractions import gcd NEW_LINE import multiprocessing NEW_LINE cin = sys . stdin . readline NEW_LINE isp = [ 1 ] * 1000500 NEW_LINE isp [ 0 ] = isp [ 1 ] = 0 NEW_LINE LL = len ( isp ) NEW_LINE prims = [ ] NEW_LINE for i in xrange ( 2 , LL ) : NEW_LINE INDENT if not isp [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT prims . append ( i ) NEW_LINE j = i * i NEW_LINE while j < LL : NEW_LINE INDENT isp [ j ] = 0 NEW_LINE j += i NEW_LINE DEDENT DEDENT def solve ( N ) : NEW_LINE INDENT if ( N == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT pp = [ ] NEW_LINE high = 1 NEW_LINE for prim in prims : NEW_LINE INDENT if prim > N : NEW_LINE INDENT break NEW_LINE DEDENT p = 1 NEW_LINE q = prim NEW_LINE while q * prim <= N : NEW_LINE INDENT p += 1 NEW_LINE q *= prim NEW_LINE DEDENT high += p NEW_LINE pp . append ( q ) NEW_LINE DEDENT pp . sort ( ) NEW_LINE pp = pp [ : : - 1 ] NEW_LINE at = 0 NEW_LINE LE = len ( pp ) NEW_LINE while at < LE : NEW_LINE INDENT q = pp [ at ] NEW_LINE while at + 1 < LE and q * pp [ at + 1 ] <= N : NEW_LINE INDENT at += 1 NEW_LINE q *= pp [ at + 1 ] NEW_LINE DEDENT high -= 1 NEW_LINE at += 1 NEW_LINE DEDENT return high NEW_LINE DEDENT def procfunc ( tup ) : NEW_LINE INDENT x = solve ( * tup [ 1 : ] ) NEW_LINE print >> sys . stderr , " SOLVE " , tup [ 0 ] NEW_LINE return x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT T = int ( cin ( ) ) NEW_LINE inputs = [ ] NEW_LINE for cnum in xrange ( T ) : NEW_LINE INDENT N = int ( cin ( ) ) NEW_LINE inputs . append ( ( cnum , N ) ) NEW_LINE DEDENT if True : NEW_LINE INDENT pool = multiprocessing . Pool ( ) NEW_LINE output = pool . map_async ( procfunc , inputs , 1 ) . get ( 999999 ) NEW_LINE DEDENT else : NEW_LINE INDENT output = list ( procfunc ( x ) for x in inputs ) NEW_LINE DEDENT for i , out in enumerate ( output ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( i + 1 , out ) NEW_LINE DEDENT DEDENT


import sys NEW_LINE from math import * NEW_LINE def lg ( a ) : NEW_LINE INDENT sys . stderr . write ( str ( a ) + " \n " ) NEW_LINE DEDENT def sieve ( n ) : NEW_LINE INDENT sqrtn = int ( n ** 0.5 ) NEW_LINE sieve = [ True ] * ( n + 1 ) NEW_LINE sieve [ 0 ] = False NEW_LINE sieve [ 1 ] = False NEW_LINE for i in range ( 2 , sqrtn + 1 ) : NEW_LINE INDENT if sieve [ i ] : NEW_LINE INDENT m = n // i - i NEW_LINE sieve [ i * i : n + 1 : i ] = [ False ] * ( m + 1 ) NEW_LINE DEDENT DEDENT sieve = [ i for i in range ( n + 1 ) if sieve [ i ] ] NEW_LINE return sieve NEW_LINE DEDENT import math NEW_LINE s = sieve ( 1000001 ) NEW_LINE t = int ( sys . stdin . readline ( ) ) NEW_LINE for testNr in range ( 1 , t + 1 ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE sqrtn = int ( n ** 0.5 ) NEW_LINE print " Case ▁ # % d : " % testNr , NEW_LINE if n == 1 : NEW_LINE INDENT print 0 NEW_LINE continue NEW_LINE DEDENT sum = 1 NEW_LINE for p in s : NEW_LINE INDENT if p * p > n : NEW_LINE INDENT break NEW_LINE DEDENT q = p * p NEW_LINE while q <= n : NEW_LINE INDENT sum += 1 NEW_LINE q *= p NEW_LINE DEDENT DEDENT print sum NEW_LINE DEDENT


def memoized ( func ) : NEW_LINE INDENT mem = { } NEW_LINE def wrapped ( * args ) : NEW_LINE INDENT if args not in mem : NEW_LINE INDENT mem [ args ] = func ( * args ) NEW_LINE DEDENT return mem [ args ] NEW_LINE DEDENT return wrapped NEW_LINE DEDENT TASK = " C " NEW_LINE print ( " Precalculation . . . " ) NEW_LINE import math NEW_LINE def isprime ( num , primes ) : NEW_LINE INDENT s = math . sqrt ( num ) NEW_LINE for p in primes : NEW_LINE INDENT if p > s : NEW_LINE INDENT return True NEW_LINE DEDENT if num % p == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT primes = [ ] NEW_LINE for i in xrange ( 2 , 10 ** 6 + 1 ) : NEW_LINE INDENT if isprime ( i , primes ) : NEW_LINE INDENT primes . append ( i ) NEW_LINE DEDENT DEDENT print ( " Precalculation ▁ done . " ) NEW_LINE print ( " Calculation . . . " ) NEW_LINE with open ( TASK + " . in " ) as infile : NEW_LINE INDENT with open ( TASK + " . out " , mode = " wt " ) as outfile : NEW_LINE INDENT cases = int ( infile . readline ( ) ) NEW_LINE for ncase in range ( cases ) : NEW_LINE INDENT N = int ( infile . readline ( ) ) NEW_LINE s = math . sqrt ( N ) NEW_LINE ans = 0 NEW_LINE for p in primes : NEW_LINE INDENT if p > s : break NEW_LINE ans += int ( math . log ( N , p ) ) - 1 NEW_LINE DEDENT if N > 1 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT outfile . write ( " Case ▁ # { nc } : ▁ { data } \n " . format ( nc = ncase + 1 , data = ans ) ) NEW_LINE DEDENT DEDENT DEDENT print ( " Calculation ▁ done . " ) NEW_LINE


import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . StringTokenizer ; public class Enclosure { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( new File ( " in " ) ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( new File ( " out " ) ) ) ; StringTokenizer st ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int cn = 1 ; cn <= T ; cn ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int M = Integer . parseInt ( st . nextToken ( ) ) ; int K = Integer . parseInt ( st . nextToken ( ) ) ; int ans = K ; for ( int i = 3 ; i <= N ; i ++ ) { for ( int j = 3 ; j <= M ; j ++ ) { int stones = 2 * ( i - 2 ) + 2 * ( j - 2 ) ; int covered = i * j - 4 ; if ( K <= covered ) ans = Math . min ( ans , stones ) ; for ( int k = 1 ; k <= 4 ; k ++ ) if ( K <= covered + k ) ans = Math . min ( ans , stones + k ) ; if ( i < N || j < M ) if ( K <= covered + 2 ) ans = Math . min ( ans , stones + 1 ) ; } } System . out . println ( N + " ▁ " + M + " ▁ " + K + " ▁ " + ans ) ; bw . append ( " Case ▁ # " + cn + " : ▁ " ) ; bw . append ( ans + " \n " ) ; } bw . flush ( ) ; } }

import sys NEW_LINE iFile = open ( sys . argv [ 1 ] , " r " ) NEW_LINE size = int ( iFile . readline ( ) . strip ( ) ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT line = iFile . readline ( ) . strip ( ) . split ( ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE M = int ( line [ 1 ] ) NEW_LINE K = int ( line [ 2 ] ) NEW_LINE stones = 0 NEW_LINE if K <= 4 : NEW_LINE INDENT stones = K NEW_LINE DEDENT elif min ( N , M ) <= 2 : NEW_LINE INDENT stones = K NEW_LINE DEDENT elif min ( N , M ) == 3 : NEW_LINE INDENT enclosed = int ( ( K - 2 ) / 3 ) NEW_LINE enclosed = min ( enclosed , max ( N , M ) - 2 ) NEW_LINE stones = K - enclosed NEW_LINE DEDENT else : NEW_LINE INDENT if K < 8 : NEW_LINE INDENT enclosed = 1 NEW_LINE DEDENT elif K < 10 : NEW_LINE INDENT enclosed = 2 NEW_LINE DEDENT elif K < 12 : NEW_LINE INDENT enclosed = 3 NEW_LINE DEDENT elif K < 14 or max ( N , M ) == 4 : NEW_LINE INDENT enclosed = 4 NEW_LINE DEDENT elif K < 16 : NEW_LINE INDENT enclosed = 5 NEW_LINE DEDENT else : NEW_LINE INDENT enclosed = 6 NEW_LINE DEDENT stones = K - enclosed NEW_LINE DEDENT output = str ( stones ) NEW_LINE print ( " Case ▁ # " + str ( i + 1 ) + " : ▁ " + output ) NEW_LINE DEDENT


nR = int ( input ( ) ) NEW_LINE for run in range ( nR ) : NEW_LINE INDENT data = input ( ) . split ( ) NEW_LINE N = int ( data [ 0 ] ) NEW_LINE M = int ( data [ 1 ] ) NEW_LINE K = int ( data [ 2 ] ) NEW_LINE mini = K NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT for j in range ( 2 , M + 1 ) : NEW_LINE INDENT loss = 0 NEW_LINE rm = 0 NEW_LINE for k in range ( min ( i , j ) // 2 ) : NEW_LINE INDENT for m in range ( 5 ) : NEW_LINE INDENT if 2 * k == min ( i , j ) and m > 2 : NEW_LINE INDENT break NEW_LINE DEDENT if i * j - loss < K : NEW_LINE INDENT break NEW_LINE DEDENT if 2 * ( i + j ) - 4 - rm < mini : NEW_LINE INDENT mini = 2 * ( i + j ) - 4 - rm NEW_LINE DEDENT loss += ( k + 1 ) NEW_LINE rm += 1 NEW_LINE DEDENT if i * j - loss < K : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( " Case ▁ # " + str ( run + 1 ) + " : ▁ " + str ( mini ) ) NEW_LINE DEDENT


N = None NEW_LINE M = None NEW_LINE K = None NEW_LINE def BT ( stone , inter , width , height ) : NEW_LINE INDENT global N NEW_LINE global M NEW_LINE global K NEW_LINE if inter >= K : NEW_LINE INDENT return stone NEW_LINE DEDENT ret = None NEW_LINE if K - inter <= 4 : NEW_LINE INDENT ret = stone + K - inter NEW_LINE DEDENT if width + 1 <= N : NEW_LINE INDENT if not ret : NEW_LINE INDENT ret = BT ( stone + 2 , inter + height / 2 + 2 , width + 1 , height ) NEW_LINE DEDENT else : NEW_LINE INDENT ret = min ( ret , BT ( stone + 2 , inter + height / 2 + 2 , width + 1 , height ) ) NEW_LINE DEDENT DEDENT if height + 1 <= M : NEW_LINE INDENT if not ret : NEW_LINE INDENT ret = BT ( stone + 2 , inter + width / 2 + 2 , width , height + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ret = min ( ret , BT ( stone + 2 , inter + width / 2 + 2 , width , height + 1 ) ) NEW_LINE DEDENT DEDENT if width + 1 <= N and height > 3 and inter + 2 >= K : NEW_LINE INDENT ret = min ( ret , stone + 1 ) NEW_LINE DEDENT if height + 1 <= M and width > 3 and inter + 2 >= K : NEW_LINE INDENT ret = min ( ret , stone + 1 ) NEW_LINE DEDENT return ret NEW_LINE DEDENT T = input ( ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , M , K = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE if N < 3 or M < 3 or K <= 4 : NEW_LINE INDENT print " Case ▁ # { 0 } : ▁ { 1 } " . format ( t + 1 , K ) NEW_LINE DEDENT else : NEW_LINE INDENT print " Case ▁ # { 0 } : ▁ { 1 } " . format ( t + 1 , BT ( 4 , 5 , 3 , 3 ) ) NEW_LINE DEDENT DEDENT


def reader ( inFile ) : NEW_LINE INDENT return tuple ( inFile . getInts ( ) ) NEW_LINE DEDENT from itertools import combinations NEW_LINE def solver ( ( N , M , K ) ) : NEW_LINE INDENT points = [ ( i , j ) for i in xrange ( N ) for j in xrange ( M ) ] NEW_LINE rec = 0 NEW_LINE for sets in combinations ( points , K ) : NEW_LINE INDENT v = set ( sets ) NEW_LINE scr = len ( [ z for z in v if len ( [ 1 for ( a , b ) in [ ( - 1 , 0 ) , ( 1 , 0 ) , ( 0 , - 1 ) , ( 0 , 1 ) ] if ( z [ 0 ] + a , z [ 1 ] + b ) in v ] ) == 4 ] ) NEW_LINE if scr > rec : NEW_LINE INDENT rec = scr NEW_LINE DEDENT DEDENT return K - rec NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , " / Users / luke / gcj / 2014/1c / c " , " c " ) . run ( ) NEW_LINE DEDENT


from cmath import sqrt NEW_LINE import math NEW_LINE T = int ( input ( ) ) NEW_LINE test = 1 NEW_LINE while test <= T : NEW_LINE INDENT print ( " Case ▁ # " + str ( test ) + " : ▁ " , end = " " ) NEW_LINE test += 1 NEW_LINE mnk = input ( ) . split ( ) NEW_LINE m = int ( mnk [ 0 ] ) NEW_LINE n = int ( mnk [ 1 ] ) NEW_LINE k = int ( mnk [ 2 ] ) NEW_LINE if m > n : NEW_LINE INDENT tmp = n NEW_LINE n = m NEW_LINE m = tmp NEW_LINE DEDENT if m <= 2 : NEW_LINE INDENT print ( k ) NEW_LINE continue NEW_LINE DEDENT if m * n - k <= 4 : NEW_LINE INDENT print ( ( m + n - 4 ) * 2 - m * n + k + 4 ) NEW_LINE continue NEW_LINE DEDENT size = math . ceil ( sqrt ( k + 4 ) . real ) NEW_LINE w = 0 NEW_LINE if size > m : NEW_LINE INDENT w = m NEW_LINE DEDENT else : NEW_LINE INDENT w = size NEW_LINE DEDENT h = size - 1 NEW_LINE while w * h - 4 < k : NEW_LINE INDENT h += 1 NEW_LINE DEDENT ans = ( w + h - 4 ) * 2 NEW_LINE if h > w : NEW_LINE INDENT tmp = h NEW_LINE h = w NEW_LINE w = tmp NEW_LINE DEDENT if ( w * h - 4 ) - k >= 2 and m > 3 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT if ( w - 1 ) * h - 3 >= k : NEW_LINE INDENT ans = min ( ( w + h - 5 ) * 2 + 1 , ans ) NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT


package codejam ; import java . io . * ; import java . util . Scanner ; public abstract class Task { protected abstract String getName ( ) ; protected abstract void runOne ( Scanner input , PrintWriter output ) ; void run ( InputStream input , OutputStream output ) { Scanner in = new Scanner ( input ) ; PrintWriter out = new PrintWriter ( output ) ; int testsCount = in . nextInt ( ) ; in . nextLine ( ) ; for ( int test = 1 ; test <= testsCount ; test ++ ) { System . out . println ( " solving ▁ " + test ) ; out . print ( " Case ▁ # " + test + " : ▁ " ) ; runOne ( in , out ) ; out . flush ( ) ; } } public static void runConsole ( Task task ) { task . run ( System . in , System . out ) ; } public static void runSmall ( Task task , int num ) throws IOException { runFiles ( task , new File ( " . / " + task . getName ( ) + " - small - attempt " + num + " . in " ) , new File ( " . / " + task . getName ( ) + " - small - attempt " + num + " . out " ) ) ; } public static void runLarge ( Task task ) throws IOException { runFiles ( task , new File ( " . / " + task . getName ( ) + " - large . in " ) , new File ( " . / " + task . getName ( ) + " - large . out " ) ) ; } private static void runFiles ( Task task , File input , File output ) throws IOException { InputStream is = new BufferedInputStream ( new FileInputStream ( input ) ) ; OutputStream os = new BufferedOutputStream ( new FileOutputStream ( output ) ) ; task . run ( is , os ) ; is . close ( ) ; os . close ( ) ; } }


import java . util . Scanner ; public class C2 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= cases ; caseNum ++ ) { int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; if ( N == 1 || M == 1 ) { System . out . println ( " Case ▁ # " + caseNum + " : ▁ " + K ) ; continue ; } int answer = 2 * N + 2 * M - 4 ; for ( int stones = 2 * N + 2 * M - 5 ; stones > 0 ; stones -- ) { int newEnclosed = Math . max ( temp ( M , N , stones ) , temp ( N , M , stones ) ) ; if ( newEnclosed >= K ) { answer = stones ; } else { break ; } } System . out . println ( " Case ▁ # " + caseNum + " : ▁ " + answer ) ; } } private static int temp ( int N , int M , int stones ) { int diff = 2 * N + 2 * M - 4 - stones ; int d1 = diff / 4 ; int d2 = ( diff + 1 ) / 4 ; int d3 = ( diff + 2 ) / 4 ; int d4 = ( diff + 3 ) / 4 ; int newEnclosed = 0 ; for ( int n = 0 ; n < N ; n ++ ) { for ( int m = 0 ; m < M ; m ++ ) { if ( n + m >= d1 && n + ( M - 1 - m ) >= d2 && ( N - 1 - n ) + ( M - 1 - m ) >= d3 && ( N - 1 - n ) + m >= d4 ) { newEnclosed ++ ; } } } return newEnclosed ; } }


import java . util . * ; import java . io . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { int tests ; Scanner scanner = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; tests = scanner . nextInt ( ) ; for ( int z = 1 ; z <= tests ; z ++ ) { BigInteger L = scanner . nextBigInteger ( ) ; int ile = scanner . nextInt ( ) ; Vector < Integer > roznice = new Vector < Integer > ( ) ; while ( ile -- > 0 ) { roznice . add ( scanner . nextInt ( ) ) ; } Collections . sort ( roznice ) ; int last = roznice . lastElement ( ) ; roznice . removeElement ( last ) ; Vector < Integer > minodl = new Vector < Integer > ( last ) ; minodl . setSize ( last ) ; for ( int i = 0 ; i < minodl . size ( ) ; i ++ ) minodl . setElementAt ( Integer . MAX_VALUE , i ) ; Queue < Integer > q = new LinkedList < Integer > ( ) ; minodl . setElementAt ( 0 , 0 ) ; q . add ( 0 ) ; while ( q . isEmpty ( ) == false ) { Integer x = q . remove ( ) ; for ( Integer i : roznice ) { int newx = x + i ; int odl = minodl . elementAt ( x ) + 1 ; while ( newx >= last ) { newx -= last ; odl -- ; } if ( minodl . elementAt ( newx ) > odl ) { minodl . setElementAt ( odl , newx ) ; q . add ( newx ) ; } } } System . out . printf ( " Case ▁ # % d : ▁ " , z ) ; BigInteger odleglosc = BigInteger . valueOf ( last ) ; BigInteger wynik = L . divide ( odleglosc ) ; Integer indeks = L . mod ( odleglosc ) . intValue ( ) ; BigInteger ileKoniec = BigInteger . valueOf ( minodl . elementAt ( indeks ) ) ; if ( ileKoniec . compareTo ( BigInteger . valueOf ( Integer . MAX_VALUE ) ) >= 0 ) { System . out . println ( " IMPOSSIBLE " ) ; } else { wynik = wynik . add ( ileKoniec ) ; System . out . println ( wynik ) ; } } } }

import sys NEW_LINE b = [ ] NEW_LINE def calcb ( a ) : NEW_LINE INDENT res = [ ] NEW_LINE last = 0 NEW_LINE for i in range ( len ( a ) - 1 ) : NEW_LINE INDENT res . append ( last + a [ i ] * ( a [ i + 1 ] - 1 ) ) NEW_LINE last = res [ - 1 ] NEW_LINE DEDENT b [ : ] = res NEW_LINE DEDENT def foo ( ifile ) : NEW_LINE INDENT L , N = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] NEW_LINE a = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] NEW_LINE a . sort ( ) NEW_LINE calcb ( a ) NEW_LINE res = { } NEW_LINE res [ 0 ] = ( 0 , 0 ) NEW_LINE n = len ( a ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT res2 = { } NEW_LINE for k , v in res . iteritems ( ) : NEW_LINE INDENT for j in range ( v [ 1 ] , v [ 1 ] + a [ i + 1 ] ) : NEW_LINE INDENT t1 = k + a [ i ] * j NEW_LINE t2 = t1 // a [ i + 1 ] NEW_LINE t3 = t1 % a [ i + 1 ] NEW_LINE t4 = v [ 0 ] + j - t2 NEW_LINE t5 = ( t4 , t2 ) NEW_LINE if t3 not in res2 : NEW_LINE INDENT res2 [ t3 ] = t5 NEW_LINE DEDENT else : NEW_LINE INDENT res2 [ t3 ] = min ( res2 [ t3 ] , t5 ) NEW_LINE DEDENT DEDENT DEDENT res = res2 NEW_LINE DEDENT t = L % a [ - 1 ] NEW_LINE if t not in res : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT else : NEW_LINE INDENT return L // a [ - 1 ] + res [ t ] [ 0 ] NEW_LINE DEDENT DEDENT def main ( ifile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ' Case ▁ # % s : ▁ % s ' % ( i + 1 , foo ( ifile ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . stdin ) NEW_LINE DEDENT


for casenum in xrange ( 1 , 1 + int ( raw_input ( ) ) ) : NEW_LINE INDENT [ L , N ] = [ int ( z ) for z in raw_input ( ) . split ( ) ] NEW_LINE Bs = [ int ( z ) for z in raw_input ( ) . split ( ) ] NEW_LINE maxB = max ( Bs ) NEW_LINE Bs = [ z for z in Bs if z != maxB ] NEW_LINE nu = [ 10 ** 200 ] * maxB NEW_LINE nu [ 0 ] = 0 NEW_LINE q = [ [ 0 , 0 ] ] NEW_LINE while ( len ( q ) > 0 ) : NEW_LINE INDENT qe = q [ 0 ] NEW_LINE q = q [ 1 : ] NEW_LINE if ( nu [ qe [ 0 ] ] == qe [ 1 ] ) : NEW_LINE INDENT for b in Bs : NEW_LINE INDENT if ( qe [ 0 ] + b < maxB ) : NEW_LINE INDENT qf = [ qe [ 0 ] + b , qe [ 1 ] + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT qf = [ qe [ 0 ] + b - maxB , qe [ 1 ] ] NEW_LINE DEDENT if qf [ 1 ] < nu [ qf [ 0 ] ] : NEW_LINE INDENT nu [ qf [ 0 ] ] = qf [ 1 ] NEW_LINE q += [ qf ] NEW_LINE DEDENT DEDENT DEDENT DEDENT if ( nu [ L % maxB ] != ( 10 ** 200 ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( casenum , nu [ L % maxB ] + ( L / maxB ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print " Case ▁ # % d : ▁ IMPOSSIBLE " % casenum NEW_LINE DEDENT DEDENT


import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return [ foo ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE def run_test ( test ) : NEW_LINE INDENT global mem , a NEW_LINE ( L , N ) = readarray ( int ) NEW_LINE INF = L + 1 NEW_LINE a = readarray ( int ) NEW_LINE m = max ( a ) NEW_LINE dp = dict ( [ ( x , 1 ) for x in a ] ) NEW_LINE K = 50000 NEW_LINE for i in xrange ( K + 1000 ) : NEW_LINE INDENT r = dp [ i ] if i in dp else INF NEW_LINE for x in a : NEW_LINE INDENT if ( i - x ) in dp : NEW_LINE INDENT r = min ( r , dp [ i - x ] + 1 ) NEW_LINE DEDENT DEDENT if r < INF : NEW_LINE INDENT dp [ i ] = r NEW_LINE DEDENT DEDENT div = int ( ( L - K ) / m ) NEW_LINE res = div NEW_LINE left = L - div * m NEW_LINE return res + dp [ left ] if left in dp else " IMPOSSIBLE " NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( " Test ▁ % d \n " % ( test + 1 ) ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( test + 1 , run_test ( test ) ) NEW_LINE DEDENT


import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class B { public void solve ( ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( " B - small - attempt0 . in " ) ) ; PrintWriter out = new PrintWriter ( " B - small - attempt0 . out " ) ; int testN = in . nextInt ( ) ; for ( int test = 1 ; test <= testN ; test ++ ) { out . print ( " Case ▁ # " + test + " : ▁ " ) ; long l = in . nextLong ( ) ; int k = in . nextInt ( ) ; int [ ] b = new int [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { b [ i ] = in . nextInt ( ) ; } Arrays . sort ( b ) ; int z = b [ b . length - 1 ] ; int [ ] a = new int [ z * z ] ; Arrays . fill ( a , Integer . MAX_VALUE ) ; a [ 0 ] = 0 ; for ( int i = 0 ; i < b . length ; i ++ ) { for ( int j = 0 ; j < a . length - b [ i ] ; j ++ ) { if ( a [ j ] != Integer . MAX_VALUE ) { a [ j + b [ i ] ] = Math . min ( a [ j + b [ i ] ] , a [ j ] + 1 ) ; } } } long ans = Long . MAX_VALUE ; for ( int i = 0 ; i < b . length ; i ++ ) { long u = ( l - z * z ) / b [ i ] + 1 ; int r = ( int ) ( l - u * b [ i ] ) ; if ( a [ r ] != Integer . MAX_VALUE ) { long v = u + a [ r ] ; if ( v < ans ) { ans = v ; } } } if ( ans == Long . MAX_VALUE ) { out . println ( " IMPOSSIBLE " ) ; } else { out . println ( ans ) ; } } in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new B ( ) . solve ( ) ; } }


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; int testCount = Integer . parseInt ( in . next ( ) ) ; for ( int i = 1 ; i <= testCount ; i ++ ) solver . solve ( i , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , InputReader in , PrintWriter out ) { char [ ] s = in . next ( ) . toCharArray ( ) ; int k = in . nextInt ( ) ; int n = s . length ; int ret = 0 ; for ( int i = 0 ; i + k <= n ; i ++ ) { if ( s [ i ] == ' - ' ) { ++ ret ; for ( int j = 0 ; j < k ; j ++ ) { s [ i + j ] = ( char ) ( ' + ' + ' - ' - s [ i + j ] ) ; } } } out . printf ( " Case ▁ # % d : ▁ " , testNumber ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] != ' + ' ) { out . println ( " IMPOSSIBLE " ) ; return ; } } out . println ( ret ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import sys NEW_LINE if __name__ == " _ _ main _ _ " : NEW_LINE INDENT f = sys . stdin NEW_LINE if len ( sys . argv ) >= 2 : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE if fn != ' - ' : NEW_LINE INDENT f = open ( fn ) NEW_LINE DEDENT DEDENT T = int ( f . readline ( ) ) NEW_LINE for _T in xrange ( T ) : NEW_LINE INDENT s , K = f . readline ( ) . split ( ) NEW_LINE K = int ( K ) NEW_LINE l = [ c == ' + ' for c in s ] NEW_LINE flips = 0 NEW_LINE for i in xrange ( len ( s ) - K + 1 ) : NEW_LINE INDENT if not l [ i ] : NEW_LINE INDENT flips += 1 NEW_LINE for j in xrange ( i , i + K ) : NEW_LINE INDENT l [ j ] = not l [ j ] NEW_LINE DEDENT DEDENT DEDENT if not all ( l ) : NEW_LINE INDENT ans = " IMPOSSIBLE " NEW_LINE DEDENT else : NEW_LINE INDENT ans = flips NEW_LINE DEDENT print " Case ▁ # % d : ▁ % s " % ( _T + 1 , ans ) NEW_LINE DEDENT DEDENT


def solve ( pancake_str , k ) : NEW_LINE INDENT pancakes = list ( pancake_str ) NEW_LINE flip_count = 0 NEW_LINE for i in range ( len ( pancakes ) ) : NEW_LINE INDENT if pancakes [ i ] == ' - ' : NEW_LINE INDENT flip_count += 1 NEW_LINE for j in range ( i , i + k ) : NEW_LINE INDENT if j >= len ( pancakes ) : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT pancakes [ j ] = ' + ' if pancakes [ j ] == ' - ' else ' - ' NEW_LINE DEDENT DEDENT DEDENT return str ( flip_count ) NEW_LINE DEDENT case_count = input ( ) NEW_LINE for i in range ( 1 , case_count + 1 ) : NEW_LINE INDENT s , k = raw_input ( ) . split ( ' ▁ ' ) NEW_LINE k = int ( k ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( i , solve ( s , k ) ) NEW_LINE DEDENT


import sys NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE def solve ( data , k ) : NEW_LINE INDENT l = len ( data ) NEW_LINE if l == k : NEW_LINE INDENT if data == [ " + " ] * k : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif data == [ " - " ] * k : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT if l < k : NEW_LINE INDENT if data == [ " + " ] * l : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT flips = 0 NEW_LINE if data [ 0 ] == ' - ' : NEW_LINE INDENT for i in range ( 0 , k ) : NEW_LINE INDENT if data [ i ] == " + " : NEW_LINE INDENT data [ i ] = " - " NEW_LINE DEDENT else : NEW_LINE INDENT data [ i ] = " + " NEW_LINE DEDENT DEDENT flips = 1 NEW_LINE DEDENT result = solve ( data [ 1 : ] , k ) NEW_LINE if result < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return result + flips NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT n , m = [ s for s in raw_input ( ) . split ( " ▁ " ) ] NEW_LINE data = list ( str ( n ) ) NEW_LINE k = int ( m ) NEW_LINE result = solve ( data , k ) NEW_LINE if result == - 1 : NEW_LINE INDENT result = " IMPOSSIBLE " NEW_LINE DEDENT print ( " Case ▁ # { } : ▁ { } " . format ( i , result ) ) NEW_LINE DEDENT


import sys NEW_LINE import numpy as np NEW_LINE if len ( sys . argv ) != 2 : NEW_LINE INDENT print " usage : ▁ . / a . py ▁ < input _ file _ name > " NEW_LINE exit ( ) NEW_LINE DEDENT input_file_name = sys . argv [ 1 ] NEW_LINE if input_file_name [ - 3 : ] == " . in " : NEW_LINE INDENT output_file_name = input_file_name [ : - 3 ] + " . out " NEW_LINE DEDENT else : NEW_LINE INDENT output_file_name = input_file_name + " . out " NEW_LINE DEDENT results = [ ] NEW_LINE with open ( input_file_name , ' r ' ) as f : NEW_LINE INDENT T = int ( f . readline ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT line = f . readline ( ) NEW_LINE S , K = line . split ( ' ▁ ' ) NEW_LINE S = list ( S ) NEW_LINE K = int ( K ) NEW_LINE ret = 0 NEW_LINE for j in xrange ( len ( S ) - K + 1 ) : NEW_LINE INDENT if S [ j ] == ' - ' : NEW_LINE INDENT for k in xrange ( K ) : NEW_LINE INDENT if S [ j + k ] == ' - ' : NEW_LINE INDENT S [ j + k ] = ' + ' NEW_LINE DEDENT else : NEW_LINE INDENT S [ j + k ] = ' - ' NEW_LINE DEDENT DEDENT ret += 1 NEW_LINE DEDENT DEDENT ret = str ( ret ) NEW_LINE for s in S : NEW_LINE INDENT if s == ' - ' : NEW_LINE INDENT ret = ' IMPOSSIBLE ' NEW_LINE break NEW_LINE DEDENT DEDENT results . append ( ret ) NEW_LINE DEDENT DEDENT with open ( output_file_name , ' w ' ) as f : NEW_LINE INDENT for i in range ( len ( results ) ) : NEW_LINE INDENT output_string = " Case ▁ # % d : ▁ % s \n " % ( i + 1 , results [ i ] ) NEW_LINE print output_string [ : - 1 ] NEW_LINE f . write ( output_string ) NEW_LINE DEDENT DEDENT


for cas in xrange ( 1 , 1 + input ( ) ) : NEW_LINE INDENT s , k = raw_input ( ) . strip ( ) . split ( ) NEW_LINE k = int ( k ) NEW_LINE s = [ v != ' + ' for v in s ] NEW_LINE f = [ 0 ] * ( len ( s ) + 1 ) NEW_LINE m = 0 NEW_LINE for i in xrange ( len ( s ) ) : NEW_LINE INDENT if i + k <= len ( s ) and ( s [ i ] ^ f [ i ] ) : NEW_LINE INDENT f [ i ] ^= 1 NEW_LINE f [ i + k ] ^= 1 NEW_LINE m += 1 NEW_LINE DEDENT s [ i ] ^= f [ i ] NEW_LINE f [ i + 1 ] ^= f [ i ] NEW_LINE DEDENT print " Case ▁ # % s : ▁ % s " % ( cas , ' IMPOSSIBLE ' if any ( s ) else m ) NEW_LINE DEDENT


import java . util . * ; class A { static int solve ( ) { int [ ] str = in . next ( ) . chars ( ) . map ( ( i ) -> i == ' + ' ? 0 : 1 ) . toArray ( ) ; int size = in . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < str . length - size + 1 ; ++ i ) { if ( str [ i ] != 0 ) { count ++ ; for ( int j = i ; j < i + size ; ++ j ) { str [ j ] = str [ j ] == 1 ? 0 : 1 ; } } } for ( int i = str . length - size + 1 ; i < str . length ; ++ i ) { if ( str [ i ] != 0 ) return - 1 ; } return count ; } static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; ++ t ) { int c = solve ( ) ; System . out . printf ( " Case ▁ # % d : ▁ % s % n " , t + 1 , c >= 0 ? Integer . toString ( c ) : " IMPOSSIBLE " ) ; } } }


package rayker . gcj2017 ; import java . io . PrintWriter ; import java . util . TreeSet ; import java . util . stream . Collectors ; public class Solver { public void solve ( InputReader in , PrintWriter out ) { int nTests = in . nextInt ( ) ; for ( int t = 1 ; t <= nTests ; t ++ ) { String v = in . next ( ) ; int k = in . nextInt ( ) ; print ( t , out , find ( v , k ) ) ; } } private long find ( String line , int k ) { Boolean [ ] b = line . chars ( ) . mapToObj ( c -> c == ' + ' ) . toArray ( Boolean [ ] :: new ) ; int count = 0 ; for ( int i = 0 ; i < b . length ; i ++ ) { if ( b [ i ] ) continue ; count ++ ; for ( int j = 0 ; j < k ; j ++ ) { if ( i + j >= b . length ) return - 1 ; b [ i + j ] = ! b [ i + j ] ; } } return count ; } private void print ( int t , PrintWriter out , long v ) { if ( v == - 1 ) { out . printf ( " Case ▁ # % d : ▁ IMPOSSIBLE % n " , t ) ; } else { out . printf ( " Case ▁ # % d : ▁ % d % n " , t , v ) ; } } }


package com . company ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Main { private static Scanner scanner = new Scanner ( System . in ) ; static private void reDirect ( ) { try { FileInputStream fileInputStream = new FileInputStream ( " A - large . in " ) ; scanner = new Scanner ( fileInputStream ) ; PrintStream ps = new PrintStream ( new FileOutputStream ( " a - out - large . txt " ) ) ; System . setOut ( ps ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } } public static void main ( String [ ] args ) { reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { int ans = run ( ) ; System . out . println ( " Case ▁ # " + cas + " : ▁ " + ( ans < 0 ? " IMPOSSIBLE " : ans ) ) ; } } static private int run ( ) { String s = scanner . next ( ) ; int k = scanner . nextInt ( ) ; char [ ] arr = s . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == ' - ' ) { if ( i + k > arr . length ) { return - 1 ; } count ++ ; for ( int j = i ; j < i + k ; j ++ ) { arr [ j ] = ( arr [ j ] == ' + ' ? ' - ' : ' + ' ) ; } } } return count ; } }


package qualifier ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . LinkedList ; import java . util . List ; import java . util . Scanner ; public class AOversizedPancakeFlipper { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ) { int tests = sc . nextInt ( ) ; outer : for ( int t = 1 ; t <= tests ; t ++ ) { char [ ] happyChars = sc . next ( ) . toCharArray ( ) ; int spatWidth = sc . nextInt ( ) ; boolean [ ] happy = new boolean [ happyChars . length ] ; for ( int x = 0 ; x < happy . length ; x ++ ) happy [ x ] = happyChars [ x ] == ' + ' ; List < Integer > flipPoints = new LinkedList < Integer > ( ) ; int flipCount = 0 ; boolean flipped = false ; for ( int x = 0 ; x <= happy . length - spatWidth ; x ++ ) { if ( ! flipPoints . isEmpty ( ) && flipPoints . get ( 0 ) == x ) { flipPoints . remove ( 0 ) ; flipped = ! flipped ; } boolean current = happy [ x ] != flipped ; if ( ! current ) { flipped = ! flipped ; flipCount ++ ; flipPoints . add ( x + spatWidth ) ; } } for ( int x = happy . length - spatWidth + 1 ; x < happy . length ; x ++ ) { if ( ! flipPoints . isEmpty ( ) && flipPoints . get ( 0 ) == x ) { flipPoints . remove ( 0 ) ; flipped = ! flipped ; } if ( happy [ x ] == flipped ) { System . out . printf ( " Case ▁ # % d : ▁ IMPOSSIBLE % n " , t ) ; continue outer ; } } System . out . printf ( " Case ▁ # % d : ▁ % d % n " , t , flipCount ) ; } } } }


import java . util . * ; public class A { static Scanner in ; public static void main ( String [ ] args ) { in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . println ( " Case ▁ # " + C + " : " + solve ( ) ) ; } } public static String solve ( ) { String out = " " ; int n = in . nextInt ( ) ; int [ ] count = new int [ n ] ; int remaining = 0 ; for ( int i = 0 ; i < n ; i ++ ) { count [ i ] = in . nextInt ( ) ; remaining += count [ i ] ; } while ( remaining > 0 ) { out += " ▁ " ; int maxIdx = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ i ] > 0 && ( maxIdx == - 1 || count [ i ] > count [ maxIdx ] ) ) { maxIdx = i ; } } out += ( char ) ( maxIdx + ' A ' ) ; count [ maxIdx ] -- ; remaining -- ; if ( remaining <= 0 ) break ; maxIdx = - 1 ; int gT0 = 0 ; boolean tie = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ i ] > 0 ) { gT0 ++ ; } if ( count [ i ] > 0 && ( maxIdx == - 1 || count [ i ] > count [ maxIdx ] ) ) { maxIdx = i ; } else if ( count [ i ] > 0 && gT0 == 2 && count [ i ] == count [ maxIdx ] ) { tie = true ; } } boolean skip = tie && gT0 == 2 ; if ( ! skip ) { out += ( char ) ( maxIdx + ' A ' ) ; count [ maxIdx ] -- ; remaining -- ; } } return out ; } }

from __future__ import print_function NEW_LINE import numpy NEW_LINE import string NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT print ( " Case ▁ # % d : " % i , end = ' ' ) NEW_LINE n = int ( raw_input ( ) ) NEW_LINE p = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE while True : NEW_LINE INDENT pp = [ x for x in range ( len ( p ) ) if p [ x ] != 0 ] NEW_LINE if len ( pp ) == 0 : NEW_LINE INDENT break NEW_LINE DEDENT elif len ( pp ) == 2 and p [ pp [ 0 ] ] == p [ pp [ 1 ] ] : NEW_LINE INDENT print ( ' ▁ ' , end = ' ' ) NEW_LINE print ( string . uppercase [ pp [ 0 ] ] , end = ' ' ) NEW_LINE print ( string . uppercase [ pp [ 1 ] ] , end = ' ' ) NEW_LINE p [ pp [ 0 ] ] -= 1 NEW_LINE p [ pp [ 1 ] ] -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT q = numpy . argmax ( p ) NEW_LINE print ( ' ▁ ' , end = ' ' ) NEW_LINE print ( string . uppercase [ q ] , end = ' ' ) NEW_LINE p [ q ] -= 1 NEW_LINE DEDENT DEDENT print ( ' ' ) NEW_LINE DEDENT


from sys import stdin NEW_LINE def each_case ( N , P ) : NEW_LINE INDENT max , max2 , argmax , argmax2 = - 1 , P [ 0 ] , 0 , 0 NEW_LINE for i , p in enumerate ( P ) : NEW_LINE INDENT if max < p : NEW_LINE INDENT max2 = max NEW_LINE max = p NEW_LINE argmax2 = argmax NEW_LINE argmax = i NEW_LINE DEDENT elif max2 < p : NEW_LINE INDENT max2 = p NEW_LINE argmax2 = i NEW_LINE DEDENT DEDENT max_party , max2_party = chr ( argmax + 65 ) , chr ( argmax2 + 65 ) NEW_LINE plan = [ ] NEW_LINE for i in xrange ( ( max - max2 ) / 2 ) : NEW_LINE INDENT plan . append ( max_party * 2 ) NEW_LINE DEDENT if ( max - max2 ) % 2 : NEW_LINE INDENT plan . append ( max_party ) NEW_LINE DEDENT for i , p in enumerate ( P ) : NEW_LINE INDENT if i != argmax and i != argmax2 : NEW_LINE INDENT plan . extend ( [ chr ( i + 65 ) ] * p ) NEW_LINE DEDENT DEDENT for i in xrange ( max2 ) : NEW_LINE INDENT plan . append ( max_party + max2_party ) NEW_LINE DEDENT return ' ▁ ' . join ( plan ) NEW_LINE DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( stdin . readline ( ) ) NEW_LINE P = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( t , each_case ( N , P ) ) NEW_LINE DEDENT


f = ' a - sample . in ' NEW_LINE f = ' A - small - attempt0 . in ' NEW_LINE f = ' A - large . in ' NEW_LINE inp = map ( str . strip , list ( open ( f ) ) [ 1 : ] ) NEW_LINE let = lambda n : chr ( ord ( ' A ' ) + n - 1 ) NEW_LINE def solve ( vals ) : NEW_LINE INDENT vals = zip ( map ( int , vals ) , range ( 1 , len ( vals ) + 1 ) ) NEW_LINE vals . sort ( reverse = True ) NEW_LINE evac = ( vals [ 0 ] [ 0 ] - vals [ 1 ] [ 0 ] ) * [ let ( vals [ 0 ] [ 1 ] ) ] NEW_LINE evac += [ let ( p ) for x , p in vals [ 2 : ] for i in range ( x ) ] NEW_LINE evac += [ let ( vals [ 0 ] [ 1 ] ) + let ( vals [ 1 ] [ 1 ] ) ] * vals [ 1 ] [ 0 ] NEW_LINE return ' ▁ ' . join ( evac ) NEW_LINE DEDENT t = 1 NEW_LINE while inp : NEW_LINE INDENT N = int ( inp . pop ( 0 ) ) NEW_LINE vals = tuple ( inp . pop ( 0 ) . split ( ) ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( t , solve ( vals ) ) NEW_LINE t += 1 NEW_LINE DEDENT


def executer_calcul ( entrees ) : NEW_LINE INDENT N = entrees [ 0 ] NEW_LINE parties = entrees [ 1 ] NEW_LINE Case = entrees [ 2 ] NEW_LINE result = ' ' NEW_LINE while ( sum ( parties ) > 0 ) : NEW_LINE INDENT evac1 = maximum ( parties ) NEW_LINE parties [ evac1 ] = parties [ evac1 ] - 1 NEW_LINE evac2 = maximum ( parties ) NEW_LINE if ( 2 * parties [ evac2 ] > sum ( parties ) ) : NEW_LINE INDENT parties [ evac2 ] = parties [ evac2 ] - 1 NEW_LINE result = result + ' ▁ ' + chr ( evac1 + 65 ) + chr ( evac2 + 65 ) NEW_LINE DEDENT else : NEW_LINE INDENT result = result + ' ▁ ' + chr ( evac1 + 65 ) NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT def maximum ( liste ) : NEW_LINE INDENT maximum = 0 NEW_LINE for i in range ( len ( liste ) ) : NEW_LINE INDENT if ( liste [ i ] > liste [ maximum ] ) : maximum = i NEW_LINE DEDENT return maximum NEW_LINE DEDENT multiprocessed = False NEW_LINE if ( multiprocessed ) : from multiprocessing import Pool NEW_LINE else : output = open ( ' Output . txt ' , ' w ' ) NEW_LINE if ( ( not multiprocessed ) or __name__ == ' _ _ main _ _ ' ) : NEW_LINE INDENT with open ( " Input . txt " , " r " ) as input : NEW_LINE INDENT lines = input . readlines ( ) NEW_LINE DEDENT T = int ( lines [ 0 ] ) NEW_LINE line = 1 NEW_LINE Case = 1 NEW_LINE calculs = [ ] NEW_LINE while ( line < len ( lines ) ) : NEW_LINE INDENT N = int ( lines [ line ] ) NEW_LINE line = line + 1 NEW_LINE parties = list ( map ( int , lines [ line ] . split ( ' ▁ ' ) ) ) NEW_LINE line = line + 1 NEW_LINE entrees = [ N , parties , Case ] NEW_LINE if ( not multiprocessed ) : output . write ( ' Case ▁ # ' + str ( Case ) + ' : ' + executer_calcul ( entrees ) + ' \n ' ) NEW_LINE else : calculs . append ( entrees ) NEW_LINE Case = Case + 1 NEW_LINE DEDENT if ( multiprocessed ) : NEW_LINE INDENT pool = Pool ( 3 ) NEW_LINE results = pool . map ( executer_calcul , calculs ) NEW_LINE output = open ( ' Output . txt ' , ' w ' ) NEW_LINE for case in range ( len ( results ) ) : NEW_LINE INDENT output . write ( ' Case ▁ # ' + str ( case + 1 ) + ' : ▁ ' + results [ case ] + ' \n ' ) NEW_LINE DEDENT DEDENT output . close ( ) NEW_LINE DEDENT


import sys NEW_LINE def letter ( x ) : NEW_LINE INDENT return chr ( ord ( ' A ' ) + x ) NEW_LINE DEDENT def solve_test ( inp ) : NEW_LINE INDENT n = int ( inp . readline ( ) ) NEW_LINE ans = [ ] NEW_LINE counts = [ int ( x ) for x in inp . readline ( ) . split ( ) ] NEW_LINE total = sum ( counts ) NEW_LINE if total % 2 == 1 : NEW_LINE INDENT winner = counts . index ( max ( counts ) ) NEW_LINE ans . append ( letter ( winner ) ) NEW_LINE counts [ winner ] -= 1 NEW_LINE DEDENT while sum ( counts ) > 0 : NEW_LINE INDENT winner1 = counts . index ( max ( counts ) ) NEW_LINE counts [ winner1 ] -= 1 NEW_LINE winner2 = counts . index ( max ( counts ) ) NEW_LINE counts [ winner2 ] -= 1 NEW_LINE ans . append ( letter ( winner1 ) + letter ( winner2 ) ) NEW_LINE DEDENT return ' ▁ ' . join ( ans ) NEW_LINE DEDENT def solve_dumb ( inp ) : NEW_LINE INDENT return '1' NEW_LINE DEDENT inp = open ( sys . argv [ 1 ] ) NEW_LINE inp_dumb = open ( sys . argv [ 1 ] ) NEW_LINE out = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . out ' , ' w ' ) NEW_LINE out_dumb = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . dumb . out ' , ' w ' ) NEW_LINE n_tests = int ( inp . readline ( ) ) NEW_LINE for i in range ( n_tests ) : NEW_LINE INDENT ans = solve_test ( inp ) NEW_LINE print ( " Case ▁ # % d : ▁ " % ( i + 1 ) + ans , file = out ) NEW_LINE ans_dumb = solve_dumb ( inp_dumb ) NEW_LINE print ( " Case ▁ # % d : ▁ " % ( i + 1 ) + ans_dumb , file = out_dumb ) NEW_LINE if ans != ans_dumb : NEW_LINE INDENT print ( ' Wrong ' , i + 1 , file = sys . stderr ) NEW_LINE DEDENT DEDENT out . close ( ) NEW_LINE


import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { new Main ( ) ; } public Main ( ) throws IOException { Scanner sc = new Scanner ( new File ( " A - large . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " A - large . out " ) ) ; int amountOfTasks = sc . nextInt ( ) ; for ( int task = 1 ; task <= amountOfTasks ; task ++ ) { int amount = sc . nextInt ( ) ; int [ ] counts = new int [ amount ] ; int sum = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { counts [ i ] = sc . nextInt ( ) ; sum += counts [ i ] ; } String sol = " " ; if ( sum % 2 == 1 ) { int max1 = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { if ( counts [ i ] > counts [ max1 ] ) { max1 = i ; } } counts [ max1 ] -- ; char first = ( char ) ( max1 + ' A ' ) ; sol += first ; sum -- ; } while ( sum > 0 ) { int max1 = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { if ( counts [ i ] > counts [ max1 ] ) { max1 = i ; } } counts [ max1 ] -- ; int max2 = 0 ; for ( int i = 0 ; i < amount ; i ++ ) { if ( counts [ i ] > counts [ max2 ] ) { max2 = i ; } } counts [ max2 ] -- ; char first = ( char ) ( max1 + ' A ' ) ; char second = ( char ) ( max2 + ' A ' ) ; if ( sol . length ( ) > 0 ) { sol += " ▁ " ; } sol += first ; sol += second ; sum -= 2 ; } String solution = " Case ▁ # " + task + " : ▁ " + sol ; System . out . println ( solution ) ; out . println ( solution ) ; } out . close ( ) ; sc . close ( ) ; } }


package com . mavtushenko . Gcj1C ; import java . io . * ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class TaskA { public static void main ( String [ ] args ) { String fileName = " A - large . in " ; try ( BufferedReader br = new BufferedReader ( new FileReader ( fileName ) ) ) { try ( BufferedWriter bw = new BufferedWriter ( new FileWriter ( fileName + " . out " ) ) ) { int tests = Integer . valueOf ( br . readLine ( ) ) ; for ( int test = 1 ; test <= tests ; ++ test ) { int n = new Scanner ( br . readLine ( ) ) . nextInt ( ) ; Scanner scanner = new Scanner ( br . readLine ( ) ) ; int s [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) s [ i ] = scanner . nextInt ( ) ; bw . write ( " Case ▁ # " + test + " : ▁ " ) ; while ( true ) { int max = 0 ; for ( int ss : s ) max = Math . max ( max , ss ) ; if ( max == 0 ) break ; ArrayList < Integer > pos = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( s [ i ] == max ) pos . add ( i ) ; } int ps = pos . size ( ) ; if ( pos . size ( ) % 2 == 1 ) { ps -- ; int cur = pos . get ( pos . size ( ) - 1 ) ; s [ cur ] -- ; bw . write ( " " + ( char ) ( ' A ' + cur ) + " ▁ " ) ; } for ( int i = 0 ; i < ps ; i += 2 ) { int c1 = pos . get ( i ) ; int c2 = pos . get ( i + 1 ) ; s [ c1 ] -- ; s [ c2 ] -- ; bw . write ( " " + ( char ) ( ' A ' + c1 ) + ( char ) ( ' A ' + c2 ) + " ▁ " ) ; } } bw . write ( " \n " ) ; } bw . close ( ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } }


package Round1 ; import java . io . * ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( " / Users / chao / Downloads / A - large . in " ) ) ; FileWriter out = new FileWriter ( " / Users / chao / Desktop / A - large . txt " ) ; String s = in . readLine ( ) ; int m = Integer . parseInt ( s ) ; int [ ] a = new int [ 26 ] ; for ( int cases = 1 ; cases <= m ; cases ++ ) { int n = Integer . parseInt ( in . readLine ( ) ) ; int cnt = n ; String [ ] ss = in . readLine ( ) . split ( " ▁ " ) ; for ( int i = 0 ; i < ss . length ; i ++ ) { a [ i ] = Integer . parseInt ( ss [ i ] ) ; } out . write ( " Case ▁ # " + cases + " : " ) ; while ( cnt > 2 ) { int k = findMaxIndex ( a , n ) ; out . write ( " ▁ " + ( char ) ( ' A ' + k ) ) ; if ( -- a [ k ] == 0 ) cnt -- ; } while ( cnt > 0 ) { int k = findMaxIndex ( a , n ) ; out . write ( " ▁ " + ( char ) ( ' A ' + k ) ) ; if ( -- a [ k ] == 0 ) cnt -- ; k = findMaxIndex ( a , n ) ; out . write ( ( char ) ( ' A ' + k ) ) ; if ( -- a [ k ] == 0 ) cnt -- ; } out . write ( " \n " ) ; } in . close ( ) ; out . flush ( ) ; out . close ( ) ; } private static int findMaxIndex ( int [ ] a , int n ) { int num = - 1 ; int k = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > num ) { num = a [ i ] ; k = i ; } } return k ; } }


import java . util . * ; import java . io . * ; public class A { static int N ; static int ans ; public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { N = input . nextInt ( ) ; int [ ] nums = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { nums [ i ] = input . nextInt ( ) ; sum += nums [ i ] ; } List < String > steps = new ArrayList < String > ( ) ; while ( sum > 0 ) { String s = " " ; s += add ( nums , false ) ; s += add ( nums , true ) ; steps . add ( s ) ; sum -= s . length ( ) ; } System . out . printf ( " Case ▁ # % d : " , n + 1 ) ; for ( String s : steps ) System . out . print ( " ▁ " + s ) ; System . out . println ( ) ; } } static String add ( int [ ] nums , boolean check ) { int most = 0 ; for ( int i = 0 ; i < nums . length ; i ++ ) if ( nums [ i ] > nums [ most ] ) most = i ; nums [ most ] -- ; int sum = 0 ; for ( int num : nums ) sum += num ; if ( check ) for ( int num : nums ) if ( num > sum / 2 ) { nums [ most ] ++ ; return " " ; } return ( char ) ( ' A ' + most ) + " " ; } }


package gcj ; import java . util . * ; import java . io . * ; public class Swinging { final static String PROBLEM_NAME = " swing " ; final static String WORK_DIR = " D : \\ Gcj\ \" + PROBLEM_NAME + " \ \" ; static void preprocess ( ) { } void solve ( Scanner sc , PrintWriter pw ) { int N = sc . nextInt ( ) ; int [ ] dist = new int [ N ] ; int [ ] len = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { dist [ i ] = sc . nextInt ( ) ; len [ i ] = sc . nextInt ( ) ; } int D = sc . nextInt ( ) ; int [ ] maxH = new int [ N ] ; Arrays . fill ( maxH , - 1 ) ; maxH [ 0 ] = dist [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( maxH [ i ] == - 1 ) continue ; if ( D - dist [ i ] <= maxH [ i ] ) { pw . println ( " YES " ) ; return ; } for ( int j = i + 1 ; j < N ; j ++ ) if ( dist [ j ] - dist [ i ] <= maxH [ i ] ) maxH [ j ] = Math . max ( maxH [ j ] , Math . min ( len [ j ] , dist [ j ] - dist [ i ] ) ) ; } pw . println ( " NO " ) ; } public static void main ( String [ ] args ) throws Exception { preprocess ( ) ; Scanner sc = new Scanner ( new FileReader ( WORK_DIR + " input . txt " ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( WORK_DIR + " output . txt " ) ) ; int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { System . out . println ( " Processing ▁ test ▁ case ▁ " + ( caseNum + 1 ) ) ; pw . print ( " Case ▁ # " + ( caseNum + 1 ) + " : ▁ " ) ; new Swinging ( ) . solve ( sc , pw ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } }

import heapq NEW_LINE for test_case in xrange ( 1 , int ( raw_input ( ) ) + 1 ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE D = [ 0 ] * ( N + 1 ) NEW_LINE L = [ 0 ] * ( N + 1 ) NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT D [ i ] , L [ i ] = map ( int , raw_input ( ) . split ( ) ) NEW_LINE DEDENT D [ N ] = int ( raw_input ( ) ) NEW_LINE earliest = [ - 1 ] * ( N + 1 ) NEW_LINE earliest [ 0 ] = 0 NEW_LINE heap = [ ] NEW_LINE heapq . heappush ( heap , ( D [ 0 ] , D [ 0 ] + min ( D [ 0 ] - earliest [ 0 ] , L [ 0 ] ) ) ) NEW_LINE for i in xrange ( 1 , N + 1 ) : NEW_LINE INDENT while heap and heap [ 0 ] [ 1 ] < D [ i ] : NEW_LINE INDENT heapq . heappop ( heap ) NEW_LINE DEDENT if heap : NEW_LINE INDENT earliest [ i ] = heap [ 0 ] [ 0 ] NEW_LINE heapq . heappush ( heap , ( D [ i ] , D [ i ] + min ( D [ i ] - earliest [ i ] , L [ i ] ) ) ) NEW_LINE DEDENT DEDENT print " Case ▁ # { 0 } : ▁ { 1 } " . format ( test_case , " YES " if earliest [ N ] != - 1 else " NO " ) NEW_LINE DEDENT


import sys NEW_LINE if __name__ == " _ _ main _ _ " : NEW_LINE INDENT f = sys . stdin NEW_LINE if len ( sys . argv ) >= 2 : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE if fn != ' - ' : NEW_LINE INDENT f = open ( fn ) NEW_LINE DEDENT DEDENT t = int ( f . readline ( ) ) NEW_LINE for _t in xrange ( t ) : NEW_LINE INDENT n = int ( f . readline ( ) ) NEW_LINE dists = [ ] NEW_LINE lengths = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT d , l = map ( int , f . readline ( ) . split ( ) ) NEW_LINE dists . append ( d ) NEW_LINE lengths . append ( l ) NEW_LINE DEDENT D = int ( f . readline ( ) ) NEW_LINE dists . append ( D ) NEW_LINE lengths . append ( 0 ) NEW_LINE n += 1 NEW_LINE max_swing = [ - 1 ] * n NEW_LINE assert lengths [ 0 ] >= dists [ 0 ] NEW_LINE max_swing [ 0 ] = dists [ 0 ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT for j in xrange ( i + 1 , n ) : NEW_LINE INDENT if dists [ j ] - dists [ i ] > max_swing [ i ] : NEW_LINE INDENT break NEW_LINE DEDENT swing = min ( lengths [ j ] , dists [ j ] - dists [ i ] ) NEW_LINE max_swing [ j ] = max ( max_swing [ j ] , swing ) NEW_LINE DEDENT DEDENT print " Case ▁ # % d : ▁ % s " % ( _t + 1 , " NO " if max_swing [ - 1 ] == - 1 else " YES " ) NEW_LINE DEDENT DEDENT


import sys NEW_LINE def get_ints ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield int ( word ) NEW_LINE DEDENT DEDENT return NEW_LINE DEDENT ints = get_ints ( ) NEW_LINE def get_floats ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield float ( word ) NEW_LINE DEDENT DEDENT return NEW_LINE DEDENT floats = get_floats ( ) NEW_LINE def up ( a ) : NEW_LINE INDENT i = 1 NEW_LINE while i < a : NEW_LINE INDENT i *= 2 NEW_LINE DEDENT return 2 * i NEW_LINE DEDENT T = next ( ints ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT def solve ( ) : NEW_LINE INDENT N = next ( ints ) NEW_LINE D = ( N + 1 ) * [ 0 ] NEW_LINE L = ( N + 1 ) * [ 0 ] NEW_LINE K = ( N + 1 ) * [ 0 ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT D [ i ] = next ( ints ) NEW_LINE L [ i ] = next ( ints ) NEW_LINE DEDENT D [ N ] = next ( ints ) NEW_LINE K [ 0 ] = D [ 0 ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT j = i + 1 NEW_LINE while j <= N and D [ j ] - D [ i ] <= K [ i ] : NEW_LINE INDENT if j == N : return True NEW_LINE K [ j ] = max ( K [ j ] , min ( D [ j ] - D [ i ] , L [ j ] ) ) NEW_LINE j += 1 NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if solve ( ) : NEW_LINE INDENT print ( " Case ▁ # " , t + 1 , " : ▁ YES " , sep = ' ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Case ▁ # " , t + 1 , " : ▁ NO " , sep = ' ' ) NEW_LINE DEDENT DEDENT


rl = lambda : map ( int , raw_input ( ) . split ( ) ) NEW_LINE def solve ( ) : NEW_LINE INDENT n = input ( ) NEW_LINE a = [ rl ( ) for _ in xrange ( n ) ] NEW_LINE d , l = zip ( * a ) NEW_LINE D = input ( ) NEW_LINE s = [ 100000000 ] * n NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT r = D - d [ i ] NEW_LINE if r > l [ i ] : continue NEW_LINE s [ i ] = r NEW_LINE DEDENT for i in xrange ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT for j in xrange ( i + 1 , n ) : NEW_LINE INDENT if s [ j ] > l [ j ] : continue NEW_LINE dd = d [ j ] - d [ i ] NEW_LINE if dd > l [ i ] : break NEW_LINE if dd < s [ j ] : continue NEW_LINE s [ i ] = min ( s [ i ] , dd ) NEW_LINE DEDENT DEDENT return " YES " if s [ 0 ] <= d [ 0 ] else " NO " NEW_LINE DEDENT t = input ( ) NEW_LINE for i in xrange ( t ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( i + 1 , solve ( ) ) NEW_LINE DEDENT


import sys NEW_LINE import logging NEW_LINE if len ( sys . argv ) > 1 : NEW_LINE INDENT sampledata = False NEW_LINE infname = sys . argv [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT sampledata = True NEW_LINE scriptname = sys . argv [ 0 ] NEW_LINE problemletter = scriptname [ : scriptname . index ( ' . ' ) ] NEW_LINE infname = problemletter + ' - example . in ' NEW_LINE DEDENT outfname = infname [ : infname . index ( ' . ' ) ] + ' . out ' NEW_LINE with open ( infname ) as f : NEW_LINE INDENT text = f . read ( ) NEW_LINE DEDENT lines = text . splitlines ( ) NEW_LINE linesiter = iter ( lines ) NEW_LINE nextline = linesiter . next NEW_LINE ofile = open ( outfname , ' w ' ) NEW_LINE sys . stdout = ofile NEW_LINE T = int ( nextline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( nextline ( ) ) NEW_LINE vs = [ map ( int , nextline ( ) . split ( ) ) + [ 0 ] for _ in xrange ( N ) ] NEW_LINE dst = int ( nextline ( ) ) NEW_LINE reach = 0 NEW_LINE vs [ 0 ] [ 2 ] = vs [ 0 ] [ 0 ] NEW_LINE while vs : NEW_LINE INDENT v = vs . pop ( 0 ) NEW_LINE l = min ( v [ 1 ] , v [ 2 ] ) NEW_LINE reach = max ( reach , v [ 0 ] + l ) NEW_LINE for ov in vs : NEW_LINE INDENT if ov [ 0 ] <= v [ 0 ] + l : NEW_LINE INDENT ov [ 2 ] = max ( ov [ 2 ] , ov [ 0 ] - v [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print ' Case ▁ # % s : ' % t , ' YES ' if reach >= dst else ' NO ' NEW_LINE DEDENT sys . stdout = sys . __stdout__ NEW_LINE ofile . close ( ) NEW_LINE if sampledata : NEW_LINE INDENT base = problemletter + ' - example . ' NEW_LINE outfile = base + ' out ' NEW_LINE rightfile = base + ' right ' NEW_LINE out = open ( outfile ) . read ( ) NEW_LINE right = open ( rightfile ) . read ( ) NEW_LINE if out == right : NEW_LINE INDENT print ' Congrats , ▁ your ▁ output ▁ matches ▁ sample ▁ output ' NEW_LINE DEDENT else : NEW_LINE INDENT print ' OUTPUT ▁ MISMATCH ' NEW_LINE import os NEW_LINE os . system ( ' diff ▁ % s ▁ % s ' % ( outfile , rightfile ) ) NEW_LINE DEDENT DEDENT


import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( A . class . getSimpleName ( ) + " . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( A . class . getSimpleName ( ) + " . out " ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = " Case ▁ # " + ( i + 1 ) + " : ▁ " + new A ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; int [ ] d = new int [ n + 1 ] ; int [ ] l = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = in . nextInt ( ) ; l [ i ] = in . nextInt ( ) ; } d [ n ] = in . nextInt ( ) ; int [ ] z = new int [ n + 1 ] ; z [ 0 ] = d [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { z [ i ] = Math . min ( z [ i ] , l [ i ] ) ; for ( int j = i + 1 ; j <= n ; j ++ ) { if ( d [ j ] <= d [ i ] + z [ i ] ) { z [ j ] = Math . max ( z [ j ] , d [ j ] - d [ i ] ) ; } } } return z [ n ] > 0 ? " YES " : " NO " ; } }


import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class A { Scanner in ; PrintWriter out ; void doit ( int tnum ) { int n = in . nextInt ( ) ; long [ ] d = new long [ n ] ; long [ ] l = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { d [ i ] = in . nextLong ( ) ; l [ i ] = in . nextLong ( ) ; } long D = in . nextLong ( ) ; long [ ] ans = new long [ n ] ; ans [ 0 ] = d [ 0 ] ; boolean ok = false ; for ( int i = 1 ; i < n ; ++ i ) ans [ i ] = - 1 ; for ( int i = 0 ; i < n ; ++ i ) { if ( D - d [ i ] <= ans [ i ] ) ok = true ; for ( int j = i + 1 ; j < n ; ++ j ) { if ( ( d [ j ] - d [ i ] ) <= ans [ i ] ) { long attempt = Math . min ( l [ j ] , d [ j ] - d [ i ] ) ; if ( ans [ j ] == - 1 ) ans [ j ] = attempt ; if ( ans [ j ] < attempt ) ans [ j ] = attempt ; } } } out . println ( " Case ▁ # " + tnum + " : ▁ " + ( ok ? " YES " : " NO " ) ) ; System . err . println ( " Case ▁ # " + tnum + " : ▁ " + ( ok ? " YES " : " NO " ) ) ; } public void doit ( ) throws IOException { out = new PrintWriter ( new FileOutputStream ( " output . txt " ) ) ; in = new Scanner ( new FileInputStream ( " A - large . in " ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; ++ i ) { doit ( i + 1 ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new A ( ) . doit ( ) ; } }


import java . util . Arrays ; import java . util . Scanner ; public class A { static int n ; static long [ ] D ; static long [ ] L ; static int [ ] P ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { n = in . nextInt ( ) ; D = new long [ n + 2 ] ; L = new long [ n + 2 ] ; P = new int [ n + 2 ] ; D [ 0 ] = 0 ; L [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { D [ i + 1 ] = in . nextLong ( ) ; L [ i + 1 ] = in . nextLong ( ) ; } D [ n + 1 ] = in . nextLong ( ) ; L [ n + 1 ] = 0 ; for ( int i = 0 ; i < n + 2 ; i ++ ) P [ i ] = n + 10 ; P [ 1 ] = 0 ; for ( int c = 1 ; c < n + 2 ; c ++ ) { if ( P [ c ] == n + 10 ) continue ; long my_len = Math . min ( L [ c ] , D [ c ] - D [ P [ c ] ] ) ; for ( int nxt = c + 1 ; nxt < n + 2 && D [ nxt ] - D [ c ] <= my_len ; nxt ++ ) { P [ nxt ] = Math . min ( P [ nxt ] , c ) ; } } System . out . printf ( " Case ▁ # % d : ▁ % s \n " , cas , P [ n + 1 ] == n + 10 ? " NO " : " YES " ) ; } } }


import java . util . Arrays ; import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; static class Solver { int N ; int [ ] ds ; int [ ] ls ; int D ; boolean solve ( ) { N = sc . nextInt ( ) ; ds = new int [ N ] ; ls = new int [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { ds [ i ] = sc . nextInt ( ) ; ls [ i ] = sc . nextInt ( ) ; } D = sc . nextInt ( ) ; int [ ] reach = new int [ N ] ; Arrays . fill ( reach , - 1 ) ; if ( ds [ 0 ] > ls [ 0 ] ) return false ; reach [ 0 ] = ds [ 0 ] ; for ( int i = 0 ; i < N ; ++ i ) { if ( reach [ i ] < 0 ) continue ; if ( reach [ i ] >= D - ds [ i ] ) return true ; for ( int j = i + 1 ; j < N ; ++ j ) { if ( reach [ j ] >= 0 ) continue ; if ( ds [ j ] > ds [ i ] + reach [ i ] ) break ; reach [ j ] = Math . min ( ds [ j ] - ds [ i ] , ls [ j ] ) ; } } return false ; } } public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( " Case ▁ # " + i + " : ▁ " ) ; Solver solver = new Solver ( ) ; System . out . println ( solver . solve ( ) ? " YES " : " NO " ) ; } } }


package round1 ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Kattio extends PrintWriter { public Kattio ( InputStream i ) { super ( new BufferedOutputStream ( System . out ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public Kattio ( InputStream i , OutputStream o ) { super ( new BufferedOutputStream ( o ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public boolean hasMoreTokens ( ) { return peekToken ( ) != null ; } public int getInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public double getDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } public long getLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } public String getWord ( ) { return nextToken ( ) ; } private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken ( ) { if ( token == null ) try { while ( st == null || ! st . hasMoreTokens ( ) ) { line = r . readLine ( ) ; if ( line == null ) return null ; st = new StringTokenizer ( line ) ; } token = st . nextToken ( ) ; } catch ( IOException e ) { } return token ; } private String nextToken ( ) { String ans = peekToken ( ) ; token = null ; return ans ; } }

import sys NEW_LINE from itertools import * NEW_LINE def allThe ( S ) : NEW_LINE INDENT yield set ( ) , set ( ) , S NEW_LINE for s in S : NEW_LINE INDENT SS = S - set ( [ s ] ) NEW_LINE for A , B , rem in allThe ( SS ) : NEW_LINE INDENT yield A | set ( [ s ] ) , B , rem NEW_LINE yield A , B | set ( [ s ] ) , rem NEW_LINE DEDENT DEDENT DEDENT def formatted ( A , B ) : NEW_LINE INDENT return ' \n ' + ' ▁ ' . join ( map ( str , A ) ) + ' \n ' + ' ▁ ' . join ( map ( str , B ) ) NEW_LINE DEDENT def solve ( S ) : NEW_LINE INDENT allSums = { } NEW_LINE for i in range ( 1 , len ( S ) ) : NEW_LINE INDENT for SS in combinations ( S , i ) : NEW_LINE INDENT ss = sum ( SS ) NEW_LINE if ss in allSums : NEW_LINE INDENT return formatted ( list ( SS ) , allSums [ ss ] ) NEW_LINE DEDENT allSums [ ss ] = list ( SS ) NEW_LINE DEDENT DEDENT return ' \n Impossible ' NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT s = set ( int ( s ) for s in raw_input ( ) . split ( ' ▁ ' ) [ 1 : ] ) NEW_LINE print " Case ▁ # % i : ▁ % s " % ( i + 1 , solve ( s ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT


class Solver ( object ) : NEW_LINE INDENT @ classmethod NEW_LINE def setup ( cls , infile ) : NEW_LINE INDENT cls . data = { } NEW_LINE DEDENT def __init__ ( self , infile , tc ) : NEW_LINE INDENT self . tc = tc NEW_LINE self . I = I = map ( int , infile . next ( ) . split ( ) ) NEW_LINE DEDENT def solve ( self ) : NEW_LINE INDENT import itertools as it NEW_LINE S = self . I [ 1 : ] NEW_LINE seen = { } NEW_LINE for n in xrange ( 1 , 4 ) : NEW_LINE INDENT for s in it . combinations ( S , n ) : NEW_LINE INDENT ss = sum ( s ) NEW_LINE if ss in seen : NEW_LINE INDENT return ' Case ▁ # % s : \n % s \n % s \n ' % ( self . tc , ' ▁ ' . join ( ' % d ' % i for i in s ) , ' ▁ ' . join ( ' % d ' % i for i in seen [ ss ] ) , ) NEW_LINE DEDENT seen [ ss ] = s NEW_LINE DEDENT DEDENT return ' Case ▁ # % s : ▁ Impossible \n ' % ( self . tc , ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE T = int ( sys . stdin . next ( ) ) NEW_LINE Solver . setup ( sys . stdin ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT sys . stdout . write ( Solver ( sys . stdin , t ) . solve ( ) ) NEW_LINE DEDENT DEDENT


from itertools import combinations NEW_LINE from random import randint NEW_LINE from collections import defaultdict NEW_LINE from time import time NEW_LINE def solve ( numbers ) : NEW_LINE INDENT nnum = len ( numbers ) NEW_LINE sums = defaultdict ( list ) NEW_LINE t0 = time ( ) NEW_LINE for i in range ( 2 , nnum ) : NEW_LINE INDENT for subset in combinations ( numbers , i ) : NEW_LINE INDENT if time ( ) - t0 > 30 : return None NEW_LINE s = set ( subset ) NEW_LINE s_sum = sum ( s ) NEW_LINE for other in sums [ s_sum ] : NEW_LINE INDENT if len ( s & other ) == 0 : NEW_LINE INDENT return s , other NEW_LINE DEDENT DEDENT sums [ s_sum ] . append ( s ) NEW_LINE DEDENT DEDENT return None NEW_LINE DEDENT def test ( ) : NEW_LINE INDENT nums = set ( ) NEW_LINE while len ( nums ) < 500 : NEW_LINE INDENT draw = 500 - len ( nums ) NEW_LINE [ nums . add ( randint ( 1 , 10 ** 12 ) ) for i in range ( draw ) ] NEW_LINE DEDENT result = solve ( nums ) NEW_LINE print result NEW_LINE print sum ( result [ 0 ] ) , sum ( result [ 1 ] ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT import sys NEW_LINE data = file ( sys . argv [ 1 ] + ' . in ' ) . readlines ( ) NEW_LINE with open ( sys . argv [ 1 ] + ' . out ' , ' w ' ) as out : NEW_LINE INDENT for i , line in enumerate ( data [ 1 : ] ) : NEW_LINE INDENT nums = map ( int , line . strip ( ) . split ( ) ) NEW_LINE answer = solve ( nums [ 1 : ] ) NEW_LINE if answer is not None : NEW_LINE INDENT a1 = ' ▁ ' . join ( map ( str , answer [ 0 ] ) ) NEW_LINE a2 = ' ▁ ' . join ( map ( str , answer [ 1 ] ) ) NEW_LINE response = " Case ▁ # % i : \n % s \n % s \n " % ( i + 1 , a1 , a2 ) NEW_LINE DEDENT else : NEW_LINE INDENT response = " Case ▁ # % i : \n Impossible \n " % ( i + 1 ) NEW_LINE DEDENT print response NEW_LINE out . write ( response ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE NEW_LINE DEDENT


import sys , math , time , itertools NEW_LINE filename = " C " NEW_LINE inputFilename = filename + " - large . in " NEW_LINE outputFilename = filename + " . txt " NEW_LINE inputFile = open ( inputFilename , " r " ) NEW_LINE outputFile = open ( outputFilename , " w " ) NEW_LINE startTime = time . time ( ) NEW_LINE testcases = int ( inputFile . readline ( ) ) NEW_LINE for testcase in range ( testcases ) : NEW_LINE INDENT outputStringHeader = " Case ▁ # " + str ( testcase + 1 ) + " : \n " NEW_LINE outputFile . write ( outputStringHeader ) NEW_LINE print " Case ▁ # " , str ( testcase + 1 ) + " : ▁ " NEW_LINE inputList = map ( int , inputFile . readline ( ) . split ( ) ) NEW_LINE inputList = inputList [ 1 : ] NEW_LINE sums = { } NEW_LINE solutionKey = None NEW_LINE for i in range ( 1 , 151 ) : NEW_LINE INDENT subsets = list ( itertools . combinations ( inputList , i ) ) NEW_LINE for subset in subsets : NEW_LINE INDENT sumOfSet = sum ( subset ) NEW_LINE if sumOfSet in sums : NEW_LINE INDENT sums [ sumOfSet ] . append ( subset ) NEW_LINE solutionKey = sumOfSet NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT sums [ sumOfSet ] = [ subset ] NEW_LINE DEDENT DEDENT if solutionKey : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if solutionKey : NEW_LINE INDENT for subset in sums [ solutionKey ] : NEW_LINE INDENT for value in subset : NEW_LINE INDENT outputFile . write ( " % d ▁ " % value ) NEW_LINE DEDENT outputFile . write ( " \n " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT outputFile . write ( " Impossible \n " ) NEW_LINE DEDENT DEDENT outputFile . close ( ) NEW_LINE inputFile . close ( ) NEW_LINE print time . time ( ) - startTime NEW_LINE


def readline_ints ( ) : NEW_LINE INDENT return [ int ( num ) for num in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT import itertools NEW_LINE def ordered_subsets_sums ( S ) : NEW_LINE INDENT lim = sum ( S ) // 2 NEW_LINE for i in range ( 1 , len ( S ) ) : NEW_LINE INDENT for subset in itertools . combinations ( S , i ) : NEW_LINE INDENT sub_sum = sum ( subset ) NEW_LINE if sub_sum > lim : NEW_LINE INDENT break NEW_LINE DEDENT yield subset , sub_sum NEW_LINE DEDENT DEDENT DEDENT def find_collision ( S ) : NEW_LINE INDENT sums = { } NEW_LINE for sub , sub_sum in ordered_subsets_sums ( S ) : NEW_LINE INDENT if sub_sum in sums : NEW_LINE INDENT return sums [ sub_sum ] , sub NEW_LINE DEDENT sums [ sub_sum ] = sub NEW_LINE DEDENT DEDENT fname = " C - large " NEW_LINE with open ( fname + " . in " , " r " ) as fin , open ( fname + " . out " , " w " ) as fout : NEW_LINE INDENT numcases = readline_ints ( ) [ 0 ] NEW_LINE print ( numcases , " cases " ) NEW_LINE for caseno in range ( 1 , numcases + 1 ) : NEW_LINE INDENT N , * S = readline_ints ( ) NEW_LINE S . sort ( ) NEW_LINE coll = find_collision ( S ) NEW_LINE if coll is None : NEW_LINE INDENT result = " Impossible " NEW_LINE DEDENT else : NEW_LINE INDENT s1 , s2 = coll NEW_LINE result = " ▁ " . join ( str ( n ) for n in sorted ( s1 ) ) + " \n " + " ▁ " . join ( str ( n ) for n in sorted ( s2 ) ) NEW_LINE DEDENT outstr = " Case ▁ # % d : \n % s " % ( caseno , result ) NEW_LINE fout . write ( outstr + " \n " ) NEW_LINE print ( outstr ) NEW_LINE DEDENT DEDENT


import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . HashMap ; import java . util . Map ; import java . util . Random ; import java . util . Scanner ; public class EqualSums2 { public static void main ( final String ... args ) throws IOException { final String fname = " C - large " ; final Scanner sc = new Scanner ( new File ( fname + " . in " ) ) ; final PrintWriter pw = new PrintWriter ( fname + " . out " ) ; final int t = sc . nextInt ( ) ; for ( int i = 1 ; i <= t ; ++ i ) { System . out . println ( i ) ; final int n = sc . nextInt ( ) ; final long [ ] a = new long [ n ] ; for ( int j = 0 ; j < n ; ++ j ) { a [ j ] = sc . nextLong ( ) ; } final Random rnd = new Random ( ) ; final Map < Long , Long > m = new HashMap < Long , Long > ( ) ; long s1 = - 1 ; long s2 = - 1 ; while ( true ) { long j = rnd . nextLong ( ) ; if ( j < 0 ) { continue ; } long x = j ; int k = 0 ; long s = 0 ; while ( x > 0 ) { if ( ( x & 1 ) != 0 ) { s += a [ k ] ; } x >>= 1 ; ++ k ; } final Long b = m . get ( s ) ; if ( b == null ) { m . put ( s , j ) ; } else if ( b != j ) { s1 = b ; s2 = j ; break ; } } pw . println ( " Case ▁ # " + i + " : " ) ; int k = 0 ; while ( s1 > 0 ) { if ( ( s1 & 1 ) != 0 ) { pw . print ( a [ k ] + " ▁ " ) ; } s1 >>= 1 ; ++ k ; } pw . println ( ) ; k = 0 ; while ( s2 > 0 ) { if ( ( s2 & 1 ) != 0 ) { pw . print ( a [ k ] + " ▁ " ) ; } s2 >>= 1 ; ++ k ; } pw . println ( ) ; } pw . close ( ) ; } }


import java . io . * ; import java . util . * ; public class C implements Runnable { private final int MAX_VALUE = 100000 * 20 + 10 ; private String IFILE = " C - small - attempt0 . in " ; private Scanner in ; private PrintWriter out ; public void Run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( " output . txt " ) ; int ntest = in . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { out . println ( " Case ▁ # " + test + " : " ) ; int n = in . nextInt ( ) ; int [ ] mas = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) mas [ i ] = in . nextInt ( ) ; Arrays . sort ( mas ) ; int [ ] f = new int [ MAX_VALUE ] ; Arrays . fill ( f , - 1 ) ; f [ 0 ] = 0 ; boolean ok = false ; for ( int i = 0 ; i < n ; i ++ ) { for ( int d = MAX_VALUE - 1 ; d >= 0 ; d -- ) { if ( f [ d ] == - 1 ) continue ; int dd = d + mas [ i ] ; if ( f [ dd ] != - 1 ) { ok = true ; int z = dd ; while ( z != 0 ) { if ( z != dd ) out . print ( " ▁ " ) ; out . print ( mas [ f [ z ] ] ) ; z -= mas [ f [ z ] ] ; } out . println ( ) ; out . print ( mas [ i ] ) ; z = d ; while ( z != 0 ) { out . print ( " ▁ " + mas [ f [ z ] ] ) ; z -= mas [ f [ z ] ] ; } out . println ( ) ; break ; } else f [ dd ] = i ; } if ( ok ) break ; } if ( ! ok ) out . println ( " Impossible " ) ; } in . close ( ) ; out . close ( ) ; } public void run ( ) { try { Run ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) throws IOException { new C ( ) . Run ( ) ; } }


import java . util . * ; import java . io . * ; public class B { static int N ; static double ans ; public static void main ( String ... orange ) throws Exception { Scanner input = new Scanner ( System . in ) ; int numCases = input . nextInt ( ) ; for ( int n = 0 ; n < numCases ; n ++ ) { N = input . nextInt ( ) ; int K = input . nextInt ( ) ; double [ ] ps = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) ps [ i ] = input . nextDouble ( ) ; ans = 0 ; solve ( new ArrayList < Double > ( ) , ps , K , 0 ) ; System . out . printf ( " Case ▁ # % d : ▁ " , n + 1 ) ; System . out . println ( ans ) ; } } static void solve ( List < Double > keep , double [ ] ps , int K , int index ) { if ( index == ps . length ) { if ( keep . size ( ) == K ) check ( keep , K ) ; return ; } solve ( keep , ps , K , index + 1 ) ; keep . add ( ps [ index ] ) ; solve ( keep , ps , K , index + 1 ) ; keep . remove ( keep . size ( ) - 1 ) ; } static void check ( List < Double > keep , int K ) { double [ ] [ ] table = new double [ K + 1 ] [ K + 1 ] ; table [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= K ; i ++ ) for ( int yes = 0 ; yes <= i ; yes ++ ) { table [ i ] [ yes ] = table [ i - 1 ] [ yes ] * ( 1 - keep . get ( i - 1 ) ) ; if ( yes > 0 ) table [ i ] [ yes ] += table [ i - 1 ] [ yes - 1 ] * keep . get ( i - 1 ) ; } if ( table [ K ] [ K / 2 ] > ans ) ans = table [ K ] [ K / 2 ] ; } }

T = input ( ) NEW_LINE from itertools import combinations NEW_LINE def pp ( a ) : NEW_LINE INDENT r = 1 NEW_LINE for x in a : NEW_LINE INDENT r *= x NEW_LINE DEDENT return r NEW_LINE DEDENT def pfor ( c ) : NEW_LINE INDENT K = len ( c ) NEW_LINE dp = [ [ 0 for i in range ( K / 2 + 1 ) ] for j in range ( K + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE cp = 0 NEW_LINE for i in range ( K ) : NEW_LINE INDENT for y in range ( 0 , K / 2 + 1 ) : NEW_LINE INDENT dp [ i + 1 ] [ y ] = dp [ i ] [ y - 1 ] * c [ i ] + dp [ i ] [ y ] * ( 1 - c [ i ] ) NEW_LINE DEDENT DEDENT return dp [ K ] [ K / 2 ] NEW_LINE DEDENT def slidebw ( P , K ) : NEW_LINE INDENT for i in range ( K ) : NEW_LINE INDENT yield P [ : i ] + P [ - ( K - i ) : ] , i NEW_LINE DEDENT yield P [ : K ] , K NEW_LINE DEDENT def solve ( N , K , P ) : NEW_LINE INDENT bp , bm , bj = - 1 , None , None NEW_LINE for c , j in slidebw ( sorted ( P ) , K ) : NEW_LINE INDENT cp = pfor ( c ) NEW_LINE if cp > bp : NEW_LINE INDENT bp , bm , bj = cp , c , j NEW_LINE DEDENT DEDENT return ' { : . 9f } ' . format ( bp ) NEW_LINE DEDENT for i in range ( 1 , T + 1 ) : NEW_LINE INDENT N , K = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE P = map ( float , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( i , solve ( N , K , P ) ) NEW_LINE DEDENT


import sys NEW_LINE import numpy as np NEW_LINE in_file = open ( ' b - large . in ' , ' r ' ) NEW_LINE out_file = open ( ' b . out ' , ' w ' ) NEW_LINE sys . stdin = in_file NEW_LINE sys . stdout = out_file NEW_LINE def calc ( a ) : NEW_LINE INDENT n = len ( a ) NEW_LINE f = np . zeros ( shape = ( n + 1 , n + 1 ) ) NEW_LINE f [ 0 ] [ 0 ] = 1 NEW_LINE for i in xrange ( 1 , n + 1 ) : NEW_LINE INDENT for j in xrange ( n + 1 ) : NEW_LINE INDENT f [ i ] [ j ] += f [ i - 1 ] [ j ] * a [ i - 1 ] NEW_LINE if j > 0 : NEW_LINE INDENT f [ i ] [ j ] += f [ i - 1 ] [ j - 1 ] * ( 1 - a [ i - 1 ] ) NEW_LINE DEDENT DEDENT DEDENT return f [ n ] [ n / 2 ] NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT n , m = map ( int , raw_input ( ) . split ( ) ) NEW_LINE a = map ( float , raw_input ( ) . split ( ) ) NEW_LINE a . sort ( ) NEW_LINE ans = 0 NEW_LINE for i in xrange ( m + 1 ) : NEW_LINE INDENT b = a [ : m - i ] + a [ n - i : ] NEW_LINE assert len ( b ) == m NEW_LINE ans = max ( ans , calc ( b ) ) NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % .10f ' % ( t + 1 , ans ) NEW_LINE DEDENT in_file . close ( ) NEW_LINE out_file . close ( ) NEW_LINE


def m ( p ) : NEW_LINE INDENT return lambda x : x * p NEW_LINE DEDENT def aa ( u , v ) : NEW_LINE INDENT for x , y in zip ( u , v ) : NEW_LINE INDENT yield x + y NEW_LINE DEDENT DEDENT def get_p ( a ) : NEW_LINE INDENT u = [ 1 ] NEW_LINE for x in a : NEW_LINE INDENT u = list ( aa ( [ 0 , 0 ] + list ( map ( m ( x ) , u ) ) , list ( map ( m ( 1 - x ) , u ) ) + [ 0 , 0 ] ) ) NEW_LINE DEDENT return u [ len ( u ) >> 1 ] NEW_LINE DEDENT for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE p = sorted ( list ( map ( float , input ( ) . split ( ) ) ) ) NEW_LINE r = 0 NEW_LINE for j in range ( k + 1 ) : NEW_LINE INDENT v = p [ : j ] + p [ : : - 1 ] [ : k - j ] NEW_LINE assert ( len ( v ) == k ) NEW_LINE r = max ( r , get_p ( v ) ) NEW_LINE DEDENT print ( " Case ▁ # % d : ▁ % .12f " % ( i + 1 , r ) ) NEW_LINE DEDENT


from multiprocessing import Pool NEW_LINE from pprint import pprint NEW_LINE import sys NEW_LINE def calcprob ( p ) : NEW_LINE INDENT prob = { } NEW_LINE k = len ( p ) NEW_LINE assert k % 2 == 0 NEW_LINE for j in range ( k // 2 + 1 ) : NEW_LINE INDENT prob [ ( 0 , j ) ] = 0 NEW_LINE DEDENT prob [ ( 0 , 0 ) ] = 1 NEW_LINE i = 0 NEW_LINE for pp in p : NEW_LINE INDENT i += 1 NEW_LINE for j in range ( k // 2 + 1 ) : NEW_LINE INDENT res = prob [ ( i - 1 , j ) ] * ( 1 - pp ) NEW_LINE if j > 0 : NEW_LINE INDENT res = res + prob [ ( i - 1 , j - 1 ) ] * pp NEW_LINE DEDENT prob [ ( i , j ) ] = res NEW_LINE DEDENT DEDENT return prob [ ( i , k // 2 ) ] NEW_LINE DEDENT def solve_test ( data ) : NEW_LINE INDENT n , k , p = data NEW_LINE p = sorted ( p ) NEW_LINE ans = - 1 NEW_LINE for i in range ( k + 1 ) : NEW_LINE INDENT left = i NEW_LINE right = k - i NEW_LINE pp = p [ : i ] + p [ n - right : ] NEW_LINE assert len ( pp ) == k NEW_LINE prob = calcprob ( pp ) NEW_LINE if prob > ans : NEW_LINE INDENT ans = prob NEW_LINE DEDENT DEDENT sys . stderr . write ( ' . ' ) NEW_LINE return ans NEW_LINE DEDENT tests = int ( input ( ) ) NEW_LINE data = [ ] NEW_LINE for test in range ( tests ) : NEW_LINE INDENT sys . stderr . write ( str ( test ) ) NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE p = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE data . append ( ( n , k , p ) ) NEW_LINE DEDENT with Pool ( 6 ) as p : NEW_LINE INDENT res = p . map ( solve_test , data ) NEW_LINE DEDENT for test in range ( tests ) : NEW_LINE INDENT print ( " Case ▁ # % d : ▁ % 0.8f " % ( test + 1 , res [ test ] ) ) NEW_LINE DEDENT


from itertools import * NEW_LINE def test ( k ) : NEW_LINE INDENT assert ( len ( k ) == K ) NEW_LINE F = [ 0.0 ] * ( K // 2 + 1 ) NEW_LINE F [ 0 ] = 1.0 NEW_LINE for p in k : NEW_LINE INDENT G = [ 0.0 ] * ( K // 2 + 1 ) NEW_LINE for j in range ( K // 2 ) : NEW_LINE INDENT G [ j ] += F [ j ] * p NEW_LINE G [ j + 1 ] += F [ j ] * ( 1 - p ) NEW_LINE DEDENT G [ K // 2 ] += F [ K // 2 ] * p NEW_LINE F = G NEW_LINE DEDENT return F [ K // 2 ] NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE F = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE F . sort ( ) NEW_LINE ans = 0.0 NEW_LINE ans = max ( test ( F [ : K ] ) , test ( F [ - K : ] ) ) NEW_LINE for i in range ( 1 , K ) : NEW_LINE INDENT ans = max ( ans , test ( F [ : i ] + F [ - ( K - i ) : ] ) ) NEW_LINE DEDENT for i in range ( N - K ) : NEW_LINE INDENT ans = max ( ans , test ( F [ i : i + K ] ) ) NEW_LINE DEDENT print ( " Case ▁ # % d : ▁ % .20f " % ( t + 1 , ans ) ) NEW_LINE DEDENT


import java . util . Arrays ; import java . util . Scanner ; public class B { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( " Case ▁ # " + i + " : ▁ " ) ; System . out . printf ( " % .9f \n " , solve ( ) ) ; } } static double solve ( ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; double [ ] Pt = new double [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { Pt [ i ] = sc . nextDouble ( ) ; } Arrays . sort ( Pt ) ; double [ ] P = new double [ K ] ; double ans = 0 ; for ( int u = 0 ; u <= K ; ++ u ) { for ( int i = 0 ; i < u ; ++ i ) { P [ i ] = Pt [ i ] ; } for ( int i = u ; i < K ; ++ i ) { P [ i ] = Pt [ N - 1 - ( i - u ) ] ; } double [ ] [ ] dp = new double [ K + 1 ] [ K + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= K ; ++ i ) { for ( int j = 0 ; j <= i ; ++ j ) { if ( j == 0 ) { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] * ( 1 - P [ i - 1 ] ) ) ; } else { dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j ] * ( 1 - P [ i - 1 ] ) + dp [ i - 1 ] [ j - 1 ] * P [ i - 1 ] ) ; } } } ans = Math . max ( ans , dp [ K ] [ K / 2 ] ) ; } return ans ; } }


package round1b ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Kattio extends PrintWriter { public Kattio ( InputStream i ) { super ( new BufferedOutputStream ( System . out ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public Kattio ( InputStream i , OutputStream o ) { super ( new BufferedOutputStream ( o ) ) ; r = new BufferedReader ( new InputStreamReader ( i ) ) ; } public boolean hasMoreTokens ( ) { return peekToken ( ) != null ; } public int getInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public double getDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } public long getLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } public String getWord ( ) { return nextToken ( ) ; } private BufferedReader r ; private String line ; private StringTokenizer st ; private String token ; private String peekToken ( ) { if ( token == null ) try { while ( st == null || ! st . hasMoreTokens ( ) ) { line = r . readLine ( ) ; if ( line == null ) return null ; st = new StringTokenizer ( line ) ; } token = st . nextToken ( ) ; } catch ( IOException e ) { } return token ; } private String nextToken ( ) { String ans = peekToken ( ) ; token = null ; return ans ; } }

import sys NEW_LINE import random NEW_LINE import re NEW_LINE from itertools import permutations NEW_LINE import networkx as nx NEW_LINE def solve ( ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE topics = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT topics . append ( sys . stdin . readline ( ) . split ( ) ) NEW_LINE DEDENT left = set ( ) NEW_LINE right = set ( ) NEW_LINE for a , b in topics : NEW_LINE INDENT left . add ( a ) NEW_LINE right . add ( b ) NEW_LINE DEDENT G = nx . DiGraph ( ) NEW_LINE for a , b in topics : NEW_LINE INDENT G . add_edges_from ( [ ( ( a , 0 ) , ( b , 1 ) , { ' capacity ' : 1 , ' weight ' : 1 } ) ] ) NEW_LINE DEDENT for a in left : NEW_LINE INDENT G . add_edges_from ( [ ( 0 , ( a , 0 ) , { ' capacity ' : 1 , ' weight ' : 0 } ) ] ) NEW_LINE DEDENT for b in right : NEW_LINE INDENT G . add_edges_from ( [ ( ( b , 1 ) , 1 , { ' capacity ' : 1 , ' weight ' : 0 } ) ] ) NEW_LINE DEDENT mincostFlow = nx . max_flow_min_cost ( G , 0 , 1 ) NEW_LINE mincost = nx . cost_of_flow ( G , mincostFlow ) NEW_LINE needed_arcs = len ( left ) + len ( right ) - mincost NEW_LINE faked = len ( topics ) - needed_arcs NEW_LINE print faked NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT t = int ( sys . stdin . readline ( ) ) NEW_LINE for i in xrange ( t ) : NEW_LINE INDENT print " Case ▁ # % d : " % ( i + 1 ) , NEW_LINE solve ( ) NEW_LINE DEDENT DEDENT


from __future__ import division NEW_LINE from gcj import * NEW_LINE FLAGS = ' ' NEW_LINE def case ( ) : NEW_LINE INDENT N , = ints ( ) NEW_LINE titles = [ line ( ) . split ( ) for i in range ( N ) ] NEW_LINE for t in titles : NEW_LINE INDENT a , b = t NEW_LINE t [ : ] = [ ' a : ' + a , ' b : ' + b ] NEW_LINE DEDENT pprint ( titles ) NEW_LINE source = 0 NEW_LINE sink = 1 NEW_LINE node2id = dict ( source = source , sink = sink ) NEW_LINE wordcounts = { } NEW_LINE for a , b in titles : NEW_LINE INDENT for x in a , b : NEW_LINE INDENT node2id . setdefault ( x , len ( node2id ) ) NEW_LINE wordcounts . setdefault ( x , 0 ) NEW_LINE wordcounts [ x ] += 1 NEW_LINE DEDENT DEDENT pprint ( node2id ) NEW_LINE pprint ( wordcounts ) NEW_LINE N = len ( node2id ) NEW_LINE capacity = [ [ 0 ] * N for i in range ( N ) ] NEW_LINE for word , count in wordcounts . items ( ) : NEW_LINE INDENT if word . startswith ( ' a ' ) : NEW_LINE INDENT capacity [ source ] [ node2id [ word ] ] = count - 1 NEW_LINE DEDENT else : NEW_LINE INDENT capacity [ node2id [ word ] ] [ sink ] = count - 1 NEW_LINE DEDENT DEDENT for a , b in titles : NEW_LINE INDENT assert capacity [ node2id [ a ] ] [ node2id [ b ] ] == 0 NEW_LINE capacity [ node2id [ a ] ] [ node2id [ b ] ] = 1 NEW_LINE DEDENT def dfs ( pos , visited ) : NEW_LINE INDENT if pos == sink : NEW_LINE INDENT return True NEW_LINE DEDENT for t in range ( N ) : NEW_LINE INDENT if capacity [ pos ] [ t ] : NEW_LINE INDENT if t in visited : continue NEW_LINE visited . add ( t ) NEW_LINE capacity [ pos ] [ t ] -= 1 NEW_LINE capacity [ t ] [ pos ] += 1 NEW_LINE res = dfs ( t , visited ) NEW_LINE if res : NEW_LINE INDENT return res NEW_LINE DEDENT capacity [ t ] [ pos ] -= 1 NEW_LINE capacity [ pos ] [ t ] += 1 NEW_LINE DEDENT DEDENT DEDENT n = 0 NEW_LINE while True : NEW_LINE INDENT res = dfs ( source , set ( ) ) NEW_LINE if not res : break NEW_LINE n += 1 NEW_LINE DEDENT return n NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


first = { } NEW_LINE second = { } NEW_LINE np = 0 NEW_LINE em = [ ] NEW_LINE match = [ ] NEW_LINE def ToNo ( x , isFirst = True ) : NEW_LINE INDENT global np , em NEW_LINE ws = first if isFirst else second NEW_LINE if x not in ws : NEW_LINE INDENT ws [ x ] = np NEW_LINE np += 1 NEW_LINE em += [ set ( ) ] NEW_LINE DEDENT return ws [ x ] NEW_LINE DEDENT def dfs ( x ) : NEW_LINE INDENT v [ x ] = True NEW_LINE for y in em [ x ] : NEW_LINE INDENT if match [ y ] == - 1 or ( not v [ match [ y ] ] and dfs ( match [ y ] ) ) : NEW_LINE INDENT match [ y ] = x NEW_LINE return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT for case in range ( 1 , int ( raw_input ( ) ) + 1 ) : NEW_LINE INDENT print " Case ▁ # % d : " % case , NEW_LINE np = 0 NEW_LINE first = { } NEW_LINE second = { } NEW_LINE em = [ ] NEW_LINE n = int ( raw_input ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT a , b = raw_input ( ) . split ( ) NEW_LINE em [ ToNo ( a ) ] . add ( ToNo ( b , False ) ) NEW_LINE em [ ToNo ( b , False ) ] . add ( ToNo ( a ) ) NEW_LINE DEDENT match = [ - 1 ] * np NEW_LINE ans = 0 NEW_LINE for x in first : NEW_LINE INDENT no = ToNo ( x ) NEW_LINE v = [ False ] * np NEW_LINE if dfs ( no ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print n - ( np - ans ) NEW_LINE DEDENT


import sys NEW_LINE import re NEW_LINE import bipartite_matching NEW_LINE input_file = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE nb_tests = int ( input_file . readline ( ) ) NEW_LINE for i in range ( nb_tests ) : NEW_LINE INDENT nb_titles = int ( input_file . readline ( ) ) NEW_LINE titles = { } NEW_LINE first_titles = set ( { } ) NEW_LINE second_titles = set ( { } ) NEW_LINE for j in range ( nb_titles ) : NEW_LINE INDENT title = input_file . readline ( ) [ : - 1 ] . split ( ' ▁ ' ) NEW_LINE first_titles = first_titles | { title [ 0 ] } NEW_LINE second_titles = second_titles | { title [ 1 ] } NEW_LINE if title [ 0 ] in titles : NEW_LINE INDENT titles [ title [ 0 ] ] . append ( title [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT titles [ title [ 0 ] ] = [ title [ 1 ] ] NEW_LINE DEDENT DEDENT matching = bipartite_matching . bipartiteMatch ( titles ) [ 0 ] NEW_LINE len_m = len ( matching ) NEW_LINE len_f = len ( first_titles ) NEW_LINE len_s = len ( second_titles ) NEW_LINE cover = len_f + len_s - len_m NEW_LINE print ( ' Case ▁ # ' , i + 1 , ' : ▁ ' , nb_titles - cover , sep = ' ' ) NEW_LINE DEDENT


def dfs ( e , ma , u , v ) : NEW_LINE INDENT if v in u : NEW_LINE INDENT return False NEW_LINE DEDENT u [ v ] = True NEW_LINE for x in e [ v ] : NEW_LINE INDENT if ( not x in ma ) or dfs ( e , ma , u , ma [ x ] ) : NEW_LINE INDENT ma [ x ] = v NEW_LINE return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE e = { } NEW_LINE av = { } NEW_LINE bv = { } NEW_LINE ac = 0 NEW_LINE bc = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT a , b = list ( input ( ) . split ( ) ) NEW_LINE if not a in e : NEW_LINE INDENT e [ a ] = [ ] NEW_LINE DEDENT e [ a ] . append ( b ) NEW_LINE if not a in av : NEW_LINE INDENT av [ a ] = True NEW_LINE ac += 1 NEW_LINE DEDENT if not b in bv : NEW_LINE INDENT bv [ b ] = True NEW_LINE bc += 1 NEW_LINE DEDENT DEDENT m = 0 NEW_LINE ma = { } NEW_LINE for a in av : NEW_LINE INDENT u = { } NEW_LINE if dfs ( e , ma , u , a ) : NEW_LINE INDENT m += 1 NEW_LINE DEDENT DEDENT return str ( n - ( ac + bc - m ) ) NEW_LINE DEDENT nt = int ( input ( ) ) NEW_LINE for tt in range ( nt ) : NEW_LINE INDENT print ( ' Case ▁ # ' + str ( tt + 1 ) + ' : ▁ ' + str ( solve ( ) ) ) NEW_LINE DEDENT


package round1B ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Locale ; import java . util . Scanner ; import round1B . PushRelabelNodeEdge . Node ; public class ProblemC { public static void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; HashMap < String , Node > map1 = new HashMap < > ( ) ; HashMap < String , Node > map2 = new HashMap < > ( ) ; Node start = new Node ( " start " ) ; Node end = new Node ( " end " ) ; for ( int i = 0 ; i < n ; i ++ ) { String firstWord = sc . next ( ) ; String secondWord = sc . next ( ) ; if ( ! map1 . containsKey ( firstWord ) ) { Node node = new Node ( firstWord ) ; map1 . put ( firstWord , node ) ; PushRelabelNodeEdge . addDirectedEdge ( start , node , 1 ) ; } if ( ! map2 . containsKey ( secondWord ) ) { Node node = new Node ( secondWord ) ; map2 . put ( secondWord , node ) ; PushRelabelNodeEdge . addDirectedEdge ( node , end , 1 ) ; } PushRelabelNodeEdge . addDirectedEdge ( map1 . get ( firstWord ) , map2 . get ( secondWord ) , 1 ) ; } ArrayList < Node > nodes = new ArrayList < > ( ) ; nodes . add ( start ) ; nodes . add ( end ) ; nodes . addAll ( map1 . values ( ) ) ; nodes . addAll ( map2 . values ( ) ) ; int flow = PushRelabelNodeEdge . getMaxFlow ( nodes , start , end ) ; int greedy = nodes . size ( ) - 2 - 2 * flow ; System . out . println ( n - flow - greedy ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( new File ( " C - large . in " ) ) ; sc . useLocale ( Locale . US ) ; int cases = sc . nextInt ( ) ; for ( int i = 1 ; i <= cases ; i ++ ) { System . out . format ( Locale . US , " Case ▁ # % d : ▁ " , i ) ; solve ( sc ) ; } sc . close ( ) ; } }


import java . io . * ; import java . util . Arrays ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( " A - small - attempt0 ▁ ( 1 ) . in " ) ) ; PrintWriter out = new PrintWriter ( " a . out " ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int n = in . nextInt ( ) ; Lev [ ] ls = new Lev [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ls [ i ] = new Lev ( ) ; ls [ i ] . i = i ; ls [ i ] . l = in . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { ls [ i ] . p = in . nextInt ( ) ; } Arrays . sort ( ls ) ; StringBuilder buf = new StringBuilder ( ) ; for ( Lev l : ls ) { buf . append ( " ▁ " ) . append ( l . i ) ; } out . println ( " Case ▁ # " + t + " : " + buf ) ; } out . close ( ) ; in . close ( ) ; } private static class Lev implements Comparable < Lev > { public int l , p , i ; public int compareTo ( Lev o ) { double q1 = Math . log ( ( 100. - p ) * 0.01 ) / l ; double q2 = Math . log ( ( 100. - o . p ) * 0.01 ) / o . l ; return Double . compare ( q1 , q2 ) ; } } }

import sys NEW_LINE T = int ( sys . stdin . readline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE L = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE P = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE l = [ ] NEW_LINE for i , p in enumerate ( P ) : NEW_LINE INDENT if p != 0 : NEW_LINE INDENT l . append ( ( float ( L [ i ] ) / p , i ) ) ; NEW_LINE DEDENT else : NEW_LINE INDENT l . append ( ( 1E30 , i ) ) ; NEW_LINE DEDENT DEDENT l . sort ( ) NEW_LINE print ' Case ▁ # % d : ▁ ' % t , NEW_LINE for p , i in l : NEW_LINE INDENT print i , NEW_LINE DEDENT print ' ' NEW_LINE DEDENT


import sys NEW_LINE def cmp_fn ( x1 , x2 ) : NEW_LINE INDENT L1 , q1 = x1 [ 1 ] , x1 [ 2 ] NEW_LINE L2 , q2 = x2 [ 1 ] , x2 [ 2 ] NEW_LINE if q1 == 100 and q2 == 100 : NEW_LINE INDENT return x1 [ 0 ] - x1 [ 1 ] NEW_LINE DEDENT if q1 == 100 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if q2 == 100 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if L1 * q2 != L2 * q1 : NEW_LINE INDENT return L2 * q1 - L1 * q2 NEW_LINE DEDENT return x1 [ 0 ] - x1 [ 1 ] NEW_LINE DEDENT def compute ( L , P ) : NEW_LINE INDENT x = [ ( i , L [ i ] , 100 - P [ i ] ) for i in xrange ( len ( L ) ) ] NEW_LINE x = sorted ( x , cmp = cmp_fn ) NEW_LINE return " ▁ " . join ( [ ( ' % d ' % x [ i ] [ 0 ] ) for i in xrange ( len ( x ) ) ] ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT N = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE L = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE P = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE return L , P NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE count = 1 NEW_LINE part = 0 NEW_LINE if len ( sys . argv ) == 3 : NEW_LINE INDENT part = int ( sys . argv [ 1 ] ) NEW_LINE count = int ( sys . argv [ 2 ] ) NEW_LINE DEDENT for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE if i * count >= part * T and i * count < ( part + 1 ) * T : NEW_LINE INDENT result = compute ( * data ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i + 1 , result ) NEW_LINE DEDENT DEDENT DEDENT


from __future__ import division NEW_LINE import os NEW_LINE import sys NEW_LINE import operator NEW_LINE import string NEW_LINE import re NEW_LINE import time NEW_LINE from os . path import splitext NEW_LINE from copy import copy NEW_LINE from math import * NEW_LINE from operator import * NEW_LINE from collections import * NEW_LINE from itertools import * NEW_LINE from functools import * NEW_LINE try : NEW_LINE INDENT from do import report_working_on NEW_LINE DEDENT except ImportError : NEW_LINE INDENT report_working_on = lambda a , b : None NEW_LINE DEDENT if len ( sys . argv ) > 1 : NEW_LINE INDENT fin = file ( sys . argv [ 1 ] , ' r ' ) NEW_LINE fout = file ( splitext ( sys . argv [ 1 ] ) [ 0 ] + ' . out ' , ' w + ' ) NEW_LINE DEDENT else : NEW_LINE INDENT fin = sys . stdin NEW_LINE fout = sys . stdout NEW_LINE DEDENT def dorun ( ) : NEW_LINE INDENT cases = int ( fin . next ( ) ) NEW_LINE for case in xrange ( cases ) : NEW_LINE INDENT report_working_on ( case , cases ) NEW_LINE print >> fout , ' Case ▁ # % d : ▁ % s ' % ( 1 + case , solve ( fin ) ) NEW_LINE DEDENT else : NEW_LINE INDENT report_working_on ( 0 , 0 ) NEW_LINE DEDENT DEDENT def solve ( fin ) : NEW_LINE INDENT N = int ( fin . next ( ) . strip ( ) ) NEW_LINE Lx = map ( int , fin . next ( ) . split ( ) ) NEW_LINE Px = map ( int , fin . next ( ) . split ( ) ) NEW_LINE LL = list ( enumerate ( Px ) ) NEW_LINE LL . sort ( key = lambda a : - a [ 1 ] ) NEW_LINE return ' ▁ ' . join ( str ( a [ 0 ] ) for a in LL ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : dorun ( ) NEW_LINE


fin = open ( " A - small - attempt0 . in " , " r " ) NEW_LINE fout = open ( " A . out " , " w " ) NEW_LINE numcases = int ( fin . readline ( ) ) NEW_LINE numcases += 1 NEW_LINE for cas in xrange ( 1 , numcases ) : NEW_LINE INDENT fout . write ( " Case ▁ # " + str ( cas ) + " : " ) NEW_LINE n = int ( fin . readline ( ) ) NEW_LINE l = map ( float , fin . readline ( ) . split ( ) ) NEW_LINE p = map ( float , fin . readline ( ) . split ( ) ) NEW_LINE q = [ p [ i ] / l [ i ] for i in xrange ( n ) ] NEW_LINE r = [ ( q [ i ] , - i ) for i in xrange ( n ) ] NEW_LINE r . sort ( ) NEW_LINE r . reverse ( ) NEW_LINE for i in r : NEW_LINE INDENT fout . write ( " ▁ " + str ( - i [ 1 ] ) ) NEW_LINE DEDENT fout . write ( " \n " ) NEW_LINE DEDENT