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
s148597189
p03720
u452015170
2,000
262,144
Wrong Answer
17
3,060
179
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?
n, m = map(int, input().split()) a = [0] * m b = [0] * m for i in range(m) : a[i], b[i] = map(int, input().split()) loute = a + b for i in range(n) : print(loute.count(i))
s949952484
Accepted
17
3,060
183
n, m = map(int, input().split()) a = [0] * m b = [0] * m for i in range(m) : a[i], b[i] = map(int, input().split()) loute = a + b for i in range(n) : print(loute.count(i + 1))
s063333640
p00011
u584777171
1,000
131,072
Wrong Answer
30
7,608
400
Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom. Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.
user = input() w = int(user) user = input() n = int(user) a = [] b = [] now = 0 for i in range(n): user = input() users = user.split(",") a.append(int(users[0])) b.append(int(users[1])) print(a) print(b) for j in range(1, w+1): now = j for k in reversed(range(n)): if now == a[k]: now = b[k] elif now == b[k]: now = a[k] print(now)
s217503761
Accepted
20
7,612
382
user = input() w = int(user) user = input() n = int(user) a = [] b = [] now = 0 for i in range(n): user = input() users = user.split(",") a.append(int(users[0])) b.append(int(users[1])) for j in range(1, w+1): now = j for k in reversed(range(n)): if now == a[k]: now = b[k] elif now == b[k]: now = a[k] print(now)
s540580543
p03129
u970308980
2,000
1,048,576
Wrong Answer
17
2,940
87
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N, K = map(int, input().split()) if 2*K-1 <= N: print('Yes') else: print('No')
s827209217
Accepted
17
2,940
87
N, K = map(int, input().split()) if K*2-1 <= N: print('YES') else: print('NO')
s895978003
p03456
u364386647
2,000
262,144
Wrong Answer
60
5,724
1,029
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """1 21""" output = """Yes""" self.assertIO(input, output) def test_入力例_2(self): input = """100 100""" output = """No""" self.assertIO(input, output) def test_入力例_3(self): input = """12 10""" output = """No""" self.assertIO(input, output) def resolve(): a, b = list(map(str, input().split())) num = int(a + b) for i in range(100100): if i * i == num: print('Yes') return print('No') return if __name__ == "__main__": unittest.main()
s774541111
Accepted
24
2,940
214
def resolve(): a, b = list(map(str, input().split())) num = int(a + b) for i in range(100100): if i * i == num: print('Yes') return print('No') return resolve()
s620002197
p03853
u183840468
2,000
262,144
Wrong Answer
19
3,188
148
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
n,m = [int(i) for i in input().split()] l = [[i for i in input()] for _ in range(n)] for i in range(n): for j in range(2): print(l[i])
s802436204
Accepted
18
3,060
157
n,m = [int(i) for i in input().split()] l = [[i for i in input()] for _ in range(n)] for i in range(n): for j in range(2): print(''.join(l[i]))
s286075668
p02420
u671553883
1,000
131,072
Wrong Answer
20
7,648
177
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
while True: s = input() if s == '-': break m = int(input()) for mi in range(m): h = int(input()) s = s[:4] + s[4:] print(s)
s980398420
Accepted
20
7,648
169
while True: s = input() if s == '-': break m = int(input()) for mi in range(m): h = int(input()) s = s[h:] + s[:h] print(s)
s683594440
p02613
u769095634
2,000
1,048,576
Wrong Answer
145
8,908
318
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): s = input() if s == "AC": ac += 1 elif s == "WA": wa += 1 elif s == "TLE": tle += 1 else: re += 1 print("AC × "+ str(ac)) print("WA × "+ str(wa)) print("TLE × " + str(tle)) print("RE × " + str(re))
s424016686
Accepted
150
9,192
314
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): s = input() if s == "AC": ac += 1 elif s == "WA": wa += 1 elif s == "TLE": tle += 1 else: re += 1 print("AC x "+ str(ac)) print("WA x "+ str(wa)) print("TLE x " + str(tle)) print("RE x " + str(re))
s443318285
p03455
u335864153
2,000
262,144
Wrong Answer
17
2,940
122
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()) def cal(): if a*b %2 == 0: print("even") else: print("odd") cal()
s380457964
Accepted
17
2,940
122
a, b = map(int, input().split()) def cal(): if a*b %2 == 0: print("Even") else: print("Odd") cal()
s229774391
p02694
u701017915
2,000
1,048,576
Wrong Answer
22
9,160
86
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
X = int(input()) y = 0 m = 100 while m <= X: m = int(m * 1.01) y = y + 1 print(y)
s307510510
Accepted
22
9,096
88
X = int(input()) y = 0 m = 100 while m < X: m = int(m * 1.01) y = y + 1 print(y)
s535498987
p03971
u647537044
2,000
262,144
Wrong Answer
102
4,708
532
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 = list(input()) A_sum = 0 B_sum = 0 for i in S: if i == 'a': if A_sum + B_sum < A + B: A_sum += 1 print('YES') else: print('NO') elif i == 'b': if A_sum + B_sum < A + B and B_sum < B: B_sum += 1 print('YES') else: print('NO') else: print('NO')
s946292135
Accepted
105
4,708
531
N, A, B = map(int, input().split()) S = list(input()) A_sum = 0 B_sum = 0 for i in S: if i == 'a': if A_sum + B_sum < A + B: A_sum += 1 print('Yes') else: print('No') elif i == 'b': if A_sum + B_sum < A + B and B_sum < B: B_sum += 1 print('Yes') else: print('No') else: print('No')
s143763858
p02741
u267983787
2,000
1,048,576
Wrong Answer
17
3,060
137
Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
a = int(input()) k = [1, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(k[a-1])
s147491164
Accepted
17
3,060
134
a = int(input()) k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(k[a-1])
s408727285
p03388
u723180465
2,000
262,144
Time Limit Exceeded
2,104
3,064
400
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.
q = int(input()) for _ in range(q): a, b = sorted(map(int, input().split())) if a == b: print(2 * a - 2) elif a + 1 == b: print(2 * a - 2) else: c = a while True: if (c + 1) * (c + 1) >= a * b: break c += 1 if c * (c + 1) >= a * b: print(2 * c - 2) else: print(2 * c - 1)
s940645311
Accepted
18
3,060
339
import math q = int(input()) for _ in range(q): a, b = sorted(map(int, input().split())) if a == b: print(2 * a - 2) elif a + 1 == b: print(2 * a - 2) else: c = math.ceil(math.sqrt(a * b)) - 1 if c * (c + 1) >= a * b: print(2 * c - 2) else: print(2 * c - 1)
s631056286
p03963
u772649753
2,000
262,144
Wrong Answer
17
2,940
60
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
n,k = map(int,input().split()) ans = k*(k**(n-1)) print(ans)
s858743548
Accepted
17
2,940
64
n,k = map(int,input().split()) ans = k*((k-1)**(n-1)) print(ans)
s160574747
p00728
u128811851
1,000
131,072
Wrong Answer
40
6,724
297
The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that sometimes counts up to one hundred. The number of judges may differ from one contestant to another, because judges with any relationship whatsoever with a specific contestant are temporarily excluded for scoring his/her performance. Basically, scores given to a contestant's performance by the judges are averaged to decide his/her score. To avoid letting judges with eccentric viewpoints too much influence the score, the highest and the lowest scores are set aside in this calculation. If the same highest score is marked by two or more judges, only one of them is ignored. The same is with the lowest score. The average, which may contain fractions, are truncated down to obtain final score as an integer. You are asked to write a program that computes the scores of performances, given the scores of all the judges, to speed up the event to be suited for a TV program.
averages = [] while True: amount = int(input()) if amount == 0: break scores = [int(input()) for i in range(amount)] scores.remove(max(scores)) scores.remove(min(scores)) averages.append(sum(scores) // amount) for i in range(len(averages)): print(averages[i])
s042068143
Accepted
30
6,724
303
averages = [] while True: amount = int(input()) if amount == 0: break scores = [int(input()) for i in range(amount)] scores.remove(max(scores)) scores.remove(min(scores)) averages.append(sum(scores) // (amount - 2)) for i in range(len(averages)): print(averages[i])
s463115899
p02260
u716198574
1,000
131,072
Wrong Answer
20
7,556
428
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.
N = int(input()) A = list(map(int, input().split())) cnt = 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] cnt += 1 print(' '.join(map(str, A))) print(cnt)
s872882981
Accepted
20
7,688
285
N = int(input()) A = list(map(int, input().split())) cnt = 0 for i in range(N): minj = i for j in range(i, N): if A[j] < A[minj]: minj = j if i is not minj: A[i], A[minj] = A[minj], A[i] cnt += 1 print(' '.join(map(str, A))) print(cnt)
s441458121
p03447
u072717685
2,000
262,144
Wrong Answer
17
2,940
91
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X = int(input()) A = int(input()) B = int(input()) X = X - A X = X - (X%B)*B print(int(X))
s221700801
Accepted
17
2,940
93
X = int(input()) A = int(input()) B = int(input()) X = X - A X = X - (X//B)*B print(int(X))
s855736978
p03997
u602677143
2,000
262,144
Wrong Answer
19
3,060
70
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()) c = int(input()) print((a+b) * c/2)
s903452375
Accepted
20
2,940
77
a = int(input()) b = int(input()) c = int(input()) print((a+b) * round(c/2))
s847123933
p02364
u134812425
1,000
131,072
Wrong Answer
30
6,092
1,024
Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E).
import sys import collections class UnionFind: def __init__(self, n): self.par = [i for i in range(n+1)] self.rank = [0] * (n+1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def are_same(self, x, y): return self.find(x) == self.find(y) Edge = collections.namedtuple('Edge', ['s', 't', 'cost']) V, E = map(int, sys.stdin.readline().split()) edges = sorted([Edge(*map(int, line.split())) for line in sys.stdin], key=lambda e: e.cost) uf = UnionFind(V) min_cost = 0 for edge in edges: if not uf.are_same(edge.s, edge.t): uf.union(edge.s, edge.t) min_cost += edge.cost min_cost
s561802875
Accepted
1,250
47,068
644
import sys import collections import heapq import math Edge = collections.namedtuple('Edge', ['s', 't', 'cost']) V, E = map(int, sys.stdin.readline().split()) edges = collections.defaultdict(list) for line in sys.stdin: e = Edge(*map(int, line.split())) edges[e.s].append(e) edges[e.t].append(Edge(e.t, e.s, e.cost)) heap = [(e.cost, e) for e in edges[0]] heapq.heapify(heap) nodes = {0} min_cost = 0 while heap: _, edge = heapq.heappop(heap) if edge.t not in nodes: nodes.add(edge.t) for e in edges[edge.t]: heapq.heappush(heap, (e.cost, e)) min_cost += edge.cost print(min_cost)
s319743951
p03549
u802772880
2,000
262,144
Wrong Answer
18
3,060
69
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n,m=map(int,input().split()) x=1900*m+100*(n-m) p=1/2**m print(x//p)
s480497204
Accepted
23
2,940
72
n,m=map(int,input().split()) x=1900*m+100*(n-m) p=1/2**m print(int(x/p))
s574431453
p01137
u269391636
8,000
131,072
Wrong Answer
100
5,676
144
English text is not available in this practice contest. ケン・マリンブルーは,宇宙ヤシガニを求めて全銀河を旅するスペースハンターである.宇宙ヤシガニは,宇宙最大とされる甲殻類であり,成長後の体長は 400 メートル以上,足を広げれば 1,000 メートル以上にもなると言われている.既に多数の人々が宇宙ヤシガニを目撃しているが,誰一人として捕らえることに成功していない. ケンは,長期間の調査によって,宇宙ヤシガニの生態に関する重要な事実を解明した.宇宙ヤシガニは,驚くべきことに,相転移航法と呼ばれる最新のワープ技術と同等のことを行い,通常空間と超空間の間を往来しながら生きていた.さらに,宇宙ヤシガニが超空間から通常空間にワープアウトするまでには長い時間がかかり,またワープアウトしてからしばらくは超空間に移動できないことも突き止めた. そこで,ケンはついに宇宙ヤシガニの捕獲に乗り出すことにした.戦略は次のとおりである.はじめに,宇宙ヤシガニが通常空間から超空間に突入する際のエネルギーを観測する.このエネルギーを _e_ とするとき,宇宙ヤシガニが超空間からワープアウトする座標 ( _x_ , _y_ , _z_ ) は以下の条件を満たすことがわかっている. * _x_ , _y_ , _z_ はいずれも非負の整数である. * _x_ \+ _y_ 2 \+ _z_ 3 = _e_ である. * 上記の条件の下で _x_ \+ _y_ \+ _z_ の値を最小にする. これらの条件だけでは座標が一意に決まるとは限らないが, _x_ \+ _y_ \+ _z_ の最小値を _m_ としたときに,ワープアウトする座標が平面 _x_ \+ _y_ \+ _z_ = _m_ 上にあることは確かである.そこで,この平面上に十分な大きさのバリアを張る.すると,宇宙ヤシガニはバリアの張られたところにワープアウトすることになる.バリアの影響を受けた宇宙ヤシガニは身動きがとれなくなる.そこをケンの操作する最新鋭宇宙船であるウェポン・ブレーカー号で捕獲しようという段取りである. バリアは一度しか張ることができないため,失敗するわけにはいかない.そこでケンは,任務の遂行にあたって計算機の助けを借りることにした.あなたの仕事は,宇宙ヤシガニが超空間に突入する際のエネルギーが与えられたときに,バリアを張るべき平面 _x_ \+ _y_ \+ _z_ = _m_ を求めるプログラムを書くことである.用意されたテストケースの全てに対して正しい結果を出力したとき,あなたのプログラムは受け入れられるであろう.
while(True): e = int(input()) if e == 0: quit() i = int(e ** (1/3)) j = (int(e - i ** 3)**0.5) print(e - i ** 3 - j ** 2 + i + j)
s549919086
Accepted
670
5,772
272
from math import floor while(True): e = int(input()) if e == 0: quit() ans = e for i in range(0,e): if i ** 3 > e: break j = floor((e - i ** 3)**0.5) k = e - i ** 3 - j ** 2 + i + j if k < ans: ans = k print(ans)
s502966352
p03759
u164261323
2,000
262,144
Wrong Answer
17
2,940
79
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 abs(a-b) == abs(c-b) else "No")
s047712204
Accepted
17
2,940
69
a,b,c = map(int,input().split()) print("YES" if b-a == c-b else "NO")
s526843973
p03836
u648881683
2,000
262,144
Wrong Answer
37
10,112
787
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): sx, sy, tx, ty = LI() dx = tx - sx dy = ty - sy ans_f0 = 'U' * dy + 'R' * dx ans_b0 = 'U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R' ans_f1 = 'R' * dx + 'U' * dy ans_b1 = 'R' + 'D' * (dx + 1) + 'L' * (dy + 1) + 'U' print(ans_f0 + ans_b0 + ans_f1 + ans_b1) if __name__ == '__main__': resolve()
s558200373
Accepted
37
10,036
787
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): sx, sy, tx, ty = LI() dx = tx - sx dy = ty - sy ans_f0 = 'U' * dy + 'R' * dx ans_b0 = 'D' * dy + 'L' * dx ans_f1 = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D' ans_b1 = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U' print(ans_f0 + ans_b0 + ans_f1 + ans_b1) if __name__ == '__main__': resolve()
s567446422
p03944
u168416324
2,000
262,144
Wrong Answer
28
9,220
341
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
w,h,n=map(int,input().split()) wx=[0]*w hy=[0]*h for i in range(n): x,y,a=map(int,input().split()) x-=1 y-=1 if a==1: for j in range(x): wx[j]=1 if a==2: for j in range(x,w): wx[j]=1 if a==3: for j in range(y): hy[j]=1 if a==4: for j in range(y,h): hy[j]=1 print(wx.count(0)*hy.count(0))
s679122459
Accepted
31
9,152
371
w,h,n=map(int,input().split()) wx=[0]*w hy=[0]*h for i in range(n): x,y,a=map(int,input().split()) x-=1 y-=1 if a==1: for j in range(x+1): wx[j]=1 if a==2: for j in range(x+1,w): wx[j]=1 if a==3: for j in range(y+1): hy[j]=1 if a==4: for j in range(y+1,h): hy[j]=1 print(wx.count(0)*hy.count(0)) #print(wx) #print(hy)
s434254574
p03721
u316386814
2,000
262,144
Wrong Answer
433
17,104
237
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
import heapq n, k = list(map(int, input().split())) li = [] for _ in range(n): li.append(tuple(map(int, input().split()))) li.sort() cnt = 0 for a, b in li: cnt += b if cnt >= k - 1: ans = a break print(ans)
s213118202
Accepted
450
17,104
233
import heapq n, k = list(map(int, input().split())) li = [] for _ in range(n): li.append(tuple(map(int, input().split()))) li.sort() cnt = 0 for a, b in li: cnt += b if cnt >= k: ans = a break print(ans)
s131699244
p00185
u847467233
1,000
131,072
Wrong Answer
820
13,512
499
ゴールドバッハ予想とは「6 以上のどんな偶数も、2 つの素数 (*1) の和として表わすことができる」というものです。 たとえば、偶数の 12 は 12 = 5 + 7 、18 は 18 = 5 + 13 = 7 + 11 などと表すことができます。 和が 134 となる 2 つの素数の組み合せをすべて書き出すと、以下の通りとなります。 134 = 3+131 = 7+127 = 31+103 = 37+97 = 61+73 = 67+67 = 131+3 = 127+7 = 103+31 = 97+37 = 73+61 与えられた数が大きくなると、いくらでも素数の組み合せが見つかるような気がします。しかし、現代数学をもってしてもこの予想を証明することも、反例を作ることもできません(*2)。ちょっと不思議な感じがしますね。 そこで、ゴールドバッハ予想を鑑賞するために、偶数 n を入力とし、和が n となる 2 つの素数の組み合せの数を求めるプログラムを作成してください。 和が n となる素数の組み合せの数とは n = p + q かつ p ≤ q であるような正の素数 p, q の組み合せの数です。上の例からわかるように和が 134 となる素数の組み合せは6 個です。 (*1) 素数とは、1 または自分自身以外に約数を持たない整数のことである。なお、1 は素数ではない。 (*2) 2007 年 2 月現在、5×1017 までの全ての偶数について成り立つことが確かめられている。(Wikipedia)
# AOJ 0185 Goldbach's Conjecture II # Python3 2018.6.20 bal4u MAX = 1000000 SQRT = 1000 # sqrt(MAX) prime = [True for i in range(MAX)] prime[1] = False def sieve(): for i in range(3, SQRT, 2): if prime[i] is True: for j in range(i*i, MAX, i): prime[j] = False sieve() print(prime[1:20:2]) while True: n = int(input()) if n == 0: break i = j = n >> 1 if (i & 1) == 0: i -= 1 j += 1 ans = 0 while i > 0: if prime[i] and prime[j]: ans += 1 i -= 2 j += 2 print(ans)
s401727949
Accepted
870
13,512
477
# AOJ 0185 Goldbach's Conjecture II # Python3 2018.6.20 bal4u MAX = 1000000 SQRT = 1000 # sqrt(MAX) prime = [True for i in range(MAX)] prime[1] = False def sieve(): for i in range(3, SQRT, 2): if prime[i] is True: for j in range(i*i, MAX, i): prime[j] = False sieve() while True: n = int(input()) if n == 0: break i = j = n >> 1 if (i & 1) == 0: i -= 1 j += 1 ans = 0 while i > 0: if prime[i] and prime[j]: ans += 1 i -= 2 j += 2 print(ans)
s555418357
p03197
u997113115
2,000
1,048,576
Wrong Answer
217
3,060
129
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
N = int(input()) r = 0 for _ in range(N): if int(input()) % 2 == 0: r += 1 print("first" if r % 2 == 0 else "second")
s930248814
Accepted
215
3,060
135
N = int(input()) flag = False for _ in range(N): if int(input()) % 2 != 0: flag = True print("first" if flag else "second")
s485044060
p04031
u050428930
2,000
262,144
Wrong Answer
17
3,064
168
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
N=int(input()) s=list(map(int,input().split())) t=0 w=0 for i in range(N): t+=s[i] t=int(((t/N)*2+1)//2) print(t) for j in range(N): w+=(t-s[j])**2 print(w)
s387678396
Accepted
17
3,060
159
N=int(input()) s=list(map(int,input().split())) t=0 w=0 for i in range(N): t+=s[i] t=int(((t/N)*2+1)//2) for j in range(N): w+=(t-s[j])**2 print(w)
s925860326
p00423
u452926933
1,000
131,072
Wrong Answer
120
5,624
509
A と B の 2 人のプレーヤーが, 0 から 9 までの数字が書かれたカードを使ってゲームを行う.最初に, 2 人は与えられた n 枚ずつのカードを,裏向きにして横一列に並べる.その後, 2 人は各自の左から 1 枚ずつカードを表向きにしていき,書かれた数字が大きい方のカードの持ち主が,その 2 枚のカードを取る.このとき,その 2 枚のカードに書かれた数字の合計が,カードを取ったプレーヤーの得点となるものとする.ただし,開いた 2 枚のカードに同じ数字が書かれているときには,引き分けとし,各プレーヤーが自分のカードを 1 枚ずつ取るものとする. 例えば, A,B の持ち札が,以下の入力例 1 から 3 のように並べられている場合を考えよう.ただし,入力ファイルは n + 1 行からなり, 1 行目には各プレーヤのカード枚数 n が書かれており, i + 1 行目(i = 1,2,... ,n)には A の左から i 枚目のカードの数字と B の左から i 枚目の カードの数字が,空白を区切り文字としてこの順で書かれている.すなわち,入力ファイルの 2 行目以降は,左側の列が A のカードの並びを,右側の列が B のカードの並びを,それぞれ表している.このとき,ゲーム終了後の A と B の得点は,それぞれ,対応する出力例に示したものとなる. 入力ファイルに対応するゲームが終了したときの A の得点と B の得点を,この順に空白を区切り文字として 1 行に出力するプログラムを作成しなさい.ただし, n ≤ 10000 とする. 入力例1 | 入力例2 | 入力例3 ---|---|--- 3| 3| 3 9 1| 9 1| 9 1 5 4| 5 4| 5 5 0 8| 1 0| 1 8 出力例1 | 出力例2 | 出力例3 19 8| 20 0| 15 14
while True: try: n = int(input()) scores = [0, 0] for i in range(n): cards = list(map(int, input().split())) if cards[0] > cards[1]: scores[0] += cards[0] + cards[1] elif cards[0] < cards[1]: scores[1] += cards[0] + cards[1] else: scores[0] += cards[0] scores[1] += cards[1] print(' '.join([str(score) for score in scores])) except EOFError: exit()
s317921548
Accepted
120
5,624
445
while True: n = int(input()) if n == 0: break scores = [0, 0] for i in range(n): cards = list(map(int, input().split())) if cards[0] > cards[1]: scores[0] += cards[0] + cards[1] elif cards[0] < cards[1]: scores[1] += cards[0] + cards[1] else: scores[0] += cards[0] scores[1] += cards[1] print(' '.join([str(score) for score in scores]))
s201818866
p03779
u799443198
2,000
262,144
Wrong Answer
17
2,940
132
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
N = int(input()) l, r = 0, 100000 while l + 1 < r: m = (l + r) / 2 if m * (m + 1) // 2 < N: l = m else: r = m print(r)
s504378105
Accepted
17
2,940
134
N = int(input()) l, r = 0, 100000 while l + 1 < r: m = (l + r) // 2 if m * (m + 1) // 2 < N: l = m else: r = m print(r)
s275624861
p03379
u349444371
2,000
262,144
Wrong Answer
222
30,780
184
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n=int(input()) a=list(map(int,input().split())) print(a) A=sorted(a) print(A) m1=A[n//2 -1] m2=A[n//2] for i in range(n): if a[i]<=m1: print(m2) else: print(m1)
s573974175
Accepted
182
30,768
168
n=int(input()) a=list(map(int,input().split())) A=sorted(a) m1=A[n//2 -1] m2=A[n//2] for i in range(n): if a[i]<=m1: print(m2) else: print(m1)
s817003789
p03693
u363118893
2,000
262,144
Wrong Answer
17
2,940
110
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 (10^2*r + 10^1*g + 10^0*b) % 4: print("NO") else: print("YES")
s088551352
Accepted
17
2,940
106
r, g, b = map(int, input().split()) if (100*r + 10*g + b) % 4 == 0: print("YES") else: print("NO")
s407687059
p03448
u786020649
2,000
262,144
Wrong Answer
22
9,168
171
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
import sys x,a,b,c=map(int,sys.stdin.read().split()) c=0 for i in range(a): for j in range(b): for k in range(c): if 500*i+100*j+50*k==x: c+=1 print(c)
s582351272
Accepted
53
8,988
190
import sys a,b,c,x=map(int,sys.stdin.read().split()) count=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if 500*i+100*j+50*k==x: count+=1 print(count)
s747885891
p03494
u845982808
2,000
262,144
Wrong Answer
25
8,972
151
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.
def division(li): for i in range(len(li)): if i % 2 == True: continue else: print(i) division([8, 12, 40])
s657942393
Accepted
34
9,100
151
N = int(input()) A = list(map(int, input().split())) count = 0 while all(a % 2 == 0 for a in A): A = [a / 2 for a in A] count += 1 print(count)
s551590260
p02841
u667084803
2,000
1,048,576
Wrong Answer
17
2,940
77
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
a, b = map(int, input().split()) c, d = map(int, input().split()) print(a!=b)
s559430883
Accepted
18
2,940
82
a, b = map(int, input().split()) c, d = map(int, input().split()) print(int(a!=c))
s692741804
p03943
u778700306
2,000
262,144
Wrong Answer
17
3,068
111
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 = map(int, input().split()) a = sorted(a) if a[0] + a[1] == a[2]: print("YES") else: print("NO")
s141374643
Accepted
17
2,940
111
a = map(int, input().split()) a = sorted(a) if a[0] + a[1] == a[2]: print("Yes") else: print("No")
s731995084
p03795
u362560965
2,000
262,144
Wrong Answer
17
2,940
52
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) x = 800*N y = N // 15 print(x-y)
s427762928
Accepted
17
2,940
58
N = int(input()) x = 800*N y = 200*(N // 15) print(x-y)
s680851142
p03351
u764956288
2,000
1,048,576
Wrong Answer
18
2,940
59
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d=map(int,input().split()) 'YNeos'[max(b-a,c-b)>d::2]
s482407466
Accepted
18
2,940
91
a,b,c,d=map(int,input().split()) print('YNeos'[abs(c-a)>d and max(abs(b-a),abs(c-b))>d::2])
s445594377
p04011
u732870425
2,000
262,144
Wrong Answer
17
2,940
111
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if n <= k: ans = n*x else: ans = k*x + (n-k)*y
s735891784
Accepted
17
3,060
122
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if n <= k: ans = n*x else: ans = k*x + (n-k)*y print(ans)
s223889180
p03434
u440551778
2,000
262,144
Wrong Answer
17
3,060
216
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) an = list(map(int, input().split())) alice = 0 bob = 0 an.sort() an.reverse() print(an) for i,v in enumerate(an): if i % 2 ==0: alice += v else: bob += v print(alice - bob)
s831450583
Accepted
17
2,940
206
n = int(input()) an = list(map(int, input().split())) alice = 0 bob = 0 an.sort() an.reverse() for i,v in enumerate(an): if i % 2 ==0: alice += v else: bob += v print(alice - bob)
s123207562
p02972
u934099192
2,000
1,048,576
Wrong Answer
2,109
17,548
586
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.
import numpy as np n = int(input()) a = np.array(list(map(int, input().strip().split()))) b = np.zeros((n)) for i in range(n): b[i] = a[i] #print(b) if n % 2 == 0: p = int(np.ceil(n/2)) else: p = int(np.ceil(n/2)-1) #print(p) for i in reversed(range(p+1)): for j in reversed(range(1,int(n/(i+1)))): #print(i,j) b[i] -= b[(i+1)*(j+1)-1] b = b.astype(int) #print(b) flag = True for i in range(n): if b[i] < 0: flag = False break if flag: print(str(b).replace('[','').replace(']','').replace(' 0','')) else: print(-1)
s298214086
Accepted
1,820
23,552
559
import numpy as np n = int(input()) a = np.array(list(map(int, input().strip().split()))) b = [0] * (n+1) for i in range(n): b[i+1] = a[i] #print(b) #print('p',n//2) for i in reversed(range(1,n//2 + 1)): j = 2 b_sum = 0 #print(i) while i * j <= n: #print(i,j) b_sum += b[i*j] j += 1 if (b_sum % 2) == a[i-1]: b[i] = 0 else: b[i] = 1 #print(b) s = sum(b) print(s) if s > 0: sl = '' for i in range(len(b)): if b[i] == 1: sl += str(i) + ' ' print(sl[:-1])
s614891042
p03997
u581603131
2,000
262,144
Wrong Answer
17
3,064
504
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.
SA = list(str(input())) SB = list(str(input())) SC = list(str(input())) card = 'a' for i in range(500): if len(SA)==1 and card=='a': print('A') break elif len(SB)==1 and card=='b': print('B') break elif len(SC)==1 and card=='c': print('C') break if card == 'a': SA = SA[1:] card = SA[0] elif card == 'b': SB = SB[1:] card = SB[0] elif card == 'c': SC =SC[1:] card = SC[0]
s529800121
Accepted
17
3,064
72
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h/2))
s727265123
p03636
u702208001
2,000
262,144
Wrong Answer
17
2,940
51
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = input() print(s[0] + str(len(s[1:-2])) + s[-1])
s322976673
Accepted
17
2,940
49
s = input() print(s[0] + str(len(s) - 2) + s[-1])
s294067789
p02411
u606989659
1,000
131,072
Wrong Answer
20
7,560
423
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
while True: m,f,r = map(int,input().split()) if m == -1 or f == -1: print('F') elif m + f >= 80: print('A') elif 65 <= (m + f) < 80: print('B') elif 50 <= (m + f) < 65: print('C') elif 30 <= (m + f) < 50: if r >= 50: print('C') else: print('D') elif (m + f) < 30: print('F') if m == f == r == -1: break
s951358968
Accepted
30
7,608
428
while True: m,f,r = map(int,input().split()) if m == f == r == -1: break if m == -1 or f == -1: print('F') elif m + f >= 80: print('A') elif 65 <= (m + f) < 80: print('B') elif 50 <= (m + f) < 65: print('C') elif 30 <= (m + f) < 50: if r >= 50: print('C') else: print('D') elif (m + f) < 30: print('F')
s944835852
p03719
u032484849
2,000
262,144
Wrong Answer
18
2,940
81
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c=map(int,input().split()) if a<=c<=b: print("YES") else: print("NO")
s139971641
Accepted
17
2,940
81
a,b,c=map(int,input().split()) if a<=c<=b: print("Yes") else: print("No")
s869219940
p03574
u066551652
2,000
262,144
Wrong Answer
39
9,292
534
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 = [] for i in range(h): i = list(input()) s.append(i) dx = [-1, 0, 1, -1, 1, -1, 0, 1] dy = [1, 1, 1, 0, 0, -1, -1, -1] for i in range(h): for j in range(w): if s[i][j] == '#': continue tmp = 0 for t in range(8): ni = i + dx[t] nj = j + dy[t] if ni < 0 or h <= ni: continue if nj < 0 or w <= nj: continue if s[ni][nj] == '#': tmp += 1 s[i][j] = str(tmp) print(s)
s490336488
Accepted
36
9,188
559
h, w = map(int,input().split()) s = [] for i in range(h): i = list(input()) s.append(i) dx = [-1, 0, 1, -1, 1, -1, 0, 1] dy = [1, 1, 1, 0, 0, -1, -1, -1] for i in range(h): for j in range(w): if s[i][j] == '#': continue tmp = 0 for t in range(8): ni = i + dx[t] nj = j + dy[t] if ni < 0 or h <= ni: continue if nj < 0 or w <= nj: continue if s[ni][nj] == '#': tmp += 1 s[i][j] = str(tmp) for i in s: print(''.join(i))
s564584621
p03543
u706414019
2,000
262,144
Wrong Answer
24
9,016
69
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**?
N = input() if N[0] == N[-1]: print('Yes') else: print('No')
s827429421
Accepted
30
9,024
112
N = input() if (N[0]==N[1] and N[1]==N[2])or(N[1]==N[2] and N[2]==N[3]): print('Yes') else: print('No')
s012765807
p02394
u956226421
1,000
131,072
Wrong Answer
20
7,576
253
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.
I = input().split() W = int(I[0]) H = int(I[1]) x = int(I[2]) y = int(I[3]) r = int(I[4]) answer = True if x - r < 0: answer = False if x + r > W: answer = False if y - r < 0: answer = False if y + r > H: answer = False print(answer)
s567974542
Accepted
60
7,728
297
I = input().split() W = int(I[0]) H = int(I[1]) x = int(I[2]) y = int(I[3]) r = int(I[4]) answer = True if x - r < 0: answer = False if x + r > W: answer = False if y - r < 0: answer = False if y + r > H: answer = False if answer == True: print("Yes") else: print("No")
s806673929
p02613
u785266893
2,000
1,048,576
Wrong Answer
146
9,196
283
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) AC, WA, TLE, RE = 0,0,0,0 for i in range(n): s = input() if s == "AC": AC += 1 elif s == "WA": WA += 1 elif s == "TLE": TLE += 1 else: RE += 1 print("AC × {}\nWA × {}\nTLE × {}\nRE × {}".format(AC,WA,TLE,RE))
s661516699
Accepted
147
9,196
279
n = int(input()) AC, WA, TLE, RE = 0,0,0,0 for i in range(n): s = input() if s == "AC": AC += 1 elif s == "WA": WA += 1 elif s == "TLE": TLE += 1 else: RE += 1 print("AC x {}\nWA x {}\nTLE x {}\nRE x {}".format(AC,WA,TLE,RE))
s106277964
p03644
u736729525
2,000
262,144
Wrong Answer
17
2,940
73
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()) for i in range(8): if N < 2**i: print(2**(i-1))
s402239511
Accepted
17
2,940
83
N = int(input()) for i in range(8): if N < 2**i: print(2**(i-1)) break
s885676435
p02972
u612975321
2,000
1,048,576
Wrong Answer
995
67,564
319
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.
import numpy as np n = int(input()) a = np.array(list(map(int,input().split())), dtype=int) b = np.zeros(n, dtype=int) for i in range(n-1, -1, -1): m = sum(b[i::i+1]) % 2 b[i] = (a[i] + m) % 2 bsum =sum(b) if bsum == 0: print(bsum) else: ans = b.astype('str') print(bsum) print(' '.join(ans))
s090076269
Accepted
891
54,728
352
import numpy as np n = int(input()) a = np.array(list(map(int,input().split())), dtype=int) b = np.zeros(n, dtype=int) for i in range(n-1, -1, -1): m = sum(b[i::i+1]) % 2 b[i] = (a[i] + m) % 2 bsum =sum(b) if bsum == 0: print(bsum) else: ans = np.where(b>0)[0] + 1 ans = ans.astype('str') print(bsum) print(' '.join(ans))
s333069792
p03338
u833543158
2,000
1,048,576
Wrong Answer
18
2,940
196
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
N = int(input()) S = input() maxCount = 0 for i in range(N-1): commonCount = len(set(S[0:i+1])&set(S[i+1:-1])) if maxCount < commonCount: maxCount = commonCount print(maxCount)
s294382840
Accepted
20
3,060
266
N = int(input()) S = input() maxCount = 0 if N == 2: print(len(set(S[0])&set(S[-1]))) else: for i in range(N): commonCount = len(set(S[0:i+1])&set(S[i+1:])) if maxCount < commonCount: maxCount = commonCount print(maxCount)
s134487640
p02833
u221264296
2,000
1,048,576
Wrong Answer
17
2,940
113
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).
def f(n,x): ret = 0 while n>0: n//=x ret+=n return ret n = int(input()) print(min(f(n,2), f(n,5)))
s094375105
Accepted
17
2,940
113
def f(n): ans = 0 while n>0: n//=5 ans+=n return ans x = int(input()) print(0 if x%2 else f(x//2))
s845072112
p00100
u150984829
1,000
131,072
Wrong Answer
30
5,792
188
There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID _i_ , the amount of sales _q_ and the corresponding unit price _p_. Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p × q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that _n_ < 4000, and each employee has an unique ID. The unit price _p_ is less than or equal to 1,000,000 and the amount of sales _q_ is less than or equal to 100,000.
while 1: a={};b=0 n=int(input()) if n==0:break for _ in[0]*n: e,p,q=map(int,input().split()) a.setdefault(e,0);a[e]+=p*q for e in a: if a[e]>=1e6:print(e);b=1 if b:print('NA')
s083249047
Accepted
30
5,788
188
while 1: a={};b=1 n=int(input()) if n==0:break for _ in[0]*n: e,p,q=map(int,input().split()) a.setdefault(e,0);a[e]+=p*q for e in a: if a[e]>=1e6:print(e);b=0 if b:print('NA')
s629980632
p03854
u256106029
2,000
262,144
Wrong Answer
19
3,188
175
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() t = '' s = s.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '') print(s) if s == t: print('YES') else: print('NO')
s470331907
Accepted
78
3,188
323
s = input() words = ['dream', 'dreamer', 'erase', 'eraser'] while len(s) > 0: for word in words: flg = False if s.endswith(word): s = s[:(len(s) - len(word))] flg = True break if not flg: break if len(s) == 0: print('YES') else: print('NO')
s113189348
p03493
u955907183
2,000
262,144
Wrong Answer
17
2,940
59
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.
a = input() cnt = 0 for c in a: cnt=cnt + 1 print(c)
s555749885
Accepted
17
2,940
81
a = input() cnt = 0 for c in a: if (c == '1'): cnt=cnt + 1 print(cnt)
s668588874
p02390
u613278035
1,000
131,072
Wrong Answer
20
5,588
93
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
time = int(input()) h = time/3600 time%3600 m = time/60 s = time%60 print("%d:%d:%d"%(h,m,s))
s202564822
Accepted
20
5,588
107
time = int(input()) h = str(time // 3600) m = str((time % 3600)//60) s = str(time%60) print(h+":"+m+":"+s)
s865094131
p02612
u716660050
2,000
1,048,576
Wrong Answer
29
9,164
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) print(1000-N)
s048039714
Accepted
26
9,120
75
N=int(input()) for i in range(11): if i*1000>=N:print((i*1000)-N);break
s014632339
p02618
u759076129
2,000
1,048,576
Wrong Answer
34
9,228
438
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
D = int(input()) cs = [int(i) for i in input().split()] last = {n: 0 for n in range(1, 27)} ans = [] for day in range(1, D-26): ss = [int(i) for i in input().split()] max_score = 0 max_i = 1 for i, s in enumerate(ss, 1): human = day-last[i] s_human = s + cs[i-1] * (human*2) if s_human > max_score: max_score = s_human max_i = i ans.append(max_i) last[max_i] = day
s777584262
Accepted
38
9,288
684
D = int(input()) cs = [int(i) for i in input().split()] last = {n: 0 for n in range(1, 27)} ans = [] change = 2 for day in range(1, D-change): ss = [int(i) for i in input().split()] max_score = 0 max_i = 1 for i, s in enumerate(ss, 1): human = day-last[i] s_human = s + cs[i-1] * (human*6) if s_human > max_score: max_score = s_human max_i = i ans.append(max_i) last[max_i] = day for day in range(D-change, D+1): ss = [int(i) for i in input().split()] m = 0 mi = 1 for i, s in enumerate(ss,1): if s > m: m = s mi = i ans.append(mi) for a in ans: print(a)
s946256091
p03160
u574053975
2,000
1,048,576
Wrong Answer
138
14,664
170
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
a=int(input()) b=list(map(int,input().split())) c=[0,abs(b[0]-b[1])] for i in range(2,a): d=min(c[i-2]+abs(b[i-2]-b[i]),c[i-1]+abs(b[i-1]-b[i])) c.append(d) print(c)
s019591797
Accepted
125
13,908
175
a=int(input()) b=list(map(int,input().split())) c=[0,abs(b[0]-b[1])] for i in range(2,a): d=min(c[i-2]+abs(b[i-2]-b[i]),c[i-1]+abs(b[i-1]-b[i])) c.append(d) print(c[a-1])
s237649792
p00025
u548155360
1,000
131,072
Wrong Answer
20
5,600
643
Let's play Hit and Blow game. _A_ imagines four numbers and _B_ guesses the numbers. After _B_ picks out four numbers, _A_ answers: * The number of numbers which have the same place with numbers _A_ imagined (Hit) * The number of numbers included (but different place) in the numbers _A_ imagined (Blow) For example, if _A_ imagined numbers: 9 1 8 2 and _B_ chose: 4 1 5 9 _A_ should say 1 Hit and 1 Blow. Write a program which reads four numbers _A_ imagined and four numbers _B_ chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.
# coding=utf-8 def hit_and_blow(answer: list, expect: list) -> tuple: hit, blow = 0, 0 for (i, j) in zip(answer, expect): if i == j: hit += 1 answer_set = set(answer) expect_set = set(expect) blow_set = answer_set & expect_set print(blow_set) blow = len(blow_set) - hit return hit, blow if __name__ == '__main__': while True: try: answer_number = list(map(int, input().split())) expected_number = list(map(int, input().split())) except EOFError: break h, b = hit_and_blow(answer_number, expected_number) print(h, b)
s285619056
Accepted
20
5,604
623
# coding=utf-8 def hit_and_blow(answer: list, expect: list) -> tuple: hit, blow = 0, 0 for (i, j) in zip(answer, expect): if i == j: hit += 1 answer_set = set(answer) expect_set = set(expect) blow_set = answer_set & expect_set blow = len(blow_set) - hit return hit, blow if __name__ == '__main__': while True: try: answer_number = list(map(int, input().split())) expected_number = list(map(int, input().split())) except EOFError: break h, b = hit_and_blow(answer_number, expected_number) print(h, b)
s711074601
p03545
u378691508
2,000
262,144
Wrong Answer
31
9,184
274
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.
a=input() A = int(a[0]) for flag in range(2**3): op=[] temp_a=A for i in range(3): if (flag>>i)&1==1: op.append("+") temp_a+=int(a[i+1]) else: op.append("-") temp_a-=int(a[i+1]) if temp_a==7: print(a[0],op[0],a[1],op[1],a[2],op[2],a[3],"=7") exit()
s481409650
Accepted
30
9,120
296
a=input() A = int(a[0]) for flag in range(2**3): op=[] temp_a=A for i in range(3): if (flag>>i)&1==1: op.append("+") temp_a+=int(a[i+1]) else: op.append("-") temp_a-=int(a[i+1]) if temp_a==7: print("{}{}{}{}{}{}{}=7".format(a[0],op[0],a[1],op[1],a[2],op[2],a[3])) exit()
s632528898
p03338
u684026548
2,000
1,048,576
Wrong Answer
19
3,060
246
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
n = int(input()) s = input() max_n = 0 for i in range(1,n): x = set() y = set() for j in range(0,i): x.add(s[j]) for j in range(i,n): y.add(s[j]) if len(x|y) > max_n: max_n = len(x|y) print(max_n)
s126392100
Accepted
19
3,060
246
n = int(input()) s = input() max_n = 0 for i in range(1,n): x = set() y = set() for j in range(0,i): x.add(s[j]) for j in range(i,n): y.add(s[j]) if len(x&y) > max_n: max_n = len(x&y) print(max_n)
s185474981
p02806
u642012866
2,525
1,048,576
Wrong Answer
27
9,160
148
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
N = int(input()) S = [] T = [] for i in range(N): s, t = input().split() S.append(s) T.append(int(t)) X = input() print(sum(T[:S.index(X)+1]))
s401916929
Accepted
28
9,148
149
N = int(input()) S = [] T = [] for i in range(N): s, t = input().split() S.append(s) T.append(int(t)) X = input() print(sum(T[S.index(X)+1:]))
s231264516
p04029
u460615319
2,000
262,144
Wrong Answer
29
9,100
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s000146878
Accepted
29
9,152
34
n = int(input()) print(n*(n+1)//2)
s616049600
p03415
u118019047
2,000
262,144
Wrong Answer
17
2,940
75
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.
a = list(input()) b = list(input()) c = list(input()) print(a[0],b[1],c[2])
s044406663
Accepted
17
2,940
70
a=list(input()) b=list(input()) c=list(input()) print(a[0]+b[1]+c[2])
s976227152
p03485
u115877451
2,000
262,144
Wrong Answer
22
9,160
52
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()) n=(a+b*(1/10)) print(n)
s128839119
Accepted
20
9,060
52
a,b=map(int,input().split()) c=-(-(a+b)//2) print(c)
s167435598
p03160
u629350026
2,000
1,048,576
Wrong Answer
136
13,980
202
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
n=int(input()) h=list(map(int,input().split())) ans=0 temp=[0]*n temp[0]=0 temp1=abs(h[1]-h[0]) for i in range(2,n): temp[i]=min(temp[i-1]+abs(h[i]-h[i-1]),temp[i-2]+abs(h[i]-h[i-2])) print(temp[n-1])
s888030513
Accepted
132
13,980
204
n=int(input()) h=list(map(int,input().split())) ans=0 temp=[0]*n temp[0]=0 temp[1]=abs(h[1]-h[0]) for i in range(2,n): temp[i]=min(temp[i-1]+abs(h[i]-h[i-1]),temp[i-2]+abs(h[i]-h[i-2])) print(temp[n-1])
s439323672
p03474
u102126195
2,000
262,144
Wrong Answer
17
3,060
340
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()) s = list(S) No = 0 for i in range(A): if s[i] == '-': print('No') No = 1 if No == 0: for i in range(B): if s[A + i] == '-': print('No') No = 1 if No == 0: if A + B + 1 == len(S) and s[A] == '-': print('Yes') else: print('No')
s930149662
Accepted
17
3,064
435
A, B = map(int, input().split()) S = str(input()) s = list(S) No = 0 if A + B + 1 != len(S): print('No') No = 1 if No == 0: for i in range(A): if s[i] == '-': print('No') No = 1 break if No == 0: for i in range(B): if s[A + i + 1] == '-': print('No') No = 1 break if No == 0: if s[A] == '-': print('Yes') else: print('No')
s477591124
p03400
u782098901
2,000
262,144
Wrong Answer
19
2,940
192
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
N = int(input()) D, X = map(int, input().split()) A = [int(input()) for _ in range(N)] cnt = 0 for a in A: n = 1 while (n - 1) * a + 1 <= D: n += 1 cnt += n - 1 print(cnt)
s861392603
Accepted
18
2,940
134
N = int(input()) D, X = map(int, input().split()) A = [int(input()) for _ in range(N)] for a in A: X += (D + a - 1) // a print(X)
s821221095
p02646
u630554891
2,000
1,048,576
Wrong Answer
24
9,084
142
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 a + v * t > b + w * t: print('Yes') else: print('No')
s176968880
Accepted
24
9,132
272
a,v=map(int, input().split()) b,w=map(int, input().split()) t=int(input()) if a < b: if a + (v * t) >= b + (w * t): print('YES') else: print('NO') elif a > b: if a - (v * t) <= b - (w * t): print('YES') else: print('NO')
s037461520
p03657
u013756322
2,000
262,144
Wrong Answer
18
2,940
101
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
a, b = map(int, input().split()) if (a * b % 3 == 0): print('Possible') else: print('Impossible')
s939787178
Accepted
17
2,940
122
a, b = map(int, input().split()) if ((a + b) % 3 == 0 or a * b % 3 == 0): print('Possible') else: print('Impossible')
s440344688
p03352
u079022693
2,000
1,048,576
Wrong Answer
18
3,188
172
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
X=int(input()) n=1 for b in range(2,X): p=2 while(True): x=b**p print(x) if x<=X: n=x p+=1 else: break print(n)
s523152821
Accepted
17
3,060
364
def main(): X=int(input()) if X==1 or X==2 or X==3: print(1) else: li=[] for p in range(2,10): for n in range(2,100): if n**p<=X: li.append(n**p) else: break li.sort(reverse=True) print(li[0]) if __name__=="__main__": main()
s815234008
p03448
u023229441
2,000
262,144
Wrong Answer
49
3,060
184
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a=int(input()) b=int(input()) c=int(input()) q=int(input()) ans=0 for i in range(a): for i in range(b): for i in range(c): if 500*a+100*b+50*c==q: ans+=1 print(ans)
s491800827
Accepted
50
3,060
191
a=int(input()) b=int(input()) c=int(input()) q=int(input()) ans=0 for i in range(a+1): for k in range(b+1): for p in range(c+1): if 500*i+100*k+50*p==q: ans+=1 print(ans)
s069718837
p03477
u140251125
2,000
262,144
Wrong Answer
18
2,940
139
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
A,B,C,D = map(int, input().split()) if A + B > C + D: print("Right") elif A + B < C + D: print("Left") else: print("Balanced")
s144445374
Accepted
18
2,940
139
A,B,C,D = map(int, input().split()) if A + B > C + D: print("Left") elif A + B < C + D: print("Right") else: print("Balanced")
s482045310
p03359
u519939795
2,000
262,144
Wrong Answer
18
2,940
55
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a,b = map(int,input().split()) print(a if a<b else a-1)
s256317976
Accepted
17
2,940
56
a,b = map(int,input().split()) print(a if a<=b else a-1)
s557498075
p03731
u112324182
2,000
262,144
Wrong Answer
213
26,836
268
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
n, t = map(int, list(input().split(' '))) ti = list(map(int, list(input().split(' ')))) result = 10 for i, item in enumerate(ti): temp = t if i == len(ti) - 1: break if ti[i+1] - ti[i] < t: temp = ti[i+1] - ti[i] result = result + temp print(result)
s971785766
Accepted
204
26,708
266
n, t = map(int, list(input().split(' '))) ti = list(map(int, list(input().split(' ')))) result = t for i, item in enumerate(ti): temp = t if i == len(ti) - 1: break if ti[i+1] - ti[i] < t: temp = ti[i+1] - ti[i] result = result + temp print(result)
s533060550
p03719
u210543511
2,000
262,144
Wrong Answer
17
2,940
94
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a, b, c = [int(i) for i in input().split()] if b<=c<=a: print('Yes') else: print('No')
s942739365
Accepted
16
2,940
94
a, b, c = [int(i) for i in input().split()] if a<=c<=b: print('Yes') else: print('No')
s846123356
p03476
u670180528
2,000
262,144
Wrong Answer
1,823
26,516
382
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
from collections import deque from bisect import bisect ref=deque() refref=deque() for i in range(3,100000,2): flag=1 for j in range(2,int(i**0.5)+1): if i%j==0: flag=0 break if flag: ref.append(i) for p in ref: if (p+1)//2 in ref: refref.append(p) q,*li=map(int,open(0).read().split()) for l,r in zip(li[::2],li[1::2]): print(bisect(refref,r+1)-bisect(refref,l-1))
s968170550
Accepted
1,757
26,280
385
from collections import deque from bisect import bisect ref=deque([2]) refref=deque() for i in range(3,100000,2): flag=1 for j in range(2,int(i**0.5)+1): if i%j==0: flag=0 break if flag: ref.append(i) for p in ref: if (p+1)//2 in ref: refref.append(p) q,*li=map(int,open(0).read().split()) for l,r in zip(li[::2],li[1::2]): print(bisect(refref,r+1)-bisect(refref,l-1))
s136732028
p03478
u243572357
2,000
262,144
Wrong Answer
40
3,060
151
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = map(int, input().split()) answer = 0 for i in range(1, n + 1): if a<= sum(list(map(int, list(str(n))))) <= b: answer += i print(answer)
s096617987
Accepted
37
3,060
148
n, a, b = map(int, input().split()) answer = 0 for i in range(n + 1): if a<= sum(list(map(int, list(str(i))))) <= b: answer += i print(answer)
s310296319
p03681
u463655976
2,000
262,144
Wrong Answer
43
3,064
214
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
M, N = map(int, input().split()) def fraction(N): a = 1 for x in range(N): a = (a * x) % (1e9 + 7) return a p = abs(M - N) if p < 2: print(fraction(M) * fraction(N) * (2 - p)) else: print(0)
s235254500
Accepted
41
3,060
238
M, N = map(int, input().split()) def fraction(N): a = N for x in range(N-1,1,-1): a = a * x % (1000000007) return a p = abs(M - N) if p < 2: print(fraction(M) * fraction(N) * (2 - p) % (1000000007)) else: print(0)
s679943545
p02843
u977661421
2,000
1,048,576
Wrong Answer
18
2,940
96
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
# -*- coding: utf-8 -*- x = int(input()) if 0 <= x % 100 <= 5: print(1) else: print(0)
s116847341
Accepted
72
3,864
327
x = int(input()) dp = [0 for _ in range(100000 + 1)] #0:"No", 1:"Yes" dp[0] = 1 for i in range(100, 106): dp[i] = 1 for i in range(106, x + 1): #if dp[i-100] == 1 or dp[i-101] == 1 or dp[i-102] == 1 or dp[i-103] == 1 or dp[i-104] == 1 or dp[i-105] == 1: if sum(dp[i-105:i-99]) >= 1: dp[i] = 1 print(dp[x])
s412620339
p04044
u792217717
2,000
262,144
Wrong Answer
17
3,060
88
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(" ")) ss = [input() for i in range(n)] print(''.join(ss))
s762947138
Accepted
17
3,060
98
n, l = map(int, input().split(" ")) ss = [input() for i in range(n)] ss.sort() print(''.join(ss))
s080476956
p03762
u785578220
2,000
262,144
Wrong Answer
127
18,624
182
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i. For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7. That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.
a,b = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) t = x[-1] -x[0] f = y[-1] -y[0] s = t*f v = 2**(a-1) c = 2**(b-1) print(s*v*c)
s133418917
Accepted
151
18,624
270
a,b = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) s = 0 k = 0 for i,t in enumerate(reversed(x)): s+= (a-i-1)*t s-= i*t for i,t in enumerate(reversed(y)): k+= (b-i-1)*t k-= i*t print((s*k)%(10**9+7))
s610281146
p03447
u486773779
2,000
262,144
Time Limit Exceeded
2,206
9,028
85
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
x=int(input()) a=int(input()) b=int(input()) af=x-a while af>0: af-b print(af)
s874872934
Accepted
27
8,956
94
x=int(input()) a=int(input()) b=int(input()) ans=x-a while ans>=b: ans=ans-b print(ans)
s408992045
p03359
u348403159
2,000
262,144
Time Limit Exceeded
2,104
2,940
231
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
numbers = input().split() a = numbers[0] b = numbers[1] i = 1 while True: if a != i: i += 1 continue else: if b < i: print(i - 1) else: print(i) break
s302902785
Accepted
17
2,940
254
numbers = input().split() a = int(numbers[0]) b = int(numbers[1]) i = 1 while True: if a != i: i += 1 continue else: if b < i: print(i - 1) break else: print(i) break
s723526023
p03730
u806403461
2,000
262,144
Wrong Answer
18
2,940
180
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int, input().split()) num = 0 while True: num += a if num % b == c: ans = 'YES' elif num % b < c: ans = 'NO' break print(ans)
s622080719
Accepted
17
2,940
142
a, b, c = map(int, input().split()) ans = 'NO' for i in range(1, b+1): if (a*i) % b == c: ans = 'YES' break print(ans)
s306979768
p03447
u698837729
2,000
262,144
Wrong Answer
19
3,316
45
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
print(int(input())-int(input())-int(input()))
s978678267
Accepted
19
3,316
74
X_A = int(input()) - int(input()) B = int(input()) print(X_A - (X_A//B)*B)
s975002529
p03048
u651480702
2,000
1,048,576
Wrong Answer
1,008
2,940
176
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
R, G, B, N = list(map(int, input().split())) ans = 0 for r in range(min(R+1, N+1)): for g in range(min(G+1, N-r+1)): if N-r-g <= B: ans += 1 print(ans)
s942104722
Accepted
1,504
2,940
176
R, G, B, N = list(map(int, input().split())) ans = 0 for r in range(N//R+1): for g in range((N-r*R)//G+1): if (N-r*R-g*G) % B == 0: ans += 1 print(ans)
s199698077
p02402
u806005289
1,000
131,072
Wrong Answer
20
5,588
158
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
n=int(input()) l=input().split() b=min(l) a=max(l) result=0 while n>=1: result=result+int(l[n-1]) n=n-1 print(str(b)+" "+str(a)+" "+str(result))
s056295846
Accepted
20
6,332
175
n=int(input()) l=input().split() b=min(map(int,l)) a=max(map(int,l)) result=0 while n>=1: result=result+int(l[n-1]) n=n-1 print(str(b)+" "+str(a)+" "+str(result))
s995559234
p03644
u881378225
2,000
262,144
Wrong Answer
17
2,940
78
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()) a=1 for i in range(7): if a >= N: break a*=2 print(a)
s849551371
Accepted
17
2,940
86
N=int(input()) a=1 for i in range(7): if a*2 > N: break a*=2 print(a)
s052738919
p03495
u636267225
2,000
262,144
Wrong Answer
142
24,748
339
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.
N,K = map(int,input().split()) A_list = list(map(int,input().split())) counter = [0]*(N+1) for i in A_list: counter[i] += 1 print(counter) zeronashi = [i for i in counter if i != 0] zeronashi.sort() length = len(zeronashi) x = length - K y = 0 if x < 1: print(0) else: for i in range(x): y += zeronashi[i] print(y)
s484237335
Accepted
127
24,836
326
N,K = map(int,input().split()) A_list = list(map(int,input().split())) counter = [0]*(N+1) for i in A_list: counter[i] += 1 zeronashi = [i for i in counter if i != 0] zeronashi.sort() length = len(zeronashi) x = length - K y = 0 if x < 1: print(0) else: for i in range(x): y += zeronashi[i] print(y)
s216179239
p03555
u791664126
2,000
262,144
Wrong Answer
17
2,940
41
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.
print('YNeos'[input()!=input()[::-1]::2])
s011852317
Accepted
17
2,940
42
print('YNEOS'[input()!=input()[::-1]::2])
s297064196
p00291
u888548672
1,000
131,072
Wrong Answer
20
5,608
104
4月に消費税が8%になってから、お財布が硬貨でパンパンになっていませんか。同じ金額を持ち歩くなら硬貨の枚数を少なくしたいですよね。硬貨の合計が1000円以上なら、硬貨をお札に両替して、お財布のメタボ状態を解消できます。 お財布の中の硬貨の枚数が種類ごとに与えられたとき、硬貨をお札に両替できるかどうかを判定するプログラムを作成してください。
c = list(map(int, input().split())) a = [1,5,10,50,100,500] print(sum([x * y for (x, y) in zip(c, a)]))
s186581305
Accepted
20
5,608
124
c = list(map(int, input().split())) a = [1,5,10,50,100,500] print(1 if sum([x * y for (x, y) in zip(c, a)]) >= 1000 else 0)
s684114972
p03352
u533885955
2,000
1,048,576
Wrong Answer
2,104
2,940
81
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
X = int(input()) count = 1 while X >= 1: X = X%2 count+=1 print(2**count)
s294941427
Accepted
80
3,060
291
X = int(input()) beki=[] for a in range(X): A=a+1 for i in range(32): I=i+1 j=0 for j in range(9): J=j+2 if A == I**J: beki.append(A) break elif A<I**J: break print(max(beki))
s423811493
p03854
u339851548
2,000
262,144
Wrong Answer
84
3,188
305
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() d = ['dream', 'dreamer', 'erase', 'eraser'] s = s[::-1] for i in range(len(d)): d[i]= d[i][::-1] while s != '': for j in range(len(d)): if s[0:len(d[j])] == d[j]: s = s[len(d[j]):] break else: print('No') break else: print('Yes')
s979063399
Accepted
87
3,188
305
s = input() d = ['dream', 'dreamer', 'erase', 'eraser'] s = s[::-1] for i in range(len(d)): d[i]= d[i][::-1] while s != '': for j in range(len(d)): if s[0:len(d[j])] == d[j]: s = s[len(d[j]):] break else: print('NO') break else: print('YES')
s760292999
p03351
u238084414
2,000
1,048,576
Wrong Answer
17
2,940
83
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = map(int, input().split()) if abs(a-c) < d: print("Yes") print("No")
s963241685
Accepted
19
2,940
129
a, b, c, d = map(int, input().split()) if (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d: print("Yes") else: print("No")
s110432180
p00018
u531482846
1,000
131,072
Wrong Answer
20
7,552
54
Write a program which reads five numbers and sorts them in descending order.
print(sorted(map(int, input().split()), reverse=True))
s105109126
Accepted
70
7,688
46
print(*sorted(map(int,input().split()))[::-1])
s918357314
p02614
u401086905
1,000
1,048,576
Wrong Answer
289
27,392
792
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import numpy as np H, W, K = map(int,input().split()) board = np.zeros((H, W), dtype=np.uint8) for h in range(H): S = input() print(S) for w in range(W): if S[w] == '#': board[h][w] = 1 hlist = board.sum(axis=1) wlist = board.sum(axis=0) hbitlist = np.asarray( [ (2**h)*(2**W) for h in range(H) ] ) wbitlist = np.asarray( [ 2**w for w in range(W) ] ) ret = 0 i = 0 loopnum = (2**H)*(2**W) while True: htarget = i & hbitlist wtarget = i & wbitlist sumnum = 0 for h in range(H): for w in range(W): if (htarget[h]==0) and (wtarget[w]==0): print(board[h][w]) sumnum += board[h][w] if sumnum == K: ret += 1 i+=1 if i>=loopnum: break print(ret)
s768764770
Accepted
227
27,128
739
import numpy as np H, W, K = map(int,input().split()) board = np.zeros((H, W), dtype=np.uint8) for h in range(H): S = input() for w in range(W): if S[w] == '#': board[h][w] = 1 hlist = board.sum(axis=1) wlist = board.sum(axis=0) hbitlist = np.asarray( [ (2**h)*(2**W) for h in range(H) ] ) wbitlist = np.asarray( [ 2**w for w in range(W) ] ) ret = 0 i = 0 loopnum = (2**H)*(2**W) while True: htarget = i & hbitlist wtarget = i & wbitlist sumnum = 0 for h in range(H): for w in range(W): if (htarget[h]==0) and (wtarget[w]==0): sumnum += board[h][w] if sumnum == K: ret += 1 i+=1 if i>=loopnum: break print(ret)
s522257636
p03110
u175590965
2,000
1,048,576
Wrong Answer
17
2,940
170
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
n = int(input()) rate = 38000.0 ans = 0.0 for i in range(n): x,u = input().split() x = float(x) ans += x*rate if u =='BTC' else x print('{:.11f}'.format(ans))
s162158514
Accepted
18
2,940
144
n=int(input()) ans=0 for i in range(n): x,u=input().split() x=float(x) if u == 'BTC': x=x*380000. ans+=x print(ans)
s403727915
p03720
u756988562
2,000
262,144
Wrong Answer
20
3,316
301
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 collections n,m=map(int,input().split()) # a = [] # b = [] temp = [] for i in range(m): tempa,tempb = map(int,input().split()) temp.append(tempa) temp.append(tempb) temp.sort() temp_count = collections.Counter(temp) print(temp_count) for i in range(1,n+1): print(temp_count[i])
s216052214
Accepted
22
3,436
304
import collections n,m=map(int,input().split()) # a = [] # b = [] temp = [] for i in range(m): tempa,tempb = map(int,input().split()) temp.append(tempa) temp.append(tempb) temp.sort() temp_count = collections.Counter(temp) # print(temp_count) for i in range(1,n+1): print(temp_count[i])