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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s186559472
|
p02618
|
u923270446
| 2,000
| 1,048,576
|
Wrong Answer
| 32
| 9,308
| 729
|
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
|
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
|
s539608852
|
Accepted
| 35
| 9,400
| 164
|
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
for i in range(d):
print(s[i].index(max(s[i])) + 1)
|
s083836846
|
p03826
|
u374802266
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 57
|
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
|
z=list(map(int,input().split()))
min(z[0]*z[1],z[2]*z[3])
|
s434196996
|
Accepted
| 17
| 2,940
| 64
|
z=list(map(int,input().split()))
print(max(z[0]*z[1],z[2]*z[3]))
|
s708371008
|
p02843
|
u399779657
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 115
|
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
X = int(input())
if X >= 1000:
print(1)
elif 0 <= X <= 99 or 106 <= X <= 199 or 207 <= X <= 299:
print(0)
|
s628210710
|
Accepted
| 17
| 3,060
| 237
|
X = int(input())
if X >= 100:
if X % 100 == 0:
print(1)
exit()
elif 0 <= X <= 99:
print(0)
exit()
a = X // 105
b = a * 105 + 1
c = str(a) + '9' * 2
c = int(c)
if b <= X <= c:
print(0)
else:
print(1)
|
s823103339
|
p04029
|
u370429695
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 69
|
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?
|
num = int(input())
cnt = 0
for i in range(num):
cnt += i
print(cnt)
|
s912675455
|
Accepted
| 20
| 2,940
| 73
|
num = int(input())
cnt = 0
for i in range(num):
cnt += i + 1
print(cnt)
|
s346748623
|
p03943
|
u627417051
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 117
|
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 b + c == a or c + a == b:
print("YES")
else:
print("NO")
|
s042114403
|
Accepted
| 17
| 2,940
| 117
|
a, b, c = list(map(int, input().split()))
if a + b == c or b + c == a or c + a == b:
print("Yes")
else:
print("No")
|
s377382819
|
p03730
|
u711452853
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 231
|
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
|
def choose_intenger(s):
a, b, c = map(int, s.split())
for i in range(c):
if ( a + a*i ) % b == c:
print("YES")
return
print("NO")
# choose_intenger("77 42 36")
choose_intenger(input())
|
s214590528
|
Accepted
| 17
| 2,940
| 231
|
def choose_intenger(s):
a, b, c = map(int, s.split())
for i in range(b):
if ( a + a*i ) % b == c:
print("YES")
return
print("NO")
# choose_intenger("40 98 58")
choose_intenger(input())
|
s497564544
|
p03360
|
u408375121
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 96
|
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?
|
l = list(map(int, input().split()))
K = int(input())
l.sort()
a = l.pop()
print(a ** K + sum(l))
|
s559054214
|
Accepted
| 17
| 2,940
| 103
|
l = list(map(int, input().split()))
K = int(input())
l.sort()
a = l.pop()
print((2 ** K) * a + sum(l))
|
s103835375
|
p02659
|
u016336953
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,088
| 53
|
Compute A \times B, truncate its fractional part, and print the result as an integer.
|
n, m= map(float, input().split())
print(round(n*m))
|
s613138575
|
Accepted
| 25
| 10,088
| 98
|
from decimal import Decimal
a,b=input().split()
a=Decimal(a)
b=Decimal(b)
ans=int(a*b)
print(ans)
|
s683012917
|
p02606
|
u856726960
| 2,000
| 1,048,576
|
Wrong Answer
| 26
| 9,144
| 50
|
How many multiples of d are there among the integers between L and R (inclusive)?
|
a,b,c=map(int,input().split())
print(b/c-(a-1)/c)
|
s795246192
|
Accepted
| 27
| 9,160
| 53
|
a,b,c=map(int,input().split())
print(b//c-(a-1)//c)
|
s278332860
|
p02602
|
u861886710
| 2,000
| 1,048,576
|
Wrong Answer
| 143
| 31,748
| 174
|
M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: * For the first through (K-1)-th terms: not given. * For each of the K-th through N-th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i-th term. For each i such that K+1 \leq i \leq N, determine whether his grade for the i-th term is **strictly** greater than the grade for the (i-1)-th term.
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = []
for i in range(K, N):
if A[i] > A[i-K]:
print("Yes")
else:
print("Yes")
|
s093019044
|
Accepted
| 141
| 31,400
| 164
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K, N):
if A[i] > A[i-K]:
print("Yes")
else:
print("No")
|
s655695040
|
p02396
|
u806005289
| 1,000
| 131,072
|
Wrong Answer
| 90
| 5,908
| 176
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
a=[]
i=0
while 1:
n=int(input())
if n==0:
break
else:
a.append(n)
i=i+1
l=0
while l<i:
print("case "+str(l+1)+": "+str(a[l]))
l=l+1
|
s515858644
|
Accepted
| 100
| 5,904
| 176
|
a=[]
i=0
while 1:
n=int(input())
if n==0:
break
else:
a.append(n)
i=i+1
l=0
while l<i:
print("Case "+str(l+1)+": "+str(a[l]))
l=l+1
|
s750126985
|
p02843
|
u737491054
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 2,940
| 92
|
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
x=int(input())
a=int(x/100)
r=x-a*100
print(a,r)
if r/5<=a:
print(1)
else:
print(0)
|
s501600528
|
Accepted
| 17
| 2,940
| 81
|
x=int(input())
a=int(x/100)
r=x-a*100
if r/5<=a:
print(1)
else:
print(0)
|
s868411726
|
p03434
|
u468972478
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,084
| 152
|
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())
l = sorted(map(int, input().split()))
a = 0
b = 0
for i in range(n):
if i % 2 == 0:
a += l.pop()
else:
b += l.pop()
print(a)
|
s356775432
|
Accepted
| 27
| 9,184
| 156
|
n = int(input())
l = sorted(map(int, input().split()))
a = 0
b = 0
for i in range(n):
if i % 2 == 0:
a += l.pop()
else:
b += l.pop()
print(a - b)
|
s452475696
|
p03044
|
u047535298
| 2,000
| 1,048,576
|
Wrong Answer
| 1,351
| 48,404
| 456
|
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.
|
import queue
N = int(input())
adj = dict([(i+1, []) for i in range(N)])
color = [-1 for i in range(N)]
for i in range(N-1):
u, v, w = map(int, input().split())
adj[u].append((v, w))
adj[v].append((u, w))
q = queue.Queue()
q.put((1, 0))
while(not q.empty()):
v, w = q.get()
color[v-1] = (color[v-1]+w)%2
for nv, nw in adj[v]:
if(color[nv-1]!=-1):
continue
q.put((nv, nw))
for c in color:
print(c)
|
s315686164
|
Accepted
| 1,396
| 52,244
| 460
|
import queue
N = int(input())
adj = dict([(i+1, []) for i in range(N)])
dist = [-1 for i in range(N)]
dist[0] = 0
for i in range(N-1):
u, v, w = map(int, input().split())
adj[u].append((v, w))
adj[v].append((u, w))
q = queue.Queue()
q.put((1, 0))
while(not q.empty()):
v, w = q.get()
dist[v-1] = w
for nv, nw in adj[v]:
if(dist[nv-1]!=-1):
continue
q.put((nv, dist[v-1]+nw))
for c in dist:
print(c%2)
|
s840288093
|
p02612
|
u132687480
| 2,000
| 1,048,576
|
Wrong Answer
| 31
| 9,072
| 66
|
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())
def Main(N):
return N % 1000
print(Main(N))
|
s942810996
|
Accepted
| 27
| 9,120
| 146
|
N = int(input())
def Main(N):
d, m = divmod(N, 1000)
if m == 0:
return 0
else:
return (d+1)*1000 - N
print(Main(N))
|
s690503417
|
p03760
|
u196404530
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 85
|
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
o=list(input())
e=list(input())+[""]
result = [x+y for x,y in zip(o,e)]
print(result)
|
s515542146
|
Accepted
| 17
| 2,940
| 93
|
o=list(input())
e=list(input())+[""]
result="".join([x+y for x,y in zip(o,e)])
print(result)
|
s811275359
|
p03543
|
u836737505
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 111
|
We call a 4-digit integer with three or more consecutive same digits, such as 1118, **good**. You are given a 4-digit integer N. Answer the question: Is N **good**?
|
a = input()
c=""
b = 0
for i in a:
if c == i:
b +=1
c = i
if b >=3:
print("Yes")
else:
print("No")
|
s690011551
|
Accepted
| 17
| 2,940
| 87
|
n=input()
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
print("Yes")
else:
print("No")
|
s995875264
|
p02584
|
u714573045
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 9,200
| 699
|
Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction. More specifically, in one move, he can go from coordinate x to x + D or x - D. He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible. Find the minimum possible absolute value of the coordinate of the destination.
|
import math
while True:
try:
x, k, d = map(int, input().split());
if x == 0:
k %= 2;
if k:
print(abs(x - d));
else :
print(0);
elif abs(x) - k * d > 0:
print(abs(x) - k * d);
elif x > 0:
k -= x // d;
k %= 2;
x -= x // d * d;
if k:
print(abs(x - d));
else:
print(x);
else:
num = x // d + 1;
x += num * d;
k -= num;
if k:
print(abs(x - d));
else:
print(x);
except EOFError:
break;
|
s725265514
|
Accepted
| 32
| 9,204
| 724
|
import math
while True:
try:
x, k, d = map(int, input().split());
if x == 0:
k %= 2;
if k:
print(abs(x - d));
else :
print(0);
elif abs(x) - k * d > 0:
print(abs(x) - k * d);
elif x > 0:
k -= x // d;
k %= 2;
x -= x // d * d;
if k:
print(abs(x - d));
else:
print(x);
else:
num = abs(x) // d + 1;
x += num * d;
k -= num;
k %= 2;
if k:
print(abs(x - d));
else:
print(x);
except EOFError:
break;
|
s961149567
|
p02612
|
u024550857
| 2,000
| 1,048,576
|
Wrong Answer
| 31
| 9,148
| 47
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
A = int(input())
result = A%1000
print(result)
|
s098220034
|
Accepted
| 27
| 9,152
| 92
|
A = int(input())
result = A%1000
if result != 0:
result = 1000 - result
print(result)
|
s400253131
|
p02697
|
u518085378
| 2,000
| 1,048,576
|
Wrong Answer
| 70
| 9,268
| 151
|
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
|
n, m = map(int, input().split())
if n % 2 == 1:
for i in range(m):
print(1+i, n-1-i)
else:
for i in range(m):
print(1+i, n-i)
|
s875139148
|
Accepted
| 74
| 9,292
| 241
|
n, m = map(int, input().split())
if n % 2 == 1:
for i in range(m):
print(1+i, n-1-i)
else:
for i in range(m):
if i % 2 == 0:
print(n//2-i//2, n//2+1+i//2)
else:
print(1+i//2, n-1-i//2)
|
s427971643
|
p03623
|
u740767776
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
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 = list(map(int,input().split()))
if abs(a - x) > abs(b - x):
print("A")
else:
print("B")
|
s550108292
|
Accepted
| 17
| 2,940
| 100
|
x, a, b = list(map(int,input().split()))
if abs(a - x) > abs(b - x):
print("B")
else:
print("A")
|
s279433087
|
p03609
|
u580697892
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 50
|
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds?
|
x,t = map(int, input().split())
print(min(0, x-t))
|
s764617771
|
Accepted
| 17
| 2,940
| 51
|
x, t = map(int, input().split())
print(max(0, x-t))
|
s812946045
|
p03695
|
u226155577
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 113
|
In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users.
|
input();A=map(int,input().split());C=[0]*99;D=0
for a in A:a//=400;D+=a>7;C[a]+=a<8
E=sum(C);print(max(E,1),E+D)
|
s510020179
|
Accepted
| 19
| 3,060
| 111
|
input();A=map(int,input().split());C=[0]*99;D=0
for a in A:a//=400;D+=a>7;C[a]=a<8
E=sum(C);print(max(E,1),E+D)
|
s557176989
|
p03556
|
u857330600
| 2,000
| 262,144
|
Wrong Answer
| 28
| 2,940
| 51
|
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())
i=1
while i**2<n:
i+=1
print(i**2)
|
s951457038
|
Accepted
| 32
| 2,940
| 56
|
n=int(input())
i=1
while i**2<=n:
i+=1
print((i-1)**2)
|
s027038647
|
p03354
|
u115682115
| 2,000
| 1,048,576
|
Wrong Answer
| 578
| 13,812
| 605
|
We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations.
|
n,m = map(int,input().split())
p = list(map(lambda x:int(x)-1,input().split()))
par = [i for i in range(n)]
rank = [0]*n
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x, y):
x = find(x)
y = find(y)
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
def same(x, y):
return find(x) == find(y)
for i in range(m):
x,y = map(int,input().split())
unite(x-1,y-1)
ans = 0
for i in range(n):
if same(i,p[i]-1):
ans += 1
print(ans)
|
s297341213
|
Accepted
| 588
| 14,008
| 603
|
n,m = map(int,input().split())
p = list(map(lambda x:int(x)-1,input().split()))
par = [i for i in range(n)]
rank = [0]*n
def find(x):
if par[x] == x:
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x, y):
x = find(x)
y = find(y)
if rank[x] < rank[y]:
par[x] = y
else:
par[y] = x
if rank[x] == rank[y]:
rank[x] += 1
def same(x, y):
return find(x) == find(y)
for i in range(m):
x,y = map(int,input().split())
unite(x-1,y-1)
ans = 0
for i in range(n):
if same(i,p[i]):
ans += 1
print(ans)
|
s806838058
|
p02927
|
u539517139
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 191
|
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
|
m,d=map(int,input().split())
x=0
if m>=4 and d>=22:
o=int(str(d)[1])
t=int(str(d)[0])
for i in range(2,t):
if m%i==0 and m/i<10:
x+=1
if m%t==0 and m/t<=o:
x+=1
print(x)
|
s061031353
|
Accepted
| 23
| 2,940
| 180
|
m,d=map(int,input().split())
x=0
if m>=4 and d>=22:
for i in range(4,m+1):
for j in range(22,d+1):
if j%10>1 and int(str(j)[1])*int(str(j)[0])==i:
x+=1
print(x)
|
s771281603
|
p03485
|
u449473917
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 64
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a,b = map(int, input().split())
c = a+b
d = round(c)
print(d)
|
s428918006
|
Accepted
| 18
| 2,940
| 97
|
a,b=[int(i) for i in input().split()]
round=lambda x:(x*2+1)//2
print(int(round(float((a+b)/2))))
|
s636347390
|
p03493
|
u927807968
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 79
|
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())
count = 0
for i in a:
if a == 0:
count += 1
print(count)
|
s725519899
|
Accepted
| 17
| 2,940
| 81
|
a = str(input())
count = 0
for i in a:
if i == "1":
count += 1
print(count)
|
s325324127
|
p03636
|
u587213169
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,060
| 43
|
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
|
s=input()
N=len(s)-2
print(s[0], N, s[-1:])
|
s138609878
|
Accepted
| 17
| 2,940
| 46
|
s=input()
N=len(s)-2
print(s[0]+str(N)+s[-1:])
|
s374037711
|
p03962
|
u393512980
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 37
|
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.
|
lst = input().split()
print(set(lst))
|
s759601180
|
Accepted
| 18
| 2,940
| 49
|
lst = input().split()
print(len(list(set(lst))))
|
s619449113
|
p03129
|
u366959492
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 76
|
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
|
n,k=map(int,input().split())
if n>=k*2+1:
print("YES")
else:
print("NO")
|
s330042512
|
Accepted
| 18
| 2,940
| 78
|
n,k=map(int,input().split())
if n>=k*2-1:
print("YES")
else:
print("NO")
|
s877503322
|
p03575
|
u926393759
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,064
| 1,370
|
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i. An edge whose removal disconnects the graph is called a _bridge_. Find the number of the edges that are bridges among the M edges.
|
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.readline
n, m = map(int, input().split()) # single line use regular input() is faster
l = [list(tuple(map(int, read().split()))) for i in range(m)]
def root(x): #recursively find root for a node
if parent[x] < 0: # if at root, return self
return x
else:
parent[x] = root(parent[x]) # while searching rejoint queried node to a common parent for hierarchical tree
return parent[x]
def merge(a, b):
a = root(a)
b = root(b)
if rank[a] < rank[b]: # joint lower rank node to a higher rank one
parent[a] = b
else:
parent[b] = a
if rank[a] == rank[b]: # rank only change if two same rank node joined
rank[a] +=1
return
score = 0
for i in range(m):
parent = [-1]*(n+1)
rank = [0]*(n+1)
for j, (a, b) in enumerate(l[i:]): #iteraete from different starting point - test different "last bridge"
a = root(a)
b = root(b)
if a != b:
merge(a, b)
else:
if j == (len(l)-1):# if the last bridge is redundant, +1
score += 1
print(m-score)
|
s944213022
|
Accepted
| 21
| 3,064
| 1,374
|
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.readline
n, m = map(int, input().split()) # single line use regular input() is faster
l = [list(tuple(map(int, read().split()))) for i in range(m)]
def root(x): #recursively find root for a node
if parent[x] < 0: # if at root, return self
return x
else:
parent[x] = root(parent[x]) # while searching rejoint queried node to a common parent for hierarchical tree
return parent[x]
def merge(a, b):
a = root(a)
b = root(b)
if rank[a] < rank[b]: # joint lower rank node to a higher rank one
parent[a] = b
else:
parent[b] = a
if rank[a] == rank[b]: # rank only change if two same rank node joined
rank[a] +=1
return
score = 0
for i in range(m):
parent = [-1]*(n+1)
rank = [0]*(n+1)
for j, (a, b) in enumerate(l[i:]+l[:i]): #iteraete from different starting point - test different last bridge
a = root(a)
b = root(b)
if a != b:
merge(a, b)
else:
if j == (len(l)-1):
score += 1 # if the last bridge is redundant, +1
print(m-score)
|
s142810160
|
p03608
|
u546338822
| 2,000
| 262,144
|
Wrong Answer
| 2,108
| 15,048
| 944
|
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road. If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?
|
n,m,R = map(int,input().split())
r = list(map(int,input().split()))
from itertools import permutations
import numpy as np
cost = np.ones((n,n))*float('inf')
for i in range(m):
a,b,c = map(int,input().split())
cost[a-1][b-1]=cost[b-1][a-1]=c
def main():
def dijkstra(g,n,s):
d = [float('inf')]*n
U = [i for i in range(n)]
d[s] = 0
while len(U)>0:
w = U[0]
for u in U:
if d[u]<d[w]:
w = u
U.pop(U.index(w))
for v in U:
d[v] = min(d[v],d[w]+g[w][v])
return d
dis_dict = {}
m = float('inf')
for i in range(n):
dis_dict[i] = dijkstra(cost,n,i)
for j in permutations(r):
l = 0
for i in range(len(j)-1):
s,t = j[i],j[i+1]
l += dis_dict[s-1][t-1]
if l<m:
m = l
print(m)
if __name__ == "__main__":
main()
|
s383605326
|
Accepted
| 672
| 19,004
| 585
|
n,m,R = map(int,input().split())
r = list(map(int,input().split()))
from itertools import permutations
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
cost = np.ones((n,n))*float('inf')
for i in range(m):
a,b,c = map(int,input().split())
cost[a-1][b-1]=cost[b-1][a-1]=c
d = floyd_warshall(cost)
def main():
m = float('inf')
for j in permutations(r):
l = 0
for i in range(len(j)-1):
s,t = j[i],j[i+1]
l += d[s-1][t-1]
if l<m:
m = l
print(int(m))
if __name__ == "__main__":
main()
|
s213527697
|
p03385
|
u801247169
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,084
| 128
|
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
|
S = str(input())
if S[0] != S[1] and S[0] != S[2] and S[1] != S[2]:
result = "Yse"
else:
result = "No"
print(result)
|
s232339211
|
Accepted
| 27
| 8,908
| 127
|
S = str(input())
if S[0] != S[1] and S[0] != S[2] and S[1] != S[2]:
result = 'Yes'
else:
result = 'No'
print(result)
|
s849674303
|
p03569
|
u626881915
| 2,000
| 262,144
|
Wrong Answer
| 224
| 4,792
| 430
|
We have a string s consisting of lowercase English letters. Snuke can perform the following operation repeatedly: * Insert a letter `x` to any position in s of his choice, including the beginning and end of s. Snuke's objective is to turn s into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.
|
s = input()
i = 0
j = len(s)-1
ist = 0
while i < j:
if s[i] == s[j]:
i += 1
j -= 1
print("i="+str(i))
print("j="+str(j))
elif s[i] == 'x':
ist += 1
i += 1
print("i="+str(i))
print("j="+str(j))
elif s[j] == 'x':
ist += 1
j -= 1
print("i="+str(i))
print("j="+str(j))
else:
print(-1)
exit()
print(ist)
|
s549505875
|
Accepted
| 63
| 3,316
| 267
|
s = input()
i = 0
j = len(s)-1
ist = 0
while i < j:
if s[i] == s[j]:
i += 1
j -= 1
elif s[i] == 'x':
ist += 1
i += 1
elif s[j] == 'x':
ist += 1
j -= 1
else:
print(-1)
exit()
print(ist)
|
s269286609
|
p03157
|
u790710233
| 2,000
| 1,048,576
|
Wrong Answer
| 962
| 213,024
| 880
|
There is a grid with H rows and W columns, where each square is painted black or white. You are given H strings S_1, S_2, ..., S_H, each of length W. If the square at the i-th row from the top and the j-th column from the left is painted black, the j-th character in the string S_i is `#`; if that square is painted white, the j-th character in the string S_i is `.`. Find the number of pairs of a black square c_1 and a white square c_2 that satisfy the following condition: * There is a path from the square c_1 to the square c_2 where we repeatedly move to a vertically or horizontally adjacent square through an alternating sequence of black and white squares: black, white, black, white...
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
h, w = map(int, input().split())
n = h*w
fld = ''.join([input()for _ in range(h)])
edges = [[]for _ in range(n)]
def to_v(i, j):
return i*w+j
for i in range(h):
for j in range(w):
v = to_v(i, j)
dirc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
for di, dj in dirc:
x, y = i+di, j+dj
if x < 0 or h <= x or y < 0 or w <= y:
continue
v2 = to_v(x, y)
if fld[v] != fld[v2]:
edges[v].append(v2)
edges[v2].append(v)
def dfs(v, c=0):
if visited[v]:
return
visited[v] = 1
cnt[c] += 1
for v2 in edges[v]:
dfs(v2, c ^ 1)
visited = [0]*n
ans = 0
for v in range(n):
if visited[v]:
continue
cnt = [0, 0]
dfs(v)
ans += cnt[0]*cnt[1]
print(ans)
|
s203991966
|
Accepted
| 700
| 273,928
| 708
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
h, w = map(int, input().split())
n = h*w
fld = ''.join([input().rstrip()for _ in range(h)])
def to_v(i, j):
return i*w+j
def generate_v2(v):
i, j = divmod(v, w)
if 0 < i:
yield v-w
if i < h-1:
yield v+w
if 0 < j:
yield v-1
if j < w-1:
yield v+1
def dfs(v, c=0):
if visited[v]:
return
visited[v] = 1
cnt[c] += 1
for v2 in generate_v2(v):
if fld[v] == fld[v2]:
continue
dfs(v2, c ^ 1)
visited = [0]*n
ans = 0
for v in range(n):
if visited[v]:
continue
cnt = [0, 0]
dfs(v)
ans += cnt[0]*cnt[1]
print(ans)
|
s023969376
|
p03129
|
u941438707
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 66
|
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
|
n,k=map(int,input().split())
print("Yes" if (n+1)//2>=k else "No")
|
s664986491
|
Accepted
| 17
| 2,940
| 66
|
n,k=map(int,input().split())
print("YES" if (n+1)//2>=k else "NO")
|
s228603375
|
p03971
|
u231685196
| 2,000
| 262,144
|
Wrong Answer
| 108
| 4,016
| 398
|
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
|
n,a,b = map(int,input().split())
s= input()
all_cnt = 0
for_cnt = 0
for i in range(n):
if s[i] == "a":
if all_cnt < a+b:
print("Yes")
all_cnt += 1
else:
print("No")
elif s[i] == "b":
if all_cnt < a+b and for_cnt < b:
print("Yes")
all_cnt += 1
for_cnt += 1
else:
print("No")
|
s613875124
|
Accepted
| 112
| 4,016
| 428
|
n,a,b = map(int,input().split())
s= input()
all_cnt = 0
for_cnt = 0
for i in range(n):
if s[i] == "a":
if all_cnt < a+b:
print("Yes")
all_cnt += 1
else:
print("No")
elif s[i] == "b":
if all_cnt < a+b and for_cnt < b:
print("Yes")
all_cnt += 1
for_cnt += 1
else:
print("No")
else:
print("No")
|
s310897891
|
p03795
|
u503813943
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 56
|
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
n = int(input())
x = 800 * n
y = n / 15 * 200
print(x-y)
|
s344296274
|
Accepted
| 17
| 2,940
| 59
|
n = int(input())
x = 800 * n
y = (n // 15) * 200
print(x-y)
|
s122876314
|
p03361
|
u316095188
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,136
| 411
|
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
|
h,w = map(int,input().rsplit())
s = []
s.append("."*(w+2))
for i in range(h):
s.append("."+input()+".")
s.append("."*(w+2))
count = 0
for i in range(1,h+1):
for j in range(1,w+1):
if s[i][j] == "#":
if s[i-1][j] == "#":
count +=1
elif s[i+1][j] == "#":
count += 1
elif s[i][j-1] == "#":
count += 1
elif s[i][j+1] == "#":
count += 1
else:
print("NO")
break
print("YES")
|
s009087582
|
Accepted
| 27
| 9,228
| 452
|
h,w = map(int,input().rsplit())
s = []
s.append("."*(w+2))
for i in range(h):
s.append("."+input()+".")
s.append("."*(w+2))
count = 0
ans = 0
for i in range(1,h+1):
for j in range(1,w+1):
if s[i][j] == "#":
if s[i-1][j] == "#":
count+=1
elif s[i+1][j] == "#":
count +=1
elif s[i][j-1] == "#":
count +=1
elif s[i][j+1] == "#":
count +=1
else:
ans = 1
break
if ans == 0:
print("Yes")
if ans == 1:
print("No")
|
s441014075
|
p04012
|
u705007443
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 234
|
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.
|
text=input()
dic={}
for i in range(len(text)):
if text[i] not in dic:
dic[text[i]]=1
else:
dic[text[i]]=+1
for i in dic.values():
if not i%2==0:
print('No')
exit()
print('Yes')
|
s898065930
|
Accepted
| 17
| 3,060
| 230
|
text=input()
dic={}
for i in range(len(text)):
if text[i] not in dic:
dic[text[i]]=1
else:
dic[text[i]]+=1
for i in dic.values():
if i%2!=0:
print('No')
exit()
print('Yes')
|
s262225579
|
p03760
|
u733814820
| 2,000
| 262,144
|
Wrong Answer
| 290
| 20,476
| 202
|
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
# ABC 58 B
import numpy as np
def resolve():
O = input()
E = input()
ans = ""
for i in range(len(O)):
ans += O[i]
if i < len(E):
ans += E[i]
print(ans)
|
s646817186
|
Accepted
| 149
| 12,500
| 244
|
# ABC 58 B
import numpy as np
def resolve():
O = input()
E = input()
ans = ""
for i in range(len(O)):
ans += O[i]
if i < len(E):
ans += E[i]
print(ans)
if __name__ == "__main__":
resolve()
|
s262732863
|
p03828
|
u622045059
| 2,000
| 262,144
|
Wrong Answer
| 40
| 3,316
| 230
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
from math import factorial
N = int(input())
mod = 10**9+7
fn = factorial(N)
ans = 1
for i in range(2, N+1):
print(fn)
count = 1
while fn % i == 0:
count += 1
fn //= i
ans *= count
print(ans%mod)
|
s612313223
|
Accepted
| 55
| 6,056
| 2,564
|
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf')
def gcd(a,b):return fractions.gcd(a,b)
def lcm(a,b):return (a*b) // fractions.gcd(a,b)
def iin(): return int(sys.stdin.readline())
def ifn(): return float(sys.stdin.readline())
def isn(): return sys.stdin.readline().split()
def imn(): return map(int, sys.stdin.readline().split())
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split())
def fmn(): return map(float, sys.stdin.readline().split())
def iln(): return list(map(int, sys.stdin.readline().split()))
def iln_s(): return sorted(iln())
def iln_r(): return sorted(iln(), reverse=True)
def fln(): return list(map(float, sys.stdin.readline().split()))
def join(l, s=''): return s.join(l)
def perm(l, n): return itertools.permutations(l, n)
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r)
def comb(l, n): return itertools.combinations(l, n)
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')
def sieves_of_e(n):
is_prime = [True] * (n+1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if not is_prime[i]: continue
for j in range(i * 2, n+1, i): is_prime[j] = False
return is_prime
def prime_factorize(n):
res = []
for i in range(2, int(n**0.5)+1):
if n % i != 0: continue
ex = 0
while (n % i == 0):
ex += 1
n //= i
res.append((i, ex))
if n != 1: res.append((n, 1))
return res
N = iin()
ex = [0 for _ in range(N+1)]
for i in range(2, N+1):
pf = prime_factorize(i)
for p in pf:
ex[p[0]] += p[1]
ans = 1
for i in range(2, N+1):
ans *= ex[i]+1
ans %= MOD
print(ans)
|
s423006757
|
p02388
|
u264450287
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,568
| 24
|
Write a program which calculates the cube of a given integer x.
|
x=int(input())
print(x)
|
s089955183
|
Accepted
| 20
| 5,576
| 29
|
x = int(input())
print(x**3)
|
s950106613
|
p02578
|
u969993073
| 2,000
| 1,048,576
|
Wrong Answer
| 203
| 24,968
| 205
|
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())
ppl=(input().split())
answer=0
for x in range(0,n-1):
ppl[x]=int(ppl[x])
ppl[x+1]=int(ppl[x+1])
if ppl[x]>ppl[x+1]:
answer+=ppl[x]-ppl[x+1]
ppl[x+1]=ppl[x]
answer
|
s415430853
|
Accepted
| 225
| 25,220
| 248
|
n=int(input())
ppl=(input().split())
answer=0
if n==1:
print(0)
for x in range(0,n-1):
ppl[x]=int(ppl[x])
ppl[x+1]=int(ppl[x+1])
if ppl[x]>ppl[x+1]:
answer+=ppl[x]-ppl[x+1]
ppl[x+1]=ppl[x]
if(n!=1):
print(answer)
|
s155890822
|
p03456
|
u064827461
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 114
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
a, b = map(str, input().split())
n = int(a+b)
m = n**1/2
if int(m)-m == 0:
print('Yes')
else:
print('No')
|
s923091538
|
Accepted
| 17
| 3,060
| 115
|
a, b = map(str, input().split())
n = int(a+b)
m = n**0.5
if int(m)-m == 0:
print('Yes')
else:
print('No')
|
s892907442
|
p03475
|
u226108478
| 3,000
| 262,144
|
Wrong Answer
| 262
| 4,692
| 1,093
|
A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.
|
# -*- coding: utf-8 -*-
if __name__ == '__main__':
station_count = int(input())
c, s, f = list(), list(), list()
# HACK: More smarter.
for _ in range(station_count - 1):
line = list(map(int, input().split()))
c.append(line[0])
s.append(line[1])
f.append(line[2])
total_elapsed_times = list()
# HACK: More smarter.
for i in range(station_count):
if i < station_count - 1:
total_elapsed_times.append(s[i])
else:
total_elapsed_times.append(0)
for j in range(station_count - 1):
for k in range(j, station_count - 1):
print(j, total_elapsed_times[j])
if (total_elapsed_times[j] >= s[k]) and (total_elapsed_times[j] % f[k] == 0):
total_elapsed_times[j] += c[k]
else:
total_elapsed_times[j] = 0
total_elapsed_times[j] += s[k]
total_elapsed_times[j] += c[k]
for total_elapsed_time in total_elapsed_times:
print(total_elapsed_time)
|
s361452330
|
Accepted
| 106
| 3,064
| 754
|
# -*- coding: utf-8 -*-
if __name__ == '__main__':
station_count = int(input())
c, s, f = list(), list(), list()
# HACK: More smarter.
for _ in range(station_count - 1):
line = list(map(int, input().split()))
c.append(line[0])
s.append(line[1])
f.append(line[2])
for i in range(station_count):
elapsed_time = 0
for j in range(i, station_count - 1):
if elapsed_time < s[j]:
elapsed_time = s[j]
elif (elapsed_time % f[j]) == 0:
pass
else:
elapsed_time = elapsed_time + f[j] - (elapsed_time % f[j])
elapsed_time += c[j]
print(elapsed_time)
|
s025189205
|
p03447
|
u863526158
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 277
|
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
|
def buying_sweets(money,p_cake,p_dounuts):
t_money = money - p_cake
c_dounuts = t_money // p_dounuts
p_after_money = t_money - (c_dounuts * p_dounuts)
return p_after_money
money = 1000
p_cake = 350
p_dounuts = 125
print(buying_sweets(money,p_cake,p_dounuts))
|
s600132855
|
Accepted
| 17
| 3,060
| 672
|
def buying_sweets(money,p_cake,p_dounuts):
t_money = money - p_cake
c_dounuts = t_money // p_dounuts
p_after_money = t_money - (c_dounuts * p_dounuts)
return p_after_money
money = int(input())
p_cake = int(input())
p_dounuts = int(input())
print(buying_sweets(money,p_cake,p_dounuts))
|
s032500987
|
p03369
|
u057415180
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 54
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
s = str(input())
n = s.count('○')
print(700 + 100*n)
|
s977777967
|
Accepted
| 17
| 2,940
| 47
|
s = input()
n = s.count('o')
print(700 + 100*n)
|
s565276693
|
p03545
|
u994988729
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 422
|
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.
|
inp=input()
a,b,c,d=[int(i) for i in inp]
for i in range(8):
calc=a
B=bin(i)[2:].zfill(3)
print(B)
calc=calc+b if B[0]=="0" else calc-b
calc=calc+c if B[1]=="0" else calc-c
calc=calc+d if B[2]=="0" else calc-d
if calc==7:
break
Operator=["+" if i=="0" else "-" for i in B]
Operator.append("=7")
ans=""
for num, op in zip([a,b,c,d], Operator):
ans+=str(num)
ans+=op
print(ans)
|
s598613002
|
Accepted
| 18
| 3,064
| 324
|
from itertools import product
S = list(input())
T = list(map(int, S))
for p in product([-1, 1], repeat=3):
tmp = T[0]
for i, s in zip(p, T[1:]):
tmp += i * s
if tmp == 7:
break
ans = S[0]
for i, s in zip(p, S[1:]):
q = "+" if i == 1 else "-"
ans += q
ans += s
ans += "=7"
print(ans)
|
s402202624
|
p02578
|
u822984882
| 2,000
| 1,048,576
|
Wrong Answer
| 159
| 32,168
| 296
|
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.
|
if __name__ == "__main__":
n = int(input())
x =list((int(x) for x in input().split()))
print(x)
tmp1 = 0
tmp2 = x[0]
for i in range(1,n):
if tmp2 > x[i]:
tmp3 = tmp2 - x[i]
tmp1 += tmp3
x[i] = x[i] + tmp3
print(tmp1)
|
s433899499
|
Accepted
| 151
| 32,212
| 384
|
if __name__ == "__main__":
n = int(input())
x =list((int(x) for x in input().split()))
# print(x)
tmp1 = 0
tmp2 = x[0]
for i in range(1,n):
if tmp2 > x[i]:
tmp3 = tmp2 - x[i]
tmp1 += tmp3
x[i] = x[i] + tmp3
tmp2 = x[i]
else:
tmp1 += 0
tmp2 = x[i]
print(tmp1)
|
s083016738
|
p03068
|
u211236379
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 139
|
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
|
N = int(input())
S = input()
K = int(input())
str = S[K-1]
for i in range(N):
if S[i] != str:
S=S.replace(S[i],'*')
print(S)
|
s269696486
|
Accepted
| 17
| 2,940
| 137
|
N = int(input())
S = input()
K = int(input())
str = S[K-1]
for i in range(N):
if S[i] != str:
S=S.replace(S[i],'*')
print(S)
|
s547430142
|
p03409
|
u905203728
| 2,000
| 262,144
|
Wrong Answer
| 20
| 3,064
| 379
|
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.
|
from operator import itemgetter
n=int(input())
A=[tuple(map(int,input().split())) for i in range(n)]
B=[tuple(map(int,input().split())) for j in range(n)]
count=0
for i in range(n):
box=[A[i] for i in range(len(A)) if (A[i][0]<B[i][0]) and (A[i][1]<B[i][1])]
if any(box):
box=sorted(box, key=itemgetter(1))
A.remove(box[-1])
count +=1
print(count)
|
s449545984
|
Accepted
| 19
| 3,064
| 324
|
N=int(input())
AB=sorted([list(map(int,input().split())) for _ in range(N)])
CD=sorted([list(map(int,input().split())) for _ in range(N)], key=lambda x:x[1])
cnt=0
for a,b in AB[::-1]:
for i,j in enumerate(CD):
c,d=j
if a<c and b<d:
cnt +=1
del CD[i]
break
print(cnt)
|
s246172399
|
p03547
|
u827141374
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 64
|
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
|
a=input()
print('>' if a[0]>a[1] else '<' if a[0]<a[1] else '=')
|
s507285881
|
Accepted
| 19
| 2,940
| 62
|
a,b=input().split()
print('>' if a>b else '<' if a<b else '=')
|
s039117210
|
p03377
|
u368796742
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 72
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a,b,x = map(int,input().split())
print("Yes" if a+b >= x >= a else "No")
|
s597717387
|
Accepted
| 17
| 2,940
| 75
|
a,b,x = map(int,input().split())
print("YES" if (a+b >= x >= a) else "NO")
|
s429411462
|
p00008
|
u926657458
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,764
| 219
|
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
|
n = int(input())
def rec(j,s):
if s > n:
return 0
if s == n:
return 1
if j == 0:
return 0
v = 0
for i in range(10):
v += rec(j-1, s + i)
return v
print(rec(4,0))
|
s394029782
|
Accepted
| 230
| 7,700
| 296
|
import sys
def rec(j,s):
if s > n:
return 0
if s == n:
return 1
if j == 0:
return 0
v = 0
for i in range(10):
v += rec(j-1, s + i)
return v
n = sys.stdin.readline()
while n:
n = int(n)
print(rec(4,0))
n = sys.stdin.readline()
|
s860435966
|
p02612
|
u468597111
| 2,000
| 1,048,576
|
Wrong Answer
| 26
| 9,136
| 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)
|
s299657863
|
Accepted
| 28
| 9,152
| 113
|
n=int(input())
if n%1000==0:
print(0)
else:
x=n//1000
y=x+1
y=y*1000
y=abs(n-y)
print(y)
|
s026638747
|
p02743
|
u644972721
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 127
|
Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?
|
a, b, c = map(int, input().split())
if (a ** (1 / 2)) + (b ** (1 / 2)) < (c ** (1 / 2)):
print("YES")
else:
print("NO")
|
s728904105
|
Accepted
| 17
| 2,940
| 125
|
a, b, c = map(int, input().split())
if (c - a - b) ** 2 > 4 * a * b and c - a - b > 0:
print("Yes")
else:
print("No")
|
s520603164
|
p03494
|
u854061980
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,060
| 244
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
N=int(input())
A = list(map(int,input().split()))
t = 0
wareru = 0
while t==0:
for j, i in enumerate(A):
c = i%2
A[j] = A[j]/2
if c == 1:
t = 1
break
wareru += 1
print(wareru)
|
s678368743
|
Accepted
| 20
| 3,060
| 254
|
N=int(input())
A = list(map(int,input().split()))
t = 0
wareru = 0
while t==0:
for j, i in enumerate(A):
c = i%2
A[j] = A[j]/2
if c == 1:
t = 1
break
if c == 0:
wareru += 1
print(wareru)
|
s317370603
|
p03486
|
u546440137
| 2,000
| 262,144
|
Wrong Answer
| 24
| 9,064
| 173
|
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
s=list(input())
t=list(input())
s.sort()
t.sort()
t.reverse()
for i in range(len(s)):
S=s[i]
for i in range(len(t)):
T=t[i]
if S>=T:
print('No')
else:
print('Yes')
|
s506056851
|
Accepted
| 30
| 9,072
| 141
|
s=list(input())
t=list(input())
s.sort()
t.sort()
t.reverse()
s_a=''.join(s)
t_a=''.join(t)
if s_a<t_a:
print('Yes')
else:
print('No')
|
s834474901
|
p00025
|
u777299405
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,592
| 295
|
Let's play Hit and Blow game. _A_ imagines four numbers and _B_ guesses the numbers. After _B_ picks out four numbers, _A_ answers: * The number of numbers which have the same place with numbers _A_ imagined (Hit) * The number of numbers included (but different place) in the numbers _A_ imagined (Blow) For example, if _A_ imagined numbers: 9 1 8 2 and _B_ chose: 4 1 5 9 _A_ should say 1 Hit and 1 Blow. Write a program which reads four numbers _A_ imagined and four numbers _B_ chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9.
|
import sys
even = True
for s in sys.stdin:
if even:
even = not even
a = list(map(int, s.split()))
else:
b = list(map(int, s.split()))
hit = sum(a[i] == b[i] for i in range(4))
blow = sum(b[i] in a for i in range(4)) - hit
print(hit, blow)
|
s070989071
|
Accepted
| 20
| 7,648
| 312
|
import sys
even = True
for s in sys.stdin:
if even:
even = False
a = list(map(int, s.split()))
else:
even = True
b = list(map(int, s.split()))
hit = sum(a[i] == b[i] for i in range(4))
blow = sum(b[i] in a for i in range(4)) - hit
print(hit, blow)
|
s205963418
|
p03854
|
u241159583
| 2,000
| 262,144
|
Wrong Answer
| 30
| 9,188
| 414
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
s = input()
a = ""
i = 0
ok = True
while i <= len(s)-1:
if len(a)<5:
a += s[i]
i += 1
else:
if a != "dream" and a != "erase":
ok = False
break
a = ""
if i+1 <= len(s)-1 and s[i]+s[i+1]== "er":
if i+2 <= len(s)-1 and s[i+2] == "a": i+=1
else: i+=2
else: i+=1
if a != "": ok = False
print("YES" if ok else "NO")
|
s268316827
|
Accepted
| 29
| 9,068
| 248
|
s = input()
s = s.replace("dream", "D")
s = s.replace("erase", "E")
s = s.replace("Der", "D")
s = s.replace("Er", "E")
s = list(set(s))
ok = True
for i in range(len(s)):
if s[i] not in ["D","E"]:
ok = False
print("YES" if ok else "NO")
|
s315014230
|
p03672
|
u328755070
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 152
|
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
|
S = input()
i = 0
leng = len(S)
while 1:
i += 1
if S[:leng//2 - i] == S[leng//2 - i:leng - 1 - i]:
print(leng//2 - i)
break
|
s161561219
|
Accepted
| 18
| 2,940
| 158
|
S = input()
i = 0
leng = len(S)
while 1:
i += 1
if S[:leng//2 - i] == S[leng//2 - i:leng - i * 2]:
print((leng//2 - i) * 2)
break
|
s391520271
|
p03493
|
u914529932
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 81
|
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()
print(s)
s1,s2,s3 = int(s[0]),int(s[1]),int(s[2])
print(s1+s2+s3)
|
s429468851
|
Accepted
| 17
| 2,940
| 72
|
s = input()
s1,s2,s3 = int(s[0]),int(s[1]),int(s[2])
print(s1+s2+s3)
|
s843880216
|
p03494
|
u137667583
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 164
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
N = int(input())
A = list(map(int,input().split()))
co = 0
for i in range(N):
if(A[i]%2==0):
co = co+1
else:
co = 0
break
print(co)
|
s829726627
|
Accepted
| 19
| 3,060
| 271
|
N = int(input())
A = list(map(int,input().split()))
flg = False
co = 0
while(True):
for i in range(N):
if(A[i]%2==0):
A[i] = A[i]/2
else:
flg = True
break
if(flg):
break
co = co+1
print(co)
|
s843410107
|
p03493
|
u866682319
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 24
|
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()
S.count("1")
|
s373987296
|
Accepted
| 17
| 2,940
| 31
|
N = input()
print(N.count("1"))
|
s676816332
|
p03360
|
u905582793
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 86
|
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()))
k=int(input())
print(sum(a)-max(a)+max(a)*(2**(k-1)))
|
s459728337
|
Accepted
| 17
| 2,940
| 82
|
a=list(map(int,input().split()))
k=int(input())
print(sum(a)-max(a)+max(a)*(2**k))
|
s553387909
|
p03214
|
u961683878
| 2,525
| 1,048,576
|
Wrong Answer
| 1,472
| 21,484
| 147
|
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
|
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
ave = a.mean()
idx = np.abs(np.argsort(a - ave))[0]
print(idx)
|
s962722635
|
Accepted
| 347
| 21,416
| 132
|
import numpy as np
_ = int(input())
a = np.array(list(map(int, input().split())))
idx = np.argmin(np.abs(a - a.mean()))
print(idx)
|
s257586876
|
p03369
|
u265118937
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 34
|
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
|
s=input()
print(700+s.count("o"))
|
s178338828
|
Accepted
| 17
| 2,940
| 40
|
s=input()
print(700+100*(s.count("o")))
|
s184975858
|
p03994
|
u464205401
| 2,000
| 262,144
|
Wrong Answer
| 145
| 11,408
| 397
|
Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For example, if you perform an operation for the second letter on `aaz`, `aaz` becomes `abz`. If you then perform an operation for the third letter on `abz`, `abz` becomes `aba`. Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s. Find the such string.
|
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s))
for i in range(len(t)):
diff = 26-t[i]
if diff <= k:
t[i]+=diff
k-=diff
print(t[i],diff,k)
else:
continue
t[-1]+=k
#print("s:",s)
#print("t:",t)
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
#print("u:",u)
|
s394635961
|
Accepted
| 82
| 11,260
| 254
|
s = list(input())
k = int(input())
t = list(map(lambda x:ord(x)-ord("a"),s))
for i in range(len(t)):
diff = 26-t[i]
if diff != 26 and diff <= k:
t[i]+=diff
k-=diff
t[-1]+=k
u = "".join(list(map(lambda x:chr((x%26+ord("a"))),t)))
print(u)
|
s577653067
|
p00017
|
u811733736
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,416
| 703
|
In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text: this is a pen is would become: uijt jt b qfo Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that".
|
import sys
def decrypt(c, i):
if c.isalpha():
t = ord(c) - i
if t < ord('a'):
t = ord('z') - i + 1
return chr(t)
else:
return c
if __name__ == '__main__':
# ??????????????\???
for line in sys.stdin:
# ?????????????????????
found = '' # ?????????????????????
for i in range(1, 25):
decrypted = ''.join([decrypt(x, i) for x in line])
# print(decrypted)
if 'the' in decrypted or 'this' in decrypted or 'that' in decrypted:
found = decrypted
break
# ???????????????
if found:
print(found)
|
s604357874
|
Accepted
| 30
| 7,384
| 824
|
import sys
def decrypt(c, i):
if c.isalpha():
t = ord(c) - i
if t < ord('a'):
t += 26
return chr(t)
else:
return c
if __name__ == '__main__':
# ??????????????\???
for line in sys.stdin:
# ?????????????????????
found = '' # ?????????????????????
for i in range(0, 26):
decrypted = ''.join([decrypt(x, i) for x in line.strip()])
# print(decrypted)
if ' the ' in decrypted or ' this ' in decrypted or ' that ' in decrypted or \
decrypted.startswith('the ') or decrypted.startswith('this ') or decrypted.startswith('that '):
found = decrypted
break
# ???????????????
if found:
print(found)
|
s095362310
|
p02381
|
u350064373
| 1,000
| 131,072
|
Wrong Answer
| 50
| 10,168
| 91
|
You have final scores of an examination for n students. Calculate standard deviation of the scores s1, s2 ... sn. The variance α2 is defined by α2 = (∑n _i_ =1(s _i_ \- m)2)/n where m is an average of si. The standard deviation of the scores is the square root of their variance.
|
import statistics
input()
ls = list(map(int, input().split()))
print(statistics.pstdev(ls))
|
s753410876
|
Accepted
| 80
| 10,276
| 189
|
import statistics
while True:
x = int(input())
if x == 0:
break
else:
ls = list(map(int, input().split()))
print("{0:.8f}".format(statistics.pstdev(ls)))
|
s043186199
|
p03545
|
u023958502
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 425
|
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.
|
s = input()
abcd = [int(s[0]),int(s[1]),int(s[2]),int(s[3])]
mark = ['-','+']
for i in range(1 << 3):
alla = abcd[0]
i2 = format(i,'03b')
for j in range(3):
if i2[2 - j] == '0':#0 = -
alla -= abcd[3 - j]
else:
alla += abcd[3 - j]
if alla == 7:
print(int(s[0]),mark[int(i2[0])],int(s[1]),mark[int(i2[1])],int(s[2]),mark[int(i2[2])],int(s[3]),'=7')
exit()
|
s576343782
|
Accepted
| 19
| 3,188
| 420
|
s = input()
abcd = [int(s[0]),int(s[1]),int(s[2]),int(s[3])]
mark = ['-','+']
for i in range(1 << 3):
alla = abcd[0]
i2 = format(i,'03b')
for j in range(3):
if i2[2 - j] == '0':#0 = -
alla -= abcd[3 - j]
else:
alla += abcd[3 - j]
if alla == 7:
print(s[0] + mark[int(i2[0])] + s[1] + mark[int(i2[1])] + s[2] + mark[int(i2[2])] + s[3] + '=7')
exit()
|
s432519298
|
p03197
|
u718096172
| 2,000
| 1,048,576
|
Wrong Answer
| 182
| 7,072
| 158
|
There is an apple tree that bears apples of N colors. The N colors of these apples are numbered 1 to N, and there are a_i apples of Color i. You and Lunlun the dachshund alternately perform the following operation (starting from you): * Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors. The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?
|
N = int(input())
aList = [int(input()) for _ in range(N)]
ans = "fisrt"
for a in aList:
if a % 2 == 1:
break
else:
ans = "second"
print(ans)
|
s823774541
|
Accepted
| 176
| 7,072
| 159
|
N = int(input())
aList = [int(input()) for _ in range(N)]
ans = "first"
for a in aList:
if a % 2 == 1:
break
else:
ans = "second"
print(ans)
|
s723466246
|
p03852
|
u284155299
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 60
|
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`.
|
if input()in "aeiou":
print('Yes')
else:
print('No')
|
s117782100
|
Accepted
| 17
| 2,940
| 69
|
if input()in "aeiou":
print('vowel')
else:
print('consonant')
|
s680768891
|
p02694
|
u727051308
| 2,000
| 1,048,576
|
Wrong Answer
| 20
| 9,164
| 111
|
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
X = int(input())
start = 100
year = 0
if start < X:
start = int(start * 1.01)
year += 1
else:
print(year)
|
s385067342
|
Accepted
| 23
| 9,160
| 114
|
X = int(input())
start = 100
year = 0
while start < X:
start = int(start * 1.01)
year += 1
else:
print(year)
|
s639756012
|
p03455
|
u673559119
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 178
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
# coding: utf-8
ab = input().split()
a = int(ab[0])
b = int(ab[1])
hantei = 0
if a%2==0:
hantei = 1
if b%2==0:
hantei = 1
if hantei == 0:
print("odd")
else:
print("even")
|
s092078005
|
Accepted
| 17
| 2,940
| 178
|
# coding: utf-8
ab = input().split()
a = int(ab[0])
b = int(ab[1])
hantei = 0
if a%2==0:
hantei = 1
if b%2==0:
hantei = 1
if hantei == 0:
print("Odd")
else:
print("Even")
|
s801012364
|
p02399
|
u391228754
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,652
| 79
|
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 = map(int, input().split())
d = a // b
r = a % b
f = a / b
print(d, r, f)
|
s955946573
|
Accepted
| 20
| 7,660
| 117
|
a, b = map(int, input().split())
d = a // b
r = a % b
f = round((a / b), 8)
print("{0} {1} {2:.5f}".format(d, r, f))
|
s463172748
|
p02694
|
u126823513
| 2,000
| 1,048,576
|
Wrong Answer
| 23
| 9,088
| 123
|
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
import math
x = int(input())
a = 100
answer = 0
while a <= x:
a += math.floor(a * 0.01)
answer += 1
print(answer)
|
s269357147
|
Accepted
| 22
| 9,164
| 122
|
import math
x = int(input())
a = 100
answer = 0
while a < x:
a += math.floor(a * 0.01)
answer += 1
print(answer)
|
s216361047
|
p03730
|
u999893056
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 103
|
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
|
a,b,c = list(map(int, input().split()))
print("Yes" if any((a*i)%b==c for i in range(1,10)) else "No")
|
s760055408
|
Accepted
| 17
| 2,940
| 94
|
a,b,c=map(int,input().split())
print("YES" if any((a*i)%b==c for i in range(1,b+1)) else "NO")
|
s043961391
|
p03455
|
u224488911
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 84
|
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
|
a,b=map(int,input().split())
x=a*b
if x%2 == 0:
print("Odd")
else:
print("Even")
|
s297755779
|
Accepted
| 17
| 2,940
| 84
|
a,b=map(int,input().split())
x=a*b
if x%2 == 0:
print("Even")
else:
print("Odd")
|
s763956646
|
p03433
|
u733738237
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 99
|
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
l=[int(input()) for i in range(2)]
N=l[0]
A=l[1]
r=N%500
if r > A:
print('NO')
else:
print('YES')
|
s299562803
|
Accepted
| 17
| 2,940
| 99
|
l=[int(input()) for i in range(2)]
N=l[0]
A=l[1]
r=N%500
if r > A:
print('No')
else:
print('Yes')
|
s609042296
|
p03737
|
u403984573
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 79
|
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
|
A,B,C=input().split()
A=A.upper()
B=B.upper()
C=C.upper()
print(A[0],B[0],C[0])
|
s719080687
|
Accepted
| 18
| 2,940
| 80
|
A,B,C=input().split()
A=A.upper()
B=B.upper()
C=C.upper()
print(A[0]+B[0]+C[0])
|
s529940217
|
p00008
|
u553148578
| 1,000
| 131,072
|
Wrong Answer
| 30
| 5,588
| 182
|
Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of (a, b, c, d): (8, 9, 9, 9), (9, 8, 9, 9), (9, 9, 8, 9), and (9, 9, 9, 8).
|
n=int(input())
count=0
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
ans = a + b + c + d
if(n == ans):
count += 1
print(count)
|
s822108475
|
Accepted
| 30
| 5,604
| 184
|
ans=[0]*51
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
ans[sum([a,b,c,d])] += 1
while True:
try:print(ans[int(input())])
except:break
|
s807807410
|
p02865
|
u798818115
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 100
|
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
|
# coding: utf-8
# Your code here!
N=int(input())
if N%2==0:
print(N/2-1)
else:
print(N//2)
|
s429393679
|
Accepted
| 70
| 2,940
| 149
|
# coding: utf-8
# Your code here!
N=int(input())
count=-1
for i in range(N//2+1):
count+=1
if N%2==0:
print(count-1)
else:
print(count)
|
s169124579
|
p03251
|
u785066634
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 248
|
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()))
x_.append(x)
y_.append(y)
x_.sort()
y_.sort()
if y_[0]>x_[-1]:
print('NoWar')
else:
print('War')
|
s807636116
|
Accepted
| 20
| 2,940
| 233
|
n,m,x,y=map(int,input().split())
x_=list(map(int,input().split()))
y_=list(map(int,input().split()))
x_.append(x)
y_.append(y)
if min(y_)>max(x_):
print('No War')
else:
print('War')
|
s922659133
|
p03493
|
u757030836
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 84
|
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()
x = 0
for i in range(len(s)):
if s[i] == 1:
x += 1
print(x)
|
s178112600
|
Accepted
| 17
| 2,940
| 102
|
s = input()
count = 0
for i in range(len(s)):
if s[i] == "1":
count +=1
print(count)
|
s924694875
|
p00105
|
u136916346
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,572
| 195
|
Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers. You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once. The words should be printed in alphabetical order and the page numbers should be printed in ascending order.
|
import sys
l=[i.split() for i in sys.stdin]
d={}
for i in l:
if i[0] not in d:
d[i[0]]=[i[1]]
else:
d[i[0]].append(i[1])
for i in sorted(d.keys()):
print(i)
print(" ".join(d[i]))
|
s047904746
|
Accepted
| 20
| 5,616
| 240
|
import sys
l=[i.split() for i in sys.stdin]
d={}
for i in l:
if i[0] not in d:
d[i[0]]=[i[1]]
else:
d[i[0]].append(i[1])
for i in sorted(d.keys()):
print(i)
d[i]=list(map(int,d[i]))
print(" ".join(map(str,sorted(d[i]))))
|
s797926320
|
p02409
|
u436634575
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,724
| 340
|
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.
|
a = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
print(a)
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().strip().split())
a[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
print(''.join(' {}'.format(a[b][f][r]) for r in range(10)))
if b < 3:
print('#'*20)
|
s359762356
|
Accepted
| 30
| 6,724
| 331
|
a = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = map(int, input().strip().split())
a[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
print(''.join(' {}'.format(a[b][f][r]) for r in range(10)))
if b < 3:
print('#'*20)
|
s485787972
|
p02843
|
u606090886
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 142
|
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
x = int(input())
for i in range(x//105,x//105+1):
ans = x - i * 100
if ans <= 5 * i:
print("1")
else:
print("0")
|
s236887475
|
Accepted
| 17
| 2,940
| 185
|
x = int(input())
flag = False
for i in range(x//105,x//105+3):
ans = x - i * 100
if ans >= 0 and ans <= 5 * i:
flag = True
if flag:
print("1")
else:
print("0")
|
s927069289
|
p03854
|
u298975656
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,188
| 167
|
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
S = input()
S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if S is '':
print('YES')
else:
print('NO')
print(S)
|
s655381778
|
Accepted
| 18
| 3,188
| 159
|
S = input()
S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if S is '':
print('YES')
else:
print('NO')
|
s420819765
|
p03471
|
u107798522
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,064
| 385
|
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.
|
#C - Otoshidama
N, Y = map(int, input().split())
x_ans = -1
y_ans = -1
z_ans = -1
flg = 0
for x in range(N+1):
for y in range(N+1-x):
for z in range(N+1-x-y):
otoshidama = 10000*x + 5000*y + 1000*z
if otoshidama == Y :
flg = 1
x_ans = x
y_ans = y
z_ans = z
print(x_ans, y_ans, z_ans)
|
s010055216
|
Accepted
| 864
| 3,064
| 355
|
#C - Otoshidama
N, Y = map(int, input().split())
x_ans = -1
y_ans = -1
z_ans = -1
flg = 0
for x in range(N+1):
for y in range(N+1-x):
otoshidama = 10000*x + 5000*y + 1000*(N-x-y)
if otoshidama == Y :
flg = 1
x_ans = x
y_ans = y
z_ans = N-x-y
print(x_ans, y_ans, z_ans)
|
s400151772
|
p02614
|
u178946688
| 1,000
| 1,048,576
|
Wrong Answer
| 64
| 9,032
| 354
|
We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is `.`, and black if c_{i,j} is `#`. Consider doing the following operation: * Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns. You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.
|
H, W, K = map(int, input().split())
C = []
for _ in range(H):
C.append(input())
ans = 0
for h in range(2 ** H):
for w in range(2 ** H):
count = 0
for i in range(H):
for j in range(W):
if ((h >> i) & 1) == 0 and (w >> j) & 1 == 0:
if C[i][j] == '#':
count += 1
if K == count:
ans += 1
print(ans)
|
s556853271
|
Accepted
| 66
| 9,136
| 356
|
H, W, K = map(int, input().split())
C = []
for _ in range(H):
C.append(input())
ans = 0
for h in range(2 ** H):
for w in range(2 ** W):
count = 0
for i in range(H):
for j in range(W):
if ((h >> i) & 1) == 0 and ((w >> j) & 1) == 0:
if C[i][j] == '#':
count += 1
if K == count:
ans += 1
print(ans)
|
s349512140
|
p04029
|
u870297120
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 377
|
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(map(str, input().split(' ')))
letter = ''
dup = 0
ans = []
for i, j in enumerate(s):
print(s.count(s[i]))
if dup < s.count(s[i]):
dup = s.count(s[i])
letter = j
for i, j in enumerate(s):
if j == letter:
ans.append(i+1)
print(dup)
print(ans)
if dup > len(s) // 2:
print('{0} {1}'.format(ans[0], ans[-1]))
else:
print('-1 -1')
|
s113718651
|
Accepted
| 17
| 2,940
| 49
|
print(sum([i for i in range(1, int(input())+1)]))
|
s169788018
|
p03557
|
u204842730
| 2,000
| 262,144
|
Wrong Answer
| 384
| 23,232
| 296
|
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
|
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
c.sort()
ans = 0
for i in range(n):
low = bisect.bisect_left(a,b[i]-1)
upp = bisect.bisect_left(c,b[i]+1)
ans += low*(n-upp)
print(ans)
|
s948627400
|
Accepted
| 393
| 23,232
| 303
|
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
#b.sort()
c.sort()
ans = 0
for i in range(n):
low = bisect.bisect_left(a,b[i])
upp = bisect.bisect_right(c,b[i])
ans += low*(n-upp)
print(ans)
|
s562223299
|
p03379
|
u698479721
| 2,000
| 262,144
|
Wrong Answer
| 339
| 25,220
| 224
|
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
|
N = int(input())
A = list(map(int, input().split()))
B = A
B.sort()
m1 = B[N//2-1]
m2 = B[N//2]
if m1 != m2:
for nums in A:
if nums <= m1:
print(m2)
else:
print(m1)
else:
for nums in A:
print(m1)
|
s846674508
|
Accepted
| 306
| 25,224
| 261
|
N = int(input())
A = list(map(int, input().split()))
A1 = []
for nums in A:
A1.append(nums)
A.sort()
m1 = A[N//2-1]
m2 = A[N//2]
if m1 != m2:
for nums in A1:
if nums <= m1:
print(m2)
else:
print(m1)
else:
for nums in A1:
print(m1)
|
s676785797
|
p03361
|
u241496594
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 596
|
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
|
h,w = map(int, input().split())
# print(h,w)
row = []
for x in range(h):
col = list(input())
row.append(col)
out = "YES"
for x in range(h):
for y in range (w):
if row[x][y] == "#":
#print(x,y)
if x > 0 and row[x-1][y] == "#":
pass
elif x < h-1 and row[x+1][y] == "#":
pass
elif y > 0 and row[x][y-1] == "#" :
pass
elif y < w-1 and row [x][y+1] == "#" :
pass
else:
out = "NO"
break
pass
print(out)
|
s962749249
|
Accepted
| 18
| 3,064
| 596
|
h,w = map(int, input().split())
# print(h,w)
row = []
for x in range(h):
col = list(input())
row.append(col)
out = "Yes"
for x in range(h):
for y in range (w):
if row[x][y] == "#":
#print(x,y)
if x > 0 and row[x-1][y] == "#":
pass
elif x < h-1 and row[x+1][y] == "#":
pass
elif y > 0 and row[x][y-1] == "#" :
pass
elif y < w-1 and row [x][y+1] == "#" :
pass
else:
out = "No"
break
pass
print(out)
|
s129418602
|
p04030
|
u468972478
| 2,000
| 262,144
|
Wrong Answer
| 27
| 9,088
| 112
|
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now?
|
s = input()
a = ""
for i in a:
if i == "1" or i == "0":
a += i
else:
if a:
a = a[:-1]
print(a)
|
s235860724
|
Accepted
| 27
| 9,088
| 112
|
s = input()
a = ""
for i in s:
if i == "1" or i == "0":
a += i
else:
if a:
a = a[:-1]
print(a)
|
s363222732
|
p03129
|
u405660020
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 64
|
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
|
n,k=map(int,input().split())
print('YES' if n//2>=k else 'NO')
|
s703724092
|
Accepted
| 17
| 2,940
| 74
|
n, k = map(int, input().split())
print('YES' if (n+1)//2 >= k else 'NO')
|
s793582330
|
p00004
|
u308369184
| 1,000
| 131,072
|
Wrong Answer
| 20
| 6,740
| 190
|
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
|
while True:
try:
line=input()
except:
break
a,b,c,d,e,f=map(int, line.strip().split())
y=(c*d-f*a)/(b*d-a*e)
x=(c*e-f*b)/(a*e-b*d)
print(x,y)
|
s697085934
|
Accepted
| 30
| 6,756
| 330
|
while True:
try:
line=input()
except:
break
a,b,c,d,e,f=map(int, line.strip().split())
y=(c*d-f*a)/(b*d-a*e)
x=(c*e-f*b)/(a*e-b*d)
if x<=0 and x>=-0.0005:
x=0.000
if y<=0 and y>=-0.0005:
y=0.000
print('{:.3f} {:.3f}'.format(x,y))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.