package round3 ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class D { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int P = sc . nextInt ( ) ; long [ ] vals = new long [ P ] , freqs = new long [ P ] ; Map < Long , Integer > pos = new HashMap < Long , Integer > ( ) ; for ( int i = 0 ; i < vals . length ; i ++ ) { vals [ i ] = sc . nextLong ( ) ; pos . put ( vals [ i ] , i ) ; } long total = 0 ; for ( int i = 0 ; i < vals . length ; i ++ ) { freqs [ i ] = sc . nextLong ( ) ; total += freqs [ i ] ; } int cant = 0 ; long tmp = total ; while ( tmp > 1 ) { tmp /= 2 ; cant ++ ; } long [ ] ans = new long [ cant ] ; int sumIdx = 0 , setIdx = 0 ; for ( setIdx = 0 ; setIdx < cant ; setIdx ++ ) { for ( int m = 0 ; m < ( 1 << setIdx ) ; m ++ ) { if ( setIdx != 0 && ( m & ( 1 << ( setIdx - 1 ) ) ) == 0 ) continue ; long val = 0 ; for ( int i = 0 ; i < setIdx ; i ++ ) if ( ( m & ( 1 << i ) ) != 0 ) val += ans [ i ] ; freqs [ pos . get ( val ) ] -- ; } while ( freqs [ sumIdx ] == 0 ) { sumIdx ++ ; } ans [ setIdx ] = vals [ sumIdx ] ; } System . out . print ( " Case ▁ # " + caze + " : " ) ; for ( int i = 0 ; i < ans . length ; i ++ ) { System . out . print ( " ▁ " + ans [ i ] ) ; } System . out . println ( ) ; } } }

import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; public class D { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numCases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; caseNum ++ ) { int P = sc . nextInt ( ) ; int [ ] E = new int [ P ] ; int [ ] F = new int [ P ] ; for ( int i = 0 ; i < P ; i ++ ) { E [ i ] = sc . nextInt ( ) ; } int total = 0 ; for ( int i = 0 ; i < P ; i ++ ) { F [ i ] = sc . nextInt ( ) ; total += F [ i ] ; } int numElems = ( int ) ( Math . log ( total ) / Math . log ( 2 ) + 0.5 ) ; List < Integer > S = new ArrayList < > ( ) ; Map < Integer , Integer > frequencies = new HashMap < > ( ) ; frequencies . put ( 0 , 1 ) ; for ( int i = 0 ; i < P ; i ++ ) { if ( ! frequencies . containsKey ( E [ i ] ) ) { frequencies . put ( E [ i ] , 0 ) ; } while ( frequencies . get ( E [ i ] ) < F [ i ] ) { S . add ( E [ i ] ) ; Map < Integer , Integer > temp = new HashMap < > ( frequencies ) ; for ( Map . Entry < Integer , Integer > entry : frequencies . entrySet ( ) ) { int sum = entry . getKey ( ) + E [ i ] ; if ( temp . containsKey ( sum ) ) { temp . put ( sum , entry . getValue ( ) + frequencies . get ( sum ) ) ; } else { temp . put ( sum , entry . getValue ( ) ) ; } } frequencies = temp ; } } System . out . print ( " Case ▁ # " + caseNum + " : " ) ; for ( int i : S ) { System . out . print ( " ▁ " + i ) ; } System . out . println ( ) ; } } }

import sys NEW_LINE def simplify ( ef , d ) : NEW_LINE INDENT ef2 = [ ] NEW_LINE for i in xrange ( len ( ef ) ) : NEW_LINE INDENT e = ef [ i ] [ 0 ] NEW_LINE f = ef [ i ] [ 1 ] NEW_LINE if f == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT ef2 . append ( ef [ i ] ) NEW_LINE for x in ef : NEW_LINE INDENT if x [ 0 ] != e + d : NEW_LINE INDENT continue NEW_LINE DEDENT x [ 1 ] -= f NEW_LINE DEDENT DEDENT return ef2 NEW_LINE DEDENT def compute ( N , E , F ) : NEW_LINE INDENT ef = sorted ( [ [ E [ i ] , F [ i ] ] for i in xrange ( len ( E ) ) ] ) NEW_LINE res = [ ] NEW_LINE a = ef [ - 1 ] [ 1 ] NEW_LINE while a > 1 : NEW_LINE INDENT res . append ( 0 ) NEW_LINE a /= 2 NEW_LINE DEDENT for i in xrange ( len ( ef ) ) : NEW_LINE INDENT ef [ i ] [ 1 ] /= ef [ - 1 ] [ 1 ] NEW_LINE DEDENT while len ( ef ) > 1 : NEW_LINE INDENT d = ef [ - 1 ] [ 0 ] - ef [ - 2 ] [ 0 ] NEW_LINE res . append ( d ) NEW_LINE ef = simplify ( ef , d ) NEW_LINE DEDENT return ' ▁ ' . join ( map ( str , sorted ( res ) ) ) NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT N = int ( sys . stdin . readline ( ) . strip ( ) ) NEW_LINE E = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE F = map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) NEW_LINE return N , E , F 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

from collections import Counter NEW_LINE T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT P , = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE E = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE F = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE neg = min ( E ) NEW_LINE E = [ i - neg for i in E ] NEW_LINE c = Counter ( dict ( zip ( E , F ) ) ) NEW_LINE ans = [ ] NEW_LINE while c [ 0 ] > 1 : NEW_LINE INDENT ans . append ( 0 ) NEW_LINE d = Counter ( ) NEW_LINE for k in c : NEW_LINE INDENT d [ k ] = c [ k ] // 2 NEW_LINE DEDENT c = d NEW_LINE DEDENT del c [ 0 ] NEW_LINE while c : NEW_LINE INDENT e = min ( c ) NEW_LINE ans . append ( e ) NEW_LINE c [ e ] -= 1 NEW_LINE d = Counter ( ) NEW_LINE for k in sorted ( c . keys ( ) ) : NEW_LINE INDENT if c [ k ] > 0 : NEW_LINE INDENT d [ k ] = c [ k ] NEW_LINE assert k + e in c NEW_LINE c [ k + e ] -= c [ k ] NEW_LINE DEDENT DEDENT c = d NEW_LINE DEDENT while neg : NEW_LINE INDENT t = max ( i for i in ans if i <= - neg ) NEW_LINE del ans [ ans . index ( t ) ] NEW_LINE ans . append ( - t ) NEW_LINE neg += t NEW_LINE DEDENT ans . sort ( ) NEW_LINE ans = ' ▁ ' . join ( map ( str , ans ) ) NEW_LINE print ( " Case ▁ # { } : ▁ { } " . format ( case , ans ) ) NEW_LINE DEDENT

