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
s748302274
p03068
u661983922
2,000
1,048,576
Wrong Answer
17
2,940
244
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
N = input() S = input() K = input() char = S[int(K)-1] #print(char) ans = [] for j in range(len(S)): #print(S[j]) if char != S[j]: ans.append("*") #print("!=") else: ans.append(char) continue print(" ".join(ans))
s117303235
Accepted
17
2,940
242
N = input() S = input() K = input() char = S[int(K)-1] #print(char) ans = [] for j in range(len(S)): #print(S[j]) if char != S[j]: ans.append("*") #print("!=") else: ans.append(char) continue print("".join(ans))
s504665685
p02690
u652656291
2,000
1,048,576
Wrong Answer
555
9,160
116
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
x = int(input()) for i in range(1000): for j in range(1000): if i**5 - j**5 == x: print(i,j) break
s807199380
Accepted
52
9,164
148
x = int(input()) a = 0 b = 0 for i in range(-130,130): for j in range(-130,130): if x == (i**5) - (j**5): a = i b = j print(a,b)
s581764055
p03063
u559048291
2,000
1,048,576
Wrong Answer
2,104
12,008
282
There are N stones arranged in a row. Every stone is painted white or black. A string S represents the color of the stones. The i-th stone from the left is white if the i-th character of S is `.`, and the stone is black if the character is `#`. Takahashi wants to change the colors of some stones to black or white so that there will be no white stone immediately to the right of a black stone. Find the minimum number of stones that needs to be recolored.
N = int(input()) S = input() wl = [] bl = [] w=0 b=0 for i in S: if i==".": w+=1; wl.append(w) for i in reversed(S): if i=="#": b+=1; bl.insert(0, b) ans = N for i in range(N): if wl[i]+bl[i] > ans: ans = wl[i]+bl[i] print(N - ans)
s133469631
Accepted
164
12,808
280
N = int(input()) S = input() wl = [0] bl = [0] w=0 b=0 for i in S: if i==".": w+=1; else: b+=1; wl.append(w) bl.append(b) wmax = wl[-1] min = wmax; for i in range(N+1): if wmax+bl[i]-wl[i] < min: min = wmax+bl[i]-wl[i] print(min)
s202874227
p03386
u939585142
2,000
262,144
Wrong Answer
2,245
4,084
123
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.
A, B, K = map(int,input().split()) li = [i for i in range(A,B + 1)] ans = li[:K] + sorted(li,reverse = True)[:K] print(ans)
s382550372
Accepted
21
3,316
180
A, B, K = map(int,input().split()) ans = [] for i in range(K): if A + i <= B: ans.append(A + i) if B - i >= A: ans.append(B - i) for i in sorted(set(ans)): print(i)
s916800039
p03972
u476199965
2,000
262,144
Wrong Answer
987
26,948
290
On an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers. There are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1. The cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i. Mr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.
w,h = list(map(int,input().split())) pq = [] for i in range(w): pq.append((int(input()),0)) for i in range(h): pq.append((int(input()),1)) pq.sort() res = 0 w+=1 h+=1 dic = {0:w,1:h} for x in pq: print(dic[x[1]],x[0]) res += dic[1-x[1]]*x[0] dic[x[1]] -= 1 print(res)
s090421389
Accepted
660
24,540
264
w,h = list(map(int,input().split())) pq = [] for i in range(w): pq.append((int(input()),0)) for i in range(h): pq.append((int(input()),1)) pq.sort() res = 0 w+=1 h+=1 dic = {0:w,1:h} for x in pq: res += dic[1-x[1]]*x[0] dic[x[1]] -= 1 print(res)
s699532037
p03388
u118642796
2,000
262,144
Time Limit Exceeded
2,104
3,064
398
10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
Q = int(input()) AB = [list(map(int,input().split())) for _ in range(Q)] def cn(A,B): ans = 0 pre = B score = A*B for i in range(A+1,score+1): tmp = (score-1)//i if tmp < 1: break if tmp == pre: ans += pre-1 break ans += 1 pre = tmp return ans for ab in AB: print(cn(ab[0],ab[1])+cn(ab[1],ab[0]))
s907748337
Accepted
20
3,064
372
Q = int(input()) AB = [list(map(int,input().split())) for _ in range(Q)] def cn(A,B): score = A*B-1 L = A+1 R = score if L>R: return 0 while L!=R: tmp = (L+R)//2 if score > tmp*(tmp+1): L = tmp+1 else: R = tmp return (L-1-A+score//L) for ab in AB: print(cn(ab[0],ab[1])+cn(ab[1],ab[0]))
s648631440
p03970
u062691227
2,000
262,144
Wrong Answer
23
9,032
60
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() sum(a!=b for a, b in zip(s, 'CODEFESTIVAL2016'))
s571363410
Accepted
25
9,000
70
s, = *open(0), print(sum(a!=b for a, b in zip(s, 'CODEFESTIVAL2016')))
s020744103
p02255
u764759179
1,000
131,072
Wrong Answer
20
5,592
251
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.
# coding:utf-8 length = int(input()) data = list(input().split()) for i in range(1,len(data)): tmp = data[i] i2 = i - 1 while i2 >=0 and data[i2] > tmp: data[i2+1] = data[i2] i2 -= 1 data[i2+1] = tmp print(data)
s917588923
Accepted
20
5,604
430
# coding:utf-8 def printline(data): l="" for i,s in enumerate(data): l = l + str(s) if i+1 != len(data): l = l+" " print(l) length = int(input()) data = list(map(int,input().split())) printline(data) for i in range(1,len(data)): tmp = data[i] i2 = i - 1 while i2 >=0 and data[i2] > tmp: data[i2+1] = data[i2] i2 -= 1 data[i2+1] = tmp printline(data)
s137495291
p03998
u322185540
2,000
262,144
Wrong Answer
17
3,064
606
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
sa = input() sb = input() sc = input() acount = 0 bcount = 0 ccount = 0 flag = True ans = '' tmp = sa[acount] while flag: if tmp == 'a': acount += 1 if acount < len(sa): tmp = sa[acount] else: ans = 'a' flag = False if tmp == 'b': bcount += 1 if bcount < len(sb): tmp = sb[bcount] else: ans = 'b' flag = False if tmp == 'c': ccount += 1 if ccount < len(sc): tmp = sc[ccount] else: ans = 'c' flag = False print(ans)
s092818153
Accepted
17
3,064
771
sa = input() sb = input() sc = input() acount = 0 bcount = 0 ccount = 0 flag = True ans = '' tmp = sa[acount] if len(sa) == 1: ans = 'A' else: while flag: if tmp == 'a': if acount == len(sa): flag = False ans = 'A' else: tmp = sa[acount] acount += 1 if tmp == 'b': if bcount == len(sb): flag = False ans = 'B' else: tmp = sb[bcount] bcount += 1 if tmp == 'c': if ccount == len(sc): flag = False ans = 'C' else: tmp = sc[ccount] ccount += 1 print(ans)
s009045289
p03485
u098968285
2,000
262,144
Wrong Answer
17
2,940
235
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.
import math def makelist(n, m): return [[0 for _ in range(m)] for _ in range(n)] # n = int(input()) # a, b = list(map(int, input().split())) a, b = list(map(int, input().split())) ans = math.ceil(a / b) print(ans)
s432211288
Accepted
17
2,940
241
import math def makelist(n, m): return [[0 for _ in range(m)] for _ in range(n)] # n = int(input()) # a, b = list(map(int, input().split())) a, b = list(map(int, input().split())) ans = math.ceil((a + b) / 2) print(ans)
s612242304
p03644
u427344224
2,000
262,144
Wrong Answer
17
2,940
72
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()) num = [i for i in range(N) if i % 2 ==0][-1] print(num)
s413918647
Accepted
17
2,940
95
N = int(input()) num = 1 for i in range(1, 9): if 2**i <= N: num = 2**i print(num)
s994668308
p04011
u127856129
2,000
262,144
Wrong Answer
18
2,940
128
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
a=int(input()) b=int(input()) c=int(input()) d=int(input()) if a>=b: print(int((b*c)-((a-b)*d))) else: print(int(a*c))
s853415886
Accepted
20
2,940
128
a=int(input()) b=int(input()) c=int(input()) d=int(input()) if a>=b: print(int((b*c)+((a-b)*d))) else: print(int(a*c))
s799110474
p03478
u840974625
2,000
262,144
Wrong Answer
24
2,940
186
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()) x = 0 for i in range(n): q = i w = i / 10 e = i / 100 r = i / 1000 sum = q + w + e + r if sum >= a and sum <= b: x += 1 print(x)
s905737721
Accepted
27
3,060
284
n, a, b = map(int, input().split()) x = 0 for i in range(1, n+1): q = i // 10000 qi = i % 10000 w = qi // 1000 wi = qi % 1000 e = wi // 100 ei = wi % 100 r = ei // 10 ri = ei % 10 t = ri sum = q + w + e + r + t if sum >= a and sum <= b: x += i print(x)
s067474325
p03545
u004025573
2,000
262,144
Wrong Answer
18
3,064
407
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.
N=int(input()) a=N//1000 b=(N%1000)//100 c=(N%100)//10 d=N%10 ope=[-1,1] for i in ope: for j in ope: for k in ope: if a+i*b+j*c+k*d==7: ans=[i,j,k] l=[0]*3 for i in range(3): if ans[i]>0: l[i]="+" else: l[i]="-" #all_ans=[str(a),l[0],str(b),l[1],str(c),l[2],str(d)] all_ans=str(a)+l[0]+str(b)+l[1]+str(c)+l[2]+str(d) print(all_ans)
s874462053
Accepted
18
3,064
411
N=int(input()) a=N//1000 b=(N%1000)//100 c=(N%100)//10 d=N%10 ope=[-1,1] for i in ope: for j in ope: for k in ope: if a+i*b+j*c+k*d==7: ans=[i,j,k] l=[0]*3 for i in range(3): if ans[i]>0: l[i]="+" else: l[i]="-" #all_ans=[str(a),l[0],str(b),l[1],str(c),l[2],str(d)] all_ans=str(a)+l[0]+str(b)+l[1]+str(c)+l[2]+str(d)+"=7" print(all_ans)
s520012173
p03377
u386819480
2,000
262,144
Wrong Answer
17
2,940
95
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 = (int(_) for _ in input().split()) print('Yes') if x >= a and a+b >= x else print('No')
s915856315
Accepted
17
3,064
685
#!/usr/bin/env python3 import sys YES = "YES" # type: str NO = "NO" # type: str def solve(A: int, B: int, X: int): print(YES) if(A <= X <= A+B) else print(NO) return # Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = int(next(tokens)) # type: int B = int(next(tokens)) # type: int X = int(next(tokens)) # type: int solve(A, B, X) if __name__ == '__main__': main()
s522526755
p03470
u309039873
2,000
262,144
Wrong Answer
17
3,060
176
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
size = 1 N = int(input()) d_s = [] for _ in range(N): d_s.append(int(input())) d_s.sort() d_s.reverse() for i in range(1,N): if d_s[i] > d_s[i-1]: size += 1 print(size)
s831350895
Accepted
17
3,060
176
size = 1 N = int(input()) d_s = [] for _ in range(N): d_s.append(int(input())) d_s.sort() d_s.reverse() for i in range(1,N): if d_s[i] < d_s[i-1]: size += 1 print(size)
s118171851
p03693
u184817817
2,000
262,144
Wrong Answer
17
2,940
117
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?
#064A r,g,b = list(map(int,input().split())) n = r*100 + g*10 + b if n%4 == 0: print('Yes') else: print('No')
s353501740
Accepted
17
2,940
117
#064A r,g,b = list(map(int,input().split())) n = r*100 + g*10 + b if n%4 == 0: print('YES') else: print('NO')
s051298675
p03645
u078349616
2,000
262,144
Wrong Answer
629
19,956
351
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
N, M = map(int, input().split()) a = [0]*M b = [0]*M for i in range(M): a[i], b[i] = map(int, input().split()) c = [] for i in range(M): if b[i] == M: c.append(a[i]) if len(c) != 0: for i in range(M): if a[i] == 1: for j in range(len(c)): if b[i] == c[j]: print("POSSIBLE") exit() print("IMPOSSIBLE")
s723571617
Accepted
811
29,104
233
N, M = map(int, input().split()) G = [[] for _ in range(N)] for i in range(M): a, b = map(lambda x: int(x)-1, input().split()) G[a].append(b) for v in G[0]: if N-1 in G[v]: print("POSSIBLE") exit() print("IMPOSSIBLE")
s515000725
p03543
u672794510
2,000
262,144
Wrong Answer
18
3,064
250
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 = int(input()) result = False h1 = -1; h2 = -1; while a > 0: print(a%10) print(h1) print(h2) result = result or (h1 == h2 and h1 == a%10) h2 = h1 h1 = a%10 a = a//10; if result: print("Yes") else: print("No")
s977952656
Accepted
18
3,060
206
a = int(input()) result = False h1 = -1; h2 = -1; while a > 0: result = result or (h1 == h2 and h1 == a%10) h2 = h1 h1 = a%10 a = a//10; if result: print("Yes") else: print("No")
s813540417
p03862
u698479721
2,000
262,144
Time Limit Exceeded
2,118
212,180
282
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
n,x = map(int, input().split()) a = [int(i) for i in input().split()] b = [] if a[0]>x: b.append(x) else: b.append(a[0]) j = 1 while j <= n-1: if b[j-1]+a[j]<=x: b.append(a[j]) else: b.append(x-b[j-1]) k = 0 ans =0 while k < n: ans += a[k]-b[k] k += 1 print(ans)
s143430975
Accepted
124
14,060
255
n,x = map(int, input().split()) a = [int(i) for i in input().split()] ans = 0 if a[0]>x: ans += a[0]-x a[0]=x else: pass j = 1 while j <= n-1: if a[j-1]+a[j]<=x: j += 1 else: ans += a[j]-x+a[j-1] a[j]=x-a[j-1] j += 1 print(ans)
s179725835
p02743
u405256066
2,000
1,048,576
Wrong Answer
17
2,940
144
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
from sys import stdin a,b,c = [int(x) for x in stdin.readline().rstrip().split()] if a**2 + b**2 < c**2: print("Yes") else: print("No")
s205444194
Accepted
17
2,940
159
from sys import stdin a,b,c = [int(x) for x in stdin.readline().rstrip().split()] if 4*a*b < (c-a-b)**2 and (c-a-b) > 0: print("Yes") else: print("No")
s607721623
p03730
u694665829
2,000
262,144
Wrong Answer
28
9,184
179
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()) flag = False for i in range(10000): if (i*b+c)%a==0: flag = True break if flag: print('Yes') else: print('No')
s463995659
Accepted
32
9,152
174
a,b,c=map(int,input().split()) flag = False for i in range(10000): if (i*b+c)%a==0: flag = True break if flag: print('YES') else: print('NO')
s980734498
p02645
u309821257
2,000
1,048,576
Wrong Answer
19
9,020
109
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
# -*- coding: utf-8 -*- _in = input() # if True: # print(_in) # else: # print(_in) print(_in[1:3])
s563077253
Accepted
21
8,888
110
# -*- coding: utf-8 -*- _in = input() # if True: # print(_in) # else: # print(_in) print(_in[0:3])
s846120238
p03565
u971124021
2,000
262,144
Wrong Answer
17
3,064
506
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 = input() t = input() s = [x for x in s[::-1]] t = [x for x in t[::-1]] for i in range(len(s)-len(t)): flg = False cnt = 0 for j in range(i+len(t)): if s[i+j] == '?': cnt += 1 continue if s[i+j] == t[j]: flg = True else: flg = False break if flg or cnt == len(t): s[i:i+len(t)] = t else: print('UNRESTORABLE') exit() ans = '' s = [x for x in s[::-1]] for i in range(len(s)): if s[i] == '?': s[i] = 'a' ans += s[i] print(ans)
s057070929
Accepted
17
3,064
594
s = input() t = input() if len(s) < len(t): print('UNRESTORABLE') exit() s = [x for x in s[::-1]] t = [x for x in t[::-1]] for i in range(len(s)-len(t)+1): flg = False cnt = 0 for j in range(len(t)): if s[i+j] == '?': cnt += 1 continue if s[i+j] == t[j]: flg = True else: flg = False break if flg or cnt == len(t): s[i:i+len(t)] = t flg = True break if not flg: print('UNRESTORABLE') exit() ans = '' s = [x for x in s[::-1]] for i in range(len(s)): if s[i] == '?': s[i] = 'a' ans += s[i] print(ans)
s791823115
p03944
u207056619
2,000
262,144
Wrong Answer
60
3,064
1,196
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting.
#!/usr/bin/env python3 import sys def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"): cnt = 0 for y_ in range(H + 1): for x_ in range(W + 1): for i in range(N): if a[i] == 1 and x_ < x[i] or a[i] == 2 and x_ > x[i] or a[i] == 3 and y_ < y[i] or a[i] == 4 and y_ > y[i]: break else: cnt += 1 return cnt # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() W = int(next(tokens)) # type: int H = int(next(tokens)) # type: int N = int(next(tokens)) # type: int x = [int()] * (N) # type: "List[int]" y = [int()] * (N) # type: "List[int]" a = [int()] * (N) # type: "List[int]" for i in range(N): x[i] = int(next(tokens)) y[i] = int(next(tokens)) a[i] = int(next(tokens)) solve(W, H, N, x, y, a) if __name__ == '__main__': main()
s779572908
Accepted
59
3,064
1,197
#!/usr/bin/env python3 import sys def solve(W: int, H: int, N: int, x: "List[int]", y: "List[int]", a: "List[int]"): cnt = 0 for y_ in range(H): for x_ in range(W): for i in range(N): if a[i] == 1 and x_ < x[i] or a[i] == 2 and x_ >= x[i] or a[i] == 3 and y_ < y[i] or a[i] == 4 and y_ >= y[i]: break else: cnt += 1 return cnt # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() W = int(next(tokens)) # type: int H = int(next(tokens)) # type: int N = int(next(tokens)) # type: int x = [int()] * (N) # type: "List[int]" y = [int()] * (N) # type: "List[int]" a = [int()] * (N) # type: "List[int]" for i in range(N): x[i] = int(next(tokens)) y[i] = int(next(tokens)) a[i] = int(next(tokens)) print(solve(W, H, N, x, y, a)) if __name__ == '__main__': main()
s620606983
p00101
u314832372
1,000
131,072
Wrong Answer
30
5,592
192
An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina". Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000.
var1 = int(input()) str2 = "Hoshino" str3 = "Hoshina" for i in range(0, var1): str1 = input() if str1.find(str2) >= 0: str1 = str1.replace(str2, str3) print(str1)
s488320142
Accepted
20
5,592
187
var1 = int(input()) str2 = "Hoshino" str3 = "Hoshina" for i in range(0, var1): str1 = input() if str1.find(str2) >= 0: str1 = str1.replace(str2, str3) print(str1)
s065435929
p00002
u855694108
1,000
131,072
Wrong Answer
20
7,592
136
Write a program which computes the digit number of sum of two integers a and b.
def main(): a, b = map(int, input().split()) hoge = list(str(a + b)) print(len(hoge)) if __name__ == "__main__": main()
s417788840
Accepted
20
7,540
157
import sys def main(): for line in sys.stdin: a, b = map(int, line.split()) print(len(str(a + b))) if __name__ == "__main__": main()
s940389793
p03828
u822961851
2,000
262,144
Wrong Answer
17
3,064
306
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
def resolve(): n = int(input()) M = 10 ** 9 + 7 pl = [0] * (n + 1) for i in range(2, n+1): x = i p = 2 while x > 1: while x % p == 0: pl[p] += 1 x //= p p += 1 ans = 1 for s in pl: ans *= (s+1)
s914474877
Accepted
34
3,060
375
def resolve(): n = int(input()) S = [0]*(n+1) MOD = (10 ** 9) + 7 for i in range(1, n+1): n_i = i p = 2 while n_i > 1: while n_i % p == 0: n_i //= p S[p] += 1 p += 1 ans = 1 for s in S: ans *= s+1 print(ans % MOD) if __name__ == '__main__': resolve()
s165211349
p03448
u655834330
2,000
262,144
Wrong Answer
57
3,064
271
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 = input() B = input() C = input() X = input() A,B,C,X = map(int, [A,B,C,X]) count = 0 for a in range(A): for b in range(B): for c in range(C): x = (a+1)*500 + (b+1)*100 + (c+1)*50 if X == x: count += 1 print(count)
s074385346
Accepted
57
3,064
289
A = input() B = input() C = input() X = input() A,B,C,X = map(int, [A,B,C,X]) pattern_count = 0 for a in range(A+1): for b in range(B+1): for c in range(C+1): x = a*500 + b*100 + c*50 if X == x: pattern_count += 1 print(pattern_count)
s557807799
p02659
u999799597
2,000
1,048,576
Wrong Answer
28
8,964
57
Compute A \times B, truncate its fractional part, and print the result as an integer.
a, b = map(float, input().split()) print(int(a) * int(b))
s248330897
Accepted
26
9,016
90
a, b = map(float, input().split()) ib = b * 100 ans = int(a) * round(ib) // 100 print(ans)
s202402107
p03377
u384679440
2,000
262,144
Wrong Answer
17
2,940
112
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
A, B, X = map(int, input().split()) if X - A < 0: print("No") elif X - A <= B: print("Yes") else: print("No")
s223673901
Accepted
17
2,940
92
A, B, X = map(int, input().split()) if A + B <= X or A > X: print("NO") else: print("YES")
s915751024
p02928
u075303794
2,000
1,048,576
Wrong Answer
2,312
1,340,836
221
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
N,K = map(int,input().split()) A = list(map(int,input().split())) B = [] ans = 0 {B.extend(A) for i in range(K)} for i in range(len(B)-1): for j in range(i,len(B)): if B[i] > B[j]: ans+=1 print(ans/(10**9+7))
s668695446
Accepted
29
3,564
682
from collections import Counter class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i n,k = map(int, input().split()) aaa = list(map(int, input().split())) MOD = 10**9 + 7 bit = Bit(2001) single = 0 for a in reversed(aaa): single += bit.sum(a) bit.add(a + 1, 1) ans = single * k % MOD coef = k * (k - 1) // 2 % MOD cnt = Counter(aaa) before = 0 for a, c in sorted(cnt.items()): ans = (ans + c * before * coef) % MOD before += c print(ans)
s261811416
p03474
u178888901
2,000
262,144
Wrong Answer
18
3,060
311
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.
strnum = [str(i) for i in range(10)] a, b = input().split() a, b = int(a), int(b) S = input() judge = True for i in range(a + b + 1): if i != a: if i in strnum: continue else: judge = False else: if S[i] == "-": continue else: judge = False if judge: print("Yes") else: print("NO")
s316811382
Accepted
18
3,060
227
strnum = [str(i) for i in range(10)] a, b = input().split() a, b = int(a), int(b) S = input() S = S.split("-") if len(S) == 2: if len(S[0]) == a and len(S[1]) == b: print('Yes') else: print('No') else: print('No')
s767846305
p03555
u662449766
2,000
262,144
Wrong Answer
17
2,940
148
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.
import sys input = sys.stdin.readline def main(): print("YES" if input() == input()[::-1] else "NO") if __name__ == "__main__": main()
s960668772
Accepted
17
2,940
107
def main(): print("YES" if input() == input()[::-1] else "NO") if __name__ == "__main__": main()
s517261847
p04011
u057964173
2,000
262,144
Wrong Answer
17
3,060
304
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
import sys def input(): return sys.stdin.readline().strip() def resolve(): w=list(input()) w.sort() if len(w)%2!=0: print('No') else: for i in range(0,len(w),2): if w[i]!=w[i+1]: print('No') break print('Yes') resolve()
s123228170
Accepted
17
2,940
168
def resolve(): n=int(input()) k=int(input()) x=int(input()) y=int(input()) if n<k: print(n*x) else: print(k*x+(n-k)*y) resolve()
s718815621
p02401
u152353734
1,000
131,072
Wrong Answer
30
7,416
77
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 = input() if '?' in a: break print(eval(a))
s440570500
Accepted
20
7,496
84
while True: a = input() if '?' in a: break print("%d" % eval(a))
s489848426
p03860
u559346857
2,000
262,144
Wrong Answer
17
2,940
26
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s=input() print("A"+s+"B")
s368810351
Accepted
17
2,940
25
print("A"+input()[8]+"C")
s499154798
p03408
u147458211
2,000
262,144
Wrong Answer
18
3,064
740
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
N = int(input()) words = [] blue_cards = {} for i in range(N): s = input() if s in blue_cards: blue_cards[s] = blue_cards[s] + 1 else: blue_cards[s] = 1 if s not in words: words.append(s) M = int(input()) red_cards= {} for i in range(M): s = input() if s in red_cards: red_cards[s] = red_cards[s] + 1 else: red_cards[s] = 1 if s not in words: words.append(s) print(blue_cards) print(red_cards) max_money = -100 for word in words: get_money, lose_money = 0, 0 if word in blue_cards: get_money = blue_cards[word] if word in red_cards: lose_money = red_cards[word] print("{} {}".format(get_money, lose_money)) max_money = max(max_money, get_money - lose_money) print(max_money)
s661467812
Accepted
17
3,064
654
N = int(input()) words = [] blue_cards = {} for i in range(N): s = input() if s in blue_cards: blue_cards[s] = blue_cards[s] + 1 else: blue_cards[s] = 1 if s not in words: words.append(s) M = int(input()) red_cards= {} for i in range(M): s = input() if s in red_cards: red_cards[s] = red_cards[s] + 1 else: red_cards[s] = 1 if s not in words: words.append(s) max_money = 0 for word in words: get_money, lose_money = 0, 0 if word in blue_cards: get_money = blue_cards[word] if word in red_cards: lose_money = red_cards[word] max_money = max(max_money, get_money - lose_money) print(max_money)
s896776295
p03737
u159335277
2,000
262,144
Wrong Answer
30
8,972
52
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
print(''.join(map(lambda x: x[0], input().split())))
s478965651
Accepted
34
8,984
61
print(''.join(map(lambda x: x[0], input().split())).upper())
s064291081
p02388
u138422838
1,000
131,072
Wrong Answer
20
7,320
22
Write a program which calculates the cube of a given integer x.
x = 3 y = x^3 print(y)
s685507751
Accepted
20
7,640
34
x = input() y = int(x)**3 print(y)
s964204350
p03407
u041196979
2,000
262,144
Wrong Answer
17
2,940
90
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
A, B, C = map(int, input().split()) if A + B <= C: print("Yes") else: print("No")
s808669549
Accepted
17
2,940
89
A, B, C = map(int, input().split()) if A + B >= C: print("Yes") else: print("No")
s373610105
p02865
u550061714
2,000
1,048,576
Wrong Answer
17
2,940
32
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
print(round((int(input())-1)/2))
s404615660
Accepted
17
2,940
49
import math print(math.floor((int(input())-1)/2))
s569879071
p00016
u553148578
1,000
131,072
Wrong Answer
20
5,724
200
When a boy was cleaning up after his grand father passing, he found an old paper: In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (x, y) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. You can assume that d ≤ 100 and -180 ≤ t ≤ 180\.
import math x = y = n= 0 while True: d,a = map(int,input().split(',')) if d == a == 0: break x += d*math.sin(math.radians(n)) y += d*math.cos(math.radians(n)) n+=a print(map(int,(x,y)),sep='\n')
s851284976
Accepted
20
5,716
201
import math x = y = n= 0 while True: d,a = map(int,input().split(',')) if d == a == 0: break x += d*math.sin(math.radians(n)) y += d*math.cos(math.radians(n)) n+=a print(*map(int,(x,y)),sep='\n')
s334230411
p02406
u483716678
1,000
131,072
Wrong Answer
20
5,588
127
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 x in range(n+1): if(x%3==0): print(x,end=' ') elif(x%10 == 3): print(x,end=' ')
s416708655
Accepted
30
5,868
264
n = int(input()) y = 1 while y <= n : if(y % 3 == 0): print(' %d'%y,end='') else: p = y while(p != 0): if(p % 10 == 3): print(' %d'%y,end='') break p //= 10 y+=1 print()
s116730671
p02850
u685983477
2,000
1,048,576
Wrong Answer
808
65,364
1,007
Given is a tree G with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. Consider painting the edges in G with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different. Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
from collections import deque def main(): n = int(input()) tree = [] edge = [[] for _ in range(n)] for i in range(n-1): a,b=map(int, input().split()) tree.append([min(a,b),max(a,b),n]) edge[a-1].append([b-1,i]) edge[b-1].append([a-1,i]) cols = [0]*(n-1) max_c = [0]*(n) tree.sort(key = lambda x:x[0]) que=deque() c = 1 for e in edge[0]: que.append([e,c]) c+=1 for i in range(n): max_c[i] = len(edge[i]) while que: v=que.popleft() ver = v[0] color = v[1] if(cols[ver[1]]>0): continue else: cols[ver[1]] = color new_c = 1 for next_v in edge[ver[0]]: if(new_c==color): new_c += 1 que.append([next_v,new_c]) new_c += 1 print(max(max_c)) for i in range(n-1): print(cols[i]) if __name__ == '__main__': main()
s465214691
Accepted
692
46,832
782
from collections import deque,defaultdict n = int(input()) edges = [[] for _ in range(n)] for i in range(n-1): a,b=map(int, input().split()) edges[a-1].append([b-1,i]) edges[b-1].append([a-1,i]) c = 1 col = [0]*(n-1) visited = [0]*(n-1) que=deque() for v in edges[0]: que.append(v) col[v[1]]=c visited[v[1]]=1 c+=1 while que: v=que.popleft() c = 1 used = set() for i in edges[v[0]]: if(visited[i[1]]): used.add(col[i[1]]) for next_v in edges[v[0]]: if(not visited[next_v[1]]): if(c in used): c+=1 col[next_v[1]] = c used.add(c) c+=1 visited[next_v[1]] = 1 que.append(next_v) print(max(col)) for i in col: print(i)
s852102285
p03195
u291732989
2,000
1,048,576
Wrong Answer
202
7,072
183
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
N = int(input()) An = [] for p in range(N): Ai = int(input()) An.append(Ai) res = True for i in An: if i % 2 != 0: res = False print("first" if res else "second")
s683037251
Accepted
197
7,072
183
N = int(input()) An = [] for p in range(N): Ai = int(input()) An.append(Ai) res = True for i in An: if i % 2 != 0: res = False print("second" if res else "first")
s922192844
p03369
u518556834
2,000
262,144
Wrong Answer
17
2,940
51
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s = list(input()) print(700 + 100 * s.count("○"))
s646526931
Accepted
17
2,940
88
s = input() c = 0 for i in range(3): if s[i] == "o": c += 1 print(700 + c*100)
s491806829
p03494
u642682703
2,000
262,144
Wrong Answer
17
2,940
218
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.
evens = [6,4,10,4] itr = 0 flg = True while flg: evens = list(map(lambda x: (x/2), evens)) is_evens = list(map(lambda x: x.is_integer(), evens)) if not all(is_evens): flg = False break itr+=1 print(itr)
s872363370
Accepted
19
3,060
257
num = input() evens = [int(x) for x in input().split()] itr = 0 flg = True while flg: evens = list(map(lambda x: (x/2), evens)) is_evens = list(map(lambda x: x.is_integer(), evens)) if not all(is_evens): flg = False break itr+=1 print(itr)
s242253957
p02393
u748921161
1,000
131,072
Wrong Answer
20
7,704
139
Write a program which reads three integers, and prints them in ascending order.
input_str = input().split(' ') input_int = [] for value in input_str: input_int.append(int(value)) input_int.sort(); print(input_int);
s761463527
Accepted
20
7,692
181
input_str = input().split(' ') input_int = [] for value in input_str: input_int.append(int(value)) input_int.sort(); print('%d %d %d'%(input_int[0],input_int[1],input_int[2]));
s960746747
p03139
u227082700
2,000
1,048,576
Wrong Answer
17
2,940
59
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
a,b,c=map(int,input().split());print(max(b,c),max(0,b+c-a))
s173186197
Accepted
17
2,940
59
a,b,c=map(int,input().split());print(min(b,c),max(0,b+c-a))
s641890480
p02856
u716530146
2,000
1,048,576
Wrong Answer
252
17,384
76
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals. The preliminary stage consists of several rounds, which will take place as follows: * All the N contestants will participate in the first round. * When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows: * The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round. For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen). When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen. * The preliminary stage ends when 9 or fewer contestants remain. Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage. Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.
_,*t=open(0) a=-18 for t in t:d,c=map(int,t.split());a+=d*c+c*9 print(a//9)
s813984942
Accepted
612
3,060
102
a=0 m=int(input()) for i in range(m): d,c=map(int,input().split()) a+=c*9+d*c print((a-10)//9)
s227315889
p03394
u694433776
2,000
262,144
Wrong Answer
32
5,084
608
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
n=int(input()) ret=[2,3,4] if n>=6 else [2,3,25] if n==3 else [2,3,5,30] if n==4 else [2,3,5,30,60] if n>=6: def getnext(a): if a%6==0: return a+2 elif a%6==2: return a+1 elif a%6==3: return a+1 elif a%6==4: return a+2 while len(ret)<n: ret.append(getnext(ret[-1])) if sum(ret)%6==5: ret[-1]=getnext(ret[-1]) elif sum(ret)%6!=0: ret.remove((sum(ret)%6)+6) ret.append(getnext(ret[-1])) while sum(ret)%6!=0: ret[-1]=getnext(ret[-1]) print(" ".join(map(str,ret)))
s223478673
Accepted
32
5,084
610
n=int(input()) ret=[2,3,4] if n>=6 else [2,5,63] if n==3 else [2,5,20,63] if n==4 else [2,5,20,30,63] if n>=6: def getnext(a): if a%6==0: return a+2 elif a%6==2: return a+1 elif a%6==3: return a+1 elif a%6==4: return a+2 while len(ret)<n: ret.append(getnext(ret[-1])) if sum(ret)%6==5: ret[-1]=getnext(ret[-1]) elif sum(ret)%6!=0: ret.remove((sum(ret)%6)+6) ret.append(getnext(ret[-1])) while sum(ret)%6!=0: ret[-1]=getnext(ret[-1]) print(" ".join(map(str,ret)))
s087547027
p03574
u887207211
2,000
262,144
Wrong Answer
23
3,064
766
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
H, W = map(int,input().split()) S = [input() for _ in range(H)] result = [[0 for _ in range(W+1)]for _ in range(H+1)] for i in range(H): for j in range(W): if(S[i][j] == '#'): result[i][j] = '#' if(result[i-1][j-1] != '#'): result[i-1][j-1] += 1 if(result[i-1][j] != '#'): result[i-1][j] += 1 if(result[i-1][j+1] != '#'): result[i-1][j+1] += 1 if(result[i][j-1] != '#'): result[i][j-1] += 1 if(result[i][j+1] != '#'): result[i][j+1] += 1 if(result[i+1][j-1] != '#'): result[i+1][j-1] += 1 if(result[i+1][j] != '#'): result[i+1][j] += 1 if(result[i+1][j+1] != '#'): result[i+1][j+1] += 1 for r in result[:-1]: ''.join(list(map(str,r[:H])))
s287803037
Accepted
24
3,188
764
H, W = map(int,input().split()) S = [input() for _ in range(H)] reach = [[0 for _ in range(W+1)] for _ in range(H+1)] for i in range(H): for j in range(W): if(S[i][j] == "#"): reach[i][j] = "#" if(reach[i-1][j-1] != "#"): reach[i-1][j-1] += 1 if(reach[i-1][j] != "#"): reach[i-1][j] += 1 if(reach[i-1][j+1] != "#"): reach[i-1][j+1] += 1 if(reach[i][j-1] != "#"): reach[i][j-1] += 1 if(reach[i][j+1] != "#"): reach[i][j+1] += 1 if(reach[i+1][j-1] != "#"): reach[i+1][j-1] += 1 if(reach[i+1][j] != "#"): reach[i+1][j] += 1 if(reach[i+1][j+1] != "#"): reach[i+1][j+1] += 1 for r in reach[:-1]: print("".join(list(map(str, r[:W]))))
s258856945
p02243
u684241248
1,000
131,072
Wrong Answer
30
6,036
4,527
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.
# -*- coding: utf-8 -*- from collections import defaultdict from heapq import heappop, heappush def dijkstra(edges, start, *, adj_matrix=False, default_value=float('inf')): ''' Returns best costs to each node from 'start' node in the given graph. (Single Source Shortest Path - SSSP) If edges is given as an adjacency list including costs and destination nodes on possible edges, adj_matrix should be False(default), and it is generally when this functions works much faster. Note that costs in edges should follow the rules below 1. The cost from a node itself should be 0, 2. If there is no edge between nodes, the cost between them should be default_value 3. The costs can't be negative # sample input when given as adjacency list (adj_matrix=False) edges = [[(1, 2), (2, 5), (3, 4)], # node 0 [(0, 2), (3, 3), (4, 6)], # node 1 [(0, 5), (3, 2), (5, 6)], # node 2 [(0, 4), (1, 3), (2, 2), (4, 2)], # node 3 [(1, 6), (3, 2), (5, 4)], # node 4 [(2, 6), (4, 4)]] # node 5 # sample input when given as adjacency matrix (adj_matrix=True) edges = [[0, 2, 5, 4, inf, inf], # node 0 [2, 0, inf, 3, 6, inf], # node 1 [5, inf, 0, 2, inf, 6], # node 2 [4, 3, 2, 0, 2, inf], # node 3 [inf, 6, inf, 2, 0, 4], # node 4 [inf, inf, 6, inf, 4, 0]] # node 5 ''' n = len(edges) inf = float('inf') # costs = [inf] * n costs = defaultdict(lambda: inf) costs[start] = 0 pq, rem = [(0, start)], n - 1 while pq and rem: tmp_cost, tmp_node = heappop(pq) if costs[tmp_node] < tmp_cost: continue rem -= 1 nxt_edges = ((node, cost) for node, cost in enumerate(edges[tmp_node]) if cost != default_value) if adj_matrix else\ edges[tmp_node] for nxt_node, nxt_cost in nxt_edges: new_cost = tmp_cost + nxt_cost if costs[nxt_node] > new_cost: costs[nxt_node] = new_cost heappush(pq, (new_cost, nxt_node)) return costs def dijkstra_route(edges, start, goal, *, adj_matrix=False, default_value=float('inf'), verbose=False): ''' Trys to find the best route to the 'goal' from the 'start' ''' n = len(edges) inf = float('inf') # costs = [inf] * n costs = defaultdict(lambda: inf) costs[start] = 0 pq, rem = [(0, start)], n - 1 # prevs = [-1 for _ in [None] * n] prevs = defaultdict(lambda: -1) while pq and rem: tmp_cost, tmp_node = heappop(pq) if costs[tmp_node] < tmp_cost: continue rem -= 1 nxt_edges = ((node, cost) for node, cost in enumerate(edges[tmp_node]) if cost != default_value) if adj_matrix else\ edges[tmp_node] for nxt_node, nxt_cost in nxt_edges: new_cost = tmp_cost + nxt_cost if costs[nxt_node] > new_cost: costs[nxt_node] = new_cost heappush(pq, (new_cost, nxt_node)) prevs[nxt_node] = tmp_node min_route = [] prev = goal cnt = 0 while prev != start: min_route.append(prev) prev = prevs[prev] cnt += 1 if prev == -1 or cnt > n: raise NoRouteError( 'There is no possible route in this graph \nedges: {} \nstart: {} \ngoal: {}'. format(edges, start, goal)) else: min_route.append(prev) min_route = min_route[::-1] min_cost = costs[goal] if verbose: print('---route---') for node in min_route[:-1]: print('{} -> '.format(node), end='') else: print(min_route[-1]) print('---distance---') print(min_cost) return costs, min_route class NoRouteError(Exception): pass if __name__ == '__main__': ''' an example of using this function AIZU ONLINE JUDGE - ALDS_1_12_C ''' n = int(input()) edges = [[] for i in range(n)] for i in range(n): i, k, *kedges = map(int, input().split()) for edge in zip(kedges[::2], kedges[1::2]): edges[i].append(edge) for i, cost in enumerate(dijkstra(edges, 0)): print(i, cost)
s889552347
Accepted
460
68,708
4,374
# -*- coding: utf-8 -*- from heapq import heappop, heappush def dijkstra(edges, start, *, adj_matrix=False, default_value=float('inf')): ''' Returns best costs to each node from 'start' node in the given graph. (Single Source Shortest Path - SSSP) If edges is given as an adjacency list including costs and destination nodes on possible edges, adj_matrix should be False(default), and it is generally when this functions works much faster. Note that costs in edges should follow the rules below 1. The cost from a node itself should be 0, 2. If there is no edge between nodes, the cost between them should be default_value 3. The costs can't be negative # sample input when given as adjacency list (adj_matrix=False) edges = [[(1, 2), (2, 5), (3, 4)], # node 0 [(0, 2), (3, 3), (4, 6)], # node 1 [(0, 5), (3, 2), (5, 6)], # node 2 [(0, 4), (1, 3), (2, 2), (4, 2)], # node 3 [(1, 6), (3, 2), (5, 4)], # node 4 [(2, 6), (4, 4)]] # node 5 # sample input when given as adjacency matrix (adj_matrix=True) edges = [[0, 2, 5, 4, inf, inf], # node 0 [2, 0, inf, 3, 6, inf], # node 1 [5, inf, 0, 2, inf, 6], # node 2 [4, 3, 2, 0, 2, inf], # node 3 [inf, 6, inf, 2, 0, 4], # node 4 [inf, inf, 6, inf, 4, 0]] # node 5 ''' n = len(edges) costs = [float('inf')] * n costs[start] = 0 pq = [(0, start)] rem = n - 1 while pq and rem: tmp_cost, tmp_node = heappop(pq) if costs[tmp_node] < tmp_cost: continue rem -= 1 nxt_edges = ((node, cost) for node, cost in enumerate(edges[tmp_node]) if cost != default_value) if adj_matrix else\ edges[tmp_node] for nxt_node, nxt_cost in nxt_edges: new_cost = tmp_cost + nxt_cost if costs[nxt_node] > new_cost: costs[nxt_node] = new_cost heappush(pq, (new_cost, nxt_node)) return costs def dijkstra_route(edges, start, goal, *, adj_matrix=False, default_value=float('inf'), verbose=False): ''' Trys to find the best route to the 'goal' from the 'start' ''' n = len(edges) costs = [float('inf')] * n costs[start] = 0 pq = [(0, start)] rem = n - 1 prevs = [-1 for _ in [None] * n] while pq and rem: tmp_cost, tmp_node = heappop(pq) if costs[tmp_node] < tmp_cost: continue rem -= 1 nxt_edges = ((node, cost) for node, cost in enumerate(edges[tmp_node]) if cost != default_value) if adj_matrix else\ edges[tmp_node] for nxt_node, nxt_cost in nxt_edges: new_cost = tmp_cost + nxt_cost if costs[nxt_node] > new_cost: costs[nxt_node] = new_cost heappush(pq, (new_cost, nxt_node)) prevs[nxt_node] = tmp_node min_route = [] prev = goal cnt = 0 while prev != start: min_route.append(prev) prev = prevs[prev] cnt += 1 if prev == -1 or cnt > n: raise NoRouteError( 'There is no possible route in this graph \nedges: {} \nstart: {} \ngoal: {}'. format(edges, start, goal)) else: min_route.append(prev) min_route = min_route[::-1] min_cost = costs[goal] if verbose: print('---route---') for node in min_route[:-1]: print('{} -> '.format(node), end='') else: print(min_route[-1]) print('---distance---') print(min_cost) return costs, min_route class NoRouteError(Exception): pass if __name__ == '__main__': ''' an example of using this function AIZU ONLINE JUDGE - ALDS_1_12_C ''' n = int(input()) edges = [[] for i in range(n)] for i in range(n): i, k, *kedges = map(int, input().split()) for edge in zip(kedges[::2], kedges[1::2]): edges[i].append(edge) costs = dijkstra(edges, 0) for i, cost in enumerate(costs): print(i, cost)
s000556123
p02853
u732870425
2,000
1,048,576
Wrong Answer
17
2,940
170
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.
X, Y = map(int, input().split()) ans = 0 if X >= 3: ans += (4 - X) * 100000 if Y >= 3: ans += (4 - Y) * 100000 if X == 1 and Y == 1: ans += 400000 print(ans)
s970646842
Accepted
17
2,940
170
X, Y = map(int, input().split()) ans = 0 if X <= 3: ans += (4 - X) * 100000 if Y <= 3: ans += (4 - Y) * 100000 if X == 1 and Y == 1: ans += 400000 print(ans)
s743337277
p04029
u876742094
2,000
262,144
Wrong Answer
28
9,008
32
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)
s581540154
Accepted
26
9,140
33
n=int(input()) print(n*(n+1)//2)
s908666455
p03696
u329865314
2,000
262,144
Wrong Answer
17
3,060
223
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.
n = int(input()) s = input() ans = "" cur = 0 for i in s: if i == "(": ans += "(" cur += 1 ans += i else: if cur: ans += i cur -= 1 else: ans = "(" + ans ans += ")" * cur print(ans)
s252872774
Accepted
17
3,060
212
n = int(input()) s = input() ans = "" cur = 0 for i in s: if i == "(": cur += 1 ans += i else: if cur: ans += i cur -= 1 else: ans = "(" + ans + i ans += ")" * cur print(ans)
s894562398
p02612
u556477263
2,000
1,048,576
Wrong Answer
31
9,004
116
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(input()) if n % 1000 == 0: print(0) sys.exit() while n > 1000: n -= 1000 print(n)
s220168034
Accepted
34
9,108
123
import sys n = int(input()) if n % 1000 == 0: print(0) sys.exit() while n > 1000: n -= 1000 print(1000 - n)
s420104534
p03090
u801049006
2,000
1,048,576
Wrong Answer
30
9,072
57
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
n = int(input()) for i in range(n-1): print(i+1, n)
s042087256
Accepted
33
9,696
233
n = int(input()) d = n ans = [] if n % 2 == 1: d -= 1 for i in range(1, n+1): for j in range(1, n+1): if j <= i or j == d: continue ans.append([i, j]) d -= 1 print(len(ans)) for f, s in ans: print(f, s)
s371745677
p02972
u143903328
2,000
1,048,576
Wrong Answer
1,080
17,200
367
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.
n = int(input()) a = list(map(int,input().split())) c = 0 ans = [] for i in range(n): m = n-i p = 1 b = 0 while m * p <= n: tmp = m * p if a[tmp-1] == 1: b += 1 p += 1 if b % 2 == 1: ans.append(m) c += 1 if c%2 == 1: print('-1') else: print(c) print(" ".join(repr(e) for e in ans))
s803347793
Accepted
1,084
19,856
405
n = int(input()) a = list(map(int,input().split())) c = 0 d = [0] * n ans = [] for i in range(n): m = n-i p = 1 b = 0 while m * p <= n: tmp = m * p if d[tmp-1] == 1: b += 1 p += 1 if b % 2 != a[m-1]: d[m-1] = 1 ans.append(m) c += 1 if c%2 != a[0]: print('-1') else: print(c) print(" ".join(repr(e) for e in ans))
s532288470
p03494
u434311880
2,000
262,144
Wrong Answer
17
2,940
153
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()) b = (int(s) for s in input().split()) x = 0 for i in b: i = i // 2 c = i % 2 x = x + 1 if c != 0: break print(x)
s783035642
Accepted
18
2,940
144
N = int(input()) a = list(map(int, input().split())) cnt = 0 while all(i % 2 == 0 for i in a): a = [i/2 for i in a] cnt += 1 print(cnt)
s316827162
p03997
u840570107
2,000
262,144
Wrong Answer
17
2,940
84
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a = int(input()) b = int(input()) h = int(input()) ans = (a + b) * h / 2 print(ans)
s179318234
Accepted
17
2,940
89
a = int(input()) b = int(input()) h = int(input()) ans = (a + b) * h / 2 print(int(ans))
s567785989
p03455
u662573896
2,000
262,144
Wrong Answer
26
9,112
97
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if (a * b) % 2 == 1: print ('odd') else: print ('even')
s666067491
Accepted
26
8,936
97
a, b = map(int, input().split()) if (a * b) % 2 == 1: print ('Odd') else: print ('Even')
s760652623
p03158
u353797797
2,000
1,048,576
Wrong Answer
1,240
25,136
804
There are N cards. The i-th card has an integer A_i written on it. For any two cards, the integers on those cards are different. Using these cards, Takahashi and Aoki will play the following game: * Aoki chooses an integer x. * Starting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner: * Takahashi should take the card with the largest integer among the remaining card. * Aoki should take the card with the integer closest to x among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards. * The game ends when there is no card remaining. You are given Q candidates for the value of x: X_1, X_2, ..., X_Q. For each i (1 \leq i \leq Q), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses x = X_i.
import sys from bisect import * sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def solve(x): l=bisect_left(aa,x) r=n+1 while l+1<r: j=(l+r)//2 s=x*2-aa[j-1] i=bisect_left(aa,s) if j-i>n-j:r=j else:l=j ans=cs[n]-cs[l]+cs2[n-(n-l)*2] print(ans) n,q=MI() aa=LI() cs=[0] cs2=[0]*(n+1) for i,a in enumerate(aa): cs.append(cs[-1]+a) if i<2:cs2[i+1]=a else:cs2[i+1]=cs2[i-1]+a for _ in range(q): x=II() solve(x)
s060800740
Accepted
1,300
24,544
829
import sys from bisect import * sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def solve(x): l=bisect_left(aa,x) r=n+1 while l+1<r: j=(l+r)//2 s=x*2-aa[j-1] i=bisect_left(aa,s) if j-i>n-j:r=j else:l=j ans=cs[n]-cs[l] if n-(n-l)*2>0:ans+=+cs2[n-(n-l)*2] print(ans) n,q=MI() aa=LI() cs=[0] cs2=[0]*(n+1) for i,a in enumerate(aa): cs.append(cs[-1]+a) if i<2:cs2[i+1]=a else:cs2[i+1]=cs2[i-1]+a for _ in range(q): x=II() solve(x)
s848349486
p03711
u702719601
2,000
262,144
Wrong Answer
17
3,064
248
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.
data = input().split() x = int(data[0]) y = int(data[1]) L1 = [1,3,5,7,8,10,12] L2 = [4,6,9,11] L3 = [2] print(L1) print(L2) print(L3) if((x in L1 and y in L1) or (x in L2 and y in L2) or (x in L3 and y in L3)): print("Yes") else: print("No")
s603266797
Accepted
17
3,060
217
data = input().split() x = int(data[0]) y = int(data[1]) L1 = [1,3,5,7,8,10,12] L2 = [4,6,9,11] L3 = [2] if((x in L1 and y in L1) or (x in L2 and y in L2) or (x in L3 and y in L3)): print("Yes") else: print("No")
s952858009
p03478
u343150957
2,000
262,144
Wrong Answer
28
3,060
185
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()) count = 0 for i in range(n+1): ans = 0 while (i // 10) != 0: i = (i // 10) ans += (i % 10) if ans >= a and ans <= b: count += 1 print(count)
s167608753
Accepted
37
3,060
144
n, a, b = map(int, input().split()) ans = 0 for i in range(n+1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
s575658305
p03609
u865413330
2,000
262,144
Wrong Answer
17
2,940
109
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
s = list(input()) result = "" for i in range(len(s)): if i % 2 != 0: result += s[i] print(result)
s331818852
Accepted
17
2,940
69
x, t = map(int, input().split()) print(x - t) if x >= t else print(0)
s403415258
p02663
u497356352
2,000
1,048,576
Wrong Answer
23
9,412
601
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?
# coding:utf-8 import sys import datetime readline = sys.stdin.buffer.readline try: H1 = int(readline()) M1 = int(readline()) H2 = int(readline()) M2 = int(readline()) K = int(readline()) while not (0 <= H1 < 23 and 0 <= M1 < 59 and 0 <= H2 < 23 and 0 <= M2 < 59): H1 = int(readline()) M1 = int(readline()) H2 = int(readline()) M2 = int(readline()) K = int(readline()) if M2 > M1: a = (H2 - H1) * 60 + M2 - M1 print(a - K) if M2 < M1: b = (H2 - H1) * 60 + M1 - M2 print(b - K) except: print(1)
s004133242
Accepted
20
9,196
132
import sys readline = sys.stdin.buffer.readline h1, m1, h2, m2, k = map(int, readline().split()) print(60 * (h2 - h1) + m2 - m1 - k)
s039610041
p04029
u658978681
2,000
262,144
Wrong Answer
20
3,060
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s089529459
Accepted
18
2,940
34
n = int(input()) print(n*(n+1)//2)
s294477566
p03555
u725757838
2,000
262,144
Wrong Answer
18
3,060
69
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a=input() b=input() if b[::-1]==a: print("Yes") else: print("NO")
s694373802
Accepted
17
2,940
69
a=input() b=input() if b[::-1]==a: print("YES") else: print("NO")
s262485123
p02744
u896741788
2,000
1,048,576
Wrong Answer
20
3,184
420
In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be **isomorphic** when the following conditions are satisfied: * |s| = |t| holds. * For every pair i, j, one of the following holds: * s_i = s_j and t_i = t_j. * s_i \neq s_j and t_i \neq t_j. For example, `abcac` and `zyxzx` are isomorphic, while `abcac` and `ppppp` are not. A string s is said to be in **normal form** when the following condition is satisfied: * For every string t that is isomorphic to s, s \leq t holds. Here \leq denotes lexicographic comparison. For example, `abcac` is in normal form, but `zyxzx` is not since it is isomorphic to `abcac`, which is lexicographically smaller than `zyxzx`. You are given an integer N. Print all strings of length N that are in normal form, in lexicographically ascending order.
from time import time n=int(input()) from itertools import combinations as pe al=[] for i in range(n): for tu in pe(range(n-1),i): if tu: pre=tu[0] ans="a"*(pre+1) for d,v in enumerate(tu[1:]): ans+=chr(98+d)*(v-pre);pre=v ans+=chr(ord(ans[-1])+1)*(n-len(ans)) al.append(ans) else:print("a"*n) print(*sorted(al),sep="\n")
s006517301
Accepted
152
4,404
162
li="abcdefghijklmn" n=int(input()) def f(s,l,k): global li,n if l==n:print(s);return for i in range(2+k): f(s+li[i],l+1,max(i,k)) f("a",1,0)
s117010763
p03693
u632413369
2,000
262,144
Wrong Answer
27
9,096
71
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?
t = sum(map(int, input().split())) print('YES' if t % 4 == 0 else 'NO')
s348639278
Accepted
23
9,160
93
a, b, c = map(int, input().split()) print('YES' if (a * 100 + b * 10 + c) % 4 == 0 else 'NO')
s347939393
p03080
u899929023
2,000
1,048,576
Wrong Answer
18
2,940
103
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.
N=int(input()) st=input() R_num = st.count('R') if R_num*2 > N: print('YES') else: print('NO')
s564687742
Accepted
17
2,940
104
N=int(input()) st=input() R_num = st.count('R') if R_num*2 > N: print('Yes') else: print('No')
s968734020
p03228
u077337864
2,000
1,048,576
Wrong Answer
17
2,940
173
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
A, B, K = map(int, input().strip().split()) for k in range(K): if k % 2 == 0: A = A // 2 B = B + A // 2 else: B = B // 2 A = A + B // 2 print(A, B)
s455429653
Accepted
18
2,940
209
A, B, K = map(int, input().strip().split()) for k in range(K): if k % 2 == 0: _A = A // 2 _B = B + A // 2 A, B = _A, _B else: _B = B // 2 _A = A + B // 2 A, B = _A, _B print(A, B)
s434498413
p03130
u131634965
2,000
1,048,576
Wrong Answer
17
3,060
188
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
city={1:0, 2:0, 3:0, 4:0} for _ in range(3): a,b=map(int, input().split()) city[a]+=1 city[b]+=1 if list(city.values()).count(2)==2: print("Yes") else: print("No")
s242330009
Accepted
17
3,060
188
city={1:0, 2:0, 3:0, 4:0} for _ in range(3): a,b=map(int, input().split()) city[a]+=1 city[b]+=1 if list(city.values()).count(2)==2: print("YES") else: print("NO")
s167732768
p03680
u689322583
2,000
262,144
Wrong Answer
224
7,084
273
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
#coding: utf-8 N = int(input()) a = [] for i in range(N): a.append(int(input())) start = 0 count = 0 for i in range(N): count += 1 next = a[start] start = a[next-1] if(start == 2): print(count) break start -= 1 else: print(-1)
s693512344
Accepted
53
7,068
162
import sys N = list(map(int, sys.stdin)) bot = N[1] for i in range(N[0]): if bot == 2: print(i+1) break bot = N[bot] else: print(-1)
s638037713
p02418
u956226421
1,000
131,072
Wrong Answer
20
7,368
287
Write a program which finds a pattern $p$ in a ring shaped text $s$.
s = input() p = input() Ans = False for i in range(len(s)): for j in range(len(p)): if i + j >= len(s): i = -1 if s[i + j] != p[j]: break if j == len(p) - 1: Ans = True break if Ans: print('Yes') else: print('No')
s621562413
Accepted
60
7,528
322
s = input() p = input() Ans = False cnt = 0 for i in range(len(s)): for j in range(len(p)): if i + j >= len(s): i = -j if s[i + j] != p[j]: break cnt += 1 if cnt == len(p): Ans = True break cnt = 0 if Ans: print('Yes') else: print('No')
s879638043
p03493
u962423738
2,000
262,144
Wrong Answer
24
8,948
50
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
n=list(map(int,input().split())) print(n.count(1))
s681993158
Accepted
28
8,944
29
n=input() print(n.count("1"))
s472435594
p03854
u738622346
2,000
262,144
Wrong Answer
18
3,940
830
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() t = "" while len(t) < len(s): target_len = len(s) - len(t) if s[len(t)] == 'd': if target_len == 5: t += "dream" elif target_len == 7: t += "dreamer" elif target_len > 7: if s[len(t) + 5] != 'd' and s[len(t) + 7] != 'a': t += "dreamer" else: t += "dream" else: break else: if target_len == 5: t += "erase" elif target_len == 6: t += "eraser" elif target_len > 6: if s[len(t) + 4] != 'd' and s[len(t) + 6] != 'a': t += "eraser" else: t += "erase" else: break print(s, t, sep=" ") if s[0:len(t)] != t: break print("YES" if s == t else "NO")
s321967328
Accepted
50
3,188
440
s = input() div = ["dream", "dreamer", "erase", "eraser"] rev = [] t = "" s_rev = s[::-1] for d in div: rev.append(d[::-1]) result = True i = 0 while i < len(s): can_divide = False for d in rev: if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d: can_divide = True i += len(d) break if not can_divide: result = False break print("YES" if result else "NO")
s387112457
p03416
u090225501
2,000
262,144
Wrong Answer
96
3,060
134
Find the number of _palindromic numbers_ among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
a, b = map(int, input().split()) c = 0 for i in range(a, b + 1): x = list(str(i)) y = reversed(x) if x == y: c += 1 print(c)
s295796917
Accepted
103
2,940
137
a, b = map(int, input().split()) c = 0 for i in range(a, b + 1): x = str(i) y = ''.join(reversed(x)) if x == y: c += 1 print(c)
s493484404
p02612
u277175276
2,000
1,048,576
Wrong Answer
31
9,128
28
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) print(N%1000)
s353094030
Accepted
29
9,124
65
N=int(input()) b=N%1000 if b==0: print(0) else: print(1000-b)
s636447721
p03044
u188745744
2,000
1,048,576
Wrong Answer
339
28,892
406
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
N=int(input()) l=[0]*N com_l=[[] for i in range(N)] for i in range(N-1): X,Y,Z=list(map(int,input().split())) com_l[X-1].append((Y-1,Z%2)) for i in range(N-1): if com_l[i] != []: if l[i] == 0: for j,k in com_l[i]: if k ==1: l[j]=1 else: for j,k in com_l[i]: if k==0: l[j]=1 print(l)
s609442877
Accepted
472
39,852
491
from collections import deque N=int(input()) visited=[-1]*N l=[[] for i in range(N)] for i in range(N-1): a,b,c=map(int,input().split()) a-=1;b-=1 l[a].append((b,c%2)) l[b].append((a,c%2)) def ans(node,dis): visited[node]=0 que=deque(l[node]) while que: node,dis=que.popleft() visited[node]=dis for i,j in l[node]: if visited[i]==-1: visited[i]=(dis+j)%2 que.append((i,(dis+j)%2)) ans(0,0) for i in visited: print(i)
s378476269
p02796
u272336707
2,000
1,048,576
Wrong Answer
2,105
30,244
379
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
n = int(input()) li=[] lis=[] count_lis=[0]*n for i in range(n): li = list(map(int, input().split())) lis.append(li) lis.sort() for i in range(n): for j in range(i+1, n): if lis[i][0] + lis[i][1] > lis[j][0] - lis[j][1]: count_lis[i] += 1 count_lis[j] += 1 else: break num = n- int(sum(count_lis)/2) print(str(num))
s231696329
Accepted
521
20,096
309
n = int(input()) lis=[] count=0 for i in range(n): li=[None]*2 x, l = map(int, input().split()) li[0] = x+l li[1] = x-l lis.append(li) lis.sort() kari_r = -(10 ** 18) for r, l in lis: if kari_r > l: continue count+=1 kari_r = r print(count)
s675774474
p03370
u706159977
2,000
262,144
Wrong Answer
354
3,064
200
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.
m,x = [int(i) for i in input().split()] s=[] for i in range(m): list.append(s, int(input())) x = x-sum(s) print(sum(s)) print(x) ct = 0 while x>min(s): x = x - min(s) ct = ct+1 print(ct+m)
s031939020
Accepted
355
3,060
178
m,x = [int(i) for i in input().split()] s=[] for i in range(m): list.append(s, int(input())) x = x-sum(s) ct = 0 while x>=min(s): x = x - min(s) ct = ct+1 print(ct+m)
s921308107
p03836
u143976525
2,000
262,144
Wrong Answer
17
3,064
233
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="" y=ty-sy x=tx-sx ans +="U"*y ans +="R"*x ans +="D"*y ans +="L"*x ans +="L" ans +="U"*y ans +="R"*x ans +="D" ans +="R" ans +="D"*y ans +="L"*x ans +="U" print(ans)
s225235510
Accepted
17
3,064
321
sx,sy,tx,ty=map(int,input().split()) ans="" y=ty-sy x=tx-sx ans +="U"*y ans +="R"*x ans +="D"*y ans +="L"*x ans +="L" ans +="U"*(y+1) ans +="R"*(x+1) ans +="D" ans +="R" ans +="D"*(y+1) ans +="L"*(x+1) ans +="U" print(ans)
s714891429
p00085
u546285759
1,000
131,072
Wrong Answer
20
7,564
203
昔、ヨセフのおイモというゲームがありました。n 人が参加しているとしましょう。参加者は中心を向いて円陣を組み、1 から順番に番号が振られます。アツアツのおイモがひとつ、参加者 n (左の図内側の大きい数字の 30 )に渡されます。おイモを渡された参加者は右隣の参加者にそのおイモを渡します。 m 回目に渡された人は右隣の人に渡して円陣から抜けます(左の図では m = 9 の場合を表しています) 。 回渡す毎に一人ずつぬけ、最後に残った人が勝者となり、おイモをいただきます。 n ,m が決まってから、実際におイモを渡し始める前にどこにいたら勝てるかわかるといいですよね。上の図は 30 人の参加者で 9 人ごとに抜けるというルールでこのゲームをした場合を書き表しています。内側の大きい数字が参加者に振られた番号、外側の小さい数字が抜ける順番です。それによると、9,18,27,6,16,26 という順番で円陣から抜け出し、最後には 21 が残ることになります。すなわち 21 が勝者となります(小さい数字が 30 になっています)。 ゲーム参加者数 n と円陣から抜け出す参加者の間隔 m を入力し、勝者の番号を出力するプログラムを作成してください。ただし、m, n < 1000 とします。
n, m = map(int, input().split()) p, i = [i+1 for i in range(n)], m while True: p.pop(m-1) if len(p)==1: print(p[0]) break tmp = m+i-1 m = tmp%len(p) if tmp>len(p) else tmp
s685147294
Accepted
30
7,720
219
while True: n, m = map(int, input().split()) if n == 0: break p = [i for i in range(1, n+1)] idx = m-1 while len(p) != 1: v = p.pop(idx) idx = (idx+m-1) % len(p) print(*p)
s192931388
p02608
u343744945
2,000
1,048,576
Wrong Answer
2,206
9,312
928
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import math N=int(input()) sqN = int(math.sqrt(N))+1 sq=list() for i in range(1,N): sq.append(i*i) def isSquare(n): if n in sq: return True else: return False ans=list() for i in range(min(N,6)): ans.append(0) if N>5: for m in range(6,N+1): cnt = 0 for x in range(1,sqN): for y in range(1,sqN): b = x+y D = -3*(x*x+y*y)-2*x*y+4*m print(m,x,y,D,isSquare(D)) if D > 0 and isSquare(D): sqD=sq.index(D)+1 if (sqD-b) > 0 and (sqD-b) % 2 == 0: # print(x,y,z) # print(x*x+y*y+z*z+x*y+y*z-m) cnt+=1 if D < 0: break ans.append(cnt) for a in ans: print(a)
s163197746
Accepted
58
9,264
659
N=int(input()) cnts=[0 for i in range(N+1)] for x in range(1,100): x2=x*x for y in range(x,100): y2=y*y xy=x*y if x2+y*y+x*y+x+y > N: break for z in range(y,100): z2 = z*z M = x2+y2+z2+xy+y*z+z*x if M > N: break if x!=y: if y!=z: cnts[M]+=6 else: cnts[M]+=3 else: if y!=z: cnts[M]+=3 else: cnts[M]+=1 for a in cnts[1:N+1]: print(a)
s147818109
p02412
u017435045
1,000
131,072
Wrong Answer
20
5,592
258
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
while 1: n, x = map(int,input().split()) if n ==0 and x ==0: break ans = 0 for i in range(n-1): for j in range(i,n): for k in range(j,n): if i + j +k ==x: ans += 1 print(ans)
s134780393
Accepted
510
5,596
264
while 1: n, x = map(int,input().split()) if n == x ==0: break ans = 0 for i in range(1, n+1): for j in range(i+1,n+1): for k in range(j+1,n+1): if i + j +k ==x: ans += 1 print(ans)
s705689954
p03672
u827202523
2,000
262,144
Wrong Answer
17
3,064
275
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
def judge(S): half = int(len(S)/2) if S[:half] == S[half:]: return True else: return False S= input() l = len(S) if l%2 == 1: S = S[:-1] else: S = S[:-2] print(S) while S != "": if judge(S): break S = S[:-2] print(len(S))
s174907134
Accepted
17
3,060
266
def judge(S): half = int(len(S)/2) if S[:half] == S[half:]: return True else: return False S= input() l = len(S) if l%2 == 1: S = S[:-1] else: S = S[:-2] while S != "": if judge(S): break S = S[:-2] print(len(S))
s171990764
p03380
u794173881
2,000
262,144
Wrong Answer
154
14,428
245
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
n = int(input()) a = list(map(int,input().split())) sort_a = sorted(a,reverse=True) max_a = sort_a[0] ans=0 for i in range(n): if min(abs(max_a//2-sort_a[i]),abs(max_a//2-ans)) == abs(max_a//2-sort_a[i]): ans = sort_a[i] print(max_a,ans)
s029248815
Accepted
166
14,428
242
n = int(input()) a = list(map(int,input().split())) sort_a = sorted(a,reverse=True) max_a = sort_a[0] ans=0 for i in range(n): if min(abs(max_a/2-sort_a[i]),abs(max_a/2-ans)) == abs(max_a/2-sort_a[i]): ans = sort_a[i] print(max_a,ans)
s472034381
p03486
u311379832
2,000
262,144
Wrong Answer
17
3,060
148
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = list(input()) t = list(input()) s.sort() t.sort(reverse=True) ss = ''.join(s) ts = ''.join(t) if s < t: print('YES') else: print('NO')
s956109656
Accepted
17
3,060
148
s = list(input()) t = list(input()) s.sort() t.sort(reverse=True) ss = ''.join(s) ts = ''.join(t) if s < t: print('Yes') else: print('No')
s472826336
p03068
u243572357
2,000
1,048,576
Wrong Answer
17
2,940
143
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
n = int(input()) a = input() l = int(input()) for i in range(n): if a[l-1] != a[i]: print('*', sep='') else: print(a[l-1], sep='')
s361658932
Accepted
17
2,940
89
input() s = input() n = int(input()) print(*[i if i==s[n-1] else "*" for i in s], sep='')
s093519404
p02261
u159356473
1,000
131,072
Wrong Answer
50
7,680
852
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).
#coding:UTF-8 def BS(N,A): for i in range(N): for j in reversed(range(i+1,N)): if int(A[j][1:])<int(A[j-1][1:]): swap=A[j] A[j]=A[j-1] A[j-1]=swap return A def SS(N,A): for i in range(N): minj=i for j in range(i,N): if int(A[j][1:])<int(A[minj][1:]): minj=j swap=A[i] A[i]=A[minj] A[minj]=swap return A def Stable(A1,A2): ans="Stable" for i in range(len(A1)): if A1[i][1:]==A2[i][1:] and A1[i][:1]!=A2[i][:1]: ans="Not stable" return ans def SS2(N,A): A1=BS(N,A) print(" ".join(A1)) print("Stable") A2=SS(N,A) print(" ".join(A2)) print(Stable(A1,A2)) if __name__=="__main__": N=int(input()) a=input() A=a.split(" ") SS2(N,A)
s658822519
Accepted
50
7,796
886
#coding:UTF-8 def BS(N,A): for i in range(N): for j in reversed(range(i+1,N)): if int(A[j][1:])<int(A[j-1][1:]): swap=A[j] A[j]=A[j-1] A[j-1]=swap return A def SS(N,A): for i in range(N): minj=i for j in range(i,N): if int(A[j][1:]) < int(A[minj][1:]): minj=j swap=A[i] A[i]=A[minj] A[minj]=swap return A def Stable(A1,A2): ans="Stable" for i in range(len(A1)): if A1[i][1:]==A2[i][1:] and A1[i][:1]!=A2[i][:1]: ans="Not stable" return ans def SS2(N,A,B): A1=BS(N,A) print(" ".join(A1)) print("Stable") A2=SS(N,B) print(" ".join(A2)) print(Stable(A1,A2)) if __name__=="__main__": N=int(input()) a=input() A=a.split(" ") B=a.split(" ") SS2(N,A,B)
s175040961
p03386
u672494157
2,000
262,144
Wrong Answer
25
3,812
823
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 from functools import reduce import copy import math from pprint import pprint sys.setrecursionlimit(4100000) def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def int_inputs(num_of_input): ins = [int(input()) for i in range(num_of_input)] return ins def solve(inputs): [A, B, K] = string_to_int(inputs[0]) ret = set() count = 0 for v in range(A, B+1): if count >= K: break ret.add(v) count += 1 count = 0 for v in reversed(range(A, B+1)): if count >= K: break ret.add(v) count += 1 return ret def string_to_int(string): return list(map(int, string.split())) if __name__ == "__main__": ret = solve(inputs(1)) for r in ret: print(r)
s651745766
Accepted
40
4,068
837
import sys from functools import reduce import copy import math from pprint import pprint sys.setrecursionlimit(4100000) def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def int_inputs(num_of_input): ins = [int(input()) for i in range(num_of_input)] return ins def solve(inputs): [A, B, K] = string_to_int(inputs[0]) ret = set() count = 0 for v in range(A, B+1): if count >= K: break ret.add(v) count += 1 count = 0 for v in reversed(range(A, B+1)): if count >= K: break ret.add(v) count += 1 return sorted(list(ret)) def string_to_int(string): return list(map(int, string.split())) if __name__ == "__main__": ret = solve(inputs(1)) for r in ret: print(r)
s166658261
p03369
u292810930
2,000
262,144
Wrong Answer
17
2,940
140
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
S = input() 100 t = 0 for i in range(len(S)): if S[i] == 'o': t =+ 1 print(700 + t*100)
s122639953
Accepted
17
2,940
160
S = input() t = 0 for i in range(len(S)): if S[i] == 'o': t += 1 print(700 + t*100)
s250078492
p03044
u227082700
2,000
1,048,576
Wrong Answer
2,105
109,564
185
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
n=int(input()) a=[0]*n b=[] for i in range(n-1):b.append(list(map(int,input().split()))) b.sort() for i,j,k in b: if k%2==0:a[j-1]=a[i-1] else:a[j-1]=-(a[i-1]-1) for i in a:print(a)
s139357246
Accepted
693
61,716
509
from sys import stdin input = stdin.readline n=int(input()) b=[] for i in range(n-1):b.append(list(map(int,input().split()))) def BFS(K,edges,N): roots=[ [] for i in range(N)] for a,b,c in edges: roots[a-1]+=[(b-1,c)] roots[b-1]+=[(a-1,c)] dist=[-1]*N stack=[] stack.append(K) dist[K]=0 while stack: label=stack.pop(-1) for i,c in roots[label]: if dist[i]==-1: dist[i]=dist[label]+c stack+=[i] return dist a=BFS(0,b,n) for i in a:print(0 if i%2==0 else 1)
s077305925
p02612
u827627481
2,000
1,048,576
Wrong Answer
28
9,148
106
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()) for i in range(0,11): if i*1000 <= N and N < (i+1)*1000: break print(N-1000*i)
s640314608
Accepted
28
9,156
112
N = int(input()) for i in range(0,11): if i*1000 < N and N <= (i+1)*1000: break print(1000*(i+1) - N)
s351400302
p03699
u149249972
2,000
262,144
Wrong Answer
27
9,176
270
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
g = int(input()) grades = [] for i in range(g): grade = int(input()) grades.append(grade) total = sum(grades) grades.sort() grades = [0] + grades for grade in grades: if (total - grade) % 10 != 0: print(total - grade) break print(0)
s581332691
Accepted
25
9,096
333
g = int(input()) grades = [] for i in range(g): grade = int(input()) grades.append(grade) total = sum(grades) grades.sort() grades = [0] + grades count = 0 for grade in grades: if (total - grade) % 10 != 0: print(total - grade) break else: count += 1 if count == len(grades): print(0)
s360039838
p02612
u303039933
2,000
1,048,576
Wrong Answer
48
10,712
2,709
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.
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): lower, upper = [], [] i = 1 while i * i <= n: if n % i == 0: lower.append(i) if i != n // i: upper.append(n // i) i += 1 return lower + upper[::-1] @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def solve(): N = Scanner.int() print(N % 1000) def main(): # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
s597029114
Accepted
42
10,708
2,769
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): lower, upper = [], [] i = 1 while i * i <= n: if n % i == 0: lower.append(i) if i != n // i: upper.append(n // i) i += 1 return lower + upper[::-1] @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True @staticmethod def fact(N): res = {} tmp = N for i in range(2, int(N ** 0.5 + 1) + 1): cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i if cnt > 0: res[i] = cnt if tmp != 1: res[tmp] = 1 if res == {}: res[N] = 1 return res def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def solve(): N = Scanner.int() if N % 1000 == 0: print(0) else: print(1000 - N % 1000) def main(): # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
s522004811
p02602
u501451051
2,000
1,048,576
Wrong Answer
2,206
31,632
315
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
n ,k = map(int, input().split()) lis = list(map(int, input().split())) t = 1 for i in range(k): t *= lis[i] print(t) for i in range(k, n): tmp = lis[i-(k-1):i+1] a = 1 for j in tmp: a *= j if a > t: print('Yes') else: print('No') t = a a = 1
s133356482
Accepted
162
31,440
192
n ,k = map(int, input().split()) lis = list(map(int, input().split())) for i in range(k, n): l = lis[i-k] r = lis[i] if r > l: print('Yes') else: print('No')