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
s385073231
p04043
u132344815
2,000
262,144
Wrong Answer
17
2,940
211
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(int,input().split()) if a == 5 and b == 5 and c == 7: print('Yes') elif a == 5 and b == 7 and c == 5: print('Yes') elif a == 7 and b == 5 and c == 5: print('Yes') else: print('No')
s706894660
Accepted
17
2,940
211
a, b, c = map(int,input().split()) if a == 5 and b == 5 and c == 7: print('YES') elif a == 5 and b == 7 and c == 5: print('YES') elif a == 7 and b == 5 and c == 5: print('YES') else: print('NO')
s031686379
p03637
u820047642
2,000
262,144
Wrong Answer
63
14,224
206
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
N=int(input()) A=list(map(int,input().split())) Odd,Four=0,0 for a in A: if a%2==1:Odd+=1 elif a%4==0:Four+=1 if Odd+Four==N and Odd-Four==1:print("Yes") elif Odd<=Four:print("Yse") else:print("No")
s773837949
Accepted
64
14,252
206
N=int(input()) A=list(map(int,input().split())) Odd,Four=0,0 for a in A: if a%2==1:Odd+=1 elif a%4==0:Four+=1 if Odd+Four==N and Odd-Four==1:print("Yes") elif Odd<=Four:print("Yes") else:print("No")
s633840703
p02401
u505411588
1,000
131,072
Wrong Answer
20
7,592
314
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.
x = [] while True: x = input().split() if x[1] == "?": break elif x[1] == "+": print(int(x[0]) + int(x[2])) elif x[1] == "-": print(int(x[0]) - int(x[2])) elif x[1] == "*": print(int(x[0]) * int(x[2])) elif x[1] == "/": print(int(x[0]) / int(x[2]))
s391758310
Accepted
30
7,732
315
x = [] while True: x = input().split() if x[1] == "?": break elif x[1] == "+": print(int(x[0]) + int(x[2])) elif x[1] == "-": print(int(x[0]) - int(x[2])) elif x[1] == "*": print(int(x[0]) * int(x[2])) elif x[1] == "/": print(int(x[0]) // int(x[2]))
s779957925
p03079
u625811641
2,000
1,048,576
Wrong Answer
17
2,940
82
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
a,b,c = map(int,input().split()) ans = "No" if a==b==c: ans = "yes" print(ans)
s756635248
Accepted
18
2,940
82
a,b,c = map(int,input().split()) ans = "No" if a==b==c: ans = "Yes" print(ans)
s169044484
p04011
u580362735
2,000
262,144
Wrong Answer
17
2,940
114
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) print(X*N) if K < N else print(X*K + Y*(N-K))
s270850416
Accepted
17
2,940
114
N = int(input()) K = int(input()) X = int(input()) Y = int(input()) print(X*N) if K > N else print(X*K + Y*(N-K))
s369690826
p03720
u016323272
2,000
262,144
Wrong Answer
18
3,060
178
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
#ABC061.B N,M = map(int,input().split()) L = [] for i in range(M): a,b = map(int,input().split()) L.append([a,b]) for m in range(N+1): ans = L.count(m) print(ans)
s996876490
Accepted
17
3,060
184
N , M = map(int,input().split()) L = [] for i in range(M): a,b = map(int,input().split()) L.append(a) L.append(b) for j in range(1,N+1): ans = L.count(j) print(ans)
s425245191
p03574
u982896977
2,000
262,144
Wrong Answer
21
3,444
960
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(w+2)] dot_map = [a] for _ in range(h): l = list(input()) l.insert(0, ".") l.append(".") dot_map.append(l) dot_map.append(a) for i in range(1, h+1): for j in range(1,w+1): if dot_map[i][j] == ".": counter = 0 if dot_map[i-1][j-1] == "#": counter += 1 if dot_map[i-1][j] == "#": counter += 1 if dot_map[i-1][j+1] == "#": counter += 1 if dot_map[i][j-1] == "#": counter += 1 if dot_map[i][j+1] == "#": counter += 1 if dot_map[i+1][j-1] == "#": counter += 1 if dot_map[i+1][j] == "#": counter += 1 if dot_map[i+1][j+1] == "#": counter += 1 dot_map[i][j] = counter for i in range(1, h+1): ans = dot_map[i] print(*ans[1:w+1])
s919844144
Accepted
21
3,188
973
h,w = map(int,input().split()) a = ["." for i in range(w+2)] dot_map = [a] for _ in range(h): l = list(input()) l.insert(0, ".") l.append(".") dot_map.append(l) dot_map.append(a) for i in range(1, h+1): for j in range(1,w+1): if dot_map[i][j] == ".": counter = 0 if dot_map[i-1][j-1] == "#": counter += 1 if dot_map[i-1][j] == "#": counter += 1 if dot_map[i-1][j+1] == "#": counter += 1 if dot_map[i][j-1] == "#": counter += 1 if dot_map[i][j+1] == "#": counter += 1 if dot_map[i+1][j-1] == "#": counter += 1 if dot_map[i+1][j] == "#": counter += 1 if dot_map[i+1][j+1] == "#": counter += 1 dot_map[i][j] = str(counter) for i in range(1, h+1): ans = dot_map[i] print("".join(ans[1:w+1]))
s162993539
p03861
u933214067
2,000
262,144
Wrong Answer
38
5,104
747
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
from statistics import mean, median,variance,stdev import sys import math import fractions def j(a): if a==1: print("YES") else :print("NO") def ct(x,y): if (x>y):print("") elif (x<y): print("") else: print("") def ip(): return int(input()) x,y,z = (int(i) for i in input().split()) print((y-x+1)//z)
s337756198
Accepted
164
13,644
1,078
from statistics import mean, median,variance,stdev import numpy as np import sys import math import fractions import itertools import copy from operator import itemgetter def j(q): if q==1: print("Yes") else:print("No") exit(0) def ct(x,y): if (x>y):print("+") elif (x<y): print("-") else: print("?") def ip(): return int(input()) x,y,z= (int(i) for i in input().split()) low = (x//z)*z if low < x: low+=z high = (y//z)*z print((high - low)//z+1)
s910995777
p03997
u841623074
2,000
262,144
Time Limit Exceeded
2,104
3,064
501
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
sa = input() sb = input() sc = input() turn = sa[0] sa = sa[1:] while True: if turn == 'a': if not sa: win = 'A' break else: turn = sa[0] sa = sa[1:] if turn == 'b': if not sb: win = 'B' break else: turn = sb[0] sb = sb[1:] if turn == 'c': if not sc: win = 'C' break else: turn = sc[0] sc = sc[1:]
s416672839
Accepted
17
2,940
74
a=int(input()) b=int(input()) h=int(input()) ans=(a+b)*h/2 print(int(ans))
s237271097
p03574
u742729271
2,000
262,144
Wrong Answer
30
3,064
424
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H, W = map(int, input().split()) S = [[""]]*H for i in range(H): S[i] = input() print(S) dh = [-1,-1,-1,0,0,1,1,1] dw = [-1,0,1,-1,1,-1,0,1] for i in range(H): for j in range(W): count=0 if S[i][j]==".": for l in range(8): if H>i+dh[l]>-1 and W>j+dw[l]>-1: if S[i+dh[l]][j+dw[l]]=="#": count+=1 S[i]=S[i][:j] + str(count) + S[i][j+1:] for i in range(H): print(S[i])
s024069534
Accepted
31
3,064
415
H, W = map(int, input().split()) S = [[""]]*H for i in range(H): S[i] = input() dh = [-1,-1,-1,0,0,1,1,1] dw = [-1,0,1,-1,1,-1,0,1] for i in range(H): for j in range(W): count=0 if S[i][j]==".": for l in range(8): if H>i+dh[l]>-1 and W>j+dw[l]>-1: if S[i+dh[l]][j+dw[l]]=="#": count+=1 S[i]=S[i][:j] + str(count) + S[i][j+1:] for i in range(H): print(S[i])
s328778273
p03353
u497046426
2,000
1,048,576
Wrong Answer
2,379
917,248
381
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
from collections import defaultdict S = input() K = int(input()) alphabet = defaultdict(list) for i, s in enumerate(S): alphabet[s].append(i) alpha_list = sorted(alphabet.keys()) cand = [] i = 0 while len(cand) < K: for j in alphabet[alpha_list[i]]: for l in range(1, len(S)-j+1): cand.append(S[j:j+l]) i += 1 cand = sorted(cand) print(cand[K-1])
s096524078
Accepted
35
5,068
190
# ABC 097 C S = input() K = int(input()) cand = [] for l in range(1, K+1): for i in range(len(S) - l + 1): cand.append(S[i:i+l]) cand = sorted(list(set(cand))) print(cand[K-1])
s739302864
p00002
u116501200
1,000
131,072
Wrong Answer
20
7,576
87
Write a program which computes the digit number of sum of two integers a and b.
[print(i//10)for i in[sum(int(e)for e in ln.split())for ln in __import__("sys").stdin]]
s239607100
Accepted
30
7,628
93
[print(len(str(i)))for i in[sum(int(e)for e in ln.split())for ln in __import__("sys").stdin]]
s734741022
p03693
u257018224
2,000
262,144
Wrong Answer
17
2,940
97
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r,g ,b=map(int,input().split()) A=100*r+10*g+b if A%4==0: print("Yes") else : print("No")
s780748164
Accepted
17
2,940
98
r,g ,b=map(int,input().split()) A=100*r+10*g+b if A%4==0 : print("YES") else : print("NO")
s580940604
p03478
u095021077
2,000
262,144
Wrong Answer
41
9,176
154
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()) ans=0 for i in range(1, N+1): s=str(i) x=0 for j in s: x+=int(j) if A<=x<=B: ans+=1 print(ans)
s895918829
Accepted
41
9,052
154
N, A, B=map(int, input().split()) ans=0 for i in range(1, N+1): s=str(i) x=0 for j in s: x+=int(j) if A<=x<=B: ans+=i print(ans)
s705896459
p02261
u482227082
1,000
131,072
Wrong Answer
20
5,600
734
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
def bubblesort(n, a): r = a[:] for i in range(n): for j in range(n-1, i, -1): if int(r[j][1]) < int(r[j-1][1]): r[j], r[j-1] = r[j-1], r[j] print(*r) print("Stable") def selectionsort(n, a): r = a[:] ret = "Stable" for i in range(n): tmp = i for j in range(i, n): if int(r[j][1]) < int(r[tmp][1]): tmp = j r[i], r[tmp] = r[tmp], r[i] if r[i][0] != r[tmp][0] and int(r[i][1]) == int(r[tmp][1]): ret = "Not Stable" print(*r) print(ret) def main(): n = int(input()) a = list(input().split()) bubblesort(n, a) selectionsort(n, a) if __name__ == '__main__': main()
s290254634
Accepted
220
5,612
892
def bubblesort(n, a): r = a[:] for i in range(n): for j in range(n-1, i, -1): if int(r[j][1]) < int(r[j-1][1]): r[j], r[j-1] = r[j-1], r[j] print(*r) print("Stable") def selectionsort(n, a): r = a[:] ret = "Stable" for i in range(n): tmp = i for j in range(i, n): if int(r[j][1]) < int(r[tmp][1]): tmp = j r[i], r[tmp] = r[tmp], r[i] for i in range(n): for j in range(i+1, n): for k in range(n): for l in range(k+1, n): if int(a[i][1]) == int(a[j][1]) and a[i] == r[l] and a[j] == r[k]: ret = "Not stable" print(*r) print(ret) def main(): n = int(input()) a = list(input().split()) bubblesort(n, a) selectionsort(n, a) if __name__ == '__main__': main()
s851576217
p02612
u036065030
2,000
1,048,576
Wrong Answer
29
9,140
33
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)
s342430840
Accepted
32
9,148
83
a = int(input()) if a % 1000 == 0: print(0) else: print(1000 - (a % 1000))
s353359937
p04045
u650245944
2,000
262,144
Wrong Answer
20
3,188
397
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
N, K = map(int, input().split()) D = list(map(int, input().split())) L = [i for i in range(10) if i not in D] A = [i for i in L] for i in L: for j in L: A.append(10*i+j) for i in L: for j in L: for k in L: A.append(100*i+10*j+k) for i in L: for j in L: for k in L: for l in L: A.append(1000*i+100*j+10*k+l) for i in A: if i >= N: print(N) break
s649714775
Accepted
43
5,732
539
N, K = map(int, input().split()) D = list(map(int, input().split())) L = [i for i in range(10) if i not in D] A = [] for i in L: A.append(i) for i in L: for j in L: A.append(10*i+j) for i in L: for j in L: for k in L: A.append(100*i+10*j+k) for i in L: for j in L: for k in L: for l in L: A.append(1000*i+100*j+10*k+l) for i in L: for j in L: for k in L: for l in L: for m in L: A.append(\ 10000*i+1000*j+100*k+10*l+m) for i in A: if i >= N: print(i) break
s572314399
p02392
u655518263
1,000
131,072
Wrong Answer
20
7,568
128
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
lin = input() l = lin.split(" ") a = int(l[0]) b = int(l[1]) c = int(l[2]) if a < b < c: print('YES') else: print('NO')
s674305619
Accepted
30
7,688
128
lin = input() l = lin.split(" ") a = int(l[0]) b = int(l[1]) c = int(l[2]) if a < b < c: print('Yes') else: print('No')
s375018332
p02613
u307622233
2,000
1,048,576
Wrong Answer
149
16,616
310
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 def main(): N = int(input()) lst = [] for _ in range(N): lst.extend(input().split()) c = dict(Counter(lst)) for i in ["AC", "WA", "TLE", "RE"]: c.setdefault(i, 0) print(f"{i} × {c[i]}") if __name__ == '__main__': main()
s955514099
Accepted
155
16,648
308
from collections import Counter def main(): N = int(input()) lst = [] for _ in range(N): lst.extend(input().split()) c = dict(Counter(lst)) for i in ["AC", "WA", "TLE", "RE"]: c.setdefault(i, 0) print(f"{i} x {c[i]}") if __name__ == '__main__': main()
s315192113
p04043
u234631479
2,000
262,144
Wrong Answer
17
3,060
173
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
L = list(map(int, input().split())) L.sort() print(L) for i in range(2): if not L[i] == 5: print("NO") exit() if not L[2] == 7: print("NO") exit() print("YES")
s820910607
Accepted
17
2,940
164
L = list(map(int, input().split())) L.sort() for i in range(2): if not L[i] == 5: print("NO") exit() if not L[2] == 7: print("NO") exit() print("YES")
s155223385
p03853
u863442865
2,000
262,144
Wrong Answer
23
3,572
193
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
import copy h, w = list(map(int, input().split())) p = [input().split() for _ in range(h)] ans = copy.deepcopy(p) for i in range(h): ans.insert(i*2, p[i]) for i in range(h*2): print(ans[i])
s793285840
Accepted
23
3,572
196
import copy h, w = list(map(int, input().split())) p = [input().split() for _ in range(h)] ans = copy.deepcopy(p) for i in range(h): ans.insert(i*2, p[i]) for i in range(h*2): print(ans[i][0])
s979724175
p03555
u203211107
2,000
262,144
Wrong Answer
17
2,940
111
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.
Ca=input() Cb=input() if Ca[0]==Cb[2] and Ca[1]==Cb[1] and Ca[2]==Cb[0]: print("Yes") else: print("No")
s928822697
Accepted
17
2,940
111
Ca=input() Cb=input() if Ca[0]==Cb[2] and Ca[1]==Cb[1] and Ca[2]==Cb[0]: print("YES") else: print("NO")
s072172272
p02646
u750651325
2,000
1,048,576
Wrong Answer
2,206
9,200
515
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
# -*- coding: utf-8 -*- """ Created on Sat Jun 13 20:58:10 2020 @author: sd18016 """ import sys A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) kyori = abs(B-A) if V <= W: print("No") sys.exit() else: miji = V - W for i in range(T): if kyori == miji*i: print("Yes") sys.exit() else: if kyori < miji*i: print("No") sys.exit() else: pass print("No")
s016519718
Accepted
36
10,136
679
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def s(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 count = 0 ans = 0 inf = float("inf") a,v = I() b,w = I() t = k() sa = v-w if sa <= 0: print("NO") sys.exit() kyori = abs(b-a) if (kyori / sa)<=t: print("YES") else: print("NO")
s861724780
p03477
u397953026
2,000
262,144
Wrong Answer
17
2,940
124
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
a,b,c,d=map(int,input().split()) if a+b>c+d: print("Right") elif a+b==c+d: print("Balanced") else: print("Left")
s319673833
Accepted
17
2,940
124
a,b,c,d=map(int,input().split()) if a+b<c+d: print("Right") elif a+b==c+d: print("Balanced") else: print("Left")
s120634927
p03504
u521389909
2,000
262,144
Wrong Answer
2,111
121,440
1,023
Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, there will never be more than one program that are broadcast on the same channel at the same time. When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T). Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: map(int, r().split()) N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 # if we can record the programms continuously (ver1) if tbl[c][2*s] != 0: tbl[c][2*s] += 1 tbl[c][2*t] -= 1 # if we can record the programms continuously (ver2) elif tbl[c][2*t-1] != 0: tbl[c][2*t-1] -= 1 tbl[c][2*s-1] += 1 # else: else: tbl[c][2*s-1] = 1 tbl[c][2*t] = -1 tbl2 = [list(accumulate(a)) for a in tbl] # ans = max([sum(x) for x in zip(*tbl2)]) # print(ans) res = 0 for i in range(200002): cc = 0 for j in range(C): if tbl2[j][i]: cc += tbl[j][i] res = max(res, cc) print(res)
s875705636
Accepted
1,569
122,992
860
import sys from itertools import accumulate # functions used r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split()) R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)] Rmap = lambda: map(int, r().split()) N, C = R() STC = [R() for _ in range(N)] # 0.5sec as one unit tbl = [[0]*(2*(10**5)+5) for _ in range(C)] for s, t, c in STC: c -= 1 tbl[c][2*s-1] += 1 tbl[c][2*t] -= 1 tbl2 = [list(accumulate(a)) for a in tbl] for i in range(200002): for j in range(C): if tbl2[j][i]>1: tbl2[j][i]=1 ans = max([sum(x) for x in zip(*tbl2)]) print(ans) # res = 0 # cc = 0 # for j in range(C): # if tbl2[j][i]: # cc += 1 # res = max(res, cc) # print(res)
s259748971
p03448
u284363684
2,000
262,144
Wrong Answer
44
9,168
355
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
# input A = int(input()) B = int(input()) C = int(input()) X = int(input()) if X % 100 == 50 and C == 0: print(0) else: all_case = len( [ 1 for a in range(A) for b in range(B) for c in range(C) if 500 * a + 100 * b + 50 * c == X ] ) print(all_case)
s508353088
Accepted
53
9,152
362
# input A = int(input()) B = int(input()) C = int(input()) X = int(input()) if X % 100 == 50 and C == 0: print(0) else: all_case = len( [ 1 for a in range(A + 1) for b in range(B + 1) for c in range(C + 1) if 500 * a + 100 * b + 50 * c == X ] ) print(all_case)
s942713408
p02856
u899645116
2,000
1,048,576
Wrong Answer
694
3,060
144
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals. The preliminary stage consists of several rounds, which will take place as follows: * All the N contestants will participate in the first round. * When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows: * The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round. For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen). When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen. * The preliminary stage ends when 9 or fewer contestants remain. Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage. Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
m = int(input()) csum = 0 dsum = 0 for i in range(m): d,c = (int(x) for x in input().split()) csum += c dsum += d*c print(c-1 + dsum // 9)
s872659859
Accepted
281
3,060
181
import sys input = sys.stdin.readline m = int(input()) csum = 0 dsum = 0 for i in range(m): d,c = map(int,input().split()) csum += c dsum += d*c print(csum-1 + (dsum-1) // 9)
s281714625
p02613
u370852395
2,000
1,048,576
Wrong Answer
140
16,612
203
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.
import collections N=int(input()) l=[input() for _ in range(N)] tmp = collections.Counter(l) print('AC','×',tmp["AC"]) print('WA','×',tmp["WA"]) print('TLE','×',tmp["TLE"]) print('RE','×',tmp["RE"])
s546874784
Accepted
146
16,616
199
import collections N=int(input()) l=[input() for _ in range(N)] tmp = collections.Counter(l) print('AC','x',tmp["AC"]) print('WA','x',tmp["WA"]) print('TLE','x',tmp["TLE"]) print('RE','x',tmp["RE"])
s089935525
p03302
u538523244
2,000
1,048,576
Wrong Answer
17
2,940
127
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds. Note that a+b=15 and a\times b=15 do not hold at the same time.
a, b = map(int, input().split()) if a+b == 15: print("+") if a*b == 15: print("*") else: print("x")
s986111606
Accepted
17
2,940
113
a, b = map(int, input().split()) if a+b == 15: print("+") elif a*b == 15: print("*") else: print("x")
s846863741
p03486
u996665352
2,000
262,144
Wrong Answer
18
2,940
65
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s=sorted(input()) t=sorted(input()) print("Yes" if s<t else "No")
s018205131
Accepted
19
3,060
71
s=sorted(input()) t=sorted(input())[::-1] print("Yes" if s<t else "No")
s445172189
p02831
u779170803
2,000
1,048,576
Wrong Answer
17
3,064
493
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): a,b = INTM() c =min(a,b) d=max(a,b) if d%c ==0: print(int(d)) else: while d%c!=0: e = d%c d = c c = e print(e) print(int(a*b/e)) if __name__ == '__main__': do()
s676881895
Accepted
17
3,064
494
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): a,b = INTM() c =min(a,b) d=max(a,b) if d%c ==0: print(int(d)) else: while d%c!=0: e = d%c d = c c = e # print(e) print(int(a*b/e)) if __name__ == '__main__': do()
s031161023
p04043
u753803401
2,000
262,144
Wrong Answer
17
2,940
143
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(int, input().split()) print("Yes" if (a == b == 5 and c == 7) or (b == c == 5 and a == 7) or (a == c == 5 and b == 7) else "No")
s127217804
Accepted
21
3,316
197
import collections a = collections.Counter(list(map(int, input().split()))).items() for k, v in a: if (k != 5 or v != 2) and (k != 7 or v != 1): print("NO") exit() print("YES")
s850765581
p03110
u793633137
2,000
1,048,576
Wrong Answer
17
3,060
190
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
N=int(input()) s=[input().split() for i in range(N)] M=0 print(s) for i in range(N): p=int(i) if s[p][1]=="JPY": M=M+float(s[p][0]) else: M=M+float(s[p][0])*380000.0 print(M)
s324053743
Accepted
17
2,940
181
N=int(input()) s=[input().split() for i in range(N)] M=0 for i in range(N): p=int(i) if s[p][1]=="JPY": M=M+float(s[p][0]) else: M=M+float(s[p][0])*380000.0 print(M)
s967288133
p02390
u467070262
1,000
131,072
Wrong Answer
20
7,644
112
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()) s = x % 60 x -= s x /= 60 m = x % 60 x -= m x /= 60 print(str(x) + ":" + str(m) + ":" + str(s))
s791737903
Accepted
20
7,640
127
x = int(input()) s = x % 60 x -= s x /= 60 m = x % 60 x -= m x /= 60 print(str(int(x)) + ":" + str(int(m)) + ":" + str(int(s)))
s336456865
p02612
u298445293
2,000
1,048,576
Wrong Answer
29
9,064
38
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) A = 1000 - N print(A)
s482559886
Accepted
28
9,072
86
N = int(input()) A = int(N/1000) if A != N/1000: print(1000*(A+1)-N) else: print(0)
s845303606
p03475
u993622994
3,000
262,144
Wrong Answer
40
5,212
572
A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) N = int(input()) c = [] s = [] f = [] t = [] t_c = [] for i in range(N-1): C, S, F = map(int, input().split()) c.append(C) s.append(S) f.append(F) T = lcm(S, F) t.append(T) t_c.append(T+C) c.reverse() s.reverse() f.reverse() t.reverse() t_c.reverse() ans = [0, t_c[0]] for i in range(1, N-1): if t[i-1] > t[i] and t_c[i-1] > t_c[i]: calc = max(ans) else: calc = ans[i] + t_c[i] - s[i-1] ans.append(calc) ans.reverse() print(*ans, sep='\n')
s620063318
Accepted
96
3,188
408
N = int(input()) csf = [list(map(int, input().split())) for _ in range(N-1)] ans = [] for i in range(N): t = 0 for j in range(i, N-1): C = csf[j][0] S = csf[j][1] F = csf[j][2] if S <= t: if t % F == 0: t += C else: t += F - t % F + C else: t = C + S ans.append(t) print(*ans, sep='\n')
s581872858
p03385
u342801789
2,000
262,144
Wrong Answer
17
2,940
65
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
s = input() if s == 'abc': print('Yes') else: print('No')
s726958385
Accepted
17
3,060
180
s = input() s_list = list(s) s_sort_list = sorted(s_list) s_sort = ','.join(s_sort_list) s_sort = s_sort.replace(',', '') if s_sort == 'abc': print('Yes') else: print('No')
s422958476
p03377
u411858517
2,000
262,144
Wrong Answer
17
2,940
89
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if X - A <= B: print("Yes") else: print("No")
s236127902
Accepted
17
2,940
94
A, B, X = map(int, input().split()) if 0 <= X - A <= B: print("YES") else: print("NO")
s491768671
p03149
u853185302
2,000
1,048,576
Wrong Answer
18
3,060
412
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
s = input() target = 'keyence' s_len = len(s) flg = 0 target1_len = 0 for i in range(8): target1_ind = -1 target1 = target[0:i] target2 = target[i:7] if target1 in s: target1_ind = s.index(target1) print(target1_ind) target1_len = len(target1) if target2 in s[target1_ind+target1_len:s_len]: flg = 1 if flg == 1: print('YES') else: print('NO')
s216668940
Accepted
17
2,940
204
N_list = input().split() flg = 0 if '1' in N_list: if '9' in N_list: if '7' in N_list: if '4' in N_list: flg = 1 if flg == 1: print('YES') else: print('NO')
s114689632
p02396
u095590628
1,000
131,072
Wrong Answer
140
5,608
97
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.
a = int(input()) i = 1 while(a != 0): print("Case ",i,": ",a) i = 1 a = int(input())
s854537339
Accepted
140
5,604
109
a = int(input()) i = 1 while(a != 0): print("Case {0}: {1}".format(i,a)) i += 1 a = int(input())
s113138591
p03796
u004025573
2,000
262,144
Wrong Answer
17
2,940
131
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
mod=1000000007 def P(x): ans=1 for i in range(x): ans=ans*(i+1)%mod return(ans) n=int(input()) print(n)
s088356266
Accepted
35
2,940
134
mod=1000000007 def P(x): ans=1 for i in range(x): ans=ans*(i+1)%mod return(ans) n=int(input()) print(P(n))
s081304554
p02694
u115877451
2,000
1,048,576
Wrong Answer
25
9,168
86
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
a=int(input()) count=0 b=100 while b<=a: b=b*1.01 b=int(b) count+=1 print(count)
s283355954
Accepted
23
9,172
85
a=int(input()) count=0 b=100 while b<a: b=b*1.01 b=int(b) count+=1 print(count)
s933085732
p03399
u144980750
2,000
262,144
Wrong Answer
17
2,940
92
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(i)) for i in range(2)] b=[int(input(i)) for i in range(2)] print(min(a)+min(b))
s497939491
Accepted
17
2,940
90
a=[int(input()) for i in range(2)] b=[int(input()) for i in range(2)] print(min(a)+min(b))
s390699258
p03351
u290187182
2,000
1,048,576
Wrong Answer
26
3,828
421
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
import sys import copy import math import bisect import pprint import bisect from functools import reduce from copy import deepcopy from collections import deque def lcm(x, y): return (x * y) // math.gcd(x, y) if __name__ == '__main__': a = [int(i) for i in input().split()] if abs(a[0]-a[2]) <a[3] or (abs(a[0] -a[1]) <a[3] and abs(a[1]-a[2]) <a[3]): print("Yes") else: print("No")
s867226880
Accepted
25
3,828
420
import sys import copy import math import bisect import pprint import bisect from functools import reduce from copy import deepcopy from collections import deque def lcm(x, y): return (x * y) // math.gcd(x, y) if __name__ == '__main__': a = [int(i) for i in input().split()] if abs(a[0]-a[2]) <=a[3] or (abs(a[0] -a[1]) <=a[3] and abs(a[1]-a[2]) <=a[3]): print("Yes") else: print("No")
s176468964
p02606
u477837488
2,000
1,048,576
Wrong Answer
30
9,124
108
How many multiples of d are there among the integers between L and R (inclusive)?
L, R, d = map(int, input().split()) if L % d == 0: print((R - L) // d + 1) else: print((R - L) // d)
s133574590
Accepted
25
9,032
58
l, r, d = map(int, input().split()) print(r//d - (l-1)//d)
s730842820
p03251
u625741705
2,000
1,048,576
Wrong Answer
17
3,064
170
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) if(max(x) < min(y)-1): print("No War") else: print("War")
s083240119
Accepted
17
3,060
192
N,M,X,Y = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) x.append(X) y.append(Y) if(max(x) < min(y)): print("No War") else: print("War")
s260626902
p03433
u678875535
2,000
262,144
Wrong Answer
17
3,060
322
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N=int(input()) A=int(input()) def hantei(N, A): if (N - A) <= 0: print("No") else: if ((N - A) % 100) != 0: print("No") elif ((N-A) % 100) == 0 and ((N-A) % 500) == 0: print("Yes") else: print("No") if __name__ == "__main__": hantei(N, A)
s483442914
Accepted
18
2,940
172
N=int(input()) A=int(input()) def hantei(N, A): if (N % 500) - A <= 0: print("Yes") else: print("No") if __name__ == "__main__": hantei(N, A)
s399989957
p03163
u841623074
2,000
1,048,576
Wrong Answer
215
15,508
250
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
import numpy as np N,W=map(int,input().split()) w,v=[],[] for i in range(N): a,b=map(int,input().split()) w+=[a] v+=[b] DP=np.zeros(W+1,dtype=int) print(DP) for i in range(N): DP[w[i]:]=np.maximum(DP[:-w[i]]+v[i],DP[w[i]:]) print(DP)
s783315942
Accepted
221
15,476
245
import numpy as np N,W=map(int,input().split()) w,v=[],[] for i in range(N): a,b=map(int,input().split()) w+=[a] v+=[b] DP=np.zeros(W+1,dtype=int) for i in range(N): DP[w[i]:]=np.maximum(DP[:-w[i]]+v[i],DP[w[i]:]) print(max(DP))
s651221979
p03597
u268285577
2,000
262,144
Wrong Answer
17
2,940
65
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
N = int(input()) A = int(input()) brack = N ** N - A print(brack)
s834050845
Accepted
17
2,940
65
n = int(input()) a = int(input()) brack = n ** 2 - a print(brack)
s166547193
p02613
u882564128
2,000
1,048,576
Wrong Answer
149
9,160
298
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) C = [0]*4 for i in range(N): S = input() if S == 'AC': C[0] += 1 elif S == 'WA': C[1] += 1 elif S == 'TLE': C[2] += 1 elif S == 'RE': C[3] += 1 print('AC ×', C[0]) print('WA ×', C[1]) print('TLE ×', C[2]) print('RE ×', C[3])
s621901416
Accepted
149
9,160
314
N = int(input()) C = [0]*4 for i in range(N): S = input() if S == 'AC': C[0] += 1 elif S == 'WA': C[1] += 1 elif S == 'TLE': C[2] += 1 elif S == 'RE': C[3] += 1 print('AC x '+str(C[0])) print('WA x '+str(C[1])) print('TLE x '+str(C[2])) print('RE x '+str(C[3]))
s267018983
p02612
u690781906
2,000
1,048,576
Wrong Answer
28
9,024
33
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s905198132
Accepted
25
9,116
81
N = int(input()) if N % 1000 == 0: print(0) else: print(1000 - N % 1000)
s297480767
p02850
u595905528
2,000
1,048,576
Wrong Answer
548
47,768
824
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
from collections import deque N = int(input()) node_branch = [[] for _ in range(N+1)] branch = [0] * (N) link = [0] * (N+1) checked = [False] * (N+1) for num in range(N - 1): a, b = map(int, input().split()) node_branch[a].append((b, num+1)) node_branch[b].append((a, num+1)) maxlen = 0 for i, node in enumerate(node_branch): if maxlen < len(node): maxlen = len(node) maxnode = i + 1 print(maxlen) d = deque() d.append(maxnode) link[1] = 0 checked[maxnode] = True while len(d)>0: now = d.popleft() color = 1 for n, b in node_branch[now]: if checked[n]: continue if color == link[now]: color += 1 branch[b] = color link[n] = color checked[n] = True d.append(n) for i in range(1, N): print(branch[i])
s805100454
Accepted
518
47,628
839
from collections import deque N = int(input()) node_branch = [[] for _ in range(N+1)] branch = [0] * (N) link = [0] * (N+1) checked = [False] * (N+1) for num in range(N - 1): a, b = map(int, input().split()) node_branch[a].append((b, num+1)) node_branch[b].append((a, num+1)) maxlen = 0 for i, node in enumerate(node_branch): if maxlen < len(node): maxlen = len(node) maxnode = i print(maxlen) d = deque() d.append(maxnode) link[1] = 0 checked[maxnode] = True while len(d)>0: now = d.popleft() color = 1 for n, b in node_branch[now]: if checked[n]: continue if color == link[now]: color += 1 branch[b] = color link[n] = color color += 1 checked[n] = True d.append(n) for i in range(1, N): print(branch[i])
s406186228
p03503
u665038048
2,000
262,144
Wrong Answer
19
3,064
456
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
N = int(input()) F = [] P = [] for i in range(N): F.append(list(map(int, input().split()))) for j in range(N): P.append(list(map(int, input().split()))) even_list = [] odd_list = [] for i in range(N): even_sum = 0 odd_sum = 0 for j in range(5): even_sum += F[i][0::2][j]*P[i][2*j] odd_sum += F[i][1::2][j]*P[i][2*j+1] even_list.append(even_sum) odd_list.append(odd_sum) print(max(sum(even_list), sum(odd_list)))
s897839653
Accepted
40
3,064
404
max_time = 10 n = int(input()) f = [sum(v << max_time - k - 1 for k, v in enumerate(map(int, input().split()))) for i in range(n)] p = [[int(j) for j in input().split()] for i in range(n)] pattern = [sum(i >> j & 1 for j in range(max_time)) for i in range(2 ** max_time)] print(max(sum( p[j][pattern[f[j] & i]] for j in range(n)) for i in range(1, 2 ** max_time)))
s176860355
p02678
u449473917
2,000
1,048,576
Wrong Answer
694
35,940
476
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque n,m=map(int,input().split()) graph=[[] for i in range(n)] sirusi=[0]*n for i in range(m): a,b=map(int,input().split()) a-=1;b-=1 graph[a].append(b) graph[b].append(a) D=deque([0]) visited=[False]*n visited[0]=True while D: v=D.popleft() for i in graph[v]: if visited[i]:continue visited[i]=True sirusi[i]=v D.append(i) print("Yes") print(sirusi) for i in range(1,n): print(sirusi[i]+1)
s701487068
Accepted
671
34,844
462
from collections import deque n,m=map(int,input().split()) graph=[[] for i in range(n)] sirusi=[0]*n for i in range(m): a,b=map(int,input().split()) a-=1;b-=1 graph[a].append(b) graph[b].append(a) D=deque([0]) visited=[False]*n visited[0]=True while D: v=D.popleft() for i in graph[v]: if visited[i]:continue visited[i]=True sirusi[i]=v D.append(i) print("Yes") for i in range(1,n): print(sirusi[i]+1)
s419136361
p02255
u217703215
1,000
131,072
Wrong Answer
20
5,596
255
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def insertionSort(A,N): for i in range(1,N): v=A[i] j=i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j-=1 A[j+1]=v print(A) return A N=int(input()) A=input().split() insertionSort(A,N)
s126442210
Accepted
30
5,984
333
N=int(input()) A=[0 for i in range(N)] A=input().split() for i in range(N): A[i]=(int)(A[i]) for i in range(N): v=A[i] j=i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j=j-1 A[j+1]=v for i in range(N): if i!=N-1: print(A[i],end=" ") if i==N-1: print(A[i])
s676270142
p03433
u304209389
2,000
262,144
Wrong Answer
17
2,940
131
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
Nyen = int(input()) Amai = int(input()) while Nyen > 500: Nyen = Nyen - 500 if Nyen < Amai: print('YES') else: print('NO')
s229381704
Accepted
17
2,940
98
Nyen = int(input()) Amai = int(input()) if Nyen % 500 <= Amai: print('Yes') else: print('No')
s698804585
p03416
u999503965
2,000
262,144
Wrong Answer
30
9,100
212
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(1,10): for j in range(1,10): for k in range(1,10): num=int(str(i)+str(j)+str(k)+str(j)+str(i)) if a<=num<=b: cnt+=1 print(cnt)
s083148665
Accepted
30
9,112
212
a,b=map(int,input().split()) cnt=0 for i in range(1,10): for j in range(0,10): for k in range(0,10): num=int(str(i)+str(j)+str(k)+str(j)+str(i)) if a<=num<=b: cnt+=1 print(cnt)
s537748299
p03228
u067986021
2,000
1,048,576
Wrong Answer
18
3,064
218
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 = [int(i) for i in input().split(" ")] for i in range(k): if a % 2 == 1: a -= 1 b += (a / 2) a = a / 2 if b % 2 == 1: b -= 1 a += (b / 2) b = b / 2 print("{} {}".format(int(a), int(b)))
s318692610
Accepted
18
3,064
309
a, b, k = [int(i) for i in input().split(" ")] for i in range(int(k / 2)): if a % 2 == 1: a -= 1 b += (a / 2) a = a / 2 if b % 2 == 1: b -= 1 a += (b / 2) b = b / 2 if k % 2 == 1: if a % 2 == 1: a -= 1 b += (a / 2) a = a / 2 print("{} {}".format(int(a), int(b)))
s979706714
p03674
u203900263
2,000
262,144
Wrong Answer
2,104
13,812
500
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
import math def nCm(n, m): return math.factorial(n) // (math.factorial(m) * (math.factorial(n - m))) n = int(input()) a = list(map(int, input().split())) saw = [-1] * n left = 0 right = 0 for i in range(n): if saw[a[i] - 1] == -1: saw[a[i] - 1] = i else: left, right = saw[a[i] -1 ], n - i break print(left, right) for i in range(1, n+2): if i == 1: print(n) else: print((nCm(n+1, i) - max(0, (left + right - (i - 2)))) % 1000000007)
s384815117
Accepted
1,375
20,420
914
def power(x, n): y = 1 while n > 0: if n % 2 == 0: x = (x * x) % (10 ** 9 + 7) n = n // 2 else: y = (y * x) % (10 ** 9 + 7) n = n - 1 return y MOD = 10 ** 9 + 7 n = int(input()) a = list(map(int, input().split())) fact = [1] * (n + 2) inv = [1] * (n + 3) for i in range(1, n + 2): fact[i] = (i * fact[i - 1]) % MOD inv[i] = power(fact[i], MOD - 2) % MOD def nCm(n, m): global fact global inv return fact[n] * inv[m] % MOD * inv[n - m] % MOD saw = [-1] * n left = 0 right = 0 for i in range(n): if saw[a[i] - 1] == -1: saw[a[i] - 1] = i else: left, right = saw[a[i] - 1], n - i break for i in range(1, n + 2): if i == 1: print(n) elif left + right >= i - 1: print((nCm(n + 1, i) - nCm(left + right, i - 1)) % MOD) else: print(nCm(n + 1, i))
s072068674
p03457
u086624329
2,000
262,144
Wrong Answer
911
3,316
276
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
n=int(input()) start=[0,0,0] ans=0 for i in range(n): cont=list(map(int,input().split())) if abs(start[0]-cont[0])!=abs(start[1]-cont[1])+abs(start[2]-cont[2]): print('No') ans=1 start=cont if ans==0: print('Yes')
s027400850
Accepted
415
3,064
490
n=int(input()) start=[0,0,0] ans=0 for i in range(n): cont=list(map(int,input().split())) x=abs(start[0]-cont[0]) y=abs(start[1]-cont[1])+abs(start[2]-cont[2]) if x<y: ans=1 else: if x%2==0: if y%2!=0: ans=1 else: if y%2!=1: ans=1 start=cont if ans==0: print('Yes') else: print('No')
s455944086
p03730
u731368968
2,000
262,144
Wrong Answer
17
2,940
122
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()) f=False for i in range(b): if a*i%b==c: f=True print('Yes' if f else 'No')
s994719726
Accepted
17
2,940
122
a, b, c = map(int, input().split()) f=False for i in range(b): if a*i%b==c: f=True print('YES' if f else 'NO')
s226989492
p03658
u744898490
2,000
262,144
Wrong Answer
18
3,064
212
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.
ab = input().split(' ') st = input().split(' ') st = [int(x) for x in st] k = int(ab[1]) max1 =0 for i in range( int(ab[0])-k): if sum(st[i:i+k+1] ) > max1: max1= sum(st[i:i+k] ) print(max1)
s091613529
Accepted
20
3,064
210
ab = input().split(' ') st = input().split(' ') st = [int(x) for x in st] k = int(ab[1]) max1 =0 pl = sum(st) for i in range(int(ab[0])-k): pl -= min(st) del st[st.index(min(st))] print(pl)
s032697963
p03565
u131634965
2,000
262,144
Wrong Answer
17
3,064
525
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`.
ss=input()[::-1] t=input()[::-1] match_len=0 for i in range(len(ss)-len(t)): for j in range(len(t)): if ss[i+j]=="?" or ss[i+j]==t[j]: match_len+=1 print("match") else: match_len=0 break if match_len==len(t): ss=ss[:i]+t+ss[i+len(t):] ss=ss.replace("?","a") print(ss[::-1]) exit() print("UNRESORABLE")
s049424677
Accepted
17
3,060
467
ss=input()[::-1] t=input()[::-1] for i in range(len(ss)-len(t)+1): match_len=0 for j in range(len(t)): if ss[i+j]=="?" or ss[i+j]==t[j]: match_len+=1 else: break if match_len==len(t): ss=ss[:i]+t+ss[i+len(t):] ss=ss.replace("?","a") print(ss[::-1]) exit() print("UNRESTORABLE")
s894395659
p03973
u139112865
2,000
262,144
Wrong Answer
244
7,080
268
N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i. Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets a positive integer P indicating its price, and shows this product to customers in order, starting from the front of the line. This step is repeated as described below. At each step, when a product is shown to a customer, if price P is equal to or less than the cash held by that customer at the time, the customer buys the product and Mr. Takahashi ends the current step. That is, the cash held by the first customer in line with cash equal to or greater than P decreases by P, and the next step begins. Mr. Takahashi can set the value of positive integer P independently at each step. He would like to sell as many products as possible. However, if a customer were to end up with 0 cash on hand after a purchase, that person would not have the fare to go home. Customers not being able to go home would be a problem for Mr. Takahashi, so he does not want anyone to end up with 0 cash. Help out Mr. Takahashi by writing a program that determines the maximum number of products he can sell, when the initial cash in possession of each customer is given.
n = int(input()) a = [int(input()) for _ in range(n)] ans = 0 tmp = 1 for i in range(n): if a[i] <= tmp: tmp = max(tmp, a[i] + 1) continue ans += -(-(a[i] - tmp) // tmp) a[i] = a[i] + (-(a[i] - tmp) // tmp) * tmp a[i] = 1 print(ans)
s533045349
Accepted
246
7,080
201
n = int(input()) a = [int(input()) for _ in range(n)] ans = 0 tmp = 1 for i in range(n): if a[i] > tmp: ans += (a[i] - 1) // tmp a[i] = 1 tmp = max(tmp, a[i] + 1) print(ans)
s575634072
p02390
u800408401
1,000
131,072
Wrong Answer
20
5,580
94
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()) h=int(S//360) m=int((S-(h*360))/60) s=int(S-(h*360+m*60)) print(h,':',m,':',s)
s742194265
Accepted
20
5,588
104
S=int(input()) h=int(S//3600) m=int((S-(h*3600))/60) s=int(S-(h*3600+m*60)) print(h,':',m,':',s,sep='')
s466698329
p03407
u094565093
2,000
262,144
Wrong Answer
17
2,940
86
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A, B, C = map(int, input().split()) if A+B<=C: print("Yes") else: print("No")
s646577328
Accepted
17
2,940
86
A, B, C = map(int, input().split()) if A+B>=C: print("Yes") else: print("No")
s747152923
p03635
u475966842
2,000
262,144
Wrong Answer
18
2,940
39
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
n,m=map(int,input().split()) print(n*m)
s364057194
Accepted
17
2,940
47
n,m=map(int,input().split()) print((n-1)*(m-1))
s718183989
p02565
u315078622
5,000
1,048,576
Wrong Answer
233
10,752
3,419
Consider placing N flags on a line. Flags are numbered through 1 to N. Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D. Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
from itertools import product import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 6 + 100) class StronglyConnectedComponets: def __init__(self, n: int) -> None: self.n = n self.edges = [[] for _ in range(n)] self.rev_edeges = [[] for _ in range(n)] self.vs = [] self.order = [0] * n self.used = [False] * n def add_edge(self, from_v: int, to_v: int) -> None: self.edges[from_v].append(to_v) self.rev_edeges[to_v].append(from_v) def dfs(self, v: int) -> None: self.used[v] = True for child in self.edges[v]: if not self.used[child]: self.dfs(child) self.vs.append(v) def rdfs(self, v: int, k: int) -> None: self.used[v] = True self.order[v] = k for child in self.rev_edeges[v]: if not self.used[child]: self.rdfs(child, k) def run(self) -> int: self.used = [False] * self.n self.vs.clear() for v in range(self.n): if not self.used[v]: self.dfs(v) self.used = [False] * self.n k = 0 for v in reversed(self.vs): if not self.used[v]: self.rdfs(v, k) k += 1 return k class TwoSat(StronglyConnectedComponets): def __init__(self, num_var: int) -> None: super().__init__(2 * num_var + 1) self.num_var = num_var self.ans = [] def add_constraint(self, a: int, b: int) -> None: super().add_edge(self._neg(a), self._pos(b)) super().add_edge(self._neg(b), self._pos(a)) def _pos(self, v: int) -> int: return v if v > 0 else self.num_var - v def _neg(self, v: int) -> int: return self.num_var + v if v > 0 else -v def run(self) -> bool: super().run() self.ans.clear() for i in range(self.num_var): if self.order[i + 1] == self.order[i + self.num_var + 1]: return False self.ans.append(self.order[i + 1] > self.order[i + self.num_var + 1]) return True def main() -> None: N, D = map(int, input().split()) flags = [] for _ in range(N): x_i, y_i = map(int, input().split()) if abs(x_i - y_i) < D: print("No") break flags.append((x_i, y_i)) sat = TwoSat(2 * N) for i in range(N): sat.add_constraint(2*i+1, 2*i+2) for i, (x_i, y_i) in enumerate(flags): for j, (x_j, y_j) in enumerate(flags[i+1:], i+1): if abs(x_i - x_j) < D: sat.add_constraint(-(2*i+1), -(2*j+1)) if abs(y_i - x_j) < D: sat.add_constraint(-(2*i+2), -(2*j+1)) if abs(x_i - y_j) < D: sat.add_constraint(-(2*i+1), -(2*j+2)) if abs(y_i - y_j) < D: sat.add_constraint(-(2*i+2), -(2*j+2)) if sat.run(): print("Yes") print(*[x_i if sat.ans[2*i-1] else y_i for i, (x_i, y_i) in enumerate(flags)], sep="\n") else: print("No") if __name__ == "__main__": main()
s410279633
Accepted
206
9,940
3,007
import sys input = sys.stdin.buffer.readline class StronglyConnectedComponets: def __init__(self, n: int) -> None: self.n = n self.edges = [[] for _ in range(n)] self.rev_edeges = [[] for _ in range(n)] self.vs = [] self.order = [0] * n self.used = [False] * n def add_edge(self, from_v: int, to_v: int) -> None: self.edges[from_v].append(to_v) self.rev_edeges[to_v].append(from_v) def dfs(self, v: int) -> None: self.used[v] = True for child in self.edges[v]: if not self.used[child]: self.dfs(child) self.vs.append(v) def rdfs(self, v: int, k: int) -> None: self.used[v] = True self.order[v] = k for child in self.rev_edeges[v]: if not self.used[child]: self.rdfs(child, k) def run(self) -> int: self.used = [False] * self.n self.vs.clear() for v in range(self.n): if not self.used[v]: self.dfs(v) self.used = [False] * self.n k = 0 for v in reversed(self.vs): if not self.used[v]: self.rdfs(v, k) k += 1 return k class TwoSat(StronglyConnectedComponets): def __init__(self, num_var: int) -> None: super().__init__(2 * num_var + 1) self.num_var = num_var self.ans = [] def add_constraint(self, a: int, b: int) -> None: super().add_edge(self._neg(a), self._pos(b)) super().add_edge(self._neg(b), self._pos(a)) def _pos(self, v: int) -> int: return v if v > 0 else self.num_var - v def _neg(self, v: int) -> int: return self.num_var + v if v > 0 else -v def run(self) -> bool: super().run() self.ans.clear() for i in range(self.num_var): if self.order[i + 1] == self.order[i + self.num_var + 1]: return False self.ans.append(self.order[i + 1] > self.order[i + self.num_var + 1]) return True def main() -> None: N, D = map(int, input().split()) flags = [tuple(int(x) for x in input().split()) for _ in range(N)] sat = TwoSat(N) for i, (x_i, y_i) in enumerate(flags, 1): for j, (x_j, y_j) in enumerate(flags[i:], i+1): if abs(x_i - x_j) < D: sat.add_constraint(-i, -j) if abs(y_i - x_j) < D: sat.add_constraint(i, -j) if abs(x_i - y_j) < D: sat.add_constraint(-i, j) if abs(y_i - y_j) < D: sat.add_constraint(i, j) if sat.run(): print("Yes") print(*[x_i if sat.ans[i] else y_i for i, (x_i, y_i) in enumerate(flags)], sep="\n") else: print("No") if __name__ == "__main__": main()
s580238823
p03155
u438383815
2,000
1,048,576
Wrong Answer
17
2,940
79
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
a = int(input()) b = int(input()) c = int(input()) d = a-b c = a-c print(d*c)
s188058226
Accepted
17
2,940
83
a = int(input()) b = int(input()) c = int(input()) d = a-b+1 c = a-c+1 print(d*c)
s855794325
p03455
u221393935
2,000
262,144
Wrong Answer
17
2,940
83
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) if a*b%2==0: print("even") else: print("odd")
s207237835
Accepted
18
2,940
83
a,b=map(int,input().split()) if a*b%2==0: print("Even") else: print("Odd")
s111105004
p03385
u272377260
2,000
262,144
Wrong Answer
18
2,940
96
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
s = input() for i in "abc": if i not in s: break else: print('Yes') print('No')
s442214399
Accepted
18
2,940
98
s = input() for i in "abc": if i not in s: print('No') break else:print('Yes')
s914320426
p03399
u084357428
2,000
262,144
Wrong Answer
17
3,060
186
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(_) for _ in input().split()] if len(a) == 4 and all(1 <= item <= 1000 for item in a): print(min(a[0] + a[2], a[0] + a[3], a[1] + a[2], a[1] + a[3])) else: print('hoge!')
s133728246
Accepted
18
3,064
271
a = [] b = int(input()) a.append(b) c = int(input()) a.append(c) d = int(input()) a.append(d) e = int(input()) a.append(e) if len(a) == 4 and all(1 <= item <= 1000 for item in a): print(min(a[0] + a[2], a[0] + a[3], a[1] + a[2], a[1] + a[3])) else: print('hoge!')
s613647860
p02669
u989345508
2,000
1,048,576
Wrong Answer
2,206
10,984
2,240
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
import sys check=dict() N,a,b,c,d=0,0,0,0,0 def dfs_sub(n,ttf,cha): global check,d if n%ttf<=(ttf//2): if n//ttf==0: if n//ttf in check: if check[n//ttf]>check[n]+(n%ttf)*d: check[n//ttf]=check[n]+(n%ttf)*d dfs(n//ttf,check[n]+(n%ttf)*d) else: check[n//ttf]=check[n]+(n%ttf)*d dfs(n//ttf,check[n]+(n%ttf)*d) else: if n//ttf in check: if check[n//ttf]>check[n]+(n%ttf)*d+cha: check[n//ttf]=check[n]+(n%ttf)*d+cha dfs(n//ttf,check[n]+(n%ttf)*d+cha) else: check[n//ttf]=check[n]+(n%ttf)*d+cha dfs(n//ttf,check[n]+(n%ttf)*d+cha) if n%ttf>(ttf//2) or (ttf==2 and n%ttf==1): if 1+n//ttf in check: if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha: check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha dfs(1+n//ttf,check[n]+(ttf-n%ttf)*d+cha) else: check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha dfs(1+n//ttf,check[n]+(ttf-n%ttf)*d+cha) def dfs(n,x): global check,a,b,c,d if n==1: if n-1 in check: if check[n-1]>x+d: check[n-1]=x+d else: check[n-1]=x+d if n==0: return dfs_sub(n,2,a) dfs_sub(n,3,b) dfs_sub(n,5,c) t=int(input()) ans=[0]*t for i in range(t): N,a,b,c,d=map(int,input().split()) check=dict() check[N]=0 dfs(N,0) ans[i]=check[0] for i in range(t): print(ans[i])
s971337432
Accepted
399
11,216
207
def f(n): if (m:=s.get(n,-1))<0:s[n]=m=min([d*n]+[abs(p*k-n)*d+c+f(k)for p,c in zip((2,3,5),b)for k in(n//p,0--n//p)]) return m exec("n,*b,d=map(int,input().split());s={0:0,1:d};print(f(n));"*int(input()))
s950136893
p03720
u027622859
2,000
262,144
Wrong Answer
17
3,064
176
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n, m = map(int, input().split()) ab = [input().split() for _ in range(m)] ab = [item for ab in ab for item in ab] print(ab) for x in range(1, n+1): print(ab.count(str(x)))
s062697906
Accepted
18
3,064
166
n, m = map(int, input().split()) ab = [input().split() for _ in range(m)] ab = [item for ab in ab for item in ab] for x in range(1, n+1): print(ab.count(str(x)))
s804927295
p03359
u740047492
2,000
262,144
Wrong Answer
17
2,940
57
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().split()) print(a if a<b else a-1)
s291387152
Accepted
17
2,940
58
a, b = map(int, input().split()) print(a if a<=b else a-1)
s983308818
p03555
u846155148
2,000
262,144
Wrong Answer
25
8,952
164
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
c = input('') d = input('') if c == d[::-1]: print('Yes') else: print('No')
s627634593
Accepted
27
8,928
164
c = input('') d = input('') if c == d[::-1]: print('YES') else: print('NO')
s642382838
p03054
u562935282
2,000
1,048,576
Wrong Answer
113
4,004
886
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.
import sys input = sys.stdin.readline def main(): h, w, n = map(int, input().split()) y, x = map(int, input().split()) y -= 1 x -= 1 s, t = input(), input() u, d, l, r = 0, h - 1, 0, w - 1 for ss, tt in zip(s[::-1], t[::-1]): if tt == 'U': d = min(d + 1, h - 1) elif tt == 'D': u = max(u - 1, 0) elif tt == 'L': r = min(r + 1, w - 1) else: l = max(l - 1, 0) if ss == 'U': u += 1 elif ss == 'D': d -= 1 elif ss == 'L': l += 1 else: r -= 1 # ss == 'R' if l > r or u > d: print('NO') return if l <= x <= r and u <= y <= d: print('YES') return else: print('NO') return if __name__ == '__main__': main()
s030204054
Accepted
110
4,024
807
def main(): h, w, n = map(int, input().split()) y, x = map(int, input().split()) s, t = input(), input() u, d, l, r = 1, h, 1, w for ss, tt in zip(s[::-1], t[::-1]): if tt == 'U': d = min(d + 1, h) elif tt == 'D': u = max(u - 1, 1) elif tt == 'L': r = min(r + 1, w) else: l = max(l - 1, 1) if ss == 'U': u += 1 elif ss == 'D': d -= 1 elif ss == 'L': l += 1 else: r -= 1 # ss == 'R' if l > r or u > d: print('NO') return if l <= x <= r and u <= y <= d: print('YES') return else: print('NO') return if __name__ == '__main__': main()
s971953638
p03624
u840958781
2,000
262,144
Wrong Answer
18
3,188
131
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
s=input() all="abcdefghijklmnopqrstuvwxyz" for i in all: if i not in s: print(i) elif i=="z": print("None")
s737896170
Accepted
17
3,188
155
s=input() ans=1 all="abcdefghijklmnopqrstuvwxyz" for i in all: if i not in s: print(i) ans=0 break if ans==1: print("None")
s043375876
p03361
u637551956
2,000
262,144
Wrong Answer
20
3,064
1,118
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
H,W=map(int,input().split()) S = [list(str(input())) for i in range(H)] judge=True for i in range(H): for j in range(W): if S[i][j]=='#': judge1=True judge2=True judge3=True judge4=True try:S[i][j-1] except IndexError:judge1=False else: if S[i][j-1]=='.': judge1=False try:S[i][j+1] except IndexError:judge2=False else: if S[i][j+1]=='.': judge2=False try:S[i+1][j] except IndexError:judge3=False else: if S[i+1][j]=='.': judge3=False try:S[i-1][j] except IndexError:judge4=False else: if S[i-1][j]=='.': judge4=False if judge1==False and judge2==False and judge3==False and judge4==False: judge=False break if judge==False:break print(judge)
s448673474
Accepted
20
3,064
1,144
H,W=map(int,input().split()) S = [list(str(input())) for i in range(H)] judge=True for i in range(H): for j in range(W): if S[i][j]=='#': judge1=True judge2=True judge3=True judge4=True try:S[i][j-1] except IndexError:judge1=False else: if S[i][j-1]=='.': judge1=False try:S[i][j+1] except IndexError:judge2=False else: if S[i][j+1]=='.': judge2=False try:S[i+1][j] except IndexError:judge3=False else: if S[i+1][j]=='.': judge3=False try:S[i-1][j] except IndexError:judge4=False else: if S[i-1][j]=='.': judge4=False if judge1==False and judge2==False and judge3==False and judge4==False: judge=False break if judge==False:break if judge:print('Yes') else:print('No')
s165230773
p03486
u168778320
2,000
262,144
Wrong Answer
19
3,064
727
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.
class Judge(): @classmethod def judge1(cls,s,t): if len(s) == len(t): return False judge = True n = min(len(s),len(t)) for i in range(n): judge = judge and s[i]==t[i] return judge @classmethod def judge2(cls,s,t): n = min(len(s),len(t)) for l in range(1,n): judge = True for i in range(l-1): judge = judge and s[i]==t[i] judge = judge and s[l] < t[l] if judge == True: break return judge s = list(input()) s.sort() t = list(input()) t.sort() judge = Judge.judge1(s,t) or Judge.judge2(s,t) if judge: print('Yes') else: print('No')
s894951742
Accepted
17
2,940
149
s = list(input()) s.sort() s = ''.join(s) t= list(input()) t.sort() t = ''.join(reversed(list(t))) if s < t: print('Yes') else: print('No')
s885481601
p03337
u444856278
2,000
1,048,576
Wrong Answer
17
2,940
63
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
a,b = [int() for i in input().split()] print(max(a+b,a-b,a*b))
s939722402
Accepted
17
2,940
64
a,b = [int(i) for i in input().split()] print(max(a+b,a-b,a*b))
s991696119
p02669
u225388820
2,000
1,048,576
Wrong Answer
276
10,984
378
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
t=int(input()) INF=10**19 def dfs(k): if k==1:return d if k==0:return 0 if k in dic:return dic[k] ans=INF ans=min(ans,dfs(k//2)+a+k%2*d,dfs((k+1)//2)+a+-k%2*d,dfs(k//3)+b+k%3*d,dfs((k+2)//3)+b+-k%3*d,dfs(k//5)+c+k%5*d,dfs((k+4)//5)+c+-k%5*d) dic[k]=ans return ans for _ in range(t): dic={} n,a,b,c,d=map(int,input().split()) print(dfs(n))
s218673512
Accepted
284
10,888
321
def f(k): if k==1:return d if k==0:return 0 if k in m:return m[k] s=min(k*d,f(k//2)+a+k%2*d,f(-(-k//2))+a+-k%2*d,f(k//3)+b+k%3*d,f(-(-k//3))+b+-k%3*d,f(k//5)+c+k%5*d,f(-(-k//5))+c+-k%5*d) m[k]=s return s for _ in range(int(input())): m={} n,a,b,c,d=map(int,input().split()) print(f(n))
s388664059
p03693
u062484507
2,000
262,144
Wrong Answer
17
2,940
85
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) print('Yes' if (r*100+g*10+b) % 4 == 0 else 'No')
s730567887
Accepted
17
2,940
85
r, g, b = map(int, input().split()) print('YES' if (r*100+g*10+b) % 4 == 0 else 'NO')
s912085386
p02411
u104931506
1,000
131,072
Wrong Answer
20
7,512
347
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
while True: m, f, r = map(int, input().split()) A = m + f + r if m == f == r == -1: break elif m == 0 or f == 0: print('F') elif A >= 80: print('A') elif 65 <= A < 80: print('B') elif 50 <= A < 65: print('C') elif 30 <= A < 50: print('D') else: print('F')
s330111671
Accepted
40
7,668
406
while True: m, f, r = map(int, input().split()) A = m + f if m == f == r == -1: break elif m == -1 or f == -1: print('F') elif A >= 80: print('A') elif 65 <= A < 80: print('B') elif 50 <= A < 65: print('C') elif 30 <= A < 50: if 50 <= r: print('C') else: print('D') else: print('F')
s868652503
p03044
u761989513
2,000
1,048,576
Wrong Answer
631
32,276
691
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
n = int(input()) a = sorted([list(map(int, input().split())) for i in range(n - 1)]) color = [-1 for i in range(n)] color[0] = 1 for i in a: u, v, w = i u -= 1 v -= 1 if w % 2 == 0: if color[u] == 0: color[v] = 0 if color[u] == 1: color[v] = 1 if color[v] == 0: color[u] = 0 if color[v] == 1: color[u] = 1 else: if color[u] == 0: color[v] = 1 if color[u] == 1: color[v] = 0 if color[v] == 0: color[u] = 1 if color[v] == 1: color[u] = 0 for i in color: if i == -1: print(0) else: print(i)
s531845399
Accepted
809
45,132
791
import heapq def dijkstra(graph, node, start): dist = [float("inf") for _ in range(node)] dist[start] = 0 q = [] heapq.heappush(q, (0, start)) while q: cost, cur_node = heapq.heappop(q) if dist[cur_node] < cost: continue for nex_cost, nex_node in graph[cur_node]: dist_cand = dist[cur_node] + nex_cost if dist_cand < dist[nex_node]: dist[nex_node] = dist_cand heapq.heappush(q, (dist[nex_node], nex_node)) return dist n = int(input()) adj = [[] for _ in range(n)] for i in range(n - 1): a, b, c = map(int, input().split()) a -= 1 b -= 1 adj[a].append((c, b)) adj[b].append((c, a)) shortest = dijkstra(adj, n, 0) for i in shortest: print(i % 2)
s992897349
p03577
u133038626
2,000
262,144
Wrong Answer
16
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()[:-9])
s524183775
Accepted
17
2,940
19
print(input()[:-8])
s113275029
p02928
u708255304
2,000
1,048,576
Wrong Answer
1,854
3,188
472
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
N, K = map(int, input().split()) A = list(map(int, input().split())) mod = 1000000007 B = A * 2 syokiti_A = 0 syokiti_B = 0 for i in range(N): for j in range(i, N): if A[i] > A[j]: syokiti_A += 1 for i in range(N*2): for j in range(i, N*2): if B[i] > B[j]: syokiti_B += 1 ans = int((syokiti_A + syokiti_B*K*(K-1)/2)) % mod print(int(ans))
s903779753
Accepted
1,061
3,188
393
N, K = map(int, input().split()) A = list(map(int, input().split())) mod = 10**9+7 ans = 0 normal = 0 for i in range(N): for j in range(i+1, N): if A[i] > A[j]: normal += 1 un_normal = 0 for i in range(N): for j in range(N): if A[i] > A[j]: un_normal += 1 print((normal * K + un_normal * K * (K-1) // 2) % mod)
s057930637
p02620
u729133443
2,000
1,048,576
Wrong Answer
29
9,124
1
"Local search" is a powerful method for finding a high-quality solution. In this method, instead of constructing a solution from scratch, we try to find a better solution by slightly modifying the already found solution. If the solution gets better, update it, and if it gets worse, restore it. By repeating this process, the quality of the solution is gradually improved over time. The pseudo-code is as follows. solution = compute an initial solution (by random generation, or by applying other methods such as greedy) while the remaining time > 0: slightly modify the solution (randomly) if the solution gets worse: restore the solution For example, in this problem, we can use the following modification: pick the date d and contest type q at random and change the type of contest to be held on day d to q. The pseudo-code is as follows. t[1..D] = compute an initial solution (by random generation, or by applying other methods such as greedy) while the remaining time > 0: pick d and q at random old = t[d] # Remember the original value so that we can restore it later t[d] = q if the solution gets worse: t[d] = old The most important thing when using the local search method is the design of how to modify solutions. 1. If the amount of modification is too small, we will soon fall into a dead-end (local optimum) and, conversely, if the amount of modification is too large, the probability of finding an improving move becomes extremely small. 2. In order to increase the number of iterations, it is desirable to be able to quickly calculate the score after applying a modification. In this problem C, we focus on the second point. The score after the modification can, of course, be obtained by calculating the score from scratch. However, by focusing on only the parts that have been modified, it may be possible to quickly compute the difference between the scores before and after the modification. From another viewpoint, the impossibility of such a fast incremental calculation implies that a small modification to the solution affects a majority of the score calculation. In such a case, we may need to redesign how to modify solutions, or there is a high possibility that the problem is not suitable for local search. Let's implement fast incremental score computation. It's time to demonstrate the skills of algorithms and data structures you have developed in ABC and ARC! In this kind of contest, where the objective is to find a better solution instead of the optimal one, a bug in a program does not result in a wrong answer, which may delay the discovery of the bug. For early detection of bugs, it is a good idea to unit test functions you implemented complicated routines. For example, if you implement fast incremental score calculation, it is a good idea to test that the scores computed by the fast implementation match the scores computed from scratch, as we will do in this problem C.
0
s205948609
Accepted
1,391
122,188
491
from numba import njit from numpy import int64,zeros @njit('i8(i8[:],i8[:])',cache=True) def func(s,x): last=zeros(26,int64) score=0 for i,v in enumerate(x,1): last[v]=i c=0 for j in range(26): c+=s[j]*(i-last[j]) score+=s[i*26+v]-c return score def main(): d,*s=map(int,open(0).read().split()) s=int64(s) x=s[26*-~d:d*27+26]-1 for d,q in s[27*-~d:].reshape(-1,2): x[d-1]=q-1 print(func(s,x)) main()
s101255448
p03557
u111497285
2,000
262,144
Wrong Answer
857
24,012
884
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a = sorted(a) b = sorted(b) c = sorted(c) def bs(li, num): """return boundary index""" l = 0 r = len(li) - 1 if li[l] >= num: return -1 elif li[r] < num: return r while r-l > 1: mid = (l+r) // 2 if li[mid] < num: l = mid else: r = mid return l def bs_1(li, num): """return boundary index""" l = 0 r = len(li) - 1 if li[l] > num: return r elif li[r] <= num: return -1 while r-l > 1: mid = (l+r) // 2 if li[mid] <= num: l = mid else: r = mid return r ans = 0 for i in range(len(b)): c_i = bs_1(c, b[i]) a_i = bs(a, b[i]) ans += (n-c_i) * (a_i+1) print(ans)
s395035776
Accepted
1,549
22,720
911
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) cnt = [0] * len(b) a = sorted(a) c = sorted(c) for i in range(len(b)): target = b[i] l = 0 r = len(a) - 1 if a[l] >= target: cnt[i] += 0 elif a[r] < target: cnt[i] += len(a) else: while r - l > 1: mid = (l + r) // 2 if a[mid] >= target: r = mid else: l = mid cnt[i] += l + 1 # decide c cnt l = 0 r = len(c) - 1 if c[l] > target: cnt[i] *= len(c) elif c[r] <= target: cnt[i] *= 0 else: while r - l > 1: mid = (l + r) // 2 if c[mid] > target: r = mid else: l = mid cnt[i] *= len(c) - (l + 1) print(sum(cnt))
s072188544
p03623
u926678805
2,000
262,144
Wrong Answer
17
2,940
87
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
# coding: utf-8 x,a,b=map(int,input().split()) print('A' if abs(x-a)>abs(x-b) else 'B')
s962482137
Accepted
17
2,940
87
# coding: utf-8 x,a,b=map(int,input().split()) print('A' if abs(x-a)<abs(x-b) else 'B')
s750501107
p02608
u209275335
2,000
1,048,576
Wrong Answer
46
9,400
258
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()) li = [0]*n for i in range(1,32): for j in range(1,32): for k in range(1,32): if i*2 + j*2 + k*2 + i*j + j*k + k*i <= n: li[i*2 + j*2 + k*2 + i*j + j*k + k*i-1] += 1 for i in range(n): print(li[i])
s223845729
Accepted
1,026
9,368
268
n = int(input()) li = [0]*n for i in range(1,100): for j in range(1,100): for k in range(1,100): if i**2 + j**2 + k**2 + i*j + j*k + k*i <= n: li[i**2 + j**2 + k**2 + i*j + j*k + k*i -1] += 1 for i in range(n): print(li[i])
s040420628
p03997
u483640741
2,000
262,144
Wrong Answer
17
2,940
64
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h*1/2)
s095323845
Accepted
17
2,940
88
a=int(input()) b=int(input()) h=int(input()) answer=(a+b)*h*1/2 print(round(answer))
s250402186
p03400
u220345792
2,000
262,144
Wrong Answer
17
2,940
138
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
n = int(input()) D, X = map(int, input().split()) cnt = 0 D = D -1 for i in range(n): tmp = int(input()) cnt += D//tmp print(X+cnt)
s900360221
Accepted
17
2,940
142
n = int(input()) D, X = map(int, input().split()) cnt = 0 D = D -1 for i in range(n): tmp = int(input()) cnt += D//tmp print(X+cnt+n)
s586255364
p03494
u840974625
2,000
262,144
Time Limit Exceeded
2,107
2,940
202
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) list = list(map(int, input().split())) b = 0 while True: for i in range(n): if(list[i] % 2 == 0): list[i] = list[i] / 2 else: break b += 1 print(b)
s859541603
Accepted
19
2,940
222
n = int(input()) list = list(map(int, input().split())) b = -1 cont = True while cont: b += 1 for i in range(n): if(list[i] % 2 == 0): list[i] = list[i] / 2 else: cont = False print(b)
s908528014
p03680
u668726177
2,000
262,144
Wrong Answer
194
7,084
162
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
n = int(input()) a = [int(input())-1 for _ in range(n)] now = 0 checked = set() for i in range(1, n+1): now = a[now] if now==1: print(i) else: print(-1)
s218792889
Accepted
187
7,084
172
n = int(input()) a = [int(input())-1 for _ in range(n)] now = 0 checked = set() for i in range(1, n+1): now = a[now] if now==1: print(i) break else: print(-1)
s154475030
p02612
u668503853
2,000
1,048,576
Wrong Answer
28
9,144
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) print(N%1000)
s845907557
Accepted
32
9,148
71
N=int(input()) if N%1000!=0: print(1000-N%1000) else: print(N%1000)
s340031347
p03067
u404057606
2,000
1,048,576
Wrong Answer
17
2,940
119
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
abc=list(map(int,input().split())) a=abc[0] b=abc[1] c=abc[2] if (b-c)*(a-c)<0: print("YES") else: print("NO")
s722039793
Accepted
17
2,940
103
h = list(map(int,input().split())) if (h[2]-h[1])*(h[2]-h[0])<0: print("Yes") else: print("No")
s241563283
p02842
u821712904
2,000
1,048,576
Wrong Answer
17
3,064
148
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n=int(input()) if 100*n/108//1==100*(n+1)/108//1: print(':(') elif 100*(n+1)/108%1!=0: print(100*(n+1)/108//1) else: print(100*(n+1)/108//1-1)
s288792138
Accepted
18
2,940
128
n=int(input()) for i in range(int(100*n/108//1),int(100*(n+1)/108//1)+1): if i*1.08//1==n: print(i) exit() print(':(')
s081872830
p00037
u150984829
1,000
131,072
Wrong Answer
20
5,612
389
上から見ると図 1 のような形の格子状の広場があります。この格子の各辺に「壁」があるかないかを 0 と 1 の並びで表します。点 A に立って壁に右手をつき、壁に右手をついたまま、矢印の方向に歩き続けて再び点 A に戻ってくるまでの経路を出力するプログラムを作成してください。 --- 図1 ---
g=[[0]*5 for _ in[0]*5] for i in range(9): e=input() for j in range(4+i%2): if int(e[j]): if i%2:g[i//2][j]+=4;g[i//2+1][j]+=1 else:r=g[i//2];r[j]+=2;r[j+1]+=8 y,x=0,1 k=1 a='1' while 1: k=k%4+3 for i in range(4): k=k+i if g[y][x]&int(2**(k%4)):a+=str(k%4);break if k%2:x+=[1,-1][(k%4)>1] else:y+=[-1,1][(k%4)>0] if x+y==0:break print(''.join('URDL'[int(c)]for c in a))
s997694967
Accepted
20
5,612
368
g=[[0]*5 for _ in[0]*5] for i in range(9): e=input() for j in range(4+i%2): if int(e[j]): if i%2:g[i//2][j]+=4;g[i//2+1][j]+=1 else:r=g[i//2];r[j]+=2;r[j+1]+=8 y,x=0,1 k=1 a=[1] while 1: k+=2 for _ in[0]*4: k+=1 if g[y][x]&int(2**(k%4)):a+=[k%4];break if k%2:x+=1-2*((k%4)>1) else:y+=2*((k%4)>0)-1 if x+y<1:break print(''.join('URDL'[c]for c in a))
s694408966
p03545
u994784668
2,000
262,144
Wrong Answer
17
3,060
230
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
import itertools num = str(input()) sign = ("+", "-") for s1, s2, s3 in itertools.product(sign, repeat=3): result = num[0] + s1 + num[1] + s2 + num[2] + s3 + num[3] if eval(result) == 7: print(result) break
s629892754
Accepted
17
3,060
235
import itertools num = str(input()) sign = ("+", "-") for s1, s2, s3 in itertools.product(sign, repeat=3): result = num[0] + s1 + num[1] + s2 + num[2] + s3 + num[3] if eval(result) == 7: print(result+"=7") break