import java . io . * ; import java . util . * ; public class A { static class Assert { static void check ( boolean e ) { if ( ! e ) { throw new Error ( ) ; } } } Scanner in ; PrintWriter out ; boolean isCons ( char c ) { return c != ' a ' && c != ' e ' && c != ' i ' && c != ' o ' && c != ' u ' ; } int getPos ( String word , int n , int from ) { int count = 0 ; for ( int i = from ; i < word . length ( ) ; i ++ ) { if ( isCons ( word . charAt ( i ) ) ) { count ++ ; if ( count == n ) { return i ; } } else { count = 0 ; } } return - 1 ; } long solveOne ( String word , int n ) { long count = 0 ; int pos = getPos ( word , n , 0 ) ; if ( pos == - 1 ) { return count ; } count += word . length ( ) - pos ; for ( int start = 1 ; start < word . length ( ) ; start ++ ) { if ( pos - start + 1 >= n ) { } else { Assert . check ( pos - start + 1 == n - 1 ) ; if ( pos == word . length ( ) - 1 ) { return count ; } if ( isCons ( word . charAt ( pos + 1 ) ) ) { pos ++ ; } else { pos = getPos ( word , n , pos + 2 ) ; if ( pos == - 1 ) { return count ; } } } count += word . length ( ) - pos ; } return count ; } void solve ( ) { int nTests = in . nextInt ( ) ; for ( int i = 1 ; i <= nTests ; i ++ ) { out . printf ( " Case ▁ # % d : ▁ % d % n " , i , solveOne ( in . next ( ) , in . nextInt ( ) ) ) ; } } void run ( ) { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; try { solve ( ) ; } finally { out . close ( ) ; } } public static void main ( String args [ ] ) { new A ( ) . run ( ) ; } }

import java . io . File ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . Scanner ; public class GCJ_2013_C1 { public static long solve ( String s , long n ) { long bef_cont = 0 ; long bef_noncont = 0 ; long endpart = 0 ; System . out . println ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { long bef_cont_prev = bef_cont ; long bef_noncont_prev = bef_noncont ; char c = s . charAt ( i ) ; boolean cns = ! ( ( c == ' a ' ) || ( c == ' e ' ) || ( c == ' i ' ) || ( c == ' o ' ) || ( c == ' u ' ) ) ; bef_noncont = bef_noncont_prev + bef_cont_prev ; if ( cns ) { endpart ++ ; if ( endpart >= n ) { bef_cont = ( i - n + 2 ) ; } else { bef_cont = bef_cont_prev ; } } else { bef_cont = bef_cont_prev ; endpart = 0 ; } } return bef_cont + bef_noncont ; } public static void main ( String [ ] args ) throws Exception { String fname = " A _ large " ; File file = new File ( fname + " _ in . txt " ) ; Scanner scanner = new Scanner ( file ) ; FileWriter outFile = new FileWriter ( fname + " _ out . txt " ) ; PrintWriter outp = new PrintWriter ( outFile ) ; int T = scanner . nextInt ( ) ; scanner . nextLine ( ) ; for ( int i = 1 ; i <= T ; i ++ ) { String s = scanner . nextLine ( ) ; String sin = s . split ( " ▁ " ) [ 0 ] ; int n = Integer . parseInt ( s . split ( " ▁ " ) [ 1 ] ) ; outp . printf ( " Case ▁ # % d : ▁ % d \n " , i , solve ( sin , n ) ) ; } outp . close ( ) ; } }

