import java . io . * ; import java . util . * ; public class Goro { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new FileReader ( " D - large . in " ) ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( " output " ) ) ; for ( int I = 1 ; I <= T ; I ++ ) { int N = Integer . parseInt ( br . readLine ( ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) , " ▁ " , false ) ; int ret = N ; for ( int i = 0 ; i < N ; i ++ ) { int k = Integer . parseInt ( st . nextToken ( ) ) ; if ( k == i + 1 ) ret -- ; } pw . println ( " Case ▁ # " + I + " : ▁ " + ret + " . 000000" ) ; } br . close ( ) ; pw . flush ( ) ; pw . close ( ) ; } catch ( IOException ie ) { ie . printStackTrace ( ) ; } } }

import java . util . * ; import java . io . * ; public class Solution { public void doIt ( ) throws Exception { Scanner sc = new Scanner ( new FileReader ( " input . txt " ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( " output . txt " ) ) ; final int MAX = 1000 ; double [ ] invFact = new double [ MAX + 1 ] ; invFact [ 0 ] = 1.0 ; for ( int i = 1 ; i <= MAX ; i ++ ) invFact [ i ] = invFact [ i - 1 ] / ( double ) i ; double [ ] derang = new double [ MAX + 1 ] ; derang [ 0 ] = invFact [ 0 ] ; for ( int i = 1 ; i <= MAX ; i ++ ) derang [ i ] = derang [ i - 1 ] + ( i % 2 == 1 ? - 1 : 1 ) * invFact [ i ] ; double [ ] avgTime = new double [ MAX + 1 ] ; avgTime [ 0 ] = 0.0 ; for ( int i = 1 ; i <= MAX ; i ++ ) { double sum = 1.0 ; for ( int j = 1 ; j <= i ; j ++ ) sum += avgTime [ i - j ] * invFact [ j ] * derang [ i - j ] ; avgTime [ i ] = sum / ( 1 - invFact [ 0 ] * derang [ i ] ) ; } int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { int N = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int x = sc . nextInt ( ) ; if ( x != i ) ans ++ ; } pw . println ( " Case ▁ # " + ( caseNum + 1 ) + " : ▁ " + ans ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) throws Exception { new Solution ( ) . doIt ( ) ; } }

import java . util . * ; public class d { static double [ ] memo = new double [ 1010 ] ; static double [ ] [ ] memoo = new double [ 1010 ] [ 1010 ] ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int n = in . nextInt ( ) ; int k = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( i != in . nextInt ( ) ) k ++ ; System . out . printf ( " Case ▁ # % d : ▁ % f % n " , t , ( double ) k ) ; } } public static double f ( int k , int j ) { if ( j < 0 || j > k ) return 0 ; if ( k == 0 && j == 0 ) return 1 ; if ( memoo [ k ] [ j ] != 0 ) return memoo [ k ] [ j ] ; double ans = f ( k - 1 , j - 1 ) + f ( k - 1 , j ) * ( k - 1 - j ) + f ( k - 1 , j + 1 ) * ( j + 1 ) ; ans /= k ; return memoo [ k ] [ j ] = ans ; } public static double go ( int k ) { if ( k == 0 ) return 0 ; if ( memo [ k ] != 0 ) return memo [ k ] ; double total = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { total += f ( k , i ) * go ( k - i ) ; } total /= ( 1 - f ( k , 0 ) ) ; return memo [ k ] = total ; } }

