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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s623121810
|
p03456
|
u169200126
| 2,000 | 262,144 |
Wrong Answer
| 21 | 9,100 | 203 |
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 = list(map(int, input().split()))
c = 10*a + b
d = math.floor(c/4 + 1)
square = [i * i for i in range(c) if i * i == c ]
if len(square) != 0 :
print('Yes')
else:
print('No')
|
s363997600
|
Accepted
| 28 | 9,112 | 222 |
import math
a, b = list(map(int, input().split()))
c = str(a) + str(b)
c = int(c)
d = math.floor(c/4 + 1)
square = [i * i for i in range(c) if i * i == c ]
if len(square) != 0 :
print('Yes')
else:
print('No')
|
s373446073
|
p03434
|
u040141413
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 171 |
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()))
a.sort(reverse=True)
p=0
q=0
for i in range(n):
if i%2==0:
p+=a[i]
else:
q+=a[i]
print(q-p)
|
s414279416
|
Accepted
| 17 | 3,060 | 171 |
n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
p=0
q=0
for i in range(n):
if i%2==0:
p+=a[i]
else:
q+=a[i]
print(p-q)
|
s139774750
|
p03860
|
u089142196
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 50 |
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
|
s=input().split()[1][0]
print("AtCode"+"Contest")
|
s416622644
|
Accepted
| 17 | 2,940 | 41 |
s=input().split()[1][0]
print("A"+s+"C")
|
s834164635
|
p03360
|
u583276018
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 125 |
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 = list(map(int, input().split()))
for i in range(int(input())):
b = a.pop(a.index(max(a)))
a.append(b**2)
print(sum(a))
|
s836627976
|
Accepted
| 17 | 3,064 | 124 |
a = list(map(int, input().split()))
for i in range(int(input())):
b = a.pop(a.index(max(a)))
a.append(b*2)
print(sum(a))
|
s954099989
|
p02612
|
u046466256
| 2,000 | 1,048,576 |
Wrong Answer
| 28 | 9,156 | 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)
|
s728486797
|
Accepted
| 31 | 9,016 | 82 |
N = int(input())
if (N % 1000 == 0):
print(0)
else:
print(1000 - N % 1000)
|
s944594000
|
p04012
|
u948524308
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 257 |
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
|
import sys
W = input()
alpha = ["a","b","c","d","e","f","g","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for num in alpha:
if W.count(num) %2 != 0:
print("No")
sys.exit()
print("yes")
|
s837975133
|
Accepted
| 17 | 2,940 | 145 |
w=input()
alpha="abcdefghijklmnopqrstuvwxyz"
for i in range(26):
if w.count(alpha[i])%2!=0:
print("No")
exit()
print("Yes")
|
s977552411
|
p02613
|
u661649266
| 2,000 | 1,048,576 |
Wrong Answer
| 146 | 16,332 | 336 |
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
P = [input() for i in range(N)]
ac = 0
wa = 0
tle = 0
re = 0
for item in P:
if item == "AC":
ac += 1
elif item == "WA":
wa += 1
elif item == "TLE":
tle += 1
else:
re += 1
print("AC × {}".format(ac))
print("WA × {}".format(wa))
print("TLE × {}".format(tle))
print("RE × {}".format(re))
|
s534166849
|
Accepted
| 145 | 16,332 | 332 |
N = int(input())
P = [input() for i in range(N)]
ac = 0
wa = 0
tle = 0
re = 0
for item in P:
if item == "AC":
ac += 1
elif item == "WA":
wa += 1
elif item == "TLE":
tle += 1
else:
re += 1
print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))
|
s595479090
|
p03478
|
u215286521
| 2,000 | 262,144 |
Wrong Answer
| 19 | 2,940 | 170 |
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
sum = 0
while(n > 0):
sum += n % 10
n /= 10
ans += sum
print(ans)
|
s308078781
|
Accepted
| 37 | 3,060 | 139 |
n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
if a <= sum(list(map(int, list(str(i))))) <= b:
ans += i
print(ans)
|
s687333668
|
p02972
|
u254871849
| 2,000 | 1,048,576 |
Wrong Answer
| 466 | 7,276 | 921 |
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
# 2019-11-15 14:12:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# from scipy.misc import comb # float
# import numpy as np
def main():
n, *a = [int(x) for x in sys.stdin.read().split()]
a = [None] + a
in_or_not = [0 for _ in range(n+1)]
for i in range(1, n+1):
count = 0
for j in range(2 * i, n+1, i):
count += in_or_not[j]
if a[i] == 1:
if count % 2 == 0:
in_or_not[i] = 1
else:
if count % 2 == 1:
in_or_not[i] = 1
print(in_or_not.count(1))
for i in range(1, n+1):
if in_or_not[i] == 1:
print(i, end=' ')
if __name__ == "__main__":
main()
|
s582107751
|
Accepted
| 224 | 13,220 | 459 |
import sys
n, *a = map(int, sys.stdin.read().split())
a = [None] + a
def main():
res = [0] * (n + 1)
chosen = []
for i in range(n, 0, -1):
tmp = sum(res[i*2:n+1:i]) & 1
if tmp ^ a[i]:
res[i] = 1
chosen.append(i)
if chosen:
m = len(chosen)
return [m], chosen[::-1]
else:
return [[0]]
if __name__ == '__main__':
ans = main()
for a in ans:
print(*a, sep=' ')
|
s735230666
|
p02747
|
u680851063
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 130 |
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.
|
a = input()
print(a)
if a == 'hi' or 'hihi' or 'hihihi' or 'hihihihi' or 'hihihihihi':
print('Yes')
else:
print('No')
|
s698390123
|
Accepted
| 17 | 2,940 | 137 |
a = input()
if a == 'hi' or a =='hihi' or a =='hihihi' or a =='hihihihi' or a =='hihihihihi':
print('Yes')
else:
print('No')
|
s015327399
|
p03251
|
u246343119
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 260 |
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()))
max_x = max(x)
min_y = min(y)
if Y-X >=1 and min_y - max_x >= 1 and max_x - Y >= 1 and min_y - X >= 1:
print('No War')
else:
print('War')
|
s711064899
|
Accepted
| 18 | 3,060 | 263 |
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
max_x = max(x)
min_y = min(y)
ans = 'War'
for z in range(X+1, Y+1):
if z > max_x and z <= min_y:
ans = 'No War'
break
print(ans)
|
s801709301
|
p03997
|
u395894569
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 55 |
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a,b,h=(int(input()) for i in range(3))
print((a+b)*h/2)
|
s342333161
|
Accepted
| 20 | 2,940 | 60 |
a,b,h=(int(input()) for i in range(3))
print(int((a+b)*h/2))
|
s998457888
|
p03659
|
u596276291
| 2,000 | 262,144 |
Wrong Answer
| 157 | 25,320 | 546 |
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
|
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 20
def main():
N = int(input())
a_list = list(map(int, input().split()))
total = sum(a_list)
dp1 = [0] * N
dp1[0] = a_list[0]
for i in range(1, N):
dp1[i] = a_list[i] + dp1[i - 1]
ans = INF
for i in range(N - 1):
ans = min(ans, abs(total - dp1[i]))
print(ans)
if __name__ == '__main__':
main()
|
s314119123
|
Accepted
| 147 | 25,836 | 909 |
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(input())
A = list(map(int, input().split()))
ans = INF
total = sum(A)
now = 0
for i in range(N - 1):
now += A[i]
ans = min(ans, abs((total - now) - now))
print(ans)
if __name__ == '__main__':
main()
|
s538740709
|
p02646
|
u902430070
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 9,172 | 142 |
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
|
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if b - a <= t*(w - v):
print("YES")
else:
print("NO")
|
s437694610
|
Accepted
| 24 | 9,172 | 195 |
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if w - v > 0:
print("NO")
else:
if abs(b - a) <= abs(t*(w - v)):
print("YES")
else:
print("NO")
|
s914038884
|
p02608
|
u892340697
| 2,000 | 1,048,576 |
Wrong Answer
| 135 | 9,720 | 643 |
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
|
import math
n = int(input())
ans = {}
for x in range(1,int(math.sqrt(n+1))+1):
for y in range(1, x+1):
for z in range(1, y+1):
print(x,y,z)
k = pow(x, 2) + pow(y, 2) + pow(z, 2) + x*y + x*z + y*z
if k >n:
break
if len(set([x,y,z])) == 3:
num = 6
elif len(set([x,y,z])) == 2:
num = 3
else:
num = 1
if not k in ans:
ans[k] = num
else:
ans[k] += num
for i in range(1, n+1):
if i in ans:
print(ans[i])
else:
print(0)
|
s347547462
|
Accepted
| 104 | 9,588 | 618 |
import math
n = int(input())
ans = {}
for x in range(1,int(math.sqrt(n+1))+1):
for y in range(1, x+1):
for z in range(1, y+1):
k = pow(x, 2) + pow(y, 2) + pow(z, 2) + x*y + x*z + y*z
if k >n:
break
if len(set([x,y,z])) == 3:
num = 6
elif len(set([x,y,z])) == 2:
num = 3
else:
num = 1
if not k in ans:
ans[k] = num
else:
ans[k] += num
for i in range(1, n+1):
if i in ans:
print(ans[i])
else:
print(0)
|
s527313078
|
p02417
|
u328199937
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,568 | 211 |
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
|
a = list(str(input()))
count = [0] * 26
for i in range(len(a)):
if 97 <= ord(a[i]) and ord(a[i]) < 123:
count[ord(a[i]) - 97] += 1
for i in range(26):
print(chr(i + 97) + ' : ' + str(count[i]))
|
s438191936
|
Accepted
| 20 | 5,584 | 458 |
import sys
def lower(word):
Word = ''
str = list(word)
for i in range(len(str)):
if str[i].isupper(): Word += str[i].lower()
else: Word += str[i]
return Word
a = []
for line in sys.stdin:
a.extend(list(line))
count = [0] * 26
for i in range(len(a)):
a[i] = lower(a[i])
if 97 <= ord(a[i]) and ord(a[i]) < 123:
count[ord(a[i]) - 97] += 1
for i in range(26):
print(chr(i + 97) + ' : ' + str(count[i]))
|
s295650081
|
p02659
|
u051613269
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 9,032 | 52 |
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
A,B = list(map(float,input().split()))
print(A*B//1)
|
s130895603
|
Accepted
| 26 | 10,052 | 105 |
import decimal
import math
A,B = input().split()
A = int(A)
B = decimal.Decimal(B)
print(math.floor(A*B))
|
s591784065
|
p03943
|
u615817983
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 105 |
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 = list(map(int, input().split()))
if a+b==c or a+c==b or b+c==a:
print('YES')
else:
print('NO')
|
s014285259
|
Accepted
| 17 | 2,940 | 105 |
a, b, c = list(map(int, input().split()))
if a+b==c or a+c==b or b+c==a:
print('Yes')
else:
print('No')
|
s751826870
|
p02237
|
u564464686
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,596 | 233 |
There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$. An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise. Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively.
|
n=int(input())
G=[[0 for i in range(n)]for j in range(n)]
u=[0 for i in range(n)]
for i in range(n):
A=input().split()
u[i]=int(A[0])
k=int(A[1])
for j in range(k):
x=int(A[j+2])-1
G[i][x]=1
print(G)
|
s013499847
|
Accepted
| 30 | 6,384 | 360 |
n=int(input())
G=[[0 for i in range(n)]for j in range(n)]
u=[0 for i in range(n)]
for i in range(n):
A=input().split()
u[i]=int(A[0])
k=int(A[1])
for j in range(k):
x=int(A[j+2])-1
G[i][x]=1
for i in range(n):
for j in range(n):
if j<n-1:
print(G[i][j],end=" ")
else:
print(G[i][j])
|
s432513321
|
p03387
|
u323626540
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 252 |
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
|
A, B, C = sorted(map(int, input().split()))
num = 0
if (C - B) % 2 == 0:
num+= (C - B) // 2
else:
num += 1 + (C - B + 1) // 2
C += 1
A += 1
if (C - A) % 2 == 0:
num += (C - A) // 2
else:
num += 1 + (C - A + 1) // 2
print(num)
|
s483974621
|
Accepted
| 18 | 3,064 | 502 |
A, B, C = sorted(map(int, input().split()))
def calculate(P, Q, R):
num = 0
if abs(P - Q) % 2 == 0:
num += abs(P - Q) // 2
else:
num += 1 + (abs(P - Q) + 1) // 2
P += 1
R += 1
if P - R >= 0:
if abs(P - R) % 2 == 0:
num += abs(P - R) // 2
else:
num += 1 + (abs(P - R) + 1) // 2
else:
num += abs(P - R)
return num
ans = min(calculate(C, B, A), calculate(C, A, B), calculate(B, A, C))
print(ans)
|
s332146434
|
p03545
|
u305018585
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 205 |
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
a, b, c, d = list( input())
op = ['+','-']
for i in op :
for j in op :
for k in op :
if eval( a+ i + b + j + c + k +d) == 7 :
print('a{}b{}c{}d == 7'.format( i, j, k))
exit()
|
s029529583
|
Accepted
| 17 | 3,060 | 215 |
a, b, c, d = list( input())
op = ['+','-']
for i in op :
for j in op :
for k in op :
if eval( a+ i + b + j + c + k +d) == 7 :
print('{}{}{}{}{}{}{}=7'.format( a,i, b,j,c,k,d))
exit()
|
s784170733
|
p03448
|
u294385082
| 2,000 | 262,144 |
Wrong Answer
| 47 | 3,060 | 239 |
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())
count = 0
for i in range(1,a+1):
for j in range(1,b+1):
for k in range(1,c+1):
if i*500 + j*100 + k*50 == x:
count += 1
print(count)
|
s871085626
|
Accepted
| 48 | 3,060 | 239 |
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(0,a+1):
for j in range(0,b+1):
for k in range(0,c+1):
if i*500 + j*100 + k*50 == x:
count += 1
print(count)
|
s859054887
|
p03852
|
u609061751
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 138 |
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
|
import sys
input = sys.stdin.readline
c = input()
v = ["a", "e", "i", "u", "o"]
if c in v:
print("vowel")
else:
print("consonant")
|
s284835174
|
Accepted
| 17 | 3,060 | 202 |
import sys
input = sys.stdin.readline
c = str(input()).rstrip()
v = ["a", "e", "i", "u", "o"]
if c == "a" or c == "e" or c == "i" or c == "u" or c == "o":
print("vowel")
else:
print("consonant")
|
s127656738
|
p02389
|
u050281953
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,420 | 70 |
Write a program which calculates the area and perimeter of a given rectangle.
|
a=input()
b,c =a.split()
print(int(b)*int(c))
print(int(b)*2+int(c)*2)
|
s642324770
|
Accepted
| 20 | 7,520 | 78 |
a=input()
b,c =a.split()
print(int(b)*int(c),end=" ")
print(int(b)*2+int(c)*2)
|
s001596038
|
p02743
|
u347203174
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 102 |
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
|
A, B, C = map(int, input().split())
if 4*A*B < (C- (A+B))**2:
print('yes')
else:
print('no')
|
s853532412
|
Accepted
| 18 | 2,940 | 125 |
A, B, C = map(int, input().split())
if (C - (A+B) >= 0) and (4*A*B < (C- (A+B))**2):
print('Yes')
else:
print('No')
|
s963184894
|
p03493
|
u282657760
| 2,000 | 262,144 |
Wrong Answer
| 20 | 2,940 | 77 |
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 = str(input())
b = 0
for i in range(3):
if a[i] == 1:
b += 1
print(b)
|
s561146616
|
Accepted
| 17 | 2,940 | 80 |
a = str(input())
b = 0
for i in range(3):
if a[i] == '1':
b += 1
print(b)
|
s267034452
|
p03682
|
u334712262
| 2,000 | 262,144 |
Wrong Answer
| 2,124 | 406,540 | 2,158 |
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
|
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
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
sys.setrecursionlimit(10000)
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
def Prim(g):
V = list(g.keys())
for v in g.values():
V.extend(list(v.keys()))
V = list(set(V))
key = {}
pred = {}
in_q = set(V)
for v in V:
key[v] = sys.maxsize
pred[v] = -1
key[V[0]] = 0
q = []
for v in V:
heapq.heappush(q, (key[v], v))
while q:
_, u = heapq.heappop(q)
for v in g[u].keys():
w = g[u][v]
if w < key[v]:
pred[v] = u
key[v] = w
heapq.heappush(q, (key[v], v))
return pred
@mt
def slv(N, XY):
g = defaultdict(dict)
for i in range(N):
for j in range(N):
if i == j:
continue
d = min(abs(XY[i][0] - XY[j][0]), abs(XY[i][1] - XY[j][1]))
g[i][j] = d
g[j][i] = d
# pprint(g)
d = Prim(g)
# print(d)
ans = 0
for v, u in d.items():
if u != -1:
# print(v, u, g[v][u])
ans += g[v][u]
return ans
def main():
N = read_int()
XY = [read_int_n() for _ in range(N)]
print(slv(N, XY))
if __name__ == '__main__':
main()
|
s084559164
|
Accepted
| 1,903 | 104,560 | 2,086 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
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
sys.setrecursionlimit(10000)
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
def Prim(g):
V = list(g.keys())
for v in g.values():
V.extend(list(v.keys()))
V = list(set(V))
used = set([])
q = []
heapq.heappush(q, (0, V[0]))
ret = 0
while q:
c, v = heapq.heappop(q)
if v in used:
continue
used.add(v)
ret += c
for u in g[v]:
heapq.heappush(q, (g[v][u], u))
return ret
@mt
def slv(N, XY):
g = defaultdict(dict)
V = [(i, x, y) for i, (x, y) in enumerate(XY)]
V.sort(key=lambda x: x[1])
for i in range(1, N):
v = V[i][0]
u = V[i-1][0]
d = min(abs(XY[v][0] - XY[u][0]), abs(XY[v][1] - XY[u][1]))
g[v][u] = d
g[u][v] = d
V.sort(key=lambda x: x[2])
for i in range(1, N):
v = V[i][0]
u = V[i-1][0]
d = min(abs(XY[v][0] - XY[u][0]), abs(XY[v][1] - XY[u][1]))
g[v][u] = d
g[u][v] = d
return Prim(g)
def main():
N = read_int()
XY = [read_int_n() for _ in range(N)]
print(slv(N, XY))
if __name__ == '__main__':
main()
|
s274189525
|
p02392
|
u838759969
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,652 | 247 |
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
|
inputStr = input()
numList = inputStr.split(' ')
numList = [int(x) for x in numList]
numList2 = numList.copy()
numList.sort()
print('numList: ',numList)
print('numList2: ', numList2)
if numList == numList2:
print('Yes')
else:
print('No')
|
s970275327
|
Accepted
| 50 | 7,668 | 301 |
inputStr = input()
numList = inputStr.split(' ')
numList = [int(x) for x in numList]
numList2 = numList.copy()
numList.sort()
numSet = set(numList)
#print('numList: ',numList)
#print('numList2: ', numList2)
if numList == numList2 and len(numList)==len(numSet):
print('Yes')
else:
print('No')
|
s910056629
|
p02612
|
u012484950
| 2,000 | 1,048,576 |
Wrong Answer
| 25 | 9,132 | 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.
|
# -*- coding: utf-8 -*-
n = int(input())
print(n % 1000)
|
s854208825
|
Accepted
| 27 | 9,084 | 110 |
# -*- coding: utf-8 -*-
n = int(input())
if (n % 1000 > 0):
print(1000 - (n % 1000))
else:
print(0)
|
s540891229
|
p03861
|
u451017206
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 49 |
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
|
a,b,x=map(int, input().split())
print((b-a+1)//x)
|
s125263977
|
Accepted
| 17 | 2,940 | 58 |
a, b, x = map(int, input().split())
print(b//x - (a-1)//x)
|
s773715792
|
p03673
|
u296150111
| 2,000 | 262,144 |
Wrong Answer
| 129 | 26,180 | 230 |
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
|
n=int(input())
a=list(map(int,input().split()))
b=[]
import math
for i in range(math.ceil(n/2)):
b.append(a[n-1-2*i])
if n%2==0:
for i in range(n//2):
b.append(a[2*i])
else:
for i in range(n//2):
b.append(a[2*i+1])
print(b)
|
s927413444
|
Accepted
| 194 | 26,180 | 231 |
n=int(input())
a=list(map(int,input().split()))
b=[]
import math
for i in range(math.ceil(n/2)):
b.append(a[n-1-2*i])
if n%2==0:
for i in range(n//2):
b.append(a[2*i])
else:
for i in range(n//2):
b.append(a[2*i+1])
print(*b)
|
s664743089
|
p03673
|
u716043626
| 2,000 | 262,144 |
Wrong Answer
| 2,104 | 26,180 | 146 |
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
|
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
tmp = a.pop(0)
b.append(tmp)
b = b[::-1]
print(b)
|
s916417546
|
Accepted
| 51 | 27,044 | 79 |
n = int(input())
a = list(input().split())
print(" ".join(a[::-2] + a[n%2::2]))
|
s205022678
|
p03738
|
u865383026
| 2,000 | 262,144 |
Wrong Answer
| 26 | 9,036 | 112 |
You are given two positive integers A and B. Compare the magnitudes of these numbers.
|
A = int(input())
B = int(input())
if A > B:
print('GRATER')
elif A < B:
print('LESS')
else:
print('EQUAL')
|
s335976000
|
Accepted
| 26 | 9,084 | 113 |
A = int(input())
B = int(input())
if A > B:
print('GREATER')
elif A < B:
print('LESS')
else:
print('EQUAL')
|
s358324084
|
p03351
|
u339503988
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 117 |
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d=map(int,input().split())
if abs(c-a)<d or (abs(b-a) < d and abs(c-b) < d):
print("Yes")
else:
print("No")
|
s233039667
|
Accepted
| 17 | 2,940 | 120 |
a,b,c,d=map(int,input().split())
if abs(c-a)<=d or (abs(b-a) <= d and abs(c-b) <= d):
print("Yes")
else:
print("No")
|
s517519458
|
p03693
|
u080986047
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 314 |
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?
|
x,y,z = map(int,input().split())
y %= 4
if y == 0:
if z % 4 ==0:
print("YES")
exit()
if y == 1:
if z % 4 == 2:
print("Yes")
exit()
if y == 2:
if z % 4 == 0:
print("Yes")
exit()
if y == 3:
if z % 4 == 2:
print("Yes")
exit()
print("No")
|
s479016920
|
Accepted
| 17 | 3,064 | 314 |
x,y,z = map(int,input().split())
y %= 4
if y == 0:
if z % 4 ==0:
print("YES")
exit()
if y == 1:
if z % 4 == 2:
print("YES")
exit()
if y == 2:
if z % 4 == 0:
print("YES")
exit()
if y == 3:
if z % 4 == 2:
print("YES")
exit()
print("NO")
|
s704290082
|
p03860
|
u243572357
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 28 |
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
|
print(input().split()[1][0])
|
s111326795
|
Accepted
| 17 | 2,940 | 54 |
a = input().split()
print(a[0][0] + a[1][0] + a[2][0])
|
s004608359
|
p03564
|
u371467115
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 101 |
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
|
n=int(input())
k=int(input())
s=1
for i in range(n):
if s*2<=k:
s=s*2
else:
s+=k
print(s)
|
s459767002
|
Accepted
| 18 | 2,940 | 105 |
n=int(input())
k=int(input())
s=1
for i in range(n):
if (s*2)-s<=k:
s=s*2
else:
s+=k
print(s)
|
s783311269
|
p02393
|
u907607057
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,600 | 199 |
Write a program which reads three integers, and prints them in ascending order.
|
import sys
def main():
input_str = sys.stdin.readline()
list1 = [int(i) for i in input_str.split(' ')]
list1.sort()
print(list1)
return
if __name__ == '__main__':
main()
|
s660294664
|
Accepted
| 20 | 5,604 | 230 |
import sys
def main():
input_str = sys.stdin.readline()
list1 = [int(i) for i in input_str.split(' ')]
list1.sort()
print('{0[0]} {0[1]} {0[2]}'.format(list1))
return
if __name__ == '__main__':
main()
|
s759434981
|
p02659
|
u605662776
| 2,000 | 1,048,576 |
Wrong Answer
| 33 | 10,004 | 72 |
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
from decimal import Decimal
a,b=input().split()
print(int(a)*Decimal(b))
|
s589516663
|
Accepted
| 32 | 9,876 | 77 |
from decimal import Decimal
a,b=input().split()
print(int(int(a)*Decimal(b)))
|
s994920396
|
p02842
|
u853010060
| 2,000 | 1,048,576 |
Wrong Answer
| 19 | 3,060 | 74 |
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
N = int(input())
if N%1.08 == 0:
print(N/1.08)
else:
print(":(")
|
s840167712
|
Accepted
| 17 | 2,940 | 136 |
N = int(input())
X = N//1.08
for n in range(10):
X += n
if int(X*1.08) == N:
print(int(X))
exit(0)
print(":(")
|
s187692740
|
p00002
|
u000317780
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,596 | 178 |
Write a program which computes the digit number of sum of two integers a and b.
|
# coding: utf-8
import sys
def main():
for line in sys.stdin:
ls = list(map(int, line.split(' ')))
print(ls[0]+ls[1])
if __name__ == '__main__':
main()
|
s103878717
|
Accepted
| 20 | 7,596 | 311 |
# coding: utf-8
import sys
def digit_check(n):
digit = 1
while int(n/(10**digit)) != 0:
digit += 1
return digit
def main():
for line in sys.stdin:
ls = list(map(int, line.split(' ')))
print(digit_check(ls[0]+ls[1]))
if __name__ == '__main__':
main()
|
s759310591
|
p02645
|
u652656291
| 2,000 | 1,048,576 |
Wrong Answer
| 27 | 8,864 | 25 |
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
s = input()
print(s[0:2])
|
s996168809
|
Accepted
| 27 | 8,968 | 51 |
s = input()
a = s[0]
b = s[1]
c = s[2]
print(a+b+c)
|
s073453040
|
p03478
|
u177411511
| 2,000 | 262,144 |
Wrong Answer
| 91 | 3,880 | 239 |
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
n, a, b = map(int, input().split())
result = 0
for i in range(1, n+1):
sum = 0
num = i
while num > 0:
sum += num % 10
num //= 10
print(i, num, sum)
if a <= sum <= b:
result += i
print(result)
|
s412257226
|
Accepted
| 56 | 5,148 | 395 |
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
n, a, b = na()
ct = 0
for i in range(1, n+1):
num = str(i)
s = 0
for j in range(len(num)):
s += int(num[j])
if a <= s <= b:
ct += i
print(ct)
|
s563505928
|
p03090
|
u994988729
| 2,000 | 1,048,576 |
Wrong Answer
| 27 | 3,996 | 585 |
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
n = int(input())
pairs = [[i for i in range(1, n + 1)] for _ in range(n)]
ans = []
if n % 2 == 0:
for i in range(n-1):
for j in range(i + 1, n):
x = pairs[i][j]
if x == i + 1 or x == n - i:
continue
ans.append((i + 1, x))
else:
for i in range(n-1):
for j in range(i + 1, n):
x = pairs[i][j]
if x == i + 1:
continue
if i != n - 1 and x == n - i:
continue
ans.append((i + 1, x))
print(len(ans))
for x, y in ans:
print(x, y)
|
s005757845
|
Accepted
| 25 | 3,956 | 470 |
N = int(input())
if N % 2 == 0:
edge = []
for s in range(1, N + 1):
ng = N - s + 1
for t in range(1, N + 1):
if s >= t or t == ng:
continue
edge.append((s, t))
else:
edge = []
for s in range(1, N + 1):
ng = N - s
for t in range(1, N + 1):
if s >= t or t == ng:
continue
edge.append((s, t))
print(len(edge))
for s, t in edge:
print(s, t)
|
s335463962
|
p02601
|
u393431864
| 2,000 | 1,048,576 |
Wrong Answer
| 32 | 9,172 | 196 |
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.
|
l = list(map(int,input().split()))
r, g, b = l[0], l[1], l[2]
k = int(input())
for _ in range(k):
if r >= g:
g *= 2
elif g >= b:
b *= 2
else:
print('Yes')
break
print('No')
|
s475668876
|
Accepted
| 27 | 9,208 | 206 |
l = list(map(int,input().split()))
r, g, b = l[0], l[1], l[2]
k = int(input())
for _ in range(k):
if r >= g:
g *= 2
elif g >= b:
b *= 2
if b > g and g > r:
print('Yes')
else:
print('No')
|
s528347343
|
p02388
|
u104931506
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,348 | 24 |
Write a program which calculates the cube of a given integer x.
|
print(2**3)
print(3**3)
|
s470327447
|
Accepted
| 50 | 7,588 | 28 |
x = int(input())
print(x**3)
|
s762836554
|
p02390
|
u597483031
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,584 | 168 |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
seconds=int(input())
hours=int(seconds/60)
minutes=int((seconds-hours*60)/60)
seconds=(seconds-hours*60-minutes*60)
print(str(hours)+":"+str(minutes)+":"+str(seconds))
|
s430529908
|
Accepted
| 20 | 5,588 | 174 |
seconds=int(input())
hours=int(seconds/3600)
minutes=int((seconds-hours*3600)/60)
seconds=(seconds-hours*3600-minutes*60)
print(str(hours)+":"+str(minutes)+":"+str(seconds))
|
s148255411
|
p03623
|
u928784113
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 126 |
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|.
|
# -*- coding: utf-8 -*-
x,a,b=map(int,input().split())
if abs(x-a) > abs(x-b):
print(b)
elif abs(x-a) < abs(x-b):
print(a)
|
s469107894
|
Accepted
| 17 | 2,940 | 130 |
# -*- coding: utf-8 -*-
x,a,b=map(int,input().split())
if abs(x-a) > abs(x-b):
print("B")
elif abs(x-a) < abs(x-b):
print("A")
|
s150433169
|
p02393
|
u602702913
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,644 | 56 |
Write a program which reads three integers, and prints them in ascending order.
|
l=list(map(int,input().split()))
list.sort(l)
print(l)
|
s702448606
|
Accepted
| 20 | 5,592 | 372 |
a,b,c=map(int,input().split())
if a<b<c:
print(a,b,c)
elif a<c<b:
print(a,c,b)
elif b<a<c:
print(b,a,c)
elif b<c<a:
print(b,c,a)
elif c<a<b:
print(c,a,b)
elif c<b<a:
print(c,b,a)
elif a==b<c:
print(a,b,c)
elif b==c<a:
print(b,c,a)
elif a==b>c:
print(c,a,b)
elif b==c>a:
print(a,b,c)
elif a==c<b:
print(a,c,b)
elif a==c>b:
print(b,a,c)
|
s220283722
|
p02418
|
u682153677
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,556 | 154 |
Write a program which finds a pattern $p$ in a ring shaped text $s$.
|
# -*- coding: utf-8 -*-
import sys
s = sys.stdin.readline().strip()
p = sys.stdin.readline().strip()
if p in s:
print('Yes')
else:
print('No')
|
s405579076
|
Accepted
| 20 | 5,560 | 162 |
# -*- coding: utf-8 -*-
import sys
s = sys.stdin.readline().strip()
p = sys.stdin.readline().strip()
s += s
if p in s:
print('Yes')
else:
print('No')
|
s558860711
|
p04029
|
u050708958
| 2,000 | 262,144 |
Wrong Answer
| 39 | 3,064 | 154 |
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?
|
s = list(input())
ans = ""
for i in s:
if i != "B":
ans += i
elif len(ans) < 1:
continue
else:
ans += "\b"
print(ans)
|
s579227035
|
Accepted
| 39 | 3,064 | 38 |
x = int(input())
print(int(x*(x+1)/2))
|
s193545596
|
p02409
|
u660912567
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,624 | 323 |
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.
|
house = [[[0]*10 for i in range(3)] for j in range(4)]
n = int(input())
for i in range(n):
data = list(map(int, input().split()))
house[data[0]-1][data[1]-1][data[2]-1] = data[3]
for i in range(4):
for j in range(3):
print('',' '.join(list(map(str,house[i][j]))))
print('####################')
|
s545292583
|
Accepted
| 30 | 7,748 | 333 |
house = [[[0]*10 for i in range(3)] for j in range(4)]
n = int(input())
for i in range(n):
data = list(map(int, input().split()))
house[data[0]-1][data[1]-1][data[2]-1] += data[3]
for i in range(4):
for j in range(3):
print('',' '.join(list(map(str,house[i][j]))))
if i!=3: print('####################')
|
s846495922
|
p02244
|
u426534722
| 1,000 | 131,072 |
Wrong Answer
| 70 | 6,352 | 1,429 |
The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure. For a given chess board where $k$ queens are already placed, find the solution of the 8 queens problem.
|
from copy import deepcopy, copy
class QueenMAP():
__slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]
def __init__(self):
self.yoko = set()
self.tate = set()
self.naname1 = set()
self.naname2 = set()
self.MAP = [["."] * 8 for _ in range(8)]
def add(self, y, x):
self.MAP[y][x] = "Q"
self.yoko.add(y)
self.tate.add(x)
self.naname1.add(y - x)
self.naname2.add(x + y)
def check(self, y, x):
if x in self.tate or (y - x) in self.naname1 or (x - y) in self.naname2:
return False
return True
def allcheck(self):
for i in range(8):
if not "Q" in self.MAP[i]:
return False
return True
def MAIN():
f = lambda M: "\n".join("".join(map(str, m)) for m in M)
QM = QueenMAP()
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
QM.add(a, b)
dp = [(deepcopy(QM), n)]
while dp:
Q, cnt = dp.pop()
if cnt == 8:
if Q.allcheck():
print(f(Q.MAP))
break
continue
cnt += 1
for i in range(8):
if i in Q.yoko:
continue
for j in range(8):
if Q.check(i, j):
CQ = deepcopy(Q)
CQ.add(i, j)
dp.append((CQ, cnt))
MAIN()
|
s096184926
|
Accepted
| 340 | 6,352 | 1,457 |
from itertools import product
from copy import deepcopy, copy
class QueenMAP():
__slots__ = ["yoko", "tate", "naname1", "naname2", "MAP"]
def __init__(self):
self.yoko = set()
self.tate = set()
self.naname1 = set()
self.naname2 = set()
self.MAP = [["."] * 8 for _ in range(8)]
def add(self, y, x):
self.MAP[y][x] = "Q"
self.yoko.add(y)
self.tate.add(x)
self.naname1.add(y - x)
self.naname2.add(x + y)
def check(self, y, x):
if y in self.yoko or x in self.tate or (y - x) in self.naname1 or (x + y) in self.naname2:
return False
return True
def allcheck(self):
for i in range(8):
if not "Q" in self.MAP[i]:
return False
return True
def show(self):
print("\n".join("".join(m) for m in self.MAP))
def MAIN():
f = lambda M: "\n".join("".join(m) for m in M)
QM = QueenMAP()
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
QM.add(a, b)
dp = [(deepcopy(QM), n)]
while dp:
Q, cnt = dp.pop()
if cnt == 8:
if Q.allcheck():
Q.show()
break
continue
cnt += 1
for i, j in product(range(8), repeat=2):
if Q.check(i, j):
CQ = deepcopy(Q)
CQ.add(i, j)
dp.append((CQ, cnt))
MAIN()
|
s316929949
|
p03493
|
u095015466
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 75 |
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
S = input()
ans = 0
for i in range(len(S)):
if S[i]==1: ans+=1
print(ans)
|
s750425230
|
Accepted
| 17 | 2,940 | 77 |
S = input()
ans = 0
for i in range(len(S)):
if S[i]=='1': ans+=1
print(ans)
|
s726836557
|
p02388
|
u316246166
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,516 | 18 |
Write a program which calculates the cube of a given integer x.
|
a = 3
print(a^3)
|
s675536247
|
Accepted
| 20 | 5,572 | 95 |
x = int(input())
print(x**3)
|
s367232260
|
p02844
|
u517327166
| 2,000 | 1,048,576 |
Wrong Answer
| 1,067 | 3,596 | 383 |
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
|
N=int(input())
S=int(input())
l_S=list(str(S))
count=0
for i in range(0,1000):
i_1=int(i/100)
i_2=int(i/10)-i_1*10
i_3=i%10
if str(i_1) in l_S[:-2]:
idx_1=l_S[:-2].index(str(i_1))
if str(i_2) in l_S[idx_1+1:-1]:
idx_2=l_S[idx_1+1:-1].index(str(i_2))+idx_1+1
if str(i_3) in l_S[idx_2+1:]:
count+=1
print(count)
|
s412750368
|
Accepted
| 1,068 | 3,600 | 378 |
N=int(input())
S=str(input())
l_S=list(S)
count=0
for i in range(0,1000):
i_1=int(i/100)
i_2=int(i/10)-i_1*10
i_3=i%10
if str(i_1) in l_S[:-2]:
idx_1=l_S[:-2].index(str(i_1))
if str(i_2) in l_S[idx_1+1:-1]:
idx_2=l_S[idx_1+1:-1].index(str(i_2))+idx_1+1
if str(i_3) in l_S[idx_2+1:]:
count+=1
print(count)
|
s248761028
|
p02390
|
u227984374
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,572 | 47 |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
S = int(input())
print(S//60,S%60//60,S%60%60)
|
s590328788
|
Accepted
| 20 | 5,580 | 67 |
x = int(input())
print(x // 3600, x // 60 % 60, x % 60, sep = ':')
|
s947056990
|
p03434
|
u019584841
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 126 |
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=[int(i) for i in input().split()]
b=sorted(a)
m=int((n+1)//2)
s=0
for i in range(m):
s+=b[2*i]
print(s)
|
s218171280
|
Accepted
| 17 | 2,940 | 152 |
N = int(input())
A = list(map(int, input().split(' ')))
revA = sorted(A, reverse=True)
alice = sum(revA[0::2])
bob = sum(revA[1::2])
print(alice - bob)
|
s195577432
|
p03998
|
u787456042
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 523 |
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
|
sa = input()
sb = input()
sc = input()
def func(x) :
global sa, sb, sc
if x == "a" :
if sa :
k = sa[0]
sa = sa[1:]
return func(k)
else :
return "A"
elif x == "b" :
if sb :
k = sb[0]
sb = sb[1:]
return func(k)
else :
return "B"
else :
if sc :
k = sc[0]
sc = sc[1:]
return func(k)
else :
return "C"
print(func("A"))
|
s322332919
|
Accepted
| 18 | 3,188 | 523 |
sa = input()
sb = input()
sc = input()
def func(x) :
global sa, sb, sc
if x == "a" :
if sa :
k = sa[0]
sa = sa[1:]
return func(k)
else :
return "A"
elif x == "b" :
if sb :
k = sb[0]
sb = sb[1:]
return func(k)
else :
return "B"
else :
if sc :
k = sc[0]
sc = sc[1:]
return func(k)
else :
return "C"
print(func("a"))
|
s047471692
|
p02409
|
u435917115
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,440 | 68 |
You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building.
|
data = [
[[] for f in range(3)] for b in range(4)
]
print(data)
|
s377028687
|
Accepted
| 30 | 7,740 | 372 |
data = [
[[0 for r in range(10)] for f in range(3)] for b in range(4)
]
count = int(input())
for c in range(count):
b, f, r, v = [int(i) for i in input().split()]
data[b-1][f-1][r-1] += v
for bi, b in enumerate(data):
for f in b:
for r in f:
print(' {0}'.format(r), end='')
print()
if bi < 3:
print('#' * 20)
|
s932106486
|
p02281
|
u498066648
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,632 | 3,200 |
Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
|
class Trees():
def __init__(self):
self.nodes = {}
def add_nodes(self, id):
if id not in self.nodes:
self.nodes[id] = Node(id)
def add_child(self, id, child_id1, child_id2):
for child_id in [child_id1, child_id2]:
if child_id != -1:
self.add_nodes(child_id)
self.nodes[id].add_child_id(self.nodes[child_id])
if child_id1 != -1:
self.nodes[child_id1].sibling = child_id2
if child_id2 != -1:
self.nodes[child_id2].sibling = child_id1
self.nodes[id].left = child_id1
self.nodes[id].right = child_id2
def setheight(self, id):
h1, h2 = 0, 0
if self.nodes[id].right != -1:
h1 = self.setheight(self.nodes[id].right) + 1
if self.nodes[id].left != -1:
h2 = self.setheight(self.nodes[id].left) + 1
self.nodes[id].height = max(h1, h2)
return max(h1, h2)
def preorder(self,u):
if u == -1:
return
print(f' {u}', end='')
self.preorder(self.nodes[u].left)
self.preorder(self.nodes[u].right)
def inorder(self,u):
if u == -1:
return
self.inorder(self.nodes[u].left)
print(f' {u}', end='')
self.inorder(self.nodes[u].right)
def postorder(self,u):
if u == -1:
return
self.postorder(self.nodes[u].left)
self.postorder(self.nodes[u].right)
print(f' {u}', end='')
class Node():
def __init__(self, id):
self.node = id
self.parent = None
self.depth = 0
self.nodetype = 'root'
self.children = []
self.sibling = -1
self.degree = 0
self.height = 0
self.left = -1
self.right = -1
def add_child_id(self, child):
child.parent = self
self.children.append(child)
child.update_depth()
self.update_nodetype()
child.update_nodetype()
self.degree += 1
def update_depth(self):
depth = self.depth
if self.parent:
self.depth = self.parent.depth + 1
if depth != self.depth:
for child in self.children:
child.update_depth()
def update_nodetype(self):
if self.depth == 0:
self.nodetype = 'root'
elif len(self.children) > 0:
self.nodetype = 'internal node'
else:
self.nodetype = 'leaf'
def __str__(self):
parent = self.parent.node if self.parent else -1
return 'node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(
self.node, parent, self.sibling, self.degree, self.depth, self.height, self.nodetype)
tree = Trees()
n = int(input())
for i in range(n):
a = list(map(int,input().split()))
tree.add_nodes(a[0])
tree.add_child(id=a[0], child_id1=a[1], child_id2=a[2])
for id in range(n):
tree.setheight(id)
print('Preorder')
tree.preorder(0)
print()
print('Inorder')
tree.inorder(0)
print()
print('Postorder')
tree.postorder(0)
|
s301368618
|
Accepted
| 20 | 5,672 | 3,390 |
class Trees():
def __init__(self):
self.nodes = {}
def add_nodes(self, id):
if id not in self.nodes:
self.nodes[id] = Node(id)
def add_child(self, id, child_id1, child_id2):
for child_id in [child_id1, child_id2]:
if child_id != -1:
self.add_nodes(child_id)
self.nodes[id].add_child_id(self.nodes[child_id])
if child_id1 != -1:
self.nodes[child_id1].sibling = child_id2
if child_id2 != -1:
self.nodes[child_id2].sibling = child_id1
self.nodes[id].left = child_id1
self.nodes[id].right = child_id2
def setheight(self, id):
h1, h2 = 0, 0
if self.nodes[id].right != -1:
h1 = self.setheight(self.nodes[id].right) + 1
if self.nodes[id].left != -1:
h2 = self.setheight(self.nodes[id].left) + 1
self.nodes[id].height = max(h1, h2)
return max(h1, h2)
def preorder(self,u):
if u == -1:
return
print(f' {u}', end='')
self.preorder(self.nodes[u].left)
self.preorder(self.nodes[u].right)
def inorder(self,u):
if u == -1:
return
self.inorder(self.nodes[u].left)
print(f' {u}', end='')
self.inorder(self.nodes[u].right)
def postorder(self,u):
if u == -1:
return
self.postorder(self.nodes[u].left)
self.postorder(self.nodes[u].right)
print(f' {u}', end='')
class Node():
def __init__(self, id):
self.node = id
self.parent = None
self.depth = 0
self.nodetype = 'root'
self.children = []
self.sibling = -1
self.degree = 0
self.height = 0
self.left = -1
self.right = -1
def add_child_id(self, child):
child.parent = self
self.children.append(child)
child.update_depth()
self.update_nodetype()
child.update_nodetype()
self.degree += 1
def update_depth(self):
depth = self.depth
if self.parent:
self.depth = self.parent.depth + 1
if depth != self.depth:
for child in self.children:
child.update_depth()
def update_nodetype(self):
if self.depth == 0:
self.nodetype = 'root'
elif len(self.children) > 0:
self.nodetype = 'internal node'
else:
self.nodetype = 'leaf'
def __str__(self):
parent = self.parent.node if self.parent else -1
return 'node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(
self.node, parent, self.sibling, self.degree, self.depth, self.height, self.nodetype)
tree = Trees()
n = int(input())
top = [0 for _ in range(n)]
for i in range(n):
a = list(map(int,input().split()))
tree.add_nodes(a[0])
tree.add_child(id=a[0], child_id1=a[1], child_id2=a[2])
if a[1] != -1:
top[a[1]] += 1
if a[2] != -1:
top[a[2]] += 1
for id in range(n):
tree.setheight(id)
for i in range(n):
if top[i] == 0:
b = i
break
print('Preorder')
tree.preorder(b)
print()
print('Inorder')
tree.inorder(b)
print()
print('Postorder')
tree.postorder(b)
print()
|
s528917968
|
p03852
|
u800258529
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 62 |
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: `a`, `e`, `i`, `o` and `u`.
|
print(['onsonant','vowelc'][input() in ['a','i','u','e','o']])
|
s085487146
|
Accepted
| 17 | 2,940 | 62 |
print(['consonant','vowel'][input() in ['a','i','u','e','o']])
|
s050619955
|
p02678
|
u688219499
| 2,000 | 1,048,576 |
Wrong Answer
| 717 | 35,656 | 737 |
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
|
from collections import deque
def bfn():
q=deque([0])
visit[0]=True
while q:
room_proper=q.popleft()
for i in graph[room_proper]:
if visit[i]==False:
visit[i]=True
shirube[i]=room_proper
q.append(i)
if __name__ == "__main__":
n,m=map(int,input().split())
shirube=[0]*n
b=[]
visit=[False]*n
graph=[[]*n for _ in range(n)]
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
graph[a].append(b)
graph[b].append(a)
bfn()
print(visit)
if all(visit)==True:
print("Yes")
for i in range(1,n):
print(shirube[i]+1)
else:
print("No")
|
s281033154
|
Accepted
| 752 | 34,764 | 721 |
from collections import deque
def bfn():
q=deque([0])
visit[0]=True
while q:
room_proper=q.popleft()
for i in graph[room_proper]:
if visit[i]==False:
visit[i]=True
shirube[i]=room_proper
q.append(i)
if __name__ == "__main__":
n,m=map(int,input().split())
shirube=[0]*n
b=[]
visit=[False]*n
graph=[[]*n for _ in range(n)]
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
graph[a].append(b)
graph[b].append(a)
bfn()
if all(visit)==True:
print("Yes")
for i in range(1,n):
print(shirube[i]+1)
else:
print("No")
|
s758590673
|
p02612
|
u068862829
| 2,000 | 1,048,576 |
Wrong Answer
| 31 | 9,132 | 56 |
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())
while(N>=1000):
N -= 1000
print(N)
|
s441074653
|
Accepted
| 31 | 9,148 | 62 |
N = int(input())
while(N>1000):
N -= 1000
print(1000 - N)
|
s561287616
|
p03473
|
u144980750
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 22 |
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
|
print(24-int(input()))
|
s996098159
|
Accepted
| 17 | 2,940 | 22 |
print(48-int(input()))
|
s473487612
|
p03964
|
u077291787
| 2,000 | 262,144 |
Wrong Answer
| 22 | 3,444 | 406 |
AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i. It is known that each candidate had at least one vote when he checked the report for the first time. Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time. It can be assumed that the number of votes obtained by each candidate never decreases.
|
from math import ceil
def main():
n = int(input())
arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
t, a = arr[0]
for i, j in arr[1:]:
r = max(ceil(t / i), ceil(a / j))
t, a = i * r, j * r
print(t, a)
print(t + a)
if __name__ == "__main__":
main()
|
s187162066
|
Accepted
| 20 | 3,060 | 366 |
def main():
n = int(input())
arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
t, a = 1, 1
for i, j in arr:
r = max((t - 1) // i + 1, (a - 1) // j + 1)
t, a = i * r, j * r
print(t + a)
if __name__ == "__main__":
main()
|
s324939413
|
p03778
|
u142693157
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 122 |
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
|
w, a, b = map(int, input().split())
if a + w < b:
ans = b - (a + w)
elif a > b + w:
ans = a - (b + w)
else:
ans = 0
|
s325093407
|
Accepted
| 17 | 3,060 | 136 |
w, a, b = map(int, input().split())
if a + w < b:
ans = b - (a + w)
elif a > b + w:
ans = a - (b + w)
else:
ans = 0
print(ans)
|
s301033140
|
p03546
|
u540761833
| 2,000 | 262,144 |
Wrong Answer
| 31 | 3,188 | 937 |
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
|
H,W = map(int,input().split())
c = []
dicta = {}
dicta[-1] = 0
for i in range(10):
c.append(list(map(int,input().split())))
dicta[i] = 0
c = [i for i in zip(*c)]
for i in range(H):
a = list(map(int,input().split()))
for i in a:
dicta[i] += 1
dicta.pop(-1)
cost = [0 for i in range(10)]
def dijkstra_heap(start,node,cost):
import heapq
d = [float('inf') for i in range(node)]
used = [False for i in range(node)]
d[start] = 0
d2 = [[0,start]]
heapq.heapify(d2)
while True:
flag = True
while d2:
c,v = heapq.heappop(d2)
flag = False
if flag:
break
used[v] = True
for j in range(node):
d[j] = min(d[j],d[v]+cost[v][j])
if not used[j]:
heapq.heappush(d2,[d[j],j])
return d
cost = dijkstra_heap(1,10,c)
ans = 0
for k,v in dicta.items():
ans += v*cost[k]
print(ans)
|
s066592301
|
Accepted
| 30 | 3,188 | 817 |
H,W = map(int,input().split())
c = []
dicta = {}
dicta[-1] = 0
for i in range(10):
c.append(list(map(int,input().split())))
dicta[i] = 0
c = [i for i in zip(*c)]
for i in range(H):
a = list(map(int,input().split()))
for i in a:
dicta[i] += 1
dicta.pop(-1)
cost = [0 for i in range(10)]
def dijkstra_heap(start,node,cost):
import heapq
d = [float('inf') for i in range(node)]
d[start] = 0
d2 = [[0,start]]
heapq.heapify(d2)
while d2:
c,v = heapq.heappop(d2)
if d[v] < c:
continue
for j in range(node):
if d[j] > d[v]+cost[v][j]:
d[j] = d[v]+cost[v][j]
heapq.heappush(d2,[d[j],j])
return d
cost = dijkstra_heap(1,10,c)
ans = 0
for k,v in dicta.items():
ans += v*cost[k]
print(ans)
|
s409484520
|
p03997
|
u937238023
| 2,000 | 262,144 |
Wrong Answer
| 29 | 9,052 | 69 |
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)
|
s891829514
|
Accepted
| 26 | 8,972 | 71 |
a = int(input())
b = int(input())
h = int(input())
print(((a+b)*h)//2)
|
s262701592
|
p03779
|
u969190727
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 43 |
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0. During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i. The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X.
|
print(int((2*int(input())+1/4)**0.5-1/2)+1)
|
s402249881
|
Accepted
| 150 | 12,500 | 66 |
import numpy
print(int(numpy.ceil((2*int(input())+1/4)**0.5-1/2)))
|
s014941305
|
p02281
|
u357267874
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,604 | 1,021 |
Binary trees are defined recursively. A binary tree _T_ is a structure defined on a finite set of nodes that either * contains no nodes, or * is composed of three disjoint sets of nodes: \- a root node. \- a binary tree called its left subtree. \- a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: 1. Print the root, the left subtree and right subtree (preorder). 2. Print the left subtree, the root and right subtree (inorder). 3. Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1.
|
class Node:
def __init__(self, id):
self.id = id
self.left = None
self.right = None
root = None
n = int(input())
node_list = []
for i in range(n):
node_list.append(Node(i))
for i in range(n):
id, left, right = list(map(int, input().split()))
node = node_list[id]
if left > -1:
node.left = node_list[left]
if right > -1:
node.right = node_list[right]
if id == 0:
root = node
def preorder(node):
if node is None:
return
print(' ' + str(node.id), end='')
preorder(node.left)
preorder(node.right)
def inorder(node):
if node is None:
return
inorder(node.left)
print(' ' + str(node.id), end='')
inorder(node.right)
def postorder(node):
if node is None:
return
print(' ' + str(node.id), end='')
postorder(node.left)
postorder(node.right)
print('Preorder')
preorder(root)
print('')
print('Inorder')
inorder(root)
print('')
print('Postorder')
postorder(root)
print('')
|
s547774364
|
Accepted
| 20 | 5,616 | 1,182 |
class Node:
def __init__(self, id):
self.id = id
self.parent = None
self.left = None
self.right = None
root = None
n = int(input())
node_list = []
for i in range(n):
node_list.append(Node(i))
for i in range(n):
id, left, right = list(map(int, input().split()))
node = node_list[id]
if left > -1:
node_list[left].parent = node
node.left = node_list[left]
if right > -1:
node_list[right].parent = node
node.right = node_list[right]
root = None
for node in node_list:
if node.parent is None:
root = node
break
def preorder(node):
if node is None:
return
print(' ' + str(node.id), end='')
preorder(node.left)
preorder(node.right)
def inorder(node):
if node is None:
return
inorder(node.left)
print(' ' + str(node.id), end='')
inorder(node.right)
def postorder(node):
if node is None:
return
postorder(node.left)
postorder(node.right)
print(' ' + str(node.id), end='')
print('Preorder')
preorder(root)
print('')
print('Inorder')
inorder(root)
print('')
print('Postorder')
postorder(root)
print('')
|
s452125619
|
p04029
|
u205561862
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 40 |
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((lambda x:x* ~-x/2)(int(input())))
|
s076515762
|
Accepted
| 17 | 2,940 | 51 |
print(sum([int(i) for i in range(int(input())+1)]))
|
s724390081
|
p03471
|
u735069283
| 2,000 | 262,144 |
Wrong Answer
| 734 | 3,060 | 227 |
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.
|
N,Y = map(int,input().split())
hantei = 0
for i in range(N+1):
for j in range(N-i+1):
if Y==i*10000+j*5000+(N-i-j)*1000 and N-i-j>=0:
print(i,j,N-i-j)
hantei +=1
break
if hantei == 0:
print('-1 -1 -1')
|
s570850093
|
Accepted
| 749 | 3,064 | 250 |
N,Y = map(int,input().split())
hantei = 0
for i in range(N+1):
for j in range(N-i+1):
if Y==i*10000+j*5000+(N-i-j)*1000 and N-i-j>=0:
ans=[i,j,N-i-j]
hantei +=1
if hantei == 0:
print('-1 -1 -1')
else:
print(ans[0],ans[1],ans[2])
|
s364180831
|
p04029
|
u250944591
| 2,000 | 262,144 |
Wrong Answer
| 26 | 9,080 | 55 |
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
n=int(input())
a=0
for i in range(n+1):
a+=n
print(a)
|
s393921164
|
Accepted
| 26 | 9,036 | 55 |
n=int(input())
a=0
for i in range(n+1):
a+=i
print(a)
|
s251074741
|
p03844
|
u898058223
| 2,000 | 262,144 |
Wrong Answer
| 25 | 8,996 | 17 |
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her.
|
s=input()
eval(s)
|
s206728703
|
Accepted
| 25 | 9,084 | 24 |
s=input()
print(eval(s))
|
s193348430
|
p02600
|
u885315507
| 2,000 | 1,048,576 |
Wrong Answer
| 33 | 9,188 | 336 |
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a _kyu_ (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 through 1199: 5-kyu * From 1200 through 1399: 4-kyu * From 1400 through 1599: 3-kyu * From 1600 through 1799: 2-kyu * From 1800 through 1999: 1-kyu What kyu does M-kun have?
|
X = int(input())
if 400 <= X <= 599:
print("'8'")
elif 600 <= X <= 799:
print("'7'")
elif 800 <= X <= 999:
print("'6'")
elif 1000 <= X <= 1199:
print("'5'")
elif 1200 <= X <= 1399:
print("'4'")
elif 1400 <= X <= 1599:
print("'3'")
elif 1600 <= X <= 1799:
print("'2'")
elif 1800 <= X <= 1999:
print("'1'")
|
s330845244
|
Accepted
| 30 | 9,140 | 320 |
X = int(input())
if 400 <= X <= 599:
print("8")
elif 600 <= X <= 799:
print("7")
elif 800 <= X <= 999:
print("6")
elif 1000 <= X <= 1199:
print("5")
elif 1200 <= X <= 1399:
print("4")
elif 1400 <= X <= 1599:
print("3")
elif 1600 <= X <= 1799:
print("2")
elif 1800 <= X <= 1999:
print("1")
|
s739531778
|
p03477
|
u364541509
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 152 |
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R. Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan. Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.
|
A, B, C, D = map(int, input().split())
if A + B >> C + D:
print('Left')
elif A + B == C + D:
print('Balanced')
elif A + B << C + D:
print('Right')
|
s424636842
|
Accepted
| 17 | 2,940 | 150 |
A, B, C, D = map(int, input().split())
if A + B > C + D:
print('Left')
elif A + B == C + D:
print('Balanced')
elif A + B < C + D:
print('Right')
|
s571921291
|
p03478
|
u725107050
| 2,000 | 262,144 |
Wrong Answer
| 33 | 2,940 | 214 |
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
|
N,A,B = map(int, input().split())
result_cnt = 0
for i in range(N):
sum_digit = sum(map(int, list(str(i))))
if (sum_digit >= A) & (sum_digit <= B):
result_cnt += sum_digit
print(result_cnt)
|
s625674847
|
Accepted
| 35 | 2,940 | 213 |
N,A,B = map(int, input().split())
result_cnt = 0
for i in range(1, N + 1):
sum_digit = sum(map(int, list(str(i))))
if (sum_digit >= A) & (sum_digit <= B):
result_cnt += i
print(result_cnt)
|
s421952669
|
p02659
|
u106095117
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 9,104 | 110 |
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
A, B = map(str, input().split())
A = int(A)
B = 100 * int(B[0]) + 10 * int(B[2]) + 1 * int(B[3])
print(A * B)
|
s843758451
|
Accepted
| 35 | 10,064 | 102 |
import decimal
a, b = input().split()
a = decimal.Decimal(a)
b = decimal.Decimal(b)
print(int(a * b))
|
s419941843
|
p02678
|
u433371341
| 2,000 | 1,048,576 |
Wrong Answer
| 2,209 | 107,880 | 1,089 |
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 = [int(n) for n in input().split()]
# node:connected
graph = {node:set() for node in range(1,N+1)}
for _ in range(M):
A, B = [int(n) for n in input().split()]
graph[A].add(B)
graph[B].add(A)
to_visit = set(range(2,N+1))
current_level = {1}
to_visit = to_visit - current_level
level = 0
levels = {0:{1}}
seen = {1}
while to_visit:
level += 1
next_level = set()
for i in current_level:
next_level = next_level.union(graph[i] & to_visit)
levels[level] = next_level
current_level = next_level
to_visit = to_visit - current_level
prevs = {}
for level in reversed(range(1,len(levels))):
for node in levels[level]:
prevs[node] = set()
for nbr in graph[node]:
if nbr in levels[level-1]:
prevs[node].add(nbr)
# print(prevs)
posts = {1:1}
for level in range(1,len(levels)):
for node in levels[level]:
for prev in prevs[node]:
if prev in posts:
posts[node] = prev
break
# print(posts)
for i in range(2, N+1):
print(posts[i])
|
s500623953
|
Accepted
| 910 | 90,536 | 753 |
N, M = [int(n) for n in input().split()]
# node:connected
graph = {node:set() for node in range(1,N+1)}
for _ in range(M):
A, B = [int(n) for n in input().split()]
graph[A].add(B)
graph[B].add(A)
to_visit = set(range(2,N+1))
level = 0
posts = {}
while to_visit:
# base
if level == 0:
levels = {0:{1:None}}
current_level = {1}
# loop
else:
prevs = levels[level-1]
levels[level] = {}
for prev in prevs:
for nbr in graph[prev]:
if nbr in to_visit:
levels[level][nbr] = prev
posts[nbr] = prev
to_visit.remove(nbr)
level += 1
print('Yes')
for i in range(2,N+1):
print(posts[i])
|
s124686927
|
p02315
|
u255317651
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,600 | 557 |
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi. You want to find a subset of items to put such that: * The total value of the items is as large as possible. * The items have combined weight at most W, that is capacity of the knapsack. Find the maximum total value of items in the knapsack.
|
n, w = list(map(int,input().split()))
things=[]
for i in range(n):
thing = list(map(int, input().split()))
things.append(thing)
print(n, w)
print(things)
#n=6
#w=8
#things = [[2,3],[1,2],[3,6],[2,1],[1,3],[5,85]]
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
# for j in range(w+1):
# dp[i][j]=0
for i in range(n):
for j in range(w+1):
if things[i][1] <= j:
dp[i+1][j] = max(dp[i][j-things[i][1]]+things[i][0],dp[i][j])
else:
dp[i+1][j] = dp[i][j]
print(dp[n][w])
|
s514852873
|
Accepted
| 980 | 23,972 | 633 |
# -*- coding: utf-8 -*-
"""
Created on Fri May 25 22:23:44 2018
Knapsack by memorized recursive call
@author: maezawa
"""
n, maxw = list(map(int, input().split()))
w = []
v = []
dp = [[None for _ in range(maxw+1)] for _ in range(n)]
for i in range(n):
i, j = list(map(int, input().split()))
v.append(i)
w.append(j)
def total_value(i, wi):
if i == n:
return 0
if dp[i][wi] != None:
return dp[i][wi]
if wi < w[i]:
dp[i][wi] = total_value(i+1,wi)
else:
dp[i][wi] = max(total_value(i+1,wi), total_value(i+1,wi-w[i])+v[i])
return dp[i][wi]
print(total_value(0, maxw))
|
s411461057
|
p03556
|
u095969144
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 43 |
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
|
n = int(input())
print(int((n ** 0.5)**2))
|
s321330816
|
Accepted
| 17 | 3,060 | 41 |
n = int(input())
print(int(n ** 0.5)**2)
|
s912930991
|
p03131
|
u201856486
| 2,000 | 1,048,576 |
Wrong Answer
| 56 | 4,024 | 5,558 |
Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: * Hit his pocket, which magically increases the number of biscuits by one. * Exchange A biscuits to 1 yen. * Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations.
|
# coding: utf-8
import sys
import collections
# import math
# import numpy as np
"""Template"""
class IP:
def __init__(self):
self.input = sys.stdin.readline
def I(self):
return int(self.input())
def S(self):
return self.input()
def IL(self):
return list(map(int, self.input().split()))
def SL(self):
return list(map(str, self.input().split()))
def ILS(self, n):
return [int(self.input()) for _ in range(n)]
def SLS(self, n):
return [self.input() for _ in range(n)]
def SILS(self, n):
return [self.IL() for _ in range(n)]
def SSLS(self, n):
return [self.SL() for _ in range(n)]
class Idea:
def __init__(self):
pass
def HF(self, p):
return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))
def Bfs2(self, a):
# https://blog.rossywhite.com/2018/08/06/bit-search/
value = []
for i in range(1 << len(a)):
output = []
for j in range(len(a)):
if self.bit_o(i, j):
# output.append(a[j])
output.append(a[j])
value.append([format(i, 'b').zfill(16), sum(output)])
value.sort(key=lambda x: x[1])
bin = [value[k][0] for k in range(len(value))]
val = [value[k][1] for k in range(len(value))]
return bin, val
def S(self, s, r=0, m=-1):
r = bool(r)
if m == -1:
s.sort(reverse=r)
else:
s.sort(reverse=r, key=lambda x: x[m])
def bit_n(self, a, b):
return bool((a >> b & 1) > 0)
def bit_o(self, a, b):
return bool(((a >> b) & 1) == 1)
def ceil(self, x, y):
return -(-x//y)
def ave(self, a):
return sum(a) / len(a)
def main():
r, e = range, enumerate
ip = IP()
id = Idea()
k, a, b = ip.IL()
n = 1
m = 0
i = 0
if a >= b - 2:
print(1 + k)
else:
p = a + 2
num = (k - (a - 1)) // p
pp = (b - a) * num
print(p)
print(pp)
print(num)
i = a + 1
n = b
n += pp
i += num * p
print(n, i)
while i < k:
print(i)
if m >= 1:
n += b * m
m = 0
print("4だよ", n, m)
elif i == k - 1:
n += 1
print("最後だよ", n, m)
elif a > n:
print(n)
u = a - n
n += u
i += u - 1
print("1だよ", n, m)
elif a <= n:
u = n // a
n -= u * a
m += u
i += u
print(u)
print("2だよ", n, m)
else:
n += 1
print("3だよ", n, m)
i += 1
print(n)
main()
|
s020349638
|
Accepted
| 19 | 3,192 | 4,595 |
# coding: utf-8
import sys
# import math
# import numpy as np
"""Template"""
class IP:
def __init__(self):
self.input = sys.stdin.readline
def I(self):
return int(self.input())
def S(self):
return self.input()
def IL(self):
return list(map(int, self.input().split()))
def SL(self):
return list(map(str, self.input().split()))
def ILS(self, n):
return [int(self.input()) for _ in range(n)]
def SLS(self, n):
return [self.input() for _ in range(n)]
def SILS(self, n):
return [self.IL() for _ in range(n)]
def SSLS(self, n):
return [self.SL() for _ in range(n)]
class Idea:
def __init__(self):
pass
def HF(self, p):
return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))
def Bfs2(self, a):
# https://blog.rossywhite.com/2018/08/06/bit-search/
value = []
for i in range(1 << len(a)):
output = []
for j in range(len(a)):
if self.bit_o(i, j):
# output.append(a[j])
output.append(a[j])
value.append([format(i, 'b').zfill(16), sum(output)])
value.sort(key=lambda x: x[1])
bin = [value[k][0] for k in range(len(value))]
val = [value[k][1] for k in range(len(value))]
return bin, val
def S(self, s, r=0, m=-1):
r = bool(r)
if m == -1:
s.sort(reverse=r)
else:
s.sort(reverse=r, key=lambda x: x[m])
def bit_n(self, a, b):
return bool((a >> b & 1) > 0)
def bit_o(self, a, b):
return bool(((a >> b) & 1) == 1)
def ceil(self, x, y):
return -(-x//y)
def ave(self, a):
return sum(a) / len(a)
def main():
r, e = range, enumerate
ip = IP()
id = Idea()
k, a, b = ip.IL()
u = k - (a - 1)
print(max(a + (u // 2) * (b - a) + u % 2, k + 1))
main()
|
s249820295
|
p03697
|
u104888971
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 192 |
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
|
import sys
S = input()
for i in range(len(S)):
temp = i + 1
for f in range(len(S) - temp):
if S[i] == S[temp]:
print('no')
sys.exit()
print('yes')
|
s878637600
|
Accepted
| 17 | 3,064 | 103 |
l = list(map(int,input().split()))
if l[0] + l[1] < 10:
print(l[0] + l[1])
else:
print('error')
|
s665078801
|
p03573
|
u955248595
| 2,000 | 262,144 |
Wrong Answer
| 32 | 9,060 | 112 |
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
|
A,B,C = (int(T) for T in input().split())
if B==C:
print('A')
elif A==C:
print('B')
else:
print('C')
|
s340958498
|
Accepted
| 27 | 9,012 | 54 |
A,B,C = (int(T) for T in input().split())
print(A^B^C)
|
s774389110
|
p02645
|
u777394984
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 9,088 | 24 |
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
s = input()
print(s[:2])
|
s381440226
|
Accepted
| 19 | 9,076 | 25 |
s = input()
print(s[:3])
|
s104843085
|
p02261
|
u264972437
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,660 | 661 |
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(C,n):
for i in range(n):
for j in range(i+1,n)[::-1]:
if C[j][1] < C[j-1][1]:
C[j],C[j-1] = C[j-1],C[j]
return C
def SelectionSort(C,n):
for i in range(n):
minj = i
for j in range(i,n):
if C[j][1] < C[minj][1]:
minj = j
C[i],C[minj] = C[minj],C[i]
return C
def stable(C):
new = []
for i in range(1,10):
Ci = [cc for cc in C if cc[1]==str(i)]
new += Ci
return C
n = int(input())
C = input().split()
print(' '.join(BubbleSort(C,n)))
print({True:'Stable',False:'Not stable'}[stable(C)==BubbleSort(C,n)])
print(' '.join(SelectionSort(C,n)))
print({True:'Stable',False:'Not stable'}[stable(C)==SelectionSort(C,n)])
|
s999096042
|
Accepted
| 20 | 7,788 | 710 |
def BubbleSort(C,n):
for i in range(n):
for j in range(i+1,n)[::-1]:
if C[j][1] < C[j-1][1]:
C[j],C[j-1] = C[j-1],C[j]
return C
def SelectionSort(C,n):
for i in range(n):
minj = i
for j in range(i,n):
if C[j][1] < C[minj][1]:
minj = j
C[i],C[minj] = C[minj],C[i]
return C
def stable(C):
new = []
for i in range(1,10):
Ci = [cc for cc in C if cc[1]==str(i)]
new += Ci
return new
n = int(input())
C = input().split()
x,y,z = C[:],C[:],C[:]
bubble = BubbleSort(x,n)
selection = SelectionSort(y,n)
sta = stable(z)
print(' '.join(bubble))
print({True:'Stable',False:'Not stable'}[sta==bubble])
print(' '.join(selection))
print({True:'Stable',False:'Not stable'}[sta==selection])
|
s361847199
|
p03795
|
u084324798
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 37 |
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
n = int(input())
print(800*n + n//15)
|
s644463463
|
Accepted
| 17 | 2,940 | 43 |
n = int(input())
print(800*n - (n//15)*200)
|
s436148281
|
p02612
|
u955248595
| 2,000 | 1,048,576 |
Wrong Answer
| 28 | 9,144 | 30 |
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
N = int(input())
print(N%1000)
|
s281637512
|
Accepted
| 28 | 9,148 | 42 |
N = int(input())
print((1000-N%1000)%1000)
|
s347420869
|
p03359
|
u192364957
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 230 |
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())
count = a
if a > b:
count -= 1
ret_str = ''
for date in range(count):
ret_str += str(date+1) + '/' + str(date+1) + ','
ret_str += 'の合計' + str(count) + '日です.'
print(ret_str)
|
s154152232
|
Accepted
| 17 | 2,940 | 83 |
a, b = map(int, input().split())
count = a
if a > b:
count -= 1
print(count)
|
s586037782
|
p03853
|
u698919163
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 131 |
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
|
H,W = map(int,input().split())
C = [input() for _ in range(H)]
print(C)
for i in range(H):
C.append(C[i])
print(*C,sep='\n')
|
s632007978
|
Accepted
| 17 | 3,060 | 160 |
H,W = map(int,input().split())
C = [input() for _ in range(H)]
ans = []
for i in range(H):
ans.append(C[i])
ans.append(C[i])
print(*ans,sep='\n')
|
s017457702
|
p03962
|
u589381719
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 40 |
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
len(set(list(map(int,input().split()))))
|
s007286346
|
Accepted
| 17 | 2,940 | 32 |
print(len(set(input().split())))
|
s537885278
|
p02258
|
u841567836
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,592 | 268 |
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
|
if __name__ == '__main__':
n = int(input())
max_num = 0
min_num = 0
for i in range(n):
R = int(input())
if not(min_num):
min_num = R
max_num = R
continue
if max_num < R:
max_num = R
elif min_num > R:
min_num = R
print(max_num - min_num)
|
s575369702
|
Accepted
| 680 | 14,904 | 531 |
if __name__ == '__main__':
n = int(input())
lists = list()
for i in range(n):
a = int(input())
lists.append(a)
S = None
while len(lists) > 1:
mini = min(lists)
mini_ind = lists.index(mini)
l = len(lists)
if mini_ind + 1 == l:
if S is None or S < lists[mini_ind] - lists[mini_ind - 1]:
S = lists[mini_ind] - lists[mini_ind - 1]
lists.pop(mini_ind)
continue
maxi = max(lists[mini_ind : l])
T = maxi - mini
if S is None or S < T:
S = T
lists = lists[0 : mini_ind]
continue
print(S)
|
s776265819
|
p03493
|
u717993780
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 93 |
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
S = input()
li = list(S)
ans = 0
for i in range(3):
if li[i] == 1:
ans += 1
print(ans)
|
s547042280
|
Accepted
| 18 | 2,940 | 31 |
s = input()
print(s.count("1"))
|
s920173627
|
p02401
|
u711765449
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,684 | 385 |
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.
|
# -*- coding:utf-8 -*-
import sys
array = []
for i in sys.stdin:
array.append(i)
for i in range(len(array)):
data = array[i].split()
a = int(data[0])
op = str(data[1])
b = int(data[2])
if op == '?':
break
if op == '+':
print(a+b)
if op == '-':
print(a-b)
if op == '/':
print(a/b)
if op == '*':
print(a*b)
|
s111480278
|
Accepted
| 30 | 7,640 | 390 |
# -*- coding:utf-8 -*-
import sys
array = []
for i in sys.stdin:
array.append(i)
for i in range(len(array)):
data = array[i].split()
a = int(data[0])
op = str(data[1])
b = int(data[2])
if op == '?':
break
if op == '+':
print(a+b)
if op == '-':
print(a-b)
if op == '/':
print(int(a/b))
if op == '*':
print(a*b)
|
s521730557
|
p02697
|
u563676207
| 2,000 | 1,048,576 |
Wrong Answer
| 101 | 21,816 | 164 |
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
|
# input
N, M = map(int, input().split())
# process
ans = []
t = 1
for i in range(M):
ans.append((t, N-t+1))
t += 1
# output
[print(a, b) for a, b in ans]
|
s164410515
|
Accepted
| 103 | 21,660 | 243 |
# input
N, M = map(int, input().split())
# process
ans = []
t = 1
for _ in range(M//2):
ans.append((t, M-t+1))
t += 1
t = M+1
for _ in range(-(-M//2)):
ans.append((t, M*3+2-t))
t += 1
# output
[print(a, b) for a, b in ans]
|
s672737079
|
p02690
|
u254871849
| 2,000 | 1,048,576 |
Wrong Answer
| 24 | 9,432 | 640 |
Give a pair of integers (A, B) such that A^5-B^5 = X. It is guaranteed that there exists such a pair for the given integer X.
|
import sys
def divisors(n):
res = set()
for i in range(1, int(n ** 0.5) + 1):
if n % i: continue
res.add(i)
res.add(n // i)
return res
x = int(sys.stdin.readline().rstrip())
def f(a, b):
return pow(a, 5) - pow(b, 5)
def binary(d):
lo, hi = 0, 10 ** 9
while lo + 1 < hi:
a = (lo + hi) // 2
b = a - d
if f(a, b) >= x:
hi = a
else:
lo = a
return hi, hi - d
def main():
diffs = divisors(x)
for d in diffs:
a, b = binary(d)
if f(a, b) == x:
print(a, b)
return
if __name__ == '__main__':
main()
|
s507953495
|
Accepted
| 24 | 9,496 | 677 |
import sys
def divisors(n):
res = set()
for i in range(1, int(n ** 0.5) + 1):
if n % i: continue
res.add(i)
res.add(n // i)
return res
x = int(sys.stdin.readline().rstrip())
def f(a, b): return pow(a, 5) - pow(b, 5)
def ternary_search(d):
lo, hi = -1, 10 ** 18
while lo + 1 < hi:
a = (lo + hi) // 2
b = a - d
bl = a >= abs(b)
bl2 = f(a, b) >= x
if bl ^ bl2: lo = a
else: hi = a
return hi, hi - d
def main():
diffs = divisors(x)
for d in diffs:
a, b = ternary_search(d)
if f(a, b) == x:
print(a, b)
return
if __name__ == '__main__':
main()
|
s393585741
|
p02399
|
u810591206
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,660 | 86 |
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
|
a, b = list(map(int, input().split()))
d = a // b
r = a % b
f = a / b
print(d, r, f)
|
s793596962
|
Accepted
| 20 | 7,648 | 109 |
a, b = list(map(int, input().split()))
d = a // b
r = a % b
f = a / b
print("{} {} {:.5f}".format(d, r, f))
|
s542432800
|
p03623
|
u756030237
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 66 |
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())
print(min(abs(x-a),abs(x-b)))
|
s289455009
|
Accepted
| 17 | 2,940 | 114 |
x, a, b = map(int, input().split())
x_a = abs(x-a)
x_b = abs(x-b)
if x_a < x_b:
print("A")
else:
print("B")
|
s106747300
|
p02578
|
u395672550
| 2,000 | 1,048,576 |
Wrong Answer
| 178 | 32,156 | 181 |
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
|
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(0, N-1):
b = L[i] - L[i+1]
c = int(b)
if c >> 0:
ans = ans + c
L[i + 1] = L[i]
print(ans)
|
s122817709
|
Accepted
| 149 | 32,092 | 176 |
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(0, N-1):
a = L[i]
b = L[i + 1]
if a - b > 0:
ans +=(a - b)
L[i + 1] = L[i]
print(ans)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.