import sys NEW_LINE CACHE = { } NEW_LINE def do_count ( x , y , rooks , h , w ) : NEW_LINE INDENT k = ( x , y , rooks , h , w ) NEW_LINE p = ( x , y ) NEW_LINE if CACHE . has_key ( k ) : return CACHE [ k ] NEW_LINE if p in rooks : return 0 NEW_LINE if x > h or y > w : return 0 NEW_LINE if x == h and y == w : return 1 NEW_LINE count = 0 NEW_LINE count = count + do_count ( x + 2 , y + 1 , rooks , h , w ) NEW_LINE count = count + do_count ( x + 1 , y + 2 , rooks , h , w ) NEW_LINE count %= 10007 NEW_LINE CACHE [ k ] = count NEW_LINE return count NEW_LINE DEDENT def do_trial ( f ) : NEW_LINE INDENT H , W , R = [ int ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE rooks = set ( ) NEW_LINE for i in range ( R ) : NEW_LINE INDENT rooks . add ( tuple ( [ int ( x ) for x in f . readline ( ) . split ( ) ] ) ) NEW_LINE DEDENT rooks = frozenset ( rooks ) NEW_LINE global CACHE NEW_LINE CACHE = { } NEW_LINE return do_count ( 1 , 1 , rooks , H , W ) NEW_LINE DEDENT f = sys . stdin NEW_LINE count = int ( f . readline ( ) ) NEW_LINE for i in range ( count ) : NEW_LINE INDENT r = do_trial ( f ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i + 1 , r ) NEW_LINE DEDENT


import java . util . Scanner ; public class EndlessKnight { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int numCases = in . nextInt ( ) ; for ( int i = 0 ; i < numCases ; i ++ ) doCase ( i + 1 , in ) ; } private static void doCase ( int caseNum , Scanner in ) { int H = in . nextInt ( ) ; int W = in . nextInt ( ) ; int R = in . nextInt ( ) ; int [ ] [ ] memoized = new int [ W ] [ H ] ; for ( int [ ] arr : memoized ) for ( int i = 0 ; i < arr . length ; i ++ ) arr [ i ] = - 1 ; for ( int i = 0 ; i < R ; i ++ ) { int rockY = in . nextInt ( ) ; int rockX = in . nextInt ( ) ; memoized [ W - rockX ] [ H - rockY ] = 0 ; } int total = findMoves ( W - 1 , H - 1 , memoized ) ; System . out . println ( " Case ▁ # " + caseNum + " : ▁ " + total ) ; } private static int findMoves ( int i , int j , int [ ] [ ] memoized ) { if ( i == 0 && j == 0 ) return 1 ; if ( i < 1 || j < 1 ) return 0 ; if ( memoized [ i ] [ j ] != - 1 ) return memoized [ i ] [ j ] ; memoized [ i ] [ j ] = ( findMoves ( i - 1 , j - 2 , memoized ) + findMoves ( i - 2 , j - 1 , memoized ) ) % 10007 ; return memoized [ i ] [ j ] ; } }

def waysToReachExit ( r , c ) : NEW_LINE INDENT if c == W and r == H : NEW_LINE INDENT return 1 NEW_LINE DEDENT if c > W or r > H : NEW_LINE INDENT return 0 NEW_LINE DEDENT isRock = False NEW_LINE for rock in rocks : NEW_LINE INDENT if rock [ 0 ] == r and rock [ 1 ] == c : NEW_LINE INDENT isRock = True NEW_LINE DEDENT DEDENT if isRock == True : NEW_LINE INDENT return 0 NEW_LINE DEDENT if squareData . has_key ( ( r , c ) ) : NEW_LINE INDENT result = squareData [ ( r , c ) ] NEW_LINE return result NEW_LINE DEDENT else : NEW_LINE INDENT result = waysToReachExit ( r + 1 , c + 2 ) + waysToReachExit ( r + 2 , c + 1 ) NEW_LINE squareData [ r , c ] = result NEW_LINE return result NEW_LINE DEDENT DEDENT inFile = open ( " D - small - attempt0 . in " , " r " ) NEW_LINE outFile = open ( " D - small - out . out " , " w " ) NEW_LINE cases = int ( inFile . readline ( ) ) NEW_LINE for caseNum in range ( 1 , cases + 1 ) : NEW_LINE INDENT params = inFile . readline ( ) . rstrip ( ) NEW_LINE params = params . split ( " ▁ " ) NEW_LINE params = map ( int , params ) NEW_LINE H = params [ 0 ] NEW_LINE W = params [ 1 ] NEW_LINE R = params [ 2 ] NEW_LINE rocks = [ ] NEW_LINE for i in range ( R ) : NEW_LINE INDENT rock = inFile . readline ( ) . rstrip ( ) NEW_LINE rock = rock . split ( " ▁ " ) NEW_LINE rock = map ( int , rock ) NEW_LINE rocks . append ( rock ) NEW_LINE DEDENT squareData = { } NEW_LINE answer = waysToReachExit ( 1 , 1 ) NEW_LINE answer = answer % 10007 NEW_LINE outString = " Case ▁ # " + str ( caseNum ) + " : ▁ " + str ( answer ) + " \n " NEW_LINE print outString . rstrip ( ) NEW_LINE outFile . write ( outString ) NEW_LINE DEDENT inFile . close ( ) NEW_LINE outFile . close ( ) NEW_LINE


import sys NEW_LINE import re NEW_LINE from Numeric import * NEW_LINE sys . setcheckinterval ( 10000 ) NEW_LINE PI = arccos ( - 1 ) NEW_LINE PI_2 = arccos ( - 1 ) / 2 NEW_LINE cache = { } NEW_LINE r = { } NEW_LINE def solveR ( x , y , H , W ) : NEW_LINE INDENT if x == W and y == H : return 1 NEW_LINE if globals ( ) [ " cache " ] . has_key ( ( x , y ) ) : return globals ( ) [ " cache " ] [ ( x , y ) ] NEW_LINE total = 0 NEW_LINE if x + 2 <= W and y + 1 <= H and ( not r . has_key ( ( x + 2 , y + 1 ) ) ) : total += solveR ( x + 2 , y + 1 , H , W ) NEW_LINE if x + 1 <= W and y + 2 <= H and ( not r . has_key ( ( x + 1 , y + 2 ) ) ) : total += solveR ( x + 1 , y + 2 , H , W ) NEW_LINE total = total % 10007 NEW_LINE globals ( ) [ " cache " ] [ ( x , y ) ] = total NEW_LINE return total NEW_LINE DEDENT def solve ( caseNum ) : NEW_LINE INDENT H , W , R = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( " ▁ " ) ) NEW_LINE globals ( ) [ " r " ] = { } NEW_LINE for i in range ( R ) : NEW_LINE INDENT tmp = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( " ▁ " ) ) NEW_LINE globals ( ) [ " r " ] [ ( tmp [ 1 ] , tmp [ 0 ] ) ] = 1 NEW_LINE DEDENT globals ( ) [ " cache " ] = { } NEW_LINE total = solveR ( 1 , 1 , H , W ) NEW_LINE sys . stdout . write ( " Case ▁ # % d : ▁ % s " % ( caseNum , total ) ) NEW_LINE DEDENT casesCount = int ( re . findall ( r ' [ \d ] + ' , sys . stdin . readline ( ) ) [ 0 ] ) NEW_LINE first = True NEW_LINE for case in range ( 1 , casesCount + 1 ) : NEW_LINE INDENT if ( first ) : NEW_LINE INDENT first = False NEW_LINE DEDENT else : NEW_LINE INDENT print " " NEW_LINE DEDENT solve ( case ) NEW_LINE DEDENT


import java . util . * ; public class DSmall { static final int P = 10007 ; public static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= N ; caseID ++ ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; boolean [ ] [ ] rock = new boolean [ H ] [ W ] ; for ( int i = 0 ; i < R ; i ++ ) { int r = sc . nextInt ( ) - 1 ; int c = sc . nextInt ( ) - 1 ; rock [ r ] [ c ] = true ; } int [ ] [ ] count = new int [ H + 2 ] [ W + 2 ] ; count [ 0 ] [ 0 ] = 1 ; for ( int y = 0 ; y < H ; y ++ ) { for ( int x = 0 ; x < W ; x ++ ) { if ( rock [ y ] [ x ] ) continue ; count [ y + 2 ] [ x + 1 ] += count [ y ] [ x ] ; count [ y + 2 ] [ x + 1 ] %= P ; count [ y + 1 ] [ x + 2 ] += count [ y ] [ x ] ; count [ y + 1 ] [ x + 2 ] %= P ; } } System . out . printf ( " Case ▁ # % d : ▁ % d % n " , caseID , count [ H - 1 ] [ W - 1 ] ) ; } } }

