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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s940801660
|
p03448
|
u021528261
| 2,000
| 262,144
|
Wrong Answer
| 48
| 3,316
| 216
|
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
|
A = int(input())
B = int(input())
C = int(input())
X = int(input())
Y = 0
for i in range(A):
for j in range(B):
for k in range(C):
if i*500 + j*100 + k*50 == X:
Y += 1
print(Y)
|
s021055963
|
Accepted
| 51
| 3,060
| 222
|
A = int(input())
B = int(input())
C = int(input())
X = int(input())
Y = 0
for i in range(A+1):
for j in range(B+1):
for k in range(C+1):
if i*500 + j*100 + k*50 == X:
Y += 1
print(Y)
|
s681329567
|
p03024
|
u065446124
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 72
|
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
|
s=input()
a=s.count("x")
if(a>7):
print("No")
else:
print("Yes")
|
s538314358
|
Accepted
| 17
| 2,940
| 72
|
s=input()
a=s.count("x")
if(a>7):
print("NO")
else:
print("YES")
|
s320138118
|
p02394
|
u302561071
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,564
| 225
|
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
|
data = input().split()
W=int(data[0])
H=int(data[1])
x=int(data[2])
y=int(data[3])
r=int(data[4])
if 0 < x - 2 < W and 0 < x + 2 < W:
if 0 < y - 2 < H and 0 < y + 2 < H:
print("Yes")
else:
print("No")
else:
print("No")
|
s083278082
|
Accepted
| 40
| 7,656
| 241
|
data = input().split()
W=int(data[0])
H=int(data[1])
x=int(data[2])
y=int(data[3])
r=int(data[4])
if (0 <= x - r <= W) and (0 <= x + r <= W):
if (0 <= y - r <= H) and (0 <= y + r <= H):
print("Yes")
else:
print("No")
else:
print("No")
|
s021899696
|
p03415
|
u928784113
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 109
|
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.
|
# -*- coding: utf-8 -*-
S = str(input())
T = str(input())
U = str(input())
print("{}".format(S[0]+S[1]+S[2]))
|
s417695715
|
Accepted
| 17
| 2,940
| 81
|
s = [input() for i in range(3)]
p = [s[i][i] for i in range(3)]
print("".join(p))
|
s147650216
|
p02833
|
u934099192
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 84
|
For an integer n not less than 0, let us define f(n) as follows: * f(n) = 1 (if n < 2) * f(n) = n f(n-2) (if n \geq 2) Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
|
n = int(input().strip())
if n % 2 == 1:
print(0)
else:
print((n/2) // 5)
|
s823175845
|
Accepted
| 18
| 2,940
| 142
|
n = int(input())
if n % 2 == 1:
print(0)
else:
ans = 0
a = 10
while a <= n:
ans += n//a
a *= 5
print(ans)
|
s237718306
|
p03545
|
u820560680
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 240
|
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.
|
ticket = input()
for i in range(1 << 3):
s = ticket[0]
for j in range(3):
if (i>>j) & 1:
s += '+' + ticket[j+1]
else:
s += '-' + ticket[j+1]
print(s)
if eval(s) == 7:
exit()
|
s499201519
|
Accepted
| 17
| 2,940
| 249
|
ticket = input()
for i in range(1 << 3):
s = ticket[0]
for j in range(3):
if (i>>j) & 1:
s += '+' + ticket[j+1]
else:
s += '-' + ticket[j+1]
if eval(s) == 7:
print(s+'=7')
exit()
|
s595367917
|
p02261
|
u626266743
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,568
| 411
|
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).
|
N = int(input())
C = list(input().split())
_C = C.copy()
for i in range(N):
for j in range(N-1, i, -1):
if (C[j] < C[j-1]):
C[j], C[j-1] = C[j-1], C[j]
print(*C)
print("Stable")
for j in range(N):
m = i
for j in range(i, N):
if (_C[j] < _C[j-1]):
m = j
_C[i], _C[m] = _C[m], _C[i]
print(*_C)
if(C ==_C):
print("Stable")
else:
print("Not stable")
|
s313459568
|
Accepted
| 50
| 7,744
| 421
|
N = int(input())
C = list(input().split())
_C = C.copy()
for i in range(N):
for j in range(N-1, i, -1):
if (C[j][1] < C[j-1][1]):
C[j], C[j-1] = C[j-1], C[j]
print(*C)
print("Stable")
for i in range(N):
m = i
for j in range(i, N):
if (_C[j][1] < _C[m][1]):
m = j
_C[i], _C[m] = _C[m], _C[i]
print(*_C)
if(C ==_C):
print("Stable")
else:
print("Not stable")
|
s499377128
|
p04029
|
u790653524
| 2,000
| 262,144
|
Wrong Answer
| 26
| 8,828
| 76
|
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 = map(int, input().split())
while n == 0:
a += n
n -= 1
print(n)
|
s598755833
|
Accepted
| 27
| 9,008
| 67
|
n = int(input())
a = 0
while n > 0:
a += n
n -= 1
print(a)
|
s725239606
|
p04012
|
u115877451
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,316
| 237
|
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
|
import collections
def calc_double(n):
return n%2
a=input()
b=collections.Counter(a)
values=zip(*b.most_common())
c=list(values)
e=c[1]
d=list(map(int,e))
print(d)
if sum(map(calc_double,d))==0:
print('Yes')
else:
print('No')
|
s695585577
|
Accepted
| 21
| 3,316
| 228
|
import collections
def calc_double(n):
return n%2
a=input()
b=collections.Counter(a)
values=zip(*b.most_common())
c=list(values)
e=c[1]
d=list(map(int,e))
if sum(map(calc_double,d))==0:
print('Yes')
else:
print('No')
|
s029405537
|
p04043
|
u171366497
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 95
|
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.
|
mondai = input()
if mondai.count('5')==2 and mondai.count('7')==1:print('Yes')
else:print('No')
|
s715632738
|
Accepted
| 18
| 2,940
| 114
|
x = input().split()
five = x.count('5')
seven = x.count('7')
if five==2 and seven==1:print('YES')
else:print('NO')
|
s316837869
|
p02419
|
u264450287
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,560
| 188
|
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
|
W=input()
Ti=[]
count=0
while True:
T=input()
if T=="END_OF_TEXT":
break
Ti += list(T.split())
for i in range(len(Ti)):
if Ti[i]==W:
count +=1
print(Ti)
print(count)
|
s767415763
|
Accepted
| 20
| 5,560
| 193
|
W=input()
Ti=[]
count=0
while True:
T=input()
s=T.lower()
if T=="END_OF_TEXT":
break
Ti += list(s.split())
for i in range(len(Ti)):
if Ti[i]==W:
count +=1
print(count)
|
s672038660
|
p03024
|
u225388820
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 116
|
Takahashi is competing in a sumo tournament. The tournament lasts for 15 days, during which he performs in one match per day. If he wins 8 or more matches, he can also participate in the next tournament. The matches for the first k days have finished. You are given the results of Takahashi's matches as a string S consisting of `o` and `x`. If the i-th character in S is `o`, it means that Takahashi won the match on the i-th day; if that character is `x`, it means that Takahashi lost the match on the i-th day. Print `YES` if there is a possibility that Takahashi can participate in the next tournament, and print `NO` if there is no such possibility.
|
s=input()
a=0
for i in range(len(s)):
if s[i]=="o":
a+=1
if a>=8:
print('YES')
else:
print('NO')
|
s328125396
|
Accepted
| 17
| 2,940
| 122
|
s=input()
b=len(s)
a=7-b
for i in range(b):
if s[i]=="o":
a+=1
if a>=0:
print('YES')
else:
print('NO')
|
s130625290
|
p03352
|
u468972478
| 2,000
| 1,048,576
|
Wrong Answer
| 27
| 9,368
| 62
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
import math
a = int(input())
print(int(math.pow(a,1/3)) ** 3)
|
s309759046
|
Accepted
| 24
| 9,020
| 91
|
a = int(input())
print(max(j ** i for j in range(32) for i in range(2, 10) if j ** i <= a))
|
s585409192
|
p03494
|
u035712734
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,316
| 152
|
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
n = int(input())
a = list(map(int, input().split()))
count = 0
while sum(a) % 2 == 0 :
for i in range(n):
a[i] = a[i] / 2
count += 1
print(count)
|
s043871380
|
Accepted
| 20
| 3,060
| 218
|
n = int(input())
a = list(map(int, input().split()))
count = 0
flag = 0
while flag == 0 :
for i in range(n):
flag += 0 if a[i] % 2 == 0 else + 1
a[i] = a[i] / 2
count += 1 if flag == 0 else +0
print(count)
|
s854224603
|
p03139
|
u657221245
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 171
|
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
|
a = list(map(int, input().split()))
if a[1] >= a[2]:
b = a[2]
if a[2] >= a[1]:
b = a[1]
c = a[0] - a[1] - a[2]
if c <= 0:
c = 0
d = str(b) + " " + str(c)
print(d)
|
s418664249
|
Accepted
| 17
| 3,060
| 174
|
a = list(map(int, input().split()))
if a[1] >= a[2]:
b = a[2]
if a[2] >= a[1]:
b = a[1]
c = (a[1] + a[2]) - a[0]
if c <= 0:
c = 0
d = str(b) + " " + str(c)
print(d)
|
s634878766
|
p03339
|
u022979415
| 2,000
| 1,048,576
|
Wrong Answer
| 233
| 22,172
| 610
|
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
|
def main():
people_num = int(input())
directions = input()
east_direction = [0]
for i in range(people_num):
if directions[i] == "E":
east_direction.append(east_direction[i] + 1)
else:
east_direction.append(east_direction[i])
answer = float("inf")
print(east_direction)
for i in range(1, people_num + 1):
change_to_east = i - 1 - east_direction[i - 1]
change_to_west = east_direction[-1] - east_direction[i]
answer = min(answer, change_to_east + change_to_west)
print(answer)
if __name__ == '__main__':
main()
|
s634501759
|
Accepted
| 189
| 15,520
| 584
|
def main():
people_num = int(input())
directions = input()
east_direction = [0]
for i in range(people_num):
if directions[i] == "E":
east_direction.append(east_direction[i] + 1)
else:
east_direction.append(east_direction[i])
answer = float("inf")
for i in range(1, people_num + 1):
change_to_east = i - 1 - east_direction[i - 1]
change_to_west = east_direction[-1] - east_direction[i]
answer = min(answer, change_to_east + change_to_west)
print(answer)
if __name__ == '__main__':
main()
|
s898273740
|
p03815
|
u595716769
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 105
|
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
|
x = int(input())
n = (x//11) * 2
for i in range(1,10):
if 11*n + i >= x:
print(11*n + i)
break
|
s808000443
|
Accepted
| 17
| 3,064
| 255
|
x = int(input())
n = (x//11)
i = 0
now = n*11
while(1):
i += 1
if x%11 == 0:
print(2*n)
break
if i%2 == 1:
now += 6
if now >= x:
print(2*n + 1)
break
else:
now += 5
if now >= x:
print(2*n + 2)
break
|
s966718175
|
p03644
|
u343977188
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 97
|
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
|
N=int(input())
ans=1
w=0
for i in range(2,N+1,2):
a=i//2
if a>w:
ans=i
w=a
print(ans)
|
s101906686
|
Accepted
| 17
| 3,064
| 100
|
N=int(input())
i=0
s=2
ans=1
while 1:
ans = s**i
if ans>N:
print(s**(i-1))
exit()
i+=1
|
s324199728
|
p03359
|
u121732701
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 78
|
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
a, b = map(int, input().split())
if b >= a:
print(a+1)
else:
print(a)
|
s867085217
|
Accepted
| 17
| 2,940
| 78
|
a, b = map(int, input().split())
if b >= a:
print(a)
else:
print(a-1)
|
s120965897
|
p02618
|
u597553490
| 2,000
| 1,048,576
|
Wrong Answer
| 47
| 9,528
| 1,236
|
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows. * The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative. * Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}. * If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)). Please schedule contests on behalf of AtCoder. If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0). There are 50 test cases, and the score of a submission is the total scores for each test case. You can make submissions multiple times, and the highest score among your submissions will be your score.
|
import sys, heapq
def calccontestnumbers(D, complaints, satisfications):
ContestDays = [1] * 26
HoldedContests = [-1] * D
for i in range(D):
Demands = []
for j in range(26):
Demand_j = ContestDays[j] * complaints[j] + satisfications[i][j]
heapq.heappush(Demands, (-Demand_j, j) )
ContestDays[j] += 1
print("Day", i, ":", Demands)
Demand_Contest = heapq.heappop(Demands)
Contest = Demand_Contest[1]
ContestDays[Contest] =1
HoldedContests[i] = Contest+1
return HoldedContests
if(__name__ == "__main__"):
D = int(input().strip())
complaints = list(map(int, input().split() ) )
satisfications = []
for i in range(D):
satisfication = list(map(int, input().split() ) )
satisfications.append(satisfication)
HoldedContests = calccontestnumbers(D, complaints, satisfications)
for i in range(D):
print(HoldedContests[i])
|
s036868604
|
Accepted
| 35
| 9,376
| 1,508
|
import sys, heapq
def calccontestnumbers(D, complaints, satisfications):
ContestDays = [1] * 26
HoldedContests = [-1] * D
for i in range(D-1):
Demands = []
for j in range(26):
Demand_j = ContestDays[j] * complaints[j] + satisfications[i][j]
heapq.heappush(Demands, (-Demand_j, j) )
ContestDays[j] += 1
Demand_Contest = heapq.heappop(Demands)
Contest = Demand_Contest[1]
ContestDays[Contest] =1
HoldedContests[i] = Contest+1
Demands = []
for j in range(26):
Demand_j = -ContestDays[j] * complaints[j] + satisfications[D-1][j]
heapq.heappush(Demands, (-Demand_j, j) )
ContestDays[j] += 1
Demand_Contest = heapq.heappop(Demands)
Contest = Demand_Contest[1]
HoldedContests[D-1] = Contest+1
return HoldedContests
if(__name__ == "__main__"):
D = int(input().strip())
complaints = list(map(int, input().split() ) )
satisfications = []
for i in range(D):
satisfication = list(map(int, input().split() ) )
satisfications.append(satisfication)
HoldedContests = calccontestnumbers(D, complaints, satisfications)
for i in range(D):
print(HoldedContests[i])
|
s236365154
|
p03815
|
u225388820
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 68
|
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
|
n=int(input())
a=2*n//11
b=(n%11)//6
c=n%11 %5
print(a+b+((c+4)//5))
|
s975795380
|
Accepted
| 17
| 2,940
| 70
|
n=int(input())
a=2*(n//11)
b=(n%11)//6
c=n%11 %6
print(a+b+((c+4)//5))
|
s575223950
|
p03449
|
u373047809
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 111
|
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, *a = map(int, open(0).read().split())
m = 0
for i in range(n+1):
m = max(m, sum(a[:i] + a[n+i:]))
print(m)
|
s913694228
|
Accepted
| 19
| 3,060
| 109
|
n, *a = map(int, open(0).read().split())
m = 0
for i in range(n): m = max(m, sum(a[:i+1] + a[n+i:]))
print(m)
|
s593121107
|
p02399
|
u007066325
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,596
| 79
|
Write a program which reads two integers a and b, and calculates the following values: * a ÷ b: d (in integer) * remainder of a ÷ b: r (in integer) * a ÷ b: f (in real number)
|
a , b = map(int, input().split())
print("{} {} {}".format(int(a/b), a%b, a/b))
|
s590306339
|
Accepted
| 20
| 5,608
| 75
|
(a,b)=(int(i) for i in input().split())
print('%s %s %.5f'%(a//b,a%b,a/b))
|
s436737046
|
p03006
|
u830054172
| 2,000
| 1,048,576
|
Wrong Answer
| 22
| 3,572
| 419
|
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1. Find the minimum total cost required to collect all the balls when we optimally choose p and q.
|
from collections import Counter
n=int(input())
if n==1:
print(1)
exit()
xy=[tuple(map(int,input().split())) for _ in range(n)]
print(xy)
xy.sort()
print(xy)
l=[]
for i in range(n-1):
for j in range(i+1,n):
l.append((xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]))
print(n-Counter(l).most_common()[0][1])
|
s396296767
|
Accepted
| 22
| 3,572
| 423
|
from collections import Counter
n=int(input())
if n==1:
print(1)
exit()
xy=[tuple(map(int,input().split())) for _ in range(n)]
# print(xy)
xy.sort()
# print(xy)
l=[]
for i in range(n-1):
for j in range(i+1,n):
l.append((xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]))
print(n-Counter(l).most_common()[0][1])
|
s497701275
|
p03469
|
u724687935
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 34
|
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
S = input()
print('2017' + S[4:])
|
s159851475
|
Accepted
| 17
| 2,940
| 34
|
S = input()
print('2018' + S[4:])
|
s575377784
|
p02389
|
u884012707
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,612
| 40
|
Write a program which calculates the area and perimeter of a given rectangle.
|
a,b=map(int, input().split())
print(a*b)
|
s059079002
|
Accepted
| 20
| 7,616
| 49
|
a,b=map(int, input().split())
print(a*b, a+a+b+b)
|
s594516456
|
p03997
|
u287431190
| 2,000
| 262,144
|
Wrong Answer
| 19
| 2,940
| 67
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h/2)
|
s051894746
|
Accepted
| 17
| 2,940
| 74
|
a = int(input())
b = int(input())
h = int(input())
s = (a+b)*h//2
print(s)
|
s732991423
|
p03673
|
u853900545
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 26,180
| 122
|
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
|
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
b.append(a[i])
b = b[::-1]
print(b)
|
s294105318
|
Accepted
| 47
| 24,260
| 71
|
n = int(input())
a = input().split()
print(" ".join(a[::-2]+a[n%2::2]))
|
s471320884
|
p02388
|
u427219397
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,572
| 49
|
Write a program which calculates the cube of a given integer x.
|
s = input()
n = int(s) ** 3
print('s =','n =',n)
|
s284720007
|
Accepted
| 20
| 5,576
| 29
|
x = int(input())
print(x**3)
|
s985748448
|
p03149
|
u293992530
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 162
|
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
|
N = list(map(int,input().split()))
answer = 'No'
if 1 in N:
if 9 in N:
if 4 in N:
if 7 in N:
answer = "Yes"
print(answer)
|
s867892399
|
Accepted
| 17
| 2,940
| 162
|
N = list(map(int,input().split()))
answer = 'NO'
if 1 in N:
if 9 in N:
if 4 in N:
if 7 in N:
answer = "YES"
print(answer)
|
s588862308
|
p03992
|
u290187182
| 2,000
| 262,144
|
Wrong Answer
| 26
| 3,828
| 318
|
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
|
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
def lcm(x, y):
return (x * y) // math.gcd(x, y)
if __name__ == '__main__':
a = [str(i) for i in input().split()]
print(a[0][:4]+" "+a[0][5:])
|
s275917706
|
Accepted
| 26
| 3,828
| 318
|
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
def lcm(x, y):
return (x * y) // math.gcd(x, y)
if __name__ == '__main__':
a = [str(i) for i in input().split()]
print(a[0][:4]+" "+a[0][4:])
|
s328559682
|
p03610
|
u229621546
| 2,000
| 262,144
|
Wrong Answer
| 47
| 3,828
| 64
|
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
|
list = input();
for i in range(0,len(list),2):
print(list[i]);
|
s868074768
|
Accepted
| 74
| 4,596
| 80
|
list = input();
for i in range(0,len(list),2):
print(list[i],end="");
print();
|
s373234094
|
p04045
|
u506888990
| 2,000
| 262,144
|
Wrong Answer
| 108
| 3,060
| 363
|
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
|
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
print(l)
while True:
N_str = str(N)
frag = 0
for i in range(len(N_str)):
if int(N_str[i]) in l:
#print("yes")
frag = 1
break
if frag == 0:
break
else:
N += 1
print(N)
|
s896029220
|
Accepted
| 107
| 3,060
| 365
|
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
#print(l)
while True:
N_str = str(N)
frag = 0
for i in range(len(N_str)):
if int(N_str[i]) in l:
#print("yes")
frag = 1
break
if frag == 0:
break
else:
N += 1
print(N)
|
s612384817
|
p03456
|
u022215787
| 2,000
| 262,144
|
Wrong Answer
| 25
| 9,124
| 130
|
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
a, b = map(int, input().split())
ab = a*10+b
ans = 'No'
for i in range(1, 101):
if i*i == ab:
ans='Yes'
break
print(ans)
|
s647355253
|
Accepted
| 31
| 9,080
| 114
|
a, b = input().split()
ab = int(a+b)
import math
if math.sqrt(ab).is_integer():
print('Yes')
else:
print('No')
|
s436030093
|
p03657
|
u556371693
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 111
|
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
|
a,b=map(int,input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
print('possible')
else:
print('Impossible')
|
s982331339
|
Accepted
| 18
| 2,940
| 112
|
a,b=map(int,input().split())
if a%3==0 or b%3==0 or (a+b)%3==0:
print('Possible')
else:
print('Impossible')
|
s437031004
|
p02663
|
u020390084
| 2,000
| 1,048,576
|
Wrong Answer
| 22
| 9,204
| 575
|
In this problem, we use the 24-hour clock. Takahashi gets up exactly at the time H_1 : M_1 and goes to bed exactly at the time H_2 : M_2. (See Sample Inputs below for clarity.) He has decided to study for K consecutive minutes while he is up. What is the length of the period in which he can start studying?
|
#!/usr/bin/env python3
import sys
def solve(H: "List[int]", M: "List[int]", K: int):
print(M[0]*60+M[1]-H[0]*60-H[1]-K)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
H = [int()] * (2) # type: "List[int]"
M = [int()] * (2) # type: "List[int]"
for i in range(2):
H[i] = int(next(tokens))
M[i] = int(next(tokens))
K = int(next(tokens)) # type: int
solve(H, M, K)
if __name__ == '__main__':
main()
|
s204720056
|
Accepted
| 21
| 9,168
| 290
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def main():
A,B,C,D,K = MAP()
print(C*60+D-A*60-B-K)
if __name__ == '__main__':
main()
|
s184840405
|
p03997
|
u982020214
| 2,000
| 262,144
|
Wrong Answer
| 24
| 3,188
| 68
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a = int(input())
b = int(input())
h = int(input())
print((a+b)*h/2)
|
s291189498
|
Accepted
| 23
| 3,064
| 73
|
a = int(input())
b = int(input())
h = int(input())
print(int((a+b)*h/2))
|
s927747218
|
p02259
|
u181187284
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,660
| 315
|
Write a program of the Bubble Sort algorithm which sorts a sequence _A_ in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode.
|
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
x = int(input())
y = list(map(int,input().split()))
z = 0
flag = 1
while flag:
flag = 0
i = x - 1
while i > 0:
if y[i] < y[i - 1]:
y[i], y[i - 1] = y[i - 1], y[i]
flag = 1
z += 1
i -= 1
print(z)
print(" ".join(list(map(str,y))))
|
s127523397
|
Accepted
| 20
| 7,692
| 315
|
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
x = int(input())
y = list(map(int,input().split()))
z = 0
flag = 1
while flag:
flag = 0
i = x - 1
while i > 0:
if y[i] < y[i - 1]:
y[i], y[i - 1] = y[i - 1], y[i]
flag = 1
z += 1
i -= 1
print(" ".join(list(map(str,y))))
print(z)
|
s928170228
|
p03050
|
u674574659
| 2,000
| 1,048,576
|
Wrong Answer
| 1,942
| 21,248
| 167
|
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.
|
import math
N = int(input())
ans = 0
for m in range(1,math.ceil(N**(1/2))):
if N == m*((N-m)/m)+m:
ans += int((N-m)/m)
print(ans,int((N-m)/m))
print(ans)
|
s990033580
|
Accepted
| 177
| 3,064
| 235
|
import math
N = int(input())
ans = 0
for m in range(1,math.ceil(N**(1/2))):
if (N-m)%m == 0 and m < (N-m)//m:
ans += int((N-m)/m)
if N == 1:
ans = 0
if N == 2:
ans = 0
if N == 3:
ans = 2
if N == 6:
ans = 5
print(ans)
|
s656546041
|
p03474
|
u934119021
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,188
| 221
|
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
import re
a, b = map(int, input().split())
s = input()
if s[a] == '-':
s = re.sub(r'-', '', s)
print(s)
if re.fullmatch(r'[0-9]+', s) and len(s) == a + b:
print('Yes')
else:
print('No')
else:
print('No')
|
s841441717
|
Accepted
| 20
| 3,188
| 234
|
import re
a, b = map(int, input().split())
s = input()
if s[a] == '-' and len(s) == a + b + 1:
s = re.sub(r'-', '', s)
if re.fullmatch(r'[0-9]+', s) and len(s) == a + b:
print('Yes')
else:
print('No')
else:
print('No')
|
s088452845
|
p03796
|
u259738923
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 3,464
| 72
|
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())
P = 1
for i in range(1, N):
P *= i
print(P%(10**9+7))
|
s795451178
|
Accepted
| 41
| 2,940
| 124
|
N = int(input())
num = N+1
pre = 1
for i in range(1,num):
total = i * pre
pre = total % (10 ** 9 + 7)
else:
print(pre)
|
s377406380
|
p03759
|
u188745744
| 2,000
| 262,144
|
Wrong Answer
| 18
| 2,940
| 96
|
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 = list(map(int,input().split()))
if abs(A-B) == abs(B-C):
print("Yes")
else:
print("No")
|
s593469334
|
Accepted
| 17
| 2,940
| 82
|
a,b,c=map(int,input().split())
if b-a==c-b:
print('YES')
else:
print('NO')
|
s652509496
|
p03644
|
u911562010
| 2,000
| 262,144
|
Wrong Answer
| 29
| 9,020
| 50
|
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())
k=1
while n>k:
k=k*2
print(k)
|
s869121540
|
Accepted
| 29
| 9,160
| 71
|
n=int(input())
k=1
while n>=k:
k=k*2
if k!=1:
k=k//2
print(k)
|
s250323705
|
p03149
|
u960513073
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 122
|
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
|
n = list(map(int, input().split()))
if "1" in n and "9" in n and "7" in n and "4" in n:
print("YES")
else:
print("NO")
|
s300308162
|
Accepted
| 17
| 2,940
| 112
|
n = list(input().split())
if "1" in n and "9" in n and "7" in n and "4" in n:
print("YES")
else:
print("NO")
|
s160218161
|
p03371
|
u223904637
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 136
|
"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())
y=min(a+b,2*c)
s=min(x,y)
if x>y:
n=x-y
k=a
else:
n=y-x
k=b
print(y*s+n*min(k,2*c))
|
s776662110
|
Accepted
| 19
| 3,060
| 139
|
a,b,c,x,y = map(int,input().split())
ya=min(a+b,2*c)
s=min(x,y)
if x>y:
n=x-y
k=a
else:
n=y-x
k=b
print(ya*s+n*min(k,2*c))
|
s371397706
|
p02396
|
u315329386
| 1,000
| 131,072
|
Wrong Answer
| 160
| 7,632
| 136
|
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.
|
cnt = 1
while True:
num = int(input())
if num == 0:
break
print("case", str(cnt) + ":", num, sep = " ")
cnt += 1
|
s858564260
|
Accepted
| 150
| 7,544
| 136
|
cnt = 1
while True:
num = int(input())
if num == 0:
break
print("Case", str(cnt) + ":", num, sep = " ")
cnt += 1
|
s758390970
|
p03401
|
u124592621
| 2,000
| 262,144
|
Wrong Answer
| 2,104
| 28,024
| 351
|
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.
|
N = int(input())
A = list(map(int, input().split()))
amounts = [0] * N
for n in range(N):
spot = A[:n] + A[(n+1):]
print(*spot)
amount = 0
for i in range(1, N - 1):
amount += abs(spot[i-1] - spot[i])
amount += abs(spot[0])
amount += abs(spot[N - 2])
amounts[n] = amount
for i in range(N):
print(amounts[i])
|
s537736489
|
Accepted
| 241
| 14,172
| 433
|
N = int(input())
A = list(map(int, input().split()))
total = 0
total = abs(A[0])
total += abs(A[N - 1])
for i in range(1, N):
total += abs(A[i - 1] - A[i])
amounts = [0] * N
for i in range(N):
left = 0
right = 0
if i > 0:
left = A[i - 1]
if i < N - 1:
right = A[i + 1]
amounts[i] = total + abs(left - right) - (abs(left - A[i]) + abs(A[i] - right))
for i in range(N):
print(amounts[i])
|
s190919461
|
p02842
|
u766566560
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 107
|
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.
|
import math
N = int(input())
if math.ceil(N / 1.08) != N:
print(':(')
else:
print(math.ceil(N / 1.08))
|
s003951261
|
Accepted
| 17
| 2,940
| 126
|
import math
N = int(input())
if math.floor(math.ceil(N / 1.08) * 1.08) == N:
print(math.ceil(N / 1.08))
else:
print(':(')
|
s572356083
|
p02853
|
u663710122
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 160
|
We held two competitions: Coding Contest and Robot Maneuver. In each competition, the contestants taking the 3-rd, 2-nd, and 1-st places receive 100000, 200000, and 300000 yen (the currency of Japan), respectively. Furthermore, a contestant taking the first place in both competitions receives an additional 400000 yen. DISCO-Kun took the X-th place in Coding Contest and the Y-th place in Robot Maneuver. Find the total amount of money he earned.
|
X, Y = map(int, input().split())
P = [300000, 200000, 100000, 0]
if X == 1 and Y == 1:
print(100000)
else:
print(P[min(3, X - 1)] + P[min(3, Y - 1)])
|
s907798200
|
Accepted
| 17
| 2,940
| 161
|
X, Y = map(int, input().split())
P = [300000, 200000, 100000, 0]
if X == 1 and Y == 1:
print(1000000)
else:
print(P[min(3, X - 1)] + P[min(3, Y - 1)])
|
s930479096
|
p03150
|
u478266845
| 2,000
| 1,048,576
|
Wrong Answer
| 19
| 3,060
| 379
|
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.
|
Key_str = 7
S = str(input())
count =0
if len(S)<Key_str:
print("No")
else:
del_str = len(S)-Key_str
for i in range(len(S)-del_str):
try_str = S[:i] + S[i+del_str:]
if try_str == 'keyence':
print("Yes")
count+=1
break
if count==0:
print("No")
|
s365205468
|
Accepted
| 17
| 3,060
| 379
|
Key_str = 7
S = str(input())
count =0
if len(S)<Key_str:
print("No")
else:
del_str = len(S)-Key_str
for i in range(len(S)-del_str):
try_str = S[:i] + S[i+del_str:]
if try_str == 'keyence':
print("YES")
count+=1
break
if count==0:
print("NO")
|
s655732998
|
p00015
|
u334031393
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,724
| 63
|
A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given integers or the sum have more than 80 digits, print "overflow".
|
import sys
a = int(input())
b = int(input())
print(a + b)
|
s958768915
|
Accepted
| 30
| 6,720
| 171
|
import sys
n = int(input())
for i in range(n):
a = int(input())
b = int(input())
if a + b >= 10**80:
print ("overflow")
else:
print(a + b)
|
s634959961
|
p04030
|
u193264896
| 2,000
| 262,144
|
Wrong Answer
| 21
| 3,316
| 479
|
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?
|
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
S = readline().decode('utf-8')
L = len(S)
d = deque()
for i in range(L):
if S[i]=='0':
d.append(0)
elif S[i]=='1':
d.append(1)
else:
if len(d)!=0:
d.pop()
print(''.join(map(str,d)))
if __name__ == '__main__':
main()
|
s540700254
|
Accepted
| 21
| 3,316
| 460
|
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
S = input()
L = len(S)
d = deque()
for i in range(L):
if S[i]=='0':
d.append(0)
elif S[i]=='1':
d.append(1)
else:
if len(d)!=0:
d.pop()
print(''.join(map(str,d)))
if __name__ == '__main__':
main()
|
s485476541
|
p03548
|
u626337957
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 54
|
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
|
X, Y, Z = map(int, input().split())
print((X-Z)%(Y+Z))
|
s870171443
|
Accepted
| 17
| 2,940
| 56
|
X, Y, Z = map(int, input().split())
print((X-Z)//(Y+Z))
|
s149792139
|
p03090
|
u893063840
| 2,000
| 1,048,576
|
Wrong Answer
| 24
| 3,700
| 377
|
You are given an integer N. Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions: * The graph is simple and connected. * There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S. It can be proved that at least one such graph exists under the constraints of this problem.
|
n = int(input())
g = [[1] * (n + 1) for _ in range(n + 1)]
if n % 2:
for i in range(1, n + 1):
j = n - i
g[i][j] = 0
g[j][i] = 0
else:
for i in range(1, n + 1):
j = n + 1 - i
g[i][j] = 0
g[j][i] = 0
for i, row in enumerate(g[1:], 1):
for j, bl in enumerate(row[i+1:], i+1):
if bl:
print(i, j)
|
s086434358
|
Accepted
| 25
| 3,996
| 443
|
n = int(input())
g = [[1] * (n + 1) for _ in range(n + 1)]
if n % 2:
for i in range(1, n + 1):
j = n - i
g[i][j] = 0
g[j][i] = 0
else:
for i in range(1, n + 1):
j = n + 1 - i
g[i][j] = 0
g[j][i] = 0
ans = []
for i, row in enumerate(g[1:], 1):
for j, bl in enumerate(row[i+1:], i+1):
if bl:
ans.append((i, j))
print(len(ans))
for i, j in ans:
print(i, j)
|
s243822339
|
p04011
|
u327532412
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 137
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
n = int(input())
k = int(input())
x = int(input())
y = int(input())
if n <= k:
print(n * x)
else:
print((n * x) + ((n - k) * y))
|
s960758696
|
Accepted
| 17
| 2,940
| 137
|
n = int(input())
k = int(input())
x = int(input())
y = int(input())
if n <= k:
print(n * x)
else:
print((k * x) + ((n - k) * y))
|
s099197943
|
p03407
|
u642120132
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 72
|
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
|
a, b, c = map(int, input().split())
print('Yes' if a + b <= c else 'No')
|
s770132878
|
Accepted
| 17
| 2,940
| 72
|
a, b, c = map(int, input().split())
print('Yes' if a + b >= c else 'No')
|
s218929788
|
p02392
|
u184989919
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,572
| 132
|
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
|
def Range():
a,b,c = list(map(int,input().split()))
if a<b<c:
print("YES")
else:
print("NO")
Range()
|
s086078894
|
Accepted
| 20
| 7,728
| 130
|
def Range():
a,b,c = list(map(int,input().split()))
if a<b<c:
print("Yes")
else:
print("No")
Range()
|
s288675719
|
p02831
|
u346358363
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,064
| 246
|
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 = [int(i) for i in input().split(' ')]
if A>B:
A, B = B, A
def eculidian_algo(A,B):
while True:
q = A//B
r = A%B
if r==0:
break
else:
A,B=B,r
return B
lcd = eculidian_algo(A,B)
gcm = A*B / lcd
print(gcm)
|
s519012768
|
Accepted
| 19
| 2,940
| 176
|
A, B = [int(i) for i in input().split(' ')]
def gcd(x, y):
while y > 0:
x, y = y, x%y
return x
def lcm(x, y):
return x/gcd(x, y)*y
print(int(lcm(A,B)))
|
s291536085
|
p02411
|
u567380442
| 1,000
| 131,072
|
Wrong Answer
| 30
| 6,720
| 419
|
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
|
import sys
for line in sys.stdin:
m, f, r = map(int, line.split())
if m == f == r == -1:
break
if m == -1 or f == -1:
print('F')
elif (m + f) >= 80:
print('A')
elif (m + f) >= 65:
print('B')
elif (m + f) >= 50:
print('C')
elif (m + f) >= 30:
if r >= 50:
print('C')
else:
print('D')
else:
print('E')
|
s095851372
|
Accepted
| 40
| 6,728
| 419
|
import sys
for line in sys.stdin:
m, f, r = map(int, line.split())
if m == f == r == -1:
break
if m == -1 or f == -1:
print('F')
elif (m + f) >= 80:
print('A')
elif (m + f) >= 65:
print('B')
elif (m + f) >= 50:
print('C')
elif (m + f) >= 30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F')
|
s586597341
|
p02398
|
u776758454
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,660
| 418
|
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
|
def main():
a, b, c = map(int,input().split())
_set = set()
if a <= c and b >= c: _set.add(c)
if c // 2 < b:
b = c // 2
if c % 2 == 0:
_set = _set | set(range(a, b+1))
else:
if a % 2 == 0:
_set = _set | set(range(a+1, b+1, 2))
else:
_set = _set | set(range(a, b+1, 2))
return sum(map(lambda x: c % x == 0, _set))
main()
|
s241027493
|
Accepted
| 30
| 8,168
| 421
|
def main():
a, b, c = map(int,input().split())
_set = set()
if a <= c and b >= c: _set.add(c)
if c // 2 < b:
b = c // 2
if c % 2 == 0:
_set = _set | set(range(a, b+1))
else:
if a % 2 == 0:
_set = _set | set(range(a+1, b+1, 2))
else:
_set = _set | set(range(a, b+1, 2))
print(sum(map(lambda x: c % x == 0, _set)))
main()
|
s126963968
|
p02842
|
u776864893
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 2,940
| 112
|
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.
|
input_ = int(input())
ex_ = input_ / (1.08)
if (ex_ - int(ex_)) > 0.1:
print(round(ex_))
else:
print(":(")
|
s443900995
|
Accepted
| 33
| 2,940
| 124
|
input_ = int(input())
for i in range(input_):
if int((i+1)*1.08) == input_:
print(i+1)
break
else:
print(":(")
|
s836233606
|
p03457
|
u789562878
| 2,000
| 262,144
|
Wrong Answer
| 368
| 3,060
| 309
|
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
|
N = int(input())
t0 = 0
x0 = 0
y0 = 0
for i in range(0, N):
t1, x1, y1 = map(int, input().split())
indicator = abs(x1-x0)+abs(y1-y0)-(t1-t0)
if indicator>0 or indicator%2==1:
print("NO")
break
elif i==N-1:
print("YES")
break
t0 = t1
x0 = x1
y0 = y1
|
s911332759
|
Accepted
| 365
| 3,060
| 274
|
N = int(input())
t0 = 0
x0 = 0
y0 = 0
for i in range(0, N):
t1, x1, y1 = map(int, input().split())
id = (t1-t0)-abs(x1-x0)-abs(y1-y0)
if id<0 or id%2==1:
print("No")
break
elif i==N-1:
print("Yes")
t0 = t1
x0 = x1
y0 = y1
|
s796627904
|
p00001
|
u655138261
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,620
| 260
|
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.
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
def main():
mountains = []
for i in range(3):
mountains.append(int(input()))
mountains = sorted(mountains, reverse = True)
for i in range(3):
print(mountains[i])
if __name__ == '__main__':
main()
|
s685788251
|
Accepted
| 20
| 7,736
| 261
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
def main():
mountains = []
for i in range(10):
mountains.append(int(input()))
mountains = sorted(mountains, reverse = True)
for i in range(3):
print(mountains[i])
if __name__ == '__main__':
main()
|
s142158000
|
p03545
|
u135847648
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,064
| 277
|
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
S = input()
count = len(S)-1
for i in range(2**count):
sign=['-']*count
for j in range(count):
if ((i>>j)&1):
sign[j]='+'
formula=''
for k in range(count):
formula += S[k] + sign[k]
formula += S[count]
if eval(formula)==7:
print(formula)
break
|
s868892985
|
Accepted
| 17
| 3,064
| 282
|
S = input()
count = len(S)-1
for i in range(2**count):
sign=['-']*count
for j in range(count):
if ((i>>j)&1):
sign[j]='+'
formula=''
for k in range(count):
formula += S[k] + sign[k]
formula += S[count]
if eval(formula)==7:
print(formula+'=7')
break
|
s124921624
|
p04043
|
u525796732
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 182
|
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,b,c = map(int,input().split())
numberlist=[a,b,c]
numberlist.sort()
if (numberlist[0]==5 and numberlist[1]==5 and numberlist==[2]==7):
print('YES')
else :
print('NO')
|
s479558171
|
Accepted
| 17
| 2,940
| 175
|
a,b,c = map(int,input().split())
numberlist=[a,b,c]
numberlist.sort()
if (numberlist[0]==5 and numberlist[1]==5 and numberlist[2]==7):
print('YES')
else :
print('NO')
|
s511514192
|
p02471
|
u150984829
| 1,000
| 131,072
|
Wrong Answer
| 20
| 5,656
| 133
|
Given positive integers a and b, find the integer solution (x, y) to ax + by = gcd(a, b), where gcd(a, b) is the greatest common divisor of a and b.
|
import math
a,b=map(int,input().split())
c=math.gcd(a,b)
for x in range(b):
y=(c-a*x)/b
if int(y)==y:x=x;print(y);break
print(x,y)
|
s738632804
|
Accepted
| 20
| 5,596
| 101
|
r,s=map(int,input().split())
a=d=1;b=c=0
while s:q=r//s;r,s,a,c,b,d=s,r%s,c,a-q*c,d,b-q*d
print(a,b)
|
s738545114
|
p02697
|
u994521204
| 2,000
| 1,048,576
|
Wrong Answer
| 83
| 9,292
| 121
|
You are going to hold a competition of one-to-one game called AtCoder Janken. _(Janken is the Japanese name for Rock-paper-scissors.)_ N players will participate in this competition, and they are given distinct integers from 1 through N. The arena has M playing fields for two players. You need to assign each playing field two distinct integers between 1 and N (inclusive). You cannot assign the same integer to multiple playing fields. The competition consists of N rounds, each of which proceeds as follows: * For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there. * Then, each player adds 1 to its integer. If it becomes N+1, change it to 1. You want to ensure that no player fights the same opponent more than once during the N rounds. Print an assignment of integers to the playing fields satisfying this condition. It can be proved that such an assignment always exists under the constraints given.
|
n, m = map(int, input().split())
for i in range(m):
num1 = 1 + i
num2 = 2 * m - i
print(num1, num2, sep=" ")
|
s284382631
|
Accepted
| 92
| 9,112
| 761
|
n, m = map(int, input().split())
if m % 2 == 1:
cnt = 0
for i in range(m // 2):
num1 = 1 + i
num2 = m - i
print(num1, num2, sep=" ")
cnt += 1
if cnt == m:
exit()
for i in range(m // 2 + 1):
num1 = m + 1 + i
num2 = 2 * m + 1 - i
print(num1, num2, sep=" ")
cnt += 1
if cnt == m:
exit()
else:
cnt = 0
for i in range(m // 2):
num1 = 1 + i
num2 = m + 1 - i
print(num1, num2, sep=" ")
cnt += 1
if cnt == m:
exit()
for i in range(m // 2):
num1 = m + 2 + i
num2 = 2 * m + 1 - i
print(num1, num2, sep=" ")
cnt += 1
if cnt == m:
exit()
|
s040482230
|
p03697
|
u910358825
| 2,000
| 262,144
|
Wrong Answer
| 26
| 9,080
| 65
|
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output `error` instead.
|
a,b=map(int, input().split())
print("error" if a*b>=10 else a*b)
|
s922005907
|
Accepted
| 21
| 8,996
| 65
|
a,b=map(int, input().split())
print("error" if a+b>=10 else a+b)
|
s954666418
|
p03141
|
u329709276
| 2,000
| 1,048,576
|
Wrong Answer
| 2,014
| 35,356
| 248
|
There are N dishes of cuisine placed in front of Takahashi and Aoki. For convenience, we call these dishes Dish 1, Dish 2, ..., Dish N. When Takahashi eats Dish i, he earns A_i points of _happiness_ ; when Aoki eats Dish i, she earns B_i points of happiness. Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat. Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end". Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".
|
n = int(input())
AB = [list(map(int,input().split())) for _ in range(n)]
AB = sorted(AB,key=lambda x:x[0] - x[1])
print(AB)
t = 0
a = 0
for i in range(n):
if i % 2 == 0:
t += AB.pop(0)[0]
else:
a += AB.pop(0)[1]
print(t-a)
|
s328261518
|
Accepted
| 365
| 21,580
| 238
|
n = int(input())
AB = [tuple(map(int,input().split())) for _ in range(n)]
all_b = sum([b for _,b in AB])
AB = sorted([a + b for a,b in AB],reverse=True)
ans = 0
for i in range(n):
if i % 2 == 0:
ans += AB[i]
print(ans - all_b)
|
s999949567
|
p03545
|
u225388820
| 2,000
| 262,144
|
Wrong Answer
| 17
| 3,060
| 242
|
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
|
s=input()
for i in range(8):
ans=s[0]
cnt=int(s[0])
for j in range(3):
if i>>j & 1:
ans+="+"+s[j+1]
cnt+=int(s[j+1])
else:
ans+="-"+s[j+1]
if cnt==7:
print(ans+"+=7")
|
s886169572
|
Accepted
| 19
| 3,192
| 279
|
a,*x=list(map(int,input()))
for i in range(8):
k=a
ans=str(a)
for j in range(3):
if i>>j&1:
k+=x[j]
ans+="+"+str(x[j])
else:
k-=x[j]
ans+="-"+str(x[j])
if k==7:
print(ans+"=7")
exit()
|
s060876388
|
p04011
|
u381739460
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 72
|
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.
|
a = int(input())
b = int(input())
c = int(input())
print(int((a+b)*c/2))
|
s964630260
|
Accepted
| 17
| 3,060
| 149
|
n = int(input())
k = int(input())
x = int(input())
y = int(input())
ans = 0
if n <= k:
ans = x*n
else:
ans = x*k + y*(n-k)
print(ans)
|
s578407898
|
p02401
|
u936401118
| 1,000
| 131,072
|
Wrong Answer
| 20
| 7,428
| 77
|
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
while True:
x = input()
if '?' in x:
break
print(eval(x))
|
s815071631
|
Accepted
| 30
| 7,436
| 82
|
while True:
x = input()
if '?' in x:
break
print(int(eval(x)))
|
s111369574
|
p03339
|
u672494157
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 660
|
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
|
def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def solve(inputs):
persons = list(map(lambda x: x, inputs[0]))
N = len(persons)
counts = []
for leader, _ in enumerate(persons):
count = 0
for p in range(0, leader):
if persons[p] == "W":
count += 1
for p in range(leader + 1, N):
if persons[p] == "E":
count += 1
counts.append(count)
min = counts[0]
for count in counts:
if min > count:
min = count
return min
if __name__ == "__main__":
ret = solve(inputs(1))
print(ret)
|
s870028586
|
Accepted
| 135
| 19,832
| 690
|
import sys
from functools import reduce
import copy
import math
sys.setrecursionlimit(4100000)
def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def solve(inputs):
persons = list(inputs[0])
count = [persons[1:].count("E")]
for i in range(1, len(persons)):
if i == 0:
continue
tmp = count[-1]
if persons[i - 1] == 'W':
tmp += 1
if persons[i] == 'E':
tmp -= 1
count.append(tmp)
return min(count)
def string_to_int(string):
return list(map(int, string.split()))
if __name__ == "__main__":
input()
ret = solve(inputs(1))
print(ret)
|
s314336629
|
p03006
|
u534308356
| 2,000
| 1,048,576
|
Wrong Answer
| 22
| 3,572
| 743
|
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1. Find the minimum total cost required to collect all the balls when we optimally choose p and q.
|
import itertools
from collections import Counter
def main():
N = int(input())
data = []
for _ in range(N):
data.append( list(map(int, input().split())) )
if N <= 2:
return 1
else:
key_num = ( N*(N - 3) ) // 2 + N
common_data = []
max_common_num = 0
for obj in itertools.combinations(data, 2):
# print(obj)
common_data.append( str(obj[0][0] - obj[1][0]) + "_" + str(obj[0][1] - obj[1][1]) )
counter = Counter(common_data)
for word, cnt in counter.most_common():
max_common_num = cnt
break
print(N - max_common_num)
# print(common_data)
if __name__ == '__main__':
main()
|
s476480321
|
Accepted
| 22
| 3,572
| 742
|
import itertools
from collections import Counter
def main():
N = int(input())
data = []
common_data = []
max_common_num = 0
for _ in range(N):
data.append( list(map(int, input().split())) )
data.sort()
if N == 1:
return 1
else:
for obj in itertools.combinations(data, 2):
# print(obj)
common_data.append( str(obj[0][0] - obj[1][0]) + "_" + str(obj[0][1] - obj[1][1]) )
counter = Counter(common_data)
for word, cnt in counter.most_common():
if cnt >= max_common_num:
max_common_num = cnt
# print(common_data)
return N - max_common_num
if __name__ == '__main__':
print( main() )
|
s974485078
|
p03828
|
u598167418
| 2,000
| 262,144
|
Wrong Answer
| 22
| 3,064
| 557
|
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
|
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
lis = []
for i in range(2,n):
if prime[i]:
lis.append(i)
return lis
n = int(input())
lis1 = []
l = SieveOfEratosthenes(n)
for i in l:
m = n
z = i
exp = 0
while(m>=z):
exp += m//z
z*=i
lis1.append(exp)
mul = 1
for i in lis1:
mul *= (i+1)
print(mul)
|
s338485010
|
Accepted
| 23
| 3,064
| 568
|
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
lis = []
for i in range(2,n+1):
if prime[i]:
lis.append(i)
return lis
n = int(input())
lis1 = []
l = SieveOfEratosthenes(n)
for i in l:
m = n
z = i
exp = 0
while(m>=z):
exp += m//z
z*=i
lis1.append(exp)
mul = 1
for i in lis1:
mul *= (i+1)
print(mul%(10**9+7))
|
s074586857
|
p02411
|
u476441153
| 1,000
| 131,072
|
Wrong Answer
| 30
| 7,392
| 1,077
|
Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
|
while():
m,f,r = list(map(int, input().split()))
if (m==-1 & f == -1 & r==-1):
break
if (m == -1 | f == -1):
print ("F")
elif (m + f >= 80):
print ("A")
elif (m+f >= 65):
print ("B")
elif (m+f >= 65):
print ("C")
elif (m+f >= 30):
if (r >= 50):
print ("C")
else:
print ("D")
elif (m+f<30):
print ("F")
|
s423662778
|
Accepted
| 30
| 7,684
| 486
|
while True:
m,f,r = list(map(int, input().split()))
if (m == -1) and (f == -1) and (r == -1):
break
elif (m == -1 or f == -1):
print("F")
elif (m+f >= 80):
print("A")
elif (m+f >= 65) and (m+f < 80):
print("B")
elif (m+f >= 50) and (m+f < 65):
print("C")
elif (m+f >= 30) and (m+f < 50):
if (r >= 50):
print("C")
else:
print("D")
elif (m+f < 30):
print("F")
|
s170949824
|
p02397
|
u138546245
| 1,000
| 131,072
|
Wrong Answer
| 50
| 7,668
| 602
|
Write a program which reads two integers x and y, and prints them in ascending order.
|
def sort_two_numbers(a, b):
"""
a: int
b: int
returns a sorted list
>>> sort_two_numbers(1, 3)
[1, 3]
>>> sort_two_numbers(3, 1)
[1, 3]
"""
result = []
if a < b:
result.append(a)
result.append(b)
else:
result.append(b)
result.append(a)
return result
if __name__ == '__main__':
# doctest.testmod()
while True:
try:
(a, b) = input().split(' ')
print('{0[0]} {0[1]}'.format(sort_two_numbers(int(a), int(b))))
except EOFError:
break
|
s645287777
|
Accepted
| 60
| 7,672
| 674
|
def sort_two_numbers(a, b):
"""
a: int
b: int
returns a sorted list
>>> sort_two_numbers(1, 3)
[1, 3]
>>> sort_two_numbers(3, 1)
[1, 3]
"""
result = []
if a < b:
result.append(a)
result.append(b)
else:
result.append(b)
result.append(a)
return result
if __name__ == '__main__':
# doctest.testmod()
while True:
try:
(a, b) = [int(i) for i in input().split(' ')]
if a == 0 and b == 0:
break
print('{0[0]} {0[1]}'.format(sort_two_numbers(int(a), int(b))))
except EOFError:
break
|
s404769717
|
p03080
|
u847451521
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 2,940
| 53
|
There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
|
a = int(input())-1
b = str(input())
c = b[a]
print(c)
|
s274345122
|
Accepted
| 17
| 2,940
| 134
|
a = int(input())
b = str(input())
c = []
for i in b:
c += i
if c.count('R') > c.count('B'):
print("Yes")
else:
print("No")
|
s407165131
|
p03485
|
u221345507
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 59
|
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
|
a,b=map(int,input().split())
import math
math.ceil((a+b)/2)
|
s769140044
|
Accepted
| 18
| 3,060
| 66
|
a,b=map(int,input().split())
import math
print(math.ceil((a+b)/2))
|
s357414434
|
p03997
|
u259334183
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 61
|
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a=int(input())
b=int(input())
h=int(input())
print((a+b)*h/2)
|
s838096269
|
Accepted
| 17
| 2,940
| 62
|
a=int(input())
b=int(input())
h=int(input())
print((a+b)*h//2)
|
s733603718
|
p02271
|
u917432951
| 5,000
| 131,072
|
Wrong Answer
| 30
| 7,640
| 525
|
Write a program which reads a sequence _A_ of _n_ elements and an integer _M_ , and outputs "yes" if you can make _M_ by adding elements in _A_ , otherwise "no". You can use an element only once. You are given the sequence _A_ and _q_ questions where each question contains _M i_.
|
import itertools
given_n = int(input())
given_A = list(map(int,input().split()))
given_q = int(input())
given_m = list(map(int,input().split()))
for mi in given_m:
partial_A = list(filter(lambda ai:ai<mi,given_A))
check = False
for num in range(1,len(partial_A)+1):
combinationPartialA = list(itertools.combinations(partial_A,num))
for tmp_cpa in combinationPartialA:
if sum(tmp_cpa) == mi:
check = True
if check:
print("yes")
else:
print("no")
|
s613807541
|
Accepted
| 300
| 19,792
| 514
|
from functools import lru_cache
@lru_cache(maxsize = None)
def canProd(i,m):
if m == 0:
return True
if i >= n:
return False
res = canProd(i+1,m) or canProd(i+1,m-a[i])
return res
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
m = [int(x) for x in input().split()]
rs = [None]*2001
maxm = max(m)
minm = min(m)
for i in range(minm,maxm+1):
if canProd(0,i):
rs[i] = "yes"
else:
rs[i] = "no"
for i in m:
print(rs[i])
|
s150142741
|
p02742
|
u984710045
| 2,000
| 1,048,576
|
Wrong Answer
| 17
| 3,060
| 157
|
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
|
i = input()
data = i.split(" ")
if (int(data[0])*int(data[1]))%2 == 0:
print(int(data[0])*int(data[1])/2)
else:
print(int(data[0])*int(data[1])//2+1)
|
s114159188
|
Accepted
| 17
| 3,064
| 264
|
i = input()
data = i.split(" ")
if int(data[0])*int(data[1]) == int(data[0]) or int(data[0])*int(data[1]) == int(data[1]):
print(1)
elif (int(data[0])*int(data[1]))%2 == 0:
print(int(data[0])*int(data[1])//2)
else:
print(int(data[0])*int(data[1])//2+1)
|
s624645096
|
p03470
|
u825440127
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 72
|
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
|
n = int(input())
nums = map(int, input().split())
print(len(set(nums)))
|
s054202429
|
Accepted
| 17
| 2,940
| 73
|
nums = [int(input()) for _ in range(int(input()))]
print(len(set(nums)))
|
s121079035
|
p03407
|
u870286225
| 2,000
| 262,144
|
Wrong Answer
| 19
| 3,316
| 92
|
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
|
A, B, C = [int(i) for i in input().split()]
if A + B >= C:
print("yes")
else:
print("No")
|
s079079158
|
Accepted
| 17
| 2,940
| 92
|
A, B, C = [int(i) for i in input().split()]
if A + B >= C:
print("Yes")
else:
print("No")
|
s545449844
|
p03711
|
u785578220
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,064
| 213
|
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
|
a ,b = map(int, input().split())
g2 = [4,6,9,11]
g1 =[1,3,5,7,8,10,12]
if a in g2 and b in g2:
print("Yes")
elif a == 2 and b ==2:
print("Yes")
elif a in g1 and b in g2:
print("Yes")
else:print("No")
|
s461619284
|
Accepted
| 18
| 3,060
| 213
|
a ,b = map(int, input().split())
g2 = [4,6,9,11]
g1 =[1,3,5,7,8,10,12]
if a in g2 and b in g2:
print("Yes")
elif a == 2 and b ==2:
print("Yes")
elif a in g1 and b in g1:
print("Yes")
else:print("No")
|
s656079550
|
p02619
|
u174181999
| 2,000
| 1,048,576
|
Wrong Answer
| 698
| 10,248
| 490
|
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.
|
import copy
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
u = []
x = [0] * 26
u.append(x)
for i in range(D):
v = copy.deepcopy(u)
y = v[-1]
y[t[i]-1] = i+1
u.append(y)
del u[0]
print(D)
print(c)
print(s)
print(t)
print(u)
ans = 0
for i in range(D):
ans += s[i][t[i]-1]
for j in range(26):
ans -= c[j] * ((i+1) - u[i][j])
print(ans)
|
s223479377
|
Accepted
| 680
| 9,916
| 447
|
import copy
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
u = []
x = [0] * 26
u.append(x)
for i in range(D):
v = copy.deepcopy(u)
y = v[-1]
y[t[i]-1] = i+1
u.append(y)
del u[0]
ans = 0
for i in range(D):
ans += s[i][t[i]-1]
for j in range(26):
ans -= c[j] * ((i+1) - u[i][j])
print(ans)
|
s164897344
|
p03352
|
u301624971
| 2,000
| 1,048,576
|
Wrong Answer
| 18
| 3,064
| 1,095
|
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
|
import math
def isPrime(num):
if num < 2: return False
elif num == 2: return True
elif num % 2 == 0: return False
for i in range(3, math.floor(math.sqrt(num))+1, 2):
if num % i == 0:
return False
return True
判定
def callIsPrime(input_num):
numbers = []
for i in range(1, input_num):
if isPrime(i):
numbers.append(i)
return numbers
def myAnswer(X:int) -> int:
prime = callIsPrime(X)
ans = 1
for p in prime:
i = 2
while True:
if(p**i <= X):
ans = max(p**i,ans)
i += 1
else:
break
return ans
def modelAnswer():
tmp=1
def main():
X = int(input())
print(myAnswer(X))
if __name__ == '__main__':
main()
|
s646976457
|
Accepted
| 18
| 3,064
| 372
|
def myAnswer(X:int) -> int:
numbers = [i for i in range(2,X+1)]
ans = 1
for p in numbers:
i = 2
while True:
if(p**i <= X):
ans = max(p**i,ans)
i += 1
else:
break
return ans
def modelAnswer():
tmp=1
def main():
X = int(input())
print(myAnswer(X))
if __name__ == '__main__':
main()
|
s489769373
|
p03473
|
u580093517
| 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?
|
m = int(input())
print(24-m)
|
s034746345
|
Accepted
| 17
| 2,940
| 24
|
print(48 - int(input()))
|
s394517090
|
p03434
|
u040168862
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 266
|
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.
|
def main(N,xs):
# type: (int, List[int]) -> None
xs.sort(reverse=True)
alice = sum(xs[0::2])
bob = sum(xs[0:1:2])
print(alice-bob)
return
if __name__ == '__main__':
N = int(input())
xs = list(map(int,input().split()))
main(N,xs)
|
s619683795
|
Accepted
| 18
| 2,940
| 265
|
def main(N,xs):
# type: (int, List[int]) -> None
xs.sort(reverse=True)
alice = xs[0::2]
bob = xs[1::2]
print(sum(alice)-sum(bob))
return
if __name__ == '__main__':
N = int(input())
xs = list(map(int,input().split()))
main(N,xs)
|
s828776229
|
p03759
|
u478266845
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 100
|
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 = [int(i) for i in input().split()]
if (b-a) == (c-b):
print("Yes")
else:
print("No")
|
s180803136
|
Accepted
| 17
| 2,940
| 100
|
a,b,c = [int(i) for i in input().split()]
if (b-a) == (c-b):
print("YES")
else:
print("NO")
|
s171242072
|
p02613
|
u561883765
| 2,000
| 1,048,576
|
Wrong Answer
| 151
| 9,204
| 356
|
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())
countA = 0
countW = 0
countT = 0
countR = 0
for i in range(n):
a = input()
if a == "AC":
countA += 1
elif a == "WA":
countW += 1
elif a == "TLE":
countT += 1
elif a == "RE":
countR += 1
print("AC × " + str(countA))
print("WA × " + str(countW))
print("TLE × " + str(countT))
print("RE × " + str(countR))
|
s213268973
|
Accepted
| 145
| 9,048
| 352
|
n = int(input())
countA = 0
countW = 0
countT = 0
countR = 0
for i in range(n):
a = input()
if a == "AC":
countA += 1
elif a == "WA":
countW += 1
elif a == "TLE":
countT += 1
elif a == "RE":
countR += 1
print("AC x " + str(countA))
print("WA x " + str(countW))
print("TLE x " + str(countT))
print("RE x " + str(countR))
|
s570671238
|
p02612
|
u349384236
| 2,000
| 1,048,576
|
Wrong Answer
| 29
| 9,152
| 68
|
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n=int(input())
if n%1000==0 :
print("0")
else :
print(n-n%1000)
|
s603427171
|
Accepted
| 29
| 9,112
| 40
|
n=int(input())
print((1000-n%1000)%1000)
|
s970669849
|
p03049
|
u495903598
| 2,000
| 1,048,576
|
Wrong Answer
| 22
| 3,700
| 333
|
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
|
# coding: utf-8
# In[7]:
import sys
input = sys.stdin.readline
N = int(input())
S = [input() for i in range(N)]
# In[9]:
b_cnt = 0
a_cnt = 0
for i in range(N):
if S[i][0]=='B':
b_cnt += 1
if S[i][-1]=='A':
a_cnt += 1
#print(b_cnt, a_cnt)
print('/'.join(S).count('AB') + min(a_cnt, b_cnt))
# In[ ]:
|
s924931732
|
Accepted
| 35
| 3,828
| 995
|
# coding: utf-8
# In[17]:
import sys
#input = sys.stdin.readline
N = int(input())
S = [input() for i in range(N)]
# In[18]:
b_cnt = 0
a_cnt = 0
ab_cnt = 0
for i in range(N):
if S[i][0]=='B'and S[i][-1]=='A':
ab_cnt += 1
elif S[i][0]=='B':
b_cnt += 1
elif S[i][-1]=='A':
a_cnt += 1
#print(b_cnt, a_cnt)
#print(ab_cnt, a_cnt, b_cnt, '/'.join(S).count('AB') )
#if abs(a_cnt-b_cnt) >= 1 and ab_cnt > 0:
ans = 0
if ab_cnt > 0:
ans += ab_cnt - 1
if b_cnt > 0:
b_cnt -= 1
ans += 1
if a_cnt > 0:
a_cnt -= 1
ans += 1
ans += min(a_cnt, b_cnt)
"""
if max(a_cnt, b_cnt) == 0 and ab_cnt > 0:
ab_cnt -= 1
elif min(a_cnt, b_cnt) > 0 and ab_cnt > 0:
ab_cnt += 1
elif abs(a_cnt-b_cnt) == 0 and ab_cnt > 0:
ab_cnt += 1
elif abs(a_cnt-b_cnt) > 0 and ab_cnt > 0:
ab_cnt += 0
"""
#if ab_cnt < 0:
# ab_cnt = 0
#ab_cnt = ab_cnt-1 if ab_cnt!=0 else ab_cnt
print('/'.join(S).count('AB') + ans)
# In[ ]:
|
s459147547
|
p03359
|
u139013163
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 219
|
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called _Takahashi_ when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi?
|
x, y = map(int, input().split())
cnt = 0
for i in range(1, 13):
if i > x:
break
for j in range(1, 13):
if i == x and j == y:
break
if i == j:
cnt += 1
print(cnt)
|
s645663406
|
Accepted
| 17
| 2,940
| 219
|
x, y = map(int, input().split())
cnt = 0
for i in range(1, 13):
if i > x:
break
for j in range(1, 13):
if i == j:
cnt += 1
if i == x and j == y:
break
print(cnt)
|
s593755608
|
p02749
|
u711539583
| 2,000
| 1,048,576
|
Wrong Answer
| 2,107
| 58,984
| 465
|
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i. Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition: * For every pair of vertices (i, j), if the distance between Vertex i and Vertex j is 3, the sum or product of p_i and p_j is a multiple of 3. Here the distance between Vertex i and Vertex j is the number of edges contained in the shortest path from Vertex i to Vertex j. Help Takahashi by finding a permutation that satisfies the condition.
|
from collections import deque
n = int(input())
E = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
E[a-1].append(b-1)
E[b-1].append(a-1)
def bfs(cur, pre, c):
stack = deque([[cur, pre, c]])
while stack:
cur, pre, c = stack.popleft()
if c <= 3:
for e in E[cur]:
if e != pre:
stack.append([e, cur, c+1])
for i in range(n):
bfs(i, -1, 0)
print(-1)
|
s497300384
|
Accepted
| 1,077
| 63,464
| 1,644
|
import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
E = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
E[a-1].append(b-1)
E[b-1].append(a-1)
mod = [3, 1, 2]
ans = [0 for i in range(n)]
count = [0, 0]
def bfs(cur, pre, c):
stack = deque([[cur, pre, c]])
while stack:
cur, pre, c = stack.popleft()
count[c % 2] += 1
for e in E[cur]:
if e != pre:
stack.append([e, cur, c+1])
def case1(cur, pre, c, i):
stack = deque([[cur, pre, c]])
while stack:
cur, pre, c = stack.popleft()
t = c % 2
if t == i:
ans[cur] = mod[0]
mod[0] += 3
else:
if mod[1] <= n:
ans[cur] = mod[1]
mod[1] += 3
elif mod[2] <= n:
ans[cur] = mod[2]
mod[2] += 3
else:
ans[cur] = mod[0]
mod[0] += 3
for e in E[cur]:
if e != pre:
stack.append([e, cur, c+1])
def case2(cur, pre, c):
stack = deque([[cur, pre, c]])
while stack:
cur, pre, c = stack.popleft()
t = c % 2
if mod[t+1] <= n:
ans[cur] = mod[t+1]
mod[t+1] += 3
else:
ans[cur] = mod[0]
mod[0] += 3
for e in E[cur]:
if e != pre:
stack.append([e, cur, c+1])
bfs(0, -1, 0)
if count[0] <= n // 3:
case1(0, -1, 0, 0)
elif count[1] <= n // 3:
case1(0, -1, 0, 1)
else:
case2(0, -1, 0)
print(" ".join([str(i) for i in ans]))
|
s522266658
|
p02972
|
u363992934
| 2,000
| 1,048,576
|
Wrong Answer
| 2,104
| 32,452
| 502
|
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied: * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2. Does there exist a good set of choices? If the answer is yes, find one good set of choices.
|
import math
N = int(input())
a_list = [0] + list(map(int, input().split()))
result = True
answer_box = [0] * (N+1)
inboxes = []
for i in range(N, 0, -1):
last_i = i * (N // i)
count = 0
for j in range(last_i, i-1, -i):
print(N, i, j)
count += answer_box[j]
if (count % 2) != a_list[i]:
answer_box[i] = 1
inboxes.append(i)
if(result):
print(len(inboxes))
if(len(inboxes) > 0):
print(" ".join(str(e) for e in inboxes))
else:
print(-1)
|
s150845218
|
Accepted
| 589
| 20,336
| 479
|
import math
N = int(input())
a_list = [0] + list(map(int, input().split()))
result = True
answer_box = [0] * (N+1)
inboxes = []
for i in range(N, 0, -1):
last_i = i * (N // i)
count = 0
for j in range(last_i, i-1, -i):
count += answer_box[j]
if (count % 2) != a_list[i]:
answer_box[i] = 1
inboxes.append(i)
if(result):
print(len(inboxes))
if(len(inboxes) > 0):
print(" ".join(str(e) for e in inboxes))
else:
print(-1)
|
s772322273
|
p03162
|
u584477760
| 2,000
| 1,048,576
|
Wrong Answer
| 500
| 31,348
| 589
|
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
|
def calc_happiness(h):
n = len(h)
if (n == 0):
return 0
states = [[None, None, None]] * len(h)
states[0] = h[0]
for i in range(1, n):
states[i][0] = h[i][0] + max(h[i-1][1], h[i-1][2])
states[i][1] = h[i][1] + max(h[i-1][0], h[i-1][2])
states[i][2] = h[i][2] + max(h[i-1][0], h[i-1][1])
return max(states[n-1][0], states[n-1][1], states[n-1][2])
if __name__ == "__main__":
n = int(input())
h = [[]] * n
for day in range(n):
h[day] = list(map(int, input().split(" ")))
res = calc_happiness(h)
print(res)
|
s511461807
|
Accepted
| 549
| 47,288
| 593
|
def calc_happiness(h):
n = len(h)
states = [[None, None, None] for i in range(n)]
states[0] = h[0]
for i in range(1, n):
states[i][0] = h[i][0] + max(states[i-1][1], states[i-1][2])
states[i][1] = h[i][1] + max(states[i-1][0], states[i-1][2])
states[i][2] = h[i][2] + max(states[i-1][0], states[i-1][1])
return max(states[n-1][0], states[n-1][1], states[n-1][2])
if __name__ == "__main__":
n = int(input())
h = [[]] * n
for day in range(n):
h[day] = list(map(int, input().split(" ")))
res = calc_happiness(h)
print(res)
|
s023506641
|
p03494
|
u006576567
| 2,000
| 262,144
|
Wrong Answer
| 18
| 3,060
| 378
|
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 calc(l):
r = 0
finish = False
while True:
for i in range(0, len(l)):
if l[i] % 2 == 0:
l[i] = l[i]//2
else:
finish = True
break
if finish:
break
print(l)
r += 1
return r
_ = input()
l = list(map(int, input().split()))
r = calc(l)
print(r)
|
s132600918
|
Accepted
| 18
| 3,060
| 361
|
def calc(l):
r = 0
finish = False
while True:
for i in range(0, len(l)):
if l[i] % 2 == 0:
l[i] = l[i]//2
else:
finish = True
break
if finish:
break
r += 1
return r
_ = input()
l = list(map(int, input().split()))
r = calc(l)
print(r)
|
s886132216
|
p03995
|
u436484848
| 2,000
| 262,144
|
Wrong Answer
| 2,107
| 106,316
| 1,387
|
There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c). Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that he fell asleep. Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing integers into all remaining cells. The grid must meet the following conditions to really surprise Mr. Takahashi. * Condition 1: Each cell contains a non-negative integer. * Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers. Determine whether it is possible to meet those conditions by properly writing integers into all remaining cells.
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# D-Grid and Integers
from collections import defaultdict
def ReadInput():
return [int(i) for i in input().split(" ")]
(R, C) = ReadInput()
N = int(input())
RowIdx = set()
ColIdx = set()
Grid = defaultdict(list)
RowGrid = defaultdict(list)
ColGrid = defaultdict(list)
for i in range(N):
(r, c, a) = ReadInput()
RowGrid[r].append(c)
ColGrid[c].append(r)
Grid[(r, c)] = a
RowIdx.add(r)
ColIdx.add(c)
print(RowIdx)
print(RowGrid)
print(ColGrid)
print(Grid)
fresh = 1
while(fresh == 1):
fresh = 0
for row in RowIdx:
if (len(RowGrid[row]) == 1):
continue
TempRow = RowGrid[row]
TempColGrid = ColGrid
for pointer in TempRow:
TempCol = TempRow
TempCol.remove(pointer)
for pair in TempCol:
dif = Grid[(row, pointer)] - Grid[(row, pair)]
ObjCol = TempColGrid[pointer]
print('pair is', pair)
print('row equal', row)
print('ObjCol equal', ObjCol)
print('TempColGrid[pointer] is', TempColGrid[pointer])
if row in ObjCol:
ObjCol.remove(row)
for obj in ObjCol:
val = Grid[(obj, pointer)]- dif
if (val < 0):
print("No")
exit()
if ((obj, pair) in Grid):
if (val != Grid[(obj, pair)]):
print("No");
exit()
else:
Grid[(obj, pair)] = val
RowGrid[obj].append(pair)
ColGrid[pair].append(obj)
fresh = 1
print("Yes")
|
s152937690
|
Accepted
| 1,798
| 166,996
| 946
|
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
def ReadInput():
return [int(i) for i in input().split(" ")]
(R, C) = ReadInput()
N = int(input())
VectorSet = set()
Grid = defaultdict(list)
for i in range(N):
(r, c, a) = ReadInput()
Grid[("R", r)].append((("C", c), a))
Grid[("C", c)].append((("R", r), a))
VectorSet.add(("R", r))
VectorSet.add(("C", c))
def iteration(vector):
VectorSet.discard(vector)
for (v, a) in Grid[vector]:
temp = a - VectorCover[vector]
if (v in VectorCover):
if(temp != VectorCover[v]):
print("No")
exit()
else:
VectorCover[v] = temp
iteration(v)
while(len(VectorSet) != 0):
vector = VectorSet.pop()
VectorCover = dict()
VectorCover[vector] = 0
iteration(vector)
minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
if (minR + minC < 0):
print("No")
exit()
print("Yes")
|
s166931030
|
p03605
|
u788856752
| 2,000
| 262,144
|
Wrong Answer
| 17
| 2,940
| 99
|
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
l = list(input())
for i in l:
if i == "9":
print("Yes")
else:
print("No")
|
s980525299
|
Accepted
| 17
| 2,940
| 104
|
l = list(input())
for i in l:
if i == "9":
print("Yes")
break
else:
print("No")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.