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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s726245614
|
p03719
|
u277641173
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 83
|
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B.
|
a,b,c=map(int,input().split())
if a<=b and b<=c:
print("Yes")
else:
print("No")
|
s147498573
|
Accepted
| 17
| 2,940
| 59
|
a,b,c=map(int,input().split())
print(["No","Yes"][a<=c<=b])
|
s770378919
|
p03167
|
u823885866
| 2,000
| 1,048,576
|
Wrong Answer
| 1,746
| 166,256
| 599
|
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}. If a_{i, j} is `.`, Square (i, j) is an empty square; if a_{i, j} is `#`, Square (i, j) is a wall square. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W). As the answer can be extremely large, find the count modulo 10^9 + 7.
|
import sys
import math
import itertools
import collections
import numpy as np
rl = sys.stdin.readline
h, w = map(int, rl().split())
li = []
dh = [0, -1]
dw = [-1, 0]
for _ in range(h):
lis = []
for v in rl().rstrip():
lis.append(1 if v == '.' else 0)
li.append(lis)
if li[-1][-1]:
li[-1][-1] = 0
for i in range(1, h):
for j in range(1, w):
if li[i][j] == 0:
continue
a = 0
for k in range(2):
nh = dh[k] + i
nw = dw[k] + j
a += li[nh][nw]
li[i][j] = a
print((li[-1][-1]) % ((10**9) + 7))
|
s820709475
|
Accepted
| 1,913
| 166,392
| 620
|
import sys
import math
import itertools
import collections
import numpy as np
rl = sys.stdin.readline
h, w = map(int, rl().split())
li = []
dh = [0, -1]
dw = [-1, 0]
dp = [[0] * w for _ in range(h)]
dp[0][0] = 1
for _ in range(h):
li.append(rl().rstrip())
for i in range(h):
for j in range(w):
if li[i][j] == '#':
continue
a = 0
for k in range(2):
nh = i + dh[k]
nw = j + dw[k]
if nh < 0 or nw < 0:
continue
a += dp[nh][nw]
if dp[i][j] == 0:
dp[i][j] = a
print((dp[-1][-1]) % (10**9 + 7))
|
s698400887
|
p03456
|
u729923016
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 101
|
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, b = input().split()
num = int(a + b)
if (num**0.5)%1 is not 0:
print("No")
else:
print("Yes")
|
s987642583
|
Accepted
| 18
| 3,188
| 97
|
a, b = input().split()
num = int(a + b)
if (num**0.5)%1 != 0:
print("No")
else:
print("Yes")
|
s950820307
|
p03597
|
u846150137
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 42
|
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
|
n=int(input())
a=int(input())
print(n*2-a)
|
s794458666
|
Accepted
| 17
| 2,940
| 43
|
n=int(input())
a=int(input())
print(n**2-a)
|
s786820819
|
p03555
|
u121732701
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 142
|
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.
|
C1 = input()
C2 = input()
C1a = C1[2]+C1[1]+C1[0]
C2a = C2[2]+C2[1]+C2[0]
if C1 == C2a and C2 == C1a:
print("Yes")
else:
print("No")
|
s560914263
|
Accepted
| 18
| 2,940
| 142
|
C1 = input()
C2 = input()
C1a = C1[2]+C1[1]+C1[0]
C2a = C2[2]+C2[1]+C2[0]
if C1 == C2a and C2 == C1a:
print("YES")
else:
print("NO")
|
s396862990
|
p03434
|
u975966195
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 106
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
n = int(input())
a = sorted(list(map(int, input().split())))
ans = sum(a[::2]) - sum(a[1::2])
print(ans)
|
s987325700
|
Accepted
| 17
| 2,940
| 119
|
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = sum(a[::2]) - sum(a[1::2])
print(ans)
|
s964703244
|
p03852
|
u280913254
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 190
|
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
|
import fileinput
def algorithm(input_lines):
c = input_lines[0]
return c in "aiueo"
def run():
out = algorithm([l.strip() for l in fileinput.input()])
print(out)
run()
|
s402981168
|
Accepted
| 18
| 3,060
| 218
|
import fileinput
def algorithm(input_lines):
c = input_lines[0]
return "vowel" if c in "aiueo" else "consonant"
def run():
out = algorithm([l.strip() for l in fileinput.input()])
print(out)
run()
|
s463366096
|
p02669
|
u726872801
| 2,000
| 1,048,576
|
Wrong Answer
| 670
| 11,568
| 1,177
|
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the number by 1, paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N? **You have to solve T testcases.**
|
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
T = int(input())
for _ in range(T):
N, A, B, C, D = map(int, input().split())
memo = {}
def f(n):
if n == 0:
return 0
if n == 1:
return D
if n in memo.keys():
return memo[n]
ret = 1 << 100
ret = min(ret, f(n // 2) + (n - n // 2 * 2) * D + A, f(n // 2) + (n - n // 2) * D)
ret = min(ret, f(n // 3) + (n - n // 3 * 3) * D + B, f(n // 3) + (n - n // 3) * D)
ret = min(ret, f(n // 5) + (n - n // 5 * 5) * D + C, f(n // 5) + (n - n // 5) * D)
ret = min(ret, f(n // 2) + ((n + 1) // 2 * 2 - n) * D + A, f((n + 1) // 2) + (n - (n + 1) // 2) * D)
ret = min(ret, f(n // 3) + ((n + 2) // 3 * 3 - n) * D + B, f((n + 2) // 3) + (n - (n + 2) // 3) * D)
ret = min(ret, f(n // 5) + ((n + 4) // 5 * 5 - n) * D + C, f((n + 4) // 5) + (n - (n + 4) // 5) * D)
memo[n] = ret
return ret
print(f(N))
|
s822586274
|
Accepted
| 673
| 11,732
| 1,195
|
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
T = int(input())
for _ in range(T):
N, A, B, C, D = map(int, input().split())
memo = {}
def f(n):
if n == 0:
return 0
if n == 1:
return D
if n in memo.keys():
return memo[n]
ret = 1 << 100
ret = min(ret, f(n // 2) + (n - n // 2 * 2) * D + A, f(n // 2) + (n - n // 2) * D)
ret = min(ret, f(n // 3) + (n - n // 3 * 3) * D + B, f(n // 3) + (n - n // 3) * D)
ret = min(ret, f(n // 5) + (n - n // 5 * 5) * D + C, f(n // 5) + (n - n // 5) * D)
ret = min(ret, f((n + 1) // 2) + ((n + 1) // 2 * 2 - n) * D + A, f((n + 1) // 2) + (n - (n + 1) // 2) * D)
ret = min(ret, f((n + 2) // 3) + ((n + 2) // 3 * 3 - n) * D + B, f((n + 2) // 3) + (n - (n + 2) // 3) * D)
ret = min(ret, f((n + 4) // 5) + ((n + 4) // 5 * 5 - n) * D + C, f((n + 4) // 5) + (n - (n + 4) // 5) * D)
memo[n] = ret
return ret
print(f(N))
|
s986519265
|
p02742
|
u007627455
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 244
|
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
# coding: utf-8
H, W = map(int, input().split())
h_even= H//2
h_odd= H-h_even
w_even= W//2
w_odd= W-w_even
# if H%2 == 1:
# r1=r+1
# print(r*W//2+r1*(W-W//2))
# else:
# print(r*W//2+r*(W-W//2))
print(h_odd*w_odd+h_even*w_even-1)
|
s739223464
|
Accepted
| 17
| 2,940
| 450
|
# coding: utf-8
H, W = map(int, input().split())
if H ==1 or W == 1:
print(1)
else:
h_even= H//2
h_odd= H-h_even
w_even= W//2
w_odd= W-w_even
# if H%2 == 1:
# r1=r+1
# print(r*W//2+r1*(W-W//2))
# else:
# print(r*W//2+r*(W-W//2))
# if H%2==1 or W%2==1:
# print(h_odd*w_odd+h_even*w_even-1)
# else:
# print(h_odd*w_odd+h_even*w_even)
print(h_odd*w_odd+h_even*w_even)
|
s524377758
|
p02242
|
u197615397
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,688
| 1,420
|
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.
|
import sys
def dijkstra(v_count: int, edges: list, start: int,
*, adj_matrix: bool = False, unreachable=float("inf")) -> list:
from heapq import heappush, heappop
vertices = [unreachable] * v_count
vertices[start] = 0
q, rem = [(0, start)], v_count - 1
while q and rem:
cost, v = heappop(q)
if vertices[v] < cost:
continue
rem -= 1
dests = (filter(lambda x: x[1] != unreachable, enumerate(edges[v]))
if adj_matrix else edges[v])
print(list(dests))
for dest, _cost in dests:
newcost = cost + _cost
if vertices[dest] > newcost:
vertices[dest] = newcost
heappush(q, (newcost, dest))
return vertices
n = int(input())
edges = [[] for _ in [0]*n]
for a in (tuple(map(int, l.split())) for l in sys.stdin):
edges[a[0]] = tuple(zip(a[2::2], a[3::2]))
vertices = dijkstra(n, edges, 0)
for i, n in enumerate(vertices):
print(i, n)
|
s338873314
|
Accepted
| 20
| 5,988
| 1,479
|
import sys
def dijkstra(v_count: int, edges: list, start: int,
*, adj_matrix: bool = False, unreachable=float("inf")) -> list:
from heapq import heappush, heappop
vertices = [unreachable] * v_count
vertices[start] = 0
q, rem = [(0, start)], v_count - 1
while q and rem:
cost, v = heappop(q)
if vertices[v] < cost:
continue
rem -= 1
dests = (filter(lambda x: x[1] != unreachable, enumerate(edges[v]))
if adj_matrix else edges[v])
for dest, _cost in dests:
newcost = cost + _cost
if vertices[dest] > newcost:
vertices[dest] = newcost
heappush(q, (newcost, dest))
return vertices
n = int(input())
inf = float("inf")
edges = [[inf]*n for _ in [0]*n]
for a in (tuple(map(int, l.split())) for l in sys.stdin):
_from = a[0]
for to, cost in zip(a[2::2], a[3::2]):
edges[_from][to] = cost
vertices = dijkstra(n, edges, 0, adj_matrix=True)
for i, n in enumerate(vertices):
print(i, n)
|
s197556903
|
p03360
|
u390958150
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 71
|
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
|
A = [int(i) for i in input().split()]
n = int(input())
print(max(A)**n)
|
s218537769
|
Accepted
| 18
| 2,940
| 99
|
A = sorted([int(i) for i in input().split()])
n = int(input())
m = A.pop()
print(sum([m*2**n]+A))
|
s124672689
|
p03610
|
u628262476
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,192
| 20
|
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
|
print(input()[1::2])
|
s090742389
|
Accepted
| 17
| 3,192
| 19
|
print(input()[::2])
|
s117429383
|
p03486
|
u766407523
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 495
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
s = input()
t = input()
sample = 'abcdefghijklmnopqrstuvwxyz'
end =0
for i in range(min(len(s), len(t))):
#print('count')
for j in range(26):
if s[i] == sample[j] and t[-i] != sample[j]:
print('Yes')
end = 1
break
elif s[i] != sample[j] and t[-i] == sample[j]:
print('No')
end = 1
break
if end == 1:
break
else:
if len(s)<len(t):
print('Yes')
else:
print('No')
|
s623381989
|
Accepted
| 18
| 3,064
| 846
|
s = input()
t = input()
slist = []
tlist = []
for i in s:
slist.append(i)
for i in t:
tlist.append(i)
sortedslist = sorted(slist)
sortedtlist = sorted(tlist)
sample ='abcdefghijklmnopqrstuvwxyz'
def checktoend(sa, ta):
n = min(len(sa), len(ta))
end = 0
for i in range(n):
for x in sample:
if sa[i]==x and ta[-(i+1)]==x:
break
elif sa[i]==x and ta[-(i+1)]!=x:
print('Yes')
end = 1#end
break
elif sa[i]!=x and ta[-(i+1)]==x:
print('No')
end = 1
break
if end == 1:
break
else:
if len(sa)<len(ta):
print('Yes')
else:
print('No')
checktoend(sortedslist, sortedtlist)
|
s423694724
|
p03447
|
u636311816
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 62
|
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-(x-a)//b)
|
s746834187
|
Accepted
| 17
| 2,940
| 68
|
x=int(input())
a=int(input())
b=int(input())
print(x-a-b*((x-a)//b))
|
s944422986
|
p03379
|
u964299793
| 2,000
| 262,144
|
Wrong Answer
| 703
| 53,552
| 302
|
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=[[int(x),i] for i,x in enumerate(input().split())]
ans=[0]*n
x.sort(key=lambda x: x[0])
print(x)
for i,val in enumerate(x):
#n-1 is odd pos=(n-1+1)//2
pos=(n-1)//2
if i>pos:
ans[val[1]]=x[pos][0]
else:
ans[val[1]]=x[pos+1][0]
for i in ans:
print(i)
|
s657045129
|
Accepted
| 587
| 51,392
| 303
|
n=int(input())
x=[[int(x),i] for i,x in enumerate(input().split())]
ans=[0]*n
x.sort(key=lambda x: x[0])
#print(x)
for i,val in enumerate(x):
#n-1 is odd pos=(n-1+1)//2
pos=(n-1)//2
if i>pos:
ans[val[1]]=x[pos][0]
else:
ans[val[1]]=x[pos+1][0]
for i in ans:
print(i)
|
s772644103
|
p03643
|
u370413678
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 49
|
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.
|
x=int(input())
n=str(bin(x))
print(2**(len(n)-3))
|
s169064668
|
Accepted
| 17
| 2,940
| 31
|
x=input()
print("ABC"+str(x))
|
s967632487
|
p03251
|
u614181788
| 2,000
| 1,048,576
|
Wrong Answer
| 28
| 9,172
| 221
|
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()))
s = 1
for i in range(-100,101):
if X < i <= Y and max(x) < i <= min(y):
s = 0
print(["No war","War"][s])
|
s699751703
|
Accepted
| 30
| 9,172
| 222
|
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
s = 1
for i in range(-100,101):
if X < i <= Y and max(x) < i <= min(y):
s = 0
print(["No War","War"][s])
|
s306128753
|
p03636
|
u908349502
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 41
|
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
|
s = input()
print(s[0]+str(len(s))+s[-1])
|
s014035548
|
Accepted
| 17
| 2,940
| 43
|
s = input()
print(s[0]+str(len(s)-2)+s[-1])
|
s936279680
|
p03943
|
u149991748
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 109
|
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,b,c = map(int,input().split())
if a+b == c or b+c == a or c+a == b:
print('YES')
else:
print('NO')
|
s130976553
|
Accepted
| 19
| 3,064
| 109
|
a,b,c = map(int,input().split())
if a+b == c or b+c == a or c+a == b:
print('Yes')
else:
print('No')
|
s241569519
|
p03455
|
u527993431
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 80
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
A,B=map(int,input().split())
if (A*B)%2==1:
print("Odd")
else:
print("Evev")
|
s550952301
|
Accepted
| 17
| 2,940
| 80
|
A,B=map(int,input().split())
if (A*B)%2==1:
print("Odd")
else:
print("Even")
|
s181717577
|
p03456
|
u691072882
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 125
|
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.
|
import math
a,b = input().split()
r = int(a + b)
p = int(math.sqrt(r))
if r == p*p:
print("YES")
else:
print("NO")
|
s288214566
|
Accepted
| 17
| 2,940
| 155
|
a,b = input().split()
r = int(a + b)
ma = 0
for i in range(1,1000):
if r == i*i:
ma = 1
if ma == 1:
print("Yes")
else:
print("No")
|
s099410587
|
p03699
|
u153902122
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 155
|
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
|
N=int(input())
ans=0
tmp=0
for i in range(N):
ni = int(input())
if ni%10==0:
tmp+=ni
else:
ans+=ni+tmp
tmp=0
print(ans)
|
s274235421
|
Accepted
| 17
| 3,060
| 209
|
N = int(input())
s = [int(input()) for _ in range(N)]
s.sort()
ans = sum(s)
if ans % 10 != 0:
print(ans)
exit()
for i in range(N):
if s[i] % 10 != 0:
print(ans-s[i])
exit()
print(0)
|
s136851759
|
p03997
|
u806392288
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 68
|
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)
|
s720857188
|
Accepted
| 17
| 2,940
| 62
|
a=int(input())
b=int(input())
h=int(input())
print((a+b)*h//2)
|
s520847859
|
p03472
|
u911575040
| 2,000
| 262,144
|
Wrong Answer
| 443
| 12,064
| 414
|
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
|
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
a,b=map(int,input().split())
A.append(a)
B.append(b)
amax=max(A)
for i in range(n):
if amax<=B[i]:
C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
i=0
for i in range(len(C)):
if ans<h:
ans+=C[i]
else:
break
cnt+=1
if ans<h:
cnt+=(h-ans)//amax
print(cnt)
|
s316351883
|
Accepted
| 440
| 12,064
| 502
|
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
a,b=map(int,input().split())
A.append(a)
B.append(b)
amax=max(A)
for i in range(n):
if amax<=B[i]:
C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
i=0
for i in range(len(C)):
if ans<h:
ans+=C[i]
else:
break
cnt+=1
if ans<h:
if ((h-ans)//amax)*amax>=h-ans:
cnt+=(h-ans)//amax
else:
cnt+=(h-ans)//amax+1
print(cnt)
|
s770577188
|
p02612
|
u738876064
| 2,000
| 1,048,576
|
Wrong Answer
| 2,205
| 9,080
| 58
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
r = N
while r <= 1000:
r-1000
print(r)
|
s074956415
|
Accepted
| 27
| 9,156
| 97
|
N = int(input())
r = N
while r >= 1000:
r = r-1000
if r == 0:
print(0)
else:
print(1000-r)
|
s767043514
|
p02406
|
u613278035
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,592
| 120
|
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
|
H = int(input())
str =""
for i in range(1,H+1):
if i%3==0 or "%d"%(i)in "3":
str+="%d "%(i)
print(str[0:-1])
|
s333855585
|
Accepted
| 30
| 5,636
| 237
|
def check(st):
for d in range(len(st)):
if st[d]=="3":
return True
return False
num = int(input())
str=""
for d in range(3,num+1):
s = "%d"%(d)
if d%3==0 or check(s):
str+=" %d"%(d)
print(str)
|
s099716454
|
p02277
|
u196653484
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,600
| 1,102
|
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Quicksort(A, p, r) 1 if p < r 2 then q = Partition(A, p, r) 3 run Quicksort(A, p, q-1) 4 run Quicksort(A, q+1, r) Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers. Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
|
class Num:
a=0
b=0
origin=0
def partition(A, p, r):
x=A[r].b
i=p-1
for j in range(p,r):
if A[j].b <= x:
i += 1
A[i].b,A[j].b = A[j].b,A[i].b
A[i].a,A[j].a = A[j].a,A[i].a
A[i+1].b,A[r].b = A[r].b,A[i+1].b
A[i+1].a,A[r].a = A[r].a,A[i+1].a
return i+1
def quick_sort(A , p, r):
if p < r:
q = partition(A,p,r)
quick_sort(A, p, q-1)
quick_sort(A, q+1, r)
def isStable(A):
n=len(A)
for i in range(n-1):
if A[i].b == A[i+1].b and A[i].origin < A[i+1].origin:
return False
return True
if __name__ == "__main__":
n=int(input())
A=[]
for i in range(n):
num =Num()
a=input().split()
num.a = a[0]
num.b = int(a[1])
num.origin=i
A.append(num)
quick_sort(A,0,n-1)
for i in A:
print("a={},b={},origin={}".format(i.a,i.b,i.origin))
if isStable(A):
print("Stable")
else:
print("Not stable")
for i in A:
print(i.a,end=" ")
print(i.b)
|
s030448708
|
Accepted
| 1,950
| 29,924
| 1,158
|
class Num:
a=0
b=0
origin=0
def partition(A, p, r):
x=A[r].b
i=p-1
for j in range(p,r):
if A[j].b <= x:
i += 1
A[i].b,A[j].b = A[j].b,A[i].b
A[i].a,A[j].a = A[j].a,A[i].a
A[i].origin,A[j].origin = A[j].origin,A[i].origin
A[i+1].b,A[r].b = A[r].b,A[i+1].b
A[i+1].a,A[r].a = A[r].a,A[i+1].a
A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin
return i+1
def quick_sort(A , p, r):
if p < r:
q = partition(A,p,r)
quick_sort(A, p, q-1)
quick_sort(A, q+1, r)
def isStable(A):
flag=True
n=len(A)
for i in range(n-1):
if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:
flag = False
return flag
if __name__ == "__main__":
n=int(input())
A=[]
for i in range(n):
num =Num()
a=input().split()
num.a = a[0]
num.b = int(a[1])
num.origin=i
A.append(num)
quick_sort(A,0,n-1)
if isStable(A):
print("Stable")
else:
print("Not stable")
for i in A:
print(i.a,end=" ")
print(i.b)
|
s013975082
|
p03338
|
u788337030
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 3,060
| 386
|
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.
|
ret = input()
count_max = 0
for i in range(1, len(ret)):
count = 0
for k in range(97, 123):
if ((chr(k) in ret[:i]) & (chr(k) in ret[i:])):
count += 1
if count > count_max:
count_max = count
print(count_max)
|
s104978392
|
Accepted
| 18
| 3,060
| 402
|
len = int(input())
ret = input()
count_max = 0
for i in range(1, len):
count = 0
for k in range(97, 123):
if ((chr(k) in ret[:i]) and (chr(k) in ret[i:])):
count += 1
if count > count_max:
count_max = count
print(count_max)
|
s008534342
|
p02601
|
u380854465
| 2,000
| 1,048,576
|
Wrong Answer
| 125
| 27,148
| 231
|
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
|
import sys
import numpy as np
A,B,C = list(map(int, input().split()))
K = int(input())
for i in range(K):
if A > B:
B = B*2
elif B > C:
C = C*2
if A < B and B < C:
print('yes')
else:
print('no')
|
s777755193
|
Accepted
| 122
| 26,856
| 233
|
import sys
import numpy as np
A,B,C = list(map(int, input().split()))
K = int(input())
for i in range(K):
if A >= B:
B = B*2
elif B >= C:
C = C*2
if A < B and B < C:
print('Yes')
else:
print('No')
|
s722272272
|
p00101
|
u775586391
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,592
| 210
|
An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina". Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000.
|
n = int(input())
for i in range(n):
l = [s for s in input().split()]
for s in l:
if s == 'Hoshino':
l[l.index(s)] = 'Hoshina'
a = ''
for s in l:
a += s
a += ' '
a.rstrip()
print(a)
|
s278064923
|
Accepted
| 20
| 7,588
| 97
|
n = int(input())
for i in range(n):
a = input()
a = a.replace('Hoshino','Hoshina')
print(a)
|
s146985276
|
p03380
|
u477977638
| 2,000
| 262,144
|
Wrong Answer
| 93
| 14,428
| 282
|
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
|
import bisect
n=int(input())
a=[0]+sorted(list(map(int,input().split())))+[10**9]
ans1=a[-2]
index=bisect.bisect_right(a,(ans1)//2)
b1=a[index-1]
b2=a[index]
if abs((ans1)/2-b1)<abs((ans1)/2-b2):ans2=b1
else:ans2=b2
print(a)
print(b1,b2)
print(index)
print(ans1,ans2,sep=" ")
|
s342004178
|
Accepted
| 80
| 14,052
| 247
|
import bisect
n=int(input())
a=[0]+sorted(list(map(int,input().split())))+[10**9]
ans1=a[-2]
index=bisect.bisect_right(a,(ans1)//2)
b1=a[index-1]
b2=a[index]
if abs((ans1)/2-b1)<=abs((ans1)/2-b2):ans2=b1
else:ans2=b2
print(ans1,ans2,sep=" ")
|
s307312936
|
p03854
|
u076996519
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,188
| 140
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
s = input().replace("eracer", "").replace("erace","").replace("dream","").replace("dreamer","")
if s:
print("NO")
else:
print("YES")
|
s295549617
|
Accepted
| 18
| 3,188
| 140
|
s = input().replace("eraser", "").replace("erase","").replace("dreamer","").replace("dream","")
if s:
print("NO")
else:
print("YES")
|
s120542606
|
p03854
|
u761529120
| 2,000
| 262,144
|
Wrong Answer
| 46
| 3,316
| 344
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
S = input()
S = S[::-1]
word_list1 = "dream"
word_list2 = "dreamer"
word_list3 = "erase"
word_list4 = "eraser"
s = ""
ans = ""
word_list = [word_list1[::-1],word_list2[::-1],word_list3[::-1],word_list4[::-1]]
for i in S:
s += i
if s in word_list:
ans += s
s = ""
if S == ans:
print('Yes')
else:
print('No')
|
s965650988
|
Accepted
| 23
| 6,516
| 112
|
import re
S = input()
if re.match('(dream|dreamer|erase|eraser)+$', S):
print('YES')
else:
print('NO')
|
s719314795
|
p02409
|
u406002631
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,624
| 368
|
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.
|
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
b = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
b[a[i][0] - 1][a[i][1] - 1][a[i][2] - 1] = a[i][3]
for i in range(4):
for j in range(3):
b[i][j].insert(0, "")
print(*b[i][j])
print("####################")
|
s607954342
|
Accepted
| 20
| 5,624
| 398
|
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
b = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
b[a[i][0] - 1][a[i][1] - 1][a[i][2] - 1] += a[i][3]
for i in range(4):
for j in range(3):
b[i][j].insert(0, "")
print(*b[i][j])
if i == 3:
break
print("####################")
|
s280986439
|
p02608
|
u083960235
| 2,000
| 1,048,576
|
Wrong Answer
| 2,205
| 9,980
| 1,000
|
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
def f(x, y, z):
return x**2 + y**2 + z **2 + x * y + y * z + z * x
L = [0] * (N + 1)
for x in range(1, N+1):
for y in range(1, N + 1):
for z in range(1, N + 1):
if f(x,y,z) < N:
L[f(x, y, z)] += 1
print(*L, sep="\n")
|
s875240753
|
Accepted
| 1,106
| 10,272
| 1,054
|
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
def f(x, y, z):
return x**2 + y**2 + z **2 + x * y + y * z + z * x
L = [0] * (N + 1)
thre = ceil(sqrt(N)) + 1
# print(thre)
for x in range(1, thre+1):
for y in range(1, thre + 1):
for z in range(1, thre + 1):
if f(x,y,z) <= N:
L[f(x, y, z)] += 1
print(*L[1:], sep="\n")
|
s094270940
|
p02612
|
u453306058
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,168
| 32
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n = int(input())
print(n % 1000)
|
s408798513
|
Accepted
| 31
| 9,152
| 89
|
n = int(input())
a = n % 1000
if a == 0:
print(0)
exit()
else:
print(1000-a)
|
s373258573
|
p04044
|
u498397607
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 121
|
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
|
n, l = map(int, input().split())
s_list = sorted([input() for i in range(n)])
mojiretu = ','.join(s_list)
print(mojiretu)
|
s271229226
|
Accepted
| 18
| 3,060
| 120
|
n, l = map(int, input().split())
s_list = sorted([input() for i in range(n)])
mojiretu = ''.join(s_list)
print(mojiretu)
|
s980757330
|
p03854
|
u401487574
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,188
| 156
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
s = input()
sr = s[::-1]
w = ["maerd","remaerd","esare","resare"]
for i in range(4):
sr = sr.replace(w[i],"")
if sr == "":print("Yes")
else:print("No")
|
s955731210
|
Accepted
| 19
| 3,188
| 155
|
s = input()
sr = s[::-1]
w = ["resare","esare","remaerd","maerd"]
for i in range(4):
sr = sr.replace(w[i],"")
if sr == "":print("YES")
else:print("NO")
|
s197966331
|
p02618
|
u607075479
| 2,000
| 1,048,576
|
Wrong Answer
| 39
| 9,844
| 853
|
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
|
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
D = NI()
C = NLI()
S = [NLI() for _ in range(D)]
#T = [NI() - 1 for _ in range(D)]
T = []
last = [0]*26
conf = 0
for i in range(D):
idx, s = argmax(S[i])
T.append(idx)
conf += s
last[idx] = i+1
for a in range(26):
conf -= C[a] * (i+1 - last[a])
print(conf)
def argmax(A):
A = [[i, a] for i, a in enumerate(A)]
A.sort(key=lambda x: x[1], reverse=True)
return A[0]
if __name__ == "__main__":
main()
|
s865157654
|
Accepted
| 37
| 9,852
| 855
|
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
D = NI()
C = NLI()
S = [NLI() for _ in range(D)]
#T = [NI() - 1 for _ in range(D)]
T = []
last = [0]*26
conf = 0
for i in range(D):
idx, s = argmax(S[i])
T.append(idx)
conf += s
last[idx] = i+1
for a in range(26):
conf -= C[a] * (i+1 - last[a])
print(idx+1)
def argmax(A):
A = [[i, a] for i, a in enumerate(A)]
A.sort(key=lambda x: x[1], reverse=True)
return A[0]
if __name__ == "__main__":
main()
|
s353416708
|
p02928
|
u596368396
| 2,000
| 1,048,576
|
Wrong Answer
| 565
| 3,188
| 493
|
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.
|
def main(n,k,a):
mod = 10**9 + 7
t1, t2 = 0, 0
for i in range(n):
for j in range(n):
if a[i] > a[j]:
t1 += 1
for j in range(n - i):
if a[i] > a[j + i]:
t2 += 1
count = t1 * k * (k - 1) / 2 % mod
count += t2 * k % mod
print(t1, t2)
print(int(count % mod))
if __name__ == '__main__':
n,k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
main(n,k,a)
|
s407417924
|
Accepted
| 608
| 3,188
| 484
|
def main(n,k,a):
mod = 10**9 + 7
t1, t2 = 0, 0
for i in range(n):
for j in range(n):
if a[i] > a[j]:
t1 += 1
for j in range(n - i - 1):
if a[i] > a[j + i + 1]:
t2 += 1
count = (t1 * ((k * (k - 1)) // 2)) % mod
count += (t2 * k) % mod
print(int(count % mod))
if __name__ == '__main__':
n, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
main(n,k,a)
|
s149534515
|
p02806
|
u343977188
| 2,525
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 216
|
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
|
N=int(input())
S=[]
T=[]
for i in range(N):
s,t=input().split()
S.append(str(s))
T.append(int(t))
X=str(input())
triger=0
j=0
A=0
for i in S:
if i==X:
triger=1
if triger==1:
A+=T[j]
j+=1
print(A)
|
s043963998
|
Accepted
| 17
| 3,064
| 216
|
N=int(input())
S=[]
T=[]
for i in range(N):
s,t=input().split()
S.append(str(s))
T.append(int(t))
X=str(input())
triger=0
j=0
A=0
for i in S:
if triger==1:
A+=T[j]
if i==X:
triger=1
j+=1
print(A)
|
s426586377
|
p02678
|
u753386263
| 2,000
| 1,048,576
|
Wrong Answer
| 2,208
| 76,828
| 1,160
|
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.
|
N,M=map(int,input().split())
AB=[]
for i in range(M):
a,b=map(int,input().split())
AB.append([a,b])
AB=list(map(list, set(map(tuple, AB))))
ROOP=[[] for i in range(N+1)]
for i in range(2,N+1):
for ab in AB:
if i ==ab[0]:
ROOP[i].append(ab[1])
elif i==ab[1]:
ROOP[i].append(ab[0])
if 1 in ROOP[i]:
GOAL_start=i
visited=[-1]*(N+1)
visited[GOAL_start]=1
def bfs(GOAL,GOAL_NEXT):
if GOAL_NEXT in ROOP[GOAL]:
ROOP[GOAL].remove(GOAL_NEXT)
else:
return 1
for i in ROOP[GOAL]:
if visited[i]==-1 or visited[i]>1+visited[GOAL]:
visited[i]=1+visited[GOAL]
bfs(i,GOAL)
else:
return 1
bfs(GOAL_start,1)
print(AB)
print(visited)
if -1 not in visited[2:]:
print("Yes")
for i in visited[2:]:
print(i)
else:
print("NO")
|
s024505721
|
Accepted
| 763
| 65,612
| 663
|
from collections import deque
N,M=map(int,input().split())
AB=[]
for i in range(M):
AB.append(list(map(int,input().split())))
links=[[] for _ in range(N+1)]
results=[-1]*(N+1)
for a, b in AB:
links[a].append(b)
links[b].append(a)
q=deque([1])
while q:
pos=q.popleft()
for i in links[pos]:
if results[i]==-1:
results[i]=pos
q.append(i)
print('Yes')
print('\n'.join(str(i) for i in results[2:]))
|
s073852996
|
p03090
|
u334712262
| 2,000
| 1,048,576
|
Wrong Answer
| 43
| 6,016
| 1,384
|
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.
|
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N):
E = []
for i in range(1, N+1):
for j in range(i+1, N+1):
if N % 2 == 0 and i+j == N+1:
continue
if N % 2 == 1 and i+j == N:
continue
E.append((i, j))
return E
def main():
N = read_int()
for e in slv(N):
print('%d %d' % e)
if __name__ == '__main__':
main()
|
s062336165
|
Accepted
| 45
| 5,980
| 1,274
|
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N):
se = N+1 if N % 2 == 0 else N
return list(filter(lambda x: x[0]+x[1]!=se, combinations(range(1, N+1), 2)))
def main():
N = read_int()
E = slv(N)
print(len(E))
for e in E:
print('%d %d' % e)
if __name__ == '__main__':
main()
|
s850809963
|
p03448
|
u267300160
| 2,000
| 262,144
|
Wrong Answer
| 42
| 3,060
| 210
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
a,b,c,x = map(int,[input() for i in range(4)])
count = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
if(100*a + 10*b + c == x):
count += 1
print(count)
|
s639081382
|
Accepted
| 50
| 3,060
| 214
|
a,b,c,x = map(int,[input() for i in range(4)])
count = 0
for i in range(a+1):
for j in range(b+1):
for k in range(c+1):
if(500*i + 100*j + 50*k == x):
count += 1
print(count)
|
s082869738
|
p03140
|
u379692329
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 231
|
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i between 1 and N (inclusive). Change the i-th character from the beginning of the chosen string to some other lowercase English letter. What is the minimum number of operations required to achieve the objective?
|
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
if A[i] == B[i] and B[i] == C[i]:
continue
elif A[i] != B[i] and B[i] != C[i]:
ans += 2
else:
ans += 1
print(ans)
|
s841657357
|
Accepted
| 17
| 3,060
| 248
|
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
if A[i] == B[i] and B[i] == C[i]:
continue
elif A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
ans += 2
else:
ans += 1
print(ans)
|
s580756792
|
p03623
|
u252964975
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 85
|
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
x,a,b=map(int, input().split())
if abs(x-a)>abs(x-b):
print('A')
else:
print('B')
|
s736878667
|
Accepted
| 18
| 2,940
| 86
|
x,a,b=map(int, input().split())
if abs(x-a)<abs(x-b):
print('A')
else:
print('B')
|
s793857947
|
p03861
|
u168416324
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,064
| 73
|
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?
|
x,y,d=map(int,input().split())
ans=y//d-x//d
if x==0:
ans+=1
print(ans)
|
s753090725
|
Accepted
| 28
| 9,164
| 60
|
x,y,d=map(int,input().split())
ans=y//d-(x-1)//d
print(ans)
|
s643507963
|
p02415
|
u184749404
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,532
| 22
|
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
|
S = input()
S.upper()
|
s739815940
|
Accepted
| 20
| 5,544
| 46
|
S = input()
S.swapcase()
print(S.swapcase())
|
s317146339
|
p04029
|
u304599973
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,100
| 44
|
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?
|
print(sum([i for i in range(int(input()))]))
|
s645048367
|
Accepted
| 27
| 9,092
| 46
|
print(sum([i for i in range(int(input())+1)]))
|
s800088096
|
p03543
|
u649558044
| 2,000
| 262,144
|
Wrong Answer
| 20
| 2,940
| 80
|
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
|
n = int(input())
a, b = 1, 2
for i in range(n - 1):
a, b = a + b, a
print(a)
|
s994194134
|
Accepted
| 19
| 2,940
| 165
|
a, b, c, d = map(int, tuple(input()))
print('Yes' if a == b == c or b == c == d else 'No')
|
s426607038
|
p03999
|
u948911484
| 2,000
| 262,144
|
Wrong Answer
| 23
| 3,064
| 230
|
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
|
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
l = [0]
for j in range(n-1):
if i << j & 2**(n-2):
l.append(j+1)
l.append(n)
print(l)
for j in range(len(l)-1):
ans += int(s[l[j]:l[j+1]])
print(ans)
|
s570878852
|
Accepted
| 20
| 3,060
| 212
|
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
l = [0]
for j in range(n-1):
if i >> j & 1:
l.append(j+1)
l.append(n)
for j in range(len(l)-1):
ans += int(s[l[j]:l[j+1]])
print(ans)
|
s028256231
|
p03449
|
u941753895
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 171
|
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())
if n==5:
exit()
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l=[]
for i in range(n):
l.append(sum(l1[:i+1]+l2[i:]))
print(max(l))
|
s404466572
|
Accepted
| 78
| 7,196
| 596
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()
def main():
n=I()
a=LI()
b=LI()
l1=[a[0]]
for i in range(1,len(a)):
l1.append(l1[i-1]+a[i])
b.reverse()
l2=[b[0]]
for i in range(1,len(b)):
l2.append(l2[i-1]+b[i])
l2.reverse()
# print(l1)
# print(l2)
mx=0
for i in range(n):
mx=max(mx,l1[i]+l2[i])
return mx
print(main())
|
s414664402
|
p03476
|
u569322757
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 3,992
| 761
|
We say that a odd number N is _similar to 2017_ when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.
|
def erat(n):
l = [1 for _ in range(n)]
i = 0
while (i < n):
if i == 0:
l[i] = 0
elif l[i] == 1:
for j in range(i + 2, n + 1):
if not j % (i + 1):
l[j - 1] = 0
# l = list(map(lambda x: 1 if x % (i + 1) else 0, l))
i += 1
return l
n_max = 10**5
is_prime = erat(n_max)
is_2017 = [0 for _ in range(n_max)]
for i in range(2, n_max + 1):
if is_prime[i - 1] and is_prime[(i + 1) // 2 - 1]:
is_2017[i - 1] = 1
s = [0]
for i in range(n_max):
s.append(s[i] + is_2017[i])
print('plz input.')
q = int(input())
ans = []
for _ in range(q):
li, ri = map(int, input().split())
ans.append(s[ri] - s[li - 1])
for a in ans:
print(a)
|
s809154261
|
Accepted
| 884
| 7,944
| 567
|
def erat(n):
l = [0, 0] + [1 for _ in range(n - 1)]
i = 2
while (i < n + 1):
if l[i] == 1:
for j in range(i**2, n + 1, i):
l[j] = 0
i += 1
return l
n_max = 10**5
is_prime = erat(n_max)
is_2017 = [0 for _ in range(n_max + 1)]
for i in range(2, n_max + 1):
if is_prime[i] and is_prime[(i + 1) // 2]:
is_2017[i] = 1
s = [0]
for i in range(1, n_max + 1):
s.append(s[i - 1] + is_2017[i])
q = int(input())
for _ in range(q):
li, ri = map(int, input().split())
print(s[ri] - s[li - 1])
|
s938687516
|
p03471
|
u350179603
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,064
| 267
|
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
|
a = list(map(int, input().split()))
count = 0
for i in range(20):
for j in range(20):
count += 1
if a[0]-i-j >=0 and 10000*i + 5000*j + (a[0] - i - j )* 1000 == a[1]:
print(i, j, a[0]-i-j)
break
if count == 400:
print(-1, -1, -1)
|
s832284569
|
Accepted
| 690
| 3,064
| 262
|
a = list(map(int, input().split()))
result = [-1, -1, -1]
for i in range(a[0]+1):
for j in range(a[0]+1-i):
if (10000*i + 5000*j + (a[0] - i - j )* 1000) == a[1]:
result = [i, j, a[0] - i - j]
break
print(' '.join(map(str, result)))
|
s497358038
|
p03563
|
u235066013
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 49
|
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
|
r=float(input())
g=float(input())
print(2*g-r)
|
s997164398
|
Accepted
| 17
| 2,940
| 45
|
r=int(input())
g=int(input())
print(2*g-r)
|
s175212917
|
p03681
|
u527261492
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,488
| 242
|
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. _("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.)_ Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.
|
import sys
n,m=map(int,input().split())
if abs(n-m)>1:
print(0)
sys.exit()
cnt=1
for i in range(1,n+1):
cnt*=i
if n==m:
print((cnt**2)%((10**9)+7))
if n-m==1:
print(cnt*(cnt//m)%(10**9)+7)
if m-n==1:
print(cnt*cnt*(n+1)%(10**9)+7)
|
s226722335
|
Accepted
| 77
| 3,064
| 403
|
import sys
n,m=map(int,input().split())
num=n
mum=m
if 2<=abs(n-m):
print(0)
sys.exit()
if abs(n-m)==1:
while n>1:
num*=n-1
n-=1
num=num%((10**9)+7)
while m>1:
mum*=m-1
m-=1
mum=mum%((10**9)+7)
print((num*mum)%((10**9)+7))
sys.exit()
if abs(n-m)==0:
while n>1:
num*=n-1
n-=1
num=num%((10**9)+7)
print((2*(num**2))%((10**9)+7))
sys.exit()
|
s177055871
|
p03548
|
u798129018
| 2,000
| 262,144
|
Wrong Answer
| 27
| 2,940
| 114
|
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
|
x,y,z = map(int,input().split())
ans = 1
while True:
if ans*(y+z)+z>x:
break
else:
ans += 1
print(ans)
|
s812863865
|
Accepted
| 26
| 2,940
| 118
|
x,y,z = map(int,input().split())
ans = 1
while True:
if ans*(y+z)+z>x:
break
else:
ans += 1
print(ans-1)
|
s145557624
|
p02336
|
u011621222
| 1,000
| 262,144
|
Wrong Answer
| 40
| 6,512
| 568
|
Balls| Boxes| Any way| At most one ball| At least one ball ---|---|---|---|--- Distinguishable| Distinguishable| 1| 2| 3 Indistinguishable| Distinguishable| 4| 5| 6 Distinguishable| Indistinguishable| 7| 8| 9 Indistinguishable| Indistinguishable| 10| 11| 12
|
# -*- coding: utf-8 -*-
n,k = map(int, input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**7+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1] 計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
a = cmb(n-1,k-1,mod)
print(a)
|
s706564298
|
Accepted
| 20
| 5,596
| 153
|
n,k = map(int, input().split())
if k > n:
print(0)
quit()
ans = 1
for i in range(1,k):
ans *= n-i
ans //= i
ans %= 1000000007
print(ans)
|
s112899634
|
p03448
|
u314350544
| 2,000
| 262,144
|
Wrong Answer
| 60
| 13,800
| 285
|
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())
answer_values = []
for c_value in range(c):
for b_value in range(b):
for a_value in range(a):
answer_values.append(c_value * 500 + b_value * 100 + a_value * 50)
print(answer_values.count(x))
|
s717848380
|
Accepted
| 59
| 13,996
| 292
|
a = int(input())
b = int(input())
c = int(input())
x = int(input())
answer_values = []
for a_value in range(a + 1):
for b_value in range(b+1):
for c_value in range(c+1):
answer_values.append(a_value * 500 + b_value * 100 + c_value * 50)
print(answer_values.count(x))
|
s769947455
|
p03130
|
u667024514
| 2,000
| 1,048,576
|
Wrong Answer
| 89
| 3,444
| 205
|
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
|
from collections import Counter
lis = [0 for i in range(4)]
for i in range(3):
a,b = map(int,input().split())
lis[a-1] += 1
lis[b-1] += 1
if lis.count(2) == 4:
print("YES")
else:print("NO")
|
s671464712
|
Accepted
| 17
| 2,940
| 97
|
print("YES") if sum([sum(list(map(int,input().split()))) for i in range(3)])==15 else print("NO")
|
s590088190
|
p04043
|
u053677958
| 2,000
| 262,144
|
Wrong Answer
| 153
| 12,420
| 291
|
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.
|
# coding: utf-8
import numpy as np
if __name__ == "__main__":
input_str = input("input >>> ")
length_str = np.array([int(f) for f in input_str.split(" ")])
if np.sum(length_str == 5) and np.sum(length_str == 7):
print("YES")
else:
print("NO")
|
s433002836
|
Accepted
| 155
| 12,512
| 291
|
# coding: utf-8
import numpy as np
if __name__ == "__main__":
input_str = input("")
length_str = np.array([int(f) for f in input_str.split(" ")])
if np.sum(length_str == 5) == 2 and np.sum(length_str == 7) == 1:
print("YES")
else:
print("NO")
|
s352649045
|
p03739
|
u597455618
| 2,000
| 262,144
|
Wrong Answer
| 112
| 14,464
| 433
|
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 = list(map(int, input().split()))
check = ''
if a[0] > 0:
check = '+'
else:
check = '-'
ans = 0
for i in range(1, n):
a[i] += a[i-1]
if check == '+':
if a[i] >= 0:
ans += abs(a[i]) + 1
a[i] -= abs(a[i]) + 1
check = '-'
else:
if a[i] <= 0:
ans += abs(a[i]) + 1
a[i] += abs(a[i]) + 1
check = '+'
print(a)
print(ans)
|
s147000574
|
Accepted
| 88
| 14,332
| 323
|
N = int(input())
A = [int(x) for x in input().split()]
def F(A, sgn):
cnt = 0
cum = 0
for a in A:
sgn *= -1
cum += a
if cum * sgn > 0:
continue
if sgn > 0:
cnt += 1 - cum
cum = 1
else:
cnt += cum + 1
cum = -1
return cnt
answer = min(F(A,1), F(A,-1))
print(answer)
|
s360865491
|
p02936
|
u744920373
| 2,000
| 1,048,576
|
Wrong Answer
| 2,116
| 183,028
| 1,001
|
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
|
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from collections import deque
N, Q = mi()
D = li2(N-1)
px = li2(Q)
que = deque()
adj = [[] for i in range(N+1)]
for i in range(N-1):
adj[D[i][0]].append(D[i][1])
ans = [0]*(N+1)
for j in range(Q):
ind, a = px[j][0], px[j][1]
que.append(ind)
while(len(que)!=0):
v = que.popleft()
ans[v] += a
for e in adj[v]:
#ans[e] += a
que.append(e)
print(ans)
for i in range(1, N+1):
print(ans[i])
|
s814201599
|
Accepted
| 1,247
| 104,624
| 1,200
|
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
## BFS
from collections import deque
def main():
N, Q = mi()
x = li2(N-1)
cnt = [0]*N
for i in range(Q):
p0, p1 = mi()
cnt[p0-1] += p1
adj = [[] for i in range(N)]
for i in range(N-1):
adj[x[i][0]-1].append(x[i][1]-1)
adj[x[i][1]-1].append(x[i][0]-1)
que = deque()
ans = [0]*N
# BFS
que.append((0, 0))
num = 0
while que!=deque():
v = que.popleft()
ans[v[1]] = ans[v[0]] + cnt[v[1]]
for next in adj[v[1]]:
if next != v[0]:
que.append((v[1], next))
print(*ans)
if __name__ == "__main__":
main()
|
s758984599
|
p03493
|
u340947941
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 49
|
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
S=list(map(int,input().split(" ")))
print(sum(S))
|
s238281975
|
Accepted
| 17
| 2,940
| 67
|
S=list(map(int,list(input())))
print(sum(S))
|
s763084714
|
p03605
|
u010110540
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 46
|
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
N = input()
print('YES' if '9' in N else 'NO')
|
s494811713
|
Accepted
| 17
| 2,940
| 46
|
N = input()
print('Yes' if '9' in N else 'No')
|
s489526985
|
p03371
|
u757919796
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 292
|
"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 = tuple(map(lambda i: int(i), input().split()))
print(a+b,c*2)
if a + b > c * 2:
if a > c or b > c:
print(c*y*2 if x<y else c*x*2)
else:
num_c = (x if x < y else y) * 2
print((b*(y-x) if x < y else a*(x-y)) + c*num_c)
else:
print(a*x + b*y)
|
s704850294
|
Accepted
| 17
| 3,060
| 254
|
a, b, c, x, y = tuple(map(lambda i: int(i), input().split()))
p1 = a * x + b * y
p2 = c * min(x, y) * 2 + (a * (x - y) if x > y else b * (y - x))
p3 = c*max(x, y)*2
print(min(p1, p2, p3))
|
s707811663
|
p03434
|
u245870380
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 91
|
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
|
N = int(input())
a = list(map(int, input().split()))[::-1]
print(sum(a[0::2])-sum(a[1::2]))
|
s632947721
|
Accepted
| 17
| 3,064
| 99
|
N = int(input())
a = sorted(list(map(int, input().split())))[::-1]
print(sum(a[0::2])-sum(a[1::2]))
|
s867427921
|
p02601
|
u893178798
| 2,000
| 1,048,576
|
Wrong Answer
| 32
| 9,180
| 211
|
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
|
A, B, C = map(int, input().split())
K = int(input())
i = 0
while(not(A < B)):
B = B * 2
i = i + 1
while(not(B < C)):
C = C * 2
i = i + 1
print(i)
if i <= K:
print('Yes')
else:
print('No')
|
s661468951
|
Accepted
| 30
| 9,052
| 194
|
A, B, C = map(int, input().split())
K = int(input())
i = 0
while(A >= B):
B = B * 2
i = i + 1
while(B >= C):
C = C * 2
i = i + 1
if i <= K:
print('Yes')
else:
print('No')
|
s445324966
|
p03971
|
u094999522
| 2,000
| 262,144
|
Wrong Answer
| 76
| 10,612
| 204
|
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
|
n, a, b = map(int, input().split())
s = input()
q = [1] * n
for i,l in enumerate(s):
q[i] *= (l == "b" and b > 0) or (l == "a" and a + b > 0)
b -= q[i]
print("".join(["YNeos"[1-i::2] for i in q]))
|
s944167198
|
Accepted
| 99
| 10,740
| 242
|
n, a, b = map(int, input().split())
s = input()
q = [1] * n
for i,l in enumerate(s):
q[i] *= ((l == "b" and b > 0) or l == "a") and a + b > 0
b -= q[i]*(l == "b")
a -= q[i]*(l == "a")
print("\n".join(["YNeos"[1-i::2] for i in q]))
|
s561390358
|
p03359
|
u370867568
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 76
|
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
a, b = map(int, input().split())
ans = a
if b <= a:
ans += 1
print(ans)
|
s182516853
|
Accepted
| 17
| 2,940
| 75
|
a, b = map(int, input().split())
ans = a
if a > b:
ans -= 1
print(ans)
|
s556060949
|
p03502
|
u945427450
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 73
|
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
n=input()
s=0
for i in n:
s+=int(i)
print(['NO','YES'][int(n)%s==0])
|
s872144497
|
Accepted
| 17
| 2,940
| 73
|
n=input()
s=0
for i in n:
s+=int(i)
print(['No','Yes'][int(n)%s==0])
|
s249849855
|
p03251
|
u188244611
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 330
|
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.
|
# ABC 110 , B
tmp = [int(el) for el in input().split(' ')]
n = tmp[0]
m = tmp[1]
x = tmp[2]
y = tmp[3]
X = [int(el) for el in input().split(' ')]
Y = [int(el) for el in input().split(' ')]
for z in range(x+1, y+1):
if max(X) < z and min(Y) >= z:
print(z)
print('No War')
break
else:
print('War')
|
s785176420
|
Accepted
| 18
| 3,064
| 313
|
# ABC 110 , B
tmp = [int(el) for el in input().split(' ')]
n = tmp[0]
m = tmp[1]
x = tmp[2]
y = tmp[3]
X = [int(el) for el in input().split(' ')]
Y = [int(el) for el in input().split(' ')]
for z in range(x+1, y+1):
if max(X) < z and min(Y) >= z:
print('No War')
break
else:
print('War')
|
s434646128
|
p03024
|
u488178971
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 79
|
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.
|
N=input()
if N.count('o')+15-len(N) >=8:
print('Yes')
else:
print('No')
|
s207010612
|
Accepted
| 17
| 2,940
| 79
|
N=input()
if N.count('o')+15-len(N) >=8:
print('YES')
else:
print('NO')
|
s470823573
|
p02401
|
u806005289
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,616
| 357
|
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.
|
x=[]
i=0
while 1:
l=input().split()
a=int(l[0])
b=int(l[2])
op=str(l[1])
if op=="?":
break
elif op=="/":
if b==0:
pass
else:
x.append(eval(str(a)+op+str(b)))
i=i+1
else:
x.append(eval(str(a)+op+str(b)))
i=i+1
m=0
while m<i:
print(x[m])
m=m+1
|
s451015991
|
Accepted
| 20
| 5,668
| 380
|
import math
x=[]
i=0
while 1:
l=input().split()
a=int(l[0])
b=int(l[2])
op=str(l[1])
if op=="?":
break
elif op=="/":
if b==0:
pass
else:
x.append(math.floor(eval(str(a)+op+str(b))))
i=i+1
else:
x.append(eval(str(a)+op+str(b)))
i=i+1
m=0
while m<i:
print(x[m])
m=m+1
|
s834364864
|
p02742
|
u133527491
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 91
|
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
h,w=map(int,input().split())
if h*w/2!=h*w//2:
print(h*w//2+1)
exit()
print(h*w/2)
|
s934530352
|
Accepted
| 17
| 2,940
| 133
|
h,w=map(int,input().split())
if h==1 or w==1:
print(1)
exit()
if h*w/2!=h*w//2:
print(h*w//2+1)
exit()
print(h*w//2)
|
s384430709
|
p02747
|
u143683072
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 84
|
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 = input()
s.replace('hi', '')
if len(s) == 0:
print('Yes')
else:
print('No')
|
s329779414
|
Accepted
| 17
| 2,940
| 81
|
s = input()
if len(s.replace('hi', '')) == 0:
print('Yes')
else:
print('No')
|
s754421329
|
p03049
|
u970899068
| 2,000
| 1,048,576
|
Wrong Answer
| 55
| 4,716
| 506
|
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
|
n=int(input())
s=[list(input()) for i in range(n)]
count=0
countA=0
countB=0
countBA=0
for i in range(n):
for j in range(len(s[i])-1):
if s[i][j]=='A' and s[i][j+1]=='B':
count+=1
for i in range(n):
if s[i][0]=='B' and s[i][-1]=='A':
countBA+=1
elif s[i][0]=='B':
countB+=1
elif s[i][-1]=='A':
countA+=1
count+=max(countBA-1,0)+min(countB+1,countA+1)
print(count)
|
s692304297
|
Accepted
| 52
| 4,596
| 604
|
n=int(input())
s=[list(input()) for i in range(n)]
count=0
countA=0
countB=0
countBA=0
for i in range(n):
for j in range(len(s[i])-1):
if s[i][j]=='A' and s[i][j+1]=='B':
count+=1
for i in range(n):
if s[i][0]=='B' and s[i][-1]=='A':
countBA+=1
elif s[i][0]=='B':
countB+=1
elif s[i][-1]=='A':
countA+=1
if (countA>0 or countB>0) and countBA>0:
count+=countBA-1+min(countB+1,countA+1)
else:
count+=min(countB,countA)+max(countBA-1,0)
print(count)
|
s065295951
|
p03150
|
u624696727
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 856
|
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.
|
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def main():
S = sys.stdin.readline()
counter = 0
if(S[0]!='k'):
if(S[-8:-1]=='keyence'):
print("Yes")
else:
print("No")
elif(S[0]=="k" and S[-2]!="e"):
if(S[0:7]=='keyence'):
print("Yes")
else:
print("No")
elif(S[0]=="k" and S[-2]=="e"):
key = "keyence"
for i in range(2,7):
if(key == str(S[0:i])+str(S[-8+i:-1])):
print("Yes")
else:
print("No")
main()
|
s740269226
|
Accepted
| 18
| 3,064
| 919
|
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def main():
S = sys.stdin.readline()
counter = 0
if(S[0]!='k'):
if(S[-8:-1]=='keyence'):
print("YES")
else:
print("NO")
elif(S[0]=="k" and S[-2]!="e"):
if(S[0:7]=='keyence'):
print("YES")
else:
print("NO")
elif(S[0]=="k" and S[-2]=="e"):
key = "keyence"
f = False
for i in range(1,7):
if(key == str(S[0:i])+str(S[-8+i:-1])):
print("YES")
f = True
break
if f==False : print("NO")
else:
print("NO")
main()
|
s542499814
|
p02261
|
u995990363
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,612
| 1,764
|
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
|
def bubbleSort(cards, N):
flag = True
while flag:
flag = False
for j in range(N-1, 0, -1):
if cards.numbers[j] < cards.numbers[j - 1]:
cards.swap(j, j-1)
flag = True
return cards
def selectionSort(cards,N):
for i in range(N):
minj = i
for j in range(i, N):
if cards.numbers[j] < cards.numbers[minj]:
minj = j
if minj != i:
cards.swap(i, minj)
return cards
class Cards(object):
def __init__(self, cards):
self.cards = cards
self.numbers = [int(card[1]) for card in cards]
def filter_by_number(self, number):
return [card for card in self.cards if card.endswith(str(number))]
def swap(self, i, j):
self.cards[i], self.cards[j] = self.cards[j], self.cards[i]
self.numbers = [int(card[1]) for card in self.cards]
def show(self):
print(' '.join(self.cards))
def is_stable(self, cards):
for n in range(1,10):
suits_x = self.filter_by_number(str(n))
suits_y = cards.filter_by_number(str(n))
if suits_x != suits_y:
return False
return True
def copy(self):
return Cards([card for card in self.cards])
def run():
n = int(input())
cards = Cards(input().split())
cards_sorted = bubbleSort(cards.copy(),n)
cards_sorted.show()
if cards.is_stable(cards_sorted):
print('Stable')
else:
print('Not Stable')
cards_sorted = selectionSort(cards.copy(),n)
cards_sorted.show()
if cards.is_stable(cards_sorted):
print('Stable')
else:
print('Not Stable')
cards.show()
if __name__ == '__main__':
run()
|
s327336738
|
Accepted
| 20
| 5,616
| 1,746
|
def bubbleSort(cards, N):
flag = True
while flag:
flag = False
for j in range(N-1, 0, -1):
if cards.numbers[j] < cards.numbers[j - 1]:
cards.swap(j, j-1)
flag = True
return cards
def selectionSort(cards,N):
for i in range(N):
minj = i
for j in range(i, N):
if cards.numbers[j] < cards.numbers[minj]:
minj = j
if minj != i:
cards.swap(i, minj)
return cards
class Cards(object):
def __init__(self, cards):
self.cards = cards
self.numbers = [int(card[1]) for card in cards]
def filter_by_number(self, number):
return [card for card in self.cards if card.endswith(str(number))]
def swap(self, i, j):
self.cards[i], self.cards[j] = self.cards[j], self.cards[i]
self.numbers = [int(card[1]) for card in self.cards]
def show(self):
print(' '.join(self.cards))
def is_stable(self, cards):
for n in range(1,10):
suits_x = self.filter_by_number(str(n))
suits_y = cards.filter_by_number(str(n))
if suits_x != suits_y:
return False
return True
def copy(self):
return Cards([card for card in self.cards])
def run():
n = int(input())
cards = Cards(input().split())
cards_sorted = bubbleSort(cards.copy(),n)
cards_sorted.show()
if cards.is_stable(cards_sorted):
print('Stable')
else:
print('Not stable')
cards_sorted = selectionSort(cards.copy(),n)
cards_sorted.show()
if cards.is_stable(cards_sorted):
print('Stable')
else:
print('Not stable')
if __name__ == '__main__':
run()
|
s695631096
|
p02261
|
u630566146
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,688
| 950
|
Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).
|
def is_stable(oline, line):
for i in range(N):
for j in range(i+1, N):
for a in range(N):
for b in range(a+1, N):
if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
return False
return True
N = int(input())
line = input().split()
oline = line.copy()
for i in range(N):
for j in range(N-1, i, -1):
if int(line[j][1]) < int(line[j-1][1]):
tmp = line[j]
line[j] = line[j-1]
line[j-1] = tmp
print(' '.join(line))
print(('Not stabe', 'Stable')[is_stable(oline, line)])
#SelectionSort
line = oline.copy()
for i in range(N):
minj = i
for j in range(i+1, N):
if int(line[minj][1]) > int(line[j][1]):
minj = j
tmp = line[i]
line[i] = line[minj]
line[minj] = tmp
print(' '.join(line))
print(('Not stabe', 'Stable')[is_stable(oline, line)])
|
s421497204
|
Accepted
| 210
| 7,828
| 952
|
def is_stable(oline, line):
for i in range(N):
for j in range(i+1, N):
for a in range(N):
for b in range(a+1, N):
if (oline[i][1] == oline[j][1]) & (oline[i] == line[b]) & (oline[j] == line[a]):
return False
return True
N = int(input())
line = input().split()
oline = line.copy()
for i in range(N):
for j in range(N-1, i, -1):
if int(line[j][1]) < int(line[j-1][1]):
tmp = line[j]
line[j] = line[j-1]
line[j-1] = tmp
print(' '.join(line))
print(('Not stable', 'Stable')[is_stable(oline, line)])
#SelectionSort
line = oline.copy()
for i in range(N):
minj = i
for j in range(i+1, N):
if int(line[minj][1]) > int(line[j][1]):
minj = j
tmp = line[i]
line[i] = line[minj]
line[minj] = tmp
print(' '.join(line))
print(('Not stable', 'Stable')[is_stable(oline, line)])
|
s319348491
|
p03449
|
u353895424
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 498
|
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?
|
def genSumList(l):
n = len(l)
ret = []
for i in range(1,n+1):
tmp = 0
for j in range(i):
tmp += l[j]
ret.append(tmp)
return ret
n = int(input())
a = []
ans = []
for i in range(2):
a.append(list(map(int, input().split())))
sum1 = genSumList(a[0])
sum2 = genSumList(sorted(a[1]))
print(sum1)
print(sum2)
for i in range(n):
ans.append(sum1[i] + sum2[(i+1)*(-1)])
print(max(ans))
|
s691169051
|
Accepted
| 17
| 3,064
| 235
|
n = int(input())
a = []
for i in range(2):
a.append(list(map(int, input().split())))
l = []
for i in range(1,n):
l.append(sum(a[0][:i]) + sum(a[1][i-1:]))
if len(l) == 0:
print(a[0][0] + a[1][0])
exit()
print(max(l))
|
s254156792
|
p02389
|
u715278210
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,576
| 76
|
Write a program which calculates the area and perimeter of a given rectangle.
|
a,b = map(int, input().split())
hirosa = a*b
nagasa = 2*(a+b)
hirosa,nagasa
|
s766474937
|
Accepted
| 20
| 5,576
| 63
|
a,b = map(int, input().split())
x = a*b
y = 2*(a+b)
print(x,y)
|
s169071007
|
p03610
|
u733167185
| 2,000
| 262,144
|
Wrong Answer
| 55
| 3,828
| 87
|
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
|
s = input()
for i in range(len(s)):
if i % 2 == 0:
print(s[i])
|
s441144126
|
Accepted
| 18
| 3,188
| 46
|
s = input()
s = s[::2]
print(s)
|
s482388409
|
p02694
|
u003505857
| 2,000
| 1,048,576
|
Wrong Answer
| 30
| 9,160
| 92
|
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())
a = 100
ans = 0
while a <= x:
a = int(a * 1.01)
ans += 1
print(ans)
|
s109871595
|
Accepted
| 29
| 9,056
| 117
|
x = int(input())
money = 100
count = 0
while money < x:
money = (money * 101) // 100
count += 1
print(count)
|
s645495809
|
p03447
|
u798316285
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 54
|
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,a,b=[int(input()) for i in range(3)]
print((x-a)//b)
|
s309315284
|
Accepted
| 17
| 2,940
| 53
|
x,a,b=[int(input()) for i in range(3)]
print((x-a)%b)
|
s012896576
|
p02659
|
u127981515
| 2,000
| 1,048,576
|
Wrong Answer
| 21
| 9,164
| 58
|
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
A,B=input().split()
a=int(A)
b=float(B)
print(int(a*b/10))
|
s344144752
|
Accepted
| 26
| 10,068
| 87
|
from decimal import Decimal
A,B=input().split()
a=int(A)
b=Decimal(B)
print(int(a*b))
|
s595473668
|
p03408
|
u649558044
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 338
|
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
|
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
cnt_dict = {}
for si in s:
cnt_dict[si] = 0
for ti in t:
cnt_dict[ti] = 0
for si in s:
cnt_dict[si] += 1
for ti in t:
cnt_dict[ti] -= 1
score = 0
for cnt in cnt_dict.values():
if cnt > 0:
score += cnt
print(score)
|
s690558777
|
Accepted
| 18
| 3,064
| 286
|
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
cnt_dict = {}
for si in s:
cnt_dict[si] = 0
for ti in t:
cnt_dict[ti] = 0
for si in s:
cnt_dict[si] += 1
for ti in t:
cnt_dict[ti] -= 1
print(max(max(cnt_dict.values()), 0))
|
s373578057
|
p03997
|
u984730891
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,316
| 73
|
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)
|
s154911810
|
Accepted
| 17
| 2,940
| 78
|
a = int(input())
b = int(input())
h = int(input())
print(int((a + b) * h / 2))
|
s201420183
|
p03607
|
u921168761
| 2,000
| 262,144
|
Time Limit Exceeded
| 2,104
| 7,388
| 249
|
You are playing the following game with Joisino. * Initially, you have a blank sheet of paper. * Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times. * Then, you are asked a question: How many numbers are written on the sheet now? The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?
|
N = int(input())
A = []
for _ in range(N):
A.append(int(input()))
A.sort()
ans = 0
idx = 0
while idx < N:
sub = 0
while idx + sub < N and A[idx] == A[idx + sub]:
sub = sub + 1
if sub % 2 == 1:
ans = ans + 1
print(ans)
|
s769857950
|
Accepted
| 300
| 7,388
| 269
|
N = int(input())
A = []
for _ in range(N):
A.append(int(input()))
A.sort()
ans = 0
idx = 0
while idx < N:
sub = 0
while idx + sub < N and A[idx] == A[idx + sub]:
sub = sub + 1
if sub % 2 == 1:
ans = ans + 1
idx = idx + sub
print(ans)
|
s049923818
|
p04030
|
u126844573
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 87
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
s = input()
print(*[s[q] if s[q] != "B" else chr(0x08) for q in range(len(s))], sep="")
|
s864358678
|
Accepted
| 17
| 2,940
| 160
|
s, s_back = input(), ""
while "B" in s:
s = s.replace("1B", "").replace("0B", "")
if s_back == s:
break
s_back = s
print(s.replace("B", ""))
|
s801762751
|
p03713
|
u830054172
| 2,000
| 262,144
|
Wrong Answer
| 439
| 18,968
| 638
|
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
|
H, W = list(map(int, input().split()))
ans = []
for i in range(1, H+1):
area1 = W*i
area2 = (H-i)//2*W
area3 = (H-(H-i)//2)*W
area4 = (H-i)*(W//2)
area5 = (H-i)*(W-(W//2))
ans.append(max(area1, area2, area3)-min(area1, area2, area3))
ans.append(max(area1, area4, area5)-min(area1, area4, area5))
for i in range(1, W+1):
area1 = H*i
area2 = (W-i)//2*H
area3 = (W-(W-i)//2)*H
area4 = (W-i)*(H//2)
area5 = (W-i)*(H-(H//2))
ans.append(max(area1, area2, area3)-min(area1, area2, area3))
ans.append(max(area1, area4, area5)-min(area1, area4, area5))
print(min(ans))
|
s268663730
|
Accepted
| 477
| 18,928
| 842
|
H, W = list(map(int, input().split()))
ans = []
for i in range(1, H):
area1 = W*i
area2 = (H-i)//2*W
area3 = (H-(H-i)//2-i)*W
area4 = (H-i)*(W//2)
area5 = (H-i)*(W-(W//2))
if area1 != 0 or area2 != 0 or area3 !=0:
ans.append(max(area1, area2, area3)-min(area1, area2, area3))
if area1 != 0 or area4 != 0 or area5 !=0:
ans.append(max(area1, area4, area5)-min(area1, area4, area5))
for i in range(1, W):
area6 = H*i
area7 = (W-i)//2*H
area8 = (W-(W-i)//2-i)*H
area9 = (W-i)*(H//2)
area10 = (W-i)*(H-(H//2))
if area6 != 0 or area7 != 0 or area8 !=0:
ans.append(max(area6, area7, area8)-min(area6, area7, area8))
if area6 != 0 or area9 != 0 or area10 !=0:
ans.append(max(area6, area9, area10)-min(area6, area9, area10))
print(min(ans))
|
s434403955
|
p02841
|
u311636831
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 2,940
| 100
|
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
|
A,B=map(int,input().split())
C,D=map(int,input().split())
if(A==B):
print(0)
else:
print(1)
|
s020502698
|
Accepted
| 20
| 3,060
| 100
|
A,B=map(int,input().split())
C,D=map(int,input().split())
if(A==C):
print(0)
else:
print(1)
|
s106706628
|
p03943
|
u911575040
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 125
|
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=[]
a=list(map(int,input().split(' ')))
a.sort()
if a[0]+a[1]==a[2]:
print('YES')
elif a[0]+a[1]!=a[2]:
print('NO')
|
s262858794
|
Accepted
| 17
| 2,940
| 111
|
a, b, c = map(int, input().split())
if a == b + c or a + b == c or a + c == b:
print('Yes')
else:
print('No')
|
s957637120
|
p03693
|
u538956308
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 99
|
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r,g,b = map(int,input().split())
ans = r*100+g*10+b
if ans%4==0:
print("Yes")
else:
print("No")
|
s365784740
|
Accepted
| 17
| 2,940
| 105
|
r, g, b = map(int,input().split())
n = r*100+g*10+b
if n % 4 == 0:
print('YES')
else:
print('NO')
|
s136810538
|
p03814
|
u319690708
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,512
| 63
|
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`.
|
N = str(input())
a = N.find("a")
z = N.rfind("z")
print(z-a+1)
|
s145733891
|
Accepted
| 17
| 3,500
| 62
|
N = str(input())
a = N.find("A")
z = N.rfind("Z")
print(z-a+1)
|
s247762122
|
p03407
|
u693105608
| 2,000
| 262,144
|
Wrong Answer
| 28
| 9,020
| 96
|
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 = list(map(int, input().split()))
if (a+b) <= c:
print("Yes")
else:
print("No")
|
s689399355
|
Accepted
| 30
| 9,100
| 97
|
a, b, c = list(map(int, input().split()))
if c <= (a+b):
print("Yes")
else:
print("No")
|
s017548721
|
p03712
|
u787562674
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,316
| 309
|
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())
input_list = [[i for i in input()] for j in range(H)]
option = ["#"]*(W+2)
input_list.insert(0, option)
input_list.append(option)
for i in range(1, H+1):
input_list[i].insert(0, "#")
input_list[i].append("#")
for i in range(H+2):
print(" ".join(input_list[i]))
|
s262695589
|
Accepted
| 18
| 3,060
| 308
|
H, W = map(int, input().split())
input_list = [[i for i in input()] for j in range(H)]
option = ["#"]*(W+2)
input_list.insert(0, option)
input_list.append(option)
for i in range(1, H+1):
input_list[i].insert(0, "#")
input_list[i].append("#")
for i in range(H+2):
print("".join(input_list[i]))
|
s173315332
|
p03493
|
u004025573
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 47
|
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
A=list(map(int,input().split()))
print(sum(A))
|
s777902879
|
Accepted
| 17
| 2,940
| 53
|
A=int(input())
print(A//100+(A%100)//10+(A%100)%10)
|
s603102338
|
p03095
|
u537782349
| 2,000
| 1,048,576
|
Wrong Answer
| 31
| 3,956
| 102
|
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of **one or more** characters from the string without changing the order.
|
a = int(input())
b = list(input())
c = {}
for i in range(a):
if b[i] not in c:
c[b[i]] = 1
|
s959871878
|
Accepted
| 43
| 3,188
| 207
|
a = int(input())
b = input()
c = {}
for i in range(a):
if b[i] not in c:
c[b[i]] = 1
else:
c[b[i]] += 1
d = 1
for k in c.keys():
d = (d * (c[k] + 1)) % (10 ** 9 + 7)
print(d - 1)
|
s757377220
|
p03408
|
u265608204
| 2,000
| 262,144
|
Wrong Answer
| 247
| 12,624
| 449
|
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
|
from collections import Counter
import numpy as np
a = int(input())
a_list = []
b_list = []
for i in range(a):
a_list.append(input())
a_list.append('null')
b = int(input())
for i in range(b):
b_list.append(input())
a_count = Counter(a_list)
b_count = Counter(b_list)
a_list_no_overlap = set(a_list)
print(a_count)
point = []
for i in a_list_no_overlap:
point.append(a_count[i]-b_count[i])
point_max = np.argmax(point)
print(point_max)
|
s883246819
|
Accepted
| 147
| 12,504
| 441
|
from collections import Counter
import numpy as np
a = int(input())
a_list = []
b_list = []
for i in range(a):
a_list.append(input())
b = int(input())
for i in range(b):
b_list.append(input())
a_count = Counter(a_list)
b_count = Counter(b_list)
a_list_no_overlap = set(a_list)
point = []
for i in a_list_no_overlap:
point.append(a_count[i]-b_count[i])
point_max = max(point)
if point_max<0:
print(0)
else:
print(point_max)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.