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
s915163148
p03487
u780962115
2,000
262,144
Wrong Answer
122
21,744
431
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
from collections import Counter as ct n=int(input()) lists=list(map(int,input().split())) wanted=dict(ct(lists)) print(wanted) if n>=2: numbers=0 for i in wanted.keys(): a=i-wanted[i] if a<0: numbers+=abs(a) elif a==0: numbers+=0 if a>0: numbers+=wanted[i] print(numbers) elif n==1: if lists==[1]: print(0) else: print(1)
s700442920
Accepted
103
21,740
419
from collections import Counter as ct n=int(input()) lists=list(map(int,input().split())) wanted=dict(ct(lists)) if n>=2: numbers=0 for i in wanted.keys(): a=i-wanted[i] if a<0: numbers+=abs(a) elif a==0: numbers+=0 if a>0: numbers+=wanted[i] print(numbers) elif n==1: if lists==[1]: print(0) else: print(1)
s356246198
p04029
u680851063
2,000
262,144
Wrong Answer
17
2,940
59
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?
a=int(input()) b=1 for i in range(a+1): b = b+i print(b)
s328835743
Accepted
18
2,940
59
a=int(input()) b=0 for i in range(a+1): b=b+i print(b)
s774042132
p03852
u874741582
2,000
262,144
Wrong Answer
17
2,940
54
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
a="abcde" c = input() print("Yes" if c in a else "No")
s810413550
Accepted
17
2,940
63
a="aeiou" c = input() print("vowel" if c in a else "consonant")
s738362727
p03407
u535659144
2,000
262,144
Wrong Answer
17
2,940
96
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a,b,c=map(int,input().split()) if a==c or b==c or a+b==c: print("Yes") else: print("No")
s149617432
Accepted
17
2,940
80
a,b,c=map(int,input().split()) if a+b>=c: print("Yes") else: print("No")
s108115393
p03693
u382303205
2,000
262,144
Wrong Answer
17
2,940
97
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r,g,b=map(int,input().split()) if (r*100+g*10+b) % 4 == 0: print("Yes") else: print("No")
s044207202
Accepted
17
2,940
82
if (int(input().replace(" ",""))) % 4 == 0: print("YES") else: print("NO")
s461920751
p03720
u842388336
2,000
262,144
Wrong Answer
17
2,940
138
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
a,b = map(int,input().split()) road_list=[] for _ in range(b): road_list+=list(input()) for i in range(a+1): print(road_list.count(i))
s923385003
Accepted
17
2,940
197
n,m = map(int,input().split()) road_list=[0 for _ in range(n)] for _ in range(m): a,b = map(int,input().split()) road_list[a-1]+=1 road_list[b-1]+=1 for i in range(n): print(road_list[i])
s437424386
p03829
u905582793
2,000
262,144
Wrong Answer
86
15,020
189
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one- dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town i is X_i. You are now at town 1, and you want to visit all the other towns. You have two ways to travel: * Walk on the line. Your _fatigue level_ increases by A each time you travel a distance of 1, regardless of direction. * Teleport to any location of your choice. Your fatigue level increases by B, regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.
n,a,b=map(int,input().split()) x=list(map(int,input().split())) ans = 0 maxwalk = b//a for i in range(n-1): if x[i+1]-x[i]>=maxwalk: ans+=b else: ans+=(x[i+1]-x[i])*a print(ans)
s195653957
Accepted
90
14,252
188
n,a,b=map(int,input().split()) x=list(map(int,input().split())) ans = 0 maxwalk = b//a for i in range(n-1): if x[i+1]-x[i]>maxwalk: ans+=b else: ans+=(x[i+1]-x[i])*a print(ans)
s434135827
p02972
u739843002
2,000
1,048,576
Wrong Answer
429
22,768
388
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
import math def main(): N = int(input()) A = [int(a) for a in input().split(" ")] B = [0] * N for i in range(1, N): for j in range(math.ceil(N / (i + 1)), math.floor(N / i) + 1): ball = 0 for k in range(2 * j, N, j): if B[k - 1] == 1: ball += 1 B[j - 1] = (ball % 2 + A[j - 1]) % 2 ans = [str(x) for x, v in enumerate(B) if v == 1] print(" ".join(ans)) main()
s753296344
Accepted
426
22,824
499
import math def main(): N = int(input()) A = [int(a) for a in input().split(" ")] B = [0] * N if N == 1: if A[0] == 1: print(1) print(1) else: print(0) return 0 for i in range(1, N): for j in range(math.ceil(N / (i + 1)), math.floor(N / i) + 1): ball = 0 for k in range(2 * j, N + 1, j): ball += B[k - 1] B[j - 1] = (ball % 2 + A[j - 1]) % 2 ans = [str(x + 1) for x, v in enumerate(B) if v == 1] print(len(ans)) if len(ans) > 0: print(" ".join(ans)) main()
s783221744
p03711
u500297289
2,000
262,144
Wrong Answer
18
2,940
215
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.
""" AtCoder """ x, y = map(int, input().split()) a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] if (x in a and y in b) or (x in b and y in b) or (x in c and y in c): print("Yes") else: print("No")
s301333303
Accepted
17
2,940
215
""" AtCoder """ x, y = map(int, input().split()) a = [1, 3, 5, 7, 8, 10, 12] b = [4, 6, 9, 11] c = [2] if (x in a and y in a) or (x in b and y in b) or (x in c and y in c): print("Yes") else: print("No")
s340657908
p03636
u282277161
2,000
262,144
Wrong Answer
25
8,952
23
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
#!/usr/bin/env python3
s770303654
Accepted
26
9,020
43
s = input() print(s[0]+str(len(s)-2)+s[-1])
s226808208
p03796
u313103408
2,000
262,144
Wrong Answer
2,206
9,400
83
Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.
n = int(input()) M = 10**9+7 sum = 1 for i in range(1,n): sum *= i%M print(sum%M)
s387957925
Accepted
40
9,160
76
n = int(input()) d = 1 for i in range(1,n+1): d = (d*i)%(10**9+7) print(d)
s735728748
p03719
u125269142
2,000
262,144
Wrong Answer
29
9,136
103
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a, b, c = map(int, input().split()) if a <= c and c <= b: ans = 'YES' else: ans = 'NO' print(ans)
s482575251
Accepted
28
9,000
104
a, b, c = map(int, input().split()) if a <= c and c <= b: ans = 'Yes' else: ans = 'No' print(ans)
s603731585
p03997
u399721252
2,000
262,144
Wrong Answer
17
2,940
50
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
print((int(input())+int(input()))//2*int(input()))
s095564623
Accepted
17
2,940
69
a = int(input()) b = int(input()) c = int(input()) print((a+b)*c//2)
s304836342
p02401
u467711590
1,000
131,072
Wrong Answer
20
5,596
197
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
while True: a, op, b = map(str, input().split()) a = int(a) b = int(b) if op == '?': break if op == '+': print(a+b) if op == '-': print(a*b) if op == '*': print(a//b)
s298252202
Accepted
20
5,596
228
while True: a, op, b = map(str, input().split()) a = int(a) b = int(b) if op == '?': break if op == '+': print(a+b) if op == '-': print(a-b) if op == '*': print(a*b) if op == '/': print(a//b)
s596245737
p03601
u941753895
3,000
262,144
Wrong Answer
3,156
5,464
987
Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. * Operation 1: Pour 100A grams of water into the beaker. * Operation 2: Pour 100B grams of water into the beaker. * Operation 3: Put C grams of sugar into the beaker. * Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): a,b,c,d,e,f=LI() ans_n=-inf ans_pair=[0,0] z=100*e/(100+e) for i in range(31): for j in range(31): for k in range(3001): for l in range(3001): a=i*100+j*100 b=k+l if a+b>f: break if a+b==0: break y=100*b/(a+b) if y<z: if ans_n<z: ans_n=z ans_pair=[a+b,b] return str(ans_pair[0])+' '+str(ans_pair[1]) # main() print(main())
s677724142
Accepted
2,675
5,840
1,023
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): a,b,c,d,e,f=LI() ans_n=-inf ans_pair=[0,0] z=100*e/(100+e) # print(z) for i in range(31): for j in range(31): for k in range(3001): for l in range(3001): _a=a*i*100+b*j*100 _b=k*c+l*d if _a+_b>f: break if _a+_b==0: break y=100*_b/(_a+_b) if y<=z: if ans_n<=y: ans_n=y ans_pair=[_a+_b,_b] return str(ans_pair[0])+' '+str(ans_pair[1]) # main() print(main())
s239539795
p04044
u893931781
2,000
262,144
Wrong Answer
17
3,060
150
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N,L=map(int,input().split()) s=[] for i in range(N): s.append(input()) s.sort() print(s) result="" for i in range(N): result+=s[i] print(result)
s218139386
Accepted
17
3,060
142
N,L=map(int,input().split()) s=[] for i in range(N): s.append(input()) s.sort() result="" for i in range(N): result+=s[i] print(result)
s516466661
p00015
u058433718
1,000
131,072
Wrong Answer
20
7,740
286
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
import sys def main(): n = int(sys.stdin.readline().strip()) for _ in range(n): x = int(sys.stdin.readline().strip()) y = int(sys.stdin.readline().strip()) print(x + y) if __name__ == '__main__': main()
s843142556
Accepted
20
7,660
487
import sys def main(): n = int(sys.stdin.readline().strip()) for _ in range(n): x = sys.stdin.readline().strip() y = sys.stdin.readline().strip() if len(x) > 80 or len(y) > 80: print('overflow') else: ans = int(x) + int(y) if len(str(ans)) > 80: print('overflow') else: print(ans) if __name__ == '__main__': main()
s692040234
p03140
u077337864
2,000
1,048,576
Wrong Answer
17
3,060
232
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
n = int(input()) a = input().strip() b = input().strip() c = input().strip() ans = 0 for _a, _b, _c in zip(a, b, c): if _a != _b and _b != _c: ans += 2 elif _a == _b and _b == _c: continue else: ans += 1 print(ans)
s275874011
Accepted
17
3,064
245
n = int(input()) a = input().strip() b = input().strip() c = input().strip() ans = 0 for _a, _b, _c in zip(a, b, c): if _a != _b and _b != _c and _a != _c: ans += 2 elif _a == _b and _b == _c: continue else: ans += 1 print(ans)
s487705287
p03814
u405256066
2,000
262,144
Wrong Answer
62
3,516
204
Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`.
from sys import stdin s = (stdin.readline().rstrip()) A = 10**9 Z = -10**9 for ind,i in enumerate(s): if i == "A" and ind < A: A = ind if i == "Z" and ind > Z: A = ind print(Z-A+1)
s591673289
Accepted
59
3,500
204
from sys import stdin s = (stdin.readline().rstrip()) A = 10**9 Z = -10**9 for ind,i in enumerate(s): if i == "A" and ind < A: A = ind if i == "Z" and ind > Z: Z = ind print(Z-A+1)
s736531549
p02612
u396210538
2,000
1,048,576
Wrong Answer
31
9,084
189
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
from sys import stdin import sys import math # A, B, C = [int(x) for x in stdin.readline().rstrip().split()] # A = list(map(int, input().split())) s = int(input()) print(s-(s//1000)*1000)
s532848173
Accepted
24
9,148
241
from sys import stdin import sys import math # A, B, C = [int(x) for x in stdin.readline().rstrip().split()] # A = list(map(int, input().split())) s = int(input()) if s % 1000 == 0: print('0') sys.exit() print(((s//1000)+1)*1000-s)
s756439126
p03067
u743164083
2,000
1,048,576
Wrong Answer
18
2,940
111
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
*s, t = map(int, input().split()) s.sort() for i in range(s[0],s[1]): if i == t: print("Yes") print("No")
s188868289
Accepted
17
2,940
142
*s, t = map(int, input().split()) s.sort() f = False for i in range(s[0],s[1]+1): if i == t: f = True print("Yes") if f else print("No")
s799209047
p03556
u488178971
2,000
262,144
Wrong Answer
19
3,060
45
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.
N = int(input()) n = (N**0.5) //1 print(n**2)
s584613913
Accepted
18
3,060
45
N = int(input()) n = int(N**0.5) print(n**2)
s269428549
p03624
u968649733
2,000
262,144
Wrong Answer
45
4,404
245
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
S = input() S = sorted(S) S_dict = {} cnt = 0 for s in S: if s not in S_dict: S_dict[s] = 1 print(S_dict) ALL = 'abcdefghijklmnopqrstuvwxyz' answer= None for c in ALL: if c not in S_dict: answer = c break print(answer)
s189489713
Accepted
79
4,408
352
S = input() S = sorted(S) S_dict = {} cnt = 0 #ord : return number of character based on character #chr : return character based on number of character for i in range(ord("a"), ord("z") +1): S_dict[i] = S.count(chr(i)) #print(S_dict) ans =None for i in range(ord("a"), ord("z") +1): if S_dict[i] == 0: ans = chr(i) break print(ans)
s084629762
p03386
u279493135
2,000
262,144
Wrong Answer
17
3,064
235
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
import sys A, B, K = map(int, input().split()) if B-A+1 <= K: for i in range(A, B+1): print(i) sys.exit() ans = set() for i in range(A, A+K): ans.add(i) for i in range(B, B-K, -1): ans.add(i) for x in ans: print(x)
s243751316
Accepted
17
3,064
243
import sys A, B, K = map(int, input().split()) if B-A+1 <= K: for i in range(A, B+1): print(i) sys.exit() ans = set() for i in range(A, A+K): ans.add(i) for i in range(B, B-K, -1): ans.add(i) for x in sorted(ans): print(x)
s353618654
p02646
u401810884
2,000
1,048,576
Wrong Answer
24
9,196
300
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if (V-W)<=0: print ("NO") exit(0) if A > B: if (A-B) // (V-W) <= T: print("YES") else: print("NO") else: if (B-A) // (V-W) <= T: print("YEs") else: print("NO")
s637811266
Accepted
21
9,200
298
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) if (V-W)<=0: print ("NO") exit(0) if A > B: if (A-B) / (V-W) <= T: print("YES") else: print("NO") else: if (B-A) / (V-W) <= T: print("YES") else: print("NO")
s838497838
p03964
u179169725
2,000
262,144
Wrong Answer
20
3,060
186
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
N=int(input()) ans=1 def retsmlst(s,n): tmp=s while s+tmp<n: tmp+=s return tmp for _ in range(N): a,b=map(int,input().split()) s=a+b ans=retsmlst(s,ans) print(ans)
s814021294
Accepted
21
3,060
882
N = int(input()) ans = 1 def ret_nm(t, a, n, m): times_t = (n - 1) // t + 1 times_a = (m - 1) // a + 1 times = max(times_t, times_a) return times * t, times * a n = m = 1 for _ in range(N): t, a = map(int, input().split()) n, m = ret_nm(t, a, n, m) print(n + m)
s062869810
p03846
u943004959
2,000
262,144
Wrong Answer
95
16,480
1,240
There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i. Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.
from collections import Counter def solve(): while 1: try: N = int(input()) A = list(map(int, input().split(" "))) MOD = 10 ** 9 + 7 counter = Counter(A) checker = [0 for _ in range(N)] for word, cnt in counter.most_common(): if word > N - 1 or cnt > 2: raise EndLoop else: checker[word] = cnt if N % 2 == 0: for i in range(N): if not i % 2 and checker[i] != 0: raise EndLoop elif i % 2 and checker[i] != 2: raise EndLoop print(((N // 2) ** 2) % MOD) break else: for i in range(N): if i == 0 and checker[i] != 1: raise EndLoop elif not i % 2 and checker[i] != 2: raise EndLoop elif i % 2 and i != 0 and checker[i] != 0: raise EndLoop print((((N - 1) // 2) ** 2) % MOD) break except: print(0) break solve()
s652150420
Accepted
98
16,480
1,283
#!/usr/bin/python # -*- coding: utf-8 -*- from collections import Counter def solve(): while 1: try: N = int(input()) A = list(map(int, input().split(" "))) MOD = 10 ** 9 + 7 counter = Counter(A) checker = [0 for _ in range(N)] for word, cnt in counter.most_common(): if word > N - 1 or cnt > 2: raise EndLoop else: checker[word] = cnt if N % 2 == 0: for i in range(N): if not i % 2 and checker[i] != 0: raise EndLoop elif i % 2 and checker[i] != 2: raise EndLoop print((2 ** (N // 2)) % MOD) break else: for i in range(N): if i == 0 and checker[i] != 1: raise EndLoop elif not i % 2 and i != 0and checker[i] != 2: raise EndLoop elif i % 2 and checker[i] != 0: raise EndLoop print(((2 ** ((N - 1) // 2)) % MOD)) break except: print(0) break solve()
s058444490
p02612
u371409687
2,000
1,048,576
Wrong Answer
30
9,144
24
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
print(int(input())%1000)
s031567983
Accepted
33
9,144
40
n=int(input()) print(-(-n//1000)*1000-n)
s028725715
p02927
u527261492
2,000
1,048,576
Wrong Answer
19
2,940
153
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
m,d=map(int,input().split()) cnt=0 for j in range(1,m+1): for i in range(1,d+1): a=i//10 b=i%10 if a*b==j: cnt+=1 print(cnt)
s061542317
Accepted
19
2,940
177
m,d=map(int,input().split()) cnt=0 for j in range(1,m+1): for i in range(1,d+1): a=i//10 b=i%10 if a>1 and b>1: if a*b==j: cnt+=1 print(cnt)
s415345184
p03854
u314089899
2,000
262,144
Wrong Answer
63
3,740
978
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
#49c S = str(input()) i = len(S) - 5 if i < 0: print("NO") else: while i >= 0: end_5_char = S[i:i+5] print(i,end_5_char) if end_5_char == "eamer": print(i,S[i-2:i]) if i < 2 or S[i-2:i] != "dr": print("NO") break else: i -= 2 elif end_5_char == "raser": print(i,S[i-1:i]) if i < 1 or S[i-1:i] != "e": print("NO") break else: i -= 1 elif end_5_char != "dream" and end_5_char != "erase": print("NO") break i -= 5 else: print("OK")
s877835051
Accepted
28
3,188
982
#49c S = str(input()) i = len(S) - 5 if i < 0: print("NO") else: while i >= 0: end_5_char = S[i:i+5] #print(i,end_5_char) if end_5_char == "eamer": #print(i,S[i-2:i]) if i < 2 or S[i-2:i] != "dr": print("NO") break else: i -= 2 elif end_5_char == "raser": #print(i,S[i-1:i]) if i < 1 or S[i-1:i] != "e": print("NO") break else: i -= 1 elif end_5_char != "dream" and end_5_char != "erase": print("NO") break i -= 5 else: print("YES")
s970278349
p03576
u802963389
2,000
262,144
Wrong Answer
1,258
3,320
2,253
We have N points in a two-dimensional plane. The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i). Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior. Here, points on the sides of the rectangle are considered to be in the interior. Find the minimum possible area of such a rectangle.
n, k = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(n)] XY.sort(key=lambda x: x[0]) XY = [xy + [x] for x, xy in enumerate(XY)] XY.sort(key=lambda x: x[1]) XY = [xy + [y] for y, xy in enumerate(XY)] gr = [[0] * n for _ in range(n)] for _, _, i, j in XY: gr[i][j] = 1 rui = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n): for j in range(n): rui[i + 1][j + 1] = rui[i + 1][j] + rui[i][j + 1] - rui[i][j] + gr[i][j] ans = 10 ** 19 for i in range(n - 1): for j in range(i + 1, n): x = [XY[i][0] for i in range(2)] y = [XY[i][1] for i in range(2)] ii = [XY[i][2] for i in range(2)] jj = [XY[i][3] for i in range(2)] innerPoints = rui[max(ii)+1][max(jj)+1] \ + rui[min(ii)][min(jj)] \ - rui[min(ii)][max(jj)] \ - rui[max(ii)][min(jj)] if innerPoints >= k: area = (max(x) - min(x)) * (max(y) - min(y)) if area < ans: ans = area if n > 2: for i in range(n - 2): for j in range(i + 1, n - 1): for k in range(j + 1, n): x = [XY[i][0] for i in range(3)] y = [XY[i][1] for i in range(3)] ii = [XY[i][2] for i in range(3)] jj = [XY[i][3] for i in range(3)] innerPoints = rui[max(ii)+1][max(jj)+1] \ + rui[min(ii)][min(jj)] \ - rui[min(ii)][max(jj)] \ - rui[max(ii)][min(jj)] if innerPoints >= k: area = (max(x) - min(x)) * (max(y) - min(y)) if area < ans: ans = area if n > 3: for i in range(n - 3): for j in range(i + 1, n - 2): for k in range(j + 1, n - 1): for l in range(k + 1, n): x = [XY[i][0] for i in range(4)] y = [XY[i][1] for i in range(4)] ii = [XY[i][2] for i in range(4)] jj = [XY[i][3] for i in range(4)] innerPoints = rui[max(ii)+1][max(jj)+1] \ + rui[min(ii)][min(jj)] \ - rui[min(ii)][max(jj)] \ - rui[max(ii)][min(jj)] if innerPoints >= k: area = (max(x) - min(x)) * (max(y) - min(y)) if area < ans: ans = area print(ans)
s343353346
Accepted
1,438
3,320
2,307
n, k = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(n)] XY.sort(key=lambda x: x[0]) XY = [xy + [x] for x, xy in enumerate(XY)] XY.sort(key=lambda x: x[1]) XY = [xy + [y] for y, xy in enumerate(XY)] gr = [[0] * n for _ in range(n)] for _, _, i, j in XY: gr[i][j] = 1 rui = [[0] * (n + 1) for _ in range(n + 1)] for i in range(n): for j in range(n): rui[i + 1][j + 1] = rui[i + 1][j] + rui[i][j + 1] - rui[i][j] + gr[i][j] ans = 10 ** 21 for i in range(n - 1): for j in range(i + 1, n): x = [XY[m][0] for m in [i, j]] y = [XY[m][1] for m in [i, j]] ii = [XY[m][2] for m in [i, j]] jj = [XY[m][3] for m in [i, j]] innerPoints = rui[max(ii) + 1][max(jj) + 1] \ + rui[min(ii)][min(jj)] \ - rui[min(ii)][max(jj) + 1] \ - rui[max(ii) + 1][min(jj)] if innerPoints >= k: area = (max(x) - min(x)) * (max(y) - min(y)) if area < ans: ans = area if n > 2: for i in range(n - 2): for j in range(i + 1, n - 1): for l in range(j + 1, n): x = [XY[m][0] for m in [i, j, l]] y = [XY[m][1] for m in [i, j, l]] ii = [XY[m][2] for m in [i, j, l]] jj = [XY[m][3] for m in [i, j, l]] innerPoints = rui[max(ii) + 1][max(jj) + 1] \ + rui[min(ii)][min(jj)] \ - rui[min(ii)][max(jj) + 1] \ - rui[max(ii) + 1][min(jj)] if innerPoints >= k: area = (max(x) - min(x)) * (max(y) - min(y)) if area < ans: ans = area if n > 3: for i in range(n - 3): for j in range(i + 1, n - 2): for l in range(j + 1, n - 1): for o in range(l + 1, n): x = [XY[m][0] for m in [i, j, o, l]] y = [XY[m][1] for m in [i, j, o, l]] ii = [XY[m][2] for m in [i, j, o, l]] jj = [XY[m][3] for m in [i, j, o, l]] innerPoints = rui[max(ii) + 1][max(jj) + 1] \ + rui[min(ii)][min(jj)] \ - rui[min(ii)][max(jj) + 1] \ - rui[max(ii) + 1][min(jj)] if innerPoints >= k: area = (max(x) - min(x)) * (max(y) - min(y)) if area < ans: ans = area print(ans)
s333245903
p03456
u940652437
2,000
262,144
Wrong Answer
23
9,040
141
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
import math a,b=input().split() c = a + b n_c = int(c) if math.sqrt(n_c).is_integer == True : print("Yes") else: print("No")
s100314176
Accepted
32
9,452
136
import math a,b=input().split() c = a + b n_c = int(c) if((n_c ** 0.5).is_integer()==True): print("Yes") else: print('No')
s850316930
p03339
u839188633
2,000
1,048,576
Wrong Answer
2,104
3,676
199
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.
n = int(input()) s = input() ans = n for i in range(0, n): kaeru = sum(s[j] == 'W' for j in range(i)) + sum(s[j] == 'E' for j in range(i+1,n)) print(kaeru) ans = min(kaeru, ans) print(ans)
s363402571
Accepted
296
27,128
233
n = int(input()) s = input() w = [0] * n for i in range(n-1): w[i+1] = w[i] + int(s[i] == 'W') e = [0] * n for i in reversed(range(1, n)): e[i-1] = e[i] + int(s[i] == 'E') print(min(ww+ee for ww, ee in zip(w, e)))
s598434972
p02241
u370086573
1,000
131,072
Wrong Answer
30
7,644
998
For a given weighted graph $G = (V, E)$, find the minimum spanning tree (MST) of $G$ and print total weight of edges belong to the MST.
INF = 9999 def prim(G): n = len(G) color = ['White' for _ in range(n)] d = [INF for _ in range(n)] p = [-1 for _ in range(n)] d[0] = 0 while True: mincost = INF u = -1 for i in range(n): if color[i] != 'Black' and d[i] < mincost: mincost = d[i] u = i if u == -1: break color[u] = 'Black' for v in range(n): if color[v] != 'Black' and G[u][v] != INF: if G[u][v] < d[v]: d[v] = G[u][v] p[v] = u color[u] = 'Gray' sum = 0 for i in range(n): if p[i] != -1: sum += G[i][p[i]] return sum if __name__ == '__main__': n = int(input()) GL = [list(map(int, input().split())) for _ in range(n)] for i in range(n): for j in range(n): if GL[i][j] == -1: GL[i][j] = INF print(prim(GL))
s155295131
Accepted
40
7,860
728
INF = 9999 def prim(M): n = len(M) color = [0] * n d = [INF] * n d[0] = 0 while True: minv = INF u = -1 for i in range(n): # Black:2 if minv > d[i] and color[i] != 2: u = i minv = d[i] if u == -1: break color[u] = 2 for v in range(n): if color[v] != 2 and M[u][v] != INF: if d[v] > M[u][v]: d[v] = M[u][v] return sum(d) if __name__ == '__main__': n = int(input()) A = [] for i in range(n): src = input() dst = src.replace('-1', str(INF)) ai = list(map(int, dst.split())) A.append(ai) print(prim(A))
s102823781
p03471
u222841610
2,000
262,144
Wrong Answer
2,104
3,064
725
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n,y = list(map(int,input().split())) if y/10000 > n: print('-1 -1 -1') else: b = False YY =[] Y10=1+int(y/10000) Y5 =1+int((y%10000)/5000) Y1 =1+int((y%5000)/1000) for i in range(Y10): if b== True: break if i <= n: YY.append(i) for j in range(Y5+2*i): if b == True: break if i+j <= n: YY.append(j) for k in range(Y1 +5*j): if i+j+k <= n and i*10000+j*5000+k*1000 ==y: YY = [i,j,k] print('%d %d %d' % (YY[0], YY[1], YY[2])) b = True break else: YY=[]
s714959217
Accepted
1,110
3,064
700
n,y = list(map(int,input().split())) if y/10000 > n: print('-1 -1 -1') if y/10000 ==n: print('%d %d %d' % (y/10000, 0, 0)) else: b = False YY =[] Y10=int(y/10000) Y5 =int(y/5000) Y1 =int(y/1000) for i in range(Y10,-1,-1): if b== True or i > n: break for j in range(Y5+1-2*i): if b == True or i+j > n: break k = n - i - j if i*10000+j*5000+k*1000 ==y: YY = [i,j,k] print('%d %d %d' % (YY[0], YY[1], YY[2])) b = True break else: YY=[] if i == 0 and b == False: print('-1 -1 -1')
s324283617
p02747
u165200006
2,000
1,048,576
Wrong Answer
17
2,940
76
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 = s.replace("hi", "") if s: print("Yes") else: print("No")
s802898137
Accepted
17
2,940
83
s = input() s = s.replace("hi", "") if s == "": print("Yes") else: print("No")
s732544845
p03738
u018679195
2,000
262,144
Wrong Answer
17
2,940
104
You are given two positive integers A and B. Compare the magnitudes of these numbers.
a=int(input()) b=int(input()) if a>b: print("GRATER") elif a<b: print("LESS") else: print("EQUAL")
s360508245
Accepted
17
3,064
134
A = int(input()) B = int(input()) if (A > B): print("GREATER") elif (A < B): print("LESS") elif (A == B): print("EQUAL")
s376256678
p02600
u679817762
2,000
1,048,576
Wrong Answer
32
9,208
277
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
X = int(input()) lst = [ [400, 599, 8], [600, 799, 7], [800, 999, 6], [1000, 1199, 5], [1200, 1399, 4], [1400, 1599, 3], [1600, 1799, 2], [1800, 1999, 1] ] def Kyu(X): for i in lst: if i[0] <= X <= i[1]: result = i[2] break print(result)
s734959959
Accepted
26
9,192
281
X = int(input()) lst = [ [400, 599, 8], [600, 799, 7], [800, 999, 6], [1000, 1199, 5], [1200, 1399, 4], [1400, 1599, 3], [1600, 1799, 2], [1800, 1999, 1] ] def Kyu(X): for i in lst: if i[0] <= X <= i[1]: result = i[2] break print(result) Kyu(X)
s313506002
p02612
u432453907
2,000
1,048,576
Wrong Answer
31
9,152
42
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) ans = n % 1000 print(ans)
s942050105
Accepted
29
9,156
74
n = int(input()) ans = n % 1000 if ans != 0: ans = 1000-ans print(ans)
s050976971
p02432
u682153677
2,000
262,144
Wrong Answer
30
6,000
486
For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print element $a_p$. * pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state.
# -*- coding: utf-8 -*- from collections import deque n = int(input()) word = deque() for i in range(n): command = list(map(int, input().split())) if command[0] == 0: if command[1] == 0: word.insert(0, command[1]) else: word.append(command[1]) elif command[0] == 1: print('{0}'.format(word[command[1]])) elif command[0] == 2: if command[1] == 0: word.pop() else: word.popleft()
s615301838
Accepted
1,710
21,984
486
# -*- coding: utf-8 -*- from collections import deque n = int(input()) word = deque() for i in range(n): command = list(map(int, input().split())) if command[0] == 0: if command[1] == 0: word.insert(0, command[2]) else: word.append(command[2]) elif command[0] == 1: print('{0}'.format(word[command[1]])) elif command[0] == 2: if command[1] == 1: word.pop() else: word.popleft()
s481116635
p02255
u046107993
1,000
131,072
Wrong Answer
30
7,592
399
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
#!/usr/bin/env python size = int(input()) line = list(map(int, input().split())) def insertionSort(A, N): for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v def main(): insertionSort(line, size) ans = " ".join(map(str, line)) print(ans) if __name__ == '__main__': main()
s241480392
Accepted
30
7,752
456
#!/usr/bin/env python size = int(input()) line = list(map(int, input().split())) def insertionSort(A, N): ans = " ".join(map(str, line)) print(ans) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v ans = " ".join(map(str, line)) print(ans) def main(): insertionSort(line, size) if __name__ == '__main__': main()
s359479898
p03361
u252883287
2,000
262,144
Wrong Answer
1,550
21,480
1,196
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.
import numpy as np na = np.array def ii(): return int(input()) def lii(): return list(map(int, input().split(' '))) def lvi(N): l = [] for _ in range(N): l.append(ii()) return l def lv(N): l = [] for _ in range(N): l.append(input()) return l def yn(b): if b: print('yes') else: print('no') def is_prime(q): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False return pow(2, q-1, q) == 1 def ok(S, i, j): try: if S[i+1][j] == '#': return True except: pass try: if S[i-1][j] == '#': return True except: pass try: if S[i][j+1] == '#': return True except: pass try: if S[i][j-1] == '#': return True except: pass return False def C(): H, W = lii() S = [] for _ in range(H): S.append(input()) for i, l in enumerate(S): for j in range(len(l)): if S[i][j] == '#': if not ok(S, i, j): return False return True if __name__ == '__main__': yn(C())
s244631356
Accepted
1,240
21,544
1,196
import numpy as np na = np.array def ii(): return int(input()) def lii(): return list(map(int, input().split(' '))) def lvi(N): l = [] for _ in range(N): l.append(ii()) return l def lv(N): l = [] for _ in range(N): l.append(input()) return l def yn(b): if b: print('Yes') else: print('No') def is_prime(q): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False return pow(2, q-1, q) == 1 def ok(S, i, j): try: if S[i+1][j] == '#': return True except: pass try: if S[i-1][j] == '#': return True except: pass try: if S[i][j+1] == '#': return True except: pass try: if S[i][j-1] == '#': return True except: pass return False def C(): H, W = lii() S = [] for _ in range(H): S.append(input()) for i, l in enumerate(S): for j in range(len(l)): if S[i][j] == '#': if not ok(S, i, j): return False return True if __name__ == '__main__': yn(C())
s856255810
p03494
u497326082
2,000
262,144
Wrong Answer
18
3,060
190
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n=int(input()) p=list(map(int,input().split())) p_=[] b=True c=0 while b: p_=list(map(lambda in_:type(in_)=="int",p)) b = "False" in p_ p_=list(map(lambda in_:in_/2,p)) c+=1 print(c)
s623752836
Accepted
19
3,060
185
n=int(input()) a=list(map(int,input().split())) ans=0 flg=0 while flg==0: for i in a: if i%2 != 0: flg=1 a=list(map(lambda x: x/2,a)) ans+=1 print(ans-1)
s679299113
p02261
u023863700
1,000
131,072
Wrong Answer
40
6,344
519
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
import copy n=int(input()) num=input().split() numa=copy.copy(num) numb=copy.copy(num) #buble for i in range(0,n): a=0 for j in range(n-1,i,-1): if numa[j]<numa[j-1]: a=numa[j] numa[j]=numa[j-1] numa[j-1]=a print(' '.join(list(map(str,numa)))) print('Stable') #select for i in range(0,n): minj=i b=0 for j in range(i,n): if numb[j]<numb[minj]: minj=j b=numb[minj] numb[minj]=numb[i] numb[i]=b print(' '.join(list(map(str,numb)))) if numb==numa: print('Stable') else: print('Not stable')
s721404229
Accepted
30
6,344
535
import copy n=int(input()) num=input().split() numa=copy.copy(num) numb=copy.copy(num) #buble for i in range(0,n): a=0 for j in range(n-1,i,-1): if numa[j][1:]<numa[j-1][1:]: a=numa[j] numa[j]=numa[j-1] numa[j-1]=a print(' '.join(list(map(str,numa)))) print('Stable') #select for i in range(0,n): minj=i b=0 for j in range(i,n): if numb[j][1:]<numb[minj][1:]: minj=j b=numb[minj] numb[minj]=numb[i] numb[i]=b print(' '.join(list(map(str,numb)))) if numb==numa: print('Stable') else: print('Not stable')
s391246324
p03624
u131634965
2,000
262,144
Wrong Answer
19
3,188
249
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.
alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] s=input() s_list=sorted(set(s)) print(s_list) for x, y in zip(s_list, alpha): if x!=y: print(y) exit() print("None")
s639145987
Accepted
18
3,188
251
#alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] alpha= list("abcdefghijklmnopqrstuvwxyz") s=input() for x in alpha: if x not in s: print(x) exit() print("None")
s545573461
p00008
u073709667
1,000
131,072
Wrong Answer
30
7,652
218
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
num=int(input()) sum=0 Range=10 for a in range(Range): for b in range(Range): for c in range(Range): for d in range(Range): if num==a+b+c+d: sum+=1 print(sum)
s308744670
Accepted
200
7,552
309
while True: try: num=int(input()) except: break sum=0 Range=10 for a in range(Range): for b in range(Range): for c in range(Range): for d in range(Range): if num==a+b+c+d: sum+=1 print(sum)
s697587686
p02612
u218834617
2,000
1,048,576
Wrong Answer
28
9,028
48
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
import sys n=int(next(sys.stdin)) print(n%1000)
s044174304
Accepted
27
9,008
62
import sys n=int(next(sys.stdin)) print((n+999)//1000*1000-n)
s102886565
p03007
u907223098
2,000
1,048,576
Wrong Answer
2,104
14,264
233
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
n=int(input()) a=[] r=0 for i in input().split(): a.append(int(i)) a.sort() for i in range(n): if i<=n//2: r=r+a[-1-i] else: r=r-a[-1-i] print(r) while len(a)>1: b=a.pop(-1) c=a.pop(0) print(b,c) a.insert(0,c-b)
s171677235
Accepted
291
22,364
251
n=int(input()) a=[] r=[] for i in input().split(): a.append(int(i)) a.sort() t=a.pop(-1) b=a.pop(0) for i in a: if i>=0: r.append([b,i]) b=b-i else: r.append([t,i]) t=t-i print(t-b) r.append([t,b]) for i in r: print(i[0],i[1])
s722433092
p03693
u920103253
2,000
262,144
Wrong Answer
17
2,940
109
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r,g,b = [int(x) for x in input().split()] if (r*100+g*10+b) % 4 == 0: print("Yes") else: print("No")
s023785153
Accepted
17
2,940
109
r,g,b = [int(x) for x in input().split()] if (r*100+g*10+b) % 4 == 0: print("YES") else: print("NO")
s989602771
p02854
u111392182
2,000
1,048,576
Wrong Answer
2,104
26,220
166
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
n = int(input()) a = list(map(int,input().split())) l = 0 r = 0 ans = 0 for i in a: l += i r = sum(a)-l if l==r: break; elif l>r: ans = l-r print(ans)
s724360670
Accepted
109
26,396
216
n = int(input()) a = list(map(int,input().split())) b = sum(a) l = 0 r = 0 x = 0 ans = 0 for i in a: l += i r = b - l if l==r: break; elif l>r: ans = min(l-r,y-x) break; x = l y = r print(ans)
s982049783
p03251
u099918199
2,000
1,048,576
Wrong Answer
17
3,060
213
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
n,m,x,y = map(int, input().split()) x_list = list(map(int, input().split())) y_list = list(map(int, input().split())) x_list.sort() y_list.sort() if x_list[-1]+1 < y_list[0]: print("No War") else: print("War")
s922604676
Accepted
17
3,060
281
n,m,x,y = map(int, input().split()) x_list = list(map(int, input().split())) y_list = list(map(int, input().split())) x_list.sort() y_list.sort() if x_list[-1] < y_list[0]: if (y_list[0] > x) and (x_list[-1] < y): print("No War") else: print("War") else: print("War")
s319193136
p02612
u969133463
2,000
1,048,576
Wrong Answer
29
9,152
31
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
a = int(input()) print(a%1000)
s988865002
Accepted
27
8,968
76
a = int(input()) b = a%1000 if(b > 0): print(1000-b) else: print(b)
s461975616
p02386
u179070318
1,000
131,072
Wrong Answer
20
5,656
1,046
Write a program which reads $n$ dices constructed in the same way as [Dice I](description.jsp?id=ITP1_11_A), and determines whether they are all different. For the determination, use the same way as [Dice III](description.jsp?id=ITP1_11_C).
import itertools class dice(): def __init__(self,number): self.number = number def korokoro(self,com): if com == 'E': self.number = [self.number[i] for i in [3,1,0,5,4,2]] if com == 'S': self.number = [self.number[i] for i in [4,0,2,3,5,1]] if com == 'N': self.number = [self.number[i] for i in [1,5,2,3,0,4]] if com == 'W': self.number = [self.number[i] for i in [2,1,5,0,4,3]] def checker(d1,d2): for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE': d1.korokoro(com) if d1.number == d2.number: ans = 'Yes' break else: ans = 'No' return ans n = int(input()) saikoro = {} for _ in range(n): saikoro[_] = dice([int(x) for x in input().split()]) l = list(itertools.combinations(saikoro.keys(),2)) for __ in l: test1 = saikoro[__[0]] test2 = saikoro[__[1]] if checker(test1,test2) == 'Yes': answer = 'Yes' break else: anser = 'No' print(answer)
s071088923
Accepted
210
5,996
1,048
import itertools class dice(): def __init__(self,number): self.number = number def korokoro(self,com): if com == 'E': self.number = [self.number[i] for i in [3,1,0,5,4,2]] if com == 'S': self.number = [self.number[i] for i in [4,0,2,3,5,1]] if com == 'N': self.number = [self.number[i] for i in [1,5,2,3,0,4]] if com == 'W': self.number = [self.number[i] for i in [2,1,5,0,4,3]] def checker(d1,d2): for com in 'EEEENEEEENEEEENEEEENWSEEEENNEEEE': d1.korokoro(com) if d1.number == d2.number: ans = 'Yes' break else: ans = 'No' return ans n = int(input()) saikoro = {} for _ in range(n): saikoro[_] = dice([int(x) for x in input().split()]) l = list(itertools.combinations(saikoro.keys(),2)) for __ in l: test1 = saikoro[__[0]] test2 = saikoro[__[1]] if checker(test1,test2) == 'Yes': answer = 'No' break else: answer = 'Yes' print(answer)
s873822335
p03730
u880466014
2,000
262,144
Wrong Answer
18
2,940
136
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
import sys a, b, c = map(int, input().split()) for i in range(1, b+1): if (a*i) % b == c: print('Yes') sys.exit() print('No')
s639433802
Accepted
18
2,940
135
import sys a, b, c = map(int, input().split()) for i in range(1, b+1): if a*i % b == c: print('YES') sys.exit() print('NO')
s394499838
p03433
u137443009
2,000
262,144
Wrong Answer
17
2,940
112
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()) #price A = int(input()) #number of coins if N%500 <= A: print('YES') else: print('NO')
s750567305
Accepted
17
2,940
88
N = int(input()) A = int(input()) if N%500 <= A: print('Yes') else: print('No')
s484460601
p03399
u777607830
2,000
262,144
Wrong Answer
17
3,060
190
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
A = int(input()) B = int(input()) C = int(input()) D = int(input()) 1 <= A <= 1000 1 <= B <= 1000 1 <= C <= 1000 1 <= D <= 1000 l = [A, B] m = [C, D] #print(max(l)) print(min(l)*min(m))
s321035995
Accepted
17
2,940
133
A = int(input()) B = int(input()) C = int(input()) D = int(input()) l = [A, B] m = [C, D] #print(max(l)) print(min(l) + min(m))
s866328968
p03543
u667024514
2,000
262,144
Wrong Answer
17
2,940
123
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**?
a=input() A=a[0] b=[1] c=[2] d=[3] if A==b and b==c: print("Yes") elif b==c and c==d: print("Yes") else: print("No")
s125158699
Accepted
17
3,060
125
a=input() A=a[0] b=a[1] c=a[2] d=a[3] if A==b and b==c: print("Yes") elif b==c and c==d: print("Yes") else: print("No")
s928432647
p04043
u203886313
2,000
262,144
Wrong Answer
17
2,940
110
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(int, input().split()); if a == 5 and b == 7 and c == 5: print("YES"); else: print("NO")
s371665105
Accepted
17
3,060
259
abc = list(map(int, input().split())); five, seven = 0, 0; for i in range(3): if abc[i] == 5: five += 1; elif abc[i] == 7: seven += 1; else: continue; if five == 2 and seven == 1: print("YES"); else: print("NO");
s356255667
p02390
u929141425
1,000
131,072
Wrong Answer
20
5,580
106
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
a = int(input(">>")) h = a//3600 m = (a%3600)//60 s = (a%3600) - m*60 print(str(h)+":"+str(m)+":"+str(s))
s438224520
Accepted
20
5,588
112
S =int(input()) h = S//3600 m = (S%3600)//60 s = S - h*3600 - m*60 print(str(h) + ":" + str(m) + ":"+ str(s))
s782977292
p03548
u729119068
2,000
262,144
Wrong Answer
28
9,012
53
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
a,b,c=map(int, input().split()) print((a-b-2*c)//2+1)
s598147556
Accepted
27
9,160
57
a,b,c=map(int, input().split()) print((a-b-2*c)//(b+c)+1)
s744581404
p03695
u243492642
2,000
262,144
Wrong Answer
310
5,352
1,136
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
# coding: utf-8 import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def IAI(LINE): return [ILI() for __ in range(LINE)] def IDI(): return {key: value for key, value in ILI()} def read(): N = II() a = ILI() return (N, a) def solve(N, a): count = [0] * 9 for ele in a: if 1 <= ele <= 399: count[0] = 1 elif 400 <= ele <= 799: count[1] = 1 elif 800 <= ele <= 1199: count[2] = 1 elif 1200 <= ele <= 1599: count[3] = 1 elif 1600 <= ele <= 1999: count[4] = 1 elif 2000 <= ele <= 2399: count[5] = 1 elif 2400 <= ele <= 2799: count[6] = 1 elif 2800 <= ele <= 3199: count[7] = 1 elif ele >= 3200: count[8] += 1 ans = sum(count) return ans def main(): params = read() print(solve(*params)) if __name__ == "__main__": main()
s818164653
Accepted
55
6,252
1,323
# coding: utf-8 import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time sys.setrecursionlimit(10 ** 7) INF = 10 ** 20 MOD = 10 ** 9 + 7 def II(): return int(input()) def ILI(): return list(map(int, input().split())) def IAI(LINE): return [ILI() for __ in range(LINE)] def IDI(): return {key: value for key, value in ILI()} def read(): N = II() a = ILI() return (N, a) def solve(N, a): count = [0] * 9 for ele in a: if 1 <= ele <= 399: count[0] = 1 elif 400 <= ele <= 799: count[1] = 1 elif 800 <= ele <= 1199: count[2] = 1 elif 1200 <= ele <= 1599: count[3] = 1 elif 1600 <= ele <= 1999: count[4] = 1 elif 2000 <= ele <= 2399: count[5] = 1 elif 2400 <= ele <= 2799: count[6] = 1 elif 2800 <= ele <= 3199: count[7] = 1 elif ele >= 3200: count[8] += 1 num_else = sum(count[0: 8]) ans_max = sum(count) if num_else == 0: ans_min = 1 else: ans_min = num_else ans = (ans_min, ans_max) return ans def main(): params = read() ans = solve(*params) print("{} {}".format(ans[0], ans[1])) if __name__ == "__main__": main()
s323761904
p03943
u039623862
2,000
262,144
Wrong Answer
17
2,940
74
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.
c = map(int, input().split()) print('Yes' if max(c)*2 == sum(c) else 'No')
s456489665
Accepted
17
2,940
80
c = list(map(int, input().split())) print('Yes' if max(c)*2 == sum(c) else 'No')
s732247054
p03567
u366886346
2,000
262,144
Wrong Answer
17
2,940
140
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
s=input() yn=0 for i in range(len(s)-1): if s[i:i+1]=="AC": yn=1 break if yn==1: print("Yes") else: print("No")
s851762479
Accepted
17
2,940
140
s=input() yn=0 for i in range(len(s)-1): if s[i:i+2]=="AC": yn=1 break if yn==1: print("Yes") else: print("No")
s939617720
p03545
u544034775
2,000
262,144
Wrong Answer
17
3,064
762
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() ls = [int(i) for i in s] n = len(ls) i = 1 ans = ls[0] def dfs(i, s, ans): if i==n: print(i, 'floor', s, ans) return ans==7, s, ans else: #print(i, 'left', s, ans) p = i + s.count('+') + s.count('-') s_temp = s[:p]+'-'+s[p:] ans_temp = ans - ls[i] tf, s_temp, ans_temp = dfs(i+1, s_temp, ans_temp) if tf: return True, s_temp, ans_temp else: #print(i, 'right', s, ans) p = i + s.count('+') + s.count('-') s_temp = s[:p]+'+'+s[p:] ans_temp = ans + ls[i] tf, s_temp, ans_temp = dfs(i+1, s_temp, ans_temp) return tf, s_temp, ans_temp tf, s, ans = dfs(1, s, ans) print(s+'=7')
s203439670
Accepted
18
3,064
763
s = input() ls = [int(i) for i in s] n = len(ls) i = 1 ans = ls[0] def dfs(i, s, ans): if i==n: #print(i, 'floor', s, ans) return ans==7, s, ans else: #print(i, 'left', s, ans) p = i + s.count('+') + s.count('-') s_temp = s[:p]+'-'+s[p:] ans_temp = ans - ls[i] tf, s_temp, ans_temp = dfs(i+1, s_temp, ans_temp) if tf: return True, s_temp, ans_temp else: #print(i, 'right', s, ans) p = i + s.count('+') + s.count('-') s_temp = s[:p]+'+'+s[p:] ans_temp = ans + ls[i] tf, s_temp, ans_temp = dfs(i+1, s_temp, ans_temp) return tf, s_temp, ans_temp tf, s, ans = dfs(1, s, ans) print(s+'=7')
s526075035
p03007
u635182517
2,000
1,048,576
Wrong Answer
207
14,144
879
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
N = int(input()) A = list(map(int, input().split())) A.sort() MAX = A.pop(-1) ans = MAX MIN = A.pop(0) if MIN <= 0: if N == 2: ans -= MIN print("{0} {1}".format(MAX, MIN)) else: for a in A: if a > 0: print("{0} {1}".format(MIN, a)) MIN -= a else: print("{0} {1}".format(MAX, a)) MAX -= a print("{0} {1}".format(MAX, MIN)) else: if N == 2: ans -= MIN print("{0} {1}".format(MAX, MIN)) else: b = A.pop(-1) print("{0} {1}".format(MIN, b)) MIN -= b for a in A: if a > 0: print("{0} {1}".format(MIN, a)) MIN -= a else: print("{0} {1}".format(MAX, a)) MAX -= a print("{0} {1}".format(MAX, MIN))
s520221808
Accepted
215
14,260
1,421
N = int(input()) A = list(map(int, input().split())) A.sort() MAX = A.pop(-1) ans = MAX MIN = A.pop(0) MIN2 = MIN MAX2 = MAX if MIN2 <= 0: if N == 2: ans -= MIN2 else: for a in A: if a > 0: MIN2 -= a else: MAX2 -= a ans = MAX2 - MIN2 else: if N == 2: ans -= MIN2 else: b = A.pop(-1) MIN2 -= b for a in A: if a > 0: MIN2 -= a else: MAX2 -= a ans = MAX2 - MIN2 print(ans) if MIN <= 0: if N == 2: ans -= MIN print("{0} {1}".format(MAX, MIN)) else: for a in A: if a > 0: print("{0} {1}".format(MIN, a)) MIN -= a else: print("{0} {1}".format(MAX, a)) MAX -= a print("{0} {1}".format(MAX, MIN)) else: if N == 2: ans -= MIN print("{0} {1}".format(MAX, MIN)) else: print("{0} {1}".format(MIN, b)) MIN -= b for a in A: if a > 0: print("{0} {1}".format(MIN, a)) MIN -= a else: print("{0} {1}".format(MAX, a)) MAX -= a print("{0} {1}".format(MAX, MIN))
s396736459
p03067
u224226076
2,000
1,048,576
Wrong Answer
17
2,940
114
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
A,B,C = (int(i) for i in input().split()) a = min(A,B) b = max(A,B) if a<C<b: print('YES') else: print('NO')
s352860535
Accepted
17
2,940
114
A,B,C = (int(i) for i in input().split()) a = min(A,B) b = max(A,B) if a<C<b: print('Yes') else: print('No')
s024938726
p02266
u620998209
1,000
131,072
Wrong Answer
20
7,468
1,008
Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively.
def main(): sectionalview = input() stack = [] a_surface = 0 surfaces = [] for cindex in range(len(sectionalview)): if sectionalview[cindex] == "\\": stack.append(cindex) elif sectionalview[cindex] == "/" and 0 < len(stack): if 0 < len(stack): left_index = stack.pop() a = cindex - left_index a_surface += a while 0 < len(surfaces): if left_index < surfaces[-1][0]: a += surfaces.pop()[1] else: break surfaces.append((cindex, a)) print(sum([i[1] for i in surfaces])) print(" ".join(map(str, [i[1] for i in surfaces]))) if __name__ == "__main__": import os import sys if len(sys.argv) > 1: if sys.argv[1] == "-d": fd = os.open("input.txt", os.O_RDONLY) os.dup2(fd, sys.stdin.fileno()) main() else: main()
s073083544
Accepted
30
7,908
1,006
def main(): sectionalview = input() stack = [] a_surface = 0 surfaces = [] for cindex in range(len(sectionalview)): if sectionalview[cindex] == "\\": stack.append(cindex) elif sectionalview[cindex] == "/" and 0 < len(stack): if 0 < len(stack): left_index = stack.pop() a = cindex - left_index a_surface += a while 0 < len(surfaces): if left_index < surfaces[-1][0]: a += surfaces.pop()[1] else: break surfaces.append((cindex, a)) t = [i[1] for i in surfaces] print(sum(t)) print(" ".join(map(str, [len(t)] + t))) if __name__ == "__main__": import os import sys if len(sys.argv) > 1: if sys.argv[1] == "-d": fd = os.open("input.txt", os.O_RDONLY) os.dup2(fd, sys.stdin.fileno()) main() else: main()
s966673071
p03544
u982762220
2,000
262,144
Wrong Answer
20
2,940
206
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2)
N = int(input()) memo = dict() def luca(n): if n == 0: return 2 elif n == 1: return 1 if n in memo: return memo[n] tmp = luca(n-1) + luca(n-2) memo[n] = tmp return tmp print(N)
s645168991
Accepted
18
3,060
212
N = int(input()) memo = dict() def luca(n): if n == 0: return 2 elif n == 1: return 1 if n in memo: return memo[n] tmp = luca(n-1) + luca(n-2) memo[n] = tmp return tmp print(luca(N))
s305168400
p03579
u033606236
2,000
262,144
Wrong Answer
604
32,524
502
Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
import sys sys.setrecursionlimit(500000) def dfs(v,c): color[v] = c for i in a[v]: if color[i] != -1: if color[i] == c:return False continue if dfs(i,1-c) == False:return False n,m = map(int,input().split()) a = [[]for i in range(n)] color = [-1 for _ in range(n)] for i in range(m): x,y= map(int,input().split()) a[x-1].append(y-1) a[y-1].append(x-1) print(a) if dfs(0,0) == False: print(n*(n-1)//2-m) else:print((n-n//2)*(n//2) - m)
s912728288
Accepted
467
31,152
508
import sys sys.setrecursionlimit(500000) def dfs(v,c): color[v] = c for i in a[v]: if color[i] != -1: if color[i] == c:return False continue if dfs(i,1-c) == False:return False n,m = map(int,input().split()) a = [[]for i in range(n)] color = [-1 for _ in range(n)] for i in range(m): x,y= map(int,input().split()) a[x-1].append(y-1) a[y-1].append(x-1) if dfs(0,0) == False: print(n*(n-1)//2-m) else:print(color.count(0) * color.count(1) -m)
s249180533
p03080
u319818856
2,000
1,048,576
Wrong Answer
17
2,940
201
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
def red_or_blue(N: int, s: str)->bool: r = sum(c == 'R' for c in s) return r > N-r if __name__ == "__main__": N = int(input()) s = input() ans = red_or_blue(N, s) print(ans)
s486446287
Accepted
17
2,940
220
def red_or_blue(N: int, s: str)->bool: r = sum(c == 'R' for c in s) return r > N-r if __name__ == "__main__": N = int(input()) s = input() yes = red_or_blue(N, s) print('Yes' if yes else 'No')
s636488642
p04043
u902130170
2,000
262,144
Wrong Answer
17
2,940
241
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a, b, c = map(str, input().split(" ")) if len(a) == 7 and len(b) == 5 and len(c) == 5 \ or len(a) == 5 and len(b) == 7 and len(c) == 5 \ or len(a) == 5 and len(b) == 5 and len(c) == 7: print("YES") else: print("NO")
s537338372
Accepted
18
2,940
197
a, b, c = map(int, input().split(" ")) if a == 5 and b == 7 and c == 5 \ or a == 5 and b == 5 and c == 7 \ or a == 7 and b == 5 and c == 5: print("YES") else: print("NO")
s637024327
p03587
u264681142
2,000
262,144
Wrong Answer
17
2,940
42
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem is not accepted. How many problems prepared by Snuke are accepted to be used in the contest?
l = max(list(map(int, input()))) print(l)
s274538309
Accepted
18
2,940
42
l = sum(list(map(int, input()))) print(l)
s533725027
p03474
u431624930
2,000
262,144
Wrong Answer
18
3,064
237
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
#coding:utf-8 a,b = (int(i) for i in input().split()) s = input() print(a,b,s[0:a],s[a],s[a+1:]) a = int(a) b = int(b) if(len(s)==(a+b+1) and s[0:a].isdigit() and s[a]=="-" and s[a+1:].isdigit()): print("Yes") else: print("No")
s951490267
Accepted
17
2,940
207
#coding:utf-8 a,b = (int(i) for i in input().split()) s = input() a = int(a) b = int(b) if(len(s)==(a+b+1) and s[0:a].isdigit() and s[a]=="-" and s[a+1:].isdigit()): print("Yes") else: print("No")
s292185367
p03379
u598229387
2,000
262,144
Wrong Answer
305
25,224
187
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n=int(input()) x=[int(i) for i in input().split()] xs=sorted(x) left=xs[n//2-1] right=xs[n//2] for i in range(n): if i <= left: print(right) else: print(left)
s760917938
Accepted
305
26,772
180
n=int(input()) x=[int(i) for i in input().split()] xs=sorted(x) left=xs[n//2-1] right=xs[n//2] for i in x: if i <= left: print(right) else: print(left)
s717943182
p03945
u318029285
2,000
262,144
Wrong Answer
20
4,212
166
Two foxes Jiro and Saburo are playing a game called _1D Reversi_. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa. In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is `B`, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is `W`, it means that the color of the corresponding stone is white. Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.
S = input().split('B') if 'B' not in S: print(0) exit() count = 0 for i in S: if i == '': continue else: count += 1 print(2*count-1)
s981783532
Accepted
43
3,188
460
S = input() if S[0] == 'W': count = 0 f = 0 for i in range(len(S)): if S[i] == 'W' and f == 1: f = 0 count += 1 elif S[i] == 'B' and f == 0: f = 1 count += 1 else: f = 0 count = 0 for i in range(len(S)): if S[i] == 'B' and f == 1: f = 0 count += 1 elif S[i] == 'W' and f == 0: f = 1 count += 1 print(count)
s890677769
p02612
u292349290
2,000
1,048,576
Wrong Answer
27
8,880
54
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
def main(): N = int(input()) y = N%1000 return y
s953476484
Accepted
26
9,132
83
x = int(input()) if x%1000 == 0: y = 0 else: y = 1000 - (x%1000) print(y)
s501988313
p03160
u285022453
2,000
1,048,576
Wrong Answer
270
13,980
303
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())) dp = [float('inf')] * n dp[0] = 0 for i in range(0, n - 1): print(i) dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])) if i + 2 >= n: continue dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2])) print(dp[n - 1])
s005358603
Accepted
250
94,100
426
import sys sys.setrecursionlimit(10 ** 6) n = int(input()) h = list(map(int, input().split())) dp = [float('inf')] * n def rec(i): if i == 0: return 0 if dp[i] < 100000000000: return dp[i] else: res = min(dp[i], rec(i - 1) + abs(h[i] - h[i - 1])) if i > 1: res = min(res, rec(i - 2) + abs(h[i] - h[i - 2])) dp[i] = res return res print(rec(n - 1))
s353333938
p02853
u285582884
2,000
1,048,576
Wrong Answer
17
2,940
196
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
a = 0 for x in map(int, input().split()): if x == 1: a += 300000 elif x == 2: a += 200000 elif x == 3: a += 300000 if x == 600000: s = 1000000 print(x)
s476741275
Accepted
17
2,940
186
s = 0 for i in map(int, input().split()): if i == 1: s+=300000 elif i ==2 : s+= 200000 elif i ==3 : s+= 100000 if s== 600000: s = 1000000 print(s)
s577849942
p03485
u765815947
2,000
262,144
Wrong Answer
17
2,940
52
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a, b = map(int, input().split()) print((a+b)//2 + 1)
s102737963
Accepted
17
2,940
101
a, b = map(int, input().split()) if (a+b) % 2 == 0: print(int((a+b)/2)) else: print((a+b)//2 + 1)
s151816091
p03494
u314350544
2,000
262,144
Wrong Answer
25
9,088
319
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
n = int(input()) array = list(map(int, input().split())) def cal(value): return value / 2 def odd_even_cal(value): return value % 2 for i in range(n): if 0 in list(map(odd_even_cal, array)): print(i + 1) break array = list(map(cal, array)) print(array) else: print(i + 1)
s691105533
Accepted
27
9,056
340
n = int(input()) array = list(map(int, input().split())) def cal(value): return value / 2 def odd_even_cal(value): return value % 2 flug, counter = -1, 0 while flug < 0: if 1 in list(map(odd_even_cal, array)) or 0 in array: flug = 1 break counter += 1 array = list(map(cal, array)) print(counter)
s349813308
p03719
u310790595
2,000
262,144
Wrong Answer
17
2,940
90
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
A, B, C = map(int, input().split()) if C <= A <= B: print("Yes") else: print("No")
s472443421
Accepted
17
2,940
90
A, B, C = map(int, input().split()) if A <= C <= B: print("Yes") else: print("No")
s775465446
p03448
u102960641
2,000
262,144
Wrong Answer
54
2,940
199
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()) ans = 0 for i in range(a): for j in range(b): for k in range(c): if (i+1)*500+(j+1)*100+(k+1)*50 == x: ans += 1
s415661678
Accepted
50
3,064
204
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if i*500+j*100+k*50 == x: ans += 1 print(ans)
s721445325
p02690
u169702930
2,000
1,048,576
Wrong Answer
2,206
9,556
372
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()) a = 0 b = 0 flag = False for i in range(10**7): tmp = (x + i)**(1/5) if tmp.is_integer(): b = i a = x + b**5 flag = True break if flag == False: for i in range(-10**7,0): tmp = (x + i)**(1/5) if tmp.is_integer(): b = i a = x + b**5 break print(int(a),int(b))
s902182192
Accepted
398
9,364
501
x = int(input()) a = [] b = [] ansa = 0 ansb = 0 for i in range(10**3): a.append(i**5) b.append(i**5) for i in a: for j in b: if i - j == x: ansa = i**(1/5) ansb = j**(1/5) elif i + j == x: ansa = i**(1/5) ansb = -(j**(1/5)) elif -i + j == x: ansa = -(i**(1/5)) ansb = -(j**(1/5)) elif -i -j == x: ansa = -(i**(1/5)) ansb = j**(1/5) print(int(ansa), int(ansb))
s805102982
p03160
u440161695
2,000
1,048,576
Wrong Answer
93
13,928
152
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
N=int(input()) A=list(map(int,input().split())) dp=[float("INF")]*(N+1) dp[0]=0 for i in range(1,N): dp[i]=min(dp[i],abs(A[i]-A[i-1])) print(dp[N-1])
s463814378
Accepted
136
13,980
201
N=int(input()) A=list(map(int,input().split())) dp=[float("INF")]*N dp[0]=0 dp[1]=abs(A[0]-A[1]) for i in range(2,N): dp[i]=min(dp[i],abs(A[i]-A[i-1])+dp[i-1],abs(A[i-2]-A[i])+dp[i-2]) print(dp[-1])
s719643528
p03476
u187205913
2,000
262,144
Time Limit Exceeded
2,105
28,620
611
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
q = int(input()) l = [list(map(int,input().split())) for _ in range(q)] def prime_table(n): list = [True for _ in range(n+1)] for i in range(2,int(n**0.5)+1): if list[i]: j = i*2 while j<=n: list[j] = False j += i table = [i for i in range(n+1) if list[i] and i>=2] return table table = prime_table(10**5) sim_sum = [0]*(10**5+1) sim_sum[3] = 1 for i in range(5,10**5,2): if i in table and (i+1)//2 in table: sim_sum[i] = 1 sim_sum[i] += sim_sum[i-2] for l_ in l: print(sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])
s414894778
Accepted
499
32,236
627
q = int(input()) l = [list(map(int,input().split())) for _ in range(q)] def prime_table(n): list = [True for _ in range(n+1)] for i in range(2,int(n**0.5)+1): if list[i]: j = i*2 while j<=n: list[j] = False j += i table = [i for i in range(n+1) if list[i] and i>=2] return table table = prime_table(10**5) table_set = set(table) sim_sum = [0]*(10**5+1) for p in table: if p*2-1 in table_set: sim_sum[p*2-1] += 1 for i in range(1,10**5+1): sim_sum[i] += sim_sum[i-1] for l_ in l: print(sim_sum[l_[1]]-sim_sum[max(l_[0]-2,0)])
s565454957
p02406
u256256172
1,000
131,072
Wrong Answer
20
7,544
111
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()) for i in range(n): if (i+1)%3 == 0 or (i+1)%10 == 0: print(" " + str(i+1), end='')
s988969022
Accepted
30
7,868
121
n = int(input()) for i in range(n): if (i+1)%3 == 0 or "3" in str(i+1): print(" " + str(i+1), end='') print()
s043926163
p02393
u230653580
1,000
131,072
Wrong Answer
30
6,720
298
Write a program which reads three integers, and prints them in ascending order.
x = input().split() a = int(x[0]) b = int(x[1]) c = int(x[2]) if a < b : if b > c : t = b b = c c = t print(a,b,c) else : if a > b : if b > c: t = b b = c c = t t = a a = b b = t print(a,b,c)
s303157048
Accepted
30
6,724
265
x = input().split() a = int(x[0]) b = int(x[1]) c = int(x[2]) if a <= b <= c : print(a,b,c) elif a <= c <= b : print(a,c,b) elif b <= a <= c : print(b,a,c) elif b <= c <= a : print(b,c,a) elif c <= a <= b : print(c,a,b) else : print(c,b,a)
s716745562
p04014
u758815106
2,000
262,144
Wrong Answer
2,206
9,196
746
For integers b (b \geq 2) and n (n \geq 1), let the function f(b,n) be defined as follows: * f(b,n) = n, when n < b * f(b,n) = f(b,\,{\rm floor}(n / b)) + (n \ {\rm mod} \ b), when n \geq b Here, {\rm floor}(n / b) denotes the largest integer not exceeding n / b, and n \ {\rm mod} \ b denotes the remainder of n divided by b. Less formally, f(b,n) is equal to the sum of the digits of n written in base b. For example, the following hold: * f(10,\,87654)=8+7+6+5+4=30 * f(100,\,87654)=8+76+54=138 You are given integers n and s. Determine if there exists an integer b (b \geq 2) such that f(b,n)=s. If the answer is positive, also find the smallest such b.
n = int(input()) s = int(input()) r = 0 if n < s: print(-1) exit() else: t1 = 1 t2 = n while abs(t1-t2) != 1: nn = n nt = 0 t3 = (t1 + t2) // 2 while nn != 0: nt += nn % t3 nn = nn // t3 if nt < s: t2 = t3 elif nt > s: t1 = t3 else: print(t3) exit() nn1 = n nn2 = n nt1 = 0 nt2 = 0 while nn1 != 0: nt1 += nn1 % t1 nn1 = nn1 // t1 if nt1 == s: print(t1) exit() while nn2 != 0: nt2 += nn2 % t2 nn2 = nn2 // t2 if nt2 == s: print(t2) exit() print(t1) print(t2) print(-1) exit()
s937233258
Accepted
414
9,200
507
import math n = int(input()) s = int(input()) r = 0 if n == s: print(n + 1) exit() elif n < s: print(-1) exit() sq = int(math.sqrt(n)) for i in range(2, sq+1): nt = n st = 0 while nt > 0: st += nt % i nt //= i if st == s: print(i) exit() for i in range(sq+1, 0, -1): b = (n - s) // i + 1 st = n % b + n // b if n // b != b and st == s: print(b) exit() print(-1)
s648904651
p00005
u183079216
1,000
131,072
Wrong Answer
20
5,612
389
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
def gcd(a,b): if a > b: x = a y = b else: x = b y = a while y > 0: r = x % y x = y y = r return x def lcm(a,b,gcd): return a*b/gcd while 1: try: a,b = [int(x) for x in input().split()] gcd = gcd(a,b) lcm = lcm(a,b,gcd) print('{} {}'.format(gcd,lcm)) except: break
s427880809
Accepted
20
5,604
410
def gcd(a,b): if a > b: x = a y = b else: x = b y = a while y > 0: r = x % y x = y y = r return x def lcm(a,b,c): return int(a*b/c) while 1: try: a,b = [int(x) for x in input().split()] res_gcd = gcd(a,b) res_lcm = lcm(a,b,res_gcd) print('{} {}'.format(res_gcd,res_lcm)) except: break
s103565514
p03658
u260036763
2,000
262,144
Wrong Answer
20
2,940
97
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
n, k = map(int, input().split()) l = sorted(map(int, input().split())) [::-1] print(sum(l[:k+1]))
s593613766
Accepted
17
2,940
102
N, K = map(int, input().split()) l = sorted(map(int, input().split()), reverse=True) print(sum(l[:K]))
s413141606
p04030
u661980786
2,000
262,144
Wrong Answer
17
3,060
226
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
s = list(input()) len_s = len(s) output = [] for i in range(0,len_s): if s[i] =="b" and s[i-1] == True: output[i-1] = "d" output.append(s[i]) output2 = [j for j in output if j.isdigit()] print("".join(output2))
s912171935
Accepted
17
3,060
223
s = list(input()) len_s = len(s) output = [] for i in range(0,len_s): if s[i] == "B": try: output.pop(-1) except: pass else: output.append(s[i]) print("".join(output))
s385107192
p03721
u072717685
2,000
262,144
Wrong Answer
2,200
1,798,940
276
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.
def main(): n, k = map(int, input().split()) nums = [tuple(map(int, input().split())) for _ in range(n)] print(nums) l = [] for num in nums: l += str(num[0]) * num[1] li = [int(i) for i in l] print(li) l.sort() print(l[k-1]) main()
s003151338
Accepted
365
18,180
284
def main(): n, k = map(int, input().split()) nums = [tuple(map(int, input().split())) for _ in range(n)] nums.sort(key = lambda x:x[0]) for num in nums: if num[1] >= k: print(num[0]) break else: k -= num[1] main()
s451165352
p03635
u216631280
2,000
262,144
Wrong Answer
17
2,940
57
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
n, m = map(int, input().split()) print((n - 2) * (m - 1))
s226747334
Accepted
18
2,940
57
n, m = map(int, input().split()) print((n - 1) * (m - 1))
s021582660
p02854
u660571124
2,000
1,048,576
Wrong Answer
2,109
34,208
285
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
import numpy as np N = int(input()) a = list(map(int, input().split())) b=[] for i in a: if i!=1: b.append(i-1) a =b mindif = 1e9 minidx=0 for i in range(1,N): dif = np.abs(sum(a[:i])-sum(a[i:])) if dif<mindif: mindif = dif minidx = i print(minidx)
s280591359
Accepted
211
26,764
189
N = int(input()) a = list(map(int, input().split())) r = sum(a) ra = 0 result = 1e30 for i in range(0,N): ra += a[i] r -= a[i] result = min(result, abs(ra-r)) print(int(result))
s808462082
p03605
u027598378
2,000
262,144
Wrong Answer
17
2,940
175
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?
input = int(input()) first_digit = input % 10 second_digit = int((input - first_digit) / 10) if first_digit == 9 or second_digit == 9: print("YES") else: print("NO")
s647816511
Accepted
18
3,316
175
input = int(input()) first_digit = input % 10 second_digit = int((input - first_digit) / 10) if first_digit == 9 or second_digit == 9: print("Yes") else: print("No")
s187644344
p03943
u481026841
2,000
262,144
Wrong Answer
18
2,940
107
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 a+c == b or b+c ==a: print('YES') else: print('NO')
s254298157
Accepted
17
2,940
107
a,b,c = map(int,input().split()) if a+b == c or a+c == b or b+c ==a: print('Yes') else: print('No')
s947267108
p03478
u248670337
2,000
262,144
Wrong Answer
20
2,940
100
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b=map(int,input().split()) ans=0 for i in range(n): if a<=i//10+i%10<=b: ans+=i print(ans)
s727670443
Accepted
30
2,940
114
n,a,b=map(int,input().split()) ans=0 for i in range(1,n+1): if a<=sum(map(int,str(i)))<=b: ans+=i print(ans)
s574253361
p03407
u325264482
2,000
262,144
Wrong Answer
17
2,940
98
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A, B, C = list(map(int, input().split())) ans = "Yes" if (A + B) > C: ans = "No" print(ans)
s755755148
Accepted
17
2,940
100
A, B, C = list(map(int, input().split())) ans = "Yes" if ((A + B) < C): ans = "No" print(ans)
s247457770
p00004
u036236649
1,000
131,072
Wrong Answer
20
7,432
224
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
import sys for line in sys.stdin: a, b, c, d, e, f = map(float, line.split()) print(a, b, c, d, e, f) print('{0:.3f} {1:.3f}'.format( (e * c - f * b) / (e * a - d * b), (d * c - f * a) / (d * b - e * a)))
s019470113
Accepted
30
7,260
204
import sys for line in sys.stdin: a, b, c, d, e, f = map(float, line.split()) print('{0:.3f} {1:.3f}'.format( (e * c - f * b) / (e * a - d * b) + 0, (d * c - f * a) / (d * b - e * a) + 0))
s921805806
p03970
u886142147
2,000
262,144
Wrong Answer
17
2,940
122
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
s = input() tmp = "C0DEFESTIVAL2O16" ans = 0 for i in range(16): if s[i] != tmp[i]: ans = ans + 1 print(ans)
s719948298
Accepted
18
2,940
122
s = input() tmp = "CODEFESTIVAL2016" ans = 0 for i in range(16): if s[i] != tmp[i]: ans = ans + 1 print(ans)