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
s103155874
p03860
u346629192
2,000
262,144
Wrong Answer
17
2,940
38
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().split()[1] print("A"+s+"C")
s691108551
Accepted
18
2,940
42
s =input().split()[1] print("A"+s[0]+"C")
s019988459
p03943
u616040357
2,000
262,144
Wrong Answer
17
2,940
257
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
def solve(): a, b, c = map(int, input().split()) if a == b + c: ans = "YES" elif b == a + c: ans = "YES" elif c == a + b: ans = "YES" else: ans = "NO" print(ans) if __name__ == '__main__': solve()
s156947766
Accepted
17
2,940
257
def solve(): a, b, c = map(int, input().split()) if a == b + c: ans = "Yes" elif b == a + c: ans = "Yes" elif c == a + b: ans = "Yes" else: ans = "No" print(ans) if __name__ == '__main__': solve()
s527867304
p03624
u130900604
2,000
262,144
Wrong Answer
20
3,956
103
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
string=input() s=set(list(string)) full=set(list("abcdefghijklmnopqrstuvwxyz")) tmp=full-s print(tmp)
s171328451
Accepted
20
3,956
153
string=input() s=set(list(string)) full=set(list("abcdefghijklmnopqrstuvwxyz")) tmp=full-s if len(tmp)==0: print("None") exit() print(min(tmp))
s782218236
p03583
u761989513
2,000
262,144
Wrong Answer
572
2,940
223
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted.
N = int(input()) if N > 0: for i in range(2, 3501, 3): for n in range(1, 1751): w = i * n if 3 * w == N * (i + 1): print("{} {} {}".format(N, n, w)) exit()
s013910927
Accepted
1,671
2,940
244
N = int(input()) for h in range(1, 3501): for n in range(h, 3501): bunbo = 4 * h * n - N * n - N * h if bunbo > 0 and N * h * n % bunbo == 0: print("{} {} {}".format(h, n, N * h * n // bunbo)) exit()
s928378301
p03149
u532966492
2,000
1,048,576
Wrong Answer
17
2,940
57
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
print("YNeos"["".join(sorted(list(input())))!="1479"::2])
s143421345
Accepted
17
2,940
65
print("YNEOS"["".join(sorted(list(input().split())))!="1479"::2])
s425594823
p03777
u672475305
2,000
262,144
Wrong Answer
17
2,940
78
Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest.
a,b = map(str,input().split()) if a==b: print('Yes') else: print('No')
s501898889
Accepted
17
2,940
75
a,b = map(str,input().split()) if a==b: print('H') else: print('D')
s337619496
p03644
u820351940
2,000
262,144
Wrong Answer
17
2,940
67
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
a = int(input()) cnt = 0 while a: cnt += 1 a >>= 1 print(cnt - 1)
s622933073
Accepted
17
2,940
81
a = int(input()) cnt = 0 while a: cnt += 1 a >>= 1 print(1 << (cnt - 1))
s481082804
p03049
u037074041
2,000
1,048,576
Wrong Answer
40
4,724
1,563
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
from sys import stdin import math import itertools def makeIntMatrix(lines): intMatrix = [] for a in makeStringMatrix(lines): intMatrix.append([int(b) for b in a]) return intMatrix def makeStringMatrix(lines): stringMatrix = [line.rstrip() for line in lines] return stringMatrix def makeInt(line): return int(line.rstrip()) def makeMultiInteger(line): return [int(x) for x in line.rstrip().split()] def solve(input_string): N = makeInt(input_string[0]) S = makeStringMatrix(input_string[1:]) print(S) C_S_has_ab = [] for s_index, s in enumerate(S): C_S_has_ab.append(0) for i in range(len(s)-1): if s[i] + s[i+1] == 'AB': C_S_has_ab[s_index] += 1 print(C_S_has_ab) _sum = 0 _sum += sum(C_S_has_ab) c_head_has_b = 0 c_tail_has_a = 0 c_head_tail_has_a_and_b = 0 for s in S: if s[0] == 'B': c_head_has_b += 1 if s[-1] == 'A': c_tail_has_a += 1 if s[0] == 'B' and s[-1] == 'A': c_head_tail_has_a_and_b += 1 print(c_tail_has_a, c_tail_has_a, c_head_tail_has_a_and_b) #count_combi_a_b = c_tail_has_a * c_tail_has_a - c_head_tail_has_a_and_b count_combi_a_b = min(c_tail_has_a, c_tail_has_a) - c_head_tail_has_a_and_b + 1 #- c_head_tail_has_a_and_b _sum += count_combi_a_b print(_sum) return _sum def main(): input_lines = stdin.readlines() answer = solve(input_lines) print(answer) if __name__ == '__main__': main()
s272327643
Accepted
36
4,596
1,877
from sys import stdin import math import itertools def makeIntMatrix(lines): intMatrix = [] for a in makeStringMatrix(lines): intMatrix.append([int(b) for b in a]) return intMatrix def makeStringMatrix(lines): stringMatrix = [line.rstrip() for line in lines] return stringMatrix def makeInt(line): return int(line.rstrip()) def makeMultiInteger(line): return [int(x) for x in line.rstrip().split()] def solve(input_string): N = makeInt(input_string[0]) S = makeStringMatrix(input_string[1:]) #print(S) C_S_has_ab = [] for s_index, s in enumerate(S): C_S_has_ab.append(0) for i in range(len(s)-1): if s[i] + s[i+1] == 'AB': C_S_has_ab[s_index] += 1 #print(C_S_has_ab) _sum = 0 _sum += sum(C_S_has_ab) c_head_has_b = 0 c_tail_has_a = 0 c_head_tail_has_a_and_b = 0 for s in S: """ if s[0] == 'B': c_head_has_b += 1 if s[-1] == 'A': c_tail_has_a += 1 if s[0] == 'B' and s[-1] == 'A': c_head_tail_has_a_and_b += 1 """ if(s[0] == 'B' and s[-1] == 'A'): c_head_tail_has_a_and_b += 1 elif(s[-1] == 'A'): c_tail_has_a += 1 elif(s[0] == 'B'): c_head_has_b += 1 #print(c_head_has_b, c_tail_has_a, c_head_tail_has_a_and_b) if c_head_tail_has_a_and_b > 0: count_combi_a_b = max(0, c_head_tail_has_a_and_b-1) + min(c_head_has_b, c_tail_has_a) if c_head_has_b > 0 or c_tail_has_a > 0: count_combi_a_b += 1 else: count_combi_a_b = min(c_head_has_b, c_tail_has_a) _sum += count_combi_a_b #print(_sum) return _sum def main(): input_lines = stdin.readlines() answer = solve(input_lines) print(answer) if __name__ == '__main__': main()
s764047388
p03131
u597455618
2,000
1,048,576
Wrong Answer
17
3,060
149
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
k, a, b = map(int, input().split()) if 2 >= b - a or k+1 <= a: print(k+1) else: i = (k-a+1)//2+1 ans = k+1 -a*i + b*i -2*i print(ans)
s929347083
Accepted
18
3,060
148
k, a, b = map(int, input().split()) if 2 >= b - a or k+1 <= a: print(k+1) else: i = -(a-k-1)//2 ans = k+1 -a*i + b*i -2*i print(ans)
s964944875
p03962
u319612498
2,000
262,144
Wrong Answer
17
3,060
176
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
a,b,c=map(int, input().split()) list=[a,b,c] list.sort() if list[0]==list[1]==list[2]: print(3) elif list[1]==list[0] or list[1]==list[2]: print(2) else: print(1)
s663823200
Accepted
17
3,060
177
a,b,c=map(int, input().split()) list=[a,b,c] list.sort() if list[0]==list[1]==list[2]: print(1) elif list[1]==list[0] or list[1]==list[2]: print(2) else: print(3)
s410416786
p02260
u424041287
1,000
131,072
Wrong Answer
20
5,604
402
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
def bubbleSort(A, N): s = 0 for i in range(N): minj = i for j in range(i,N): if A[j] < A[minj]: minj = j A[j], A[j - 1] = A[j - 1], A[j] s += 1 t = str(A[0]) for i in range(1,N): t = t + " " + str(A[i]) print(t) print(s) n = int(input()) a = [int(i) for i in input().split()] bubbleSort(a, n)
s738175576
Accepted
30
5,600
416
def selectionSort(A, N): s = 0 for i in range(N): minj = i for j in range(i,N): if A[j] < A[minj]: minj = j A[i], A[minj] = A[minj], A[i] if i != minj: s += 1 t = str(A[0]) for i in range(1,N): t = t + " " + str(A[i]) print(t) print(s) n = int(input()) a = [int(i) for i in input().split()] selectionSort(a, n)
s842440767
p03943
u209918867
2,000
262,144
Wrong Answer
17
2,940
75
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a,b,c=map(int,input().split());print('YNeos'[a+b!=c and a+c!=b and b+c!=a])
s462398620
Accepted
17
2,940
78
a,b,c=map(int,input().split());print('YNeos'[a+b!=c and a+c!=b and b+c!=a::2])
s901942335
p02936
u047668580
2,000
1,048,576
Wrong Answer
2,111
60,396
957
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.
import sys input = sys.stdin.readline import numpy as np N, Q = list(map(int, input().split())) graph = [[] for i in range(N)] for i in range(N-1): a, b = list(map(int, input().split())) graph[a-1].append(b-1) points = np.zeros(N, dtype=int) for _ in range(Q): p, x = list(map(int, input().split())) points[p-1] += x visited = np.zeros(N, dtype=bool) tot_points = np.zeros(N, dtype=int) tot_points[0] = points[0] top_nodes = np.full(N, -1, dtype=int) nodes = graph[0] top_nodes[nodes] = 0 old_node = 0 while len(nodes): node = nodes.pop() if top_nodes[node] == -1: top_nodes[node] = old_node else: old_node = top_nodes[node] top_nodes[graph[node]] = node nodes.extend(graph[node]) tot_points[node] = tot_points[old_node] + points[node] old_node = node for x in tot_points.tolist(): print(x, end=" ")
s136273131
Accepted
1,088
65,320
827
import sys from queue import deque input = sys.stdin.readline def main(): N, Q = list(map(int, input().split())) graph = [[] for i in range(N)] for i in range(N-1): a, b = list(map(int, input().split())) graph[a-1].append(b-1) graph[b-1].append(a-1) points = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) points[p-1] += x visited = [False] * N nodes = deque([0]) while nodes: node = nodes.pop() visited[node] = True for _node in graph[node]: if visited[_node]: continue points[_node] += points[node] nodes.append(_node) print(*points) main()
s696800556
p03693
u464603191
2,000
262,144
Wrong Answer
21
3,316
115
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) s = int(100*r + 10*g + b) t = s%4 if t == 0 : print('yes') else : print('no')
s603842610
Accepted
29
3,064
115
r, g, b = map(int, input().split()) s = int(100*r + 10*g + b) t = s%4 if t == 0 : print('YES') else : print('NO')
s869215881
p03601
u777923818
3,000
262,144
Wrong Answer
71
3,968
600
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
# -*- coding: utf-8 -*- A, B, C, D, E, F = tuple(map(int, input().split())) A, B = 100*A, 100*B waters = set([a+b for b in range(0, F+1, B) for a in range(b, F-b+1, A)]) res_water = 0 res_sugar = 0 max_ratio = 0 for w in sorted(waters): sugar = max([c+d for c in range(0, int(w/100)*E+1, C) for d in range(c, int(w/100)*E-c+1, D) if (c+d+w <= F)]) if w+sugar==0: continue if 100*sugar / (w+sugar) > max_ratio: max_ratio = 100*sugar / (w+sugar) res_water = w res_sugar = sugar print("{} {}".format(res_water+res_sugar, res_sugar))
s027183652
Accepted
298
6,160
714
# -*- coding: utf-8 -*- A, B, C, D, E, F = tuple(map(int, input().split())) A, B = 100*A, 100*B waters = set([a+b for b in range(0, F+1, B) for a in range(0, F+1, A) if a+b <= F]) res_water = min(A, B) res_sugar = 0 max_ratio = 0 for w in sorted(waters): sugars = [c+d for c in range(0, int(w//100)*E+1, C) for d in range(0, int(w//100)*E+1, D) if (c+d+w <= F) and (c+d <= int(w/100)*E)] sugar = max(sugars) #print(sugars) if w+sugar==0: continue if 100*sugar / (w+sugar) > max_ratio: max_ratio = 100*sugar / (w+sugar) res_water = w res_sugar = sugar print("{} {}".format(res_water+res_sugar, res_sugar))
s997755401
p04043
u165388538
2,000
262,144
Wrong Answer
22
9,024
88
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.
abc = input().split() print("YES" if abc.count(5) == 2 and abc.count(7) == 1 else "NO")
s689875645
Accepted
29
9,024
92
abc = input().split() print("YES" if abc.count("5") == 2 and abc.count("7") == 1 else "NO")
s020589925
p04044
u614181788
2,000
262,144
Wrong Answer
18
3,188
152
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 = [0]*n for i in range(n): s[i] = input() s = sorted(s) ans = [] for i in range(n): ans.extend(s[i]) print(ans)
s535660481
Accepted
18
3,060
153
n,l = map(int,input().split()) s = [0]*n for i in range(n): s[i] = input() s = sorted(s) ans = [] for i in range(n): print(s[i],end="") print("")
s985513710
p03455
u363466395
2,000
262,144
Wrong Answer
17
2,940
100
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = [int(x) for x in input().split()] if a * b % 2 == 0: print("even") else: print("odd")
s741772721
Accepted
18
2,940
100
a, b = [int(x) for x in input().split()] if a * b % 2 == 0: print("Even") else: print("Odd")
s034698655
p03644
u762420987
2,000
262,144
Wrong Answer
17
2,940
158
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) def two(n): ans = 0 while n % 2 == 0: n //= 2 ans += 1 return ans print(max([two(i + 1) for i in range(N)]))
s785426336
Accepted
17
2,940
183
N = int(input()) def two(n): ans = 0 while n % 2 == 0: n //= 2 ans += 1 return ans ans = [two(i + 1) for i in range(N)] print(ans.index(max(ans)) + 1)
s149276689
p02646
u736981539
2,000
1,048,576
Wrong Answer
25
9,180
160
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) if V==W: print("NO") elif (B-A)/(V-W) >= T: print("YES") else: print("NO")
s079002341
Accepted
20
9,184
167
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) if V <= W: print("NO") elif abs((B-A))/(V-W) <= T: print("YES") else: print("NO")
s483686042
p03699
u021877437
2,000
262,144
Wrong Answer
18
3,060
280
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
N = int(input().rstrip()) a = [] for i in range(N): a.append(int(input().rstrip())) a.sort() total = sum(a) if (a[i] % 10) == 0: for i in range(N): if (a[i] % 10) != 0: total = total - a[i] break print(0 if (total % 10) == 0 else total)
s036291309
Accepted
18
3,060
281
N = int(input().rstrip()) a = [] for i in range(N): a.append(int(input().rstrip())) a.sort() total = sum(a) if (total % 10) == 0: for i in range(N): if (a[i] % 10) != 0: total = total - a[i] break print(0 if (total % 10) == 0 else total)
s740232071
p03854
u360061665
2,000
262,144
Wrong Answer
17
3,316
252
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S = input() temp = ['dream', 'dreamer', 'erase', 'eraser'] while(1): for i in temp: if S.startswith(i): S = S.lstrip(i) break else: break print(S) if len(S) == 0: print('YES') else: print('NO')
s309166738
Accepted
18
3,188
150
S = input().replace('eraser', '').replace( 'erase', '').replace('dreamer', '').replace('dream', '') if S: print('NO') else: print('YES')
s992263888
p02272
u918457647
1,000
131,072
Wrong Answer
30
7,684
610
Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right)
def merge(a, left, mid, right): global cnt l = a[left:mid] + [10**9 + 1] r = a[mid:right] + [10**9 + 1] i = 0 j = 0 for k in range(left, right): cnt += 1 if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 def mergesort(a, left, right): if left+1 < right: mid = (left + right)//2 mergesort(a, left, mid) mergesort(a, mid, right) merge(a, left, mid, right) pass n = int(input()) S = list(map(int, input().split())) cnt = 0 mergesort(S, 0, n) print(S) print(cnt)
s945920020
Accepted
4,350
63,764
611
def merge(a, left, mid, right): global cnt l = a[left:mid] + [10**9 + 1] r = a[mid:right] + [10**9 + 1] i = 0 j = 0 for k in range(left, right): cnt += 1 if l[i] <= r[j]: a[k] = l[i] i += 1 else: a[k] = r[j] j += 1 def mergesort(a, left, right): if left+1 < right: mid = (left + right)//2 mergesort(a, left, mid) mergesort(a, mid, right) merge(a, left, mid, right) pass n = int(input()) S = list(map(int, input().split())) cnt = 0 mergesort(S, 0, n) print(*S) print(cnt)
s041265265
p02850
u202570162
2,000
1,048,576
Wrong Answer
2,106
39,492
814
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.
# TLE? N = int(input()) T = [[]for i in range(N)] Eo = [] for i in range(N-1): a,b = map(int,input().split()) T[a-1].append(b-1) T[b-1].append(a-1) Eo.append((a-1,b-1)) Eo = tuple(Eo) K = 0 for i in range(N): K = max(len(T[i]),K) P = [-1 for i in range(N)] for i in range(N): for j in T[i]: if P[j] == -1: P[j] = i from collections import deque q = deque(T[0]) E = [] flag = [] num = 0 while q: i = q.popleft() if i != P[i] and not (tuple(sorted([i,P[i]])) in tuple(flag)): flag.append(tuple(sorted([i,P[i]]))) E.append((tuple(sorted([i,P[i]])),num)) num =(num+1)%K for j in T[i]: q.append(j) ans = [-1 for i in range(N-1)] for i,j in E: print(i,j) ans[Eo.index(i)] = j print(K) for i in ans: print(i+1)
s153679487
Accepted
790
50,840
628
N = int(input()) AB =[] V = [[] for _ in range(N)] Edict = dict() for _ in range(N-1): a,b = map(int,input().split()) AB.append((a-1,b-1)) V[a-1].append(b-1) V[b-1].append(a-1) K = max(len(V[i]) for i in range(N)) for i in V: i.sort() for i,v in enumerate(V[0]): Edict[(0,v)] = i for i in range(1,N): # 2(N-1) color = 0 for j in V[i]: if j < i: # unique per V and first parent_color = Edict[(j,i)] else: if color == parent_color: color += 1 Edict[(i,j)] = color color += 1 print(K) for i in AB: print(Edict[i]+1)
s204380237
p03737
u652656291
2,000
262,144
Wrong Answer
17
2,940
84
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
a,b,c = map(str,input().split()) a.upper() b.upper() c.upper() print(a[0]+b[0]+c[0])
s264688288
Accepted
17
2,940
97
a,b,c = map(str,input().split()) a = a.upper() b = b.upper() c = c.upper() print(a[0]+b[0]+c[0])
s134756392
p03861
u962819039
2,000
262,144
Wrong Answer
18
2,940
54
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()) print(b//x - a//x)
s989693338
Accepted
20
2,940
92
a, b, x = map(int, input().split()) c = 0 if a % x == 0: c += 1 print(b // x - a // x + c)
s595789261
p03637
u140672616
2,000
262,144
Wrong Answer
63
11,100
322
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
n = int(input()) a = map(int, input().split(" ")) point = 0 for i in a: if i % 4 == 0: point += 2 elif i % 2 == 0: point += 1 if n % 2 == 1: if n <= point + 1: print("YES") else: print("NO") else: if n <= point: print("YES") else: print("NO")
s773627644
Accepted
64
11,100
319
n = int(input()) a = map(int, input().split(" ")) point = 0 for i in a: if i % 4 == 0: point += 2 elif i % 2 == 0: point += 1 if n % 2 == 1: if n <= point + 1: print("Yes") else: print("No") else: if n <= point: print("Yes") else: print("No")
s963812331
p04011
u183840468
2,000
262,144
Wrong Answer
19
3,060
168
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,k = [int(input()) for _ in range(2)] x,y = [int(input()) for _ in range(2)] ans = 0 for i in range(n): if i <= k: ans += x else: ans += y print(ans)
s210097554
Accepted
19
2,940
172
n,k = [int(input()) for _ in range(2)] x,y = [int(input()) for _ in range(2)] ans = 0 for i in range(1,n+1): if i <= k: ans += x else: ans += y print(ans)
s868024824
p03658
u371530330
2,000
262,144
Wrong Answer
17
2,940
94
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n,k = map(int, input().split()) l = map(int, input().split()) x = sorted(l) print(sum(x[k:]))
s559924715
Accepted
17
2,940
101
n,k = map(int, input().split()) l = list(map(int, input().split())) x = sorted(l) print(sum(x[n-k:]))
s417684624
p03860
u546853743
2,000
262,144
Wrong Answer
18
2,940
33
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[0]","C")
s225771100
Accepted
17
2,940
24
print("A%sC"%input()[8])
s028943061
p03449
u007886915
2,000
262,144
Wrong Answer
159
13,892
10,015
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
# -*- coding: utf-8 -*- import sys import fractions import copy import bisect import math import numpy as np import itertools from itertools import combinations_with_replacement #w=input() from operator import itemgetter from sys import stdin from operator import mul from functools import reduce from collections import Counter #from collections import deque #input = stdin.readline j=0 k=0 n=3 r=1 a=[0] #n=int(input()) #r=int(input()) #print(M) #A=int(input()) #B=int(input()) #print(N) "1行1つの整数を入力を取得し、整数と取得する" #print(number_list) "12 21 332 とか入力する時に使う" "1行に複数の整数の入力を取得し、整数として扱う" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #print(type(brray[0][0])) #print(brray) "列数に関して自由度の高いint型の値を入力するタイプの行列" ''' table = [[int(i) for i in input().split()] for m in range(m)] print(type(N)) print(N) print(type(M)) print(M) print(type(table)) print(table) ''' #s=input() #print(a[0]) #print([a]) #a= stdin.readline().rstrip() #print(a.upper()) "aという変数に入っているものを大文字にして出力" #a=[[int(i) for i in 1.strip()]for 1 in sys.stdin] #a = [[int(c) for c in l.strip()] for l in sys.stdin]] #print(a) ############################################################################################## ############################################################################################## #under this line explains example calculation #nCr combination ''' def cmb(n,r): #When n < r , this function isn't valid r= min(n-r,r) #print(n,r) if r == 0: return 1 over = reduce(mul, range(n, n-r, -1)) #flochart mul(n,n-1)=x #next mul(x,n-2)........(n-r+1,n-r) #mul read a,b and returns a*b under = reduce(mul, range(1, r+1)) #print(over, under) #reduce is applied mul(1,2)=2 #next mul(2,3)=6 #next mul(6,4)=4.........last(r!,r+1)=r+1! return over // under #// is integer divide #calc example 5C2 #over=5*4*3 #under=3*2*1 a = cmb(n, r) #print(a) ''' #A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6] #print(A) #A.insert(index, 5) #print(index) #print(A) def is_prime(n): if n == 1: return False for k in range(2, int(np.sqrt(n)) + 1): if n % k == 0: return False return True ######################################################################## ######################################################################## #print(b2) #print(b3) def main(): w=1 j=0 k=0 dppp=[] n=int(input()) a12=[list(map(int, input().split(" ")))for i in range(2)] for i in range(n): dppp.append(sum(a12[0][:i])+sum(a12[1][i:])) print(max(dppp)) #dpppp[i]=sum(a12[]) #a1li=list(map(int, input().split(" "))) #a2li=list(map(int, input().split(" "))) #r=int(input()) DP = np.zeros(w+1, dtype=int) exdp=np.zeros((3,4)) # a, b = map(int, input().split()) #dp[i][0] += [a] # dp[i] += [a] # dp[i] += [b] #print(dp) "1行1つの整数を入力を取得し、整数と取得する" #print(number_list) "12 21 332 とか入力する時に使う" "1行に複数の整数の入力を取得し、整数として扱う" #print(brray) #s=input() #int取るとstrでも行ける #print(a) pin_l=["x" for i in range(10)] #print(pin_l) ls = ["a", "b", "c", "d", "e"] #print(ls[2:5]) #print(ls[:-3]) #print(ls[:4:2]) #print(ls[::2]) if __name__ == "__main__": main()
s981489976
Accepted
157
13,640
10,142
# -*- coding: utf-8 -*- import sys import fractions import copy import bisect import math import numpy as np import itertools from itertools import combinations_with_replacement #w=input() from operator import itemgetter from sys import stdin from operator import mul from functools import reduce from collections import Counter #from collections import deque #input = stdin.readline j=0 k=0 n=3 r=1 a=[0] #n=int(input()) #r=int(input()) #print(M) #A=int(input()) #B=int(input()) #print(N) "1行1つの整数を入力を取得し、整数と取得する" #print(number_list) "12 21 332 とか入力する時に使う" "1行に複数の整数の入力を取得し、整数として扱う" '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #print(type(brray[0][0])) #print(brray) "列数に関して自由度の高いint型の値を入力するタイプの行列" ''' table = [[int(i) for i in input().split()] for m in range(m)] print(type(N)) print(N) print(type(M)) print(M) print(type(table)) print(table) ''' #s=input() #print(a[0]) #print([a]) #a= stdin.readline().rstrip() #print(a.upper()) "aという変数に入っているものを大文字にして出力" #a=[[int(i) for i in 1.strip()]for 1 in sys.stdin] #a = [[int(c) for c in l.strip()] for l in sys.stdin]] #print(a) ############################################################################################## ############################################################################################## #under this line explains example calculation #nCr combination ''' def cmb(n,r): #When n < r , this function isn't valid r= min(n-r,r) #print(n,r) if r == 0: return 1 over = reduce(mul, range(n, n-r, -1)) #flochart mul(n,n-1)=x #next mul(x,n-2)........(n-r+1,n-r) #mul read a,b and returns a*b under = reduce(mul, range(1, r+1)) #print(over, under) #reduce is applied mul(1,2)=2 #next mul(2,3)=6 #next mul(6,4)=4.........last(r!,r+1)=r+1! return over // under #// is integer divide #calc example 5C2 #over=5*4*3 #under=3*2*1 a = cmb(n, r) #print(a) ''' #A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6] #print(A) #A.insert(index, 5) #print(index) #print(A) def is_prime(n): if n == 1: return False for k in range(2, int(np.sqrt(n)) + 1): if n % k == 0: return False return True ######################################################################## ######################################################################## #print(b2) #print(b3) def main(): w=1 j=0 k=0 dppp=[] n=int(input()) a12=[list(map(int, input().split(" ")))for i in range(2)] for i in range(n): #print(i) #print(sum(a12[0][0:i+1]),sum(a12[1][i:n])) dppp.append(sum(a12[0][:i+1])+sum(a12[1][i:n] )) print(max(dppp)) #dpppp[i]=sum(a12[]) #a1li=list(map(int, input().split(" "))) #a2li=list(map(int, input().split(" "))) #r=int(input()) DP = np.zeros(w+1, dtype=int) exdp=np.zeros((3,4)) # a, b = map(int, input().split()) #dp[i][0] += [a] # dp[i] += [a] # dp[i] += [b] #print(dp) "1行1つの整数を入力を取得し、整数と取得する" #print(number_list) "12 21 332 とか入力する時に使う" "1行に複数の整数の入力を取得し、整数として扱う" #print(brray) #s=input() #int取るとstrでも行ける #print(a) pin_l=["x" for i in range(10)] #print(pin_l) ls = ["a", "b", "c", "d", "e"] #print(ls[2:5]) #print(ls[:-3]) #print(ls[:4:2]) #print(ls[::2]) if __name__ == "__main__": main()
s597133758
p02697
u948911484
2,000
1,048,576
Wrong Answer
71
9,280
68
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
n,m = map(int,input().split()) for i in range(m): print(i+1,2*m-i)
s037779867
Accepted
74
9,144
242
n,m = map(int,input().split()) ans=[] if m%2==1: for i in range(m//2): print(i+1,m-i) for i in range(m//2+1): print(m+1+i,2*m+1-i) else: for i in range(m//2): print(i+1,m-i+1) for i in range(m//2): print(m+2+i,2*m+1-i)
s247865710
p03555
u749770850
2,000
262,144
Wrong Answer
17
2,940
122
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 = [input() for _ in range(2)] if c[0][1] == c[1][1] and sorted(c[0]) == sorted(c[1]): print("Yes") else: print("No")
s277176075
Accepted
17
2,940
150
c = [input() for _ in range(2)] if c[0][1] == c[1][1] and c[0][0] == c[1][2] and c[0][2] == c[1][0]: print("YES") exit() else: print("NO") exit()
s073091862
p03609
u301302814
2,000
262,144
Wrong Answer
17
2,940
67
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
# coding: utf-8 x, t = map(int, input().split()) print(min(x-t, 0))
s240163165
Accepted
17
2,940
67
# coding: utf-8 x, t = map(int, input().split()) print(max(x-t, 0))
s994445654
p03943
u475966842
2,000
262,144
Wrong Answer
17
2,940
92
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a,b,c=input().split() if a+b==c or a+c==b or b+c==a : print("Yes") else: print("No")
s184227431
Accepted
18
2,940
120
a,b,c=input().split() a=int(a) b=int(b) c=int(c) if a+b==c or a+c==b or b+c==a : print("Yes") else: print("No")
s391190831
p03556
u785989355
2,000
262,144
Wrong Answer
338
20,380
60
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.
import numpy as np N=int(input()) print(int(np.sqrt(N)))
s203151215
Accepted
28
2,940
87
N=int(input()) for i in range(1,10**5): if i**2>N: break print((i-1)**2)
s807140647
p03563
u395287676
2,000
262,144
Wrong Answer
17
3,064
3,286
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
import sys def main(): # Get Args args = _input_args() # get arguments as an array from console/script parameters. # Call main Logic result = _main(args) # Output a result in a correct way. _output_result(result) def _main(args): """Write Main Logic here for the contest. :param args: arguments :type args: list :return: result :rtype: depends on your logic. """ # Extract arguments. Sd = args[0] T = args[1] # Write main logic here. result = _fit_partial_strings(Sd, T) # Return something. return result def _fit_partial_strings(Sd, T): for i in range(len(Sd)): for j in range(len(T)): if Sd[i] == T[j]: if len(Sd) - i >= len(T) - j: # enough space available? offset = i - j Sd_list = list(Sd) # convert str to list for operation for k in range(len(T)): Sd_list[k + offset] = T[k] # patch T to Sd Sd = "".join(Sd_list) # convert list to str else: return 'UNRESTORABLE' if Sd.count('?') == 1: Sd = Sd.replace('?', 'a') return Sd return 'UNRESTORABLE' def _input_args(): # Comment-out appropriate pattern depends on subject. # arguments = sys.argv[1:] # ptn1: get args from script parameters. # arguments = _input().split() # ptn2: get args from 1 line console prompt with space separated. # for multi-line console input, use this. arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2) # Cast elements If you need. # arguments = list(map(int, arguments)) # cast elements to int for example. return arguments # This will be array. def _input(): # If Subject requires interactive input, use this and patch mock in unittest. return input() def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2): """Get arguments from multiple lines standard input. :param end_of_lines_char: Strings that indicate the end of lines. :type end_of_lines_char: list of str :param limit: If a number of the input line are certain, you can use this param to close prompt immediately. :type limit: int :return: args :rtype list of str """ args = [] for i in range(limit): try: arg = _input() if arg in end_of_lines_char: break args.append(arg) except EOFError: # Supports EOF Style. (Very Rare case) break return args def _output_result(result): # Comment-out appropriate output pattern depends on subject. # sys.stdout.write(result) # No Line Feed, and an result must be string (not useful). for single value output. # print(result) # The result will cast to strings. Line feed will be appended to the end. for single value output. # print(result, end='') # Same as above except Line Feed won't be appended. for single value output. # print(','.join(map(str, result))) # Print array elements as comma separated strings. for multi-value. print('{}'.format(str(result))) # Same as above, but more versatile. if __name__ == '__main__': main()
s812405423
Accepted
17
3,064
2,449
import sys def main(): # Get Args args = _input_args() # get arguments as an array from console/script parameters. # Call main Logic result = _main(args) # Export a result in a correct way. _export_result(result) def _main(args): """Write Main Logic here for the contest. :param args: arguments :type args: list :return: result :rtype: depends on your logic. """ # Extract arguments. R = int(args[0]) G = int(args[1]) # Write main logic here. X = (2 * G) - R # Return something. return X def _input_args(): # Comment-out appropriate pattern depends on subject. # arguments = sys.argv[1:] # ptn1: get args from script parameters. # arguments = _input().split() # ptn2: get args from 1 line console prompt with space separated. # for multi-line console input, use this. arguments = _get_args_from_multiple_lines(end_of_lines_char=['']) # Cast elements If you need. # arguments = list(map(int, arguments)) # cast elements to int for example. return arguments # This will be array. def _input(): # If Subject requires interactive input, use this and patch mock in unittest. return input() def _get_args_from_multiple_lines(end_of_lines_char=['']): """Get arguments from multiple lines standard input. :param end_of_lines_char: Strings that indicate the end of lines. :type end_of_lines_char: list of str :return: args :rtype list of str """ args = [] while True: try: arg = _input() if arg in end_of_lines_char: break args.append(arg) except EOFError: # Supports EOF Style. (Very Rare case) break return args def _export_result(result): # Comment-out appropriate output pattern depends on subject. # sys.stdout.write(result) # No Line Feed, and an result must be string (not useful). for single value output. # print(result) # The result will cast to strings. Line feed will be appended to the end. for single value output. # print(result, end='') # Same as above except Line Feed won't be appended. for single value output. # print(','.join(map(str, result))) # Print array elements as comma separated strings. for multi-value. print('{}'.format(str(result))) # Same as above, but more versatile. if __name__ == '__main__': main()
s518260211
p03370
u538956308
2,000
262,144
Wrong Answer
17
2,940
139
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.
N,X = map(int,input().split()) D = [] for i in range(N): d = int(input()) D.append(d) a = X//sum(D) b = X%sum(D)//min(D) print(a+b)
s830524817
Accepted
17
2,940
142
N,X = map(int,input().split()) D = [] for i in range(N): d = int(input()) D.append(d) a = X-sum(D) b = len(D) c = a//min(D) print(b+c)
s684139700
p03556
u994521204
2,000
262,144
Wrong Answer
17
2,940
52
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.
import math a=int(input()) print(math.floor(a**0.5))
s499877533
Accepted
17
2,940
57
import math a=int(input()) print((math.floor(a**0.5))**2)
s304899238
p02417
u395334793
1,000
131,072
Wrong Answer
20
7,408
246
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
import sys cs = { c : 0 for c in list("abcdefghijklmnopqrstuvwxyz")} for c in list(sys.stdin.read()): c = c.lower() if c in cs.keys(): cs[c] = cs[c] + 1 for (c,cnt) in sorted(list(cs.items())): print('[0] : [1]'.format(c,cnt))
s548897686
Accepted
30
7,432
246
import sys cs = { c : 0 for c in list("abcdefghijklmnopqrstuvwxyz")} for c in list(sys.stdin.read()): c = c.lower() if c in cs.keys(): cs[c] = cs[c] + 1 for (c,cnt) in sorted(list(cs.items())): print('{0} : {1}'.format(c,cnt))
s411765193
p03761
u232733545
2,000
262,144
Wrong Answer
23
3,444
257
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
from collections import Counter as cn d=int(input()) l = [] for k in range(d): p = cn(input()) l.append(p) oi = l[0] for g in range(len(l)): oi = oi & l[g] print(oi) print("".join(sorted(oi.elements())))
s313422014
Accepted
22
3,444
236
from collections import Counter d = int(input()) l = [] for k in range(d): r = input() l.append(Counter(r)) oi = l[0] for g in range(1,d): oi = oi & l[g] print("".join(sorted(oi.elements())))
s330672591
p02260
u058433718
1,000
131,072
Wrong Answer
20
7,636
519
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
import sys def selection_sort(nums, n): cnt = 0 for i in range(n): minj = i for j in range(i, n): if nums[j] < nums[minj]: minj = j if i != minj: nums[i], nums[minj] = nums[minj], nums[i] cnt += 1 print(cnt) def main(): n = int(sys.stdin.readline().strip()) data = sys.stdin.readline().strip().split(' ') nums = [int(i) for i in data] selection_sort(nums, n) if __name__ == '__main__': main()
s023515229
Accepted
20
7,772
559
import sys def selection_sort(nums, n): cnt = 0 for i in range(n): minj = i for j in range(i, n): if nums[j] < nums[minj]: minj = j nums[i], nums[minj] = nums[minj], nums[i] if i != minj: cnt += 1 print(' '.join([str(i) for i in nums])) print(cnt) def main(): n = int(sys.stdin.readline().strip()) data = sys.stdin.readline().strip().split(' ') nums = [int(i) for i in data] selection_sort(nums, n) if __name__ == '__main__': main()
s502682278
p03997
u457957084
2,000
262,144
Wrong Answer
17
2,940
75
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)
s634711218
Accepted
17
2,940
81
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h / 2))
s589496022
p02646
u609176437
2,000
1,048,576
Wrong Answer
21
9,184
180
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
a,v = map(int,input().split()) b,w = map(int,input().split()) t = int(input()) coordinate_ab = b-a speed_ab = w-v if coordinate_ab < speed_ab * t: print("YES") else:print("NO")
s906982222
Accepted
21
9,168
141
a,v = map(int,input().split()) b,w = map(int,input().split()) t = int(input()) if (v-w)*t >= abs(b-a): print("YES") else: print("NO")
s921307695
p03494
u085334230
2,000
262,144
Wrong Answer
32
2,940
247
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
N = int(input()) A = list(map(int,input().split())) j = True count = 0 while j: for i in A: if i % 2 == 0: A[A.index(i)] = i / 2 else: j = False count += 1 print(count)
s171545440
Accepted
32
3,060
290
N = int(input()) A = list(map(int,input().split())) j = True count = 0 while j : for i in A: if i % 2 == 0 or i == 0: A[A.index(i)] = i / 2 else: j = False if j == True: count += 1 print(count)
s499864871
p02743
u732870425
2,000
1,048,576
Wrong Answer
17
2,940
120
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a, b, c = map(int, input().split()) if a ** 0.5 + b ** 0.5 > c ** 0.5: ans = "Yes" else: ans = "No" print(ans)
s685016167
Accepted
17
3,068
174
a, b, c = map(int, input().split()) if c - a - b > 0: if 4 * a * b < (c - a - b) ** 2: ans = "Yes" else: ans = "No" else: ans = "No" print(ans)
s301709358
p03854
u816428863
2,000
262,144
Wrong Answer
19
3,188
159
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
S=input() S=S.replace("eraser","") S=S.replace("erase","") S=S.replace("dreamer","") S=S.replace("dream","") if S=="": print("Yes") else: print("No")
s959798379
Accepted
18
3,188
159
S=input() S=S.replace("eraser","") S=S.replace("erase","") S=S.replace("dreamer","") S=S.replace("dream","") if S=="": print("YES") else: print("NO")
s798044546
p00001
u897625141
1,000
131,072
Wrong Answer
30
7,500
135
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
Array = [] for i in range(10): Array.append(int(input())) Anum = len(Array) for i in range(Anum-1,Anum-4,-1): print(Array[i])
s224429001
Accepted
30
7,636
98
array = [int(input()) for i in range(10)] array.sort() for i in range(9,6,-1): print(array[i])
s446888606
p03474
u077019541
2,000
262,144
Wrong Answer
17
2,940
137
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
A,B = map(int,input().split()) S = [i for i in input().split()] if len(S[0])==A and len(S[1])==B: print("Yes") else: print("No")
s421794753
Accepted
17
2,940
140
A,B = map(int,input().split()) S = [i for i in input().split("-")] if len(S[0])==A and len(S[1])==B: print("Yes") else: print("No")
s037931982
p03860
u821251381
2,000
262,144
Wrong Answer
17
2,940
25
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.
print("A"+input()[0]+"C")
s320687500
Accepted
17
2,940
36
print("A"+input().split()[1][0]+"C")
s438348558
p03455
u863478942
2,000
262,144
Wrong Answer
17
2,940
88
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()) if a * b % 2 == 0: print("Odd") else: print("Even")
s006452711
Accepted
17
2,940
88
a, b = map(int, input().split()) if a * b % 2 == 0: print("Even") else: print("Odd")
s793972981
p02796
u960080897
2,000
1,048,576
Wrong Answer
491
20,104
253
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
N = int(input()) robot = [] ans = 0 for i in range(N): x,l = map(int,input().split()) robot.append([x-l,x+l]) robot.sort() cur = -float('inf') for i in range(N): if cur <= robot[i][1]: ans += 1 cur = robot[i][0] print(ans)
s193395569
Accepted
519
20,104
253
N = int(input()) robot = [] ans = 0 for i in range(N): x,l = map(int,input().split()) robot.append([x+l,x-l]) robot.sort() cur = -float('inf') for i in range(N): if cur <= robot[i][1]: ans += 1 cur = robot[i][0] print(ans)
s184813134
p03698
u044746696
2,000
262,144
Wrong Answer
17
2,940
50
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=input() print('yes' if len(s)==set(s) else 'no')
s714871905
Accepted
17
2,940
55
s=input() print('yes' if len(s)==len(set(s)) else 'no')
s133290491
p03386
u916806287
2,000
262,144
Wrong Answer
2,104
2,940
118
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a, b, k = map(int, input().split()) result = [i for i in range(a, b+1) if i <= (a + k) or (b - k) <= i] print(result)
s061312669
Accepted
17
3,064
293
a, b, k = map(int, input().split()) if a + k > b: a_k = b else: a_k = a + k if b - k < a: b_k = a else: b_k = b - k if a == b: a_k = a + 1 b_k = b + 1 result = list(set([i for i in range(a, a_k)] + [i for i in range(b_k + 1, b + 1)])) result.sort() for n in result: print(n)
s897238053
p02394
u533681846
1,000
131,072
Wrong Answer
20
5,596
106
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 r<x & r<y & x<W-r & y<H-r: print("Yes") else: print("No")
s686380040
Accepted
20
5,596
120
W,H,x,y,r = map(int,input().split()) if r<=x and r<=y and x<=(W-r) and y<=(H-r): print("Yes") else: print("No")
s066663804
p02678
u952773501
2,000
1,048,576
Wrong Answer
2,213
227,700
662
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, m = map(int, input().split()) abj = [set() for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a, b = a-1, b-1 abj[a].add(b) abj[b].add(a) def bfs_paths(graph, start, goal): queue = [(start, [start])] result = [] while queue: n, path = queue.pop(0) if n == goal: result.append(path) else: for m in graph[n] - set(path): queue.append((m, path + [m])) return result if all([bfs_paths(abj, i, 0)[0][-1] == 0 for i in range(n)]): print('yes') for i in range(1,n): print(bfs_paths(abj, i, 0)[0][1]+1) else: print('No')
s529331168
Accepted
707
37,744
501
from collections import deque n, m = map(int, input().split()) g = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) g[a-1].append(b-1) g[b-1].append(a-1) queue = deque([0]) d = [None]*n d[0] = 0 while queue: v = queue.popleft() for i in g[v]: if d[i] == None: d[i] = v + 1 queue.append(i) if all(type(i) is int for i in d): print('Yes') for i in d[1:]: print(i) else: print('No')
s239508556
p03827
u599547273
2,000
262,144
Wrong Answer
17
2,940
77
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).
n,s=map(input,"aa");print(max(s[:i].count("I")*2-i for i in range(int(n)+1)))
s343573766
Accepted
17
2,940
77
n,s=input(),input();print(max(s[:i].count("I")*2-i for i in range(int(n)+1)))
s708169315
p03493
u626468554
2,000
262,144
Wrong Answer
17
2,940
176
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) n = list(input()) cnt =0 for i in range(3): if n[i]==1: cnt += 1 print(cnt)
s367183182
Accepted
17
2,940
178
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) n = list(input()) cnt =0 for i in range(3): if n[i]=="1": cnt += 1 print(cnt)
s304775806
p01085
u546285759
8,000
262,144
Wrong Answer
110
7,584
216
The International Competitive Programming College (ICPC) is famous for its research on competitive programming. Applicants to the college are required to take its entrance examination. The successful applicants of the examination are chosen as follows. * The score of any successful applicant is higher than that of any unsuccessful applicant. * The number of successful applicants _n_ must be between _n_ min and _n_ max, inclusive. We choose _n_ within the specified range that maximizes the _gap._ Here, the _gap_ means the difference between the lowest score of successful applicants and the highest score of unsuccessful applicants. * When two or more candidates for _n_ make exactly the same _gap,_ use the greatest _n_ among them. Let's see the first couple of examples given in Sample Input below. In the first example, _n_ min and _n_ max are two and four, respectively, and there are five applicants whose scores are 100, 90, 82, 70, and 65. For _n_ of two, three and four, the gaps will be 8, 12, and 5, respectively. We must choose three as _n_ , because it maximizes the gap. In the second example, _n_ min and _n_ max are two and four, respectively, and there are five applicants whose scores are 100, 90, 80, 75, and 65. For _n_ of two, three and four, the gap will be 10, 5, and 10, respectively. Both two and four maximize the gap, and we must choose the greatest number, four. You are requested to write a program that computes the number of successful applicants that satisfies the conditions.
while 1: m,nn,nx= map(int,input().split()) if m==0: break s=[int(input()) for _ in range(m)] v=k=0 for i in range(nn-1,nx): t=s[i]-s[i+1] if v<t: k,v=i+1,t print(k)
s173878269
Accepted
130
5,624
294
while True: m, n_min, n_max = map(int, input().split()) if m == 0: break p = [int(input()) for _ in range(m)] ans = tmp = 0 for i in range(n_min, n_max+1): hoge = p[i-1] - p[i] if tmp <= hoge: tmp = hoge ans = i print(ans)
s750851909
p03609
u346629192
2,000
262,144
Wrong Answer
17
2,940
48
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
X,t = map(int,input().split()) print(min(0,X-t))
s781290388
Accepted
17
3,064
48
X,t = map(int,input().split()) print(max(0,X-t))
s500945177
p03455
u756464404
2,000
262,144
Wrong Answer
18
2,940
93
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
def product_judge(a,b): c = a*b if c % 2 == 0: print("Even") else: print("Odd")
s318850180
Accepted
17
2,940
84
a,b = map(int,input().split()) if a*b % 2 == 0: print("Even") else: print("Odd")
s179293903
p03495
u710921979
2,000
262,144
Wrong Answer
54
20,228
148
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
import collections N,K=map(int,input().split()) c=sorted(collections.Counter(ball=list(map(str,input().split()))).values()) print(sum(c[:len(c)-K]))
s393128412
Accepted
102
35,996
137
import collections N,K=map(int,input().split()) c=sorted(collections.Counter(list(map(str,input().split()))).values()) print(sum(c[:-K]))
s895880476
p02412
u634490486
1,000
131,072
Wrong Answer
20
5,600
341
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
from sys import stdin while True: n, x = [int(x) for x in stdin.readline().rstrip().split()] if n == 0 and x == 0: break else: count = 0 for i in range(1, n-1): for j in range(i+1, n-2): if j < x-i-j <= n: count += 1 else: print(count)
s009559354
Accepted
40
5,608
339
from sys import stdin while True: n, x = [int(x) for x in stdin.readline().rstrip().split()] if n == 0 and x == 0: break else: count = 0 for i in range(1, n-1): for j in range(i+1, n): if j < x-i-j <= n: count += 1 else: print(count)
s503922479
p03502
u928385607
2,000
262,144
Wrong Answer
17
2,940
237
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
n= int(input()) nn = n f = 0 while nn != 0: f = f + nn % 10 nn = int( nn / 10) if n%f == 0: print('YES') else: print('NO')
s173582844
Accepted
17
3,060
237
n= int(input()) nn = n f = 0 while nn != 0: f += int(nn % 10) nn = int(nn/10) if n%f == 0: print('Yes') else: print('No')
s807160580
p03962
u451017206
2,000
262,144
Wrong Answer
17
2,940
37
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
print(len(set([i for i in input()])))
s202798219
Accepted
17
2,940
45
print(len(set([i for i in input().split()])))
s720303279
p02413
u510829608
1,000
131,072
Wrong Answer
20
7,504
117
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
n, m = map(int, input().split()) for i in range(n): a = list(map(int, input().split())) a.append(sum(a)) print(*a)
s208890749
Accepted
30
8,356
269
n, m = map(int, input().split()) li = [list(map(int,input().split())) for i in range(n)] c = [] for i in range(n): li[i].append(sum(li[i])) for j in range(m+1): t = 0 for i in range(n): t += li[i][j] c.append(t) li.append(c) for i in range(n+1): print(*li[i])
s584537198
p02413
u711765449
1,000
131,072
Wrong Answer
30
7,772
499
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
r,c = map(int,input().split(' ')) arr = [[0 for i in range(c+1)] for i in range(r+1)] for i in range(r): row = list(map(int,input().split(' '))) for j in range(c): arr[i][j] = row[j] for i in range(r): for j in range(c): arr[i][-1] += arr[i][j] for i in range(c): for j in range(r): arr[-1][i] += arr[j][i] for i in range(r+1): arr[-1][-1] += arr[-1][i] for i in range(c): for j in range(r): print(arr[i][j],end = ' ') print(arr[i][-1])
s597119797
Accepted
40
8,428
662
r,c = map(int,input().split(' ')) arr = [[0 for i in range(c+1)] for i in range(r+1)] for i in range(r): row = list(map(int,input().split(' '))) for j in range(c): arr[i][j] = row[j] for i in range(r): for j in range(c): arr[i][-1] += arr[i][j] for i in range(c): for j in range(r): arr[-1][i] += arr[j][i] if c == 1: for i in range(r): arr[-1][-1] += arr[i][0] elif r == 1: for i in range(c): arr[-1][-1] += arr[0][i] else: for i in range(r): arr[-1][-1] += arr[i][-1] for i in range(r+1): for j in range(c): print(arr[i][j],end = ' ') print(arr[i][-1])
s683024417
p03693
u024442309
2,000
262,144
Wrong Answer
17
2,940
91
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) if (r*100+g*10+b)%4: print('No') else: print('Yes')
s287527601
Accepted
17
2,940
91
r, g, b = map(int, input().split()) if (r*100+g*10+b)%4: print('NO') else: print('YES')
s163736084
p03435
u506858457
2,000
262,144
Wrong Answer
29
9,112
189
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.
a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g,h,i=map(int,input().split()) if a+e==b+d: if b+f==c+e: if d+h==e+g: if e+i==f+h: print('Yes') print('No')
s365766587
Accepted
31
9,072
204
a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g,h,i=map(int,input().split()) if a+e==b+d: if b+f==c+e: if d+h==e+g: if e+i==f+h: print('Yes') exit() print('No')
s036959410
p03557
u706330549
2,000
262,144
Wrong Answer
243
20,064
466
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) a = np.array(readline().split(), dtype=np.int32) b = np.array(readline().split(), dtype=np.int32) c = np.array(readline().split(), dtype=np.int32) a.sort() b.sort() c.sort() cnt_a = np.searchsorted(a, b, side='left') cnt_c = np.searchsorted(c, -b, side='left') answer = (cnt_a * cnt_c).sum() print(answer)
s247581566
Accepted
242
20,064
468
import numpy as np import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(readline()) a = np.array(readline().split(), dtype=np.int32) b = np.array(readline().split(), dtype=np.int32) c = - np.array(readline().split(), dtype=np.int32) a.sort() b.sort() c.sort() cnt_a = np.searchsorted(a, b, side='left') cnt_c = np.searchsorted(c, -b, side='left') answer = (cnt_a * cnt_c).sum() print(answer)
s265714323
p02255
u508054630
1,000
131,072
Wrong Answer
20
5,596
376
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def InsertionSort(A, N): ans = '' i = 1 while i < N: v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v ans += ' '.join(map(str, A)) + '\n' i += 1 return ans[:-1] n = int(input()) A = list(map(int, input().split(' '))) ans = InsertionSort(A, n) print(ans)
s245754284
Accepted
20
5,644
402
def InsertionSort(A, N): ans = ' '.join(map(str, A)) + '\n' i = 1 while i < N: v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v ans += ' '.join(map(str, A)) + '\n' i += 1 return ans[:-1] n = int(input()) A = list(map(int, input().split(' '))) ans = InsertionSort(A, n) print(ans)
s702805840
p03759
u794753968
2,000
262,144
Wrong Answer
17
3,060
70
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()) print("Yes" if b-a == c-b else "No")
s349079369
Accepted
17
2,940
70
a,b,c = map(int, input().split()) print("YES" if b-a == c-b else "NO")
s340017120
p02259
u749243807
1,000
131,072
Wrong Answer
20
5,604
444
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.
count = int(input()); data = [int(n) for n in input().split(" ")]; def bubble_sort(data): show(data); count = len(data); for i in range(count): for j in range(count - 1, i, -1): if data[j] < data[j - 1]: temp = data[j]; data[j] = data[j - 1]; data[j - 1] = temp; show(data); def show(data): print(" ".join(str(n) for n in data)); bubble_sort(data);
s680910922
Accepted
20
5,604
473
count = int(input()); data = [int(n) for n in input().split(" ")]; def bubble_sort(data): count = len(data); o = 0; for i in range(count): for j in range(count - 1, i, -1): if data[j] < data[j - 1]: o += 1; temp = data[j]; data[j] = data[j - 1]; data[j - 1] = temp; show(data); print(o); def show(data): print(" ".join(str(n) for n in data)); bubble_sort(data);
s210123905
p03388
u631277801
2,000
262,144
Wrong Answer
17
3,060
213
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
from math import sqrt, floor import sys sdin = sys.stdin.readline q = int(sdin()) ab = [] for i in range(q): ab.append(tuple(map(int, sdin().split()))) for a, b in ab: print(floor(2 * sqrt(a*b)) - 2)
s420806605
Accepted
18
3,064
862
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int, stdin.readline().split()) def li_(): return map(lambda x: int(x)-1, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from math import sqrt def wc(a:int, b:int) -> int: if a == b: return 2*a - 2 elif abs(a-b) == 1: return 2*min(a,b) - 2 else: c = int(sqrt(a*b)) if a*b == c*c: c -= 1 if a*b > c*(c+1): return 2*c - 1 else: return 2*c - 2 q = ni() query = [tuple(li()) for _ in range(q)] for a,b in query: print(wc(a,b))
s208474498
p03377
u655975843
2,000
262,144
Wrong Answer
17
2,940
94
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int, input().split()) if a <= x and x <= a + b: print('Yes') else: print('No')
s006376784
Accepted
20
3,060
94
a, b, x = map(int, input().split()) if a <= x and x <= a + b: print('YES') else: print('NO')
s184327059
p03997
u610143410
2,000
262,144
Wrong Answer
23
3,064
84
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()) s = ((a + b) * h ) / 2 print(s)
s778322622
Accepted
23
3,064
89
a = int(input()) b = int(input()) h = int(input()) s = ((a + b) * h ) / 2 print(int(s))
s527663521
p03998
u473291366
2,000
262,144
Wrong Answer
17
3,064
350
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A = input() B = input() C = input() a = list(A) b = list(B) c = list(C) state = [a, b, c] player = 0 player_name = ["a", "b", "c"] get_player = {"a": 0, "b":1, "c": 2} while True: if len(state[player]) == 0: print(player_name[player]) exit() next_player_name = state[player].pop(0) player = get_player[next_player_name]
s437133313
Accepted
17
3,060
331
A = input() B = input() C = input() state = [list(A), list(B), list(C)] player = 0 player_name = ["A", "B", "C"] get_player = {"a": 0, "b":1, "c": 2} while True: if len(state[player]) == 0: print(player_name[player]) exit() next_player_name = state[player].pop(0) player = get_player[next_player_name]
s111260720
p02972
u771007149
2,000
1,048,576
Wrong Answer
995
22,796
675
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
#D n = int(input()) a = list(map(int,input().split())) box = [0 for _ in range(n)] result = [] def baisu(n,max_n): ans = [] cnt = 1 while n*cnt <= max_n: ans.append(n*cnt) cnt += 1 return ans for i in range(n-1,-1,-1): if i+1 > n//2: box[i] = a[i] else: num = baisu(i+1,n) tmp = 0 for j in num: tmp += a[j-1] if tmp % 2 == a[i]: box[i] = 0 else: box[i] = 1 for i,j in enumerate(box): if j == 1: result.append(i+1) if result == []: print(0) else: print(len(result)) print(*result)
s775321783
Accepted
1,002
21,684
677
#D n = int(input()) a = list(map(int,input().split())) box = [0 for _ in range(n)] result = [] def baisu(n,max_n): ans = [] cnt = 1 while n*cnt <= max_n: ans.append(n*cnt) cnt += 1 return ans for i in range(n-1,-1,-1): if i+1 > n//2: box[i] = a[i] else: num = baisu(i+1,n) tmp = 0 for j in num: tmp += box[j-1] if tmp % 2 == a[i]: box[i] = 0 else: box[i] = 1 for i,j in enumerate(box): if j == 1: result.append(i+1) if result == []: print(0) else: print(len(result)) print(*result)
s592792121
p03827
u609061751
2,000
262,144
Wrong Answer
17
2,940
217
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).
import sys input = sys.stdin.readline N = int(input()) S = list(input().rstrip()) maxx = -(10 ** 9) x = 0 for i in S: if i == "I": x += 1 else: x -= 1 if x > maxx: maxx = x print(x)
s297315000
Accepted
17
3,060
200
import sys input = sys.stdin.readline N = int(input()) S = list(input().rstrip()) ans = [0] x = 0 for i in S: if i == "I": x += 1 else: x -= 1 ans.append(x) print(max(ans))
s374112321
p02397
u782850499
1,000
131,072
Wrong Answer
40
8,028
202
Write a program which reads two integers x and y, and prints them in ascending order.
a=[] while True: m,n=input().split() if m==n=="0": break else: a.append(sorted([int(m),int(n)])) print(a) for i in range(len(a)): print("{0} {1}".format(a[i][0],a[i][1]))
s321470688
Accepted
50
8,024
193
a=[] while True: m,n=input().split() if m==n=="0": break else: a.append(sorted([int(m),int(n)])) for i in range(len(a)): print("{0} {1}".format(a[i][0],a[i][1]))
s160876996
p02612
u662396511
2,000
1,048,576
Wrong Answer
28
9,144
58
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 -= 1000 print(n)
s612844840
Accepted
29
9,156
77
n = int(input()) if n%1000 == 0: print(0) else: print(1000-(n%1000))
s040279139
p03546
u677121387
2,000
262,144
Time Limit Exceeded
2,108
3,444
699
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
from itertools import permutations h,w = map(int,input().split()) c = [[int(i) for i in input().split()] for _ in range(10)] a = [[int(i) for i in input().split()] for _ in range(h)] ans = 0 lst = [int(i) for i in range(10) if i != 1] mp = [0]*10 for i in lst: mp[i] = c[i][1] for j in range(1,9): for k in permutations(lst,j): newlst = list(k) cnt = c[i][newlst[0]] for l in range(j-1): cnt += c[newlst[l]][newlst[l+1]] cnt += c[newlst[-1]][1] if cnt < mp[i]: mp[i] = cnt for i in range(h): for j in range(w): if abs(a[i][j]) != 1: ans += mp[a[i][j]] print(ans)
s234074289
Accepted
35
3,316
402
h,w = map(int,input().split()) c = [[int(i) for i in input().split()] for _ in range(10)] a = [[int(i) for i in input().split()] for _ in range(h)] for k in range(10): for i in range(10): for j in range(10): c[i][j] = min(c[i][j], c[i][k] + c[k][j]) ans = 0 mp = [c[i][1] for i in range(10)] mp.append(0) for i in range(h): for j in range(w): ans += mp[a[i][j]] print(ans)
s950527047
p02731
u067694718
2,000
1,048,576
Wrong Answer
17
2,940
49
Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L.
a = int(input()) b = a // 3 print(float(b ** 3))
s957531867
Accepted
17
2,940
58
a = int(input()) b = a / 3 print('{:.12f}'.format(b ** 3))
s957688638
p03371
u857673087
2,000
262,144
Wrong Answer
17
3,064
222
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A,B,C,X,Y = map(int,input().split()) plan1 = (A*X) + (B*Y) plan2 = (C*2) * max(X,Y) plan3 = (C*2) * X + B*(Y-X) plan4 = (C*2) * Y + A*(Y-X) if X <= Y: print(min(plan1,plan2,plan3)) else: print(min(plan1,plan2,plan4))
s049085731
Accepted
18
3,060
223
A,B,C,X,Y = map(int,input().split()) plan1 = (A*X) + (B*Y) plan2 = (C*2) * max(X,Y) plan3 = (C*2) * X + B*(Y-X) plan4 = (C*2) * Y + A*(X-Y) if X <= Y: print(min(plan1,plan2,plan3)) else: print(min(plan1,plan2,plan4))
s322472040
p03971
u282228874
2,000
262,144
Wrong Answer
106
4,016
370
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
N,A,B = map(int,input().split()) S = input() a = 0 b = 0 for s in S: if s == 'a': if a+b <= A+B: print("Yes") a += 1 else: a += 1 elif s == 'b': if a+b <= A+B and b <= B: print("Yes") b += 1 else: print("No") b += 1 else: print("No")
s631336243
Accepted
133
4,016
287
N,A,B = map(int,input().split()) S = input() a = 0 b = 0 for s in S: if s == 'a': a += 1 print("Yes" if a+b <= A+B else "No") elif s == 'b': b += 1 print("Yes" if a+b <= A+B and b <= B else "No" ) b = min(b,B) else: print("No")
s698481658
p03485
u456033454
2,000
262,144
Wrong Answer
17
2,940
50
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int, input().split()) print((a+b)//2+1)
s165281368
Accepted
19
3,060
52
a, b = map(int, input().split()) print(-(-(a+b)//2))
s468166541
p02833
u075739430
2,000
1,048,576
Wrong Answer
17
2,940
120
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
n = int(input()) if n % 2 == 1: print(0) exit() n //= 1 res = 0 while n > 0: n //= 5 res += n print(res)
s987298545
Accepted
17
2,940
120
n = int(input()) if n % 2 == 1: print(0) exit() n //= 2 res = 0 while n > 0: n //= 5 res += n print(res)
s648091403
p02612
u314079346
2,000
1,048,576
Wrong Answer
24
8,992
76
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()) for i in range(0,11000,1000): if N<=i: print(int(i-N))
s855663103
Accepted
27
9,084
31
print((1000-int(input()))%1000)
s822317816
p02408
u786891610
1,000
131,072
Wrong Answer
20
5,596
253
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.
n = int(input()) cards = {} for i in range(n): card = input() cards[card] = 1 #print(cards) for c in ['S','H','C','D']: for n in range(1,13): key = c + '' + str(n) if not key in cards: print(key)
s779137958
Accepted
20
5,600
256
n = int(input()) cards = {} for i in range(n): card = input() cards[card] = 1 # print(cards) for c in ['S','H','C','D']: for n in range(1, 14): key = c + ' ' + str(n) if not key in cards: print(key)
s502479734
p02981
u094932051
2,000
1,048,576
Wrong Answer
17
2,940
169
N of us are going on a trip, by train or taxi. The train will cost each of us A yen (the currency of Japan). The taxi will cost us a total of B yen. How much is our minimum total travel expense?
while True: try: N, A, B = map(int, input().split()) if A >= B: print(N*B) else: print(N*A) except: break
s082488143
Accepted
17
2,940
169
while True: try: N, A, B = map(int, input().split()) if N*A >= B: print(B) else: print(N*A) except: break
s109690466
p03007
u306950978
2,000
1,048,576
Wrong Answer
162
21,228
593
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
from collections import deque n = int(input()) a = list(map(int,input().split())) a.sort() d = deque(a) print(sum(a)-2*sum(a[:n//2])) if n % 2 == 1: now = d.pop() for i in range(n-1): if i % 2 == 0: nex = d.popleft() elif i % 2 == 1: nex = d.pop() print(str(nex) + " " + str(now)) now = nex - now elif n % 2 == 0: now = d.popleft() for i in range(n-1): if i % 2 == 0: nex = d.pop() elif i % 2 == 1: nex = d.popleft() print(str(nex) + " " + str(now)) now = nex - now
s636890139
Accepted
190
24,792
883
n = int(input()) a = list(map(int,input().split())) a.sort() aminus = [] aplus = [] p = 0 q = 0 for i in a: if i >= 0: aplus.append(i) p += 1 elif i < 0: aminus.append(i) q += 1 ans = [] cou = 0 if aplus and aminus: now = aminus[0] for i in range(p-1): ans.append((now,aplus[i])) now = now - aplus[i] aminus[0] = now now = aplus[p-1] for i in range(q): ans.append((now,aminus[i])) now = now - aminus[i] cou = now elif aplus: now = aplus[0] for i in range(1,p-1): ans.append((now,aplus[i])) now = now - aplus[i] ans.append((aplus[p-1],now)) cou = aplus[p-1] - now elif aminus: now = aminus[q-1] for i in range(q-1): ans.append((now,aminus[i])) now = now - aminus[i] cou = now print(cou) for i in range(n-1): print(*ans[i])
s164342027
p02617
u571331348
2,000
1,048,576
Wrong Answer
934
9,600
395
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i. For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows: * Let S be the set of the vertices numbered L through R. f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S. Compute \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R).
n = int(input()) ans = 0 for i in range(1,n+1): ans += i*(n-i+1) print(ans) for _ in range(n-1): u,v = map(int, input().split()) if u > v: u,v = v,u ans -= u*(n-v+1) print(ans) print(ans)
s948257313
Accepted
416
9,184
414
# coding: utf-8 n = int(input()) ans = 0 for i in range(1,n+1): ans += i*(n-i+1) #print(ans) for _ in range(n-1): u,v = map(int, input().split()) if u > v: u,v = v,u ans -= u*(n-v+1) #print(ans) print(ans)
s627433988
p03720
u440129511
2,000
262,144
Wrong Answer
18
3,060
172
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
import itertools n,m=map(int,input().split()) ab= [list(input()) for _ in range(m)] ab=list(itertools.chain.from_iterable(ab)) for i in range(1,n+1): print(ab.count(i))
s873341326
Accepted
17
3,060
189
import itertools n,m=map(int,input().split()) ab= [list(map(int,input().split())) for _ in range(m)] ab=list(itertools.chain.from_iterable(ab)) for i in range(1,n+1): print(ab.count(i))
s054608097
p03524
u548624367
2,000
262,144
Wrong Answer
31
9,740
104
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
s = list(input()) a = [s.count('a'),s.count('b'),s.count('c')] print("No" if max(a)-min(a)>1 else "Yes")
s646786301
Accepted
38
9,836
104
s = list(input()) a = [s.count('a'),s.count('b'),s.count('c')] print("NO" if max(a)-min(a)>1 else "YES")
s884414431
p03543
u823885866
2,000
262,144
Wrong Answer
117
27,072
459
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**?
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 li = list(rr()) print('Yes' if len(list(itertools.groupby(li))) > 2 else 'No')
s059873148
Accepted
120
26,912
464
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 s = rr() if s[0] == s[1] == s[2] or s[1] == s[2] == s[3]: print('Yes') else: print('No')
s058939207
p03470
u493491792
2,000
262,144
Wrong Answer
17
2,940
127
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
n=int(input()) lista=[] for i in range(n): lista.append(int(input())) lista=set(lista) print(lista) print(len(lista))
s052171409
Accepted
17
2,940
77
n=int(input()) a=[int(input()) for i in range(n)] print(len(set(a)))
s839320410
p03574
u161703388
2,000
262,144
Wrong Answer
32
3,444
444
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H, W = map(int, input().split()) S = [input() for i in range(H)] offset_h = (-1,-1,-1,0,0,1,1,1) offset_w = (-1,0,1,-1,1,-1,0,1) for h in range(H): for w in range(W): if S[h][w] == "#": print("#", end="") else: bomb = 0 for i,j in zip(offset_h, offset_w): if h+i >= 0 and h+i < H and w+j >=0 and w+j < W and S[h+i][w+j]==".": bomb += 1 print(bomb, end="") print("")
s897716621
Accepted
32
3,444
444
H, W = map(int, input().split()) S = [input() for i in range(H)] offset_h = (-1,-1,-1,0,0,1,1,1) offset_w = (-1,0,1,-1,1,-1,0,1) for h in range(H): for w in range(W): if S[h][w] == "#": print("#", end="") else: bomb = 0 for i,j in zip(offset_h, offset_w): if h+i >= 0 and h+i < H and w+j >=0 and w+j < W and S[h+i][w+j]=="#": bomb += 1 print(bomb, end="") print("")
s904075421
p03474
u629350026
2,000
262,144
Wrong Answer
17
3,064
217
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
a,b=map(int,input().split()) s=str(input()) slist=list(s) temp=slist.count("-") if temp==1 and slist[a]=="-": s.replace("","-") if s.isdecimal()==True: print("Yes") else: print("No") else: print("No")
s943549794
Accepted
18
3,060
219
a,b=map(int,input().split()) s=str(input()) slist=list(s) temp=slist.count("-") if temp==1 and slist[a]=="-": s=s.replace("-","") if s.isdecimal()==True: print("Yes") else: print("No") else: print("No")
s427989068
p03545
u562016607
2,000
262,144
Wrong Answer
18
3,060
173
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
import itertools S=input() TT=itertools.product(["+","-"],repeat=3) for T in TT: A=S[0]+T[0]+S[1]+T[1]+S[2]+T[2]+S[3] if eval(A)==7: print(A) exit()
s722904031
Accepted
18
3,060
178
import itertools S=input() TT=itertools.product(["+","-"],repeat=3) for T in TT: A=S[0]+T[0]+S[1]+T[1]+S[2]+T[2]+S[3] if eval(A)==7: print(A+"=7") exit()
s670023034
p03470
u426108351
2,000
262,144
Wrong Answer
17
3,060
116
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
N = int(input()) mochi = [] for i in range(N): mochi.append(int(input())) print(list(set(mochi)))
s609243016
Accepted
18
2,940
121
N = int(input()) mochi = [] for i in range(N): mochi.append(int(input())) print(len(list(set(mochi))))