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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s728164521 | p03415 | u624475441 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 53 | We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. | print(input()[0])
print(input()[1])
print(input()[2]) | s049216430 | Accepted | 17 | 2,940 | 39 | print(input()[0]+input()[1]+input()[2]) |
s992744035 | p03409 | u123745130 | 2,000 | 262,144 | Wrong Answer | 19 | 3,064 | 309 | On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point. At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs. | n=int(input())
ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[1])
mm=sorted([list(map(int,input().split())) for _ in range(n)])
count_num=0
for i,j in mm:
for k,h in ll:
if k<=i and h<=j:
count_num+=1
ll.remove([k,h])
break
print(n,ll,mm,count_num) | s982287217 | Accepted | 19 | 3,060 | 302 | n=int(input())
ll = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: -x[1])
mm=sorted([list(map(int,input().split())) for _ in range(n)])
count_num=0
for i,j in mm:
for k,h in ll:
if k<=i and h<=j:
count_num+=1
ll.remove([k,h])
break
print(count_num)
|
s190788981 | p03435 | u329749432 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 371 | 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. | c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())
t22 = c12+c21-c11
t32 = t22+c31-c21
t23 = t22+c13-c12
t33 = t23+t32-t22
t = [t22,t23,t32,t33]
c = [c22,c23,c32,c33]
flag = True
for i in range(0,4):
if t[i]!=c[i]:
flag = False
if flag==True:
print("YES")
else:
print("NO")
| s580433472 | Accepted | 17 | 3,064 | 371 | c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())
t22 = c12+c21-c11
t32 = t22+c31-c21
t23 = t22+c13-c12
t33 = t23+t32-t22
t = [t22,t23,t32,t33]
c = [c22,c23,c32,c33]
flag = True
for i in range(0,4):
if t[i]!=c[i]:
flag = False
if flag==True:
print("Yes")
else:
print("No")
|
s917141584 | p04029 | u918935103 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 82 | 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())
count = 0
for i in range(n):
count = count + i*i
print(count) | s479805292 | Accepted | 17 | 2,940 | 80 | n = int(input())
count = 0
for i in range(n+1):
count = count + i
print(count) |
s704425244 | p03644 | u819710930 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 141 | 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())
i=1
for _ in range(9):
i**=2
if i==n:
print(i)
exit()
elif i>n:
print(i//2)
exit() | s417256142 | Accepted | 17 | 2,940 | 137 | n=int(input())
for i in range(9):
if n==2**i:
print(n)
exit()
elif n<2**i:
print(2**(i-1))
exit() |
s619228323 | p03814 | u737321654 | 2,000 | 262,144 | Wrong Answer | 17 | 3,716 | 92 | Snuke has decided to construct a string that starts with `A` and ends with `Z`, by taking out a substring of a string s (that is, a consecutive part of s). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with `A` and ends with `Z`. | s = input()
indexA = s.find("A")
indexZ = s.rfind("Z")
ans = s[indexA:indexZ + 1]
print(ans) | s721489652 | Accepted | 18 | 3,516 | 97 | s = input()
indexA = s.find("A")
indexZ = s.rfind("Z")
ans = len(s[indexA:indexZ + 1])
print(ans) |
s710966237 | p03407 | u076827647 | 2,000 | 262,144 | Wrong Answer | 347 | 20,792 | 121 | An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. | import numpy as np
a = list(map(int, input().split()))
if a[0] + a[1] >= a[2]:
print('yes')
else:
print('no')
| s795109378 | Accepted | 17 | 2,940 | 99 | a = list(map(int, input().split()))
if a[0] + a[1] >= a[2]:
print('Yes')
else:
print('No') |
s960012948 | p00007 | u503263570 | 1,000 | 131,072 | Wrong Answer | 20 | 7,540 | 36 | Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. | n=int(input())
print(n*10000+100000) | s775829602 | Accepted | 20 | 7,540 | 94 | import math
n=int(input())
r=100000
for i in range(n):
r=math.ceil(r*1.05/1000)*1000
print(r) |
s823578519 | p03693 | u903948194 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 93 | 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? | nums = int(''.join(input().split()))
if nums % 4 == 0:
print('Yes')
else:
print('No') | s149523168 | Accepted | 18 | 2,940 | 93 | nums = int(''.join(input().split()))
if nums % 4 == 0:
print('YES')
else:
print('NO') |
s589868980 | p03433 | u512623857 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 92 | E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. | n = int(input())
a = int(input())
if (n % 500) >= a:
print("NO")
else:
print("YES")
| s784114327 | Accepted | 17 | 2,940 | 92 | n = int(input())
a = int(input())
if (n % 500) <= a:
print("Yes")
else:
print("No")
|
s584009857 | p00001 | u139200784 | 1,000 | 131,072 | Wrong Answer | 20 | 7,532 | 246 | There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order. | # -*- coding: utf-8 -*-
#print a # [a1, a2, a3, ..., aN]
import sys
a = []
for line in sys.stdin:
a.append(int(line))
#print a # [a1, a2, a3, ...]
sorted(a, reverse=True)
print(a[0])
print(a[1])
print(a[2]) | s105926465 | Accepted | 40 | 7,656 | 243 | # -*- coding: utf-8 -*-
#print a # [a1, a2, a3, ..., aN]
import sys
a = []
for line in sys.stdin:
a.append(int(line))
#print a # [a1, a2, a3, ...]
a.sort(reverse=True)
print(a[0])
print(a[1])
print(a[2]) |
s876914569 | p03478 | u252828980 | 2,000 | 262,144 | Wrong Answer | 20 | 2,940 | 142 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | n,a,b = map(int,input().split())
sum1 = 0
for i in range(1,n+1):
if a<= i//10 + (i - i//10) <=b:
sum1 += i//10 + (i - i//10)
print(sum1) | s843809195 | Accepted | 48 | 3,060 | 182 | n,a,b = map(int,input().split())
sum1 = 0
ans = 0
for i in range(1,n+1):
sum1 =0
for j in range(len(str(i))):
sum1 +=int(str(i)[j])
if a<= sum1 <=b:
ans += i
print(ans) |
s811745996 | p00025 | u071010747 | 1,000 | 131,072 | Wrong Answer | 20 | 7,400 | 538 | Let's play Hit and Blow game. _A_ imagines four numbers and _B_ guesses the numbers. After _B_ picks out four numbers, _A_ answers: * The number of numbers which have the same place with numbers _A_ imagined (Hit) * The number of numbers included (but different place) in the numbers _A_ imagined (Blow) For example, if _A_ imagined numbers: 9 1 8 2 and _B_ chose: 4 1 5 9 _A_ should say 1 Hit and 1 Blow. Write a program which reads four numbers _A_ imagined and four numbers _B_ chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9. | # -*- coding:utf-8 -*-
def main():
while True:
try:
A=input().split()
B=input().split()
Hit=0
Blow=0
for b in B:
if b in A:
index=B.index(b)
print(index)
if b==A[index]:
Hit+=1
else:
Blow+=1
print(Hit,Blow)
except:
break
if __name__ == '__main__':
main() | s477121779 | Accepted | 20 | 7,400 | 505 | # -*- coding:utf-8 -*-
def main():
while True:
try:
A=input().split()
B=input().split()
Hit=0
Blow=0
for b in B:
if b in A:
index=B.index(b)
if b==A[index]:
Hit+=1
else:
Blow+=1
print(Hit,Blow)
except:
break
if __name__ == '__main__':
main() |
s907227196 | p03449 | u388323466 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 224 | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? | n = int(input())
arr = []
for i in range(2):
arr += [list(map(int,input().split()))]
ans = 0
for j in range(n):
tmp = 0
tmp += sum(arr[0][0:j+1])
tmp += sum(arr[1][j:])
print(tmp)
ans = max(ans,tmp)
print(ans)
| s652994058 | Accepted | 17 | 3,060 | 212 | n = int(input())
arr = []
for i in range(2):
arr += [list(map(int,input().split()))]
ans = 0
for j in range(n):
tmp = 0
tmp += sum(arr[0][0:j+1])
tmp += sum(arr[1][j:])
ans = max(ans,tmp)
print(ans)
|
s905952318 | p03636 | u559346857 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 37 | 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. | a,*b,c=input()
print(a,str(len(b)),c) | s027444352 | Accepted | 17 | 2,940 | 37 | a,*b,c=input()
print(a+str(len(b))+c) |
s845071632 | p02845 | u852690916 | 2,000 | 1,048,576 | Wrong Answer | 173 | 14,056 | 405 | N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green. The person numbered i says: * "In front of me, exactly A_i people are wearing hats with the same color as mine." Assuming that all these statements are correct, find the number of possible combinations of colors of the N people's hats. Since the count can be enormous, compute it modulo 1000000007. | N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007
C=[0,0,0]
ans=1
for a in A:
found=False
count=C.count(a)
if count==0:
print(0)
exit()
C[C.index(a)]+=1
ans=ans*count%MOD
print(count)
print(ans) | s849470621 | Accepted | 104 | 14,056 | 388 | N = int(input())
A = list(map(int,input().split()))
MOD = 1000000007
C=[0,0,0]
ans=1
for a in A:
found=False
count=C.count(a)
if count==0:
print(0)
exit()
C[C.index(a)]+=1
ans=ans*count%MOD
print(ans) |
s086558769 | p03068 | u943294442 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 138 | You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`. | n = int(input())
sstr = input()
k = int(input())
s = list(sstr)
for i in range(n):
if s[k-1] != s[i]:
s[i] = "*"
sStr = "".join(s) | s971947286 | Accepted | 17 | 3,060 | 150 | n = int(input())
sstr = input()
k = int(input())
s = list(sstr)
for i in range(n):
if s[k-1] != s[i]:
s[i] = "*"
sStr = "".join(s)
print(sStr) |
s419032590 | p03386 | u502731482 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 187 | Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers. |
a, b, k = map(int, input().split())
for i in range(a, a + k):
if i > b:
break
print(i)
for i in range(max(a + k, b - k), b + 1):
if i > b:
break
print(i) | s172240965 | Accepted | 18 | 3,060 | 191 |
a, b, k = map(int, input().split())
for i in range(a, a + k):
if i > b:
break
print(i)
for i in range(max(a + k, b - k + 1), b + 1):
if i > b:
break
print(i) |
s381784965 | p02608 | u222668979 | 2,000 | 1,048,576 | Wrong Answer | 954 | 9,772 | 333 | Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N). | n = int(input())
cnt = [0] * n
for x in range(1, int(n ** 0.5) + 1):
for y in range(1, int(n ** 0.5) + 1):
for z in range(1, int(n ** 0.5) + 1):
num = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
if num <= n:
print(num)
cnt[num - 1] += 1
print(*cnt, sep="\n")
| s503768365 | Accepted | 477 | 9,712 | 296 | n = int(input())
cnt = [0] * n
for x in range(1, int(n ** 0.5) + 1):
for y in range(1, int(n ** 0.5) + 1):
for z in range(1, int(n ** 0.5) + 1):
num = (x + y) ** 2 - x * y + z * (x + y + z)
if num <= n:
cnt[num - 1] += 1
print(*cnt, sep="\n")
|
s318317358 | p02409 | u964416376 | 1,000 | 131,072 | Wrong Answer | 30 | 7,752 | 280 | You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b, f, r and v which represent that v persons entered to room r of fth floor at building b. If v is negative, it means that −v persons left. Assume that initially no person lives in the building. | a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = [int(i) for i in input().split()]
a[b-1][f-1][r-1] = v
for x in a:
for y in x:
print(' '.join(map(str, y)))
print('####################') | s544270354 | Accepted | 20 | 7,688 | 355 | a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
b, f, r, v = [int(i) for i in input().split()]
a[b-1][f-1][r-1] += v
for i, x in enumerate(a):
for y in x:
for z in y:
print(' %d' % z, end='')
print('')
if i < 4 - 1:
print('####################') |
s758840822 | p03493 | u476048753 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 101 | Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble. | s = input()
ans = 0
if s[0] == "1":
ans += 1
if s[1] == "1":
ans += 1
if s[2] == "1":
ans += 1
| s822372948 | Accepted | 18 | 2,940 | 114 | s = input()
ans = 0
if s[0] == "1":
ans += 1
if s[1] == "1":
ans += 1
if s[2] == "1":
ans += 1
print(ans) |
s679557730 | p03471 | u083494782 | 2,000 | 262,144 | Wrong Answer | 794 | 3,060 | 231 | The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough. | N,Y=map(int,input().split())
#10000:i 5000:j 1000:k
i = -1
j = -1
k = -1
for i in range(N+1):
for j in range(N+1-i):
k = N - i - j
if 10000 * i + 5000 * j + 1000 * k == Y:
break
print(i,j,k)
| s842365650 | Accepted | 828 | 3,060 | 285 | N,Y=map(int,input().split())
#10000:i 5000:j 1000:k
i2 = -1
j2 = -1
k2 = -1
for i in range(N+1):
for j in range(N+1-i):
k = N - i - j
if 10000 * i + 5000 * j + 1000 * k == Y:
i2 = i
j2 = j
k2 = k
break
print(i2,j2,k2) |
s766292543 | p03399 | u705418271 | 2,000 | 262,144 | Wrong Answer | 30 | 9,168 | 92 | You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. | A=int(input())
B=int(input())
C=int(input())
D=int(input())
a=max(A,B)
b=max(C,D)
print(a+b) | s967539073 | Accepted | 28 | 9,168 | 92 | A=int(input())
B=int(input())
C=int(input())
D=int(input())
a=min(A,B)
b=min(C,D)
print(a+b) |
s043620180 | p00002 | u454259029 | 1,000 | 131,072 | Wrong Answer | 20 | 7,540 | 54 | Write a program which computes the digit number of sum of two integers a and b. | a,b = map(int,input().split(" "))
print(len(str(a+b))) | s648482927 | Accepted | 30 | 7,492 | 124 | while True:
try:
a,b = map(int,input().split())
print (len(str(a+b)))
except EOFError:
break |
s604775150 | p03729 | u403984573 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 96 | You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`. | A,B,C=input().split()
if A[-0]==B[0]:
if B[-0]==C[0]:
print("YES")
else:
print("NO") | s800847304 | Accepted | 18 | 2,940 | 116 | A,B,C=input().split()
if A[-1]==B[0]:
if B[-1]==C[0]:
print("YES")
else:
print("NO")
else:
print("NO") |
s849403570 | p03765 | u638795007 | 2,000 | 262,144 | Wrong Answer | 690 | 12,500 | 2,362 | Let us consider the following operations on a string consisting of `A` and `B`: 1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`. 2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string. For example, if the first operation is performed on `ABA` and the first character is selected, the string becomes `BBBA`. If the second operation is performed on `BBBAAAA` and the fourth through sixth characters are selected, the string becomes `BBBA`. These operations can be performed any number of times, in any order. You are given two string S and T, and q queries a_i, b_i, c_i, d_i. For each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i}, a substring of S, can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i}, a substring of T. | def examC():
N = I()
d = defaultdict(int)
for i in range(N):
curD = defaultdict(int)
S = SI()
for s in S:
curD[s]+=1
if i==0:
d = curD
continue
for s in alphabet:
d[s] = min(d[s],curD[s])
d = sorted(d.items())
ans = ""
for key,i in d:
ans +=key*i
print(ans)
return
def examD():
N, M = LI()
X = LI(); Y = LI()
distX = [0]*N; distY = [0]*M
for i in range(N-1):
distX[i+1] = X[i+1]-X[i]
for i in range(M-1):
distY[i+1] = Y[i+1]-Y[i]
numX = [0]*N; numY = [0]*M
for i in range(N):
numX[i] = i*(N-i)
for i in range(M):
numY[i] = i*(M-i)
LX = 0; LY = 0
for i in range(N):
LX += distX[i]*numX[i]
LX %= mod
for i in range(M):
LY += distY[i]*numY[i]
LY %= mod
ans = (LX*LY) % mod
print(ans)
return
def examE():
S = SI(); T = SI()
numaS = [0]*(len(S)+1)
numaT = [0]*(len(T)+1)
for i,s in enumerate(S):
numaS[i+1] = numaS[i]
if s=="A":
numaS[i+1] +=1
for i,s in enumerate(T):
numaT[i+1] = numaT[i]
if s=="A":
numaT[i+1] +=1
# print(numaS); print(numaT)
Q = I()
ans = ["YES"]*Q
for i in range(Q):
a,b,c,d = LI()
curaS = numaS[b] - numaS[a-1]
curbS = (b-a)-curaS+1
curaT = numaT[d] - numaT[c-1]
curbT = (d-c)-curaT+1
print(curaS,curbS,curaT,curbT)
if (curaS%3+(curaS+curbS)%3)%3 != (curaT%3+(curaT+curbT)%3)%3:
# if (curbS % 3 + (curaS + curbS) % 3) % 3 != (curbT % 3 + (curaT + curbT) % 3) % 3:
ans[i]="NO"
for v in ans:
print(v)
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
if __name__ == '__main__':
examE()
| s869635980 | Accepted | 440 | 10,320 | 2,363 | def examC():
N = I()
d = defaultdict(int)
for i in range(N):
curD = defaultdict(int)
S = SI()
for s in S:
curD[s]+=1
if i==0:
d = curD
continue
for s in alphabet:
d[s] = min(d[s],curD[s])
d = sorted(d.items())
ans = ""
for key,i in d:
ans +=key*i
print(ans)
return
def examD():
N, M = LI()
X = LI(); Y = LI()
distX = [0]*N; distY = [0]*M
for i in range(N-1):
distX[i+1] = X[i+1]-X[i]
for i in range(M-1):
distY[i+1] = Y[i+1]-Y[i]
numX = [0]*N; numY = [0]*M
for i in range(N):
numX[i] = i*(N-i)
for i in range(M):
numY[i] = i*(M-i)
LX = 0; LY = 0
for i in range(N):
LX += distX[i]*numX[i]
LX %= mod
for i in range(M):
LY += distY[i]*numY[i]
LY %= mod
ans = (LX*LY) % mod
print(ans)
return
def examE():
S = SI(); T = SI()
numaS = [0]*(len(S)+1)
numaT = [0]*(len(T)+1)
for i,s in enumerate(S):
numaS[i+1] = numaS[i]
if s=="A":
numaS[i+1] +=1
for i,s in enumerate(T):
numaT[i+1] = numaT[i]
if s=="A":
numaT[i+1] +=1
# print(numaS); print(numaT)
Q = I()
ans = ["YES"]*Q
for i in range(Q):
a,b,c,d = LI()
curaS = numaS[b] - numaS[a-1]
curbS = (b-a)-curaS+1
curaT = numaT[d] - numaT[c-1]
curbT = (d-c)-curaT+1
# print(curaS,curbS,curaT,curbT)
if (curaS%3+(curaS+curbS)%3)%3 != (curaT%3+(curaT+curbT)%3)%3:
# if (curbS % 3 + (curaS + curbS) % 3) % 3 != (curbT % 3 + (curaT + curbT) % 3) % 3:
ans[i]="NO"
for v in ans:
print(v)
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
if __name__ == '__main__':
examE()
|
s192832451 | p02260 | u798803522 | 1,000 | 131,072 | Wrong Answer | 20 | 7,644 | 349 | Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini. | length = int(input())
targ = [int(n) for n in input().split(' ')]
ans = 0
for l in range(length):
value = l
for init in range(l + 1,length):
if targ[value] > targ[init]:
value = init
if value != l:
disp = targ[l]
targ[l] = targ[value]
targ[value] = disp
ans += 1
print(targ)
print(ans) | s315896276 | Accepted | 20 | 7,744 | 377 | length = int(input())
targ = [int(n) for n in input().split(' ')]
ans = 0
for l in range(length):
value = l
for init in range(l + 1,length):
if targ[value] > targ[init]:
value = init
if value != l:
disp = targ[l]
targ[l] = targ[value]
targ[value] = disp
ans += 1
print(' '.join([str(n) for n in targ]))
print(ans) |
s549301994 | p04030 | u902151549 | 2,000 | 262,144 | Wrong Answer | 46 | 5,576 | 3,572 | Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: * The `0` key: a letter `0` will be inserted to the right of the string. * The `1` key: a letter `1` will be inserted to the right of the string. * The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter `0` stands for the `0` key, the letter `1` stands for the `1` key and the letter `B` stands for the backspace key. What string is displayed in the editor now? | # coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(N)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def is_power(a,b):
now=b
while now<a:
now*=b
if now==a:return True
else:return False
def bin_(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def get_facs(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:
return num
def get_primes(n,type="int"):
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def is_prime(num):
if(num<=2):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def ifelse(a,b,c):
if a:return b
else:return c
def join(A,c=""):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
def factorize(n,type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b+=1
if n > 1:list_.append(n)
if type_=="dict":
dic={}
for a in list_:
if a in dic:
dic[a]+=1
else:
dic[a]=1
return dic
elif type_=="list":
return list_
else:
return None
def floor_(n,x=1):
return x*(n//x)
def ceil_(n,x=1):
return x*((n+x-1)//x)
def hani(x,min_,max_):
ret=x
if x<min_:ret=min_
if x>max_:ret=max_
return ret
def seifu(x):
return x//abs(x)
###################################################
def main():
s=input()
ans=""
for a in range(len(s)):
if s=="B":
ans=ans[:-1]
else:
ans+=s[a]
print(ans)
main() | s226479199 | Accepted | 45 | 5,704 | 3,575 | # coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
if b:
print("yes")
else:
print("no")
def Yn(b):
if b:
print("Yes")
else:
print("No")
def YN(b):
if b:
print("YES")
else:
print("NO")
class union_find():
def __init__(self,n):
self.n=n
self.P=[a for a in range(N)]
self.rank=[0]*n
def find(self,x):
if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
return self.P[x]
def same(self,x,y):
return self.find(x)==self.find(y)
def link(self,x,y):
if self.rank[x]<self.rank[y]:
self.P[x]=y
elif self.rank[y]<self.rank[x]:
self.P[y]=x
else:
self.P[x]=y
self.rank[y]+=1
def unite(self,x,y):
self.link(self.find(x),self.find(y))
def size(self):
S=set()
for a in range(self.n):
S.add(self.find(a))
return len(S)
def is_power(a,b):
now=b
while now<a:
now*=b
if now==a:return True
else:return False
def bin_(num,size):
A=[0]*size
for a in range(size):
if (num>>(size-a-1))&1==1:
A[a]=1
else:
A[a]=0
return A
def get_facs(n,mod_=0):
A=[1]*(n+1)
for a in range(2,len(A)):
A[a]=A[a-1]*a
if(mod>0):A[a]%=mod_
return A
def comb(n,r,mod,fac):
if(n-r<0):return 0
return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
x=num&(-num)
y=num+x
z=num&(~y)
z//=x
z=z>>1
num=(y|z)
if(num>=(1<<size)):return False
else:
return num
def get_primes(n,type="int"):
A=[True]*(n+1)
A[0]=False
A[1]=False
for a in range(2,n+1):
if A[a]:
for b in range(a*2,n+1,a):
A[b]=False
if(type=="bool"):return A
B=[]
for a in range(n+1):
if(A[a]):B.append(a)
return B
def is_prime(num):
if(num<=2):return False
i=2
while i*i<=num:
if(num%i==0):return False
i+=1
return True
def ifelse(a,b,c):
if a:return b
else:return c
def join(A,c=""):
n=len(A)
A=list(map(str,A))
s=""
for a in range(n):
s+=A[a]
if(a<n-1):s+=c
return s
def factorize(n,type_="dict"):
b = 2
list_ = []
while b * b <= n:
while n % b == 0:
n //= b
list_.append(b)
b+=1
if n > 1:list_.append(n)
if type_=="dict":
dic={}
for a in list_:
if a in dic:
dic[a]+=1
else:
dic[a]=1
return dic
elif type_=="list":
return list_
else:
return None
def floor_(n,x=1):
return x*(n//x)
def ceil_(n,x=1):
return x*((n+x-1)//x)
def hani(x,min_,max_):
ret=x
if x<min_:ret=min_
if x>max_:ret=max_
return ret
def seifu(x):
return x//abs(x)
###################################################
def main():
s=input()
ans=""
for a in range(len(s)):
if s[a]=="B":
ans=ans[:-1]
else:
ans+=s[a]
print(ans)
main() |
s928532066 | p03729 | u808569469 | 2,000 | 262,144 | Wrong Answer | 28 | 8,940 | 114 | You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`. | a, b, c = map(str, input().split())
if a[-1] == b[-1] and b[-1] == c[-1]:
print("YES")
else:
print("NO")
| s252045735 | Accepted | 27 | 9,092 | 112 | a, b, c = map(str, input().split())
if a[-1] == b[0] and b[-1] == c[0]:
print("YES")
else:
print("NO")
|
s158217010 | p03759 | u473023730 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 79 | Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. | a,b,c=map(int, input().split())
if b-a==c-b:
print("Yes")
else:
print("No") | s358331888 | Accepted | 17 | 3,064 | 79 | a,b,c=map(int, input().split())
if b-a==c-b:
print("YES")
else:
print("NO") |
s143560540 | p03449 | u924828749 | 2,000 | 262,144 | Wrong Answer | 25 | 9,108 | 235 | We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 0
for i in range(n):
c = 0
for j in range(n):
if j <= i:
c += a[j]
else:
c += b[j]
res = max(res,c)
print(res) | s374459355 | Accepted | 29 | 9,112 | 283 | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
res = 0
for i in range(n):
c = 0
for j in range(n):
if j < i:
c += a[j]
elif j == i:
c += a[j]
c += b[j]
else:
c += b[j]
res = max(res,c)
print(res) |
s349046409 | p03473 | u613996976 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 29 | How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December? | a = int(input())
print(24-a)
| s088097319 | Accepted | 18 | 2,940 | 29 | a = int(input())
print(48-a)
|
s662358046 | p02928 | u478719560 | 2,000 | 1,048,576 | Wrong Answer | 1,180 | 3,572 | 835 | We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
sys.setrecursionlimit(1000000000)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,k = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
A = list(map(int, stdin.readline().rstrip().split()))
a_tento = 0
for i in range(n-1):
for j in range(i+1,n):
if A[i] > A[j]:
a_tento += 1
a_inten = 0
for i in range(n):
for j in range(n):
if A[i] > A[j]:
a_inten += 1
a_inten = a_inten - a_tento
print(a_inten)
print(int((a_tento*(k*(k+1)/2)+ a_inten*((k*(k-1)/2))) %MOD))
| s350326056 | Accepted | 806 | 3,572 | 781 | from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
sys.setrecursionlimit(10000000)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,k = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
A = list(map(int, stdin.readline().rstrip().split()))
ans = 0
for i in range(n):
right = 0
left = 0
for j in range(i):
if A[i] > A[j]:
left += 1
for j in range(i+1, n):
if A[i] > A[j]:
right += 1
ans += int(right*k*(k+1)//2 + left*k*(k-1)//2)
print(ans % MOD)
|
s680799449 | p02678 | u079022116 | 2,000 | 1,048,576 | Wrong Answer | 1,033 | 106,376 | 863 | There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists. | from collections import deque
N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]
link = [[] for _ in range(N + 1)]
for a, b in AB:
link[a].append(b)
link[b].append(a)
dist = [-1] * (N + 1)
que = deque([1])
while que:
v = que.popleft()
for i in link[v]:
if dist[i] == -1:
dist[i] = v
que.append(i)
print(dist)
print('Yes')
print('\n'.join(str(v) for v in dist[2:])) | s184253789 | Accepted | 1,118 | 106,472 | 843 | from collections import deque
N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]
link = [[] for _ in range(N + 1)]
for a, b in AB:
link[a].append(b)
link[b].append(a)
dist = [-1] * (N + 1)
que = deque([1])
while que:
v = que.popleft()
for i in link[v]:
if dist[i] == -1:
dist[i] = v
que.append(i)
print('Yes')
print('\n'.join(str(v) for v in dist[2:])) |
s271986137 | p02255 | u445032255 | 1,000 | 131,072 | Wrong Answer | 20 | 5,604 | 345 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. | def insertionSort(A, N):
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j + 1] = A[j]
j -= 1
A[j + 1] = v
print(" ".join(list(map(str, A))))
def main():
N = int(input())
A = [int(i) for i in input().split()]
insertionSort(A, N)
main()
| s540710798 | Accepted | 20 | 5,600 | 373 | def print_list(A):
print(" ".join(list(map(str, A))))
def main():
N = int(input())
A = list(map(int, input().split()))
print_list(A)
for i in range(1, N):
store_v = A[i]
j = i - 1
while j >= 0 and A[j] > store_v:
A[j + 1] = A[j]
j -= 1
A[j+1] = store_v
print_list(A)
main()
|
s237446788 | p03494 | u848654125 | 2,000 | 262,144 | Wrong Answer | 18 | 3,188 | 292 | There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. | def count2(number):
count = 0
while True:
if number % 2 == 0:
count = count + 1
number = number / 2
else:
break
return count
A_list = list(map(int, input().split()))
answer = min(list(map(count2, A_list)))
print(answer) | s370973649 | Accepted | 18 | 3,060 | 308 | def count2(number):
count = 0
while True:
if number % 2 == 0:
count = count + 1
number = number / 2
else:
break
return count
N = int(input())
A_list = list(map(int, input().split()))
answer = min(list(map(count2, A_list)))
print(answer) |
s956731799 | p03351 | u096845660 | 2,000 | 1,048,576 | Wrong Answer | 30 | 9,164 | 383 | Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate. |
a, b, c, d = map(int, input().split())
if (a - c) <= d:
print('yes')
elif (a - b) <= d and (b - c) <= d:
print('yes')
else:
print('no') | s732065167 | Accepted | 25 | 9,056 | 916 |
a, b, c, d = map(int, input().split())
if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d):
print('Yes')
else:
print('No') |
s544624936 | p03943 | u268516119 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 88 | 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. | ans=["NO","YES"]
candy=list(map(int,input().split()))
print(ans[sum(candy)/2 in candy])
| s574263043 | Accepted | 17 | 2,940 | 88 | ans=["No","Yes"]
candy=list(map(int,input().split()))
print(ans[sum(candy)/2 in candy])
|
s114719278 | p03475 | u543954314 | 3,000 | 262,144 | Wrong Answer | 90 | 3,188 | 279 | A railroad running from west to east in Atcoder Kingdom is now complete. There are N stations on the railroad, numbered 1 through N from west to east. Tomorrow, the opening ceremony of the railroad will take place. On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated. The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds. Here, it is guaranteed that F_i divides S_i. That is, for each Time t satisfying S_i≤t and t%F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A%B denotes A modulo B, and there will be no other trains. For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains. | def tcalc(station):
time = 0
for i in range(station-1,n-1):
f = l[i][2]
s = l[i][1]
c = l[i][0]
time = max(((time-1)//f+1)*f, s)+c
return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(1,n):
print(tcalc(i)) | s813585691 | Accepted | 83 | 3,064 | 281 | def tcalc(station):
time = 0
for i in range(station-1,n-1):
f = l[i][2]
s = l[i][1]
c = l[i][0]
time = max(((time-1)//f+1)*f, s)+c
return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for j in range(1,n+1):
print(tcalc(j)) |
s256520889 | p02613 | u130076114 | 2,000 | 1,048,576 | Wrong Answer | 167 | 16,332 | 391 | 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())
s=[]
cnt=[0 for i in range(4)]
for i in range(N):
s.append(input())
for i in range(N):
if s[i]=="AC":
cnt[0]+=1
elif s[i]=="WA":
cnt[1]+=1
elif s[i]=="TLE":
cnt[2]+=1
elif s[i]=="RE":
cnt[3]+=1
print("AC x {}".format(cnt[0]))
print("WA x {}".format(cnt[1]))
print("TRE x {}".format(cnt[2]))
print("RE x {}".format(cnt[3])) | s520809101 | Accepted | 162 | 16,196 | 391 | N=int(input())
s=[]
cnt=[0 for i in range(4)]
for i in range(N):
s.append(input())
for i in range(N):
if s[i]=="AC":
cnt[0]+=1
elif s[i]=="WA":
cnt[1]+=1
elif s[i]=="TLE":
cnt[2]+=1
elif s[i]=="RE":
cnt[3]+=1
print("AC x {}".format(cnt[0]))
print("WA x {}".format(cnt[1]))
print("TLE x {}".format(cnt[2]))
print("RE x {}".format(cnt[3])) |
s091063702 | p03759 | u228294553 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 86 | Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. | a,b,c=map(int,input().split())
if b-a == c-b:
print("Yes")
else:
print("No")
| s574672937 | Accepted | 17 | 2,940 | 86 | a,b,c=map(int,input().split())
if b-a == c-b:
print("YES")
else:
print("NO")
|
s351317428 | p02261 | u822165491 | 1,000 | 131,072 | Wrong Answer | 20 | 5,608 | 1,017 | Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). | def BubbleSort(A, N):
flag = 1
while flag:
flag = 0
for j in reversed(range(1, N)):
if A[j]['value']<A[j-1]['value']:
A[j], A[j-1] = A[j-1], A[j]
flag = 1
return A
def SelectionSort(A, N):
for i in range(0, N):
minj = i
for j in range(i, N):
if A[i]['value']<A[j]['value']:
minj = j
if i!=minj:
A[i], A[minj] = A[minj], A[i]
return A
def IsStable(answer, target):
N = len(answer)
for i in range(N):
if answer[i]['value'] != target[i]['value']:
return False
return True
# Stable Sort
N = int(input())
A = list(
map(lambda x: {'body': x, 'value': int(x[1])}, input().split())
)
bubble = BubbleSort(A, N)
selection = SelectionSort(A, N)
print(' '.join(map(lambda x: x['body'],bubble)))
print('Stable')
print(' '.join(map(lambda x: x['body'], selection)))
if IsStable(bubble, selection):
print('Stable')
else:
print('Not stable')
| s626200736 | Accepted | 30 | 6,356 | 1,271 | import time
import copy
def BubbleSort(A, N):
flag = 1
while flag:
flag = 0
for j in reversed(range(1, N)):
if A[j]['value']<A[j-1]['value']:
A[j], A[j-1] = A[j-1], A[j]
flag = 1
return A
def SelectionSort(A, N):
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j]['value']<A[minj]['value']:
minj = j
if i!=minj:
A[i], A[minj] = A[minj], A[i]
return A
def IsStable(answer, target):
N = len(answer)
for i in range(N):
if answer[i]['body'] != target[i]['body']:
return False
return True
# Stable Sort
def main():
N = int(input())
A = list(
map(lambda x: {'body': x, 'value': int(x[1])}, input().split())
)
A_sortby_bubble = copy.deepcopy(A)
A_sortby_select = copy.deepcopy(A)
A_sortby_bubble = BubbleSort(A_sortby_bubble, N)
A_sortby_select = SelectionSort(A_sortby_select, N)
print(' '.join(map(lambda x: x['body'],A_sortby_bubble)))
print('Stable')
print(' '.join(map(lambda x: x['body'], A_sortby_select)))
if IsStable(A_sortby_bubble, A_sortby_select):
print('Stable')
else:
print('Not stable')
main()
|
s695290444 | p03338 | u330314953 | 2,000 | 1,048,576 | Wrong Answer | 18 | 2,940 | 136 | You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position. | n = int(input())
s = list(input())
z = 0
for i in range(n-1):
x,y = s[0:i],s[i+1:n-1]
z = max(z,len(set(x) & set(y)))
print(z) | s668164895 | Accepted | 20 | 3,316 | 130 | n = int(input())
s = list(input())
z = 0
for i in range(n):
x,y = s[0:i],s[i:n]
z = max(z,len(set(x) & set(y)))
print(z) |
s000890931 | p02645 | u417348126 | 2,000 | 1,048,576 | Wrong Answer | 29 | 9,036 | 31 | 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. | name = input()
print(name[0:2]) | s496339744 | Accepted | 28 | 8,960 | 31 | name = input()
print(name[0:3]) |
s482896793 | p03386 | u584558499 | 2,000 | 262,144 | Wrong Answer | 17 | 3,064 | 317 | Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers. | def main():
A, B, K = (int(i) for i in input().split())
result = set()
A_min = min(A+K, B)
B_max = max(A, B-K)
for i in range(A, A_min):
result.add(i)
for j in range(B_max, B+1):
result.add(j)
for i in sorted(result):
print(i)
if __name__ == '__main__':
main() | s944898545 | Accepted | 17 | 3,064 | 324 | def main():
A, B, K = (int(i) for i in input().split())
result = set()
A_min = min(A+K-1, B)
B_max = max(A, B-K+1)
for i in range(A, A_min+1):
result.add(i)
for j in range(B_max, B+1):
result.add(j)
for i in sorted(result):
print(i)
if __name__ == '__main__':
main() |
s499993138 | p02261 | u387437217 | 1,000 | 131,072 | Wrong Answer | 30 | 7,772 | 754 | Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which sorts a given set of cards in ascending order by their values using the Bubble Sort algorithms and the Selection Sort algorithm respectively. These algorithms should be based on the following pseudocode: BubbleSort(C) 1 for i = 0 to C.length-1 2 for j = C.length-1 downto i+1 3 if C[j].value < C[j-1].value 4 swap C[j] and C[j-1] SelectionSort(C) 1 for i = 0 to C.length-1 2 mini = i 3 for j = i to C.length-1 4 if C[j].value < C[mini].value 5 mini = j 6 swap C[i] and C[mini] Note that, indices for array elements are based on 0-origin. For each algorithm, report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance). | # coding: utf-8
# Here your code !
n=int(input())
cards=input().split()
def bubble_sort(cards,n):
for i in range(n):
for j in range(-1,-i,-1):
a=int(cards[j][1])
b=int(cards[j-1][1])
if a<b:
cards[j],cards[j-1]=cards[j-1],cards[j]
return cards
def selection_sort(cards,n):
for i in range(n):
minv=i
for j in range(i,n):
a=int(cards[minv][1])
b=int(cards[j][1])
if a>b:
minv=j
cards[minv],cards[i]=cards[i],cards[minv]
return cards
ans_1=bubble_sort(cards,n)
ans_2=selection_sort(cards,n)
print(*ans_1)
print("Stable")
print(*ans_2)
if ans_1!=ans_2:
print("Not stable")
else:
print("Stable") | s324604112 | Accepted | 20 | 7,780 | 807 | # coding: utf-8
# Here your code !
n=int(input())
cards=input().split()
def bubble_sort(cards_b,n):
for i in range(n):
for j in range(-1,-n,-1):
a=int(cards_b[j][1])
b=int(cards_b[j-1][1])
if a<b:
cards_b[j],cards_b[j-1]=cards_b[j-1],cards_b[j]
return cards_b
def selection_sort(cards_s,n):
for i in range(n):
minv=i
for j in range(i,n):
a=int(cards_s[minv][1])
b=int(cards_s[j][1])
if a>b:
minv=j
cards_s[minv],cards_s[i]=cards_s[i],cards_s[minv]
return cards_s
dummy=cards.copy()
ans_1=bubble_sort(cards,n)
ans_2=selection_sort(dummy,n)
print(*ans_1)
print("Stable")
print(*ans_2)
if ans_1!=ans_2:
print("Not stable")
else:
print("Stable") |
s286875853 | p03369 | u223646582 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 33 | In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen. | S=input()
print(700+S.count('o')) | s747364500 | Accepted | 17 | 2,940 | 37 | S=input()
print(700+100*S.count('o')) |
s920296601 | p03150 | u003670363 | 2,000 | 1,048,576 | Wrong Answer | 28 | 3,700 | 243 | A string is called a KEYENCE string when it can be changed to `keyence` by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string. | A = str(input())
for i in range(len(A)):
for j in range(len(A)):
b =A[:i]+A[len(A)-j:len(A)]
print(b)
if b == "keyence":
print("YES")
exit()
elif i==len(A):
print("NO")
exit()
else:
continue | s153254182 | Accepted | 21 | 2,940 | 191 | A = str(input())
for i in range(len(A)):
for j in range(len(A)):
b =A[:i]+A[len(A)-j:len(A)]
if b == "keyence":
print("YES")
exit()
else:
continue
print("NO") |
s044956101 | p03494 | u260040951 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 232 | There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. | l = list(input().split(","))
d = [0]
count = 0
max_count = 0
for n in l:
while int(n) % 2 == 0:
n = int(n)/2
count = count + 1
if max_count < count:
max_count = count
count = 0
print(max_count) | s371378332 | Accepted | 21 | 3,064 | 340 | number = input()
l = list(input().split(" "))
loop_count = 0
count = 0
min_count = 0
for n in l:
loop_count = loop_count + 1
while int(n) % 2 == 0:
n = int(n)/2
count = count + 1
if loop_count == 1:
min_count = count
elif min_count > count:
min_count = count
count = 0
print(min_count) |
s458990574 | p03495 | u813174766 | 2,000 | 262,144 | Wrong Answer | 152 | 35,032 | 173 | Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them. | n,k=map(int,input().split())
nm=[0 for i in range(200010)]
a=list(map(int,input().split()))
for i in a:
nm[i]+=1
a.sort(reverse=True)
for i in range(k):
n-=a[i]
print(n) | s719257093 | Accepted | 118 | 35,308 | 175 | n,k=map(int,input().split())
nm=[0 for i in range(200010)]
a=list(map(int,input().split()))
for i in a:
nm[i]+=1
nm.sort(reverse=True)
for i in range(k):
n-=nm[i]
print(n) |
s756796710 | p03720 | u800258529 | 2,000 | 262,144 | Wrong Answer | 20 | 3,188 | 114 | There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? | n,m=map(int,input().split())
l=list(open(0).read().split())
print(*[l.count(str(i+1)) for i in range(n)],sep='\n') | s000875904 | Accepted | 17 | 2,940 | 140 | n,m=map(int,input().split())
l=[]
for _ in range(m):
l+=list(map(int,input().split()))
print(*[l.count(i+1) for i in range(n)],sep='\n') |
s437786989 | p03635 | u928784113 | 2,000 | 262,144 | Wrong Answer | 18 | 2,940 | 77 | In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city? | # -*- coding: utf-8 -*-
n,m =map(int,input().split())
print("{}".format(n*m)) | s993070096 | Accepted | 18 | 2,940 | 85 | # -*- coding: utf-8 -*-
n,m =map(int,input().split())
print("{}".format((n-1)*(m-1))) |
s408567630 | p02846 | u972416428 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 418 | Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows **towards the east** : * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. * Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact. | import sys
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
ha = a1 * t1
hb = b1 * t1
if a == b or ha == hb:
print ("infinity")
sys.exit(0)
if a > b:
a, b = b, a
ha, hb = hb, ha
gap = b - a
hgap = ha - hb
if hgap < 0:
print (0)
sys.exit(0)
ans = 2 * (hgap // gap) + 1
print (hgap, gap)
print (ans)
| s389406401 | Accepted | 18 | 3,064 | 427 | import sys
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = a1 * t1 + a2 * t2
b = b1 * t1 + b2 * t2
ha = a1 * t1
hb = b1 * t1
if a == b or ha == hb:
print ("infinity")
sys.exit(0)
if a > b:
a, b = b, a
ha, hb = hb, ha
gap = b - a
hgap = ha - hb
if hgap < 0:
print (0)
sys.exit(0)
ans = 2 * (hgap // gap) + (1 if hgap % gap > 0 else 0)
print (ans)
|
s998420497 | p02255 | u588555117 | 1,000 | 131,072 | Wrong Answer | 20 | 7,604 | 258 | Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step. | n = int(input())
array = input().split()
intarr = [int(x) for x in array]
print(intarr)
for c in range(1,n):
v = intarr[c]
j = c-1
while j>=0 and intarr[j]>v:
intarr[j+1] = intarr[j]
j -= 1
intarr[j+1] = v
print(intarr) | s785499583 | Accepted | 30 | 8,104 | 434 | n = int(input())
array = input().split()
intarr = [int(x) for x in array]
for x in intarr:
if x == intarr[-1]:
print(x)
else:
print(x,end=' ')
for c in range(1,n):
v = intarr[c]
j = c-1
while j>=0 and intarr[j]>v:
intarr[j+1] = intarr[j]
j -= 1
intarr[j+1] = v
for x in intarr:
if x == intarr[-1]:
print(x)
else:
print(x, end=' ') |
s588398586 | p02399 | u177081782 | 1,000 | 131,072 | Wrong Answer | 20 | 5,600 | 114 | Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number) | a, b= map(int, input(). split())
d = a / b
r = a % b
f = "%.5F"%(a/b)
print(str(d) + " " + str(r) + " " +str(f))
| s477628633 | Accepted | 20 | 5,604 | 115 | a, b= map(int, input(). split())
d = a // b
r = a % b
f = "%.5F"%(a/b)
print(str(d) + " " + str(r) + " " +str(f))
|
s395175596 | p03919 | u328755070 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 254 | There is a grid with H rows and W columns. The square at the i-th row and j-th column contains a string S_{i,j} of length 5. The rows are labeled with the numbers from 1 through H, and the columns are labeled with the uppercase English letters from `A` through the W-th letter of the alphabet. Exactly one of the squares in the grid contains the string `snuke`. Find this square and report its location. For example, the square at the 6-th row and 8-th column should be reported as `H6`. | H, W = list(map(int, input().split()))
S = [input().split() for i in range(H)]
for i in range(H):
for j in range(W):
if S[i][j] == 'snuke':
ans = [chr(i) for i in range(97, 97+26)][j] + str(i + 1)
break
print(ans)
| s529193400 | Accepted | 30 | 3,828 | 257 | import string
H, W = list(map(int, input().split()))
S = [input().split() for i in range(H)]
for i in range(H):
for j in range(W):
if S[i][j] == 'snuke':
ans = string.ascii_uppercase[j] + str(i + 1)
break
print(ans)
|
s518717787 | p03434 | u509739538 | 2,000 | 262,144 | Wrong Answer | 22 | 3,444 | 2,597 | 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. | import math
from collections import deque
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
def factorization(n):
res = []
if n%2==0:
res.append(2)
for i in range(3,math.floor(n//2)+1,2):
if n%i==0:
c = 0
for j in res:
if i%j==0:
c=1
if c==0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c=0
z=n
while 1:
if z%i==0:
c+=1
z/=i
else:
break
res.append([i,c])
return res
def fact(n):
ans = 1
m=n
for _i in range(n-1):
ans*=m
m-=1
return ans
def comb(n,r):
if n<r:
return 0
l = min(r,n-r)
m=n
u=1
for _i in range(l):
u*=m
m-=1
return u//fact(l)
def combmod(n,r,mod):
return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
r=copyQueue(q)
ans=[0]*r.qsize()
for i in range(r.qsize()-1,-1,-1):
ans[i] = r.get()
print(ans)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x): # root
if self.parents[x]<0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y = y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def size(self,x):
return -1*self.parents[self.find(x)]
def same(self,x,y):
return self.find(x)==self.find(y)
def members(self,x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):
x = 1
zero = "0"*n
ans = []
ans.append([0]*n)
for i in range(2**n-1):
ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
x+=1
return ans;
def arrsSum(a1,a2):
for i in range(len(a1)):
a1[i]+=a2[i]
return a1
def maxValue(a,b,v):
v2 = v
for i in range(v2,-1,-1):
for j in range(v2//a+1):
k = i-a*j
if k%b==0:
return i
return -1
def copyQueue(q):
nq = queue.Queue()
n = q.qsize()
for i in range(n):
x = q.get()
q.put(x)
nq.put(x)
return nq
n = readInt()
a = readInts()
a.sort()
if len(a)%2:
a.append(0)
alice = 0
bob = 0
for i in range(0,len(a),2):
alice+=a[i]
bob+=a[i+1]
print(alice-bob) | s413990366 | Accepted | 22 | 3,444 | 2,609 | import math
from collections import deque
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
def factorization(n):
res = []
if n%2==0:
res.append(2)
for i in range(3,math.floor(n//2)+1,2):
if n%i==0:
c = 0
for j in res:
if i%j==0:
c=1
if c==0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c=0
z=n
while 1:
if z%i==0:
c+=1
z/=i
else:
break
res.append([i,c])
return res
def fact(n):
ans = 1
m=n
for _i in range(n-1):
ans*=m
m-=1
return ans
def comb(n,r):
if n<r:
return 0
l = min(r,n-r)
m=n
u=1
for _i in range(l):
u*=m
m-=1
return u//fact(l)
def combmod(n,r,mod):
return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
r=copyQueue(q)
ans=[0]*r.qsize()
for i in range(r.qsize()-1,-1,-1):
ans[i] = r.get()
print(ans)
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x): # root
if self.parents[x]<0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x]>self.parents[y]:
x,y = y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x
def size(self,x):
return -1*self.parents[self.find(x)]
def same(self,x,y):
return self.find(x)==self.find(y)
def members(self,x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
return [i for i,x in enumerate(self.parents) if x<0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):
x = 1
zero = "0"*n
ans = []
ans.append([0]*n)
for i in range(2**n-1):
ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
x+=1
return ans;
def arrsSum(a1,a2):
for i in range(len(a1)):
a1[i]+=a2[i]
return a1
def maxValue(a,b,v):
v2 = v
for i in range(v2,-1,-1):
for j in range(v2//a+1):
k = i-a*j
if k%b==0:
return i
return -1
def copyQueue(q):
nq = queue.Queue()
n = q.qsize()
for i in range(n):
x = q.get()
q.put(x)
nq.put(x)
return nq
n = readInt()
a = readInts()
a.sort(reverse=True)
if len(a)%2:
a.append(0)
alice = 0
bob = 0
for i in range(0,len(a),2):
alice+=a[i]
bob+=a[i+1]
print(alice-bob) |
s074350663 | p03050 | u367130284 | 2,000 | 1,048,576 | Wrong Answer | 119 | 3,268 | 346 | Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those. | def dv(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
n=int(input())
ans=0
for i in dv(n):
if n//(i+1)==n%(i+1):
ans+=i%(10**9+7)
print(ans%(10**9+7))
| s985259307 | Accepted | 115 | 3,264 | 327 | def dv(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.remove(1)
return divisors
n=int(input())
x=dv(n)
ans=0
for i in x:
if n//(i-1)==n%(i-1):
ans+=i-1
print(ans)
|
s831336642 | p03156 | u970809473 | 2,000 | 1,048,576 | Wrong Answer | 17 | 3,064 | 229 | You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: * A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points. The same problem should not be used in multiple contests. At most how many contests can be held? | n = int(input())
a,b = map(int, input().split())
res = [0,0,0]
arr = list(map(int, input().split()))
for i in range(n):
if arr[i] <= a:
res[0] += 1
elif arr[i] <= b:
res[1] += 1
else:
res[2] += 1
print(min(arr)) | s663114866 | Accepted | 17 | 3,060 | 230 | n = int(input())
a,b = map(int, input().split())
res = [0,0,0]
arr = list(map(int, input().split()))
for i in range(n):
if arr[i] <= a:
res[0] += 1
elif arr[i] <= b:
res[1] += 1
else:
res[2] += 1
print(min(res))
|
s560661846 | p03361 | u009348313 | 2,000 | 262,144 | Wrong Answer | 23 | 3,064 | 438 | We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective. | import itertools
H, W = map(int, input().split())
s = []
for i in range(H):
s.append(input())
print(s)
for i in range(H):
for j in range(W):
if s[i][j] == "#":
flag = False
for x, y in [[1, 0],[-1, 0],[0, 1],[0, -1]]:
if i + x >= 0 and i + x <= H - 1 and j + y >= 0 and j + y <= W - 1 and s[i + x][j + y] == '#':
flag = True
if not flag:
print('No')
exit(0)
print('Yes')
| s503470786 | Accepted | 24 | 3,064 | 409 | H, W = map(int, input().split())
s = []
for i in range(H):
s.append(input())
for i in range(H):
for j in range(W):
if s[i][j] == "#":
flag = False
for x, y in [[1, 0],[-1, 0],[0, 1],[0, -1]]:
if i + x >= 0 and i + x <= H - 1 and j + y >= 0 and j + y <= W - 1 and s[i + x][j + y] == '#':
flag = True
if not flag:
print('No')
exit(0)
print('Yes')
|
s034234855 | p03944 | u281152316 | 2,000 | 262,144 | Wrong Answer | 75 | 9,356 | 799 | There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white. Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i). Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows: * If a_i = 1, he painted the region satisfying x < x_i within the rectangle. * If a_i = 2, he painted the region satisfying x > x_i within the rectangle. * If a_i = 3, he painted the region satisfying y < y_i within the rectangle. * If a_i = 4, he painted the region satisfying y > y_i within the rectangle. Find the area of the white region within the rectangle after he finished painting. | W, H, N = map(int,input().split())
x = 0
y = 0
a = 0
X = []
Y = []
A = []
for i in range(N):
x, y, a = map(int,input().split())
X.append(x)
Y.append(y)
A.append(a)
P = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
if A[i] == 1:
for j in range(X[i]):
for k in range(H):
P[k][j] = 1
elif A[i] == 2:
for j in range(X[i],W):
for k in range(H):
P[k][j] = 1
elif A[i] == 3:
for j in range(Y[i]):
for k in range(W):
P[j][k] = 1
elif A[i] == 4:
for j in range(Y[i],H):
for k in range(W):
P[j][k] = 1
ans = 0
for i in range(W):
for j in range(H):
if P[j][i] == 0:
ans += 1
print(P)
print(ans)
| s378135582 | Accepted | 75 | 9,352 | 790 | W, H, N = map(int,input().split())
x = 0
y = 0
a = 0
X = []
Y = []
A = []
for i in range(N):
x, y, a = map(int,input().split())
X.append(x)
Y.append(y)
A.append(a)
P = [[0 for i in range(W)] for j in range(H)]
for i in range(N):
if A[i] == 1:
for j in range(X[i]):
for k in range(H):
P[k][j] = 1
elif A[i] == 2:
for j in range(X[i],W):
for k in range(H):
P[k][j] = 1
elif A[i] == 3:
for j in range(Y[i]):
for k in range(W):
P[j][k] = 1
elif A[i] == 4:
for j in range(Y[i],H):
for k in range(W):
P[j][k] = 1
ans = 0
for i in range(W):
for j in range(H):
if P[j][i] == 0:
ans += 1
print(ans)
|
s467712235 | p00018 | u868716420 | 1,000 | 131,072 | Wrong Answer | 20 | 7,672 | 99 | Write a program which reads five numbers and sorts them in descending order. | a = [int(temp) for temp in input().split()]
a.sort
a = [str(temp) for temp in a]
print(' '.join(a)) | s153816500 | Accepted | 20 | 7,684 | 115 | a = [int(temp) for temp in input().split()]
a.sort(reverse = True)
a = [str(temp) for temp in a]
print(' '.join(a)) |
s821487257 | p03695 | u488884575 | 2,000 | 262,144 | Wrong Answer | 21 | 3,316 | 275 | In AtCoder, a person who has participated in a contest receives a _color_ , which corresponds to the person's rating as follows: * Rating 1-399 : gray * Rating 400-799 : brown * Rating 800-1199 : green * Rating 1200-1599 : cyan * Rating 1600-1999 : blue * Rating 2000-2399 : yellow * Rating 2400-2799 : orange * Rating 2800-3199 : red Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not. Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i. Find the minimum and maximum possible numbers of different colors of the users. | n = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x//400, A))
#print(A)
import collections
c = collections.Counter(A)
if not 8 in c.keys():
print(len(c.keys()), ' ', len(c.keys()))
else:
print(len(c.keys()) -1, ' ', len(c.keys()) -1 + c[8]) | s887062332 | Accepted | 21 | 3,316 | 431 | n = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x: x//400, A))
#print(A)
import collections
c = collections.Counter(A)
#print(c)
f1 = f2 = 0
for k in c.keys():
if k >= 8:
f1 += 1
f2 += c[k]
if f1 == 0:
min_ = max_ = len(c.keys())
else:
min_ = len(c.keys()) -f1
max_ = len(c.keys()) -f1 +f2
'''if max_ >8:
max_ = 8'''
if min_ <1:
min_ = 1
print(min_, max_) |
s344385517 | p02286 | u893844544 | 2,000 | 262,144 | Wrong Answer | 20 | 5,620 | 2,152 | A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shuffle the elements to be inserted. However, we should consider to maintain the balanced binary tree where different operations can be performed one by one depending on requirement. We can maintain the balanced binary search tree by assigning a priority randomly selected to each node and by ordering nodes based on the following properties. Here, we assume that all priorities are distinct and also that all keys are distinct. * **binary-search-tree property.** If $v$ is a **left child** of $u$, then $v.key < u.key$ and if $v$ is a **right child** of $u$, then $u.key < v.key$ * **heap property.** If $v$ is a **child** of $u$, then $v.priority < u.priority$ This combination of properties is why the tree is called Treap (tree + heap). An example of Treap is shown in the following figure. **Insert** To insert a new element into a Treap, first of all, insert a node which a randomly selected priority value is assigned in the same way for ordinal binary search tree. For example, the following figure shows the Treap after a node with key = 6 and priority = 90 is inserted. It is clear that this Treap violates the heap property, so we need to modify the structure of the tree by **rotate** operations. The rotate operation is to change parent-child relation while maintaing the binary-search-tree property. The rotate operations can be implemented as follows. rightRotate(Node t) Node s = t.left t.left = s.right s.right = t return s // the new root of subtree | leftRotate(Node t) Node s = t.right t.right = s.left s.left = t return s // the new root of subtree ---|--- The following figure shows processes of the rotate operations after the insert operation to maintain the properties. The insert operation with rotate operations can be implemented as follows. insert(Node t, int key, int priority) // search the corresponding place recursively if t == NIL return Node(key, priority) // create a new node when you reach a leaf if key == t.key return t // ignore duplicated keys if key < t.key // move to the left child t.left = insert(t.left, key, priority) // update the pointer to the left child if t.priority < t.left.priority // rotate right if the left child has higher priority t = rightRotate(t) else // move to the right child t.right = insert(t.right, key, priority) // update the pointer to the right child if t.priority < t.right.priority // rotate left if the right child has higher priority t = leftRotate(t) return t **Delete** To delete a node from the Treap, first of all, the target node should be moved until it becomes a leaf by rotate operations. Then, you can remove the node (the leaf). These processes can be implemented as follows. delete(Node t, int key) // seach the target recursively if t == NIL return NIL if key < t.key // search the target recursively t.left = delete(t.left, key) else if key > t.key t.right = delete(t.right, key) else return _delete(t, key) return t _delete(Node t, int key) // if t is the target node if t.left == NIL && t.right == NIL // if t is a leaf return NIL else if t.left == NIL // if t has only the right child, then perform left rotate t = leftRotate(t) else if t.right == NIL // if t has only the left child, then perform right rotate t = rightRotate(t) else // if t has both the left and right child if t.left.priority > t.right.priority // pull up the child with higher priority t = rightRotate(t) else t = leftRotate(t) return delete(t, key) Write a program which performs the following operations to a Treap $T$ based on the above described algorithm. * insert ($k$, $p$): Insert a node containing $k$ as key and $p$ as priority to $T$. * find ($k$): Report whether $T$ has a node containing $k$. * delete ($k$): Delete a node containing $k$. * print(): Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. | class Node:
def __init__(self, key, pri):
self.key = key
self.pri = pri
self.left = None
self.right = None
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.left
s.left = t
return s
def insert(t, key, pri):
if t == None:
return Node(key, pri)
if key == t.key:
return t
if key < t.key:
t.left = insert(t.left, key, pri)
if t.pri < t.left.pri:
t = rightRotate(t)
else:
t.right = insert(t.right, key, pri)
if t.pri < t.right.pri:
t = leftRotate(t)
return t
def delete(t, key):
if t == None:
return None
if key == t.key:
if t.right == None and t.left == None:
return None
elif t.left == None:
t = leftRotate(t)
elif t.right == None:
t = rightRotate(t)
else :
if t.left.pri > t.right.pri:
t = rightRotate(t)
else :
t = leftRotate(t)
return delete(t, key)
if key < t.key:
t.left = delete(t.left, key)
else:
t.right = delete(t.right, key)
return t
def find(t, key):
if t == None:
return False
if key == t.key:
return True
if key < t.key:
return find(t.left, key)
else:
return find(t.right, key)
def priorder(t):
if t == None:
return
print(" " + str(t.key), end='')
priorder(t.left)
priorder(t.right)
def inorder(t):
if t == None:
return
inorder(t.left)
print(" " + str(t.key), end='')
inorder(t.right)
m = int(input())
t = None
for i in range(m):
com = input().split()
if com[0] == "insert":
t = insert(t, int(com[1]), int(com[2]))
elif com[0] == "find":
if find(t, int(com[1])):
print("yes")
else :
print("no")
elif com[0] == "delete":
delete(t, int(com[1]))
elif com[0] == "print":
inorder(t)
print()
priorder(t)
print()
| s146946386 | Accepted | 5,500 | 52,020 | 2,158 | class Node:
def __init__(self, key, pri):
self.key = key
self.pri = pri
self.left = None
self.right = None
def rightRotate(t):
s = t.left
t.left = s.right
s.right = t
return s
def leftRotate(t):
s = t.right
t.right = s.left
s.left = t
return s
def insert(t, key, pri):
if t == None:
return Node(key, pri)
if key == t.key:
return t
if key < t.key:
t.left = insert(t.left, key, pri)
if t.pri < t.left.pri:
t = rightRotate(t)
else:
t.right = insert(t.right, key, pri)
if t.pri < t.right.pri:
t = leftRotate(t)
return t
def delete(t, key):
if t == None:
return None
if key < t.key:
t.left = delete(t.left , key)
elif key > t.key:
t.right = delete(t.right, key)
else:
return _delete(t, key)
return t
def _delete(t, key):
if t.left == None and t.right == None:
return None
elif t.left == None:
t = leftRotate(t)
elif t.right == None:
t = rightRotate(t)
else:
if t.left.pri > t.right.pri:
t = rightRotate(t)
else:
t = leftRotate(t)
return delete(t, key)
def find(t, key):
if t == None:
return False
if key == t.key:
return True
if key < t.key:
return find(t.left, key)
else:
return find(t.right, key)
def priorder(t):
if t == None:
return
print(' ' + str(t.key), end='')
priorder(t.left)
priorder(t.right)
def inorder(t):
if t == None:
return
inorder(t.left)
print(' ' + str(t.key), end='')
inorder(t.right)
m = int(input())
t = None
for _ in range(m):
com = input().split()
if com[0] == 'insert':
t = insert(t, int(com[1]), int(com[2]))
elif com[0] == 'find':
if find(t, int(com[1])):
print('yes')
else :
print('no')
elif com[0] == 'delete':
t = delete(t, int(com[1]))
elif com[0] == 'print':
inorder(t)
print()
priorder(t)
print()
|
s497758940 | p02842 | u115110170 | 2,000 | 1,048,576 | Wrong Answer | 17 | 2,940 | 122 | 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())
k = n*100/108
k = int(k)
ans = ":("
for i in range(-1,2):
if n==int(k*1.08):
ans = k+i
print(ans) | s202517653 | Accepted | 17 | 2,940 | 125 | n = int(input())
k = n*100/108
k = int(k)
ans = ":("
for i in range(k-1,k+2):
if n==int(i*1.08):
ans = i
print(ans)
|
s098115380 | p03378 | u959759457 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 147 | There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal. | N,M,X=map(int,input().split())
A=list(map(int,input().split()))
N_cost=len([i>X for i in A])
Z_cost=len([i<X for i in A])
print(min(N_cost,Z_cost)) | s698756949 | Accepted | 19 | 3,060 | 177 | N,M,X=map(int,input().split())
A=list(map(int,input().split()))
N_cost=len(list(filter(lambda x:x >X, A)))
Z_cost=len(list(filter(lambda x:x <X, A)))
print(min(N_cost,Z_cost))
|
s178432076 | p03494 | u335448425 | 2,000 | 262,144 | Wrong Answer | 30 | 3,520 | 302 | There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform. | import math
N = int(input())
A = list(map(int, input().split()))
res = 1000
for a in A:
print('a:', a)
cnt = 0
while a%2 == 0:
a = (a//2)
cnt += 1
print(' ->', a, '(cnt:', cnt, ')')
print(' cnt:', cnt)
res = min(res, cnt)
print(' res:', res)
print(res) | s238550227 | Accepted | 18 | 3,060 | 194 | import math
N = int(input())
A = list(map(int, input().split()))
res = 1000
for a in A:
cnt = 0
while a%2 == 0:
a = (a//2)
cnt += 1
res = min(res, cnt)
print(res) |
s222035622 | p03609 | u459150945 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 52 | We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds? | X, t = map(int, input().split())
print(min(X-t, 0))
| s280801687 | Accepted | 17 | 2,940 | 52 | X, t = map(int, input().split())
print(max(X-t, 0))
|
s949184736 | p03623 | u117193815 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 69 | 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())
a=abs(a-x)
b=abs(b-x)
print(min(a,b)) | s045138708 | Accepted | 17 | 2,940 | 93 | x,a,b=map(int, input().split())
a=abs(a-x)
b=abs(b-x)
if a<b:
print("A")
else:
print("B") |
s826558713 | p03371 | u930723367 | 2,000 | 262,144 | Wrong Answer | 28 | 9,156 | 351 | "Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas. | a,b,c,x,y = map(int, input().split())
kei = 0
if c > a/2 + b/2:
kei = a * x + b*y
elif c < a+ b:
kei += c * (min(x,y)*2)
if x > y:
kei += c * ((x - y)*2)
else:
kei += c * ((y - x)*2)
elif c < a/2 + b/2:
kei += c * (min(x,y)*2)
if x > y:
kei += a * (x -y)
else:
kei += b *(y-x)
print(kei) | s516942085 | Accepted | 28 | 9,108 | 421 | a,b,c,x,y = map(int, input().split())
kei = 0
if c >= a/2 + b/2:
kei = a * x + b*y
elif c*2 <= a+ b and a >= c * 2 and x > y:
kei += c * (min(x,y)*2)
kei += c * ((x - y)*2)
elif c*2 <= a+ b and b >= c * 2 and x < y:
kei += c * (min(x,y)*2)
kei += c * ((y - x)*2)
elif c <= a/2 + b/2:
kei += c * (min(x,y)*2)
if x > y:
kei += a * (x -y)
else:
kei += b *(y-x)
print(kei) |
s919911047 | p02272 | u890722286 | 1,000 | 131,072 | Wrong Answer | 30 | 7,628 | 727 | Write a program of a Merge Sort algorithm implemented by the following pseudocode. You should also report the number of comparisons in the Merge function. Merge(A, left, mid, right) n1 = mid - left; n2 = right - mid; create array L[0...n1], R[0...n2] for i = 0 to n1-1 do L[i] = A[left + i] for i = 0 to n2-1 do R[i] = A[mid + i] L[n1] = SENTINEL R[n2] = SENTINEL i = 0; j = 0; for k = left to right-1 if L[i] <= R[j] then A[k] = L[i] i = i + 1 else A[k] = R[j] j = j + 1 Merge-Sort(A, left, right){ if left+1 < right then mid = (left + right)/2; call Merge-Sort(A, left, mid) call Merge-Sort(A, mid, right) call Merge(A, left, mid, right) | import sys
n = int(input())
SENTINEL = 10000000000
COMPAR = 0
A = list(map(int, sys.stdin.readline().split()))
def merge(A, left, mid, right):
global COMPAR
n1 = mid - left
n2 = right - mid
L = A[left:mid]
R = A[mid:right]
L.append(SENTINEL)
R.append(SENTINEL)
j = 0
i = 0
for k in range(left, right):
COMPAR += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(A, 0, n)
print(A)
print(COMPAR) | s183604604 | Accepted | 4,400 | 72,664 | 747 | import sys
n = int(input())
SENTINEL = 10000000000
COMPAR = 0
A = list(map(int, sys.stdin.readline().split()))
def merge(A, left, mid, right):
global COMPAR
n1 = mid - left
n2 = right - mid
L = A[left:mid]
R = A[mid:right]
L.append(SENTINEL)
R.append(SENTINEL)
j = 0
i = 0
for k in range(left, right):
COMPAR += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(A, 0, n)
print(' '.join(map(str, A)))
print(COMPAR) |
s004012498 | p03229 | u735763891 | 2,000 | 1,048,576 | Wrong Answer | 214 | 8,272 | 448 | You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like. | def tpbc_2018_c():
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
if len(a) % 2 == 0:
low = a[:len(a) // 2]
high = sorted(a[len(a) // 2:], reverse=True)
return 2 * (sum(high) - sum(low)) + max(low) - min(high)
else:
low = a[:len(a) // 2]
high = sorted(a[len(a) // 2:], reverse=True)
return 2 * (sum(high) - sum(low)) - max(high) - min(high)
print(tpbc_2018_c()) | s965621243 | Accepted | 217 | 8,532 | 451 | def tpbc_2018_c():
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()
low = a[:len(a) // 2]
high = a[len(a) // 2:]
if len(a) % 2 == 0:
return 2 * (sum(high) - sum(low)) + max(low) - min(high)
else:
low2 = a[:len(a) // 2 + 1]
high2 = a[len(a) // 2 + 1:]
return max(2 * (sum(high) - sum(low)) - high[0]-high[1],2 * (sum(high2) - sum(low2))+low2[-2]+low2[-1])
print(tpbc_2018_c()) |
s755485922 | p03557 | u595353654 | 2,000 | 262,144 | Wrong Answer | 398 | 48,224 | 2,649 | The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different. | ##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)] a[0,0]
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
def keta(kazu):
kazu_str = str(kazu)
kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
return kazu_list
def gcd(*numbers):
return reduce(math.gcd, numbers)
def combination(m,n): # mCn
if n > m:
return 'すまん'
return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))
def pow_k(x,n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
x *= x
n //= 2
return K * x
def fact(n):
arr = {}
temp = n
for i in range(2,int(n**0.5)+1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if arr == {}:
arr[n] = 1
return arr
def main():
n = int(stdin.readline().rstrip())
a_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
a = sorted(a_kari)
b_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
b = sorted(b_kari)
c_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
c = sorted(c_kari)
board_ab = [0] * n
board_bc = [0] * n
ans = 0
for i in range(n):
ab = bisect.bisect_left(a, b[i])
bc = n - bisect.bisect_right(c, b[i])
ans += ab * bc
print(ab,bc)
print(ans)
main() | s323606815 | Accepted | 330 | 48,744 | 2,651 | ##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)] a[0,0]
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
def keta(kazu):
kazu_str = str(kazu)
kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
return kazu_list
def gcd(*numbers):
return reduce(math.gcd, numbers)
def combination(m,n): # mCn
if n > m:
return 'すまん'
return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))
def pow_k(x,n):
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
x *= x
n //= 2
return K * x
def fact(n):
arr = {}
temp = n
for i in range(2,int(n**0.5)+1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr[i] = cnt
if temp != 1:
arr[temp] = 1
if arr == {}:
arr[n] = 1
return arr
def main():
n = int(stdin.readline().rstrip())
a_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
a = sorted(a_kari)
b_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
b = sorted(b_kari)
c_kari = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
c = sorted(c_kari)
board_ab = [0] * n
board_bc = [0] * n
ans = 0
for i in range(n):
ab = bisect.bisect_left(a, b[i])
bc = n - bisect.bisect_right(c, b[i])
ans += ab * bc
# print(ab,bc)
print(ans)
main() |
s987832972 | p03478 | u021166294 | 2,000 | 262,144 | Wrong Answer | 48 | 3,884 | 454 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive). | import math
def main():
num_n, num_a, num_b = list(map(int, input().split()))
count_list = []
for i in range(1, num_n + 1):
print("num", i)
digit_list = list(str(i))
digit_list_int = [int(j) for j in digit_list]
num_sum = sum(digit_list_int)
if num_a <= num_sum and num_sum <= num_b: count_list.append(i)
#print(count_list)
print(sum(count_list))
if __name__ == '__main__':
main()
| s747224348 | Accepted | 38 | 3,680 | 455 | import math
def main():
num_n, num_a, num_b = list(map(int, input().split()))
count_list = []
for i in range(1, num_n + 1):
#print("num", i)
digit_list = list(str(i))
digit_list_int = [int(j) for j in digit_list]
num_sum = sum(digit_list_int)
if num_a <= num_sum and num_sum <= num_b: count_list.append(i)
#print(count_list)
print(sum(count_list))
if __name__ == '__main__':
main()
|
s494271472 | p03545 | u868982936 | 2,000 | 262,144 | Wrong Answer | 18 | 3,060 | 308 | 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. | ABCD = input()
for i in range(2**3):
ans = ABCD[0]
num = int(ABCD[0])
for j in range(3):
if i >> j & 1:
ans = ans + '+' + ABCD[j+1]
num = num + int(ABCD[j+1])
else:
ans = ans + '-' + ABCD[j+1]
num = num + int(ABCD[j+1])
if num == 7:
print(ans + '=7')
break
| s471406162 | Accepted | 17 | 3,064 | 355 | ABCD = input()
for i in range(2**3):
ans = ABCD[0]
num = int(ABCD[0])
for j in range(3):
if (i >>j & 1):
ans = ans + '+' + ABCD[j+1]
num = num + int(ABCD[j+1])
else:
ans = ans + '-' + ABCD[j+1]
num = num - int(ABCD[j+1])
if num == 7:
print(ans + '=7')
break |
s296287111 | p03369 | u210295876 | 2,000 | 262,144 | Wrong Answer | 25 | 8,992 | 97 | In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen. | S = input()
ramen = 700
for i in range(2):
if S[i] == 'o':
ramen += 100
print(ramen) | s690648632 | Accepted | 26 | 9,000 | 76 | S=input()
ans=700
for i in range(3):
if S[i]=='o':
ans+=100
print(ans) |
s229314653 | p03860 | u799521877 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 31 | Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name. | s = input()
print('A'+s[0]+'C') | s919356197 | Accepted | 17 | 2,940 | 29 | s=input()
print('A'+s[8]+'C') |
s335326609 | p02608 | u452512115 | 2,000 | 1,048,576 | Time Limit Exceeded | 2,206 | 8,828 | 218 | Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N). | N = int(input())
for n in range(1, N+1):
count = 0
for i in range (1, 101):
for j in range(1, 101):
for k in range(1, 101):
if i*i+j*j+k*k+i*j+j*k+k*i == n:
count += 1
print(count)
| s848623932 | Accepted | 442 | 9,316 | 215 | N = int(input())
ans = [0] * (N + 1)
for i in range (1, 101):
for j in range(1, 101):
for k in range(1, 101):
n = i*i+j*j+k*k+i*j+j*k+k*i
if n <= N:
ans[n] += 1
print(*ans[1:], sep='\n')
|
s725131743 | p03609 | u371467115 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 43 | We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds? | s=list(input())
s=s[::2]
print("".join(s))
| s480638296 | Accepted | 17 | 2,940 | 72 | X,t=map(int,input().split())
if X-t>0:
print(X-t)
else:
print(0) |
s336761313 | p03796 | u103902792 | 2,000 | 262,144 | Wrong Answer | 41 | 2,940 | 100 | Snuke loves working out. He is now exercising N times. Before he starts exercising, his _power_ is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7. | n = int(input())
mod = 10**9 + 7
ans = 1
for i in range(1,n+1):
ans *= i
ans %= mod
print(mod) | s223449830 | Accepted | 41 | 2,940 | 102 | n = int(input())
mod = 10**9 + 7
ans = 1
for i in range(1,n+1):
ans *= i
ans %= mod
print(ans)
|
s580326448 | p03457 | u565380863 | 2,000 | 262,144 | Wrong Answer | 276 | 11,764 | 894 | 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. | import sys
sys.setrecursionlimit(200000)
def input():
return sys.stdin.readline()[:-1]
def ii(t: type = int):
return t(input())
def il(t: type = int):
return list(map(t, input().split()))
def imi(N: int, t: type = int):
return [ii(t) for _ in range(N)]
def iml(N: int, t: type = int):
return [il(t) for _ in range(N)]
def solve():
N = ii()
T = [0] * (N + 1)
X = [0] * (N + 1)
Y = [0] * (N + 1)
for n in range(N):
t = il()
T[n + 1] = t[0]
X[n + 1] = t[1]
Y[n + 1] = t[2]
for i in range(N):
dt = T[i + 1] - T[i]
dst = abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i])
if dt < dst or dt % 2 != dst % 2:
return "NO"
return "YES"
if __name__ == "__main__":
print(solve())
| s389649786 | Accepted | 280 | 11,764 | 894 | import sys
sys.setrecursionlimit(200000)
def input():
return sys.stdin.readline()[:-1]
def ii(t: type = int):
return t(input())
def il(t: type = int):
return list(map(t, input().split()))
def imi(N: int, t: type = int):
return [ii(t) for _ in range(N)]
def iml(N: int, t: type = int):
return [il(t) for _ in range(N)]
def solve():
N = ii()
T = [0] * (N + 1)
X = [0] * (N + 1)
Y = [0] * (N + 1)
for n in range(N):
t = il()
T[n + 1] = t[0]
X[n + 1] = t[1]
Y[n + 1] = t[2]
for i in range(N):
dt = T[i + 1] - T[i]
dst = abs(X[i + 1] - X[i]) + abs(Y[i + 1] - Y[i])
if dt < dst or dt % 2 != dst % 2:
return "No"
return "Yes"
if __name__ == "__main__":
print(solve())
|
s807188447 | p03555 | u186426563 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 50 | 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. | print('Yes' if input() == input()[::-1] else 'No') | s439901422 | Accepted | 17 | 2,940 | 50 | print('YES' if input() == input()[::-1] else 'NO') |
s780329795 | p03854 | u626467464 | 2,000 | 262,144 | Wrong Answer | 19 | 3,188 | 157 | You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`. | s = input()
line = s.replace("dream","").replace("dreamer","").replace("erase","").replace("eraser","")
if len(line) == 0:
print("Yes")
else:
print("No") | s474430749 | Accepted | 18 | 3,188 | 147 | s = input()
line = s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if line:
print("NO")
else:
print("YES") |
s245858271 | p02393 | u293957970 | 1,000 | 131,072 | Wrong Answer | 20 | 5,588 | 66 | Write a program which reads three integers, and prints them in ascending order. | a = list(map(int,input().split()))
a.sort()
print(a[0],a[1],a[1])
| s711782636 | Accepted | 30 | 5,588 | 99 | numbers = list(map(int,input().split()))
numbers .sort()
print(numbers[0],numbers[1],numbers[2])
|
s064122413 | p02619 | u798890085 | 2,000 | 1,048,576 | Wrong Answer | 33 | 9,388 | 475 | Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated. | D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
print(len(yasumi))
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasumi))
yasumi[T[day] - 1] = 0
manzoku += S[day][T[day] - 1]
for i in range(26):
manzoku -= C[i] * yasumi[i]
print(manzoku) | s306760082 | Accepted | 35 | 9,516 | 456 | D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasumi))
yasumi[T[day] - 1] = 0
manzoku += S[day][T[day] - 1]
for i in range(26):
manzoku -= C[i] * yasumi[i]
print(manzoku) |
s890061340 | p02831 | u164873417 | 2,000 | 1,048,576 | Wrong Answer | 100 | 3,868 | 285 | Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests. | A, B = map(int, input().split())
N = A*B
#print(N)
if A >= B:
a = int(N/A)
for i in range(a):
if A*(a-i) % B == 0:
N = A*(a-i)
else:
b = int(N/B)
for i in range(b):
print(b-i)
if B*(b-i) % A == 0:
N = B*(b-i)
print(N) | s591877034 | Accepted | 37 | 3,060 | 257 | A, B = map(int, input().split())
N = A*B
if A >= B:
a = int(N/A)
for i in range(a):
if A*(a-i) % B == 0:
N = A*(a-i)
else:
b = int(N/B)
for i in range(b):
if B*(b-i) % A == 0:
N = B*(b-i)
print(N)
|
s826593345 | p02383 | u998435601 | 1,000 | 131,072 | Wrong Answer | 20 | 7,452 | 714 | Write a program to simulate rolling a dice, which can be constructed by the following net. As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures. | # coding: utf-8
class Dice(object):
def __init__(self):
self.x = [2, 5]
self.y = [3, 4]
self.z = [1, 6]
SN = {'S': 0, 'N': 1}
WE = {'W': 0, 'E': 1}
pass
def rotate(self, _dir):
def rot(_k, _r):
return list(reversed(_r)), _k
if _dir=='N':
self.x, self.z = rot(self.x, self.z)
elif _dir=='S':
self.z, self.x = rot(self.z, self.x)
elif _dir=='E':
self.z, self.y = rot(self.z, self.y)
elif _dir=='W':
self.y, self.z = rot(self.y, self.z)
else:
pass
def top(self):
return self.z[0]
if __name__=="__main__":
dice = Dice()
dr = input()
for d in dr:
dice.rotate(d)
print(dice.top()) | s783211891 | Accepted | 30 | 7,800 | 760 | # coding: utf-8
class Dice(object):
def __init__(self):
self.x = [2, 5]
self.y = [3, 4]
self.z = [1, 6]
SN = {'S': 0, 'N': 1}
WE = {'W': 0, 'E': 1}
pass
def rotate(self, _dir):
def rot(_k, _r):
return list(reversed(_r)), _k
if _dir=='N':
self.x, self.z = rot(self.x, self.z)
elif _dir=='S':
self.z, self.x = rot(self.z, self.x)
elif _dir=='E':
self.z, self.y = rot(self.z, self.y)
elif _dir=='W':
self.y, self.z = rot(self.y, self.z)
else:
pass
def top(self):
return self.z[0]
if __name__=="__main__":
dice = Dice()
val = list(map(int, input().split()))
dr = input()
for d in dr:
dice.rotate(d)
print(val[dice.top()-1]) |
s920119853 | p02731 | u096294926 | 2,000 | 1,048,576 | Wrong Answer | 153 | 2,940 | 130 | Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. | L = int(input())
m = 0
for i in range(L):
for j in range(L-i):
if i*j*(L-i-j)>=m:
m = i*j*(L-i-j)
print(m) | s493771924 | Accepted | 17 | 2,940 | 77 | import math
L = float(input())
m = float((L/3)**3)
print('{:.12f}'.format(m)) |
s584071661 | p04043 | u675044240 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 119 | Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order. | a = list(map(str, input().split()))
if a.count("5") == 2 and a.count("7") == 1:
print("Yes")
else:
print("No") | s586090244 | Accepted | 17 | 2,940 | 120 | a = list(map(str, input().split()))
if a.count("5") == 2 and a.count("7") == 1:
print("YES")
else:
print("NO")
|
s789724832 | p02265 | u938045879 | 1,000 | 131,072 | Wrong Answer | 20 | 5,600 | 404 | Your task is to implement a double linked list. Write a program which performs the following operations: * insert x: insert an element with key x into the front of the list. * delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything. * deleteFirst: delete the first element from the list. * deleteLast: delete the last element from the list. | n = int(input())
output = []
for i in range(n):
li = input().split(' ')
if(li[0] == 'insert'):
output.insert(0, int(li[1]))
elif(li[0] == 'delete'):
if(li[1] in output):
output.remove(int(li[1]))
elif(li[0] == 'deleteFirst'):
del output[0]
elif(li[0] == 'deleteLast'):
del output[-1]
str_l = [str(o) for o in output]
print(' '.join(str_l))
| s861967074 | Accepted | 4,680 | 69,736 | 416 | from collections import deque
n = int(input())
output = deque()
for i in range(n):
li = input().split(' ')
if(li[0] == 'insert'):
output.appendleft(li[1])
elif(li[0] == 'deleteFirst'):
output.popleft()
elif(li[0] == 'deleteLast'):
output.pop()
elif(li[0] == 'delete'):
try:
output.remove(li[1])
except:
pass
print(' '.join(output))
|
s264492851 | p03415 | u591295155 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 59 | We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. | A = input()
B = input()
C = input()
print(A[0], B[1], C[2]) | s034650545 | Accepted | 17 | 2,940 | 57 | A = input()
B = input()
C = input()
print(A[0]+B[1]+C[2]) |
s490574048 | p00087 | u452926933 | 1,000 | 131,072 | Wrong Answer | 20 | 5,576 | 753 | 博士 : ピーター君、ついにやったよ。 ピーター : またですか。今度はどんなくだらない発明ですか。 博士 : ついに数式を計算機で処理する画期的な方法を思いついたんだ。この表をみてごらん。 通常の記法| 博士の「画期的な」記法 ---|--- 1 + 2| 1 2 + 3 * 4 + 7| 3 4 * 7 + 10 / ( 2 - 12 ) | 10 2 12 - / ( 3 - 4 ) * ( 7 + 2 * 3 )| 3 4 - 7 2 3 * + * ピーター : はぁ。 博士 : ふっふっふ。これだけでは、未熟者の君には何のことだかわからないだろうねえ。ここからが肝心なんじゃ。 ピーター : っていうか・・・。 博士 : 計算機にはスタックというデータ構造があることは君も知っているね。ほれ、「先入れ後出し」のあれじゃよ。 ピーター : はい。知ってますが、あの・・・。 博士 : この画期的な記法はあのスタックを使うんじゃ。例えばこの 10 2 12 - / だが、次のように処理する。 処理対象| 10| 2| 12| -| / ---|---|---|---|---|--- | ↓| ↓| ↓| ↓2-12| ↓10/-10 スタック| | . --- . 10 | . --- 2 10 | 12 --- 2 10 | . --- -10 10 | . --- . -1 博士 : どうじゃな。括弧も演算子の優先順位も気にする必要がないじゃろう?語順も「10 を 2 から 12 を引いたもので割る。」となり、何となく彼の極東の島国の言葉、日本語と似ておるじゃろうて。 この画期的な発明さえあれば、我が研究室は安泰じゃて。ファファファ。 ピーター : っていうか博士。これって日本にいたとき会津大学の基礎コースで習いましたよ。「逆ポーランド記法」とかいって、みんな簡単にプログラムしてました。 博士 : ・・・。 ということで、ピーター君に変わって博士に、このプログラムを教える事になりました。「逆ポーランド記法」で書かれた数式を入力とし、計算結果を出力するプログラムを作成してください。 | def is_float_str(num_str, default=0):
try:
return {"is_float": True, "val": float(num_str)}
except ValueError:
return {"is_float": False, "val": default}
def compute(operand, val1, val2):
if operand == "+":
return val1 + val2
elif operand == "-":
return val1 - val2
elif operand == "*":
return val1 * val2
elif operand == "/":
return val1 / val2
# Receive input
formula = input()
# split with ' '
ops = formula.split()
stack = []
for op in ops:
if is_float_str(op)["is_float"]:
stack.append(is_float_str(op)["val"])
elif op in ['+', '-', '*', '/']:
stack.append(compute(op, stack.pop(), stack.pop()))
if len(stack) == 1:
print(stack[0])
| s530934220 | Accepted | 20 | 5,596 | 1,089 | def is_float_str(num_str, default=0):
try:
return {"is_float": True, "val": float(num_str)}
except ValueError:
return {"is_float": False, "val": default}
def compute(operand, val1, val2):
if operand == "+":
return val2 + val1
elif operand == "-":
return val2 - val1
elif operand == "*":
return val2 * val1
elif operand == "/":
return val2 / val1
def get_input():
while True:
try:
yield input()
except EOFError:
break
if __name__ == '__main__':
# split with ' '
formulas = list(get_input())
for (i, formula) in enumerate(formulas, 0):
formulas[i] = formula.split(' ')
stack = []
for formula in formulas:
stack = []
for elm in formula:
if is_float_str(elm)["is_float"]:
stack.append(is_float_str(elm)["val"])
elif elm in ['+', '-', '*', '/']:
stack.append(compute(elm, stack.pop(), stack.pop()))
if len(stack) == 1:
print(format(stack[0], '.6f'))
|
s301117813 | p03305 | u729707098 | 2,000 | 1,048,576 | Wrong Answer | 1,731 | 90,548 | 690 | Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains. Two currencies are used in the country: yen and snuuk. Any train fare can be paid by both yen and snuuk. The fare of the i-th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk. In a city with a money exchange office, you can change 1 yen into 1 snuuk. However, when you do a money exchange, you have to change all your yen into snuuk. That is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk. Currently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year. Kenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t, and change his yen into snuuk in some city while traveling. It is acceptable to do the exchange in City s or City t. Kenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange. For each i=0,...,n-1, find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years. You can assume that the trip finishes within the year. | from heapq import heappop,heappush
n,m,s,t = (int(i) for i in input().split())
x,y = [[] for i in range(n+1)],[[] for i in range(n+1)]
for i in range(m):
u,v,a,b = (int(i) for i in input().split())
x[u].append((v,a))
x[v].append((u,a))
y[u].append((v,b))
y[v].append((u,b))
def dijkstra(n,s,adj):
dis = [float("inf") for i in range(n+1)]
dis[s],q = 0,[[0,s]]
while q:
num2,num = heappop(q)
for i,j in adj[num]:
if dis[i]>num2+j:
dis[i] = num2+j
heappush(q,[dis[i],i])
return dis
X,Y,z = dijkstra(n,s,x),dijkstra(n,t,y),[]
for i in range(1,n+1): z.append((X[i]+Y[i],i))
z,k = sorted(z),0
for i in range(n):
while z[k][1]<=i: k+=1
print(z[k][0]) | s171020440 | Accepted | 1,742 | 90,572 | 697 | from heapq import heappop,heappush
n,m,s,t = (int(i) for i in input().split())
x,y = [[] for i in range(n+1)],[[] for i in range(n+1)]
for i in range(m):
u,v,a,b = (int(i) for i in input().split())
x[u].append((v,a))
x[v].append((u,a))
y[u].append((v,b))
y[v].append((u,b))
def dijkstra(n,s,adj):
dis = [float("inf") for i in range(n+1)]
dis[s],q = 0,[[0,s]]
while q:
num2,num = heappop(q)
for i,j in adj[num]:
if dis[i]>num2+j:
dis[i] = num2+j
heappush(q,[dis[i],i])
return dis
X,Y,z = dijkstra(n,s,x),dijkstra(n,t,y),[]
for i in range(1,n+1): z.append((X[i]+Y[i],i))
z,k = sorted(z),0
for i in range(n):
while z[k][1]<=i: k+=1
print(10**15-z[k][0]) |
s515615403 | p03644 | u374103100 | 2,000 | 262,144 | Wrong Answer | 21 | 3,444 | 308 | 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. |
import itertools
from collections import Counter
from collections import defaultdict
import bisect
def main():
N = int(input())
ans = 0
while N % 2 == 0:
ans += 1
N //= 2
print(ans)
if __name__ == '__main__':
main()
| s990177524 | Accepted | 21 | 3,444 | 454 |
import itertools
from collections import Counter
from collections import defaultdict
import bisect
def main():
N = int(input())
ans = 0
count = -1
for i in range(1, N+1):
c = 0
v = i
while v % 2 == 0:
c += 1
v //= 2
if c > count:
count = c
ans = i
print(ans)
if __name__ == '__main__':
main()
|
s907837249 | p02612 | u852870914 | 2,000 | 1,048,576 | Wrong Answer | 41 | 9,604 | 573 | 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. |
from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq
int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7
n = int_input()
print(n%1000) | s502978057 | Accepted | 31 | 9,600 | 623 |
from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq
int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7
n = int_input()
if (n%1000 == 0):
print(0)
else:
print(1000 - (n%1000)) |
s874492542 | p03644 | u119983020 | 2,000 | 262,144 | Wrong Answer | 17 | 2,940 | 127 | 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())
power = [1,2,4,8,16,32,64]
for i in range(len(power)):
if N <= power[i] :
print(power[i])
break
| s992798343 | Accepted | 20 | 2,940 | 95 | N = int(input())
power = [64,32,16,8,4,2,1]
for i in power:
if N >= i:
print(i)
break |
s826228722 | p00352 | u737311644 | 1,000 | 262,144 | Wrong Answer | 20 | 5,584 | 44 | Alice and Brown are brothers in a family and each receives pocket money in celebration of the coming year. They are very close and share the total amount of the money fifty-fifty. The pocket money each receives is a multiple of 1,000 yen. Write a program to calculate each one’s share given the amount of money Alice and Brown received. | a,b=map(int,input().split())
print((a+b)/2)
| s841147161 | Accepted | 20 | 5,580 | 45 | a,b=map(int,input().split())
print((a+b)//2)
|
s903274867 | p03388 | u944209426 | 2,000 | 262,144 | Wrong Answer | 18 | 3,064 | 421 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
ans = 0
AB = a[i][0]*a[i][1]
if a[i][0]<=a[i][1]:
A, B = a[i][0], a[i][1]
else:
A, B = a[i][1], a[i][0]
x = int(math.sqrt(AB))
if A==B:
ans=2*A-2
elif A+1==B:
ans= 2*A-2
elif x*(x+1)>=AB:
ans = 2*x-2
else:
ans = 2*x-1
print(ans) | s545407131 | Accepted | 18 | 3,064 | 455 | import math
q = int(input())
a = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
ans = 0
AB = a[i][0]*a[i][1]
if a[i][0]<=a[i][1]:
A, B = a[i][0], a[i][1]
else:
A, B = a[i][1], a[i][0]
x = int(math.sqrt(AB-1))
while x*x>=AB:
x-=1
if A==B:
ans=2*A-2
elif A+1==B:
ans= 2*A-2
elif x*(x+1)>=AB:
ans = 2*x-2
else:
ans = 2*x-1
print(ans) |
s222123486 | p03448 | u045176840 | 2,000 | 262,144 | Wrong Answer | 120 | 27,148 | 364 | You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. | import numpy as np
A_init = 500
B_init = 100
C_init = 50
A_list = [A_init * i for i in range(1,int(input())+1)]
B_list = [B_init * i for i in range(1,int(input())+1)]
C_list = [C_init * i for i in range(1,int(input())+1)]
X = int(input())
All_list = np.concatenate([A_list, B_list, C_list], 0)
np.count_nonzero([k+[i for i in All_list] == X for k in All_list]) | s662847536 | Accepted | 29 | 9,136 | 553 | # import numpy as np
A_init = 500
B_init = 100
C_init = 50
A_n = int(input())
B_n = int(input())
C_n = int(input())
X = int(input())
cnt = 0
for a in range(A_n+1):
if A_init * a <= X:
for b in range(B_n+1):
if (A_init * a + B_init * b) <= X:
K = X - (A_init * a + B_init * b)
if K % 50 == 0 and K / C_init <= C_n:
cnt += 1
else:
break
else:
break
print(cnt) |
s048172163 | p03152 | u905802918 | 2,000 | 1,048,576 | Wrong Answer | 22 | 3,188 | 554 | Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions: * The largest among the values in the i-th row (1 \leq i \leq N) is A_i. * The largest among the values in the j-th column (1 \leq j \leq M) is B_j. For him, find the number of ways to write the numbers under these conditions, modulo 10^9 + 7. | def f(A,B,M,N):
# return int
ans=1
mod=10**9+7
r,c=0,0
for i in range(M*N,-1,-1):
ans=ans%mod
if (i in A) and (i in B):
r+=1
c+=1
continue
if i in A:
r+=1
if c==0: return 0
ans*=c
continue
if i in B:
c+=1
if r==0: return 0
ans*=r
continue
if r!=N or c!=M:
return 0
ans*=i
return ans
N,M=(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if len(A)!=N or len(B)!=M:
print(0)
else:
print(f(A,B,M,N)) | s940635689 | Accepted | 368 | 3,188 | 793 | def f(A,B,M,N):
ans=1
MOD=10**9+7
r,c=1,1
if (M*N not in A) or (M*N not in B):
return 0;
# print("MN in A or B")
for o in range(M*N-1,0,-1):
ans=ans%MOD
if o in A:
r+=1
#row i-th's max is o:
if o in B:
c+=1
continue;
else:
# o must in colum j which not the max
ans*=c
continue
if o in B:
# o in B but not in A
c+=1
ans*=r
continue
ans*=(r*c-(M*N-o))
return ans%MOD;
N,M=(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=set(A)
B=set(B)
if len(A)!=N or len(B)!=M:
print(0)
else:
print(f(A,B,M,N)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.