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
s877184599
p03719
u093783313
2,000
262,144
Wrong Answer
18
3,060
218
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
# coding: utf-8 # Your code here! line = input().split() l = [int(s) for s in line] # print(l) a = 0 if -100 <= l[0] <= l[1] <= l[2]<=100: a = 1 if a == 1 : print("Yes") else: print("No")
s793493178
Accepted
17
2,940
139
line = input().split() l = [int(s) for s in line] if -100 <= l[0] <= l[2] <= l[1]<=100: print("Yes") else: print("No")
s776652261
p03679
u816919571
2,000
262,144
Wrong Answer
17
2,940
100
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b = map(int,input().split()) print("delicious" if b <= a else "safe" if a<b<=x else "dangerous")
s756944672
Accepted
17
2,940
102
x,a,b = map(int,input().split()) print("delicious" if b <= a else "safe" if a<b<=a+x else "dangerous")
s950083108
p03501
u498465804
2,000
262,144
Wrong Answer
17
2,940
65
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
a, b, c = map(int, input().split()) print(a*b if a*b >= c else c)
s382701043
Accepted
17
2,940
65
a, b, c = map(int, input().split()) print(a*b if a*b <= c else c)
s129141183
p03475
u887207211
3,000
262,144
Wrong Answer
79
3,064
280
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.
N = int(input()) CSF = [list(map(int,input().split())) for _ in range(N-1)] for i in range(N): t = 0 for j in range(i,N-1): if(t < CSF[j][1]): t = CSF[j][1] elif(t%CSF[j][2] == 0): pass else: t = CSF[j][2]-t%CSF[j][2] t += CSF[j][0] print(t)
s797466333
Accepted
107
3,188
283
N = int(input()) CSF = [list(map(int,input().split())) for _ in range(N-1)] for i in range(N): t = 0 for j in range(i,N-1): if(t < CSF[j][1]): t = CSF[j][1] elif(t%CSF[j][2] == 0): pass else: t += CSF[j][2]-t%CSF[j][2] t += CSF[j][0] print(t)
s411383758
p03729
u217303170
2,000
262,144
Wrong Answer
17
2,940
101
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = input().split() if a[-1] == b[0] and b[-1] == c[0]: print('Yes') else: print('No')
s522428112
Accepted
17
3,064
101
a, b, c = input().split() if a[-1] == b[0] and b[-1] == c[0]: print('YES') else: print('NO')
s336741666
p03110
u063550903
2,000
1,048,576
Wrong Answer
17
3,060
182
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()) T=[0]*N mysum=0 for i in range(N): T[i]=[float(i) for i in input().replace("JPY","1").replace("BTC","380000").split()] mysum+=T[i][0]*T[i][1] print(int(mysum))
s609932963
Accepted
18
3,060
177
N=int(input()) T=[0]*N mysum=0 for i in range(N): T[i]=[float(i) for i in input().replace("JPY","1").replace("BTC","380000").split()] mysum+=T[i][0]*T[i][1] print(mysum)
s882854856
p03555
u924308178
2,000
262,144
Wrong Answer
17
2,940
77
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a = input() b = input() if a==b[::-1]: print("Yes") else: print("No")
s380225706
Accepted
17
2,940
77
a = input() b = input() if a==b[::-1]: print("YES") else: print("NO")
s984865284
p03379
u353855427
2,000
262,144
Wrong Answer
303
25,620
174
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N = int(input()) X = list(map(int,input().split())) X_s = sorted(X) print(X) l1 = X_s[N//2 - 1] l2 = X_s[(N//2)+1 - 1] for i in X: if i <= l1: print(l2) else: print(l1)
s543551013
Accepted
281
25,620
165
N = int(input()) X = list(map(int,input().split())) X_s = sorted(X) l1 = X_s[N//2 - 1] l2 = X_s[(N//2)+1 - 1] for i in X: if i <= l1: print(l2) else: print(l1)
s486496077
p02612
u459023872
2,000
1,048,576
Wrong Answer
30
9,144
44
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()) payment=N%1000 print(payment)
s402419600
Accepted
34
9,092
85
N=int(input()) payment=N%1000 if payment==0: print("0") else: print(1000-payment)
s453616062
p03827
u256464928
2,000
262,144
Wrong Answer
17
3,060
149
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
n = int(input()) s = input() x = 0 X = [0] for i in range(n): if s[0]=="I": x+=1 X.append(x) else: x-=1 X.append(x) print(max(X))
s394541620
Accepted
17
3,060
149
n = int(input()) s = input() x = 0 X = [0] for i in range(n): if s[i]=="I": x+=1 X.append(x) else: x-=1 X.append(x) print(max(X))
s111968971
p03545
u612223903
2,000
262,144
Wrong Answer
17
3,064
558
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.
abcd = input() answers =[] for i in range(2**3): a = int(abcd[0]) b = int(abcd[1]) c = int(abcd[2]) d = int(abcd[3]) plus_minus = [1,1,1] for j in range(3): if (i >> j)& 1: plus_minus[j] = -1 ans = a + b*plus_minus[0] + c*plus_minus[1] + d*plus_minus[2] if ans == 7: pmw =[] for j in range(3): if plus_minus[j] == -1: pmw.append("-") else: pmw.append("+") print(str(a)+pmw[0]+str(b)+pmw[1]+str(c)+pmw[2]+str(d)) break
s130327356
Accepted
17
3,064
572
abcd = input() answers =[] for i in range(2**3): a = int(abcd[0]) b = int(abcd[1]) c = int(abcd[2]) d = int(abcd[3]) plus_minus = [1,1,1] for j in range(3): if (i >> j)& 1: plus_minus[j] = -1 ans = a + b*plus_minus[0] + c*plus_minus[1] + d*plus_minus[2] if ans == 7: pmw =[] for j in range(3): if plus_minus[j] == -1: pmw.append("-") else: pmw.append("+") print(str(a)+pmw[0]+str(b)+pmw[1]+str(c)+pmw[2]+str(d)+"=7") break
s090056973
p03524
u018984506
2,000
262,144
Wrong Answer
46
3,188
254
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
s=input() n=[0,0,0] for i in range(len(s)): if s[i] == "a": n[0]+=1 elif s[i] == "b": n[1]+=1 else: n[2]+=1 if abs(n[0]-n[1]) <= 1 and abs(n[1]-n[2]) <= 1 and abs(n[0]-n[2]) <= 1: print("Yes") else: print("No")
s512767487
Accepted
46
3,188
254
s=input() n=[0,0,0] for i in range(len(s)): if s[i] == "a": n[0]+=1 elif s[i] == "b": n[1]+=1 else: n[2]+=1 if abs(n[0]-n[1]) <= 1 and abs(n[1]-n[2]) <= 1 and abs(n[0]-n[2]) <= 1: print("YES") else: print("NO")
s441279613
p02975
u107639613
2,000
1,048,576
Wrong Answer
2,104
14,468
806
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
from collections import deque N = int(input()) A = deque(map(int, input().split())) first = A.popleft() def round(a): B = set(A) eval = 0 pre = first post = a B.discard(a) while len(B) != 0: c = pre ^ post if c in B: B.discard(c) pre = post post = c else: return 'No' eval = 1 break if post ^ first == a: return 'Yes' elif eval == 0: return 'No' for i in range(0, N - 1): ans = round(A[i]) if ans == 'Yes': print('Yes') if ans == 'No': print('No')
s770192395
Accepted
1,774
14,468
1,053
from collections import deque N = int(input()) A = deque(map(int, input().split())) first = A.popleft() def round(a): B = list(A) eval = 0 pre = first post = a B.remove(a) num = N - 2 while num != 0: c = pre ^ post try: B.remove(c) pre = post post = c num -= 1 except: return 0 eval = 1 break if eval == 0 and post ^ first == a: return 1 elif eval == 0: return 0 val = first for i in range(N - 1): val = val ^ A[i] if val != 0: print('No') else: ans = 0 for i in range(0, N - 1): ans = round(A[i]) if ans == 1: print('Yes') break if ans == 0: print('No')
s415774732
p03080
u035605655
2,000
1,048,576
Wrong Answer
17
2,940
213
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
# -*- coding: utf-8 -*- N = int(input()) s = input() rcount = 0 for c in s: if c == 'Red': rcount += 1 bcount = N - rcount if rcount > bcount: print('Yes') else: print('No')
s108835383
Accepted
18
2,940
211
# -*- coding: utf-8 -*- N = int(input()) s = input() rcount = 0 for c in s: if c == 'R': rcount += 1 bcount = N - rcount if rcount > bcount: print('Yes') else: print('No')
s196767262
p03697
u813371068
2,000
262,144
Wrong Answer
16
2,940
62
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
A,B=map(int,input().split()) print(A+B if A+B>10 else 'error')
s976421539
Accepted
17
2,940
76
A,B=map(int,input().split()) print(A+B if A+B<10 else 'error')
s518684804
p00005
u298999032
1,000
131,072
Wrong Answer
50
6,920
93
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
import fractions as f a,b=map(float,input().split()) print(f.gcd(a,b)) print(a*b//f.gcd(a,b))
s870913137
Accepted
20
5,596
220
import sys for i in sys.stdin: a,b=map(int,i.split()) if a<b:a,b=b,a def gcd(x,y): while y>0:x,y=y,x%y return x def lcm(x,y): return x*y/gcd(x,y) print(gcd(a,b),int(lcm(a,b)))
s414564077
p03131
u223904637
2,000
1,048,576
Wrong Answer
17
2,940
156
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
k,a,b=map(int,input().split()) if k+1<=a: print(k+1) exit() s=k+1-a if a>=b-1: print(k+1) else: n=s//2 m=s%2 print(n*(a-b)+m)
s267927248
Accepted
17
2,940
158
k,a,b=map(int,input().split()) if k+1<=a: print(k+1) exit() s=k+1-a if a>=b-1: print(k+1) else: n=s//2 m=s%2 print(a+n*(b-a)+m)
s794937666
p03593
u905582793
2,000
262,144
Wrong Answer
21
3,444
340
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter. Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition: * Every row and column in A' can be read as a palindrome. Determine whether he can create a matrix satisfying the condition.
from collections import Counter import sys h,w=map(int,input().split()) a=list(sys.stdin.read()) c=Counter(a) c["\n"]=0 n1=0 n2=0 if h*w%2: n1=1 if h%2: n2+=w//2 if w%2: n2+=h//2 n4=h//2+w//2 n1r,n2r,n4r=0,0,0 for i in c.values(): n1r += i%2 n2r += (i//2)%2 n4r += i//4 if n1==n1r and n4r>=n4: print("Yes") else: print("No")
s918268115
Accepted
22
3,444
344
from collections import Counter import sys h,w=map(int,input().split()) a=list(sys.stdin.read()) c=Counter(a) c["\n"]=0 n1=0 n2=0 if h*w%2: n1=1 if h%2: n2+=w//2 if w%2: n2+=h//2 n4=(h//2)*(w//2) n1r,n2r,n4r=0,0,0 for i in c.values(): n1r += i%2 n2r += (i//2)%2 n4r += i//4 if n1==n1r and n4r>=n4: print("Yes") else: print("No")
s630325117
p02416
u088337682
1,000
131,072
Wrong Answer
20
5,540
73
Write a program which reads an integer and prints sum of its digits.
while True: x = input() if x == "0":break print(len(str(x)))
s066261450
Accepted
20
5,588
83
while True: x = input() if x == "0":break print(sum(list(map(int,x))))
s416778069
p03448
u335281728
2,000
262,144
Wrong Answer
123
3,952
285
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): total = i*500+j*100+k*50 if total == x: count += 1 else: print('a') print(count)
s713028438
Accepted
53
3,060
256
a = int(input()) b = int(input()) c = int(input()) x = int(input()) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): total = i*500+j*100+k*50 if total == x: count += 1 print(count)
s724612343
p03455
u431981421
2,000
262,144
Wrong Answer
18
2,940
90
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')
s676739243
Accepted
17
2,940
88
a, b = map(int, input().split()) if a * b % 2 == 0: print('Even') else: print('Odd')
s598786941
p03997
u692711472
2,000
262,144
Wrong Answer
23
9,036
73
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) s = (a+b)*h/2 print(s)
s202383411
Accepted
28
9,152
78
a = int(input()) b = int(input()) h = int(input()) s = (a+b)*h/2 print(int(s))
s420582432
p03997
u992759582
2,000
262,144
Wrong Answer
17
2,940
69
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h /2)
s827414704
Accepted
17
2,940
74
a = int(input()) b = int(input()) h = int(input()) print(int((a+b)*h /2))
s848086711
p03862
u353638740
2,000
262,144
Wrong Answer
2,103
149,884
641
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
N, x = map(int,input().split()) a_list = list(map(int,input().split())) b_list = [a_list[i]+a_list[i+1] for i in range(0,N-1)] excess_list = [max(0,val -x) for val in b_list] ans = 0 for i in range(0,len(b_list)-1): a_val = a_list[i+1] b_prev = excess_list[i] b_next = excess_list[i+1] min_val = min(a_val,b_prev,b_next) print("prev a_list",a_list[i+1]) a_list[i+1] -= min_val print("after a_list",a_list[i+1]) excess_list[i] -= min_val excess_list[i+1] -= min_val print("i:",i,"min_val:",min_val) print("a_list:",a_list,"b_list:",b_list) ans += min_val ans += sum(excess_list) print(ans)
s228219701
Accepted
195
14,948
428
N, x = map(int,input().split()) a_list = list(map(int,input().split())) b_list = [a_list[i]+a_list[i+1] for i in range(0,N-1)] excess_list = [max(0,val -x) for val in b_list] ans = 0 for i in range(0,len(excess_list)-1): min_val = min(a_list[i+1],excess_list[i],excess_list[i+1]) a_list[i+1] -= min_val excess_list[i] -= min_val excess_list[i+1] -= min_val ans += min_val ans += sum(excess_list) print(ans)
s306488137
p02396
u029473859
1,000
131,072
Wrong Answer
20
7,400
20
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.
i = input() print(i)
s052245450
Accepted
120
7,344
129
k = 0 while True: i = input() k = k + 1 if i == "0": break else: print("Case {}: {}".format(k,i))
s952612595
p04043
u238605674
2,000
262,144
Wrong Answer
17
2,940
90
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.
I=input().split() if I[0]=="5" and I[1]=="7" and I[2]: print("YES") else: print("NO")
s349275143
Accepted
17
2,940
143
I=input().split() c5=0 c7=0 for i in I: if i=="5": c5+=1 elif i=="7": c7+=1 if c5==2 and c7==1: print("YES") else: print("NO")
s611829840
p03494
u522375638
2,000
262,144
Wrong Answer
19
3,060
177
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 = input() numbers = list(map(int, input().split())) cnt = 0 while sum([True if n%2==0 else False for n in numbers])>0: numbers = [n/2 for n in numbers] cnt += 1 print(cnt)
s916077209
Accepted
19
3,060
178
N = input() numbers = list(map(int, input().split())) cnt = 0 while sum([True if n%2==1 else False for n in numbers])==0: numbers = [n/2 for n in numbers] cnt += 1 print(cnt)
s172556310
p03472
u667024514
2,000
262,144
Wrong Answer
426
16,728
439
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
import math n, h = map(int,input().split()) thr = [] att = [] ans = 0 for i in range(n): a, b = map(int,input().split()) att.append(a) thr.append(b) thr.sort(reverse = True) att.sort(reverse = True) print(h,sum(thr)) for m in range(n): if h > 0: if thr[m] > att[0]: h = h -thr[m] ans = ans+1 else: h = h-att[0] ans = ans+1 if h > 0: turn = h/att[0] turn = math.ceil(turn) ans = ans+ turn print(att,thr,h) print(ans)
s871327493
Accepted
409
11,392
406
import math n, h = map(int,input().split()) thr = [] att = [] ans = 0 for i in range(n): a, b = map(int,input().split()) att.append(a) thr.append(b) thr.sort(reverse = True) att.sort(reverse = True) for m in range(n): if h > 0: if thr[m] > att[0]: h = h -thr[m] ans = ans+1 else: h = h-att[0] ans = ans+1 if h > 0: turn = h/att[0] turn = math.ceil(turn) ans = ans+ turn print(ans)
s134588893
p03557
u994988729
2,000
262,144
Wrong Answer
494
23,744
281
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
import bisect n=int(input()) a=sorted(list(map(int,input().split()))) b=list(map(int,input().split())) c=sorted(list(map(int,input().split()))) ans=0 for i in b: a_tmp=bisect.bisect_left(a,i) c_tmp=n-bisect.bisect(c,i) print(a_tmp,c_tmp) ans+=a_tmp*c_tmp print(ans)
s962247206
Accepted
266
26,476
350
import numpy as np N = int(input()) A = np.array(input().split(), dtype=int) B = np.array(input().split(), dtype=int) C = np.array(input().split(), dtype=int) A.sort() B.sort() C.sort() CB = np.searchsorted(B, C, side="left") BA = np.searchsorted(A, B, side="left") tmp = [0]+BA.cumsum().tolist() tmp = np.array(tmp) ans = tmp[CB].sum() print(ans)
s264883204
p03360
u604262137
2,000
262,144
Wrong Answer
21
3,316
215
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
A, B, C = list(map(int, input().split())) K = int(input()) seisuu_list = [A, B, C] seisuu_list.sort(reverse=True) seisuu_list[0] *= 1024*seisuu_list[0] sum = seisuu_list[0]+seisuu_list[1]+seisuu_list[2] print(sum)
s971676630
Accepted
17
3,060
219
A, B, C = list(map(int, input().split())) K = int(input()) seisuu_list = [A, B, C] seisuu_list.sort(reverse=True) for _ in range(K): seisuu_list[0] *= 2 sum = seisuu_list[0]+seisuu_list[1]+seisuu_list[2] print(sum)
s685840008
p03494
u607074939
2,000
262,144
Wrong Answer
20
3,060
250
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) a = list(map(int, input().split())) count = 0 flg = True while(flg): for i in range(n): if a[i]%2 != 0: flg = False break else: a[i] = a[i]/2 count += 1 print(count)
s365537318
Accepted
19
3,060
256
n = int(input()) a = list(map(int, input().split())) count = 0 flg = True while(flg): for i in range(n): if a[i]%2 != 0: flg = False break else: a[i] = a[i]/2 else: count += 1 print(count)
s943170858
p02277
u643021750
1,000
131,072
Wrong Answer
20
5,624
1,742
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also 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 merge(A, n, left, mid, right): n1 = mid - left n2 = right - mid for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = new_list("X", SENTINEL) R[n2] = new_list("X", SENTINEL) i = 0 j = 0 for k in range(left, right): if L[i].value <= R[j].value: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, n, left, right): if left+1 < right: mid = (left+right)//2 mergeSort(A, n, left, mid) mergeSort(A, n, mid, right) merge(A, n, left, mid, right) def partition(p, r): x = A[r].value i = p - 1 for j in range(p, r): if A[j].value <= x: i += 1 A_tmp = A[i] A[i] = A[j] A[j] = A_tmp t = A[i+1] A[i+1] = A[r] A[r] = t return i+1 def quickSort(A, n, p, r): if p < r: q = partition(p, r) quickSort(A, n, p, q-1) quickSort(A, n, q+1, r) class new_list: def __init__(self, a1, a2): self.suit = a1 self.value = a2 n = int(input()) S_tmp = [input().split() for i in range(n)] for i in range(n): print(S_tmp[i]) A = [] B = [] for i in range(n): A.append(new_list(S_tmp[i][0], int(S_tmp[i][1]))) B.append(new_list(S_tmp[i][0], int(S_tmp[i][1]))) # print(i, A[i].suit, A[i].value) L = [''] * (n//2+2) R = [''] * (n//2+2) SENTINEL = 2000000000 mergeSort(A, n, 0, n) quickSort(B, n, 0, n-1) for i in range(n): if A[i].suit != B[i].suit: break if i == n-1: print("Stable") else: print("Not Stable") for i in range(n): print(A[i].suit, A[i].value)
s722490088
Accepted
2,530
70,384
1,746
def merge(A, n, left, mid, right): n1 = mid - left n2 = right - mid for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = new_list("X", SENTINEL) R[n2] = new_list("X", SENTINEL) i = 0 j = 0 for k in range(left, right): if L[i].value <= R[j].value: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, n, left, right): if left+1 < right: mid = (left+right)//2 mergeSort(A, n, left, mid) mergeSort(A, n, mid, right) merge(A, n, left, mid, right) def partition(p, r): x = B[r].value i = p - 1 for j in range(p, r): if B[j].value <= x: i += 1 B_tmp = B[i] B[i] = B[j] B[j] = B_tmp t = B[i+1] B[i+1] = B[r] B[r] = t return i+1 def quickSort(B, n, p, r): if p < r: q = partition(p, r) quickSort(B, n, p, q-1) quickSort(B, n, q+1, r) class new_list: def __init__(self, a1, a2): self.suit = a1 self.value = a2 n = int(input()) S_tmp = [input().split() for i in range(n)] # print(S_tmp[i]) A = [] B = [] for i in range(n): A.append(new_list(S_tmp[i][0], int(S_tmp[i][1]))) B.append(new_list(S_tmp[i][0], int(S_tmp[i][1]))) # print(i, A[i].suit, A[i].value) L = [''] * (n//2+2) R = [''] * (n//2+2) SENTINEL = 2000000000 mergeSort(A, n, 0, n) quickSort(B, n, 0, n-1) for i in range(n): if A[i].suit != B[i].suit: break if i == n-1: print("Stable") else: print("Not stable") for i in range(n): print(B[i].suit, B[i].value)
s416078417
p03826
u843318346
2,000
262,144
Wrong Answer
17
2,940
54
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
a,b,c,d = map(int,input().split()) print(max(a*b,d*d))
s068119667
Accepted
17
2,940
55
a,b,c,d = map(int,input().split()) print(max(a*b,c*d))
s906073700
p03997
u586577600
2,000
262,144
Wrong Answer
17
2,940
67
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s933719547
Accepted
17
2,940
68
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s249466910
p03997
u557523358
2,000
262,144
Wrong Answer
23
3,188
50
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,b,h=(int(input())for _ in[0]*3);print((a+b)*h/2)
s867202484
Accepted
24
3,064
51
a,b,h=(int(input())for _ in[0]*3);print((a+b)*h//2)
s070353889
p03486
u598229387
2,000
262,144
Wrong Answer
17
2,940
124
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() t = input() ss = ''.join(sorted(s)) tt = ''.join(sorted(t)) if ss < tt: print('Yes') else: print('No')
s442902018
Accepted
17
2,940
104
s = input() t = input() print('Yes' if ''.join(sorted(s)) < ''.join(sorted(t,reverse=True)) else 'No')
s638218836
p03400
u614459338
2,000
262,144
Wrong Answer
17
3,064
190
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
N = int(input()) D,X = map(int,input().split()) A = [0]*N for i in range(N): A[i] = int(input()) cnt = 0 for i in range(N): print((D-1)//A[i]+1) cnt += (D-1)//A[i]+1 print(X+cnt)
s470342317
Accepted
18
3,060
165
N = int(input()) D,X = map(int,input().split()) A = [0]*N for i in range(N): A[i] = int(input()) cnt = 0 for i in range(N): cnt += (D-1)//A[i]+1 print(X+cnt)
s992580251
p03997
u703890795
2,000
262,144
Wrong Answer
17
2,940
62
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s549655807
Accepted
17
2,940
63
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
s684885258
p02600
u426108351
2,000
1,048,576
Wrong Answer
30
9,136
22
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
print(10-int(input()))
s169284374
Accepted
33
9,044
28
print(10-int(input())//200)
s884327333
p04011
u980503157
2,000
262,144
Wrong Answer
30
9,164
156
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.
num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = int(input()) if num1>num2: print(num1*num3+(num2-num1)*num4) else: print(num1*num3)
s051600301
Accepted
28
9,192
156
num1 = int(input()) num2 = int(input()) num3 = int(input()) num4 = int(input()) if num1>num2: print(num2*num3+(num1-num2)*num4) else: print(num1*num3)
s454107327
p03193
u814986259
2,000
1,048,576
Wrong Answer
32
9,144
129
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
N,H,W=map(int,input().split()) ans=0 for i in range(N): x,y=map(int,input().split()) if x<=H and y <=W: ans+=1 print(ans)
s210097464
Accepted
29
9,100
129
N,H,W=map(int,input().split()) ans=0 for i in range(N): x,y=map(int,input().split()) if x>=H and y>=W: ans+=1 print(ans)
s019545849
p03593
u375616706
2,000
262,144
Wrong Answer
22
3,436
852
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the top and j-th column from the left. In this matrix, each a_{ij} is a lowercase English letter. Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A. Here, he wants to satisfy the following condition: * Every row and column in A' can be read as a palindrome. Determine whether he can create a matrix satisfying the condition.
from collections import Counter H, W = map(int, input().split()) D = [] for _ in range(H): D.extend(list([v for v in input()])) C = Counter(D) L = list([v for i, v in C.most_common()]) print(C) if H == 1 and W == 1: ans = "Yes" elif H == 1 or W == 1: if sum([1 if v % 2 == 1 else 0 for v in L]) == 1: ans = "Yes" else: ans = "No" elif H % 2 == 1 and W % 2 == 1: if sum(v % 2 for v in L) == 1 and (sum(1 if v % 4 == 0 else 0 for v in L) == len(L)-1 or (sum(1 if v % 4 == 0 else 0 for v in L)) == len(L)-2): ans = "Yes" else: ans = "No" elif H % 2 == 0 and W % 2 == 0: ans = "Un" else: if sum(v % 2 for v in L) == 0 and (sum(1 if v % 4 == 0 else 0 for v in L) == len(L)-1 or (sum(1 if v % 4 == 0 else 0 for v in L)) == len(L)-2): ans = "Yes" else: ans = "No" print(ans)
s805653776
Accepted
21
3,436
340
from collections import Counter H, W = map(int, input().split()) D = [] for _ in range(H): D.extend(list([v for v in input()])) C = Counter(D) L = list([v for i, v in C.most_common()]) g1 = sum(v % 2 for v in L) g4 = sum(v//4 for v in L) if g4 >= (W-(W % 2))*(H-(H % 2))//4 and g1 == H & 1 & W: print("Yes") else: print("No")
s132617944
p03997
u733337827
2,000
262,144
Wrong Answer
18
3,060
260
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().strip() Sb = input().strip() Sc = input().strip() l = [len(Sa), len(Sb), len(Sc)] s = [Sa, Sb, Sc] p = 0 while True: l[p] -= 1 if l[p] <= 0: print("ABC"[p]) break else: p = "abc".find(s[p][l[p] - len(s[p]) + 1])
s208736166
Accepted
18
2,940
79
a = int(input()) b = int(input()) h = int(input()) print(int((a + b) * h >> 1))
s447561546
p03779
u227082700
2,000
262,144
Wrong Answer
17
2,940
58
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
x,t=int(input()),0 while round(t*(t+1)/2)>=x:t+=1 print(t)
s612049538
Accepted
28
2,940
75
x=int(input()) for t in range(1,10**10): if t*(t+1)//2>=x:print(t);exit()
s114268466
p02612
u267933821
2,000
1,048,576
Wrong Answer
33
9,096
43
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()) change=n%1000 print(change)
s186058643
Accepted
26
9,076
83
n=int(input()) change=1000-n%1000 if change==1000: print(0) else: print(change)
s003404523
p00604
u078042885
1,000
131,072
Wrong Answer
20
7,728
95
Peter loves any kinds of cheating. A week before ICPC, he broke into Doctor's PC and sneaked a look at all the problems that would be given in ICPC. He solved the problems, printed programs out, and brought into ICPC. Since electronic preparation is strictly prohibited, he had to type these programs again during the contest. Although he believes that he can solve every problems thanks to carefully debugged programs, he still has to find an optimal strategy to make certain of his victory. Teams are ranked by following rules. 1. Team that solved more problems is ranked higher. 2. In case of tie (solved same number of problems), team that received less Penalty is ranked higher. Here, Penalty is calculated by these rules. 1. When the team solves a problem, time that the team spent to solve it (i.e. (time of submission) - (time of beginning of the contest)) are added to penalty. 2. For each submittion that doesn't solve a problem, 20 minutes of Penalty are added. However, if the problem wasn't solved eventually, Penalty for it is not added. You must find that order of solving will affect result of contest. For example, there are three problem named A, B, and C, which takes 10 minutes, 20 minutes, and 30 minutes to solve, respectively. If you solve A, B, and C in this order, Penalty will be 10 + 30 + 60 = 100 minutes. However, If you do in reverse order, 30 + 50 + 60 = 140 minutes of Penalty will be given. Peter can easily estimate time to need to solve each problem (actually it depends only on length of his program.) You, Peter's teammate, are asked to calculate minimal possible Penalty when he solve all the problems.
n=int(input()) print(sum((n-i)*x for i,x in enumerate(sorted(list(map(int,input().split()))))))
s451716683
Accepted
30
7,736
133
while 1: try:n=int(input()) except:break print(sum((n-i)*x for i,x in enumerate(sorted(list(map(int,input().split()))))))
s926560919
p02972
u122994151
2,000
1,048,576
Wrong Answer
2,105
22,652
541
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
import fractions def add(n): return n + 1 def lcm(a): print(a) ans = a[0] for i in range(1, len(a)): ans = ans * a[i] // fractions.gcd(ans, a[i]) return ans if __name__ == "__main__": n = int(input()) buf = input().split() a = [int(s) for s in buf] indexes = [i for i, x in enumerate(a) if x == 1] indexes = list(map(add, indexes)) if indexes: num = lcm(indexes) if num > n: print("-1") else: print(num) else: print("0")
s644065954
Accepted
274
23,332
663
def add(n): return n + 1 if __name__ == "__main__": n = int(input()) buf = input().split() a = [int(s) for s in buf] boxes = [0] * n for i in reversed(range(n)): pick_boxes = boxes[i::i+1] pick_boxes.pop(0) if pick_boxes: if (sum(pick_boxes) % 2) == a[i]: boxes[i] = 0 else: boxes[i] = 1 else: boxes[i] = a[i] box_name = [i for i, x in enumerate(boxes) if x == 1] box_name = list(map(add, box_name)) print(len(box_name)) if len(box_name) != 0: box_name = ' '.join(map(str,box_name)) print(box_name)
s611391245
p03997
u328090531
2,000
262,144
Wrong Answer
17
2,940
75
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h / 2)
s420420388
Accepted
17
2,940
82
a = int(input()) b = int(input()) h = int(input()) print(round((a + b) * h / 2))
s375631974
p03163
u554698951
2,000
1,048,576
Wrong Answer
139
29,128
199
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.
N, W = map(int, input().split()) import numpy as np dp = np.zeros(W, dtype=int) for i in range(N): w, v = map(int, input().split()) np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print(dp.max())
s000068330
Accepted
137
28,540
205
N, W = map(int, input().split()) import numpy as np dp = np.zeros(W + 1, dtype=int) for i in range(N): w, v = map(int, input().split()) np.maximum(dp[:-w] + v, dp[w:], out=dp[w:]) print(dp[-1])
s736756573
p03380
u373047809
2,000
262,144
Wrong Answer
2,104
17,132
172
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
import math f = math.factorial _, *a = map(int, open(0).read().split()) a.sort() n = a.pop(-1) r = sorted((abs(n/2 - i), i) for i in a)[0][1] print(f(n) // (f(n-r) * f(r)))
s970540703
Accepted
69
14,028
98
_, *a = map(int, open(0).read().split()) n = max(a) print(n, min((abs(n/2 - i), i) for i in a)[1])
s522032693
p02646
u638231966
2,000
1,048,576
Wrong Answer
22
9,176
172
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if(V > W): print("NO") elif(abs(A-B)>T*(W-V)): print("NO") else: print("YES")
s253956562
Accepted
24
9,184
170
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if(V<W): print("NO") elif(abs(A-B)>T*(V-W)): print("NO") else: print("YES")
s341915303
p03495
u746849814
2,000
262,144
Wrong Answer
101
32,564
146
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
from collections import Counter n, k = map(int, input().split()) c = Counter(list(map(int, input().split()))) print(sum(sorted(c.values())[k:]))
s177756661
Accepted
99
32,540
160
from collections import Counter n, k = map(int, input().split()) c = Counter(list(map(int, input().split()))) print(sum(sorted(c.values(), reverse=True)[k:]))
s444450699
p03574
u468431843
2,000
262,144
Wrong Answer
23
3,188
1,265
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.
# -*- coding: utf-8 -*- # h, w = map(int, input().split()) s_list = [list(input()) for _ in range(h)] ans_list = [[0] * w for _ in range(h)] print(s_list) print(ans_list) for i in range(h): for j in range(w): if s_list[i][j] == "#": ans_list[i][j] = "#" else: if (i!=0) and (j!=0): if (s_list[i-1][j-1] == "#"): ans_list[i][j] += 1 if (i!=0): if (s_list[i-1][j] == "#"): ans_list[i][j] += 1 if (i!=0) and (j!=w-1): if (s_list[i-1][j+1] == "#"): ans_list[i][j] += 1 if (j!=0): if (s_list[i][j-1] == "#"): ans_list[i][j] += 1 if (j!=w-1): if (s_list[i][j+1] == "#"): ans_list[i][j] += 1 if (i!=h-1) and (j!=0): if (s_list[i+1][j-1] == "#"): ans_list[i][j] += 1 if (i!=h-1): if (s_list[i+1][j] == "#"): ans_list[i][j] += 1 if (i!=h-1) and (j!=w-1): if (s_list[i+1][j+1] == "#"): ans_list[i][j] += 1 for i in ans_list: print(''.join(map(str, i)))
s886565853
Accepted
24
3,188
1,235
# -*- coding: utf-8 -*- # h, w = map(int, input().split()) s_list = [list(input()) for _ in range(h)] ans_list = [[0] * w for _ in range(h)] for i in range(h): for j in range(w): if s_list[i][j] == "#": ans_list[i][j] = "#" else: if (i!=0) and (j!=0): if (s_list[i-1][j-1] == "#"): ans_list[i][j] += 1 if (i!=0): if (s_list[i-1][j] == "#"): ans_list[i][j] += 1 if (i!=0) and (j!=w-1): if (s_list[i-1][j+1] == "#"): ans_list[i][j] += 1 if (j!=0): if (s_list[i][j-1] == "#"): ans_list[i][j] += 1 if (j!=w-1): if (s_list[i][j+1] == "#"): ans_list[i][j] += 1 if (i!=h-1) and (j!=0): if (s_list[i+1][j-1] == "#"): ans_list[i][j] += 1 if (i!=h-1): if (s_list[i+1][j] == "#"): ans_list[i][j] += 1 if (i!=h-1) and (j!=w-1): if (s_list[i+1][j+1] == "#"): ans_list[i][j] += 1 for i in ans_list: print(''.join(map(str, i)))
s618064617
p03370
u045408189
2,000
262,144
Wrong Answer
712
2,940
118
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
a,b=map(int,input().split()) ans=0 for i in range(a+1): for t in range(b+1): if i==t: ans=ans+1 print(ans)
s741105731
Accepted
18
2,940
103
n,x=map(int,input().split()) m=[int(input()) for i in range(n)] a=x-sum(m) b=a//min(m) print(len(m)+b)
s614872487
p04029
u728611988
2,000
262,144
Wrong Answer
17
2,940
62
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) s = 0 for i in range(n): s = s+i print(s)
s337115257
Accepted
17
2,940
64
n = int(input()) s = 0 for i in range(n+1): s = s+i print(s)
s487594100
p02396
u067975558
1,000
131,072
Wrong Answer
270
7,156
225
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.
c = 1 a = [] while True: x = int(input()) a = a + [x] if x == 0: break; for i in a: print('Case {0}: {1}'.format(c,i)) c += 1
s846712280
Accepted
260
6,968
239
c = 1 a = [] while True: x = int(input()) if x == 0: break; else: a = a + [x] for i in a: print('Case {0}: {1}'.format(c,i)) c += 1
s132127666
p02612
u845847173
2,000
1,048,576
Wrong Answer
34
9,144
54
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) x = N // 1000 x = 2 * x print(x - N)
s984790609
Accepted
28
9,156
110
N = int(input()) if N%1000 == 0: print(0) else: x = N // 1000 x = (x + 1) * 1000 print(x - N)
s023357285
p03658
u802963389
2,000
262,144
Wrong Answer
17
2,940
121
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n, k = map(int, input().split()) L = list(map(int, input().split())) L.sort(reverse=True) ans = sum(L[:k + 1]) print(ans)
s829596076
Accepted
17
2,940
118
n, k = map(int, input().split()) L = list(map(int, input().split())) L.sort(reverse=True) ans = sum(L[:k]) print(ans)
s887602143
p03478
u309120194
2,000
262,144
Wrong Answer
42
9,176
157
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 n in range(1, N+1): s = sum(list(map(int, list(str(n))))) if A <= s and s <= B: ans += 1 print(ans)
s554327472
Accepted
35
9,176
230
N, A, B = map(int, input().split()) ans = 0 for n in range(1, N+1): s = 0 m = n while m > 0: s += m % 10 m = m // 10 if A <= s and s <= B: ans += n print(ans)
s553304010
p03998
u663014688
2,000
262,144
Wrong Answer
17
3,064
535
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
A = list(input()) B = list(input()) C = list(input()) turn = "a" while True: if turn == "a": if len(A): turn = A[0] A.pop(0) else: break elif turn == "b": if len(B): turn = B[0] B.pop(0) else: break else: if len(C): turn = C[0] C.pop(0) else: break if turn == "A": print("A") elif turn == "B": print("B") else: print("C")
s649077835
Accepted
17
3,064
535
A = list(input()) B = list(input()) C = list(input()) turn = "a" while True: if turn == "a": if len(A): turn = A[0] A.pop(0) else: break elif turn == "b": if len(B): turn = B[0] B.pop(0) else: break else: if len(C): turn = C[0] C.pop(0) else: break if turn == "a": print("A") elif turn == "b": print("B") else: print("C")
s791552756
p03623
u765401716
2,000
262,144
Wrong Answer
17
2,940
239
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|.
S = list(input()) S.sort() S = set(S) alphabet = list("abcdefghijklmnopqrstuvwxyz") for i in alphabet: if i in S: if i == "z": print("None") else: pass elif i not in S: print(i) break
s181292917
Accepted
17
3,064
103
x,a,b = list(map(int, input().split())) if abs(x - a) > abs(x - b): print("B") else: print("A")
s878507216
p03503
u859897687
2,000
262,144
Wrong Answer
276
3,064
428
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=[list(map(int,input().split())) for i in range(n)] p=[list(map(int,input().split())) for i in range(n)] ans=-10**9 for i in range(1,2**10): a=0 m=[i%2,i//2%2,i//4%2,i//8%2,i//16%2,i//32%2,i//64%2,i//128%2,i//256%2,i//512%2] mm=[0 for i in range(n)] for i in range(10): for j in range(n): if m[i]==f[j][i]: mm[j]+=1 for i in range(n): a+=p[i][mm[i]] ans=max(ans,a) print(ans)
s649456917
Accepted
204
3,064
437
n=int(input()) f=[list(map(int,input().split())) for i in range(n)] p=[list(map(int,input().split())) for i in range(n)] ans=-10**9 for i in range(1,2**10): a=0 m=[i%2,i//2%2,i//4%2,i//8%2,i//16%2,i//32%2,i//64%2,i//128%2,i//256%2,i//512%2] mm=[0 for i in range(n)] for i in range(10): for j in range(n): if m[i]==1 and f[j][i]==1: mm[j]+=1 for i in range(n): a+=p[i][mm[i]] ans=max(ans,a) print(ans)
s278746591
p03545
u788068140
2,000
262,144
Wrong Answer
18
3,064
392
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.
S = [int(s) for s in input()] res = [] for i in range(2**4): s = S[0] c = [] for j in range(3): m = i >> j & 1 if m == 0: s = s + S[j+1]* -1 c.append("-") else: s = s + S[j+1] c.append("+") if s == 7: print(str(S[0])+""+c[0]+""+str(S[1])+""+c[1]+""+str(S[2])+""+c[2]+str(S[3])) break
s726719096
Accepted
17
3,064
397
S = [int(s) for s in input()] res = [] for i in range(2**4): s = S[0] c = [] for j in range(3): m = i >> j & 1 if m == 0: s = s + S[j+1]* -1 c.append("-") else: s = s + S[j+1] c.append("+") if s == 7: print(str(S[0])+""+c[0]+""+str(S[1])+""+c[1]+""+str(S[2])+""+c[2]+str(S[3])+"=7") break
s840090241
p03472
u152566588
2,000
262,144
Wrong Answer
298
11,020
573
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
def main(): N, H = map(int, input().split()) A = [] B = [] throwTotal = 0 throwCount = 0 count = 0 for _ in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) swing = max(A) for i in range(N): if B[i] > swing: throwTotal += B[i] throwCount += 1 if H - throwTotal >= 0: life = H - throwTotal swingCount = life // swing else: swingCount = 0 count = swingCount + throwCount print(count) if __name__ == "__main__": main()
s285509917
Accepted
313
11,296
502
def main(): N, H = map(int, input().split()) A = [] B = [] count = 0 for _ in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) B.sort(reverse=True) swing = max(A) for i in range(N): if B[i] > swing: H -= B[i] count += 1 if H <= 0: print(count) exit() swingCount = -(-H // swing) count += swingCount print(count) if __name__ == "__main__": main()
s232345940
p02795
u893270619
2,000
1,048,576
Wrong Answer
17
2,940
99
We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations.
H = int(input()) W = int(input()) N = int(input()) if H > W: print(N // H) else: print(N // W)
s146774875
Accepted
18
3,060
114
import math H = int(input()) W = int(input()) N = int(input()) Big = W if W > H else H print(math.ceil(N / Big))
s177741164
p03110
u103902792
2,000
1,048,576
Wrong Answer
18
2,940
167
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()) amount = 0 for i in range(n): x,c = input().split() if c == 'JPY': amount += int(x) else : amount += int(float(x)* 380000) print(amount)
s452904389
Accepted
17
2,940
163
n = int(input()) amount = 0 for i in range(n): x,c = input().split() if c == 'JPY': amount += int(x) else : amount += float(x)* 380000 print(amount)
s585184841
p02927
u199356004
2,000
1,048,576
Wrong Answer
24
2,940
227
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
M,D=[int(i) for i in input().split()] if D<10: print(0) else : count = 0 for i in range(1,M+1): for id in list(range(10, D+1)): if ( int(str(id)[0]))*int((str(id))[1]) == i : count += 1 print(count)
s425525135
Accepted
26
3,060
254
M,D=[int(i) for i in input().split()] if D<20: print(0) else : count = 0 for i in range(1,M+1): for id in list(range(20, D+1)): if int((str(id))[1]) >= 2 and ( int(str(id)[0]))*int((str(id))[1]) == i : count += 1 print(count)
s371744410
p02742
u941645670
2,000
1,048,576
Wrong Answer
17
3,064
399
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
a,b=map(int, input().split()) if a%2 == 0: if b%2 == 0: print(int((a*b)/2)) elif a > b: print(int((-(-a//2)*b) /2)) else: print(int((-(-b//2)*a) /2)) elif b%2 == 0: if a > b: print(int((-(-a//2)*b) /2)) else: print(int((-(-b//2)*a) /2)) else: if a > b: print(int((-(-a//2)*b) /2)) else: print(int((-(-b//2)*a) /2))
s311525215
Accepted
18
3,064
294
a,b=map(int, input().split()) if a ==1 or b == 1: print(1) exit() if a%2 != 0: if b%2 != 0: if a > b: print(int((-(-a//2))+(a*(b-1)/2))) else: print(int((-(-a//2))+(a*(b-1)/2))) else: print(int(a*b/2)) else: print(int(a*b/2))
s582782516
p03598
u858136677
2,000
262,144
Wrong Answer
17
2,940
168
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
N = int(input()) K = int(input()) x = list(map(int,input().split())) L = 0 for i in range(N): if K - x[i] <= x[i]: L = L + x[i] else: L = K -x[i] print (L)
s608691852
Accepted
17
3,060
169
N = int(input()) K = int(input()) x = list(map(int,input().split())) L = 0 for i in range(N): if K - x[i] >= x[i]: L += x[i] else: L += K -x[i] print (2 * L)
s924534886
p02344
u408284582
3,000
262,144
Wrong Answer
20
5,616
1,128
There is a sequence $A = a_0, a_1, ..., a_{n-1}$. You are given the following information and questions. * relate$(x, y, z)$: $a_y$ is greater than $a_x$ by $z$ * diff$(x, y)$: report the difference between $a_x$ and $a_y$ $(a_y - a_x)$
def union(x, y, t): x, t_x = findSet(x) y, t_y = findSet(y) link(x, t_x, y, t_y, t) def link(x, d_x, y, d_y, t): print('', 'x', 'y') print('', x, y) print('', d_x, d_y, t) if r[x] > r[y]: p[y] = x d[y] = d_x + d_y - t print('', y, '->', p[y], '=', d[y], '\n') else: p[x] = y d[x] = d_y - d_x + t if r[x] == r[y]: r[y] = r[y] + 1 print('', x, '->', p[x], '=', d[x], '\n') def findSet(x): if x != p[x]: p[x], t = findSet(p[x]) d[x] += t return p[x], d[x] def diff(x, y): x, d_x = findSet(x) y, d_y = findSet(y) if x == y: return d_x - d_y else: return '?' if __name__ == '__main__': p, r, d = [], [], [] n_set, n_quare = map(int, input().split()) for i in range(n_set): p.append(i) r.append(0) d.append(0) for i in range(n_quare): l = input().split() if len(l) == 4: _, x, y, t = map(int, l) union(x, y, t) else: _, x, y = map(int, l) print(diff(x, y))
s432092086
Accepted
1,860
11,400
1,133
def union(x, y, t): x, t_x = findSet(x) y, t_y = findSet(y) link(x, t_x, y, t_y, t) def link(x, d_x, y, d_y, t): #print('', 'x', 'y') #print('', x, y) #print('', d_x, d_y, t) if r[x] > r[y]: p[y] = x d[y] = d_x - d_y - t #print('', y, '->', p[y], '=', d[y], '\n') else: p[x] = y d[x] = d_y - d_x + t if r[x] == r[y]: r[y] = r[y] + 1 #print('', x, '->', p[x], '=', d[x], '\n') def findSet(x): if x != p[x]: p[x], t = findSet(p[x]) d[x] += t return p[x], d[x] def diff(x, y): x, d_x = findSet(x) y, d_y = findSet(y) if x == y: return d_x - d_y else: return '?' if __name__ == '__main__': p, r, d = [], [], [] n_set, n_quare = map(int, input().split()) for i in range(n_set): p.append(i) r.append(0) d.append(0) for i in range(n_quare): l = input().split() if len(l) == 4: _, x, y, t = map(int, l) union(x, y, t) else: _, x, y = map(int, l) print(diff(x, y))
s349419967
p03919
u785220618
2,000
262,144
Wrong Answer
17
3,060
187
There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`.
h, w = map(int, input().split()) S = [input().split() for _ in range(h)] for i in range(h): for j in range(w): if S[i][j] == 'snuke': print(chr(i+65) + str(j+1))
s220608812
Accepted
17
3,060
187
h, w = map(int, input().split()) S = [input().split() for _ in range(h)] for i in range(h): for j in range(w): if S[i][j] == 'snuke': print(chr(j+65) + str(i+1))
s989211766
p03416
u710952331
2,000
262,144
Wrong Answer
84
2,940
138
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()) cc = 0 for i in range(A, B+1): x = list(str(i)) if x[0]==x[4] and x[1]==x[2]: cc += 1 print(cc)
s704539741
Accepted
74
3,060
141
A, B = map(int, input().split()) cc = 0 for i in range(A,B+1): x = list(str(i)) if x[0]==x[4] and x[1]==x[3]: cc += 1 print(cc)
s952539379
p02743
u143051858
2,000
1,048,576
Wrong Answer
20
2,940
133
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
import math a,b,c=(int(x) for x in input().split()) if math.sqrt(a) + math.sqrt(b) < math.sqrt(c): print('YES') else: print('NO')
s718475133
Accepted
33
9,936
156
from decimal import * a,b,c = map(Decimal,input().split()) if a**Decimal(0.5) + b**Decimal(0.5) < c**Decimal(0.5): print('Yes') else: print('No')
s377124998
p02831
u750120744
2,000
1,048,576
Wrong Answer
17
2,940
80
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.
a, b = map(int, input().split()) while b: a, b = b, a%b print(a*b//a)
s688837858
Accepted
17
2,940
87
a, b = map(int, input().split()) x = a * b while b: a, b = b, a%b print(x//a)
s569939495
p03836
u634079249
2,000
262,144
Wrong Answer
19
3,064
933
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
import sys import os ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") sx, sy, tx, ty = il() ret = '' for n in range(tx - sx): ret += 'R' for n in range(ty - sy): ret += 'U' for n in range(tx - sx): ret += 'L' for n in range(ty - sy): ret += 'D' ret += 'L' for n in range(ty - sy + 1): ret += 'U' for n in range(tx - sx + 1): ret += 'R' ret += 'D' ret += 'R' for n in range(tx - sx): ret += 'D' for n in range(ty - sy): ret += 'L' ret += 'U' print(ret) if __name__ == '__main__': main()
s895017632
Accepted
42
10,732
1,693
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall from decimal import Decimal from collections import defaultdict, deque # import fractions sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) # lcm = lambda x, y: (x * y) // fractions.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def calcTwoPointDistance(x1, y1, x2, y2): return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") sx, sy, tx, ty = il() move = [] for _ in range(sy, ty): move.append('U') for _ in range(sx, tx): move.append('R') for _ in range(sy, ty): move.append('D') for _ in range(sx, tx): move.append('L') move.append('L') for _ in range(sy, ty + 1): move.append('U') for _ in range(sx, tx + 1): move.append('R') move.append('D') move.append('R') for _ in range(sy, ty + 1): move.append('D') for _ in range(sx, tx + 1): move.append('L') move.append('U') print(*move, sep='') if __name__ == '__main__': main()
s818494920
p03659
u578953945
2,000
262,144
Wrong Answer
2,240
1,841,440
102
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
import itertools n=int(input()) l=map(int,input().split()) print(list(itertools.combinations(l,n-1)))
s541721039
Accepted
197
23,800
230
import sys N=int(input()) A=list(map(int,input().split())) L=[0]*(N+1) ans=sys.maxsize for i in range(N): L[i+1]=L[i]+A[i] for i in range(1,N): x = L[i] y = L[-1] - L[i] if ans >= abs(x-y): ans = abs(x-y) print(ans)
s636251510
p03943
u131666536
2,000
262,144
Wrong Answer
18
2,940
145
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
# -*- coding: utf-8 -*- abc = [int(s) for s in input().split()] abc.sort() if abc[0]+abc[1] == abc[2]: print('yYs') else: print('No')
s327126787
Accepted
17
2,940
119
abc = [int(s) for s in input().split()] abc.sort() if abc[0]+abc[1] == abc[2]: print('Yes') else: print('No')
s522050710
p03545
u686390526
2,000
262,144
Wrong Answer
18
3,064
517
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
a=input() A=int(a[0]) B=int(a[1]) C=int(a[2]) D=int(a[3]) f=False if A+B+C+D==7: print("{}+{}+{}+{}".format(A,B,C,D)) elif A+B+C-D==7: print("{}+{}+{}-{}".format(A,B,C,D)) elif A+B-C+D==7: print("{}+{}-{}+{}".format(A,B,C,D)) elif A+B-C-D==7: print("{}+{}-{}-{}".format(A,B,C,D)) elif A-B+C+D==7: print("{}-{}+{}+{}".format(A,B,C,D)) elif A-B+C-D==7: print("{}-{}+{}-{}".format(A,B,C,D)) elif A-B-C+D==7: print("{}-{}-{}+{}".format(A,B,C,D)) elif A-B-C-D==7: print("{}-{}-{}-{}".format(A,B,C,D))
s846975622
Accepted
18
3,064
533
a=input() A=int(a[0]) B=int(a[1]) C=int(a[2]) D=int(a[3]) f=False if A+B+C+D==7: print("{}+{}+{}+{}=7".format(A,B,C,D)) elif A+B+C-D==7: print("{}+{}+{}-{}=7".format(A,B,C,D)) elif A+B-C+D==7: print("{}+{}-{}+{}=7".format(A,B,C,D)) elif A+B-C-D==7: print("{}+{}-{}-{}=7".format(A,B,C,D)) elif A-B+C+D==7: print("{}-{}+{}+{}=7".format(A,B,C,D)) elif A-B+C-D==7: print("{}-{}+{}-{}=7".format(A,B,C,D)) elif A-B-C+D==7: print("{}-{}-{}+{}=7".format(A,B,C,D)) elif A-B-C-D==7: print("{}-{}-{}-{}=7".format(A,B,C,D))
s425915041
p03555
u516242950
2,000
262,144
Wrong Answer
17
2,940
99
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.
one = list(input()) two = list(input()) if one == two.reverse(): print('YES') else: print('NO')
s805419257
Accepted
17
2,940
140
one = list(input()) two = list(input()) two.reverse() iti = "".join(one) ni = "".join(two) if iti == ni: print('YES') else: print('NO')
s892767014
p03377
u432453907
2,000
262,144
Wrong Answer
28
9,116
78
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()) ans="No" if A<=X<=A+B: ans="Yes" print(ans)
s399891229
Accepted
27
8,988
78
A,B,X=map(int,input().split()) ans="NO" if A<=X<=A+B: ans="YES" print(ans)
s753612010
p03352
u633548583
2,000
1,048,576
Wrong Answer
17
3,060
54
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
import math as m x=int(input()) print(m.floor(x**0.5))
s791200913
Accepted
22
2,940
135
x=int(input()) a=[] for i in range(1,100): for j in range(2,100): if i**j<=x: a.append(i**j) print(max(set(a)))
s404154624
p03473
u085530099
2,000
262,144
Wrong Answer
17
2,940
28
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
m = int(input()) print(24+m)
s012089642
Accepted
17
2,940
31
m = int(input()) print(24-m+24)
s891728822
p02694
u560464565
2,000
1,048,576
Wrong Answer
21
9,156
103
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x = int(input()) a = 100 cnt = 0 while x >= a: a = a * 1.01 a = int(a) cnt += 1 print(cnt)
s711845882
Accepted
24
9,156
102
x = int(input()) a = 100 cnt = 0 while x > a: a = a * 1.01 a = int(a) cnt += 1 print(cnt)
s076494409
p02534
u867200256
2,000
1,048,576
Wrong Answer
38
10,016
520
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
# coding: utf-8 # Your code here! import collections import sys import copy import re import math def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): K = I() ans = "" for i in range(K): ans+="ALC" print(ans) if __name__ == '__main__': main()
s760518913
Accepted
36
10,000
520
# coding: utf-8 # Your code here! import collections import sys import copy import re import math def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): K = I() ans = "" for _ in range(K): ans+="ACL" print(ans) if __name__ == '__main__': main()
s359801613
p03471
u084949493
2,000
262,144
Wrong Answer
1,717
3,064
356
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N, Y = map(int, input().split()) res10000 = -1 res5000 = -1 res1000 = -1 for ai in range(N+1): for bi in range(N+1): ci = N - ai - bi total = 10000*ai + 5000*bi + 1000*ci if total == Y: res10000 = ai res5000 = bi res1000 = ci break print(res10000) print(res5000) print(res1000)
s623758394
Accepted
920
3,064
379
N, Y = map(int, input().split()) res10000 = -1 res5000 = -1 res1000 = -1 for ai in range(N+1): for bi in range(0, N-ai+1): ci = N - ai - bi total = 10000*ai + 5000*bi + 1000*ci if total == Y: res10000 = ai res5000 = bi res1000 = ci break print(str(res10000) + " " + str(res5000) + " " + str(res1000))
s147943719
p03997
u052332717
2,000
262,144
Wrong Answer
17
2,940
99
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()) length = int(input()) area = ((a + b) * length) / 2 print(area)
s788519254
Accepted
18
2,940
69
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s772763834
p03829
u672475305
2,000
262,144
Wrong Answer
84
14,224
164
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one- dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i. You are now at town 1, and you want to visit all the other towns. You have two ways to travel: * Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction. * Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.
n,a,b = map(int,input().split()) X = list(map(int,input().split())) pos = X[0] ans = 0 for i in range(1, n): ans += min(b, X[i] - pos) pos = X[i] print(ans)
s823413426
Accepted
95
14,224
168
n,a,b = map(int,input().split()) X = list(map(int,input().split())) pos = X[0] ans = 0 for i in range(1, n): ans += min(b, (X[i] - pos)*a) pos = X[i] print(ans)
s530203126
p02420
u436634575
1,000
131,072
Wrong Answer
30
6,720
160
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
while True: s = input() if s == '-': break n = int(input()) for i in range(n): h = int(input()) s = s[-h:] + s[:-h] print(s)
s893056423
Accepted
30
6,724
158
while True: s = input() if s == '-': break n = int(input()) for i in range(n): h = int(input()) s = s[h:] + s[:h] print(s)
s321127878
p04030
u559126797
2,000
262,144
Wrong Answer
17
3,060
206
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s=input() answer="" for i in range(len(s)): if s[i]== '0': answer+="0" elif s[i]=='1': answer+="1" elif len(answer)>0: print("a") answer=answer[:-1] print(answer)
s297169550
Accepted
17
2,940
187
s=input() answer="" for i in range(len(s)): if s[i]== '0': answer+="0" elif s[i]=='1': answer+="1" elif len(answer)>0: answer=answer[:-1] print(answer)
s510565297
p02669
u984276646
2,000
1,048,576
Wrong Answer
414
9,200
524
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()) b, c, e = [1], [1], [1] pos = 0 while max(b) <= 10**18: b.append(2 * b[pos]) pos += 1 pos = 0 while max(c) <= 10**18: c.append(3 * c[pos]) pos += 1 pos = 0 while max(e) <= 10**18: e.append(5 * e[pos]) pos += 1 bn, cn, en = len(b), len(c), len(e) for _ in range(T): N, A, B, C, D = map(int, input().split()) cost = int(1e18) for i in range(bn): for j in range(cn): for k in range(en): x = b[i] * c[j] * e[k] cost = min(i*A+j*B+k*C+D+D*abs(N-x), cost) print(cost)
s491234633
Accepted
379
10,888
731
peak = int(1e18) A, B, C, D = 0, 0, 0, 0 memo = {} def PtW(n): if n == 0: return 0 if n == 1: return D if n in memo: return memo[n] m = peak if n * D < peak: m = n * D u2, d2 = n // 2 + (n % 2 != 0), n // 2 u3, d3 = n // 3 + (n % 3 != 0), n // 3 u5, d5 = n // 5 + (n % 5 != 0), n // 5 m = min(m, abs(u2*2-n)*D+A+PtW(u2)) m = min(m, abs(d2*2-n)*D+A+PtW(d2)) m = min(m, abs(u3*3-n)*D+B+PtW(u3)) m = min(m, abs(d3*3-n)*D+B+PtW(d3)) m = min(m, abs(u5*5-n)*D+C+PtW(u5)) m = min(m, abs(d5*5-n)*D+C+PtW(d5)) memo[n] = m return m T = int(input()) for _ in range(T): N, A, B, C, D = map(int, input().split()) memo = {} print(PtW(N))
s497967339
p03779
u169138653
2,000
262,144
Wrong Answer
2,104
2,940
114
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
x=int(input()) r=0 while 1: if x-r==r+1: print(r) exit() if x-r==r+2: print(r+2) exit() r+=1
s103454710
Accepted
17
2,940
95
x=int(input()) r=(-1+(1+8*x)**0.5)/2 if r.is_integer(): print(int(r)) else: print(int(r)+1)
s065351155
p04044
u357751375
2,000
262,144
Wrong Answer
17
3,060
109
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n,l = map(int,input().split()) s = [] for i in range(n): s.append(input()) sorted(s) print(''.join(s))
s345012979
Accepted
25
9,064
93
n,l = map(int,input().split()) s = list(input() for i in range(n)) s.sort() print(''.join(s))
s569486037
p03997
u914330401
2,000
262,144
Wrong Answer
17
2,940
67
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s590272305
Accepted
17
2,940
69
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s892456605
p00032
u651428295
1,000
131,072
Wrong Answer
20
7,640
200
機械に辺・対角線の長さのデータを入力し、プラスティック板の型抜きをしている工場があります。この工場では、サイズは様々ですが、平行四辺形の型のみを切り出しています。あなたは、切り出される平行四辺形のうち、長方形とひし形の製造個数を数えるように上司から命じられました。 「機械に入力するデータ」を読み込んで、長方形とひし形の製造個数を出力するプログラムを作成してください。
import sys t = 0 h = 0 for line in sys.stdin : line = list(map(int, line.split(','))) if line[2]**2 == line[0] ** 2 + line[1] ** 2 : t += 1 else : h += 1 print(t) print(h)
s308969627
Accepted
20
7,648
219
import sys t = 0 h = 0 for line in sys.stdin : line = list(map(int, line.split(','))) if line[2]**2 == line[0] ** 2 + line[1] ** 2 : t += 1 elif line[0] == line[1] : h += 1 print(t) print(h)
s268176087
p03699
u225388820
2,000
262,144
Wrong Answer
17
3,060
183
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
n=int(input()) scr=[int(input()) for i in range(n)] s=sum(scr) if s%10==0: print(s) exit() scr.sort() for i in range(n): if scr[i]%10!=0: print(s-scr[i]) exit() print(0)
s770374331
Accepted
18
3,060
183
n=int(input()) scr=[int(input()) for i in range(n)] s=sum(scr) if s%10!=0: print(s) exit() scr.sort() for i in range(n): if scr[i]%10!=0: print(s-scr[i]) exit() print(0)
s576947671
p03574
u578850957
2,000
262,144
Wrong Answer
169
12,460
913
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.
import numpy as np def countsherp(S_pad,i,j): count = 0 for k in range(-1,2): for l in range(-1,2): if S_pad[i+k][j+l]=='#': count += 1 return count h, w = map(int,input().split()) S = np.array([list(input()) for i in range(h)]) w_pad = np.array([['p' for i in range(w)]]) h_pad = 'p' S_pad = np.empty((0,w),int) S_pad = np.append(S_pad,w_pad,axis=0) S_pad = np.append(S_pad,S,axis=0) S_pad = np.append(S_pad,w_pad,axis=0) S_pad = np.insert(S_pad,0,h_pad,axis=1) S_pad = np.insert(S_pad,S_pad.shape[1],h_pad,axis=1) for i in range(1,S_pad.shape[0]-1): for j in range(1,S_pad.shape[1]-1): count = 0 if S_pad[i][j] == '.': S_pad[i][j] = countsherp(S_pad,i,j) print(S_pad[1:-1,1:-1])
s355767771
Accepted
171
13,088
969
import numpy as np def countsherp(S_pad,i,j): count = 0 for k in range(-1,2): for l in range(-1,2): if S_pad[i+k][j+l]=='#': count += 1 return count h, w = map(int,input().split()) S = np.array([list(input()) for i in range(h)]) w_pad = np.array([['p' for i in range(w)]]) h_pad = 'p' S_pad = np.empty((0,w),int) S_pad = np.append(S_pad,w_pad,axis=0) S_pad = np.append(S_pad,S,axis=0) S_pad = np.append(S_pad,w_pad,axis=0) S_pad = np.insert(S_pad,0,h_pad,axis=1) S_pad = np.insert(S_pad,S_pad.shape[1],h_pad,axis=1) for i in range(1,S_pad.shape[0]-1): for j in range(1,S_pad.shape[1]-1): count = 0 if S_pad[i][j] == '.': S_pad[i][j] = countsherp(S_pad,i,j) ans = S_pad[1:-1,1:-1] for i in range(ans.shape[0]): print(''.join(ans[i]))
s088079747
p03470
u227082700
2,000
262,144
Wrong Answer
17
3,060
181
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
def sortex(X): X.sort() a=[] for i in range(len(X)-1): if X[i]!=X[i+1]:a.append(X[i]) return a n=int(input());a=[int(input())for i in range(n)];a=sortex(a);print(len(a))
s373360516
Accepted
19
3,060
201
def sortex(X): b=sorted(X) b.append("null") a=[] for i in range(len(X)): if b[i]!=b[i+1]:a.append(b[i]) return a n=int(input());a=[int(input())for i in range(n)];a=sortex(a);print(len(a))
s164099806
p03719
u545503667
2,000
262,144
Wrong Answer
17
2,940
102
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a, b, c = [int(x) for x in input().split()] if c < a or c > b: print("NO") else: print("YES")
s332142897
Accepted
17
2,940
104
a, b, c = [int(x) for x in input().split()] if c < a or c > b: print("No") else: print("Yes")
s544455216
p02865
u973167272
2,000
1,048,576
Wrong Answer
27
9,012
67
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
n = int(input()) if n%2 == 0: print(n/2-1) else: print((n-1)/2)
s980760103
Accepted
28
9,056
77
n = int(input()) if n%2 == 0: print(int(n/2-1)) else: print(int((n-1)/2))
s865383757
p02833
u990300472
2,000
1,048,576
Wrong Answer
17
2,940
207
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
N = "1000000000000000000" if int(N[-1]) %2 == 0: ans = int(N[:-1]) N = int(N[:-1]) k = 1 while k != 0: k = N // 5 N = k ans += k print(ans) else: print(0)
s936419378
Accepted
17
3,060
229
N = input() if len(N) <= 1: print(0) exit() if int(N[-1]) %2 == 0: ans = int(N[:-1]) N = int(N[:-1]) k = 1 while k != 0: k = N // 5 N = k ans += k print(ans) else: print(0)