import java . util . * ; import java . io . * ; import java . math . * ; public class a { static InputReader in ; static PrintWriter out ; public static void main ( String args [ ] ) { in = new InputReader ( System . in ) ; out = new PrintWriter ( System . out ) ; int n = Integer . valueOf ( in . next ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { out . printf ( " Case ▁ # % d : ▁ % s \n " , i , solve ( ) ) ; } out . close ( ) ; } static BigInteger solve ( ) { BigInteger r = new BigInteger ( in . next ( ) ) ; BigInteger t = new BigInteger ( in . next ( ) ) ; BigInteger x = new BigInteger ( "0" ) ; BigInteger y = new BigInteger ( "2000000000000000000" ) ; BigInteger ans = new BigInteger ( "0" ) ; while ( x . compareTo ( y ) != 1 ) { BigInteger m = x . add ( y ) . shiftRight ( 1 ) ; BigInteger tmp = m . multiply ( r ) . shiftLeft ( 1 ) . add ( m . multiply ( m . multiply ( m ) . shiftLeft ( 2 ) . subtract ( BigInteger . ONE ) ) . divide ( new BigInteger ( "3" ) ) ) . subtract ( m . subtract ( BigInteger . ONE ) . shiftLeft ( 1 ) . multiply ( m ) . multiply ( m . shiftLeft ( 1 ) . subtract ( BigInteger . ONE ) ) . divide ( new BigInteger ( "3" ) ) ) ; if ( tmp . compareTo ( t ) != 1 ) { ans = m ; x = m . add ( BigInteger . ONE ) ; } else y = m . subtract ( BigInteger . ONE ) ; } return ans ; } } class InputReader { StringTokenizer tokenizer ; BufferedReader reader ; public InputReader ( InputStream stream ) { tokenizer = null ; reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException E ) { throw new RuntimeException ( E ) ; } } return tokenizer . nextToken ( ) ; } }

import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; public class R1A { public static void main ( String [ ] args ) { String prblm = " A " ; boolean fl = true ; String filein = prblm + " - " + ( ( fl ) ? " large " : " small " ) + " . in . txt " ; String fileout = prblm + " - " + ( ( fl ) ? " large " : " small " ) + " . out . txt " ; try { BufferedReader fr = new BufferedReader ( new FileReader ( filein ) ) ; BufferedWriter fw = new BufferedWriter ( new FileWriter ( fileout ) ) ; String s = fr . readLine ( ) ; int T = Integer . parseInt ( s ) ; for ( int i = 1 ; i <= T ; i ++ ) { s = fr . readLine ( ) ; String [ ] tok = s . split ( " ▁ " ) ; long r = Long . parseLong ( tok [ 0 ] ) ; long t = Long . parseLong ( tok [ 1 ] ) ; long mn = 0 , mx = 2000000000l ; while ( mx - mn > 0 ) { long v = ( mn + mx + 1 ) / 2 ; if ( Long . MAX_VALUE / ( 2 * r + 2 * v - 1 ) < v || v * ( 2 * r + 2 * v - 1 ) > t ) mx = v - 1 ; else mn = v ; } System . out . println ( mn ) ; fw . write ( " Case ▁ # " + i + " : ▁ " + mn + " \n " ) ; } fr . close ( ) ; fw . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } }

import java . math . BigInteger ; import java . util . Scanner ; public class A { static BigInteger B ( long x ) { return BigInteger . valueOf ( x ) ; } static BigInteger r ; static BigInteger f ( long guess ) { BigInteger x = B ( guess ) ; BigInteger two_x_minus_one = x . multiply ( B ( 2 ) ) . subtract ( B ( 1 ) ) ; return B ( 2 ) . multiply ( x ) . multiply ( r ) . add ( x . multiply ( two_x_minus_one ) ) ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { r = BigInteger . valueOf ( in . nextLong ( ) ) ; BigInteger t = BigInteger . valueOf ( in . nextLong ( ) ) ; long lo = 0 ; long hi = t . longValue ( ) ; while ( lo < hi ) { long mid = ( lo + hi + 1 ) / 2 ; BigInteger score = f ( mid ) ; if ( score . compareTo ( t ) > 0 ) hi = mid - 1 ; else lo = mid ; } System . out . printf ( " Case ▁ # % d : ▁ % d \n " , cas , lo ) ; } } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . math . BigInteger ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner scan = new Scanner ( System . in ) ; BigInteger TWO = BigInteger . valueOf ( 2 ) ; BigInteger FOUR = BigInteger . valueOf ( 4 ) ; int cases = scan . nextInt ( ) ; BigInteger r , t , res ; PrintStream outfile = new PrintStream ( " C - large . out . txt " ) ; for ( int c = 1 ; c <= cases ; c ++ ) { r = scan . nextBigInteger ( ) ; t = scan . nextBigInteger ( ) ; res = r . multiply ( r ) . subtract ( r ) ; res = res . add ( t . multiply ( TWO ) ) ; res = res . multiply ( FOUR ) . add ( BigInteger . ONE ) ; res = bigIntSqRootFloor ( res ) ; res = res . subtract ( r . mod ( TWO ) . equals ( BigInteger . ZERO ) ? BigInteger . valueOf ( 3 ) : BigInteger . valueOf ( 5 ) ) ; res = res . divide ( FOUR ) ; res = res . subtract ( r . divide ( TWO ) ) . add ( BigInteger . ONE ) ; outfile . println ( " Case ▁ # " + c + " : ▁ " + res . toString ( ) ) ; } } public static BigInteger bigIntSqRootFloor ( BigInteger x ) throws IllegalArgumentException { if ( x . compareTo ( BigInteger . ZERO ) < 0 ) { throw new IllegalArgumentException ( " Negative ▁ argument . " ) ; } if ( x == BigInteger . ZERO || x == BigInteger . ONE ) { return x ; } BigInteger two = BigInteger . valueOf ( 2L ) ; BigInteger y ; for ( y = x . divide ( two ) ; y . compareTo ( x . divide ( y ) ) > 0 ; y = ( ( x . divide ( y ) ) . add ( y ) ) . divide ( two ) ) ; return y ; } }

import java . util . * ; import java . lang . * ; import java . math . * ; import java . io . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; public class A { Scanner sc = new Scanner ( System . in ) ; int INF = 1 << 28 ; double EPS = 1e-9 ; int caze , T ; long r , t ; void run ( ) { T = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( caze = 1 ; caze <= T ; caze ++ ) { r = sc . nextLong ( ) ; t = sc . nextLong ( ) ; solveSmall ( ) ; } } void solveSmall ( ) { long left = 0 , right = ( long ) 1e18 ; for ( ; right - left > 1 ; ) { long mid = ( left + right ) / 2 ; boolean ok = ( 2 * mid + 2 * r - 1 ) <= t / mid ; if ( ok ) { left = mid ; } else { right = mid ; } } answer ( " " + left ) ; } void solveLarge ( ) { } void answer ( String s ) { println ( " Case ▁ # " + caze + " : ▁ " + s ) ; } void println ( String s ) { System . out . println ( s ) ; } void print ( String s ) { System . out . print ( s ) ; } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new A ( ) . run ( ) ; } }

def check ( R , t , n ) : NEW_LINE INDENT a1 = R * 2 - 1 NEW_LINE an = a1 + 4 * ( n - 1 ) NEW_LINE return ( a1 + an ) * n <= t * 2 NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT R , t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE R += 1 NEW_LINE l = 1 NEW_LINE r = 10 ** 18 NEW_LINE while l + 1 < r : NEW_LINE INDENT m = ( l + r ) / 2 NEW_LINE if check ( R , t , m ) : NEW_LINE INDENT l = m NEW_LINE DEDENT else : NEW_LINE INDENT r = m NEW_LINE DEDENT DEDENT return l NEW_LINE DEDENT for i in xrange ( input ( ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( i + 1 , solve ( ) ) NEW_LINE DEDENT

import sys NEW_LINE lc = 0 NEW_LINE for line in sys . stdin : NEW_LINE INDENT tok = line . split ( ) NEW_LINE if len ( tok ) == 1 : continue NEW_LINE lc += 1 NEW_LINE r , t = map ( int , tok ) NEW_LINE lo = 0 NEW_LINE hi = t NEW_LINE while hi - lo > 1 : NEW_LINE INDENT m = ( lo + hi ) / 2 ; NEW_LINE if 2 * m * r + ( 1 + 4 * m - 3 ) / 2 * m <= t : lo = m NEW_LINE else : hi = m NEW_LINE DEDENT print " Case ▁ # { 0 } : ▁ { 1 } " . format ( lc , lo ) NEW_LINE DEDENT

import os , sys , math NEW_LINE def solve_slow ( r , t ) : NEW_LINE INDENT rings = 0 NEW_LINE while True : NEW_LINE INDENT t -= ( 2 * r + 1 ) NEW_LINE if t < 0 : NEW_LINE INDENT return rings NEW_LINE DEDENT rings += 1 NEW_LINE if t == 0 : NEW_LINE INDENT return rings NEW_LINE DEDENT r += 2 NEW_LINE DEDENT return rings NEW_LINE DEDENT def paint_needed ( r , n ) : NEW_LINE INDENT return 2 * n * n + ( 2 * r - 1 ) * n NEW_LINE DEDENT def solve_fast ( r , t ) : NEW_LINE INDENT n = math . floor ( ( - 1 * ( 2 * r - 1 ) + math . sqrt ( ( 2 * r - 1 ) * ( 2 * r - 1 ) + 4 * 2 * t ) ) / 4 ) NEW_LINE n = int ( n ) NEW_LINE if paint_needed ( r , n ) > t : NEW_LINE INDENT return n - 1 NEW_LINE DEDENT return n NEW_LINE DEDENT def solve_bin_search ( r , t ) : NEW_LINE INDENT lower_bound = 1 NEW_LINE upper_bound = t NEW_LINE while ( lower_bound + 1 ) < upper_bound : NEW_LINE INDENT mid = int ( ( lower_bound + upper_bound ) / 2 ) NEW_LINE if paint_needed ( r , mid ) > t : NEW_LINE INDENT upper_bound = mid NEW_LINE DEDENT else : NEW_LINE INDENT lower_bound = mid NEW_LINE DEDENT DEDENT return lower_bound NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT ( r , t ) = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE answer = solve_bin_search ( r , t ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT

T = int ( raw_input ( ) ) NEW_LINE def area ( r , ncircle ) : NEW_LINE INDENT return ( ( 2 * r + 1 ) + ( 2 * r + 4 * ( ncircle ) - 3 ) ) * ncircle / 2 NEW_LINE DEDENT for case in xrange ( T ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % ( case + 1 ) , NEW_LINE r , t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE low = 1 NEW_LINE high = 10000000000000000 NEW_LINE while high - low > 1 : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if area ( r , mid ) <= t : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT print low NEW_LINE DEDENT

from functools import * NEW_LINE inf = open ( ' A - large . in ' ) NEW_LINE ouf = open ( ' output . txt ' , ' w ' ) NEW_LINE input = lambda : inf . readline ( ) . strip ( ) NEW_LINE print = partial ( print , file = ouf ) NEW_LINE def solve ( ) : NEW_LINE INDENT r , t = map ( int , input ( ) . split ( ) ) NEW_LINE le = 1 NEW_LINE ri = 10 ** 18 NEW_LINE while le + 1 < ri : NEW_LINE INDENT m = ( le + ri ) // 2 NEW_LINE if ( 2 * r + 1 ) * m + 2 * ( m - 1 ) * m <= t : NEW_LINE INDENT le = m NEW_LINE DEDENT else : NEW_LINE INDENT ri = m NEW_LINE DEDENT DEDENT print ( le ) NEW_LINE DEDENT tests = int ( input ( ) ) NEW_LINE for z in range ( tests ) : NEW_LINE INDENT print ( " Case ▁ # { } : ▁ " . format ( z + 1 ) , end = ' ' ) NEW_LINE solve ( ) NEW_LINE DEDENT ouf . close ( ) NEW_LINE


import java . util . Arrays ; import java . util . Scanner ; public class D { 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 . println ( " Case ▁ # " + i + " : ▁ " + solve ( ) ) ; } } static String solve ( ) { int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; String [ ] G = new String [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { G [ i ] = sc . next ( ) ; } String B = sc . next ( ) ; for ( int i = 0 ; i < N ; ++ i ) { if ( G [ i ] . equals ( B ) ) { return " IMPOSSIBLE " ; } } if ( L == 1 ) { return " ? ▁ 0" ; } char [ ] p1 = new char [ L - 1 ] ; Arrays . fill ( p1 , ' ? ' ) ; StringBuilder p2 = new StringBuilder ( ) ; for ( int i = 0 ; i < 49 ; ++ i ) { p2 . append ( ( char ) ( '0' + i % 2 ) ) ; } p2 . append ( ' ? ' ) ; for ( int i = 0 ; i < 49 ; ++ i ) { p2 . append ( ( char ) ( '0' + ( i + 1 ) % 2 ) ) ; } return String . valueOf ( p1 ) + " ▁ " + p2 . toString ( ) ; } }

import java . util . * ; import java . io . * ; import static lib . Util . * ; public class D { static int 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 ++ ) { int N = input . nextInt ( ) ; int L = input . nextInt ( ) ; String [ ] Gs = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) Gs [ i ] = input . next ( ) ; String B = input . next ( ) ; boolean bad = false ; for ( String G : Gs ) if ( G . equals ( B ) ) bad = true ; if ( bad ) { System . out . printf ( " Case ▁ # % d : ▁ IMPOSSIBLE \n " , n + 1 ) ; continue ; } if ( L == 1 ) { System . out . printf ( " Case ▁ # % d : ▁ 0 ▁ ? \n " , n + 1 ) ; continue ; } StringBuilder p1 = new StringBuilder ( ) ; StringBuilder p2 = new StringBuilder ( ) ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == L - 1 ) { if ( i % 2 == 0 ) p2 . append ( " ? 1" ) ; else p1 . append ( " ? 1" ) ; } else if ( i % 2 == 0 ) { p1 . append ( "10" ) ; p2 . append ( " ? " ) ; } else { p1 . append ( " ? " ) ; p2 . append ( "10" ) ; } } System . out . printf ( " Case ▁ # % d : ▁ % s ▁ % s \n " , n + 1 , p1 , p2 ) ; } } }

