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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

import java . io . * ; import java . util . Arrays ; import java . util . Locale ; import java . util . StringTokenizer ; public class A { BufferedReader in ; StringTokenizer str ; PrintWriter out ; String SK ; String next ( ) throws IOException { while ( ( str == null ) || ( ! str . hasMoreTokens ( ) ) ) { SK = in . readLine ( ) ; if ( SK == null ) return null ; str = new StringTokenizer ( SK ) ; } return str . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } class Sob implements Comparable < Sob > { int t ; int p ; int num ; public int compareTo ( Sob o ) { return o . p * t - p * o . t ; } } void solve ( ) throws IOException { int n = nextInt ( ) ; Sob [ ] a = new Sob [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = new Sob ( ) ; a [ i ] . num = i ; } for ( int i = 0 ; i < n ; i ++ ) { a [ i ] . t = nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { a [ i ] . p = nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = 0 ; i < n ; i ++ ) { out . print ( " ▁ " + a [ i ] . num ) ; } out . println ( ) ; } void run ( ) throws IOException { in = new BufferedReader ( new FileReader ( " input . txt " ) ) ; out = new PrintWriter ( " output . txt " ) ; int t = nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { out . print ( " Case ▁ # " + ( i + 1 ) + " : " ) ; solve ( ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new A ( ) . run ( ) ; } }

import java . util . * ; import java . io . * ; import java . math . * ; import java . awt . * ; public class A { public static Comparator < Point > cmp = new Comparator < Point > ( ) { public int compare ( Point a , Point b ) { if ( a . y > b . y ) return - 1 ; if ( a . y < b . y ) return 1 ; return a . x - b . x ; } } ; public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int T = scan . nextInt ( ) ; for ( int ca = 1 ; ca <= T ; ca ++ ) { int n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) scan . nextInt ( ) ; Point [ ] a = new Point [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = new Point ( i , scan . nextInt ( ) ) ; Arrays . sort ( a , cmp ) ; System . out . print ( " Case ▁ # " + ca + " : " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( " ▁ " + a [ i ] . x ) ; System . out . println ( ) ; } } }

import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main implements Runnable { public static void main ( String [ ] args ) throws IOException { new Thread ( new Main ( ) ) . start ( ) ; } public void run ( ) { try { run1 ( ) ; } catch ( IOException e ) { throw new RuntimeException ( ) ; } } public void run1 ( ) throws IOException { Scanner sc = new Scanner ( new FileReader ( " input . txt " ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( " output . txt " ) ) ; int tN = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int tn = 0 ; tn < tN ; tn ++ ) { int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; int [ ] len = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { len [ i ] = sc . nextInt ( ) ; } boolean [ ] oppa = new boolean [ n ] ; pw . print ( " Case ▁ # " + ( tn + 1 ) + " : " ) ; c : for ( int i = 0 ; i < n ; i ++ ) { int be = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ! oppa [ j ] ) { if ( be == - 1 || len [ j ] * p [ be ] > len [ be ] * p [ j ] ) { be = j ; } } } oppa [ be ] = true ; pw . print ( " ▁ " + be ) ; } pw . println ( ) ; } pw . close ( ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class A { static Scanner sc = new Scanner ( System . in ) ; static class Solver { int N ; int [ ] L , P ; void solve ( ) { N = sc . nextInt ( ) ; L = new int [ N ] ; P = new int [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { L [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; ++ i ) { P [ i ] = sc . nextInt ( ) ; } Stage [ ] stages = new Stage [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { stages [ i ] = new Stage ( L [ i ] , P [ i ] , i ) ; } Arrays . sort ( stages ) ; for ( int i = 0 ; i < N ; ++ i ) { System . out . print ( stages [ i ] . idx ) ; if ( i != N - 1 ) { System . out . print ( " ▁ " ) ; } } System . out . println ( ) ; } } static class Stage implements Comparable < Stage > { int l , p , idx ; Stage ( int l , int p , int idx ) { this . l = l ; this . p = p ; this . idx = idx ; } public int compareTo ( Stage o ) { return o . l * o . p - this . l * this . p ; } } public static void main ( String [ ] args ) { int T = sc . nextInt ( ) ; for ( int i = 1 ; i <= T ; ++ i ) { System . out . print ( " Case ▁ # " + i + " : ▁ " ) ; Solver solver = new Solver ( ) ; solver . solve ( ) ; } } }

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

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

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

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

import sys NEW_LINE stdin = sys . stdin NEW_LINE def computeEtries ( p ) : NEW_LINE INDENT pr = p / 100.0 NEW_LINE re = 1 NEW_LINE running = pr NEW_LINE multiplier = 2 NEW_LINE while multiplier < 10000 or multiplier * running > 1e-9 : NEW_LINE INDENT re += multiplier * running NEW_LINE running *= pr NEW_LINE multiplier += 1 NEW_LINE DEDENT return ( 1 - pr ) * re NEW_LINE DEDENT ets = [ computeEtries ( p ) for p in range ( 100 ) ] NEW_LINE T = int ( stdin . readline ( ) ) NEW_LINE for tcase in range ( T ) : NEW_LINE INDENT N = int ( stdin . readline ( ) ) NEW_LINE Ls = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE Ps = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE etries = [ ets [ p ] for p in Ps ] NEW_LINE seq = [ ( index , Ls [ index ] , etries [ index ] ) for index in range ( N ) ] NEW_LINE for k in range ( N ) : NEW_LINE INDENT best = k NEW_LINE for s in range ( k + 1 , N ) : NEW_LINE INDENT in1 = seq [ best ] [ 0 ] NEW_LINE L1 = seq [ best ] [ 1 ] NEW_LINE E1 = seq [ best ] [ 2 ] NEW_LINE in2 = seq [ s ] [ 0 ] NEW_LINE L2 = seq [ s ] [ 1 ] NEW_LINE E2 = seq [ s ] [ 2 ] NEW_LINE extra_if_1_goes_first = ( E2 - 1 ) * E1 * L1 NEW_LINE extra_if_2_goes = ( E1 - 1 ) * E2 * L2 NEW_LINE if abs ( extra_if_1_goes_first - extra_if_2_goes ) < 1e-9 : NEW_LINE INDENT if in2 < in1 : NEW_LINE INDENT best = s NEW_LINE DEDENT DEDENT elif extra_if_2_goes < extra_if_1_goes_first : NEW_LINE INDENT best = s NEW_LINE DEDENT DEDENT swap = seq [ best ] NEW_LINE seq [ best ] = seq [ k ] NEW_LINE seq [ k ] = swap NEW_LINE DEDENT print " Case ▁ # % d : " % ( tcase + 1 ) , NEW_LINE print ' ▁ ' . join ( map ( str , [ seq [ i ] [ 0 ] for i in range ( N ) ] ) ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; public class A { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( " in . txt " ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( " out . txt " ) ) ; int N = Integer . parseInt ( br . readLine ( ) ) ; for ( int pp = 0 ; pp < N ; pp ++ ) { String [ ] ss = br . readLine ( ) . split ( " ▁ " ) ; int d = Integer . parseInt ( ss [ 0 ] ) ; int n = Integer . parseInt ( ss [ 1 ] ) ; double max = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { ss = br . readLine ( ) . split ( " ▁ " ) ; int k = Integer . parseInt ( ss [ 0 ] ) ; int s = Integer . parseInt ( ss [ 1 ] ) ; double time = ( d - k ) / ( ( double ) s ) ; System . out . println ( d + " ▁ " + k + " ▁ " + s + " ▁ " + time ) ; max = Math . max ( max , time ) ; } double ret = d / max ; pw . println ( " Case ▁ # " + ( pp + 1 ) + " : ▁ " + ret ) ; } pw . flush ( ) ; pw . close ( ) ; } }

package year2017 . round1b ; import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; public class CruiseControl { public static void main ( String [ ] args ) throws Exception { File inputFile = new File ( " A - large . in " ) ; Scanner in = new Scanner ( inputFile ) ; File outputFile = new File ( " output . txt " ) ; PrintWriter out = new PrintWriter ( outputFile ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { double D = in . nextDouble ( ) ; int N = in . nextInt ( ) ; double maxTime = 0 ; for ( int n = 0 ; n < N ; n ++ ) { double K = in . nextDouble ( ) ; double S = in . nextDouble ( ) ; double time = ( D - K ) / S ; maxTime = Math . max ( time , maxTime ) ; } double speed = D / maxTime ; out . println ( " Case ▁ # " + ( t + 1 ) + " : ▁ " + speed ) ; } out . close ( ) ; } }

import static java . lang . Double . parseDouble ; import static java . lang . Integer . parseInt ; import static java . lang . Long . parseLong ; import static java . lang . Math . max ; import static java . lang . System . exit ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . util . Locale ; import java . util . StringTokenizer ; public class A { static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; static int test ; static void solve ( ) throws Exception { int d = nextInt ( ) ; int n = nextInt ( ) ; double ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int k = nextInt ( ) ; int s = nextInt ( ) ; ans = max ( ans , ( double ) ( d - k ) / s ) ; } printCase ( ) ; out . printf ( Locale . US , " % .9f \n " , d / ans ) ; } static void printCase ( ) { out . print ( " Case ▁ # " + test + " : ▁ " ) ; } static void printlnCase ( ) { out . println ( " Case ▁ # " + test + " : " ) ; } static int nextInt ( ) throws IOException { return parseInt ( next ( ) ) ; } static long nextLong ( ) throws IOException { return parseLong ( next ( ) ) ; } static double nextDouble ( ) throws IOException { return parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } public static void main ( String [ ] args ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int tests = nextInt ( ) ; for ( test = 1 ; test <= tests ; test ++ ) { solve ( ) ; } in . close ( ) ; out . close ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; exit ( 1 ) ; } } }

package codejam ; import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . nio . file . Files ; import java . nio . file . Paths ; public class Horse { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( " src / codejam / A - large . in " ) ) ; StringBuilder sb = new StringBuilder ( ) ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int t_i = 1 ; t_i <= T ; t_i ++ ) { String [ ] split = br . readLine ( ) . split ( " ▁ " ) ; int D = Integer . parseInt ( split [ 0 ] ) ; int N = Integer . parseInt ( split [ 1 ] ) ; int [ ] k = new int [ N ] ; int [ ] s = new int [ N ] ; double latest = 0 ; for ( int n_i = 0 ; n_i < N ; n_i ++ ) { split = br . readLine ( ) . split ( " ▁ " ) ; k [ n_i ] = Integer . parseInt ( split [ 0 ] ) ; s [ n_i ] = Integer . parseInt ( split [ 1 ] ) ; double time = 1. * ( D - k [ n_i ] ) / s [ n_i ] ; if ( time > latest ) latest = time ; } sb . append ( " Case ▁ # " ) . append ( t_i ) . append ( " : ▁ " ) . append ( D / latest ) . append ( " \n " ) ; } Files . write ( Paths . get ( " src / codejam / horse . out " ) , sb . toString ( ) . getBytes ( ) ) ; System . out . println ( sb . toString ( ) ) ; } }

package Y2017 . r1b ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . io . UnsupportedEncodingException ; import java . util . Scanner ; public class CruiseControl { public static void main ( String [ ] args ) throws FileNotFoundException , UnsupportedEncodingException { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; scanner . nextLine ( ) ; try ( PrintWriter writer = new PrintWriter ( " solution . txt " , " UTF - 8" ) ) { for ( int i = 1 ; i <= n ; ++ i ) { writer . print ( String . format ( " Case ▁ # % d : ▁ " , i ) ) ; solve ( scanner , writer ) ; } } } public static void solve ( Scanner scanner , PrintWriter writer ) { int D = scanner . nextInt ( ) ; int N = scanner . nextInt ( ) ; double duration = 0 ; for ( int i = 0 ; i < N ; ++ i ) { int K = scanner . nextInt ( ) ; int S = scanner . nextInt ( ) ; double d = ( D - K ) / ( ( double ) S ) ; duration = Math . max ( duration , d ) ; } writer . println ( D / duration ) ; } }

def solve ( ) : NEW_LINE INDENT d , n = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 10 ** 100 NEW_LINE for i in range ( n ) : NEW_LINE INDENT k , s = map ( int , input ( ) . split ( ) ) NEW_LINE ans = min ( ans , d * s / ( d - k ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT t = int ( input ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT print ( " Case ▁ # % d : ▁ % .20f " % ( i + 1 , solve ( ) ) ) NEW_LINE DEDENT

def initialize_solver ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT def solve_testcase ( ) : NEW_LINE INDENT d , n = read ( ) NEW_LINE mx = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT k , s = read ( ) NEW_LINE mx = max ( ( d - k ) / s , mx ) NEW_LINE DEDENT return str ( d / mx ) NEW_LINE DEDENT def read ( callback = int , split = True ) : NEW_LINE INDENT if sfile : NEW_LINE INDENT input_line = sfile . readline ( ) . strip ( ) NEW_LINE DEDENT else : NEW_LINE INDENT input_line = input ( ) . strip ( ) NEW_LINE DEDENT if split : NEW_LINE INDENT return list ( map ( callback , input_line . split ( ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return callback ( input_line ) NEW_LINE DEDENT DEDENT def write ( value = " \n " ) : NEW_LINE INDENT if value is None : return NEW_LINE try : NEW_LINE INDENT if not isinstance ( value , str ) : NEW_LINE INDENT value = " ▁ " . join ( map ( str , value ) ) NEW_LINE DEDENT DEDENT except : NEW_LINE INDENT pass NEW_LINE DEDENT if tfile : NEW_LINE INDENT tfile . write ( value ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( value , end = " " ) NEW_LINE DEDENT DEDENT output_format = " Case ▁ # % d : ▁ " NEW_LINE filename = input ( ) . strip ( ) NEW_LINE sfile = None NEW_LINE tfile = None NEW_LINE if filename != " " : NEW_LINE INDENT sfile = open ( filename + " . in " , " r " ) NEW_LINE sfile . seek ( 0 ) NEW_LINE tfile = open ( filename + " . out " , " w " ) NEW_LINE DEDENT if output_format == None : NEW_LINE INDENT solve_testcase ( ) NEW_LINE DEDENT else : NEW_LINE INDENT initialize_solver ( ) NEW_LINE total_cases , = read ( ) NEW_LINE for case_number in range ( 1 , total_cases + 1 ) : NEW_LINE INDENT write ( output_format . replace ( " % d " , str ( case_number ) ) ) NEW_LINE write ( solve_testcase ( ) ) NEW_LINE write ( ) NEW_LINE DEDENT DEDENT if tfile is not None : tfile . close ( ) NEW_LINE

TEST = ' large ' NEW_LINE IN = ' A - { } . in ' . format ( TEST ) NEW_LINE OUT = ' A - { } . out ' . format ( TEST ) NEW_LINE def run ( d , h ) : NEW_LINE INDENT t = max ( ( d - k ) / s for k , s in h ) NEW_LINE return d / t NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT with open ( IN ) as fin , open ( OUT , ' w ' ) as fout : NEW_LINE INDENT t = int ( fin . readline ( ) . strip ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT d , n = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE h = [ tuple ( map ( int , fin . readline ( ) . split ( ) ) ) for i in range ( n ) ] NEW_LINE res = run ( d , h ) NEW_LINE print ( ' Case ▁ # { } : ▁ { } ' . format ( i + 1 , res ) , file = fout ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

from sys import stdin NEW_LINE for cn in xrange ( 1 , 1 + int ( stdin . readline ( ) ) ) : NEW_LINE INDENT ( D , N ) = tuple ( int ( z ) for z in stdin . readline ( ) . split ( ) ) NEW_LINE slowest = 0 NEW_LINE for h in xrange ( N ) : NEW_LINE INDENT ( K , S ) = tuple ( int ( z ) for z in stdin . readline ( ) . split ( ) ) NEW_LINE time = float ( D - K ) / S NEW_LINE slowest = max ( slowest , time ) NEW_LINE DEDENT speed = D / slowest NEW_LINE print " Case ▁ # { } : ▁ { } " . format ( cn , speed ) NEW_LINE DEDENT

with open ( ' A - large . in ' , ' r ' ) as f , open ( ' out . txt ' , ' w ' ) as fout : NEW_LINE INDENT t = int ( f . readline ( ) . strip ( ) ) NEW_LINE for case in range ( 1 , t + 1 ) : NEW_LINE INDENT d , n = [ int ( s ) for s in f . readline ( ) . strip ( ) . split ( ) ] NEW_LINE last_arrive = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT ki , si = [ int ( s ) for s in f . readline ( ) . strip ( ) . split ( ) ] NEW_LINE last_arrive = max ( last_arrive , ( ( d - ki ) / si ) ) NEW_LINE DEDENT print ( ' Case ▁ # % d : ▁ % .6f ' % ( case , d / last_arrive ) , file = fout ) NEW_LINE DEDENT DEDENT


import java . io . * ; import java . util . * ; public class Round0B { int cases ; int count ( String stack ) { int flips = 0 ; for ( int n = 1 ; n < stack . length ( ) ; n ++ ) { if ( stack . charAt ( n - 1 ) != stack . charAt ( n ) ) flips ++ ; } return flips ; } void process ( Scanner scanner , PrintStream out ) throws IOException { cases = scanner . nextInt ( ) ; scanner . nextLine ( ) ; for ( int curCase = 0 ; curCase < cases ; curCase ++ ) { String stack = scanner . nextLine ( ) . trim ( ) ; out . println ( " Case ▁ # " + ( curCase + 1 ) + " : ▁ " + count ( stack + " + " ) ) ; } } Round0B ( ) throws IOException { Scanner in = new Scanner ( new File ( " C : \\ Users \\ Olaf \\ Downloads \\ B - large . in " ) ) ; PrintStream out = new PrintStream ( " out - B - large . txt " ) ; process ( in , out ) ; in . close ( ) ; out . close ( ) ; } public static void main ( String [ ] args ) throws IOException { new Round0B ( ) ; } }

package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; Scanner sin = new Scanner ( System . in ) ; int n = Integer . parseInt ( sin . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sin . next ( ) ; s += ' + ' ; int counter = 0 ; for ( int j = 0 ; j < s . length ( ) - 1 ; j ++ ) { if ( s . charAt ( j ) != s . charAt ( j + 1 ) ) { counter ++ ; } } System . out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + counter ) ; } } }

package gcj2016 . qualif ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class ExoB { public static void main ( final String [ ] args ) { final String base = " / home / jfortin / workspace - gcj / Codejam2016 / q / ExoB / " ; final String input = base + " b1 . in " ; final String output = base + " b1 . out " ; try { final Scanner sc = new Scanner ( new FileReader ( input ) ) ; final PrintWriter pw = new PrintWriter ( output ) ; final int n = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int c = 0 ; c < n ; c ++ ) { System . out . println ( " Test ▁ case ▁ " + ( c + 1 ) + " . . . " ) ; pw . print ( " Case ▁ # " + ( c + 1 ) + " : ▁ " ) ; test ( sc , pw ) ; pw . println ( ) ; } pw . println ( ) ; pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } catch ( final FileNotFoundException ex ) { Logger . getLogger ( ExoB . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } private static void test ( final Scanner sc , final PrintWriter pw ) { String in = sc . next ( ) ; System . out . println ( in ) ; int i = count ( in , in . length ( ) , ' + ' ) ; pw . print ( i ) ; } private static int count ( final String in , final int length , final char c ) { if ( length == 0 ) { return 0 ; } if ( in . charAt ( length - 1 ) == c ) { return count ( in , length - 1 , c ) ; } else { return 1 + count ( in , length - 1 , c == ' + ' ? ' - ' : ' + ' ) ; } } }

import java . awt . * ; import java . awt . event . * ; import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . text . * ; import java . util . * ; import java . util . concurrent . * ; public class B { static BufferedReader br ; static StringTokenizer st ; static PrintWriter pw ; public static void main ( String [ ] args ) throws Exception { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; pw = new PrintWriter ( new BufferedWriter ( new FileWriter ( " b . out " ) ) ) ; final int MAX_CASES = readInt ( ) ; for ( int casenum = 1 ; casenum <= MAX_CASES ; casenum ++ ) { pw . printf ( " Case ▁ # % d : ▁ " , casenum ) ; String s = nextToken ( ) ; boolean [ ] good = new boolean [ s . length ( ) ] ; int ret = 0 ; boolean last = true ; for ( int i = 0 ; i < good . length ; i ++ ) { good [ i ] = s . charAt ( i ) == ' + ' ; if ( i > 0 && last != good [ i ] ) { ret ++ ; } last = good [ i ] ; } if ( ! last ) ret ++ ; pw . println ( ret ) ; } pw . close ( ) ; } public static int readInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } public static long readLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } public static double readDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } public static String nextToken ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { if ( ! br . ready ( ) ) { pw . close ( ) ; System . exit ( 0 ) ; } st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { System . err . println ( e ) ; System . exit ( 1 ) ; } } return st . nextToken ( ) ; } public static String readLine ( ) { st = null ; try { return br . readLine ( ) ; } catch ( IOException e ) { System . err . println ( e ) ; System . exit ( 1 ) ; return null ; } } }

import java . io . * ; import java . util . * ; public class revengepancake { private static InputReader in ; private static PrintWriter out ; public static boolean SUBMIT = true ; public static final String NAME = " B - large " ; private static void main2 ( ) throws IOException { char [ ] s = in . next ( ) . toCharArray ( ) ; int n = s . length ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) count ++ ; } if ( s [ n - 1 ] == ' - ' ) count ++ ; out . println ( count ) ; } public static void main ( String [ ] args ) throws IOException { if ( SUBMIT ) { in = new InputReader ( new FileInputStream ( new File ( NAME + " . in " ) ) ) ; out = new PrintWriter ( new BufferedWriter ( new FileWriter ( NAME + " . out " ) ) ) ; } else { in = new InputReader ( System . in ) ; out = new PrintWriter ( System . out , true ) ; } int numCases = in . nextInt ( ) ; for ( int test = 1 ; test <= numCases ; test ++ ) { out . print ( " Case ▁ # " + test + " : ▁ " ) ; main2 ( ) ; } out . close ( ) ; System . exit ( 0 ) ; } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import sys NEW_LINE with open ( sys . argv [ 1 ] ) as f : NEW_LINE INDENT lines = f . readlines ( ) NEW_LINE DEDENT T = int ( lines [ 0 ] , 10 ) NEW_LINE for tt , l in enumerate ( lines [ 1 : ] ) : NEW_LINE INDENT pancakes = l . strip ( ) NEW_LINE done = False NEW_LINE flips = 0 NEW_LINE while 1 : NEW_LINE INDENT index = pancakes . rfind ( " - " ) NEW_LINE if index == - 1 : NEW_LINE INDENT break NEW_LINE DEDENT flips += 1 NEW_LINE new_cakes = " " NEW_LINE for i in xrange ( index + 1 ) : NEW_LINE INDENT if pancakes [ i ] == " + " : NEW_LINE INDENT new_cakes += " - " NEW_LINE DEDENT elif pancakes [ i ] == " - " : NEW_LINE INDENT new_cakes += " + " NEW_LINE DEDENT else : NEW_LINE INDENT raise Exception ( " wtf " ) NEW_LINE DEDENT DEDENT pancakes = new_cakes + pancakes [ index + 1 : ] NEW_LINE DEDENT print ( " Case ▁ # % d : " % ( tt + 1 ) ) , flips NEW_LINE DEDENT

f = open ( ' C : \\Users\\djspence\\Downloads\\B - large . in ' , ' r ' ) NEW_LINE tries = int ( f . readline ( ) ) NEW_LINE for i in range ( 0 , tries ) : NEW_LINE INDENT pans = f . readline ( ) . strip ( ) NEW_LINE flips = 0 NEW_LINE for j in range ( 1 , len ( pans ) ) : NEW_LINE INDENT if pans [ j ] != pans [ j - 1 ] : NEW_LINE INDENT flips += 1 NEW_LINE DEDENT DEDENT if pans [ len ( pans ) - 1 ] == " - " : NEW_LINE INDENT flips += 1 NEW_LINE DEDENT print ( " Case ▁ # " + str ( i + 1 ) + " : ▁ " + str ( flips ) ) NEW_LINE DEDENT

with open ( ' / home / gauravjs / Documents / Google ▁ Code ▁ Jam / 2016Q / B - large . in ' , ' r ' ) as f : NEW_LINE INDENT cases = int ( f . readline ( ) ) NEW_LINE lines = f . readlines ( ) NEW_LINE DEDENT for i in range ( cases ) : NEW_LINE INDENT n = 0 NEW_LINE if lines [ i ] [ - 2 ] == ' - ' : NEW_LINE INDENT n += 1 NEW_LINE DEDENT s = lines [ i ] [ - 2 ] NEW_LINE for j in range ( len ( lines [ i ] ) - 3 , - 1 , - 1 ) : NEW_LINE INDENT if lines [ i ] [ j ] != s : NEW_LINE INDENT s = lines [ i ] [ j ] NEW_LINE n += 1 NEW_LINE DEDENT DEDENT print " Case ▁ # " + str ( i + 1 ) + " : ▁ " + str ( n ) NEW_LINE DEDENT

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

import collections NEW_LINE import math NEW_LINE import re NEW_LINE import sys NEW_LINE INPUT = " tiny " NEW_LINE INPUT = " B - large . in " NEW_LINE def debug ( * args ) : NEW_LINE INDENT return NEW_LINE sys . stderr . write ( str ( args ) + " \n " ) NEW_LINE DEDENT def do_trial ( s ) : NEW_LINE INDENT count = 0 NEW_LINE last = " + " NEW_LINE for c in reversed ( s ) : NEW_LINE INDENT if c != last : NEW_LINE INDENT count += 1 NEW_LINE DEDENT last = c NEW_LINE DEDENT return count NEW_LINE DEDENT f = file ( INPUT ) NEW_LINE T = int ( f . readline ( ) [ : - 1 ] ) NEW_LINE for i in range ( T ) : NEW_LINE INDENT s = f . readline ( ) [ : - 1 ] NEW_LINE v = do_trial ( s ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i + 1 , v ) NEW_LINE DEDENT


import java . util . * ; class Lawnmower { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; int tests = sc . nextInt ( ) ; for ( int test = 1 ; test <= tests ; ++ test ) { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] lawn = new int [ n ] [ m ] ; int [ ] rowMaxes = new int [ n ] ; int [ ] colMaxes = new int [ m ] ; boolean possible = true ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { int a = sc . nextInt ( ) ; lawn [ i ] [ j ] = a ; rowMaxes [ i ] = Math . max ( a , rowMaxes [ i ] ) ; colMaxes [ j ] = Math . max ( a , colMaxes [ j ] ) ; if ( a > 100 ) { possible = false ; } } } for ( int i = 0 ; i < n & possible ; ++ i ) { for ( int j = 0 ; j < m & possible ; ++ j ) { if ( lawn [ i ] [ j ] < rowMaxes [ i ] && lawn [ i ] [ j ] < colMaxes [ j ] ) { possible = false ; } } } System . out . println ( " Case ▁ # " + test + " : ▁ " + ( possible ? " YES " : " NO " ) ) ; } } }

package lawnmower ; public class Lawnmower { public static String [ ] execute ( String [ ] input ) { String [ ] words = { " NO " , " YES " } ; String [ ] out ; String [ ] splitted ; int n , m ; int [ ] [ ] board ; int result ; int test = 1 ; int ntests ; ntests = Integer . parseInt ( input [ 0 ] ) ; out = new String [ ntests ] ; for ( int i = 1 ; test < 1 + ntests ; ) { splitted = input [ i ++ ] . split ( " \\ s " ) ; n = Integer . parseInt ( splitted [ 0 ] ) ; m = Integer . parseInt ( splitted [ 1 ] ) ; board = new int [ n ] [ m ] ; for ( int j = 0 ; j < n ; j ++ ) { splitted = input [ i ++ ] . split ( " \\ s " ) ; for ( int k = 0 ; k < m ; k ++ ) { board [ j ] [ k ] = Integer . parseInt ( splitted [ k ] ) ; } } result = isFeasible ( board , n , m ) ; out [ test - 1 ] = " Case ▁ # " + test + " : ▁ " + words [ result ] ; System . out . println ( out [ test - 1 ] ) ; test ++ ; } return out ; } private static int isFeasible ( int [ ] [ ] board , int n , int m ) { int [ ] maxrow = new int [ n ] ; int [ ] maxcol = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( board [ i ] [ j ] > maxrow [ i ] ) maxrow [ i ] = board [ i ] [ j ] ; if ( board [ i ] [ j ] > maxcol [ j ] ) maxcol [ j ] = board [ i ] [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( board [ i ] [ j ] < maxrow [ i ] ) if ( board [ i ] [ j ] < maxcol [ j ] ) return 0 ; } } return 1 ; } }

import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Lawnmower { public static boolean check ( int [ ] [ ] map , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { boolean flag = true , flag2 = true ; for ( int k = 0 ; k < N ; k ++ ) { if ( map [ k ] [ j ] > map [ i ] [ j ] ) { flag = false ; break ; } } for ( int k = 0 ; k < M ; k ++ ) { if ( map [ i ] [ k ] > map [ i ] [ j ] ) { flag2 = false ; break ; } } if ( ! flag && ! flag2 ) return false ; } } return true ; } public static void main ( String args [ ] ) throws Exception { Scanner in = new Scanner ( new FileInputStream ( " B - large . in " ) ) ; PrintWriter writer = new PrintWriter ( new FileOutputStream ( " B - large . out " ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int [ ] [ ] map = new int [ N ] [ M ] ; for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < M ; k ++ ) { map [ j ] [ k ] = in . nextInt ( ) ; } } boolean result = check ( map , N , M ) ; writer . write ( " Case ▁ # " + ( i + 1 ) + " : ▁ " ) ; writer . println ( result ? " YES " : " NO " ) ; } in . close ( ) ; writer . close ( ) ; } }