rocks = { } NEW_LINE num_ways = { } NEW_LINE mod = 10007 NEW_LINE def num_u_ways ( r , c , H , W ) : NEW_LINE INDENT if ( r >= H or c >= W ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( ( r , c ) in rocks ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( r == H - 1 and c == W - 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( ( r , c ) in num_ways ) : NEW_LINE INDENT return num_ways [ ( r , c ) ] NEW_LINE DEDENT a = num_u_ways ( r + 2 , c + 1 , H , W ) NEW_LINE b = num_u_ways ( r + 1 , c + 2 , H , W ) NEW_LINE num_ways [ ( r , c ) ] = ( a + b ) % mod NEW_LINE return num_ways [ ( r , c ) ] NEW_LINE DEDENT filename = " D - small - attempt0 . in " NEW_LINE f = open ( filename , ' r ' ) NEW_LINE of = open ( " D - small . out " , ' w ' ) NEW_LINE N = int ( f . readline ( ) ) NEW_LINE for x in xrange ( N ) : NEW_LINE INDENT l = f . readline ( ) . split ( ' ▁ ' ) NEW_LINE H = int ( l [ 0 ] ) NEW_LINE W = int ( l [ 1 ] ) NEW_LINE R = int ( l [ 2 ] ) NEW_LINE rocks = { } NEW_LINE for y in xrange ( R ) : NEW_LINE INDENT l = f . readline ( ) . split ( ' ▁ ' ) NEW_LINE rocks [ ( int ( l [ 0 ] ) - 1 , int ( l [ 1 ] ) - 1 ) ] = True NEW_LINE DEDENT num_ways = { } NEW_LINE ans = num_u_ways ( 0 , 0 , H , W ) NEW_LINE print >> of , " Case ▁ # % d : ▁ % d " % ( x + 1 , ans ) NEW_LINE DEDENT


import sys NEW_LINE def isrock ( i , j ) : NEW_LINE INDENT global rocks NEW_LINE for r , c in rocks : NEW_LINE INDENT if r == i and c == j : return True NEW_LINE DEDENT return False NEW_LINE DEDENT filename = sys . argv [ 1 ] NEW_LINE inputfile = file ( filename , ' r ' ) NEW_LINE numcases = int ( inputfile . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , numcases + 1 ) : NEW_LINE INDENT H , W , R = map ( long , inputfile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE rocks = [ ] NEW_LINE for k in range ( R ) : NEW_LINE INDENT r , c = map ( long , inputfile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE rocks . append ( ( r - 1 , c - 1 ) ) NEW_LINE DEDENT F = [ [ 0 ] * W for i in range ( H ) ] NEW_LINE F [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , H ) : NEW_LINE INDENT for j in range ( 1 , W ) : NEW_LINE INDENT n = 0 NEW_LINE if i > 0 and j > 1 and not isrock ( i - 1 , j - 2 ) : NEW_LINE INDENT n += F [ i - 1 ] [ j - 2 ] NEW_LINE DEDENT if i > 1 and j > 0 and not isrock ( i - 2 , j - 1 ) : NEW_LINE INDENT n += F [ i - 2 ] [ j - 1 ] NEW_LINE DEDENT F [ i ] [ j ] = n NEW_LINE DEDENT DEDENT M = F [ H - 1 ] [ W - 1 ] NEW_LINE print " Case ▁ # % d : ▁ % d " % ( case , M % 10007 ) NEW_LINE DEDENT


import static java . lang . Math . * ; import static java . math . BigInteger . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; import java . math . * ; import java . util . * ; public class D { public static void main ( String [ ] args ) { new D ( ) . run ( ) ; } long M = 10007 ; static final int [ ] di = { 1 , 2 } , dj = { 2 , 1 } ; void run ( ) { Scanner sc = new Scanner ( System . in ) ; int on = sc . nextInt ( ) ; for ( int o = 1 ; o <= on ; o ++ ) { System . out . printf ( " Case ▁ # % d : ▁ " , o ) ; int h = sc . nextInt ( ) , w = sc . nextInt ( ) , r = sc . nextInt ( ) ; boolean [ ] [ ] bs = new boolean [ h ] [ w ] ; for ( int i = 0 ; i < r ; i ++ ) bs [ sc . nextInt ( ) - 1 ] [ sc . nextInt ( ) - 1 ] = true ; long [ ] [ ] dp = new long [ h ] [ w ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) if ( ! bs [ i ] [ j ] ) { for ( int k = 0 ; k < 2 ; k ++ ) { int ii = i + di [ k ] , jj = j + dj [ k ] ; if ( ii < h && jj < w ) dp [ ii ] [ jj ] = ( dp [ ii ] [ jj ] + dp [ i ] [ j ] ) % M ; } } } System . out . println ( dp [ h - 1 ] [ w - 1 ] ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } }


import java . io . PrintWriter ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Scanner ; public class D { static Scanner in ; static PrintWriter out ; public static void main ( String [ ] args ) throws FileNotFoundException { in = new Scanner ( new File ( " input . txt " ) ) ; out = new PrintWriter ( " output . txt " ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + new D ( ) . solve ( ) ) ; } out . close ( ) ; } private Object solve ( ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int r = in . nextInt ( ) ; boolean [ ] [ ] a = new boolean [ n ] [ m ] ; for ( int i = 0 ; i < r ; i ++ ) { a [ in . nextInt ( ) - 1 ] [ in . nextInt ( ) - 1 ] = true ; } int [ ] [ ] d = new int [ n ] [ m ] ; d [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < m ; j ++ ) if ( ! a [ i ] [ j ] ) { if ( i > 1 ) { d [ i ] [ j ] += d [ i - 2 ] [ j - 1 ] ; } if ( j > 1 ) { d [ i ] [ j ] += d [ i - 1 ] [ j - 2 ] ; } d [ i ] [ j ] %= 10007 ; } } return d [ n - 1 ] [ m - 1 ] ; } }


import java . util . * ; import java . io . * ; public class x { static int fla ( int p , int q ) { int ti = 2 * q - p ; int tj = 2 * p - q ; if ( ti % 3 != 0 || tj % 3 != 0 ) return 0 ; ti /= 3 ; tj /= 3 ; return 0 ; } ; public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; for ( int tt = 1 ; tt <= t ; tt ++ ) { int h = in . nextInt ( ) ; int w = in . nextInt ( ) ; int r = in . nextInt ( ) ; int [ ] a = new int [ r ] , b = new int [ r ] ; boolean [ ] [ ] f = new boolean [ h + 1 ] [ w + 1 ] ; for ( int i = 0 ; i < r ; i ++ ) { a [ i ] = in . nextInt ( ) ; b [ i ] = in . nextInt ( ) ; f [ a [ i ] ] [ b [ i ] ] = true ; } ; int [ ] [ ] D = new int [ h + 1 ] [ w + 1 ] ; D [ 1 ] [ 1 ] = 1 ; for ( int i = 2 ; i <= h ; i ++ ) for ( int j = 2 ; j <= w ; j ++ ) if ( ! f [ i ] [ j ] ) D [ i ] [ j ] += ( D [ i - 2 ] [ j - 1 ] + D [ i - 1 ] [ j - 2 ] ) % 10007 ; System . out . println ( " Case ▁ # " + tt + " : ▁ " + D [ h ] [ w ] ) ; } ; } ; } ;


import java . io . * ; import java . util . * ; public class Round0D { int cases ; void process ( Scanner scanner , PrintStream out ) throws IOException { cases = scanner . nextInt ( ) ; scanner . nextLine ( ) ; for ( int curCase = 0 ; curCase < cases ; curCase ++ ) { long K = scanner . nextLong ( ) ; long C = scanner . nextLong ( ) ; long S = scanner . nextLong ( ) ; if ( C * S < K ) { out . println ( " Case ▁ # " + ( curCase + 1 ) + " : ▁ IMPOSSIBLE " ) ; } else { out . print ( " Case ▁ # " + ( curCase + 1 ) + " : " ) ; long k = 0 ; for ( long s = 0 ; s < S && k < K ; s ++ ) { long num = 0 ; for ( int i = 0 ; i < C ; i ++ ) { num = num * K + ( k % K ) ; k ++ ; } out . print ( ' ▁ ' ) ; out . print ( num + 1 ) ; } out . println ( ) ; } } } Round0D ( ) throws IOException { Scanner in = new Scanner ( new File ( " C : \\ Users \\ Olaf \\ Downloads \\ D - large . in " ) ) ; PrintStream out = new PrintStream ( " out - D - large . txt " ) ; process ( in , out ) ; in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new Round0D ( ) ; } }

import sys NEW_LINE def fract ( K , C , S ) : NEW_LINE INDENT if S * C < K : return " IMPOSSIBLE " NEW_LINE l = [ ] NEW_LINE for c in range ( 0 , K , C ) : NEW_LINE INDENT t = 0 NEW_LINE for i in range ( C ) : t = t * K + min ( c + i , K - 1 ) NEW_LINE l . append ( t ) NEW_LINE DEDENT return ' ▁ ' . join ( [ str ( i + 1 ) for i in l ] ) NEW_LINE DEDENT case = 0 NEW_LINE for x in sys . stdin : NEW_LINE INDENT if case > 0 : NEW_LINE INDENT [ K , C , S ] = [ int ( y ) for y in x . strip ( ) . split ( ) ] NEW_LINE print " Case ▁ # % d : " % case , fract ( K , C , S ) NEW_LINE DEDENT case += 1 NEW_LINE DEDENT


t = int ( input ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT k , c , s = map ( int , input ( ) . split ( ) ) NEW_LINE if c * s < k : NEW_LINE INDENT print ( " Case ▁ # % d : ▁ IMPOSSIBLE " % ( i + 1 ) ) NEW_LINE continue NEW_LINE DEDENT pos = [ ] NEW_LINE x = 0 NEW_LINE while x < k : NEW_LINE INDENT a = 0 NEW_LINE for _ in range ( c ) : NEW_LINE INDENT a *= k NEW_LINE a += min ( x , k - 1 ) NEW_LINE if x < k : NEW_LINE INDENT x += 1 NEW_LINE DEDENT DEDENT pos . append ( str ( a + 1 ) ) NEW_LINE DEDENT print ( " Case ▁ # % d : ▁ % s " % ( i + 1 , " ▁ " . join ( pos ) ) ) NEW_LINE DEDENT


import os , inspect NEW_LINE problemName = ' fractiles ' NEW_LINE runOnRealData = True NEW_LINE def solution ( K , C , S ) : NEW_LINE INDENT necessaryTiles = ( K + C - 1 ) / C NEW_LINE if S < necessaryTiles : NEW_LINE INDENT return [ ' IMPOSSIBLE ' ] NEW_LINE DEDENT result = [ ] NEW_LINE k = 0 NEW_LINE level = 0 NEW_LINE tile = 0 NEW_LINE while len ( result ) < necessaryTiles : NEW_LINE INDENT tile = ( tile * K ) + min ( k , K - 1 ) NEW_LINE level += 1 NEW_LINE k += 1 NEW_LINE if level == C : NEW_LINE INDENT result . append ( tile + 1 ) NEW_LINE level = 0 NEW_LINE tile = 0 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT currentDir = os . path . dirname ( os . path . abspath ( inspect . getfile ( inspect . currentframe ( ) ) ) ) NEW_LINE inputString = ' D - large . in ' NEW_LINE outputString = problemName + ( ' _ example _ output ' if not runOnRealData else ' _ output ' ) NEW_LINE inFile = os . path . join ( currentDir , ' inputfiles ' , inputString ) NEW_LINE outFile = os . path . join ( currentDir , ' outputfiles ' , ' % s . txt ' % outputString ) NEW_LINE if os . path . exists ( outFile ) : NEW_LINE INDENT os . remove ( outFile ) NEW_LINE DEDENT with open ( inFile , ' r ' ) as inputfile : NEW_LINE INDENT numberOfCases = int ( inputfile . readline ( ) ) NEW_LINE for case in xrange ( 1 , numberOfCases + 1 ) : NEW_LINE INDENT [ K , C , S ] = map ( int , inputfile . readline ( ) . split ( ' ▁ ' ) ) NEW_LINE result = solution ( K , C , S ) NEW_LINE with open ( outFile , ' a ' ) as f : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ % s \n ' % ( case , ' ▁ ' . join ( map ( str , result ) ) ) ) NEW_LINE DEDENT DEDENT DEDENT


import math NEW_LINE import sys NEW_LINE def findsol ( K , C , S ) : NEW_LINE INDENT if C * S < K : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT a = [ ] NEW_LINE flag = 0 NEW_LINE for ii in range ( S ) : NEW_LINE INDENT tmp = [ ] NEW_LINE for jj in range ( C ) : NEW_LINE INDENT x = ii * C + jj NEW_LINE if ( x >= K ) : NEW_LINE INDENT x = K - 1 NEW_LINE flag = 1 NEW_LINE DEDENT tmp . append ( x ) NEW_LINE DEDENT tmp2 = 0 NEW_LINE for jj in tmp : NEW_LINE INDENT tmp2 = K * tmp2 + jj NEW_LINE DEDENT a . append ( tmp2 + 1 ) NEW_LINE if ( flag == 1 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return a NEW_LINE DEDENT def convertnums ( s ) : NEW_LINE INDENT a = [ ] NEW_LINE ii = 0 NEW_LINE for jj in range ( len ( s ) ) : NEW_LINE INDENT if s [ jj ] == ' ▁ ' : NEW_LINE INDENT if ( ii < jj ) : NEW_LINE INDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE ii = jj + 1 NEW_LINE DEDENT DEDENT DEDENT a . append ( float ( s [ ii : jj ] ) ) NEW_LINE return a NEW_LINE DEDENT fidi = open ( ' D - large . in ' , ' r ' ) NEW_LINE fido = open ( ' a . out ' , ' w ' ) NEW_LINE T = fidi . readline ( ) NEW_LINE T = int ( T ) NEW_LINE for ii in range ( 1 , T + 1 ) : NEW_LINE INDENT tmp = fidi . readline ( ) NEW_LINE tmp = convertnums ( tmp ) NEW_LINE K = int ( tmp [ 0 ] ) NEW_LINE C = int ( tmp [ 1 ] ) NEW_LINE S = int ( tmp [ 2 ] ) NEW_LINE a = findsol ( K , C , S ) NEW_LINE if ( a [ 0 ] == ' I ' ) : NEW_LINE INDENT fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + a + ' \n ' ) NEW_LINE print ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' + a ) NEW_LINE DEDENT else : NEW_LINE INDENT fido . write ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' ) NEW_LINE for jj in a : NEW_LINE INDENT fido . write ( str ( jj ) + ' ▁ ' ) NEW_LINE DEDENT fido . write ( ' \n ' ) NEW_LINE print ( ' Case ▁ # ' + str ( ii ) + ' : ▁ ' , str ( a ) ) NEW_LINE DEDENT DEDENT fidi . close ( ) NEW_LINE fido . close ( ) NEW_LINE


import os , sys , ljqpy , time NEW_LINE time . clock ( ) NEW_LINE def RunSmall ( v ) : NEW_LINE INDENT k , c , s = map ( int , v . split ( ) ) NEW_LINE ans = [ ( i + 1 ) * k ** ( c - 1 ) for i in range ( k ) ] NEW_LINE return ' ▁ ' . join ( str ( x ) for x in ans ) NEW_LINE DEDENT def Run ( v ) : NEW_LINE INDENT k , c , s = map ( int , v . split ( ) ) NEW_LINE if s * c < k : return ' IMPOSSIBLE ' NEW_LINE ans = [ ] NEW_LINE for ii in range ( 1 , k + 1 , c ) : NEW_LINE INDENT z = 1 NEW_LINE for jj in range ( ii , min ( [ ii + c , k + 1 ] ) ) : NEW_LINE INDENT z += ( jj - 1 ) * ( k ** ( c - ( jj - ii ) - 1 ) ) NEW_LINE DEDENT ans . append ( z ) NEW_LINE DEDENT return ' ▁ ' . join ( str ( x ) for x in ans ) NEW_LINE DEDENT lst = ljqpy . LoadList ( ' D - large . in ' ) NEW_LINE outf = ' D - large . out ' NEW_LINE with open ( outf , ' w ' ) as fout : NEW_LINE INDENT for k , v in enumerate ( lst [ 1 : ] ) : NEW_LINE INDENT fout . write ( ' Case ▁ # % d : ▁ % s \n ' % ( 1 + k , Run ( v ) ) ) NEW_LINE DEDENT DEDENT os . system ( outf ) NEW_LINE print ( ' completed ' ) NEW_LINE


package qualification ; import java . io . * ; import java . math . * ; import java . util . * ; public class D_Fractiles { private static final String FILENAME = " data / qualification / D - large " ; private static final boolean STANDARD_OUTPUT = false ; private static BufferedReader in = null ; private static PrintStream out = null ; public static void main ( String [ ] args ) throws Throwable { try ( BufferedReader reader = in = new BufferedReader ( new FileReader ( FILENAME + " . in " ) ) ) { try ( PrintStream writer = out = ! STANDARD_OUTPUT ? new PrintStream ( FILENAME + " . out " ) : System . out ) { process ( ) ; } } } private static void process ( ) throws Throwable { for ( int caseNumber = 1 , T = Integer . parseInt ( in . readLine ( ) ) ; caseNumber <= T ; caseNumber ++ ) { StringTokenizer tokenizer = new StringTokenizer ( in . readLine ( ) ) ; K = Integer . parseInt ( tokenizer . nextToken ( ) ) ; C = Integer . parseInt ( tokenizer . nextToken ( ) ) ; S = Integer . parseInt ( tokenizer . nextToken ( ) ) ; positions = new ArrayList < > ( ) ; visited = new HashSet < > ( ) ; f ( BigInteger . ZERO , 0 ) ; out . print ( " Case ▁ # " + caseNumber + " : " ) ; if ( positions . size ( ) <= S ) { for ( BigInteger position : positions ) { out . print ( " ▁ " + position . add ( BigInteger . ONE ) ) ; } out . println ( ) ; } else { out . println ( " ▁ IMPOSSIBLE " ) ; } } } static int K , C , S ; static List < BigInteger > positions ; static Set < Integer > visited ; static void f ( BigInteger start , int c ) { if ( c == C || visited . size ( ) == K ) { positions . add ( start ) ; } else { BigInteger childSize = BigInteger . valueOf ( K ) . pow ( C - c - 1 ) ; for ( int i = 0 ; i < K ; i ++ ) { if ( ! visited . contains ( i ) ) { visited . add ( i ) ; f ( start . add ( childSize . multiply ( BigInteger . valueOf ( i ) ) ) , c + 1 ) ; if ( c > 0 ) break ; } } } } }


package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long k = in . nextInt ( ) ; long c = in . nextInt ( ) ; int s = in . nextInt ( ) ; System . out . print ( " Case ▁ # " + ( i + 1 ) + " : ▁ " ) ; if ( c * s < k ) { System . out . println ( " IMPOSSIBLE " ) ; } else { long val = 0 ; while ( s > 0 ) { long exp = 1 ; long total = 0 ; while ( exp < Math . pow ( k , c ) ) { total += val * exp ; exp *= k ; if ( val < k - 1 ) { val ++ ; } } s -- ; System . out . print ( total + 1 ) ; if ( total + 1 == Math . pow ( k , c ) ) { s = 0 ; } if ( s != 0 ) { System . out . print ( " ▁ " ) ; } else { System . out . println ( ) ; } } } } } }


package cj2016 . qr ; import java . io . * ; import java . util . * ; public class D { Scanner sc ; PrintWriter pw ; int K , C , S ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : " D - large " ; try { new D ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + " . in " ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + " . out " ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( " Case ▁ # " + test + " : ▁ " ) ; System . out . print ( " Case ▁ # " + test + " : ▁ " ) ; solve ( ) ; } System . out . println ( " Finished . " ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { K = sc . nextInt ( ) ; C = sc . nextInt ( ) ; S = sc . nextInt ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } public void solve ( ) { if ( C * S < K ) { println ( " IMPOSSIBLE " ) ; return ; } int M = ( K + C - 1 ) / C ; long [ ] pos = new long [ M ] ; for ( int i = 0 ; i < K ; i ++ ) { pos [ i / C ] += pow ( K , i % C ) * i ; } for ( int i = 0 ; i < M ; i ++ ) print ( ( pos [ i ] + 1 ) + ( i == M - 1 ? " \n " : " ▁ " ) ) ; } long pow ( long a , int b ) { long ans = 1 ; for ( int i = 0 ; i < b ; i ++ ) ans *= a ; return ans ; } }


import java . io . * ; import java . util . * ; public class D { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( " src / D - large . in " ) ) ) ) ; String output = " " ; int t = sc . nextInt ( ) ; for ( int i = 1 ; i <= t ; i ++ ) { int k = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; if ( s * c < k ) { output += " Case ▁ # " + i + " : ▁ IMPOSSIBLE \n " ; continue ; } ArrayList < Long > nums = new ArrayList < Long > ( ) ; for ( int j = 0 ; j < s ; j ++ ) { if ( j * c >= k ) break ; long next = 0 ; long mult = 1 ; for ( int m = 0 ; m < c ; m ++ ) { if ( j * c + m >= k ) break ; next += ( j * c + m ) * mult ; mult *= k ; } next ++ ; nums . add ( next ) ; } String toAdd = " " ; for ( int j = 0 ; j < nums . size ( ) ; j ++ ) { toAdd += " ▁ " + nums . get ( j ) ; } output += " Case ▁ # " + i + " : " + toAdd + " \n " ; } BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( " src / D - large . out " ) , " utf - 8" ) ) ; bw . write ( output ) ; bw . close ( ) ; } }