import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . LineNumberReader ; public class A { static long result ( String name , int n ) { int len = name . length ( ) ; boolean hasPrev = false ; int curr = 0 ; int prevStart = 0 ; long res = 0 ; int pos = 0 ; while ( pos < len ) { boolean is = " aeiou " . indexOf ( name . charAt ( pos ++ ) ) < 0 ; if ( is ) { curr ++ ; if ( curr >= n ) { hasPrev = true ; prevStart = pos - n ; res += 1 + pos - n ; continue ; } } else { curr = 0 ; } if ( hasPrev ) { res += 1 + prevStart ; } } return res ; } static void go ( String inputFile ) throws Exception { LineNumberReader in = new LineNumberReader ( new FileReader ( inputFile ) ) ; FileWriter out = new FileWriter ( inputFile + " . out " ) ; int nCases = Integer . parseInt ( in . readLine ( ) ) ; for ( int c = 1 ; c <= nCases ; c ++ ) { String [ ] tmp = in . readLine ( ) . split ( " ▁ " ) ; long res = result ( tmp [ 0 ] , Integer . parseInt ( tmp [ 1 ] ) ) ; String line = " Case ▁ # " + c + " : ▁ " + res ; System . out . println ( line ) ; out . write ( line + " \n " ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws Exception { LineNumberReader sysIn = new LineNumberReader ( new InputStreamReader ( System . in ) ) ; String line ; while ( ( line = sysIn . readLine ( ) ) != null ) { go ( line . trim ( ) ) ; } } }

import java . io . * ; import java . util . * ; public class Round1C_2013_A { private static void jam ( String inFile , String outFile ) throws Exception { BufferedReader brIn = new BufferedReader ( new FileReader ( inFile ) ) ; BufferedWriter bwOut = new BufferedWriter ( new FileWriter ( outFile ) ) ; String sLine ; int ca = 1 ; brIn . readLine ( ) ; int [ ] starts = new int [ 1000000 ] ; int [ ] ends = new int [ 1000000 ] ; while ( ( sLine = brIn . readLine ( ) ) != null ) { String [ ] fields = sLine . split ( " ▁ " ) ; if ( fields . length != 2 ) { System . out . println ( " skipping ▁ mis - parse : ▁ " + sLine ) ; continue ; } String s = fields [ 0 ] ; int n = Integer . parseInt ( fields [ 1 ] ) ; int numSets = 0 ; int seqNum = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( c != ' a ' && c != ' e ' && c != ' i ' && c != ' o ' && c != ' u ' ) { seqNum ++ ; if ( seqNum >= n ) { starts [ numSets ] = i + 1 - n ; ends [ numSets ] = i + 1 ; numSets ++ ; } } else { seqNum = 0 ; } } int lastStart = - 1 ; long sum = 0 ; for ( int i = 0 ; i < numSets ; i ++ ) { int choicesLeft = starts [ i ] - lastStart ; int choicesRight = 1 + s . length ( ) - ends [ i ] ; sum += ( long ) choicesLeft * ( long ) choicesRight ; lastStart = starts [ i ] ; } String msg = " " + sum ; System . out . println ( " " + s . length ( ) ) ; bwOut . write ( " Case ▁ # " + ca + " : ▁ " + msg + " \r \n " ) ; ca ++ ; } brIn . close ( ) ; bwOut . close ( ) ; } public static void main ( String [ ] args ) throws Exception { jam ( args [ 0 ] , args [ 1 ] ) ; } }

import java . awt . * ; import java . awt . event . * ; import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . text . * ; import java . util . * ; public class A { static BufferedReader br ; static StringTokenizer st ; static PrintWriter pw ; public static void main ( String [ ] args ) throws IOException { br = new BufferedReader ( new FileReader ( " a . in " ) ) ; pw = new PrintWriter ( new BufferedWriter ( new FileWriter ( " a . out " ) ) ) ; final int MAX_CASES = readInt ( ) ; String vowel = " aeiou " ; for ( int casenum = 1 ; casenum <= MAX_CASES ; casenum ++ ) { pw . printf ( " Case ▁ # % d : ▁ " , casenum ) ; String str = nextToken ( ) ; int count = readInt ( ) ; long ret = 0 ; int curr = 0 ; int lastStart = - 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( vowel . indexOf ( str . charAt ( i ) + " " ) == - 1 ) { curr ++ ; } else { curr = 0 ; } if ( curr >= count ) { int begin = i - count + 1 ; int goAfter = i ; ret += ( begin - lastStart ) * 1L * ( str . length ( ) - goAfter ) ; lastStart = begin ; } } pw . println ( ret ) ; } pw . close ( ) ; } public static int readInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } public static long readLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } public static double readDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; } public static String nextToken ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { if ( ! br . ready ( ) ) { pw . close ( ) ; System . exit ( 0 ) ; } st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } public static String readLine ( ) throws IOException { st = null ; return br . readLine ( ) ; } }

