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
s625405979
p03214
u528388170
2,525
1,048,576
Wrong Answer
17
3,060
165
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
n=int(input()) a=[int(i) for i in input().split()] s=sum(a) l=len(a) x=s/l ans=100 for cnt,i in enumerate(a): y=abs(i-x) if y<ans: ans=cnt print(ans)
s571899059
Accepted
17
3,064
173
n=int(input()) a=[int(i) for i in input().split()] s=sum(a) l=len(a) x=s/l z=100 for cnt,i in enumerate(a): y=abs(i-x) if y<z: ans=cnt z=y print(ans)
s899402041
p04012
u516447519
2,000
262,144
Wrong Answer
18
2,940
123
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
w = str(input()) for i in range(len(w)): if w.count(w[i]) % 2 ==0: print('Yes') else: print('No')
s401078989
Accepted
17
2,940
165
w = str(input()) count = int() for i in range(len(w)): if w.count(w[i]) % 2 == 0: count += 1 if count == len(w): print('Yes') else: print('No')
s934711844
p03359
u468972478
2,000
262,144
Wrong Answer
23
9,152
75
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().split()) if a <= b: print(a + 1) else: print(a)
s966741399
Accepted
29
9,152
61
a, b = map(int, input().split()) print(a - 1 if a > b else a)
s969431959
p03545
u061127257
2,000
262,144
Wrong Answer
17
3,064
415
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.
num = list(map(int,list(input()))) for i in range(len(num) ** 2): op = [] for j in range(len(num)): if (i >> j) & 1: op.append("+") else: op.append("-") sum = num[0] for k in range(1,len(num)): if op[k] == "+": sum += num[k] elif op[k] == "-": sum -= num[k] if sum == 7: print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3])) break
s861330065
Accepted
17
3,064
419
num = list(map(int,list(input()))) for i in range(len(num) ** 2): op = [] for j in range(len(num)): if (i >> j) & 1: op.append("+") else: op.append("-") sum = num[0] for k in range(len(num)-1): if op[k] == "+": sum += num[k+1] elif op[k] == "-": sum -= num[k+1] if sum == 7: print("{}{}{}{}{}{}{}=7".format(num[0],op[0],num[1],op[1],num[2],op[2],num[3])) break
s744660471
p03448
u256833330
2,000
262,144
Wrong Answer
18
2,940
153
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,b,c,x=[int(input()) for _ in range(4)] print(len([1 for i in range(a+1) for j in range(b+1) if (x-500*a-100*b)%50==0 and 0<=(x-500*a-100*b)//50 <=c]))
s238287649
Accepted
18
2,940
153
a,b,c,x=[int(input()) for _ in range(4)] print(len([1 for i in range(a+1) for j in range(b+1) if (x-500*i-100*j)%50==0 and 0<=(x-500*i-100*j)//50 <=c]))
s601318781
p03469
u911793272
2,000
262,144
Wrong Answer
30
8,944
31
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S = input() print("2018"+S[:4])
s817568402
Accepted
27
8,984
32
S = input() print("2018"+S[4:])
s158539794
p03795
u136843617
2,000
262,144
Wrong Answer
17
2,940
44
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
x = int(input()) print(x*1500 - (x//15)*200)
s067724392
Accepted
17
2,940
106
def solve(): N = int(input()) print(N*800 - (N//15) * 200) if __name__ == '__main__': solve()
s088444273
p02418
u100813820
1,000
131,072
Wrong Answer
20
7,508
9
Write a program which finds a pattern $p$ in a ring shaped text $s$.
import re
s704773730
Accepted
50
7,632
969
# 18-Character-Ring.py # Input # ????????????????????? p ???????????????????????? # Output # Constraints # 1???p????????????s????????????100 # Sample Input 1 # vanceknowledgetoad # advance # Sample Output 1 # Yes # Sample Input 2 # vanceknowledgetoad # advanced # Sample Output 2 # No import re pattern=[] s=input() p=input() s= s+s # for p2 in list(p): # pattern.append(p2) # pattern.append(".*") # pattern = "".join(pattern) # print(pattern) matchOB = re.search(p, s) if matchOB: print("Yes") else: print("No")
s313788032
p02646
u731807761
2,000
1,048,576
Wrong Answer
112
27,152
2,157
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.
import numpy as np import sys #import copy def xnxn(n=0, flag="v"): """ args: int n: a number of lows to read example: input 1 retrun 1 input 1 2 3 return [1,2,3] input 1 2 3 4 return [[1,2,3], [4]] """ if n == 0: temp = list(map(int, input().split())) if len(temp) == 1: if flag == "l": return temp else: return temp[0] elif len(temp) > 1: return temp else: temp = [list(map(int, input().split())) for _ in range(n)] return temp def sp_xnxn(n=0): """ args: int n: a number of lows to read example input 1 retrun [1] input 123 return [1,2,3] input 123 4 return [[1,2,3], [4]] """ if n == 0: return [int(k) for k in xsxs()] else: return [[int(k) for k in xsxs()] for _ in range(n)] def xsxs(n=0): """ args: int n: a number of lows to read example: input AA retrun AA input A BBB CC return ["A","BBB","CC"] input A BB CCC D return [["A","BBB","CC"], ["D"]] """ if n == 0: temp = list(input().split()) if len(temp) == 1: return temp[0] elif len(temp) > 1: return temp else: return [list(input().split()) for _ in range(n)] def sp_xsxs(n=0): """ args: int n: a number of lows to read example: input A retrun ["A"] input ABC return ["A","B","C"] input ABC D return [["A","B","C"], ["D"]] """ if n == 0: return [s for s in xsxs()] else: return [[s for s in xsxs()] for _ in range(n)] a, v = xnxn() b, w = xnxn() t = xnxn() if v - w <= 0: print("No") elif abs(b - a) / (v - w) <= t: print("Yes") else: print("No")
s035041849
Accepted
111
27,004
1,426
import numpy as np import sys # import copy def xnxn(n=0, flag="v"): """ args: int n: a number of lows to read example: input 1 retrun 1 input 1 2 3 return [1,2,3] input 1 2 3 4 return [[1,2,3], [4]] """ if n == 0: temp = list(map(int, input().split())) if len(temp) == 1: if flag == "l": return temp else: return temp[0] elif len(temp) > 1: return temp else: temp = [list(map(int, input().split())) for _ in range(n)] return temp a, v = xnxn() b, w = xnxn() t = xnxn() # if b - a > 0: # b = min(b + w, 10 ** 9) # a = min(a + v, 10 ** 9) # if b == a: # print("YES") # sys.exit() # elif b - a < 0: # b = max(b - w, 10 ** 9) # a = max(a - v, 10 ** 9) # if b == a: # print("YES") # sys.exit() # print("NO") if b - a > 0: # b_f = min(b+t*w, 10 ** 9) # a_f = min(a + t * v, 10 ** 9) b_f = b+t*w a_f = a+t*v if b_f > a_f: print("NO") else: print("YES") else: # b_f = max(b-t*w, -10 ** 9) # a_f = max(a-t*v, -10 ** 9) b_f = b-t*w a_f = a-t*v if b_f < a_f: print("NO") else: print("YES")
s571466470
p02396
u328199937
1,000
131,072
Wrong Answer
130
5,568
125
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.
num = 1 while True: a = input() if a == '0': break print('case ' + str(num) + ':' + str(a)) num += 1
s952431910
Accepted
130
5,564
126
num = 1 while True: a = input() if a == '0': break print('Case ' + str(num) + ': ' + str(a)) num += 1
s419018785
p03160
u681444474
2,000
1,048,576
Wrong Answer
153
14,680
332
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N = int(input()) H_ = list(map(int,input().split())) def dp_solver(x): H = H_ dp=[float('inf')]*N dp[0]=0 dp[1]=abs(H[1]-H[0]) for i in range(N-2): dp[i+2] = min(dp[i+2],dp[i]+abs(H[i+2]-H[i])) dp[i+2] = min(dp[i+2],dp[i+1]+abs(H[i+2]-H[i+1])) print(dp) return dp[x-1] print(dp_solver(N))
s120961646
Accepted
121
20,716
208
# coding: utf-8 n = int(input()) h = list(map(int,input().split())) dp = [0] * n dp[1] = abs(h[0]-h[1]) for i in range(2, n): dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2])) print(dp[n-1])
s485277962
p03449
u064408584
2,000
262,144
Wrong Answer
17
3,064
336
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
def C_Candies(): N=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) print(a) print(b) count=0 for i in range(N): if sum(a[i+1:N])<sum(b[i:N-1]): break count = count +1 print(count) print(sum(a[0:count+1])+sum(b[count:N])) C_Candies()
s914308825
Accepted
17
3,064
268
def C_Candies(): N=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) count=0 for i in range(N): if count < sum(a[0:i+1])+sum(b[i:N+1]): count =sum(a[0:i+1])+sum(b[i:N+1]) print(count) C_Candies()
s815768737
p03943
u778348725
2,000
262,144
Wrong Answer
17
3,060
281
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a,b,c = (int(x) for x in input().split()) half_pack = int((a+b+c)/2) if(a == half_pack) and ((b+c) == half_pack): print("YES") elif(b == half_pack) and ((a+c) == half_pack): print("YES") elif(c == half_pack) and ((b+a) == half_pack): print("YES") else: print("NO")
s973476636
Accepted
18
3,060
281
a,b,c = (int(x) for x in input().split()) half_pack = int((a+b+c)/2) if(a == half_pack) and ((b+c) == half_pack): print("Yes") elif(b == half_pack) and ((a+c) == half_pack): print("Yes") elif(c == half_pack) and ((b+a) == half_pack): print("Yes") else: print("No")
s327935801
p02833
u903005414
2,000
1,048,576
Wrong Answer
322
22,284
248
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).
import sys import numpy as np N = int(input()) if N % 2 != 0: print(0) sys.exit() N = N // 10 * 10 ans = 0 for i in range(1, 19): if N < 10**i: break ans += N // 10**i ans += N // 50 ans -= N // 200 print('ans', ans)
s834407029
Accepted
17
2,940
140
import sys N = int(input()) if N % 2 != 0: print(0) sys.exit() N //= 2 ans = 0 while N: ans += N // 5 N //= 5 print(ans)
s002640022
p02601
u514334797
2,000
1,048,576
Wrong Answer
28
9,144
212
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
# B>G>R R,G,B = map(int,input().split()) K = int(input()) cnt = 0 while G<R: G *= 2 cnt += 1 while not B>G: B *= 2 cnt += 1 print(cnt) if cnt<=K: print("Yes") else: print("No")
s218364874
Accepted
30
8,968
201
# B>G>R R,G,B = map(int,input().split()) K = int(input()) cnt = 0 while not G>R: G *= 2 cnt += 1 while not B>G: B *= 2 cnt += 1 if cnt<=K: print("Yes") else: print("No")
s056738773
p03556
u403355272
2,000
262,144
Wrong Answer
17
3,060
39
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
x = int(input()) print((int(x ** 0.5)))
s863248015
Accepted
17
2,940
44
x = int(input()) print((int(x ** 0.5)) ** 2)
s872221593
p03861
u279229189
2,000
262,144
Wrong Answer
19
3,060
102
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
v = input().split(" ") a = int(v[0]) b = int(v[1]) x = int(v[2]) fb = b/x fa = (a-1)/x print(fb-fa)
s696385584
Accepted
17
3,060
112
v = input().split(" ") a = int(v[0]) b = int(v[1]) x = int(v[2]) fb = b//x fa = (a-1)//x print(max(fb-fa, 0))
s472175945
p03455
u985376351
2,000
262,144
Wrong Answer
17
2,940
96
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%2==0 and b%2==0: print('Even') else: print('Odd')
s098882286
Accepted
19
2,940
92
a, b = map(int, input().split()) c = a*b if c%2==0: print('Even') else: print('Odd')
s449925884
p02665
u135847648
2,000
1,048,576
Wrong Answer
2,211
180,596
462
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
def main(): n = int(input()) A = list(map(int, input().split())) if A[0] != 0: print(-1) exit() tree = [2 ** i for i in range(n + 1)] tree[-1] = A[-1] for i in range(n): if A[i] > tree[i]: print(-1) exit() for i in range(n - 1, 0, -1): cnt = A[i] + tree[i + 1] tree[i] = min(tree[i], cnt) #print(tree) print(sum(tree)) if __name__ == "__main__": main()
s333461392
Accepted
84
20,024
822
def main(): n = int(input()) A = list(map(int, input().split())) B = [0] * (n+1) if n == 0: x = A[0] if x == 1: print(1) else: print(-1) exit() # A0 + B0 = 1 now_s = sum(A) s = now_s for i in range(n+1): if i == 0: B[i] = 1 - A[i] else: now_s -= A[i] B[i] = min(now_s, 2 * B[i - 1] - A[i]) #print(A,B,now_s) if B[i] < 0: print(-1) exit() print(sum(B) + s) if __name__ == "__main__": main()
s426795358
p03644
u408375121
2,000
262,144
Wrong Answer
17
2,940
63
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) i = 0 while 2 ** i <= N: i += 1 print(i - 1)
s636688243
Accepted
17
2,940
71
N = int(input()) i = 0 while 2 ** i <= N: i += 1 print(2 ** (i - 1))
s610344384
p03337
u413165887
2,000
1,048,576
Wrong Answer
17
2,940
136
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
n,*a=map(int,open(0).read().split());x=s=l=c=0 for r,b in enumerate(a): x^=b;s+=b while x<s:x^=a[l];s-=a[l];l+=1 c+=r-l+1 print(c)
s293672836
Accepted
17
2,940
58
a, b = map(int, input().split()) print(max([a*b,a-b,a+b]))
s457167108
p02694
u022215787
2,000
1,048,576
Wrong Answer
24
9,020
84
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()) c = 100 r = 0 while c <= x: c = int(c*1.01) r += 1 print(r)
s336294559
Accepted
22
9,168
88
x = int(input()) c = 100 r = 0 while c < x: c = c + int(c*0.01) r += 1 print(r)
s235830411
p03944
u804358525
2,000
262,144
Wrong Answer
69
3,188
729
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
# -*- coding: utf-8 -*- w,h,n = map(int, input().split()) print(w,h) area = [[0 for i in range(w)] for j in range(h)] for i in range(n): a,b,c = map(int, input().split()) if(c == 1): for j in range(h): for k in range(a): area[j][k] = 1 if (c == 2): for j in range(h): for k in range(a,w): area[j][k] = 1 if(c == 3): for j in range(b): for k in range(w): area[j][k] = 1 if (c == 4): for j in range(b,h): for k in range(w): area[j][k] = 1 counter = 0 for i in range(h): for j in range(w): if(area[i][j] == 0): counter += 1 print(counter)
s002799309
Accepted
74
3,064
718
# -*- coding: utf-8 -*- w,h,n = map(int, input().split()) area = [[0 for i in range(w)] for j in range(h)] for i in range(n): a,b,c = map(int, input().split()) if(c == 1): for j in range(h): for k in range(a): area[j][k] = 1 if (c == 2): for j in range(h): for k in range(a,w): area[j][k] = 1 if(c == 3): for j in range(b): for k in range(w): area[j][k] = 1 if (c == 4): for j in range(b,h): for k in range(w): area[j][k] = 1 counter = 0 for i in range(h): for j in range(w): if(area[i][j] == 0): counter += 1 print(counter)
s342839867
p02613
u504573674
2,000
1,048,576
Wrong Answer
159
9,124
328
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
t = int(input()) c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(t): s = str(input()) if s == 'AC': c0 += 1 elif s == 'WA': c1 += 1 elif s == 'TLE': c2 += 1 elif s == 'RE': c3 += 1 print('AC X ' + str(c0)) print('WA X ' + str(c1)) print('TLE X ' + str(c2)) print('RE X ' + str(c3))
s301551905
Accepted
160
9,096
328
t = int(input()) c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(t): s = str(input()) if s == 'AC': c0 += 1 elif s == 'WA': c1 += 1 elif s == 'TLE': c2 += 1 elif s == 'RE': c3 += 1 print('AC x ' + str(c0)) print('WA x ' + str(c1)) print('TLE x ' + str(c2)) print('RE x ' + str(c3))
s851072259
p02396
u313089641
1,000
131,072
Wrong Answer
80
7,960
154
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.
num = [] while True: x = int(input()) if x == 0: break num.append(x) for i, n in enumerate(num): print('Case{} :{}'.format(i, n))
s551582103
Accepted
70
8,124
163
num = [] while True: x = int(input()) if x == 0: break num.append(x) for i, n in enumerate(num, start=1): print('Case {}: {}'.format(i, n))
s712872434
p03699
u652656291
2,000
262,144
Wrong Answer
19
3,060
202
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()) s =[int(input()) for i in range(n)] s.sort() s_sum =sum(s) if s_sum % 10 != 0: print(s_sum) else: for i in range(n): if s[i] % 10 != 0: s[i] = 0 break print(s_sum)
s193690804
Accepted
18
2,940
152
n = int(input()) s = [0] for i in range(n): s.append(int(input())) m=sum(s) s.sort() for x in s: if (m-x)%10!=0: print(m-x) exit() print(0)
s556371526
p02399
u264450287
1,000
131,072
Wrong Answer
20
5,600
75
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
a,b = map(int,input().split()) d = a // b r = a % b f = a / b print(d,r,f)
s682062103
Accepted
20
5,608
92
a,b = map(int,input().split()) d = a // b r = a % b f = a / b print(d,r,"{:.5f}".format(f))
s982003374
p03543
u093492951
2,000
262,144
Wrong Answer
18
2,940
85
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
N = input() if N[0] == N[1] and N[1] == N[2]: print("yes") else: print("no")
s451830393
Accepted
17
2,940
122
N = input() if (N[0] == N[1] and N[1] == N[2]) or (N[1] == N[2] and N[2] == N[3]): print("Yes") else: print("No")
s160710332
p02659
u945405878
2,000
1,048,576
Wrong Answer
22
9,096
116
Compute A \times B, truncate its fractional part, and print the result as an integer.
a, b = input().split(" ") A, B = int(a), float(b) B100 = int(round(B * 100)) C = int(round(A * B100 / 100)) print(C)
s498029663
Accepted
20
9,100
110
a, b = input().split(" ") A, B = int(a), float(b) B100 = round(B * 100) C = A * B100 ans = C // 100 print(ans)
s359888698
p03827
u902151549
2,000
262,144
Wrong Answer
19
3,184
210
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
# coding: utf-8 import time import re import math def main(): n=int(input()) s=input() x=0 mx=0 for a in s: if(a=='I'):x+=1 elif(a=='D'):x-=1 mx=max([mx,x]) main()
s781972256
Accepted
19
3,184
223
# coding: utf-8 import time import re import math def main(): n=int(input()) s=input() x=0 mx=0 for a in s: if(a=='I'):x+=1 elif(a=='D'):x-=1 mx=max([mx,x]) print(mx) main()
s215440508
p02259
u253463900
1,000
131,072
Wrong Answer
30
7,484
404
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
n = int(input()) s = input() A = list(map(int,s.split())) flag = 1 while(flag == 1): for k in range(0,len(A)-1): print(A[k],end=" ") print(A[len(A)-1]) flag = 0 for j in range(n-1,0,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag = 1 for k in range(0,len(A)-1): print(A[k],end=" ") print(A[len(A)-1])
s217929547
Accepted
60
7,616
362
n = int(input()) s = input() A = list(map(int,s.split())) flag = 1 cnt = 0 while(flag == 1): flag = 0 for j in range(n-1,0,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag = 1 cnt += 1 for k in range(0,len(A)-1): print(A[k],end=" ") print(A[len(A)-1]) print (cnt)
s780981360
p03480
u846150137
2,000
262,144
Wrong Answer
2,104
9,952
430
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
l=input() def hntn(a,s,t): e=s+t n="".join([str((int(i)+1) % 2) for i in a[s:e]]) return a[:s]+ n + a[e:] for i in range(len(l),0,-1): c=[] for w in range(len(l),i-1,-1): d='0'*len(l) for j in range(2*(len(l)-i+1)): b='0'*(len(l)-i+1-len(str(format(j, 'b'))))+str(format(j, 'b')) for v in range(len(b)): if b[v]=='1': d=hntn(d,v,w) c.append(d) if l in c: break print(i)
s262283351
Accepted
66
3,188
114
l=input() n=len(l) x = n for i in range(1,n): if l[i-1] != l[i]: nx = max(i, n-i) x = min(x,nx) print(x)
s261019402
p03637
u494209838
2,000
262,144
Wrong Answer
307
23,072
397
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
# -*- coding: utf-8 -*- import numpy as np N = np.int64(input()) a = np.array([int(x) for x in input().split()]) mod_a = np.mod(a, 4) count4 = (mod_a==0).sum() count2 = (mod_a==2).sum() odd = ((mod_a==1) | (mod_a==3)).sum() if N % 2 == 0: if count4 >= odd: print('yes') else: print('no') else: if count4 >= odd - 1: print('yes') else: print('no')
s824488720
Accepted
363
23,072
397
# -*- coding: utf-8 -*- import numpy as np N = np.int64(input()) a = np.array([int(x) for x in input().split()]) mod_a = np.mod(a, 4) count4 = (mod_a==0).sum() count2 = (mod_a==2).sum() odd = ((mod_a==1) | (mod_a==3)).sum() if N % 2 == 0: if count4 >= odd: print('Yes') else: print('No') else: if count4 >= odd - 1: print('Yes') else: print('No')
s060437673
p02747
u854405453
2,000
1,048,576
Wrong Answer
17
2,940
63
A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string.
s = input() s.replace("hi", "") print("Yes" if s=="" else "No")
s105989124
Accepted
17
2,940
65
s = input() s=s.replace("hi", "") print("Yes" if s=="" else "No")
s652809155
p03545
u543954314
2,000
262,144
Wrong Answer
17
3,064
217
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.
e = (1,-1) a,b,c,d = map(int, list(input())) for i in e: for j in e: for k in e: if a+b*i+c*j+d*k == 7: break dic = {1:"+",-1:"-"} l = [a,dic[i],b,dic[j],c,dic[k],d] print("".join(map(str,l))+"=7")
s747649345
Accepted
18
3,064
231
from itertools import product e = (1,-1) a,b,c,d = map(int, list(input())) for i,j,k in product(e,repeat=3): if a+b*i+c*j+d*k == 7: break dic = {1:"+",-1:"-"} l = [a,dic[i],b,dic[j],c,dic[k],d] print("".join(map(str,l))+"=7")
s343605031
p03699
u769870836
2,000
262,144
Wrong Answer
17
3,060
206
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()) l=sorted([int(input()) for i in range(n)]) if sum(l)%10!=0: print(sum(l)) else: ans=sum(l) for i in range(n): ans-=l[-1-i] if ans%10!=0: print(ans) quit() print(0)
s088928685
Accepted
18
3,060
206
n=int(input()) l=sorted([int(input()) for i in range(n)]) if sum(l)%10!=0: print(sum(l)) else: ans=sum(l) for i in range(n): if l[i]%10!=0: ans-=l[i] print(ans) quit() print(0)
s843106658
p02240
u424457654
1,000
131,072
Wrong Answer
30
5,604
778
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
def dfs(r, c): global color global g s = [r] color[r] = c while len(s) > 0: u = s.pop() for u in g[u]: v = color[u] if v is None: color[u] = c s.append(u) def assigncolor(): global g global color global n c = 1 for i in range(n): if color[i] == None: dfs(i, c) c += 1 n, m = list(map(int, input().split())) g = [[] for i in range(n)] for i in range(m): s, t = list(map(int, input().split())) g[s].append(t) g[t].append(s) color = [None for i in range(n)] assigncolor() q = int(input()) for i in range(q): if color[s] == color[t]: print("yes") else: print("no")
s045476713
Accepted
710
23,388
821
def dfs(r, c): global color global g s = [r] color[r] = c while len(s) > 0: u = s.pop() for u in g[u]: v = color[u] if v is None: color[u] = c s.append(u) def assigncolor(): global g global color global n c = 1 for i in range(n): if color[i] == None: dfs(i, c) c += 1 n, m = list(map(int, input().split())) g = [[] for i in range(n)] for i in range(m): s, t = list(map(int, input().split())) g[s].append(t) g[t].append(s) color = [None for i in range(n)] assigncolor() q = int(input()) for i in range(q): s, t = list(map(int, input().split())) if color[s] == color[t]: print("yes") else: print("no")
s902398302
p03545
u327532412
2,000
262,144
Wrong Answer
19
3,064
282
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, = list(input()) s = ['+', '-'] for i in range(2**3): formula = A[0] for j in range(3): if i >> j & 1: formula += s[0] else: formula += s[1] formula += A[j+1] if eval(formula) == 7: print(formula) exit()
s742159238
Accepted
29
9,064
258
ABCD = list(input()) ope = ['+', '-'] for i in range(2**3): f = ABCD[0] for j in range(3): if i >> j & 1: f += '+' else: f += '-' f += ABCD[j+1] if eval(f) == 7: print(f+"=7") exit()
s756251267
p02406
u299231628
1,000
131,072
Wrong Answer
20
5,584
155
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
n = int(input()) i = 1 a = '' while i <= n: if i % 3 == 0: a += ' ' + str(i) if i % 10 == 3: a += ' ' + str(i) i += 1 print(a)
s881545463
Accepted
30
5,980
326
n = int(input()) i = 1 l = [] while i <= n: x = i if x % 3 == 0: l.append(i) elif x % 10 == 3: l.append(i) else: x /= 10 x = int(x) while x: if x % 10 == 3: l.append(i) break x /= 10 x = int(x) i += 1 print('',*l)
s897914647
p03943
u646336933
2,000
262,144
Wrong Answer
17
2,940
106
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a, b, c = map(int, input().split()) if a+b==c or b+c==a or c+a==b: print("YES") else: print("NO")
s435364952
Accepted
17
2,940
106
a, b, c = map(int, input().split()) if a+b==c or b+c==a or c+a==b: print("Yes") else: print("No")
s300086778
p03501
u740047492
2,000
262,144
Wrong Answer
18
3,188
79
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.
n, a, b = map(int, input().split()) if (n*a) > b: print(n*a) else: print(b)
s421349627
Accepted
17
2,940
79
n, a, b = map(int, input().split()) if (n*a) < b: print(n*a) else: print(b)
s295972450
p03251
u111508936
2,000
1,048,576
Wrong Answer
863
21,524
352
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N, M, X, Y = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) maxx = max(x) miny = min(y) if miny > maxx and maxx < Y and miny < X: print('No War') else: print('War')
s317721934
Accepted
149
12,508
371
import numpy as np import math # K = int(input()) # N, K = map(int, input().split()) # A = list(map(int, input().split())) N, M, X, Y = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) maxx = max(x) miny = min(y) maxxx = max(maxx, X) minyy = min(miny, Y) if maxxx < minyy: print('No War') else: print('War')
s642667350
p03845
u519939795
2,000
262,144
Wrong Answer
18
2,940
161
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
n = int(input()) T = list(map(int, input().split())) s = sum(T) m = int(input()) for _ in range(m): p, x = map(int, input().split()) sub = -x + T[p - 1]
s367084143
Accepted
18
3,060
179
n = int(input()) T = list(map(int, input().split())) s = sum(T) m = int(input()) for _ in range(m): p, x = map(int, input().split()) sub = -x + T[p - 1] print(s - sub)
s609109006
p02417
u874395007
1,000
131,072
Wrong Answer
20
5,556
211
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
import sys data = sys.stdin.read() letters = 'abcdefghijklmnopqrstuvwxyz' for letter in letters: count = 0 for d in data: if letter == d: count += 1 print(f'{letter} : {count}')
s054347869
Accepted
20
5,564
219
import sys data = sys.stdin.read() letters = 'abcdefghijklmnopqrstuvwxyz' for letter in letters: count = 0 for d in data: if letter == d.lower(): count += 1 print(f'{letter} : {count}')
s561993514
p03836
u480847874
2,000
262,144
Wrong Answer
18
3,064
504
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.
def m(): sx, sy, tx, ty = map(int, input().split()) X = tx-sx Y = ty-sy ans = "" for _ in range(X): ans += "R" for _ in range(Y): ans += "U" for _ in range(X): ans += "L" for _ in range(Y): ans += "D" ans += "D" for _ in range(X): ans += "R" ans += "R" ans += "U" for _ in range(Y): ans += "U" ans += "U" ans += "L" * (X+1) ans += "D" * (Y+1) ans += "R" return ans print(m())
s591375295
Accepted
17
3,064
455
def m(): sx, sy, tx, ty = map(int, input().split()) X = tx-sx Y = ty-sy ans = "" ans += "U" * Y ans += "R" * X ans += "D" * Y ans += "L" * X ans += "L" ans += "U" * (Y+1) ans += "R" * (X+1) ans += "D" ans += "R" ans += "D" * (Y+1) ans += "L" * (X+1) ans += "U" return ans print(m())
s028794460
p03485
u564060397
2,000
262,144
Wrong Answer
17
2,940
91
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b=map(int,input().split()) if (a+b)%2==0: print((a+b)/2) else: print((a+b)//2+1)
s160718447
Accepted
17
2,940
49
a,b=map(int,input().split()) print(-(-(a+b)//2))
s340616000
p03486
u420522278
2,000
262,144
Wrong Answer
18
3,064
202
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() sl = sorted(s) tl = sorted(t) out = 'No' for i in range(0,min(len(s), len(t))): if sl[i] < tl[-1*i]: out = 'Yes' break elif sl[i] > tl[-1*i]: break print(out)
s029371668
Accepted
17
2,940
130
s = input() t = input() sl = ''.join(sorted(s)) tl = ''.join(reversed(sorted(t))) if sl < tl: print('Yes') else: print('No')
s312010741
p02602
u996506712
2,000
1,048,576
Wrong Answer
168
31,600
162
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
n,k=map(int,input().split()) a=list(map(int,input().split())) print(a) for i in range(n-k): if a[k+i]>a[i]: print('Yes') else: print('No')
s512842190
Accepted
144
31,524
153
n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(n-k): if a[k+i]>a[i]: print('Yes') else: print('No')
s399869989
p03433
u725044506
2,000
262,144
Wrong Answer
17
2,940
96
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) a = N % 500 if a <= A: print('YES') else: print('NO')
s328268044
Accepted
17
2,940
96
N = int(input()) A = int(input()) a = N % 500 if a <= A: print('Yes') else: print('No')
s567573114
p03352
u064408584
2,000
1,048,576
Wrong Answer
17
2,940
126
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x=int(input()) a=0 for i in range(300): for j in range(11): if i**j>x: break if a<i**j: a=i**j print(a)
s709342699
Accepted
17
2,940
128
x=int(input()) a=0 for i in range(300): for j in range(2,11): if i**j>x: break if a<i**j: a=i**j print(a)
s294888575
p02697
u614875193
2,000
1,048,576
Wrong Answer
69
9,280
66
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
N,M=map(int,input().split()) for i in range(M): print(1+i,N-i)
s599988063
Accepted
102
21,180
393
N,M=map(int,input().split()) ans=[] if N%2==0: N-=1 half=N//2 if half%2==0: for i in range(half//2): ans.append((i+1,half-i)) for j in range(half//2): ans.append((half+1+j,N-j)) else: for i in range(half//2): ans.append((i+1,half-i)) for j in range(half//2+1): ans.append((half+1+j,N-j)) #print(ans) for i in range(M): print(*ans[i])
s998721280
p03625
u969708690
2,000
262,144
Wrong Answer
155
33,264
224
We have N sticks with negligible thickness. The length of the i-th stick is A_i. Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
import collections N=int(input()) L=list(map(int,input().split())) c = collections.Counter(L) A=c.keys() B=c.values() R = zip(A,B) R=sorted(R,reverse=True) a, b = zip(*R) if b[0]>=4: print(a[0]**2) else: print(a[0]*a[1])
s022752133
Accepted
111
22,384
353
import collections N=int(input()) L=list(map(int,input().split())) c = collections.Counter(L) A=list(c.keys()) B=list(c.values()) R=list() for i in range(len(A)): if B[i]>=2: R.append([A[i],B[i]]) R=sorted(R,reverse=True) if len(R)==0: print(0) exit() if R[0][1]>=4: print(R[0][0]**2) elif len(R)<2: print(0) else: print(R[0][0]*R[1][0])
s971580559
p02393
u058433718
1,000
131,072
Wrong Answer
20
5,600
229
Write a program which reads three integers, and prints them in ascending order.
data = input() nums = [int(i) for i in data.split()] max_idx = len(nums) for i in range(1, max_idx): for j in range(max_idx-i): if nums[j] > nums[j+1]: nums[j], nums[j+1] = nums[j+1], nums[j] print(nums)
s805199166
Accepted
20
5,608
257
data = input() nums = [int(i) for i in data.split()] max_idx = len(nums) for i in range(1, max_idx): for j in range(max_idx-i): if nums[j] > nums[j+1]: nums[j], nums[j+1] = nums[j+1], nums[j] print(' '.join([str(i) for i in nums]))
s345364312
p03693
u532966492
2,000
262,144
Wrong Answer
17
2,940
57
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
print("YNEOS"[int("".join(sorted(input()))[2:])%4!=0::2])
s933296393
Accepted
17
2,940
111
def main(): a, b, c = map(int, input().split()) print(['NO', 'YES'][(a*100+b*10+c) % 4 == 0]) main()
s505450425
p02743
u891945807
2,000
1,048,576
Wrong Answer
17
2,940
109
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
a,b,c = map(int,input().split()) res = (c-a-b)**2 - a*b if res > 0 : print('Yes') else: print('No')
s074224975
Accepted
17
2,940
126
a,b,c = map(int,input().split()) res = (c-a-b)**2 - 4* a*b if res > 0 and c-a-b > 0 : print('Yes') else: print('No')
s725771506
p04012
u408620326
2,000
262,144
Wrong Answer
17
2,940
101
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
w=input().split() ans='No' for wd in w: if w.count(wd)%2!=0: break else: ans='Yes' print(ans)
s411309948
Accepted
17
2,940
93
w=input() ans='No' for wd in w: if w.count(wd)%2!=0: break else: ans='Yes' print(ans)
s955672619
p03836
u964299793
2,000
262,144
Wrong Answer
17
3,064
284
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty=map(int,input().split()) print('U'*(ty-sy),end='') print('R'*(tx-sx),end='') print('D'*(ty-sy),end='') print('L'*(tx-sx),end='') print('L',end='') print('U'*(ty-sy+1),end='') print('R'*(tx-sx+1),end='') print('D'*(ty-sy+1),end='') print('L'*(tx-sx+1),end='') print('U')
s071814483
Accepted
17
3,064
320
sx,sy,tx,ty=map(int,input().split()) print('U'*(ty-sy),end='') print('R'*(tx-sx),end='') print('D'*(ty-sy),end='') print('L'*(tx-sx),end='') print('L',end='') print('U'*(ty-sy+1),end='') print('R'*(tx-sx+1),end='') print('D',end='') print('R',end='') print('D'*(ty-sy+1),end='') print('L'*(tx-sx+1),end='') print('U')
s412942740
p03547
u626468554
2,000
262,144
Wrong Answer
18
2,940
194
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) a = list(input()) if a[0] > a[1]: print(">") elif a[0] == a[1]: print("=") else: print("<")
s477524012
Accepted
17
2,940
235
#n = int(input()) #n,k = map(int,input().split()) #x = list(map(int,input().split())) a = list(input().split()) li = ["A","B","C","D","E","F"] if a[0] > a[1]: print(">") elif a[0] == a[1]: print("=") else: print("<")
s937807910
p03502
u320098990
2,000
262,144
Wrong Answer
17
3,060
205
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = int(input()) f = 0 N_dammy = N while N_dammy>0: f += N_dammy % 10 N_dammy = int(N_dammy/10) print("f:",f) print("N_dammy:",N_dammy) if N%f==0: print("Yes") else: print("No")
s556920348
Accepted
17
2,940
156
N = int(input()) f = 0 N_dammy = N while N_dammy>0: f += N_dammy % 10 N_dammy = int(N_dammy/10) if N%f==0: print("Yes") else: print("No")
s896097873
p04029
u852790844
2,000
262,144
Wrong Answer
17
2,940
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s915580984
Accepted
17
2,940
39
n = int(input()) print(int(n*(n+1)/2))
s473102075
p03569
u539517139
2,000
262,144
Wrong Answer
60
3,316
182
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
s=input() l=0 r=len(s)-1 x=0 while l<r: if s[l]==s[r]: l+=1 r-=1 elif s[l]=='x': x+=1 l+=1 elif s[l]=='x': x+=1 r-=1 else: x=-1 break print(x)
s571265590
Accepted
62
3,316
182
s=input() l=0 r=len(s)-1 x=0 while l<r: if s[l]==s[r]: l+=1 r-=1 elif s[l]=='x': x+=1 l+=1 elif s[r]=='x': x+=1 r-=1 else: x=-1 break print(x)
s468859289
p03434
u201928947
2,000
262,144
Wrong Answer
17
3,060
181
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) a = list(map(int,input().split())) ans1 = 0 ans2 = 0 for i in range(n): if i % 2 == 1: ans1 += a[i] else: ans2 += a[i] print(max(ans1,ans2))
s891212843
Accepted
17
3,060
199
n = int(input()) a = sorted(list(map(int,input().split())),reverse = True) ans1 = 0 ans2 = 0 for i in range(n): if i % 2 == 0: ans1 += a[i] else: ans2 += a[i] print(ans1-ans2)
s221216903
p03721
u146597538
2,000
262,144
Wrong Answer
464
34,320
267
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
n,k = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(n)] s_ab = sorted(ab, key=lambda x: x[0]) cnt = 0 ans = -1 print(s_ab) for i in s_ab: cnt += i[1] if cnt >= k: print(cnt) ans = i[0] break print(ans)
s169700573
Accepted
499
28,640
187
n,k = map(int, input().split()) ab = sorted([list(map(int, input().split())) for _ in range(n)]) cnt = 0 for i in ab: cnt += i[1] if cnt >= k: print(i[0]) exit(0)
s780015286
p03162
u506858457
2,000
1,048,576
Wrong Answer
632
35,660
460
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
N = int(input()) a, b, c = [0] * N, [0] * N, [0] * N for i in range(N): a[i], b[i], c[i] = map(int, input().split()) dp = [[0] * 3 for _ in range(N)] print(dp) dp[0] = [a[0], b[0], c[0]] for i in range(N - 1): dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + a[i + 1], dp[i][2] + a[i + 1]) dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + b[i + 1], dp[i][2] + b[i + 1]) dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + c[i + 1], dp[i][1] + c[i + 1]) print(max(dp[N - 1]))
s421625946
Accepted
993
47,348
407
n=int(input()) happy=[list(map(int, input().split())) for i in range(n)] dp=[[0 for j in range(3)] for i in range(n+1)] for i in range(1,n+1): for place in range(3): for placeY in range(3): if place==placeY: continue dp[i][place]=max(dp[i][place], dp[i-1][placeY]+happy[i-1][place]) ans=0 for place in range(3): ans=max(ans,dp[n][place]) print(ans)
s882609039
p03574
u011062360
2,000
262,144
Wrong Answer
29
3,444
522
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
h, w = map(int, input().split()) map = a = [ list(input()) for _ in range(h) ] d = [[1, 0], [0, 1], [1, 1], [-1, 0], [0, -1], [-1, -1], [1, -1], [-1, 1]] for i in range(h): for j in range(w): cnt = 0 if map[i][j] == ".": for dx, dy in d: nx = j + dx ny = i + dy if 0 <= nx < w and 0 <= ny < h and map[ny][nx] == "#": cnt += 1 if map[i][j] != "#": map[i][j] = cnt for i in range(h): print(*map[i])
s202475042
Accepted
28
3,444
529
h, w = map(int, input().split()) map = a = [ list(input()) for _ in range(h) ] d = [[1, 0], [0, 1], [1, 1], [-1, 0], [0, -1], [-1, -1], [1, -1], [-1, 1]] for i in range(h): for j in range(w): cnt = 0 if map[i][j] == ".": for dx, dy in d: nx = j + dx ny = i + dy if 0 <= nx < w and 0 <= ny < h and map[ny][nx] == "#": cnt += 1 if map[i][j] != "#": map[i][j] = cnt for i in range(h): print(*map[i],sep="")
s065777915
p03657
u350093546
2,000
262,144
Wrong Answer
17
2,940
112
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
a,b=map(int,input().split()) if a%3!=0 and b%3!=0 and (a+b)%3!=0: print('Impossible') else: print('Posible')
s723919861
Accepted
17
2,940
114
a,b=map(int,input().split()) if a%3!=0 and b%3!=0 and (a+b)%3!=0: print('Impossible') else: print('Possible')
s093867624
p03110
u810066979
2,000
1,048,576
Wrong Answer
18
3,060
203
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?
import sys import math import itertools n=input() sum=0 for i in range(int(n)): x,u=list(input().split()) if u=="JPY": sum+=int(x) else : b_money=float(x)*380000.0 sum+=int(b_money) print(sum)
s562329209
Accepted
18
3,060
199
import sys import math import itertools n=input() sum=0 for i in range(int(n)): x,u=list(input().split()) if u=="JPY": sum+=int(x) else : b_money=float(x)*380000.0 sum+=b_money print(sum)
s463192976
p03672
u773686010
2,000
262,144
Wrong Answer
30
9,100
174
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
N = str(input()) cnt = 0 while True: N = N[0:-1] cnt += 1 if len(N) % 2 == 0: if N[0:int(len(N)/2)] == N[int(len(N)/2):]: break print(cnt)
s042673138
Accepted
30
9,060
154
N = str(input()) while True: N = N[0:-1] if len(N) % 2 == 0: if N[0:int(len(N)/2)] == N[int(len(N)/2):]: break print(len(N))
s036456548
p03369
u517152997
2,000
262,144
Wrong Answer
17
3,060
291
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = input("in") if S == "ooo" : print('1000') elif S == "oox": print('900') elif S == "oxo" : print('900') elif S == "xoo": print('900') elif S == "oxx": print('800') elif S == "xox": print('800') elif S == "xxo": print('800') elif S == "xxx": print('700')
s037311718
Accepted
17
2,940
276
S = input() if S == "ooo" : print('1000') elif S == "oox": print('900') elif S == "oxo" : print('900') elif S == "xoo": print('900') elif S == "oxx": print('800') elif S == "xox": print('800') elif S == "xxo": print('800') else: print('700')
s084328002
p03090
u335278042
2,000
1,048,576
Wrong Answer
20
3,572
323
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
#import collections as c #ip = lambda : map(int, input().split()) ################# N = int(input()) S = N*(N+1)/2 r = [] a = [] b = [] f = 1 for i in range(N,0,-1): if f%4==1 or f%4==0: a.append(i) f += 1 else: b.append(i) f += 1 for ia in a: for ib in b: print(ia,ib)
s077238722
Accepted
24
3,612
695
#import collections as c #ip = lambda : map(int, input().split()) ################# N = int(input()) if N%2==0: print(N*(N-1)//2-N//2) S = N + 1 for i in range(1,N): for j in range(i+1,N+1): if i!=j and i+j!=S: print(i,j) elif N%2==1: print(N*(N-1)//2-(N-1)//2) S = N for i in range(1,N): for j in range(i+1,N+1): if i!=j and i+j!=S: print(i,j) # a = [] # b = [] # f = 1 # if f%4==1 or f%4==0: # a.append(i) # f += 1 # else: # b.append(i) # f += 1 # print(len(a)*len(b)) # for ia in a: # for ib in b: # print(ia,ib)
s257742278
p03798
u633450100
2,000
262,144
Wrong Answer
20
3,316
45
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
N = int(input()) s = input() print("WWSSSS")
s654466747
Accepted
236
3,740
4,892
N = int(input()) s = str(input()) A = '' def majikayo(): k = 0 if A[0] == 'S' and s[0] == 'o': if A[-1] == 'S' and s[-1] == 'o': if A[1] == 'S' and A[-2] == 'S': k = 1 elif A[-1] == 'S' and s[-1] == 'x': if A[1] == 'S' and A[-2] == 'W': k = 1 elif A[-1] == 'W' and s[-1] == 'o': if A[1] == 'W' and A[-2] == 'W': k = 1 elif A[-1] == 'W' and s[-1] == 'x': if A[1] == 'W' and A[-2] == 'S': k = 1 elif A[0] == 'S' and s[0] == 'x': if A[-1] == 'S' and s[-1] == 'o': if A[1] == 'W' and A[-2] == 'S': k = 1 elif A[-1] == 'S' and s[-1] == 'x': if A[1] == 'W' and A[-2] == 'W': k = 1 elif A[-1] == 'W' and s[-1] == 'o': if A[1] == 'S' and A[-2] == 'W': k = 1 elif A[-1] == 'W' and s[-1] == 'x': if A[1] == 'S' and A[-2] == 'S': k = 1 elif A[0] == 'W' and s[0] == 'o': if A[-1] == 'S' and s[-1] == 'o': if A[1] == 'W' and A[-2] == 'W': k = 1 elif A[-1] == 'S' and s[-1] == 'x': if A[1] == 'W' and A[-2] == 'S': k = 1 elif A[-1] == 'W' and s[-1] == 'o': if A[1] == 'S' and A[-2] == 'S': k = 1 elif A[-1] == 'W' and s[-1] == 'x': if A[1] == 'S' and A[-2] == 'W': k = 1 elif A[0] == 'W' and s[0] == 'x': if A[-1] == 'S' and s[-1] == 'o': if A[1] == 'S' and A[-2] == 'W': k = 1 elif A[-1] == 'S' and s[-1] == 'x': if A[1] == 'S' and A[-2] == 'S': k = 1 elif A[-1] == 'W' and s[-1] == 'o': if A[1] == 'W' and A[-2] == 'S': k = 1 elif A[-1] == 'W' and s[-1] == 'x': if A[1] == 'W' and A[-2] == 'W': k = 1 if k == 1: return 1 A = 'SS' for i in range(1,N-1): if s[i] == 'o' and A[i] == 'S': if A[i-1] == 'S': A += 'S' else: A += 'W' elif s[i] == 'o' and A[i] == 'W': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'S': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'W': if A[i-1] == 'S': A += 'S' else: A += 'W' if majikayo() == 1: print(A) else: A = 'SW' for i in range(1,N-1): if s[i] == 'o' and A[i] == 'S': if A[i-1] == 'S': A += 'S' else: A += 'W' elif s[i] == 'o' and A[i] == 'W': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'S': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'W': if A[i-1] == 'S': A += 'S' else: A += 'W' if majikayo() == 1: print(A) else: k = 0 A = 'WS' for i in range(1,N-1): if s[i] == 'o' and A[i] == 'S': if A[i-1] == 'S': A += 'S' else: A += 'W' elif s[i] == 'o' and A[i] == 'W': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'S': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'W': if A[i-1] == 'S': A += 'S' else: A += 'W' majikayo() if majikayo() == 1: print(A) else: k = 0 A = 'WW' for i in range(1,N-1): if s[i] == 'o' and A[i] == 'S': if A[i-1] == 'S': A += 'S' else: A += 'W' elif s[i] == 'o' and A[i] == 'W': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'S': if A[i-1] == 'S': A += 'W' else: A += 'S' elif s[i] == 'x' and A[i] == 'W': if A[i-1] == 'S': A += 'S' else: A += 'W' if majikayo() == 1: print(A) else: print(-1)
s300406007
p03339
u057109575
2,000
1,048,576
Wrong Answer
17
3,060
137
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
S = input() cnt = S.count('E') ans = cnt for v in S: if v == 'E': cnt -= 1 else: cnt += 1 ans = min(ans, cnt) print(ans)
s893479917
Accepted
124
3,676
148
N = input() S = input() cnt = S.count('E') ans = cnt for v in S: if v == 'E': cnt -= 1 else: cnt += 1 ans = min(ans, cnt) print(ans)
s879787974
p03545
u996996256
2,000
262,144
Wrong Answer
18
3,064
343
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 = input() n= 2**(len(s)-1) ans = 'inf' for i in range(n): total = int(s[0]) str = s[0] for j in range(1,len(s)): if i>>(len(s)-j)&1: total += int(s[j]) str += '+' + s[j] else: total -= int(s[j]) str += '-' + s[j] if total == 7: ans = str print(str+'=7')
s736820188
Accepted
17
3,060
318
s = input() for i in range(8): total = int(s[0]) str = s[0] for j in range(1, 4): if i >> (j - 1) & 1: total += int(s[j]) str += '+' + s[j] else: total -= int(s[j]) str += '-' + s[j] if total == 7: print(str + '=7') exit()
s761891555
p03456
u867826040
2,000
262,144
Wrong Answer
18
3,060
99
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
n = int("".join(input().split())) x = n**(1/2) if x%1 != 0: print("No") else: print(int(x))
s858185467
Accepted
18
3,060
98
n = int("".join(input().split())) x = n**(1/2) if x%1 != 0: print("No") else: print("Yes")
s126917146
p03007
u994988729
2,000
1,048,576
Wrong Answer
259
19,532
355
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
from collections import deque n = int(input()) a = list(map(int, input().split())) a.sort() a = deque(a) left = a.popleft() right = a.pop() ans = [] for i in a: if i > 0: ans.append((left, i)) left -= i else: ans.append((right, i)) right -= i else: ans.append((right, left)) for x, y in ans: print(x, y)
s229691525
Accepted
261
19,524
373
from collections import deque n = int(input()) a = list(map(int, input().split())) a.sort() a = deque(a) left = a.popleft() right = a.pop() ans = [] for i in a: if i > 0: ans.append((left, i)) left -= i else: ans.append((right, i)) right -= i else: ans.append((right, left)) print(right-left) for x, y in ans: print(x, y)
s385306064
p02259
u905313459
1,000
131,072
Time Limit Exceeded
40,000
7,376
256
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
import sys x = input() y = input().split() r = sorted(y) c = 0 while y != r: for i, j in enumerate(y[:-1]): if y[i] > y[i+1]: y[i], y[i+1] = y[i+1], y[i] c += 1 else: break print(" ".join(y)) print(c)
s556346758
Accepted
20
7,704
231
x = int(input()) y = input() y = list(map(int, y.split())) r = sorted(y) c = 0 while y != r: for i, j in enumerate(y[:-1]): if y[i] > y[i+1]: y[i], y[i+1] = y[i+1], y[i] c += 1 print(*y) print(c)
s531122085
p03563
u580093517
2,000
262,144
Wrong Answer
17
2,940
37
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
print(int(input())**2 - int(input()))
s571478375
Accepted
18
2,940
39
print(-(int(input()) - 2*int(input())))
s068035689
p03361
u460468647
2,000
262,144
Wrong Answer
21
3,188
521
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
h,w = map(int,input().split()) array = [] for _ in range(h): array.append(list(map(str,input()))) print(array) for i in range(h): array[i].insert(0,".") array[i].append(".") print(array) array.insert(0,["."]*(w+2)) array.append(["."]*(w+2)) print(array) for i in range(1,h+1): for j in range(1,w+1): if array[i][j]=="#" and array[i][j-1] == array[i][j+1] == array[i-1][j] == array[i+1][j] == ".": print("No") break if i==h and j==w: print("Yes") break else: continue break
s949220300
Accepted
18
3,064
313
H,W=map(int,input().split()) S=["."+input()+"." for i in range(H)] S=["."*(W+2)]+S+["."*(W+2)] flag=0 for i in range(H): for j in range(W): if S[i][j]=="#": if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".": flag=1 print("Yes" if flag==0 else "No")
s404224557
p03827
u214547877
2,000
262,144
Wrong Answer
30
9,160
118
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() ans = 0 for i in range(N): if S[i] == "I": ans += 1 else: ans -= 1 print(ans)
s952173437
Accepted
31
9,176
139
N = int(input()) S = input() ans = 0 x = 0 for i in range(N): if S[i] == "I": x += 1 else: x -= 1 ans = max(ans,x) print(ans)
s090412570
p03605
u911612592
2,000
262,144
Wrong Answer
33
9,092
79
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
s = str(input()) if s[0] == 9 or s[1] == 9: print("Yes") else: print("No")
s582958345
Accepted
29
9,016
53
if "9" in input(): print("Yes") else: print("No")
s958266433
p03659
u099566485
2,000
262,144
Wrong Answer
229
24,948
216
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|.
#067-C n=int(input()) a=list(map(int,input().split())) sa=[a[0] for i in range(n)] for i in range(1,n): sa[i]=sa[i-1]+a[i] mm=float("INF") for i in range(n): mm=min(mm,abs(a[i]-(sa[n-1]-a[i]))) print(int(mm))
s495045545
Accepted
231
24,812
220
#067-C n=int(input()) a=list(map(int,input().split())) sa=[a[0] for i in range(n)] for i in range(1,n): sa[i]=sa[i-1]+a[i] mm=float("INF") for i in range(n-1): mm=min(mm,abs(sa[i]-(sa[n-1]-sa[i]))) print(int(mm))
s311130182
p03090
u509911932
2,000
1,048,576
Wrong Answer
45
4,484
878
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
""" 234 23 134 14 124 14 123 23 """ import copy N = 100 initial = [list(range(1, N + 1)) for i in range(N)] for i in range(N): initial[i].pop(i) # print(initial) neighbors = copy.deepcopy(initial) S = sum(neighbors[-1]) while True: # print(S) # print(neighbors) for i, tyouten in enumerate(neighbors): delta = sum(tyouten) - S if delta in tyouten: tyouten.remove(delta) neighbors[delta - 1].remove(i + 1) elif delta == 0: continue else: S -= 1 neighbors = copy.deepcopy(initial) break else: break # print(neighbors) ans = [] for i, tyouten in enumerate(neighbors): for j in tyouten: if j > i+1: ans.append(str(i+1)+" "+str(j)) print(len(ans)) for s in ans: print(s)
s891760819
Accepted
43
4,356
887
""" 234 23 134 14 124 14 123 23 """ import copy N = int(input()) initial = [list(range(1, N + 1)) for i in range(N)] for i in range(N): initial[i].pop(i) # print(initial) neighbors = copy.deepcopy(initial) S = sum(neighbors[-1]) while True: # print(S) # print(neighbors) for i, tyouten in enumerate(neighbors): delta = sum(tyouten) - S if delta in tyouten: tyouten.remove(delta) neighbors[delta - 1].remove(i + 1) elif delta == 0: continue else: S -= 1 neighbors = copy.deepcopy(initial) break else: break # print(neighbors) ans = [] for i, tyouten in enumerate(neighbors): for j in tyouten: if j > i+1: ans.append(str(i+1)+" "+str(j)) print(len(ans)) for s in ans: print(s)
s058053849
p03024
u814986259
2,000
1,048,576
Wrong Answer
28
9,004
68
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S=input() k=S.count("o") if k>=8: print("YES") else: print("NO")
s984335156
Accepted
31
9,012
87
S=input() l=len(S) k=S.count("o") K=15-l if k+K>=8: print("YES") else: print("NO")
s694052030
p03369
u728498511
2,000
262,144
Wrong Answer
17
2,940
39
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
print(700+100*list(input()).count("x"))
s729169628
Accepted
17
2,940
39
print(700+100*list(input()).count("o"))
s878851259
p03455
u082584636
2,000
262,144
Wrong Answer
17
2,940
124
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
int_list = list(map(int, input().split())) if (((int_list[0] + int_list[1]) % 2) == 0): print('Even') else: print('Odd')
s698105848
Accepted
17
2,940
125
int_list = list(map(int, input().split())) if (((int_list[0]*int_list[1]) % 2) == 0): print('Even') else: print('Odd')
s171184664
p03679
u461636820
2,000
262,144
Wrong Answer
17
2,940
137
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
X, A, B = map(int, input().split()) if A - B <= X: print('delicious') elif B - A >= X: print('dangerous') else: print('safe')
s810075976
Accepted
18
2,940
133
X, A, B = map(int, input().split()) if A >= B: print('delicious') elif B - A <= X: print('safe') else: print('dangerous')
s741695582
p02690
u606523772
2,000
1,048,576
Time Limit Exceeded
2,248
27,832
196
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
X = int(input()) for i in range(-800, 800): for j in range(-800, 800): print(i**5 - j**5) if i**5 - j**5 == X: ans = [i, j] break print(ans)
s333255655
Accepted
544
9,044
189
X = int(input()) for i in range(-500, 500): for j in range(-500, 500): if i**5 - j**5 == X: ans = [str(i), str(j)] break print(" ".join(ans))
s863268295
p03448
u119983020
2,000
262,144
Wrong Answer
48
3,060
202
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()) cnt = 0 for a in range(A): for b in range(B): for c in range(C): if X == 500*a + 100*b + 50*c: cnt += 1 print(cnt)
s436676476
Accepted
51
3,060
208
A = int(input()) B = int(input()) C = int(input()) X = int(input()) cnt = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): if X == 500*a + 100*b + 50*c: cnt += 1 print(cnt)
s092883903
p02614
u382407432
1,000
1,048,576
Wrong Answer
27
9,204
361
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
H, W, K = map(int,(input().split())) c=[] for _ in range(H): c.append(input()) ans=0 for maskR in range(H): for maskC in range(W): black=0 for i in range(H): for j in range(W): if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == '#': black = black + 1 if black == K: ans = ans + 1 print(ans)
s706687583
Accepted
66
9,208
367
H, W, K = map(int,(input().split())) c = [] for _ in range(H): c.append(input()) ans = 0 for maskR in range((1<<H)-1): for maskC in range((1<<W)-1): black=0 for i in range(H): for j in range(W): if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == '#': black += 1 if black == K: ans += 1 print(ans)
s139530306
p03711
u320763652
2,000
262,144
Wrong Answer
18
3,060
196
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
a,b = map(int, input().split()) listb = [4,6,9,11] tmp = a in listb print(tmp) if (a == 2 and b ==2): print("YES") elif (a in listb and b in listb): print("YES") else: print("NO")
s268120638
Accepted
18
3,064
274
a,b = map(int, input().split()) lista = [1,3,5,7,8,10,12] listb = [4,6,9,11] tmp = a in listb # print(tmp) if (a == 2 and b ==2): print("Yes") elif (a in listb and b in listb): print("Yes") elif (a in lista and b in lista): print("Yes") else: print("No")
s132208432
p04012
u131406102
2,000
262,144
Wrong Answer
17
3,064
351
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
a = list(input()) a = sorted(a) def count(a): b =[] for i in range(0,len(a)-2): if a[i] != a[i+1]: b.append( i+1) return b b = count(a) b.append(len(a)) for i in reversed(range(0,len(b)-1)): b[i+1] =b[i+1] - b[i] d = 0 for i in range(0,len(b)): d = d +b[i]%2 if d ==0: print('yes') else: print('no')
s977999972
Accepted
18
3,064
351
a = list(input()) a = sorted(a) def count(a): b =[] for i in range(0,len(a)-2): if a[i] != a[i+1]: b.append( i+1) return b b = count(a) b.append(len(a)) for i in reversed(range(0,len(b)-1)): b[i+1] =b[i+1] - b[i] d = 0 for i in range(0,len(b)): d = d +b[i]%2 if d ==0: print('Yes') else: print('No')
s097319999
p03943
u870841038
2,000
262,144
Wrong Answer
17
2,940
148
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.
li = list(map(int, input().split())) if li[0]+li[1] == li[2] or li[1]+li[2] == li[0] or li[2]+li[0] == li[1]: print('YES') else: print('NO')
s876762461
Accepted
17
2,940
148
li = list(map(int, input().split())) if li[0]+li[1] == li[2] or li[1]+li[2] == li[0] or li[2]+li[0] == li[1]: print('Yes') else: print('No')
s640434774
p02613
u002663801
2,000
1,048,576
Wrong Answer
147
9,216
358
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): s = input() if s == "AC": ac += 1 if s == "WA": wa += 1 if s == "TLE": tle += 1 if s == "RE": re += 1 a1 = "AC × " + str(ac) a2 = "WA × " + str(wa) a3 = "TLE × " + str(tle) a4 = "RE × " + str(re) print(a1) print(a2) print(a3) print(a4)
s164949046
Accepted
151
9,220
354
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): s = input() if s == "AC": ac += 1 if s == "WA": wa += 1 if s == "TLE": tle += 1 if s == "RE": re += 1 a1 = "AC x " + str(ac) a2 = "WA x " + str(wa) a3 = "TLE x " + str(tle) a4 = "RE x " + str(re) print(a1) print(a2) print(a3) print(a4)
s126435944
p03738
u533039576
2,000
262,144
Wrong Answer
17
3,060
253
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a = input() b = input() max_len = 105 if len(a) < max_len: a = '0' * (max_len - len(a)) + a if len(b) < max_len: b = '0' * (max_len - len(b)) + b if a > b: ans = "GRATER" elif a == b: ans = "EQUAL" else: ans = "LESS" print(ans)
s216927799
Accepted
18
3,060
254
a = input() b = input() max_len = 105 if len(a) < max_len: a = '0' * (max_len - len(a)) + a if len(b) < max_len: b = '0' * (max_len - len(b)) + b if a > b: ans = "GREATER" elif a == b: ans = "EQUAL" else: ans = "LESS" print(ans)
s498565793
p03473
u750389519
2,000
262,144
Wrong Answer
28
9,088
27
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
M=input() M=int(M) M=48-M
s324034406
Accepted
29
8,836
32
M=input() M=int(M) print(48-M)
s673410077
p03943
u027403702
2,000
262,144
Wrong Answer
19
3,060
105
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
a,b,c = input().split() if a + b == c or a + c == b or b + c == a: print("Yes") else: print("No")
s293109907
Accepted
18
2,940
115
a,b,c = map(int, input().split()) if a + b == c or a + c == b or b + c == a: print("Yes") else: print("No")
s361958606
p03861
u978510477
2,000
262,144
Wrong Answer
17
2,940
58
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a, b, x = map(int, input().split()) print(b // x - a // x)
s060716374
Accepted
17
2,940
64
a, b, x = map(int, input().split()) print(b // x - (a - 1) // x)
s029147917
p03624
u396961814
2,000
262,144
Wrong Answer
60
4,800
158
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
s = list(sorted(input())) ans = 'None' for i in range(26): if chr(97 + i) not in s: ans = chr(97 + i) print(ans) break print(ans)
s958961185
Accepted
60
4,800
140
s = list(sorted(input())) ans = 'None' for i in range(26): if chr(97 + i) not in s: ans = chr(97 + i) break print(ans)
s471006461
p02233
u798803522
1,000
131,072
Wrong Answer
20
7,604
220
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula: \begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + fib(n - 2) & \\\ \end{array} \right. \end{equation*}
target = int(input()) fib = [0 for n in range(target + 1)] for i in range(target): if i == 0: continue elif i == 1: fib[i] = 1 else: fib[i] = fib[i - 1] + fib[i - 2] print(fib[target])
s960290085
Accepted
20
7,768
228
target = int(input()) + 1 fib = [0 for n in range(target + 1)] for i in range(target + 1): if i == 0: continue elif i == 1: fib[i] = 1 else: fib[i] = fib[i - 1] + fib[i - 2] print(fib[target])
s789377090
p00014
u252368621
1,000
131,072
Wrong Answer
40
7,612
83
Write a program which computes the area of a shape represented by the following three lines: $y = x^2$ $y = 0$ $x = 600$ It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles in the shape as shown in the following figure: $f(x) = x^2$ The approximative area $s$ where the width of the rectangles is $d$ is: area of rectangle where its width is $d$ and height is $f(d)$ $+$ area of rectangle where its width is $d$ and height is $f(2d)$ $+$ area of rectangle where its width is $d$ and height is $f(3d)$ $+$ ... area of rectangle where its width is $d$ and height is $f(600 - d)$ The more we decrease $d$, the higer-precision value which is close to $72000000$ we could obtain. Your program should read the integer $d$ which is a divisor of $600$, and print the area $s$.
d=int(input()) sum=0 for i in range(int(600/d)): sum+=(((i*d)**2)*d) print(sum)
s876835198
Accepted
30
7,676
171
while(True): try: d=int(input()) sum=0 for i in range(int(600/d)): sum+=(((i*d)**2)*d) print(sum) except: break