import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Welcome { public static void main ( String [ ] args ) throws Exception { int i , j , k , p ; char c ; int res ; String score ; String line ; String sentence ; String original = " welcome ▁ to ▁ code ▁ jam " ; int N , M ; BufferedReader br = new BufferedReader ( new FileReader ( " C - large . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( " C - large . out " ) ) ) ; StringTokenizer st ; line = br . readLine ( ) ; N = Integer . parseInt ( line ) ; for ( k = 1 ; k <= N ; k ++ ) { sentence = br . readLine ( ) ; M = sentence . length ( ) ; int opt [ ] [ ] = new int [ M ] [ 19 ] ; for ( i = 0 ; i < M ; i ++ ) { c = sentence . charAt ( i ) ; if ( c == ' w ' ) { opt [ i ] [ 0 ] = 1 ; } for ( j = 1 ; j < 19 ; j ++ ) { if ( c == original . charAt ( j ) ) { for ( p = 0 ; p < i ; p ++ ) { opt [ i ] [ j ] = ( opt [ i ] [ j ] + opt [ p ] [ j - 1 ] ) % 10000 ; } } } } res = 0 ; for ( i = 0 ; i < M ; i ++ ) { res = ( res + opt [ i ] [ 18 ] ) % 10000 ; } score = Integer . toString ( res ) ; while ( score . length ( ) < 4 ) { score = '0' + score ; } out . println ( " Case ▁ # " + k + " : ▁ " + score ) ; } out . close ( ) ; System . exit ( 0 ) ; } }

import sys NEW_LINE S = " welcome ▁ to ▁ code ▁ jam " NEW_LINE LS = len ( S ) NEW_LINE def main ( ) : NEW_LINE INDENT n = int ( raw_input ( ) . strip ( ) ) NEW_LINE for I in range ( n ) : NEW_LINE INDENT L = raw_input ( ) . strip ( ) NEW_LINE LL = len ( L ) NEW_LINE t = [ [ 0 ] * ( LL + 1 ) for _ in range ( LS + 1 ) ] NEW_LINE for j in range ( LL + 1 ) : NEW_LINE INDENT t [ 0 ] [ j ] = 1 NEW_LINE DEDENT for i in range ( 1 , LS + 1 ) : NEW_LINE INDENT for j in range ( 1 , LL + 1 ) : NEW_LINE INDENT if S [ i - 1 ] == L [ j - 1 ] : NEW_LINE INDENT t [ i ] [ j ] = t [ i ] [ j - 1 ] + t [ i - 1 ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT t [ i ] [ j ] = t [ i ] [ j - 1 ] NEW_LINE DEDENT DEDENT DEDENT sys . stdout . write ( " Case ▁ # % d : ▁ % 04d \n " % ( I + 1 , t [ LS ] [ LL ] % 10000 ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


text = [ line . strip ( " \n " ) for line in open ( " C . in " , " rt " ) . readlines ( ) ] NEW_LINE outfile = open ( " C . out " , " wt " ) NEW_LINE MOD = 10000 NEW_LINE searched_string = " welcome ▁ to ▁ code ▁ jam " NEW_LINE tests = int ( text [ 0 ] ) NEW_LINE offset = 1 NEW_LINE for test in range ( 1 , tests + 1 ) : NEW_LINE INDENT line = text [ offset ] NEW_LINE print line NEW_LINE line = " # " + line NEW_LINE found = { } NEW_LINE for x in range ( len ( line ) ) : NEW_LINE INDENT found [ x ] = [ 0 ] * ( len ( searched_string ) + 1 ) NEW_LINE if x == 0 : NEW_LINE INDENT found [ x ] [ 0 ] = 1 NEW_LINE DEDENT for found_idx in range ( 0 , len ( searched_string ) ) : NEW_LINE INDENT if line [ x ] == searched_string [ found_idx ] : NEW_LINE INDENT for y in range ( x ) : NEW_LINE INDENT found [ x ] [ found_idx + 1 ] += found [ y ] [ found_idx ] NEW_LINE found [ x ] [ found_idx + 1 ] %= MOD NEW_LINE DEDENT DEDENT DEDENT DEDENT ans = str ( ( sum ( line [ - 1 ] for line in found . values ( ) ) ) % MOD ) NEW_LINE ans = "0" * ( 4 - len ( ans ) ) + ans NEW_LINE assert ( len ( ans ) == 4 ) NEW_LINE print " Case ▁ # % s : ▁ % s " % ( test , ans ) NEW_LINE outfile . write ( " Case ▁ # % s : ▁ % s \n " % ( test , ans ) ) NEW_LINE offset += 1 NEW_LINE DEDENT


import heapq NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE def memoize ( function ) : NEW_LINE INDENT cache = { } NEW_LINE def decorated_function ( * args ) : NEW_LINE INDENT if args in cache : NEW_LINE INDENT return cache [ args ] NEW_LINE DEDENT else : NEW_LINE INDENT val = function ( * args ) NEW_LINE cache [ args ] = val NEW_LINE return val NEW_LINE DEDENT DEDENT return decorated_function NEW_LINE DEDENT class Case : NEW_LINE INDENT def __init__ ( self , s , caseNum ) : NEW_LINE INDENT self . caseNum = caseNum NEW_LINE self . string = s . read ( ) NEW_LINE DEDENT def solve ( self ) : NEW_LINE INDENT return " % 04d " % ( self . count_find ( " welcome ▁ to ▁ code ▁ jam " , self . string ) % 10000 ) NEW_LINE DEDENT @ memoize NEW_LINE def count_find ( self , sub , string ) : NEW_LINE INDENT if len ( sub ) == 0 or len ( sub ) > len ( string ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if len ( sub ) == 1 : NEW_LINE INDENT return string . count ( sub ) NEW_LINE DEDENT raw = self . count_find ( sub , string [ 1 : ] ) % 10000 NEW_LINE if sub [ 0 ] != string [ 0 ] : NEW_LINE INDENT return raw NEW_LINE DEDENT return ( raw + self . count_find ( sub [ 1 : ] , string [ 1 : ] ) ) % 10000 NEW_LINE DEDENT def __repr__ ( self ) : NEW_LINE INDENT return " Problem ▁ C ▁ Case ▁ % d " % self . caseNum NEW_LINE DEDENT DEDENT class Contents : NEW_LINE INDENT def __init__ ( self , f ) : NEW_LINE INDENT self . data = [ line . strip ( ) for line in f ] NEW_LINE self . i = 0 NEW_LINE DEDENT def read ( self ) : NEW_LINE INDENT return self . readList ( 1 ) [ 0 ] NEW_LINE DEDENT def readList ( self , len ) : NEW_LINE INDENT result = self . data [ self . i : self . i + len ] NEW_LINE self . i += len NEW_LINE return result NEW_LINE DEDENT DEDENT def run ( ) : NEW_LINE INDENT import sys NEW_LINE f = file ( sys . argv [ 1 ] ) NEW_LINE s = Contents ( f ) NEW_LINE numCases = int ( s . read ( ) ) NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT case = Case ( s , caseNum ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( caseNum + 1 , case . solve ( ) ) NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT run ( ) NEW_LINE DEDENT


from sys import stdin NEW_LINE from sys import stdout NEW_LINE pattern = ' welcome ▁ to ▁ code ▁ jam ' NEW_LINE ip = { } NEW_LINE for i , c in enumerate ( pattern ) : NEW_LINE INDENT ip . setdefault ( c , [ ] ) . append ( i ) NEW_LINE DEDENT n = len ( pattern ) NEW_LINE N = int ( stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( 1 , N + 1 ) : NEW_LINE INDENT line = stdin . readline ( ) . strip ( ) NEW_LINE ans = [ ] NEW_LINE for p , c in enumerate ( line ) : NEW_LINE INDENT val = [ 0 ] * n NEW_LINE if c in ip : NEW_LINE INDENT for j in ip [ c ] : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT val [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT for k in xrange ( p ) : NEW_LINE INDENT val [ j ] += ans [ k ] [ j - 1 ] NEW_LINE DEDENT val [ j ] %= 10000 NEW_LINE DEDENT DEDENT DEDENT ans . append ( val ) NEW_LINE DEDENT total = 0 NEW_LINE for val in ans : NEW_LINE INDENT total += val [ n - 1 ] NEW_LINE DEDENT stdout . write ( ' Case ▁ # % d : ▁ % 04d \n ' % ( i , total % 10000 ) ) NEW_LINE DEDENT


import numpy NEW_LINE import scipy NEW_LINE import sys NEW_LINE import csv NEW_LINE from numpy import ones NEW_LINE from numpy import size NEW_LINE import math NEW_LINE def __main__ ( ) : NEW_LINE INDENT input = sys . argv [ 1 ] NEW_LINE r = csv . reader ( open ( input ) , delimiter = ' \n ' , quoting = csv . QUOTE_NONE ) NEW_LINE n = int ( r . next ( ) [ 0 ] ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT [ text ] = r . next ( ) NEW_LINE print " Case ▁ # " + str ( i + 1 ) + " : ▁ " + solve ( text ) NEW_LINE DEDENT DEDENT def solve ( text ) : NEW_LINE INDENT welcome = ' welcome ▁ to ▁ code ▁ jam ' NEW_LINE row = len ( welcome ) NEW_LINE col = len ( text ) NEW_LINE m = ones ( [ row , col ] , dtype = int ) * ( - 1 ) NEW_LINE n = dp ( m , welcome , text , 0 , 0 ) NEW_LINE strn = str_n ( n ) NEW_LINE return ( strn ) NEW_LINE DEDENT def dp ( m , welcome , text , x , y ) : NEW_LINE INDENT if ( x == len ( welcome ) ) : NEW_LINE INDENT return ( 1 ) NEW_LINE DEDENT elif ( y == len ( text ) ) : NEW_LINE INDENT return ( 0 ) NEW_LINE DEDENT elif ( m [ x , y ] != - 1 ) : NEW_LINE INDENT return ( m [ x , y ] ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( welcome [ x ] == text [ y ] ) : NEW_LINE INDENT m [ x , y ] = ( dp ( m , welcome , text , x + 1 , y + 1 ) + dp ( m , welcome , text , x , y + 1 ) ) % 10000 NEW_LINE DEDENT else : NEW_LINE INDENT m [ x , y ] = dp ( m , welcome , text , x , y + 1 ) NEW_LINE DEDENT return ( m [ x , y ] ) NEW_LINE DEDENT DEDENT def str_n ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return ( '0000' ) NEW_LINE DEDENT m = int ( 4 - ( math . floor ( math . log10 ( n ) ) + 1 ) ) NEW_LINE strn = str ( n ) NEW_LINE for i in range ( 0 , m ) : NEW_LINE INDENT strn = '0' + strn NEW_LINE DEDENT return ( strn ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : __main__ ( ) NEW_LINE


package gcj2009 . qual ; import java . io . * ; import java . util . * ; import static java . lang . Math . * ; public class C { static final int INF = 1 << 20 ; static final int [ ] di = { - 1 , 0 , 0 , 1 } ; static final int [ ] dj = { 0 , - 1 , 1 , 0 } ; static final char [ ] key = " welcome ▁ to ▁ code ▁ jam " . toCharArray ( ) ; static final int mod = 10000 ; public void run ( ) { char [ ] input = sc . nextLine ( ) . toCharArray ( ) ; int [ ] dp = new int [ key . length + 1 ] ; dp [ 0 ] = 1 ; for ( char c : input ) for ( int i = key . length - 1 ; i >= 0 ; i -- ) if ( key [ i ] == c ) dp [ i + 1 ] = ( dp [ i + 1 ] + dp [ i ] ) % mod ; System . out . printf ( " % 04d % n " , dp [ key . length ] ) ; } public static void main ( String ... args ) { try { System . setIn ( new FileInputStream ( " C - large . in " ) ) ; System . setOut ( new PrintStream ( " C - large . out " ) ) ; } catch ( Exception e ) { } sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { System . out . printf ( " Case ▁ # % d : ▁ " , t ) ; new C ( ) . run ( ) ; } } static Scanner sc ; }


package qualifiers ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; public class WelcomeToCodeJam { private char [ ] input ; private char [ ] target ; private BigInteger [ ] [ ] memo ; private BigInteger solve ( int inputIdx , int targetIdx ) { if ( memo [ inputIdx ] [ targetIdx ] != null ) return memo [ inputIdx ] [ targetIdx ] ; else { BigInteger ret = BigInteger . ZERO ; if ( inputIdx >= input . length ) { if ( targetIdx >= target . length ) { ret = BigInteger . ONE ; } else ret = BigInteger . ZERO ; } else { if ( targetIdx < target . length ) { char c1 = target [ targetIdx ] ; char c2 = input [ inputIdx ] ; if ( c1 == c2 ) ret = ret . add ( solve ( inputIdx + 1 , targetIdx + 1 ) ) ; } ret = ret . add ( solve ( inputIdx + 1 , targetIdx ) ) ; } memo [ inputIdx ] [ targetIdx ] = ret ; return ret ; } } public String getWelcome ( String inp , String target ) { this . input = inp . toCharArray ( ) ; this . target = target . toCharArray ( ) ; this . memo = new BigInteger [ input . length + 1 ] [ this . target . length + 1 ] ; BigInteger val = solve ( 0 , 0 ) ; String ret = val . toString ( ) ; if ( ret . length ( ) < 4 ) { for ( int i = ret . length ( ) ; i < 4 ; ++ i ) ret = "0" + ret ; } else ret = ret . substring ( ret . length ( ) - 4 ) ; return ret ; } public static void main ( String [ ] args ) throws NumberFormatException , IOException { WelcomeToCodeJam obj = new WelcomeToCodeJam ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . valueOf ( br . readLine ( ) ) ; String target = " welcome ▁ to ▁ code ▁ jam " ; for ( int i = 1 ; i <= N ; ++ i ) { String inp = br . readLine ( ) ; String ret = obj . getWelcome ( inp , target ) ; System . out . println ( " Case ▁ # " + i + " : ▁ " + ret ) ; } } }


import java . io . * ; public class Welcome { static int current [ ] ; static void inc ( int index ) { current [ index ] = ( current [ index ] + 1 ) % 10000 ; } static void move ( int index ) { current [ index + 1 ] = ( current [ index ] + current [ index + 1 ] ) % 10000 ; } private static int solve ( String line ) { String wel = " welcome ▁ to ▁ code ▁ jam " ; int length = wel . length ( ) ; current = new int [ length ] ; int i , j ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; for ( j = 0 ; j < length ; j ++ ) { if ( c == wel . charAt ( j ) ) { if ( j > 0 ) { move ( j - 1 ) ; } else { inc ( j ) ; } } } } return current [ length - 1 ] ; } public static void main ( String args [ ] ) { try { BufferedReader reader = new BufferedReader ( new FileReader ( " src / C - large . in " ) ) ; BufferedWriter writer = new BufferedWriter ( new FileWriter ( " output " ) ) ; int n = Integer . parseInt ( reader . readLine ( ) ) ; int i ; for ( i = 0 ; i < n ; i ++ ) { String line = reader . readLine ( ) ; int result = solve ( line ) ; writer . write ( " Case ▁ # " + ( i + 1 ) + " : ▁ " ) ; if ( result < 1000 ) { writer . write ( "0" ) ; } if ( result < 100 ) { writer . write ( "0" ) ; } if ( result < 10 ) { writer . write ( "0" ) ; } writer . write ( result + " " ) ; writer . newLine ( ) ; } reader . close ( ) ; writer . close ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } }


package gcj ; import java . io . BufferedReader ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . StringTokenizer ; import java . util . regex . Pattern ; public class QR_Q3 { public static void main ( String [ ] args ) throws Exception { new QR_Q3 ( ) . run ( ) ; } int N ; int [ ] map = new int [ 256 ] ; int mod = 10000 ; void run ( ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( " C - large . in " ) ) ; PrintWriter pw = new PrintWriter ( " QR _ Q3 . out " ) ; N = Integer . parseInt ( br . readLine ( ) ) ; String ph = " welcome ▁ to ▁ code ▁ jam " ; int l = ph . length ( ) ; digest ( ph ) ; for ( int n_case = 1 ; n_case <= N ; n_case ++ ) { String line = br . readLine ( ) ; int [ ] result = new int [ l + 1 ] ; result [ 0 ] = 1 ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; int amap = map [ c ] ; for ( int i_p = 0 ; i_p < l ; i_p ++ ) { if ( ( amap & 1 << i_p ) == 0 ) { } else { result [ i_p + 1 ] = ( result [ i_p ] + result [ i_p + 1 ] ) % mod ; } } } pw . printf ( " Case ▁ # % d : ▁ % 04d " , n_case , result [ l ] ) ; pw . println ( ) ; } pw . close ( ) ; } private void digest ( String ph ) { for ( int i = 0 ; i < ph . length ( ) ; i ++ ) { char c = ph . charAt ( i ) ; map [ c ] |= 1 << i ; } } }


import java . util . * ; public class a { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int T = input . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { System . out . printf ( " Case ▁ # % d : ▁ " , t + 1 ) ; int n = input . nextInt ( ) ; int p = input . nextInt ( ) , q = input . nextInt ( ) , r = input . nextInt ( ) , s = input . nextInt ( ) ; int [ ] data = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { data [ i ] = ( int ) ( ( ( long ) i * p + q ) % r + s ) ; } long lo = 1 , hi = ( long ) 1e13 ; while ( lo < hi - 1 ) { long mid = ( lo + hi ) / 2 ; if ( canDo ( data , mid ) ) hi = mid ; else lo = mid ; } if ( ! canDo ( data , lo ) ) lo ++ ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += data [ i ] ; double res = 1. * lo / sum ; System . out . printf ( " % .9f \n " , 1 - res ) ; } } static boolean canDo ( int [ ] data , long max ) { long count = 1 , sum = 0 ; int n = data . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( data [ i ] > max ) return false ; sum += data [ i ] ; if ( sum > max ) { count ++ ; sum = data [ i ] ; if ( count > 3 ) return false ; } } return count <= 3 ; } }

n = int ( raw_input ( ) ) NEW_LINE for testcase in range ( n ) : NEW_LINE INDENT [ N , p , q , r , s ] = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE transistors = [ ( i * p + q ) % r + s for i in range ( N ) ] NEW_LINE transistorsum = sum ( transistors ) NEW_LINE first = 0 NEW_LINE last = N NEW_LINE firstsum = 0 NEW_LINE lastsum = 0 NEW_LINE minimax = transistorsum NEW_LINE while last - first != 1 : NEW_LINE INDENT nextfirstsum = firstsum + transistors [ first ] NEW_LINE nextlastsum = lastsum + transistors [ last - 1 ] NEW_LINE if nextfirstsum < nextlastsum : NEW_LINE INDENT firstsum += transistors [ first ] NEW_LINE first += 1 NEW_LINE DEDENT else : NEW_LINE INDENT last -= 1 NEW_LINE lastsum += transistors [ last ] NEW_LINE DEDENT currentmax = max ( [ firstsum , lastsum , transistorsum - firstsum - lastsum ] ) NEW_LINE minimax = min ( currentmax , minimax ) NEW_LINE DEDENT answer = float ( transistorsum - minimax ) / float ( transistorsum ) NEW_LINE print " Case ▁ # % d : ▁ % .10f " % ( testcase + 1 , answer ) NEW_LINE DEDENT


from sys import stdin NEW_LINE from numpy import * NEW_LINE T = int ( stdin . readline ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT N , p , q , r , s = [ int ( word ) for word in stdin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE NT = ( arange ( N , dtype = int64 ) * p + q ) % r + s NEW_LINE PS = array ( [ 0 ] + list ( cumsum ( NT ) ) , dtype = int64 ) NEW_LINE S = PS [ - 1 ] NEW_LINE minmax = S NEW_LINE for a in range ( N ) : NEW_LINE INDENT s1 = PS [ a ] NEW_LINE b0 = searchsorted ( PS , s1 + ( S - s1 ) / 2.0 ) NEW_LINE assert b0 >= a NEW_LINE for b in ( b0 - 1 , b0 ) : NEW_LINE INDENT if 0 < b and b <= N : NEW_LINE INDENT mx = max ( s1 , PS [ b ] - PS [ a ] , S - PS [ b ] ) NEW_LINE if mx < minmax : NEW_LINE INDENT minmax = mx NEW_LINE DEDENT DEDENT DEDENT DEDENT print " Case ▁ # " + str ( t ) + " : " , float ( S - minmax ) / S NEW_LINE DEDENT


import collections NEW_LINE import sys NEW_LINE if __name__ == " _ _ main _ _ " : NEW_LINE INDENT f = sys . stdin NEW_LINE if len ( sys . argv ) >= 2 : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE if fn != ' - ' : NEW_LINE INDENT f = open ( fn ) NEW_LINE DEDENT DEDENT T = int ( f . readline ( ) ) NEW_LINE for _T in xrange ( T ) : NEW_LINE INDENT N , p , q , r , s = map ( int , f . readline ( ) . split ( ) ) NEW_LINE transistors = [ ( i * p + q ) % r + s for i in xrange ( N ) ] NEW_LINE total = sum ( transistors ) NEW_LINE sums = [ ] NEW_LINE t = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT sums . append ( t ) NEW_LINE t += transistors [ i ] NEW_LINE DEDENT sums . append ( t ) NEW_LINE assert t == total NEW_LINE def can3 ( p ) : NEW_LINE INDENT needed = ( 1 - p ) * total NEW_LINE for i in xrange ( N - 1 , 0 , - 1 ) : NEW_LINE INDENT if sums [ i ] <= needed : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT for j in xrange ( N - 1 , i - 1 , - 1 ) : NEW_LINE INDENT if sums [ j + 1 ] - sums [ i ] <= needed : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT if total - sums [ j + 1 ] <= needed : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def can2 ( p ) : NEW_LINE INDENT needed = ( 1 - p ) * total NEW_LINE for i in xrange ( N - 1 , 0 , - 1 ) : NEW_LINE INDENT if sums [ i ] <= needed : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT if total - sums [ i ] <= needed : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT low = 0.0 NEW_LINE high = 1.0 NEW_LINE for i in xrange ( 40 ) : NEW_LINE INDENT g = ( low + high ) * 0.5 NEW_LINE if can3 ( g ) or can2 ( g ) : NEW_LINE INDENT low = g NEW_LINE DEDENT else : NEW_LINE INDENT high = g NEW_LINE DEDENT DEDENT print " Case ▁ # % d : ▁ % .10f " % ( _T + 1 , low ) NEW_LINE DEDENT DEDENT


import sys NEW_LINE import bisect NEW_LINE def compute ( N , p , q , r , s ) : NEW_LINE INDENT a = [ 0 ] NEW_LINE last = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT x = ( i * p + q ) % r + s NEW_LINE last += 2 * x NEW_LINE a . append ( last ) NEW_LINE DEDENT best = 0.0 NEW_LINE if a [ - 1 ] == 0 : NEW_LINE INDENT return 0.0 NEW_LINE DEDENT q = ( 0 , 0 , 0 ) NEW_LINE for i in xrange ( len ( a ) ) : NEW_LINE INDENT first = a [ i ] NEW_LINE need = first + ( a [ - 1 ] - first ) / 2 NEW_LINE pos = bisect . bisect_left ( a , need ) NEW_LINE second = a [ pos ] - first NEW_LINE third = a [ - 1 ] - first - second NEW_LINE m = a [ - 1 ] - max ( first , second , third ) NEW_LINE if float ( m ) / float ( a [ - 1 ] ) > best : NEW_LINE INDENT q = ( i , pos ) NEW_LINE best = float ( m ) / float ( a [ - 1 ] ) NEW_LINE DEDENT if pos - 1 > i : NEW_LINE INDENT second = a [ pos - 1 ] - first NEW_LINE third = a [ - 1 ] - first - second NEW_LINE m = a [ - 1 ] - max ( first , second , third ) NEW_LINE if float ( m ) / float ( a [ - 1 ] ) > best : NEW_LINE INDENT best = float ( m ) / float ( a [ - 1 ] ) NEW_LINE q = ( i , pos - 1 ) NEW_LINE DEDENT DEDENT DEDENT return best NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT N , p , q , r , s = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE return N , p , q , r , s NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT sys . setrecursionlimit ( 100000 ) NEW_LINE T = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT data = parse ( ) NEW_LINE result = compute ( * data ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i + 1 , result ) NEW_LINE DEDENT DEDENT


num_trials = int ( input ( ) ) NEW_LINE def in_range ( a , b , S ) : NEW_LINE INDENT return S [ b + 1 ] - S [ a ] NEW_LINE DEDENT def compute ( ) : NEW_LINE INDENT N , p , q , r , s = map ( int , input ( ) . split ( ) ) NEW_LINE S = [ 0 ] * ( N + 1 ) NEW_LINE S [ 0 ] = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT S [ i + 1 ] = ( p * i + q ) % r + s + S [ i ] NEW_LINE DEDENT a_lo = 0 NEW_LINE a_hi = N - 1 NEW_LINE min_solveig_score = S [ N ] + 1 NEW_LINE while a_lo <= a_hi : NEW_LINE INDENT a_try = ( a_lo + a_hi ) // 2 NEW_LINE lo_range = S [ a_try ] NEW_LINE b_lo = a_try NEW_LINE b_hi = N - 1 NEW_LINE min_max_mid_hi = S [ N ] + 1 NEW_LINE while b_lo <= b_hi : NEW_LINE INDENT b_try = ( b_lo + b_hi ) // 2 NEW_LINE mid_range = S [ b_try + 1 ] - S [ a_try ] NEW_LINE hi_range = S [ N ] - S [ b_try + 1 ] NEW_LINE min_max_mid_hi = min ( min_max_mid_hi , max ( mid_range , hi_range ) ) NEW_LINE if mid_range > hi_range : NEW_LINE INDENT b_hi = b_try - 1 NEW_LINE DEDENT elif mid_range < hi_range : NEW_LINE INDENT b_lo = b_try + 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT min_solveig_score = min ( min_solveig_score , max ( lo_range , min_max_mid_hi ) ) NEW_LINE if lo_range > min_max_mid_hi : NEW_LINE INDENT a_hi = a_try - 1 NEW_LINE DEDENT elif lo_range < min_max_mid_hi : NEW_LINE INDENT a_lo = a_try + 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return ( " % 1.10f " % ( 1 - min_solveig_score / S [ N ] ) ) NEW_LINE DEDENT for i in range ( 0 , num_trials ) : NEW_LINE INDENT print ( " Case ▁ # " + str ( i + 1 ) + " : ▁ " + str ( compute ( ) ) ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; public class Dancing { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < T ; i ++ ) { StringTokenizer st = new StringTokenizer ( in . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int S = Integer . parseInt ( st . nextToken ( ) ) ; int p = Integer . parseInt ( st . nextToken ( ) ) ; int [ ] scores = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { scores [ j ] = Integer . parseInt ( st . nextToken ( ) ) ; } int ans = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( p == 0 ) { ans ++ ; continue ; } if ( scores [ j ] == 0 ) continue ; if ( scores [ j ] / 3 >= p ) { ans ++ ; } else if ( scores [ j ] / 3 == p - 1 && scores [ j ] % 3 > 0 ) { ans ++ ; } else if ( scores [ j ] / 3 == p - 1 && scores [ j ] % 3 == 0 && S > 0 ) { ans ++ ; S -- ; } else if ( scores [ j ] / 3 == p - 2 && scores [ j ] % 3 == 2 && S > 0 ) { ans ++ ; S -- ; } } System . out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + ans ) ; } } }

import sys NEW_LINE L = 30 NEW_LINE normal = [ 0 , 1 ] NEW_LINE surprise = [ 0 , 1 ] NEW_LINE for i in range ( 2 , L + 1 ) : NEW_LINE INDENT normal . append ( i / 3 + ( ( i % 3 ) > 0 ) ) NEW_LINE surprise . append ( 2 + ( i - 2 ) / 3 ) NEW_LINE DEDENT for case_index in range ( 1 , 1 + input ( ) ) : NEW_LINE INDENT sys . stderr . write ( str ( case_index ) + ' ▁ ' ) NEW_LINE v = map ( int , raw_input ( ) . split ( ) ) NEW_LINE N = v . pop ( 0 ) NEW_LINE S = v . pop ( 0 ) NEW_LINE p = v . pop ( 0 ) NEW_LINE res = 0 NEW_LINE a = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if p <= normal [ v [ i ] ] : NEW_LINE INDENT res += 1 NEW_LINE DEDENT elif surprise [ v [ i ] ] == p : NEW_LINE INDENT a += 1 NEW_LINE DEDENT DEDENT if S < a : NEW_LINE INDENT a = S NEW_LINE DEDENT res += a NEW_LINE print ' Case ▁ # % s : ▁ % s ' % ( case_index , res ) NEW_LINE DEDENT sys . stderr . write ( ' \n ' ) NEW_LINE


dull_modifiers = [ ( 0 , 0 , 0 ) , ( 0 , 0 , 1 ) , ( 0 , 1 , 1 ) ] NEW_LINE surp_modifiers = [ ( - 1 , 0 , 1 ) , ( - 1 , 1 , 1 ) , ( 0 , 0 , 2 ) ] NEW_LINE def solvecase ( target , surprising , values ) : NEW_LINE INDENT total_dull_count = 0 NEW_LINE surp_deltas = [ ] NEW_LINE for v in values : NEW_LINE INDENT dull_scores = [ ( v // 3 ) + m for m in dull_modifiers [ v % 3 ] ] NEW_LINE surp_scores = [ ( v // 3 ) + m for m in surp_modifiers [ v % 3 ] ] NEW_LINE dull_count = int ( bool ( len ( [ s for s in dull_scores if s >= target ] ) ) ) NEW_LINE surp_count = int ( bool ( len ( [ s for s in surp_scores if s >= target ] ) ) ) NEW_LINE total_dull_count += dull_count NEW_LINE if any ( ( score < 0 ) or ( score > 10 ) for score in surp_scores ) : NEW_LINE INDENT continue NEW_LINE DEDENT surp_deltas . append ( surp_count - dull_count ) NEW_LINE DEDENT surp_deltas . sort ( ) NEW_LINE count = total_dull_count + ( sum ( surp_deltas [ - surprising : ] ) if surprising > 0 else 0 ) NEW_LINE return count NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT cases = int ( raw_input ( ) ) NEW_LINE for c in range ( cases ) : NEW_LINE INDENT values = map ( int , raw_input ( ) . split ( ) ) NEW_LINE surprising = values [ 1 ] NEW_LINE target = values [ 2 ] NEW_LINE totals = values [ 3 : ] NEW_LINE count = solvecase ( target , surprising , totals ) NEW_LINE print " Case ▁ # { 0 } : ▁ { 1 } " . format ( c + 1 , count ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE


import sys , re , string , math , fractions , itertools NEW_LINE from fractions import Fraction NEW_LINE ssr = sys . stdin . readline NEW_LINE ssw = sys . stdout . write NEW_LINE def rdline ( ) : return ssr ( ) . strip ( ) NEW_LINE def rdstrs ( ) : return ssr . split ( ) NEW_LINE def rdints ( ) : return map ( int , ssr ( ) . split ( ) ) NEW_LINE def do_one_case ( cnum ) : NEW_LINE INDENT v = rdints ( ) NEW_LINE ( N , S , p ) = v [ : 3 ] NEW_LINE t = v [ 3 : ] NEW_LINE assert len ( t ) == N NEW_LINE nums = 0 NEW_LINE numns = 0 NEW_LINE for x in t : NEW_LINE INDENT mn = max ( 0 , x / 3 - 1 ) NEW_LINE mx = min ( 10 , ( x + 2 ) / 3 + 1 ) NEW_LINE r = range ( mn , mx + 1 ) NEW_LINE tplx = [ ( s1 , s2 , s3 ) for s1 in r for s2 in r for s3 in r if s1 + s2 + s3 == x ] NEW_LINE tpls = [ tt for tt in tplx if max ( tt ) - min ( tt ) <= 2 ] NEW_LINE tplns = [ tt for tt in tpls if max ( tt ) - min ( tt ) < 2 ] NEW_LINE maxs = max ( [ - 99 ] + [ max ( tt ) for tt in tpls ] ) NEW_LINE maxns = max ( [ - 99 ] + [ max ( tt ) for tt in tplns ] ) NEW_LINE if maxs >= p : nums += 1 NEW_LINE if maxns >= p : numns += 1 NEW_LINE DEDENT nn = min ( nums , numns + S ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( cnum , nn ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N = int ( rdline ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT do_one_case ( i + 1 ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


with open ( ' B - large . in ' , ' r ' ) as fin : NEW_LINE INDENT with open ( ' output . txt ' , ' w ' ) as fout : NEW_LINE INDENT numcases = int ( fin . readline ( ) ) NEW_LINE for i in range ( 1 , numcases + 1 ) : NEW_LINE INDENT line = [ int ( j ) for j in fin . readline ( ) . split ( ) ] NEW_LINE surprising = line [ 1 ] NEW_LINE minscore = line [ 2 ] NEW_LINE oknum = 0 NEW_LINE needsSurprising = 0 NEW_LINE for j in line [ 3 : ] : NEW_LINE INDENT d = j / 3 NEW_LINE m = j % 3 NEW_LINE if m == 0 : NEW_LINE INDENT if d >= minscore : NEW_LINE INDENT oknum += 1 NEW_LINE DEDENT elif d >= minscore - 1 and d > 0 : NEW_LINE INDENT needsSurprising += 1 NEW_LINE DEDENT DEDENT elif m == 1 : NEW_LINE INDENT if d >= minscore - 1 : NEW_LINE INDENT oknum += 1 NEW_LINE DEDENT DEDENT elif m == 2 : NEW_LINE INDENT if d >= minscore - 1 : NEW_LINE INDENT oknum += 1 NEW_LINE DEDENT elif d >= minscore - 2 : NEW_LINE INDENT needsSurprising += 1 NEW_LINE DEDENT DEDENT DEDENT fout . write ( " Case ▁ # " ) NEW_LINE fout . write ( str ( i ) ) NEW_LINE fout . write ( " : ▁ " ) NEW_LINE fout . write ( str ( oknum + min ( surprising , needsSurprising ) ) ) NEW_LINE fout . write ( ' \n ' ) NEW_LINE DEDENT DEDENT DEDENT


T = input ( ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT inp = raw_input ( ) . split ( ) NEW_LINE [ N , S , p ] = [ int ( s ) for s in inp [ 0 : 3 ] ] NEW_LINE ts = [ int ( s ) for s in inp [ 3 : ] ] NEW_LINE min_without_surprise = p + 2 * max ( p - 1 , 0 ) NEW_LINE min_with_surprise = p + 2 * max ( p - 2 , 0 ) NEW_LINE without_surprise = 0 NEW_LINE with_surprise = 0 NEW_LINE for ti in ts : NEW_LINE INDENT if ti >= min_without_surprise : NEW_LINE INDENT without_surprise += 1 NEW_LINE DEDENT elif ti >= min_with_surprise : NEW_LINE INDENT with_surprise += 1 NEW_LINE DEDENT DEDENT answer = without_surprise + min ( with_surprise , S ) NEW_LINE print " Case ▁ # " + str ( t ) + " : ▁ " + str ( answer ) NEW_LINE DEDENT


package j2012qualifier ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class B { public static String inputDirectory = " src / j2012qualifier / " ; public static String inputFile = " B . in " ; public static String outputFile = " B . out " ; public static PrintWriter output ; public static void main ( String [ ] args ) throws FileNotFoundException { Scanner s = new Scanner ( new File ( inputDirectory + inputFile ) ) ; output = new PrintWriter ( new File ( inputDirectory + outputFile ) ) ; int cases = s . nextInt ( ) ; for ( int Case = 1 ; Case <= cases ; Case ++ ) { s . nextLine ( ) ; int googlers = s . nextInt ( ) ; int maxSupriseScores = s . nextInt ( ) ; int targetScore = s . nextInt ( ) ; int normalScores = 0 ; int surpriseScores = 0 ; for ( int i = 0 ; i < googlers ; i ++ ) { int score = s . nextInt ( ) ; if ( targetScore > score ) { continue ; } int otherScore = ( score - targetScore ) / 2 ; if ( otherScore >= targetScore - 1 ) { normalScores ++ ; } else if ( otherScore >= targetScore - 2 ) { surpriseScores ++ ; } } int answer = normalScores + Math . min ( surpriseScores , maxSupriseScores ) ; out ( " Case ▁ # " + Case + " : ▁ " + answer ) ; } output . flush ( ) ; } public static void out ( String s ) { output . println ( s ) ; } }


import java . io . * ; import java . util . * ; public class CodeJam2012_Q_B { public int calc ( int N , int S , int p , int [ ] score ) { int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( score [ i ] >= p + Math . max ( p - 1 , 0 ) * 2 ) { cnt ++ ; } else if ( score [ i ] >= p + Math . max ( p - 2 , 0 ) * 2 && S > 0 ) { cnt ++ ; S -- ; } } return cnt ; } public static void main ( String [ ] args ) { try { ( new CodeJam2012_Q_B ( ) ) . exec ( " B - large . in " , "2012 _ Q _ B - large . out " ) ; } catch ( Exception ex ) { } } public final void exec ( String inFileName , String outFileName ) throws Exception { BufferedReader inReader = new BufferedReader ( new FileReader ( inFileName ) ) ; PrintWriter outWriter = new PrintWriter ( new BufferedWriter ( new FileWriter ( outFileName ) ) ) ; int caseNums = 0 ; caseNums = Integer . parseInt ( inReader . readLine ( ) ) ; for ( int i = 0 ; i < caseNums ; i ++ ) { String [ ] input = inReader . readLine ( ) . split ( " ▁ " ) ; int N = Integer . valueOf ( input [ 0 ] ) ; int S = Integer . valueOf ( input [ 1 ] ) ; int p = Integer . valueOf ( input [ 2 ] ) ; int [ ] score = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) score [ j ] = Integer . valueOf ( input [ j + 3 ] ) ; int outStr = calc ( N , S , p , score ) ; String fmtOutStr = " Case ▁ # " + ( i + 1 ) + " : ▁ " + outStr ; outWriter . println ( fmtOutStr ) ; System . out . println ( fmtOutStr ) ; } System . out . println ( caseNums + " ▁ cases ▁ complete " ) ; outWriter . close ( ) ; inReader . close ( ) ; } }


import static java . lang . Double . parseDouble ; import static java . lang . Integer . parseInt ; import static java . lang . Long . parseLong ; import static java . lang . System . exit ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class B { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static int test ; static void solve ( ) throws Exception { int n = nextInt ( ) ; int s = nextInt ( ) ; int p = nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int t = nextInt ( ) ; if ( ( t + 2 ) / 3 >= p ) { ++ ans ; } else if ( s > 0 && t > 0 && ( t + 4 ) / 3 >= p ) { -- s ; ++ ans ; } } printCase ( ) ; out . println ( ans ) ; } static void printCase ( ) { out . print ( " Case ▁ # " + test + " : ▁ " ) ; } static void printlnCase ( ) { out . println ( " Case ▁ # " + test + " : " ) ; } static int nextInt ( ) throws IOException { return parseInt ( next ( ) ) ; } static long nextLong ( ) throws IOException { return parseLong ( next ( ) ) ; } static double nextDouble ( ) throws IOException { return parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } public static void main ( String [ ] args ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int tests = nextInt ( ) ; for ( test = 1 ; test <= tests ; test ++ ) { solve ( ) ; } in . close ( ) ; out . close ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; exit ( 1 ) ; } } }


import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; public class codejamp2 { public static char [ ] map ; public static void main ( String [ ] args ) throws IOException { readFile ( ) ; } public static String getResult ( String input ) { int resultInt = 0 ; String [ ] splitResult = input . split ( " ▁ " ) ; int dancerCount = Integer . parseInt ( splitResult [ 0 ] ) ; int suprising = Integer . parseInt ( splitResult [ 1 ] ) ; int max = Integer . parseInt ( splitResult [ 2 ] ) ; for ( int i = 3 ; i < dancerCount + 3 ; i ++ ) { int current = Integer . parseInt ( splitResult [ i ] ) ; int ave = current / 3 ; int remain = current - 3 * ave ; int currentmax = ave + remain ; if ( remain == 0 && ( max - currentmax == 1 ) && current != 0 ) { if ( suprising > 0 ) { suprising -- ; resultInt ++ ; } } if ( currentmax >= max ) { if ( remain <= 1 ) { resultInt ++ ; } else if ( remain == 2 ) { if ( max - ave <= 1 ) { resultInt ++ ; } else if ( suprising > 0 ) { suprising -- ; resultInt ++ ; } } } } return " " + resultInt ; } public static void readFile ( ) throws IOException { FileWriter fstream = new FileWriter ( " out . txt " ) ; BufferedWriter out = new BufferedWriter ( fstream ) ; FileReader input = new FileReader ( " in . txt " ) ; BufferedReader bufRead = new BufferedReader ( input ) ; String line = bufRead . readLine ( ) ; String current = getResult ( line ) ; int i = 1 ; out . write ( " Case ▁ # " + i + " : ▁ " + current ) ; line = bufRead . readLine ( ) ; while ( line != null ) { i ++ ; System . out . println ( " Case ▁ # " + i + " : ▁ " + getResult ( line ) ) ; out . write ( ' \n ' + " Case ▁ # " + i + " : ▁ " + getResult ( line ) ) ; line = bufRead . readLine ( ) ; } bufRead . close ( ) ; out . close ( ) ; } }


import java . io . * ; import java . math . * ; public class a { public static void main ( String [ ] args ) { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { int cases = Integer . valueOf ( input . readLine ( ) ) ; for ( int cas = 1 ; cas <= cases ; cas ++ ) { String line = input . readLine ( ) ; int digit [ ] = new int [ 256 ] ; int base = 0 , i ; BigInteger num = new BigInteger ( "0" ) ; for ( i = 0 ; i < 256 ; i ++ ) digit [ i ] = - 1 ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { if ( ( line . charAt ( i ) < '0' || line . charAt ( i ) > '9' ) && ( line . charAt ( i ) < ' a ' || line . charAt ( i ) > ' z ' ) ) continue ; if ( digit [ line . charAt ( i ) ] == - 1 ) { if ( base == 0 ) digit [ line . charAt ( i ) ] = 1 ; else if ( base == 1 ) digit [ line . charAt ( i ) ] = 0 ; else digit [ line . charAt ( i ) ] = base ; base ++ ; } } if ( base < 2 ) base = 2 ; int cnt = 0 ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { if ( ( line . charAt ( i ) < '0' || line . charAt ( i ) > '9' ) && ( line . charAt ( i ) < ' a ' || line . charAt ( i ) > ' z ' ) ) continue ; num = num . multiply ( BigInteger . valueOf ( base ) ) ; num = num . add ( BigInteger . valueOf ( digit [ line . charAt ( i ) ] ) ) ; } System . out . printf ( " Case ▁ # % d : ▁ " , cas ) ; System . out . println ( num ) ; } } catch ( java . io . IOException e ) { } } } ;

T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT string = raw_input ( ) NEW_LINE base = len ( set ( string ) ) NEW_LINE if base == 1 : base = 2 NEW_LINE ans = 1 NEW_LINE d = { string [ 0 ] : 1 } NEW_LINE next = 0 NEW_LINE for digit in string [ 1 : ] : NEW_LINE INDENT ans *= base NEW_LINE if digit in d : NEW_LINE INDENT ans += d [ digit ] NEW_LINE DEDENT else : NEW_LINE INDENT ans += next NEW_LINE d [ digit ] = next NEW_LINE next = 2 if next == 0 else next + 1 NEW_LINE DEDENT DEDENT print " Case ▁ # % d : ▁ % d " % ( t + 1 , ans ) NEW_LINE DEDENT


def get_base ( digits ) : NEW_LINE INDENT return len ( set ( list ( str ( digits ) ) ) ) NEW_LINE DEDENT def minsecond ( digits ) : NEW_LINE INDENT digits = list ( digits ) NEW_LINE new_digits = list ( ) NEW_LINE count = 1 NEW_LINE letter2digit = { } NEW_LINE tmp = digits . pop ( 0 ) NEW_LINE letter2digit [ tmp ] = str ( count ) NEW_LINE count = 0 NEW_LINE new_digits . append ( letter2digit [ tmp ] ) NEW_LINE while digits : NEW_LINE INDENT tmp = digits . pop ( 0 ) NEW_LINE if tmp in letter2digit : NEW_LINE INDENT new_digits . append ( letter2digit [ tmp ] ) NEW_LINE DEDENT else : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT letter2digit [ tmp ] = str ( count ) NEW_LINE new_digits . append ( letter2digit [ tmp ] ) NEW_LINE count = 2 NEW_LINE DEDENT else : NEW_LINE INDENT letter2digit [ tmp ] = str ( count ) NEW_LINE new_digits . append ( letter2digit [ tmp ] ) NEW_LINE count += 1 NEW_LINE DEDENT DEDENT DEDENT new_digits = int ( ' ' . join ( new_digits ) ) NEW_LINE second = cal_base ( new_digits , count ) NEW_LINE return second NEW_LINE DEDENT def cal_base ( d , base ) : NEW_LINE INDENT if base <= 1 : NEW_LINE INDENT base = 2 NEW_LINE DEDENT d = list ( str ( d ) ) NEW_LINE count = 0 NEW_LINE res = 0 NEW_LINE while d : NEW_LINE INDENT t = int ( d . pop ( ) ) NEW_LINE res += t * base ** count NEW_LINE count += 1 NEW_LINE DEDENT return res NEW_LINE DEDENT def main ( filename , result = ' result . txt ' ) : NEW_LINE INDENT rfile = open ( filename ) NEW_LINE rfile . readline ( ) NEW_LINE case = 1 NEW_LINE wfile = open ( result , ' w ' ) NEW_LINE for line in rfile : NEW_LINE INDENT d = line . strip ( ) NEW_LINE n = minsecond ( d ) NEW_LINE wfile . write ( ' Case ▁ # ' + str ( case ) + ' : ▁ ' + str ( n ) + ' \n ' ) NEW_LINE case += 1 NEW_LINE print case NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE import psyco NEW_LINE psyco . full ( ) NEW_LINE in_file = sys . argv [ 1 ] NEW_LINE main ( in_file ) NEW_LINE DEDENT


class Gcjt ( object ) : NEW_LINE INDENT class Testcase ( object ) : NEW_LINE INDENT def __init__ ( self , num , gcjt ) : NEW_LINE INDENT self . num = num NEW_LINE self . gcjt = gcjt NEW_LINE DEDENT def answer ( self , answer ) : NEW_LINE INDENT self . gcjt . outs . write ( ' Case ▁ # { num } : ▁ { ans } ' . format ( num = self . num , ans = answer ) + ' \n ' ) NEW_LINE DEDENT def ws ( self , string ) : NEW_LINE INDENT self . gcjt . outs . write ( string ) NEW_LINE DEDENT def rl ( self ) : NEW_LINE INDENT return self . gcjt . ins . readline ( ) NEW_LINE DEDENT def ri ( self ) : NEW_LINE INDENT return ( int ( s ) for s in self . rl ( ) . split ( ) ) NEW_LINE DEDENT DEDENT def __init__ ( self ) : NEW_LINE INDENT filename = input ( ' file ▁ name ▁ : ▁ ' ) NEW_LINE self . fin = filename + ' . in ' NEW_LINE self . fout = filename + ' . out ' NEW_LINE DEDENT def __enter__ ( self ) : NEW_LINE INDENT self . ins = open ( self . fin ) NEW_LINE self . outs = open ( self . fout , ' w ' ) NEW_LINE DEDENT def __exit__ ( self , errtype = None , errvalu = None , errtrace = None ) : NEW_LINE INDENT self . ins . close ( ) NEW_LINE self . outs . close ( ) NEW_LINE DEDENT def tests ( self , num = None ) : NEW_LINE INDENT with self : NEW_LINE INDENT if num is None : num = int ( self . ins . readline ( ) ) NEW_LINE for t in range ( num ) : NEW_LINE INDENT yield self . Testcase ( t + 1 , self ) NEW_LINE DEDENT DEDENT DEDENT DEDENT def array ( * dim ) : NEW_LINE INDENT if len ( dim ) == 1 : return [ None ] * ( dim [ 0 ] ) NEW_LINE else : return [ array ( * dim [ 1 : ] ) for i in range ( dim [ 0 ] ) ] NEW_LINE DEDENT def tests ( ) : NEW_LINE INDENT return Gcjt ( ) . tests ( ) NEW_LINE DEDENT


import sys NEW_LINE def decode ( s , base ) : NEW_LINE INDENT c2v = { } NEW_LINE res = 0 NEW_LINE next = 1 NEW_LINE for c in s : NEW_LINE INDENT if not c in c2v : NEW_LINE INDENT if len ( c2v ) < base : NEW_LINE INDENT c2v [ c ] = next NEW_LINE if next == 1 : NEW_LINE INDENT next = 0 NEW_LINE DEDENT elif next == 0 : NEW_LINE INDENT next = 2 NEW_LINE DEDENT else : NEW_LINE INDENT next += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return ( False , ) NEW_LINE DEDENT DEDENT dig = c2v [ c ] NEW_LINE res = base * res + dig NEW_LINE DEDENT return ( True , res ) NEW_LINE DEDENT sIn = " A - large ( 2 ) . in " ; sOut = " A - large ( 2 ) . out " NEW_LINE fIn = open ( sIn , " r " ) NEW_LINE fOut = open ( sOut , " w " ) NEW_LINE nT = int ( fIn . readline ( ) . strip ( ) ) NEW_LINE for t in xrange ( nT ) : NEW_LINE INDENT inp = fIn . readline ( ) . strip ( ) NEW_LINE mn = - 1 NEW_LINE for base in xrange ( 2 , 100 ) : NEW_LINE INDENT dRes = decode ( inp , base ) NEW_LINE if dRes [ 0 ] : NEW_LINE INDENT if mn == - 1 or mn > dRes [ 1 ] : NEW_LINE INDENT mn = dRes [ 1 ] NEW_LINE DEDENT DEDENT DEDENT print >> fOut , " Case ▁ # % d : ▁ % d " % ( t + 1 , mn ) NEW_LINE DEDENT


def solve ( message ) : NEW_LINE INDENT time = 0 NEW_LINE base = max ( 2 , len ( set ( message ) ) ) NEW_LINE digits = range ( base ) NEW_LINE digits . remove ( 1 ) NEW_LINE digits . reverse ( ) NEW_LINE symbols = { message [ 0 ] : 1 } NEW_LINE for symbol in message : NEW_LINE INDENT time *= base NEW_LINE if symbol not in symbols : NEW_LINE INDENT symbols [ symbol ] = digits . pop ( ) NEW_LINE DEDENT time += symbols [ symbol ] NEW_LINE DEDENT return time NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT T = int ( raw_input ( ) ) NEW_LINE for case in xrange ( T ) : NEW_LINE INDENT message = raw_input ( ) NEW_LINE print ' Case ▁ # % d : ▁ % d ' % ( case + 1 , solve ( message ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


package allyourbase ; import java . io . IOException ; public class Main extends Base { String alien ; char app [ ] ; int apos ; public static void main ( String [ ] args ) throws IOException { Main m = new Main ( ) ; m . run ( " A " , " large " ) ; } @ Override void init ( ) { } @ Override void load ( ) { } void insert ( char ch ) { int i = 0 ; while ( i < apos && app [ i ] != ch ) i ++ ; if ( i < apos ) return ; app [ apos ] = ch ; apos ++ ; } @ Override void solve ( ) throws IOException { System . out . println ( " Case ▁ " + caseId ) ; alien = br . readLine ( ) ; System . out . println ( alien ) ; app = new char [ alien . length ( ) ] ; apos = 0 ; for ( int i = 0 ; i < alien . length ( ) ; i ++ ) { insert ( alien . charAt ( i ) ) ; } long base = apos ; if ( base == 1 ) base ++ ; long res [ ] = new long [ alien . length ( ) ] ; for ( int i = 0 ; i < apos ; i ++ ) { int digit = i ; if ( digit == 0 ) digit = 1 ; else if ( digit == 1 ) digit = 0 ; for ( int j = 0 ; j < alien . length ( ) ; j ++ ) { if ( app [ i ] == alien . charAt ( j ) ) { res [ j ] = digit ; } } } for ( int i = 0 ; i < alien . length ( ) ; i ++ ) { System . out . print ( res [ i ] + " ▁ " ) ; } System . out . println ( ) ; long result = 0 ; long cur = 1 ; for ( int j = res . length - 1 ; j >= 0 ; j -- ) { result = result + cur * res [ j ] ; cur = cur * base ; } printResult ( " " + result ) ; } }


import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . math . BigInteger ; import java . util . HashMap ; import java . util . Scanner ; public class AllYourBase { public static void main ( String [ ] args ) { try { BufferedReader in = new BufferedReader ( new FileReader ( " A - small . in " ) ) ; BufferedWriter out = new BufferedWriter ( new FileWriter ( " x . txt " ) ) ; Scanner scan = new Scanner ( in ) ; int T = scan . nextInt ( ) ; scan . nextLine ( ) ; for ( int ii = 0 ; ii < T ; ii ++ ) { String str = scan . nextLine ( ) ; HashMap < Character , Integer > hm = new HashMap < Character , Integer > ( ) ; hm . put ( str . charAt ( 0 ) , 1 ) ; int count = 1 ; while ( count < str . length ( ) ) { char c = str . charAt ( count ) ; if ( ! hm . containsKey ( c ) ) { hm . put ( c , 0 ) ; break ; } count ++ ; } count ++ ; int val = 2 ; while ( count < str . length ( ) ) { char c = str . charAt ( count ) ; if ( ! hm . containsKey ( c ) ) { hm . put ( c , val ++ ) ; } count ++ ; } String tgt = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { tgt += hm . get ( str . charAt ( i ) ) ; } BigInteger x = new BigInteger ( tgt , val ) ; out . write ( " Case ▁ # " + ( ii + 1 ) + " : ▁ " + x . toString ( ) + " \n " ) ; } in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }


import java . io . * ; import java . util . * ; public class A { PrintWriter out ; Scanner in ; String testCase = " a2" ; public static void main ( String [ ] args ) throws Exception { new A ( ) . solve ( ) ; } void solve ( ) throws Exception { Locale . setDefault ( Locale . ENGLISH ) ; out = new PrintWriter ( new FileOutputStream ( testCase + " . out " ) ) ; in = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( testCase + " . in " ) ) ) ) ; int N = in . nextInt ( ) ; for ( int t = 1 ; t <= N ; ++ t ) { out . print ( " Case ▁ # " + t + " : ▁ " ) ; String num = in . next ( ) ; Map < Character , Integer > map = new HashMap < Character , Integer > ( ) ; for ( char c : num . toCharArray ( ) ) { if ( map . containsKey ( c ) ) { continue ; } if ( map . size ( ) == 0 ) { map . put ( c , 1 ) ; } else if ( map . size ( ) == 1 ) { map . put ( c , 0 ) ; } else { map . put ( c , map . size ( ) ) ; } } long result = 0 ; int base = map . size ( ) ; if ( base == 1 ) { base = 2 ; } for ( char c : num . toCharArray ( ) ) { result = result * base + map . get ( c ) ; } out . println ( result ) ; } out . close ( ) ; } }


import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Scanner ; public class P1 { public static void main ( String args [ ] ) throws FileNotFoundException { Scanner s = new Scanner ( new FileInputStream ( " A - large . in " ) ) ; int cnt = s . nextInt ( ) ; for ( int cases = 0 ; cases < cnt ; cases ++ ) { String buf = s . next ( ) ; long num = 0 ; int bb = - 1 ; int [ ] ar = new int [ buf . length ( ) ] ; HashMap < String , Integer > set = new HashMap < String , Integer > ( ) ; set . put ( buf . substring ( 0 , 1 ) , 1 ) ; for ( int i = 0 ; i < buf . length ( ) ; i ++ ) { if ( set . containsKey ( buf . substring ( i , i + 1 ) ) ) { ar [ i ] = set . get ( buf . substring ( i , i + 1 ) ) ; } else { bb ++ ; if ( bb == 1 ) { bb = 2 ; } set . put ( buf . substring ( i , i + 1 ) , bb ) ; ar [ i ] = bb ; } } bb ++ ; if ( bb < 2 ) { bb = 2 ; } for ( int i = 0 ; i < buf . length ( ) ; i ++ ) { long temp = 1 ; for ( int j = 0 ; j < buf . length ( ) - i - 1 ; j ++ ) { temp = temp * ( long ) bb ; } num += ( long ) ar [ i ] * temp ; } System . out . println ( " Case ▁ # " + ( cases + 1 ) + " : ▁ " + num ) ; } } }


package r1c ; import java . io . FileReader ; import java . util . Scanner ; public class B { public static void answer ( Scanner in ) { double sx , sy , sz , svx , svy , svz ; sx = 0 ; sy = 0 ; sz = 0 ; svx = 0 ; svy = 0 ; svz = 0 ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sx += in . nextDouble ( ) ; sy += in . nextDouble ( ) ; sz += in . nextDouble ( ) ; svx += in . nextDouble ( ) ; svy += in . nextDouble ( ) ; svz += in . nextDouble ( ) ; } double a , b , c ; a = svx * svx + svy * svy + svz * svz ; b = 2 * ( sx * svx + sy * svy + sz * svz ) ; c = sx * sx + sy * sy + sz * sz ; double outT ; if ( a != 0 ) { outT = - b / ( 2 * a ) ; if ( outT < 0 ) { outT = 0 ; } } else { outT = 0 ; } double outD = a * outT * outT + b * outT + c ; if ( outD < 0 ) { outD = 0 ; } outD = Math . sqrt ( outD ) / n ; System . out . println ( outD + " ▁ " + outT ) ; } public static void main ( String [ ] args ) { try { Scanner infile = new Scanner ( new FileReader ( args [ 0 ] ) ) ; int t = infile . nextInt ( ) ; infile . nextLine ( ) ; for ( int i = 0 ; i < t ; i ++ ) { System . out . print ( " Case ▁ # " + ( i + 1 ) + " : ▁ " ) ; answer ( infile ) ; } infile . close ( ) ; } catch ( Exception e ) { System . out . println ( " Exception ▁ occured , ▁ stacktrace ▁ to ▁ follow . " ) ; e . printStackTrace ( ) ; } } }

from __future__ import division NEW_LINE from math import sqrt NEW_LINE filein = " B . in " NEW_LINE fileout = " B . out " NEW_LINE def solve ( caseid , flydata ) : NEW_LINE INDENT num = len ( flydata ) NEW_LINE X = Y = Z = DX = DY = DZ = 0 NEW_LINE for i in range ( num ) : NEW_LINE INDENT x , y , z , dx , dy , dz = map ( float , flydata [ i ] . split ( ' ▁ ' ) ) NEW_LINE X += x NEW_LINE Y += y NEW_LINE Z += z NEW_LINE DX += dx NEW_LINE DY += dy NEW_LINE DZ += dz NEW_LINE DEDENT X = X / num NEW_LINE Y = Y / num NEW_LINE Z = Z / num NEW_LINE DX = DX / num NEW_LINE DY = DY / num NEW_LINE DZ = DZ / num NEW_LINE try : NEW_LINE INDENT t = max ( 0 , - ( X * DX + Y * DY + Z * DZ ) / ( DX * DX + DY * DY + DZ * DZ ) ) NEW_LINE DEDENT except : NEW_LINE INDENT print DX , DY , DZ NEW_LINE t = 0 NEW_LINE DEDENT px , py , pz = ( X + t * DX , Y + t * DY , Z + t * DZ ) NEW_LINE minD = sqrt ( px ** 2 + py ** 2 + pz ** 2 ) NEW_LINE return ' Case ▁ # % d : ▁ % .8f ▁ % .8f ' % ( caseid , minD , t ) NEW_LINE DEDENT datain = """ STRNEWLINE 3 STRNEWLINE 3 STRNEWLINE 3 ▁ 0 ▁ - 4 ▁ 0 ▁ 0 ▁ 3 STRNEWLINE - 3 ▁ - 2 ▁ - 1 ▁ 3 ▁ 0 ▁ 0 STRNEWLINE - 3 ▁ - 1 ▁ 2 ▁ 0 ▁ 3 ▁ 0 STRNEWLINE 3 STRNEWLINE - 5 ▁ 0 ▁ 0 ▁ 1 ▁ 0 ▁ 0 STRNEWLINE - 7 ▁ 0 ▁ 0 ▁ 1 ▁ 0 ▁ 0 STRNEWLINE - 6 ▁ 3 ▁ 0 ▁ 1 ▁ 0 ▁ 0 STRNEWLINE 4 STRNEWLINE 1 ▁ 2 ▁ 3 ▁ 1 ▁ 2 ▁ 3 STRNEWLINE 3 ▁ 2 ▁ 1 ▁ 3 ▁ 2 ▁ 1 STRNEWLINE 1 ▁ 0 ▁ 0 ▁ 0 ▁ 0 ▁ - 1 STRNEWLINE 0 ▁ 10 ▁ 0 ▁ 0 ▁ - 10 ▁ - 1 STRNEWLINE """ NEW_LINE datain = open ( filein ) . read ( ) NEW_LINE dataout = open ( fileout , " w " ) NEW_LINE data = [ x for x in datain . split ( ' \n ' ) if x ] NEW_LINE N = int ( data [ 0 ] ) NEW_LINE atrow = 1 NEW_LINE for case in range ( N ) : NEW_LINE INDENT flies = int ( data [ atrow ] ) NEW_LINE flydata = data [ atrow + 1 : atrow + flies + 1 ] NEW_LINE text = str ( solve ( case + 1 , flydata ) ) NEW_LINE print text NEW_LINE dataout . write ( text + ' \n ' ) NEW_LINE atrow += flies + 1 NEW_LINE DEDENT dataout . close ( ) NEW_LINE print " Wrote ▁ % s " % fileout NEW_LINE


import euclid NEW_LINE def main ( ) : NEW_LINE INDENT T = int ( raw_input ( ) ) NEW_LINE for case in xrange ( T ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE position = euclid . Vector3 ( ) NEW_LINE velocity = euclid . Vector3 ( ) NEW_LINE for _ in xrange ( N ) : NEW_LINE INDENT x , y , z , vx , vy , vz = map ( float , raw_input ( ) . split ( ) ) NEW_LINE position += euclid . Vector3 ( x , y , z ) NEW_LINE velocity += euclid . Vector3 ( vx , vy , vz ) NEW_LINE DEDENT position /= N NEW_LINE velocity /= N NEW_LINE if velocity == euclid . Vector3 ( ) : NEW_LINE INDENT d_min = abs ( position - euclid . Point3 ( ) ) NEW_LINE t_min = 0. NEW_LINE DEDENT else : NEW_LINE INDENT position = euclid . Point3 ( position . x , position . y , position . z ) NEW_LINE ray = euclid . Ray3 ( position , velocity ) NEW_LINE connection = ray . connect ( euclid . Point3 ( ) ) NEW_LINE d_min = abs ( connection ) NEW_LINE t_min = abs ( connection . p1 - position ) / abs ( velocity ) NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % 1.8f ▁ % 1.8f ' % ( case + 1 , d_min , t_min ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


from sys import stdin NEW_LINE import math NEW_LINE def vecAdd ( v1 , v2 ) : NEW_LINE INDENT return [ x1 + x2 for x1 , x2 in zip ( v1 , v2 ) ] NEW_LINE DEDENT def vecSub ( v1 , v2 ) : NEW_LINE INDENT return [ x1 - x2 for x1 , x2 in zip ( v1 , v2 ) ] NEW_LINE DEDENT def vecDot ( v1 , v2 ) : NEW_LINE INDENT return sum ( [ x1 * x2 for x1 , x2 in zip ( v1 , v2 ) ] ) NEW_LINE DEDENT def vecScale ( v , s ) : NEW_LINE INDENT return [ x * s for x in v ] NEW_LINE DEDENT def compute ( flies ) : NEW_LINE INDENT vecAvg = [ 0 , 0 , 0 , 0 , 0 , 0 ] NEW_LINE for vec in flies : NEW_LINE INDENT vecAvg = [ x + y for x , y in zip ( vecAvg , vec ) ] NEW_LINE DEDENT flyCount = len ( flies ) NEW_LINE vecAvg = [ float ( x ) / float ( flyCount ) for x in vecAvg ] NEW_LINE x1 = vecAvg [ 0 : 3 ] NEW_LINE x2 = vecAvg [ 3 : ] NEW_LINE speedSqr = vecDot ( x2 , x2 ) NEW_LINE if speedSqr == 0 : NEW_LINE INDENT t = 0 NEW_LINE DEDENT else : NEW_LINE INDENT t = - vecDot ( x1 , x2 ) / vecDot ( x2 , x2 ) NEW_LINE DEDENT if t < 0 : NEW_LINE INDENT t = 0 NEW_LINE DEDENT diffv = vecAdd ( x1 , vecScale ( x2 , t ) ) NEW_LINE d = math . sqrt ( vecDot ( diffv , diffv ) ) NEW_LINE return ( d , t ) NEW_LINE DEDENT cases = int ( stdin . readline ( ) ) NEW_LINE for caseNo in xrange ( 1 , cases + 1 ) : NEW_LINE INDENT flyCount = int ( stdin . readline ( ) ) NEW_LINE flies = [ ] NEW_LINE for flyNo in xrange ( 0 , flyCount ) : NEW_LINE INDENT flies . append ( [ int ( x ) for x in stdin . readline ( ) . strip ( ) . split ( ) ] ) NEW_LINE DEDENT d , t = compute ( flies ) NEW_LINE print " Case ▁ # % d : ▁ % .8f ▁ % .8f " % ( caseNo , d , t ) NEW_LINE DEDENT


for ii in range ( 1 , int ( raw_input ( ) ) + 1 ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE f = [ [ int ( a ) for a in raw_input ( ) . split ( ) ] for j in range ( N ) ] NEW_LINE g = [ sum ( [ z [ i ] for z in f ] ) for i in range ( 6 ) ] NEW_LINE x = g [ : 3 ] NEW_LINE d = g [ 3 : ] NEW_LINE t = 0 NEW_LINE if ( d != [ 0 , 0 , 0 ] and sum ( [ x [ i ] * d [ i ] for i in range ( 3 ) ] ) < 0 ) : NEW_LINE INDENT t = - ( 0.0 + sum ( [ x [ i ] * d [ i ] for i in range ( 3 ) ] ) ) / sum ( [ d [ i ] * d [ i ] for i in range ( 3 ) ] ) NEW_LINE DEDENT x = [ float ( x [ i ] + t * d [ i ] ) / N for i in range ( 3 ) ] NEW_LINE x = ( x [ 0 ] * x [ 0 ] + x [ 1 ] * x [ 1 ] + x [ 2 ] * x [ 2 ] ) ** 0.5 NEW_LINE print " Case ▁ # % d : ▁ % .8f ▁ % .8f " % ( ii , x , t ) NEW_LINE DEDENT


from math import sqrt NEW_LINE def dot ( a , b ) : NEW_LINE INDENT return a [ 0 ] * b [ 0 ] + a [ 1 ] * b [ 1 ] + a [ 2 ] * b [ 2 ] NEW_LINE DEDENT def sub ( a , b ) : NEW_LINE INDENT return ( a [ 0 ] - b [ 0 ] , a [ 1 ] - b [ 1 ] , a [ 2 ] - b [ 2 ] ) NEW_LINE DEDENT def add ( a , b ) : NEW_LINE INDENT return ( a [ 0 ] + b [ 0 ] , a [ 1 ] + b [ 1 ] , a [ 2 ] + b [ 2 ] ) NEW_LINE DEDENT def mul ( a , f ) : NEW_LINE INDENT return ( a [ 0 ] * f , a [ 1 ] * f , a [ 2 ] * f ) NEW_LINE DEDENT def norm22 ( a ) : NEW_LINE INDENT return dot ( a , a ) NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT x , y , z = 0 , 0 , 0 NEW_LINE vx , vy , vz = 0 , 0 , 0 NEW_LINE n = int ( raw_input ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT xi , yi , zi , vxi , vyi , vzi = map ( int , raw_input ( ) . split ( ) ) NEW_LINE x = x + xi NEW_LINE y = y + yi NEW_LINE z = z + zi NEW_LINE vx = vx + vxi NEW_LINE vy = vy + vyi NEW_LINE vz = vz + vzi NEW_LINE DEDENT c = mul ( ( x , y , z ) , 1. / n ) NEW_LINE v = mul ( ( vx , vy , vz ) , 1. / n ) NEW_LINE b = dot ( v , v ) NEW_LINE if b == 0 : NEW_LINE INDENT tmin = 0 NEW_LINE DEDENT else : NEW_LINE INDENT tmin = - dot ( c , v ) / b NEW_LINE if tmin < 0 : NEW_LINE INDENT tmin = 0 NEW_LINE DEDENT DEDENT d2 = norm22 ( add ( c , mul ( v , tmin ) ) ) NEW_LINE print " Case ▁ # % i : " % ( t + 1 ) , sqrt ( d2 ) , tmin NEW_LINE DEDENT


import java . util . * ; import java . math . * ; class Main { public static void main ( String [ ] argv ) { Scanner sc = new Scanner ( System . in ) ; int tests = sc . nextInt ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { int n = sc . nextInt ( ) ; double x = 0. , y = 0 , z = 0 , dx = 0 , dy = 0 , dz = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x += sc . nextDouble ( ) ; y += sc . nextDouble ( ) ; z += sc . nextDouble ( ) ; dx += sc . nextDouble ( ) ; dy += sc . nextDouble ( ) ; dz += sc . nextDouble ( ) ; } x /= n ; y /= n ; z /= n ; dx /= n ; dy /= n ; dz /= n ; double a = dx * dx + dy * dy + dz * dz ; double b = 2 * ( dx * x + dy * y + dz * z ) ; double c = x * x + y * y + z * z ; double s ; if ( a == 0 && b == 0 ) { s = 0 ; } else if ( a == 0 && b / c > 0 ) { s = 0 ; } else if ( a == 0 ) { s = - c / b ; } else if ( b / a > 0 ) { s = 0 ; } else { s = - b / a / 2 ; } double v = a * s * s + b * s + c ; if ( v < 0 ) { v = 0 ; } v = Math . sqrt ( v ) ; System . err . println ( t ) ; System . out . printf ( " Case ▁ # % d : ▁ % .08f ▁ % .08f \n " , t , v , s ) ; } } }


import java . io . * ; import java . util . * ; public class B { PrintWriter out ; Scanner in ; String testCase = " b2" ; public static void main ( String [ ] args ) throws Exception { new B ( ) . solve ( ) ; } long sqr ( long a ) { return a * a ; } double sqrt ( double a ) { if ( a < 1E-8 ) { return 0 ; } else { return Math . sqrt ( a ) ; } } void solve ( ) throws Exception { Locale . setDefault ( Locale . ENGLISH ) ; out = new PrintWriter ( new FileOutputStream ( testCase + " . out " ) ) ; in = new Scanner ( new BufferedReader ( new InputStreamReader ( new FileInputStream ( testCase + " . in " ) ) ) ) ; int N = in . nextInt ( ) ; for ( int t = 1 ; t <= N ; ++ t ) { out . print ( " Case ▁ # " + t + " : ▁ " ) ; int n = in . nextInt ( ) ; long x = 0 , y = 0 , z = 0 , vx = 0 , vy = 0 , vz = 0 ; for ( int i = 0 ; i < n ; ++ i ) { x += in . nextInt ( ) ; y += in . nextInt ( ) ; z += in . nextInt ( ) ; vx += in . nextInt ( ) ; vy += in . nextInt ( ) ; vz += in . nextInt ( ) ; } long a = sqr ( vx ) + sqr ( vy ) + sqr ( vz ) ; long b = 2 * ( x * vx + y * vy + z * vz ) ; long c = sqr ( x ) + sqr ( y ) + sqr ( z ) ; double time ; if ( a != 0 ) { time = - b / ( 2.0 * a ) ; } else { time = 0 ; } if ( time < 0 ) { time = 0 ; } double d = sqrt ( ( a * time * time + b * time + c ) ) / n ; out . println ( d + " ▁ " + time ) ; } out . close ( ) ; } }


import java . io . * ; import java . util . * ; public class CenterOfMass { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( " B . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( " B . out " ) ) ) ; StringTokenizer st ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int caseNum = 1 ; caseNum <= T ; caseNum ++ ) { int N = Integer . parseInt ( in . readLine ( ) ) ; double xPos = 0.0 ; double yPos = 0.0 ; double zPos = 0.0 ; double xVel = 0.0 ; double yVel = 0.0 ; double zVel = 0.0 ; double time ; double distance ; for ( int i = 0 ; i < N ; i ++ ) { st = new StringTokenizer ( in . readLine ( ) ) ; xPos += Double . parseDouble ( st . nextToken ( ) ) ; yPos += Double . parseDouble ( st . nextToken ( ) ) ; zPos += Double . parseDouble ( st . nextToken ( ) ) ; xVel += Double . parseDouble ( st . nextToken ( ) ) ; yVel += Double . parseDouble ( st . nextToken ( ) ) ; zVel += Double . parseDouble ( st . nextToken ( ) ) ; } xPos /= ( double ) N ; yPos /= ( double ) N ; zPos /= ( double ) N ; xVel /= ( double ) N ; yVel /= ( double ) N ; zVel /= ( double ) N ; if ( xVel == 0.0 && yVel == 0.0 && zVel == 0.0 ) { time = 0 ; distance = Math . sqrt ( xPos * xPos + yPos * yPos + zPos * zPos ) ; } else { time = - ( xPos * xVel + yPos * yVel + zPos * zVel ) / ( xVel * xVel + yVel * yVel + zVel * zVel ) ; if ( time < 0 ) time = 0 ; double xNew = xPos + time * xVel ; double yNew = yPos + time * yVel ; double zNew = zPos + time * zVel ; distance = Math . sqrt ( xNew * xNew + yNew * yNew + zNew * zNew ) ; } out . println ( " Case ▁ # " + caseNum + " : ▁ " + distance + " ▁ " + time ) ; } in . close ( ) ; out . close ( ) ; System . exit ( 0 ) ; } }


import java . io . * ; import java . util . * ; public class A { MyScanner in ; PrintWriter out ; final static String FILENAME = " a " ; public static void main ( String [ ] args ) throws Exception { new A ( ) . run ( ) ; } public void run ( ) throws Exception { in = new MyScanner ( FILENAME + " . in " ) ; out = new PrintWriter ( FILENAME + " . out " ) ; int tests = in . nextInt ( ) ; for ( int test = 0 ; test < tests ; test ++ ) { out . println ( " Case ▁ # " + ( test + 1 ) + " : ▁ " + solve ( ) ) ; } out . close ( ) ; } public long solve ( ) throws Exception { int r = in . nextInt ( ) ; int c = in . nextInt ( ) ; int w = in . nextInt ( ) ; return r * ( c / w + w + ( c % w == 0 ? - 1 : 0 ) ) ; } class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( String file ) throws Exception { br = new BufferedReader ( new FileReader ( file ) ) ; } String next ( ) throws Exception { while ( ( st == null ) || ( ! st . hasMoreTokens ( ) ) ) { String t = br . readLine ( ) ; if ( t == null ) { return null ; } st = new StringTokenizer ( t ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( next ( ) ) ; } double nextDouble ( ) throws Exception { return Double . parseDouble ( next ( ) ) ; } boolean nextBoolean ( ) throws Exception { return Boolean . parseBoolean ( next ( ) ) ; } long nextLong ( ) throws Exception { return Long . parseLong ( next ( ) ) ; } } }

testSum = input ( ) NEW_LINE for test in xrange ( testSum ) : NEW_LINE INDENT x , y , w = map ( int , raw_input ( ) . split ( ) ) NEW_LINE ans = x * ( ( y - 1 ) / w + 1 ) + w - 1 NEW_LINE print " Case ▁ # " + str ( test + 1 ) + " : " , ans NEW_LINE DEDENT


def check ( R , C , W , B ) : NEW_LINE INDENT c = sum ( b . count ( 1 ) for b in B ) NEW_LINE for y in range ( R ) : NEW_LINE INDENT for x in range ( C - W + 1 ) : NEW_LINE INDENT if B [ y ] [ x : x + W ] . count ( 1 ) == c and B [ y ] [ x : x + W ] . count ( - 1 ) == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT def BT ( R , C , W , B ) : NEW_LINE INDENT Bt = tuple ( tuple ( b ) for b in B ) NEW_LINE if Bt in memo : NEW_LINE INDENT return memo [ Bt ] NEW_LINE DEDENT ans = 9999 NEW_LINE for y in range ( R ) : NEW_LINE INDENT for x in range ( C ) : NEW_LINE INDENT if B [ y ] [ x ] == 0 : NEW_LINE INDENT ans2 = 0 NEW_LINE B [ y ] [ x ] = 1 NEW_LINE if check ( R , C , W , B ) : NEW_LINE INDENT if sum ( b . count ( 1 ) for b in B ) == W : NEW_LINE INDENT ans2 = max ( ans2 , 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans2 = max ( ans2 , BT ( R , C , W , B ) + 1 ) NEW_LINE DEDENT DEDENT B [ y ] [ x ] = 0 NEW_LINE B [ y ] [ x ] = - 1 NEW_LINE if check ( R , C , W , B ) : NEW_LINE INDENT ans2 = max ( ans2 , BT ( R , C , W , B ) + 1 ) NEW_LINE DEDENT B [ y ] [ x ] = 0 NEW_LINE ans = min ( ans , ans2 ) NEW_LINE DEDENT DEDENT DEDENT memo [ Bt ] = ans NEW_LINE return ans NEW_LINE DEDENT def solve ( R , C , W ) : NEW_LINE INDENT global memo NEW_LINE B = [ [ 0 ] * C for _ in range ( R ) ] NEW_LINE memo = { } NEW_LINE return BT ( R , C , W , B ) NEW_LINE DEDENT for t in range ( input ( ) ) : NEW_LINE INDENT R , C , W = map ( int , raw_input ( ) . split ( ) ) NEW_LINE print " Case ▁ # % s : ▁ % s " % ( t + 1 , solve ( R , C , W ) ) NEW_LINE DEDENT


import math NEW_LINE import itertools NEW_LINE import numpy as NP NEW_LINE def read_case ( f ) : NEW_LINE INDENT return read_ints ( f ) NEW_LINE DEDENT def solve_small ( case ) : NEW_LINE INDENT R , C , W = case NEW_LINE return ( C // W ) * R + W - ( 1 if C % W == 0 else 0 ) NEW_LINE DEDENT def solve_large ( case ) : NEW_LINE INDENT return solve_small ( case ) NEW_LINE DEDENT def write_case ( f , i , res ) : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ ' % i ) NEW_LINE f . write ( ' % s ' % res ) NEW_LINE f . write ( ' \n ' ) NEW_LINE DEDENT def read_word ( f ) : NEW_LINE INDENT return next ( f ) . strip ( ) NEW_LINE DEDENT def read_int ( f , b = 10 ) : NEW_LINE INDENT return int ( read_word ( f ) , b ) NEW_LINE DEDENT def read_letters ( f ) : NEW_LINE INDENT return list ( read_word ( f ) ) NEW_LINE DEDENT def read_digits ( f , b = 10 ) : NEW_LINE INDENT return [ int ( x , b ) for x in read_letters ( f ) ] NEW_LINE DEDENT def read_words ( f , d = ' ▁ ' ) : NEW_LINE INDENT return read_word ( f ) . split ( d ) NEW_LINE DEDENT def read_ints ( f , b = 10 , d = ' ▁ ' ) : NEW_LINE INDENT return [ int ( x , b ) for x in read_words ( f , d ) ] NEW_LINE DEDENT def read_floats ( f , d = ' ▁ ' ) : NEW_LINE INDENT return [ float ( x ) for x in read_words ( f , d ) ] NEW_LINE DEDENT def read_arr ( f , R , reader = read_ints , * args , ** kwargs ) : NEW_LINE INDENT return [ reader ( f , * args , ** kwargs ) for i in range ( R ) ] NEW_LINE DEDENT def solve ( solver , fn , out_fn = None ) : NEW_LINE INDENT in_fn = fn + ' . in ' NEW_LINE if out_fn is None : NEW_LINE INDENT out_fn = fn + ' . out ' NEW_LINE DEDENT with open ( in_fn , ' r ' ) as fi : NEW_LINE INDENT with open ( out_fn , ' w ' ) as fo : NEW_LINE INDENT T = read_int ( fi ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT case = read_case ( fi ) NEW_LINE res = solver ( case ) NEW_LINE write_case ( fo , i , res ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEBUG = ' i ' NEW_LINE from run import * NEW_LINE


import os NEW_LINE import sys NEW_LINE from collections import defaultdict NEW_LINE problem_id = ' A ' NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input_path = ' % s . in ' % problem_id NEW_LINE output_path = ' % s . out ' % problem_id NEW_LINE def read_line ( ) : NEW_LINE INDENT line = ' ' NEW_LINE while len ( line ) == 0 : NEW_LINE INDENT line = input_file . readline ( ) . strip ( ) NEW_LINE DEDENT return line NEW_LINE DEDENT def write_line ( line ) : NEW_LINE INDENT print line NEW_LINE return output_file . write ( line + os . linesep ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT r , c , w = map ( int , read_line ( ) . split ( ' ▁ ' ) ) NEW_LINE nc = ( c / w ) * r + ( w - 1 ) NEW_LINE if c % w : NEW_LINE INDENT nc += 1 NEW_LINE DEDENT return ' % s ' % nc NEW_LINE DEDENT input_file = open ( input_path , " r " ) NEW_LINE output_file = open ( output_path , " w + " ) NEW_LINE T = int ( read_line ( ) ) NEW_LINE for case_id in xrange ( 1 , T + 1 ) : NEW_LINE INDENT write_line ( " Case ▁ # % d : ▁ % s " % ( case_id , solve ( ) ) ) NEW_LINE DEDENT input_file . close ( ) NEW_LINE output_file . close ( ) NEW_LINE


FILE_NAME_BASE = ' A - large ' NEW_LINE NUM_PROCESSES = 0 NEW_LINE MEM_LIMIT_GB = 1.5 NEW_LINE RECURSION_LIMIT = 1000 NEW_LINE def parse ( inp ) : NEW_LINE INDENT rows , cols , size = ( int ( x ) for x in inp . readline ( ) . split ( ) ) NEW_LINE return rows , cols , size NEW_LINE DEDENT def solve ( rows , cols , size ) : NEW_LINE INDENT toHit = cols / size NEW_LINE hitFlex = cols % size NEW_LINE toSink = size - 1 if hitFlex == 0 else size NEW_LINE return rows * toHit + toSink NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT import sys NEW_LINE sys . setrecursionlimit ( RECURSION_LIMIT ) NEW_LINE import resource NEW_LINE soft , hard = resource . getrlimit ( resource . RLIMIT_AS ) NEW_LINE resource . setrlimit ( resource . RLIMIT_AS , ( MEM_LIMIT_GB * 1024 ** 3 , hard ) ) NEW_LINE with open ( FILE_NAME_BASE + ' . in ' , ' r ' ) as inp : NEW_LINE INDENT numCases = int ( inp . readline ( ) ) NEW_LINE inputs = [ parse ( inp ) for _ in xrange ( numCases ) ] NEW_LINE DEDENT if NUM_PROCESSES == 0 : NEW_LINE INDENT runners = [ lambda inp = inp : apply ( solve , inp ) for inp in inputs ] NEW_LINE DEDENT else : NEW_LINE INDENT from multiprocessing import Pool NEW_LINE from signal import SIGINT , SIG_IGN , signal NEW_LINE pool = Pool ( NUM_PROCESSES , signal , ( SIGINT , SIG_IGN ) ) NEW_LINE runners = [ pool . apply_async ( solve , inp ) . get for inp in inputs ] NEW_LINE pool . close ( ) NEW_LINE DEDENT caseFmt = ' % ' + str ( len ( str ( numCases ) ) ) + ' d ' NEW_LINE progressFmt = ' [ % s / % s ] ▁ % % s \n ' % ( caseFmt , caseFmt ) NEW_LINE with open ( FILE_NAME_BASE + ' . out ' , ' w ' ) as out : NEW_LINE INDENT for case , runner in enumerate ( runners , 1 ) : NEW_LINE INDENT result = runner ( ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % s \n ' % ( case , result ) ) NEW_LINE out . flush ( ) NEW_LINE sys . stderr . write ( progressFmt % ( case , numCases , result ) ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


package com . archieve ; import java . io . BufferedInputStream ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; import static java . util . Arrays . deepToString ; public class codejam2015_1C_A { static PrintWriter out = null ; static FileInputStream in = null ; Scanner sc ; int N ; Integer R , C , W ; void read ( ) { R = sc . nextInt ( ) ; C = sc . nextInt ( ) ; W = sc . nextInt ( ) ; } void solve ( ) { long solution = 0 ; solution += ( R - 1 ) * ( C / W ) ; solution += ( C - 1 ) / W ; solution += W ; out . println ( solution ) ; System . out . println ( solution ) ; } void output ( long a ) { out . println ( a ) ; System . out . println ( a ) ; } void run ( ) { try { in = new FileInputStream ( " src / com / resources / smallInput . txt " ) ; out = new PrintWriter ( " src / com / resources / output . txt " ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } sc = new Scanner ( in ) ; int caseN = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseN ; caseID ++ ) { read ( ) ; out . printf ( " Case ▁ # % d : ▁ " , caseID ) ; System . out . printf ( " Case ▁ # % d : ▁ " , caseID ) ; solve ( ) ; System . out . flush ( ) ; } out . close ( ) ; } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { try { System . setIn ( new BufferedInputStream ( new FileInputStream ( args . length > 0 ? args [ 0 ] : ( codejam2015_1C_A . class . getName ( ) + " . in " ) ) ) ) ; } catch ( Exception e ) { } new codejam2015_1C_A ( ) . run ( ) ; } }


import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class ProblemA { public static void main ( String [ ] args ) throws IOException { ProblemA solver = new ProblemA ( ) ; solver . init ( ) ; solver . solve ( ) ; } void init ( ) { } private void solve ( ) throws IOException { Reader in = new Reader ( System . in ) ; PrintWriter out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int R = in . nextInt ( ) ; int C = in . nextInt ( ) ; int W = in . nextInt ( ) ; int r = ( C / W ) * R ; r += ( W - 1 ) ; if ( ( C % W ) > 0 ) r ++ ; out . println ( " Case ▁ # " + t + " : ▁ " + r ) ; } out . flush ( ) ; out . close ( ) ; } private static class Reader { BufferedReader reader ; StringTokenizer tokenizer ; Reader ( InputStream input ) { reader = new BufferedReader ( new InputStreamReader ( input ) ) ; tokenizer = new StringTokenizer ( " " ) ; } public void skipLine ( ) throws IOException { reader . readLine ( ) ; } public String next ( ) throws IOException { while ( ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } } }


import java . util . Scanner ; public final class A { public static void main ( final String ... args ) { final Scanner sc = new Scanner ( System . in ) ; final int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; ++ i ) { System . out . println ( String . format ( " Case ▁ # % d : ▁ % d " , i + 1 , testcase ( sc ) ) ) ; } } private static int testcase ( final Scanner sc ) { final int r = sc . nextInt ( ) ; final int c = sc . nextInt ( ) ; final int w = sc . nextInt ( ) ; return ( c / w ) * r + ( w - 1 ) + ( c % w == 0 ? 0 : 1 ) ; } }