from collections import Counter NEW_LINE vowels = [ ' a ' , ' e ' , ' i ' , ' o ' , ' u ' ] NEW_LINE def solve ( s , n ) : NEW_LINE INDENT total = 0 NEW_LINE is_first = True NEW_LINE cont = 0 NEW_LINE arr = [ 0 for i in range ( len ( s ) ) ] NEW_LINE if s [ 0 ] not in vowels : NEW_LINE INDENT cont = 1 NEW_LINE if n == 1 : NEW_LINE INDENT is_first = False NEW_LINE last_cont = 0 NEW_LINE arr [ 0 ] = 1 NEW_LINE DEDENT DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] in vowels : NEW_LINE INDENT cont = 0 NEW_LINE arr [ i ] = arr [ i - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT cont += 1 NEW_LINE if cont < n : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] NEW_LINE DEDENT elif cont == n : NEW_LINE INDENT if is_first : NEW_LINE INDENT is_first = False NEW_LINE arr [ i ] = i + 2 - n NEW_LINE last_cont = i NEW_LINE DEDENT else : NEW_LINE INDENT arr [ i ] = i - last_cont + arr [ i - 1 ] NEW_LINE last_cont = i NEW_LINE DEDENT DEDENT elif cont > n : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] + 1 NEW_LINE last_cont = i NEW_LINE DEDENT else : raise Exception ( ' wo ' ) NEW_LINE DEDENT DEDENT print arr NEW_LINE return sum ( arr ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE input_file = sys . argv [ 1 ] NEW_LINE output_file = input_file [ : ] . replace ( ' . in ' , ' . out ' ) NEW_LINE f_in = open ( input_file , ' r ' ) NEW_LINE f_out = open ( output_file , ' w ' ) NEW_LINE T , = [ int ( x ) for x in f_in . readline ( ) . split ( ) ] NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT print NEW_LINE print ' = = = = = = = = = = = = = = = = = = = = = ' NEW_LINE print ' ▁ ▁ ▁ ▁ ' + str ( case ) NEW_LINE print ' = = = = = = = = = = = = = = = = = = = = = ' NEW_LINE s , n = [ x for x in f_in . readline ( ) . split ( ) ] NEW_LINE n = int ( n ) NEW_LINE ans = solve ( s , n ) NEW_LINE print ans NEW_LINE f_out . write ( ' Case ▁ # % d : ▁ % s \n ' % ( case , ans ) ) NEW_LINE DEDENT DEDENT

import argparse NEW_LINE import collections NEW_LINE import fractions NEW_LINE import functools NEW_LINE import itertools NEW_LINE import math NEW_LINE import operator NEW_LINE from sys import exit , stdin NEW_LINE from multiprocessing import Pool NEW_LINE def solve_star ( args ) : NEW_LINE INDENT return solve ( * args ) NEW_LINE DEDENT def read_int ( ) : NEW_LINE INDENT return int ( stdin . readline ( ) . strip ( ) ) NEW_LINE DEDENT def read_ints ( ) : NEW_LINE INDENT return [ int ( n ) for n in stdin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def read_words ( ) : NEW_LINE INDENT return stdin . readline ( ) . strip ( ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT name , n = read_words ( ) . split ( ) NEW_LINE return [ name , int ( n ) ] NEW_LINE DEDENT def solve ( name , n ) : NEW_LINE INDENT vowels = [ " a " , " e " , " i " , " o " , " u " ] NEW_LINE count = 0 NEW_LINE last = 0 NEW_LINE total = 0 NEW_LINE for e , c in enumerate ( name ) : NEW_LINE INDENT if c in vowels : NEW_LINE INDENT count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE if count == n : NEW_LINE INDENT this_string_starts = e - ( n - 1 ) NEW_LINE total += ( this_string_starts - last + 1 ) * ( len ( name ) - e ) NEW_LINE last = this_string_starts + 1 NEW_LINE count -= 1 NEW_LINE DEDENT DEDENT DEDENT return total NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT parser = argparse . ArgumentParser ( ) NEW_LINE parser . add_argument ( " - m " , " - - multi " , help = " turn ▁ on ▁ multiprocessing " , action = " store _ true " ) NEW_LINE args = parser . parse_args ( ) NEW_LINE with open ( " out . txt " , " w " ) as f : NEW_LINE INDENT if args . multi : NEW_LINE INDENT pool = Pool ( ) NEW_LINE iter = pool . imap ( solve_star , ( parse ( ) for i in range ( read_int ( ) ) ) ) NEW_LINE for i , result in enumerate ( iter ) : NEW_LINE INDENT s = " Case ▁ # { } : ▁ { } " . format ( i + 1 , result ) NEW_LINE print ( s ) NEW_LINE f . write ( s + " \n " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( read_int ( ) ) : NEW_LINE INDENT s = " Case ▁ # { } : ▁ { } " . format ( i + 1 , solve ( * parse ( ) ) ) NEW_LINE print ( s ) NEW_LINE f . write ( s + " \n " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT

import sys NEW_LINE import math NEW_LINE import itertools NEW_LINE for testcase in xrange ( 1 , int ( sys . stdin . readline ( ) ) + 1 ) : NEW_LINE INDENT name , n = [ str ( w ) for w in sys . stdin . readline ( ) . split ( ) ] NEW_LINE n = int ( n ) NEW_LINE starting_points = { } NEW_LINE enough_consants = False NEW_LINE num_consecutive = 0 NEW_LINE for index in xrange ( len ( name ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if name [ index ] in ' aeiou ' : NEW_LINE INDENT num_consecutive = 0 NEW_LINE DEDENT else : NEW_LINE INDENT num_consecutive += 1 NEW_LINE DEDENT if num_consecutive >= n : NEW_LINE INDENT starting_points [ index ] = 1 NEW_LINE DEDENT DEDENT if 0 in starting_points : NEW_LINE INDENT count = 1 NEW_LINE last_used = 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE last_used = 0 NEW_LINE DEDENT for index in xrange ( n , len ( name ) ) : NEW_LINE INDENT index_minus = index - n + 1 NEW_LINE if index_minus in starting_points : NEW_LINE INDENT count = count + index_minus + 1 NEW_LINE last_used = index_minus + 1 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + last_used NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % d ' % ( testcase , count ) NEW_LINE NEW_LINE DEDENT

import math , os , sys , random NEW_LINE vowels = ' aeiou ' NEW_LINE consonants = ' bcdfghjklmnpqrstvwxyz ' NEW_LINE vowels_set = frozenset ( vowels ) NEW_LINE consonants_set = frozenset ( consonants ) NEW_LINE def single_test ( IN , OUT ) : NEW_LINE INDENT name , n = IN . readline ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE L = len ( name ) NEW_LINE data = ' ' NEW_LINE for l in name : data += ' v ' if l in vowels_set else ' c ' NEW_LINE starts = [ ] NEW_LINE count = 0 NEW_LINE for i , l in enumerate ( data ) : NEW_LINE INDENT if l == ' v ' : NEW_LINE INDENT count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE if count >= n : NEW_LINE INDENT starts . append ( i + 1 - n ) NEW_LINE DEDENT DEDENT DEDENT freespaces = [ ] NEW_LINE cs = 0 NEW_LINE for i in range ( L ) : NEW_LINE INDENT while cs != - 1 and cs < len ( starts ) and i > starts [ cs ] : NEW_LINE INDENT cs += 1 NEW_LINE DEDENT if cs == len ( starts ) : NEW_LINE INDENT cs = - 1 NEW_LINE DEDENT if cs == - 1 : NEW_LINE INDENT if i < L : freespaces . append ( ( i , L - i ) ) NEW_LINE DEDENT else : NEW_LINE INDENT if starts [ cs ] + n - 1 > i : freespaces . append ( ( i , starts [ cs ] + n - 1 - i ) ) NEW_LINE DEDENT DEDENT result = ( L * ( L + 1 ) ) // 2 NEW_LINE for f in freespaces : NEW_LINE INDENT result -= f [ 1 ] NEW_LINE DEDENT return result NEW_LINE DEDENT def main ( IN , OUT ) : NEW_LINE INDENT T = int ( IN . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT OUT . write ( ' Case ▁ # % d : ▁ % d \n ' % ( i , single_test ( IN , OUT ) ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT assert len ( sys . argv ) == 2 NEW_LINE IN = open ( sys . argv [ 1 ] , ' rt ' ) NEW_LINE OUT = open ( ' % s . out ' % sys . argv [ 1 ] [ : - 3 ] , ' wt ' ) NEW_LINE main ( IN , OUT ) NEW_LINE OUT . close ( ) NEW_LINE IN . close ( ) NEW_LINE DEDENT

def puts ( s ) : NEW_LINE INDENT print ( s , end = ' ' ) NEW_LINE DEDENT vowels = " aeiou " NEW_LINE def solve ( case ) : NEW_LINE INDENT S , n = input ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE streak = 0 NEW_LINE cons = [ ] NEW_LINE for c in S : NEW_LINE INDENT if c in vowels : NEW_LINE INDENT streak = 0 NEW_LINE DEDENT else : NEW_LINE INDENT streak += 1 NEW_LINE DEDENT cons += [ streak ] NEW_LINE DEDENT count = 0 NEW_LINE m = 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if cons [ i ] >= n : NEW_LINE INDENT m = i + 2 - n NEW_LINE DEDENT count += m NEW_LINE DEDENT print ( count ) NEW_LINE DEDENT for case in range ( 1 , 1 + int ( input ( ) ) ) : NEW_LINE INDENT puts ( " Case ▁ # " + str ( case ) + " : ▁ " ) NEW_LINE solve ( case ) NEW_LINE DEDENT


import java . io . * ; import java . util . StringTokenizer ; public class B { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( " B - large . in " ) ) ; PrintWriter out = new PrintWriter ( " b . out " ) ; int C = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 1 ; i <= C ; i ++ ) { StringTokenizer tz = new StringTokenizer ( in . readLine ( ) ) ; int N = Integer . parseInt ( tz . nextToken ( ) ) ; int M = Integer . parseInt ( tz . nextToken ( ) ) ; int A = Integer . parseInt ( tz . nextToken ( ) ) ; String ans ; if ( A > N * M ) { ans = " IMPOSSIBLE " ; } else { int a = A / M ; int b , c = 1 , d = M ; if ( a * M == A ) { b = 0 ; } else { a ++ ; b = a * d - A ; } ans = "0 ▁ 0 ▁ " + a + " ▁ " + b + " ▁ " + c + " ▁ " + d ; } out . println ( " Case ▁ # " + i + " : ▁ " + ans ) ; } in . close ( ) ; out . close ( ) ; } }

import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . Locale ; public class B implements Runnable { static final String NAME = " b - large " ; public void solve ( ) throws Exception { int ntest = Integer . parseInt ( readWord ( ) ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { long n = Long . parseLong ( readWord ( ) ) ; long m = Long . parseLong ( readWord ( ) ) ; long a = Long . parseLong ( readWord ( ) ) ; if ( a > n * m ) { stdout . write ( " Case ▁ # " + test + " : ▁ " + " IMPOSSIBLE \n " ) ; continue ; } long s = a % n ; if ( s == 0 ) { stdout . write ( " Case ▁ # " + test + " : ▁ " + "0 ▁ 0 ▁ " + n + " ▁ " + 0 + " ▁ " + n + " ▁ " + ( a / n ) + " \n " ) ; } else { stdout . write ( " Case ▁ # " + test + " : ▁ " + "0 ▁ 0 ▁ " + n + " ▁ " + 1 + " ▁ " + ( n - s ) + " ▁ " + ( a / n + 1 ) + " \n " ) ; } } } static BufferedReader stdin ; static BufferedWriter stdout ; String readWord ( ) throws Exception { StringBuilder b = new StringBuilder ( ) ; int c ; while ( true ) { c = stdin . read ( ) ; if ( c < 0 ) { return " " ; } if ( c > 32 ) { break ; } } while ( true ) { b . append ( ( char ) c ) ; c = stdin . read ( ) ; if ( c <= 32 ) { break ; } } return b . toString ( ) ; } public void run ( ) { try { stdin = new BufferedReader ( new FileReader ( NAME + " . in " ) ) ; stdout = new BufferedWriter ( new FileWriter ( NAME + " . out " ) ) ; solve ( ) ; stdout . close ( ) ; stdin . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } public static void main ( String [ ] args ) { try { Locale . setDefault ( Locale . US ) ; } catch ( Throwable e ) { } new Thread ( new B ( ) ) . start ( ) ; } }

import java . io . PrintWriter ; import java . io . File ; import java . io . FileNotFoundException ; import java . util . Scanner ; public class B { static Scanner in ; static PrintWriter out ; public static void main ( String [ ] args ) throws FileNotFoundException { in = new Scanner ( new File ( " input . txt " ) ) ; out = new PrintWriter ( " output . txt " ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + new B ( ) . solve ( ) ) ; } out . close ( ) ; } private Object solve ( ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int a = in . nextInt ( ) ; boolean [ ] q = new boolean [ n * m + 1 ] ; int [ ] xx = new int [ n * m + 1 ] ; int [ ] yy = new int [ n * m + 1 ] ; for ( int x = 0 ; x <= n ; x ++ ) { for ( int y = 0 ; y <= m ; y ++ ) { int z = ( x * y ) ; q [ z ] = true ; xx [ z ] = x ; yy [ z ] = y ; } } for ( int i = 0 ; i <= ( n * m - a ) ; i ++ ) { if ( q [ i ] && q [ i + a ] ) { return "0 ▁ 0 ▁ " + xx [ i ] + " ▁ " + yy [ i + a ] + " ▁ " + xx [ i + a ] + " ▁ " + yy [ i ] ; } } return " IMPOSSIBLE " ; } }

import java . io . * ; import java . util . * ; public class B implements Runnable { private Scanner in ; private PrintWriter out ; private void solve ( int testCase ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int a = in . nextInt ( ) ; if ( a > n * m ) { out . println ( " Case ▁ # " + testCase + " : ▁ IMPOSSIBLE " ) ; return ; } int p = a - a % n ; if ( p < a ) p += n ; int y3 = p / n ; int x3 = p - a ; out . println ( " Case ▁ # " + testCase + " : ▁ 0 ▁ 0 ▁ " + n + " ▁ 1 ▁ " + x3 + " ▁ " + y3 ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; new Thread ( new B ( ) ) . start ( ) ; } public void run ( ) { try { in = new Scanner ( new FileReader ( " b . in " ) ) ; out = new PrintWriter ( " b . out " ) ; int n = in . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) solve ( i ) ; in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } }

import java . io . BufferedInputStream ; import java . io . FileInputStream ; import java . io . InputStream ; import java . util . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . lang . Integer . * ; import static java . lang . Character . * ; public class B { Scanner scan ; InputStream in ; int intLine ( ) { return parseInt ( scan . nextLine ( ) ) ; } String find ( long A , long B , long area ) { for ( long a = 1 ; a <= A ; a ++ ) for ( long b = 1 ; b <= B ; b ++ ) { for ( long x = 0 ; x <= b ; x ++ ) for ( long y = 0 ; y <= a ; y ++ ) { long r = x * a + y * b - x * y ; if ( r == area ) { return String . format ( " % d ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d " , 0 , x , y , 0 , a , b ) ; } } } return null ; } String solve ( ) { long res = 0 ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; long area = scan . nextLong ( ) ; if ( find ( A , B , area ) != null ) return find ( A , B , area ) ; return " IMPOSSIBLE " ; } void solveAll ( ) { int N = parseInt ( scan . nextLine ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { String r = solve ( ) ; System . out . format ( " Case ▁ # % d : ▁ % s \n " , i + 1 , r ) ; } } B ( ) throws Exception { in = new BufferedInputStream ( new FileInputStream ( " B - small - attempt0 . in " ) ) ; scan = new Scanner ( in ) ; } public static void main ( String [ ] args ) throws Exception { Locale . setDefault ( Locale . US ) ; new B ( ) . solveAll ( ) ; } }

import psyco NEW_LINE psyco . full ( ) NEW_LINE def solve ( N , M , A ) : NEW_LINE INDENT for x1 in range ( N + 1 ) : NEW_LINE INDENT for y1 in range ( M + 1 ) : NEW_LINE INDENT for x2 in range ( N + 1 ) : NEW_LINE INDENT for y2 in range ( M + 1 ) : NEW_LINE INDENT S = abs ( x1 * y2 - x2 * y1 ) NEW_LINE if S == A : NEW_LINE INDENT return " % d ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d " % ( 0 , 0 , x1 , y1 , x2 , y2 ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT return " IMPOSSIBLE " NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT C = input ( ) NEW_LINE for case in range ( C ) : NEW_LINE INDENT N , M , A = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE print " Case ▁ # % d : " % ( case + 1 ) , solve ( N , M , A ) NEW_LINE DEDENT DEDENT

def process ( n , m , a ) : NEW_LINE INDENT if n * m < a : return None NEW_LINE for x1 in xrange ( n + 1 ) : NEW_LINE INDENT for y1 in xrange ( m + 1 ) : NEW_LINE INDENT for x2 in xrange ( max ( x1 - n , - n ) , min ( x1 + n , n ) + 1 ) : NEW_LINE INDENT for y2 in xrange ( max ( y1 - m , - m ) , min ( y1 + m , m ) + 1 ) : NEW_LINE INDENT if abs ( x2 * y1 - y2 * x1 ) == a : NEW_LINE INDENT xmin = - min ( 0 , x1 , x2 ) NEW_LINE ymin = - min ( 0 , y1 , y2 ) NEW_LINE return ( ( xmin , ymin ) , ( x1 + xmin , y1 + ymin ) , ( x2 + xmin , y2 + ymin ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT return None NEW_LINE DEDENT import sys NEW_LINE next = iter ( sys . stdin ) . next NEW_LINE ncases = int ( next ( ) ) NEW_LINE for i in xrange ( ncases ) : NEW_LINE INDENT n , m , a = map ( int , next ( ) . split ( ) ) NEW_LINE coords = process ( n , m , a ) NEW_LINE if coords is None : NEW_LINE INDENT print ' Case ▁ # % d : ▁ IMPOSSIBLE ' % ( i + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT assert abs ( ( coords [ 2 ] [ 0 ] - coords [ 0 ] [ 0 ] ) * ( coords [ 1 ] [ 1 ] - coords [ 0 ] [ 1 ] ) - ( coords [ 1 ] [ 0 ] - coords [ 0 ] [ 0 ] ) * ( coords [ 2 ] [ 1 ] - coords [ 0 ] [ 1 ] ) ) == a NEW_LINE print ' Case ▁ # % d : ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d ▁ % d ' % ( i + 1 , coords [ 0 ] [ 0 ] , coords [ 0 ] [ 1 ] , coords [ 1 ] [ 0 ] , coords [ 1 ] [ 1 ] , coords [ 2 ] [ 0 ] , coords [ 2 ] [ 1 ] ) NEW_LINE DEDENT sys . stdout . flush ( ) NEW_LINE DEDENT

import psyco NEW_LINE import sys NEW_LINE psyco . profile ( ) NEW_LINE def main ( ) : NEW_LINE INDENT rl = sys . stdin . readline NEW_LINE for t in xrange ( int ( rl ( ) ) ) : NEW_LINE INDENT n , m , a = [ int ( x ) for x in rl ( ) . strip ( ) . split ( ) ] NEW_LINE ans = False NEW_LINE val = { } NEW_LINE for x in xrange ( 0 , n + 1 ) : NEW_LINE INDENT for y in xrange ( 0 , m + 1 ) : NEW_LINE INDENT if x * y not in val : NEW_LINE INDENT val [ x * y ] = ( x , y ) NEW_LINE DEDENT DEDENT DEDENT for x in xrange ( 1 , n + 1 ) : NEW_LINE INDENT for y in xrange ( a / x , m + 1 ) : NEW_LINE INDENT if x * y < a : NEW_LINE INDENT continue NEW_LINE DEDENT if x * y - a in val : NEW_LINE INDENT v = val [ x * y - a ] NEW_LINE ans = ( 0 , 0 , x , v [ 1 ] , v [ 0 ] , y ) NEW_LINE break NEW_LINE DEDENT DEDENT if ans : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ' % ( t + 1 ) , NEW_LINE if ans : NEW_LINE INDENT for i in ans : NEW_LINE INDENT print i , NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ' IMPOSSIBLE ' , NEW_LINE DEDENT print NEW_LINE DEDENT DEDENT main ( ) NEW_LINE

FI = ' B - large . in ' NEW_LINE def case ( fi , fo , num ) : NEW_LINE INDENT N , M , A = map ( int , fi . readline ( ) . split ( ) ) NEW_LINE for X in xrange ( 1 , N + 1 ) : NEW_LINE INDENT for Y in xrange ( A / X , M + 1 ) : NEW_LINE INDENT for x in xrange ( 1 , X + 1 ) : NEW_LINE INDENT y = ( X * Y - A ) / x NEW_LINE if y >= 0 and A == X * Y - x * y : NEW_LINE INDENT fo . write ( ' Case ▁ # % d : ▁ 0 ▁ 0 ▁ % d ▁ % d ▁ % d ▁ % d \n ' % ( num , x , Y , X , y ) ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT DEDENT fo . write ( ' Case ▁ # % d : ▁ IMPOSSIBLE \n ' % num ) NEW_LINE DEDENT def rl ( f , n ) : NEW_LINE INDENT return [ f . readline ( ) for i in xrange ( n ) ] NEW_LINE DEDENT def zw ( fs , es ) : NEW_LINE INDENT return [ f ( e ) for f , e in zip ( fs , es ) ] NEW_LINE DEDENT def cases ( fi , fo ) : NEW_LINE INDENT for i in xrange ( int ( fi . readline ( ) ) ) : NEW_LINE INDENT case ( fi , fo , i + 1 ) NEW_LINE DEDENT DEDENT fi = open ( FI ) NEW_LINE fo = open ( ' out . txt ' , ' w ' ) NEW_LINE cases ( fi , fo ) NEW_LINE fi . close ( ) NEW_LINE fo . close ( ) NEW_LINE f = open ( ' out . txt ' ) NEW_LINE print f . read ( ) NEW_LINE

import sys NEW_LINE import math NEW_LINE def do_test ( input ) : NEW_LINE INDENT line = input . readline ( ) . split ( ' ▁ ' ) NEW_LINE N = int ( line [ 0 ] ) NEW_LINE M = int ( line [ 1 ] ) NEW_LINE A = int ( line [ 2 ] ) NEW_LINE flipped = False NEW_LINE if M > N : NEW_LINE INDENT z = M NEW_LINE M = N NEW_LINE N = z NEW_LINE flipped = True NEW_LINE DEDENT if A > M * N : NEW_LINE INDENT return " IMPOSSIBLE " NEW_LINE DEDENT beta = - ( ( - A ) % M ) NEW_LINE alpha = ( A - beta ) // M + beta NEW_LINE a = M NEW_LINE b = M - 1 NEW_LINE x2 = 0 NEW_LINE x1 = alpha - beta NEW_LINE x3 = - beta NEW_LINE y3 = 0 NEW_LINE y1 = b NEW_LINE y2 = a NEW_LINE if not flipped : NEW_LINE INDENT return str ( x1 ) + ' ▁ ' + str ( y1 ) + ' ▁ ' + str ( x2 ) + ' ▁ ' + str ( y2 ) + ' ▁ ' + str ( x3 ) + ' ▁ ' + str ( y3 ) NEW_LINE DEDENT else : NEW_LINE INDENT return str ( y1 ) + ' ▁ ' + str ( x1 ) + ' ▁ ' + str ( y2 ) + ' ▁ ' + str ( x2 ) + ' ▁ ' + str ( y3 ) + ' ▁ ' + str ( x3 ) NEW_LINE DEDENT DEDENT input = sys . stdin NEW_LINE N = int ( input . readline ( ) ) NEW_LINE for test in range ( N ) : NEW_LINE INDENT answer = do_test ( input ) NEW_LINE print ' Case ▁ # % ( case ) d : ▁ % ( answer ) s ' % { ' case ' : test + 1 , ' answer ' : answer } NEW_LINE sys . stdout . flush ( ) NEW_LINE DEDENT


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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