import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class ProblemB { static final String YES = " YES " ; static final String NO = " NO " ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int T = in . nextInt ( ) ; for ( int cn = 1 ; cn <= T ; cn ++ ) { int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int [ ] [ ] a = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { a [ i ] [ j ] = in . nextInt ( ) ; } } out . println ( String . format ( " Case ▁ # % d : ▁ % s " , cn , ( solve ( a ) ? YES : NO ) ) ) ; } out . flush ( ) ; } private static boolean solve ( int [ ] [ ] board ) { int N = board . length ; int M = board [ 0 ] . length ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int a = board [ i ] [ j ] ; int rmax = 0 , cmax = 0 ; for ( int x = 0 ; x < M ; x ++ ) { if ( x != j ) { rmax = Math . max ( rmax , board [ i ] [ x ] ) ; } } for ( int y = 0 ; y < N ; y ++ ) { if ( y != i ) { cmax = Math . max ( cmax , board [ y ] [ j ] ) ; } } if ( rmax > a && cmax > a ) { return false ; } } } return true ; } public static void debug ( Object ... o ) { System . err . println ( Arrays . deepToString ( o ) ) ; } }

import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . util . StringTokenizer ; public class Lawnmower { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( new File ( " in " ) ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( new File ( " out " ) ) ) ; StringTokenizer st ; int T = Integer . parseInt ( br . readLine ( ) ) ; for ( int cn = 1 ; cn <= T ; cn ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int M = Integer . parseInt ( st . nextToken ( ) ) ; int arr [ ] [ ] = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; for ( int j = 0 ; j < M ; j ++ ) { arr [ i ] [ j ] = Integer . parseInt ( st . nextToken ( ) ) ; } } boolean okay = true ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int h = arr [ i ] [ j ] ; boolean ok1 = true ; for ( int k = 0 ; k < N ; k ++ ) ok1 &= arr [ k ] [ j ] <= h ; boolean ok2 = true ; for ( int k = 0 ; k < M ; k ++ ) ok2 &= arr [ i ] [ k ] <= h ; if ( ! ( ok1 || ok2 ) ) okay = false ; } } if ( okay ) bw . append ( " Case ▁ # " + cn + " : ▁ YES \n " ) ; else bw . append ( " Case ▁ # " + cn + " : ▁ NO \n " ) ; } bw . flush ( ) ; } }

