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
s832323841
p03150
u358051561
2,000
1,048,576
Wrong Answer
17
3,060
207
A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string.
S = input() ky = 'keyence' lky = len(ky) tf = [all({S[:i] == ky[:i], S[-(lky-i):] == ky[-(lky-i):]}) for i in range(lky)] print(any(tf))
s968353265
Accepted
18
3,060
248
S = input() ky = 'keyence' lky = len(ky) tf = [all({S[:i] == ky[:i], S[-(lky-i):] == ky[-(lky-i):]}) for i in range(lky)] if any(tf): print('YES') else: print('NO')
s661987058
p02929
u545368057
2,000
1,048,576
Wrong Answer
2,105
17,800
599
There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares. The color of the i-th square from the left is black if the i-th character of S is `B`, and white if that character is `W`. You will perform the following operation exactly N times: choose two distinct squares, then invert the colors of these squares and the squares between them. Here, to invert the color of a square is to make it white if it is black, and vice versa. Throughout this process, you cannot choose the same square twice or more. That is, each square has to be chosen exactly once. Find the number of ways to make all the squares white at the end of the process, modulo 10^9+7. Two ways to make the squares white are considered different if and only if there exists i (1 \leq i \leq N) such that the pair of the squares chosen in the i-th operation is different.
from math import factorial N = int(input()) d = {"W":0, "B":1} ls = [d[s] for s in input()] r_ls = reversed(ls) xs = [] for i,r in enumerate(r_ls): xs.append(r + i) LR = [x%2 for x in list(reversed(xs))] print(LR) cnt = 0 num = 1 for lr in LR: if lr == 0: cnt += 1 else: num *= cnt cnt -= 1 ans = num * factorial(N) print(ans)
s972166544
Accepted
389
15,908
1,008
from math import factorial N = int(input()) d = {"W":0, "B":1} ls = [d[s] for s in input()] r_ls = reversed(ls) xs = [] mod = 10**9 + 7 for i,r in enumerate(r_ls): xs.append(r + i) LR = [x%2 for x in list(reversed(xs))] cnt = 0 num = 1 for lr in LR: if lr == 0: cnt += 1 else: num *= cnt cnt -= 1 cnt = max(0,cnt) num %= mod if cnt > 0: num = 0 ans = num * factorial(N) print(ans%mod)
s669480143
p03524
u896741788
2,000
262,144
Wrong Answer
26
4,340
294
Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is possible.
from collections import Counter as co s=input() n=len(s) l=co(list(s)).most_common() if n==1:print("Yes");exit() if n==2: print("Yes") if len(l)==2 else print("No") exit() if len(l)==2: print("No") exit() m=l[-1][1] for k,v in l: if v-m>1:print("No");break else:print("Yes")
s251488092
Accepted
98
4,340
254
from collections import Counter as co s=input() n=len(s) l=sorted(co(list(s)).values()) if len(l)<=2: print("YES") if n==len(l) else print("NO") else: m=l[0] for v in l: if v-m<=1:continue print("NO");exit() print("YES")
s183442487
p03957
u785578220
1,000
262,144
Wrong Answer
17
2,940
136
This contest is `CODEFESTIVAL`, which can be shortened to the string `CF` by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain `CF` from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string `CF` can be obtained from the string s by deleting some characters.
a = input() s = 0 t = 0 for i in a: if i == "C": s+=1 if i == "F" and s==1: t = 1 if t == 0: print("Yes") else:print("No")
s703166921
Accepted
18
2,940
136
a = input() s = 0 t = 0 for i in a: if i == "C": s=1 if i == "F" and s==1: t = 1 if t == 1: print("Yes") else:print("No")
s071667068
p04043
u411278350
2,000
262,144
Wrong Answer
17
2,940
117
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
A, B, C = map(int, input().split()) if {A, B, C} == {5, 7, 5} and A+B+C == 17: print("Yes") else: print("No")
s930725397
Accepted
17
2,940
114
A, B, C = map(int, input().split()) if {A, B, C} == {5, 7} and A+B+C == 17: print("YES") else: print("NO")
s932118099
p03139
u257162238
2,000
1,048,576
Wrong Answer
17
2,940
284
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.
def read(): N, A, B = map(int, input().strip().split()) return N, A, B def solve(N, A, B): intersect_max = min(A, B) intersect_min = max(0, A + B - N) return intersect_max, intersect_min if __name__ == '__main__': inputs = read() print(solve(*inputs))
s101942790
Accepted
17
2,940
294
def read(): N, A, B = map(int, input().strip().split()) return N, A, B def solve(N, A, B): intersect_max = min(A, B) intersect_min = max(0, A + B - N) return intersect_max, intersect_min if __name__ == '__main__': inputs = read() print("%d %d" % solve(*inputs))
s547799947
p02261
u657361950
1,000
131,072
Wrong Answer
20
5,616
1,165
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
import sys class Card: def __init__(self, card): self.card = card self.mark = card[0] self.value = int(card[1]) def print_cards(arr_print, arr_compare): n = len(arr_print) same = True for i in range(n): if arr_compare != None and arr_print[i].card != arr_compare[i].card: same = False sys.stdout.write(str(arr_print[i])) if i != n - 1: sys.stdout.write(' ') print() return same def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp def bubble_sort(arr): n = len(arr) for i in range(0, n): for j in range(n - 1, i, -1): if arr[j].value < arr[j - 1].value: swap(arr, j, j - 1) def selection_sort(arr): n = len(arr) for i in range(n): minj = i for j in range(i, n): if arr[j].value < arr[minj].value: minj = j if minj != i: swap(arr, i, minj) n = int(input()) arr = list(map(str, input().split())) cards1 = [None] * n cards2 = [None] * n for i in range(n): cards1[i] = Card(arr[i]) cards2[i] = Card(arr[i]) bubble_sort(cards1) selection_sort(cards2) print_cards(cards1, None) print('Stable') stable = print_cards(cards2, cards1) if stable == True: print('Stable') else: print('Not stable')
s251489802
Accepted
20
5,624
1,360
import sys class Card: def __init__(self, card): self.card = card self.mark = card[0] self.value = card[1] def equals(self, other): if self.mark != other.mark: return False if self.value != other.value: return False return True def __str__(self): return self.card def print_cards(cards, cards_): n = len(cards) same = True for i in range(n): if cards_ != None and cards[i].equals(cards_[i]) == False: same = False sys.stdout.write(str(cards[i])) if i != n - 1: sys.stdout.write(' ') print() return same def swap(cards, i, j): temp = cards[i] cards[i] = cards[j] cards[j] = temp def bubble_sort(cards): n = len(cards) for i in range(n): for j in range(n - 1, i, -1): if cards[j].value < cards[j - 1].value: swap(cards, j, j - 1) def selection_sort(cards): n = len(cards) for i in range(n): mini = i for j in range(i, n): if cards[j].value < cards[mini].value: mini = j if mini != i: swap(cards, i, mini) n = int(input()) input_list = list(map(str, input().split())) cards1 = [None] * n cards2 = [None] * n for i in range(n): cards1[i] = Card(input_list[i]) cards2[i] = Card(input_list[i]) bubble_sort(cards1) selection_sort(cards2) print_cards(cards1, None) print('Stable') stable = print_cards(cards2, cards1) if stable == True: print('Stable') else: print('Not stable')
s103697881
p03160
u114933382
2,000
1,048,576
Wrong Answer
98
13,716
297
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
import math N=int(input()) h = [int(i) for i in input().split()] h = h[::-1] +[-1,1] #print(h) i=0 count=0 while True: if h[i+1]*h[i+2]<1: break a=abs(h[i+1]-h[i]) b=abs(h[i+2]-h[i]) if a<b: i+=1 count+=a else: i+=2 count+=b print(count)
s700375496
Accepted
225
13,976
241
N = int(input()) h = [int(i) for i in input().split()] i = 1 dp = [0 for i in range(N)] K = 2 while not i==N: l = min(K,i) data = [dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,l+1)] dp[i] = min(data) i+=1 print(dp[N-1])
s746774183
p02606
u440608859
2,000
1,048,576
Wrong Answer
25
8,940
47
How many multiples of d are there among the integers between L and R (inclusive)?
l,r,d=map(int,input().split()) print(r//d-l//r)
s343713374
Accepted
28
8,772
86
l,r,d=map(int,input().split()) ans=(r-l)//d if r%d==0 or l%d==0: ans+=1 print(ans)
s196317794
p02414
u610816226
1,000
131,072
Wrong Answer
20
5,608
393
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
x, y, z = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(x)] B = [list(map(int, input().split())) for _ in range(y)] ans_s = [] ans = [] for i in range(x): for j in range(z): p = 0 for k in range(y): p += A[i][k] * B[k][j] ans_s.append(p) ans.append((ans_s)) for i in ans: print(' '.join([str(v) for v in ans]))
s548938654
Accepted
420
6,912
406
x, y, z = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(x)] B = [list(map(int, input().split())) for _ in range(y)] ans_s = [] ans = [] for i in range(x): ans_s = [] for j in range(z): p = 0 for k in range(y): p += A[i][k] * B[k][j] ans_s.append(p) ans.append((ans_s)) for i in ans: print(' '.join([str(v) for v in i]))
s212181858
p03693
u931889893
2,000
262,144
Wrong Answer
18
2,940
98
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = input().split() a = int(r + g + b) if a % 4 == 0: print('Yes') else: print('No')
s067802155
Accepted
17
2,940
98
r, g, b = input().split() a = int(r + g + b) if a % 4 == 0: print('YES') else: print('NO')
s708028040
p02821
u227082700
2,000
1,048,576
Wrong Answer
2,109
26,340
384
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
from heapq import heappop as hpop from heapq import heappush as hpush n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort(reverse=1) print(*a) a+=[-99999999999999] h=[] for i in range(n):hpush(h,[-a[i]*2,i]) count=m ans=0 while count!=0: x,i=hpop(h) x=-x c=min(count,1+(x!=a[i]*2)) count-=c ans+=c*x x-=a[i] x+=a[i+1] i+=1 hpush(h,[-x,i]) print(ans)
s682757559
Accepted
1,242
14,196
394
from bisect import bisect_right as br n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(n):a[i]*=-1 a.sort() b=[0] for i in a:b.append(b[-1]+i) ng=2*10**5+7 ok=-1 while ok+1!=ng: mid=(ng+ok)//2 co=0 for i in a:co+=br(a,-(mid+i)) if co<m:ng=mid else:ok=mid ans=0 co=0 for i in a: ind=br(a,-(ok+i)-1) co+=ind ans+=-b[ind]-i*ind ans+=(m-co)*ok print(ans)
s527694708
p02608
u020933954
2,000
1,048,576
Time Limit Exceeded
2,206
8,960
261
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).
def f(num): ans=0 for x in range(1,100): for y in range(1,100): for z in range(1,100): if x**2+y**2+z**2+x*y+y*z+z*x==num: ans+=1 return ans N=int(input()) for i in range(N): print(f(i+1))
s708267171
Accepted
942
9,380
256
N=int(input()) ans=[0 for _ in range(10050)] for x in range(1,105): for y in range(1,105): for z in range(1,105): v=x**2+y**2+z**2+x*y+y*z+z*x if v<10050: ans[v]+=1 for i in range(N): print(ans[i+1])
s027861346
p03471
u369079926
2,000
262,144
Wrong Answer
498
9,076
279
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
import sys N,Y = map(int,sys.stdin.readline().split(' ')) result = [-1] * 3 for x in range(N+1): for y in range(N-x+1): if (10000*x + 5000*y + 1000*(N-x-y)) == Y and (N-x-y) >= 0: result = [x,y,N-x-y] print(*result) else: print(*result)
s769397956
Accepted
500
9,152
261
import sys N,Y = map(int,sys.stdin.readline().split(' ')) result = [-1] * 3 for x in range(N+1): for y in range(N-x+1): if (10000*x + 5000*y + 1000*(N-x-y)) == Y and (N-x-y) >= 0: result = [x,y,N-x-y] break print(*result)
s839485729
p03549
u989345508
2,000
262,144
Wrong Answer
19
3,188
65
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n,m=map(int,input().split()) x=100*n+1800*m p=2**(-m) print(x//p)
s246687143
Accepted
19
2,940
69
n,m=map(int,input().split()) x=100*n+1800*m p=2**(-m) print(int(x/p))
s814901746
p02866
u920204936
2,000
1,048,576
Wrong Answer
370
13,892
317
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
n = int(input()) d = [int(i) for i in input().split()] a = sorted(d) print(a) start = 0 counta = 0 countb = 1 ans = 1 for i in a: if(start == i): counta += 1 else: ans *= countb ** counta start = i countb = counta counta = 1 ans *= countb ** counta print(ans%998244353)
s311741024
Accepted
373
14,396
572
n = int(input()) d = [int(i) for i in input().split()] a = sorted(d) checkZero = False if(d[0] != 0): checkZero = True for i in range(1,len(d)): if(d[i] == 0): checkZero = True if(checkZero): print(0) else: start = 0 counta = 0 countb = 1 ans = 1 for i in a: if(start == i): counta += 1 elif(i - start > 1): ans = 0 else: ans *= countb ** counta start = i countb = counta counta = 1 ans *= countb ** counta print(ans%998244353)
s215100260
p02398
u596993252
1,000
131,072
Wrong Answer
20
5,592
89
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
j=0 a,b,c=map(int,input().split()) for i in (a,b): if(c%i==0): j+=1 print(j)
s009364773
Accepted
20
5,596
96
j=0 a,b,c=map(int,input().split()) for i in range(a,b+1): if(c%i==0): j+=1 print(j)
s345098830
p03623
u593227551
2,000
262,144
Wrong Answer
21
3,060
92
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b= map(int, input().split()) if abs(x-a) > abs(x-b): print("A") else: print("B")
s401066323
Accepted
17
2,940
92
x,a,b= map(int, input().split()) if abs(x-a) < abs(x-b): print("A") else: print("B")
s525409682
p03149
u168416324
2,000
1,048,576
Wrong Answer
27
9,164
78
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
out=["No","Yes"] print(out[sorted(list(map(int,input().split())))==[1,4,7,9]])
s178278217
Accepted
29
9,156
79
out=["NO","YES"] print(out[sorted(list(map(int,input().split())))==[1,4,7,9]])
s236329091
p02613
u770468054
2,000
1,048,576
Wrong Answer
174
16,240
366
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) lists = [] AC = 0 TLE = 0 WA = 0 RE = 0 for i in range(N): S = str(input()) lists.append(S) for o in lists: if o == "AC": AC +=1 elif o == "TLE": TLE +=1 elif o == "WA": WA +=1 elif o == "RE": RE +=1 print("AC X "+str(AC)) print("WA X "+str(WA)) print("TLE X "+str(TLE)) print("RE X "+str(RE))
s629139460
Accepted
174
16,148
366
N = int(input()) lists = [] AC = 0 TLE = 0 WA = 0 RE = 0 for i in range(N): S = str(input()) lists.append(S) for o in lists: if o == "AC": AC +=1 elif o == "TLE": TLE +=1 elif o == "WA": WA +=1 elif o == "RE": RE +=1 print("AC x "+str(AC)) print("WA x "+str(WA)) print("TLE x "+str(TLE)) print("RE x "+str(RE))
s723299578
p02601
u633535831
2,000
1,048,576
Wrong Answer
31
9,112
150
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
a,b,c=map(int,input().split()) k=int(input()) cnt=0 while not a<b: cnt+=1 b*=2 while not b<c: cnt+=1 c*=2 print('yes' if k>=cnt else 'no')
s783914687
Accepted
32
9,172
150
a,b,c=map(int,input().split()) k=int(input()) cnt=0 while not a<b: cnt+=1 b*=2 while not b<c: cnt+=1 c*=2 print('Yes' if k>=cnt else 'No')
s406067854
p03130
u629350026
2,000
1,048,576
Wrong Answer
27
9,108
344
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.
a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) if b1==a2 and b2==a3: print("YES") elif b1==a3 and b3==a2: print("YES") elif b2==a1 and b1==a3: print("YES") elif b2==a3 and b3==a1: print("YES") elif b3==a1 and b1==a2: print("YES") elif b3==a2 and b2==a1: print("YES") else: print("NO")
s200382091
Accepted
26
9,148
244
a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) temp=[a1,a2,a3,b1,b2,b3] t1=temp.count(1) t2=temp.count(2) t3=temp.count(3) t4=temp.count(4) if max(t1,t2,t3,t4)==2: print("YES") else: print("NO")
s274926424
p03549
u893063840
2,000
262,144
Wrong Answer
31
9,372
192
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
n, m = map(int, input().split()) left = 1 prob = 0 ac = 0.5 ** m for i in range(1, 10000): prob += i * left * ac left -= left * ac ans = (100 * (n - m) + 1900 * m) * prob print(ans)
s025351075
Accepted
28
9,156
86
n, m = map(int, input().split()) ans = (100 * (n - m) + 1900 * m) * 2 ** m print(ans)
s621028938
p02697
u262597910
2,000
1,048,576
Wrong Answer
130
24,000
189
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
n,m = map(int, input().split()) ans = [[] for _ in range(m)] for i in range(m): ans[i].append(i+1) for i in range(m): ans[m-1-i].append(m+i+1) for i in range(m): print(*ans[i])
s611857576
Accepted
114
22,592
211
n,m = map(int, input().split()) ans = [] for i in range(2,m+1,2): ans.append([n-(i//2),(i//2)]) for i in range(1,m+1,2): ans.append([n//2-(i-1)//2,n//2+1+(i-1)//2]) for i in range(m): print(*ans[i])
s555995978
p03761
u220345792
2,000
262,144
Wrong Answer
23
3,316
311
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
from collections import Counter n = int(input()) data = [k for k in input()] ans = Counter(data) for i in range(n-1): tmp = Counter([k for k in input()]) for j in set(data): ans[j] = min(ans[j], tmp[j]) ans_list = list(ans.elements()) ans_list.sort() answer = "" for i in ans_list: answer += i*ans[i]
s869980295
Accepted
23
3,316
388
from collections import Counter n = int(input()) data = [k for k in input()] ans = Counter(data) for i in range(n-1): tmp = Counter([k for k in input()]) for j in set(data): ans[j] = min(ans[j], tmp[j]) # print(j, ans[j], tmp[j], min(ans[j], tmp[j])) ans_list = list(set(list(ans.elements()))) ans_list.sort() answer = "" for i in ans_list: answer += i*ans[i] print(answer)
s533282908
p03407
u541610817
2,000
262,144
Wrong Answer
17
2,940
80
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 = (int(_) for _ in input().split()) print('Yes' if a + b <= c else 'No')
s300318238
Accepted
17
2,940
81
a, b, c = (int(_) for _ in input().split()) print('Yes' if a + b >= c else 'No')
s078347355
p04043
u877470025
2,000
262,144
Wrong Answer
17
2,940
147
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
#2033~ import sys [a,b,c] = list(map(int,input().split())) #print(a,b,c) if sorted([a,b,c])==[5,5,7]: print('Yes') else: print('No')
s183041843
Accepted
17
2,940
147
#2033~ import sys [a,b,c] = list(map(int,input().split())) #print(a,b,c) if sorted([a,b,c])==[5,5,7]: print('YES') else: print('NO')
s462762062
p03605
u296518383
2,000
262,144
Wrong Answer
18
2,940
53
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
print("Yes" if sorted(list(input()))[1]==9 else "No")
s719321017
Accepted
17
2,940
55
print("Yes" if sorted(list(input()))[1]=="9" else "No")
s949356013
p03303
u957722693
2,000
1,048,576
Wrong Answer
17
3,060
163
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
S = input() N = int(input()) output=[] print(len(S)) for i in range(len(S)): if i%N==0: output.append(S[i]) output2 = ''.join(output) print(output2)
s755146520
Accepted
17
2,940
148
S = input() N = int(input()) output=[] for i in range(len(S)): if i%N==0: output.append(S[i]) output2 = ''.join(output) print(output2)
s088040941
p03251
u451598761
2,000
1,048,576
Wrong Answer
18
3,060
325
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
def main(): N,M,X,Y = map(int, input().split()) max_x = max(map(int,input().split())) min_y = min(map(int,input().split())) max_xx = max(max_x,X) min_yy = min(min_y,Y) print(max_x) print(min_y) print(max_xx) print(min_yy) if min_yy - max_xx > 0: print("No War") else: print("War") main()
s874043659
Accepted
17
3,060
329
def main(): N,M,X,Y = map(int, input().split()) max_x = max(map(int,input().split())) min_y = min(map(int,input().split())) max_xx = max(max_x,X) min_yy = min(min_y,Y) #print(max_x) #print(min_y) #print(max_xx) if min_yy - max_xx > 0: print("No War") else: print("War") main()
s171588213
p03997
u430223993
2,000
262,144
Wrong Answer
17
2,940
79
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()) area = h*(a+b)/2 print(area)
s733817625
Accepted
17
2,940
84
a = int(input()) b = int(input()) h = int(input()) area = (a+b)*h/2 print(int(area))
s352280723
p03564
u078349616
2,000
262,144
Wrong Answer
17
2,940
94
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
N = int(input()) K = int(input()) ans = 1 for i in range(N): ans += min(K, ans*2) print(ans)
s331896887
Accepted
17
2,940
126
N = int(input()) K = int(input()) ans = 1 for i in range(N): if K+ans <= ans*2: ans += K else: ans *= 2 print(ans)
s959401253
p02612
u426506583
2,000
1,048,576
Wrong Answer
29
9,140
187
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.
S = 1e3 def main(): n = int(input()) r = n % S if r == 0: return int(r) else: return int(S - r) if __name__ == '__main__': # print(main()) main()
s922029567
Accepted
30
9,012
187
S = 1e3 def main(): n = int(input()) r = n % S if r == 0: return int(r) else: return int(S - r) if __name__ == '__main__': print(main()) # main()
s407373643
p03448
u867736259
2,000
262,144
Wrong Answer
48
3,060
230
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) d = int(input()) count = 0 for i in range(a): for j in range(b): for k in range(c): if (500*i + 100*j + 50*k) == d: count += 1 print(count)
s222880223
Accepted
53
3,060
236
a = int(input()) b = int(input()) c = int(input()) d = int(input()) count = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if (500*i + 100*j + 50*k) == d: count += 1 print(count)
s046285006
p03473
u449473917
2,000
262,144
Wrong Answer
17
2,940
38
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
n = int(input()) d = 25+24-n print(d)
s147007592
Accepted
17
2,940
35
n = int(input()) d = 48-n print(d)
s912740410
p03591
u201082459
2,000
262,144
Wrong Answer
17
2,940
76
Ringo is giving a present to Snuke. Ringo has found out that Snuke loves _yakiniku_ (a Japanese term meaning grilled meat. _yaki_ : grilled, _niku_ : meat). He supposes that Snuke likes grilled things starting with `YAKI` in Japanese, and does not like other things. You are given a string S representing the Japanese name of Ringo's present to Snuke. Determine whether S starts with `YAKI`.
s = str(input()) if s[0:3] == 'YAKI': print('Yes') else: print('No')
s252922537
Accepted
17
2,940
76
s = str(input()) if s[0:4] == 'YAKI': print('Yes') else: print('No')
s100564364
p03997
u218843509
2,000
262,144
Wrong Answer
18
2,940
66
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a, b, h = [int(input()) for _ in range(3)] print((a + b) * h / 2)
s628989098
Accepted
17
2,940
73
a, b, h = [int(input()) for _ in range(3)] print(int((a + b) * h / 2))
s379366465
p03485
u836737505
2,000
262,144
Wrong Answer
17
2,940
53
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b = map(int, input().split()) print(int((a+b)/2)+1)
s297008001
Accepted
17
2,940
74
import math a,b = map(int, input().split()) print(int(math.ceil((a+b)/2)))
s883794922
p03377
u699296734
2,000
262,144
Wrong Answer
25
9,028
93
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 a <= x <= a+b: print("Yes") else: print("No")
s622722209
Accepted
25
9,088
93
a, b, x = map(int, input().split()) if a <= x <= a+b: print("YES") else: print("NO")
s756235293
p03487
u652150585
2,000
262,144
Wrong Answer
141
27,040
225
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a **good sequence**. Here, an sequence b is a **good sequence** when the following condition holds true: * For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence.
import sys import collections input=sys.stdin.readline n=int(input()) l=list(map(int,input().split())) li=collections.Counter(l) print(li) a=0 for k,v in li.items(): if k>v: a+=v else: a+=v-k print(a)
s996787049
Accepted
77
18,336
223
import sys import collections input=sys.stdin.readline n=int(input()) l=list(map(int,input().split())) s=collections.Counter(l) #print(s) a=0 for k,v in s.items(): if k>v: a+=v else: a+=v-k print(a)
s065908348
p03024
u872030436
2,000
1,048,576
Wrong Answer
17
2,940
112
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
S = input() sum_maru = sum([1 for c in S if c == 'x']) if sum_maru >= 8: print("No") else: print("Yes")
s722724378
Accepted
18
2,940
112
S = input() sum_maru = sum([1 for c in S if c == 'x']) if sum_maru >= 8: print("NO") else: print("YES")
s539342834
p04044
u425762225
2,000
262,144
Wrong Answer
17
3,064
445
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
#!/usr/bin/env python3 # 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(): N, l = map(int,input().split()) s = [] for i in range(N): s.append(input()) s_sorted = sorted(s) answer = "" for i in range(N): answer += s[i] print(answer) if __name__ == '__main__': main()
s842660936
Accepted
18
3,060
356
#!/usr/bin/env python3 # 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(): N, l = map(int,input().split()) s_sorted = sorted([input() for i in range(N)]) print("".join(s_sorted)) if __name__ == '__main__': main()
s624377359
p03698
u430928274
2,000
262,144
Wrong Answer
26
9,044
196
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s = input() flag = 1 for i in range(len(s)-1) : for j in range(i+1,len(s)) : if s[i] == s[j] : flag = 0 if flag == 1 : print("Yes") else : print("No")
s158109426
Accepted
28
8,900
184
s = input() flag = 1 for i in range(len(s)-1) : for j in range(i+1,len(s)) : if s[i] == s[j] : flag = 0 if flag == 1 : print("yes") else : print("no")
s303429511
p02678
u691018832
2,000
1,048,576
Wrong Answer
2,266
2,405,580
625
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra n, m = map(int, readline().split()) graph = [[0] * n for _ in range(n)] ab = [list(map(int, readline().split())) for _ in range(m)] for a, b in ab: graph[a - 1][b - 1] = 1 graph[b - 1][a - 1] = 1 _, ans = dijkstra(csr_matrix(graph), return_predecessors=True) if any(int(v) == -9999 for v in ans[0][1:]): print('NO') else: print('YES') print('\n'.join(map(str, ans[0][1:] + 1)))
s489689567
Accepted
355
40,592
668
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) def bfs(s): from collections import deque check = [0] * (n + 1) check[s] = 1 q = deque([s]) while q: now = q.popleft() for next in graph[now]: if check[next] == 0: check[next] = str(now) q.append(next) return check n, m = map(int, readline().split()) graph = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, readline().split()) graph[a].append(b) graph[b].append(a) print('Yes') print('\n'.join(bfs(1)[2:]))
s716150855
p02259
u776145982
1,000
131,072
Wrong Answer
20
5,592
576
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
# -*- coding: UTF-8 -*- N = int(input()) A = list(map(int,input().split())) #print('input') #print(N) #print(A) flag = 1 i = 0 cnt = 0 while flag: flag = 0 for j in reversed(range(i+1,N)): if A[j] < A[j-1]: tmp = A[j-1] A[j-1] = A[j] A[j] = tmp flag = 1 cnt += 1 i += 1 #print('output') print(A) print(cnt)
s590962926
Accepted
20
5,600
605
# -*- coding: UTF-8 -*- N = int(input()) A = list(map(int,input().split())) #print('input') #print(N) #print(A) flag = 1 i = 0 cnt = 0 while flag: flag = 0 for j in reversed(range(i+1,N)): if A[j] < A[j-1]: tmp = A[j-1] A[j-1] = A[j] A[j] = tmp flag = 1 cnt += 1 i += 1 #print('output') #print(A) print(' '.join(map(str,A))) print(cnt)
s046366823
p03644
u629350026
2,000
262,144
Wrong Answer
19
2,940
47
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
N=int(input()) i=1 while i<=N: i=i*2 print(i)
s731316485
Accepted
17
2,940
54
N=int(input()) i=1 while i<=int(N/2): i=i*2 print(i)
s668343924
p04043
u277802731
2,000
262,144
Wrong Answer
17
2,940
85
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
#42a l = sorted(input().split()) print(l) print('YES' if l==['5','5','7'] else 'NO')
s867526030
Accepted
17
2,940
76
#42a l = sorted(input().split()) print('YES' if l==['5','5','7'] else 'NO')
s954826713
p03944
u174273188
2,000
262,144
Wrong Answer
17
3,064
548
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.
def resolve(): w, h, n = map(int, input().split()) min_x, min_y = 0, 0 max_x, max_y = w, h for _ in range(n): x, y, a = map(int, input().split()) if a == 1: min_x = min(min_x, x) elif a == 2: max_x = max(max_x, x) elif a == 3: min_y = min(min_y, y) elif a == 4: max_y = max(max_y, y) if min_x >= max_x or min_y >= max_y: print(0) else: print((max_x - min_x) * (max_y - min_y)) if __name__ == "__main__": resolve()
s190614841
Accepted
18
3,064
548
def resolve(): w, h, n = map(int, input().split()) min_x, min_y = 0, 0 max_x, max_y = w, h for _ in range(n): x, y, a = map(int, input().split()) if a == 1: min_x = max(min_x, x) elif a == 2: max_x = min(max_x, x) elif a == 3: min_y = max(min_y, y) elif a == 4: max_y = min(max_y, y) if min_x >= max_x or min_y >= max_y: print(0) else: print((max_x - min_x) * (max_y - min_y)) if __name__ == "__main__": resolve()
s983127748
p02245
u825008385
1,000
131,072
Wrong Answer
40
6,380
5,307
The goal of the 8 puzzle problem is to complete pieces on $3 \times 3$ cells where one of the cells is empty space. In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 8 as shown below. 1 3 0 4 2 5 7 8 6 You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps). 1 2 3 4 5 6 7 8 0 Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle.
import copy z = 0 [N, d] = [3, 0] check_flag = [[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4], [2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1], [3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2], [4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3], [3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4], [2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3], [1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2], [4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1]] start = [] goal = [[i + j*N for i in range(1, N + 1)] for j in range(N)] goal[2][2] = 0 for i in range(N): start.append(list(map(int, input().split()))) def manhattan(value, pairs): h = 0 if value == 1: h = (pairs[0] + pairs[1]) if value == 2: h = (pairs[0] + abs(pairs[1] - 1)) if value == 3: h = (pairs[0] + abs(pairs[1] - 2)) if value == 4: h = (abs(pairs[0] - 1) + pairs[1]) if value == 5: h = (abs(pairs[0] - 1) + abs(pairs[1] - 1)) if value == 6: h = (abs(pairs[0] - 1) + abs(pairs[1] - 2)) if value == 7: h = (abs(pairs[0] - 2) + pairs[1]) if value == 8: h = (abs(pairs[0] - 2) + abs(pairs[1] - 1)) return h def flag_array(flag, input): flag.pop(0) flag.append(input) return flag s_h = 0 for i in range(N): for j in range(N): s_h += manhattan(start[i][j], [i, j]) # print(s_h) for i in range(N): check = start[i].count(0) if check != 0: [s_r, s_c] = [i, start[i].index(0)] break if i == 3: print("Error") while True: d += 1 queue = [] flag = [0 for i in range(12)] queue.append([s_h, start, 0, [s_r, s_c], flag]) #while True: while len(queue) != 0: short_n = queue.pop(0) h = short_n[0] - short_n[2] state = short_n[1] g = short_n[2] [r, c] = short_n[3] flag = short_n[4] print("left_Q: ", len(queue), "depth: ", d, "h: ", h, "g: ", g, "state: ", state, "g+h: ", short_n[0], "flag: ", flag[len(flag) - 1]) #print(short_n[0]) #print(state) #print(g) if h == 0: print(short_n[2]) print(z) break if r - 1 >= 0 and flag[len(flag) - 1] != 3: [temp, temp_array] = [copy.deepcopy(state), flag[:]] h = short_n[0] - short_n[2] - manhattan(temp[r - 1][c], [r - 1, c]) + manhattan(temp[r - 1][c], [r, c]) [temp[r][c], temp[r - 1][c]] = [temp[r - 1][c], temp[r][c]] #if temp[r][c] != goal[r][c]: #[r, c] = [r - 1, c] #if temp #h = manhattan(temp) #print("1: ", h, temp) if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r - 1, c], flag_array(temp_array, 1)]) if c + 1 < N and flag[len(flag) - 1] != 4: #print("2: ") [temp, temp_array] = [copy.deepcopy(state), flag[:]] #temp_array = copy.deepcopy(flag) h = short_n[0] - short_n[2] - manhattan(temp[r][c + 1], [r, c + 1]) + manhattan(temp[r][c + 1], [r, c]) [temp[r][c], temp[r][c + 1]] = [temp[r][c + 1], temp[r][c]] #print("2: ", h, temp) if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r, c + 1], flag_array(temp_array, 2)]) if r + 1 < N and flag[len(flag) - 1] != 1: #print("3: ") [temp, temp_array] = [copy.deepcopy(state), flag[:]] #temp_array = copy.deepcopy(flag) h = short_n[0] - short_n[2] - manhattan(temp[r + 1][c], [r + 1, c]) + manhattan(temp[r + 1][c], [r, c]) [temp[r][c], temp[r + 1][c]] = [temp[r + 1][c], temp[r][c]] #print("3: ", h, temp) if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r + 1, c], flag_array(temp_array, 3)]) if c - 1 >= 0 and flag[len(flag) - 1] != 2: #print("4: ") [temp, temp_array] = [copy.deepcopy(state), flag[:]] h = short_n[0] - short_n[2] - manhattan(temp[r][c - 1], [r, c - 1]) + manhattan(temp[r][c - 1], [r, c]) [temp[r][c], temp[r][c - 1]] = [temp[r][c - 1], temp[r][c]] if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r, c - 1], flag_array(temp_array, 4)]) queue.sort(key = lambda data:data[0]) queue.sort(key = lambda data:data[2], reverse = True) data = [] g_data = [] """ for i in range(len(queue)): data.append(str(queue[i][0])) g_data.append(str(queue[i][2])) #print(queue[i]) print("g+h: ",' '.join(data)) print("g: ",' '.join(g_data)) """ if state == goal: break
s936065007
Accepted
1,710
6,376
3,135
import copy [N, d] = [3, 0] start = [] goal = [[i + j*N for i in range(1, N + 1)] for j in range(N)] goal[2][2] = 0 for i in range(N): start.append(list(map(int, input().split()))) def manhattan(value, pairs): h = 0 if value == 1: h = (pairs[0] + pairs[1]) if value == 2: h = (pairs[0] + abs(pairs[1] - 1)) if value == 3: h = (pairs[0] + abs(pairs[1] - 2)) if value == 4: h = (abs(pairs[0] - 1) + pairs[1]) if value == 5: h = (abs(pairs[0] - 1) + abs(pairs[1] - 1)) if value == 6: h = (abs(pairs[0] - 1) + abs(pairs[1] - 2)) if value == 7: h = (abs(pairs[0] - 2) + pairs[1]) if value == 8: h = (abs(pairs[0] - 2) + abs(pairs[1] - 1)) return h s_h = 0 for i in range(N): for j in range(N): s_h += manhattan(start[i][j], [i, j]) for i in range(N): check = start[i].count(0) if check != 0: [s_r, s_c] = [i, start[i].index(0)] break if i == 3: print("Error") while True: d += 1 flag = 0 queue = [[s_h, start, 0, [s_r, s_c], flag]] while len(queue) != 0: short_n = queue.pop(0) h = short_n[0] - short_n[2] state = short_n[1] g = short_n[2] [r, c] = short_n[3] flag = short_n[4] if h == 0: print(short_n[2]) break if r - 1 >= 0 and flag != 3: temp = copy.deepcopy(state) h = short_n[0] - short_n[2] - manhattan(temp[r - 1][c], [r - 1, c]) + manhattan(temp[r - 1][c], [r, c]) [temp[r][c], temp[r - 1][c]] = [temp[r - 1][c], temp[r][c]] if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r - 1, c], 1]) if c + 1 < N and flag != 4: temp = copy.deepcopy(state) h = short_n[0] - short_n[2] - manhattan(temp[r][c + 1], [r, c + 1]) + manhattan(temp[r][c + 1], [r, c]) [temp[r][c], temp[r][c + 1]] = [temp[r][c + 1], temp[r][c]] if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r, c + 1], 2]) if r + 1 < N and flag != 1: temp = copy.deepcopy(state) h = short_n[0] - short_n[2] - manhattan(temp[r + 1][c], [r + 1, c]) + manhattan(temp[r + 1][c], [r, c]) [temp[r][c], temp[r + 1][c]] = [temp[r + 1][c], temp[r][c]] if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r + 1, c], 3]) if c - 1 >= 0 and flag != 2: temp = copy.deepcopy(state) h = short_n[0] - short_n[2] - manhattan(temp[r][c - 1], [r, c - 1]) + manhattan(temp[r][c - 1], [r, c]) [temp[r][c], temp[r][c - 1]] = [temp[r][c - 1], temp[r][c]] if g + 1 + h <= d: queue.append([h + g + 1, temp, g + 1, [r, c - 1], 4]) queue.sort(key = lambda data:data[0]) queue.sort(key = lambda data:data[2], reverse = True) data = [] g_data = [] if state == goal: break
s395077900
p01131
u124909914
8,000
131,072
Wrong Answer
90
6,736
603
Alice さんは Miku さんに携帯電話でメールを送ろうとしている。 携帯電話には入力に使えるボタンは数字のボタンしかない。 そこで、文字の入力をするために数字ボタンを何度か押して文字の入力を行う。携帯電話の数字ボタンには、次の文字が割り当てられており、ボタン 0 は確定ボタンが割り当てられている。この携帯電話では 1 文字の入力が終わったら必ず確定ボタンを押すことになっている。 * 1: . , ! ? (スペース) * 2: a b c * 3: d e f * 4: g h i * 5: j k l * 6: m n o * 7: p q r s * 8: t u v * 9: w x y z * 0: 確定ボタン 例えば、ボタン 2、ボタン 2、ボタン 0 と押すと、文字が 'a' → 'b' と変化し、ここで確定ボタンが押されるので、文字 b が出力される。 同じ数字を続けて入力すると変化する文字はループする。すなわち、ボタン 2 を 5 回押して、次にボタン 0 を押すと、文字が 'a' → 'b' → 'c' → 'a' → 'b' と変化し、ここで確定ボタンを押されるから 'b' が出力される。 何もボタンが押されていないときに確定ボタンを押すことはできるが、その場合には何も文字は出力されない。 あなたの仕事は、Alice さんが押したボタンの列から、Alice さんが作ったメッセージを再現することである。
#!/usr/bin/python3 def atoi(c): return ord(c) - ord('0') table = [(), #dummy ('.',',','!','?'),\ ('a','b','c'), ('d','e','f'), ('g','h','i'), ('j','k','l'), ('m','n','o'), ('p','q','r','s'), ('t','u','v'), ('w','x','y','z')] n = int(input()) for i in range(n): digits = list(input()) s = "" c = '' m = 0 for d in digits: if d == '0': s += c c = '' m = 0 else: c = table[atoi(d)][m] m = (m + 1) % len(table[atoi(d)]) print(s)
s034600245
Accepted
90
6,736
607
#!/usr/bin/python3 def atoi(c): return ord(c) - ord('0') table = [(), #dummy ('.',',','!','?',' '),\ ('a','b','c'), ('d','e','f'), ('g','h','i'), ('j','k','l'), ('m','n','o'), ('p','q','r','s'), ('t','u','v'), ('w','x','y','z')] n = int(input()) for i in range(n): digits = list(input()) s = "" c = '' m = 0 for d in digits: if d == '0': s += c c = '' m = 0 else: c = table[atoi(d)][m] m = (m + 1) % len(table[atoi(d)]) print(s)
s173810570
p03493
u277641173
2,000
262,144
Wrong Answer
17
2,940
71
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.
s=input() c=1 for i in range(0,3): if s[i]==1: c+=1 print(c)
s388839665
Accepted
18
2,940
73
s=input() c=0 for i in range(0,3): if s[i]=="1": c+=1 print(c)
s916956871
p03505
u163320134
2,000
262,144
Wrong Answer
17
2,940
141
_ButCoder Inc._ runs a programming competition site called _ButCoder_. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is 0, and a user whose rating reaches K or higher is called _Kaiden_ ("total transmission"). Note that a user's rating may become negative. Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by A in each of his odd-numbered contests (first, third, fifth, ...), and decreases by B in each of his even-numbered contests (second, fourth, sixth, ...). According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden?
import math g,a,b=map(int,input().split()) if g<=a: print(1) else: if a<=b: print(-1) else: print(2*math.ceil((g-a)//(a-b))+1)
s237984367
Accepted
17
3,060
188
g,a,b=map(int,input().split()) if g<=a: print(1) else: if a<=b: print(-1) else: if (g-a)%(a-b)==0: print(2*((g-a)//(a-b))+1) else: print(2*((g-a)//(a-b)+1)+1)
s731162602
p03548
u143492911
2,000
262,144
Wrong Answer
24
2,940
129
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
x,y,z=map(int,input().split()) total=x-z one_pair=y+z k=0 while True: k+=1 if total<=one_pair*k: break print(k-1)
s530930300
Accepted
25
2,940
153
x,y,z=map(int,input().split()) total=x-z one_pair=y+z k=1 while one_pair*k<total: k+=1 if one_pair*k%total==0: print(k) else: print(k-1)
s770604514
p04031
u088552457
2,000
262,144
Wrong Answer
17
2,940
208
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
# -*- coding: utf-8 -*- import math n = input() numbers = list(map(int, input().split())) print(numbers) s = sum(numbers) t = math.floor(s/2) r = 0 for num in numbers: r += abs((num - t) * 2) print(r)
s276697101
Accepted
27
3,060
386
# -*- coding: utf-8 -*- import math n = input() numbers = list(map(int, input().split())) unique_numbers = list(set(numbers)) if len(unique_numbers) == 1: print(0) exit(0) min_num = min(numbers) max_num = max(numbers) results = [] for i in range(min_num, max_num): r = 0 for num in numbers: r += abs((num - i) ** 2) results.append(r) min_r = min(results) print(min_r)
s887721082
p03597
u911276694
2,000
262,144
Wrong Answer
18
3,188
42
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
N=int(input()) A=int(input()) print(N**-A)
s114958151
Accepted
17
2,940
48
N=int(input()) A=int(input()) B=N**2-A print(B)
s700623447
p02255
u895660619
1,000
131,072
Wrong Answer
20
7,652
191
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.
N = int(input()) A = [int(N) for N in input().split()] for i in range(1, N-1): v = A[i] j = i - 1 while(j >=0 and A[j] > v): A[j+1] = A[j] j -= 1 A[j+1] = v
s335177997
Accepted
30
7,744
270
N = int(input()) A = [int(a) for a in input().split()] print((" ").join((str(a) for a in A))) for i in range(1, N): v = A[i] j = i - 1 while(j >=0 and A[j] > v): A[j+1] = A[j] j -= 1 A[j+1] = v print((" ").join((str(a) for a in A)))
s837250781
p02393
u614711522
1,000
131,072
Wrong Answer
30
6,724
182
Write a program which reads three integers, and prints them in ascending order.
nums = input().split() a = int( nums[0]) b = int( nums[1]) c = int( nums[2]) if a > b: tmp = a a = b b = tmp if b > c: tmp = b b = c c = tmp print( a, b, c)
s455372517
Accepted
30
6,724
226
nums = input().split() a = int( nums[0]) b = int( nums[1]) c = int( nums[2]) if a > b: tmp = a a = b b = tmp if b > c: tmp = b b = c c = tmp if a > b: tmp = a a = b b = tmp print( a, b, c)
s233712772
p03162
u411203878
2,000
1,048,576
Wrong Answer
587
29,840
402
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
n=int(input()) ab = [] for _ in range(n): a, b, c = (int(x) for x in input().split()) ab.append([a, b, c]) dp = [0]*n memo = -1 memos = -1 for i in range(n): for j in range(3): if i == 0: dp[i] = max(ab[0]) memos = j elif memo != j and dp[i] < dp[i-1]+ab[i][j]: dp[i] = dp[i-1]+ab[i][j] memos = j memo = memos print(dp)
s859495421
Accepted
1,134
44,100
343
n=int(input()) ab = [] for _ in range(n): a, b, c = (int(x) for x in input().split()) ab.append([a, b, c]) dp = [[0 for i in range(3)] for j in range(n+1)] for i in range(n): for j in range(3): for k in range(3): if j != k: dp[i+1][k] = max([dp[i+1][k], dp[i][j]+ab[i][k]]) print(max(dp[n]))
s876494419
p03407
u464912173
2,000
262,144
Wrong Answer
17
2,940
69
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
a,b,c = map(int, input().split()) print('YES' if a+b >= c else 'NO')
s526170402
Accepted
17
2,940
69
a,b,c = map(int, input().split()) print('Yes' if a+b >= c else 'No')
s611664939
p03457
u182249053
2,000
262,144
Wrong Answer
324
21,052
976
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
N = int(input()) X = [] temp = [] for i in range(N): X.append([int(i) for i in input().split()]) for i in X: if temp == []: if i[0] % 2 == 0 and (i[1] + i[2]) % 2 == 1: print("No") break elif i[0] % 2 == 1 and (i[1] + i[2]) % 2 == 0: print("No") break else: if i[1] + i[2] < i[0]: print("Yes") break else: print("No") break else: if (i[0]-temp[0]) % 2 == 0 and (abs(i[1]-temp[1])+abs(i[2]-temp[2])) % 2 == 1: print("No") break elif (i[0]-temp[0]) % 2 == 1 and (abs(i[1]-temp[1])+abs(i[2]-temp[2])) % 2 == 0: print("No") break else: if abs(i[1]-temp[1])+abs(i[2]-temp[2]) < i[0]-temp[0]: print("Yes") break else: print("No") break temp = i
s222355815
Accepted
395
21,108
365
N = int(input()) X = [] flag = True dt=0 dx=0 dy=0 for i in range(N): X.append([int(i) for i in input().split()]) for i in X: dt = abs(i[0] - dt) dx = abs(i[1] - dx) dy = abs(i[2] - dy) if dx + dy > dt: flag = False elif (dt - dx - dy) % 2 == 1: flag = False if flag == False: print("No") else: print("Yes")
s767773301
p02865
u547608423
2,000
1,048,576
Wrong Answer
17
2,940
67
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
N=int(input()) if N%2==1: print(N//2) else: print(N/2-1)
s714261884
Accepted
17
2,940
77
N=int(input()) if N%2==1: print(int(N//2)) else: print(int(N/2-1))
s812245432
p03456
u729836751
2,000
262,144
Wrong Answer
17
2,940
121
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a = [int(item) for item in input().split()] seki = a[0] * a[1] if seki % 2 == 0: print('Even') else: print('Odd')
s946070597
Accepted
43
2,940
151
a = int(input().replace(' ', '')) count = 1 while count < a: if a == count * count: print('Yes') exit() count += 1 print('No')
s470156570
p03958
u597374218
1,000
262,144
Wrong Answer
17
2,940
90
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
K,T=map(int,input().split()) a=list(map(int,input().split())) print(max(a)-(K-max(a))-1,0)
s199137109
Accepted
18
2,940
95
K,T=map(int,input().split()) a=list(map(int,input().split())) print(max(max(a)-(K-max(a))-1,0))
s177121835
p02678
u613350811
2,000
1,048,576
Wrong Answer
586
35,016
535
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
from collections import deque N, M = map(int, input().split()) graph = [[] for i in range(N+1)] ans = [0] * (N+1) for i in range(M): f, t = map(int, input().split()) graph[f].append(t) graph[t].append(f) D = deque([1]) checked = [0] * (N+1) checked[0] = 1 checked[1] = 1 while D: n = D.popleft() for i in graph[n]: if checked[i] == 1: continue checked[i] = 1 ans[i] = n D.append(i) if 0 in checked: print("No") else: for i in range(2,N+1): print(ans[i])
s999532951
Accepted
643
34,876
552
from collections import deque N, M = map(int, input().split()) graph = [[] for i in range(N+1)] ans = [0] * (N+1) for i in range(M): f, t = map(int, input().split()) graph[f].append(t) graph[t].append(f) D = deque([1]) checked = [0] * (N+1) checked[0] = 1 checked[1] = 1 while D: n = D.popleft() for i in graph[n]: if checked[i] == 1: continue checked[i] = 1 ans[i] = n D.append(i) if 0 in checked: print("No") else: print("Yes") for i in range(2,N+1): print(ans[i])
s933291440
p03457
u225627575
2,000
262,144
Wrong Answer
481
12,824
613
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
N = int(input()) x = [] y = [] t = [] distance = [] x.append(0) y.append(0) t.append(0) for i in range(N): STR = input().split() t.append(int(STR[0])) x.append(int(STR[1])) y.append(int(STR[2])) dis = 0 flag = True for i in range(1,N+1): time = t[i] - t[i-1] dis = abs(x[i] -x[i-1])+abs(y[i] - y[i-1]) print(time) print(dis) if time != dis : if time < dis: #print("time<dis") flag = False elif time - dis > 0 and (time-dis) %2 == 1: #print("time%2") flag = False if flag: print("Yes") else: print("No")
s163340108
Accepted
351
11,780
615
N = int(input()) x = [] y = [] t = [] distance = [] x.append(0) y.append(0) t.append(0) for i in range(N): STR = input().split() t.append(int(STR[0])) x.append(int(STR[1])) y.append(int(STR[2])) dis = 0 flag = True for i in range(1,N+1): time = t[i] - t[i-1] dis = abs(x[i] -x[i-1])+abs(y[i] - y[i-1]) #print(time) #print(dis) if time != dis : if time < dis: #print("time<dis") flag = False elif time - dis > 0 and (time-dis) %2 == 1: #print("time%2") flag = False if flag: print("Yes") else: print("No")
s971693750
p03447
u166621202
2,000
262,144
Wrong Answer
17
2,940
98
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X = int(input()) A = int(input()) B = int(input()) tmp=X-A while tmp < B: tmp=tmp-B print(tmp)
s775699197
Accepted
17
2,940
100
X = int(input()) A = int(input()) B = int(input()) tmp=X-A while tmp >= B: tmp=tmp-B print(tmp)
s159496082
p03795
u552502395
2,000
262,144
Wrong Answer
17
2,940
44
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
N = int(input()) print(800*N - 200 * (N/15))
s504270414
Accepted
17
2,940
51
N = int(input()) print(800 * N - 200 * int(N /15))
s854950976
p02927
u066411497
2,000
1,048,576
Wrong Answer
42
3,700
466
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
data = input().split(" ") M = int(data[0]) D = int(data[1]) count = 0 for i in range(M): i += 1 for j in range(D): j += 1 print(i,"/",j) if j >= 10: d_1 = int(str(j)[:1]) d_10 = int(str(j)[1:]) if d_1 >= 2 and d_10 >= 2: if d_1 * d_10 == i: count += 1 print(count)
s245777828
Accepted
27
3,064
434
data = input().split(" ") M = int(data[0]) D = int(data[1]) count = 0 for i in range(M): i += 1 for j in range(D): j += 1 if j >= 10: d_1 = int(str(j)[:1]) d_10 = int(str(j)[1:]) if d_1 >= 2 and d_10 >= 2: if d_1 * d_10 == i: count += 1 print(count)
s334307697
p02614
u285833393
1,000
1,048,576
Wrong Answer
160
9,308
483
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
import copy H, W, K = map(int, input().split()) C = [[c for c in input()] for _ in range(H)] count = 0 for i in range(2 ** (H + W)): V = copy.deepcopy(C) for j in range(H + W): if (i >> j) & 1: if j < H: for k in range(W): V[j][k] = "R" else: for k in range(H): V[k][j - H] = "R" print(sum(V, [])) if sum(V, []).count("#") == K: count += 1 print(count)
s347724014
Accepted
145
9,352
461
import copy H, W, K = map(int, input().split()) C = [[c for c in input()] for _ in range(H)] count = 0 for i in range(2 ** (H + W)): V = copy.deepcopy(C) for j in range(H + W): if (i >> j) & 1: if j < H: for k in range(W): V[j][k] = "R" else: for k in range(H): V[k][j - H] = "R" if sum(V, []).count("#") == K: count += 1 print(count)
s647919366
p03997
u842689614
2,000
262,144
Wrong Answer
17
2,940
62
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h/2)
s072977740
Accepted
17
2,940
65
a=int(input()) b=int(input()) h=int(input()) print((a+b)*h//2)
s585619266
p03370
u444722572
2,000
262,144
Wrong Answer
527
4,660
252
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N,X=map(int,input().split()) m=[int(input()) for _ in range(N)] m.sort() cnt=0 flg=1 flg2=1 X-=sum(m) cnt+=len(m) while flg2==1: if X>=min(m): X-=min(m) cnt+=1 print(X,cnt,2) else: flg2=0 print(cnt)
s188439245
Accepted
360
3,188
229
N,X=map(int,input().split()) m=[int(input()) for _ in range(N)] m.sort() cnt=0 flg=1 flg2=1 X-=sum(m) cnt+=len(m) while flg2==1: if X>=min(m): X-=min(m) cnt+=1 else: flg2=0 print(cnt)
s412825483
p03434
u782685137
2,000
262,144
Wrong Answer
24
3,444
231
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
from collections import deque n = int(input()) a = list(map(int, input().split())) a = deque(sorted(a))#[::-1] alice, bob = 0, 0 for i in range(n): if i%2==0: alice += a.popleft() else: bob += a.popleft() print(alice - bob)
s993326079
Accepted
19
3,064
187
n = int(input()) a = list(map(int, input().split())) a = sorted(a)[::-1] alice, bob = 0, 0 for i in range(n): if i%2==0: alice += a.pop(0) else: bob += a.pop(0) print(alice - bob)
s981788926
p03548
u945359338
2,000
262,144
Wrong Answer
19
2,940
48
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
A,B,C = map(int,input().split()) print((A+C)//B)
s772517855
Accepted
17
2,940
52
A,B,C = map(int,input().split()) print((A-C)//(B+C))
s462121245
p03711
u502149531
2,000
262,144
Wrong Answer
17
3,060
388
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.
x, y = map(int,input().split()) if x == 2 : print ('NO') if x == 4 or x == 6 or x == 9 or x == 11 : if y == 4 or y == 6 or y == 9 or y == 11 : print ('YES') else : print ('NO') if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12 : if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12 : print ('YES') else : print ('NO')
s074029130
Accepted
17
3,060
388
x, y = map(int,input().split()) if x == 2 : print ('No') if x == 4 or x == 6 or x == 9 or x == 11 : if y == 4 or y == 6 or y == 9 or y == 11 : print ('Yes') else : print ('No') if x == 1 or x == 3 or x == 5 or x == 7 or x == 8 or x == 10 or x == 12 : if y == 1 or y == 3 or y == 5 or y == 7 or y == 8 or y == 10 or y == 12 : print ('Yes') else : print ('No')
s000421824
p03129
u914797917
2,000
1,048,576
Wrong Answer
17
2,940
63
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N,K=map(int, input().split()) print('YES' if N>2*K-1 else 'NO')
s277503923
Accepted
17
2,940
94
N,K=map(int, input().split()) if K<0: print('NO') else: print('YES' if N>=2*K-1 else 'NO')
s395362946
p03854
u673559119
2,000
262,144
Wrong Answer
18
3,188
387
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`.
# coding:utf-8 S = input() t=0 n = int(len(S)/5)+1 def endcheck(t,S): if t==len(S): print("YES") for i in range(n): if S[t:t+5] =="dream": t += 5 endcheck(t,S) elif S[t:t+7] =="dreamer": t += 7 endcheck(t,S) elif S[t:t+5] =="erase": t += 5 endcheck(t,S) elif S[t:t+6] =="eraser": t += 6 endcheck(t,S) else: print("NO") break
s468634997
Accepted
32
3,316
381
# coding:utf-8 S = input() s =len(S) t=0 def endcheck(t,s): if t==s: print("YES") while t < s: if S[-t-5:s-t] =="dream": t += 5 endcheck(t,s) elif S[-t-7:s-t] =="dreamer": t += 7 endcheck(t,s) elif S[-t-5:s-t] =="erase": t += 5 endcheck(t,s) elif S[-t-6:s-t] =="eraser": t += 6 endcheck(t,s) else: print("NO") break
s084563882
p02397
u589886885
1,000
131,072
Wrong Answer
20
7,696
142
Write a program which reads two integers x and y, and prints them in ascending order.
import sys n = sys.stdin.readlines() for i in n: a = [int(x) for x in i.split()] if a[0] == a[1]: break print(*sorted(a))
s785086724
Accepted
40
8,104
192
import sys n = sys.stdin.readlines() for i in n: a, b = [int(x) for x in i.split()] if a == 0 and b == 0: break if a < b: print(a, b) else: print(b, a)
s004236959
p03385
u740284863
2,000
262,144
Wrong Answer
18
2,940
80
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
S = str(input()) if S[0] != S[1] !=S[2]: print("YES") else: print("NO")
s194603334
Accepted
18
2,940
100
S = str(input()) L = {"a","b","c"} if {S[0],S[1],S[2]} == L: print("Yes") else: print("No")
s826800352
p03738
u968846084
2,000
262,144
Wrong Answer
17
3,064
279
You are given two positive integers A and B. Compare the magnitudes of these numbers.
A=input() B=input() a=len(A) b=len(B) if a>b: print("GREATER") elif b>a: print("LESS") else: i=0 while i<a: if A[i]>B[i]: print("GRATER") break elif B[i]>A[i]: print("LESS") break else: i=i+1 if i==a: print("EQUAL")
s132055749
Accepted
17
3,064
280
A=input() B=input() a=len(A) b=len(B) if a>b: print("GREATER") elif b>a: print("LESS") else: i=0 while i<a: if A[i]>B[i]: print("GREATER") break elif B[i]>A[i]: print("LESS") break else: i=i+1 if i==a: print("EQUAL")
s991825668
p03643
u487288850
2,000
262,144
Wrong Answer
29
9,024
36
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
s = input() print("0"*(3-len(s))+s)
s795532491
Accepted
29
8,968
42
s = input() print("ABC"+"0"*(3-len(s))+s)
s180892316
p03637
u324207738
2,000
262,144
Wrong Answer
65
14,252
257
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
n = int(input()) a = list(map(int, input().split())) b1, b2, b4 = 0, 0, 0 for i in a: if i%4 == 0: b4 += 1 elif i%2 == 0: b2 += 1 else: b1 += 1 if b2 > 0: b1 += 1 if b1 <= b4+1: print('yes') else: print('no')
s086339989
Accepted
66
14,252
257
n = int(input()) a = list(map(int, input().split())) b1, b2, b4 = 0, 0, 0 for i in a: if i%4 == 0: b4 += 1 elif i%2 == 0: b2 += 1 else: b1 += 1 if b2 > 0: b1 += 1 if b1 <= b4+1: print('Yes') else: print('No')
s303144338
p02255
u688488162
1,000
131,072
Wrong Answer
20
7,576
320
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.
n = int(input()) a = list(map(int,input().split())) for i in range(1,n): v = a[i] j = i-1 while j >= 0 and a[j] > v: a[j+1] = a[j] j = j-1 a[j+1] = v for k in range(n): if k == n-1: print(a[k],end='') else: print(a[k],end=' ') print()
s673368522
Accepted
30
8,088
318
n = int(input()) a = list(map(int,input().split())) for i in range(n): v = a[i] j = i-1 while j >= 0 and a[j] > v: a[j+1] = a[j] j = j-1 a[j+1] = v for k in range(n): if k == n-1: print(a[k],end='') else: print(a[k],end=' ') print()
s065655707
p03387
u748311048
2,000
262,144
Wrong Answer
17
2,940
201
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
l=list(map(int, input().split())) l.sort() cnt=0 while l[0]!=l[2]: l.sort() print(l) if l[1] == l[2]: l[0] += 2 else: l[0] += 1 l[1] += 1 cnt+=1 print(cnt)
s650206152
Accepted
18
3,060
230
l=list(map(int, input().split())) l.sort() cnt=0 while l[0]!=l[1] or l[0]!=l[2] or l[1]!=l[2]: l.sort() #print(l) if l[1] == l[2]: l[0] += 2 else: l[0] += 1 l[1] += 1 cnt+=1 print(cnt)
s359850951
p03399
u128748980
2,000
262,144
Wrong Answer
17
2,940
186
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
A = input() B = input() C = input() D = input() print(A,B,C,D) if A <= B: train = A else: train = B if C <= D: bus = C else: bus = D total = train + bus print(total)
s738187681
Accepted
18
2,940
207
A = int(input()) B = int(input()) C = int(input()) D = int(input()) #print(A,B,C,D) if A <= B: train = A else: train = B if C <= D: bus = C else: bus = D total = train + bus print(total)
s835783956
p03474
u037221289
2,000
262,144
Wrong Answer
19
3,188
138
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.
import re A,B = map(int,input().split(' ')) S = input() match = re.match("[0-9]{A}-[0-9]",S) if match: print('Yes') else: print('No')
s728248435
Accepted
17
2,940
116
A,B = map(int,input().split()) S = input() if S.count('-')==1 and S[A]=='-': print('Yes') else: print('No')
s049530288
p02678
u240630407
2,000
1,048,576
Wrong Answer
683
60,124
1,861
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
# import itertools # import math import sys sys.setrecursionlimit(500*500) # import numpy as np from collections import deque # N = int(input()) # S = input() # n, *a = map(int, open(0)) N, M = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # A_B = [list(map(int,input().split())) for _ in range(M)] # S = input() # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # edges = [list(map(int,input().split())) for _ in range(M)] # tree = [[] for _ in range(N + 1)] # for edge in edges: # tree[edge[0]].append([edge[1], edge[2]]) # tree[edge[1]].append([edge[0], edge[2]]) # for l in tree[s]: # dfs(tree, l[0]) # dfs(tree, 1) # arr = [] # temp = n # if temp%i==0: # cnt=0 # while temp%i==0: # cnt+=1 # temp //= i # arr.append([i, cnt]) # if temp!=1: # arr.append([temp, 1]) # if arr==[]: # arr.append([n, 1]) # return arr edges = [list(map(int,input().split())) for _ in range(M)] tree = [[] for _ in range(N + 1)] for edge in edges: tree[edge[0]].append(edge[1]) tree[edge[1]].append(edge[0]) depth = [-1] * (N + 1) depth[1] = 0 d = deque() d.append(1) while d: v = d.popleft() for i in tree[v]: if depth[i] != -1: continue depth[i] = depth[v] + 1 d.append(i) ans = depth[2:] print(*ans, sep="\n")
s393137151
Accepted
686
60,024
1,914
# import itertools # import math import sys sys.setrecursionlimit(500*500) # import numpy as np from collections import deque # N = int(input()) # S = input() # n, *a = map(int, open(0)) N, M = map(int, input().split()) # A = list(map(int, input().split())) # B = list(map(int, input().split())) # A_B = [list(map(int,input().split())) for _ in range(M)] # S = input() # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # edges = [list(map(int,input().split())) for _ in range(M)] # tree = [[] for _ in range(N + 1)] # for edge in edges: # tree[edge[0]].append([edge[1], edge[2]]) # tree[edge[1]].append([edge[0], edge[2]]) # for l in tree[s]: # dfs(tree, l[0]) # dfs(tree, 1) # arr = [] # temp = n # if temp%i==0: # cnt=0 # while temp%i==0: # cnt+=1 # temp //= i # arr.append([i, cnt]) # if temp!=1: # arr.append([temp, 1]) # if arr==[]: # arr.append([n, 1]) # return arr tree = [[] for _ in range(N + 1)] edges = [list(map(int,input().split())) for _ in range(M)] for edge in edges: tree[edge[0]].append(edge[1]) tree[edge[1]].append(edge[0]) depth = [-1] * (N + 1) depth[1] = 0 d = deque() d.append(1) ans = [0] * (N + 1) while d: v = d.popleft() for i in tree[v]: if depth[i] != -1: continue depth[i] = depth[v] + 1 ans[i] = v d.append(i) print('Yes') print(*ans[2:], sep="\n")
s921349806
p02578
u917642744
2,000
1,048,576
Wrong Answer
180
38,392
332
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
a=input() b=input() c=b.split() d=map(int,c) main=list(d) sum=0 print(main) for i in range(len(main)-2): stool=main[i]-main[i+1] if stool>0: main[i+1]+=stool sum+=stool stool=main[len(main)-2]-main[len(main)-1] if stool>0: sum+=stool main[len(main)-1]+=stool print("sum = ",sum, "main = ",main)
s894862829
Accepted
145
33,560
296
a=input() b=input() c=b.split() d=map(int,c) main=list(d) sum=0 for i in range(len(main)-2): stool=main[i]-main[i+1] if stool>0: main[i+1]+=stool sum+=stool stool=main[len(main)-2]-main[len(main)-1] if stool>0: sum+=stool main[len(main)-1]+=stool print(sum)
s256867950
p03998
u518064858
2,000
262,144
Wrong Answer
18
3,064
334
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.
s1=input() s2=input() s3=input() x=s1[0] s1.lstrip(x) while min(len(s1),len(s2),len(s3))==0: if x=="a": x=s1[0] s1.lstrip(x) elif x=="b": x=s2[0] s2.lstrip(x) else: x=s3[0] s3.lstrip(x) if len(s1)==0: print("A") elif len(s2)==0: print("B") else: print("C")
s244256800
Accepted
18
3,064
399
s1=input() s2=input() s3=input() x=s1[0] s1=s1[1:] while (len(s1)!=0 or x!="a") and (len(s2)!=0 or x!="b") and (len(s3)!=0 or x!="c") : if x=="a": x=s1[0] s1=s1[1:] elif x=="b": x=s2[0] s2=s2[1:] else: x=s3[0] s3=s3[1:] if len(s1)==0 and x=="a": print("A") elif len(s2)==0 and x=="b": print("B") else: print("C")
s733969429
p00008
u927516039
1,000
131,072
Wrong Answer
30
7,600
232
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
n=int(input()) cnt=0 for i in range(10): for j in range(10): for k in range(10): for l in range(10): if i+j+k+l==n: cnt=cnt+1 print(i,j,k,l) print(cnt)
s678269357
Accepted
190
7,692
263
import sys for line in sys.stdin: n=int(line) cnt=0 for i in range(10): for j in range(10): for k in range(10): for l in range(10): if i+j+k+l==n: cnt=cnt+1 print(cnt)
s357835336
p03730
u950708010
2,000
262,144
Wrong Answer
17
2,940
159
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 = (int(i) for i in input().split()) flag = 0 for i in range(102): if(a*i)%b == c: flag =1 if flag == 0: ans ='No' else: ans = 'Yes' print(ans)
s745315521
Accepted
18
3,060
159
a,b,c = (int(i) for i in input().split()) flag = 0 for i in range(102): if(a*i)%b == c: flag =1 if flag == 0: ans ='NO' else: ans = 'YES' print(ans)
s951691087
p03997
u571832343
2,000
262,144
Wrong Answer
27
9,116
61
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.
u=int(input()) d=int(input()) h=int(input()) print((u+d)*h/2)
s108604581
Accepted
26
9,044
66
u=int(input()) d=int(input()) h=int(input()) print(int((u+d)*h/2))
s968830187
p04035
u143509139
2,000
262,144
Wrong Answer
139
14,052
323
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
n, l = map(int, input().split()) a = list(map(int, input().split())) ma = 0 midx = 0 for i in range(n - 1): if ma < a[i] + a[i + 1]: midx = i ma = a[i] + a[i + 1] if l > ma: print('Impossible') else: print('Posiible') for i in range(midx): print(i + 1) for i in range(n - 1, midx, -1): print(i)
s074032884
Accepted
137
14,060
323
n, l = map(int, input().split()) a = list(map(int, input().split())) ma = 0 midx = 0 for i in range(n - 1): if ma < a[i] + a[i + 1]: midx = i ma = a[i] + a[i + 1] if l > ma: print('Impossible') else: print('Possible') for i in range(midx): print(i + 1) for i in range(n - 1, midx, -1): print(i)
s602141780
p02694
u306033313
2,000
1,048,576
Wrong Answer
22
9,168
107
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
x = int(input()) n = 100 count = 0 while n <= x: n *= 1.01 n = int(n) count += 1 print(count)
s390944871
Accepted
25
9,164
106
x = int(input()) n = 100 count = 0 while n < x: n *= 1.01 n = int(n) count += 1 print(count)
s581451654
p03215
u781755665
2,525
1,048,576
Wrong Answer
2,620
42,948
823
One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
# coding: utf-8 def check(subarray, msb, threshold): count = 0 index = 0 for i, element in enumerate(subarray): if element >= 2 ** msb: count += 1 subarray[i] -= 2 ** msb else: index = i break return (subarray[:index], 2 ** msb) if count >= threshold else (subarray, 0) nums = [int(n) for n in input().split()] array = [int(n) for n in input().split()] subarray = [] for i in range(nums[0]): for j in range(i+1): subarray.append(sum(array[j:j+nums[0]-i])) subarray.sort(reverse=True) temp = subarray[0] msb = 0 while temp // 2 != 0: temp = temp // 2 msb += 1 print(subarray) answer = 0 while msb >= 0: subarray, add = check(subarray, msb, nums[1]) answer += add subarray.sort(reverse=True) msb -= 1 print(answer)
s004543245
Accepted
2,071
23,880
785
# coding: utf-8 def calculate_msb(maximum): msb = 0 while (maximum // 2) != 0: maximum = maximum // 2 msb += 1 return msb def examine(beauties, msb, threshold): count = 0 mask = 2 ** msb passed = [] for beauty in beauties: if (beauty & mask) == mask: passed.append(beauty) count += 1 return (passed, mask) if count >= threshold else (beauties, 0) n, threshold = map(int, input().split()) array = [int(element) for element in input().split()] beauties = [] for i in range(n): for j in range(i+1): beauties.append(sum(array[j:j+n-i])) msb = calculate_msb(beauties[0]) answer = 0 while msb >= 0: beauties, add = examine(beauties, msb, threshold) answer += add msb -= 1 print(answer)
s144958944
p03474
u881621300
2,000
262,144
Wrong Answer
18
3,060
354
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.
def solve(): a,b = map(int, input().split()) s = input() for i in s[0:a]: if '0' > i or i > '9': print("NO") return if s[a] != '-': print("NO") return for i in s[a+1:a+b+1]: if '0' > i or i > '9': print("NO") return print("YES") return solve()
s819312298
Accepted
18
3,060
354
def solve(): a,b = map(int, input().split()) s = input() for i in s[0:a]: if '0' > i or i > '9': print("No") return if s[a] != '-': print("No") return for i in s[a+1:a+b+1]: if '0' > i or i > '9': print("No") return print("Yes") return solve()
s250269570
p04044
u975644365
2,000
262,144
Wrong Answer
17
3,060
99
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n,l = map(int, input().split()) l = [input() for i in range(n)] l.sort() print(l) print(''.join(l))
s602390897
Accepted
17
3,060
90
n,l = map(int, input().split()) l = [input() for i in range(n)] l.sort() print(''.join(l))
s214308031
p03351
u305965165
2,000
1,048,576
Wrong Answer
18
2,940
134
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a, b, c, d = (int(i) for i in input().split()) if abs(a-c) < d or (abs(a-b)<d and abs(b-c<d)): print("Yes") else: print("No")
s468380788
Accepted
18
2,940
137
a, b, c, d = (int(i) for i in input().split()) if abs(a-c) <= d or (abs(a-b)<=d and abs(b-c)<=d): print("Yes") else: print("No")
s595702754
p03095
u663101675
2,000
1,048,576
Wrong Answer
31
4,340
161
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
import collections N = int(input()) S = list(input()) c = collections.Counter(S) v = c.values() count = 1 for v in c.values(): count *= (v+1) print(count)
s719490069
Accepted
26
4,260
175
import collections N = int(input()) S = list(input()) c = collections.Counter(S) v = c.values() count = 1 for v in c.values(): count *= (v+1) print((count-1)%(10**9+7))
s772137072
p02742
u171132311
2,000
1,048,576
Wrong Answer
18
2,940
110
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h,w=map(int,input().split()) result = h*w if result%2==0: print(result/2) else: print(int(result/2)+1)
s079613725
Accepted
17
3,060
149
h,w=map(int,input().split()) result = h*w if h==1 or w==1: print(1) elif result%2==0: print(int(result//2)) else: print(int(result//2)+1)
s390699611
p03543
u566574814
2,000
262,144
Wrong Answer
17
3,060
138
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
N = input() if N[0] == N[1] and N[1] == N[2]: print("yes") elif N[1] == N[2] and N[2] == N[3]: print("yes") else: print("NO")
s674486546
Accepted
18
2,940
100
N = input() if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]: print("Yes") else: print("No")