import java . util . * ; class Main { static long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long n = scan . nextLong ( ) ; int B = 62 ; long [ ] [ ] dp = new long [ 3 ] [ B ] ; dp [ 0 ] [ B - 1 ] = 1 ; for ( int i = B - 2 ; i >= 0 ; -- i ) { for ( int a = 0 ; a <= 2 ; ++ a ) { if ( n >>> i < a ) continue ; long m = n >>> i ; int b = ( int ) ( m / 2 - ( m - a ) / 2 ) ; int c = ( int ) ( ( m - a ) % 2 ) ; if ( c != 0 ) dp [ a ] [ i ] = dp [ b ] [ i + 1 ] % MOD ; else dp [ a ] [ i ] = ( dp [ b ] [ i + 1 ] + dp [ b + 1 ] [ i + 1 ] ) % MOD ; } } long [ ] r = new long [ B ] , s = new long [ B ] ; r [ 0 ] = 1 ; s [ 0 ] = 0 ; for ( int i = 1 ; i < B ; ++ i ) r [ i ] = ( 3 * r [ i - 1 ] + MOD - 1 ) % MOD ; for ( int i = 1 ; i < B ; ++ i ) s [ i ] = ( 3 * s [ i - 1 ] + 1 ) % MOD ; long t = 0 ; for ( int i = B - 2 ; i >= 0 ; -- i ) { if ( ( n & 1L << i ) != 0 ) { t += dp [ 1 ] [ i ] * r [ i ] % MOD ; t += dp [ 2 ] [ i ] * s [ i ] % MOD ; t %= MOD ; } } t = ( t + dp [ 0 ] [ 0 ] ) % MOD ; System . out . println ( t ) ; } }

import java . io . * ; import java . util . * ; public class Main { static Map < Long , Long > check = new HashMap < Long , Long > ( ) ; public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String buf ; String [ ] input ; long N ; N = Long . parseLong ( br . readLine ( ) ) ; System . out . println ( solve ( N ) ) ; } static long solve ( long n ) { long a , b ; if ( n == 0 ) return 1 ; if ( n == 1 ) return 2 ; if ( check . containsKey ( n / 2 ) ) { a = check . get ( n / 2 ) ; } else { a = solve ( n / 2 ) % 1000000007 ; check . put ( n / 2 , a ) ; } if ( check . containsKey ( n / 2 - 1 ) ) { b = check . get ( n / 2 - 1 ) ; } else { b = solve ( n / 2 - 1 ) % 1000000007 ; check . put ( n / 2 - 1 , b ) ; } if ( n % 2 == 1 ) { return ( 2 * a + b ) % 1000000007 ; } else { return ( 2 * b + a ) % 1000000007 ; } } }

import java . util . HashMap ; import java . util . Scanner ; public class Main { public static long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; System . out . println ( f ( n + 1 ) ) ; } static HashMap < Long , Long > mb = new HashMap < > ( ) ; public static long f ( long n ) { Long memo = mb . get ( n ) ; if ( memo != null ) return memo ; if ( n <= 2 ) { return n ; } long res = f ( n / 2 ) + f ( ( n - 1 ) / 2 ) + f ( ( n + 1 ) / 2 ) ; res %= MOD ; mb . put ( n , res ) ; return res ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; public class Main { private static final long MOD = ( long ) ( 1e9 + 7 ) ; private void solve ( ) throws IOException { long n = Long . parseLong ( next ( ) ) + 1 ; String s = Long . toBinaryString ( n ) ; int m = s . length ( ) ; int [ ] a = new int [ m ] ; Arrays . fill ( a , - 1 ) ; long res = 0 ; for ( int i = 0 ; i < m ; i ++ ) if ( s . charAt ( i ) == '1' ) { for ( int j = 0 ; j < i ; j ++ ) { a [ j ] = s . charAt ( j ) - '0' ; } a [ i ] = 0 ; res += calc ( a ) ; res %= MOD ; } out . println ( res ) ; } private long calc ( int [ ] a ) { long q = 1 , w = 0 ; for ( int i = a . length - 1 ; i >= 0 ; i -- ) { long qq = 0 , ww = 0 ; if ( a [ i ] != 1 ) { qq += q ; ww += ( q + w ) ; } if ( a [ i ] != 0 ) { qq += ( q + w ) ; ww += w ; } q = qq % MOD ; w = ww % MOD ; } return q ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st ; PrintWriter out = new PrintWriter ( System . out ) ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } private void run ( ) throws IOException { solve ( ) ; out . close ( ) ; } }

import java . util . HashMap ; import java . util . Scanner ; public class Main { static HashMap < Long , Long > map = new HashMap < > ( ) ; static final long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; sc . close ( ) ; System . out . println ( dfs ( n + 1 ) ) ; } static long dfs ( long n ) { if ( n == 1 ) return 1 ; if ( n == 0 ) return 0 ; if ( map . containsKey ( n ) ) return map . get ( n ) ; long ret ; if ( n % 2 == 1 ) { ret = ( 2 * dfs ( n / 2 ) + dfs ( n / 2 + 1 ) ) % MOD ; map . put ( n , ret ) ; } else { ret = ( 2 * dfs ( n / 2 ) + dfs ( n / 2 - 1 ) ) % MOD ; map . put ( n , ret ) ; } return ret ; } }

from copy import deepcopy NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE IMAX = 200 NEW_LINE JMAX = 2 NEW_LINE def dp ( n ) : NEW_LINE INDENT dp = [ 0 for j in range ( JMAX + 1 ) ] NEW_LINE dp [ 0 ] = 1 NEW_LINE for i in reversed ( range ( IMAX + 1 ) ) : NEW_LINE INDENT pre = deepcopy ( dp ) NEW_LINE dp [ 2 ] += pre [ 1 ] NEW_LINE dp [ 2 ] += 2 * pre [ 2 ] NEW_LINE d = ( ( 1 << i ) & n ) >> i NEW_LINE if d : NEW_LINE INDENT dp [ 1 ] += pre [ 0 ] NEW_LINE dp [ 2 ] += pre [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ 0 ] += pre [ 1 ] NEW_LINE DEDENT dp = take_mod ( dp ) NEW_LINE DEDENT return sum ( dp ) % MOD NEW_LINE DEDENT def take_mod ( dp ) : NEW_LINE INDENT res = [ x % MOD for x in dp ] NEW_LINE return res NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE print ( dp ( n ) ) NEW_LINE DEDENT main ( ) NEW_LINE