def setup ( infile ) : NEW_LINE INDENT return locals ( ) NEW_LINE DEDENT def reader ( testcase , infile , ** ignore ) : NEW_LINE INDENT P = map ( int , infile . next ( ) . split ( ) ) NEW_LINE S = [ map ( int , infile . next ( ) . split ( ) ) for i in range ( P [ 0 ] ) ] NEW_LINE return locals ( ) NEW_LINE DEDENT def solver ( infile , testcase , N = None , P = None , I = None , T = None , S = None , C = None , ** ignore ) : NEW_LINE INDENT import numpypy as np NEW_LINE S = np . array ( S ) NEW_LINE done = np . zeros ( P , dtype = int ) NEW_LINE for row in range ( P [ 0 ] ) : NEW_LINE INDENT m = S [ row ] . max ( ) NEW_LINE done [ row ] [ S [ row ] == m ] = 1 NEW_LINE DEDENT for col in range ( P [ 1 ] ) : NEW_LINE INDENT m = S [ : , col ] . max ( ) NEW_LINE done [ : , col ] [ S [ : , col ] == m ] = 1 NEW_LINE DEDENT res = ' YES ' if done . sum ( ) == P [ 0 ] * P [ 1 ] else ' NO ' NEW_LINE return ' Case ▁ # % s : ▁ % s \n ' % ( testcase , res ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE T = int ( sys . stdin . next ( ) ) NEW_LINE common = setup ( sys . stdin ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT sys . stdout . write ( solver ( ** reader ( t , ** common ) ) ) NEW_LINE DEDENT DEDENT

n = int ( raw_input ( ) ) NEW_LINE for v in range ( n ) : NEW_LINE INDENT board = [ ] NEW_LINE inpline = raw_input ( ) . split ( ' ▁ ' ) NEW_LINE m = int ( inpline [ 0 ] ) NEW_LINE n = int ( inpline [ 1 ] ) NEW_LINE [ board . append ( [ int ( x ) for x in raw_input ( ) . split ( ' ▁ ' ) ] ) for i in range ( m ) ] NEW_LINE bs = sorted ( [ ( i , j ) for i in range ( m ) for j in range ( n ) ] , key = lambda ( i , j ) : board [ i ] [ j ] ) NEW_LINE good = True NEW_LINE for ( i , j ) in bs : NEW_LINE INDENT if board [ i ] [ j ] == ' X ' : continue NEW_LINE if all ( board [ i2 ] [ j ] in [ board [ i ] [ j ] , ' X ' ] for i2 in range ( m ) ) : NEW_LINE INDENT for i2 in range ( m ) : board [ i2 ] [ j ] = ' X ' NEW_LINE DEDENT elif all ( board [ i ] [ j2 ] in [ board [ i ] [ j ] , ' X ' ] for j2 in range ( n ) ) : NEW_LINE INDENT for j2 in range ( n ) : board [ i ] [ j2 ] = ' X ' NEW_LINE DEDENT else : NEW_LINE INDENT good = False NEW_LINE break NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( v + 1 , ' YES ' if good else ' NO ' ) NEW_LINE DEDENT

import sys NEW_LINE import time NEW_LINE timeit = 1 NEW_LINE debugv = 0 NEW_LINE def main ( ) : NEW_LINE INDENT T = int ( sys . stdin . readline ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT doCase ( case ) NEW_LINE DEDENT DEDENT def doCase ( case ) : NEW_LINE INDENT N , M = [ int ( n ) for n in sys . stdin . readline ( ) . split ( ) ] NEW_LINE lawn = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT row = [ int ( n ) for n in sys . stdin . readline ( ) . split ( ) ] NEW_LINE if len ( row ) != M : NEW_LINE INDENT raise Exception ( " incorrect ▁ line ▁ length " ) NEW_LINE DEDENT lawn . append ( row ) NEW_LINE DEDENT lawn_possible = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT row_possible = 1 NEW_LINE for k in range ( N ) : NEW_LINE INDENT if lawn [ k ] [ j ] > lawn [ i ] [ j ] : NEW_LINE INDENT row_possible = 0 NEW_LINE DEDENT DEDENT col_possible = 1 NEW_LINE for k in range ( M ) : NEW_LINE INDENT if lawn [ i ] [ k ] > lawn [ i ] [ j ] : NEW_LINE INDENT col_possible = 0 NEW_LINE DEDENT DEDENT if not ( row_possible or col_possible ) : NEW_LINE INDENT lawn_possible = 0 NEW_LINE DEDENT DEDENT DEDENT result = ' YES ' if lawn_possible else ' NO ' NEW_LINE debug ( " { } \n " . format ( result ) ) NEW_LINE sys . stdout . write ( " Case ▁ # { } : ▁ { } \n " . format ( case , result ) ) NEW_LINE DEDENT def debug ( m ) : NEW_LINE INDENT if debugv : NEW_LINE INDENT sys . stderr . write ( m ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT startTime = time . clock ( ) NEW_LINE main ( ) NEW_LINE if timeit : NEW_LINE INDENT sys . stderr . write ( " Completed ▁ in ▁ { } ▁ seconds . \n " . format ( time . clock ( ) - startTime ) ) NEW_LINE DEDENT DEDENT

import sys NEW_LINE from collections import defaultdict NEW_LINE def readline ( ) : NEW_LINE INDENT s = raw_input ( ) . strip ( ) NEW_LINE while s == " " : NEW_LINE INDENT s = raw_input ( ) . strip ( ) NEW_LINE DEDENT return s NEW_LINE DEDENT def readvals ( ) : NEW_LINE INDENT return map ( int , readline ( ) . split ( ) ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT r , c = readvals ( ) NEW_LINE grid = tuple ( readvals ( ) for i in range ( r ) ) NEW_LINE row_min = tuple ( map ( max , grid ) ) NEW_LINE col_min = tuple ( map ( max , zip ( * grid ) ) ) NEW_LINE for y in range ( r ) : NEW_LINE INDENT for x in range ( c ) : NEW_LINE INDENT if grid [ y ] [ x ] != min ( row_min [ y ] , col_min [ x ] ) : NEW_LINE INDENT return " NO " NEW_LINE DEDENT DEDENT DEDENT return " YES " NEW_LINE DEDENT N = int ( readline ( ) ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT sol = solve ( ) NEW_LINE print ( " Case ▁ # { 0 } : ▁ { 1 } " . format ( i + 1 , sol ) ) NEW_LINE DEDENT

filename = ' B - large . in ' NEW_LINE def getCol ( array , c ) : NEW_LINE INDENT return [ row [ c ] for row in array ] NEW_LINE DEDENT def mowable ( array ) : NEW_LINE INDENT for i , line in enumerate ( array ) : NEW_LINE INDENT for j , col in enumerate ( line ) : NEW_LINE INDENT if ( array [ i ] [ j ] < max ( array [ i ] ) ) and ( array [ i ] [ j ] < max ( getCol ( array , j ) ) ) : NEW_LINE INDENT return ' NO ' NEW_LINE DEDENT DEDENT DEDENT return ' YES ' NEW_LINE DEDENT FILE = open ( filename ) NEW_LINE T = int ( FILE . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT rawLine = FILE . readline ( ) . split ( ' ▁ ' ) NEW_LINE rows , cols = int ( rawLine [ 0 ] ) , int ( rawLine [ 1 ] ) NEW_LINE array = [ 0 ] * rows NEW_LINE for r in range ( 0 , rows ) : NEW_LINE INDENT array [ r ] = [ int ( x ) for x in FILE . readline ( ) . split ( ' ▁ ' ) ] NEW_LINE DEDENT print ( ' Case ▁ # ' + str ( i ) + ' : ▁ ' + mowable ( array ) ) NEW_LINE DEDENT


import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . * ; public class Diamond implements Runnable { final Scanner in ; final PrintWriter out ; public Diamond ( ) throws FileNotFoundException { out = new PrintWriter ( getClass ( ) . getName ( ) . toLowerCase ( ) + " . out " ) ; in = new Scanner ( new File ( getClass ( ) . getName ( ) . toLowerCase ( ) + " . in " ) ) ; } public static void main ( String [ ] args ) { try { new Diamond ( ) . run ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } } public void run ( ) { int tests = in . nextInt ( ) ; in . nextLine ( ) ; for ( int testcase = 1 ; testcase <= tests ; testcase ++ ) { int n = in . nextInt ( ) ; List < List < Integer > > edges = new ArrayList < List < Integer > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { List < Integer > cur = new ArrayList < Integer > ( ) ; int mi = in . nextInt ( ) ; for ( int x = 0 ; x < mi ; x ++ ) { cur . add ( in . nextInt ( ) - 1 ) ; } edges . add ( cur ) ; } boolean path = false ; for ( int st = 0 ; st < n ; st ++ ) { Queue < Integer > q = new ArrayDeque < Integer > ( ) ; Set < Integer > v = new HashSet < Integer > ( ) ; v . add ( st ) ; for ( q . offer ( st ) ; ! q . isEmpty ( ) ; q . poll ( ) ) { int c = q . peek ( ) ; for ( int d : edges . get ( c ) ) { if ( v . contains ( d ) ) { path = true ; continue ; } v . add ( d ) ; q . offer ( d ) ; } } } out . println ( " Case ▁ # " + testcase + " : ▁ " + ( path ? " Yes " : " No " ) ) ; } out . close ( ) ; in . close ( ) ; } }

import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . util . Scanner ; import java . util . logging . Level ; import java . util . logging . Logger ; public class R1CC { static boolean [ ] g ; static int [ ] [ ] p ; static int [ ] d ; public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( new File ( " A - large . in " ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( new File ( " output . out " ) ) ) ; int t = sc . nextInt ( ) ; X : for ( int i = 0 ; i < t ; i ++ ) { bw . write ( " Case ▁ # " + String . valueOf ( i + 1 ) + " : ▁ " ) ; int r = 0 ; int n = sc . nextInt ( ) ; d = new int [ n ] ; p = new int [ n ] [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { d [ j ] = sc . nextInt ( ) ; for ( int k = 0 ; k < d [ j ] ; k ++ ) p [ j ] [ k ] = sc . nextInt ( ) - 1 ; } for ( int j = 0 ; j < n ; j ++ ) { g = new boolean [ n ] ; if ( traverse ( j ) ) { bw . write ( " Yes " ) ; bw . newLine ( ) ; bw . flush ( ) ; continue X ; } } bw . write ( " No " ) ; bw . newLine ( ) ; bw . flush ( ) ; } bw . close ( ) ; } catch ( Exception ex ) { Logger . getLogger ( QA . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } static boolean traverse ( int h ) { for ( int i = 0 ; i < d [ h ] ; i ++ ) { if ( g [ p [ h ] [ i ] ] ) return true ; else g [ p [ h ] [ i ] ] = true ; if ( traverse ( p [ h ] [ i ] ) ) return true ; } return false ; } }

package codejam . round1c_2012 ; import java . io . File ; import java . io . PrintStream ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Deque ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; import java . util . Set ; public class MainA { static char [ ] mapping = new char [ 256 ] ; static List < Set < Integer > > defs ; public static void main ( String [ ] args ) throws Exception { String f = " / home / floris / dev / java / Test / src / codejam / round1c _ 2012 / A - large . in " ; Scanner sc = new Scanner ( new File ( f ) ) ; System . setOut ( new PrintStream ( new File ( f + " . out " ) ) ) ; int T = sc . nextInt ( ) ; for ( int i = 1 ; T -- > 0 ; i ++ ) { defs = new ArrayList < Set < Integer > > ( ) ; int classCount = sc . nextInt ( ) ; for ( int j = 0 ; j < classCount ; j ++ ) { Set < Integer > cur = new HashSet < Integer > ( ) ; int ic = sc . nextInt ( ) ; for ( int k = 0 ; k < ic ; k ++ ) cur . add ( sc . nextInt ( ) - 1 ) ; defs . add ( cur ) ; } System . out . printf ( " Case ▁ # % d : ▁ % s % n " , i , solve ( ) ) ; } } private static String solve ( ) { for ( int i = 0 ; i < defs . size ( ) ; i ++ ) { List < Integer > contained = new ArrayList < Integer > ( ) ; Deque < Integer > d = new ArrayDeque ( ) ; d . addAll ( defs . get ( i ) ) ; contained . addAll ( defs . get ( i ) ) ; contained . add ( i ) ; while ( ! d . isEmpty ( ) ) { int v = d . remove ( ) ; for ( int k : defs . get ( v ) ) { if ( contained . contains ( k ) ) return " Yes " ; d . add ( k ) ; contained . add ( k ) ; } } } return " No " ; } }

import java . io . * ; import java . util . * ; public class A { public static void main ( String args [ ] ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( " A - small - attempt0 . in " ) ) ; PrintWriter out = new PrintWriter ( new FileWriter ( " A - small . out " ) ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < T ; i ++ ) { boolean adj [ ] [ ] = new boolean [ 1005 ] [ 1005 ] ; int N ; String s = in . readLine ( ) ; StringTokenizer st = new StringTokenizer ( s ) ; N = Integer . parseInt ( st . nextToken ( ) ) ; for ( int r = 0 ; r < N ; r ++ ) { s = in . readLine ( ) ; st = new StringTokenizer ( s ) ; int M = Integer . parseInt ( st . nextToken ( ) ) ; for ( int c = 0 ; c < M ; c ++ ) { int d = Integer . parseInt ( st . nextToken ( ) ) - 1 ; adj [ r ] [ d ] = true ; } } boolean ans = false ; for ( int n = 0 ; n < N ; n ++ ) { LinkedList < Integer > q = new LinkedList < Integer > ( ) ; q . add ( n ) ; boolean v [ ] = new boolean [ N ] ; while ( ! q . isEmpty ( ) ) { int x = q . pollFirst ( ) ; if ( v [ x ] ) { ans = true ; break ; } v [ x ] = true ; for ( int m = 0 ; m < N ; m ++ ) { if ( adj [ x ] [ m ] ) { q . addFirst ( m ) ; } } } } out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + ( ans ? " Yes " : " No " ) ) ; } out . close ( ) ; } }

import java . util . ArrayList ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Scanner ; import java . util . Set ; public class Q1 { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int numTests = s . nextInt ( ) ; for ( int test = 0 ; test < numTests ; test ++ ) { System . out . println ( " Case ▁ # " + ( test + 1 ) + " : ▁ " + getResult ( s ) ) ; } } private static String getResult ( Scanner s ) { int numNodes = s . nextInt ( ) ; List < GraphNode > nodes = new ArrayList < GraphNode > ( numNodes ) ; for ( int i = 0 ; i < numNodes ; i ++ ) { nodes . add ( new GraphNode ( ) ) ; } for ( int i = 0 ; i < numNodes ; i ++ ) { int numChildren = s . nextInt ( ) ; for ( int j = 0 ; j < numChildren ; j ++ ) { int child = s . nextInt ( ) ; nodes . get ( child - 1 ) . childNodes . add ( nodes . get ( i ) ) ; } } for ( GraphNode node : nodes ) { if ( node . childNodes . size ( ) > 1 && node . hasDiamond ( ) ) { return " Yes " ; } } return " No " ; } public static class GraphNode { public List < GraphNode > childNodes = new LinkedList < GraphNode > ( ) ; public boolean hasDiamond ( ) { List < GraphNode > foundSoFar = new LinkedList < GraphNode > ( ) ; Set < GraphNode > fastLookup = new HashSet < GraphNode > ( ) ; foundSoFar . add ( this ) ; fastLookup . add ( this ) ; while ( foundSoFar . size ( ) > 0 ) { GraphNode node = foundSoFar . remove ( 0 ) ; for ( GraphNode child : node . childNodes ) { if ( fastLookup . contains ( child ) ) return true ; foundSoFar . add ( child ) ; fastLookup . add ( child ) ; } } return false ; } } }

import operator NEW_LINE import itertools NEW_LINE import functools NEW_LINE import math NEW_LINE from collections import deque NEW_LINE def bfs ( i ) : NEW_LINE INDENT res = False NEW_LINE visited = [ 0 ] * ( N + 1 ) NEW_LINE q = deque ( [ node [ i ] ] ) NEW_LINE while len ( q ) : NEW_LINE INDENT n = q . popleft ( ) NEW_LINE if visited [ n [ 0 ] ] : NEW_LINE INDENT res = True NEW_LINE return res NEW_LINE DEDENT else : NEW_LINE INDENT visited [ n [ 0 ] ] = 1 NEW_LINE DEDENT for x in n [ 1 : ] : NEW_LINE INDENT q . append ( node [ x ] ) NEW_LINE DEDENT DEDENT DEDENT fn = open ( '1 . in ' ) NEW_LINE ofn = open ( '1 . out ' , ' w ' ) NEW_LINE TC = int ( fn . readline ( ) ) NEW_LINE for tc in range ( TC ) : NEW_LINE INDENT N = int ( fn . readline ( ) . strip ( ) ) NEW_LINE node = [ None ] * ( N + 1 ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT r = map ( int , fn . readline ( ) . strip ( ) . split ( ) ) NEW_LINE node [ i ] = [ i ] + r [ 1 : ] NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if bfs ( i ) : NEW_LINE INDENT print >> ofn , ' Case ▁ # { } : ▁ { } ' . format ( tc + 1 , ' Yes ' ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print >> ofn , ' Case ▁ # { } : ▁ { } ' . format ( tc + 1 , ' No ' ) NEW_LINE DEDENT DEDENT

import string NEW_LINE def FindAncestorsDiamond ( i , Parents , Ancestors ) : NEW_LINE INDENT PofI = Parents [ i ] NEW_LINE anI = PofI NEW_LINE for p in PofI : NEW_LINE INDENT if p not in Ancestors : NEW_LINE INDENT if FindAncestorsDiamond ( p , Parents , Ancestors ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT if len ( anI & Ancestors [ p ] ) > 0 : NEW_LINE INDENT return True NEW_LINE DEDENT anI = anI | Ancestors [ p ] NEW_LINE DEDENT Ancestors [ i ] = anI NEW_LINE return False NEW_LINE DEDENT def A ( inpfile ) : NEW_LINE INDENT fin = open ( inpfile , ' r ' ) NEW_LINE fout = open ( inpfile + ' . out ' , ' w ' ) NEW_LINE CNT = int ( fin . readline ( ) ) NEW_LINE for iCNT in xrange ( CNT ) : NEW_LINE INDENT Parents = [ ] NEW_LINE N = int ( fin . readline ( ) ) NEW_LINE for iC in xrange ( 1 , N + 1 ) : NEW_LINE INDENT Parents . append ( set ( map ( lambda x : int ( x ) - 1 , fin . readline ( ) . split ( ) [ 1 : ] ) ) ) NEW_LINE DEDENT Ancestors = { } NEW_LINE Answer = False NEW_LINE for iC in xrange ( N ) : NEW_LINE INDENT if FindAncestorsDiamond ( iC , Parents , Ancestors ) : NEW_LINE INDENT Answer = True NEW_LINE break NEW_LINE DEDENT DEDENT text = ' Case ▁ # ' + str ( iCNT + 1 ) + ' : ▁ ' + ( Answer and ' Yes ' or ' No ' ) NEW_LINE print text NEW_LINE fout . write ( text + ' \n ' ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A ( ' . . \\test\\A - large . in ' ) ; NEW_LINE DEDENT

import itertools NEW_LINE class DiamondFound ( Exception ) : NEW_LINE INDENT pass NEW_LINE DEDENT def find_ancestors ( class_num , inheritance , ancestors ) : NEW_LINE INDENT if ancestors [ class_num ] : NEW_LINE INDENT return NEW_LINE DEDENT direct_fathers = inheritance [ class_num ] NEW_LINE ancestors [ class_num ] . update ( direct_fathers ) NEW_LINE for direct_father in direct_fathers : NEW_LINE INDENT find_ancestors ( direct_father , inheritance , ancestors ) NEW_LINE ancestors_of_direct_father = ancestors [ direct_father ] NEW_LINE before = len ( ancestors [ class_num ] ) NEW_LINE ancestors [ class_num ] . update ( ancestors_of_direct_father ) NEW_LINE after = len ( ancestors [ class_num ] ) NEW_LINE if after - before != len ( ancestors_of_direct_father ) : NEW_LINE INDENT raise DiamondFound ( ) NEW_LINE DEDENT DEDENT DEDENT def solve ( num_of_classes , inheritance ) : NEW_LINE INDENT ancestors = dict ( ( i , set ( ) ) for i in xrange ( 1 , num_of_classes + 1 ) ) NEW_LINE for class_num in inheritance : NEW_LINE INDENT try : NEW_LINE INDENT find_ancestors ( class_num , inheritance , ancestors ) NEW_LINE DEDENT except DiamondFound : NEW_LINE INDENT return ' Yes ' NEW_LINE DEDENT DEDENT return ' No ' NEW_LINE DEDENT def process_files ( in_file , out_file ) : NEW_LINE INDENT num_of_test_cases = int ( in_file . next ( ) . strip ( ) ) NEW_LINE for test_number in xrange ( num_of_test_cases ) : NEW_LINE INDENT num_of_classes = int ( in_file . next ( ) . strip ( ) ) NEW_LINE inheritance = { } NEW_LINE for class_num in xrange ( 1 , num_of_classes + 1 ) : NEW_LINE INDENT params = in_file . next ( ) . strip ( ) . split ( ) NEW_LINE assert len ( params ) - 1 == int ( params [ 0 ] ) NEW_LINE inheritance [ class_num ] = [ int ( i ) for i in params [ 1 : ] ] NEW_LINE DEDENT result = solve ( num_of_classes , inheritance ) NEW_LINE out_file . write ( ' Case ▁ # % d : ▁ % s \n ' % ( test_number + 1 , result ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT with open ( ' A - large . in ' , ' rb ' ) as in_file : NEW_LINE INDENT with open ( ' A - large . out ' , ' wb ' ) as out_file : NEW_LINE INDENT process_files ( in_file , out_file ) NEW_LINE DEDENT DEDENT DEDENT

import sys NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE def get ( n , graph ) : NEW_LINE INDENT visited = [ False ] * n NEW_LINE order = [ ] NEW_LINE def dfs ( now ) : NEW_LINE INDENT if visited [ now ] : return NEW_LINE visited [ now ] = True NEW_LINE for x in graph [ now ] : NEW_LINE INDENT dfs ( x ) NEW_LINE DEDENT order . append ( now ) NEW_LINE DEDENT for x in xrange ( n ) : NEW_LINE INDENT dfs ( x ) NEW_LINE DEDENT def check ( now ) : NEW_LINE INDENT checked [ now ] = True NEW_LINE if visited [ now ] : return True NEW_LINE visited [ now ] = True NEW_LINE for x in graph [ now ] : NEW_LINE INDENT if check ( x ) : return True NEW_LINE DEDENT return False NEW_LINE DEDENT checked = [ False ] * n NEW_LINE for x in reversed ( order ) : NEW_LINE INDENT visited = [ False ] * n NEW_LINE if not checked [ x ] and check ( x ) : return ' Yes ' NEW_LINE DEDENT return ' No ' NEW_LINE DEDENT t = input ( ) NEW_LINE for x in xrange ( t ) : NEW_LINE INDENT n = input ( ) NEW_LINE graph = [ [ ] for i in xrange ( n ) ] NEW_LINE for y in xrange ( n ) : NEW_LINE INDENT nums = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE for z in nums [ 1 : ] : NEW_LINE INDENT graph [ y ] . append ( z - 1 ) NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( x + 1 , get ( n , graph ) ) NEW_LINE DEDENT

def iterative_dfs ( graph , start , path = [ ] ) : NEW_LINE INDENT q = [ start ] NEW_LINE while q : NEW_LINE INDENT v = q . pop ( 0 ) NEW_LINE if v not in path : NEW_LINE INDENT path = path + [ v ] NEW_LINE q = graph [ v ] + q NEW_LINE DEDENT DEDENT return path NEW_LINE DEDENT def iterative_bfs ( graph , start , path = [ ] ) : NEW_LINE INDENT q = [ start ] NEW_LINE while q : NEW_LINE INDENT v = q . pop ( 0 ) NEW_LINE if not v in path : NEW_LINE INDENT path = path + [ v ] NEW_LINE q = q + graph [ v ] NEW_LINE DEDENT DEDENT return path NEW_LINE DEDENT T = int ( raw_input ( ) ) NEW_LINE for t in range ( 1 , T + 1 ) : NEW_LINE INDENT N = int ( raw_input ( ) ) NEW_LINE G = dict ( ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT G [ i ] = [ ] NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT line = map ( int , raw_input ( ) . split ( ) ) [ 1 : ] NEW_LINE for j in line : NEW_LINE INDENT G [ i ] . append ( j ) NEW_LINE DEDENT DEDENT parents = dict ( ) NEW_LINE for i in G : NEW_LINE INDENT parents [ i ] = set ( iterative_bfs ( G , i , [ ] ) ) NEW_LINE DEDENT diamond = False NEW_LINE for node in G : NEW_LINE INDENT if diamond : NEW_LINE INDENT break NEW_LINE DEDENT visited = set ( ) NEW_LINE for par in G [ node ] : NEW_LINE INDENT if diamond : NEW_LINE INDENT break NEW_LINE DEDENT for x in parents [ par ] : NEW_LINE INDENT if x in visited : NEW_LINE INDENT diamond = True NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT visited . add ( x ) NEW_LINE DEDENT DEDENT DEDENT DEDENT print " Case ▁ # { 0 } : ▁ { 1 } " . format ( t , " Yes " if diamond else " No " ) NEW_LINE DEDENT


import java . util . Scanner ; public class iCode2012OutofGas { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int index = 1 ; index <= T ; index ++ ) { System . out . println ( " Case ▁ # " + index + " : " ) ; double D = in . nextDouble ( ) ; int N = in . nextInt ( ) ; int A = in . nextInt ( ) ; double [ ] time = new double [ N + 1 ] ; double [ ] pos = new double [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { time [ i ] = in . nextDouble ( ) ; pos [ i ] = in . nextDouble ( ) ; } for ( int acc = 0 ; acc < A ; acc ++ ) { double a = in . nextDouble ( ) ; double startmovingat = 0 ; for ( int i = 1 ; i < N ; i ++ ) { startmovingat = Math . max ( startmovingat , time [ i ] - Math . sqrt ( 2 * pos [ i ] / a ) ) ; } double effectivetime = time [ N - 1 ] + ( time [ N ] - time [ N - 1 ] ) / ( pos [ N ] - pos [ N - 1 ] ) * ( D - pos [ N - 1 ] ) ; startmovingat = Math . max ( startmovingat , effectivetime - Math . sqrt ( 2 * D / a ) ) ; System . out . println ( Math . max ( effectivetime , startmovingat + Math . sqrt ( 2 * D / a ) ) ) ; } } } }

import java . util . Scanner ; public class Gas { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . printf ( " Case ▁ # % d : \n " , C ) ; double D = sc . nextDouble ( ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; if ( N == 1 ) { sc . nextDouble ( ) ; sc . nextDouble ( ) ; for ( int i = 0 ; i < A ; i ++ ) { double a = sc . nextDouble ( ) ; System . out . println ( Math . sqrt ( 2 * D / a ) ) ; } continue ; } double t1 = sc . nextDouble ( ) ; double d1 = sc . nextDouble ( ) ; double t2 = sc . nextDouble ( ) ; double d2 = sc . nextDouble ( ) ; double v = ( d2 - d1 ) / t2 ; for ( int i = 0 ; i < A ; i ++ ) { double a = sc . nextDouble ( ) ; double t_meet = ( v + Math . sqrt ( v * v + 2 * a * d1 ) ) / a ; double d_meet = d1 + v * t_meet ; if ( d_meet >= D ) { System . out . println ( Math . sqrt ( 2 * D / a ) ) ; } else { System . out . println ( t_meet + ( D - d_meet ) / v ) ; } } } } }

package round1c ; import java . util . Locale ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Locale . setDefault ( Locale . ENGLISH ) ; Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { double d = sc . nextDouble ( ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; double times [ ] = new double [ n ] ; double positions [ ] = new double [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { times [ j ] = sc . nextDouble ( ) ; positions [ j ] = sc . nextDouble ( ) ; } System . out . println ( " Case ▁ # " + ( i + 1 ) + " : " ) ; for ( int j = 0 ; j < a ; j ++ ) { double acc = sc . nextDouble ( ) ; double otherTime = n == 1 ? 0 : ( d - positions [ 0 ] ) / ( positions [ 1 ] - positions [ 0 ] ) * ( times [ 1 ] - times [ 0 ] ) + times [ 0 ] ; double myTime = Math . sqrt ( d * 2 / acc ) ; System . out . println ( " " + Math . max ( otherTime , myTime ) ) ; } } } }

import java . util . * ; import java . io . * ; public class B { public static void main ( String [ ] args ) throws Exception { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; double D ; int N , A ; for ( int caseNo = 1 ; caseNo <= T ; caseNo ++ ) { D = in . nextDouble ( ) ; N = in . nextInt ( ) ; A = in . nextInt ( ) ; double anotherVelocity ; double [ ] t = new double [ N ] ; double [ ] x = new double [ N ] ; double minTime = 0 ; for ( int i = 0 ; i < N ; i ++ ) { t [ i ] = in . nextDouble ( ) ; x [ i ] = in . nextDouble ( ) ; } if ( N == 2 ) { anotherVelocity = ( x [ 1 ] - x [ 0 ] ) / ( t [ 1 ] - t [ 0 ] ) ; minTime = ( D - x [ 0 ] ) / anotherVelocity + t [ 0 ] ; } System . out . println ( " Case ▁ # " + caseNo + " : " ) ; for ( int i = 0 ; i < A ; i ++ ) { double a = in . nextDouble ( ) ; if ( N == 1 ) { System . out . printf ( " % .7f \n " , Math . sqrt ( 2 * D / a ) ) ; } else { System . out . printf ( " % .7f \n " , Math . max ( Math . sqrt ( 2 * D / a ) , minTime ) ) ; } } } } }

import os , sys , math NEW_LINE inFile = None NEW_LINE outFile = None NEW_LINE def printAnswer ( case , answer ) : NEW_LINE INDENT outFile . write ( ' Case ▁ # { 0 } : ▁ { 1 } \n ' . format ( case + 1 , answer ) ) NEW_LINE DEDENT def solveSimple ( tc , a , d ) : NEW_LINE INDENT t = math . sqrt ( 2.0 * d / a ) NEW_LINE if t < tc : NEW_LINE INDENT t = tc NEW_LINE DEDENT outFile . write ( ' { 0 } \n ' . format ( t ) ) NEW_LINE DEDENT def solveCase ( caseNo ) : NEW_LINE INDENT ( d , n , a ) = inFile . readline ( ) . strip ( ) . split ( ) NEW_LINE d = float ( d ) NEW_LINE n = int ( n ) NEW_LINE a = int ( a ) NEW_LINE printAnswer ( caseNo , ' ' ) NEW_LINE xc = d + 100.0 NEW_LINE tc = 0 NEW_LINE if n == 1 : NEW_LINE INDENT ( t0 , x0 ) = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE if x0 > d + ( 0.00000001 ) : NEW_LINE INDENT tc = 0 NEW_LINE DEDENT else : NEW_LINE INDENT tc = t0 NEW_LINE print tc NEW_LINE DEDENT DEDENT if n == 2 : NEW_LINE INDENT ( t0 , x0 ) = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE ( t1 , x1 ) = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE vc = ( x1 - x0 ) / ( t1 - t0 ) NEW_LINE if x1 > d : NEW_LINE INDENT tc = t0 + ( d - x0 ) / vc NEW_LINE DEDENT else : NEW_LINE INDENT tc = t1 NEW_LINE DEDENT DEDENT av = map ( float , inFile . readline ( ) . strip ( ) . split ( ) ) NEW_LINE for a in av : NEW_LINE INDENT solveSimple ( tc , a , d ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT cases = int ( inFile . readline ( ) . strip ( ) ) NEW_LINE for case in range ( cases ) : NEW_LINE INDENT solveCase ( case ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT inFile = open ( ' in . txt ' , ' rt ' ) NEW_LINE outFile = open ( ' out . txt ' , ' wt ' ) NEW_LINE main ( ) NEW_LINE DEDENT

from math import * NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for tInput in xrange ( 1 , T + 1 ) : NEW_LINE INDENT line = raw_input ( ) . split ( ) NEW_LINE D = float ( line [ 0 ] ) NEW_LINE N , A = int ( line [ 1 ] ) , int ( line [ 2 ] ) NEW_LINE ts = [ 0 ] * N NEW_LINE xs = [ 0 ] * N NEW_LINE for i in xrange ( N ) : NEW_LINE INDENT line = raw_input ( ) . split ( ) NEW_LINE ts [ i ] , xs [ i ] = float ( line [ 0 ] ) , float ( line [ 1 ] ) NEW_LINE DEDENT accelerations = map ( float , raw_input ( ) . split ( ) ) NEW_LINE print " Case ▁ # % d : " % tInput NEW_LINE c = xs [ 0 ] NEW_LINE if N == 1 : v0 = 0 NEW_LINE else : v0 = ( xs [ 1 ] - xs [ 0 ] ) / ( ts [ 1 ] - ts [ 0 ] ) NEW_LINE if v0 == 0 : NEW_LINE INDENT for a in accelerations : NEW_LINE INDENT print sqrt ( 2 * D / a ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT t2 = ( D - c ) / v0 ; NEW_LINE for a in accelerations : NEW_LINE INDENT t2star = ( v0 + sqrt ( v0 * v0 + 2 * a * c ) ) / a NEW_LINE if a < ( 2 * t2 * v0 + 2 * c ) / ( t2 * t2 ) or v0 > a * t2 : print sqrt ( 2 * D / a ) NEW_LINE else : print t2 NEW_LINE DEDENT DEDENT DEDENT

inp = open ( ' . / B - large . in ' , ' r ' ) NEW_LINE outp = open ( ' . / B . out ' , ' w ' ) NEW_LINE T = int ( inp . readline ( ) ) NEW_LINE def solve ( i ) : NEW_LINE INDENT I = inp . readline ( ) . replace ( ' \n ' , ' ' ) . split ( ' ▁ ' ) NEW_LINE D = float ( I [ 0 ] ) NEW_LINE N = int ( I [ 1 ] ) NEW_LINE A = int ( I [ 2 ] ) NEW_LINE Ns = [ ] NEW_LINE for n in range ( N ) : NEW_LINE INDENT Ns . append ( [ float ( x ) for x in inp . readline ( ) . replace ( ' \n ' , ' ' ) . split ( ' ▁ ' ) ] ) NEW_LINE if Ns [ n ] [ 1 ] > D : NEW_LINE INDENT if n != 0 : Ns [ n ] [ 0 ] = Ns [ n - 1 ] [ 0 ] + ( D - Ns [ n - 1 ] [ 1 ] ) / ( Ns [ n ] [ 1 ] - Ns [ n - 1 ] [ 1 ] ) * ( Ns [ n ] [ 0 ] - Ns [ n - 1 ] [ 0 ] ) NEW_LINE Ns [ n ] [ 1 ] = D NEW_LINE DEDENT DEDENT As = [ float ( x ) for x in inp . readline ( ) . replace ( ' \n ' , ' ' ) . split ( ' ▁ ' ) ] NEW_LINE Mx = [ 0 ] * A NEW_LINE for n in range ( N ) : NEW_LINE INDENT for a in range ( A ) : NEW_LINE INDENT Mx [ a ] = max ( Mx [ a ] , Ns [ n ] [ 0 ] - ( 2 * Ns [ n ] [ 1 ] / As [ a ] ) ** 0.5 ) NEW_LINE DEDENT DEDENT outp . write ( ' Case ▁ # ' + str ( i ) + ' : \n ' ) NEW_LINE for a in range ( A ) : NEW_LINE INDENT x = ( 2 * D / As [ a ] ) ** 0.5 + Mx [ a ] NEW_LINE outp . write ( str ( x ) + ' \n ' ) NEW_LINE DEDENT DEDENT for k in range ( T ) : NEW_LINE INDENT solve ( k + 1 ) NEW_LINE DEDENT inp . close ( ) NEW_LINE outp . close ( ) NEW_LINE

import sys NEW_LINE from fractions import Fraction NEW_LINE from math import sqrt NEW_LINE line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == 1 NEW_LINE ntc = int ( fields [ 0 ] ) NEW_LINE def solve ( d , a , other_car ) : NEW_LINE INDENT wait_time = Fraction ( 0 ) NEW_LINE first = True NEW_LINE for time , distance in other_car : NEW_LINE INDENT if distance > d : NEW_LINE INDENT if first : NEW_LINE INDENT break NEW_LINE DEDENT time = last_time + ( time - last_time ) * ( d - last_distance ) / ( distance - last_distance ) NEW_LINE distance = d NEW_LINE DEDENT first = False NEW_LINE arrival_time = sqrt ( 2 * distance / a ) NEW_LINE if arrival_time < time : NEW_LINE INDENT cur_wait_time = time - arrival_time NEW_LINE DEDENT else : NEW_LINE INDENT cur_wait_time = Fraction ( 0 ) NEW_LINE DEDENT if cur_wait_time > wait_time : NEW_LINE INDENT wait_time = cur_wait_time NEW_LINE DEDENT last_time , last_distance = time , distance NEW_LINE DEDENT arrival_time = sqrt ( 2 * d / a ) NEW_LINE return wait_time + arrival_time NEW_LINE DEDENT for tc in range ( 1 , ntc + 1 ) : NEW_LINE INDENT line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == 3 NEW_LINE d = Fraction ( fields [ 0 ] ) NEW_LINE n = int ( fields [ 1 ] ) NEW_LINE a = int ( fields [ 2 ] ) NEW_LINE other_car = [ ] NEW_LINE for _ in range ( n ) : NEW_LINE INDENT line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == 2 NEW_LINE time = Fraction ( fields [ 0 ] ) NEW_LINE distance = Fraction ( fields [ 1 ] ) NEW_LINE other_car . append ( ( time , distance ) ) NEW_LINE DEDENT line = sys . stdin . readline ( ) NEW_LINE fields = line . split ( ) NEW_LINE assert len ( fields ) == a NEW_LINE print ( ' Case ▁ # { 0 } : ' . format ( tc ) ) NEW_LINE for i in range ( a ) : NEW_LINE INDENT accel = Fraction ( fields [ i ] ) NEW_LINE ans = solve ( d , accel , other_car ) NEW_LINE print ( ans ) NEW_LINE DEDENT DEDENT

import sys NEW_LINE import re NEW_LINE import math NEW_LINE import fractions NEW_LINE f = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE num = int ( f . readline ( ) ) NEW_LINE for z in range ( num ) : NEW_LINE INDENT d , n , m = f . readline ( ) . split ( ) NEW_LINE d = float ( d ) NEW_LINE n = int ( n ) NEW_LINE m = int ( m ) NEW_LINE tx = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT tx . append ( [ float ( x ) for x in f . readline ( ) . split ( ) ] ) NEW_LINE DEDENT tx . sort ( ) NEW_LINE a = [ float ( x ) for x in f . readline ( ) . split ( ) ] NEW_LINE if len ( tx ) > 1 : NEW_LINE INDENT tf = tx [ 0 ] [ 0 ] + ( d - tx [ 0 ] [ 1 ] ) * ( tx [ 1 ] [ 0 ] - tx [ 0 ] [ 0 ] ) / ( tx [ 1 ] [ 1 ] - tx [ 0 ] [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT tf = 0 NEW_LINE DEDENT print ' Case ▁ # { } : ' . format ( z + 1 ) NEW_LINE for x in a : NEW_LINE INDENT print max ( math . sqrt ( 2 * d / x ) , tf ) NEW_LINE DEDENT sys . stdout . flush ( ) NEW_LINE DEDENT