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
s100984830
p04012
u737840172
2,000
262,144
Wrong Answer
17
2,940
350
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
# Vicfred # implementation w = input() english = {} for ch in w: if ch in english: english[ch] += 1 else: english[ch] = 1 beautiful = True for value in english.values(): if value%2 == 1: beautiful = False if beautiful: print("YES") else: print("NO")
s072770482
Accepted
17
2,940
350
# Vicfred # implementation w = input() english = {} for ch in w: if ch in english: english[ch] += 1 else: english[ch] = 1 beautiful = True for value in english.values(): if value%2 == 1: beautiful = False if beautiful: print("Yes") else: print("No")
s428252452
p03836
u798129018
2,000
262,144
Wrong Answer
20
3,060
166
Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up. Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1. Here, both the x\- and y-coordinates before and after each movement must be integers. He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy). Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty). Under this condition, find a shortest path for him.
sx,sy,tx,ty = map(int,input().split()) print("U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(ty-sy)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sy+1)+"U")
s848363094
Accepted
17
3,060
166
sx,sy,tx,ty = map(int,input().split()) print("U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx)+"L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U")
s612885880
p02742
u018679195
2,000
1,048,576
Wrong Answer
18
3,060
151
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:
import math r,c = input().split() r = int(r) c = int(c) ans = r*c/2 if r%2==0 and c%2==0: print(math.floor(ans)) else: print(math.floor(ans)+1)
s237665894
Accepted
17
3,064
471
from math import floor, ceil def solve(): h, w = map(int, input().split()) h1 = float(h/2) w1 = float(w/2) if(h == 1 or w == 1): print(1) exit() if (h % 2 and w % 2 is 0) or (h % 2 and w % 2 is not 0): tot = ceil(h1) * ceil(w1) + floor(h1) * floor(w1) else: if h % 2 is 0: tot = h1 * w elif w % 2 is 0: tot = w1 * h print(int(tot)) if __name__ == "__main__": solve()
s366181761
p02612
u780698286
2,000
1,048,576
Wrong Answer
31
9,144
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(1000 - n)
s371923846
Accepted
26
9,092
80
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - n % 1000)
s053240015
p03434
u893048163
2,000
262,144
Wrong Answer
17
2,940
234
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
n = int(input()) a_list = [int(x) for x in input().split()] alice = bob = [] for i, a in enumerate(sorted(a_list, reverse=True)): if i % 2 == 0: alice.append(a) else: bob.append(a) print(sum(alice) - sum(bob))
s184762568
Accepted
17
2,940
213
n = int(input()) a_list = [int(x) for x in input().split()] alice = bob = 0 for i, a in enumerate(sorted(a_list, reverse=True)): if i % 2 == 0: alice += a else: bob += a print(alice - bob)
s237676393
p03369
u382303205
2,000
262,144
Wrong Answer
17
2,940
25
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
print(input().count("o"))
s690032544
Accepted
17
2,940
35
print((input().count("o"))*100+700)
s681608140
p02694
u745861782
2,000
1,048,576
Wrong Answer
21
9,140
136
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()) y = 100 count = 0 while (True): if y <= x: y *= 1.01 y = int(y) count += 1 else: break print(count)
s411208075
Accepted
23
9,156
135
x = int(input()) y = 100 count = 0 while (True): if y < x: y *= 1.01 y = int(y) count += 1 else: break print(count)
s953391038
p03485
u466478199
2,000
262,144
Wrong Answer
17
2,940
50
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()) x=(a+b)/2 print(x//1)
s712444220
Accepted
17
2,940
95
a,b=map(int,input().split()) x=(a+b)/2 if int(x)==x: print(int(x)) else : print(int(x)+1)
s224140667
p02285
u007270338
2,000
131,072
Wrong Answer
20
5,456
1
Write a program which performs the following operations to a binary search tree $T$ by adding delete operation to B: Binary Search Tree II. * insert $k$: Insert a node containing $k$ as key into $T$. * find $k$: Report whether $T$ has a node containing $k$. * delete $k$: Delete a node containing $k$. * print: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. The operation delete $k$ for deleting a given node $z$ containing key $k$ from $T$ can be implemented by an algorithm which considers the following cases: 1. If $z$ has no children, we modify its parent $z.p$ to replace $z$ with NIL as its child (delete $z$). 2. If $z$ has only a single child, we "splice out" $z$ by making a new link between its child and its parent. 3. If $z$ has two children, we splice out $z$'s successor $y$ and replace $z$'s key with $y$'s key.
s279452581
Accepted
7,360
121,640
2,261
#coding:utf-8 class MakeTree(): def __init__(self, key, p=None, l=None, r=None): self.key = key self.p = p self.l = l self.r = r def Insert(root,value): y = None x = root z = MakeTree(value) while x != None: y = x if x.key > z.key: x = x.l else: x = x.r z.p = y if y == None: root = z elif z.key < y.key: y.l = z else: y.r = z return root def Find(u, target): y = None x = u while x != None and target != x.key: y = x if x.key > target: x = x.l else: x = x.r return x def Delete(u, z): if z.l == None or z.r == None: y = z else: y = getSuccessor(z) if y.l != None: x = y.l else: x = y.r if x != None: x.p = y.p if y.p == None: root = x elif y == y.p.l: y.p.l = x else: y.p.r = x if y != z: z.key = y.key def getSuccessor(x): if x.r != None: return getMinimum(x.r) y = x.p while y != None and x == y.r: x = y y = y.p return y def getMinimum(x): while x.l != None: x = x.l return x def inParse(u): if u == None: return inParse(u.l) global inParseList inParseList.append(u.key) inParse(u.r) def preParse(u): if u == None: return global preParseList preParseList.append(u.key) preParse(u.l) preParse(u.r) root = None n = int(input()) inParseList = [] preParseList = [] for i in range(n): order = list(input().split()) if order[0] == "insert": root = Insert(root, int(order[1])) elif order[0] == "print": inParse(root) preParse(root) print(" " + " ".join([str(i) for i in inParseList])) print(" " + " ".join([str(i) for i in preParseList])) preParseList = [] inParseList = [] elif order[0] == "find": x = Find(root, int(order[1])) if x == None: print("no") else: print("yes") else: x = Find(root, int(order[1])) Delete(root, x)
s059835745
p03378
u508141157
2,000
262,144
Wrong Answer
17
2,940
89
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
n,m,x=map(int,input().split()) s=sum(int(i)<x for i in input().split()) print(min(s,s-m))
s587790830
Accepted
18
2,940
89
n,m,x=map(int,input().split()) s=sum(int(i)<x for i in input().split()) print(min(s,m-s))
s967056432
p02854
u348868667
2,000
1,048,576
Wrong Answer
105
26,764
156
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters. Takahashi wanted to choose a notch and cut the bar at that point into two parts with the same length. However, this may not be possible as is, so he will do the following operations some number of times **before** he does the cut: * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan). * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen. Find the minimum amount of money needed before cutting the bar into two parts with the same length.
N = int(input()) A = list(map(int,input().split())) tmp = 0 std = sum(A)/2 index = 0 while tmp < std: tmp += A[index] index += 1 print(int(tmp-std))
s364602427
Accepted
108
26,220
261
N = int(input()) A = list(map(int,input().split())) mid = sum(A)/2 length = 0 i = 0 while True: if length >= mid: length = min(abs(length-mid),abs(length-mid-A[i-1]))+mid break length += A[i] i += 1 print(int(length-(sum(A)-length)))
s418889080
p03575
u629350026
2,000
262,144
Wrong Answer
2,103
3,064
441
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
n,m=map(int,input().split()) temp=[[] for i in range(n)] for i in range(m): a,b=map(int,input().split()) a=a-1 b=b-1 temp[a].append(b) temp[b].append(a) count=0 print(temp) for i in range(n): if len(temp[i])==1: count=count+1 l=temp[i][0] while True: if len(temp[l])==2: count=count+1 for j in range(2): if temp[l][j]!=i: l=temp[l][j] else: break print(count)
s490900373
Accepted
22
3,444
370
import copy n,m=map(int,input().split()) temp=[[] for i in range(n)] for i in range(m): a,b=map(int,input().split()) a=a-1 b=b-1 temp[a].append(b) temp[b].append(a) count=0 a=[] c=True while c: c=False for i in range(n): if len(temp[i])==1 and i not in a: temp[temp[i][0]].remove(i) a.append(i) count=count+1 c=True print(count)
s274674354
p03636
u379424722
2,000
262,144
Wrong Answer
18
3,060
110
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
N = list(input()) M = [] M.append(N[0]) M.append(str(len(N))) M.append(N[-1]) date = ''.join(M) print(date)
s765029832
Accepted
17
3,060
114
N = list(input()) M = [] M.append(N[0]) M.append(str(len(N) - 2)) M.append(N[-1]) date = ''.join(M) print(date)
s406741225
p02603
u911619829
2,000
1,048,576
Wrong Answer
30
9,192
215
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
N=int(input()) A=list(map(int,input().split())) G=1000 K=0 for i in range(N-1): if A[i+1]>A[i]: K=int(G/A[i]) G=G % A[i] if A[i+1]<A[i]: G=G+A[i]*K K=0 print(G) print(K) G=G+A[N-1]*K print(G)
s577587922
Accepted
26
9,084
191
N=int(input()) A=list(map(int,input().split())) G=1000 K=0 for i in range(N-1): if A[i+1]>A[i]: K=K+G//A[i] G=G % A[i] if A[i+1]<A[i]: G=G+A[i]*K K=0 G=G+A[N-1]*K print(G)
s352693468
p03860
u314050667
2,000
262,144
Wrong Answer
17
2,940
39
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
s = input().split() print("A"+s[0]+"C")
s358423401
Accepted
17
2,940
42
s = input().split() print("A"+s[1][0]+"C")
s000836918
p03795
u451017206
2,000
262,144
Wrong Answer
17
2,940
56
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()) x = 800 * n y = n //15 * 100 print(x-y)
s466376978
Accepted
18
2,940
59
n = int(input()) x = 800 * n y = (n //15) * 200 print(x-y)
s039731774
p02608
u802234211
2,000
1,048,576
Wrong Answer
900
16,944
207
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).
n = int(input()) list_ = [0]*1000000 for i in range(100): for j in range(100): for k in range(100): list_[i**2 + j**2 + k**2+i*j+j*k+k*i - 1] += 1 for i in range(n): print(list_[i])
s498333297
Accepted
1,190
16,804
213
n = int(input()) list_ = [0]*1000000 for i in range(1,100): for j in range(1,100): for k in range(1,100): list_[i**2 + j**2 + k**2+i*j+j*k+k*i - 1] += 1 for i in range(n): print(list_[i])
s966432151
p03759
u974935538
2,000
262,144
Wrong Answer
18
2,940
86
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
a,b,c = map(int,input().split()) if b-a == c-b: print("Yes") else: print("No")
s057382279
Accepted
18
2,940
86
a,b,c = map(int,input().split()) if b-a == c-b: print("YES") else: print("NO")
s515893705
p03378
u003505857
2,000
262,144
Wrong Answer
28
9,172
207
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
N, M, X = map(int, input().split()) A = list(map(int, input().split())) for i , a in enumerate(A): if X < a: break if i > len(A) / 2: ans = len(A[:i]) else: ans = len(A[:i]) print(ans)
s961205436
Accepted
29
8,972
295
n, m, x = map(int, input().split()) a = list(map(int, input().split())) cnt1 = 0 cnt2 = 0 x1 = x x2 = x while x1 < n+1: x1 += 1 if x1 in a: cnt1 += 1 while x2 > 0: x2 -= 1 if x2 in a: cnt2 += 1 if cnt1 < cnt2: ans = cnt1 else: ans = cnt2 print(ans)
s013584710
p03761
u982594421
2,000
262,144
Wrong Answer
19
3,060
189
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.
n = int(input()) ans = set() for _ in range(n): s = input().rstrip() if len(s): ans |= set(s) else: ans = ans.intersection(set(s)) ans = ''.join(sorted(list(ans))) print(ans)
s953084541
Accepted
22
3,316
365
from collections import Counter n = int(input()) counter = Counter(input()) for _ in range(n - 1): counter2 = Counter(input()) for k in counter.keys(): if counter2[k] > 0: counter[k] = min(counter[k], counter2[k]) else: counter[k] = 0 ans = '' for k in sorted(counter.keys()): ans += k * counter[k] print(ans)
s100579409
p03545
u520276780
2,000
262,144
Wrong Answer
17
3,064
589
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
import sys s = input() a = int(s[0]) b=[] for i in range(3): b.append(int(s[i+1])) print(a,*b) for i in range(8): tmp = a for j in range(3): if (i>>j) & 1 == 0: tmp += b[j] else: tmp -= b[j] if tmp ==7: ans = [str(a)] for k in range(3): if (i>>k) & 1 == 0: ans.append("+") else: ans.append("-") ans.append(str(b[k])) print(''.join(ans),end="") print("=7") sys.exit()
s750972546
Accepted
18
3,064
535
import sys s = input() a = int(s[0]) b=[] for i in range(3): b.append(int(s[i+1])) for i in range(8): tmp = a for j in range(3): if (i>>j) & 1 == 0: tmp += b[j] else: tmp -= b[j] if tmp == 7: ans = [str(a)] for k in range(3): if (i>>k) & 1 == 0: ans.append("+") else: ans.append("-") ans.append(str(b[k])) print(''.join(ans),end="") print("=7") sys.exit()
s946134935
p03167
u758815106
2,000
1,048,576
Wrong Answer
614
48,424
659
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}. If a_{i, j} is `.`, Square (i, j) is an empty square; if a_{i, j} is `#`, Square (i, j) is a wall square. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W). As the answer can be extremely large, find the count modulo 10^9 + 7.
def mod(num): return num % (10 ** 9 + 7) H, W = map(int, input().split()) dp = [[0] * W for _ in range(H)] for i in range(H): a = input() for j in range(W): if a[j] == "#": dp[i][j] = -1 dp[0][0] = 1 for col in range(1, W): if dp[0][col] != 0: dp[0][col] = dp[0][col - 1] else: dp[0][col] = 0 for row in range(1, H): for col in range(W): if dp[row][col] != -1: if col == 0: dp[row][col] = dp[row - 1][col] else: dp[row][col] = mod(dp[row - 1][col] + dp[row][col - 1]) else: dp[row][col] = 0 print(dp[-1][-1])
s782640433
Accepted
637
48,144
660
def mod(num): return num % (10 ** 9 + 7) H, W = map(int, input().split()) dp = [[0] * W for _ in range(H)] for i in range(H): a = input() for j in range(W): if a[j] == "#": dp[i][j] = -1 dp[0][0] = 1 for col in range(1, W): if dp[0][col] != -1: dp[0][col] = dp[0][col - 1] else: dp[0][col] = 0 for row in range(1, H): for col in range(W): if dp[row][col] != -1: if col == 0: dp[row][col] = dp[row - 1][col] else: dp[row][col] = mod(dp[row - 1][col] + dp[row][col - 1]) else: dp[row][col] = 0 print(dp[-1][-1])
s020194420
p02612
u218757284
2,000
1,048,576
Wrong Answer
35
9,140
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s849268300
Accepted
24
9,152
76
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - n % 1000)
s876646075
p04046
u497625442
2,000
262,144
Wrong Answer
17
3,064
706
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7.
# E.py# #K, N = map(int,input().split()) P = 10**9+7 H, W, A, B = map(int,"10 7 3 4".split()) def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def fact(i): t = 1 while i > 0: t = (t * i) % P i -= 1 return t def comb(i,j): return (fact(i+j) * modinv(fact(i),P) * modinv(fact(j),P)) % P s = 0 i = 0 while H-A-i > 0 and B+i+1 <= W and A+i <= H and W-B-i >= 0: # print((H-A-i,B+i+1)) s = (s + comb(H-A-i-1,B+i+1-1) * comb(A+i,W-B-i-1)) % P i += 1 print(s)
s679606905
Accepted
324
18,804
576
H, W, A, B = map(int,input().split()) P = 10**9+7 # H, W, A, B = map(int,"2 3 1 1".split()) M = H+W-1 factlist = [1] * (H+W) factinvlist = [1] * (H+W) t = 1 for i in range(M): t = (t * (i+1)) % P factlist[i+1] = t t = pow(factlist[M],P-2,P) factinvlist[M] = t for i in range(M): t = (t * (M-i)) % P factinvlist[M-i-1] = t def comb(i,j): return (factlist[i+j] * factinvlist[i] * factinvlist[j]) % P s = 0 i = 0 while H-A-i-1 >= 0 and B+i <= W and A+i <= H and W-B-i-1 >= 0: # print((H-A-i,B+i+1)) s = (s + comb(H-A-i-1,B+i) * comb(A+i,W-B-i-1)) % P i += 1 print(s)
s628252175
p03971
u013202780
2,000
262,144
Wrong Answer
100
4,016
228
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
n,a,b=map(int,input().split()) c=0 l=a+b for i in input(): if i=="a" and l>0: l-=1 print ("YES") elif i=="b" and l>0 and b>0: print ("YES") l-=1 b-=1 else: print ("NO")
s941171939
Accepted
92
4,016
238
n,a,b=map(int,input().split()) l=a+b for i in input(): if i=="a" and l>0: l-=1 print ("Yes") elif i=="b" and l>0 and b>0: print ("Yes") l-=1 b-=1 else: print ("No")
s081657587
p03379
u171065106
2,000
262,144
Wrong Answer
168
30,856
182
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n = int(input()) x = sorted(list(map(int, input().split()))) a = x[len(x)//2] b = x[(len(x)//2) - 1] for _ in range(len(x)//2): print(a) for _ in range(len(x)//2): print(b)
s574114792
Accepted
179
30,832
190
n = int(input()) x = list(map(int, input().split())) y = sorted(x) a = y[len(x)//2] b = y[(len(x)//2) - 1] for i in range(n): if x[i] <= b: print(a) else: print(b)
s447367354
p02407
u025362139
1,000
131,072
Wrong Answer
20
5,572
58
Write a program which reads a sequence and prints it in the reverse order.
i = list(map(int, input().split())) i.reverse() print(i)
s557969750
Accepted
20
5,624
187
N = int(input()) i = list(map(int, input().split())) i.reverse() for idx, val in enumerate(i): if idx == N-1: print(val) else: print(val, ' ', sep = '', end='')
s140551070
p02678
u453815934
2,000
1,048,576
Wrong Answer
2,207
48,016
511
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 import sys a,b=map(int,input().split()) List=[list(map(int,input().split())) for i in range(b)] l=[0]*(a+1) line=deque([1]) while line: i=line.popleft() bye=[] for j in range(len(List)): x,y=List[j] if x==i: if l[y]==0: l[y]=i bye+=[j] line.append(y) if y==i: if l[x]==0: l[x]=i bye+=[j] line.append(x) for p in range(len(bye)): List.pop(bye[p]-p) print("yes") for h in range(a-1): print(l[h+2])
s373732376
Accepted
519
34,412
612
import math import sys from collections import deque import heapq import copy import itertools from itertools import permutations from itertools import combinations import bisect def mi() : return map(int,sys.stdin.readline().split()) def ii() : return int(sys.stdin.readline().rstrip()) def i() : return sys.stdin.readline().rstrip() a,b=mi() l=[[] for i in range(a)] for j in range(b): x,y=mi() l[x-1].append(y-1) l[y-1].append(x-1) lst=[-1]*a q=deque([0]) while q: s=q.popleft() for j in l[s]: if lst[j]==-1: lst[j]=s q.append(j) print("Yes") for k in range(a-1): print(lst[k+1]+1)
s200095021
p03447
u317710033
2,000
262,144
Wrong Answer
17
2,940
149
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?
total = int(input()) first_cake = int(input()) second_cake = int(input()) total =- first_cake while total >= 0: total =- second_cake print(total)
s136837225
Accepted
17
2,940
161
total = int(input()) first_cake = int(input()) second_cake = int(input()) total -= first_cake while total >= second_cake: total -= second_cake print(total )
s056710278
p03671
u722535636
2,000
262,144
Wrong Answer
18
2,940
70
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
print(sum(sorted(list(map(int,input().split())), reverse = True)[:2]))
s027439714
Accepted
17
2,940
54
print(sum(sorted(list(map(int,input().split())))[:2]))
s656535780
p03696
u024442309
2,000
262,144
Wrong Answer
17
2,940
218
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
N = int(input()) S = input() nl = 0 nr = 0 for i in S: if i == ')': if nr > 0: nr -= 1 else: nl += 1 else: nr += 1 print(nr) print(nl) print('('*nl + S + ')'*nr)
s493831568
Accepted
17
2,940
198
N = int(input()) S = input() nl = 0 nr = 0 for i in S: if i == ')': if nr > 0: nr -= 1 else: nl += 1 else: nr += 1 print('('*nl + S + ')'*nr)
s477854525
p03448
u292220197
2,000
262,144
Wrong Answer
54
3,060
283
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(), 10) b = int(input(), 10) c = int(input(), 10) x = int(input(), 10) ptn = 0 for i in range(a+1): for j in range(b+1): for t in range(c+1): total = (a * 500) + (b * 100) + (c * 50) if x == total: ptn += 1 print(ptn)
s245440571
Accepted
51
3,060
221
a = int(input()) b = int(input()) c = int(input()) x = int(input()) cnt = 0 for i in range(0,a+1): for j in range(0,b+1): for k in range(0,c+1): if x == 500*i + 100*j + 50*k: cnt = cnt + 1 print(cnt)
s616208576
p02612
u376812964
2,000
1,048,576
Wrong Answer
36
9,144
33
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s919750420
Accepted
28
9,136
75
N = int(input()) % 1000 if N == 0: print(0) else: print(1000 - N)
s387824145
p02647
u878384274
2,000
1,048,576
Wrong Answer
2,206
32,196
252
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row: * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i. Find the intensity of each bulb after the K operations.
N , K = map(int,input().split()) Lum = [a for a in map(int,input().split())] for i1 in range(K): B = [0 for i in range(N)] for i in range(N): for j in range(max(0,i-Lum[i]),min(i+Lum[i]+1,N)): B[j]+=1 Lum = B print(Lum)
s365698432
Accepted
895
136,004
560
import numpy as np from numba import jit N , K = map(int,input().split()) Lum = np.array(list(map(int,input().split()))) @jit("i8,i8,i8[:]") def fn(N,K,A): K1 = min(K,41) for i1 in range(K1): B = np.zeros(N,dtype=np.int64) for i in range(N): l = max(0,i-A[i]) r = min(N-1,i+A[i]) B[l]+=1 if r+1<N: B[r+1]-=1 for i in range(1,N): B[i]+=B[i-1] A = B return A Lum = list(fn(N,K,Lum)) Lum = [str(l) for l in Lum] Lum=" ".join(Lum) print(Lum)
s021674248
p03457
u167501921
2,000
262,144
Wrong Answer
841
3,188
458
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()) oldn,oldx,oldy=0,0,0 #print(x,y) no=0 for i in range(N): nxy=input().split() n,x,y=int(nxy[0]),int(nxy[1]),int(nxy[2]) # print(n,x,y) ndiff = n - oldn distance = abs(x - oldx) + abs(y - oldy) # print(ndiff,distance) oldn,oldx,oldy=n,x,y if distance > ndiff: print("No") no=1 break print((ndiff-distance)%2) if (ndiff-distance)%2==0: continue else: no=1 print("No") break if no==0: print("Yes")
s700230684
Accepted
352
3,064
459
N=int(input()) oldn,oldx,oldy=0,0,0 #print(x,y) no=0 for i in range(N): nxy=input().split() n,x,y=int(nxy[0]),int(nxy[1]),int(nxy[2]) # print(n,x,y) ndiff = n - oldn distance = abs(x - oldx) + abs(y - oldy) # print(ndiff,distance) oldn,oldx,oldy=n,x,y if distance > ndiff: print("No") no=1 break # print((ndiff-distance)%2) if (ndiff-distance)%2==0: continue else: no=1 print("No") break if no==0: print("Yes")
s715205293
p02645
u191960840
2,000
1,048,576
Wrong Answer
27
8,956
30
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
S = str(input()) print(S[0:2])
s354882271
Accepted
29
8,916
30
S = str(input()) print(S[0:3])
s886731081
p02402
u316584871
1,000
131,072
Wrong Answer
20
5,592
119
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
n = int(input()) l = input().split() l.sort() sum = 0 for i in range(n): sum = sum+int(l[i]) print(l[0],l[-1],sum)
s789610085
Accepted
20
6,588
135
n = int(input()) l = list(map(int, input().split())) l.sort() sum = 0 for i in range(n): sum = sum+int(l[i]) print(l[0],l[-1],sum)
s193759479
p03679
u695079172
2,000
262,144
Wrong Answer
17
2,940
225
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
def main(): x,a,b = map(int,input().split()) now = b - a if now < 0: print("delicious") elif now <= x: print("save") else: print("dangerous") if __name__ == '__main__': main()
s687239823
Accepted
17
2,940
226
def main(): x,a,b = map(int,input().split()) now = b - a if now <= 0: print("delicious") elif now <= x: print("safe") else: print("dangerous") if __name__ == '__main__': main()
s933047832
p03963
u288430479
2,000
262,144
Wrong Answer
17
2,940
53
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls.
n,k = map(int,input().split()) print(k+(k-1)**(n-1))
s507494333
Accepted
17
2,940
52
n,k = map(int,input().split()) print(k*(k-1)**(n-1))
s860517316
p03379
u896726004
2,000
262,144
Wrong Answer
323
25,228
286
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
n = int(input()) x = list(map(int, input().split())) if n==2: print(x[1]) print(x[0]) exit() x_sort = sorted(x) med1_ix = n//2-1 med2_ix = n//2 med1 = x_sort[med1_ix] med2 = x_sort[med2_ix] for i in x: if i <= med1: print(med1) else: print(med2)
s999215213
Accepted
286
26,772
233
n = int(input()) x = list(map(int, input().split())) x_sort = sorted(x) med1_ix = n//2-1 med2_ix = n//2 med1 = x_sort[med1_ix] med2 = x_sort[med2_ix] for i in x: if i <= med1: print(med2) else: print(med1)
s974315352
p03645
u301823349
2,000
262,144
Wrong Answer
2,105
17,312
272
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
N,M=map(int, input().split()) p=[] for x in range(M): p.append(input()) f=0 for x in range(M): if "1 %s" % x in p: if "%s N" % x in p: print("POSSIBLE") else: f=f+1 else: f=f+1 if f==M: print("IMPOSSIBLE")
s039041268
Accepted
584
34,796
403
N,M=map(int, input().split()) p=[] for x in range(M): p.append(input()) A=[] B=[] for x in range(M): a,b=map(int,p[x].split()) A.append(a) B.append(b) isl=[] for x in range(N): isl.append(0) for x in range(M): if A[x]==1: isl[B[x]]=1 for x in range(M): if B[x]==N: isl[A[x]]=isl[A[x]]+1 if 2 in isl: print("POSSIBLE") else: print("IMPOSSIBLE")
s922272750
p03477
u821432765
2,000
262,144
Wrong Answer
17
3,060
111
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
A=3 B=2 C=1 D=4 L=A+B R=C+D if L<R: print("Right") if L>R: print("Left") if L==R: print("Balanced")
s902206874
Accepted
18
3,060
140
A,B,C,D=map(int,input().split()) AB=A+B CD=C+D if AB==CD: print("Balanced") elif AB>CD: print("Left") elif AB<CD: print("Right")
s949917742
p02257
u409571842
1,000
131,072
Wrong Answer
30
5,660
354
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
#coding: UTF-8 import sys import math class Algo: @staticmethod def is_prime(l): ans = 0 for n in l: if n == 2: ans += 1 else: for i in range(2,int(math.sqrt(n))+2): if n%i == 0: ans += 1 print(ans) N = int(input()) L = [] for i in range(0,N): L.append(int(input())) Algo.is_prime(L)
s761235905
Accepted
230
5,676
387
#coding: UTF-8 import sys import math class Algo: @staticmethod def is_prime(n): if n == 2: return True elif n<2 or n%2 == 0: return False else: for i in range(3,int(math.sqrt(n))+2, 2): if n%i == 0: return False return True N = int(input()) ans = 0 for i in range(0,N): if Algo.is_prime(int(input())): ans += 1 print(ans)
s832149203
p03557
u406138190
2,000
262,144
Wrong Answer
577
23,360
375
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
import bisect n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) sum=0 for i in range(n): bisect_a=bisect.bisect_left(a,b[i]) print(bisect_a) bisect_c=bisect.bisect_right(c,b[i]) print(bisect_c) sum+=bisect_a*(n-bisect_c) print(sum) print(sum)
s345414669
Accepted
350
22,516
326
import bisect n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) sum=0 for i in range(n): bisect_a=bisect.bisect_left(a,b[i]) bisect_c=bisect.bisect_right(c,b[i]) sum+=bisect_a*(n-bisect_c) print(sum)
s460671840
p03387
u685983477
2,000
262,144
Wrong Answer
18
3,060
196
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.
a=[int(i) for i in input().split()] a.sort() print(a) ans=0 while a[1]!=a[2]: a[1]+=1 a[0]+=1 ans+=1 if a[1]%2==a[0]%2: ans+=(a[1]-a[0])//2 else: ans+=(a[1]-a[0])+1 print(ans)
s971794954
Accepted
18
3,060
211
a=[int(i) for i in input().split()] a.sort() ans=0 while a[1]!=a[2]: a[1]+=1 a[0]+=1 ans+=1 if a[1]%2==a[0]%2: ans+=(a[1]-a[0])//2 else: ans+=1 a[1]+=1 ans+=(a[1]-a[0])//2 print(ans)
s302850758
p02388
u478810373
1,000
131,072
Wrong Answer
20
7,380
10
Write a program which calculates the cube of a given integer x.
x =2 x**3
s870450756
Accepted
20
7,548
28
x = int(input()) print(x**3)
s514604747
p02613
u208120643
2,000
1,048,576
Wrong Answer
144
9,204
341
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.
"""B - Judge Status Summary""" N = int(input()) ac, wa, tle, re = 0, 0, 0, 0 for i in range(N): S = input() if S == "AC": ac = +1 elif S == "WA": wa = +1 elif S == "TLE": tle = +1 else: re = +1 print("AC x "+str(ac)) print("WA x "+str(wa)) print("TLE x "+str(tle)) print("RE x "+str(re))
s181685667
Accepted
144
9,044
341
"""B - Judge Status Summary""" N = int(input()) ac, wa, tle, re = 0, 0, 0, 0 for i in range(N): S = input() if S == "AC": ac += 1 elif S == "WA": wa += 1 elif S == "TLE": tle += 1 else: re += 1 print("AC x "+str(ac)) print("WA x "+str(wa)) print("TLE x "+str(tle)) print("RE x "+str(re))
s153300510
p02240
u569960318
1,000
131,072
Wrong Answer
30
7,672
627
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
def connected(G,s,t): checked = [False]*len(G) def main(G,s,t): if t in G[s]: return True checked[s] = True for f in G[s]: if checked[f]: continue if main(G,f,t): return True return False return main(G,s,t) if __name__=='__main__': n,m = list(map(int,input().split())) G = [[] for _ in range(n)] for _ in range(m): s,t = list(map(int,input().split())) G[s].append(t) G[t].append(s) q = int(input()) for _ in range(q): s,t = list(map(int,input().split())) print('Yes' if connected(G,s,t) else 'No')
s400225314
Accepted
480
33,568
840
import sys def make_connected_group(G): C = [None]*len(G) group = 0 for i,p in enumerate(C): if p != None: continue friends = [i] while len(friends) > 0: f = friends.pop() if C[f] == None: C[f] = group friends += G[f] group += 1 return C if __name__=='__main__': n,m = list(map(int,sys.stdin.readline().split())) G = [[] for _ in range(n)] for j,line in enumerate(sys.stdin): if not j < m: q = int(line) break s,t = list(map(int,line.split())) G[s].append(t) G[t].append(s) C = make_connected_group(G) for j,line in enumerate(sys.stdin): if not j < q: break s,t = list(map(int,line.split())) print('yes' if C[s] == C[t] else 'no')
s778492916
p03456
u083960235
2,000
262,144
Wrong Answer
17
2,940
200
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.
l=list(map(str,input().split())) l=int(l[0]+l[1]) print(l) temp=False for i in range(1000): if i*i==l: temp=True break if temp==True: print("Yes") else: print("No")
s438110368
Accepted
17
2,940
191
l=list(map(str,input().split())) l=int(l[0]+l[1]) temp=False for i in range(1000): if i*i==l: temp=True break if temp==True: print("Yes") else: print("No")
s155310751
p02400
u636711749
1,000
131,072
Wrong Answer
30
6,804
104
Write a program which calculates the area and circumference of a circle for given radius r.
import math r = float(input()) S =r * r * math.pi C =r * math.pi print('{0:.6f} {1:.6f}'.format(S,C))
s498598270
Accepted
30
6,804
110
import math r = float(input()) S =r * r * math.pi C =(r + r) * math.pi print('{0:.6f} {1:.6f}'.format(S,C))
s242579115
p03386
u167647458
2,000
262,144
Wrong Answer
17
3,060
197
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
a, b, k = map(int, input().split()) s = set() for i in range(a, a+k): if a <= i <= b: s.add(i) for i in range(b-k, b+1): if a <= i <= b: s.add(i) for i in s: print(i)
s722197413
Accepted
17
3,060
206
a, b, k = map(int, input().split()) s = set() for i in range(a, a+k): if a <= i <= b: s.add(i) for i in range(b-k+1, b+1): if a <= i <= b: s.add(i) for i in sorted(s): print(i)
s728122646
p03435
u698479721
2,000
262,144
Wrong Answer
18
3,060
324
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
c1, c2, c3 = map(int, input().split()) c4, c5, c6 = map(int, input().split()) c7, c8, c9 = map(int, input().split()) if c4-c1==c5-c2 and c5-c2 == c6-c3 and c7-c4 ==c8-c5 and c8-c5 == c9-c6: if c2-c1 == c5-c4 and c5-c4 == c8-c7 and c3-c2 == c6-c5 and c6-c5 == c9-c8: print('Yes') print('No') else: print('No')
s504262118
Accepted
17
3,060
329
c1, c2, c3 = map(int, input().split()) c4, c5, c6 = map(int, input().split()) c7, c8, c9 = map(int, input().split()) if c4-c1==c5-c2 and c5-c2 == c6-c3 and c7-c4 ==c8-c5 and c8-c5 == c9-c6: if c2-c1 == c5-c4 and c5-c4 == c8-c7 and c3-c2 == c6-c5 and c6-c5 == c9-c8: print('Yes') else:print('No') else: print('No')
s276038000
p03730
u721970149
2,000
262,144
Wrong Answer
17
2,940
126
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
A, B, C = map(int,input().split()) ans = "No" for i in range(1,B+1) : if (A*i)%B == C : ans = "Yes" print(ans)
s756371860
Accepted
17
2,940
126
A, B, C = map(int,input().split()) ans = "NO" for i in range(1,B+1) : if (A*i)%B == C : ans = "YES" print(ans)
s961435019
p03852
u089376182
2,000
262,144
Wrong Answer
17
2,940
55
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
print('vowel' if input() in ['aeiou'] else 'consonant')
s067232311
Accepted
17
2,940
54
print('vowel' if input() in 'aeiou' else 'consonant')
s466928357
p03448
u617037231
2,000
262,144
Wrong Answer
49
3,064
193
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.
def i(): return int(input()) A = i() B = i() C = i() X = i() ans = 0 for i in range(A): for j in range(B): for k in range(C): if 500*i+100*j+50*k == X: ans += 1 print(ans)
s665368294
Accepted
51
3,060
200
def i(): return int(input()) A = i() B = i() C = i() X = i() ans = 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 == X: ans += 1 print(ans)
s655648460
p03644
u502389123
2,000
262,144
Time Limit Exceeded
2,104
2,940
207
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()) count = 0 counter = [] for i in range(1, N+1): while i % 2 == 0: count += 1 counter.append([count, i]) count = 0 counter.sort() counter.reverse() print(counter[0][1])
s846552788
Accepted
17
3,060
238
N = int(input()) count = 0 counter = [] for i in range(1, N+1): num = i while num % 2 == 0: count += 1 num /= 2 counter.append([count, i]) count = 0 counter.sort() counter.reverse() print(counter[0][1])
s647369063
p02927
u970809473
2,000
1,048,576
Wrong Answer
24
3,060
183
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
m,d = map(int, input().split()) res = 0 for i in range(1,m+1): for j in range(1,d+1): if j >= 22 and j%10 >= 2 and int(str(j)[0]) *int(str(j)[1]) == m: res += 1 print(res)
s932744564
Accepted
23
2,940
187
m,d = map(int, input().split()) res = 0 for i in range(1,m+1): for j in range(1,d+1): if j >= 22 and j % 10 >= 2 and int(str(j)[0]) * int(str(j)[1]) == i: res += 1 print(res)
s829307282
p03050
u422711869
2,000
1,048,576
Wrong Answer
116
3,272
438
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
from sys import stdin def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors n = int(stdin.readline().rstrip()) ds = make_divisors(n) #print(ds) sum = 0 for x in ds: if x==n: continue m = int(n/x-1) # print(x,m) sum += m print(sum)
s383742698
Accepted
119
3,264
504
from sys import stdin def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors n = int(stdin.readline().rstrip()) ds = make_divisors(n) #print(ds) sum = 0 for x in ds: if x==n: continue m = int(n/x-1) if m==1: continue # print(x,m, int(n/m), n%m) if(int(n/m) == n%m): sum += m print(sum)
s081115065
p03525
u368796742
2,000
262,144
Wrong Answer
30
9,176
237
In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi. Takahashi checked and found that the _time gap_ (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if the local time in city B is d o'clock at the moment when the local time in city A is 0 o'clock, then the time gap between these two cities is defined to be min(d,24-d) hours. Here, we are using 24-hour notation. That is, the local time in the i-th person's city is either d o'clock or 24-d o'clock at the moment when the local time in Takahashi's city is 0 o'clock, for example. Then, for each pair of two people chosen from the N+1 people, he wrote out the time gap between their cities. Let the smallest time gap among them be s hours. Find the maximum possible value of s.
n = int(input()) d = list(map(int,input().split())) if n >= 12: count = [0]*24 count[0] += 2 for i in d: count[i] += 1 count[(24-i)%24] += 1 if max(count) > 2: print(0) else: print(1)
s621327431
Accepted
42
9,220
539
n = int(input()) d = list(map(int,input().split())) if n >= 12: count = [0]*24 count[0] += 2 for i in d: count[i] += 1 count[(24-i)%24] += 1 if max(count) > 2: print(0) else: print(1) exit() ans = 0 for i in range(1<<n): l = [0,24] for j in range(n): if i>>j & 1: l.append(d[j]) else: l.append(24-d[j]) l.sort() count = 24 for j in range(len(l)-1): count = min(count,l[j+1]-l[j]) ans = max(ans,count) print(ans)
s283146449
p03386
u316233444
2,000
262,144
Wrong Answer
2,103
3,060
171
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A,B,K=map(int,input().split()) ans=[] for i in range(A,B+1): if i <= A+K: ans.append(i) if i >= B-K: ans.append(i) for i in sorted(set(ans)): print(i)
s174072423
Accepted
17
3,060
165
A,B,K=map(int,input().split()) ans=[] for i in range(K): if A+i <= B: ans.append(A+i) if B-i >= A: ans.append(B-i) for i in sorted(set(ans)): print(i)
s660610992
p03730
u145600939
2,000
262,144
Wrong Answer
18
2,940
118
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a,b,c = map(int,input().split()) ans = 'No' for i in range(1,b+1): if (a*i)%b == c: ans = 'Yes' print(ans)
s056197593
Accepted
17
2,940
129
a,b,c = map(int,input().split()) ans = 'NO' for i in range(1,b+1): if (a*i)%b == c: ans = 'YES' break print(ans)
s062544841
p02928
u814986259
2,000
1,048,576
Wrong Answer
359
3,188
206
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
N,K=map(int,input().split()) A=list(map(int,input().split())) ans=0 for i in range(N): count=0 for j in range(i+1,N): if A[i]>A[j]: count+=1 ans+=count ans+=((N-1)*N // 2)*(K-1) print(ans)
s204508105
Accepted
611
9,320
440
N, K = map(int, input().split()) A = list(map(int, input().split())) count = [[0, 0] for i in range(N)] for i in range(N): for j in range(i): if A[j] < A[i]: count[i][0] += 1 for j in range(i+1, N): if A[j] < A[i]: count[i][1] += 1 ans = 0 mod = 10**9 + 7 for i in range(N): ans += (1+K-1)*(K-1) // 2 * count[i][0] ans += (1+K)*K // 2 * count[i][1] ans %= mod print(ans % mod)
s912006159
p03386
u576434377
2,000
262,144
Wrong Answer
17
3,060
192
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A, B, K = map(int,input().strip().split()) res = [] for a in range(A,min(A + K,B)): res.append(a) for b in range(max(A,B - K + 1),B + 1): res.append(b) print(sorted(list(set(res))))
s756846836
Accepted
17
3,060
209
A, B, K = map(int,input().strip().split()) res = [] for a in range(A,min(A + K,B)): res.append(a) for b in range(max(A,B - K + 1),B + 1): res.append(b) for r in sorted(list(set(res))): print(r)
s837213962
p02411
u628732336
1,000
131,072
Wrong Answer
20
7,652
394
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
while True: m, f, r = [int(i) for i in input().split()] if m == f == r == -1: break total = m + f if m == -1 or f == -1 or total < 30: print("F") elif total <= 80: print("A") elif 65 <= total < 80: print("B") elif 50 <= total < 65: print("C") elif 30 <= total < 50 and r < 50: print("D") print()
s037137086
Accepted
30
7,656
345
while True: m, f, r = [int(i) for i in input().split()] if m == f == r == -1: break total = m + f if m == -1 or f == -1 or total < 30: print("F") elif total < 50 and r < 50: print("D") elif r >= 50 or total < 65: print("C") elif total < 80: print("B") else: print("A")
s413248696
p03377
u198274496
2,000
262,144
Wrong Answer
17
2,940
83
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()) print("Yes" if A <= X and A + B >= X else "No")
s538537871
Accepted
18
2,940
84
A, B, X = map(int, input().split()) print("YES" if A <= X and A + B >= X else "NO")
s212511885
p03473
u657208344
2,000
262,144
Wrong Answer
20
3,060
30
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
m=int(input()) m=24-m print(m)
s313069745
Accepted
17
2,940
30
m=int(input()) m=48-m print(m)
s381616907
p02972
u099450021
2,000
1,048,576
Wrong Answer
56
7,148
211
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
N = int(input()) A = [int(s) for s in input().split(' ')] for i in range(N): ai = A[i] if ai == 0: print(0) exit(0) else: print(1) print(i) exit(0) print(-1)
s247654624
Accepted
791
19,816
390
N = int(input()) A = [0] + [int(s) for s in input().split(' ')] B = [0] * (N + 1) count = 0 ret = [] for i in range(N, 0, -1): ai = A[i] ii = i total = 0 while ii <= N: total += B[ii] ii += i if total % 2 == ai: continue else: B[i] = 1 count += 1 ret.append(i) print(count) print(' '.join(str(i) for i in ret))
s130368850
p03494
u510630535
2,000
262,144
Wrong Answer
29
8,832
182
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
def resolve(): import re N = int(input()) An = input().split() ret = min( len((re.findall("0+$", bin(int(a))) + [""])[0]) for a in An) print(ret)
s388354898
Accepted
36
9,884
105
import re input() An=input().split() print(min(len((re.findall("0+$",bin(int(a)))+[""])[0]) for a in An))
s218120971
p02613
u303711501
2,000
1,048,576
Wrong Answer
136
16,304
200
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()) s = [input() for i in range(N)] c = [s.count('AC'),s.count('WA'),s.count('TLE'),s.count('RE')] d = ['AC','WA','TLE','RE'] for i in range(4): print(d[i]+' '+'×'+' '+str(c[i]) )
s442270267
Accepted
139
16,284
199
N = int(input()) s = [input() for i in range(N)] c = [s.count('AC'),s.count('WA'),s.count('TLE'),s.count('RE')] d = ['AC','WA','TLE','RE'] for i in range(4): print(d[i]+' '+'x'+' '+str(c[i]) )
s316544934
p03131
u578406587
2,000
1,048,576
Time Limit Exceeded
2,103
3,064
409
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
K, A, B = (int(i) for i in input().split()) num = 1 while True: if A + 2 - num >= B: print(K + num) break elif num >= A: if (K // 2) is not 0: print(num + (K // 2) * (B - A) + (K % 2)) break else: if K >= 2 and K >= (A + 2 - num): K -= (A + 2 - num) num = B else: print(K + num) break
s626332983
Accepted
17
3,060
361
K, A, B = (int(i) for i in input().split()) num = 1 while True: if A + 2 - num >= B: print(K + num) break elif num >= A and (K // 2) is not 0: print(num + (K // 2) * (B - A) + (K % 2)) break elif K >= 2 and K >= (A + 2 - num): K -= (A + 2 - num) num = B else: print(K + num) break
s230919198
p03719
u810356688
2,000
262,144
Wrong Answer
17
2,940
79
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
a,b,c = map(int,input().split()) if c>=a and c<=b:print("YES") else:print("NO")
s529136963
Accepted
17
2,940
79
a,b,c = map(int,input().split()) if c>=a and c<=b:print("Yes") else:print("No")
s753413315
p03089
u121161758
2,000
1,048,576
Wrong Answer
17
2,940
135
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
N = int(input()) b = list(map(int, input().split())) print(b) for i in range(N): if b[i] > i: print("-1") exit()
s290412320
Accepted
18
3,064
366
N = int(input()) b = list(map(int, input().split())) #print(b) ans = [] i = len(b)-1 while(1): if i == -1: print("-1") exit() if b[i] == i + 1: #print("check") ans.append(b.pop(i)) if len(b) == 0: break i = len(b)-1 else: i -= 1 for i in range(len(ans)-1, -1, -1): print(ans[i])
s328073965
p03493
u233588813
2,000
262,144
Wrong Answer
17
2,940
26
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.
a,b,c=input() print(a+b+c)
s758672201
Accepted
17
2,940
53
a,b,c=input() a=int(a) b=int(b) c=int(c) print(a+b+c)
s142357394
p04044
u841531687
2,000
262,144
Wrong Answer
17
3,060
111
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()) list = [] for s in range(n - 1): list.append(input()) print(sorted(list))
s349593533
Accepted
18
3,188
131
n, l = map(int, input().split()) list = [] for s in range(n): list.append(input()) s_list = sorted(list) print(*s_list, sep='')
s371866323
p02842
u579015878
2,000
1,048,576
Wrong Answer
17
2,940
83
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
N=float(input()) x=N//1.08 if x*1.08<=N<=(x+1)*1.08: print(x) else: print(':(')
s159715189
Accepted
17
2,940
140
N=int(input()) x=int(N/1.08) a=int(x*1.08) b=int((x+1)*1.08) if N==a: print(x) exit() if N==b: print(x+1) exit() else: print(':(')
s507810992
p03197
u941047297
2,000
1,048,576
Wrong Answer
149
13,640
207
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
def main(): n = int(input()) A = [int(input()) for _ in range(n)] if any([a % 2 != 0 for a in A]): print('second') else: print('first') if __name__ == '__main__': main()
s163552062
Accepted
146
13,848
214
def main(): n = int(input()) A = [int(input()) for _ in range(n)] if any([a % 2 != 0 for a in A]): print('first') else: print('second') if __name__ == '__main__': main()
s739952392
p03695
u710789518
2,000
262,144
Wrong Answer
17
3,064
604
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
N = int(input()) a = list(map(int, input().split())) color = [0] * 9 for i in range(N): if a[i] <= 399: color[0] += 1 elif a[i] <= 799: color[1] += 1 elif a[i] <= 1199: color[2] += 1 elif a[i] <= 1599: color[3] += 1 elif a[i] <= 1999: color[4] += 1 elif a[i] <= 2399: color[5] += 1 elif a[i] <= 2799: color[6] += 1 elif a[i] <= 3199: color[7] += 1 else: color[8] += 1 print(color) tmp = 0 for i in range(8): if color[i] > 0: tmp += 1 color_min = max(tmp, 1) color_max = tmp + min(8-tmp, color[8]) #print("{0} {1}".format(color_min, color_max))
s222333555
Accepted
17
3,064
584
N = int(input()) a = list(map(int, input().split())) color = [0] * 9 for i in range(N): if a[i] < 400: color[0] += 1 elif a[i] < 800: color[1] += 1 elif a[i] < 1200: color[2] += 1 elif a[i] < 1600: color[3] += 1 elif a[i] < 2000: color[4] += 1 elif a[i] < 2400: color[5] += 1 elif a[i] < 2800: color[6] += 1 elif a[i] < 3200: color[7] += 1 else: color[8] += 1 #print(color) tmp = 0 for i in range(8): if color[i] > 0: tmp += 1 color_min = max(tmp, 1) color_max = tmp + color[8] print("{0} {1}".format(color_min, color_max))
s317400106
p03644
u383450070
2,000
262,144
Time Limit Exceeded
2,104
3,060
260
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()) count = 0 result = 0 if n == 1: print(1) else: for i in range(0, n+1, 2): counta = 0 num = i while (num % 2 == 0): num = num/2 counta += 1 if counta > count: count = counta result = i print(result)
s674557006
Accepted
17
2,940
74
n=int(input()) ans=1 for i in range(7): if 2**i<=n:ans=2**i print(ans)
s846849935
p03351
u632557492
2,000
1,048,576
Wrong Answer
17
2,940
85
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()] print('Yes' if (c - a) <= d else 'No')
s592055412
Accepted
17
2,940
119
a, b, c, d = [int(i) for i in input().split()] print('Yes' if ((abs(b-a)<=d and abs(c-b)<=d)) or abs(c-a)<=d else 'No')
s127058177
p02394
u546968095
1,000
131,072
Wrong Answer
20
5,596
345
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
def cinr(i): tmp = (i.split(" ")) W = int(tmp[0]) H = int(tmp[1]) x = int(tmp[2]) y = int(tmp[3]) r = int(tmp[4]) print(W, H, x, y, r) if x >= 0 + r and x <= W - r and y >= 0 + r and y <= H - r: print("YES") else: print("NO") return 0 if __name__ == "__main__": ret = cinr(input())
s554721398
Accepted
20
5,600
320
def cinr(i): tmp = (i.split(" ")) W = int(tmp[0]) H = int(tmp[1]) x = int(tmp[2]) y = int(tmp[3]) r = int(tmp[4]) if x >= 0 + r and x <= W - r and y >= 0 + r and y <= H - r: print("Yes") else: print("No") return 0 if __name__ == "__main__": ret = cinr(input())
s308849409
p03861
u069170167
2,000
262,144
Wrong Answer
2,152
898,968
81
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a, b, x = list(map(int, input().split())) print(sum([c%x for c in range(a,b+1)]))
s960017588
Accepted
29
3,068
62
a, b, x = list(map(int, input().split())) print(b//x-(a-1)//x)
s760538808
p03609
u597047658
2,000
262,144
Wrong Answer
18
2,940
82
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
X, t = map(int, input().split()) if X >= t: print(t) else: print(X)
s508746166
Accepted
17
2,940
86
X, t = map(int, input().split()) if X >= t: print(X - t) else: print(0)
s001611939
p03455
u481197205
2,000
262,144
Wrong Answer
17
3,064
106
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) ab = a * b if ab%2 ==0: print('even') else: print('odd')
s825985213
Accepted
17
2,940
106
a, b = map(int, input().split()) ab = a * b if ab%2 ==0: print('Even') else: print('Odd')
s494954042
p03575
u370331385
2,000
262,144
Wrong Answer
18
3,064
590
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
N,M = map(int,input().split()) graph = [[0]*N for _ in range(N)] Edge = [] for i in range(M): a,b = map(int,input().split()) graph[a-1][b-1] = 1 graph[b-1][a-1] = 1 Edge.append([a-1,b-1]) def dfs(x): if(vis[x] == 1): return vis[x] = 1 for i in range(N): if(graph[x][i] == 1): dfs(0) ans = 0 for i in range(M): graph[Edge[i][0]][Edge[i][1]] = 0 graph[Edge[i][1]][Edge[i][0]] = 0 vis = [0]*60 dfs(0) for j in range(N): if(vis[j] == 0): ans += 1 break graph[Edge[i][0]][Edge[i][1]] = 1 graph[Edge[i][1]][Edge[i][0]] = 1 print(ans)
s977402496
Accepted
22
3,064
2,056
class UnionFind(): def __init__(self, n): self.n = n self.root = [-1]*(n+1) self.rnk = [0]*(n+1) def Find_Root(self, x): if(self.root[x] < 0): return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] def Unite(self, x, y): x = self.Find_Root(x) y = self.Find_Root(y) if(x == y): return elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) def Count(self, x): return -self.root[self.Find_Root(x)] N,M = map(int,input().split()) Edge = [] for i in range(M): a,b = map(int,input().split()) Edge.append([a-1,b-1]) ans = 0 for i in range(M): graph = UnionFind(N) for j in range(M): if(i != j): graph.Unite(Edge[j][0],Edge[j][1]) if(graph.Count(0) != N): ans += 1 print(ans)
s990379085
p03852
u865413330
2,000
262,144
Wrong Answer
18
3,064
122
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
import sys input = sys.stdin.readline vowels = "aiueo" c = input() print ("vowel") if c in vowels else print("consonant")
s874832965
Accepted
18
2,940
83
vowels = "aiueo" c = input() print("vowel") if c in vowels else print("consonant")
s000489748
p03140
u966601619
2,000
1,048,576
Wrong Answer
18
2,940
154
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
N = int(input()) A = input() B = input() C = input() count = 0 for num in range(N) : count += len(list(set(list( [ A[num], B[num], C[num] ] ) ) )) - 1
s078573546
Accepted
18
3,060
167
N = int(input()) A = input() B = input() C = input() count = 0 for num in range(N) : count += len(list(set(list( [ A[num], B[num], C[num] ] ) ) )) - 1 print(count)
s676612399
p03130
u185243955
2,000
1,048,576
Wrong Answer
17
3,060
207
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
city = [0, 0, 0, 0] for i in range(3): a, b = ([int(x)-1 for x in input().split()]) city[a] += 1 city[b] += 1 if city[a] > 2 or city[b] > 2: print('No') exit() print('Yes')
s754369268
Accepted
17
2,940
206
city = [0, 0, 0, 0] for i in range(3): a, b = ([int(x)-1 for x in input().split()]) city[a] += 1 city[b] += 1 if city[a] > 2 or city[b] > 2: print('NO') exit() print('YES')
s131260168
p00423
u243053043
1,000
131,072
Wrong Answer
120
7,572
315
A と B の 2 人のプレーヤーが, 0 から 9 までの数字が書かれたカードを使ってゲームを行う.最初に, 2 人は与えられた n 枚ずつのカードを,裏向きにして横一列に並べる.その後, 2 人は各自の左から 1 枚ずつカードを表向きにしていき,書かれた数字が大きい方のカードの持ち主が,その 2 枚のカードを取る.このとき,その 2 枚のカードに書かれた数字の合計が,カードを取ったプレーヤーの得点となるものとする.ただし,開いた 2 枚のカードに同じ数字が書かれているときには,引き分けとし,各プレーヤーが自分のカードを 1 枚ずつ取るものとする. 例えば, A,B の持ち札が,以下の入力例 1 から 3 のように並べられている場合を考えよう.ただし,入力ファイルは n + 1 行からなり, 1 行目には各プレーヤのカード枚数 n が書かれており, i + 1 行目(i = 1,2,... ,n)には A の左から i 枚目のカードの数字と B の左から i 枚目の カードの数字が,空白を区切り文字としてこの順で書かれている.すなわち,入力ファイルの 2 行目以降は,左側の列が A のカードの並びを,右側の列が B のカードの並びを,それぞれ表している.このとき,ゲーム終了後の A と B の得点は,それぞれ,対応する出力例に示したものとなる. 入力ファイルに対応するゲームが終了したときの A の得点と B の得点を,この順に空白を区切り文字として 1 行に出力するプログラムを作成しなさい.ただし, n ≤ 10000 とする. 入力例1 | 入力例2 | 入力例3 ---|---|--- 3| 3| 3 9 1| 9 1| 9 1 5 4| 5 4| 5 5 0 8| 1 0| 1 8 出力例1 | 出力例2 | 出力例3 19 8| 20 0| 15 14
while True: n_line = input() if n_line == "0": break score_a, score_b = (0, 0) for i in range(int(n_line)): a, b = [int(x) for x in input().split(" ")] if a >= b: score_a += a if a <= b: score_b += b print("{} {}".format(score_a, score_b))
s880956391
Accepted
110
7,612
387
while True: n_line = input() if n_line == "0": break score_a, score_b = (0, 0) for i in range(int(n_line)): a, b = [int(x) for x in input().split(" ")] if a > b: score_a += a + b elif a < b: score_b += a + b else: score_a += a score_b += b print("{} {}".format(score_a, score_b))
s921012528
p03548
u985702482
2,000
262,144
Wrong Answer
18
3,064
177
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?
def isu(x, y, z): n = int(x / (y + z)) if x - n * (y + z) - z < 0: return int(n - 1) return int(n) x, y, z = map(int, input().strip().split()) isu(x, y, z)
s329642805
Accepted
17
2,940
184
def isu(x, y, z): n = int(x / (y + z)) if x - n * (y + z) - z < 0: return int(n - 1) return int(n) x, y, z = map(int, input().strip().split()) print(isu(x, y, z))
s412644590
p03860
u951684192
2,000
262,144
Wrong Answer
17
2,940
46
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
a,b,c = input().split() print(a[0],b[0],c[0])
s411120358
Accepted
17
2,940
44
a,b,c= input().split() print(a[0]+b[0]+c[0])
s119219622
p02392
u050103511
1,000
131,072
Wrong Answer
30
7,512
93
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a,b,c = map(int, input().split()) if a < b and a < c and b < c: print("Yes") print("No")
s963194665
Accepted
20
7,660
124
a,b,c = map(int, input().split()) if a < b and b < c: print("Yes") else: print("No")
s695253675
p03457
u877283726
2,000
262,144
Wrong Answer
494
32,800
499
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()) scedule = [] scedule.append([0, 0, 0]) for i in range(N): scedule.append(list(map(int,input().split()))) print(scedule) for i in range(N): timelimit = scedule[i+1][0] - scedule[i][0] x_distance = abs(scedule[i+1][1] - scedule[i][1]) y_distance = abs(scedule[i+1][2] - scedule[i][2]) if timelimit < (x_distance + y_distance): print("No") exit() if timelimit % (x_distance + y_distance) != 0: print("No") exit() print("Yes")
s841097318
Accepted
434
27,300
483
N = int(input()) scedule = [] scedule.append([0, 0, 0]) for i in range(N): scedule.append(list(map(int,input().split()))) for i in range(N): timelimit = scedule[i+1][0] - scedule[i][0] x_distance = abs(scedule[i+1][1] - scedule[i][1]) y_distance = abs(scedule[i+1][2] - scedule[i][2]) if timelimit < (x_distance + y_distance): print("No") exit() if timelimit % (x_distance + y_distance) != 0: print("No") exit() print("Yes")
s672444894
p00004
u525269094
1,000
131,072
Wrong Answer
30
7,760
279
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
import sys import math r = sys.stdin.readlines() r.pop(0) n = [[int(i) for i in (j.split())] for j in r] #n is list of each lines for l in n: y = (l[2]*l[3]-l[0]*l[5])/(l[1]*l[3]-l[0]*l[4]) x = (l[2]-l[1]*y)/l[0] print("{:.3f} {:.3f} ".format(x,y))
s398602737
Accepted
20
7,508
273
import sys import math r = sys.stdin.readlines() n = [[float(i) for i in (j.split())] for j in r] for l in n: y = (l[2]*l[3]-l[0]*l[5])/(l[1]*l[3]-l[0]*l[4])+0 x = (l[2]*l[4]-l[5]*l[1])/(l[0]*l[4]-l[3]*l[1])+0 print("%.3f %.3f" %(x, y))
s956442980
p04043
u077080573
2,000
262,144
Wrong Answer
37
3,068
13
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.
print("hoge")
s999993951
Accepted
1,859
7,020
279
A,B,C = input().split() array =[A,B,C] array.sort() if "5" in array[0]: del array[0] if "5" in array[0]: del array[0] if "7" in array[0]: print("YES") else: print("NO") else: print("NO") else: print("NO")
s601190435
p02417
u641082901
1,000
131,072
Wrong Answer
20
5,552
126
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
letters = 'abcdefghijklmnopqrstuvwxyz' s = input() for i in range(26) : print(letters[i] + ' : %d' % s.count(letters[i]))
s966246026
Accepted
20
5,556
154
import sys letters = 'abcdefghijklmnopqrstuvwxyz' s = sys.stdin.read().lower() for i in range(26) : print(letters[i] + ' : %d' % s.count(letters[i]))
s629638404
p03693
u252964975
2,000
262,144
Wrong Answer
17
2,940
84
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?
a,b,c=map(int, input().split()) if 10*b+c%4 == 0: print('YES') else: print('NO')
s318068331
Accepted
17
2,940
87
a,b,c=map(int, input().split()) if (10*b+c)%4 == 0: print('YES') else: print('NO')
s627586738
p02748
u399481362
2,000
1,048,576
Wrong Answer
440
50,424
558
You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
s = input().split(' ') n = 0 if int(s[0]) > 0: n += 1 if int(s[1]) > 0: n += 1 if int(s[2]) > 0: n += int(s[2]) coupon = [] for times in range(1, n+1): if times == 1: ref = input().split(' ') if times == 2: micro = input().split(' ') if times > 2: coupon.append(input().split(' ')) price = int(ref[0]) + int(micro[0]) minPrice = price for discount in coupon: price = int(ref[int(discount[0])-1]) + int(micro[int(discount[1])-1]) - int(discount[2]) minPrice = min(minPrice, price) print("$$$", minPrice)
s505320761
Accepted
554
50,804
643
s = input().split(' ') n = 0 if int(s[0]) > 0: n += 1 if int(s[1]) > 0: n += 1 if int(s[2]) > 0: n += int(s[2]) coupon = [] for times in range(1, n+1): if times == 1: ref = input().split(' ') if times == 2: micro = input().split(' ') if times > 2: coupon.append(input().split(' ')) price = int(ref[0]) + int(micro[0]) minPrice = price for discount in coupon: price = int(ref[int(discount[0])-1]) + int(micro[int(discount[1])-1]) - int(discount[2]) minPrice = min(minPrice, price) ref.sort() micro.sort() price = int(ref[0]) + int(micro[0]) minPrice = min(minPrice, price) print(minPrice)
s526932917
p02262
u612243550
6,000
131,072
Wrong Answer
20
7,688
548
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and int(A[j]) > int(v): A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = v def shellSort(A, n): global m, G for i in range(0, m): insertionSort(A, n, G[i]) cnt = 0 n = int(input()) A = [] for i in range(0, n): A.append(int(input())) m = 3 G = (4,3,1) shellSort(A, n) print(m) print(" ".join(map(str, G))) print(cnt) for i in range(0, n): print(A[i])
s779091403
Accepted
21,860
47,520
683
def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j + g] = A[j] j = j - g cnt += 1 A[j + g] = v def shellSort(A, n): global m, G for i in range(0, m): insertionSort(A, n, G[i]) n = int(input()) A = [] for i in range(0, n): A.append(int(input())) G = [] h = 1 for i in range(1, 999999): if h > n: break G.append(h) h = 3 * h + 1 G.reverse() cnt = 0 m = len(G) shellSort(A, n) ''' m = 2 G = (4,1) shellSort(A, n) ''' print(m) print(" ".join(map(str, G))) print(cnt) for i in range(0, n): print(A[i])
s437388183
p04043
u600261652
2,000
262,144
Wrong Answer
17
2,940
81
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 = input().split() print("YES" if A.count(5) == 2 and A.count(7) == 1 else "NO")
s220905398
Accepted
17
2,940
85
A = input().split() print("YES" if A.count("5") == 2 and A.count("7") == 1 else "NO")
s043697602
p03672
u362829196
2,000
262,144
Wrong Answer
17
3,060
255
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys S = sys.stdin.readline() for i in range(1, len(S)): S2 = S[0:-i] if len(S2)%2 != 0: continue S3 = S2[0:int(len(S2)/2)] S4 = S2[int(len(S2)/2):] if S3 == S4: print(str(len(S2))) break
s566378936
Accepted
17
3,060
303
S = str(input()) S = S[:-1] hantei = False while hantei == False: if len(S) % 2 == 1: S = S[:-1] else: half = int(len(S)/2) last = int(len(S)) if S[0:half] == S[half:last]: print(last) hantei = True else: S = S[0:-1]