id
stringlengths 13
20
| java
sequence | python
sequence |
---|---|---|
atcoder_abc013_C | [
"import java . util . Scanner ; public class Main { static long N , H , W , bmax , kingaku ; static long ayen , bup , cyen , dup , edown ; public static void main ( String [ ] args ) { scanning ( ) ; bup += edown ; dup += edown ; W = N * edown - H ; bmax = W / bup + 1 ; if ( W > 0 ) { long Wtemp ; kingaku = bmax * ayen ; for ( long i = 0 ; i < bmax ; i ++ ) { Wtemp = W - i * bup ; kingaku = min ( kingaku , i * ayen + ( Wtemp / dup + 1 ) * cyen ) ; } } System . out . println ( kingaku ) ; } public static void scanning ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; H = scan . nextInt ( ) ; ayen = scan . nextInt ( ) ; bup = scan . nextInt ( ) ; cyen = scan . nextInt ( ) ; dup = scan . nextInt ( ) ; edown = scan . nextInt ( ) ; scan . close ( ) ; } public static long min ( long x , long y ) { return x > y ? y : x ; } }",
"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 ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) , h = in . nextInt ( ) ; long a = in . nextLong ( ) , b = in . nextLong ( ) , c = in . nextLong ( ) , d = in . nextLong ( ) , e = in . nextLong ( ) ; long s = b + e , t = d + e , u = e * n - h ; long ans = Long . MAX_VALUE ; int y = 0 ; for ( int x = n ; x >= 0 ; x -- ) { while ( s * x + t * y <= u ) { y ++ ; } if ( x + y > n ) { break ; } ans = Math . min ( ans , a * x + c * y ) ; } out . println ( ans ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] $ ) { Scanner scanner = new Scanner ( System . in ) ; long n = scanner . nextInt ( ) , h = scanner . nextInt ( ) , a = scanner . nextInt ( ) , b = scanner . nextInt ( ) , c = scanner . nextInt ( ) , d = scanner . nextInt ( ) , e = scanner . nextInt ( ) ; java . util . stream . LongStream . rangeClosed ( 0 , n ) . map ( x -> a * x + c * ( ( - Math . min ( 0 , h - 1 + b * x - e * ( n - x ) ) + d + e - 1 ) / ( d + e ) ) ) . min ( ) . ifPresent ( System . out :: println ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { long n , a , b , c , d , e ; long h ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextLong ( ) ; h = sc . nextLong ( ) ; a = sc . nextLong ( ) ; b = sc . nextLong ( ) ; c = sc . nextLong ( ) ; d = sc . nextLong ( ) ; e = sc . nextLong ( ) ; solve ( ) ; } void solve ( ) { b += e ; d += e ; long diff = n * e - h ; long ans = Long . MAX_VALUE ; for ( int i = 0 ; i <= n ; i ++ ) { long tempDiff = diff - i * b ; long minJ = tempDiff / d + 1 ; if ( tempDiff < 0 ) { minJ = 0 ; } long tempAns = i * a + minJ * c ; if ( tempAns < ans ) { ans = tempAns ; } } System . out . println ( ans ) ; } 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 java . util . * ; import java . awt . * ; import java . awt . Graphics . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; long n = sc . nextLong ( ) ; long h = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; long e = sc . nextLong ( ) ; long ans = h - e * n > 0 ? 0 : Long . MAX_VALUE ; for ( long i = 0 ; i <= n ; i ++ ) { if ( n * e - h - ( b + e ) * i < 0 ) continue ; long j = ( n * e - h - ( b + e ) * i ) / ( d + e ) + 1l ; if ( j >= 0 ) ans = min ( ans , a * i + c * j ) ; } for ( long j = 0 ; j < n + 1 ; j ++ ) { if ( ( n * e - h - ( d + e ) * j ) < 0 ) continue ; long i = ( n * e - h - ( d + e ) * j ) / ( b + e ) + 1l ; if ( i >= 0 ) ans = min ( ans , a * i + c * j ) ; } for ( long i = 0 ; i < n + 1 ; i ++ ) { long f = h + i * b - ( n - i ) * e ; if ( f > 0 ) ans = min ( ans , a * i ) ; } for ( long i = 0 ; i < n + 1 ; i ++ ) { long f = h + i * d - ( n - i ) * e ; if ( f > 0 ) ans = min ( ans , c * i ) ; } out . println ( ans ) ; } }"
] | [
"n , h = map ( int , input ( ) . split ( ) ) NEW_LINE a , b , c , d , e = map ( int , input ( ) . split ( ) ) NEW_LINE ans = float ( \" inf \" ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT j = max ( 0 , ( ( n * e - h ) - ( b + e ) * i ) // ( d + e ) + 1 ) NEW_LINE cost = i * a + j * c NEW_LINE if ( 0 <= j <= n ) and ( ans > cost ) : NEW_LINE INDENT ans = cost NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"import sys NEW_LINE inp = sys . stdin . readline NEW_LINE N , H = map ( int , inp ( ) . split ( ) ) NEW_LINE A , B , C , D , E = map ( int , inp ( ) . split ( ) ) NEW_LINE h = H NEW_LINE K = N * E - H NEW_LINE B += E NEW_LINE D += E NEW_LINE if ( H - E * N > 0 ) : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT m = 10000000000000 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT if ( K - ( B * i ) <= 0 ) : NEW_LINE INDENT m = min ( m , ( A * i ) ) NEW_LINE DEDENT else : NEW_LINE INDENT m = min ( m , ( K - ( B * i ) ) // D * C + C + A * i ) NEW_LINE DEDENT DEDENT print ( m ) NEW_LINE DEDENT",
"import math NEW_LINE N , H = map ( int , input ( ) . split ( ) ) NEW_LINE A , B , C , D , E = map ( int , input ( ) . split ( ) ) NEW_LINE flag = False NEW_LINE ans = float ( ' inf ' ) NEW_LINE for x in range ( N ) : NEW_LINE INDENT ansx = - 1 NEW_LINE ansy = - 1 NEW_LINE y = math . ceil ( ( - ( B + E ) * x / ( D + E ) ) + ( ( E * N - H ) / ( D + E ) ) ) NEW_LINE if y != ( ( - ( B + E ) * x / ( D + E ) ) + ( ( E * N - H ) / ( D + E ) ) ) : NEW_LINE INDENT if y <= 0 : NEW_LINE INDENT ansy = 0 NEW_LINE ansx = x NEW_LINE DEDENT else : NEW_LINE INDENT if x + y <= N : NEW_LINE INDENT ansy = y NEW_LINE ansx = x NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT if y <= 0 : NEW_LINE INDENT ansy = 1 NEW_LINE ansx = x NEW_LINE DEDENT else : NEW_LINE INDENT if x + y <= N - 1 : NEW_LINE INDENT ansy = y + 1 NEW_LINE ansx = x NEW_LINE DEDENT DEDENT DEDENT if 0 <= ansx + ansy <= N and 0 <= ansx <= N and 0 <= ansy <= N : NEW_LINE INDENT if ans >= A * ansx + C * ansy : NEW_LINE INDENT ans = A * ansx + C * ansy NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE",
"import math NEW_LINE N , H = map ( int , input ( ) . split ( ) ) NEW_LINE A , B , C , D , E = map ( int , input ( ) . split ( ) ) NEW_LINE min = float ( ' inf ' ) NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT tmp1 = H + ( B + E ) * i - E * N NEW_LINE j = math . ceil ( - 1 * tmp1 / ( D + E ) ) NEW_LINE if j < 0 : NEW_LINE INDENT j = 0 NEW_LINE DEDENT if tmp1 + ( D + E ) * j == 0 : NEW_LINE INDENT j += 1 NEW_LINE DEDENT tmp2 = A * i + C * j NEW_LINE if tmp2 < min : NEW_LINE INDENT min = tmp2 NEW_LINE DEDENT if j == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( min ) NEW_LINE",
"N , H = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE A , B , C , D , E = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE min_cost = A * N NEW_LINE for i in range ( 0 , N + 1 ) : NEW_LINE INDENT j = max ( 0 , ( N * E - H - i * ( B + E ) ) // ( D + E ) + 1 ) NEW_LINE k = N - i - j NEW_LINE min_cost = min ( min_cost , A * i + C * j ) NEW_LINE DEDENT print ( min_cost ) NEW_LINE NEW_LINE"
] |
atcoder_abc044_A | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; if ( N >= K ) { System . out . println ( X * K + ( N - K ) * Y ) ; } else { System . out . println ( N * X ) ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . ArrayDeque ; import java . util . Queue ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int X = in . nextInt ( ) ; int Y = in . nextInt ( ) ; int total = 0 ; if ( N < K ) { for ( int i = 0 ; i < N ; i ++ ) { total += X ; } } else { for ( int i = 0 ; i < K ; i ++ ) { total += X ; } } for ( int i = 0 ; i < N - K ; i ++ ) { total += Y ; } out . println ( total ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int price = ( N <= K ) ? N * X : ( K * X ) + ( ( N - K ) * Y ) ; System . out . println ( price ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long y = sc . nextLong ( ) ; System . out . println ( Math . min ( n , k ) * x + Math . max ( n - k , 0 ) * y ) ; } }",
"import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) , k = sc . nextInt ( ) , x = sc . nextInt ( ) , y = sc . nextInt ( ) ; System . out . println ( Math . min ( n , k ) * x + Math . max ( n - k , 0 ) * y ) ; } }"
] | [
"N , K , X , Y = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE print ( K * X + ( N - K ) * Y if N > K else N * X ) NEW_LINE",
"def tak_and_hotels ( N : int , K : int , X : int , Y : int ) -> int : NEW_LINE INDENT return min ( N , K ) * X + max ( 0 , N - K ) * Y NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE K = int ( input ( ) ) NEW_LINE X = int ( input ( ) ) NEW_LINE Y = int ( input ( ) ) NEW_LINE ans = tak_and_hotels ( N , K , X , Y ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"n = int ( input ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE x = int ( input ( ) ) NEW_LINE y = int ( input ( ) ) NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i + 1 <= k : NEW_LINE INDENT sum += x NEW_LINE DEDENT else : NEW_LINE INDENT sum += y NEW_LINE DEDENT DEDENT print ( sum ) NEW_LINE",
"max = int ( input ( ) ) NEW_LINE sam = int ( input ( ) ) NEW_LINE sam_num = int ( input ( ) ) NEW_LINE sam_later = int ( input ( ) ) NEW_LINE if ( max < sam ) : NEW_LINE INDENT print ( sam_num * max ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( sam_num * sam + sam_later * ( max - sam ) ) NEW_LINE DEDENT",
"n , k , x , y = map ( int , open ( 0 ) ) ; print ( n * x - ( x - y ) * max ( n - k , 0 ) ) NEW_LINE"
] |
atcoder_arc093_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; System . out . println ( \"100 β 100\" ) ; boolean ans [ ] [ ] = new boolean [ 100 ] [ 100 ] ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { if ( i < 50 ) { ans [ i ] [ j ] = true ; } else { ans [ i ] [ j ] = false ; } } } for ( int i = 0 ; i < B - 1 ; i ++ ) { ans [ 2 * ( i / 50 ) ] [ 2 * ( i % 50 ) ] = false ; } for ( int i = 0 ; i < A - 1 ; i ++ ) { ans [ 2 * ( i / 50 ) + 51 ] [ 2 * ( i % 50 ) ] = true ; } for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { if ( ans [ i ] [ j ] ) { System . out . print ( ' . ' ) ; } else { System . out . print ( ' # ' ) ; } } System . out . println ( ) ; } } }",
"import java . util . * ; public class Main { public void main ( Scanner sc ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; char data [ ] [ ] = new char [ 100 ] [ 100 ] ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { data [ i ] [ j ] = ( i / 50 == 0 ? ' # ' : ' . ' ) ; } } for ( int i = 0 ; i < a - 1 ; i ++ ) { data [ 2 * ( i / 50 ) ] [ 2 * ( i % 50 ) ] = ' . ' ; } for ( int i = 0 ; i < b - 1 ; i ++ ) { data [ 2 * ( i / 50 ) + 51 ] [ 2 * ( i % 50 ) ] = ' # ' ; } System . out . println ( \"100 β 100\" ) ; for ( int i = 0 ; i < 100 ; i ++ ) { System . out . println ( new String ( data [ i ] ) ) ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . io . PrintStream ; 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 ) ; DGridComponents solver = new DGridComponents ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class DGridComponents { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int a = in . nextInt ( ) - 1 , b = in . nextInt ( ) - 1 ; System . out . println ( \"100 β 100\" ) ; for ( int y = 0 ; y < 49 ; y ++ ) { for ( int x = 0 ; x < 100 ; x ++ ) { if ( b > 0 && x % 2 == 0 && y % 2 == 0 ) { System . out . print ( ' # ' ) ; b -- ; } else { System . out . print ( ' . ' ) ; } } System . out . println ( ) ; } for ( int i = 0 ; i < 100 ; i ++ ) { System . out . print ( ' . ' ) ; } System . out . println ( ) ; for ( int i = 0 ; i < 100 ; i ++ ) { System . out . print ( ' # ' ) ; } System . out . println ( ) ; for ( int y = 51 ; y < 100 ; y ++ ) { for ( int x = 0 ; x < 100 ; x ++ ) { if ( a > 0 && x % 2 == 0 && y % 2 == 0 ) { System . out . print ( ' . ' ) ; a -- ; } else { System . out . print ( ' # ' ) ; } } System . out . println ( ) ; } } } }",
"import java . util . * ; class Main { static Scanner s = new Scanner ( System . in ) ; static char [ ] [ ] f = new char [ 40 ] [ 99 ] ; public static void main ( String [ ] $ ) { for ( int i = 0 ; i < 20 ; ++ i ) Arrays . fill ( f [ i ] , ' # ' ) ; for ( int i = 20 ; i < 40 ; ++ i ) Arrays . fill ( f [ i ] , ' . ' ) ; f ( 0 , ' . ' ) ; f ( 21 , ' # ' ) ; System . out . println ( \"40 β 99\" ) ; Arrays . stream ( f ) . forEach ( System . out :: println ) ; } static void f ( int b , char c ) { int a = s . nextInt ( ) - 1 ; for ( int i = 0 ; i < a ; ++ i ) f [ i / 50 * 2 + b ] [ i % 50 * 2 ] = c ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int numWhite = in . nextInt ( ) ; int numBlack = in . nextInt ( ) ; char WHITE = ' . ' ; char BLACK = ' # ' ; char [ ] [ ] map = new char [ 100 ] [ 100 ] ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { map [ i ] [ j ] = j <= 49 ? WHITE : BLACK ; } } int count = 1 ; for ( int i = 0 ; i < 100 ; i += 2 ) { for ( int j = 0 ; j <= 49 && count < numBlack ; j += 2 ) { map [ i ] [ j ] = BLACK ; count ++ ; } } count = 1 ; for ( int i = 0 ; i < 100 ; i += 2 ) { for ( int j = 51 ; j < 100 && count < numWhite ; j += 2 ) { map [ i ] [ j ] = WHITE ; count ++ ; } } System . out . println ( \"100 β 100\" ) ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { System . out . printf ( \" % c \" , map [ i ] [ j ] ) ; } System . out . println ( ) ; } } }"
] | [
"a , b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE g1 = [ [ \" # \" for i in range ( 100 ) ] for i in range ( 20 ) ] NEW_LINE g2 = [ [ \" . \" for i in range ( 100 ) ] for i in range ( 20 ) ] NEW_LINE a , b = a - 1 , b - 1 NEW_LINE j = 0 NEW_LINE while a != 0 : NEW_LINE INDENT for i in range ( 0 , 100 , 2 ) : NEW_LINE INDENT g1 [ j ] [ i ] = \" . \" NEW_LINE a -= 1 NEW_LINE if a == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT j += 2 NEW_LINE DEDENT j = 1 NEW_LINE while b != 0 : NEW_LINE INDENT for i in range ( 0 , 100 , 2 ) : NEW_LINE INDENT g2 [ j ] [ i ] = \" # \" NEW_LINE b -= 1 NEW_LINE if b == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT j += 2 NEW_LINE DEDENT g1 . extend ( g2 ) NEW_LINE print ( 40 , 100 ) NEW_LINE for ele in g1 : NEW_LINE INDENT print ( \" \" . join ( ele ) ) NEW_LINE DEDENT",
"def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE A , B = inpl ( ) NEW_LINE def nextin ( nwin ) : NEW_LINE INDENT nx , ny = nwin NEW_LINE if nx != 98 : NEW_LINE INDENT return ( nx + 2 , ny ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( 0 , ny + 2 ) NEW_LINE DEDENT DEDENT Wh = [ [ ' # ' for _ in range ( 100 ) ] for _ in range ( 50 ) ] NEW_LINE nowin = [ 0 , 0 ] NEW_LINE for _ in range ( A - 1 ) : NEW_LINE INDENT ix , iy = nowin NEW_LINE Wh [ iy ] [ ix ] = ' . ' NEW_LINE nowin = nextin ( nowin ) NEW_LINE DEDENT Bl = [ [ ' . ' for _ in range ( 100 ) ] for _ in range ( 50 ) ] NEW_LINE nowin = [ 0 , 1 ] NEW_LINE for _ in range ( B - 1 ) : NEW_LINE INDENT ix , iy = nowin NEW_LINE Bl [ iy ] [ ix ] = ' # ' NEW_LINE nowin = nextin ( nowin ) NEW_LINE DEDENT print ( '100' , '100' ) NEW_LINE for i in range ( 50 ) : NEW_LINE INDENT print ( ' ' . join ( Wh [ i ] ) ) NEW_LINE DEDENT for j in range ( 50 ) : NEW_LINE INDENT print ( ' ' . join ( Bl [ j ] ) ) NEW_LINE DEDENT",
"A , B = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE print ( 100 , 100 ) NEW_LINE x1 = ' ' . join ( [ ' . ' ] * 100 ) NEW_LINE y1 = ' ' . join ( [ ' # ' ] * 100 ) NEW_LINE for i in range ( 25 ) : NEW_LINE INDENT x = [ ' . ' ] * 100 NEW_LINE for j in range ( 50 ) : NEW_LINE INDENT if B > 1 : NEW_LINE INDENT x [ 2 * j ] = ' # ' NEW_LINE B -= 1 NEW_LINE DEDENT DEDENT print ( ' ' . join ( x ) ) NEW_LINE print ( x1 ) NEW_LINE DEDENT for i in range ( 25 ) : NEW_LINE INDENT print ( y1 ) NEW_LINE y = [ ' # ' ] * 100 NEW_LINE for j in range ( 50 ) : NEW_LINE INDENT if A > 1 : NEW_LINE INDENT y [ 2 * j ] = ' . ' NEW_LINE A -= 1 NEW_LINE DEDENT DEDENT print ( ' ' . join ( y ) ) NEW_LINE DEDENT",
"import string NEW_LINE import re NEW_LINE import datetime NEW_LINE import calendar NEW_LINE import collections NEW_LINE import heapq NEW_LINE import bisect NEW_LINE import array NEW_LINE import numpy as np NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE ans = np . empty ( ( 100 , 100 ) , dtype = int ) NEW_LINE x , y = ans . shape NEW_LINE for i in range ( x ) : NEW_LINE INDENT for j in range ( y ) : NEW_LINE INDENT if j == 0 : NEW_LINE INDENT ans [ i , j ] = 1 NEW_LINE DEDENT elif j == y - 1 : NEW_LINE INDENT ans [ i , j ] = 0 NEW_LINE DEDENT elif ( i % 4 ) == 0 or ( i % 4 ) == 1 : NEW_LINE INDENT ans [ i , j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans [ i , j ] = 0 NEW_LINE DEDENT DEDENT DEDENT def cut_b ( ) : NEW_LINE INDENT itr = 1 NEW_LINE for i in range ( 2 , x , 4 ) : NEW_LINE INDENT for j in range ( 2 , y // 2 , 2 ) : NEW_LINE INDENT yield itr NEW_LINE ans [ i , j ] = ans [ i + 1 , j ] = 1 NEW_LINE itr += 1 NEW_LINE DEDENT DEDENT DEDENT def cut_w ( ) : NEW_LINE INDENT itr = 1 NEW_LINE for i in range ( 0 , x , 4 ) : NEW_LINE INDENT for j in range ( - 3 , - y // 2 , - 2 ) : NEW_LINE INDENT yield itr NEW_LINE ans [ i , j ] = ans [ i + 1 , j ] = 0 NEW_LINE itr += 1 NEW_LINE DEDENT DEDENT DEDENT for i in cut_b ( ) : NEW_LINE INDENT if i == a : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT for i in cut_w ( ) : NEW_LINE INDENT if i == b : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( 100 , 100 ) NEW_LINE for i in range ( x ) : NEW_LINE INDENT for j in range ( y ) : NEW_LINE INDENT if ans [ i , j ] == 0 : NEW_LINE INDENT print ( ' . ' , end = \" \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' # ' , end = \" \" ) NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT",
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE grid = [ ] NEW_LINE for i in range ( 50 ) : NEW_LINE INDENT whiteline = [ \" . \" for k in range ( 100 ) ] NEW_LINE grid . append ( whiteline ) NEW_LINE DEDENT for i in range ( 50 ) : NEW_LINE INDENT blackline = [ \" # \" for k in range ( 100 ) ] NEW_LINE grid . append ( blackline ) NEW_LINE DEDENT b += - 1 NEW_LINE check = 1 NEW_LINE x = 1 NEW_LINE y = 1 NEW_LINE while b > 0 : NEW_LINE INDENT grid [ y ] [ x ] = \" # \" NEW_LINE b += - 1 NEW_LINE if x + 2 < 50 : NEW_LINE INDENT x += 2 NEW_LINE DEDENT else : NEW_LINE INDENT check = check * ( - 1 ) NEW_LINE if check == 1 : NEW_LINE INDENT x = 2 NEW_LINE DEDENT else : NEW_LINE INDENT x = 1 NEW_LINE DEDENT y += 2 NEW_LINE DEDENT DEDENT a += - 1 NEW_LINE check = 1 NEW_LINE x = 1 NEW_LINE y = 55 NEW_LINE while a > 0 : NEW_LINE INDENT grid [ y ] [ x ] = \" . \" NEW_LINE a += - 1 NEW_LINE if x + 2 < 50 : NEW_LINE INDENT x += 2 NEW_LINE DEDENT else : NEW_LINE INDENT check = check * ( - 1 ) NEW_LINE if check == 1 : NEW_LINE INDENT x = 2 NEW_LINE DEDENT else : NEW_LINE INDENT x = 1 NEW_LINE DEDENT y += 2 NEW_LINE DEDENT DEDENT print ( 100 , 100 ) NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT for k in range ( 100 ) : NEW_LINE INDENT if k != 99 : NEW_LINE INDENT print ( grid [ i ] [ k ] , end = \" \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( grid [ i ] [ k ] ) NEW_LINE DEDENT DEDENT DEDENT"
] |
atcoder_abc057_D | [
"import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; long [ ] t = new long [ n ] ; long r = 0 ; long p1 = 0 ; long p2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long v = sc . nextLong ( ) ; t [ i ] = v ; } Arrays . sort ( t ) ; double ans1 = 0 ; long ans2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i <= a - 1 ) { ans1 += t [ n - 1 - i ] ; } if ( r == t [ n - 1 - i ] ) { p1 ++ ; } else { if ( i <= a - 1 ) { r = t [ n - 1 - i ] ; p1 = 1 ; } else { break ; } } if ( i == a - 1 ) { p2 = p1 ; } } if ( p2 != a ) { if ( ( ( ans1 - r * p2 ) / ( a - p2 ) ) == r ) { for ( long i = p2 ; i <= Math . min ( b - a + p2 , p1 ) ; i ++ ) { ans2 += c ( p1 , i ) ; } } else { ans2 += c ( p1 , p2 ) ; } } else { for ( long i = p2 ; i <= Math . min ( b - a + p2 , p1 ) ; i ++ ) { ans2 += c ( p1 , i ) ; } } System . out . println ( ans1 / a ) ; System . out . println ( ans2 ) ; } public static long c ( long o , long l ) { long ans = 1 ; for ( long i = 1 ; i <= l ; i ++ ) { ans *= o - i + 1 ; ans /= i ; } return ans ; } }",
"import java . util . * ; import java . util . Map . * ; public class Main { static int MAX = 50 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; long [ ] [ ] c = comb ( n ) ; List < Long > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { v . add ( sc . nextLong ( ) ) ; } Collections . sort ( v , Comparator . reverseOrder ( ) ) ; long sum = 0 ; for ( int i = 0 ; i < a ; i ++ ) { sum += v . get ( i ) ; } double ave = ( double ) sum / a ; int aInCnt = 0 ; int aCnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( v . get ( i ) . equals ( v . get ( a - 1 ) ) ) { aCnt ++ ; if ( i < a ) { aInCnt ++ ; } } } long ans = 0 ; if ( v . get ( 0 ) . equals ( v . get ( a - 1 ) ) ) { for ( int i = a ; i <= b ; i ++ ) { ans += c [ aCnt ] [ i ] ; } } else { ans += c [ aCnt ] [ aInCnt ] ; } System . out . println ( String . format ( \" % .6f \" , ave ) ) ; System . out . println ( ans ) ; } public static long [ ] [ ] comb ( long n ) { long [ ] [ ] c = new long [ MAX + 1 ] [ MAX + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( j == 0 || i == j ) { c [ i ] [ j ] = 1L ; continue ; } c [ i ] [ j ] = c [ i - 1 ] [ j - 1 ] + c [ i - 1 ] [ j ] ; } } return c ; } }",
"import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; long [ ] nums = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextLong ( ) ; } Arrays . sort ( nums ) ; double sum = 0 ; int [ ] occurs = new int [ a ] ; long count = 0 ; for ( int i = n - 1 ; i >= n - a ; i -- ) { sum += nums [ i ] ; } sum /= a ; boolean flag = true ; int index = - 1 ; if ( nums [ n - 1 ] != nums [ n - a ] ) { int counts = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( nums [ i ] == nums [ n - a ] ) { if ( flag ) { index = i + 1 ; flag = false ; } counts ++ ; } } count = combinations ( counts , a - ( n - index ) ) ; } else { int l = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( nums [ i ] == nums [ n - 1 ] ) { l ++ ; } } for ( int i = a ; i <= b ; i ++ ) { if ( nums [ n - 1 ] == nums [ n - i ] ) { count += combinations ( l , i ) ; } } } System . out . println ( sum ) ; System . out . println ( count ) ; } private static long combinations ( int n , int k ) { long ans = 1 ; for ( int i = 1 ; i <= k ; i ++ ) { ans *= n - k + i ; ans /= i ; } return ans ; } }",
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; long [ ] [ ] nCr = new long [ N + 1 ] [ N + 1 ] ; nCr [ 0 ] [ 0 ] = 0 ; for ( int row = 1 ; row <= N ; row ++ ) { nCr [ row ] [ 0 ] = 1 ; for ( int col = 1 ; col <= row - 1 ; col ++ ) { nCr [ row ] [ col ] = nCr [ row - 1 ] [ col - 1 ] + nCr [ row - 1 ] [ col ] ; } nCr [ row ] [ row ] = 1 ; } long [ ] v = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { v [ i ] = sc . nextLong ( ) ; } Arrays . sort ( v ) ; long sum1 = 0 ; for ( int i = N - 1 ; i >= N - A ; i -- ) { sum1 += v [ i ] ; } double ans1 = sum1 / ( ( double ) A ) ; int cnt1 = 0 ; int cnt2 = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( v [ i ] > v [ N - A ] ) cnt1 ++ ; if ( v [ i ] == v [ N - A ] ) cnt2 ++ ; } long ans2 = 0 ; if ( v [ N - A ] < v [ N - 1 ] ) { ans2 = nCr [ cnt2 ] [ A - cnt1 ] ; } else { for ( int i = A ; i <= Math . min ( B , cnt2 ) ; i ++ ) { ans2 += nCr [ cnt2 ] [ i ] ; } } System . out . println ( ans1 ) ; System . out . println ( ans2 ) ; } }",
"import java . math . * ; import java . util . * ; class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = s . nextInt ( ) , a = s . nextInt ( ) , b = s . nextInt ( ) ; long [ ] v = new long [ n ] ; Arrays . setAll ( v , i -> s . nextLong ( ) ) ; Arrays . sort ( v ) ; long sum = 0 ; int use = 0 , count = 0 ; for ( int i = n - a ; i < n ; ++ i ) { if ( v [ n - a ] == v [ i ] ) { ++ use ; ++ count ; } sum += v [ i ] ; } System . out . println ( BigDecimal . valueOf ( sum * 1.0 / a ) . toPlainString ( ) ) ; for ( int i = 0 ; i < n - a ; ++ i ) if ( v [ n - a ] == v [ i ] ) ++ count ; System . err . println ( count + \" β \" + use ) ; if ( v [ n - a ] == v [ n - 1 ] ) { long r = 0 ; for ( int i = 0 , e = Math . min ( b - a , count - use ) ; i <= e ; ++ i ) r += comb ( count , use + i ) ; System . out . println ( r ) ; } else { System . out . println ( comb ( count , use ) ) ; } } static long comb ( int count , int use ) { long r = 1 ; for ( int i = use + 1 ; i <= count ; ++ i ) { r *= i ; r /= i - use ; } return r ; } }"
] | [
"d = { } NEW_LINE def nCr ( n , r ) : NEW_LINE INDENT if n < r : NEW_LINE INDENT return 0 NEW_LINE DEDENT if n == r or r == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( n , r ) in d : NEW_LINE INDENT return d [ ( n , r ) ] NEW_LINE DEDENT d [ ( n , r ) ] = nCr ( n - 1 , r ) + nCr ( n - 1 , r - 1 ) NEW_LINE return d [ ( n , r ) ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n , a , b = map ( int , input ( ) . split ( ) ) NEW_LINE v = sorted ( ( int ( s ) for s in input ( ) . split ( ) ) , reverse = True ) NEW_LINE print ( sum ( v [ : a ] ) / a ) NEW_LINE x = v . count ( v [ a - 1 ] ) NEW_LINE print ( nCr ( x , v [ : a ] . count ( v [ a - 1 ] ) ) if v [ 0 ] > v [ a - 1 ] else sum ( nCr ( x , i ) for i in range ( a , b + 1 ) ) ) NEW_LINE DEDENT",
"def comb ( n , r ) : NEW_LINE INDENT r = min ( r , n - r ) NEW_LINE result = 1 NEW_LINE for i in range ( n - r + 1 , n + 1 ) : NEW_LINE INDENT result *= i NEW_LINE DEDENT for i in range ( 1 , r + 1 ) : NEW_LINE INDENT result //= i NEW_LINE DEDENT return result NEW_LINE DEDENT N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE V = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE V . sort ( reverse = True ) NEW_LINE ave = sum ( V [ : A ] ) / A NEW_LINE pat = 0 NEW_LINE note = 0 NEW_LINE cnt = 0 NEW_LINE for v in V : NEW_LINE INDENT if v > V [ A - 1 ] : NEW_LINE INDENT note += 1 NEW_LINE DEDENT elif v == V [ A - 1 ] : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT elif v < V [ A - 1 ] : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if V [ 0 ] == V [ A - 1 ] : NEW_LINE INDENT for i in range ( A - note , B + 1 - note ) : NEW_LINE INDENT if i > cnt : NEW_LINE INDENT break NEW_LINE DEDENT pat += comb ( cnt , i ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT pat = comb ( cnt , A - note ) NEW_LINE DEDENT print ( ave ) NEW_LINE print ( pat ) NEW_LINE",
"import sys NEW_LINE from collections import Counter NEW_LINE try : NEW_LINE INDENT from scipy . special import comb NEW_LINE DEDENT except ImportError : NEW_LINE INDENT from scipy . misc import comb NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT input = sys . stdin . readline NEW_LINE N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE V = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE V = sorted ( V , key = lambda x : - x ) NEW_LINE m_ave = sum ( V [ : A ] ) / A NEW_LINE b = A NEW_LINE while b < B : NEW_LINE INDENT if V [ 0 ] == V [ b ] : NEW_LINE INDENT b += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if A == b : NEW_LINE INDENT ans = 1 NEW_LINE c = Counter ( V [ : A ] ) NEW_LINE d = Counter ( V ) NEW_LINE for key in c . keys ( ) : NEW_LINE INDENT n = d [ key ] NEW_LINE r = c [ key ] NEW_LINE ans *= comb ( n , r , exact = True ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT d = Counter ( V ) NEW_LINE key = V [ 0 ] NEW_LINE n = d [ key ] NEW_LINE ans = 0 NEW_LINE for r in range ( A , b + 1 ) : NEW_LINE INDENT ans += comb ( n , r , exact = True ) NEW_LINE DEDENT DEDENT print ( m_ave ) NEW_LINE print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"import math NEW_LINE N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE V = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE V . sort ( ) NEW_LINE V . reverse ( ) NEW_LINE cur = 0 NEW_LINE selectlist = [ ] NEW_LINE for i in range ( A , B + 1 ) : NEW_LINE INDENT S = 0 NEW_LINE for j in range ( i ) : NEW_LINE INDENT S += V [ j ] NEW_LINE DEDENT S = S / i NEW_LINE if cur < S : NEW_LINE INDENT cur = S NEW_LINE selectlist = [ i ] NEW_LINE DEDENT elif cur == S : NEW_LINE INDENT selectlist . append ( i ) NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for p in range ( len ( selectlist ) ) : NEW_LINE INDENT nowselect = 1 NEW_LINE s = 0 NEW_LINE K = [ ] NEW_LINE for i in range ( selectlist [ p ] ) : NEW_LINE INDENT K . append ( V [ i ] ) NEW_LINE DEDENT P = list ( set ( K ) ) NEW_LINE P . sort ( ) NEW_LINE P . reverse ( ) NEW_LINE for j in range ( len ( P ) ) : NEW_LINE INDENT cnt = V . count ( P [ j ] ) NEW_LINE s += cnt NEW_LINE if s >= selectlist [ p ] : NEW_LINE INDENT res = K . count ( P [ j ] ) NEW_LINE nowselect *= math . factorial ( cnt ) // ( math . factorial ( res ) * math . factorial ( cnt - res ) ) NEW_LINE ans += nowselect NEW_LINE DEDENT else : NEW_LINE INDENT nowselect *= cnt NEW_LINE DEDENT DEDENT DEDENT print ( cur ) NEW_LINE print ( ans ) NEW_LINE",
"import itertools NEW_LINE import sys NEW_LINE import math NEW_LINE from functools import lru_cache NEW_LINE from queue import Queue NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE nCr = { } NEW_LINE def cmb ( n , r ) : NEW_LINE INDENT if r == 0 or r == n : return 1 NEW_LINE if r == 1 : return n NEW_LINE if ( n , r ) in nCr : return nCr [ ( n , r ) ] NEW_LINE nCr [ ( n , r ) ] = cmb ( n - 1 , r ) + cmb ( n - 1 , r - 1 ) NEW_LINE return nCr [ ( n , r ) ] NEW_LINE DEDENT n , a , b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE value = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE value = list ( reversed ( sorted ( value ) ) ) NEW_LINE takai = 0 NEW_LINE avg = 0 NEW_LINE for i in range ( a ) : NEW_LINE INDENT if value [ i ] > value [ a ] : NEW_LINE INDENT takai += 1 NEW_LINE DEDENT avg += value [ i ] NEW_LINE DEDENT avg /= a NEW_LINE print ( avg ) NEW_LINE cc = value . count ( value [ a ] ) NEW_LINE if value [ 0 ] == value [ a ] : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( a , min ( cc , b ) + 1 ) : NEW_LINE INDENT sum += cmb ( cc , i ) NEW_LINE DEDENT print ( sum ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( cmb ( cc , a - takai ) ) NEW_LINE NEW_LINE DEDENT"
] |
atcoder_abc062_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; String a [ ] = new String [ h ] ; for ( int i = 0 ; i < h ; i ++ ) { a [ i ] = sc . next ( ) ; } for ( int i = 0 ; i < w + 2 ; i ++ ) { System . out . print ( \" # \" ) ; } System . out . println ( \" \" ) ; for ( int i = 0 ; i < h ; i ++ ) { System . out . println ( \" # \" + a [ i ] + \" # \" ) ; } for ( int i = 0 ; i < w + 2 ; i ++ ) { System . out . print ( \" # \" ) ; } System . out . println ( \" \" ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int H = in . nextInt ( ) ; int W = in . nextInt ( ) ; String [ ] array = new String [ H ] ; for ( int i = 0 ; i < array . length ; i ++ ) { array [ i ] = \" # \" + in . next ( ) + \" # \" ; } String repeated = new String ( new char [ W + 2 ] ) . replace ( \" \\0\" , \" # \" ) ; out . println ( repeated ) ; for ( int i = 0 ; i < array . length ; i ++ ) { out . println ( array [ i ] ) ; } out . println ( repeated ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }",
"import java . io . IOException ; import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; char a [ ] [ ] = new char [ 102 ] [ 102 ] ; String str = \" \" ; for ( int i = 0 ; i < h + 2 ; i ++ ) { if ( i != 0 && i != h + 1 ) { str = sc . next ( ) ; } for ( int j = 0 ; j < w + 2 ; j ++ ) { if ( i == 0 || i == h + 1 || j == 0 || j == w + 1 ) a [ i ] [ j ] = ' # ' ; else a [ i ] [ j ] = str . charAt ( j - 1 ) ; } } for ( int i = 0 ; i < h + 2 ; i ++ ) { for ( int j = 0 ; j < w + 2 ; j ++ ) { System . out . print ( a [ i ] [ j ] ) ; if ( j == w + 1 ) System . out . println ( ) ; } } } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int x = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int y = Integer . parseInt ( tokenizer . nextToken ( ) ) ; StringBuilder firstAndLast = new StringBuilder ( ) ; for ( int i = 0 ; i < y + 2 ; i ++ ) { firstAndLast . append ( ' # ' ) ; } StringBuilder out = new StringBuilder ( ) ; out . append ( firstAndLast ) . append ( ' \\n ' ) ; for ( int i = 0 ; i < x ; i ++ ) { out . append ( ' # ' ) . append ( input . readLine ( ) ) . append ( ' # ' ) . append ( ' \\n ' ) ; } out . append ( firstAndLast ) . append ( ' \\n ' ) ; System . out . print ( out ) ; } }",
"import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int mod = 1000000007 ; public static void main ( String [ ] args ) { int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; String [ ] ar = new String [ h ] ; for ( int i = 0 ; i < h ; i ++ ) { ar [ i ] = \" # \" + sc . next ( ) + \" # \" ; } for ( int i = 0 ; i < w + 2 ; i ++ ) { System . out . print ( \" # \" ) ; } System . out . println ( ) ; for ( int i = 0 ; i < h ; i ++ ) { System . out . println ( ar [ i ] ) ; } for ( int i = 0 ; i < w + 2 ; i ++ ) { System . out . print ( \" # \" ) ; } System . out . println ( ) ; } }"
] | [
"H , W = map ( int , input ( ) . split ( ) ) NEW_LINE print ( \" # \" * ( W + 2 ) ) NEW_LINE for i in range ( 0 , H ) : NEW_LINE INDENT print ( \" # \" + input ( ) + \" # \" ) NEW_LINE DEDENT print ( \" # \" * ( W + 2 ) ) NEW_LINE",
"import sys NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE h , w = nm ( ) NEW_LINE a = [ [ ' # ' ] + list ( map ( str , sys . stdin . readline ( ) . split ( ) ) ) + [ ' # ' ] for _ in range ( h ) ] NEW_LINE a . insert ( 0 , [ ' # ' for _ in range ( w + 2 ) ] ) NEW_LINE a . append ( [ ' # ' for _ in range ( w + 2 ) ] ) NEW_LINE for i in range ( h + 2 ) : NEW_LINE INDENT print ( ' ' . join ( a [ i ] ) ) NEW_LINE DEDENT",
"H , W = map ( int , input ( ) . split ( ) ) NEW_LINE joubu = [ \" # \" for i in range ( W + 2 ) ] NEW_LINE print ( \" \" . join ( joubu ) ) NEW_LINE for i in range ( H ) : NEW_LINE INDENT S = input ( ) NEW_LINE print ( \" # \" + S + \" # \" ) NEW_LINE DEDENT print ( \" \" . join ( joubu ) ) NEW_LINE",
"h , w = map ( int , input ( ) . split ( ) ) NEW_LINE ans = [ [ \" # \" for i in range ( w + 2 ) ] for i in range ( h + 2 ) ] NEW_LINE a = [ input ( ) for i in range ( h ) ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT for j in range ( w ) : NEW_LINE INDENT ans [ i + 1 ] [ j + 1 ] = a [ i ] [ j ] NEW_LINE DEDENT DEDENT for i in range ( h + 2 ) : NEW_LINE INDENT for j in range ( w + 2 ) : NEW_LINE INDENT print ( ans [ i ] [ j ] , end = \" \" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT",
"import sys NEW_LINE def main ( ) : NEW_LINE INDENT input = sys . stdin . readline NEW_LINE H , W = map ( int , input ( ) . split ( ) ) NEW_LINE ud = ' # ' * ( W + 2 ) NEW_LINE print ( ud ) NEW_LINE for _ in range ( H ) : NEW_LINE INDENT a = input ( ) . strip ( ) NEW_LINE print ( ' # ' + a + ' # ' ) NEW_LINE DEDENT print ( ud ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT"
] |
atcoder_abc019_B | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; int count = 1 ; char now = s [ 0 ] ; String ans = \" \" ; for ( int i = 1 ; i < s . length ; i ++ ) { if ( now == s [ i ] ) { count ++ ; } else { ans += now + \" \" + count ; now = s [ i ] ; count = 1 ; } } ans += now + \" \" + count ; System . out . println ( ans ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String s = in . next ( ) ; int count = 1 ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i - 1 ) ) { count ++ ; } else { out . print ( ( char ) ( s . charAt ( i - 1 ) ) ) ; out . print ( count ) ; count = 1 ; } } out . print ( s . charAt ( s . length ( ) - 1 ) ) ; out . println ( count ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }",
"import java . util . * ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; Pattern p = Pattern . compile ( \" ( . ) \\\\ 1 { 0 , } \" ) ; Matcher m = p . matcher ( s ) ; while ( m . find ( ) ) { System . out . print ( m . group ( 0 ) . charAt ( 0 ) ) ; System . out . print ( m . group ( 0 ) . length ( ) ) ; } System . out . println ( ) ; } }",
"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 ( ) + \" β \" ; String t = \" \" ; int count = 0 ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { count ++ ; if ( s . charAt ( i ) != s . charAt ( i - 1 ) ) { t += String . valueOf ( s . charAt ( i - 1 ) ) ; t += String . valueOf ( count ) ; count = 0 ; } } System . out . println ( t ) ; } }",
"import java . util . * ; class Main { public static void main ( String [ ] args ) { new Main ( ) . main ( ) ; } public void main ( ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; int i = 0 ; StringBuilder builder = new StringBuilder ( ) ; while ( i < s . length ( ) ) { char ch = s . charAt ( i ) ; int count = this . countChar ( s . substring ( i , s . length ( ) ) , ch ) ; builder . append ( String . format ( \" % c % d \" , ch , count ) ) ; i += count ; } System . out . println ( builder . toString ( ) ) ; } private int countChar ( String s , char ch ) { int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ch ) { count ++ ; } else { break ; } } return count ; } }"
] | [
"s = list ( input ( ) ) NEW_LINE s . append ( \" β \" ) NEW_LINE i = 0 NEW_LINE am = 1 NEW_LINE while i < len ( s ) - 1 : NEW_LINE INDENT if s [ i ] == s [ i + 1 ] : NEW_LINE INDENT am += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ i ] + str ( am ) , end = \" \" ) NEW_LINE am = 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT print ( ) NEW_LINE",
"hoge = input ( ) NEW_LINE mae = \" β \" NEW_LINE kazu = 0 NEW_LINE flag = 0 NEW_LINE for i in range ( len ( hoge ) ) : NEW_LINE INDENT moji = hoge [ i ] NEW_LINE if ( moji == mae ) : NEW_LINE INDENT kazu += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( flag == 0 ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( kazu , end = \" \" ) NEW_LINE DEDENT print ( moji , end = \" \" ) NEW_LINE kazu = 1 NEW_LINE DEDENT mae = hoge [ i ] NEW_LINE DEDENT print ( kazu , end = \" \" ) NEW_LINE print ( \" \" ) NEW_LINE",
"s = input ( ) NEW_LINE pre = \" \" NEW_LINE cnt = 0 NEW_LINE res = \" \" NEW_LINE for x in s : NEW_LINE INDENT if x != pre : NEW_LINE INDENT if pre != \" \" : NEW_LINE INDENT res += pre + str ( cnt ) NEW_LINE DEDENT pre = x NEW_LINE cnt = 1 NEW_LINE DEDENT else : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT res += pre + str ( cnt ) NEW_LINE print ( res ) NEW_LINE",
"Ss = [ i for i in input ( ) ] NEW_LINE chars = [ ] NEW_LINE char = [ Ss [ 0 ] ] NEW_LINE for s in range ( 1 , len ( Ss ) ) : NEW_LINE INDENT if Ss [ s ] in char : NEW_LINE INDENT char . append ( Ss [ s ] ) NEW_LINE DEDENT else : NEW_LINE INDENT chars . append ( char ) NEW_LINE char = [ Ss [ s ] ] NEW_LINE DEDENT DEDENT chars . append ( char ) NEW_LINE ans = [ char [ 0 ] + str ( len ( char ) ) for char in chars ] NEW_LINE print ( \" \" . join ( ans ) ) NEW_LINE",
"def solve ( ) : NEW_LINE INDENT s = input ( ) NEW_LINE n = len ( s ) NEW_LINE ans = \" \" NEW_LINE ct = 1 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ans == \" \" : NEW_LINE INDENT ans += s [ i ] NEW_LINE ct = 1 NEW_LINE DEDENT elif ans [ - 1 ] == s [ i ] : NEW_LINE INDENT ct += 1 NEW_LINE DEDENT elif ans [ - 1 ] != s [ i ] : NEW_LINE INDENT ans += str ( ct ) NEW_LINE ans += s [ i ] NEW_LINE ct = 1 NEW_LINE DEDENT DEDENT ans += str ( ct ) NEW_LINE print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE"
] |
atcoder_abc030_D | [
"import java . math . BigInteger ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; int a = sc . nextInt ( ) - 1 ; BigInteger k = new BigInteger ( sc . next ( ) ) ; int [ ] b = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) b [ i ] = sc . nextInt ( ) - 1 ; sc . close ( ) ; int count = 1 ; int current = b [ a ] ; int [ ] dpCount = new int [ N ] ; int [ ] dpPos = new int [ N + 1 ] ; while ( dpCount [ current ] == 0 ) { dpCount [ current ] = count ; dpPos [ count ] = current ; current = b [ current ] ; count ++ ; } int startRoop = dpCount [ current ] ; BigInteger rk = k . subtract ( BigInteger . valueOf ( startRoop ) ) ; int ans = 0 ; if ( rk . max ( BigInteger . ZERO ) . equals ( BigInteger . ZERO ) ) { ans = dpPos [ k . intValue ( ) ] ; } else { ans = dpPos [ startRoop + rk . mod ( BigInteger . valueOf ( count - startRoop ) ) . intValue ( ) ] ; } System . out . println ( ans + 1 ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; String k = sc . next ( ) ; long [ ] b = new long [ ( int ) N ] ; for ( int i = 0 ; i < N ; i ++ ) { b [ i ] = sc . nextLong ( ) ; } ArrayList < Long > f = new ArrayList < Long > ( ) ; f . add ( a ) ; long presence = a ; long s = 0 ; long g = 1 ; for ( int i = 0 ; i < N ; i ++ ) { presence = b [ ( int ) presence - 1 ] ; if ( f . contains ( presence ) ) { for ( int j = 0 ; j < N ; j ++ ) { if ( f . get ( j ) == presence ) { s = ( long ) j ; g = ( long ) ( i + 1 ) - s ; break ; } } break ; } else { f . add ( presence ) ; } } long ans = 0 ; if ( k . length ( ) <= 6 ) { int step = Integer . parseInt ( k ) ; int p = ( int ) a ; for ( int i = 0 ; i < step ; i ++ ) { p = ( int ) b [ p - 1 ] ; } ans = p ; } else { long r = 0 ; if ( k . length ( ) <= 18 ) { r = ( Long . parseLong ( k ) ) % g ; } else { for ( int i = 0 ; i < k . length ( ) ; i ++ ) { long d = Long . parseLong ( String . valueOf ( k . charAt ( i ) ) ) ; r = ( 10 * r + d ) % g ; } } while ( r < s ) { r += g ; } ans = f . get ( ( int ) r ) ; } System . out . println ( ans ) ; } }",
"import java . math . BigInteger ; import java . util . Scanner ; public class Main { private static final BigInteger TWO = BigInteger . valueOf ( 2 ) ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int a = scanner . nextInt ( ) - 1 ; BigInteger k = scanner . nextBigInteger ( ) ; int [ ] b = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) b [ i ] = scanner . nextInt ( ) - 1 ; int n = 0 ; int i1 = a ; int i2 = a ; do { i1 = b [ i1 ] ; i2 = b [ b [ i2 ] ] ; n ++ ; } while ( i1 != i2 ) ; int m = 0 ; int i3 = a ; while ( i1 != i3 ) { i1 = b [ i1 ] ; i3 = b [ i3 ] ; m ++ ; } int l ; if ( k . compareTo ( BigInteger . valueOf ( m ) ) < 0 ) { l = k . intValue ( ) ; } else { l = m + k . subtract ( BigInteger . valueOf ( m ) ) . mod ( BigInteger . valueOf ( n ) ) . intValue ( ) ; } while ( l > 0 ) { a = b [ a ] ; l -- ; } System . out . println ( a + 1 ) ; } }"
] | [
"n , a = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE b = list ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE hist = [ ] NEW_LINE while a not in hist : NEW_LINE INDENT hist . append ( a ) NEW_LINE a = b [ a - 1 ] NEW_LINE DEDENT init = hist [ 0 : hist . index ( a ) ] NEW_LINE loop = hist [ hist . index ( a ) : ] NEW_LINE if k < len ( init ) : NEW_LINE INDENT print ( init [ k ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( loop [ ( k - len ( init ) ) % len ( loop ) ] ) NEW_LINE DEDENT",
"def mod ( k : int , c : int ) -> int : NEW_LINE INDENT ret = 0 NEW_LINE for n in str ( k ) : NEW_LINE INDENT ret = ( ret * 10 + int ( n ) ) % c NEW_LINE DEDENT return ret NEW_LINE DEDENT def strange_dict ( N : int , a : int , k : int , B : list ) -> int : NEW_LINE INDENT route = [ ] NEW_LINE idx = a - 1 NEW_LINE while idx not in route : NEW_LINE INDENT route . append ( idx ) NEW_LINE idx = B [ idx ] - 1 NEW_LINE DEDENT cycle_start = idx NEW_LINE if k < len ( route ) : NEW_LINE INDENT return route [ k ] + 1 NEW_LINE DEDENT T = route . index ( cycle_start ) NEW_LINE C = len ( route ) - T NEW_LINE return route [ ( k - T ) % C + T ] + 1 NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT N , a = map ( int , input ( ) . split ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE B = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE ans = strange_dict ( N , a , k , B ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE n , a = li ( ) NEW_LINE k = ni ( ) NEW_LINE b = [ 0 ] + list ( li ( ) ) NEW_LINE searched = [ 0 ] * ( n + 1 ) NEW_LINE cur = a NEW_LINE order = [ ] NEW_LINE for _ in range ( 10 ** 5 + 1 ) : NEW_LINE INDENT cur = b [ cur ] NEW_LINE if searched [ cur ] : NEW_LINE INDENT lpst = order . index ( cur ) NEW_LINE header = order [ : lpst ] NEW_LINE loop = order [ lpst : ] NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT searched [ cur ] = 1 NEW_LINE order . append ( cur ) NEW_LINE DEDENT DEDENT if header : NEW_LINE INDENT if k <= len ( header ) : NEW_LINE INDENT print ( order [ k - 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT k -= len ( header ) NEW_LINE print ( loop [ ( k - 1 ) % len ( loop ) ] ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( loop [ ( k - 1 ) % len ( loop ) ] ) NEW_LINE DEDENT",
"import bisect NEW_LINE import numpy as np NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE def IL ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def SL ( ) : return input ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE N , a = IL ( ) NEW_LINE k = I ( ) NEW_LINE bl = IL ( ) NEW_LINE dp = [ 0 , bl [ a - 1 ] ] NEW_LINE ans = - 1 NEW_LINE if k == 1 : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 2 , N + 2 ) : NEW_LINE INDENT tmp = bl [ dp [ - 1 ] - 1 ] NEW_LINE if tmp in dp : NEW_LINE INDENT dp . append ( tmp ) NEW_LINE f = dp . index ( tmp ) NEW_LINE ans = f + ( k - i ) % ( i - f ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT dp . append ( tmp ) NEW_LINE DEDENT DEDENT DEDENT print ( dp [ ans ] ) NEW_LINE",
"N , a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a -= 1 NEW_LINE k = int ( input ( ) ) NEW_LINE b = [ int ( i ) - 1 for i in input ( ) . split ( ) ] NEW_LINE t = [ - 1 for i in range ( N ) ] NEW_LINE nowt = 0 NEW_LINE while t [ a ] == - 1 : NEW_LINE INDENT t [ a ] = nowt NEW_LINE a = b [ a ] NEW_LINE nowt += 1 NEW_LINE DEDENT loop = max ( t ) - t [ a ] + 1 NEW_LINE if k <= max ( t ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT if t [ i ] == k : NEW_LINE INDENT print ( i + 1 ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT base = t [ a ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT t [ i ] -= base NEW_LINE DEDENT k -= base NEW_LINE k %= loop NEW_LINE for i in range ( N ) : NEW_LINE INDENT if t [ i ] == k : NEW_LINE INDENT print ( i + 1 ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT"
] |
atcoder_abc064_A | [
"import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { System . out . println ( ( sc . nextInt ( ) * 100 + sc . nextInt ( ) * 10 + sc . nextInt ( ) ) % 4 == 0 ? \" YES \" : \" NO \" ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; int r = reader . nextInt ( ) ; int g = reader . nextInt ( ) ; int b = reader . nextInt ( ) ; int num = r * 100 + g * 10 + b ; String ans = \" NO \" ; if ( num % 4 == 0 ) { ans = \" YES \" ; } reader . close ( ) ; System . out . print ( ans ) ; } }",
"import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int cnt = N * 100 + A * 10 + B ; if ( cnt % 4 == 0 ) { out . println ( \" YES \" ) ; } else { out . println ( \" NO \" ) ; } out . flush ( ) ; } }",
"import java . util . Scanner ; public class Main { private static Scanner sc ; public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( sc . next ( ) ) . append ( sc . next ( ) ) . append ( sc . next ( ) ) ; int a = Integer . valueOf ( sb . toString ( ) ) ; if ( a % 4 == 0 ) { System . out . print ( \" YES \" ) ; } else { System . out . print ( \" NO \" ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int r = sc . nextInt ( ) ; int g = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int num = r * 100 + g * 10 + b * 1 ; System . out . println ( ( num % 4 == 0 ) ? \" YES \" : \" NO \" ) ; } }"
] | [
"r , g , b = map ( int , input ( ) . split ( ) ) NEW_LINE print ( \" YES \" if ( 10 * g + b ) % 4 == 0 else \" NO \" ) NEW_LINE",
"print ( ' YNEOS ' [ not eval ( input ( ) . replace ( ' β ' , ' ' ) + ' % 4 = = 0' ) : : 2 ] ) NEW_LINE",
"x , y , z = input ( ) . split ( ) NEW_LINE a = int ( x + y + z ) NEW_LINE if a % 4 == 0 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT",
"work = input ( ) . split ( \" β \" ) NEW_LINE r = int ( work [ 0 ] ) NEW_LINE b = int ( work [ 1 ] ) NEW_LINE g = int ( work [ 2 ] ) NEW_LINE num = r * 100 + b * 10 + g NEW_LINE if ( num % 4 == 0 ) : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT",
"print ( [ \" NO \" , \" YES \" ] [ int ( \" \" . join ( input ( ) . split ( ) ) ) % 4 == 0 ] ) NEW_LINE"
] |
atcoder_arc054_B | [
"import java . util . Scanner ; public class Main { private static double f ( double P , double x ) { return x + P / Math . pow ( 2 , x / 1.5 ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double P = sc . nextDouble ( ) ; double left = 0 ; double right = Long . MAX_VALUE ; for ( int i = 0 ; i < 200 ; i ++ ) { double x1 = ( left * 2 + right ) / 3 ; double x2 = ( left + right * 2 ) / 3 ; if ( f ( P , x1 ) > f ( P , x2 ) ) { left = x1 ; } else { right = x2 ; } } System . out . println ( f ( P , left ) ) ; } }",
"import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; double p = sc . nextDouble ( ) ; if ( p >= 1.5 / log ( 2 ) ) { out . println ( f ( 1.5 * log ( log ( 2 ) * p / 1.5 ) / log ( 2 ) , p ) ) ; } else { out . println ( p ) ; } } static double f ( double x , double p ) { return x + p / ( pow ( 2 , x / 1.5 ) ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; double P = sc . nextDouble ( ) ; double bibin = 1 - P * Math . log ( 2 ) / 1.5 ; if ( bibin > 0 ) { pl ( P ) ; } else { double t = 1.5 / Math . log ( 2 ) * Math . log ( P * Math . log ( 2 ) / 1.5 ) ; double ans = t + P / ( Math . pow ( 2 , t / 1.5 ) ) ; pl ( ans ) ; } } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } public String nextLine ( ) { try { return reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }",
"import java . util . * ; import java . io . * ; import java . awt . geom . * ; import java . math . * ; public class Main { static final Scanner in = new Scanner ( System . in ) ; static final PrintWriter out = new PrintWriter ( System . out , false ) ; static boolean debug = false ; static double f ( double x , double p ) { return x + p / Math . pow ( 2 , x * 2 / 3 ) ; } static void solve ( ) { double p = in . nextDouble ( ) ; double l = 0.0 , r = Integer . MAX_VALUE / 2 ; for ( int i = 0 ; i < 100 ; i ++ ) { double s = ( l * 2 + r ) / 3 ; double t = ( l + r * 2 ) / 3 ; if ( f ( s , p ) < f ( t , p ) ) { r = t ; } else { l = s ; } } out . printf ( \" % .10f \\n \" , f ( ( l + r ) * 0.5 , p ) ) ; } public static void main ( String [ ] args ) { debug = args . length > 0 ; long start = System . nanoTime ( ) ; solve ( ) ; out . flush ( ) ; long end = System . nanoTime ( ) ; dump ( ( end - start ) / 1000000 + \" β ms \" ) ; in . close ( ) ; out . close ( ) ; } static void dump ( Object ... o ) { if ( debug ) System . err . println ( Arrays . deepToString ( o ) ) ; } }",
"import java . util . * ; import java . util . function . * ; class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { double p = s . nextDouble ( ) ; DoubleUnaryOperator f = i -> i + p / Math . pow ( 2 , i / 1.5 ) ; System . out . println ( f . applyAsDouble ( goldenSelectionSearch ( 0 , p , 1e-9 , f ) ) ) ; } private static double goldenSelectionSearch ( double l , double r , double off , DoubleUnaryOperator f ) { final double g = ( 1 + Math . sqrt ( 5 ) ) / 2 ; double a = ( l * g + r ) / ( 1 + g ) , fa = f . applyAsDouble ( a ) ; double b = ( l + r * g ) / ( 1 + g ) , fb = f . applyAsDouble ( b ) ; while ( l + off < r ) { if ( fa <= fb ) { r = b ; b = a ; fb = fa ; a = ( l * g + r ) / ( 1 + g ) ; fa = f . applyAsDouble ( a ) ; } else { l = a ; a = b ; fa = fb ; b = ( l + r * g ) / ( 1 + g ) ; fb = f . applyAsDouble ( b ) ; } } return ( a + b ) / 2 ; } }"
] | [
"import sys NEW_LINE input = sys . stdin . readline NEW_LINE p = float ( input ( ) ) NEW_LINE def f ( x ) : NEW_LINE INDENT return x + p / 2 ** ( x / 1.5 ) NEW_LINE DEDENT high = 100 NEW_LINE low = 0 NEW_LINE while high - low > 0.000000001 : NEW_LINE INDENT mid_left = high / 3 + low * 2 / 3 NEW_LINE mid_right = high * 2 / 3 + low / 3 NEW_LINE if f ( mid_left ) >= f ( mid_right ) : NEW_LINE INDENT low = mid_left NEW_LINE DEDENT else : NEW_LINE INDENT high = mid_right NEW_LINE DEDENT DEDENT print ( f ( high ) ) NEW_LINE",
"from decimal import Decimal NEW_LINE from decimal import getcontext NEW_LINE getcontext ( ) . prec = 56 NEW_LINE def f ( x , P ) : NEW_LINE INDENT return Decimal ( x ) + P * Decimal ( 2 ** Decimal ( Decimal ( - 1 ) * Decimal ( x * Decimal ( 2 / 3 ) ) ) ) NEW_LINE DEDENT def solv ( P ) : NEW_LINE INDENT l = Decimal ( 0 ) NEW_LINE r = Decimal ( 100 ) NEW_LINE while True : NEW_LINE INDENT ml = Decimal ( l + ( r - l ) * Decimal ( 1 / 3 ) ) NEW_LINE mr = Decimal ( l + ( r - l ) * Decimal ( 2 / 3 ) ) NEW_LINE if ( mr - ml ) < 0.000000001 : NEW_LINE INDENT return f ( mr , P ) NEW_LINE DEDENT fml = f ( ml , P ) NEW_LINE fmr = f ( mr , P ) NEW_LINE if fml < fmr : NEW_LINE INDENT r = mr NEW_LINE DEDENT elif fml > fmr : NEW_LINE INDENT l = ml NEW_LINE DEDENT else : NEW_LINE INDENT l = ml NEW_LINE r = mr NEW_LINE DEDENT DEDENT DEDENT I = input ( ) . split ( \" . \" ) NEW_LINE I [ 1 ] = \" . \" + I [ 1 ] NEW_LINE P = Decimal ( I [ 0 ] ) + Decimal ( I [ 1 ] ) NEW_LINE print ( solv ( P ) ) NEW_LINE",
"p = float ( input ( ) ) NEW_LINE def func ( t ) : NEW_LINE INDENT return t + p / ( 2 ** ( t / 1.5 ) ) NEW_LINE DEDENT def TernarySearch ( f , xmin , xmax ) : NEW_LINE INDENT x0 = xmin NEW_LINE x3 = xmax NEW_LINE while x3 - x0 > 10 ** ( - 12 ) : NEW_LINE INDENT x1 = ( x0 * 2 + x3 ) / 3 NEW_LINE x2 = ( x0 + x3 * 2 ) / 3 NEW_LINE if f ( x1 ) < f ( x2 ) : NEW_LINE INDENT x3 = x2 NEW_LINE DEDENT else : NEW_LINE INDENT x0 = x1 NEW_LINE DEDENT DEDENT return x3 NEW_LINE DEDENT print ( func ( TernarySearch ( func , 0 , 100 ) ) ) NEW_LINE",
"from scipy . optimize import minimize NEW_LINE p = float ( input ( ) ) NEW_LINE t = lambda x : x + p / ( 2 ** ( x / 1.5 ) ) NEW_LINE c = ( { ' type ' : ' ineq ' , ' fun ' : lambda x : x } , { ' type ' : ' ineq ' , ' fun ' : t } ) NEW_LINE m = minimize ( t , x0 = 0 , tol = 0.1 ** 9 , constraints = c , method = \" COBYLA \" ) NEW_LINE print ( min ( p , m . fun ) ) NEW_LINE",
"import numpy as np NEW_LINE def main ( ) : NEW_LINE INDENT p = float ( input ( ) ) NEW_LINE b = get_b ( ) NEW_LINE x = max ( 0.0 , np . log ( - 1.0 / ( p * b ) ) / b ) NEW_LINE def f ( x ) : NEW_LINE INDENT return func ( p , x ) NEW_LINE DEDENT print ( f ( ternary_search ( f , 0 , p ) ) ) NEW_LINE DEDENT def ternary_search ( f , xmin , xmax ) : NEW_LINE INDENT assert xmin <= xmax NEW_LINE x0 = xmin NEW_LINE x3 = xmax NEW_LINE for i in range ( 200 ) : NEW_LINE INDENT x1 = ( x0 * 2 + x3 ) / 3.0 NEW_LINE x2 = ( x0 + x3 * 2 ) / 3.0 NEW_LINE if f ( x1 ) < f ( x2 ) : NEW_LINE INDENT x3 = x2 NEW_LINE DEDENT else : NEW_LINE INDENT x0 = x1 NEW_LINE DEDENT DEDENT return x3 NEW_LINE DEDENT def func ( p , x ) : NEW_LINE INDENT return p * 2.0 ** ( - x / 1.5 ) + x NEW_LINE DEDENT def get_b ( ) : NEW_LINE INDENT a = 2.0 ** ( - 1 / 1.5 ) NEW_LINE b = np . log ( a ) NEW_LINE return b NEW_LINE DEDENT main ( ) NEW_LINE"
] |
atcoder_abc091_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Map < String , Integer > map = new HashMap < > ( ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String str = sc . next ( ) ; if ( ! map . containsKey ( str ) ) { map . put ( str , 0 ) ; } map . put ( str , map . get ( str ) + 1 ) ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { String str = sc . next ( ) ; if ( ! map . containsKey ( str ) ) { map . put ( str , 0 ) ; } map . put ( str , map . get ( str ) - 1 ) ; } int max = 0 ; for ( int i : map . values ( ) ) { max = max > i ? max : i ; } System . out . println ( max ) ; } }",
"import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; Map < String , Integer [ ] > map = new HashMap < String , Integer [ ] > ( ) ; int N = reader . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String s = reader . next ( ) ; if ( map . containsKey ( s ) ) { map . get ( s ) [ 0 ] ++ ; } else { Integer [ ] arr = new Integer [ 2 ] ; arr [ 0 ] = 1 ; arr [ 1 ] = 0 ; map . put ( s , arr ) ; } } int M = reader . nextInt ( ) ; for ( int i = 0 ; i < M ; i ++ ) { String s = reader . next ( ) ; if ( map . containsKey ( s ) ) { map . get ( s ) [ 1 ] ++ ; } else { Integer [ ] arr = new Integer [ 2 ] ; arr [ 0 ] = 0 ; arr [ 1 ] = 1 ; map . put ( s , arr ) ; } } int ans = 0 ; for ( Entry < String , Integer [ ] > entry : map . entrySet ( ) ) { Integer [ ] arr = entry . getValue ( ) ; int gap = arr [ 0 ] - arr [ 1 ] ; ans = Math . max ( gap , ans ) ; } System . out . println ( ans ) ; reader . close ( ) ; } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . HashMap ; public class Main { static final BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static void main ( String [ ] args ) throws Exception { HashMap < String , Integer > map = new HashMap < > ( ) ; int n = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { String key = in . readLine ( ) ; if ( map . containsKey ( key ) ) { map . put ( key , map . get ( key ) + 1 ) ; } else { map . put ( key , 1 ) ; } } int m = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < m ; i ++ ) { String key = in . readLine ( ) ; if ( map . containsKey ( key ) ) { map . put ( key , map . get ( key ) - 1 ) ; } else { map . put ( key , - 1 ) ; } } in . close ( ) ; int max = - 1 ; for ( int val : map . values ( ) ) { if ( max < val ) { max = val ; } } ; System . out . println ( max < 0 ? 0 : max ) ; } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { HashMap < String , Integer > map = new HashMap < > ( ) ; int n = sc . nextInt ( ) ; String s ; for ( int i = 0 ; i < n ; i ++ ) { s = sc . next ( ) ; map . put ( s , map . getOrDefault ( s , 0 ) ) ; map . put ( s , map . get ( s ) + 1 ) ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { s = sc . next ( ) ; map . put ( s , map . getOrDefault ( s , 0 ) ) ; map . put ( s , map . get ( s ) - 1 ) ; } int max = 0 ; for ( Map . Entry < String , Integer > e : map . entrySet ( ) ) { max = Math . max ( max , e . getValue ( ) ) ; } out . println ( max ) ; } }",
"import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int N = Integer . parseInt ( sc . next ( ) ) ; String s [ ] = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { s [ i ] = sc . next ( ) ; } int M = Integer . parseInt ( sc . next ( ) ) ; String t [ ] = new String [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { t [ i ] = sc . next ( ) ; } int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int cnt = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( s [ i ] . equals ( s [ j ] ) ) { cnt ++ ; } } for ( int j = 0 ; j < M ; j ++ ) { if ( s [ i ] . equals ( t [ j ] ) ) { cnt -- ; } } if ( cnt > 0 && cnt > ans ) { ans = cnt ; } } out . println ( ans ) ; out . flush ( ) ; } }"
] | [
"import sys NEW_LINE from collections import Counter , defaultdict 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 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 = II ( ) NEW_LINE blue = defaultdict ( int ) NEW_LINE for _ in range ( n ) : NEW_LINE INDENT blue [ SI ( ) ] += 1 NEW_LINE DEDENT m = II ( ) NEW_LINE red = defaultdict ( int ) NEW_LINE for _ in range ( m ) : NEW_LINE INDENT red [ SI ( ) ] += 1 NEW_LINE DEDENT res = 0 NEW_LINE for key , v in blue . items ( ) : NEW_LINE INDENT res = max ( res , v - red [ key ] ) NEW_LINE DEDENT return res NEW_LINE DEDENT print ( main ( ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE s = [ input ( ) for _ in range ( N ) ] NEW_LINE M = int ( input ( ) ) NEW_LINE t = [ input ( ) for _ in range ( M ) ] NEW_LINE a = 0 NEW_LINE for i in s : NEW_LINE INDENT b = s . count ( i ) - t . count ( i ) NEW_LINE if a < b : NEW_LINE INDENT a = b NEW_LINE DEDENT DEDENT print ( a ) NEW_LINE",
"n , * s = open ( 0 ) ; print ( max ( 0 , * [ s . count ( i ) - s [ int ( n ) : ] . count ( i ) * 2 for i in s ] ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE blue = { } NEW_LINE for _ in range ( N ) : NEW_LINE INDENT s = input ( ) . rstrip ( ) NEW_LINE if blue . get ( s ) == None : NEW_LINE INDENT blue [ s ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT blue [ s ] += 1 NEW_LINE DEDENT DEDENT M = int ( input ( ) ) NEW_LINE red = { } NEW_LINE for _ in range ( M ) : NEW_LINE INDENT t = input ( ) . rstrip ( ) NEW_LINE if red . get ( t ) == None : NEW_LINE INDENT red [ t ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT red [ t ] += 1 NEW_LINE DEDENT DEDENT answer = 0 NEW_LINE for i , blue_elem in blue . items ( ) : NEW_LINE INDENT red_elem = red [ i ] if red . get ( i ) != None else 0 NEW_LINE answer = blue_elem - red_elem if answer < blue_elem - red_elem else answer NEW_LINE DEDENT print ( answer ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE input_Blue = [ input ( ) for i in range ( N ) ] NEW_LINE M = int ( input ( ) ) NEW_LINE input_Red = [ input ( ) for j in range ( M ) ] NEW_LINE dict_Blue = { } NEW_LINE for str_Blue in input_Blue : NEW_LINE INDENT dict_Blue [ str_Blue ] = dict_Blue . get ( str_Blue , 0 ) + 1 NEW_LINE DEDENT dict_Red = { } NEW_LINE for str_Red in input_Red : NEW_LINE INDENT dict_Red [ str_Red ] = dict_Red . get ( str_Red , 0 ) + 1 NEW_LINE DEDENT for Blue_Key in dict_Blue . keys ( ) : NEW_LINE INDENT if Blue_Key in dict_Red . keys ( ) : NEW_LINE INDENT dict_Blue [ Blue_Key ] = dict_Blue [ Blue_Key ] - dict_Red [ Blue_Key ] NEW_LINE DEDENT DEDENT if max ( dict_Blue . values ( ) ) < 0 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( max ( dict_Blue . values ( ) ) ) NEW_LINE DEDENT"
] |
atcoder_abc052_B | [
"import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int x = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' I ' ) { x ++ ; } else if ( s . charAt ( i ) == ' D ' ) { x -- ; } ans = Math . max ( ans , x ) ; } System . out . println ( ans ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; String S = in . next ( ) ; int ans = 0 ; int tmp = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == ' I ' ) { tmp ++ ; } else if ( S . charAt ( i ) == ' D ' ) { tmp -- ; } ans = Math . max ( ans , tmp ) ; } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int k = sc . nextInt ( ) ; String s = sc . next ( ) ; int ans = 0 ; int x = 0 ; for ( int i = 0 ; i < k ; i ++ ) { if ( s . charAt ( i ) == ' I ' ) { x ++ ; } else { x -- ; } ans = Math . max ( x , ans ) ; } System . out . println ( ans ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { @ SuppressWarnings ( \" resource \" ) Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; String S = scan . next ( ) ; int x = 0 ; int max = 0 ; for ( char s : S . toCharArray ( ) ) { switch ( s ) { case ' I ' : x ++ ; if ( max < x ) { max = x ; } break ; case ' D ' : x -- ; } } System . out . println ( max ) ; } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; input . readLine ( ) ; String word = input . readLine ( ) ; int value = 0 ; int max = 0 ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { if ( word . charAt ( i ) == ' I ' ) { value ++ ; } else { value -- ; } max = Math . max ( max , value ) ; } System . out . println ( max ) ; } }"
] | [
"from functools import reduce NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) . rstrip ( ) ) NEW_LINE S = list ( _ for _ in input ( ) ) NEW_LINE x = 0 NEW_LINE max_x = 0 NEW_LINE for s in S : NEW_LINE INDENT if s == ' I ' : NEW_LINE INDENT x += 1 NEW_LINE DEDENT elif s == ' D ' : NEW_LINE INDENT x += - 1 NEW_LINE DEDENT max_x = max ( x , max_x ) NEW_LINE DEDENT print ( max_x ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"_ , t = open ( 0 ) ; a = b = 0 NEW_LINE for x in t : b += x > ' D ' or - 1 ; a = max ( a , b ) NEW_LINE print ( a ) NEW_LINE",
"x = 0 NEW_LINE N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE ans = [ ] NEW_LINE ans . append ( x ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if S [ i ] == \" I \" : NEW_LINE INDENT x += 1 NEW_LINE DEDENT else : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT ans . append ( x ) NEW_LINE DEDENT print ( max ( ans ) ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE b = 0 NEW_LINE t = 0 NEW_LINE for c in input ( ) : NEW_LINE INDENT if c == ' I ' : NEW_LINE INDENT t += 1 NEW_LINE DEDENT else : NEW_LINE INDENT t -= 1 NEW_LINE DEDENT if t > b : NEW_LINE INDENT b = t NEW_LINE DEDENT DEDENT print ( b ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE res = 0 NEW_LINE tmp = 0 NEW_LINE for s in S : NEW_LINE INDENT if s == \" I \" : NEW_LINE INDENT tmp += 1 NEW_LINE DEDENT if s == \" D \" : NEW_LINE INDENT tmp -= 1 NEW_LINE DEDENT res = max ( tmp , res ) NEW_LINE DEDENT print ( res ) NEW_LINE"
] |
atcoder_agc031_C | [
"import static java . lang . Integer . parseInt ; import static java . lang . Long . parseLong ; import static java . lang . System . exit ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { static void solve ( ) throws Exception { int n = scanInt ( ) , a = scanInt ( ) , b = scanInt ( ) ; if ( ( Integer . bitCount ( a ^ b ) & 1 ) == 0 ) { out . print ( \" NO \" ) ; } else { out . println ( \" YES \" ) ; go ( ( 1 << n ) - 1 , a , b ) ; } } static void go ( int mask , int a , int b ) { if ( ( mask & ( mask - 1 ) ) == 0 ) { out . print ( a + \" β \" + b + \" β \" ) ; } else { int c = Integer . lowestOneBit ( a ^ b ) ; int d = Integer . lowestOneBit ( mask ^ c ) ; go ( mask ^ c , a , a ^ d ) ; go ( mask ^ c , a ^ d ^ c , b ) ; } } static int scanInt ( ) throws IOException { return parseInt ( scanString ( ) ) ; } static long scanLong ( ) throws IOException { return parseLong ( scanString ( ) ) ; } static String scanString ( ) throws IOException { while ( tok == null || ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } static BufferedReader in ; static PrintWriter out ; static StringTokenizer tok ; public static void main ( String [ ] args ) { try { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ; solve ( ) ; in . close ( ) ; out . close ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; exit ( 1 ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int first = sc . nextInt ( ) ; int last = sc . nextInt ( ) ; boolean bit [ ] = new boolean [ num ] ; int index [ ] = new int [ num ] ; int sum = 0 ; for ( int i = 0 ; i < num ; i ++ ) { bit [ i ] = ( first & ( 1 << i ) ) != ( last & ( 1 << i ) ) ; sum += bit [ i ] ? 1 : 0 ; index [ bit [ i ] ? sum - 1 : num - ( i - sum ) - 1 ] = i ; } if ( sum % 2 == 0 ) { System . out . println ( \" NO \" ) ; } else { System . out . println ( \" YES \" ) ; int max = ( int ) Math . pow ( 2 , num ) ; int tmp = first ; int change [ ] = new int [ num ] ; System . out . print ( tmp + \" β \" ) ; for ( int i = 1 ; i < max ; i ++ ) { int crtIndex = 0 ; for ( ; crtIndex < num ; crtIndex ++ ) { if ( ( i & ( 1 << crtIndex ) ) != 0 ) { break ; } } crtIndex = num - crtIndex - 1 ; if ( bit [ index [ crtIndex ] ] && crtIndex != 0 ) { if ( crtIndex % 2 == 0 ) { if ( change [ crtIndex ] < 2 ) { change [ crtIndex ] ++ ; crtIndex -- ; } } else { if ( change [ crtIndex ] < 1 ) { change [ crtIndex ] ++ ; crtIndex ++ ; } } } int crtDigit = 1 << index [ crtIndex ] ; tmp = ( tmp & crtDigit ) != 0 ? tmp - crtDigit : tmp + crtDigit ; System . out . print ( tmp + \" β \" ) ; } } System . out . println ( ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) , 1000000 ) ; StringTokenizer tok = new StringTokenizer ( \" \" ) ; StringBuilder out = new StringBuilder ( ) ; String next ( ) throws IOException { if ( ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } int n = 0 ; int k = 0 ; void go ( int a , int b , int mask , char removed ) { if ( removed == k - 1 ) { out . append ( a + \" β \" + b + \" β \" ) ; } else { int k1 = 0 ; for ( int i = 0 ; i < k ; i ++ ) { if ( ( mask & ( 1 << i ) ) == 0 && ( ( a ^ b ) & ( 1 << i ) ) > 0 ) { mask |= ( 1 << i ) ; removed ++ ; k1 = i ; break ; } } int a1 = 0 ; for ( int j = 0 ; j < k ; j ++ ) { if ( ( mask & ( 1 << j ) ) == 0 ) { a1 = a ^ ( 1 << j ) ; break ; } } go ( a , a1 , mask , removed ) ; go ( ( a1 ^ ( 1 << k1 ) ) , b , mask , removed ) ; } } void slave ( ) throws IOException { k = nextInt ( ) ; int A = nextInt ( ) ; int B = nextInt ( ) ; n = 1 << k ; if ( Integer . bitCount ( A ^ B ) % 2 == 0 ) { out . append ( \" NO \" ) ; } else { out . append ( \" YES \\n \" ) ; go ( A , B , 0 , ( char ) 0 ) ; } System . out . print ( out ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . slave ( ) ; } }",
"import java . io . PrintWriter ; import java . util . Scanner ; public class Main { private static int [ ] path ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; path = new int [ 1 << n ] ; if ( Integer . bitCount ( a ^ b ) % 2 != 0 ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; return ; } path ( a , b , 0 , ( 1 << n ) - 1 ) ; PrintWriter pw = new PrintWriter ( System . out ) ; for ( int i = 0 ; i < path . length ; i ++ ) { pw . print ( path [ i ] + \" β \" ) ; } pw . println ( ) ; pw . flush ( ) ; } private static void path ( int a , int b , int st , int mask ) { int diffBit = Integer . highestOneBit ( mask & ( a ^ b ) ) ; mask = mask ^ diffBit ; int size = Integer . bitCount ( mask ) ; if ( size == 0 ) { path [ st ] = a ; path [ st + 1 ] = b ; } else { int otherBit = Integer . highestOneBit ( mask ) ; path ( a , a ^ otherBit , st , mask ) ; path ( a ^ diffBit ^ otherBit , b , st + ( 1 << size ) , mask ) ; } } }",
"import java . util . ArrayList ; import java . util . Arrays ; import java . util . Scanner ; public class Main { int n , a , b ; ArrayList < Integer > ans ; void run ( ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; if ( Integer . bitCount ( a ^ b ) % 2 == 0 ) { System . out . println ( \" NO \" ) ; return ; } System . out . println ( \" YES \" ) ; ans = new ArrayList < > ( ) ; solve ( a , b , ( 1 << n ) - 1 ) ; boolean check = true ; for ( int i = 0 ; i < ( 1 << n ) - 1 ; i ++ ) { System . out . print ( ans . get ( i ) + \" β \" ) ; } System . out . println ( b ) ; } void reverse ( int [ ] ar , int l , int r ) { int c = ( l + r ) / 2 - l ; for ( int i = 0 ; i < c ; i ++ ) { int tmp = ar [ l + i ] ; ar [ l + i ] = ar [ r - i ] ; ar [ r - i ] = tmp ; } } void solve ( int A , int B , int mask ) { if ( Integer . bitCount ( mask ) == 1 ) { ans . add ( A ) ; ans . add ( B ) ; return ; } int div = - 1 ; for ( int i = 0 ; i < n ; i ++ ) if ( ( ( ( A ^ B ) & mask ) & ( 1 << i ) ) > 0 ) { div = i ; } mask ^= 1 << div ; int c = mask & ( - mask ) ; int C = A ^ c ; solve ( A , C , mask ) ; solve ( C ^ ( 1 << div ) , B , mask ) ; } void debug ( Object ... os ) { System . err . println ( Arrays . deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } }"
] | [
"import sys NEW_LINE def revBit ( Ai ) : NEW_LINE INDENT return '1' if Ai == '0' else '0' NEW_LINE DEDENT def rec ( binA , binB ) : NEW_LINE INDENT if len ( binA ) == 1 : NEW_LINE INDENT return [ binA , binB ] NEW_LINE DEDENT for i , ( Ai , Bi ) in enumerate ( zip ( binA , binB ) ) : NEW_LINE INDENT if Ai != Bi : NEW_LINE INDENT x = i NEW_LINE Ax , Bx = Ai , Bi NEW_LINE break NEW_LINE DEDENT DEDENT binA2 = binA [ : x ] + binA [ x + 1 : ] NEW_LINE binB2 = binB [ : x ] + binB [ x + 1 : ] NEW_LINE binC = binA2 [ : - 1 ] + revBit ( binA2 [ - 1 ] ) NEW_LINE ptn1s = rec ( binA2 , binC ) NEW_LINE ptn2s = rec ( binC , binB2 ) NEW_LINE ptns = [ ] NEW_LINE for ptn1 in ptn1s : NEW_LINE INDENT ptns . append ( ptn1 [ : x ] + Ax + ptn1 [ x : ] ) NEW_LINE DEDENT for ptn2 in ptn2s : NEW_LINE INDENT ptns . append ( ptn2 [ : x ] + Bx + ptn2 [ x : ] ) NEW_LINE DEDENT return ptns NEW_LINE DEDENT N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE binA , binB = bin ( A ) [ 2 : ] . zfill ( N ) , bin ( B ) [ 2 : ] . zfill ( N ) NEW_LINE numDiff = sum ( [ Ai != Bi for Ai , Bi in zip ( binA , binB ) ] ) NEW_LINE if numDiff % 2 == 0 : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT ptns = rec ( binA , binB ) NEW_LINE print ( ' YES ' ) NEW_LINE print ( ' β ' . join ( [ str ( int ( ptn , 2 ) ) for ptn in ptns ] ) ) NEW_LINE",
"n , a , b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE def f ( n , a , b ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT return [ a , b ] NEW_LINE DEDENT mask = 1 << ( n - 1 ) NEW_LINE if a & mask == b & mask : NEW_LINE INDENT v1 = f ( n - 1 , a , b ) NEW_LINE v2 = f ( n - 1 , a ^ mask , v1 [ 1 ] ^ mask ) NEW_LINE ret = [ a ] NEW_LINE ret . extend ( v2 ) NEW_LINE ret . extend ( v1 [ 1 : ] ) NEW_LINE return ret NEW_LINE DEDENT else : NEW_LINE INDENT v1 = f ( n - 1 , a , a ^ 1 ) NEW_LINE v2 = f ( n - 1 , a ^ 1 ^ mask , b ) NEW_LINE v1 . extend ( v2 ) NEW_LINE return v1 NEW_LINE DEDENT DEDENT if bin ( a ^ b ) . count ( \"1\" ) % 2 == 0 : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE res = f ( n , a , b ) NEW_LINE for p in res : NEW_LINE INDENT print ( p , end = \" β \" ) NEW_LINE DEDENT DEDENT",
"N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE if bin ( A ) . count ( \"1\" ) % 2 == bin ( B ) . count ( \"1\" ) % 2 : NEW_LINE INDENT print ( \" No \" ) NEW_LINE exit ( 0 ) NEW_LINE DEDENT print ( \" Yes \" ) NEW_LINE ans = [ ] NEW_LINE def solve ( c , A , B , S ) : NEW_LINE INDENT P = A ^ B NEW_LINE U = P & S NEW_LINE b = 1 NEW_LINE if c == 1 : NEW_LINE INDENT ans . append ( A ) NEW_LINE ans . append ( B ) NEW_LINE return NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT if U & b : NEW_LINE INDENT assert S & b > 0 , ( P , S , U , b ) NEW_LINE S0 = S ^ b NEW_LINE k = 1 NEW_LINE while not S0 & k : NEW_LINE INDENT k <<= 1 NEW_LINE DEDENT C = A ^ k NEW_LINE solve ( c - 1 , A , C , S0 ) NEW_LINE solve ( c - 1 , C ^ b , B , S0 ) NEW_LINE break NEW_LINE DEDENT b <<= 1 NEW_LINE DEDENT DEDENT solve ( N , A , B , 2 ** N - 1 ) NEW_LINE print ( * ans ) NEW_LINE",
"import sys NEW_LINE def sum_digits ( n , m ) : NEW_LINE INDENT r = 0 NEW_LINE while n : NEW_LINE INDENT r , n = r + n % m , n // m NEW_LINE DEDENT return r NEW_LINE DEDENT n , a , b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE c = a ^ b NEW_LINE if sum_digits ( c , 2 ) % 2 == 0 : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT def grey ( n ) : NEW_LINE INDENT if n == 1 : return [ 0 , 1 ] NEW_LINE a0 = grey ( n - 1 ) NEW_LINE a2 = [ ( 2 ** ( n - 2 ) ) ^ i ^ ( 2 ** ( n - 1 ) ) for i in grey ( n - 1 ) ] NEW_LINE return a0 + a2 NEW_LINE DEDENT def newgrey ( a , b , move ) : NEW_LINE INDENT if len ( move ) == 1 : NEW_LINE INDENT return [ a , b ] NEW_LINE DEDENT diff = 0 NEW_LINE for j in move : NEW_LINE INDENT if a & ( 2 ** j ) != b & ( 2 ** j ) : NEW_LINE INDENT diff = j NEW_LINE break NEW_LINE DEDENT DEDENT ac = a NEW_LINE bc = b NEW_LINE for j in move : NEW_LINE INDENT if j == diff : continue NEW_LINE ac = a ^ ( 2 ** j ) NEW_LINE bc = ac ^ ( 2 ** diff ) NEW_LINE if bc != b : break NEW_LINE DEDENT return newgrey ( a , ac , move - set ( { diff } ) ) + newgrey ( bc , b , move - set ( { diff } ) ) NEW_LINE DEDENT print ( ' YES ' ) NEW_LINE ans = newgrey ( a , b , set ( range ( n ) ) ) NEW_LINE print ( * ans ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 6 ) NEW_LINE n , a , b = map ( int , input ( ) . split ( ) ) NEW_LINE def pop_count ( x ) : NEW_LINE INDENT res = 0 NEW_LINE for i in range ( 17 ) : NEW_LINE INDENT res += ( ( x >> i ) % 2 == 1 ) NEW_LINE DEDENT return res NEW_LINE DEDENT if ( pop_count ( a ^ b ) ) % 2 == 0 : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE def f ( m , x , y ) : NEW_LINE INDENT if m == 1 : NEW_LINE INDENT if x == 0 : NEW_LINE INDENT return [ 0 , 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT return [ 1 , 0 ] NEW_LINE DEDENT DEDENT res = [ x ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT if ( x >> i ) % 2 != ( y >> i ) % 2 : NEW_LINE INDENT diff = i NEW_LINE break NEW_LINE DEDENT DEDENT s = ( x % ( 2 ** diff ) ) + ( ( ( x // ( 2 ** ( diff + 1 ) ) ) * 2 ** ( diff + 1 ) ) >> 1 ) NEW_LINE t = ( y % ( 2 ** diff ) ) + ( ( ( y // ( 2 ** ( diff + 1 ) ) ) * 2 ** ( diff + 1 ) ) >> 1 ) NEW_LINE u = s ^ 1 NEW_LINE left = f ( m - 1 , s , u ) NEW_LINE right = f ( m - 1 , u , t ) NEW_LINE x_bit , y_bit = ( x >> diff ) % 2 , ( y >> diff ) % 2 NEW_LINE left = [ l % ( 2 ** diff ) + ( 2 ** diff * x_bit ) + ( ( ( l // ( 2 ** diff ) ) * 2 ** diff ) << 1 ) for l in left ] NEW_LINE right = [ r % ( 2 ** diff ) + ( 2 ** diff * y_bit ) + ( ( ( r // ( 2 ** diff ) ) * 2 ** diff ) << 1 ) for r in right ] NEW_LINE return left + right NEW_LINE DEDENT print ( * f ( n , a , b ) ) NEW_LINE DEDENT"
] |
atcoder_arc051_B | [
"import java . util . * ; public class Main { static int count = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int prevA = 0 ; int a = 1 ; int prevB = 1 ; int b = 1 ; for ( int i = 2 ; i <= k ; i ++ ) { int ta = prevA + a ; int tb = prevB + b ; prevA = a ; a = ta ; prevB = b ; b = tb ; } System . out . println ( a + \" β \" + b ) ; } }",
"import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; int k = sc . nextInt ( ) ; int a = 2 , b = 1 ; for ( int i = 0 ; i < k - 1 ; ++ i ) { int c = a + b ; b = a ; a = c ; } out . println ( a + \" β \" + b ) ; out . close ( ) ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . io . BufferedInputStream ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; long a = 1 ; long b = 1 ; for ( int i = 0 ; i < K ; i ++ ) { long tmp = a ; a += b ; b = tmp ; } System . out . println ( a + \" β \" + b ) ; } public static class Scanner { private BufferedInputStream inputStream ; public Scanner ( InputStream in ) { inputStream = new BufferedInputStream ( in ) ; } public int nextInt ( ) throws IOException { int num = 0 ; int read = skip ( ) ; do { num = num * 10 + ( read - 0x30 ) ; } while ( ( read = inputStream . read ( ) ) > 0x20 ) ; return num ; } public int [ ] nextInt ( int n ) throws IOException { int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = nextInt ( ) ; } return array ; } public long nextLong ( ) throws IOException { long num = 0 ; int read = skip ( ) ; do { num = num * 10 + ( read - 0x30 ) ; } while ( ( read = inputStream . read ( ) ) > 0x20 ) ; return num ; } public long [ ] nextLong ( int n ) throws IOException { long [ ] array = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = nextLong ( ) ; } return array ; } public String next ( ) throws IOException { StringBuilder builder = new StringBuilder ( ) ; int read = skip ( ) ; do { builder . append ( ( char ) read ) ; } while ( ( read = inputStream . read ( ) ) > 0x20 ) ; return builder . toString ( ) ; } private int skip ( ) throws IOException { int read ; while ( ( read = inputStream . read ( ) ) <= 0x20 ) ; return read ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { static BufferedReader br ; static final double PHI = ( 1 + Math . sqrt ( 5 ) ) / 2 ; public static void main ( String [ ] args ) throws IOException { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int k = Integer . parseInt ( br . readLine ( ) ) ; System . out . println ( ( int ) ( pow ( k ) / Math . sqrt ( 5 ) + 0.5 ) + \" β \" + ( int ) ( PHI * pow ( k ) / Math . sqrt ( 5 ) + 0.5 ) ) ; } private static double pow ( int k ) { double d = 0.0 ; if ( k == 0 ) return 1 ; if ( k % 2 == 0 ) { d = pow ( k / 2 ) ; return d * d ; } d = pow ( k / 2 ) ; return PHI * d * d ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { new Main ( ) . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; long k = sc . nextLong ( ) ; for ( long aa = 1 ; ; aa ++ ) { long a = aa ; long b = 0 ; for ( int i = 0 ; i < k ; i ++ ) { if ( a < b ) { long d = a ; a = b ; b = d ; } long nextA ; long nextB = a ; nextA = a + b ; a = nextA ; b = nextB ; } if ( 1000000000 > a || 1000000000 > b ) { System . out . println ( b + \" β \" + a ) ; return ; } } } static int count = 0 ; long gcd ( long a , long b ) { if ( a > b ) { long d = a ; a = b ; b = d ; } if ( a == 0 ) return b ; else { count ++ ; return gcd ( a , b % a ) ; } } }"
] | [
"K = int ( input ( ) ) NEW_LINE f = [ 0 ] * 42 NEW_LINE f [ 0 ] = 1 NEW_LINE f [ 1 ] = 1 NEW_LINE for k in range ( 2 , 42 ) : NEW_LINE INDENT f [ k ] = f [ k - 1 ] + f [ k - 2 ] NEW_LINE DEDENT print ( f [ K + 1 ] , f [ K ] ) NEW_LINE",
"def mat_mul ( a , b ) : NEW_LINE INDENT ans = [ ] NEW_LINE for i in range ( len ( a ) ) : NEW_LINE INDENT ans . append ( [ ] ) NEW_LINE for j in range ( len ( b [ 0 ] ) ) : NEW_LINE INDENT tmp = 0 NEW_LINE for k in range ( len ( a [ 0 ] ) ) : NEW_LINE INDENT tmp += a [ i ] [ k ] * b [ k ] [ j ] NEW_LINE DEDENT ans [ i ] . append ( tmp ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT n = int ( input ( ) ) + 1 NEW_LINE x = [ [ 1 ] , [ 0 ] ] NEW_LINE y = [ [ 1 , 1 ] , [ 1 , 0 ] ] NEW_LINE while n > 0 : NEW_LINE INDENT if ( n & 1 ) > 0 : NEW_LINE INDENT x = mat_mul ( y , x ) NEW_LINE DEDENT n //= 2 NEW_LINE y = mat_mul ( y , y ) NEW_LINE DEDENT print ( \" { } β { } \" . format ( x [ 0 ] [ 0 ] , x [ 1 ] [ 0 ] ) ) NEW_LINE",
"cache = { } NEW_LINE def fib ( n ) : NEW_LINE INDENT if cache . get ( n ) : NEW_LINE INDENT return cache [ n ] NEW_LINE DEDENT if n == 1 or n == 2 : NEW_LINE INDENT return 1 NEW_LINE DEDENT cache [ n - 1 ] = fib ( n - 1 ) NEW_LINE cache [ n - 2 ] = fib ( n - 2 ) NEW_LINE return cache [ n - 1 ] + cache [ n - 2 ] NEW_LINE DEDENT k = int ( input ( ) ) NEW_LINE print ( fib ( k + 2 ) , fib ( k + 1 ) ) NEW_LINE",
"from functools import lru_cache NEW_LINE @ lru_cache ( maxsize = None ) NEW_LINE def fib ( n ) : NEW_LINE INDENT if n < 2 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return fib ( n - 1 ) + fib ( n - 2 ) NEW_LINE DEDENT K = int ( input ( ) ) NEW_LINE print ( fib ( K + 1 ) , fib ( K ) ) NEW_LINE",
"a = 0 NEW_LINE b = 1 NEW_LINE for i in range ( int ( input ( ) ) ) : a , b = b , a + b NEW_LINE print ( a , b ) NEW_LINE"
] |
atcoder_abc007_D | [
"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 ) ; D solver = new D ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class D { public void solve ( int testNumber , Scanner in , PrintWriter out ) { long a = in . nextLong ( ) , b = in . nextLong ( ) ; out . println ( calc ( b ) - calc ( a - 1 ) ) ; } private long calc ( long n ) { char [ ] cs = Long . toString ( n ) . toCharArray ( ) ; boolean eight = false ; for ( int i = 0 ; i < cs . length ; i ++ ) { if ( ! eight && ( cs [ i ] == '4' || cs [ i ] == '9' ) ) { eight = true ; } else if ( eight ) { cs [ i ] = '8' ; } if ( cs [ i ] >= '9' ) { cs [ i ] -= 2 ; } else if ( cs [ i ] >= '4' ) { cs [ i ] -- ; } } long wo8 = Long . parseLong ( String . valueOf ( cs ) , 8 ) ; return n - wo8 ; } } }",
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] a , b ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; a = String . valueOf ( A ) . toCharArray ( ) ; b = String . valueOf ( B + 1 ) . toCharArray ( ) ; System . out . println ( B - A + 1 - ( f ( b , 0 ) - f ( a , 0 ) ) ) ; } static long f ( char [ ] v , int idx ) { if ( idx == v . length ) return 0 ; long ret = 0 ; for ( int i = 0 ; i < v [ idx ] - '0' ; ++ i ) { if ( i == 4 || i == 9 ) continue ; ret += pow ( 8 , v . length - 1 - idx ) ; } if ( v [ idx ] - '0' != 4 && v [ idx ] - '0' != 9 ) ret += f ( v , idx + 1 ) ; return ret ; } static long pow ( long a , long n ) { long ret = 1 ; for ( ; n > 0 ; n >>= 1 , a = a * a ) { if ( n % 2 == 1 ) { ret = ret * a ; } } return ret ; } static void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } }",
"import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; long A = sc . nextLong ( ) - 1 ; long B = sc . nextLong ( ) ; int [ ] a = new int [ 19 ] ; int [ ] b = new int [ 19 ] ; for ( int i = 0 ; i < 19 ; i ++ ) { a [ 18 - i ] = ( int ) ( A % 10 ) ; b [ 18 - i ] = ( int ) ( B % 10 ) ; A /= 10 ; B /= 10 ; } out . println ( c ( b ) - c ( a ) ) ; } static long c ( int [ ] a ) { long [ ] [ ] [ ] dp = new long [ 20 ] [ 2 ] [ 2 ] ; dp [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < 19 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { int x = j == 1 ? 9 : a [ i ] ; for ( int k = 0 ; k < 2 ; k ++ ) { for ( int l = 0 ; l <= x ; l ++ ) { dp [ i + 1 ] [ j == 1 || l < x ? 1 : 0 ] [ l == 4 || l == 9 ? 1 : k ] += dp [ i ] [ j ] [ k ] ; } } } } return dp [ 19 ] [ 0 ] [ 1 ] + dp [ 19 ] [ 1 ] [ 1 ] ; } }",
"import java . util . * ; class Main { static long f ( long a ) { int [ ] d = new int [ 19 ] ; long b = a ; for ( int i = 0 ; i < 19 ; ++ i ) { d [ 18 - i ] = ( int ) ( a % 10 ) ; a /= 10 ; } long [ ] dp = new long [ 20 ] ; boolean f = false ; for ( int i = 0 ; i < 19 ; ++ i ) { dp [ i + 1 ] = 8 * dp [ i ] ; for ( int k = d [ i ] + 1 ; k < 10 ; ++ k ) { if ( k != 4 && k != 9 && ! f ) dp [ i + 1 ] -- ; } if ( d [ i ] == 4 || d [ i ] == 9 ) f = true ; } return b + 1 - dp [ 19 ] ; } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long a = scan . nextLong ( ) ; long b = scan . nextLong ( ) ; System . out . println ( f ( b ) - f ( a - 1 ) ) ; } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long ANum = solver ( A - 1 ) ; long BNum = solver ( B ) ; out . println ( BNum - ANum ) ; } public static long solver ( long N ) { if ( N < 0 ) { return 0 ; } long ans = 0 ; while ( true ) { int first = Character . getNumericValue ( String . valueOf ( N ) . charAt ( 0 ) ) ; int k = String . valueOf ( N ) . length ( ) - 1 ; if ( k == 0 ) { for ( int i = 0 ; i <= first ; i ++ ) { if ( i == 4 || i == 9 ) { ans ++ ; } } break ; } else { long ansTmp = first * ( long ) Math . pow ( 10.0 , k ) ; for ( int i = 0 ; i < first ; i ++ ) { if ( i == 4 || i == 9 ) { continue ; } ansTmp -= ( long ) Math . pow ( 8 , k ) ; } ans += ansTmp ; } if ( k > 0 && ( first == 4 || first == 9 ) ) { ans += N - first * ( long ) Math . pow ( 10 , k ) + 1 ; break ; } else { N %= first * ( long ) Math . pow ( 10.0 , k ) ; } } return ans ; } }"
] | [
"whitedigits = [ 0 , 1 , 2 , 3 , 4 , 4 , 5 , 6 , 7 , 8 , 8 ] NEW_LINE def count ( n , whitedigits = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) : NEW_LINE INDENT n += 1 NEW_LINE c = 0 NEW_LINE d = 1 NEW_LINE while n > 0 : NEW_LINE INDENT digit = n % 10 NEW_LINE c *= whitedigits [ digit + 1 ] - whitedigits [ digit ] NEW_LINE c += whitedigits [ digit ] * d NEW_LINE d *= whitedigits [ 10 ] NEW_LINE n //= 10 NEW_LINE DEDENT return c NEW_LINE DEDENT A , B = map ( int , input ( ) . split ( ) ) NEW_LINE print ( ( B - count ( B , whitedigits ) ) - ( A - 1 - count ( A - 1 , whitedigits ) ) ) NEW_LINE",
"from itertools import product NEW_LINE a , b = input ( ) . split ( ) NEW_LINE def cnt ( c : str ) : NEW_LINE INDENT n = len ( c ) NEW_LINE dp = [ [ [ 0 ] * 2 for i in range ( 2 ) ] for j in range ( n + 1 ) ] NEW_LINE dp [ 0 ] [ 1 ] [ 0 ] = 1 NEW_LINE for i , j , k in product ( range ( n ) , range ( 2 ) , range ( 2 ) ) : NEW_LINE INDENT max_n = int ( c [ i ] ) if j else 9 NEW_LINE for n in range ( max_n + 1 ) : NEW_LINE INDENT dp [ i + 1 ] [ j and n == max_n ] [ k or n == 4 or n == 9 ] += dp [ i ] [ j ] [ k ] NEW_LINE DEDENT DEDENT res = 0 NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT res += dp [ - 1 ] [ i ] [ 1 ] NEW_LINE DEDENT return res NEW_LINE DEDENT print ( cnt ( b ) - cnt ( str ( int ( a ) - 1 ) ) ) NEW_LINE",
"import copy NEW_LINE AB = input ( ) . split ( ) NEW_LINE Ans = [ 0 , 0 ] NEW_LINE AB [ 0 ] = str ( int ( AB [ 0 ] ) - 1 ) NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT Dset = [ 2 , 2 , len ( AB [ i ] ) + 1 ] NEW_LINE D = 0 NEW_LINE for j in range ( 3 ) : NEW_LINE INDENT D = [ copy . deepcopy ( D ) for k in range ( Dset [ j ] ) ] NEW_LINE DEDENT D [ 0 ] [ 1 ] [ 0 ] = 1 NEW_LINE for j in range ( len ( AB [ i ] ) ) : NEW_LINE INDENT t = int ( AB [ i ] [ j ] ) NEW_LINE if t < 4 : a , b , c , d = ( t , 0 , 1 , 0 ) NEW_LINE elif t == 4 : a , b , c , d = ( 4 , 0 , 0 , 1 ) NEW_LINE elif t < 9 : a , b , c , d = ( t - 1 , 1 , 1 , 0 ) NEW_LINE else : a , b , c , d = ( 8 , 1 , 0 , 1 ) NEW_LINE D [ j + 1 ] [ 0 ] [ 0 ] = D [ j ] [ 0 ] [ 0 ] * 8 + D [ j ] [ 1 ] [ 0 ] * a NEW_LINE D [ j + 1 ] [ 0 ] [ 1 ] = D [ j ] [ 0 ] [ 0 ] * 2 + D [ j ] [ 0 ] [ 1 ] * 10 + D [ j ] [ 1 ] [ 0 ] * b + D [ j ] [ 1 ] [ 1 ] * t NEW_LINE D [ j + 1 ] [ 1 ] [ 0 ] = D [ j ] [ 1 ] [ 0 ] * c NEW_LINE D [ j + 1 ] [ 1 ] [ 1 ] = D [ j ] [ 1 ] [ 0 ] * d + D [ j ] [ 1 ] [ 1 ] NEW_LINE DEDENT Ans [ i ] = D [ - 1 ] [ 0 ] [ 1 ] + D [ - 1 ] [ 1 ] [ 1 ] NEW_LINE DEDENT print ( Ans [ 1 ] - Ans [ 0 ] ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE OK = [ 0 , 1 , 2 , 3 , 5 , 6 , 7 , 8 ] NEW_LINE def cnt ( N ) : NEW_LINE INDENT L = len ( N ) NEW_LINE dp = [ [ 0 ] * 2 for _ in range ( L + 1 ) ] NEW_LINE N = \" \" . join ( list ( reversed ( [ c for c in N ] ) ) ) NEW_LINE dp [ 0 ] [ 1 ] = 1 NEW_LINE for dig in range ( L ) : NEW_LINE INDENT for less in range ( 2 ) : NEW_LINE INDENT for new in OK : NEW_LINE INDENT leq = new < int ( N [ dig ] ) or ( less == 1 and int ( N [ dig ] ) == new ) NEW_LINE dp [ dig + 1 ] [ leq ] += dp [ dig ] [ less ] NEW_LINE DEDENT DEDENT DEDENT return dp [ L ] [ 1 ] NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT A , B = input ( ) . split ( ) NEW_LINE noKinsi = cnt ( B ) - cnt ( str ( int ( A ) - 1 ) ) NEW_LINE ans = int ( B ) - int ( A ) - noKinsi + 1 NEW_LINE print ( ans ) NEW_LINE DEDENT solve ( ) NEW_LINE",
"from collections import defaultdict 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 II ( ) : return int ( input ( ) ) NEW_LINE def LS ( ) : return input ( ) . split ( ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def IIR ( n ) : return [ II ( ) 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 mod = 1000000007 NEW_LINE a , b = LS ( ) NEW_LINE a = list ( map ( int , a ) ) NEW_LINE b = list ( map ( int , b ) ) NEW_LINE for i in range ( len ( b ) - len ( a ) ) : NEW_LINE INDENT a . insert ( 0 , 0 ) NEW_LINE DEDENT n = len ( b ) NEW_LINE dp = [ [ [ [ 0 for i in range ( 2 ) ] for j in range ( 2 ) ] for h in range ( 2 ) ] for k in range ( 20 ) ] NEW_LINE dp [ 0 ] [ 0 ] [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( 2 ) : NEW_LINE INDENT for k in range ( 2 ) : NEW_LINE INDENT for h in range ( 2 ) : NEW_LINE INDENT x = 0 if j else a [ i ] NEW_LINE y = 9 if k else b [ i ] NEW_LINE for d in range ( x , y + 1 ) : NEW_LINE INDENT dp [ i + 1 ] [ j or d > a [ i ] ] [ k or d < b [ i ] ] [ h or d == 4 or d == 9 ] += dp [ i ] [ j ] [ k ] [ h ] NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT ans = 0 NEW_LINE for j in range ( 2 ) : NEW_LINE INDENT for k in range ( 2 ) : NEW_LINE INDENT ans += dp [ n ] [ j ] [ k ] [ 1 ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE NEW_LINE"
] |
atcoder_agc026_C | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; String s = in . next ( ) ; char [ ] l = new char [ n ] ; char [ ] r = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = s . charAt ( i ) ; r [ i ] = s . charAt ( 2 * n - 1 - i ) ; } char [ ] [ ] buf = new char [ 2 ] [ n ] ; long count = 0 ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int [ ] p = new int [ 2 ] ; for ( int j = 0 ; j < n ; j ++ ) { int k = ( i >> j ) & 1 ; buf [ k ] [ p [ k ] ++ ] = l [ j ] ; } long [ ] [ ] dp = new long [ p [ 0 ] + 1 ] [ p [ 1 ] + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int x = 0 ; x <= p [ 0 ] ; x ++ ) { for ( int y = 0 ; y <= p [ 1 ] ; y ++ ) { if ( x < p [ 0 ] && r [ x + y ] == buf [ 0 ] [ x ] ) { dp [ x + 1 ] [ y ] += dp [ x ] [ y ] ; } if ( y < p [ 1 ] && r [ x + y ] == buf [ 1 ] [ y ] ) { dp [ x ] [ y + 1 ] += dp [ x ] [ y ] ; } } } count += dp [ p [ 0 ] ] [ p [ 1 ] ] ; } System . out . println ( count ) ; in . close ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; HashMap < String , Long > h = new HashMap < > ( ) ; for ( int i = 0 ; i < 1 << n ; i ++ ) { String red = \" \" ; String blue = \" \" ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) { red += s . charAt ( j ) ; } else { blue += s . charAt ( j ) ; } } String key = red + \" : \" + blue ; long tmp = h . getOrDefault ( key , 0L ) ; h . put ( key , tmp + 1 ) ; } long ans = 0 ; for ( int i = 0 ; i < 1 << n ; i ++ ) { String red = \" \" ; String blue = \" \" ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) { red += s . charAt ( 2 * n - 1 - j ) ; } else { blue += s . charAt ( 2 * n - 1 - j ) ; } } String key = red + \" : \" + blue ; long tmp = h . getOrDefault ( key , 0L ) ; ans += tmp ; } System . out . println ( ans ) ; } }",
"import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char s1 [ ] = s . substring ( 0 , n ) . toCharArray ( ) ; char s2 [ ] = new StringBuilder ( s . substring ( n , 2 * n ) ) . reverse ( ) . toString ( ) . toCharArray ( ) ; Map < String , Long > map1 = new HashMap < > ( ) ; Map < String , Long > map2 = new HashMap < > ( ) ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { StringBuilder red1 = new StringBuilder ( ) ; StringBuilder blue1 = new StringBuilder ( ) ; StringBuilder red2 = new StringBuilder ( ) ; StringBuilder blue2 = new StringBuilder ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i >> j ) % 2 == 1 ) { red1 . append ( s1 [ j ] ) ; blue2 . append ( s2 [ j ] ) ; } else { blue1 . append ( s1 [ j ] ) ; red2 . append ( s2 [ j ] ) ; } } String key1 = red1 . toString ( ) + \" : \" + blue1 . toString ( ) ; map1 . compute ( key1 , ( k , v ) -> v == null ? 1 : v + 1 ) ; String key2 = red2 . toString ( ) + \" : \" + blue2 . toString ( ) ; map2 . compute ( key2 , ( k , v ) -> v == null ? 1 : v + 1 ) ; } long sum = 0 ; for ( Map . Entry < String , Long > entry : map1 . entrySet ( ) ) { String key = entry . getKey ( ) ; sum += entry . getValue ( ) * map2 . getOrDefault ( key , 0L ) ; } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char [ ] a = new char [ n ] , b = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s . charAt ( i ) ; b [ i ] = s . charAt ( 2 * n - 1 - i ) ; } HashMap < String , Long > am = get ( a ) , bm = get ( b ) ; Set < String > keyset = am . keySet ( ) ; long res = 0 ; for ( String str : keyset ) { try { long aa = am . get ( str ) , bb = bm . get ( str ) ; res += aa * bb ; } catch ( Exception e ) { } } System . out . println ( res ) ; } static HashMap < String , Long > get ( char [ ] a ) { int n = a . length ; HashMap < String , Long > map = new HashMap < > ( ) ; int jou = 1 << n ; for ( int i = 0 ; i < jou ; i ++ ) { String tane = \" \" ; String taneb = \" \" ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( ( i >> j ) & 1 ) == 1 ) { tane += a [ j ] ; } else { taneb += a [ j ] ; } } String key = tane + \" : \" + taneb ; if ( map . containsKey ( key ) ) { map . put ( key , map . get ( key ) + 1 ) ; } else map . put ( key , 1L ) ; } return map ; } }"
] | [
"n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE sl = s [ : n ] NEW_LINE sr = s [ n : ] [ : : - 1 ] NEW_LINE from collections import Counter NEW_LINE l = Counter ( ) NEW_LINE r = Counter ( ) NEW_LINE from itertools import product NEW_LINE for m in product ( [ False , True ] , repeat = n ) : NEW_LINE INDENT key = [ sl [ i ] for i in range ( n ) if not m [ i ] ] NEW_LINE key += [ ' - ' ] NEW_LINE key += [ sl [ i ] for i in range ( n ) if m [ i ] ] NEW_LINE l [ ' ' . join ( key ) ] += 1 NEW_LINE key = [ sr [ i ] for i in range ( n ) if not m [ i ] ] NEW_LINE key += [ ' - ' ] NEW_LINE key += [ sr [ i ] for i in range ( n ) if m [ i ] ] NEW_LINE r [ ' ' . join ( key ) ] += 1 NEW_LINE DEDENT ans = sum ( l [ lk ] * r [ lk ] for lk in l . keys ( ) ) NEW_LINE print ( ans ) NEW_LINE",
"import itertools as it NEW_LINE from collections import Counter as c NEW_LINE n = int ( input ( ) ) NEW_LINE a = c ( ) NEW_LINE b = c ( ) NEW_LINE s = input ( ) NEW_LINE q = s [ : n ] NEW_LINE r = s [ n : ] [ : : - 1 ] NEW_LINE for i in it . product ( [ 0 , 1 ] , repeat = n ) : NEW_LINE INDENT d , e , f , g = \" \" , \" \" , \" \" , \" \" NEW_LINE for j in range ( n ) : NEW_LINE INDENT if i [ j ] == 1 : NEW_LINE INDENT d += q [ j ] NEW_LINE f += r [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT e += q [ j ] NEW_LINE g += r [ j ] NEW_LINE DEDENT DEDENT a [ d , e ] += 1 NEW_LINE b [ f , g ] += 1 NEW_LINE DEDENT print ( sum ( a [ i ] * b [ i ] for i in a . keys ( ) ) ) NEW_LINE",
"from itertools import product , compress NEW_LINE from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE Ss = input ( ) NEW_LINE S1s = Ss [ : N ] NEW_LINE ptn1s = [ ' ' . join ( compress ( S1s , sels ) ) for sels in product ( range ( 2 ) , repeat = N ) ] NEW_LINE cnt1 = Counter ( [ ( red , blue ) for red , blue in zip ( ptn1s , reversed ( ptn1s ) ) ] ) NEW_LINE S2s = Ss [ N : ] [ : : - 1 ] NEW_LINE ptn2s = [ ' ' . join ( compress ( S2s , sels ) ) for sels in product ( range ( 2 ) , repeat = N ) ] NEW_LINE cnt2 = Counter ( [ ( red , blue ) for red , blue in zip ( ptn2s , reversed ( ptn2s ) ) ] ) NEW_LINE ans = 0 NEW_LINE for ptn1 , num1 in cnt1 . items ( ) : NEW_LINE INDENT ans += num1 * cnt2 [ ptn1 ] NEW_LINE DEDENT print ( ans ) NEW_LINE",
"def run ( n , s ) : NEW_LINE INDENT sl = s [ 0 : n ] NEW_LINE sr = s [ n : 2 * n ] [ : : - 1 ] NEW_LINE dic = { } NEW_LINE keys = [ ] NEW_LINE cnt = 0 NEW_LINE for i in range ( 2 ** n ) : NEW_LINE INDENT red , blue , red2 , blue2 = ' ' , ' ' , ' ' , ' ' NEW_LINE bits = bin ( 2 ** n + i ) [ 3 : ] NEW_LINE for j in range ( n ) : NEW_LINE INDENT if bits [ j ] == '0' : NEW_LINE INDENT red += sl [ j ] NEW_LINE red2 += sr [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT blue += sl [ j ] NEW_LINE blue2 += sr [ j ] NEW_LINE DEDENT DEDENT keys . append ( red2 + ' - ' + blue2 ) NEW_LINE key = red + ' - ' + blue NEW_LINE if key not in dic . keys ( ) : NEW_LINE INDENT dic [ key ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic [ key ] += 1 NEW_LINE DEDENT DEDENT for key in keys : NEW_LINE INDENT cnt += dic . get ( key , 0 ) NEW_LINE DEDENT return cnt NEW_LINE DEDENT def read_line ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE return ( n , s ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n , s = read_line ( ) NEW_LINE print ( run ( n , s ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"from itertools import product NEW_LINE from collections import defaultdict NEW_LINE n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE sa , sb = s [ : n ] , s [ n : ] [ : : - 1 ] NEW_LINE a , b , ans = defaultdict ( int ) , defaultdict ( int ) , 0 NEW_LINE for p in product ( range ( 2 ) , repeat = n ) : NEW_LINE INDENT word_a_1 , word_b_1 , word_a_2 , word_b_2 = \" \" , \" \" , \" \" , \" \" NEW_LINE for j in range ( n ) : NEW_LINE INDENT if p [ j ] : NEW_LINE INDENT word_a_1 += sa [ j ] NEW_LINE word_b_1 += sb [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT word_a_2 += sa [ j ] NEW_LINE word_b_2 += sb [ j ] NEW_LINE DEDENT DEDENT a [ ( word_a_1 , word_a_2 ) ] += 1 NEW_LINE b [ ( word_b_1 , word_b_2 ) ] += 1 NEW_LINE DEDENT while a : NEW_LINE INDENT key , value = a . popitem ( ) NEW_LINE ans += value * b [ key ] NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc039_B | [
"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 ) { out . println ( ( int ) Math . pow ( in . ints ( ) , 0.25 ) ) ; } } 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 ; class Main { static int n ; static long ans = 1000000000 ; static int [ ] memo ; static int [ ] dp ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; long ans = ( long ) Math . sqrt ( a ) ; ans = ( long ) Math . sqrt ( ans ) ; System . out . println ( ans ) ; } } class Pair implements Comparable { int from ; int end ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return end - otherpair . end ; } }",
"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 ) { int n = in . nextInt ( ) ; out . println ( ( int ) Math . sqrt ( Math . sqrt ( n ) ) ) ; } } 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 ; } 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 isSpaceChar ( int c ) { return c == ' β ' || c == ' \\n ' || c == ' \\r ' || c == ' \\t ' || c == - 1 ; } public long nextLong ( ) { long n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } public int nextInt ( ) { long n = nextLong ( ) ; if ( n < Integer . MIN_VALUE || n > Integer . MAX_VALUE ) throw new NumberFormatException ( ) ; return ( int ) n ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double N = sc . nextDouble ( ) ; N = Math . sqrt ( N ) ; N = Math . sqrt ( N ) ; System . out . println ( ( int ) N ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; int ans = 1 ; for ( int i = 1 ; i < x ; i ++ ) { long tmp = i * i * i * i ; if ( tmp == x ) { ans = i ; break ; } else if ( tmp > x ) break ; } System . out . println ( ans ) ; } }"
] | [
"X = int ( input ( ) ) NEW_LINE tmp = 1 NEW_LINE while 10 ** 9 > tmp : NEW_LINE INDENT if tmp ** 4 == X : NEW_LINE INDENT print ( tmp ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT tmp += 1 NEW_LINE DEDENT DEDENT",
"import math NEW_LINE x = int ( input ( ) ) NEW_LINE print ( int ( math . sqrt ( math . sqrt ( x ) ) ) ) NEW_LINE",
"def agent_takahashi ( X : int ) -> int : NEW_LINE INDENT for n in range ( 400 ) : NEW_LINE INDENT if n * n * n * n == X : NEW_LINE INDENT return n NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT X = int ( input ( ) ) NEW_LINE ans = agent_takahashi ( X ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"print ( int ( int ( input ( ) ) ** 0.25 ) ) NEW_LINE",
"x = int ( input ( ) ) NEW_LINE for i in range ( x + 1 ) : NEW_LINE INDENT if i ** 4 == x : NEW_LINE INDENT print ( i ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT"
] |
atcoder_arc087_A | [
"import java . util . * ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; m . put ( a , m . containsKey ( a ) ? m . get ( a ) + 1 : 1 ) ; } int s = 0 ; for ( Entry < Integer , Integer > e : m . entrySet ( ) ) { int k = e . getKey ( ) ; int v = e . getValue ( ) ; if ( k <= v ) { s += v - k ; } else { s += v ; } } System . out . println ( s ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { int n ; int [ ] as ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; as = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { as [ i ] = sc . nextInt ( ) ; } solve ( ) ; } void solve ( ) { Arrays . sort ( as ) ; int ans = 0 ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { count ++ ; if ( as [ i - 1 ] < as [ i ] ) { if ( count < as [ i - 1 ] ) { ans += count ; } else { ans += count - as [ i - 1 ] ; } count = 0 ; } } count ++ ; if ( count < as [ as . length - 1 ] ) { ans += count ; } else { ans += count - as [ as . length - 1 ] ; } System . out . println ( ans ) ; } 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 java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; import java . util . stream . IntStream ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] a = IntStream . range ( 0 , N ) . map ( i -> scan . nextInt ( ) ) . toArray ( ) ; Map < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { if ( ! map . containsKey ( a [ i ] ) ) { map . put ( a [ i ] , 0 ) ; } map . put ( a [ i ] , map . get ( a [ i ] ) + 1 ) ; } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry : map . entrySet ( ) ) { if ( entry . getKey ( ) > entry . getValue ( ) ) { ans += entry . getValue ( ) ; } else { ans += entry . getValue ( ) - entry . getKey ( ) ; } } System . out . println ( ans ) ; } }",
"import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; int num = scanner . nextInt ( ) ; for ( int i = 0 ; i < num ; i ++ ) { list . add ( scanner . nextInt ( ) ) ; } scanner . close ( ) ; Collections . sort ( list ) ; int stock = 0 ; int count = 0 ; int stockNum = 0 ; for ( int i : list ) { if ( stock != i ) { stock = i ; count = i ; } count -- ; if ( count == 0 ) { stockNum += stock ; } } System . out . println ( list . size ( ) - stockNum ) ; } }",
"import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Integer , Integer > cnt = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x = sc . nextInt ( ) ; int c = 1 ; if ( cnt . containsKey ( x ) ) { c = cnt . get ( x ) + 1 ; } cnt . put ( x , c ) ; } int ans = 0 ; for ( int x : cnt . keySet ( ) ) { int c = cnt . get ( x ) ; if ( c < x ) { ans += c ; } else if ( c > x ) { ans += c - x ; } } System . out . println ( ans ) ; } } }"
] | [
"import collections NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE c = collections . Counter ( a ) NEW_LINE k = 0 NEW_LINE for s , t in c . items ( ) : NEW_LINE INDENT if t < s : NEW_LINE INDENT k += t NEW_LINE DEDENT else : NEW_LINE INDENT k += t - s NEW_LINE DEDENT DEDENT print ( k ) NEW_LINE",
"from collections import defaultdict NEW_LINE def getN ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT def getMN ( ) : NEW_LINE INDENT a = input ( ) . split ( ) NEW_LINE b = [ int ( i ) for i in a ] NEW_LINE return b [ 0 ] , b [ 1 ] NEW_LINE DEDENT def getlist ( ) : NEW_LINE INDENT a = input ( ) . split ( ) NEW_LINE b = [ int ( i ) for i in a ] NEW_LINE return b NEW_LINE DEDENT n = getN ( ) NEW_LINE nums = getlist ( ) NEW_LINE kazu = defaultdict ( int ) NEW_LINE for i in nums : NEW_LINE INDENT kazu [ i ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for x in kazu . keys ( ) : NEW_LINE INDENT if kazu [ x ] >= x : NEW_LINE INDENT ans += kazu [ x ] - x NEW_LINE DEDENT else : NEW_LINE INDENT ans += kazu [ x ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE from collections import Counter NEW_LINE n = ni ( ) NEW_LINE a = list ( li ( ) ) NEW_LINE cnt = Counter ( a ) NEW_LINE ans = 0 NEW_LINE for k , v in cnt . items ( ) : NEW_LINE INDENT if v < k : NEW_LINE INDENT ans += v NEW_LINE DEDENT elif v > k : NEW_LINE INDENT ans += ( v - k ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE d = { } NEW_LINE for i in a : d [ i ] = d . get ( i , 0 ) + 1 NEW_LINE print ( sum ( d [ i ] - i * ( d [ i ] >= i ) for i in d ) ) NEW_LINE",
"import collections NEW_LINE def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE A = collections . Counter ( inpl ( ) ) NEW_LINE ans = 0 NEW_LINE for i in A . keys ( ) : NEW_LINE INDENT if i > A [ i ] : NEW_LINE INDENT ans += A [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT ans += A [ i ] - i NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE"
] |
atcoder_arc072_C | [
"import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int [ ] x = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) x [ i ] = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; long [ ] qq = new long [ Q ] ; for ( int i = 0 ; i < Q ; i ++ ) qq [ i ] = ( sc . nextLong ( ) - 1 ) << 30 | i ; Arrays . sort ( qq ) ; int [ ] rest = new int [ N + 1 ] ; rest [ 0 ] = D ; for ( int i = 0 ; i < N ; i ++ ) rest [ i + 1 ] = Math . min ( rest [ i ] , Math . abs ( rest [ i ] - x [ i ] ) ) ; boolean [ ] ans = new boolean [ Q ] ; long range = 0 ; int idx = Q - 1 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { while ( idx >= 0 && ( qq [ idx ] >> 30 ) == i ) { if ( rest [ i ] > range ) { ans [ ( int ) ( qq [ idx ] & ( ( 1 << 30 ) - 1 ) ) ] = true ; } idx -- ; } if ( x [ i ] <= range * 2 + 1 ) { range += x [ i ] ; } } for ( int i = 0 ; i < Q ; i ++ ) pw . println ( ans [ i ] ? \" YES \" : \" NO \" ) ; sc . close ( ) ; pw . close ( ) ; } }"
] | [
"N , D = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE d = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = int ( input ( ) ) NEW_LINE q = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = [ D for i in range ( N ) ] NEW_LINE b = [ 1 for i in range ( N + 1 ) ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT a [ i ] = min ( abs ( a [ i - 1 ] - d [ i - 1 ] ) , a [ i - 1 ] ) NEW_LINE DEDENT for i in range ( N ) [ : : - 1 ] : NEW_LINE INDENT if d [ i ] // 2 < b [ i + 1 ] : NEW_LINE INDENT b [ i ] = b [ i + 1 ] + d [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT b [ i ] = b [ i + 1 ] NEW_LINE DEDENT DEDENT res = \" \" NEW_LINE for i in q : NEW_LINE INDENT if a [ i - 1 ] < b [ i ] : NEW_LINE INDENT res += \" NO \" NEW_LINE DEDENT else : NEW_LINE INDENT res += \" YES \" NEW_LINE DEDENT res += \" \\n \" NEW_LINE DEDENT print ( res ) NEW_LINE",
"import sys NEW_LINE import math NEW_LINE N , D = map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) NEW_LINE ds = list ( map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) ) NEW_LINE Q , = map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) NEW_LINE qs = list ( map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) ) NEW_LINE targets = [ 1 ] NEW_LINE for d in reversed ( ds ) : NEW_LINE INDENT if ( d // 2 < targets [ - 1 ] ) : NEW_LINE INDENT targets . append ( targets [ - 1 ] + d ) NEW_LINE DEDENT else : NEW_LINE INDENT targets . append ( targets [ - 1 ] ) NEW_LINE DEDENT DEDENT targets . reverse ( ) NEW_LINE current = D NEW_LINE can_avoids = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT d = ds [ i ] NEW_LINE target = targets [ i + 1 ] NEW_LINE can_avoids . append ( current >= target ) NEW_LINE if d // 2 < current : NEW_LINE INDENT current -= d NEW_LINE current = max ( - current , current ) NEW_LINE DEDENT DEDENT for q in qs : NEW_LINE INDENT if ( can_avoids [ q - 1 ] ) : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT DEDENT exit ( 0 ) NEW_LINE",
"N , start = map ( int , input ( ) . split ( ) ) NEW_LINE D = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE input ( ) NEW_LINE Q = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = [ ( k - 1 , i ) for i , k in enumerate ( Q ) ] NEW_LINE Q . sort ( ) NEW_LINE P = [ start ] NEW_LINE for d in D : NEW_LINE INDENT a = P [ - 1 ] NEW_LINE b = abs ( a - d ) NEW_LINE P . append ( min ( a , b ) ) NEW_LINE DEDENT result = [ None ] * len ( Q ) NEW_LINE x = 1 NEW_LINE for i , d in zip ( reversed ( range ( len ( D ) ) ) , reversed ( D ) ) : NEW_LINE INDENT if Q [ - 1 ] [ 0 ] == i : NEW_LINE INDENT result [ Q [ - 1 ] [ 1 ] ] = P [ i ] >= x NEW_LINE Q . pop ( ) NEW_LINE if not Q : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if abs ( x - d ) < x : NEW_LINE INDENT x += d NEW_LINE DEDENT DEDENT for r in result : NEW_LINE INDENT print ( ' YES ' if r else ' NO ' ) NEW_LINE DEDENT",
"N , D = map ( int , input ( ) . split ( ) ) NEW_LINE ds = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = int ( input ( ) ) NEW_LINE querys = list ( map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) ) NEW_LINE ps = [ 0 ] * ( N + 1 ) NEW_LINE ps [ 0 ] = D NEW_LINE for i in range ( N ) : NEW_LINE INDENT ps [ i + 1 ] = min ( abs ( ps [ i ] - ds [ i ] ) , ps [ i ] ) NEW_LINE DEDENT if ps [ N ] != 0 : NEW_LINE INDENT print ( ' \\n ' . join ( [ ' YES ' ] * Q ) ) NEW_LINE exit ( ) NEW_LINE DEDENT ms = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) [ : : - 1 ] : NEW_LINE INDENT if ms [ i + 1 ] + 1 >= ds [ i ] - ms [ i + 1 ] : NEW_LINE INDENT ms [ i ] = ms [ i + 1 ] + ds [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT ms [ i ] = ms [ i + 1 ] NEW_LINE DEDENT DEDENT for q in querys : NEW_LINE INDENT if ps [ q ] <= ms [ q + 1 ] : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT DEDENT",
"N , D = map ( int , input ( ) . split ( ) ) NEW_LINE dv = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = int ( input ( ) ) NEW_LINE qv = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dist_alice = D NEW_LINE dist_alice_list = [ D ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if dist_alice >= dv [ i ] : NEW_LINE INDENT dist_alice -= dv [ i ] NEW_LINE DEDENT elif 2 * dist_alice >= dv [ i ] : NEW_LINE INDENT dist_alice = dv [ i ] - dist_alice NEW_LINE DEDENT dist_alice_list . append ( dist_alice ) NEW_LINE DEDENT sol_min = [ 1 ] NEW_LINE sol_min_ = 1 NEW_LINE for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if 2 * sol_min_ > dv [ i ] : NEW_LINE INDENT sol_min_ += dv [ i ] NEW_LINE DEDENT sol_min . append ( sol_min_ ) NEW_LINE DEDENT for i in range ( Q ) : NEW_LINE INDENT if dist_alice_list [ qv [ i ] - 1 ] >= sol_min [ N - qv [ i ] ] : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT DEDENT"
] |
atcoder_arc068_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; int min = a [ 0 ] ; int max = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] < min ) min = a [ i ] ; else if ( a [ i ] > max ) max = a [ i ] ; } boolean [ ] hash = new boolean [ max - min + 1 ] ; for ( int i = 0 ; i < hash . length ; i ++ ) hash [ i ] = false ; int identity = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! hash [ a [ i ] - min ] ) { identity ++ ; hash [ a [ i ] - min ] = true ; } } System . out . println ( String . valueOf ( identity - ( ( identity + 1 ) % 2 ) ) ) ; } }",
"import java . util . * ; import java . io . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; public class Main { static final long mod = 1000000007 ; public static void main ( String [ ] args ) throws Exception , IOException { Reader sc = new Reader ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; int a [ ] = new int [ 100001 ] ; int ans = 0 , even = 0 , odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ sc . nextInt ( ) ] ++ ; } for ( int i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] > 0 ) { if ( a [ i ] % 2 == 0 ) even ++ ; ans ++ ; } } if ( even % 2 == 1 ) ans -- ; out . println ( ans ) ; out . flush ( ) ; } static void db ( Object ... os ) { System . err . println ( Arrays . deepToString ( os ) ) ; } } class P implements Comparable < P > { int id , d ; P ( int id , int d ) { this . id = id ; this . d = d ; } public int compareTo ( P p ) { return d - p . d ; } } class Reader { private BufferedReader x ; private StringTokenizer st ; public Reader ( InputStream in ) { x = new BufferedReader ( new InputStreamReader ( in ) ) ; st = null ; } public String nextString ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( x . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( nextString ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( nextString ( ) ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( nextString ( ) ) ; } }",
"import java . io . IOException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . Scanner ; class Main { public static void main ( String args [ ] ) throws IOException { @ SuppressWarnings ( \" resource \" ) Scanner cin = new Scanner ( System . in ) ; ArrayList < String > inLines = new ArrayList < String > ( ) ; for ( ; cin . hasNext ( ) ; ) { inLines . add ( cin . nextLine ( ) ) ; } Solver solver = new Solver ( ) ; solver . solve ( inLines ) ; } } class Solver { public void solve ( ArrayList < String > inLines ) { int N = Integer . parseInt ( inLines . get ( 0 ) ) ; String [ ] strArr = inLines . get ( 1 ) . split ( \" β \" ) ; HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int An = Integer . parseInt ( strArr [ i ] ) ; if ( map . containsKey ( An ) ) map . put ( An , map . get ( An ) + 1 ) ; else map . put ( An , 1 ) ; } int cnt = 0 ; for ( int key : map . keySet ( ) ) { if ( map . get ( key ) % 2 == 0 ) { cnt ++ ; } } if ( cnt % 2 == 0 ) System . out . println ( map . size ( ) ) ; else System . out . println ( map . size ( ) - 1 ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; int [ ] as ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; as = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { as [ i ] = sc . nextInt ( ) ; } solve ( ) ; } void solve ( ) { Arrays . sort ( as ) ; Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { set . add ( as [ i ] ) ; } if ( set . size ( ) % 2 == 1 ) { System . out . println ( set . size ( ) ) ; } else { System . out . println ( set . size ( ) - 1 ) ; } } 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 java . util . * ; import java . lang . * ; import java . io . * ; class Counter < T > extends HashMap < T , Integer > { public Counter ( ) { super ( ) ; } public Counter ( T [ ] array ) { super ( ) ; for ( int i = 0 ; i < array . length ; i ++ ) add ( array [ i ] ) ; } public Integer get ( Object elm ) { return getOrDefault ( elm , 0 ) ; } public void add ( T elm ) { put ( elm , get ( elm ) + 1 ) ; } } public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] A = new Integer [ N ] ; for ( int n = 0 ; n < N ; n ++ ) A [ n ] = sc . nextInt ( ) ; Counter < Integer > count = new Counter ( A ) ; if ( ( N - count . size ( ) ) % 2 == 0 ) System . out . println ( count . size ( ) ) ; else System . out . println ( count . size ( ) - 1 ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details ."
] | [
"n = int ( input ( ) ) NEW_LINE lis = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = set ( ) NEW_LINE for num in lis : ans . add ( num ) NEW_LINE print ( len ( ans ) - ( ( len ( ans ) % 2 ) + 1 ) % 2 ) NEW_LINE",
"from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) . rstrip ( ) ) NEW_LINE A = list ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE dict = { } NEW_LINE for a in A : NEW_LINE INDENT if a in dict : NEW_LINE INDENT dict [ a ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT dict [ a ] = 1 NEW_LINE DEDENT DEDENT sum = 0 NEW_LINE for v in dict . values ( ) : NEW_LINE INDENT if v >= 2 : NEW_LINE INDENT sum += v - 1 NEW_LINE DEDENT DEDENT if sum % 2 == 0 : NEW_LINE INDENT ans = len ( dict ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = len ( dict ) - 1 NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"from collections import Counter NEW_LINE def inpl ( ) : NEW_LINE INDENT return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE A = inpl ( ) NEW_LINE oe = [ 0 , 0 ] NEW_LINE for k , v in Counter ( A ) . items ( ) : NEW_LINE INDENT oe [ v % 2 ] += 1 NEW_LINE DEDENT if oe [ 0 ] % 2 == 0 : NEW_LINE INDENT print ( sum ( oe ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( sum ( oe ) - 1 ) NEW_LINE DEDENT",
"def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE an = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE k = len ( set ( an ) ) NEW_LINE res = k - 1 if k % 2 == 0 else k NEW_LINE print ( res ) NEW_LINE DEDENT main ( ) NEW_LINE",
"from collections import Counter NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE Num = list ( input ( ) . split ( ) ) NEW_LINE C = Counter ( Num ) NEW_LINE ans = 0 NEW_LINE l = [ 0 ] NEW_LINE v = len ( C ) NEW_LINE odd = len ( list ( filter ( lambda x : x % 2 == 1 , C . values ( ) ) ) ) NEW_LINE even = v - odd NEW_LINE ans += odd + even // 2 * 2 NEW_LINE print ( ans ) NEW_LINE"
] |
atcoder_arc031_A | [
"import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner scanner = new Scanner ( System . in ) ; String name = scanner . next ( ) ; boolean flag = true ; for ( int i = 0 ; i < name . length ( ) / 2 ; i ++ ) { if ( name . charAt ( i ) != name . charAt ( name . length ( ) - 1 - i ) ) { flag = false ; break ; } } if ( flag ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { Scanner scanner = null ; char [ ] name = null ; try { scanner = new Scanner ( System . in ) ; name = scanner . next ( ) . toCharArray ( ) ; int half = name . length % 2 == 0 ? name . length / 2 : ( name . length / 2 ) + 1 ; int length = name . length - 1 ; boolean isKaibun = true ; for ( int i = 0 ; i < half ; i ++ ) { if ( name [ i ] != name [ length - i ] ) { isKaibun = false ; } } if ( isKaibun ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveB ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveC ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveD ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String name = sc . next ( ) ; String names [ ] = name . split ( \" \" ) ; String ans = \" \" ; if ( name . length ( ) % 2 == 0 ) { String a = name . substring ( 0 , name . length ( ) / 2 ) ; String b = name . substring ( ( name . length ( ) / 2 ) , name . length ( ) ) ; String [ ] aa = a . split ( \" \" ) ; String [ ] bb = b . split ( \" \" ) ; for ( int i = 0 ; i < a . length ( ) ; i ++ ) { if ( ! aa [ i ] . equals ( bb [ b . length ( ) - ( i + 1 ) ] ) ) { ans = \" NO \" ; } else { ans = \" YES \" ; } } } else { int j = name . length ( ) - 1 ; int l = ( j / 2 ) ; String c = name . substring ( 0 , l ) ; String d = name . substring ( l + 1 , name . length ( ) ) ; String [ ] cc = c . split ( \" \" ) ; String [ ] dd = d . split ( \" \" ) ; for ( int k = 0 ; k < l ; k ++ ) { if ( ! cc [ k ] . equals ( dd [ d . length ( ) - ( k + 1 ) ] ) ) { ans = \" NO \" ; } else { ans = \" YES \" ; } } } System . out . println ( ans ) ; } }",
"import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { char [ ] in = s . next ( ) . toCharArray ( ) ; for ( int i = in . length / 2 ; i >= 0 ; i -- ) { if ( in [ in . length - i - 1 ] != in [ i ] ) { System . out . println ( \" NO \" ) ; return ; } } System . out . println ( \" YES \" ) ; } }",
"import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( s . length ( ) - 1 - i ) ) { out . println ( \" NO \" ) ; exit ( 0 ) ; } } out . println ( \" YES \" ) ; } }"
] | [
"s = input ( ) NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if s [ i ] != s [ n - 1 - i ] : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( \" YES \" ) NEW_LINE",
"s = str ( input ( ) ) NEW_LINE S = s [ : : - 1 ] NEW_LINE if s == S : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT",
"Name = input ( ) NEW_LINE print ( ' YES ' if all ( [ Name [ k ] == Name [ - 1 - k ] for k in range ( len ( Name ) // 2 ) ] ) else ' NO ' ) NEW_LINE",
"s = input ( ) NEW_LINE x = len ( s ) NEW_LINE if x % 2 == 1 : NEW_LINE INDENT a = s [ : x // 2 ] NEW_LINE b = s [ x // 2 + 1 : ] [ : : - 1 ] NEW_LINE if a == b : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT a = s [ : x // 2 ] NEW_LINE b = s [ x // 2 : ] [ : : - 1 ] NEW_LINE if a == b : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT DEDENT",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE s = input ( ) NEW_LINE s = s [ : - 1 ] NEW_LINE s_rev = reversed ( s ) NEW_LINE for i , j in zip ( s , s_rev ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( \" YES \" ) NEW_LINE"
] |
atcoder_arc097_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int p [ ] = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } DS ds = new DS ( N + 1 ) ; for ( int i = 1 ; i <= M ; i ++ ) { ds . union ( sc . nextInt ( ) , sc . nextInt ( ) ) ; } int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( p [ i ] == i ) { ans ++ ; } else if ( ds . root ( i ) == ds . root ( p [ i ] ) ) { ans ++ ; } } System . out . println ( ans ) ; } static class DS { int [ ] parent ; int [ ] counter ; DS ( int n ) { parent = new int [ n ] ; counter = new int [ n ] ; Arrays . fill ( counter , 1 ) ; Arrays . setAll ( parent , i -> i ) ; } int root ( int a ) { int q = a ; while ( q != parent [ q ] ) { q = parent [ q ] ; } while ( a != q ) { int next = parent [ a ] ; parent [ a ] = q ; a = next ; } return q ; } void union ( int i , int j ) { int ri = root ( i ) ; int rj = root ( j ) ; if ( ri == rj ) { return ; } if ( counter [ rj ] < counter [ ri ] ) { int s = ri ; ri = rj ; rj = s ; } parent [ ri ] = rj ; counter [ rj ] += counter [ ri ] ; } } }",
"import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int p [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int data [ ] = new int [ n ] ; init ( n , data ) ; for ( int i = 0 ; i < m ; i ++ ) { link ( sc . nextInt ( ) , sc . nextInt ( ) , data ) ; } int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isSame ( i + 1 , p [ i ] , data ) ) { cnt ++ ; } } System . out . println ( cnt ) ; } public void init ( int n , int data [ ] ) { for ( int i = 0 ; i < n ; i ++ ) { data [ i ] = i + 1 ; } } public void link ( int x , int y , int data [ ] ) { data [ root ( x , data ) - 1 ] = root ( y , data ) ; } public boolean isSame ( int x , int y , int data [ ] ) { return root ( x , data ) == root ( y , data ) ; } public int root ( int p , int data [ ] ) { return ( data [ p - 1 ] == p ) ? p : ( data [ p - 1 ] = root ( data [ p - 1 ] , data ) ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }",
"import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; } UnionFind uf = new UnionFind ( N + 1 ) ; for ( int i = 0 ; i < M ; i ++ ) { int x = scanner . nextInt ( ) ; int y = scanner . nextInt ( ) ; uf . union ( x , y ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( uf . find ( i + 1 ) == uf . find ( a [ i ] ) ) count ++ ; } System . out . println ( count ) ; } static class UnionFind { private final int [ ] table ; private final int [ ] ranks ; private final int [ ] sizes ; public UnionFind ( int size ) { this . table = new int [ size ] ; this . ranks = new int [ size ] ; this . sizes = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { table [ i ] = i ; sizes [ i ] = 1 ; } } public int find ( int x ) { if ( table [ x ] != x ) { table [ x ] = find ( table [ x ] ) ; } return table [ x ] ; } public void union ( int x , int y ) { int xRoot = find ( x ) ; int yRoot = find ( y ) ; if ( xRoot == yRoot ) return ; if ( ranks [ xRoot ] < ranks [ yRoot ] ) { int tmp = xRoot ; xRoot = yRoot ; yRoot = tmp ; } table [ yRoot ] = xRoot ; sizes [ xRoot ] += sizes [ yRoot ] ; if ( ranks [ xRoot ] == ranks [ yRoot ] ) ranks [ xRoot ] ++ ; } } }",
"import java . util . Scanner ; class Pair { int x ; int y ; public Pair ( int x , int y ) { this . x = x ; this . y = y ; } } class UnionFind { int [ ] par ; public UnionFind ( int N ) { par = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) par [ i ] = i ; } int root ( int x ) { if ( par [ x ] == x ) return x ; return par [ x ] = root ( par [ x ] ) ; } void unite ( int x , int y ) { int rx = root ( x ) ; int ry = root ( y ) ; if ( rx == ry ) return ; par [ rx ] = ry ; } boolean same ( int x , int y ) { int rx = root ( x ) ; int ry = root ( y ) ; return rx == ry ; } } public class Main { static int N ; static int M ; static int [ ] p ; static Pair [ ] sw ; static UnionFind uf ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; M = sc . nextInt ( ) ; p = new int [ N + 1 ] ; sw = new Pair [ M + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i <= M ; i ++ ) { sw [ i ] = new Pair ( sc . nextInt ( ) , sc . nextInt ( ) ) ; } uf = new UnionFind ( N + 1 ) ; for ( int i = 1 ; i <= M ; i ++ ) { Pair s = sw [ i ] ; uf . unite ( s . x , s . y ) ; } int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( uf . same ( i , p [ i ] ) ) sum ++ ; } System . out . println ( sum ) ; } }",
"import java . util . * ; public class Main { static int n , m ; static int [ ] p ; static int modP = 1000000007 ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; n = in . nextInt ( ) ; m = in . nextInt ( ) ; p = new int [ n ] ; UF uf = new UF ( n ) ; for ( int i = 0 ; i < n ; i ++ ) p [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int x = in . nextInt ( ) - 1 ; int y = in . nextInt ( ) - 1 ; uf . union ( x , y ) ; } int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( uf . same ( i , p [ i ] - 1 ) ) cnt ++ ; } print ( cnt ) ; } static void print ( String s ) { System . out . println ( s ) ; } static void print ( int i ) { System . out . println ( i ) ; } } class UF { int [ ] table , ranks ; UF ( int s ) { table = new int [ s ] ; ranks = new int [ s ] ; for ( int i = 0 ; i < s ; i ++ ) { table [ i ] = i ; } } public int find ( int x ) { if ( table [ x ] != x ) table [ x ] = find ( table [ x ] ) ; return table [ x ] ; } public void union ( int x , int y ) { int xR = find ( x ) ; int yR = find ( y ) ; if ( xR == yR ) return ; if ( ranks [ xR ] < ranks [ yR ] ) { table [ xR ] = yR ; } else { table [ yR ] = xR ; if ( ranks [ xR ] == ranks [ yR ] ) ranks [ xR ] ++ ; } } public boolean same ( int x , int y ) { return find ( x ) == find ( y ) ; } }"
] | [
"class UnionFind : NEW_LINE INDENT def __init__ ( self , N ) : NEW_LINE INDENT self . parent = [ i for i in range ( N ) ] NEW_LINE self . rank = [ 0 ] * N NEW_LINE DEDENT def find ( self , x ) : NEW_LINE INDENT if self . parent [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT self . parent [ x ] = self . find ( self . parent [ x ] ) NEW_LINE return self . parent [ x ] NEW_LINE DEDENT DEDENT def same ( self , x , y ) : NEW_LINE INDENT return self . find ( x ) == self . find ( y ) NEW_LINE DEDENT def union ( self , x , y ) : NEW_LINE INDENT x = self . find ( x ) NEW_LINE y = self . find ( y ) NEW_LINE if self . rank [ x ] < self . rank [ y ] : NEW_LINE INDENT self . parent [ x ] = y NEW_LINE DEDENT else : NEW_LINE INDENT self . parent [ y ] = x NEW_LINE if self . rank [ x ] == self . rank [ y ] : NEW_LINE INDENT self . rank [ x ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE P = list ( map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) ) NEW_LINE UF = UnionFind ( N ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT x , y = map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) NEW_LINE UF . union ( x , y ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if UF . find ( P [ i ] ) == UF . find ( i ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE p_ls = [ int ( i ) - 1 for i in input ( ) . split ( ) ] NEW_LINE par = [ i for i in range ( N ) ] NEW_LINE rank = [ 1 for i in range ( N ) ] NEW_LINE def find ( x ) : NEW_LINE INDENT if par [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT return find ( par [ x ] ) NEW_LINE DEDENT DEDENT def unite ( x , y ) : NEW_LINE INDENT x = find ( x ) NEW_LINE y = find ( y ) NEW_LINE if x == y : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT if rank [ x ] > rank [ y ] : NEW_LINE INDENT par [ y ] = x NEW_LINE rank [ x ] += rank [ y ] NEW_LINE DEDENT else : NEW_LINE INDENT par [ x ] = par [ y ] NEW_LINE rank [ y ] += rank [ x ] NEW_LINE DEDENT DEDENT DEDENT def is_same ( x , y ) : NEW_LINE INDENT if find ( x ) == find ( y ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT data_ls = list ( ) NEW_LINE for i in range ( M ) : NEW_LINE INDENT x , y = [ int ( i ) - 1 for i in input ( ) . split ( ) ] NEW_LINE if is_same ( x , y ) : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT unite ( x , y ) NEW_LINE DEDENT DEDENT cnt = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if is_same ( i , p_ls [ i ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE",
"def init ( n ) : NEW_LINE INDENT global par , rank NEW_LINE par = [ i for i in range ( n ) ] NEW_LINE rank = [ 0 ] * n NEW_LINE DEDENT def find ( x ) : NEW_LINE INDENT global par NEW_LINE if par [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT par [ x ] = find ( par [ x ] ) NEW_LINE return par [ x ] NEW_LINE DEDENT DEDENT def unite ( x , y ) : NEW_LINE INDENT global par , rank NEW_LINE x = find ( x ) NEW_LINE y = find ( y ) NEW_LINE if x == y : NEW_LINE INDENT return NEW_LINE DEDENT if rank [ x ] < rank [ y ] : NEW_LINE INDENT par [ x ] = y NEW_LINE DEDENT else : NEW_LINE INDENT par [ y ] = x NEW_LINE if rank [ x ] == rank [ y ] : NEW_LINE INDENT rank [ x ] += 1 NEW_LINE DEDENT DEDENT DEDENT def same ( x , y ) : NEW_LINE INDENT return find ( x ) == find ( y ) NEW_LINE DEDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE init ( N ) NEW_LINE p = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE unite ( x - 1 , y - 1 ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if same ( i , p [ i ] - 1 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"class UnionFind ( ) : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . n = n NEW_LINE self . par = [ - 1 for _ in range ( n ) ] NEW_LINE DEDENT def same ( self , x , y ) : NEW_LINE INDENT return self . root ( x ) == self . root ( y ) NEW_LINE DEDENT def root ( self , x ) : NEW_LINE INDENT if self . par [ x ] < 0 : NEW_LINE INDENT return x NEW_LINE DEDENT self . par [ x ] = self . root ( self . par [ x ] ) NEW_LINE return self . par [ x ] NEW_LINE DEDENT def unite ( self , x , y ) : NEW_LINE INDENT x = self . root ( x ) NEW_LINE y = self . root ( y ) NEW_LINE if x == y : NEW_LINE INDENT return NEW_LINE DEDENT if self . par [ x ] > self . par [ y ] : NEW_LINE INDENT x , y = y , x NEW_LINE DEDENT self . par [ x ] += self . par [ y ] NEW_LINE self . par [ y ] = x NEW_LINE DEDENT def size ( self , x ) : NEW_LINE INDENT return - self . par [ self . root ( x ) ] NEW_LINE DEDENT DEDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE pl = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE uf = UnionFind ( n + 1 ) NEW_LINE for _ in range ( m ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE uf . unite ( x , y ) NEW_LINE DEDENT res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if uf . same ( i + 1 , pl [ i ] ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE",
"n , m = map ( int , input ( ) . split ( ) ) NEW_LINE ps = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE xys = [ tuple ( map ( int , input ( ) . split ( ) ) ) for _ in range ( m ) ] NEW_LINE t = { p : p for p in ps } NEW_LINE def trace ( x ) : NEW_LINE INDENT route = [ x ] NEW_LINE while t [ x ] != x : NEW_LINE INDENT x = t [ x ] NEW_LINE route . append ( x ) NEW_LINE DEDENT for v in route : NEW_LINE INDENT t [ v ] = route [ - 1 ] NEW_LINE DEDENT return route NEW_LINE DEDENT for x , y in xys : NEW_LINE INDENT u = trace ( x ) [ - 1 ] NEW_LINE v = trace ( y ) [ - 1 ] NEW_LINE if u != v : NEW_LINE INDENT t [ u ] = v NEW_LINE DEDENT DEDENT avs = [ p for i , p in enumerate ( ps ) if trace ( i + 1 ) [ - 1 ] == trace ( p ) [ - 1 ] ] NEW_LINE print ( len ( avs ) ) NEW_LINE"
] |
atcoder_abc082_A | [
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double a = sc . nextDouble ( ) ; double b = sc . nextDouble ( ) ; System . out . println ( ( int ) Math . ceil ( ( a + b ) / 2 ) ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { start ( ) ; } public static void start ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; System . out . println ( ( int ) Math . ceil ( ( a + b ) / 2.0 ) ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { double a ; double b ; double x ; Scanner sc = new Scanner ( System . in ) ; a = sc . nextDouble ( ) ; b = sc . nextDouble ( ) ; x = ( a + b ) / 2 ; x = Math . ceil ( x ) ; System . out . println ( ( int ) x ) ; sc . close ( ) ; } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double a , b ; a = Double . parseDouble ( sc . next ( ) ) ; b = Double . parseDouble ( sc . next ( ) ) ; int ans = ( int ) Math . ceil ( ( a + b ) / 2 ) ; System . out . println ( ans ) ; sc . close ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int ave = ( a + b ) / 2 ; if ( ( a + b ) % 2 == 1 ) ave ++ ; System . out . println ( ave ) ; } }"
] | [
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE abr = ( a + b + 1 ) // 2 NEW_LINE print ( abr ) NEW_LINE",
"import math NEW_LINE work = input ( ) . split ( \" β \" ) NEW_LINE a = int ( work [ 0 ] ) NEW_LINE b = int ( work [ 1 ] ) NEW_LINE print ( math . ceil ( ( a + b ) / 2 ) ) NEW_LINE",
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE x = ( a + b ) / 2 NEW_LINE if x - int ( x ) >= 0.5 : NEW_LINE INDENT print ( int ( x ) + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( x ) ) NEW_LINE DEDENT",
"print ( ( sum ( map ( int , input ( ) . split ( ) ) ) + 1 ) // 2 ) NEW_LINE",
"import math NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE c = math . ceil ( ( a + b ) / 2 ) NEW_LINE print ( \" { } \" . format ( c ) ) NEW_LINE"
] |
atcoder_arc091_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long m = sc . nextLong ( ) ; if ( n == 1 && m == 1 ) System . out . println ( 1 ) ; else if ( n == 1 || m == 1 ) System . out . println ( Math . max ( n , m ) - 2 ) ; else System . out . println ( ( n - 2 ) * ( m - 2 ) ) ; } }",
"import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . function . Consumer ; import static java . util . stream . Collectors . toList ; public class Main { private static final Scanner scanner = new Scanner ( System . in ) ; private static final Consumer < List < String > > consumer = solve ( ) ; public static void main ( String [ ] args ) { consumer . accept ( readInput ( ) ) ; } private static List < String > readInput ( ) { final List < String > lineList = new ArrayList < > ( ) ; while ( scanner . hasNextLine ( ) ) { lineList . add ( scanner . nextLine ( ) ) ; } return lineList ; } private static Consumer < List < String > > solve ( ) { return args -> { final List < Long > numList = Arrays . stream ( args . get ( 0 ) . split ( \" β \" ) ) . map ( Long :: valueOf ) . collect ( toList ( ) ) ; final Long x = numList . get ( 0 ) ; final Long y = numList . get ( 1 ) ; if ( x == 1 ) { if ( y == 1 ) { System . out . println ( 1 ) ; } else { System . out . println ( y - 2 ) ; } } else if ( y == 1 ) { System . out . println ( x - 2 ) ; } else { System . out . println ( ( x - 2 ) * ( y - 2 ) ) ; } } ; } }",
"import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { solve ( ) ; } public static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long m = sc . nextLong ( ) ; long count = Math . abs ( ( n - 2 ) * ( m - 2 ) ) ; System . out . println ( count ) ; } }",
"import java . util . * ; public class Main { private long N ; private long M ; public void inputData ( ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextLong ( ) ; M = sc . nextLong ( ) ; } public void printAnswer ( ) { if ( N > 1 ) { N -= 2 ; } if ( M > 1 ) { M -= 2 ; } System . out . println ( N * M ) ; } public void run ( ) { inputData ( ) ; printAnswer ( ) ; } public static void main ( String [ ] args ) { ( new Main ( ) ) . run ( ) ; } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static String yesno ( boolean b ) { return b ? \" Yes \" : \" No \" ; } public static void main ( String [ ] args ) { int n = nextInt ( ) , m = nextInt ( ) ; long h = min ( n , m ) , w = max ( n , m ) ; long ans = 0 ; if ( h == 1 && w == 1 ) { ans = 1 ; } else if ( h == 1 && w != 1 ) { ans = w - 2 ; } else ans = ( h - 2 ) * ( w - 2 ) ; System . out . println ( ans ) ; } }"
] | [
"N , M = map ( int , input ( ) . strip ( ) . split ( ' β ' ) ) NEW_LINE if N == 1 and M == 1 : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT elif N == 1 : NEW_LINE INDENT ans = M - 2 NEW_LINE DEDENT elif M == 1 : NEW_LINE INDENT ans = N - 2 NEW_LINE DEDENT else : NEW_LINE INDENT ans = ( N - 2 ) * ( M - 2 ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"n , m = map ( int , input ( ) . split ( ) ) ; print ( abs ( ( n - 2 ) * ( m - 2 ) ) ) NEW_LINE",
"def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N , M = inpl ( ) NEW_LINE if M < N : NEW_LINE INDENT N , M = M , N NEW_LINE DEDENT if N == 1 : NEW_LINE INDENT if M == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( M - 2 ) NEW_LINE DEDENT DEDENT elif N == 2 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( N - 2 ) * ( M - 2 ) ) NEW_LINE DEDENT",
"n , m = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE n , m = max ( n , m ) , min ( n , m ) NEW_LINE if n == 1 and m == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT a = min ( 2 , n ) NEW_LINE b = max ( 0 , n - 2 ) NEW_LINE c = min ( 2 , m ) NEW_LINE d = max ( 0 , m - 2 ) NEW_LINE if m == 1 : NEW_LINE INDENT print ( b ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b * d ) NEW_LINE DEDENT DEDENT",
"N , M = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE if N == 1 and M == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT elif N == 1 or M == 1 : NEW_LINE INDENT print ( max ( N , M ) - 2 ) NEW_LINE DEDENT elif N == 2 or M == 2 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( N - 2 ) * ( M - 2 ) ) NEW_LINE DEDENT"
] |
atcoder_arc030_B | [
"import java . util . * ; public class Main { static int res = 0 ; static ArrayList < Integer > [ ] g ; static boolean dfs ( int u , int par , int [ ] h ) { boolean exist = ( h [ u ] == 1 ) ; for ( int v : g [ u ] ) { if ( v == par ) continue ; boolean child = dfs ( v , u , h ) ; if ( child ) res += 2 ; exist |= child ; } return exist ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int k = sc . nextInt ( ) - 1 ; int h [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } g = new ArrayList [ N ] ; for ( int i = 0 ; i < N ; i ++ ) g [ i ] = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; g [ a ] . add ( b ) ; g [ b ] . add ( a ) ; } dfs ( k , - 1 , h ) ; System . out . println ( res ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .",
"import java . util . * ; public class Main { static int ret = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) - 1 ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } ArrayList < Integer > [ ] table = new ArrayList [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { table [ i ] = new ArrayList < > ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; table [ a ] . add ( b ) ; table [ b ] . add ( a ) ; } dfs ( x , - 1 , h , table ) ; System . out . println ( ret ) ; } public static boolean dfs ( int now , int parent , int [ ] h , ArrayList < Integer > [ ] table ) { boolean exist = h [ now ] == 1 ; for ( int next : table [ now ] ) { if ( next == parent ) continue ; boolean child = dfs ( next , now , h , table ) ; if ( child ) ret += 2 ; exist |= child ; } return exist ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details ."
] | [
"class Node : NEW_LINE INDENT parent = None NEW_LINE children = set ( ) NEW_LINE count = None NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE hn = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ab = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE ab . append ( ( a - 1 , b - 1 ) ) NEW_LINE DEDENT nodes = [ Node ( ) for i in range ( n ) ] NEW_LINE dfs_make_tree ( x - 1 , None , n , ab , nodes ) NEW_LINE dfs_count ( x - 1 , nodes , hn ) NEW_LINE print ( max ( 0 , ( count_nonzero_branches ( nodes ) - 1 ) ) * 2 ) NEW_LINE DEDENT def dfs_make_tree ( my_id , parent_id , n , ab , nodes ) : NEW_LINE INDENT assert my_id != parent_id NEW_LINE node = nodes [ my_id ] NEW_LINE node . parent = parent_id NEW_LINE adjs = set ( ) NEW_LINE for edge in ab : NEW_LINE INDENT if my_id == edge [ 0 ] : NEW_LINE INDENT adjs . add ( edge [ 1 ] ) NEW_LINE DEDENT elif my_id == edge [ 1 ] : NEW_LINE INDENT adjs . add ( edge [ 0 ] ) NEW_LINE DEDENT DEDENT adjs -= { parent_id } NEW_LINE node . children = adjs NEW_LINE for c in node . children : NEW_LINE INDENT dfs_make_tree ( c , my_id , n , ab , nodes ) NEW_LINE DEDENT DEDENT def dfs_count ( my_id , nodes , hn ) : NEW_LINE INDENT node = nodes [ my_id ] NEW_LINE node . count = hn [ my_id ] NEW_LINE for c in node . children : NEW_LINE INDENT node . count += dfs_count ( c , nodes , hn ) NEW_LINE DEDENT return node . count NEW_LINE DEDENT def count_nonzero_branches ( nodes ) : NEW_LINE INDENT cnt = 0 NEW_LINE for nd in nodes : NEW_LINE INDENT if nd . count > 0 : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT main ( ) NEW_LINE",
"I = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE n , x = I ( ) NEW_LINE r = range ( n + 1 ) NEW_LINE H = [ 0 ] + I ( ) NEW_LINE T = [ [ ] for i in r ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a , b = I ( ) NEW_LINE T [ a ] += [ b ] NEW_LINE T [ b ] += [ a ] NEW_LINE DEDENT while 1 : NEW_LINE INDENT f = 1 NEW_LINE for i in r : NEW_LINE INDENT if all ( [ len ( T [ i ] ) == 1 , H [ i ] < 1 , i != x ] ) : NEW_LINE INDENT p = T [ i ] . pop ( ) NEW_LINE T [ p ] . remove ( i ) NEW_LINE f = 0 NEW_LINE DEDENT DEDENT if f : break NEW_LINE DEDENT print ( sum ( len ( t ) for t in T ) ) NEW_LINE",
"def b_tree ( N , X , H , Edges ) : NEW_LINE INDENT x = X - 1 NEW_LINE graph = [ [ ] for _ in [ 0 ] * N ] NEW_LINE for a , b in Edges : NEW_LINE INDENT a , b = a - 1 , b - 1 NEW_LINE graph [ a ] . append ( b ) NEW_LINE graph [ b ] . append ( a ) NEW_LINE DEDENT is_visited = [ False ] * N NEW_LINE is_exist_treasure = [ True if h == 1 else False for h in H ] NEW_LINE ans = 0 NEW_LINE def dfs ( v ) : NEW_LINE INDENT nonlocal ans NEW_LINE is_visited [ v ] = True NEW_LINE need_reach = is_exist_treasure [ v ] NEW_LINE for target in graph [ v ] : NEW_LINE INDENT if is_visited [ target ] : NEW_LINE INDENT continue NEW_LINE DEDENT if dfs ( target ) : NEW_LINE INDENT ans += 2 NEW_LINE need_reach = True NEW_LINE DEDENT DEDENT return need_reach NEW_LINE DEDENT dfs ( x ) NEW_LINE return ans NEW_LINE DEDENT N , X = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE H = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE Edges = [ [ int ( i ) for i in input ( ) . split ( ) ] for j in range ( N - 1 ) ] NEW_LINE print ( b_tree ( N , X , H , Edges ) ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N , x = map ( int , input ( ) . split ( ) ) NEW_LINE L = [ 0 ] + list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE adj = [ [ ] for _ in range ( N + 1 ) ] NEW_LINE for _ in range ( N - 1 ) : NEW_LINE INDENT a , b = map ( lambda x : int ( x ) , input ( ) . split ( ) ) NEW_LINE adj [ a ] . append ( b ) NEW_LINE adj [ b ] . append ( a ) NEW_LINE DEDENT def dfs ( c , p ) : NEW_LINE INDENT if len ( adj [ c ] ) == 1 : NEW_LINE INDENT if L [ c ] : NEW_LINE INDENT return 2 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ret = 0 NEW_LINE for n in adj [ c ] : NEW_LINE INDENT if n == p : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT ret += dfs ( n , c ) NEW_LINE DEDENT DEDENT if ret == 0 : NEW_LINE INDENT if L [ c ] : NEW_LINE INDENT return 2 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return ret + 2 NEW_LINE DEDENT DEDENT DEDENT ans = 0 NEW_LINE for n in adj [ x ] : NEW_LINE INDENT ans += dfs ( n , x ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"n , x = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE h = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE s , ans = [ [ ] for i in range ( n + 1 ) ] , 0 NEW_LINE for _ in range ( n - 1 ) : NEW_LINE INDENT a , b = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE s [ a ] . append ( b ) NEW_LINE s [ b ] . append ( a ) NEW_LINE DEDENT t , q , vis , p = 0 , [ x ] , [ True ] * ( n + 1 ) , [ 0 ] * ( n + 1 ) NEW_LINE while q : NEW_LINE INDENT t2 = q . pop ( ) NEW_LINE while p [ t2 ] != t : NEW_LINE INDENT if h [ t - 1 ] : ans , h [ p [ t ] - 1 ] = ans + 2 , 1 NEW_LINE t = p [ t ] NEW_LINE DEDENT vis [ t ] , t = False , t2 NEW_LINE for i in s [ t ] : NEW_LINE INDENT if vis [ i ] : NEW_LINE INDENT p [ i ] = t NEW_LINE q . append ( i ) NEW_LINE DEDENT DEDENT DEDENT while t != x : NEW_LINE INDENT if h [ t - 1 ] : ans , h [ p [ t ] - 1 ] = ans + 2 , 1 NEW_LINE t = p [ t ] NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc019_C | [
"import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int N = ( int ) sc . nextInt ( ) ; int a [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int ans = 0 ; Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { while ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; } map . put ( a [ i ] , 1 ) ; } System . out . println ( map . size ( ) ) ; } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; 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 ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = in . nextInt ( ) ; while ( ( a & 1 ) == 0 ) { a = a >> 1 ; } set . add ( a ) ; } out . println ( set . size ( ) ) ; } } }",
"public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) ; java . util . Set < Integer > a = java . util . stream . IntStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) ) . boxed ( ) . collect ( java . util . stream . Collectors . toSet ( ) ) ; System . out . println ( a . stream ( ) . filter ( i -> { while ( i % 2 == 0 ) if ( a . contains ( i /= 2 ) ) return false ; return true ; } ) . count ( ) ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = nums [ i ] / ( int ) Math . pow ( 2 , dividebyN ( nums [ i ] , 2 ) ) ; } Arrays . sort ( nums ) ; int tmp = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( nums [ i ] != tmp ) { tmp = nums [ i ] ; output ++ ; } } System . out . println ( output ) ; } static int dividebyN ( int input , int n ) { int output = 0 ; while ( true ) { if ( input % n == 0 ) { output ++ ; input /= n ; } else { break ; } } return output ; } }",
"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 [ ] a = new int [ n ] ; HashSet < Integer > ans = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; while ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; } ans . add ( a [ i ] ) ; } out . println ( ans . size ( ) ) ; } }"
] | [
"_ = int ( input ( ) ) NEW_LINE l = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE count = 0 NEW_LINE output = [ ] NEW_LINE for num in l : NEW_LINE INDENT while num % 2 == 0 : NEW_LINE INDENT num = num / 2 NEW_LINE DEDENT output . append ( num ) NEW_LINE DEDENT print ( len ( set ( output ) ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE ans = set ( ) NEW_LINE for a in map ( int , input ( ) . split ( ) ) : NEW_LINE INDENT while True : NEW_LINE INDENT if a % 2 == 1 : NEW_LINE INDENT ans |= { a , } NEW_LINE break NEW_LINE DEDENT else : a //= 2 NEW_LINE DEDENT DEDENT print ( len ( ans ) ) NEW_LINE",
"import sys NEW_LINE input = sys . stdin . readline NEW_LINE inf = 10 ** 18 NEW_LINE N = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a_id = list ( a ) NEW_LINE for i , ai in enumerate ( a ) : NEW_LINE INDENT ai_tmp = ai NEW_LINE while ai_tmp > 0 and ai_tmp & 1 == 0 : ai_tmp = ai_tmp >> 1 NEW_LINE a_id [ i ] = ai_tmp NEW_LINE DEDENT a_id = set ( a_id ) NEW_LINE print ( len ( a_id ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE b = set ( ) NEW_LINE for x in a : NEW_LINE INDENT while 1 : NEW_LINE INDENT if x % 2 == 0 : NEW_LINE INDENT x = x // 2 NEW_LINE DEDENT else : NEW_LINE INDENT b . add ( x ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( len ( b ) ) NEW_LINE",
"from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE an = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT while ( an [ i ] & 1 ) == 0 : NEW_LINE INDENT an [ i ] = ( an [ i ] >> 1 ) NEW_LINE DEDENT DEDENT ac = Counter ( an ) NEW_LINE print ( len ( ac ) ) NEW_LINE"
] |
atcoder_abc075_B | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int s [ ] [ ] = new int [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { String c = sc . next ( ) ; for ( int j = 0 ; j < m ; j ++ ) if ( c . substring ( j , j + 1 ) . equals ( \" # \" ) ) s [ i ] [ j ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( s [ i ] [ j ] == - 1 ) { for ( int y = i - 1 ; y <= i + 1 ; y ++ ) { for ( int x = j - 1 ; x <= j + 1 ; x ++ ) { if ( y >= 0 && y < n && x >= 0 && x < m ) { if ( s [ y ] [ x ] > - 1 ) s [ y ] [ x ] ++ ; } } } } } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { System . out . print ( s [ i ] [ j ] < 0 ? \" # \" : s [ i ] [ j ] ) ; } System . out . println ( ) ; } } }",
"import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; sc . nextLine ( ) ; String [ ] [ ] S = new String [ H ] [ W ] ; final int height = H ; final int width = W ; int [ ] [ ] number = new int [ H ] [ W ] ; String [ ] tmp = new String [ H ] ; for ( int i = 0 ; i < H ; i ++ ) { tmp [ i ] = sc . nextLine ( ) ; } for ( int i = 0 ; i < H ; i ++ ) { String [ ] str = tmp [ i ] . split ( \" \" ) ; for ( int j = 0 ; j < W ; j ++ ) { S [ i ] [ j ] = str [ j ] ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { if ( S [ i ] [ j ] . equals ( \" # \" ) ) { System . out . print ( S [ i ] [ j ] ) ; } else { number [ i ] [ j ] = countMine ( i , j , height , width , S ) ; System . out . print ( number [ i ] [ j ] ) ; } } System . out . println ( ) ; } sc . close ( ) ; } public static int countMine ( int h , int w , int height , int width , String [ ] [ ] S ) { int count = 0 ; for ( int i = h - 1 ; i <= h + 1 ; i ++ ) { if ( i < 0 || i >= height ) { continue ; } for ( int j = w - 1 ; j <= w + 1 ; j ++ ) { if ( j < 0 || j >= width ) { continue ; } if ( S [ i ] [ j ] . equals ( \" # \" ) ) { count ++ ; } } } return count ; } }",
"import java . util . * ; import java . util . stream . IntStream ; public class Main { public static boolean found = false ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; char [ ] [ ] board = new char [ h ] [ w ] ; int [ ] [ ] dt = new int [ ] [ ] { new int [ ] { 1 , 0 } , new int [ ] { 1 , 1 } , new int [ ] { 0 , 1 } , new int [ ] { - 1 , 1 } , new int [ ] { - 1 , 0 } , new int [ ] { - 1 , - 1 } , new int [ ] { 0 , - 1 } , new int [ ] { 1 , - 1 } } ; for ( int i = 0 ; i < h ; i ++ ) { String line = sc . next ( ) ; board [ i ] = line . toCharArray ( ) ; } for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( board [ i ] [ j ] != ' # ' ) { int count = 0 ; for ( int k = 0 ; k < dt . length ; k ++ ) { int x = i + dt [ k ] [ 0 ] ; int y = j + dt [ k ] [ 1 ] ; if ( ( 0 <= x && x < h ) && ( 0 <= y && y < w ) && board [ x ] [ y ] == ' # ' ) { count ++ ; } } board [ i ] [ j ] = ( char ) ( count + '0' ) ; } System . out . print ( board [ i ] [ j ] ) ; } System . out . println ( \" \" ) ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int h = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int w = Integer . parseInt ( tokenizer . nextToken ( ) ) ; char [ ] [ ] letters = new char [ h ] [ ] ; for ( int i = 0 ; i < h ; i ++ ) { letters [ i ] = input . readLine ( ) . toCharArray ( ) ; } int [ ] x = { 1 , 0 , 1 , 0 , - 1 , 1 , - 1 , - 1 } ; int [ ] y = { 1 , 1 , 0 , - 1 , 0 , - 1 , 1 , - 1 } ; int sum ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( letters [ i ] [ j ] == ' . ' ) { sum = 0 ; for ( int k = 0 ; k < 8 ; k ++ ) { if ( check ( h , w , i + x [ k ] , j + y [ k ] ) && letters [ i + x [ k ] ] [ j + y [ k ] ] == ' # ' ) sum ++ ; } letters [ i ] [ j ] = ( char ) ( '0' + sum ) ; } } } StringBuilder out = new StringBuilder ( ) ; StringBuilder row ; for ( int i = 0 ; i < h ; i ++ ) { row = new StringBuilder ( ) ; for ( int j = 0 ; j < w ; j ++ ) { row . append ( letters [ i ] [ j ] ) ; } out . append ( row ) . append ( \" \\n \" ) ; } System . out . print ( out ) ; } public static boolean check ( int x1 , int y1 , int x2 , int y2 ) { return x2 > - 1 && x2 < x1 && y2 > - 1 && y2 < y1 ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { B ( ) ; return ; } public static void A ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; if ( A == B ) System . out . println ( C ) ; else if ( B == C ) System . out . println ( A ) ; else System . out . println ( B ) ; } public static void calc8 ( char [ ] [ ] cell , int h , int w ) { if ( cell [ h ] [ w ] == ' # ' ) System . out . print ( ' # ' ) ; else { int [ ] hs = new int [ ] { h - 1 , h , h + 1 } ; int [ ] ws = new int [ ] { w - 1 , w , w + 1 } ; int sum = 0 ; for ( int nh : hs ) { for ( int nw : ws ) { if ( nh < cell . length && nh >= 0 && nw >= 0 && nw < cell [ 0 ] . length ) { if ( cell [ nh ] [ nw ] == ' # ' ) sum ++ ; } } } System . out . print ( sum ) ; } if ( w == cell [ 0 ] . length - 1 ) System . out . println ( \" \" ) ; } public static void B ( ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; char [ ] [ ] cell = new char [ H ] [ W ] ; for ( int i = 0 ; i < H ; i ++ ) { String s = sc . next ( ) ; for ( int j = 0 ; j < W ; j ++ ) { cell [ i ] [ j ] = s . charAt ( j ) ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { calc8 ( cell , i , j ) ; } } } }"
] | [
"h , w = [ int ( n ) for n in input ( ) . split ( ) ] NEW_LINE B = [ [ ' . ' ] * ( w + 2 ) ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT s = [ ' . ' ] + list ( input ( ) ) + [ ' . ' ] NEW_LINE B . append ( s ) NEW_LINE DEDENT B . append ( [ ' . ' ] * ( w + 2 ) ) NEW_LINE for i in range ( 1 , h + 1 ) : NEW_LINE INDENT for j in range ( 1 , w + 1 ) : NEW_LINE INDENT if B [ i ] [ j ] == ' # ' : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT B [ i ] [ j ] = str ( ( B [ i - 1 ] [ j - 1 : j + 2 ] + [ B [ i ] [ j - 1 ] ] + [ B [ i ] [ j + 1 ] ] + B [ i + 1 ] [ j - 1 : j + 2 ] ) . count ( ' # ' ) ) NEW_LINE DEDENT DEDENT DEDENT for i in range ( 1 , h + 1 ) : NEW_LINE INDENT print ( ' ' . join ( B [ i ] [ 1 : w + 1 ] ) ) NEW_LINE DEDENT",
"def count ( i , j ) : NEW_LINE INDENT count = 0 NEW_LINE if list [ i - 1 ] [ j - 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i - 1 ] [ j ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i - 1 ] [ j + 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i ] [ j - 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i ] [ j + 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i + 1 ] [ j - 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i + 1 ] [ j ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i + 1 ] [ j + 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT h , w = map ( int , input ( ) . split ( ) ) NEW_LINE s_init = '0' * ( w + 2 ) NEW_LINE list = [ ] NEW_LINE list . append ( s_init ) NEW_LINE for i in range ( h ) : NEW_LINE INDENT s = str ( input ( ) ) NEW_LINE list . append ( '0' + s + '0' ) NEW_LINE DEDENT list . append ( s_init ) NEW_LINE for i in range ( 1 , h + 1 ) : NEW_LINE INDENT for j in range ( 1 , w + 1 ) : NEW_LINE INDENT if list [ i ] [ j ] == ' . ' : NEW_LINE INDENT list [ i ] = list [ i ] [ : j ] + str ( count ( i , j ) ) + list [ i ] [ j + 1 : ] NEW_LINE DEDENT DEDENT DEDENT for i in range ( h ) : NEW_LINE INDENT print ( list [ i + 1 ] [ 1 : - 1 ] ) NEW_LINE DEDENT",
"import math NEW_LINE import functools NEW_LINE import itertools NEW_LINE import numpy as np NEW_LINE import sys NEW_LINE MAX_INT = int ( 10e10 ) NEW_LINE MIN_INT = - MAX_INT NEW_LINE mod = 1000000007 NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE def IL ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def SL ( ) : return input ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def judge ( n , m ) : NEW_LINE INDENT if ( 0 <= n < H ) and ( 0 <= m < W ) and s [ n ] [ m ] == \" # \" : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT def cnt ( a , b ) : NEW_LINE INDENT l = [ - 1 , 0 , 1 ] NEW_LINE num = 0 NEW_LINE for i in l : NEW_LINE INDENT for j in l : NEW_LINE INDENT if i == j == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT if judge ( a + i , b + j ) : NEW_LINE INDENT num += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return num NEW_LINE DEDENT H , W = IL ( ) NEW_LINE s = [ [ i for i in S ( ) ] for i in range ( H ) ] NEW_LINE ans = [ [ \" # \" for i in range ( W ) ] for i in range ( H ) ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT for j in range ( W ) : NEW_LINE INDENT if s [ i ] [ j ] == \" . \" : NEW_LINE INDENT ans [ i ] [ j ] = cnt ( i , j ) NEW_LINE DEDENT DEDENT DEDENT for i in ans : NEW_LINE INDENT print ( \" \" . join ( list ( map ( str , i ) ) ) ) NEW_LINE DEDENT",
"h , w = map ( int , input ( ) . split ( ) ) NEW_LINE S = [ input ( ) for i in range ( h ) ] NEW_LINE def count ( x , y ) : NEW_LINE INDENT p = 0 NEW_LINE if x >= 1 and y >= 1 and S [ x - 1 ] [ y - 1 ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x >= 1 and S [ x - 1 ] [ y ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x >= 1 and y <= w - 2 and S [ x - 1 ] [ y + 1 ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if y >= 1 and S [ x ] [ y - 1 ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if y <= w - 2 and S [ x ] [ y + 1 ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x <= h - 2 and y >= 1 and S [ x + 1 ] [ y - 1 ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x <= h - 2 and S [ x + 1 ] [ y ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x <= h - 2 and y <= w - 2 and S [ x + 1 ] [ y + 1 ] == \" # \" : NEW_LINE INDENT p += 1 NEW_LINE DEDENT p = str ( p ) NEW_LINE return ( p ) NEW_LINE DEDENT for i in range ( h ) : NEW_LINE INDENT ans = \" \" NEW_LINE for j in range ( w ) : NEW_LINE INDENT if S [ i ] [ j ] == \" # \" : NEW_LINE INDENT ans += \" # \" NEW_LINE DEDENT else : NEW_LINE INDENT ans += count ( i , j ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT",
"H , W = map ( int , input ( ) . split ( ) ) NEW_LINE Ss = [ [ \" . \" ] + [ j for j in input ( ) ] + [ \" . \" ] for i in range ( H ) ] NEW_LINE Ss . insert ( 0 , [ \" . \" ] * len ( Ss [ 0 ] ) ) NEW_LINE Ss . append ( [ \" . \" ] * len ( Ss [ 0 ] ) ) NEW_LINE ans = [ ] NEW_LINE for i in range ( 1 , len ( Ss ) - 1 ) : NEW_LINE INDENT nums = [ ] NEW_LINE for j in range ( 1 , len ( Ss [ i ] ) - 1 ) : NEW_LINE INDENT num = 0 NEW_LINE if Ss [ i ] [ j ] == \" . \" : NEW_LINE INDENT if Ss [ i + 1 ] [ j ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i + 1 ] [ j + 1 ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i + 1 ] [ j - 1 ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i - 1 ] [ j ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i - 1 ] [ j + 1 ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i - 1 ] [ j - 1 ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i ] [ j + 1 ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i ] [ j - 1 ] == \" # \" : NEW_LINE INDENT num += 1 NEW_LINE DEDENT nums . append ( str ( num ) ) NEW_LINE DEDENT else : NEW_LINE INDENT nums . append ( \" # \" ) NEW_LINE DEDENT DEDENT print ( \" \" . join ( nums ) ) NEW_LINE DEDENT"
] |
atcoder_abc103_A | [
"import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int [ ] ar = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) ar [ i ] = sc . nextInt ( ) ; Arrays . sort ( ar ) ; System . out . println ( ( ar [ 2 ] - ar [ 1 ] ) + ( ar [ 1 ] - ar [ 0 ] ) ) ; } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x3 = Math . abs ( a - b ) ; int x1 = Math . abs ( a - c ) ; int x2 = Math . abs ( b - c ) ; int total = x1 + x2 + x3 ; total = Math . abs ( total - ( Math . max ( x3 , Math . max ( x2 , x1 ) ) ) ) ; System . out . println ( total ) ; } }",
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { Scanner scanner = null ; int numA1 = 0 ; int numA2 = 0 ; int numA3 = 0 ; try { scanner = new Scanner ( System . in ) ; int [ ] wk = new int [ 3 ] ; for ( int i = 0 ; i < wk . length ; i ++ ) { wk [ i ] = scanner . nextInt ( ) ; } Arrays . sort ( wk ) ; int res = Math . abs ( wk [ 0 ] - wk [ 1 ] ) + Math . abs ( wk [ 1 ] - wk [ 2 ] ) ; System . out . println ( res ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveB ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveC ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveD ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } }",
"import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > a = new ArrayList < > ( ) ; IntStream . range ( 0 , 3 ) . forEach ( i -> a . add ( sc . nextInt ( ) ) ) ; Collections . sort ( a ) ; System . out . println ( Math . abs ( a . get ( 2 ) - a . get ( 1 ) ) + Math . abs ( a . get ( 1 ) - a . get ( 0 ) ) ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int [ ] A = { sc . nextInt ( ) , sc . nextInt ( ) , sc . nextInt ( ) } ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( j == i ) continue ; for ( int k = 0 ; k < 3 ; k ++ ) { if ( k == i || k == j ) continue ; int cost = Math . abs ( A [ i ] - A [ j ] ) + Math . abs ( A [ j ] - A [ k ] ) ; if ( min > cost ) min = cost ; } } } System . out . println ( min ) ; } }"
] | [
"List = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( max ( List ) - min ( List ) ) NEW_LINE",
"task = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE task = sorted ( task ) NEW_LINE cost = 0 NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT cost += task [ i + 1 ] - task [ i ] NEW_LINE DEDENT print ( cost ) NEW_LINE",
"a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE s = abs ( a - b ) + abs ( b - c ) + abs ( c - a ) NEW_LINE m = max ( abs ( a - b ) , abs ( b - c ) , abs ( c - a ) ) NEW_LINE print ( s - m ) NEW_LINE",
"A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE A . sort ( ) NEW_LINE ans = 0 NEW_LINE for i in range ( 1 , len ( A ) ) : NEW_LINE INDENT ans += abs ( A [ i ] - A [ i - 1 ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"A = sorted ( list ( map ( int , input ( ) . split ( ) ) ) , reverse = True ) NEW_LINE print ( abs ( ( A [ 1 ] - A [ 0 ] ) ) + abs ( ( A [ 2 ] - A [ 1 ] ) ) ) NEW_LINE"
] |
atcoder_abc037_C | [
"import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long [ ] sum = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } sum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { sum [ i ] = sum [ i - 1 ] + a [ i ] ; } long su = sum [ k - 1 ] ; for ( int i = k ; i < n ; i ++ ) { su += sum [ i ] - sum [ i - k ] ; } System . out . println ( su ) ; } }",
"import java . util . * ; import java . awt . * ; 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 ( ) ; long [ ] a = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long ans = 0 ; for ( int i = 1 ; i <= n - k + 1 ; i ++ ) { for ( int j = 0 ; j < k ; j ++ ) { ans += a [ i + j ] ; } } out . println ( ans ) ; } static long power ( long x , int n ) { long mod = 1000000007 ; long ans = 1 ; while ( n > 0 ) { if ( ( n & 1 ) == 1 ) { ans = ( ans * x ) % mod ; } x = ( x * x ) % mod ; n >>= 1 ; } return ans ; } static int gcd ( int a , int b ) { int temp ; while ( ( temp = a % b ) != 0 ) { a = b ; b = temp ; } return b ; } static class UF { static int size = 51 ; static int [ ] par = new int [ size ] ; static void init ( ) { for ( int i = 1 ; i < size ; i ++ ) { par [ i ] = i ; } } static int root ( int x ) { if ( par [ x ] == x ) { return x ; } else { return par [ x ] = root ( par [ x ] ) ; } } static boolean same ( int x , int y ) { return root ( x ) == root ( y ) ; } static void unite ( int x , int y ) { x = root ( x ) ; y = root ( y ) ; if ( x == y ) return ; par [ x ] = y ; } } }",
"public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = scanner . nextInt ( ) , k = scanner . nextInt ( ) ; System . out . println ( java . util . stream . LongStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) * Math . min ( Math . min ( Math . min ( i + 1 , n - i ) , k ) , n - k + 1 ) ) . sum ( ) ) ; } }",
"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 [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int [ ] cum = new int [ N + 1 ] ; for ( int i = 0 ; i <= N - K ; i ++ ) { cum [ i ] ++ ; cum [ i + K ] -- ; } for ( int i = 1 ; i <= N ; i ++ ) { cum [ i ] += cum [ i - 1 ] ; } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += ( long ) a [ i ] * cum [ i ] ; } out . println ( ans ) ; } }",
"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 ( ) , k = sc . nextInt ( ) ; long ans = 0 ; long [ ] a = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; a [ i ] += a [ i - 1 ] ; } for ( int i = k ; i <= n ; i ++ ) { ans += a [ i ] - a [ i - k ] ; } out . println ( ans ) ; } }"
] | [
"N , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = sum ( A [ : K ] ) NEW_LINE now = sum ( A [ : K ] ) NEW_LINE for i in range ( N - K ) : NEW_LINE INDENT now -= A [ i ] NEW_LINE now += A [ i + K ] NEW_LINE ans += now NEW_LINE DEDENT print ( ans ) NEW_LINE",
"from numpy import * NEW_LINE def section_sum ( numbers , separate ) : NEW_LINE INDENT sep1 = array ( numbers [ separate : ] , dtype = int ) NEW_LINE sep2 = array ( numbers [ : - separate ] , dtype = int ) NEW_LINE sep3 = sum ( numbers [ : separate ] ) NEW_LINE return insert ( sep3 + cumsum ( sep1 - sep2 ) , 0 , sep3 ) NEW_LINE DEDENT n , k , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE print ( sum ( section_sum ( a , k ) ) ) NEW_LINE",
"from itertools import accumulate NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ 0 ] + [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE b = list ( accumulate ( a ) ) NEW_LINE ans = 0 NEW_LINE for x , y in zip ( b , b [ K : ] ) : NEW_LINE INDENT ans += y - x NEW_LINE DEDENT print ( ans ) NEW_LINE",
"def main ( ) : NEW_LINE INDENT N , K = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE l = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE sum_list = getSumList ( l ) NEW_LINE res = 0 NEW_LINE for i in range ( N - K + 1 ) : NEW_LINE INDENT if ( i == 0 ) : NEW_LINE INDENT res += ( sum_list [ i + K - 1 ] - 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT res += ( sum_list [ i + K - 1 ] - sum_list [ i - 1 ] ) NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE DEDENT def getSumList ( li ) : NEW_LINE INDENT sum_list = [ 0 ] NEW_LINE for i in li : NEW_LINE INDENT sum_list . append ( sum_list [ - 1 ] + i ) NEW_LINE DEDENT del sum_list [ 0 ] NEW_LINE return sum_list NEW_LINE DEDENT main ( ) NEW_LINE",
"from itertools import accumulate as ac NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE lst_a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE lst_imosu = [ 0 ] * ( N + 1 ) NEW_LINE for l in range ( N - K + 1 ) : NEW_LINE INDENT r = l + K NEW_LINE lst_imosu [ l ] += 1 NEW_LINE lst_imosu [ r ] -= 1 NEW_LINE DEDENT lst_ac = list ( ac ( lst_imosu ) ) [ 0 : N ] NEW_LINE ans = 0 NEW_LINE for a , i_ac in zip ( lst_a , lst_ac ) : NEW_LINE INDENT ans += a * i_ac NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc079_B | [
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long ans = 0 ; long pre = 1 ; long pre2 = 2 ; if ( N == 1 ) ans = pre ; for ( int i = 2 ; i <= N ; i ++ ) { ans = pre + pre2 ; pre2 = pre ; pre = ans ; } System . out . println ( ans ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] L = new long [ 87 ] ; L [ 0 ] = 2 ; L [ 1 ] = 1 ; for ( int i = 2 ; i < L . length ; i ++ ) { L [ i ] = L [ i - 1 ] + L [ i - 2 ] ; } out . println ( L [ N ] ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Long > lucas = new ArrayList < > ( ) ; lucas . add ( 2L ) ; lucas . add ( 1L ) ; for ( int i = 2 ; i <= n ; i ++ ) { lucas . add ( lucas . get ( i - 1 ) + lucas . get ( i - 2 ) ) ; } System . out . println ( lucas . get ( n ) ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { B ( ) ; } public static void A ( ) { Scanner sc = new Scanner ( System . in ) ; Integer n = sc . nextInt ( ) ; sc . close ( ) ; String num = n . toString ( ) ; if ( num . charAt ( 1 ) != num . charAt ( 2 ) ) { System . out . println ( \" No \" ) ; return ; } char mid = num . charAt ( 1 ) ; if ( mid == num . charAt ( 0 ) || mid == num . charAt ( 3 ) ) { System . out . println ( \" Yes \" ) ; } else System . out . println ( \" No \" ) ; } public static void B ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( 1 ) ; return ; } sc . close ( ) ; long Li = 2 ; long Lj = 1 ; long temp ; for ( int i = 2 ; i < N + 1 ; i ++ ) { temp = Lj ; Lj = Li + Lj ; Li = temp ; } System . out . println ( Lj ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; long [ ] nValues = new long [ n + 1 ] ; nValues [ 0 ] = 2 ; nValues [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { nValues [ i ] = nValues [ i - 1 ] + nValues [ i - 2 ] ; } System . out . println ( nValues [ n ] ) ; } }"
] | [
"n = int ( input ( ) ) NEW_LINE l_i = 0 NEW_LINE l_i_1 = 1 NEW_LINE l_i_2 = 2 NEW_LINE if n == 1 : NEW_LINE INDENT print ( \"1\" ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( n - 1 ) : NEW_LINE INDENT l_i = 0 NEW_LINE l_i = l_i_1 + l_i_2 NEW_LINE l_i_2 = l_i_1 NEW_LINE l_i_1 = l_i NEW_LINE DEDENT print ( l_i ) NEW_LINE DEDENT",
"from functools import lru_cache NEW_LINE @ lru_cache ( maxsize = 1000 ) NEW_LINE def lucas ( i ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT return 2 NEW_LINE DEDENT if i == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return lucas ( i - 1 ) + lucas ( i - 2 ) NEW_LINE DEDENT print ( lucas ( int ( input ( ) ) ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE ryukasu = [ 2 , 1 ] NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT ryukasu . append ( ryukasu [ i - 1 ] + ryukasu [ i - 2 ] ) NEW_LINE DEDENT print ( ryukasu [ - 1 ] ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE L0 = 2 NEW_LINE L1 = 1 NEW_LINE i = N NEW_LINE while i - 1 > 0 : NEW_LINE INDENT Ln = L0 + L1 NEW_LINE i -= 1 NEW_LINE L0 = L1 NEW_LINE L1 = Ln NEW_LINE DEDENT if N == 0 : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT elif N == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( Ln ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE luca = [ 2 , 1 ] NEW_LINE while len ( luca ) <= N : NEW_LINE INDENT luca . append ( luca [ - 2 ] + luca [ - 1 ] ) NEW_LINE DEDENT print ( luca [ N ] ) NEW_LINE"
] |
atcoder_abc014_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( x % Math . pow ( 2 , i + 1 ) - x % Math . pow ( 2 , i ) != 0 ) { output += nums [ i ] ; } } System . out . println ( output ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String nx = scanner . nextLine ( ) ; String price = scanner . nextLine ( ) ; scanner . close ( ) ; int n = Integer . parseInt ( nx . split ( \" β \" ) [ 0 ] ) ; int x = Integer . parseInt ( nx . split ( \" β \" ) [ 1 ] ) ; String [ ] prices = price . split ( \" β \" ) ; String bitX = Integer . toBinaryString ( x ) ; int toAddZero = n - bitX . length ( ) ; for ( int i = 0 ; i < toAddZero ; i ++ ) { bitX = \"0\" + bitX ; } boolean [ ] shouldAdd = new boolean [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String bit = bitX . substring ( bitX . length ( ) - 1 - i , bitX . length ( ) - i ) ; shouldAdd [ i ] = bit . equals ( \"1\" ) ; } int sumPrice = 0 ; for ( int i = 0 ; i < shouldAdd . length ; i ++ ) { if ( shouldAdd [ i ] ) { sumPrice += Integer . parseInt ( prices [ i ] ) ; } } System . out . println ( sumPrice ) ; } }",
"import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { ArrayList < Long > mo = new ArrayList < Long > ( ) ; long answer = 0 ; Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int du = sc . nextInt ( ) ; String d = Integer . toBinaryString ( du ) ; for ( int i = 0 ; i != d . length ( ) ; i ++ ) { int c = sc . nextInt ( ) ; if ( d . charAt ( d . length ( ) - 1 - i ) == '1' ) { answer += c ; } } System . out . println ( + answer ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; char [ ] _list = Long . toBinaryString ( x ) . toCharArray ( ) ; char [ ] list = new char [ n ] ; for ( int i = 0 ; i < _list . length ; i ++ ) { list [ i ] = _list [ _list . length - i - 1 ] ; } int totalPrice = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int price = sc . nextInt ( ) ; if ( list [ i ] == '1' ) { totalPrice += price ; } } System . out . println ( totalPrice ) ; } }",
"import java . util . Scanner ; 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 x = Integer . parseInt ( line [ 1 ] ) ; int result = 0 ; line = scanner . nextLine ( ) . split ( \" β \" , n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( x & ( 1 << i ) ) != 0 ) { result += Integer . parseInt ( line [ i ] ) ; } } System . out . println ( result ) ; } }"
] | [
"n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE y = format ( x , \" b \" ) NEW_LINE y = list ( y ) [ : : - 1 ] NEW_LINE res = 0 NEW_LINE for i in range ( len ( y ) ) : NEW_LINE INDENT if y [ i ] == \"1\" : NEW_LINE INDENT res += a [ i ] NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE",
"N , K = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE A = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE res = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( K >> i ) & 1 == 1 : NEW_LINE INDENT res += A [ i ] NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE",
"n , X = map ( int , input ( ) . split ( ) ) NEW_LINE price = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE X_bin = format ( X , '0' + str ( n ) + ' b ' ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if X_bin [ i ] == '1' : NEW_LINE INDENT ans += price [ n - 1 - i ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"list = input ( ) . split ( \" β \" ) NEW_LINE a = input ( ) . split ( \" β \" ) NEW_LINE b = int ( list [ 1 ] ) NEW_LINE sum = 0 NEW_LINE for i in range ( int ( list [ 0 ] ) ) : NEW_LINE INDENT if b % 2 == 1 : NEW_LINE INDENT sum += int ( a [ i ] ) NEW_LINE DEDENT b = b // 2 NEW_LINE DEDENT print ( sum ) NEW_LINE",
"n , X = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE bX = bin ( X ) [ 2 : ] NEW_LINE bX = '0' * ( n - len ( bX ) ) + bX NEW_LINE print ( sum ( [ e for e , _ in zip ( reversed ( a ) , list ( bX ) ) if _ == '1' ] ) ) NEW_LINE"
] |
atcoder_arc064_D | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) , k = sc . nextLong ( ) ; long [ ] divs = divs ( n ) ; int nd = divs . length ; long mod = 1000000007 ; HashMap < Long , Long > map = new HashMap < > ( ) ; long res = 0 ; for ( int i = 0 ; i < nd ; i ++ ) { long div = divs [ i ] ; long [ ] dd = divs ( div ) ; long nama = modPow ( k , ( div + 1 ) / 2 , mod ) ; for ( int j = 0 ; j < dd . length - 1 ; j ++ ) { nama = ( nama - map . get ( dd [ j ] ) + mod ) % mod ; } map . put ( div , nama ) ; long coef = ( div % 2 == 1 ? div : div / 2 ) ; res = ( res + nama * coef % mod ) % mod ; } System . out . println ( res ) ; } static long modPow ( long a , long b , long mod ) { long res = 1 ; long c = a ; while ( b > 0 ) { if ( b % 2 == 1 ) res = res * c % mod ; c = c * c % mod ; b /= 2 ; } return res ; } static long [ ] divs ( long x ) { long [ ] res = new long [ ( int ) ( Math . sqrt ( x ) + 2 ) * 2 ] ; int size = 0 ; long i = 1 ; for ( ; i * i < x ; i ++ ) { if ( x % i > 0 ) continue ; res [ size ++ ] = i ; } if ( i * i == x ) res [ size ++ ] = i ; i -- ; for ( ; i > 0 ; i -- ) { if ( x % i > 0 ) continue ; res [ size ++ ] = x / i ; } return Arrays . copyOf ( res , size ) ; } }",
"import java . util . * ; public class Main { final static long MODULO = 1_000_000_000 + 7 ; static ArrayList < Integer > divs ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long K = sc . nextLong ( ) ; divs = new ArrayList < > ( ) ; for ( int i = 1 ; i * i <= N ; ++ i ) { if ( N % i == 0 ) { divs . add ( i ) ; if ( i * i != N ) { divs . add ( N / i ) ; } } } Collections . sort ( divs ) ; HashMap < Integer , Long > dp = new HashMap < > ( ) ; for ( int d : divs ) { dp . put ( d , pow ( K , ( d + 1 ) / 2 ) ) ; for ( int i = 0 ; divs . get ( i ) < d ; ++ i ) { if ( d % divs . get ( i ) == 0 ) dp . put ( d , ( dp . get ( d ) - dp . get ( divs . get ( i ) ) + MODULO ) % MODULO ) ; } } long ans = 0 ; for ( int d : divs ) { ans = ( ans + dp . get ( d ) * ( d % 2 == 0 ? d / 2 : d ) ) % MODULO ; } System . out . println ( ans ) ; } static class Div { int div ; int num ; public Div ( int div , int num ) { this . div = div ; this . num = num ; } } static long pow ( long a , long n ) { long ret = 1 ; for ( ; n > 0 ; n >>= 1 , a = ( a * a ) % MODULO ) { if ( n % 2 == 1 ) { ret = ( ret * a ) % MODULO ; } } return ret ; } }",
"import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static final long MOD = 1_000_000_007 ; public static void main ( String [ ] args ) { long N = sc . nextInt ( ) ; long K = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( K ) ; return ; } ArrayList < Long > divisor = new ArrayList < > ( ) ; for ( long i = 2 ; i * i <= N ; i ++ ) { if ( N % i != 0 ) continue ; divisor . add ( i ) ; if ( i * i != N ) { divisor . add ( N / i ) ; } } divisor . add ( N ) ; Collections . sort ( divisor ) ; HashMap < Long , Long > map = new HashMap < > ( ) ; map . put ( 1L , K ) ; for ( long d : divisor ) { long add = pow ( K , ( d + 1 ) / 2 ) - K ; for ( long i = 2 ; i * i <= d ; i ++ ) { if ( d % i != 0 ) continue ; add += MOD - map . get ( i ) ; if ( i * i != d ) add += MOD - map . get ( d / i ) ; } map . put ( d , add % MOD ) ; } long ans = 0 ; for ( long k : map . keySet ( ) ) { ans += ( k % 2 == 0 ? k / 2 : k ) * map . get ( k ) ; } System . out . println ( ans % MOD ) ; } static long pow ( long base , long p ) { if ( p == 0 ) return 1 ; if ( p == 1 ) return base ; long ret = pow ( base , p / 2 ) ; ret = ret * ret % MOD ; if ( p % 2 == 1 ) { ret = ret * base % MOD ; } return ret ; } }"
] | [
"N , K = map ( int , input ( ) . split ( ) ) NEW_LINE S = [ ] ; T = [ ] NEW_LINE for x in range ( 1 , int ( N ** .5 ) + 1 ) : NEW_LINE INDENT if N % x == 0 : NEW_LINE INDENT S . append ( x ) NEW_LINE if x * x < N : NEW_LINE INDENT T . append ( N // x ) NEW_LINE DEDENT DEDENT DEDENT T . reverse ( ) NEW_LINE S += T NEW_LINE M = len ( S ) NEW_LINE U = [ ] NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE ans = 0 NEW_LINE v = 0 NEW_LINE for i in range ( M ) : NEW_LINE INDENT x = S [ i ] NEW_LINE v = pow ( K , ( x + 1 ) // 2 , MOD ) NEW_LINE for j in range ( i ) : NEW_LINE INDENT y = S [ j ] NEW_LINE if x % y == 0 : NEW_LINE INDENT v -= U [ j ] NEW_LINE DEDENT DEDENT U . append ( v % MOD ) NEW_LINE ans = ( ans + ( v * x if x & 1 else v * ( x // 2 ) ) ) % MOD NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_agc032_A | [
"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) list . add ( Integer . parseInt ( sc . next ( ) ) ) ; sc . close ( ) ; List < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = i ; j >= 0 ; j -- ) { if ( list . get ( j ) == j + 1 ) { res . add ( j + 1 ) ; list . remove ( j ) ; break ; } } } if ( res . size ( ) == n ) for ( int i = n - 1 ; i >= 0 ; i -- ) System . out . println ( res . get ( i ) ) ; else System . out . println ( - 1 ) ; } }",
"import java . util . * ; import java . io . * ; import java . awt . * ; import java . awt . geom . Point2D ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { int n = sc . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } ArrayDeque < Integer > ans = new ArrayDeque < > ( ) ; int c = 1 ; while ( c == 1 && ! list . isEmpty ( ) ) { for ( int i = list . size ( ) - 1 ; i > - 1 ; i -- ) { if ( list . get ( i ) == i + 1 ) { ans . push ( list . get ( i ) ) ; list . remove ( i ) ; c = 1 ; break ; } else c = 0 ; } } if ( list . size ( ) > 0 ) { out . println ( - 1 ) ; } else { while ( ! ans . isEmpty ( ) ) { out . println ( ans . pop ( ) ) ; } } out . close ( ) ; } static PrintWriter out = new PrintWriter ( System . out ) ; static class sc { static Scanner s = new Scanner ( System . in ) ; static String next ( ) { return s . next ( ) ; } static int nextInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } static long nextLong ( ) { return Long . parseLong ( s . next ( ) ) ; } static double nextDouble ( ) { return Double . parseDouble ( s . next ( ) ) ; } } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = ni ( ) ; List < Integer > b = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { b . add ( sc . nextInt ( ) ) ; } List < Integer > seq = new ArrayList < > ( ) ; boolean canPick = true ; while ( canPick ) { canPick = false ; for ( int i = b . size ( ) - 1 ; i >= 0 ; i -- ) { if ( b . get ( i ) == i + 1 ) { b . remove ( i ) ; seq . add ( i + 1 ) ; canPick = true ; break ; } } } if ( b . isEmpty ( ) ) { Collections . reverse ( seq ) ; for ( int s : seq ) { out . println ( s ) ; } } else { out . println ( - 1 ) ; } } static int ni ( ) { return sc . nextInt ( ) ; } static long nl ( ) { return sc . nextLong ( ) ; } static String ns ( ) { return sc . next ( ) ; } static int [ ] niarr ( int N ) { int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } return a ; } static long [ ] nlarr ( int N ) { long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } return a ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean flag = false , imposible = false ; ArrayList < Integer > a = new ArrayList < Integer > ( ) ; ArrayList < Integer > b = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { b . add ( sc . nextInt ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = b . size ( ) - 1 ; 0 <= j ; j -- ) { if ( b . get ( j ) == j + 1 ) { a . add ( j + 1 ) ; b . remove ( j ) ; flag = true ; break ; } } if ( flag == false ) { imposible = true ; break ; } else { flag = false ; } } if ( imposible == true ) { System . out . println ( - 1 ) ; } else { for ( int i = a . size ( ) - 1 ; 0 <= i ; i -- ) { System . out . println ( a . get ( i ) ) ; } } } }",
"import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { static int n , k ; static long mod = 1000000000 + 7 ; static long [ ] fac , inv ; static int [ ] id , size ; static ArrayList < Integer > ans = new ArrayList < > ( ) ; static boolean flag = true ; public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > rec = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) rec . add ( sc . nextInt ( ) ) ; LinkedList < Integer > ans = new LinkedList < > ( ) ; while ( rec . size ( ) > 0 ) { int idx = - 1 ; for ( int i = rec . size ( ) - 1 ; i >= 0 ; i -- ) { if ( rec . get ( i ) == i + 1 ) { idx = i ; break ; } } if ( idx == - 1 ) break ; ans . addFirst ( rec . get ( idx ) ) ; rec . remove ( idx ) ; } if ( ans . size ( ) != n ) System . out . println ( - 1 ) ; else { for ( int w : ans ) System . out . println ( w ) ; } } }"
] | [
"import sys NEW_LINE N = int ( input ( ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = [ ] NEW_LINE while len ( b ) > 0 : NEW_LINE INDENT poped = False NEW_LINE for i in range ( len ( b ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if i + 1 == b [ i ] : NEW_LINE INDENT ans . append ( b . pop ( i ) ) NEW_LINE poped = True NEW_LINE break NEW_LINE DEDENT DEDENT if not poped : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT ans . reverse ( ) NEW_LINE for a in ans : NEW_LINE INDENT print ( a ) NEW_LINE DEDENT",
"_ , s = open ( 0 ) ; a = [ ' ' ] NEW_LINE for i in s . split ( ) : a . insert ( int ( i ) - 1 , i ) NEW_LINE print ( * a [ - 1 ] and [ - 1 ] or a ) NEW_LINE",
"listOutput = list ( ) NEW_LINE listInput = list ( ) NEW_LINE nNum = int ( input ( ) ) NEW_LINE strInput = input ( ) NEW_LINE listInput = strInput . split ( ) NEW_LINE while ( len ( listInput ) > 0 ) and ( ( nNum - 1 ) >= 0 ) : NEW_LINE INDENT if int ( listInput [ nNum - 1 ] ) == nNum : NEW_LINE INDENT listOutput . insert ( 0 , nNum ) NEW_LINE del listInput [ nNum - 1 ] NEW_LINE nNum = len ( listInput ) NEW_LINE continue NEW_LINE DEDENT nNum -= 1 NEW_LINE DEDENT if len ( listInput ) == 0 : NEW_LINE INDENT while ( len ( listOutput ) > 0 ) : NEW_LINE INDENT print ( listOutput . pop ( 0 ) ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' - 1' ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a = [ 0 for i in range ( N ) ] NEW_LINE number = [ ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT for i in range ( len ( b ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( i + 1 == b [ i ] and a [ i ] == 0 ) : NEW_LINE INDENT del a [ i ] NEW_LINE number . append ( b [ i ] ) NEW_LINE del b [ i ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if ( not a ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT print ( number . pop ( ) ) NEW_LINE DEDENT DEDENT if ( a ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT",
"a = [ ] NEW_LINE num_len = int ( input ( ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N = 100 NEW_LINE for i in range ( num_len ) : NEW_LINE INDENT if b [ i ] - 1 <= len ( a ) : NEW_LINE INDENT a . insert ( b [ i ] - 1 , b [ i ] ) NEW_LINE flag = True NEW_LINE DEDENT else : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT for i in a : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT"
] |
atcoder_agc023_A | [
"import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextLong ( ) ; } sc . close ( ) ; long [ ] b = new long [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { b [ i + 1 ] = b [ i ] + A [ i ] ; } Map < Long , Long > m = new TreeMap < Long , Long > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { m . merge ( b [ i ] , 1l , ( v1 , v2 ) -> ( v1 + v2 ) ) ; } long ans = 0 ; for ( long k : m . keySet ( ) ) { if ( k == 0 ) { long t = m . get ( k ) ; ans += t * ( t + 1 ) / 2 ; } else { long t = m . get ( k ) ; ans += t * ( t - 1 ) / 2 ; } } System . out . println ( ans ) ; } }",
"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 ( ) ; long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long [ ] acc = new long [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { acc [ i + 1 ] = acc [ i ] + a [ i ] ; } Map < Long , Integer > cnts = new HashMap < > ( ) ; for ( int i = 0 ; i <= N ; i ++ ) { int cnt = cnts . containsKey ( acc [ i ] ) ? cnts . get ( acc [ i ] ) : 0 ; cnts . put ( acc [ i ] , ++ cnt ) ; } long ans = 0 ; for ( Map . Entry e : cnts . entrySet ( ) ) { int num = ( int ) e . getValue ( ) ; ans += ( long ) num * ( num - 1 ) / 2 ; } out . println ( ans ) ; } }",
"import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . PriorityQueue ; import java . util . Scanner ; import java . util . TreeSet ; import org . omg . Messaging . SyncScopeHelper ; import org . omg . PortableInterceptor . SYSTEM_EXCEPTION ; public class Main { Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) ; } public Main ( ) { new Test_200 ( ) . doIt ( ) ; } class Test_200 { void doIt ( ) { int N = sc . nextInt ( ) ; long S [ ] = new long [ N + 1 ] ; S [ 0 ] = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { S [ i ] = S [ i - 1 ] + sc . nextLong ( ) ; } Arrays . sort ( S ) ; long ans = 0 ; long cnt = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { if ( S [ i ] == S [ i - 1 ] ) { cnt ++ ; ans = ans + cnt ; } else cnt = 0 ; } System . out . println ( ans ) ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashMap ; public class Main { static long t [ ] ; static long l [ ] ; static long h [ ] ; public static void main ( String [ ] args ) throws IOException { BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ; String s ; String sl [ ] ; s = r . readLine ( ) ; int n = Integer . parseInt ( s ) ; HashMap < Long , Long > m = new HashMap < > ( ) ; m . put ( 0L , 1L ) ; long a = 0 ; long v = 0 ; s = r . readLine ( ) ; sl = s . split ( \" β \" ) ; for ( int i = 0 ; i < n ; i ++ ) { v += Long . parseLong ( sl [ i ] ) ; Long z = m . get ( v ) ; if ( z != null && z > 0 ) { a += z ; } z = m . getOrDefault ( v , 0L ) ; m . put ( v , z + 1 ) ; } System . out . println ( a ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) + 1 ; long [ ] nums = new long [ n ] ; nums [ 0 ] = 0 ; long output = 0 ; for ( int i = 1 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { nums [ i ] += nums [ i - 1 ] ; } Arrays . sort ( nums ) ; long tmp = Integer . MIN_VALUE ; int outtmp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( tmp == nums [ i ] ) { outtmp ++ ; if ( i == n - 1 ) { i -- ; tmp = Integer . MIN_VALUE ; } } else { if ( outtmp > 1 ) { output += nc2 ( outtmp ) ; } tmp = nums [ i ] ; outtmp = 1 ; } } System . out . println ( output ) ; } static long nc2 ( long input ) { long output = 1 ; output = input * ( input - 1 ) / 2 ; return output ; } }"
] | [
"n = int ( input ( ) ) NEW_LINE a = list ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE sa = [ 0 ] * ( n + 1 ) NEW_LINE num_cnt = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT sa [ i + 1 ] = sa [ i ] + a [ i ] NEW_LINE DEDENT for num in sa : NEW_LINE INDENT if num in num_cnt : NEW_LINE INDENT num_cnt [ num ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT num_cnt [ num ] = 1 NEW_LINE DEDENT DEDENT res = 0 NEW_LINE for cnt in num_cnt . values ( ) : NEW_LINE INDENT res += cnt * ( cnt - 1 ) // 2 NEW_LINE DEDENT print ( res ) NEW_LINE",
"import collections , itertools ; input ( ) ; print ( sum ( ( s * ( s - 1 ) ) // 2 for s in collections . Counter ( ( i for i in itertools . accumulate ( [ 0 ] + [ int ( i ) for i in input ( ) . split ( ) ] ) ) ) . values ( ) ) ) NEW_LINE",
"from itertools import * NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE from collections import * NEW_LINE n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE def cmb ( n , r ) : NEW_LINE INDENT r = min ( n - r , r ) NEW_LINE if r == 0 : return 1 NEW_LINE over = reduce ( mul , range ( n , n - r , - 1 ) ) NEW_LINE under = reduce ( mul , range ( 1 , r + 1 ) ) NEW_LINE return over // under NEW_LINE DEDENT b = list ( accumulate ( a ) ) NEW_LINE print ( sum ( cmb ( v , 2 ) for k , v in Counter ( b ) . items ( ) if v > 1 ) + b . count ( 0 ) ) NEW_LINE",
"import sys NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = input ( ) . split ( \" β \" ) NEW_LINE A = [ int ( s ) for s in A ] NEW_LINE maps = [ 0 ] * ( len ( A ) ) NEW_LINE for i , val in enumerate ( A ) : NEW_LINE INDENT maps [ i ] = maps [ i - 1 ] + val NEW_LINE DEDENT maps . append ( 0 ) NEW_LINE counts = { } NEW_LINE for i , val in enumerate ( maps ) : NEW_LINE INDENT if val in counts : NEW_LINE INDENT counts [ val ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT counts [ val ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for key , val in counts . items ( ) : NEW_LINE INDENT if val == 1 : NEW_LINE INDENT continue NEW_LINE DEDENT for i in range ( val - 1 , 0 , - 1 ) : NEW_LINE INDENT ans += i NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"from collections import defaultdict NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dp = defaultdict ( int , { 0 : 1 } ) NEW_LINE s = 0 NEW_LINE ans = 0 NEW_LINE for a in A : NEW_LINE INDENT s += a NEW_LINE ans += dp [ s ] NEW_LINE dp [ s ] += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_agc020_C | [
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; sum += a [ i ] ; } BitSet bs = new BitSet ( sum + 1 ) ; bs . set ( sum ) ; for ( int i = 0 ; i < n ; i ++ ) { BitSet cur = bs . get ( a [ i ] , sum + 1 ) ; bs . or ( cur ) ; } int ini = sum % 2 == 0 ? sum / 2 : ( sum + 1 ) / 2 ; for ( int i = ini ; i <= sum ; i ++ ) { if ( bs . get ( i ) ) { System . out . println ( i ) ; break ; } } } }",
"import java . io . FileNotFoundException ; import java . math . BigInteger ; import java . util . Arrays ; import java . util . Scanner ; class Main { public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int s = 0 ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = sc . nextInt ( ) ; s += a [ i ] ; } BigInteger can = BigInteger . ONE ; for ( int i = 0 ; i < n ; ++ i ) { can = can . shiftLeft ( a [ i ] ) . or ( can ) ; } for ( int i = ( s + 1 ) / 2 ; i <= s ; ++ i ) { if ( can . testBit ( i ) ) { System . out . println ( i ) ; return ; } } } void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } public static void main ( String [ ] args ) throws FileNotFoundException { new Main ( ) . run ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; sum += a [ i ] ; } int len = 4000001 ; BitSet bs = new BitSet ( len ) ; bs . set ( len ) ; for ( int i = 0 ; i < n ; i ++ ) { BitSet shift = bs . get ( a [ i ] , len + 1 ) ; bs . or ( shift ) ; } for ( int i = len - ( sum + 1 ) / 2 ; i > 0 ; i -- ) { if ( bs . get ( i ) ) { System . out . println ( len - i ) ; break ; } } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . util . BitSet ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; MedianSum solver = new MedianSum ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class MedianSum { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int [ ] A = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = in . nextInt ( ) ; sum += A [ i ] ; } BitSet bitSet = new BitSet ( sum ) ; bitSet . set ( sum ) ; for ( int i = 0 ; i < N ; i ++ ) { bitSet . or ( bitSet . get ( A [ i ] , sum + 1 ) ) ; } out . println ( bitSet . nextSetBit ( ( sum + 1 ) / 2 ) ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; sum += a [ i ] ; } BitSet bs = new BitSet ( sum + 1 ) ; bs . set ( sum ) ; for ( int i = 0 ; i < n ; i ++ ) { BitSet cur = bs . get ( a [ i ] , sum + 1 ) ; bs . or ( cur ) ; } int ini = sum % 2 == 0 ? sum / 2 : ( sum + 1 ) / 2 ; for ( int i = ini ; i <= sum ; i ++ ) { if ( bs . get ( i ) ) { System . out . println ( i ) ; break ; } } } }"
] | [
"from collections import defaultdict , deque NEW_LINE import sys , heapq , bisect , math , itertools , string , queue , datetime NEW_LINE sys . setrecursionlimit ( 10 ** 8 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE eps = 10 ** - 7 NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def inpl_s ( ) : return list ( input ( ) . split ( ) ) NEW_LINE N = int ( input ( ) ) NEW_LINE aa = inpl ( ) NEW_LINE b = 1 NEW_LINE for a in aa : NEW_LINE INDENT b |= b << a NEW_LINE DEDENT S = sum ( aa ) NEW_LINE half = ( S + 1 ) // 2 NEW_LINE b >>= half NEW_LINE print ( ( b & - b ) . bit_length ( ) + half - 1 ) NEW_LINE",
"import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE eps = 1.0 / 10 ** 15 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 I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def pf ( s ) : return print ( s , flush = True ) NEW_LINE def main ( ) : NEW_LINE INDENT n = I ( ) NEW_LINE a = LI ( ) NEW_LINE s = sum ( a ) NEW_LINE t = 1 NEW_LINE m = 2 ** ( s // 2 + 1 ) - 1 NEW_LINE for c in a : NEW_LINE INDENT t |= t << c NEW_LINE DEDENT t &= m NEW_LINE return s - ( t . bit_length ( ) - 1 ) NEW_LINE DEDENT print ( main ( ) ) NEW_LINE",
"import math NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sumA = sum ( A ) NEW_LINE halfA = math . ceil ( sumA / 2 ) NEW_LINE bitset = 1 NEW_LINE for a in A : bitset |= bitset << a NEW_LINE bitset >>= halfA NEW_LINE i = 0 NEW_LINE while 1 : NEW_LINE INDENT if bitset & 1 : NEW_LINE INDENT print ( i + halfA ) NEW_LINE exit ( ) NEW_LINE DEDENT bitset >>= 1 NEW_LINE i += 1 NEW_LINE DEDENT",
"import numpy NEW_LINE n = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE dp = 1 NEW_LINE for i in range ( 0 , len ( a ) ) : NEW_LINE INDENT dp = ( dp | ( dp << a [ i ] ) ) NEW_LINE DEDENT asum = 0 NEW_LINE for i in range ( 0 , len ( a ) ) : NEW_LINE INDENT asum += a [ i ] NEW_LINE DEDENT for i in range ( int ( ( asum + 1 ) / 2 ) , asum + 1 ) : NEW_LINE INDENT if ( dp >> i ) & 1 : NEW_LINE INDENT print ( i ) NEW_LINE break NEW_LINE DEDENT DEDENT",
"input ( ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dp = 1 NEW_LINE for x in a : NEW_LINE INDENT dp |= dp << x NEW_LINE DEDENT s = sum ( a ) NEW_LINE dp >>= ( s + 1 ) // 2 NEW_LINE dp <<= ( s + 1 ) // 2 NEW_LINE dp = bin ( dp ) NEW_LINE print ( len ( dp ) - len ( dp . rstrip ( '0' ) ) ) NEW_LINE"
] |
atcoder_abc026_D | [
"import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double A = ( double ) ( sc . nextInt ( ) ) ; double B = ( double ) ( sc . nextInt ( ) ) ; double C = ( double ) ( sc . nextInt ( ) ) ; double PI = 3.1415926535897932384626d ; double min = 0d ; double max = 100d ; while ( Math . abs ( A * min + B * Math . sin ( C * PI * min ) - 100d ) > 0.0000001 ) { double middle = ( min + max ) / 2 ; if ( A * middle + B * Math . sin ( C * PI * middle ) - 100d < 0 ) { min = middle ; } else { max = middle ; } } System . out . println ( min ) ; } }",
"import java . util . Scanner ; public class Main { private static double eps = 1e-9 ; private static double f ( int a , int b , int c , double x ) { return a * x + b * Math . sin ( c * x * Math . PI ) ; } public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int a = Integer . parseInt ( sc . next ( ) ) ; int b = Integer . parseInt ( sc . next ( ) ) ; int c = Integer . parseInt ( sc . next ( ) ) ; double left = 0.0 , right = 1000.0 ; for ( int i = 0 ; i < 100 ; i ++ ) { double mid = ( left + right ) / 2 ; if ( f ( a , b , c , mid ) - 100 > eps ) { right = mid ; } else { left = mid ; } } System . out . println ( left ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { int a , b , c ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; c = sc . nextInt ( ) ; solve ( ) ; } void solve ( ) { double low = 0 ; double high = 100 ; int count = 0 ; while ( count < 10000 ) { double mid = ( low + high ) / 2 ; double value = f ( mid ) ; if ( value >= 100 ) { high = mid ; } else { low = mid ; } count ++ ; } System . out . println ( low ) ; } double f ( double t ) { return a * t + b * Math . sin ( c * t * Math . PI ) ; } 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 java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; import java . util . function . DoubleUnaryOperator ; 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 ) ; D1 solver = new D1 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class D1 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int a = in . nextInt ( ) , b = in . nextInt ( ) , c = in . nextInt ( ) ; DoubleUnaryOperator calc = t -> a * t + b * Math . sin ( c * t * Math . PI ) ; double min = 0.0 , max = 128.0 ; while ( max - min > 1e-12 ) { double mid = ( min + max ) / 2.0 ; if ( calc . applyAsDouble ( mid ) > 100 ) { max = mid ; } else { min = mid ; } } out . println ( max ) ; } } }",
"import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { static Scanner s = new Scanner ( System . in ) ; static int getInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } static IntStream REPS ( int v ) { return IntStream . range ( 0 , v ) ; } static IntStream REPS ( int l , int r ) { return IntStream . rangeClosed ( l , r ) ; } static IntStream INS ( int n ) { return REPS ( n ) . map ( i -> getInt ( ) ) ; } static class Pair < T , U > { T l ; U r ; Pair ( T L , U R ) { l = L ; r = R ; } T getL ( ) { return l ; } U getR ( ) { return r ; } } static final int a = getInt ( ) , b = getInt ( ) , c = getInt ( ) ; public static void main ( String [ ] $ ) { double d = 1 , t = 0 ; while ( true ) { if ( f ( d + t ) < 100 ) t += d ; else d /= 10 ; if ( Math . abs ( f ( t ) - 100 ) <= 0.000001 ) break ; } System . out . println ( t ) ; } static double f ( double t ) { return t * a + Math . sin ( t * c * Math . PI ) * b ; } }"
] | [
"import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE from math import sin , pi NEW_LINE def ev ( a , b , c , t ) : NEW_LINE INDENT return a * t + b * sin ( pi * c * t ) NEW_LINE DEDENT a , b , c = li ( ) NEW_LINE prev = 0 NEW_LINE while prev + ( 1 / 2 * c ) < ( 100 - b ) / a : NEW_LINE INDENT prev += 1 / ( 2 * c ) NEW_LINE DEDENT cur = prev + 1 / ( 2 * c ) NEW_LINE while ( 100 - ev ( a , b , c , prev ) ) * ( 100 - ev ( a , b , c , cur ) ) > 0 : NEW_LINE INDENT prev += 1 / ( 2 * c ) NEW_LINE cur += 1 / ( 2 * c ) NEW_LINE DEDENT left = prev NEW_LINE right = cur NEW_LINE pl = True NEW_LINE if ev ( a , b , c , left ) < ev ( a , b , c , right ) : NEW_LINE INDENT pl = True NEW_LINE DEDENT else : NEW_LINE INDENT pl = False NEW_LINE DEDENT eps = 1 / ( 10 ** 10 ) NEW_LINE while right - left > eps : NEW_LINE INDENT mid = ( right + left ) / 2 NEW_LINE if ev ( a , b , c , mid ) > 100 : NEW_LINE INDENT if pl : NEW_LINE INDENT right = mid NEW_LINE DEDENT else : NEW_LINE INDENT left = mid NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if pl : NEW_LINE INDENT left = mid NEW_LINE DEDENT else : NEW_LINE INDENT right = mid NEW_LINE DEDENT DEDENT DEDENT print ( mid ) NEW_LINE",
"from scipy import optimize NEW_LINE import numpy as np NEW_LINE np . set_printoptions ( precision = 15 ) NEW_LINE a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE def f ( x ) : NEW_LINE INDENT return a * x + b * np . sin ( c * np . pi * x ) - 100 NEW_LINE DEDENT ans = optimize . newton ( f , 0 ) NEW_LINE print ( ans ) NEW_LINE",
"import sys NEW_LINE input = sys . stdin . readline NEW_LINE import math NEW_LINE a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE def f ( t ) : NEW_LINE INDENT return a * t + b * math . sin ( c * t * math . pi ) NEW_LINE DEDENT left = 0 NEW_LINE right = 10000 NEW_LINE while abs ( f ( right ) - 100 ) > 10 ** ( - 6 ) : NEW_LINE INDENT mid = ( left + right ) / 2 NEW_LINE f_mid = f ( mid ) NEW_LINE if f_mid >= 100 : NEW_LINE INDENT right = mid NEW_LINE DEDENT else : NEW_LINE INDENT left = mid NEW_LINE DEDENT DEDENT print ( right ) NEW_LINE",
"import math NEW_LINE def takahashi_ball1 ( A : int , B : int , C : int ) -> float : NEW_LINE INDENT E = 10 ** ( - 6 ) NEW_LINE def f ( t : float ) -> float : NEW_LINE INDENT return A * t + B * math . sin ( C * t * math . pi ) NEW_LINE DEDENT def newton ( ta : float , tb : float , g ) -> float : NEW_LINE INDENT if g ( tb ) < 0 : NEW_LINE INDENT ta , tb = tb , ta NEW_LINE DEDENT while True : NEW_LINE INDENT m = ( ta + tb ) / 2 NEW_LINE if abs ( g ( m ) ) < E : NEW_LINE INDENT return m NEW_LINE DEDENT if g ( m ) < 0 : NEW_LINE INDENT ta = m NEW_LINE DEDENT else : NEW_LINE INDENT tb = m NEW_LINE DEDENT DEDENT DEDENT ta = 0 NEW_LINE k = 0 NEW_LINE while True : NEW_LINE INDENT tb = ta NEW_LINE ta = ( 2 * k + 1 ) // ( 2 * C ) NEW_LINE if ( f ( tb ) - 100 ) * ( f ( ta ) - 100 ) < 0 : NEW_LINE INDENT return newton ( ta , tb , lambda x : f ( x ) - 100 ) NEW_LINE DEDENT elif ( f ( tb ) - 100 ) * ( f ( ta ) - 100 ) <= E * E : NEW_LINE INDENT if abs ( f ( tb ) - 100 ) <= E : NEW_LINE INDENT return tb NEW_LINE DEDENT if abs ( f ( ta ) - 100 ) <= E : NEW_LINE INDENT return ta NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT k += 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT A , B , C = map ( int , input ( ) . split ( ) ) NEW_LINE ans = takahashi_ball1 ( A , B , C ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"from math import pi NEW_LINE from math import sin NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE A , B , C = map ( int , input ( ) . split ( ) ) NEW_LINE def f ( t ) : NEW_LINE INDENT return A * t + B * sin ( C * t * pi ) - 100 NEW_LINE DEDENT e = 10 ** ( - 7 ) NEW_LINE def check ( y ) : NEW_LINE INDENT if abs ( y ) <= e : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT False NEW_LINE DEDENT DEDENT lower = 0 NEW_LINE upper = 100 NEW_LINE mid = ( lower + upper ) / 2 NEW_LINE for _ in range ( 10 ** 4 ) : NEW_LINE INDENT mid = ( upper + lower ) / 2 NEW_LINE yl = f ( lower ) NEW_LINE ym = f ( mid ) NEW_LINE yu = f ( upper ) NEW_LINE if yl * ym >= 0 : NEW_LINE INDENT lower = mid NEW_LINE DEDENT else : NEW_LINE INDENT upper = mid NEW_LINE DEDENT DEDENT print ( mid ) NEW_LINE"
] |
atcoder_abc076_B | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ans < m ) ans *= 2 ; else ans += m ; } System . out . println ( ans ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; int k = Integer . parseInt ( input . readLine ( ) ) ; System . out . println ( calc ( n , 1 , k , 1 ) ) ; } public static int calc ( int k , int count , int incrementValue , int sum ) { if ( count > k ) { return sum ; } return Math . min ( calc ( k , count + 1 , incrementValue , sum * 2 ) , calc ( k , count + 1 , incrementValue , sum + incrementValue ) ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { ans = Math . min ( ans * 2 , ans + K ) ; } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int mod = 1000000007 ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . min ( ans + k , 2 * ans ) ; } System . out . println ( ans ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int ans = 1 ; while ( N > 0 ) { ans += Math . min ( ans , K ) ; N -- ; } System . out . println ( ans ) ; } }"
] | [
"N = int ( input ( ) ) NEW_LINE K = int ( input ( ) ) NEW_LINE ans = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT a = 2 * ans NEW_LINE b = ans + K NEW_LINE ans = min ( a , b ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"n , k = map ( int , open ( 0 ) ) ; r = 1 ; exec ( ' r + = min ( r , k ) ; ' * n ) ; print ( r ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def POW ( x , y ) : NEW_LINE INDENT if y == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif y == 1 : NEW_LINE INDENT return x NEW_LINE DEDENT elif y % 2 == 0 : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 % MOD NEW_LINE DEDENT else : NEW_LINE INDENT return POW ( x , y // 2 ) ** 2 * x % MOD NEW_LINE DEDENT DEDENT def mod_factorial ( x , y ) : return x * POW ( y , MOD - 2 ) % MOD 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 from functools import reduce NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE K = II ( ) NEW_LINE ans = 1 NEW_LINE for _ in range ( N ) : NEW_LINE INDENT if ans < K : NEW_LINE INDENT ans *= 2 NEW_LINE DEDENT else : NEW_LINE INDENT ans += K NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE dp = [ [ 0 , 0 ] for i in range ( n + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE dp [ 0 ] [ 1 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT dp [ i ] [ 0 ] = min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) * 2 NEW_LINE dp [ i ] [ 1 ] = min ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + k NEW_LINE DEDENT print ( min ( dp [ n ] [ 0 ] , dp [ n ] [ 1 ] ) ) NEW_LINE",
"num = 1 NEW_LINE n = int ( input ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE while num <= k and n : NEW_LINE INDENT num *= 2 NEW_LINE n -= 1 NEW_LINE DEDENT while n : NEW_LINE INDENT num += k NEW_LINE n -= 1 NEW_LINE DEDENT print ( num ) NEW_LINE"
] |
atcoder_abc080_B | [
"import java . util . Scanner ; public class Main { private static int findSumOfDigit ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += n % 10 ; n /= 10 ; } return sum ; } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int sumOfDigit = findSumOfDigit ( n ) ; System . out . println ( n % sumOfDigit == 0 ? \" Yes \" : \" No \" ) ; } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; System . out . println ( n % getSum ( n ) == 0 ? \" Yes \" : \" No \" ) ; } public static int getSum ( int n ) { int sum = 0 ; while ( n > 9 ) { sum += n % 10 ; n /= 10 ; } if ( n > 0 ) sum += n ; return sum ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int n = a ; int [ ] array = new int [ 8 ] ; int b = 10 ; int sum = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { array [ i ] = a % b ; a -= array [ i ] ; sum += array [ i ] / ( b / 10 ) ; b *= 10 ; } if ( n % sum == 0 ) { System . out . println ( \" Yes \" ) ; } else { System . out . println ( \" No \" ) ; } } }",
"import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int initialN = n ; int x = 0 ; while ( n % 10 != 0 ) { x += n % 10 ; n /= 10 ; } if ( initialN % x == 0 ) { System . out . println ( \" Yes \" ) ; } else { System . out . println ( \" No \" ) ; } } }",
"import java . util . * ; class Main { public static int findSumOfDigits ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += n % 10 ; n = n / 10 ; } return sum ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int sum = findSumOfDigits ( N ) ; if ( N % sum == 0 ) { System . out . print ( \" Yes \" ) ; } else { System . out . print ( \" No \" ) ; } } }"
] | [
"n = input ( ) NEW_LINE print ( \" Yes \" if int ( n ) % sum ( map ( int , n ) ) == 0 else \" No \" ) NEW_LINE",
"def n ( num ) : NEW_LINE INDENT ret = 0 NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT ret += int ( ( num % ( 10 ** ( i + 1 ) ) ) / ( 10 ** i ) ) NEW_LINE DEDENT return ret NEW_LINE DEDENT a = int ( input ( ) ) NEW_LINE if a % n ( a ) == 0 : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE n = N NEW_LINE tmp = 0 NEW_LINE while 1 : NEW_LINE INDENT tmp += n % 10 NEW_LINE n = int ( n / 10 ) NEW_LINE if n == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ' Yes ' if N % tmp == 0 else ' No ' ) NEW_LINE",
"n = input ( ) . rstrip ( ) NEW_LINE keta_sum = sum ( [ int ( item ) for item in n ] ) NEW_LINE if int ( n ) % keta_sum == 0 : NEW_LINE INDENT print ( \" Yes \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" No \" ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE result = [ ] NEW_LINE memo = N NEW_LINE while memo > 0 : NEW_LINE INDENT result . append ( memo % 10 ) NEW_LINE memo //= 10 NEW_LINE DEDENT if N % sum ( result ) == 0 : NEW_LINE INDENT print ( \" Yes \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" No \" ) NEW_LINE DEDENT"
] |
atcoder_abc119_C | [
"import java . util . Scanner ; public class Main { static int N , A , B , C ; static int [ ] l ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; C = sc . nextInt ( ) ; l = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { l [ i ] = sc . nextInt ( ) ; } System . out . println ( cost ( 0 , 0 , 0 , 0 ) ) ; sc . close ( ) ; } static int cost ( int depth , int a , int b , int c ) { int INF = ( int ) 10e8 ; int pattern0 , pattern1 , pattern2 , pattern3 ; if ( depth == N ) { if ( a > 0 && b > 0 && c > 0 ) { return Math . abs ( a - A ) + Math . abs ( b - B ) + Math . abs ( c - C ) - 30 ; } else { return INF ; } } pattern0 = cost ( depth + 1 , a , b , c ) ; pattern1 = cost ( depth + 1 , a + l [ depth ] , b , c ) + 10 ; pattern2 = cost ( depth + 1 , a , b + l [ depth ] , c ) + 10 ; pattern3 = cost ( depth + 1 , a , b , c + l [ depth ] ) + 10 ; return Math . min ( Math . min ( pattern0 , pattern1 ) , Math . min ( pattern2 , pattern3 ) ) ; } Main ( ) { } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { public static int A ; public static int B ; public static int C ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; C = sc . nextInt ( ) ; int [ ] l = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { l [ i ] = sc . nextInt ( ) ; } out . println ( calMin ( 0 , 0 , 0 , l , 0 , 0 ) ) ; } public static int calMin ( int a , int b , int c , int [ ] l , int i , int cost ) { if ( i == l . length ) { if ( a == 0 || b == 0 || c == 0 ) { return Integer . MAX_VALUE ; } else { return cost + Math . abs ( A - a ) + Math . abs ( B - b ) + Math . abs ( C - c ) - 30 ; } } return Math . min ( Math . min ( calMin ( a + l [ i ] , b , c , l , i + 1 , cost + 10 ) , calMin ( a , b + l [ i ] , c , l , i + 1 , cost + 10 ) ) , Math . min ( calMin ( a , b , c + l [ i ] , l , i + 1 , cost + 10 ) , calMin ( a , b , c , l , i + 1 , cost ) ) ) ; } }",
"import java . util . stream . IntStream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; private static int n , a , b , c , l [ ] ; public static void main ( String [ ] args ) { n = scanner . nextInt ( ) ; a = scanner . nextInt ( ) ; b = scanner . nextInt ( ) ; c = scanner . nextInt ( ) ; l = IntStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) ) . toArray ( ) ; System . out . println ( dfs ( 0 , 0 , 0 , 0 ) ) ; } private static int dfs ( int cur , int a0 , int b0 , int c0 ) { if ( cur == n ) return ( Math . min ( Math . min ( a0 , b0 ) , c0 ) > 0 ? Math . abs ( a0 - a ) + Math . abs ( b0 - b ) + Math . abs ( c0 - c ) - 30 : 1000000000 ) ; int ret0 = dfs ( cur + 1 , a0 , b0 , c0 ) ; int ret1 = dfs ( cur + 1 , a0 + l [ cur ] , b0 , c0 ) + 10 ; int ret2 = dfs ( cur + 1 , a0 , b0 + l [ cur ] , c0 ) + 10 ; int ret3 = dfs ( cur + 1 , a0 , b0 , c0 + l [ cur ] ) + 10 ; return Math . min ( Math . min ( Math . min ( ret0 , ret1 ) , ret2 ) , ret3 ) ; } }",
"import java . util . Scanner ; public class Main { int N ; int A ; int B ; int C ; int imihu ; int [ ] list ; public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } private void solve ( ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; C = sc . nextInt ( ) ; list = new int [ N ] ; for ( int index = 0 ; index < N ; index ++ ) { list [ index ] = sc . nextInt ( ) ; } imihu = ( int ) Math . pow ( 10 , 9 ) ; int answer = calculate ( 0 , 0 , 0 , 0 ) ; System . out . println ( answer ) ; } private int calculate ( int nowTake , int aTake , int bTake , int cTake ) { if ( nowTake == N ) { int min = aTake ; if ( min > bTake ) { min = bTake ; } if ( min > cTake ) { min = cTake ; } if ( min > 0 ) { return Math . abs ( A - aTake ) + Math . abs ( B - bTake ) + Math . abs ( C - cTake ) - 30 ; } else { return imihu ; } } int first = calculate ( nowTake + 1 , aTake , bTake , cTake ) ; int second = calculate ( nowTake + 1 , aTake + list [ nowTake ] , bTake , cTake ) + 10 ; int third = calculate ( nowTake + 1 , aTake , bTake + list [ nowTake ] , cTake ) + 10 ; int fourth = calculate ( nowTake + 1 , aTake , bTake , cTake + list [ nowTake ] ) + 10 ; int min = first ; if ( min > second ) { min = second ; } if ( min > third ) { min = third ; } if ( min > fourth ) { min = fourth ; } return min ; } }",
"import java . util . * ; import static java . lang . Math . * ; public class Main { static int A , B , C , N ; static int [ ] L ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; L = new int [ N ] ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; C = sc . nextInt ( ) ; int i ; for ( i = 0 ; i < N ; i ++ ) { L [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; sc = null ; System . out . println ( calmp ( 0 , 0 , 0 , 0 ) ) ; } static int calmp ( int n , int a , int b , int c ) { if ( n == N ) { return ( min ( min ( a , b ) , c ) > 0 ) ? ( abs ( A - a ) + abs ( B - b ) + abs ( C - c ) - 30 ) : 3000 ; } int mp0 = calmp ( n + 1 , a , b , c ) ; int mp1 = calmp ( n + 1 , a + L [ n ] , b , c ) + 10 ; int mp2 = calmp ( n + 1 , a , b + L [ n ] , c ) + 10 ; int mp3 = calmp ( n + 1 , a , b , c + L [ n ] ) + 10 ; return min ( min ( mp0 , mp1 ) , min ( mp2 , mp3 ) ) ; } }"
] | [
"N , A , B , C = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE L = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE def dfs ( idx , a , b , c ) : NEW_LINE INDENT if idx == N : NEW_LINE INDENT if a == 0 or b == 0 or c == 0 : NEW_LINE INDENT return 1e9 NEW_LINE DEDENT return abs ( A - a ) + abs ( B - b ) + abs ( C - c ) NEW_LINE DEDENT x = dfs ( idx + 1 , a , b , c ) NEW_LINE y = dfs ( idx + 1 , a + L [ idx ] , b , c ) + 10 * ( a != 0 ) NEW_LINE z = dfs ( idx + 1 , a , b + L [ idx ] , c ) + 10 * ( b != 0 ) NEW_LINE w = dfs ( idx + 1 , a , b , c + L [ idx ] ) + 10 * ( c != 0 ) NEW_LINE return min ( x , y , z , w ) ; NEW_LINE DEDENT ans = dfs ( 0 , 0 , 0 , 0 ) ; NEW_LINE print ( ans ) NEW_LINE",
"import sys NEW_LINE def solve ( N : int , A : int , B : int , C : int , l : \" List [ int ] \" ) : NEW_LINE INDENT result = 10000000000 NEW_LINE for i in range ( 2 ** ( N * 2 ) - 1 ) : NEW_LINE INDENT bitBase = i | 2 ** ( N * 2 ) NEW_LINE debug = False NEW_LINE mergeCost = 0 NEW_LINE a = 0 NEW_LINE b = 0 NEW_LINE c = 0 NEW_LINE invalid = False NEW_LINE debugStr = \" \" NEW_LINE for j in range ( N ) : NEW_LINE INDENT flag = ( ( 3 << ( j * 2 ) ) & bitBase ) >> ( j * 2 ) NEW_LINE if flag == 1 : NEW_LINE INDENT if a != 0 : NEW_LINE INDENT mergeCost += 10 NEW_LINE DEDENT if debug : NEW_LINE INDENT debugStr += \" A \" NEW_LINE DEDENT a += l [ j ] NEW_LINE DEDENT elif flag == 2 : NEW_LINE INDENT if b != 0 : NEW_LINE INDENT mergeCost += 10 NEW_LINE DEDENT if debug : NEW_LINE INDENT debugStr += \" B \" NEW_LINE DEDENT b += l [ j ] NEW_LINE DEDENT elif flag == 3 : NEW_LINE INDENT if c != 0 : NEW_LINE INDENT mergeCost += 10 NEW_LINE DEDENT if debug : NEW_LINE INDENT debugStr += \" C \" NEW_LINE DEDENT c += l [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT if debug : NEW_LINE INDENT debugStr += \" X \" NEW_LINE DEDENT DEDENT DEDENT if a == 0 or b == 0 or c == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT cost = mergeCost + abs ( A - a ) + abs ( B - b ) + abs ( C - c ) NEW_LINE if debug : NEW_LINE INDENT print ( debugStr ) NEW_LINE DEDENT result = min ( cost , result ) NEW_LINE DEDENT print ( result ) NEW_LINE 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 N = int ( next ( tokens ) ) NEW_LINE A = int ( next ( tokens ) ) NEW_LINE B = int ( next ( tokens ) ) NEW_LINE C = int ( next ( tokens ) ) NEW_LINE l = [ int ( next ( tokens ) ) for _ in range ( N ) ] NEW_LINE solve ( N , A , B , C , l ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"def Base_10_to_n ( X , n ) : NEW_LINE INDENT if ( int ( X / n ) ) : NEW_LINE INDENT return Base_10_to_n ( int ( X / n ) , n ) + str ( X % n ) NEW_LINE DEDENT return str ( X % n ) NEW_LINE DEDENT def scorecalc ( a , target ) : NEW_LINE INDENT if len ( a ) == 0 : NEW_LINE INDENT ans = 10 ** 9 NEW_LINE DEDENT else : NEW_LINE INDENT ans = 10 * ( len ( a ) - 1 ) NEW_LINE ans += abs ( sum ( a ) - target ) NEW_LINE DEDENT return ans NEW_LINE DEDENT n , a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE l = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT temp = int ( input ( ) ) NEW_LINE l . append ( temp ) NEW_LINE DEDENT mnm = 10 ** 9 NEW_LINE for i in range ( 1 , 4 ** n + 1 ) : NEW_LINE INDENT test = Base_10_to_n ( i , 4 ) NEW_LINE test = list ( test ) NEW_LINE for k in range ( n - len ( test ) ) : NEW_LINE INDENT test . insert ( 0 , \"0\" ) NEW_LINE DEDENT fora = [ ] NEW_LINE forb = [ ] NEW_LINE forc = [ ] NEW_LINE for k in range ( n ) : NEW_LINE INDENT if test [ k ] == \"0\" : NEW_LINE INDENT fora . append ( l [ k ] ) NEW_LINE DEDENT elif test [ k ] == \"1\" : NEW_LINE INDENT forb . append ( l [ k ] ) NEW_LINE DEDENT elif test [ k ] == \"2\" : NEW_LINE INDENT forc . append ( l [ k ] ) NEW_LINE DEDENT DEDENT temp = scorecalc ( fora , a ) + scorecalc ( forb , b ) + scorecalc ( forc , c ) NEW_LINE if temp < mnm : NEW_LINE INDENT mnm = temp NEW_LINE DEDENT DEDENT print ( mnm ) NEW_LINE",
"N , A , B , C = map ( int , input ( ) . split ( ) ) NEW_LINE bamboos = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT l = int ( input ( ) ) NEW_LINE bamboos . append ( l ) NEW_LINE DEDENT import copy NEW_LINE def dfs ( i , bs ) : NEW_LINE INDENT if i == len ( bamboos ) : NEW_LINE INDENT if not bs [ ' A ' ] or not bs [ ' B ' ] or not bs [ ' C ' ] : NEW_LINE INDENT return [ ] NEW_LINE DEDENT return [ bs ] NEW_LINE DEDENT ret = [ ] NEW_LINE tmp = copy . deepcopy ( bs ) NEW_LINE tmp [ ' A ' ] . append ( bamboos [ i ] ) NEW_LINE ret . extend ( dfs ( i + 1 , tmp ) ) NEW_LINE tmp = copy . deepcopy ( bs ) NEW_LINE tmp [ ' B ' ] . append ( bamboos [ i ] ) NEW_LINE ret . extend ( dfs ( i + 1 , tmp ) ) NEW_LINE tmp = copy . deepcopy ( bs ) NEW_LINE tmp [ ' C ' ] . append ( bamboos [ i ] ) NEW_LINE ret . extend ( dfs ( i + 1 , tmp ) ) NEW_LINE tmp = copy . deepcopy ( bs ) NEW_LINE tmp [ ' D ' ] . append ( bamboos [ i ] ) NEW_LINE ret . extend ( dfs ( i + 1 , tmp ) ) NEW_LINE return ret NEW_LINE DEDENT ABC = { ' A ' : A , ' B ' : B , ' C ' : C } NEW_LINE bs_comb = dfs ( 0 , { ' A ' : [ ] , ' B ' : [ ] , ' C ' : [ ] , ' D ' : [ ] } ) NEW_LINE import sys NEW_LINE ans = sys . maxsize NEW_LINE for bs in bs_comb : NEW_LINE INDENT cost = 0 NEW_LINE for abc in [ ' A ' , ' B ' , ' C ' ] : NEW_LINE INDENT cost += ( len ( bs [ abc ] ) - 1 ) * 10 NEW_LINE cost += abs ( sum ( bs [ abc ] ) - ABC [ abc ] ) NEW_LINE DEDENT ans = min ( ans , cost ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"from itertools import product NEW_LINE n , a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE l = [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE x = list ( product ( [ 0 , 1 , 2 , 3 ] , repeat = n ) ) NEW_LINE ans = 10 ** 10 NEW_LINE for i in range ( len ( x ) ) : NEW_LINE INDENT if x [ i ] . count ( 1 ) == 0 or x [ i ] . count ( 2 ) == 0 or x [ i ] . count ( 3 ) == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT tmpa = 0 NEW_LINE tmpb = 0 NEW_LINE tmpc = 0 NEW_LINE for j in range ( n ) : NEW_LINE INDENT if x [ i ] [ j ] == 1 : NEW_LINE INDENT tmpa += l [ j ] NEW_LINE DEDENT if x [ i ] [ j ] == 2 : NEW_LINE INDENT tmpb += l [ j ] NEW_LINE DEDENT if x [ i ] [ j ] == 3 : NEW_LINE INDENT tmpc += l [ j ] NEW_LINE DEDENT DEDENT tmpans = abs ( a - tmpa ) + abs ( b - tmpb ) + abs ( c - tmpc ) NEW_LINE tmpans += ( x [ i ] . count ( 1 ) - 1 ) * 10 + ( x [ i ] . count ( 2 ) - 1 ) * 10 + ( x [ i ] . count ( 3 ) - 1 ) * 10 NEW_LINE ans = min ( ans , tmpans ) NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc038_D | [
"import java . util . * ; public class Main { static long mod = 1000000000 + 7 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( ( sc . next ( ) ) ) ; int [ ] [ ] box = new int [ n ] [ ] ; for ( int i = 0 ; i < n ; i ++ ) { int w = Integer . parseInt ( ( sc . next ( ) ) ) ; int h = Integer . parseInt ( ( sc . next ( ) ) ) ; box [ i ] = new int [ ] { w , h } ; } Arrays . sort ( box , new myComparator ( ) ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = box [ i ] [ 1 ] ; int ans = LIS ( a ) ; System . out . println ( ans ) ; } static int LIS ( int [ ] a ) { int n = a . length ; int [ ] max = new int [ n + 1 ] ; Arrays . fill ( max , Integer . MAX_VALUE / 2 ) ; for ( int i = 0 ; i < n ; i ++ ) { int idx = Arrays . binarySearch ( max , a [ i ] ) ; if ( idx >= 0 ) continue ; idx = - ( idx + 1 ) ; max [ idx ] = Math . min ( a [ i ] , max [ idx ] ) ; } for ( int i = n ; i >= 0 ; i -- ) { if ( max [ i ] < Integer . MAX_VALUE / 2 ) return i + 1 ; } return 1 ; } static class myComparator implements Comparator < int [ ] > { public int compare ( int [ ] a , int [ ] b ) { if ( a [ 0 ] == b [ 0 ] ) return b [ 1 ] - a [ 1 ] ; else return a [ 0 ] - b [ 0 ] ; } } }",
"import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] [ ] box = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { box [ i ] [ 0 ] = scan . nextInt ( ) ; box [ i ] [ 1 ] = scan . nextInt ( ) ; } Arrays . sort ( box , new ArraySort ( ) ) ; final int INF = 1000000000 ; int dp [ ] = new int [ N + 1 ] ; int dpw [ ] = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { dp [ i ] = INF ; dpw [ i ] = INF ; } for ( int i = 0 ; i < N ; i ++ ) { int result = Arrays . binarySearch ( dp , box [ i ] [ 1 ] ) ; int insertionPoint = ( result >= 0 ) ? result : ~ result ; dp [ insertionPoint ] = box [ i ] [ 1 ] ; dpw [ insertionPoint ] = box [ i ] [ 0 ] ; } for ( int i = 0 ; i < N ; i ++ ) { if ( dp [ i + 1 ] == INF ) { System . out . println ( i + 1 ) ; break ; } } } } class ArraySort implements Comparator < int [ ] > { public int compare ( int [ ] num1 , int [ ] num2 ) { if ( num1 [ 0 ] == num2 [ 0 ] ) { return num2 [ 1 ] - num1 [ 1 ] ; } return num1 [ 0 ] - num2 [ 0 ] ; } }",
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; Box [ ] boxes = new Box [ N ] ; for ( int i = 0 ; i < N ; i ++ ) boxes [ i ] = new Box ( scanner . nextInt ( ) , scanner . nextInt ( ) ) ; Arrays . sort ( boxes , ( b1 , b2 ) -> { if ( b1 . w != b2 . w ) return b1 . w - b2 . w ; return b2 . h - b1 . h ; } ) ; int [ ] dp = new int [ N ] ; int INF = 1_000_000 ; for ( int i = 0 ; i < N ; i ++ ) dp [ i ] = INF ; for ( int i = 0 ; i < N ; i ++ ) dp [ upperBound ( dp , boxes [ i ] . h ) + 1 ] = boxes [ i ] . h ; System . out . println ( upperBound ( dp , INF ) + 1 ) ; } private static int upperBound ( int [ ] a , int k ) { int left = - 1 ; int right = a . length ; while ( right - left > 1 ) { int mid = ( left + right ) / 2 ; if ( a [ mid ] < k ) { left = mid ; } else { right = mid ; } } return left ; } private static class Box { public final int w ; public final int h ; private Box ( int w , int h ) { this . w = w ; this . h = h ; } } }",
"import java . util . Scanner ; import java . util . Arrays ; import java . util . Comparator ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Point [ ] p = new Point [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int w = sc . nextInt ( ) ; int h = sc . nextInt ( ) ; p [ i ] = new Point ( w , h ) ; } Arrays . sort ( p , new Comparator < Point > ( ) { public int compare ( Point p1 , Point p2 ) { if ( p1 . x == p2 . x ) { return - ( p1 . y - p2 . y ) ; } else { return p1 . x - p2 . x ; } } } ) ; int [ ] max = new int [ n + 1 ] ; Arrays . fill ( max , Integer . MAX_VALUE ) ; max [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int idx = Arrays . binarySearch ( max , p [ i ] . y ) ; if ( idx < 0 ) { idx = - idx - 1 ; max [ idx ] = Math . min ( max [ idx ] , p [ i ] . y ) ; } } for ( int i = n ; i >= 0 ; i -- ) { if ( max [ i ] < Integer . MAX_VALUE ) { System . out . println ( i ) ; return ; } } } static class Point { int x ; int y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } }",
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; Box [ ] boxes = new Box [ N ] ; for ( int i = 0 ; i < N ; i ++ ) boxes [ i ] = new Box ( scanner . nextInt ( ) , scanner . nextInt ( ) ) ; Arrays . sort ( boxes , ( b1 , b2 ) -> { if ( b1 . w != b2 . w ) return b1 . w - b2 . w ; return b2 . h - b1 . h ; } ) ; int [ ] dp = new int [ N ] ; int INF = 1_000_000 ; for ( int i = 0 ; i < N ; i ++ ) dp [ i ] = INF ; for ( int i = 0 ; i < N ; i ++ ) { int j = lowerBound ( dp , boxes [ i ] . h ) ; if ( j == 0 || dp [ j - 1 ] < boxes [ i ] . h ) dp [ j ] = boxes [ i ] . h ; } int max = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( dp [ i ] < INF ) max = Math . max ( max , i + 1 ) ; System . out . println ( max ) ; } private static int lowerBound ( int [ ] a , int k ) { int left = - 1 ; int right = a . length ; while ( right - left > 1 ) { int mid = ( left + right ) / 2 ; if ( k < a [ mid ] ) { right = mid ; } else { left = mid ; } } return right ; } private static class Box { public final int w ; public final int h ; private Box ( int w , int h ) { this . w = w ; this . h = h ; } } }"
] | [
"N = int ( input ( ) ) NEW_LINE S = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT w , h = map ( int , input ( ) . split ( ) ) NEW_LINE S . append ( ( w , h ) ) NEW_LINE DEDENT S . sort ( key = lambda x : x [ 0 ] , reverse = True ) NEW_LINE S . sort ( key = lambda x : x [ 1 ] ) NEW_LINE import bisect NEW_LINE DP = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT wi , hi = S [ i ] NEW_LINE idx = bisect . bisect_left ( DP , wi ) NEW_LINE if len ( DP ) == idx : NEW_LINE INDENT DP . append ( wi ) NEW_LINE DEDENT else : NEW_LINE INDENT DP [ idx ] = wi NEW_LINE DEDENT DEDENT print ( len ( DP ) ) NEW_LINE",
"import bisect NEW_LINE class BITree : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . size = n NEW_LINE self . tree = [ 0 ] * ( n + 1 ) NEW_LINE DEDENT def query ( self , i ) : NEW_LINE INDENT s = 0 NEW_LINE while i > 0 : NEW_LINE INDENT s = max ( self . tree [ i ] , s ) NEW_LINE i -= i & - i NEW_LINE DEDENT return s NEW_LINE DEDENT def update ( self , i , x ) : NEW_LINE INDENT while i <= self . size : NEW_LINE INDENT self . tree [ i ] = max ( self . tree [ i ] , x ) NEW_LINE i += i & - i NEW_LINE DEDENT DEDENT DEDENT N = int ( input ( ) ) NEW_LINE X = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT h , w = map ( int , input ( ) . split ( ) ) NEW_LINE X . append ( ( h , - w ) ) NEW_LINE DEDENT X . sort ( ) NEW_LINE h0 = [ i [ 0 ] for i in X ] NEW_LINE w0 = [ - i [ 1 ] for i in X ] NEW_LINE h1 = sorted ( list ( set ( h0 ) ) ) NEW_LINE w1 = sorted ( list ( set ( w0 ) ) ) NEW_LINE h = [ bisect . bisect_left ( h1 , t ) + 1 for t in h0 ] NEW_LINE w = [ bisect . bisect_left ( w1 , t ) + 1 for t in w0 ] NEW_LINE dp = [ 0 for i in range ( N ) ] NEW_LINE bit = BITree ( N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT dp [ i ] = bit . query ( w [ i ] - 1 ) + 1 NEW_LINE bit . update ( w [ i ] , dp [ i ] ) NEW_LINE DEDENT print ( max ( dp ) ) NEW_LINE",
"import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE L = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT w , h = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE L . append ( ( w , - h ) ) NEW_LINE DEDENT L . sort ( ) NEW_LINE import bisect NEW_LINE LIS = [ - L [ 0 ] [ 1 ] ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT h = - L [ i ] [ 1 ] NEW_LINE if LIS [ - 1 ] < h : NEW_LINE INDENT LIS . append ( h ) NEW_LINE DEDENT else : NEW_LINE INDENT LIS [ bisect . bisect_left ( LIS , h ) ] = h NEW_LINE DEDENT DEDENT print ( len ( LIS ) ) NEW_LINE",
"import bisect NEW_LINE def present ( N : int , boxes : list ) -> int : NEW_LINE INDENT sorted_boxes = sorted ( sorted ( boxes , key = lambda x : - x [ 1 ] ) , key = lambda x : x [ 0 ] ) NEW_LINE _ , w = sorted_boxes [ 0 ] NEW_LINE wrapping = [ w ] NEW_LINE for _ , w in sorted_boxes : NEW_LINE INDENT if wrapping [ - 1 ] < w : NEW_LINE INDENT wrapping . append ( w ) NEW_LINE DEDENT else : NEW_LINE INDENT wrapping [ bisect . bisect_left ( wrapping , w ) ] = w NEW_LINE DEDENT DEDENT return len ( wrapping ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE boxes = [ tuple ( int ( s ) for s in input ( ) . split ( ) ) for _ in range ( N ) ] NEW_LINE ans = present ( N , boxes ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE WH = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE WH = sorted ( WH , key = lambda x : ( x [ 0 ] , - x [ 1 ] ) ) NEW_LINE class FenwickTree : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . size = n NEW_LINE self . tree = [ 0 ] * self . size NEW_LINE DEDENT def update ( self , index , value ) : NEW_LINE INDENT x = index NEW_LINE while x < self . size : NEW_LINE INDENT if self . tree [ x ] < value : NEW_LINE INDENT self . tree [ x ] = value NEW_LINE DEDENT else : NEW_LINE INDENT return NEW_LINE DEDENT x |= x + 1 NEW_LINE DEDENT DEDENT def maximum ( self , index ) : NEW_LINE INDENT ret = 0 NEW_LINE x = index - 1 NEW_LINE while x >= 0 : NEW_LINE INDENT ret = max ( ret , self . tree [ x ] ) NEW_LINE x = ( x & ( x + 1 ) ) - 1 NEW_LINE DEDENT return ret NEW_LINE DEDENT DEDENT ft = FenwickTree ( 10 ** 5 + 1 ) NEW_LINE for p in WH : NEW_LINE INDENT ftv = ft . maximum ( p [ 1 ] ) + 1 NEW_LINE ft . update ( p [ 1 ] , ftv ) NEW_LINE DEDENT print ( ft . maximum ( 10 ** 5 + 1 ) ) NEW_LINE"
] |
atcoder_abc011_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int month = sc . nextInt ( ) ; if ( month == 12 ) { System . out . println ( \"1\" ) ; } else { System . out . println ( month + 1 ) ; } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( in . nextInt ( ) % 12 + 1 ) ; } } 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 isSpaceChar ( int c ) { return c == ' β ' || c == ' \\n ' || c == ' \\r ' || c == ' \\t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; if ( N == 12 ) { out . println ( 1 ) ; } else { out . println ( N + 1 ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; System . out . println ( a == 12 ? \"1\" : a + 1 ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) ; out . println ( n == 12 ? 1 : n + 1 ) ; } }"
] | [
"n = int ( input ( ) ) NEW_LINE if n == 12 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( n + 1 ) NEW_LINE DEDENT",
"print ( int ( input ( ) ) % 12 + 1 ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE if 1 <= N <= 11 : NEW_LINE INDENT print ( N + 1 ) NEW_LINE DEDENT elif N == 12 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT",
"n = int ( input ( ) ) + 1 NEW_LINE print ( 1 if n == 13 else n ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE m = n + 1 NEW_LINE if m > 12 : NEW_LINE INDENT print ( m - 12 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( m ) NEW_LINE DEDENT"
] |
atcoder_arc073_C | [
"import java . util . * ; import java . util . stream . Stream ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long xMin = 1L << 30 ; long xMax = 0 ; long yMin = 1L << 30 ; long yMax = 0 ; long [ ] [ ] bg = new long [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( x > y ) { int tmp = x ; x = y ; y = tmp ; } bg [ i ] [ 0 ] = x ; bg [ i ] [ 1 ] = y ; xMin = Math . min ( xMin , x ) ; xMax = Math . max ( xMax , x ) ; yMin = Math . min ( yMin , y ) ; yMax = Math . max ( yMax , y ) ; } long ans = ( xMax - xMin ) * ( yMax - yMin ) ; Arrays . sort ( bg , new Comparator < long [ ] > ( ) { public int compare ( long [ ] p1 , long [ ] p2 ) { if ( p1 [ 0 ] < p2 [ 0 ] ) return - 1 ; if ( p1 [ 0 ] > p2 [ 0 ] ) return 1 ; return 0 ; } } ) ; long yUsedMax = 0 ; long yUsedMin = 1L << 30 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { yUsedMin = Math . min ( yUsedMin , bg [ i ] [ 1 ] ) ; yUsedMax = Math . max ( yUsedMax , bg [ i ] [ 1 ] ) ; long bMin = Math . min ( yUsedMin , bg [ i + 1 ] [ 0 ] ) ; long bMax = Math . max ( yUsedMax , bg [ n - 1 ] [ 0 ] ) ; ans = Math . min ( ans , ( yMax - xMin ) * ( bMax - bMin ) ) ; } System . out . println ( ans ) ; } }"
] | [
"import heapq NEW_LINE N = int ( input ( ) ) NEW_LINE Rmax = 0 NEW_LINE Rmin = 1000000001 NEW_LINE Bmax = 0 NEW_LINE Bmin = 1000000001 NEW_LINE data = sorted ( [ sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) for i in range ( N ) ] , key = lambda x : x [ 0 ] ) NEW_LINE tempBlues = sorted ( [ d [ 1 ] for d in data ] ) NEW_LINE tempReds = [ d [ 0 ] for d in data ] NEW_LINE heapq . heapify ( tempReds ) NEW_LINE Rmin = data [ 0 ] [ 0 ] NEW_LINE Rmax = data [ N - 1 ] [ 0 ] NEW_LINE Bmax = max ( tempBlues ) NEW_LINE Bmin = min ( tempBlues ) NEW_LINE minValue = ( Rmax - Rmin ) * ( Bmax - Bmin ) NEW_LINE Bmin = Rmin NEW_LINE for i in range ( N ) : NEW_LINE INDENT heapMin = heapq . heappop ( tempReds ) NEW_LINE if heapMin == data [ i ] [ 0 ] : NEW_LINE INDENT heapq . heappush ( tempReds , data [ i ] [ 1 ] ) NEW_LINE if data [ i ] [ 1 ] > Rmax : NEW_LINE INDENT Rmax = data [ i ] [ 1 ] NEW_LINE DEDENT if ( Rmax - tempReds [ 0 ] ) * ( Bmax - Bmin ) < minValue : NEW_LINE INDENT minValue = ( Rmax - tempReds [ 0 ] ) * ( Bmax - Bmin ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( minValue ) NEW_LINE",
"def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE C = [ ( ) ] * N NEW_LINE X = [ 0 ] * N NEW_LINE Y = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT x , y = inpl ( ) NEW_LINE if x > y : NEW_LINE INDENT x , y = y , x NEW_LINE DEDENT X [ i ] = x NEW_LINE Y [ i ] = y NEW_LINE C [ i ] = ( x , y ) NEW_LINE DEDENT minx , maxx , miny , maxy = min ( X ) , max ( X ) , min ( Y ) , max ( Y ) NEW_LINE ans = ( maxy - miny ) * ( maxx - minx ) NEW_LINE ix = X . index ( minx ) NEW_LINE iy = Y . index ( maxy ) NEW_LINE l , r = X [ iy ] , Y [ ix ] NEW_LINE if r < l : NEW_LINE INDENT l , r = r , l NEW_LINE DEDENT H = [ ] NEW_LINE for x , y in C : NEW_LINE INDENT if y <= l : NEW_LINE INDENT l = y NEW_LINE continue NEW_LINE DEDENT if x >= r : NEW_LINE INDENT r = x NEW_LINE continue NEW_LINE DEDENT H . append ( ( x , y ) ) NEW_LINE DEDENT Candi = [ ] NEW_LINE for x , y in H : NEW_LINE INDENT if l <= x <= r or l <= y <= r : NEW_LINE INDENT continue NEW_LINE DEDENT Candi . append ( ( x , y ) ) NEW_LINE DEDENT Candi . sort ( ) NEW_LINE for x , y in Candi : NEW_LINE INDENT ans = min ( ans , ( maxy - minx ) * ( r - x ) ) NEW_LINE r = max ( r , y ) NEW_LINE DEDENT ans = min ( ans , ( maxy - minx ) * ( r - l ) ) NEW_LINE print ( ans ) NEW_LINE",
"import sys NEW_LINE from operator import itemgetter NEW_LINE inf = 1 << 30 NEW_LINE def solve ( ) : NEW_LINE INDENT n = int ( sys . stdin . readline ( ) ) NEW_LINE r_max = b_max = 0 NEW_LINE r_min = b_min = inf NEW_LINE p = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT xi , yi = map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE if xi > yi : NEW_LINE INDENT xi , yi = yi , xi NEW_LINE DEDENT p . append ( ( xi , yi ) ) NEW_LINE r_max = max ( r_max , yi ) NEW_LINE r_min = min ( r_min , yi ) NEW_LINE b_max = max ( b_max , xi ) NEW_LINE b_min = min ( b_min , xi ) NEW_LINE DEDENT ans1 = ( r_max - r_min ) * ( b_max - b_min ) NEW_LINE ans2 = ( r_max - b_min ) NEW_LINE p . sort ( key = itemgetter ( 0 ) ) NEW_LINE b_min = p [ 0 ] [ 0 ] NEW_LINE b_max = p [ - 1 ] [ 0 ] NEW_LINE y_min = inf NEW_LINE dif_b = b_max - b_min NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT y_min = min ( y_min , p [ i ] [ 1 ] ) NEW_LINE b_min = min ( p [ i + 1 ] [ 0 ] , y_min ) NEW_LINE b_max = max ( b_max , p [ i ] [ 1 ] ) NEW_LINE dif_b = min ( dif_b , b_max - b_min ) NEW_LINE DEDENT ans2 *= dif_b NEW_LINE ans = min ( ans1 , ans2 ) NEW_LINE print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT solve ( ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE balls = sorted ( tuple ( sorted ( map ( int , input ( ) . split ( ) ) ) ) for i in range ( N ) ) NEW_LINE maxmin = balls [ - 1 ] [ 0 ] NEW_LINE minmin = balls [ 0 ] [ 0 ] NEW_LINE maxmax = max ( b [ 1 ] for b in balls ) NEW_LINE minmax = min ( b [ 1 ] for b in balls ) NEW_LINE v1 = ( maxmin - minmin ) * ( maxmax - minmax ) NEW_LINE best = float ( ' inf ' ) NEW_LINE cur_max = maxmin NEW_LINE for b in balls : NEW_LINE INDENT if b [ 0 ] > minmax : NEW_LINE INDENT best = min ( best , cur_max - minmax ) NEW_LINE break NEW_LINE DEDENT best = min ( best , cur_max - b [ 0 ] ) NEW_LINE cur_max = max ( cur_max , b [ 1 ] ) NEW_LINE DEDENT v2 = ( maxmax - minmin ) * best NEW_LINE print ( min ( v1 , v2 ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE Ball = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE x , y = min ( x , y ) , max ( x , y ) NEW_LINE Ball . append ( ( x , y ) ) NEW_LINE DEDENT Ball . sort ( ) NEW_LINE X = [ x for x , y in Ball ] NEW_LINE Y = [ y for x , y in Ball ] NEW_LINE MIN = X [ 0 ] NEW_LINE MAX = max ( Y ) NEW_LINE ans = ( max ( X ) - MIN ) * ( MAX - min ( Y ) ) NEW_LINE MIN_index , MAX_index = X . index ( MIN ) , Y . index ( MAX ) NEW_LINE MIN_O = X [ MAX_index ] NEW_LINE MAX_O = Y [ MIN_index ] NEW_LINE MIN_O , MAX_O = min ( MIN_O , MAX_O ) , max ( MIN_O , MAX_O ) NEW_LINE Ball = [ Ball [ i ] for i in range ( N ) if i not in ( MIN_index , MAX_index ) ] NEW_LINE X = [ x for x , y in Ball ] NEW_LINE Y = [ y for x , y in Ball ] NEW_LINE B = [ x for x in X ] + [ MAX_O , MIN_O ] NEW_LINE B_max = max ( B ) NEW_LINE for i in range ( len ( Ball ) ) : NEW_LINE INDENT x , y = X [ i ] , Y [ i ] NEW_LINE if B_max - x > B_max - y >= 0 : NEW_LINE INDENT B [ i ] = y NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT ans = min ( ans , ( MAX - MIN ) * ( max ( B ) - min ( B ) ) ) NEW_LINE print ( ans ) NEW_LINE"
] |
atcoder_arc002_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int year = sc . nextInt ( ) ; boolean isUruYear = false ; if ( year % 4 == 0 ) { isUruYear = true ; } if ( year % 100 == 0 ) { isUruYear = false ; } if ( year % 400 == 0 ) { isUruYear = true ; } System . out . println ( isUruYear ? \" YES \" : \" NO \" ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int Y = in . nextInt ( ) ; String ans = \" NO \" ; if ( Y % 400 == 0 || ( Y % 4 == 0 && Y % 100 != 0 ) ) { ans = \" YES \" ; } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int y = in . nextInt ( ) ; if ( ( y % 4 == 0 && y % 100 != 0 ) || y % 400 == 0 ) out . println ( \" YES \" ) ; else out . println ( \" NO \" ) ; } } 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 isSpaceChar ( int c ) { return c == ' β ' || c == ' \\n ' || c == ' \\r ' || c == ' \\t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }",
"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 y = sc . nextInt ( ) ; if ( y % 4 != 0 ) { out . println ( \" NO \" ) ; } else { if ( y % 16 == 0 ) { out . println ( \" YES \" ) ; } else if ( y % 25 == 0 ) { out . println ( \" NO \" ) ; } else { out . println ( \" YES \" ) ; } } } }",
"import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int y = sc . nextInt ( ) ; boolean uruu = false ; if ( y % 400 == 0 ) { uruu = true ; } else if ( y % 100 != 0 && y % 4 == 0 ) { uruu = true ; } if ( uruu ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } }"
] | [
"Y = int ( input ( ) ) NEW_LINE if Y % 400 == 0 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT elif Y % 100 == 0 : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT elif Y % 4 == 0 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT",
"def main ( ) : NEW_LINE INDENT y = int ( input ( ) ) NEW_LINE if y % 400 == 0 : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT elif y % 100 == 0 : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT elif y % 4 == 0 : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"y = int ( input ( ) ) NEW_LINE print ( \" YES \" if y % 4 == 0 and y % 100 != 0 or y % 400 == 0 else \" NO \" ) NEW_LINE",
"s = int ( input ( ) ) NEW_LINE if s % 4 != 0 : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT else : NEW_LINE INDENT if s % 400 == 0 : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT elif s % 100 == 0 : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT DEDENT",
"y = int ( input ( ) ) NEW_LINE ans = 0 NEW_LINE if y % 4 == 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT if y % 100 == 0 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT if y % 400 == 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT if ans == 1 : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT"
] |
atcoder_arc032_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int score = 0 ; int n = sc . nextInt ( ) ; if ( n == 1 ) { System . out . println ( \" BOWWOW \" ) ; System . exit ( 0 ) ; } for ( int i = 0 ; i <= n ; i ++ ) { score += i ; } for ( int i = 2 ; i < Math . sqrt ( score ) ; i ++ ) { if ( score % i == 0 ) { System . out . println ( \" BOWWOW \" ) ; System . exit ( 0 ) ; } } System . out . println ( \" WANWAN \" ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; int a = sc . nextInt ( ) ; int sum = a * ( a + 1 ) / 2 ; if ( isPrime ( sum ) ) { pl ( \" WANWAN \" ) ; } else { pl ( \" BOWWOW \" ) ; } } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } public String nextLine ( ) { try { return reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } public static boolean isPrime ( int a ) { if ( a < 4 ) { if ( a == 2 || a == 3 ) { return true ; } else { return false ; } } else { for ( int j = 2 ; j * j <= a ; j ++ ) { if ( a % j == 0 ) { return false ; } if ( a % j != 0 && ( j + 1 ) * ( j + 1 ) > a ) { return true ; } } return true ; } } }",
"import java . util . * ; 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 ( ) ; n = n * ( n + 1 ) / 2 ; int t = ( int ) sqrt ( n ) + 1 ; for ( int i = 2 ; i <= t ; i ++ ) { if ( n % i == 0 ) { out . println ( \" BOWWOW \" ) ; exit ( 0 ) ; } } if ( n != 1 ) out . println ( \" WANWAN \" ) ; else out . println ( \" BOWWOW \" ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int upper = 1000000 ; int a [ ] = new int [ upper + 1 ] ; for ( int i = 2 ; i <= upper ; i ++ ) { a [ i ] = i ; } for ( int i = 2 ; i <= Math . sqrt ( upper ) ; i ++ ) { for ( int j = i + i ; j <= upper ; j += i ) { a [ j ] = 0 ; } } int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += i ; if ( a [ sum ] == 0 ) System . out . println ( \" BOWWOW \" ) ; else System . out . println ( \" WANWAN \" ) ; } }",
"import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += i ; } boolean flag = true ; if ( N == 1 ) { flag = false ; } else if ( N == 2 ) { flag = true ; } else if ( N > 2 ) { for ( int i = 2 ; i <= Math . sqrt ( sum ) ; i ++ ) { if ( sum % i == 0 ) { flag = false ; break ; } } } if ( flag ) { System . out . println ( \" WANWAN \" ) ; } else { System . out . println ( \" BOWWOW \" ) ; } } }"
] | [
"n = int ( input ( ) ) NEW_LINE def is_prime ( n ) : NEW_LINE INDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if i * i > n : NEW_LINE INDENT break NEW_LINE DEDENT if n % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return n != 1 NEW_LINE DEDENT res = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT res += i NEW_LINE DEDENT if is_prime ( res ) : NEW_LINE INDENT print ( ' WANWAN ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' BOWWOW ' ) NEW_LINE DEDENT",
"print ( \" BOWWOW \" if int ( input ( ) ) != 2 else \" WANWAN \" ) NEW_LINE",
"def a_holidog ( N ) : NEW_LINE INDENT if N == 1 : NEW_LINE INDENT return ' BOWWOW ' NEW_LINE DEDENT total = N * ( N + 1 ) // 2 NEW_LINE ans = ' BOWWOW ' NEW_LINE for k in range ( 2 , int ( total ** 0.5 ) + 1 ) : NEW_LINE INDENT if total % k == 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ans = ' WANWAN ' NEW_LINE DEDENT return ans NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE print ( a_holidog ( N ) ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE s = sum ( range ( 1 , N + 1 ) ) NEW_LINE def isPrime ( N ) : NEW_LINE INDENT if N <= 1 : NEW_LINE INDENT return False NEW_LINE DEDENT i = 2 NEW_LINE while i * i <= N : NEW_LINE INDENT if N % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return True NEW_LINE DEDENT if not isPrime ( s ) : NEW_LINE INDENT print ( \" BOWWOW \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" WANWAN \" ) NEW_LINE DEDENT",
"n = int ( input ( ) ) NEW_LINE temp = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT temp += i NEW_LINE DEDENT flag = 0 NEW_LINE if n == 1 : NEW_LINE INDENT print ( \" BOWWOW \" ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 2 , temp + 1 ) : NEW_LINE INDENT if temp % i == 0 and i != temp : NEW_LINE INDENT print ( \" BOWWOW \" ) NEW_LINE flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if flag == 0 : NEW_LINE INDENT print ( \" WANWAN \" ) NEW_LINE DEDENT DEDENT"
] |
atcoder_abc113_D | [
"import java . util . Scanner ; class Main { static final long MOD = 1000000007 ; static int H , W , K ; static long [ ] [ ] dp = new long [ 110 ] [ 10 ] ; static int ans = 0 ; static long n = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; long MOD = 1000000007 ; int [ ] [ ] dp = new int [ H + 1 ] [ W ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int h = 1 ; h <= H ; h ++ ) { for ( int w = 0 ; w < W ; w ++ ) { for ( int i = 0 ; i < ( 1 << W - 1 ) ; i ++ ) { int mask = 3 ; boolean flag = true ; while ( true ) { if ( ( mask & i ) == mask ) { flag = false ; } if ( mask == 3 << W - 1 ) { break ; } mask = mask << 1 ; } if ( flag ) { if ( w > 0 && ( i & ( 1 << w - 1 ) ) > 0 ) { dp [ h ] [ w ] += dp [ h - 1 ] [ w - 1 ] ; } else if ( w < W - 1 && ( i & ( 1 << w ) ) > 0 ) { dp [ h ] [ w ] += dp [ h - 1 ] [ w + 1 ] ; } else { dp [ h ] [ w ] += dp [ h - 1 ] [ w ] ; } dp [ h ] [ w ] %= MOD ; } } } } System . out . println ( dp [ H ] [ K - 1 ] ) ; } } class Pair implements Comparable { int from ; int end ; int num ; int bango ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return end - otherpair . end ; } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { final long mod = 1_000_000_007L ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] p = br . readLine ( ) . split ( \" β \" ) ; int h = Integer . parseInt ( p [ 0 ] ) ; int w = Integer . parseInt ( p [ 1 ] ) ; int k = Integer . parseInt ( p [ 2 ] ) ; br . close ( ) ; long [ ] [ ] a = new long [ h + 1 ] [ w + 2 ] ; long [ ] f = new long [ w + 2 ] ; a [ 0 ] [ 1 ] = 1 ; f [ 0 ] = 0 ; f [ 1 ] = f [ 2 ] = 1 ; for ( int i = 3 ; i < w + 2 ; i ++ ) f [ i ] = f [ i - 1 ] + f [ i - 2 ] ; for ( int i = 1 ; i < h + 1 ; i ++ ) for ( int j = 1 ; j < w + 1 ; j ++ ) a [ i ] [ j ] = ( f [ j - 1 ] * f [ w - j + 1 ] * a [ i - 1 ] [ j - 1 ] % mod + f [ j ] * f [ w - j + 1 ] * a [ i - 1 ] [ j ] % mod + f [ j ] * f [ w - j ] * a [ i - 1 ] [ j + 1 ] % mod ) % mod ; System . out . println ( a [ h ] [ k ] ) ; } }",
"import java . util . * ; import java . lang . * ; public class Main { static long mod = 1000000007 ; static int h ; static int w ; static int k ; static long [ ] [ ] dp ; static int i ; static int j ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; h = sc . nextInt ( ) ; w = sc . nextInt ( ) ; k = sc . nextInt ( ) ; dp = new long [ h + 1 ] [ w + 2 ] ; dp [ 0 ] [ 1 ] = 1 ; for ( i = 1 ; i <= h ; i ++ ) { for ( j = 1 ; j <= w ; j ++ ) { dfs ( 1 , false , false , false ) ; } } System . out . println ( dp [ h ] [ k ] ) ; } static void dfs ( int now , boolean te , boolean mae , boolean ato ) { if ( now == w ) { if ( mae ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] ; dp [ i ] [ j ] %= mod ; } else if ( ato ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j + 1 ] ; dp [ i ] [ j ] %= mod ; } else { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ; dp [ i ] [ j ] %= mod ; } return ; } if ( te ) { dfs ( now + 1 , false , mae , ato ) ; } else if ( now == j - 1 ) { dfs ( now + 1 , true , true , false ) ; dfs ( now + 1 , false , mae , ato ) ; } else if ( now == j ) { dfs ( now + 1 , true , mae , true ) ; dfs ( now + 1 , false , mae , ato ) ; } else { dfs ( now + 1 , true , mae , ato ) ; dfs ( now + 1 , false , mae , ato ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int k1 = sc . nextInt ( ) ; long [ ] [ ] dp = new long [ h + 1 ] [ w ] ; long mod = 1000000007 ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= h ; i ++ ) { for ( int j = w - 1 ; j >= 0 ; j -- ) { for ( int k = 0 ; k < Math . pow ( 2 , w - 1 ) ; k ++ ) { boolean a = false ; boolean b = false ; boolean jud = false ; int count = 0 ; int y = k ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) { if ( jud ) { break ; } if ( w - 1 - count == j ) { a = true ; } else if ( w - 1 - count == j + 1 ) { b = true ; } jud = true ; } else { jud = false ; } count ++ ; y >>= 1 ; if ( y <= 0 ) { jud = false ; } } if ( jud ) { continue ; } if ( j > 0 && a ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] ; } else if ( j < w - 1 && b ) { dp [ i ] [ j ] += dp [ i - 1 ] [ j + 1 ] ; } else { dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ; } dp [ i ] [ j ] %= mod ; } } } System . out . println ( dp [ h ] [ k1 - 1 ] ) ; } }",
"import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; @ SuppressWarnings ( \" unchecked \" ) public class Main { static final int INF = 1000000007 ; public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( \" β \" ) ; int H = Integer . parseInt ( sl [ 0 ] ) ; int W = Integer . parseInt ( sl [ 1 ] ) ; int K = Integer . parseInt ( sl [ 2 ] ) ; int [ ] [ ] dp = new int [ H + 1 ] [ W ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int y = 0 ; y < H ; y ++ ) { for ( int x = 0 ; x < W ; x ++ ) { for ( int k = 0 ; k < 1 << ( W - 1 ) ; k ++ ) { boolean ok = true ; for ( int l = 0 ; l < W - 2 ; l ++ ) if ( ( k >> l & 1 ) == 1 && ( k >> l + 1 & 1 ) == 1 ) ok = false ; if ( ok ) { if ( x >= 1 && ( k >> x - 1 & 1 ) == 1 ) { dp [ y + 1 ] [ x - 1 ] += dp [ y ] [ x ] ; dp [ y + 1 ] [ x - 1 ] %= INF ; } else if ( x <= W - 2 && ( k >> x & 1 ) == 1 ) { dp [ y + 1 ] [ x + 1 ] += dp [ y ] [ x ] ; dp [ y + 1 ] [ x + 1 ] %= INF ; } else { dp [ y + 1 ] [ x ] += dp [ y ] [ x ] ; dp [ y + 1 ] [ x ] %= INF ; } } } } } out . println ( dp [ H ] [ K - 1 ] ) ; out . flush ( ) ; } }"
] | [
"H , W , K = map ( int , input ( ) . split ( ) ) NEW_LINE dp = [ [ 0 for _ in range ( W ) ] for _ in range ( H + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE P = 10 ** 9 + 7 NEW_LINE def check ( l ) : NEW_LINE INDENT for i in range ( len ( l ) - 1 ) : NEW_LINE INDENT if l [ i + 1 ] + l [ i ] == 2 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT for i in range ( 1 , H + 1 ) : NEW_LINE INDENT for w in range ( W ) : NEW_LINE INDENT X , Y , Z = 0 , 0 , 0 NEW_LINE for j in range ( 2 ** ( W - 1 ) ) : NEW_LINE INDENT tmp = [ ] NEW_LINE for k in range ( W - 1 ) : NEW_LINE INDENT tmp . append ( j >> k & 1 ) NEW_LINE DEDENT if check ( tmp ) : NEW_LINE INDENT if w - 1 >= 0 and ( j >> ( w - 1 ) ) & 1 == 1 : NEW_LINE INDENT X += 1 NEW_LINE DEDENT elif w <= W - 2 and j >> w & 1 == 1 : NEW_LINE INDENT Z += 1 NEW_LINE DEDENT else : NEW_LINE INDENT Y += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT if w - 1 >= 0 : dp [ i ] [ w - 1 ] = ( dp [ i ] [ w - 1 ] + dp [ i - 1 ] [ w ] * X ) % P NEW_LINE dp [ i ] [ w ] = ( dp [ i ] [ w ] + dp [ i - 1 ] [ w ] * Y ) % P NEW_LINE if w + 1 <= W - 1 : dp [ i ] [ w + 1 ] = ( dp [ i ] [ w + 1 ] + dp [ i - 1 ] [ w ] * Z ) % P NEW_LINE DEDENT DEDENT print ( dp [ H ] [ K - 1 ] ) NEW_LINE",
"import itertools NEW_LINE height , width , k = map ( int , input ( ) . split ( ) ) NEW_LINE k -= 1 NEW_LINE MOD = 1000000007 NEW_LINE patterns = [ ] NEW_LINE for r in range ( width - 1 ) : NEW_LINE INDENT for pattern in itertools . combinations ( range ( width - 1 ) , r ) : NEW_LINE INDENT if all ( abs ( a - b ) != 1 for a , b in zip ( pattern [ : - 1 ] , pattern [ 1 : ] ) ) : NEW_LINE INDENT patterns . append ( pattern ) NEW_LINE DEDENT DEDENT DEDENT counts = [ [ 0 for _ in range ( width ) ] for _ in range ( width ) ] NEW_LINE for pattern in patterns : NEW_LINE INDENT for w in range ( width ) : NEW_LINE INDENT if w in pattern : NEW_LINE INDENT counts [ w ] [ w + 1 ] += 1 NEW_LINE DEDENT elif w - 1 in pattern : NEW_LINE INDENT counts [ w ] [ w - 1 ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT counts [ w ] [ w ] += 1 NEW_LINE DEDENT DEDENT DEDENT dp = [ [ 0 for _ in range ( width ) ] for _ in range ( height ) ] NEW_LINE dp [ 0 ] = counts [ 0 ] . copy ( ) NEW_LINE for h in range ( height - 1 ) : NEW_LINE INDENT for w in range ( width ) : NEW_LINE INDENT dp [ h + 1 ] [ w ] = sum ( [ dp [ h ] [ v ] * counts [ v ] [ w ] for v in range ( width ) ] ) % MOD NEW_LINE DEDENT DEDENT if width == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( dp [ - 1 ] [ k ] ) NEW_LINE DEDENT",
"def way ( h , w , k ) : NEW_LINE INDENT if w == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if [ h , k ] == [ 1 , 1 ] or [ h , k ] == [ 1 , 2 ] : NEW_LINE INDENT return fibo [ w - k ] NEW_LINE DEDENT if h == 1 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if memo [ h ] [ k ] != - 1 : NEW_LINE INDENT return memo [ h ] [ k ] NEW_LINE DEDENT re = way ( h - 1 , w , k ) * fibo [ k - 1 ] * fibo [ w - k ] NEW_LINE if k != 1 : NEW_LINE INDENT re += way ( h - 1 , w , k - 1 ) * fibo [ max ( k - 2 , 0 ) ] * fibo [ w - k ] NEW_LINE DEDENT if k != w : NEW_LINE INDENT re += way ( h - 1 , w , k + 1 ) * fibo [ k - 1 ] * fibo [ max ( w - k - 1 , 0 ) ] NEW_LINE DEDENT memo [ h ] [ k ] = re NEW_LINE return re NEW_LINE DEDENT h , w , k = map ( int , input ( ) . split ( ) ) NEW_LINE fibo = [ 1 , 1 ] NEW_LINE for i in range ( 2 , w ) : NEW_LINE INDENT fibo += [ fibo [ i - 1 ] + fibo [ i - 2 ] ] NEW_LINE DEDENT memo = [ [ - 1 ] * ( w + 1 ) for _ in range ( h + 1 ) ] NEW_LINE print ( way ( h , w , k ) % 1000000007 ) NEW_LINE",
"import sys NEW_LINE import functools NEW_LINE INF = float ( \" inf \" ) NEW_LINE MOD = 1000000007 NEW_LINE @ functools . lru_cache ( maxsize = None ) NEW_LINE def f ( x ) : NEW_LINE INDENT if x <= 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif x == 1 : NEW_LINE INDENT return 2 NEW_LINE DEDENT else : NEW_LINE INDENT return f ( x - 1 ) + f ( x - 2 ) NEW_LINE DEDENT DEDENT def solve ( H : int , W : int , K : int ) : NEW_LINE INDENT dp = [ 0 ] * ( W + 2 ) NEW_LINE dp [ 1 ] = 1 NEW_LINE for h in range ( H ) : NEW_LINE INDENT buf = [ 0 ] * ( W + 2 ) NEW_LINE for i in range ( 1 , W + 1 ) : NEW_LINE INDENT buf [ i ] += dp [ i - 1 ] * f ( i - 3 ) * f ( W - i - 1 ) NEW_LINE buf [ i ] %= MOD NEW_LINE buf [ i ] += dp [ i ] * f ( i - 2 ) * f ( W - i - 1 ) NEW_LINE buf [ i ] %= MOD NEW_LINE buf [ i ] += dp [ i + 1 ] * f ( i - 2 ) * f ( W - i - 2 ) NEW_LINE buf [ i ] %= MOD NEW_LINE DEDENT for i in range ( 1 , W + 1 ) : NEW_LINE INDENT dp [ i ] = buf [ i ] NEW_LINE DEDENT DEDENT print ( dp [ K ] ) NEW_LINE 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 H = int ( next ( tokens ) ) NEW_LINE W = int ( next ( tokens ) ) NEW_LINE K = int ( next ( tokens ) ) NEW_LINE solve ( H , W , K ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"from itertools import product NEW_LINE H , W , K = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE mod = int ( 1e9 + 7 ) NEW_LINE memo = [ [ 0 ] * W for _ in range ( H + 1 ) ] NEW_LINE memo [ 0 ] [ 0 ] = 1 NEW_LINE from itertools import product NEW_LINE def one_row ( W ) : NEW_LINE INDENT one_row_amida = { i : { i : 0 for i in range ( W ) } for i in range ( W ) } NEW_LINE for p in product ( [ 0 , 1 ] , repeat = W - 1 ) : NEW_LINE INDENT if any ( [ p [ i ] == 1 and p [ i + 1 ] == 1 for i in range ( W - 2 ) ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT after = [ i for i in range ( W ) ] NEW_LINE for i in range ( W - 1 ) : NEW_LINE INDENT if p [ i ] : NEW_LINE INDENT after [ i ] , after [ i + 1 ] = after [ i + 1 ] , after [ i ] NEW_LINE DEDENT DEDENT for i , a in enumerate ( after ) : NEW_LINE INDENT one_row_amida [ i ] [ a ] += 1 NEW_LINE DEDENT DEDENT return one_row_amida NEW_LINE DEDENT one_row_amida = one_row ( W ) NEW_LINE for h in range ( H ) : NEW_LINE INDENT for w in range ( W ) : NEW_LINE INDENT for j in range ( W ) : NEW_LINE INDENT memo [ h + 1 ] [ j ] += memo [ h ] [ w ] * one_row_amida [ w ] [ j ] NEW_LINE DEDENT DEDENT memo [ h + 1 ] = [ x % mod for x in memo [ h + 1 ] ] NEW_LINE DEDENT answer = memo [ H ] [ K - 1 ] NEW_LINE print ( answer ) NEW_LINE"
] |
atcoder_abc084_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int m = sc . nextInt ( ) ; System . out . println ( 48 - m ) ; } }",
"import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . PriorityQueue ; import java . util . Scanner ; import java . util . TreeSet ; import org . omg . Messaging . SyncScopeHelper ; public class Main { Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) ; } public Main ( ) { new Test_100 ( ) . doIt ( ) ; } class Test_100 { void doIt ( ) { int M = sc . nextInt ( ) ; int ans = 48 - M ; System . out . println ( ans ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int M = sc . nextInt ( ) ; System . out . println ( 24 + ( 24 - M ) ) ; } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int m ; m = Integer . parseInt ( sc . next ( ) ) ; int x = 48 - m ; System . out . println ( x ) ; sc . close ( ) ; } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( 48 - a ) ; } }"
] | [
"print ( 48 - int ( input ( ) ) ) NEW_LINE",
"M = input ( ) NEW_LINE M = int ( M ) NEW_LINE print ( 48 - M ) NEW_LINE",
"def main ( ) : NEW_LINE INDENT print ( 24 * 2 - int ( input ( ) ) ) NEW_LINE DEDENT main ( ) NEW_LINE",
"a = int ( input ( ) ) NEW_LINE print ( ( 24 - a ) + 24 ) NEW_LINE",
"print ( 48 - int ( input ( ) ) ) NEW_LINE"
] |
atcoder_abc039_C | [
"import java . util . * ; public class Main { static final String [ ] KEY = new String [ ] { \" WBWBWWBWBWBW \" , \" WBWWBWBWBWWB \" , \" WWBWBWBWWBWB \" , \" WBWBWBWWBWBW \" , \" WBWBWWBWBWWB \" , \" WBWWBWBWWBWB \" , \" WWBWBWWBWBWB \" } ; static final String [ ] VALUE = new String [ ] { \" Do \" , \" Re \" , \" Mi \" , \" Fa \" , \" So \" , \" La \" , \" Si \" } ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < KEY . length ; i ++ ) { if ( s . startsWith ( KEY [ i ] ) ) { System . out . println ( VALUE [ i ] ) ; return ; } } } }",
"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 ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { String keyboard = \" WBWBWWBWBWBWWBWBWWBWBWBWWBWBWWBWBWBW \" ; String [ ] ans = { \" Do \" , \" Do \" , \" Re \" , \" Re \" , \" Mi \" , \" Fa \" , \" Fa \" , \" So \" , \" So \" , \" La \" , \" La \" , \" Si \" } ; String s = in . next ( ) . substring ( 0 , 12 ) ; for ( int i = 0 ; i < keyboard . length ( ) - 12 ; i ++ ) { if ( s . equals ( keyboard . substring ( i , i + 12 ) ) ) { out . println ( ans [ i % 12 ] ) ; return ; } } } } 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 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isPrintableChar ( int c ) { return c >= 33 && c <= 126 ; } public String next ( ) { StringBuilder sb = new StringBuilder ( ) ; int b = readByte ( ) ; while ( ! isPrintableChar ( b ) ) b = readByte ( ) ; while ( isPrintableChar ( b ) ) { sb . appendCodePoint ( b ) ; b = readByte ( ) ; } return sb . toString ( ) ; } } }",
"import java . util . Scanner ; class Main { static int n ; static long ans = 1000000000 ; static int [ ] memo ; static int [ ] dp ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String k = sc . next ( ) ; int num = 0 ; for ( int i = 0 ; i < k . length ( ) - 4 ; i ++ ) { if ( k . charAt ( i ) == ' B ' && k . charAt ( i + 2 ) == ' B ' && k . charAt ( i + 4 ) == ' B ' ) { num = i ; break ; } } if ( num == 6 ) { System . out . println ( \" Do \" ) ; return ; } else if ( num == 4 ) { System . out . println ( \" Re \" ) ; } else if ( num == 2 ) { System . out . println ( \" Mi \" ) ; } else if ( num == 1 ) { System . out . println ( \" Fa \" ) ; } else if ( num == 11 ) { System . out . println ( \" So \" ) ; } else if ( num == 9 ) { System . out . println ( \" La \" ) ; } else if ( num == 7 ) { System . out . println ( \" Si \" ) ; } } } class Pair implements Comparable { int from ; int end ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return end - otherpair . end ; } }",
"public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { switch ( scanner . next ( ) ) { case \" WBWBWWBWBWBWWBWBWWBW \" : case \" BWBWWBWBWBWWBWBWWBWB \" : System . out . println ( \" Do \" ) ; return ; case \" WBWWBWBWBWWBWBWWBWBW \" : case \" BWWBWBWBWWBWBWWBWBWB \" : System . out . println ( \" Re \" ) ; return ; case \" WWBWBWBWWBWBWWBWBWBW \" : System . out . println ( \" Mi \" ) ; return ; case \" WBWBWBWWBWBWWBWBWBWW \" : case \" BWBWBWWBWBWWBWBWBWWB \" : System . out . println ( \" Fa \" ) ; return ; case \" WBWBWWBWBWWBWBWBWWBW \" : case \" BWBWWBWBWWBWBWBWWBWB \" : System . out . println ( \" So \" ) ; return ; case \" WBWWBWBWWBWBWBWWBWBW \" : case \" BWWBWBWWBWBWBWWBWBWW \" : System . out . println ( \" La \" ) ; return ; case \" WWBWBWWBWBWBWWBWBWWB \" : System . out . println ( \" Si \" ) ; } } }",
"import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; @ SuppressWarnings ( \" unchecked \" ) public class Main { static final String [ ] scales = { \" Do \" , \" Re \" , \" Mi \" , \" Fa \" , \" So \" , \" La \" , \" Si \" } ; static final char [ ] keys = { ' W ' , ' B ' , ' W ' , ' B ' , ' W ' , ' W ' , ' B ' , ' W ' , ' B ' , ' W ' , ' B ' , ' W ' } ; public static void main ( String [ ] args ) throws IOException { final String S ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { S = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; for ( int i = 0 ; i < scales . length ; i ++ ) { int idx = 0 ; int cnt = 0 ; for ( char c : keys ) { if ( c == S . charAt ( 0 ) ) cnt ++ ; if ( i < cnt ) break ; idx ++ ; } boolean flg = true ; for ( int j = 0 ; j < S . length ( ) ; j ++ ) { char c = S . charAt ( j ) ; if ( keys . length <= idx ) idx -= keys . length ; if ( c != keys [ idx ] ) { flg = false ; break ; } idx ++ ; } if ( flg ) { out . println ( scales [ i ] ) ; break ; } } out . flush ( ) ; } }"
] | [
"s = list ( input ( ) ) NEW_LINE a = 0 NEW_LINE b = 0 NEW_LINE n = len ( s ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if s [ i ] == s [ i - 1 ] : NEW_LINE INDENT a = i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( a + 1 , n ) : NEW_LINE INDENT if s [ i ] == s [ i - 1 ] : NEW_LINE INDENT b = i NEW_LINE break NEW_LINE DEDENT DEDENT ans_a = [ ' ' , ' Mi ' , ' ' , ' Re ' , ' ' , ' Do ' ] NEW_LINE ans_b = [ ' ' , ' Si ' , ' ' , ' La ' , ' ' , ' So ' , ' ' , ' Fa ' ] NEW_LINE if b - a == 7 : NEW_LINE INDENT print ( ans_a [ a ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ans_b [ a ] ) NEW_LINE DEDENT",
"s = input ( ) NEW_LINE moji = [ \" Mi \" , \" Fa \" , \" \" , \" So \" , \" \" , \" La \" , \" \" , \" Si \" , \" Do \" , \" \" , \" Re \" , \" \" , \" Mi \" , \" Fa \" , \" \" , \" So \" , \" \" , \" La \" , \" \" , \" Si \" , \" Do \" , \" \" , \" Re \" , \" \" , \" Mi \" ] [ : : - 1 ] NEW_LINE moji2 = [ \" Mi \" , \" Fa \" , \" \" , \" So \" , \" \" , \" La \" , \" \" , \" Si \" , \" Do \" , \" \" , \" Re \" , \" \" , \" Mi \" , \" Fa \" , \" \" , \" So \" , \" \" , \" La \" , \" \" , \" Si \" ] [ : : - 1 ] NEW_LINE for i in range ( 11 ) : NEW_LINE INDENT if s [ i ] == \" W \" and s [ i + 1 ] == \" W \" and s [ i + 7 ] == \" W \" and s [ i + 8 ] == \" W \" : NEW_LINE INDENT print ( moji [ i ] ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT for i in range ( 13 ) : NEW_LINE INDENT if s [ i ] == \" W \" and s [ i + 1 ] == \" W \" and s [ i + 5 ] == \" W \" and s [ i + 6 ] == \" W \" : NEW_LINE INDENT print ( moji2 [ i ] ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT",
"def pianist_takahashi ( S : str ) -> int : NEW_LINE INDENT scales = [ ' Do ' , ' Do # ' , ' Re ' , ' Re # ' , ' Mi ' , ' Fa ' , ' Fa # ' , ' So ' , ' So # ' , ' La ' , ' La # ' , ' Si ' ] NEW_LINE keyboard = ' WBWBWWBWBWBW ' NEW_LINE for i , scale in enumerate ( scales ) : NEW_LINE INDENT if ( S ) . startswith ( keyboard [ i : ] + keyboard [ : i ] ) : NEW_LINE INDENT return scale NEW_LINE DEDENT DEDENT return ' Unknown ' NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT S = input ( ) NEW_LINE ans = pianist_takahashi ( S ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"def solve ( s ) : NEW_LINE INDENT pattern = ( \" WBWBWWBWBWBW \" * 10 ) NEW_LINE oto = [ \" Do \" , \" Do \" , \" Re \" , \" Re \" , \" Mi \" , \" Fa \" , \" Fa \" , \" So \" , \" So \" , \" La \" , \" La \" , ] i = pattern . find ( s ) NEW_LINE return oto [ i ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT print ( solve ( input ( ) ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"S = input ( ) NEW_LINE dic_scale = { \" WBWBWWBWBWBWWBWBWWBW \" : \" Do \" , \" WBWWBWBWBWWBWBWWBWBW \" : \" Re \" , \" WWBWBWBWWBWBWWBWBWBW \" : \" Mi \" , \" WBWBWBWWBWBWWBWBWBWW \" : \" Fa \" , \" WBWBWWBWBWWBWBWBWWBW \" : \" So \" , \" WBWWBWBWWBWBWBWWBWBW \" : \" La \" , \" WWBWBWWBWBWBWWBWBWWB \" : \" Si \" } NEW_LINE ans = dic_scale [ S ] NEW_LINE print ( ans ) NEW_LINE"
] |
atcoder_agc024_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] P = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = sc . nextInt ( ) ; } int [ ] Q = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { Q [ P [ i ] - 1 ] = i ; } int cnt = 1 ; int ret = 1 ; int prev = Q [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( Q [ i ] > prev ) { cnt ++ ; } else { ret = Math . max ( ret , cnt ) ; cnt = 1 ; } prev = Q [ i ] ; } ret = Math . max ( ret , cnt ) ; System . out . println ( N - ret ) ; } }",
"import java . io . BufferedReader ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . HashMap ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Throwable { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < Integer , Integer > dp = new HashMap ( ) ; int res = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int x = sc . nextInt ( ) ; dp . put ( x , dp . getOrDefault ( x - 1 , 0 ) + 1 ) ; res = Math . max ( res , dp . get ( x ) ) ; } System . out . println ( n - res ) ; } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner ( InputStream s ) { br = new BufferedReader ( new InputStreamReader ( s ) ) ; } public Scanner ( String s ) throws FileNotFoundException { br = new BufferedReader ( new FileReader ( new File ( s ) ) ) ; } public String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public String nextLine ( ) throws IOException { return br . readLine ( ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public boolean ready ( ) throws IOException { return br . ready ( ) ; } } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .",
"import java . util . * ; import java . awt . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] p_index = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p_index [ sc . nextInt ( ) - 1 ] = i ; } int ans = 0 ; int count = 0 ; int prev_index = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p_index [ i ] > prev_index ) { count ++ ; } else { ans = Math . max ( ans , count ) ; count = 1 ; } prev_index = p_index [ i ] ; } ans = Math . max ( ans , count ) ; System . out . println ( n - ans ) ; } }",
"import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int p [ ] = new int [ n ] ; int q [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; q [ p [ i ] - 1 ] = i + 1 ; } int max = 0 ; int cnt = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { cnt ++ ; if ( q [ i ] > q [ i + 1 ] ) { max = Math . max ( max , cnt ) ; cnt = 0 ; } } max = Math . max ( max , cnt + 1 ) ; System . out . println ( n - max ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }",
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] A = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) A [ i ] = sc . nextInt ( ) ; int [ ] rec = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) rec [ A [ i ] ] = i ; int [ ] dp = new int [ n + 1 ] ; Arrays . fill ( dp , 1 ) ; boolean [ ] visited = new boolean [ n + 1 ] ; for ( int i = 1 ; i <= n - 1 ; i ++ ) { if ( visited [ i ] ) continue ; visited [ i ] = true ; int cur = i ; int len = 1 ; while ( cur <= n - 1 && rec [ cur + 1 ] > rec [ cur ] ) { cur ++ ; len ++ ; visited [ cur ] = true ; } dp [ i ] = len ; } int res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res = Math . max ( dp [ i ] , res ) ; System . out . println ( n - res ) ; } }"
] | [
"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 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 = II ( ) NEW_LINE P = [ II ( ) for _ in range ( n ) ] NEW_LINE dp = [ 0 ] * ( n + 1 ) NEW_LINE for p in P : NEW_LINE INDENT dp [ p ] += dp [ p - 1 ] + 1 NEW_LINE DEDENT return n - max ( dp ) NEW_LINE DEDENT print ( main ( ) ) NEW_LINE",
"from functools import reduce NEW_LINE N = int ( input ( ) ) NEW_LINE P = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE INF = 10 ** 15 NEW_LINE Q = { p : i for i , p in enumerate ( P , 1 ) } NEW_LINE ans = reduce ( lambda acc , j : ( min ( acc [ 0 ] , acc [ 1 ] + N - j + 1 ) , acc [ 1 ] if j > N or Q [ j - 1 ] < Q [ j ] else j - 1 ) , range ( 2 , N + 2 ) , ( INF , 0 ) ) [ 0 ] if N >= 2 else 0 NEW_LINE print ( ans ) NEW_LINE",
"import numpy as np NEW_LINE import os NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE test_data1 = ''' \\ STRNEWLINE 8 STRNEWLINE 6 STRNEWLINE 3 STRNEWLINE 1 STRNEWLINE 2 STRNEWLINE 7 STRNEWLINE 4 STRNEWLINE 8 STRNEWLINE 5 STRNEWLINE ''' NEW_LINE test_data2 = ''' \\ STRNEWLINE 6 STRNEWLINE 3 STRNEWLINE 2 STRNEWLINE 5 STRNEWLINE 1 STRNEWLINE 4 STRNEWLINE 6 STRNEWLINE ''' NEW_LINE test_data3 = ''' \\ STRNEWLINE 4 STRNEWLINE 1 STRNEWLINE 3 STRNEWLINE 2 STRNEWLINE 4 STRNEWLINE ''' NEW_LINE td_num = 3 NEW_LINE def GetTestData ( index ) : NEW_LINE INDENT if index == 1 : NEW_LINE INDENT return test_data1 NEW_LINE DEDENT if index == 2 : NEW_LINE INDENT return test_data2 NEW_LINE DEDENT if index == 3 : NEW_LINE INDENT return test_data3 NEW_LINE DEDENT DEDENT if False : NEW_LINE INDENT with open ( \" . . / test . txt \" , mode = ' w ' ) as f : NEW_LINE INDENT f . write ( GetTestData ( td_num ) ) NEW_LINE DEDENT with open ( \" . . / test . txt \" ) as f : NEW_LINE INDENT n = int ( f . readline ( ) ) NEW_LINE p = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT p [ i ] = int ( f . readline ( ) ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE p = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT p [ i ] = int ( input ( ) ) NEW_LINE DEDENT DEDENT a = [ 0 ] * n NEW_LINE cnt = 1 NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ p [ i ] - 1 ] = i NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT pre = a [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT if a [ i ] > pre : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max ( ans , cnt ) NEW_LINE cnt = 1 NEW_LINE DEDENT DEDENT ans = max ( ans , cnt ) NEW_LINE pre = a [ i ] NEW_LINE DEDENT print ( n - ans ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE P = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE T = [ 0 ] * ( N + 1 ) NEW_LINE for i in P : NEW_LINE INDENT if T [ i - 1 ] == 0 : NEW_LINE INDENT T [ i ] = - 1 NEW_LINE DEDENT elif T [ i - 1 ] < 0 : NEW_LINE INDENT T [ i - 1 ] -= 1 NEW_LINE T [ i ] = i - 1 NEW_LINE DEDENT else : NEW_LINE INDENT T [ T [ i - 1 ] ] -= 1 NEW_LINE T [ i ] = T [ i - 1 ] NEW_LINE DEDENT DEDENT print ( N + min ( T ) ) NEW_LINE",
"import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE A = [ int ( input ( ) ) - 1 for i in range ( N ) ] NEW_LINE Q = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT Q [ A [ i ] ] = i NEW_LINE DEDENT num = 0 NEW_LINE s = 1 NEW_LINE t = Q [ 0 ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT if t > Q [ i ] : NEW_LINE INDENT num = max ( s , num ) NEW_LINE s = 0 NEW_LINE DEDENT s += 1 NEW_LINE t = Q [ i ] NEW_LINE DEDENT num = max ( s , num ) NEW_LINE print ( N - num ) NEW_LINE"
] |
atcoder_arc079_A | [
"import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int [ ] a = new int [ 200001 ] ; int [ ] b = new int [ 200001 ] ; HashSet < Integer > [ ] via = new HashSet [ 200001 ] ; if ( n == 200001 || m == 200001 ) { while ( true ) { } } for ( int i = 1 ; i <= 200000 ; i ++ ) { via [ i ] = new HashSet < > ( ) ; } for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = sc . nextInt ( ) ; b [ i ] = sc . nextInt ( ) ; via [ a [ i ] ] . add ( b [ i ] ) ; via [ b [ i ] ] . add ( a [ i ] ) ; } for ( Integer k : via [ 1 ] ) { for ( Integer l : via [ k ] ) { if ( l == n ) { out . println ( \" POSSIBLE \" ) ; exit ( 0 ) ; } } } out . println ( \" IMPOSSIBLE \" ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .",
"import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . ArrayList ; import java . util . Stack ; public class Main { public static void main ( String [ ] args ) { Scanner stdin = new Scanner ( System . in ) ; int N , M ; int a , b ; List < Integer > alist = new ArrayList < Integer > ( ) ; List < Integer > blist = new ArrayList < Integer > ( ) ; N = stdin . nextInt ( ) ; M = stdin . nextInt ( ) ; for ( int i = 1 ; i <= M ; i ++ ) { a = stdin . nextInt ( ) ; b = stdin . nextInt ( ) ; if ( a == 1 ) alist . add ( b ) ; if ( b == N ) blist . add ( a ) ; } Collections . sort ( alist ) ; Collections . sort ( blist ) ; Stack < Integer > astack = new Stack < Integer > ( ) ; Stack < Integer > bstack = new Stack < Integer > ( ) ; for ( int i = 0 ; i < alist . size ( ) ; i ++ ) { astack . push ( alist . get ( i ) ) ; } for ( int i = 0 ; i < blist . size ( ) ; i ++ ) { bstack . push ( blist . get ( i ) ) ; } if ( astack . empty ( ) || bstack . empty ( ) ) { System . out . print ( \" IMPOSSIBLE \" ) ; System . exit ( 0 ) ; } a = astack . pop ( ) ; b = bstack . pop ( ) ; do { if ( a < b ) { if ( bstack . empty ( ) ) break ; b = bstack . pop ( ) ; } if ( a > b ) { if ( astack . empty ( ) ) break ; a = astack . pop ( ) ; } if ( a == b ) { System . out . print ( \" POSSIBLE \" ) ; System . exit ( 0 ) ; } } while ( true ) ; System . out . print ( \" IMPOSSIBLE \" ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashSet ; import java . util . Set ; import java . util . StringTokenizer ; public class Main { int n , m ; Set < Integer > oneLines ; Set < Integer > nLines ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; oneLines = new HashSet < > ( ) ; nLines = new HashSet < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a == 1 ) { oneLines . add ( b ) ; } if ( b == n ) { nLines . add ( a ) ; } } solve ( ) ; } void solve ( ) { for ( int i : oneLines ) { if ( nLines . contains ( i ) ) { System . out . println ( \" POSSIBLE \" ) ; return ; } } System . out . println ( \" IMPOSSIBLE \" ) ; } 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 java . util . * ; public class Main { public static void main ( String [ ] args ) throws InterruptedException { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; Set < Integer > from1 = new TreeSet < Integer > ( ) ; Set < Integer > toN = new TreeSet < Integer > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int s = in . nextInt ( ) ; int g = in . nextInt ( ) ; if ( s == 1 && ! from1 . contains ( g ) ) { from1 . add ( g ) ; } else if ( g == N && ! toN . contains ( s ) ) { toN . add ( s ) ; } } String answer = \" IMPOSSIBLE \" ; for ( int island : from1 ) { if ( toN . contains ( island ) ) { answer = \" POSSIBLE \" ; break ; } } System . out . println ( answer ) ; } }",
"import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; Map < Integer , Set < Integer > > shipMap = new HashMap < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; shipMap . computeIfAbsent ( a , e -> new HashSet < Integer > ( ) ) . add ( b ) ; } Set < Integer > toSet = shipMap . getOrDefault ( 1 , Collections . emptySet ( ) ) ; for ( Integer i : toSet ) { Set < Integer > toSet2 = shipMap . getOrDefault ( i , Collections . emptySet ( ) ) ; if ( toSet2 . contains ( n ) ) { System . out . println ( \" POSSIBLE \" ) ; return ; } } System . out . println ( \" IMPOSSIBLE \" ) ; } }"
] | [
"a , b = map ( int , input ( ) . split ( \" β \" ) ) NEW_LINE ar = [ [ ] for i in range ( a + 1 ) ] NEW_LINE for i in range ( b ) : NEW_LINE INDENT l = list ( map ( int , input ( ) . split ( \" β \" ) ) ) NEW_LINE ar [ l [ 0 ] ] . append ( l [ 1 ] ) NEW_LINE ar [ l [ 1 ] ] . append ( l [ 0 ] ) NEW_LINE DEDENT for r in ar [ 1 ] : NEW_LINE INDENT if a in ar [ r ] : NEW_LINE INDENT print ( \" POSSIBLE \" ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( \" IMPOSSIBLE \" ) NEW_LINE",
"def main ( ) : NEW_LINE INDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE is_included_1 = set ( ) NEW_LINE is_included_n = set ( ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT ai , bi = map ( int , input ( ) . split ( ) ) NEW_LINE if ai == 1 : NEW_LINE INDENT is_included_1 . add ( bi ) NEW_LINE DEDENT elif bi == 1 : NEW_LINE INDENT is_included_1 . add ( ai ) NEW_LINE DEDENT if ai == n : NEW_LINE INDENT is_included_n . add ( bi ) NEW_LINE DEDENT elif bi == n : NEW_LINE INDENT is_included_n . add ( ai ) NEW_LINE DEDENT DEDENT if len ( is_included_1 & is_included_n ) > 0 : NEW_LINE INDENT print ( ' POSSIBLE ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' IMPOSSIBLE ' ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"class UnionFind : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . par = [ i for i in range ( n + 1 ) ] NEW_LINE self . rank = [ 0 ] * ( n + 1 ) NEW_LINE DEDENT def find ( self , x ) : NEW_LINE INDENT if self . par [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT self . par [ x ] = self . find ( self . par [ x ] ) NEW_LINE return self . par [ x ] NEW_LINE DEDENT DEDENT def union ( self , x , y ) : NEW_LINE INDENT x = self . find ( x ) NEW_LINE y = self . find ( y ) NEW_LINE if self . rank [ x ] < self . rank [ y ] : NEW_LINE INDENT self . par [ x ] = y NEW_LINE DEDENT else : NEW_LINE INDENT self . par [ y ] = x NEW_LINE if self . rank [ x ] == self . rank [ y ] : NEW_LINE INDENT self . rank [ x ] += 1 NEW_LINE DEDENT DEDENT DEDENT def same_check ( self , x , y ) : NEW_LINE INDENT return self . find ( x ) == self . find ( y ) NEW_LINE DEDENT DEDENT n , m = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE uf = UnionFind ( n - 1 ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE if a == 1 or b == n : uf . union ( a - 1 , b - 1 ) NEW_LINE DEDENT if uf . same_check ( 0 , n - 1 ) : print ( ' POSSIBLE ' ) NEW_LINE else : print ( ' IMPOSSIBLE ' ) NEW_LINE",
"import heapq NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE cand_1 = [ ] NEW_LINE cand_2 = [ ] NEW_LINE for _ in range ( M ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT cand_1 . append ( b ) NEW_LINE DEDENT elif b == N : NEW_LINE INDENT cand_2 . append ( a ) NEW_LINE DEDENT DEDENT ans = \" IMPOSSIBLE \" NEW_LINE heapq . heapify ( cand_1 ) NEW_LINE heapq . heapify ( cand_2 ) NEW_LINE while len ( cand_1 ) != 0 and len ( cand_2 ) != 0 : NEW_LINE INDENT if cand_1 [ 0 ] < cand_2 [ 0 ] : NEW_LINE INDENT heapq . heappop ( cand_1 ) NEW_LINE DEDENT elif cand_1 [ 0 ] > cand_2 [ 0 ] : NEW_LINE INDENT heapq . heappop ( cand_2 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = \" POSSIBLE \" NEW_LINE break NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"from collections import deque NEW_LINE def dfs ( path ) : NEW_LINE INDENT global visited , A NEW_LINE q = deque ( [ ] ) NEW_LINE q . append ( path ) NEW_LINE for d in A [ 1 ] : NEW_LINE INDENT q . append ( d ) NEW_LINE DEDENT while q : NEW_LINE INDENT p = q . pop ( ) NEW_LINE for d in A [ p ] : NEW_LINE INDENT if visited [ d ] == True : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT visited [ d ] = True NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE A = [ [ ] for _ in range ( N + 1 ) ] NEW_LINE for _ in range ( M ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE A [ a ] . append ( b ) NEW_LINE A [ b ] . append ( a ) NEW_LINE DEDENT visited = [ False ] * ( N + 1 ) NEW_LINE dfs ( 1 ) NEW_LINE if visited [ N ] : NEW_LINE INDENT print ( \" POSSIBLE \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" IMPOSSIBLE \" ) NEW_LINE DEDENT DEDENT"
] |
atcoder_abc092_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int A = scn . nextInt ( ) ; int B = scn . nextInt ( ) ; int C = scn . nextInt ( ) ; int D = scn . nextInt ( ) ; System . out . println ( Math . min ( A , B ) + Math . min ( C , D ) ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { Scanner scanner = null ; int numA = 0 ; int numB = 0 ; int numC = 0 ; int numD = 0 ; try { scanner = new Scanner ( System . in ) ; numA = scanner . nextInt ( ) ; numB = scanner . nextInt ( ) ; numC = scanner . nextInt ( ) ; numD = scanner . nextInt ( ) ; int wkBus = numA < numB ? numA : numB ; int wkTrain = numC < numD ? numC : numD ; System . out . println ( wkBus + wkTrain ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveB ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveC ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveD ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int a , b , c , d ; try { a = Integer . parseInt ( bf . readLine ( ) ) ; b = Integer . parseInt ( bf . readLine ( ) ) ; c = Integer . parseInt ( bf . readLine ( ) ) ; d = Integer . parseInt ( bf . readLine ( ) ) ; System . out . println ( Math . min ( a , b ) + Math . min ( c , d ) ) ; } catch ( Exception e ) { } } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { RapidScanner sc = new RapidScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; System . out . println ( Math . min ( a , b ) + Math . min ( c , d ) ) ; } } class RapidScanner { BufferedReader reader ; int index ; String [ ] buffer ; public RapidScanner ( ) { reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { buffer = reader . readLine ( ) . split ( \" β \" ) ; } catch ( Exception e ) { } index = 0 ; } public int nextInt ( ) { if ( index == buffer . length ) { try { buffer = reader . readLine ( ) . split ( \" β \" ) ; } catch ( Exception e ) { } index = 0 ; } return Integer . parseInt ( buffer [ index ++ ] ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; System . out . println ( Math . min ( A , B ) + Math . min ( C , D ) ) ; } }"
] | [
"A = int ( input ( ) ) NEW_LINE B = int ( input ( ) ) NEW_LINE C = int ( input ( ) ) NEW_LINE D = int ( input ( ) ) NEW_LINE print ( min ( A , B ) + min ( C , D ) ) NEW_LINE",
"a = int ( input ( ) ) NEW_LINE b = int ( input ( ) ) NEW_LINE c = int ( input ( ) ) NEW_LINE d = int ( input ( ) ) NEW_LINE if a <= b and c <= d : NEW_LINE INDENT print ( a + c ) NEW_LINE DEDENT elif a <= b and c >= d : NEW_LINE INDENT print ( a + d ) NEW_LINE DEDENT elif a >= b and c <= d : NEW_LINE INDENT print ( b + c ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b + d ) NEW_LINE DEDENT",
"A = list ( map ( int , open ( 0 ) . read ( ) . split ( ) ) ) NEW_LINE print ( min ( A [ 0 ] , A [ 1 ] ) + min ( A [ 2 ] , A [ 3 ] ) ) NEW_LINE",
"print ( min ( int ( input ( ) ) , int ( input ( ) ) ) + min ( int ( input ( ) ) , int ( input ( ) ) ) ) NEW_LINE",
"A , B , C , D = map ( int , [ input ( ) for _ in range ( 4 ) ] ) NEW_LINE print ( min ( A , B ) + min ( C , D ) ) NEW_LINE"
] |
atcoder_abc109_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a , b , c ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; if ( a * b % 2 == 0 ) System . out . println ( \" No \" ) ; else System . out . println ( \" Yes \" ) ; } }",
"import java . io . * ; import java . util . Scanner ; public class Main { public static boolean Odd ( int a , int b ) { for ( int i = 1 ; i <= 3 ; i ++ ) { if ( ( a * b * i ) % 2 != 0 ) return true ; } return false ; } public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( Odd ( a , b ) == true ) System . out . println ( \" Yes \" ) ; else System . out . println ( \" No \" ) ; } }",
"import java . util . Scanner ; public class Main { private static final String YES = \" Yes \" ; private static final String NO = \" No \" ; public static String process ( TestCase testCase ) { final int A = testCase . A ; final int B = testCase . B ; return areBothOdd ( A , B ) ? YES : NO ; } private static boolean areBothOdd ( int A , int B ) { return isOdd ( A ) && isOdd ( B ) ; } private static boolean isOdd ( int n ) { return n % 2 != 0 ; } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; return new TestCase ( A , B ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final int A ; final int B ; public TestCase ( int A , int B ) { this . A = A ; this . B = B ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] abc = br . readLine ( ) . split ( \" β \" ) ; int a = Integer . parseInt ( abc [ 0 ] ) ; int b = Integer . parseInt ( abc [ 1 ] ) ; boolean flag = false ; for ( int c = 1 ; c <= 3 ; c ++ ) { if ( ( a * b * c ) % 2 == 1 ) { flag = true ; } } if ( flag ) { System . out . println ( \" Yes \" ) ; } else { System . out . println ( \" No \" ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { Scanner scanner = null ; int numA = 0 ; int numB = 0 ; try { scanner = new Scanner ( System . in ) ; numA = scanner . nextInt ( ) ; numB = scanner . nextInt ( ) ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( numA * numB * i % 2 != 0 ) { System . out . println ( \" Yes \" ) ; return ; } } System . out . println ( \" No \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveB ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveC ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveD ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( \" \" ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } }"
] | [
"A , B = map ( int , input ( ) . split ( ) ) NEW_LINE if A % 2 == 1 and B % 2 == 1 : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT",
"print ( \" No \" if \"2\" in input ( ) . split ( ) else \" Yes \" ) NEW_LINE",
"def YesNo ( f ) : NEW_LINE INDENT return [ \" Yes \" , \" No \" ] [ not ( f ) ] NEW_LINE DEDENT A , B = map ( int , input ( ) . split ( ) ) NEW_LINE print ( YesNo ( A * B % 2 != 0 ) ) NEW_LINE",
"def main ( ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if ( a * b ) % 2 != 0 : NEW_LINE INDENT print ( \" Yes \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" No \" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"A , B = map ( int , input ( ) . split ( ) ) NEW_LINE res = \" No \" NEW_LINE for i in range ( 1 , 4 ) : NEW_LINE INDENT if ( A * B * i ) % 2 == 1 : NEW_LINE INDENT res = \" Yes \" NEW_LINE break NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE"
] |
atcoder_arc012_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double va = sc . nextDouble ( ) ; double vb = sc . nextDouble ( ) ; double L = sc . nextDouble ( ) ; double ans = L ; for ( int i = 0 ; i < N ; i ++ ) { ans = ( vb * ans ) / va ; } System . out . println ( ans ) ; } }",
"import java . util . Scanner ; import java . util . function . LongSupplier ; import java . util . stream . IntStream ; public class Main { static final Scanner s = new Scanner ( System . in ) ; static final long [ ] fal_rnd ( long [ ] ar , LongSupplier sp ) { int l = - 1 , r = ar . length ; while ( l + 1 != r ) ar [ Math . random ( ) < 0.5 ? ++ l : -- r ] = sp . getAsLong ( ) ; return ar ; } static final IntStream REPS ( int v ) { return IntStream . range ( 0 , v ) ; } ; public static void main ( String [ ] __ ) { int n = s . nextInt ( ) , chokudai = s . nextInt ( ) , kame = s . nextInt ( ) ; double dist = s . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { dist = dist / chokudai * kame ; } System . out . printf ( \" % .20f \" , dist ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . math . BigDecimal ; import java . util . StringTokenizer ; public class Main { static int N , VA , VB , L ; public static void main ( String [ ] args ) { FastScanner fc = new FastScanner ( System . in ) ; N = fc . nextInt ( ) ; VA = fc . nextInt ( ) ; VB = fc . nextInt ( ) ; L = fc . nextInt ( ) ; System . out . println ( BigDecimal . valueOf ( solve ( ) ) . toPlainString ( ) ) ; } static double solve ( ) { double len = L ; for ( int i = 0 ; i < N ; i ++ ) { double b = len / VA ; len = b * VB ; } return len ; } @ SuppressWarnings ( \" unused \" ) static class FastScanner { private BufferedReader reader ; private StringTokenizer tokenizer ; FastScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; tokenizer = null ; } String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } String nextLine ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { return reader . readLine ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( \" \\n \" ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } int [ ] nextIntArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } long [ ] nextLongArray ( int n ) { long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextLong ( ) ; return a ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double N = sc . nextDouble ( ) ; double va = sc . nextDouble ( ) ; double vb = sc . nextDouble ( ) ; double L = sc . nextDouble ( ) ; double y = L ; for ( int i = 0 ; i < N ; i ++ ) { y = y / va ; y = vb * y ; } System . out . println ( ( double ) y ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double va = sc . nextInt ( ) ; double vb = sc . nextInt ( ) ; double len = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { double t = len / va ; len = vb * t ; } System . out . println ( java . math . BigDecimal . valueOf ( len ) . toPlainString ( ) ) ; } }"
] | [
"list = input ( ) . split ( \" β \" ) NEW_LINE a = int ( list [ 1 ] ) NEW_LINE b = int ( list [ 2 ] ) NEW_LINE c = int ( list [ 3 ] ) NEW_LINE for i in range ( int ( list [ 0 ] ) ) : NEW_LINE INDENT full = c / a NEW_LINE full2 = full * b NEW_LINE c = full2 NEW_LINE DEDENT print ( c ) NEW_LINE",
"n , va , vb , l = map ( int , input ( ) . split ( ) ) ; print ( l * ( vb / va ) ** n if l > 10 ** - 6 else 0 ) NEW_LINE",
"def b_achilles_and_turtle ( N , Va , Vb , L ) : NEW_LINE INDENT distance = L NEW_LINE for _ in range ( N ) : NEW_LINE INDENT takahashi_moving_dist = distance NEW_LINE turtle_moving_dist = distance * ( 1 + ( Vb / Va ) ) NEW_LINE distance = turtle_moving_dist - takahashi_moving_dist NEW_LINE if distance <= 10 ** ( - 10 ) : NEW_LINE INDENT distance = 0 NEW_LINE break NEW_LINE DEDENT DEDENT ans = round ( distance , 12 ) NEW_LINE return ans NEW_LINE DEDENT N , Va , Vb , L = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( b_achilles_and_turtle ( N , Va , Vb , L ) ) NEW_LINE",
"a = list ( map ( int , input ( ) . split ( \" β \" ) ) ) NEW_LINE b = 0 NEW_LINE c = a [ 3 ] NEW_LINE for i in range ( a [ 0 ] ) : NEW_LINE INDENT k = ( c - b ) / a [ 1 ] NEW_LINE b = c NEW_LINE c += k * a [ 2 ] NEW_LINE DEDENT print ( c - b ) NEW_LINE",
"N , a , b , L = map ( int , input ( ) . split ( ) ) NEW_LINE dl = ( b / a ) ** N * L NEW_LINE print ( ' { : . 6f } ' . format ( dl ) ) NEW_LINE"
] |
atcoder_abc010_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String name = sc . next ( ) ; System . out . println ( name + \" pp \" ) ; } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { out . println ( sc . next ( ) + \" pp \" ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . lang . String ; public class Main { public static void main ( String args [ ] ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; System . out . println ( str + \" pp \" ) ; } catch ( IOException e ) { System . out . println ( \" Exception β : \" + e ) ; } } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( System . in ) ; String s ; s = sc . next ( ) ; System . out . println ( s + \" pp \" ) ; } catch ( Exception e ) { System . out . println ( \" out \" ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( s + \" pp \" ) ; } }"
] | [
"s = input ( ) NEW_LINE print ( s + ' pp ' ) NEW_LINE",
"print ( ' { } pp ' . format ( input ( ) ) ) NEW_LINE",
"S = input ( ) NEW_LINE if S . islower ( ) : NEW_LINE INDENT if 1 <= len ( S ) <= 10 : NEW_LINE INDENT print ( S + \" pp \" ) NEW_LINE DEDENT DEDENT",
"s = input ( ) NEW_LINE s += \" pp \" NEW_LINE print ( s ) NEW_LINE",
"print ( str ( input ( ) ) + ' pp ' ) NEW_LINE"
] |
atcoder_arc060_B | [
"import java . util . * ; public class Main { private static long split ( long n , long k ) { long sum = 0 ; while ( n > 0 ) { sum += n % k ; n /= k ; } return sum ; } private static long solve ( long n , long s ) { long k ; for ( k = 2 ; k * k <= n || k < 100 ; k ++ ) { if ( split ( n , k ) == s ) { return k ; } } while ( k <= n ) { long a = n / k ; long b = n % k ; if ( ( a + b - s ) % a == 0 ) { long dk = ( a + b - s ) / a ; if ( dk >= 0 && b - dk * a >= 0 ) { return k + dk ; } } k = n / a + 1 ; } if ( n == s ) { return n + 1 ; } return - 1 ; } public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; long nl = s . nextLong ( ) ; long sl = s . nextLong ( ) ; System . out . println ( solve ( nl , sl ) ) ; } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . util . InputMismatchException ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskD solver = new TaskD ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskD { public void solve ( int testNumber , InputReader in , PrintWriter out ) { long n = in . nextLong ( ) ; long s = in . nextLong ( ) ; if ( n < s ) { out . println ( - 1 ) ; return ; } if ( n == s ) { out . println ( n + 1 ) ; return ; } long i = 2 ; while ( i * i <= n ) { long tmp = n ; long sum = 0 ; while ( tmp > 0 ) { sum += tmp % i ; tmp /= i ; } if ( sum == s ) { out . println ( i ) ; return ; } i ++ ; } while ( i * i >= n ) i -- ; while ( i > 0 ) { long b = ( n - s ) / i + 1 ; if ( n / b + n % b == s ) { out . println ( b ) ; return ; } i -- ; } out . println ( - 1 ) ; } } static class InputReader { BufferedReader in ; StringTokenizer tok ; public String nextString ( ) { while ( ! tok . hasMoreTokens ( ) ) { try { tok = new StringTokenizer ( in . readLine ( ) , \" β \" ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return tok . nextToken ( ) ; } public long nextLong ( ) { return Long . parseLong ( nextString ( ) ) ; } public InputReader ( InputStream inputStream ) { in = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; tok = new StringTokenizer ( \" \" ) ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; long n = Long . parseLong ( br . readLine ( ) ) ; long s = Long . parseLong ( br . readLine ( ) ) ; if ( n < s ) { System . out . println ( - 1 ) ; return ; } if ( n == s ) { System . out . println ( n + 1 ) ; return ; } long squareRootN = Double . valueOf ( Math . ceil ( Math . sqrt ( n ) ) ) . longValue ( ) ; for ( long base = 2 ; base <= squareRootN ; base ++ ) { long sum = sumDigitsInBase ( base , n ) ; if ( sum == s ) { System . out . println ( base ) ; return ; } } long nMinusS = n - s ; long minBase = - 1 ; for ( long p = 1 ; p <= squareRootN ; p ++ ) { if ( nMinusS % p != 0 ) { continue ; } long base = nMinusS / p + 1 ; if ( base > squareRootN ) { long sum = sumDigitsInBase ( base , n ) ; if ( sum == s ) { minBase = base ; } } } System . out . println ( minBase ) ; } private static long sumDigitsInBase ( long base , long number ) { if ( base > number ) { return number ; } long sum = sumDigitsInBase ( base , number / base ) ; return sum + ( number % base ) ; } }",
"import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long s = sc . nextLong ( ) ; System . out . println ( ans ( n , s ) ) ; } static long ans ( long n , long s ) { if ( n < s ) { return - 1 ; } else if ( n == s ) { return n + 1 ; } else { List < Long > divisor = new ArrayList < Long > ( ) ; for ( long i = 1 ; i <= Math . sqrt ( n - s ) ; i ++ ) { if ( digitSum ( n , i + 1 ) == s ) { return i + 1 ; } if ( ( n - s ) % i == 0 ) { divisor . add ( i ) ; } } Collections . reverse ( divisor ) ; for ( Long l : divisor ) { if ( digitSum ( n , ( n - s ) / l + 1 ) == s ) { return ( n - s ) / l + 1 ; } } return - 1 ; } } static long digitSum ( long n , long b ) { if ( n < b ) { return n ; } else { return ( n % b + digitSum ( n / b , b ) ) ; } } }",
"import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long s = sc . nextLong ( ) ; if ( n == s ) { System . out . println ( n + 1 ) ; return ; } if ( ( n + 1 ) / 2 < s ) { System . out . println ( - 1 ) ; return ; } for ( long b = 2 ; b * b <= n ; b ++ ) { if ( f ( n , b ) == s ) { System . out . println ( b ) ; return ; } } long min = Long . MAX_VALUE ; for ( long p = 1 ; p * p <= n ; p ++ ) { long b = ( n - s ) / p + 1 ; if ( f ( n , b ) == s ) { min = Math . min ( min , b ) ; } } System . out . println ( min ) ; } private long f ( long n , long b ) { if ( n < b ) { return n ; } else { return f ( n / b , b ) + n % b ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }"
] | [
"def digitsum ( n , b ) : NEW_LINE INDENT if n < b : NEW_LINE INDENT return n NEW_LINE DEDENT else : NEW_LINE INDENT return digitsum ( n // b , b ) + n % b NEW_LINE DEDENT DEDENT n = int ( input ( ) ) NEW_LINE s = int ( input ( ) ) NEW_LINE inf = float ( ' inf ' ) NEW_LINE ans = inf NEW_LINE for i in range ( 2 , int ( n ** ( 1 / 2 ) ) + 2 ) : NEW_LINE INDENT if digitsum ( n , i ) == s : NEW_LINE INDENT ans = i NEW_LINE break NEW_LINE DEDENT DEDENT if n == s : NEW_LINE INDENT ans = n + 1 NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 1 , int ( n ** ( 1 / 2 ) ) ) : NEW_LINE INDENT if i * i - i >= n - s : NEW_LINE INDENT break NEW_LINE DEDENT if ( n - s ) % i == 0 : NEW_LINE INDENT if s - i >= ( n - s ) // i + 1 or i > s : NEW_LINE INDENT continue NEW_LINE DEDENT ans = min ( ans , ( ( n - s ) // i ) + 1 ) NEW_LINE DEDENT DEDENT DEDENT if ans == inf : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( ans ) ) NEW_LINE DEDENT",
"import array NEW_LINE from bisect import * NEW_LINE from collections import * NEW_LINE import fractions NEW_LINE import heapq NEW_LINE from itertools import * NEW_LINE import math NEW_LINE import random NEW_LINE import re NEW_LINE import string NEW_LINE import sys NEW_LINE def get_sum ( base , n ) : NEW_LINE INDENT nums = [ ] NEW_LINE while n > 0 : NEW_LINE INDENT nums . append ( n % base ) NEW_LINE n //= base NEW_LINE DEDENT return sum ( nums ) NEW_LINE DEDENT def solve ( N , S ) : NEW_LINE INDENT if S == N : NEW_LINE INDENT return S + 1 NEW_LINE DEDENT for base in range ( 2 , int ( math . sqrt ( N ) ) + 2 ) : NEW_LINE INDENT if S == get_sum ( base , N ) : NEW_LINE INDENT return base NEW_LINE DEDENT DEDENT for p in range ( int ( math . sqrt ( N ) ) + 1 , 0 , - 1 ) : NEW_LINE INDENT q = S - p NEW_LINE if ( N - q ) % p == 0 : NEW_LINE INDENT base = ( N - q ) // p NEW_LINE if base <= 1 or q < 0 or q >= base : NEW_LINE INDENT continue NEW_LINE DEDENT return base NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE S = int ( input ( ) ) NEW_LINE print ( solve ( N , S ) ) NEW_LINE",
"import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE from math import floor , sqrt NEW_LINE def digit_sum ( num : int , base : int ) -> int : NEW_LINE INDENT if num < base : NEW_LINE INDENT return num NEW_LINE DEDENT else : NEW_LINE INDENT return digit_sum ( int ( num / base ) , base ) + ( num % base ) NEW_LINE DEDENT DEDENT n = ni ( ) NEW_LINE s = ni ( ) NEW_LINE root = floor ( sqrt ( n ) ) NEW_LINE ans = float ( \" inf \" ) NEW_LINE for p in range ( 2 , root + 1 ) : NEW_LINE INDENT ds = digit_sum ( n , p ) NEW_LINE if ds == s : NEW_LINE INDENT ans = min ( ans , p ) NEW_LINE DEDENT DEDENT for a in range ( 1 , root + 2 ) : NEW_LINE INDENT p = ( n - s + a ) / a NEW_LINE b = s - a NEW_LINE if p == int ( p ) and 0 < a < p and 0 <= b < p : NEW_LINE INDENT ans = min ( ans , int ( p ) ) NEW_LINE DEDENT DEDENT if n == s : NEW_LINE INDENT ans = min ( ans , n + 1 ) NEW_LINE DEDENT print ( - 1 ) if ans == float ( \" inf \" ) else print ( ans ) NEW_LINE",
"from math import floor NEW_LINE from math import sqrt NEW_LINE def f ( bb , nn ) : NEW_LINE INDENT if ( nn < bb ) : return nn NEW_LINE else : return f ( bb , floor ( nn / bb ) ) + ( nn % bb ) NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE s = int ( input ( ) ) NEW_LINE if n == s : NEW_LINE INDENT print ( n + 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT elif n < s : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT for i in range ( 2 , int ( sqrt ( n ) ) + 2 ) : NEW_LINE INDENT if s == f ( i , n ) : NEW_LINE INDENT print ( i ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT for i in reversed ( range ( 1 , int ( sqrt ( n ) ) + 2 ) ) : NEW_LINE INDENT if ( n - s ) % i == 0 : NEW_LINE INDENT tmpb = ( n - s ) // i + 1 NEW_LINE if tmpb >= sqrt ( n ) and f ( tmpb , n ) == s : NEW_LINE INDENT print ( tmpb ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( - 1 ) NEW_LINE",
"import itertools NEW_LINE import math NEW_LINE n , s = [ int ( input ( ) ) for _ in range ( 2 ) ] NEW_LINE def n_base_sum ( n , b ) : NEW_LINE INDENT if ( math . floor ( n / b ) ) : NEW_LINE INDENT return n_base_sum ( math . floor ( n / b ) , b ) + n % b NEW_LINE DEDENT else : NEW_LINE INDENT return n % b NEW_LINE DEDENT DEDENT def search_p ( n , s ) : NEW_LINE INDENT for p in range ( math . floor ( math . sqrt ( n ) ) + 1 , 0 , - 1 ) : NEW_LINE INDENT b = ( n - s ) // p + 1 NEW_LINE if b > 1 : NEW_LINE INDENT q = n % b NEW_LINE if p + q == s and q < b and n == p * b + q and p < b : NEW_LINE INDENT return b NEW_LINE DEDENT DEDENT DEDENT return - 1 NEW_LINE DEDENT ans = - 1 NEW_LINE flag = False NEW_LINE answers = [ ] NEW_LINE if s == n : NEW_LINE INDENT ans = n + 1 NEW_LINE flag = True NEW_LINE answers . append ( ans ) NEW_LINE DEDENT for b in range ( 2 , math . ceil ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if s == n_base_sum ( n , b ) : NEW_LINE INDENT ans = b NEW_LINE flag = True NEW_LINE answers . append ( ans ) NEW_LINE break NEW_LINE DEDENT DEDENT ans = search_p ( n , s ) NEW_LINE if ans != - 1 : NEW_LINE INDENT flag = True NEW_LINE answers . append ( ans ) NEW_LINE DEDENT if not flag : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( min ( answers ) ) ) NEW_LINE DEDENT"
] |
atcoder_abc013_D | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int [ ] id = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { id [ i ] = i ; } for ( int i = 0 ; i < M ; i ++ ) { int a = sc . nextInt ( ) ; int temp = id [ a ] ; id [ a ] = id [ a + 1 ] ; id [ a + 1 ] = temp ; } int [ ] goal = new int [ N + 1 ] ; for ( int i = 1 ; i < N + 1 ; i ++ ) { goal [ id [ i ] ] = i ; } int [ ] [ ] powGoal = new int [ N + 1 ] [ 31 ] ; for ( int i = 1 ; i < N + 1 ; i ++ ) { powGoal [ i ] [ 0 ] = goal [ i ] ; } for ( int j = 1 ; j < 31 ; j ++ ) { for ( int i = 1 ; i < N + 1 ; i ++ ) { powGoal [ i ] [ j ] = powGoal [ powGoal [ i ] [ j - 1 ] ] [ j - 1 ] ; } } for ( int i = 1 ; i < N + 1 ; i ++ ) { int g = i ; for ( int j = 0 ; j < 30 ; j ++ ) { if ( ( D & ( 1 << j ) ) != 0 ) { g = powGoal [ g ] [ j ] ; } } System . out . println ( g ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; final int M = sc . nextInt ( ) ; final int D = sc . nextInt ( ) ; final int [ ] a = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) a [ i ] = sc . nextInt ( ) - 1 ; sc . close ( ) ; int [ ] once = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) once [ i ] = i ; for ( int m = 0 ; m < M ; m ++ ) { int t = once [ a [ m ] ] ; once [ a [ m ] ] = once [ a [ m ] + 1 ] ; once [ a [ m ] + 1 ] = t ; } int [ ] intervel = new int [ N ] ; int [ ] ans = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { intervel [ once [ i ] ] = i ; ans [ i ] = i ; } for ( int i = D ; i > 0 ; i = i / 2 ) { if ( i % 2 == 1 ) for ( int j = 0 ; j < N ; j ++ ) ans [ j ] = intervel [ ans [ j ] ] ; int [ ] tmp = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) tmp [ j ] = intervel [ j ] ; for ( int j = 0 ; j < N ; j ++ ) intervel [ j ] = tmp [ tmp [ j ] ] ; } for ( int i = 0 ; i < N ; i ++ ) System . out . println ( ans [ i ] + 1 ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , M = sc . nextInt ( ) , D = sc . nextInt ( ) ; int A [ ] = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = sc . nextInt ( ) - 1 ; } int amida [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { amida [ i ] = i ; } for ( int i = 0 ; i < M ; i ++ ) { int tmp = amida [ A [ i ] ] ; amida [ A [ i ] ] = amida [ A [ i ] + 1 ] ; amida [ A [ i ] + 1 ] = tmp ; } int doubling [ ] [ ] = new int [ 31 ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { doubling [ 0 ] [ amida [ i ] ] = i ; } for ( int i = 0 ; i < 30 ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { doubling [ i + 1 ] [ j ] = doubling [ i ] [ doubling [ i ] [ j ] ] ; } } for ( int i = 0 ; i < N ; i ++ ) { int now = i , res = D ; for ( int j = 30 ; j >= 0 ; j -- ) { if ( ( res >> j & 1 ) == 1 ) { now = doubling [ j ] [ now ] ; res -= 1 << j ; } } System . out . println ( now + 1 ) ; } } }"
] | [
"N , M , D = map ( int , input ( ) . split ( ) ) NEW_LINE A = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE S = [ i for i in range ( N ) ] NEW_LINE Q = [ 0 ] * N NEW_LINE for a in A : NEW_LINE INDENT swap = S [ a ] NEW_LINE S [ a ] = S [ a - 1 ] NEW_LINE S [ a - 1 ] = swap NEW_LINE DEDENT for i , s in enumerate ( S ) : NEW_LINE INDENT Q [ s ] = i NEW_LINE DEDENT L = [ 0 ] * N NEW_LINE for q in range ( N ) : NEW_LINE INDENT if L [ q ] == 0 : NEW_LINE INDENT P = [ q ] NEW_LINE nq = q NEW_LINE while Q [ nq ] != q : NEW_LINE INDENT nq = Q [ nq ] NEW_LINE P . append ( nq ) NEW_LINE DEDENT k = D % len ( P ) NEW_LINE for i , p in enumerate ( P ) : NEW_LINE INDENT L [ p ] = P [ ( i + k ) % len ( P ) ] + 1 NEW_LINE DEDENT DEDENT DEDENT for l in L : NEW_LINE INDENT print ( l ) NEW_LINE DEDENT",
"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 , sys . stdin . readline ( ) . 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 ( ) ) 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 mul ( a , b ) : NEW_LINE INDENT c = [ 0 for i in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT c [ i ] = a [ b [ i ] ] NEW_LINE DEDENT return c NEW_LINE DEDENT def pow ( a , b ) : NEW_LINE INDENT if b == 1 : NEW_LINE INDENT return a NEW_LINE DEDENT if b % 2 : NEW_LINE INDENT return mul ( a , pow ( mul ( a , a ) , b // 2 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return pow ( mul ( a , a ) , b // 2 ) NEW_LINE DEDENT DEDENT n , m , d = LI ( ) NEW_LINE a = LI ( ) NEW_LINE f = [ i for i in range ( n + 1 ) ] NEW_LINE for i in range ( m ) [ : : - 1 ] : NEW_LINE INDENT v = f [ a [ i ] ] NEW_LINE f [ a [ i ] ] = f [ a [ i ] + 1 ] NEW_LINE f [ a [ i ] + 1 ] = v NEW_LINE DEDENT f = pow ( f , d ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( f [ i ] ) NEW_LINE NEW_LINE DEDENT",
"n , m , d = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE b = [ i for i in range ( n + 1 ) ] NEW_LINE for i in a : b [ i ] , b [ i + 1 ] = b [ i + 1 ] , b [ i ] NEW_LINE x , y , ans = [ 0 for i in range ( n + 1 ) ] , [ True for i in range ( n + 1 ) ] , [ 0 for i in range ( n + 1 ) ] NEW_LINE for i in range ( 1 , n + 1 ) : x [ b [ i ] ] = i NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if y [ i ] : NEW_LINE INDENT z , now = [ ] , i NEW_LINE while True : NEW_LINE INDENT if y [ now ] : NEW_LINE INDENT z . append ( now ) NEW_LINE y [ now ] , now = False , x [ now ] NEW_LINE DEDENT else : break NEW_LINE DEDENT num , lz = d % len ( z ) , len ( z ) NEW_LINE for i in range ( lz ) : ans [ z [ i ] ] = z [ ( i + num ) % lz ] NEW_LINE DEDENT DEDENT for i in ans [ 1 : ] : print ( i ) NEW_LINE",
"from collections import defaultdict , deque NEW_LINE import sys , heapq , bisect , math , itertools , string , queue , datetime NEW_LINE sys . setrecursionlimit ( 10 ** 8 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE eps = 10 ** - 7 NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def inpl_s ( ) : return list ( input ( ) . split ( ) ) NEW_LINE N , M , D = inpl ( ) NEW_LINE aa = inpl ( ) NEW_LINE L = int ( math . log2 ( D ) ) + 1 NEW_LINE T = [ [ i for i in range ( N ) ] for j in range ( L ) ] NEW_LINE for a in reversed ( aa ) : NEW_LINE INDENT T [ 0 ] [ a - 1 ] , T [ 0 ] [ a ] = T [ 0 ] [ a ] , T [ 0 ] [ a - 1 ] NEW_LINE DEDENT flags = [ ] NEW_LINE for k in range ( L ) : NEW_LINE INDENT flags . append ( D >> k & 1 ) NEW_LINE DEDENT for k in range ( 1 , L ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT T [ k ] [ i ] = T [ k - 1 ] [ T [ k - 1 ] [ i ] ] NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT ans = i NEW_LINE for k , flag in enumerate ( flags ) : NEW_LINE INDENT if flag : NEW_LINE INDENT ans = T [ k ] [ ans ] NEW_LINE DEDENT DEDENT print ( ans + 1 ) NEW_LINE DEDENT",
"N , M , D = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE A = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE Amida = [ [ ] for x in range ( N + 1 ) ] NEW_LINE for a in A : NEW_LINE INDENT Amida [ a ] . append ( ( a + 1 , len ( Amida [ a + 1 ] ) + 1 ) ) NEW_LINE Amida [ a + 1 ] . append ( ( a , len ( Amida [ a ] ) ) ) NEW_LINE DEDENT rec = [ 0 for x in range ( N ) ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT r = i NEW_LINE j = 0 NEW_LINE while j < len ( Amida [ r ] ) : NEW_LINE INDENT r , j = Amida [ r ] [ j ] [ 0 ] , Amida [ r ] [ j ] [ 1 ] NEW_LINE DEDENT rec [ i - 1 ] = r NEW_LINE DEDENT kaijou = [ ] NEW_LINE for i in reversed ( range ( 30 ) ) : NEW_LINE INDENT c = 2 ** i NEW_LINE if c > D : NEW_LINE INDENT continue NEW_LINE DEDENT kaijou . append ( i ) NEW_LINE if D == c : break NEW_LINE D -= c NEW_LINE DEDENT R = [ ] NEW_LINE R . append ( rec ) NEW_LINE for a in range ( kaijou [ 0 ] + 1 ) : NEW_LINE INDENT R . append ( [ R [ - 1 ] [ r - 1 ] for r in R [ - 1 ] ] ) NEW_LINE DEDENT ans = [ i for i in range ( 1 , N + 1 ) ] NEW_LINE for k in kaijou : NEW_LINE INDENT ans = [ R [ k ] [ i - 1 ] for i in ans ] NEW_LINE DEDENT print ( * ans , sep = ' \\n ' ) NEW_LINE"
] |
atcoder_abc122_C | [
"import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { solve ( ) ; } public static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; String s = sc . next ( ) ; int [ ] l = new int [ q ] ; int [ ] r = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { l [ i ] = sc . nextInt ( ) ; r [ i ] = sc . nextInt ( ) ; } int [ ] len = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' C ' && s . charAt ( i - 1 ) == ' A ' ) { len [ i ] = len [ i - 1 ] + 1 ; } else { len [ i ] = len [ i - 1 ] ; } } for ( int i = 0 ; i < q ; i ++ ) { System . out . println ( len [ r [ i ] - 1 ] - len [ l [ i ] - 1 ] ) ; } } }",
"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 ) ; CGeTAC solver = new CGeTAC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class CGeTAC { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int q = in . nextInt ( ) ; String s = in . next ( ) ; int p [ ] = new int [ n ] ; char a [ ] = s . toCharArray ( ) ; if ( a [ 0 ] == ' A ' && a [ 1 ] == ' C ' ) p [ 0 ] = 1 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i ] == ' A ' && a [ i + 1 ] == ' C ' ) { p [ i ] = p [ i - 1 ] + 1 ; } else { p [ i ] = p [ i - 1 ] ; } } p [ n - 1 ] = p [ n - 2 ] ; int ans = 0 ; for ( int i = 0 ; i < q ; i ++ ) { int l = in . nextInt ( ) ; int r = in . nextInt ( ) ; l -- ; r -- ; if ( l == 0 ) { ans = p [ r - 1 ] ; } else { ans = p [ r - 1 ] - p [ l - 1 ] ; } out . println ( ans ) ; } } } }",
"import java . io . * ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int Q = Integer . parseInt ( st . nextToken ( ) ) ; char [ ] arr = br . readLine ( ) . toCharArray ( ) ; int [ ] num = new int [ N ] ; num [ 0 ] = 0 ; for ( int i = 1 ; i < N ; ++ i ) { num [ i ] = num [ i - 1 ] + ( arr [ i - 1 ] == ' A ' && arr [ i ] == ' C ' ? 1 : 0 ) ; } for ( int i = 0 ; i < Q ; ++ i ) { st = new StringTokenizer ( br . readLine ( ) ) ; int start = Integer . parseInt ( st . nextToken ( ) ) ; int end = Integer . parseInt ( st . nextToken ( ) ) ; bw . write ( ( num [ end - 1 ] - num [ start - 1 ] ) + \" \\n \" ) ; } bw . close ( ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastReader scan = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = scan . nextInt ( ) , q = scan . nextInt ( ) ; int [ ] p = new int [ n + 1 ] ; char prev = ' z ' ; char [ ] a = scan . next ( ) . toCharArray ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( a [ i - 1 ] == ' C ' && prev == ' A ' ) p [ i ] ++ ; p [ i ] += p [ i - 1 ] ; prev = a [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) { int l = scan . nextInt ( ) - 1 , r = scan . nextInt ( ) ; int get = p [ r ] - p [ l ] ; if ( l > 0 && a [ l ] == ' C ' && a [ l - 1 ] == ' A ' ) get -- ; out . println ( get ) ; } out . close ( ) ; } 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 java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int N = Integer . parseInt ( sc . next ( ) ) ; int Q = Integer . parseInt ( sc . next ( ) ) ; String S = sc . next ( ) ; int [ ] [ ] lr = new int [ Q ] [ 2 ] ; for ( int i = 0 ; i < Q ; i ++ ) { lr [ i ] [ 0 ] = Integer . parseInt ( sc . next ( ) ) ; lr [ i ] [ 1 ] = Integer . parseInt ( sc . next ( ) ) ; } final String AC = \" AC \" ; int [ ] [ ] counter = new int [ S . length ( ) ] [ 2 ] ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) - 1 ; i ++ ) { counter [ i ] [ 1 ] = count ; if ( AC . equals ( S . substring ( i , i + 2 ) ) ) { count ++ ; } } counter [ S . length ( ) - 1 ] [ 1 ] = count ; for ( int i = 0 ; i < Q ; i ++ ) { System . out . println ( counter [ lr [ i ] [ 1 ] - 1 ] [ 1 ] - counter [ lr [ i ] [ 0 ] - 1 ] [ 1 ] ) ; } } } }"
] | [
"n , q = map ( int , input ( ) . split ( ) ) NEW_LINE s = input ( ) NEW_LINE t = [ 0 ] * ( n + 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT t [ i + 1 ] = t [ i ] + ( 1 if s [ i : i + 2 ] == \" AC \" else 0 ) NEW_LINE DEDENT for i in range ( q ) : NEW_LINE INDENT l , r = map ( int , input ( ) . split ( ) ) NEW_LINE print ( t [ r - 1 ] - t [ l - 1 ] ) NEW_LINE DEDENT",
"import sys NEW_LINE s2nn = lambda s : [ int ( c ) for c in s . split ( ' β ' ) ] NEW_LINE ss2nn = lambda ss : [ int ( s ) for s in list ( ss ) ] NEW_LINE ss2nnn = lambda ss : [ s2nn ( s ) for s in list ( ss ) ] NEW_LINE i2s = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE i2n = lambda : int ( i2s ( ) ) NEW_LINE i2nn = lambda : s2nn ( i2s ( ) ) NEW_LINE ii2ss = lambda n : [ sys . stdin . readline ( ) for _ in range ( n ) ] NEW_LINE def main ( N , Q , S , lrs ) : NEW_LINE INDENT S2 = [ 0 ] * ( N ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT if S [ i - 1 ] == ' A ' and S [ i ] == ' C ' : NEW_LINE INDENT S2 [ i ] = S2 [ i - 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT S2 [ i ] = S2 [ i - 1 ] NEW_LINE DEDENT DEDENT for l , r in lrs : NEW_LINE INDENT count = S2 [ r - 1 ] - S2 [ l - 1 ] NEW_LINE print ( count ) NEW_LINE DEDENT DEDENT N , Q = i2nn ( ) NEW_LINE S = i2s ( ) NEW_LINE lr = ss2nnn ( ii2ss ( Q ) ) NEW_LINE main ( N , Q , S , lr ) NEW_LINE",
"if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT length , question_count = map ( int , input ( ) . split ( ) ) NEW_LINE string = input ( ) NEW_LINE ac_sums = [ 0 ] NEW_LINE for i in range ( 1 , len ( string ) + 1 ) : NEW_LINE INDENT if i > 1 and string [ i - 2 ] == ' A ' and string [ i - 1 ] == ' C ' : NEW_LINE INDENT ac_sums . append ( ac_sums [ i - 1 ] + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ac_sums . append ( ac_sums [ i - 1 ] ) NEW_LINE DEDENT DEDENT for i in range ( question_count ) : NEW_LINE INDENT l , r = map ( int , input ( ) . split ( ) ) NEW_LINE ans = ac_sums [ r ] - ac_sums [ l - 1 ] NEW_LINE if l > 1 and string [ l - 1 ] == ' C ' and string [ l - 2 ] == ' A ' : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT DEDENT",
"N , Q = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE S = input ( ) NEW_LINE t = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if S [ i : i + 2 ] == ' AC ' : NEW_LINE INDENT t [ i + 1 ] = t [ i ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT t [ i + 1 ] = t [ i ] NEW_LINE DEDENT DEDENT for i in range ( Q ) : NEW_LINE INDENT l , r = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE print ( t [ r - 1 ] - t [ l - 1 ] ) NEW_LINE DEDENT",
"n , q = map ( int , input ( ) . split ( ) ) NEW_LINE s = input ( ) NEW_LINE lr = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( q ) ] NEW_LINE for i in range ( q ) : NEW_LINE INDENT for j in range ( 2 ) : NEW_LINE INDENT lr [ i ] [ j ] -= 1 NEW_LINE DEDENT DEDENT ac_cnt = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT ac_cnt [ i + 1 ] = ac_cnt [ i ] + ( 1 if s [ i : i + 2 ] == ' AC ' else 0 ) NEW_LINE DEDENT for i in range ( q ) : NEW_LINE INDENT print ( ac_cnt [ lr [ i ] [ 1 ] ] - ac_cnt [ lr [ i ] [ 0 ] ] ) NEW_LINE DEDENT"
] |
atcoder_arc003_A | [
"import java . util . * ; import java . awt . * ; 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 ( ) ; char [ ] r = sc . next ( ) . toCharArray ( ) ; double sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( r [ i ] != ' F ' ) sum += ( 69 - ( int ) r [ i ] ) ; } out . println ( sum / n ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; String t = in . next ( ) ; double total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { switch ( t . charAt ( i ) ) { case ' A ' : total += 4 ; break ; case ' B ' : total += 3 ; break ; case ' C ' : total += 2 ; break ; case ' D ' : total += 1 ; break ; case ' F ' : break ; } } if ( total / N == 0.0 ) { out . println ( 0 ) ; } else { out . println ( total / N ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . stream . IntStream ; 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 ) ; AGPA solver = new AGPA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AGPA { public void solve ( int testNumber , Scanner in , PrintWriter out ) { double n = in . nextInt ( ) ; out . println ( in . next ( ) . chars ( ) . map ( i -> Math . max ( 0 , ' E ' - i ) ) . sum ( ) / n ) ; } } }",
"import java . util . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { int total = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String C = sc . next ( ) ; for ( int i = 0 ; i < C . length ( ) ; i ++ ) { char ca = C . charAt ( i ) ; if ( ca == ' A ' ) { total += 4 ; } else if ( ca == ' B ' ) { total += 3 ; } else if ( ca == ' C ' ) { total += 2 ; } else if ( ca == ' D ' ) { total += 1 ; } } BigDecimal divided = new BigDecimal ( total ) ; BigDecimal divisor = new BigDecimal ( N ) ; BigDecimal ans = divided . divide ( divisor , 10 , RoundingMode . HALF_UP ) ; System . out . println ( ans ) ; sc . close ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; String rLine = sc . nextLine ( ) ; char [ ] r = rLine . toCharArray ( ) ; HashMap < Character , Integer > map = new HashMap < Character , Integer > ( ) ; map . put ( ' A ' , 4 ) ; map . put ( ' B ' , 3 ) ; map . put ( ' C ' , 2 ) ; map . put ( ' D ' , 1 ) ; map . put ( ' F ' , 0 ) ; double sum = 0 ; for ( char c : r ) { sum += map . get ( c ) ; } System . out . println ( sum / n ) ; } }"
] | [
"n = int ( input ( ) ) ; s = input ( ) ; print ( sum ( v * ( 4 - k ) for ( k , v ) in enumerate ( map ( s . count , \" ABCD \" ) ) ) / n ) NEW_LINE",
"SCORE = { ' A ' : 4 , ' B ' : 3 , ' C ' : 2 , ' D ' : 1 , ' F ' : 0 } NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE ranks = input ( ) . rstrip ( ) NEW_LINE gpa = float ( sum ( SCORE [ t ] for t in ranks ) ) / float ( len ( ranks ) ) NEW_LINE print ( \" { } \" . format ( gpa ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"import sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE r = input ( ) . rstrip ( ) NEW_LINE sum = 0 NEW_LINE sum += r . count ( ' A ' ) * 4 NEW_LINE sum += r . count ( ' B ' ) * 3 NEW_LINE sum += r . count ( ' C ' ) * 2 NEW_LINE sum += r . count ( ' D ' ) * 1 NEW_LINE print ( sum / N ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE list = list ( input ( ) ) NEW_LINE gpa = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if list [ i ] == \" A \" : NEW_LINE INDENT gpa += 4 NEW_LINE DEDENT elif list [ i ] == \" B \" : NEW_LINE INDENT gpa += 3 NEW_LINE DEDENT elif list [ i ] == \" C \" : NEW_LINE INDENT gpa += 2 NEW_LINE DEDENT elif list [ i ] == \" D \" : NEW_LINE INDENT gpa += 1 NEW_LINE DEDENT DEDENT print ( gpa / n ) NEW_LINE",
"def io_generator ( ) : NEW_LINE INDENT return input ( ) NEW_LINE DEDENT def main ( io ) : NEW_LINE INDENT n = int ( io ( ) ) NEW_LINE s = io ( ) [ : n ] NEW_LINE dd = { ' A ' : 4 , ' B ' : 3 , ' C ' : 2 , ' D ' : 1 , ' F ' : 0 } NEW_LINE aa = [ dd [ c ] for c in s ] NEW_LINE print ( sum ( aa ) / len ( aa ) ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT io = lambda : io_generator ( ) NEW_LINE main ( io ) NEW_LINE DEDENT"
] |
atcoder_arc004_A | [
"import java . util . Scanner ; class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x [ ] = new int [ n ] ; int y [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; } double line = 0.0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { double line2 = ( double ) Math . pow ( x [ i ] - x [ j ] , 2 ) + ( double ) Math . pow ( y [ i ] - y [ j ] , 2 ) ; if ( line < line2 ) { line = line2 ; } } } double answer = Math . sqrt ( line ) ; System . out . println ( answer ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . math . BigDecimal ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int [ ] x = new int [ N ] ; int [ ] y = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { x [ i ] = in . nextInt ( ) ; y [ i ] = in . nextInt ( ) ; } double max = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i == j ) continue ; max = Math . max ( max , Math . sqrt ( Math . pow ( x [ i ] - x [ j ] , 2 ) + Math . pow ( y [ i ] - y [ j ] , 2 ) ) ) ; } } System . out . println ( max ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Stream ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = Integer . parseInt ( sc . nextLine ( ) ) ; List < int [ ] > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < num ; i ++ ) { String [ ] str = sc . nextLine ( ) . split ( \" β \" ) ; list . add ( Stream . of ( str ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ) ; } double maxLength = 0 ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int [ ] baseNums = list . get ( i ) ; for ( int k = 0 ; k < list . size ( ) ; k ++ ) { if ( i <= k ) { continue ; } int [ ] targetNums = list . get ( k ) ; double xLength = Math . pow ( Math . abs ( baseNums [ 0 ] - targetNums [ 0 ] ) , 2 ) ; double yLength = Math . pow ( Math . abs ( baseNums [ 1 ] - targetNums [ 1 ] ) , 2 ) ; double sqrt = Math . sqrt ( xLength + yLength ) ; if ( sqrt > maxLength ) { maxLength = sqrt ; } } } System . out . println ( maxLength ) ; } }",
"import java . io . PrintStream ; import java . util . Scanner ; public class Main { static void exec ( Scanner in , PrintStream out ) { int N = in . nextInt ( ) ; int [ ] x = new int [ N ] ; int [ ] y = new int [ N ] ; for ( int i = 0 ; i < N ; i += 1 ) { x [ i ] = in . nextInt ( ) ; y [ i ] = in . nextInt ( ) ; } double max = 0.0 ; for ( int i = 0 ; i < N ; i += 1 ) { for ( int j = i + 1 ; j < N ; j += 1 ) { int dx = x [ i ] - x [ j ] ; int dy = y [ i ] - y [ j ] ; double len = Math . sqrt ( dx * dx + dy * dy ) ; if ( max < len ) { max = len ; } } } out . printf ( \" % .6f % n \" , max ) ; } public static void main ( String [ ] args ) { exec ( new Scanner ( System . in ) , System . out ) ; } }",
"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Integer > x = new ArrayList < > ( ) ; List < Integer > y = new ArrayList < > ( ) ; IntStream . range ( 0 , n ) . forEach ( i -> { x . add ( sc . nextInt ( ) ) ; y . add ( sc . nextInt ( ) ) ; } ) ; double maxLen = 0 ; for ( int i = 0 ; i < x . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < x . size ( ) ; j ++ ) { double len = Math . sqrt ( Math . pow ( x . get ( j ) - x . get ( i ) , 2 ) + Math . pow ( y . get ( j ) - y . get ( i ) , 2 ) ) ; if ( i == 0 && j == 1 || maxLen < len ) { maxLen = len ; } } } System . out . println ( maxLen ) ; } }"
] | [
"import math NEW_LINE N = int ( input ( ) ) NEW_LINE points = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( N ) ] NEW_LINE max = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT dist = ( points [ i ] [ 0 ] - points [ j ] [ 0 ] ) ** 2 + ( points [ i ] [ 1 ] - points [ j ] [ 1 ] ) ** 2 NEW_LINE if dist > max : max = dist NEW_LINE DEDENT DEDENT print ( math . sqrt ( max ) ) NEW_LINE",
"from math import sqrt NEW_LINE n = int ( input ( ) ) NEW_LINE points = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT point = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE points . append ( point ) NEW_LINE DEDENT ans = 0 NEW_LINE while not points == [ ] : NEW_LINE INDENT point = points . pop ( ) NEW_LINE x , y = point NEW_LINE for other in points : NEW_LINE INDENT x1 , y1 = other NEW_LINE ans = max ( ans , sqrt ( ( x - x1 ) ** 2 + ( y - y1 ) ** 2 ) ) NEW_LINE DEDENT DEDENT print ( \" { : . 6f } \" . format ( ans , ) ) NEW_LINE",
"import math NEW_LINE import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE setlist = [ input ( ) for _ in range ( N ) ] NEW_LINE result = 0.0 NEW_LINE for s1 in setlist : NEW_LINE INDENT x1 , y1 = map ( int , s1 . split ( ) ) NEW_LINE for s2 in setlist : NEW_LINE INDENT x2 , y2 = map ( int , s2 . split ( ) ) NEW_LINE tmp = math . sqrt ( ( x2 - x1 ) ** 2 + ( y2 - y1 ) ** 2 ) NEW_LINE if result < tmp : NEW_LINE INDENT result = tmp NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE",
"import math NEW_LINE n = int ( input ( ) ) NEW_LINE lmax = 0 NEW_LINE lx = [ ] NEW_LINE ly = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE lx . append ( x ) NEW_LINE ly . append ( y ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( 1 , n ) : NEW_LINE INDENT a = abs ( lx [ i ] - lx [ j ] ) NEW_LINE b = abs ( ly [ i ] - ly [ j ] ) NEW_LINE l = a * a + b * b NEW_LINE if lmax < l : NEW_LINE INDENT lmax = l NEW_LINE DEDENT DEDENT DEDENT print ( math . sqrt ( lmax ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE points = [ [ int ( i ) for i in input ( ) . split ( ) ] for i in range ( N ) ] NEW_LINE ans = 0 NEW_LINE for x , y , in points : NEW_LINE INDENT for dx , dy in points : NEW_LINE INDENT ans = max ( ans , ( ( x - dx ) ** 2 + ( y - dy ) ** 2 ) ** 0.5 ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE"
] |
atcoder_arc055_B | [
"import java . util . Scanner ; public class Main { static double dp [ ] [ ] [ ] ; static int n , k ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; k = sc . nextInt ( ) ; dp = new double [ n + 1 ] [ k + 2 ] [ 2 ] ; for ( int i = 0 ; i < k + 1 ; i ++ ) { dp [ n ] [ i ] [ 1 ] = 1 ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < k + 1 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) { double p = 1.0 / ( i + 1 ) ; double r = ( 1.0 - p ) * dp [ i + 1 ] [ j ] [ l ] + p * Math . max ( dp [ i + 1 ] [ j + 1 ] [ 1 ] , dp [ i + 1 ] [ j ] [ 0 ] ) ; dp [ i ] [ j ] [ l ] = r ; } } } System . out . println ( dp [ 0 ] [ 0 ] [ 0 ] ) ; } }",
"import java . util . * ; public class Main { static int n , k ; static double [ ] [ ] [ ] dp ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; k = sc . nextInt ( ) ; dp = new double [ n + 1 ] [ k + 2 ] [ 2 ] ; for ( int i = 0 ; i < k + 1 ; i ++ ) { dp [ n ] [ i ] [ 1 ] = 1 ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < k + 1 ; j ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) { double p = 1.0 / ( i + 1 ) ; double r = ( 1.0 - p ) * dp [ i + 1 ] [ j ] [ l ] + p * Math . max ( dp [ i + 1 ] [ j + 1 ] [ 1 ] , dp [ i + 1 ] [ j ] [ 0 ] ) ; dp [ i ] [ j ] [ l ] = r ; } } } System . out . println ( dp [ 0 ] [ 0 ] [ 0 ] ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double [ ] [ ] dp = new double [ 1001 ] [ 1001 ] ; for ( int r = n - 1 ; r > 0 ; r -- ) { dp [ r ] [ 0 ] = dp [ r + 1 ] [ 0 ] ; for ( int s = 1 ; s <= k ; s ++ ) { dp [ r ] [ s ] = dp [ r + 1 ] [ s ] + Math . max ( 1.0 / n + dp [ r + 1 ] [ s - 1 ] , dp [ r + 1 ] [ s ] ) / r ; } } System . out . println ( Math . max ( 1.0 / n + dp [ 1 ] [ k - 1 ] , dp [ 1 ] [ k ] ) ) ; } }",
"import java . io . * ; import java . util . * ; public class Main { private static Scanner sc ; private static Printer pr ; private static void solve ( ) { int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double [ ] [ ] dp = new double [ k + 1 ] [ n + 1 ] ; double [ ] [ ] dp2 = new double [ k + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= k ; i ++ ) { dp2 [ i ] [ 0 ] = 1 ; } for ( int i = 1 ; i <= n ; i ++ ) { double p = ( double ) 1 / ( n - i + 1 ) ; for ( int j = 0 ; j <= k ; j ++ ) { dp [ j ] [ i ] = dp [ j ] [ i - 1 ] * ( 1 - p ) ; dp2 [ j ] [ i ] = dp2 [ j ] [ i - 1 ] * ( 1 - p ) ; double tmp = 0 ; if ( j > 0 ) { tmp = dp2 [ j - 1 ] [ i - 1 ] * p ; } else { } dp [ j ] [ i ] += Math . max ( tmp , dp [ j ] [ i - 1 ] * p ) ; dp2 [ j ] [ i ] += Math . max ( tmp , dp [ j ] [ i - 1 ] * p ) ; } } pr . printf ( \" % .7f \\n \" , dp [ k ] [ n ] ) ; } public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; pr = new Printer ( System . out ) ; solve ( ) ; pr . close ( ) ; sc . close ( ) ; } private static class Printer extends PrintWriter { Printer ( PrintStream out ) { super ( out ) ; } } }",
"import java . util . * ; public class Main { static int N ; static double [ ] [ ] [ ] memo ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; memo = new double [ 2 ] [ N + 1 ] [ K + 1 ] ; for ( int t = 0 ; t < 2 ; t ++ ) for ( int i = 0 ; i < N + 1 ; i ++ ) Arrays . fill ( memo [ t ] [ i ] , - 1 ) ; System . out . println ( calc ( 0 , 0 , K ) ) ; sc . close ( ) ; } static double calc ( int i , int j , int k ) { if ( memo [ i ] [ j ] [ k ] >= 0 ) return memo [ i ] [ j ] [ k ] ; double ans = 0 ; if ( j == N ) return i == 1 ? 1.0 : 0.0 ; double p = 1.0 / ( j + 1 ) ; if ( k > 0 ) { ans = p * Math . max ( calc ( 0 , j + 1 , k ) , calc ( 1 , j + 1 , k - 1 ) ) + ( 1 - p ) * calc ( i , j + 1 , k ) ; } else { ans = p * calc ( 0 , j + 1 , k ) + ( 1 - p ) * calc ( i , j + 1 , k ) ; } return memo [ i ] [ j ] [ k ] = ans ; } }"
] | [
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 6 ) NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE dp = [ [ [ - 1 , - 1 ] for _ in [ 0 ] * ( K + 2 ) ] for _ in [ 0 ] * ( N + 1 ) ] NEW_LINE for i in range ( K + 1 ) : NEW_LINE INDENT dp [ N ] [ i ] = [ 0 , 0 ] NEW_LINE DEDENT dp [ N ] [ K ] [ 1 ] = 1 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT dp [ i ] [ K + 1 ] = [ 0 , 0 ] NEW_LINE DEDENT def solve ( i , j , b ) : NEW_LINE INDENT if dp [ i ] [ j ] [ b ] == - 1 : NEW_LINE INDENT max_prob , not_max_prob = 1 / ( i + 1 ) , 1 - 1 / ( i + 1 ) NEW_LINE if N - i + j == K : NEW_LINE INDENT dp [ i ] [ j ] [ b ] = solve ( i + 1 , j + 1 , b ) * not_max_prob + solve ( i + 1 , j + 1 , 1 ) * max_prob NEW_LINE DEDENT else : NEW_LINE INDENT dp [ i ] [ j ] [ b ] = solve ( i + 1 , j , b ) * not_max_prob + max ( solve ( i + 1 , j + 1 , 1 ) , solve ( i + 1 , j , 0 ) ) * max_prob NEW_LINE DEDENT DEDENT return dp [ i ] [ j ] [ b ] NEW_LINE DEDENT print ( solve ( 0 , 0 , 0 ) ) NEW_LINE",
"from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE INF = float ( \" inf \" ) NEW_LINE def main ( ) : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE dp = [ [ [ 0 , 0 ] for j in range ( K + 2 ) ] for l in range ( N + 1 ) ] NEW_LINE for j in range ( K + 1 ) : NEW_LINE INDENT dp [ N ] [ j ] [ 1 ] = 1 NEW_LINE DEDENT for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT for j in range ( K + 1 ) : NEW_LINE INDENT p = 1 / ( i + 1 ) NEW_LINE a = p * max ( dp [ i + 1 ] [ j + 1 ] [ 1 ] , dp [ i + 1 ] [ j ] [ 0 ] ) NEW_LINE dp [ i ] [ j ] [ 1 ] = ( 1 - p ) * dp [ i + 1 ] [ j ] [ 1 ] + a NEW_LINE dp [ i ] [ j ] [ 0 ] = ( 1 - p ) * dp [ i + 1 ] [ j ] [ 0 ] + a NEW_LINE DEDENT DEDENT print ( dp [ 0 ] [ 0 ] [ 0 ] ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"def read ( ) : NEW_LINE INDENT return map ( int , input ( ) . split ( ) ) NEW_LINE DEDENT ( N , K ) = read ( ) NEW_LINE dp = [ [ 0 ] * ( K + 1 ) for _ in range ( 2 ) ] NEW_LINE for r in range ( N - 1 , 0 , - 1 ) : NEW_LINE INDENT dp [ r & 1 ] [ 0 ] = dp [ ( r + 1 ) & 1 ] [ 0 ] NEW_LINE for s in range ( 1 , K + 1 ) : NEW_LINE INDENT dp [ r & 1 ] [ s ] = dp [ ( r + 1 ) & 1 ] [ s ] + max ( 1 / N + dp [ ( r + 1 ) & 1 ] [ s - 1 ] , dp [ ( r + 1 ) & 1 ] [ s ] ) / r NEW_LINE DEDENT DEDENT print ( max ( 1 / N + dp [ 1 ] [ K - 1 ] , dp [ 1 ] [ K ] ) ) NEW_LINE",
"import sys NEW_LINE def read ( ) : NEW_LINE INDENT return map ( int , input ( ) . split ( ) ) NEW_LINE DEDENT ( N , K ) = read ( ) NEW_LINE if N == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT dp = [ [ 0 ] * ( K + 1 ) for _ in range ( 2 ) ] NEW_LINE dp [ ( N - 1 ) & 1 ] [ 0 ] = 0 NEW_LINE for s in range ( 1 , K + 1 ) : NEW_LINE INDENT dp [ ( N - 1 ) & 1 ] [ s ] = 1 / N / ( N - 1 ) NEW_LINE DEDENT for r in range ( N - 2 , 0 , - 1 ) : NEW_LINE INDENT dp [ r & 1 ] [ 0 ] = dp [ ( r + 1 ) & 1 ] [ 0 ] NEW_LINE for s in range ( 1 , K + 1 ) : NEW_LINE INDENT dp [ r & 1 ] [ s ] = dp [ ( r + 1 ) & 1 ] [ s ] + max ( 1 / N + dp [ ( r + 1 ) & 1 ] [ s - 1 ] , dp [ ( r + 1 ) & 1 ] [ s ] ) / r NEW_LINE DEDENT DEDENT result = max ( 1 / N + dp [ 1 ] [ K - 1 ] , dp [ 1 ] [ K ] ) NEW_LINE print ( result ) NEW_LINE",
"n , k = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE dp = [ [ [ 0 , 0 ] for i in range ( k + 2 ) ] for i in range ( n + 1 ) ] NEW_LINE for i in range ( k + 1 ) : dp [ n ] [ i ] [ 1 ] = 1 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT for j in range ( min ( i + 1 , k + 1 ) ) : NEW_LINE INDENT dp [ i ] [ j ] [ 0 ] = ( dp [ i + 1 ] [ j ] [ 0 ] * i + max ( dp [ i + 1 ] [ j ] [ 0 ] , dp [ i + 1 ] [ j + 1 ] [ 1 ] ) ) / ( i + 1 ) NEW_LINE dp [ i ] [ j ] [ 1 ] = ( dp [ i + 1 ] [ j ] [ 1 ] * i + max ( dp [ i + 1 ] [ j ] [ 0 ] , dp [ i + 1 ] [ j + 1 ] [ 1 ] ) ) / ( i + 1 ) NEW_LINE DEDENT DEDENT print ( dp [ 0 ] [ 0 ] [ 0 ] ) NEW_LINE"
] |
atcoder_abc006_C | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int two , three , four ; if ( m % 2 == 0 ) { three = 0 ; two = ( 4 * n - m ) / 2 ; four = n - two ; } else { three = 1 ; two = ( 4 * n - m - 1 ) / 2 ; four = n - 1 - two ; } if ( two < 0 || four < 0 ) { System . out . println ( \" - 1 β - 1 β - 1\" ) ; } else { System . out . println ( two + \" β \" + three + \" β \" + four ) ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Comparator ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int a = - 1 ; int b = - 1 ; int c = - 1 ; if ( M % 2 == 0 ) { for ( int i = 0 ; i <= N ; i ++ ) { if ( 2 * i + ( 4 * ( N - i ) ) == M ) { a = i ; b = 0 ; c = N - i ; } } } else { for ( int i = 0 ; i <= N - 1 ; i ++ ) { if ( 2 * i + 3 + ( 4 * ( N - 1 - i ) ) == M ) { a = i ; b = 1 ; c = N - 1 - i ; } } } out . println ( a + \" β \" + b + \" β \" + c ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; @ SuppressWarnings ( \" unchecked \" ) public class Main { public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( \" β \" ) ; long N = Long . parseLong ( sl [ 0 ] ) ; long M = Long . parseLong ( sl [ 1 ] ) ; long adult = - 1 ; long old = - 1 ; long baby = - 1 ; boolean flg = false ; for ( long i = 0 ; i < N + 1 ; i ++ ) { for ( long j = 0 ; j < 2 ; j ++ ) { if ( N - i - j < 0 ) continue ; if ( M == 2 * ( N - i - j ) + 3 * j + 4 * i ) { flg = true ; adult = N - i - j ; old = j ; baby = i ; break ; } } if ( flg ) break ; } out . println ( adult + \" β \" + old + \" β \" + baby ) ; out . flush ( ) ; } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int s = ( M - 2 * N ) / 2 ; for ( int k = 0 ; k <= s ; k ++ ) { int j = M - 2 * ( N + k ) ; int i = N - j - k ; if ( i >= 0 && j >= 0 && i + j + k == N ) { out . println ( i + \" β \" + j + \" β \" + k ) ; exit ( 0 ) ; } } out . println ( \" - 1 β - 1 β - 1\" ) ; } }",
"import java . util . * ; import java . util . stream . IntStream ; public class Main { public static boolean found = false ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numOfPerson = sc . nextInt ( ) ; int numOfFoot = sc . nextInt ( ) ; int maxFoot = numOfPerson * 4 ; int minFoot = numOfPerson * 2 ; if ( numOfFoot < minFoot || maxFoot < numOfFoot ) { System . out . println ( \" - 1 β - 1 β - 1\" ) ; return ; } int numOfAdult = numOfPerson ; int diff = numOfFoot - minFoot ; if ( diff % 2 == 0 ) { int numOfBaby = ( diff / 2 ) ; numOfAdult = numOfAdult - numOfBaby ; System . out . println ( numOfAdult + \" β 0 β \" + numOfBaby ) ; } else { int numOfBaby = ( diff / 2 ) ; numOfAdult = numOfAdult - numOfBaby - 1 ; System . out . println ( numOfAdult + \" β 1 β \" + numOfBaby ) ; } } }"
] | [
"N , M = map ( int , input ( ) . split ( ) ) NEW_LINE if M / N > 4 or M / N < 2 : NEW_LINE INDENT print ( \" - 1 β - 1 β - 1\" ) NEW_LINE DEDENT else : NEW_LINE INDENT a = M - N * 3 NEW_LINE if ( a < 0 ) : NEW_LINE INDENT print ( - a , a + N , 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 , N - a , a ) NEW_LINE DEDENT DEDENT",
"import sys NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT b = 4 * n - 2 * i - m NEW_LINE if isinstance ( b , int ) and n - i - b >= 0 and b >= 0 : NEW_LINE INDENT print ( i , b , n - i - b ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT print ( - 1 , - 1 , - 1 ) NEW_LINE",
"N , M = map ( int , input ( ) . split ( ' β ' ) ) NEW_LINE rem = M % 4 NEW_LINE if rem == 0 : NEW_LINE INDENT if M // 4 <= N <= M // 2 : NEW_LINE INDENT print ( M // 2 - ( M // 2 - N ) * 2 , 0 , M // 2 - N ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' - 1 β - 1 β - 1' ) NEW_LINE DEDENT DEDENT elif rem == 1 : NEW_LINE INDENT if M // 4 + 1 <= N <= M // 2 : NEW_LINE INDENT print ( M // 2 - ( M // 2 - N ) * 2 - 1 , 1 , M // 2 - N ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' - 1 β - 1 β - 1' ) NEW_LINE DEDENT DEDENT elif rem == 2 : NEW_LINE INDENT if M // 4 + 1 <= N <= M // 2 : NEW_LINE INDENT print ( M // 2 - ( M // 2 - N ) * 2 , 0 , M // 2 - N ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' - 1 β - 1 β - 1' ) NEW_LINE DEDENT DEDENT elif rem == 3 : NEW_LINE INDENT if M // 4 + 1 <= N <= M // 2 : NEW_LINE INDENT print ( M // 2 - ( M // 2 - N ) * 2 - 1 , 1 , M // 2 - N ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' - 1 β - 1 β - 1' ) NEW_LINE DEDENT DEDENT",
"n , m = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE if m < 2 * n or 4 * n < m : NEW_LINE INDENT print ( - 1 , - 1 , - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT f = m - 2 * n NEW_LINE baby = f // 2 NEW_LINE old = f % 2 NEW_LINE adult = n - baby - old NEW_LINE print ( adult , old , baby ) NEW_LINE DEDENT",
"N , M = map ( int , input ( ) . split ( ' β ' ) ) NEW_LINE if M % 4 == 0 : NEW_LINE INDENT ans = ( M // 2 - ( M // 2 - N ) * 2 , 0 , M // 2 - N ) if M // 4 <= N <= M // 2 else ( - 1 , - 1 , - 1 ) NEW_LINE DEDENT elif M % 4 == 2 : NEW_LINE INDENT ans = ( M // 2 - ( M // 2 - N ) * 2 , 0 , M // 2 - N ) if M // 4 + 1 <= N <= M // 2 else ( - 1 , - 1 , - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = ( M // 2 - ( M // 2 - N ) * 2 - 1 , 1 , M // 2 - N ) if M // 4 + 1 <= N <= M // 2 else ( - 1 , - 1 , - 1 ) NEW_LINE DEDENT print ( ans [ 0 ] , ans [ 1 ] , ans [ 2 ] ) NEW_LINE"
] |
atcoder_abc013_A | [
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( in . next ( ) . charAt ( 0 ) - ' A ' + 1 ) ; } } 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 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isPrintableChar ( int c ) { return c >= 33 && c <= 126 ; } public String next ( ) { StringBuilder sb = new StringBuilder ( ) ; int b = readByte ( ) ; while ( ! isPrintableChar ( b ) ) b = readByte ( ) ; while ( isPrintableChar ( b ) ) { sb . appendCodePoint ( b ) ; b = readByte ( ) ; } return sb . toString ( ) ; } } }",
"import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { char x = sc . next ( ) . charAt ( 0 ) ; System . out . println ( x - ' A ' + 1 ) ; } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; String s = sc . next ( ) ; char x [ ] = s . toCharArray ( ) ; System . out . println ( x [ 0 ] - ' A ' + 1 ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String X = in . next ( ) ; int ans = 0 ; switch ( X ) { case \" A \" : ans = 1 ; break ; case \" B \" : ans = 2 ; break ; case \" C \" : ans = 3 ; break ; case \" D \" : ans = 4 ; break ; case \" E \" : ans = 5 ; break ; } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String x = scanner . nextLine ( ) ; scanner . close ( ) ; String [ ] alphabets = { \" A \" , \" B \" , \" C \" , \" D \" , \" E \" } ; int order = Arrays . asList ( alphabets ) . indexOf ( x ) + 1 ; System . out . println ( order ) ; } }"
] | [
"n = input ( ) NEW_LINE if n == \" A \" : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT elif n == \" B \" : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT elif n == \" C \" : NEW_LINE INDENT print ( 3 ) NEW_LINE DEDENT elif n == \" D \" : NEW_LINE INDENT print ( 4 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 5 ) NEW_LINE DEDENT",
"s = input ( ) NEW_LINE print ( ord ( s ) - 64 ) NEW_LINE",
"s = input ( ) NEW_LINE if s == \" A \" : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT elif s == \" B \" : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT elif s == \" C \" : NEW_LINE INDENT print ( 3 ) NEW_LINE DEDENT elif s == \" D \" : NEW_LINE INDENT print ( 4 ) NEW_LINE DEDENT elif s == \" E \" : NEW_LINE INDENT print ( 5 ) NEW_LINE DEDENT",
"print ( ' ABCDE ' . find ( input ( ) ) + 1 ) NEW_LINE",
"a = input ( ) NEW_LINE for i , j in enumerate ( [ \" A \" , \" B \" , \" C \" , \" D \" , \" E \" ] ) : NEW_LINE INDENT if j == a : NEW_LINE INDENT print ( i + 1 ) NEW_LINE DEDENT DEDENT"
] |
atcoder_abc038_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h1 = sc . nextInt ( ) ; int w1 = sc . nextInt ( ) ; int h2 = sc . nextInt ( ) ; int w2 = sc . nextInt ( ) ; if ( h1 == h2 || w1 == w2 || h1 == w2 || w1 == h2 ) { System . out . print ( \" YES \" ) ; } else { System . out . print ( \" NO \" ) ; } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . stream . IntStream ; 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 { private static final String YES = \" YES \" ; private static final String NO = \" NO \" ; public void solve ( int testNumber , LightScanner in , PrintWriter out ) { int [ ] a = in . ints ( 4 ) ; if ( a [ 0 ] == a [ 2 ] || a [ 1 ] == a [ 2 ] || a [ 0 ] == a [ 3 ] || a [ 1 ] == a [ 3 ] ) { out . println ( YES ) ; } else { out . println ( NO ) ; } } } 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 ( ) ) ; } public int [ ] ints ( int length ) { return IntStream . range ( 0 , length ) . map ( x -> ints ( ) ) . toArray ( ) ; } } }",
"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 ) { int h1 = in . nextInt ( ) ; int w1 = in . nextInt ( ) ; int h2 = in . nextInt ( ) ; int w2 = in . nextInt ( ) ; if ( h1 == h2 || w1 == w2 || h1 == w2 || h2 == w1 ) out . println ( \" YES \" ) ; else out . println ( \" NO \" ) ; } } 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 ; } 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 isSpaceChar ( int c ) { return c == ' β ' || c == ' \\n ' || c == ' \\r ' || c == ' \\t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }",
"import java . util . * ; import static java . lang . System . in ; import static java . lang . System . out ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; String [ ] input1 = sc . nextLine ( ) . split ( \" β \" , 0 ) ; String [ ] input2 = sc . nextLine ( ) . split ( \" β \" , 0 ) ; int [ ] hw1 = new int [ 2 ] ; int [ ] hw2 = new int [ 2 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { hw1 [ i ] = Integer . parseInt ( input1 [ i ] ) ; hw2 [ i ] = Integer . parseInt ( input2 [ i ] ) ; } for ( int i = 0 ; i < 2 ; i ++ ) for ( int j = 0 ; j < 2 ; j ++ ) { if ( hw1 [ i ] == hw2 [ j ] ) { out . println ( \" YES \" ) ; return ; } } out . println ( \" NO \" ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int h1 = Integer . parseInt ( sc . next ( ) ) ; int w1 = Integer . parseInt ( sc . next ( ) ) ; int h2 = Integer . parseInt ( sc . next ( ) ) ; int w2 = Integer . parseInt ( sc . next ( ) ) ; sc . close ( ) ; if ( h1 == h2 || h1 == w2 || w1 == h2 || w1 == w2 ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } }"
] | [
"a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE ans = \" NO \" NEW_LINE for i in a : NEW_LINE INDENT if i in b : NEW_LINE INDENT ans = \" YES \" NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"def display ( H1 : int , W1 : int , H2 : int , W2 : int ) -> bool : NEW_LINE INDENT return H1 == H2 or H1 == W2 or W1 == H2 or W1 == W2 NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT H1 , W1 = map ( int , input ( ) . split ( ) ) NEW_LINE H2 , W2 = map ( int , input ( ) . split ( ) ) NEW_LINE yes = display ( H1 , W1 , H2 , W2 ) NEW_LINE print ( ' YES ' if yes else ' NO ' ) NEW_LINE DEDENT",
"a , b = input ( ) . split ( ) NEW_LINE c = input ( ) . split ( ) NEW_LINE if a in c : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT elif b in c : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT",
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE c , d = map ( int , input ( ) . split ( ) ) NEW_LINE print ( \" YES \" if { a , b } & { c , d } != set ( ) else \" NO \" ) NEW_LINE",
"H1 , W1 = map ( int , input ( ) . split ( ) ) NEW_LINE H2 , W2 = map ( int , input ( ) . split ( ) ) NEW_LINE flag = False NEW_LINE if H1 == H2 : NEW_LINE INDENT flag = True NEW_LINE DEDENT if H1 == W2 : NEW_LINE INDENT flag = True NEW_LINE DEDENT if W1 == H2 : NEW_LINE INDENT flag = True NEW_LINE DEDENT if W1 == W2 : NEW_LINE INDENT flag = True NEW_LINE DEDENT if flag : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT"
] |
atcoder_abc008_A | [
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int i = sc . nextInt ( ) ; System . out . println ( sc . nextInt ( ) - i + 1 ) ; } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( 1 - in . nextInt ( ) + in . nextInt ( ) ) ; } } 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 isSpaceChar ( int c ) { return c == ' β ' || c == ' \\n ' || c == ' \\r ' || c == ' \\t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; System . out . println ( b - a + 1 ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int a = nextInt ( ) , b = nextInt ( ) ; out . println ( b - a + 1 ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String range = scanner . nextLine ( ) ; scanner . close ( ) ; int delimiterPos = range . indexOf ( \" β \" ) ; int s = Integer . parseInt ( range . substring ( 0 , delimiterPos ) ) ; int t = Integer . parseInt ( range . substring ( delimiterPos + 1 ) ) ; int num = t - ( s - 1 ) ; System . out . println ( num ) ; } }"
] | [
"S , T = map ( int , input ( ) . split ( ) ) NEW_LINE print ( T - S + 1 ) NEW_LINE",
"import numpy as np NEW_LINE class Calculator : NEW_LINE INDENT def __init__ ( self , arr ) : NEW_LINE INDENT self . arr = arr NEW_LINE self . calc ( ) NEW_LINE DEDENT def calc ( self ) : NEW_LINE INDENT self . num = np . sum ( self . arr > 0 ) NEW_LINE DEDENT def get_num ( self ) : NEW_LINE INDENT return self . num NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT S , T , = map ( int , input ( ) . split ( ) ) NEW_LINE arr = np . arange ( S , T + 1 ) NEW_LINE calc = Calculator ( arr ) NEW_LINE print ( calc . get_num ( ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"s = input ( ) . split ( ) NEW_LINE S = int ( s [ 0 ] ) NEW_LINE T = int ( s [ 1 ] ) NEW_LINE if 1 <= S <= T <= 1000 : NEW_LINE INDENT print ( T - S + 1 ) NEW_LINE DEDENT",
"print ( len ( range ( * map ( int , input ( ) . split ( ) ) ) ) + 1 ) NEW_LINE",
"l = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( l [ 1 ] - l [ 0 ] + 1 ) NEW_LINE"
] |
atcoder_abc070_A | [
"import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; String S = sc . next ( ) ; if ( S . charAt ( 0 ) == S . charAt ( 2 ) ) { out . println ( \" Yes \" ) ; } else { out . println ( \" No \" ) ; } out . flush ( ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String N = in . next ( ) ; if ( N . charAt ( 0 ) == N . charAt ( 2 ) ) { out . println ( \" Yes \" ) ; } else { out . println ( \" No \" ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; System . out . println ( n == getRevers ( n ) ? \" Yes \" : \" No \" ) ; } public static int getRevers ( int n ) { int reverse = 0 ; while ( n > 9 ) { reverse = reverse * 10 + ( n % 10 ) ; n /= 10 ; } if ( n > 0 ) reverse = reverse * 10 + n ; return reverse ; } }",
"import java . util . * ; import static java . lang . Math . abs ; public class Main { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; String string = sc . next ( ) ; if ( string . charAt ( 0 ) == string . charAt ( 2 ) ) { System . out . println ( \" Yes \" ) ; } else { System . out . println ( \" No \" ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int hundred = N / 100 ; int one = N % 10 ; System . out . println ( ( hundred == one ) ? \" Yes \" : \" No \" ) ; } }"
] | [
"N = input ( ) NEW_LINE print ( ' Yes ' if int ( N ) == int ( N [ : : - 1 ] ) else ' No ' ) NEW_LINE",
"n = list ( input ( ) ) NEW_LINE t = list ( reversed ( n ) ) NEW_LINE if t == n : NEW_LINE INDENT print ( \" Yes \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" No \" ) NEW_LINE DEDENT",
"print ( \" YNeos \" [ len ( set ( input ( ) [ 0 : 3 : 2 ] ) ) - 1 : : 2 ] ) NEW_LINE",
"n = input ( ) NEW_LINE ans = ' No ' NEW_LINE if n [ 0 ] == n [ 2 ] : NEW_LINE INDENT ans = ' Yes ' NEW_LINE DEDENT print ( ans ) NEW_LINE",
"a = input ( ) NEW_LINE b = a [ : : - 1 ] NEW_LINE print ( \" Yes \" if a == b else \" No \" ) NEW_LINE"
] |
atcoder_arc058_A | [
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashSet ; import java . util . Set ; import java . util . StringTokenizer ; public class Main { int n , k ; Set < Integer > ds ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; k = sc . nextInt ( ) ; ds = new HashSet < > ( ) ; for ( int i = 0 ; i < k ; i ++ ) { ds . add ( sc . nextInt ( ) ) ; } solve ( ) ; } void solve ( ) { while ( true ) { boolean flag = true ; int temp = n ; while ( temp > 0 ) { if ( ds . contains ( temp % 10 ) ) { flag = false ; break ; } temp /= 10 ; } if ( flag ) { System . out . println ( n ) ; return ; } else { n ++ ; } } } 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 java . io . * ; import java . util . * ; import java . util . function . * ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } int N , K ; boolean [ ] D ; public Main ( ) { Scanner in = new Scanner ( System . in ) ; N = in . nextInt ( ) ; K = in . nextInt ( ) ; D = new boolean [ 10 ] ; for ( int i = 0 ; i < K ; i ++ ) { D [ in . nextInt ( ) ] = true ; } } void solve ( ) { Function < Integer , Boolean > ok = ( n ) -> { while ( n > 0 ) { if ( D [ n % 10 ] ) return false ; n /= 10 ; } return true ; } ; for ( int n = N ; ; n ++ ) { if ( ok . apply ( n ) ) { System . out . println ( n ) ; break ; } } } }",
"import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { static class Fast { BufferedReader br ; StringTokenizer st ; public Fast ( ) { 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 ; } } public static void main ( String args [ ] ) throws Exception { Fast in = new Fast ( ) ; int arr [ ] = new int [ 10 ] ; int n = in . nextInt ( ) , k = in . nextInt ( ) ; for ( int i = 0 ; i < k ; i ++ ) { arr [ in . nextInt ( ) ] = 1 ; } l : for ( int i = n ; i < 10000000 ; i ++ ) { String str = \" \" + i ; for ( int j = 0 ; j < str . length ( ) ; j ++ ) { if ( arr [ str . charAt ( j ) - '0' ] == 1 ) { continue l ; } } System . out . println ( i ) ; return ; } } }",
"import java . util . * ; import java . io . * ; public class Main { public static boolean hated ( int price , Set < Integer > hateNum ) { if ( price < 10 ) return hateNum . contains ( price ) ; else return hateNum . contains ( price % 10 ) || hated ( price / 10 , hateNum ) ; } public static int pay ( int price , Set < Integer > hateNum ) { while ( hated ( price , hateNum ) ) { price ++ ; } return price ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; Set < Integer > hateNum = new HashSet < > ( ) ; for ( int k = 0 ; k < K ; k ++ ) hateNum . add ( sc . nextInt ( ) ) ; System . out . println ( pay ( N , hateNum ) ) ; } }",
"import java . io . BufferedInputStream ; import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( new BufferedInputStream ( System . in ) ) ; String N = scan . next ( ) ; int K = scan . nextInt ( ) ; HashSet < Integer > dis = new HashSet < > ( ) ; for ( int i = 0 ; i < K ; i ++ ) dis . add ( scan . nextInt ( ) ) ; int low = 0 ; while ( dis . contains ( low ) ) low ++ ; int [ ] num = new int [ N . length ( ) ] ; for ( int i = 0 ; i < num . length ; i ++ ) num [ i ] = N . charAt ( i ) - '0' ; String res = dfs ( dis , 0 , num , low ) ; if ( res != null ) { System . out . println ( res ) ; return ; } int first = low ; if ( first == 0 ) { first ++ ; while ( dis . contains ( first ) ) first ++ ; } System . out . print ( first ) ; for ( int i = 0 ; i < num . length ; i ++ ) System . out . print ( low ) ; System . out . println ( ) ; } private static String dfs ( HashSet < Integer > dis , int idx , int [ ] num , int low ) { if ( idx == num . length ) return \" \" ; int i = num [ idx ] ; while ( dis . contains ( i ) ) i ++ ; if ( i > 9 ) return null ; if ( i == num [ idx ] ) { String next = dfs ( dis , idx + 1 , num , low ) ; if ( next != null ) return \" \" + i + next ; i ++ ; while ( dis . contains ( i ) ) i ++ ; if ( i > 9 ) return null ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( i ) ; for ( int j = 0 ; j < num . length - idx - 1 ; j ++ ) sb . append ( low ) ; return sb . toString ( ) ; } }"
] | [
"n , a = open ( 0 ) ; n = int ( n . split ( ) [ 0 ] ) NEW_LINE while set ( a ) & set ( str ( n ) ) : n += 1 NEW_LINE print ( n ) NEW_LINE",
"import bisect NEW_LINE N , K = input ( ) . split ( ) NEW_LINE dList = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE useList = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] NEW_LINE for d in dList : NEW_LINE INDENT useList . remove ( d ) NEW_LINE DEDENT result = ' ' NEW_LINE if int ( N [ 0 ] ) > max ( useList ) : NEW_LINE INDENT if useList [ 0 ] != 0 : NEW_LINE INDENT result += str ( useList [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT result += str ( useList [ 1 ] ) NEW_LINE DEDENT result += str ( useList [ 0 ] ) * ( len ( N ) ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( len ( N ) ) : NEW_LINE INDENT a = int ( N [ i ] ) NEW_LINE if a in useList : NEW_LINE INDENT result += N [ i ] NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT count = 0 NEW_LINE if a > max ( useList ) : NEW_LINE INDENT while not max ( useList ) > int ( result [ - 1 ] ) : NEW_LINE INDENT count += 1 NEW_LINE result = result [ : - 1 ] NEW_LINE if result == ' ' : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if result == ' ' : NEW_LINE INDENT if useList [ 0 ] != 0 : NEW_LINE INDENT result += str ( useList [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT result += str ( useList [ 1 ] ) NEW_LINE DEDENT result += str ( useList [ 0 ] ) * ( len ( N ) ) NEW_LINE break NEW_LINE DEDENT count += 1 NEW_LINE sect = int ( result [ - 1 ] ) NEW_LINE result = result [ : - 1 ] NEW_LINE result += str ( useList [ bisect . bisect_right ( useList , sect ) ] ) NEW_LINE result += str ( useList [ 0 ] ) * ( len ( N ) - len ( result ) ) NEW_LINE DEDENT else : NEW_LINE INDENT result += str ( useList [ bisect . bisect_right ( useList , a ) ] ) NEW_LINE result += str ( useList [ 0 ] ) * ( len ( N ) - i - 1 ) NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE",
"import itertools NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE Ds = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE NDs = list ( set ( [ i for i in range ( 10 ) ] ) - set ( Ds ) ) NEW_LINE NDs = list ( map ( str , NDs ) ) NEW_LINE min_price = 100000 NEW_LINE for p in itertools . product ( NDs , repeat = len ( str ( N ) ) ) : NEW_LINE INDENT if p [ 0 ] == '0' : NEW_LINE INDENT continue NEW_LINE DEDENT price = int ( ' ' . join ( p ) ) NEW_LINE if price < N : NEW_LINE INDENT continue NEW_LINE DEDENT min_price = min ( price , min_price ) NEW_LINE DEDENT if min_price == 100000 : NEW_LINE INDENT for p in itertools . product ( NDs , repeat = len ( str ( N ) ) + 1 ) : NEW_LINE INDENT if p [ 0 ] == '0' : NEW_LINE INDENT continue NEW_LINE DEDENT price = int ( ' ' . join ( p ) ) NEW_LINE min_price = min ( price , min_price ) NEW_LINE DEDENT DEDENT print ( min_price ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 6 ) NEW_LINE def main ( ) : NEW_LINE INDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE lst = list ( input ( ) . split ( ) ) NEW_LINE for i in range ( n , 1000000 ) : NEW_LINE INDENT flg = True NEW_LINE for j in str ( i ) : NEW_LINE INDENT if j in lst : NEW_LINE INDENT flg = False NEW_LINE DEDENT DEDENT if flg : NEW_LINE INDENT print ( i ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT main ( ) NEW_LINE",
"N , K = map ( int , input ( ) . split ( ) ) NEW_LINE D = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE kazu = [ 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 ] NEW_LINE for item in D : NEW_LINE INDENT kazu . remove ( item ) NEW_LINE DEDENT p = [ ] NEW_LINE m = len ( str ( N ) ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT p . append ( kazu [ 0 ] * ( 10 ** i ) ) NEW_LINE DEDENT p . sort ( reverse = True ) NEW_LINE j = 0 NEW_LINE while j < m : NEW_LINE INDENT for i in range ( 1 , len ( kazu ) ) : NEW_LINE INDENT if sum ( p ) - p [ j ] + kazu [ i ] * ( 10 ** ( m - j - 1 ) ) >= N : NEW_LINE INDENT p [ j ] = kazu [ i ] * ( 10 ** ( m - j - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT j += 1 NEW_LINE DEDENT if sum ( p ) < N : NEW_LINE INDENT if kazu [ - 1 ] != 0 : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( m + 1 ) : NEW_LINE INDENT ans += kazu [ - 1 ] * ( 10 ** i ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ans = kazu [ - 2 ] * ( 10 ) ** m NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ans = sum ( p ) NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc025_A | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] arr = sc . next ( ) . toCharArray ( ) ; int n = sc . nextInt ( ) ; System . out . println ( \" \" + arr [ ( n - 1 ) / 5 % 5 ] + arr [ ( n - 1 ) % 5 ] ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String S = in . next ( ) ; int N = in . nextInt ( ) ; String [ ] ans = new String [ S . length ( ) * S . length ( ) ] ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { for ( int j = 0 ; j < S . length ( ) ; j ++ ) { ans [ count ] = S . substring ( i , i + 1 ) + S . substring ( j , j + 1 ) ; count ++ ; } } Arrays . sort ( ans ) ; out . println ( ans [ N - 1 ] ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; String s = sc . next ( ) ; int a = sc . nextInt ( ) ; String s1 ; String s2 ; s1 = String . valueOf ( s . charAt ( ( int ) ( a - 1 ) / 5 ) ) ; s2 = String . valueOf ( s . charAt ( ( a - 1 ) % 5 ) ) ; System . out . println ( s1 + s2 ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { String s = sc . next ( ) ; int n = sc . nextInt ( ) ; String [ ] ss = new String [ 5 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { ss [ i ] = s . charAt ( i ) + \" \" ; } List < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < ss . length ; i ++ ) { for ( int j = 0 ; j < ss . length ; j ++ ) { list . add ( ss [ i ] + ss [ j ] ) ; } } System . out . println ( list . get ( n - 1 ) ) ; } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { String s = sc . next ( ) ; int n = nextInt ( ) ; ArrayList < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { for ( int j = 0 ; j < s . length ( ) ; j ++ ) { StringBuilder temp = new StringBuilder ( ) ; temp . append ( s . charAt ( i ) ) ; temp . append ( s . charAt ( j ) ) ; list . add ( temp . toString ( ) ) ; } } Collections . sort ( list ) ; out . println ( list . get ( n - 1 ) ) ; } }"
] | [
"S = input ( ' ' ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = N % 5 NEW_LINE b = int ( N - 1 ) // 5 NEW_LINE print ( S [ b ] + S [ a - 1 ] ) NEW_LINE",
"def string25 ( S : str , N : int ) -> str : NEW_LINE INDENT sortedS = sorted ( S ) NEW_LINE count = 1 NEW_LINE for c1 in sortedS : NEW_LINE INDENT for c2 in sortedS : NEW_LINE INDENT if count == N : NEW_LINE INDENT return c1 + c2 NEW_LINE DEDENT count += 1 NEW_LINE DEDENT DEDENT return \" hoge \" NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT S = input ( ) NEW_LINE N = int ( input ( ) ) NEW_LINE ans = string25 ( S , N ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"S = input ( ) NEW_LINE N = int ( input ( ) ) NEW_LINE S = sorted ( S ) NEW_LINE cnt = 0 NEW_LINE for s in S : NEW_LINE INDENT for t in S : NEW_LINE INDENT cnt += 1 NEW_LINE ans = s + t NEW_LINE if cnt == N : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if cnt == N : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"s , n = open ( 0 ) ; n = int ( n ) - 1 ; print ( s [ n // 5 ] + s [ n % 5 ] ) NEW_LINE",
"import math NEW_LINE s = list ( input ( ) ) NEW_LINE n = int ( input ( ) ) NEW_LINE a = math . floor ( n / 5 ) NEW_LINE b = n % 5 NEW_LINE if a != 0 and b != 0 : NEW_LINE INDENT print ( s [ a ] + s [ b - 1 ] ) NEW_LINE DEDENT elif a == 0 and b != 0 : NEW_LINE INDENT print ( s [ a ] + s [ b - 1 ] ) NEW_LINE DEDENT elif a != 0 and b == 0 : NEW_LINE INDENT print ( s [ a - 1 ] + s [ b + 4 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ a ] + s [ b ] ) NEW_LINE DEDENT"
] |
atcoder_abc013_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; System . out . println ( Math . min ( Math . abs ( a - b ) , Math . min ( Math . abs ( a + 10 - b ) , Math . abs ( b + 10 - a ) ) ) ) ; } }",
"import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { PrintWriter out = new PrintWriter ( System . out ) ; InputStreamScanner in = new InputStreamScanner ( System . in ) ; new Main ( ) . solve ( in , out ) ; out . flush ( ) ; } private void solve ( InputStreamScanner in , PrintWriter out ) { int s = in . nextInt ( ) ; int e = in . nextInt ( ) ; int d = Math . abs ( s - e ) ; out . println ( d < 6 ? d : 10 - d ) ; } static class InputStreamScanner { private InputStream in ; private byte [ ] buf = new byte [ 1024 ] ; private int len = 0 ; private int off = 0 ; InputStreamScanner ( InputStream in ) { this . in = in ; } String next ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int b = skip ( ) ; ! isSpace ( b ) ; ) { sb . appendCodePoint ( b ) ; b = read ( ) ; } return sb . toString ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } char nextChar ( ) { return ( char ) skip ( ) ; } int skip ( ) { for ( int b ; ( b = read ( ) ) != - 1 ; ) { if ( ! isSpace ( b ) ) { return b ; } } return - 1 ; } private boolean isSpace ( int c ) { return c < 33 || c > 126 ; } private int read ( ) { if ( len == - 1 ) { throw new InputMismatchException ( \" End β of β Input \" ) ; } if ( off >= len ) { off = 0 ; try { len = in . read ( buf ) ; } catch ( IOException e ) { throw new InputMismatchException ( e . getMessage ( ) ) ; } if ( len <= 0 ) { return - 1 ; } } return buf [ off ++ ] ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; if ( Math . abs ( b - a ) > 5 ) { out . println ( 10 - Math . abs ( b - a ) ) ; } else { out . println ( Math . abs ( b - a ) ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }",
"import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; Queue < Integer > q = new ArrayDeque < > ( ) ; Queue < Integer > ans = new ArrayDeque < > ( ) ; q . add ( a ) ; ans . add ( 0 ) ; int answer = 10 ; while ( ! q . isEmpty ( ) ) { int p = q . poll ( ) ; int c = ans . poll ( ) ; if ( p == b ) { answer = c ; break ; } else { q . add ( ( p + 1 ) % 10 ) ; q . add ( ( p - 1 + 10 ) % 10 ) ; ans . add ( c + 1 ) ; ans . add ( c + 1 ) ; } } out . println ( answer ) ; } }",
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = Integer . parseInt ( scanner . nextLine ( ) ) ; int b = Integer . parseInt ( scanner . nextLine ( ) ) ; int c ; if ( a < b ) { c = b - 10 ; } else { c = b + 10 ; } System . out . println ( Math . min ( Math . abs ( b - a ) , Math . abs ( c - a ) ) ) ; } }"
] | [
"from statistics import mean , median , variance , stdev NEW_LINE import numpy as np NEW_LINE import sys NEW_LINE import math NEW_LINE import fractions NEW_LINE import itertools NEW_LINE import copy NEW_LINE import collections NEW_LINE from operator import itemgetter NEW_LINE def j ( q ) : NEW_LINE INDENT if q == 1 : print ( \" Yay ! \" ) NEW_LINE else : print ( \" : ( \" ) NEW_LINE exit ( 0 ) NEW_LINE DEDENT def ct ( x , y ) : NEW_LINE INDENT if ( x > y ) : print ( \" + \" ) NEW_LINE elif ( x < y ) : print ( \" - \" ) NEW_LINE else : print ( \" ? \" ) NEW_LINE DEDENT def ip ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT def printrow ( a ) : NEW_LINE INDENT for i in range ( len ( a ) ) : NEW_LINE INDENT print ( a [ i ] ) NEW_LINE DEDENT DEDENT def combinations ( n , r ) : NEW_LINE INDENT if n < r : return 0 NEW_LINE return math . factorial ( n ) // ( math . factorial ( n - r ) * math . factorial ( r ) ) NEW_LINE DEDENT def permutations ( n , r ) : NEW_LINE INDENT if n < r : return 0 NEW_LINE return math . factorial ( n ) // math . factorial ( n - r ) NEW_LINE DEDENT n = ip ( ) NEW_LINE a = ip ( ) NEW_LINE if abs ( a - n ) >= 6 : NEW_LINE INDENT print ( 10 - abs ( a - n ) ) NEW_LINE DEDENT else : print ( abs ( a - n ) ) NEW_LINE",
"a = int ( input ( ) ) NEW_LINE b = int ( input ( ) ) NEW_LINE x_min = min ( a , b ) NEW_LINE x_max = max ( a , b ) NEW_LINE print ( min ( x_max - x_min , x_min + 9 - x_max + 1 ) ) NEW_LINE",
"a , b = map ( int , open ( 0 ) ) ; print ( 5 - abs ( 5 - abs ( a - b ) ) ) NEW_LINE",
"a = int ( input ( ) ) NEW_LINE b = int ( input ( ) ) NEW_LINE up_count = 0 NEW_LINE down_count = 0 NEW_LINE a1 = a NEW_LINE a2 = a NEW_LINE while ( a1 != b ) : NEW_LINE INDENT if ( a1 == 9 ) : NEW_LINE INDENT a1 = 0 NEW_LINE up_count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT a1 += 1 NEW_LINE up_count += 1 NEW_LINE DEDENT DEDENT while ( a2 != b ) : NEW_LINE INDENT if ( a2 == 0 ) : NEW_LINE INDENT a2 = 9 NEW_LINE down_count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT a2 -= 1 NEW_LINE down_count += 1 NEW_LINE DEDENT DEDENT print ( min ( up_count , down_count ) ) NEW_LINE",
"a , b = int ( input ( ) ) , int ( input ( ) ) NEW_LINE print ( min ( abs ( a - b ) , abs ( ( 10 - max ( a , b ) ) + min ( a , b ) ) ) ) NEW_LINE"
] |
atcoder_arc015_B | [
"import java . util . * ; public class Main { private static int n ; private static ArrayList < Double > maxT = new ArrayList < > ( ) ; private static ArrayList < Double > minT = new ArrayList < > ( ) ; private static int count1 = 0 , count2 = 0 , count3 = 0 , count4 = 0 , count5 = 0 , count6 = 0 ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { maxT . add ( scan . nextDouble ( ) ) ; minT . add ( scan . nextDouble ( ) ) ; } } public static void main ( String args [ ] ) { input ( ) ; for ( int i = 0 ; i < maxT . size ( ) ; i ++ ) { double max = maxT . get ( i ) ; if ( max >= 35 ) count1 ++ ; else if ( max >= 30 ) count2 ++ ; else if ( max >= 25 ) count3 ++ ; else if ( max < 0 ) count6 ++ ; double min = minT . get ( i ) ; if ( min >= 25 ) count4 ++ ; else if ( min < 0 && max >= 0 ) count5 ++ ; } System . out . println ( count1 + \" β \" + count2 + \" β \" + count3 + \" β \" + count4 + \" β \" + count5 + \" β \" + count6 ) ; } }",
"import java . util . Iterator ; import java . util . PrimitiveIterator ; import java . util . Scanner ; class Main { public static void main ( String [ ] $ ) { int a = 0 , b = 0 , c = 0 , d = 0 , e = 0 , f = 0 ; for ( int v : new Range ( gInt ( ) ) ) { double high = s . nextDouble ( ) , low = s . nextDouble ( ) ; if ( high >= 35 ) ++ a ; if ( 35 > high && high >= 30 ) ++ b ; if ( 30 > high && high >= 25 ) ++ c ; if ( low >= 25 ) ++ d ; if ( low < 0 && high >= 0 ) ++ e ; if ( high < 0 ) ++ f ; } System . out . println ( a + \" β \" + b + \" β \" + c + \" β \" + d + \" β \" + e + \" β \" + f ) ; } static Scanner s = new Scanner ( System . in ) ; static int gInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } static long gLong ( ) { return Long . parseLong ( s . next ( ) ) ; } static class Range implements Iterable < Integer > , PrimitiveIterator . OfInt { int from , to , c ; Range ( int from , int to ) { this . from = from ; this . to = to ; this . c = from ; } Range ( int n ) { this ( 0 , n - 1 ) ; } @ Override public Iterator < Integer > iterator ( ) { return this ; } @ Override public boolean hasNext ( ) { return c <= to ; } @ Override public int nextInt ( ) { return c ++ ; } } }",
"public class Main { public static void main ( String [ ] args ) { java . util . Scanner sc = new java . util . Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double mLT1 [ ] = new double [ N ] ; double mST1 [ ] = new double [ N ] ; int c1 = 0 ; int c2 = 0 ; int c3 = 0 ; int c4 = 0 ; int c5 = 0 ; int c6 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { mLT1 [ i ] = sc . nextDouble ( ) ; mST1 [ i ] = sc . nextDouble ( ) ; if ( 35 <= mLT1 [ i ] ) { c1 ++ ; } if ( 30 <= mLT1 [ i ] & mLT1 [ i ] < 35 ) { c2 ++ ; } if ( 25 <= mLT1 [ i ] & mLT1 [ i ] < 30 ) { c3 ++ ; } if ( 25 <= mST1 [ i ] ) { c4 ++ ; } if ( 0 <= mLT1 [ i ] & mST1 [ i ] < 0 ) { c5 ++ ; } if ( mLT1 [ i ] < 0 ) { c6 ++ ; } } System . out . println ( c1 + \" β \" + c2 + \" β \" + c3 + \" β \" + c4 + \" β \" + c5 + \" β \" + c6 ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int ans [ ] = new int [ 6 ] ; int N = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { double high = sc . nextDouble ( ) ; double low = sc . nextDouble ( ) ; if ( high >= 35 ) { ans [ 0 ] ++ ; } else if ( high >= 30 && high < 35 ) { ans [ 1 ] ++ ; } else if ( high >= 25 && high < 30 ) { ans [ 2 ] ++ ; } if ( low >= 25 ) { ans [ 3 ] ++ ; } if ( low < 0 && high >= 0 ) { ans [ 4 ] ++ ; } if ( high < 0 ) { ans [ 5 ] ++ ; } } for ( int i = 0 ; i < 6 ; i ++ ) { if ( i > 0 ) { System . out . print ( \" β \" ) ; } System . out . print ( ans [ i ] ) ; } System . out . println ( ) ; } }",
"import java . util . * ; public class Main { private static ArrayList < Double > maxT = new ArrayList < > ( ) ; private static ArrayList < Double > minT = new ArrayList < > ( ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int ans [ ] = new int [ 6 ] ; for ( int i = 0 ; i < N ; i ++ ) { double max = sc . nextDouble ( ) ; double min = sc . nextDouble ( ) ; maxT . add ( max ) ; minT . add ( min ) ; } for ( int i = 0 ; i < N ; i ++ ) { double max = maxT . get ( i ) ; if ( max >= 35 ) { ans [ 0 ] ++ ; } else if ( max >= 30 ) { ans [ 1 ] ++ ; } else if ( max >= 25 ) { ans [ 2 ] ++ ; } else if ( max < 0 ) { ans [ 5 ] ++ ; } double min = minT . get ( i ) ; if ( min >= 25 ) { ans [ 3 ] ++ ; } else if ( min < 0 && max >= 0 ) { ans [ 4 ] ++ ; } } System . out . println ( ans [ 0 ] + \" β \" + ans [ 1 ] + \" β \" + ans [ 2 ] + \" β \" + ans [ 3 ] + \" β \" + ans [ 4 ] + \" β \" + ans [ 5 ] ) ; } }"
] | [
"n = int ( input ( ) ) NEW_LINE l = [ 0 for _ in range ( 6 ) ] NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a , b = map ( float , input ( ) . split ( ) ) NEW_LINE if a >= 35 : NEW_LINE INDENT l [ 0 ] += 1 NEW_LINE DEDENT elif a >= 30 : NEW_LINE INDENT l [ 1 ] += 1 NEW_LINE DEDENT elif a >= 25 : NEW_LINE INDENT l [ 2 ] += 1 NEW_LINE DEDENT if b >= 25 : NEW_LINE INDENT l [ 3 ] += 1 NEW_LINE DEDENT if b < 0 <= a : NEW_LINE INDENT l [ 4 ] += 1 NEW_LINE DEDENT if a < 0 : NEW_LINE INDENT l [ 5 ] += 1 NEW_LINE DEDENT DEDENT print ( \" β \" . join ( list ( map ( str , l ) ) ) ) NEW_LINE",
"def b_days ( N , Observations ) : NEW_LINE INDENT from collections import OrderedDict NEW_LINE weather_forecast = OrderedDict ( ) NEW_LINE weather_forecast [ ' mousho ' ] = 0 NEW_LINE weather_forecast [ ' manatsu ' ] = 0 NEW_LINE weather_forecast [ ' natsu ' ] = 0 NEW_LINE weather_forecast [ ' nettaiya ' ] = 0 NEW_LINE weather_forecast [ ' fuyu ' ] = 0 NEW_LINE weather_forecast [ ' mafuyu ' ] = 0 NEW_LINE for highest_temp , lowest_temp in Observations : NEW_LINE INDENT if ' . ' in highest_temp : NEW_LINE INDENT highest_temp = int ( highest_temp . replace ( ' . ' , ' ' ) ) NEW_LINE DEDENT else : NEW_LINE INDENT highest_temp = int ( highest_temp ) * 10 NEW_LINE DEDENT if ' . ' in lowest_temp : NEW_LINE INDENT lowest_temp = int ( lowest_temp . replace ( ' . ' , ' ' ) ) NEW_LINE DEDENT else : NEW_LINE INDENT lowest_temp = int ( lowest_temp ) * 10 NEW_LINE DEDENT if highest_temp >= 350 : NEW_LINE INDENT weather_forecast [ ' mousho ' ] += 1 NEW_LINE DEDENT elif 300 <= highest_temp < 350 : NEW_LINE INDENT weather_forecast [ ' manatsu ' ] += 1 NEW_LINE DEDENT elif 250 <= highest_temp < 300 : NEW_LINE INDENT weather_forecast [ ' natsu ' ] += 1 NEW_LINE DEDENT if lowest_temp >= 250 : NEW_LINE INDENT weather_forecast [ ' nettaiya ' ] += 1 NEW_LINE DEDENT if highest_temp >= 0 and lowest_temp < 0 : NEW_LINE INDENT weather_forecast [ ' fuyu ' ] += 1 NEW_LINE DEDENT if highest_temp < 0 : NEW_LINE INDENT weather_forecast [ ' mafuyu ' ] += 1 NEW_LINE DEDENT DEDENT ans = ' β ' . join ( map ( str , weather_forecast . values ( ) ) ) NEW_LINE return ans NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE Observations = [ input ( ) . split ( ) for j in range ( N ) ] NEW_LINE print ( b_days ( N , Observations ) ) NEW_LINE",
"d1 = d2 = d3 = d4 = d5 = d6 = 0 NEW_LINE for _ in range ( int ( input ( ) ) ) : NEW_LINE INDENT ma , mi = map ( float , input ( ) . split ( ) ) NEW_LINE if ma < 0 : d6 += 1 NEW_LINE elif 35 <= ma : d1 += 1 NEW_LINE elif 30 <= ma < 35 : d2 += 1 NEW_LINE elif 25 <= ma < 30 : d3 += 1 NEW_LINE if 25 <= mi : d4 += 1 NEW_LINE if mi < 0 and 0 <= ma : d5 += 1 NEW_LINE DEDENT print ( d1 , d2 , d3 , d4 , d5 , d6 ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE a = [ 0 , 0 , 0 , 0 , 0 , 0 ] NEW_LINE for x in range ( n ) : NEW_LINE INDENT maxx , minn = map ( float , input ( ) . split ( ' β ' ) ) NEW_LINE if ( maxx >= 35 ) : NEW_LINE INDENT a [ 0 ] = a [ 0 ] + 1 NEW_LINE DEDENT if ( maxx >= 30 and maxx < 35 ) : NEW_LINE INDENT a [ 1 ] = a [ 1 ] + 1 NEW_LINE DEDENT if ( maxx >= 25 and maxx < 30 ) : NEW_LINE INDENT a [ 2 ] = a [ 2 ] + 1 NEW_LINE DEDENT if ( minn >= 25 ) : NEW_LINE INDENT a [ 3 ] = a [ 3 ] + 1 NEW_LINE DEDENT if ( maxx >= 0 and minn < 0 ) : NEW_LINE INDENT a [ 4 ] = a [ 4 ] + 1 NEW_LINE DEDENT if ( maxx < 0 ) : NEW_LINE INDENT a [ 5 ] = a [ 5 ] + 1 NEW_LINE DEDENT DEDENT print ( \" % d β % d β % d β % d β % d β % d \" % ( a [ 0 ] , a [ 1 ] , a [ 2 ] , a [ 3 ] , a [ 4 ] , a [ 5 ] ) ) NEW_LINE",
"def b_days ( N , Observations ) : NEW_LINE INDENT day_mousho , day_manatsu , day_natsu , day_nettai , day_fuyu , day_mafuyu = 0 , 0 , 0 , 0 , 0 , 0 NEW_LINE for highest_temp , lowest_temp in Observations : NEW_LINE INDENT if ' . ' in highest_temp : NEW_LINE INDENT highest_temp = int ( highest_temp . replace ( ' . ' , ' ' ) ) NEW_LINE DEDENT else : NEW_LINE INDENT highest_temp = int ( highest_temp ) * 10 NEW_LINE DEDENT if ' . ' in lowest_temp : NEW_LINE INDENT lowest_temp = int ( lowest_temp . replace ( ' . ' , ' ' ) ) NEW_LINE DEDENT else : NEW_LINE INDENT lowest_temp = int ( lowest_temp ) * 10 NEW_LINE DEDENT if highest_temp >= 350 : NEW_LINE INDENT day_mousho += 1 NEW_LINE DEDENT elif 300 <= highest_temp < 350 : NEW_LINE INDENT day_manatsu += 1 NEW_LINE DEDENT elif 250 <= highest_temp < 300 : NEW_LINE INDENT day_natsu += 1 NEW_LINE DEDENT if lowest_temp >= 250 : NEW_LINE INDENT day_nettai += 1 NEW_LINE DEDENT if lowest_temp < 0 and highest_temp >= 0 : NEW_LINE INDENT day_fuyu += 1 NEW_LINE DEDENT if highest_temp < 0 : NEW_LINE INDENT day_mafuyu += 1 NEW_LINE DEDENT DEDENT ans = ' β ' . join ( map ( str , [ day_mousho , day_manatsu , day_natsu , day_nettai , day_fuyu , day_mafuyu ] ) ) NEW_LINE return ans NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE Observations = [ [ i for i in input ( ) . split ( ) ] for j in range ( N ) ] NEW_LINE print ( b_days ( N , Observations ) ) NEW_LINE"
] |
atcoder_abc006_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; if ( x % 3 == 0 ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } }",
"import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { PrintWriter out = new PrintWriter ( System . out ) ; InputStreamScanner in = new InputStreamScanner ( System . in ) ; new Main ( ) . solve ( in , out ) ; out . flush ( ) ; } private void solve ( InputStreamScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( ( n % 3 == 0 ) ? \" YES \" : \" NO \" ) ; } static class InputStreamScanner { private InputStream in ; private byte [ ] buf = new byte [ 1024 ] ; private int len = 0 ; private int off = 0 ; InputStreamScanner ( InputStream in ) { this . in = in ; } String next ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int b = skip ( ) ; ! isSpace ( b ) ; ) { sb . appendCodePoint ( b ) ; b = read ( ) ; } return sb . toString ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } char nextChar ( ) { return ( char ) skip ( ) ; } int skip ( ) { for ( int b ; ( b = read ( ) ) != - 1 ; ) { if ( ! isSpace ( b ) ) { return b ; } } return - 1 ; } private boolean isSpace ( int c ) { return c < 33 || c > 126 ; } private int read ( ) { if ( len == - 1 ) { throw new InputMismatchException ( \" End β of β Input \" ) ; } if ( off >= len ) { off = 0 ; try { len = in . read ( buf ) ; } catch ( IOException e ) { throw new InputMismatchException ( e . getMessage ( ) ) ; } if ( len <= 0 ) { return - 1 ; } } return buf [ off ++ ] ; } } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) ; out . println ( n % 3 == 0 || String . valueOf ( n ) . contains ( \"3\" ) ? \" YES \" : \" NO \" ) ; } }",
"import java . util . * ; import java . util . List ; import java . util . ArrayList ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; String SplitN [ ] = Integer . toString ( N ) . split ( \" \" ) ; if ( Arrays . asList ( SplitN ) . contains ( \"3\" ) || N % 3 == 0 ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; scanner . close ( ) ; String msg = \" NO \" ; if ( n == 3 || n % 3 == 0 ) { msg = \" YES \" ; } System . out . println ( msg ) ; } }"
] | [
"N = input ( ) NEW_LINE for i in range ( len ( N ) ) : NEW_LINE INDENT if N [ i ] == 3 : NEW_LINE INDENT ans = True NEW_LINE DEDENT elif int ( N ) % 3 == 0 : NEW_LINE INDENT ans = True NEW_LINE DEDENT else : ans = False NEW_LINE DEDENT if ans == True : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT",
"print ( ' YES ' if input ( ) in '369' else ' NO ' ) NEW_LINE",
"class Calculator : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT pass NEW_LINE DEDENT def set_num ( self , x ) : NEW_LINE INDENT self . x = x NEW_LINE DEDENT def get_judgement ( self ) : NEW_LINE INDENT self . judge = False NEW_LINE if \"3\" in str ( self . x ) or self . x % 3 == 0 : NEW_LINE INDENT self . judge = True NEW_LINE DEDENT return self . judge NEW_LINE DEDENT DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT n , = map ( int , input ( ) . split ( ) ) NEW_LINE c = Calculator ( ) NEW_LINE c . set_num ( n ) NEW_LINE if c . get_judgement ( ) : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT DEDENT",
"N = input ( ) NEW_LINE f = False NEW_LINE for i in N : NEW_LINE INDENT if i == '3' : NEW_LINE INDENT f = True NEW_LINE DEDENT DEDENT if int ( N ) % 3 == 0 : NEW_LINE INDENT f = True NEW_LINE DEDENT if f : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT",
"n = int ( input ( ) ) NEW_LINE print ( \" YES \" ) if n % 3 == 0 and n != 0 else print ( \" NO \" ) NEW_LINE"
] |
atcoder_arc081_C | [
"import java . util . * ; public class Main { public void main ( Scanner sc ) { char a [ ] = sc . next ( ) . toCharArray ( ) ; int len = a . length ; Map < Character , TreeSet < Integer > > map = new HashMap < > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { map . putIfAbsent ( a [ i ] , new TreeSet < > ( ) ) ; map . get ( a [ i ] ) . add ( i + 1 ) ; } int data [ ] = new int [ len + 1 ] ; BitSet bset = new BitSet ( ) ; data [ len ] = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { bset . set ( a [ i ] - ' a ' ) ; data [ i ] = data [ i + 1 ] ; if ( bset . cardinality ( ) == 26 ) { bset . clear ( ) ; data [ i ] ++ ; } } int p = 0 ; int ansLen = data [ 0 ] + 1 ; char ans [ ] = new char [ ansLen ] ; for ( int i = 0 ; i < ansLen ; i ++ ) { for ( char c = ' a ' ; c <= ' z ' ; c ++ ) { if ( ! map . containsKey ( c ) ) { ans [ i ] = c ; p = len + 1 ; break ; } else { Integer next = map . get ( c ) . higher ( p ) ; if ( next == null || ( data [ p ] - data [ next ] == 1 ) ) { ans [ i ] = c ; p = getOrDefault ( next , len + 1 ) ; break ; } } } } System . out . println ( new String ( ans ) ) ; } private int getOrDefault ( Integer n , int def ) { return n == null ? def : n ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int n = s . length ( ) ; int [ ] [ ] table = new int [ n / 26 + 1 ] [ 26 ] ; int [ ] [ ] table2 = new int [ n / 26 + 1 ] [ 26 ] ; for ( int i = 0 ; i < table . length ; i ++ ) Arrays . fill ( table [ i ] , - 1 ) ; int res = 0 ; int index = n - 1 ; int count = 0 ; for ( ; index >= 0 ; index -- ) { int c = ( int ) ( s . charAt ( index ) - ' a ' ) ; table2 [ res ] [ c ] = index ; if ( table [ res ] [ c ] != - 1 ) continue ; table [ res ] [ c ] = index ; count ++ ; if ( count == 26 ) { res ++ ; count = 0 ; } } int [ ] str = new int [ res + 1 ] ; for ( int i = res ; i >= 0 ; i -- ) { int pre = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( table [ i ] [ j ] != - 1 ) continue ; pre = j ; break ; } str [ res - i ] = pre ; if ( i > 0 ) { int min = table2 [ i - 1 ] [ pre ] ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( table [ i - 1 ] [ j ] <= min ) table [ i - 1 ] [ j ] = - 1 ; } } } for ( int i = 0 ; i < res + 1 ; i ++ ) System . out . print ( ( char ) ( ' a ' + str [ i ] ) ) ; System . out . println ( ) ; } }"
] | [
"abc = \" abcdefghijklmnopqrstuvwxyz \" NEW_LINE A = str ( input ( ) ) NEW_LINE n = len ( A ) NEW_LINE word_pos = [ ] NEW_LINE ct = [ n ] * 26 NEW_LINE orda = ord ( \" a \" ) NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT ct [ ord ( A [ i ] ) - orda ] = i NEW_LINE word_pos . append ( ct . copy ( ) ) NEW_LINE DEDENT word_pos . reverse ( ) NEW_LINE dp = [ 0 ] * n + [ 1 , 0 ] NEW_LINE j = n NEW_LINE sep = [ ] NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT ct = word_pos [ i ] NEW_LINE if ( max ( ct ) < j ) : NEW_LINE INDENT sep . append ( i ) NEW_LINE j = min ( ct ) NEW_LINE DEDENT DEDENT if ( j == n ) : NEW_LINE INDENT for i in abc : NEW_LINE INDENT if ( i not in A ) : NEW_LINE INDENT print ( i + \" \\n \" ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT sep . reverse ( ) NEW_LINE ans = \" \" NEW_LINE for i in abc : NEW_LINE INDENT if ( i not in A [ : sep [ 0 ] ] ) : NEW_LINE INDENT ans += i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( 0 , len ( sep ) ) : NEW_LINE INDENT start = sep [ i ] NEW_LINE try : NEW_LINE INDENT end = sep [ i + 1 ] NEW_LINE DEDENT except : NEW_LINE INDENT end = n NEW_LINE DEDENT next = word_pos [ start ] [ ord ( ans [ - 1 ] ) - orda ] NEW_LINE for i in range ( 0 , 26 ) : NEW_LINE INDENT if ( word_pos [ next + 1 ] [ i ] > end - 1 ) : NEW_LINE INDENT ans += chr ( orda + i ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT ans += \" \\n \" NEW_LINE print ( ans ) NEW_LINE DEDENT",
"import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE gosa = 1.0 / 10 ** 10 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 I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT a = S ( ) NEW_LINE l = len ( a ) NEW_LINE t = { } NEW_LINE for c in string . ascii_lowercase : NEW_LINE INDENT t [ c ] = l NEW_LINE DEDENT b = [ ( 1 , 0 , 0 ) for _ in range ( l ) ] NEW_LINE b . append ( ( 1 , ' a ' , l ) ) NEW_LINE b . append ( ( 0 , ' ' , l + 1 ) ) NEW_LINE for c , i in reversed ( list ( zip ( a , range ( l ) ) ) ) : NEW_LINE INDENT t [ c ] = i NEW_LINE b [ i ] = min ( [ ( b [ t [ d ] + 1 ] [ 0 ] + 1 , d , t [ d ] + 1 ) for d in string . ascii_lowercase ] ) NEW_LINE DEDENT r = ' ' NEW_LINE i = 0 NEW_LINE while i < l : NEW_LINE INDENT r += b [ i ] [ 1 ] NEW_LINE i = b [ i ] [ 2 ] NEW_LINE DEDENT return r NEW_LINE DEDENT print ( main ( ) ) NEW_LINE",
"ord_a = ord ( ' a ' ) NEW_LINE L = 26 NEW_LINE S = list ( map ( lambda c : ord ( c ) - ord_a , input ( ) ) ) NEW_LINE memo = [ ] NEW_LINE f = [ 0 ] * L NEW_LINE cnt = 0 NEW_LINE for i , s in zip ( reversed ( range ( len ( S ) ) ) , reversed ( S ) ) : NEW_LINE INDENT cnt += ( f [ s ] == 0 ) NEW_LINE f [ s ] += 1 NEW_LINE if cnt == L : NEW_LINE INDENT memo . append ( ( i , f ) ) NEW_LINE f = [ 0 ] * L NEW_LINE cnt = 0 NEW_LINE DEDENT DEDENT result = [ f . index ( 0 ) ] NEW_LINE for i , f in reversed ( memo ) : NEW_LINE INDENT c = result [ - 1 ] NEW_LINE for j in range ( i , len ( S ) ) : NEW_LINE INDENT s = S [ j ] NEW_LINE f [ s ] -= 1 NEW_LINE if s == c : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT result . append ( f . index ( 0 ) ) NEW_LINE DEDENT print ( ' ' . join ( map ( lambda x : chr ( x + ord_a ) , result ) ) ) NEW_LINE",
"from bisect import bisect_left NEW_LINE CHARACTERs = ' abcdefghijklmnopqrstuvwxyz ' NEW_LINE As = input ( ) NEW_LINE lenA = len ( As ) NEW_LINE posChars = dict ( [ ( ch , [ lenA ] ) for ch in CHARACTERs ] ) NEW_LINE dp = [ 0 ] * lenA + [ 1 , 0 ] NEW_LINE for i in reversed ( range ( lenA ) ) : NEW_LINE INDENT posChars [ As [ i ] ] . append ( i ) NEW_LINE dp [ i ] = min ( [ dp [ posChars [ ch ] [ - 1 ] + 1 ] for ch in CHARACTERs ] ) + 1 NEW_LINE DEDENT for ch in CHARACTERs : NEW_LINE INDENT posChars [ ch ] = posChars [ ch ] [ : : - 1 ] NEW_LINE DEDENT ans = [ ] NEW_LINE i = 0 NEW_LINE for k in reversed ( range ( dp [ 0 ] ) ) : NEW_LINE INDENT for ch in CHARACTERs : NEW_LINE INDENT pos = posChars [ ch ] [ bisect_left ( posChars [ ch ] , i ) ] NEW_LINE if dp [ pos + 1 ] == k : NEW_LINE INDENT ans . append ( ch ) NEW_LINE i = pos + 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( ' ' . join ( ans ) ) NEW_LINE",
"A = input ( ) NEW_LINE import string NEW_LINE p = { } NEW_LINE for x in string . ascii_lowercase : p [ x ] = len ( A ) NEW_LINE tb = [ ( 0 , 0 , 0 ) ] * len ( A ) NEW_LINE tb . append ( ( 1 , 0 , 0 ) ) NEW_LINE tb . append ( ( 0 , 0 , 0 ) ) NEW_LINE for i , x in reversed ( list ( enumerate ( A ) ) ) : NEW_LINE INDENT p [ x ] = i NEW_LINE tb [ i ] = min ( [ ( tb [ p [ c ] + 1 ] [ 0 ] + 1 , c , p [ c ] + 1 ) for c in string . ascii_lowercase ] ) NEW_LINE DEDENT i = 0 NEW_LINE ans = [ ] NEW_LINE while i < len ( A ) : NEW_LINE INDENT ans . append ( tb [ i ] [ 1 ] ) NEW_LINE i = tb [ i ] [ 2 ] NEW_LINE DEDENT print ( \" \" . join ( ans ) ) NEW_LINE"
] |
atcoder_abc050_B | [
"import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; int [ ] problems = new int [ n ] ; int sum = 0 ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { problems [ i ] = Integer . parseInt ( tokenizer . nextToken ( ) ) ; sum += problems [ i ] ; } StringBuilder out = new StringBuilder ( ) ; int m = Integer . parseInt ( input . readLine ( ) ) ; for ( int i = 0 ; i < m ; i ++ ) { tokenizer = new StringTokenizer ( input . readLine ( ) ) ; out . append ( ( sum - problems [ Integer . parseInt ( tokenizer . nextToken ( ) ) - 1 ] ) + Integer . parseInt ( tokenizer . nextToken ( ) ) ) . append ( \" \\n \" ) ; } System . out . print ( out ) ; } }",
"import java . io . InputStream ; import java . io . IOException ; class MyScanner { InputStream stream ; public MyScanner ( ) { stream = System . in ; } public int nextInt ( ) { int ret = 0 ; try { while ( true ) { char readed = ( char ) stream . read ( ) ; if ( readed < '0' || readed > '9' ) { break ; } ret = ret * 10 + ( readed - '0' ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { return ret ; } } } class Main { public static void main ( String args [ ] ) { MyScanner sc = new MyScanner ( ) ; int n = sc . nextInt ( ) ; int [ ] t = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { t [ i ] = sc . nextInt ( ) ; sum += t [ i ] ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; ++ i ) { int p , x ; p = sc . nextInt ( ) - 1 ; x = sc . nextInt ( ) ; System . out . println ( sum - t [ p ] + x ) ; } } }",
"import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String probCount = scanner . nextLine ( ) ; String [ ] timesList = scanner . nextLine ( ) . split ( \" β \" ) ; Integer drinkCount = new Integer ( scanner . nextLine ( ) ) ; IntStream . range ( 0 , drinkCount ) . forEach ( i -> { String [ ] pair = scanner . nextLine ( ) . split ( \" β \" ) ; Integer nProb = new Integer ( pair [ 0 ] ) ; String nTime = pair [ 1 ] ; String [ ] copiedList = new String [ timesList . length ] ; System . arraycopy ( timesList , 0 , copiedList , 0 , timesList . length ) ; copiedList [ nProb - 1 ] = nTime ; System . out . println ( addTimes ( copiedList ) ) ; } ) ; } private static Integer addTimes ( String [ ] timesList ) { Integer sum = 0 ; for ( int i = 0 ; i < timesList . length ; i ++ ) { sum = sum + new Integer ( timesList [ i ] ) ; } return sum ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] T = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) T [ i ] = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] P = new int [ M ] ; int [ ] X = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { P [ i ] = sc . nextInt ( ) ; X [ i ] = sc . nextInt ( ) ; } int sumTime = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sumTime += T [ i ] ; } for ( int i = 0 ; i < M ; i ++ ) { int ans = sumTime - ( T [ P [ i ] - 1 ] - X [ i ] ) ; System . out . println ( ans ) ; } } }",
"import java . util . Scanner ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . nextLine ( ) ; String line = sc . nextLine ( ) ; int M = sc . nextInt ( ) ; String [ ] lineArray = line . split ( \" β \" , 0 ) ; int [ ] T = new int [ N ] ; int [ ] P = new int [ M ] ; int [ ] X = new int [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { T [ i ] = Integer . parseInt ( lineArray [ i ] ) ; } for ( int i = 0 ; i < M ; i ++ ) { P [ i ] = sc . nextInt ( ) ; X [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < M ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( P [ i ] - 1 == j ) { sum += X [ i ] ; } else { sum += T [ j ] ; } } System . out . println ( sum ) ; } } }"
] | [
"n = int ( input ( ) ) NEW_LINE T = [ int ( t ) for t in input ( ) . split ( ) ] NEW_LINE m = int ( input ( ) ) NEW_LINE drinks = [ ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT p , x = map ( int , input ( ) . split ( ) ) NEW_LINE drinks . append ( [ p , x ] ) NEW_LINE DEDENT for drink in drinks : NEW_LINE INDENT diff = T [ drink [ 0 ] - 1 ] - drink [ 1 ] NEW_LINE print ( sum ( T ) - diff ) NEW_LINE DEDENT",
"import sys , re NEW_LINE from collections import deque , defaultdict , Counter NEW_LINE from math import ceil , sqrt , hypot , factorial , pi , sin , cos , radians NEW_LINE from itertools import permutations , combinations , product NEW_LINE from operator import itemgetter , mul NEW_LINE from copy import deepcopy NEW_LINE from string import ascii_lowercase , ascii_uppercase , digits NEW_LINE def input ( ) : return sys . stdin . readline ( ) . strip ( ) NEW_LINE def INT ( ) : return int ( input ( ) ) NEW_LINE def MAP ( ) : return map ( int , input ( ) . split ( ) ) NEW_LINE def LIST ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE N = INT ( ) NEW_LINE T = LIST ( ) NEW_LINE M = INT ( ) NEW_LINE PX = [ LIST ( ) for _ in range ( M ) ] NEW_LINE for p , x in PX : NEW_LINE INDENT tmp = T . copy ( ) NEW_LINE T [ p - 1 ] = x NEW_LINE print ( sum ( T ) ) NEW_LINE T = tmp NEW_LINE DEDENT",
"n = int ( input ( ) ) NEW_LINE t = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE m = int ( input ( ) ) NEW_LINE px = [ ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT p , x = map ( int , input ( ) . split ( ) ) NEW_LINE px . append ( [ p , x ] ) NEW_LINE DEDENT for i in range ( m ) : NEW_LINE INDENT time = 0 NEW_LINE for j in range ( n ) : NEW_LINE INDENT if j + 1 == px [ i ] [ 0 ] : NEW_LINE INDENT time += px [ i ] [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT time += t [ j ] NEW_LINE DEDENT DEDENT print ( time ) NEW_LINE DEDENT",
"I = lambda : map ( int , input ( ) . split ( ) ) NEW_LINE N = int ( input ( ) ) NEW_LINE T = list ( I ( ) ) NEW_LINE M = int ( input ( ) ) NEW_LINE ans = [ sum ( T ) ] * M NEW_LINE for i in range ( M ) : NEW_LINE INDENT p , x = I ( ) NEW_LINE ans [ i ] = ans [ i ] - T [ p - 1 ] + x NEW_LINE DEDENT print ( ' \\n ' . join ( map ( str , ans ) ) ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE t = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE s = sum ( t ) NEW_LINE m = int ( input ( ) ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE print ( s - t [ a - 1 ] + b ) NEW_LINE DEDENT"
] |
atcoder_abc053_A | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; System . out . println ( sc . nextInt ( ) < 1200 ? \" ABC \" : \" ARC \" ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int x = in . nextInt ( ) ; out . println ( x < 1200 ? \" ABC \" : \" ARC \" ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( in . nextInt ( ) < 1200 ? \" ABC \" : \" ARC \" ) ; } } 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 ; } 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 isSpaceChar ( int c ) { return c == ' β ' || c == ' \\n ' || c == ' \\r ' || c == ' \\t ' || c == - 1 ; } public long nextLong ( ) { long n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } public int nextInt ( ) { long n = nextLong ( ) ; if ( n < Integer . MIN_VALUE || n > Integer . MAX_VALUE ) throw new NumberFormatException ( ) ; return ( int ) n ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean ans = false ; if ( 1200 <= n ) ans = true ; sc . close ( ) ; System . out . println ( ans ? \" ARC \" : \" ABC \" ) ; } }",
"import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; System . out . println ( n < 1200 ? \" ABC \" : \" ARC \" ) ; } }"
] | [
"print ( ' ABC ' if int ( input ( ) ) < 1200 else ' ARC ' ) NEW_LINE",
"from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT a = int ( input ( ) . rstrip ( ) ) NEW_LINE if a >= 1200 : NEW_LINE INDENT print ( ' ARC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' ABC ' ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"def abc_arc ( x : int ) -> str : NEW_LINE INDENT return ' ABC ' if x < 1200 else ' ARC ' NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT x = int ( input ( ) ) NEW_LINE ans = abc_arc ( x ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"from sys import stdin NEW_LINE n = int ( stdin . readline ( ) . rstrip ( ) ) NEW_LINE if n < 1200 : NEW_LINE INDENT print ( ' ABC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' ARC ' ) NEW_LINE DEDENT",
"x = int ( input ( ) ) NEW_LINE print ( \" ABC \" if x < 1200 else \" ARC \" ) NEW_LINE"
] |
atcoder_abc120_B | [
"import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; int max = Math . max ( A , B ) ; for ( int i = 1 ; i <= max ; i ++ ) { if ( A % i == 0 && B % i == 0 ) { list . add ( new Integer ( i ) ) ; } } System . out . println ( list . get ( list . size ( ) - K ) ) ; } }",
"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 ) ; BKThCommonDivisor solver = new BKThCommonDivisor ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BKThCommonDivisor { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; int K = in . nextInt ( ) ; int res = solve ( A , B , K ) ; out . println ( res ) ; } private int solve ( int a , int b , int K ) { int cur = 0 ; for ( int i = 101 ; i >= 1 ; i -- ) { if ( a % i == 0 && b % i == 0 ) { cur ++ ; if ( cur == K ) return i ; } } throw new RuntimeException ( \" Impossible \" ) ; } } }",
"import java . math . BigDecimal ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; int a = Integer . parseInt ( sc . next ( ) ) ; int b = Integer . parseInt ( sc . next ( ) ) ; int c = Integer . parseInt ( sc . next ( ) ) ; int count = 0 ; if ( a < b ) { for ( int i = 0 ; i < a ; i ++ ) { int d = i + 1 ; if ( a % d == 0 && b % d == 0 ) { list . add ( d ) ; } } } else { for ( int i = 0 ; i < b ; i ++ ) { int d = i + 1 ; if ( a % d == 0 && b % d == 0 ) { list . add ( d ) ; } } } System . out . println ( list . get ( list . size ( ) - c ) ) ; System . out . flush ( ) ; sc . close ( ) ; } }",
"import java . util . ArrayList ; import java . util . Collections ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; Main abc120B = new Main ( ) ; System . out . println ( abc120B . solve ( A , B , K ) ) ; } public int solve ( int A , int B , int K ) { ABC120BSolve abc120BSolve = new ABC120BSolve ( A , B ) ; return abc120BSolve . solve ( K ) ; } class ABC120BSolve { List < Integer > D ; public ABC120BSolve ( int A , int B ) { Set < Integer > divB = divisors ( new HashSet ( ) , B ) ; List < Integer > divAList = new ArrayList ( divisors ( new HashSet ( ) , A ) ) ; Collections . sort ( divAList , Collections . reverseOrder ( ) ) ; D = new ArrayList ( ) ; for ( int a : divAList ) { if ( divB . contains ( a ) ) { D . add ( a ) ; } } } public int solve ( int k ) { if ( this . D . size ( ) >= k ) { return this . D . get ( k - 1 ) ; } else { return - 1 ; } } private Set < Integer > divisors ( Set < Integer > ans , int n ) { for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { ans . add ( i ) ; ans . add ( n / i ) ; } } return ans ; } } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .",
"import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; String [ ] ABK = str . split ( \" β \" ) ; int cont = 0 ; for ( int i = Math . min ( Integer . parseInt ( ABK [ 0 ] ) , Integer . parseInt ( ABK [ 1 ] ) ) ; i > 0 ; i -- ) { if ( Integer . parseInt ( ABK [ 0 ] ) % i == 0 && Integer . parseInt ( ABK [ 1 ] ) % i == 0 ) { cont ++ ; if ( cont == Integer . parseInt ( ABK [ 2 ] ) ) { System . out . println ( i ) ; return ; } } } } }"
] | [
"A , B , K = map ( int , input ( ) . split ( ) ) NEW_LINE List = [ x for x in range ( min ( A , B ) , 0 , - 1 ) if A % x == 0 and B % x == 0 ] NEW_LINE print ( List [ K - 1 ] ) NEW_LINE",
"m = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = m [ 0 ] NEW_LINE b = m [ 1 ] NEW_LINE k = m [ 2 ] NEW_LINE c = min ( a , b ) NEW_LINE d = 0 NEW_LINE e = 0 NEW_LINE for i in range ( c ) : NEW_LINE INDENT if ( a % ( c - i ) == 0 and b % ( c - i ) == 0 ) : NEW_LINE INDENT d += 1 NEW_LINE DEDENT if ( d == k ) : NEW_LINE INDENT e = c - i NEW_LINE break NEW_LINE DEDENT DEDENT print ( e ) NEW_LINE",
"a , b , k = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE def f ( s , l , k ) : NEW_LINE INDENT numbers = [ ] NEW_LINE for i in range ( 1 , s + 1 ) : NEW_LINE INDENT if s % i == 0 and l % i == 0 : NEW_LINE INDENT numbers . append ( i ) NEW_LINE DEDENT DEDENT print ( numbers [ - k ] ) NEW_LINE DEDENT if a > b : NEW_LINE INDENT f ( b , a , k ) NEW_LINE DEDENT else : NEW_LINE INDENT f ( a , b , k ) NEW_LINE DEDENT",
"a , b , k = map ( int , input ( ) . split ( ) ) NEW_LINE c = min ( a , b ) NEW_LINE count = 0 NEW_LINE for i in reversed ( range ( 1 , c + 1 ) ) : NEW_LINE INDENT if a % i == 0 and b % i == 0 : NEW_LINE INDENT count += 1 NEW_LINE if k == count : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT DEDENT DEDENT",
"import numpy as np NEW_LINE a , b , k = map ( int , input ( ) . split ( ) ) NEW_LINE c = np . array ( list ( range ( 1 , min ( a , b ) + 1 ) ) ) NEW_LINE e = [ f for f , g in enumerate ( zip ( a % c , b % c ) ) if g == ( 0 , 0 ) ] NEW_LINE print ( c [ e [ - k ] ] ) NEW_LINE"
] |
atcoder_arc019_B | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; if ( s . length ( ) == 1 ) { System . out . println ( 0 ) ; return ; } boolean flag = true ; int total = 0 ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( s . length ( ) - i - 1 ) ) { count ++ ; flag = false ; } } if ( flag ) { if ( s . length ( ) % 2 == 1 ) { total = 25 * ( s . length ( ) - 1 ) ; } else { total = 25 * s . length ( ) ; } } else if ( count == 1 ) { total = 25 * s . length ( ) - 2 ; } else { total = 25 * s . length ( ) ; } System . out . println ( total ) ; } }",
"import java . util . * ; public class Main { private static String s ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; s = scan . next ( ) ; } public static void main ( String args [ ] ) { input ( ) ; int N = s . length ( ) ; int count = 0 ; for ( int i = 0 ; i < N / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( N - i - 1 ) ) count ++ ; } int ans = 0 ; if ( count == 0 ) { if ( N % 2 == 1 ) { ans = 25 * N - 25 ; } else { ans = 25 * N ; } } else if ( count == 1 ) { ans = 25 * N - 2 ; } else if ( count >= 2 ) { ans = 25 * N ; } System . out . println ( ans ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( s . length ( ) - 1 - i ) ) { count ++ ; } } int sum = 0 ; if ( count == 0 ) { if ( s . length ( ) == 1 ) { sum = 0 ; } else if ( s . length ( ) % 2 == 1 ) { sum = 25 * ( s . length ( ) - 1 ) ; } else { sum = 25 * s . length ( ) ; } } else if ( count == 1 ) { sum = 25 * s . length ( ) - 2 ; } else { sum = 25 * s . length ( ) ; } System . out . println ( sum ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String A = sc . next ( ) ; int N = A . length ( ) ; int count = 0 ; for ( int i = 0 ; i < N / 2 ; i ++ ) { if ( A . charAt ( i ) != A . charAt ( N - i - 1 ) ) count ++ ; } int ans = 0 ; if ( count == 0 ) { if ( N % 2 == 1 ) { ans = 25 * N - 25 ; } else { ans = 25 * N ; } } else if ( count == 1 ) { ans = 25 * N - 2 ; } else if ( count >= 2 ) { ans = 25 * N ; } System . out . println ( ans ) ; } }"
] | [
"s = input ( ) NEW_LINE n = len ( s ) NEW_LINE l = [ True if s [ i ] == s [ - i - 1 ] else False for i in range ( n // 2 ) ] NEW_LINE print ( 25 * ( n - n % 2 ) if all ( l ) else 25 * n - 2 if n // 2 - sum ( l ) == 1 else 25 * n ) NEW_LINE",
"import numpy as np NEW_LINE def is_palindrome ( ) : NEW_LINE INDENT return A == A [ : : - 1 ] NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT l = len ( A ) NEW_LINE if l == 1 : NEW_LINE INDENT print ( 0 ) NEW_LINE return NEW_LINE DEDENT if is_palindrome ( ) : NEW_LINE INDENT if l % 2 == 0 : NEW_LINE INDENT print ( l * 25 ) NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( l - 1 ) * 25 ) NEW_LINE return NEW_LINE DEDENT DEDENT a_l = A [ : l // 2 ] NEW_LINE a_r = A [ l - l // 2 : ] [ : : - 1 ] NEW_LINE a_l2 = np . array ( list ( a_l ) ) NEW_LINE a_r2 = np . array ( list ( a_r ) ) NEW_LINE d_num = ( a_l2 != a_r2 ) . sum ( ) NEW_LINE if d_num == 1 : NEW_LINE INDENT print ( ( l - 2 ) * 25 + 2 * 24 ) NEW_LINE return NEW_LINE DEDENT print ( l * 25 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = input ( ) NEW_LINE main ( ) NEW_LINE DEDENT",
"def count_diff_ch ( s ) : NEW_LINE INDENT count = 0 NEW_LINE length = len ( s ) NEW_LINE for i in range ( 0 , length // 2 ) : NEW_LINE INDENT if s [ i ] != s [ length - i - 1 ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT s = input ( ) NEW_LINE c = count_diff_ch ( s ) NEW_LINE ans = len ( s ) * 25 NEW_LINE parity = len ( s ) % 2 NEW_LINE if c == 0 : NEW_LINE INDENT ans -= parity * 25 NEW_LINE DEDENT elif c == 1 : NEW_LINE INDENT ans -= 2 NEW_LINE DEDENT print ( ans ) NEW_LINE",
"a = list ( input ( ) ) NEW_LINE n = len ( a ) NEW_LINE if n == 1 : NEW_LINE INDENT print ( 0 ) NEW_LINE exit ( ) NEW_LINE DEDENT res = 0 NEW_LINE if n % 2 == 1 : NEW_LINE INDENT k = n // 2 NEW_LINE judge = True NEW_LINE for i in range ( k ) : NEW_LINE INDENT if a [ i ] != a [ n - 1 - i ] : NEW_LINE INDENT judge = False NEW_LINE break NEW_LINE DEDENT DEDENT if judge : NEW_LINE INDENT res = 0 NEW_LINE DEDENT else : NEW_LINE INDENT res = 25 NEW_LINE DEDENT a = a [ : k : ] + a [ k + 1 : : ] NEW_LINE n -= 1 NEW_LINE DEDENT d = 0 NEW_LINE k = n // 2 NEW_LINE for i in range ( k ) : NEW_LINE INDENT if a [ i ] != a [ n - 1 - i ] : NEW_LINE INDENT d += 1 NEW_LINE DEDENT DEDENT for i in range ( k ) : NEW_LINE INDENT if d >= 2 : NEW_LINE INDENT res += 50 NEW_LINE DEDENT elif d == 1 : NEW_LINE INDENT if a [ i ] == a [ n - 1 - i ] : NEW_LINE INDENT res += 50 NEW_LINE DEDENT else : NEW_LINE INDENT res += 48 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT res += 50 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE",
"A = input ( ) NEW_LINE lenA = len ( A ) NEW_LINE A1 = A [ : lenA // 2 ] NEW_LINE A2 = A [ lenA - lenA // 2 : ] [ : : - 1 ] NEW_LINE if A1 == A2 : NEW_LINE INDENT if lenA % 2 == 0 : NEW_LINE INDENT print ( 25 * lenA ) NEW_LINE exit ( ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 25 * lenA - 25 ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT count = 0 NEW_LINE for i , z in zip ( A1 , A2 ) : NEW_LINE INDENT if i != z : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if count == 1 : NEW_LINE INDENT print ( ( lenA - 2 ) * 25 + 24 * 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( lenA * 25 ) NEW_LINE DEDENT"
] |
atcoder_abc046_B | [
"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 ( ) ; System . out . println ( k * ( int ) Math . pow ( k - 1 , n - 1 ) ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { int n = 0 ; int k = 0 ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String [ ] tmp = br . readLine ( ) . split ( \" \\\\ s \" ) ; n = Integer . parseInt ( tmp [ 0 ] ) ; k = Integer . parseInt ( tmp [ 1 ] ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } long quotient = k ; quotient *= ( long ) Math . pow ( k - 1 , n - 1 ) ; System . out . print ( quotient ) ; } }",
"import java . util . * ; import java . util . stream . IntStream ; public class Main { public static boolean found = false ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long ans = k ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans *= ( k - 1 ) ; } System . out . println ( ans ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int n = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int k = Integer . parseInt ( tokenizer . nextToken ( ) ) ; BigInteger bigDecimal = BigInteger . valueOf ( k ) ; for ( int i = 1 ; i < n ; i ++ ) { bigDecimal = bigDecimal . multiply ( BigInteger . valueOf ( k - 1 ) ) ; } System . out . println ( bigDecimal ) ; } }",
"import java . math . BigDecimal ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; System . out . println ( BigDecimal . valueOf ( K ) . multiply ( BigDecimal . valueOf ( K - 1 ) . pow ( N - 1 ) ) ) ; } }"
] | [
"N , K = map ( int , input ( ) . split ( ) ) NEW_LINE print ( K * ( K - 1 ) ** ( N - 1 ) ) NEW_LINE",
"def painting_balls_with_atcodeer ( N : int , K : int ) -> int : NEW_LINE INDENT return K * ( ( K - 1 ) ** ( N - 1 ) ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE ans = painting_balls_with_atcodeer ( N , K ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"N , K = map ( int , input ( ) . split ( ' β ' ) ) NEW_LINE res = K NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT res *= K - 1 NEW_LINE DEDENT print ( res ) NEW_LINE",
"a = [ int ( n ) for n in input ( ) . split ( ) ] NEW_LINE if a [ 0 ] == 1 : NEW_LINE INDENT print ( a [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a [ 1 ] * ( a [ 1 ] - 1 ) ** ( a [ 0 ] - 1 ) ) NEW_LINE DEDENT",
"N , K = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE a = K * ( ( K - 1 ) ** ( N - 1 ) ) NEW_LINE print ( a ) NEW_LINE"
] |
atcoder_abc008_B | [
"import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; ArrayList < String > names = new ArrayList < String > ( ) ; ArrayList < String > votes = new ArrayList < String > ( ) ; for ( int i = 0 ; i <= n ; i ++ ) { String name = scanner . nextLine ( ) ; if ( ! names . contains ( name ) ) { names . add ( name ) ; } votes . add ( name ) ; } scanner . close ( ) ; String mostName = \" \" ; int mostNum = 0 ; for ( String name : names ) { int count = 0 ; for ( String vote : votes ) { if ( vote . equals ( name ) ) { count ++ ; } if ( count >= mostNum ) { mostName = name ; mostNum = count ; } } } System . out . println ( mostName ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; String [ ] S = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { S [ i ] = in . next ( ) ; } int count ; int max = 0 ; String ans = \" \" ; for ( int i = 0 ; i < N ; i ++ ) { count = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( S [ i ] . equals ( S [ j ] ) ) { count ++ ; } } if ( count > max ) { max = count ; ans = S [ i ] ; } } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; if ( map . containsKey ( s ) ) { map . put ( s , map . get ( s ) + 1 ) ; } else { map . put ( s , 1 ) ; } } Pair ans = new Pair ( \" \" , 0 ) ; for ( Map . Entry < String , Integer > ele : map . entrySet ( ) ) { if ( ans . count < ele . getValue ( ) ) { ans = new Pair ( ele . getKey ( ) , ele . getValue ( ) ) ; } } System . out . println ( ans . name ) ; } static class Pair { String name ; int count ; public Pair ( String name , int count ) { this . name = name ; this . count = count ; } } }",
"import java . util . * ; import java . util . Map . Entry ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S [ ] = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { S [ i ] = sc . next ( ) ; } Map < String , Integer > m = new HashMap < String , Integer > ( ) ; for ( String s : S ) { int v ; if ( m . containsKey ( s ) ) { v = m . get ( s ) + 1 ; } else { v = 1 ; } m . put ( s , v ) ; } List < Entry < String , Integer > > list_entries = new ArrayList < Entry < String , Integer > > ( m . entrySet ( ) ) ; Collections . sort ( list_entries , new Comparator < Entry < String , Integer > > ( ) { public int compare ( Entry < String , Integer > obj1 , Entry < String , Integer > obj2 ) { return obj2 . getValue ( ) . compareTo ( obj1 . getValue ( ) ) ; } } ) ; System . out . println ( list_entries . get ( 0 ) . getKey ( ) ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] bodies = new String [ sc . nextInt ( ) ] ; int [ ] voted = new int [ bodies . length ] ; String temp ; int lastElement = 0 ; flag : for ( int i = 0 ; i < bodies . length ; i ++ ) { temp = sc . next ( ) ; try { for ( int j = 0 ; j < bodies . length ; j ++ ) { if ( bodies [ j ] . equals ( temp ) ) { voted [ j ] ++ ; continue flag ; } } } catch ( NullPointerException e ) { bodies [ lastElement ] = temp ; voted [ lastElement ] ++ ; lastElement ++ ; } } int mostVoted = 0 ; int mostVotedBody = 0 ; for ( int i = 0 ; i < voted . length ; i ++ ) { if ( voted [ i ] > mostVoted ) { mostVoted = voted [ i ] ; mostVotedBody = i ; } } System . out . println ( bodies [ mostVotedBody ] ) ; } }"
] | [
"from collections import Counter NEW_LINE n = int ( input ( ) ) NEW_LINE s = [ input ( ) for _ in range ( n ) ] NEW_LINE c = Counter ( s ) NEW_LINE ans = ' ' NEW_LINE t = 0 NEW_LINE for x , y in c . items ( ) : NEW_LINE INDENT if y > t : NEW_LINE INDENT t = y NEW_LINE ans = x NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"_ , * s = open ( 0 ) ; print ( max ( s , key = s . count ) [ : - 1 ] ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE dic = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT tmp = input ( ) NEW_LINE if tmp in dic . keys ( ) : NEW_LINE INDENT dic [ tmp ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic [ tmp ] = 1 NEW_LINE DEDENT DEDENT for name in dic . keys ( ) : NEW_LINE INDENT if dic [ name ] == max ( dic . values ( ) ) : NEW_LINE INDENT print ( name ) NEW_LINE break NEW_LINE DEDENT DEDENT",
"n = int ( input ( ) ) NEW_LINE s = [ input ( ) for i in range ( n ) ] NEW_LINE res = 0 NEW_LINE temp = 0 NEW_LINE for i in set ( s ) : NEW_LINE INDENT temp = 0 NEW_LINE for j in s : NEW_LINE INDENT if i == j : NEW_LINE INDENT temp += 1 NEW_LINE DEDENT DEDENT res = max ( res , temp ) NEW_LINE DEDENT for i in set ( s ) : NEW_LINE INDENT if s . count ( i ) == res : NEW_LINE INDENT print ( i ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT",
"n = int ( input ( ) ) NEW_LINE hoge = [ ] NEW_LINE ans_name = \" hoge \" NEW_LINE ans_coun = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT hoge . append ( input ( ) ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( hoge . count ( hoge [ i ] ) >= ans_coun ) : NEW_LINE INDENT ans_name = hoge [ i ] NEW_LINE ans_coun = hoge . count ( hoge [ i ] ) NEW_LINE DEDENT DEDENT print ( ans_name ) NEW_LINE"
] |
atcoder_abc112_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int minCost = 1001 ; for ( int i = 0 ; i < n ; i ++ ) { int cost = sc . nextInt ( ) ; int time = sc . nextInt ( ) ; if ( t >= time ) { if ( minCost > cost ) minCost = cost ; } } if ( minCost == 1001 ) System . out . println ( \" TLE \" ) ; else System . out . println ( minCost ) ; } }",
"import java . util . ArrayList ; import java . util . List ; import java . util . Optional ; import java . util . Scanner ; public class Main { private static final String TLE = \" TLE \" ; public static String process ( TestCase testCase ) { final int N = testCase . N ; final int T = testCase . T ; final List < Integer > c = testCase . c ; final List < Integer > t = testCase . t ; Optional < Integer > minCost = Optional . empty ( ) ; for ( int i = 0 ; i < N ; ++ i ) { final int cost = c . get ( i ) ; final int time = t . get ( i ) ; if ( time <= T ) { if ( minCost . isPresent ( ) ) { minCost = minCost . map ( curr -> Math . min ( curr , cost ) ) ; } else { minCost = Optional . of ( cost ) ; } } } return minCost . map ( String :: valueOf ) . orElse ( TLE ) ; } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; List < Integer > c = new ArrayList < > ( ) ; List < Integer > t = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { c . add ( sc . nextInt ( ) ) ; t . add ( sc . nextInt ( ) ) ; } return new TestCase ( N , T , c , t ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final int N ; final int T ; final List < Integer > c ; final List < Integer > t ; public TestCase ( int N , int T , List < Integer > c , List < Integer > t ) { this . N = N ; this . T = T ; this . c = c ; this . t = t ; } } }",
"import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int t = Integer . parseInt ( sc . next ( ) ) ; Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int c = Integer . parseInt ( sc . next ( ) ) ; int time = Integer . parseInt ( sc . next ( ) ) ; if ( time <= t ) { map . put ( c , time ) ; } } int min = Integer . MAX_VALUE ; for ( Map . Entry < Integer , Integer > entry : map . entrySet ( ) ) { min = Math . min ( entry . getKey ( ) , min ) ; } System . out . println ( min == Integer . MAX_VALUE ? \" TLE \" : min ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int min = 10000000 ; while ( N -- > 0 ) { int c = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; if ( t <= T && c < min ) { min = c ; } } System . out . println ( min == 10000000 ? \" TLE \" : min ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int [ ] hairetu1 = new int [ N ] ; int [ ] hairetu2 = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { hairetu1 [ i ] = sc . nextInt ( ) ; hairetu2 [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( hairetu2 [ i ] <= T ) { count ++ ; } } if ( count == 0 ) { System . out . println ( \" TLE \" ) ; System . exit ( 0 ) ; } int z = 0 ; int [ ] hairetu3 = new int [ count ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( hairetu2 [ i ] <= T ) { hairetu3 [ z ] = hairetu1 [ i ] ; z ++ ; } } int min = hairetu3 [ 0 ] ; for ( int i = 0 ; i < count ; i ++ ) { if ( min > hairetu3 [ i ] ) { min = hairetu3 [ i ] ; } } System . out . println ( min ) ; } }"
] | [
"import sys NEW_LINE import copy NEW_LINE from bisect import bisect_left NEW_LINE def main ( ) : NEW_LINE INDENT N , T = map ( int , input ( ) . split ( \" β \" ) ) NEW_LINE CT = [ ] NEW_LINE isOK = False NEW_LINE for _ in range ( N ) : NEW_LINE INDENT c , t = map ( int , input ( ) . split ( \" β \" ) ) NEW_LINE if t <= T : NEW_LINE INDENT isOK = True NEW_LINE CT . append ( ( c , t ) ) NEW_LINE DEDENT DEDENT if isOK == False : NEW_LINE INDENT print ( \" TLE \" ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT CT . sort ( ) NEW_LINE c , t = CT [ 0 ] NEW_LINE print ( c ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"N , T = [ int ( elem ) for elem in input ( ) . split ( ) ] NEW_LINE min_cost = None NEW_LINE min_cost_time = None NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT c , t = [ int ( elem ) for elem in input ( ) . split ( ) ] NEW_LINE if t <= T : NEW_LINE INDENT if min_cost is None : NEW_LINE INDENT min_cost = c NEW_LINE min_cost_time = t NEW_LINE DEDENT else : NEW_LINE INDENT if c < min_cost : NEW_LINE INDENT min_cost = c NEW_LINE min_cost_time = t NEW_LINE DEDENT DEDENT DEDENT DEDENT if min_cost is None : NEW_LINE INDENT print ( ' TLE ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( min_cost ) NEW_LINE DEDENT",
"N , T = map ( int , input ( ) . split ( ) ) NEW_LINE m = min ( [ c if t <= T else 9999 for c , t in [ map ( int , input ( ) . split ( ) ) for _ in range ( N ) ] ] ) NEW_LINE print ( \" TLE \" if m == 9999 else m ) NEW_LINE",
"import sys NEW_LINE def solve ( N : int , T : int , c : \" List [ int ] \" , t : \" List [ int ] \" ) : NEW_LINE INDENT ret = float ( ' inf ' ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if t [ i ] <= T : NEW_LINE INDENT ret = min ( ret , c [ i ] ) NEW_LINE DEDENT DEDENT if ret == float ( ' inf ' ) : NEW_LINE INDENT print ( ' TLE ' ) NEW_LINE DEDENT else : NEW_LINE INDENT 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 N = int ( next ( tokens ) ) NEW_LINE T = int ( next ( tokens ) ) NEW_LINE c = [ int ( ) ] * ( N ) NEW_LINE t = [ int ( ) ] * ( N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT c [ i ] = int ( next ( tokens ) ) NEW_LINE t [ i ] = int ( next ( tokens ) ) NEW_LINE DEDENT solve ( N , T , c , t ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"import sys NEW_LINE ans = sys . maxsize NEW_LINE N , T = map ( int , input ( ) . split ( ) ) NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT c , t = map ( int , input ( ) . split ( ) ) NEW_LINE if t <= T : NEW_LINE INDENT ans = min ( ans , c ) NEW_LINE DEDENT DEDENT if ans == sys . maxsize : NEW_LINE INDENT print ( \" TLE \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ans ) NEW_LINE DEDENT"
] |
atcoder_abc004_C | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] arr = new String [ 6 ] ; arr [ 0 ] = \"1\" ; arr [ 1 ] = \"2\" ; arr [ 2 ] = \"3\" ; arr [ 3 ] = \"4\" ; arr [ 4 ] = \"5\" ; arr [ 5 ] = \"6\" ; String r = \" \" ; int c = N % 30 ; for ( int i = 0 ; i < c ; i ++ ) { r = arr [ ( i % 5 ) ] ; arr [ ( i % 5 ) ] = arr [ ( i % 5 ) + 1 ] ; arr [ ( i % 5 ) + 1 ] = r ; } System . out . println ( arr [ 0 ] + arr [ 1 ] + arr [ 2 ] + arr [ 3 ] + arr [ 4 ] + arr [ 5 ] ) ; } }",
"import java . util . * ; public class Main { static int num [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = sc . nextInt ( ) % 30 ; for ( int i = 0 ; i < count ; i ++ ) { replace ( i ) ; } for ( int i = 0 ; i < 6 ; i ++ ) { System . out . print ( num [ i ] ) ; } System . out . println ( ) ; } public static void replace ( int a ) { a %= 5 ; int tmp = num [ a ] ; num [ a ] = num [ a + 1 ] ; num [ a + 1 ] = tmp ; } }",
"import java . io . InputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Main { InputStream in = System . in ; PrintStream out = System . out ; private static void swap ( int [ ] a , int i ) { int tmp = a [ i ] ; a [ i ] = a [ i + 1 ] ; a [ i + 1 ] = tmp ; } public void _main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int [ ] c = { 1 , 2 , 3 , 4 , 5 , 6 } ; n %= 30 ; for ( int i = 0 ; i < n ; i ++ ) { swap ( c , i % 5 ) ; } for ( int x : c ) { out . print ( x ) ; } out . println ( ) ; sc . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Map < Integer , String > map = new HashMap < > ( ) ; StringBuilder str = new StringBuilder ( \"123456\" ) ; for ( int i = 0 ; i < 30 ; i ++ ) { map . put ( i , str . toString ( ) ) ; int x = i % 5 ; int y = x + 1 ; char tmp = str . charAt ( x ) ; str . setCharAt ( x , str . charAt ( y ) ) ; str . setCharAt ( y , tmp ) ; } Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) % 30 ; System . out . println ( map . get ( n ) ) ; } }",
"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 ( ) ; N %= 30 ; int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; for ( int i = 0 ; i < N ; i ++ ) { int j1 = i % 5 ; int j2 = i % 5 + 1 ; int tmp = arr [ j1 ] ; arr [ j1 ] = arr [ j2 ] ; arr [ j2 ] = tmp ; } StringBuilder builder = new StringBuilder ( ) ; for ( int num : arr ) { builder . append ( num ) ; } out . println ( builder . toString ( ) ) ; } }"
] | [
"import re NEW_LINE n = int ( input ( ) ) NEW_LINE card = [ i + 1 for i in range ( 6 ) ] NEW_LINE for i in range ( n % 30 ) : NEW_LINE INDENT card [ ( i % 5 ) ] , card [ ( i % 5 ) + 1 ] = card [ ( i % 5 ) + 1 ] , card [ ( i % 5 ) ] NEW_LINE DEDENT print ( re . sub ( r ' \\D ' , ' ' , str ( card ) ) ) NEW_LINE",
"card = list ( range ( 1 , 7 ) ) NEW_LINE N = int ( input ( ) ) % 30 NEW_LINE for i in range ( N ) : NEW_LINE INDENT tmp = card [ i % 5 ] NEW_LINE card [ i % 5 ] = card [ ( i % 5 ) + 1 ] NEW_LINE card [ ( i % 5 ) + 1 ] = tmp NEW_LINE DEDENT for i in range ( 6 ) : NEW_LINE INDENT print ( card [ i ] , end = \" \" ) NEW_LINE DEDENT",
"import math NEW_LINE N = int ( input ( ) ) NEW_LINE MovingCardNum = math . floor ( N / 5 ) % 6 + 1 NEW_LINE List = list ( range ( MovingCardNum + 1 , 7 ) ) + list ( range ( 1 , MovingCardNum + 1 ) ) NEW_LINE idx = N % 5 NEW_LINE List [ ( idx + 1 ) : 6 ] = List [ idx : 5 ] NEW_LINE List [ idx ] = MovingCardNum NEW_LINE print ( ' ' . join ( [ str ( x ) for x in List ] ) ) NEW_LINE",
"N = int ( input ( ) ) % 30 NEW_LINE card = [ '1' , '2' , '3' , '4' , '5' , '6' ] NEW_LINE def sort ( Card , n ) : NEW_LINE INDENT tmp = n // 5 NEW_LINE idx = n % 5 NEW_LINE for i in range ( tmp ) : NEW_LINE INDENT Card . append ( Card . pop ( 0 ) ) NEW_LINE DEDENT Card . insert ( idx , Card . pop ( 0 ) ) NEW_LINE print ( ' ' . join ( Card ) ) NEW_LINE DEDENT sort ( card , N ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE N = n % 30 NEW_LINE I = N // 5 NEW_LINE i = N % 5 NEW_LINE number = [ [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 2 , 3 , 4 , 5 , 6 , 1 ] , [ 3 , 4 , 5 , 6 , 1 , 2 ] , [ 4 , 5 , 6 , 1 , 2 , 3 ] , [ 5 , 6 , 1 , 2 , 3 , 4 ] , [ 6 , 1 , 2 , 3 , 4 , 5 ] ] NEW_LINE for s in range ( 0 , i ) : NEW_LINE INDENT number [ I ] [ s ] , number [ I ] [ s + 1 ] = number [ I ] [ s + 1 ] , number [ I ] [ s ] NEW_LINE DEDENT number_str = \" \" NEW_LINE for t in number [ I ] : NEW_LINE INDENT number_str += str ( t ) NEW_LINE DEDENT print ( number_str ) NEW_LINE"
] |
atcoder_agc012_B | [
"import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] a = new int [ M ] ; int [ ] b = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { a [ i ] = sc . nextInt ( ) - 1 ; b [ i ] = sc . nextInt ( ) - 1 ; } int MAXD = 10 ; int [ ] [ ] dp = new int [ N ] [ MAXD + 1 ] ; int Q = sc . nextInt ( ) ; int [ ] c = new int [ Q + 1 ] ; for ( int i = 0 ; i < Q ; i ++ ) { int v = sc . nextInt ( ) - 1 ; int d = sc . nextInt ( ) ; c [ i + 1 ] = sc . nextInt ( ) ; dp [ v ] [ d ] = Math . max ( dp [ v ] [ d ] , i + 1 ) ; } for ( int i = MAXD ; i > 0 ; i -- ) { for ( int j = 0 ; j < M ; j ++ ) { dp [ a [ j ] ] [ i - 1 ] = Math . max ( dp [ a [ j ] ] [ i - 1 ] , dp [ b [ j ] ] [ i ] ) ; dp [ b [ j ] ] [ i - 1 ] = Math . max ( dp [ b [ j ] ] [ i - 1 ] , dp [ a [ j ] ] [ i ] ) ; } for ( int j = 0 ; j < N ; j ++ ) { dp [ j ] [ i - 1 ] = Math . max ( dp [ j ] [ i - 1 ] , dp [ j ] [ i ] ) ; } } for ( int i = 0 ; i < N ; i ++ ) pw . println ( c [ dp [ i ] [ 0 ] ] ) ; sc . close ( ) ; pw . close ( ) ; } }"
] | [
"from collections import defaultdict NEW_LINE def paint ( v , d , c ) : NEW_LINE INDENT if color [ v ] == 0 : NEW_LINE INDENT color [ v ] = c NEW_LINE DEDENT if dp [ v ] >= d or d == 0 : NEW_LINE INDENT return NEW_LINE DEDENT dp [ v ] = d NEW_LINE for nb in graph [ v ] : NEW_LINE INDENT paint ( nb , d - 1 , c ) NEW_LINE DEDENT DEDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE dp = [ 0 ] * N NEW_LINE color = [ 0 ] * N NEW_LINE graph = defaultdict ( set ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT i , j = map ( int , input ( ) . split ( ) ) NEW_LINE graph [ i - 1 ] . add ( j - 1 ) NEW_LINE graph [ j - 1 ] . add ( i - 1 ) NEW_LINE DEDENT Q = int ( input ( ) ) NEW_LINE vdcs = [ ] NEW_LINE for _ in range ( Q ) : NEW_LINE INDENT v , d , c = map ( int , input ( ) . split ( ) ) NEW_LINE vdcs . append ( ( v - 1 , d , c ) ) NEW_LINE DEDENT vdcs . reverse ( ) NEW_LINE for v , d , c in vdcs : NEW_LINE INDENT paint ( v , d , c ) NEW_LINE DEDENT for c in color : NEW_LINE INDENT print ( c ) NEW_LINE DEDENT",
"import sys NEW_LINE sys . setrecursionlimit ( 100000 ) NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE node = [ [ ] for i in range ( n + 1 ) ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE node [ a ] . append ( b ) NEW_LINE node [ b ] . append ( a ) NEW_LINE DEDENT q = int ( input ( ) ) NEW_LINE vdc = [ [ 0 ] * 3 for i in range ( q ) ] NEW_LINE for i in range ( q ) : NEW_LINE INDENT vdc [ i ] [ 0 ] , vdc [ i ] [ 1 ] , vdc [ i ] [ 2 ] = map ( int , input ( ) . split ( ) ) NEW_LINE DEDENT vdc = vdc [ : : - 1 ] NEW_LINE ans = [ 0 ] * ( n + 1 ) NEW_LINE visited = [ [ 0 ] * 11 for i in range ( n + 1 ) ] NEW_LINE def f ( v , d , c ) : NEW_LINE INDENT if d < 0 : NEW_LINE INDENT return NEW_LINE DEDENT if visited [ v ] [ d ] : NEW_LINE INDENT return NEW_LINE DEDENT visited [ v ] [ d ] = 1 NEW_LINE if ans [ v ] == 0 : NEW_LINE INDENT ans [ v ] = c NEW_LINE DEDENT for x in node [ v ] : NEW_LINE INDENT f ( x , d - 1 , c ) NEW_LINE DEDENT DEDENT for v , d , c in vdc : NEW_LINE INDENT f ( v , d , c ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( ans [ i + 1 ] ) NEW_LINE DEDENT",
"import sys , math , copy NEW_LINE HUGE = 2147483647 NEW_LINE HUGEL = 9223372036854775807 NEW_LINE ABC = \" abcdefghijklmnopqrstuvwxyz \" NEW_LINE MAX = 100001 NEW_LINE dp = [ 0 for i in range ( MAX ) ] NEW_LINE color = [ 0 for i in range ( MAX ) ] NEW_LINE e = [ [ ] for i in range ( MAX ) ] NEW_LINE def paint ( v , d , c ) : NEW_LINE INDENT if not color [ v ] : NEW_LINE INDENT color [ v ] = c NEW_LINE DEDENT if dp [ v ] >= d or d == 0 : NEW_LINE INDENT return NEW_LINE DEDENT dp [ v ] = d NEW_LINE for u in e [ v ] : NEW_LINE INDENT paint ( u , d - 1 , c ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE e [ a ] . append ( b ) NEW_LINE e [ b ] . append ( a ) NEW_LINE DEDENT q = int ( input ( ) ) NEW_LINE vq , dq , cq = [ ] , [ ] , [ ] NEW_LINE for i in range ( q ) : NEW_LINE INDENT v , d , c = map ( int , input ( ) . split ( ) ) NEW_LINE vq . append ( v ) NEW_LINE dq . append ( d ) NEW_LINE cq . append ( c ) NEW_LINE DEDENT assert len ( vq ) == len ( dq ) == len ( cq ) == q NEW_LINE for i in reversed ( range ( q ) ) : NEW_LINE INDENT paint ( vq [ i ] , dq [ i ] , cq [ i ] ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( color [ i + 1 ] ) NEW_LINE DEDENT DEDENT main ( ) NEW_LINE",
"import sys NEW_LINE def dfs ( v , d , c , e ) : NEW_LINE INDENT if ( dp [ v ] [ d ] != 0 ) : NEW_LINE INDENT return dp [ v ] [ d ] NEW_LINE DEDENT if ( d == 0 ) : NEW_LINE INDENT dp [ v ] [ d ] = c NEW_LINE return dp [ v ] [ d ] NEW_LINE DEDENT for u in e [ v ] : NEW_LINE INDENT dp [ u ] [ d - 1 ] = dfs ( u , d - 1 , c , e ) NEW_LINE DEDENT dp [ v ] [ d ] = dfs ( v , d - 1 , c , e ) NEW_LINE return dp [ v ] [ d ] NEW_LINE DEDENT stdin = sys . stdin NEW_LINE ns = lambda : stdin . readline ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE na = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) NEW_LINE dp = [ [ 0 ] * 11 for i in range ( 10 ** 5 + 1 ) ] NEW_LINE e = [ [ ] for i in range ( 10 ** 5 + 1 ) ] NEW_LINE N , M = na ( ) NEW_LINE for i in range ( M ) : NEW_LINE INDENT a , b = na ( ) NEW_LINE a -= 1 NEW_LINE b -= 1 NEW_LINE e [ a ] . append ( b ) NEW_LINE e [ b ] . append ( a ) NEW_LINE DEDENT Q = ni ( ) NEW_LINE qv = [ [ 0 , 0 , 0 ] for i in range ( Q ) ] NEW_LINE for i in range ( Q ) : NEW_LINE INDENT v , d , c = na ( ) NEW_LINE v -= 1 NEW_LINE qv [ Q - 1 - i ] [ 0 ] = v NEW_LINE qv [ Q - 1 - i ] [ 1 ] = d NEW_LINE qv [ Q - 1 - i ] [ 2 ] = c NEW_LINE DEDENT for i in range ( Q ) : NEW_LINE INDENT dfs ( qv [ i ] [ 0 ] , qv [ i ] [ 1 ] , qv [ i ] [ 2 ] , e ) NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT print ( dp [ i ] [ 0 ] ) NEW_LINE DEDENT",
"from collections import deque NEW_LINE from collections import defaultdict NEW_LINE G = defaultdict ( list ) NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE color = [ 0 ] * ( N + 1 ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE G [ a ] . append ( b ) NEW_LINE G [ b ] . append ( a ) NEW_LINE DEDENT Q = int ( input ( ) ) NEW_LINE data = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( Q ) ] NEW_LINE data . reverse ( ) NEW_LINE color_d = [ - 1 ] * ( N + 1 ) NEW_LINE for v , d , c in data : NEW_LINE INDENT if color_d [ v ] >= d : NEW_LINE INDENT pass NEW_LINE DEDENT deq = deque ( [ v ] ) NEW_LINE if color [ v ] == 0 : NEW_LINE INDENT color [ v ] = c NEW_LINE DEDENT color_d [ v ] = d NEW_LINE while len ( deq ) > 0 : NEW_LINE INDENT s = deq . popleft ( ) NEW_LINE for t in G [ s ] : NEW_LINE INDENT if color_d [ t ] >= color_d [ s ] - 1 : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT color_d [ t ] = color_d [ s ] - 1 NEW_LINE if color [ t ] == 0 : NEW_LINE INDENT color [ t ] = c NEW_LINE DEDENT if color_d [ t ] > 0 : NEW_LINE INDENT deq . append ( t ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT for n in range ( 1 , N + 1 ) : NEW_LINE INDENT print ( color [ n ] ) NEW_LINE DEDENT"
] |
atcoder_arc007_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] cdCase = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { cdCase [ i ] = i ; } for ( int i = 0 ; i < M ; i ++ ) { int disk = sc . nextInt ( ) ; int index = 0 ; for ( int j = 0 ; j < N + 1 ; j ++ ) { if ( cdCase [ j ] == disk ) { index = j ; break ; } } cdCase [ index ] = cdCase [ 0 ] ; cdCase [ 0 ] = disk ; } for ( int i = 1 ; i < N + 1 ; i ++ ) { System . out . println ( cdCase [ i ] ) ; } } }",
"import java . util . * ; public class Main { void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] arr = new int [ n + 1 ] ; int h = 0 ; for ( int i = 0 ; i < n + 1 ; i ++ ) arr [ i ] = i ; for ( int i = 0 ; i < m ; i ++ ) { int c = sc . nextInt ( ) ; int key = 0 ; for ( int j = 1 ; j < arr . length ; j ++ ) { if ( arr [ j ] == c ) { key = j ; int tmp = h ; h = arr [ key ] ; arr [ key ] = tmp ; break ; } } } for ( int i = 1 ; i < arr . length ; i ++ ) System . out . println ( arr [ i ] ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] strArray = br . readLine ( ) . split ( \" β \" ) ; int caseNum = Integer . parseInt ( strArray [ 0 ] ) ; int listenedCdNum = Integer . parseInt ( strArray [ 1 ] ) ; int listenDisk = 0 ; int [ ] cdCase = new int [ caseNum ] ; for ( int i = 1 ; i <= caseNum ; i ++ ) { cdCase [ i - 1 ] = i ; } for ( int i = 0 ; i < listenedCdNum ; i ++ ) { int disk = Integer . parseInt ( br . readLine ( ) ) ; for ( int j = 0 ; j < caseNum ; j ++ ) { if ( cdCase [ j ] == disk ) { cdCase [ j ] = listenDisk ; listenDisk = disk ; } } } for ( int diskNum : cdCase ) { System . out . println ( diskNum ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } void run ( ) { Scanner cin = new Scanner ( System . in ) ; int n = cin . nextInt ( ) ; int m = cin . nextInt ( ) ; int nowPlaying = 0 ; int [ ] CDCase = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) CDCase [ i ] = i + 1 ; for ( int i = 0 ; i < m ; i ++ ) { int targetCD = cin . nextInt ( ) ; int targetCase = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( CDCase [ j ] == targetCD ) { targetCase = j ; break ; } } if ( targetCase == - 1 ) continue ; CDCase [ targetCase ] = nowPlaying ; nowPlaying = targetCD ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( CDCase [ i ] ) ; } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] disks = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { disks [ i ] = i + 1 ; } int now = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int x = sc . nextInt ( ) ; if ( x == now ) { continue ; } for ( int j = 0 ; j < n ; j ++ ) { if ( disks [ j ] == x ) { disks [ j ] = now ; now = x ; break ; } } } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sb . append ( disks [ i ] ) . append ( \" \\n \" ) ; } System . out . print ( sb ) ; } }"
] | [
"N , M = map ( int , input ( ) . split ( ) ) NEW_LINE n_lis = [ i for i in range ( 1 , N + 1 ) ] NEW_LINE liscd = 0 NEW_LINE for _ in range ( M ) : NEW_LINE INDENT cd = int ( input ( ) ) NEW_LINE if cd in n_lis : NEW_LINE INDENT case = n_lis . index ( cd ) NEW_LINE n_lis [ case ] = liscd NEW_LINE liscd = cd NEW_LINE DEDENT DEDENT for c in n_lis : NEW_LINE INDENT print ( c ) NEW_LINE DEDENT",
"def b_cd_case ( N , M , Disk ) : NEW_LINE INDENT ans = list ( range ( N + 1 ) ) NEW_LINE for d in Disk : NEW_LINE INDENT ans [ ans . index ( d ) ] , ans [ 0 ] = ans [ 0 ] , ans [ ans . index ( d ) ] NEW_LINE DEDENT ans = ' \\n ' . join ( map ( str , ans [ 1 : ] ) ) NEW_LINE return ans NEW_LINE DEDENT N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE Disk = [ int ( input ( ) ) for _ in range ( M ) ] NEW_LINE print ( b_cd_case ( N , M , Disk ) ) NEW_LINE",
"inp1 = input ( ) NEW_LINE inp1 = inp1 . split ( ' β ' ) NEW_LINE inp1 [ 0 ] = int ( inp1 [ 0 ] ) NEW_LINE inp1 [ 1 ] = int ( inp1 [ 1 ] ) NEW_LINE case = [ x for x in range ( 0 , inp1 [ 0 ] + 1 ) ] NEW_LINE caselist = dict ( zip ( case , case ) ) NEW_LINE listening = 0 NEW_LINE count = 0 NEW_LINE while ( count < inp1 [ 1 ] ) : NEW_LINE INDENT inp2 = int ( input ( ) ) NEW_LINE caselist [ listening ] = caselist [ inp2 ] NEW_LINE caselist [ inp2 ] = 0 NEW_LINE listening = inp2 NEW_LINE count += 1 NEW_LINE DEDENT out = { y : x for x , y in caselist . items ( ) } NEW_LINE for x in range ( 1 , inp1 [ 0 ] + 1 ) : NEW_LINE INDENT print ( out [ x ] ) NEW_LINE DEDENT",
"from itertools import product NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N , M = inpl ( ) NEW_LINE where = list ( range ( 0 , N + 1 ) ) NEW_LINE now = 0 NEW_LINE for _ in range ( M ) : NEW_LINE INDENT disk = int ( input ( ) ) NEW_LINE where [ disk ] , where [ now ] = where [ now ] , where [ disk ] NEW_LINE now = disk NEW_LINE DEDENT answer = [ - 1 ] * ( N + 1 ) NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT answer [ where [ i ] ] = i NEW_LINE DEDENT print ( * answer [ 1 : ] , sep = \" \\n \" ) NEW_LINE",
"import sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE N , M = map ( int , input ( ) . rstrip ( ) . split ( ) ) NEW_LINE disk = [ int ( input ( ) ) for _ in range ( M ) ] NEW_LINE ans = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT ans [ i ] = i NEW_LINE DEDENT for x in disk : NEW_LINE INDENT pos = 0 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT if ans [ i ] == x : NEW_LINE INDENT pos = i NEW_LINE DEDENT DEDENT ans [ 0 ] , ans [ pos ] = ans [ pos ] , ans [ 0 ] NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT print ( ans [ i ] ) NEW_LINE DEDENT"
] |
atcoder_abc104_C | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . execute ( ) ; } public void execute ( ) { Scanner sc = new Scanner ( System . in ) ; final int D = sc . nextInt ( ) ; final int G = sc . nextInt ( ) / 100 ; int [ ] score = new int [ D ] ; int [ ] p = new int [ D ] ; int [ ] c = new int [ D ] ; for ( int i = 0 ; i < D ; i ++ ) { score [ i ] = i + 1 ; p [ i ] = sc . nextInt ( ) ; c [ i ] = sc . nextInt ( ) / 100 ; } int minTurns = Integer . MAX_VALUE ; for ( int mask = 0 , bound = ( 1 << D ) ; mask < bound ; mask ++ ) { int s = 0 ; int turns = 0 ; boolean [ ] ptn = getPatterns ( D , mask ) ; for ( int i = 0 ; i < D ; i ++ ) { if ( ptn [ i ] ) { s += p [ i ] * score [ i ] + c [ i ] ; turns += p [ i ] ; } } if ( s >= G ) { minTurns = Math . min ( minTurns , turns ) ; continue ; } for ( int i = ( D - 1 ) ; i >= 0 ; i -- ) { if ( ptn [ i ] ) { continue ; } for ( int j = 0 ; j < p [ i ] - 1 ; j ++ ) { s += score [ i ] ; turns ++ ; if ( s >= G ) { minTurns = Math . min ( minTurns , turns ) ; break ; } } } } System . out . println ( minTurns ) ; sc . close ( ) ; } private boolean [ ] getPatterns ( int d , int mask ) { boolean [ ] patterns = new boolean [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { if ( ( mask & ( 1 << i ) ) > 0 ) { patterns [ i ] = true ; } } return patterns ; } }",
"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 d = sc . nextInt ( ) ; int g = sc . nextInt ( ) ; int [ ] p = new int [ d + 1 ] ; int [ ] c = new int [ d + 1 ] ; for ( int i = 0 ; i < d ; i ++ ) { p [ i + 1 ] = sc . nextInt ( ) ; c [ i + 1 ] = sc . nextInt ( ) ; } int ans = 1000000000 ; for ( int i = 0 ; i < ( 1 << d ) ; i ++ ) { int temp = 0 ; long score = 0 ; for ( int j = 0 ; j < d ; j ++ ) { if ( ( 1 & ( i >> j ) ) == 1 ) { score += ( j + 1 ) * 100 * p [ j + 1 ] + c [ j + 1 ] ; temp += p [ j + 1 ] ; } } if ( score >= g ) { ans = min ( ans , temp ) ; } else { for ( int j = d - 1 ; j > - 1 ; j -- ) { if ( ( 1 & ( i >> j ) ) == 1 ) continue ; else { for ( int k = 1 ; k < p [ j + 1 ] ; k ++ ) { score += ( j + 1 ) * 100 ; temp += 1 ; if ( score >= g ) { ans = min ( ans , temp ) ; break ; } } break ; } } } } out . println ( ans ) ; } }",
"import java . util . Scanner ; public class Main { private static final int INF = 10000 ; private static int [ ] [ ] memo ; private static int solve ( int d , int g , int [ ] p , int [ ] c , int used ) { if ( memo [ g ] [ used ] != 0 ) return memo [ g ] [ used ] ; int res = INF ; for ( int i = 0 ; i < d ; i ++ ) { int bit = ( int ) Math . pow ( 2 , i ) ; if ( ( used / bit ) % 2 == 1 ) continue ; if ( ( i + 1 ) * ( p [ i ] - 1 ) >= g ) { res = Math . min ( res , ( int ) Math . ceil ( 1.0 * g / ( i + 1 ) ) ) ; } else if ( ( i + 1 ) * p [ i ] + c [ i ] >= g ) { res = Math . min ( res , p [ i ] ) ; } else { res = Math . min ( res , p [ i ] + solve ( d , g - ( ( i + 1 ) * p [ i ] + c [ i ] ) , p , c , used + bit ) ) ; } } memo [ g ] [ used ] = res ; return res ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) ; int g = sc . nextInt ( ) / 100 ; int [ ] p = new int [ d ] ; int [ ] c = new int [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { p [ i ] = sc . nextInt ( ) ; c [ i ] = sc . nextInt ( ) / 100 ; } memo = new int [ 105501 ] [ 1024 ] ; System . out . println ( solve ( d , g , p , c , 0 ) ) ; sc . close ( ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) ; int g = sc . nextInt ( ) ; Problem [ ] array = new Problem [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { array [ i ] = new Problem ( 100 * ( i + 1 ) , sc . nextInt ( ) , sc . nextInt ( ) ) ; } sc . close ( ) ; int ans = Integer . MAX_VALUE ; System . out . println ( dfs ( d , g , array , \" \" , ans ) ) ; } static class Problem { int p ; int c ; int total ; public Problem ( int s , int p , int c ) { this . p = p ; this . c = c ; this . total = s * p + c ; } } static int dfs ( int d , int g , Problem [ ] array , String select , int ans ) { if ( select . length ( ) == d ) { int total = 0 ; int cnt = 0 ; for ( int i = 0 ; i < d ; i ++ ) { if ( select . charAt ( i ) == '1' ) { total += array [ i ] . total ; cnt += array [ i ] . p ; } } if ( g <= total ) { return cnt ; } for ( int i = d - 1 ; i >= 0 ; i -- ) { if ( select . charAt ( i ) == '0' ) { double zanScore = g - total ; int zanCnt = ( int ) Math . ceil ( zanScore / ( 100 * ( i + 1 ) ) ) ; if ( zanCnt < array [ i ] . p ) { cnt += zanCnt ; } else { cnt = Integer . MAX_VALUE ; } break ; } } return cnt ; } ans = Math . min ( ans , dfs ( d , g , array , select + \"0\" , ans ) ) ; ans = Math . min ( ans , dfs ( d , g , array , select + \"1\" , ans ) ) ; return ans ; } }",
"public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int d = scanner . nextInt ( ) , g = scanner . nextInt ( ) ; int [ ] p = new int [ d ] , c = new int [ d ] ; for ( int i = 0 ; i < d ; i ++ ) { p [ i ] = scanner . nextInt ( ) ; c [ i ] = scanner . nextInt ( ) ; } int ans = 10000 ; for ( int i = 0 ; i < 1 << d ; i ++ ) { int sum = 0 , count = 0 , zero = 0 ; for ( int j = 0 ; j < d ; j ++ ) { if ( ( 1 << j & i ) != 0 ) { sum += ( j + 1 ) * 100 * p [ j ] + c [ j ] ; count += p [ j ] ; } else { zero = j ; } } if ( sum < g ) { int t = ( int ) Math . ceil ( ( g - sum ) / ( ( zero + 1 ) * 100F ) ) ; if ( p [ zero ] < t ) continue ; count += Math . ceil ( ( g - sum ) / ( ( zero + 1 ) * 100F ) ) ; } ans = Math . min ( ans , count ) ; } System . out . println ( ans ) ; } }"
] | [
"D , G = map ( int , input ( ) . split ( ) ) NEW_LINE p , c = { } , { } NEW_LINE for i in range ( 1 , D + 1 ) : NEW_LINE INDENT pi , ci = map ( int , input ( ) . split ( ) ) NEW_LINE p [ i ] = pi NEW_LINE c [ i ] = ci NEW_LINE DEDENT ans = sum ( p . values ( ) ) NEW_LINE for i in range ( 2 ** D ) : NEW_LINE INDENT cmp = { i : False for i in range ( 1 , D + 1 ) } NEW_LINE score = 0 NEW_LINE ans_tmp = 0 NEW_LINE for j in range ( D ) : NEW_LINE INDENT if ( i >> j ) & 1 : NEW_LINE INDENT cmp [ j + 1 ] = True NEW_LINE score += ( j + 1 ) * 100 * p [ j + 1 ] + c [ j + 1 ] NEW_LINE ans_tmp += p [ j + 1 ] NEW_LINE DEDENT DEDENT keys = [ k for k , v in cmp . items ( ) if v == False ] NEW_LINE if G > score and len ( keys ) > 0 : NEW_LINE INDENT if ( G - score ) // ( max ( keys ) * 100 ) <= p [ max ( keys ) ] : NEW_LINE INDENT ans_tmp += ( G - score ) // ( max ( keys ) * 100 ) NEW_LINE if ( G - score ) % ( max ( keys ) * 100 ) != 0 : NEW_LINE INDENT ans_tmp += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ans_tmp = sum ( p . values ( ) ) NEW_LINE DEDENT DEDENT ans = min ( ans , ans_tmp ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"import sys NEW_LINE import itertools NEW_LINE import collections NEW_LINE import functools NEW_LINE import math NEW_LINE import operator NEW_LINE from queue import Queue NEW_LINE INF = float ( \" inf \" ) NEW_LINE def dfs ( curr , goal , count , probs ) : NEW_LINE INDENT if curr >= goal : NEW_LINE INDENT return count NEW_LINE DEDENT if len ( probs ) == 0 : NEW_LINE INDENT return INF NEW_LINE DEDENT m1 = dfs ( curr , goal , count , probs [ : - 1 ] ) NEW_LINE m2 = dfs ( curr + probs [ - 1 ] [ 0 ] * probs [ - 1 ] [ 1 ] + probs [ - 1 ] [ 2 ] , goal , count + probs [ - 1 ] [ 1 ] , probs [ : - 1 ] ) NEW_LINE m3 = INF NEW_LINE s = goal - curr NEW_LINE if ( probs [ - 1 ] [ 0 ] * probs [ - 1 ] [ 1 ] ) >= s : NEW_LINE INDENT m3 = count + int ( math . ceil ( s / probs [ - 1 ] [ 0 ] ) ) NEW_LINE DEDENT return min ( m1 , m2 , m3 ) NEW_LINE DEDENT def solve ( D : int , G : int , p : \" List [ int ] \" , c : \" List [ int ] \" ) : NEW_LINE INDENT probs = [ ] NEW_LINE for i in range ( D ) : NEW_LINE INDENT probs . append ( [ 100 * ( i + 1 ) , p [ i ] , c [ i ] ] ) NEW_LINE DEDENT m = dfs ( 0 , G , 0 , probs ) NEW_LINE print ( m ) NEW_LINE 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 D = int ( next ( tokens ) ) NEW_LINE G = int ( next ( tokens ) ) NEW_LINE p = [ int ( ) ] * ( D ) NEW_LINE c = [ int ( ) ] * ( D ) NEW_LINE for i in range ( D ) : NEW_LINE INDENT p [ i ] = int ( next ( tokens ) ) NEW_LINE c [ i ] = int ( next ( tokens ) ) NEW_LINE DEDENT solve ( D , G , p , c ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"import math NEW_LINE D , G = map ( int , input ( ) . split ( ) ) NEW_LINE p_c_list = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( D ) ] NEW_LINE min_n_solved = 1000000000 NEW_LINE for p_combi in range ( 1 << D ) : NEW_LINE INDENT tmp_score = 0 NEW_LINE n_solved = 0 NEW_LINE selected_p_idxs = [ ] NEW_LINE for digit in range ( D ) : NEW_LINE INDENT if ( p_combi >> digit ) & 1 : NEW_LINE INDENT tmp_score += 100 * ( digit + 1 ) * p_c_list [ digit ] [ 0 ] + p_c_list [ digit ] [ 1 ] NEW_LINE n_solved += p_c_list [ digit ] [ 0 ] NEW_LINE selected_p_idxs . append ( digit ) NEW_LINE DEDENT DEDENT score_diff = tmp_score - G NEW_LINE if score_diff >= 0 : NEW_LINE INDENT p_idx_lowest = selected_p_idxs [ 0 ] NEW_LINE score_per_p = 100 * ( p_idx_lowest + 1 ) NEW_LINE n_oversolved = None NEW_LINE score_diff_wo_bonus = score_diff - p_c_list [ p_idx_lowest ] [ 1 ] NEW_LINE if score_diff_wo_bonus > 0 : NEW_LINE INDENT n_oversolved = round ( score_diff_wo_bonus / score_per_p ) NEW_LINE if n_oversolved < p_c_list [ p_idx_lowest ] [ 0 ] : NEW_LINE INDENT n_solved -= n_oversolved NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT not_selected_p_idxs = [ p_idx for p_idx in range ( D ) if p_idx not in selected_p_idxs ] NEW_LINE not_selected_p_idxs = sorted ( not_selected_p_idxs , reverse = True ) NEW_LINE not_selected_p_idx_highest = not_selected_p_idxs [ 0 ] NEW_LINE addable_score = 100 * p_c_list [ not_selected_p_idx_highest ] [ 0 ] * ( not_selected_p_idx_highest + 1 ) NEW_LINE if score_diff + addable_score > 0 : NEW_LINE INDENT score_per_p = 100 * ( not_selected_p_idx_highest + 1 ) NEW_LINE n_undersolved = math . ceil ( abs ( score_diff ) / score_per_p ) NEW_LINE if n_undersolved < p_c_list [ not_selected_p_idx_highest ] [ 0 ] : NEW_LINE INDENT n_solved += n_undersolved NEW_LINE DEDENT DEDENT DEDENT if n_solved > 0 and score_diff >= 0 : NEW_LINE INDENT min_n_solved = min ( n_solved , min_n_solved ) NEW_LINE DEDENT DEDENT print ( min_n_solved ) NEW_LINE",
"print ( ( lambda d , D , G : ( lambda a : min ( d [ ' P ' ] + max ( 0 , d [ ' q ' ] ) for i in range ( 1 << D ) if d . update ( P = 0 , g = 0 , k = - 1 ) or any ( d . update ( P = d [ ' P ' ] + p , g = d [ ' g ' ] + c + 100 * p * - ~ j ) if i >> j & 1 else d . update ( k = j ) for j , ( p , c ) in enumerate ( a ) ) or d [ ' k ' ] < 0 and [ d . update ( q = 0 ) ] or d . update ( q = ( G - d [ ' g ' ] - 1 ) // ( 100 * - ~ d [ ' k ' ] ) + 1 ) or a [ d [ ' k ' ] ] [ 0 ] > d [ ' q ' ] ) ) ( [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * D ] ) ) ( { } , * map ( int , input ( ) . split ( ) ) ) ) NEW_LINE",
"import copy NEW_LINE def calc ( wk , kouho , G ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( D ) : NEW_LINE INDENT if kouho [ i ] == 1 : NEW_LINE INDENT G -= wk [ i ] [ 1 ] + 100 * ( i + 1 ) * wk [ i ] [ 0 ] NEW_LINE ans += wk [ i ] [ 0 ] NEW_LINE wk [ i ] [ 0 ] = 0 NEW_LINE DEDENT DEDENT if G <= 0 : NEW_LINE INDENT return ans NEW_LINE DEDENT solve = D - 1 NEW_LINE while G > 0 and solve >= 0 : NEW_LINE INDENT if wk [ solve ] [ 0 ] >= 2 : NEW_LINE INDENT wk [ solve ] [ 0 ] -= 1 NEW_LINE G -= 100 * ( solve + 1 ) NEW_LINE ans += 1 NEW_LINE DEDENT if wk [ solve ] [ 0 ] <= 1 : NEW_LINE INDENT solve -= 1 NEW_LINE DEDENT DEDENT return ans if G <= 0 else 10000 NEW_LINE DEDENT D , G = map ( int , input ( ) . split ( ) ) NEW_LINE zenbu = 2 ** D NEW_LINE prob = [ ] NEW_LINE min = 10000 NEW_LINE for i in range ( D ) : NEW_LINE INDENT prob . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE DEDENT for i in range ( zenbu ) : NEW_LINE INDENT work = copy . deepcopy ( prob ) NEW_LINE kouho = [ ] NEW_LINE key = i NEW_LINE for j in range ( D ) : NEW_LINE INDENT kouho . append ( key % 2 ) NEW_LINE key //= 2 NEW_LINE DEDENT res = calc ( work , kouho , G ) NEW_LINE if res < min : NEW_LINE INDENT min = res NEW_LINE DEDENT DEDENT print ( str ( min ) ) NEW_LINE"
] |
atcoder_abc120_C | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String input = sc . nextLine ( ) ; int count = 0 ; String inputStr [ ] = new String [ input . length ( ) ] ; int currentIndex = 0 ; for ( int i = 0 ; i < input . length ( ) ; i ++ ) { inputStr [ currentIndex ] = input . substring ( i , i + 1 ) ; if ( currentIndex != 0 && ! inputStr [ currentIndex ] . equals ( inputStr [ currentIndex - 1 ] ) ) { currentIndex -- ; count += 2 ; } else { currentIndex ++ ; } } System . out . println ( count ) ; sc . close ( ) ; } }",
"import java . util . LinkedList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; Main abc120C = new Main ( ) ; System . out . println ( abc120C . solve ( S ) ) ; } public int solve ( String S ) { ABC120CSolve abc120CSolve = new ABC120CSolve ( ) ; return abc120CSolve . solve ( S ) ; } class ABC120CSolve { static final int ZERO = ( int ) '0' ; public int solve ( String S ) { int ans = 0 ; LinkedList < Integer > list = new LinkedList ( ) ; for ( char c : S . toCharArray ( ) ) { int i = ( int ) c - ZERO ; if ( list . size ( ) == 0 ) { list . addLast ( i ) ; } else { if ( list . getLast ( ) != i ) { list . removeLast ( ) ; ans += 2 ; } else { list . addLast ( i ) ; } } } return ans ; } } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .",
"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 ) ; CUnification solver = new CUnification ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class CUnification { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String s = in . next ( ) ; char [ ] arr = s . toCharArray ( ) ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == '0' ) a ++ ; else b ++ ; } out . println ( Math . min ( a , b ) * 2 ) ; } } }",
"import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; List < String > sList = Arrays . asList ( S . split ( \" \" ) ) ; int zeroCount = 0 ; int oneCount = 0 ; int ans = 0 ; for ( String s : sList ) { if ( s . equals ( \"0\" ) ) { zeroCount ++ ; } else { oneCount ++ ; } } if ( zeroCount > oneCount ) { ans = oneCount * 2 ; } else { ans = zeroCount * 2 ; } System . out . println ( ans ) ; } }",
"import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; int [ ] rb = { 0 , 0 } ; for ( String s : str . split ( \" \" ) ) { if ( s . equals ( \"0\" ) ) { rb [ 0 ] ++ ; } else { rb [ 1 ] ++ ; } } System . out . println ( Math . min ( rb [ 0 ] , rb [ 1 ] ) * 2 ) ; } }"
] | [
"s = input ( ) NEW_LINE a_1 = s . count ( \"1\" ) NEW_LINE b_1 = s . count ( \"0\" ) NEW_LINE if a_1 <= b_1 : NEW_LINE INDENT print ( 2 * a_1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 2 * b_1 ) NEW_LINE DEDENT",
"S = list ( input ( ) ) NEW_LINE prev = \" \" NEW_LINE index = 0 NEW_LINE ans = 0 NEW_LINE while index < len ( S ) : NEW_LINE INDENT if prev == \" \" : NEW_LINE INDENT prev = S [ index ] NEW_LINE index = index + 1 NEW_LINE continue NEW_LINE DEDENT if S [ index ] != prev : NEW_LINE INDENT S . pop ( index ) NEW_LINE S . pop ( index - 1 ) NEW_LINE ans = ans + 2 NEW_LINE if len ( S ) == 0 : NEW_LINE INDENT break NEW_LINE DEDENT index = index - 2 if index - 2 > 0 else 0 NEW_LINE prev = \" \" NEW_LINE DEDENT else : NEW_LINE INDENT prev = S [ index ] NEW_LINE index = index + 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"import numpy as np NEW_LINE s = [ int ( i ) for i in input ( ) ] NEW_LINE array = np . array ( s ) NEW_LINE zero = np . sum ( array == 0 ) NEW_LINE one = np . sum ( array == 1 ) NEW_LINE print ( 2 * min ( zero , one ) ) NEW_LINE",
"S = input ( ) NEW_LINE redcount = S . count ( '0' ) NEW_LINE bluecount = S . count ( '1' ) NEW_LINE mincount = min ( redcount , bluecount ) NEW_LINE answer = mincount * 2 NEW_LINE print ( answer ) NEW_LINE",
"s = input ( ) ; print ( min ( s . count ( \"0\" ) , s . count ( \"1\" ) ) * 2 ) NEW_LINE"
] |
atcoder_abc112_D | [
"import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; class Pair { long first ; long second ; Pair ( long first , long second ) { this . first = first ; this . second = second ; } } @ SuppressWarnings ( \" unchecked \" ) public class Main { static void divisor ( ArrayList < Pair > div , long N ) { long n ; long i = 1 ; n = N ; while ( i <= Math . sqrt ( n ) ) { if ( n % i == 0 ) div . add ( new Pair ( i , n / i ) ) ; i ++ ; } } public static void main ( String [ ] args ) throws IOException { final String s ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { s = reader . readLine ( ) ; } PrintWriter out = new PrintWriter ( System . out ) ; final String [ ] sl = s . split ( \" β \" ) ; int N = Integer . parseInt ( sl [ 0 ] ) ; int M = Integer . parseInt ( sl [ 1 ] ) ; ArrayList < Pair > div = new ArrayList < > ( ) ; divisor ( div , M ) ; long MAX = M / N + 1 ; long ans = 0 ; for ( Pair p : div ) { long first = p . first ; long second = p . second ; if ( first < MAX && ans < first ) ans = first ; if ( second < MAX && ans < second ) ans = second ; } out . println ( ans ) ; out . flush ( ) ; } }",
"import java . util . Scanner ; public class Main { public void main ( Scanner sc ) throws Exception { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; sc . close ( ) ; int ans = 1 ; for ( int i = 1 ; i * i <= m ; i ++ ) { if ( m % i != 0 ) { continue ; } if ( i >= n ) { ans = Math . max ( ans , m / i ) ; } else if ( m / i >= n ) { ans = Math . max ( ans , i ) ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; } }",
"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 ( ) ; long M = sc . nextInt ( ) ; Set < Long > divisors = new TreeSet < > ( Collections . reverseOrder ( ) ) ; for ( long i = 1 ; i <= ( long ) Math . sqrt ( M ) ; i ++ ) { if ( M % i == 0 ) { divisors . add ( i ) ; divisors . add ( M / i ) ; } } for ( long p : divisors ) { if ( M % p == 0 && M / p >= N ) { out . println ( p ) ; return ; } } } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; final int m = ( int ) Math . sqrt ( M ) ; boolean [ ] prm = new boolean [ m + 1 ] ; for ( int i = 2 ; i < m + 1 ; i ++ ) prm [ i ] = true ; for ( int i = 2 ; i < m + 1 ; i ++ ) { if ( prm [ i ] ) { for ( int j = 2 * i ; j < m + 1 ; j += i ) prm [ j ] = false ; } } int [ ] L1 = new int [ m + 1 ] ; int [ ] L2 = new int [ m + 1 ] ; int id = 0 ; int M2 = M ; for ( int i = 2 ; i < m + 1 ; i ++ ) { if ( prm [ i ] && M2 % i == 0 ) { L1 [ id ] = i ; while ( M2 % i == 0 ) { L2 [ id ] ++ ; M2 /= i ; } id ++ ; } if ( i == m && M2 > 1 ) { L1 [ id ] = M2 ; L2 [ id ] ++ ; id ++ ; } } int p = solve ( 1 , L1 , L2 , 0 , N , id ) ; System . out . println ( M / p ) ; } public static int solve ( int a , int [ ] l1 , int [ ] l2 , int ind , int n , int l ) { if ( ind == l ) { if ( a >= n ) return a ; else return 1000000007 ; } else { int min = 1000000007 ; for ( int i = 0 ; i <= l2 [ ind ] ; i ++ ) { min = Math . min ( solve ( a * ( int ) Math . pow ( l1 [ ind ] , i ) , l1 , l2 , ind + 1 , n , l ) , min ) ; } return min ; } } }",
"import java . util . LinkedList ; import java . util . Queue ; import java . util . Scanner ; public class Main { static Queue < Integer > q = new LinkedList < Integer > ( ) ; static void Divisor ( int M ) { for ( int i = 1 ; i < Math . sqrt ( M ) ; i ++ ) { if ( M % i != 0 ) continue ; q . add ( i ) ; q . add ( M / i ) ; } if ( M % Math . sqrt ( M ) == 0 ) q . add ( ( int ) Math . sqrt ( M ) ) ; } public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; Divisor ( M ) ; int max = 0 ; while ( ! q . isEmpty ( ) ) { int s = q . remove ( ) ; if ( M % s == 0 && M / s >= N ) { max = Math . max ( max , s ) ; } } System . out . println ( max ) ; } } }"
] | [
"N , M = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def solution ( ) : NEW_LINE INDENT if M - N < M // N : NEW_LINE INDENT for n in range ( N , M + 1 ) : NEW_LINE INDENT if M % n == 0 : NEW_LINE INDENT return M // n NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT for m in range ( M // N , 0 , - 1 ) : NEW_LINE INDENT if M % m == 0 : NEW_LINE INDENT return m NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( solution ( ) ) NEW_LINE",
"import math NEW_LINE def soinsu ( N ) : NEW_LINE INDENT sqr = int ( math . sqrt ( N ) ) NEW_LINE lis = [ ] NEW_LINE for i in range ( 2 , sqr + 2 ) : NEW_LINE INDENT while N % i == 0 : NEW_LINE INDENT lis . append ( i ) NEW_LINE N = N // i NEW_LINE DEDENT DEDENT if not N == 1 : NEW_LINE INDENT lis . append ( N ) NEW_LINE DEDENT return lis NEW_LINE DEDENT def yakusu ( N ) : NEW_LINE INDENT sqr = int ( math . sqrt ( N ) ) NEW_LINE lis = [ ] NEW_LINE for i in range ( 1 , sqr + 2 ) : NEW_LINE INDENT if N % i == 0 : NEW_LINE INDENT lis . append ( i ) NEW_LINE lis . append ( N // i ) NEW_LINE DEDENT DEDENT return lis NEW_LINE DEDENT mod = 1000000007 NEW_LINE def modpow ( a , b , MOD = mod ) : NEW_LINE INDENT res = 1 NEW_LINE while b > 0 : NEW_LINE INDENT if ( b & 1 ) == 1 : NEW_LINE INDENT res = ( res * a ) % MOD NEW_LINE DEDENT a = ( a * a ) % MOD NEW_LINE b = b >> 1 NEW_LINE DEDENT return res NEW_LINE DEDENT fact = [ ] NEW_LINE def ncrinit ( MOD = mod ) : NEW_LINE INDENT fact . append ( 1 ) NEW_LINE for i in range ( 1 , 110005 ) : NEW_LINE INDENT fact . append ( ( fact [ i - 1 ] * i ) % MOD ) NEW_LINE DEDENT DEDENT def calcnCr ( n , r , MOD = mod ) : NEW_LINE INDENT up = fact [ n ] NEW_LINE down = modpow ( ( fact [ n - r ] * fact [ r ] ) % mod , mod - 2 , mod ) NEW_LINE return ( up * down ) % mod NEW_LINE DEDENT def compres ( lis ) : NEW_LINE INDENT li = [ ] NEW_LINE se = set ( lis ) NEW_LINE for i in se : NEW_LINE INDENT li . append ( lis . count ( i ) ) NEW_LINE DEDENT return li NEW_LINE DEDENT res = 1 NEW_LINE N , M = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE co = yakusu ( M ) NEW_LINE co . sort ( ) NEW_LINE for i in co : NEW_LINE INDENT if M // i >= N : NEW_LINE INDENT res = max ( res , i ) NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE",
"import sys NEW_LINE def solve ( N : int , M : int ) : NEW_LINE INDENT ret = 0 NEW_LINE i = 1 NEW_LINE while i * i <= M : NEW_LINE INDENT if M % i == 0 : NEW_LINE INDENT if i >= N : NEW_LINE INDENT ret = max ( ret , M // i ) NEW_LINE DEDENT if M // i >= N : NEW_LINE INDENT ret = max ( ret , i ) NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT print ( ret ) NEW_LINE 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 N = int ( next ( tokens ) ) NEW_LINE M = int ( next ( tokens ) ) NEW_LINE solve ( N , M ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"n , m = map ( int , input ( ) . split ( ) ) NEW_LINE f1 = [ ] NEW_LINE f2 = [ ] NEW_LINE for i1 in range ( 1 , int ( m ** 0.5 ) + 1 ) : NEW_LINE INDENT if m % i1 == 0 : NEW_LINE INDENT i2 = m // i1 NEW_LINE if i1 >= n : NEW_LINE INDENT ans = i2 NEW_LINE break NEW_LINE DEDENT elif i2 == n : NEW_LINE INDENT ans = i1 NEW_LINE break NEW_LINE DEDENT elif i2 < n : NEW_LINE INDENT ans = f1 [ - 1 ] NEW_LINE break NEW_LINE DEDENT f1 += [ i1 ] NEW_LINE f2 += [ i2 ] NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ans = f1 [ - 1 ] NEW_LINE DEDENT print ( ans ) NEW_LINE",
"import math NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE def get_divisors ( n ) : NEW_LINE INDENT ret = [ ] NEW_LINE for i in range ( 1 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT ret . append ( i ) NEW_LINE if n // i != i : NEW_LINE INDENT ret . append ( n // i ) NEW_LINE DEDENT DEDENT DEDENT return ret NEW_LINE DEDENT divs = get_divisors ( m ) NEW_LINE divs . sort ( reverse = True ) NEW_LINE for d in divs : NEW_LINE INDENT if d * n <= m : NEW_LINE INDENT print ( d ) NEW_LINE break NEW_LINE DEDENT DEDENT"
] |
atcoder_arc098_A | [
"import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; public class Main { private static final String ZERO = \"0\" ; private enum Direction { W , E ; } public static String process ( TestCase testCase ) { final int N = testCase . N ; final String S = testCase . S ; if ( N <= 0 ) { return ZERO ; } else { final List < Direction > directions = Arrays . stream ( S . split ( \" \" ) ) . map ( Direction :: valueOf ) . collect ( Collectors . toList ( ) ) ; long min = IntStream . range ( 1 , N ) . mapToObj ( directions :: get ) . filter ( Direction . E :: equals ) . count ( ) ; long change = min ; for ( int i = 1 ; i < N ; ++ i ) { final Direction prev = directions . get ( i - 1 ) ; final Direction curr = directions . get ( i ) ; if ( Direction . W . equals ( prev ) ) { change ++ ; } if ( Direction . E . equals ( curr ) ) { change -- ; } min = Math . min ( min , change ) ; } return String . valueOf ( min ) ; } } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; return new TestCase ( N , S ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final int N ; final String S ; public TestCase ( int N , String S ) { this . N = N ; this . S = S ; } } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; String s = in . next ( ) ; int east = 0 ; int west = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' E ' ) east ++ ; else west ++ ; } int ans = Integer . MAX_VALUE ; int ce = 0 , cw = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int req = cw + east - ce + ( s . charAt ( i ) == ' E ' ? - 1 : 0 ) ; ans = Math . min ( ans , req ) ; if ( s . charAt ( i ) == ' E ' ) ce ++ ; else cw ++ ; } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . Scanner ; public class Main { public static int findMinTurns ( int n , String s ) { int eastTotal = 0 ; int westTotal = 0 ; for ( char ch : s . toCharArray ( ) ) { if ( ch == ' E ' ) { eastTotal ++ ; } else if ( ch == ' W ' ) { westTotal ++ ; } } int eastPassed = 0 ; int westPassed = 0 ; int currentTurns ; int leastTurns = n ; for ( char ch : s . toCharArray ( ) ) { currentTurns = westPassed + eastTotal - eastPassed ; if ( ch == ' E ' ) { currentTurns -- ; eastPassed ++ ; } else if ( ch == ' W ' ) { westPassed ++ ; } if ( currentTurns < leastTurns ) { leastTurns = currentTurns ; } } return leastTurns ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; System . out . println ( findMinTurns ( n , s ) ) ; sc . close ( ) ; } }",
"import java . util . * ; public class Main { static int n , k ; static int [ ] a ; static int modP = 1000000007 ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; n = in . nextInt ( ) ; char [ ] s = in . next ( ) . toCharArray ( ) ; int [ ] wOnLeftCnt = new int [ n ] ; int [ ] eOnLeftCnt = new int [ n ] ; int [ ] wOnRightCnt = new int [ n ] ; int [ ] eOnRightCnt = new int [ n ] ; int wCnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { wOnLeftCnt [ i ] = wCnt ; if ( s [ i ] == ' W ' ) { wCnt ++ ; } } int eCnt = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { eOnRightCnt [ i ] = eCnt ; if ( s [ i ] == ' E ' ) { eCnt ++ ; } } int minTurned = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( minTurned > wOnLeftCnt [ i ] + eOnRightCnt [ i ] ) { minTurned = wOnLeftCnt [ i ] + eOnRightCnt [ i ] ; } minTurned = Math . min ( minTurned , wOnLeftCnt [ i ] + eOnRightCnt [ i ] ) ; } System . out . println ( minTurned ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numberOfPeople = sc . nextInt ( ) ; char [ ] peopleDirections = sc . next ( ) . toCharArray ( ) ; int [ ] east = new int [ numberOfPeople ] ; int [ ] west = new int [ numberOfPeople ] ; for ( int i = 0 ; i < numberOfPeople ; i ++ ) { if ( peopleDirections [ i ] == ' E ' ) { east [ i ] = 1 ; } else { west [ i ] = 1 ; } } for ( int i = 1 ; i < numberOfPeople ; i ++ ) { east [ i ] += east [ i - 1 ] ; west [ i ] += west [ i - 1 ] ; } int minimumNumberOfPeopleToChangeDirection = numberOfPeople ; for ( int i = 0 ; i < numberOfPeople ; i ++ ) { int countOfEastAtRightSide = east [ numberOfPeople - 1 ] - east [ i ] ; int countOfWestAtLeftSide = i == 0 ? 0 : west [ i - 1 ] ; int totalCount = countOfEastAtRightSide + countOfWestAtLeftSide ; if ( minimumNumberOfPeopleToChangeDirection > totalCount ) { minimumNumberOfPeopleToChangeDirection = totalCount ; } } System . out . println ( minimumNumberOfPeopleToChangeDirection ) ; } }"
] | [
"n = int ( input ( ) ) NEW_LINE s = list ( input ( ) ) NEW_LINE p = [ 0 , 0 ] NEW_LINE l = [ s . count ( \" E \" ) , s . count ( \" W \" ) ] NEW_LINE t = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if s [ i ] == \" E \" : NEW_LINE INDENT t . append ( l [ 0 ] + p [ 1 ] - 1 ) NEW_LINE l [ 0 ] -= 1 NEW_LINE p [ 0 ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT t . append ( l [ 0 ] + p [ 1 ] ) NEW_LINE l [ 1 ] -= 1 NEW_LINE p [ 1 ] += 1 NEW_LINE DEDENT DEDENT print ( min ( t ) ) NEW_LINE",
"from sys import stdin NEW_LINE import numpy as np NEW_LINE N = int ( stdin . readline ( ) . rstrip ( ) . split ( ) [ 0 ] ) NEW_LINE S = stdin . readline ( ) . rstrip ( ) . split ( ) [ 0 ] NEW_LINE is_w_list = [ 1 if s == \" W \" else 0 for s in S ] NEW_LINE cumsum_w = np . append ( np . array ( [ 0 ] ) , ( np . cumsum ( is_w_list ) [ : - 1 ] ) ) NEW_LINE is_e_list = [ not ( x ) for x in is_w_list [ : : - 1 ] ] NEW_LINE cumsum_e = np . append ( np . array ( [ 0 ] ) , ( np . cumsum ( is_e_list ) [ : - 1 ] ) ) [ : : - 1 ] NEW_LINE print ( np . min ( cumsum_w + cumsum_e ) ) 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 LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE n = II ( ) NEW_LINE s = SI ( ) NEW_LINE W = [ 0 ] NEW_LINE E = [ 0 ] NEW_LINE for c in s : NEW_LINE INDENT W . append ( W [ - 1 ] + ( c == ' W ' ) ) NEW_LINE E . append ( E [ - 1 ] + ( c == ' E ' ) ) NEW_LINE DEDENT e_max = E [ - 1 ] NEW_LINE ans = INF NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ans = min ( ans , W [ i - 1 ] + e_max - E [ i ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"def solve ( string ) : NEW_LINE INDENT length = len ( string ) NEW_LINE east , west = [ 0 ] * ( length + 1 ) , [ 0 ] * ( length + 2 ) NEW_LINE for i in range ( 1 , length + 1 ) : NEW_LINE INDENT if string [ i - 1 ] == \" W \" : NEW_LINE INDENT east [ i ] = east [ i - 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT east [ i ] = east [ i - 1 ] NEW_LINE DEDENT DEDENT for j in range ( length , 0 , - 1 ) : NEW_LINE INDENT if string [ j - 1 ] == \" E \" : NEW_LINE INDENT west [ j ] = west [ j + 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT west [ j ] = west [ j + 1 ] NEW_LINE DEDENT DEDENT ans = length NEW_LINE for k in range ( 1 , length + 1 ) : NEW_LINE INDENT ans = min ( ans , east [ k - 1 ] + west [ k + 1 ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE string = input ( ) NEW_LINE ans = solve ( string ) NEW_LINE print ( ans ) NEW_LINE DEDENT main ( ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE west = [ 0 for i in range ( n + 1 ) ] NEW_LINE east = [ 0 for i in range ( n + 1 ) ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT west [ i ] = west [ i - 1 ] NEW_LINE east [ i ] = east [ i - 1 ] NEW_LINE if s [ i - 1 ] == ' W ' : NEW_LINE INDENT west [ i ] += 1 NEW_LINE DEDENT if s [ i - 1 ] == ' E ' : NEW_LINE INDENT east [ i ] += 1 NEW_LINE DEDENT DEDENT ans = 1e9 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT reqd_east_cnt = i - 1 NEW_LINE got_east_cnt = east [ i - 1 ] NEW_LINE reqd_west_cnt = n - i NEW_LINE got_west_cnt = west [ n ] - west [ i ] NEW_LINE ans = min ( ans , reqd_east_cnt - got_east_cnt + reqd_west_cnt - got_west_cnt ) NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc115_C | [
"import java . util . Arrays ; import java . util . Scanner ; public class Main { static int N , K ; static int [ ] trees ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; K = sc . nextInt ( ) ; trees = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { trees [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( trees ) ; int current = trees [ K - 1 ] - trees [ 0 ] ; int height = 0 ; for ( int i = 1 ; i < N - K + 1 ; i ++ ) { height = trees [ i + K - 1 ] - trees [ i ] ; if ( current > height ) { current = height ; } } System . out . println ( current ) ; } }",
"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 [ ] h = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } Arrays . sort ( h ) ; int min = h [ 0 ] ; int max = h [ K - 1 ] ; int diff = max - min ; for ( int i = K ; i < N ; i ++ ) { min = h [ i - K + 1 ] ; max = h [ i ] ; diff = Math . min ( diff , max - min ) ; } out . println ( diff ) ; } }",
"import java . util . stream . IntStream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = scanner . nextInt ( ) , k = scanner . nextInt ( ) ; int [ ] h = IntStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) ) . sorted ( ) . toArray ( ) ; System . out . println ( IntStream . range ( k - 1 , n ) . map ( i -> h [ i ] - h [ i - k + 1 ] ) . min ( ) . getAsInt ( ) ) ; } }",
"import java . io . InputStream ; import java . io . PrintStream ; import java . util . Arrays ; import java . util . Scanner ; public class Main { InputStream in = System . in ; PrintStream out = System . out ; public void _main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } Arrays . sort ( h ) ; int [ ] d = new int [ n - ( k - 1 ) ] ; for ( int i = 0 ; i < n - ( k - 1 ) ; i ++ ) { d [ i ] = h [ i + ( k - 1 ) ] - h [ i ] ; } Arrays . sort ( d ) ; out . println ( d [ 0 ] ) ; sc . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = bf . readLine ( ) . split ( \" β \" ) ; int N = Integer . parseInt ( str [ 0 ] ) , K = Integer . parseInt ( str [ 1 ] ) ; int [ ] h = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = Integer . parseInt ( bf . readLine ( ) ) ; } Arrays . sort ( h ) ; int min = h [ N - 1 ] - h [ 0 ] ; for ( int i = 0 ; i < N - K + 1 ; i ++ ) { int value = h [ i + K - 1 ] - h [ i ] ; if ( value < min ) { min = value ; } } System . out . println ( min ) ; } }"
] | [
"N , K = map ( int , input ( ) . split ( ) ) NEW_LINE h = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT h . append ( int ( input ( ) ) ) NEW_LINE DEDENT h2 = sorted ( h ) NEW_LINE ans = 10 ** 9 NEW_LINE for i in range ( N - K + 1 ) : NEW_LINE INDENT if h2 [ i + K - 1 ] - h2 [ i ] < ans : NEW_LINE INDENT ans = h2 [ i + K - 1 ] - h2 [ i ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE",
"from sys import stdin NEW_LINE n , k = [ int ( _ ) for _ in stdin . readline ( ) . rstrip ( ) . split ( ) ] NEW_LINE h = [ int ( stdin . readline ( ) . rstrip ( ) ) for _ in range ( n ) ] NEW_LINE h . sort ( ) NEW_LINE print ( min ( h [ i + k - 1 ] - h [ i ] for i in range ( n - k + 1 ) ) ) NEW_LINE",
"import sys NEW_LINE INF = float ( \" inf \" ) NEW_LINE def solve ( N : int , K : int , h : \" List [ int ] \" ) : NEW_LINE INDENT h . sort ( ) NEW_LINE print ( min ( h [ i + K - 1 ] - h [ i ] for i in range ( N - K + 1 ) ) ) NEW_LINE 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 N = int ( next ( tokens ) ) NEW_LINE K = int ( next ( tokens ) ) NEW_LINE h = [ int ( next ( tokens ) ) for _ in range ( N ) ] NEW_LINE solve ( N , K , h ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"N , K = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE H = sorted ( [ int ( input ( ) ) for _ in range ( N ) ] ) NEW_LINE min_h = 1e15 NEW_LINE for i in range ( N - K + 1 ) : NEW_LINE INDENT tmp = H [ i + K - 1 ] - H [ i ] NEW_LINE if tmp < min_h : NEW_LINE INDENT min_h = tmp NEW_LINE DEDENT DEDENT print ( min_h ) NEW_LINE",
"n , k = map ( int , input ( ) . split ( ) ) NEW_LINE heights = [ ] NEW_LINE for _ in range ( n ) : NEW_LINE INDENT heights . append ( int ( input ( ) ) ) NEW_LINE DEDENT heights . sort ( ) NEW_LINE ans = float ( ' inf ' ) NEW_LINE for i in range ( len ( heights ) ) : NEW_LINE INDENT if i + k - 1 >= len ( heights ) : NEW_LINE INDENT break NEW_LINE DEDENT ans = min ( ans , heights [ i + k - 1 ] - heights [ i ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc104_D | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; char [ ] s = scanner . next ( ) . toCharArray ( ) ; int n = s . length ; long dp [ ] [ ] = new long [ n + 1 ] [ 4 ] ; for ( int i = 0 ; i <= 3 ; i ++ ) { dp [ n ] [ i ] = i == 3 ? 1 : 0 ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = 3 ; j >= 0 ; j -- ) { dp [ i ] [ j ] = dp [ i + 1 ] [ j ] * ( s [ i ] == ' ? ' ? 3L : 1L ) ; if ( j < 3 && ( s [ i ] == ' ? ' || s [ i ] == \" ABC \" . toCharArray ( ) [ j ] ) ) { dp [ i ] [ j ] += dp [ i + 1 ] [ j + 1 ] ; } dp [ i ] [ j ] %= 1_000_000_007L ; } } System . out . println ( dp [ 0 ] [ 0 ] ) ; } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; long [ ] [ ] dp = new long [ S . length ( ) + 1 ] [ 4 ] ; long prime = 1000000007 ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= S . length ( ) ; i ++ ) { for ( int j = 0 ; j < 4 ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; dp [ i ] [ j ] %= prime ; } if ( S . charAt ( i - 1 ) == ' A ' ) { dp [ i ] [ 1 ] += dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 1 ] %= prime ; } else if ( S . charAt ( i - 1 ) == ' B ' ) { dp [ i ] [ 2 ] += dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 2 ] %= prime ; } else if ( S . charAt ( i - 1 ) == ' C ' ) { dp [ i ] [ 3 ] += dp [ i - 1 ] [ 2 ] ; dp [ i ] [ 3 ] %= prime ; } else { for ( int j = 0 ; j < 4 ; j ++ ) { dp [ i ] [ j ] += 2 * dp [ i - 1 ] [ j ] ; dp [ i ] [ j ] %= prime ; } dp [ i ] [ 1 ] += dp [ i - 1 ] [ 0 ] ; dp [ i ] [ 2 ] += dp [ i - 1 ] [ 1 ] ; dp [ i ] [ 3 ] += dp [ i - 1 ] [ 2 ] ; dp [ i ] [ 1 ] %= prime ; dp [ i ] [ 2 ] %= prime ; dp [ i ] [ 3 ] %= prime ; } } out . println ( dp [ S . length ( ) ] [ 3 ] ) ; } }",
"import java . util . * ; public class Main { private static final char ABC [ ] = \" ABC \" . toCharArray ( ) ; private static final long MOD = 1_000_000_007L ; public void main ( Scanner sc ) throws Exception { char s [ ] = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; int len = s . length ; long data [ ] [ ] = new long [ len + 1 ] [ 4 ] ; data [ len ] [ 3 ] = 1 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { data [ i ] [ 3 ] = ( s [ i ] == ' ? ' ? 3 : 1 ) * data [ i + 1 ] [ 3 ] ; data [ i ] [ 3 ] %= MOD ; } for ( int i = len - 1 ; i >= 0 ; i -- ) { for ( int j = 2 ; j >= 0 ; j -- ) { data [ i ] [ j ] = ( s [ i ] == ' ? ' ? 3 : 1 ) * data [ i + 1 ] [ j ] + ( s [ i ] == ABC [ j ] || s [ i ] == ' ? ' ? 1 : 0 ) * data [ i + 1 ] [ j + 1 ] ; data [ i ] [ j ] %= MOD ; } } System . out . println ( data [ 0 ] [ 0 ] % MOD ) ; } public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; } }",
"import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; StringBuffer sb = new StringBuffer ( S ) ; S = sb . reverse ( ) . toString ( ) ; String [ ] T = S . split ( \" \" ) ; long C = 0 ; long BC = 0 ; long ABC = 0 ; long AB = 1 ; long X = 1 ; for ( String i : T ) { if ( \" ? \" . equals ( i ) ) { ABC = ( ABC * 3 + BC ) % 1000000007 ; BC = ( BC * 3 + C ) % 1000000007 ; C = ( C * 3 + X ) % 1000000007 ; X = ( X * 3 ) % 1000000007 ; } else if ( \" C \" . equals ( i ) ) { AB = 0 ; C += X ; } else if ( \" B \" . equals ( i ) ) { BC += C ; } else if ( \" A \" . equals ( i ) ) { ABC += BC ; } } System . out . println ( ABC % 1000000007 ) ; } }",
"import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; long mod = 1000000007L ; String ABC = \" ABC \" ; long [ ] [ ] dp = new long [ S . length ( ) ] [ 4 ] ; if ( S . charAt ( 0 ) == ' ? ' ) { dp [ 0 ] [ 0 ] = 3 ; } else { dp [ 0 ] [ 0 ] = 1 ; } if ( S . charAt ( 0 ) == ' A ' || S . charAt ( 0 ) == ' ? ' ) { dp [ 0 ] [ 1 ] = 1 ; } for ( int i = 1 ; i < S . length ( ) ; i ++ ) { for ( int j = 0 ; j < 4 ; j ++ ) { if ( j == 0 ) { if ( S . charAt ( i ) == ' A ' || S . charAt ( i ) == ' B ' || S . charAt ( i ) == ' C ' ) { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ; } else { dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] * 3L ; } dp [ i ] [ j ] %= mod ; } else { long x = ( S . charAt ( i ) == ' ? ' ? 3L : 1L ) ; long y = ( ( S . charAt ( i ) == ABC . charAt ( j - 1 ) || S . charAt ( i ) == ' ? ' ) ? 1L : 0L ) ; dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] * x ) + ( dp [ i - 1 ] [ j - 1 ] * y ) ; dp [ i ] [ j ] %= mod ; } } } System . out . println ( dp [ S . length ( ) - 1 ] [ 3 ] ) ; } }"
] | [
"s = input ( ) NEW_LINE dp = [ [ 0 ] * ( len ( s ) + 1 ) for _ in range ( 4 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE for i , c in enumerate ( s ) : NEW_LINE INDENT if c == \" A \" or c == \" ? \" : NEW_LINE INDENT dp [ 1 ] [ i + 1 ] = dp [ 0 ] [ i ] NEW_LINE DEDENT if c == \" B \" or c == \" ? \" : NEW_LINE INDENT dp [ 2 ] [ i + 1 ] = dp [ 1 ] [ i ] NEW_LINE DEDENT if c == \" C \" or c == \" ? \" : NEW_LINE INDENT dp [ 3 ] [ i + 1 ] = dp [ 2 ] [ i ] NEW_LINE DEDENT for j in range ( 4 ) : NEW_LINE INDENT if c == \" ? \" : NEW_LINE INDENT dp [ j ] [ i + 1 ] += dp [ j ] [ i ] * 3 NEW_LINE DEDENT else : NEW_LINE INDENT dp [ j ] [ i + 1 ] += dp [ j ] [ i ] NEW_LINE DEDENT dp [ j ] [ i + 1 ] %= 10 ** 9 + 7 NEW_LINE DEDENT DEDENT print ( dp [ - 1 ] [ - 1 ] ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE test_data1 = ''' \\ STRNEWLINE A ? ? C STRNEWLINE ''' NEW_LINE test_data2 = ''' \\ STRNEWLINE ACACAC STRNEWLINE ''' NEW_LINE test_data3 = ''' \\ STRNEWLINE ? ? ? ? C ? ? ? ? ? B ? ? ? ? ? ? A ? ? ? ? ? ? ? STRNEWLINE ''' NEW_LINE test_data4 = ''' \\ STRNEWLINE ? AC ? AC STRNEWLINE ''' NEW_LINE td_num = 3 NEW_LINE def GetTestData ( index ) : NEW_LINE INDENT if index == 1 : NEW_LINE INDENT return test_data1 NEW_LINE DEDENT if index == 2 : NEW_LINE INDENT return test_data2 NEW_LINE DEDENT if index == 3 : NEW_LINE INDENT return test_data3 NEW_LINE DEDENT if index == 4 : NEW_LINE INDENT return test_data4 NEW_LINE DEDENT DEDENT if False : NEW_LINE INDENT with open ( \" . . / test . txt \" , mode = ' w ' ) as f : NEW_LINE INDENT f . write ( GetTestData ( td_num ) ) NEW_LINE DEDENT with open ( \" . . / test . txt \" ) as f : NEW_LINE INDENT s = f . readline ( ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT s = input ( ) NEW_LINE DEDENT n = len ( s ) NEW_LINE dc = dict ( ) NEW_LINE dc [ ' A ' ] = 0 NEW_LINE dc [ ' B ' ] = 1 NEW_LINE dc [ ' C ' ] = 2 NEW_LINE dc [ ' ? ' ] = 3 NEW_LINE dp = [ [ 0 for i in range ( 4 ) ] for j in range ( n + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE mo = 10 ** 9 + 7 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for t in range ( 4 ) : NEW_LINE INDENT ch = s [ i ] NEW_LINE if dc [ ch ] == t - 1 or dc [ ch ] == 3 : NEW_LINE INDENT m = 1 NEW_LINE DEDENT else : NEW_LINE INDENT m = 0 NEW_LINE DEDENT if t != 0 : NEW_LINE INDENT dp [ i + 1 ] [ t ] += ( dp [ i ] [ t - 1 ] * m ) % mo NEW_LINE DEDENT dp [ i + 1 ] [ t ] += ( dp [ i ] [ t ] * max ( int ( dc [ ch ] / 3 ) * 3 , 1 ) ) % mo NEW_LINE DEDENT DEDENT ans = dp [ n ] [ 3 ] NEW_LINE print ( ans % mo ) NEW_LINE NEW_LINE",
"import sys NEW_LINE import itertools NEW_LINE import collections NEW_LINE import functools NEW_LINE import math NEW_LINE from queue import Queue NEW_LINE INF = float ( \" inf \" ) NEW_LINE MOD = 1000000007 NEW_LINE d = { } NEW_LINE def thpow ( q ) : NEW_LINE INDENT if q < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if q == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if q in d : NEW_LINE INDENT return d [ q ] NEW_LINE DEDENT else : NEW_LINE INDENT d [ q ] = ( 3 * thpow ( q - 1 ) ) % MOD NEW_LINE return d [ q ] NEW_LINE DEDENT DEDENT def solve ( S : str ) : NEW_LINE INDENT dp = [ 0 , 0 , 0 ] NEW_LINE q = 0 NEW_LINE for ch in S : NEW_LINE INDENT a , b , c = dp NEW_LINE if ch == \" A \" : NEW_LINE INDENT dp = [ ( a + thpow ( q ) ) % MOD , b , c ] NEW_LINE DEDENT elif ch == \" B \" : NEW_LINE INDENT dp = [ a , ( b + a ) % MOD , c ] NEW_LINE DEDENT elif ch == \" C \" : NEW_LINE INDENT dp = [ a , b , ( c + b ) % MOD ] NEW_LINE DEDENT elif ch == \" ? \" : NEW_LINE INDENT dp = [ ( ( a * 3 % MOD ) + thpow ( q ) ) % MOD , ( ( b * 3 ) % MOD + a ) % MOD , ( ( c * 3 ) + b ) % MOD ] NEW_LINE q += 1 NEW_LINE DEDENT DEDENT print ( dp [ 2 ] ) NEW_LINE 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 S = next ( tokens ) NEW_LINE solve ( S ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"X = list ( input ( ) ) NEW_LINE q_num = X . count ( \" ? \" ) NEW_LINE a_num = 0 NEW_LINE c_num = X . count ( \" C \" ) NEW_LINE left_q_num = 0 NEW_LINE right_q_num = q_num NEW_LINE ans = 0 NEW_LINE len_x = len ( X ) NEW_LINE q_dict = [ ] NEW_LINE b_ans = 0 NEW_LINE q_ans = 0 NEW_LINE q_dict = { } NEW_LINE q_dict [ q_num - 1 ] = ( 3 ** ( q_num - 1 ) ) % ( 10 ** 9 + 7 ) NEW_LINE q_dict [ q_num - 2 ] = ( 3 ** ( q_num - 2 ) ) % ( 10 ** 9 + 7 ) NEW_LINE q_dict [ q_num - 3 ] = ( 3 ** ( q_num - 3 ) ) % ( 10 ** 9 + 7 ) NEW_LINE q_dict [ q_num ] = ( 3 ** ( q_num ) ) % ( 10 ** 9 + 7 ) NEW_LINE if X [ 0 ] == \" ? \" : NEW_LINE INDENT right_q_num -= 1 NEW_LINE DEDENT elif X [ 0 ] == \" C \" : NEW_LINE INDENT c_num -= 1 NEW_LINE DEDENT for i , x in enumerate ( X ) : NEW_LINE INDENT if x == \" B \" or x == \" ? \" : NEW_LINE INDENT ans += ( a_num * c_num ) * ( q_dict [ ( left_q_num + right_q_num ) ] ) NEW_LINE if left_q_num + right_q_num >= 2 : NEW_LINE INDENT ans += ( right_q_num * left_q_num + 3 * ( left_q_num * c_num ) + 3 * ( right_q_num * a_num ) ) * ( q_dict [ ( left_q_num + right_q_num - 2 ) ] ) NEW_LINE DEDENT elif left_q_num + right_q_num == 1 : NEW_LINE INDENT ans += ( ( left_q_num * c_num ) + ( right_q_num * a_num ) ) * ( q_dict [ ( left_q_num + right_q_num - 1 ) ] ) NEW_LINE DEDENT ans = ans % ( 10 ** 9 + 7 ) NEW_LINE DEDENT if i == len_x - 1 : NEW_LINE INDENT break NEW_LINE DEDENT if x == \" A \" : NEW_LINE INDENT a_num += 1 NEW_LINE DEDENT elif x == \" ? \" : NEW_LINE INDENT left_q_num += 1 NEW_LINE DEDENT if X [ i + 1 ] == \" C \" : NEW_LINE INDENT c_num -= 1 NEW_LINE DEDENT elif X [ i + 1 ] == \" ? \" : NEW_LINE INDENT right_q_num -= 1 NEW_LINE DEDENT DEDENT print ( ans % ( 10 ** 9 + 7 ) ) NEW_LINE",
"a = [ 1 ] + [ 0 ] * 4 NEW_LINE m = 10 ** 9 + 7 NEW_LINE for s in input ( ) : NEW_LINE INDENT i = ord ( s ) - 64 NEW_LINE if i > 0 : a [ i ] += a [ i - 1 ] NEW_LINE else : a = [ a [ i ] * 3 % m + a [ i - 1 ] for i in range ( 4 ) ] + [ 0 ] NEW_LINE DEDENT print ( a [ 3 ] % m ) NEW_LINE"
] |
atcoder_abc003_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { ans += ( i * 10000.0 ) ; } System . out . println ( ans / n ) ; } }",
"import java . util . ArrayList ; import java . util . Scanner ; import static java . lang . System . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static ArrayList < Integer > train = new ArrayList ( ) ; public static void main ( String [ ] args ) { int a = sc . nextInt ( ) ; int count = 0 ; String answer = null ; for ( int i = a ; i > 0 ; i -- ) { count += ( i * 10000 ) ; } count = count / a ; answer = String . valueOf ( count ) ; out . println ( answer ) ; out . flush ( ) ; } static ArrayList < Integer > gcd ( int a , int b ) { for ( int i = 101 ; i > 0 ; i -- ) { if ( a % i == 0 ) { if ( b % i == 0 ) { train . add ( i ) ; } } } return train ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .",
"import java . util . * ; import java . util . List ; import java . util . ArrayList ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int sum = N * ( N + 1 ) / 2 ; System . out . println ( 10000 * sum / N ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = 0 ; A = N * ( N + 1 ) / 2 ; System . out . println ( A * 10000 / N ) ; } }",
"import java . util . Arrays ; import java . util . Collection ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += i ; } System . out . println ( ( sum * 10000 ) / N ) ; } static String adjustValue ( int value ) { if ( 10 > value ) { return \"0\" + value ; } else { return value + \" \" ; } } }"
] | [
"n = int ( input ( ) ) NEW_LINE print ( int ( sum ( [ i + 1 for i in range ( n ) ] ) / n * 10000 ) ) NEW_LINE",
"def calc ( n ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) / 2 ) * 10000 NEW_LINE return ( int ) ( sum / n ) NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT n , = map ( int , input ( ) . split ( ) ) NEW_LINE print ( calc ( n ) ) NEW_LINE DEDENT",
"n = int ( input ( ) ) NEW_LINE i = 0 NEW_LINE k = 10000 NEW_LINE sum = 0 NEW_LINE while i < n : NEW_LINE INDENT sum += k / n NEW_LINE k += 10000 NEW_LINE i += 1 NEW_LINE DEDENT print ( int ( sum ) ) NEW_LINE",
"print ( ( int ( input ( ) ) + 1 ) * 5000 ) NEW_LINE",
"N = float ( input ( ) ) NEW_LINE if N % 2 == 0 : NEW_LINE INDENT print ( int ( ( N / 2 + 0.5 ) * 10000 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( ( N + 1 ) / 2 * 10000 ) ) NEW_LINE DEDENT"
] |
atcoder_arc067_B | [
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . util . InputMismatchException ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskD solver = new TaskD ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskD { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; long a = in . nextLong ( ) , b = in . nextLong ( ) ; long [ ] x = in . nextLongArray ( n ) ; long sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum += Math . min ( a * ( x [ i + 1 ] - x [ i ] ) , b ) ; } out . println ( sum ) ; } } static class InputReader { BufferedReader in ; StringTokenizer tok ; public String nextString ( ) { while ( ! tok . hasMoreTokens ( ) ) { try { tok = new StringTokenizer ( in . readLine ( ) , \" β \" ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return tok . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( nextString ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( nextString ( ) ) ; } public long [ ] nextLongArray ( int n ) { long [ ] res = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { res [ i ] = nextLong ( ) ; } return res ; } public InputReader ( InputStream inputStream ) { in = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; tok = new StringTokenizer ( \" \" ) ; } } }",
"import java . util . Scanner ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . ArrayList ; import java . util . Set ; import java . util . Queue ; import java . text . DecimalFormat ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; long a = input . nextLong ( ) ; long b = input . nextLong ( ) ; long fatiga = 0 ; input . nextLine ( ) ; long pueblos [ ] = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { pueblos [ i ] = input . nextLong ( ) ; } input . nextLine ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ( pueblos [ i + 1 ] - pueblos [ i ] ) * a < b ) fatiga += ( pueblos [ i + 1 ] - pueblos [ i ] ) * a ; else fatiga += b ; } System . out . println ( fatiga ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { int n , a , b ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; long ans = 0 ; int prevX = sc . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; if ( ( long ) a * ( x - prevX ) < b ) { ans += ( long ) a * ( x - prevX ) ; } else { ans += b ; } prevX = x ; } System . out . println ( ans ) ; } 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 java . util . * ; import java . io . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; public class Main { static final long mod = 1000000007 ; public static void main ( String [ ] args ) throws Exception , IOException { Reader sc = new Reader ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int pre = sc . nextInt ( ) ; long ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int c = sc . nextInt ( ) ; ans += min ( b , ( long ) a * ( c - pre ) ) ; pre = c ; } out . println ( ans ) ; out . flush ( ) ; } static void db ( Object ... os ) { System . err . println ( Arrays . deepToString ( os ) ) ; } } class P implements Comparable < P > { int id , d ; P ( int id , int d ) { this . id = id ; this . d = d ; } public int compareTo ( P p ) { return d - p . d ; } } class Reader { private BufferedReader x ; private StringTokenizer st ; public Reader ( InputStream in ) { x = new BufferedReader ( new InputStreamReader ( in ) ) ; st = null ; } public String nextString ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( x . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( nextString ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( nextString ( ) ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( nextString ( ) ) ; } }",
"import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long [ ] x = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) x [ i ] = sc . nextLong ( ) ; long ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans += Math . min ( A * ( x [ i + 1 ] - x [ i ] ) , B ) ; } PrintWriter out = new PrintWriter ( System . out ) ; out . println ( ans ) ; out . flush ( ) ; } }"
] | [
"n , a , b = map ( int , input ( ) . split ( ) ) NEW_LINE x = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ret = 0 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT ret += min ( a * ( x [ i + 1 ] - x [ i ] ) , b ) NEW_LINE DEDENT print ( ret ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE from functools import partial , reduce NEW_LINE from operator import mul NEW_LINE prod = partial ( reduce , mul ) 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 , A , B = LI ( ) NEW_LINE X = LI ( ) NEW_LINE ans = 0 NEW_LINE for x , y in zip ( X , X [ 1 : ] ) : NEW_LINE INDENT if ( y - x ) * A < B : NEW_LINE INDENT ans += ( y - x ) * A NEW_LINE DEDENT else : NEW_LINE INDENT ans += B NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE",
"( N , A , B ) = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE X = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE hirou = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT length = X [ i + 1 ] - X [ i ] NEW_LINE if length * A <= B : NEW_LINE INDENT hirou += length * A NEW_LINE DEDENT else : NEW_LINE INDENT hirou += B NEW_LINE DEDENT DEDENT print ( hirou ) NEW_LINE",
"N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE X = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE X . insert ( 0 , 0 ) NEW_LINE ans = 0 NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT ans += min ( A * ( X [ i ] - X [ i - 1 ] ) , B ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N , A , B = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE L = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE diff = [ 0 ] * N NEW_LINE for i in range ( N ) : NEW_LINE INDENT diff [ i ] = L [ i ] - L [ i - 1 ] NEW_LINE DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT if diff [ i ] * A >= B : NEW_LINE INDENT ans += B NEW_LINE DEDENT else : NEW_LINE INDENT ans += diff [ i ] * A NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE"
] |
atcoder_abc117_A | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; System . out . println ( ( double ) t / x ) ; } }",
"import java . math . BigDecimal ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; double a = Double . parseDouble ( sc . next ( ) ) ; double b = Double . parseDouble ( sc . next ( ) ) ; double count = 0 ; count = a / b ; System . out . println ( count ) ; System . out . flush ( ) ; sc . close ( ) ; } }",
"import java . math . BigDecimal ; import java . math . RoundingMode ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { BigDecimal number1 = new BigDecimal ( scanner . next ( ) ) ; BigDecimal number2 = new BigDecimal ( scanner . next ( ) ) ; System . out . println ( number1 . divide ( number2 , 10 , RoundingMode . HALF_UP ) ) ; } } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] s = br . readLine ( ) . split ( \" β \" ) ; double ans = Double . parseDouble ( s [ 0 ] ) / Double . parseDouble ( s [ 1 ] ) ; System . out . println ( ans ) ; } }",
"import java . util . * ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double t = sc . nextDouble ( ) ; double x = sc . nextDouble ( ) ; System . out . println ( t / x ) ; sc . close ( ) ; } }"
] | [
"t , x = map ( int , input ( ) . split ( ) ) NEW_LINE print ( ' { :4f } ' . format ( t / x ) ) NEW_LINE",
"a , b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( a / b ) NEW_LINE",
"T , X = map ( int , input ( ) . split ( ) ) NEW_LINE output = T / X NEW_LINE print ( output ) NEW_LINE",
"A = list ( map ( float , input ( ) . split ( ) ) ) NEW_LINE print ( A [ 0 ] / A [ 1 ] ) NEW_LINE",
"T , X = list ( map ( int , input ( ) . split ( ' β ' ) ) ) NEW_LINE print ( float ( T ) / float ( X ) ) NEW_LINE"
] |
atcoder_abc114_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; if ( a == 3 || a == 5 || a == 7 ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } sc . close ( ) ; } }",
"import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { PrintWriter out = new PrintWriter ( System . out ) ; InputStreamScanner in = new InputStreamScanner ( System . in ) ; new Main ( ) . solve ( in , out ) ; out . flush ( ) ; } private void solve ( InputStreamScanner in , PrintWriter out ) { int a = in . nextInt ( ) ; List < Integer > c = Arrays . asList ( 3 , 5 , 7 ) ; out . println ( c . contains ( a ) ? \" YES \" : \" NO \" ) ; } static class InputStreamScanner { private InputStream in ; private byte [ ] buf = new byte [ 1024 ] ; private int len = 0 ; private int off = 0 ; InputStreamScanner ( InputStream in ) { this . in = in ; } String next ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int b = skip ( ) ; ! isSpace ( b ) ; ) { sb . appendCodePoint ( b ) ; b = read ( ) ; } return sb . toString ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } char nextChar ( ) { return ( char ) skip ( ) ; } int skip ( ) { for ( int b ; ( b = read ( ) ) != - 1 ; ) { if ( ! isSpace ( b ) ) { return b ; } } return - 1 ; } private boolean isSpace ( int c ) { return c < 33 || c > 126 ; } private int read ( ) { if ( len == - 1 ) { throw new InputMismatchException ( \" End β of β Input \" ) ; } if ( off >= len ) { off = 0 ; try { len = in . read ( buf ) ; } catch ( IOException e ) { throw new InputMismatchException ( e . getMessage ( ) ) ; } if ( len <= 0 ) { return - 1 ; } } return buf [ off ++ ] ; } } }",
"import java . util . Scanner ; public class Main { static int N ; static String ans = \" NO \" ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; if ( N == 7 || N == 5 || N == 3 ) ans = \" YES \" ; System . out . println ( ans ) ; } }",
"import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; switch ( a ) { case 7 : case 5 : case 3 : System . out . println ( \" YES \" ) ; break ; default : System . out . println ( \" NO \" ) ; break ; } } }",
"import java . util . * ; import java . util . List ; import java . util . ArrayList ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int X = scanner . nextInt ( ) ; if ( X == 3 || X == 5 || X == 7 ) { System . out . println ( \" YES \" ) ; } else { System . out . println ( \" NO \" ) ; } } }"
] | [
"List = [ 7 , 5 , 3 ] NEW_LINE X = int ( input ( ) ) NEW_LINE if X in List : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT",
"age = int ( input ( ) ) NEW_LINE ans = ' YES ' if age == 7 or age == 5 or age == 3 else ' NO ' NEW_LINE print ( ans ) NEW_LINE",
"a = [ \"7\" , \"5\" , \"3\" ] NEW_LINE old = input ( ) NEW_LINE res = \" NO \" NEW_LINE if old in a : NEW_LINE INDENT res = \" YES \" NEW_LINE DEDENT print ( res ) NEW_LINE",
"if int ( input ( ) ) in ( 7 , 5 , 3 ) : NEW_LINE INDENT print ( \" YES \" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" NO \" ) NEW_LINE DEDENT",
"X = input ( ) NEW_LINE if X in [ '3' , '5' , '7' ] : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT"
] |
atcoder_abc107_B | [
"import java . util . Scanner ; import java . util . StringJoiner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; String [ ] [ ] a = new String [ h ] [ w ] ; boolean [ ] row = new boolean [ h ] ; boolean [ ] column = new boolean [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { a [ i ] = sc . next ( ) . split ( \" \" ) ; row [ i ] = false ; } for ( int i = 0 ; i < w ; i ++ ) { column [ i ] = false ; } for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( \" # \" . equals ( a [ i ] [ j ] ) ) { row [ i ] = true ; column [ j ] = true ; } } } for ( int i = 0 ; i < h ; i ++ ) { if ( ! row [ i ] ) { continue ; } StringJoiner sj = new StringJoiner ( \" \" ) ; for ( int j = 0 ; j < w ; j ++ ) { if ( ! column [ j ] ) { continue ; } sj . add ( a [ i ] [ j ] ) ; } System . out . println ( sj . toString ( ) ) ; } } }",
"import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; import static java . util . stream . Collectors . joining ; public class Main { private static final String WHITE = \" . \" ; private static final String BLACK = \" # \" ; public static List < String > process ( int H , int W , List < String > a ) { final List < String > removedBlankRows = a . stream ( ) . filter ( Main :: keepRowWithAnyBlack ) . collect ( Collectors . toList ( ) ) ; final List < String > transposed = transpose ( removedBlankRows ) ; final List < String > compressedTranspose = transposed . stream ( ) . filter ( Main :: keepRowWithAnyBlack ) . collect ( Collectors . toList ( ) ) ; return transpose ( compressedTranspose ) ; } private static boolean keepRowWithAnyBlack ( String row ) { return row . chars ( ) . anyMatch ( Main :: isBlack ) ; } private static boolean isBlack ( int c ) { return c == BLACK . codePointAt ( 0 ) ; } private static List < String > transpose ( List < String > grid ) { if ( grid . isEmpty ( ) ) { return new ArrayList < > ( ) ; } else { final int W = grid . get ( 0 ) . length ( ) ; return IntStream . range ( 0 , W ) . boxed ( ) . map ( i -> grid . stream ( ) . map ( row -> row . substring ( i , i + 1 ) ) . collect ( joining ( ) ) ) . collect ( Collectors . toList ( ) ) ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; final List < String > a = IntStream . range ( 0 , H ) . mapToObj ( i -> sc . next ( ) ) . collect ( Collectors . toList ( ) ) ; final List < String > result = process ( H , W , a ) ; result . forEach ( System . out :: println ) ; } }",
"import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; char [ ] [ ] map = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) map [ i ] = sc . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < h ; i ++ ) { boolean F = true ; for ( int j = 0 ; j < w ; j ++ ) { if ( map [ i ] [ j ] == ' # ' ) { F = false ; break ; } } if ( F == true ) { for ( int j = 0 ; j < w ; j ++ ) { map [ i ] [ j ] = ' x ' ; } } } for ( int i = 0 ; i < w ; i ++ ) { boolean F = true ; for ( int j = 0 ; j < h ; j ++ ) { if ( map [ j ] [ i ] == ' # ' ) { F = false ; break ; } } if ( F == true ) { for ( int j = 0 ; j < h ; j ++ ) { map [ j ] [ i ] = ' x ' ; } } } for ( int i = 0 ; i < h ; i ++ ) { StringBuilder sb = new StringBuilder ( \" \" ) ; boolean F = true ; for ( int j = 0 ; j < w ; j ++ ) { if ( map [ i ] [ j ] != ' x ' ) sb . append ( map [ i ] [ j ] ) ; } if ( ! sb . toString ( ) . equals ( \" \" ) ) System . out . println ( sb ) ; } } }",
"import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int H = input . nextInt ( ) ; int W = input . nextInt ( ) ; String [ ] HS = new String [ H ] ; boolean [ ] rows = new boolean [ H ] ; boolean [ ] cols = new boolean [ W ] ; Arrays . fill ( rows , false ) ; Arrays . fill ( cols , false ) ; for ( int i = 0 ; i < H ; i ++ ) { HS [ i ] = input . next ( ) ; } for ( int j = 0 ; j < H ; j ++ ) { if ( HS [ j ] . indexOf ( \" # \" ) != - 1 ) { rows [ j ] = true ; } for ( int i = 0 ; i < W ; i ++ ) { if ( HS [ j ] . charAt ( i ) == ' # ' ) { cols [ i ] = true ; } } } for ( int i = 0 ; i < H ; i ++ ) { if ( rows [ i ] ) { for ( int j = 0 ; j < W ; j ++ ) { if ( cols [ j ] ) { System . out . print ( HS [ i ] . charAt ( j ) ) ; } } System . out . println ( ) ; } } } }",
"import java . util . List ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; import java . util . stream . Stream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int h = scanner . nextInt ( ) ; int w = scanner . nextInt ( ) ; String [ ] a = Stream . generate ( ( ) -> null ) . limit ( h ) . map ( b -> scanner . next ( ) ) . filter ( b -> b . contains ( \" # \" ) ) . toArray ( String [ ] :: new ) ; List < Integer > i = IntStream . range ( 0 , w ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; for ( String s : a ) i . removeIf ( i2 -> s . charAt ( i2 ) == ' # ' ) ; for ( String s : a ) { char [ ] c = s . toCharArray ( ) ; for ( int j = 0 ; j < c . length ; j ++ ) if ( ! i . contains ( j ) ) System . out . print ( c [ j ] ) ; System . out . println ( ) ; } } }"
] | [
"H , W = map ( int , input ( ) . split ( ) ) NEW_LINE bd = [ ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT bd . append ( input ( ) ) NEW_LINE DEDENT x = set ( ) NEW_LINE y = set ( ) NEW_LINE for i in range ( H ) : NEW_LINE INDENT for j in range ( W ) : NEW_LINE INDENT if bd [ i ] [ j ] == \" # \" : NEW_LINE INDENT x . add ( j ) NEW_LINE y . add ( i ) NEW_LINE DEDENT DEDENT DEDENT for i in y : NEW_LINE INDENT for j in x : NEW_LINE INDENT print ( bd [ i ] [ j ] , end = \" \" ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT",
"f = lambda s : zip ( * [ t for t in s if ' # ' in t ] ) ; print ( * map ( ' ' . join , f ( f ( open ( 0 ) ) ) ) ) NEW_LINE",
"H , W = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ [ 0 ] * W for _ in range ( H ) ] NEW_LINE for h in range ( H ) : NEW_LINE INDENT a [ h ] = [ inp for inp in input ( ) ] NEW_LINE DEDENT check = [ [ 0 ] * W for _ in range ( H ) ] NEW_LINE for h in range ( H ) : NEW_LINE INDENT for w in range ( W ) : NEW_LINE INDENT if a [ h ] [ w ] == ' # ' : NEW_LINE INDENT check [ h ] [ w ] = 1 NEW_LINE DEDENT DEDENT DEDENT final_w = [ 0 ] * W NEW_LINE for h in range ( H ) : NEW_LINE INDENT final_w = [ final_w [ w ] + check [ h ] [ w ] for w in range ( W ) ] NEW_LINE DEDENT final_h = [ 0 ] * H NEW_LINE for w in range ( W ) : NEW_LINE INDENT final_h = [ final_h [ h ] + check [ h ] [ w ] for h in range ( H ) ] NEW_LINE DEDENT for h in range ( H ) : NEW_LINE INDENT res = ' ' NEW_LINE for w in range ( W ) : NEW_LINE INDENT if final_w [ w ] >= 1 and final_h [ h ] >= 1 : NEW_LINE INDENT res += a [ h ] [ w ] NEW_LINE DEDENT DEDENT print ( res + ' \\n ' ) NEW_LINE DEDENT",
"H , W = map ( int , input ( ) . split ( ) ) NEW_LINE box = [ ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT a = [ j for j in input ( ) ] NEW_LINE if all ( j == ' . ' for j in a ) : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT box . append ( a ) NEW_LINE DEDENT DEDENT idx = [ ] NEW_LINE for i in range ( len ( box [ 0 ] ) ) : NEW_LINE INDENT ct = 0 NEW_LINE for j in box : NEW_LINE INDENT if j [ i ] == ' . ' : NEW_LINE INDENT ct += 1 NEW_LINE DEDENT DEDENT if ct == len ( box ) : NEW_LINE INDENT idx . append ( i ) NEW_LINE DEDENT DEDENT for i in box : NEW_LINE INDENT for j in range ( len ( i ) ) : NEW_LINE INDENT if j < len ( i ) - 1 : NEW_LINE INDENT if j in idx : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT print ( i [ j ] , end = ' ' ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if j in idx : NEW_LINE INDENT print ( ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( i [ j ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT",
"def main ( ) : NEW_LINE INDENT H , W = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ [ \" . \" for _ in range ( W ) ] for _ in range ( H ) ] NEW_LINE ans = [ ] NEW_LINE is_column_white = [ True ] * H NEW_LINE is_row_white = [ True ] * W NEW_LINE for i in range ( H ) : NEW_LINE INDENT row = input ( ) NEW_LINE for j in range ( W ) : NEW_LINE INDENT a [ i ] [ j ] = row [ j ] NEW_LINE if row [ j ] == \" # \" : NEW_LINE INDENT is_column_white [ i ] = False NEW_LINE is_row_white [ j ] = False NEW_LINE DEDENT DEDENT DEDENT for i in range ( H ) : NEW_LINE INDENT if is_column_white [ i ] : NEW_LINE INDENT continue NEW_LINE DEDENT ans_row = \" \" NEW_LINE for j in range ( W ) : NEW_LINE INDENT if is_row_white [ j ] : NEW_LINE INDENT continue NEW_LINE DEDENT ans_row += a [ i ] [ j ] NEW_LINE DEDENT print ( ans_row ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT"
] |
atcoder_arc008_B | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; String name = sc . next ( ) ; String kit = sc . next ( ) ; char n [ ] = new char [ 26 ] ; char m [ ] = new char [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { char nc = name . charAt ( i ) ; n [ nc - ' A ' ] ++ ; } for ( int i = 0 ; i < M ; i ++ ) { char nk = kit . charAt ( i ) ; m [ nk - ' A ' ] ++ ; } int an = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { char target = name . charAt ( i ) ; int count = 0 ; if ( m [ target - ' A ' ] == 0 ) { System . out . println ( - 1 ) ; return ; } if ( n [ target - ' A ' ] % m [ target - ' A ' ] == 0 ) { count = n [ target - ' A ' ] / m [ target - ' A ' ] ; } else { count = n [ target - ' A ' ] / m [ target - ' A ' ] + 1 ; } an = Math . max ( an , count ) ; } System . out . println ( an ) ; } }",
"import java . io . * ; import java . util . * ; import java . math . * ; public class Main { static boolean debug = false ; static boolean debug2 = false ; public static void main ( String [ ] args ) throws java . io . IOException { debug = 1 <= args . length ; debug2 = 2 <= args . length ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; in . readLine ( ) ; final String name = in . readLine ( ) ; final String kit = in . readLine ( ) ; int [ ] name_count = new int [ ' Z ' - ' A ' + 1 ] ; int [ ] kit_count = new int [ name_count . length ] ; for ( int i = 0 ; i < name . length ( ) ; ++ i ) { ++ name_count [ name . charAt ( i ) - ' A ' ] ; } for ( int i = 0 ; i < kit . length ( ) ; ++ i ) { ++ kit_count [ kit . charAt ( i ) - ' A ' ] ; } int ans = 0 ; for ( int i = 0 ; i < kit_count . length ; ++ i ) { if ( kit_count [ i ] == 0 ) { if ( 0 < name_count [ i ] ) { ans = - 1 ; break ; } } else { ans = Math . max ( ans , name_count [ i ] / kit_count [ i ] + ( 0 < name_count [ i ] % kit_count [ i ] ? 1 : 0 ) ) ; } } System . out . println ( ans ) ; } }",
"import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { static final Scanner s = new Scanner ( System . in ) ; static IntStream REPS ( int v ) { return IntStream . range ( 0 , v ) ; } static IntStream REPS ( int l , int r ) { return IntStream . rangeClosed ( l , r ) ; } static IntStream INS ( int n ) { return REPS ( n ) . map ( i -> getInt ( ) ) ; } static int getInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } public static void main ( String [ ] $ ) { int [ ] name = new int [ 26 ] , kit = new int [ 26 ] ; s . next ( ) ; s . next ( ) ; s . next ( ) . chars ( ) . forEach ( i -> ++ name [ i - ' A ' ] ) ; s . next ( ) . chars ( ) . forEach ( i -> ++ kit [ i - ' A ' ] ) ; if ( REPS ( 26 ) . anyMatch ( i -> name [ i ] > 0 && kit [ i ] == 0 ) ) { System . out . println ( - 1 ) ; return ; } System . out . println ( REPS ( 26 ) . map ( i -> name [ i ] == 0 ? 0 : ( name [ i ] + kit [ i ] - 1 ) / kit [ i ] ) . max ( ) . getAsInt ( ) ) ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] setting = br . readLine ( ) . split ( \" β \" ) ; int nameNum = Integer . parseInt ( setting [ 0 ] ) ; int kitLetterNum = Integer . parseInt ( setting [ 1 ] ) ; String [ ] nameArray = br . readLine ( ) . split ( \" \" ) ; String [ ] kitArray = br . readLine ( ) . split ( \" \" ) ; int count = 1 ; int nullNum = 0 ; while ( true ) { for ( int i = 0 ; i < kitLetterNum ; i ++ ) { for ( int j = 0 ; j < nameNum ; j ++ ) { if ( nameArray [ j ] == null ) { } else if ( nameArray [ j ] . equals ( kitArray [ i ] ) ) { nameArray [ j ] = null ; nullNum ++ ; break ; } } } if ( nullNum == nameNum ) { break ; } else if ( count == 50000 ) { count = - 1 ; break ; } else { count ++ ; } } System . out . println ( count ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; String name = sc . next ( ) ; String kit = sc . next ( ) ; HashMap < String , Integer > namemap = new HashMap < String , Integer > ( ) ; HashMap < String , Integer > kitmap = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String s = String . valueOf ( name . charAt ( i ) ) ; if ( namemap . containsKey ( s ) ) { namemap . put ( s , namemap . get ( s ) + 1 ) ; } else { namemap . put ( s , 1 ) ; } } for ( int i = 0 ; i < M ; i ++ ) { String s = String . valueOf ( kit . charAt ( i ) ) ; if ( kitmap . containsKey ( s ) ) { kitmap . put ( s , kitmap . get ( s ) + 1 ) ; } else { kitmap . put ( s , 1 ) ; } } int ans = 0 ; for ( String s : namemap . keySet ( ) ) { int num1 = namemap . get ( s ) ; int num2 = 0 ; if ( kitmap . containsKey ( s ) ) num2 = kitmap . get ( s ) ; if ( num2 == 0 ) { ans = - 1 ; break ; } else { ans = Math . max ( ans , ( num1 + num2 - 1 ) / num2 ) ; } } System . out . println ( ans ) ; } }"
] | [
"n , m = map ( int , input ( ) . split ( ) ) NEW_LINE N = list ( input ( ) ) NEW_LINE K = list ( input ( ) ) NEW_LINE dic_N = { } NEW_LINE for i in N : NEW_LINE INDENT if i not in dic_N : NEW_LINE INDENT dic_N [ i ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic_N [ i ] += 1 NEW_LINE DEDENT DEDENT dic_K = { } NEW_LINE for i in K : NEW_LINE INDENT if i not in dic_K : NEW_LINE INDENT dic_K [ i ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic_K [ i ] += 1 NEW_LINE DEDENT DEDENT cou = 0 NEW_LINE for i in dic_N : NEW_LINE INDENT ni = dic_N [ i ] NEW_LINE if i not in dic_K : NEW_LINE INDENT cou = - 1 NEW_LINE break NEW_LINE DEDENT ki = dic_K [ i ] NEW_LINE re = ni // ki NEW_LINE if ni % ki != 0 : NEW_LINE INDENT re += 1 NEW_LINE DEDENT cou = max ( cou , re ) NEW_LINE DEDENT print ( cou ) NEW_LINE",
"I = input ; I ( ) ; s , t = I ( ) , I ( ) ; print ( - ( len ( set ( s ) - set ( t ) ) > 0 ) or - min ( - s . count ( c ) // t . count ( c ) for c in s ) ) NEW_LINE",
"import sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE from collections import Counter NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE name = input ( ) . rstrip ( ) NEW_LINE kit = input ( ) . rstrip ( ) NEW_LINE name_cnt = Counter ( name ) NEW_LINE kit_cnt = Counter ( kit ) NEW_LINE for key , val in name_cnt . items ( ) : NEW_LINE INDENT if kit_cnt [ key ] == 0 : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for key , val in name_cnt . items ( ) : NEW_LINE INDENT d = kit_cnt [ key ] NEW_LINE ans = max ( ans , ( val + d - 1 ) // d ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"def b_uncle ( N , M , Name , Kit ) : NEW_LINE INDENT from collections import defaultdict NEW_LINE name_usechar = defaultdict ( int ) NEW_LINE for c in Name : NEW_LINE INDENT name_usechar [ c ] += 1 NEW_LINE DEDENT kit_chars = defaultdict ( int ) NEW_LINE for c in Kit : NEW_LINE INDENT kit_chars [ c ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for key in name_usechar . keys ( ) : NEW_LINE INDENT if kit_chars [ key ] == 0 : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT ans = max ( ans , ( name_usechar [ key ] + kit_chars [ key ] - 1 ) // kit_chars [ key ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE Name = input ( ) NEW_LINE Kit = input ( ) NEW_LINE print ( b_uncle ( N , M , Name , Kit ) ) NEW_LINE",
"N , M = map ( int , input ( ) . split ( ) ) NEW_LINE n = input ( ) NEW_LINE k = input ( ) NEW_LINE A = [ \" A \" , \" B \" , \" C \" , \" D \" , \" E \" , \" F \" , \" G \" , \" H \" , \" I \" , \" J \" , \" K \" , \" L \" , \" M \" , \" N \" , \" O \" , \" P \" , \" Q \" , \" R \" , \" S \" , \" T \" , \" U \" , \" V \" , \" W \" , \" X \" , \" Y \" , \" Z \" ] NEW_LINE a = [ 0 for i in range ( 26 ) ] NEW_LINE for i in range ( len ( n ) ) : NEW_LINE INDENT for j in range ( 26 ) : NEW_LINE INDENT if n [ i ] == A [ j ] : NEW_LINE INDENT a [ j ] += 1 NEW_LINE DEDENT DEDENT DEDENT b = [ 0 for i in range ( 26 ) ] NEW_LINE for l in range ( len ( k ) ) : NEW_LINE INDENT for m in range ( 26 ) : NEW_LINE INDENT if k [ l ] == A [ m ] : NEW_LINE INDENT b [ m ] += 1 NEW_LINE DEDENT DEDENT DEDENT for x in range ( 1 , 51 ) : NEW_LINE INDENT cnt = 0 NEW_LINE for y in range ( 26 ) : NEW_LINE INDENT if a [ y ] <= b [ y ] * x : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if cnt == 26 : NEW_LINE INDENT print ( x ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( - 1 ) NEW_LINE"
] |
atcoder_abc029_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String a = scan . next ( ) ; System . out . println ( a + \" s \" ) ; } }",
"import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { out . println ( in . next ( ) + \" s \" ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isPrintableChar ( int c ) { return c >= 33 && c <= 126 ; } public String next ( ) { StringBuilder sb = new StringBuilder ( ) ; int b = readByte ( ) ; while ( ! isPrintableChar ( b ) ) b = readByte ( ) ; while ( isPrintableChar ( b ) ) { sb . appendCodePoint ( b ) ; b = readByte ( ) ; } return sb . toString ( ) ; } } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; String s = sc . next ( ) ; System . out . println ( s + \" s \" ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = \" \" ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . ArrayDeque ; import java . util . Queue ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { out . println ( in . next ( ) + \" s \" ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }",
"import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { out . println ( sc . next ( ) + \" s \" ) ; } }"
] | [
"W = input ( ' ' ) NEW_LINE print ( W + ' s ' ) NEW_LINE",
"def start_process ( ) : NEW_LINE INDENT X , Y , Z , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE return NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT print ( input ( ) + ' s ' ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT",
"def plural ( w : str ) -> str : NEW_LINE INDENT return w + ' s ' NEW_LINE DEDENT if __name__ == \" _ _ main _ _ \" : NEW_LINE INDENT w = input ( ) NEW_LINE ans = plural ( w ) NEW_LINE print ( ans ) NEW_LINE DEDENT",
"w = input ( ) NEW_LINE w = w + \" s \" NEW_LINE print ( w ) NEW_LINE",
"print ( input ( ) . strip ( ) + ' s ' ) NEW_LINE"
] |
atcoder_abc117_D | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long k = sc . nextLong ( ) ; int [ ] p = new int [ 44 ] ; long [ ] a1 = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { long a = sc . nextLong ( ) ; a1 [ i ] = a ; int count = 0 ; while ( a > 0 ) { if ( ( a & 1 ) == 1 ) { p [ count ] ++ ; } a >>= 1 ; count ++ ; } } long [ ] pow = new long [ 44 ] ; pow [ 0 ] = 1 ; for ( int i = 1 ; i < 44 ; i ++ ) { pow [ i ] = pow [ i - 1 ] * 2 ; } long ans = 0 ; for ( int i = 43 ; i >= 0 ; i -- ) { if ( p [ i ] * 2 <= n ) { if ( ans + pow [ i ] <= k ) { ans += pow [ i ] ; } } } long an = 0 ; for ( int i = 0 ; i < n ; i ++ ) { an += ans ^ a1 [ i ] ; } System . out . println ( an ) ; } }",
"import java . util . * ; import static java . lang . System . * ; public class Main { public static final int MAX_BIT = 39 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long K = sc . nextLong ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextLong ( ) ; } int [ ] oneBitNums = new int [ MAX_BIT + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j <= MAX_BIT ; j ++ ) { if ( ( A [ i ] >> j & 1 ) == 1 ) { oneBitNums [ j ] ++ ; } } } int [ ] xBits = new int [ MAX_BIT + 1 ] ; for ( int i = MAX_BIT ; i >= 0 ; i -- ) { if ( oneBitNums [ i ] <= N / 2 ) { xBits [ i ] = 1 ; } } long X = 0 ; for ( int i = MAX_BIT ; i >= 0 ; i -- ) { if ( xBits [ i ] == 1 ) { long num = ( long ) Math . pow ( 2.0 , i ) ; if ( X + num <= K ) { X += num ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += X ^ A [ i ] ; } out . println ( ans ) ; } }",
"import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { String [ ] nm = sc . nextLine ( ) . split ( \" β \" ) ; int n = Integer . parseInt ( nm [ 0 ] ) ; long k = Long . parseLong ( nm [ 1 ] ) ; String [ ] alist = sc . nextLine ( ) . split ( \" β \" ) ; long [ ] aary = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { aary [ i ] = Long . parseLong ( alist [ i ] ) ; } String [ ] bsary = new String [ n ] ; int maxbslen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { bsary [ i ] = Long . toBinaryString ( aary [ i ] ) ; maxbslen = Math . max ( maxbslen , bsary [ i ] . length ( ) ) ; } long bitcount [ ] = new long [ maxbslen ] ; for ( String bs : bsary ) { for ( int j = bs . length ( ) - 1 ; j >= 0 ; j -- ) { if ( bs . charAt ( j ) == '1' ) { bitcount [ bs . length ( ) - 1 - j ] ++ ; } } } int xdigit = Long . toBinaryString ( k ) . length ( ) ; long x = 0 ; for ( int i = xdigit - 1 ; i >= 0 ; i -- ) { long next = x + ( long ) Math . pow ( 2 , i ) ; if ( next <= k ) { if ( i >= bitcount . length ) { x = next ; } else { if ( bitcount [ i ] <= n / 2 ) { x = next ; } } } } long f = 0 ; for ( long a : aary ) { f += x ^ a ; } System . out . println ( f ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; long K = scanner . nextLong ( ) ; int [ ] digits = new int [ 41 ] ; int t = 0 ; while ( K > 0 ) { if ( K % 2 == 1 ) digits [ t ] = 1 ; K /= 2 ; t ++ ; } int [ ] numOnes = new int [ 41 ] ; for ( int i = 0 ; i < N ; i ++ ) { long a = scanner . nextLong ( ) ; int j = 0 ; while ( a > 0 ) { if ( a % 2 == 1 ) numOnes [ j ] ++ ; a /= 2 ; j ++ ; } } long [ ] [ ] dp = new long [ 42 ] [ 2 ] ; for ( int i = 40 ; i >= 0 ; i -- ) { long d = 1L << i ; int ones = numOnes [ i ] ; int zeros = N - ones ; if ( digits [ i ] == 0 ) { dp [ i ] [ 0 ] = dp [ i + 1 ] [ 0 ] + d * ones ; if ( dp [ i + 1 ] [ 1 ] > 0 ) dp [ i ] [ 1 ] = dp [ i + 1 ] [ 1 ] + d * Math . max ( ones , zeros ) ; } else { dp [ i ] [ 0 ] = dp [ i + 1 ] [ 0 ] + d * zeros ; dp [ i ] [ 1 ] = dp [ i + 1 ] [ 0 ] + d * ones ; if ( dp [ i + 1 ] [ 1 ] > 0 ) dp [ i ] [ 1 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i + 1 ] [ 1 ] + d * Math . max ( ones , zeros ) ) ; } } System . out . println ( Math . max ( dp [ 0 ] [ 0 ] , dp [ 0 ] [ 1 ] ) ) ; } }",
"import java . util . Scanner ; public class Main { static int MAX_DIGIT = 60 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long k = Long . parseLong ( sc . next ( ) ) ; long [ ] A = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = Long . parseLong ( sc . next ( ) ) ; } sc . close ( ) ; long res = 0 ; for ( int d = MAX_DIGIT ; d >= - 1 ; -- d ) { if ( d != - 1 && ! ( ( k & 1L << d ) != 0 ) ) continue ; long tmp = 0 ; for ( int e = MAX_DIGIT ; e >= 0 ; -- e ) { long mask = 1L << e ; int num = 0 ; for ( int i = 0 ; i < n ; ++ i ) if ( ( A [ i ] & mask ) != 0 ) ++ num ; if ( e > d ) { if ( ( k & mask ) != 0 ) tmp += mask * ( n - num ) ; else tmp += mask * num ; } else if ( e == d ) { tmp += mask * num ; } else { tmp += mask * Math . max ( num , n - num ) ; } } res = Math . max ( res , tmp ) ; } System . out . println ( res ) ; } }"
] | [
"n , k = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE cnt = [ 0 ] * 50 NEW_LINE for i in a : NEW_LINE INDENT for j in range ( 50 ) : NEW_LINE INDENT if i & ( 1 << j ) == 0 : NEW_LINE INDENT cnt [ j ] += 1 << j NEW_LINE DEDENT else : NEW_LINE INDENT cnt [ j ] -= 1 << j NEW_LINE DEDENT DEDENT DEDENT gg = [ ] NEW_LINE for i in range ( 50 ) : NEW_LINE INDENT gg . append ( [ cnt [ i ] , i ] ) NEW_LINE DEDENT gg . sort ( reverse = True ) NEW_LINE ans = 0 NEW_LINE for i in gg : NEW_LINE INDENT if i [ 0 ] < 0 : NEW_LINE INDENT break NEW_LINE DEDENT if ( 1 << i [ 1 ] ) <= k : NEW_LINE INDENT k -= 1 << i [ 1 ] NEW_LINE ans += i [ 0 ] NEW_LINE DEDENT DEDENT print ( ans + sum ( a ) ) NEW_LINE",
"num_terms , max_value = map ( int , input ( ) . split ( ) ) NEW_LINE coef = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE res = 0 NEW_LINE for i in range ( 40 , - 1 , - 1 ) : NEW_LINE INDENT num_bits = 0 NEW_LINE for a in coef : NEW_LINE INDENT num_bits += ( ( a >> i ) & 1 ) NEW_LINE DEDENT cand = 2 ** i NEW_LINE if ( num_terms - num_bits ) > num_bits and cand <= max_value : NEW_LINE INDENT res += ( num_terms - num_bits ) * cand NEW_LINE max_value -= cand NEW_LINE DEDENT else : NEW_LINE INDENT res += num_bits * cand NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE",
"from functools import lru_cache NEW_LINE def get_bit ( n , d ) : NEW_LINE INDENT return ( n >> d ) & 1 NEW_LINE DEDENT @ lru_cache ( maxsize = None ) NEW_LINE def xor ( bit , digit ) : NEW_LINE INDENT assert bit in [ 0 , 1 ] NEW_LINE if bit == 0 : NEW_LINE INDENT return bit_counts [ digit ] << digit NEW_LINE DEDENT else : NEW_LINE INDENT return ( N - bit_counts [ digit ] ) << digit NEW_LINE DEDENT DEDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE DIGIT = 50 NEW_LINE bit_counts = [ sum ( [ get_bit ( a , d = d ) for a in A ] ) for d in range ( DIGIT ) ] NEW_LINE dp = [ [ - float ( ' inf ' ) for _ in range ( 2 ) ] for _ in range ( DIGIT + 1 ) ] NEW_LINE dp [ - 1 ] [ 0 ] = 0 NEW_LINE for d in reversed ( range ( DIGIT ) ) : NEW_LINE INDENT k = get_bit ( K , d = d ) NEW_LINE dp [ d ] [ 0 ] = max ( dp [ d ] [ 0 ] , dp [ d + 1 ] [ 0 ] + xor ( bit = k , digit = d ) ) NEW_LINE if k == 1 : NEW_LINE INDENT dp [ d ] [ 1 ] = max ( dp [ d ] [ 1 ] , dp [ d + 1 ] [ 0 ] + xor ( bit = 0 , digit = d ) ) NEW_LINE DEDENT dp [ d ] [ 1 ] = max ( dp [ d ] [ 1 ] , dp [ d + 1 ] [ 1 ] + xor ( bit = 0 , digit = d ) ) NEW_LINE dp [ d ] [ 1 ] = max ( dp [ d ] [ 1 ] , dp [ d + 1 ] [ 1 ] + xor ( bit = 1 , digit = d ) ) NEW_LINE DEDENT print ( max ( dp [ 0 ] ) ) NEW_LINE",
"def solve ( string ) : NEW_LINE INDENT n , k , * a = map ( int , string . split ( ) ) NEW_LINE if k == 0 : NEW_LINE INDENT x = 0 NEW_LINE DEDENT else : NEW_LINE INDENT l = len ( \" { : b } \" . format ( k ) ) NEW_LINE base = [ 2 ** ( l - i - 1 ) for i in range ( l ) ] NEW_LINE count = [ 0 ] * l NEW_LINE for _a in a : NEW_LINE INDENT tmp = \" { : b } \" . format ( _a ) NEW_LINE for i , _f in enumerate ( tmp [ : : - 1 ] ) : NEW_LINE INDENT if i >= l : NEW_LINE INDENT break NEW_LINE DEDENT if _f == \"1\" : NEW_LINE INDENT count [ l - i - 1 ] += 1 NEW_LINE DEDENT DEDENT DEDENT x = 0 NEW_LINE for _c , _b in zip ( count , base ) : NEW_LINE INDENT if _c < n / 2 and x + _b <= k : NEW_LINE INDENT x += _b NEW_LINE DEDENT DEDENT DEDENT return str ( sum ( [ x ^ _a for _a in a ] ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( solve ( ' \\n ' . join ( [ input ( ) , input ( ) ] ) ) ) NEW_LINE DEDENT",
"import math NEW_LINE n , k = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE bit_num = math . floor ( math . log2 ( max ( max ( a ) , k ) ) ) + 1 NEW_LINE num_one = [ ] NEW_LINE for i in range ( bit_num ) : NEW_LINE INDENT num_one_tmp = 0 NEW_LINE for j in a : NEW_LINE INDENT num_one_tmp += ( j >> i ) & 1 NEW_LINE DEDENT num_one . append ( num_one_tmp ) NEW_LINE DEDENT if k == 0 : NEW_LINE INDENT bit_k = 1 NEW_LINE DEDENT else : NEW_LINE INDENT bit_k = math . floor ( math . log2 ( k ) ) + 1 NEW_LINE DEDENT constant_ans = 0 NEW_LINE for i in range ( bit_k , bit_num ) : NEW_LINE INDENT constant_ans += num_one [ i ] * 2 ** i NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( bit_k ) [ : : - 1 ] : NEW_LINE INDENT if 2 ** i > k : NEW_LINE INDENT constant_ans += num_one [ i ] * 2 ** i NEW_LINE DEDENT else : NEW_LINE INDENT variant_ans = num_one [ i ] * 2 ** i NEW_LINE for j in range ( i ) : NEW_LINE INDENT if num_one [ j ] >= ( n + 1 ) // 2 : NEW_LINE INDENT variant_ans += num_one [ j ] * 2 ** j NEW_LINE DEDENT else : NEW_LINE INDENT variant_ans += ( n - num_one [ j ] ) * 2 ** j NEW_LINE DEDENT DEDENT ans = max ( ans , constant_ans + variant_ans ) NEW_LINE constant_ans += ( n - num_one [ i ] ) * 2 ** i NEW_LINE k -= 2 ** i NEW_LINE DEDENT DEDENT ans = max ( ans , constant_ans ) NEW_LINE print ( ans ) NEW_LINE"
] |
atcoder_abc112_A | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( \" Hello β World \" ) ; } else { int A = sc . nextInt ( ) , B = sc . nextInt ( ) ; System . out . println ( A + B ) ; } sc . close ( ) ; } }",
"import java . util . Optional ; import java . util . Scanner ; public class Main { private static final String HELLO_WORLD = \" Hello β World \" ; public static String process ( TestCase testCase ) { final int N = testCase . N ; switch ( N ) { case 1 : return HELLO_WORLD ; case 2 : { final int A = unsafeGet ( testCase . A , \" A \" ) ; final int B = unsafeGet ( testCase . B , \" B \" ) ; return String . valueOf ( A + B ) ; } default : { throw unknownN ( N ) ; } } } private static int unsafeGet ( Optional < Integer > argument , String argumentName ) { return argument . orElseThrow ( ( ) -> new IllegalArgumentException ( \" Missing β Argument β \" + argumentName ) ) ; } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; switch ( N ) { case 1 : { sc . close ( ) ; return new TestCase ( N ) ; } case 2 : { int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; sc . close ( ) ; return new TestCase ( N , A , B ) ; } default : { throw unknownN ( N ) ; } } } private static IllegalArgumentException unknownN ( int N ) { return new IllegalArgumentException ( \" Unknown β N : β \" + N ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final int N ; final Optional < Integer > A ; final Optional < Integer > B ; public TestCase ( int N ) { this . N = N ; this . A = Optional . empty ( ) ; this . B = Optional . empty ( ) ; } public TestCase ( int N , int A , int B ) { this . N = N ; this . A = Optional . of ( A ) ; this . B = Optional . of ( B ) ; } } }",
"import java . io . InputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Main { InputStream in = System . in ; PrintStream out = System . out ; public void _main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; if ( n == 1 ) { out . println ( \" Hello β World \" ) ; } else { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; out . println ( a + b ) ; } sc . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } }",
"import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( System . in ) ; int n ; n = Integer . parseInt ( sc . next ( ) ) ; if ( n == 1 ) { System . out . println ( \" Hello β World \" ) ; } if ( n == 2 ) { int a , b ; a = Integer . parseInt ( sc . next ( ) ) ; b = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( a + b ) ; } } catch ( Exception e ) { System . out . println ( \" out \" ) ; } } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; int N = reader . nextInt ( ) ; String result = \" \" ; if ( N == 1 ) { result = \" Hello β World \" ; } else { int A = reader . nextInt ( ) ; int B = reader . nextInt ( ) ; result = Integer . toString ( A + B ) ; } reader . close ( ) ; System . out . print ( result ) ; } }"
] | [
"N = int ( input ( ) ) NEW_LINE if N == 1 : NEW_LINE INDENT print ( \" Hello β World \" ) NEW_LINE DEDENT else : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE B = int ( input ( ) ) NEW_LINE print ( A + B ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE if ( N == 2 ) : NEW_LINE INDENT A = int ( input ( ) ) NEW_LINE B = int ( input ( ) ) NEW_LINE print ( int ( A + B ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( \" Hello β World \" ) NEW_LINE DEDENT",
"N = int ( input ( ) ) NEW_LINE if N == 1 : NEW_LINE INDENT print ( ' Hello β World ' ) NEW_LINE exit ( ) NEW_LINE DEDENT else : NEW_LINE INDENT l = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT l . append ( int ( input ( ) ) ) NEW_LINE DEDENT DEDENT print ( sum ( l ) ) NEW_LINE",
"if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE if n == 1 : NEW_LINE INDENT print ( \" Hello β World \" ) NEW_LINE DEDENT if n == 2 : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE b = int ( input ( ) ) NEW_LINE print ( a + b ) NEW_LINE DEDENT DEDENT",
"a = int ( input ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT print ( \" Hello β World \" ) NEW_LINE DEDENT elif a == 2 : NEW_LINE INDENT b = int ( input ( ) ) NEW_LINE c = int ( input ( ) ) NEW_LINE print ( b + c ) NEW_LINE DEDENT"
] |
atcoder_abc018_D | [
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n , m , p , q , r ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; p = sc . nextInt ( ) ; q = sc . nextInt ( ) ; r = sc . nextInt ( ) ; int [ ] [ ] mat = new int [ n ] [ m ] ; for ( int i = 0 ; i < r ; ++ i ) { int x , y , z ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; z = sc . nextInt ( ) ; -- x ; -- y ; mat [ x ] [ y ] = z ; } int ans = 0 ; for ( int s = 0 ; s < 1 << n ; ++ s ) { if ( Integer . bitCount ( s ) != p ) continue ; int [ ] a = new int [ m ] ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < n ; ++ j ) { if ( ( ( s >> j ) & 1 ) > 0 ) { a [ i ] += mat [ j ] [ i ] ; } } } Arrays . sort ( a ) ; int tmp = 0 ; for ( int i = 0 ; i < q ; ++ i ) { tmp += a [ a . length - 1 - i ] ; } ans = Math . max ( ans , tmp ) ; } System . out . println ( ans ) ; } static void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } }",
"import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; final int M = sc . nextInt ( ) ; final int P = sc . nextInt ( ) ; final int Q = sc . nextInt ( ) ; final int R = sc . nextInt ( ) ; int [ ] x = new int [ R ] ; int [ ] y = new int [ R ] ; int [ ] z = new int [ R ] ; for ( int i = 0 ; i < R ; i ++ ) { x [ i ] = sc . nextInt ( ) - 1 ; y [ i ] = sc . nextInt ( ) - 1 ; z [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int max = ( int ) Math . pow ( 2 , N ) ; int ans = 0 ; for ( int i = 1 ; i < ( int ) Math . pow ( 2 , N ) ; i ++ ) { String comb = Integer . toBinaryString ( i ) ; int count = 0 ; while ( comb . length ( ) < N ) comb = \"0\" + comb ; for ( int j = 0 ; j < N ; j ++ ) if ( comb . charAt ( j ) == '1' ) count ++ ; if ( count == P ) { int [ ] boy = new int [ M ] ; for ( int j = 0 ; j < R ; j ++ ) { if ( comb . charAt ( x [ j ] ) == '1' ) boy [ y [ j ] ] += z [ j ] ; } Arrays . sort ( boy ) ; int tmp = 0 ; for ( int j = M - 1 ; j >= M - Q ; j -- ) tmp += boy [ j ] ; ans = Math . max ( tmp , ans ) ; } } System . out . println ( ans ) ; } }",
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int P = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; int [ ] [ ] z = new int [ n ] [ m ] ; for ( int i = 0 ; i < R ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; z [ x - 1 ] [ y - 1 ] = sc . nextInt ( ) ; } HashSet < Integer > boyCan = new HashSet < > ( ) ; calCan ( boyCan , m , Q ) ; int ans = 0 ; for ( Integer w : boyCan ) { int cur = w ; ArrayList < Integer > boys = new ArrayList < > ( ) ; for ( int i = 0 ; i < 19 ; i ++ ) { if ( ( cur & ( 1 << i ) ) > 0 ) boys . add ( i ) ; } int sum = 0 ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; for ( int girl = 0 ; girl < n ; girl ++ ) { int now = 0 ; for ( int boy : boys ) now += z [ girl ] [ boy ] ; pq . add ( now ) ; sum += now ; if ( pq . size ( ) > P ) sum -= pq . poll ( ) ; } ans = Math . max ( ans , sum ) ; } System . out . println ( ans ) ; } static void calCan ( HashSet < Integer > boyCan , int m , int Q ) { for ( int i = 1 ; i <= ( 1 << m ) - 1 ; i ++ ) { if ( numOfOne ( i ) == Q ) boyCan . add ( i ) ; } } static int numOfOne ( int s ) { int cnt = 0 ; while ( s > 0 ) { if ( s % 2 == 1 ) cnt ++ ; s = s / 2 ; } return cnt ; } }",
"import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , M = sc . nextInt ( ) , P = sc . nextInt ( ) , Q = sc . nextInt ( ) , R = sc . nextInt ( ) ; int choco [ ] [ ] = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { choco [ i ] [ j ] = 0 ; } } for ( int i = 0 ; i < R ; i ++ ) { int x = sc . nextInt ( ) - 1 , y = sc . nextInt ( ) - 1 , z = sc . nextInt ( ) ; choco [ x ] [ y ] = z ; } int ans = 0 ; int comb = ( 1 << P ) - 1 ; while ( comb < ( 1 << N ) ) { int men [ ] = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { men [ i ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { if ( ( comb >> i & 1 ) == 1 ) { for ( int j = 0 ; j < M ; j ++ ) { men [ j ] += choco [ i ] [ j ] ; } } } Arrays . sort ( men ) ; int cand = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { cand += men [ M - i - 1 ] ; } ans = Math . max ( ans , cand ) ; int x = comb & - comb , y = comb + x ; comb = ( ( comb & ~ y ) / x >> 1 ) | y ; } System . out . println ( ans ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int m = s . nextInt ( ) ; int p = s . nextInt ( ) ; int q = s . nextInt ( ) ; int r = s . nextInt ( ) ; int [ ] [ ] score = new int [ n ] [ m ] ; for ( int i = 0 ; i < r ; i ++ ) { int x = s . nextInt ( ) - 1 ; int y = s . nextInt ( ) - 1 ; score [ x ] [ y ] = s . nextInt ( ) ; } int topScore = 0 ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { boolean [ ] xSelected = new boolean [ n ] ; int xSelectedCount = 0 ; for ( int j = 0 ; j < n ; j ++ ) { xSelected [ j ] = ( i & ( 1 << j ) ) != 0 ; if ( xSelected [ j ] ) { xSelectedCount ++ ; } } if ( xSelectedCount != p ) { continue ; } int [ ] yScore = new int [ m ] ; for ( int k = 0 ; k < m ; k ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( xSelected [ j ] ) { yScore [ k ] += score [ j ] [ k ] ; } } } Arrays . sort ( yScore ) ; int sumScore = 0 ; for ( int k = 0 ; k < q ; k ++ ) { sumScore += yScore [ m - 1 - k ] ; } topScore = Math . max ( topScore , sumScore ) ; } System . out . println ( topScore ) ; } }"
] | [
"import itertools NEW_LINE n , m , p , q , r = map ( int , input ( ) . split ( ) ) NEW_LINE x = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( r ) ] NEW_LINE c = list ( itertools . combinations ( range ( n ) , p ) ) NEW_LINE wata = [ [ 0 ] * m for i in range ( n ) ] NEW_LINE MAX = 0 NEW_LINE for i in x : NEW_LINE INDENT wata [ i [ 0 ] - 1 ] [ i [ 1 ] - 1 ] += i [ 2 ] NEW_LINE DEDENT for i in c : NEW_LINE INDENT mora = [ 0 ] * m NEW_LINE for j in i : NEW_LINE INDENT for k in range ( m ) : NEW_LINE INDENT mora [ k ] += wata [ j ] [ k ] NEW_LINE DEDENT DEDENT mora . sort ( ) NEW_LINE mora = mora [ : : - 1 ] NEW_LINE mora = mora [ : q ] NEW_LINE MAX = max ( MAX , sum ( mora ) ) NEW_LINE DEDENT print ( MAX ) NEW_LINE",
"N , M , P , Q , R = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE Z = [ [ ] for x in range ( N ) ] NEW_LINE for i in range ( R ) : NEW_LINE INDENT x , y , z = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE Z [ x - 1 ] . append ( ( y - 1 , z ) ) NEW_LINE DEDENT from itertools import combinations NEW_LINE ans = 0 NEW_LINE for C in combinations ( range ( N ) , P ) : NEW_LINE INDENT man = [ 0 ] * M NEW_LINE for c in C : NEW_LINE INDENT for z in Z [ c ] : NEW_LINE INDENT man [ z [ 0 ] ] += z [ 1 ] NEW_LINE DEDENT DEDENT man . sort ( reverse = True ) NEW_LINE ans = max ( ans , sum ( man [ : Q ] ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"def d_valentine ( N , M , P , Q , R , C ) : NEW_LINE INDENT from itertools import combinations NEW_LINE choco = [ [ 0 ] * M for _ in range ( N ) ] NEW_LINE for row in C : NEW_LINE INDENT choco [ row [ 0 ] - 1 ] [ row [ 1 ] - 1 ] = row [ 2 ] NEW_LINE DEDENT ans = 0 NEW_LINE for girl in combinations ( range ( N ) , P ) : NEW_LINE INDENT target = [ 0 ] * M NEW_LINE for i in girl : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT target [ j ] += choco [ i ] [ j ] NEW_LINE DEDENT DEDENT ans = max ( ans , sum ( sorted ( target , reverse = True ) [ : Q ] ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT N , M , P , Q , R = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE C = [ [ int ( i ) for i in input ( ) . split ( ) ] for j in range ( R ) ] NEW_LINE print ( d_valentine ( N , M , P , Q , R , C ) ) NEW_LINE",
"from itertools import combinations NEW_LINE n , m , p , q , r = map ( int , input ( ) . split ( ) ) NEW_LINE combos = list ( combinations ( list ( range ( 0 , n ) ) , p ) ) NEW_LINE ans = 0 NEW_LINE info = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT info . append ( [ 0 ] * m ) NEW_LINE DEDENT for i in range ( r ) : NEW_LINE INDENT a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE info [ a - 1 ] [ b - 1 ] = c NEW_LINE DEDENT combos = list ( combinations ( list ( range ( 0 , n ) ) , p ) ) NEW_LINE for combo in combos : NEW_LINE INDENT temp = [ 0 ] * m NEW_LINE for i in range ( m ) : NEW_LINE INDENT for w in combo : NEW_LINE INDENT temp [ i ] += info [ w ] [ i ] NEW_LINE DEDENT DEDENT temp = sorted ( temp , reverse = True ) NEW_LINE ans = max ( ans , sum ( temp [ : q ] ) ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"import itertools NEW_LINE import numpy as np NEW_LINE N , M , P , Q , R = map ( int , input ( ) . split ( ) ) NEW_LINE choco = np . zeros ( ( N , M ) ) NEW_LINE for i in range ( R ) : NEW_LINE INDENT x , y , z = map ( int , input ( ) . split ( ) ) NEW_LINE choco [ x - 1 ] [ y - 1 ] = z NEW_LINE DEDENT seq = [ i for i in range ( N ) ] NEW_LINE ans = 0 NEW_LINE for girls in itertools . combinations ( seq , P ) : NEW_LINE INDENT happiness = np . sum ( choco [ list ( girls ) ] , axis = 0 ) NEW_LINE happiness = sorted ( happiness , key = lambda x : - x ) NEW_LINE ans = max ( ans , sum ( happiness [ : Q ] ) ) NEW_LINE DEDENT print ( int ( ans ) ) NEW_LINE"
] |
atcoder_arc039_B | [
"import java . util . * ; public class Main { static final long MOD = 1000000007L ; static long [ ] [ ] dp ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; if ( n > k ) { dp = new long [ n + k ] [ k + 1 ] ; System . out . println ( combination ( n + k - 1 , k ) ) ; } else { dp = new long [ n + 1 ] [ k % n + 1 ] ; System . out . println ( combination ( n , k % n ) ) ; } } static long combination ( int left , int right ) { if ( right > left - right ) { return combination ( left , left - right ) ; } if ( right == 0 ) { return 1 ; } if ( right == 1 ) { return left ; } if ( dp [ left ] [ right ] != 0 ) { return dp [ left ] [ right ] ; } long val = combination ( left - 1 , right ) + combination ( left - 1 , right - 1 ) ; val %= MOD ; dp [ left ] [ right ] = val ; return val ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sn = new Scanner ( System . in ) ; int N = sn . nextInt ( ) ; int K = sn . nextInt ( ) ; if ( N > K ) { System . out . println ( nCr ( N + K - 1 , K ) ) ; return ; } int c = K % N ; int r = N - c ; System . out . println ( nCr ( N , r ) ) ; } public static long nCr ( int n , int r ) { long M = 1000000007L ; long dp [ ] [ ] = new long [ 502 ] [ 502 ] ; for ( int i = 0 ; i < 502 ; ++ i ) { for ( int j = 0 ; j < 502 ; ++ j ) { dp [ i ] [ j ] = 0 ; } } dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { dp [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j <= i + 1 ; ++ j ) { dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j ] ) % M ; } } return dp [ n ] [ r ] ; } }"
] | [
"import math NEW_LINE N , K = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE if K < N : NEW_LINE INDENT ans = math . factorial ( N + K - 1 ) // ( math . factorial ( N + K - 1 - K ) * math . factorial ( K ) ) % ( 10 ** 9 + 7 ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = math . factorial ( N ) // ( math . factorial ( N - K % N ) * math . factorial ( K % N ) ) % ( 10 ** 9 + 7 ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE class FactMod ( ) : NEW_LINE INDENT def __init__ ( self , n , mod ) : NEW_LINE INDENT self . mod = mod NEW_LINE self . f = [ 1 ] * ( n + 1 ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT self . f [ i ] = self . f [ i - 1 ] * i % mod NEW_LINE DEDENT self . inv = [ pow ( self . f [ - 1 ] , mod - 2 , mod ) ] NEW_LINE for i in range ( 1 , n + 1 ) [ : : - 1 ] : NEW_LINE INDENT self . inv . append ( self . inv [ - 1 ] * i % mod ) NEW_LINE DEDENT self . inv . reverse ( ) NEW_LINE DEDENT def fact ( self , n ) : NEW_LINE INDENT return self . f [ n ] NEW_LINE DEDENT def comb ( self , n , r ) : NEW_LINE INDENT ret = self . f [ n ] * self . inv [ n - r ] * self . inv [ r ] NEW_LINE ret %= self . mod NEW_LINE return ret NEW_LINE DEDENT DEDENT N , K = map ( int , input ( ) . split ( ) ) NEW_LINE F = FactMod ( N + K , 10 ** 9 + 7 ) NEW_LINE if K >= N : NEW_LINE INDENT print ( F . comb ( N , K % N ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( F . comb ( N - 1 + K , K ) ) NEW_LINE DEDENT",
"MOD = 10 ** 9 + 7 NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE def nCk ( n , k ) : NEW_LINE INDENT res = 1 NEW_LINE k = min ( n , n - k ) NEW_LINE for i in range ( k ) : NEW_LINE INDENT res *= ( n - i ) NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT res //= ( k - i ) NEW_LINE DEDENT return res NEW_LINE DEDENT res = 0 NEW_LINE if N > K : NEW_LINE INDENT res = nCk ( N - 1 + K , K ) % MOD NEW_LINE DEDENT elif N == K : NEW_LINE INDENT res = 1 NEW_LINE DEDENT else : NEW_LINE INDENT K %= N NEW_LINE res = nCk ( N , K ) % MOD NEW_LINE DEDENT print ( res ) NEW_LINE",
"class Combination : NEW_LINE INDENT def __init__ ( self , n , mod ) : NEW_LINE INDENT self . fact = [ 1 ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT self . fact . append ( self . fact [ - 1 ] * i % mod ) NEW_LINE DEDENT self . inv_fact = [ pow ( self . fact [ i ] , mod - 2 , mod ) for i in range ( n + 1 ) ] NEW_LINE self . mod = mod NEW_LINE DEDENT def factorial ( self , i ) : NEW_LINE INDENT return self . fact [ i ] NEW_LINE DEDENT def inverse_factorial ( self , i ) : NEW_LINE INDENT return self . inv_fact [ i ] NEW_LINE DEDENT def combination ( self , i , j ) : NEW_LINE INDENT return ( self . fact [ i ] * self . inv_fact [ i - j ] * self . inv_fact [ j ] ) % self . mod NEW_LINE DEDENT DEDENT n , k = map ( int , input ( ) . split ( ) ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE comb = Combination ( n + k , MOD ) NEW_LINE if k // n == 0 : NEW_LINE INDENT print ( comb . combination ( k + n - 1 , k ) ) NEW_LINE DEDENT else : NEW_LINE INDENT otoku_enji_num = n - k % n NEW_LINE son_enji_num = n - otoku_enji_num NEW_LINE print ( comb . combination ( n , otoku_enji_num ) ) NEW_LINE DEDENT",
"N , K = map ( int , input ( ) . split ( ) ) NEW_LINE MOD = int ( 1e9 + 7 ) NEW_LINE M = N + K + 10 NEW_LINE fac , finv , inv = [ 1 ] * M , [ 1 ] * M , [ 1 ] * M NEW_LINE def COMinit ( MAX ) : NEW_LINE INDENT fac [ 0 ] , fac [ 1 ] = 1 , 1 NEW_LINE finv [ 0 ] , finv [ 1 ] = 1 , 1 NEW_LINE inv [ 1 ] = 1 NEW_LINE for i in range ( 2 , MAX ) : NEW_LINE INDENT fac [ i ] = fac [ i - 1 ] * i % MOD NEW_LINE inv [ i ] = MOD - inv [ MOD % i ] * ( MOD // i ) % MOD NEW_LINE finv [ i ] = finv [ i - 1 ] * inv [ i ] % MOD NEW_LINE DEDENT DEDENT def COM ( n , k ) : NEW_LINE INDENT if n < k or n < 0 or k < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT return fac [ n ] * ( finv [ k ] * finv [ n - k ] % MOD ) % MOD NEW_LINE DEDENT COMinit ( M ) NEW_LINE if N > K : NEW_LINE INDENT print ( COM ( N + K - 1 , N - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT a = K % N NEW_LINE print ( COM ( N , a ) ) NEW_LINE DEDENT"
] |
atcoder_arc090_A | [
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] candies = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { candies [ i ] [ j ] = sc . nextInt ( ) ; } } int max = maxCandies ( candies ) ; System . out . println ( max ) ; } private static int maxCandies ( int [ ] [ ] candies ) { int topSum = 0 ; int bottomDelta = 0 ; int i = 0 ; for ( ; i < candies [ 0 ] . length - 1 ; i ++ ) { bottomDelta += candies [ 1 ] [ i ] - candies [ 0 ] [ i + 1 ] ; if ( bottomDelta < 0 ) bottomDelta = 0 ; topSum += candies [ 0 ] [ i ] ; } topSum += candies [ 0 ] [ i ] + candies [ 1 ] [ i ] ; return topSum + bottomDelta ; } }",
"import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . function . Consumer ; import java . util . stream . IntStream ; import static java . util . stream . Collectors . toList ; public class Main { private static final Scanner scanner = new Scanner ( System . in ) ; private static final Consumer < List < String > > consumer = solve ( ) ; public static void main ( String [ ] args ) { consumer . accept ( readInput ( ) ) ; } private static List < String > readInput ( ) { final List < String > lineList = new ArrayList < > ( ) ; while ( scanner . hasNextLine ( ) ) { lineList . add ( scanner . nextLine ( ) ) ; } return lineList ; } private static Consumer < List < String > > solve ( ) { return args -> { final List < Integer > firstRow = Arrays . stream ( args . get ( 1 ) . split ( \" β \" ) ) . map ( Integer :: valueOf ) . collect ( toList ( ) ) ; final List < Integer > secondRow = Arrays . stream ( args . get ( 2 ) . split ( \" β \" ) ) . map ( Integer :: valueOf ) . collect ( toList ( ) ) ; final Integer ans = IntStream . range ( 0 , firstRow . size ( ) ) . map ( index -> firstRow . subList ( 0 , index + 1 ) . stream ( ) . mapToInt ( Integer :: intValue ) . sum ( ) + secondRow . subList ( index , secondRow . size ( ) ) . stream ( ) . mapToInt ( Integer :: intValue ) . sum ( ) ) . max ( ) . orElse ( - 1 ) ; System . out . println ( ans ) ; } ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . parseInt ( reader . readLine ( ) ) ; int [ ] [ ] grid = new int [ 2 ] [ N ] ; for ( int i = 0 ; i < 2 ; i ++ ) { String [ ] temp = reader . readLine ( ) . split ( \" [ β ] \" ) ; for ( int j = 0 ; j < N ; j ++ ) { grid [ i ] [ j ] = Integer . parseInt ( temp [ j ] ) ; } } System . out . println ( solution ( grid , N ) ) ; } public static int solution ( int [ ] [ ] grid , int N ) { for ( int i = 1 ; i >= 0 ; i -- ) { for ( int j = N - 1 ; j >= 0 ; j -- ) { int current = 0 ; if ( j + 1 < N ) { current = Math . max ( current , grid [ i ] [ j + 1 ] ) ; } if ( i + 1 < 2 ) { current = Math . max ( current , grid [ i + 1 ] [ j ] ) ; } grid [ i ] [ j ] += current ; } } return grid [ 0 ] [ 0 ] ; } }",
"import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int candies_a = 0 ; int candies_b = 0 ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; a [ 0 ] = sc . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int tmp = sc . nextInt ( ) ; a [ i ] = a [ i - 1 ] + tmp ; } b [ 0 ] = sc . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int tmp = sc . nextInt ( ) ; b [ i ] = b [ i - 1 ] + tmp ; } int candies = a [ 0 ] + b [ n - 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { int tmp = a [ i ] + ( b [ n - 1 ] - b [ i - 1 ] ) ; if ( tmp > candies ) { candies = tmp ; } } System . out . print ( candies ) ; } }",
"import java . util . Scanner ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int map [ ] [ ] = new int [ 2 ] [ n ] ; int sum [ ] [ ] = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { map [ i ] [ j ] = sc . nextInt ( ) ; } } sum [ 0 ] [ 0 ] = map [ 0 ] [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { sum [ 0 ] [ j ] = sum [ 0 ] [ j - 1 ] + map [ 0 ] [ j ] ; } sum [ 1 ] [ 0 ] = sum [ 0 ] [ 0 ] + map [ 1 ] [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { sum [ 1 ] [ j ] = Math . max ( sum [ 0 ] [ j ] , sum [ 1 ] [ j - 1 ] ) + map [ 1 ] [ j ] ; } System . out . println ( sum [ 1 ] [ n - 1 ] ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }"
] | [
"N = int ( input ( ) ) NEW_LINE A1 = list ( map ( int , input ( ) . split ( ' β ' ) ) ) NEW_LINE A2 = list ( map ( int , input ( ) . split ( ' β ' ) ) ) NEW_LINE now_gain = sum ( A2 ) + A1 [ 0 ] NEW_LINE max_gain = now_gain NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT now_gain = now_gain - A2 [ i - 1 ] + A1 [ i ] NEW_LINE max_gain = max ( max_gain , now_gain ) NEW_LINE DEDENT print ( max_gain ) NEW_LINE",
"import numpy as np NEW_LINE def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE A1 = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE A2 = np . cumsum ( np . array ( inpl ( ) ) ) NEW_LINE ans = A1 [ 0 ] + A2 [ - 1 ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT ans = max ( ans , A1 [ i ] + A2 [ - 1 ] - A2 [ i - 1 ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE",
"n = int ( input ( ) ) NEW_LINE a = [ None ] * 2 NEW_LINE a [ 0 ] = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a [ 1 ] = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dp = [ [ 0 ] * n for i in range ( 2 ) ] NEW_LINE dp [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT dp [ 1 ] [ i ] = dp [ 0 ] [ i ] + a [ 1 ] [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] NEW_LINE dp [ 1 ] [ i ] = max ( dp [ 0 ] [ i ] , dp [ 1 ] [ i - 1 ] ) + a [ 1 ] [ i ] NEW_LINE DEDENT DEDENT print ( dp [ 1 ] [ n - 1 ] ) NEW_LINE",
"n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) ; print ( max ( sum ( a [ : i + 1 ] + a [ n + i : ] ) for i in range ( n ) ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE A = list ( ) NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT A . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE DEDENT dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( 2 ) ] NEW_LINE dp [ 0 ] [ 0 ] = A [ 0 ] [ 0 ] NEW_LINE dp [ 1 ] [ 0 ] = A [ 0 ] [ 0 ] + A [ 1 ] [ 0 ] NEW_LINE for j in range ( N - 1 ) : NEW_LINE INDENT dp [ 0 ] [ j + 1 ] = dp [ 0 ] [ j ] + A [ 0 ] [ j + 1 ] NEW_LINE DEDENT for j in range ( N - 1 ) : NEW_LINE INDENT dp [ 1 ] [ j + 1 ] = max ( dp [ 0 ] [ j + 1 ] + A [ 1 ] [ j + 1 ] , dp [ 1 ] [ j ] + A [ 1 ] [ j + 1 ] ) NEW_LINE DEDENT print ( dp [ 1 ] [ N - 1 ] ) NEW_LINE"
] |
atcoder_abc118_A | [
"import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = b % a ; if ( c == 0 ) System . out . println ( a + b ) ; else System . out . println ( b - a ) ; } }",
"import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int a = Integer . parseInt ( scan . next ( ) ) ; int b = Integer . parseInt ( scan . next ( ) ) ; int count = 0 ; if ( b % a == 0 ) { count = a + b ; } else { count = b - a ; } PrintWriter out = new PrintWriter ( System . out ) ; out . println ( count ) ; out . flush ( ) ; scan . close ( ) ; } }",
"import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . Date ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( B % A == 0 ) { System . out . println ( A + B ) ; } else { System . out . println ( B - A ) ; } } }",
"import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { final int A = s . nextInt ( ) ; final int B = s . nextInt ( ) ; System . out . println ( B % A == 0 ? A + B : B - A ) ; } }",
"import java . util . * ; import java . util . List ; import java . util . ArrayList ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; if ( B % A == 0 ) { System . out . println ( A + B ) ; } else { System . out . println ( B - A ) ; } } }"
] | [
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if ( b % a ) == 0 : NEW_LINE INDENT print ( a + b ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b - a ) NEW_LINE DEDENT",
"A , B = map ( int , input ( ) . split ( ) ) NEW_LINE print ( [ A + B , B - A ] [ not ( B % A == 0 ) ] ) NEW_LINE",
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if b % a : NEW_LINE INDENT print ( b - a ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a + b ) NEW_LINE DEDENT",
"a , b = map ( int , input ( ) . split ( ) ) NEW_LINE print ( a + b if b % a == 0 else b - a ) NEW_LINE",
"i = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE if ( i [ 1 ] % i [ 0 ] ) == 0 : NEW_LINE INDENT print ( i [ 0 ] + i [ 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( i [ 1 ] - i [ 0 ] ) NEW_LINE DEDENT"
] |
atcoder_abc068_A | [
"import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; System . out . println ( \" ABC \" + sc . nextInt ( ) ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; Scanner sc = new Scanner ( System . in ) ; main . solve ( sc ) ; sc . close ( ) ; } void solve ( Scanner sc ) { int N = sc . nextInt ( ) ; System . out . println ( \" ABC \" + N ) ; } }",
"import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; String S = sc . next ( ) ; out . println ( \" ABC \" + S ) ; out . flush ( ) ; } }",
"import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; System . out . println ( \" ABC \" + N ) ; } }",
"import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner inScanner = new Scanner ( System . in ) ; System . out . println ( \" ABC \" + inScanner . nextInt ( ) ) ; } }"
] | [
"N = input ( ) NEW_LINE print ( ' ABC ' + N ) NEW_LINE",
"print ( ' ABC { } ' . format ( input ( ) ) ) NEW_LINE",
"n = input ( ) NEW_LINE print ( \" ABC \" + str ( n ) ) NEW_LINE",
"a = input ( ) NEW_LINE print ( \" ABC \" + a ) NEW_LINE",
"N = input ( ) NEW_LINE print ( \" ABC \" + N ) NEW_LINE"
] |
atcoder_arc066_B | [
"import java . util . * ; class Main { static long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long n = scan . nextLong ( ) ; int B = 62 ; long [ ] [ ] dp = new long [ 3 ] [ B ] ; dp [ 0 ] [ B - 1 ] = 1 ; for ( int i = B - 2 ; i >= 0 ; -- i ) { for ( int a = 0 ; a <= 2 ; ++ a ) { if ( n >>> i < a ) continue ; long m = n >>> i ; int b = ( int ) ( m / 2 - ( m - a ) / 2 ) ; int c = ( int ) ( ( m - a ) % 2 ) ; if ( c != 0 ) dp [ a ] [ i ] = dp [ b ] [ i + 1 ] % MOD ; else dp [ a ] [ i ] = ( dp [ b ] [ i + 1 ] + dp [ b + 1 ] [ i + 1 ] ) % MOD ; } } long [ ] r = new long [ B ] , s = new long [ B ] ; r [ 0 ] = 1 ; s [ 0 ] = 0 ; for ( int i = 1 ; i < B ; ++ i ) r [ i ] = ( 3 * r [ i - 1 ] + MOD - 1 ) % MOD ; for ( int i = 1 ; i < B ; ++ i ) s [ i ] = ( 3 * s [ i - 1 ] + 1 ) % MOD ; long t = 0 ; for ( int i = B - 2 ; i >= 0 ; -- i ) { if ( ( n & 1L << i ) != 0 ) { t += dp [ 1 ] [ i ] * r [ i ] % MOD ; t += dp [ 2 ] [ i ] * s [ i ] % MOD ; t %= MOD ; } } t = ( t + dp [ 0 ] [ 0 ] ) % MOD ; System . out . println ( t ) ; } }",
"import java . io . * ; import java . util . * ; public class Main { static Map < Long , Long > check = new HashMap < Long , Long > ( ) ; public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String buf ; String [ ] input ; long N ; N = Long . parseLong ( br . readLine ( ) ) ; System . out . println ( solve ( N ) ) ; } static long solve ( long n ) { long a , b ; if ( n == 0 ) return 1 ; if ( n == 1 ) return 2 ; if ( check . containsKey ( n / 2 ) ) { a = check . get ( n / 2 ) ; } else { a = solve ( n / 2 ) % 1000000007 ; check . put ( n / 2 , a ) ; } if ( check . containsKey ( n / 2 - 1 ) ) { b = check . get ( n / 2 - 1 ) ; } else { b = solve ( n / 2 - 1 ) % 1000000007 ; check . put ( n / 2 - 1 , b ) ; } if ( n % 2 == 1 ) { return ( 2 * a + b ) % 1000000007 ; } else { return ( 2 * b + a ) % 1000000007 ; } } }",
"import java . util . HashMap ; import java . util . Scanner ; public class Main { public static long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; System . out . println ( f ( n + 1 ) ) ; } static HashMap < Long , Long > mb = new HashMap < > ( ) ; public static long f ( long n ) { Long memo = mb . get ( n ) ; if ( memo != null ) return memo ; if ( n <= 2 ) { return n ; } long res = f ( n / 2 ) + f ( ( n - 1 ) / 2 ) + f ( ( n + 1 ) / 2 ) ; res %= MOD ; mb . put ( n , res ) ; return res ; } }",
"import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; public class Main { private static final long MOD = ( long ) ( 1e9 + 7 ) ; private void solve ( ) throws IOException { long n = Long . parseLong ( next ( ) ) + 1 ; String s = Long . toBinaryString ( n ) ; int m = s . length ( ) ; int [ ] a = new int [ m ] ; Arrays . fill ( a , - 1 ) ; long res = 0 ; for ( int i = 0 ; i < m ; i ++ ) if ( s . charAt ( i ) == '1' ) { for ( int j = 0 ; j < i ; j ++ ) { a [ j ] = s . charAt ( j ) - '0' ; } a [ i ] = 0 ; res += calc ( a ) ; res %= MOD ; } out . println ( res ) ; } private long calc ( int [ ] a ) { long q = 1 , w = 0 ; for ( int i = a . length - 1 ; i >= 0 ; i -- ) { long qq = 0 , ww = 0 ; if ( a [ i ] != 1 ) { qq += q ; ww += ( q + w ) ; } if ( a [ i ] != 0 ) { qq += ( q + w ) ; ww += w ; } q = qq % MOD ; w = ww % MOD ; } return q ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st ; PrintWriter out = new PrintWriter ( System . out ) ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } private void run ( ) throws IOException { solve ( ) ; out . close ( ) ; } }",
"import java . util . HashMap ; import java . util . Scanner ; public class Main { static HashMap < Long , Long > map = new HashMap < > ( ) ; static final long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; sc . close ( ) ; System . out . println ( dfs ( n + 1 ) ) ; } static long dfs ( long n ) { if ( n == 1 ) return 1 ; if ( n == 0 ) return 0 ; if ( map . containsKey ( n ) ) return map . get ( n ) ; long ret ; if ( n % 2 == 1 ) { ret = ( 2 * dfs ( n / 2 ) + dfs ( n / 2 + 1 ) ) % MOD ; map . put ( n , ret ) ; } else { ret = ( 2 * dfs ( n / 2 ) + dfs ( n / 2 - 1 ) ) % MOD ; map . put ( n , ret ) ; } return ret ; } }"
] | [
"from copy import deepcopy NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE IMAX = 200 NEW_LINE JMAX = 2 NEW_LINE def dp ( n ) : NEW_LINE INDENT dp = [ 0 for j in range ( JMAX + 1 ) ] NEW_LINE dp [ 0 ] = 1 NEW_LINE for i in reversed ( range ( IMAX + 1 ) ) : NEW_LINE INDENT pre = deepcopy ( dp ) NEW_LINE dp [ 2 ] += pre [ 1 ] NEW_LINE dp [ 2 ] += 2 * pre [ 2 ] NEW_LINE d = ( ( 1 << i ) & n ) >> i NEW_LINE if d : NEW_LINE INDENT dp [ 1 ] += pre [ 0 ] NEW_LINE dp [ 2 ] += pre [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ 0 ] += pre [ 1 ] NEW_LINE DEDENT dp = take_mod ( dp ) NEW_LINE DEDENT return sum ( dp ) % MOD NEW_LINE DEDENT def take_mod ( dp ) : NEW_LINE INDENT res = [ x % MOD for x in dp ] NEW_LINE return res NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE print ( dp ( n ) ) NEW_LINE DEDENT main ( ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE bit = bin ( N ) [ 2 : ] NEW_LINE k = len ( bit ) NEW_LINE dp = [ [ 0 ] * 2 for i in range ( len ( bit ) + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE dp [ 0 ] [ 1 ] = 1 NEW_LINE for i in range ( k ) : NEW_LINE INDENT j = int ( bit [ k - i - 1 ] ) NEW_LINE a , b , c = [ ( 1 , 0 , 0 ) , ( 1 , 1 , 0 ) ] [ j ] NEW_LINE d , e , f = [ ( 1 , 1 , 1 ) , ( 0 , 1 , 2 ) ] [ j ] NEW_LINE dp [ i + 1 ] [ 0 ] = ( a * dp [ i ] [ 0 ] + b * dp [ i ] [ 1 ] + c * 3 ** i ) % 1000000007 NEW_LINE dp [ i + 1 ] [ 1 ] = d * dp [ i ] [ 0 ] + e * dp [ i ] [ 1 ] + f * 3 ** i % 1000000007 NEW_LINE DEDENT print ( dp [ k ] [ 0 ] ) NEW_LINE",
"def Dp ( x , hl , islim ) : NEW_LINE INDENT if x == len ( digit ) : NEW_LINE INDENT return hl == 0 NEW_LINE DEDENT if f [ x ] [ hl ] [ islim ] : NEW_LINE INDENT return f [ x ] [ hl ] [ islim ] NEW_LINE DEDENT ans = 0 NEW_LINE mx = int ( digit [ x ] ) if islim else 1 NEW_LINE for i in range ( mx + 1 ) : NEW_LINE INDENT ans += Dp ( x + 1 , hl , islim and i == mx ) NEW_LINE if hl != i : NEW_LINE INDENT ans += Dp ( x + 1 , not hl , islim and i == mx ) NEW_LINE DEDENT DEDENT ans %= p NEW_LINE f [ x ] [ hl ] [ islim ] = ans NEW_LINE return ans NEW_LINE DEDENT p = 10 ** 9 + 7 NEW_LINE digit = bin ( int ( input ( ) ) ) [ 2 : ] NEW_LINE f = [ [ [ 0 , 0 ] , [ 0 , 0 ] ] for i in range ( len ( digit ) ) ] NEW_LINE print ( Dp ( 0 , 0 , 1 ) ) NEW_LINE",
"N = int ( input ( ) ) NEW_LINE binN = format ( N , \" b \" ) . zfill ( 60 ) NEW_LINE mod = 7 + 10 ** 9 NEW_LINE DP = [ [ 0 , 0 , 0 ] for _ in range ( 60 ) ] NEW_LINE if binN [ 0 ] == \"0\" : NEW_LINE INDENT DP [ 0 ] = [ 1 , 0 , 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT DP [ 0 ] = [ 1 , 1 , 0 ] NEW_LINE DEDENT for i in range ( 1 , 60 ) : NEW_LINE INDENT if binN [ i ] == \"0\" : NEW_LINE INDENT DP [ i ] [ 0 ] = ( DP [ i - 1 ] [ 0 ] + DP [ i - 1 ] [ 1 ] ) % mod NEW_LINE DP [ i ] [ 1 ] = DP [ i - 1 ] [ 1 ] NEW_LINE DP [ i ] [ 2 ] = ( DP [ i - 1 ] [ 2 ] * 3 + DP [ i - 1 ] [ 1 ] ) % mod NEW_LINE DEDENT else : NEW_LINE INDENT DP [ i ] [ 0 ] = DP [ i - 1 ] [ 0 ] NEW_LINE DP [ i ] [ 1 ] = ( DP [ i - 1 ] [ 0 ] + DP [ i - 1 ] [ 1 ] ) % mod NEW_LINE DP [ i ] [ 2 ] = ( DP [ i - 1 ] [ 2 ] * 3 + DP [ i - 1 ] [ 1 ] * 2 ) % mod NEW_LINE DEDENT DEDENT print ( sum ( DP [ - 1 ] ) % mod ) NEW_LINE",
"MOD = 10 ** 9 + 7 NEW_LINE N = int ( input ( ) ) NEW_LINE binN = list ( map ( int , bin ( N ) [ 2 : ] ) ) NEW_LINE dp = [ [ 0 ] * 3 for _ in range ( len ( binN ) + 1 ) ] NEW_LINE dp [ 0 ] [ 0 ] = 1 NEW_LINE for i , Ni in enumerate ( binN ) : NEW_LINE INDENT dp [ i + 1 ] [ 0 ] += dp [ i ] [ 0 ] * 1 NEW_LINE dp [ i + 1 ] [ 1 ] += dp [ i ] [ 0 ] * Ni NEW_LINE dp [ i + 1 ] [ 0 ] += dp [ i ] [ 1 ] * ( 1 - Ni ) NEW_LINE dp [ i + 1 ] [ 1 ] += dp [ i ] [ 1 ] * 1 NEW_LINE dp [ i + 1 ] [ 2 ] += dp [ i ] [ 1 ] * ( 1 + Ni ) NEW_LINE dp [ i + 1 ] [ 2 ] += dp [ i ] [ 2 ] * 3 NEW_LINE dp [ i + 1 ] [ 0 ] %= MOD NEW_LINE dp [ i + 1 ] [ 1 ] %= MOD NEW_LINE dp [ i + 1 ] [ 2 ] %= MOD NEW_LINE DEDENT print ( sum ( dp [ - 1 ] ) % MOD ) NEW_LINE"
] |