id
stringlengths
2
6
java
stringlengths
48
5.92k
python
stringlengths
33
11.1k
T400
import java . util . Arrays ; import java . util . Scanner ; class Main { public static void reverse ( int [ ] A ) { for ( int i = 0 ; i < A . length / 2 ; i ++ ) { int tmp = A [ i ] ; A [ i ] = A [ A . length - i - 1 ] ; A [ A . length - i - 1 ] = tmp ; } } private static final int [ ] num = { 999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; private static final int INF = Integer . MAX_VALUE / 4 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int M = Integer . parseInt ( scanner . next ( ) ) ; int [ ] A = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = Integer . parseInt ( scanner . next ( ) ) ; } Arrays . sort ( A ) ; reverse ( A ) ; int [ ] dp = new int [ 10010 ] ; Arrays . fill ( dp , - INF ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i - num [ A [ j ] ] >= 0 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - num [ A [ j ] ] ] + 1 ) ; } } } String ans = " " ; int goal = dp [ N ] ; for ( int k = 0 ; k < goal ; k ++ ) { for ( int i = 0 ; i < M ; i ++ ) { if ( N - num [ A [ i ] ] >= 0 && dp [ N ] != 0 && dp [ N - num [ A [ i ] ] ] == dp [ N ] - 1 ) { ans += A [ i ] ; N -= num [ A [ i ] ] ; break ; } } } System . out . println ( ans ) ; } }
import sys NEW_LINE def solve ( N : int , M : int , A : " List [ int ] " ) : NEW_LINE INDENT costs = [ 10 ** 18 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] NEW_LINE cand = [ ( i , costs [ i ] ) for i in A ] NEW_LINE cand . sort ( reverse = True ) NEW_LINE digits = [ - 1 * 10 ** 16 for i in range ( N + 1 ) ] NEW_LINE digits [ 0 ] = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT r = - 1 * 10 ** 16 NEW_LINE for c in cand : NEW_LINE INDENT if i - c [ 1 ] >= 0 : NEW_LINE INDENT r = max ( r , digits [ i - c [ 1 ] ] + 1 ) NEW_LINE DEDENT DEDENT digits [ i ] = r NEW_LINE DEDENT digit = digits [ N ] NEW_LINE lastCost = N NEW_LINE result = 0 NEW_LINE for i in range ( digit ) : NEW_LINE INDENT for c in cand : NEW_LINE INDENT if lastCost - c [ 1 ] >= 0 and digits [ lastCost - c [ 1 ] ] == digits [ lastCost ] - 1 : NEW_LINE INDENT result = result * 10 + c [ 0 ] NEW_LINE lastCost = lastCost - c [ 1 ] NEW_LINE break NEW_LINE DEDENT DEDENT 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 M = int ( next ( tokens ) ) NEW_LINE A = [ int ( next ( tokens ) ) for _ in range ( M ) ] NEW_LINE solve ( N , M , A ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T401
import java . util . Arrays ; import java . util . Scanner ; class Main { public static void reverse ( int [ ] A ) { for ( int i = 0 ; i < A . length / 2 ; i ++ ) { int tmp = A [ i ] ; A [ i ] = A [ A . length - i - 1 ] ; A [ A . length - i - 1 ] = tmp ; } } private static final int [ ] num = { 999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; private static final int INF = Integer . MAX_VALUE / 4 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int M = Integer . parseInt ( scanner . next ( ) ) ; int [ ] A = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = Integer . parseInt ( scanner . next ( ) ) ; } Arrays . sort ( A ) ; reverse ( A ) ; int [ ] dp = new int [ 10010 ] ; Arrays . fill ( dp , - INF ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i - num [ A [ j ] ] >= 0 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - num [ A [ j ] ] ] + 1 ) ; } } } String ans = " " ; int goal = dp [ N ] ; for ( int k = 0 ; k < goal ; k ++ ) { for ( int i = 0 ; i < M ; i ++ ) { if ( N - num [ A [ i ] ] >= 0 && dp [ N ] != 0 && dp [ N - num [ A [ i ] ] ] == dp [ N ] - 1 ) { ans += A [ i ] ; N -= num [ A [ i ] ] ; break ; } } } System . out . println ( ans ) ; } }
N , M = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def num ( k ) : NEW_LINE INDENT costs = [ 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] NEW_LINE return costs [ k - 1 ] NEW_LINE DEDENT inf = 1000 NEW_LINE dp = [ - inf for _ in range ( N + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE cost_list = [ num ( k ) for k in A ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT for cost in cost_list : NEW_LINE INDENT if i - cost < 0 : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT temp = dp [ i - cost ] + 1 NEW_LINE dp [ i ] = max ( dp [ i ] , temp ) NEW_LINE DEDENT DEDENT DEDENT ans = ' ' NEW_LINE many = N NEW_LINE for d in range ( dp [ N ] ) : NEW_LINE INDENT for k in sorted ( A , reverse = True ) : NEW_LINE INDENT if many - num ( k ) < 0 : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT if dp [ many - num ( k ) ] == dp [ many ] - 1 : NEW_LINE INDENT ans += str ( k ) NEW_LINE many -= num ( k ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT pass NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
T402
import java . util . Arrays ; import java . util . Scanner ; class Main { public static void reverse ( int [ ] A ) { for ( int i = 0 ; i < A . length / 2 ; i ++ ) { int tmp = A [ i ] ; A [ i ] = A [ A . length - i - 1 ] ; A [ A . length - i - 1 ] = tmp ; } } private static final int [ ] num = { 999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; private static final int INF = Integer . MAX_VALUE / 4 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int M = Integer . parseInt ( scanner . next ( ) ) ; int [ ] A = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = Integer . parseInt ( scanner . next ( ) ) ; } Arrays . sort ( A ) ; reverse ( A ) ; int [ ] dp = new int [ 10010 ] ; Arrays . fill ( dp , - INF ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i - num [ A [ j ] ] >= 0 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - num [ A [ j ] ] ] + 1 ) ; } } } String ans = " " ; int goal = dp [ N ] ; for ( int k = 0 ; k < goal ; k ++ ) { for ( int i = 0 ; i < M ; i ++ ) { if ( N - num [ A [ i ] ] >= 0 && dp [ N ] != 0 && dp [ N - num [ A [ i ] ] ] == dp [ N ] - 1 ) { ans += A [ i ] ; N -= num [ A [ i ] ] ; break ; } } } System . out . println ( ans ) ; } }
def solve ( string ) : NEW_LINE INDENT n , m , * a = map ( int , string . split ( ) ) NEW_LINE needs = { i + 1 : n for i , n in enumerate ( map ( int , "2 ▁ 5 ▁ 5 ▁ 4 ▁ 5 ▁ 6 ▁ 3 ▁ 7 ▁ 6" . split ( ) ) ) } NEW_LINE if 2 in a and 5 in a : NEW_LINE INDENT a . remove ( 2 ) NEW_LINE DEDENT if 3 in a and 5 in a : NEW_LINE INDENT a . remove ( 3 ) NEW_LINE DEDENT if 2 in a and 3 in a : NEW_LINE INDENT a . remove ( 2 ) NEW_LINE DEDENT if 6 in a and 9 in a : NEW_LINE INDENT a . remove ( 6 ) NEW_LINE DEDENT b = sorted ( a , key = lambda x : needs [ x ] ) NEW_LINE index = 0 NEW_LINE base = str ( b [ 0 ] ) * ( n // needs [ b [ 0 ] ] ) NEW_LINE n %= needs [ b [ 0 ] ] NEW_LINE while n > 0 : NEW_LINE INDENT use = [ _b for _b in b if needs [ _b ] <= needs [ b [ 0 ] ] + n ] NEW_LINE if len ( use ) == 1 : NEW_LINE INDENT base = base [ : - 1 ] NEW_LINE n += needs [ b [ 0 ] ] NEW_LINE DEDENT elif max ( use ) == b [ 0 ] : NEW_LINE INDENT tmp_n = use [ - 1 ] NEW_LINE tmp_c = n // ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) NEW_LINE base = base [ : - tmp_c ] + str ( tmp_n ) * tmp_c NEW_LINE n -= ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) * tmp_c NEW_LINE DEDENT else : NEW_LINE INDENT tmp_n = max ( use ) NEW_LINE tmp_c = n // ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) NEW_LINE base = base [ : index ] + str ( tmp_n ) * tmp_c + base [ index + tmp_c : ] NEW_LINE n -= ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) * tmp_c NEW_LINE index += tmp_c NEW_LINE DEDENT DEDENT return base NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( solve ( ' \n ' . join ( [ input ( ) , input ( ) ] ) ) ) NEW_LINE DEDENT
T403
import java . util . Arrays ; import java . util . Scanner ; class Main { public static void reverse ( int [ ] A ) { for ( int i = 0 ; i < A . length / 2 ; i ++ ) { int tmp = A [ i ] ; A [ i ] = A [ A . length - i - 1 ] ; A [ A . length - i - 1 ] = tmp ; } } private static final int [ ] num = { 999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; private static final int INF = Integer . MAX_VALUE / 4 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int M = Integer . parseInt ( scanner . next ( ) ) ; int [ ] A = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = Integer . parseInt ( scanner . next ( ) ) ; } Arrays . sort ( A ) ; reverse ( A ) ; int [ ] dp = new int [ 10010 ] ; Arrays . fill ( dp , - INF ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i - num [ A [ j ] ] >= 0 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - num [ A [ j ] ] ] + 1 ) ; } } } String ans = " " ; int goal = dp [ N ] ; for ( int k = 0 ; k < goal ; k ++ ) { for ( int i = 0 ; i < M ; i ++ ) { if ( N - num [ A [ i ] ] >= 0 && dp [ N ] != 0 && dp [ N - num [ A [ i ] ] ] == dp [ N ] - 1 ) { ans += A [ i ] ; N -= num [ A [ i ] ] ; break ; } } } System . out . println ( ans ) ; } }
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 nms = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE n , m = nm ( ) NEW_LINE a = nl ( ) NEW_LINE lis = [ 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] NEW_LINE dp = [ - 1 for _ in range ( n + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in a : NEW_LINE INDENT if i - lis [ j ] >= 0 : NEW_LINE INDENT dp [ i ] = max ( dp [ i ] , dp [ i - lis [ j ] ] * 10 + j ) NEW_LINE DEDENT DEDENT DEDENT print ( dp [ n ] ) NEW_LINE
T404
import java . util . Arrays ; import java . util . Scanner ; class Main { public static void reverse ( int [ ] A ) { for ( int i = 0 ; i < A . length / 2 ; i ++ ) { int tmp = A [ i ] ; A [ i ] = A [ A . length - i - 1 ] ; A [ A . length - i - 1 ] = tmp ; } } private static final int [ ] num = { 999999 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; private static final int INF = Integer . MAX_VALUE / 4 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int M = Integer . parseInt ( scanner . next ( ) ) ; int [ ] A = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = Integer . parseInt ( scanner . next ( ) ) ; } Arrays . sort ( A ) ; reverse ( A ) ; int [ ] dp = new int [ 10010 ] ; Arrays . fill ( dp , - INF ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( i - num [ A [ j ] ] >= 0 ) { dp [ i ] = Math . max ( dp [ i ] , dp [ i - num [ A [ j ] ] ] + 1 ) ; } } } String ans = " " ; int goal = dp [ N ] ; for ( int k = 0 ; k < goal ; k ++ ) { for ( int i = 0 ; i < M ; i ++ ) { if ( N - num [ A [ i ] ] >= 0 && dp [ N ] != 0 && dp [ N - num [ A [ i ] ] ] == dp [ N ] - 1 ) { ans += A [ i ] ; N -= num [ A [ i ] ] ; break ; } } } System . out . println ( ans ) ; } }
import sys NEW_LINE RESOURCE_DICT = dict ( [ ( k , v ) for k , v in zip ( range ( 1 , 10 ) , [ 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ) ] ) NEW_LINE def get_input ( ) : NEW_LINE INDENT N , M = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE A = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE return N , M , A NEW_LINE DEDENT def solve ( N , M , A ) : NEW_LINE INDENT sorted_A = sorted ( A ) [ : : - 1 ] NEW_LINE dp = fill_dp ( N , sorted_A ) NEW_LINE array = find_array ( dp , N , sorted_A ) NEW_LINE return " " . join ( map ( str , array ) ) NEW_LINE DEDENT def fill_dp ( N , A ) : NEW_LINE INDENT dp = [ - 100 * N for _ in range ( N + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT fill ( A , dp , i , N ) NEW_LINE DEDENT return dp NEW_LINE DEDENT def fill ( A , dp , n , N ) : NEW_LINE INDENT cand = [ dp [ n - RESOURCE_DICT [ num ] ] + 1 for num in A if n - RESOURCE_DICT [ num ] >= 0 ] NEW_LINE dp [ n ] = max ( cand ) if len ( cand ) > 0 else - 100 * N NEW_LINE DEDENT def find_array ( dp , N , sorted_A ) : NEW_LINE INDENT array = [ ] NEW_LINE current_n = N NEW_LINE for _ in range ( dp [ N ] ) : NEW_LINE INDENT for number in sorted_A : NEW_LINE INDENT if current_n - RESOURCE_DICT [ number ] >= 0 and dp [ current_n - RESOURCE_DICT [ number ] ] == dp [ current_n ] - 1 : NEW_LINE INDENT array . append ( number ) NEW_LINE current_n -= RESOURCE_DICT [ number ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return array NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N , M , A = get_input ( ) NEW_LINE ans = solve ( N , M , A ) NEW_LINE print ( ans ) NEW_LINE DEDENT
T405
import java . util . Arrays ; import java . util . Scanner ; public class Main { private static final int [ ] NUMBER = { 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; scanner . nextLine ( ) ; int [ ] a = new int [ m ] ; int [ ] num = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; num [ i ] = num ( a [ i ] ) ; } scanner . nextLine ( ) ; Arrays . sort ( a ) ; Arrays . sort ( num ) ; int digit = dp ( n , num ) ; int remain = n ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < digit ; i ++ ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( dp ( remain - num ( a [ j ] ) , num ) == dp ( remain , num ) - 1 ) { sb . append ( a [ j ] ) ; remain -= num ( a [ j ] ) ; break ; } } } System . out . println ( sb . toString ( ) ) ; } } private static int num ( int k ) { return NUMBER [ k ] ; } private static int dp ( int n , int [ ] num ) { if ( 0 == n ) { return 0 ; } int min = num [ 0 ] ; if ( n % min == 0 ) { return n / min ; } else { for ( int number : num ) { if ( n >= number ) { int next = dp ( n - number , num ) ; if ( next >= 0 ) { return next + 1 ; } } } } return - 1 ; } }
import sys NEW_LINE def solve ( N : int , M : int , A : " List [ int ] " ) : NEW_LINE INDENT costs = [ 10 ** 18 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] NEW_LINE cand = [ ( i , costs [ i ] ) for i in A ] NEW_LINE cand . sort ( reverse = True ) NEW_LINE digits = [ - 1 * 10 ** 16 for i in range ( N + 1 ) ] NEW_LINE digits [ 0 ] = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT r = - 1 * 10 ** 16 NEW_LINE for c in cand : NEW_LINE INDENT if i - c [ 1 ] >= 0 : NEW_LINE INDENT r = max ( r , digits [ i - c [ 1 ] ] + 1 ) NEW_LINE DEDENT DEDENT digits [ i ] = r NEW_LINE DEDENT digit = digits [ N ] NEW_LINE lastCost = N NEW_LINE result = 0 NEW_LINE for i in range ( digit ) : NEW_LINE INDENT for c in cand : NEW_LINE INDENT if lastCost - c [ 1 ] >= 0 and digits [ lastCost - c [ 1 ] ] == digits [ lastCost ] - 1 : NEW_LINE INDENT result = result * 10 + c [ 0 ] NEW_LINE lastCost = lastCost - c [ 1 ] NEW_LINE break NEW_LINE DEDENT DEDENT 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 M = int ( next ( tokens ) ) NEW_LINE A = [ int ( next ( tokens ) ) for _ in range ( M ) ] NEW_LINE solve ( N , M , A ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T406
import java . util . Arrays ; import java . util . Scanner ; public class Main { private static final int [ ] NUMBER = { 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; scanner . nextLine ( ) ; int [ ] a = new int [ m ] ; int [ ] num = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; num [ i ] = num ( a [ i ] ) ; } scanner . nextLine ( ) ; Arrays . sort ( a ) ; Arrays . sort ( num ) ; int digit = dp ( n , num ) ; int remain = n ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < digit ; i ++ ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( dp ( remain - num ( a [ j ] ) , num ) == dp ( remain , num ) - 1 ) { sb . append ( a [ j ] ) ; remain -= num ( a [ j ] ) ; break ; } } } System . out . println ( sb . toString ( ) ) ; } } private static int num ( int k ) { return NUMBER [ k ] ; } private static int dp ( int n , int [ ] num ) { if ( 0 == n ) { return 0 ; } int min = num [ 0 ] ; if ( n % min == 0 ) { return n / min ; } else { for ( int number : num ) { if ( n >= number ) { int next = dp ( n - number , num ) ; if ( next >= 0 ) { return next + 1 ; } } } } return - 1 ; } }
N , M = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def num ( k ) : NEW_LINE INDENT costs = [ 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] NEW_LINE return costs [ k - 1 ] NEW_LINE DEDENT inf = 1000 NEW_LINE dp = [ - inf for _ in range ( N + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE cost_list = [ num ( k ) for k in A ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT for cost in cost_list : NEW_LINE INDENT if i - cost < 0 : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT temp = dp [ i - cost ] + 1 NEW_LINE dp [ i ] = max ( dp [ i ] , temp ) NEW_LINE DEDENT DEDENT DEDENT ans = ' ' NEW_LINE many = N NEW_LINE for d in range ( dp [ N ] ) : NEW_LINE INDENT for k in sorted ( A , reverse = True ) : NEW_LINE INDENT if many - num ( k ) < 0 : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT if dp [ many - num ( k ) ] == dp [ many ] - 1 : NEW_LINE INDENT ans += str ( k ) NEW_LINE many -= num ( k ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT pass NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
T407
import java . util . Arrays ; import java . util . Scanner ; public class Main { private static final int [ ] NUMBER = { 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; scanner . nextLine ( ) ; int [ ] a = new int [ m ] ; int [ ] num = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; num [ i ] = num ( a [ i ] ) ; } scanner . nextLine ( ) ; Arrays . sort ( a ) ; Arrays . sort ( num ) ; int digit = dp ( n , num ) ; int remain = n ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < digit ; i ++ ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( dp ( remain - num ( a [ j ] ) , num ) == dp ( remain , num ) - 1 ) { sb . append ( a [ j ] ) ; remain -= num ( a [ j ] ) ; break ; } } } System . out . println ( sb . toString ( ) ) ; } } private static int num ( int k ) { return NUMBER [ k ] ; } private static int dp ( int n , int [ ] num ) { if ( 0 == n ) { return 0 ; } int min = num [ 0 ] ; if ( n % min == 0 ) { return n / min ; } else { for ( int number : num ) { if ( n >= number ) { int next = dp ( n - number , num ) ; if ( next >= 0 ) { return next + 1 ; } } } } return - 1 ; } }
def solve ( string ) : NEW_LINE INDENT n , m , * a = map ( int , string . split ( ) ) NEW_LINE needs = { i + 1 : n for i , n in enumerate ( map ( int , "2 ▁ 5 ▁ 5 ▁ 4 ▁ 5 ▁ 6 ▁ 3 ▁ 7 ▁ 6" . split ( ) ) ) } NEW_LINE if 2 in a and 5 in a : NEW_LINE INDENT a . remove ( 2 ) NEW_LINE DEDENT if 3 in a and 5 in a : NEW_LINE INDENT a . remove ( 3 ) NEW_LINE DEDENT if 2 in a and 3 in a : NEW_LINE INDENT a . remove ( 2 ) NEW_LINE DEDENT if 6 in a and 9 in a : NEW_LINE INDENT a . remove ( 6 ) NEW_LINE DEDENT b = sorted ( a , key = lambda x : needs [ x ] ) NEW_LINE index = 0 NEW_LINE base = str ( b [ 0 ] ) * ( n // needs [ b [ 0 ] ] ) NEW_LINE n %= needs [ b [ 0 ] ] NEW_LINE while n > 0 : NEW_LINE INDENT use = [ _b for _b in b if needs [ _b ] <= needs [ b [ 0 ] ] + n ] NEW_LINE if len ( use ) == 1 : NEW_LINE INDENT base = base [ : - 1 ] NEW_LINE n += needs [ b [ 0 ] ] NEW_LINE DEDENT elif max ( use ) == b [ 0 ] : NEW_LINE INDENT tmp_n = use [ - 1 ] NEW_LINE tmp_c = n // ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) NEW_LINE base = base [ : - tmp_c ] + str ( tmp_n ) * tmp_c NEW_LINE n -= ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) * tmp_c NEW_LINE DEDENT else : NEW_LINE INDENT tmp_n = max ( use ) NEW_LINE tmp_c = n // ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) NEW_LINE base = base [ : index ] + str ( tmp_n ) * tmp_c + base [ index + tmp_c : ] NEW_LINE n -= ( needs [ tmp_n ] - needs [ b [ 0 ] ] ) * tmp_c NEW_LINE index += tmp_c NEW_LINE DEDENT DEDENT return base NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( solve ( ' \n ' . join ( [ input ( ) , input ( ) ] ) ) ) NEW_LINE DEDENT
T408
import java . util . Arrays ; import java . util . Scanner ; public class Main { private static final int [ ] NUMBER = { 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; scanner . nextLine ( ) ; int [ ] a = new int [ m ] ; int [ ] num = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; num [ i ] = num ( a [ i ] ) ; } scanner . nextLine ( ) ; Arrays . sort ( a ) ; Arrays . sort ( num ) ; int digit = dp ( n , num ) ; int remain = n ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < digit ; i ++ ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( dp ( remain - num ( a [ j ] ) , num ) == dp ( remain , num ) - 1 ) { sb . append ( a [ j ] ) ; remain -= num ( a [ j ] ) ; break ; } } } System . out . println ( sb . toString ( ) ) ; } } private static int num ( int k ) { return NUMBER [ k ] ; } private static int dp ( int n , int [ ] num ) { if ( 0 == n ) { return 0 ; } int min = num [ 0 ] ; if ( n % min == 0 ) { return n / min ; } else { for ( int number : num ) { if ( n >= number ) { int next = dp ( n - number , num ) ; if ( next >= 0 ) { return next + 1 ; } } } } return - 1 ; } }
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 nms = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE n , m = nm ( ) NEW_LINE a = nl ( ) NEW_LINE lis = [ 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] NEW_LINE dp = [ - 1 for _ in range ( n + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in a : NEW_LINE INDENT if i - lis [ j ] >= 0 : NEW_LINE INDENT dp [ i ] = max ( dp [ i ] , dp [ i - lis [ j ] ] * 10 + j ) NEW_LINE DEDENT DEDENT DEDENT print ( dp [ n ] ) NEW_LINE
T409
import java . util . Arrays ; import java . util . Scanner ; public class Main { private static final int [ ] NUMBER = { 0 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; scanner . nextLine ( ) ; int [ ] a = new int [ m ] ; int [ ] num = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; num [ i ] = num ( a [ i ] ) ; } scanner . nextLine ( ) ; Arrays . sort ( a ) ; Arrays . sort ( num ) ; int digit = dp ( n , num ) ; int remain = n ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < digit ; i ++ ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( dp ( remain - num ( a [ j ] ) , num ) == dp ( remain , num ) - 1 ) { sb . append ( a [ j ] ) ; remain -= num ( a [ j ] ) ; break ; } } } System . out . println ( sb . toString ( ) ) ; } } private static int num ( int k ) { return NUMBER [ k ] ; } private static int dp ( int n , int [ ] num ) { if ( 0 == n ) { return 0 ; } int min = num [ 0 ] ; if ( n % min == 0 ) { return n / min ; } else { for ( int number : num ) { if ( n >= number ) { int next = dp ( n - number , num ) ; if ( next >= 0 ) { return next + 1 ; } } } } return - 1 ; } }
import sys NEW_LINE RESOURCE_DICT = dict ( [ ( k , v ) for k , v in zip ( range ( 1 , 10 ) , [ 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ) ] ) NEW_LINE def get_input ( ) : NEW_LINE INDENT N , M = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE A = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE return N , M , A NEW_LINE DEDENT def solve ( N , M , A ) : NEW_LINE INDENT sorted_A = sorted ( A ) [ : : - 1 ] NEW_LINE dp = fill_dp ( N , sorted_A ) NEW_LINE array = find_array ( dp , N , sorted_A ) NEW_LINE return " " . join ( map ( str , array ) ) NEW_LINE DEDENT def fill_dp ( N , A ) : NEW_LINE INDENT dp = [ - 100 * N for _ in range ( N + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT fill ( A , dp , i , N ) NEW_LINE DEDENT return dp NEW_LINE DEDENT def fill ( A , dp , n , N ) : NEW_LINE INDENT cand = [ dp [ n - RESOURCE_DICT [ num ] ] + 1 for num in A if n - RESOURCE_DICT [ num ] >= 0 ] NEW_LINE dp [ n ] = max ( cand ) if len ( cand ) > 0 else - 100 * N NEW_LINE DEDENT def find_array ( dp , N , sorted_A ) : NEW_LINE INDENT array = [ ] NEW_LINE current_n = N NEW_LINE for _ in range ( dp [ N ] ) : NEW_LINE INDENT for number in sorted_A : NEW_LINE INDENT if current_n - RESOURCE_DICT [ number ] >= 0 and dp [ current_n - RESOURCE_DICT [ number ] ] == dp [ current_n ] - 1 : NEW_LINE INDENT array . append ( number ) NEW_LINE current_n -= RESOURCE_DICT [ number ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return array NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N , M , A = get_input ( ) NEW_LINE ans = solve ( N , M , A ) NEW_LINE print ( ans ) NEW_LINE DEDENT
T410
import java . util . * ; import java . awt . * ; import java . awt . geom . Point2D ; 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 x = sc . nextLong ( ) ; out . println ( f ( x , n - x ) + n ) ; } static long f ( long a , long b ) { if ( a > b ) { long t = a ; a = b ; b = t ; } if ( b % a == 0 ) return ( b / a - 1 ) * 2 * a + a ; return 2 * a * ( b / a ) + f ( b % a , a ) ; } }
import sys NEW_LINE stdin = sys . stdin NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE na = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) NEW_LINE nn = lambda : list ( stdin . readline ( ) . split ( ) ) NEW_LINE ns = lambda : stdin . readline ( ) . rstrip ( ) NEW_LINE n , x = na ( ) NEW_LINE def loop ( a , b ) : NEW_LINE INDENT h = max ( a , b ) NEW_LINE w = min ( a , b ) NEW_LINE if h % w == 0 : NEW_LINE INDENT return int ( ( 2 * h / w - 1 ) * w ) NEW_LINE DEDENT else : NEW_LINE INDENT m = h % w NEW_LINE q = h // w NEW_LINE return 2 * q * w + loop ( m , w ) NEW_LINE DEDENT DEDENT print ( loop ( x , n - x ) + n ) NEW_LINE
T411
import java . util . * ; import java . awt . * ; import java . awt . geom . Point2D ; 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 x = sc . nextLong ( ) ; out . println ( f ( x , n - x ) + n ) ; } static long f ( long a , long b ) { if ( a > b ) { long t = a ; a = b ; b = t ; } if ( b % a == 0 ) return ( b / a - 1 ) * 2 * a + a ; return 2 * a * ( b / a ) + f ( b % a , a ) ; } }
n , x = map ( int , input ( ) . split ( ) ) NEW_LINE if ( x > n // 2 and n % 2 == 0 ) or ( x > ( n + 1 ) // 2 and n % 2 == 1 ) : NEW_LINE INDENT x = n - x NEW_LINE DEDENT A = n - x NEW_LINE B = x NEW_LINE k = 0 NEW_LINE m = - 1 NEW_LINE ans = n NEW_LINE while m != 0 : NEW_LINE INDENT k = A // B NEW_LINE m = A % B NEW_LINE ans += B * k * 2 NEW_LINE if m == 0 : NEW_LINE INDENT ans -= B NEW_LINE DEDENT A = B NEW_LINE B = m NEW_LINE DEDENT print ( ans ) NEW_LINE
T412
import java . util . * ; import java . awt . * ; import java . awt . geom . Point2D ; 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 x = sc . nextLong ( ) ; out . println ( f ( x , n - x ) + n ) ; } static long f ( long a , long b ) { if ( a > b ) { long t = a ; a = b ; b = t ; } if ( b % a == 0 ) return ( b / a - 1 ) * 2 * a + a ; return 2 * a * ( b / a ) + f ( b % a , a ) ; } }
def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a , b = n - x , x NEW_LINE if ( a < b ) : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT path_length = calc_path ( a , b , n ) NEW_LINE print ( path_length ) NEW_LINE DEDENT def calc_path ( a1 , b1 , c1 ) : NEW_LINE INDENT q , mod = divmod ( a1 , b1 ) NEW_LINE count = 0 NEW_LINE if mod == 0 : NEW_LINE INDENT c2 = c1 + 2 * b1 * q - b1 NEW_LINE return c2 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + 1 NEW_LINE c2 = c1 + 2 * b1 * q NEW_LINE a2 = a1 - b1 * q NEW_LINE b2 = b1 NEW_LINE if ( a2 < b2 ) : NEW_LINE INDENT a2 , b2 = b2 , a2 NEW_LINE DEDENT return calc_path ( a2 , b2 , c2 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T413
import java . util . * ; import java . awt . * ; import java . awt . geom . Point2D ; 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 x = sc . nextLong ( ) ; out . println ( f ( x , n - x ) + n ) ; } static long f ( long a , long b ) { if ( a > b ) { long t = a ; a = b ; b = t ; } if ( b % a == 0 ) return ( b / a - 1 ) * 2 * a + a ; return 2 * a * ( b / a ) + f ( b % a , a ) ; } }
import sys NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n , x = LI ( ) NEW_LINE b , a = sorted ( [ x , n - x ] ) NEW_LINE ans = a + b NEW_LINE while b : NEW_LINE INDENT q , mod = divmod ( a , b ) NEW_LINE ans += ( 2 * q - ( not mod ) ) * b NEW_LINE a , b = b , mod NEW_LINE DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T414
import java . util . * ; import java . awt . * ; import java . awt . geom . Point2D ; 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 x = sc . nextLong ( ) ; out . println ( f ( x , n - x ) + n ) ; } static long f ( long a , long b ) { if ( a > b ) { long t = a ; a = b ; b = t ; } if ( b % a == 0 ) return ( b / a - 1 ) * 2 * a + a ; return 2 * a * ( b / a ) + f ( b % a , a ) ; } }
def solve ( s , a , b ) : NEW_LINE INDENT if a % b == 0 : NEW_LINE INDENT return s + ( ( a // b ) * 2 - 1 ) * b NEW_LINE DEDENT if b % a == 0 : NEW_LINE INDENT return s + ( ( b // a ) * 2 - 1 ) * a NEW_LINE DEDENT elif a > b : NEW_LINE INDENT s += ( a // b ) * 2 * b NEW_LINE return solve ( s , a % b , b ) NEW_LINE DEDENT else : NEW_LINE INDENT s += ( b // a ) * 2 * a NEW_LINE return solve ( s , a , b % a ) NEW_LINE DEDENT DEDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( n , n - x , x ) ) NEW_LINE
T415
import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long ans = n ; long a = n - x ; long b = x ; while ( b != 0 ) { long r = a / b ; long q = a % b ; ans += 2 * b * r ; if ( q == 0 ) { ans -= b ; } a = b ; b = q ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }
import sys NEW_LINE stdin = sys . stdin NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE na = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) NEW_LINE nn = lambda : list ( stdin . readline ( ) . split ( ) ) NEW_LINE ns = lambda : stdin . readline ( ) . rstrip ( ) NEW_LINE n , x = na ( ) NEW_LINE def loop ( a , b ) : NEW_LINE INDENT h = max ( a , b ) NEW_LINE w = min ( a , b ) NEW_LINE if h % w == 0 : NEW_LINE INDENT return int ( ( 2 * h / w - 1 ) * w ) NEW_LINE DEDENT else : NEW_LINE INDENT m = h % w NEW_LINE q = h // w NEW_LINE return 2 * q * w + loop ( m , w ) NEW_LINE DEDENT DEDENT print ( loop ( x , n - x ) + n ) NEW_LINE
T416
import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long ans = n ; long a = n - x ; long b = x ; while ( b != 0 ) { long r = a / b ; long q = a % b ; ans += 2 * b * r ; if ( q == 0 ) { ans -= b ; } a = b ; b = q ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }
n , x = map ( int , input ( ) . split ( ) ) NEW_LINE if ( x > n // 2 and n % 2 == 0 ) or ( x > ( n + 1 ) // 2 and n % 2 == 1 ) : NEW_LINE INDENT x = n - x NEW_LINE DEDENT A = n - x NEW_LINE B = x NEW_LINE k = 0 NEW_LINE m = - 1 NEW_LINE ans = n NEW_LINE while m != 0 : NEW_LINE INDENT k = A // B NEW_LINE m = A % B NEW_LINE ans += B * k * 2 NEW_LINE if m == 0 : NEW_LINE INDENT ans -= B NEW_LINE DEDENT A = B NEW_LINE B = m NEW_LINE DEDENT print ( ans ) NEW_LINE
T417
import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long ans = n ; long a = n - x ; long b = x ; while ( b != 0 ) { long r = a / b ; long q = a % b ; ans += 2 * b * r ; if ( q == 0 ) { ans -= b ; } a = b ; b = q ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }
def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a , b = n - x , x NEW_LINE if ( a < b ) : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT path_length = calc_path ( a , b , n ) NEW_LINE print ( path_length ) NEW_LINE DEDENT def calc_path ( a1 , b1 , c1 ) : NEW_LINE INDENT q , mod = divmod ( a1 , b1 ) NEW_LINE count = 0 NEW_LINE if mod == 0 : NEW_LINE INDENT c2 = c1 + 2 * b1 * q - b1 NEW_LINE return c2 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + 1 NEW_LINE c2 = c1 + 2 * b1 * q NEW_LINE a2 = a1 - b1 * q NEW_LINE b2 = b1 NEW_LINE if ( a2 < b2 ) : NEW_LINE INDENT a2 , b2 = b2 , a2 NEW_LINE DEDENT return calc_path ( a2 , b2 , c2 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T418
import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long ans = n ; long a = n - x ; long b = x ; while ( b != 0 ) { long r = a / b ; long q = a % b ; ans += 2 * b * r ; if ( q == 0 ) { ans -= b ; } a = b ; b = q ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }
import sys NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n , x = LI ( ) NEW_LINE b , a = sorted ( [ x , n - x ] ) NEW_LINE ans = a + b NEW_LINE while b : NEW_LINE INDENT q , mod = divmod ( a , b ) NEW_LINE ans += ( 2 * q - ( not mod ) ) * b NEW_LINE a , b = b , mod NEW_LINE DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T419
import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long ans = n ; long a = n - x ; long b = x ; while ( b != 0 ) { long r = a / b ; long q = a % b ; ans += 2 * b * r ; if ( q == 0 ) { ans -= b ; } a = b ; b = q ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }
def solve ( s , a , b ) : NEW_LINE INDENT if a % b == 0 : NEW_LINE INDENT return s + ( ( a // b ) * 2 - 1 ) * b NEW_LINE DEDENT if b % a == 0 : NEW_LINE INDENT return s + ( ( b // a ) * 2 - 1 ) * a NEW_LINE DEDENT elif a > b : NEW_LINE INDENT s += ( a // b ) * 2 * b NEW_LINE return solve ( s , a % b , b ) NEW_LINE DEDENT else : NEW_LINE INDENT s += ( b // a ) * 2 * a NEW_LINE return solve ( s , a , b % a ) NEW_LINE DEDENT DEDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( n , n - x , x ) ) NEW_LINE
T420
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; long N = sc . nextLong ( ) ; long X = sc . nextLong ( ) ; long sum = 0 ; if ( X > N / 2 ) { X = N - X ; } long big = N - X ; long mini = X ; sum = N ; while ( true ) { if ( big % mini != 0 ) { sum += mini * 2 * ( big / mini ) ; long tmp = mini ; mini = big % mini ; big = tmp ; } else { sum += mini * ( ( big / mini ) * 2 - 1 ) ; break ; } } pl ( sum ) ; } 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 pl ( ) { System . out . println ( ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }
import sys NEW_LINE stdin = sys . stdin NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE na = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) NEW_LINE nn = lambda : list ( stdin . readline ( ) . split ( ) ) NEW_LINE ns = lambda : stdin . readline ( ) . rstrip ( ) NEW_LINE n , x = na ( ) NEW_LINE def loop ( a , b ) : NEW_LINE INDENT h = max ( a , b ) NEW_LINE w = min ( a , b ) NEW_LINE if h % w == 0 : NEW_LINE INDENT return int ( ( 2 * h / w - 1 ) * w ) NEW_LINE DEDENT else : NEW_LINE INDENT m = h % w NEW_LINE q = h // w NEW_LINE return 2 * q * w + loop ( m , w ) NEW_LINE DEDENT DEDENT print ( loop ( x , n - x ) + n ) NEW_LINE
T421
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; long N = sc . nextLong ( ) ; long X = sc . nextLong ( ) ; long sum = 0 ; if ( X > N / 2 ) { X = N - X ; } long big = N - X ; long mini = X ; sum = N ; while ( true ) { if ( big % mini != 0 ) { sum += mini * 2 * ( big / mini ) ; long tmp = mini ; mini = big % mini ; big = tmp ; } else { sum += mini * ( ( big / mini ) * 2 - 1 ) ; break ; } } pl ( sum ) ; } 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 pl ( ) { System . out . println ( ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }
n , x = map ( int , input ( ) . split ( ) ) NEW_LINE if ( x > n // 2 and n % 2 == 0 ) or ( x > ( n + 1 ) // 2 and n % 2 == 1 ) : NEW_LINE INDENT x = n - x NEW_LINE DEDENT A = n - x NEW_LINE B = x NEW_LINE k = 0 NEW_LINE m = - 1 NEW_LINE ans = n NEW_LINE while m != 0 : NEW_LINE INDENT k = A // B NEW_LINE m = A % B NEW_LINE ans += B * k * 2 NEW_LINE if m == 0 : NEW_LINE INDENT ans -= B NEW_LINE DEDENT A = B NEW_LINE B = m NEW_LINE DEDENT print ( ans ) NEW_LINE
T422
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; long N = sc . nextLong ( ) ; long X = sc . nextLong ( ) ; long sum = 0 ; if ( X > N / 2 ) { X = N - X ; } long big = N - X ; long mini = X ; sum = N ; while ( true ) { if ( big % mini != 0 ) { sum += mini * 2 * ( big / mini ) ; long tmp = mini ; mini = big % mini ; big = tmp ; } else { sum += mini * ( ( big / mini ) * 2 - 1 ) ; break ; } } pl ( sum ) ; } 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 pl ( ) { System . out . println ( ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }
def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a , b = n - x , x NEW_LINE if ( a < b ) : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT path_length = calc_path ( a , b , n ) NEW_LINE print ( path_length ) NEW_LINE DEDENT def calc_path ( a1 , b1 , c1 ) : NEW_LINE INDENT q , mod = divmod ( a1 , b1 ) NEW_LINE count = 0 NEW_LINE if mod == 0 : NEW_LINE INDENT c2 = c1 + 2 * b1 * q - b1 NEW_LINE return c2 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + 1 NEW_LINE c2 = c1 + 2 * b1 * q NEW_LINE a2 = a1 - b1 * q NEW_LINE b2 = b1 NEW_LINE if ( a2 < b2 ) : NEW_LINE INDENT a2 , b2 = b2 , a2 NEW_LINE DEDENT return calc_path ( a2 , b2 , c2 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T423
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; long N = sc . nextLong ( ) ; long X = sc . nextLong ( ) ; long sum = 0 ; if ( X > N / 2 ) { X = N - X ; } long big = N - X ; long mini = X ; sum = N ; while ( true ) { if ( big % mini != 0 ) { sum += mini * 2 * ( big / mini ) ; long tmp = mini ; mini = big % mini ; big = tmp ; } else { sum += mini * ( ( big / mini ) * 2 - 1 ) ; break ; } } pl ( sum ) ; } 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 pl ( ) { System . out . println ( ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }
import sys NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n , x = LI ( ) NEW_LINE b , a = sorted ( [ x , n - x ] ) NEW_LINE ans = a + b NEW_LINE while b : NEW_LINE INDENT q , mod = divmod ( a , b ) NEW_LINE ans += ( 2 * q - ( not mod ) ) * b NEW_LINE a , b = b , mod NEW_LINE DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T424
import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; long N = sc . nextLong ( ) ; long X = sc . nextLong ( ) ; long sum = 0 ; if ( X > N / 2 ) { X = N - X ; } long big = N - X ; long mini = X ; sum = N ; while ( true ) { if ( big % mini != 0 ) { sum += mini * 2 * ( big / mini ) ; long tmp = mini ; mini = big % mini ; big = tmp ; } else { sum += mini * ( ( big / mini ) * 2 - 1 ) ; break ; } } pl ( sum ) ; } 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 pl ( ) { System . out . println ( ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } }
def solve ( s , a , b ) : NEW_LINE INDENT if a % b == 0 : NEW_LINE INDENT return s + ( ( a // b ) * 2 - 1 ) * b NEW_LINE DEDENT if b % a == 0 : NEW_LINE INDENT return s + ( ( b // a ) * 2 - 1 ) * a NEW_LINE DEDENT elif a > b : NEW_LINE INDENT s += ( a // b ) * 2 * b NEW_LINE return solve ( s , a % b , b ) NEW_LINE DEDENT else : NEW_LINE INDENT s += ( b // a ) * 2 * a NEW_LINE return solve ( s , a , b % a ) NEW_LINE DEDENT DEDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( n , n - x , x ) ) NEW_LINE
T425
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; long start = sc . nextLong ( ) ; System . out . println ( num + cal ( start , num - start ) ) ; } public static long cal ( long width , long height ) { if ( width * height == 0 ) { return - Math . max ( width , height ) ; } else if ( width == height ) { return width ; } else if ( width > height ) { return width / height * height * 2 + cal ( width % height , height ) ; } else { return height / width * width * 2 + cal ( width , height % width ) ; } } }
import sys NEW_LINE stdin = sys . stdin NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE na = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) NEW_LINE nn = lambda : list ( stdin . readline ( ) . split ( ) ) NEW_LINE ns = lambda : stdin . readline ( ) . rstrip ( ) NEW_LINE n , x = na ( ) NEW_LINE def loop ( a , b ) : NEW_LINE INDENT h = max ( a , b ) NEW_LINE w = min ( a , b ) NEW_LINE if h % w == 0 : NEW_LINE INDENT return int ( ( 2 * h / w - 1 ) * w ) NEW_LINE DEDENT else : NEW_LINE INDENT m = h % w NEW_LINE q = h // w NEW_LINE return 2 * q * w + loop ( m , w ) NEW_LINE DEDENT DEDENT print ( loop ( x , n - x ) + n ) NEW_LINE
T426
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; long start = sc . nextLong ( ) ; System . out . println ( num + cal ( start , num - start ) ) ; } public static long cal ( long width , long height ) { if ( width * height == 0 ) { return - Math . max ( width , height ) ; } else if ( width == height ) { return width ; } else if ( width > height ) { return width / height * height * 2 + cal ( width % height , height ) ; } else { return height / width * width * 2 + cal ( width , height % width ) ; } } }
n , x = map ( int , input ( ) . split ( ) ) NEW_LINE if ( x > n // 2 and n % 2 == 0 ) or ( x > ( n + 1 ) // 2 and n % 2 == 1 ) : NEW_LINE INDENT x = n - x NEW_LINE DEDENT A = n - x NEW_LINE B = x NEW_LINE k = 0 NEW_LINE m = - 1 NEW_LINE ans = n NEW_LINE while m != 0 : NEW_LINE INDENT k = A // B NEW_LINE m = A % B NEW_LINE ans += B * k * 2 NEW_LINE if m == 0 : NEW_LINE INDENT ans -= B NEW_LINE DEDENT A = B NEW_LINE B = m NEW_LINE DEDENT print ( ans ) NEW_LINE
T427
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; long start = sc . nextLong ( ) ; System . out . println ( num + cal ( start , num - start ) ) ; } public static long cal ( long width , long height ) { if ( width * height == 0 ) { return - Math . max ( width , height ) ; } else if ( width == height ) { return width ; } else if ( width > height ) { return width / height * height * 2 + cal ( width % height , height ) ; } else { return height / width * width * 2 + cal ( width , height % width ) ; } } }
def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a , b = n - x , x NEW_LINE if ( a < b ) : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT path_length = calc_path ( a , b , n ) NEW_LINE print ( path_length ) NEW_LINE DEDENT def calc_path ( a1 , b1 , c1 ) : NEW_LINE INDENT q , mod = divmod ( a1 , b1 ) NEW_LINE count = 0 NEW_LINE if mod == 0 : NEW_LINE INDENT c2 = c1 + 2 * b1 * q - b1 NEW_LINE return c2 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + 1 NEW_LINE c2 = c1 + 2 * b1 * q NEW_LINE a2 = a1 - b1 * q NEW_LINE b2 = b1 NEW_LINE if ( a2 < b2 ) : NEW_LINE INDENT a2 , b2 = b2 , a2 NEW_LINE DEDENT return calc_path ( a2 , b2 , c2 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T428
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; long start = sc . nextLong ( ) ; System . out . println ( num + cal ( start , num - start ) ) ; } public static long cal ( long width , long height ) { if ( width * height == 0 ) { return - Math . max ( width , height ) ; } else if ( width == height ) { return width ; } else if ( width > height ) { return width / height * height * 2 + cal ( width % height , height ) ; } else { return height / width * width * 2 + cal ( width , height % width ) ; } } }
import sys NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n , x = LI ( ) NEW_LINE b , a = sorted ( [ x , n - x ] ) NEW_LINE ans = a + b NEW_LINE while b : NEW_LINE INDENT q , mod = divmod ( a , b ) NEW_LINE ans += ( 2 * q - ( not mod ) ) * b NEW_LINE a , b = b , mod NEW_LINE DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T429
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; long start = sc . nextLong ( ) ; System . out . println ( num + cal ( start , num - start ) ) ; } public static long cal ( long width , long height ) { if ( width * height == 0 ) { return - Math . max ( width , height ) ; } else if ( width == height ) { return width ; } else if ( width > height ) { return width / height * height * 2 + cal ( width % height , height ) ; } else { return height / width * width * 2 + cal ( width , height % width ) ; } } }
def solve ( s , a , b ) : NEW_LINE INDENT if a % b == 0 : NEW_LINE INDENT return s + ( ( a // b ) * 2 - 1 ) * b NEW_LINE DEDENT if b % a == 0 : NEW_LINE INDENT return s + ( ( b // a ) * 2 - 1 ) * a NEW_LINE DEDENT elif a > b : NEW_LINE INDENT s += ( a // b ) * 2 * b NEW_LINE return solve ( s , a % b , b ) NEW_LINE DEDENT else : NEW_LINE INDENT s += ( b // a ) * 2 * a NEW_LINE return solve ( s , a , b % a ) NEW_LINE DEDENT DEDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( n , n - x , x ) ) NEW_LINE
T430
import java . util . Scanner ; public class Main { public long solve ( long N , long X ) { long longEdge = Math . max ( X , N - X ) ; long shortEdge = Math . min ( X , N - X ) ; long length = X + N - X ; long times = 1 ; while ( shortEdge > 0 ) { long num = longEdge / shortEdge ; long left = longEdge - ( shortEdge * num ) ; length += ( shortEdge * num * 2 ) ; longEdge = shortEdge ; shortEdge = left ; times ++ ; } length -= longEdge ; return length ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long N = in . nextLong ( ) ; long X = in . nextLong ( ) ; in . close ( ) ; Main main = new Main ( ) ; long result = main . solve ( N , X ) ; System . out . println ( result ) ; } }
import sys NEW_LINE stdin = sys . stdin NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE na = lambda : list ( map ( int , stdin . readline ( ) . split ( ) ) ) NEW_LINE nn = lambda : list ( stdin . readline ( ) . split ( ) ) NEW_LINE ns = lambda : stdin . readline ( ) . rstrip ( ) NEW_LINE n , x = na ( ) NEW_LINE def loop ( a , b ) : NEW_LINE INDENT h = max ( a , b ) NEW_LINE w = min ( a , b ) NEW_LINE if h % w == 0 : NEW_LINE INDENT return int ( ( 2 * h / w - 1 ) * w ) NEW_LINE DEDENT else : NEW_LINE INDENT m = h % w NEW_LINE q = h // w NEW_LINE return 2 * q * w + loop ( m , w ) NEW_LINE DEDENT DEDENT print ( loop ( x , n - x ) + n ) NEW_LINE
T431
import java . util . Scanner ; public class Main { public long solve ( long N , long X ) { long longEdge = Math . max ( X , N - X ) ; long shortEdge = Math . min ( X , N - X ) ; long length = X + N - X ; long times = 1 ; while ( shortEdge > 0 ) { long num = longEdge / shortEdge ; long left = longEdge - ( shortEdge * num ) ; length += ( shortEdge * num * 2 ) ; longEdge = shortEdge ; shortEdge = left ; times ++ ; } length -= longEdge ; return length ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long N = in . nextLong ( ) ; long X = in . nextLong ( ) ; in . close ( ) ; Main main = new Main ( ) ; long result = main . solve ( N , X ) ; System . out . println ( result ) ; } }
n , x = map ( int , input ( ) . split ( ) ) NEW_LINE if ( x > n // 2 and n % 2 == 0 ) or ( x > ( n + 1 ) // 2 and n % 2 == 1 ) : NEW_LINE INDENT x = n - x NEW_LINE DEDENT A = n - x NEW_LINE B = x NEW_LINE k = 0 NEW_LINE m = - 1 NEW_LINE ans = n NEW_LINE while m != 0 : NEW_LINE INDENT k = A // B NEW_LINE m = A % B NEW_LINE ans += B * k * 2 NEW_LINE if m == 0 : NEW_LINE INDENT ans -= B NEW_LINE DEDENT A = B NEW_LINE B = m NEW_LINE DEDENT print ( ans ) NEW_LINE
T432
import java . util . Scanner ; public class Main { public long solve ( long N , long X ) { long longEdge = Math . max ( X , N - X ) ; long shortEdge = Math . min ( X , N - X ) ; long length = X + N - X ; long times = 1 ; while ( shortEdge > 0 ) { long num = longEdge / shortEdge ; long left = longEdge - ( shortEdge * num ) ; length += ( shortEdge * num * 2 ) ; longEdge = shortEdge ; shortEdge = left ; times ++ ; } length -= longEdge ; return length ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long N = in . nextLong ( ) ; long X = in . nextLong ( ) ; in . close ( ) ; Main main = new Main ( ) ; long result = main . solve ( N , X ) ; System . out . println ( result ) ; } }
def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a , b = n - x , x NEW_LINE if ( a < b ) : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT path_length = calc_path ( a , b , n ) NEW_LINE print ( path_length ) NEW_LINE DEDENT def calc_path ( a1 , b1 , c1 ) : NEW_LINE INDENT q , mod = divmod ( a1 , b1 ) NEW_LINE count = 0 NEW_LINE if mod == 0 : NEW_LINE INDENT c2 = c1 + 2 * b1 * q - b1 NEW_LINE return c2 NEW_LINE DEDENT else : NEW_LINE INDENT count = count + 1 NEW_LINE c2 = c1 + 2 * b1 * q NEW_LINE a2 = a1 - b1 * q NEW_LINE b2 = b1 NEW_LINE if ( a2 < b2 ) : NEW_LINE INDENT a2 , b2 = b2 , a2 NEW_LINE DEDENT return calc_path ( a2 , b2 , c2 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
T433
import java . util . Scanner ; public class Main { public long solve ( long N , long X ) { long longEdge = Math . max ( X , N - X ) ; long shortEdge = Math . min ( X , N - X ) ; long length = X + N - X ; long times = 1 ; while ( shortEdge > 0 ) { long num = longEdge / shortEdge ; long left = longEdge - ( shortEdge * num ) ; length += ( shortEdge * num * 2 ) ; longEdge = shortEdge ; shortEdge = left ; times ++ ; } length -= longEdge ; return length ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long N = in . nextLong ( ) ; long X = in . nextLong ( ) ; in . close ( ) ; Main main = new Main ( ) ; long result = main . solve ( N , X ) ; System . out . println ( result ) ; } }
import sys NEW_LINE INF = float ( ' inf ' ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT n , x = LI ( ) NEW_LINE b , a = sorted ( [ x , n - x ] ) NEW_LINE ans = a + b NEW_LINE while b : NEW_LINE INDENT q , mod = divmod ( a , b ) NEW_LINE ans += ( 2 * q - ( not mod ) ) * b NEW_LINE a , b = b , mod NEW_LINE DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE
T434
import java . util . Scanner ; public class Main { public long solve ( long N , long X ) { long longEdge = Math . max ( X , N - X ) ; long shortEdge = Math . min ( X , N - X ) ; long length = X + N - X ; long times = 1 ; while ( shortEdge > 0 ) { long num = longEdge / shortEdge ; long left = longEdge - ( shortEdge * num ) ; length += ( shortEdge * num * 2 ) ; longEdge = shortEdge ; shortEdge = left ; times ++ ; } length -= longEdge ; return length ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long N = in . nextLong ( ) ; long X = in . nextLong ( ) ; in . close ( ) ; Main main = new Main ( ) ; long result = main . solve ( N , X ) ; System . out . println ( result ) ; } }
def solve ( s , a , b ) : NEW_LINE INDENT if a % b == 0 : NEW_LINE INDENT return s + ( ( a // b ) * 2 - 1 ) * b NEW_LINE DEDENT if b % a == 0 : NEW_LINE INDENT return s + ( ( b // a ) * 2 - 1 ) * a NEW_LINE DEDENT elif a > b : NEW_LINE INDENT s += ( a // b ) * 2 * b NEW_LINE return solve ( s , a % b , b ) NEW_LINE DEDENT else : NEW_LINE INDENT s += ( b // a ) * 2 * a NEW_LINE return solve ( s , a , b % a ) NEW_LINE DEDENT DEDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE print ( solve ( n , n - x , x ) ) NEW_LINE
T435
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; scanner . close ( ) ; String formatted = " " ; if ( s . length ( ) == 1 ) { formatted = s . toUpperCase ( ) ; } else { formatted = s . substring ( 0 , 1 ) . toUpperCase ( ) + s . substring ( 1 , s . length ( ) ) . toLowerCase ( ) ; } System . out . println ( formatted ) ; } }
s = str ( input ( ) ) NEW_LINE print ( s . capitalize ( ) ) NEW_LINE
T436
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; scanner . close ( ) ; String formatted = " " ; if ( s . length ( ) == 1 ) { formatted = s . toUpperCase ( ) ; } else { formatted = s . substring ( 0 , 1 ) . toUpperCase ( ) + s . substring ( 1 , s . length ( ) ) . toLowerCase ( ) ; } System . out . println ( formatted ) ; } }
s = input ( ) NEW_LINE s = s . lower ( ) NEW_LINE if len ( s ) >= 2 : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) ) NEW_LINE DEDENT
T437
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; scanner . close ( ) ; String formatted = " " ; if ( s . length ( ) == 1 ) { formatted = s . toUpperCase ( ) ; } else { formatted = s . substring ( 0 , 1 ) . toUpperCase ( ) + s . substring ( 1 , s . length ( ) ) . toLowerCase ( ) ; } System . out . println ( formatted ) ; } }
s = input ( ) NEW_LINE if len ( s ) == 1 : NEW_LINE INDENT print ( s . upper ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] . lower ( ) ) NEW_LINE DEDENT
T438
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; scanner . close ( ) ; String formatted = " " ; if ( s . length ( ) == 1 ) { formatted = s . toUpperCase ( ) ; } else { formatted = s . substring ( 0 , 1 ) . toUpperCase ( ) + s . substring ( 1 , s . length ( ) ) . toLowerCase ( ) ; } System . out . println ( formatted ) ; } }
print ( input ( ) . capitalize ( ) ) NEW_LINE
T439
import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; scanner . close ( ) ; String formatted = " " ; if ( s . length ( ) == 1 ) { formatted = s . toUpperCase ( ) ; } else { formatted = s . substring ( 0 , 1 ) . toUpperCase ( ) + s . substring ( 1 , s . length ( ) ) . toLowerCase ( ) ; } System . out . println ( formatted ) ; } }
s = list ( input ( ) ) NEW_LINE s [ 0 ] = s [ 0 ] . upper ( ) NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = s [ i ] . lower ( ) NEW_LINE DEDENT print ( " " . join ( s ) ) NEW_LINE
T440
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 ) { String s = in . next ( ) ; out . print ( Character . toUpperCase ( s . charAt ( 0 ) ) ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { out . print ( Character . toLowerCase ( s . charAt ( i ) ) ) ; } out . println ( ) ; } } 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 ( ) ; } } }
s = str ( input ( ) ) NEW_LINE print ( s . capitalize ( ) ) NEW_LINE
T441
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 ) { String s = in . next ( ) ; out . print ( Character . toUpperCase ( s . charAt ( 0 ) ) ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { out . print ( Character . toLowerCase ( s . charAt ( i ) ) ) ; } out . println ( ) ; } } 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 ( ) ; } } }
s = input ( ) NEW_LINE s = s . lower ( ) NEW_LINE if len ( s ) >= 2 : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) ) NEW_LINE DEDENT
T442
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 ) { String s = in . next ( ) ; out . print ( Character . toUpperCase ( s . charAt ( 0 ) ) ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { out . print ( Character . toLowerCase ( s . charAt ( i ) ) ) ; } out . println ( ) ; } } 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 ( ) ; } } }
s = input ( ) NEW_LINE if len ( s ) == 1 : NEW_LINE INDENT print ( s . upper ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] . lower ( ) ) NEW_LINE DEDENT
T443
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 ) { String s = in . next ( ) ; out . print ( Character . toUpperCase ( s . charAt ( 0 ) ) ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { out . print ( Character . toLowerCase ( s . charAt ( i ) ) ) ; } out . println ( ) ; } } 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 ( ) ; } } }
print ( input ( ) . capitalize ( ) ) NEW_LINE
T444
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 ) { String s = in . next ( ) ; out . print ( Character . toUpperCase ( s . charAt ( 0 ) ) ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { out . print ( Character . toLowerCase ( s . charAt ( i ) ) ) ; } out . println ( ) ; } } 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 ( ) ; } } }
s = list ( input ( ) ) NEW_LINE s [ 0 ] = s [ 0 ] . upper ( ) NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = s [ i ] . lower ( ) NEW_LINE DEDENT print ( " " . join ( s ) ) NEW_LINE
T445
import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String cap = s . substring ( 0 , 1 ) . toUpperCase ( ) ; String other = s . substring ( 1 ) . toLowerCase ( ) ; System . out . println ( cap + other ) ; sc . close ( ) ; } private static long gcd ( Long m , long n ) { if ( m < n ) { return gcd ( n , m ) ; } if ( n == 0 ) { return m ; } return gcd ( n , m % n ) ; } private static long [ ] [ ] Combination_nCk ( long n , long k ) { n ++ ; k ++ ; long [ ] [ ] ans = new long [ ( int ) n ] [ ( int ) k ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ i ] [ 0 ] = 1 ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < k - 1 ; j ++ ) { if ( i < j ) { ans [ i ] [ j ] = 0 ; } else { ans [ i + 1 ] [ j + 1 ] = ans [ i ] [ j ] + ans [ i ] [ j + 1 ] ; } } } return ans ; } }
s = str ( input ( ) ) NEW_LINE print ( s . capitalize ( ) ) NEW_LINE
T446
import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String cap = s . substring ( 0 , 1 ) . toUpperCase ( ) ; String other = s . substring ( 1 ) . toLowerCase ( ) ; System . out . println ( cap + other ) ; sc . close ( ) ; } private static long gcd ( Long m , long n ) { if ( m < n ) { return gcd ( n , m ) ; } if ( n == 0 ) { return m ; } return gcd ( n , m % n ) ; } private static long [ ] [ ] Combination_nCk ( long n , long k ) { n ++ ; k ++ ; long [ ] [ ] ans = new long [ ( int ) n ] [ ( int ) k ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ i ] [ 0 ] = 1 ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < k - 1 ; j ++ ) { if ( i < j ) { ans [ i ] [ j ] = 0 ; } else { ans [ i + 1 ] [ j + 1 ] = ans [ i ] [ j ] + ans [ i ] [ j + 1 ] ; } } } return ans ; } }
s = input ( ) NEW_LINE s = s . lower ( ) NEW_LINE if len ( s ) >= 2 : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) ) NEW_LINE DEDENT
T447
import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String cap = s . substring ( 0 , 1 ) . toUpperCase ( ) ; String other = s . substring ( 1 ) . toLowerCase ( ) ; System . out . println ( cap + other ) ; sc . close ( ) ; } private static long gcd ( Long m , long n ) { if ( m < n ) { return gcd ( n , m ) ; } if ( n == 0 ) { return m ; } return gcd ( n , m % n ) ; } private static long [ ] [ ] Combination_nCk ( long n , long k ) { n ++ ; k ++ ; long [ ] [ ] ans = new long [ ( int ) n ] [ ( int ) k ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ i ] [ 0 ] = 1 ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < k - 1 ; j ++ ) { if ( i < j ) { ans [ i ] [ j ] = 0 ; } else { ans [ i + 1 ] [ j + 1 ] = ans [ i ] [ j ] + ans [ i ] [ j + 1 ] ; } } } return ans ; } }
s = input ( ) NEW_LINE if len ( s ) == 1 : NEW_LINE INDENT print ( s . upper ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] . lower ( ) ) NEW_LINE DEDENT
T448
import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String cap = s . substring ( 0 , 1 ) . toUpperCase ( ) ; String other = s . substring ( 1 ) . toLowerCase ( ) ; System . out . println ( cap + other ) ; sc . close ( ) ; } private static long gcd ( Long m , long n ) { if ( m < n ) { return gcd ( n , m ) ; } if ( n == 0 ) { return m ; } return gcd ( n , m % n ) ; } private static long [ ] [ ] Combination_nCk ( long n , long k ) { n ++ ; k ++ ; long [ ] [ ] ans = new long [ ( int ) n ] [ ( int ) k ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ i ] [ 0 ] = 1 ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < k - 1 ; j ++ ) { if ( i < j ) { ans [ i ] [ j ] = 0 ; } else { ans [ i + 1 ] [ j + 1 ] = ans [ i ] [ j ] + ans [ i ] [ j + 1 ] ; } } } return ans ; } }
print ( input ( ) . capitalize ( ) ) NEW_LINE
T449
import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String cap = s . substring ( 0 , 1 ) . toUpperCase ( ) ; String other = s . substring ( 1 ) . toLowerCase ( ) ; System . out . println ( cap + other ) ; sc . close ( ) ; } private static long gcd ( Long m , long n ) { if ( m < n ) { return gcd ( n , m ) ; } if ( n == 0 ) { return m ; } return gcd ( n , m % n ) ; } private static long [ ] [ ] Combination_nCk ( long n , long k ) { n ++ ; k ++ ; long [ ] [ ] ans = new long [ ( int ) n ] [ ( int ) k ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ i ] [ 0 ] = 1 ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < k - 1 ; j ++ ) { if ( i < j ) { ans [ i ] [ j ] = 0 ; } else { ans [ i + 1 ] [ j + 1 ] = ans [ i ] [ j ] + ans [ i ] [ j + 1 ] ; } } } return ans ; } }
s = list ( input ( ) ) NEW_LINE s [ 0 ] = s [ 0 ] . upper ( ) NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = s [ i ] . lower ( ) NEW_LINE DEDENT print ( " " . join ( s ) ) NEW_LINE
T450
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 ( ) ; out . println ( S . toUpperCase ( ) . charAt ( 0 ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } } 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 ( ) ) ; } } }
s = str ( input ( ) ) NEW_LINE print ( s . capitalize ( ) ) NEW_LINE
T451
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 ( ) ; out . println ( S . toUpperCase ( ) . charAt ( 0 ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } } 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 ( ) ) ; } } }
s = input ( ) NEW_LINE s = s . lower ( ) NEW_LINE if len ( s ) >= 2 : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) ) NEW_LINE DEDENT
T452
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 ( ) ; out . println ( S . toUpperCase ( ) . charAt ( 0 ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } } 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 ( ) ) ; } } }
s = input ( ) NEW_LINE if len ( s ) == 1 : NEW_LINE INDENT print ( s . upper ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] . lower ( ) ) NEW_LINE DEDENT
T453
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 ( ) ; out . println ( S . toUpperCase ( ) . charAt ( 0 ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } } 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 ( ) ) ; } } }
print ( input ( ) . capitalize ( ) ) NEW_LINE
T454
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 ( ) ; out . println ( S . toUpperCase ( ) . charAt ( 0 ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } } 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 ( ) ) ; } } }
s = list ( input ( ) ) NEW_LINE s [ 0 ] = s [ 0 ] . upper ( ) NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = s [ i ] . lower ( ) NEW_LINE DEDENT print ( " " . join ( s ) ) NEW_LINE
T455
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 ( ) ; System . out . println ( S . substring ( 0 , 1 ) . toUpperCase ( ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } }
s = str ( input ( ) ) NEW_LINE print ( s . capitalize ( ) ) NEW_LINE
T456
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 ( ) ; System . out . println ( S . substring ( 0 , 1 ) . toUpperCase ( ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } }
s = input ( ) NEW_LINE s = s . lower ( ) NEW_LINE if len ( s ) >= 2 : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) ) NEW_LINE DEDENT
T457
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 ( ) ; System . out . println ( S . substring ( 0 , 1 ) . toUpperCase ( ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } }
s = input ( ) NEW_LINE if len ( s ) == 1 : NEW_LINE INDENT print ( s . upper ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ 0 ] . upper ( ) + s [ 1 : ] . lower ( ) ) NEW_LINE DEDENT
T458
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 ( ) ; System . out . println ( S . substring ( 0 , 1 ) . toUpperCase ( ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } }
print ( input ( ) . capitalize ( ) ) NEW_LINE
T459
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 ( ) ; System . out . println ( S . substring ( 0 , 1 ) . toUpperCase ( ) + S . substring ( 1 ) . toLowerCase ( ) ) ; } }
s = list ( input ( ) ) NEW_LINE s [ 0 ] = s [ 0 ] . upper ( ) NEW_LINE for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT s [ i ] = s [ i ] . lower ( ) NEW_LINE DEDENT print ( " " . join ( s ) ) NEW_LINE
T460
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; boolean b1 , b2 = false , b3 = true ; b1 = ( s . charAt ( 0 ) == ' A ' ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( i != 1 && i != s . length ( ) - 1 && c == ' C ' ) { if ( ! b2 ) { b2 = true ; } else { b1 = false ; } } else if ( Character . isUpperCase ( c ) ) { b3 = false ; } } if ( b1 && b2 && b3 ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
from collections import Counter NEW_LINE from functools import reduce NEW_LINE import fractions NEW_LINE import math NEW_LINE import statistics NEW_LINE import sys NEW_LINE import time NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) 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 MI ( ) : return map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def IS ( ) : return input ( ) NEW_LINE def P ( x ) : return print ( x ) NEW_LINE def C ( x ) : return Counter ( x ) NEW_LINE def GCD_LIST ( numbers ) : NEW_LINE INDENT return reduce ( fractions . gcd , numbers ) NEW_LINE DEDENT def LCM_LIST ( numbers ) : NEW_LINE INDENT return reduce ( LCM , numbers ) NEW_LINE DEDENT def LCM ( m , n ) : NEW_LINE INDENT return ( m * n // fractions . gcd ( m , n ) ) NEW_LINE DEDENT s = IS ( ) NEW_LINE if s [ 0 ] == ' A ' and s [ 2 : len ( s ) - 1 ] . count ( ' C ' ) == 1 and ' ' . join ( [ s [ i ] for i in range ( 1 , len ( s ) ) if not i == s . index ( ' C ' ) ] ) . islower ( ) : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T461
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; boolean b1 , b2 = false , b3 = true ; b1 = ( s . charAt ( 0 ) == ' A ' ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( i != 1 && i != s . length ( ) - 1 && c == ' C ' ) { if ( ! b2 ) { b2 = true ; } else { b1 = false ; } } else if ( Character . isUpperCase ( c ) ) { b3 = false ; } } if ( b1 && b2 && b3 ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
s = input ( ) NEW_LINE a = " AC " NEW_LINE if s [ 0 ] != " A " : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT cnt = 0 NEW_LINE for i in range ( 2 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT if cnt != 1 : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] != " C " and ord ( s [ i ] ) < ord ( " a " ) : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT DEDENT print ( a ) NEW_LINE
T462
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; boolean b1 , b2 = false , b3 = true ; b1 = ( s . charAt ( 0 ) == ' A ' ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( i != 1 && i != s . length ( ) - 1 && c == ' C ' ) { if ( ! b2 ) { b2 = true ; } else { b1 = false ; } } else if ( Character . isUpperCase ( c ) ) { b3 = false ; } } if ( b1 && b2 && b3 ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
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 def solve ( S : str ) : NEW_LINE INDENT if S [ 0 ] != " A " : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT if S [ 2 : - 1 ] . count ( " C " ) != 1 : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT flag = False NEW_LINE for i , c in enumerate ( S ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if ord ( " a " ) <= ord ( c ) and ord ( c ) <= ord ( " z " ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif 1 < i and i < len ( S ) - 1 and c == " C " and flag == False : NEW_LINE INDENT flag = True NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " AC " ) 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
T463
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; boolean b1 , b2 = false , b3 = true ; b1 = ( s . charAt ( 0 ) == ' A ' ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( i != 1 && i != s . length ( ) - 1 && c == ' C ' ) { if ( ! b2 ) { b2 = true ; } else { b1 = false ; } } else if ( Character . isUpperCase ( c ) ) { b3 = false ; } } if ( b1 && b2 && b3 ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
S = [ i for i in input ( ) ] NEW_LINE count = 0 NEW_LINE if S . pop ( 0 ) == ' A ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if S [ 1 : - 1 ] . count ( ' C ' ) == 1 : NEW_LINE INDENT count += 1 NEW_LINE S . remove ( ' C ' ) NEW_LINE if ' ' . join ( S ) . islower ( ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( ' AC ' if count == 3 else ' WA ' ) NEW_LINE
T464
import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; boolean b1 , b2 = false , b3 = true ; b1 = ( s . charAt ( 0 ) == ' A ' ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( i != 1 && i != s . length ( ) - 1 && c == ' C ' ) { if ( ! b2 ) { b2 = true ; } else { b1 = false ; } } else if ( Character . isUpperCase ( c ) ) { b3 = false ; } } if ( b1 && b2 && b3 ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
S = input ( ) NEW_LINE if S [ 0 ] == ' A ' : NEW_LINE INDENT f1 = True NEW_LINE DEDENT else : NEW_LINE INDENT f1 = False NEW_LINE DEDENT C_cnt = 0 NEW_LINE for s in S [ 2 : - 1 ] : NEW_LINE INDENT if s == ' C ' : NEW_LINE INDENT C_cnt += 1 NEW_LINE DEDENT DEDENT if C_cnt == 1 : NEW_LINE INDENT f2 = True NEW_LINE DEDENT else : NEW_LINE INDENT f2 = False NEW_LINE DEDENT f3 = True NEW_LINE for s in S : NEW_LINE INDENT if s == ' A ' or s == ' C ' : NEW_LINE INDENT continue NEW_LINE DEDENT if s != s . lower ( ) : NEW_LINE INDENT f3 = False NEW_LINE break NEW_LINE DEDENT DEDENT if f1 and f2 and f3 : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T465
import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( s . matches ( " A [ a - z ] + C [ a - z ] + " ) ? " AC " : " WA " ) ; sc . close ( ) ; } }
from collections import Counter NEW_LINE from functools import reduce NEW_LINE import fractions NEW_LINE import math NEW_LINE import statistics NEW_LINE import sys NEW_LINE import time NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) 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 MI ( ) : return map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def IS ( ) : return input ( ) NEW_LINE def P ( x ) : return print ( x ) NEW_LINE def C ( x ) : return Counter ( x ) NEW_LINE def GCD_LIST ( numbers ) : NEW_LINE INDENT return reduce ( fractions . gcd , numbers ) NEW_LINE DEDENT def LCM_LIST ( numbers ) : NEW_LINE INDENT return reduce ( LCM , numbers ) NEW_LINE DEDENT def LCM ( m , n ) : NEW_LINE INDENT return ( m * n // fractions . gcd ( m , n ) ) NEW_LINE DEDENT s = IS ( ) NEW_LINE if s [ 0 ] == ' A ' and s [ 2 : len ( s ) - 1 ] . count ( ' C ' ) == 1 and ' ' . join ( [ s [ i ] for i in range ( 1 , len ( s ) ) if not i == s . index ( ' C ' ) ] ) . islower ( ) : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T466
import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( s . matches ( " A [ a - z ] + C [ a - z ] + " ) ? " AC " : " WA " ) ; sc . close ( ) ; } }
s = input ( ) NEW_LINE a = " AC " NEW_LINE if s [ 0 ] != " A " : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT cnt = 0 NEW_LINE for i in range ( 2 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT if cnt != 1 : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] != " C " and ord ( s [ i ] ) < ord ( " a " ) : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT DEDENT print ( a ) NEW_LINE
T467
import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( s . matches ( " A [ a - z ] + C [ a - z ] + " ) ? " AC " : " WA " ) ; sc . close ( ) ; } }
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 def solve ( S : str ) : NEW_LINE INDENT if S [ 0 ] != " A " : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT if S [ 2 : - 1 ] . count ( " C " ) != 1 : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT flag = False NEW_LINE for i , c in enumerate ( S ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if ord ( " a " ) <= ord ( c ) and ord ( c ) <= ord ( " z " ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif 1 < i and i < len ( S ) - 1 and c == " C " and flag == False : NEW_LINE INDENT flag = True NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " AC " ) 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
T468
import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( s . matches ( " A [ a - z ] + C [ a - z ] + " ) ? " AC " : " WA " ) ; sc . close ( ) ; } }
S = [ i for i in input ( ) ] NEW_LINE count = 0 NEW_LINE if S . pop ( 0 ) == ' A ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if S [ 1 : - 1 ] . count ( ' C ' ) == 1 : NEW_LINE INDENT count += 1 NEW_LINE S . remove ( ' C ' ) NEW_LINE if ' ' . join ( S ) . islower ( ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( ' AC ' if count == 3 else ' WA ' ) NEW_LINE
T469
import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( s . matches ( " A [ a - z ] + C [ a - z ] + " ) ? " AC " : " WA " ) ; sc . close ( ) ; } }
S = input ( ) NEW_LINE if S [ 0 ] == ' A ' : NEW_LINE INDENT f1 = True NEW_LINE DEDENT else : NEW_LINE INDENT f1 = False NEW_LINE DEDENT C_cnt = 0 NEW_LINE for s in S [ 2 : - 1 ] : NEW_LINE INDENT if s == ' C ' : NEW_LINE INDENT C_cnt += 1 NEW_LINE DEDENT DEDENT if C_cnt == 1 : NEW_LINE INDENT f2 = True NEW_LINE DEDENT else : NEW_LINE INDENT f2 = False NEW_LINE DEDENT f3 = True NEW_LINE for s in S : NEW_LINE INDENT if s == ' A ' or s == ' C ' : NEW_LINE INDENT continue NEW_LINE DEDENT if s != s . lower ( ) : NEW_LINE INDENT f3 = False NEW_LINE break NEW_LINE DEDENT DEDENT if f1 and f2 and f3 : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T470
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int size = str . length ( ) ; if ( " A " . equals ( str . substring ( 0 , 1 ) ) ) { int num = 0 ; String str2 = str . substring ( 2 , size - 1 ) ; int size2 = str2 . length ( ) ; for ( int i = 0 ; i < size2 ; i ++ ) { String str4 = str2 . substring ( 0 , 1 ) ; if ( str4 . equals ( " C " ) ) { num = num + 1 ; } str2 = str2 . substring ( 1 ) ; } if ( num == 1 ) { str2 = str . substring ( 2 , size - 1 ) ; str2 = str2 . replace ( " C " , " c " ) ; str2 = str2 . concat ( str . substring ( str . length ( ) - 1 ) ) ; str2 = str . substring ( 1 , 2 ) . concat ( str2 ) ; String str3 = str2 . toLowerCase ( ) ; if ( str2 . equals ( str3 ) ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } }
from collections import Counter NEW_LINE from functools import reduce NEW_LINE import fractions NEW_LINE import math NEW_LINE import statistics NEW_LINE import sys NEW_LINE import time NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) 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 MI ( ) : return map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def IS ( ) : return input ( ) NEW_LINE def P ( x ) : return print ( x ) NEW_LINE def C ( x ) : return Counter ( x ) NEW_LINE def GCD_LIST ( numbers ) : NEW_LINE INDENT return reduce ( fractions . gcd , numbers ) NEW_LINE DEDENT def LCM_LIST ( numbers ) : NEW_LINE INDENT return reduce ( LCM , numbers ) NEW_LINE DEDENT def LCM ( m , n ) : NEW_LINE INDENT return ( m * n // fractions . gcd ( m , n ) ) NEW_LINE DEDENT s = IS ( ) NEW_LINE if s [ 0 ] == ' A ' and s [ 2 : len ( s ) - 1 ] . count ( ' C ' ) == 1 and ' ' . join ( [ s [ i ] for i in range ( 1 , len ( s ) ) if not i == s . index ( ' C ' ) ] ) . islower ( ) : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T471
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int size = str . length ( ) ; if ( " A " . equals ( str . substring ( 0 , 1 ) ) ) { int num = 0 ; String str2 = str . substring ( 2 , size - 1 ) ; int size2 = str2 . length ( ) ; for ( int i = 0 ; i < size2 ; i ++ ) { String str4 = str2 . substring ( 0 , 1 ) ; if ( str4 . equals ( " C " ) ) { num = num + 1 ; } str2 = str2 . substring ( 1 ) ; } if ( num == 1 ) { str2 = str . substring ( 2 , size - 1 ) ; str2 = str2 . replace ( " C " , " c " ) ; str2 = str2 . concat ( str . substring ( str . length ( ) - 1 ) ) ; str2 = str . substring ( 1 , 2 ) . concat ( str2 ) ; String str3 = str2 . toLowerCase ( ) ; if ( str2 . equals ( str3 ) ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } }
s = input ( ) NEW_LINE a = " AC " NEW_LINE if s [ 0 ] != " A " : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT cnt = 0 NEW_LINE for i in range ( 2 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT if cnt != 1 : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] != " C " and ord ( s [ i ] ) < ord ( " a " ) : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT DEDENT print ( a ) NEW_LINE
T472
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int size = str . length ( ) ; if ( " A " . equals ( str . substring ( 0 , 1 ) ) ) { int num = 0 ; String str2 = str . substring ( 2 , size - 1 ) ; int size2 = str2 . length ( ) ; for ( int i = 0 ; i < size2 ; i ++ ) { String str4 = str2 . substring ( 0 , 1 ) ; if ( str4 . equals ( " C " ) ) { num = num + 1 ; } str2 = str2 . substring ( 1 ) ; } if ( num == 1 ) { str2 = str . substring ( 2 , size - 1 ) ; str2 = str2 . replace ( " C " , " c " ) ; str2 = str2 . concat ( str . substring ( str . length ( ) - 1 ) ) ; str2 = str . substring ( 1 , 2 ) . concat ( str2 ) ; String str3 = str2 . toLowerCase ( ) ; if ( str2 . equals ( str3 ) ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } }
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 def solve ( S : str ) : NEW_LINE INDENT if S [ 0 ] != " A " : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT if S [ 2 : - 1 ] . count ( " C " ) != 1 : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT flag = False NEW_LINE for i , c in enumerate ( S ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if ord ( " a " ) <= ord ( c ) and ord ( c ) <= ord ( " z " ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif 1 < i and i < len ( S ) - 1 and c == " C " and flag == False : NEW_LINE INDENT flag = True NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " AC " ) 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
T473
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int size = str . length ( ) ; if ( " A " . equals ( str . substring ( 0 , 1 ) ) ) { int num = 0 ; String str2 = str . substring ( 2 , size - 1 ) ; int size2 = str2 . length ( ) ; for ( int i = 0 ; i < size2 ; i ++ ) { String str4 = str2 . substring ( 0 , 1 ) ; if ( str4 . equals ( " C " ) ) { num = num + 1 ; } str2 = str2 . substring ( 1 ) ; } if ( num == 1 ) { str2 = str . substring ( 2 , size - 1 ) ; str2 = str2 . replace ( " C " , " c " ) ; str2 = str2 . concat ( str . substring ( str . length ( ) - 1 ) ) ; str2 = str . substring ( 1 , 2 ) . concat ( str2 ) ; String str3 = str2 . toLowerCase ( ) ; if ( str2 . equals ( str3 ) ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } }
S = [ i for i in input ( ) ] NEW_LINE count = 0 NEW_LINE if S . pop ( 0 ) == ' A ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if S [ 1 : - 1 ] . count ( ' C ' ) == 1 : NEW_LINE INDENT count += 1 NEW_LINE S . remove ( ' C ' ) NEW_LINE if ' ' . join ( S ) . islower ( ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( ' AC ' if count == 3 else ' WA ' ) NEW_LINE
T474
import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int size = str . length ( ) ; if ( " A " . equals ( str . substring ( 0 , 1 ) ) ) { int num = 0 ; String str2 = str . substring ( 2 , size - 1 ) ; int size2 = str2 . length ( ) ; for ( int i = 0 ; i < size2 ; i ++ ) { String str4 = str2 . substring ( 0 , 1 ) ; if ( str4 . equals ( " C " ) ) { num = num + 1 ; } str2 = str2 . substring ( 1 ) ; } if ( num == 1 ) { str2 = str . substring ( 2 , size - 1 ) ; str2 = str2 . replace ( " C " , " c " ) ; str2 = str2 . concat ( str . substring ( str . length ( ) - 1 ) ) ; str2 = str . substring ( 1 , 2 ) . concat ( str2 ) ; String str3 = str2 . toLowerCase ( ) ; if ( str2 . equals ( str3 ) ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } else { System . out . println ( " WA " ) ; } } }
S = input ( ) NEW_LINE if S [ 0 ] == ' A ' : NEW_LINE INDENT f1 = True NEW_LINE DEDENT else : NEW_LINE INDENT f1 = False NEW_LINE DEDENT C_cnt = 0 NEW_LINE for s in S [ 2 : - 1 ] : NEW_LINE INDENT if s == ' C ' : NEW_LINE INDENT C_cnt += 1 NEW_LINE DEDENT DEDENT if C_cnt == 1 : NEW_LINE INDENT f2 = True NEW_LINE DEDENT else : NEW_LINE INDENT f2 = False NEW_LINE DEDENT f3 = True NEW_LINE for s in S : NEW_LINE INDENT if s == ' A ' or s == ' C ' : NEW_LINE INDENT continue NEW_LINE DEDENT if s != s . lower ( ) : NEW_LINE INDENT f3 = False NEW_LINE break NEW_LINE DEDENT DEDENT if f1 and f2 and f3 : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T475
import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { String str = ( new Scanner ( System . in ) ) . next ( ) ; String ans = str . matches ( " ^ A [ a - z ] + C [ a - z ] + $ " ) ? " AC " : " WA " ; System . out . println ( ans ) ; } }
from collections import Counter NEW_LINE from functools import reduce NEW_LINE import fractions NEW_LINE import math NEW_LINE import statistics NEW_LINE import sys NEW_LINE import time NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) 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 MI ( ) : return map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def IS ( ) : return input ( ) NEW_LINE def P ( x ) : return print ( x ) NEW_LINE def C ( x ) : return Counter ( x ) NEW_LINE def GCD_LIST ( numbers ) : NEW_LINE INDENT return reduce ( fractions . gcd , numbers ) NEW_LINE DEDENT def LCM_LIST ( numbers ) : NEW_LINE INDENT return reduce ( LCM , numbers ) NEW_LINE DEDENT def LCM ( m , n ) : NEW_LINE INDENT return ( m * n // fractions . gcd ( m , n ) ) NEW_LINE DEDENT s = IS ( ) NEW_LINE if s [ 0 ] == ' A ' and s [ 2 : len ( s ) - 1 ] . count ( ' C ' ) == 1 and ' ' . join ( [ s [ i ] for i in range ( 1 , len ( s ) ) if not i == s . index ( ' C ' ) ] ) . islower ( ) : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T476
import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { String str = ( new Scanner ( System . in ) ) . next ( ) ; String ans = str . matches ( " ^ A [ a - z ] + C [ a - z ] + $ " ) ? " AC " : " WA " ; System . out . println ( ans ) ; } }
s = input ( ) NEW_LINE a = " AC " NEW_LINE if s [ 0 ] != " A " : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT cnt = 0 NEW_LINE for i in range ( 2 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT if cnt != 1 : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] != " C " and ord ( s [ i ] ) < ord ( " a " ) : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT DEDENT print ( a ) NEW_LINE
T477
import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { String str = ( new Scanner ( System . in ) ) . next ( ) ; String ans = str . matches ( " ^ A [ a - z ] + C [ a - z ] + $ " ) ? " AC " : " WA " ; System . out . println ( ans ) ; } }
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 def solve ( S : str ) : NEW_LINE INDENT if S [ 0 ] != " A " : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT if S [ 2 : - 1 ] . count ( " C " ) != 1 : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT flag = False NEW_LINE for i , c in enumerate ( S ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if ord ( " a " ) <= ord ( c ) and ord ( c ) <= ord ( " z " ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif 1 < i and i < len ( S ) - 1 and c == " C " and flag == False : NEW_LINE INDENT flag = True NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " AC " ) 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
T478
import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { String str = ( new Scanner ( System . in ) ) . next ( ) ; String ans = str . matches ( " ^ A [ a - z ] + C [ a - z ] + $ " ) ? " AC " : " WA " ; System . out . println ( ans ) ; } }
S = [ i for i in input ( ) ] NEW_LINE count = 0 NEW_LINE if S . pop ( 0 ) == ' A ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if S [ 1 : - 1 ] . count ( ' C ' ) == 1 : NEW_LINE INDENT count += 1 NEW_LINE S . remove ( ' C ' ) NEW_LINE if ' ' . join ( S ) . islower ( ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( ' AC ' if count == 3 else ' WA ' ) NEW_LINE
T479
import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { String str = ( new Scanner ( System . in ) ) . next ( ) ; String ans = str . matches ( " ^ A [ a - z ] + C [ a - z ] + $ " ) ? " AC " : " WA " ; System . out . println ( ans ) ; } }
S = input ( ) NEW_LINE if S [ 0 ] == ' A ' : NEW_LINE INDENT f1 = True NEW_LINE DEDENT else : NEW_LINE INDENT f1 = False NEW_LINE DEDENT C_cnt = 0 NEW_LINE for s in S [ 2 : - 1 ] : NEW_LINE INDENT if s == ' C ' : NEW_LINE INDENT C_cnt += 1 NEW_LINE DEDENT DEDENT if C_cnt == 1 : NEW_LINE INDENT f2 = True NEW_LINE DEDENT else : NEW_LINE INDENT f2 = False NEW_LINE DEDENT f3 = True NEW_LINE for s in S : NEW_LINE INDENT if s == ' A ' or s == ' C ' : NEW_LINE INDENT continue NEW_LINE DEDENT if s != s . lower ( ) : NEW_LINE INDENT f3 = False NEW_LINE break NEW_LINE DEDENT DEDENT if f1 and f2 and f3 : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T480
import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int L = str . length ( ) ; int cnt = 0 ; boolean check = true ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == 0 ) { if ( str . charAt ( i ) != ' A ' ) { check = false ; } } else if ( 2 <= i && i <= L - 2 ) { if ( str . charAt ( i ) == ' C ' ) { cnt ++ ; } else if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) { check = false ; } } else { if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) check = false ; } } if ( cnt != 1 ) { check = false ; } if ( check ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
from collections import Counter NEW_LINE from functools import reduce NEW_LINE import fractions NEW_LINE import math NEW_LINE import statistics NEW_LINE import sys NEW_LINE import time NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) 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 MI ( ) : return map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def IS ( ) : return input ( ) NEW_LINE def P ( x ) : return print ( x ) NEW_LINE def C ( x ) : return Counter ( x ) NEW_LINE def GCD_LIST ( numbers ) : NEW_LINE INDENT return reduce ( fractions . gcd , numbers ) NEW_LINE DEDENT def LCM_LIST ( numbers ) : NEW_LINE INDENT return reduce ( LCM , numbers ) NEW_LINE DEDENT def LCM ( m , n ) : NEW_LINE INDENT return ( m * n // fractions . gcd ( m , n ) ) NEW_LINE DEDENT s = IS ( ) NEW_LINE if s [ 0 ] == ' A ' and s [ 2 : len ( s ) - 1 ] . count ( ' C ' ) == 1 and ' ' . join ( [ s [ i ] for i in range ( 1 , len ( s ) ) if not i == s . index ( ' C ' ) ] ) . islower ( ) : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T481
import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int L = str . length ( ) ; int cnt = 0 ; boolean check = true ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == 0 ) { if ( str . charAt ( i ) != ' A ' ) { check = false ; } } else if ( 2 <= i && i <= L - 2 ) { if ( str . charAt ( i ) == ' C ' ) { cnt ++ ; } else if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) { check = false ; } } else { if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) check = false ; } } if ( cnt != 1 ) { check = false ; } if ( check ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
s = input ( ) NEW_LINE a = " AC " NEW_LINE if s [ 0 ] != " A " : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT cnt = 0 NEW_LINE for i in range ( 2 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == " C " : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT if cnt != 1 : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] != " C " and ord ( s [ i ] ) < ord ( " a " ) : NEW_LINE INDENT a = " WA " NEW_LINE DEDENT DEDENT print ( a ) NEW_LINE
T482
import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int L = str . length ( ) ; int cnt = 0 ; boolean check = true ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == 0 ) { if ( str . charAt ( i ) != ' A ' ) { check = false ; } } else if ( 2 <= i && i <= L - 2 ) { if ( str . charAt ( i ) == ' C ' ) { cnt ++ ; } else if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) { check = false ; } } else { if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) check = false ; } } if ( cnt != 1 ) { check = false ; } if ( check ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
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 def solve ( S : str ) : NEW_LINE INDENT if S [ 0 ] != " A " : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT if S [ 2 : - 1 ] . count ( " C " ) != 1 : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT flag = False NEW_LINE for i , c in enumerate ( S ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if ord ( " a " ) <= ord ( c ) and ord ( c ) <= ord ( " z " ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif 1 < i and i < len ( S ) - 1 and c == " C " and flag == False : NEW_LINE INDENT flag = True NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( " WA " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " AC " ) 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
T483
import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int L = str . length ( ) ; int cnt = 0 ; boolean check = true ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == 0 ) { if ( str . charAt ( i ) != ' A ' ) { check = false ; } } else if ( 2 <= i && i <= L - 2 ) { if ( str . charAt ( i ) == ' C ' ) { cnt ++ ; } else if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) { check = false ; } } else { if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) check = false ; } } if ( cnt != 1 ) { check = false ; } if ( check ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
S = [ i for i in input ( ) ] NEW_LINE count = 0 NEW_LINE if S . pop ( 0 ) == ' A ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if S [ 1 : - 1 ] . count ( ' C ' ) == 1 : NEW_LINE INDENT count += 1 NEW_LINE S . remove ( ' C ' ) NEW_LINE if ' ' . join ( S ) . islower ( ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( ' AC ' if count == 3 else ' WA ' ) NEW_LINE
T484
import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int L = str . length ( ) ; int cnt = 0 ; boolean check = true ; for ( int i = 0 ; i < L ; i ++ ) { if ( i == 0 ) { if ( str . charAt ( i ) != ' A ' ) { check = false ; } } else if ( 2 <= i && i <= L - 2 ) { if ( str . charAt ( i ) == ' C ' ) { cnt ++ ; } else if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) { check = false ; } } else { if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) check = false ; } } if ( cnt != 1 ) { check = false ; } if ( check ) { System . out . println ( " AC " ) ; } else { System . out . println ( " WA " ) ; } } }
S = input ( ) NEW_LINE if S [ 0 ] == ' A ' : NEW_LINE INDENT f1 = True NEW_LINE DEDENT else : NEW_LINE INDENT f1 = False NEW_LINE DEDENT C_cnt = 0 NEW_LINE for s in S [ 2 : - 1 ] : NEW_LINE INDENT if s == ' C ' : NEW_LINE INDENT C_cnt += 1 NEW_LINE DEDENT DEDENT if C_cnt == 1 : NEW_LINE INDENT f2 = True NEW_LINE DEDENT else : NEW_LINE INDENT f2 = False NEW_LINE DEDENT f3 = True NEW_LINE for s in S : NEW_LINE INDENT if s == ' A ' or s == ' C ' : NEW_LINE INDENT continue NEW_LINE DEDENT if s != s . lower ( ) : NEW_LINE INDENT f3 = False NEW_LINE break NEW_LINE DEDENT DEDENT if f1 and f2 and f3 : NEW_LINE INDENT print ( ' AC ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' WA ' ) NEW_LINE DEDENT
T485
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 [ ] dp = new int [ n ] ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( a [ 0 ] - a [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] + Math . abs ( a [ i ] - a [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( a [ i ] - a [ i - 2 ] ) ) ; } System . out . println ( dp [ n - 1 ] ) ; } }
n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE dp = [ 0 for i in range ( n ) ] NEW_LINE dp [ 1 ] = abs ( a [ 0 ] - a [ 1 ] ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT x = abs ( a [ i ] - a [ i - 2 ] ) + dp [ i - 2 ] NEW_LINE y = abs ( a [ i ] - a [ i - 1 ] ) + dp [ i - 1 ] NEW_LINE dp [ i ] = min ( x , y ) NEW_LINE DEDENT print ( dp [ - 1 ] ) NEW_LINE
T486
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 [ ] dp = new int [ n ] ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( a [ 0 ] - a [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] + Math . abs ( a [ i ] - a [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( a [ i ] - a [ i - 2 ] ) ) ; } System . out . println ( dp [ n - 1 ] ) ; } }
if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT scaffold_count = int ( input ( ) ) NEW_LINE scaffold_list = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE jump_costs = [ 0 ] * scaffold_count NEW_LINE jump_costs [ 0 ] = 0 NEW_LINE jump_costs [ 1 ] = abs ( scaffold_list [ 0 ] - scaffold_list [ 1 ] ) NEW_LINE for i in range ( 2 , scaffold_count ) : NEW_LINE INDENT jump_costs [ i ] = min ( jump_costs [ i - 2 ] + abs ( scaffold_list [ i - 2 ] - scaffold_list [ i ] ) , jump_costs [ i - 1 ] + abs ( scaffold_list [ i - 1 ] - scaffold_list [ i ] ) ) NEW_LINE DEDENT print ( jump_costs [ scaffold_count - 1 ] ) NEW_LINE DEDENT
T487
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 [ ] dp = new int [ n ] ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( a [ 0 ] - a [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] + Math . abs ( a [ i ] - a [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( a [ i ] - a [ i - 2 ] ) ) ; } System . out . println ( dp [ n - 1 ] ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE dp = [ 0 ] * N NEW_LINE dp [ 0 ] = 0 NEW_LINE dp [ 1 ] = abs ( a [ 1 ] - a [ 0 ] ) NEW_LINE def dpdfs ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return dp [ 0 ] NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT return dp [ 1 ] NEW_LINE DEDENT if dp [ n ] != 0 : NEW_LINE INDENT return dp [ n ] NEW_LINE DEDENT dp [ n ] = min ( dpdfs ( n - 1 ) + abs ( a [ n ] - a [ n - 1 ] ) , dpdfs ( n - 2 ) + abs ( a [ n ] - a [ n - 2 ] ) ) NEW_LINE return dp [ n ] NEW_LINE DEDENT dpdfs ( N - 1 ) NEW_LINE print ( dp [ - 1 ] ) NEW_LINE
T488
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 [ ] dp = new int [ n ] ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( a [ 0 ] - a [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] + Math . abs ( a [ i ] - a [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( a [ i ] - a [ i - 2 ] ) ) ; } System . out . println ( dp [ n - 1 ] ) ; } }
_ , t = open ( 0 ) NEW_LINE b , * a = map ( int , t . split ( ) ) NEW_LINE c = b NEW_LINE e = f = 0 NEW_LINE for g in a : e , f , b , c = min ( abs ( b - g ) + e , abs ( c - g ) + f ) , e , g , b NEW_LINE print ( e ) NEW_LINE
T489
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 [ ] dp = new int [ n ] ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( a [ 0 ] - a [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Math . min ( dp [ i - 1 ] + Math . abs ( a [ i ] - a [ i - 1 ] ) , dp [ i - 2 ] + Math . abs ( a [ i ] - a [ i - 2 ] ) ) ; } System . out . println ( dp [ n - 1 ] ) ; } }
def poll_poll_poll_poll_poll ( N : int , A : list ) -> int : NEW_LINE INDENT dp = [ float ( ' inf ' ) ] * N NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT dp [ i ] = dp [ i - 1 ] + abs ( A [ i ] - A [ i - 1 ] ) NEW_LINE if i > 1 : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , dp [ i - 2 ] + abs ( A [ i ] - A [ i - 2 ] ) ) NEW_LINE DEDENT DEDENT return dp [ N - 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE ans = poll_poll_poll_poll_poll ( N , A ) NEW_LINE print ( ans ) NEW_LINE DEDENT
T490
import java . util . * ; 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 ( ) ; } int [ ] output = new int [ n ] ; output [ 1 ] = Math . abs ( nums [ 1 ] - nums [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { output [ i ] = Math . min ( output [ i - 1 ] + Math . abs ( nums [ i ] - nums [ i - 1 ] ) , output [ i - 2 ] + Math . abs ( nums [ i ] - nums [ i - 2 ] ) ) ; } System . out . println ( output [ n - 1 ] ) ; } }
n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE dp = [ 0 for i in range ( n ) ] NEW_LINE dp [ 1 ] = abs ( a [ 0 ] - a [ 1 ] ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT x = abs ( a [ i ] - a [ i - 2 ] ) + dp [ i - 2 ] NEW_LINE y = abs ( a [ i ] - a [ i - 1 ] ) + dp [ i - 1 ] NEW_LINE dp [ i ] = min ( x , y ) NEW_LINE DEDENT print ( dp [ - 1 ] ) NEW_LINE
T491
import java . util . * ; 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 ( ) ; } int [ ] output = new int [ n ] ; output [ 1 ] = Math . abs ( nums [ 1 ] - nums [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { output [ i ] = Math . min ( output [ i - 1 ] + Math . abs ( nums [ i ] - nums [ i - 1 ] ) , output [ i - 2 ] + Math . abs ( nums [ i ] - nums [ i - 2 ] ) ) ; } System . out . println ( output [ n - 1 ] ) ; } }
if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT scaffold_count = int ( input ( ) ) NEW_LINE scaffold_list = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE jump_costs = [ 0 ] * scaffold_count NEW_LINE jump_costs [ 0 ] = 0 NEW_LINE jump_costs [ 1 ] = abs ( scaffold_list [ 0 ] - scaffold_list [ 1 ] ) NEW_LINE for i in range ( 2 , scaffold_count ) : NEW_LINE INDENT jump_costs [ i ] = min ( jump_costs [ i - 2 ] + abs ( scaffold_list [ i - 2 ] - scaffold_list [ i ] ) , jump_costs [ i - 1 ] + abs ( scaffold_list [ i - 1 ] - scaffold_list [ i ] ) ) NEW_LINE DEDENT print ( jump_costs [ scaffold_count - 1 ] ) NEW_LINE DEDENT
T492
import java . util . * ; 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 ( ) ; } int [ ] output = new int [ n ] ; output [ 1 ] = Math . abs ( nums [ 1 ] - nums [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { output [ i ] = Math . min ( output [ i - 1 ] + Math . abs ( nums [ i ] - nums [ i - 1 ] ) , output [ i - 2 ] + Math . abs ( nums [ i ] - nums [ i - 2 ] ) ) ; } System . out . println ( output [ n - 1 ] ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE dp = [ 0 ] * N NEW_LINE dp [ 0 ] = 0 NEW_LINE dp [ 1 ] = abs ( a [ 1 ] - a [ 0 ] ) NEW_LINE def dpdfs ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return dp [ 0 ] NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT return dp [ 1 ] NEW_LINE DEDENT if dp [ n ] != 0 : NEW_LINE INDENT return dp [ n ] NEW_LINE DEDENT dp [ n ] = min ( dpdfs ( n - 1 ) + abs ( a [ n ] - a [ n - 1 ] ) , dpdfs ( n - 2 ) + abs ( a [ n ] - a [ n - 2 ] ) ) NEW_LINE return dp [ n ] NEW_LINE DEDENT dpdfs ( N - 1 ) NEW_LINE print ( dp [ - 1 ] ) NEW_LINE
T493
import java . util . * ; 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 ( ) ; } int [ ] output = new int [ n ] ; output [ 1 ] = Math . abs ( nums [ 1 ] - nums [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { output [ i ] = Math . min ( output [ i - 1 ] + Math . abs ( nums [ i ] - nums [ i - 1 ] ) , output [ i - 2 ] + Math . abs ( nums [ i ] - nums [ i - 2 ] ) ) ; } System . out . println ( output [ n - 1 ] ) ; } }
_ , t = open ( 0 ) NEW_LINE b , * a = map ( int , t . split ( ) ) NEW_LINE c = b NEW_LINE e = f = 0 NEW_LINE for g in a : e , f , b , c = min ( abs ( b - g ) + e , abs ( c - g ) + f ) , e , g , b NEW_LINE print ( e ) NEW_LINE
T494
import java . util . * ; 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 ( ) ; } int [ ] output = new int [ n ] ; output [ 1 ] = Math . abs ( nums [ 1 ] - nums [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { output [ i ] = Math . min ( output [ i - 1 ] + Math . abs ( nums [ i ] - nums [ i - 1 ] ) , output [ i - 2 ] + Math . abs ( nums [ i ] - nums [ i - 2 ] ) ) ; } System . out . println ( output [ n - 1 ] ) ; } }
def poll_poll_poll_poll_poll ( N : int , A : list ) -> int : NEW_LINE INDENT dp = [ float ( ' inf ' ) ] * N NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT dp [ i ] = dp [ i - 1 ] + abs ( A [ i ] - A [ i - 1 ] ) NEW_LINE if i > 1 : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , dp [ i - 2 ] + abs ( A [ i ] - A [ i - 2 ] ) ) NEW_LINE DEDENT DEDENT return dp [ N - 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE ans = poll_poll_poll_poll_poll ( N , A ) NEW_LINE print ( ans ) NEW_LINE DEDENT
T495
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 [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextInt ( ) ; solver ( N , a ) ; } public static void solver ( int N , int [ ] a ) { int [ ] ans = new int [ N ] ; for ( int n = N - 1 ; n >= 0 ; n -- ) { if ( n == N - 1 ) { continue ; } else if ( n == N - 2 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 1 ] ) ; } else if ( n == N - 3 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 2 ] ) ; } else { ans [ n ] = Math . min ( Math . abs ( ans [ n + 1 ] + Math . abs ( a [ n ] - a [ n + 1 ] ) ) , Math . abs ( ans [ n + 2 ] + Math . abs ( a [ n ] - a [ n + 2 ] ) ) ) ; } } out . println ( ans [ 0 ] ) ; } }
n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE dp = [ 0 for i in range ( n ) ] NEW_LINE dp [ 1 ] = abs ( a [ 0 ] - a [ 1 ] ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT x = abs ( a [ i ] - a [ i - 2 ] ) + dp [ i - 2 ] NEW_LINE y = abs ( a [ i ] - a [ i - 1 ] ) + dp [ i - 1 ] NEW_LINE dp [ i ] = min ( x , y ) NEW_LINE DEDENT print ( dp [ - 1 ] ) NEW_LINE
T496
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 [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextInt ( ) ; solver ( N , a ) ; } public static void solver ( int N , int [ ] a ) { int [ ] ans = new int [ N ] ; for ( int n = N - 1 ; n >= 0 ; n -- ) { if ( n == N - 1 ) { continue ; } else if ( n == N - 2 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 1 ] ) ; } else if ( n == N - 3 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 2 ] ) ; } else { ans [ n ] = Math . min ( Math . abs ( ans [ n + 1 ] + Math . abs ( a [ n ] - a [ n + 1 ] ) ) , Math . abs ( ans [ n + 2 ] + Math . abs ( a [ n ] - a [ n + 2 ] ) ) ) ; } } out . println ( ans [ 0 ] ) ; } }
if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT scaffold_count = int ( input ( ) ) NEW_LINE scaffold_list = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE jump_costs = [ 0 ] * scaffold_count NEW_LINE jump_costs [ 0 ] = 0 NEW_LINE jump_costs [ 1 ] = abs ( scaffold_list [ 0 ] - scaffold_list [ 1 ] ) NEW_LINE for i in range ( 2 , scaffold_count ) : NEW_LINE INDENT jump_costs [ i ] = min ( jump_costs [ i - 2 ] + abs ( scaffold_list [ i - 2 ] - scaffold_list [ i ] ) , jump_costs [ i - 1 ] + abs ( scaffold_list [ i - 1 ] - scaffold_list [ i ] ) ) NEW_LINE DEDENT print ( jump_costs [ scaffold_count - 1 ] ) NEW_LINE DEDENT
T497
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 [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextInt ( ) ; solver ( N , a ) ; } public static void solver ( int N , int [ ] a ) { int [ ] ans = new int [ N ] ; for ( int n = N - 1 ; n >= 0 ; n -- ) { if ( n == N - 1 ) { continue ; } else if ( n == N - 2 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 1 ] ) ; } else if ( n == N - 3 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 2 ] ) ; } else { ans [ n ] = Math . min ( Math . abs ( ans [ n + 1 ] + Math . abs ( a [ n ] - a [ n + 1 ] ) ) , Math . abs ( ans [ n + 2 ] + Math . abs ( a [ n ] - a [ n + 2 ] ) ) ) ; } } out . println ( ans [ 0 ] ) ; } }
import sys NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE N = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE dp = [ 0 ] * N NEW_LINE dp [ 0 ] = 0 NEW_LINE dp [ 1 ] = abs ( a [ 1 ] - a [ 0 ] ) NEW_LINE def dpdfs ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return dp [ 0 ] NEW_LINE DEDENT elif n == 1 : NEW_LINE INDENT return dp [ 1 ] NEW_LINE DEDENT if dp [ n ] != 0 : NEW_LINE INDENT return dp [ n ] NEW_LINE DEDENT dp [ n ] = min ( dpdfs ( n - 1 ) + abs ( a [ n ] - a [ n - 1 ] ) , dpdfs ( n - 2 ) + abs ( a [ n ] - a [ n - 2 ] ) ) NEW_LINE return dp [ n ] NEW_LINE DEDENT dpdfs ( N - 1 ) NEW_LINE print ( dp [ - 1 ] ) NEW_LINE
T498
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 [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextInt ( ) ; solver ( N , a ) ; } public static void solver ( int N , int [ ] a ) { int [ ] ans = new int [ N ] ; for ( int n = N - 1 ; n >= 0 ; n -- ) { if ( n == N - 1 ) { continue ; } else if ( n == N - 2 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 1 ] ) ; } else if ( n == N - 3 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 2 ] ) ; } else { ans [ n ] = Math . min ( Math . abs ( ans [ n + 1 ] + Math . abs ( a [ n ] - a [ n + 1 ] ) ) , Math . abs ( ans [ n + 2 ] + Math . abs ( a [ n ] - a [ n + 2 ] ) ) ) ; } } out . println ( ans [ 0 ] ) ; } }
_ , t = open ( 0 ) NEW_LINE b , * a = map ( int , t . split ( ) ) NEW_LINE c = b NEW_LINE e = f = 0 NEW_LINE for g in a : e , f , b , c = min ( abs ( b - g ) + e , abs ( c - g ) + f ) , e , g , b NEW_LINE print ( e ) NEW_LINE
T499
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 [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextInt ( ) ; solver ( N , a ) ; } public static void solver ( int N , int [ ] a ) { int [ ] ans = new int [ N ] ; for ( int n = N - 1 ; n >= 0 ; n -- ) { if ( n == N - 1 ) { continue ; } else if ( n == N - 2 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 1 ] ) ; } else if ( n == N - 3 ) { ans [ n ] = Math . abs ( a [ n ] - a [ n + 2 ] ) ; } else { ans [ n ] = Math . min ( Math . abs ( ans [ n + 1 ] + Math . abs ( a [ n ] - a [ n + 1 ] ) ) , Math . abs ( ans [ n + 2 ] + Math . abs ( a [ n ] - a [ n + 2 ] ) ) ) ; } } out . println ( ans [ 0 ] ) ; } }
def poll_poll_poll_poll_poll ( N : int , A : list ) -> int : NEW_LINE INDENT dp = [ float ( ' inf ' ) ] * N NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT dp [ i ] = dp [ i - 1 ] + abs ( A [ i ] - A [ i - 1 ] ) NEW_LINE if i > 1 : NEW_LINE INDENT dp [ i ] = min ( dp [ i ] , dp [ i - 2 ] + abs ( A [ i ] - A [ i - 2 ] ) ) NEW_LINE DEDENT DEDENT return dp [ N - 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE ans = poll_poll_poll_poll_poll ( N , A ) NEW_LINE print ( ans ) NEW_LINE DEDENT