import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; import static java . util . stream . Collectors . joining ; public class Main { private static final String WHITE = " . " ; private static final String BLACK = " # " ; public static List < String > process ( int H , int W , List < String > a ) { final List < String > removedBlankRows = a . stream ( ) . filter ( Main :: keepRowWithAnyBlack ) . collect ( Collectors . toList ( ) ) ; final List < String > transposed = transpose ( removedBlankRows ) ; final List < String > compressedTranspose = transposed . stream ( ) . filter ( Main :: keepRowWithAnyBlack ) . collect ( Collectors . toList ( ) ) ; return transpose ( compressedTranspose ) ; } private static boolean keepRowWithAnyBlack ( String row ) { return row . chars ( ) . anyMatch ( Main :: isBlack ) ; } private static boolean isBlack ( int c ) { return c == BLACK . codePointAt ( 0 ) ; } private static List < String > transpose ( List < String > grid ) { if ( grid . isEmpty ( ) ) { return new ArrayList < > ( ) ; } else { final int W = grid . get ( 0 ) . length ( ) ; return IntStream . range ( 0 , W ) . boxed ( ) . map ( i -> grid . stream ( ) . map ( row -> row . substring ( i , i + 1 ) ) . collect ( joining ( ) ) ) . collect ( Collectors . toList ( ) ) ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; final List < String > a = IntStream . range ( 0 , H ) . mapToObj ( i -> sc . next ( ) ) . collect ( Collectors . toList ( ) ) ; final List < String > result = process ( H , W , a ) ; result . forEach ( System . out :: println ) ; } }


f = lambda s : zip ( * [ t for t in s if ' # ' in t ] ) ; print ( * map ( ' ' . join , f ( f ( open ( 0 ) ) ) ) ) NEW_LINE


H , W = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ [ 0 ] * W for _ in range ( H ) ] NEW_LINE for h in range ( H ) : NEW_LINE INDENT a [ h ] = [ inp for inp in input ( ) ] NEW_LINE DEDENT check = [ [ 0 ] * W for _ in range ( H ) ] NEW_LINE for h in range ( H ) : NEW_LINE INDENT for w in range ( W ) : NEW_LINE INDENT if a [ h ] [ w ] == ' # ' : NEW_LINE INDENT check [ h ] [ w ] = 1 NEW_LINE DEDENT DEDENT DEDENT final_w = [ 0 ] * W NEW_LINE for h in range ( H ) : NEW_LINE INDENT final_w = [ final_w [ w ] + check [ h ] [ w ] for w in range ( W ) ] NEW_LINE DEDENT final_h = [ 0 ] * H NEW_LINE for w in range ( W ) : NEW_LINE INDENT final_h = [ final_h [ h ] + check [ h ] [ w ] for h in range ( H ) ] NEW_LINE DEDENT for h in range ( H ) : NEW_LINE INDENT res = ' ' NEW_LINE for w in range ( W ) : NEW_LINE INDENT if final_w [ w ] >= 1 and final_h [ h ] >= 1 : NEW_LINE INDENT res += a [ h ] [ w ] NEW_LINE DEDENT DEDENT print ( res + ' \n ' ) NEW_LINE DEDENT


