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
s744029173
p04029
u867848444
2,000
262,144
Wrong Answer
16
2,940
31
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n=int(input()) print(n*(n+1)/2)
s129680578
Accepted
18
2,940
36
n=int(input()) print(int(n*(n+1)/2))
s626492891
p03674
u627417051
2,000
262,144
Wrong Answer
260
13,812
448
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
n = int(input()) A = list(map(int,input().split())) S = sum(A) x = int(S - (n * (n + 1) / 2)) a = A.index(x) A[a] = 0 b = A.index(x) C = [] c = [] M = n + 1 N = 1 print(M - N) for i in range(2, n + a - b + 2): M = (M * (n + 2 - i) / i) % 1000000007 N = (N * (n + a - b + 1 - i) / (i - 1)) % 1000000007 print(int((M - N + 1000000007) % 1000000007)) for i in range(n + a - b + 2, n + 2): M = (M * (n + 2 - i) / i) % 1000000007 print(int(M))
s571862051
Accepted
445
34,136
1,335
import sys input = sys.stdin.buffer.readline from collections import defaultdict con = 10 ** 9 + 7 def getlist(): return list(map(int, input().split())) class Combination(object): def __init__(self, N, con): self.fac = [0] * (N + 1) self.inv = [0] * (N + 1) self.finv = [0] * (N + 1) self.fac[0], self.fac[1] = 1, 1 self.inv[1] = 1 self.finv[0], self.finv[1] = 1, 1 for i in range(2, N + 1): self.fac[i] = self.fac[i - 1] * i % con self.inv[i] = self.inv[con % i] * (con - (con // i)) % con self.finv[i] = self.finv[i - 1] * self.inv[i] % con def com(self, N, k): return (self.fac[N] * self.finv[k] * self.finv[N - k]) % con def main(): N = int(input()) A = getlist() x = 0 y = 0 D = defaultdict(lambda: -1) for i in range(N + 1): if D[A[i]] == -1: D[A[i]] = i else: x = D[A[i]] y = i break n = y - x if N - n == 0: C1 = Combination(N + 1, con) print(C1.com(N + 1, i) - 1) for i in range(2, N + 2): print(C1.com(N + 1, i)) else: C1 = Combination(N + 1, con) C2 = Combination(N - n, con) for i in range(1, N - n + 2): print((C1.com(N + 1, i) - C2.com(N - n, i - 1)) % con) for i in range(N - n + 2, N + 2): print(C1.com(N + 1, i)) if __name__ == '__main__': main()
s588123911
p03054
u843135954
2,000
1,048,576
Wrong Answer
1,189
14,640
904
We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i-th row from the top and the j-th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c). Takahashi and Aoki will play a game, where each player has a string of length N. Takahashi's string is S, and Aoki's string is T. S and T both consist of four kinds of letters: `L`, `R`, `U` and `D`. The game consists of N steps. The i-th step proceeds as follows: * First, Takahashi performs a move. He either moves the piece in the direction of S_i, or does not move the piece. * Second, Aoki performs a move. He either moves the piece in the direction of T_i, or does not move the piece. Here, to move the piece in the direction of `L`, `R`, `U` and `D`, is to move the piece from square (r,c) to square (r,c-1), (r,c+1), (r-1,c) and (r+1,c), respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally.
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() h,w,n = na() sh,sw = na() s = ns() t = ns() iit = [sw,sh,h-sh+1,w-sw+1] print(iit) #ludr tshi = [0,0,0,0] aoki = [0,0,0,0] for i in range(n): if s[i] == 'L': tshi[0] += 1 if s[i] == 'U': tshi[1] += 1 if s[i] == 'D': tshi[2] += 1 if s[i] == 'R': tshi[3] += 1 print(tshi) print(aoki) for j in range(4): if tshi[j] >= iit[j]+aoki[3-j]: print('NO') exit() if t[i] == 'L': aoki[0] += 1 if t[i] == 'U': aoki[1] += 1 if t[i] == 'D': aoki[2] += 1 if t[i] == 'R': aoki[3] += 1 for j in range(4): if aoki[j] >= iit[j]+tshi[3-j]: aoki[j] -= 1 print('YES')
s317695689
Accepted
590
3,888
861
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() h,w,n = na() sh,sw = na() s = ns() t = ns() iit = [sw,sh,h-sh+1,w-sw+1] #ludr tshi = [0,0,0,0] aoki = [0,0,0,0] for i in range(n): if s[i] == 'L': tshi[0] += 1 if s[i] == 'U': tshi[1] += 1 if s[i] == 'D': tshi[2] += 1 if s[i] == 'R': tshi[3] += 1 for j in range(4): if tshi[j] >= iit[j]+aoki[3-j]: print('NO') exit() if t[i] == 'L': aoki[0] += 1 if t[i] == 'U': aoki[1] += 1 if t[i] == 'D': aoki[2] += 1 if t[i] == 'R': aoki[3] += 1 for j in range(4): if aoki[j] >= iit[j]+tshi[3-j]: aoki[j] -= 1 print('YES')
s217328192
p03067
u169866169
2,000
1,048,576
Wrong Answer
18
2,940
242
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.
r_str = input() r_str = r_str.split() r = [int(s) for s in r_str] a = 'Yes' if r[0] >= r[1]: if r[0] <= r[2]: a = 'Yes' else: a = 'No' else: if r[1] <= r[2]: a = 'Yes' else: a = 'No' print(a)
s607694267
Accepted
17
3,060
277
r_str = input() r_str = r_str.split() r = [int(s) for s in r_str] a = 'Yes' if r[0] <= r[1]: if r[0] <= r[2] and r[2] <= r[1]: a = 'Yes' else: a = 'No' else: if r[1] <= r[2] and r[2] <= r[0]: a = 'Yes' else: a = 'No' print(a)
s979111866
p04029
u630211216
2,000
262,144
Wrong Answer
26
9,116
29
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
N=int(input()) print(N*(N+1))
s149547378
Accepted
22
8,900
32
N=int(input()) print(N*(N+1)//2)
s999354670
p03371
u032484849
2,000
262,144
Wrong Answer
120
3,060
151
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
a,b,c,x,y=map(int,input().split()) ans=float("inf") for i in range(max(x,y)-1): t=a*(x-min(x,i))+b*(y-min(y,i))+2*c*i ans=min(ans,t) print(ans)
s214166420
Accepted
123
3,060
147
a,b,c,x,y=map(int,input().split()) ans=float("inf") for i in range(max(x,y)+1): t=a*max(0,x-i)+b*max(0,y-i)+2*c*i ans=min(ans,t) print(ans)
s608836083
p03067
u507116804
2,000
1,048,576
Wrong Answer
17
2,940
85
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=map(int,input().split()) if a<b<c or a>b>c: print("Yes") else: print("No")
s808226031
Accepted
17
2,940
85
a,b,c=map(int,input().split()) if a<c<b or a>c>b: print("Yes") else: print("No")
s897409592
p03131
u740284863
2,000
1,048,576
Wrong Answer
2,104
3,064
398
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
K,A,B = map(int,input().split()) oK = K bis = 1 yen = 0 if A >= B: bis += K print(bis) else: while K > 0: if yen >= 1: bis += B yen -= 1 else: if bis < A or K < A: bis += 1 else: bis -= A yen += 1 K -= 1 if bis > 1 + oK: print(bis,yen) else: print(1+oK,0)
s762852509
Accepted
17
3,060
273
k,a,b=map(int,input().split()) if b - a <= 2: ans = k + 1 else: if 1 <= k <= a - 1: ans = k + 1 else: if (k - (a-1)) % 2 == 0: ans = a + (b-a)*((k - (a-1))//2) else: ans = 1 + a + (b-a)*((k - (a-1))//2) print(ans)
s828506169
p03548
u594956556
2,000
262,144
Wrong Answer
21
3,316
55
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?
X, Y, Z = map(int, input().split()) X -= Z print(X//Y)
s757551083
Accepted
17
2,940
59
X, Y, Z = map(int, input().split()) X -= Z print(X//(Y+Z))
s798604571
p03487
u518987899
2,000
262,144
Wrong Answer
84
23,668
213
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 N = int(input().strip()) counter_A = Counter(map(int, input().strip().split(' '))) ans = 0 for k,v in counter_A.items(): if k >= v: ans += v-k else: ans += v print(ans)
s390333408
Accepted
79
23,668
213
from collections import Counter N = int(input().strip()) counter_A = Counter(map(int, input().strip().split(' '))) ans = 0 for k,v in counter_A.items(): if v >= k: ans += v-k else: ans += v print(ans)
s920645783
p03469
u636684559
2,000
262,144
Wrong Answer
17
2,940
29
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
S=input() print('2008'+S[4:])
s676533853
Accepted
17
2,940
29
S=input() print('2018'+S[4:])
s031489533
p03193
u859897687
2,000
1,048,576
Wrong Answer
20
3,060
128
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
n,h,w=map(int,input().split()) ans=0 for _ in range(n): y,x=map(int,input().split()) if y<=h and x<=w: ans+=1 print(ans)
s785018177
Accepted
20
3,060
128
n,h,w=map(int,input().split()) ans=0 for _ in range(n): a,b=map(int,input().split()) if a>=h and b>=w: ans+=1 print(ans)
s827149552
p02393
u212392281
1,000
131,072
Wrong Answer
20
5,592
188
Write a program which reads three integers, and prints them in ascending order.
a, b, c = map(int, input().split()) d = 0 if a > b: d = a a = b b = d else: pass d = 0 if b > c: d = b b = c c = d d = 0 if a > c: d = a a = c c = d print(a, b, c)
s477101330
Accepted
20
5,596
208
a, b, c = map(int, input().split()) d = 0 if a > b: d = a a = b b = d else: pass d = 0 if b > c: d = b b = c c = d else: pass d = 0 if a > b: d = a a = b b = d else: pass print(a, b, c)
s252494199
p03643
u284262180
2,000
262,144
Wrong Answer
17
2,940
143
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
list = [64,32,16,8,4,2] O = int(input()) if O == 1: print(1) exit() for num in list: if O > num: print(num) break
s597177618
Accepted
17
2,940
20
print("ABC"+input())
s600950040
p02612
u457802431
2,000
1,048,576
Wrong Answer
29
9,144
30
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n%1000)
s778615622
Accepted
34
9,156
86
n = int(input()) ans = 1000 - n%1000 if ans == 1000: print(0) else: print(ans)
s319019827
p03845
u019584841
2,000
262,144
Wrong Answer
17
2,940
149
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds. It does not affect the time to solve the other problems. A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.
n=int(input()) t=[int(x) for x in input().split()] m=int(input()) for i in range(m): a,b=map(int,input().split()) s=b+sum(t[0:a])+sum(t[a+1:])
s752877250
Accepted
21
3,316
164
N = input() T = list(map(int, input().split())) M = int(input()) sumT = sum(T) for i in range(M): P, X = map(int, input().split()) print(sumT - T[P-1] + X)
s446512750
p03719
u513793759
2,000
262,144
Wrong Answer
18
2,940
84
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 and c>=b: print('Yes') else: print('No')
s814275462
Accepted
18
2,940
86
a,b,c = map(int, input().split()) if c>=a and c<=b: print('Yes') else: print('No')
s485330596
p01224
u078042885
3,000
131,072
Time Limit Exceeded
40,000
7,700
219
ある整数 N に対し,その数自身を除く約数の和を S とする. N = S のとき N は完全数 (perfect number), N > S のとき N は不足数 (deficient number), N < S のとき N は過剰数 (abundant number) と呼ばれる. 与えられた整数が,完全数・不足数・過剰数のどれであるかを 判定するプログラムを作成せよ. プログラムの実行時間が制限時間を越えないように注意すること.
def f(p): return sum([n for n in range(1,p) if p%n==0]) while 1: n=int(input()) if n==0:break m=f(n) if n==m:print('perfect number') else: print('deficient number' if n>m else 'abundant number')
s143786049
Accepted
130
7,680
331
def f(p): ans=1 if p<=5: return 0 for n in range(2,int(p**0.5)+1): if p%n==0: if n!=p//n:ans+=n+p//n else:ans+=n return ans while 1: n=int(input()) if n==0:break m=f(n) if n==m:print('perfect number') else: print('deficient number' if n>m else 'abundant number')
s278765842
p03605
u721425712
2,000
262,144
Wrong Answer
17
2,940
73
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
s = input() if s[0] == 9 or s[1] == 9: print('Yes') else: print('No')
s435356401
Accepted
17
2,940
77
s = input() if s[0] == '9' or s[1] == '9': print('Yes') else: print('No')
s111933188
p00025
u966364923
1,000
131,072
Wrong Answer
20
7,636
268
Let's play Hit and Blow game. _A_ imagines four numbers and _B_ guesses the numbers. After _B_ picks out four numbers, _A_ answers: * The number of numbers which have the same place with numbers _A_ imagined (Hit) * The number of numbers included (but different place) in the numbers _A_ imagined (Blow) For example, if _A_ imagined numbers: 9 1 8 2 and _B_ chose: 4 1 5 9 _A_ should say 1 Hit and 1 Blow. Write a program which reads four numbers _A_ imagined and four numbers _B_ chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.
import sys for line in sys.stdin: a = list(map(int, line.split())) b = list(map(int, line.split())) hit = 0 blow = 0 for i in range(4): if b[i] == a[i]: hit += 1 elif b[i] in a: blow += 1 print(hit,blow)
s343083433
Accepted
20
7,532
367
import sys inputs = [] for line in sys.stdin: inputs.append(line) n = len(inputs) for _ in range(n // 2): a = list(map(int, inputs[_ * 2].split())) b = list(map(int, inputs[_ * 2 + 1].split())) hit = 0 blow = 0 for i in range(4): if b[i] == a[i]: hit += 1 elif b[i] in a: blow += 1 print(hit, blow)
s643214879
p02420
u986478725
1,000
131,072
Wrong Answer
20
5,600
490
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
# AOJ ITP1_9_B def numinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): while True: string = input() if string == "-": break n = int(input()) for i in range(n): h = int(input()) front = string[0 : h] back = string[h : len(string) - h] string = back + front print(string) if __name__ == "__main__": main()
s245245936
Accepted
20
5,596
433
# AOJ ITP1_9_B def main(): while True: string = input() if string == "-": break n = int(input()) for i in range(n): h = int(input()) front = string[0 : h] back = string[h : len(string)] string = back + front print(string) if __name__ == "__main__": main()
s202162876
p03303
u545411641
2,000
1,048,576
Wrong Answer
30
9,100
79
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
s = input() step = int(input()) for i in range(0, len(s), step): print(s[i])
s093774197
Accepted
26
9,072
86
s = input() step = int(input()) print(''.join([s[i] for i in range(0, len(s), step)]))
s339325855
p02747
u393512980
2,000
1,048,576
Wrong Answer
21
3,316
247
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.
import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import defaultdict from bisect import * mod = 10**9+7 S = input() for i in range(5): if 'hi' * (i+1) == S: print('Yes') exit() print('No')
s915409725
Accepted
25
3,444
252
import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import defaultdict from bisect import * mod = 10**9+7 S = input()[:-1] for i in range(5): if 'hi' * (i+1) == S: print('Yes') exit() print('No')
s054999013
p03449
u916806287
2,000
262,144
Wrong Answer
17
2,940
174
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
n = int(input()) A1 = list(map(int, input().split())) A2 = list(map(int, input().split())) c = [0]*n for i in range(n): c[i] += sum(A1[:i+1]) c[i] += sum(A2[i:]) print(c)
s294674012
Accepted
19
3,060
179
n = int(input()) A1 = list(map(int, input().split())) A2 = list(map(int, input().split())) c = [0]*n for i in range(n): c[i] += sum(A1[:i+1]) c[i] += sum(A2[i:]) print(max(c))
s242598354
p03563
u276192130
2,000
262,144
Wrong Answer
17
3,064
368
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
s = list(input()) t = list(input()) def eq(s, t): for i in range(len(s)): if s[i] != t[i] and s[i] != '?': return False return True for i in reversed(range(len(s) - len(t)+1)): if eq(s[i:i+len(t)], t[:]): s[i:i + len(t)] = t[:] ans = ''.join(s) print(ans.replace('?', 'b')) quit() print('UNRESTORABLE')
s578301006
Accepted
17
2,940
50
r = int(input()) g = int(input()) print(r+(g-r)*2)
s881156852
p03636
u382303205
2,000
262,144
Wrong Answer
17
2,940
64
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.
s = "awefaewf"#input() n = len(s) print(s[0]+ str(n - 2) +s[-1])
s450235279
Accepted
17
2,940
53
s = input() n = len(s) print(s[0]+ str(n - 2) +s[-1])
s562899146
p03434
u054935796
2,000
262,144
Wrong Answer
17
3,060
234
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
N = int(input()) A = list(map(int, input().split())) n = range(N) list_Alice = [0] list_Bob = [0] A.sort() for i in n: if i%2 == 0: list_Alice.append(A[i]) else: list_Bob.append(A[i]) print(sum(list_Alice) - sum(list_Bob))
s486148120
Accepted
17
3,064
248
N = int(input()) A = list(map(int, input().split())) n = range(N) list_Alice = [0] list_Bob = [0] A.sort(reverse = True) for i in n: if i%2 == 0: list_Alice.append(A[i]) else: list_Bob.append(A[i]) print(sum(list_Alice) - sum(list_Bob))
s252940834
p02406
u780342333
1,000
131,072
Wrong Answer
30
7,672
115
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; }
num = int(input()) res = " ".join([str(x) for x in range(1, num+1) if x % 3 == 0]) print(" {}".format(res), end="")
s285184990
Accepted
20
6,136
115
n = int(input()) res = [i for i in range(3, n+1) if (i % 3 == 0) or ("3" in str(i))] print(" ",end="") print(*res)
s850569155
p03852
u582243208
2,000
262,144
Wrong Answer
23
3,064
161
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`.
s=input() s=s.replace("eraser","") s=s.replace("erase","") s=s.replace("dreamer","") s=s.replace("dream","") if len(s)==0: print("YES") else: print("NO")
s274983371
Accepted
34
3,188
53
print("vowel" if input() in "aiueo" else "consonant")
s367016657
p03251
u611655181
2,000
1,048,576
Wrong Answer
18
3,064
492
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=input().split() N=int(N) M=int(M) X=int(X) Y=int(Y) x=input().split() y=input().split() for i in range(0,len(x)): x[i]=int(x[i]) for i in range(0,len(y)): y[i]=int(y[i]) #X< Z <=Y comment='War' for Z in range(X+1,Y+1): #print(Z) if(max(x) < Z): if(min(y)>=Z): comment='Nor War' break print(comment)
s867837406
Accepted
18
3,064
513
N,M,X,Y=input().split() N=int(N) M=int(M) X=int(X) Y=int(Y) x=input().split() y=input().split() for i in range(0,len(x)): x[i]=int(x[i]) for i in range(0,len(y)): y[i]=int(y[i]) #X< Z <=Y comment='War' for Z in range(X+1,Y+1): #print(Z) if(max(x) < Z): if(min(y)>=Z): comment='No War' break print(comment)
s730092548
p03826
u711626986
2,000
262,144
Wrong Answer
17
3,060
104
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
a, b, c, d=map(int,input().split()) e=a*b f=c*d if e>f : print(e) if e<f : print(f) else: print(e)
s925494974
Accepted
17
2,940
107
a, b, c, d=map(int,input().split()) e=a*b f=c*d if e>f : print(e) elif e<f : print(f) else: print(e)
s835210721
p03693
u404062634
2,000
262,144
Wrong Answer
17
2,940
105
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()) x = r*100 + g*10 + b if x%4 == 0: print('Yes') else: print('No')
s756611957
Accepted
17
2,940
105
r,g,b = map(int,input().split()) x = r*100 + g*10 + b if x%4 == 0: print('YES') else: print('NO')
s064155585
p03067
u157887852
2,000
1,048,576
Wrong Answer
17
3,064
209
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.
input = input().split() a = int(input[0]) b = int(input[1]) c = int(input[2]) print(a) print(b) print(c) if (c > a and c > b) or (c < a and c < b): print("No") else: print("Yes")
s241722046
Accepted
17
2,940
182
input = input().split() a = int(input[0]) b = int(input[1]) c = int(input[2]) if (c > a and c > b) or (c < a and c < b): print("No") else: print("Yes")
s841196324
p02607
u261427665
2,000
1,048,576
Wrong Answer
23
9,172
169
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
N = int(input()) a = list(map(int, input().split())) p = 0 for i in range(0, N): if i % 2 == 1 and a[i] % 2 == 0: p = p + 1 else: p = p print (p)
s439005255
Accepted
24
9,116
175
N = int(input()) a = list(map(int, input().split())) p = 0 for i in range(0, N): if (i + 1) % 2 == 1 and a[i] % 2 == 1: p = p + 1 else: p = p print (p)
s894534417
p02408
u603049633
1,000
131,072
Wrong Answer
30
7,620
354
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
N = int(input()) FL =[] for i in range(13): FL.append("S" + str(i+1)) for i in range(13): FL.append("H" + str(i+1)) for i in range(13): FL.append("C" + str(i+1)) for i in range(13): FL.append("D" + str(i+1)) for i in range(N): x,y = map(str, input().split()) FL.remove(x + y) for i in range(52 - N - 1): print(FL[i] + " ", end="") print(FL[-1])
s850510852
Accepted
20
7,704
339
N = int(input()) #?????????????????????????????? FL =[] for i in range(13): FL.append("S " + str(i+1)) for i in range(13): FL.append("H " + str(i+1)) for i in range(13): FL.append("C " + str(i+1)) for i in range(13): FL.append("D " + str(i+1)) for i in range(N): D = str(input()) FL.remove(D) for i in range(52 - N): print(FL[i])
s401980375
p02742
u281796054
2,000
1,048,576
Wrong Answer
17
2,940
98
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
a,b=map(int,input().split()) if a%2==1 and b%2==1: print(a*(b+1)/2-(a-1)/2) else: print(a*b/2)
s963389477
Accepted
17
2,940
157
a,b=map(int,input().split()) if a%2==1 and b%2==1 and a!=1 and b!=1: print(int(a*(b+1)/2-(a-1)/2)) elif a==1 or b==1: print(1) else: print(int(a*b/2))
s481053306
p03433
u851704997
2,000
262,144
Wrong Answer
18
2,940
86
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) A = int(input()) if N % 500 <= A: print("YES") else: print("NO")
s055672714
Accepted
25
9,160
90
N = int(input()) A = int(input()) if(N % 500 <= A): print("Yes") else: print("No")
s191710903
p03129
u479977918
2,000
1,048,576
Wrong Answer
17
2,940
136
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
# -*- coding: utf-8 -*- N, K = map(int, input().split()) if int((N+1) /2) > K: print("Yes") else: print("No")
s236321095
Accepted
17
2,940
137
# -*- coding: utf-8 -*- N, K = map(int, input().split()) if int((N+1) /2) >= K: print("YES") else: print("NO")
s946973308
p02393
u361028487
1,000
131,072
Wrong Answer
20
5,452
1
Write a program which reads three integers, and prints them in ascending order.
s327055710
Accepted
20
5,560
111
tmp=input().split() tmp.sort() for i in range(0,len(tmp)-1): print(tmp[i],end=' ') print(tmp[len(tmp)-1])
s293266247
p03377
u519721530
2,000
262,144
Wrong Answer
17
3,064
103
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if 0 < (X-A) and (X-A) <= B: print('Yes') else: print('No')
s745342128
Accepted
17
2,940
100
A, B, X = map(int, input().split()) if A <= X and (X-A) <= B: print('YES') else: print('NO')
s378352589
p03337
u484856305
2,000
1,048,576
Wrong Answer
17
2,940
58
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
a,b=map(int,input().split()) c=[a+b,a*b,a-b] print(sum(c))
s236208417
Accepted
17
2,940
58
a,b=map(int,input().split()) c=[a+b,a-b,a*b] print(max(c))
s874598310
p02694
u758884263
2,000
1,048,576
Wrong Answer
105
27,136
241
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
import numpy as np def main(): x = int(input()) money = 100 ans = 0 while x >= money: ans += 1 money += money * 0.01 money = np.floor(money) print(ans) if __name__ == '__main__': main()
s417678859
Accepted
115
26,988
281
import numpy as np def main(): x = int(input()) money = 100 ans = 0 while x > money: money += money * 0.01 ans += 1 money = np.floor(money) #print(money) #print(ans) print(ans) if __name__ == '__main__': main()
s560682788
p02690
u667084803
2,000
1,048,576
Time Limit Exceeded
2,205
9,040
219
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 while True: for B in range(A): if A ** 5 + B ** 5 == X: print(A, B) break if A ** 5 - B ** 5 == X: print(A, B) break A += 1
s147429412
Accepted
29
9,200
328
import sys X = int(input()) A = 0 while True: for B in range(A+1): if A ** 5 + B ** 5 == X: print(A, -B) sys.exit() if A ** 5 - B ** 5 == X: print(A, B) sys.exit() if - A ** 5 + B ** 5 == X: print(-A, -B) sys.exit() A += 1
s719057881
p03623
u897328029
2,000
262,144
Wrong Answer
19
3,060
94
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x, a, b = list(map(int, input().split())) ans = "A" if abs(x-a) > abs(x-b) else "B" print(ans)
s788838295
Accepted
17
2,940
95
x, a, b = list(map(int, input().split())) ans = "A" if abs(x-a) < abs(x-b) else "B" print(ans)
s404775377
p03854
u674395364
2,000
262,144
Wrong Answer
21
3,444
262
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`.
import re s = input() re_list = [r'dream$', r'dreamer$', r'erase$', r'eraser$'] while True: if s == '': print('YES') break for regex in re_list: m = re.sub(regex, '', s) if m != s: s = m continue else: print('NO') break
s534158315
Accepted
82
3,188
369
S = input() S = S[::-1] while len(S) != 0: num = len(S) if S.find('maerd') == 0: S = S.replace('maerd', '', 1) if S.find('remaerd') == 0: S = S.replace('remaerd', '', 1) if S.find('esare') == 0: S = S.replace('esare', '', 1) if S.find('resare') == 0: S = S.replace('resare', '', 1) if num == len(S): print('NO') exit(0) print('YES')
s854373700
p00446
u408260374
1,000
131,072
Wrong Answer
30
6,720
632
次のような2人で行うカードゲームがある. * このゲームでは, 1から2nまでの各整数が書かれた全部で2n枚のカードを使用する. ここで,nは1以上100以下の整数である. * このカードを2人にn枚ずつ配る. * 次のルールに従って交互にカードを1枚ずつ場に出す. * 場にカードが出ていないならば, 好きなカードを出すことができる. * 場にカードが出ているならば, 最後に場に出たカードよりも大きい数の書かれたカードを出すことができる. * カードが出せる場合は,必ず場にカードを出す必要がある. * 出せるカードが無い場合はパスとなり,相手の番になる. このとき,場に出ているカードは無くなる. * ゲームは場にカードが出ていない状態で始める. * どちらかの手持ちのカードが無くなった時点でゲームは終了する. * ゲーム終了時に相手の持っているカードの枚数を得点とする. 太郎と花子は,このゲームで対戦することになった.ゲームは太郎の番から始める. 2人は共に,出すことのできるカードのうち必ず一番小さい数が書かれたカードを出すことにしている. 太郎に配られるカードが入力されたとき,太郎と花子の得点を出力するプログラムを作成せよ.
n = int(input()) taro = [int(input()) for _ in range(n)] hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro] taro.sort() hanako.sort() def discard(c, cards): for card in cards: if c < card: return card return 0 table = 0 while True: if taro: table = discard(table, taro) if table: taro.remove(table) if not taro: print(len(hanako)) print(0) break if hanako: table = discard(table, hanako) if table: hanako.remove(table) if not hanako: print(0) print(len(taro))
s963656555
Accepted
40
6,724
780
def discard(c, cards): for card in cards: if c < card: return card return 0 while True: n = int(input()) if n == 0: break taro = [int(input()) for _ in range(n)] hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro] taro.sort() hanako.sort() table = 0 while True: if taro: table = discard(table, taro) if table: taro.remove(table) if not taro: print(len(hanako)) print(0) break if hanako: table = discard(table, hanako) if table: hanako.remove(table) if not hanako: print(0) print(len(taro)) break
s195965742
p03455
u665452497
2,000
262,144
Wrong Answer
17
2,940
153
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
# -*- coding: utf-8 -*- a, b = map(int, input().split()) if a%2 and b%2: print('Even') else: print('Odd')
s739799783
Accepted
17
2,940
153
# -*- coding: utf-8 -*- a, b = map(int, input().split()) if a%2 and b%2: print('Odd') else: print('Even')
s187279364
p02972
u289288647
2,000
1,048,576
Wrong Answer
451
12,292
433
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 sys n = int(input()) a = list(map(int, input().split())) for i in range(n, 0, -1): val = 0 for j in range(i, n+1, i): val += a[j-1] if val%2 != a[i-1]: a[i-1] += 1 if a[i-1] > 1: print(-1) sys.exit() num = sum(a) if num == 0: print(0) else: print(num) for i in range(n): if a[i] != 0: print(i+1, end=' ') print('')
s674005550
Accepted
534
12,192
368
import sys n = int(input()) a = list(map(int, input().split())) b = [0 for _ in range(n)] for i in range(n, 0, -1): val = 0 for j in range(i, n+1, i): val += b[j-1] if val%2 != a[i-1]: b[i-1] += 1 num = sum(b) if num == 0: print(0) else: print(num) for i in range(n): if b[i] != 0: print(i+1)
s090011768
p03836
u813450984
2,000
262,144
Wrong Answer
18
3,060
290
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx, sy, tx, ty = map(int, input().split()) ans = "" temp_x = tx - sx temp_y = ty - sy ans += "U"*temp_y + "R"*temp_x + "D"*temp_y + "L"* temp_x temp_x += 1 temp_y += 1 ans += "L" + "U"*temp_y + "R"*temp_x + "D" + "R" + "D"*temp_y + "L"* temp_x + "U" print(ans) print("UURDDLLUUURRDRDDDLLU")
s832377860
Accepted
17
3,060
261
sx, sy, tx, ty = map(int, input().split()) ans = "" temp_x = tx - sx temp_y = ty - sy ans += "U"*temp_y + "R"*temp_x + "D"*temp_y + "L"* temp_x temp_x += 1 temp_y += 1 ans += "L" + "U"*temp_y + "R"*temp_x + "D" + "R" + "D"*temp_y + "L"* temp_x + "U" print(ans)
s359431675
p02612
u979951365
2,000
1,048,576
Wrong Answer
26
9,052
33
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s247289778
Accepted
30
9,156
77
n = int(input()) result = n % 1000 print(0 if result == 0 else 1000 - result)
s203663236
p03359
u686036872
2,000
262,144
Wrong Answer
17
2,940
59
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
a, b = map(int, input().split()) print(a if a < b else a-1)
s301003465
Accepted
17
2,940
48
a, b = map(int, input().split()) print(a-(a>b))
s428020594
p03067
u247769252
2,000
1,048,576
Wrong Answer
17
2,940
221
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.
import sys A, B, C = map(int, sys.stdin.readline().split()) print(A) if A < B: if B < C: print("No") else: print("Yes") if A > B: if B > C: print("No") else: print("Yes")
s832406339
Accepted
17
2,940
229
import sys A, B, C = map(int, sys.stdin.readline().split()) if A < B: if B < C or C < A: print("No") else: print("Yes") if A > B: if B > C or C > A: print("No") else: print("Yes")
s631895968
p04043
u390694622
2,000
262,144
Wrong Answer
17
2,940
143
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
l=map(int,input().split()) for num in l: if num not in [5,7]: print("NO") exit() if sum(l) == 17: print("YES") else: print("NO")
s139251407
Accepted
17
2,940
148
l=list(map(int,input().split())) for num in l: if num not in [5,7]: print("NO") exit() if sum(l) == 17: print("YES") else: print("NO")
s924187939
p02613
u349863397
2,000
1,048,576
Wrong Answer
151
16,352
1,319
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
from sys import stdin, stdout import math,sys from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi import heapq def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime--------------------------------------# sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); def I():return (int(input())) def In():return(map(int,input().split())) else: #------------------PYPY FAst I/o--------------------------------# def I():return (int(stdin.readline())) def In():return(map(int,stdin.readline().split())) def dict(a): d={} for x in a: if d.get(x,-1)!=-1: d[x]+=1 else: d[x]=1 return d def main(): try: l=[] n=I() for x in range(n): l.append(input()) d=dict(l) temp=['AC','WA','TLE','RE'] for x in temp: if d.get(x,-1)==-1: d[x]=0 print('AC X',d['AC']) print('WA X',d['WA']) print('TLE X',d['TLE']) print('RE X',d['RE']) except: pass M = 998244353 P = 1000000007 if __name__ == '__main__': #for _ in range(I()):main() for _ in range(1):main()
s654697734
Accepted
146
16,448
1,337
from sys import stdin, stdout import math,sys from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi import heapq def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime--------------------------------------# sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w'); def I():return (int(input())) def In():return(map(int,input().split())) else: #------------------PYPY FAst I/o--------------------------------# def I():return (int(stdin.readline())) def In():return(map(int,stdin.readline().split())) def dict(a): d={} for x in a: if d.get(x,-1)!=-1: d[x]+=1 else: d[x]=1 return d def main(): try: l=[] n=I() for x in range(n): l.append(input()) #d=dict(l) d={} temp=['AC','WA','TLE','RE'] for x in temp: d[x]=0 for x in l: d[x]+=1 print('AC x',d['AC']) print('WA x',d['WA']) print('TLE x',d['TLE']) print('RE x',d['RE']) except: pass M = 998244353 P = 1000000007 if __name__ == '__main__': #for _ in range(I()):main() for _ in range(1):main()
s519101420
p03370
u217627525
2,000
262,144
Wrong Answer
17
2,940
90
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
n,x=map(int,input().split()) m=[int(input()) for _ in range(n)] ans=n+(x-sum(m))//min(m)
s504394843
Accepted
17
2,940
164
n,x=map(int,input().split()) m_min=1001 m_sum=0 for _ in range(n): m=int(input()) m_sum+=m if m<m_min: m_min=m ans=n+(x-m_sum)//m_min print(ans)
s084690069
p03469
u203211107
2,000
262,144
Wrong Answer
17
2,940
68
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
#A-Already 2018(ABC085) S=str(input()) S=S.replace("7","8") print(S)
s356075240
Accepted
17
2,940
69
#A-Already 2018(ABC085) S=input() S=S.replace("2017","2018") print(S)
s214744489
p03993
u325956328
2,000
262,144
Wrong Answer
80
20,500
156
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a _friendly pair_ if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs.
N = int(input()) A = [x - 1 for x in map(int, input().split())] print(A) cnt = 0 for i in range(N): if A[A[i]] == i: cnt += 1 print(cnt // 2)
s234536348
Accepted
69
20,452
147
N = int(input()) A = [x - 1 for x in map(int, input().split())] cnt = 0 for i in range(N): if A[A[i]] == i: cnt += 1 print(cnt // 2)
s566745377
p03696
u535171899
2,000
262,144
Wrong Answer
28
9,452
1,298
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
def main(): import sys input = lambda:sys.stdin.readline().strip() N = int(input()) S = input() #solve from itertools import groupby def runLengthEncode(S: str)->list: ''' str to list(tuple).required itertools.groupby ''' grouped = groupby(S) res = [] for k, v in grouped: res.append((k, len(list(v)))) return res runs = runLengthEncode(S) from collections import deque left=deque() right=deque() idx = len(runs)-1 #)()()( while idx>=0: print(idx) if idx==len(runs)-1 and runs[idx][0]=='(': right.append('('*runs[idx][1]+')'*runs[idx][1]) idx-=1 elif idx==0 and runs[idx][0]==')': left.appendleft('('*runs[idx][1]+')'*runs[idx][1]) break elif idx==0: break else: tmp = runs[idx][1]-runs[idx-1][1] if tmp>0: left.appendleft('('*tmp) right.appendleft('('*runs[idx-1][1]+')'*runs[idx][1]) else: right.appendleft('('*runs[idx-1][1]+')'*runs[idx-1][1]) idx-=2 # print(left,right) print(''.join(left+right)) if __name__=='__main__': main()
s925765022
Accepted
28
9,100
405
def main(): import sys input = lambda:sys.stdin.readline().strip() N = int(input()) S = input() #solve right=0 left=0 for i in range(N): if S[i]=='(': right+=1 else: if right: right-=1 else: left+=1 print(left*'('+S+right*')') if __name__=='__main__': main()
s691769467
p03854
u369212307
2,000
262,144
Wrong Answer
17
3,188
448
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`.
s = input() s = s[::-1] while True: if s.find("maerd") == 0: s = s.lstrip("maerd") elif s.find("remaerd") == 0: s = s.lstrip("remaerd") elif s.find("esare") == 0: s = s.lstrip("esare") elif s.find("resare") == 0: s = s.lstrip("resare") else: break if s : print("NO") else: print("YES")
s116728467
Accepted
19
3,188
141
s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","") if s : print("NO") else: print("YES")
s053904499
p03455
u076941004
2,000
262,144
Wrong Answer
17
2,940
162
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a = input().split() print(a[0]) A = [] for i in range(len(a)): A.append(int(a[i])) if not (A[0]*A[1]) % 2: print('Even') else: print('Odd')
s124231180
Accepted
18
2,940
111
a, b = (int(i) for i in input().split()) product = a*b if product % 2 == 0: print('Even') else: print('Odd')
s029512967
p03659
u141574039
2,000
262,144
Wrong Answer
2,108
23,792
283
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
N=int(input()) A=list(map(int,input().split())) M=N;SU=0;AR=0;C=[0]*(N);C[0]=abs(A[0]-sum(A[1:]));x=10**9;P=0 for i in range(1,N): if N-i==1: p=0 break else: C[i]=abs(C[i-1]+A[i]-sum(A[i+1:])) if x>C[i]: x=C[i] p=i print(abs(C[p-1]+A[p]-sum(A[p+1:])))
s060154546
Accepted
242
28,688
306
S=[] N=int(input()) A=list(map(int,input().split())) C=[0]*(N);x=10**10;p=0 S.append(A[0]) for i in range(1,N): S.append(S[i-1]+A[i]) #print(S) C[0]=abs(A[0]-(S[-1]-S[0])) for i in range(1,N-1): C[i]=abs(S[i-1]+A[i]-(S[-1]-S[i])) if x>(C[i]): x=(C[i]) p=i print(abs(S[p-1]+A[p]-(S[-1]-S[p])))
s349699493
p03555
u960570220
2,000
262,144
Wrong Answer
29
8,920
73
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
C = str(input()) if C[0] == C[1]: print('Yes') else: print('No')
s969480116
Accepted
23
8,936
135
C1 = str(input()) C2 = str(input()) if C1[0] == C2[-1] and C1[1] == C2[-2] and C1[2] == C2[-3]: print('YES') else: print('NO')
s259013580
p02747
u368780724
2,000
1,048,576
Wrong Answer
17
2,940
156
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.
import sys readline = sys.stdin.buffer.readline S = readline().strip() ans = 'No' for i in range(1, 8): if S == 'hi'*i: ans = 'Yes' print(ans)
s328810265
Accepted
17
2,940
146
import sys readline = sys.stdin.buffer.readline S = input() ans = 'No' for i in range(1, 8): if S == 'hi'*i: ans = 'Yes' print(ans)
s161735692
p03129
u497046426
2,000
1,048,576
Wrong Answer
17
2,940
69
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N, K = map(int, input().split()) print('YES' if N >= 1+2*K else 'NO')
s185349649
Accepted
17
2,940
74
N, K = map(int, input().split()) print('YES' if (N+1) // K >= 2 else 'NO')
s906129269
p02613
u505582857
2,000
1,048,576
Wrong Answer
92
15,396
423
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
#!/usr/bin/env python3 import sys rl = sys.stdin.buffer.readline read = sys.stdin.buffer.read N = int(rl()) SL = read().split() A, W, T, R = ord('A'), ord('W'), ord('T'), ord('R') na, nw, nt, nr = 0, 0, 0, 0 for s in SL: print(s[0]) if s[0] == A: na += 1 elif s[0] == W: nw += 1 elif s[0] == T: nt += 1 elif s[0] == R: nr += 1 print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(na, nw, nt, nr))
s913141217
Accepted
60
15,244
442
#!/usr/bin/env python3 import sys rl = sys.stdin.buffer.readline read = sys.stdin.buffer.read N = int(rl()) SL = read().split() A, W, T, R = ord('A'), ord('W'), ord('T'), ord('R') na, nw, nt, nr = 0, 0, 0, 0 for s in SL: if s[0] == A: na += 1 elif s[0] == W: nw += 1 elif s[0] == T: nt += 1 elif s[0] == R: nr += 1 print('AC x ' + str(na)) print('WA x ' + str(nw)) print('TLE x ' + str(nt)) print('RE x ' + str(nr))
s696968206
p03943
u317508154
2,000
262,144
Wrong Answer
28
9,072
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 = list(map(int, input().split())) a.sort() if a[0] + a[1] == a[2]: print('YES') else: print('NO')
s615463926
Accepted
24
9,052
107
a = list(map(int, input().split())) a.sort() if a[0] + a[1] == a[2]: print('Yes') else: print('No')
s880197696
p03970
u379692329
2,000
262,144
Wrong Answer
20
2,940
128
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() correct = "CODEFESTIVAL2016" cnt = 0 for i in range(len(S)): if S[i] == correct[i]: cnt += 1 print(cnt)
s136317650
Accepted
17
2,940
137
S = input() correct = "CODEFESTIVAL2016" cnt = 0 for i in range(len(S)): if S[i] == correct[i]: cnt += 1 print(len(S) - cnt)
s038140811
p03997
u558374183
2,000
262,144
Wrong Answer
17
2,940
74
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.
l = [int(input()) for i in range(3)] s = (l[0] + l[1]) * l[2] / 2 print(s)
s428583188
Accepted
17
2,940
79
l = [int(input()) for i in range(3)] s = int((l[0] + l[1]) * l[2] / 2) print(s)
s126064649
p03407
u897302879
2,000
262,144
Wrong Answer
17
2,940
100
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()) print('Yes' if ((A == C) or (B == C) or (A + B == C)) else 'No')
s074749965
Accepted
17
2,940
72
A, B, C = map(int, input().split()) print('Yes' if A + B >= C else 'No')
s305068629
p03635
u580362735
2,000
262,144
Wrong Answer
17
2,940
49
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
n,m = map(int,input().split()) print(n*m-2*n-2*m)
s894276980
Accepted
17
2,940
57
n,m = map(int,input().split()) print((n+1)*(m+1)-2*n-2*m)
s193424481
p03469
u508273185
2,000
262,144
Wrong Answer
17
2,940
33
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
s = input() print("2018" + s[:4])
s152213712
Accepted
18
2,940
33
s = input() print("2018" + s[4:])
s218594763
p02936
u994910167
2,000
1,048,576
Wrong Answer
2,113
102,040
600
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
N, Q = map(int, input().split()) tree = list() ope = list() cnt = [0] * N for i in range(N-1): tree.append(list(map(int, input().split()))) for i in range(Q): ope.append(list(map(int, input().split()))) #print(tree, ope) for i in range(Q): vertex = ope[i][0] add = ope[i][1] parent = list() parent.append(vertex) for j in range(N-1): #print(j, tree[j][0], parent) if tree[j][0] in parent: parent.append(tree[j][1]) if tree[j][1] in parent: cnt[j+1] += add if vertex == 1: cnt[0] += add #print(tree) print(cnt)
s051986203
Accepted
1,844
113,604
259
N, Q = map(int, input().split()) ab = [list(map(int, input().split())) for i in range(N-1)] px = [list(map(int, input().split())) for i in range(Q)] cnt = [0] * N for p, x in px: cnt[p-1] += x for a, b in sorted(ab): cnt[b-1] += cnt[a-1] print(*cnt)
s220803968
p03644
u137228327
2,000
262,144
Wrong Answer
25
9,112
46
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N = int(input()) print(N if N%2 == 0 else N-1)
s579614075
Accepted
30
8,972
78
N = int(input()) i = 0 while N >= 2**i: #count+=1 i+=1 print(2**(i-1))
s021518557
p03193
u405256066
2,000
1,048,576
Wrong Answer
19
3,188
277
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
from sys import stdin N,k1,k2=[int(x) for x in stdin.readline().rstrip().split()] a = [] for i in range(N): a.append([int(x) for x in stdin.readline().rstrip().split()]) cnt=0 for i in a: tmp1=i[0]-k1 tmp2=i[1]-k2 if tmp1>0 and tmp2>0: cnt+=1 print(cnt)
s773526528
Accepted
19
3,188
279
from sys import stdin N,k1,k2=[int(x) for x in stdin.readline().rstrip().split()] a = [] for i in range(N): a.append([int(x) for x in stdin.readline().rstrip().split()]) cnt=0 for i in a: tmp1=i[0]-k1 tmp2=i[1]-k2 if tmp1>=0 and tmp2>=0: cnt+=1 print(cnt)
s318428311
p03457
u426964396
2,000
262,144
Wrong Answer
17
3,060
174
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
n = int(input()) for i in range(n): a, b, c = map(int, input().split()) if abs(a) + abs(b) > c: print('No') break else: print('Yes')
s249288135
Accepted
337
3,060
249
n = int(input()) c = True for i in range(n): t, x, y = map(int, input().split()) if x + y == t: c = True elif x + y < t and (t - x - y) % 2 == 0: c = True else: c = False break if c == True: print("Yes") else: print("No")
s749250271
p03409
u054514819
2,000
262,144
Wrong Answer
30
9,188
662
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) from bisect import bisect_right N = int(input()) ab = [list(mapint()) for _ in range(N)] cd = [list(mapint()) for _ in range(N)] ab.sort() cd.sort(key=lambda x: x[1]) clis = [c for c, d in cd] checked = [0]*N cdidx = 0 ans = 0 for n in range(N): a, b = ab[n] cdidx = bisect_right(clis, a) if cdidx>=N: break for i in range(cdidx, N): if checked[i]: continue c, d = cd[i] if a<c and b<d: ans += 1 checked[i] = 1 break print(ans)
s601073805
Accepted
28
9,212
566
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) from bisect import bisect_right N = int(input()) ab = [list(mapint()) for _ in range(N)] cd = [list(mapint()) for _ in range(N)] ab.sort(reverse=True) cd.sort(key=lambda x: x[1]) checked = [0]*N ans = 0 for n in range(N): a, b = ab[n] for i in range(N): if checked[i]: continue c, d = cd[i] if a<c and b<d: ans += 1 checked[i] = 1 break print(ans)
s535893939
p01448
u192570203
8,000
131,072
Wrong Answer
30
8,360
297
明日から、待ちに待った夏休みが始まります。なのでわたしは、友だちを誘って、海に遊びに行くこ とに決めました。 けれども、わたしの友だちには、恥ずかしがりやさんが多いです。その人たちは、あまり多くの人が いっしょに来ると知ったら、きっと嫌がるでしょう。 ほかにも、わたしの友だちには、目立ちたがりやさんも多いです。その人たちは、いっしょに来る人 があまり多くないと知れば、きっと嫌がるでしょう。 それと、わたしの友だちには、いつもは目立ちたがりやなのに実は恥ずかしがりやさんな人もいま す。その人たちは、いっしょに来る人が多すぎても少なすぎても、きっと嫌がるでしょう。 こういうのは、大勢で行った方が楽しいはずです。だからわたしは、できるだけたくさんの友だちを 誘いたいと思っています。けれども、嫌がる友だちを無理やり連れていくのはよくありません。 いったい、わたしは最大で何人の友だちを誘うことができるのでしょうか。 わたしは、こういう頭を使いそうな問題が大の苦手です。なので、あなたにお願いがあります。もし よろしければ、わたしの代わりにこの問題を解いていただけないでしょうか。いえ、決して無理にと は言いません。けれど、もし解いていただるのでしたら、わたしはとても嬉しいです。
N = int(input()) l = [list(map(int, input().split())) for _ in range(N)] diff = [0] * 100001 for k in l : diff[k[0] - 1] += 1 diff[k[1]] -= 1 hist = [0,0] for i in range(2, N + 1) : hist.append(hist[-1] + diff[i-1]) print(max([y for (x,y) in zip(hist, range(N + 1)) if x + 1 >= y]))
s220871121
Accepted
470
38,964
307
N = int(input()) l = [list(map(int, input().split())) for _ in range(N)] diff = [0] * 100002 for k in l : diff[k[0] - 1] += 1 diff[k[1]] -= 1 hist = [0,0] for i in range(2, N + 2) : hist.append(hist[-1] + diff[i-1]) print(max([0] + [y - 1 for (x,y) in zip(hist, range(N + 2)) if x + 1 >= y]))
s149192471
p00012
u572790226
1,000
131,072
Wrong Answer
30
7,456
544
There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain. Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.
import sys def crossMulti(p1, p2): return p1[0] * p2[1] - p1[1] * p2[0] lines = sys.stdin.readlines() for line in lines: Zd = [] x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split()) Ps = [(x2-x1, y2-y1),(x3-x2, y3-y2),(x1-x3, y1-y3)] Px = [(xp-x1, yp-y1),(xp-x2, yp-y2),(xp-x3, yp-y3)] for p in range(3): Zd.append(crossMulti(Ps[p], Px[p])) Zd = [x > 0 for x in Zd] if (Zd[0] and Zd[1] and Zd[2]) or not(Zd[0] or Zd[1] or Zd[2]): print('Yes') else: print('No')
s032965930
Accepted
30
7,544
544
import sys def crossMulti(p1, p2): return p1[0] * p2[1] - p1[1] * p2[0] lines = sys.stdin.readlines() for line in lines: Zd = [] x1, y1, x2, y2, x3, y3, xp, yp = map(float, line.split()) Ps = [(x2-x1, y2-y1),(x3-x2, y3-y2),(x1-x3, y1-y3)] Px = [(xp-x1, yp-y1),(xp-x2, yp-y2),(xp-x3, yp-y3)] for p in range(3): Zd.append(crossMulti(Ps[p], Px[p])) Zd = [x > 0 for x in Zd] if (Zd[0] and Zd[1] and Zd[2]) or not(Zd[0] or Zd[1] or Zd[2]): print('YES') else: print('NO')
s031170631
p01127
u598551137
8,000
131,072
Wrong Answer
860
5,628
949
これは 20XX 年の話である.再生発電網による安定したエネルギー供給,および液化合成燃料の発明によって航空旅客数は鰻登りに増加した.しかし,航空機によるテロリズムの脅威は依然として存在するため,高速でかつ高い信頼性をもつ自動手荷物検査システムの重要性が高まっている.検査官が全部の荷物を調べることは実際問題として困難であることから,自動検査において疑わしいと判断された手荷物だけを検査官で改めて調べるという仕組みを整えたいわけである. 航空機業界からの要請を受け,国際客室保護会社(International Cabin Protection Company)では,新たな自動検査システムを開発するため,最近の旅客の手荷物について調査した.調査の結果,最近の旅客の手荷物には次のような傾向があることが判明した. * 手荷物は 1 辺だけが短い直方体のような形状をしている. * 一般の乗客が手荷物に詰めて航空機に持ち込む品物としてはノートパソコン,音楽プレイヤー,携帯ゲーム機,トランプなどがあり,これらはいずれも長方形である. * 個々の品物は,その長方形の辺が手荷物の辺と平行になるように詰めこまれる. * 一方,テロリズムに用いられるような武器は,長方形とは非常に異なる形状をもつ. 上記の調査結果をふまえて,以下のような手荷物検査のためのモデルを考案した.それぞれの手荷物は X 線に対して透明である直方体の容器だとみなす.その中には X 線に対して不透明である複数の品物が入っている.ここで,直方体の 3 辺を x 軸,y 軸,z 軸とする座標系を考え,x 軸と平行な方向に X 線を照射して,y-z 平面に投影された画像を撮影する.撮影された画像は適当な大きさの格子に分割され,画像解析によって,それぞれの格子領域に映っている品物の材質が推定される.この会社には非常に高度の解析技術があり,材質の詳細な違いすらも解析することが可能であることから,品物の材質は互いに異なると考えることができる.なお,複数の品物が x 軸方向に関して重なっているときは,それぞれの格子領域について最も手前にある,すなわち x 座標が最小である品物の材質が得られる.また,2 つ以上の品物の x 座標が等しいことはないと仮定する. あなたの仕事は,画像解析の結果が与えられたときに,長方形ではない(武器であるかもしれない)品物が入っていることが断言できるか,あるいはその手荷物には長方形の品物以外のものは入っていないと推測されるかを判定するプログラムを作成することである.
def is_safe(image, p): count = 0 for k, v in p.items(): rect = True for y in range(v[1], v[3] + 1, 1): for x in range(v[0], v[2] + 1, 1): m = image[y][x] if m == '.': return False if k != m: rect = False if rect: count += 1 return count > 0 n = int(input()) for i in range(n): h, w = map(int, input().split(' ')) image = [input() for y in range(h)] p = {} for y in range(h): for x in range(w): m = image[y][x] if m == '.': continue if m not in p: p[m] = [x, y, x, y] else: p[m][0] = min(p[m][0], x) p[m][1] = min(p[m][1], y) p[m][2] = max(p[m][2], x) p[m][3] = max(p[m][3], y) print('SAFE' if is_safe(image, p) else 'SUSPICIOUS')
s072024332
Accepted
850
5,624
1,172
def can_fill(image, k, v): for y in range(v[1], v[3] + 1): for x in range(v[0], v[2] + 1): m = image[y][x] if m != k and m != '*': return False return True def is_safe(image, p): keys = list(p.keys()) i = 0 while i < len(keys): k = keys[i] v = p[k] if can_fill(image, k, v): for y in range(v[1], v[3] + 1): for x in range(v[0], v[2] + 1): image[y][x] = '*' keys.remove(k) i = 0 else: i += 1 return len(keys) == 0 n = int(input()) for i in range(n): h, w = map(int, input().split(' ')) image = [list(input()) for y in range(h)] p = {} for y in range(h): for x in range(w): m = image[y][x] if m != '.': if m not in p: p[m] = [x, y, x, y] else: p[m][0] = min(p[m][0], x) p[m][1] = min(p[m][1], y) p[m][2] = max(p[m][2], x) p[m][3] = max(p[m][3], y) print('SAFE' if is_safe(image, p) else 'SUSPICIOUS')
s347288831
p03149
u723583932
2,000
1,048,576
Wrong Answer
29
9,096
193
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
n=list(map(int,input().split())) if ('1' in n) and ('9' in n) and ('7' in n) and ('4' in n): print('YES') else: print('NO')
s222661620
Accepted
28
9,148
185
n=list(map(int,input().split())) if (1 in n) and (9 in n) and (7 in n) and (4 in n): print('YES') else: print('NO')
s176223376
p03545
u049979154
2,000
262,144
Wrong Answer
18
3,060
412
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.
from itertools import * ABCD = input() n = len(ABCD) - 1 plumi_list = list(product(["+", "-"], repeat=n)) print(plumi_list) for bit in range(1 << n): formula = ABCD[0] for num, op in zip(ABCD[1:], plumi_list[bit]): formula += op + num ans = eval(formula) if ans == 7: print(formula + "=7") break else: continue break
s278645100
Accepted
18
3,060
345
from itertools import * ABCD = input() n = len(ABCD) - 1 plumi_list = list(product(["+", "-"], repeat=n)) for bit in range(1 << n): formula = ABCD[0] for num, op in zip(ABCD[1:], plumi_list[bit]): formula += op + num ans = eval(formula) if ans == 7: print(formula + "=7") break
s541339743
p02612
u367319568
2,000
1,048,576
Wrong Answer
30
9,148
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s764836573
Accepted
27
9,168
93
n = int(input()) i = 0 m = n while (m > 0): m = m - 1000 i = i + 1 print(i*1000 - n)
s822002736
p04043
u361826811
2,000
262,144
Wrong Answer
17
2,940
322
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.
import sys # import itertools # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines S = readline().decode('utf8').rstrip().split() print('Yes' if S.count('5') == 2 and S.count('7') == 1 else 'No')
s664173253
Accepted
17
2,940
322
import sys # import itertools # import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines S = readline().decode('utf8').rstrip().split() print('YES' if S.count('5') == 2 and S.count('7') == 1 else 'NO')
s684339270
p04012
u017719431
2,000
262,144
Wrong Answer
17
2,940
243
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
s = input() def isBeautiful(s): dict = {} for i in s: if i not in dict: dict[i] = 1 else: dict[i] += 1 for key in dict: if dict[key] % 2 != 0: return False return True print(isBeautiful(s))
s681963245
Accepted
17
2,940
243
s = input() def isBeautiful(s): dict = {} for i in s: if i not in dict: dict[i] = 1 else: dict[i] += 1 for key in dict: if dict[key] % 2 != 0: return "No" return "Yes" print(isBeautiful(s))
s179927675
p03386
u924308178
2,000
262,144
Wrong Answer
17
3,060
256
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.
# coding: utf-8 # Your code here! A,B,K = list(map(int,input().split(" "))) ans = [] for i in range(K): if A<=A+i<=B: ans.append(A+i) if A<=A-i<=B: ans.append(B-i) ans = list(set(ans)) ans.sort() for i in ans: print(i)
s193342609
Accepted
19
3,060
256
# coding: utf-8 # Your code here! A,B,K = list(map(int,input().split(" "))) ans = [] for i in range(K): if A<=A+i<=B: ans.append(A+i) if A<=B-i<=B: ans.append(B-i) ans = list(set(ans)) ans.sort() for i in ans: print(i)
s630616950
p03658
u089142196
2,000
262,144
Wrong Answer
17
2,940
105
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
N,K=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) print(sum(l[0:K+1]))
s111073797
Accepted
17
2,940
103
N,K=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) print(sum(l[0:K]))
s237987166
p02842
u723583932
2,000
1,048,576
Wrong Answer
41
9,124
157
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n=int(input()) ans=0 for i in range(1,50000+1): z=i*1.08 if n<=z<(n+1): ans=z break if ans==0: print(":(") else: print(ans)
s051431410
Accepted
41
9,172
157
n=int(input()) ans=0 for i in range(1,50000+1): z=i*1.08 if n<=z<(n+1): ans=i break if ans==0: print(":(") else: print(ans)
s574268710
p03565
u956433805
2,000
262,144
Wrong Answer
31
9,116
826
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
S = str(input()) T = str(input()) ans = [] flag = False T_l = len(T) S_l = len(S) u = 0 while u < S_l: cnt = 0 name = S[u] if name == T[0] or name == "?": cnt += 1 u += 1 for j in range(u,S_l): if cnt == T_l: break if S[j] == "?" or S[j] == T[cnt]: cnt += 1 u += 1 else: break if cnt == T_l: ans = ans + list(T) flag = True else: for j in range(cnt): if S[j] == "?": ans.append("a") else: ans.append(S[j]) else: ans.append(name) u += 1 continue if flag: ans = "".join(ans) print(*ans) else: print("UNRESTORABLE")
s884651076
Accepted
30
9,084
368
sd = input() t = input() n = len(sd) m = len(t) s = [] for i in range(n - m, -1, -1): t_kamo = sd[i:i + m] for j in range(m + 1): if j == m: print((sd[:i] + t + sd[i + len(t):]).replace("?", "a")) exit() if t_kamo[j] == "?": continue elif t_kamo[j] != t[j]: break print("UNRESTORABLE")
s288037472
p03448
u385244248
2,000
262,144
Wrong Answer
48
2,940
198
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A,B,C,X = map(int,open(0).read().split()) a = 0 for i in range(1,A+1): for l in range(1,B+1): for q in range(1,C+1): if 500*i+100*B+50*C == X: a += 1 print(a)
s671419630
Accepted
50
2,940
192
A,B,C,X = map(int,open(0).read().split()) a = 0 for i in range(A+1): for l in range(B+1): for q in range(C+1): if 500*i+100*l+50*q == X: a += 1 print(a)
s551675368
p04044
u955691979
2,000
262,144
Wrong Answer
17
3,060
143
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.
a = input().split() s = [input() for i in range(int(a[0]))] b = '' s.sort() print(s) for i in range(int(a[0]),0): b = s[i] + b print(b)
s848079205
Accepted
17
3,064
103
a = input().split() s = [input() for i in range(int(a[0]))] b = '' s.sort() b = ''.join(s) print(b)
s044943089
p03563
u298497862
2,000
262,144
Wrong Answer
17
2,940
55
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
R = float(input()) G = float(input()) print(G * 2 - R)
s229402630
Accepted
17
2,940
51
R = int(input()) G = int(input()) print(G * 2 - R)
s828593726
p03730
u940780117
2,000
262,144
Wrong Answer
28
9,060
173
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A,B,C=map(int,input().split()) mod=set() tmp=0 D=A while tmp not in mod: mod.add(tmp) tmp=D%B if tmp==C: print('Yes') exit() D+=A print('No')
s093202733
Accepted
28
9,168
173
A,B,C=map(int,input().split()) mod=set() tmp=0 D=A while tmp not in mod: mod.add(tmp) tmp=D%B if tmp==C: print('YES') exit() D+=A print('NO')
s756036104
p03828
u614550445
2,000
262,144
Wrong Answer
23
3,064
452
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
import math N = int(input()) mod = 10**9+7 def get_primes(n): ps = [0, 0] + [i for i in range(2, n)] for i in range(2, n): if ps[i] == 0: continue for j in range(i * i, n, i): ps[j] = 0 return [p for p in ps if p] prime = get_primes(N) ans = 1 for p in prime: tmp = 0 for i in range(1, int(math.log(N, p))+1): tmp += N // (p**i) ans = (ans * (tmp + 1)) % mod print(ans)
s447755705
Accepted
23
3,064
458
import math N = int(input()) mod = 10**9+7 def get_primes(n): ps = [0, 0] + [i for i in range(2, n+1)] for i in range(2, n+1): if ps[i] == 0: continue for j in range(i * i, n+1, i): ps[j] = 0 return [p for p in ps if p] prime = get_primes(N) ans = 1 for p in prime: tmp = 0 for i in range(1, int(math.log(N, p))+1): tmp += N // (p**i) ans = (ans * (tmp + 1)) % mod print(ans)
s909031484
p03131
u782685137
2,000
1,048,576
Wrong Answer
17
2,940
85
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
K,A,B=map(int,input().split()) c=K-A;d=B-A print(K+1 if d<2 or c<1 else A+c%2+c//2*d)
s442508036
Accepted
17
2,940
87
K,A,B=map(int,input().split()) c=K-A+1;d=B-A print(K+1 if d<2 or c<1 else A+c%2+c//2*d)
s274752915
p03455
u227082700
2,000
262,144
Wrong Answer
17
2,940
71
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b=map(int,input().split()) if (a*b)&1:print("Even") else:print("Odd")
s205013567
Accepted
17
2,940
77
a,b=map(int,input().split()) if ((a*b)&1)==0:print("Even") else:print("Odd")
s301330882
p02392
u609407244
1,000
131,072
Wrong Answer
30
6,724
71
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a, b, c = map(int, input().split()) print('YES' if a < b < c else 'NO')
s212419342
Accepted
30
6,724
71
a, b, c = map(int, input().split()) print('Yes' if a < b < c else 'No')
s171251936
p02663
u511379665
2,000
1,048,576
Wrong Answer
21
9,092
85
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
h1,m1,h2,m2,k=map(int,input().split()) t=h2*60+m2-(h1*60+m1) t-=0.5 g=t//k print(g*k)
s296704249
Accepted
22
9,080
78
h1,m1,h2,m2,k=map(int,input().split()) t=h2*60+m2-(h1*60+m1) print(max(0,t-k))
s803547852
p02259
u065504661
1,000
131,072
Wrong Answer
20
5,596
404
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
if __name__ == '__main__': N = input('Please input the number of elements: ') N = int(N) array = list(map(int, input('Please input the array: ').split())) for i in range(N): print(' '.join(map(str, array))) for j in range(N-1, i, -1): if array[j] < array[j-1]: array[j], array[j-1] = array[j-1], array[j] print(' '.join(map(str, array)))
s525013779
Accepted
20
5,600
422
def bubble_sort(A): global N flag = True i = 0 cnt = 0 while flag: flag = False for j in range(N-1, i, -1): if A[j] < A[j-1]: A[j],A[j-1] = A[j-1],A[j] cnt += 1 flag = True i += 1 return cnt N = int(input()) A = list(map(int, input().split())) cnt = bubble_sort(A) print(' '.join(list(map(str, A)))) print(cnt)
s496720936
p03732
u557437077
2,000
262,144
Wrong Answer
19
3,064
981
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
def func(n, W, w): dp = [[0 for _ in range(W+1)] for _ in range(n+1)] for i in range(1, len(dp)): for j in range(len(dp[0])): if j-w[-i][0] >= 0: dp[i][j] = max(dp[i-1][j-w[-i][0]] + w[-i][1], dp[i-1][j]) else: dp[i][j] = dp[i-1][j] # print(dp[i]) return dp[n][W] n, W = [int(i) for i in input().split()] w = [[0, 0] for _ in range(n)] for i in range(n): w[i] = [int(i) for i in input().split()] """ # print("print(\" vs \" + str(func({}, {}, {})))".format(n, W, w)) print("11 vs " + str(func(4, 6, [[2, 1], [3, 4], [4, 10], [3, 4]]))) print("13 vs " + str(func(4, 6, [[2, 1], [3, 7], [4, 10], [3, 6]]))) print("400 vs " + str(func(4, 10, [[1, 100], [1, 100], [1, 100], [1, 100]]))) print("0 vs " + str(func(4, 1, [[10, 100], [10, 100], [10, 100], [10, 100]]))) """
s349926928
Accepted
306
3,064
1,683
def func(n, W, w): _max = 0 weights = [[] for _ in range(4)] for i in range(n): weights[w[i][0]-w[0][0]].append(w[i][1]) for i in range(len(weights)): weights[i].sort() weights[i].append(0) weights[i].reverse() for j in range(1, len(weights[i])): weights[i][j] += weights[i][j-1] # print(weights) for i in range(len(weights[0])): # print("i:{}".format(i)) for j in range(len(weights[1])): for k in range(len(weights[2])): for l in range(len(weights[3])): if w[0][0]*i\ + (w[0][0]+1)*j\ + (w[0][0]+2)*k\ + (w[0][0]+3)*l <= W: # j]+weights[2][k]+weights[3][l])) _max = max(_max, weights[0][i]+weights[1][j]+weights[2][k]+weights[3][l]) return _max n, W = [int(i) for i in input().split()] w = [[0, 0] for _ in range(n)] for i in range(n): w[i] = [int(i) for i in input().split()] print(func(n, W, w)) """ # print("print(\" vs \" + str(func({}, {}, {})))".format(n, W, w)) print("11 vs " + str(func(4, 6, [[2, 1], [3, 4], [4, 10], [3, 4]]))) print("13 vs " + str(func(4, 6, [[2, 1], [3, 7], [4, 10], [3, 6]]))) print("400 vs " + str(func(4, 10, [[1, 100], [1, 100], [1, 100], [1, 100]]))) print("0 vs " + str(func(4, 1, [[10, 100], [10, 100], [10, 100], [10, 100]]))) """
s179026498
p03545
u215461917
2,000
262,144
Wrong Answer
18
3,064
485
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
import operator s = [int(i) for i in list(input())] op = [] op.append( operator.add ) op.append( operator.sub ) for i in range(2) : for j in range(2) : for k in range(2) : r = op[i](s[0],s[1]) r = op[j](r,s[2]) r = op[k](r,s[3]) if r == 7 : op1 = "+" if i == 0 else "-" op2 = "+" if j == 0 else "-" op3 = "+" if k == 0 else "-" print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3])) exit()
s035515607
Accepted
18
3,064
490
import operator s = [int(i) for i in list(input())] op = [] op.append( operator.add ) op.append( operator.sub ) for i in range(2) : for j in range(2) : for k in range(2) : r = op[i](s[0],s[1]) r = op[j](r,s[2]) r = op[k](r,s[3]) if r == 7 : op1 = "+" if i == 0 else "-" op2 = "+" if j == 0 else "-" op3 = "+" if k == 0 else "-" print(str(s[0])+op1+str(s[1])+op2+str(s[2])+op3+str(s[3])+"=7") exit()