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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s232151030
|
p03401
|
u272557899
| 2,000 | 262,144 |
Wrong Answer
| 226 | 14,048 | 430 |
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
|
n = int(input())
a = [int(x) for x in input().split()]
b = []
for i in range(n):
if i == 0:
b.append(abs(a[i]))
if i == n - 1:
b.append(abs(a[i]))
else:
b.append(abs(a[i] - a[i - 1]))
sd = sum(b)
for j in range(n):
if j == 0:
print(sd - b[j] - b[j + 1] + abs(a[j + 1]))
if j == n - 1:
print(sd - b[j + 1] - b[j] + abs(a[j]))
else:
print(sd - b[j] - b[j + 1] + abs(a[j + 1] - a[j - 1]))
|
s463851647
|
Accepted
| 215 | 14,048 | 439 |
n = int(input())
a = [int(x) for x in input().split()]
b = []
for i in range(n + 1):
if i == 0:
b.append(abs(a[i]))
elif i == n:
b.append(abs(a[i - 1]))
else:
b.append(abs(a[i] - a[i - 1]))
sd = sum(b)
for j in range(n):
if j == 0:
print(sd - b[j] - b[j + 1] + abs(a[j + 1]))
elif j == n - 1:
print(sd - b[j] - b[j + 1] + abs(a[j - 1]))
else:
print(sd - b[j] - b[j + 1] + abs(a[j + 1] - a[j - 1]))
|
s481158991
|
p03079
|
u144980750
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 78 |
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
|
A,B,C=map(int,input().split())
if A-B==2*C:
print("Yes")
else:
print("No")
|
s236457095
|
Accepted
| 17 | 2,940 | 83 |
A,B,C=map(int,input().split())
if A==B and A==C:
print("Yes")
else:
print("No")
|
s098667577
|
p03434
|
u813450984
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 189 |
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 = list(map(int, input().split()))
l.sort(reverse=True)
a, b = 0, 0
print(l)
for i in range(len(l)):
if i % 2 == 0:
a += l[i]
else:
b += l[i]
print(abs(a-b))
|
s168143748
|
Accepted
| 17 | 2,940 | 180 |
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
a, b = 0, 0
for i in range(len(l)):
if i % 2 == 0:
a += l[i]
else:
b += l[i]
print(abs(a-b))
|
s176851211
|
p02806
|
u094191970
| 2,525 | 1,048,576 |
Wrong Answer
| 21 | 3,316 | 196 |
Niwango created a playlist of N songs. The title and the duration of the i-th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X. Find the duration of time when some song was played while Niwango was asleep.
|
n=int(input())
l=[input().split() for i in range(n)]
x=input()
ans=0
sum=0
for i,j in l:
print(i,j)
if i!=x:
ans+=int(j)
else:
ans+=int(j)
break
for i,j in l:
sum+=int(j)
print(sum-ans)
|
s439843186
|
Accepted
| 31 | 9,156 | 269 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(input())
l=[input().split() for i in range(n)]
x=input()
ans=0
c=False
for s,t in l:
if c:
ans+=int(t)
if x==s:
c=True
print(ans)
|
s443848828
|
p03129
|
u671239754
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 159 |
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
|
A, B = map(int, input().split())
line = []
for k in range(0,A):
line.append(k)
line = line[1::2]
if len(line) >= B:
print("YES")
else:
print("NO")
|
s923194643
|
Accepted
| 17 | 2,940 | 164 |
A, B = map(int, input().split())
line = []
for k in range(0,A+1):
line.append(k)
line = line[1::2]
if len(line) >= B:
print("YES")
else:
print("NO")
|
s364751745
|
p02275
|
u022407960
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,864 | 695 |
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail: Counting-Sort(A, B, k) 1 for i = 0 to k 2 do C[i] = 0 3 for j = 1 to length[A] 4 do C[A[j]] = C[A[j]]+1 5 /* C[i] now contains the number of elements equal to i */ 6 for i = 1 to k 7 do C[i] = C[i] + C[i-1] 8 /* C[i] now contains the number of elements less than or equal to i */ 9 for j = length[A] downto 1 10 do B[C[A[j]]] = A[j] 11 C[A[j]] = C[A[j]]-1 Write a program which sorts elements of given array ascending order based on the counting sort.
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def counting_sort(A, k):
B = [0] * k
C = [0] * k
for j in range(array_length):
C[A[j]] += 1
print('1', C[:array_length])
for i in range(1, k):
C[i] += C[i - 1]
print('2', C[:array_length])
for m in range(array_length - 1, -1, -1):
B[C[A[m]]] = A[m]
C[A[m]] -= 1
return B[1:array_length + 1]
if __name__ == '__main__':
_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1].split()))
assert len(array) == array_length
MAX_ELEM = int(1e4 + 1)
result = counting_sort(A=array, k=MAX_ELEM)
print(*result)
|
s279301699
|
Accepted
| 2,380 | 220,968 | 789 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def counting_sort(A, max_occurance):
result = [0] * array_length
count_list = [0] * max_occurance
for j in range(array_length):
count_list[A[j]] += 1
# print('step-1', C[:array_length])
for i in range(1, max_occurance):
count_list[i] += count_list[i - 1]
# print('step-2', C[:array_length])
for m in array[::-1]:
result[count_list[m] - 1] = m
count_list[m] -= 1
return result
if __name__ == '__main__':
_input = sys.stdin.readlines()
array_length = int(_input[0])
array = list(map(int, _input[1].split()))
assert len(array) == array_length
max_elem = int(1e4)
result = counting_sort(A=array, max_occurance=max_elem)
print(*result)
|
s093486317
|
p03359
|
u050708958
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 63 |
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
a, b = map(int, input().split())
print(a - (0 if a < b else 1))
|
s774680618
|
Accepted
| 17 | 2,940 | 64 |
a, b = map(int, input().split())
print(a - (0 if a <= b else 1))
|
s094355466
|
p02612
|
u299645128
| 2,000 | 1,048,576 |
Wrong Answer
| 29 | 9,144 | 24 |
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.
|
print(int(input())%1000)
|
s047665739
|
Accepted
| 28 | 9,156 | 84 |
X = int(input())
lack = X % 1000
if lack == 0:
print(0)
else:
print(1000 - lack)
|
s518913832
|
p03457
|
u279229189
| 2,000 | 262,144 |
Wrong Answer
| 629 | 13,252 | 640 |
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
t = []
x = []
y = []
t.append(0)
x.append(0)
y.append(0)
for i in (range(0, 1000000, 1)):
try:
c = input()
if i == 0:
N = int(c)
else:
t.append(int(c.split(" ")[0]))
x.append(int(c.split(" ")[1]))
y.append(int(c.split(" ")[2]))
except:
break
for i in range(0, len(t) - 1, 1):
con1 = t[i + 1] >= (x[i + 1] + y[i + 1])
dt = t[i+1] - t[i]
dist = (x[i+1]-x[i]) + (y[i+1] - y[i])
print("{0} {1} {2}".format(con1, dist, dt))
if con1 is True and (dt - dist) %2 == 0:
print("yes")
else:
print("No")
break
|
s978324313
|
Accepted
| 436 | 11,844 | 603 |
t = []
x = []
y = []
t.append(0)
x.append(0)
y.append(0)
for i in (range(0, 1000000, 1)):
try:
c = input()
if i == 0:
N = int(c)
else:
t.append(int(c.split(" ")[0]))
x.append(int(c.split(" ")[1]))
y.append(int(c.split(" ")[2]))
except:
break
for i in range(0, len(t) - 1, 1):
con1 = t[i + 1] >= (x[i + 1] + y[i + 1])
dt = t[i+1] - t[i]
dist = (x[i+1]-x[i]) + (y[i+1] - y[i])
if con1 is True and (dt - dist) %2 == 0:
ans = "Yes"
else:
ans = "No"
break
print(ans)
|
s390763625
|
p03697
|
u594762426
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 71 |
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
|
s = str(input())
if s == set(s):
print("yes")
else:
print("no")
|
s836843782
|
Accepted
| 17 | 2,940 | 92 |
h , w = map(int, input().split())
if(h + w < 10):
print(h + w)
else:
print("error")
|
s754895803
|
p03377
|
u271469978
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 81 |
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
|
a, b, x = map(int, input().split())
print('Yes' if a <= x and a+b >= x else 'No')
|
s209537698
|
Accepted
| 17 | 2,940 | 81 |
a, b, x = map(int, input().split())
print('YES' if a <= x and a+b >= x else 'NO')
|
s093687609
|
p03129
|
u470717435
| 2,000 | 1,048,576 |
Wrong Answer
| 18 | 3,060 | 116 |
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
|
import math
n, k = [int(i) for i in input().split()]
if math.ceil(n-1) < k:
print("No")
else:
print("Yes")
|
s474900228
|
Accepted
| 17 | 2,940 | 116 |
import math
n, k = [int(i) for i in input().split()]
if math.ceil(n/2) < k:
print("NO")
else:
print("YES")
|
s450735130
|
p03457
|
u201565171
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 297 |
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N=int(input())
pre_t=0
pre_x=0
pre_y=0
for i in range(N):
now_t,now_x,now_y=list(map(int,input().split()))
d=abs(pre_x-now_x)+abs(pre_y-now_y)
t=pre_t-now_t
if d<=t and t%2==d%2:
flg=1
else:
flg=0
break
if flg==1:
print('Yes')
else:
print('No')
|
s898556346
|
Accepted
| 407 | 3,060 | 335 |
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
for i in range(N):
now_t,now_x,now_y = list(map(int,input().split()))
d = abs(now_x - pre_x) + abs(now_y - pre_y)
t = now_t - pre_t
if d <= t and t % 2 == d % 2:
flg = 1
else:
flg = 0
break
if flg == 1:
print('Yes')
else:
print('No')
|
s739390660
|
p03637
|
u107269063
| 2,000 | 262,144 |
Wrong Answer
| 64 | 14,252 | 296 |
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective.
|
N = int(input())
l = list(map(int,input().split()))
num_odd = 0
num_even = 0
num_four = 0
for i in l:
if i % 4 == 0:
num_four += 1
elif i % 2 == 0:
num_even += 1
else:
num_odd += 1
if num_four <= 2 * num_odd:
ans = "No"
else:
ans = "Yes"
print(ans)
|
s807660638
|
Accepted
| 65 | 14,252 | 359 |
N = int(input())
l = list(map(int,input().split()))
num_odd = 0
num_even = 0
num_four = 0
for i in l:
if i % 2 == 1:
num_odd += 1
elif i % 4 == 0:
num_four += 1
else:
num_even += 1
if num_four + 1 > num_odd:
ans = "Yes"
elif num_four + 1 == num_odd and num_even == 0:
ans = "Yes"
else:
ans = "No"
print(ans)
|
s635793848
|
p03435
|
u466478199
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 343 |
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
|
l=[]
for i in range(3):
l1=list(map(int,input().split()))
l.append(l1)
flag=0
for i in range(l[0][0]+1):
y0=l[0][0]-i
y1=l[1][0]-i
y2=l[2][0]-i
x1=l[0][1]-y1
x2=l[0][2]-y1
if l[1][1]==y1+x1 and l[1][2]==y1+x2 and l[2][1]==y2+x1 and l[2][2]==y2+x2:
flag=1
else:
continue
if flag==1:
print('Yes')
else:
print('No')
|
s289848634
|
Accepted
| 18 | 3,064 | 297 |
l=[]
for i in range(3):
l1=list(map(int,input().split()))
l.append(l1)
flag=0
y0=l[0][0]-0
y1=l[1][0]-0
y2=l[2][0]-0
x1=l[0][1]-y0
x2=l[0][2]-y0
if l[1][1]==y1+x1 and l[1][2]==y1+x2 and l[2][1]==y2+x1 and l[2][2]==y2+x2:
flag=1
else:
pass
if flag==1:
print('Yes')
else:
print('No')
|
s792193938
|
p02865
|
u366886346
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 31 |
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
|
n=int(input())
print(-(n//-2))
|
s637152220
|
Accepted
| 17 | 2,940 | 31 |
n=int(input())
print((n-1)//2)
|
s617576533
|
p02612
|
u556610039
| 2,000 | 1,048,576 |
Wrong Answer
| 29 | 9,144 | 36 |
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.
|
num = int(input())
print(num % 1000)
|
s074228911
|
Accepted
| 31 | 9,152 | 81 |
num = int(input())
val = num % 1000
if val == 0: print(0)
else: print(1000 - val)
|
s871910720
|
p03636
|
u423624748
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 65 |
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()
slen =len(s)
ans = s[0:1]+str(slen)+s[-1:]
print(ans)
|
s028358773
|
Accepted
| 17 | 2,940 | 67 |
s = input()
slen =len(s)
ans = s[0:1]+str(slen-2)+s[-1:]
print(ans)
|
s249864500
|
p03048
|
u684120680
| 2,000 | 1,048,576 |
Wrong Answer
| 1,641 | 3,060 | 243 |
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this?
|
r,g,b,n = [int(i) for i in input().split()]
cnt = 0
for i in range(n//r+1):
n_r = i*r
if n_r > n:
break
for j in range(n//g+1):
n_rg = j*g + n_r
if n_rg > n:
break
if n_rg%b == 0:
cnt += 1
print(cnt)
|
s602590805
|
Accepted
| 1,885 | 3,060 | 247 |
r,g,b,n = [int(i) for i in input().split()]
cnt = 0
for i in range(n//r+1):
n_r = i*r
if n_r > n:
break
for j in range(n//g+1):
n_rg = j*g + n_r
if n_rg > n:
break
if (n-n_rg)%b == 0:
cnt += 1
print(cnt)
|
s899520289
|
p03456
|
u553070631
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 177 |
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(int,input().split())
ab=10*a+b
if ab==1 or ab==4 or ab ==9 or ab==16 or ab==25 or ab==36 or ab==49 or ab==64 or ab==81 or ab==100:
print('Yes')
else:
print('No')
|
s220109746
|
Accepted
| 17 | 2,940 | 149 |
a,b=input().split()
ab=int(a+b)
a=0
for i in range (4,317):
if ab==i*i:
print('Yes')
a=1
break
if a==0:
print('No')
|
s817169058
|
p03151
|
u489959379
| 2,000 | 1,048,576 |
Wrong Answer
| 163 | 20,332 | 442 |
A university student, Takahashi, has to take N examinations and pass all of them. Currently, his _readiness_ for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination. Takahashi thinks that he may not be able to pass all the examinations, and he has decided to ask a magician, Aoki, to change the readiness for as few examinations as possible so that he can pass all of them, while not changing the total readiness. For Takahashi, find the minimum possible number of indices i such that A_i and C_i are different, for a sequence C_1, C_2, ..., C_{N} that satisfies the following conditions: * The sum of the sequence A_1, A_2, ..., A_{N} and the sum of the sequence C_1, C_2, ..., C_{N} are equal. * For every i, B_i \leq C_i holds. If such a sequence C_1, C_2, ..., C_{N} cannot be constructed, print -1.
|
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff_AB = sum(A) - sum(B)
if diff_AB < 0:
print(-1)
exit()
Diff = []
for i in range(n):
diff = A[i] - B[i]
Diff.append(diff)
Diff = sorted(Diff)
print(Diff)
res = 0
for i in range(n):
if Diff[i] < 0:
res += 1
else:
if Diff[i] <= diff_AB:
diff_AB -= Diff[i]
else:
diff_AB = 0
res += 1
if diff_AB > 0:
res += 1
print(res)
|
s130492427
|
Accepted
| 125 | 19,112 | 733 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff_AB = sum(A) - sum(B)
if diff_AB < 0:
print(-1)
exit()
Diff = []
for i in range(n):
Diff.append(A[i] - B[i])
Diff.sort()
res = 0
for j in range(n):
if Diff[j] < 0:
res += 1
else:
if Diff[j] <= diff_AB:
diff_AB -= Diff[j]
else:
diff_AB = 0
res += 1
if diff_AB > 0:
res += 1
print(res)
if __name__ == '__main__':
resolve()
|
s421963328
|
p03693
|
u016901717
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 71 |
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r,g,b = map(int,input().split())
print("YES" if (g+b)%4==0 else "NO" )
|
s899093597
|
Accepted
| 18 | 2,940 | 74 |
r,g,b = map(int,input().split())
print("YES" if (10*g+b)%4==0 else "NO" )
|
s039422281
|
p00436
|
u811733736
| 1,000 | 131,072 |
Wrong Answer
| 30 | 7,704 | 796 |
1 から 2n の数が書かれた 2n 枚のカードがあり,上から 1, 2, 3, ... , 2n の順に積み重なっている. このカードを,次の方法を何回か用いて並べ替える. **整数 k でカット** 上から k 枚のカードの山 A と 残りのカードの山 B に分けた後, 山 A の上に山 B をのせる. **リフルシャッフル** 上から n 枚の山 A と残りの山 B に分け, 上から A の1枚目, B の1枚目, A の2枚目, B の2枚目, …, A の n枚目, B の n枚目, となるようにして, 1 つの山にする. 入力の指示に従い,カードを並び替えたあとのカードの番号を,上から順番に出力するプログラムを作成せよ.
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
def main(args):
n = int(input())
m = int(input())
cards = [x for x in range(1, (2*n)+1)]
for _ in range(m):
op = input().strip('\n')
if op == '0':
temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
cards = list(flatten(temp))
else:
# cut(k)
k = int(op)
cards = cards[:k] + cards[k:]
print('\n'.join(map(str, cards)))
if __name__ == '__main__':
main(sys.argv[1:])
|
s600604529
|
Accepted
| 30 | 7,796 | 793 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
cards = []
def main(args):
global cards
n = int(input())
m = int(input())
cards = [x for x in range(1, (2*n)+1)]
for _ in range(m):
op = int(input())
if op == 0:
temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
cards = list(flatten(temp))
else:
# cut(k)
cards = cards[op:] + cards[:op]
print('\n'.join(map(str, cards)))
if __name__ == '__main__':
main(sys.argv[1:])
|
s657333910
|
p02396
|
u382692819
| 1,000 | 131,072 |
Wrong Answer
| 130 | 7,216 | 122 |
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.
|
s = input()
i=1
while True:
print("case {0}: {1}".format(i,s))
i += 1
s = input()
if s=="0":
break
|
s081656829
|
Accepted
| 130 | 7,784 | 137 |
a = []
i = 0
while True:
n = input()
if n == "0":
break
a.append(n)
i += 1
print("Case {0}: {1}".format(i,n))
|
s021312620
|
p03853
|
u648890761
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 107 |
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).
|
a = input().split()
n = int(a[0])
m = a[1]
for i in range(1, n):
s = input()
print(s + "\n" + s)
|
s820310349
|
Accepted
| 17 | 3,060 | 198 |
a = input().split()
n = int(a[0])
m = a[1]
s = "";
for i in range(0, n):
tmp = input()
if i != 0:
s = s + "\n" + tmp + "\n" + tmp
else:
s = s + tmp + "\n" + tmp
print(s)
|
s122544739
|
p02645
|
u913294360
| 2,000 | 1,048,576 |
Wrong Answer
| 24 | 9,028 | 39 |
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
a=input()
str = list(a)
print(str[0:2])
|
s799687535
|
Accepted
| 23 | 8,844 | 37 |
a=input()
#str = list(a)
print(a[:3])
|
s837046772
|
p03737
|
u264265458
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 43 |
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()
print(a[0]+b[0]+c[0])
|
s234963822
|
Accepted
| 17 | 2,940 | 67 |
a,b,c=input().split()
print(a[0].upper()+b[0].upper()+c[0].upper())
|
s721319111
|
p03447
|
u128859393
| 2,000 | 262,144 |
Wrong Answer
| 24 | 3,060 | 233 |
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?
|
N = int(input())
cnt1 = list(map(int, input().split()))
cnt2 = list(map(int, input().split()))
max_candies = 0
for i in range(N):
temp = sum(cnt1[:i]) + sum(cnt2[i:])
max_candies = max(temp, max_candies)
print(max_candies)
|
s731954228
|
Accepted
| 17 | 2,940 | 61 |
X, A, B = [int(input()) for _ in range(3)];print((X - A) % B)
|
s974172348
|
p03643
|
u785066634
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 25 |
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
|
n=input()
print ('ABC',n)
|
s778399725
|
Accepted
| 17 | 2,940 | 30 |
n=str(input())
print ('ABC'+n)
|
s529669392
|
p03409
|
u947823593
| 2,000 | 262,144 |
Wrong Answer
| 24 | 3,064 | 683 |
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.
|
#coding=utf-8
def solve(abs, cds):
abs = sorted(abs, key = lambda x: -1 * x[1]) #sorted by y
cds = sorted(cds, key = lambda x: x[0]) #sorted by x
count = 0
for r in cds:
print(r)
_abs = list(filter(lambda x: r[0] > x[0] and r[1] > x[1], abs))
if len(_abs) == 0:
continue
del abs[abs.index(_abs[0])]
count += 1
return count
if __name__ == '__main__':
N = int(input())
abs = []
cds = []
for _ in range(N):
abs = abs + [list(map(lambda x: int(x), input().split()))]
for _ in range(N):
cds = cds + [list(map(lambda x: int(x), input().split()))]
print(solve(abs, cds))
|
s516385186
|
Accepted
| 20 | 3,064 | 666 |
#coding=utf-8
def solve(abs, cds):
abs = sorted(abs, key = lambda x: -1 * x[1]) #sorted by y
cds = sorted(cds, key = lambda x: x[0]) #sorted by x
count = 0
for r in cds:
_abs = list(filter(lambda x: r[0] > x[0] and r[1] > x[1], abs))
if len(_abs) == 0:
continue
del abs[abs.index(_abs[0])]
count += 1
return count
if __name__ == '__main__':
N = int(input())
abs = []
cds = []
for _ in range(N):
abs = abs + [list(map(lambda x: int(x), input().split()))]
for _ in range(N):
cds = cds + [list(map(lambda x: int(x), input().split()))]
print(solve(abs, cds))
|
s879834360
|
p02645
|
u481187938
| 2,000 | 1,048,576 |
Wrong Answer
| 24 | 9,364 | 712 |
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him.
|
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
s = input()
print(s)
main()
|
s654651183
|
Accepted
| 26 | 9,384 | 737 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
def main():
s = input()
print(s[0:3])
main()
|
s771263054
|
p04011
|
u371132735
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 97 |
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
n = int(input())
k = int(input())
x = int(input())
y = int(input())
print(((n-k) * x) + (k * y))
|
s493462608
|
Accepted
| 17 | 2,940 | 130 |
n = int(input())
k = int(input())
x = int(input())
y = int(input())
if n-k>0:
print(((n-k) * y) + (k * x))
else:
print(n * x)
|
s785736866
|
p03130
|
u671239754
| 2,000 | 1,048,576 |
Wrong Answer
| 18 | 3,064 | 290 |
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
|
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
k = 0
if A[1] - A[0] == 2:
k += 1
if B[1] - B[0] == 2:
k += 1
if C[1] - C[0] == 2:
k += 1
if k == 1:
print("No")
else:
print("Yes")
|
s821812770
|
Accepted
| 18 | 3,060 | 291 |
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
k = 0
if A[1] - A[0] == 2:
k += 1
if B[1] - B[0] == 2:
k += 1
if C[1] - C[0] == 2:
k += 1
if k == 1:
print("NO")
else:
print("YES")
|
s406752979
|
p04011
|
u777028980
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 109 |
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
a=int(input())
b=int(input())
c=int(input())
d=int(input())
if(a>b):
print(a*c+(b-a)*d)
else:
print(a*c)
|
s969825511
|
Accepted
| 18 | 2,940 | 111 |
a=int(input())
b=int(input())
c=int(input())
d=int(input())
if(a>b):
print(b*c+(a-b)*d)
else:
print(a*c)
|
s374214293
|
p03712
|
u721425712
| 2,000 | 262,144 |
Wrong Answer
| 20 | 3,316 | 215 |
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
|
# B
h, w = map(int, input().split())
a = []
for _ in range(h):
a.append('#' + input() + '#')
from collections import deque
a = deque(a)
a.appendleft('#'*w)
a.append('#'*w)
for i in a:
print(''.join(i))
|
s355422958
|
Accepted
| 31 | 3,444 | 223 |
# B
h, w = map(int, input().split())
a = []
for _ in range(h):
a.append('#' + input() + '#')
from collections import deque
a = deque(a)
a.appendleft('#'*(w+2))
a.append('#'*(w+2))
for i in a:
print(''.join(i))
|
s092353407
|
p02613
|
u805011545
| 2,000 | 1,048,576 |
Wrong Answer
| 162 | 9,228 | 320 |
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
|
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
st = str(input())
if(st == 'AC'):
ac += 1
elif(st == 'WA'):
wa += 1
elif(st == 'TLE'):
tle += 1
else:
re += 1
print('AC × {}'.format(ac))
print('WA × {}'.format(wa))
print('TLE × {}'.format(tle))
print('RE × {}'.format(re))
|
s486686464
|
Accepted
| 164 | 9,212 | 316 |
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
st = str(input())
if(st == 'AC'):
ac += 1
elif(st == 'WA'):
wa += 1
elif(st == 'TLE'):
tle += 1
else:
re += 1
print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))
|
s149866897
|
p00015
|
u408260374
| 1,000 | 131,072 |
Wrong Answer
| 30 | 6,724 | 159 |
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
|
n = int(input())
for _ in range(n):
a = sum([int(input()) for _ in range(2)])
if len(str(a)) < 80:
print(a)
else:
print('overflow')
|
s003076343
|
Accepted
| 30 | 6,720 | 104 |
for _ in range(int(input())):
a=int(input())+int(input())
print(a if a < 10**80 else 'overflow')
|
s222539102
|
p02742
|
u957098479
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 3,060 | 182 |
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
H, W = map(int,input().split())
if H % 2 == 0:
sum = W * H / 2
elif W % 2 == 0:
sum = (W * (H-1) / 2) + (W / 2)
else:
sum = (W * (H-1) / 2) + ((W+1) / 2)
print(sum)
|
s292685250
|
Accepted
| 17 | 3,060 | 226 |
H,W = map(int,input().split())
if (H == 1)or(W == 1):
sum = 1
elif H % 2 == 0:
sum = W * H // 2
elif W % 2 == 0:
sum = (W * (H-1) // 2) + (W // 2)
else:
sum = (W * (H-1) // 2) + ((W+1) // 2)
print(int(sum))
|
s740025450
|
p03943
|
u037901699
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 118 |
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.
|
a, b, c = map(int, input().split())
if a == b + c or b == a + c or c == a + b:
print("YES")
else:
print("NO")
|
s959262272
|
Accepted
| 17 | 2,940 | 118 |
a, b, c = map(int, input().split())
if a == b + c or b == a + c or c == a + b:
print("Yes")
else:
print("No")
|
s258612145
|
p04029
|
u367130284
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 29 |
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
n=int(input());print(n*-~n/2)
|
s113091885
|
Accepted
| 17 | 2,940 | 33 |
print(sum(range(int(input())+1)))
|
s284039638
|
p03555
|
u131411061
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 109 |
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
C = [input() for _ in range(2)]
tmp = C[0] + C[1]
if tmp == tmp[::-1]:
print('Yes')
else:
print('No')
|
s222507443
|
Accepted
| 17 | 2,940 | 109 |
C = [input() for _ in range(2)]
tmp = C[0] + C[1]
if tmp == tmp[::-1]:
print('YES')
else:
print('NO')
|
s804990844
|
p02975
|
u441575327
| 2,000 | 1,048,576 |
Wrong Answer
| 63 | 14,212 | 165 |
Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: - When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
|
N = int(input())
A = list(map(int, input().split()))
xor = A[0]
for i in range(N-1):
xor = xor ^ A[i+1]
if xor == 0:
print("yes")
else:
print("no")
|
s502007680
|
Accepted
| 65 | 14,116 | 165 |
N = int(input())
A = list(map(int, input().split()))
xor = A[0]
for i in range(N-1):
xor = xor ^ A[i+1]
if xor == 0:
print("Yes")
else:
print("No")
|
s882156649
|
p03141
|
u794173881
| 2,000 | 1,048,576 |
Wrong Answer
| 2,104 | 47,304 | 598 |
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
|
n = int(input())
info =[list(map(int,input().split())) for i in range(n)]
diff = [[0] for i in range(n)]
sorted_diff = [[0] for i in range(n)]
for i in range(n):
diff[i][0] = info[i][0]+info[i][1]
for i in range(n):
info[i].extend(diff[i])
#print(info)
sorted_diff = sorted(info, key=lambda x: x[2],reverse=True)
takahashi =0
aoki = 0
for i in range(n):
if i%2==0:
takahashi+= sorted_diff[0][1]
print(sorted_diff[0][1])
del sorted_diff[0]
else:
aoki+=sorted_diff[0][1]
print(sorted_diff[0][1])
del sorted_diff[0]
print(takahashi-aoki)
|
s244958536
|
Accepted
| 555 | 47,368 | 591 |
n = int(input())
info =[list(map(int,input().split())) for i in range(n)]
diff = [[0] for i in range(n)]
sorted_diff = [[0] for i in range(n)]
for i in range(n):
diff[i][0] = info[i][0]+info[i][1]
for i in range(n):
info[i].extend(diff[i])
#print(info)
sorted_diff = sorted(info, key=lambda x: x[2])
takahashi =0
aoki = 0
for i in range(n):
if i%2==0:
takahashi+= sorted_diff[-1][0]
del sorted_diff[-1]
else:
aoki+=sorted_diff[-1][1]
del sorted_diff[-1]
print(takahashi-aoki)
|
s209525907
|
p03612
|
u735008991
| 2,000 | 262,144 |
Wrong Answer
| 60 | 14,008 | 135 |
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
|
N = int(input())
P = list(map(int, input().split()))
c = 0
for i, p in enumerate(P):
c += (i+1 == p)
print(c - 1 if c >= 2 else c)
|
s483052115
|
Accepted
| 72 | 14,008 | 230 |
N = int(input())
P = list(map(int, input().split()))
c = 0
prev = False
for i, p in enumerate(P):
if p == i+1:
c += 1
if prev:
c -= 1
prev = not prev
else:
prev = False
print(c)
|
s223553972
|
p02612
|
u453683890
| 2,000 | 1,048,576 |
Wrong Answer
| 33 | 9,076 | 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.
|
l = input()
print(int(l[-3:]))
|
s438994981
|
Accepted
| 26 | 9,152 | 76 |
l = input()
if int(l[-3:]) == 0:
print(0)
else:
print(1000-int(l[-3:]))
|
s071095810
|
p03433
|
u901447859
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 79 |
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
|
if (int(input()) - int(input())) % 500 == 0:
print('Yes')
else:
print('No')
|
s297308079
|
Accepted
| 17 | 2,940 | 60 |
print('Yes' if int(input()) % 500 <= int(input()) else 'No')
|
s160360100
|
p03455
|
u315714363
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 110 |
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 -*-
a, b = map(int, input().split())
if a*b%2 == 0:
print("0dd")
else:
print("Even")
|
s300339101
|
Accepted
| 17 | 2,940 | 85 |
a, b = map(int, input().split())
if a*b%2 == 0:
print('Even')
else:
print('Odd')
|
s418173684
|
p03469
|
u973663980
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 46 |
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
s=str(input())
print(s.replace("2018","2017"))
|
s355997331
|
Accepted
| 18 | 2,940 | 46 |
s=str(input())
print(s.replace("2017","2018"))
|
s647825355
|
p02841
|
u706786134
| 2,000 | 1,048,576 |
Wrong Answer
| 153 | 12,504 | 261 |
In this problem, a date is written as Y-M-D. For example, 2019-11-30 means November 30, 2019. Integers M_1, D_1, M_2, and D_2 will be given as input. It is known that the date 2019-M_2-D_2 follows 2019-M_1-D_1. Determine whether the date 2019-M_1-D_1 is the last day of a month.
|
import numpy as np
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
x = [30] * 13
x[1] = x[3] = x[5] = x[7] = x[8] = x[10] = x[12] = 31
x[2] = 28
x[0] = 0
x = np.add.accumulate(x)
print('1' if x[m1 - 1] + d1 + 1 == x[m2 - 1] + d2 else '0')
|
s474218335
|
Accepted
| 149 | 12,396 | 211 |
import numpy as np
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
x = [30] * 13
x[1] = x[3] = x[5] = x[7] = x[8] = x[10] = x[12] = 31
x[2] = 28
x[0] = 0
print('1' if x[m1] == d1 else '0')
|
s769506378
|
p04011
|
u449555432
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 95 |
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
n=int(input())
k=int(input())
x=int(input())
y=int(input())
print(n*x if n<=k else n*x+(n-k)*y)
|
s175508335
|
Accepted
| 17 | 3,060 | 106 |
n = int(input())
k = int(input())
x = int(input())
y = int(input())
print(n*x if n <= k else k*x+(n-k)*y)
|
s109582463
|
p02401
|
u316584871
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,600 | 292 |
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
while True:
a, op, b = input().split(' ')
if (op == '+'):
print(int(a) + int(b))
elif (op == '-'):
print(int(a) - int(b))
elif (op == '*'):
print(int(a) * int(b))
elif (op == '/'):
print(int(a) / int(b))
elif (op == '?'):
break
|
s780580024
|
Accepted
| 20 | 5,648 | 333 |
import math
while True:
a, op, b = input().split()
if (op == '+'):
print(int(a) + int(b))
elif (op == '-'):
print(int(a) - int(b))
elif (op == '*'):
print(int(a) * int(b))
elif (op == '/' and int(b) != 0):
print(math.trunc((int(a) / int(b))))
elif (op == '?' ):
break
|
s934749083
|
p02694
|
u526094365
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 9,160 | 135 |
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())
ans = 100
cnt = 0
risok = 0
while ans <= X:
cnt += 1
risok = int(ans * 0.01)
ans = ans + risok
print(cnt)
|
s592875039
|
Accepted
| 24 | 9,156 | 102 |
X = int(input())
ans = 100
year = 0
while ans < X:
year += 1
ans = int(ans*1.01)
print(year)
|
s239589721
|
p03828
|
u677440371
| 2,000 | 262,144 |
Wrong Answer
| 32 | 3,552 | 2,351 |
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
N = int(input())
def make_prime_list(num):
if num < 2:
return []
prime_list = []
for prime in range(2, num + 1):
if is_prime(prime):
prime_list.append(prime)
return prime_list
def is_prime(num):
if num < 2:
return False
if num == 2 or num == 3 or num == 5:
return True
if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
return False
prime = 7
step = 4
num_sqrt = math.sqrt(num)
while prime <= num_sqrt:
if num % prime == 0:
return False
prime += step
step = 6 - step
return True
import math
from collections import defaultdict
def search_divisor_num_of_factorial_num(num):
if num <= 0:
return 0
elif num == 1 or num == 2:
return 1
else:
dict_counter = defaultdict(int)
dict_memo = defaultdict(list)
for a_num in range(2, num + 1):
num_sqrt = math.ceil(math.sqrt(a_num))
prime_list = make_prime_list(num_sqrt)
に入れるためのkeyを残しておく
now_num = a_num
for prime in prime_list:
while a_num % prime == 0:
if a_num in dict_memo:
for memo in dict_memo[a_num]:
dict_counter[memo] += 1
dict_memo[now_num].append(memo)
a_num = 1
else:
dict_counter[prime] += 1
dict_memo[now_num].append(prime)
a_num //= prime
if a_num != 1:
dict_counter[a_num] += 1
dict_memo[now_num].append(a_num)
divisor_num = 1
dict_fact = dict(dict_counter)
for value in dict_fact.values():
divisor_num *= (value + 1)
return divisor_num
print(search_divisor_num_of_factorial_num(N) % (10 ** 9 + 7))
|
s383917440
|
Accepted
| 40 | 3,064 | 1,071 |
N = int(input())
import math
def is_prime(num):
if num < 2:
return False
if num == 2 or num == 3 or num == 5:
return True
if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
return False
prime = 7
step = 4
num_sqrt = math.sqrt(num)
while prime <= num_sqrt:
if num % prime == 0:
return False
prime += step
step = 6 - step
return True
def make_prime_list(num):
if num < 2:
return []
prime_list = []
for prime in range(2, num + 1):
if is_prime(prime):
prime_list.append(prime)
return prime_list
num = N
prime_list = make_prime_list(num)
pcount={}
for p in prime_list:
pcount[p]=0
for nn in range(2,num+1):
for p in prime_list:
n=nn
if n<p:
break
while n%p==0:
n//=p
pcount[p]+=1
ans = 1
for i in pcount.values():
ans *= (i + 1)
print(ans % (10 ** 9 + 7))
|
s891857985
|
p03214
|
u782654209
| 2,525 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 30 |
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.
|
print(int((int(input())+1)/2))
|
s866857551
|
Accepted
| 17 | 2,940 | 108 |
N=int(input())
A=list(map(int,input().split(' ')))
m=sum(A)/N
B=[abs(a-m) for a in A]
print(B.index(min(B)))
|
s319015254
|
p04012
|
u114233208
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 255 |
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.
|
S = input()
ec = 0
c = {}
for each in S:
try:
c[each] += 1
if c[each] % 2 == 0:
ec -= 1
else:
ec += 1
except:
c[each] = 1
ec += 1
if (ec == 0):
print("YES")
else:
print("NO")
|
s919793159
|
Accepted
| 17 | 2,940 | 255 |
S = input()
ec = 0
c = {}
for each in S:
try:
c[each] += 1
if c[each] % 2 == 0:
ec -= 1
else:
ec += 1
except:
c[each] = 1
ec += 1
if (ec == 0):
print("Yes")
else:
print("No")
|
s098285367
|
p03162
|
u867826040
| 2,000 | 1,048,576 |
Wrong Answer
| 425 | 34,732 | 379 |
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
|
n = int(input())
abc = [list(map(int, input().split())) for i in range(n)]
dp = [-1] * n
m = max(abc[0])
dp[0] = m
x = abc[0].index(m)
for i in range(1,n):
m = -1
t = -1
for j in range(3):
if x == j:
continue
print(j,x)
if m < abc[i][j]:
m = abc[i][j]
t = j
x = t
dp[i] = m + dp[i-1]
print(dp[-1])
|
s866166841
|
Accepted
| 643 | 45,152 | 309 |
n = int(input())
abc = [tuple(map(int,input().split())) for i in range(n)]
dp = [[0,0,0] for i in range(n+1)]
for i in range(n):
for j in range(3):
for k in range(3):
if j == k:
continue
dp[i+1][k] = max(dp[i+1][k],dp[i][j]+abc[i][k])
print(max(dp[-1]))
|
s263605816
|
p03598
|
u063896676
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 217 |
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i). Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.
|
# -*- coding: utf-8 -*-
n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]
sum = 0
for i in x:
if i > k - i:
sum = sum + i
else:
sum = sum + k - i
print(sum)
|
s193880275
|
Accepted
| 17 | 2,940 | 219 |
# -*- coding: utf-8 -*-
n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]
sum = 0
for i in x:
if i < k - i:
sum = sum + i
else:
sum = sum + k - i
print(sum*2)
|
s694668422
|
p03999
|
u894623942
| 2,000 | 262,144 |
Wrong Answer
| 30 | 9,028 | 324 |
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
|
def abc045_c():
S = list(input())
for i in range(len(S)-1):
i = i * 2 + 1
S.insert(i,'+')
abc045_c2(S)
def abc045_c2(S):
cnt = 0
for i in range(S.count('+')):
cnt += eval(''.join(S))
i = i + 1
del S[i]
print(cnt)
if __name__ == '__main__':
abc045_c()
|
s501776793
|
Accepted
| 27 | 9,120 | 199 |
def dfs(i, f):
if i == n - 1:
return sum(list(map(int, f.split('+'))))
return dfs(i + 1, f + a[i + 1]) + dfs(i + 1, f + '+' + a[i + 1])
a = input()
n = len(a)
print(dfs(0, a[0]))
|
s598238941
|
p00113
|
u811733736
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,624 | 908 |
2 つの正の整数 p, q を入力し、 p / q を小数として正確に表現することを考えます。(ただし、0 < p < q < 106とします。) このとき、結果は * 有限の桁で正確に表現できる。 * ある桁の範囲を繰り返す循環小数となる。 のいずれかとなります。筆算と同じ手順で1桁ずつ小数部を求めていくと、 * 割り切れた(余りが 0 になった)なら、そこまでの桁で正確に表現できた。 * 1度出てきた余りが、再び現れたなら、循環した。 と区別できます。 2 つの整数 p, q を入力すると、 p / q を小数で表した時の、小数部を出力するプログラムを作成してください。 ただし、 * 結果が有限の桁で正確に表現できる時は、数値だけを 1 行に出力してください。 * 結果が循環小数になる時は次のように 2 行に出力してください。 * 最初の行に、循環する部分までの数字を出力してください。 * 次の行には、循環しない部分の下には空白を出力し、循環する部分の下には「^」を出力してください。 * いずれの場合も数字列は 80 文字を超えることはないものとします。
|
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0113
"""
import sys
def solve(p, q):
quotients = []
mods = []
cyclic = False
cycle_start = 0
cycle_length = 0
while True:
mods.append(p)
p *= 10
quotients.append(p // q)
p = p % q
if p == 0:
break
if p in mods:
cyclic = True
cycle_start = mods.index(p)
cycle_length = len(quotients) - mods.index(p)
break
return cyclic, quotients, cycle_start, cycle_length
def main(args):
p = 100000
q = 32768
cyclic, quotients, cycle_start, cycle_length = solve(p, q)
if cyclic:
print(''.join(map(str, quotients)))
print(' '*cycle_start + '^'*cycle_length)
else:
print(''.join(map(str, quotients)))
if __name__ == '__main__':
main(sys.argv[1:])
|
s841950956
|
Accepted
| 30 | 7,688 | 987 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0113
"""
import sys
def solve(p, q):
quotients = []
mods = []
cyclic = False
cycle_start = 0
cycle_length = 0
while True:
mods.append(p)
p *= 10
quotients.append(p // q)
p = p % q
if p == 0:
break
if p in mods:
cyclic = True
cycle_start = mods.index(p)
cycle_length = len(quotients) - mods.index(p)
break
return cyclic, quotients, cycle_start, cycle_length
def main(args):
for line in sys.stdin:
p, q = [int(x) for x in line.strip().split(' ')]
cyclic, quotients, cycle_start, cycle_length = solve(p, q)
if cyclic:
print(''.join(map(str, quotients)))
print(' '*cycle_start + '^'*cycle_length)
else:
print(''.join(map(str, quotients)))
if __name__ == '__main__':
main(sys.argv[1:])
|
s721701318
|
p02606
|
u701638736
| 2,000 | 1,048,576 |
Wrong Answer
| 29 | 9,108 | 120 |
How many multiples of d are there among the integers between L and R (inclusive)?
|
a,b,c = input().split()
count = 0
for i in range(int(b)):
i+=int(a)
if i % int(c) == 0:
count+=1
print(count)
|
s049997241
|
Accepted
| 32 | 9,156 | 133 |
a,b,c = input().split()
count = 0
num = int(a)
while num <= int(b):
if num % int(c) == 0:
count+=1
num += 1
print(count)
|
s696489772
|
p03555
|
u498401785
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 115 |
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
|
a = input()
b = input()
if(a[0] == b[2] and a[1] == b[1] and a[2] == b[0]):
print("Yes")
else:
print("No")
|
s527783636
|
Accepted
| 17 | 2,940 | 114 |
a = input()
b = input()
if(a[0] == b[2] and a[1] == b[1] and a[2] == b[0]):
print("YES")
else:
print("NO")
|
s711034751
|
p02678
|
u346395915
| 2,000 | 1,048,576 |
Wrong Answer
| 20 | 9,088 | 11 |
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
|
print('No')
|
s363539084
|
Accepted
| 1,380 | 191,460 | 548 |
from collections import deque
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]
ans = [deque([]) for _ in range(m+10)]
ans2 = [[] for _ in range(m+10)]
for i in range(m):
s = li[i][0]
t = li[i][1]
ans[s].append(t)
ans[t].append(s)
stack = deque([1])
while stack:
v = stack[0]
if ans[v]:
w = ans[v].popleft()
if True:
ans2[w].append(v)
stack.append(w)
else:
stack.popleft()
print('Yes')
for i in range(2, n+1):
print(ans2[i][0])
|
s908233789
|
p04046
|
u786020649
| 2,000 | 262,144 |
Time Limit Exceeded
| 2,206 | 24,428 | 656 |
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7.
|
h,w,a,b=map(int,input().split())
p=10**9+7
#p=127
def modp_factorial(n):
s=1
for x in range(1,h+1):
s=(s*x) % p
return s
def modp_prod(lst):
s=1
for x in lst:
s=(s*x)%p
return s
def inv(n):
s=1
q=p-2
while q>0:
if q&1:
s=s*n % p
n=n*n
q>>=1
return s
l=[1]
f=1
for x in range(1,h+w+1):
f=f*x % p
l.append(f)
invl=[inv(l[-1])]
for n in range(h+w,1,-1):
invl.append((invl[-1]*n) % p)
invl.append(1)
invl.reverse()
s=0
for x in range(1,h-a+1):
s=s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])% p
print(s)
|
s563161959
|
Accepted
| 245 | 24,744 | 670 |
h,w,a,b=map(int,input().split())
p=10**9+7
#p=127
def modp_factorial(n):
s=1
for x in range(1,h+1):
s=(s*x) % p
return s
def modp_prod(lst):
s=1
for x in lst:
s=(s*x)%p
return s
def inv(n):
s=1
q=p-2
while q>0:
if q&1:
s=(s*n) % p
n=(n*n) % p
q>>=1
return s
l=[1]
f=1
for x in range(1,h+w):
f=(f*x) % p
l.append(f)
invl=[inv(l[-1])]
for n in range(h+w-1,1,-1):
invl.append((invl[-1]*n) % p)
invl.append(1)
invl.reverse()
s=0
for x in range(1,h-a+1):
s=(s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])) % p
print(s)
|
s539217672
|
p03645
|
u273010357
| 2,000 | 262,144 |
Wrong Answer
| 2,105 | 41,288 | 402 |
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
|
from operator import itemgetter
N, M = map(int, input().split())
ab = []
for i in range(M):
a,b = map(int, input().split())
ab.append((a,b))
ab.sort(key=itemgetter(0))
print(ab)
fl = False
for i,j in ab:
if i!=1:
continue
for k,l in ab:
if i==1 and (j!=k or l!=N):
continue
else:
fl = True
print('POSSIBLE') if fl else print('IMPOSSIBLE')
|
s967619344
|
Accepted
| 750 | 48,144 | 259 |
from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(list)
for i in range(M):
a,b = map(int, input().split())
d[a].append(b)
for j in d[1]:
if N in d[j]:
print('POSSIBLE')
exit()
print('IMPOSSIBLE')
|
s017110861
|
p03997
|
u396495667
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 68 |
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
A = int(input())
B = int(input())
H = int(input())
print((A+B)*H/2)
|
s015899400
|
Accepted
| 17 | 2,940 | 87 |
A = int(input())
B = int(input())
H = int(input())
answer = (H*(A+B)//2)
print(answer)
|
s378601941
|
p02612
|
u916358282
| 2,000 | 1,048,576 |
Wrong Answer
| 31 | 9,072 | 28 |
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.
|
def pay(N):
return N % 1000
|
s266589897
|
Accepted
| 25 | 9,124 | 54 |
N = int(input())
N = (1000 - N % 1000) % 1000
print(N)
|
s408154657
|
p02235
|
u831244171
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,620 | 644 |
For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\\{b,c,a\\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\\{b,c,b,a\\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\\{b,c,b,a\\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters.
|
q = int(input())
for i in range(q):
x = list(input())
y = list(input())
max_count = 0
for j in range(len(x)):
for k in range(len(y)):
count = 0
if x[j] == y[k]:
count += 1
ret = j
ret_2 = k
while j < len(x) -1 and k < len(y) -1:
j += 1
k += 1
if x[j] == y[k]:
count += 1
else:
break
j = ret
k = ret_2
max_count = max(count,max_count)
print(max_count)
|
s227202220
|
Accepted
| 4,870 | 7,704 | 397 |
q = int(input())
def lcss(x,y):
lcs = [0]*(len(x)+1)
for i in range(len(y)):
w1 = y[i]
lcs_2 = lcs[:]
for j in range(len(x)):
if x[j] == w1:
lcs[j+1] = lcs_2[j] + 1
elif lcs[j+1] < lcs[j]:
lcs[j+1] = lcs[j]
return lcs[-1]
for i in range(q):
x = input()
y = input()
print(lcss(x,y))
|
s899195852
|
p02390
|
u899891332
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,700 | 89 |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
a=int(input())
print(a/(60*60), end=':')
print(a%(60*60)/60, end=':')
print(a%(60*60*60))
|
s517638230
|
Accepted
| 30 | 7,692 | 94 |
a=int(input())
print(int(a/60/60), end=':')
print(int(a%(60*60)/60), end=':')
print(int(a%60))
|
s981782410
|
p02401
|
u592815095
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,560 | 61 |
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
a=input()
while a!="0 ? 0":
print(eval(a))
a=input()
|
s325084715
|
Accepted
| 20 | 5,556 | 73 |
while 1:
s=input()
if s.split()[1]=="?":exit()
print(int(eval(s)))
|
s844605595
|
p02390
|
u628732336
| 1,000 | 131,072 |
Wrong Answer
| 40 | 7,380 | 17 |
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
|
print(38400/3600)
|
s451844176
|
Accepted
| 20 | 7,640 | 78 |
S = int(input())
print(S // 3600, ":", S % 3600 // 60, ":", S % 60, sep = "")
|
s274671295
|
p02842
|
u512895485
| 2,000 | 1,048,576 |
Wrong Answer
| 18 | 2,940 | 86 |
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
|
n = int(input())
x = n//1.08 + 1
m = x*1.08//1
if n==m:
print(x)
else:
print(':(')
|
s619334098
|
Accepted
| 42 | 2,940 | 122 |
n = int(input())
for x in range(46297):
if (x+1)*1.08//1 == n:
print(x+1)
break
if x == 46296:
print(':(')
|
s742639186
|
p03606
|
u993461026
| 2,000 | 262,144 |
Wrong Answer
| 20 | 3,060 | 114 |
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now?
|
N = int(input())
total = 0
for i in range(N):
l, r = map(int, input().split())
total += l - r + 1
print(total)
|
s536407873
|
Accepted
| 20 | 3,060 | 114 |
N = int(input())
total = 0
for i in range(N):
l, r = map(int, input().split())
total += r - l + 1
print(total)
|
s628966173
|
p03680
|
u219180252
| 2,000 | 262,144 |
Wrong Answer
| 2,140 | 485,300 | 667 |
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym. The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up. These buttons are numbered 1 through N. When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i. When Button i is not lighten up, nothing will happen by pressing it. Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up. Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.
|
n = int(input())
edges = [[0 for _ in range(n)] for _ in range(n)]
mem = [[0 for _ in range(n)] for _ in range(n)]
dist = []
for i in range(n):
edges[i][int(input())-1] = 1
for i in range(n):
print(''.join([str(e) for e in edges[i]]))
def has_edge(edges, v, t, d):
targets = [i for i, e in enumerate(edges[v]) if e != 0]
for target in targets:
if mem[v][target] == 0:
mem[v][target] = 1
if target == t:
dist.append(d)
return True
else:
return has_edge(edges, target, t, d+1)
return False
print(min(dist)+1) if has_edge(edges, 0, 1, 0) else print(-1)
|
s316620156
|
Accepted
| 202 | 17,892 | 221 |
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
def push_buttom(v, goal):
for i in range(n):
v = edges[v]
if v == goal:
return i+1
return -1
print(push_buttom(0, 1))
|
s475927568
|
p03227
|
u416223629
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 3,064 | 73 |
You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
|
S=input()
if len(S)==2:
print(S)
else:
print(list(reversed(S)))
|
s898546549
|
Accepted
| 17 | 2,940 | 82 |
S=input()
if len(S)==2:
print(S)
else:
print(''.join(list(reversed(S))))
|
s306778940
|
p03474
|
u614181788
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 241 |
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
a,b = map(int,input().split())
s = input()
sw = 0
for i in range(len(s)):
if i == a and s[i] != '-':
sw = 1
elif i != a and s[i] == '-':
sw = 1
else:
pass
if sw == 1:
print('No')
else:
print('Yse')
|
s257098616
|
Accepted
| 17 | 3,064 | 241 |
a,b = map(int,input().split())
s = input()
sw = 0
for i in range(len(s)):
if i == a and s[i] != '-':
sw = 1
elif i != a and s[i] == '-':
sw = 1
else:
pass
if sw == 1:
print('No')
else:
print('Yes')
|
s307052975
|
p02742
|
u052221988
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 104 |
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
h, w = map(int, input().split())
ans = h * w
if ans % 2 == 1:
print(ans//2+1)
else:
print(ans/2)
|
s831832053
|
Accepted
| 17 | 3,060 | 159 |
h, w = map(int, input().split())
if h == 1 or w == 1:
ans = 1
elif h % 2 == 0 or w % 2 == 0:
ans = h * w // 2
else:
ans = h * w // 2 + 1
print(ans)
|
s225123077
|
p03469
|
u238940874
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 45 |
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
s = input()
s.replace("2017","2018")
print(s)
|
s304409340
|
Accepted
| 17 | 2,940 | 49 |
s = input()
s = s.replace("2017","2018")
print(s)
|
s285541087
|
p02612
|
u464950331
| 2,000 | 1,048,576 |
Wrong Answer
| 28 | 8,968 | 31 |
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)
|
s663819677
|
Accepted
| 27 | 9,152 | 48 |
N = int(input())
print((1000 - (N%1000))%1000)
|
s598768407
|
p03623
|
u047197186
| 2,000 | 262,144 |
Wrong Answer
| 24 | 9,060 | 98 |
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
x, a, b = map(int, input().split())
if abs(a - x) > abs(b - x):
print('A')
else:
print('B')
|
s229924855
|
Accepted
| 28 | 9,048 | 98 |
x, a, b = map(int, input().split())
if abs(a - x) > abs(b - x):
print('B')
else:
print('A')
|
s591571855
|
p03457
|
u642012866
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 284 |
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N = int(input())
nx = 0
ny = 0
nt = 0
for _ in range(N):
t, x, y = map(int, input().split())
k = abs(nx-x)+abs(ny-y)
if k > t:
print("No")
break
if (k-t)%2 != 0:
print("No")
break
nx = x
ny = y
nt = t
else:
print("Yes")
|
s986663088
|
Accepted
| 380 | 3,064 | 292 |
N = int(input())
nx = 0
ny = 0
nt = 0
for _ in range(N):
t, x, y = map(int, input().split())
k = abs(nx-x)+abs(ny-y)
if k > t-nt:
print("No")
break
if (k-(t-nt))%2 != 0:
print("No")
break
nx = x
ny = y
nt = t
else:
print("Yes")
|
s740095111
|
p03693
|
u642418876
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 89 |
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
|
r,g,b=map(int,input().split())
if (100*r+10*g+b)%4==0:
print("Yes")
else:
print("No")
|
s069386878
|
Accepted
| 17 | 2,940 | 92 |
r,g,b=map(int,input().split())
if (100*r+10*g+b)%4==0:
print("YES")
else:
print("NO")
|
s069301710
|
p03079
|
u629540524
| 2,000 | 1,048,576 |
Wrong Answer
| 23 | 8,912 | 70 |
You are given three integers A, B and C. Determine if there exists an equilateral triangle whose sides have lengths A, B and C.
|
a=input().split()
if set(a)==a:
print('Yes')
else:
print('No')
|
s558277164
|
Accepted
| 29 | 9,028 | 75 |
a=input().split()
if len(set(a))==1:
print('Yes')
else:
print('No')
|
s523308401
|
p00005
|
u811773570
| 1,000 | 131,072 |
Wrong Answer
| 40 | 7,664 | 305 |
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
|
#GCD and LCM
while True:
try:
a, b = (int(i) for i in input(). split())
x = a * b
while True:
c = a % b
a = b
b = c
if a % b == 0:
break
x = x / a
print("%d %d" % (b, x))
except:
break
|
s812636317
|
Accepted
| 30 | 7,656 | 292 |
def main():
gcd = lambda n, m : gcd(m, n % m) if m != 0 else n
while True:
try:
n, m = map(int, input().split())
g = gcd(n, m)
l = n * m // g
print(g, l)
except:
break
if __name__ == '__main__':
main()
|
s849950812
|
p03110
|
u201382544
| 2,000 | 1,048,576 |
Wrong Answer
| 20 | 3,060 | 214 |
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
|
n = int(input())
x = []
ans = 0
for i in range(n):
array = list(map(str,input().split()))
x.append(array)
if x[i][1] == "JPY":
ans += int(x[i][0])
else:
ans += int(float(x[i][0]) * 380000)
print(ans)
|
s818133356
|
Accepted
| 17 | 2,940 | 209 |
n = int(input())
x = []
ans = 0
for i in range(n):
array = list(map(str,input().split()))
x.append(array)
if x[i][1] == "JPY":
ans += int(x[i][0])
else:
ans += float(x[i][0]) * 380000
print(ans)
|
s155477142
|
p03568
|
u422104747
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 87 |
We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are _similar_ when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N and an integer sequence of length N, A_1, A_2, ..., A_N. How many integer sequences b_1, b_2, ..., b_N are there such that b_1, b_2, ..., b_N is similar to A and the product of all elements, b_1 b_2 ... b_N, is even?
|
n=int(input())
s=input().split()
x=1
for i in s:
if(int(i)%2==0):
x*=2
print(2**n-x)
|
s696654678
|
Accepted
| 18 | 2,940 | 87 |
n=int(input())
s=input().split()
x=1
for i in s:
if(int(i)%2==0):
x*=2
print(3**n-x)
|
s961493739
|
p04012
|
u732844340
| 2,000 | 262,144 |
Wrong Answer
| 41 | 3,064 | 239 |
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.
|
w = input()
flag = 0
for j in range(0,len(w)):
sum = 0
for i in range(0,len(w)):
if w[j] == w[i]:
sum += 1
if sum % 2 != 0:
print("NO")
flag = 1
break
if flag == 0:
print("YES")
|
s575317584
|
Accepted
| 171 | 3,572 | 208 |
from collections import Counter
w = input()
flag = 0
counter = Counter(w)
for word, cnt in counter.most_common():
if cnt % 2 != 0:
flag = 1
if flag == 0:
print("Yes")
else:
print("No")
|
s720289065
|
p03854
|
u089376182
| 2,000 | 262,144 |
Wrong Answer
| 23 | 6,516 | 95 |
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`.
|
import re
s = input()
print('Yes' if re.match('^(dream|dreamer|erase|eraser)+$', s) else 'No')
|
s823282616
|
Accepted
| 23 | 6,516 | 95 |
import re
s = input()
print('YES' if re.match('^(dream|dreamer|erase|eraser)+$', s) else 'NO')
|
s870128584
|
p03455
|
u078214750
| 2,000 | 262,144 |
Wrong Answer
| 29 | 9,016 | 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())
if (a*b)%2==0:
print('Odd')
else:
print('Even')
|
s530833610
|
Accepted
| 27 | 9,152 | 71 |
a, b = map(int, input().split())
print('Even' if a*b%2 == 0 else 'Odd')
|
s864331181
|
p04011
|
u934740772
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 100 |
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
if N<=K:
print(X)
else:
print(Y)
|
s824702107
|
Accepted
| 17 | 2,940 | 114 |
N=int(input())
K=int(input())
X=int(input())
Y=int(input())
if N<=K:
print(X*N)
else:
print(X*(K)+Y*(N-K))
|
s294597312
|
p03644
|
u514118270
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 123 |
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
N = int(input())
ans = 0
for i in range(100):
if N%2 == 0:
ans += 1
else:
print(ans)
exit()
|
s182466608
|
Accepted
| 17 | 2,940 | 131 |
N = int(input())
if N == 1:
print(1)
exit()
for i in range(8):
if 2**i > N:
print(2**(i-1))
exit()
|
s047363245
|
p03659
|
u437215432
| 2,000 | 262,144 |
Wrong Answer
| 314 | 33,064 | 185 |
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
|
import numpy as np
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
Min = np.inf
s = 0
for i in range(len(a)-1):
s += a[i]
Min = min(Min, abs(2 * s- total))
|
s978392472
|
Accepted
| 308 | 33,044 | 196 |
import numpy as np
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
Min = np.inf
s = 0
for i in range(len(a)-1):
s += a[i]
Min = min(Min, abs(2 * s- total))
print(Min)
|
s936553097
|
p03574
|
u395287676
| 2,000 | 262,144 |
Wrong Answer
| 37 | 3,952 | 3,329 |
You are given an H × W grid. The squares in the grid are described by H strings, S_1,...,S_H. The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W). `.` stands for an empty square, and `#` stands for a square containing a bomb. Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square. (Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.) He decides to replace each `.` in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square. Print the strings after the process.
|
import sys
def main():
# Get Args
args = _input_args() # get arguments as an array from console/script parameters.
# Call main Logic
result = _main(args)
# Output a result in a correct way.
_output_result(result)
def _main(args):
"""Write Main Logic here for the contest.
:param args: arguments
:type args: list
:return: result
:rtype: depends on your logic.
"""
# Extract arguments.
lines = args
H, W = int(lines[0].split()[0]), int(lines[0].split()[1])
field_map = get_field_map(lines[1:])
result_map = [[0 for col in range(W)] for row in range(H)]
for h in range(H):
for w in range(W):
result_map[h][w] = sweep_perimeters(h, w, field_map, H, W)
result_lines = convert_map_to_lines(result_map)
# Return something.
return result_lines
def sweep_perimeters(h, w, field_map, H, W):
found_mine = 0
if field_map[h][w] == '#':
return '#'
for i in range(h-1, h+1+1):
for j in range(w-1, w+1+1):
if (0 <= i <= H-1) and (0 <= j <= W-1):
target = field_map[i][j]
print(target)
if target == '#':
found_mine += 1
return found_mine
def get_field_map(lines):
field_maps = []
for line in lines:
elements = list(line)
field_maps.append(elements)
return field_maps
def convert_map_to_lines(result_map):
result_lines = []
for row_array in result_map:
stringfied_row = ''
for value in row_array:
value = str(value)
stringfied_row += value
result_lines.append(stringfied_row)
return result_lines
def _input_args():
# Comment-out appropriate pattern depends on subject.
# arguments = sys.argv[1:] # ptn1: get args from script parameters.
# arguments = _input().split() # ptn2: get args from 1 line console prompt with space separated.
# for multi-line console input, use this.
arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=10000000)
# Cast elements If you need.
# arguments = list(map(int, arguments)) # cast elements to int for example.
return arguments # This will be array.
def _input():
# If Subject requires interactive input, use this and patch mock in unittest.
return input()
def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=10000000):
"""Get arguments from multiple lines standard input.
:param end_of_lines_char: Strings that indicate the end of lines.
:type end_of_lines_char: list of str
:param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
:type limit: int
:return: args
:rtype list of str
"""
args = []
for i in range(limit):
try:
arg = _input()
if arg in end_of_lines_char:
break
args.append(arg)
except EOFError: # Supports EOF Style. (Very Rare case)
break
return args
def _output_result(result):
# Comment-out appropriate output pattern depends on subject.
for line in result:
print('{}'.format(str(line))) # Same as above, but more versatile.
if __name__ == '__main__':
main()
|
s568474102
|
Accepted
| 26 | 3,316 | 3,293 |
import sys
def main():
# Get Args
args = _input_args() # get arguments as an array from console/script parameters.
# Call main Logic
result = _main(args)
# Output a result in a correct way.
_output_result(result)
def _main(args):
"""Write Main Logic here for the contest.
:param args: arguments
:type args: list
:return: result
:rtype: depends on your logic.
"""
# Extract arguments.
lines = args
H, W = int(lines[0].split()[0]), int(lines[0].split()[1])
field_map = get_field_map(lines[1:])
result_map = [[0 for col in range(W)] for row in range(H)]
for h in range(H):
for w in range(W):
result_map[h][w] = sweep_perimeters(h, w, field_map, H, W)
result_lines = convert_map_to_lines(result_map)
# Return something.
return result_lines
def sweep_perimeters(h, w, field_map, H, W):
found_mine = 0
if field_map[h][w] == '#':
return '#'
for i in range(h-1, h+1+1):
for j in range(w-1, w+1+1):
if (0 <= i < H) and (0 <= j < W):
target = field_map[i][j]
if target == '#':
found_mine += 1
return found_mine
def get_field_map(lines):
field_maps = []
for line in lines:
elements = list(line)
field_maps.append(elements)
return field_maps
def convert_map_to_lines(result_map):
result_lines = []
for row_array in result_map:
stringfied_row = ''
for value in row_array:
value = str(value)
stringfied_row += value
result_lines.append(stringfied_row)
return result_lines
def _input_args():
# Comment-out appropriate pattern depends on subject.
# arguments = sys.argv[1:] # ptn1: get args from script parameters.
# arguments = _input().split() # ptn2: get args from 1 line console prompt with space separated.
# for multi-line console input, use this.
arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=10000000)
# Cast elements If you need.
# arguments = list(map(int, arguments)) # cast elements to int for example.
return arguments # This will be array.
def _input():
# If Subject requires interactive input, use this and patch mock in unittest.
return input()
def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=10000000):
"""Get arguments from multiple lines standard input.
:param end_of_lines_char: Strings that indicate the end of lines.
:type end_of_lines_char: list of str
:param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
:type limit: int
:return: args
:rtype list of str
"""
args = []
for i in range(limit):
try:
arg = _input()
if arg in end_of_lines_char:
break
args.append(arg)
except EOFError: # Supports EOF Style. (Very Rare case)
break
return args
def _output_result(result):
# Comment-out appropriate output pattern depends on subject.
for line in result:
print('{}'.format(str(line))) # Same as above, but more versatile.
if __name__ == '__main__':
main()
|
s352835199
|
p03379
|
u474925961
| 2,000 | 262,144 |
Wrong Answer
| 1,277 | 34,156 | 981 |
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.
|
import numpy as np
n=int(input())
l=list(map(int,input().split()))
arr=np.sort(np.array(l))
med=np.median(arr)
med_max=np.median(np.delete(arr,0))
med_min=np.median(np.delete(arr,n-1))
if n%2==1:
p=(n-1)//2
med_midmin=np.median(np.delete(arr,p+1))
med_mid=np.median(np.delete(arr,p))
med_midmax=np.median(np.delete(arr,p-1))
for i in range(n):
if l[i]<arr[p-1]:
print(med_max)
elif l[i]==arr[p-1]:
print(med_midmax)
elif l[i]==arr[p]:
print(med_mid)
elif l[i]==arr[p+1]:
print(med_midmin)
else:
print(med_min)
if n%2==0:
p=(n+1)//2
med_midmin=np.median(np.delete(arr,p))
med_midmax=np.median(np.delete(arr,p-1))
for i in range(n):
if l[i]<arr[p-1]:
print(med_max)
elif l[i]==arr[p-1]:
print(med_midmax)
elif l[i]==arr[p]:
print(med_midmin)
else:
print(med_min)
|
s378371826
|
Accepted
| 646 | 34,176 | 307 |
import numpy as np
n=int(input())
l=list(map(int,input().split()))
arr=np.sort(np.array(l))
med=np.median(arr)
med_max=int(np.median(np.delete(arr,0)))
med_min=int(np.median(np.delete(arr,n-1)))
p=(n+1)//2
for i in range(n):
if l[i]<=arr[p-1]:
print(med_max)
else:
print(med_min)
|
s155288221
|
p03671
|
u449555432
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 54 |
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the minimum total price of two different bells.
|
a,b,c=map(int,input().split());print(max(a+b,b+c,a+c))
|
s356065671
|
Accepted
| 18 | 2,940 | 54 |
a,b,c=map(int,input().split());print(min(a+b,b+c,a+c))
|
s530197307
|
p02678
|
u633355062
| 2,000 | 1,048,576 |
Wrong Answer
| 22 | 9,140 | 11 |
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
|
print('No')
|
s940257512
|
Accepted
| 687 | 34,748 | 528 |
from collections import deque
n, m = map(int, input().split())
dir = [[] for _ in range(n+1)]
for i in range(m):
ta, tb = map(int, input().split())
dir[ta].append(tb)
dir[tb].append(ta)
ans = [0]*(n+1)
flag = [False]*(n+1)
flag[1] = True
que = deque([1])
while que:
now = que.popleft()
for to in dir[now]:
if flag[to]:
continue
que.append(to)
flag[to] = True
ans[to] = now
print('Yes')
for i in range(2,n+1):
print(ans[i])
|
s050167814
|
p03546
|
u152061705
| 2,000 | 262,144 |
Wrong Answer
| 34 | 3,316 | 627 |
Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive). You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows: * If A_{i,j}≠-1, the square contains a digit A_{i,j}. * If A_{i,j}=-1, the square does not contain a digit. Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.
|
# python3
# utf-8
import itertools
rows_nr, cols_nr = (int(x) for x in input().split())
d1___d2___cost = []
for i in range(10):
d1___d2___cost_i___j = [int(x) for x in input().split()]
d1___d2___cost.append(d1___d2___cost_i___j)
r_c___value = []
for row in range(rows_nr):
c___value = [int(x) for x in input().split()]
r_c___value.append(c___value)
f = d1___d2___cost
for i, v, u in itertools.product(range(10), repeat=3):
f[u][v] = min(f[u][v], f[u][i] + f[i][v])
ans = 0
for row in r_c___value:
for value in row:
if value == '-1':
continue
ans += f[value][1]
print(ans)
|
s947865569
|
Accepted
| 32 | 3,316 | 625 |
# python3
# utf-8
import itertools
rows_nr, cols_nr = (int(x) for x in input().split())
d1___d2___cost = []
for i in range(10):
d1___d2___cost_i___j = [int(x) for x in input().split()]
d1___d2___cost.append(d1___d2___cost_i___j)
r_c___value = []
for row in range(rows_nr):
c___value = [int(x) for x in input().split()]
r_c___value.append(c___value)
f = d1___d2___cost
for i, v, u in itertools.product(range(10), repeat=3):
f[u][v] = min(f[u][v], f[u][i] + f[i][v])
ans = 0
for row in r_c___value:
for value in row:
if value == -1:
continue
ans += f[value][1]
print(ans)
|
s663334124
|
p03400
|
u403331159
| 2,000 | 262,144 |
Wrong Answer
| 19 | 3,316 | 287 |
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
|
N=int(input())
D,X=map(int,input().split())
A=[int(input()) for i in range(N)]
cnt=0
for i in range(N):
cnt+=1
day=1
for j in range(1,101):
if D>=j*A[i]+1:
day=j*A[i]+1
cnt+=1
print(day)
else:
break
print(cnt+X)
|
s084920278
|
Accepted
| 19 | 3,060 | 264 |
N=int(input())
D,X=map(int,input().split())
A=[int(input()) for i in range(N)]
cnt=0
for i in range(N):
cnt+=1
day=1
for j in range(1,101):
if D>=j*A[i]+1:
day=j*A[i]+1
cnt+=1
else:
break
print(cnt+X)
|
s164385838
|
p03545
|
u773686010
| 2,000 | 262,144 |
Wrong Answer
| 29 | 9,220 | 355 |
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
import itertools
moji = str(input())
A,B,C,D = int(moji[0]),int(moji[1]),int(moji[2]),int(moji[3])
Bn = [B,B*-1]
Cn = [C,C*-1]
Dn = [D,D*-1]
flg = 0
for i,j,k in itertools.product(Bn, Cn,Dn):
X = A + i + j + k
if X == 7:
break
print(str(A) + (str(i),"+"+str(i))[i >= 0]+ (str(j),"+"+str(j))[j >= 0]+ (str(k),"+"+str(k))[k >= 0])
|
s879125583
|
Accepted
| 29 | 9,216 | 360 |
import itertools
moji = str(input())
A,B,C,D = int(moji[0]),int(moji[1]),int(moji[2]),int(moji[3])
Bn = [B,B*-1]
Cn = [C,C*-1]
Dn = [D,D*-1]
flg = 0
for i,j,k in itertools.product(Bn, Cn,Dn):
X = A + i + j + k
if X == 7:
break
print(str(A) + (str(i),"+"+str(i))[i >= 0]+ (str(j),"+"+str(j))[j >= 0]+ (str(k),"+"+str(k))[k >= 0]+"=7")
|
s317004688
|
p03565
|
u354915818
| 2,000 | 262,144 |
Wrong Answer
| 1,451 | 16,812 | 1,128 |
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with `?`. One more thing he found is a sheet of paper with the following facts written on it: * Condition 1: The string S contains a string T as a contiguous substring. * Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1. Print the string S. If such a string does not exist, print `UNRESTORABLE`.
|
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import copy as cp
S = input()
T = input()
s = len(S)
t = len(T)
rst = []
for i in range(t) :
flag = False
for j in reversed(range(i , s + i - t + 1)):
if (T[i] != S[j]) & (S[j] != "?") : continue
else:
flag = True
for k in range(t) :
if (T[k] == S[j - i + k]) | (S[j - i + k] == "?"): continue
else :
flag = False
break
if flag :
x = cp.deepcopy(S)
for k in range(t) :
if (T[k] == S[j - i + k]) : x = x[ : (j-i+k-1)] + T[k] + x[(j -i +k) : ]
x = x.replace("?" , "a")
rst.append(x)
if len(rst) != 0 :
print(min(rst))
else :
print("UNRESTORABLE")
|
s429040596
|
Accepted
| 155 | 12,516 | 1,131 |
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import copy as cp
S = input()
T = input()
s = len(S)
t = len(T)
rst = []
for i in range(t) :
flag = False
for j in reversed(range(i , s + i - t + 1)):
if (T[i] != S[j]) & (S[j] != "?") : continue
else:
flag = True
for k in range(t) :
if (T[k] == S[j - i + k]) | (S[j - i + k] == "?"): continue
else :
flag = False
break
if flag :
x = cp.deepcopy(S)
for k in range(t) :
if x[j - i + k] == "?" : x = x[ : (j-i+k)] + T[k] + x[(j -i +k + 1) : ]
x = x.replace("?" , "a")
rst.append(x)
if len(rst) != 0 :
print(min(rst))
else :
print("UNRESTORABLE")
|
s636544483
|
p03729
|
u959421160
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 130 |
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
|
Nstr = input().split()
result = True
for i in range(2):
if Nstr[i][-1] != Nstr[i + 1][0]:
result = False
print(result)
|
s972190421
|
Accepted
| 17 | 2,940 | 130 |
Nstr = input().split()
result = 'YES'
for i in range(2):
if Nstr[i][-1] != Nstr[i + 1][0]:
result = 'NO'
print(result)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.