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
s495675854
p03160
u268793453
2,000
1,048,576
Wrong Answer
2,211
1,783,096
773
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()) A = [int(i) for i in input().split()] DP = [[0] * n for i in range(n)] if n % 2 == 1: for i in range(n): DP[i][i] = A[i] else: for i in range(n): DP[i][i] = -A[i] for i in range(1, n): for l in range(n-i): if (n - i) % 2 == 1: DP[l][l+i] = max(DP[l+1][l+i] + A[l], DP[l][l+i-1] + A[l+i]) else: DP[l][l+i] = min(DP[l+1][l+i] - A[l], DP[l][l+i-1] - A[l+i]) score = [0] * 2 l = 0 r = n - 1 for i in range(n-2): if A[l] + A[r - 1] > A[r] + A[l + 1]: score[i%2] += A[l] l += 1 else: score[i%2] += A[r] r -= 1 score[n%2] += max(A[l], A[r]) score[(n+1)%2] += min(A[l], A[r]) if n % 2 == 1: print(score[0] - score[1]) else: print(DP[0][n-1])
s021728595
Accepted
210
14,052
265
n = int(input()) H = [int(i) for i in input().split()] INF = 10 ** 18 DP = [INF] * n DP[0] = 0 for i in range(n-1): DP[i+1] = min(DP[i+1], DP[i] + abs(H[i+1] - H[i])) if i + 2 < n: DP[i+2] = min(DP[i+2], DP[i] + abs(H[i+2] - H[i])) print(DP[n-1])
s942973135
p03399
u523781418
2,000
262,144
Wrong Answer
17
2,940
107
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
a=int(input()) b=int(input()) c=int(input()) d=int(input()) if a+d>b+c: print(a+d) else: print(b+c)
s199581698
Accepted
19
3,060
155
a=int(input()) b=int(input()) c=int(input()) d=int(input()) temp=0 if a<b: temp+=a else: temp+=b if c<d: temp+=c else: temp+=d print(temp)
s023504055
p03486
u417835834
2,000
262,144
Wrong Answer
17
3,064
294
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
str_list1 = list(input()) str_list2 = list(input()) str_list2_inv = [i for i in sorted(str_list2)[::-1]] str1 = ''.join(sorted(str_list1)) str2 = ''.join(str_list2_inv) print(str1,str2) if str1 == str2: print('No') elif sorted([str1,str2])[0] == str1: print('Yes') else: print('No')
s847482695
Accepted
17
3,064
277
str_list1 = list(input()) str_list2 = list(input()) str_list2_inv = [i for i in sorted(str_list2)[::-1]] str1 = ''.join(sorted(str_list1)) str2 = ''.join(str_list2_inv) if str1 == str2: print('No') elif sorted([str1,str2])[0] == str1: print('Yes') else: print('No')
s628708057
p02608
u358859892
2,000
1,048,576
Wrong Answer
425
9,296
270
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
n = int(input()) ans = [0] * (n+1) for i in range(1, 100): for j in range(1, 100): for k in range(1, 100): tmp = i*i + j*j * k*k + i*j + j*k + i*k if tmp <= n: ans[tmp] += 1 for i in range(1, n+1): print(ans[i])
s706250373
Accepted
434
9,128
270
n = int(input()) ans = [0] * (n+1) for i in range(1, 100): for j in range(1, 100): for k in range(1, 100): tmp = i*i + j*j + k*k + i*j + j*k + i*k if tmp <= n: ans[tmp] += 1 for i in range(1, n+1): print(ans[i])
s076805920
p03485
u227085629
2,000
262,144
Wrong Answer
17
2,940
58
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.
import math a,b = map(int, input().split()) print((a+b)/2)
s099960732
Accepted
17
2,940
70
import math a,b = map(int, input().split()) print(math.ceil((a+b)/2))
s346581251
p02600
u140986701
2,000
1,048,576
Wrong Answer
30
9,192
328
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
x=int(input()) if(x<=400 and x>=599): print("8") elif(x<=600 and x>=799): print("7") elif(x<=800 and x>=999): print("6") elif(x<=1000 and x>=1199): print("5") elif(x<=1200 and x>=1399): print("4") elif(x<=1400 and x>=1599): print("3") elif(x<=1600 and x>=1799): print("2") elif(x<=1800 and x>=1999): print("1")
s919030325
Accepted
32
9,192
329
x=int(input()) if(x>=400 and x<=599): print("8") elif(x>=600 and x<=799): print("7") elif(x>=800 and x<=999): print("6") elif(x>=1000 and x<=1199): print("5") elif(x>=1200 and x<=1399): print("4") elif(x>=1400 and x<=1599): print("3") elif(x>=1600 and x<=1799): print("2") elif(x>=1800 and x<=1999): print("1")
s342384080
p02417
u867824281
1,000
131,072
Wrong Answer
20
7,544
833
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
word = input() word.lower() print("a",":",word.count("a")) print("b",":",word.count("b")) print("c",":",word.count("c")) print("d",":",word.count("d")) print("e",":",word.count("e")) print("f",":",word.count("f")) print("g",":",word.count("g")) print("h",":",word.count("h")) print("i",":",word.count("i")) print("j",":",word.count("j")) print("k",":",word.count("k")) print("l",":",word.count("l")) print("m",":",word.count("m")) print("n",":",word.count("n")) print("o",":",word.count("o")) print("p",":",word.count("p")) print("q",":",word.count("q")) print("r",":",word.count("r")) print("s",":",word.count("s")) print("t",":",word.count("t")) print("u",":",word.count("u")) print("v",":",word.count("v")) print("w",":",word.count("w")) print("x",":",word.count("x")) print("y",":",word.count("y")) print("z",":",word.count("z"))
s435394707
Accepted
20
7,432
163
import sys words = str() data = "abcdefghijklmnopqrstuvwxyz" for line in sys.stdin: words += line.lower() for i in data: print(i+" : "+str(words.count(i)))
s122013382
p03471
u210545407
2,000
262,144
Wrong Answer
1,048
3,064
358
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n, purpose = map(int, input().split(" ")) resultI = resultJ = resultK = -1 def combiValue(i, j, k): return 10000 * i + 5000 * j + 1000 * k for i in range(n+1): for j in range(n+1-i): k = n+1 - i - j if combiValue(i, j, k) == purpose: resultI = i resultJ = j resultK = k print("{0} {1} {2}".format(resultI, resultJ, resultK))
s808895559
Accepted
989
3,060
356
n, purpose = map(int, input().split(" ")) resultI = resultJ = resultK = -1 def combiValue(i, j, k): return 10000 * i + 5000 * j + 1000 * k for i in range(n+1): for j in range(n+1-i): k = n - i - j if combiValue(i, j, k) == purpose: resultI = i resultJ = j resultK = k print("{0} {1} {2}".format(resultI, resultJ, resultK))
s141735244
p03048
u626337957
2,000
1,048,576
Wrong Answer
1,459
9,056
182
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 = map(int, input().split()) answer = 0 for r in range(R): for g in range(G): if r + g > N or N - r - g > B: continue else: answer += 1 print(answer)
s037749901
Accepted
1,645
9,100
221
R, G, B, N = map(int, input().split()) answer = 0 for r in range(N//R+1): for g in range(N//G+1): if r*R + g*G > N: break elif (N-r*R-g*G)%B != 0: continue else: answer += 1 print(answer)
s664741226
p03435
u977349332
2,000
262,144
Wrong Answer
17
3,060
233
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.
c = [list(map(int, input().split())) for _ in range(3)] a2 = c[1][0] - c[0][0] a3 = c[2][0] - c[0][0] if any(c[1][x] != a2 + c[1][x] for x in [1, 2]) or any(c[2][x] != a3 + c[1][x] for x in [0, 2]): print('No') else: print('Yes')
s077960215
Accepted
18
3,064
234
c = [list(map(int, input().split())) for _ in range(3)] a2 = c[1][0] - c[0][0] a3 = c[2][0] - c[0][0] if any(c[1][x] != a2 + c[0][x] for x in [1, 2]) or any(c[2][x] != a3 + c[0][x] for x in [1, 2]): print('No') else: print('Yes')
s536149877
p02396
u675844759
1,000
131,072
Wrong Answer
130
7,624
100
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
cnt = 0 num = int(input()) while num != 0: print('Case {0}: {1}', ++cnt, num) num = int(input())
s104989470
Accepted
50
7,292
141
import sys cnt = 1 while 1: num=sys.stdin.readline().strip() if num == "0": break print('Case {0}: {1}'.format(cnt, num)) cnt+=1
s654284089
p03565
u530786533
2,000
262,144
Wrong Answer
17
3,064
414
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
s = input() t = input() if (len(s) < len(t)): print('UNRESTORABLE') exit() ns = len(s) nt = len(t) for i in range(0, ns-nt+1): x = s[i:i+nt] ok = 1 for j in range(nt): if (t[j] != x[j] and x[j] != '?'): ok = 0 break if (ok == 1): ss = s[0:i] + t if (i+nt < ns): ss = ss + s[i+nt] ss = ss.replace('?', 'a') exit() print('UNRESTORABLE')
s095748561
Accepted
17
3,060
339
s = input() t = input() ns = len(s) nt = len(t) for i in range(ns-nt, -1, -1): x = s[i:i+nt] for j in range(nt+1): if (j == nt): ss = s[:i] + t + s[i+nt:] print(ss.replace('?', 'a')) exit() if (x[j] == '?'): continue elif (x[j] != t[j]): break print('UNRESTORABLE')
s068663143
p03671
u902380746
2,000
262,144
Wrong Answer
18
3,060
247
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
import sys import math import bisect def main(): A = input().split() B = [] for i in range(len(A)): for j in range(i + 1, len(A)): B.append(A[i] + A[j]) print(min(B)) if __name__ == "__main__": main()
s686837830
Accepted
18
2,940
165
import sys import math import bisect def main(): A = list(map(int, input().split())) A.sort() print(sum(A[0:2])) if __name__ == "__main__": main()
s645197082
p03544
u623819879
2,000
262,144
Wrong Answer
18
2,940
76
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
n=int(input()) a=[2,1] for i in range(n-2): a+=[sum(a[-2:])] print(a[n-1])
s178655578
Accepted
17
2,940
73
n=int(input()) a=[2,1] for i in range(n): a+=[sum(a[-2:])] print(a[n])
s973936559
p03493
u382303205
2,000
262,144
Wrong Answer
17
2,940
25
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.
print(input().count("0"))
s650114929
Accepted
17
2,940
25
print(input().count("1"))
s507814954
p03679
u973108807
2,000
262,144
Wrong Answer
18
3,060
124
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int, input().split()) if a < b: print('delicious') elif a + x <= b: print('safe') else: print('dangerous')
s231989658
Accepted
17
2,940
125
x,a,b = map(int, input().split()) if a >= b: print('delicious') elif a + x >= b: print('safe') else: print('dangerous')
s038460254
p02972
u202570162
2,000
1,048,576
Wrong Answer
1,404
53,448
818
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.
#AGC018-A if False: import fractions N,K=map(int,input().split()) A=[int(i) for i in input().split()] MAX=max(A) GCD=A[0] for a in A: GCD=fractions.gcd(a,GCD) if K%GCD==0 and K<=MAX: print('POSSIBLE') else: print('IMPOSSIBLE') #ABC134-D if True: M=int(input()) B=[int(i) for i in input().split()] fact=[[1] for i in range(M)] for i in range(2,M+1): k=2 while k*i<=M: fact[k*i-1].append(i) k+=1 # print(fact) ANS=[0 for i in range(M)] for i in reversed(range(M)): if (i+1)*2>M: ANS[i]=B[i] for j in fact[i]: ANS[j-1]+=ANS[i] else: if B[j]!=(ANS[j]%2): ANS[j]+=1 # print(ANS) print(ANS)
s999142794
Accepted
1,698
62,616
1,065
#ABC134-D if True: N=int(input()) A=[int(i) for i in input().split()] fact=[[1] for i in range(N)] for i in range(2,N+1): k=2 while k*i<=N: fact[k*i-1].append(i) k+=1 # print(fact) SUM=[0 for i in range(N)] ANS=[] for i in reversed(range(N)): if (i+1)*2>N: if A[i]==1: ANS.append(i+1) SUM[i]=A[i] for j in fact[i]: SUM[j-1]=(SUM[j-1]+A[i])%2 else: if SUM[i]==1: if A[i]==1: continue else: ANS.append(i+1) SUM[i]=1 for j in fact[i]: SUM[j-1]=(SUM[j-1]+1)%2 else: if A[i]==0: continue else: ANS.append(i+1) SUM[i]=1 for j in fact[i]: SUM[j-1]=(SUM[j-1]+1)%2 print(len(ANS)) print(' '.join(map(str,ANS)))
s754485478
p02401
u606989659
1,000
131,072
Wrong Answer
20
7,528
287
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a, op, b = map(str,input().split()) if op == '+': print(int(a) + int(b)) elif op == '-': print(int(a) - int(b)) elif op == '*': print(int(a) * int(b)) elif op == '/': print(int(a) / int(b)) elif op == '?': break
s322566324
Accepted
20
7,504
288
while True: a, op, b = map(str,input().split()) if op == '+': print(int(a) + int(b)) elif op == '-': print(int(a) - int(b)) elif op == '*': print(int(a) * int(b)) elif op == '/': print(int(a) // int(b)) elif op == '?': break
s639462714
p03599
u667024514
3,000
262,144
Wrong Answer
124
3,188
686
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.
a ,b ,c ,d ,e ,f = map(int,input().split()) water = set() sugar = set() cou = 0 co = 0 for i in range(f//b): cou = 0 while 100 * b * i + 100 * a * cou <= f: water.add(100 * b * i + 100 * a * cou) cou += 1 water = sorted(water) print(water) for i in range(f//d): cow = 0 while d * i + c * cow <= f: sugar.add(d * i + c * cow) cow += 1 sugar = sorted(sugar) print(sugar) ans = [0,0,0] for wat in water: for sug in sugar: if wat or sug: if wat + sug <= f and e / (100 + e) >= sug/(wat+sug): if ans[0] <= sug/(wat+sug): ans = [sug/(wat+sug), wat+sug, sug] print(ans[1],ans[2])
s807184162
Accepted
132
3,188
662
a ,b ,c ,d ,e ,f = map(int,input().split()) water = set() sugar = set() cou = 0 co = 0 for i in range(f//b): cou = 0 while 100 * b * i + 100 * a * cou <= f: water.add(100 * b * i + 100 * a * cou) cou += 1 water = sorted(water) for i in range(f//d): cow = 0 while d * i + c * cow <= f: sugar.add(d * i + c * cow) cow += 1 sugar = sorted(sugar) ans = [0,0,0] for wat in water: for sug in sugar: if wat or sug: if wat + sug <= f and e / (100 + e) >= sug/(wat+sug): if ans[0] <= sug/(wat+sug): ans = [sug/(wat+sug), wat+sug, sug] print(ans[1],ans[2])
s411332911
p03730
u349444371
2,000
262,144
Wrong Answer
17
2,940
185
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()) if a%2==0 and b%2==0 and c%2==1: print("NO") else: print("Yes")
s015784306
Accepted
17
2,940
218
a,b,c=map(int,input().split()) x=0 for i in range(1,b+1): if i*a%b==c: x+=1 if x==0: print("NO") else: print("YES")
s121514586
p02410
u711765449
1,000
131,072
Wrong Answer
30
7,768
431
Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \\[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\\ a_{21} & a_{22} & ... & a_{2m} \\\ : & : & : & : \\\ a_{n1} & a_{n2} & ... & a_{nm} \\\ \end{array} \right) \\] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \\[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \\]
# -*- coding:utf-8 -*- row, col = map(int,input().split()) mat = [[0 for i2 in range(col)] for i1 in range(row)] for i in range(row): mat[i] = list(map(float,input().split())) vec = [0 for i in range(col)] for i in range(col): vec[i] = float(input()) result = [0 for i in range(col)] for i in range(row): for j in range(col): result[i] += mat[i][j]*vec[j] for i in range(len(result)): print(result[i])
s027883107
Accepted
20
7,960
413
row, col = map(int,input().split()) mat = [[0 for i2 in range(col)] for i1 in range(row)] for i in range(row): mat[i] = list(map(float,input().split())) vec = [0 for i in range(col)] for i in range(col): vec[i] = float(input()) result = [0 for i in range(row)] for i in range(row): for j in range(col): result[i] += mat[i][j]*vec[j] for i in range(len(result)): print(int(result[i]))
s008951823
p03478
u300269535
2,000
262,144
Wrong Answer
39
3,060
265
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(' ')) count = 0 for i in range(1, n+1): letter_list = [] for letter in str(i): letter_list.append(letter) num_list = list(map(int, letter_list)) if a <= sum(num_list) <= b: count += 1 print(count)
s617183209
Accepted
41
3,060
265
n, a, b = map(int, input().split(' ')) total = 0 for i in range(1, n+1): letter_list = [] for letter in str(i): letter_list.append(letter) num_list = list(map(int, letter_list)) if a <= sum(num_list) <= b: total += i print(total)
s869152698
p03827
u143318682
2,000
262,144
Wrong Answer
17
3,064
338
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).
# -*- coding: utf-8 -*- N = int(input()) S = input() I_count = [i for i, x in enumerate(S) if x == 'I'] D_count = [i for i, x in enumerate(S) if x == 'D'] tmp = [0] * N for i in I_count: tmp[i] = 1 for i in D_count: tmp[i] = -1 ans = 0 List = [] for i in range(N): ans += tmp[i] List.append(ans) print(max(0, ans))
s574350279
Accepted
17
3,064
340
# -*- coding: utf-8 -*- N = int(input()) S = input() I_count = [i for i, x in enumerate(S) if x == 'I'] D_count = [i for i, x in enumerate(S) if x == 'D'] tmp = [0] * N for i in I_count: tmp[i] = 1 for i in D_count: tmp[i] = -1 ans = 0 List = [] for i in range(N): ans += tmp[i] List.append(ans) print(max(0, max(List)))
s303418673
p02406
u789974879
1,000
131,072
Wrong Answer
20
5,456
1
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
s343578264
Accepted
60
5,624
534
n = int(input()) x = 1 y = "" z = 1 while True: z = 1 x += 1 if x % 3 == 0: y += " " y += str(x) else: while True: b = int(x % 10 ** (z - 1)) a = int((x - b) / 10 ** z) c = a % 10 ** z d = a % 10 ** (z - 1) if a == 3 or b == 3 or c == 3 or d == 3: y += " " y += str(x) break z += 1 if a < 3 and z > 3: break if x >= n: break print(y)
s992123807
p02397
u892219101
1,000
131,072
Wrong Answer
50
7,524
94
Write a program which reads two integers x and y, and prints them in ascending order.
while 1: a,b=map(int,input().split()) if a+b==0: break elif a>b: print(b,a) print(a,b)
s318999566
Accepted
60
7,620
105
while 1: a,b=map(int,input().split()) if a+b==0: break elif a>b: print(b,a) continue print(a,b)
s223782423
p03672
u785066634
2,000
262,144
Wrong Answer
17
2,940
519
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
l=list(input()) for i in range(len(l)): del l[-1] if len(l)%2!=0: del l[-1] #print('1',l) if len(l)%2==0: if l[:len(l)//2]==l[len(l)//2:]: #print('2',l,'len(l)',len(l)) exit() else: del l[-1] #print('3',l)
s174973860
Accepted
17
2,940
503
l=list(input()) for i in range(len(l)): del l[-1] if len(l)%2!=0: del l[-1] #print('1',l) if len(l)%2==0: if l[:len(l)//2]==l[len(l)//2:]: print(len(l)) exit() else: del l[-1] #print('3',l)
s697506549
p03130
u893063840
2,000
1,048,576
Wrong Answer
17
2,940
191
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
li = [] for _ in range(3): li += list(map(int, input().split())) mx = 0 for i in range(1, 5): mx = max(mx, li.count(i)) if mx == 3: ans = "No" else: ans = "Yes" print(ans)
s746774218
Accepted
17
2,940
191
li = [] for _ in range(3): li += list(map(int, input().split())) mx = 0 for i in range(1, 5): mx = max(mx, li.count(i)) if mx == 3: ans = "NO" else: ans = "YES" print(ans)
s912757964
p02235
u810922275
1,000
131,072
Wrong Answer
20
5,600
413
For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
ans=[] n=int(input("n=")) for i in range(n): X=input("X=") Y=input("Y=") com=[0] for i in X: for j in range(len(com)-1,-1,-1): tmp=X.find(i,com[j])+1 if tmp: if j+1<len(com): com[j+1]=min(com[j+1],tmp) else: com.append(tmp) ans.append(len(com)-1) for i in range(n): print(ans[i])
s388039487
Accepted
4,460
5,612
401
ans=[] n=int(input()) for i in range(n): X=input() Y=input() com=[0] for i in Y: for j in range(len(com)-1,-1,-1): tmp=X.find(i,com[j]) if tmp+1: if j+1<len(com): com[j+1]=min(com[j+1],tmp+1) else: com.append(tmp+1) ans.append(len(com)-1) for i in range(n): print(ans[i])
s119941012
p03007
u360090862
2,000
1,048,576
Wrong Answer
252
14,264
294
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.
N=int(input()) A=[int(i) for i in input().split()] B=[] A=sorted(A) M=0 for i in range(N): if i<N//2: M-=A[i] else: M+=A[i] print(M) for i in range(N//2): print(A[i],A[N-i-1]) B.append(A[i]-A[N-i-1]) if N%2==1: B.append(A[N//2]) B=sorted(B) for i in range(len(B)-1): print(B[-1],B[i])
s562858781
Accepted
223
14,076
273
N=int(input()) A=[int(i) for i in input().split()] B=[] A=sorted(A) M=0 amin=A[0] amax=A[-1] for a in A[1:N-1]: if a<0: M-=a else: M+=a print(M-amin+amax) for a in A[1:N-1]: if a<0: print(amax,a) amax=amax-a else: print(amin,a) amin=amin-a print(amax,amin)
s989112122
p03081
u198440493
2,000
1,048,576
Wrong Answer
1,768
41,364
1,151
There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square. Snuke cast Q spells to move the golems. The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke cast this spell, for each square with the character t_i, all golems on that square moved to the square adjacent to the left if d_i is `L`, and moved to the square adjacent to the right if d_i is `R`. However, when a golem tried to move left from Square 1 or move right from Square N, it disappeared. Find the number of golems remaining after Snuke cast the Q spells.
n,q=map(int,input().split()) c=input() s=[input().split() for _ in [0]*q] def judge(x,opt): for y in s: if y[0]==c[x]: if y[1]=='L': x-=1 else: x+=1 if not opt: if x>=n: return False elif x<0: return True else: if x<0: return False elif x>=n: return True return False def bisect(l,r,opt): print(l,r) center=(r+l)//2 if judge(center,opt): if r-l<=1: if not opt: return l+1 else: return n-l if not opt: return bisect(center+1,r,opt) else: return bisect(l,center,opt) else: if r-l<=1: if not opt: return l else: return n-r if not opt: return bisect(l,center,opt) else: return bisect(center+1,r,opt) def func(): l=bisect(0,n,0) r=bisect(0,n,1) print(l,r) print(n-l-r) func()
s301728111
Accepted
1,793
41,368
1,121
n,q=map(int,input().split()) c=input() s=[input().split() for _ in [0]*q] def judge(x,opt): for y in s: if y[0]==c[x]: if y[1]=='L': x-=1 else: x+=1 if not opt: if x>=n: return False elif x<0: return True else: if x<0: return False elif x>=n: return True return False def bisect(l,r,opt): center=(r+l)//2 if judge(center,opt): if r-l<=1: if not opt: return l+1 else: return n-l if not opt: return bisect(center+1,r,opt) else: return bisect(l,center,opt) else: if r-l<=1: if not opt: return l else: return n-r if not opt: return bisect(l,center,opt) else: return bisect(center+1,r,opt) def func(): l=bisect(0,n,0) r=bisect(0,n,1) print(n-l-r) func()
s711619944
p03836
u350997995
2,000
262,144
Wrong Answer
17
3,060
189
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty = map(int,input().split()) ans = "U"*(tx-sx)+"R"*(ty-sx)+"D"*(tx-sx)+"L"*(ty-sx) ans += "L"+"U"*(tx-sx+1)+"R"*(ty-sx+1)+"D" ans += "R"+"D"*(tx-sx+1)+"L"*(ty-sx+1)+"U" print(ans)
s618224143
Accepted
18
3,060
189
sx,sy,tx,ty = map(int,input().split()) ans = "U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx) ans += "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D" ans += "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U" print(ans)
s900603673
p03415
u604262137
2,000
262,144
Wrong Answer
17
2,940
62
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.
for i in range(2): sanmoji = input() print(sanmoji[i])
s741834075
Accepted
17
2,940
124
sanmoji=[0]*3 for i in range(3): sanmoji[i] = input()[i] moji="" for i in range(3): moji += sanmoji[i] print(moji)
s444693788
p03568
u225388820
2,000
262,144
Wrong Answer
17
2,940
97
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
n=int(input()) a=list(map(int,input().split())) f=1 for i in a: if i&1: f=0 print(3**n-1-f)
s926661146
Accepted
18
2,940
100
n=int(input()) a=list(map(int,input().split())) f=1 for i in a: if i%2==0: f<<=1 print(3**n-f)
s591966588
p02694
u057668615
2,000
1,048,576
Wrong Answer
23
9,156
96
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()) val = 100 cnt = 0 while val <= X: val += val//100 cnt += 1 print(cnt)
s542264602
Accepted
24
9,152
95
X = int(input()) val = 100 cnt = 0 while val < X: val += val//100 cnt += 1 print(cnt)
s310369692
p03998
u539018546
2,000
262,144
Wrong Answer
18
3,064
401
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() x=A[0] while (len(A)!=0)or(len(B)!=0)or (len(C)!=0): if x =="a": x=A[0] A=A[1:] if A=="": print("A") exit() elif x=="b": x=B[0] B=B[1:] if B=="": print("B") exit() else: x=C[0] C=C[1:] if C=="": print("C") exit()
s352435993
Accepted
18
3,064
417
A=input() B=input() C=input() x=A[0] while (len(A)!=0)or(len(B)!=0)or (len(C)!=0): if x =="a": if A=="": print("A") exit() x=A[0] A=A[1:] elif x=="b": if B=="": print("B") exit() x=B[0] B=B[1:] elif x=="c": if C=="": print("C") exit() x=C[0] C=C[1:]
s446911017
p03369
u625495026
2,000
262,144
Wrong Answer
19
2,940
145
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s = input() counter = 0 if s[0] == "○": counter += 1 if s[1] == "○": counter += 1 if s[2] == "○": counter += 1 print(700+100*counter)
s363224456
Accepted
16
2,940
33
print(700+input().count('o')*100)
s477407002
p03438
u898967808
2,000
262,144
Wrong Answer
30
9,020
81
You are given two integer sequences of length N: a_1,a_2,..,a_N and b_1,b_2,..,b_N. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal. Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions **simultaneously** : * Add 2 to a_i. * Add 1 to b_j.
s = input() if (len(s)+1)//2 == s.count('hi'): print('Yes') else: print('No')
s343534006
Accepted
36
10,520
254
n = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) k = sum(B)-sum(A) cb = sum([a-b for b,a in zip(B,A) if b<a]) ca = sum([(b-a+1)//2 for b,a in zip(B,A) if b>a]) if ca<=k and cb<= k: print('Yes') else: print('No')
s279136769
p03455
u124063060
2,000
262,144
Wrong Answer
17
2,940
95
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()) mul = a*b if mul==0: print("Even") else: print("Odd")
s321143233
Accepted
19
2,940
97
a, b = map(int, input().split()) mul = a*b if mul%2==0: print("Even") else: print("Odd")
s913408187
p02612
u590853144
2,000
1,048,576
Wrong Answer
28
9,140
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
a=int(input()) print(a%1000)
s124018025
Accepted
33
9,156
40
a=int(input()) print((1000-a%1000)%1000)
s088233128
p03416
u697696097
2,000
262,144
Wrong Answer
140
3,060
189
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
a,b=map(int,input().split()) cnt=0 for i in range(a,b+1): s=str(i) for j in range(len(s)//2): same=1 if s[j]!=s[-1*(j+1)]: same=0 if same==1: cnt+=1 print(cnt)
s466690870
Accepted
50
2,940
126
a,b=map(int,input().split()) cnt=0 for i in range(a,b+1): s=str(i) if s[0]==s[-1] and s[1]==s[-2]: cnt+=1 print(cnt)
s900039139
p03698
u864453204
2,000
262,144
Wrong Answer
17
2,940
117
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = list(input()) n = set(s) ans = 'yes' for nn in n: if s.count(nn): ans = 'no' break print(ans)
s526078965
Accepted
17
2,940
122
s = list(input()) n = set(s) ans = 'yes' for nn in n: if s.count(nn) != 1: ans = 'no' break print(ans)
s597222199
p02418
u369313788
1,000
131,072
Wrong Answer
20
7,336
215
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s = input() P = input() e = s + s x = len(P) m = 0 count = 0 for i in range(len(s)): if P == e[m:x]: count += 1 m += 1 x += 1 if count >= 1: print("Yes") else: print("No")
s814694484
Accepted
30
7,472
199
s = input() P = input() e = s + s x = len(P) m = 0 count = 0 for i in range(len(s)): if P == e[m:x]: count += 1 m += 1 x += 1 if count >= 1: print("Yes") else: print("No")
s392502342
p03471
u981449436
2,000
262,144
Wrong Answer
2,104
3,064
381
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N, Y = map(int, input().split()) n, m, l = -1, -1, -1 flag = False for i in range(N, -1, -1): for j in range(N-i, -1, -1): for k in range(N-i-j, -1, -1): if Y == 10000 * i + 5000 * j + 1000 * k: flag = True n, m, l = i, j, k break if flag: break if flag: break print(n, m, l)
s940653868
Accepted
839
3,060
214
n, y = map(int, input().split()) a, b, c = -1, -1, -1 for i in range(n+1): for j in range(n-i+1): k = n - i - j if 10000*i + 5000*j + 1000*k == y: a, b, c = i, j, k print(a, b, c)
s911840399
p03577
u045939752
2,000
262,144
Wrong Answer
17
2,940
19
Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For example, `CODEFESTIVAL` is a festival of `CODE`.
print(input()[-8:])
s115256796
Accepted
18
2,940
19
print(input()[:-8])
s568663960
p02409
u222716853
1,000
131,072
Wrong Answer
20
5,612
788
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
num = input() L = [] house = [] for i in range(int(num)): k = input().split() k[0] = int(k[0]) k[1] = int(k[1]) k[2] = int(k[2]) k[3] = int(k[3]) L.append(k) for i in range(3): a = ["0","0","0","0","0","0","0","0","0","0","0"] b = ["0","0","0","0","0","0","0","0","0","0","0"] c = ["0","0","0","0","0","0","0","0","0","0","0"] d = ["#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"] house.append([a,b,c,d]) a = ["0","0","0","0","0","0","0","0","0","0","0"] b = ["0","0","0","0","0","0","0","0","0","0","0"] c = ["0","0","0","0","0","0","0","0","0","0","0"] house.append([a,b,c]) for i in L: house[i[0]-1][i[1]-1][i[2]-1] = str(i[3]) for i in house: for j in i: k = "".join(j) print(k)
s374168280
Accepted
20
5,620
741
num = input() L = [] house = [] for i in range(int(num)): k = input().split() k[0] = int(k[0]) k[1] = int(k[1]) k[2] = int(k[2]) k[3] = int(k[3]) L.append(k) for i in range(3): a = ["","0","0","0","0","0","0","0","0","0","0"] b = ["","0","0","0","0","0","0","0","0","0","0"] c = ["","0","0","0","0","0","0","0","0","0","0"] d = ["#"*20] house.append([a,b,c,d]) a = ["","0","0","0","0","0","0","0","0","0","0"] b = ["","0","0","0","0","0","0","0","0","0","0"] c = ["","0","0","0","0","0","0","0","0","0","0"] house.append([a,b,c]) for i in L: house[i[0]-1][i[1]-1][i[2]] = str(int(house[i[0]-1][i[1]-1][i[2]])+i[3]) for i in house: for j in i: k = " ".join(j) print(k)
s195687882
p02795
u088488125
2,000
1,048,576
Wrong Answer
26
9,056
82
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
h=int(input()) w=int(input()) n=int(input()) print(min((h+n-1)//h+1,(w+n-1)//w+1))
s236110181
Accepted
29
9,068
78
h=int(input()) w=int(input()) n=int(input()) print(min((n+h-1)//h,(n+w-1)//w))
s491373083
p03544
u754022296
2,000
262,144
Wrong Answer
17
2,940
112
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
n = int(input()) L = [0]*(n+1) L[0] = 2 L[1] = 1 for i in range(3, n+1): L[i] = L[i-2] + L[i-1] print(L[n])
s055884597
Accepted
17
2,940
112
n = int(input()) L = [0]*(n+1) L[0] = 2 L[1] = 1 for i in range(2, n+1): L[i] = L[i-2] + L[i-1] print(L[n])
s546440773
p03846
u875600867
2,000
262,144
Wrong Answer
102
20,064
674
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
import collections N = int(input()) A = list(map(int, input().split())) c = collections.Counter(A) print(c) if len(A)%2==0: if list(c.values()).count(2) == (len(A) // 2 ): print(len(c.values())**2) else: print(0) else: if list(c.values()).count(2) == (len(A) // 2 ) and c[0] == 1: print((len(c.values())-1)**2) else: print(0)
s983766646
Accepted
57
14,812
735
import collections N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 c = collections.Counter(A) if len(A) ==1 and A[0]==0: print(1) elif len(A)%2==0: if list(c.values()).count(2) == (len(A) // 2 ): print(2**(len(c.values()))%mod) else: print(0) else: if list(c.values()).count(2) == (len(A) // 2 ) and c[0] == 1: print((2**(len(c.values())-1))%mod) else: print(0)
s063911755
p02256
u852112234
1,000
131,072
Wrong Answer
20
5,592
193
Write a program which finds the greatest common divisor of two natural numbers _a_ and _b_
x,y = map(int,input().split()) def swap(x,y): temp = x x = y y = temp def gcd(x,y): if x<y: swap(x,y) while(x == y): x = x%y swap(x,y) print(x)
s782571631
Accepted
20
5,600
246
x,y = map(int,input().split()) def swap(x,y): temp = x x = y y = temp return(x,y) def gcd(x,y): if x < y: x,y= swap(x,y) while(x != y and y != 0): x = x%y x,y = swap(x,y) print(x) gcd(x,y)
s458613368
p03965
u567434159
2,000
262,144
Wrong Answer
35
3,316
218
AtCoDeer the deer and his friend TopCoDeer is playing a game. The game consists of N turns. In each turn, each player plays one of the two _gestures_ , _Rock_ and _Paper_ , as in Rock-paper-scissors, under the following condition: (※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock). Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors. _(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)_ With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts. Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score. The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is `g`, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in `p`, TopCoDeer will play Paper in the i-th turn.
s = input() score = 0 toUse = 0 for it in s: if it == 'g' and toUse > 0: toUse -= 1 score += 1 continue if it == 'g': continue if toUse > 0: toUse -= 1 else: score -=1 print(score)
s955567651
Accepted
40
3,316
248
s = input() score = 0 toUse = 0 for it in s: if it == 'g' and toUse > 0: toUse -= 1 score += 1 continue if it == 'g': toUse += 1 continue if toUse > 0: toUse -= 1 else: toUse += 1 score -=1 print(score)
s528650886
p03574
u821251381
2,000
262,144
Wrong Answer
31
3,444
376
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()) A = [] for i in range(H): A.append(list(input())) for h in range(H): for w in range(W): if A[h][w] == "#": print("#",end="") elif A[h][w] == ".": c = 0 for i in range(-1,2): for j in range(-1,2): if 0<=h+i<=h and 0<=w+j<=w and A[h+i][w+j]=="#": c+=1 print(c,end="") print("")
s555955238
Accepted
35
3,444
380
H,W = map(int,input().split()) A = [] for i in range(H): A.append(list(input())) for h in range(H): for w in range(W): if A[h][w] == "#": print("#",end="") elif A[h][w] == ".": c = 0 for i in range(-1,2): for j in range(-1,2): if 0<=h+i<=H-1 and 0<=w+j<=W-1 and A[h+i][w+j]=="#": c+=1 print(c,end="") print("")
s173075292
p03228
u114366889
2,000
1,048,576
Wrong Answer
17
3,060
178
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
A, B, K= map(int, input().split()) for i in range(int(K)): if A % 2 != 0 : A += -1 B += A/2 A -= A/2 if B % 2 != 0 : B+= -1 A += B/2 B -= B/2 print(int(A) , int(B))
s240275836
Accepted
18
3,060
200
A, B, K= map(int, input().split()) for i in range(int(K)): if i % 2 == 0: if A % 2 != 0 : A += -1 B += A/2 A -= A/2 else: if B % 2 != 0 : B+= -1 A += B/2 B -= B/2 print(int(A) , int(B))
s954596395
p03679
u923659712
2,000
262,144
Wrong Answer
18
2,940
119
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b=map(int,input().split()) if b>=a: print("delicious") elif x+a>=b: print("safe") else: print("dangerous")
s550779648
Accepted
17
2,940
116
x,a,b=map(int,input().split()) if b<=a: print("delicious") elif x+a>=b: print("safe") else: print("dangerous")
s257924286
p03578
u177040005
2,000
262,144
Wrong Answer
2,105
36,820
407
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
N = int(input()) D = sorted(list(map(int, input().split()))) M = int(input()) T = sorted(list(map(int, input().split()))) if N < M: print('No') else: ind = 0 for t in T: for i,d in enumerate(D[ind:]): if d == t: # print(ind,D[ind:]) ind += i + 1 break else: print('No') exit() print('Yes')
s760442578
Accepted
452
57,312
340
import collections N = int(input()) D = sorted(list(map(int, input().split()))) M = int(input()) T = sorted(list(map(int, input().split()))) DD = collections.Counter(D) TT = collections.Counter(T) ch = 1 for t,num_t in TT.items(): num_d = DD[t] if num_t > num_d: ch = 0 if ch == 1: print('YES') else: print('NO')
s125457828
p04044
u397942996
2,000
262,144
Wrong Answer
18
3,060
108
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()) list_a = [str(input()) for i in range(N)] list_a.sort() print(list_a[0])
s182670256
Accepted
17
3,060
182
N, L = map(int, input().split()) list_a = [input() for i in range(N)] list_a.sort() list_b = "".join(list_a) print(list_b)
s309000394
p03854
u223904637
2,000
262,144
Wrong Answer
19
3,956
513
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`.
l=list(input()) a=[list('dream'),list('erase')] b=[list('dreamer'),list('eraser')] n=len(l) r=0 while n<=4: f=0 if n>=6: if l[len(l)-5:] in a: l[len(l)-5:]=[] n-=5 f+=1 if l[len(l)-6:] in b: l[len(l)-6:]=[] n-=6 f+=1 elif n>=5: if l[len(l)-5:] in a: l[len(l)-5:]=[] n-=5 f+=1 if f==0: r=1 break if r==1 or n>0: print('NO') else: print('YES')
s517454746
Accepted
38
4,084
809
l=list(input()) a=[list('dream'),list('erase')] b=[list('eraser')] c=[list('dreamer')] n=len(l) r=0 while n>=5: f=0 if n>=7: if l[len(l)-5:] in a: l[len(l)-5:]=[] n-=5 f+=1 if l[len(l)-6:] in b: l[len(l)-6:]=[] n-=6 f+=1 if l[len(l)-7:] in c: l[len(l)-7:]=[] n-=7 f+=1 elif n>=6: if l[len(l)-5:] in a: l[len(l)-5:]=[] n-=5 f+=1 if l[len(l)-6:] in b: l[len(l)-6:]=[] n-=6 f+=1 elif n>=5: if l[len(l)-5:] in a: l[len(l)-5:]=[] n-=5 f+=1 if f==0: r=1 break if r==1 or n>0: print('NO') else: print('YES')
s483357875
p03141
u058861899
2,000
1,048,576
Wrong Answer
383
16,100
293
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] x = [0 for i in range(n)] for i in range(n): a[i],b[i]=map(int,input().split()) x[i]=a[i]-b[i] s=sorted(x,reverse=True) nu=n//2 mod=n%2 count=0 for i in range(nu+mod): count+=s[i*2] print(count)
s673134273
Accepted
595
25,580
446
n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] x = [[0,0,0] for i in range(n)] for i in range(n): a[i],b[i]=map(int,input().split()) x[i][0]=abs(a[i]+b[i]) x[i][1]=a[i] x[i][2]=b[i] s=sorted(x,reverse=True) #print(s) nu=n//2 mod=n%2 count=0 for i in range(nu): count+=s[i*2][1] # print(count) count-=s[i*2+1][2] # print(count) if mod==1: count+=s[2*nu][1] print(count)
s190656032
p03698
u806855121
2,000
262,144
Wrong Answer
17
2,940
103
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
S = input() d = set() for s in S: d.add(s) if len(S) == d: print('yes') else: print('no')
s352501025
Accepted
17
2,940
108
S = input() d = set() for s in S: d.add(s) if len(S) == len(d): print('yes') else: print('no')
s342465320
p03694
u657541767
2,000
262,144
Wrong Answer
17
2,940
131
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along _TopCoDeer street_. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.
n = int(input()) a = list(set(map(int, input().split()))) res = 0 for i in range(len(a) - 1): res += a[i+1] - a[i] print(res)
s127300046
Accepted
17
2,940
129
n = int(input()) a = list(map(int, input().split())) a.sort() res = 0 for i in range(n - 1): res += a[i+1] - a[i] print(res)
s630533203
p03455
u055507189
2,000
262,144
Wrong Answer
17
2,940
92
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()) c = a*b if c%2 == 0 : print("even") else : print("odd")
s321958555
Accepted
17
2,940
96
a, b = map(int, input().split()) c = a*b if c%2 == 0 : print("Even") else : print("Odd")
s579334578
p03470
u923285281
2,000
262,144
Wrong Answer
17
3,064
243
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?
mochi_list = [] N = int(input()) for i in range(N): mochi_list.append(int(input())) last_mochi = 0 count = 0 for mochi in sorted(mochi_list): if last_mochi == mochi: break last_mochi = mochi count += 1 print(count)
s845975078
Accepted
18
2,940
283
# -*- coding: utf-8 -*- mochi_list = [] N = int(input()) for i in range(N): d = int(input()) mochi_list.append(d) last_mochi = 101 count = 0 for mochi in sorted(mochi_list, reverse=True): if mochi < last_mochi: count += 1 last_mochi = mochi print(count)
s949916942
p03943
u316603606
2,000
262,144
Wrong Answer
27
8,924
127
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.
l = input ().split () list.sort (l, reverse=True) a = l[0] b = l[1] c = l[2] if a+b == c: print ('Yes') else: print ('No')
s200936957
Accepted
32
9,040
133
l = [int(x) for x in input().split()] if l[2]==l[0]+l[1] or l[0]==l[1]+l[2] or l[1]==l[0]+l[2]: print ('Yes') else: print ('No')
s430225941
p03862
u050428930
2,000
262,144
Wrong Answer
113
14,132
226
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
N,M=map(int,input().split()) s=list(map(int,input().split())) w=0 if s[0]+s[1]>M and s[1]<M: s[1]=0 w+=s[0]-M for i in range(0,N-1): if s[i]+s[i+1]>M: w+=s[i]+s[i+1]-M s[i+1]=M-s[i] print(w)
s023301002
Accepted
107
14,068
242
N,M=map(int,input().split()) s=list(map(int,input().split())) w=0 if s[0]+s[1]>M and s[0]>M: w+=s[1]+s[0]-M s[1]=0 s[0]=M for i in range(0,N-1): if s[i]+s[i+1]>M: w+=s[i]+s[i+1]-M s[i+1]=M-s[i] print(w)
s465555686
p03737
u765721093
2,000
262,144
Wrong Answer
17
2,940
53
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=input().split() print((a[0]+a[0]+a[0]).upper())
s589297575
Accepted
17
2,940
53
a,b,c=input().split() print((a[0]+b[0]+c[0]).upper())
s925730671
p03737
u102126195
2,000
262,144
Wrong Answer
17
2,940
54
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.
S = input().split() print(S[0][0] + S[1][0] + S[2][0])
s227193118
Accepted
17
2,940
97
a, b, c = input().split() print(chr(ord(a[0]) - 32) + chr(ord(b[0]) - 32) + chr(ord(c[0]) - 32))
s347761606
p03679
u849229491
2,000
262,144
Wrong Answer
17
2,940
125
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int,input().split()) if a<=b: print('delicious') elif b>(a+x): print('dangerous') else: print('safe')
s411790032
Accepted
17
2,940
125
x,a,b = map(int,input().split()) if a>=b: print('delicious') elif b>(a+x): print('dangerous') else: print('safe')
s691772605
p02260
u285980122
1,000
131,072
Wrong Answer
20
5,600
858
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 selectionSort(A, N): A = A.split(" ") change_count = 0 for i in range(N): minj = i for j in range(i,N): if A[j] < A[minj]: minj = j if i != minj: tmp = A[i] A[i] = A[minj] A[minj] = tmp change_count+=1 return A, change_count N = int(input("数列の長さを表す整数を入力して下さい ")) A = input("N 個の整数が空白区切りで入力して下さい ") sorted_list, change_count = selectionSort(A,N) print(" ".join(map(str,sorted_list))) print(change_count)
s355914011
Accepted
20
5,600
652
def selectionSort(A, N): A = list(map(int, A.split(" "))) change_count = 0 for i in range(N): minj = i for j in range(i,N): if A[j] < A[minj]: minj = j if i != minj: tmp = A[i] A[i] = A[minj] A[minj] = tmp change_count+=1 print(" ".join(map(str,A))) print(change_count) #return True N = int(input()) A = input("") selectionSort(A,N)
s850277593
p03555
u266171694
2,000
262,144
Wrong Answer
17
2,940
77
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.
c1 = list(input()) c2 = list(input()) if c1.reverse() == c2: print("YES")
s895650520
Accepted
17
2,940
129
c1 = list(input()) c2 = list(input()) r1 = c1[::-1] r2 = c2[::-1] if c1 == r2 and c2 == r1: print("YES") else: print("NO")
s050988260
p02265
u535719732
1,000
131,072
Wrong Answer
20
5,596
362
Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list.
n = int(input()) dList = [] for _ in range(n): op = list(map(str,input().split())) if(op[0] == "insert"): dList.append(op[1]) elif(op[0] == "delete"): for j,k in enumerate(dList): if(op[1] == k): dList.pop(j) elif(op[0] == "deleteFirst"): dList.pop(0) elif(op[0] == "deleteLast") : dList.pop(len(dList)-1) print(*dList)
s212178274
Accepted
770
69,740
285
import collections,sys def s(): d = collections.deque() input() for e in sys.stdin: if "i"==e[0]: d.appendleft(e[7:-1]) else: if " "==e[6]: m = e[7:0-1] if m in d: d.remove(m) elif "i"==e[7]: d.popleft() else: d.pop() print(*d) s()
s363355901
p03150
u102461423
2,000
1,048,576
Wrong Answer
17
2,940
160
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
S = input() bl = False for L in range(8): T = S[:L] + S[len(S)-L:] if T == 'keyence': bl = True break answer = 'YES' if bl else 'NO' print(answer)
s653543222
Accepted
17
2,940
164
S = input() bl = False for L in range(8): T = S[:L] + S[len(S)-(7-L):] if T == 'keyence': bl = True break answer = 'YES' if bl else 'NO' print(answer)
s760984753
p02408
u914146430
1,000
131,072
Wrong Answer
30
7,732
598
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()) card_have=[input().split() for i in range(n)] nums={1,2,3,4,5,6,7,8,9,10,11,12,13} s_have={int(s[1]) for s in card_have if s[0]=="S"} h_have={int(h[1]) for h in card_have if h[0]=="H"} c_have={int(c[1]) for c in card_have if c[0]=="C"} d_have={int(d[1]) for d in card_have if d[0]=="S"} s_lost=list(nums^s_have) h_lost=list(nums^h_have) c_lost=list(nums^c_have) d_lost=list(nums^d_have) s_lost.sort() h_lost.sort() c_lost.sort() d_lost.sort() for s in s_lost: print("S",s) for h in h_lost: print("H",h) for c in c_lost: print("C",c) for d in d_lost: print("D",d)
s682988956
Accepted
30
7,772
598
n=int(input()) card_have=[input().split() for i in range(n)] nums={1,2,3,4,5,6,7,8,9,10,11,12,13} s_have={int(s[1]) for s in card_have if s[0]=="S"} h_have={int(h[1]) for h in card_have if h[0]=="H"} c_have={int(c[1]) for c in card_have if c[0]=="C"} d_have={int(d[1]) for d in card_have if d[0]=="D"} s_lost=list(nums^s_have) h_lost=list(nums^h_have) c_lost=list(nums^c_have) d_lost=list(nums^d_have) s_lost.sort() h_lost.sort() c_lost.sort() d_lost.sort() for s in s_lost: print("S",s) for h in h_lost: print("H",h) for c in c_lost: print("C",c) for d in d_lost: print("D",d)
s795752415
p03433
u086503932
2,000
262,144
Wrong Answer
17
2,940
59
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
print('No')if int(input())%500>int(input())else print('No')
s901691941
Accepted
17
2,940
60
print('No')if int(input())%500>int(input())else print('Yes')
s852830314
p03588
u642012866
2,000
262,144
Wrong Answer
429
9,140
147
A group of people played a game. All players had distinct scores, which are positive integers. Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i. Find the maximum possible number of players in the game.
N = int(input()) x = 0 ans = 0 for _ in range(N): A, B = map(int, input().split()) if A > x: x = A ans = B print(x+ans)
s815996472
Accepted
189
9,072
143
N = int(input()) x = 0 ans = 0 for _ in range(N): A, B = map(int, input().split()) if A > x: x = A ans = B print(x+ans)
s063069995
p02399
u075836834
1,000
131,072
Wrong Answer
40
7,644
50
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a,b = map(int,input().split()) print(a//b,a%b,a/b)
s768278272
Accepted
40
7,648
65
a,b = map(int,input().split()) print("%d %d %.5f"%(a//b,a%b,a/b))
s171178873
p03140
u367130284
2,000
1,048,576
Wrong Answer
18
3,064
361
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
N=int(input()) A=list(input()) B=list(input()) C=list(input()) litter=[] c=0 for s in range(N): if A[s] and B[s]: litter.append(A[s]) elif A[s] and C[s]: litter.append(A[s]) else: litter.append(B[s]) if litter[s] != A[s]: c+=1 if litter[s] != B[s]: c+=1 if litter[s] != C[s]: c+=1 print(c)
s006044274
Accepted
18
3,060
149
N=int(input()) A=list(input()) B=list(input()) C=list(input()) litter=[] c=0 for s in range(N): c+=[0,0,1,2][len(set([A[s],B[s],C[s]]))] print(c)
s363919940
p03712
u756988562
2,000
262,144
Wrong Answer
17
3,060
160
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
h,w = map(int,input().split()) for i in range(h+2): if i == 0 or i == h+1: print("#"*w) else: temp = input() print("#"+temp+"#")
s514759604
Accepted
17
3,060
201
h,w = map(int,input().split()) temp = [] for i in range(h): temp.append("#"+input()+"#") for i in range(h+2): if i == 0 or i == h+1: print("#"*(w+2)) else: print(temp[i-1])
s486813470
p04012
u172569352
2,000
262,144
Wrong Answer
17
2,940
331
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
def q69(w): word_count = {} for i in w: if i in word_count: word_count[i] += 1 else: word_count[i] = 1 for i in word_count.values(): if i // 2 == 0: print(i) else: return 'No' return 'Yes' w = list(input()) print(q69(w))
s038401531
Accepted
17
2,940
304
def q69(w): word_count = {} for i in w: if i in word_count: word_count[i] += 1 else: word_count[i] = 1 for i in word_count.values(): if i % 2 != 0: return 'No' return 'Yes' w = list(input()) print(q69(w))
s990273975
p03456
u142903114
2,000
262,144
Wrong Answer
17
2,940
98
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a, b = map(int, input().split()) c = a * b if c == (a**2): print('Yes') else: print('No')
s402793815
Accepted
17
2,940
131
import math a, b = map(str, input().split()) c = int(a + b) if math.sqrt(c).is_integer(): print('Yes') else: print('No')
s009430572
p03679
u498174425
2,000
262,144
Wrong Answer
17
2,940
167
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
#-*- coding:utf-8 -*- data = input().split() if data[1] >= data[2]: print("delicious") exit() if data[0] + data[1] >= data[2]: print("safe") exit()
s600909513
Accepted
17
2,940
135
x,a,b = map(int, input().split()) if a >= b: print("delicious") elif b - a <= x: print("safe") else: print("dangerous")
s516082623
p02390
u327972099
1,000
131,072
Wrong Answer
30
6,728
66
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.
s_ = int(input()) print("%d %d %d" % (s_//3600, s_//60%60, s_%60))
s082507908
Accepted
30
6,724
66
s_ = int(input()) print("%d:%d:%d" % (s_//3600, s_//60%60, s_%60))
s266639291
p02397
u313089641
1,000
131,072
Wrong Answer
40
8,000
182
Write a program which reads two integers x and y, and prints them in ascending order.
num = [] while True: n = input() a, b = [int(x) for x in n.split()] if a == 0 and b == 0: break num.append([a, b]) for ls in num: ls.sort() print(ls)
s536378349
Accepted
40
8,020
208
num = [] while True: n = input() a, b = [int(x) for x in n.split()] if a == 0 and b == 0: break num.append([a, b]) for ls in num: ls.sort() print('{} {}'.format(ls[0], ls[1]))
s734080169
p02613
u279695802
2,000
1,048,576
Wrong Answer
150
16,536
206
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.
from collections import Counter N = int(input()) S = [input() for i in range(N)] res = Counter(S) print(f"AC x {res['AC']}") print(f"AC x {res['WA']}") print(f"AC x {res['TLE']}") print(f"AC x {res['RE']}")
s590242824
Accepted
143
16,488
207
from collections import Counter N = int(input()) S = [input() for i in range(N)] res = Counter(S) print(f"AC x {res['AC']}") print(f"WA x {res['WA']}") print(f"TLE x {res['TLE']}") print(f"RE x {res['RE']}")
s956045492
p00026
u661290476
1,000
131,072
Wrong Answer
30
7,740
534
As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system. We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as shown in the figure depending on its size. In the figure, a star denotes the point of fall and a circle denotes the surrounding cells. Originally, the paper is white that means for each cell the value of density is 0. The value of density is increased by 1 when the ink sinks into the corresponding cells. For example, if we put a drop of Small ink at (1, 2) and a drop of Medium ink at (3, 2), the ink will sink as shown in the following figure (left side): In the figure, density values of empty cells are 0. The ink sinking into out of the paper should be ignored as shown in the figure (top side). We can put several drops of ink at the same point. Your task is to write a program which reads a sequence of points of fall (x, y) with its size (Small = 1, Medium = 2, Large = 3), and prints the number of cells whose density value is 0. The program must also print the maximum value of density. You may assume that the paper always consists of 10 × 10, and 0 ≤ x < 10, 0 ≤ y < 10\.
board=[[0]*10 for i in range(10)] ink=[[[0,0,0,0,0],[0,0,1,0,0],[0,1,1,1,0],[0,0,1,0,0],[0,0,0,0,0]], [[0,0,0,0,0],[0,1,1,1,0],[0,1,1,1,0],[0,1,1,1,0],[0,0,0,0,0]], [[0,0,1,0,0],[0,1,1,1,0],[1,1,1,1,1],[0,1,1,1,0],[0,0,1,0,0]]] while True: try: x,y,s=map(int,input().split(",")) except: break for i in range(5): for j in range(5): if 0<=i+y-2<=9 and 0<=j+x-2<=9: board[i+y-2][j+x-2]+=ink[s-1][i][j] flat=sum(board,[]) print(flat.count(0)) print(flat.count(max(flat)))
s634855216
Accepted
20
7,696
526
board=[[0]*10 for i in range(10)] ink=[[[0,0,0,0,0],[0,0,1,0,0],[0,1,1,1,0],[0,0,1,0,0],[0,0,0,0,0]], [[0,0,0,0,0],[0,1,1,1,0],[0,1,1,1,0],[0,1,1,1,0],[0,0,0,0,0]], [[0,0,1,0,0],[0,1,1,1,0],[1,1,1,1,1],[0,1,1,1,0],[0,0,1,0,0]]] while True: try: x,y,s=map(int,input().split(",")) except: break for i in range(5): for j in range(5): if 0<=i+y-2<=9 and 0<=j+x-2<=9: board[i+y-2][j+x-2]+=ink[s-1][i][j] flat=sum(board,[]) print(flat.count(0)) print(max(flat))
s790261250
p02601
u964521959
2,000
1,048,576
Wrong Answer
25
9,208
441
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
A_list = list(map(int, input().split())) K = int(input()) sort_ = sorted(A_list) if(A_list == sort_): print("Yes") for i in range(K): if(A_list[0]>=A_list[1]): A_list[1] = A_list[1]*2 elif(A_list[1]>=A_list[2]): A_list[2] = A_list[2]*2 else: exit() #print(A_list) sort_ = sorted(A_list) set_ = list(set(A_list)) if(A_list != set_): print("No") elif(A_list == sort_): print("Yes") else: print("No")
s505656321
Accepted
35
9,176
392
A_list = list(map(int, input().split())) K = int(input()) for i in range(K): if(A_list[0]>=A_list[1]): A_list[1] = A_list[1]*2 elif(A_list[1]>=A_list[2]): A_list[2] = A_list[2]*2 #print(A_list) sort_ = sorted(A_list) set_ = sorted(list(set(A_list))) #print(A_list,set_) if(A_list != set_): print("No") elif(A_list == sort_): print("Yes") else: print("No")
s696027339
p03575
u210827208
2,000
262,144
Wrong Answer
24
3,316
521
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
from collections import deque n,m=map(int,input().split()) X=[] M=[[] for _ in range(n)] for i in range(m): a,b=map(int,input().split()) X.append([a,b]) M[a-1].append(b-1) M[b-1].append(a-1) ans=0 for i in range(m): se={X[i][0],X[i][1]} q=deque([0]) visited=[0]*n while q: s=q.popleft() if visited[s]==1: continue visited[s]=1 for x in M[s]: if {s,x}!=se: q.append(x) if sum(visited)!=n: ans+=1 print(ans)
s227750805
Accepted
29
9,244
519
n,m=map(int,input().split()) def find(x): if par[x]<0: return x else: par[x]=find(par[x]) return par[x] def union(x,y): x,y=find(x),find(y) if x!=y: if x>y: x,y=y,x par[x]+=par[y] par[y]=x M=[] for i in range(m): x,y=map(int,input().split()) M.append([x-1,y-1]) ans=0 for i in range(m): X=M[:i]+M[i+1:] par = [-1] * n for x in X: union(x[0],x[1]) if [p<0 for p in par].count(1)>1: ans+=1 print(ans)
s064681366
p03696
u714878632
2,000
262,144
Wrong Answer
18
3,064
708
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
n = int(input()) s = input() rs = [c for c in s] rs.reverse() stack = [0]*n for i in range(n): if(i > 0): stack[-i - 1] = stack[-i] if(s[-i - 1] == ')'): stack[-i - 1] += 1 else: if(stack[-i - 1] > 0): stack[-i - 1] -= 1 print(stack) print(s) nr = 0 ind = 0 ret = "" for i in range(n): if(stack[i] > nr): if(s[ind] != "("): ret += "(" * (stack[i] - nr) nr += (stack[i] - nr) else: nr += 1 elif(stack[i] < nr): nr -= 1 ret += s[ind] ind += 1 stack2 = 0 for c in ret: if(c == "("): stack2 += 1 else: stack2 -= 1 if(stack2 != 0): ret += ")"*stack2 print(ret)
s589661712
Accepted
17
3,064
333
n = int(input()) s = input() stack_num = 0 ind = 0 ret = "" nr = 0 for c in s: if(c == "("): stack_num += 1 else: stack_num -= 1 if(stack_num < 0): ret += "(" stack_num += 1 if(stack_num < 0): ret += "(" * (-stack_num) ret += s if(stack_num >= 0): ret += ")" * stack_num print(ret)
s183918855
p03007
u322185540
2,000
1,048,576
Wrong Answer
292
21,224
588
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.
n = int(input()) alist = list(map(int,input().split())) ans = [] if len(alist) == 2: alist.sort(reverse = True) print(alist[0]-alist[1]) print(' '.join(map(str,alist))) else: plus =[w for w in alist if w>=0] minus =[x for x in alist if x<0] if minus == []: plus.sort() for y in range(len(plus)-2): ans.append(' '.join(map(str,plus[y:y+2]))) plus[y+1] = plus[y]-plus[y+1] pplus = plus[::-1] ans.append(' '.join(map(str,pplus[0:2]))) print(pplus[0]-pplus[1]) for y in ans: print(y)
s044218264
Accepted
312
22,052
1,181
n = int(input()) alist = list(map(int,input().split())) ans = [] if len(alist) == 2: alist.sort(reverse = True) print(alist[0]-alist[1]) print(' '.join(map(str,alist))) else: plus =[w for w in alist if w>=0] minus =[x for x in alist if x<0] if minus == []: plus.sort() for y in range(len(plus)-2): ans.append(' '.join(map(str,plus[y:y+2]))) plus[y+1] = plus[y]-plus[y+1] pplus = plus[::-1] ans.append(' '.join(map(str,pplus[0:2]))) print(pplus[0]-pplus[1]) for y in ans: print(y) elif plus == []: minus.sort(reverse = True) for y in range(len(minus)-1): ans.append(' '.join(map(str,minus[y:y+2]))) minus[y+1] = minus[y]-minus[y+1] print(minus[-1]) for y in ans: print(y) else: for z in range(len(plus)-1): ans.append(' '.join(map(str,[minus[0],plus[z]]))) minus[0] = minus[0]-plus[z] for q in minus: ans.append(' '.join(map(str,[plus[-1],q]))) plus[-1] = plus[-1]-q print(plus[-1]) for t in ans: print(t)
s270178759
p03449
u951492009
2,000
262,144
Wrong Answer
18
2,940
215
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?
n = int(input()) a1 = list(map(int,input().split())) a2 = list(map(int,input().split())) a3 = [] for i in range(n): a3.append(sum( a1[:i+1]+a2[i:])) #print(max(a3)) print(a3)
s465448351
Accepted
18
2,940
178
n = int(input()) a1 = list(map(int,input().split())) a2 = list(map(int,input().split())) a3 = [] for i in range(n): a3.append(sum( a1[:i+1]+a2[i:])) print(max(a3))
s577930676
p03712
u374531474
2,000
262,144
Wrong Answer
18
3,060
138
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
H, W = map(int, input().split()) a = [input() for i in range(H)] print('*' * W) for ai in a: print('*{}*'.format(ai)) print('*' * W)
s630747545
Accepted
17
3,060
150
H, W = map(int, input().split()) a = [input() for i in range(H)] print('#' * (W + 2)) for ai in a: print('#{}#'.format(ai)) print('#' * (W + 2))
s191917352
p03779
u905582793
2,000
262,144
Wrong Answer
35
7,016
98
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.
import bisect tri=[i*(i+1)//2 for i in range(10**5)] print(bisect.bisect_left(tri,int(input()))+1)
s339276145
Accepted
35
7,144
96
import bisect tri=[i*(i+1)//2 for i in range(10**5)] print(bisect.bisect_left(tri,int(input())))
s243963846
p03129
u185243955
2,000
1,048,576
Wrong Answer
17
2,940
149
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
import math N,K = [int(x) for x in input().split()] print(N,K) print(math.ceil(N/2)) if K <= math.ceil(N/2): print('Yes') else: print('No')
s215292024
Accepted
18
2,940
116
import math N,K = [int(x) for x in input().split()] if K <= math.ceil(N/2): print('YES') else: print('NO')
s620990737
p03658
u768559443
2,000
262,144
Wrong Answer
17
2,940
89
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=sorted(map(int,input().split()))[::-1] print(sum(l[:k+1]))
s915952565
Accepted
18
2,940
88
n,k=map(int,input().split()) l=sorted(map(int,input().split()))[::-1] print(sum(l[:k]))
s733210970
p03944
u001687078
2,000
262,144
Wrong Answer
17
3,064
302
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()) L, D = 0, 0 R = W U = H for i in range(N): x, y, a = map(int, input().split()) if a == 1: if L < x: L = x if a == 2: if R > x: R = x if a == 3: if D < y: D = y if a == 4: if U > y: U == y print(max((R -L)*(U-D), 0))
s886832751
Accepted
18
3,064
276
W, H, N = map(int, input().split()) L = 0 R = W D = 0 U = H for i in range(N): x, y, a = map(int, input().split()) if a == 1: L = max(L, x) if a == 2: R = min(R, x) if a == 3: D = max(D, y) if a == 4: U = min(U, y) print(max((R-L),0) * max((U-D),0))
s086545625
p03660
u722189950
2,000
262,144
Wrong Answer
2,106
37,464
660
Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree. Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored. Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell. More specifically, each player performs the following action in her/his turn: * Fennec: selects an uncolored cell that is adjacent to a **black** cell, and paints it **black**. * Snuke: selects an uncolored cell that is adjacent to a **white** cell, and paints it **white**. A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
N = int(input()) ab = [list(map(int, input().split())) for _ in range(N - 1)] g = [[] for _ in range(N + 1)] gtf = [False] * (N+1) gtf[1] = True gtf[-1] = True finish = False win = "" for a, b in ab: g[a].append(b) g[b].append(a) now_f = 1 now_s = N while win == "": next_f = -1 next_s = -1 for i in g[now_f]: if not gtf[i]: next_f = max(next_f, len(g[i])) for j in g[now_s]: if not gtf[i]: next_s = max(next_s, len(g[j])) if next_f == -1: win = "Snuke" break if next_s == -1: win = "Fennec" break now_f = next_f now_s = next_s print(win)
s690061955
Accepted
564
29,168
986
N = int(input()) ab = [[] for i in range(N+1)] for i in range(N-1): a, b = map(int, input().split()) ab[a].append(b) ab[b].append(a) def calc_dist(K): dist = [-1 for i in range(N+1)] dist[K] = 0 stack = [] stack.append(K) while stack: v = stack.pop() for nxt in ab[v]: if dist[nxt] == -1: dist[nxt] = dist[v] + 1 stack.append(nxt) return dist dist1 = calc_dist(1) distN = calc_dist(N) Fennec = 0 Snuke = 0 for v in range(1,N+1): if dist1[v] <= distN[v]: Fennec += 1 else: Snuke += 1 if Fennec > Snuke: print('Fennec') else: print('Snuke')
s303220110
p02602
u766565683
2,000
1,048,576
Wrong Answer
2,206
31,668
353
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
n, k = map(int, input().split()) a = list(map(int, input().split())) t = 0 s = 1 k_k = k temp = [] while k != n+1: for i in range(t, k): alpha = a[i] s = s * alpha temp.append(s) k = k + 1 t = t + 1 s = 1 print(k) for i in range(0, k_k-1): t_s = temp[i] t_t = temp[i+1] if t_s < t_t: print("Yes") else: print("No")
s493799352
Accepted
153
31,608
153
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(k, n): if a[i-k] < a[i]: print("Yes") else: print("No")
s103503784
p03493
u978494963
2,000
262,144
Wrong Answer
18
2,940
69
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 = list(map(lambda x: int(x), input().split(" "))) print(a.count(1))
s653334665
Accepted
17
2,940
25
print(input().count("1"))
s755077472
p02743
u915879510
2,000
1,048,576
Wrong Answer
17
2,940
109
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a, b, c = list(map(int, input().split())) n = a*a+2*a*b+b*b-c*c if n>=0: print("No") else: print("Yes")
s592958770
Accepted
35
5,076
212
import math from decimal import Decimal a, b, c = list(map(int, input().split())) # ra+rb<rc # a+b+2rab<c # 2rab<c-a-b # 4ab<(c-a-b)**2 if ((c-a-b)>0) and (4*a*b<(c-a-b)**2): print("Yes") else: print("No")
s158580009
p03813
u167908302
2,000
262,144
Wrong Answer
18
2,940
81
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print `ABC` if Smeke will participate in ABC, and print `ARC` otherwise.
#coding:utf-8 x = int(input()) if x >= 120: print('ARC') else: print('ABC')
s609717267
Accepted
18
2,940
83
#coding:utf-8 x = int(input()) if x >= 1200: print('ARC') else: print('ABC')
s417089985
p03415
u869154953
2,000
262,144
Wrong Answer
28
8,952
71
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])
s511854296
Accepted
27
9,092
54
U=input() M=input() B=input() print(U[0]+M[1]+B[2])
s806231927
p02390
u823513038
1,000
131,072
Wrong Answer
30
7,544
64
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.
x = int(input()) print(x / 3600, x / 60 % 60, x % 60, sep = ':')
s261984288
Accepted
20
5,580
67
S = int(input()) print(S // 3600, S // 60 % 60, S % 60, sep = ':')