H , W = map ( int , input ( ) . split ( ) ) NEW_LINE box = [ ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT a = [ j for j in input ( ) ] NEW_LINE if all ( j == ' . ' for j in a ) : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT box . append ( a ) NEW_LINE DEDENT DEDENT idx = [ ] NEW_LINE for i in range ( len ( box [ 0 ] ) ) : NEW_LINE INDENT ct = 0 NEW_LINE for j in box : NEW_LINE INDENT if j [ i ] == ' . ' : NEW_LINE INDENT ct += 1 NEW_LINE DEDENT DEDENT if ct == len ( box ) : NEW_LINE INDENT idx . append ( i ) NEW_LINE DEDENT DEDENT for i in box : NEW_LINE INDENT for j in range ( len ( i ) ) : NEW_LINE INDENT if j < len ( i ) - 1 : NEW_LINE INDENT if j in idx : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT print ( i [ j ] , end = ' ' ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if j in idx : NEW_LINE INDENT print ( ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( i [ j ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT


def main ( ) : NEW_LINE INDENT H , W = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ [ " . " for _ in range ( W ) ] for _ in range ( H ) ] NEW_LINE ans = [ ] NEW_LINE is_column_white = [ True ] * H NEW_LINE is_row_white = [ True ] * W NEW_LINE for i in range ( H ) : NEW_LINE INDENT row = input ( ) NEW_LINE for j in range ( W ) : NEW_LINE INDENT a [ i ] [ j ] = row [ j ] NEW_LINE if row [ j ] == " # " : NEW_LINE INDENT is_column_white [ i ] = False NEW_LINE is_row_white [ j ] = False NEW_LINE DEDENT DEDENT DEDENT for i in range ( H ) : NEW_LINE INDENT if is_column_white [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT ans_row = " " NEW_LINE for j in range ( W ) : NEW_LINE INDENT if is_row_white [ j ] : NEW_LINE INDENT continue NEW_LINE DEDENT ans_row += a [ i ] [ j ] NEW_LINE DEDENT print ( ans_row ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; char [ ] [ ] map = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) map [ i ] = sc . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < h ; i ++ ) { boolean F = true ; for ( int j = 0 ; j < w ; j ++ ) { if ( map [ i ] [ j ] == ' # ' ) { F = false ; break ; } } if ( F == true ) { for ( int j = 0 ; j < w ; j ++ ) { map [ i ] [ j ] = ' x ' ; } } } for ( int i = 0 ; i < w ; i ++ ) { boolean F = true ; for ( int j = 0 ; j < h ; j ++ ) { if ( map [ j ] [ i ] == ' # ' ) { F = false ; break ; } } if ( F == true ) { for ( int j = 0 ; j < h ; j ++ ) { map [ j ] [ i ] = ' x ' ; } } } for ( int i = 0 ; i < h ; i ++ ) { StringBuilder sb = new StringBuilder ( " " ) ; boolean F = true ; for ( int j = 0 ; j < w ; j ++ ) { if ( map [ i ] [ j ] != ' x ' ) sb . append ( map [ i ] [ j ] ) ; } if ( ! sb . toString ( ) . equals ( " " ) ) System . out . println ( sb ) ; } } }

H , W = map ( int , input ( ) . split ( ) ) NEW_LINE bd = [ ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT bd . append ( input ( ) ) NEW_LINE DEDENT x = set ( ) NEW_LINE y = set ( ) NEW_LINE for i in range ( H ) : NEW_LINE INDENT for j in range ( W ) : NEW_LINE INDENT if bd [ i ] [ j ] == " # " : NEW_LINE INDENT x . add ( j ) NEW_LINE y . add ( i ) NEW_LINE DEDENT DEDENT DEDENT for i in y : NEW_LINE INDENT for j in x : NEW_LINE INDENT print ( bd [ i ] [ j ] , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT


import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int H = input . nextInt ( ) ; int W = input . nextInt ( ) ; String [ ] HS = new String [ H ] ; boolean [ ] rows = new boolean [ H ] ; boolean [ ] cols = new boolean [ W ] ; Arrays . fill ( rows , false ) ; Arrays . fill ( cols , false ) ; for ( int i = 0 ; i < H ; i ++ ) { HS [ i ] = input . next ( ) ; } for ( int j = 0 ; j < H ; j ++ ) { if ( HS [ j ] . indexOf ( " # " ) != - 1 ) { rows [ j ] = true ; } for ( int i = 0 ; i < W ; i ++ ) { if ( HS [ j ] . charAt ( i ) == ' # ' ) { cols [ i ] = true ; } } } for ( int i = 0 ; i < H ; i ++ ) { if ( rows [ i ] ) { for ( int j = 0 ; j < W ; j ++ ) { if ( cols [ j ] ) { System . out . print ( HS [ i ] . charAt ( j ) ) ; } } System . out . println ( ) ; } } } }


import java . util . List ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; import java . util . stream . Stream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int h = scanner . nextInt ( ) ; int w = scanner . nextInt ( ) ; String [ ] a = Stream . generate ( ( ) -> null ) . limit ( h ) . map ( b -> scanner . next ( ) ) . filter ( b -> b . contains ( " # " ) ) . toArray ( String [ ] :: new ) ; List < Integer > i = IntStream . range ( 0 , w ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; for ( String s : a ) i . removeIf ( i2 -> s . charAt ( i2 ) == ' # ' ) ; for ( String s : a ) { char [ ] c = s . toCharArray ( ) ; for ( int j = 0 ; j < c . length ; j ++ ) if ( ! i . contains ( j ) ) System . out . print ( c [ j ] ) ; System . out . println ( ) ; } } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; String name = sc . next ( ) ; String kit = sc . next ( ) ; char n [ ] = new char [ 26 ] ; char m [ ] = new char [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { char nc = name . charAt ( i ) ; n [ nc - ' A ' ] ++ ; } for ( int i = 0 ; i < M ; i ++ ) { char nk = kit . charAt ( i ) ; m [ nk - ' A ' ] ++ ; } int an = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { char target = name . charAt ( i ) ; int count = 0 ; if ( m [ target - ' A ' ] == 0 ) { System . out . println ( - 1 ) ; return ; } if ( n [ target - ' A ' ] % m [ target - ' A ' ] == 0 ) { count = n [ target - ' A ' ] / m [ target - ' A ' ] ; } else { count = n [ target - ' A ' ] / m [ target - ' A ' ] + 1 ; } an = Math . max ( an , count ) ; } System . out . println ( an ) ; } }

n , m = map ( int , input ( ) . split ( ) ) NEW_LINE N = list ( input ( ) ) NEW_LINE K = list ( input ( ) ) NEW_LINE dic_N = { } NEW_LINE for i in N : NEW_LINE INDENT if i not in dic_N : NEW_LINE INDENT dic_N [ i ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic_N [ i ] += 1 NEW_LINE DEDENT DEDENT dic_K = { } NEW_LINE for i in K : NEW_LINE INDENT if i not in dic_K : NEW_LINE INDENT dic_K [ i ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic_K [ i ] += 1 NEW_LINE DEDENT DEDENT cou = 0 NEW_LINE for i in dic_N : NEW_LINE INDENT ni = dic_N [ i ] NEW_LINE if i not in dic_K : NEW_LINE INDENT cou = - 1 NEW_LINE break NEW_LINE DEDENT ki = dic_K [ i ] NEW_LINE re = ni // ki NEW_LINE if ni % ki != 0 : NEW_LINE INDENT re += 1 NEW_LINE DEDENT cou = max ( cou , re ) NEW_LINE DEDENT print ( cou ) NEW_LINE


I = input ; I ( ) ; s , t = I ( ) , I ( ) ; print ( - ( len ( set ( s ) - set ( t ) ) > 0 ) or - min ( - s . count ( c ) // t . count ( c ) for c in s ) ) NEW_LINE


import sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE from collections import Counter NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE name = input ( ) . rstrip ( ) NEW_LINE kit = input ( ) . rstrip ( ) NEW_LINE name_cnt = Counter ( name ) NEW_LINE kit_cnt = Counter ( kit ) NEW_LINE for key , val in name_cnt . items ( ) : NEW_LINE INDENT if kit_cnt [ key ] == 0 : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for key , val in name_cnt . items ( ) : NEW_LINE INDENT d = kit_cnt [ key ] NEW_LINE ans = max ( ans , ( val + d - 1 ) // d ) NEW_LINE DEDENT print ( ans ) NEW_LINE


def b_uncle ( N , M , Name , Kit ) : NEW_LINE INDENT from collections import defaultdict NEW_LINE name_usechar = defaultdict ( int ) NEW_LINE for c in Name : NEW_LINE INDENT name_usechar [ c ] += 1 NEW_LINE DEDENT kit_chars = defaultdict ( int ) NEW_LINE for c in Kit : NEW_LINE INDENT kit_chars [ c ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for key in name_usechar . keys ( ) : NEW_LINE INDENT if kit_chars [ key ] == 0 : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT ans = max ( ans , ( name_usechar [ key ] + kit_chars [ key ] - 1 ) // kit_chars [ key ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE Name = input ( ) NEW_LINE Kit = input ( ) NEW_LINE print ( b_uncle ( N , M , Name , Kit ) ) NEW_LINE


N , M = map ( int , input ( ) . split ( ) ) NEW_LINE n = input ( ) NEW_LINE k = input ( ) NEW_LINE A = [ " A " , " B " , " C " , " D " , " E " , " F " , " G " , " H " , " I " , " J " , " K " , " L " , " M " , " N " , " O " , " P " , " Q " , " R " , " S " , " T " , " U " , " V " , " W " , " X " , " Y " , " Z " ] NEW_LINE a = [ 0 for i in range ( 26 ) ] NEW_LINE for i in range ( len ( n ) ) : NEW_LINE INDENT for j in range ( 26 ) : NEW_LINE INDENT if n [ i ] == A [ j ] : NEW_LINE INDENT a [ j ] += 1 NEW_LINE DEDENT DEDENT DEDENT b = [ 0 for i in range ( 26 ) ] NEW_LINE for l in range ( len ( k ) ) : NEW_LINE INDENT for m in range ( 26 ) : NEW_LINE INDENT if k [ l ] == A [ m ] : NEW_LINE INDENT b [ m ] += 1 NEW_LINE DEDENT DEDENT DEDENT for x in range ( 1 , 51 ) : NEW_LINE INDENT cnt = 0 NEW_LINE for y in range ( 26 ) : NEW_LINE INDENT if a [ y ] <= b [ y ] * x : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if cnt == 26 : NEW_LINE INDENT print ( x ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( - 1 ) NEW_LINE


import java . io . * ; import java . util . * ; import java . math . * ; public class Main { static boolean debug = false ; static boolean debug2 = false ; public static void main ( String [ ] args ) throws java . io . IOException { debug = 1 <= args . length ; debug2 = 2 <= args . length ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; in . readLine ( ) ; final String name = in . readLine ( ) ; final String kit = in . readLine ( ) ; int [ ] name_count = new int [ ' Z ' - ' A ' + 1 ] ; int [ ] kit_count = new int [ name_count . length ] ; for ( int i = 0 ; i < name . length ( ) ; ++ i ) { ++ name_count [ name . charAt ( i ) - ' A ' ] ; } for ( int i = 0 ; i < kit . length ( ) ; ++ i ) { ++ kit_count [ kit . charAt ( i ) - ' A ' ] ; } int ans = 0 ; for ( int i = 0 ; i < kit_count . length ; ++ i ) { if ( kit_count [ i ] == 0 ) { if ( 0 < name_count [ i ] ) { ans = - 1 ; break ; } } else { ans = Math . max ( ans , name_count [ i ] / kit_count [ i ] + ( 0 < name_count [ i ] % kit_count [ i ] ? 1 : 0 ) ) ; } } System . out . println ( ans ) ; } }


import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { static final Scanner s = new Scanner ( System . in ) ; static IntStream REPS ( int v ) { return IntStream . range ( 0 , v ) ; } static IntStream REPS ( int l , int r ) { return IntStream . rangeClosed ( l , r ) ; } static IntStream INS ( int n ) { return REPS ( n ) . map ( i -> getInt ( ) ) ; } static int getInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } public static void main ( String [ ] $ ) { int [ ] name = new int [ 26 ] , kit = new int [ 26 ] ; s . next ( ) ; s . next ( ) ; s . next ( ) . chars ( ) . forEach ( i -> ++ name [ i - ' A ' ] ) ; s . next ( ) . chars ( ) . forEach ( i -> ++ kit [ i - ' A ' ] ) ; if ( REPS ( 26 ) . anyMatch ( i -> name [ i ] > 0 && kit [ i ] == 0 ) ) { System . out . println ( - 1 ) ; return ; } System . out . println ( REPS ( 26 ) . map ( i -> name [ i ] == 0 ? 0 : ( name [ i ] + kit [ i ] - 1 ) / kit [ i ] ) . max ( ) . getAsInt ( ) ) ; } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] setting = br . readLine ( ) . split ( " ▁ " ) ; int nameNum = Integer . parseInt ( setting [ 0 ] ) ; int kitLetterNum = Integer . parseInt ( setting [ 1 ] ) ; String [ ] nameArray = br . readLine ( ) . split ( " " ) ; String [ ] kitArray = br . readLine ( ) . split ( " " ) ; int count = 1 ; int nullNum = 0 ; while ( true ) { for ( int i = 0 ; i < kitLetterNum ; i ++ ) { for ( int j = 0 ; j < nameNum ; j ++ ) { if ( nameArray [ j ] == null ) { } else if ( nameArray [ j ] . equals ( kitArray [ i ] ) ) { nameArray [ j ] = null ; nullNum ++ ; break ; } } } if ( nullNum == nameNum ) { break ; } else if ( count == 50000 ) { count = - 1 ; break ; } else { count ++ ; } } System . out . println ( count ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; String name = sc . next ( ) ; String kit = sc . next ( ) ; HashMap < String , Integer > namemap = new HashMap < String , Integer > ( ) ; HashMap < String , Integer > kitmap = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String s = String . valueOf ( name . charAt ( i ) ) ; if ( namemap . containsKey ( s ) ) { namemap . put ( s , namemap . get ( s ) + 1 ) ; } else { namemap . put ( s , 1 ) ; } } for ( int i = 0 ; i < M ; i ++ ) { String s = String . valueOf ( kit . charAt ( i ) ) ; if ( kitmap . containsKey ( s ) ) { kitmap . put ( s , kitmap . get ( s ) + 1 ) ; } else { kitmap . put ( s , 1 ) ; } } int ans = 0 ; for ( String s : namemap . keySet ( ) ) { int num1 = namemap . get ( s ) ; int num2 = 0 ; if ( kitmap . containsKey ( s ) ) num2 = kitmap . get ( s ) ; if ( num2 == 0 ) { ans = - 1 ; break ; } else { ans = Math . max ( ans , ( num1 + num2 - 1 ) / num2 ) ; } } System . out . println ( ans ) ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String a = scan . next ( ) ; System . out . println ( a + " s " ) ; } }

W = input ( ' ' ) NEW_LINE print ( W + ' s ' ) NEW_LINE


def start_process ( ) : NEW_LINE INDENT X , Y , Z , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE return NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT print ( input ( ) + ' s ' ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


def plural ( w : str ) -> str : NEW_LINE INDENT return w + ' s ' NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT w = input ( ) NEW_LINE ans = plural ( w ) NEW_LINE print ( ans ) NEW_LINE DEDENT


w = input ( ) NEW_LINE w = w + " s " NEW_LINE print ( w ) NEW_LINE


print ( input ( ) . strip ( ) + ' s ' ) NEW_LINE


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( in . next ( ) + " s " ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isPrintableChar ( int c ) { return c >= 33 && c <= 126 ; } public String next ( ) { StringBuilder sb = new StringBuilder ( ) ; int b = readByte ( ) ; while ( ! isPrintableChar ( b ) ) b = readByte ( ) ; while ( isPrintableChar ( b ) ) { sb . appendCodePoint ( b ) ; b = readByte ( ) ; } return sb . toString ( ) ; } } }


import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; String s = sc . next ( ) ; System . out . println ( s + " s " ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . ArrayDeque ; import java . util . Queue ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { out . println ( in . next ( ) + " s " ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }


import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { out . println ( sc . next ( ) + " s " ) ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long k = sc . nextLong ( ) ; int [ ] p = new int [ 44 ] ; long [ ] a1 = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { long a = sc . nextLong ( ) ; a1 [ i ] = a ; int count = 0 ; while ( a > 0 ) { if ( ( a & 1 ) == 1 ) { p [ count ] ++ ; } a >>= 1 ; count ++ ; } } long [ ] pow = new long [ 44 ] ; pow [ 0 ] = 1 ; for ( int i = 1 ; i < 44 ; i ++ ) { pow [ i ] = pow [ i - 1 ] * 2 ; } long ans = 0 ; for ( int i = 43 ; i >= 0 ; i -- ) { if ( p [ i ] * 2 <= n ) { if ( ans + pow [ i ] <= k ) { ans += pow [ i ] ; } } } long an = 0 ; for ( int i = 0 ; i < n ; i ++ ) { an += ans ^ a1 [ i ] ; } System . out . println ( an ) ; } }

n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE cnt = [ 0 ] * 50 NEW_LINE for i in a : NEW_LINE INDENT for j in range ( 50 ) : NEW_LINE INDENT if i & ( 1 << j ) == 0 : NEW_LINE INDENT cnt [ j ] += 1 << j NEW_LINE DEDENT else : NEW_LINE INDENT cnt [ j ] -= 1 << j NEW_LINE DEDENT DEDENT DEDENT gg = [ ] NEW_LINE for i in range ( 50 ) : NEW_LINE INDENT gg . append ( [ cnt [ i ] , i ] ) NEW_LINE DEDENT gg . sort ( reverse = True ) NEW_LINE ans = 0 NEW_LINE for i in gg : NEW_LINE INDENT if i [ 0 ] < 0 : NEW_LINE INDENT break NEW_LINE DEDENT if ( 1 << i [ 1 ] ) <= k : NEW_LINE INDENT k -= 1 << i [ 1 ] NEW_LINE ans += i [ 0 ] NEW_LINE DEDENT DEDENT print ( ans + sum ( a ) ) NEW_LINE


num_terms , max_value = map ( int , input ( ) . split ( ) ) NEW_LINE coef = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE res = 0 NEW_LINE for i in range ( 40 , - 1 , - 1 ) : NEW_LINE INDENT num_bits = 0 NEW_LINE for a in coef : NEW_LINE INDENT num_bits += ( ( a >> i ) & 1 ) NEW_LINE DEDENT cand = 2 ** i NEW_LINE if ( num_terms - num_bits ) > num_bits and cand <= max_value : NEW_LINE INDENT res += ( num_terms - num_bits ) * cand NEW_LINE max_value -= cand NEW_LINE DEDENT else : NEW_LINE INDENT res += num_bits * cand NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE


from functools import lru_cache NEW_LINE def get_bit ( n , d ) : NEW_LINE INDENT return ( n >> d ) & 1 NEW_LINE DEDENT @ lru_cache ( maxsize = None ) NEW_LINE def xor ( bit , digit ) : NEW_LINE INDENT assert bit in [ 0 , 1 ] NEW_LINE if bit == 0 : NEW_LINE INDENT return bit_counts [ digit ] << digit NEW_LINE DEDENT else : NEW_LINE INDENT return ( N - bit_counts [ digit ] ) << digit NEW_LINE DEDENT DEDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE DIGIT = 50 NEW_LINE bit_counts = [ sum ( [ get_bit ( a , d = d ) for a in A ] ) for d in range ( DIGIT ) ] NEW_LINE dp = [ [ - float ( ' inf ' ) for _ in range ( 2 ) ] for _ in range ( DIGIT + 1 ) ] NEW_LINE dp [ - 1 ] [ 0 ] = 0 NEW_LINE for d in reversed ( range ( DIGIT ) ) : NEW_LINE INDENT k = get_bit ( K , d = d ) NEW_LINE dp [ d ] [ 0 ] = max ( dp [ d ] [ 0 ] , dp [ d + 1 ] [ 0 ] + xor ( bit = k , digit = d ) ) NEW_LINE if k == 1 : NEW_LINE INDENT dp [ d ] [ 1 ] = max ( dp [ d ] [ 1 ] , dp [ d + 1 ] [ 0 ] + xor ( bit = 0 , digit = d ) ) NEW_LINE DEDENT dp [ d ] [ 1 ] = max ( dp [ d ] [ 1 ] , dp [ d + 1 ] [ 1 ] + xor ( bit = 0 , digit = d ) ) NEW_LINE dp [ d ] [ 1 ] = max ( dp [ d ] [ 1 ] , dp [ d + 1 ] [ 1 ] + xor ( bit = 1 , digit = d ) ) NEW_LINE DEDENT print ( max ( dp [ 0 ] ) ) NEW_LINE


def solve ( string ) : NEW_LINE INDENT n , k , * a = map ( int , string . split ( ) ) NEW_LINE if k == 0 : NEW_LINE INDENT x = 0 NEW_LINE DEDENT else : NEW_LINE INDENT l = len ( " { : b } " . format ( k ) ) NEW_LINE base = [ 2 ** ( l - i - 1 ) for i in range ( l ) ] NEW_LINE count = [ 0 ] * l NEW_LINE for _a in a : NEW_LINE INDENT tmp = " { : b } " . format ( _a ) NEW_LINE for i , _f in enumerate ( tmp [ : : - 1 ] ) : NEW_LINE INDENT if i >= l : NEW_LINE INDENT break NEW_LINE DEDENT if _f == "1" : NEW_LINE INDENT count [ l - i - 1 ] += 1 NEW_LINE DEDENT DEDENT DEDENT x = 0 NEW_LINE for _c , _b in zip ( count , base ) : NEW_LINE INDENT if _c < n / 2 and x + _b <= k : NEW_LINE INDENT x += _b NEW_LINE DEDENT DEDENT DEDENT return str ( sum ( [ x ^ _a for _a in a ] ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( solve ( ' \n ' . join ( [ input ( ) , input ( ) ] ) ) ) NEW_LINE DEDENT


import math NEW_LINE n , k = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE bit_num = math . floor ( math . log2 ( max ( max ( a ) , k ) ) ) + 1 NEW_LINE num_one = [ ] NEW_LINE for i in range ( bit_num ) : NEW_LINE INDENT num_one_tmp = 0 NEW_LINE for j in a : NEW_LINE INDENT num_one_tmp += ( j >> i ) & 1 NEW_LINE DEDENT num_one . append ( num_one_tmp ) NEW_LINE DEDENT if k == 0 : NEW_LINE INDENT bit_k = 1 NEW_LINE DEDENT else : NEW_LINE INDENT bit_k = math . floor ( math . log2 ( k ) ) + 1 NEW_LINE DEDENT constant_ans = 0 NEW_LINE for i in range ( bit_k , bit_num ) : NEW_LINE INDENT constant_ans += num_one [ i ] * 2 ** i NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( bit_k ) [ : : - 1 ] : NEW_LINE INDENT if 2 ** i > k : NEW_LINE INDENT constant_ans += num_one [ i ] * 2 ** i NEW_LINE DEDENT else : NEW_LINE INDENT variant_ans = num_one [ i ] * 2 ** i NEW_LINE for j in range ( i ) : NEW_LINE INDENT if num_one [ j ] >= ( n + 1 ) // 2 : NEW_LINE INDENT variant_ans += num_one [ j ] * 2 ** j NEW_LINE DEDENT else : NEW_LINE INDENT variant_ans += ( n - num_one [ j ] ) * 2 ** j NEW_LINE DEDENT DEDENT ans = max ( ans , constant_ans + variant_ans ) NEW_LINE constant_ans += ( n - num_one [ i ] ) * 2 ** i NEW_LINE k -= 2 ** i NEW_LINE DEDENT DEDENT ans = max ( ans , constant_ans ) NEW_LINE print ( ans ) NEW_LINE


import java . util . * ; import static java . lang . System . * ; public class Main { public static final int MAX_BIT = 39 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long K = sc . nextLong ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextLong ( ) ; } int [ ] oneBitNums = new int [ MAX_BIT + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j <= MAX_BIT ; j ++ ) { if ( ( A [ i ] >> j & 1 ) == 1 ) { oneBitNums [ j ] ++ ; } } } int [ ] xBits = new int [ MAX_BIT + 1 ] ; for ( int i = MAX_BIT ; i >= 0 ; i -- ) { if ( oneBitNums [ i ] <= N / 2 ) { xBits [ i ] = 1 ; } } long X = 0 ; for ( int i = MAX_BIT ; i >= 0 ; i -- ) { if ( xBits [ i ] == 1 ) { long num = ( long ) Math . pow ( 2.0 , i ) ; if ( X + num <= K ) { X += num ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += X ^ A [ i ] ; } out . println ( ans ) ; } }


import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { String [ ] nm = sc . nextLine ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( nm [ 0 ] ) ; long k = Long . parseLong ( nm [ 1 ] ) ; String [ ] alist = sc . nextLine ( ) . split ( " ▁ " ) ; long [ ] aary = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { aary [ i ] = Long . parseLong ( alist [ i ] ) ; } String [ ] bsary = new String [ n ] ; int maxbslen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bsary [ i ] = Long . toBinaryString ( aary [ i ] ) ; maxbslen = Math . max ( maxbslen , bsary [ i ] . length ( ) ) ; } long bitcount [ ] = new long [ maxbslen ] ; for ( String bs : bsary ) { for ( int j = bs . length ( ) - 1 ; j >= 0 ; j -- ) { if ( bs . charAt ( j ) == '1' ) { bitcount [ bs . length ( ) - 1 - j ] ++ ; } } } int xdigit = Long . toBinaryString ( k ) . length ( ) ; long x = 0 ; for ( int i = xdigit - 1 ; i >= 0 ; i -- ) { long next = x + ( long ) Math . pow ( 2 , i ) ; if ( next <= k ) { if ( i >= bitcount . length ) { x = next ; } else { if ( bitcount [ i ] <= n / 2 ) { x = next ; } } } } long f = 0 ; for ( long a : aary ) { f += x ^ a ; } System . out . println ( f ) ; } } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; long K = scanner . nextLong ( ) ; int [ ] digits = new int [ 41 ] ; int t = 0 ; while ( K > 0 ) { if ( K % 2 == 1 ) digits [ t ] = 1 ; K /= 2 ; t ++ ; } int [ ] numOnes = new int [ 41 ] ; for ( int i = 0 ; i < N ; i ++ ) { long a = scanner . nextLong ( ) ; int j = 0 ; while ( a > 0 ) { if ( a % 2 == 1 ) numOnes [ j ] ++ ; a /= 2 ; j ++ ; } } long [ ] [ ] dp = new long [ 42 ] [ 2 ] ; for ( int i = 40 ; i >= 0 ; i -- ) { long d = 1L << i ; int ones = numOnes [ i ] ; int zeros = N - ones ; if ( digits [ i ] == 0 ) { dp [ i ] [ 0 ] = dp [ i + 1 ] [ 0 ] + d * ones ; if ( dp [ i + 1 ] [ 1 ] > 0 ) dp [ i ] [ 1 ] = dp [ i + 1 ] [ 1 ] + d * Math . max ( ones , zeros ) ; } else { dp [ i ] [ 0 ] = dp [ i + 1 ] [ 0 ] + d * zeros ; dp [ i ] [ 1 ] = dp [ i + 1 ] [ 0 ] + d * ones ; if ( dp [ i + 1 ] [ 1 ] > 0 ) dp [ i ] [ 1 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i + 1 ] [ 1 ] + d * Math . max ( ones , zeros ) ) ; } } System . out . println ( Math . max ( dp [ 0 ] [ 0 ] , dp [ 0 ] [ 1 ] ) ) ; } }


import java . util . Scanner ; public class Main { static int MAX_DIGIT = 60 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long k = Long . parseLong ( sc . next ( ) ) ; long [ ] A = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = Long . parseLong ( sc . next ( ) ) ; } sc . close ( ) ; long res = 0 ; for ( int d = MAX_DIGIT ; d >= - 1 ; -- d ) { if ( d != - 1 && ! ( ( k & 1L << d ) != 0 ) ) continue ; long tmp = 0 ; for ( int e = MAX_DIGIT ; e >= 0 ; -- e ) { long mask = 1L << e ; int num = 0 ; for ( int i = 0 ; i < n ; ++ i ) if ( ( A [ i ] & mask ) != 0 ) ++ num ; if ( e > d ) { if ( ( k & mask ) != 0 ) tmp += mask * ( n - num ) ; else tmp += mask * num ; } else if ( e == d ) { tmp += mask * num ; } else { tmp += mask * Math . max ( num , n - num ) ; } } res = Math . max ( res , tmp ) ; } System . out . println ( res ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( " Hello ▁ World " ) ; } else { int A = sc . nextInt ( ) , B = sc . nextInt ( ) ; System . out . println ( A + B ) ; } sc . close ( ) ; } }

N = int ( input ( ) ) NEW_LINE if N == 1 : NEW_LINE INDENT print ( " Hello ▁ World " ) NEW_LINE DEDENT else : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE B = int ( input ( ) ) NEW_LINE print ( A + B ) NEW_LINE DEDENT


N = int ( input ( ) ) NEW_LINE if ( N == 2 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE B = int ( input ( ) ) NEW_LINE print ( int ( A + B ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Hello ▁ World " ) NEW_LINE DEDENT


N = int ( input ( ) ) NEW_LINE if N == 1 : NEW_LINE INDENT print ( ' Hello ▁ World ' ) NEW_LINE exit ( ) NEW_LINE DEDENT else : NEW_LINE INDENT l = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT l . append ( int ( input ( ) ) ) NEW_LINE DEDENT DEDENT print ( sum ( l ) ) NEW_LINE


if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE if n == 1 : NEW_LINE INDENT print ( " Hello ▁ World " ) NEW_LINE DEDENT if n == 2 : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE b = int ( input ( ) ) NEW_LINE print ( a + b ) NEW_LINE DEDENT DEDENT


a = int ( input ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT print ( " Hello ▁ World " ) NEW_LINE DEDENT elif a == 2 : NEW_LINE INDENT b = int ( input ( ) ) NEW_LINE c = int ( input ( ) ) NEW_LINE print ( b + c ) NEW_LINE DEDENT


import java . util . Optional ; import java . util . Scanner ; public class Main { private static final String HELLO_WORLD = " Hello ▁ World " ; public static String process ( TestCase testCase ) { final int N = testCase . N ; switch ( N ) { case 1 : return HELLO_WORLD ; case 2 : { final int A = unsafeGet ( testCase . A , " A " ) ; final int B = unsafeGet ( testCase . B , " B " ) ; return String . valueOf ( A + B ) ; } default : { throw unknownN ( N ) ; } } } private static int unsafeGet ( Optional < Integer > argument , String argumentName ) { return argument . orElseThrow ( ( ) -> new IllegalArgumentException ( " Missing ▁ Argument ▁ " + argumentName ) ) ; } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; switch ( N ) { case 1 : { sc . close ( ) ; return new TestCase ( N ) ; } case 2 : { int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; sc . close ( ) ; return new TestCase ( N , A , B ) ; } default : { throw unknownN ( N ) ; } } } private static IllegalArgumentException unknownN ( int N ) { return new IllegalArgumentException ( " Unknown ▁ N : ▁ " + N ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final int N ; final Optional < Integer > A ; final Optional < Integer > B ; public TestCase ( int N ) { this . N = N ; this . A = Optional . empty ( ) ; this . B = Optional . empty ( ) ; } public TestCase ( int N , int A , int B ) { this . N = N ; this . A = Optional . of ( A ) ; this . B = Optional . of ( B ) ; } } }


import java . io . InputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Main { InputStream in = System . in ; PrintStream out = System . out ; public void _main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; if ( n == 1 ) { out . println ( " Hello ▁ World " ) ; } else { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; out . println ( a + b ) ; } sc . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } }


import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( System . in ) ; int n ; n = Integer . parseInt ( sc . next ( ) ) ; if ( n == 1 ) { System . out . println ( " Hello ▁ World " ) ; } if ( n == 2 ) { int a , b ; a = Integer . parseInt ( sc . next ( ) ) ; b = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( a + b ) ; } } catch ( Exception e ) { System . out . println ( " out " ) ; } } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; int N = reader . nextInt ( ) ; String result = " " ; if ( N == 1 ) { result = " Hello ▁ World " ; } else { int A = reader . nextInt ( ) ; int B = reader . nextInt ( ) ; result = Integer . toString ( A + B ) ; } reader . close ( ) ; System . out . print ( result ) ; } }