from collections import defaultdict NEW_LINE from math import log NEW_LINE def solve ( ) : NEW_LINE INDENT n = int ( raw_input ( ) ) NEW_LINE e = map ( int , raw_input ( ) . split ( ) ) NEW_LINE f = map ( int , raw_input ( ) . split ( ) ) NEW_LINE zeroes = int ( log ( f [ 0 ] , 2 ) ) NEW_LINE res = [ 0 ] * zeroes NEW_LINE sums = defaultdict ( int ) NEW_LINE for i in xrange ( 1 , n ) : NEW_LINE INDENT a = e [ i ] NEW_LINE freq = f [ i ] / ( 2 ** zeroes ) NEW_LINE for j in xrange ( freq - sums [ a ] ) : NEW_LINE INDENT res . append ( a ) NEW_LINE new_sums = defaultdict ( int ) NEW_LINE new_sums [ a ] = 1 NEW_LINE for k , v in sums . iteritems ( ) : NEW_LINE INDENT new_sums [ k ] += v NEW_LINE new_sums [ k + a ] += v NEW_LINE DEDENT sums = new_sums NEW_LINE DEDENT DEDENT return ' ▁ ' . join ( map ( str , res ) ) NEW_LINE DEDENT for i in xrange ( input ( ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( i + 1 , solve ( ) ) NEW_LINE DEDENT

from itertools import * NEW_LINE from bisect import bisect NEW_LINE from math import log NEW_LINE import sys NEW_LINE facts = [ 1 ] NEW_LINE for i in xrange ( 1 , 100 ) : NEW_LINE INDENT facts . append ( facts [ - 1 ] * i ) NEW_LINE DEDENT def choose ( n , k ) : NEW_LINE INDENT return facts [ n ] / facts [ k ] / facts [ n - k ] NEW_LINE DEDENT lines = open ( " c . in " ) . read ( ) . split ( " \n " ) NEW_LINE T = int ( lines [ 0 ] ) NEW_LINE def f ( P , E , F ) : NEW_LINE INDENT elements = [ [ int ( i ) , int ( j ) ] for i , j in izip ( E , F ) ] NEW_LINE total_elts = sum ( f for e , f in elements ) NEW_LINE accounted_for = [ ] NEW_LINE accounted_for_sums = { 0 : 1 } NEW_LINE unaccounted_for_elts = dict ( [ int ( i ) , int ( j ) ] for i , j in izip ( E , F ) ) NEW_LINE unaccounted_for_elts [ 0 ] -= 1 NEW_LINE while unaccounted_for_elts : NEW_LINE INDENT elt = min ( unaccounted_for_elts ) NEW_LINE freq = 1 NEW_LINE if unaccounted_for_elts [ elt ] == 0 : NEW_LINE INDENT del unaccounted_for_elts [ elt ] NEW_LINE continue NEW_LINE DEDENT new_d = dict ( accounted_for_sums . iteritems ( ) ) NEW_LINE for i in xrange ( freq ) : NEW_LINE INDENT accounted_for . append ( elt ) NEW_LINE new_e = ( i + 1 ) * elt NEW_LINE new_f = choose ( freq , i + 1 ) NEW_LINE for e , f in accounted_for_sums . iteritems ( ) : NEW_LINE INDENT total_e = new_e + e NEW_LINE total_f = new_f * f NEW_LINE new_d [ total_e ] = new_d . get ( total_e , 0 ) + total_f NEW_LINE unaccounted_for_elts [ total_e ] = unaccounted_for_elts . get ( total_e , 0 ) - total_f NEW_LINE DEDENT DEDENT accounted_for_sums = new_d NEW_LINE DEDENT return ' ▁ ' . join ( str ( s ) for s in sorted ( accounted_for ) ) NEW_LINE DEDENT curr_i = 1 NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT P = int ( lines [ curr_i ] ) NEW_LINE curr_i += 1 NEW_LINE out = f ( P , lines [ curr_i ] . split ( ' ▁ ' ) , lines [ curr_i + 1 ] . split ( ' ▁ ' ) ) NEW_LINE curr_i += 2 NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i , out ) NEW_LINE DEDENT

import math , collections , itertools NEW_LINE import sys NEW_LINE NCASE = int ( sys . stdin . readline ( ) ) NEW_LINE for case in range ( 1 , NCASE + 1 ) : NEW_LINE INDENT P = map ( int , sys . stdin . readline ( ) . split ( ) ) [ 0 ] NEW_LINE E = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE F = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE count = dict ( ( e , f ) for ( e , f ) in zip ( E , F ) ) NEW_LINE ans = [ ] NEW_LINE if count [ 0 ] > 1 : NEW_LINE INDENT while count [ 0 ] > 1 : NEW_LINE INDENT ans . append ( 0 ) NEW_LINE count [ 0 ] /= 2 NEW_LINE DEDENT m = 1 << len ( ans ) NEW_LINE for k in count : NEW_LINE INDENT if k != 0 : NEW_LINE INDENT count [ k ] /= m NEW_LINE DEDENT DEDENT DEDENT keys = sorted ( count . keys ( ) ) NEW_LINE while len ( keys ) > 1 : NEW_LINE INDENT key = keys [ 1 ] NEW_LINE ans . append ( key ) NEW_LINE nc = { } NEW_LINE nkeys = [ ] NEW_LINE for k in reversed ( keys ) : NEW_LINE INDENT if count [ k ] > 0 : NEW_LINE INDENT count [ k - key ] -= count [ k ] NEW_LINE nc [ k - key ] = count [ k ] NEW_LINE DEDENT DEDENT count = nc NEW_LINE keys = sorted ( nc . keys ( ) ) NEW_LINE DEDENT ans = ' ▁ ' . join ( map ( str , sorted ( ans ) ) ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( case , ans ) NEW_LINE DEDENT


import java . io . * ; import java . math . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( new File ( " Main . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " Main . out " ) ) ; int tests = in . nextInt ( ) ; final int MOD = 100003 ; int [ ] [ ] f = new int [ 512 ] [ 512 ] ; for ( int m = 0 ; m < 512 ; m ++ ) f [ 0 ] [ m ] = 1 ; for ( int n = 1 ; n < 512 ; n ++ ) { for ( int m = 1 ; m <= n ; m ++ ) { f [ n ] [ m ] = 0 ; for ( int k = 1 ; k <= m ; k ++ ) { f [ n ] [ m ] = ( f [ n ] [ m ] + f [ n - k ] [ m ] ) % MOD ; } } } for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) System . out . print ( f [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } for ( int test = 1 ; test <= tests ; test ++ ) { out . print ( " Case ▁ # " + test + " : ▁ " ) ; int n = in . nextInt ( ) ; int ans = 0 ; for ( int h = 2 ; h <= n ; h ++ ) ans = ( ans + f [ n - 1 ] [ h - 1 ] ) % MOD ; out . println ( ans ) ; } out . close ( ) ; } }

import java . util . * ; import java . io . * ; public class x { static final int MOD = 100003 ; static final int MAXN = 500 ; public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( System . in ) ; int t = in . nextInt ( ) ; int [ ] [ ] C = new int [ MAXN + 1 ] [ MAXN + 1 ] ; for ( int i = 0 ; i <= MAXN ; i ++ ) { C [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j <= i ; j ++ ) { C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) % MOD ; } } int [ ] [ ] D = new int [ MAXN + 1 ] [ MAXN + 1 ] ; int [ ] A = new int [ MAXN + 1 ] ; D [ 1 ] [ 0 ] = 1 ; for ( int i = 2 ; i <= MAXN ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) { for ( int k = 0 ; k < j ; k ++ ) if ( j - k - 1 >= 0 && j - k - 1 <= i - j - 1 ) { long cur = D [ j ] [ k ] ; cur = ( D [ i ] [ j ] + cur * C [ i - j - 1 ] [ j - k - 1 ] ) % MOD ; D [ i ] [ j ] = ( int ) cur ; } A [ i ] = ( A [ i ] + D [ i ] [ j ] ) % MOD ; } } for ( int tt = 1 ; tt <= t ; tt ++ ) { int n = in . nextInt ( ) ; System . out . println ( " Case ▁ # " + tt + " : ▁ " + A [ n ] ) ; } ; } ; } ;

import java . io . BufferedInputStream ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintStream ; import java . io . FileOutputStream ; public class Main { public static void main ( String [ ] args ) { try { File file = new File ( " C - large . in " ) ; FileInputStream fis = new FileInputStream ( file ) ; BufferedInputStream bis = new BufferedInputStream ( fis ) ; BufferedReader dis = new BufferedReader ( new InputStreamReader ( bis ) ) ; File ofile = new File ( " C - large . out " ) ; if ( ! ofile . exists ( ) ) { ofile . createNewFile ( ) ; } PrintStream out = new PrintStream ( new FileOutputStream ( ofile ) ) ; int [ ] [ ] f = new int [ 501 ] [ 501 ] ; for ( int i = 0 ; i < 501 ; i ++ ) { for ( int j = 0 ; j < 501 ; j ++ ) { if ( i == 0 ) { f [ i ] [ j ] = 1 ; } else { for ( int k = 1 ; k <= j ; k ++ ) { if ( k > i ) break ; f [ i ] [ j ] += f [ i - k ] [ j ] ; } f [ i ] [ j ] %= 100003 ; } } } int [ ] f2 = new int [ 501 ] ; for ( int i = 1 ; i < 501 ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { f2 [ i ] += f [ j ] [ i - j ] ; f2 [ i ] %= 100003 ; } } int T = Integer . parseInt ( dis . readLine ( ) ) ; int c = 0 ; while ( c ++ < T ) { out . print ( " Case ▁ # " + c + " : ▁ " ) ; out . println ( f2 [ Integer . parseInt ( dis . readLine ( ) ) - 1 ] ) ; } fis . close ( ) ; bis . close ( ) ; dis . close ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }

import java . io . * ; import java . math . * ; import java . util . * ; public class C { public static void main ( String [ ] args ) { BigInteger [ ] [ ] combine = new BigInteger [ 512 ] [ 512 ] ; BigInteger [ ] [ ] a = new BigInteger [ 512 ] [ 512 ] ; BigInteger [ ] s = new BigInteger [ 512 ] ; for ( int i = 0 ; i < 512 ; i ++ ) { combine [ i ] [ 0 ] = BigInteger . ONE ; combine [ i ] [ i ] = BigInteger . ONE ; for ( int j = 1 ; j < i ; j ++ ) { combine [ i ] [ j ] = combine [ i - 1 ] [ j ] . add ( combine [ i - 1 ] [ j - 1 ] ) ; } for ( int j = 0 ; j < 512 ; j ++ ) a [ i ] [ j ] = BigInteger . ZERO ; s [ i ] = BigInteger . ZERO ; } for ( int n = 2 ; n < 512 ; n ++ ) { a [ n ] [ 1 ] = BigInteger . ONE ; for ( int m = 2 ; m < n ; m ++ ) { a [ n ] [ m ] = BigInteger . ZERO ; for ( int k = 1 ; k < m ; k ++ ) { int N = n - m - 1 ; int M = m - k - 1 ; if ( M >= 0 && M <= N ) { a [ n ] [ m ] = a [ n ] [ m ] . add ( combine [ N ] [ M ] . multiply ( a [ m ] [ k ] ) ) ; } } } for ( int m = 1 ; m < n ; m ++ ) { s [ n ] = s [ n ] . add ( a [ n ] [ m ] ) ; } } Scanner sc = new Scanner ( System . in ) ; int tests = sc . nextInt ( ) ; for ( int cas = 1 ; cas <= tests ; cas ++ ) { int n = sc . nextInt ( ) ; System . out . println ( " Case ▁ # " + cas + " : ▁ " + ( s [ n ] . mod ( BigInteger . valueOf ( 100003 ) ) ) ) ; } } }

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

from sys import stdin , stdout NEW_LINE nCk = [ [ int ( ) ] * 501 for i in range ( 501 ) ] NEW_LINE for n in range ( 0 , 501 ) : NEW_LINE INDENT nCk [ n ] [ 0 ] = 1 NEW_LINE for k in range ( 1 , n + 1 ) : NEW_LINE INDENT nCk [ n ] [ k ] = nCk [ n ] [ k - 1 ] * ( n + 1 - k ) / k NEW_LINE DEDENT DEDENT for n in range ( 0 , 501 ) : NEW_LINE INDENT for k in range ( 1 , n + 1 ) : NEW_LINE INDENT nCk [ n ] [ k ] %= 100003 NEW_LINE DEDENT DEDENT Y = [ [ int ( ) ] * 501 for i in range ( 501 ) ] NEW_LINE y = [ int ( ) ] * 501 NEW_LINE for i in range ( 2 , 501 ) : NEW_LINE INDENT Y [ i ] [ 1 ] = 1 NEW_LINE y [ i ] = 1 NEW_LINE for j in range ( 2 , i ) : NEW_LINE INDENT for k in range ( 1 , j ) : NEW_LINE INDENT Y [ i ] [ j ] += Y [ j ] [ k ] * nCk [ i - j - 1 ] [ j - k - 1 ] NEW_LINE DEDENT y [ i ] += Y [ i ] [ j ] NEW_LINE DEDENT y [ i ] %= 100003 NEW_LINE DEDENT for x in range ( 1 , int ( stdin . readline ( ) ) + 1 ) : NEW_LINE INDENT n = int ( stdin . readline ( ) ) NEW_LINE stdout . write ( ' Case ▁ # % i : ▁ % i \n ' % ( x , y [ n ] ) ) NEW_LINE DEDENT

import pickle NEW_LINE import os NEW_LINE modulo = 100003 NEW_LINE combtable = { } NEW_LINE for i in xrange ( 0 , 1000 ) : NEW_LINE INDENT for j in xrange ( 0 , i + 1 ) : NEW_LINE INDENT if j == 0 or i == j : NEW_LINE INDENT combtable [ ( i , j ) ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT combtable [ ( i , j ) ] = ( combtable [ ( i - 1 , j - 1 ) ] + combtable [ ( i - 1 , j ) ] ) % modulo NEW_LINE DEDENT DEDENT DEDENT D = { } NEW_LINE if os . path . exists ( ' cached ' ) : NEW_LINE INDENT D = pickle . loads ( file ( ' cached ' , ' rb ' ) . read ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT for n in xrange ( 2 , 501 ) : NEW_LINE INDENT for l in xrange ( 1 , n ) : NEW_LINE INDENT if l == 1 : NEW_LINE INDENT D [ ( n , l ) ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT result = 0 NEW_LINE for m in xrange ( 1 , l ) : NEW_LINE INDENT bucket = ( n - 1 ) - ( l + 1 ) + 1 NEW_LINE pick = ( l - 1 ) - ( m + 1 ) + 1 NEW_LINE if bucket >= pick : NEW_LINE INDENT result += D [ ( l , m ) ] * combtable [ ( n - l - 1 , l - m - 1 ) ] NEW_LINE DEDENT DEDENT D [ ( n , l ) ] = result % modulo NEW_LINE DEDENT DEDENT DEDENT file ( ' cached ' , ' wb ' ) . write ( pickle . dumps ( D ) ) NEW_LINE DEDENT c = raw_input ( ) NEW_LINE for cs in xrange ( 1 , int ( c ) + 1 ) : NEW_LINE INDENT n = int ( raw_input ( ) ) NEW_LINE result = 0 NEW_LINE for l in xrange ( 1 , n ) : NEW_LINE INDENT result += D [ ( n , l ) ] NEW_LINE DEDENT print " Case ▁ # % d : ▁ % d " % ( cs , result % modulo ) NEW_LINE DEDENT

import fileinput NEW_LINE memo = { } NEW_LINE def f ( n , m ) : NEW_LINE INDENT if n < 0 : return 0 NEW_LINE if n == 0 : return 1 NEW_LINE if n in memo and m in memo [ n ] : return memo [ n ] [ m ] NEW_LINE s = 0 NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT s += f ( n - i , m ) NEW_LINE DEDENT if n not in memo : memo [ n ] = { } NEW_LINE memo [ n ] [ m ] = s NEW_LINE return s NEW_LINE DEDENT def a079500 ( n ) : NEW_LINE INDENT s = 0 NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT s += f ( i , n - i ) NEW_LINE DEDENT return s NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT reader = fileinput . input ( ) NEW_LINE trials = int ( reader . next ( ) ) NEW_LINE for t in range ( 1 , trials + 1 ) : NEW_LINE INDENT result = trial ( reader ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( t , result ) NEW_LINE DEDENT DEDENT def trial ( reader ) : NEW_LINE INDENT n = int ( reader . next ( ) ) NEW_LINE return a079500 ( n - 1 ) % 100003 NEW_LINE DEDENT main ( ) NEW_LINE

import sys NEW_LINE def line ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) [ : - 1 ] NEW_LINE DEDENT def readList ( ) : NEW_LINE INDENT return map ( eval , line ( ) . split ( ) ) NEW_LINE DEDENT modulo = 100003 NEW_LINE chooses = dict ( ) NEW_LINE def choose ( n , m ) : NEW_LINE INDENT if ( n , m ) not in chooses : NEW_LINE INDENT if ( n < m ) : NEW_LINE INDENT chooses [ ( n , m ) ] = 0 NEW_LINE DEDENT else : NEW_LINE INDENT chooses [ ( n , m ) ] = ( factorial ( n ) / ( factorial ( n - m ) * factorial ( m ) ) ) % modulo NEW_LINE DEDENT DEDENT return chooses [ ( n , m ) ] NEW_LINE DEDENT factorials = dict ( ) NEW_LINE factorials [ 1 ] = 1 NEW_LINE factorials [ 0 ] = 1 NEW_LINE def factorial ( n ) : NEW_LINE INDENT if n not in factorials : NEW_LINE INDENT i = n NEW_LINE factorials [ n ] = 1 NEW_LINE while i >= 2 : NEW_LINE INDENT factorials [ n ] *= i NEW_LINE i -= 1 NEW_LINE DEDENT DEDENT return factorials [ n ] NEW_LINE DEDENT def buildTable ( N ) : NEW_LINE INDENT table = dict ( ) NEW_LINE for n in range ( 2 , N + 1 ) : NEW_LINE INDENT table [ ( n , 1 ) ] = 1 NEW_LINE for pos in range ( 2 , n ) : NEW_LINE INDENT table [ ( n , pos ) ] = sum ( [ table [ ( pos , i ) ] * choose ( n - pos - 1 , pos - i - 1 ) % modulo for i in range ( 1 , pos ) ] ) % modulo NEW_LINE DEDENT DEDENT return table NEW_LINE DEDENT def ways ( n , table ) : NEW_LINE INDENT return sum ( [ table [ n , pos ] for pos in range ( 1 , n ) ] ) % modulo NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT numberOfCases = eval ( line ( ) ) NEW_LINE table = buildTable ( 500 ) NEW_LINE for caseNumber in range ( numberOfCases ) : NEW_LINE INDENT n = eval ( line ( ) ) NEW_LINE answer = ways ( n , table ) NEW_LINE print " Case ▁ # " + str ( caseNumber + 1 ) + " : ▁ " + str ( answer % 100003 ) NEW_LINE DEDENT DEDENT

def doit ( i , j ) : NEW_LINE INDENT if i == 0 or j == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if j == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if j >= i : NEW_LINE INDENT return 0 NEW_LINE DEDENT aux = 0 NEW_LINE for x in xrange ( 1 , j ) : NEW_LINE INDENT aux += A [ j ] [ x ] * C [ i - j - 1 ] [ j - x - 1 ] NEW_LINE aux %= MOD NEW_LINE DEDENT return aux NEW_LINE DEDENT def comb ( i , j ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT if j > i : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) % MOD NEW_LINE DEDENT f = open ( ' c . in ' , ' r ' ) NEW_LINE MOD = 100003 NEW_LINE nmax = 512 NEW_LINE A = [ [ 0 ] * nmax for i in range ( nmax ) ] NEW_LINE C = [ [ 0 ] * nmax for i in range ( nmax ) ] NEW_LINE for i in range ( 0 , nmax ) : NEW_LINE INDENT for j in range ( 0 , nmax ) : NEW_LINE INDENT C [ i ] [ j ] = comb ( i , j ) NEW_LINE A [ i ] [ j ] = doit ( i , j ) NEW_LINE DEDENT DEDENT T = int ( f . readline ( ) ) NEW_LINE for t_no in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( f . readline ( ) ) NEW_LINE sol = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT sol += A [ N ] [ i ] NEW_LINE sol %= MOD NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( t_no , sol ) NEW_LINE DEDENT


package gcj2009 . qual ; import java . io . * ; import java . util . * ; import static java . lang . Math . * ; public class A { static final int INF = 1 << 20 ; static char [ ] [ ] css ; public void run ( ) { char [ ] key = sc . next ( ) . toCharArray ( ) ; boolean [ ] [ ] b = new boolean [ L ] [ 127 ] ; for ( int i = 0 , j = 0 ; i < key . length ; i ++ , j ++ ) if ( key [ i ] == ' ( ' ) while ( key [ ++ i ] != ' ) ' ) b [ j ] [ key [ i ] ] = true ; else b [ j ] [ key [ i ] ] = true ; int ans = 0 ; loop : for ( char [ ] cs : css ) { for ( int i = 0 ; i < L ; i ++ ) if ( ! b [ i ] [ cs [ i ] ] ) continue loop ; ans ++ ; } System . out . println ( ans ) ; } public static void main ( String ... args ) { try { System . setIn ( new FileInputStream ( " A - large . in " ) ) ; System . setOut ( new PrintStream ( " A - large . out " ) ) ; } catch ( Exception e ) { } sc = new Scanner ( System . in ) ; L = sc . nextInt ( ) ; D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; css = new char [ D ] [ ] ; for ( int i = 0 ; i < D ; i ++ ) css [ i ] = sc . next ( ) . toCharArray ( ) ; for ( int n = 1 ; n <= N ; n ++ ) { System . out . printf ( " Case ▁ # % d : ▁ " , n ) ; new A ( ) . run ( ) ; } } static int L , D ; static Scanner sc ; }

package de . measite . gcj ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . LineNumberReader ; import java . util . regex . Pattern ; public class Main1 { public static void main ( String [ ] args ) { try { LineNumberReader lnr = new LineNumberReader ( new InputStreamReader ( System . in ) ) ; String line [ ] = lnr . readLine ( ) . trim ( ) . split ( " ▁ " ) ; final int d = Integer . parseInt ( line [ 1 ] ) ; final int n = Integer . parseInt ( line [ 2 ] ) ; String word [ ] = new String [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { word [ i ] = lnr . readLine ( ) . trim ( ) ; } for ( int i = 1 ; i <= n ; i ++ ) { String m = lnr . readLine ( ) . trim ( ) . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) ; Pattern pattern = Pattern . compile ( m ) ; int count = 0 ; for ( String w : word ) { if ( pattern . matcher ( w ) . matches ( ) ) { count ++ ; } } System . out . println ( " Case ▁ # " + i + " : ▁ " + count ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } }

import java . io . * ; import java . util . * ; public class Solution { public static BufferedReader cin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static StringTokenizer tok = null ; public static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( cin . readLine ( ) ) ; } return tok . nextToken ( ) ; } public static int nextInt ( ) throws NumberFormatException , IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws NumberFormatException , IOException { int L = nextInt ( ) ; int D = nextInt ( ) ; int N = nextInt ( ) ; String [ ] dict = new String [ D ] ; for ( int i = 0 ; i < D ; i ++ ) dict [ i ] = cin . readLine ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String pat = cin . readLine ( ) ; TreeSet [ ] st = new TreeSet [ L ] ; for ( int j = 0 ; j < L ; j ++ ) { st [ j ] = new TreeSet ( ) ; } int k = 0 ; for ( int j = 0 ; j < pat . length ( ) ; j ++ ) { if ( pat . charAt ( j ) != ' ( ' ) { st [ k ] . add ( Character . valueOf ( pat . charAt ( j ) ) ) ; k ++ ; } else { j ++ ; while ( pat . charAt ( j ) != ' ) ' ) { st [ k ] . add ( Character . valueOf ( pat . charAt ( j ) ) ) ; j ++ ; } k ++ ; } } int ans = 0 ; for ( int j = 0 ; j < D ; j ++ ) { boolean ok = true ; for ( int t = 0 ; t < L ; t ++ ) { if ( ! st [ t ] . contains ( Character . valueOf ( dict [ j ] . charAt ( t ) ) ) ) { ok = false ; break ; } } if ( ok ) ans ++ ; } System . out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + ans ) ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Set ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader buffer = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String entrada = buffer . readLine ( ) ; String ns [ ] = entrada . split ( " ▁ " ) ; int l = Integer . parseInt ( ns [ 0 ] ) ; int d = Integer . parseInt ( ns [ 1 ] ) ; int n = Integer . parseInt ( ns [ 2 ] ) ; String palavras [ ] = new String [ d + 1 ] ; for ( int i = 0 ; i < d ; i ++ ) { palavras [ i ] = buffer . readLine ( ) ; } for ( int k = 1 ; k <= n ; k ++ ) { List < Set < Character > > conjuntosAceitaveis = new ArrayList < Set < Character > > ( ) ; for ( int i = 0 ; i < l ; i ++ ) { conjuntosAceitaveis . add ( new HashSet < Character > ( ) ) ; } String expressao = buffer . readLine ( ) ; int pt = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( expressao . charAt ( pt ) == ' ( ' ) { for ( pt ++ ; expressao . charAt ( pt ) != ' ) ' ; pt ++ ) { conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ; } pt ++ ; } else { conjuntosAceitaveis . get ( i ) . add ( expressao . charAt ( pt ) ) ; pt ++ ; } } int cont = 0 ; for ( int i = 0 ; i < d ; i ++ ) { boolean pode = true ; for ( int j = 0 ; j < l ; j ++ ) { if ( ! conjuntosAceitaveis . get ( j ) . contains ( palavras [ i ] . charAt ( j ) ) ) { pode = false ; break ; } } if ( pode ) cont ++ ; } System . out . println ( " Case ▁ # " + k + " : ▁ " + cont ) ; } } }

package gcj2009 . qualification ; import java . io . File ; import java . io . PrintWriter ; import java . text . SimpleDateFormat ; import java . util . Date ; import java . util . Scanner ; import java . util . regex . Pattern ; public class A_Alien_Language { private static boolean SMALL = false ; private static String PROBLEM = " A " ; public static void main ( String [ ] args ) { try { Scanner scan = new Scanner ( new File ( String . format ( " % s - % s . in " , PROBLEM , ( SMALL ? " small " : " large " ) ) ) ) ; PrintWriter pw = new PrintWriter ( new File ( String . format ( " % s - % s . out " , PROBLEM , ( SMALL ? " small " : " large " ) ) ) ) ; int L = scan . nextInt ( ) , D = scan . nextInt ( ) , N = scan . nextInt ( ) ; scan . nextLine ( ) ; String [ ] dictionary = new String [ D ] ; for ( int i = 0 ; i < D ; ++ i ) dictionary [ i ] = scan . nextLine ( ) ; System . out . println ( String . format ( " % d ▁ test ▁ cases : " , N ) ) ; long start = System . currentTimeMillis ( ) , t1 , left ; for ( int CASE = 1 ; CASE <= N ; ++ CASE ) { t1 = System . currentTimeMillis ( ) ; System . out . print ( String . format ( " % d . [ % s ] ▁ " , CASE , new SimpleDateFormat ( " HH : mm : ss . SSS " ) . format ( new Date ( t1 ) ) ) ) ; String pattern = scan . nextLine ( ) ; pattern = pattern . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) ; Pattern p = Pattern . compile ( pattern ) ; int cnt = 0 ; for ( int i = 0 ; i < D ; ++ i ) if ( p . matcher ( dictionary [ i ] ) . matches ( ) ) cnt ++ ; String res = String . valueOf ( cnt ) ; pw . println ( String . format ( " Case ▁ # % d : ▁ % s " , CASE , res ) ) ; left = ( System . currentTimeMillis ( ) - start ) * ( N - CASE ) / CASE ; System . out . println ( String . format ( " % s ▁ ( % dms , ▁ ~ % dms ▁ left ) " , res , ( System . currentTimeMillis ( ) - t1 ) , left ) ) ; } pw . close ( ) ; scan . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }

import re NEW_LINE import sys NEW_LINE r = re . compile ( r ' ( \ ( [ a - z ] * \ ) | [ a - z ] ) ' ) NEW_LINE def main ( ) : NEW_LINE INDENT [ l , d , n ] = [ int ( x ) for x in raw_input ( ) . strip ( ) . split ( ) ] NEW_LINE words = [ ] NEW_LINE for _ in range ( d ) : NEW_LINE INDENT words . append ( raw_input ( ) . strip ( ) ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT q = raw_input ( ) . strip ( ) NEW_LINE q = [ c for c in r . split ( q ) if c ] NEW_LINE w = words NEW_LINE for qq in q : NEW_LINE INDENT w = [ x [ 1 : ] for x in w if x [ 0 ] in qq ] NEW_LINE DEDENT sys . stdout . write ( " Case ▁ # % d : ▁ % d \n " % ( i + 1 , len ( w ) ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

from __future__ import division NEW_LINE import sys NEW_LINE import itertools NEW_LINE def parse_pattern ( pattern ) : NEW_LINE INDENT res = [ ] NEW_LINE while pattern : NEW_LINE INDENT if pattern [ 0 ] == ' ( ' : NEW_LINE INDENT i = pattern . find ( ' ) ' ) NEW_LINE res . append ( set ( pattern [ 1 : i ] ) ) NEW_LINE pattern = pattern [ i + 1 : ] NEW_LINE DEDENT else : NEW_LINE INDENT res . append ( set ( pattern [ 0 ] ) ) NEW_LINE pattern = pattern [ 1 : ] NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def matches_pattern ( pattern , word ) : NEW_LINE INDENT for p , w in itertools . izip ( pattern , word ) : NEW_LINE INDENT if w not in p : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def solve ( pattern , words ) : NEW_LINE INDENT p = parse_pattern ( pattern ) NEW_LINE res = 0 NEW_LINE for w in words : NEW_LINE INDENT if matches_pattern ( p , w ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def go ( ) : NEW_LINE INDENT l , d , n = [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE words = [ ] NEW_LINE for i in xrange ( d ) : NEW_LINE INDENT word = sys . stdin . readline ( ) . strip ( ) NEW_LINE words . append ( word ) NEW_LINE DEDENT for i in xrange ( n ) : NEW_LINE INDENT pattern = sys . stdin . readline ( ) . strip ( ) NEW_LINE print ' Case ▁ # % d : ▁ % d ' % ( i + 1 , solve ( pattern , words ) ) NEW_LINE DEDENT DEDENT go ( ) NEW_LINE

from StringIO import StringIO NEW_LINE import re NEW_LINE def process ( f , out = None ) : NEW_LINE INDENT if isinstance ( f , str ) : NEW_LINE INDENT if not out : NEW_LINE INDENT out = open ( f + ' . out . txt ' , ' wb ' ) NEW_LINE DEDENT f = open ( f , ' rb ' ) NEW_LINE DEDENT else : NEW_LINE INDENT if not out : NEW_LINE INDENT out = StringIO ( ) NEW_LINE DEDENT DEDENT l , d , n = map ( int , f . readline ( ) . strip ( ) . split ( ) ) NEW_LINE words = [ ] NEW_LINE for i in range ( d ) : NEW_LINE INDENT words . append ( f . readline ( ) . strip ( ) ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT pattern = f . readline ( ) . strip ( ) NEW_LINE pattern = pattern . replace ( ' ( ' , ' [ ' ) . replace ( ' ) ' , ' ] ' ) NEW_LINE expr = re . compile ( ' ^ ' + pattern + ' $ ' ) NEW_LINE count = len ( filter ( lambda x : expr . match ( x ) , words ) ) NEW_LINE out . write ( ' Case ▁ # % d : ▁ % s \n ' % ( i + 1 , count ) ) NEW_LINE DEDENT if isinstance ( out , StringIO ) : NEW_LINE INDENT return out . getvalue ( ) NEW_LINE DEDENT DEDENT TEST_DATA = ( """ 3 ▁ 5 ▁ 4 STRNEWLINE abc STRNEWLINE bca STRNEWLINE dac STRNEWLINE dbc STRNEWLINE cba STRNEWLINE ( ab ) ( bc ) ( ca ) STRNEWLINE abc STRNEWLINE ( abc ) ( abc ) ( abc ) STRNEWLINE ( zyx ) bc """ , """ Case ▁ # 1 : ▁ 2 STRNEWLINE Case ▁ # 2 : ▁ 1 STRNEWLINE Case ▁ # 3 : ▁ 3 STRNEWLINE Case ▁ # 4 : ▁ 0 STRNEWLINE """ ) NEW_LINE def go ( ) : NEW_LINE INDENT assert process ( StringIO ( TEST_DATA [ 0 ] ) ) == TEST_DATA [ 1 ] NEW_LINE for x in [ ' A - large . in . txt ' ] : NEW_LINE INDENT process ( x ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT go ( ) NEW_LINE DEDENT

import sys , string NEW_LINE from subprocess import Popen , PIPE NEW_LINE input = sys . stdin . readlines ( ) NEW_LINE specs = [ int ( num ) for num in input [ 0 ] . split ( ) ] NEW_LINE L = specs [ 0 ] NEW_LINE D = specs [ 1 ] NEW_LINE N = specs [ 2 ] NEW_LINE words = input [ 1 : 1 + D ] NEW_LINE table = string . maketrans ( ' ( ) ' , ' [ ] ' ) NEW_LINE case = 1 NEW_LINE for exp in input [ 1 + D : ] : NEW_LINE INDENT exp = ' ^ ' + exp . strip ( ) . translate ( table ) + ' $ ' NEW_LINE cmd = " grep ▁ ' % s ' " % exp NEW_LINE p = Popen ( cmd , shell = True , bufsize = 4096 , stdin = PIPE , stdout = PIPE , close_fds = True ) NEW_LINE ( child_stdin , child_stdout ) = ( p . stdin , p . stdout ) NEW_LINE for word in words : NEW_LINE INDENT print >> child_stdin , word NEW_LINE DEDENT child_stdin . close ( ) NEW_LINE count = 0 NEW_LINE for line in child_stdout : NEW_LINE INDENT count += 1 NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , count ) NEW_LINE child_stdout . close ( ) NEW_LINE case += 1 NEW_LINE DEDENT

import os , sys NEW_LINE def processCase ( caseStr , letterData , wordlength ) : NEW_LINE INDENT casePos = 0 NEW_LINE allowedWords = set ( ) NEW_LINE for letterPos in range ( wordlength ) : NEW_LINE INDENT allowedLetters = [ ] NEW_LINE if caseStr [ casePos ] == ' ( ' : NEW_LINE INDENT casePos += 1 NEW_LINE while ( caseStr [ casePos ] != ' ) ' ) : NEW_LINE INDENT allowedLetters . append ( caseStr [ casePos ] ) NEW_LINE casePos += 1 NEW_LINE DEDENT casePos += 1 NEW_LINE DEDENT else : NEW_LINE INDENT allowedLetters . append ( caseStr [ casePos ] ) NEW_LINE casePos += 1 NEW_LINE DEDENT tempWords = set ( ) NEW_LINE for l in allowedLetters : NEW_LINE INDENT if l in letterData [ letterPos ] : NEW_LINE INDENT tempWords . update ( letterData [ letterPos ] [ l ] ) NEW_LINE DEDENT DEDENT if letterPos == 0 : NEW_LINE INDENT allowedWords = tempWords NEW_LINE DEDENT else : NEW_LINE INDENT allowedWords . intersection_update ( tempWords ) NEW_LINE DEDENT DEDENT return len ( allowedWords ) NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE words = [ ] NEW_LINE [ wordlength , numdict , numcases ] = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE letterPosToWords = [ { } for x in range ( wordlength ) ] NEW_LINE index += 1 NEW_LINE for i in range ( numdict ) : NEW_LINE INDENT word = fileLines [ index ] [ : - 1 ] NEW_LINE index += 1 NEW_LINE for j in range ( wordlength ) : NEW_LINE INDENT c = word [ j ] NEW_LINE if ( not ( c in letterPosToWords [ j ] ) ) : NEW_LINE INDENT letterPosToWords [ j ] [ c ] = set ( ) NEW_LINE DEDENT letterPosToWords [ j ] [ c ] . add ( word ) NEW_LINE DEDENT words . append ( word ) NEW_LINE DEDENT for i in range ( numcases ) : NEW_LINE INDENT case = fileLines [ index ] [ : - 1 ] NEW_LINE index += 1 NEW_LINE numWords = processCase ( case , letterPosToWords , wordlength ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( i + 1 , numWords ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; import java . math . * ; public class Problem3 { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( " Problem3 . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( " Problem3 . out " ) ) ) ; int c = in . nextInt ( ) ; for ( int cn = 0 ; cn < c ; cn ++ ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; long x = in . nextInt ( ) ; long y = in . nextInt ( ) ; long z = in . nextInt ( ) ; long sub [ ] = new long [ n ] ; BigInteger ans [ ] = new BigInteger [ n ] ; long array [ ] = new long [ m ] ; for ( int i = 0 ; i < m ; i ++ ) array [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sub [ i ] = array [ i % m ] ; array [ i % m ] = ( x * array [ i % m ] + y * ( i + 1 ) ) % z ; } Arrays . fill ( ans , BigInteger . ONE ) ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) { if ( sub [ j ] < sub [ i ] ) ans [ i ] = ans [ i ] . add ( ans [ j ] ) ; } BigInteger sum = BigInteger . ZERO ; for ( int i = 0 ; i < n ; i ++ ) sum = sum . add ( ans [ i ] ) ; sum = sum . remainder ( new BigInteger ( "1000000007" ) ) ; out . write ( " Case ▁ # " + ( cn + 1 ) + " : ▁ " + sum . toString ( ) + " \n " ) ; } in . close ( ) ; out . close ( ) ; } }

package Andra ; import java . util . * ; public class CumulativeTable { public static final long MOD = 1000000007 ; private long [ ] sum ; private int [ ] degreeTwo ; private int n ; public CumulativeTable ( int n ) { this . n = n ; this . sum = new long [ n + 1 ] ; this . degreeTwo = new int [ n + 1 ] ; calculateDegrees ( ) ; } private void calculateDegrees ( ) { degreeTwo [ 0 ] = 1 ; degreeTwo [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { if ( ( i & 1 ) == 0 ) degreeTwo [ i ] = degreeTwo [ i >> 1 ] * 2 ; else degreeTwo [ i ] = 1 ; } } public void reset ( ) { for ( int i = 0 ; i < n ; i ++ ) sum [ i ] = 0 ; } public void add ( int index , long value ) { int i = index ; while ( i <= n ) { sum [ i ] = ( sum [ i ] + value ) % MOD ; i = i + degreeTwo [ i ] ; } } public long count ( int index ) { int i = index ; long toReturn = 0 ; while ( i >= 0 ) { toReturn = ( toReturn + sum [ i ] ) % MOD ; i = i - degreeTwo [ i ] ; } return toReturn ; } public static void main ( String [ ] args ) { Random rnd = new Random ( ) ; int n = 100 ; int [ ] a = new int [ n ] ; CumulativeTable ct = new CumulativeTable ( n ) ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { int index = rnd . nextInt ( n ) ; int value = rnd . nextInt ( 1000 ) ; a [ index ] = a [ index ] + value ; ct . add ( index , value ) ; int sum = 0 ; for ( int j = 0 ; j <= index ; j ++ ) sum += a [ j ] ; System . out . println ( sum ) ; System . out . println ( ct . count ( index ) ) ; } } }

package codejam2c ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( " c - small . in " ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( " c - small - out . out " ) ) ; final long M = 1000000007 ; int T = in . nextInt ( ) ; for ( int x = 1 ; x <= T ; x ++ ) { int n = in . nextInt ( ) , m = in . nextInt ( ) , X = in . nextInt ( ) , Y = in . nextInt ( ) , Z = in . nextInt ( ) ; int i , j ; int [ ] a = new int [ n ] , A = new int [ m ] ; long [ ] nr = new long [ n ] ; long S = 0 ; for ( i = 0 ; i < m ; i ++ ) { A [ i ] = in . nextInt ( ) ; } for ( i = 0 ; i < n ; i ++ ) { a [ i ] = A [ i % m ] ; A [ i % m ] = ( int ) ( ( ( long ) ( ( long ) X * A [ i % m ] + ( long ) Y * ( i + 1 ) ) ) % ( long ) Z ) ; } nr [ 0 ] = 1 ; S = 1 ; for ( i = 1 ; i < n ; i ++ ) { nr [ i ] = 1 ; for ( j = 0 ; j < i ; j ++ ) if ( a [ j ] < a [ i ] ) { nr [ i ] += nr [ j ] ; nr [ i ] %= M ; } S += nr [ i ] ; S %= M ; } out . printf ( " Case ▁ # % d : ▁ % d % n " , x , S ) ; } in . close ( ) ; out . close ( ) ; } }

import java . util . Scanner ; public class ProblemC { public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final int cases = sc . nextInt ( ) ; for ( int cc = 1 ; cc <= cases ; cc ++ ) { final int n = sc . nextInt ( ) ; final int m = sc . nextInt ( ) ; final long x = sc . nextLong ( ) , y = sc . nextLong ( ) , z = sc . nextLong ( ) ; final int [ ] h = new int [ n ] ; final int [ ] a = new int [ n ] ; for ( int i = 0 ; i < m ; i ++ ) h [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = h [ i % m ] ; h [ i % m ] = ( int ) ( ( x * h [ i % m ] + y * ( i + 1 ) ) % z ) ; } final int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = 1 ; for ( int j = 0 ; j < i ; j ++ ) if ( a [ j ] < a [ i ] ) s [ i ] = ( s [ i ] + s [ j ] ) % 1000000007 ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) count = ( count + s [ i ] ) % 1000000007 ; System . out . printf ( " Case ▁ # % s : ▁ % s \n " , cc , count ) ; } System . out . flush ( ) ; } }

import java . io . * ; import java . util . * ; public class Main { Scanner in ; PrintWriter out ; String IFILE = " c - small - attempt0 . in " ; String OFILE = " c - small - attempt0 . out " ; final long MOD = 1000000007 ; public void run ( ) throws IOException { in = new Scanner ( new File ( IFILE ) ) ; out = new PrintWriter ( OFILE ) ; int nt = in . nextInt ( ) ; for ( int it = 0 ; it < nt ; it ++ ) { int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; long x = in . nextInt ( ) ; long y = in . nextInt ( ) ; long z = in . nextInt ( ) ; long [ ] a = new long [ m ] ; for ( int i = 0 ; i < m ; i ++ ) a [ i ] = in . nextLong ( ) ; long [ ] mas = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { mas [ i ] = a [ i % m ] ; a [ i % m ] = ( x * a [ i % m ] + y * ( i + 1 ) ) % z ; } long [ ] f = new long [ n ] ; Arrays . fill ( f , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( mas [ j ] < mas [ i ] ) f [ i ] = ( f [ i ] + f [ j ] ) % MOD ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans = ( ans + f [ i ] ) % MOD ; out . println ( " Case ▁ # " + ( it + 1 ) + " : ▁ " + ans ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } }

import sys NEW_LINE def genseq ( n , m , X , Y , Z , A ) : NEW_LINE INDENT s = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT s . append ( A [ i % m ] ) NEW_LINE A [ i % m ] = ( X * A [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT return s NEW_LINE DEDENT def go_seq ( seq ) : NEW_LINE INDENT s = [ 0 for x in range ( len ( seq ) ) ] NEW_LINE for i in range ( len ( seq ) ) : NEW_LINE INDENT s [ i ] = 1 NEW_LINE for j in range ( i ) : NEW_LINE INDENT if seq [ i ] > seq [ j ] : NEW_LINE INDENT s [ i ] += s [ j ] NEW_LINE DEDENT DEDENT DEDENT return sum ( s ) NEW_LINE DEDENT def go ( name ) : NEW_LINE INDENT f = file ( name ) NEW_LINE line = f . readline ( ) . strip ( ) NEW_LINE total = int ( line ) NEW_LINE for i in range ( total ) : NEW_LINE INDENT n , m , X , Y , Z = [ int ( x ) for x in f . readline ( ) . strip ( ) . split ( ) ] NEW_LINE A = [ ] NEW_LINE for j in range ( m ) : NEW_LINE INDENT A . append ( int ( f . readline ( ) . strip ( ) ) ) NEW_LINE DEDENT seq = genseq ( n , m , X , Y , Z , A ) NEW_LINE r = go_seq ( seq ) % 1000000007 NEW_LINE print " Case ▁ # % d : ▁ % d " % ( i + 1 , r ) NEW_LINE DEDENT f . close ( ) NEW_LINE DEDENT try : NEW_LINE INDENT fn = sys . argv [ 1 ] NEW_LINE DEDENT except : NEW_LINE INDENT print " Usage : \n " , " python " , sys . argv [ 0 ] + " ▁ input _ file _ name " NEW_LINE sys . exit ( 1 ) NEW_LINE DEDENT go ( fn ) NEW_LINE

import os NEW_LINE import sys NEW_LINE sys . stdin = open ( ' C - small - attempt0 . in ' , ' r ' ) NEW_LINE sys . stdout = open ( ' C - small - attempt0 . out ' , ' w ' ) NEW_LINE DEBUG = 1 or os . getenv ( " DEBUG " ) == '1' NEW_LINE if DEBUG : NEW_LINE INDENT sys . stderr = open ( ' log ' , ' w ' ) NEW_LINE DEDENT def debug ( * what ) : NEW_LINE INDENT if DEBUG : NEW_LINE INDENT sys . stderr . write ( " [ DEBUG ] ▁ " + " ▁ " . join ( map ( str , what ) ) + " \n " ) NEW_LINE DEDENT DEDENT L = 1000000007 NEW_LINE for case in xrange ( input ( ) ) : NEW_LINE INDENT debug ( ) NEW_LINE debug ( " Case ▁ # % d : " % ( case + 1 ) ) NEW_LINE n , m , X , Y , Z = map ( int , raw_input ( ) . split ( ) ) NEW_LINE A = [ ] NEW_LINE for i in xrange ( m ) : NEW_LINE INDENT A . append ( input ( ) ) NEW_LINE DEDENT debug ( ' n ▁ m ▁ X ▁ Y ▁ Z ' , n , m , X , Y , Z , ' A ' , A ) NEW_LINE S = [ ] NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT S . append ( A [ i % m ] ) NEW_LINE A [ i % m ] = ( X * A [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT debug ( ' S ' , S ) NEW_LINE c = [ 1 ] * n NEW_LINE r = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT debug ( ' i ' , i ) NEW_LINE for j in xrange ( i ) : NEW_LINE INDENT if S [ j ] < S [ i ] : NEW_LINE INDENT c [ i ] += c [ j ] ; c [ i ] %= L NEW_LINE DEDENT DEDENT r += c [ i ] ; r %= L NEW_LINE debug ( ' c ' , c ) NEW_LINE debug ( ' r ' , r ) NEW_LINE DEDENT print " Case ▁ # % d : ▁ % d " % ( case + 1 , r ) NEW_LINE DEDENT

import sys NEW_LINE import math NEW_LINE input = open ( sys . argv [ 1 ] , " r " ) NEW_LINE output = open ( " speed . out " , " w " ) NEW_LINE caseN = 0 NEW_LINE case = 0 NEW_LINE n = 0 NEW_LINE m = 0 NEW_LINE X = 0 NEW_LINE Y = 0 NEW_LINE Z = 0 NEW_LINE acc = 0 NEW_LINE A = [ ] NEW_LINE B = [ ] NEW_LINE C = [ ] NEW_LINE MODNUM = 1000000007 NEW_LINE for line in input : NEW_LINE INDENT if caseN == 0 : NEW_LINE INDENT caseN = int ( line ) NEW_LINE continue NEW_LINE DEDENT elif n == 0 : NEW_LINE INDENT intLine = map ( int , line . split ( ' ▁ ' ) ) NEW_LINE n = intLine [ 0 ] NEW_LINE m = intLine [ 1 ] NEW_LINE X = intLine [ 2 ] NEW_LINE Y = intLine [ 3 ] NEW_LINE Z = intLine [ 4 ] NEW_LINE acc = m - 1 NEW_LINE DEDENT elif acc > 0 : NEW_LINE INDENT acc -= 1 NEW_LINE A += [ int ( line ) ] NEW_LINE DEDENT else : NEW_LINE INDENT A += [ int ( line ) ] NEW_LINE ans = 0 NEW_LINE B = [ 0 for x in range ( n ) ] NEW_LINE C = [ 0 for x in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT B [ i ] = int ( A [ i % m ] ) NEW_LINE A [ i % m ] = ( X * A [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT loopNums = range ( n ) NEW_LINE loopNums . reverse ( ) NEW_LINE for i in loopNums : NEW_LINE INDENT seqNum = 1 NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT if B [ j ] > B [ i ] : NEW_LINE INDENT seqNum += C [ j ] NEW_LINE seqNum %= MODNUM NEW_LINE DEDENT DEDENT C [ i ] = seqNum NEW_LINE C [ i ] %= MODNUM NEW_LINE ans += seqNum NEW_LINE ans %= MODNUM NEW_LINE DEDENT case += 1 NEW_LINE output . write ( " Case ▁ # " + str ( case ) + " : ▁ " + str ( ans ) + " \n " ) NEW_LINE n = 0 NEW_LINE A = [ ] NEW_LINE DEDENT DEDENT input . close ( ) NEW_LINE output . close ( ) NEW_LINE

fd = open ( " input . in " ) NEW_LINE num_cases = int ( fd . readline ( ) ) NEW_LINE for i in range ( 0 , num_cases ) : NEW_LINE INDENT ( n , m , X , Y , Z ) = [ int ( item ) for item in fd . readline ( ) . split ( " ▁ " ) ] NEW_LINE A = [ 0 ] * n NEW_LINE for j in range ( 0 , m ) : NEW_LINE INDENT A [ j ] = int ( fd . readline ( ) ) NEW_LINE DEDENT speeds = [ ] NEW_LINE for j in range ( 0 , n ) : NEW_LINE INDENT speeds . append ( A [ j % m ] ) NEW_LINE A [ j % m ] = ( X * A [ j % m ] + Y * ( j + 1 ) ) % Z NEW_LINE DEDENT num_sets = [ 1 ] * len ( speeds ) NEW_LINE for j in range ( len ( speeds ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT for k in range ( j + 1 , len ( speeds ) ) : NEW_LINE INDENT if speeds [ k ] > speeds [ j ] : NEW_LINE INDENT num_sets [ j ] += num_sets [ k ] NEW_LINE DEDENT DEDENT DEDENT tot_sets = 0 NEW_LINE for j in range ( 0 , len ( speeds ) ) : NEW_LINE INDENT tot_sets += num_sets [ j ] NEW_LINE DEDENT print " Case ▁ # % d : " % ( i + 1 ) , tot_sets % 1000000007 NEW_LINE DEDENT

import sys NEW_LINE FILE_NAME = ' C - small - attempt0' NEW_LINE INPUT_FILE = FILE_NAME + ' . in ' NEW_LINE OUTPUT_FILE = FILE_NAME + ' . out ' NEW_LINE def process ( case , n , m , X , Y , Z , B ) : NEW_LINE INDENT A = [ 0 ] * n NEW_LINE S = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT A [ i ] = int ( B [ i % m ] ) NEW_LINE B [ i % m ] = ( X * B [ i % m ] + Y * ( i + 1 ) ) % Z NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT S [ i ] = 1 NEW_LINE for j in range ( i ) : NEW_LINE INDENT if A [ j ] < A [ i ] : NEW_LINE INDENT S [ i ] = S [ i ] + S [ j ] NEW_LINE DEDENT DEDENT DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , sum ( S ) % 1000000007 ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT fp_in = open ( INPUT_FILE , ' r ' ) NEW_LINE fp_out = open ( OUTPUT_FILE , ' w ' ) NEW_LINE sys . stdin = fp_in NEW_LINE sys . stdout = fp_out NEW_LINE num_cases = int ( input ( ) ) NEW_LINE for case in range ( 1 , num_cases + 1 ) : NEW_LINE INDENT n , m , X , Y , Z = map ( int , raw_input ( ) . split ( ) ) NEW_LINE B = [ 0 ] * m NEW_LINE for i in range ( m ) : NEW_LINE INDENT B [ i ] = input ( ) NEW_LINE DEDENT process ( case , n , m , X , Y , Z , B ) NEW_LINE DEDENT fp_in . close ( ) NEW_LINE fp_out . close ( ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . util . Arrays ; import java . util . Scanner ; public class ProblemC { public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { int cases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= cases ; caseNum ++ ) { solve ( sc , caseNum ) ; } } } static void solve ( Scanner sc , int caseNum ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; double U = sc . nextDouble ( ) ; double [ ] P = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = sc . nextDouble ( ) ; } Arrays . sort ( P ) ; double eps = 1e-8 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { double add = P [ i + 1 ] - P [ i ] ; if ( add * ( i + 1 ) > U + eps ) { for ( int j = 0 ; j <= i ; j ++ ) { P [ j ] += U / ( i + 1 ) ; } U = 0 ; break ; } else { for ( int j = 0 ; j <= i ; j ++ ) { P [ j ] += add ; } U -= add * ( i + 1 ) ; } } if ( U > 0 ) { for ( int j = 0 ; j < N ; j ++ ) { P [ j ] += U / N ; } } double res = 1 ; for ( int j = 0 ; j < N ; j ++ ) { res *= P [ j ] ; } System . out . printf ( " Case ▁ # % d : ▁ % .8f \n " , caseNum , res ) ; } }

package round1c ; import java . util . Arrays ; public class ProbC extends Prob { void setup ( ) { bin = true ; bout = true ; in = " C - small - 1 - attempt0 . in " ; out = " cout . txt " ; } @ Override public void main ( ) { setup ( ) ; reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { double ans = run ( ) ; System . out . println ( String . format ( " Case ▁ # % d : ▁ % f " , cas , ans ) ) ; } } double run ( ) { int n = scanner . nextInt ( ) ; int k = scanner . nextInt ( ) ; double u = scanner . nextDouble ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = scanner . nextDouble ( ) ; } Arrays . sort ( p ) ; double limit = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == n - 1 || ( p [ i + 1 ] - p [ i ] ) * ( i + 1 ) > u ) { limit = u / ( i + 1 ) + p [ i ] ; break ; } else { u -= ( p [ i + 1 ] - p [ i ] ) * ( i + 1 ) ; } } double poss = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] < limit ) poss *= limit ; else poss *= p [ i ] ; } return poss ; } }

package gcj2017 . r1c ; import java . io . * ; import java . util . Arrays ; import java . util . Scanner ; public class Training { static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { String name = " gcj2017 / r1c / C - small - 1" ; Scanner s = new Scanner ( new File ( name + " . in " ) ) ; int count = s . nextInt ( ) ; out = new PrintWriter ( new BufferedWriter ( new FileWriter ( name + " . out " ) ) ) ; for ( int ii = 1 ; ii <= count ; ii ++ ) { out . print ( " Case ▁ # " + ii + " : ▁ " ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; double u = s . nextDouble ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = s . nextDouble ( ) ; } double res = solve ( n , k , u , p ) ; out . print ( String . format ( " % .8f " , res ) ) ; out . println ( ) ; } out . close ( ) ; } static double solve ( int n , int k , double u , double [ ] p ) { Arrays . sort ( p ) ; while ( u > 0.000000001 ) { double min = p [ 0 ] ; int ni = n ; double np = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( p [ i ] == min ) { continue ; } np = p [ i ] ; ni = i ; break ; } if ( ni * ( np - min ) <= u ) { for ( int i = 0 ; i < ni ; i ++ ) { p [ i ] = np ; } u -= ni * ( np - min ) ; } else { double d = u / ni ; for ( int i = 0 ; i < ni ; i ++ ) { p [ i ] += d ; } u = 0 ; } } double res = 1 ; for ( int i = 0 ; i < n ; i ++ ) { res *= p [ i ] ; } return res ; } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( new File ( " output . txt " ) ) ; int T = in . nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; double budget = in . nextDouble ( ) ; double [ ] p = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = in . nextDouble ( ) ; } out . println ( " Case ▁ # " + t + " : ▁ " + calc ( p , budget ) ) ; } out . close ( ) ; } static double calc ( double [ ] p , double budget ) { double ans = 1.0 ; int n = p . length ; Arrays . sort ( p ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { double d = p [ i + 1 ] - p [ i ] ; double need = d * ( i + 1 ) ; if ( budget < need ) { double minP = p [ i ] + budget / ( i + 1 ) ; for ( int j = 0 ; j <= i ; j ++ ) { ans *= minP ; } for ( int j = i + 1 ; j < n ; j ++ ) { ans *= p [ j ] ; } return ans ; } budget -= need ; } double minP = p [ n - 1 ] + budget / n ; return Math . pow ( minP , n ) ; } }

import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( " C - small - 1 - attempt2 . in " ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( " solve . txt " ) ) ; int T = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; StringTokenizer s ; for ( int t = 1 ; t <= T ; t ++ ) { s = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; int N = Integer . parseInt ( s . nextToken ( ) ) ; int K = Integer . parseInt ( s . nextToken ( ) ) ; double [ ] arr = new double [ N ] ; double U = Double . parseDouble ( br . readLine ( ) . trim ( ) ) ; s = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = Double . parseDouble ( s . nextToken ( ) ) ; } Arrays . sort ( arr ) ; double pro = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i != N - 1 ) { if ( U > ( ( i + 1 ) * ( arr [ i + 1 ] - arr [ i ] ) ) ) { U -= ( ( i + 1 ) * ( arr [ i + 1 ] - arr [ i ] ) ) ; } else { pro = Math . pow ( ( arr [ i ] + ( U / ( i + 1 ) ) ) , i + 1 ) ; for ( int j = i + 1 ; j < N ; j ++ ) { pro *= arr [ j ] ; } break ; } } else { pro = Math . pow ( ( U / N ) + arr [ i ] , N ) ; } } bw . write ( " Case ▁ # " + t + " : ▁ " ) ; bw . write ( String . format ( " % .6f \n " , pro ) ) ; } br . close ( ) ; bw . close ( ) ; return ; } }

def check ( V , U , P ) : NEW_LINE INDENT return sum ( V - x for x in P if x < V ) <= U NEW_LINE DEDENT def solve ( N , K , U , P ) : NEW_LINE INDENT L , R = 0.0 , 1.0 NEW_LINE if ( check ( R , U , P ) ) : NEW_LINE INDENT return R NEW_LINE DEDENT while R - L > 1e-10 : NEW_LINE INDENT M = ( L + R ) / 2.0 NEW_LINE if check ( M , U , P ) : NEW_LINE INDENT L = M NEW_LINE DEDENT else : NEW_LINE INDENT R = M NEW_LINE DEDENT DEDENT res = 1.0 NEW_LINE for x in P : NEW_LINE INDENT res *= max ( x , L ) NEW_LINE DEDENT return res NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , K = map ( int , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE U = float ( raw_input ( ) ) NEW_LINE P = map ( float , raw_input ( ) . split ( ' ▁ ' ) ) NEW_LINE res = solve ( N , K , U , P ) NEW_LINE print ' Case ▁ # % d : ▁ % s ' % ( t + 1 , res ) NEW_LINE DEDENT

import sys NEW_LINE import math NEW_LINE from functools import reduce NEW_LINE lines = [ l . strip ( ) for l in sys . stdin . readlines ( ) ] NEW_LINE T = int ( lines [ 0 ] ) NEW_LINE i = 1 NEW_LINE for t in range ( T ) : NEW_LINE INDENT N , K = map ( int , lines [ i ] . split ( ' ▁ ' ) ) NEW_LINE i += 1 NEW_LINE U = float ( lines [ i ] ) NEW_LINE i += 1 NEW_LINE P = list ( map ( float , lines [ i ] . split ( ' ▁ ' ) ) ) NEW_LINE i += 1 NEW_LINE P . sort ( ) NEW_LINE j = 0 NEW_LINE while j < N and U > 0.000000000001 : NEW_LINE INDENT while j < N - 1 and P [ j ] == P [ j + 1 ] : NEW_LINE INDENT j += 1 NEW_LINE DEDENT target = P [ j + 1 ] if j < N - 1 else 1 NEW_LINE required = ( target - P [ j ] ) * ( j + 1 ) NEW_LINE if required <= U : NEW_LINE INDENT U -= required NEW_LINE P [ 0 : j + 1 ] = [ target ] * ( j + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT target = P [ j ] + U / ( j + 1 ) NEW_LINE U = 0 NEW_LINE P [ 0 : j + 1 ] = [ target ] * ( j + 1 ) NEW_LINE DEDENT DEDENT print ( " Case ▁ # % d : ▁ % f " % ( t + 1 , reduce ( lambda x , y : x * y , P , 1.0 ) ) ) NEW_LINE DEDENT

import math NEW_LINE CONVERT = 10000 NEW_LINE def f ( nums , power , k ) : NEW_LINE INDENT for i in range ( power ) : NEW_LINE INDENT nums [ nums . index ( min ( nums ) ) ] += 1 NEW_LINE DEDENT ans = 1 NEW_LINE for n in nums : NEW_LINE INDENT ans *= n / CONVERT NEW_LINE DEDENT return ans NEW_LINE DEDENT def logs ( x ) : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return - 100000 NEW_LINE DEDENT return math . log ( x ) NEW_LINE DEDENT def logadd ( a , b ) : NEW_LINE INDENT if a < b : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT return a + logs ( 1 + math . exp ( b - a ) ) NEW_LINE DEDENT def p ( nums , K ) : NEW_LINE INDENT store = [ ] NEW_LINE for i in range ( K + 1 ) : NEW_LINE INDENT store . append ( [ 0 ] * len ( nums ) ) NEW_LINE DEDENT for k in range ( K + 1 ) : NEW_LINE INDENT for i in range ( len ( nums ) ) : NEW_LINE INDENT if k == 0 : NEW_LINE INDENT store [ k ] [ i ] = 0 NEW_LINE DEDENT elif i == 0 : NEW_LINE INDENT store [ k ] [ i ] = - 100000 NEW_LINE DEDENT else : NEW_LINE INDENT store [ k ] [ i ] = logadd ( store [ k - 1 ] [ i - 1 ] + logs ( nums [ i ] ) , store [ k ] [ i - 1 ] + logs ( 1 - nums [ i ] ) ) NEW_LINE DEDENT DEDENT DEDENT return store [ K ] [ len ( nums ) - 1 ] NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE power = float ( input ( ) ) NEW_LINE power *= CONVERT NEW_LINE power = round ( power ) NEW_LINE starts = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE for i in range ( len ( starts ) ) : NEW_LINE INDENT starts [ i ] = round ( starts [ i ] * CONVERT ) NEW_LINE DEDENT ans = f ( starts , power , k ) NEW_LINE print ( " Case ▁ # % s : ▁ % s " % ( case , ans ) ) NEW_LINE DEDENT

with open ( ' C - small - 1 - attempt0 . in ' ) as infile : NEW_LINE INDENT with open ( ' C - small - 1 - attempt0 . out ' , ' w ' ) as outfile : NEW_LINE INDENT cases = int ( next ( infile ) ) NEW_LINE for case in range ( 1 , cases + 1 ) : NEW_LINE INDENT n , k = map ( int , next ( infile ) . split ( ) ) NEW_LINE u = round ( float ( next ( infile ) ) * 10000 ) NEW_LINE p = list ( map ( lambda x : round ( float ( x ) * 10000 ) , next ( infile ) . split ( ) ) ) NEW_LINE p . sort ( ) NEW_LINE p . append ( 10000 ) NEW_LINE i = 0 NEW_LINE while u > 0 and i < len ( p ) : NEW_LINE INDENT while i < len ( p ) and p [ i ] == p [ i + 1 ] : NEW_LINE INDENT i += 1 NEW_LINE DEDENT x = min ( ( p [ i + 1 ] - p [ i ] ) * ( i + 1 ) , u ) NEW_LINE for j in range ( i + 1 ) : NEW_LINE INDENT p [ j ] += x / ( i + 1 ) NEW_LINE DEDENT u -= x NEW_LINE DEDENT product = 1 NEW_LINE for x in p : NEW_LINE INDENT product *= x / 10000 NEW_LINE DEDENT print ( case , product ) NEW_LINE print ( " Case ▁ # { } : ▁ { } " . format ( case , product ) , file = outfile ) NEW_LINE DEDENT DEDENT DEDENT

import sys NEW_LINE def problem ( success , units , cores ) : NEW_LINE INDENT cores . sort ( ) NEW_LINE cores . append ( 1.0 ) NEW_LINE spent = 0.0 NEW_LINE min_prob = 0.0 NEW_LINE for i , core in enumerate ( cores ) : NEW_LINE INDENT if core == 1.0 : NEW_LINE INDENT min_prob = 1.0 NEW_LINE break NEW_LINE DEDENT plan = ( cores [ i + 1 ] - cores [ i ] ) * ( i + 1 ) NEW_LINE if plan > units - spent : NEW_LINE INDENT min_prob = core + ( units - spent ) / ( i + 1 ) NEW_LINE break NEW_LINE DEDENT spent += plan NEW_LINE DEDENT prob = 1.0 NEW_LINE for n in cores : NEW_LINE INDENT prob *= max ( min_prob , n ) NEW_LINE DEDENT return prob NEW_LINE DEDENT def nextline ( input_file ) : NEW_LINE INDENT data = " " NEW_LINE while not data : NEW_LINE INDENT data = input_file . readline ( ) NEW_LINE DEDENT return data [ : - 1 ] NEW_LINE DEDENT def intsplit ( s ) : NEW_LINE INDENT return [ int ( x ) for x in s . split ( " ▁ " ) ] NEW_LINE DEDENT def floatsplit ( s ) : NEW_LINE INDENT return [ float ( x ) for x in s . split ( " ▁ " ) ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT result = " " NEW_LINE with sys . stdin if len ( sys . argv ) == 1 else open ( sys . argv [ 1 ] , ' r ' ) as infile : NEW_LINE INDENT number = int ( nextline ( infile ) ) NEW_LINE for run in range ( number ) : NEW_LINE INDENT case = nextline ( infile ) NEW_LINE total , success = intsplit ( case ) NEW_LINE units = float ( nextline ( infile ) ) NEW_LINE cores = floatsplit ( nextline ( infile ) ) NEW_LINE result += ' Case ▁ # { } : ▁ { } \n ' . format ( 1 + run , problem ( success , units , cores ) ) NEW_LINE DEDENT DEDENT if len ( sys . argv ) == 1 : NEW_LINE INDENT print ( result , end = ' ' ) NEW_LINE DEDENT else : NEW_LINE INDENT with open ( sys . argv [ 1 ] . replace ( ' in ' , ' sol ' ) , ' w ' ) as result_file : NEW_LINE INDENT result_file . write ( result ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; import java . math . * ; public class C { private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; private void solve ( ) throws IOException { int tests = nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { out . print ( " Case ▁ # " + test + " : ▁ " ) ; int N = nextInt ( ) ; long L = nextLong ( ) ; long H = nextLong ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = nextLong ( ) ; } long result = - 1 ; for ( long C = L ; C <= H ; C ++ ) { boolean ok = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( C % A [ i ] != 0 && A [ i ] % C != 0 ) { ok = false ; break ; } } if ( ok ) { result = C ; break ; } } if ( result == - 1 ) { out . println ( " NO " ) ; } else { out . println ( result ) ; } } } public static void main ( String [ ] args ) { new C ( ) . run ( ) ; } public void run ( ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ; st = null ; solve ( ) ; in . close ( ) ; out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } private String nextToken ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( in . readLine ( ) ) ; } return st . nextToken ( ) ; } private int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } private long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } private double nextDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; } }

package CodeJam ; import java . util . * ; import java . io . * ; import org . apache . commons . lang . StringUtils ; import org . apache . commons . lang . ArrayUtils ; import java . lang . Math . * ; import java . math . BigInteger ; import static helper . Print . * ; public class B { private static String inFilename = " C - small - attempt0 . in " ; public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new FileReader ( " src / CodeJam / " + inFilename ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( " src / CodeJam / output . txt " ) ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { String result = " NO " ; int N = in . nextInt ( ) ; int L = in . nextInt ( ) ; int H = in . nextInt ( ) ; int [ ] f = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { f [ i ] = in . nextInt ( ) ; } loop : for ( int i = L ; i <= H ; i ++ ) { int j = 0 ; for ( ; j < N ; j ++ ) { if ( ! ( f [ j ] % i == 0 || i % f [ j ] == 0 ) ) { continue loop ; } } if ( j == N ) { result = String . valueOf ( i ) ; break ; } } out . print ( " Case ▁ # " + ( t + 1 ) + " : ▁ " + result + " \n " ) ; } in . close ( ) ; out . close ( ) ; } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class PerfectHarmony { public static void main ( String args [ ] ) throws FileNotFoundException { new PerfectHarmony ( ) ; } public PerfectHarmony ( ) throws FileNotFoundException { Scanner scanner = new Scanner ( System . in ) ; PrintWriter writer = new PrintWriter ( new File ( " C : / res . txt " ) ) ; int COUNT = scanner . nextInt ( ) ; for ( int y = 1 ; y <= COUNT ; y ++ ) { int N = scanner . nextInt ( ) , L = scanner . nextInt ( ) , H = scanner . nextInt ( ) ; int nums [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) nums [ i ] = scanner . nextInt ( ) ; boolean result = false ; loop : for ( int i = L ; i <= H ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) if ( i % nums [ j ] != 0 && nums [ j ] % i != 0 ) continue loop ; writer . write ( String . format ( " Case ▁ # % d : ▁ % d \n " , y , i ) ) ; result = true ; break loop ; } if ( ! result ) { writer . write ( String . format ( " Case ▁ # % d : ▁ NO \n " , y ) ) ; } } writer . close ( ) ; } }

import java . io . * ; import java . util . * ; public class Main { Scanner in ; PrintWriter out ; static final String problem = " C - small " ; static void asserT ( boolean e ) { if ( ! e ) { throw new Error ( ) ; } } void solveOne ( ) { int nPlayers = in . nextInt ( ) ; int low = in . nextInt ( ) ; int high = in . nextInt ( ) ; int freq [ ] = new int [ nPlayers ] ; for ( int i = 0 ; i < freq . length ; i ++ ) { freq [ i ] = in . nextInt ( ) ; } for ( int f = low ; f <= high ; f ++ ) { boolean fail = false ; for ( int other : freq ) { if ( other % f != 0 && f % other != 0 ) { fail = true ; break ; } } if ( ! fail ) { out . println ( f ) ; return ; } } out . println ( " NO " ) ; } void solve ( ) { int nTests = in . nextInt ( ) ; for ( int i = 0 ; i < nTests ; i ++ ) { out . print ( " Case ▁ # " + ( i + 1 ) + " : ▁ " ) ; solveOne ( ) ; } } void run ( ) { try { in = new Scanner ( new FileReader ( " C : \ \r oundC\ \" + problem + " . in " ) ) ; out = new PrintWriter ( new FileWriter ( " C : \ \r oundC\ \" + problem + " . out " ) ) ; } catch ( IOException e ) { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; } try { solve ( ) ; } finally { out . close ( ) ; } } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } }

import java . io . * ; import java . math . * ; import java . util . * ; import java . text . * ; import java . util . regex . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; import static java . lang . Integer . * ; import static java . lang . Double . * ; import static java . lang . Character . * ; public class C { Object solve ( ) { int N = sc . nextInt ( ) ; long L = sc . nextLong ( ) ; long H = sc . nextLong ( ) ; long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextLong ( ) ; loop : for ( long m = L ; m <= H ; m ++ ) { for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] % m != 0 && m % a [ i ] != 0 ) continue loop ; } return m ; } return " NO " ; } private static Scanner sc ; private static PrintWriter fw ; public static void main ( String [ ] args ) throws Exception { String inFile ; inFile = " C - small - attempt0 . in " ; sc = new Scanner ( new FileInputStream ( inFile ) ) ; fw = new PrintWriter ( new FileWriter ( " output . txt " , false ) ) ; int N = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int cas = 1 ; cas <= N ; cas ++ ) { fw . print ( " Case ▁ # " + cas + " : ▁ " ) ; Object res = new C ( ) . solve ( ) ; if ( res instanceof Double ) fw . printf ( " % .10f \n " , res ) ; else fw . printf ( " % s \n " , res ) ; fw . flush ( ) ; } fw . close ( ) ; sc . close ( ) ; } }

class streamreader : NEW_LINE INDENT def __init__ ( _ , s ) : _ . t = ( t for t in s . read ( ) . split ( ) ) NEW_LINE def __div__ ( _ , t ) : return ( t ) ( _ . t . next ( ) ) NEW_LINE DEDENT import sys NEW_LINE sr = streamreader ( sys . stdin ) NEW_LINE for tc in xrange ( sr / int ) : NEW_LINE INDENT n , l , h = sr / int , sr / int , sr / int NEW_LINE fr = [ sr / int for i in xrange ( n ) ] NEW_LINE answer = ' NO ' NEW_LINE for x in xrange ( l , h + 1 ) : NEW_LINE INDENT ok = True NEW_LINE for f in fr : NEW_LINE INDENT if f % x != 0 and x % f != 0 : NEW_LINE INDENT ok = False NEW_LINE break NEW_LINE DEDENT DEDENT if ok : NEW_LINE INDENT answer = x NEW_LINE break NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ' % ( tc + 1 ) , answer NEW_LINE DEDENT

import math NEW_LINE import sys NEW_LINE def printe ( * st ) : NEW_LINE INDENT return True NEW_LINE sys . stderr . write ( " , " . join ( [ str ( x ) for x in st ] ) + " \n " ) NEW_LINE DEDENT def generator ( N , l ) : NEW_LINE INDENT a = 0 NEW_LINE i = 0 NEW_LINE while a < N : NEW_LINE INDENT yield l [ i ] NEW_LINE i += 1 NEW_LINE if i == len ( l ) : NEW_LINE INDENT i = 0 NEW_LINE DEDENT a += 1 NEW_LINE DEDENT DEDENT def simulate ( ) : NEW_LINE INDENT [ n , l , h ] = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE orchestra = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE notes = [ ] NEW_LINE for i in range ( l , h + 1 ) : NEW_LINE INDENT notes . append ( i ) NEW_LINE DEDENT for l in orchestra : NEW_LINE INDENT i = 0 NEW_LINE while i < len ( notes ) : NEW_LINE INDENT if notes [ i ] % l == 0 or l % notes [ i ] == 0 : NEW_LINE INDENT i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT notes . pop ( i ) NEW_LINE DEDENT DEDENT printe ( notes ) NEW_LINE DEDENT if len ( notes ) == 0 : NEW_LINE INDENT return " NO " NEW_LINE DEDENT else : NEW_LINE INDENT return notes [ 0 ] NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT print ( " Case ▁ # { } : ▁ { } " . format ( i + 1 , simulate ( ) ) ) NEW_LINE DEDENT DEDENT

f = open ( ' C - small - attempt0 . in ' , ' r ' ) NEW_LINE x = f . readlines ( ) NEW_LINE x = x [ 1 : ] NEW_LINE for i in range ( len ( x ) / 2 ) : NEW_LINE INDENT a = 2 * i NEW_LINE x [ a ] = x [ a ] . strip ( ) . split ( ) NEW_LINE x [ a + 1 ] = x [ a + 1 ] . strip ( ) . split ( ) NEW_LINE n = x [ a ] [ 0 ] NEW_LINE l = int ( x [ a ] [ 1 ] ) NEW_LINE h = int ( x [ a ] [ 2 ] ) NEW_LINE ans = 0 NEW_LINE for z in range ( l , h + 1 ) : NEW_LINE INDENT cou = 0 NEW_LINE for c in x [ a + 1 ] : NEW_LINE INDENT if z % int ( c ) == 0 or int ( c ) % z == 0 : NEW_LINE INDENT cou += 1 NEW_LINE DEDENT DEDENT if cou == len ( x [ a + 1 ] ) : NEW_LINE INDENT ans = z NEW_LINE break NEW_LINE DEDENT DEDENT if ans == 0 : NEW_LINE INDENT print " Case ▁ # % d : ▁ NO " % ( i + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( i + 1 , ans ) NEW_LINE DEDENT DEDENT

filename = " C - small - attempt1 . in " NEW_LINE outputname = filename + " out . txt " NEW_LINE inFile = open ( filename , ' r ' ) NEW_LINE outFile = open ( outputname , ' w ' ) NEW_LINE numCases = int ( inFile . readline ( ) ) NEW_LINE for i in range ( numCases ) : NEW_LINE INDENT print i NEW_LINE nextLine = inFile . readline ( ) . split ( ) NEW_LINE numPlayers = int ( nextLine [ 0 ] ) NEW_LINE low = int ( nextLine [ 1 ] ) NEW_LINE high = int ( nextLine [ 2 ] ) NEW_LINE players = [ ] NEW_LINE playerLine = inFile . readline ( ) . split ( ) NEW_LINE for j in range ( numPlayers ) : NEW_LINE INDENT players += [ float ( playerLine [ j ] ) ] NEW_LINE DEDENT minFreq = min ( players ) NEW_LINE possFreqs = [ minFreq * j for j in range ( 1 , int ( high / minFreq ) + 1 ) ] NEW_LINE for j in range ( 1 , int ( minFreq ) ) : NEW_LINE INDENT if ( minFreq / j ) % 1 == 0 : NEW_LINE INDENT possFreqs += [ j ] NEW_LINE DEDENT DEDENT for player in players : NEW_LINE INDENT j = len ( possFreqs ) - 1 NEW_LINE while j >= 0 : NEW_LINE INDENT if ( player / possFreqs [ j ] ) % 1 == 0 or ( possFreqs [ j ] / player ) % 1 == 0 : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT possFreqs . pop ( j ) NEW_LINE j -= 1 NEW_LINE DEDENT DEDENT DEDENT finals = [ ] NEW_LINE for freq in possFreqs : NEW_LINE INDENT if freq >= low and freq <= high : NEW_LINE INDENT finals += [ freq ] NEW_LINE DEDENT DEDENT finals . sort ( ) NEW_LINE if len ( finals ) == 0 : NEW_LINE INDENT outFile . write ( " Case ▁ # " + str ( i + 1 ) + " : ▁ NO \n " ) NEW_LINE DEDENT else : NEW_LINE INDENT outFile . write ( " Case ▁ # " + str ( i + 1 ) + " : ▁ " + str ( int ( finals [ 0 ] ) ) + " \n " ) NEW_LINE DEDENT DEDENT inFile . close ( ) NEW_LINE outFile . close ( ) NEW_LINE

from collections import defaultdict NEW_LINE from random import shuffle NEW_LINE import sys NEW_LINE def go ( filename ) : NEW_LINE INDENT with open ( filename ) as f : NEW_LINE INDENT with open ( " out . txt " , " w " ) as output : NEW_LINE INDENT for case in range ( 1 , int ( f . readline ( ) ) + 1 ) : NEW_LINE INDENT output . write ( " Case ▁ # % s : ▁ " % case ) NEW_LINE in1 = [ int ( v ) for v in f . readline ( ) . split ( ) ] NEW_LINE l , h = in1 [ 1 ] , in1 [ 2 ] NEW_LINE jeff = [ ] NEW_LINE for i in range ( l , h + 1 ) : NEW_LINE INDENT jeff . append ( i ) NEW_LINE DEDENT players = [ int ( v ) for v in f . readline ( ) . split ( ) ] NEW_LINE for p in players : NEW_LINE INDENT nj = [ ] NEW_LINE for j in jeff : NEW_LINE INDENT if ( j >= p and j % p == 0 ) or ( j < p and p % j == 0 ) : NEW_LINE INDENT nj . append ( j ) NEW_LINE DEDENT DEDENT jeff = nj NEW_LINE if not jeff : NEW_LINE INDENT output . write ( " NO \n " ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT output . write ( " % s \n " % jeff [ 0 ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT def main ( ) : NEW_LINE INDENT if len ( sys . argv ) < 1 : NEW_LINE INDENT print " Usage : ▁ % s ▁ < filename > " % os . path . basename ( sys . argv [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT go ( sys . argv [ 1 ] ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . util . * ; import static java . lang . Math . * ; public class D { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { String S = in . next ( ) ; long v = 0 ; long nv = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int at = S . length ( ) - i - 1 ; if ( S . charAt ( i ) == ' ? ' ) { nv |= 1L << at ; } else if ( S . charAt ( i ) == '1' ) { v |= 1L << at ; } } long ans = 0 ; for ( long c = nv ; ; c = ( c - 1 ) & nv ) { long test = v + c ; if ( issquare ( test ) ) { ans = test ; break ; } if ( c == 0 ) break ; } System . out . format ( " Case ▁ # % d : ▁ % s \n " , zz , Long . toBinaryString ( ans ) ) ; } } private static boolean issquare ( long t ) { long low = 1 ; long high = Integer . MAX_VALUE ; while ( low <= high ) { long mid = ( low + high ) / 2 ; long v = mid * mid ; if ( v == t ) { return true ; } if ( v < t ) { low = mid + 1 ; } else { high = mid - 1 ; } } return false ; } }

import java . io . * ; import java . util . * ; public class D { private static String fileName = D . class . getSimpleName ( ) . replaceFirst ( " _ . * " , " " ) . toLowerCase ( ) ; private static String inputFileName = fileName + " . in " ; private static String outputFileName = fileName + " . out " ; private static Scanner in ; private static PrintWriter out ; private void solve ( ) { String s = in . next ( ) ; int n = s . length ( ) ; int [ ] a = new int [ n ] ; int q = 0 ; for ( int i = 0 ; i < n ; i ++ ) { switch ( s . charAt ( i ) ) { case '0' : a [ i ] = 0 ; break ; case '1' : a [ i ] = 1 ; break ; case ' ? ' : a [ i ] = 2 ; q ++ ; break ; } } for ( int mask = 0 ; mask < ( 1 << q ) ; mask ++ ) { long v = 0 ; for ( int i = 0 , j = 0 ; i < n ; i ++ ) { int c = a [ i ] ; if ( c == 2 ) { c = ( mask >> j ) & 1 ; j ++ ; } v = 2 * v + c ; } long u = Math . round ( Math . sqrt ( v ) ) ; if ( u * u == v ) { out . println ( Long . toBinaryString ( v ) ) ; return ; } } throw new RuntimeException ( ) ; } public static void main ( String [ ] args ) throws IOException { Locale . setDefault ( Locale . US ) ; if ( args . length >= 2 ) { inputFileName = args [ 0 ] ; outputFileName = args [ 1 ] ; } in = new Scanner ( new FileReader ( inputFileName ) ) ; out = new PrintWriter ( outputFileName ) ; int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { out . print ( " Case ▁ # " + t + " : ▁ " ) ; new D ( ) . solve ( ) ; System . out . println ( " Case ▁ # " + t + " : ▁ solved " ) ; } in . close ( ) ; out . close ( ) ; } }

import static java . lang . Math . * ; import static java . util . Arrays . * ; import java . io . * ; import java . util . * ; public class D { Scanner sc = new Scanner ( System . in ) ; void solve ( ) { char [ ] cs = sc . next ( ) . toCharArray ( ) ; int m = 0 ; for ( char c : cs ) if ( c == ' ? ' ) m ++ ; for ( int i = 0 ; i < 1 << m ; i ++ ) { char [ ] ds = cs . clone ( ) ; int p = 0 ; for ( int j = 0 ; j < cs . length ; j ++ ) if ( cs [ j ] == ' ? ' ) { ds [ j ] = ( char ) ( '0' + ( i >> p & 1 ) ) ; p ++ ; } long v = 0 ; for ( char c : ds ) v = v * 2 + c - '0' ; long a = ( long ) sqrt ( v ) ; while ( a * a < v ) a ++ ; while ( a * a > v ) a -- ; if ( a * a == v ) { System . out . println ( Long . toBinaryString ( v ) ) ; return ; } } } void run ( ) { int caseN = sc . nextInt ( ) ; for ( int caseID = 1 ; caseID <= caseN ; caseID ++ ) { System . out . printf ( " Case ▁ # % d : ▁ " , caseID ) ; solve ( ) ; System . out . flush ( ) ; } } 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 ] : ( D . class . getName ( ) + " . in " ) ) ) ) ; } catch ( Exception e ) { } new D ( ) . run ( ) ; } }

package round3 ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ; public class D { static long [ ] stepeni = new long [ 62 ] ; static { stepeni [ 0 ] = 1 ; for ( int i = 1 ; i < stepeni . length ; i ++ ) stepeni [ i ] = 2 * stepeni [ i - 1 ] ; } static boolean jePotpunKvadrat ( long a ) { long koren = Math . round ( Math . sqrt ( a ) ) ; return koren * koren == a ; } static long resi ( String s , long value , int position ) { if ( jePotpunKvadrat ( value ) ) return value ; if ( position == s . length ( ) ) return - 1 ; if ( s . charAt ( position ) == ' ? ' ) { long res = resi ( s , value , position + 1 ) ; if ( res != - 1 ) return res ; return resi ( s , value + stepeni [ s . length ( ) - position - 1 ] , position + 1 ) ; } else return resi ( s , value , position + 1 ) ; } public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( " D . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " D . out " ) ) ; int tt = in . nextInt ( ) ; for ( int ttt = 1 ; ttt <= tt ; ttt ++ ) { String s = in . next ( ) ; long min = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( s . length ( ) - i - 1 ) == '1' ) min += stepeni [ i ] ; long res = resi ( s , min , 0 ) ; out . printf ( " Case ▁ # % d : ▁ % s " , ttt , Long . toBinaryString ( res ) ) ; out . println ( ) ; } out . flush ( ) ; out . close ( ) ; in . close ( ) ; } }

import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class Main { public StringBuffer s ; public boolean ok ; public String ans ; public void rec ( ) { if ( ok ) return ; int pos = - 1 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i ) == ' ? ' ) { pos = i ; break ; } if ( pos == - 1 ) { BigInteger b = BigInteger . ZERO ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( s . charAt ( i ) == '1' ) b = b . add ( BigInteger . ONE . shiftLeft ( s . length ( ) - 1 - i ) ) ; BigInteger l = BigInteger . ONE , r = BigInteger . TEN . pow ( 25 ) ; while ( l . compareTo ( r ) != 0 ) { BigInteger x = l . add ( r ) . shiftRight ( 1 ) ; BigInteger xx = x . multiply ( x ) ; if ( xx . compareTo ( b ) >= 0 ) r = x ; else l = x . add ( BigInteger . ONE ) ; } BigInteger test = l . multiply ( l ) ; if ( test . compareTo ( b ) == 0 ) { ok = true ; ans = test . toString ( 2 ) ; } } else { s . setCharAt ( pos , '0' ) ; rec ( ) ; s . setCharAt ( pos , '1' ) ; rec ( ) ; s . setCharAt ( pos , ' ? ' ) ; } } public void run ( ) throws IOException { Scanner in = new Scanner ( new File ( " D . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " D . out " ) ) ; int T = in . nextInt ( ) ; in . nextLine ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { out . print ( " Case ▁ # " + t + " : ▁ " ) ; String ss = in . nextLine ( ) ; s = new StringBuffer ( ss ) ; ok = false ; rec ( ) ; out . println ( ans ) ; out . flush ( ) ; } } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } }

import sys NEW_LINE from fractions import Fraction NEW_LINE from fractions import gcd NEW_LINE from collections import defaultdict NEW_LINE import copy NEW_LINE import multiprocessing NEW_LINE cin = sys . stdin . readline NEW_LINE def nrt ( n ) : NEW_LINE INDENT op = n NEW_LINE res = 0 NEW_LINE one = 1 NEW_LINE while one * 4 <= op : NEW_LINE INDENT one *= 4 NEW_LINE DEDENT while one != 0 : NEW_LINE INDENT if op >= res + one : NEW_LINE INDENT op -= res + one NEW_LINE res = ( res >> 1 ) + one NEW_LINE DEDENT else : NEW_LINE INDENT res >>= 1 NEW_LINE DEDENT one >>= 2 NEW_LINE DEDENT return op NEW_LINE DEDENT def solve ( s ) : NEW_LINE INDENT out = 0 NEW_LINE unknown = 0 NEW_LINE S = len ( s ) NEW_LINE bits = list ( ) NEW_LINE for e , i in enumerate ( s ) : NEW_LINE INDENT out *= 2 NEW_LINE unknown *= 2 NEW_LINE if i == '1' : NEW_LINE INDENT out += 1 NEW_LINE DEDENT elif i == ' ? ' : NEW_LINE INDENT unknown += 1 NEW_LINE bits . append ( ( 1 << ( S - e - 1 ) ) ) NEW_LINE DEDENT DEDENT answer = ( out | unknown ) NEW_LINE x = nrt ( answer ) NEW_LINE while x != 0 : NEW_LINE INDENT answer -= x NEW_LINE new_answer = out NEW_LINE for num in bits : NEW_LINE INDENT if ( new_answer | num ) <= answer : NEW_LINE INDENT new_answer |= num NEW_LINE DEDENT DEDENT answer = new_answer NEW_LINE x = nrt ( answer ) NEW_LINE DEDENT return bin ( answer ) [ 2 : ] NEW_LINE DEDENT def procfunc ( tup ) : NEW_LINE INDENT x = solve ( * tup [ 1 : ] ) NEW_LINE print >> sys . stderr , " SOLVE " , tup [ 0 ] NEW_LINE return x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT T = int ( cin ( ) ) NEW_LINE inputs = [ ] NEW_LINE for cnum in xrange ( T ) : NEW_LINE INDENT arr = cin ( ) . strip ( ) NEW_LINE inputs . append ( ( cnum , arr ) ) NEW_LINE DEDENT if False : NEW_LINE INDENT pool = multiprocessing . Pool ( ) NEW_LINE output = pool . map_async ( procfunc , inputs , 1 ) . get ( 999999 ) NEW_LINE DEDENT else : NEW_LINE INDENT output = list ( procfunc ( x ) for x in inputs ) NEW_LINE DEDENT for i , out in enumerate ( output ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( i + 1 , out ) NEW_LINE DEDENT DEDENT

from math import sqrt NEW_LINE T = int ( raw_input ( ) ) NEW_LINE def is_square ( x ) : NEW_LINE INDENT y = int ( sqrt ( x ) + 0.1 ) NEW_LINE return y * y == x NEW_LINE DEDENT def try_it ( s , i ) : NEW_LINE INDENT global poss NEW_LINE if i >= len ( poss ) : NEW_LINE INDENT return s if is_square ( s ) else 0 NEW_LINE DEDENT else : NEW_LINE INDENT p = poss [ i ] NEW_LINE x = try_it ( s , i + 1 ) NEW_LINE if x : NEW_LINE INDENT return x NEW_LINE DEDENT return try_it ( s + p , i + 1 ) NEW_LINE DEDENT DEDENT for case_num in xrange ( 1 , T + 1 ) : NEW_LINE INDENT S = raw_input ( ) . strip ( ) NEW_LINE N = len ( S ) NEW_LINE poss = [ ] NEW_LINE s = 0 NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT c = S [ i ] NEW_LINE power = N - 1 - i NEW_LINE if c == '1' : NEW_LINE INDENT s += 2 ** power NEW_LINE DEDENT elif c == ' ? ' : NEW_LINE INDENT poss . append ( 2 ** power ) NEW_LINE DEDENT DEDENT res = try_it ( s , 0 ) NEW_LINE output = ' ' NEW_LINE while res : NEW_LINE INDENT output = str ( res % 2 ) + output NEW_LINE res /= 2 NEW_LINE DEDENT print " Case ▁ # % d : ▁ % s " % ( case_num , output ) NEW_LINE DEDENT

def run ( ) : NEW_LINE INDENT s = raw_input ( ) NEW_LINE q = [ ] NEW_LINE a = 0 NEW_LINE for ( i , b ) in enumerate ( reversed ( s ) ) : NEW_LINE INDENT if ( b == ' ? ' ) : q . append ( i ) NEW_LINE if ( b == '1' ) : a += 1 << i NEW_LINE DEDENT if not q : return s NEW_LINE for i in xrange ( 1 << len ( q ) ) : NEW_LINE INDENT r = a NEW_LINE for ( j , b ) in enumerate ( q ) : NEW_LINE INDENT if ( ( ( i >> j ) & 1 ) == 0 ) : continue NEW_LINE r += 1 << b NEW_LINE DEDENT if r == int ( r ** 0.5 ) ** 2 : NEW_LINE INDENT res = list ( s ) NEW_LINE for ( j , b ) in enumerate ( q ) : NEW_LINE INDENT res [ - b - 1 ] = '0' if ( ( i >> j ) & 1 ) == 0 else '1' NEW_LINE DEDENT return ' ' . join ( res ) NEW_LINE DEDENT DEDENT assert False NEW_LINE DEDENT for test in xrange ( input ( ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( test + 1 , run ( ) ) NEW_LINE DEDENT

import sys , collections NEW_LINE infile = sys . stdin NEW_LINE def find_square ( S ) : NEW_LINE INDENT qpos = [ i for i , ch in enumerate ( S ) if ch == ' ? ' ] NEW_LINE ns = len ( S ) NEW_LINE nq = len ( qpos ) NEW_LINE baseval = int ( S . replace ( ' ? ' , '0' ) , 2 ) NEW_LINE for i in xrange ( 1 << len ( qpos ) ) : NEW_LINE INDENT val = baseval NEW_LINE for j in xrange ( nq ) : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT p = 1 << ( ns - qpos [ j ] - 1 ) NEW_LINE val += p NEW_LINE DEDENT DEDENT r = int ( val ** 0.5 ) NEW_LINE if ( r * r == val ) : NEW_LINE INDENT return bin ( val ) [ 2 : ] NEW_LINE DEDENT DEDENT DEDENT T = int ( infile . readline ( ) ) NEW_LINE for i in xrange ( T ) : NEW_LINE INDENT S = infile . readline ( ) . strip ( ) NEW_LINE result = find_square ( S ) NEW_LINE print ( " Case ▁ # % d : ▁ % s " % ( i + 1 , result ) ) NEW_LINE DEDENT

import sys NEW_LINE def foo2 ( word , idx , n ) : NEW_LINE INDENT word = word [ : ] NEW_LINE for i in range ( len ( idx ) ) : NEW_LINE INDENT word [ idx [ i ] ] = n % 2 NEW_LINE n //= 2 NEW_LINE DEDENT res = 0 NEW_LINE for x in word : NEW_LINE INDENT res = res * 2 + x NEW_LINE DEDENT t = int ( res ** 0.5 ) NEW_LINE if t * t == res : NEW_LINE INDENT return ' ' . join ( str ( x ) for x in word ) NEW_LINE DEDENT DEDENT def foo ( ifile ) : NEW_LINE INDENT word = list ( ifile . readline ( ) . strip ( ) ) NEW_LINE idx = [ ] NEW_LINE n = 0 NEW_LINE for i in range ( len ( word ) ) : NEW_LINE INDENT if word [ i ] == ' ? ' : NEW_LINE INDENT idx . append ( i ) NEW_LINE word [ i ] = None NEW_LINE DEDENT else : NEW_LINE INDENT word [ i ] = int ( word [ i ] ) NEW_LINE DEDENT DEDENT n = len ( idx ) NEW_LINE if n == 0 : NEW_LINE INDENT return ' ' . join ( str ( x ) for x in word ) NEW_LINE DEDENT for i in range ( 2 ** n ) : NEW_LINE INDENT t = foo2 ( word , idx , i ) NEW_LINE if t is not None : NEW_LINE INDENT return t NEW_LINE DEDENT DEDENT DEDENT def main ( ifile , ofile ) : NEW_LINE INDENT n = int ( ifile . readline ( ) ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT ofile . write ( " Case ▁ # % s : ▁ % s \n " % ( i + 1 , foo ( ifile ) ) ) NEW_LINE ofile . flush ( ) NEW_LINE DEDENT DEDENT main ( sys . stdin , sys . stdout ) NEW_LINE


package round1a ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; Set < Long > need = new HashSet < Long > ( ) , have = new HashSet < Long > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String tmp = sc . next ( ) ; long tmp2 = 0 ; for ( int j = 0 ; j < L ; j ++ ) if ( tmp . charAt ( j ) == '1' ) tmp2 |= ( 1L << j ) ; have . add ( tmp2 ) ; } long lastNeeded = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String tmp = sc . next ( ) ; long tmp2 = 0 ; for ( int j = 0 ; j < L ; j ++ ) if ( tmp . charAt ( j ) == '1' ) tmp2 |= ( 1L << j ) ; need . add ( tmp2 ) ; lastNeeded = tmp2 ; } int ans = L + 1 ; for ( Long elem : have ) { long flip = lastNeeded ^ elem ; Set < Long > got = new HashSet < Long > ( ) ; for ( Long e : need ) { got . add ( e ^ flip ) ; } if ( got . equals ( have ) ) { ans = Math . min ( ans , Long . bitCount ( flip ) ) ; } } System . out . println ( " Case ▁ # " + caze + " : ▁ " + ( ans > L ? " NOT ▁ POSSIBLE " : ans ) ) ; } } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Scanner ; public class ChargingChaos { public static void main ( String [ ] Args ) throws FileNotFoundException { Scanner sc = new Scanner ( new File ( " A - large ▁ ( 1 ) . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " things . out " ) ) ; int t = sc . nextInt ( ) , cc = 0 ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; long [ ] things = new long [ n ] ; long [ ] things2 = new long [ n ] ; HashSet < Long > hs = new HashSet < Long > ( ) ; for ( int k = 0 ; k < n ; k ++ ) things [ k ] = make ( sc . next ( ) ) ; for ( int k = 0 ; k < n ; k ++ ) { things2 [ k ] = make ( sc . next ( ) ) ; hs . add ( things2 [ k ] ) ; } int ans = l + 1 ; for ( int k = 0 ; k < n ; k ++ ) { long swit = things [ 0 ] ^ things2 [ k ] ; boolean good = true ; for ( int j = 0 ; good && j < n ; j ++ ) if ( ! hs . contains ( things [ j ] ^ swit ) ) good = false ; if ( good ) ans = Math . min ( Long . bitCount ( swit ) , ans ) ; } if ( ans != l + 1 ) out . printf ( " Case ▁ # % d : ▁ % d % n " , ++ cc , ans ) ; else out . printf ( " Case ▁ # % d : ▁ NOT ▁ POSSIBLE % n " , ++ cc ) ; } out . close ( ) ; } private static long make ( String s ) { return Long . parseLong ( s , 2 ) ; } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Ae { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( " A . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( " A . out " ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = " Case ▁ # " + ( i + 1 ) + " : ▁ " + new Ae ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; int l = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( in . next ( ) , 2 ) ; } int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = Integer . parseInt ( in . next ( ) , 2 ) ; } int res = l + 1 ; Arrays . sort ( a ) ; for ( int m = 0 ; m < ( 1 << l ) ; m ++ ) { for ( int i = 0 ; i < n ; i ++ ) { b [ i ] ^= m ; } Arrays . sort ( b ) ; boolean ok = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { ok = false ; break ; } } if ( ok ) { res = Math . min ( res , Integer . bitCount ( m ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] ^= m ; } } return res > l ? " NOT ▁ POSSIBLE " : ( " " + res ) ; } }

import sys NEW_LINE def countBit ( x ) : NEW_LINE INDENT return 0 if x == 0 else ( x & 1 ) + countBit ( x >> 1 ) NEW_LINE DEDENT def trans ( s , m ) : NEW_LINE INDENT return ' ' . join ( [ chr ( ord ( c ) ^ ( ( m >> i ) & 1 ) ) for ( i , c ) in enumerate ( s ) ] ) NEW_LINE DEDENT TT = int ( sys . stdin . readline ( ) ) NEW_LINE for T in xrange ( 1 , TT + 1 ) : NEW_LINE INDENT N , L = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE A = sys . stdin . readline ( ) . split ( ) NEW_LINE B = sys . stdin . readline ( ) . split ( ) NEW_LINE ans = L + 1 NEW_LINE for m in xrange ( 1 << L ) : NEW_LINE INDENT cnt = countBit ( m ) NEW_LINE if cnt >= ans : continue NEW_LINE A2 = [ trans ( s , m ) for s in A ] NEW_LINE if set ( A2 ) == set ( B ) : NEW_LINE INDENT ans = cnt NEW_LINE DEDENT DEDENT anss = " NOT ▁ POSSIBLE " if ans == L + 1 else str ( ans ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( T , anss ) NEW_LINE DEDENT

def reader ( f ) : NEW_LINE INDENT f = open ( f ) NEW_LINE for line in f : NEW_LINE INDENT yield line . strip ( ) NEW_LINE DEDENT f . close ( ) NEW_LINE DEDENT def write ( f , lst ) : NEW_LINE INDENT for i in xrange ( len ( lst ) ) : NEW_LINE INDENT lst [ i ] = " Case ▁ # % s : ▁ % s " % ( i + 1 , lst [ i ] ) NEW_LINE DEDENT f = open ( f , ' w ' ) NEW_LINE f . write ( ' \n ' . join ( lst ) ) NEW_LINE f . close ( ) NEW_LINE DEDENT

T = int ( raw_input ( ) ) NEW_LINE def flipTheFlip ( groups , l ) : NEW_LINE INDENT if l == 0 : return 0 NEW_LINE notFlip = True NEW_LINE flip = True NEW_LINE nfgr = [ ] NEW_LINE fgr = [ ] NEW_LINE for outs , targs in groups : NEW_LINE INDENT targ1 = [ x [ 1 : ] for x in targs if x [ 0 ] == '1' ] NEW_LINE targ0 = [ x [ 1 : ] for x in targs if x [ 0 ] == '0' ] NEW_LINE outs0 = [ x [ 1 : ] for x in outs if x [ 0 ] == '0' ] NEW_LINE outs1 = [ x [ 1 : ] for x in outs if x [ 0 ] == '1' ] NEW_LINE if len ( outs0 ) != len ( targ0 ) : notFlip = False NEW_LINE else : NEW_LINE INDENT if outs0 : nfgr . append ( ( outs0 , targ0 ) ) NEW_LINE if outs1 : nfgr . append ( ( outs1 , targ1 ) ) NEW_LINE DEDENT if len ( outs1 ) != len ( targ0 ) : flip = False NEW_LINE else : NEW_LINE INDENT if outs1 : fgr . append ( ( outs1 , targ0 ) ) NEW_LINE if outs0 : fgr . append ( ( outs0 , targ1 ) ) NEW_LINE DEDENT DEDENT resp = 1000000 NEW_LINE if notFlip : NEW_LINE INDENT resp = min ( resp , flipTheFlip ( nfgr , l - 1 ) ) NEW_LINE DEDENT if flip : NEW_LINE INDENT resp = min ( resp , 1 + flipTheFlip ( fgr , l - 1 ) ) NEW_LINE DEDENT return resp NEW_LINE DEDENT for t in xrange ( T ) : NEW_LINE INDENT print " Case ▁ # % d : " % ( t + 1 ) , NEW_LINE N , L = map ( int , raw_input ( ) . split ( ) ) NEW_LINE outlets = raw_input ( ) . split ( ) NEW_LINE targets = raw_input ( ) . split ( ) NEW_LINE flips = flipTheFlip ( [ ( outlets , targets ) ] , L ) NEW_LINE print flips if flips <= L else " NOT ▁ POSSIBLE " NEW_LINE DEDENT

fin = open ( ' A - large . in ' , ' r ' ) NEW_LINE fout = open ( ' out . txt ' , ' w ' ) NEW_LINE t = int ( fin . readline ( ) ) NEW_LINE for casecount in range ( 1 , t + 1 ) : NEW_LINE INDENT n , l = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE outlet = [ list ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE device = [ list ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE device . sort ( ) NEW_LINE smallest = 41 NEW_LINE for func in range ( 0 , n ) : NEW_LINE INDENT switch = [ ] NEW_LINE for i in range ( 0 , l ) : NEW_LINE INDENT if outlet [ 0 ] [ i ] != device [ func ] [ i ] : NEW_LINE INDENT switch . append ( i ) NEW_LINE DEDENT DEDENT output = [ ] NEW_LINE for x in outlet : NEW_LINE INDENT x1 = x . copy ( ) NEW_LINE for y in switch : NEW_LINE INDENT if x1 [ y ] == '0' : NEW_LINE INDENT x1 [ y ] = '1' NEW_LINE DEDENT else : NEW_LINE INDENT x1 [ y ] = '0' NEW_LINE DEDENT DEDENT output . append ( x1 ) NEW_LINE DEDENT output . sort ( ) NEW_LINE if smallest > len ( switch ) and output == device : NEW_LINE INDENT smallest = len ( switch ) NEW_LINE DEDENT DEDENT fout . write ( ' Case ▁ # % d : ▁ ' % casecount ) NEW_LINE if smallest == 41 : NEW_LINE INDENT fout . write ( ' NOT ▁ POSSIBLE \n ' ) NEW_LINE DEDENT else : NEW_LINE INDENT fout . write ( ' % d \n ' % smallest ) NEW_LINE DEDENT DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE

import sys NEW_LINE def F ( s ) : NEW_LINE INDENT re = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT re += ( ord ( s [ i ] ) - ord ( '0' ) ) << i NEW_LINE DEDENT return re NEW_LINE DEDENT def C ( x ) : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return x % 2 + C ( x / 2 ) NEW_LINE DEDENT t = input ( ) NEW_LINE for tt in range ( t ) : NEW_LINE INDENT print >> sys . stderr , " ? ? ? " , tt NEW_LINE n , l = map ( int , raw_input ( ) . split ( ) ) NEW_LINE a = map ( F , raw_input ( ) . split ( ) ) NEW_LINE b = map ( F , raw_input ( ) . split ( ) ) NEW_LINE ans = 2 * l NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT A = [ ] NEW_LINE B = [ ] NEW_LINE for k in range ( n ) : NEW_LINE INDENT A . append ( a [ k ] ^ a [ i ] ) NEW_LINE B . append ( b [ k ] ^ b [ j ] ) NEW_LINE DEDENT A = sorted ( A ) NEW_LINE B = sorted ( B ) NEW_LINE if A == B : NEW_LINE INDENT ans = min ( ans , C ( a [ i ] ^ b [ j ] ) ) NEW_LINE DEDENT DEDENT DEDENT print " Case ▁ # % d : " % ( tt + 1 ) , NEW_LINE if ans == 2 * l : NEW_LINE INDENT print " NOT ▁ POSSIBLE " NEW_LINE DEDENT else : NEW_LINE INDENT print ans NEW_LINE DEDENT DEDENT