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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s655817869 | p03544 | u011872685 | 2,000 | 262,144 | Wrong Answer | 2,205 | 9,120 | 150 | It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2) | N=int(input())
def ryuka(n):
if n==0:
return 2
elif n==1:
return 1
else:
return ryuka(n-1)+ryuka(n-2)
ryuka(N) | s986350194 | Accepted | 29 | 9,088 | 126 | #79B
N=int(input())
data=[2]
data.append(1)
for i in range(2,N+1):
data.append(data[i-1]+data[i-2])
print(data[N]) |
s984960646 | p02747 | u180926680 | 2,000 | 1,048,576 | Wrong Answer | 18 | 2,940 | 117 | A Hitachi string is a concatenation of one or more copies of the string `hi`. For example, `hi` and `hihi` are Hitachi strings, while `ha` and `hii` are not. Given a string S, determine whether S is a Hitachi string. | S = str(input())
S_size = len(S)
hi_size = S.count('hi')
if S_size == hi_size * 2:
print('yes')
else:
print('no') | s534963942 | Accepted | 17 | 2,940 | 117 | S = str(input())
S_size = len(S)
hi_size = S.count('hi')
if S_size == hi_size * 2:
print('Yes')
else:
print('No') |
s694720756 | p02401 | u671553883 | 1,000 | 131,072 | Wrong Answer | 40 | 7,556 | 310 | Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part. | while True:
a, op, b = input().split()
a = int(a)
b = int(b)
if op == '?':
break
if op == '+':
print(a + b)
if op == '-':
print(a - b)
if op == '*':
print(a * b)
if op == '%':
print(a % b) | s085230414 | Accepted | 20 | 7,652 | 317 | while True:
a, op, b = input().split()
a = int(a)
b = int(b)
if op == '?':
break
if op == '+':
print(a + b)
if op == '-':
print(a - b)
if op == '*':
print(a * b)
if op == '/':
print(a // b)
|
s225072615 | p03494 | u627530854 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 209 | 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 count_factors(num, fact):
res = 0
while num % fact == 0:
res += 1
num //= fact
return res
nums = [int(tok) for tok in input().split()]
print(min(map((lambda n : count_factors(n, 2)), nums))) | s859151162 | Accepted | 18 | 3,060 | 220 | def count_factors(num, fact):
if num % fact != 0:
return 0
return 1 + count_factors(num // fact, fact)
input()
nums = [int(tok) for tok in input().split()]
print(min(map((lambda n : count_factors(n, 2)), nums))) |
s854396881 | p03997 | u121732701 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 70 | You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid. | a = int(input())
b = int(input())
h = int(input())
print((a+b)*h/2) | s645641843 | Accepted | 17 | 2,940 | 75 | a = int(input())
b = int(input())
h = int(input())
print(int((a+b)*h/2)) |
s176996513 | p02928 | u802191176 | 2,000 | 1,048,576 | Wrong Answer | 2,104 | 3,188 | 308 | 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=(input().split())
N,K=int(N),int(K)
seq=list(input().split())
seq=[int(x) for x in seq]
print(seq)
cou=0
C=0
inc=0
for i in range(len(seq)):
for j in range(i+1,len(seq)):
if seq[i]>seq[j]: cou+=1
if seq[i]<seq[j]: inc+=1
for m in range(K):
C+=((K-m)*cou+m*inc)
print(C%(10**9+7))
| s566825342 | Accepted | 1,050 | 3,188 | 333 | N,K=(input().split())
N,K=int(N),int(K)
seq=list(input().split())
seq=[int(x) for x in seq]
cou=0
C=0
inc=0
for i in range(len(seq)):
for j in range(i+1,len(seq)):
if seq[i]>seq[j]: cou+=1
for i in range(len(seq)):
for j in range(len(seq)):
if seq[i]>seq[j]: inc+=1
C=(K*(K-1)//2)*inc+K*cou
print(C%(10**9+7)) |
s392890543 | p03024 | u874549552 | 2,000 | 1,048,576 | Wrong Answer | 18 | 2,940 | 136 | Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility. | s=list(input())
maru = 0
for i in range(len(s)):
if s[i] == "o":
maru = maru + 1
if maru >= 8:
print("YES")
else:
print("NO") | s632455723 | Accepted | 17 | 3,060 | 192 | s=list(input())
maru = 0
batu = 0
for i in range(len(s)):
if s[i] == "o":
maru = maru + 1
else:
batu = batu + 1
if 15 - maru - batu >= 8 - maru:
print("YES")
else:
print("NO") |
s333903618 | p02972 | u941645670 | 2,000 | 1,048,576 | Wrong Answer | 49 | 6,488 | 65 | 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. | #d
n = int(input())
a = list(map(int, input().split()))
print(-1) | s318931862 | Accepted | 220 | 14,776 | 294 | #d
n = int(input())
a = list(map(int, input().split()))
ans = [0]*len(a)
for i in range(len(a),0,-1):
if sum(ans[i-1::i])%2 != a[i-1]:
ans[i-1] = 1
print(sum(ans))
if sum(ans) > 0:
ans_n = [str(i+1) for i, x in enumerate(ans) if x==1]
ans_n=" ".join(ans_n)
print(ans_n) |
s006423500 | p02393 | u553058997 | 1,000 | 131,072 | Wrong Answer | 20 | 7,468 | 52 | Write a program which reads three integers, and prints them in ascending order. | a = list(map(int, input().split()))
print(sorted(a)) | s393211473 | Accepted | 30 | 7,576 | 78 | a = list(map(int, input().split()))
print(' '.join(list(map(str, sorted(a))))) |
s234174167 | p00036 | u647694976 | 1,000 | 131,072 | Time Limit Exceeded | 9,990 | 5,560 | 730 | 縦 8、横 8 のマスからなる図 1 のような平面があります。 □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ 図1 --- この平面上に、以下の A から G の図形のどれかが一つだけ置かれています。 | A --- ■| ■| | ---|---|---|--- ■| ■| | | | | | | | | B --- | ■| | ---|---|---|--- | ■| | | ■| | | ■| | | C --- ■| ■| ■| ■ ---|---|---|--- | | | | | | | | | | D --- | ■| | ---|---|---|--- ■| ■| | ■| | | | | | | E --- ■| ■| | ---|---|---|--- | ■| ■| | | | | | | | F --- ■| | | ---|---|---|--- ■| ■| | | ■| | | | | | G --- | ■| ■| ---|---|---|--- ■| ■| | | | | | | | たとえば、次の図 2 の例では E の図形が置かれています。 | □| □| □| □| □| □| □| □ ---|---|---|---|---|---|---|--- □| □| □| □| □| □| □| □ □| ■| ■| □| □| □| □| □ □| □| ■| ■| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ □| □| □| □| □| □| □| □ 図2 --- 平面の中で図形が占めているマスを 1、占めていないマスを 0 で表現した数字の列を読み込んで、置かれている図形の種類(A〜G)を出力するプログラムを作成してください。 ただし、ひとつの平面に置かれている図形は必ず1つで、複数の図形が置かれていることはありません。また、A〜G で表される図形以外のものが置かれていることはありません。 | def trim():
num=[]
N=[input() for _ in range(8)]
for x in range(8):
for y in range(8):
if N[y][x]=="1":
if not num:
refer=(x,y)
num.append((x,y))
num=[(x-refer[0],y-refer[1]) for x,y in num]
return num
def point(point):
if point==[(0,0),(0,1),(1,0),(1,1)]:print("A")
if point==[(0,0),(0,1),(0,2),(0,3)]:print("B")
if point==[(1,0),(2,0),(3,0),(4,0)]:print("C")
if point==[(0,0),(0,1),(1,-1),(1,0)]:print("D")
if point==[(0,0),(1,0),(1,1),(2,1)]:print("E")
if point==[(0,0),(0,1),(1,1),(1,2)]:print("F")
if point==[(0,0),(1,-1),(1,0),(2,-1)]:print("G")
while True:
try:
point(trim)
except:break
| s036040581 | Accepted | 20 | 5,584 | 749 | def trim(N):
num=[]
for x in range(8):
for y in range(8):
if N[y][x]=="1":
if not num:
refer=(x,y)
num.append((x,y))
num=[(x-refer[0],y-refer[1]) for x,y in num]
return num
def points(point):
if point==[(0,0),(0,1),(1,0),(1,1)]:print("A")
if point==[(0,0),(0,1),(0,2),(0,3)]:print("B")
if point==[(0,0),(1,0),(2,0),(3,0)]:print("C")
if point==[(0,0),(0,1),(1,-1),(1,0)]:print("D")
if point==[(0,0),(1,0),(1,1),(2,1)]:print("E")
if point==[(0,0),(0,1),(1,1),(1,2)]:print("F")
if point==[(0,0),(1,-1),(1,0),(2,-1)]:print("G")
while True:
N=[input() for _ in range(8)]
points(trim(N))
try:
input()
except:break
|
s766100289 | p03469 | u931938233 | 2,000 | 262,144 | Wrong Answer | 29 | 9,020 | 36 | On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it. | print('2018/01/',input()[8:],end='') | s841890999 | Accepted | 28 | 8,876 | 29 | print('2018/01/'+input()[8:]) |
s877027835 | p03385 | u361826811 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 266 | You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`. |
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode('utf8')
print('Yes' if set('abc') == set(S) else 'No')
| s776035220 | Accepted | 17 | 2,940 | 275 |
import sys
# import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
S = readline().decode('utf8').rstrip()
print('Yes' if set('abc') == set(S) else 'No')
|
s558116860 | p03548 | u107039373 | 2,000 | 262,144 | Wrong Answer | 30 | 2,940 | 86 | We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat? | a,b,c = map(int,input().split())
x = 1
while a >= b*x + c*(x+1):
x += 1
print(x) | s185467341 | Accepted | 29 | 2,940 | 89 | a,b,c = map(int,input().split())
x = 1
while a >= b*x + c*(x+1):
x += 1
print(x-1)
|
s064108868 | p03696 | u886747123 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 245 | 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. | # D - Insertion
N = int(input())
S = input().split("()")
ans = []
for x in S:
tmp = x
for _ in range(x.count(")")):
tmp = "(" + tmp
for _ in range(x.count("(")):
tmp += ")"
ans.append(tmp)
print("()".join(ans)) | s671230393 | Accepted | 20 | 3,060 | 162 | # D - Insertion
N = int(input())
S = input()
s = S
for _ in range(50):
s = s.replace("()", "")
ans = "(" * s.count(")") + S + ")" * s.count("(")
print(ans) |
s951429354 | p03635 | u725324053 | 2,000 | 262,144 | Wrong Answer | 31 | 9,036 | 69 | In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city? | n,m = input().split()
n = int(n)
m = int(m)
print ((n + 1) * (m + 1)) | s239446398 | Accepted | 27 | 9,096 | 69 | n,m = input().split()
n = int(n)
m = int(m)
print ((n - 1) * (m - 1)) |
s763226394 | p03643 | u281303342 | 2,000 | 262,144 | Wrong Answer | 19 | 3,060 | 143 | This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer. |
# N = input()
# print("ABC"+N)
N = int(input())
print("{:03d}".format(N)) | s133467807 | Accepted | 19 | 3,060 | 149 |
# N = input()
# print("ABC"+N)
N = int(input())
print("ABC"+"{:03d}".format(N)) |
s094746478 | p03861 | u163791883 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 55 | 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 = map(int, input().split())
print((B - A) // X) | s294987802 | Accepted | 17 | 2,940 | 110 | A, B, X = map(int, input().split())
if A % X == 0:
print(B // X - A // X + 1)
else:
print(B // X - A // X) |
s782071755 | p03371 | u731448038 | 2,000 | 262,144 | Wrong Answer | 56 | 3,060 | 204 | "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas. | a, b, c, x, y = map(int, input().split())
na, nb, nc = x, y, 0
mx = 10**18
for i in range(max(x,y)):
if i%2==1: continue
total = a*(na-i//2) + b*(nb-i//2) + c*i
if total<mx:
mx=total
print(mx) | s784302472 | Accepted | 128 | 3,060 | 274 | a, b, c, x, y = map(int, input().split())
mx = 10**18
for i in range(0, max(x,y)*2+1):
if i%2==1: continue
total = max(a*(x-i//2), 0) + max(b*(y-i//2), 0) + c*i
if total<mx:
mx=total
print(mx)
|
s996372070 | p03378 | u733608212 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 114 | 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())
li = list(map(int, input().split()))
print(min(len(li[:x]), len(li[x+1:])))
| s690738107 | Accepted | 17 | 2,940 | 164 | n, m, x = map(int, input().split())
li = list(map(int, input().split()))
li = [1 if i in li else 0 for i in range(1, n+1)]
print(min(sum(li[:x-1]), sum(li[x:])))
|
s184954047 | p04029 | u498975813 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 63 | There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? | n = int(input())
ans=0
for i in range(n):
n+=1+i
print(ans) | s750966995 | Accepted | 17 | 2,940 | 65 | n = int(input())
ans=0
for i in range(n):
ans+=1+i
print(ans) |
s726473923 | p03760 | u768896740 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 211 | Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password. | o = list(input())
e = list(input())
password = []
for i in range(len(e)):
password.append(o[i])
password.append(e[i])
if o > e:
password.append(o[-1])
password = ''.join(password)
print(password) | s194805096 | Accepted | 18 | 3,060 | 221 | o = list(input())
e = list(input())
password = []
for i in range(len(e)):
password.append(o[i])
password.append(e[i])
if len(o) > len(e):
password.append(o[-1])
password = ''.join(password)
print(password) |
s560475610 | p02678 | u711238850 | 2,000 | 1,048,576 | Wrong Answer | 1,069 | 110,256 | 4,884 | There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. | import heapq
from collections import deque
class Graph:
def __init__(self,v,edgelist,w_v = None,directed = False):
super().__init__()
self.v = v
self.w_e = [{} for _ in [0]*self.v]
self.neighbor = [[] for _ in [0]*self.v]
self.w_v = w_v
self.directed = directed
for i,j,w in edgelist:
self.w_e[i][j] = w
self.neighbor[i].append(j)
def dijkstra(self,v_n):
d = [float('inf')]*self.v
d[v_n] = 0
prev = [-1]*self.v
queue = []
for i,d_i in enumerate(d): heapq.heappush(queue,(d_i,i))
while len(queue)>0:
d_u,u = queue.pop()
if d[u]<d_u :continue
for v in self.neighbor[u]:
alt = d[u]+self.w_e[u][v]
if d[v]>alt:
d[v] = alt
prev[v] = u
heapq.heappush(queue,(alt,v))
return d,prev
def warshallFloyd(self):
d = [[10**18]*self.v for _ in [0]*self.v]
for i in range(self.v):
d[i][i] = 0
for i in range(self.v):
for j in self.neighbor[i]:
d[i][j] = self.w_e[i][j]
for i in range(self.v):
for j in self.neighbor[i]:
d[i][j] = self.w_e[i][j]
for k in range(self.v):
for i in range(self.v):
for j in range(self.v):
check = d[i][k] + d[k][j]
if d[i][j] > check:
d[i][j] = check
return d
def prim(self):
gb = GraphBuilder(self.v,self.directed)
queue = []
for i,w in self.w_e[0].items(): heapq.heappush(queue,(w,0,i))
rest = [True]*self.v
rest[0] = False
while len(queue)>0:
w,i,j = heapq.heappop(queue)
if rest[j]:
gb.addEdge(i,j,w)
rest[j] = False
for k,w in self.w_e[j].items():
if rest[k]:
heapq.heappush(queue,(w,j,k))
return gb
def bfs(self,vartex = 0):
todo = [True]*self.v
queue = deque([vartex])
while(len(queue)>0):
v = queue.popleft
todo[v] = False
yield v
for v_i in self.neighbor[v]:
if todo[v_i]:
queue.append(v_i)
def dfs(self,vartex = 0):
seen = [False]*self.v
def recdfs(v):
seen[vartex] = True
for next_v in self.neighbor[vartex]:
if (seen[next_v]):continue
recdfs(next_v)
class Tree():
def __init__(self,v,e):
pass
class GraphBuilder():
def __init__(self,v,directed = False,edge = None, weights = None):
self.v = v
self.directed = directed
self.edge = []
self.weights = []
if edge is not None:
self.addEdges(edge)
if weights is not None:
self.addVartex(weights)
def addEdge(self,i,j,w=1):
if not self.directed:
self.edge.append((j,i,w))
self.edge.append((i,j,w))
def addEdges(self,edgelist,weight = True):
if weight:
if self.directed:
for i,j,w in edgelist:
self.edge.append((i,j,w))
else:
for i,j,w in edgelist:
self.edge.append((i,j,w))
self.edge.append((j,i,w))
else:
if self.directed:
for i,j in edgelist:
self.edge.append((i,j,1))
else:
for i,j in edgelist:
self.edge.append((i,j,1))
self.edge.append((j,i,1))
def addVartex(self,weights):
if len(weights) != self.v:
return
self.weights.extend(weights)
def addAdjMat(self, mat):
for i,mat_i in enumerate(mat):
for j,w in enumerate(mat_i):
self.edge.append((i,j,w))
def buildTree(self):
pass
def buildGraph(self):
return Graph(self.v,self.edge,directed=self.directed)
def main():
n,m = tuple([int(t)for t in input().split()])
edge = []
for i in range(m):
a,b = tuple([int(t)for t in input().split()])
edge.append((a-1,b-1,1))
gb = GraphBuilder(n,edge=edge)
g = gb.buildGraph()
queue = deque([0])
root = [-1]*n
checked = [False]*n
while(len(queue)>0):
p = queue.popleft()
if checked[p]:
continue
checked[p] = True
for q in g.neighbor[p]:
root[q] = p+1
queue.append(q)
if all(checked):
print("Yes")
for i in root[1:]:
print(i)
if __name__ == "__main__":
main() | s804628671 | Accepted | 932 | 109,852 | 5,030 | import heapq
from collections import deque
class Graph:
def __init__(self,v,edgelist,w_v = None,directed = False):
super().__init__()
self.v = v
self.w_e = [{} for _ in [0]*self.v]
self.neighbor = [[] for _ in [0]*self.v]
self.w_v = w_v
self.directed = directed
for i,j,w in edgelist:
self.w_e[i][j] = w
self.neighbor[i].append(j)
def dijkstra(self,v_n):
d = [float('inf')]*self.v
d[v_n] = 0
prev = [-1]*self.v
queue = []
for i,d_i in enumerate(d): heapq.heappush(queue,(d_i,i))
while len(queue)>0:
d_u,u = queue.pop()
if d[u]<d_u :continue
for v in self.neighbor[u]:
alt = d[u]+self.w_e[u][v]
if d[v]>alt:
d[v] = alt
prev[v] = u
heapq.heappush(queue,(alt,v))
return d,prev
def warshallFloyd(self):
d = [[10**18]*self.v for _ in [0]*self.v]
for i in range(self.v):
d[i][i] = 0
for i in range(self.v):
for j in self.neighbor[i]:
d[i][j] = self.w_e[i][j]
for i in range(self.v):
for j in self.neighbor[i]:
d[i][j] = self.w_e[i][j]
for k in range(self.v):
for i in range(self.v):
for j in range(self.v):
check = d[i][k] + d[k][j]
if d[i][j] > check:
d[i][j] = check
return d
def prim(self):
gb = GraphBuilder(self.v,self.directed)
queue = []
for i,w in self.w_e[0].items(): heapq.heappush(queue,(w,0,i))
rest = [True]*self.v
rest[0] = False
while len(queue)>0:
w,i,j = heapq.heappop(queue)
if rest[j]:
gb.addEdge(i,j,w)
rest[j] = False
for k,w in self.w_e[j].items():
if rest[k]:
heapq.heappush(queue,(w,j,k))
return gb
def bfs(self,vartex = 0):
todo = [True]*self.v
queue = deque([vartex])
while(len(queue)>0):
v = queue.popleft
todo[v] = False
yield v
for v_i in self.neighbor[v]:
if todo[v_i]:
queue.append(v_i)
def dfs(self,vartex = 0):
seen = [False]*self.v
def recdfs(v):
seen[vartex] = True
for next_v in self.neighbor[vartex]:
if (seen[next_v]):continue
recdfs(next_v)
class Tree():
def __init__(self,v,e):
pass
class GraphBuilder():
def __init__(self,v,directed = False,edge = None, weights = None):
self.v = v
self.directed = directed
self.edge = []
self.weights = []
if edge is not None:
self.addEdges(edge)
if weights is not None:
self.addVartex(weights)
def addEdge(self,i,j,w=1):
if not self.directed:
self.edge.append((j,i,w))
self.edge.append((i,j,w))
def addEdges(self,edgelist,weight = True):
if weight:
if self.directed:
for i,j,w in edgelist:
self.edge.append((i,j,w))
else:
for i,j,w in edgelist:
self.edge.append((i,j,w))
self.edge.append((j,i,w))
else:
if self.directed:
for i,j in edgelist:
self.edge.append((i,j,1))
else:
for i,j in edgelist:
self.edge.append((i,j,1))
self.edge.append((j,i,1))
def addVartex(self,weights):
if len(weights) != self.v:
return
self.weights.extend(weights)
def addAdjMat(self, mat):
for i,mat_i in enumerate(mat):
for j,w in enumerate(mat_i):
self.edge.append((i,j,w))
def buildTree(self):
pass
def buildGraph(self):
return Graph(self.v,self.edge,directed=self.directed)
def main():
n,m = tuple([int(t)for t in input().split()])
edge = []
for i in range(m):
a,b = tuple([int(t)for t in input().split()])
edge.append((a-1,b-1,1))
gb = GraphBuilder(n,edge=edge)
g = gb.buildGraph()
queue = deque([0])
root = [-1]*n
checked = [False]*n
determined = [False]*n
while(len(queue)>0):
p = queue.popleft()
if checked[p]:
continue
checked[p] = True
for q in g.neighbor[p]:
if determined[q]:
continue
root[q] = p+1
queue.append(q)
determined[q] = True
if all(checked):
print("Yes")
for i in root[1:]:
print(i)
else:
print("No")
if __name__ == "__main__":
main() |
s518696487 | p02468 | u659034691 | 1,000 | 131,072 | Wrong Answer | 20 | 7,624 | 189 | For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M. | m,n=(int(i) for i in input().split())
m2=1
while n>0:
m1=m
l=1
while l<n:
m1*=m1
l*=2
n-=l
m2*=m1
if m2>1000000007:
m2//=1000000007
print(m2) | s564131461 | Accepted | 40 | 7,800 | 300 | # your code goes here
m,n=(int(i) for i in input().split())
m2=1
while n>0:
m1=m
l=1
while l*2<=n:
m1*=m1
if m1>1000000007:
m1%=1000000007
# print(m1)
l*=2
n-=l
m2*=m1
if m2>1000000007:
m2%=1000000007
# print(m2)
print(m2) |
s028324223 | p02612 | u033893324 | 2,000 | 1,048,576 | Wrong Answer | 26 | 9,144 | 30 | We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. | a=int(input())
print(a % 1000) | s526174085 | Accepted | 25 | 9,148 | 68 | a=int(input())
b=a % 1000
if b>>0:
print(1000-b)
else:
print(0)
|
s965364501 | p02613 | u107091170 | 2,000 | 1,048,576 | Wrong Answer | 160 | 9,196 | 239 | 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())
a = 0
w = 0
t = 0
r = 0
for i in range(N):
S=input();
if S[0] == "A":
a+=1
elif S[0] == "W":
w+=1
elif S[0] == "T":
t+=1
else:
r+=1
print("AC x",a)
print("WC x",w)
print("TLE x",t)
print("RE x",r)
| s018581087 | Accepted | 150 | 9,136 | 239 | N=int(input())
a = 0
w = 0
t = 0
r = 0
for i in range(N):
S=input();
if S[0] == "A":
a+=1
elif S[0] == "W":
w+=1
elif S[0] == "T":
t+=1
else:
r+=1
print("AC x",a)
print("WA x",w)
print("TLE x",t)
print("RE x",r)
|
s005007880 | p03090 | u016128476 | 2,000 | 1,048,576 | Wrong Answer | 38 | 3,976 | 885 | You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem. | # input
n = int(input())
# 1. make validate graph fragment (all index are includede completely)
fragments = []
if n % 2 == 0:
fragments = [(i + 1, n - i) for i in range(n // 2)]
else:
fragments = [(i + 1, n - i - 1) for i in range(n // 2)]
fragments.append((n,))
# 2. each vertex connect all vertex excepy for one's belonging graph's element
edges = []
for i, frag in enumerate(fragments):
for vtx in frag:
other_frags = fragments[:i] + fragments[i + 1:]
edges.extend([(vtx, o_vtx) for o_frag in other_frags for o_vtx in o_frag])
for edge in edges:
if edge[0] > edge[1]:
del edge
print(len(edges))
for edge in edges:
print(' '.join(str(i) for i in edge))
| s192179119 | Accepted | 371 | 3,976 | 898 | # input
n = int(input())
# 1. make validate graph fragment (all index are includede completely)
fragments = []
if n % 2 == 0:
fragments = [(i + 1, n - i) for i in range(n // 2)]
else:
fragments = [(i + 1, n - i - 1) for i in range(n // 2)]
fragments.append((n,))
# 2. each vertex connect all vertex excepy for one's belonging graph's element
edges = []
for i, frag in enumerate(fragments):
for vtx in frag:
other_frags = fragments[:i] + fragments[i + 1:]
edges.extend([(vtx, o_vtx) for o_frag in other_frags for o_vtx in o_frag])
for edge in edges[:]:
if edge[0] > edge[1]:
edges.remove(edge)
print(len(edges))
for edge in edges:
print(' '.join(str(i) for i in edge))
|
s604374273 | p03007 | u046432236 | 2,000 | 1,048,576 | Wrong Answer | 64 | 14,060 | 256 | There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer. | n=int(input())
newlist = list(map(int, input().split()))
switch=0
mazu=newlist[0]
for nl in newlist:
if mazu!=nl:
switch=1
if switch==1:
wa=0
for nl in newlist:
wa+=abs(nl)
print(wa)
else:
print(mazu*(len(newlist)-2)) | s711404190 | Accepted | 363 | 22,264 | 3,068 | n=int(input())
newlist = list(map(int, input().split()))
switch=0
counter=0
mazu=newlist[0]
if newlist[0]>=0:
seihu=1
else:
seihu=-1
konzai=0
for nl in newlist:
if mazu!=nl:
switch=1
if switch==1:
wa=0
list2=[]
for nl in range(n):
list2.append([newlist[nl], abs(newlist[nl])])
if seihu*newlist[nl]<0:
konzai=1
numb=nl
numba=newlist[numb]
if konzai==1:
wa=0
for nl in range(n):
wa+=abs(newlist[nl])
print(wa)
now=newlist[numb]
#print(newlist)
newlist.remove(numba)
#print(newlist)
#print(now,newlist[0])
#print('d', now, newlist[0], newlist[1])
if newlist[1]>0:
if now>=0:
#now*=-1
print(newlist[0], now)
else:
#now*=-1
print(now,newlist[0])
else:
if now>=0:
print(now, newlist[0])
else:
print(newlist[0], now)
now=abs(now)+abs(newlist[0])
if newlist[1]>0:
now=now*(-1)
for xi in range(n-3):
#print('d', now, newlist[xi+1], newlist[xi+2])
if newlist[xi+2]>0:
if now>=0:
print(newlist[xi+1], now)
else:
print(now, newlist[xi+1])
now=-abs(now)-abs(newlist[xi+1])
else:
if now>=0:
print(now, newlist[xi+1])
else:
print(newlist[xi+1], now)
now=abs(now)+abs(newlist[xi+1])
if newlist[-1]>0:
print(newlist[-1], now)
else:
print(now, newlist[-1])
elif seihu==1:
newlist=sorted(newlist)
wa=0
for nl in range(n):
wa+=abs(newlist[nl])
wa-=newlist[0]*2
print(wa)
print(newlist[0], newlist[1])
now=newlist[0]-newlist[1]
for ll in range(n-2):
if counter==n-3:
print(newlist[ll+2], now)
now=-(abs(now)+abs(newlist[ll+2]))
else:
print(now, newlist[ll+2])
now=-(abs(now)+abs(newlist[ll+2]))
counter+=1
elif seihu==-1:
newlist=sorted(newlist, reverse=True)
wa=0
for nl in range(n):
wa+=abs(newlist[nl])
wa+=newlist[0]*2
print(wa)
print(newlist[0], newlist[1])
now=newlist[0]-newlist[1]
for ll in range(n-2):
if counter==n-3:
print(now, newlist[ll+2])
now=(abs(now)+abs(newlist[ll+2]))
else:
print(now, newlist[ll+2])
now=(abs(now)+abs(newlist[ll+2]))
counter+=1
else:
print(abs(mazu*(len(newlist)-2)))
for i in range(len(newlist)-2):
print(mazu*(1-i), mazu)
if mazu>=0:
print(mazu, mazu*(3-len(newlist)))
else:
print(mazu*(3-len(newlist)), mazu) |
s133832989 | p00074 | u150984829 | 1,000 | 131,072 | Wrong Answer | 20 | 5,636 | 190 | 標準録画で 120 分のビデオテープがあります。テープを完全に巻き戻した状態でビデオデッキのカウンタを 00:00:00 にし、標準録画モードで録画したところ、あるカウンタ値になりました。このカウンタ値(時、分、秒)を入力し、残りのテープの長さ(録画可能時間)を求め、時:分:秒の形式で出力するプログラムを作成して下さい。 ただし、2 時間(120分)以内の入力とします。なお、テープ残量は標準録画モードと 3 倍録画モードの場合の2通りを計算し、出力例のように時、分、秒とも 2 桁ずつ出力します。また "05" のように 10 の位が 0 の場合は、"0" をつけてください。 | while 1:
t,h,s=map(int,input().split())
if t<0:break
d,e=7200,t*3600+h*60+s
a,b=d-e,d-e/3
print(f'{a//3600:02}:{a//60%60:02}:{a%60:02}')
print(f'{b//3600:02}:{b//60%60:02}:{b%60:02}')
| s773462136 | Accepted | 20 | 5,612 | 152 | p=lambda x:print(f'{x//3600:02}:{x//60%60:02}:{x%60:02}')
for e in iter(input,'-1 -1 -1'):
h,m,s=map(int,e.split())
d=7200-h*3600-m*60-s
p(d);p(d*3)
|
s250146373 | p02409 | u130834228 | 1,000 | 131,072 | Wrong Answer | 20 | 7,612 | 356 | You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building. | import sys
n = int(input())
list_room = [0 for i in range(120)]
for i in range(n):
b, f, r, v = map(int, input().split())
room = ((b-1)*3+(f-1))*10 + r-1
list_room[room] += v
#print(list_room)
for i in range(4):
for j in range(3):
line = ""
for k in range(10):
line += " "+str(list_room[i*30 + j*10 + k])
print(line)
print("#"*20)
| s183475542 | Accepted | 20 | 7,632 | 368 | import sys
n = int(input())
list_room = [0 for i in range(120)]
for i in range(n):
b, f, r, v = map(int, input().split())
room = ((b-1)*3+(f-1))*10 + r-1
list_room[room] += v
#print(list_room)
for i in range(4):
for j in range(3):
line = ""
for k in range(10):
line += " "+str(list_room[i*30 + j*10 + k])
print(line)
if i != 3:
print("#"*20)
|
s050303320 | p03456 | u559103167 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 86 | AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number. | a = int("".join(list(input().split())))
print("YES" if (int(a**.5))**2 == a else "NO") | s287156774 | Accepted | 17 | 2,940 | 86 | a = int("".join(list(input().split())))
print("Yes" if (int(a**.5))**2 == a else "No") |
s411988946 | p03407 | u533679935 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 76 | An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. | A,B,C=map(int,input().split())
if A+B>=C:
print('No')
else:
print('Yes') | s517958643 | Accepted | 17 | 2,940 | 84 | A,B,C=map(int,input().split())
if A+B>=C:
print('Yes')
elif A+B<=C:
print('No')
|
s508992981 | p03795 | u802772880 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 35 | Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y. | n=int(input())
print(n*800-40*n//3) | s305777190 | Accepted | 17 | 2,940 | 39 | n=int(input())
print(n*800-200*(n//15)) |
s582141658 | p03796 | u354126779 | 2,000 | 262,144 | Wrong Answer | 42 | 2,940 | 69 | Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7. | n=int(input())
p=1
for i in range(1,n+1):
p=p*i
p=p%(10**9+7) | s348471338 | Accepted | 42 | 2,940 | 78 | n=int(input())
p=1
for i in range(1,n+1):
p=p*i
p=p%(10**9+7)
print(p) |
s052465087 | p03672 | u384124931 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 130 | 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. | s = input()
for i in range(1, len(s), 2):
a = s[:-i]
if a[:len(a)//2]==a[len(a)//2:]:
print(len(a))
exit() | s422427660 | Accepted | 17 | 2,940 | 130 | s = input()
for i in range(2, len(s), 2):
a = s[:-i]
if a[:len(a)//2]==a[len(a)//2:]:
print(len(a))
exit() |
s071127273 | p03730 | u686036872 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 154 | 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())
for i in range(1, 1000):
if B*i%A==0:
count=1
else:
count=0
print("No" if count==0 else "Yes") | s146787372 | Accepted | 19 | 2,940 | 175 | A, B, C = map(int, input().split())
for i in range(1, 10000):
if ((B*i)+C)%A==0:
count=1
break
else:
count=0
print("YES" if count==1 else "NO") |
s470023407 | p03474 | u244836567 | 2,000 | 262,144 | Wrong Answer | 26 | 9,076 | 188 | The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom. | a,b=input().split()
c=input()
a=int(a)
b=int(b)
d=0
if c[a]=="-":
for i in range(a):
if c[i]=="-":
d=d+1
if d==1:
print("Yes")
else:
print("No")
else:
print("No") | s430667625 | Accepted | 27 | 9,188 | 192 | a,b=input().split()
c=input()
a=int(a)
b=int(b)
d=0
if c[a]=="-":
for i in range(a+b+1):
if c[i]=="-":
d=d+1
if d==1:
print("Yes")
else:
print("No")
else:
print("No") |
s923649451 | p03435 | u214344212 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 373 | 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. | a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
true=0
while true==0:
if b[0]-a[0]==b[1]-a[1]==b[2]-a[2]:
true+=0
else:
true+=1
if c[0]-b[0]==c[1]-b[1]==c[2]-b[2]:
true+=0
break
else:
true+=1
break
if true==0:
print('yes')
else:
print('No') | s370314305 | Accepted | 17 | 3,064 | 443 | c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))
num=0
if c1[1]-c1[0]==c2[1]-c2[0]==c3[1]-c3[0]:
num+=0
else:
num+=1
if c1[2]-c1[1]==c2[2]-c2[1]==c3[2]-c3[1]:
num+=0
else:
num+=1
if c2[0]-c1[0]==c2[1]-c1[1]==c2[2]-c1[2]:
num+=0
else:
num+=1
if c3[0]-c2[0]==c3[1]-c2[1]==c3[2]-c2[2]:
num+=0
else:
num+=1
if num==0:
print("Yes")
else:
print("No") |
s456132965 | p04045 | u463836923 | 2,000 | 262,144 | Wrong Answer | 40 | 3,192 | 614 | Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier. | #coding=UTF-8
mojir=input()
hyo=mojir.split(' ')
N=int(hyo[0])
K=int(hyo[1])
mojir=input()
hyo=mojir.split(' ')
D=[int(mono) for mono in hyo]
kouho=N
def usecheck(gaku):
gakustr=str(gaku)
keta=len(gakustr)
dame=None
for idx in range(0,keta,1):
if gakustr[idx] in hyo:
dame=idx
break
if dame == None:
return None
else:
return (keta-dame)
while True:
print(kouho)
dameketa=usecheck(kouho)
if dameketa == None:
break
kouho=(kouho//(10**(dameketa-1)) +1)*(10**(dameketa-1))
print(kouho)
| s085766481 | Accepted | 40 | 3,064 | 615 | #coding=UTF-8
mojir=input()
hyo=mojir.split(' ')
N=int(hyo[0])
K=int(hyo[1])
mojir=input()
hyo=mojir.split(' ')
D=[int(mono) for mono in hyo]
kouho=N
def usecheck(gaku):
gakustr=str(gaku)
keta=len(gakustr)
dame=None
for idx in range(0,keta,1):
if gakustr[idx] in hyo:
dame=idx
break
if dame == None:
return None
else:
return (keta-dame)
while True:
dameketa=usecheck(kouho)
if dameketa == None:
break
kouho=(kouho//(10**(dameketa-1)) +1)*(10**(dameketa-1))
print(kouho)
|
s454697086 | p03698 | u464912173 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 116 | You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different. | s = list(input().split())
s.sort()
for i in range(len(s)-1):
if s[i]==s[i+1]:
print('no')
else: print('yes') | s923230694 | Accepted | 17 | 2,940 | 72 | a = input()
if len(a)==len(set(a)):
print('yes')
else: print('no') |
s005032379 | p02409 | u587193722 | 1,000 | 131,072 | Wrong Answer | 20 | 7,736 | 339 | You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building. | date = [
[[0 for r in range(10)] for f in range(3)] for b in range(4)
]
count = int(input())
for c in range(count):
b,f,r,v= [int(i) for i in input().split()]
date[b-1][f-1][r-1] +=v
for b in date:
for f in b:
for r in f:
print(' {0}'.format(r), end='')
print('#' * 20)
| s540783846 | Accepted | 20 | 7,640 | 377 | data = [
[[0 for r in range(10)] for f in range(3)] for b in range(4)
]
count = int(input())
for c in range(count):
b, f, r, v = [int(i) for i in input().split()]
data[b - 1][f - 1][r - 1] += v
for bi, b in enumerate(data):
for f in b:
for r in f:
print(' {0}'.format(r), end='')
print()
if bi < 3:
print('#' * 20) |
s924754135 | p03861 | u393512980 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 59 | 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 = map(int, input().split())
print((b - a + 1) // x) | s807135676 | Accepted | 17 | 2,940 | 65 | a, b, x = map(int, input().split())
print(b // x - (a - 1) // x)
|
s945786732 | p02697 | u402629484 | 2,000 | 1,048,576 | Wrong Answer | 84 | 10,060 | 2,093 | You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given. | import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0:
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2]
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def main():
N,M=mis()
for m in range(M):
print(m+1, N-m)
main()
| s470243184 | Accepted | 115 | 29,584 | 1,437 |
from collections import deque
def main():
N, M = map(int, input().split())
if N&1:
q = deque(range(M*2))
while q:
print(q.popleft()+1, q.pop()+1)
else:
q1 = deque(range(N))
q2 = deque(range(N-1))
p1 = []
while q1:
p1.append((q1.popleft()+1, q1.pop()+1))
p2 = []
while len(q2)>=2:
p2.append((q2.popleft()+1, q2.pop()+1))
p2.reverse()
for _ in range(M):
print(*p1.pop())
p1, p2 = p2, p1
main()
|
s629117997 | p03415 | u736729525 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 39 | We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. | print(input()[0],input()[1],input()[2]) | s998213218 | Accepted | 17 | 2,940 | 46 | print(input()[0],input()[1],input()[2],sep="") |
s841496863 | p03386 | u640303028 | 2,000 | 262,144 | Wrong Answer | 34 | 3,444 | 306 | 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 = [int(i) for i in input().split()]
if a + b - 1 <= b:
for i in range(a,a+k):
print(i)
if b-a+1>=2*k:
for i in range(b-k+1,b+1):
print(i)
else:
for i in range(a+k,b+1):
print(i)
else:
for i in range(a,b+1):
print(i)
| s514101140 | Accepted | 17 | 3,060 | 293 | a,b,k = [int(i) for i in input().split()]
if a + k - 1 <= b:
for i in range(a,a+k):
print(i)
if b-a+1>=2*k:
for i in range(b-k+1,b+1):
print(i)
else:
for i in range(a+k,b+1):
print(i)
else:
for i in range(a,b+1):
print(i) |
s017952561 | p03637 | u879870653 | 2,000 | 262,144 | Wrong Answer | 65 | 14,252 | 290 | We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. | N = int(input())
A = list(map(int,input().split()))
odd = 0
even2 = 0
even4 = 0
for i in A :
if not i % 4 :
even4 += 1
elif not i % 2 :
even2 += 1
else :
odd += 1
print(odd,even2,even4)
if odd <= even4 :
ans = "Yes"
else :
ans = "No"
print(ans)
| s758680984 | Accepted | 64 | 14,252 | 243 | N = int(input())
A = list(map(int,input().split()))
odd = 0
even4 = 0
for i in A :
if not i % 4 :
even4 += 1
elif i % 2 :
odd += 1
if (odd <= even4) or (N//2 <= even4) :
ans = "Yes"
else :
ans = "No"
print(ans)
|
s832071052 | p03657 | u861141787 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 132 | Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies. | A, B = map(int, input().split())
if A + B % 3 == 0 or A % 3 == 0 or B % 3 == 0:
print("Possible")
else:
print("Impossible") | s046044290 | Accepted | 17 | 2,940 | 139 | A, B = map(int, input().split())
if (A + B) % 3 == 0 or A % 3 == 0 or B % 3 == 0:
print("Possible")
else:
print("Impossible")
|
s041111801 | p04011 | u495677768 | 2,000 | 262,144 | Wrong Answer | 41 | 3,064 | 367 | There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee. | '''
Created on 2016/08/28
@author: diyosko7
'''
import sys
if __name__ == '__main__':
n = 4
input_lines = [int(input()) for i in range(n)]
N = input_lines[0]
K = input_lines[1]
X = input_lines[2]
Y = input_lines[3]
SUM = 0
for i in range(0,N):
if i <= K:
SUM += X
else:
SUM += Y
print(SUM) | s793761268 | Accepted | 40 | 3,316 | 383 | '''
Created on 2016/08/28
@author: diyosko7
'''
if __name__ == '__main__':
n = 4
input_lines = [int(input()) for i in range(n)]
N = int(input_lines[0])
K = int(input_lines[1])
X = int(input_lines[2])
Y = int(input_lines[3])
SUM = 0
for i in range(0,N):
if i < K:
SUM += X
else:
SUM += Y
print(SUM) |
s208337679 | p02409 | u447630054 | 1,000 | 131,072 | Wrong Answer | 30 | 6,724 | 356 | You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building. | data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for nc in range(n):
(b,f,r,v) = [int(i) for i in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print('{0}'.format(data[b][f][r]), end='')
print()
print('#' * 20) | s913369963 | Accepted | 30 | 6,724 | 378 | data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for nc in range(n):
(b,f,r,v) = [int(i) for i in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print('',data[b][f][r], end='')
print()
print('#' * 20) if b < 4 - 1 else print(end='') |
s231533093 | p03447 | u477320129 | 2,000 | 262,144 | Wrong Answer | 27 | 9,088 | 69 | You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping? | X = int(input())
A = int(input())
B = int(input())
print((X-A) // B)
| s743515578 | Accepted | 28 | 9,152 | 68 | X = int(input())
A = int(input())
B = int(input())
print((X-A) % B)
|
s410463700 | p03399 | u864197622 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 48 | You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. | print(min(input(),input())+min(input(),input())) | s665169521 | Accepted | 17 | 2,940 | 61 | def A(): return int(input())
print(min(A(),A())+min(A(),A())) |
s895034672 | p03814 | u243572357 | 2,000 | 262,144 | Wrong Answer | 17 | 3,512 | 65 | Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. | s = input()
print(len(s) - 1 - s[::-1].index('Z') - s.index('A')) | s068856934 | Accepted | 18 | 3,500 | 67 | a = input()
l = len(a) - a.index('A') - a[::-1].index('Z')
print(l) |
s434614387 | p03997 | u822179469 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 71 | You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid. | a, b, h = map(int,[input() for i in range(3)])
s = (a+b)*h/2
print(s) | s508323287 | Accepted | 17 | 2,940 | 76 | a, b, h = map(int,[input() for i in range(3)])
s = (a+b)*h/2
print(int(s)) |
s133208636 | p03739 | u513081876 | 2,000 | 262,144 | Wrong Answer | 2,105 | 64,352 | 550 | You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-th term is not zero. * For every i (1≤i≤n-1), the sign of the sum of the terms from the 1-st through i-th term, is different from the sign of the sum of the terms from the 1-st through (i+1)-th term. | N = int(input())
a = [int(i) for i in input().split()]
def pura(A):
ans = 0
check = 0
if A[0] <= 0:
ans += abs(1-A[0])
A[0] = 1
check += A[0]
for i in range(1, N):
if i % 2 != 0:
if check + A[i] >= 0:
ans += abs(A[i] + 1 + check)
A[i] = -1 + check
else:
if check + A[i] <= 0:
ans += abs(A[i] - (1 + check))
A[i] = 1 - check
check += A[i]
print(ans)
return ans
print(pura(a)) | s009439359 | Accepted | 159 | 14,468 | 884 | n = int(input())
a = [int(i) for i in input().split()]
ans1 = 0
ans2 = 0
summ = 0
summ2 = 0
a2 = a[:]
for i in range(n):
if i % 2 == 0:
if summ + a[i] <= 0:
ans1 += abs(summ + a[i]) + 1
a[i] = -summ + 1
summ = 1
else:
summ += a[i]
else:
if summ + a[i] >= 0:
ans1 += abs(summ + a[i]) + 1
a[i] = -summ -1
summ = -1
else:
summ += a[i]
#-+-
for i in range(n):
if i % 2 != 0:
if summ2 + a2[i] <= 0:
ans2 += abs(summ2 + a2[i]) + 1
a2[i] = -summ2 + 1
summ2 = 1
else:
summ2 += a2[i]
else:
if summ2 + a2[i] >= 0:
ans2 += abs(summ2 + a2[i]) + 1
a2[i] = -summ2 -1
summ2 = -1
else:
summ2 += a2[i]
print(min(ans1, ans2))
|
s727062062 | p02578 | u382639013 | 2,000 | 1,048,576 | Wrong Answer | 136 | 32,256 | 148 | N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal. | n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(len(a)-1):
if a[i]>a[i+1]:
ans += a[i] - a[i+1]
print(ans) | s286446351 | Accepted | 141 | 32,064 | 207 | n = int(input())
a = list(map(int, input().split()))
ans = 0
max_a = a[0]
for i in range(len(a)-1):
if max_a<a[i+1]:
max_a = a[i+1]
if max_a>a[i+1]:
ans += max_a - a[i+1]
print(ans) |
s950784354 | p03448 | u158778550 | 2,000 | 262,144 | Wrong Answer | 54 | 3,060 | 237 | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0
for a in range(A):
for b in range(B):
for c in range(C):
x = 500*a + 100*b + 50*c
if X == x:
counter += 1
print(counter) | s630946437 | Accepted | 56 | 3,060 | 243 | A = int(input())
B = int(input())
C = int(input())
X = int(input())
counter = 0
for a in range(A+1):
for b in range(B+1):
for c in range(C+1):
x = 500*a + 100*b + 50*c
if X == x:
counter += 1
print(counter) |
s718935747 | p03777 | u792078574 | 2,000 | 262,144 | Wrong Answer | 21 | 8,920 | 65 | Two deer, AtCoDeer and TopCoDeer, are playing a game called _Honest or Dishonest_. In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either `H` or `D`, and carries the following information: If a=`H`, AtCoDeer is honest; if a=`D`, AtCoDeer is dishonest. If b=`H`, AtCoDeer is saying that TopCoDeer is honest; if b=`D`, AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest. | a, b = input().split()
if a == b:
print('D')
else:
print('H') | s020010662 | Accepted | 27 | 9,020 | 65 | a, b = input().split()
if a == b:
print('H')
else:
print('D') |
s220036909 | p03549 | u038408819 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 95 | Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer). | N, M = map(int, input().split())
ms = 1900 * M + 100 * (N - M)
p = (1 / 2) ** M
print(ms*p**-1) | s339220118 | Accepted | 17 | 2,940 | 101 | N, M = map(int, input().split())
ms = 1900 * M + 100 * (N - M)
p = (1 / 2) ** M
print(int(ms*p**-1))
|
s986739500 | p03377 | u483945851 | 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())
if A<=X<=(A+B):
print("Yes")
else:
print("No") | s748050344 | Accepted | 17 | 2,940 | 83 | A, B, X=map(int,input().split())
if A<=X<=(A+B):
print("YES")
else:
print("NO") |
s571769628 | p02694 | u505181116 | 2,000 | 1,048,576 | Wrong Answer | 24 | 9,160 | 112 | 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())
i = 0
money = 100
while money < x:
money *= 1.01
money = int(money)
i += 1
print(i,money) | s735455111 | Accepted | 25 | 9,160 | 107 | x = int(input())
i = 0
money = 100
while money < x:
money *= 1.01
money = int(money)
i += 1
print(i)
|
s171758388 | p03555 | u155251346 | 2,000 | 262,144 | Wrong Answer | 31 | 8,960 | 181 | You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise. | word1 = input()
word2 = input()
up = list(word1)
down = list(word2)
if word1[0]==word2[2] and word1[1]== word2[1] and word1[2] == word2[0]:
print("Yes")
else:
print("No")
| s915803881 | Accepted | 26 | 9,008 | 220 |
A = input()
B = input()
if A[0]==B[2] and A[1]==B[1] and A[2]==B[0]:
print("YES")
else:
print("NO")
|
s041344848 | p03251 | u662449766 | 2,000 | 1,048,576 | Wrong Answer | 19 | 3,064 | 403 | Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out. | import sys
input = sys.stdin.readline
def main():
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
war = "No War"
for z in range(X, Y + 1):
if X <= z <= Y and all([i < z for i in x]) and all([i >= z for i in y]):
war = "War"
break
print(war)
if __name__ == "__main__":
main()
| s254675834 | Accepted | 19 | 3,064 | 392 | import sys
input = sys.stdin.readline
def main():
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
war = "War"
for z in range(X + 1, Y + 1):
if all([i < z for i in x]) and all([i >= z for i in y]):
war = "No War"
break
print(war)
if __name__ == "__main__":
main()
|
s340727282 | p03545 | u225183661 | 2,000 | 262,144 | Wrong Answer | 28 | 9,120 | 550 | 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. | num=input()
A=int(num[0])
B=int(num[1])
C=int(num[2])
D=int(num[3])
for i in range(2):
for j in range(2):
for k in range(2):
b=B*(-1)**i
c=C*(-1)**j
d=D*(-1)**k
ans=A+b+c+d
print(ans)
if ans==7:
sgn=[i,j,k]
for l in range(3):
if sgn[l]%2==0:
sgn[l]='+'
else:
sgn[l]='-'
print(str(A)+sgn[0]+str(B)+sgn[1]+str(C)+sgn[2]+str(D)+'=7') | s401919552 | Accepted | 29 | 9,132 | 534 | num=open(0).read()
A=int(num[0])
B=int(num[1])
C=int(num[2])
D=int(num[3])
for i in range(2):
for j in range(2):
for k in range(2):
b=B*(-1)**i
c=C*(-1)**j
d=D*(-1)**k
ans=A+b+c+d
if ans==7:
sgn=[i,j,k]
for l in range(3):
if sgn[l]%2==0:
sgn[l]='+'
else:
sgn[l]='-'
print(str(A)+sgn[0]+str(B)+sgn[1]+str(C)+sgn[2]+str(D)+'=7') |
s162084699 | p03067 | u420194640 | 2,000 | 1,048,576 | Wrong Answer | 325 | 21,400 | 130 | There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise. | import numpy as np
def test(A, B, C):
if (A<C) & (C<B):
print('Yes')
elif (B<C) & (C<A):
print('Yes')
else:
print('No')
| s352503962 | Accepted | 17 | 3,060 | 132 | A,B,C = input().split()
A=int(A)
B=int(B)
C=int(C)
AB=abs(A-B)
ACB=abs(A-C)+abs(C-B)
if AB==ACB:
print('Yes')
else:
print('No') |
s611813495 | p03450 | u368796742 | 2,000 | 262,144 | Wrong Answer | 2,109 | 91,012 | 684 | There are N people standing on the x-axis. Let the coordinate of Person i be x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i-th piece of information has the form (L_i, R_i, D_i). This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information. | from collections import deque
n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
a,b,c = map(int,input().split())
a -= 1
b -= 1
e[a].append([b,c])
e[b].append([a,-c])
print(e)
dis = [False]*n
def search(x):
q = deque([])
dis[x] = 0
q.append(x)
while q:
now = q.pop()
for nex,d in e[now]:
if dis[nex] == False:
dis[nex] = dis[now]+d
q.append(nex)
else:
if dis[nex] != dis[now]+d:
print("No")
exit()
for i in range(n):
if e[i] and dis[i] == False:
search(i)
print("Yes") | s371893764 | Accepted | 1,349 | 78,888 | 917 | def main():
from collections import deque
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
a,b,c = map(int,input().split())
a -= 1
b -= 1
e[a].append([b,c])
e[b].append([a,-c])
dis = [float("INF")]*n
def search(x):
q = deque([])
dis[x] = 0
q.append(x)
while q:
now = q.popleft()
for nex,d in e[now]:
if dis[nex] == float("INF"):
dis[nex] = dis[now]+d
q.append(nex)
else:
if dis[nex] != dis[now]+d:
print("No")
exit()
for i in range(n):
if e[i] and dis[i] == float("INF"):
search(i)
print("Yes")
if __name__ == "__main__":
main() |
s533944334 | p02928 | u150787983 | 2,000 | 1,048,576 | Wrong Answer | 871 | 3,188 | 459 | 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 = list(map(int, input().split()))
A = list(map(int, input().split()))
def cal(A, N):
cnt1 = 0
cnt2 = 0
for i in range(N):
for j in range(i+1,N):
if A[N-1-j] > A[N-1-i]:
cnt1 += 1
for i in range(N):
for j in range(N):
if A[N-1-i] < A[j]:
cnt2 += 1
return cnt1, cnt2
x, y = cal(A,N)
tmp = int(y*(K-1)/2)
ans = K*(tmp + x)
print(int(ans%(10**9+7))) | s211008185 | Accepted | 873 | 3,188 | 482 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
def cal(A, N):
cnt1 = 0
cnt2 = 0
for i in range(N):
for j in range(i+1,N):
if A[N-1-j] > A[N-1-i]:
cnt1 += 1
for i in range(N):
for j in range(N):
if A[N-1-i] < A[j]:
cnt2 += 1
return int(cnt1), int(cnt2)
x, y = cal(A,N)
R = int(1*10**9 +7)
tmp = K*(K-1)//2
ans = tmp*y + x*K
print(int(ans%R))
|
s515125164 | p03044 | u968404618 | 2,000 | 1,048,576 | Wrong Answer | 665 | 79,488 | 450 | We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem. | import sys
sys.setrecursionlimit(10 ** 7)
def dfs(v, p, c):
color[v] = c
for vi, wi in g[v]:
if vi == p: continue
if wi % 2: dfs(vi, v, 0)
else: dfs(vi, v, 1)
return color
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
g[u].append((v, w))
g[v].append((u, w))
color = [0 for _ in range(n)]
for i in dfs(0, -1, 0):
print(i) | s017750401 | Accepted | 717 | 79,492 | 454 | import sys
sys.setrecursionlimit(10 ** 7)
def dfs(v, p, c):
color[v] = c
for vi, wi in g[v]:
if vi == p: continue
if wi % 2: dfs(vi, v, 1-c)
else: dfs(vi, v, c)
return color
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
g[u].append((v, w))
g[v].append((u, w))
color = [0 for _ in range(n)]
for i in dfs(0, -1, 0):
print(i) |
s021061239 | p02846 | u780475861 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 398 | Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows **towards the east** : * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. * Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact. | T1, T2 = [int(i) for i in input().split()]
A1, A2 = [int(i) for i in input().split()]
B1, B2 = [int(i) for i in input().split()]
d1 = T1*(A1-B1)
d2 = T2*(A2-B2)
if d1 + d2 == 0:
print('infinity')
if (d1 > 0 and d2 > 0) or (d1 < 0 and d2 < 0):
print(0)
if d1 * (d2 - d1) > 0:
if d1 % (d2 - d1) != 0:
print(2 * d1 // (d2 - d1) + 1)
else:
print(2 * d1 // (d2 - d1)) | s272551309 | Accepted | 17 | 3,064 | 369 | T1, T2 = [int(i) for i in input().split()]
A1, A2 = [int(i) for i in input().split()]
B1, B2 = [int(i) for i in input().split()]
d1 = T1*(A1-B1)
d2 = T2*(B2-A2)
if d1 == d2:
print('infinity')
if d1 * (d2 - d1) < 0:
print(0)
if d1 * (d2 - d1) > 0:
if d1 % (d2 - d1) != 0:
print(d1 // (d2 - d1) * 2+ 1)
else:
print(d1 // (d2 - d1) * 2) |
s836088529 | p04029 | u951601135 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 56 | There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total? | N=int(input())
x=0
for i in range(N):
x+=i**2
print(x) | s024790188 | Accepted | 18 | 2,940 | 57 | N=int(input())
x=0
for i in range(N):
x+=(i+1)
print(x) |
s555269631 | p02613 | u533039576 | 2,000 | 1,048,576 | Wrong Answer | 152 | 9,180 | 225 | 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())
cnt = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(n):
si = input()
cnt[si] += 1
print(f'AC x {cnt["AC"]}')
print(f'WA x {cnt["WA"]}')
print(f'TLT x {cnt["TLE"]}')
print(f'RE x {cnt["RE"]}')
| s950577017 | Accepted | 147 | 9,180 | 225 | n = int(input())
cnt = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(n):
si = input()
cnt[si] += 1
print(f'AC x {cnt["AC"]}')
print(f'WA x {cnt["WA"]}')
print(f'TLE x {cnt["TLE"]}')
print(f'RE x {cnt["RE"]}')
|
s473043318 | p03251 | u780475861 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 189 | Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out. | n,m,x,y = map(int,input().split())
x1 = max(map(int,input().split())) + 1
y1 = min(map(int,input().split()))
if x1 <= y1 and x1 <= y and y1 > x:
print('No war')
else:
print('War') | s911715305 | Accepted | 17 | 2,940 | 189 | n,m,x,y = map(int,input().split())
x1 = max(map(int,input().split())) + 1
y1 = min(map(int,input().split()))
if x1 <= y1 and x1 <= y and y1 > x:
print('No War')
else:
print('War') |
s856669578 | p02831 | u670961163 | 2,000 | 1,048,576 | Wrong Answer | 27 | 9,136 | 136 | Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests. | def main():
a, b = map(int, input().split())
import math
print(math.gcd(a,b))
if __name__ == "__main__":
main()
| s428910792 | Accepted | 30 | 9,044 | 145 | def main():
a, b = map(int, input().split())
import math
print(int(a*b/math.gcd(a,b)))
if __name__ == "__main__":
main()
|
s433308337 | p02613 | u115877451 | 2,000 | 1,048,576 | Wrong Answer | 143 | 16,536 | 447 | 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. | import collections
a=int(input())
b=[input() for i in range(a)]
c=collections.Counter(b)
n,m=zip(*c.most_common())
n=list(n)
m=list(m)
result=[0]*4
for i in range(len(n)):
if n[i]=='AC':
result[0]=m[i]
if n[i]=='WA':
result[1]=m[i]
if n[i]=='TLE':
result[2]=m[i]
if n[i]=='RE':
result[3]=m[i]
print('AC ×',result[0])
print('WA ×',result[1])
print('TLE ×',result[2])
print('RE ×',result[3])
| s766730208 | Accepted | 142 | 16,520 | 444 | import collections
a=int(input())
b=[input() for i in range(a)]
c=collections.Counter(b)
n,m=zip(*c.most_common())
n=list(n)
m=list(m)
result=[0]*4
for i in range(len(n)):
if n[i]=='AC':
result[0]=m[i]
if n[i]=='WA':
result[1]=m[i]
if n[i]=='TLE':
result[2]=m[i]
if n[i]=='RE':
result[3]=m[i]
print('AC x',result[0])
print('WA x',result[1])
print('TLE x',result[2])
print('RE x',result[3])
|
s577205186 | p02613 | u225493896 | 2,000 | 1,048,576 | Wrong Answer | 146 | 9,204 | 290 | 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())
C = [ 0 for i in range(4) ]
s2num = {"AC":0, "WA":1, "TLE":2, "RE":3}
num2s = {0:"AC", 1:"WA", 2:"TLE", 3:"RE"}
# read
for i in range(N):
num = s2num[ input() ]
C[num] += 1
#print(num)
# print
for i in range(4):
print("{} × {}".format( num2s[i], C[i] ))
| s511158312 | Accepted | 151 | 9,200 | 289 | N = int(input())
C = [ 0 for i in range(4) ]
s2num = {"AC":0, "WA":1, "TLE":2, "RE":3}
num2s = {0:"AC", 1:"WA", 2:"TLE", 3:"RE"}
# read
for i in range(N):
num = s2num[ input() ]
C[num] += 1
#print(num)
# print
for i in range(4):
print("{} x {}".format( num2s[i], C[i] ))
|
s046994498 | p02795 | u595952233 | 2,000 | 1,048,576 | Wrong Answer | 24 | 9,092 | 86 | We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: * Choose one row, then paint all the squares in that row black. * Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations. | n, h, w = [int(input()) for i in range(3)]
k = max(h, w)
ans = (n+k-1)//k
print(ans) | s139698725 | Accepted | 30 | 9,096 | 83 | h, w, n= [int(input()) for i in range(3)]
k = max(h, w)
ans = (n+k-1)//k
print(ans) |
s006177676 | p02397 | u706023549 | 1,000 | 131,072 | Wrong Answer | 10 | 5,604 | 204 | Write a program which reads two integers x and y, and prints them in ascending order. | # coding:utf-8
n = list(map(int, input().split()))
print(n)
if n[0] > n[1]:
i = n[0]
n[0] = n[1]
n[1] = i
print (str(n[0]) + " " + str(n[1]))
else:
print (str(n[0]) + " " + str(n[1]))
| s201876173 | Accepted | 70 | 5,620 | 251 | n = []
i = 0
while i < 3000:
n = [int(i) for i in input().split()]
if n[0] == 0 and n[1] == 0:
break
m = 0
if n[0] > n[1]:
m = n[0]
n[0] = n[1]
n[1] = m
print(str(n[0]) + " " + str(n[1]))
i += 1
|
s497156850 | p03150 | u886747123 | 2,000 | 1,048,576 | Wrong Answer | 19 | 3,060 | 213 | A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string. | S = input()
if S == "keyence":
print("Yes")
exit()
for i in range(len(S)-1):
for j in range(i+1, len(S)):
if S[:i]+S[j:] == "keyence":
print("Yes")
exit()
print("No") | s061621093 | Accepted | 18 | 3,060 | 213 | S = input()
if S == "keyence":
print("YES")
exit()
for i in range(len(S)-1):
for j in range(i+1, len(S)):
if S[:i]+S[j:] == "keyence":
print("YES")
exit()
print("NO") |
s112872447 | p03644 | u045270305 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 138 | 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())
val = 1
res = 0
while val <= N:
val *= 2
print('val = ', val)
mod_2 = divmod(val, 2)
mod_2 = mod_2[0]
print(mod_2)
| s576767592 | Accepted | 17 | 2,940 | 108 | N = int(input())
val = 1
while val <= N:
val *= 2
mod_2 = divmod(val, 2)
mod_2 = mod_2[0]
print(mod_2) |
s500882142 | p03606 | u773686010 | 2,000 | 262,144 | Wrong Answer | 27 | 9,044 | 164 | Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now? |
N = int(input())
ans = 0
for i in range(N):
st,sp = map(int,input().split())
ans += abs(sp-st)
print(ans) | s151464428 | Accepted | 31 | 9,180 | 166 |
N = int(input())
ans = 0
for i in range(N):
st,sp = map(int,input().split())
ans += abs(sp-st+1)
print(ans) |
s423141495 | p02928 | u762420987 | 2,000 | 1,048,576 | Wrong Answer | 185 | 14,532 | 413 | 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. | import numpy as np
N,K = map(int,input().split())
Alist = np.array(list(map(int,input().split())))
counter = 0
for i,A in enumerate(Alist,0):
fir_tenti = np.count_nonzero(A>Alist[i:])
print(fir_tenti)
counter += (K*(fir_tenti*(K+1)))/2
second_tenti = np.count_nonzero(A>Alist)
print(second_tenti)
counter += second_tenti*K**2-(2*second_tenti*K)+second_tenti/2
print(int(counter%(10**9+7))) | s991005362 | Accepted | 945 | 3,188 | 564 | N, K = map(int, input().split())
Alist = list(map(int, input().split()))
mod = 10**9 + 7
def sum_n(n):
return (n * (n+1))//2
ans = 0
left = [0] * N
right = [0] * N
for i in range(N):
a = Alist[i]
in_left = True
for j in range(N):
if i == j:
in_left = False
continue
else:
if Alist[j] < a:
if in_left:
left[i] += 1
else:
right[i] += 1
ans += right[i] * sum_n(K)
ans += left[i] * sum_n(K-1)
ans %= mod
print(ans) |
s050338511 | p04043 | u692178082 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 238 | 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. |
example = ('5', '7', '5')
five = 0
seven = 0
ipt = []
s = input(">")
s = s.split()
for i in s:
if i == '5':
five += 1
elif i == '7':
seven += 1
if five == 2 and seven == 1:
print("YES")
else:
print("NO") | s921057498 | Accepted | 17 | 3,060 | 235 |
example = ('5', '7', '5')
five = 0
seven = 0
ipt = []
s = input()
s = s.split()
for i in s:
if i == '5':
five += 1
elif i == '7':
seven += 1
if five == 2 and seven == 1:
print("YES")
else:
print("NO") |
s250255447 | p02843 | u134520518 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 249 | AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.) | x = int(input())
nokori = x%100
max_n = x//100
print(nokori//5 + nokori%5//4 + nokori%5%4//3 + nokori%5%4%3//2 + nokori%5%4%3%2)
if max_n < nokori//5 + nokori%5//4 + nokori%5%4//3 + nokori%5%4%3//2 + nokori%5%4%3%2:
print(0)
else:
print(1)
| s674054461 | Accepted | 17 | 2,940 | 168 | x = int(input())
nokori = x%100
max_n = x//100
if max_n < nokori//5 + nokori%5//4 + nokori%5%4//3 + nokori%5%4%3//2 + nokori%5%4%3%2:
print(0)
else:
print(1)
|
s101784445 | p03447 | u917558625 | 2,000 | 262,144 | Wrong Answer | 29 | 9,044 | 57 | You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping? | X=int(input())
A=int(input())
B=int(input())
print(X-A-B) | s403193399 | Accepted | 28 | 9,100 | 61 | X=int(input())
A=int(input())
B=int(input())
print((X-A-B)%B) |
s786919342 | p02396 | u229478139 | 1,000 | 131,072 | Wrong Answer | 20 | 5,504 | 64 | In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem. | def testcase(x):
print("Case {}: {}".format(str(x),str(x)))
| s849089701 | Accepted | 140 | 5,568 | 116 | c = 0
while True:
n = input()
if n == '0':
break
c += 1
print('Case ' + str(c) + ': ' + n)
|
s969713677 | p03338 | u548545174 | 2,000 | 1,048,576 | Wrong Answer | 18 | 3,060 | 220 | You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position. | N = int(input())
S = input()
ans = 0
for sakaime in range(N):
left = S[:sakaime]
right = S[sakaime:]
cnt = 0
for c in left:
if c in right:
cnt += 1
ans = max(ans, cnt)
print(ans) | s406513882 | Accepted | 25 | 3,772 | 294 | N = int(input())
S = input()
import string
abcs = string.ascii_lowercase
ans = 0
for sakaime in range(N):
cnt = 0
left = S[:sakaime]
right = S[sakaime:]
for alpha in abcs:
if alpha in left and alpha in right:
cnt += 1
ans = max(ans, cnt)
print(ans) |
s549995729 | p03409 | u934788990 | 2,000 | 262,144 | Wrong Answer | 25 | 3,064 | 512 | On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs. | n = int(input())
AB = []
for i in range(n):
a,b=map(int,input().split())
AB.append([a,b])
CD = []
for i in range(n):
c,d=map(int,input().split())
CD.append([c,d])
coutAB = []
coutCD = []
count = 0
for i in range(n):
for j in range(n):
if AB[i][0] <= CD[j][0] and AB[i][1] <= CD[j][1]:
if AB[i] not in coutAB and CD[j] not in coutCD:
count+=1
coutAB.append(AB[i])
coutCD.append(CD[j])
print(coutAB)
print(coutCD)
print(count) | s526477987 | Accepted | 18 | 3,064 | 293 | N = int(input())
x = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: -x[1])
y = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for c, d in y:
for a, b in x:
if a < c and b < d:
x.remove([a, b])
cnt += 1
break
print(cnt)
|
s327506620 | p03720 | u957872856 | 2,000 | 262,144 | Wrong Answer | 26 | 3,444 | 235 | There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? | N, M = map(int, input().split())
dp = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
a, b = map(int, input().split())
dp[a-1][b-1] += 1
dp[b-1][a-1] += 1
print(dp)
for i in range(N):
print(sum(dp[i])) | s725858129 | Accepted | 18 | 3,060 | 140 | n, m = map(int,input().split())
l = []
for i in range(m):
l += list(map(int, input().split()))
for i in range(1, n+1):
print(l.count(i)) |
s160531580 | p03943 | u367130284 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 74 | Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students. | a=map(int,input().split())
print("Yes") if sum(a)//2 in a else print("No") | s455000586 | Accepted | 18 | 2,940 | 85 | a=list(map(int,input().split()))
print("Yes") if sum(a)/2 in list(a) else print("No") |
s077417244 | p03251 | u874741582 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,060 | 190 | Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out. | n,m,x,y=map(int,input().split())
X= list(map(int,input().split()))
Y= list(map(int,input().split()))
maxx = max(X)
miny = min(Y)
if maxx +1 < miny:
print("No War")
else:
print("War") | s911364434 | Accepted | 17 | 3,064 | 280 | n,m,x,y=map(int,input().split())
X= list(map(int,input().split()))
Y= list(map(int,input().split()))
maxx = max(X)
miny = min(Y)
frag = 0
for i in range(x+1,y+1):
if i >maxx and i <=miny :
frag = 1
break
if frag == 1:
print("No War")
else:
print("War") |
s422516451 | p03470 | u747005359 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 50 | An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? | input()
print(len(set(map(int, input().split())))) | s331431895 | Accepted | 17 | 2,940 | 67 | N = int(input())
d = [input() for i in range(N)]
print(len(set(d))) |
s417811338 | p02927 | u615820360 | 2,000 | 1,048,576 | Wrong Answer | 25 | 3,060 | 288 | 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? | a,b=map(int,input().split())
x=0
for i in range(1,a+1):
for j in range(11,b):
lst = []
while j > 0:
lst.append(j%10)
j //= 10
lst.reverse()
if lst[0] >= 2 and lst[1] >= 2:
if i == lst[0]*lst[1]:
print(lst[0],lst[1])
x+=1
print(x)
| s670885486 | Accepted | 24 | 3,060 | 261 | a,b=map(int,input().split())
x=0
for i in range(1,a+1):
for j in range(11,b+1):
lst = []
while j > 0:
lst.append(j%10)
j //= 10
lst.reverse()
if lst[0] >= 2 and lst[1] >= 2:
if i == lst[0]*lst[1]:
x+=1
print(x)
|
s399094839 | p02833 | u387774811 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,060 | 108 | For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N). | N= int(input())
if N%2==1:
print(0)
else:
N/=2
a=0
i=0
while (5**i)<=N:
i+=1
a+=N//(5**i)
print(a) | s001168027 | Accepted | 17 | 2,940 | 114 | N= int(input())
if N%2==1:
print(0)
else:
a=0
i=0
while (5**i)*2<=N:
i+=1
b=(5**i)*2
a+=(N//b)
print(a) |
s863724498 | p02280 | u153665391 | 1,000 | 131,072 | Wrong Answer | 20 | 5,616 | 1,389 | A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree _T_ and prints the following information for each node _u_ of _T_ : * node ID of _u_ * parent of _u_ * sibling of _u_ * the number of children of _u_ * depth of _u_ * height of _u_ * node type (root, internal node or leaf) If two nodes have the same parent, they are **siblings**. Here, if _u_ and _v_ have the same parent, we say _u_ is a sibling of _v_ (vice versa). The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1. | N = int(input())
binary_tree = [{"parent": -1, "sibling": -1} for _ in range(N)]
for _ in range(N):
node_input = input()
id, left, right = map(int, node_input.split())
binary_tree[id]["left"] = left
binary_tree[id]["right"] = right
degree = 0
if left != -1:
degree += 1
binary_tree[left]["parent"] = id
binary_tree[left]["sibling"] = right
if right != -1:
degree += 1
binary_tree[right]["parent"] = id
binary_tree[right]["sibling"] = left
binary_tree[id]["degree"] = degree
def measure_depth_and_height(id, depth):
H[id] = max(H[id], depth)
parent_id = binary_tree[id]["parent"]
if parent_id == -1:
return depth
return measure_depth_and_height(parent_id, depth+1)
D = [0 for i in range(N)]
H = [0 for i in range(N)]
for id in range(N):
depth = measure_depth_and_height(id, 0)
D[id] = depth
def get_type(node):
if node["degree"] == 0:
return "leaf"
if node["parent"] == -1:
return "parent"
return "internal node"
for id in range(N):
node = binary_tree[id]
parent_id = node["parent"]
sibling_id = node["sibling"]
degree = node["degree"]
node_type = get_type(node)
print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height= {}, {}".format(id, parent_id, sibling_id, degree, D[id], H[id], node_type))
| s177008299 | Accepted | 20 | 5,624 | 1,947 | N = int(input())
class Node():
def __init__(self, parent = -1, left = -1, right = -1):
self.parent = parent
self.left = left
self.right = right
binary_tree = [Node() for _ in range(N)]
for _ in range(N):
node_input = input()
id, left, right = map(int, node_input.split())
binary_tree[id].left = left
binary_tree[id].right = right
if left != -1:
binary_tree[left].parent = id
if right != -1:
binary_tree[right].parent = id
def set_depth(id, depth):
if id == -1:
return
D[id] = depth
set_depth(binary_tree[id].left, depth+1)
set_depth(binary_tree[id].right, depth+1)
def set_height(id):
h1, h2 = 0, 0
if binary_tree[id].left != -1:
h1 = set_height(binary_tree[id].left) + 1
if binary_tree[id].right != -1:
h2 = set_height(binary_tree[id].right) + 1
H[id] = max(h1, h2)
return H[id]
D = [0 for i in range(N)]
H = [0 for i in range(N)]
for id in range(N):
if binary_tree[id].parent == -1:
set_depth(id, 0)
set_height(id)
break
def get_sibling(id):
parent_id = node.parent
if parent_id == -1:
return -1
if binary_tree[parent_id].left != id:
return binary_tree[parent_id].left
else:
return binary_tree[parent_id].right
def get_degree(node):
degree = 0
if node.left != -1:
degree += 1
if node.right != -1:
degree += 1
return degree
def get_type(node, dgree):
if node.parent == -1:
return "root"
if degree == 0:
return "leaf"
return "internal node"
for id in range(N):
node = binary_tree[id]
parent_id = node.parent
sibling_id = get_sibling(id)
degree = get_degree(node)
node_type = get_type(node, degree)
print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(id, parent_id, sibling_id, degree, D[id], H[id], node_type))
|
s295169836 | p03827 | u396266329 | 2,000 | 262,144 | Wrong Answer | 17 | 3,060 | 148 | You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation). | N = int(input())
S = input()
num = [0]
cu = 0
for i in S:
if i == "I":
cu += 1
num.append(cu)
else:
cu -= 1
num.sort()
print(num[0]) | s481663886 | Accepted | 17 | 3,060 | 149 | N = int(input())
S = input()
num = [0]
cu = 0
for i in S:
if i == "I":
cu += 1
num.append(cu)
else:
cu -= 1
num.sort()
print(num[-1]) |
s665421208 | p03712 | u492447501 | 2,000 | 262,144 | Wrong Answer | 20 | 3,700 | 234 | You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1. | H, W = map(int, input().split())
pic = ["#"]*(W+2)
pic_list = []
pic_list.append(pic)
for i in range(H):
pic = "#"+input()+"#"
pic_list.append(pic)
pic = ["#"]*(W+2)
pic_list.append(pic)
for i in pic_list:
print(*i)
| s562142926 | Accepted | 21 | 4,596 | 421 | H,W = map(int, input().split())
H_output = H+2
W_output = W+2
S = []
for _ in range(H):
s = list(input())
S.append(s)
count = 0
for i in range(H_output):
if i==0 or i==H+1:
row = ["#"]*(W+2)
print(*row,sep="")
continue
else:
row_left = ["#"]*1
row_right = ["#"]*1
row = row_left + S[count] + row_right
print(*row,sep="")
count = count + 1 |
s321890465 | p03449 | u062459048 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 224 | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? | n = int(input())
a1list = list(map(int, input().split()))
a2list = list(map(int, input().split()))
countlist = []
for i in range(n):
p = sum(a1list[0:i]) + sum(a2list[i:n-1])
countlist.append(p)
print(max(countlist)) | s505627405 | Accepted | 17 | 3,060 | 225 | n = int(input())
a1list = list(map(int, input().split()))
a2list = list(map(int, input().split()))
countlist = []
for i in range(n):
p = sum(a1list[0:i+1]) + sum(a2list[i:n])
countlist.append(p)
print(max(countlist))
|
s119041529 | p03693 | u102242691 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 134 | AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4? |
r,g,b = input().split()
r = int(r)
g = int(g)
b = int(b)
if (r * 100 + g * 10 * b) % 2 == 0:
print("Yes")
else:
print("No")
| s876044232 | Accepted | 18 | 2,940 | 147 | r,g,b = input().split()
r = int(r)
g = int(g)
b = int(b)
number = r * 100 + g * 10 + b
if number % 4 == 0:
print("YES")
else:
print("NO") |
s705507962 | p03150 | u288948615 | 2,000 | 1,048,576 | Wrong Answer | 20 | 3,060 | 104 | A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string. | S = input()
if S.startswith('keyence') or S.endswith('keyence'):
print('YES')
else:
print('NO') | s482306634 | Accepted | 18 | 3,060 | 256 | S = input()
KEYENCE = 'keyence'
patterns = []
for i in range(len(KEYENCE)):
patterns.append((KEYENCE[:i:], KEYENCE[i::]))
for stt, end in patterns:
if S.startswith(stt) and S.endswith(end):
print('YES')
break
else:
print('NO') |
s168542958 | p03624 | u923662841 | 2,000 | 262,144 | Wrong Answer | 26 | 3,832 | 147 | You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. | import string
import sys
a = string.ascii_lowercase
S =sys.stdin.readline()
a = sorted(set(a)^set(S))
if a:
print(a[0])
else:
print("None") | s681589753 | Accepted | 26 | 3,832 | 123 | import string
a = string.ascii_lowercase
S =input()
a = sorted(set(a)^set(S))
if a:
print(a[0])
else:
print("None") |
s899477287 | p03729 | u444722572 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 113 | You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`. | A,B,C=input().split()
a,b=len(A),len(B)
if(A[a-1]==B[0] and B[b-1]==C[0]):
print("Yes")
else:
print("No") | s199681540 | Accepted | 19 | 3,060 | 113 | A,B,C=input().split()
a,b=len(A),len(B)
if(A[a-1]==B[0] and B[b-1]==C[0]):
print("YES")
else:
print("NO") |
s489564777 | p03379 | u179169725 | 2,000 | 262,144 | Wrong Answer | 239 | 26,772 | 140 | 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()))
s = N // 2
for _ in range(s):
print(X[s - 1])
for _ in range(s, N):
print(X[s]) | s203878248 | Accepted | 339 | 26,180 | 231 | N = int(input())
X = list(map(int, input().split()))
X_sort = X.copy()
X_sort.sort()
s = N // 2
median = (X_sort[s - 1] + X_sort[s]) / 2
for x in X:
if x < median:
print(X_sort[s])
else:
print(X_sort[s-1])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.