import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n , m , p , q , r ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; p = sc . nextInt ( ) ; q = sc . nextInt ( ) ; r = sc . nextInt ( ) ; int [ ] [ ] mat = new int [ n ] [ m ] ; for ( int i = 0 ; i < r ; ++ i ) { int x , y , z ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; z = sc . nextInt ( ) ; -- x ; -- y ; mat [ x ] [ y ] = z ; } int ans = 0 ; for ( int s = 0 ; s < 1 << n ; ++ s ) { if ( Integer . bitCount ( s ) != p ) continue ; int [ ] a = new int [ m ] ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < n ; ++ j ) { if ( ( ( s >> j ) & 1 ) > 0 ) { a [ i ] += mat [ j ] [ i ] ; } } } Arrays . sort ( a ) ; int tmp = 0 ; for ( int i = 0 ; i < q ; ++ i ) { tmp += a [ a . length - 1 - i ] ; } ans = Math . max ( ans , tmp ) ; } System . out . println ( ans ) ; } static void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } }

import itertools NEW_LINE n , m , p , q , r = map ( int , input ( ) . split ( ) ) NEW_LINE x = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( r ) ] NEW_LINE c = list ( itertools . combinations ( range ( n ) , p ) ) NEW_LINE wata = [ [ 0 ] * m for i in range ( n ) ] NEW_LINE MAX = 0 NEW_LINE for i in x : NEW_LINE INDENT wata [ i [ 0 ] - 1 ] [ i [ 1 ] - 1 ] += i [ 2 ] NEW_LINE DEDENT for i in c : NEW_LINE INDENT mora = [ 0 ] * m NEW_LINE for j in i : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT mora [ k ] += wata [ j ] [ k ] NEW_LINE DEDENT DEDENT mora . sort ( ) NEW_LINE mora = mora [ : : - 1 ] NEW_LINE mora = mora [ : q ] NEW_LINE MAX = max ( MAX , sum ( mora ) ) NEW_LINE DEDENT print ( MAX ) NEW_LINE


N , M , P , Q , R = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE Z = [ [ ] for x in range ( N ) ] NEW_LINE for i in range ( R ) : NEW_LINE INDENT x , y , z = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE Z [ x - 1 ] . append ( ( y - 1 , z ) ) NEW_LINE DEDENT from itertools import combinations NEW_LINE ans = 0 NEW_LINE for C in combinations ( range ( N ) , P ) : NEW_LINE INDENT man = [ 0 ] * M NEW_LINE for c in C : NEW_LINE INDENT for z in Z [ c ] : NEW_LINE INDENT man [ z [ 0 ] ] += z [ 1 ] NEW_LINE DEDENT DEDENT man . sort ( reverse = True ) NEW_LINE ans = max ( ans , sum ( man [ : Q ] ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE


def d_valentine ( N , M , P , Q , R , C ) : NEW_LINE INDENT from itertools import combinations NEW_LINE choco = [ [ 0 ] * M for _ in range ( N ) ] NEW_LINE for row in C : NEW_LINE INDENT choco [ row [ 0 ] - 1 ] [ row [ 1 ] - 1 ] = row [ 2 ] NEW_LINE DEDENT ans = 0 NEW_LINE for girl in combinations ( range ( N ) , P ) : NEW_LINE INDENT target = [ 0 ] * M NEW_LINE for i in girl : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT target [ j ] += choco [ i ] [ j ] NEW_LINE DEDENT DEDENT ans = max ( ans , sum ( sorted ( target , reverse = True ) [ : Q ] ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT N , M , P , Q , R = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE C = [ [ int ( i ) for i in input ( ) . split ( ) ] for j in range ( R ) ] NEW_LINE print ( d_valentine ( N , M , P , Q , R , C ) ) NEW_LINE


from itertools import combinations NEW_LINE n , m , p , q , r = map ( int , input ( ) . split ( ) ) NEW_LINE combos = list ( combinations ( list ( range ( 0 , n ) ) , p ) ) NEW_LINE ans = 0 NEW_LINE info = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT info . append ( [ 0 ] * m ) NEW_LINE DEDENT for i in range ( r ) : NEW_LINE INDENT a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE info [ a - 1 ] [ b - 1 ] = c NEW_LINE DEDENT combos = list ( combinations ( list ( range ( 0 , n ) ) , p ) ) NEW_LINE for combo in combos : NEW_LINE INDENT temp = [ 0 ] * m NEW_LINE for i in range ( m ) : NEW_LINE INDENT for w in combo : NEW_LINE INDENT temp [ i ] += info [ w ] [ i ] NEW_LINE DEDENT DEDENT temp = sorted ( temp , reverse = True ) NEW_LINE ans = max ( ans , sum ( temp [ : q ] ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE


import itertools NEW_LINE import numpy as np NEW_LINE N , M , P , Q , R = map ( int , input ( ) . split ( ) ) NEW_LINE choco = np . zeros ( ( N , M ) ) NEW_LINE for i in range ( R ) : NEW_LINE INDENT x , y , z = map ( int , input ( ) . split ( ) ) NEW_LINE choco [ x - 1 ] [ y - 1 ] = z NEW_LINE DEDENT seq = [ i for i in range ( N ) ] NEW_LINE ans = 0 NEW_LINE for girls in itertools . combinations ( seq , P ) : NEW_LINE INDENT happiness = np . sum ( choco [ list ( girls ) ] , axis = 0 ) NEW_LINE happiness = sorted ( happiness , key = lambda x : - x ) NEW_LINE ans = max ( ans , sum ( happiness [ : Q ] ) ) NEW_LINE DEDENT print ( int ( ans ) ) NEW_LINE


import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; final int M = sc . nextInt ( ) ; final int P = sc . nextInt ( ) ; final int Q = sc . nextInt ( ) ; final int R = sc . nextInt ( ) ; int [ ] x = new int [ R ] ; int [ ] y = new int [ R ] ; int [ ] z = new int [ R ] ; for ( int i = 0 ; i < R ; i ++ ) { x [ i ] = sc . nextInt ( ) - 1 ; y [ i ] = sc . nextInt ( ) - 1 ; z [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int max = ( int ) Math . pow ( 2 , N ) ; int ans = 0 ; for ( int i = 1 ; i < ( int ) Math . pow ( 2 , N ) ; i ++ ) { String comb = Integer . toBinaryString ( i ) ; int count = 0 ; while ( comb . length ( ) < N ) comb = "0" + comb ; for ( int j = 0 ; j < N ; j ++ ) if ( comb . charAt ( j ) == '1' ) count ++ ; if ( count == P ) { int [ ] boy = new int [ M ] ; for ( int j = 0 ; j < R ; j ++ ) { if ( comb . charAt ( x [ j ] ) == '1' ) boy [ y [ j ] ] += z [ j ] ; } Arrays . sort ( boy ) ; int tmp = 0 ; for ( int j = M - 1 ; j >= M - Q ; j -- ) tmp += boy [ j ] ; ans = Math . max ( tmp , ans ) ; } } System . out . println ( ans ) ; } }


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int P = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; int [ ] [ ] z = new int [ n ] [ m ] ; for ( int i = 0 ; i < R ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; z [ x - 1 ] [ y - 1 ] = sc . nextInt ( ) ; } HashSet < Integer > boyCan = new HashSet < > ( ) ; calCan ( boyCan , m , Q ) ; int ans = 0 ; for ( Integer w : boyCan ) { int cur = w ; ArrayList < Integer > boys = new ArrayList < > ( ) ; for ( int i = 0 ; i < 19 ; i ++ ) { if ( ( cur & ( 1 << i ) ) > 0 ) boys . add ( i ) ; } int sum = 0 ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; for ( int girl = 0 ; girl < n ; girl ++ ) { int now = 0 ; for ( int boy : boys ) now += z [ girl ] [ boy ] ; pq . add ( now ) ; sum += now ; if ( pq . size ( ) > P ) sum -= pq . poll ( ) ; } ans = Math . max ( ans , sum ) ; } System . out . println ( ans ) ; } static void calCan ( HashSet < Integer > boyCan , int m , int Q ) { for ( int i = 1 ; i <= ( 1 << m ) - 1 ; i ++ ) { if ( numOfOne ( i ) == Q ) boyCan . add ( i ) ; } } static int numOfOne ( int s ) { int cnt = 0 ; while ( s > 0 ) { if ( s % 2 == 1 ) cnt ++ ; s = s / 2 ; } return cnt ; } }


import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , M = sc . nextInt ( ) , P = sc . nextInt ( ) , Q = sc . nextInt ( ) , R = sc . nextInt ( ) ; int choco [ ] [ ] = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { choco [ i ] [ j ] = 0 ; } } for ( int i = 0 ; i < R ; i ++ ) { int x = sc . nextInt ( ) - 1 , y = sc . nextInt ( ) - 1 , z = sc . nextInt ( ) ; choco [ x ] [ y ] = z ; } int ans = 0 ; int comb = ( 1 << P ) - 1 ; while ( comb < ( 1 << N ) ) { int men [ ] = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { men [ i ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( ( comb >> i & 1 ) == 1 ) { for ( int j = 0 ; j < M ; j ++ ) { men [ j ] += choco [ i ] [ j ] ; } } } Arrays . sort ( men ) ; int cand = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { cand += men [ M - i - 1 ] ; } ans = Math . max ( ans , cand ) ; int x = comb & - comb , y = comb + x ; comb = ( ( comb & ~ y ) / x >> 1 ) | y ; } System . out . println ( ans ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int m = s . nextInt ( ) ; int p = s . nextInt ( ) ; int q = s . nextInt ( ) ; int r = s . nextInt ( ) ; int [ ] [ ] score = new int [ n ] [ m ] ; for ( int i = 0 ; i < r ; i ++ ) { int x = s . nextInt ( ) - 1 ; int y = s . nextInt ( ) - 1 ; score [ x ] [ y ] = s . nextInt ( ) ; } int topScore = 0 ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { boolean [ ] xSelected = new boolean [ n ] ; int xSelectedCount = 0 ; for ( int j = 0 ; j < n ; j ++ ) { xSelected [ j ] = ( i & ( 1 << j ) ) != 0 ; if ( xSelected [ j ] ) { xSelectedCount ++ ; } } if ( xSelectedCount != p ) { continue ; } int [ ] yScore = new int [ m ] ; for ( int k = 0 ; k < m ; k ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( xSelected [ j ] ) { yScore [ k ] += score [ j ] [ k ] ; } } } Arrays . sort ( yScore ) ; int sumScore = 0 ; for ( int k = 0 ; k < q ; k ++ ) { sumScore += yScore [ m - 1 - k ] ; } topScore = Math . max ( topScore , sumScore ) ; } System . out . println ( topScore ) ; } }


import java . util . * ; public class Main { static final long MOD = 1000000007L ; static long [ ] [ ] dp ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; if ( n > k ) { dp = new long [ n + k ] [ k + 1 ] ; System . out . println ( combination ( n + k - 1 , k ) ) ; } else { dp = new long [ n + 1 ] [ k % n + 1 ] ; System . out . println ( combination ( n , k % n ) ) ; } } static long combination ( int left , int right ) { if ( right > left - right ) { return combination ( left , left - right ) ; } if ( right == 0 ) { return 1 ; } if ( right == 1 ) { return left ; } if ( dp [ left ] [ right ] != 0 ) { return dp [ left ] [ right ] ; } long val = combination ( left - 1 , right ) + combination ( left - 1 , right - 1 ) ; val %= MOD ; dp [ left ] [ right ] = val ; return val ; } }

import math NEW_LINE N , K = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE if K < N : NEW_LINE INDENT ans = math . factorial ( N + K - 1 ) // ( math . factorial ( N + K - 1 - K ) * math . factorial ( K ) ) % ( 10 ** 9 + 7 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = math . factorial ( N ) // ( math . factorial ( N - K % N ) * math . factorial ( K % N ) ) % ( 10 ** 9 + 7 ) NEW_LINE DEDENT print ( ans ) NEW_LINE


import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE class FactMod ( ) : NEW_LINE INDENT def __init__ ( self , n , mod ) : NEW_LINE INDENT self . mod = mod NEW_LINE self . f = [ 1 ] * ( n + 1 ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT self . f [ i ] = self . f [ i - 1 ] * i % mod NEW_LINE DEDENT self . inv = [ pow ( self . f [ - 1 ] , mod - 2 , mod ) ] NEW_LINE for i in range ( 1 , n + 1 ) [ : : - 1 ] : NEW_LINE INDENT self . inv . append ( self . inv [ - 1 ] * i % mod ) NEW_LINE DEDENT self . inv . reverse ( ) NEW_LINE DEDENT def fact ( self , n ) : NEW_LINE INDENT return self . f [ n ] NEW_LINE DEDENT def comb ( self , n , r ) : NEW_LINE INDENT ret = self . f [ n ] * self . inv [ n - r ] * self . inv [ r ] NEW_LINE ret %= self . mod NEW_LINE return ret NEW_LINE DEDENT DEDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE F = FactMod ( N + K , 10 ** 9 + 7 ) NEW_LINE if K >= N : NEW_LINE INDENT print ( F . comb ( N , K % N ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( F . comb ( N - 1 + K , K ) ) NEW_LINE DEDENT


MOD = 10 ** 9 + 7 NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE def nCk ( n , k ) : NEW_LINE INDENT res = 1 NEW_LINE k = min ( n , n - k ) NEW_LINE for i in range ( k ) : NEW_LINE INDENT res *= ( n - i ) NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT res //= ( k - i ) NEW_LINE DEDENT return res NEW_LINE DEDENT res = 0 NEW_LINE if N > K : NEW_LINE INDENT res = nCk ( N - 1 + K , K ) % MOD NEW_LINE DEDENT elif N == K : NEW_LINE INDENT res = 1 NEW_LINE DEDENT else : NEW_LINE INDENT K %= N NEW_LINE res = nCk ( N , K ) % MOD NEW_LINE DEDENT print ( res ) NEW_LINE


class Combination : NEW_LINE INDENT def __init__ ( self , n , mod ) : NEW_LINE INDENT self . fact = [ 1 ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT self . fact . append ( self . fact [ - 1 ] * i % mod ) NEW_LINE DEDENT self . inv_fact = [ pow ( self . fact [ i ] , mod - 2 , mod ) for i in range ( n + 1 ) ] NEW_LINE self . mod = mod NEW_LINE DEDENT def factorial ( self , i ) : NEW_LINE INDENT return self . fact [ i ] NEW_LINE DEDENT def inverse_factorial ( self , i ) : NEW_LINE INDENT return self . inv_fact [ i ] NEW_LINE DEDENT def combination ( self , i , j ) : NEW_LINE INDENT return ( self . fact [ i ] * self . inv_fact [ i - j ] * self . inv_fact [ j ] ) % self . mod NEW_LINE DEDENT DEDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE comb = Combination ( n + k , MOD ) NEW_LINE if k // n == 0 : NEW_LINE INDENT print ( comb . combination ( k + n - 1 , k ) ) NEW_LINE DEDENT else : NEW_LINE INDENT otoku_enji_num = n - k % n NEW_LINE son_enji_num = n - otoku_enji_num NEW_LINE print ( comb . combination ( n , otoku_enji_num ) ) NEW_LINE DEDENT


N , K = map ( int , input ( ) . split ( ) ) NEW_LINE MOD = int ( 1e9 + 7 ) NEW_LINE M = N + K + 10 NEW_LINE fac , finv , inv = [ 1 ] * M , [ 1 ] * M , [ 1 ] * M NEW_LINE def COMinit ( MAX ) : NEW_LINE INDENT fac [ 0 ] , fac [ 1 ] = 1 , 1 NEW_LINE finv [ 0 ] , finv [ 1 ] = 1 , 1 NEW_LINE inv [ 1 ] = 1 NEW_LINE for i in range ( 2 , MAX ) : NEW_LINE INDENT fac [ i ] = fac [ i - 1 ] * i % MOD NEW_LINE inv [ i ] = MOD - inv [ MOD % i ] * ( MOD // i ) % MOD NEW_LINE finv [ i ] = finv [ i - 1 ] * inv [ i ] % MOD NEW_LINE DEDENT DEDENT def COM ( n , k ) : NEW_LINE INDENT if n < k or n < 0 or k < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return fac [ n ] * ( finv [ k ] * finv [ n - k ] % MOD ) % MOD NEW_LINE DEDENT COMinit ( M ) NEW_LINE if N > K : NEW_LINE INDENT print ( COM ( N + K - 1 , N - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT a = K % N NEW_LINE print ( COM ( N , a ) ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sn = new Scanner ( System . in ) ; int N = sn . nextInt ( ) ; int K = sn . nextInt ( ) ; if ( N > K ) { System . out . println ( nCr ( N + K - 1 , K ) ) ; return ; } int c = K % N ; int r = N - c ; System . out . println ( nCr ( N , r ) ) ; } public static long nCr ( int n , int r ) { long M = 1000000007L ; long dp [ ] [ ] = new long [ 502 ] [ 502 ] ; for ( int i = 0 ; i < 502 ; ++ i ) { for ( int j = 0 ; j < 502 ; ++ j ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { dp [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j <= i + 1 ; ++ j ) { dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j ] ) % M ; } } return dp [ n ] [ r ] ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] candies = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { candies [ i ] [ j ] = sc . nextInt ( ) ; } } int max = maxCandies ( candies ) ; System . out . println ( max ) ; } private static int maxCandies ( int [ ] [ ] candies ) { int topSum = 0 ; int bottomDelta = 0 ; int i = 0 ; for ( ; i < candies [ 0 ] . length - 1 ; i ++ ) { bottomDelta += candies [ 1 ] [ i ] - candies [ 0 ] [ i + 1 ] ; if ( bottomDelta < 0 ) bottomDelta = 0 ; topSum += candies [ 0 ] [ i ] ; } topSum += candies [ 0 ] [ i ] + candies [ 1 ] [ i ] ; return topSum + bottomDelta ; } }

N = int ( input ( ) ) NEW_LINE A1 = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) NEW_LINE A2 = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) NEW_LINE now_gain = sum ( A2 ) + A1 [ 0 ] NEW_LINE max_gain = now_gain NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT now_gain = now_gain - A2 [ i - 1 ] + A1 [ i ] NEW_LINE max_gain = max ( max_gain , now_gain ) NEW_LINE DEDENT print ( max_gain ) NEW_LINE


import numpy as np NEW_LINE def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE A1 = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE A2 = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE ans = A1 [ 0 ] + A2 [ - 1 ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT ans = max ( ans , A1 [ i ] + A2 [ - 1 ] - A2 [ i - 1 ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE


n = int ( input ( ) ) NEW_LINE a = [ None ] * 2 NEW_LINE a [ 0 ] = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a [ 1 ] = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dp = [ [ 0 ] * n for i in range ( 2 ) ] NEW_LINE dp [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT dp [ 1 ] [ i ] = dp [ 0 ] [ i ] + a [ 1 ] [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] NEW_LINE dp [ 1 ] [ i ] = max ( dp [ 0 ] [ i ] , dp [ 1 ] [ i - 1 ] ) + a [ 1 ] [ i ] NEW_LINE DEDENT DEDENT print ( dp [ 1 ] [ n - 1 ] ) NEW_LINE


n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( max ( sum ( a [ : i + 1 ] + a [ n + i : ] ) for i in range ( n ) ) ) NEW_LINE


N = int ( input ( ) ) NEW_LINE A = list ( ) NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT A . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE DEDENT dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( 2 ) ] NEW_LINE dp [ 0 ] [ 0 ] = A [ 0 ] [ 0 ] NEW_LINE dp [ 1 ] [ 0 ] = A [ 0 ] [ 0 ] + A [ 1 ] [ 0 ] NEW_LINE for j in range ( N - 1 ) : NEW_LINE INDENT dp [ 0 ] [ j + 1 ] = dp [ 0 ] [ j ] + A [ 0 ] [ j + 1 ] NEW_LINE DEDENT for j in range ( N - 1 ) : NEW_LINE INDENT dp [ 1 ] [ j + 1 ] = max ( dp [ 0 ] [ j + 1 ] + A [ 1 ] [ j + 1 ] , dp [ 1 ] [ j ] + A [ 1 ] [ j + 1 ] ) NEW_LINE DEDENT print ( dp [ 1 ] [ N - 1 ] ) NEW_LINE


import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . function . Consumer ; import java . util . stream . IntStream ; import static java . util . stream . Collectors . toList ; public class Main { private static final Scanner scanner = new Scanner ( System . in ) ; private static final Consumer < List < String > > consumer = solve ( ) ; public static void main ( String [ ] args ) { consumer . accept ( readInput ( ) ) ; } private static List < String > readInput ( ) { final List < String > lineList = new ArrayList < > ( ) ; while ( scanner . hasNextLine ( ) ) { lineList . add ( scanner . nextLine ( ) ) ; } return lineList ; } private static Consumer < List < String > > solve ( ) { return args -> { final List < Integer > firstRow = Arrays . stream ( args . get ( 1 ) . split ( " ▁ " ) ) . map ( Integer :: valueOf ) . collect ( toList ( ) ) ; final List < Integer > secondRow = Arrays . stream ( args . get ( 2 ) . split ( " ▁ " ) ) . map ( Integer :: valueOf ) . collect ( toList ( ) ) ; final Integer ans = IntStream . range ( 0 , firstRow . size ( ) ) . map ( index -> firstRow . subList ( 0 , index + 1 ) . stream ( ) . mapToInt ( Integer :: intValue ) . sum ( ) + secondRow . subList ( index , secondRow . size ( ) ) . stream ( ) . mapToInt ( Integer :: intValue ) . sum ( ) ) . max ( ) . orElse ( - 1 ) ; System . out . println ( ans ) ; } ; } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . parseInt ( reader . readLine ( ) ) ; int [ ] [ ] grid = new int [ 2 ] [ N ] ; for ( int i = 0 ; i < 2 ; i ++ ) { String [ ] temp = reader . readLine ( ) . split ( " [ ▁ ] " ) ; for ( int j = 0 ; j < N ; j ++ ) { grid [ i ] [ j ] = Integer . parseInt ( temp [ j ] ) ; } } System . out . println ( solution ( grid , N ) ) ; } public static int solution ( int [ ] [ ] grid , int N ) { for ( int i = 1 ; i >= 0 ; i -- ) { for ( int j = N - 1 ; j >= 0 ; j -- ) { int current = 0 ; if ( j + 1 < N ) { current = Math . max ( current , grid [ i ] [ j + 1 ] ) ; } if ( i + 1 < 2 ) { current = Math . max ( current , grid [ i + 1 ] [ j ] ) ; } grid [ i ] [ j ] += current ; } } return grid [ 0 ] [ 0 ] ; } }


import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int candies_a = 0 ; int candies_b = 0 ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; a [ 0 ] = sc . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int tmp = sc . nextInt ( ) ; a [ i ] = a [ i - 1 ] + tmp ; } b [ 0 ] = sc . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int tmp = sc . nextInt ( ) ; b [ i ] = b [ i - 1 ] + tmp ; } int candies = a [ 0 ] + b [ n - 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { int tmp = a [ i ] + ( b [ n - 1 ] - b [ i - 1 ] ) ; if ( tmp > candies ) { candies = tmp ; } } System . out . print ( candies ) ; } }


import java . util . Scanner ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int map [ ] [ ] = new int [ 2 ] [ n ] ; int sum [ ] [ ] = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { map [ i ] [ j ] = sc . nextInt ( ) ; } } sum [ 0 ] [ 0 ] = map [ 0 ] [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { sum [ 0 ] [ j ] = sum [ 0 ] [ j - 1 ] + map [ 0 ] [ j ] ; } sum [ 1 ] [ 0 ] = sum [ 0 ] [ 0 ] + map [ 1 ] [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { sum [ 1 ] [ j ] = Math . max ( sum [ 0 ] [ j ] , sum [ 1 ] [ j - 1 ] ) + map [ 1 ] [ j ] ; } System . out . println ( sum [ 1 ] [ n - 1 ] ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = b % a ; if ( c == 0 ) System . out . println ( a + b ) ; else System . out . println ( b - a ) ; } }

a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if ( b % a ) == 0 : NEW_LINE INDENT print ( a + b ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b - a ) NEW_LINE DEDENT


A , B = map ( int , input ( ) . split ( ) ) NEW_LINE print ( [ A + B , B - A ] [ not ( B % A == 0 ) ] ) NEW_LINE


a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if b % a : NEW_LINE INDENT print ( b - a ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a + b ) NEW_LINE DEDENT


a , b = map ( int , input ( ) . split ( ) ) NEW_LINE print ( a + b if b % a == 0 else b - a ) NEW_LINE


i = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE if ( i [ 1 ] % i [ 0 ] ) == 0 : NEW_LINE INDENT print ( i [ 0 ] + i [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( i [ 1 ] - i [ 0 ] ) NEW_LINE DEDENT


import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int a = Integer . parseInt ( scan . next ( ) ) ; int b = Integer . parseInt ( scan . next ( ) ) ; int count = 0 ; if ( b % a == 0 ) { count = a + b ; } else { count = b - a ; } PrintWriter out = new PrintWriter ( System . out ) ; out . println ( count ) ; out . flush ( ) ; scan . close ( ) ; } }


import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . Date ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( B % A == 0 ) { System . out . println ( A + B ) ; } else { System . out . println ( B - A ) ; } } }


import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { final int A = s . nextInt ( ) ; final int B = s . nextInt ( ) ; System . out . println ( B % A == 0 ? A + B : B - A ) ; } }


import java . util . * ; import java . util . List ; import java . util . ArrayList ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; if ( B % A == 0 ) { System . out . println ( A + B ) ; } else { System . out . println ( B - A ) ; } } }


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; System . out . println ( " ABC " + sc . nextInt ( ) ) ; } }

N = input ( ) NEW_LINE print ( ' ABC ' + N ) NEW_LINE


print ( ' ABC { } ' . format ( input ( ) ) ) NEW_LINE


n = input ( ) NEW_LINE print ( " ABC " + str ( n ) ) NEW_LINE


a = input ( ) NEW_LINE print ( " ABC " + a ) NEW_LINE


N = input ( ) NEW_LINE print ( " ABC " + N ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; Scanner sc = new Scanner ( System . in ) ; main . solve ( sc ) ; sc . close ( ) ; } void solve ( Scanner sc ) { int N = sc . nextInt ( ) ; System . out . println ( " ABC " + N ) ; } }


import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; String S = sc . next ( ) ; out . println ( " ABC " + S ) ; out . flush ( ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; System . out . println ( " ABC " + N ) ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner inScanner = new Scanner ( System . in ) ; System . out . println ( " ABC " + inScanner . nextInt ( ) ) ; } }


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

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


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

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


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

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 . * ; 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 .


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

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


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