N = int ( input ( ) ) NEW_LINE bit = bin ( N ) [ 2 : ] NEW_LINE k = len ( bit ) NEW_LINE dp = [ [ 0 ] * 2 for i in range ( len ( bit ) + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE dp [ 0 ] [ 1 ] = 1 NEW_LINE for i in range ( k ) : NEW_LINE INDENT j = int ( bit [ k - i - 1 ] ) NEW_LINE a , b , c = [ ( 1 , 0 , 0 ) , ( 1 , 1 , 0 ) ] [ j ] NEW_LINE d , e , f = [ ( 1 , 1 , 1 ) , ( 0 , 1 , 2 ) ] [ j ] NEW_LINE dp [ i + 1 ] [ 0 ] = ( a * dp [ i ] [ 0 ] + b * dp [ i ] [ 1 ] + c * 3 ** i ) % 1000000007 NEW_LINE dp [ i + 1 ] [ 1 ] = d * dp [ i ] [ 0 ] + e * dp [ i ] [ 1 ] + f * 3 ** i % 1000000007 NEW_LINE DEDENT print ( dp [ k ] [ 0 ] ) NEW_LINE

def Dp ( x , hl , islim ) : NEW_LINE INDENT if x == len ( digit ) : NEW_LINE INDENT return hl == 0 NEW_LINE DEDENT if f [ x ] [ hl ] [ islim ] : NEW_LINE INDENT return f [ x ] [ hl ] [ islim ] NEW_LINE DEDENT ans = 0 NEW_LINE mx = int ( digit [ x ] ) if islim else 1 NEW_LINE for i in range ( mx + 1 ) : NEW_LINE INDENT ans += Dp ( x + 1 , hl , islim and i == mx ) NEW_LINE if hl != i : NEW_LINE INDENT ans += Dp ( x + 1 , not hl , islim and i == mx ) NEW_LINE DEDENT DEDENT ans %= p NEW_LINE f [ x ] [ hl ] [ islim ] = ans NEW_LINE return ans NEW_LINE DEDENT p = 10 ** 9 + 7 NEW_LINE digit = bin ( int ( input ( ) ) ) [ 2 : ] NEW_LINE f = [ [ [ 0 , 0 ] , [ 0 , 0 ] ] for i in range ( len ( digit ) ) ] NEW_LINE print ( Dp ( 0 , 0 , 1 ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE binN = format ( N , " b " ) . zfill ( 60 ) NEW_LINE mod = 7 + 10 ** 9 NEW_LINE DP = [ [ 0 , 0 , 0 ] for _ in range ( 60 ) ] NEW_LINE if binN [ 0 ] == "0" : NEW_LINE INDENT DP [ 0 ] = [ 1 , 0 , 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT DP [ 0 ] = [ 1 , 1 , 0 ] NEW_LINE DEDENT for i in range ( 1 , 60 ) : NEW_LINE INDENT if binN [ i ] == "0" : NEW_LINE INDENT DP [ i ] [ 0 ] = ( DP [ i - 1 ] [ 0 ] + DP [ i - 1 ] [ 1 ] ) % mod NEW_LINE DP [ i ] [ 1 ] = DP [ i - 1 ] [ 1 ] NEW_LINE DP [ i ] [ 2 ] = ( DP [ i - 1 ] [ 2 ] * 3 + DP [ i - 1 ] [ 1 ] ) % mod NEW_LINE DEDENT else : NEW_LINE INDENT DP [ i ] [ 0 ] = DP [ i - 1 ] [ 0 ] NEW_LINE DP [ i ] [ 1 ] = ( DP [ i - 1 ] [ 0 ] + DP [ i - 1 ] [ 1 ] ) % mod NEW_LINE DP [ i ] [ 2 ] = ( DP [ i - 1 ] [ 2 ] * 3 + DP [ i - 1 ] [ 1 ] * 2 ) % mod NEW_LINE DEDENT DEDENT print ( sum ( DP [ - 1 ] ) % mod ) NEW_LINE

MOD = 10 ** 9 + 7 NEW_LINE N = int ( input ( ) ) NEW_LINE binN = list ( map ( int , bin ( N ) [ 2 : ] ) ) NEW_LINE dp = [ [ 0 ] * 3 for _ in range ( len ( binN ) + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE for i , Ni in enumerate ( binN ) : NEW_LINE INDENT dp [ i + 1 ] [ 0 ] += dp [ i ] [ 0 ] * 1 NEW_LINE dp [ i + 1 ] [ 1 ] += dp [ i ] [ 0 ] * Ni NEW_LINE dp [ i + 1 ] [ 0 ] += dp [ i ] [ 1 ] * ( 1 - Ni ) NEW_LINE dp [ i + 1 ] [ 1 ] += dp [ i ] [ 1 ] * 1 NEW_LINE dp [ i + 1 ] [ 2 ] += dp [ i ] [ 1 ] * ( 1 + Ni ) NEW_LINE dp [ i + 1 ] [ 2 ] += dp [ i ] [ 2 ] * 3 NEW_LINE dp [ i + 1 ] [ 0 ] %= MOD NEW_LINE dp [ i + 1 ] [ 1 ] %= MOD NEW_LINE dp [ i + 1 ] [ 2 ] %= MOD NEW_LINE DEDENT print ( sum ( dp [ - 1 ] ) % MOD ) NEW_LINE


import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] w = new int [ n ] ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = sc . nextInt ( ) ; p [ i ] = sc . nextInt ( ) ; } double max = 100 , min = 0 , mid = 0 ; for ( int i = 0 ; i < 40 ; i ++ ) { double [ ] d = new double [ n ] ; double sum = 0 ; mid = ( max + min ) / 2 ; for ( int j = 0 ; j < n ; j ++ ) { d [ j ] = ( p [ j ] - mid ) * w [ j ] ; } Arrays . sort ( d ) ; for ( int j = 1 ; j <= k ; j ++ ) { sum += d [ n - j ] ; } if ( sum >= 0 ) { min = mid ; } else { max = mid ; } } out . println ( mid ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskD solver = new TaskD ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskD { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; int [ ] w = new int [ n ] ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = in . nextInt ( ) ; p [ i ] = in . nextInt ( ) ; } double max = 100 ; double min = 0 ; for ( int i = 0 ; i < 200 ; i ++ ) { double target = ( max + min ) / 2 ; double [ ] score = new double [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { score [ j ] = w [ j ] * ( ( ( double ) p [ j ] / 100 ) - ( target / 100 ) ) ; } Arrays . sort ( score ) ; double sum = 0 ; for ( int j = n - k ; j < n ; j ++ ) { sum += score [ j ] ; } if ( sum > 0 ) min = target ; else max = target ; } out . println ( min ) ; } } }

import java . io . * ; import java . util . * ; import static java . lang . System . in ; class Main { static double [ ] [ ] rec ; public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , K = sc . nextInt ( ) ; rec = new double [ n ] [ 2 ] ; double sum = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { double w = sc . nextDouble ( ) , p = sc . nextDouble ( ) / 100.0 ; rec [ i ] [ 0 ] = w ; rec [ i ] [ 1 ] = p ; sum += p ; } if ( sum < 0.0001 ) { System . out . println ( 0 ) ; return ; } double lo = 0 , hi = 1 ; for ( int i = 0 ; i < 33 ; i ++ ) { double mid = ( lo + hi ) / 2 ; if ( check ( mid , K , n ) ) lo = mid ; else hi = mid ; } System . out . println ( lo * 100 ) ; } static boolean check ( double target , int K , int n ) { myC mc = new myC ( target ) ; Arrays . sort ( rec , mc ) ; double w = 0 , q = 0 ; for ( int i = n - 1 ; i >= n - K ; i -- ) { w += rec [ i ] [ 0 ] ; q += rec [ i ] [ 1 ] * rec [ i ] [ 0 ] ; } return q / w >= target ; } static class myC implements Comparator < double [ ] > { double target ; public myC ( double t ) { this . target = t ; } public int compare ( double [ ] a , double [ ] b ) { return Double . compare ( a [ 0 ] * ( a [ 1 ] - target ) , b [ 0 ] * ( b [ 1 ] - target ) ) ; } } }

import java . util . * ; import java . io . * ; public class Main { static int N ; static int K ; static double [ ] w ; static double [ ] v ; static double [ ] y ; static boolean calc ( double x ) { for ( int i = 0 ; i < N ; i ++ ) { y [ i ] = v [ i ] - w [ i ] * x ; } Arrays . sort ( y ) ; double sum = 0.0 ; for ( int i = 0 ; i < K ; i ++ ) { sum += y [ N - i - 1 ] ; } if ( sum >= 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; K = sc . nextInt ( ) ; w = new double [ N ] ; v = new double [ N ] ; y = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; int p = sc . nextInt ( ) ; v [ i ] = w [ i ] * p / 100.0 ; } double lb = 0.0 ; double ub = 1000.0 ; for ( int loop = 0 ; loop < 100 ; loop ++ ) { double mid = ( lb + ub ) / 2 ; if ( calc ( mid ) ) lb = mid ; else ub = mid ; } System . out . println ( lb * 100.0 ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double [ ] w = new double [ n ] ; double [ ] p = new double [ n ] ; double pmax = 0 ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = sc . nextDouble ( ) ; p [ i ] = sc . nextDouble ( ) ; pmax = Math . max ( pmax , p [ i ] ) ; } double low = 0 ; double upp = pmax ; double x = ( low + upp ) / 2 ; while ( upp - low > 0.00000001 ) { double [ ] c = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = w [ i ] * ( p [ i ] - x ) ; } Arrays . sort ( c ) ; double sum = 0 ; for ( int i = n - 1 ; i >= n - k ; i -- ) { sum += c [ i ] ; } if ( sum > 0 ) { low = x ; x = ( low + upp ) / 2 ; } else { upp = x ; x = ( low + upp ) / 2 ; } } System . out . println ( x ) ; } }

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE WP = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE MIN = 0 NEW_LINE MAX = 100 NEW_LINE while MAX - MIN > 10 ** ( - 8 ) : NEW_LINE INDENT x = ( MAX + MIN ) / 2 NEW_LINE NEEDLIST = [ WP [ i ] [ 0 ] * x - WP [ i ] [ 0 ] * WP [ i ] [ 1 ] for i in range ( N ) ] NEW_LINE NEEDLIST . sort ( ) NEW_LINE if sum ( NEEDLIST [ : K ] ) >= 0 : NEW_LINE INDENT MAX = x NEW_LINE DEDENT else : NEW_LINE INDENT MIN = x NEW_LINE DEDENT DEDENT print ( ( MAX + MIN ) / 2 ) NEW_LINE

def salt_solution ( N : int , K : int , solutions : list ) -> float : NEW_LINE INDENT l , r = 0.0 , 100.0 NEW_LINE e = 10 ** ( - 10 ) NEW_LINE def check ( goal : float ) -> bool : NEW_LINE INDENT A = sorted ( ( - w * ( p - goal ) , w , p ) for w , p in solutions ) NEW_LINE cw , cp = 0 , 0 NEW_LINE for _ , w , p in A [ : K ] : NEW_LINE INDENT cp = ( cw * cp + w * p ) / ( cw + w ) NEW_LINE cw = w + cw NEW_LINE DEDENT return cp >= goal NEW_LINE DEDENT while r - l > e : NEW_LINE INDENT m = ( r + l ) / 2 NEW_LINE if check ( m ) : NEW_LINE INDENT l = m NEW_LINE DEDENT else : NEW_LINE INDENT r = m NEW_LINE DEDENT DEDENT return l NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 0 NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE solutions = [ tuple ( int ( s ) for s in input ( ) . split ( ) ) for _ in range ( N ) ] NEW_LINE ans = salt_solution ( N , K , solutions ) NEW_LINE print ( ans ) NEW_LINE DEDENT

def calculate ( a ) : NEW_LINE INDENT salt = 0 NEW_LINE tot = 0 NEW_LINE for w , p in a : NEW_LINE INDENT salt += w * p NEW_LINE tot += w NEW_LINE DEDENT return salt / tot NEW_LINE DEDENT def prioritize ( a , target ) : NEW_LINE INDENT return sorted ( a , key = lambda x : x [ 0 ] * ( x [ 1 ] - target ) , reverse = True ) NEW_LINE DEDENT def search ( a , K ) : NEW_LINE INDENT ng = 100 NEW_LINE ok = 0 NEW_LINE mid = ( ok + ng ) / 2 NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT prev = mid NEW_LINE a = prioritize ( a , mid ) NEW_LINE rho = calculate ( a [ : K ] ) NEW_LINE if rho >= mid : NEW_LINE INDENT ok = mid NEW_LINE DEDENT else : NEW_LINE INDENT ng = mid NEW_LINE DEDENT mid = ( ok + ng ) / 2 NEW_LINE if abs ( mid - prev ) < 1e-9 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return a [ : K ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N , K = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE a = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT w , p = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE a . append ( ( w , p ) ) NEW_LINE DEDENT aa = search ( a , K ) NEW_LINE print ( calculate ( aa ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

n , k = map ( int , input ( ) . split ( ) ) NEW_LINE info = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( n ) ] NEW_LINE used = [ False ] * n NEW_LINE ans_solution_g = 0 NEW_LINE ans_salt_g = 0 NEW_LINE for j in range ( k ) : NEW_LINE INDENT tmp_salution_g = 0 NEW_LINE tmp_salt_g = 0 NEW_LINE tmp_solution_p = 0 NEW_LINE tmp_i = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if used [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT new_solution_g = ans_solution_g + info [ i ] [ 0 ] NEW_LINE new_salt_g = ans_salt_g + ( info [ i ] [ 0 ] * info [ i ] [ 1 ] ) / 100 NEW_LINE new_solution_p = ( new_salt_g / new_solution_g ) * 100 NEW_LINE if new_solution_p > tmp_solution_p : NEW_LINE INDENT tmp_solution_g = new_solution_g NEW_LINE tmp_salt_g = new_salt_g NEW_LINE tmp_solution_p = new_solution_p NEW_LINE tmp_i = i NEW_LINE DEDENT DEDENT DEDENT used [ tmp_i ] = True NEW_LINE ans_solution_g = tmp_solution_g NEW_LINE ans_salt_g = tmp_salt_g NEW_LINE DEDENT print ( ans_salt_g / ans_solution_g * 100 ) NEW_LINE

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE item = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT w , p = map ( int , input ( ) . split ( ) ) NEW_LINE item . append ( [ p * w , w ] ) NEW_LINE DEDENT def check ( x ) : NEW_LINE INDENT y = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT y [ i ] = item [ i ] [ 0 ] - item [ i ] [ 1 ] * x NEW_LINE DEDENT y = sorted ( y , reverse = True ) NEW_LINE if sum ( y [ : K ] ) >= 0 : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def solve ( ) : NEW_LINE INDENT low = 0 NEW_LINE up = 10 ** 10 NEW_LINE e = 10 ** ( - 8 ) NEW_LINE while up - low >= e : NEW_LINE INDENT mid = ( low + up ) / 2 NEW_LINE if check ( mid ) : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT up = mid NEW_LINE DEDENT DEDENT print ( up ) NEW_LINE DEDENT solve ( ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N ; N = Integer . parseInt ( reader . readLine ( ) ) ; List < Integer > result = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int value = Integer . parseInt ( reader . readLine ( ) ) ; int minIndex = - 1 , min = Integer . MAX_VALUE ; for ( int j = 0 ; j < result . size ( ) ; j ++ ) { if ( value <= result . get ( j ) ) { if ( result . get ( j ) - value < min ) { min = result . get ( j ) - value ; minIndex = j ; } } } if ( minIndex == - 1 ) { result . add ( value ) ; } else { result . set ( minIndex , value ) ; } } System . out . println ( result . size ( ) ) ; } }

import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int ans = 0 ; int tmp [ ] = new int [ n ] ; Arrays . fill ( tmp , 100_001 ) ; for ( int i = 0 ; i < n ; i ++ ) { Arrays . sort ( tmp ) ; int w = sc . nextInt ( ) ; boolean canStack = false ; for ( int j = 0 ; j < ans ; j ++ ) { if ( tmp [ j ] >= w ) { canStack = true ; tmp [ j ] = w ; break ; } } if ( ! canStack ) { tmp [ ans ++ ] = w ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { new Main ( ) . main ( sc ) ; } catch ( Exception e ) { throw e ; } } }

import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try ( CustomReader in = new CustomReader ( ) ) { new Main ( ) . execute ( in ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public void execute ( CustomReader in ) throws IOException { final int N = Integer . parseInt ( in . readLine ( ) ) ; int [ ] mountain = new int [ N ] ; int count = 0 ; Arrays . fill ( mountain , Integer . MAX_VALUE ) ; for ( int i = 0 ; i < N ; i ++ ) { int w = Integer . parseInt ( in . readLine ( ) ) ; int target = - 1 ; for ( int j = 0 ; j < count ; j ++ ) { if ( mountain [ j ] >= w ) { if ( target == - 1 || mountain [ target ] > mountain [ j ] ) { target = j ; } } } if ( target == - 1 ) { mountain [ count ++ ] = w ; } else { mountain [ target ] = w ; } } System . out . println ( count ) ; } static class CustomReader extends BufferedReader { private static final int DEFAULT_BUF_SIZE = 2048 ; public CustomReader ( ) throws IOException { super ( new InputStreamReader ( System . in ) , DEFAULT_BUF_SIZE ) ; } public int [ ] readLineAsIntArray ( ) throws IOException { String [ ] strArray = this . readLine ( ) . split ( " ▁ " ) ; int [ ] intArray = new int [ strArray . length ] ; for ( int i = 0 , n = strArray . length ; i < n ; i ++ ) { intArray [ i ] = Integer . parseInt ( strArray [ i ] ) ; } return intArray ; } public int [ ] [ ] readAsIntMatrix ( int rows , int columns ) throws IOException { int [ ] [ ] matrix = new int [ rows ] [ columns ] ; for ( int i = 0 ; i < rows ; i ++ ) { String [ ] r = this . readLine ( ) . split ( " ▁ " ) ; for ( int j = 0 ; j < columns ; j ++ ) { matrix [ i ] [ j ] = Integer . parseInt ( r [ j ] ) ; } } return matrix ; } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; int arr [ ] = new int [ 55 ] ; while ( n -- != 0 ) { int w = sc . nextInt ( ) ; int yes = 0 ; int mid = 100005 , j = - 1 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == w ) { yes = 1 ; break ; } if ( arr [ i ] > w ) { if ( arr [ i ] - w < mid ) { mid = arr [ i ] - w ; j = i ; } } if ( arr [ i ] == 0 ) break ; } if ( yes == 0 && j != - 1 ) { arr [ j ] = w ; } if ( yes == 0 && j == - 1 ) { for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == 0 ) { arr [ i ] = w ; ans ++ ; break ; } } } } System . out . println ( ans ) ; } }

import java . util . * ; import java . io . InputStreamReader ; import java . io . BufferedReader ; import java . util . Arrays ; import java . util . List ; import java . util . ArrayList ; import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; List < Integer > boxes = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) { boxes . add ( Integer . parseInt ( br . readLine ( ) ) ) ; } List < Integer > mtns = new ArrayList ( ) ; for ( Integer box : boxes ) { int min = 100000 ; int index = - 1 ; for ( int i = 0 ; i < mtns . size ( ) ; i ++ ) { int diff = mtns . get ( i ) - box ; if ( diff >= 0 && diff < min ) { min = diff ; index = i ; } } if ( min == 100000 ) { mtns . add ( box ) ; } else mtns . set ( index , box ) ; } System . out . println ( mtns . size ( ) ) ; } } class Box { int w ; int h ; public Box ( int w , int h ) { this . w = w ; this . h = h ; } } class BoxComparator1 implements Comparator < Box > { public int compare ( Box b1 , Box b2 ) { return b1 . w - b2 . w ; } } class BoxComparator2 implements Comparator < Box > { public int compare ( Box b1 , Box b2 ) { return b1 . h - b2 . h ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

n = int ( input ( ) ) NEW_LINE L = [ ] NEW_LINE L . append ( int ( input ( ) ) ) NEW_LINE ans = 1 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT L . sort ( ) NEW_LINE a = int ( input ( ) ) NEW_LINE y = 0 NEW_LINE for j in range ( len ( L ) ) : NEW_LINE INDENT if L [ j ] >= a : NEW_LINE INDENT L [ j ] = a NEW_LINE y = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if y == 0 : NEW_LINE INDENT ans += 1 NEW_LINE L . append ( a ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

import bisect NEW_LINE N = int ( input ( ) ) NEW_LINE W = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE ds = [ W [ 0 ] ] NEW_LINE for w in W [ 1 : ] : NEW_LINE INDENT i = bisect . bisect_left ( ds , w ) NEW_LINE if i == len ( ds ) : NEW_LINE INDENT ds . append ( w ) NEW_LINE DEDENT else : NEW_LINE INDENT ds [ i ] = w NEW_LINE DEDENT DEDENT print ( len ( ds ) ) NEW_LINE

if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT box_count = int ( input ( ) ) NEW_LINE boxes = [ ] NEW_LINE box_towers = [ ] NEW_LINE for i in range ( box_count ) : NEW_LINE INDENT boxes . append ( int ( input ( ) ) ) NEW_LINE DEDENT for box in boxes : NEW_LINE INDENT is_stacked = False NEW_LINE for tower in box_towers : NEW_LINE INDENT if tower [ - 1 ] >= box : NEW_LINE INDENT tower . append ( box ) NEW_LINE is_stacked = True NEW_LINE break NEW_LINE DEDENT DEDENT if not is_stacked : NEW_LINE INDENT box_towers . append ( [ box ] ) NEW_LINE DEDENT DEDENT print ( len ( box_towers ) ) NEW_LINE DEDENT

import bisect NEW_LINE def bump ( T , x ) : NEW_LINE INDENT if T == [ ] : NEW_LINE INDENT return [ [ x ] ] NEW_LINE DEDENT else : NEW_LINE INDENT i = bisect . bisect_right ( T [ 0 ] , x ) NEW_LINE if i == len ( T [ 0 ] ) : NEW_LINE INDENT return [ T [ 0 ] + [ x ] ] + T [ 1 : ] NEW_LINE DEDENT else : NEW_LINE INDENT y = T [ 0 ] [ i ] NEW_LINE T [ 0 ] [ i ] = x NEW_LINE return [ T [ 0 ] ] + bump ( T [ 1 : ] , y ) NEW_LINE DEDENT DEDENT DEDENT N = int ( input ( ) ) NEW_LINE w = [ None for i in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT w [ i ] = int ( input ( ) ) NEW_LINE DEDENT T = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT T = bump ( T , w [ N - 1 - i ] ) NEW_LINE DEDENT print ( len ( T ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE upper_nums = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT new_num = int ( input ( ) ) NEW_LINE if len ( upper_nums ) == 0 : NEW_LINE INDENT upper_nums . append ( new_num ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( len ( upper_nums ) ) : NEW_LINE INDENT if upper_nums [ i ] >= new_num : NEW_LINE INDENT upper_nums [ i ] = new_num NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT upper_nums . append ( new_num ) NEW_LINE DEDENT DEDENT upper_nums . sort ( ) NEW_LINE DEDENT print ( len ( upper_nums ) ) NEW_LINE


import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Scanner ; public class A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numCases = sc . nextInt ( ) ; for ( int caseNum = 1 ; caseNum <= numCases ; caseNum ++ ) { String S = sc . next ( ) ; char ch = S . charAt ( 0 ) ; Deque < Character > chars = new ArrayDeque < > ( ) ; chars . addLast ( S . charAt ( 0 ) ) ; for ( int i = 1 ; i < S . length ( ) ; i ++ ) { char next = S . charAt ( i ) ; if ( next >= chars . getFirst ( ) ) { chars . addFirst ( next ) ; } else { chars . addLast ( next ) ; } } System . out . print ( " Case ▁ # " + caseNum + " : ▁ " ) ; for ( Character c : chars ) { System . out . print ( c ) ; } System . out . println ( ) ; } } }

package cj2016 . r1a ; import java . io . * ; import java . util . * ; public class A { Scanner sc ; PrintWriter pw ; char [ ] S ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : " A - large " ; try { new A ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + " . in " ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + " . out " ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( " Case ▁ # " + test + " : ▁ " ) ; System . out . print ( " Case ▁ # " + test + " : ▁ " ) ; solve ( ) ; } System . out . println ( " Finished . " ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { S = sc . next ( ) . toCharArray ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } public void solve ( ) { String ans = " " ; for ( char c : S ) { String s1 = ans + c ; String s2 = c + ans ; ans = s1 . compareTo ( s2 ) < 0 ? s2 : s1 ; } println ( ans ) ; } }

package lab6zp ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Lab6ZP { public static String solve ( String s , int x ) { if ( s . equals ( " . " ) ) { return " " ; } String t = " " ; char c = ' Z ' ; c -= x ; String [ ] u = s . split ( Character . toString ( c ) ) ; for ( int i = 0 ; i < u . length - 1 ; i ++ ) { t += c ; } for ( int i = 0 ; i < u . length ; i ++ ) { if ( i == 0 ) { t += solve ( u [ i ] , x + 1 ) ; } else { t += remove ( u [ i ] ) ; } } return t ; } public static String remove ( String s ) { String t = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) != ' . ' ) { t += s . charAt ( i ) ; } } return t ; } public static String interlace ( String s ) { String t = " . " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { t += s . charAt ( i ) ; t += " . " ; } return t ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = Integer . parseInt ( in . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . next ( ) ; s = interlace ( s ) ; System . out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + solve ( s , 0 ) ) ; } } }

import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; public class Round1A { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( " A . txt " ) ; int T = Integer . parseInt ( in . readLine ( ) ) ; for ( int c = 1 ; c <= T ; c ++ ) { String s = in . readLine ( ) ; int [ ] fl = new int [ s . length ( ) ] ; int nfl = 0 ; while ( nfl < s . length ( ) ) { char last = ( char ) ( ' A ' - 1 ) ; int firstL = - 1 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 0 && s . charAt ( i ) > last ) { last = s . charAt ( i ) ; firstL = i ; } } for ( int i = firstL ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 0 ) { nfl ++ ; if ( s . charAt ( i ) == last ) { fl [ i ] = 1 ; } else fl [ i ] = - 1 ; } } } String ans = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( fl [ i ] == 1 ) { ans = s . charAt ( i ) + ans ; } else if ( fl [ i ] == - 1 ) { ans = ans + s . charAt ( i ) ; } } pw . println ( " Case ▁ # " + c + " : ▁ " + ans ) ; } pw . close ( ) ; } }

import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileReader ; import java . io . FileWriter ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class a { public static void main ( String [ ] Args ) throws Exception { FS sc = new FS ( new File ( " A - large . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( new File ( " a . out " ) ) ) ) ; int cc = 0 ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { out . printf ( " Case ▁ # % d : ▁ " , ++ cc ) ; String s = sc . next ( ) ; out . printf ( " % s " , foo ( s ) ) ; out . println ( " " ) ; } out . close ( ) ; } public static String foo ( String s ) throws Exception { if ( s . length ( ) == 0 ) return " " ; int last = ' A ' ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { last = Math . max ( last , s . charAt ( i ) ) ; } for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { if ( s . charAt ( i ) == last ) { return ( char ) ( last ) + foo ( s . substring ( 0 , i ) ) + s . substring ( i + 1 ) ; } } throw new Exception ( " BANANAS " ) ; } public static class FS { BufferedReader br ; StringTokenizer st ; FS ( InputStream in ) throws Exception { br = new BufferedReader ( new InputStreamReader ( in ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; } FS ( File in ) throws Exception { br = new BufferedReader ( new FileReader ( in ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; } String next ( ) throws Exception { if ( st . hasMoreTokens ( ) ) return st . nextToken ( ) ; st = new StringTokenizer ( br . readLine ( ) ) ; return next ( ) ; } int nextInt ( ) throws Exception { return Integer . parseInt ( next ( ) ) ; } } }

tt = int ( raw_input ( ) ) NEW_LINE for t in xrange ( 1 , tt + 1 ) : NEW_LINE INDENT s = raw_input ( ) . strip ( ) NEW_LINE ans = s [ 0 ] NEW_LINE signat = [ s [ 0 ] + s [ 0 ] ] NEW_LINE for i in xrange ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] < signat [ i - 1 ] [ 0 ] : NEW_LINE INDENT ans = ans + s [ i ] NEW_LINE signat . append ( signat [ i - 1 ] ) NEW_LINE DEDENT elif s [ i ] > signat [ i - 1 ] [ 0 ] : NEW_LINE INDENT ans = s [ i ] + ans NEW_LINE signat . append ( s [ i ] + signat [ i - 1 ] [ 0 ] ) NEW_LINE DEDENT elif s [ i ] < signat [ i - 1 ] [ 1 ] : NEW_LINE INDENT ans = ans + s [ i ] NEW_LINE signat . append ( signat [ i - 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = s [ i ] + ans NEW_LINE signat . append ( signat [ i - 1 ] ) NEW_LINE DEDENT DEDENT print ' Case ▁ # % d : ▁ % s ' % ( t , ans ) NEW_LINE DEDENT

class Case : NEW_LINE INDENT def __init__ ( self , fin , fout , n ) : NEW_LINE INDENT self . _fin = fin NEW_LINE self . _fout = fout NEW_LINE self . _n = n NEW_LINE self . _line = None NEW_LINE DEDENT def readInt ( self ) : NEW_LINE INDENT if self . _line is None : NEW_LINE INDENT self . _line = self . _fin . readline ( ) . split ( " ▁ " ) NEW_LINE DEDENT result = int ( self . _line . pop ( 0 ) ) NEW_LINE if len ( self . _line ) == 0 : NEW_LINE INDENT self . _line = None NEW_LINE DEDENT return result NEW_LINE DEDENT def readLine ( self ) : NEW_LINE INDENT line = self . _fin . readline ( ) NEW_LINE if line [ - 1 ] == " \n " : NEW_LINE INDENT return line [ : - 1 ] NEW_LINE DEDENT return line NEW_LINE DEDENT def output ( self , s ) : NEW_LINE INDENT if s is None : NEW_LINE INDENT return NEW_LINE DEDENT s = str ( s ) NEW_LINE if " \n " in s : NEW_LINE INDENT self . _fout . write ( " Case ▁ # % d : % s " % ( self . _n , s ) ) NEW_LINE DEDENT else : NEW_LINE INDENT self . _fout . write ( " Case ▁ # % d : ▁ % s \n " % ( self . _n , s ) ) NEW_LINE DEDENT DEDENT DEDENT def run ( fileName , solve ) : NEW_LINE INDENT fin = open ( fileName ) NEW_LINE fout = open ( fileName + " . out " , " w " ) NEW_LINE caseCount = int ( fin . readline ( ) ) NEW_LINE for i in range ( caseCount ) : NEW_LINE INDENT case = Case ( fin , fout , i + 1 ) NEW_LINE case . output ( solve ( case ) ) NEW_LINE DEDENT DEDENT

import sys NEW_LINE def compute ( S ) : NEW_LINE INDENT if S == ' ' : NEW_LINE INDENT return ' ' NEW_LINE DEDENT x = max ( S ) NEW_LINE p = S . find ( x ) NEW_LINE y = compute ( S [ : p ] ) NEW_LINE z = filter ( lambda c : c != x , S [ p : ] ) NEW_LINE return ( x * ( len ( S ) - p - len ( z ) ) ) + y + z NEW_LINE DEDENT def parse ( ) : NEW_LINE INDENT S = sys . stdin . readline ( ) . strip ( ) NEW_LINE return S , 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 sys import stdin , stdout NEW_LINE def solve ( test_id ) : NEW_LINE INDENT s = stdin . readline ( ) . strip ( ) NEW_LINE r = ' ' NEW_LINE for a in s : NEW_LINE INDENT if len ( r ) > 0 and r [ 0 ] <= a : NEW_LINE INDENT r = a + r NEW_LINE DEDENT else : NEW_LINE INDENT r = r + a NEW_LINE DEDENT DEDENT print ( " Case ▁ # { } : ▁ { } " . format ( test_id , r ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT t = int ( stdin . readline ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT solve ( i + 1 ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE

import sys NEW_LINE import itertools NEW_LINE def ans ( S ) : NEW_LINE INDENT ans = " " NEW_LINE for x in S : NEW_LINE INDENT if ( x + ans ) > ( ans + x ) : NEW_LINE INDENT ans = x + ans NEW_LINE DEDENT else : NEW_LINE INDENT ans = ans + x NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT s = sys . stdin . readline ( ) NEW_LINE T = int ( s ) NEW_LINE for i in xrange ( 0 , T ) : NEW_LINE INDENT S = sys . stdin . readline ( ) NEW_LINE print " Case ▁ # { 0 } : ▁ { 1 } " . format ( i + 1 , ans ( S . strip ( ) ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . util . * ; public class B { static Scanner in ; public static void main ( String [ ] args ) { in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int C = 1 ; C <= T ; C ++ ) { System . out . println ( " Case ▁ # " + C + " : ▁ " + solve ( ) ) ; } } public static String solve ( ) { String out = " " ; int B = in . nextInt ( ) ; long M = in . nextLong ( ) - 1 ; String binary = " " ; while ( M > 0 ) { binary += M % 2 ; M = M / 2 ; } System . err . println ( binary ) ; if ( binary . length ( ) > B - 2 ) { out = " IMPOSSIBLE " ; } else { out = " POSSIBLE " ; for ( int i = 0 ; i < B ; i ++ ) { String line = " " ; for ( int j = 0 ; j <= i ; j ++ ) { line += "0" ; } for ( int j = 0 ; j < B - 2 - i ; j ++ ) { line += "1" ; } if ( i < B - 1 ) { if ( i == 0 ) { line += "1" ; } else if ( i - 1 < binary . length ( ) ) { line += binary . charAt ( i - 1 ) ; } else { line += "0" ; } } out += " \n " + line ; } } return out ; } }

import java . io . File ; import java . io . FileInputStream ; import java . io . FileOutputStream ; import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scanner = new Scanner ( System . in ) ; int t = scanner . nextInt ( ) ; for ( int x = 1 ; x <= t ; ++ x ) { int b = scanner . nextInt ( ) ; long m = scanner . nextLong ( ) ; System . out . print ( " Case ▁ # " + x + " : ▁ " ) ; if ( m > Math . pow ( 2 , b - 2 ) ) { System . out . print ( " IMPOSSIBLE \n " ) ; continue ; } else System . out . print ( " POSSIBLE \n " ) ; int [ ] [ ] slides = new int [ b ] [ b ] ; for ( int i = 0 ; i < b ; ++ i ) { for ( int j = i + 1 ; j < b ; ++ j ) { slides [ i ] [ j ] = 1 ; } } String str = Long . toBinaryString ( m - 1 ) + " " ; if ( str . equals ( "0" ) ) str = " " ; while ( str . length ( ) < b - 1 ) { str = "0" + str ; } str += "1" ; System . out . println ( str ) ; for ( int i = 1 ; i < b ; ++ i ) { for ( int j = 0 ; j < b ; ++ j ) { System . out . print ( slides [ i ] [ j ] ) ; } System . out . print ( " \n " ) ; } } } }

import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class B { public static void main ( String [ ] args ) { new B ( ) . run ( ) ; } BufferedReader br ; StringTokenizer in ; PrintWriter out ; public String nextToken ( ) throws IOException { while ( in == null || ! in . hasMoreTokens ( ) ) { in = new StringTokenizer ( br . readLine ( ) ) ; } return in . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } public void solve ( ) throws IOException { int n = nextInt ( ) ; long b = nextLong ( ) ; if ( b > 1L << ( n - 2 ) ) { out . println ( " IMPOSSIBLE " ) ; return ; } int [ ] [ ] a = new int [ n ] [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { a [ i ] [ j ] = 1 ; } } b -- ; a [ 0 ] [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( b % 2 == 1 ) { a [ 0 ] [ i ] = 1 ; } b /= 2 ; } out . println ( " POSSIBLE " ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { out . print ( a [ i ] [ j ] ) ; } out . println ( ) ; } } public void run ( ) { try { br = new BufferedReader ( new FileReader ( " input . txt " ) ) ; out = new PrintWriter ( " output . txt " ) ; int t = nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { out . print ( String . format ( " Case ▁ # % d : ▁ " , i + 1 ) ) ; solve ( ) ; } out . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } }

import java . util . * ; import java . io . * ; public class B { static int N ; 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 B = input . nextInt ( ) ; long M = input . nextLong ( ) ; if ( M > ( 1L << ( B - 2 ) ) ) { System . out . printf ( " Case ▁ # % d : ▁ IMPOSSIBLE \n " , n + 1 ) ; continue ; } boolean [ ] [ ] slides = new boolean [ B ] [ B ] ; if ( M == ( 1L << ( B - 2 ) ) ) { for ( int i = 0 ; i < B ; i ++ ) for ( int j = i + 1 ; j < B ; j ++ ) slides [ i ] [ j ] = true ; } for ( int i = 0 ; i + 1 < B ; i ++ ) for ( int j = i + 1 ; j + 1 < B ; j ++ ) slides [ i ] [ j ] = true ; for ( int i = 0 ; i + 2 < B ; i ++ ) if ( ( M & ( 1L << i ) ) > 0 ) slides [ i + 1 ] [ B - 1 ] = true ; System . out . printf ( " Case ▁ # % d : ▁ POSSIBLE \n " , n + 1 ) ; for ( int i = 0 ; i < B ; i ++ ) { for ( int j = 0 ; j < B ; j ++ ) System . out . print ( slides [ i ] [ j ] ? '1' : '0' ) ; System . out . println ( ) ; } } } }

package Round1 ; import java . io . * ; public class B { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new FileReader ( " / Users / chao / Downloads / B - large . in " ) ) ; FileWriter out = new FileWriter ( " / Users / chao / Desktop / B - large . txt " ) ; String s = in . readLine ( ) ; int m = Integer . parseInt ( s ) ; for ( int cases = 1 ; cases <= m ; cases ++ ) { String [ ] ss = in . readLine ( ) . split ( " ▁ " ) ; int B = Integer . parseInt ( ss [ 0 ] ) ; long M = Long . parseLong ( ss [ 1 ] ) ; out . write ( " Case ▁ # " + cases + " : ▁ " ) ; int n = B ; long max = pow ( B - 2 ) ; if ( max >= M ) { out . write ( " POSSIBLE \n " ) ; int [ ] [ ] map = new int [ n ] [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { map [ i ] [ j ] = 1 ; } } for ( int k = 1 ; k < n ; k ++ ) { if ( k != n - 1 ) max = max / 2 ; if ( max <= M ) { M -= max ; map [ 0 ] [ k ] = 1 ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { out . write ( " " + map [ i ] [ j ] ) ; } out . write ( " \n " ) ; } } else { out . write ( " IMPOSSIBLE \n " ) ; } } in . close ( ) ; out . flush ( ) ; out . close ( ) ; } private static long pow ( int n ) { long x = 1 ; for ( int i = 0 ; i < n ; i ++ ) { x *= 2 ; } return x ; } }

from sys import stdin NEW_LINE from string import zfill NEW_LINE def each_case ( B , M ) : NEW_LINE INDENT if M < 2 ** ( B - 2 ) : NEW_LINE INDENT print zfill ( bin ( M ) [ 2 : ] , B - 1 ) + '0' NEW_LINE for i in xrange ( B - 1 ) : NEW_LINE INDENT print '0' * ( i + 2 ) + '1' * ( B - i - 2 ) NEW_LINE DEDENT DEDENT elif M == 2 ** ( B - 2 ) : NEW_LINE INDENT print '0' + '1' * ( B - 1 ) NEW_LINE for i in xrange ( B - 1 ) : NEW_LINE INDENT print '0' * ( i + 2 ) + '1' * ( B - i - 2 ) NEW_LINE DEDENT DEDENT DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for t in xrange ( 1 , T + 1 ) : NEW_LINE INDENT B , M = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( t , ' POSSIBLE ' if ( M <= 2 ** ( B - 2 ) ) else ' IMPOSSIBLE ' ) NEW_LINE each_case ( B , M ) NEW_LINE DEDENT

def solve ( b , m ) : NEW_LINE INDENT if m > 2 ** ( b - 2 ) : NEW_LINE INDENT print ( " IMPOSSIBLE " ) NEW_LINE return NEW_LINE DEDENT print ( " POSSIBLE " ) NEW_LINE if m == 2 ** ( b - 2 ) : NEW_LINE INDENT print ( "0" + "1" * ( b - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT l = [ ( m >> i ) & 1 for i in range ( b - 2 ) ] NEW_LINE print ( "0" + " " . join ( map ( str , reversed ( l ) ) ) + "0" ) NEW_LINE DEDENT for i in range ( 1 , b ) : NEW_LINE INDENT print ( "0" * ( i + 1 ) + "1" * ( b - i - 1 ) ) NEW_LINE DEDENT DEDENT t = int ( input ( ) ) NEW_LINE for i in range ( t ) : NEW_LINE INDENT print ( " Case ▁ # " + str ( i + 1 ) + " : " , end = " ▁ " ) NEW_LINE b , m = map ( int , input ( ) . split ( ) ) NEW_LINE solve ( b , m ) NEW_LINE DEDENT

import sys NEW_LINE def solve_test ( inp ) : NEW_LINE INDENT B , M = map ( int , inp . readline ( ) . split ( ) ) NEW_LINE if M > 2 ** ( B - 2 ) : NEW_LINE INDENT return ' IMPOSSIBLE ' NEW_LINE DEDENT if M == 2 ** ( B - 2 ) : NEW_LINE INDENT first = '0' + '1' * ( B - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT first = '0' + bin ( M ) [ 2 : ] . zfill ( B - 2 ) + '0' NEW_LINE DEDENT print ( bin ( M ) , bin ( M ) [ 2 : ] . zfill ( B - 2 ) ) NEW_LINE lines = [ '0' * i + '1' * ( B - i ) for i in range ( 2 , B + 1 ) ] NEW_LINE return ' POSSIBLE \n ' + ' \n ' . join ( [ first ] + lines ) NEW_LINE DEDENT def solve_dumb ( inp ) : NEW_LINE INDENT return '1' NEW_LINE DEDENT inp = open ( sys . argv [ 1 ] ) NEW_LINE inp_dumb = open ( sys . argv [ 1 ] ) NEW_LINE out = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . out ' , ' w ' ) NEW_LINE out_dumb = open ( sys . argv [ 1 ] . rsplit ( ' . ' , 1 ) [ 0 ] + ' . dumb . out ' , ' w ' ) NEW_LINE n_tests = int ( inp . readline ( ) ) NEW_LINE for i in range ( n_tests ) : NEW_LINE INDENT ans = solve_test ( inp ) NEW_LINE print ( " Case ▁ # % d : ▁ " % ( i + 1 ) + ans , file = out ) NEW_LINE ans_dumb = solve_dumb ( inp_dumb ) NEW_LINE print ( " Case ▁ # % d : ▁ " % ( i + 1 ) + ans_dumb , file = out_dumb ) NEW_LINE if ans != ans_dumb : NEW_LINE INDENT print ( ' Wrong ' , i + 1 , file = sys . stderr ) NEW_LINE DEDENT DEDENT out . close ( ) NEW_LINE

f = open ( ' large2 . in ' ) NEW_LINE T = int ( f . readline ( ) . strip ( ) ) NEW_LINE for k in range ( T ) : NEW_LINE INDENT case = f . readline ( ) . split ( ) NEW_LINE B = int ( case [ 0 ] ) NEW_LINE M = int ( case [ 1 ] ) NEW_LINE if ( M > ( 2 ** ( B - 2 ) ) ) : NEW_LINE INDENT print " Case ▁ # % d : ▁ IMPOSSIBLE " % ( k + 1 ) NEW_LINE continue NEW_LINE DEDENT print " Case ▁ # % d : ▁ POSSIBLE " % ( k + 1 ) NEW_LINE matrix = [ ] NEW_LINE for i in range ( B ) : NEW_LINE INDENT oneLine = [ ] NEW_LINE for j in range ( B ) : NEW_LINE INDENT oneLine . append ( "0" ) NEW_LINE DEDENT matrix . append ( oneLine ) NEW_LINE DEDENT if ( M > 0 ) : NEW_LINE INDENT M -= 1 NEW_LINE matrix [ 0 ] [ B - 1 ] = "1" NEW_LINE DEDENT totalPossible = 1 NEW_LINE lastIdx = 1 NEW_LINE for i in range ( B - 2 ) : NEW_LINE INDENT currentIdx = B - i - 2 NEW_LINE if ( M == 0 ) : NEW_LINE INDENT lastIdx = currentIdx + 1 NEW_LINE break NEW_LINE DEDENT if ( M >= totalPossible ) : NEW_LINE INDENT M -= totalPossible NEW_LINE totalPossible *= 2 NEW_LINE otherIdx = currentIdx NEW_LINE while ( otherIdx < B - 1 ) : NEW_LINE INDENT otherIdx += 1 NEW_LINE matrix [ currentIdx ] [ otherIdx ] = "1" NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT otherIdx = currentIdx NEW_LINE while ( otherIdx < B - 1 ) : NEW_LINE INDENT otherIdx += 1 NEW_LINE totalPossible /= 2 NEW_LINE if ( totalPossible == 0 ) : NEW_LINE INDENT totalPossible = 1 NEW_LINE DEDENT if ( M >= totalPossible ) : NEW_LINE INDENT M -= totalPossible NEW_LINE matrix [ currentIdx ] [ otherIdx ] = "1" NEW_LINE DEDENT DEDENT lastIdx = currentIdx NEW_LINE break NEW_LINE DEDENT DEDENT while ( lastIdx < B - 1 ) : NEW_LINE INDENT matrix [ 0 ] [ lastIdx ] = "1" NEW_LINE lastIdx += 1 NEW_LINE DEDENT for line in matrix : NEW_LINE INDENT print " " . join ( line ) NEW_LINE DEDENT DEDENT

def f ( b , m ) : NEW_LINE INDENT if m > ( 1 << ( b - 2 ) ) : NEW_LINE INDENT return [ ] NEW_LINE DEDENT x = [ [ 1 if ( ( i > j ) and ( i < ( b - 1 ) ) ) else 0 for i in xrange ( b ) ] for j in xrange ( b ) ] NEW_LINE m -= 1 NEW_LINE x [ 0 ] [ b - 1 ] = 1 NEW_LINE for i in xrange ( 1 , b - 1 ) : NEW_LINE INDENT if ( m >> ( i - 1 ) ) & 1 : NEW_LINE INDENT x [ i ] [ b - 1 ] = 1 NEW_LINE DEDENT DEDENT return x NEW_LINE DEDENT from sys import stdin NEW_LINE def getint ( ) : NEW_LINE INDENT return int ( stdin . readline ( ) ) NEW_LINE DEDENT def getints ( ) : NEW_LINE INDENT return tuple ( int ( z ) for z in stdin . readline ( ) . split ( ) ) NEW_LINE DEDENT for cn in xrange ( 1 , 1 + getint ( ) ) : NEW_LINE INDENT ( b , m ) = getints ( ) NEW_LINE sol = f ( b , m ) NEW_LINE if len ( sol ) == 0 : NEW_LINE INDENT output = " IMPOSSIBLE " NEW_LINE DEDENT else : NEW_LINE INDENT output = " POSSIBLE \n " + " \n " . join ( " " . join ( str ( k ) for k in row ) for row in sol ) NEW_LINE DEDENT print " Case ▁ # { } : ▁ { } " . format ( cn , output ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; public class teachingassistant { private static InputReader in ; private static PrintWriter out ; public static boolean SUBMIT = true ; public static final String NAME = " A - large " ; private static void main2 ( ) throws IOException { char [ ] c = in . next ( ) . toCharArray ( ) ; int n = c . length ; char [ ] stack = new char [ n ] ; int idx = 0 ; int need = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( idx > 0 && stack [ idx - 1 ] == c [ i ] ) { idx -- ; continue ; } if ( i + idx >= n ) { need ++ ; idx -- ; } else { stack [ idx ++ ] = c [ i ] ; } } out . println ( ( n - need ) * 5 ) ; } 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 ( ) ) ; } } }

package cj2016 . r3 ; import java . io . * ; import java . util . * ; public class A { Scanner sc ; PrintWriter pw ; char [ ] c ; public static void main ( String [ ] args ) throws Exception { String filePrefix = args . length > 0 ? args [ 0 ] : " A - large " ; try { new A ( ) . run ( filePrefix ) ; } catch ( Exception e ) { System . err . println ( e ) ; } } public void run ( String filePrefix ) throws Exception { sc = new Scanner ( new FileReader ( filePrefix + " . in " ) ) ; pw = new PrintWriter ( new FileWriter ( filePrefix + " . out " ) ) ; int ntest = sc . nextInt ( ) ; for ( int test = 1 ; test <= ntest ; test ++ ) { read ( sc ) ; pw . print ( " Case ▁ # " + test + " : ▁ " ) ; System . out . print ( " Case ▁ # " + test + " : ▁ " ) ; solve ( ) ; } System . out . println ( " Finished . " ) ; sc . close ( ) ; pw . close ( ) ; } void read ( Scanner sc ) { c = sc . next ( ) . toCharArray ( ) ; } void print ( Object s ) { pw . print ( s ) ; System . out . print ( s ) ; } void println ( Object s ) { pw . println ( s ) ; System . out . println ( s ) ; } void solve ( ) { int N = c . length ; int score = 0 ; LinkedList < Character > stack = new LinkedList < Character > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! stack . isEmpty ( ) && stack . peek ( ) == c [ i ] ) { stack . pop ( ) ; score += 10 ; } else { stack . push ( c [ i ] ) ; } } println ( score + stack . size ( ) / 2 * 5 ) ; } }

import java . io . OutputStream ; import java . io . FilenameFilter ; import java . util . Locale ; import java . io . FileOutputStream ; import java . io . IOException ; import java . io . FileInputStream ; import java . io . File ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . LinkedList ; public class Main { public static void main ( String [ ] args ) { Locale . setDefault ( Locale . US ) ; InputStream inputStream ; try { final String regex = " A - ( small | large ) . * [ . ] in " ; File directory = new File ( " . " ) ; File [ ] candidates = directory . listFiles ( new FilenameFilter ( ) { public boolean accept ( File dir , String name ) { return name . matches ( regex ) ; } } ) ; File toRun = null ; for ( File candidate : candidates ) { if ( toRun == null || candidate . lastModified ( ) > toRun . lastModified ( ) ) toRun = candidate ; } inputStream = new FileInputStream ( toRun ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } OutputStream outputStream ; try { outputStream = new FileOutputStream ( " a . out " ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; int testCount = Integer . parseInt ( in . next ( ) ) ; for ( int i = 1 ; i <= testCount ; i ++ ) solver . solve ( i , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String s = in . next ( ) ; int pairs = 0 ; LinkedList < Character > list = new LinkedList < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char next = s . charAt ( i ) ; char last = list . size ( ) > 0 ? list . peekLast ( ) : ' x ' ; if ( last == next ) { pairs ++ ; list . pollLast ( ) ; } else { list . add ( next ) ; } } out . printf ( " Case ▁ # % d : ▁ % d \n " , testNumber , pairs * 10 + 5 * list . size ( ) / 2 ) ; } } }

import java . io . * ; import java . util . * ; public class Assistant { public void solve ( ) { String s = in . nextToken ( ) ; char [ ] stack = new char [ s . length ( ) ] ; int size = 0 ; for ( char c : s . toCharArray ( ) ) { if ( size > 0 && c == stack [ size - 1 ] ) { size -- ; } else { stack [ size ++ ] = c ; } } out . println ( 5 * ( size / 2 ) + 10 * ( s . length ( ) - size ) / 2 ) ; } public void run ( ) { try { in = new FastScanner ( " input . txt " ) ; out = new PrintWriter ( " output . txt " ) ; int tests = in . nextInt ( ) ; for ( int i = 1 ; i <= tests ; i ++ ) { long time = System . currentTimeMillis ( ) ; out . printf ( " Case ▁ # % d : ▁ " , i ) ; solve ( ) ; System . err . printf ( " Solved ▁ case ▁ # % d ▁ in ▁ % d ▁ ms \n " , i , System . currentTimeMillis ( ) - time ) ; } out . close ( ) ; } catch ( FileNotFoundException e ) { } } FastScanner in ; PrintWriter out ; class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner ( String fileName ) { try { br = new BufferedReader ( new FileReader ( fileName ) ) ; } catch ( FileNotFoundException e ) { } } String nextToken ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( nextToken ( ) ) ; } } public static void main ( String [ ] args ) { new Assistant ( ) . run ( ) ; } }

package gcj . gcj2016 . round3 ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . Stack ; public class A { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int t = in . nextInt ( ) ; for ( int cs = 1 ; cs <= t ; cs ++ ) { char [ ] c = in . next ( ) . toCharArray ( ) ; out . println ( String . format ( " Case ▁ # % d : ▁ % d " , cs , solve ( c ) ) ) ; } out . flush ( ) ; } private static int solve ( char [ ] mood ) { int n = mood . length ; int score = 0 ; int code = 0 ; int jam = 0 ; Stack < Character > stk = new Stack < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( stk . size ( ) == 0 ) { stk . push ( mood [ i ] ) ; } else { if ( stk . peek ( ) == mood [ i ] ) { stk . pop ( ) ; score += 10 ; } else { int pool = stk . size ( ) ; int left = n - i ; if ( pool + 1 <= left - 1 ) { stk . push ( mood [ i ] ) ; } else { stk . pop ( ) ; score += 5 ; } } } } return score ; } }

def solve ( seq ) : NEW_LINE INDENT memo = { } NEW_LINE def opt ( lo , hi ) : NEW_LINE INDENT if ( lo , hi ) in memo : NEW_LINE INDENT return memo [ lo , hi ] NEW_LINE DEDENT if lo == hi : NEW_LINE INDENT result = 0 NEW_LINE DEDENT else : NEW_LINE INDENT best = None NEW_LINE if hi == len ( seq ) : NEW_LINE INDENT o1 = opt ( lo + 1 , hi ) NEW_LINE if o1 is not None : NEW_LINE INDENT best = max ( best , o1 ) NEW_LINE DEDENT DEDENT for i in xrange ( lo + 1 , hi ) : NEW_LINE INDENT o1 = opt ( lo + 1 , i ) NEW_LINE o2 = opt ( i + 1 , hi ) NEW_LINE if o1 is not None and o2 is not None : NEW_LINE INDENT best = max ( best , o1 + ( 10 if seq [ lo ] == seq [ i ] else 5 ) + o2 ) NEW_LINE DEDENT DEDENT result = best NEW_LINE DEDENT memo [ lo , hi ] = result NEW_LINE return result NEW_LINE DEDENT return opt ( 0 , len ( seq ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT import sys NEW_LINE fp = open ( sys . argv [ 1 ] ) NEW_LINE def readline ( ) : NEW_LINE INDENT return fp . readline ( ) . strip ( ) NEW_LINE DEDENT num_cases = int ( readline ( ) ) NEW_LINE for i in xrange ( num_cases ) : NEW_LINE INDENT seq = readline ( ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( i + 1 , solve ( seq ) ) NEW_LINE DEDENT DEDENT

import sys , math , random , operator NEW_LINE from string import ascii_lowercase NEW_LINE from string import ascii_uppercase NEW_LINE from fractions import Fraction , gcd NEW_LINE from decimal import Decimal , getcontext NEW_LINE from itertools import product , permutations , combinations NEW_LINE from Queue import Queue , PriorityQueue NEW_LINE from collections import deque , defaultdict , Counter NEW_LINE getcontext ( ) . prec = 100 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE INF = float ( " + inf " ) NEW_LINE if sys . subversion [ 0 ] != " CPython " : NEW_LINE INDENT raw_input = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE DEDENT pr = lambda * args : sys . stdout . write ( " ▁ " . join ( str ( x ) for x in args ) + " \n " ) NEW_LINE epr = lambda * args : sys . stderr . write ( " ▁ " . join ( str ( x ) for x in args ) + " \n " ) NEW_LINE die = lambda * args : pr ( * args ) ^ exit ( 0 ) NEW_LINE read_str = raw_input NEW_LINE read_strs = lambda : raw_input ( ) . split ( ) NEW_LINE read_int = lambda : int ( raw_input ( ) ) NEW_LINE read_ints = lambda : map ( int , raw_input ( ) . split ( ) ) NEW_LINE read_float = lambda : float ( raw_input ( ) ) NEW_LINE read_floats = lambda : map ( float , raw_input ( ) . split ( ) ) NEW_LINE def solve_brute ( ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT def solve_fast ( s ) : NEW_LINE INDENT st = [ ] NEW_LINE ans = 0 NEW_LINE for c in s : NEW_LINE INDENT if st and st [ - 1 ] == c : NEW_LINE INDENT st . pop ( ) NEW_LINE ans += 10 NEW_LINE DEDENT else : NEW_LINE INDENT st . append ( c ) NEW_LINE DEDENT DEDENT ans += ( len ( st ) // 2 ) * 5 NEW_LINE return ans NEW_LINE DEDENT t = read_int ( ) NEW_LINE for t in xrange ( 1 , t + 1 ) : NEW_LINE INDENT s = read_str ( ) NEW_LINE ans_fast = solve_fast ( s ) NEW_LINE if 0 : NEW_LINE INDENT ans_brute = solve_brute ( s ) NEW_LINE if ans_fast != ans_brute : NEW_LINE INDENT print " BAD " , ans_brute , ans_fast NEW_LINE quit ( ) NEW_LINE DEDENT DEDENT print " Case ▁ # % d : ▁ % d " % ( t , ans_fast ) NEW_LINE DEDENT

import os , inspect NEW_LINE problemName = ' A ' NEW_LINE testCase = ' large ' NEW_LINE attempt = 0 NEW_LINE def solution ( preferences ) : NEW_LINE INDENT totalTaken = 0 NEW_LINE holding = [ ] NEW_LINE points = 0 NEW_LINE for c in preferences : NEW_LINE INDENT if len ( holding ) == 0 or holding [ - 1 ] != c : NEW_LINE INDENT if totalTaken == len ( preferences ) / 2 : NEW_LINE INDENT holding . pop ( ) NEW_LINE points += 5 NEW_LINE DEDENT else : NEW_LINE INDENT holding . append ( c ) NEW_LINE totalTaken += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT holding . pop ( ) NEW_LINE points += 10 NEW_LINE DEDENT DEDENT return points NEW_LINE DEDENT currentDir = os . path . dirname ( os . path . abspath ( inspect . getfile ( inspect . currentframe ( ) ) ) ) NEW_LINE if testCase in [ ' large ' , ' example ' ] : NEW_LINE INDENT inputString = problemName + ( ' - % s ' % testCase ) NEW_LINE outputString = problemName + ( ' - % s ' % testCase ) NEW_LINE DEDENT else : NEW_LINE INDENT inputString = problemName + ( ' - % s - attempt % d ' % ( testCase , attempt ) ) NEW_LINE outputString = problemName + ( ' - % s ' % testCase ) NEW_LINE DEDENT inFile = os . path . join ( currentDir , ' inputfiles ' , ' % s . in ' % inputString ) NEW_LINE outFile = os . path . join ( currentDir , ' outputfiles ' , ' % s . out ' % outputString ) NEW_LINE if os . path . exists ( outFile ) : NEW_LINE INDENT os . remove ( outFile ) NEW_LINE DEDENT with open ( inFile , ' r ' ) as inputfile : NEW_LINE INDENT numberOfCases = int ( inputfile . readline ( ) ) NEW_LINE for case in xrange ( 1 , numberOfCases + 1 ) : NEW_LINE INDENT result = solution ( inputfile . readline ( ) . strip ( ) ) NEW_LINE with open ( outFile , ' a ' ) as f : NEW_LINE INDENT f . write ( ' Case ▁ # % d : ▁ % d \n ' % ( case , result ) ) NEW_LINE DEDENT DEDENT DEDENT

def initialize_solver ( ) : NEW_LINE INDENT pass NEW_LINE DEDENT def solve_testcase ( ) : NEW_LINE INDENT s = read ( False , str ) NEW_LINE c1 = 0 NEW_LINE c2 = 0 NEW_LINE j1 = 0 NEW_LINE j2 = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT c1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT j1 += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT c2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT j2 += 1 NEW_LINE DEDENT DEDENT DEDENT return 10 * ( min ( [ c1 , c2 ] ) + min ( [ j1 , j2 ] ) ) + 5 * abs ( c1 - c2 ) 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

T = input ( ) NEW_LINE from collections import defaultdict NEW_LINE def solve ( S ) : NEW_LINE INDENT dp = [ { ' ' : 0 } ] NEW_LINE for i , ch in enumerate ( S ) : NEW_LINE INDENT last = dp [ - 1 ] NEW_LINE nxt = defaultdict ( int ) NEW_LINE for pre , val in last . iteritems ( ) : NEW_LINE INDENT if not ( len ( S ) - i < len ( pre ) ) : NEW_LINE INDENT st = pre + ch NEW_LINE nxt [ st ] = max ( nxt [ st ] , val ) NEW_LINE DEDENT if pre : NEW_LINE INDENT sc = val + ( 10 if ch == pre [ - 1 ] else 5 ) NEW_LINE st = pre [ : - 1 ] NEW_LINE nxt [ st ] = max ( nxt [ st ] , sc ) NEW_LINE DEDENT DEDENT dp . append ( nxt ) NEW_LINE DEDENT return max ( dp [ - 1 ] . values ( ) ) NEW_LINE DEDENT for i in range ( 1 , T + 1 ) : NEW_LINE INDENT S = raw_input ( ) . strip ( ) NEW_LINE print ' Case ▁ # { } : ▁ { } ' . format ( i , solve ( S ) ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String args [ ] ) { ( new Main ( ) ) . solve ( ) ; } void solve ( ) { Scanner cin = new Scanner ( System . in ) ; int T = cin . nextInt ( ) ; for ( int C = 1 ; C <= T ; ++ C ) { int Row = cin . nextInt ( ) ; int Col = cin . nextInt ( ) ; int Num = cin . nextInt ( ) ; System . out . println ( " Case ▁ # " + C + " : ▁ " + solve ( Row , Col , Num ) ) ; } } int solve ( int R , int C , int N ) { List < Integer > all = new ArrayList < Integer > ( ) ; List < Integer > all2 = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < R ; ++ i ) { for ( int j = 0 ; j < C ; ++ j ) { int wall = 0 ; if ( i > 0 ) { ++ wall ; } if ( j > 0 ) { ++ wall ; } if ( i + 1 < R ) { ++ wall ; } if ( j + 1 < C ) { ++ wall ; } if ( ( i + j ) % 2 == 0 ) { all . add ( wall ) ; } else { all2 . add ( wall ) ; } } } int ret = 0 ; Collections . sort ( all ) ; for ( int i = 0 ; i < all . size ( ) - ( R * C - N ) ; ++ i ) { ret += all . get ( i ) ; } int ret2 = 0 ; Collections . sort ( all2 ) ; for ( int i = 0 ; i < all2 . size ( ) - ( R * C - N ) ; ++ i ) { ret2 += all2 . get ( i ) ; } return Math . min ( ret , ret2 ) ; } }

import java . util . * ; public class B { String solve ( Scanner sc ) { int R = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < 1 << ( R * C ) ; i ++ ) { if ( Integer . bitCount ( i ) == N ) { int s = 0 ; boolean [ ] [ ] b = new boolean [ R ] [ C ] ; for ( int r = 0 ; r < R ; r ++ ) { for ( int c = 0 ; c < C ; c ++ ) { b [ r ] [ c ] = ( i & ( 1 << ( r * C + c ) ) ) != 0 ; if ( b [ r ] [ c ] ) { if ( r > 0 && b [ r - 1 ] [ c ] ) { s ++ ; } if ( c > 0 && b [ r ] [ c - 1 ] ) { s ++ ; } } } } min = Math . min ( min , s ) ; } } return " " + min ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; for ( int cs = 1 ; cs <= T ; cs ++ ) { String res = new B ( ) . solve ( sc ) ; System . out . println ( " Case ▁ # " + cs + " : ▁ " + res ) ; } sc . close ( ) ; } }

import java . util . * ; public class NN { static Scanner sc = new Scanner ( System . in ) ; static int k ; { k = sc . nextInt ( ) ; for ( int kk = 1 ; kk <= k ; kk ++ ) { System . out . print ( " Case ▁ # " + kk + " : ▁ " ) ; int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int a = val ( r , c , n ) ; System . out . println ( val ( r , c , n ) ) ; } } static int thing ( int r , int c , int n , int basegood , int corn , int edg ) { if ( n <= basegood ) return 0 ; n -= basegood ; if ( n <= corn ) return 2 * n ; int result = 2 * corn ; n -= corn ; if ( n <= edg ) return result + 3 * n ; result += 3 * edg ; n -= edg ; return result + 4 * n ; } static int special ( int size , int n ) { if ( size % 2 == 0 ) { if ( n <= size / 2 ) return 0 ; return 2 * ( n - size / 2 ) - 1 ; } else { if ( n <= size / 2 + 1 ) return 0 ; return 2 * ( n - size / 2 - 1 ) ; } } static int val ( int r , int c , int n ) { if ( r == 1 ) return special ( c , n ) ; if ( c == 1 ) return special ( r , n ) ; if ( ( r * c ) % 2 == 0 ) return thing ( r , c , n , r * c / 2 , 2 , r + c - 4 ) ; else return Math . min ( thing ( r , c , n , r * c / 2 + 1 , 0 , r + c - 2 ) , thing ( r , c , n , r * c / 2 , 4 , r + c - 6 ) ) ; } public static void main ( String [ ] args ) { new NN ( ) ; } }

from sys import stdin , stderr NEW_LINE from math import log10 NEW_LINE def solve ( R , C , N ) : NEW_LINE INDENT if R == 1 or C == 1 : NEW_LINE INDENT L = R * C NEW_LINE if L % 2 == 1 : NEW_LINE INDENT return max ( N - L / 2 - 1 , 0 ) * 2 NEW_LINE DEDENT else : NEW_LINE INDENT if N <= L / 2 : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 + ( N - L / 2 - 1 ) * 2 NEW_LINE DEDENT DEDENT DEDENT if ( R * C ) % 2 == 0 : NEW_LINE INDENT if N <= R * C / 2 : return 0 NEW_LINE inner = ( R - 2 ) * ( C - 2 ) / 2 NEW_LINE edge = R + C - 4 NEW_LINE conner = 2 NEW_LINE DEDENT else : NEW_LINE INDENT if N <= ( R * C + 1 ) / 2 : return 0 NEW_LINE if N <= ( R * C + 1 ) / 2 + 1 : return 3 NEW_LINE inner = ( ( R - 2 ) * ( C - 2 ) + 1 ) / 2 NEW_LINE edge = R + C - 6 NEW_LINE conner = 4 NEW_LINE pass NEW_LINE DEDENT ret = ( R - 1 ) * C + ( C - 1 ) * R NEW_LINE n = R * C - N NEW_LINE if n <= inner : return ret - n * 4 NEW_LINE ret -= inner * 4 NEW_LINE n -= inner NEW_LINE if n <= edge : return ret - n * 3 NEW_LINE ret -= edge * 3 NEW_LINE n -= edge NEW_LINE return ret - n * 2 NEW_LINE DEDENT T = int ( stdin . readline ( ) ) NEW_LINE for t in range ( T ) : NEW_LINE INDENT R , C , N = ( int ( wd ) for wd in stdin . readline ( ) . split ( ) ) NEW_LINE print " Case ▁ # % i : " % ( t + 1 ) , NEW_LINE print solve ( R , C , N ) NEW_LINE DEDENT

import sys NEW_LINE infile = None NEW_LINE outfile = None NEW_LINE def readline ( ) : NEW_LINE INDENT x = infile . readline ( ) NEW_LINE if len ( x ) > 0 and x [ - 1 ] == ' \n ' : NEW_LINE INDENT return x [ : - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return x NEW_LINE DEDENT DEDENT def readint ( ) : NEW_LINE INDENT return int ( readline ( ) ) NEW_LINE DEDENT def readfloat ( ) : NEW_LINE INDENT return float ( readline ( ) ) NEW_LINE DEDENT def readints ( ) : NEW_LINE INDENT return [ int ( x ) for x in readline ( ) . split ( ) ] NEW_LINE DEDENT def readfloats ( ) : NEW_LINE INDENT return [ float ( x ) for x in readline ( ) . split ( ) ] NEW_LINE DEDENT def writeline ( x ) : NEW_LINE INDENT outfile . write ( x + ' \n ' ) NEW_LINE DEDENT def writecase ( casenum , answer ) : NEW_LINE INDENT outfile . write ( ' Case ▁ # { : d } : ▁ { } \n ' . format ( casenum , answer ) ) NEW_LINE DEDENT def run ( main ) : NEW_LINE INDENT global infile , outfile NEW_LINE args = sys . argv NEW_LINE infile = sys . stdin NEW_LINE outfile = sys . stdout NEW_LINE if len ( args ) == 2 : NEW_LINE INDENT if args [ 1 ] != ' - ' : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE if args [ 1 ] . endswith ( ' . in ' ) : NEW_LINE INDENT outfile = open ( args [ 1 ] [ : - 3 ] + ' . out ' , ' w ' ) NEW_LINE DEDENT DEDENT DEDENT elif len ( args ) == 3 : NEW_LINE INDENT if args [ 1 ] != ' - ' : NEW_LINE INDENT infile = open ( args [ 1 ] , ' r ' ) NEW_LINE DEDENT if args [ 2 ] != ' - ' : NEW_LINE INDENT outfile = open ( args [ 2 ] , ' w ' ) NEW_LINE DEDENT DEDENT elif len ( args ) > 3 : NEW_LINE INDENT print ( " Expected ▁ 0 , ▁ 1 , ▁ or ▁ 2 ▁ arguments , ▁ not ▁ { } " . format ( len ( args ) - 1 ) ) NEW_LINE print ( args ) NEW_LINE return NEW_LINE DEDENT t = readint ( ) NEW_LINE for casenum in range ( 1 , t + 1 ) : NEW_LINE INDENT main ( casenum ) NEW_LINE DEDENT if infile is not sys . stdin : NEW_LINE INDENT infile . close ( ) NEW_LINE DEDENT if outfile is not sys . stdout : NEW_LINE INDENT outfile . close ( ) NEW_LINE DEDENT DEDENT

def run ( x , r , c , k ) : NEW_LINE INDENT a = [ [ 0 ] * c for i in range ( r ) ] NEW_LINE for i in range ( r ) : NEW_LINE INDENT for j in range ( ( i & 1 ) ^ x , c , 2 ) : NEW_LINE INDENT if i > 0 : NEW_LINE INDENT a [ i - 1 ] [ j ] += 1 NEW_LINE DEDENT if j > 0 : NEW_LINE INDENT a [ i ] [ j - 1 ] += 1 NEW_LINE DEDENT if i + 1 < r : NEW_LINE INDENT a [ i + 1 ] [ j ] += 1 NEW_LINE DEDENT if j + 1 < c : NEW_LINE INDENT a [ i ] [ j + 1 ] += 1 NEW_LINE DEDENT DEDENT DEDENT b = [ j for i in a for j in i ] NEW_LINE b . sort ( ) NEW_LINE return sum ( b [ : k ] ) NEW_LINE DEDENT n = input ( ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT r , c , k = [ int ( x ) for x in raw_input ( ) . split ( ) ] NEW_LINE ans = min ( run ( 0 , r , c , k ) , run ( 1 , r , c , k ) ) NEW_LINE print " Case ▁ # % d : ▁ % d " % ( i , ans ) NEW_LINE DEDENT

from functools import * NEW_LINE inf = open ( ' B - large . in ' ) NEW_LINE ouf = open ( ' B - large . out ' , ' w ' ) NEW_LINE input = lambda : inf . readline ( ) . strip ( ) NEW_LINE print = partial ( print , file = ouf ) NEW_LINE def solve ( ) : NEW_LINE INDENT r , c , n = map ( int , input ( ) . split ( ) ) NEW_LINE if r > c : NEW_LINE INDENT r , c = c , r NEW_LINE DEDENT if n <= ( r * c ) // 2 + ( r * c ) % 2 : NEW_LINE INDENT print ( 0 ) NEW_LINE return NEW_LINE DEDENT free = r * c - n NEW_LINE cur = ( r - 1 ) * c + ( c - 1 ) * r NEW_LINE if r == 1 : NEW_LINE INDENT if c % 2 == 0 : NEW_LINE INDENT ways = [ [ 2 ] * ( c // 2 - 1 ) + [ 1 ] ] NEW_LINE DEDENT else : NEW_LINE INDENT ways = [ [ 2 ] * ( c // 2 ) , [ 2 ] * ( c // 2 - 1 ) + [ 1 , 1 ] ] NEW_LINE DEDENT DEDENT elif r * c % 2 == 0 : NEW_LINE INDENT ways = [ [ 4 ] * ( ( r - 2 ) * ( c - 2 ) // 2 ) + [ 3 ] * ( r - 2 + c - 2 ) + [ 2 , 2 ] ] NEW_LINE DEDENT else : NEW_LINE INDENT ways = [ [ 4 ] * ( ( r - 2 ) * ( c - 2 ) // 2 + 1 ) + [ 3 ] * ( r - 3 + c - 3 ) + [ 2 ] * 4 , [ 4 ] * ( ( r - 2 ) * ( c - 2 ) // 2 ) + [ 3 ] * ( r - 1 + c - 1 ) , ] NEW_LINE DEDENT print ( cur - max ( sum ( way [ : free ] ) for way in ways ) ) 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 sys NEW_LINE def debug ( * args ) : NEW_LINE INDENT print ( * args , file = sys . stderr ) NEW_LINE DEDENT def permutations ( n , k ) : NEW_LINE INDENT if k == 0 : NEW_LINE INDENT yield [ False ] * n NEW_LINE return NEW_LINE DEDENT for p in permutations ( n - 1 , k - 1 ) : NEW_LINE INDENT yield p + [ True ] NEW_LINE DEDENT if n > k : NEW_LINE INDENT for p in permutations ( n - 1 , k ) : NEW_LINE INDENT yield p + [ False ] NEW_LINE DEDENT DEDENT DEDENT def cost ( p , r , c ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( r ) : NEW_LINE INDENT for j in range ( c - 1 ) : NEW_LINE INDENT if p [ i * c + j ] and p [ i * c + j + 1 ] : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( r - 1 ) : NEW_LINE INDENT for j in range ( c ) : NEW_LINE INDENT if p [ i * c + j ] and p [ i * c + j + c ] : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT fin = sys . stdin NEW_LINE T = int ( fin . readline ( ) ) NEW_LINE for case in range ( 1 , T + 1 ) : NEW_LINE INDENT R , C , N = map ( int , fin . readline ( ) . split ( ) ) NEW_LINE best = R * C * 10 NEW_LINE for p in permutations ( R * C , N ) : NEW_LINE INDENT best = min ( best , cost ( p , R , C ) ) NEW_LINE DEDENT result = best NEW_LINE print ( " Case ▁ # % d : ▁ % s " % ( case , result ) ) NEW_LINE DEDENT


import java . io . BufferedWriter ; import java . io . File ; import java . io . FileWriter ; import java . io . PrintWriter ; import java . util . Scanner ; public class b { public static void main ( String [ ] Args ) throws Exception { Scanner sc = new Scanner ( new File ( " B - large . in " ) ) ; PrintWriter out = new PrintWriter ( new BufferedWriter ( new FileWriter ( new File ( " b . out " ) ) ) ) ; int cc = 0 ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { String x = sc . next ( ) ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) for ( int j = 0 ; j + 1 < x . length ( ) ; j ++ ) if ( x . charAt ( j ) > x . charAt ( j + 1 ) ) { String nx = x . substring ( 0 , j ) ; nx = nx + ( char ) ( x . charAt ( j ) - 1 ) ; while ( nx . length ( ) < x . length ( ) ) nx = nx + "9" ; x = nx ; } while ( x . length ( ) > 1 && x . charAt ( 0 ) == '0' ) x = x . substring ( 1 ) ; out . printf ( " Case ▁ # % d : ▁ % s % n " , ++ cc , x ) ; } out . close ( ) ; } }

import java . io . * ; import java . util . StringTokenizer ; public class B { private String solveTest ( ) throws IOException { String s = next ( ) ; int i = 0 ; while ( i < s . length ( ) - 1 && s . charAt ( i + 1 ) >= s . charAt ( i ) ) { i ++ ; } if ( i == s . length ( ) - 1 ) return s ; while ( i > 0 && s . charAt ( i - 1 ) == s . charAt ( i ) ) i -- ; String res = " " ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { res += j < i ? s . charAt ( j ) : j == i ? ( char ) ( s . charAt ( j ) - 1 ) : '9' ; } if ( res . charAt ( 0 ) == '0' ) res = res . substring ( 1 ) ; return res ; } private void solve ( ) throws IOException { int n = nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String res = solveTest ( ) ; System . out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + res ) ; out . println ( " Case ▁ # " + ( i + 1 ) + " : ▁ " + res ) ; } } BufferedReader br ; StringTokenizer st ; PrintWriter out ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new B ( ) . run ( ) ; } private void run ( ) throws FileNotFoundException { br = new BufferedReader ( new FileReader ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + " . in " ) ) ; out = new PrintWriter ( this . getClass ( ) . getSimpleName ( ) . substring ( 0 , 1 ) + " . out " ) ; try { solve ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } out . close ( ) ; } }

package qualification ; import java . io . * ; import java . util . * ; public class B_TidyNumbers { private static final String FILENAME = " B - large " ; private static final boolean STANDARD_OUTPUT = false ; public static void main ( String [ ] args ) throws Throwable { try ( BufferedReader in = new BufferedReader ( new FileReader ( FILENAME + " . in " ) ) ) { try ( PrintStream out = ! STANDARD_OUTPUT ? new PrintStream ( FILENAME + " . out " ) : System . out ) { for ( int t = 1 , T = Integer . parseInt ( in . readLine ( ) ) ; t <= T ; t ++ ) { char [ ] N = in . readLine ( ) . toCharArray ( ) ; int i = 1 , k = 0 ; for ( i = 1 ; i < N . length && N [ i ] >= N [ i - 1 ] ; i ++ ) { } if ( i < N . length ) { for ( k = i - 1 ; k >= 0 && N [ k ] == N [ i - 1 ] ; k -- ) { } N [ ++ k ] -- ; Arrays . fill ( N , k + 1 , N . length , '9' ) ; k = k == 0 && N [ 0 ] == '0' ? 1 : 0 ; } out . println ( " Case ▁ # " + t + " : ▁ " + new String ( N , k , N . length - k ) ) ; } } } } }

package com . company ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . PrintStream ; import java . util . Arrays ; import java . util . Scanner ; public class ProbB { private Scanner scanner = new Scanner ( System . in ) ; public void main ( ) { reDirect ( ) ; int T = scanner . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { long ans = run ( ) ; System . out . println ( " Case ▁ # " + cas + " : ▁ " + ans ) ; } } private long run ( ) { long input = scanner . nextLong ( ) ; char [ ] arr = Long . valueOf ( input ) . toString ( ) . toCharArray ( ) ; int x = arr . length ; for ( int i = 0 ; i < arr . length - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) { x = i + 1 ; break ; } } if ( x == arr . length ) { return input ; } int y = x - 1 ; while ( y > 0 && arr [ y ] == arr [ y - 1 ] ) y -- ; arr [ y ] -- ; for ( int i = y + 1 ; i < arr . length ; i ++ ) { arr [ i ] = '9' ; } return Long . valueOf ( new String ( arr ) ) ; } private void reDirect ( ) { try { FileInputStream fileInputStream = new FileInputStream ( " B - large . in " ) ; scanner = new Scanner ( fileInputStream ) ; PrintStream ps = new PrintStream ( new FileOutputStream ( " bout - large . txt " ) ) ; System . setOut ( ps ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } } }

package qualifier ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class BTidyNumbers { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ) { int tests = sc . nextInt ( ) ; for ( int t = 1 ; t <= tests ; t ++ ) { int [ ] digits = sc . next ( ) . chars ( ) . map ( i -> i - '0' ) . toArray ( ) ; for ( int x = 0 ; x < digits . length - 1 ; x ++ ) { if ( digits [ x ] > digits [ x + 1 ] ) { digits [ x ] -- ; for ( int y = x + 1 ; y < digits . length ; y ++ ) digits [ y ] = 9 ; while ( digits [ x ] < 0 || ( x > 0 && digits [ x ] < digits [ x - 1 ] ) ) { digits [ x ] = 9 ; digits [ x - 1 ] -- ; x -- ; } break ; } } int start = 0 ; while ( digits [ start ] == 0 ) start ++ ; StringBuilder sb = new StringBuilder ( ) ; for ( int x = start ; x < digits . length ; x ++ ) sb . append ( ( char ) ( digits [ x ] + '0' ) ) ; System . out . printf ( " Case ▁ # % d : ▁ % s % n " , t , sb . toString ( ) ) ; } } } }

def tidy ( N ) : NEW_LINE INDENT return list ( N ) == sorted ( N ) NEW_LINE DEDENT def solve ( N ) : NEW_LINE INDENT if N == '0' : NEW_LINE INDENT return ' ' NEW_LINE DEDENT if tidy ( N ) or len ( N ) <= 1 : NEW_LINE INDENT return N NEW_LINE DEDENT return solve ( str ( int ( N [ : - 1 ] ) - 1 ) ) + '9' NEW_LINE DEDENT T = int ( input ( ) ) NEW_LINE for case_number in range ( 1 , T + 1 ) : NEW_LINE INDENT N = input ( ) NEW_LINE print ( ' Case ▁ # % d : ' % case_number , solve ( N ) ) NEW_LINE DEDENT

infilecode = " BLI " 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" , " 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 = int ( input ( ) ) NEW_LINE print ( N ) NEW_LINE a = str ( N ) NEW_LINE l = len ( a ) NEW_LINE for i in range ( l - 1 , 0 , - 1 ) : NEW_LINE INDENT if a [ i ] >= a [ i - 1 ] : NEW_LINE INDENT continue NEW_LINE DEDENT a = a [ : i ] + "0" * ( l - i ) NEW_LINE N = int ( a ) - 1 NEW_LINE a = str ( N ) NEW_LINE DEDENT answer = a NEW_LINE print ( " Case ▁ # % d : " % case , answer ) NEW_LINE print ( " Case ▁ # % d : " % case , answer , file = output ) NEW_LINE DEDENT

def solve ( n ) : NEW_LINE INDENT digits = [ ] NEW_LINE while n : NEW_LINE INDENT digits . append ( n % 10 ) NEW_LINE n //= 10 NEW_LINE DEDENT digits = list ( reversed ( digits ) ) NEW_LINE ans = None NEW_LINE for i in range ( len ( digits ) ) : NEW_LINE INDENT if i and digits [ i ] < digits [ i - 1 ] : NEW_LINE INDENT break NEW_LINE DEDENT if i == 0 or digits [ i ] - 1 >= digits [ i - 1 ] : NEW_LINE INDENT if digits [ i ] - 1 == 0 : NEW_LINE INDENT ans = [ 9 ] * ( len ( digits ) - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = digits [ : i ] + [ digits [ i ] - 1 ] + [ 9 ] * ( len ( digits ) - i - 1 ) NEW_LINE DEDENT DEDENT if i == len ( digits ) - 1 : NEW_LINE INDENT ans = digits NEW_LINE DEDENT DEDENT return ' ' . join ( map ( str , ans ) ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT ntest = int ( input ( ) ) NEW_LINE for i in range ( ntest ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE ans = solve ( n ) NEW_LINE print ( " Case ▁ # % d : ▁ % s " % ( i + 1 , ans ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE NEW_LINE DEDENT

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 = int ( IN . readline ( ) ) NEW_LINE while True : NEW_LINE INDENT l = [ int ( c ) for c in str ( N ) ] NEW_LINE for i in xrange ( len ( l ) - 1 ) : NEW_LINE INDENT if l [ i ] > l [ i + 1 ] : NEW_LINE INDENT N = int ( str ( N ) [ : i + 1 ] + '0' * ( len ( l ) - i - 1 ) ) - 1 NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT OUT . write ( ' Case ▁ # { } : ▁ { } \n ' . format ( test + 1 , N ) ) NEW_LINE print test + 1 , N NEW_LINE DEDENT IN . close ( ) NEW_LINE OUT . close ( ) NEW_LINE

from __future__ import print_function NEW_LINE import sys NEW_LINE from sys import stdin NEW_LINE def eprint ( * args , ** kwargs ) : NEW_LINE INDENT print ( * args , file = sys . stderr , ** kwargs ) NEW_LINE DEDENT def ln ( f = int ) : NEW_LINE INDENT return list ( map ( f , stdin . readline ( ) . strip ( ) . split ( ) ) ) NEW_LINE DEDENT T , = ln ( ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE for test in range ( T ) : NEW_LINE INDENT s , = ln ( str ) NEW_LINE s = list ( map ( int , list ( s ) ) ) NEW_LINE prev = 9 NEW_LINE res = " " NEW_LINE ind = None NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] < s [ i - 1 ] : NEW_LINE INDENT ind = i NEW_LINE break NEW_LINE DEDENT DEDENT if ind != None : NEW_LINE INDENT for i in range ( ind + 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = 9 NEW_LINE DEDENT while ind != 0 and s [ ind ] < s [ ind - 1 ] : NEW_LINE INDENT s [ ind - 1 ] -= 1 NEW_LINE s [ ind ] = 9 NEW_LINE ind -= 1 NEW_LINE DEDENT DEDENT res = int ( " " . join ( list ( map ( str , s ) ) ) ) NEW_LINE print ( " Case ▁ # " + str ( test + 1 ) + " : ▁ " + str ( res ) ) NEW_LINE DEDENT


import java . util . Scanner ; public class B { static Scanner sc = new Scanner ( System . in ) ; static int N ; static long P ; public static void main ( String [ ] args ) throws Exception { int T = sc . nextInt ( ) ; for ( int t = 1 ; t <= T ; ++ t ) { N = sc . nextInt ( ) ; P = sc . nextLong ( ) ; System . out . println ( " Case ▁ # " + t + " : ▁ " + ( solveGuarantee ( 1L << N , P ) - 1 ) + " ▁ " + ( solveCould ( 1L << N , P ) - 1 ) ) ; } } static long solveGuarantee ( long n , long p ) { if ( p == n ) return n ; if ( p <= n / 2 ) return 1 ; return solveGuarantee ( n / 2 , p - n / 2 ) * 2 + 1 ; } static long solveCould ( long n , long p ) { if ( p == n ) return n ; if ( p >= n / 2 ) return n - 1 ; long c = solveCould ( n / 2 , p ) ; return c + c - 1 ; } }

package contest ; import java . util . * ; import java . io . * ; public class ManyPrizes { final static String PROBLEM_NAME = " mprizes " ; final static String WORK_DIR = " D : \\ Gcj\ \" + PROBLEM_NAME + " \ \" ; void solve ( Scanner sc , PrintWriter pw ) { int N = sc . nextInt ( ) ; long P = sc . nextLong ( ) ; long ans1 = - 1 ; long sum = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { sum += ( 1L << i ) ; if ( P <= sum ) { ans1 = ( 1L << ( N - i ) ) - 1 ; break ; } } if ( ans1 == - 1 ) ans1 = ( 1L << N ) ; long ans2 = - 1 ; int needWins = 0 ; while ( ( 1L << ( N - needWins ) ) > P ) needWins ++ ; ans2 = ( 1L << N ) - ( 1L << needWins ) + 1 ; ans1 -- ; ans2 -- ; pw . println ( ans1 + " ▁ " + ans2 ) ; } public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( new FileReader ( WORK_DIR + " input . txt " ) ) ; PrintWriter pw = new PrintWriter ( new FileWriter ( WORK_DIR + " output . txt " ) ) ; int caseCnt = sc . nextInt ( ) ; for ( int caseNum = 0 ; caseNum < caseCnt ; caseNum ++ ) { System . out . println ( " Processing ▁ test ▁ case ▁ " + ( caseNum + 1 ) ) ; pw . print ( " Case ▁ # " + ( caseNum + 1 ) + " : ▁ " ) ; new ManyPrizes ( ) . solve ( sc , pw ) ; } pw . flush ( ) ; pw . close ( ) ; sc . close ( ) ; } }

import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class B { void solve ( ) throws IOException { int t = nextInt ( ) ; for ( int testCase = 0 ; testCase < t ; testCase ++ ) { long n = nextInt ( ) ; long p = nextLong ( ) ; long max = 1l << n ; long a1 = 0 , a2 = max - 2 ; if ( p == 1 ) { a1 = a2 = 0 ; } else if ( p == max ) { a1 = a2 = max - 1 ; } else { long x = max >> 1l ; long y = x >> 1l ; long z = 2 ; while ( p > x ) { a1 += z ; z <<= 1l ; x |= y ; y >>= 1l ; } x = max >> 1l ; z = 2 ; while ( p < x ) { a2 -= z ; z <<= 1l ; x >>= 1l ; } } out . printf ( " Case ▁ # % d : ▁ % d ▁ % d \n " , testCase + 1 , a1 , a2 ) ; } } public static void main ( String [ ] args ) throws IOException { new B ( ) . run ( ) ; } void run ( ) throws IOException { reader = new BufferedReader ( new FileReader ( " input . txt " ) ) ; out = new PrintWriter ( new FileWriter ( " output . txt " ) ) ; tokenizer = null ; solve ( ) ; reader . close ( ) ; out . flush ( ) ; } BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter out ; int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; } String nextToken ( ) throws IOException { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } }

import java . math . BigInteger ; import java . util . * ; public class B { static BigInteger B ( long n ) { return BigInteger . valueOf ( n ) ; } static BigInteger A ( BigInteger A , BigInteger B ) { return A . add ( B ) ; } static BigInteger M ( BigInteger A , BigInteger B ) { return A . multiply ( B ) ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int cas = 1 ; cas <= T ; cas ++ ) { int n = in . nextInt ( ) ; BigInteger P = new BigInteger ( in . next ( ) ) ; BigInteger last_pos = B ( 2 ) . pow ( n ) . subtract ( P ) ; int min_ones = 0 ; for ( min_ones = 0 ; min_ones <= n ; min_ones ++ ) { BigInteger val = B ( 0 ) ; for ( int i = 0 ; i < min_ones ; i ++ ) val = A ( val , B ( 2 ) . pow ( n - 1 - i ) ) ; if ( val . compareTo ( last_pos ) >= 0 ) break ; } BigInteger last_win = B ( 2 ) . pow ( n ) . subtract ( B ( 2 ) . pow ( min_ones ) ) ; int min_zeroes = 0 ; for ( min_zeroes = 0 ; min_zeroes <= n ; min_zeroes ++ ) { BigInteger val = B ( 2 ) . pow ( n ) . subtract ( B ( 1 ) ) ; for ( int i = 0 ; i < min_zeroes ; i ++ ) val = val . subtract ( B ( 2 ) . pow ( n - 1 - i ) ) ; if ( val . compareTo ( last_pos ) < 0 ) break ; } BigInteger last_guarantee = B ( 2 ) . pow ( min_zeroes ) . subtract ( B ( 2 ) ) ; if ( last_pos . equals ( B ( 0 ) ) ) last_guarantee = B ( 2 ) . pow ( n ) . subtract ( B ( 1 ) ) ; System . out . printf ( " Case ▁ # % d : ▁ % s ▁ % s \n " , cas , last_guarantee , last_win ) ; } } }

import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Scanner ; public class B { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( B . class . getSimpleName ( ) + " . in " ) ) ; PrintWriter out = new PrintWriter ( new File ( B . class . getSimpleName ( ) + " . out " ) ) ; int T = in . nextInt ( ) ; for ( int i = 0 ; i < T ; i ++ ) { String s = " Case ▁ # " + ( i + 1 ) + " : ▁ " + new B ( ) . solve ( in ) ; out . println ( s ) ; System . out . println ( s ) ; } out . close ( ) ; } private String solve ( Scanner in ) { int n = in . nextInt ( ) ; long p = in . nextLong ( ) ; p -- ; long b = 1 ; if ( p == ( ( 1L << n ) - 1 ) ) { b = ( ( 1L << n ) - 1 ) + 2 ; } else { long pp = ( 1L << n ) - 1 - ( p + 1 ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ( ( pp >> i ) & 1 ) == 0 ) { b *= 2 ; } else { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( ( ( pp >> j ) & 1 ) == 0 ) { b *= 2 ; break ; } } break ; } } } long pp = ( 1L << n ) - 1 - p ; long c = 1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ( ( pp >> i ) & 1 ) == 1 ) { c *= 2 ; } else { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( ( ( pp >> j ) & 1 ) == 1 ) { c *= 2 ; break ; } } break ; } } return ( b - 2 ) + " ▁ " + ( ( 1L << n ) - c ) ; } }

def lpos ( N , L ) : NEW_LINE INDENT return 2 ** N - 2 ** ( N - L ) NEW_LINE DEDENT def wpos ( N , W ) : NEW_LINE INDENT return 2 ** ( N - W ) - 1 NEW_LINE DEDENT def hforl ( N , L ) : NEW_LINE INDENT r = 0 NEW_LINE for i in xrange ( L ) : NEW_LINE INDENT r = 2 * r + 2 NEW_LINE DEDENT return min ( 2 ** N - 1 , r ) NEW_LINE DEDENT def hforw ( N , W ) : NEW_LINE INDENT r = 0 NEW_LINE for i in xrange ( W ) : NEW_LINE INDENT r = 2 * r + 1 NEW_LINE DEDENT return max ( 0 , 2 ** N - r - 1 ) NEW_LINE DEDENT def solve ( N , P ) : NEW_LINE INDENT maxl = 0 NEW_LINE while maxl <= N and lpos ( N , maxl ) < P : maxl += 1 NEW_LINE maxl -= 1 NEW_LINE guaranteed = hforl ( N , maxl ) NEW_LINE minw = N NEW_LINE while minw >= 0 and wpos ( N , minw ) < P : minw -= 1 NEW_LINE minw += 1 NEW_LINE could = hforw ( N , minw ) NEW_LINE return ( guaranteed , could ) NEW_LINE DEDENT T = input ( ) NEW_LINE for t in xrange ( T ) : NEW_LINE INDENT N , P = map ( int , raw_input ( ) . split ( ) ) NEW_LINE s = solve ( N , P ) NEW_LINE print ' Case ▁ # % s : ▁ % s ▁ % s ' % ( t + 1 , s [ 0 ] , s [ 1 ] ) NEW_LINE DEDENT

code = " B - large " NEW_LINE infile = code + " . in " NEW_LINE outfile = code + " . out " NEW_LINE def willwin ( n , s ) : NEW_LINE INDENT pos = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if s > 0 : NEW_LINE INDENT pos += 2 ** ( n - i - 1 ) NEW_LINE s = ( s - 1 ) // 2 NEW_LINE DEDENT DEDENT return pos NEW_LINE DEDENT def maywin ( n , w ) : NEW_LINE INDENT pos = 0 NEW_LINE for i in xrange ( n ) : NEW_LINE INDENT if w > 0 : NEW_LINE INDENT w = ( w - 1 ) // 2 NEW_LINE DEDENT else : NEW_LINE INDENT pos += 2 ** ( n - i - 1 ) NEW_LINE DEDENT DEDENT return pos NEW_LINE DEDENT def solve ( n , p ) : NEW_LINE INDENT if p == 2 ** n : NEW_LINE INDENT return p - 1 , p - 1 NEW_LINE DEDENT low , high = 0 , 2 ** n - 1 NEW_LINE while high - low > 1 : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if willwin ( n , mid ) < p : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT will = low NEW_LINE low , high = 0 , 2 ** n - 1 NEW_LINE while high - low > 1 : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if maywin ( n , 2 ** n - mid - 1 ) < p : NEW_LINE INDENT low = mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid NEW_LINE DEDENT DEDENT may = low NEW_LINE return will , may NEW_LINE DEDENT lines = [ s . strip ( ) for s in open ( infile ) ] NEW_LINE c = int ( lines [ 0 ] ) NEW_LINE f = open ( outfile , " w " ) NEW_LINE lineno = 1 NEW_LINE for i in range ( 1 , c + 1 ) : NEW_LINE INDENT n , p = map ( int , lines [ lineno ] . split ( ) ) NEW_LINE r = solve ( n , p ) NEW_LINE lineno += 1 NEW_LINE msg = " Case ▁ # { 0 } : ▁ { 1[0 ] } ▁ { 1[1 ] } " . format ( i , r ) NEW_LINE print msg NEW_LINE print >> f , msg NEW_LINE DEDENT f . close ( ) NEW_LINE

import sys NEW_LINE import re NEW_LINE import math NEW_LINE import string NEW_LINE f = open ( sys . argv [ 1 ] , ' r ' ) NEW_LINE num = int ( f . readline ( ) ) NEW_LINE for i in xrange ( num ) : NEW_LINE INDENT l = f . readline ( ) NEW_LINE N , P = [ int ( x ) for x in l . split ( ) ] NEW_LINE if 2 ** N == P : NEW_LINE INDENT print ' Case ▁ # { } : ' . format ( i + 1 ) , 2 ** N - 1 , 2 ** N - 1 NEW_LINE continue NEW_LINE DEDENT j = 0 NEW_LINE while P >= 2 ** j : NEW_LINE INDENT j += 1 NEW_LINE DEDENT j -= 1 NEW_LINE k = 1 NEW_LINE while P > 2 ** N - 2 ** ( N - k ) : NEW_LINE INDENT k += 1 NEW_LINE DEDENT print ' Case ▁ # { } : ' . format ( i + 1 ) , 2 ** k - 2 , 2 ** N - 2 ** ( N - j ) NEW_LINE DEDENT

from sys import * NEW_LINE from heapq import * NEW_LINE import math NEW_LINE def write ( msg ) : NEW_LINE INDENT stdout . write ( msg ) NEW_LINE fo . write ( msg ) NEW_LINE DEDENT def writeln ( msg ) : NEW_LINE INDENT write ( str ( msg ) + ' \n ' ) NEW_LINE DEDENT def readint ( ) : NEW_LINE INDENT return int ( fi . readline ( ) ) NEW_LINE DEDENT def readints ( ) : NEW_LINE INDENT return [ int ( X ) for X in fi . readline ( ) . split ( ) ] NEW_LINE DEDENT def readstr ( ) : NEW_LINE INDENT return fi . readline ( ) . rstrip ( ) NEW_LINE DEDENT fni = " % s - % s - % s . in " % ( argv [ 1 ] , argv [ 2 ] , argv [ 3 ] ) NEW_LINE fno = " % s - % s - % s . out " % ( argv [ 1 ] , argv [ 2 ] , argv [ 3 ] ) NEW_LINE fi = open ( fni , ' r ' ) NEW_LINE fo = open ( fno , ' w ' ) NEW_LINE def ffail ( start , step , num , prizes ) : NEW_LINE INDENT if prizes >= num : NEW_LINE INDENT return start + step * ( num - 1 ) + 1 NEW_LINE DEDENT if prizes <= 0 : NEW_LINE INDENT return start NEW_LINE DEDENT if 2 * prizes <= num : NEW_LINE INDENT return start + step NEW_LINE DEDENT return ffail ( start + step , step * 2 , num / 2 , prizes - num / 2 ) NEW_LINE DEDENT def wwin ( start , step , num , prizes ) : NEW_LINE INDENT if prizes >= num : NEW_LINE INDENT return start + step * ( num - 1 ) NEW_LINE DEDENT if prizes <= 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return wwin ( start , step * 2 , num / 2 , prizes ) NEW_LINE DEDENT num_cases = readint ( ) NEW_LINE for case in range ( 1 , 1 + num_cases ) : NEW_LINE INDENT ( N , P ) = readints ( ) NEW_LINE g = ffail ( 0 , 1 , 2 ** N , P ) - 1 NEW_LINE w = wwin ( 0 , 1 , 2 ** N , P ) NEW_LINE writeln ( " Case ▁ # % d : ▁ % d ▁ % d " % ( case , g , w ) ) NEW_LINE DEDENT

def reader ( inFile ) : NEW_LINE INDENT return tuple ( inFile . getInts ( ) ) NEW_LINE DEDENT def solver ( ( N , p ) ) : NEW_LINE INDENT wins = [ ( ( ( p - 1 ) >> i ) & 1 ) == 0 for i in xrange ( N ) ] [ : : - 1 ] NEW_LINE a1 = 0 NEW_LINE for win in wins : NEW_LINE INDENT if not win : NEW_LINE INDENT a1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT a1 = ( ( 1 << ( a1 + 1 ) ) - 2 ) if ( a1 < N ) else ( ( 1 << N ) - 1 ) NEW_LINE a2 = 0 NEW_LINE for win in wins : NEW_LINE INDENT if win : NEW_LINE INDENT a2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( a2 == len ( [ win for win in wins if win ] ) ) : NEW_LINE INDENT a2 -= 1 NEW_LINE DEDENT a2 = ( 1 << N ) - ( 1 << ( a2 + 1 ) ) NEW_LINE return " % d ▁ % d " % ( a1 , a2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT from GCJ import GCJ NEW_LINE GCJ ( reader , solver , " / Users / lpebody / gcj / 2013_2 / b / " , " b " ) . run ( ) NEW_LINE DEDENT