import java . io . * ; import java . util . * ; public class D { String solveOne ( Scanner in ) { int size = in . nextInt ( ) ; int len = in . nextInt ( ) ; String g [ ] = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { g [ i ] = in . next ( ) ; } String bad = in . next ( ) ; if ( bad . contains ( "0" ) ) { throw new Error ( ) ; } for ( String s : g ) { if ( ! s . contains ( "0" ) ) { return " IMPOSSIBLE " ; } } String ans = "0" ; for ( int i = 1 ; i < len ; i ++ ) { ans += "1" ; } ans += " ▁ " ; for ( int i = 0 ; i < len ; i ++ ) { ans += "0 ? " ; } return ans ; } void solve ( Scanner in , PrintWriter out ) { int nTests = in . nextInt ( ) ; for ( int iTest = 1 ; iTest <= nTests ; iTest ++ ) { out . printf ( " Case ▁ # % d : ▁ % s % n " , iTest , solveOne ( in ) ) ; } } void run ( ) { try ( Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; ) { solve ( in , out ) ; } } public static void main ( String args [ ] ) { new D ( ) . run ( ) ; } }

import java . io . BufferedReader ; import java . io . File ; import java . io . FileReader ; import java . io . PrintWriter ; import java . io . StreamTokenizer ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Go implements Runnable { private static final String NAME = " go " ; private StreamTokenizer in ; int nextInt ( ) throws Exception { in . nextToken ( ) ; return ( int ) in . nval ; } long nextLong ( ) throws Exception { in . nextToken ( ) ; return ( long ) in . nval ; } @ Override public void run ( ) { try { Scanner in = new Scanner ( new File ( NAME + " . in " ) ) ; PrintWriter out = new PrintWriter ( NAME + " . out " ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { int n = in . nextInt ( ) ; int l = in . nextInt ( ) ; Set < String > s = new HashSet < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { s . add ( in . next ( ) ) ; } String b = in . next ( ) ; if ( b . contains ( "0" ) ) { throw new IllegalStateException ( ) ; } if ( s . contains ( b ) ) { out . println ( " Case ▁ # " + test + " : ▁ IMPOSSIBLE " ) ; } else { String r1 = " " ; String r2 = " " ; for ( int i = 0 ; i < l ; i ++ ) { r1 += "0 ? " ; } r2 += "0" ; for ( int i = 0 ; i < l - 1 ; i ++ ) { r2 += "01" ; } r2 += "0" ; out . println ( " Case ▁ # " + test + " : ▁ " + r1 + " ▁ " + r2 ) ; } } out . close ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public static void main ( String [ ] args ) { new Thread ( new Go ( ) ) . start ( ) ; } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintStream ; import java . util . Arrays ; import java . util . Scanner ; public class GoPlusPlus { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner cin = new Scanner ( new File ( " D - small - attempt0 . in " ) ) ; PrintStream cout = new PrintStream ( " D - small - attempt0 . out " ) ; int _case = 0 ; for ( int T = cin . nextInt ( ) ; T > 0 ; T -- ) { _case ++ ; StringBuilder ans = new StringBuilder ( ) ; int N = cin . nextInt ( ) ; int L = cin . nextInt ( ) ; String [ ] a = new String [ N ] ; boolean impossible = false ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = cin . next ( ) ; String shit = cin . next ( ) ; for ( String each : a ) if ( each . equals ( shit ) ) impossible = true ; if ( impossible ) ans . append ( " IMPOSSIBLE " ) ; else { String one = "0" ; for ( int i = 0 ; i < L - 1 ; i ++ ) one += "1" ; String two = " " ; for ( int i = 0 ; i < L ; i ++ ) two += "0 ? " ; ans . append ( one ) ; ans . append ( " ▁ " ) ; ans . append ( two ) ; } cout . printf ( " Case ▁ # % d : ▁ % s % n " , _case , ans . toString ( ) ) ; } cin . close ( ) ; cout . close ( ) ; } }

def solve ( n , l , gs , b ) : NEW_LINE INDENT if b in gs : NEW_LINE INDENT return " IMPOSSIBLE " NEW_LINE DEDENT if l == 1 : NEW_LINE INDENT return "0 ▁ ? " NEW_LINE DEDENT return " ? " * ( l - 1 ) + " ▁ " + "1" * ( l - 1 ) + "0 ? " + "01" * ( l - 1 ) NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for cas in xrange ( 1 , t + 1 ) : NEW_LINE INDENT n , l = map ( int , raw_input ( ) . split ( ) ) NEW_LINE gs = raw_input ( ) . split ( ) NEW_LINE b = raw_input ( ) NEW_LINE ans = solve ( n , l , gs , b ) NEW_LINE print " Case ▁ # { } : ▁ { } " . format ( cas , ans ) NEW_LINE DEDENT

T = int ( raw_input ( ) ) NEW_LINE for TK in xrange ( T ) : NEW_LINE INDENT print ' Case ▁ # % d : ' % ( TK + 1 ) , NEW_LINE N , L = map ( int , raw_input ( ) . split ( ) ) NEW_LINE G = raw_input ( ) . split ( ) NEW_LINE B = raw_input ( ) NEW_LINE if '1' * L in G : NEW_LINE INDENT print ' IMPOSSIBLE ' NEW_LINE continue NEW_LINE DEDENT if L == 1 : NEW_LINE INDENT print '0 ▁ 0 ? ' NEW_LINE DEDENT else : NEW_LINE INDENT a = ' ? ' * ( L - 1 ) NEW_LINE b = '10?1' + ( '01' * L ) NEW_LINE print a , b NEW_LINE DEDENT DEDENT

import io , sys NEW_LINE import datetime NEW_LINE import random NEW_LINE fin = None NEW_LINE def solve ( ) : NEW_LINE INDENT n , l = nums ( ) NEW_LINE good = strs ( ) NEW_LINE bad = sstrip ( ) NEW_LINE if '1' * l in good : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT if l == 1 : NEW_LINE INDENT return '0 ▁ ? ' NEW_LINE DEDENT return '0 % s ? % s ▁ % s ' % ( '10' * l , '1' * ( l - 1 ) , ' ? ' * ( l - 1 ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT fname = ' test . in ' NEW_LINE if len ( sys . argv ) > 1 : NEW_LINE INDENT fname = sys . argv [ 1 ] NEW_LINE DEDENT global fin NEW_LINE fin = io . open ( fname ) NEW_LINE fout = io . open ( fname + ' . out ' , ' w ' ) NEW_LINE t0 = datetime . datetime . now ( ) NEW_LINE t = int ( fin . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT fout . write ( ' Case ▁ # % d : ▁ ' % ( i + 1 ) ) NEW_LINE fout . write ( ' % s \n ' % str ( solve ( ) ) ) NEW_LINE DEDENT print ( ' Time ▁ = ▁ % s ' % str ( datetime . datetime . now ( ) - t0 ) ) NEW_LINE fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE DEDENT def nums ( ) : NEW_LINE INDENT return [ int ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE DEDENT def fnums ( ) : NEW_LINE INDENT return [ float ( x ) for x in fin . readline ( ) . split ( ) ] NEW_LINE DEDENT def num ( ) : NEW_LINE INDENT return int ( fin . readline ( ) ) NEW_LINE DEDENT def sstrip ( ) : NEW_LINE INDENT return fin . readline ( ) . strip ( ) NEW_LINE DEDENT def strs ( ) : NEW_LINE INDENT return fin . readline ( ) . split ( ) NEW_LINE DEDENT def arrstr ( a , sep = ' ▁ ' ) : NEW_LINE INDENT return sep . join ( [ str ( x ) for x in a ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

t = int ( input ( ) ) NEW_LINE def inverse ( s ) : NEW_LINE INDENT return " " . join ( chr ( ord ( u ) ^ 1 ) for u in s ) NEW_LINE DEDENT def chapeau ( s ) : NEW_LINE INDENT if len ( s ) == 0 : NEW_LINE INDENT return " " NEW_LINE DEDENT u = 0 NEW_LINE while u < len ( s ) and s [ u ] == s [ 0 ] : NEW_LINE INDENT u += 1 NEW_LINE DEDENT if u == len ( s ) : NEW_LINE INDENT return s [ 0 ] * ( u - 1 ) NEW_LINE DEDENT rem = s [ u : ] NEW_LINE return s [ 0 ] * ( u - 1 ) + inverse ( s [ 0 ] ) + s [ 0 ] + chapeau ( rem ) NEW_LINE DEDENT for i in range ( t ) : NEW_LINE INDENT print ( " Case ▁ # % d : " % ( i + 1 ) , end = " ▁ " ) NEW_LINE n , l = map ( int , input ( ) . split ( ) ) NEW_LINE good = input ( ) . strip ( ) . split ( ) NEW_LINE bad = input ( ) . strip ( ) NEW_LINE if bad in good : NEW_LINE INDENT print ( " IMPOSSIBLE " ) NEW_LINE DEDENT else : NEW_LINE INDENT if l == 1 : NEW_LINE INDENT print ( inverse ( bad [ 0 ] ) + " ? ▁ " + inverse ( bad [ 0 ] ) ) NEW_LINE continue NEW_LINE DEDENT z = inverse ( bad ) NEW_LINE u = chapeau ( bad ) NEW_LINE v = " " . join ( c + " ? " for c in z ) NEW_LINE assert ( len ( u ) + len ( v ) <= 200 ) NEW_LINE print ( u + " ▁ " + v ) NEW_LINE DEDENT DEDENT

def initialize_solver ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT def solve_testcase ( ) : NEW_LINE INDENT n , l = read ( ) NEW_LINE g = read ( rettype = str ) NEW_LINE b = read ( False , str ) NEW_LINE if b in g : NEW_LINE INDENT return " IMPOSSIBLE " NEW_LINE DEDENT return [ " ? 0" * l , "1" * ( l - 1 ) + "0" ] NEW_LINE 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 def read ( split = True , rettype = int ) : 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 ( rettype , input_line . split ( ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return rettype ( input_line ) NEW_LINE DEDENT DEDENT def write ( s = " \n " ) : NEW_LINE INDENT if s is None : s = " " NEW_LINE if isinstance ( s , list ) : s = " ▁ " . join ( map ( str , s ) ) NEW_LINE s = str ( s ) NEW_LINE if tfile : NEW_LINE INDENT tfile . write ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s , end = " " ) NEW_LINE DEDENT DEDENT if output_format == 0 : NEW_LINE INDENT solve_testcase ( ) NEW_LINE DEDENT else : NEW_LINE INDENT initialize_solver ( ) NEW_LINE total_cases = read ( split = False ) 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 ( " \n " ) NEW_LINE DEDENT DEDENT if tfile is not None : tfile . close ( ) NEW_LINE


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

import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Arrays ; public class C { public String solve ( int [ ] a ) { Arrays . sort ( a ) ; int n = a . length ; int total = 0 ; int xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xor ^= a [ i ] ; total += a [ i ] ; } if ( xor != 0 ) { return " NO \n " ; } total -= a [ 0 ] ; return total + " \n " ; } public String runInput ( BufferedReader br ) throws IOException { int n = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; String [ ] items = br . readLine ( ) . trim ( ) . split ( " \\ s + " ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( items [ i ] ) ; } return solve ( a ) ; } public static void main ( String [ ] args ) { C c = new C ( ) ; try { c . parseFile ( " C - sample " ) ; c . parseFile ( " C - small - attempt0" ) ; c . parseFile ( " C - large " ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public void parseFile ( String filePrefix ) throws IOException { String fileIn = filePrefix + " . in " ; String fileOut = filePrefix + " . out " ; BufferedReader br = new BufferedReader ( new FileReader ( fileIn ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( fileOut ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { String ret = " Case ▁ # " + i + " : ▁ " ; ret += runInput ( br ) ; System . out . print ( ret ) ; bw . write ( ret ) ; } br . close ( ) ; bw . close ( ) ; } }

import java . util . Scanner ; public class C { private static Scanner sc ; public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) System . out . printf ( " Case ▁ # % d : ▁ % s \n " , i + 1 , exec ( ) ) ; } private static String exec ( ) { int n = sc . nextInt ( ) ; int [ ] candy = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) candy [ i ] = sc . nextInt ( ) ; return calc ( candy ) ; } private static String calc ( int [ ] candy ) { int xor = 0 ; int smallest = Integer . MAX_VALUE ; int sum = 0 ; for ( int c : candy ) { if ( smallest > c ) smallest = c ; xor ^= c ; sum += c ; } if ( xor != 0 ) return " NO " ; return " " + ( sum - smallest ) ; } }

import java . awt . geom . * ; import java . io . * ; import java . math . * ; import java . util . * ; import java . util . regex . * ; import static java . lang . Math . * ; public class C_small { public static void main ( String [ ] args ) throws Exception { new C_small ( ) ; } public C_small ( ) throws Exception { line = br . readLine ( ) ; st = new StringTokenizer ( line ) ; int caseCount = Integer . parseInt ( st . nextToken ( ) ) ; for ( int caseNum = 1 ; caseNum <= caseCount ; caseNum ++ ) { String ans = null ; int N = Integer . parseInt ( br . readLine ( ) ) ; int total = 0 ; int xor = 0 ; int min = 1 << 30 ; line = br . readLine ( ) ; st = new StringTokenizer ( line ) ; for ( int i = 0 ; i < N ; i ++ ) { int v = Integer . parseInt ( st . nextToken ( ) ) ; xor ^= v ; total += v ; min = min ( min , v ) ; } if ( xor != 0 ) ans = " NO " ; else { ans = total - min + " " ; } buf . append ( String . format ( " Case ▁ # % d : ▁ % s \n " , caseNum , ans ) ) ; } System . out . print ( buf ) ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line ; StringTokenizer st ; StringBuilder buf = new StringBuilder ( ) ; public static void debug ( Object ... arr ) { System . err . println ( Arrays . deepToString ( arr ) ) ; } }

import java . io . * ; import java . util . * ; public class C { private BufferedReader in ; private PrintWriter out ; private StringTokenizer st ; C ( ) throws IOException { in = new BufferedReader ( new FileReader ( " C . large . in " ) ) ; out = new PrintWriter ( " C . large . out " ) ; eat ( " " ) ; int T = nextInt ( ) ; for ( int t = 1 ; t <= T ; t ++ ) { int N = nextInt ( ) , xor = 0 , sum = 0 , m = 1000001 , c ; for ( int i = 0 ; i < N ; i ++ ) { c = nextInt ( ) ; xor ^= c ; sum += c ; m = Math . min ( m , c ) ; } out . print ( " Case ▁ # " + t + " : ▁ " ) ; if ( xor != 0 ) { out . println ( " NO " ) ; } else { out . println ( sum - m ) ; } } in . close ( ) ; out . close ( ) ; } private void eat ( String str ) { st = new StringTokenizer ( str ) ; } String next ( ) throws IOException { while ( ! st . hasMoreTokens ( ) ) { String line = in . readLine ( ) ; if ( line == null ) { return null ; } eat ( line ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public static void main ( String [ ] args ) throws IOException { new C ( ) ; } }

from math import * NEW_LINE fin = open ( " c - large . in " ) NEW_LINE fout = open ( " c - large . out " , " w " ) NEW_LINE cases = int ( fin . readline ( ) . split ( ) [ 0 ] ) NEW_LINE case = 0 NEW_LINE def answer ( x ) : NEW_LINE INDENT global case , cases NEW_LINE case += 1 NEW_LINE print >> fout , " Case ▁ # " + str ( case ) + " : ▁ " + str ( x ) NEW_LINE print " Case ▁ # " + str ( case ) + " : ▁ " + str ( x ) NEW_LINE DEDENT def nim ( x ) : NEW_LINE INDENT aux = 0 NEW_LINE for i in x : NEW_LINE INDENT aux = aux ^ i NEW_LINE DEDENT return aux NEW_LINE DEDENT for test in xrange ( cases ) : NEW_LINE INDENT n = int ( fin . readline ( ) . split ( ) [ 0 ] ) NEW_LINE bag = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE if nim ( bag ) == 0 : NEW_LINE INDENT answer ( str ( sum ( bag ) - min ( bag ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT answer ( " NO " ) NEW_LINE DEDENT DEDENT

xsum = lambda x : reduce ( lambda v , s : v ^ s , x ) NEW_LINE def main ( ) : NEW_LINE INDENT f = open ( " input . txt " ) NEW_LINE testlen = int ( f . readline ( ) . strip ( ) ) NEW_LINE tests = [ ] NEW_LINE i = 0 NEW_LINE for line in f : NEW_LINE INDENT if i % 2 : NEW_LINE INDENT tests . append ( line . strip ( ) ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT tests = tests [ : testlen ] NEW_LINE for test , i in zip ( tests , range ( testlen ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % s " % ( i + 1 , solve ( parse ( test ) ) ) NEW_LINE DEDENT DEDENT def parse ( test ) : NEW_LINE INDENT return map ( int , test . split ( " ▁ " ) ) NEW_LINE DEDENT def solve ( test ) : NEW_LINE INDENT if xsum ( test ) != 0 : NEW_LINE INDENT return " NO " NEW_LINE DEDENT else : NEW_LINE INDENT return str ( sum ( test ) - min ( test ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

import sys NEW_LINE def read_values ( ) : NEW_LINE INDENT return map ( int , raw_input ( ) . split ( ) ) NEW_LINE DEDENT for case_index in range ( 1 , 1 + input ( ) ) : NEW_LINE INDENT sys . stderr . write ( str ( case_index ) + ' ▁ ' ) NEW_LINE n = input ( ) NEW_LINE t = map ( int , raw_input ( ) . split ( ) ) NEW_LINE t . sort ( ) NEW_LINE s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT s = s ^ t [ i ] NEW_LINE DEDENT if s == 0 : NEW_LINE INDENT res = sum ( t [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT res = ' NO ' NEW_LINE DEDENT print ' Case ▁ # % s : ▁ % s ' % ( case_index , res ) NEW_LINE DEDENT sys . stderr . write ( ' \n ' ) NEW_LINE

import os , sys , collections NEW_LINE def bits ( xs ) : NEW_LINE INDENT i = 0 NEW_LINE toReturn = [ [ 0 ] * 32 for x in xs ] NEW_LINE cur2 = 1 NEW_LINE while i < 32 : NEW_LINE INDENT for ( j , x ) in enumerate ( xs ) : NEW_LINE INDENT if x % 2 == 1 : NEW_LINE INDENT toReturn [ j ] [ i ] = 1 NEW_LINE xs [ j ] -= 1 NEW_LINE DEDENT xs [ j ] /= 2 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT toReturn = [ x [ : : - 1 ] for x in toReturn ] NEW_LINE return toReturn NEW_LINE DEDENT def findBigCandy ( candies ) : NEW_LINE INDENT candies . sort ( ) NEW_LINE origCandies = candies [ : ] NEW_LINE candyBits = bits ( candies ) NEW_LINE for i in range ( 32 ) : NEW_LINE INDENT totalBit = sum ( [ candyBits [ x ] [ i ] for x in range ( len ( candyBits ) ) ] ) NEW_LINE if totalBit % 2 == 1 : NEW_LINE INDENT return ' NO ' NEW_LINE DEDENT DEDENT return sum ( origCandies [ 1 : ] ) NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT numCandies = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE candies = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE answer = findBigCandy ( candies ) NEW_LINE print " Case ▁ # % d : ▁ % s " % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT

lines = open ( " c2 . in " , " r " ) . readlines ( ) NEW_LINE num_cases = int ( lines [ 0 ] . strip ( ) ) NEW_LINE for case_no in range ( num_cases ) : NEW_LINE INDENT n = int ( lines [ case_no * 2 + 1 ] . strip ( ) ) NEW_LINE items = lines [ case_no * 2 + 2 ] . strip ( ) . split ( " ▁ " ) NEW_LINE a = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT a . append ( int ( items [ i ] ) ) NEW_LINE DEDENT sum = 0 NEW_LINE total = 0 NEW_LINE min = a [ 0 ] NEW_LINE for i in a : NEW_LINE INDENT sum = sum ^ i NEW_LINE if ( i < min ) : min = i NEW_LINE total = total + i NEW_LINE DEDENT if sum == 0 : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( case_no + 1 , total - min ) NEW_LINE DEDENT else : NEW_LINE INDENT print " Case ▁ # % d : ▁ NO " % ( case_no + 1 ) NEW_LINE DEDENT DEDENT


import java . util . * ; import static java . lang . Math . * ; public class B { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int zz = 1 ; zz <= T ; zz ++ ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; long [ ] sum = new long [ N - K + 1 ] ; for ( int i = 0 ; i < sum . length ; i ++ ) sum [ i ] = in . nextInt ( ) ; long [ ] diff = new long [ N ] ; long [ ] A = new long [ K ] ; long [ ] B = new long [ K ] ; for ( int i = 0 ; i + 1 < sum . length ; i ++ ) { long d = sum [ i + 1 ] - sum [ i ] ; diff [ i + K ] = diff [ i ] + d ; A [ i % K ] = min ( A [ i % K ] , diff [ i + K ] ) ; B [ i % K ] = max ( B [ i % K ] , diff [ i + K ] ) ; } long total = 0 ; for ( int i = 0 ; i < K ; i ++ ) { total -= A [ i ] ; B [ i ] -= A [ i ] ; A [ i ] = 0 ; } Arrays . sort ( B ) ; long d = sum [ 0 ] - total ; d = ( ( d % K ) + K ) % K ; if ( d < 0 || d >= K ) throw new RuntimeException ( ) ; for ( long ans = B [ K - 1 ] ; ; ans ++ ) { long less = 0 ; for ( long b : B ) less += ans - b ; if ( less >= d ) { System . out . format ( " Case ▁ # % d : ▁ % d \n " , zz , ans ) ; break ; } } } } }

package round3 ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cases = sc . nextInt ( ) ; for ( int caze = 1 ; caze <= cases ; caze ++ ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] sums = new int [ N - K + 1 ] ; for ( int i = 0 ; i < sums . length ; i ++ ) { sums [ i ] = sc . nextInt ( ) ; } int [ ] min = new int [ K ] , max = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) { int val = 0 ; for ( int j = i ; j + 1 < sums . length ; j += K ) { val += sums [ j + 1 ] - sums [ j ] ; min [ i ] = Math . min ( min [ i ] , val ) ; max [ i ] = Math . max ( max [ i ] , val ) ; } } int sumModulo = 0 , maxInterval = 0 , canUse = 0 ; for ( int i = 0 ; i < K ; i ++ ) { sumModulo -= min [ i ] ; maxInterval = Math . max ( maxInterval , max [ i ] - min [ i ] ) ; } for ( int i = 0 ; i < K ; i ++ ) { canUse += maxInterval - ( max [ i ] - min [ i ] ) ; } boolean can = false ; for ( int i = 0 ; i <= canUse ; i ++ ) { if ( ( sumModulo + i - sums [ 0 ] ) % K == 0 ) { can = true ; break ; } } if ( ! can ) maxInterval ++ ; System . out . println ( " Case ▁ # " + caze + " : ▁ " + maxInterval ) ; } } }

import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numCases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; caseNum ++ ) { int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] sums = new int [ N - K + 1 ] ; for ( int i = 0 ; i < N - K + 1 ; i ++ ) { sums [ i ] = sc . nextInt ( ) ; } int [ ] maxDiff = new int [ K ] ; int [ ] minDiff = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) { int totalDiff = 0 ; for ( int j = i ; j < N - K ; j += K ) { totalDiff += sums [ j + 1 ] - sums [ j ] ; maxDiff [ i ] = Math . max ( maxDiff [ i ] , totalDiff ) ; minDiff [ i ] = Math . min ( minDiff [ i ] , totalDiff ) ; } } long min = 0 ; long max = Integer . MAX_VALUE ; while ( min < max ) { long mid = ( min + max ) / 2 ; boolean possible = true ; long minSum = 0 , maxSum = 0 ; for ( int i = 0 ; i < K ; i ++ ) { if ( maxDiff [ i ] - minDiff [ i ] > mid ) { possible = false ; break ; } long minValue = - minDiff [ i ] , maxValue = mid - maxDiff [ i ] ; minSum += minValue ; maxSum += maxValue ; } long target = ( ( sums [ 0 ] - minSum ) % K + K ) % K + minSum ; if ( possible && target <= maxSum ) { max = mid ; } else { min = mid + 1 ; } } System . out . println ( " Case ▁ # " + caseNum + " : ▁ " + min ) ; } } }

import java . util . * ; import java . io . * ; public class B { 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 ++ ) { int N = input . nextInt ( ) ; int K = input . nextInt ( ) ; int [ ] sums = new int [ N - K + 1 ] ; for ( int i = 0 ; i < N - K + 1 ; i ++ ) sums [ i ] = input . nextInt ( ) ; int [ ] maxdiffs = new int [ K ] ; int [ ] mindiffs = new int [ K ] ; int [ ] currdiff = new int [ K ] ; for ( int i = K ; i < N ; i ++ ) { currdiff [ i % K ] += sums [ i - K + 1 ] - sums [ i - K ] ; if ( currdiff [ i % K ] > maxdiffs [ i % K ] ) maxdiffs [ i % K ] = currdiff [ i % K ] ; if ( currdiff [ i % K ] < mindiffs [ i % K ] ) mindiffs [ i % K ] = currdiff [ i % K ] ; } int [ ] diffdiffs = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) diffdiffs [ i ] = maxdiffs [ i ] - mindiffs [ i ] ; int maxdiffdiff = 0 ; for ( int i = 0 ; i < K ; i ++ ) if ( diffdiffs [ i ] > maxdiffdiff ) maxdiffdiff = diffdiffs [ i ] ; int highBound = 0 ; for ( int i = 0 ; i < K ; i ++ ) highBound += maxdiffdiff - diffdiffs [ i ] ; int target = sums [ 0 ] ; for ( int i = 0 ; i < K ; i ++ ) target += mindiffs [ i ] ; target = ( target % K + K ) % K ; int ans = maxdiffdiff + ( target <= highBound ? 0 : 1 ) ; System . out . printf ( " Case ▁ # % d : ▁ " , n + 1 ) ; System . out . println ( ans ) ; } } }

from itertools import * NEW_LINE from bisect import bisect NEW_LINE import sys NEW_LINE lines = open ( " b . in " ) . read ( ) . split ( " \n " ) NEW_LINE T = int ( lines [ 0 ] ) NEW_LINE def f ( N , K , sum_i ) : NEW_LINE INDENT min_diff = [ 0 ] * K NEW_LINE max_diff = [ 0 ] * K NEW_LINE curr_diff = [ 0 ] * K NEW_LINE first_sum = int ( sum_i [ 0 ] ) NEW_LINE last_thing = first_sum NEW_LINE for i , a in enumerate ( sum_i [ 1 : ] ) : NEW_LINE INDENT curr_diff [ i % K ] += int ( a ) - last_thing NEW_LINE last_thing = int ( a ) NEW_LINE max_diff [ i % K ] = max ( curr_diff [ i % K ] , max_diff [ i % K ] ) NEW_LINE min_diff [ i % K ] = min ( curr_diff [ i % K ] , min_diff [ i % K ] ) NEW_LINE DEDENT diff = list ( x - n for x , n in izip ( max_diff , min_diff ) ) NEW_LINE worst_diff = max ( diff ) NEW_LINE move_up_min = 0 NEW_LINE move_up_max = 0 NEW_LINE move_down_min = 0 NEW_LINE move_down_max = 0 NEW_LINE for i in xrange ( K ) : NEW_LINE INDENT if min_diff [ i ] < 0 : NEW_LINE INDENT move_up_min += - min_diff [ i ] NEW_LINE move_up_max += worst_diff - max_diff [ i ] NEW_LINE DEDENT elif max_diff [ i ] > worst_diff : NEW_LINE INDENT move_down_min += max_diff [ i ] - worst_diff NEW_LINE move_down_max += min_diff [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT move_up_max += worst_diff - max_diff [ i ] NEW_LINE move_down_max += min_diff [ i ] NEW_LINE DEDENT DEDENT move_up_d = move_up_max - move_up_min NEW_LINE move_down_d = move_down_max - move_down_min NEW_LINE move_min = move_up_min - move_down_max NEW_LINE move_d = move_down_d + move_up_d NEW_LINE move_min %= ( K ) NEW_LINE move_amt = first_sum % ( K ) NEW_LINE if move_amt < move_min : NEW_LINE INDENT move_min -= K NEW_LINE DEDENT if move_min + move_d >= move_amt : NEW_LINE INDENT return worst_diff NEW_LINE DEDENT return worst_diff + 1 NEW_LINE DEDENT curr_i = 1 NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT N , K = tuple ( int ( j ) for j in lines [ curr_i ] . split ( ' ▁ ' ) ) NEW_LINE curr_i += 1 NEW_LINE out = f ( N , K , lines [ curr_i ] . split ( ' ▁ ' ) ) NEW_LINE curr_i += 1 NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i , out ) NEW_LINE DEDENT

def solve ( ) : NEW_LINE INDENT n , k = map ( int , raw_input ( ) . split ( ) ) NEW_LINE s = map ( int , raw_input ( ) . split ( ) ) NEW_LINE sizes = [ ] NEW_LINE summin = 0 NEW_LINE for i in xrange ( k ) : NEW_LINE INDENT a = 0 if i != k - 1 else s [ 0 ] NEW_LINE seq = [ a ] NEW_LINE for j in xrange ( i , n - k , k ) : NEW_LINE INDENT a += s [ j + 1 ] - s [ j ] NEW_LINE seq . append ( a ) NEW_LINE DEDENT m = min ( seq ) NEW_LINE sizes . append ( max ( seq ) - m ) NEW_LINE summin += m NEW_LINE DEDENT sizes . sort ( ) NEW_LINE left = summin % k NEW_LINE res = sizes [ - 1 ] NEW_LINE for i in xrange ( k ) : NEW_LINE INDENT left -= res - sizes [ i ] NEW_LINE DEDENT if left > 0 : res += 1 NEW_LINE return res NEW_LINE DEDENT for i in xrange ( input ( ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( i + 1 , solve ( ) ) NEW_LINE DEDENT

import sys NEW_LINE def run ( N , K , sums ) : NEW_LINE INDENT diffs = [ ] NEW_LINE for i in range ( K ) : NEW_LINE INDENT cmin = 0 NEW_LINE cmax = 0 NEW_LINE ctemp = 0 NEW_LINE for j in range ( i , N - K , K ) : NEW_LINE INDENT ctemp += sums [ j + 1 ] - sums [ j ] NEW_LINE cmin = min ( cmin , ctemp ) NEW_LINE cmax = max ( cmax , ctemp ) NEW_LINE DEDENT diffs . append ( [ cmax - cmin , cmin , cmax ] ) NEW_LINE DEDENT diffs . sort ( ) NEW_LINE diff2 = [ ] NEW_LINE offset = 0 NEW_LINE for d in diffs : NEW_LINE INDENT if d [ 1 ] < diffs [ - 1 ] [ 1 ] : NEW_LINE INDENT offset += diffs [ - 1 ] [ 1 ] - d [ 1 ] NEW_LINE diff2 . append ( [ d [ 0 ] , diffs [ - 1 ] [ 1 ] , d [ 2 ] + diffs [ - 1 ] [ 1 ] - d [ 1 ] ] ) NEW_LINE DEDENT else : NEW_LINE INDENT diff2 . append ( d ) NEW_LINE DEDENT DEDENT totminus = sum ( r [ 1 ] - diff2 [ - 1 ] [ 1 ] for r in diff2 ) NEW_LINE totplus = sum ( diff2 [ - 1 ] [ 2 ] - r [ 2 ] for r in diff2 ) NEW_LINE needplus = ( sums [ 0 ] - offset ) % K NEW_LINE needminus = ( offset - sums [ 0 ] ) % K NEW_LINE if totminus >= needminus or totplus >= needplus : NEW_LINE INDENT return diff2 [ - 1 ] [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT return diff2 [ - 1 ] [ 0 ] + 1 NEW_LINE DEDENT DEDENT fin = open ( sys . argv [ 1 ] ) NEW_LINE T = int ( fin . readline ( ) . strip ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT N , K = [ int ( x ) for x in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE sums = [ int ( x ) for x in fin . readline ( ) . strip ( ) . split ( ) ] NEW_LINE ans = run ( N , K , sums ) NEW_LINE print ( ' Case ▁ # % d : ▁ % s ' % ( i , ans ) ) NEW_LINE DEDENT

import math , collections , itertools NEW_LINE import sys NEW_LINE NCASE = int ( sys . stdin . readline ( ) ) NEW_LINE for case in range ( 1 , NCASE + 1 ) : NEW_LINE INDENT N , K = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE SUM = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE A = [ 0 ] * N NEW_LINE mxd , mnd = [ 0 ] * K , [ 0 ] * K NEW_LINE for i in xrange ( 0 , len ( SUM ) - 1 ) : NEW_LINE INDENT d = SUM [ i + 1 ] - SUM [ i ] NEW_LINE A [ i + K ] = A [ i ] + d NEW_LINE k = i % K NEW_LINE mxd [ k ] = max ( A [ i + K ] , mxd [ k ] ) NEW_LINE mnd [ k ] = min ( A [ i + K ] , mnd [ k ] ) NEW_LINE DEDENT mxrng = max ( mxd [ i ] - mnd [ i ] for i in xrange ( K ) ) NEW_LINE r = next ( i for i in xrange ( K ) if mxd [ i ] - mnd [ i ] == mxrng ) NEW_LINE smn = sum ( mnd [ r ] - d for d in mnd ) NEW_LINE smx = sum ( mxd [ r ] - d for d in mxd ) NEW_LINE if ( SUM [ 0 ] - smn ) % K <= smx - smn : NEW_LINE INDENT ans = mxrng NEW_LINE DEDENT else : NEW_LINE INDENT ans = mxrng + 1 NEW_LINE DEDENT print ' Case ▁ # % d : ▁ % d ' % ( case , ans ) NEW_LINE DEDENT

for x in range ( 1 , int ( input ( ) ) + 1 ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE sums = tuple ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = [ 0 ] * K NEW_LINE t = sums [ 0 ] NEW_LINE for i in range ( K ) : NEW_LINE INDENT b = 0 NEW_LINE c = 0 NEW_LINE for j in range ( i , N - K , K ) : NEW_LINE INDENT c += sums [ j + 1 ] - sums [ j ] NEW_LINE if c > a [ i ] : NEW_LINE INDENT a [ i ] = c NEW_LINE DEDENT elif c < b : NEW_LINE INDENT b = c NEW_LINE DEDENT DEDENT a [ i ] -= b NEW_LINE t += b NEW_LINE DEDENT t %= K NEW_LINE for i in range ( t ) : NEW_LINE INDENT bestj = 0 NEW_LINE for j in range ( 1 , K ) : NEW_LINE INDENT if a [ j ] < a [ bestj ] : NEW_LINE INDENT bestj = j NEW_LINE DEDENT DEDENT a [ bestj ] += 1 NEW_LINE DEDENT y = max ( a ) NEW_LINE print ( ' Case ▁ # ' + str ( x ) + ' : ' , y ) NEW_LINE DEDENT


import java . io . File ; import java . io . PrintWriter ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) throws Exception { String path = " D : \\ B - large " ; Scanner sc = new Scanner ( new File ( path + " . in " ) ) ; PrintWriter pw = new PrintWriter ( path + " . out " ) ; int testCases = sc . nextInt ( ) ; for ( int testCase = 1 ; testCase <= testCases ; testCase ++ ) { long E = sc . nextInt ( ) ; long R = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; long [ ] v = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = sc . nextInt ( ) ; } long res = 0 ; long energy = E ; for ( int i = 0 ; i < n ; i ++ ) { long cur = energy ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( v [ j ] > v [ i ] ) { long d = j - i ; long regeneration = d * R ; long y = regeneration - ( E - energy ) ; cur = Math . min ( y , energy ) ; cur = Math . max ( cur , 0 ) ; break ; } } res += cur * v [ i ] ; energy = Math . min ( energy - cur + R , E ) ; } pw . println ( " Case ▁ # " + testCase + " : ▁ " + res ) ; pw . flush ( ) ; } pw . close ( ) ; } }

import java . util . * ; public class Energy { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; StringBuilder out = new StringBuilder ( ) ; int numCases = in . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; ++ caseNum ) { out . append ( String . format ( " Case ▁ # % d : ▁ " , caseNum ) ) ; long maxEnergy = in . nextLong ( ) ; long currentEnergy = maxEnergy ; long regen = in . nextLong ( ) ; int numEvents = in . nextInt ( ) ; long [ ] values = new long [ numEvents ] ; for ( int i = 0 ; i < values . length ; ++ i ) values [ i ] = in . nextLong ( ) ; int curEvent = 0 ; long totalValue = 0 ; while ( curEvent != numEvents ) { int nextEvent = curEvent + 1 ; while ( nextEvent != numEvents && values [ nextEvent ] <= values [ curEvent ] ) ++ nextEvent ; if ( nextEvent == numEvents ) { totalValue += values [ curEvent ] * currentEnergy ; currentEnergy = 0 ; } else { long energyToLeave = Math . max ( maxEnergy - regen * ( nextEvent - curEvent ) , 0L ) ; if ( energyToLeave >= currentEnergy ) { } else { long energyToSpend = currentEnergy - energyToLeave ; totalValue += values [ curEvent ] * energyToSpend ; currentEnergy = energyToLeave ; } } currentEnergy += regen ; currentEnergy = Math . min ( currentEnergy , maxEnergy ) ; ++ curEvent ; } out . append ( totalValue ) ; out . append ( ' \n ' ) ; } System . out . print ( out ) ; } }

import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int cases = scan . nextInt ( ) ; int e , r , n ; long result ; int [ ] maxE , minE ; ArrayList < Activity > activities = new ArrayList < Activity > ( ) ; for ( int c = 1 ; c <= cases ; c ++ ) { e = scan . nextInt ( ) ; r = scan . nextInt ( ) ; if ( r > e ) r = e ; n = scan . nextInt ( ) ; activities . clear ( ) ; for ( int i = 0 ; i < n ; i ++ ) activities . add ( new Activity ( i , scan . nextInt ( ) ) ) ; Collections . sort ( activities ) ; maxE = new int [ n ] ; minE = new int [ n ] ; Arrays . fill ( maxE , e ) ; Arrays . fill ( minE , 0 ) ; result = 0 ; for ( Activity act : activities ) { result += ( maxE [ act . i ] - minE [ act . i ] ) * ( long ) act . v ; for ( int i = act . i + 1 , rNext = minE [ act . i ] + r ; i < n && rNext < maxE [ i ] ; i ++ , rNext += r ) maxE [ i ] = rNext ; for ( int i = act . i - 1 , rNext = maxE [ act . i ] - r ; i >= 0 && rNext >= minE [ i ] ; i -- , rNext -= r ) minE [ i ] = rNext ; } System . out . println ( " Case ▁ # " + c + " : ▁ " + result ) ; } } private static class Activity implements Comparable < Activity > { public final int i , v ; public Activity ( int i , int v ) { this . i = i ; this . v = v ; } public int compareTo ( Activity other ) { return - 1 * ( ( Integer ) v ) . compareTo ( other . v ) ; } } }

def solve ( e , r , n , v ) : NEW_LINE INDENT before = [ e ] * n NEW_LINE after = [ 0 ] * n NEW_LINE finish = [ 0 ] * n NEW_LINE gain = 0 NEW_LINE vv = list ( enumerate ( v ) ) NEW_LINE vv . sort ( key = lambda v : v [ 1 ] , reverse = True ) NEW_LINE for i , v in vv : NEW_LINE INDENT finish [ i ] = 1 NEW_LINE B = before [ i ] NEW_LINE A = after [ i ] NEW_LINE gain += v * ( B - A ) NEW_LINE a = B NEW_LINE for ii in xrange ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT if finish [ ii ] : NEW_LINE INDENT break NEW_LINE DEDENT a -= r NEW_LINE if a < 0 : NEW_LINE INDENT break NEW_LINE DEDENT after [ ii ] = a NEW_LINE DEDENT b = A NEW_LINE for ii in xrange ( i + 1 , n ) : NEW_LINE INDENT if finish [ ii ] : NEW_LINE INDENT break NEW_LINE DEDENT b += r NEW_LINE if b > e : NEW_LINE INDENT break NEW_LINE DEDENT before [ ii ] = b NEW_LINE DEDENT DEDENT return gain NEW_LINE DEDENT import sys NEW_LINE T = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( 1 , T + 1 ) : NEW_LINE INDENT e , r , n = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE vs = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( i , solve ( e , r , n , vs ) ) NEW_LINE DEDENT

from sys import * NEW_LINE z = input ( ) NEW_LINE from functools import wraps NEW_LINE def memoize ( function ) : NEW_LINE INDENT memo = { } NEW_LINE @ wraps ( function ) NEW_LINE def f ( * args , ** kwargs ) : NEW_LINE INDENT key = args , tuple ( sorted ( kwargs . items ( ) ) ) NEW_LINE if key not in memo : NEW_LINE INDENT memo [ key ] = function ( * args , ** kwargs ) NEW_LINE DEDENT return memo [ key ] NEW_LINE DEDENT f . memo = memo NEW_LINE return f NEW_LINE DEDENT for cas in xrange ( 1 , z + 1 ) : NEW_LINE INDENT e , r , n = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE v = map ( int , raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE @ memoize NEW_LINE def f ( E , N ) : NEW_LINE INDENT if N == n : NEW_LINE INDENT return 0 NEW_LINE DEDENT s = 0 NEW_LINE for t in xrange ( E + 1 ) : NEW_LINE INDENT w = f ( min ( e , E - t + r ) , N + 1 ) + t * v [ N ] NEW_LINE s = max ( s , w ) NEW_LINE DEDENT return s NEW_LINE DEDENT f . memo . clear ( ) NEW_LINE ans = f ( e , 0 ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( cas , ans ) NEW_LINE DEDENT

import math NEW_LINE def solve ( activities , E , R ) : NEW_LINE INDENT def find_waste_points ( a , i , e ) : NEW_LINE INDENT rec = R NEW_LINE i += 1 NEW_LINE while a > activities [ i ] : NEW_LINE INDENT rec += R NEW_LINE i += 1 NEW_LINE DEDENT return max ( 0 , min ( e , e + rec - E ) ) NEW_LINE DEDENT window = int ( math . ceil ( float ( E ) / R ) ) + 1 NEW_LINE gain = 0 NEW_LINE e = E NEW_LINE for i , a in enumerate ( activities ) : NEW_LINE INDENT m = max ( activities [ i : i + window ] ) NEW_LINE if m == a : NEW_LINE INDENT gain += a * e NEW_LINE e = 0 NEW_LINE DEDENT else : NEW_LINE INDENT wp = find_waste_points ( a , i , e ) NEW_LINE gain += wp * a NEW_LINE e -= wp NEW_LINE DEDENT e += R NEW_LINE if e > E : NEW_LINE INDENT e = E NEW_LINE DEDENT DEDENT return gain NEW_LINE DEDENT tcases = int ( raw_input ( ) ) NEW_LINE for d in xrange ( 1 , tcases + 1 ) : NEW_LINE INDENT E , R , N = map ( int , raw_input ( ) . split ( ) ) NEW_LINE activities = map ( int , raw_input ( ) . split ( ) ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( d , solve ( activities , E , R ) ) NEW_LINE DEDENT

import os , sys , math NEW_LINE def max_energy ( max_e , e , r , values , i ) : NEW_LINE INDENT if ( i == ( len ( values ) - 1 ) ) : NEW_LINE INDENT return ( e * values [ i ] , 0 ) NEW_LINE DEDENT best = 0 NEW_LINE best_index = - 1 NEW_LINE possible_energies = [ 0 , e ] NEW_LINE if ( e + r > max_e ) : NEW_LINE INDENT possible_energies [ 0 ] = min ( e , e + r - max_e ) NEW_LINE DEDENT next_highest = 1 NEW_LINE while ( i + next_highest ) < len ( values ) and values [ i + next_highest ] < values [ i ] : NEW_LINE INDENT next_highest += 1 NEW_LINE DEDENT if ( i + next_highest ) == len ( values ) : NEW_LINE INDENT possible_energies = [ e ] NEW_LINE DEDENT else : NEW_LINE INDENT possible_energies = [ min ( e , max ( possible_energies [ 0 ] , ( e + next_highest * r ) - max_e ) ) ] NEW_LINE DEDENT energy_to_use = possible_energies [ 0 ] NEW_LINE energy_for_next_step = min ( e - energy_to_use + r , max_e ) NEW_LINE return ( energy_to_use * values [ i ] , energy_for_next_step ) NEW_LINE DEDENT def solve ( e , r , values ) : NEW_LINE INDENT global best_matrix NEW_LINE best_matrix = { } NEW_LINE best = 0 NEW_LINE max_e = e NEW_LINE for i in range ( len ( values ) ) : NEW_LINE INDENT ( new_energy , e ) = max_energy ( max_e , e , r , values , i ) NEW_LINE best += new_energy NEW_LINE DEDENT return best NEW_LINE DEDENT def main ( filename ) : NEW_LINE INDENT fileLines = open ( filename , ' r ' ) . readlines ( ) NEW_LINE index = 0 NEW_LINE numCases = int ( fileLines [ index ] [ : - 1 ] ) NEW_LINE index += 1 NEW_LINE for caseNum in range ( numCases ) : NEW_LINE INDENT ( e , r , n ) = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE values = [ int ( x ) for x in fileLines [ index ] [ : - 1 ] . split ( ' ▁ ' ) ] NEW_LINE index += 1 NEW_LINE answer = solve ( e , r , values ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( caseNum + 1 , answer ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( sys . argv [ 1 ] ) NEW_LINE DEDENT

def readint ( ) : return int ( raw_input ( ) ) NEW_LINE def readarray ( f ) : return map ( f , raw_input ( ) . split ( ) ) NEW_LINE E = 0 NEW_LINE R = 0 NEW_LINE def update ( maybe , must , i , D ) : NEW_LINE INDENT j = i - 1 NEW_LINE m = maybe [ i ] NEW_LINE while j >= 0 : NEW_LINE INDENT m -= R NEW_LINE if m < must [ j ] : NEW_LINE INDENT break NEW_LINE DEDENT must [ j ] = m NEW_LINE j -= 1 NEW_LINE DEDENT j = i + 1 NEW_LINE m = must [ i ] NEW_LINE while j < len ( maybe ) : NEW_LINE INDENT m += R NEW_LINE if m > maybe [ j ] : NEW_LINE INDENT break NEW_LINE DEDENT maybe [ j ] = m NEW_LINE j += 1 NEW_LINE DEDENT DEDENT for test in range ( readint ( ) ) : NEW_LINE INDENT print ' Case ▁ # % i : ' % ( test + 1 ) , NEW_LINE E , R , N = readarray ( int ) NEW_LINE V = readarray ( int ) NEW_LINE D = [ - 1 ] * N NEW_LINE maybe = [ E ] * N NEW_LINE must = [ 0 ] * N NEW_LINE tasks = list ( reversed ( sorted ( [ ( V [ i ] , i ) for i in range ( N ) ] ) ) ) NEW_LINE best = 0 NEW_LINE for v , i in tasks : NEW_LINE INDENT best += v * ( maybe [ i ] - must [ i ] ) NEW_LINE D [ i ] = maybe [ i ] - must [ i ] NEW_LINE update ( maybe , must , i , D ) NEW_LINE DEDENT print best NEW_LINE DEDENT


import java . io . * ; import java . util . * ; import java . text . * ; public class CS { public PrintStream out = System . out ; public PrintStream err = System . err ; public Scanner in = new Scanner ( System . in ) ; public DecimalFormat fmt = new DecimalFormat ( "0.000000000" ) ; public int Amin , Amax , Bmin , Bmax ; public void main ( ) { try { int TCase , cc ; int i , j , k ; int A , B ; TCase = in . nextInt ( ) ; for ( cc = 1 ; cc <= TCase ; ++ cc ) { Amin = in . nextInt ( ) ; Amax = in . nextInt ( ) ; Bmin = in . nextInt ( ) ; Bmax = in . nextInt ( ) ; int res = 0 ; for ( A = Amin ; A <= Amax ; ++ A ) for ( B = Bmin ; B <= Bmax ; ++ B ) { res += sim ( A , B ) ; } out . println ( " Case ▁ # " + cc + " : ▁ " + res ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } } public int sim ( int A , int B ) { if ( A == B ) return 0 ; if ( A < B ) return sim ( B , A ) ; if ( A >= 2 * B ) return 1 ; return 1 - sim ( B , A - B ) ; } public static void main ( String [ ] args ) { long startTime = System . currentTimeMillis ( ) ; ( new CS ( ) ) . main ( ) ; long endTime = System . currentTimeMillis ( ) ; long ms = endTime - startTime ; long sec = ms / 1000 ; ms = ms % 1000 ; long min = sec / 60 ; sec = sec % 60 ; System . err . println ( " Time ▁ Spent : ▁ " + min + " ▁ minute ( s ) ▁ " + sec + " ▁ second ( s ) ▁ " + ms + " ▁ ( ms ) " ) ; } }

import java . math . * ; import java . util . * ; public class C { public static int [ ] a ; public static int find ( int k , int x ) { int low = 1 ; int up = k ; while ( low < up ) { int mid = ( low + up ) / 2 ; if ( a [ mid ] <= x ) low = mid + 1 ; else up = mid ; } return low ; } public static void main ( String args [ ] ) { a = new int [ 1000001 ] ; a [ 1 ] = 2 ; a [ 2 ] = 4 ; for ( int i = 3 ; i <= 1000000 ; ++ i ) a [ i ] = find ( i - 1 , i ) + i ; Scanner scanner = new Scanner ( System . in ) ; int caseNumber = scanner . nextInt ( ) ; for ( int cases = 0 ; cases < caseNumber ; ++ cases ) { int a1 = scanner . nextInt ( ) ; int a2 = scanner . nextInt ( ) ; int b1 = scanner . nextInt ( ) ; int b2 = scanner . nextInt ( ) ; BigInteger ans = new BigInteger ( "0" ) ; for ( int i = a1 ; i <= a2 ; ++ i ) { int up = b2 ; int low = a [ i ] ; if ( b1 > low ) low = b1 ; if ( low > up ) continue ; ans = ans . add ( new BigInteger ( Integer . toString ( up - low + 1 ) ) ) ; } for ( int i = b1 ; i <= b2 ; ++ i ) { int up = a2 ; int low = a [ i ] ; if ( a1 > low ) low = a1 ; if ( low > up ) continue ; ans = ans . add ( new BigInteger ( Integer . toString ( up - low + 1 ) ) ) ; } System . out . println ( " Case ▁ # " + ( cases + 1 ) + " : ▁ " + ans ) ; } } }

import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class NumberGame { public static void main ( String args [ ] ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( " C - large . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( " C . out " ) ) ) ; long alow , ahigh , blow , bhigh , cases ; cases = Integer . parseInt ( in . readLine ( ) ) ; double gold = ( 1 + Math . sqrt ( 5 ) ) / 2 ; for ( int i = 1 ; i <= cases ; i ++ ) { StringTokenizer st = new StringTokenizer ( in . readLine ( ) ) ; alow = Integer . parseInt ( st . nextToken ( ) ) ; ahigh = Integer . parseInt ( st . nextToken ( ) ) ; blow = Integer . parseInt ( st . nextToken ( ) ) ; bhigh = Integer . parseInt ( st . nextToken ( ) ) ; long count = ( ahigh - alow + 1 ) * ( bhigh - blow + 1 ) ; for ( long a = alow ; a <= ahigh ; a ++ ) { long low = Math . max ( ( long ) ( a / gold + 1 ) , blow ) ; long high = Math . min ( bhigh , ( long ) ( a * gold ) ) ; if ( low <= bhigh && high >= blow ) count -= high - low + 1 ; } out . println ( " Case ▁ # " + i + " : ▁ " + count ) ; } out . close ( ) ; } }

import static java . lang . Math . * ; import static java . util . Arrays . * ; import java . util . * ; public class C { boolean TIME = false ; Scanner sc ; void solve ( ) { int A1 = sc . nextInt ( ) , A2 = sc . nextInt ( ) ; int B1 = sc . nextInt ( ) , B2 = sc . nextInt ( ) ; long res = 0 ; for ( int b = B1 ; b <= B2 ; b ++ ) { int min = ( int ) ( ceil ( 1.0 / R * b ) ) ; int max = ( int ) ( floor ( R * b ) ) ; min = max ( min , A1 ) ; max = min ( max , A2 ) ; res += A2 - A1 + 1 ; if ( min <= max ) { res -= max - min + 1 ; } } System . out . println ( res ) ; } double R = ( sqrt ( 5 ) + 1 ) / 2 ; void run ( ) { long time = System . currentTimeMillis ( ) ; sc = new Scanner ( System . in ) ; int on = sc . nextInt ( ) ; for ( int o = 1 ; o <= on ; o ++ ) { double t = ( System . currentTimeMillis ( ) - time ) * 1e-3 ; if ( TIME ) System . err . printf ( " % 03d / %03d ▁ % .3f / % . 3f % n " , o , on , t , t / ( o - 1 ) * on ) ; System . out . printf ( " Case ▁ # % d : ▁ " , o ) ; solve ( ) ; System . out . flush ( ) ; } } void debug ( Object ... os ) { System . err . println ( deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new C ( ) . run ( ) ; } }

import java . io . FileInputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Number { private Scanner fin ; private PrintStream fout ; public Number ( String in , String out ) { try { fin = new Scanner ( new FileInputStream ( in ) ) ; fout = new PrintStream ( out ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } private void run ( ) { int cas = fin . nextInt ( ) ; for ( int t = 1 ; t <= cas ; ++ t ) { fout . println ( " Case ▁ # " + t + " : ▁ " + process ( ) ) ; } } private int startpos [ ] ; private long process ( ) { int a1 , a2 , b1 , b2 ; a1 = fin . nextInt ( ) ; a2 = fin . nextInt ( ) ; b1 = fin . nextInt ( ) ; b2 = fin . nextInt ( ) ; startpos = new int [ a2 + 1 ] ; if ( a2 >= 1 ) startpos [ 1 ] = 1 ; if ( a2 >= 2 ) startpos [ 2 ] = 2 ; int k = 1 ; for ( int i = 3 ; i <= a2 ; ++ i ) { while ( i >= startpos [ k ] + k ) k ++ ; startpos [ i ] = k ; } long res = 0 ; for ( int i = a1 ; i <= a2 ; ++ i ) { res += count ( i , b1 , b2 ) ; } return res ; } private long count ( int id , int b1 , int b2 ) { long res = b2 - b1 + 1 ; if ( b1 < startpos [ id ] ) { if ( b2 < startpos [ id ] ) return res ; else if ( b2 < startpos [ id ] + id ) { return res - ( b2 - startpos [ id ] + 1 ) ; } else { return res - id ; } } else if ( b1 < startpos [ id ] + id ) { if ( b2 < startpos [ id ] + id ) { return 0 ; } else { return b2 - ( startpos [ id ] + id ) + 1 ; } } else { return res ; } } public static void main ( String [ ] args ) { new Number ( " c . in " , " c . out " ) . run ( ) ; } }

import math NEW_LINE phi = ( 1 + math . sqrt ( 5 ) ) / 2 NEW_LINE for t in xrange ( int ( raw_input ( ) ) ) : NEW_LINE INDENT A1 , A2 , B1 , B2 = map ( int , raw_input ( ) . split ( " ▁ " ) ) NEW_LINE c = 0 NEW_LINE for a in xrange ( A1 , A2 + 1 ) : NEW_LINE INDENT start = int ( math . ceil ( a / phi ) ) NEW_LINE end = int ( math . floor ( a * phi ) ) + 1 NEW_LINE istart = max ( B1 , start ) NEW_LINE iend = min ( B2 + 1 , end ) NEW_LINE dist = iend - istart NEW_LINE c += dist if dist > 0 else 0 NEW_LINE DEDENT c = ( A2 - A1 + 1 ) * ( B2 - B1 + 1 ) - c NEW_LINE print " Case ▁ # % i : ▁ % i " % ( t + 1 , c ) NEW_LINE DEDENT

import sys NEW_LINE def solve ( a , b ) : NEW_LINE INDENT if a == 0 or b == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if a == b : NEW_LINE INDENT return 0 NEW_LINE DEDENT if a < b : NEW_LINE INDENT return solve ( b , a ) NEW_LINE DEDENT if a >= 2 * b : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 - solve ( a % b , b ) NEW_LINE DEDENT DEDENT def num ( a , b1 , b2 ) : NEW_LINE INDENT low = 0 NEW_LINE high = a - 1 NEW_LINE far = 0 NEW_LINE while low <= high : NEW_LINE INDENT mid = ( low + high ) / 2 NEW_LINE if solve ( a , mid ) == 1 : NEW_LINE INDENT low = mid + 1 NEW_LINE far = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid - 1 NEW_LINE DEDENT DEDENT add = 0 NEW_LINE if b1 <= far : NEW_LINE INDENT add = min ( b2 , far ) - b1 + 1 NEW_LINE DEDENT actual = 0 NEW_LINE for b in range ( b1 , b2 + 1 ) : NEW_LINE INDENT if b < a and solve ( a , b ) == 1 : NEW_LINE INDENT actual += 1 NEW_LINE DEDENT DEDENT if add != actual : NEW_LINE INDENT print " ERRROR ! ▁ % d ▁ % d ▁ % d ▁ % d " % ( a , add , actual , far ) NEW_LINE DEDENT return add NEW_LINE DEDENT T = int ( sys . stdin . readline ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT s = sys . stdin . readline ( ) . split ( ) NEW_LINE a1 = int ( s [ 0 ] ) NEW_LINE a2 = int ( s [ 1 ] ) NEW_LINE b1 = int ( s [ 2 ] ) NEW_LINE b2 = int ( s [ 3 ] ) NEW_LINE ans = 0 NEW_LINE for a in range ( a1 , a2 + 1 ) : NEW_LINE INDENT ans += num ( a , b1 , b2 ) NEW_LINE DEDENT for b in range ( b1 , b2 + 1 ) : NEW_LINE INDENT ans += num ( b , a1 , a2 ) NEW_LINE DEDENT print " Case ▁ # % d : ▁ % d " % ( t + 1 , ans ) NEW_LINE DEDENT

import sys , itertools NEW_LINE fst = [ 1 , 1 ] NEW_LINE def pre ( ) : NEW_LINE INDENT global fst NEW_LINE for i in xrange ( 2 , 1000001 ) : NEW_LINE INDENT fst . append ( i + 1 - fst [ fst [ i - 1 ] ] ) NEW_LINE DEDENT DEDENT def solve ( X ) : NEW_LINE INDENT global fst NEW_LINE A1 , A2 , B1 , B2 = ( int ( i ) for i in raw_input ( ) . strip ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE for i in xrange ( A1 , A2 + 1 ) : NEW_LINE INDENT f , l = fst [ i ] , fst [ i ] + i - 1 NEW_LINE if B2 < f or B1 > l : NEW_LINE INDENT ans += ( B2 - B1 + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT if B1 >= f and B2 <= l : NEW_LINE INDENT pass NEW_LINE DEDENT elif B1 <= f and B2 >= l : NEW_LINE INDENT ans += ( B2 - B1 + 1 ) - ( l - f + 1 ) NEW_LINE DEDENT elif B1 > f : NEW_LINE INDENT ans += ( B2 - l ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += ( f - B1 ) NEW_LINE DEDENT DEDENT DEDENT print " Case ▁ # % d : " % ( X , ) , ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT pre ( ) NEW_LINE T = int ( raw_input ( ) ) NEW_LINE for i in xrange ( 1 , T + 1 ) : NEW_LINE INDENT solve ( i ) NEW_LINE DEDENT DEDENT

filename = " C - small . in " NEW_LINE ll = - 1 NEW_LINE for line in open ( filename , " r " ) : NEW_LINE INDENT ll += 1 NEW_LINE if ll == 0 : continue NEW_LINE data = map ( lambda x : long ( x ) , line . rstrip ( ) . split ( ) ) NEW_LINE ret = 0 NEW_LINE for a in range ( data [ 0 ] , data [ 1 ] + 1 ) : NEW_LINE INDENT b_min = max ( ( a + 1 ) / 2 , data [ 2 ] ) NEW_LINE b_max = min ( a * 2 , data [ 3 ] ) NEW_LINE if b_min > b_max : NEW_LINE INDENT ret += data [ 3 ] - data [ 2 ] + 1 NEW_LINE continue NEW_LINE DEDENT ret += b_min - data [ 2 ] + data [ 3 ] - b_max NEW_LINE bs = range ( b_min , b_max + 1 ) NEW_LINE for b in bs : NEW_LINE INDENT atmp = a NEW_LINE turn = 1 NEW_LINE while True : NEW_LINE INDENT if atmp > b : NEW_LINE INDENT if ( atmp - 1 ) / b >= 2 : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT atmp -= b NEW_LINE DEDENT DEDENT elif atmp == b : NEW_LINE INDENT turn += 1 NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT if ( b - 1 ) / atmp >= 2 : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT b -= atmp NEW_LINE DEDENT DEDENT turn += 1 NEW_LINE DEDENT if turn % 2 == 1 : NEW_LINE INDENT ret += 1 NEW_LINE DEDENT DEDENT DEDENT print " Case ▁ # % d : ▁ % d " % ( ll , ret ) NEW_LINE DEDENT

import sys NEW_LINE import re NEW_LINE import os NEW_LINE import time NEW_LINE from math import * NEW_LINE from itertools import * NEW_LINE from pprint import pprint NEW_LINE if len ( sys . argv ) != 2 : NEW_LINE INDENT print ' specify ▁ input ▁ file ' NEW_LINE exit ( ) NEW_LINE DEDENT startTime = time . clock ( ) NEW_LINE fin = open ( sys . argv [ 1 ] ) NEW_LINE fout = open ( os . path . splitext ( sys . argv [ 1 ] ) [ 0 ] + ' . out ' , ' w ' ) NEW_LINE phi = 0.5 * ( sqrt ( 5 ) + 1 ) NEW_LINE def loosing ( a , b ) : NEW_LINE INDENT return a <= b <= int ( phi * a ) or b <= a <= int ( phi * b ) NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT a1 , a2 , b1 , b2 = map ( int , next ( fin ) . split ( ) ) NEW_LINE n = 0 NEW_LINE for a in range ( a1 , a2 + 1 ) : NEW_LINE INDENT for b in range ( b1 , b2 + 1 ) : NEW_LINE INDENT if not loosing ( a , b ) : NEW_LINE INDENT n += 1 NEW_LINE DEDENT DEDENT DEDENT print >> fout , n NEW_LINE DEDENT numCases = int ( next ( fin ) ) NEW_LINE for caseNo in range ( numCases ) : NEW_LINE INDENT print ' \b ' * 10 , 100 * caseNo / numCases , ' % ' , NEW_LINE print >> fout , ' Case ▁ # % s : ' % ( caseNo + 1 ) , NEW_LINE solve ( ) NEW_LINE DEDENT fin . close ( ) NEW_LINE fout . close ( ) NEW_LINE print ' \b ' * 10 + ' it ▁ took ▁ % .1fs ' % ( time . clock ( ) - startTime ) NEW_LINE


import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . Scanner ; public class c { public static void main ( String [ ] Args ) throws Exception { Scanner sc = new Scanner ( new File ( " C - large . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( new File ( " c . out " ) ) ) ) ; int cc = 0 ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { long n = sc . nextLong ( ) ; long pos = sc . nextLong ( ) ; int dep = 0 ; long v = 0 ; while ( pos > ( ( v << 1 ) | 1 ) ) { v = ( ( v << 1 ) | 1 ) ; dep ++ ; } n -= v ; pos -= v + 1 ; v ++ ; if ( n % v > pos ) n = n / v + 1 ; else n = n / v ; out . printf ( " Case ▁ # % d : ▁ % d ▁ % d % n " , ++ cc , n >> 1 , ( n - 1 ) >> 1 ) ; } out . close ( ) ; } }

import java . math . BigInteger ; import java . util . * ; import java . io . * ; public class Main { private static BigInteger solve ( BigInteger n , BigInteger m ) { if ( m . equals ( BigInteger . ONE ) ) return n ; n = n . subtract ( BigInteger . ONE ) ; m = m . subtract ( BigInteger . ONE ) ; BigInteger x , y , sumX , sumY ; y = n . shiftRight ( 1 ) ; x = n . subtract ( y ) ; sumX = sumY = BigInteger . ONE ; for ( ; m . compareTo ( sumX . add ( sumY ) ) > 0 ; ) { m = m . subtract ( sumX . add ( sumY ) ) ; x = x . subtract ( BigInteger . ONE ) ; y = y . subtract ( BigInteger . ONE ) ; BigInteger tx , ty , tSumX = sumX , tSumY = sumY ; tx = x . shiftRight ( 1 ) ; x = x . subtract ( tx ) ; ty = y . subtract ( y . shiftRight ( 1 ) ) ; y = y . shiftRight ( 1 ) ; if ( tx . equals ( x ) ) { sumX = sumX . add ( tSumX ) ; } else { sumY = sumY . add ( tSumX ) ; } if ( ty . equals ( x ) ) { sumX = sumX . add ( tSumY ) ; } else { sumY = sumY . add ( tSumY ) ; } } return m . compareTo ( sumX ) <= 0 ? x : y ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int t = in . nextInt ( ) ; for ( int i = 1 ; i <= t ; ++ i ) { BigInteger n = in . nextBigInteger ( ) ; BigInteger m = in . nextBigInteger ( ) ; BigInteger sum = solve ( n , m ) ; sum = sum . subtract ( BigInteger . ONE ) ; BigInteger div = sum . shiftRight ( 1 ) ; System . out . println ( " Case ▁ # " + i + " : ▁ " + sum . subtract ( div ) + " ▁ " + div ) ; } } }

package zhang00000 ; import com . sun . tools . javac . jvm . Code ; import org . apache . commons . math3 . complex . Complex ; import java . io . * ; import java . util . * ; import java . util . stream . * ; import static java . util . stream . Collectors . * ; public class App { final int di [ ] = { 1 , - 1 , 0 , 0 , 1 , - 1 , 1 , - 1 } ; final int dj [ ] = { 0 , 0 , 1 , - 1 , 1 , - 1 , - 1 , 1 } ; final int diK [ ] = { - 2 , - 2 , - 1 , 1 , 2 , 2 , 1 , - 1 } ; final int djK [ ] = { - 1 , 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 } ; public static void main ( String [ ] args ) { if ( args . length == 1 ) { String filename = " src / main / java / zhang00000 / " + args [ 0 ] + " . in " ; if ( ! filename . isEmpty ( ) ) try { System . setIn ( new FileInputStream ( filename ) ) ; } catch ( FileNotFoundException e ) { System . out . println ( e . getMessage ( ) ) ; System . exit ( 1 ) ; } } Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int t = Integer . valueOf ( in . nextLine ( ) ) ; for ( int number = 1 ; number <= t ; number ++ ) { long n = in . nextLong ( ) ; long k = in . nextLong ( ) ; int d = Long . toBinaryString ( k ) . length ( ) - 1 ; long prev = ( n - k + Long . highestOneBit ( k ) ) >> d ; long max = prev / 2 ; long min = ( prev - 1 ) / 2 ; System . out . println ( " Case ▁ # " + number + " : ▁ " + max + " ▁ " + min ) ; } } }

import java . util . * ; import java . io . * ; public class Main { public static long [ ] solve ( long N , long K ) { if ( K == 1 ) { long [ ] arr = new long [ 2 ] ; arr [ 0 ] = N / 2 ; arr [ 1 ] = ( N - 1 ) / 2 ; return arr ; } if ( K % 2 == 0 ) { return solve ( N / 2 , K / 2 ) ; } return solve ( ( N - 1 ) / 2 , K / 2 ) ; } public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new FileReader ( " C - large . in " ) ) ; BufferedWriter bw = new BufferedWriter ( new FileWriter ( " solve . txt " ) ) ; int T = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; StringTokenizer s ; for ( int i = 1 ; i <= T ; i ++ ) { bw . write ( " Case ▁ # " + i + " : ▁ " ) ; s = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; long N = Long . parseLong ( s . nextToken ( ) ) ; long K = Long . parseLong ( s . nextToken ( ) ) ; long [ ] arr = solve ( N , K ) ; bw . write ( arr [ 0 ] + " ▁ " + arr [ 1 ] + " \n " ) ; } br . close ( ) ; bw . close ( ) ; return ; } }

import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int testCount = in . nextInt ( ) ; for ( int testNo = 1 ; testNo <= testCount ; testNo ++ ) { solve ( testNo , in ) ; } } private static void solve ( int testNo , Scanner in ) { long n = in . nextLong ( ) ; long k = in . nextLong ( ) ; System . out . println ( " Case ▁ # " + testNo + " : ▁ " + calc ( n , k ) ) ; } private static String calc ( long n , long k ) { TreeMap < Long , Long > treeMap = new TreeMap < > ( ) ; treeMap . put ( n , 1L ) ; while ( k > 0 ) { Map . Entry < Long , Long > entry = treeMap . lastEntry ( ) ; treeMap . remove ( entry . getKey ( ) ) ; if ( k <= entry . getValue ( ) ) { return entry . getKey ( ) / 2 + " ▁ " + ( entry . getKey ( ) - 1 ) / 2 ; } else { k -= entry . getValue ( ) ; if ( entry . getKey ( ) / 2 > 0 ) { long key = entry . getKey ( ) / 2 ; treeMap . put ( key , treeMap . getOrDefault ( key , 0L ) + entry . getValue ( ) ) ; } if ( ( entry . getKey ( ) - 1 ) / 2 > 0 ) { long key = ( entry . getKey ( ) - 1 ) / 2 ; treeMap . put ( key , treeMap . getOrDefault ( key , 0L ) + entry . getValue ( ) ) ; } } } throw new RuntimeException ( ) ; } }

for tc in range ( input ( ) ) : NEW_LINE INDENT N , K = map ( int , raw_input ( ) . split ( ) ) NEW_LINE s = 1 NEW_LINE x = N NEW_LINE lc = 1 NEW_LINE sc = 0 NEW_LINE while K > s : NEW_LINE INDENT if x % 2 == 0 : NEW_LINE INDENT lc , sc = lc , lc + 2 * sc NEW_LINE DEDENT else : NEW_LINE INDENT lc , sc = 2 * lc + sc , sc NEW_LINE DEDENT x = x / 2 NEW_LINE K = K - s NEW_LINE s = s * 2 NEW_LINE DEDENT x = x if K <= lc else x - 1 NEW_LINE if x % 2 == 0 : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d ▁ % d " % ( tc + 1 , x / 2 , x / 2 - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d ▁ % d " % ( tc + 1 , x / 2 , x / 2 ) NEW_LINE DEDENT DEDENT

from itertools import groupby NEW_LINE def solve ( ) : NEW_LINE INDENT n , k = [ int ( w ) for w in input ( ) . split ( ) ] NEW_LINE a = [ ( n , 1 ) ] NEW_LINE while True : NEW_LINE INDENT b = [ ] NEW_LINE for d , cnt in a : NEW_LINE INDENT if cnt < k : NEW_LINE INDENT k -= cnt NEW_LINE b . append ( ( ( d - 1 ) // 2 , cnt ) ) NEW_LINE b . append ( ( d // 2 , cnt ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return " { } ▁ { } " . format ( d // 2 , ( d - 1 ) // 2 ) NEW_LINE DEDENT DEDENT a = [ ( f , sum ( s for _ , s in g ) ) for f , g in groupby ( sorted ( b ) , key = lambda t : t [ 0 ] ) ] NEW_LINE a = list ( reversed ( [ x for x in a if x [ 0 ] > 0 ] ) ) NEW_LINE DEDENT DEDENT def prepare_input ( ) : NEW_LINE INDENT local = False NEW_LINE task = ' C ' NEW_LINE attempt = - 1 NEW_LINE import sys NEW_LINE if local : NEW_LINE INDENT sys . stdin = open ( " . . / input . txt " , " r " ) NEW_LINE DEDENT else : NEW_LINE INDENT filename = " . . / { } - small - 2 - attempt { } " . format ( task , attempt ) if attempt >= 0 else " . . / { } - large " . format ( task ) NEW_LINE sys . stdin = open ( filename + " . in " , " r " ) NEW_LINE sys . stdout = open ( filename + " . out " , " w " ) NEW_LINE print ( " filename : " , filename [ 3 : ] , file = sys . stderr ) NEW_LINE DEDENT DEDENT prepare_input ( ) NEW_LINE tests = int ( input ( ) ) NEW_LINE for test in range ( 1 , tests + 1 ) : NEW_LINE INDENT res = solve ( ) NEW_LINE print ( " Case ▁ # { } : ▁ { } " . format ( test , res ) ) NEW_LINE DEDENT

import sys NEW_LINE import numpy as np NEW_LINE import heapq NEW_LINE def solve ( n , k ) : NEW_LINE INDENT intervals = { n : 1 } NEW_LINE lens = [ - n ] NEW_LINE ls = 0 NEW_LINE rs = 0 NEW_LINE while k > 0 : NEW_LINE INDENT val = - heapq . heappop ( lens ) NEW_LINE num = intervals [ val ] NEW_LINE del intervals [ val ] NEW_LINE k = k - num NEW_LINE ls = int ( ( val - 1 ) / 2 ) NEW_LINE rs = val - ls - 1 NEW_LINE if not ls in intervals : NEW_LINE INDENT intervals [ ls ] = 0 NEW_LINE heapq . heappush ( lens , - ls ) NEW_LINE DEDENT if not rs in intervals : NEW_LINE INDENT intervals [ rs ] = 0 NEW_LINE heapq . heappush ( lens , - rs ) NEW_LINE DEDENT intervals [ rs ] = intervals [ rs ] + num NEW_LINE intervals [ ls ] = intervals [ ls ] + num NEW_LINE DEDENT return ( max ( ls , rs ) , min ( ls , rs ) ) NEW_LINE DEDENT t = int ( raw_input ( ) ) NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT n , m = [ s for s in raw_input ( ) . split ( " ▁ " ) ] NEW_LINE data = [ int ( a ) for a in list ( str ( n ) ) ] NEW_LINE result = solve ( int ( n ) , int ( m ) ) NEW_LINE print ( " Case ▁ # { } : ▁ { } ▁ { } " . format ( i , result [ 0 ] , result [ 1 ] ) ) NEW_LINE DEDENT

from collections import defaultdict NEW_LINE IN = open ( ' input . txt ' , ' r ' ) NEW_LINE OUT = open ( ' output . txt ' , ' w ' ) NEW_LINE NUM_TESTS = int ( IN . readline ( ) ) NEW_LINE for test in xrange ( NUM_TESTS ) : NEW_LINE INDENT N , K = map ( int , IN . readline ( ) . split ( ) ) NEW_LINE queue = defaultdict ( int ) NEW_LINE queue [ N ] = 1 NEW_LINE sizes = [ ] NEW_LINE binN = ' { : b } ' . format ( N ) NEW_LINE for i in xrange ( 1 , len ( binN ) + 1 ) : NEW_LINE INDENT sizes . append ( int ( binN [ : i ] , 2 ) - 1 ) NEW_LINE sizes . append ( int ( binN [ : i ] , 2 ) ) NEW_LINE DEDENT sizes = sizes [ : : - 1 ] NEW_LINE for chunkSize in sizes : NEW_LINE INDENT chunkNum = queue [ chunkSize ] NEW_LINE minNext = ( chunkSize - 1 ) / 2 NEW_LINE maxNext = ( chunkSize - 1 ) - minNext NEW_LINE if K <= chunkNum : NEW_LINE INDENT answer = ( maxNext , minNext ) NEW_LINE break NEW_LINE DEDENT K -= chunkNum NEW_LINE if maxNext == minNext : NEW_LINE INDENT queue [ maxNext ] += 2 * chunkNum NEW_LINE DEDENT else : NEW_LINE INDENT queue [ maxNext ] += chunkNum NEW_LINE queue [ minNext ] += chunkNum NEW_LINE DEDENT DEDENT OUT . write ( ' Case ▁ # { } : ▁ { } ▁ { } \n ' . format ( test + 1 , answer [ 0 ] , answer [ 1 ] ) ) NEW_LINE print test + 1 , answer NEW_LINE DEDENT IN . close ( ) NEW_LINE OUT . close ( ) NEW_LINE

infilecode = " CLI " NEW_LINE import sys NEW_LINE mapping = { " A " : " A " , " B " : " B " , " C " : " C " , " D " : " D " , " E " : " E " , " X " : " example " , " S " : " - small " , " L " : " - large " , " P " : " - practice " , "0" : " - attempt0" , "1" : " - attempt1" , "2" : " - attempt2" , " z " : " - 1" , " Z " : " - 2" , " I " : " . in " , " T " : " . txt " } NEW_LINE infile = " " . join ( mapping [ c ] for c in infilecode ) NEW_LINE outfile = infile . replace ( " . in " , " " ) + " . out . txt " NEW_LINE sys . stdin = open ( infile , ' r ' ) NEW_LINE output = open ( outfile , ' w ' ) NEW_LINE T = int ( input ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE print ( N , K ) NEW_LINE sizes = [ N , N + 1 ] NEW_LINE num = [ 1 , 0 ] NEW_LINE while K > sum ( num ) : NEW_LINE INDENT a , b = sizes NEW_LINE K -= sum ( num ) NEW_LINE sizes = [ ( a - 1 ) // 2 , b // 2 ] NEW_LINE if a % 2 == 0 : NEW_LINE INDENT num = [ num [ 0 ] , num [ 0 ] + num [ 1 ] * 2 ] NEW_LINE DEDENT else : NEW_LINE INDENT num = [ num [ 0 ] * 2 + num [ 1 ] , num [ 1 ] ] NEW_LINE DEDENT print ( sizes , num , K ) NEW_LINE DEDENT if K <= num [ 1 ] : NEW_LINE INDENT size = sizes [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT size = sizes [ 0 ] NEW_LINE DEDENT R = size // 2 NEW_LINE L = ( size - 1 ) // 2 NEW_LINE answer = str ( R ) + " ▁ " + str ( L ) NEW_LINE print ( " Case ▁ # % d : " % case , answer ) NEW_LINE print ( " Case ▁ # % d : " % case , answer , file = output ) NEW_LINE DEDENT


import java . util . * ; import java . math . * ; public class B { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; int caseN = cin . nextInt ( ) ; for ( int caseI = 1 ; caseI <= caseN ; caseI ++ ) { int n = cin . nextInt ( ) ; BigInteger [ ] times = new BigInteger [ n ] ; for ( int i = 0 ; i < n ; i ++ ) times [ i ] = new BigInteger ( cin . next ( ) ) ; BigInteger ans = times [ 0 ] . subtract ( times [ 1 ] ) . abs ( ) ; for ( int i = 2 ; i < n ; i ++ ) ans = ans . gcd ( times [ i ] . subtract ( times [ i - 1 ] ) . abs ( ) ) ; ans = ans . subtract ( times [ 0 ] . mod ( ans ) ) . mod ( ans ) ; System . out . printf ( " Case ▁ # % d : ▁ % s " , caseI , ans . toString ( ) ) ; System . out . println ( ) ; } } }

import java . math . BigInteger ; import java . util . * ; public class Main { Scanner in = new Scanner ( System . in ) ; BigInteger [ ] data ; BigInteger solve ( ) { int N = in . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) data [ i ] = in . nextBigInteger ( ) ; Arrays . sort ( data , 0 , N ) ; BigInteger g = data [ 1 ] . subtract ( data [ 0 ] ) ; for ( int i = 2 ; i < N ; i ++ ) g = g . gcd ( data [ i ] . subtract ( data [ i - 1 ] ) ) ; return g . subtract ( data [ 0 ] . remainder ( g ) ) . remainder ( g ) ; } void cases ( ) { data = new BigInteger [ 1000 ] ; int T = in . nextInt ( ) ; for ( int c = 1 ; c <= T ; c ++ ) System . out . println ( " Case ▁ # " + c + " : ▁ " + solve ( ) ) ; } public static void main ( String [ ] args ) throws Exception { ( new Main ( ) ) . cases ( ) ; } }

import java . io . * ; import java . math . * ; import java . util . * ; public class Main { Scanner in ; BufferedReader br ; PrintWriter out ; public void run ( ) throws Exception { in = new Scanner ( System . in ) ; out = new PrintWriter ( System . out ) ; int tests = in . nextInt ( ) ; for ( int test = 1 ; test <= tests ; test ++ ) { TreeSet < BigInteger > hs = new TreeSet < BigInteger > ( ) ; int nnn = in . nextInt ( ) ; for ( int i = 0 ; i < nnn ; i ++ ) hs . add ( in . nextBigInteger ( ) ) ; int n = hs . size ( ) ; BigInteger [ ] a = new BigInteger [ n ] ; nnn = 0 ; for ( BigInteger x : hs ) a [ nnn ++ ] = x ; BigInteger g = a [ 1 ] . subtract ( a [ 0 ] ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { g = g . gcd ( a [ j ] . subtract ( a [ i ] ) ) ; } } BigInteger mn = BigInteger . valueOf ( 10 ) . pow ( 100 ) ; BigInteger g1 = g . subtract ( BigInteger . ONE ) ; for ( int i = 0 ; i < n ; i ++ ) { BigInteger cur = a [ i ] . add ( g1 ) . divide ( g ) . multiply ( g ) . subtract ( a [ i ] ) ; mn = mn . min ( cur ) ; } out . println ( " Case ▁ # " + test + " : ▁ " + mn ) ; } out . close ( ) ; } public static void main ( String [ ] args ) throws Exception { new Main ( ) . run ( ) ; } }

import java . io . * ; import java . util . * ; import java . math . * ; public class Main implements Runnable { static Scanner scanner ; static BufferedReader input ; static PrintWriter pw ; public static void main ( String [ ] args ) throws Exception { new Thread ( new Main ( ) ) . start ( ) ; } public void run ( ) { try { input = new BufferedReader ( new FileReader ( " input . txt " ) ) ; scanner = new Scanner ( input ) ; pw = new PrintWriter ( new File ( " output . txt " ) ) ; solve ( ) ; pw . close ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } } public void solve ( ) throws Exception { int qq = scanner . nextInt ( ) ; for ( int ii = 0 ; ii < qq ; ii ++ ) { int n = scanner . nextInt ( ) ; BigInteger [ ] a = new BigInteger [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scanner . nextBigInteger ( ) ; } BigInteger x = BigInteger . ZERO ; for ( int i = 1 ; i < n ; i ++ ) { x = x . gcd ( a [ i ] . subtract ( a [ 0 ] ) ) ; } BigInteger ans = ( x . subtract ( a [ 0 ] . mod ( x ) ) ) . mod ( x ) ; pw . println ( " Case ▁ # " + ( ii + 1 ) + " : ▁ " + ans ) ; } } }

import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class B { public static void main ( String args [ ] ) throws Exception { String inFile = " B - large . in " ; String outFile = inFile + " . out " ; LineNumberReader lin = new LineNumberReader ( new InputStreamReader ( new FileInputStream ( inFile ) ) ) ; PrintWriter out = new PrintWriter ( new File ( outFile ) ) ; int NCASE = Integer . parseInt ( lin . readLine ( ) ) ; for ( int CASE = 1 ; CASE <= NCASE ; CASE ++ ) { out . print ( " Case ▁ # " + CASE + " : ▁ " ) ; String l = lin . readLine ( ) ; String ll [ ] = l . split ( " ▁ " ) ; int N = Integer . parseInt ( ll [ 0 ] ) ; BigInteger t [ ] = new BigInteger [ N ] ; for ( int i = 0 ; i < N ; i ++ ) t [ i ] = new BigInteger ( ll [ i + 1 ] ) ; BigInteger T = null ; for ( int a = 0 ; a < N ; a ++ ) for ( int b = a ; ++ b < N ; ) { BigInteger d = t [ a ] . subtract ( t [ b ] ) . abs ( ) ; if ( T == null ) T = d ; else T = T . gcd ( d ) ; } BigInteger y = t [ 0 ] . mod ( T ) ; if ( ! y . equals ( BigInteger . ZERO ) ) y = T . subtract ( y ) ; out . println ( y ) ; } lin . close ( ) ; out . close ( ) ; } }

C = int ( raw_input ( ) ) NEW_LINE from fractions import gcd NEW_LINE for case in xrange ( 1 , C + 1 ) : NEW_LINE INDENT ts = [ int ( t ) for t in raw_input ( ) . split ( ) [ 1 : ] ] NEW_LINE m = min ( ts ) NEW_LINE td = [ t - m for t in ts ] NEW_LINE T = reduce ( gcd , td ) NEW_LINE print " Case ▁ # " + str ( case ) + " : " , ( T - m ) % T NEW_LINE DEDENT

import sys NEW_LINE def readline ( ) : NEW_LINE INDENT return sys . stdin . readline ( ) [ : - 1 ] NEW_LINE DEDENT def readnlines ( n ) : NEW_LINE INDENT l = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT l . append ( readline ( ) ) NEW_LINE DEDENT DEDENT def gcd ( a , b ) : NEW_LINE INDENT if a >= b : NEW_LINE INDENT m = a % b NEW_LINE if m == 0 : NEW_LINE INDENT return b NEW_LINE DEDENT else : NEW_LINE INDENT return gcd ( b , m ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return gcd ( b , a ) NEW_LINE DEDENT DEDENT def truc ( x0 , x ) : NEW_LINE INDENT y = abs ( x0 - x ) NEW_LINE if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return y NEW_LINE DEDENT DEDENT for curcase in range ( 1 , int ( readline ( ) ) + 1 ) : NEW_LINE INDENT l = map ( int , readline ( ) . split ( ) ) NEW_LINE n = l [ 0 ] NEW_LINE l = l [ 1 : ] NEW_LINE x0 = l [ 0 ] NEW_LINE diff = map ( lambda x : abs ( x0 - x ) , l [ 1 : ] ) NEW_LINE cur = diff [ 0 ] NEW_LINE for i in range ( 1 , len ( diff ) ) : NEW_LINE INDENT if cur == 0 : NEW_LINE INDENT cur = diff [ i ] NEW_LINE DEDENT if diff [ i ] != 0 : NEW_LINE INDENT cur = gcd ( cur , diff [ i ] ) NEW_LINE DEDENT DEDENT todo = x0 % cur NEW_LINE if todo == 0 : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( curcase , 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print " Case ▁ # % d : ▁ % d " % ( curcase , cur - todo ) NEW_LINE DEDENT DEDENT

from __future__ import division NEW_LINE import collections NEW_LINE import itertools NEW_LINE import sys NEW_LINE class gcj : NEW_LINE INDENT IN = sys . stdin NEW_LINE number = 0 NEW_LINE @ classmethod NEW_LINE def case ( cls ) : NEW_LINE INDENT cls . number += 1 NEW_LINE return ' Case ▁ # % d : ' % cls . number NEW_LINE DEDENT @ classmethod NEW_LINE def line ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return type ( line . strip ( ' \n ' ) ) NEW_LINE DEDENT @ classmethod NEW_LINE def splitline ( cls , type = str ) : NEW_LINE INDENT line = cls . IN . readline ( ) NEW_LINE return [ type ( x ) for x in line . split ( ) ] NEW_LINE DEDENT DEDENT def go ( ) : NEW_LINE INDENT c = gcj . line ( int ) NEW_LINE for _ in xrange ( c ) : NEW_LINE INDENT events = gcj . splitline ( int ) [ 1 : ] NEW_LINE print gcj . case ( ) , solve ( events ) NEW_LINE DEDENT DEDENT def gcd ( a , b ) : NEW_LINE INDENT while a != 0 : NEW_LINE INDENT a , b = b % a , a NEW_LINE DEDENT return b NEW_LINE DEDENT def mgcd ( l ) : NEW_LINE INDENT l = iter ( l ) NEW_LINE res = l . next ( ) NEW_LINE for x in l : NEW_LINE INDENT res = gcd ( res , x ) NEW_LINE if res == 1 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def solve ( events ) : NEW_LINE INDENT T = mgcd ( x - y for x in events for y in events if x > y ) NEW_LINE return ( - min ( events ) ) % T NEW_LINE DEDENT go ( ) NEW_LINE

import sys NEW_LINE def GCD ( x , y ) : NEW_LINE INDENT if x < 0 : x = - x NEW_LINE if y < 0 : y = - y NEW_LINE if x + y > 0 : NEW_LINE INDENT g = y NEW_LINE while x > 0 : NEW_LINE INDENT g = x NEW_LINE x = y % x NEW_LINE y = g NEW_LINE DEDENT return g NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def f ( a ) : NEW_LINE INDENT xx = a [ - 1 ] NEW_LINE x = xx NEW_LINE a = a [ : - 1 ] NEW_LINE for i in range ( len ( a ) ) : NEW_LINE INDENT a [ i ] = a [ i ] - x NEW_LINE DEDENT g = a [ 0 ] NEW_LINE for x in a [ 1 : ] : NEW_LINE INDENT g = GCD ( g , x ) NEW_LINE DEDENT g = abs ( g ) NEW_LINE return ( g - xx ) % g NEW_LINE DEDENT c = int ( sys . stdin . readline ( ) ) NEW_LINE for i in range ( 1 , c + 1 ) : NEW_LINE INDENT a = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = a [ 0 ] NEW_LINE a = a [ 1 : ] NEW_LINE assert len ( a ) == n NEW_LINE print " Case ▁ # % d : ▁ % s " % ( i , f ( a ) ) NEW_LINE DEDENT

def debug ( ** a ) : NEW_LINE INDENT print " ▁ " . join ( " % s = % s " % ( k , v ) for ( k , v ) in a . iteritems ( ) ) NEW_LINE DEDENT def read_ints ( ) : NEW_LINE INDENT return [ int ( x ) for x in raw_input ( ) . strip ( ) . split ( ) ] NEW_LINE DEDENT def gcd2 ( a , b ) : NEW_LINE INDENT if a < b : NEW_LINE INDENT return gcd2 ( b , a ) NEW_LINE DEDENT elif b == 0 : NEW_LINE INDENT return a NEW_LINE DEDENT else : NEW_LINE INDENT return gcd2 ( b , a % b ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT [ C ] = read_ints ( ) NEW_LINE for c in xrange ( 1 , C + 1 ) : NEW_LINE INDENT t = read_ints ( ) [ 1 : ] NEW_LINE T = abs ( t [ 0 ] - t [ 1 ] ) NEW_LINE for i in xrange ( len ( t ) ) : NEW_LINE INDENT for j in xrange ( i + 1 , len ( t ) ) : NEW_LINE INDENT T = gcd2 ( T , abs ( t [ i ] - t [ j ] ) ) NEW_LINE DEDENT DEDENT y = - t [ 0 ] % T NEW_LINE print " Case ▁ # % d : ▁ % d " % ( c , y ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT