import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; int N = sc . nextInt ( ) ; double [ ] x = new double [ N ] ; double sum = 0 ; String [ ] u = new String [ N ] ; for ( int i = 0 ; i < u . length ; i ++ ) { x [ i ] = sc . nextDouble ( ) ; u [ i ] = sc . next ( ) ; } for ( int i = 0 ; i < u . length ; i ++ ) { if ( u [ i ] . equals ( " JPY " ) ) { sum += x [ i ] ; } else { sum += x [ i ] * 380000.0 ; } } PrintWriter out = new PrintWriter ( System . out ) ; out . print ( sum ) ; out . flush ( ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { 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 sys NEW_LINE n = int ( input ( ) ) NEW_LINE money = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT y = sys . stdin . readline ( ) . rstrip ( ' \n ' ) NEW_LINE a , b = y . split ( ' ▁ ' ) NEW_LINE x = float ( a ) NEW_LINE if b == ' JPY ' : NEW_LINE INDENT money = money + x NEW_LINE DEDENT else : NEW_LINE INDENT money = money + x * 380000.0 NEW_LINE DEDENT DEDENT print ( money ) NEW_LINE


N = int ( input ( ) ) NEW_LINE rate = 380000.0 NEW_LINE ans = 0.0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT x , u = input ( ) . split ( ) NEW_LINE x = float ( x ) NEW_LINE ans += x * rate if u == ' BTC ' else x NEW_LINE DEDENT print ( ' { : . 11f } ' . format ( ans ) ) NEW_LINE


n = int ( input ( ) ) NEW_LINE x = [ ] NEW_LINE u = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT xu = list ( map ( str , input ( ) . split ( ) ) ) NEW_LINE x . append ( float ( xu [ 0 ] ) ) NEW_LINE mon = xu [ 1 ] NEW_LINE if mon == " JPY " : NEW_LINE INDENT u . append ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT u . append ( 380000 ) NEW_LINE DEDENT DEDENT s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT s = s + x [ i ] * u [ i ] NEW_LINE DEDENT print ( s ) NEW_LINE


n = int ( input ( ) ) NEW_LINE xu = [ input ( ) . split ( ) for i in range ( n ) ] NEW_LINE for i in xu : NEW_LINE INDENT i [ 0 ] = float ( i [ 0 ] ) NEW_LINE DEDENT for i in xu : NEW_LINE INDENT if i [ 1 ] == ' BTC ' : NEW_LINE INDENT i [ 0 ] *= 380000 NEW_LINE DEDENT DEDENT print ( sum ( xu [ i ] [ 0 ] for i in range ( n ) ) ) NEW_LINE


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 c = Integer . parseInt ( scan . next ( ) ) ; scan . nextLine ( ) ; double yourfortune = 0 ; double btcprice = 380000.0 ; for ( int i = 0 ; i < c ; i ++ ) { double a = 0 ; a = Double . parseDouble ( scan . next ( ) ) ; String b = null ; if ( scan . hasNext ( ) ) { b = scan . next ( ) ; } else { b = " " ; } if ( b . equals ( " JPY " ) ) { yourfortune += a ; } else { yourfortune += ( a * btcprice ) ; } } String ans = null ; PrintWriter out = new PrintWriter ( System . out ) ; out . println ( yourfortune ) ; out . flush ( ) ; scan . close ( ) ; } }

N = int ( input ( ) ) NEW_LINE A = [ list ( map ( str , input ( ) . split ( ) ) ) for _ in range ( N ) ] NEW_LINE ans = 0 NEW_LINE for value , unit in A : NEW_LINE INDENT if unit == " BTC " : NEW_LINE INDENT ans += float ( value ) * 380000 NEW_LINE DEDENT else : NEW_LINE INDENT ans += float ( value ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; 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 ) ; TaskAtCoder19B solver = new TaskAtCoder19B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskAtCoder19B { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int N = in . nextInt ( ) ; double res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { double tmp = Double . parseDouble ( in . next ( ) ) ; if ( in . next ( ) . equals ( " BTC " ) ) tmp *= 380000.0 ; res += tmp ; } out . println ( res ) ; } } }


import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; long limit = sc . nextLong ( ) ; long a [ ] = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } boolean ok = false ; int ans [ ] = new int [ n - 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] + a [ i + 1 ] >= limit ) { ans [ i ] = n - 1 ; ok = true ; break ; } } if ( ! ok ) { System . out . println ( " Impossible " ) ; return ; } int p = 1 ; for ( int i = 0 ; ans [ i ] == 0 ; i ++ ) { ans [ i ] = p ++ ; } for ( int i = n - 2 ; ans [ i ] == 0 ; i -- ) { ans [ i ] = p ++ ; } System . out . println ( " Possible " ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { System . out . println ( ans [ i ] ) ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

N , L = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE I = [ i + 1 for i in range ( N - 1 ) if a [ i ] + a [ i + 1 ] >= L ] NEW_LINE ans = ( ' Possible \n { } ' . format ( ' \n ' . join ( map ( str , list ( range ( 1 , I [ 0 ] ) ) + list ( range ( N - 1 , I [ 0 ] , - 1 ) ) + [ I [ 0 ] ] ) ) ) if I else ) print ( ans ) NEW_LINE


import sys NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n , l = LI ( ) NEW_LINE A = LI ( ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if A [ i ] + A [ i + 1 ] >= l : NEW_LINE INDENT k = i NEW_LINE print ( ' Possible ' ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' Impossible ' ) NEW_LINE return 0 NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT print ( i + 1 ) NEW_LINE DEDENT for i in range ( k , n - 1 ) [ : : - 1 ] : NEW_LINE INDENT print ( i + 1 ) NEW_LINE DEDENT return 1 NEW_LINE DEDENT main ( ) NEW_LINE


n , l = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE max_len = a [ 0 ] + a [ 1 ] NEW_LINE max_joint = 1 NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT len = a [ i ] + a [ i + 1 ] NEW_LINE if len > max_len : NEW_LINE INDENT max_len = len NEW_LINE max_joint = i + 1 NEW_LINE DEDENT DEDENT if max_len < l : NEW_LINE INDENT print ( " Impossible " ) NEW_LINE exit ( ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Possible " ) NEW_LINE for i in range ( 1 , max_joint ) : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT for i in range ( n - 1 , max_joint , - 1 ) : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT print ( max_joint ) NEW_LINE DEDENT


import sys NEW_LINE input = sys . stdin . readline NEW_LINE inf = float ( " inf " ) NEW_LINE n , L = map ( int , input ( ) . split ( ) ) NEW_LINE a = tuple ( map ( int , input ( ) . split ( ) ) ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if a [ i ] + a [ i - 1 ] >= L : NEW_LINE INDENT print ( ' Possible ' ) NEW_LINE for j in range ( 1 , i ) : NEW_LINE INDENT print ( j ) NEW_LINE DEDENT for j in range ( n - 1 , i , - 1 ) : NEW_LINE INDENT print ( j ) NEW_LINE DEDENT print ( i ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( ' Impossible ' ) NEW_LINE


N , L = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE P = " Possible " NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT if a [ i ] + a [ i + 1 ] >= L : NEW_LINE INDENT start = i NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT P = " Impossible " NEW_LINE DEDENT print ( P ) NEW_LINE if P == " Possible " : NEW_LINE INDENT ans = [ start ] NEW_LINE if start > 0 : NEW_LINE INDENT ans += reversed ( list ( range ( start ) ) ) NEW_LINE DEDENT if start != N - 2 : NEW_LINE INDENT ans += list ( range ( start + 1 , N - 1 ) ) NEW_LINE DEDENT ans . reverse ( ) NEW_LINE for a in ans : NEW_LINE INDENT print ( a + 1 ) NEW_LINE DEDENT DEDENT


import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { InputReader cin = new InputReader ( System . in ) ; PrintWriter cout = new PrintWriter ( System . out ) ; Task task = new Task ( ) ; task . run ( cin , cout ) ; cout . close ( ) ; } } class Task { void run ( InputReader cin , PrintWriter cout ) { int n = cin . nextInt ( ) ; int l = cin . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = cin . nextInt ( ) ; } int p = 0 ; for ( int i = 1 ; i < n ; ++ i ) { if ( a [ i - 1 ] + a [ i ] >= l ) { p = i ; break ; } } if ( p == 0 ) { cout . printf ( " Impossible \n " ) ; } else { cout . printf ( " Possible \n " ) ; for ( int i = 1 ; i < p ; ++ i ) { cout . println ( i ) ; } for ( int i = n - 1 ; i >= p + 1 ; -- i ) { cout . println ( i ) ; } cout . println ( p ) ; } } } class InputReader { private BufferedReader reader ; private StringTokenizer tokenizer ; private int BUFFER_SIZE = 32768 ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , BUFFER_SIZE ) ; tokenizer = null ; } public boolean hasNext ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { String line ; try { line = reader . readLine ( ) ; if ( line == null ) { return false ; } tokenizer = new StringTokenizer ( line ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return true ; } public String next ( ) { if ( ! hasNext ( ) ) { return null ; } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( this . next ( ) ) ; } }


import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( is ) ; String input [ ] = br . readLine ( ) . split ( " ▁ " ) ; int count = Integer . parseInt ( input [ 0 ] ) ; int maxLength = Integer . parseInt ( input [ 1 ] ) ; String input2 [ ] = br . readLine ( ) . split ( " ▁ " ) ; ArrayList < Integer > result = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < count ; i ++ ) { if ( i + 1 >= count ) { break ; } int num = Integer . parseInt ( input2 [ i ] ) ; int num2 = Integer . parseInt ( input2 [ i + 1 ] ) ; if ( num + num2 >= maxLength ) { for ( int j = 0 ; j < i ; j ++ ) { result . add ( j + 1 ) ; } for ( int n = count - 1 ; n > i + 1 ; n -- ) { result . add ( n ) ; } result . add ( i + 1 ) ; System . out . println ( " Possible " ) ; for ( int re : result ) { System . out . println ( re ) ; } return ; } } System . out . println ( " Impossible " ) ; } }


import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] array ; array = br . readLine ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( array [ 0 ] ) ; int l = Integer . parseInt ( array [ 1 ] ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( String str : br . readLine ( ) . split ( " ▁ " ) ) { list . add ( Integer . parseInt ( str ) ) ; } int index = - 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( list . get ( i ) + list . get ( i + 1 ) >= l ) { index = i ; break ; } } if ( index < 0 ) { System . out . println ( " Impossible " ) ; } else { System . out . println ( " Possible " ) ; for ( int i = 0 ; i < index ; i ++ ) { System . out . println ( i + 1 ) ; } for ( int i = n - 1 ; index < i ; i -- ) { System . out . println ( i ) ; } } } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int b = last ( a , l ) ; if ( b == - 1 ) { System . out . println ( " Impossible " ) ; } else { System . out . println ( " Possible " ) ; for ( int i = 0 ; i < b ; i ++ ) { System . out . println ( i + 1 ) ; } for ( int i = n - 2 ; i > b ; i -- ) { System . out . println ( i + 1 ) ; } System . out . println ( b + 1 ) ; } } static int last ( int [ ] a , int l ) { for ( int i = 0 ; i < a . length - 1 ; i ++ ) { if ( a [ i ] + a [ i + 1 ] >= l ) { return i ; } } return - 1 ; } }


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

import sys NEW_LINE fin = sys . stdin . readline NEW_LINE N , Z , W = [ int ( elem ) for elem in fin ( ) . split ( ) ] NEW_LINE a_list = [ int ( elem ) for elem in fin ( ) . split ( ) ] NEW_LINE assert len ( a_list ) == N NEW_LINE if N == 1 : NEW_LINE INDENT print ( abs ( a_list [ - 1 ] - W ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( max ( abs ( a_list [ - 1 ] - W ) , abs ( a_list [ - 2 ] - a_list [ - 1 ] ) ) ) NEW_LINE DEDENT


ai = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE n , z , w = ai ( ) NEW_LINE a = ai ( ) NEW_LINE if n == 1 : NEW_LINE INDENT print ( abs ( a [ - 1 ] - w ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( max ( abs ( a [ - 1 ] - w ) , abs ( a [ - 1 ] - a [ - 2 ] ) ) ) NEW_LINE DEDENT


def main ( ) : NEW_LINE INDENT n , z , w = input ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE w = int ( w ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = [ w ] + a NEW_LINE sx = s_min = s_max = abs ( a [ n ] - a [ n - 1 ] ) NEW_LINE for i in range ( n - 1 , 0 , - 1 ) : NEW_LINE INDENT sx = max ( s_max , abs ( a [ n ] - a [ i - 1 ] ) ) NEW_LINE sy = min ( s_min , abs ( a [ n ] - a [ i - 1 ] ) ) NEW_LINE s_max = max ( s_max , sy ) NEW_LINE s_min = min ( s_min , sx ) NEW_LINE DEDENT print ( sx ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


N , Z , W = map ( int , input ( ) . split ( ) ) NEW_LINE A = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE if N == 1 : print ( abs ( A [ 0 ] - W ) ) NEW_LINE else : print ( max ( abs ( A [ - 2 ] - A [ - 1 ] ) , abs ( A [ - 1 ] - W ) ) ) NEW_LINE


n , z , w = map ( int , input ( ) . split ( ) ) NEW_LINE a = tuple ( map ( int , input ( ) . split ( ) ) ) NEW_LINE res = abs ( a [ - 1 ] - w ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT cand = abs ( a [ - 1 ] - a [ i ] ) NEW_LINE for j in range ( i + 1 , n - 1 ) : NEW_LINE INDENT cand = min ( a [ j ] - a [ - 1 ] , cand ) NEW_LINE DEDENT res = max ( res , cand ) NEW_LINE DEDENT print ( res ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] tmpArray = br . readLine ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( tmpArray [ 0 ] ) ; int z = Integer . parseInt ( tmpArray [ 1 ] ) ; int w = Integer . parseInt ( tmpArray [ 2 ] ) ; int [ ] input = new int [ n ] ; tmpArray = br . readLine ( ) . split ( " ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { input [ i ] = Integer . parseInt ( tmpArray [ i ] ) ; } int score = 0 ; if ( n == 1 ) { score = Math . abs ( w - input [ n - 1 ] ) ; } else { score = Math . max ( Math . abs ( input [ n - 2 ] - input [ n - 1 ] ) , Math . abs ( w - input [ n - 1 ] ) ) ; } System . out . println ( score ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) , y = sc . nextLong ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextLong ( ) ; System . out . println ( max ( a , 0 , y ) ) ; } static HashMap < Long , Long > minmap = new HashMap < > ( ) ; static long min ( long [ ] a , int teban , long taro ) { long res = Math . abs ( a [ a . length - 1 ] - taro ) ; long key = taro * 10000 + teban ; if ( minmap . containsKey ( key ) ) return minmap . get ( key ) ; for ( int i = teban ; i < a . length - 1 ; i ++ ) { res = Math . min ( res , max ( a , i + 1 , a [ i ] ) ) ; } minmap . put ( key , res ) ; return res ; } static HashMap < Long , Long > maxmap = new HashMap < > ( ) ; static long max ( long [ ] a , int teban , long ziro ) { long res = Math . abs ( a [ a . length - 1 ] - ziro ) ; long key = ziro * 10000 + teban ; if ( maxmap . containsKey ( key ) ) return maxmap . get ( key ) ; for ( int i = teban ; i < a . length - 1 ; i ++ ) { res = Math . max ( res , min ( a , i + 1 , a [ i ] ) ) ; } maxmap . put ( key , res ) ; return res ; } }


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


import java . util . Arrays ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int z = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = sc . nextInt ( ) ; } if ( n >= 2 ) { System . out . println ( Math . max ( Math . abs ( w - a [ n - 1 ] ) , Math . abs ( a [ n - 1 ] - a [ n - 2 ] ) ) ) ; } else if ( n == 1 ) { System . out . println ( Math . abs ( w - a [ 0 ] ) ) ; } } void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i <= Math . min ( s , k ) ; i ++ ) { ans += Math . max ( 0 , Math . min ( s - i + 1 , k + 1 ) - Math . max ( 0 , s - i - k ) ) ; } System . out . println ( ans ) ; } }

k , s = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE for x in range ( k + 1 ) : NEW_LINE INDENT for y in range ( k + 1 ) : NEW_LINE INDENT if s - x - y >= 0 and s - x - y <= k : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE


import itertools NEW_LINE K , S = map ( int , input ( ) . split ( ) ) NEW_LINE count = 0 NEW_LINE for x , y in itertools . product ( range ( 0 , K + 1 ) , range ( 0 , K + 1 ) ) : NEW_LINE INDENT z = S - x - y NEW_LINE if 0 <= z <= K : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE


A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE K = A [ 0 ] NEW_LINE S = A [ 1 ] NEW_LINE count = 0 NEW_LINE for a in range ( K + 1 ) : NEW_LINE INDENT for b in range ( K + 1 ) : NEW_LINE INDENT c = S - a - b NEW_LINE if 0 <= c <= K : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT DEDENT print ( count ) NEW_LINE


k , s = map ( int , input ( ) . split ( ) ) NEW_LINE print ( len ( [ 1 for z in range ( k + 1 ) for y in range ( k + 1 ) if 0 <= s - y - z <= k ] ) ) NEW_LINE


K , S = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE for x in range ( 0 , K + 1 ) : NEW_LINE INDENT for y in range ( 0 , K + 1 ) : NEW_LINE INDENT if 0 <= S - ( x + y ) <= K : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastScanner fc = new FastScanner ( System . in ) ; int K = fc . nextInt ( ) ; int S = fc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i <= K ; i ++ ) { for ( int j = 0 ; j <= K ; j ++ ) { int temp = S - i - j ; if ( temp >= 0 && temp <= K ) count ++ ; } } System . out . println ( count ) ; } static class FastScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public FastScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; tokenizer = null ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public String nextLine ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { return reader . readLine ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( " \n " ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } public int [ ] nextIntArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } public long [ ] nextLongArray ( int n ) { long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextLong ( ) ; return a ; } } }


import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; BufferedWriter out = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int k = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int s = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int count = 0 ; for ( int i = 0 ; i <= k ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { if ( s >= i + j && s - ( i + j ) <= k ) { count ++ ; } if ( s < i + j ) break ; } if ( s < i ) break ; } out . write ( String . valueOf ( count ) ) ; out . write ( " \n " ) ; out . close ( ) ; } }


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 K = sc . nextInt ( ) ; int S = sc . nextInt ( ) ; int count = 0 ; for ( int x = 0 ; x <= K ; x ++ ) { for ( int y = 0 ; y <= K ; y ++ ) { if ( S - x - y <= K && S >= x + y ) { count ++ ; } } } System . out . println ( count ) ; } }


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = Integer . parseInt ( sc . next ( ) ) ; int S = Integer . parseInt ( sc . next ( ) ) ; int C = 0 ; int nam = 0 ; for ( int a = 0 ; a <= K ; a ++ ) { for ( int b = 0 ; b <= K ; b ++ ) { C = S - a - b ; if ( 0 <= C && C <= K ) { nam = nam + 1 ; } } } System . out . print ( nam ) ; } }


import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; long a [ ] = new long [ 3 * n ] ; for ( int i = 0 ; i < 3 * n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long sumr [ ] = new long [ n + 1 ] ; long sumb [ ] = new long [ n + 1 ] ; Queue < Long > rq = new PriorityQueue < > ( ( o1 , o2 ) -> Long . compare ( o1 , o2 ) ) ; Queue < Long > bq = new PriorityQueue < > ( ( o1 , o2 ) -> Long . compare ( o2 , o1 ) ) ; for ( int i = 0 ; i < n ; i ++ ) { rq . add ( a [ i ] ) ; sumr [ 0 ] += a [ i ] ; bq . add ( a [ 2 * n + i ] ) ; sumb [ n ] += a [ 2 * n + i ] ; } for ( int i = n ; i < 2 * n ; i ++ ) { sumr [ i - n + 1 ] = sumr [ i - n ] + a [ i ] ; rq . add ( a [ i ] ) ; sumr [ i - n + 1 ] -= rq . poll ( ) ; sumb [ 2 * n - i - 1 ] = sumb [ 2 * n - i ] + a [ 3 * n - i - 1 ] ; bq . add ( a [ 3 * n - i - 1 ] ) ; sumb [ 2 * n - i - 1 ] -= bq . poll ( ) ; } long ans = sumr [ n ] - sumb [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , sumr [ i ] - sumb [ i ] ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

import heapq NEW_LINE n = int ( input ( ) ) NEW_LINE a = [ 0 ] + list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE selectleft , selectright = [ ] , [ ] NEW_LINE leftscore , rightscore = [ ] , [ ] NEW_LINE for i in range ( 1 , n + 1 ) : heapq . heappush ( selectleft , a [ i ] ) NEW_LINE leftscore . append ( sum ( selectleft ) ) NEW_LINE for i in range ( n + 1 , 2 * n + 1 ) : NEW_LINE INDENT heapq . heappush ( selectleft , a [ i ] ) NEW_LINE tmpscore = leftscore [ - 1 ] + a [ i ] NEW_LINE poped = heapq . heappop ( selectleft ) NEW_LINE tmpscore -= poped NEW_LINE leftscore . append ( tmpscore ) NEW_LINE DEDENT for i in range ( 2 * n + 1 , 3 * n + 1 ) : NEW_LINE INDENT heapq . heappush ( selectright , ( - 1 ) * a [ i ] ) NEW_LINE DEDENT rightscore . append ( sum ( selectright ) * ( - 1 ) ) NEW_LINE for i in range ( 2 * n , n , - 1 ) : NEW_LINE INDENT heapq . heappush ( selectright , ( - 1 ) * a [ i ] ) NEW_LINE tmpscore = rightscore [ - 1 ] + a [ i ] NEW_LINE poped = heapq . heappop ( selectright ) * ( - 1 ) NEW_LINE tmpscore -= poped NEW_LINE rightscore . append ( tmpscore ) NEW_LINE DEDENT rightscore . reverse ( ) NEW_LINE print ( max ( map ( lambda x , y : x - y , leftscore , rightscore ) ) ) NEW_LINE


ai = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE n = int ( input ( ) ) NEW_LINE a = ai ( ) NEW_LINE big = sum ( a [ : n ] ) NEW_LINE small = sum ( a [ 2 * n : ] ) NEW_LINE import heapq NEW_LINE af = a [ : n ] NEW_LINE heapq . heapify ( af ) NEW_LINE ar = [ - i for i in a [ 2 * n : ] ] NEW_LINE heapq . heapify ( ar ) NEW_LINE ans = [ [ 0 , 0 ] for _ in range ( n + 1 ) ] NEW_LINE ans [ 0 ] [ 0 ] = big NEW_LINE ans [ - 1 ] [ 1 ] = small NEW_LINE for k in range ( n ) : NEW_LINE INDENT if af [ 0 ] < a [ n + k ] : NEW_LINE INDENT b = heapq . heapreplace ( af , a [ n + k ] ) NEW_LINE big += a [ n + k ] - b NEW_LINE DEDENT ans [ k + 1 ] [ 0 ] = big NEW_LINE DEDENT for k in range ( n ) : NEW_LINE INDENT if - ar [ 0 ] > a [ - n - k - 1 ] : NEW_LINE INDENT s = heapq . heapreplace ( ar , - a [ - n - k - 1 ] ) NEW_LINE small += a [ - n - k - 1 ] + s NEW_LINE DEDENT ans [ - k - 2 ] [ 1 ] = small NEW_LINE DEDENT print ( max ( i - j for i , j in ans ) ) NEW_LINE


from heapq import heappush , heappushpop , heapify NEW_LINE n = int ( input ( ) ) NEW_LINE a = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE q = [ ] NEW_LINE s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT heappush ( q , a [ i ] ) NEW_LINE s += a [ i ] NEW_LINE DEDENT left = [ s ] NEW_LINE for k in range ( n ) : NEW_LINE INDENT x = heappushpop ( q , a [ n + k ] ) NEW_LINE s = s - x + a [ n + k ] NEW_LINE left . append ( s ) NEW_LINE DEDENT q = [ ] NEW_LINE s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT heappush ( q , - 1 * a [ 3 * n - 1 - i ] ) NEW_LINE s += a [ 3 * n - 1 - i ] NEW_LINE DEDENT right = [ 0 for _ in range ( n + 1 ) ] NEW_LINE right [ n ] = s NEW_LINE for k in range ( n ) : NEW_LINE INDENT x = heappushpop ( q , - 1 * a [ 2 * n - 1 - k ] ) NEW_LINE s = s - ( - 1 * x ) + a [ 2 * n - 1 - k ] NEW_LINE right [ n - 1 - k ] = s NEW_LINE DEDENT m = None NEW_LINE for k in range ( n + 1 ) : NEW_LINE INDENT if m is None : NEW_LINE INDENT m = left [ k ] - right [ k ] NEW_LINE DEDENT else : NEW_LINE INDENT m = max ( m , left [ k ] - right [ k ] ) NEW_LINE DEDENT DEDENT print ( m ) NEW_LINE


import sys NEW_LINE sys . setrecursionlimit ( 100000 ) NEW_LINE import heapq NEW_LINE n = int ( input ( ) ) NEW_LINE data = [ ] NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE amax = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT heapq . heappush ( data , a [ i ] ) NEW_LINE amax += a [ i ] NEW_LINE DEDENT ansdata = [ amax ] NEW_LINE for i in range ( n , 2 * n ) : NEW_LINE INDENT heapq . heappush ( data , a [ i ] ) NEW_LINE amax += a [ i ] NEW_LINE amax -= heapq . heappop ( data ) NEW_LINE ansdata . append ( amax ) NEW_LINE DEDENT data = [ ] NEW_LINE bmin = 0 NEW_LINE for i in range ( 2 * n , 3 * n ) : NEW_LINE INDENT heapq . heappush ( data , - a [ i ] ) NEW_LINE bmin += a [ i ] NEW_LINE DEDENT ansdata [ - 1 ] -= bmin NEW_LINE for i in range ( n ) : NEW_LINE INDENT t = i NEW_LINE i = 2 * n - 1 - i NEW_LINE heapq . heappush ( data , - a [ i ] ) NEW_LINE bmin += a [ i ] NEW_LINE bmin += heapq . heappop ( data ) NEW_LINE ansdata [ - t - 2 ] -= bmin NEW_LINE DEDENT print ( max ( ansdata ) ) NEW_LINE


import heapq NEW_LINE N = int ( input ( ) ) NEW_LINE a_ls = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE before = [ ] NEW_LINE _sum_before = 0 NEW_LINE before_scores = [ ] NEW_LINE after = [ ] NEW_LINE _sum_after = 0 NEW_LINE after_scores = [ ] NEW_LINE best = None NEW_LINE for i in range ( 2 * N ) : NEW_LINE INDENT _sum_before += a_ls [ i ] NEW_LINE heapq . heappush ( before , a_ls [ i ] ) NEW_LINE _sum_after += a_ls [ - i - 1 ] NEW_LINE heapq . heappush ( after , - a_ls [ - i - 1 ] ) NEW_LINE if i >= N : NEW_LINE INDENT _sum_before -= heapq . heappop ( before ) NEW_LINE _sum_after -= - heapq . heappop ( after ) NEW_LINE DEDENT if i >= N - 1 : NEW_LINE INDENT before_scores . append ( _sum_before ) NEW_LINE after_scores . append ( _sum_after ) NEW_LINE DEDENT DEDENT after_scores = after_scores [ : : - 1 ] NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT score = before_scores [ i ] - after_scores [ i ] NEW_LINE if best is None : NEW_LINE INDENT best = score NEW_LINE DEDENT best = score if best < score else best NEW_LINE DEDENT print ( best ) NEW_LINE


import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; PriorityQueue < Long > left = new PriorityQueue < > ( n ) ; long [ ] center = new long [ n ] ; PriorityQueue < Long > right = new PriorityQueue < > ( ( l1 , l2 ) -> { return l2 . compareTo ( l1 ) ; } ) ; for ( int i = 0 ; i < n ; i ++ ) { left . add ( sc . nextLong ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { center [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { right . add ( sc . nextLong ( ) ) ; } long [ ] lmove = new long [ n + 1 ] ; lmove [ 0 ] = left . stream ( ) . mapToLong ( i -> i ) . sum ( ) ; long [ ] rmove = new long [ n + 1 ] ; rmove [ 0 ] = right . stream ( ) . mapToLong ( i -> i ) . sum ( ) ; for ( int i = 0 ; i < n ; i ++ ) { left . add ( center [ i ] ) ; lmove [ i + 1 ] = lmove [ i ] - left . poll ( ) + center [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { right . add ( center [ n - 1 - i ] ) ; rmove [ i + 1 ] = rmove [ i ] - right . poll ( ) + center [ n - 1 - i ] ; } long ans = Long . MIN_VALUE ; for ( int i = 0 ; i <= n ; i ++ ) { long temp = lmove [ i ] - rmove [ n - i ] ; ans = Math . max ( temp , ans ) ; } System . out . println ( ans ) ; } }


import java . util . Comparator ; import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { int n ; long [ ] as ; PriorityQueue < Long > maxQueue ; PriorityQueue < Long > minQueue ; public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . read ( ) ; m . solve ( ) ; } private void read ( ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; as = new long [ 3 * n ] ; for ( int i = 0 ; i < as . length ; i ++ ) { as [ i ] = sc . nextLong ( ) ; } } private void solve ( ) { maxQueue = new PriorityQueue < > ( ) ; minQueue = new PriorityQueue < > ( Comparator . reverseOrder ( ) ) ; long [ ] maxs = new long [ n + 1 ] ; long [ ] mins = new long [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { maxQueue . add ( as [ i ] ) ; maxs [ 0 ] += as [ i ] ; minQueue . add ( as [ 3 * n - 1 - i ] ) ; mins [ mins . length - 1 ] += as [ 3 * n - 1 - i ] ; } for ( int i = n ; i < 2 * n ; i ++ ) { maxQueue . add ( as [ i ] ) ; long e = maxQueue . poll ( ) ; maxs [ i - n + 1 ] = maxs [ i - n ] + as [ i ] - e ; } for ( int i = 2 * n - 1 ; i >= n ; i -- ) { minQueue . add ( as [ i ] ) ; long e = minQueue . poll ( ) ; mins [ i - n ] = mins [ i - n + 1 ] + as [ i ] - e ; } long ans = maxs [ 0 ] - mins [ 0 ] ; for ( int i = 0 ; i <= n ; i ++ ) { ans = Math . max ( ans , maxs [ i ] - mins [ i ] ) ; } System . out . println ( ans ) ; } }


import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; PriorityQueue < Integer > mae = new PriorityQueue < Integer > ( ) ; PriorityQueue < Integer > ato = new PriorityQueue < Integer > ( ( Integer x1 , Integer x2 ) -> x2 - x1 ) ; long [ ] maeSum = new long [ N + 1 ] ; long [ ] atoSum = new long [ N + 1 ] ; long ans = Long . MIN_VALUE ; int [ ] A = new int [ N * 3 ] ; for ( int i = 0 ; i < N * 3 ; i ++ ) { int a = sc . nextInt ( ) ; A [ i ] = a ; if ( i < N ) { mae . add ( a ) ; maeSum [ 0 ] += a ; } else if ( i >= N * 2 ) { ato . add ( a ) ; atoSum [ N ] += a ; } } for ( int i = N ; i < N * 2 ; i ++ ) { int k = i - ( N - 1 ) ; if ( A [ i ] > mae . peek ( ) ) { maeSum [ k ] = maeSum [ k - 1 ] - mae . poll ( ) + A [ i ] ; mae . add ( A [ i ] ) ; } else { maeSum [ k ] = maeSum [ k - 1 ] ; } } for ( int i = N * 2 - 1 ; i >= N ; i -- ) { int k = i - N ; if ( A [ i ] < ato . peek ( ) ) { atoSum [ k ] = atoSum [ k + 1 ] - ato . poll ( ) + A [ i ] ; ato . add ( A [ i ] ) ; } else { atoSum [ k ] = atoSum [ k + 1 ] ; } } for ( int i = 0 ; i <= N ; i ++ ) { ans = Math . max ( ans , maeSum [ i ] - atoSum [ i ] ) ; } System . out . println ( ans ) ; sc . close ( ) ; } }


import java . util . Comparator ; import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; long [ ] a = new long [ n * 3 ] ; for ( int i = 0 ; i < 3 * n ; ++ i ) { a [ i ] = scanner . nextLong ( ) ; } final PriorityQueue < Long > firstHalf = new PriorityQueue < > ( ) ; final PriorityQueue < Long > secondHalf = new PriorityQueue < > ( Comparator . reverseOrder ( ) ) ; long [ ] leftSum = new long [ n + 1 ] ; long [ ] rightSum = new long [ n + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) { firstHalf . add ( a [ i ] ) ; leftSum [ 0 ] += a [ i ] ; } for ( int i = n ; i < 2 * n ; ++ i ) { firstHalf . add ( a [ i ] ) ; long head = firstHalf . poll ( ) ; leftSum [ i - n + 1 ] = leftSum [ i - n ] + a [ i ] - head ; } for ( int i = 3 * n - 1 ; i >= 2 * n ; -- i ) { secondHalf . add ( a [ i ] ) ; rightSum [ n ] += a [ i ] ; } for ( int i = 2 * n - 1 ; i >= n ; -- i ) { secondHalf . add ( a [ i ] ) ; long head = secondHalf . poll ( ) ; rightSum [ i - n ] = rightSum [ i - n + 1 ] + a [ i ] - head ; } long result = Long . MIN_VALUE ; for ( int i = 0 ; i <= n ; ++ i ) { result = Math . max ( result , leftSum [ i ] - rightSum [ i ] ) ; } System . out . println ( result ) ; } }


import java . util . * ; class Main { static long [ ] a , b ; static int n ; static long count ( long v ) { long res = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int l = - 1 , r = n ; while ( r - l > 1 ) { int c = ( l + r ) / 2 ; if ( a [ i ] * b [ c ] <= v ) l = c ; else r = c ; } res += r ; } return res ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; long k = sc . nextLong ( ) ; a = new long [ n ] ; b = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) a [ i ] = sc . nextLong ( ) ; for ( int i = 0 ; i < n ; ++ i ) b [ i ] = sc . nextLong ( ) ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; long l = 0 , r = Long . MAX_VALUE / 2 ; while ( r - l > 1L ) { long c = ( l + r ) / 2 ; if ( count ( c ) < k ) l = c ; else r = c ; } System . out . println ( r ) ; } }

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE * A , = map ( int , input ( ) . split ( ) ) NEW_LINE * B , = map ( int , input ( ) . split ( ) ) NEW_LINE A . sort ( reverse = 1 ) ; B . sort ( ) NEW_LINE def check ( mid ) : NEW_LINE INDENT j = 0 NEW_LINE res = 0 NEW_LINE for a in A : NEW_LINE INDENT while j < N and a * B [ j ] <= mid : NEW_LINE INDENT j += 1 NEW_LINE DEDENT res += j NEW_LINE DEDENT return K <= res NEW_LINE DEDENT left = 0 ; right = 10 ** 18 + 1 NEW_LINE while left + 1 < right : NEW_LINE INDENT mid = ( left + right ) // 2 NEW_LINE if check ( mid ) : NEW_LINE INDENT right = mid NEW_LINE DEDENT else : NEW_LINE INDENT left = mid NEW_LINE DEDENT DEDENT print ( right ) NEW_LINE


import bisect NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE B = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE minp = A [ 0 ] * B [ 0 ] NEW_LINE maxp = A [ - 1 ] * B [ - 1 ] NEW_LINE if K == 1 : NEW_LINE INDENT print ( minp ) NEW_LINE exit ( ) NEW_LINE DEDENT if K == N * N : NEW_LINE INDENT print ( maxp ) NEW_LINE exit ( ) NEW_LINE DEDENT def enough ( n ) : NEW_LINE INDENT cnt = 0 NEW_LINE for a in A : NEW_LINE INDENT cnt += bisect . bisect_right ( B , n // a ) NEW_LINE if cnt >= K : return True NEW_LINE DEDENT return False NEW_LINE DEDENT ng = 0 NEW_LINE ok = maxp NEW_LINE while ok - ng > 1 : NEW_LINE INDENT m = ( ok + ng ) // 2 NEW_LINE if enough ( m ) : NEW_LINE INDENT ok = m NEW_LINE DEDENT else : NEW_LINE INDENT ng = m NEW_LINE DEDENT DEDENT print ( ok ) NEW_LINE


import sys , bisect NEW_LINE input = sys . stdin . readline NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = sorted ( tuple ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE b = tuple ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sma = 1 NEW_LINE big = 10 ** 18 NEW_LINE while big - sma > 1 : NEW_LINE INDENT mid = ( big + sma ) // 2 NEW_LINE cnt = 0 NEW_LINE for e in b : NEW_LINE INDENT p = mid // e NEW_LINE q = bisect . bisect_right ( a , p ) NEW_LINE cnt += q NEW_LINE DEDENT if cnt >= k : NEW_LINE INDENT big = mid NEW_LINE DEDENT else : NEW_LINE INDENT sma = mid NEW_LINE DEDENT DEDENT cnt = 0 NEW_LINE for e in b : NEW_LINE INDENT p = sma // e NEW_LINE q = bisect . bisect_right ( a , p ) NEW_LINE cnt += q NEW_LINE DEDENT if cnt >= k : NEW_LINE INDENT print ( sma ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( big ) NEW_LINE DEDENT


import bisect NEW_LINE def solve ( n , k , a , b ) : NEW_LINE INDENT b . sort ( ) NEW_LINE lo = 0 NEW_LINE hi = 10 ** 18 NEW_LINE while lo + 1 < hi : NEW_LINE INDENT mid = ( lo + hi ) // 2 NEW_LINE c = 0 NEW_LINE for ai in a : NEW_LINE INDENT p = mid // ai NEW_LINE j = bisect . bisect_right ( b , p ) NEW_LINE c += j NEW_LINE DEDENT if k <= c : NEW_LINE INDENT hi = mid NEW_LINE DEDENT else : NEW_LINE INDENT lo = mid NEW_LINE DEDENT DEDENT return hi NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n , k = input ( ) . split ( ) NEW_LINE n = int ( n ) NEW_LINE k = int ( k ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE print ( solve ( n , k , a , b ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


from bisect import bisect_right NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = sorted ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE l , r = 0 , 10 ** 18 + 1 NEW_LINE while r - l > 1 : NEW_LINE INDENT x = ( r + l ) // 2 NEW_LINE count = sum ( bisect_right ( a , x // bi ) for bi in b ) NEW_LINE if count < k : NEW_LINE INDENT l = x NEW_LINE DEDENT else : NEW_LINE INDENT r = x NEW_LINE DEDENT DEDENT print ( r ) NEW_LINE


import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main implements Runnable { public static void main ( String [ ] args ) { new Thread ( null , new Main ( ) , " " , Runtime . getRuntime ( ) . maxMemory ( ) ) . start ( ) ; } boolean check ( long [ ] a , long [ ] b , long middle , int k ) { int n = a . length ; long sum = 0 ; int h = n - 1 ; for ( int i = 0 ; i < n ; ++ i ) { while ( h > 0 && a [ i ] * b [ h ] > middle ) { -- h ; } if ( a [ i ] * b [ h ] <= middle ) sum += h + 1 ; } return sum >= k ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long [ ] b = new long [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < n ; ++ i ) { b [ i ] = sc . nextLong ( ) ; } Arrays . sort ( a ) ; Arrays . sort ( b ) ; long ng = 0 ; long ok = a [ n - 1 ] * b [ n - 1 ] ; while ( ok - ng > 1 ) { long middle = ( ok + ng ) / 2 ; if ( check ( a , b , middle , k ) ) { ok = middle ; } else { ng = middle ; } } System . out . println ( ok ) ; } static void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } }


import java . util . * ; class Main { static int inf = Integer . MAX_VALUE ; static int n , k ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = Integer . parseInt ( sc . next ( ) ) ; k = Integer . parseInt ( sc . next ( ) ) ; long [ ] hori = new long [ n ] ; long [ ] vert = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) vert [ i ] = Long . parseLong ( sc . next ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) hori [ i ] = Long . parseLong ( sc . next ( ) ) ; Arrays . sort ( vert ) ; Arrays . sort ( hori ) ; long hi = hori [ n - 1 ] * vert [ n - 1 ] ; long lo = hori [ 0 ] * vert [ 0 ] - 1 ; long mid ; while ( hi - lo > 1 ) { mid = ( hi + lo ) / 2 ; if ( check ( vert , hori , mid ) ) hi = mid ; else lo = mid ; } System . out . println ( hi ) ; } static boolean check ( long [ ] vert , long [ ] hori , long guess ) { int cnt = 0 ; for ( int x = 0 ; x < n ; x ++ ) { long target = guess / hori [ x ] ; int cur = binary ( vert , target ) ; cnt += cur ; if ( cnt >= k ) return true ; } return cnt >= k ; } static int binary ( long [ ] a , long target ) { if ( target < a [ 0 ] ) return 0 ; if ( target >= a [ n - 1 ] ) return n ; int hi = n - 1 ; int lo = - 1 ; int mid ; while ( hi - lo > 1 ) { mid = ( hi + lo ) / 2 ; if ( a [ mid ] <= target ) lo = mid ; else hi = mid ; } return hi ; } }


import java . util . * ; public class Main { static int n ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; long k = sc . nextLong ( ) ; long [ ] a = new long [ n ] ; long [ ] b = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = sc . nextLong ( ) ; } Arrays . sort ( a ) ; Arrays . sort ( b ) ; long max = a [ n - 1 ] * b [ n - 1 ] ; System . out . println ( binSearch ( max , - 1 , k , a , b ) ) ; } public static long binSearch ( long ok , long ng , long k , long [ ] a , long [ ] b ) { while ( Math . abs ( ok - ng ) > 1 ) { long mid = ( ok + ng ) / 2 ; if ( solve ( mid , a , b ) >= k ) { ok = mid ; } else { ng = mid ; } } return ok ; } public static long solve ( long k , long [ ] a , long [ ] b ) { long cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( b [ 0 ] * a [ i ] > k ) { continue ; } long ok = 0 ; long ng = n ; while ( Math . abs ( ok - ng ) > 1 ) { long mid = ( ok + ng ) / 2 ; if ( b [ ( int ) mid ] * a [ i ] <= k ) { ok = mid ; } else { ng = mid ; } } cnt += ok + 1 ; } return cnt ; } }


import java . util . Arrays ; import java . util . Scanner ; public class Main { static Scanner in = new Scanner ( System . in ) ; int n , k ; String s ; void solve ( ) { n = in . nextInt ( ) ; k = in . nextInt ( ) ; in . nextLine ( ) ; s = in . nextLine ( ) ; char [ ] c = s . toCharArray ( ) ; Arrays . sort ( c ) ; String ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( c [ j ] == ' \0' ) continue ; if ( count ( ans , c , c [ j ] ) <= k ) { ans += c [ j ] ; c [ j ] = ' \0' ; break ; } } } System . out . println ( ans ) ; } int count ( String ans , char [ ] c , char ch ) { int diff = 0 ; for ( int i = 0 ; i < ans . length ( ) ; i ++ ) { diff += s . charAt ( i ) == ans . charAt ( i ) ? 0 : 1 ; } if ( ch != s . charAt ( ans . length ( ) ) ) { diff ++ ; } int [ ] a = new int [ 26 ] ; for ( char b : c ) { if ( b == ' \0' ) continue ; a [ b - ' a ' ] ++ ; } a [ ch - ' a ' ] -- ; for ( int i = ans . length ( ) + 1 ; i < s . length ( ) ; i ++ ) { int idx = s . charAt ( i ) - ' a ' ; if ( a [ idx ] > 0 ) { a [ idx ] -- ; } else { diff ++ ; } } return diff ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } }

from copy import copy NEW_LINE def main ( ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE s = list ( input ( ) ) NEW_LINE print ( " " . join ( smallest ( k , s , s ) ) ) NEW_LINE DEDENT def smallest ( k , s , avail ) : NEW_LINE INDENT assert len ( s ) == len ( avail ) NEW_LINE assert k >= 0 NEW_LINE if len ( s ) == 1 : NEW_LINE INDENT return avail NEW_LINE DEDENT else : NEW_LINE INDENT for x in sorted ( avail ) : NEW_LINE INDENT k2 = k if x == s [ 0 ] else k - 1 NEW_LINE if is_possible ( k2 , s [ 1 : ] , sub ( avail , x ) ) : NEW_LINE INDENT return [ x ] + smallest ( k2 , s [ 1 : ] , sub ( avail , x ) ) NEW_LINE DEDENT DEDENT raise Exception NEW_LINE DEDENT DEDENT def is_possible ( k , s , avail ) : NEW_LINE INDENT return diff_multisets ( s , avail ) <= k NEW_LINE DEDENT def diff_multisets ( s , t ) : NEW_LINE INDENT assert len ( s ) == len ( t ) NEW_LINE ss = copy ( s ) NEW_LINE tt = copy ( t ) NEW_LINE for x in ss : NEW_LINE INDENT if x in tt : NEW_LINE INDENT i = tt . index ( x ) NEW_LINE tt = tt [ : i ] + tt [ i + 1 : ] NEW_LINE DEDENT DEDENT return len ( tt ) NEW_LINE DEDENT def sub ( li , x ) : NEW_LINE INDENT assert x in li NEW_LINE i = li . index ( x ) NEW_LINE return li [ : i ] + li [ i + 1 : ] NEW_LINE DEDENT main ( ) NEW_LINE


from collections import defaultdict NEW_LINE from heapq import heappush , heappop NEW_LINE import sys NEW_LINE import math NEW_LINE import bisect NEW_LINE import random NEW_LINE def LI ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def S ( ) : return list ( sys . stdin . readline ( ) ) [ : - 1 ] NEW_LINE def IR ( n ) : return [ I ( ) for i in range ( n ) ] NEW_LINE def LIR ( n ) : return [ LI ( ) for i in range ( n ) ] NEW_LINE def SR ( n ) : return [ S ( ) for i in range ( n ) ] NEW_LINE def LSR ( n ) : return [ LS ( ) for i in range ( n ) ] NEW_LINE mod = 1000000007 NEW_LINE def score ( x ) : NEW_LINE INDENT res = 0 NEW_LINE for i in d . keys ( ) : NEW_LINE INDENT res += min ( c [ i ] , d [ i ] ) NEW_LINE DEDENT return x - res NEW_LINE DEDENT n , k = LI ( ) NEW_LINE s = S ( ) NEW_LINE t = [ ] NEW_LINE l = [ 1 for i in range ( n ) ] NEW_LINE c = defaultdict ( int ) NEW_LINE d = defaultdict ( int ) NEW_LINE for i in s : NEW_LINE INDENT c [ i ] += 1 NEW_LINE d [ i ] += 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT c [ s [ i ] ] -= 1 NEW_LINE for j in sorted ( list ( d . keys ( ) ) ) : NEW_LINE INDENT if d [ j ] : NEW_LINE INDENT d [ j ] -= 1 NEW_LINE sc = score ( n - i - 1 ) NEW_LINE if k >= sc : NEW_LINE INDENT if s [ i ] == j : NEW_LINE INDENT t . append ( j ) NEW_LINE break NEW_LINE DEDENT elif k > sc : NEW_LINE INDENT k -= 1 NEW_LINE t . append ( j ) NEW_LINE break NEW_LINE DEDENT DEDENT d [ j ] += 1 NEW_LINE DEDENT DEDENT DEDENT for i in t : NEW_LINE INDENT print ( i , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE NEW_LINE


from copy import deepcopy as dc NEW_LINE import sys NEW_LINE def swap ( a , b , l ) : NEW_LINE INDENT s = dc ( l ) NEW_LINE s [ a ] , s [ b ] = s [ b ] , s [ a ] NEW_LINE return s NEW_LINE DEDENT def diff ( e , d ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( len ( e ) ) : NEW_LINE INDENT if e [ i ] != d [ i ] : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT input = sys . stdin . readline NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE S = input ( ) [ : - 1 ] NEW_LINE m = list ( S ) NEW_LINE c = [ i for i in m ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = i NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( c [ x ] > c [ j ] ) and ( diff ( m , swap ( i , j , c ) ) <= k ) : NEW_LINE INDENT x = j NEW_LINE DEDENT DEDENT c = swap ( i , x , c ) NEW_LINE DEDENT print ( " " . join ( c ) ) NEW_LINE


import sys NEW_LINE from collections import Counter NEW_LINE inp = sys . stdin . readline NEW_LINE N , K = map ( int , inp ( ) . split ( ) ) NEW_LINE S = inp ( ) . replace ( " \n " , " " ) NEW_LINE sort_S = sorted ( S ) NEW_LINE T = " " NEW_LINE cnt = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT count = Counter ( S [ : i + 1 ] ) - Counter ( list ( T ) ) NEW_LINE sum_ = sum ( count . values ( ) ) NEW_LINE for ss in sort_S : NEW_LINE INDENT if ( ss != S [ i ] ) : NEW_LINE INDENT miss = cnt + 1 NEW_LINE DEDENT else : NEW_LINE INDENT miss = cnt NEW_LINE DEDENT if ( count [ ss ] > 0 ) : NEW_LINE INDENT dif = sum_ - 1 NEW_LINE DEDENT else : NEW_LINE INDENT dif = sum_ NEW_LINE DEDENT if ( miss + dif <= K ) : NEW_LINE INDENT T += ss NEW_LINE sort_S . remove ( ss ) NEW_LINE cnt = miss NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( T ) NEW_LINE


def replace ( s : list , a ) : NEW_LINE INDENT s = list ( s ) NEW_LINE i = s . index ( a ) NEW_LINE s [ 0 ] , s [ i ] = s [ i ] , s [ 0 ] NEW_LINE return s NEW_LINE DEDENT def adopt ( s : list , s0 : list ) : NEW_LINE INDENT res = [ 0 ] * len ( s ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if s0 [ i ] in s : NEW_LINE INDENT res [ i ] = s0 [ i ] NEW_LINE s [ s . index ( s0 [ i ] ) ] = 0 NEW_LINE DEDENT DEDENT import collections NEW_LINE rest = collections . deque ( [ c for c in s if c != 0 ] ) NEW_LINE for i in range ( 0 , len ( res ) ) : NEW_LINE INDENT if res [ i ] == 0 : NEW_LINE INDENT res [ i ] = rest . pop ( ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE s = list ( input ( ) ) NEW_LINE s0 = list ( s ) NEW_LINE for pos in range ( len ( s ) ) : NEW_LINE INDENT pq = sorted ( s [ pos : ] ) NEW_LINE for a in pq : NEW_LINE INDENT t = replace ( s [ pos : ] , a ) [ 1 : ] NEW_LINE t = adopt ( t , s0 [ pos + 1 : ] ) NEW_LINE ss = s [ : pos ] + [ a ] + t NEW_LINE kk = sum ( [ ss [ i ] != s0 [ i ] for i in range ( len ( ss ) ) ] ) NEW_LINE if kk > K : NEW_LINE INDENT continue NEW_LINE DEDENT if len ( t ) != 0 : NEW_LINE INDENT s = ss NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( " " . join ( s ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; char t [ ] = s . clone ( ) ; char ans [ ] = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { Arrays . sort ( t , i , n ) ; for ( int j = i ; j < n ; j ++ ) { ans [ i ] = t [ j ] ; t [ j ] = t [ i ] ; int diff = count1 ( s , ans , i + 1 ) + count2 ( s , t , i + 1 , n ) ; if ( diff <= k ) { break ; } t [ j ] = ans [ i ] ; } } System . out . println ( ans ) ; } private int count1 ( char sr [ ] , char tg [ ] , int e ) { int diff = 0 ; for ( int i = 0 ; i < e ; i ++ ) { if ( sr [ i ] != tg [ i ] ) { diff ++ ; } } return diff ; } private int count2 ( char sr [ ] , char tg [ ] , int s , int e ) { int diff = e - s ; int i = 0 ; int j = 0 ; char src [ ] = Arrays . copyOfRange ( sr , s , e ) ; char tgt [ ] = Arrays . copyOfRange ( tg , s , e ) ; Arrays . sort ( src ) ; Arrays . sort ( tgt ) ; while ( i < src . length && j < tgt . length ) { if ( src [ i ] < tgt [ j ] ) { i ++ ; } else if ( src [ i ] > tgt [ j ] ) { j ++ ; } else { diff -- ; i ++ ; j ++ ; } } return diff ; } 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 . util . * ; public class Main { static String S ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; sc . nextLine ( ) ; S = sc . nextLine ( ) ; char [ ] c = S . toCharArray ( ) ; Arrays . sort ( c ) ; String ans = " " ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( c [ j ] == ' \0' ) continue ; if ( count ( ans , c , c [ j ] ) > K ) continue ; ans += c [ j ] ; c [ j ] = ' \0' ; break ; } } System . out . println ( ans ) ; } private static int count ( String ans , char [ ] c , char ch ) { int diff = 0 ; for ( int i = 0 ; i < ans . length ( ) ; i ++ ) { diff += S . charAt ( i ) == ans . charAt ( i ) ? 0 : 1 ; } if ( ch != S . charAt ( ans . length ( ) ) ) diff ++ ; int [ ] a = new int [ 26 ] ; for ( char b : c ) { if ( b == ' \0' ) continue ; a [ b - ' a ' ] ++ ; } a [ ch - ' a ' ] -- ; for ( int i = ans . length ( ) + 1 ; i < S . length ( ) ; i ++ ) { int idx = S . charAt ( i ) - ' a ' ; if ( a [ idx ] > 0 ) { a [ idx ] -- ; } else { diff ++ ; } } return diff ; } }


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] nk = scanner . nextLine ( ) . split ( " ▁ " , 2 ) ; int n = Integer . parseInt ( nk [ 0 ] ) ; int k = Integer . parseInt ( nk [ 1 ] ) ; String s = scanner . nextLine ( ) ; char [ ] orig = s . toCharArray ( ) ; char [ ] chars = s . toCharArray ( ) ; if ( k == chars . length ) { Arrays . sort ( chars ) ; System . out . println ( new String ( chars ) ) ; return ; } for ( int i = 0 ; i < chars . length ; i ++ ) { int minI = i ; for ( int j = i + 1 ; j < chars . length ; j ++ ) { if ( chars [ minI ] > chars [ j ] ) { char tmp = chars [ i ] ; chars [ i ] = chars [ j ] ; chars [ j ] = tmp ; int count = replaceCount ( orig , chars ) ; if ( count <= k ) { minI = j ; } tmp = chars [ i ] ; chars [ i ] = chars [ j ] ; chars [ j ] = tmp ; } } if ( i != minI ) { char tmp = chars [ i ] ; chars [ i ] = chars [ minI ] ; chars [ minI ] = tmp ; } } System . out . println ( new String ( chars ) ) ; } private static int replaceCount ( char [ ] orig , char [ ] chars ) { int count = 0 ; for ( int i = 0 ; i < orig . length ; i ++ ) { if ( orig [ i ] != chars [ i ] ) { count ++ ; } } return count ; } }


import java . util . LinkedList ; import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; char [ ] ans = new char [ n ] ; LinkedList < Character > list = new LinkedList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( s [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { PriorityQueue < Character > pq = new PriorityQueue < > ( ) ; for ( int j = 0 ; j < list . size ( ) ; j ++ ) { pq . add ( list . get ( j ) ) ; } loop : while ( true ) { char first = pq . poll ( ) ; int tmp = k ; LinkedList < Character > tmpList = ( LinkedList < Character > ) list . clone ( ) ; tmpList . remove ( ( Character ) first ) ; if ( first != s [ i ] ) { tmp -- ; if ( tmp < 0 ) continue ; } for ( int j = i + 1 ; j < n ; j ++ ) { if ( tmpList . contains ( ( Character ) s [ j ] ) ) { tmpList . remove ( ( Character ) s [ j ] ) ; } else { tmp -- ; if ( tmp < 0 ) continue loop ; } } if ( first != s [ i ] ) k -- ; ans [ i ] = first ; list . remove ( ( Character ) first ) ; break ; } } System . out . println ( String . valueOf ( ans ) ) ; sc . close ( ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) , q = sc . nextInt ( ) ; TreeSet < Long > t = new TreeSet < Long > ( ) , s = new TreeSet < Long > ( ) ; for ( int i = 0 ; i < a ; i ++ ) s . add ( sc . nextLong ( ) ) ; for ( int i = 0 ; i < b ; i ++ ) t . add ( sc . nextLong ( ) ) ; for ( int i = 0 ; i < q ; i ++ ) { long pos = sc . nextLong ( ) ; Long tl = t . floor ( pos ) , tr = t . ceiling ( pos ) , sl = s . floor ( pos ) , sr = s . ceiling ( pos ) ; if ( tl == null ) tl = - 1L << 60 ; if ( tr == null ) tr = 1L << 60 ; if ( sl == null ) sl = - 1L << 60 ; if ( sr == null ) sr = 1L << 60 ; Long min = 1L << 60 ; min = Math . min ( Math . max ( pos - tl , pos - sl ) , Math . max ( tr - pos , sr - pos ) ) ; min = Math . min ( min , ( pos - tl ) + ( sr - pos ) + Math . min ( ( pos - tl ) , ( sr - pos ) ) ) ; min = Math . min ( min , ( tr - pos ) + ( pos - sl ) + Math . min ( ( tr - pos ) , ( pos - sl ) ) ) ; System . out . println ( min ) ; } } }

from bisect import bisect_left NEW_LINE a , b , q = map ( int , input ( ) . split ( ) ) NEW_LINE inf = float ( ' inf ' ) NEW_LINE S = [ - inf ] + [ int ( input ( ) ) for i in range ( a ) ] + [ inf ] NEW_LINE T = [ - inf ] + [ int ( input ( ) ) for i in range ( b ) ] + [ inf ] NEW_LINE def f ( S , T ) : NEW_LINE INDENT res = 10 ** 30 NEW_LINE s = bisect_left ( S , x ) NEW_LINE ans = 0 NEW_LINE t = bisect_left ( T , S [ s - 1 ] ) NEW_LINE ans += abs ( x - S [ s - 1 ] ) + min ( abs ( S [ s - 1 ] - T [ t - 1 ] ) , abs ( S [ s - 1 ] - T [ t ] ) ) NEW_LINE if ans <= res : NEW_LINE INDENT res = ans NEW_LINE DEDENT ans = 0 NEW_LINE t = bisect_left ( T , S [ s ] ) NEW_LINE ans += abs ( x - S [ s ] ) + min ( abs ( S [ s ] - T [ t - 1 ] ) , abs ( S [ s ] - T [ t ] ) ) NEW_LINE if ans <= res : NEW_LINE INDENT res = ans NEW_LINE DEDENT return res NEW_LINE DEDENT for i in range ( q ) : NEW_LINE INDENT x = int ( input ( ) ) NEW_LINE print ( min ( f ( S , T ) , f ( T , S ) ) ) NEW_LINE DEDENT


A , B , Q = map ( int , input ( ) . split ( ) ) NEW_LINE s = [ ] NEW_LINE t = [ ] NEW_LINE x = [ ] NEW_LINE for _ in range ( A ) : NEW_LINE INDENT s . append ( int ( input ( ) ) ) NEW_LINE DEDENT for _ in range ( B ) : NEW_LINE INDENT t . append ( int ( input ( ) ) ) NEW_LINE DEDENT for _ in range ( Q ) : NEW_LINE INDENT x . append ( int ( input ( ) ) ) NEW_LINE DEDENT import sys NEW_LINE INT_MAX = sys . maxsize NEW_LINE s . insert ( 0 , - 1 * INT_MAX ) NEW_LINE s . append ( INT_MAX ) NEW_LINE t . insert ( 0 , - 1 * INT_MAX ) NEW_LINE t . append ( INT_MAX ) NEW_LINE import bisect NEW_LINE for xi in x : NEW_LINE INDENT si = bisect . bisect_right ( s , xi ) NEW_LINE ti = bisect . bisect_right ( t , xi ) NEW_LINE sa = s [ si ] NEW_LINE ta = t [ ti ] NEW_LINE sb = s [ si - 1 ] NEW_LINE tb = t [ ti - 1 ] NEW_LINE ans = min ( [ abs ( xi - sa ) + abs ( sa - ta ) , abs ( xi - sa ) + abs ( sa - tb ) , abs ( xi - sb ) + abs ( sb - ta ) , abs ( xi - sb ) + abs ( sb - tb ) , abs ( xi - ta ) + abs ( ta - sa ) , abs ( xi - ta ) + abs ( ta - sb ) , abs ( xi - tb ) + abs ( tb - sa ) , abs ( xi - tb ) + abs ( tb - sb ) ] ) NEW_LINE print ( ans ) NEW_LINE DEDENT


import sys NEW_LINE def solve ( N : int , M : int , Q : int , s : " List [ int ] " , t : " List [ int ] " , x : " List [ int ] " ) : NEW_LINE INDENT def binary_search ( ary , val ) : NEW_LINE INDENT n = len ( ary ) NEW_LINE l = - 1 NEW_LINE r = n NEW_LINE while r - l > 1 : NEW_LINE INDENT mid = ( l + r ) // 2 NEW_LINE if ary [ mid ] >= val : NEW_LINE INDENT r = mid NEW_LINE DEDENT else : NEW_LINE INDENT l = mid NEW_LINE DEDENT DEDENT if l == - 1 : NEW_LINE INDENT return [ ary [ 0 ] ] NEW_LINE DEDENT if r == n : NEW_LINE INDENT return [ ary [ n - 1 ] ] NEW_LINE DEDENT return [ ary [ l ] , ary [ r ] ] NEW_LINE DEDENT for q in x : NEW_LINE INDENT ret = float ( ' inf ' ) NEW_LINE a_pos = binary_search ( s , q ) NEW_LINE b_pos = binary_search ( t , q ) NEW_LINE for a in a_pos : NEW_LINE INDENT for b in b_pos : NEW_LINE INDENT ret = min ( ret , abs ( a - q ) + abs ( b - a ) ) NEW_LINE ret = min ( ret , abs ( b - q ) + abs ( a - b ) ) NEW_LINE DEDENT DEDENT print ( ret ) NEW_LINE DEDENT return NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT def iterate_tokens ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield word NEW_LINE DEDENT DEDENT DEDENT tokens = iterate_tokens ( ) NEW_LINE A = int ( next ( tokens ) ) NEW_LINE B = int ( next ( tokens ) ) NEW_LINE Q = int ( next ( tokens ) ) NEW_LINE s = [ int ( next ( tokens ) ) for _ in range ( A ) ] NEW_LINE t = [ int ( next ( tokens ) ) for _ in range ( B ) ] NEW_LINE x = [ int ( next ( tokens ) ) for _ in range ( Q ) ] NEW_LINE solve ( A , B , Q , s , t , x ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


from bisect import bisect_left NEW_LINE def solve ( string ) : NEW_LINE INDENT a , b , q , * stx = map ( int , string . split ( ) ) NEW_LINE s = [ - 10 ** 10 ] + stx [ : a ] + [ 2 * 10 ** 10 ] NEW_LINE t = [ - 10 ** 10 ] + stx [ a : a + b ] + [ 2 * 10 ** 10 ] NEW_LINE x = dict ( [ ] ) NEW_LINE ans = [ ] NEW_LINE i_s = 0 NEW_LINE i_t = 0 NEW_LINE for _x in sorted ( stx [ - q : ] ) : NEW_LINE INDENT while s [ i_s ] < _x : NEW_LINE INDENT i_s += 1 NEW_LINE DEDENT while t [ i_t ] < _x : NEW_LINE INDENT i_t += 1 NEW_LINE DEDENT ls , rs = _x - s [ i_s - 1 ] , s [ i_s ] - _x NEW_LINE lt , rt = _x - t [ i_t - 1 ] , t [ i_t ] - _x NEW_LINE r_max = rs if rs > rt else rt NEW_LINE l_max = ls if ls > lt else lt NEW_LINE x [ _x ] = str ( min ( r_max , l_max , rt + ls + ( rt if rt < ls else ls ) , rs + lt + ( rs if rs < lt else lt ) ) ) NEW_LINE DEDENT return " \n " . join ( [ x [ _x ] for _x in stx [ - q : ] ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n , m , l = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( ' { } ▁ { } ▁ { } \n ' . format ( n , m , l ) + ' \n ' . join ( [ input ( ) for _ in range ( n + m + l ) ] ) ) ) NEW_LINE DEDENT


import itertools NEW_LINE A , B , Q = [ int ( _ ) for _ in input ( ) . split ( " ▁ " ) ] NEW_LINE s_array = [ int ( input ( ) ) for _ in range ( A ) ] NEW_LINE t_array = [ int ( input ( ) ) for _ in range ( B ) ] NEW_LINE x = [ int ( input ( ) ) for _ in range ( Q ) ] NEW_LINE def binary_search ( arr , point , start , end ) : NEW_LINE INDENT pivot = ( start + end ) // 2 NEW_LINE if end - start > 1 : NEW_LINE INDENT if arr [ pivot ] < point : NEW_LINE INDENT return binary_search ( arr , point , pivot , end ) NEW_LINE DEDENT else : NEW_LINE INDENT return binary_search ( arr , point , start , pivot ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return start NEW_LINE DEDENT DEDENT def find_closest_path ( s_1 , s_2 , t_1 , t_2 , point ) : NEW_LINE INDENT shortest = 10 ** 11 NEW_LINE for s , t in itertools . product ( [ s_1 , s_2 ] , [ t_1 , t_2 ] ) : NEW_LINE INDENT length = min ( abs ( point - t ) , abs ( point - s ) ) + abs ( s - t ) NEW_LINE if length < shortest : NEW_LINE INDENT shortest = length NEW_LINE DEDENT DEDENT return shortest NEW_LINE DEDENT for i in range ( Q ) : NEW_LINE INDENT s_idx = binary_search ( s_array , x [ i ] , 0 , len ( s_array ) - 1 ) NEW_LINE t_idx = binary_search ( t_array , x [ i ] , 0 , len ( t_array ) - 1 ) NEW_LINE if len ( s_array ) > 1 : NEW_LINE INDENT s_1 , s_2 = s_array [ s_idx ] , s_array [ s_idx + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT s_1 , s_2 = s_array [ 0 ] , s_array [ 0 ] NEW_LINE DEDENT if len ( t_array ) > 1 : NEW_LINE INDENT t_1 , t_2 = t_array [ t_idx ] , t_array [ t_idx + 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT t_1 , t_2 = t_array [ 0 ] , t_array [ 0 ] NEW_LINE DEDENT answer = find_closest_path ( s_1 , s_2 , t_1 , t_2 , x [ i ] ) NEW_LINE print ( answer ) NEW_LINE DEDENT


import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; long [ ] a1 = new long [ a + 2 ] ; long [ ] b1 = new long [ b + 2 ] ; a1 [ 0 ] = b1 [ 0 ] = Long . MIN_VALUE ; a1 [ a + 1 ] = b1 [ b + 1 ] = Long . MAX_VALUE / 2 ; long [ ] ans1 = new long [ q ] ; for ( int i = 1 ; i <= a ; i ++ ) { a1 [ i ] = sc . nextLong ( ) ; } for ( int i = 1 ; i <= b ; i ++ ) { b1 [ i ] = sc . nextLong ( ) ; } for ( int k = 0 ; k < q ; k ++ ) { long x = sc . nextLong ( ) ; long ans = Long . MAX_VALUE ; int idxa = - Arrays . binarySearch ( a1 , x ) - 1 ; int [ ] a2 = { idxa , ( idxa == 1 ) ? a + 1 : idxa - 1 } ; int idxb = - Arrays . binarySearch ( b1 , x ) - 1 ; int [ ] b2 = { idxb , ( idxb == 1 ) ? b + 1 : idxb - 1 } ; for ( int i : a2 ) { for ( int j : b2 ) { ans = Math . min ( ans , Math . abs ( a1 [ i ] - x ) + Math . abs ( a1 [ i ] - b1 [ j ] ) ) ; ans = Math . min ( ans , Math . abs ( b1 [ j ] - x ) + Math . abs ( a1 [ i ] - b1 [ j ] ) ) ; } } ans1 [ k ] = ans ; } for ( int i = 0 ; i < q ; i ++ ) { System . out . println ( ans1 [ i ] ) ; } } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { long inf = ( long ) Math . pow ( 10 , 11 ) ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; long [ ] s = new long [ A + 2 ] ; s [ 0 ] = - inf ; s [ A + 1 ] = inf ; for ( int i = 1 ; i < A + 1 ; i ++ ) s [ i ] = sc . nextLong ( ) ; long [ ] t = new long [ B + 2 ] ; t [ 0 ] = - inf ; t [ B + 1 ] = inf ; for ( int i = 1 ; i < B + 1 ; i ++ ) t [ i ] = sc . nextLong ( ) ; long [ ] x = new long [ Q ] ; for ( int i = 0 ; i < Q ; i ++ ) x [ i ] = sc . nextLong ( ) ; for ( int i = 0 ; i < Q ; i ++ ) { int b = Math . abs ( Arrays . binarySearch ( s , x [ i ] ) ) - 1 ; int d = Math . abs ( Arrays . binarySearch ( t , x [ i ] ) ) - 1 ; long res = inf ; for ( int j = b - 1 ; j <= b ; j ++ ) { for ( int k = d - 1 ; k <= d ; k ++ ) { long d1 = Math . abs ( s [ j ] - x [ i ] ) + Math . abs ( s [ j ] - t [ k ] ) ; long d2 = Math . abs ( t [ k ] - x [ i ] ) + Math . abs ( s [ j ] - t [ k ] ) ; res = Math . min ( res , Math . min ( d1 , d2 ) ) ; } } System . out . println ( res ) ; } } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] st = sc . nextLine ( ) . split ( " ▁ " ) ; sc . close ( ) ; int n = Integer . parseInt ( st [ 0 ] ) ; int m = Integer . parseInt ( st [ 1 ] ) ; n = n >= 12 ? n - 12 : n ; double shortHand = ( n * 30 ) + ( m * 0.5 ) ; double longHand = m * 6 ; double ans = Math . abs ( shortHand - longHand ) ; ans = ans > 180 ? Math . abs ( 360 - ans ) : ans ; System . out . println ( ans ) ; } }

n , m = map ( int , input ( ) . split ( ) ) NEW_LINE n = n % 12 NEW_LINE n_angle = n * 30 + m * 0.5 NEW_LINE m_angle = m * 6 NEW_LINE print ( min ( abs ( n_angle - m_angle ) , 360 - abs ( n_angle - m_angle ) ) ) NEW_LINE


def watch ( n : int , m : int ) -> float : NEW_LINE INDENT long_angle = ( n % 12 ) * ( 360 // 12 ) + m * ( 360 // 12 ) / 60 NEW_LINE shor_angle = m * 360 // 60 NEW_LINE angle_diff = abs ( long_angle - shor_angle ) NEW_LINE return min ( angle_diff , 360 - angle_diff ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE ans = watch ( n , m ) NEW_LINE print ( ans ) NEW_LINE DEDENT


n , m = map ( int , input ( ) . split ( ) ) NEW_LINE if abs ( ( 30 * n + 0.5 * m ) - 6 * m ) % 360 == 180 : NEW_LINE INDENT print ( 180 ) NEW_LINE exit ( ) NEW_LINE DEDENT if abs ( ( 30 * n + 0.5 * m ) - 6 * m ) % 360 == 0 : NEW_LINE INDENT print ( 0 ) NEW_LINE exit ( ) NEW_LINE DEDENT if abs ( ( 30 * n + 0.5 * m ) - 6 * m ) % 360 < 180 : NEW_LINE INDENT print ( abs ( ( 30 * n + 0.5 * m ) - 6 * m ) % 360 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 360 - abs ( ( 30 * n + 0.5 * m ) - 6 * m ) % 360 ) NEW_LINE DEDENT


n , m = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE a = ( n % 12 / 12 ) * 360 + ( m / 60 ) * 30 NEW_LINE b = ( m / 60 ) * 360 NEW_LINE x = abs ( a - b ) NEW_LINE print ( min ( x , 360 - x ) ) NEW_LINE


ji , fun = map ( int , input ( ) . split ( ) ) NEW_LINE if ( ji >= 12 ) : NEW_LINE INDENT ji -= 12 NEW_LINE DEDENT tanshin = 6 * fun NEW_LINE tyoushin = 30 * ji + 0.5 * fun NEW_LINE kakudo = abs ( tyoushin - tanshin ) NEW_LINE if ( kakudo >= 180 ) : NEW_LINE INDENT print ( 360 - kakudo ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( kakudo ) NEW_LINE DEDENT


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 ) ; TaskB solver = new TaskB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskB { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { double a = ( in . nextDouble ( ) % 12 ) * 30.0 ; double b = in . nextDouble ( ) * 6.0 ; a += ( 30.0 * ( b / 360.0 ) ) ; double d = Math . abs ( a - b ) ; out . println ( Math . min ( d , 360.0 - d ) ) ; } } 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 ( ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] line = scanner . nextLine ( ) . split ( " ▁ " , 2 ) ; int n = Integer . parseInt ( line [ 0 ] ) ; int m = Integer . parseInt ( line [ 1 ] ) ; double n60 = ( ( double ) ( n % 12 ) + ( ( double ) m / 60.0 ) ) * 5.0 ; double diff = Math . abs ( n60 - ( double ) m ) ; if ( diff > 30.0 ) { diff = 60.0 - diff ; } System . out . println ( 6.0 * diff ) ; } }


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; LightScanner in = new LightScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; B solver = new B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B { public void solve ( int testNumber , LightScanner in , PrintWriter out ) { double n = in . ints ( ) % 12 * 30 , m = in . ints ( ) * 6 ; n += m / 12 ; out . println ( Math . min ( ( n - m + 360 ) % 360 , ( m - n + 360 ) % 360 ) ) ; } } static class LightScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public LightScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String string ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int ints ( ) { return Integer . parseInt ( string ( ) ) ; } } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; double rad = Math . abs ( ( double ) ( sc . nextInt ( ) % 12 ) * 30 - ( double ) sc . nextInt ( ) * ( 11.0 / 2 ) ) ; System . out . println ( Math . min ( rad , 360.0 - rad ) ) ; } }


import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] [ ] t = new int [ n ] [ k ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < k ; j ++ ) { t [ i ] [ j ] = sc . nextInt ( ) ; } } Queue < Integer > rank = new ArrayDeque < > ( ) ; Queue < Integer > q = new ArrayDeque < > ( ) ; for ( int i = 0 ; i < k ; i ++ ) { q . add ( t [ 0 ] [ i ] ) ; rank . add ( 0 ) ; } while ( ! q . isEmpty ( ) ) { int p = q . poll ( ) ; int row = rank . poll ( ) ; if ( p == 0 ) { out . println ( " Found " ) ; exit ( 0 ) ; } for ( int i = 0 ; i < k && row < n - 1 ; i ++ ) { q . add ( p ^ t [ row + 1 ] [ i ] ) ; rank . add ( row + 1 ) ; } } out . println ( " Nothing " ) ; } }

from itertools import product NEW_LINE from functools import reduce NEW_LINE from operator import xor NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE T = [ [ int ( _ ) for _ in input ( ) . split ( ) ] for _ in range ( N ) ] NEW_LINE flag = False NEW_LINE for i in product ( * T ) : NEW_LINE INDENT if reduce ( xor , i ) == 0 : NEW_LINE INDENT flag = True NEW_LINE break NEW_LINE DEDENT DEDENT print ( " Found " if flag else " Nothing " ) NEW_LINE


import math NEW_LINE import copy NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product NEW_LINE from bisect import bisect_left , bisect_right NEW_LINE def s_inpl ( ) : return map ( int , input ( ) . split ( ) ) NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE INF = float ( " inf " ) NEW_LINE N , K = s_inpl ( ) NEW_LINE T = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT row = inpl ( ) NEW_LINE T . append ( row ) NEW_LINE DEDENT flag = True NEW_LINE for row in product ( * T ) : NEW_LINE INDENT tmp = None NEW_LINE for i in row : NEW_LINE INDENT if tmp is None : NEW_LINE INDENT tmp = i NEW_LINE DEDENT else : NEW_LINE INDENT tmp = tmp ^ i NEW_LINE DEDENT DEDENT if tmp == 0 : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT print ( " Nothing " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Found " ) NEW_LINE DEDENT


n , k = map ( int , input ( ) . split ( ) ) NEW_LINE tAll = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT tmp = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE tAll . append ( tmp ) NEW_LINE DEDENT for i in range ( 5 - n ) : NEW_LINE INDENT tAll . append ( [ 0 ] * k ) NEW_LINE DEDENT ans = " Nothing " NEW_LINE for a in range ( k ) : NEW_LINE INDENT for b in range ( k ) : NEW_LINE INDENT for c in range ( k ) : NEW_LINE INDENT for d in range ( k ) : NEW_LINE INDENT for e in range ( k ) : NEW_LINE INDENT if tAll [ 0 ] [ a ] ^ tAll [ 1 ] [ b ] ^ tAll [ 2 ] [ c ] ^ tAll [ 3 ] [ d ] ^ tAll [ 4 ] [ e ] == 0 : NEW_LINE INDENT ans = " Found " NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE


import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE n , k = map ( int , input ( ) . split ( ) ) NEW_LINE t = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( n ) ] NEW_LINE def dfs ( q , x ) : NEW_LINE INDENT if q == n : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT for i in range ( k ) : NEW_LINE INDENT if dfs ( q + 1 , x ^ t [ q ] [ i ] ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT if dfs ( 0 , 0 ) : NEW_LINE INDENT print ( " Found " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Nothing " ) NEW_LINE DEDENT


def tobi ( string ) : NEW_LINE INDENT return format ( int ( string ) , "07b " ) NEW_LINE DEDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE T = [ list ( map ( tobi , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE flag = True NEW_LINE def bi5 ( inte , a , b ) : NEW_LINE INDENT ans = [ 0 ] * b NEW_LINE for i in range ( b - 1 , - 1 , - 1 ) : NEW_LINE INDENT if inte >= a ** i : NEW_LINE INDENT ans [ i ] = int ( inte / ( a ** i ) ) NEW_LINE inte = inte % a ** i NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT for i in range ( k ** n ) : NEW_LINE INDENT temp = [ 0 ] * 7 NEW_LINE for p , l in zip ( bi5 ( i , k , n ) , range ( n ) ) : NEW_LINE INDENT for t , m in zip ( T [ l ] [ p ] , range ( 7 ) ) : NEW_LINE INDENT temp [ m ] += int ( t ) NEW_LINE DEDENT DEDENT for j in range ( 7 ) : NEW_LINE INDENT temp [ j ] = temp [ j ] % 2 NEW_LINE DEDENT if sum ( temp ) == 0 : NEW_LINE INDENT print ( " Found " ) NEW_LINE flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT print ( " Nothing " ) NEW_LINE DEDENT


import java . util . stream . IntStream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; static int n , k , a [ ] [ ] ; public static void main ( String [ ] $ ) { n = scanner . nextInt ( ) ; k = scanner . nextInt ( ) ; a = IntStream . range ( 0 , n ) . mapToObj ( i -> IntStream . range ( 0 , k ) . map ( j -> scanner . nextInt ( ) ) . toArray ( ) ) . toArray ( int [ ] [ ] :: new ) ; System . out . println ( dfs ( 0 , 0 ) ? " Found " : " Nothing " ) ; } private static boolean dfs ( int d , int x ) { return d == n ? x == 0 : IntStream . range ( 0 , k ) . anyMatch ( i -> dfs ( d + 1 , x ^ a [ d ] [ i ] ) ) ; } }


import java . util . Arrays ; import java . util . Scanner ; public class Main { public boolean solve ( int n , int k , int [ ] [ ] ts ) { int [ ] selects = new int [ n ] ; Arrays . fill ( selects , 0 ) ; while ( true ) { int xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xor = xor ^ ts [ i ] [ selects [ i ] ] ; } if ( xor == 0 ) { return true ; } selects [ 0 ] ++ ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( selects [ i ] >= k ) { selects [ i ] = 0 ; selects [ i + 1 ] ++ ; } else { break ; } } if ( selects [ n - 1 ] >= k ) { break ; } } return false ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; int ts [ ] [ ] = new int [ n ] [ k ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < k ; j ++ ) { ts [ i ] [ j ] = in . nextInt ( ) ; } } in . close ( ) ; Main main = new Main ( ) ; boolean ret = main . solve ( n , k , ts ) ; if ( ret ) { System . out . println ( " Found " ) ; } else { System . out . println ( " Nothing " ) ; } } }


import java . util . Scanner ; public class Main { public static int N ; public static int K ; public static int [ ] [ ] T ; public static void main ( String [ ] args ) { readInput ( ) ; boolean hasBug = xor ( 0 , 0 , 0 ) ; if ( hasBug ) { System . out . println ( " Found " ) ; } else { System . out . println ( " Nothing " ) ; } } public static void readInput ( ) { try ( Scanner sc = new Scanner ( System . in ) ) { N = sc . nextInt ( ) ; K = sc . nextInt ( ) ; T = new int [ N + 1 ] [ K + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= K ; j ++ ) { T [ i ] [ j ] = sc . nextInt ( ) ; } } } } public static boolean xor ( int i , int j , int sum ) { if ( i > N ) { if ( sum == 0 ) { return true ; } else { return false ; } } sum ^= T [ i ] [ j ] ; boolean hasBug = false ; for ( int k = 1 ; k <= K ; k ++ ) { hasBug = hasBug || xor ( i + 1 , k , sum ) ; } return hasBug ; } }


import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] [ ] T = new int [ N ] [ K ] ; for ( int n = 0 ; n < N ; n ++ ) { for ( int k = 0 ; k < K ; k ++ ) { T [ n ] [ k ] = sc . nextInt ( ) ; } } if ( dfs ( T , N , K , 0 , - 1 ) ) { out . println ( " Found " ) ; } else { out . println ( " Nothing " ) ; } } public static boolean dfs ( int [ ] [ ] T , int N , int K , int n , int num ) { if ( n == 0 ) { for ( int k = 0 ; k < K ; k ++ ) { if ( dfs ( T , N , K , n + 1 , T [ n ] [ k ] ) ) { return true ; } } } else if ( n < N ) { for ( int k = 0 ; k < K ; k ++ ) { if ( dfs ( T , N , K , n + 1 , num ^ T [ n ] [ k ] ) ) { return true ; } } } else { if ( num == 0 ) { return true ; } } return false ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int x = 0 ; int y = 0 ; int uk = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . substring ( i , i + 1 ) ) { case " R " : x ++ ; break ; case " L " : x -- ; break ; case " D " : y -- ; break ; case " U " : y ++ ; break ; case " ? " : uk ++ ; break ; } } int ans = Math . abs ( x ) + Math . abs ( y ) ; int t = sc . nextInt ( ) ; if ( t == 1 ) System . out . println ( ans + uk ) ; else { if ( ans >= uk ) System . out . println ( ans - uk ) ; else System . out . println ( ( uk - ans ) % 2 ) ; } } }

import math NEW_LINE def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def zeros2 ( n , m ) : return [ zeros ( m ) for i in range ( n ) ] NEW_LINE class Debug ( ) : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . debug = True NEW_LINE DEDENT def off ( self ) : NEW_LINE INDENT self . debug = False NEW_LINE DEDENT def dmp ( self , x , cmt = ' ' ) : NEW_LINE INDENT if self . debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT w = cmt + ' : ▁ ' + str ( x ) NEW_LINE DEDENT else : NEW_LINE INDENT w = str ( x ) NEW_LINE DEDENT print ( w ) NEW_LINE DEDENT return x NEW_LINE DEDENT DEDENT def prob ( ) : NEW_LINE INDENT d = Debug ( ) NEW_LINE d . off ( ) NEW_LINE S = input ( ) NEW_LINE d . dmp ( ( S ) , ' S ' ) NEW_LINE T = getInt ( ) NEW_LINE d . dmp ( ( T ) , ' T ' ) NEW_LINE x , y , q = 0 , 0 , 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if S [ i ] == ' R ' : NEW_LINE INDENT x += 1 NEW_LINE DEDENT elif S [ i ] == ' L ' : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT elif S [ i ] == ' U ' : NEW_LINE INDENT y += 1 NEW_LINE DEDENT elif S [ i ] == ' D ' : NEW_LINE INDENT y -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT q += 1 NEW_LINE DEDENT DEDENT val = abs ( x ) + abs ( y ) NEW_LINE if T == 1 : NEW_LINE INDENT val += q NEW_LINE DEDENT else : NEW_LINE INDENT if val >= q : NEW_LINE INDENT val -= q NEW_LINE DEDENT else : NEW_LINE INDENT val = ( q - val ) % 2 NEW_LINE DEDENT DEDENT return val NEW_LINE DEDENT ans = prob ( ) NEW_LINE print ( ans ) NEW_LINE


s = input ( ) NEW_LINE x = abs ( s . count ( ' R ' ) - s . count ( ' L ' ) ) + abs ( s . count ( ' U ' ) - s . count ( ' D ' ) ) NEW_LINE c = s . count ( ' ? ' ) NEW_LINE if int ( input ( ) ) == 1 : NEW_LINE INDENT print ( x + c ) NEW_LINE DEDENT elif c <= x : NEW_LINE INDENT print ( x - c ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( x + c ) % 2 ) NEW_LINE DEDENT


s = list ( input ( ) ) NEW_LINE t = int ( input ( ) ) NEW_LINE x = 0 NEW_LINE y = 0 NEW_LINE d = 0 NEW_LINE count = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' L ' : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT elif s [ i ] == ' R ' : NEW_LINE INDENT x += 1 NEW_LINE DEDENT elif s [ i ] == ' U ' : NEW_LINE INDENT y += 1 NEW_LINE DEDENT elif s [ i ] == ' D ' : NEW_LINE INDENT y -= 1 NEW_LINE DEDENT elif s [ i ] == ' ? ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if t == 1 : NEW_LINE INDENT print ( max ( abs ( x + count ) + abs ( y ) , abs ( x ) + abs ( y + count ) , abs ( x - count ) + abs ( y ) , abs ( x ) + abs ( y - count ) ) ) NEW_LINE DEDENT elif t == 2 : NEW_LINE INDENT d = abs ( x ) + abs ( y ) NEW_LINE if d > count : NEW_LINE INDENT print ( d - count ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( d - count ) % 2 == 0 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT DEDENT DEDENT


def drone ( S : int , T : int ) -> int : NEW_LINE INDENT d = { ' L ' : 0 , ' R ' : 0 , ' U ' : 0 , ' D ' : 0 , ' ? ' : 0 } NEW_LINE for c in S : NEW_LINE INDENT d [ c ] += 1 NEW_LINE DEDENT dx = abs ( d [ ' L ' ] - d [ ' R ' ] ) NEW_LINE dy = abs ( d [ ' U ' ] - d [ ' D ' ] ) NEW_LINE if T == 1 : NEW_LINE INDENT return dx + dy + d [ ' ? ' ] NEW_LINE DEDENT min_d = dx + dy - d [ ' ? ' ] NEW_LINE if min_d >= 0 : NEW_LINE INDENT return min_d NEW_LINE DEDENT return ( - min_d ) % 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = input ( ) NEW_LINE T = int ( input ( ) ) NEW_LINE ans = drone ( S , T ) NEW_LINE print ( ans ) NEW_LINE DEDENT


s = list ( input ( ) ) NEW_LINE t = int ( input ( ) ) NEW_LINE c = [ 0 , 0 ] NEW_LINE for s_ in s : NEW_LINE INDENT if s_ == " L " : NEW_LINE INDENT c [ 0 ] += - 1 NEW_LINE DEDENT elif s_ == " R " : NEW_LINE INDENT c [ 0 ] += 1 NEW_LINE DEDENT elif s_ == " U " : NEW_LINE INDENT c [ 1 ] += 1 NEW_LINE DEDENT elif s_ == " D " : NEW_LINE INDENT c [ 1 ] += - 1 NEW_LINE DEDENT DEDENT ques = s . count ( " ? " ) NEW_LINE ans = abs ( c [ 0 ] ) + abs ( c [ 1 ] ) NEW_LINE if t == 1 : NEW_LINE INDENT ans += ques NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( ques ) : NEW_LINE INDENT if ans > 0 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT elif ans == 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; LightScanner in = new LightScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; B solver = new B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B { public void solve ( int testNumber , LightScanner in , PrintWriter out ) { String s = in . string ( ) ; int p = 0 ; int x = 0 , y = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' L ' : x -- ; break ; case ' R ' : x ++ ; break ; case ' U ' : y ++ ; break ; case ' D ' : y -- ; break ; case ' ? ' : p ++ ; break ; } } int t = in . ints ( ) ; int total = Math . abs ( x ) + Math . abs ( y ) ; if ( t == 2 ) { if ( total > p ) { out . println ( total - p ) ; } else { out . println ( ( p - total ) % 2 ) ; } } else { out . println ( total + p ) ; } } } static class LightScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public LightScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String string ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int ints ( ) { return Integer . parseInt ( string ( ) ) ; } } }


import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; int T = scanner . nextInt ( ) ; int x = 0 ; int y = 0 ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == ' L ' ) { x += - 1 ; } if ( S . charAt ( i ) == ' R ' ) { x += 1 ; } if ( S . charAt ( i ) == ' U ' ) { y += 1 ; } if ( S . charAt ( i ) == ' D ' ) { y += - 1 ; } if ( S . charAt ( i ) == ' ? ' ) { count ++ ; } } if ( T == 1 ) { System . out . println ( Math . abs ( x ) + Math . abs ( y ) + count ) ; } if ( T == 2 ) { if ( Math . abs ( x ) + Math . abs ( y ) - count >= 0 ) { System . out . println ( Math . abs ( x ) + Math . abs ( y ) - count ) ; } else if ( Math . abs ( x ) + Math . abs ( y ) - count < 0 && ( Math . abs ( x ) + Math . abs ( y ) ) % 2 == count % 2 ) { System . out . println ( 0 ) ; } else { System . out . println ( 1 ) ; } } } }


import java . util . * ; import java . lang . * ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int t = sc . nextInt ( ) ; int lr = 0 ; int ud = 0 ; int qc = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' L ' ) { lr -- ; } else if ( s . charAt ( i ) == ' R ' ) { lr ++ ; } else if ( s . charAt ( i ) == ' D ' ) { ud -- ; } else if ( s . charAt ( i ) == ' U ' ) { ud ++ ; } else { qc ++ ; } } if ( lr < 0 ) { lr = lr * ( - 1 ) ; } if ( ud < 0 ) { ud = ud * ( - 1 ) ; } if ( t == 1 ) { System . out . println ( lr + ud + qc ) ; } else { if ( qc >= lr + ud ) { System . out . println ( ( qc - ( lr + ud ) ) % 2 ) ; } else { System . out . println ( lr + ud - qc ) ; } } sc . close ( ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String po = sc . nextLine ( ) ; int n = sc . nextInt ( ) ; int count = 0 ; int x = 0 , y = 0 ; String s [ ] = po . split ( " " , 0 ) ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] . equals ( " U " ) ) y -- ; else if ( s [ i ] . equals ( " D " ) ) y ++ ; else if ( s [ i ] . equals ( " R " ) ) x ++ ; else if ( s [ i ] . equals ( " L " ) ) x -- ; else count ++ ; } int h = Math . abs ( x ) + Math . abs ( y ) ; System . out . println ( ( n == 1 ) ? h + count : ( h < count ) ? ( ( h - count ) % 2 == 0 ) ? 0 : 1 : h - count ) ; } }


import java . io . * ; import java . util . * ; public class Main { static final Reader in = new Reader ( ) ; static final long M = ( long ) 1e9 + 7 ; public static void main ( String [ ] args ) { int n = in . nextInt ( ) ; long [ ] ps = new long [ n + 1 ] ; long nf = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { ps [ i ] = ( ps [ i - 1 ] + in . nextInt ( ) ) % M ; nf = nf * i % M ; } long ans = nf * ps [ n ] % M , s = 0 ; for ( int i = 1 ; i <= n - 1 ; ++ i ) { s = ( s + ps [ n - i ] - ps [ i ] + M ) % M ; ans = ( ans + nf * modI ( ( long ) ( i + 1 ) * ( i >= n - 1 ? 1 : i + 2 ) , M ) % M * 2 * s + nf * modI ( i + 1 , M ) % M * ( ps [ i ] + ps [ n ] - ps [ n - i ] + M ) ) % M ; } System . out . println ( ans ) ; } static long modI ( long a , long m ) { return ( a %= m ) <= 1 ? 1 : ( 1 - modI ( m % a , a ) * m ) / a + m ; } static class Reader { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st ; String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) { } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE F = 1 NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT F = F * i % mod NEW_LINE DEDENT D = [ 0 ] NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT D . append ( D [ - 1 ] + pow ( i , mod - 2 , mod ) ) NEW_LINE DEDENT L = [ 0 ] * N NEW_LINE for i in range ( N // 2 + N % 2 ) : NEW_LINE INDENT t = round ( F * ( D [ - 1 - i ] + D [ i ] + 1 ) ) % mod NEW_LINE L [ i ] = t NEW_LINE L [ - 1 - i ] = t NEW_LINE DEDENT Ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT Ans += L [ i ] * A [ i ] % mod NEW_LINE DEDENT print ( Ans % mod ) NEW_LINE


import sys NEW_LINE fin = sys . stdin . readline NEW_LINE sys . setrecursionlimit ( 200000 ) NEW_LINE def factorial ( n , mod ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return n * factorial ( n - 1 , mod ) % mod NEW_LINE DEDENT DEDENT MOD = 10 ** 9 + 7 NEW_LINE N = int ( fin ( ) ) NEW_LINE A_list = [ int ( elem ) for elem in fin ( ) . split ( ) ] NEW_LINE fac_N = factorial ( N , MOD ) NEW_LINE inv_nums = [ fac_N * pow ( i , MOD - 2 , MOD ) % MOD for i in range ( 1 , N + 1 ) ] NEW_LINE cuml_inv_nums = [ inv_nums [ 0 ] ] NEW_LINE for inv_num in inv_nums [ 1 : ] : NEW_LINE INDENT cuml_inv_nums . append ( ( cuml_inv_nums [ - 1 ] + inv_num ) % MOD ) NEW_LINE DEDENT ans = 0 NEW_LINE for i , A in enumerate ( A_list ) : NEW_LINE INDENT ans += A * ( cuml_inv_nums [ i ] + cuml_inv_nums [ N - 1 - i ] - cuml_inv_nums [ 0 ] ) % MOD NEW_LINE ans %= MOD NEW_LINE DEDENT print ( ans ) NEW_LINE


def power ( a , b ) : NEW_LINE INDENT if b == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif b == 1 : NEW_LINE INDENT return a % 1000000007 NEW_LINE DEDENT elif b % 2 == 0 : NEW_LINE INDENT return ( power ( a , b // 2 ) ** 2 ) % 1000000007 NEW_LINE DEDENT else : NEW_LINE INDENT return ( power ( a , b // 2 ) ** 2 * a ) % 1000000007 NEW_LINE DEDENT DEDENT def divide ( a , b ) : NEW_LINE INDENT return ( a * power ( b , 1000000005 ) ) % 1000000007 NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE fac_lim = N NEW_LINE fac = [ None ] * ( fac_lim + 1 ) NEW_LINE fac [ 0 ] = 1 NEW_LINE for i in range ( fac_lim ) : NEW_LINE INDENT fac [ i + 1 ] = fac [ i ] * ( i + 1 ) NEW_LINE fac [ i + 1 ] = fac [ i + 1 ] % 1000000007 NEW_LINE DEDENT fs = [ 0 ] * ( N + 1 ) NEW_LINE fs [ 1 ] = fac [ N ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT fs [ i + 1 ] = fs [ i ] + divide ( fs [ 1 ] , i + 1 ) NEW_LINE fs [ i + 1 ] %= 1000000007 NEW_LINE DEDENT A = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT ans += ( fs [ i + 1 ] + fs [ N - i ] - fs [ 1 ] ) * A [ i ] NEW_LINE ans %= 1000000007 NEW_LINE DEDENT print ( ans ) NEW_LINE


def extgcd ( a , b ) : NEW_LINE INDENT r = [ 1 , 0 , a ] NEW_LINE w = [ 0 , 1 , b ] NEW_LINE while w [ 2 ] != 1 : NEW_LINE INDENT q = r [ 2 ] // w [ 2 ] NEW_LINE r2 = w NEW_LINE w2 = [ r [ 0 ] - q * w [ 0 ] , r [ 1 ] - q * w [ 1 ] , r [ 2 ] - q * w [ 2 ] ] NEW_LINE r = r2 NEW_LINE w = w2 NEW_LINE DEDENT return [ w [ 0 ] , w [ 1 ] ] NEW_LINE DEDENT def mod_inv ( a , m ) : NEW_LINE INDENT x = extgcd ( a , m ) [ 0 ] NEW_LINE return ( m + x % m ) % m NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE m = 10 ** 9 + 7 NEW_LINE r = [ 0 ] NEW_LINE w = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT w = ( w + mod_inv ( i , m ) ) % m NEW_LINE r . append ( w ) NEW_LINE DEDENT fact = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT fact = fact * i % m NEW_LINE DEDENT res = 0 NEW_LINE for j in range ( 1 , n + 1 ) : NEW_LINE INDENT sum_p = ( r [ j ] + r [ n - j + 1 ] - 1 ) % m NEW_LINE res = ( res + a [ j - 1 ] * sum_p * fact ) % m NEW_LINE DEDENT print ( res % m ) NEW_LINE


from math import factorial NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE invsum = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT invsum [ i ] = ( invsum [ i - 1 ] + pow ( i , MOD - 2 , MOD ) ) % MOD NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT ans += ( A [ i - 1 ] * ( invsum [ i ] + invsum [ N - i + 1 ] - 1 ) ) % MOD NEW_LINE DEDENT ans *= factorial ( N ) NEW_LINE print ( ans % MOD ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int mod = ( ( int ) 1e9 ) + 7 ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } long k = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { k *= i ; k %= mod ; } long [ ] r = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { r [ i ] = ( r [ i - 1 ] + mod_pow ( i , mod - 2 , mod ) ) % mod ; } long res = 0L ; for ( int i = 0 ; i < n ; i ++ ) { res += ( r [ i + 1 ] + r [ n - i ] - r [ 1 ] ) * a [ i ] ; res %= mod ; } System . out . println ( res * k % mod ) ; } public static long mod_pow ( long x , long p , long m ) { long a = 1 ; while ( p > 0 ) { if ( p % 2 == 1 ) { a = a * x % m ; } x = x * x % m ; p /= 2 ; } return a ; } }