import java . io . * ; import java . util . * ; import java . math . * ; public class Main implements Runnable { String file = " D - large " ; private void solve ( ) throws IOException { int tn = nextInt ( ) ; for ( int testN = 1 ; testN <= tn ; ++ testN ) { int n = nextInt ( ) ; int ans = n ; for ( int i = 0 ; i < n ; ++ i ) { if ( nextInt ( ) == i + 1 ) { -- ans ; } } out . printf ( " Case ▁ # % d : ▁ % d . 000000 \n " , testN , ans ) ; } } public static void main ( String [ ] args ) { new Thread ( new Main ( ) ) . start ( ) ; } StringTokenizer tok ; PrintWriter out ; BufferedReader br ; @ Override public void run ( ) { try { Locale . setDefault ( Locale . US ) ; out = new PrintWriter ( new FileWriter ( file + " . out " ) ) ; br = new BufferedReader ( new FileReader ( file + " . in " ) ) ; tok = new StringTokenizer ( " " ) ; while ( hasNext ( ) ) { solve ( ) ; } out . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } boolean hasNext ( ) throws IOException { while ( ! tok . hasMoreElements ( ) ) { String line = br . readLine ( ) ; if ( line == null ) { return false ; } tok = new StringTokenizer ( line ) ; } return true ; } String next ( ) throws IOException { if ( hasNext ( ) ) { return tok . nextToken ( ) ; } throw new IOException ( " No ▁ more ▁ tokens " ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) throws IOException { if ( hasNext ( ) ) { return tok . nextToken ( " \n " ) ; } throw new IOException ( " No ▁ more ▁ tokens " ) ; } }

import java . io . File ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class D { static double [ ] dpc = new double [ 1024 ] ; static double [ ] dpa = new double [ 1024 ] ; public static void main ( String [ ] args ) throws Exception { Scanner s = new Scanner ( new File ( " D . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " D . out " ) ) ; dpc [ 1 ] = 0 ; dpc [ 2 ] = 2 ; dpa [ 1 ] = 0 ; dpa [ 2 ] = 1 ; for ( int i = 3 ; i <= 1000 ; i ++ ) { dpc [ i ] = 1 ; for ( int j = 1 ; j < i ; j ++ ) { dpc [ i ] += ( dpc [ j ] + dpa [ i - j ] ) / i ; } dpc [ i ] *= ( ( double ) i ) / ( i - 1 ) ; dpa [ i ] = dpc [ i ] - 1 ; } int T = s . nextInt ( ) ; int [ ] arr = new int [ 1024 ] ; boolean [ ] mark = new boolean [ 1024 ] ; for ( int tc = 1 ; tc <= T ; tc ++ ) { out . print ( " Case ▁ # " + tc + " : ▁ " ) ; int N = s . nextInt ( ) ; for ( int i = 1 ; i <= N ; i ++ ) arr [ i ] = s . nextInt ( ) ; double answer = 0 ; Arrays . fill ( mark , false ) ; for ( int i = 1 ; i <= N ; i ++ ) { int cycleLength = 0 ; int cur = i ; while ( ! mark [ cur ] ) { mark [ cur ] = true ; cur = arr [ cur ] ; cycleLength ++ ; } answer += dpc [ cycleLength ] ; } out . println ( answer ) ; } out . close ( ) ; System . out . println ( dpc [ 1000 ] ) ; } }

import sys NEW_LINE def c ( ) : NEW_LINE INDENT t = int ( sys . stdin . readline ( ) ) NEW_LINE for i in xrange ( t ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE arr = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE arr = [ x - 1 for x in arr ] NEW_LINE assert len ( arr ) == n NEW_LINE count = 0 NEW_LINE seen = [ False for _ in xrange ( n ) ] NEW_LINE for ix , x in enumerate ( arr ) : NEW_LINE INDENT if x == ix : NEW_LINE INDENT continue NEW_LINE DEDENT while not seen [ x ] : NEW_LINE INDENT seen [ x ] = True NEW_LINE x = arr [ x ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT print " Case ▁ # % d : ▁ % d " % ( i + 1 , count ) NEW_LINE DEDENT DEDENT c ( ) NEW_LINE

def get_permutation ( L1 , L2 ) : NEW_LINE INDENT if sorted ( L1 ) != sorted ( L2 ) : NEW_LINE INDENT raise ValueError ( " L2 ▁ must ▁ be ▁ permutation ▁ of ▁ L1 ▁ ( % s , ▁ % s ) " % ( L1 , L2 ) ) NEW_LINE DEDENT permutation = map ( dict ( ( v , i ) for i , v in enumerate ( L1 ) ) . get , L2 ) NEW_LINE assert [ L1 [ p ] for p in permutation ] == L2 NEW_LINE return permutation NEW_LINE DEDENT def get_cycles ( permutation ) : NEW_LINE INDENT nswaps = 0 NEW_LINE seen = set ( ) NEW_LINE cycles = [ ] NEW_LINE for i in xrange ( len ( permutation ) ) : NEW_LINE INDENT if i not in seen : NEW_LINE INDENT j = i NEW_LINE cycles . append ( [ i + 1 ] ) NEW_LINE while permutation [ j ] != i : NEW_LINE INDENT j = permutation [ j ] NEW_LINE seen . add ( j ) NEW_LINE nswaps += 1 NEW_LINE cycles [ - 1 ] . append ( j + 1 ) NEW_LINE DEDENT DEDENT DEDENT return cycles NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT f = open ( " input . txt " ) NEW_LINE testlen = int ( f . readline ( ) . strip ( ) ) NEW_LINE tests = [ ] NEW_LINE i = 0 NEW_LINE for line in f : NEW_LINE INDENT if i % 2 : NEW_LINE INDENT tests . append ( line . strip ( ) ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT tests = tests [ : testlen ] NEW_LINE for test , i in zip ( tests , range ( testlen ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( i + 1 , solve ( parse ( test ) ) ) NEW_LINE DEDENT DEDENT def parse ( test ) : NEW_LINE INDENT return map ( int , test . split ( " ▁ " ) ) NEW_LINE DEDENT def solve ( test ) : NEW_LINE INDENT perm = get_permutation ( test , sorted ( test ) ) NEW_LINE cycles = get_cycles ( perm ) NEW_LINE v = 0 NEW_LINE for cy in cycles : NEW_LINE INDENT if len ( cy ) > 1 : NEW_LINE INDENT v += len ( cy ) NEW_LINE DEDENT DEDENT return " % d . 000000" % ( v ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

import sys NEW_LINE def process ( num , fin , fout ) : NEW_LINE INDENT n = int ( fin . readline ( ) ) NEW_LINE data = [ int ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE unmatched = 0 NEW_LINE for i in xrange ( len ( data ) ) : NEW_LINE INDENT if data [ i ] != i + 1 : NEW_LINE INDENT unmatched += 1 NEW_LINE DEDENT DEDENT fout . write ( str ( unmatched ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT if len ( sys . argv ) != 3 : NEW_LINE INDENT print " Please ▁ indicate ▁ input ▁ and ▁ output " NEW_LINE exit ( 0 ) NEW_LINE DEDENT fin = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE fout = open ( sys . argv [ 2 ] , ' w ' ) NEW_LINE times = int ( fin . readline ( ) ) NEW_LINE for i in xrange ( times ) : NEW_LINE INDENT fout . write ( " Case ▁ # % d : ▁ " % ( i + 1 ) ) NEW_LINE process ( i , fin , fout ) NEW_LINE fout . write ( " \n " ) NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE DEDENT

infile = " D - large . in " NEW_LINE debug = False NEW_LINE def find_subsets ( L ) : NEW_LINE INDENT used = [ False ] * len ( L ) NEW_LINE subsets = [ ] NEW_LINE for ix in xrange ( len ( L ) ) : NEW_LINE INDENT if used [ ix ] : NEW_LINE INDENT continue NEW_LINE DEDENT used [ ix ] = True NEW_LINE ix_subset = [ ix ] NEW_LINE next_ix = L [ ix ] - 1 NEW_LINE while next_ix != ix : NEW_LINE INDENT ix_subset . append ( next_ix ) NEW_LINE used [ next_ix ] = True NEW_LINE next_ix = L [ next_ix ] - 1 NEW_LINE DEDENT subsets . append ( ix_subset ) NEW_LINE DEDENT assert False not in used NEW_LINE assert sum ( map ( len , subsets ) ) == len ( L ) NEW_LINE return subsets NEW_LINE DEDENT def how_many ( set_size ) : NEW_LINE INDENT if set_size == 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return set_size NEW_LINE DEDENT DEDENT def solve ( nstr , data ) : NEW_LINE INDENT N = int ( nstr ) NEW_LINE data = map ( int , data . split ( ) ) NEW_LINE assert len ( data ) == N NEW_LINE subsets = find_subsets ( data ) NEW_LINE if debug : NEW_LINE INDENT print subsets NEW_LINE print map ( len , subsets ) NEW_LINE DEDENT avg = 0.0 NEW_LINE for subset in subsets : NEW_LINE INDENT avg += how_many ( len ( subset ) ) NEW_LINE DEDENT return " % .7f " % avg NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT i = file ( infile ) NEW_LINE N = int ( i . readline ( ) ) NEW_LINE for n in xrange ( N ) : NEW_LINE INDENT soln = solve ( i . readline ( ) , i . readline ( ) ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( n + 1 , soln ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE

data = [ l . strip ( ) for l in open ( " infile " , " r " ) . readlines ( ) ] NEW_LINE out = open ( " outfile " , " w " ) NEW_LINE ncases = int ( data . pop ( 0 ) ) NEW_LINE for case in range ( ncases ) : NEW_LINE INDENT numelements = int ( data . pop ( 0 ) ) NEW_LINE elements = [ int ( s ) for s in data . pop ( 0 ) . split ( ' ▁ ' ) ] NEW_LINE inwrongplace = 0 NEW_LINE for i in range ( len ( elements ) ) : NEW_LINE INDENT if elements [ i ] != i + 1 : NEW_LINE INDENT inwrongplace += 1 NEW_LINE DEDENT DEDENT out . write ( " Case ▁ # " + str ( case + 1 ) + " : ▁ " + str ( " % .6f " % inwrongplace ) + " \n " ) NEW_LINE DEDENT


import java . util . * ; public class Smooth { static Scanner sc = new Scanner ( System . in ) ; static int [ ] [ ] memo = new int [ 100 ] [ 257 ] ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { System . out . print ( " Case ▁ # " + i + " : ▁ " ) ; solveCase ( ) ; } } static final int SPC = 256 ; static void solveCase ( ) { del = sc . nextInt ( ) ; ins = sc . nextInt ( ) ; maxDist = sc . nextInt ( ) ; n = sc . nextInt ( ) ; arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = sc . nextInt ( ) ; for ( int [ ] arr : memo ) Arrays . fill ( arr , - 1 ) ; System . out . println ( solve ( 0 , SPC ) ) ; } static int del , ins , maxDist , n ; static int [ ] arr ; static int solve ( int index , int prev ) { if ( index >= n ) return 0 ; if ( memo [ index ] [ prev ] == - 1 ) { int res = del + solve ( index + 1 , prev ) ; for ( int val = 0 ; val < SPC ; val ++ ) { res = Math . min ( res , Math . abs ( arr [ index ] - val ) + insCost ( val , prev ) + solve ( index + 1 , val ) ) ; } memo [ index ] [ prev ] = res ; } return memo [ index ] [ prev ] ; } static int insCost ( int cur , int prev ) { if ( prev == SPC || cur == prev ) return 0 ; if ( maxDist == 0 ) return 100000000 ; return ins * ( ( Math . abs ( cur - prev ) + maxDist - 1 ) / maxDist - 1 ) ; } }

import java . util . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int D = sc . nextInt ( ) ; int I = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = sc . nextInt ( ) ; int [ ] DP = new int [ 256 ] ; Arrays . fill ( DP , 0 ) ; int [ ] CUR = new int [ 256 ] ; for ( int at = N - 1 ; at >= 0 ; at -- ) { for ( int i = 0 ; i < 1000 ; i ++ ) { int prev ; if ( i % 2 == 0 ) prev = A [ at ] + i / 2 ; else prev = A [ at ] - ( i + 1 ) / 2 ; if ( prev < 0 || prev >= 256 ) continue ; int cost = DP [ prev ] + D ; for ( int j = 0 ; j < 256 ; j ++ ) { if ( abs ( j - prev ) <= M || prev == - 1 ) cost = min ( cost , DP [ j ] + abs ( j - A [ at ] ) ) ; if ( abs ( j - A [ at ] ) < abs ( A [ at ] - prev ) && ( prev == - 1 || abs ( j - prev ) <= M ) ) cost = min ( cost , CUR [ j ] + I ) ; } CUR [ prev ] = cost ; } for ( int j = 0 ; j < 256 ; j ++ ) DP [ j ] = CUR [ j ] ; Arrays . fill ( CUR , 0 ) ; } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < DP . length ; i ++ ) ans = min ( ans , DP [ i ] ) ; System . out . format ( " Case ▁ # % d : ▁ % d \n " , t , ans ) ; } } }

import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return [ foo ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE def doit ( p , last ) : NEW_LINE INDENT if ( p , last ) in mem : return mem [ ( p , last ) ] NEW_LINE if ( p == N ) : return 0 NEW_LINE res = doit ( p + 1 , last ) + D NEW_LINE for i in xrange ( 256 ) : NEW_LINE INDENT if last == - 1 : NEW_LINE INDENT res = min ( res , doit ( p + 1 , i ) + abs ( a [ p ] - i ) ) NEW_LINE continue NEW_LINE DEDENT diff = abs ( last - i ) NEW_LINE if M == 0 and diff > 0 : continue NEW_LINE insertcost = ( ( diff - 1 ) / M ) * I if ( diff > 0 and I > 0 ) else 0 NEW_LINE editcost = abs ( a [ p ] - i ) NEW_LINE res = min ( res , doit ( p + 1 , i ) + editcost + insertcost ) NEW_LINE DEDENT mem [ ( p , last ) ] = res NEW_LINE return res NEW_LINE DEDENT def run_test ( test ) : NEW_LINE INDENT global D , I , M , N , a , mem NEW_LINE ( D , I , M , N ) = readarray ( int ) NEW_LINE a = readarray ( int ) NEW_LINE mem = { } NEW_LINE res = doit ( 0 , - 1 ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( test + 1 , res ) NEW_LINE DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( " Test ▁ % d \n " % ( test + 1 ) ) NEW_LINE run_test ( test ) NEW_LINE DEDENT

from __future__ import division NEW_LINE import collections NEW_LINE import itertools NEW_LINE import sys NEW_LINE class gcj : NEW_LINE INDENT IN = sys . stdin NEW_LINE number = 0 NEW_LINE @ classmethod NEW_LINE def case ( cls ) : NEW_LINE INDENT cls . number += 1 NEW_LINE return ' Case ▁ # % d : ' % cls . number NEW_LINE DEDENT @ classmethod NEW_LINE def line ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return type ( line . strip ( ' \n ' ) ) NEW_LINE DEDENT @ classmethod NEW_LINE def splitline ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return [ type ( x ) for x in line . split ( ) ] NEW_LINE DEDENT DEDENT def go ( ) : NEW_LINE INDENT t = gcj . line ( int ) NEW_LINE for _ in xrange ( t ) : NEW_LINE INDENT D , I , m , n = gcj . splitline ( int ) NEW_LINE data = gcj . splitline ( int ) NEW_LINE assert len ( data ) == n NEW_LINE print gcj . case ( ) , solve ( D , I , m , data ) NEW_LINE DEDENT DEDENT def solve ( D , I , m , data ) : NEW_LINE INDENT n = len ( data ) NEW_LINE tab = [ 0 ] * 256 NEW_LINE otab = [ 0 ] * 256 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT otab , tab = tab , otab NEW_LINE for j in xrange ( 256 ) : NEW_LINE INDENT cur = otab [ j ] + D NEW_LINE base = abs ( data [ i ] - j ) NEW_LINE if cur > base : NEW_LINE INDENT for k in xrange ( 256 ) : NEW_LINE INDENT if m == 0 and k != j : NEW_LINE INDENT continue NEW_LINE DEDENT new = otab [ k ] NEW_LINE if k < j : NEW_LINE INDENT new += ( j - k - 1 ) // m * I NEW_LINE DEDENT elif k > j : NEW_LINE INDENT new += ( k - j - 1 ) // m * I NEW_LINE DEDENT if cur > base + new : NEW_LINE INDENT cur = base + new NEW_LINE DEDENT DEDENT DEDENT tab [ j ] = cur NEW_LINE DEDENT DEDENT return min ( tab [ i ] for i in xrange ( 256 ) ) NEW_LINE DEDENT go ( ) NEW_LINE

from sys import stdin NEW_LINE N = 256 NEW_LINE def main ( ) : NEW_LINE INDENT dd , ii , mm , n = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE A = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE x = [ 0 ] * N NEW_LINE for a in A : NEW_LINE INDENT y = [ ] NEW_LINE for v in x : NEW_LINE INDENT y . append ( v + dd ) NEW_LINE DEDENT for i in xrange ( N ) : NEW_LINE INDENT y [ i ] = min ( y [ i ] , min ( x [ max ( 0 , i - mm ) : min ( i + mm + 1 , N ) ] ) + abs ( i - a ) ) NEW_LINE DEDENT for i in xrange ( N ) : NEW_LINE INDENT for j in xrange ( i + 1 , min ( N , i + mm + 1 ) ) : NEW_LINE INDENT y [ j ] = min ( y [ j ] , y [ i ] + ii ) NEW_LINE DEDENT DEDENT for i in xrange ( N ) : NEW_LINE INDENT for j in xrange ( i + 1 , min ( N , i + mm + 1 ) ) : NEW_LINE INDENT y [ N - 1 - j ] = min ( y [ N - 1 - j ] , y [ N - 1 - i ] + ii ) NEW_LINE DEDENT DEDENT x = y NEW_LINE DEDENT return str ( min ( x ) ) NEW_LINE DEDENT tno = int ( stdin . readline ( ) ) NEW_LINE for i in xrange ( 0 , tno ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( i + 1 , main ( ) ) NEW_LINE DEDENT

import os NEW_LINE import sys NEW_LINE def debug ( * x , ** a ) : NEW_LINE INDENT print " DEBUG : ▁ % s " % " ▁ " . join ( [ repr ( v ) for v in x ] + [ " % s = % s " % ( k , repr ( v ) ) for ( k , v ) in a . iteritems ( ) ] ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT def read_ints ( ) : NEW_LINE INDENT return [ int ( x ) for x in raw_input ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT [ N_CASES ] = read_ints ( ) NEW_LINE for case in xrange ( 1 , N_CASES + 1 ) : NEW_LINE INDENT [ D , I , M , N ] = read_ints ( ) NEW_LINE A = read_ints ( ) NEW_LINE minA = min ( A ) NEW_LINE A = [ x - minA for x in A ] NEW_LINE Z = max ( A ) + 1 NEW_LINE def insertions ( a , b ) : NEW_LINE INDENT if abs ( a - b ) <= M : NEW_LINE INDENT return 0 NEW_LINE DEDENT if M == 0 : NEW_LINE INDENT return 1000000 NEW_LINE DEDENT return ( abs ( a - b ) - 1 ) // M * I NEW_LINE DEDENT c = [ 0 ] * Z NEW_LINE for a in A : NEW_LINE INDENT cc = [ 0 ] * Z NEW_LINE for j in xrange ( Z ) : NEW_LINE INDENT cost = c [ j ] + D NEW_LINE for k in xrange ( Z ) : NEW_LINE INDENT if j == a : NEW_LINE INDENT cost = min ( cost , c [ k ] + insertions ( k , a ) ) NEW_LINE DEDENT else : NEW_LINE INDENT cost = min ( cost , c [ k ] + insertions ( k , a ) + insertions ( a , j ) + I ) NEW_LINE cost = min ( cost , c [ k ] + abs ( j - a ) + insertions ( k , j ) ) NEW_LINE DEDENT DEDENT cc [ j ] = cost NEW_LINE DEDENT c = cc NEW_LINE DEDENT print " Case ▁ # % d : ▁ % d " % ( case , min ( c ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

def read ( ) : NEW_LINE INDENT D , I , M , nVal = map ( int , raw_input ( ) . split ( ) ) NEW_LINE val = map ( int , raw_input ( ) . split ( ) ) NEW_LINE return D , I , M , val NEW_LINE DEDENT def rec ( lastV , idx , D , I , M , val , dp ) : NEW_LINE INDENT if idx == len ( val ) : return 0 NEW_LINE ret = dp [ lastV ] [ idx ] NEW_LINE if ret != - 1 : return ret NEW_LINE ret = 1 << 30 NEW_LINE if lastV != 256 and abs ( lastV - val [ idx ] ) > M and M != 0 : NEW_LINE INDENT absV = abs ( lastV - val [ idx ] ) NEW_LINE ret = min ( ret , rec ( val [ idx ] , idx + 1 , D , I , M , val , dp ) + max ( 0 , ( absV / M - ( absV % M == 0 ) ) * I ) ) NEW_LINE DEDENT ret = min ( ret , rec ( lastV , idx + 1 , D , I , M , val , dp ) + D ) NEW_LINE if lastV == 256 : NEW_LINE INDENT for i in range ( 0 , 256 ) : NEW_LINE INDENT ret = min ( ret , rec ( i , idx + 1 , D , I , M , val , dp ) + abs ( val [ idx ] - i ) ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 0 , 256 ) : NEW_LINE INDENT if abs ( lastV - i ) <= M : NEW_LINE INDENT ret = min ( ret , rec ( i , idx + 1 , D , I , M , val , dp ) + abs ( val [ idx ] - i ) ) NEW_LINE DEDENT DEDENT DEDENT dp [ lastV ] [ idx ] = ret NEW_LINE return ret NEW_LINE DEDENT def work ( cases , ( D , I , M , val ) ) : NEW_LINE INDENT dp = [ [ - 1 for j in range ( len ( val ) ) ] for i in range ( 257 ) ] NEW_LINE print " Case ▁ # % d : ▁ % d " % ( cases , rec ( 256 , 0 , D , I , M , val , dp ) ) NEW_LINE DEDENT for i in range ( int ( raw_input ( ) ) ) : NEW_LINE INDENT work ( i + 1 , read ( ) ) NEW_LINE DEDENT


import java . util . * ; public class C { public static void main ( String args [ ] ) { ( new C ( ) ) . exec ( ) ; } void exec ( ) { Scanner cin = new Scanner ( System . in ) ; int t = cin . nextInt ( ) ; for ( int z = 0 ; z < t ; ++ z ) { int k = cin . nextInt ( ) ; int value [ ] = new int [ k ] ; boolean used [ ] = new boolean [ k ] ; int count = 0 ; int cur = 0 ; while ( count < k ) { for ( int i = 0 ; i < k ; ++ i ) { if ( used [ i ] ) { continue ; } if ( cur == count ) { value [ i ] = ++ count ; cur = 0 ; used [ i ] = true ; } else { ++ cur ; } } } System . out . print ( " Case ▁ # " + ( z + 1 ) + " : " ) ; int n = cin . nextInt ( ) ; for ( int i = 0 ; i < n ; ++ i ) { System . out . print ( " ▁ " + value [ cin . nextInt ( ) - 1 ] ) ; } System . out . println ( ) ; } } }

import java . io . * ; import java . util . * ; public class TaskC implements Runnable { private String IFILE = " C - large . in " ; private Scanner in ; private PrintWriter out ; public void Run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( " output . txt " ) ; int ntest = in . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { out . print ( " Case ▁ # " + test + " : " ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int [ ] mas = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { int v = in . nextInt ( ) - 1 ; int count = n ; for ( int j = 0 ; j < n ; j ++ ) { int pos = j % count ; if ( pos == v ) { out . print ( " ▁ " + ( j + 1 ) ) ; break ; } if ( pos > v ) { v += count - pos - 1 ; } else { v = v - pos - 1 ; } count -- ; } } out . println ( ) ; } in . close ( ) ; out . close ( ) ; } public void run ( ) { try { Run ( ) ; } catch ( IOException e ) { } } public static void main ( String [ ] args ) throws IOException { new TaskC ( ) . Run ( ) ; } }

package common ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; public class Helper { public static String [ ] getAllFileContentAsArray ( String filename ) throws Exception { BufferedReader in = new BufferedReader ( new FileReader ( filename ) ) ; List < String > all = new ArrayList < String > ( ) ; String s = in . readLine ( ) ; while ( s != null ) { all . add ( s ) ; s = in . readLine ( ) ; } in . close ( ) ; return all . toArray ( new String [ 0 ] ) ; } public static void writeToFile ( String [ ] cont , String filename ) throws Exception { File file = new File ( filename ) ; file . delete ( ) ; FileWriter w = null ; try { w = new FileWriter ( file , true ) ; for ( String s : cont ) { w . write ( s + " \n " ) ; } } finally { if ( w != null ) { w . close ( ) ; } } } public static int [ ] getIntegersFromString ( String s ) throws Exception { List < Integer > a = new ArrayList < Integer > ( ) ; for ( String se : s . split ( " ▁ " ) ) { try { Integer x = Integer . parseInt ( se ) ; a . add ( x ) ; } catch ( Exception e ) { } } int [ ] ret = new int [ a . size ( ) ] ; for ( int i = 0 ; i < a . size ( ) ; ++ i ) { ret [ i ] = a . get ( i ) . intValue ( ) ; } return ret ; } private Helper ( ) { } }

import java . io . * ; import java . util . * ; public class C { public static void main ( String args [ ] ) throws IOException { new C ( ) . solve ( ) ; } void solve ( ) throws IOException { br = new BufferedReader ( new FileReader ( " C - small - attempt0 . in " ) ) ; pw = new PrintWriter ( " C - small . out " ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int c = 1 ; c <= T ; ++ c ) { System . out . println ( c ) ; int K = Integer . parseInt ( br . readLine ( ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { d [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; } int [ ] v = new int [ K ] ; int s = 0 ; for ( int k = 1 ; k <= K ; ++ k ) { for ( int p = 1 ; p < k ; ++ p ) { s ++ ; if ( s == K ) s = 0 ; while ( v [ s ] != 0 ) { s ++ ; if ( s == K ) s = 0 ; } } v [ s ] = k ; if ( k < K ) { s ++ ; if ( s == K ) s = 0 ; while ( v [ s ] != 0 ) { s ++ ; if ( s == K ) s = 0 ; } } } pw . print ( " Case ▁ # " + c + " : " ) ; for ( int i = 0 ; i < n ; ++ i ) { pw . print ( " ▁ " + v [ d [ i ] - 1 ] ) ; } pw . println ( ) ; } pw . close ( ) ; } BufferedReader br ; PrintWriter pw ; }

import java . util . * ; public class CSmall { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= T ; caseID ++ ) { int K = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] ds = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ds [ i ] = sc . nextInt ( ) ; } boolean [ ] visited = new boolean [ K ] ; int [ ] cards = new int [ K ] ; int iter = 0 ; for ( int i = 1 ; i <= K ; i ++ ) { int cnt = 0 ; int next = ( i - 1 ) % ( K - i + 1 ) ; while ( true ) { if ( iter == K ) iter = 0 ; if ( ! visited [ iter ] ) { if ( cnt == next ) { visited [ iter ] = true ; cards [ iter ] = i ; cnt ++ ; iter ++ ; break ; } else { cnt ++ ; iter ++ ; } } else { iter ++ ; } } } System . out . printf ( " Case ▁ # % d : " , caseID ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . printf ( " ▁ % d " , cards [ ds [ i ] - 1 ] ) ; } System . out . printf ( " % n " ) ; } } }

import sys NEW_LINE def readdata ( ) : NEW_LINE INDENT def rl ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) . strip ( ) . split ( ' ▁ ' ) NEW_LINE DEDENT n = int ( rl ( ) [ 0 ] ) NEW_LINE cases = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT K = int ( rl ( ) [ 0 ] ) NEW_LINE il = [ int ( x ) for x in rl ( ) ] NEW_LINE case = ( K , il [ 1 : il [ 0 ] + 1 ] ) NEW_LINE cases . append ( case ) NEW_LINE DEDENT return cases NEW_LINE DEDENT case_number = 1 NEW_LINE for case in readdata ( ) : NEW_LINE INDENT sc = case [ 0 ] NEW_LINE si = range ( sc ) NEW_LINE sv = [ 0 ] * sc NEW_LINE cv = 1 NEW_LINE ci = 0 NEW_LINE for z in xrange ( sc ) : NEW_LINE INDENT ci += z NEW_LINE ci = ci % len ( si ) NEW_LINE sv [ si [ ci ] ] = z + 1 NEW_LINE si . remove ( si [ ci ] ) NEW_LINE DEDENT print ' Case ▁ # ' + str ( case_number ) + ' : ' , ' ▁ ' . join ( [ str ( sv [ x - 1 ] ) for x in case [ 1 ] ] ) NEW_LINE case_number += 1 NEW_LINE DEDENT

inp_file = file ( " C - small . in " ) NEW_LINE out_file = file ( " C - small . out " , " w " ) NEW_LINE def solve ( line ) : NEW_LINE INDENT line = [ int ( c1 ) for c1 in line . split ( " ▁ " ) ] NEW_LINE card_num , indices = line [ : 2 ] NEW_LINE line = line [ 2 : ] NEW_LINE positions = range ( card_num ) NEW_LINE result = [ 0 for c1 in range ( card_num ) ] NEW_LINE c1 = 1 NEW_LINE c2 = 0 NEW_LINE while c1 < card_num : NEW_LINE INDENT result [ positions [ c2 ] ] = c1 NEW_LINE positions . pop ( c2 ) NEW_LINE c2 = ( c2 + c1 ) % len ( positions ) NEW_LINE c1 += 1 NEW_LINE DEDENT result [ result . index ( 0 ) ] = card_num NEW_LINE return " ▁ " . join ( [ str ( result [ c1 - 1 ] ) for c1 in line ] ) NEW_LINE DEDENT num = int ( inp_file . readline ( ) ) NEW_LINE for case in range ( num ) : NEW_LINE INDENT line = inp_file . readline ( ) [ : - 1 ] + " ▁ " + inp_file . readline ( ) [ : - 1 ] NEW_LINE out_file . write ( " Case ▁ # % s : ▁ " % ( case + 1 ) + solve ( line ) + " \n " ) NEW_LINE DEDENT inp_file . close ( ) NEW_LINE out_file . close ( ) NEW_LINE

import sys NEW_LINE filename = sys . argv [ 1 ] NEW_LINE inputfile = file ( filename , ' r ' ) NEW_LINE numcases = int ( inputfile . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , numcases + 1 ) : NEW_LINE INDENT K = int ( inputfile . readline ( ) . strip ( ) ) NEW_LINE data = map ( int , inputfile . readline ( ) . strip ( ) . split ( " ▁ " ) ) NEW_LINE n = data [ 0 ] NEW_LINE dis = data [ 1 : ] NEW_LINE cards = range ( K ) NEW_LINE remainingcards = range ( K ) NEW_LINE remainingcardpos = 0 NEW_LINE for cardvalue in range ( K ) : NEW_LINE INDENT remainingcardpos = ( cardvalue + remainingcardpos ) % len ( remainingcards ) NEW_LINE card = remainingcards [ remainingcardpos ] NEW_LINE cards [ card ] = cardvalue + 1 NEW_LINE del remainingcards [ remainingcardpos ] NEW_LINE DEDENT sys . stdout . write ( " Case ▁ # % d : " % case ) NEW_LINE for di in dis : NEW_LINE INDENT sys . stdout . write ( " ▁ % d " % cards [ di - 1 ] ) NEW_LINE DEDENT sys . stdout . write ( " \n " ) NEW_LINE DEDENT

import sys , itertools NEW_LINE data = filter ( None , map ( lambda x : x . strip ( ) , open ( sys . argv [ 1 ] ) . readlines ( ) ) ) NEW_LINE def pop_int ( data ) : NEW_LINE INDENT return int ( data . pop ( 0 ) ) NEW_LINE DEDENT def pop_ints ( data ) : NEW_LINE INDENT return map ( int , data . pop ( 0 ) . split ( ) ) NEW_LINE DEDENT def pop_rows ( data , num_rows ) : NEW_LINE INDENT result = data [ : num_rows ] NEW_LINE for i in range ( num_rows ) : NEW_LINE INDENT data . pop ( 0 ) NEW_LINE DEDENT return result NEW_LINE DEDENT def pop_case ( data ) : NEW_LINE INDENT num_cards = pop_int ( data ) NEW_LINE indices = pop_ints ( data ) [ 1 : ] NEW_LINE return num_cards , indices NEW_LINE DEDENT def make_deck ( num_cards ) : NEW_LINE INDENT deck = [ None for i in range ( num_cards ) ] NEW_LINE indices_open = range ( num_cards ) NEW_LINE last_ii = 0 NEW_LINE for i in range ( 1 , num_cards + 1 ) : NEW_LINE INDENT last_ii = index_index = ( i + last_ii - 1 ) % len ( indices_open ) NEW_LINE position = indices_open [ index_index ] NEW_LINE assert ( deck [ position ] is None ) NEW_LINE deck [ position ] = i NEW_LINE indices_open . remove ( position ) NEW_LINE DEDENT return deck NEW_LINE DEDENT def solve ( num_cards , indices ) : NEW_LINE INDENT solution = make_deck ( num_cards ) NEW_LINE answer = ' ▁ ' . join ( str ( solution [ i - 1 ] ) for i in indices ) NEW_LINE return answer NEW_LINE DEDENT num_cases = pop_int ( data ) NEW_LINE for case_num in range ( 1 , num_cases + 1 ) : NEW_LINE INDENT num_cards , indices = pop_case ( data ) NEW_LINE answer = solve ( num_cards , indices ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( case_num , answer ) NEW_LINE DEDENT

case = " small - attempt0" NEW_LINE input_file = " C - % s . in " % case NEW_LINE output_file = " C - % s . out " % case NEW_LINE fin = open ( input_file ) NEW_LINE fout = open ( output_file , " w " ) NEW_LINE ncase = int ( fin . readline ( ) . strip ( ) ) NEW_LINE for z in xrange ( 1 , ncase + 1 ) : NEW_LINE INDENT print >> fout , " Case ▁ # % d : " % z , NEW_LINE k = int ( fin . readline ( ) . strip ( ) ) NEW_LINE d = [ int ( x ) - 1 for x in fin . readline ( ) . strip ( ) . split ( ) [ 1 : ] ] NEW_LINE for dd in d : NEW_LINE INDENT n , p , r , i = k , dd , 0 , 1 NEW_LINE while p != r : NEW_LINE INDENT n -= 1 NEW_LINE if p > r : NEW_LINE INDENT p -= 1 NEW_LINE DEDENT r = ( r + i ) % n NEW_LINE i += 1 NEW_LINE DEDENT print >> fout , i , NEW_LINE DEDENT print >> fout NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE


import java . util . * ; import java . io . * ; public class x { static class Pt implements Comparable < Pt > { int x , y , z ; Pt ( int xx , int yy , int zz ) { x = xx ; y = yy ; z = zz ; } ; public int compareTo ( Pt a ) { if ( y != a . y ) return y - a . y ; if ( x != a . x ) return x - a . x ; if ( z != a . z ) return z - a . z ; return 0 ; } ; } ; public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int tcnt = in . nextInt ( ) ; for ( int i = 1 ; i <= tcnt ; i ++ ) { int n = in . nextInt ( ) ; Pt [ ] p = new Pt [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; p [ j ] = new Pt ( a , b , c ) ; } ; Arrays . sort ( p ) ; int mx = 0 ; for ( int x = 0 ; x <= 10000 ; x ++ ) { int [ ] T = new int [ 10002 ] ; for ( int j = 0 ; j < n ; j ++ ) { if ( p [ j ] . x <= x ) { int z = 10000 - p [ j ] . y - x ; for ( int k = 1 + p [ j ] . z ; k <= 10001 ; k += k & - k ) T [ k ] ++ ; if ( z >= 0 ) { int sum = 0 ; for ( int k = 1 + Math . max ( 0 , z ) ; k > 0 ; k -= k & - k ) sum += T [ k ] ; mx = Math . max ( mx , sum ) ; } ; } ; } ; } ; out . println ( " Case ▁ # " + i + " : ▁ " + mx ) ; } ; out . close ( ) ; } ; } ;

import java . io . * ; import java . util . * ; public class Main { Scanner in ; PrintWriter out ; public void solve ( ) throws Exception { int n = in . nextInt ( ) ; int [ ] x = new int [ n ] ; int [ ] y = new int [ n ] ; int [ ] z = new int [ n ] ; int M = 10000 ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = in . nextInt ( ) ; y [ i ] = in . nextInt ( ) ; z [ i ] = in . nextInt ( ) ; } int [ ] k = new int [ M + 2 ] ; int best = 0 ; for ( int u = 0 ; u <= M ; u ++ ) { Arrays . fill ( k , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) if ( x [ i ] <= u ) if ( y [ i ] <= M - u - z [ i ] + 1 ) { k [ y [ i ] ] ++ ; k [ M - u - z [ i ] + 1 ] -- ; } int bb = 0 ; int b = 0 ; for ( int i = 0 ; i <= M ; i ++ ) { bb += k [ i ] ; if ( b < bb ) b = bb ; } if ( best < b ) { best = b ; } } out . println ( best ) ; } public void run ( ) throws Exception { in = new Scanner ( new File ( " input . txt " ) ) ; out = new PrintWriter ( new FileWriter ( new File ( " output . txt " ) ) ) ; int _ = in . nextInt ( ) ; for ( int __ = 0 ; __ < _ ; __ ++ ) { out . print ( " Case ▁ # " + ( __ + 1 ) + " : ▁ " ) ; solve ( ) ; } } public void close ( ) { out . close ( ) ; } public static void main ( String [ ] args ) { new Thread ( ) { public void run ( ) { try { Main a = new Main ( ) ; a . run ( ) ; a . close ( ) ; } catch ( Exception E ) { throw new RuntimeException ( E ) ; } } } . start ( ) ; } }

import java . util . * ; import java . io . * ; import java . math . * ; import static java . lang . Math . * ; public class A { static final int TOTAL = 10000 ; static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int caseNum = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseNum ; caseID ++ ) { new A ( ) . solveDataSet ( caseID ) ; } } int N ; ArrayList < Int3D > [ ] x2Points ; void solveDataSet ( int caseID ) { N = sc . nextInt ( ) ; x2Points = ( ArrayList < Int3D > [ ] ) ( new ArrayList < ? > [ TOTAL + 1 ] ) ; for ( int x = 0 ; x <= TOTAL ; x ++ ) { x2Points [ x ] = new ArrayList < Int3D > ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int z = sc . nextInt ( ) ; x2Points [ x ] . add ( new Int3D ( x , y , z ) ) ; } int ans = 0 ; for ( int z = 0 ; z <= TOTAL ; z ++ ) { int cnt = 0 ; int [ ] yCnt = new int [ TOTAL - z + 1 ] ; for ( int x = 0 ; x <= TOTAL - z ; x ++ ) { if ( x > 0 ) { cnt -= yCnt [ TOTAL - z - ( x - 1 ) ] ; } for ( Int3D p : x2Points [ x ] ) { if ( p . z <= z && p . y <= TOTAL - z - x ) { yCnt [ p . y ] ++ ; cnt ++ ; } } ans = Math . max ( cnt , ans ) ; } } System . err . printf ( " Case ▁ # % d : % n " , caseID ) ; System . out . printf ( " Case ▁ # % d : ▁ % d % n " , caseID , ans ) ; } } class Int3D { int x , y , z ; public Int3D ( int x , int y , int z ) { super ( ) ; this . x = x ; this . y = y ; this . z = z ; } }

import java . util . * ; import java . io . * ; import java . math . * ; public class A { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new InputStreamReader ( System . in ) ) ; int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int N = sc . nextInt ( ) ; int [ ] [ ] nums = new int [ N ] [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) nums [ i ] [ j ] = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { Vector < Integer > low = new Vector < Integer > ( ) ; Vector < Integer > high = new Vector < Integer > ( ) ; int cur = 0 ; int A = nums [ i ] [ 0 ] ; for ( int j = 0 ; j < N ; j ++ ) { if ( A < nums [ j ] [ 0 ] ) continue ; if ( nums [ j ] [ 1 ] <= 10000 - A - nums [ j ] [ 2 ] ) { low . add ( nums [ j ] [ 1 ] ) ; high . add ( 10000 - A - nums [ j ] [ 2 ] ) ; } } if ( low . size ( ) == 0 ) continue ; Collections . sort ( low ) ; Collections . sort ( high ) ; int lc = 0 , hc = 0 , lcur = low . get ( 0 ) , hcur = high . get ( 0 ) ; while ( lc < low . size ( ) ) { if ( lcur <= hcur ) { cur ++ ; ans = Math . max ( ans , cur ) ; lc ++ ; if ( lc < low . size ( ) ) lcur = low . get ( lc ) ; } else { cur -- ; hc ++ ; if ( hc < high . size ( ) ) hcur = high . get ( hc ) ; } } } System . out . println ( " Case ▁ # " + t + " : ▁ " + ans ) ; } } }

import sys NEW_LINE def isset ( n , i ) : return ( n >> i ) & 1 != 0 NEW_LINE def dbg ( a ) : sys . stderr . write ( str ( a ) ) NEW_LINE def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readfloat ( ) : return float ( raw_input ( ) ) NEW_LINE def readarray ( foo ) : return map ( foo , raw_input ( ) . split ( ) ) NEW_LINE for test in range ( readint ( ) ) : NEW_LINE INDENT dbg ( " Test ▁ % d \n " % ( test + 1 ) ) NEW_LINE n = readint ( ) NEW_LINE data = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT ( a , b , c ) = readarray ( int ) NEW_LINE data . append ( ( a , b , c ) ) NEW_LINE DEDENT res = 0 NEW_LINE for A in xrange ( 10001 ) : NEW_LINE INDENT q = [ ] NEW_LINE for ( a , b , c ) in data : NEW_LINE INDENT if ( a > A ) : continue NEW_LINE if ( A + b > 10000 ) : continue NEW_LINE minb = b NEW_LINE maxb = 10000 - A - c NEW_LINE if ( maxb < minb ) : continue NEW_LINE q . append ( ( minb , 0 ) ) NEW_LINE q . append ( ( maxb , 1 ) ) NEW_LINE DEDENT q . sort ( ) NEW_LINE r = 0 NEW_LINE for ( t , d ) in q : NEW_LINE INDENT if d == 0 : NEW_LINE INDENT r += 1 NEW_LINE res = max ( res , r ) NEW_LINE DEDENT else : NEW_LINE INDENT r -= 1 NEW_LINE DEDENT DEDENT DEDENT print " Case ▁ # % d : ▁ % d " % ( test + 1 , res ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class A { static int calc ( int [ ] q ) { int res = 1234567 ; for ( int a = 0 ; a <= 100 ; a ++ ) { int cur = 0 ; for ( int i = 0 ; i < q . length ; i ++ ) cur += Math . abs ( q [ i ] - a ) ; res = Math . min ( res , cur ) ; } return res ; } public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int numTests = sc . nextInt ( ) ; for ( int test = 1 ; test <= numTests ; test ++ ) { int n = sc . nextInt ( ) ; String must = " " ; int [ ] [ ] q = new int [ 111 ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) + " ? " ; String t = " " ; int ind = 0 ; char c = ' ? ' ; int cnt = 1 ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( j ) == c ) cnt ++ ; else { t += c ; q [ ind ] [ i ] = cnt ; cnt = 0 ; ind ++ ; c = s . charAt ( j ) ; } } if ( i == 0 ) must = t ; else if ( ! must . equals ( t ) ) must = " ? " ; } String lost = " Fegla ▁ Won " ; if ( must . equals ( " ? " ) ) { System . out . println ( " Case ▁ # " + test + " : ▁ " + lost ) ; } else { int res = 0 ; for ( int i = 0 ; i < 111 ; i ++ ) res += calc ( q [ i ] ) ; System . out . println ( " Case ▁ # " + test + " : ▁ " + res ) ; } } } }

import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . printf ( " Case ▁ # % d : ▁ % s \n " , i , solve ( ) ) ; } } static String solve ( ) { int N = sc . nextInt ( ) ; String [ ] str = new String [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { str [ i ] = sc . next ( ) ; } int [ ] [ ] count = new int [ N ] [ 101 ] ; int [ ] pos = new int [ N ] ; for ( int i = 0 ; pos [ 0 ] < str [ 0 ] . length ( ) ; ++ i ) { char c = str [ 0 ] . charAt ( pos [ 0 ] ) ; for ( int j = 0 ; j < N ; ++ j ) { if ( pos [ j ] >= str [ j ] . length ( ) || str [ j ] . charAt ( pos [ j ] ) != c ) { return " Fegla ▁ Won " ; } while ( pos [ j ] < str [ j ] . length ( ) && str [ j ] . charAt ( pos [ j ] ) == c ) { ++ pos [ j ] ; ++ count [ j ] [ i ] ; } } } for ( int i = 0 ; i < N ; ++ i ) { if ( pos [ i ] != str [ i ] . length ( ) ) { return " Fegla ▁ Won " ; } } int ans = 0 ; for ( int i = 0 ; count [ 0 ] [ i ] > 0 ; ++ i ) { int min = 1 << 30 ; for ( int j = 1 ; j <= 100 ; ++ j ) { int sum = 0 ; for ( int k = 0 ; k < N ; ++ k ) { sum += Math . abs ( count [ k ] [ i ] - j ) ; } min = Math . min ( min , sum ) ; } ans += min ; } return " " + ans ; } }

import sys NEW_LINE from itertools import zip_longest as zip NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE def cost ( v ) : NEW_LINE INDENT v . sort ( ) NEW_LINE m = v [ len ( v ) // 2 ] NEW_LINE return sum ( abs ( i - m ) for i in v ) NEW_LINE DEDENT def partition ( s ) : NEW_LINE INDENT i = 0 NEW_LINE while i < len ( s ) : NEW_LINE INDENT j = i + 1 NEW_LINE while j < len ( s ) and s [ i ] == s [ j ] : NEW_LINE INDENT j += 1 NEW_LINE DEDENT yield ( s [ i ] , j - i ) NEW_LINE i = j NEW_LINE DEDENT DEDENT for t in range ( T ) : NEW_LINE INDENT N = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE ss = list ( sys . stdin . readline ( ) . strip ( ) for _ in range ( N ) ) NEW_LINE res = 0 NEW_LINE for items in zip ( * list ( partition ( s ) for s in ss ) ) : NEW_LINE INDENT if any ( i is None for i in items ) : NEW_LINE INDENT print ( " Case ▁ # % d : ▁ Fegla ▁ Won " % ( t + 1 ) ) NEW_LINE break NEW_LINE DEDENT if any ( a != items [ 0 ] [ 0 ] for a , _ in items [ 1 : ] ) : NEW_LINE INDENT print ( " Case ▁ # % d : ▁ Fegla ▁ Won " % ( t + 1 ) ) NEW_LINE break NEW_LINE DEDENT res += cost ( list ( b for _ , b in items ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Case ▁ # % d : ▁ % d " % ( t + 1 , res ) ) NEW_LINE DEDENT DEDENT

T = input ( ) NEW_LINE def encode ( input_string ) : NEW_LINE INDENT count = 1 NEW_LINE prev = ' ' NEW_LINE lst = [ ] NEW_LINE for character in input_string : NEW_LINE INDENT if character != prev : NEW_LINE INDENT if prev : NEW_LINE INDENT entry = ( prev , count ) NEW_LINE lst . append ( entry ) NEW_LINE DEDENT count = 1 NEW_LINE prev = character NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT entry = ( character , count ) NEW_LINE lst . append ( entry ) NEW_LINE DEDENT return lst NEW_LINE DEDENT def moves ( l ) : NEW_LINE INDENT m = 100000000 NEW_LINE for i in range ( 200 ) : NEW_LINE INDENT m = min ( m , sum ( abs ( x - i ) for x in l ) ) NEW_LINE DEDENT return m NEW_LINE DEDENT for case in range ( 1 , T + 1 ) : NEW_LINE INDENT N = input ( ) NEW_LINE strs = [ raw_input ( ) for i in range ( N ) ] NEW_LINE uniq = set ( ' ' . join ( x [ 0 ] for x in encode ( s ) ) for s in strs ) NEW_LINE enc = [ [ x [ 1 ] for x in encode ( s ) ] for s in strs ] NEW_LINE ans = ' Fegla ▁ Won ' NEW_LINE if len ( uniq ) == 1 : NEW_LINE INDENT bypos = [ [ l [ i ] for l in enc ] for i in range ( len ( enc [ 0 ] ) ) ] NEW_LINE ans = sum ( moves ( l ) for l in bypos ) NEW_LINE DEDENT print " Case ▁ # % d : " % case , ans NEW_LINE DEDENT

file_in = open ( ' a . in ' , ' r ' ) NEW_LINE file_out = open ( ' a . out ' , ' w ' ) NEW_LINE n_case = int ( file_in . readline ( ) ) NEW_LINE class Word : NEW_LINE INDENT def __init__ ( self , s ) : NEW_LINE INDENT char = '0' NEW_LINE self . chars = [ ] NEW_LINE self . counts = [ ] NEW_LINE for c in s : NEW_LINE INDENT if c != char : NEW_LINE INDENT self . chars . append ( c ) NEW_LINE self . counts . append ( 1 ) NEW_LINE char = c NEW_LINE DEDENT else : NEW_LINE INDENT self . counts [ - 1 ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT for i_case in range ( n_case ) : NEW_LINE INDENT N = int ( file_in . readline ( ) ) NEW_LINE words = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT words . append ( Word ( file_in . readline ( ) . strip ( ) ) ) NEW_LINE DEDENT chars = words [ 0 ] . chars NEW_LINE def check_equal ( ) : NEW_LINE INDENT for word in words : NEW_LINE INDENT if word . chars != chars : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if not check_equal ( ) : NEW_LINE INDENT file_out . write ( " Case ▁ # % d : ▁ % s \n " % ( i_case + 1 , " Fegla ▁ Won " ) ) NEW_LINE continue NEW_LINE DEDENT def median ( arr ) : NEW_LINE INDENT s = sorted ( arr ) NEW_LINE return s [ len ( s ) / 2 ] NEW_LINE DEDENT def actions_needed ( arr ) : NEW_LINE INDENT count = 0 NEW_LINE med = median ( arr ) NEW_LINE for a in arr : NEW_LINE INDENT count += abs ( med - a ) NEW_LINE DEDENT return count NEW_LINE DEDENT actions = 0 NEW_LINE for i_char in range ( len ( chars ) ) : NEW_LINE INDENT arr = [ ] NEW_LINE for word in words : NEW_LINE INDENT arr . append ( word . counts [ i_char ] ) NEW_LINE DEDENT actions += actions_needed ( arr ) NEW_LINE DEDENT file_out . write ( " Case ▁ # % d : ▁ % s \n " % ( i_case + 1 , str ( actions ) ) ) NEW_LINE DEDENT file_in . close ( ) NEW_LINE file_out . close ( ) NEW_LINE

import sys NEW_LINE infile = None NEW_LINE outfile = None NEW_LINE def readline ( ) : NEW_LINE INDENT x = infile . readline ( ) NEW_LINE if len ( x ) > 0 : NEW_LINE INDENT return x [ : - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return x NEW_LINE DEDENT DEDENT def readint ( ) : NEW_LINE INDENT return int ( readline ( ) ) NEW_LINE DEDENT def readfloat ( ) : NEW_LINE INDENT return float ( readline ( ) ) NEW_LINE DEDENT def readints ( ) : NEW_LINE INDENT xs = readline ( ) . split ( ) NEW_LINE return [ int ( x ) for x in xs ] NEW_LINE DEDENT def readfloats ( ) : NEW_LINE INDENT xs = readline ( ) . split ( ) NEW_LINE return [ float ( x ) for x in xs ] NEW_LINE DEDENT def writeline ( x ) : NEW_LINE INDENT outfile . write ( x + ' \n ' ) NEW_LINE DEDENT def run ( main ) : NEW_LINE INDENT global infile , outfile NEW_LINE args = sys . argv NEW_LINE if len ( args ) == 1 : NEW_LINE INDENT infile = sys . stdin NEW_LINE outfile = sys . stdout NEW_LINE DEDENT elif len ( args ) == 2 : NEW_LINE INDENT if args [ 1 ] == ' - ' : NEW_LINE INDENT infile = sys . stdin NEW_LINE DEDENT else : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE DEDENT if args [ 1 ] . endswith ( ' . in ' ) : NEW_LINE INDENT outfile = open ( args [ 1 ] [ : - 3 ] + ' . out ' , ' w ' ) NEW_LINE DEDENT else : NEW_LINE INDENT outfile = sys . stdout NEW_LINE DEDENT DEDENT elif len ( args ) == 3 : NEW_LINE INDENT if args [ 1 ] == ' - ' : NEW_LINE INDENT infile = sys . stdin NEW_LINE DEDENT else : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE DEDENT if args [ 2 ] == ' - ' : NEW_LINE INDENT outfile = sys . stdout NEW_LINE DEDENT else : NEW_LINE INDENT outfile = open ( args [ 2 ] , ' w ' ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " Expected ▁ 0 , ▁ 1 , ▁ or ▁ 2 ▁ args , ▁ not ▁ { : d } " . format ( len ( args ) - 1 ) ) NEW_LINE print ( args ) NEW_LINE return NEW_LINE DEDENT t = readint ( ) NEW_LINE for casenum in range ( 1 , t + 1 ) : NEW_LINE INDENT main ( casenum ) NEW_LINE DEDENT if infile is not sys . stdin : NEW_LINE INDENT infile . close ( ) NEW_LINE DEDENT if outfile is not sys . stdout : NEW_LINE INDENT outfile . close ( ) NEW_LINE DEDENT DEDENT

def minify ( s ) : NEW_LINE INDENT r = " " NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i == 0 or s [ i - 1 ] != s [ i ] : NEW_LINE INDENT r += s [ i ] NEW_LINE DEDENT DEDENT return r NEW_LINE DEDENT def toarray ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i == 0 or s [ i - 1 ] != s [ i ] : NEW_LINE INDENT a += [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT a [ - 1 ] += 1 NEW_LINE DEDENT DEDENT return a NEW_LINE DEDENT def solve ( S ) : NEW_LINE INDENT if len ( set ( minify ( s ) for s in S ) ) > 1 : NEW_LINE INDENT return " Fegla ▁ Won " NEW_LINE DEDENT A = [ toarray ( s ) for s in S ] NEW_LINE ans = 0 NEW_LINE for p in range ( len ( A [ 0 ] ) ) : NEW_LINE INDENT a = 99999999 NEW_LINE for x in range ( min ( a [ p ] for a in A ) , max ( a [ p ] for a in A ) + 1 ) : NEW_LINE INDENT a = min ( a , sum ( abs ( a [ p ] - x ) for a in A ) ) NEW_LINE DEDENT ans += a NEW_LINE DEDENT return ans NEW_LINE DEDENT for i in range ( input ( ) ) : NEW_LINE INDENT N = input ( ) NEW_LINE S = [ raw_input ( ) for _ in range ( N ) ] NEW_LINE a = solve ( S ) NEW_LINE print " Case ▁ # % s : ▁ % s " % ( i + 1 , a ) NEW_LINE DEDENT


package code10 . qualification ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; public class A { public static String solve ( int N , long K , int [ ] times ) { String result = " " ; int time = times [ N ] ; if ( K < time ) { result = " OFF " ; } else if ( K == time ) { result = " ON " ; } else { long remain = K - time ; if ( remain % ( time + 1 ) == 0 ) { result = " ON " ; } else { result = " OFF " ; } } return result ; } public static void initTimes ( int [ ] times ) { times [ 1 ] = 1 ; for ( int i = 2 ; i < times . length ; i ++ ) { times [ i ] = times [ i - 1 ] * 2 + 1 ; } } public static void main ( String [ ] args ) throws Exception { String fileName = " A - large " ; File inputFile = new File ( fileName + " . in " ) ; File outputFile = new File ( fileName + " . out " ) ; FileReader reader = new FileReader ( inputFile ) ; FileWriter writer = new FileWriter ( outputFile ) ; StringBuilder inputLine = new StringBuilder ( ) ; String [ ] inputPart ; int totalCase ; char c = 0 ; int N = 0 ; long K = 0 ; int [ ] times = new int [ 31 ] ; initTimes ( times ) ; while ( ( c = ( char ) reader . read ( ) ) != ' \n ' ) { inputLine . append ( c ) ; } totalCase = Integer . parseInt ( inputLine . toString ( ) ) ; for ( int caseIndex = 1 ; caseIndex <= totalCase ; caseIndex ++ ) { inputLine = new StringBuilder ( ) ; while ( ( c = ( char ) reader . read ( ) ) != ' \n ' ) { inputLine . append ( c ) ; } inputPart = inputLine . toString ( ) . split ( " ▁ " ) ; N = Integer . parseInt ( inputPart [ 0 ] ) ; K = Long . parseLong ( inputPart [ 1 ] ) ; String output = " Case ▁ # " + caseIndex + " : ▁ " + solve ( N , K , times ) ; System . out . println ( output ) ; writer . write ( output + " \n " ) ; } reader . close ( ) ; writer . close ( ) ; } }

import java . io . * ; import java . util . * ; import java . text . * ; public class SnapperChain { public PrintStream out = System . out ; public PrintStream err = System . err ; public Scanner in = new Scanner ( System . in ) ; public DecimalFormat fmt = new DecimalFormat ( "0.000000000" ) ; public void main ( ) { try { int TCase , cc ; TCase = in . nextInt ( ) ; for ( cc = 1 ; cc <= TCase ; ++ cc ) { long n , K , L ; n = in . nextLong ( ) ; K = in . nextLong ( ) ; L = ( 1L << n ) ; out . println ( " Case ▁ # " + cc + " : ▁ " + ( ( K % ( L ) == ( L ) - 1 ) ? " ON " : " OFF " ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } public int iInt ( ) { return in . nextInt ( ) ; } public long iLong ( ) { return in . nextLong ( ) ; } public String iToken ( ) { return in . next ( ) ; } public String iLine ( ) { return in . nextLine ( ) ; } public static void main ( String [ ] args ) { long startTime = System . currentTimeMillis ( ) ; ( new SnapperChain ( ) ) . main ( ) ; long endTime = System . currentTimeMillis ( ) ; long ms = endTime - startTime ; long sec = ms / 1000 ; ms = ms % 1000 ; long min = sec / 60 ; sec = sec % 60 ; System . err . println ( " Time ▁ Spent : ▁ " + min + " ▁ minute ( s ) ▁ " + sec + " ▁ second ( s ) ▁ " + ms + " ▁ ( ms ) " ) ; } }

import java . util . * ; import java . io . * ; public class AChain { public static void main ( String [ ] args ) { if ( args . length < 1 ) { System . out . println ( " Usage : ▁ < fnIn > " ) ; } String fn = args [ 0 ] ; String fnOut = toFnOut ( fn ) ; try { BufferedReader br = new BufferedReader ( new FileReader ( fn ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( fnOut ) ) ; String line = null ; int NCase = Integer . valueOf ( br . readLine ( ) . trim ( ) ) ; long stime = System . currentTimeMillis ( ) ; for ( int icase = 0 ; icase < NCase ; icase ++ ) { int [ ] a = toIntArray ( br . readLine ( ) ) ; String buf = process ( a [ 0 ] , a [ 1 ] ) ; String out = " Case ▁ # " + ( icase + 1 ) + " : ▁ " + buf ; bw . write ( out , 0 , out . length ( ) ) ; bw . newLine ( ) ; long ctime = System . currentTimeMillis ( ) ; System . out . println ( String . format ( " - - - ▁ Done : ▁ # %2d , %3.0fs , ▁ ends ▁ in : %2.1fm " , ( icase + 1 ) , ( ctime - stime ) * 0.001 , ( ctime - stime ) * 0.001 / 60 * NCase / ( icase + 1 ) ) ) ; } br . close ( ) ; bw . close ( ) ; } catch ( IOException ex ) { System . out . println ( ex ) ; } } static String process ( int N , int K ) { int x = ( 1 << N ) ; while ( K >= x ) { K %= x ; } if ( K == x - 1 ) return " ON " ; return " OFF " ; } static int [ ] toIntArray ( String line ) { String [ ] p = line . trim ( ) . split ( " \\ s + " ) ; int [ ] out = new int [ p . length ] ; for ( int i = 0 ; i < out . length ; i ++ ) out [ i ] = Integer . valueOf ( p [ i ] ) ; return out ; } static String toFnOut ( String fn ) { if ( fn . lastIndexOf ( ' . ' ) != - 1 ) { return fn . substring ( 0 , fn . lastIndexOf ( ' . ' ) ) + " . out " ; } else return fn + " . out " ; } }

package codejam2010 . qualification ; import java . io . BufferedReader ; import java . io . Closeable ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; public class ProblemA { public static void main ( String [ ] args ) { BufferedReader reader = null ; PrintWriter writer = null ; try { String fileName = " A - large " ; File folder = new File ( new File ( " files " , " codejam2010" ) , " qualification " ) ; File inputFile = new File ( folder , fileName + " . in " ) ; File outputFile = new File ( folder , fileName + " . out " ) ; reader = new BufferedReader ( new FileReader ( inputFile ) ) ; writer = new PrintWriter ( new FileWriter ( outputFile ) ) ; int count = Integer . parseInt ( reader . readLine ( ) ) ; for ( int i = 0 ; i < count ; i ++ ) { String [ ] parameters = reader . readLine ( ) . split ( " \\ s " ) ; writer . printf ( " Case ▁ # % d : ▁ % s \n " , i + 1 , solveIt ( Integer . parseInt ( parameters [ 0 ] ) , Integer . parseInt ( parameters [ 1 ] ) ) ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { close ( reader ) ; close ( writer ) ; } System . out . println ( " Done . " ) ; } private static String solveIt ( int n , int k ) { int allOn = ( 1 << n ) - 1 ; return ( ( allOn & k ) == allOn ) ? " ON " : " OFF " ; } private static void close ( Closeable file ) { if ( file != null ) { try { file . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class A extends SolutionT { public static void main ( String [ ] args ) { ( new A ( ) ) . run ( ) ; } @ Override void runOneTest ( Scanner input , PrintWriter output ) { int n = input . nextInt ( ) ; int k = input . nextInt ( ) ; k = k % ( 1 << n ) ; if ( ( k + 1 ) == ( 1 << n ) ) { output . println ( " ON " ) ; } else { output . println ( " OFF " ) ; } } } abstract class Solution implements Runnable { abstract void runOneTest ( Scanner input , PrintWriter output ) ; public void run ( ) { Scanner input = null ; PrintWriter output = null ; try { input = new Scanner ( new File ( " input . txt " ) ) ; output = new PrintWriter ( new File ( " output . txt " ) ) ; } catch ( FileNotFoundException e ) { } int testCount = input . nextInt ( ) ; for ( int test = 1 ; test <= testCount ; test ++ ) { output . print ( " Case ▁ # " + test + " : ▁ " ) ; runOneTest ( input , output ) ; } input . close ( ) ; output . close ( ) ; } }

import sys NEW_LINE import time NEW_LINE import re NEW_LINE try : NEW_LINE INDENT import psyco NEW_LINE psyco . full ( ) NEW_LINE DEDENT except ImportError : NEW_LINE INDENT pass NEW_LINE DEDENT class tee : NEW_LINE INDENT def __init__ ( self , * fds ) : NEW_LINE INDENT self . _fds = fds NEW_LINE DEDENT def write ( self , data ) : NEW_LINE INDENT for fd in self . _fds : NEW_LINE INDENT fd . write ( data ) NEW_LINE DEDENT DEDENT def flush ( self ) : NEW_LINE INDENT for fd in self . _fds : NEW_LINE INDENT fd . flush ( ) NEW_LINE DEDENT DEDENT def close ( self ) : NEW_LINE INDENT for fd in self . _fds : NEW_LINE INDENT fd . close ( ) NEW_LINE DEDENT DEDENT DEDENT def fileCaseReader ( source ) : NEW_LINE INDENT entryCount = int ( source . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , entryCount + 1 ) : NEW_LINE INDENT yield i NEW_LINE DEDENT DEDENT def readLines ( source ) : NEW_LINE INDENT entryCount = int ( source . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 0 , entryCount ) : NEW_LINE INDENT yield source . readline ( ) NEW_LINE DEDENT DEDENT def readLineOfInts ( f ) : NEW_LINE INDENT return map ( int , f . readline ( ) . strip ( ) . split ( " ▁ " ) ) NEW_LINE DEDENT def runCase ( f ) : NEW_LINE INDENT n , k = readLineOfInts ( f ) NEW_LINE if ( k + 1 ) % 2 ** n == 0 : NEW_LINE INDENT print " ON " NEW_LINE DEDENT else : NEW_LINE INDENT print " OFF " NEW_LINE DEDENT DEDENT def timerWrap ( f ) : NEW_LINE INDENT def __inner ( * args , ** kwargs ) : NEW_LINE INDENT start = time . time ( ) NEW_LINE try : NEW_LINE INDENT return f ( * args , ** kwargs ) NEW_LINE DEDENT finally : NEW_LINE INDENT print >> sys . stderr , " Runtime : ▁ % .3f ▁ sec " % ( time . time ( ) - start ) NEW_LINE DEDENT DEDENT return __inner NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT f = file ( " snapper . in " , " r " ) ; NEW_LINE sys . stdout = tee ( sys . stdout , file ( " snapper . out " , " w " ) ) NEW_LINE for index in fileCaseReader ( f ) : NEW_LINE INDENT print " Case ▁ # % d : " % index , NEW_LINE runCase ( f ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE

if __name__ == " _ _ main _ _ " : NEW_LINE INDENT inFile = open ( " A - large . in " , " r " ) NEW_LINE outFile = open ( " realtest . out " , " w " ) NEW_LINE caseNum = int ( inFile . readline ( ) ) NEW_LINE for i in range ( 1 , caseNum + 1 ) : NEW_LINE INDENT items = inFile . readline ( ) . replace ( " \n " , " " ) . split ( " ▁ " ) NEW_LINE N = int ( items [ 0 ] ) NEW_LINE K = int ( items [ 1 ] ) NEW_LINE lightFlag = 1 NEW_LINE for j in range ( N ) : NEW_LINE INDENT if K % 2 == 0 : NEW_LINE INDENT lightFlag = 0 NEW_LINE break ; NEW_LINE DEDENT else : NEW_LINE INDENT K /= 2 NEW_LINE DEDENT DEDENT if lightFlag == 1 : NEW_LINE INDENT outFile . write ( " Case ▁ # % d : ▁ ON \n " % ( i , ) ) NEW_LINE DEDENT else : NEW_LINE INDENT outFile . write ( " Case ▁ # % d : ▁ OFF \n " % ( i , ) ) NEW_LINE DEDENT DEDENT outFile . close ( ) NEW_LINE inFile . close ( ) NEW_LINE DEDENT

m = { 0 : " OFF " , 1 : " ON " } NEW_LINE def f ( n , k ) : NEW_LINE INDENT return m [ int ( ( ( k + 1 ) % ( 2 ** n ) ) == 0 ) ] NEW_LINE DEDENT import sys NEW_LINE t = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT a = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE assert len ( a ) == 2 NEW_LINE ( n , k ) = a NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i , f ( n , k ) ) NEW_LINE DEDENT

tn = int ( raw_input ( ) ) NEW_LINE for loop in xrange ( tn ) : NEW_LINE INDENT n , k = raw_input ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE k = int ( k ) NEW_LINE x = 2 ** n NEW_LINE on = False NEW_LINE if k % x == x - 1 : NEW_LINE INDENT on = True NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( loop + 1 , [ ' OFF ' , ' ON ' ] [ on ] ) NEW_LINE DEDENT

import sys , re NEW_LINE getline = lambda f : f . readline ( ) . strip ( ) NEW_LINE gettoken = lambda f : re . split ( " \s + " , getline ( f ) ) NEW_LINE getint = lambda f : int ( getline ( f ) ) NEW_LINE getints = lambda f : map ( int , gettoken ( f ) ) NEW_LINE product = lambda l : reduce ( lambda x , y : x * y , l ) if l else 1 NEW_LINE factorial = lambda n : product ( xrange ( n , 1 , - 1 ) ) NEW_LINE nPr = lambda n , r : product ( xrange ( n , n - r , - 1 ) ) NEW_LINE nCr = lambda n , r : nPr ( n , r ) / factorial ( r ) NEW_LINE nMr = lambda l : factorial ( sum ( l ) ) / product ( map ( factorial , l ) ) NEW_LINE gcd = lambda x , y : gcd ( y , x % y ) if y != 0 else x NEW_LINE lcm = lambda x , y : x * y / gcd ( x , y ) NEW_LINE def gcd2 ( a , b ) : NEW_LINE INDENT if b == 0 : return ( a , 1 , 0 ) NEW_LINE ( d , x , y ) = gcd2 ( b , a % b ) NEW_LINE return ( d , y , x - a / b * y ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT f = open ( sys . argv [ 1 ] ) NEW_LINE [ N ] = getints ( f ) NEW_LINE for cases in xrange ( 0 , N ) : NEW_LINE INDENT ans = 0 NEW_LINE n , k = getints ( f ) NEW_LINE M = ( 1 << n ) NEW_LINE s = " OFF " NEW_LINE if k % M == ( M - 1 ) : s = " ON " NEW_LINE print " Case ▁ # % d : ▁ % s " % ( cases + 1 , s ) NEW_LINE DEDENT DEDENT


import java . util . * ; import static java . lang . Math . * ; public class C { void p ( String s ) { System . out . println ( s ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { C = sc . nextInt ( ) ; N = sc . nextInt ( ) ; dp = new double [ C + 1 ] ; Arrays . fill ( dp , - 1.0 ) ; System . out . println ( " Case ▁ # " + zz + " : ▁ " + dp ( 0 ) ) ; } } static int C , N ; static double [ ] dp ; public static double dp ( int numDiff ) { if ( numDiff >= C ) return 0.0 ; if ( dp [ numDiff ] != - 1.0 ) return dp [ numDiff ] ; double pr0 = ( ( double ) choose ( numDiff , N ) ) / choose ( C , N ) ; double ev = 0.0 ; for ( int i = 1 ; i <= N ; i ++ ) { ev += ( 1.0 + dp ( numDiff + i ) ) * ( ( ( double ) choose ( numDiff , N - i ) * choose ( C - numDiff , i ) ) ) / ( choose ( C , N ) ) ; } double ans = ( pr0 + ev ) / ( 1 - pr0 ) ; dp [ numDiff ] = ans ; return ans ; } public static long choose ( int n , int k ) { long ans = 1 ; ArrayList < Integer > toDiv = new ArrayList < Integer > ( ) ; for ( int i = 2 ; i <= k ; i ++ ) toDiv . add ( i ) ; for ( int i = n ; i >= n - k + 1 ; i -- ) { ans *= i ; for ( int j = 0 ; j < toDiv . size ( ) ; j ++ ) { if ( ans % toDiv . get ( j ) == 0 ) { ans /= toDiv . get ( j ) ; toDiv . remove ( j ) ; j -- ; } } } return ans ; } }

import java . util . * ; import java . io . * ; import java . math . * ; public class x { public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; long [ ] [ ] C = new long [ 41 ] [ 41 ] ; for ( int i = 0 ; i <= 40 ; i ++ ) { C [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j <= i ; j ++ ) C [ i ] [ j ] = C [ i - 1 ] [ j ] + C [ i - 1 ] [ j - 1 ] ; } MathContext mc = new MathContext ( 50 , RoundingMode . HALF_EVEN ) ; for ( int tt = 1 ; tt <= t ; tt ++ ) { int A = in . nextInt ( ) , N = in . nextInt ( ) ; BigDecimal [ ] E = new BigDecimal [ A + 1 ] ; E [ A ] = new BigDecimal ( 0 , mc ) ; for ( int i = A - 1 ; i >= 0 ; i -- ) { E [ i ] = new BigDecimal ( C [ A ] [ N ] , mc ) ; for ( int j = i + 1 ; j <= Math . min ( A , i + N ) ; j ++ ) { BigDecimal P = new BigDecimal ( C [ A - i ] [ j - i ] , mc ) ; P = P . multiply ( new BigDecimal ( C [ i ] [ N - j + i ] , mc ) , mc ) ; E [ i ] = E [ i ] . add ( P . multiply ( E [ j ] , mc ) , mc ) ; } BigDecimal D = new BigDecimal ( C [ A ] [ N ] , mc ) . subtract ( new BigDecimal ( C [ i ] [ N ] , mc ) , mc ) ; E [ i ] = E [ i ] . divide ( D , mc ) ; } System . out . println ( " Case ▁ # " + tt + " : ▁ " + E [ 0 ] ) ; } ; } ; } ;

import java . util . Arrays ; import java . util . Scanner ; public class C { public static void main ( String [ ] args ) throws Exception { new C ( ) ; } final int oo = ( int ) 1e9 ; double [ ] [ ] choose = new double [ 50 ] [ 50 ] ; int N , C ; double D ; double [ ] memo = new double [ 50 ] ; C ( ) throws Exception { for ( double [ ] c : choose ) Arrays . fill ( c , - 1 ) ; Scanner in = new Scanner ( System . in ) ; for ( int T = in . nextInt ( ) , ds = 1 ; T -- > 0 ; ++ ds ) { C = in . nextInt ( ) ; N = in . nextInt ( ) ; D = choose ( C , N ) ; Arrays . fill ( memo , - 1 ) ; System . out . printf ( " Case ▁ # % d : ▁ % .9f % n " , ds , go ( 0 ) ) ; } } double go ( int X ) { if ( X == C ) return 0 ; if ( memo [ X ] > - 0.5 ) return memo [ X ] ; double exp = 1 ; for ( int i = 1 ; i <= N ; ++ i ) { if ( X + i > C ) break ; exp += choose ( X , N - i ) * choose ( C - X , i ) / D * go ( X + i ) ; } exp /= ( 1 - choose ( X , N ) * choose ( C - X , 0 ) / D ) ; return memo [ X ] = exp ; } double choose ( int n , int k ) { if ( k == 0 || n == k ) return 1 ; if ( n < k ) return 0 ; if ( choose [ n ] [ k ] > - 0.5 ) return choose [ n ] [ k ] ; return choose [ n ] [ k ] = choose ( n - 1 , k - 1 ) + choose ( n - 1 , k ) ; } }

import java . io . BufferedReader ; import java . io . FileReader ; import java . io . PrintStream ; import java . util . Scanner ; public class C { private static String PNAME = " C - large " ; public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( PNAME + " . in " ) ) ; PrintStream out = new PrintStream ( PNAME + " . out " ) ; Scanner in = new Scanner ( br ) ; int TC = in . nextInt ( ) ; for ( int tc = 1 ; tc <= TC ; tc ++ ) { int c = in . nextInt ( ) ; int n = in . nextInt ( ) ; out . println ( " Case ▁ # " + tc + " : ▁ " + solve ( c , n ) ) ; } br . close ( ) ; out . close ( ) ; } private static double solve ( int c , int n ) { for ( int i = 0 ; i < memo . length ; i ++ ) memo [ i ] = - 1 ; return calc ( c , n , c ) ; } private static double calc ( int c , int n , int need ) { if ( need == 0 ) return 0 ; if ( memo [ need ] != - 1 ) return memo [ need ] ; double ret = 1 ; int have = c - need ; for ( int good = 1 ; good <= Math . min ( n , need ) ; good ++ ) { int bad = n - good ; double p = choose ( need , good ) ; p *= choose ( have , bad ) ; p /= choose ( c , n ) ; ret += p * calc ( c , n , need - good ) ; } if ( have >= n ) { double p = choose ( have , n ) * 1.0 / choose ( c , n ) ; ret /= 1 - p ; } memo [ need ] = ret ; return ret ; } private static long choose ( int n , int k ) { long ret = 1 ; for ( int i = 0 ; i < k ; i ++ ) { ret *= n - i ; ret /= i + 1 ; } return ret ; } static double [ ] memo = new double [ 64 ] ; }

import os , sys NEW_LINE import operator NEW_LINE def choose ( n , c ) : NEW_LINE INDENT if c == 0 or c == n : NEW_LINE INDENT return 1 NEW_LINE DEDENT return reduce ( operator . mul , range ( n , n - c , - 1 ) ) / reduce ( operator . mul , range ( 1 , c + 1 ) ) NEW_LINE DEDENT def buildCardsTable ( cards , numNeeded , numPerPack ) : NEW_LINE INDENT table = [ ] NEW_LINE possiblePacks = 1.0 * choose ( cards , numPerPack ) NEW_LINE for entry in range ( 0 , numNeeded + 1 ) : NEW_LINE INDENT if entry == 0 : NEW_LINE INDENT table . append ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT a = 0 NEW_LINE b = 0 NEW_LINE for numInThisPack in range ( numPerPack + 1 ) : NEW_LINE INDENT if ( numInThisPack <= entry ) : NEW_LINE INDENT frac = ( choose ( entry , numInThisPack ) * choose ( cards - entry , numPerPack - numInThisPack ) ) NEW_LINE if ( numInThisPack != 0 ) : NEW_LINE INDENT b += frac * ( 1 + table [ entry - numInThisPack ] ) NEW_LINE DEDENT else : NEW_LINE INDENT a += frac NEW_LINE b += frac NEW_LINE DEDENT DEDENT DEDENT table . append ( b / ( possiblePacks - a ) ) NEW_LINE DEDENT DEDENT return table [ numNeeded ] NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE words = [ ] NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT [ cards , numPerPack ] = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE numNeeded = cards - numPerPack NEW_LINE expected = buildCardsTable ( cards , numNeeded , numPerPack ) NEW_LINE index += 1 NEW_LINE print " Case ▁ # % d : ▁ % .9f " % ( caseNum + 1 , 1.0 + expected ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT

from __future__ import division NEW_LINE def memoize ( f ) : NEW_LINE INDENT d = { } NEW_LINE def g ( * args ) : NEW_LINE INDENT if args not in d : NEW_LINE INDENT d [ args ] = f ( * args ) NEW_LINE DEDENT return d [ args ] NEW_LINE DEDENT return g NEW_LINE DEDENT def ints ( ) : NEW_LINE INDENT return map ( int , raw_input ( ) . split ( ) ) NEW_LINE DEDENT @ memoize NEW_LINE def p ( get , have , packsize , total ) : NEW_LINE INDENT if get < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif get < packsize - have : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif get > total - have : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif packsize == 0 : NEW_LINE INDENT if get == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return have / total * p ( get , have - 1 , packsize - 1 , total - 1 ) + ( total - have ) / total * p ( get - 1 , have , packsize - 1 , total - 1 ) NEW_LINE DEDENT DEDENT @ memoize NEW_LINE def E ( obtain , have , packsize , total ) : NEW_LINE INDENT if obtain == have : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return ( 1 + sum ( E ( obtain , have + get , packsize , total ) * p ( get , have , packsize , total ) for get in xrange ( 1 , min ( packsize , total - have ) + 1 ) ) ) / ( 1 - p ( 0 , have , packsize , total ) ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT T , = ints ( ) NEW_LINE for case in xrange ( T ) : NEW_LINE INDENT total , packsize = ints ( ) NEW_LINE print " Case ▁ # % s : ▁ % s " % ( ( case + 1 ) , E ( total , 0 , packsize , total ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

filename = ' C - large ' NEW_LINE f = open ( filename + ' . in ' , ' r ' ) NEW_LINE lines = f . readlines ( ) NEW_LINE f . close ( ) NEW_LINE MAX = 41 NEW_LINE FACT = [ 0.0 ] * MAX NEW_LINE def fact ( n ) : NEW_LINE INDENT if FACT [ n ] != 0 : NEW_LINE INDENT return FACT [ n ] NEW_LINE DEDENT tot = 1.0 NEW_LINE for x in xrange ( 1 , n + 1 ) : NEW_LINE INDENT tot *= x NEW_LINE DEDENT FACT [ n ] = tot NEW_LINE return tot NEW_LINE DEDENT def choose ( N , k ) : NEW_LINE INDENT if k > N : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT return fact ( N ) / fact ( k ) / fact ( N - k ) NEW_LINE DEDENT print choose ( 5 , 0 ) , choose ( 5 , 1 ) , choose ( 5 , 5 ) , choose ( 5 , 7 ) NEW_LINE CACHE = { } NEW_LINE def get_exp_num ( C , N , S ) : NEW_LINE INDENT if S in CACHE : NEW_LINE INDENT return CACHE [ S ] NEW_LINE DEDENT if S >= C : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT tot_num = choose ( C , N ) NEW_LINE self_fact = choose ( C - S , 0 ) * choose ( S , N ) / tot_num NEW_LINE ans = 0.0 NEW_LINE ans += 1.0 * self_fact NEW_LINE for k in xrange ( 1 , N + 1 ) : NEW_LINE INDENT prob = choose ( C - S , k ) * choose ( S , N - k ) / tot_num NEW_LINE ans += prob * ( 1.0 + get_exp_num ( C , N , S + k ) ) NEW_LINE DEDENT ans = ans / ( 1.0 - self_fact ) NEW_LINE CACHE [ S ] = ans NEW_LINE return ans NEW_LINE DEDENT out = open ( filename + ' . out ' , ' w ' ) NEW_LINE T = int ( lines [ 0 ] . strip ( ) ) NEW_LINE case = 1 NEW_LINE for line in lines [ 1 : ] : NEW_LINE INDENT C , N = [ int ( x ) for x in line . strip ( ) . split ( ' ▁ ' ) ] NEW_LINE CACHE = { } NEW_LINE ans = get_exp_num ( C , N , 0 ) NEW_LINE print ' Case ▁ # % d : ▁ % 0.6f ' % ( case , ans ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % 0.6f \n ' % ( case , ans ) ) NEW_LINE case += 1 NEW_LINE DEDENT out . close ( ) NEW_LINE

from scipy . special import gammaln , exp NEW_LINE from scipy import comb NEW_LINE import sys NEW_LINE def factln ( n ) : NEW_LINE INDENT return gammaln ( n + 1 ) NEW_LINE DEDENT def prob_old ( c , n , j , k ) : NEW_LINE INDENT pi = k - j NEW_LINE po = c - pi NEW_LINE lnp = factln ( n - c ) + factln ( j ) + factln ( n - j ) NEW_LINE lnp -= factln ( n ) + factln ( j - po ) + factln ( n - j - pi ) NEW_LINE p = exp ( lnp ) NEW_LINE return p NEW_LINE DEDENT def prob ( c , n , j , k ) : NEW_LINE INDENT pi = k - j NEW_LINE po = c - pi NEW_LINE old_count = j NEW_LINE new_count = n - j NEW_LINE return comb ( old_count , po ) * comb ( new_count , pi ) / comb ( n , c ) NEW_LINE DEDENT def solve ( c , n ) : NEW_LINE INDENT p0 = [ 0 for x in range ( n + 1 ) ] NEW_LINE p0 [ 0 ] = 1.0 NEW_LINE p1 = [ 0.0 for x in range ( n + 1 ) ] NEW_LINE sum = 0.0 NEW_LINE nstep = 0 NEW_LINE prob_prev = 0.0 NEW_LINE while p0 [ n ] < 0.999999 : NEW_LINE INDENT for j in range ( n + 1 ) : p1 [ j ] = 0.0 NEW_LINE for j in range ( n + 1 ) : NEW_LINE INDENT for k in range ( j , n + 1 ) : NEW_LINE INDENT if k - j > c : break NEW_LINE p = prob ( c , n , j , k ) NEW_LINE p1 [ k ] += p0 [ j ] * p NEW_LINE DEDENT DEDENT for j in range ( n + 1 ) : p0 [ j ] = p1 [ j ] NEW_LINE nstep += 1 NEW_LINE sum += ( p0 [ n ] - prob_prev ) * ( nstep ) NEW_LINE prob_prev = p0 [ n ] NEW_LINE DEDENT return sum NEW_LINE DEDENT fn = sys . argv [ 1 ] NEW_LINE f = open ( fn , ' r ' ) NEW_LINE t = int ( f . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT n , c = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE s = solve ( c , n ) NEW_LINE print " Case ▁ # % d : ▁ % .8f " % ( i + 1 , s ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT

import sys NEW_LINE import psyco NEW_LINE from numpy import linalg NEW_LINE psyco . full ( ) NEW_LINE def p ( a , b ) : NEW_LINE INDENT if b < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if a < b : NEW_LINE INDENT return 0 NEW_LINE DEDENT if b * 2 > a : NEW_LINE INDENT return p ( a , a - b ) NEW_LINE DEDENT res = 1 NEW_LINE for i in range ( b ) : NEW_LINE INDENT res *= a - i NEW_LINE DEDENT for i in range ( b ) : NEW_LINE INDENT res //= ( i + 1 ) NEW_LINE DEDENT return res NEW_LINE DEDENT def foo ( ifile ) : NEW_LINE INDENT n , c = [ int ( x ) for x in ifile . readline ( ) . split ( ) ] NEW_LINE pnc = p ( n , c ) NEW_LINE res = [ ] NEW_LINE for i in range ( c , n ) : NEW_LINE INDENT t = [ 0.0 ] * ( n + 1 ) NEW_LINE for j in range ( i , n + 1 ) : NEW_LINE INDENT ii = n - i NEW_LINE jj = j - i NEW_LINE t [ j ] = ( p ( ii , jj ) * p ( i , c - jj ) + 0.0 ) / pnc NEW_LINE DEDENT t [ i ] -= 1.0 NEW_LINE t = t [ c : ] NEW_LINE res . append ( t ) NEW_LINE DEDENT t = [ 0 ] * ( n + 1 - c ) NEW_LINE t [ 0 ] = 1 NEW_LINE res . append ( t ) NEW_LINE t2 = [ 1.0 ] * ( n + 1 - c ) NEW_LINE return ' % .7f ' % linalg . solve ( res , t2 ) [ - 1 ] NEW_LINE DEDENT def main ( ifile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ' Case ▁ # % d : ▁ % s ' % ( i + 1 , foo ( ifile ) ) NEW_LINE DEDENT DEDENT main ( sys . stdin ) NEW_LINE


import java . io . * ; import java . util . StringTokenizer ; public class C { private int solveTest ( ) throws IOException { int n = nextInt ( ) ; double f = Double . parseDouble ( next ( ) ) ; int [ ] a = new int [ n ] ; String s = next ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s . charAt ( i ) - '0' ; } double best = 1e100 ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int k = 0 ; for ( int j = i ; j < n ; j ++ ) { int l = j - i + 1 ; k += a [ j ] ; double x = 1.0 * k / l ; double dif = Math . abs ( x - f ) ; if ( dif < best - 1e-9 ) { best = dif ; res = i ; } } } return res ; } private void solve ( ) throws IOException { int n = nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int res = solveTest ( ) ; System . out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + res ) ; out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + res ) ; } } BufferedReader br ; StringTokenizer st ; PrintWriter out ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new C ( ) . run ( ) ; } private void run ( ) throws FileNotFoundException { br = new BufferedReader ( new FileReader ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + " . in " ) ) ; out = new PrintWriter ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + " . out " ) ; try { solve ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } out . close ( ) ; } }

from fractions import Fraction NEW_LINE def reader ( inFile ) : NEW_LINE INDENT ( N , F ) = inFile . getWords ( ) NEW_LINE N = int ( N ) NEW_LINE F = Fraction ( F ) NEW_LINE return ( N , F , inFile . readline ( ) ) NEW_LINE DEDENT def solver ( ( N , F , word ) ) : NEW_LINE INDENT t = [ 0 ] * ( N + 1 ) NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT t [ i + 1 ] = t [ i ] + int ( word [ i ] ) NEW_LINE DEDENT rec = ( 2 , 0 ) NEW_LINE for j in xrange ( 1 , N + 1 ) : NEW_LINE INDENT for i in xrange ( j ) : NEW_LINE INDENT ratio = Fraction ( t [ j ] - t [ i ] , j - i ) NEW_LINE scr = ( abs ( ratio - F ) , i ) NEW_LINE if scr < rec : NEW_LINE INDENT rec = scr NEW_LINE DEDENT DEDENT DEDENT return rec [ 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , r " C : \gcj\finals\c " , " c " ) . run ( ) NEW_LINE DEDENT


import java . util . * ; import java . io . * ; public class B { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( " B - large . in " ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( new File ( " B - large . out " ) ) ) ; int t = in . nextInt ( ) ; for ( int y = 0 ; y < t ; y ++ ) { double c = in . nextDouble ( ) ; double f = in . nextDouble ( ) ; double x = in . nextDouble ( ) ; long low = 0 ; long high = ( long ) 1E6 ; while ( low + 2 < high ) { long mid1 = low + ( high - low ) / 3 ; long mid2 = low + 2 * ( high - low ) / 3 ; if ( getTime ( mid1 , c , f , x ) < getTime ( mid2 , c , f , x ) ) { high = mid2 - 1 ; } else { low = mid1 ; } } double result = Double . POSITIVE_INFINITY ; for ( long z = low ; z <= high ; z ++ ) { result = Math . min ( result , getTime ( z , c , f , x ) ) ; } out . printf ( " Case ▁ # % d : ▁ % .7f \n " , y + 1 , result ) ; } out . close ( ) ; } public static double getTime ( long buildings , double c , double f , double x ) { double time = 0 ; double rate = 2 ; for ( int i = 0 ; i < buildings ; i ++ ) { time += c / rate ; rate += f ; } return time + ( x / rate ) ; } }

import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . text . DecimalFormat ; import java . util . Scanner ; public class Cookie { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new FileReader ( " jam . in " ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( " jam . out " ) ) ; int cases ; cases = sc . nextInt ( ) ; for ( int z = 1 ; z <= cases ; z ++ ) { double C = sc . nextDouble ( ) ; double F = sc . nextDouble ( ) ; double X = sc . nextDouble ( ) ; double product = 2 ; double ans = 0 ; while ( X / ( product + F ) + C / product < X / product ) { ans += C / product ; product += F ; } ans += X / product ; bw . write ( " Case ▁ # " + z + " : ▁ " ) ; DecimalFormat df = new DecimalFormat ( "0.00000000" ) ; bw . write ( " " + df . format ( ans ) + " \n " ) ; } sc . close ( ) ; bw . close ( ) ; } }

package con2014Q ; import java . io . * ; import java . util . * ; public class B { private static final String islarge = " - large " ; private static final String fileName = " results / con2014Q / " + B . class . getSimpleName ( ) . toLowerCase ( ) + islarge ; private static final String inputFileName = fileName + " . in " ; private static final String outputFileName = fileName + " . out " ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { double C = Double . parseDouble ( in . next ( ) ) , F = Double . parseDouble ( in . next ( ) ) , X = Double . parseDouble ( in . next ( ) ) ; double best = X / 2 ; double cur = 0 ; int a_farms = 0 ; while ( cur < best ) { cur += C / ( 2 + ( a_farms * F ) ) ; a_farms ++ ; best = Math . min ( best , cur + ( X / ( 2 + ( a_farms * F ) ) ) ) ; } out . format ( " % .7f % n " , best ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; long start = System . currentTimeMillis ( ) ; in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( " Case ▁ # " + t + " : ▁ " ) ; new B ( ) . solve ( ) ; System . out . println ( " Case ▁ # " + t + " : ▁ solved " ) ; } in . close ( ) ; out . close ( ) ; long stop = System . currentTimeMillis ( ) ; System . out . println ( stop - start + " ▁ ms " ) ; } }

import java . io . File ; import java . io . PrintStream ; import java . util . Scanner ; public class B { static final Boolean SAMPLE = false ; static final String PROBLEM = " B " ; static final String INPUT = " large " ; static final String ID = "0" ; static final String PATH = " F : \\ software ▁ installation \\ codejam - commandline - 1.2 - beta1 \\ source\ \" ; public static void main ( String args [ ] ) throws Throwable { Scanner in = SAMPLE ? new Scanner ( System . in ) : new Scanner ( new File ( PATH + PROBLEM + " - " + INPUT + " - " + ID + " . in " ) ) ; PrintStream out = SAMPLE ? System . out : new PrintStream ( PATH + PROBLEM + " - " + INPUT + " - " + ID + " . out " ) ; int test = in . nextInt ( ) ; for ( int t = 1 ; t <= test ; t ++ ) { out . print ( " Case ▁ # " + t + " : ▁ " ) ; double C = in . nextDouble ( ) ; double F = in . nextDouble ( ) ; double X = in . nextDouble ( ) ; double time = 0 ; double speed = 2 ; while ( X / speed > C / speed + X / ( speed + F ) ) { time += C / speed ; speed += F ; } time += X / speed ; out . println ( time ) ; } out . close ( ) ; in . close ( ) ; System . out . println ( " finish ! " ) ; } }

package exoB ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoB { public static void main ( String [ ] args ) { String base = " / home / jean / gcj2014 / q / ExoB / " ; String input = base + " b1 . in " ; String output = base + " b1 . out " ; try { Scanner sc = new Scanner ( new FileReader ( input ) ) ; PrintWriter pw = new PrintWriter ( output ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( " Test ▁ case ▁ " + ( c + 1 ) + " . . . " ) ; pw . print ( " Case ▁ # " + ( c + 1 ) + " : ▁ " ) ; test ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( FileNotFoundException ex ) { Logger . getLogger ( ExoB . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test ( Scanner sc , PrintWriter pw ) { double C = sc . nextDouble ( ) ; double F = sc . nextDouble ( ) ; double X = sc . nextDouble ( ) ; double r = 2.0 ; double t = 0.0 ; while ( X / r > C / r + X / ( r + F ) ) { t = t + C / r ; r += F ; } t = t + X / r ; pw . print ( t ) ; } }

def bestCookieTime ( c , f , x ) : NEW_LINE INDENT zero_time = cookieTime ( c , f , x , 0 ) NEW_LINE best_time = zero_time NEW_LINE total_farms = 1000 NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 1000 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT total_farms -= 1900 NEW_LINE if total_farms < 10 : NEW_LINE INDENT total_farms = 10 NEW_LINE DEDENT best_time = zero_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 100 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT total_farms -= 190 NEW_LINE if total_farms < 10 : NEW_LINE INDENT total_farms = 10 NEW_LINE DEDENT best_time = zero_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 10 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT total_farms -= 19 NEW_LINE if total_farms < 1 : NEW_LINE INDENT total_farms = 1 NEW_LINE DEDENT best_time = zero_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE while new_time < best_time : NEW_LINE INDENT total_farms += 1 NEW_LINE best_time = new_time NEW_LINE new_time = cookieTime ( c , f , x , total_farms ) NEW_LINE DEDENT return str ( best_time ) NEW_LINE DEDENT def cookieTime ( c , f , x , total_farms ) : NEW_LINE INDENT if x < c : NEW_LINE INDENT return x / 2 NEW_LINE DEDENT farms = 0 NEW_LINE time = 0 NEW_LINE cookie_rate = 2 NEW_LINE while farms < total_farms : NEW_LINE INDENT time += c / cookie_rate NEW_LINE cookie_rate += f NEW_LINE farms += 1 NEW_LINE DEDENT return time + x / cookie_rate NEW_LINE DEDENT input_text = open ( " input . in " ) NEW_LINE lines = input_text . readlines ( ) NEW_LINE input_text . close ( ) NEW_LINE with open ( " output " , " a " ) as outputfile : NEW_LINE INDENT for num in range ( 0 , int ( lines [ 0 ] ) ) : NEW_LINE INDENT line = lines [ num + 1 ] . split ( " ▁ " ) NEW_LINE outputfile . write ( " Case ▁ # " + str ( num + 1 ) + " : ▁ " + bestCookieTime ( float ( line [ 0 ] ) , float ( line [ 1 ] ) , float ( line [ 2 ] ) ) + " \n " ) NEW_LINE DEDENT DEDENT

import fileinput NEW_LINE import sys NEW_LINE import math NEW_LINE def read_cases ( ) : NEW_LINE INDENT fh = fileinput . input ( ) NEW_LINE T = int ( fh . readline ( ) . strip ( ) ) NEW_LINE cases = [ ] NEW_LINE for t in range ( T ) : NEW_LINE INDENT case = { } NEW_LINE case [ " C " ] , case [ " F " ] , case [ " X " ] = map ( float , fh . readline ( ) . strip ( ) . split ( " ▁ " ) ) NEW_LINE cases += [ case ] NEW_LINE DEDENT if fh . readline ( ) . strip ( ) != " " : NEW_LINE INDENT raise Exception NEW_LINE DEDENT return cases NEW_LINE DEDENT def process_case ( case ) : NEW_LINE INDENT cps = [ 2.0 ] NEW_LINE C , F , X = case [ " C " ] , case [ " F " ] , case [ " X " ] NEW_LINE factories2timecomplete = [ X / cps [ 0 ] ] NEW_LINE elapsed2factory = [ 0.0 ] NEW_LINE factory_count = 0 NEW_LINE while True : NEW_LINE INDENT elapsed2factory += [ elapsed2factory [ - 1 ] + C / cps [ - 1 ] ] NEW_LINE factory_count += 1 NEW_LINE cps += [ cps [ - 1 ] + F ] NEW_LINE factories2timecomplete += [ elapsed2factory [ - 1 ] + X / cps [ - 1 ] ] NEW_LINE if factories2timecomplete [ - 1 ] > factories2timecomplete [ - 2 ] : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return factories2timecomplete [ - 2 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT cases = read_cases ( ) NEW_LINE for i , case in enumerate ( cases [ : ] ) : NEW_LINE INDENT result = process_case ( case ) NEW_LINE print " Case ▁ # % s : " % ( i + 1 , ) , result NEW_LINE DEDENT DEDENT

import math NEW_LINE input_file_name = ' . / B - large . in ' NEW_LINE output_file_name = ' . / B - large . out ' NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT input_file = open ( input_file_name , ' r ' ) NEW_LINE output_file = open ( output_file_name , ' w ' ) NEW_LINE file_line = input_file . readline ( ) NEW_LINE file_line = file_line . replace ( ' \n ' , ' ' ) NEW_LINE num_cases = int ( file_line ) NEW_LINE case_num = 1 NEW_LINE while True : NEW_LINE INDENT file_line = input_file . readline ( ) NEW_LINE if file_line == ' ' or file_line == ' \n ' : NEW_LINE INDENT input_file . close ( ) NEW_LINE break NEW_LINE DEDENT file_line = file_line . replace ( ' \n ' , ' ' ) NEW_LINE file_line_list = file_line . split ( ) NEW_LINE C = float ( file_line_list [ 0 ] ) NEW_LINE F = float ( file_line_list [ 1 ] ) NEW_LINE X = float ( file_line_list [ 2 ] ) NEW_LINE if C >= X : NEW_LINE INDENT total_time = X / 2.0 NEW_LINE DEDENT else : NEW_LINE INDENT n = max ( 0.0 , float ( math . floor ( ( F * X - 2.0 * C ) / ( C * F ) ) ) ) NEW_LINE total_time = 0.0 NEW_LINE for n_i in range ( int ( n ) ) : NEW_LINE INDENT total_time += C / ( 2.0 + n_i * F ) NEW_LINE DEDENT total_time += X / ( 2.0 + n * F ) NEW_LINE DEDENT output_file . write ( ' Case ▁ # ' + str ( case_num ) + ' : ▁ % 0.7f \n ' % total_time ) NEW_LINE print ( case_num ) NEW_LINE case_num += 1 NEW_LINE DEDENT output_file . close ( ) NEW_LINE DEDENT

import sys , numpy NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( sys . argv [ 1 ] ) NEW_LINE T = int ( f . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT ( C , F , X ) = f . readline ( ) . strip ( ) . split ( ) NEW_LINE print " Case ▁ # % d : ▁ % .7f " % ( i , minTime ( float ( C ) , float ( F ) , float ( X ) ) ) NEW_LINE DEDENT DEDENT def minTime ( C , F , X ) : NEW_LINE INDENT C = numpy . longdouble ( C ) NEW_LINE F = numpy . longdouble ( F ) NEW_LINE X = numpy . longdouble ( X ) NEW_LINE n = numpy . longdouble ( 0.0 ) NEW_LINE two = numpy . longdouble ( 2.0 ) NEW_LINE prevTime = X / two ; NEW_LINE farmBuildTime = numpy . longdouble ( 0.0 ) ; NEW_LINE while True : NEW_LINE INDENT farmBuildTime += C / ( two + n * F ) NEW_LINE n += 1.0 NEW_LINE time = numpy . longdouble ( farmBuildTime + X / ( two + n * F ) ) NEW_LINE if time > prevTime : NEW_LINE INDENT return prevTime NEW_LINE DEDENT prevTime = time NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) ; NEW_LINE DEDENT

import math NEW_LINE import sys NEW_LINE def findsol ( C , F , X ) : NEW_LINE INDENT t = 0.0 NEW_LINE tmax = X / 2 NEW_LINE N = 0 NEW_LINE while 1 : NEW_LINE INDENT t += C / ( 2 + N * F ) NEW_LINE if ( t > tmax ) : NEW_LINE INDENT return str ( tmax ) NEW_LINE DEDENT N += 1 NEW_LINE t2 = t + X / ( 2 + N * F ) NEW_LINE if ( t2 < tmax ) : NEW_LINE INDENT tmax = t2 NEW_LINE DEDENT DEDENT return b NEW_LINE DEDENT def convertreals ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE ii = 0 NEW_LINE for jj in range ( len ( s ) ) : NEW_LINE INDENT if s [ jj ] == ' ▁ ' : NEW_LINE INDENT if ( ii < jj ) : NEW_LINE INDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE ii = jj + 1 NEW_LINE DEDENT DEDENT DEDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE return a NEW_LINE DEDENT fidi = open ( ' B - large . in ' , ' r ' ) NEW_LINE fido = open ( ' a . out ' , ' w ' ) NEW_LINE T = fidi . readline ( ) NEW_LINE T = int ( T ) NEW_LINE for ii in range ( 1 , T + 1 ) : NEW_LINE INDENT R = fidi . readline ( ) NEW_LINE R = convertreals ( R ) NEW_LINE C = R [ 0 ] NEW_LINE F = R [ 1 ] NEW_LINE X = R [ 2 ] NEW_LINE a = findsol ( C , F , X ) NEW_LINE fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + str ( a ) + ' \n ' ) NEW_LINE print ( ' Case ▁ # ' , str ( ii ) , ' : ▁ ' , str ( a ) ) NEW_LINE DEDENT fidi . close ( ) NEW_LINE fido . close ( ) NEW_LINE