wrong_submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
131k
1.05M
wrong_status
stringclasses
2 values
wrong_cpu_time
float64
10
40k
wrong_memory
float64
2.94k
3.37M
wrong_code_size
int64
1
15.5k
problem_description
stringlengths
1
4.75k
wrong_code
stringlengths
1
6.92k
acc_submission_id
stringlengths
10
10
acc_status
stringclasses
1 value
acc_cpu_time
float64
10
27.8k
acc_memory
float64
2.94k
960k
acc_code_size
int64
19
14.9k
acc_code
stringlengths
19
14.9k
s074068886
p02261
u742013327
1,000
131,072
Wrong Answer
50
7,784
2,349
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp #?????????????????? def bubble_sort(origin_list): list_length = len(origin_list) target_list = [i for i in origin_list] flag = True change_count = 0 top_index = 1 while flag: flag = False for i in range(top_index, list_length)[::-1]: if target_list[i][1] < target_list[i - 1][1]: tmp = target_list[i] target_list[i] = target_list[i - 1] target_list[i - 1] = tmp change_count += 1 flag = True top_index += 1 return target_list def selection_sort(origin_list): list_length = len(origin_list) target_list = [i for i in origin_list] change_count = 0 for i in range(list_length): min_index = i for j in range(i, list_length): if target_list[j][1] < target_list[min_index][1]: min_index = j else: if not i == min_index: tmp = target_list[i] target_list[i] = target_list[min_index] target_list[min_index] = tmp change_count += 1 return target_list def check_stable(origin_list, target_list): for i, origin_v in enumerate(origin_list): for origin_v2 in origin_list[i+1:]: if origin_v[1] == origin_v2[1]: for j, target_v in enumerate(target_list): for target_v2 in target_list[j+1:]: if origin_v == target_v2 and origin_v2 == target_v: return False return True def stable_sort(target_list): print(*bubble_sort(target_list)) print(check_stable(target_list, bubble_sort(target_list))) print(*selection_sort(target_list)) print(check_stable(target_list, selection_sort(target_list))) def main(): n_list = int(input()) target_list = [a for a in input().split()] stable_sort(target_list) if __name__ == "__main__": main()
s087191675
Accepted
20
7,840
2,360
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C&lang=jp #?????????????????? def bubble_sort(origin_list): list_length = len(origin_list) target_list = [i for i in origin_list] flag = True change_count = 0 top_index = 1 while flag: flag = False for i in range(top_index, list_length)[::-1]: if target_list[i][1] < target_list[i - 1][1]: tmp = target_list[i] target_list[i] = target_list[i - 1] target_list[i - 1] = tmp change_count += 1 flag = True top_index += 1 return target_list def selection_sort(origin_list): list_length = len(origin_list) target_list = [i for i in origin_list] change_count = 0 for i in range(list_length): min_index = i for j in range(i, list_length): if target_list[j][1] < target_list[min_index][1]: min_index = j else: if not i == min_index: tmp = target_list[i] target_list[i] = target_list[min_index] target_list[min_index] = tmp change_count += 1 return target_list def check_stable(origin_list, target_list): for i, origin_v in enumerate(origin_list): for origin_v2 in origin_list[i+1:]: if origin_v[1] == origin_v2[1]: for j, target_v in enumerate(target_list): for target_v2 in target_list[j+1:]: if origin_v == target_v2 and origin_v2 == target_v: return "Not stable" return "Stable" def stable_sort(target_list): print(*bubble_sort(target_list)) print(check_stable(target_list, bubble_sort(target_list))) print(*selection_sort(target_list)) print(check_stable(target_list, selection_sort(target_list))) def main(): n_list = int(input()) target_list = [a for a in input().split()] stable_sort(target_list) if __name__ == "__main__": main()
s285108897
p03860
u314219654
2,000
262,144
Wrong Answer
17
2,940
29
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s=input() print("A"+s[1]+"C")
s862916486
Accepted
17
2,940
31
s = input() print("A"+s[8]+"C")
s154001671
p02831
u121161758
2,000
1,048,576
Wrong Answer
43
3,064
1,086
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
import math A, B = map(int, input().split()) A_orgn = A B_orgn = B dict_a = {} dict_b = {} for i in range(2,int(math.sqrt(A))+1): if A % i == 0: while(1): A //= i if i not in dict_a: dict_a[i] = 1 else: dict_a[i] += 1 if A % i != 0: break if A != 1: dict_a[A] = 1 for i in range(2,int(math.sqrt(B))+1): if B % i == 0: while(1): B //= i if i not in dict_b: dict_b[i] = 1 else: dict_b[i] += 1 if A % i != 0: break if B != 1: dict_b[B] = 1 #print(dict_a) #print(dict_b) sum = 1 for i in range(max(A_orgn, B_orgn)): #print(i) if (i not in dict_a) and ( i in dict_b): #print("====") sum *= i elif (i in dict_a) and ( i not in dict_b): sum *= i elif (i in dict_a) and ( i in dict_b): sum *= max(dict_a[i], dict_b[i]) * i print(sum)
s254981755
Accepted
42
3,064
1,293
import math A, B = map(int, input().split()) A_orgn = A B_orgn = B dict_a = {} dict_b = {} if A == 1: dict_a[1] = 1 for i in range(2,int(math.sqrt(A))+1): if A % i == 0: while(1): A //= i if i not in dict_a: dict_a[i] = 1 else: dict_a[i] += 1 if A % i != 0: break if A != 1: dict_a[A] = 1 if B == 1: dict_b[1] = 1 for i in range(2,int(math.sqrt(B))+1): if B % i == 0: while(1): B //= i if i not in dict_b: dict_b[i] = 1 else: dict_b[i] += 1 if B % i != 0: break if B != 1: dict_b[B] = 1 #print(dict_a) #print(dict_b) sum = 1 for i in range(max(A_orgn, B_orgn)+1): #print(i) if (i not in dict_a) and ( i in dict_b): sum *= i ** dict_b[i] #print("====",i, "====",sum) elif (i in dict_a) and ( i not in dict_b): sum *= i ** dict_a[i] #print("||||",i, "||||", sum) elif (i in dict_a) and ( i in dict_b): sum *= i ** max(dict_a[i], dict_b[i]) #print("????",i,"????", sum) print(sum)
s465214444
p03814
u496744988
2,000
262,144
Wrong Answer
682
8,696
256
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
s=input() ans=0 for i in range(len(s)): if s[i] == 'A': for j in range(len(s)-1,0,-1): print(i,j) if s[j] == 'Z': if ans < abs(i-j): ans = abs(i-j) break print(ans+1)
s145271152
Accepted
17
3,500
44
s=input() print(s.rfind('Z')-s.find('A')+1)
s089495248
p04044
u580404776
2,000
262,144
Wrong Answer
17
3,060
156
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1โ‰ฆiโ‰ฆmin(n,m)), such that s_j = t_j for all indices j(1โ‰ฆj<i), and s_i<t_i. * s_i = t_i for all integers i(1โ‰ฆiโ‰ฆmin(n,m)), and n<m.
N,L=map(int,input().split()) S=[] ans="" for _ in range(N): S.append(input()) SS=sorted(S) for _ in range(N): ans+=S[0] S.pop(0) print(ans)
s883244195
Accepted
17
3,060
158
N,L=map(int,input().split()) S=[] ans="" for _ in range(N): S.append(input()) SS=sorted(S) for _ in range(N): ans+=SS[0] SS.pop(0) print(ans)
s669684501
p03455
u163421511
2,000
262,144
Wrong Answer
25
8,812
109
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
A, B = map(int, input().split()) num = int(A+B)*0.05 result = "Yes" if num.is_integer else "No" print(result)
s462019753
Accepted
27
9,056
133
# -*- coding: utf-8 -*- a, b = map(int, input().split()) if a * b % 2 == 0: x = "Even" else: x = "Odd" print(x)
s607427855
p03672
u766407523
2,000
262,144
Time Limit Exceeded
2,104
7,284
151
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
s = input() if len(s)%2==1: s += '0' s = s[:-2] while True: if s[:len(s)//2] == s[len(s)//2:]: print(len(s[:len(s)//2])) s = s[:-2]
s143641818
Accepted
17
2,940
154
s = input() if len(s)%2==1: s += '0' s = s[:-2] while True: if s[:len(s)//2] == s[len(s)//2:]: print(len(s)) break s = s[:-2]
s107259142
p02422
u671553883
1,000
131,072
Wrong Answer
20
7,584
332
Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th character to the b-th character of $str$ with p Note that the indices of $str$ start with 0.
s = input() q = int(input()) for qi in range(q): command = input().split() a = int(command[1]) b = int(command[2]) if command[0] == 'print': print(s[a:b + 1]) elif command[0] == 'reverse': s = s[:a] + s[a:b + 1][::-1] + s[b + 1:] else: p = command[3] s = s[a:] + p + s[:b]
s390009217
Accepted
20
7,692
336
s = input() q = int(input()) for qi in range(q): command = input().split() a = int(command[1]) b = int(command[2]) if command[0] == 'print': print(s[a:b + 1]) elif command[0] == 'reverse': s = s[:a] + s[a:b + 1][::-1] + s[b + 1:] else: p = command[3] s = s[:a] + p + s[b + 1:]
s541763331
p03861
u693933222
2,000
262,144
Wrong Answer
17
2,940
105
You are given nonnegative integers a and b (a โ‰ค b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x = map(int, input().split()) ax = min(0,(a-1)//x) bx = b//x #print(ax) #print(bx)# print(bx-ax+1)
s504097511
Accepted
18
2,940
55
a,b,x = map(int, input().split()) print(b//x-(a-1)//x)
s991116336
p03486
u666964944
2,000
262,144
Wrong Answer
28
8,996
115
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() t = input() sa = ''.join(sorted(s)) ta = ''.join(sorted(t, reverse=True)) print('Yes' if s<t else 'No')
s019822616
Accepted
29
8,980
117
s = input() t = input() sa = ''.join(sorted(s)) ta = ''.join(sorted(t, reverse=True)) print('Yes' if sa<ta else 'No')
s563349365
p02694
u612635771
2,000
1,048,576
Wrong Answer
26
9,068
60
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
n = int(input()) i = 100 while i>=n: i = i*0.01 i = i//1
s360901073
Accepted
29
9,092
87
n = int(input()) i = 100 total=0 while i<n: i = i*101//100 total +=1 print(total)
s383874682
p03435
u580327099
2,000
262,144
Wrong Answer
18
3,064
780
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys input = sys.stdin.readline def main(): G = [[0 for _ in range(3)] for _ in range(3)] for i in range(3): G[i] = [int(e) for e in input().split()] for a0 in range(0, 100+1): b0 = G[0][0] - a0 b1 = G[0][1] - a0 b2 = G[0][2] - a0 a1 = G[1][0] - b0 a2 = G[2][0] - b1 if a0 + b0 == G[0][0] and \ a0 + b1 == G[0][1] and \ a0 + b2 == G[0][2] and \ a1 + b0 == G[1][0] and \ a1 + b1 == G[1][1] and \ a1 + b2 == G[1][2] and \ a2 + b0 == G[2][0] and \ a2 + b1 == G[2][1] and \ a2 + b2 == G[2][2]: print("Yes") return print("No") main()
s954683879
Accepted
17
3,064
780
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys input = sys.stdin.readline def main(): G = [[0 for _ in range(3)] for _ in range(3)] for i in range(3): G[i] = [int(e) for e in input().split()] for a0 in range(0, 100+1): b0 = G[0][0] - a0 b1 = G[0][1] - a0 b2 = G[0][2] - a0 a1 = G[1][0] - b0 a2 = G[2][0] - b0 if a0 + b0 == G[0][0] and \ a0 + b1 == G[0][1] and \ a0 + b2 == G[0][2] and \ a1 + b0 == G[1][0] and \ a1 + b1 == G[1][1] and \ a1 + b2 == G[1][2] and \ a2 + b0 == G[2][0] and \ a2 + b1 == G[2][1] and \ a2 + b2 == G[2][2]: print("Yes") return print("No") main()
s326688828
p02928
u919463386
2,000
1,048,576
Wrong Answer
399
3,188
557
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
# -*- coding: utf-8 -*- def main(): N, K = map(int,input().split()) A = list(map(int,input().split())) inner = 0 outer = 0 for i in range(0,N): for j in range(0,i): if A[i] > A[j]: outer += 1 for j in range(i+1,N): if A[i] > A[j]: inner += 1 outer += 1 count = (inner * K + outer * int(K * (K-1) / 2)) count = count % (1000000000 +7) print(A) print(inner) print(outer) print(count) if __name__ == "__main__": main()
s960803143
Accepted
399
3,188
499
# -*- coding: utf-8 -*- def main(): N, K = map(int,input().split()) A = list(map(int,input().split())) inner = 0 outer = 0 for i in range(0,N): for j in range(0,i): if A[i] > A[j]: outer += 1 for j in range(i+1,N): if A[i] > A[j]: inner += 1 outer += 1 count = inner * K + outer * K * (K-1) // 2 count = count % (10**9 +7) print(count) if __name__ == "__main__": main()
s669287192
p02407
u002280517
1,000
131,072
Wrong Answer
20
5,588
121
Write a program which reads a sequence and prints it in the reverse order.
n = int(input()) a = list(map(int,input().split())) a.sort(reverse=True) for i in a: print("{0} ".format(i),end="")
s643634412
Accepted
20
5,616
187
n = int(input()) a = list(map(int,input().split())) j = 0 for i in a[::-1]: j+=1 print("{0}".format(i),end="") if j != n : print(" ",end="") else: print()
s645211732
p03623
u220345792
2,000
262,144
Wrong Answer
17
2,940
92
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = map(int, input().split()) if abs(a-x) > abs(b-x): print("A") else: print("B")
s168889432
Accepted
17
2,940
93
x, a, b = map(int, input().split()) if abs(a-x) < abs(b-x): print("A") else: print("B")
s253300758
p03110
u555947166
2,000
1,048,576
Wrong Answer
18
2,940
264
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
N = int(input()) money = [] for i in range(N): money.append(input().split()) B2Y = 38000.0 otoshidama = 0 for item in money: if item[1] == 'JPY': otoshidama += float(item[0]) else: otoshidama += float(item[0])*B2Y print(otoshidama)
s103871819
Accepted
18
3,060
265
N = int(input()) money = [] for i in range(N): money.append(input().split()) B2Y = 380000.0 otoshidama = 0 for item in money: if item[1] == 'JPY': otoshidama += float(item[0]) else: otoshidama += float(item[0])*B2Y print(otoshidama)
s078280313
p03759
u957198490
2,000
262,144
Wrong Answer
17
2,940
87
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int,input().split()) if b-a == c-a: print('YES') else: print('NO')
s661962706
Accepted
17
3,064
87
a,b,c = map(int,input().split()) if b-a == c-b: print('YES') else: print('NO')
s542002552
p03436
u113375133
2,000
262,144
Wrong Answer
62
6,328
1,591
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
from collections import deque import sys sys.setrecursionlimit(4000) def validCordinate(x, y, dist, Grid): if x < 0 or x >= len(Grid[0]): return False if y < 0 or y >= len(Grid): return False if dist[y][x] != -1: return False if Grid[y][x] != '.': return False return True def bfs(x, y, q, dist, Grid): if validCordinate(x + 1, y, dist, Grid): q.append((x+1, y)) dist[y][x+1] = dist[y][x] + 1 if validCordinate(x, y + 1, dist, Grid): q.append((x, y + 1)) dist[y+1][x] = dist[y][x] + 1 if validCordinate(x - 1, y, dist, Grid): q.append((x-1, y)) dist[y][x-1] = dist[y][x] + 1 if validCordinate(x, y - 1, dist, Grid): q.append((x, y-1)) dist[y-1][x] = dist[y][x] + 1 print(q) # finish if x == len(Grid[0]) - 1 and y == len(Grid) - 1: return dist if len(q) == 0: return False cx, cy = q.popleft() return bfs(cx, cy, q, dist, Grid) def main(): # input H, W = map(int, input().split()) Grid = [] dist = [[-1 for j in range(W)] for i in range(H)] q = deque() for i in range(H): Grid.append(input()) print(Grid) dist[0][0] = 0 res = bfs(0, 0, q, dist, Grid) if res: whiteNumber = 0 for i in range(H): for j in range(W): if Grid[i][j] == ".": whiteNumber += 1 print(whiteNumber - res[-1][-1] - 1) else: print(-1) if __name__ == "__main__": main()
s586521733
Accepted
29
5,484
1,562
from collections import deque import sys sys.setrecursionlimit(4000) def validCordinate(x, y, dist, Grid): if x < 0 or x >= len(Grid[0]): return False if y < 0 or y >= len(Grid): return False if dist[y][x] != -1: return False if Grid[y][x] != '.': return False return True def bfs(x, y, q, dist, Grid): if validCordinate(x + 1, y, dist, Grid): q.append((x+1, y)) dist[y][x+1] = dist[y][x] + 1 if validCordinate(x, y + 1, dist, Grid): q.append((x, y + 1)) dist[y+1][x] = dist[y][x] + 1 if validCordinate(x - 1, y, dist, Grid): q.append((x-1, y)) dist[y][x-1] = dist[y][x] + 1 if validCordinate(x, y - 1, dist, Grid): q.append((x, y-1)) dist[y-1][x] = dist[y][x] + 1 # finish if x == len(Grid[0]) - 1 and y == len(Grid) - 1: return dist if len(q) == 0: return False cx, cy = q.popleft() return bfs(cx, cy, q, dist, Grid) def main(): # input H, W = map(int, input().split()) Grid = [] dist = [[-1 for j in range(W)] for i in range(H)] q = deque() for i in range(H): Grid.append(input()) dist[0][0] = 0 res = bfs(0, 0, q, dist, Grid) if res: whiteNumber = 0 for i in range(H): for j in range(W): if Grid[i][j] == ".": whiteNumber += 1 print(whiteNumber - res[-1][-1] - 1) else: print(-1) if __name__ == "__main__": main()
s896841714
p03711
u341267151
2,000
262,144
Wrong Answer
17
2,940
368
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 โ‰ค x < y โ‰ค 12), determine whether they belong to the same group.
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y)
s388153238
Accepted
18
3,064
1,375
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) s=[[1,3,5,7,8,10,12],[4,6,9,11],[2]] uf=UnionFind(13) for i in range(len(s)): for j in range(len(s[i])): uf.union(s[i][0],s[i][j]) x,y=map(int,input().split()) if uf.same(x,y): print("Yes") else: print("No")
s601772703
p03229
u539517139
2,000
1,048,576
Wrong Answer
212
7,512
380
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
n=int(input()) a=[int(input()) for _ in range(n)] a.sort() if n==2: x=a[1]-a[0] elif n%2==0: x=(sum(a[n//2+1:])-sum(a[:n//2-1]))*2 x-=a[n//2-1] x+=a[n//2] elif n==3: x=a[2]*2-a[0]-a[1] y=a[2]+a[1]-a[0]*2 x=max(x,y) else: x=(sum(a[n//2+2:])-sum(a[:n//2]))*2 x+=a[n//2]+a[n//2+1] y=(sum(a[n//2+1:])-sum(a[:n//2-1]))*2 y-=a[n//2]-a[n//2-1] x=max(x,y) print(x)
s860643660
Accepted
214
7,512
380
n=int(input()) a=[int(input()) for _ in range(n)] a.sort() if n==2: x=a[1]-a[0] elif n%2==0: x=(sum(a[n//2+1:])-sum(a[:n//2-1]))*2 x-=a[n//2-1] x+=a[n//2] elif n==3: x=a[2]*2-a[0]-a[1] y=a[2]+a[1]-a[0]*2 x=max(x,y) else: x=(sum(a[n//2+2:])-sum(a[:n//2]))*2 x+=a[n//2]+a[n//2+1] y=(sum(a[n//2+1:])-sum(a[:n//2-1]))*2 y-=a[n//2]+a[n//2-1] x=max(x,y) print(x)
s883405468
p03836
u378328623
2,000
262,144
Wrong Answer
18
3,316
200
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) x = tx - sx y = ty - sy print("".join(["U"]*x + ["R"]*y +["D"]*x + ["L"]*(y+1) + ["U"]*(x+1) + ["R"]*(y+1) + ["D", "R"] + ["D"]*(y+1) + ["L"]*(x+1) + ["U"]))
s993702789
Accepted
18
3,316
200
sx, sy, tx, ty = map(int, input().split()) x = tx - sx y = ty - sy print("".join(["U"]*y + ["R"]*x +["D"]*y + ["L"]*(x+1) + ["U"]*(y+1) + ["R"]*(x+1) + ["D", "R"] + ["D"]*(y+1) + ["L"]*(x+1) + ["U"]))
s461868655
p03456
u448655578
2,000
262,144
Wrong Answer
18
3,188
175
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math a, b = map(str, input().split()) c = a+b print(round(math.sqrt(int(c)))) print(int(c)) if round(math.sqrt(int(c)))**2 == int(c): print('Yes') else: print('No')
s200728413
Accepted
17
3,060
109
a, b = map(str, input().split()) c = a+b if int(int(c)**0.5)**2 == int(c): print('Yes') else: print('No')
s448223199
p02396
u092736322
1,000
131,072
Wrong Answer
170
5,600
120
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
for i in range(10000): k=int(input()) if k==0: break else: print("Case "+str(i)+":"+str(k))
s010681358
Accepted
140
5,600
123
for i in range(10000): k=int(input()) if k==0: break else: print("Case "+str(i+1)+": "+str(k))
s137990404
p02678
u736227279
2,000
1,048,576
Wrong Answer
1,518
38,356
660
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
n,edge = map(int,input().split()) l = [0]*n stack = [1] dic = {} for i in range (edge) : x = [int(x) for x in input().split()] if x[0] not in dic : dic[x[0]] = [] if x[1] not in dic : dic[x[1]] = [] dic[x[0]].append(x[1]) dic[x[1]].append(x[0]) x = 1 while len(stack) != 0 : check = stack[0] stack.pop(0) for i in range (len(dic[check])) : if l[dic[check][i]-1] == 0 : x += 1 stack.append(dic[check][i]) l[dic[check][i]-1] = check if l.count(0) != 0 : print("NO") else : print("YES") for i in range (1,n) : print(l[i])
s115965177
Accepted
1,504
38,364
660
n,edge = map(int,input().split()) l = [0]*n stack = [1] dic = {} for i in range (edge) : x = [int(x) for x in input().split()] if x[0] not in dic : dic[x[0]] = [] if x[1] not in dic : dic[x[1]] = [] dic[x[0]].append(x[1]) dic[x[1]].append(x[0]) x = 1 while len(stack) != 0 : check = stack[0] stack.pop(0) for i in range (len(dic[check])) : if l[dic[check][i]-1] == 0 : x += 1 stack.append(dic[check][i]) l[dic[check][i]-1] = check if l.count(0) != 0 : print("No") else : print("Yes") for i in range (1,n) : print(l[i])
s706346655
p03826
u281303342
2,000
262,144
Wrong Answer
17
2,940
383
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- A,B,C,D = map(int,input().split()) print(A*B,C*D)
s716395777
Accepted
17
2,940
389
# Python3 (3.4.3) import sys input = sys.stdin.readline # ------------------------------------------------------------- # function # ------------------------------------------------------------- # ------------------------------------------------------------- # main # ------------------------------------------------------------- A,B,C,D = map(int,input().split()) print(max(A*B,C*D))
s416345983
p02975
u248670337
2,000
1,048,576
Wrong Answer
53
16,960
59
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
input();x=0 for i in map(int,input().split()):x^=i print(x)
s459375627
Accepted
59
20,828
287
from collections import* n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C) if l==3: x=0 for c in C:x^=c[0] f=(len(set(c[1]for c in C))>1)+n%3+x>0 elif l==2:f=(abs(sum(c[1]*(-1)**i for i,c in enumerate(C)))!=n//3)+n%3>0 else:f=(l!=1)+A[0]>0 print('YNeos'[f::2])
s451269315
p03797
u794753968
2,000
262,144
Wrong Answer
17
2,940
49
Snuke loves puzzles. Today, he is working on a puzzle using `S`\- and `c`-shaped pieces. In this puzzle, you can combine two `c`-shaped pieces into one `S`-shaped piece, as shown in the figure below: Snuke decided to create as many `Scc` groups as possible by putting together one `S`-shaped piece and two `c`-shaped pieces. Find the maximum number of `Scc` groups that can be created when Snuke has N `S`-shaped pieces and M `c`-shaped pieces.
N,M = map(int, input().split()) print(N*2+M // 4)
s839868431
Accepted
17
2,940
107
N,M = map(int, input().split()) ans = 0 sp = min(N, M // 2) ans += sp M -= sp*2 ans += M // 4 print(ans)
s865709815
p03997
u068584789
2,000
262,144
Wrong Answer
17
2,940
74
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h / 2)
s609416900
Accepted
17
2,940
79
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h / 2))
s661619027
p03351
u154191677
2,000
1,048,576
Wrong Answer
18
2,940
121
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) print('YES' if (abs(a - b) <= d and abs(b - c) <= d) or abs(a - c) <= d else 'NO')
s330492704
Accepted
18
3,060
150
a, b, c, d = map(int, input().split()) if abs(a-b) <= d and abs(b-c) <= d: print('Yes') elif abs(a-c) <= d: print('Yes') else: print('No')
s274344260
p02402
u896065593
1,000
131,072
Wrong Answer
30
7,556
233
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
n = int(input()) a = input().split() min = int(a[0]) max = int(a[0]) sum = 0 for i in a: if min > int(i): min = int(i) if max < int(i): max = int(i) sum += int(i) print("{0} {1} {2}".format(max, min, sum))
s488615958
Accepted
40
8,340
233
n = int(input()) a = input().split() min = int(a[0]) max = int(a[0]) sum = 0 for i in a: if min > int(i): min = int(i) if max < int(i): max = int(i) sum += int(i) print("{0} {1} {2}".format(min, max, sum))
s360925693
p02408
u279955105
1,000
131,072
Wrong Answer
20
7,552
297
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
cards = { "S" : [0 for i in range(13)], "H" : [0 for i in range(13)], "D" : [0 for i in range(13)], "C" : [0 for i in range(13)] } n = int(input()) for i in range(n): a,b = input().split() cards[a][int(b)-1] = 1 for a in ("S","H","D","C"): for b in range(13): cards[a][b] = 0 print(a,b+1)
s203530319
Accepted
20
5,596
527
n = int(input()) a = list() for i in range(n): x,y = input().split() y = int(y) if x == 'S': a.append(y+0) elif x == 'H': a.append(y+13) elif x == 'C': a.append(y+26) else: a.append(y+39) for i in range(1,53): if not (i in a): if i <= 13: print('S {}'.format(i)) elif 13 < i <= 26: print('H {}'.format(i-13)) elif 26 < i <=39: print('C {}'.format(i-26)) else: print('D {}'.format(i-39))
s072663196
p03352
u987164499
2,000
1,048,576
Wrong Answer
23
2,940
135
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x = int(input()) ma = 0 for i in range(1,100): for j in range(1,100): if i**j <= x: ma = max(ma,i**j) print(ma)
s606963513
Accepted
22
2,940
135
x = int(input()) ma = 0 for i in range(1,100): for j in range(2,100): if i**j <= x: ma = max(ma,i**j) print(ma)
s995617763
p02259
u279605379
1,000
131,072
Wrong Answer
20
7,516
304
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
def bubbleSort(A,N): flag=1 while flag: flag=0 j=N-1 while j>0: if(A[j]<A[j-1]): A[j],A[j-1]=A[j-1],A[j] flag=1 j-=1 N=int(input()) A=[int(x) for x in input().split()] bubbleSort(A,N) print(A)
s878938751
Accepted
20
7,728
405
def bubbleSort(A,N): c=0 flag=1 while flag: flag=0 j=N-1 while j>0: if(int(A[j])<int(A[j-1])): c+=1 A[j],A[j-1]=A[j-1],A[j] flag=1 j-=1 return c N=int(input()) A=input().split() c=bubbleSort(A,N) S="" for i in range(N-1): S+=A[i]+" " S+=str(A[-1]) print(S) print(c)
s274158578
p00004
u979795132
1,000
131,072
Wrong Answer
20
5,604
680
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 โ‰ค a, b, c, d, e, f โ‰ค 1,000). You can suppose that given equation has a unique solution.
def equation(a,b,c,d,e,f,x): buff = a*e-b*d buff_a = a a = e/buff b = -b/buff d = -d/buff e = buff_a/buff x.append((a*c)+(b*f)) x.append((d*c)+(e*f)) count = 0 a = [] b = [] c = [] d = [] e = [] f = [] while True: try: buff = input().split() a.append(float(buff[0])) b.append(float(buff[1])) c.append(float(buff[2])) d.append(float(buff[3])) e.append(float(buff[4])) f.append(float(buff[5])) count += 1 except: break for i in range(count): ans = [] equation(a[i],b[i],c[i],d[i],e[i],f[i],ans) print('{:.4f}'.format(ans[0]),'{:.4f}'.format(ans[1]))
s147254113
Accepted
20
5,600
680
def equation(a,b,c,d,e,f,x): buff = a*e-b*d buff_a = a a = e/buff b = -b/buff d = -d/buff e = buff_a/buff x.append((a*c)+(b*f)) x.append((d*c)+(e*f)) count = 0 a = [] b = [] c = [] d = [] e = [] f = [] while True: try: buff = input().split() a.append(float(buff[0])) b.append(float(buff[1])) c.append(float(buff[2])) d.append(float(buff[3])) e.append(float(buff[4])) f.append(float(buff[5])) count += 1 except: break for i in range(count): ans = [] equation(a[i],b[i],c[i],d[i],e[i],f[i],ans) print('{:.3f}'.format(ans[0]),'{:.3f}'.format(ans[1]))
s176445898
p02394
u037441960
1,000
131,072
Wrong Answer
20
5,588
154
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
W,H,x,y,r = map(int, input().split()) if(x+r <= W & y+r <= H): if(x-r >= 0 & y-r >= 0) : print("Yes") else : print("No") else : print("No")
s278187190
Accepted
20
5,596
184
W, H, x, y, r = map(int, input().split()) if x - r >= 0 and y - r >= 0 : if x + r <= W and y + r <= H : print("Yes") else : print("No") else : print("No")
s832413597
p03047
u848654125
2,000
1,048,576
Wrong Answer
19
2,940
55
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers?
h = list(map(int, input().split())) print(h[0]-h[1])
s872756548
Accepted
17
2,940
57
h = list(map(int, input().split())) print(h[0]-h[1]+1)
s707877034
p03151
u869292891
2,000
1,048,576
Wrong Answer
441
27,084
639
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
import numpy as np N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) A=np.array(A) B=np.array(B) E=A-B e=sum(E) if e<0: print(-1) else: Eminus=[] Ezero=[] Eplus=[] nn=0 n0=0 for n in range(N): if E[n]<0: Eminus.append(E[n]) elif E[n]>0: Eplus.append(E[n]) nn=nn+1 else: Ezero.append(E[n]) n0=n0+1 Eplus.sort() sumup=0 for n in range(nn): sumup=sumup+Eplus[n] if sumup>e: break if n==nn-1: n=nn print(N-n0-n)
s190717059
Accepted
461
27,072
699
import numpy as np N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) A=np.array(A) B=np.array(B) E=A-B e=sum(E) if e<0: print(-1) else: Eminus=[] Ezero=[] Eplus=[] nn=0 n0=0 nminus=0 for n in range(N): if E[n]<0: Eminus.append(E[n]) nminus=nminus+1 elif E[n]>0: Eplus.append(E[n]) nn=nn+1 else: Ezero.append(E[n]) n0=n0+1 Eplus.sort() sumup=0 for n in range(nn): sumup=sumup+Eplus[n] if sumup>e: break if nminus==0: print(0) else: print(N-n0-n)
s693912573
p03068
u862466626
2,000
1,048,576
Wrong Answer
18
3,060
136
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = list(input()) K = int(input()) target = S[K-1] for item in S: if item != target: item = '*' print(''.join(S))
s434893907
Accepted
17
2,940
142
N = int(input()) S = list(input()) K = int(input()) target = S[K-1] for i in range(N): if S[i] != target: S[i] = '*' print(''.join(S))
s103222703
p02936
u105608888
2,000
1,048,576
Wrong Answer
2,207
65,848
593
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = map(int, input().split()) A = [tuple(map(int, input().split())) for _ in range(N-1)] P = [tuple(map(int, input().split())) for _ in range(Q)] def solve(A, num): ans = [] if True in [num==i[0] for i in A] : for i in A: if num == i[0]: ans.append(i[1]) k = solve(A, i[1]) if k: ans +=k return ans else: return False ans = [0] * N for i in P: print(i) ans[i[0]-1] += i[1] l = solve(A, i[0]) if l: for k in l: ans[k-1] += i[1] print(*ans)
s682178728
Accepted
1,434
228,100
525
import sys sys.setrecursionlimit(2*10**9) N, Q = map(int, input().split()) A = [[] for _ in range(N)] for _ in range(N-1): i, k = map(int, input().split()) A[i-1].append(k-1) A[k-1].append(i-1) n_P = [0] * N for _ in range(Q): k, n = map(int, input().split()) n_P[k-1] += n ans = [0] * N visited = [0] * N def make(num, p): ans[num] += n_P[num] ans[num] += p visited[num] = 1 for i in A[num]: if visited[i] == 0: make(i,ans[num]) return make(0, ans[0]) print(*ans)
s202927248
p02645
u200228637
2,000
1,048,576
Wrong Answer
21
9,016
27
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
S = input() print(S[:2])
s735151436
Accepted
25
9,020
24
s = input() print(s[:3])
s841438951
p03556
u763177133
2,000
262,144
Time Limit Exceeded
2,206
9,064
68
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
n = int(input()) a = 1 while a <= n: b = a a **= 2 print(b)
s140461804
Accepted
36
9,096
95
n = int(input()) a = 1 b = 0 c = 0 while c <= n: b = c c = a ** 2 a += 1 print(b)
s444117150
p02694
u427690532
2,000
1,048,576
Wrong Answer
33
9,208
72
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math X = int(input()) year = math.log((X / 100),1.01) print(year)
s905995313
Accepted
37
9,932
195
from decimal import Decimal X = int(input()) n = 0 money = 100 while True: money += int(money * Decimal("0.01")) #print(money) n += 1 if money >= X: print(n) break
s003196112
p03910
u603958124
2,000
262,144
Wrong Answer
42
10,240
1,138
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1โ‰ฆiโ‰ฆN) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) ans = [] def dfs(m): if m == 1: ans.append(1) return 0 elif m == 3: ans.append(2) ans.append(1) return 0 elif m == 4: ans.append(3) ans.append(1) return 0 elif m == 5: ans.append(3) ans.append(2) return 0 else: ans. append((m+1)//2) dfs(m//2) n = INT() dfs(n) for x in ans: print(x)
s404669528
Accepted
39
10,564
882
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) n = INT() ans = [] reg = 0 i = 1 while reg <= n: ans.append(i) reg += i i += 1 if reg - n > 0: ans.remove(reg-n) for x in ans: print(x)
s093608007
p03251
u432453907
2,000
1,048,576
Wrong Answer
30
9,112
182
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) ans="War" x.append(X) y.append(Y) if max(x)<min(y): ans="NO War" print(ans)
s692782147
Accepted
28
9,176
182
N,M,X,Y=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) ans="War" x.append(X) y.append(Y) if max(x)<min(y): ans="No War" print(ans)
s030596193
p03472
u665415433
2,000
262,144
Wrong Answer
564
30,752
548
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, โ€ฆ, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 โ‰ค i โ‰ค N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 โ‰ค i โ‰ค N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
N,H = map(int,input().split()) katana = [] damage = 0 for n in range(N): katana.append(list(map(int,input().split()))) katanaA = sorted(katana,reverse = True) katanaB = sorted(katana, key = lambda x:x[1],reverse = True) numb = 0 num = 0 check = True while damage < H: if katanaA[0][0] <= katanaB[numb][1] and check: damage += katanaB[numb][1] numb += 1 if numb == N: numb = N-1 check = False else: num += (H-damage)//katanaA[0][0] - 1 damage = H num += 1 print(num)
s335571853
Accepted
592
30,728
608
N,H = map(int,input().split()) katana = [] damage = 0 for n in range(N): katana.append(list(map(int,input().split()))) katanaA = sorted(katana,reverse = True) katanaB = sorted(katana, key = lambda x:x[1],reverse = True) numb = 0 num = 0 check = True while damage < H: if katanaA[0][0] <= katanaB[numb][1] and check: damage += katanaB[numb][1] numb += 1 if numb == N: numb = N-1 check = False else: num += (H-damage)//katanaA[0][0] if (H-damage)%katanaA[0][0] == 0: num -= 1 damage = H num += 1 print(num)
s881656543
p03433
u936985471
2,000
262,144
Wrong Answer
17
2,940
62
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n=int(input()) a=int(input()) print(("No","Yes")[n%500>=a])
s748261089
Accepted
17
2,940
59
n=int(input()) a=int(input()) print(("No","Yes")[n%500<=a])
s411399471
p03080
u587199081
2,000
1,048,576
Wrong Answer
17
3,060
330
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
from sys import stdin n = int(stdin.readline().rstrip()) data = stdin.readline().rstrip().split() print(type(data)) s = str(data[0]) count_red, count_blue = 0,0 for i in range(len(s)): if s[i] == "R": count_red += 1 else: count_blue += 1 if count_red > count_blue: print("Yes") else: print("No")
s085538917
Accepted
17
3,060
312
from sys import stdin n = int(stdin.readline().rstrip()) data = stdin.readline().rstrip().split() s = str(data[0]) count_red, count_blue = 0,0 for i in range(len(s)): if s[i] == "R": count_red += 1 else: count_blue += 1 if count_red > count_blue: print("Yes") else: print("No")
s445189610
p03543
u175034939
2,000
262,144
Wrong Answer
18
2,940
178
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
s = list(input()) cnt = 0 for i in range(len(s)-1): if s[i] == s[i+1]: cnt += 1 else: cnt = 0 if cnt == (3 or 4): print('Yes') else: print('No')
s760943484
Accepted
18
2,940
103
s = input() if (s[0] == s[1] == s[2]) or (s[1] == s[2] == s[3]): print('Yes') else: print('No')
s574219790
p03455
u201565171
2,000
262,144
Wrong Answer
2,104
2,940
155
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=input().split() N=int(a+b) flag=1 for i in range(1,N): s=N//i if N%i==0 and s==i: print("Yes") flag=0 break if flag==1: print("No")
s338069622
Accepted
17
2,940
86
a,b=map(int,input().split()) N=a*b if N%2==0: print("Even") else: print("Odd")
s086879997
p03997
u734936991
2,000
262,144
Wrong Answer
22
3,316
132
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
#!/use/bin/env python3 from collections import defaultdict (a, b, h) = [int(input()) for _ in range(0, 3)] print((a + b) * h /2)
s511000060
Accepted
21
3,316
134
#!/use/bin/env python3 from collections import defaultdict (a, b, h) = [int(input()) for _ in range(0, 3)] print((a + b) * h // 2)
s031093895
p00003
u454259029
1,000
131,072
Wrong Answer
40
7,548
257
Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so.
n = int(input()) for i in range(n): a,b,c = map(int,input().split(" ")) if a**2 == b**2 + c**2: print("Yes") elif b**2 == a**2 + c**2: print("Yes") elif c**2 == a**2 + b**2: print("Yes") else: print("No")
s202074087
Accepted
40
7,656
257
n = int(input()) for i in range(n): a,b,c = map(int,input().split(" ")) if a**2 == b**2 + c**2: print("YES") elif b**2 == a**2 + c**2: print("YES") elif c**2 == a**2 + b**2: print("YES") else: print("NO")
s711255711
p02612
u460980455
2,000
1,048,576
Wrong Answer
31
9,140
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n=int(input()) print(n%1000)
s361280290
Accepted
30
9,148
55
n=int(input()) n=int(n%1000) n=1000-n n=n%1000 print(n)
s184156907
p03815
u235376569
2,000
262,144
Wrong Answer
17
3,060
194
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90ยฐ toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
a=int(input()) flag=0 if(a<6): flag=1 print(1) elif(a<=6 and a<=11): flag=1 print(2) elif(flag!=1 and a%11==0): print(a//11*2) elif(flag!=1 and a%11!=0): print(a//11*2+1)
s875282803
Accepted
17
3,060
248
a=int(input()) flag=0 if(a<=6): flag=1 print(1) elif(6<a and a<=11): flag=1 print(2) elif(flag!=1 and a%11==0): print(a//11*2) elif(flag!=1 and a%11!=0): if 6<a%11: print(a//11*2+2) else: print(a//11*2+1)
s387855584
p03068
u435108403
2,000
1,048,576
Wrong Answer
17
3,060
183
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = int(input()) S = input() K = int(input()) S_list = list(S) target = S_list[K-1] for i in S_list: if not i == target : i = "*" S_new = "".join(S_list) print(S_new)
s060656674
Accepted
17
2,940
135
N, S, K = int(input()), list(input()), int(input()) S_new = "".join(["*" if S[i] != S[K-1] else S[i] for i in range(N)]) print(S_new)
s140787896
p03680
u781262926
2,000
262,144
Wrong Answer
40
14,068
165
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
n, *A = map(int, open(0).read().split()) x = 0 for i in range(n): x, A[x] = A[x]-1, 0 if x == -1: print(-1) exit() if x == 1: print(i+1) exit()
s364787903
Accepted
67
14,068
164
n, *A = map(int, open(0).read().split()) x = 0 for i in range(n): A[x], x = 0, A[x]-1 if x == -1: print(x) exit() if x == 1: print(i+1) exit()
s969287090
p02384
u216804574
1,000
131,072
Wrong Answer
20
5,608
1,463
Construct a dice from a given sequence of integers in the same way as
class Dice: def __init__(self, labels): self.labels = labels def east(self): self.labels[1], self.labels[2], self.labels[3], self.labels[4] = self.labels[3], self.labels[1], self.labels[4], self.labels[2] def west(self): self.labels[1], self.labels[2], self.labels[3], self.labels[4] = self.labels[2], self.labels[4], self.labels[1], self.labels[3] def north(self): self.labels[0], self.labels[1], self.labels[4], self.labels[5] = self.labels[1], self.labels[5], self.labels[0], self.labels[4] def south(self): self.labels[0], self.labels[1], self.labels[4], self.labels[5] = self.labels[4], self.labels[0], self.labels[5], self.labels[1] def clockwise(self): self.labels[0], self.labels[2], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[2], self.labels[5] dice = Dice(list(map(int, input().split()))) for n in range(int(input())): foward, top = map(int, input().split()) if foward+top == 7: print("not found") break south_cnt = 0 while True: if foward == dice.labels[5] and top == dice.labels[1]: break if foward == dice.labels[5]: dice.east() elif top == dice.labels[1]: dice.clockwise() else: if south_cnt == 3: dice.east() else: dice.south() south_cnt += 1 print(dice.labels[2])
s928628660
Accepted
20
5,608
1,381
class Dice: def __init__(self, labels): self.labels = labels def east(self): self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5] def west(self): self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0] def north(self): self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0] def south(self): self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5] dice = Dice(list(map(int, input().split()))) for n in range(int(input())): top, foward = map(int, input().split()) south_cnt = 0 while True: if foward == dice.labels[1] and top == dice.labels[0]: break if foward == dice.labels[1]: dice.east() elif top == dice.labels[0]: dice.south() dice.east() dice.north() else: if south_cnt == 3: dice.east() else: dice.south() south_cnt += 1 print(dice.labels[2])
s290241339
p02406
u685534465
1,000
131,072
Wrong Answer
20
7,460
105
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
n = int(input()) for i in range(1, n+1): if i%3 == 0 or str(i) in "3": print(" {0}".format(i), end='')
s974824220
Accepted
20
7,824
113
n = int(input()) for i in range(1, n+1): if i%3 == 0 or "3" in str(i): print(" {0}".format(i), end='') print()
s010311875
p03605
u871841829
2,000
262,144
Wrong Answer
17
2,940
63
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
s = input() if s in '9': print("Yes") else: print("No")
s756892130
Accepted
28
8,832
53
if '9' in input(): print("Yes") else: print("No")
s918995605
p03160
u634873566
2,000
1,048,576
Wrong Answer
17
3,064
608
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N = 7 input = "2 9 4 5 1 6 10" hights = [int(h) for h in input.split()] print(hights) eval = [] def chmin(a,b): if a > b: b = a return True return False for i in range(N): if i == N: break elif i == 0: eval.append(0) continue elif i == 1: eval.append(abs(hights[i] - hights[i-1] )) continue to_next = abs(hights[i] - hights[i-1]) + eval[i-1] prev_to_next = abs(hights[i] - hights[i-2]) + eval[i-2] if prev_to_next > to_next: eval.append(to_next) else: eval.append(prev_to_next) print(eval[N-1])
s090271182
Accepted
206
14,052
544
N = int(input()) steps = [int(i) for i in input().split()] dp = [float('inf')]*N for i in range(N): if i == 0: dp[0] = 0 if N > 1: dp[1] = abs(steps[1] - steps[0]) if N > 2: dp[2] = abs(steps[2] - steps[0]) else: if i+1 < N: dp[i+1] = min(abs(steps[i] - steps[i+1]) + dp[i], dp[i+1]) if i+2 < N: dp[i+2] = min(abs(steps[i] - steps[i+2]) + dp[i], dp[i+2]) print(dp[-1])
s387612822
p02389
u655518263
1,000
131,072
Wrong Answer
20
7,524
67
Write a program which calculates the area and perimeter of a given rectangle.
s = input() l = s.split(" ") a = int(l[0]) b = int(l[1]) print(a*b)
s893648553
Accepted
20
7,696
76
s = input() l = s.split(" ") a = int(l[0]) b = int(l[1]) print(a*b, 2*(a+b))
s971431557
p03958
u268792407
1,000
262,144
Wrong Answer
17
2,940
96
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 โ‰ค i โ‰ค T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
k,t=map(int,input().split()) a=list(map(int,input().split())) m=max(a) n=k-m print(min(m-n-1,0))
s926618200
Accepted
18
3,064
96
k,t=map(int,input().split()) a=list(map(int,input().split())) m=max(a) n=k-m print(max(m-n-1,0))
s052155527
p03625
u106297876
2,000
262,144
Wrong Answer
131
28,580
260
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
N = int(input()) A = list(map(int, input().split())) import collections A_c=collections.Counter(A) print(A_c) keys = [k for k, v in A_c.items() if v >= 2] keys.sort() if len(keys) < 2: ans = 0 else: ans = keys[len(keys)-1] * keys[len(keys)-2] print(ans)
s566662931
Accepted
76
18,316
335
N = int(input()) A = list(map(int, input().split())) import collections A_c=collections.Counter(A) keys = [k for k, v in A_c.items() if v >= 2] keys.sort() if len(keys) < 2: ans = 0 elif A_c.get(keys[len(keys)-1]) >= 4: ans = keys[len(keys)-1] * keys[len(keys)-1] else: ans = keys[len(keys)-1] * keys[len(keys)-2] print(ans)
s769412915
p03827
u434282696
2,000
262,144
Wrong Answer
17
2,940
88
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
x=0 n=int(input()) s=input() for i in range(n): if s[i]=='I':x+=1 else:x-=1 print(x)
s496640940
Accepted
17
2,940
113
x=0 res=0 n=int(input()) s=input() for i in range(n): if s[i]=='I':x+=1 else:x-=1 res=max(res,x) print(res)
s652676699
p02282
u947762778
1,000
131,072
Wrong Answer
30
7,612
558
Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree.
def getPostorder(preorder, inorder): if not preorder: return [] postorder = [] root = preorder[0] rootIndex = inorder.index(root) postorder.extend(getPostorder(preorder[1:rootIndex + 1], inorder[:rootIndex])) postorder.extend(getPostorder(preorder[rootIndex + 1:], inorder[rootIndex + 1:])) postorder.append(root) return postorder if __name__ == '__main__': n = int(input()) preorder = list(map(int, input().split())) inorder = list(map(int, input().split())) print(getPostorder(preorder, inorder))
s612550712
Accepted
20
7,780
559
def getPostorder(preorder, inorder): if not preorder: return [] postorder = [] root = preorder[0] rootIndex = inorder.index(root) postorder.extend(getPostorder(preorder[1:rootIndex + 1], inorder[:rootIndex])) postorder.extend(getPostorder(preorder[rootIndex + 1:], inorder[rootIndex + 1:])) postorder.append(root) return postorder if __name__ == '__main__': n = int(input()) preorder = list(map(int, input().split())) inorder = list(map(int, input().split())) print(*getPostorder(preorder, inorder))
s409326250
p04011
u663438907
2,000
262,144
Wrong Answer
19
2,940
155
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) ans = 0 for i in range(N): if i <= K: ans += X else: ans += Y print(ans)
s286873157
Accepted
19
3,060
160
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) ans = 0 for i in range(N): if i+1 <= K: ans += X else: ans += Y print(ans)
s566063273
p02398
u962381052
1,000
131,072
Wrong Answer
30
7,616
62
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
a, b, c = [int(n) for n in input().split()] print(b//c - a//c)
s166215168
Accepted
30
7,708
128
a, b ,c = [int(n) for n in input().split()] count = 0 for n in range(a, b+1): if c%n == 0: count += 1 print(count)
s583718133
p03369
u767438459
2,000
262,144
Wrong Answer
29
9,024
41
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = input() print(S.count("x")*100 + 700)
s702901963
Accepted
25
9,000
41
S = input() print(S.count("o")*100 + 700)
s108002226
p03150
u733774002
2,000
1,048,576
Wrong Answer
17
2,940
105
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
s = input() if s == "keyence" + s[7:] or s == s[:-7] + "keyence": print("YES") else: print("NO")
s477405526
Accepted
17
2,940
174
s = input() target = "keyence" ans = "NO" for i in range(len(target) + 1): if target == s[:i] + s[len(s) - len(target) + i:]: ans = "YES" break print(ans)
s466902304
p03597
u798129018
2,000
262,144
Wrong Answer
18
2,940
49
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
N = int(input()) A = int(input()) print(N**N - A)
s314011372
Accepted
17
2,940
49
n = int(input()) a = int(input()) print(n**2 -a)
s337331503
p03448
u559367141
2,000
262,144
Wrong Answer
56
9,040
213
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a,b,c,x = [int(input()) for i in range(4)] count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if (500*a + 100*b + 50*c == x): count += 1 print(count)
s572881469
Accepted
59
9,180
241
A = int(input()) B = int(input()) C = int(input()) X = int(input()) counts = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): if (500*a + 100*b + 50*c) == X: counts += 1 print(counts)
s658847733
p03598
u274635633
2,000
262,144
Wrong Answer
17
2,940
122
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
n=int(input()) k=int(input()) x=list(map(int,input().split())) ans=0 for i in range(n): ans+=min(x[i],k-x[i]) print(ans)
s649016062
Accepted
18
3,060
124
n=int(input()) k=int(input()) x=list(map(int,input().split())) ans=0 for i in range(n): ans+=min(x[i],k-x[i]) print(ans*2)
s953063204
p02607
u268674745
2,000
1,048,576
Wrong Answer
25
9,008
150
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
n = int(input()) cnt = 0 arr = [int(x) for x in input().split()] for i in range(0, len(arr), 2): if arr[i] % 2 == 0: cnt += 1 print(cnt)
s890357593
Accepted
23
9,140
150
n = int(input()) cnt = 0 arr = [int(x) for x in input().split()] for i in range(0, len(arr), 2): if arr[i] % 2 != 0: cnt += 1 print(cnt)
s894453425
p03229
u936985471
2,000
1,048,576
Wrong Answer
135
14,068
276
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
n,*a=map(int,open(0).read().split()) a=sorted(list(a)) from collections import deque a=deque(a) i=0 ans=0 cur=a.popleft() for i in range(1,n): if i%2==0: w=a.popleft() ans+=abs(w-cur) cur=w else: w=a.pop() ans+=abs(w-cur) cur=w print(ans)
s931823818
Accepted
326
8,856
1,083
# 6,8,1,2,3 # 3 8 1 6 2 # # 3 1 4 1 5 9 # 1 1 3 4 5 9 # # 5 5 1 # 5 1 5 N=int(input()) A=[0] * N for i in range(N): A[i] = int(input()) if N == 2: print(abs(A[0] - A[1])) exit(0) A=sorted(A) from collections import deque def calc(A,first,flip): q = deque(A) ans = 0 cur = first while q: if flip: a = q.popleft() else: a = q.pop() ans += abs(a - cur) cur = a flip^=True return ans if N%2: mid = A.pop(N//2) ans1 = calc(A,mid,True) ans2 = calc(A,mid,False) print(max(ans1,ans2)) else: A2 = A.copy() mid1 = A.pop(N//2-1) ans1_1 = calc(A,mid1,True) ans1_2 = calc(A,mid1,False) mid2 = A2.pop(N//2) ans2_1 = calc(A2,mid2,True) ans2_2 = calc(A2,mid2,False) print(max(ans1_1,ans1_2,ans2_1,ans2_2))
s532309578
p02407
u981139449
1,000
131,072
Wrong Answer
40
7,724
55
Write a program which reads a sequence and prints it in the reverse order.
input() print(*sorted(int(i) for i in input().split()))
s854231143
Accepted
20
7,472
41
input() print(*reversed(input().split()))
s441412834
p02612
u762469320
2,000
1,048,576
Wrong Answer
29
9,084
54
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) while n >= 1000: n = n-1000 print(n)
s126879738
Accepted
28
9,152
69
n = input() a = int(n[-3:]) if a == 0: print(0) else: print(1000-a)
s834273353
p03370
u353855427
2,000
262,144
Wrong Answer
17
3,064
232
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 โ‰ค i โ‰ค N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
num = list(map(int, input().split())) m = [] for i in range(num[0]): m.append(int(input())) for i in range(num[0]): num[1]-=m[i] m = sorted(m) print(num[1]) print(m) if(num[1]==0): print(num[0]) else: print(num[1]//m[0]+num[0])
s353316198
Accepted
18
3,064
233
num = list(map(int, input().split())) m = [] for i in range(num[0]): m.append(int(input())) for i in range(num[0]): num[1]-=m[i] m = sorted(m) #print(num[1]) #print(m) if(num[1]==0): print(num[0]) else: print(num[1]//m[0]+num[0])
s291132548
p03997
u135521563
2,000
262,144
Wrong Answer
24
3,064
74
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h / 2)
s318822422
Accepted
24
3,188
75
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h // 2)
s869553126
p02806
u422272120
2,525
1,048,576
Wrong Answer
17
3,064
305
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
n = int(input()) l = {} for i in range(0,n): #print (i) line = input() l[i] = line.strip().split() x = str(input()) time = 0 for i in range(0,n): print (str(l[i][0]), x) if l[i][0] == x: l.pop(i) break l.pop(i) for i in l: time += int((l[i][1])) print (time)
s997985561
Accepted
17
3,064
277
n = int(input()) l = {} for i in range(0,n): #print (i) line = input() l[i] = line.strip().split() x = str(input()) time = 0 for i in range(0,n): if l[i][0] == x: l.pop(i) break l.pop(i) for i in l: time += int((l[i][1])) print (time)
s477500221
p03730
u777283665
2,000
262,144
Wrong Answer
17
2,940
124
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int, input().split()) for i in range(1, a+b+1): if a * i % b == c: print("Yes") exit() print("No")
s368354195
Accepted
17
2,940
126
a, b, c = map(int, input().split()) for i in range(1, a*b+1): if (a * i) % b == c: print("YES") exit() print("NO")
s948887550
p03861
u857070771
2,000
262,144
Wrong Answer
18
2,940
62
You are given nonnegative integers a and b (a โ‰ค b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x=map(int,input().split()) ans = b // x - a //x print(ans)
s214902654
Accepted
17
2,940
65
a,b,x=map(int,input().split()) ans = b // x - (a-1)//x print(ans)
s668729154
p03155
u814781830
2,000
1,048,576
Wrong Answer
17
2,940
89
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
N = int(input()) H = int(input()) W = int(input()) print(int((H - N + 1) * (W - N + 1)))
s103723479
Accepted
17
2,940
90
N = int(input()) H = int(input()) W = int(input()) print(int((N - H + 1) * (N - W + 1)))
s946058850
p02742
u056358163
2,000
1,048,576
Wrong Answer
17
2,940
86
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
H, W = map(int, input().split()) print((W + 1) // 2 * (H + 1) // 2 + W // 2 * H // 2)
s775123347
Accepted
17
2,940
160
H, W = map(int, input().split()) if H == 1 or W == 1: print(1) else: odd = ((W + 1) // 2) * ((H + 1) // 2) even = (W // 2) * (H // 2) print(odd + even)
s976679911
p03555
u903948194
2,000
262,144
Wrong Answer
17
2,940
86
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
c = list(input()) if c[::-1] == list(input()): print('Yes') else: print('No')
s872004300
Accepted
17
2,940
86
c = list(input()) if c[::-1] == list(input()): print('YES') else: print('NO')
s795464437
p03778
u254871849
2,000
262,144
Wrong Answer
17
2,940
119
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
w, a, b = [int(x) for x in input().split()] if abs(a - b) > w: ans = abs(a - b) + w else: ans = 0 print(ans)
s754666260
Accepted
17
3,060
252
import sys w, a, b = map(int, sys.stdin.readline().split()) def main(): if a + w < b: return b - (a + w) elif b + w < a: return a - (b + w) else: return 0 if __name__ == '__main__': ans = main() print(ans)
s296477769
p03719
u007263493
2,000
262,144
Wrong Answer
17
2,940
93
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a ,b, c=map(int,input().split()) if c >= a and c <= b: print('YES') else: print('NO')
s792537955
Accepted
17
2,940
93
a ,b, c=map(int,input().split()) if c >= a and c <= b: print('Yes') else: print('No')
s615929167
p03672
u839537730
2,000
262,144
Wrong Answer
17
2,940
122
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
s = input().strip() ls = len(s) for i in range(ls//2-1, 0, -1): if s[:i] == s[i:2*1]: print(2*i) break
s959359466
Accepted
17
3,060
209
S = input() for i in range(1, len(S)): if len(S[:-i]) % 2 == 1: continue if S[:int(len(S[:-i])/2)] == S[int(len(S[:-i])/2):-i]: ans = len(S[:int(len(S[:-i]))]) break print(ans)
s153389000
p03455
u702582248
2,000
262,144
Wrong Answer
17
2,940
62
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
print('Yes'if[i for i in input().split() if int(i)%2]else'No')
s521059305
Accepted
17
2,940
67
print('Even'if[i for i in input().split() if int(i)%2==0]else'Odd')
s267612407
p03167
u686230543
2,000
1,048,576
Wrong Answer
2,109
22,216
589
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}. If a_{i, j} is `.`, Square (i, j) is an empty square; if a_{i, j} is `#`, Square (i, j) is a wall square. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W). As the answer can be extremely large, find the count modulo 10^9 + 7.
import numpy as np MOD = 10 ** 9 + 7 H, W = map(int, input().split()) count = np.ones((H, W), dtype=np.int) row = input() for w in range(1, W): if row[w] == '#': count[w:] = 0 break flag = True for h in range(1, H): row = input() if flag and row[0] == '#': count[h:, 0] = 0 flag = False count[h, 1:] = count[h-1, 1:] for w in range(1, W): period = 0 if row[w] == '#': count[h, period : w] = count[h, period : w].cumsum() % MOD count[h, w] = 0 period = w + 1 count[h, period:] = count[h, period:].cumsum() % MOD print(count[-1, -1])
s653823319
Accepted
402
3,064
371
MOD = 10 ** 9 + 7 H, W = map(int, input().split()) count = [0] * W row = input() for w in range(W): if row[w] == '#': break else: count[w] = 1 for h in range(1, H): row = input() if row[0] == '#': count[0] = 0 for w in range(1, W): if row[w] == '#': count[w] = 0 else: count[w] = (count[w-1] + count[w]) % MOD print(count[-1])
s747682543
p02417
u248424983
1,000
131,072
Wrong Answer
30
7,900
127
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
import string x=input() allcase=string.ascii_lowercase for letter in allcase: print(letter + " : " + repr(x.count(letter)))
s373166365
Accepted
40
7,996
183
import string x = '' allcase = string.ascii_lowercase while True: try: x+=input().lower() except:break for letter in allcase: print(letter + " : " + repr(x.count(letter)))
s121435825
p02399
u973203074
1,000
131,072
Wrong Answer
20
5,608
95
Write a program which reads two integers a and b, and calculates the following values: * a รท b: d (in integer) * remainder of a รท b: r (in integer) * a รท b: f (in real number)
a, b = map(int, input().split()) ans = [a // b, a % b, a / b] print(" ".join(map(str, ans)))
s185049398
Accepted
20
5,608
98
a, b = map(int, input().split()) d = a // b r = a % b f = a / b print(d, r, '{:.5f}'.format(f))
s546482688
p01448
u226888928
8,000
131,072
Wrong Answer
20
7,684
350
ๆ˜Žๆ—ฅใ‹ใ‚‰ใ€ๅพ…ใกใซๅพ…ใฃใŸๅคไผ‘ใฟใŒๅง‹ใพใ‚Šใพใ™ใ€‚ใชใฎใงใ‚ใŸใ—ใฏใ€ๅ‹ใ ใกใ‚’่ช˜ใฃใฆใ€ๆตทใซ้Šใณใซ่กŒใใ“ ใจใซๆฑบใ‚ใพใ—ใŸใ€‚ ใ‘ใ‚Œใฉใ‚‚ใ€ใ‚ใŸใ—ใฎๅ‹ใ ใกใซใฏใ€ๆฅใšใ‹ใ—ใŒใ‚Šใ‚„ใ•ใ‚“ใŒๅคšใ„ใงใ™ใ€‚ใใฎไบบใŸใกใฏใ€ใ‚ใพใ‚ŠๅคšใใฎไบบใŒ ใ„ใฃใ—ใ‚‡ใซๆฅใ‚‹ใจ็ŸฅใฃใŸใ‚‰ใ€ใใฃใจๅซŒใŒใ‚‹ใงใ—ใ‚‡ใ†ใ€‚ ใปใ‹ใซใ‚‚ใ€ใ‚ใŸใ—ใฎๅ‹ใ ใกใซใฏใ€็›ฎ็ซ‹ใกใŸใŒใ‚Šใ‚„ใ•ใ‚“ใ‚‚ๅคšใ„ใงใ™ใ€‚ใใฎไบบใŸใกใฏใ€ใ„ใฃใ—ใ‚‡ใซๆฅใ‚‹ไบบ ใŒใ‚ใพใ‚Šๅคšใใชใ„ใจ็Ÿฅใ‚Œใฐใ€ใใฃใจๅซŒใŒใ‚‹ใงใ—ใ‚‡ใ†ใ€‚ ใใ‚Œใจใ€ใ‚ใŸใ—ใฎๅ‹ใ ใกใซใฏใ€ใ„ใคใ‚‚ใฏ็›ฎ็ซ‹ใกใŸใŒใ‚Šใ‚„ใชใฎใซๅฎŸใฏๆฅใšใ‹ใ—ใŒใ‚Šใ‚„ใ•ใ‚“ใชไบบใ‚‚ใ„ใพ ใ™ใ€‚ใใฎไบบใŸใกใฏใ€ใ„ใฃใ—ใ‚‡ใซๆฅใ‚‹ไบบใŒๅคšใ™ใŽใฆใ‚‚ๅฐ‘ใชใ™ใŽใฆใ‚‚ใ€ใใฃใจๅซŒใŒใ‚‹ใงใ—ใ‚‡ใ†ใ€‚ ใ“ใ†ใ„ใ†ใฎใฏใ€ๅคงๅ‹ขใง่กŒใฃใŸๆ–นใŒๆฅฝใ—ใ„ใฏใšใงใ™ใ€‚ใ ใ‹ใ‚‰ใ‚ใŸใ—ใฏใ€ใงใใ‚‹ใ ใ‘ใŸใใ•ใ‚“ใฎๅ‹ใ ใกใ‚’ ่ช˜ใ„ใŸใ„ใจๆ€ใฃใฆใ„ใพใ™ใ€‚ใ‘ใ‚Œใฉใ‚‚ใ€ๅซŒใŒใ‚‹ๅ‹ใ ใกใ‚’็„ก็†ใ‚„ใ‚Š้€ฃใ‚Œใฆใ„ใใฎใฏใ‚ˆใใ‚ใ‚Šใพใ›ใ‚“ใ€‚ ใ„ใฃใŸใ„ใ€ใ‚ใŸใ—ใฏๆœ€ๅคงใงไฝ•ไบบใฎๅ‹ใ ใกใ‚’่ช˜ใ†ใ“ใจใŒใงใใ‚‹ใฎใงใ—ใ‚‡ใ†ใ‹ใ€‚ ใ‚ใŸใ—ใฏใ€ใ“ใ†ใ„ใ†้ ญใ‚’ไฝฟใ„ใใ†ใชๅ•้กŒใŒๅคงใฎ่‹ฆๆ‰‹ใงใ™ใ€‚ใชใฎใงใ€ใ‚ใชใŸใซใŠ้ก˜ใ„ใŒใ‚ใ‚Šใพใ™ใ€‚ใ‚‚ใ— ใ‚ˆใ‚ใ—ใ‘ใ‚Œใฐใ€ใ‚ใŸใ—ใฎไปฃใ‚ใ‚Šใซใ“ใฎๅ•้กŒใ‚’่งฃใ„ใฆใ„ใŸใ ใ‘ใชใ„ใงใ—ใ‚‡ใ†ใ‹ใ€‚ใ„ใˆใ€ๆฑบใ—ใฆ็„ก็†ใซใจ ใฏ่จ€ใ„ใพใ›ใ‚“ใ€‚ใ‘ใ‚Œใฉใ€ใ‚‚ใ—่งฃใ„ใฆใ„ใŸใ ใ‚‹ใฎใงใ—ใŸใ‚‰ใ€ใ‚ใŸใ—ใฏใจใฆใ‚‚ๅฌ‰ใ—ใ„ใงใ™ใ€‚
import heapq n=int(input()) abs=sorted([list(map(int,input().split())) for _ in range(n)]) s=0 best=0 heap=[] for k in range(1,n+1): while(s < n and abs[s][0] <= k+1): heapq.heappush(heap, -abs[s][1]) s+=1 while(len(heap) > 0 and -heap[0] <= k): heapq.heappop(heap) if(len(heap) >= k): best = k print(best)
s515017875
Accepted
870
33,108
348
import heapq n=int(input()) abs=sorted([list(map(int,input().split())) for _ in range(n)]) s=0 best=0 heap=[] for k in range(1,n+1): while(s < n and abs[s][0] <= k+1): heapq.heappush(heap, abs[s][1]) s+=1 while(len(heap) > 0 and heap[0] <= k): heapq.heappop(heap) if(len(heap) >= k): best = k print(best)
s302383858
p02678
u671211357
2,000
1,048,576
Wrong Answer
24
9,116
11
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
print("No")
s094680331
Accepted
585
34,628
472
from collections import deque N,M=map(int,input().split()) haba=[[] for i in range(N+1)] for i in range(M): A,B=map(int,input().split()) haba[A].append(B) haba[B].append(A) kyori=[-1]*(N+1) kyori[0]=0 kyori[1]=0 que=deque() que.append(1) while que: kari=que.popleft() for i in haba[kari]: if kyori[i]!=-1: continue kyori[i]=kari que.append(i) ans=kyori[2:] print("Yes") for i in range(len(ans)): print(ans[i])
s242382241
p03623
u842388336
2,000
262,144
Wrong Answer
17
2,940
60
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b=map(int,input().split()) print(min(abs(x-a),abs(x-b)))
s795910260
Accepted
17
2,940
84
x,a,b=map(int,input().split()) if abs(x-a)>abs(x-b): print("B") else: print("A")
s558057469
p03478
u982762220
2,000
262,144
Wrong Answer
28
3,060
178
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
N, A, B = map(int, input().split()) res = 0 for num in range(N): tmp = 0 while num > 0: tmp += num % 10 num //= 10 if A <= tmp and tmp <= B: res += 1 print(res)
s536823033
Accepted
29
3,060
193
N, A, B = map(int, input().split()) res = 0 for i in range(1, N + 1): tmp = 0 num = i while num > 0: tmp += num % 10 num //= 10 if A <= tmp and tmp <= B: res += i print(res)
s714237641
p04043
u061361273
2,000
262,144
Wrong Answer
27
9,020
159
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
def hiku(): lst=input() lst = lst.split() lst.sort() print(lst) if lst[0]=='5' and lst[1]=='5' and lst[2]=='7': print("YES") else: print('NO') hiku()
s840830848
Accepted
25
8,964
213
def test(): x = input() x = x.split() if x == ['5', '5', '7']: print("YES") elif x == ['5', '7', '5']: print("YES") elif x == ['7', '5', '5']: print("YES") else: print("NO") test()
s384619803
p02694
u922769680
2,000
1,048,576
Wrong Answer
23
9,108
106
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import math X=int(input()) M=100 count=0 while M <= X: M=math.floor(M*1.01) count+=1 print(count)
s424898804
Accepted
27
9,164
105
import math X=int(input()) M=100 count=0 while M < X: M=math.floor(M*1.01) count+=1 print(count)
s981428787
p03456
u765401716
2,000
262,144
Wrong Answer
18
2,940
212
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a,b = input().split() C = a + b number_list =list(range(1,101)) squared_list =[] for i in number_list: D = i * i squared_list.append(D) if C in squared_list: print("Yes") else: print("No")
s732547572
Accepted
18
3,060
234
a,b = input().split() C = a + b number_list =list(range(1,1000)) squared_list =[] for i in number_list: D = i * i D2 = str(D) squared_list.append(D2) if C in squared_list: print("Yes") else: print("No")
s612342148
p02850
u321035578
2,000
1,048,576
Wrong Answer
2,104
16,284
655
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
def main(): n = int(input()) G = [[0] * (n-1) for i in range(2)] cnt = [0] * n for i in range(n-1): a,b = map(int, input().split()) G[0][i] = a-1 G[1][i] = b-1 cnt[a-1] += 1 cnt[b-1] += 1 num = 0 print(G) print(max(cnt)) tmp_clr = [0] * (n-1) for i in range(n-1): clr = 1 for j in range(i): if G[0][j] == G[0][i] or G[1][j] == G[0][i] or G[0][j] == G[1][i] or G[1][j] == G[1][i]: if tmp_clr[j] == clr: clr += 1 tmp_clr[i] = clr print('\n'.join(map(str, tmp_clr))) if __name__=='__main__': main()
s834333168
Accepted
484
34,204
942
def main(): n = int(input()) cnt = [0] * n G = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) G[a-1].append((b-1, i)) cnt[a-1] += 1 cnt[b-1] += 1 # a,b = map(int, input().split()) # G[0][i] = a-1 # G[1][i] = b-1 # cnt[a-1] += 1 # cnt[b-1] += 1 num = 0 # print(G) print(max(cnt)) tmp_clr = [0] * (n-1) tmp_edge = [0] * n # print(G) for frm, child in enumerate(G): clr = 1 for j, to in enumerate(child): if tmp_edge[frm] == clr : clr += 1 tmp_clr[to[1]] = clr # tmp_edge[frm] = clr tmp_edge[to[0]] = clr clr+=1 # print(tmp_edge) # print(tmp_clr) print('\n'.join(map(str, tmp_clr))) if __name__=='__main__': main()
s673749233
p03762
u371763408
2,000
262,144
Wrong Answer
268
18,576
258
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i. For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7. That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.
n,m = map(int,input().split()) X = list(map(int,input().split())) Y = list(map(int,input().split())) area=0 mod=10**9+7 x=0 for i in range(n): x += -(n-i-1)*X[i]+i*X[i] print("x",x) y = 0 for i in range(m): y += -(m-i-1)*Y[i]+i*Y[i] print(x*y%mod)
s852297004
Accepted
154
18,624
243
n,m = map(int,input().split()) X = list(map(int,input().split())) Y = list(map(int,input().split())) area=0 mod=10**9+7 x=0 for i in range(n): x += -(n-i-1)*X[i]+i*X[i] y = 0 for i in range(m): y += -(m-i-1)*Y[i]+i*Y[i] print(x*y%mod)
s086798682
p02261
u809233245
1,000
131,072
Wrong Answer
30
6,336
975
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
import copy def bubble_sort(a): ba = copy.copy(a) flag = True for i in range(0, n): if not flag: break flag = False for j in range(n-1, 0, -1): if int(ba[j][1]) < int(ba[j-1][1]): ba[j], ba[j-1] = ba[j-1], ba[j] flag = True return ba def selection_sort(a): sa = copy.copy(a) for i in range(n): flag = False minj = i for j in range(i, n): if int(sa[j][1]) < int(sa[minj][1]): minj = j flag = True if flag: sa[i], sa[minj] = sa[minj], sa[i] return sa def is_stable(ba, sa): for b, s in zip(ba, sa): if b != s: return 'Not Stable' return 'Stable' n = int(input()) a = list(map(str, input().split())) ba = bubble_sort(a) print(' '.join(map(str, ba))) print('Stable') sa = selection_sort(a) print(' '.join(map(str, sa))) print(is_stable(ba, sa))
s999845297
Accepted
30
6,344
975
import copy def bubble_sort(a): ba = copy.copy(a) flag = True for i in range(0, n): if not flag: break flag = False for j in range(n-1, 0, -1): if int(ba[j][1]) < int(ba[j-1][1]): ba[j], ba[j-1] = ba[j-1], ba[j] flag = True return ba def selection_sort(a): sa = copy.copy(a) for i in range(n): flag = False minj = i for j in range(i, n): if int(sa[j][1]) < int(sa[minj][1]): minj = j flag = True if flag: sa[i], sa[minj] = sa[minj], sa[i] return sa def is_stable(ba, sa): for b, s in zip(ba, sa): if b != s: return 'Not stable' return 'Stable' n = int(input()) a = list(map(str, input().split())) ba = bubble_sort(a) print(' '.join(map(str, ba))) print('Stable') sa = selection_sort(a) print(' '.join(map(str, sa))) print(is_stable(ba, sa))