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
s830081522
p02240
u963402991
1,000
131,072
Wrong Answer
40
8,584
803
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
from queue import deque n, m = map(int, input().split()) color = [-1 for i in range(n)] G = deque([[0] * n for i in range(n)]) for i in range(m): s, t = map(int, input().split()) G[s][t] = 1 G[t][s] = 1 def dfs(r, c): S = deque([r]) color[r] = c while (len(S)): u = S.popleft() for i in [j for j in range(0, m) if G[u][j] == 1]: if color[i] == -1: color[i] = c S.append(i) def assginColor(): i_d = 1 for u in range(n): if color[u] == -1: dfs(u, i_d) i_d += 1 assginColor() q = int(input()) for i in range(q): s,t = map(int, input().split()) if color[s] == color[t]: print("yes") else: print("no")
s716413462
Accepted
970
30,280
977
from queue import deque n, m = map(int, input().split()) G = deque([[] for i in range(n)]) for i in range(m): s, t = map(int, input().split()) G[s].append(t) G[t].append(s) def dfs(r, c): S = deque() S.append(r) color[r] = c while (len(S) > 0): u = S.popleft() for j in G[u]: if color[j] == -1: color[j] = c S.append(j) def assginColor(): i_d = 1 for u in range(n): if color[u] == -1: dfs(u, i_d) i_d += 1 color = [-1] * n assginColor() q = int(input()) s_t = [list(map(int, input().split())) for i in range(q)] for s, t in s_t: if color[s] == color[t]: print("yes") else: print("no")
s415889953
p03089
u379234461
2,000
1,048,576
Wrong Answer
17
3,060
447
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
# AGC032 Problem-AGC032 n = int(input()) a = list (map(int, input().split())) #print (a) a.insert(0,-1) result = [] for i in range (n, 0, -1) : for j in range (i, -1, -1) : # print (a) if a[j] == j : result.append(j) # print (result) a = a[:j+1] + a[j+2:] break if j == 0 : result = [-1] break result.reverse() for ans in result : print (ans)
s297953200
Accepted
19
3,060
445
# AGC032 Problem-AGC032 n = int(input()) a = list (map(int, input().split())) #print (a) a.insert(0,-1) result = [] for i in range (n, 0, -1) : for j in range (i, -1, -1) : # print (a) if a[j] == j : result.append(j) # print (result) a = a[:j] + a[j+1:] break if j == 0 : result = [-1] break result.reverse() for ans in result : print (ans)
s698704451
p03549
u595952233
2,000
262,144
Wrong Answer
1,428
9,096
313
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
from math import ceil n, m = map(int, input().split()) base = (n-m)*100+1900*m allok = 2**m def prob(k): assert k > 0 return (allok-1)**(k-1) i = 1 temp = 0 for i in range(1, 10000): temp += i*base*prob(i)/pow(allok, i) print(ceil(temp))
s466001250
Accepted
28
8,896
231
from math import ceil n, m = map(int, input().split()) base = (n-m)*100+1900*m allok = pow(2,m) print(base*allok)
s272190115
p03720
u935254309
2,000
262,144
Wrong Answer
17
3,064
279
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
N,M = map(int,input().split()) glaf = [[] for i in range(N)] for i in range(M): a,b = map(int,input().split()) a=a-1 b=b-1 glaf[a].append(b) glaf[b].append(a) print(glaf) for i in glaf: cnt =0 for j in i: cnt+=1 print(cnt)
s579839397
Accepted
18
3,064
262
N,M = map(int,input().split()) glaf = [[] for i in range(N)] for i in range(M): a,b = map(int,input().split()) a=a-1 b=b-1 glaf[a].append(b) glaf[b].append(a) for i in glaf: cnt =0 for j in i: cnt+=1 print(cnt)
s861230811
p02558
u751843916
5,000
1,048,576
Wrong Answer
1,328
102,336
512
You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types. * `0 u v`: Add an edge (u, v). * `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.
from networkx.utils.union_find import UnionFind n,q=map(int,input().split()) a=[[int(i) for i in input().split()] for _ in range(q)] uf=UnionFind() for i in range(n): uf.union(i,i) for x in a: if x[0]==0: uf.union(x[1],x[2]) else: f=x[1] while True: if f==uf.parents[f]:break f=uf.parents[f] b=x[2] while True: if b==uf.parents[b]:break b=uf.parents[b] print(0 if f==b else 1)
s359935219
Accepted
1,328
102,228
512
from networkx.utils.union_find import UnionFind n,q=map(int,input().split()) a=[[int(i) for i in input().split()] for _ in range(q)] uf=UnionFind() for i in range(n): uf.union(i,i) for x in a: if x[0]==0: uf.union(x[1],x[2]) else: f=x[1] while True: if f==uf.parents[f]:break f=uf.parents[f] b=x[2] while True: if b==uf.parents[b]:break b=uf.parents[b] print(1 if f==b else 0)
s268307905
p03644
u062306892
2,000
262,144
Wrong Answer
17
2,940
82
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, 2, 4, 8, 16, 32, 64] max([i for i in ans if n-i >= 0])
s106941271
Accepted
17
2,940
89
n = int(input()) ans = [1, 2, 4, 8, 16, 32, 64] print(max([i for i in ans if n-i >= 0]))
s856947351
p03251
u604398799
2,000
1,048,576
Wrong Answer
23
3,064
409
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
N, M, X, Y = map(int, input().split()) x = map(int, input().split()) y = map(int, input().split()) x_max = max(x) y_min = min(y) flag_war = True for z in range(X+1, Y): if x_max < z: if y_min >= z: print('No War') print(z) flag_war = False else: continue else: continue if flag_war == True: print('War')
s069402121
Accepted
17
3,064
408
N, M, X, Y = map(int, input().split()) x = map(int, input().split()) y = map(int, input().split()) x_max = max(x) y_min = min(y) flag_war = True for z in range(X+1, Y+1): if x_max < z: if y_min >= z: print('No War') flag_war = False break else: continue else: continue if flag_war == True: print('War')
s080329688
p02264
u650459696
1,000
131,072
Wrong Answer
30
5,996
400
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
from collections import OrderedDict n, q = map(int, input().split()) od = OrderedDict() for i in range(n): name, time = input().split() od.update({name: int(time)}) total = 0 while len(od) > 0: name, time = od.popitem(False) if time < q: total += time print("{} {}".format(name, total)) else: total += q time -= q od.update({name: time})
s033509592
Accepted
480
14,932
401
from collections import OrderedDict n, q = map(int, input().split()) od = OrderedDict() for i in range(n): name, time = input().split() od.update({name: int(time)}) total = 0 while len(od) > 0: name, time = od.popitem(False) if time <= q: total += time print("{} {}".format(name, total)) else: total += q time -= q od.update({name: time})
s181000092
p02237
u193453446
1,000
131,072
Wrong Answer
30
7,704
371
There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$. An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise. Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively.
def main(): num = int(input()) T = [[0] * num for i in range(num)] for n in range(num): a = list(map(int,input().split())) u = a[0] - 1 if a[1] > 0: for i in a[2:]: print(i) T[u][i-1] = 1 for i in range(num): print(" ".join(map(str,T[i]))) if __name__ == '__main__': main()
s677680318
Accepted
20
7,792
346
def main(): num = int(input()) T = [[0] * num for i in range(num)] for n in range(num): a = list(map(int,input().split())) u = a[0] - 1 if a[1] > 0: for i in a[2:]: T[u][i-1] = 1 for i in range(num): print(" ".join(map(str,T[i]))) if __name__ == '__main__': main()
s533708605
p03693
u393881437
2,000
262,144
Wrong Answer
18
2,940
84
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
r, g, b = map(int, input().split()) print('Yes' if r*100+g*10+b % 4 == 0 else 'No')
s221241783
Accepted
17
2,940
89
r, g, b = map(int, input().split()) print('YES' if (100*r + 10*g + b) % 4 == 0 else 'NO')
s946169656
p03150
u977193988
2,000
1,048,576
Wrong Answer
18
3,064
249
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.
import sys s=input() l=len(s)-7 if s=='keyence': print('YES') sys.exit() if l<=0: print('NO') sys.exit() for i in range(l): print(s[:i]+s[i+l:]) if s[:i]+s[i+l:]=='keyence': print('YES') sys.exit() print('NO')
s074168964
Accepted
18
3,060
248
import sys s=input() l=len(s)-7 if l<0: print('NO') sys.exit() for i in range(7): # print(s[:i]+s[i+l:]) if s[:i]+s[i+l:]=='keyence': print('YES') sys.exit() if s[:7]=='keyence': print('YES') else: print('NO')
s720505235
p03693
u291373585
2,000
262,144
Wrong Answer
17
2,940
108
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
a,b,c= list(map(int,input().split())) N = 100*a + 10*b + c if N % 4 == 0: print('Yes') else: print('No')
s231370806
Accepted
17
2,940
108
a,b,c= list(map(int,input().split())) N = 100*a + 10*b + c if N % 4 == 0: print('YES') else: print('NO')
s640060337
p03386
u777607830
2,000
262,144
Wrong Answer
18
3,060
154
Print all the integers that satisfies the following in ascending order: * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
A,B,K = map(int,input().split()) for i in range(K): if A+i <= B: print(A+i) for i in range(K): if B-K+i >= A + K: print(B-K+i)
s211708837
Accepted
17
3,060
158
A,B,K = map(int,input().split()) for i in range(K): if A+i <= B: print(A+i) for i in range(K): if B-K+i+1 >= A + K: print(B-K+i+1)
s700028747
p03162
u952081880
2,000
1,048,576
Wrong Answer
1,104
31,672
296
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.
# C - Vacation import numpy as np N = int(input()) value = np.zeros((N, 3)) for i in range(N): value[i, :] = list(map(int, input().split())) value = value.tolist() dp = [0]*3 for a, b, c in value: dp = [max(dp[1], dp[2])+a, max(dp[0], dp[2])+b, max(dp[0], dp[1])+c] print(max(dp))
s662803770
Accepted
1,090
33,464
301
# C - Vacation import numpy as np N = int(input()) value = np.zeros((N, 3)) for i in range(N): value[i, :] = list(map(int, input().split())) value = value.tolist() dp = [0]*3 for a, b, c in value: dp = [max(dp[1], dp[2])+a, max(dp[0], dp[2])+b, max(dp[0], dp[1])+c] print(int(max(dp)))
s026324058
p03370
u026155812
2,000
262,144
Wrong Answer
17
2,940
140
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: * For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.
N, X = map(int, input().split()) m = [] cur = 0 for i in range(N): cur += int(input()) m.append(cur) print(len(m) + (X-cur)//min(m))
s304499019
Accepted
19
2,940
148
N, X = map(int, input().split()) m = [] cur = 0 for i in range(N): a = int(input()) cur += a m.append(a) print(len(m) + (X-cur)//min(m))
s830622416
p03636
u549002697
2,000
262,144
Wrong Answer
17
2,940
121
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
string = input() cnt = 0 le = len(string) for i in range(1,le-1): cnt =cnt +1 print(string[0],cnt,string[le-1])
s035134869
Accepted
17
3,060
123
string = input() cnt = 0 le = len(string) for i in range(1,le-1): cnt =cnt +1 print(string[0],cnt,string[le-1],sep ='')
s473875840
p03588
u780709476
2,000
262,144
Wrong Answer
691
13,472
449
A group of people played a game. All players had distinct scores, which are positive integers. Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i. Find the maximum possible number of players in the game.
n = int(input()) A = [] B = [] for i in range(n): a, b = map(int, input().split()) A.append(a) B.append(b) A = sorted(A) B = sorted(B, reverse = True) ans = 0 ans += A[0] print(ans) for i in range(1, n): print(A[i] - A[i - 1], B[i - 1] - B[i]) if(A[i] - A[i - 1] > B[i - 1] - B[i]): ans += B[i - 1] - B[i] print("B", ans) else: ans += A[i] - A[i - 1] print("A", ans) ans += B[-1] print(ans)
s757805139
Accepted
445
12,484
346
n = int(input()) A = [] B = [] for i in range(n): a, b = map(int, input().split()) A.append(a) B.append(b) A = sorted(A) B = sorted(B, reverse = True) ans = 0 ans += A[0] for i in range(1, n): if(A[i] - A[i - 1] > B[i - 1] - B[i]): ans += B[i - 1] - B[i] else: ans += A[i] - A[i - 1] ans += B[-1] print(ans)
s254629848
p03729
u027675217
2,000
262,144
Wrong Answer
17
2,940
89
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a,b,c = input().split() if a[-1]==b[0] and b[-1]==c[0]: print("Yes") else: print("No")
s292756920
Accepted
17
2,940
89
a,b,c = input().split() if a[-1]==b[0] and b[-1]==c[0]: print("YES") else: print("NO")
s429660964
p03361
u306241759
2,000
262,144
Wrong Answer
34
9,208
506
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= `#`, and to make Square (i, j) white when s_{i, j}= `.`. However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.
h, w = map(int,input().split()) grid = [] for _ in range(h): grid.append(list(input())) dx=[-1,0,0,1] dy=[0,-1,1,0] for i in range(h): for j in range(w): flag=False if grid[i][j]==".": continue for x,y in zip(dx,dy): if i+x<0 or i+x>h-1 or j+y<0 or j+y>w-1: continue if grid[i+x][j+y]=="#": flag=True break if not flag: print("NO") exit() print("YES")
s797700902
Accepted
27
9,140
507
h, w = map(int,input().split()) grid = [] for _ in range(h): grid.append(list(input())) dx=[-1,0,0,1] dy=[0,-1,1,0] for i in range(h): for j in range(w): flag=False if grid[i][j]==".": continue for x,y in zip(dx,dy): if i+x<0 or i+x>h-1 or j+y<0 or j+y>w-1: continue if grid[i+x][j+y]=="#": flag=True break if not flag: print("No") exit() print("Yes")
s610360943
p03457
u142023109
2,000
262,144
Wrong Answer
400
11,816
529
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()) t = [0 for i in range(N)] x = [0 for i in range(N)] y = [0 for i in range(N)] for i in range(N): t[i], x[i], y[i] = map(int, input().split()) a = "YES" for i in range(N): if i == 0: dt = t[0] dist = abs(x[0]) + abs(y[0]) else: dt = t[i]-t[i-1] dist = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]) if dist > dt or (dist+dt) % 2 == 1: a = "NO" print(a)
s185361630
Accepted
391
11,824
527
N = int(input()) t = [0 for i in range(N)] x = [0 for i in range(N)] y = [0 for i in range(N)] for i in range(N): t[i], x[i], y[i] = map(int, input().split()) a = "Yes" for i in range(N): if i == 0: dt = t[0] dist = abs(x[0]) + abs(y[0]) else: dt = t[i]-t[i-1] dist = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]) if dist > dt or (dist+dt) % 2 == 1: a = "No" print(a)
s519406111
p03556
u702582248
2,000
262,144
Wrong Answer
17
2,940
51
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
import math n=int(input()) print(int(math.sqrt(n)))
s100365395
Accepted
34
4,372
74
n=int(input()) print(list(filter(lambda x:x*x<=n,range(int(1e5))))[-1]**2)
s929141294
p02865
u029935728
2,000
1,048,576
Wrong Answer
256
3,060
138
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
import math N1 = input() N = int(N1) i = 0 j = 1 r = 0 for j in range (N): i=N-j if i!=j : r+=1 math.floor (r/2)
s904099019
Accepted
260
3,060
157
import math N1 = input() N = int(N1) i = 0 j = 1 r = 0 a = 0 for j in range (N): i=N-j if i!=j : r+=1 a = math.floor (r/2) print(a)
s778774457
p03377
u765590009
2,000
262,144
Wrong Answer
17
2,940
105
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int, input().split()) if (x >= a) and (a+b >= x) : print("Yes") else : print("No")
s766956212
Accepted
17
2,940
105
a, b, x = map(int, input().split()) if (x >= a) and (a+b >= x) : print("YES") else : print("NO")
s220825082
p03494
u813993459
2,000
262,144
Wrong Answer
17
2,940
215
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.
s=map(int,input().split()) ans = [] for i in s: tmp=i count=0 while(1): if tmp%2==0: tmp=tmp/2 count=count+1 else: break ans.append(count) min(ans)
s632055737
Accepted
19
3,060
249
s=map(int,input().split()) s=map(int,input().split()) ans = [] for i in s: tmp=i count=0 while(1): if tmp%2==0: tmp=tmp/2 count=count+1 else: break ans.append(count) print(min(ans))
s624934523
p02646
u619672182
2,000
1,048,576
Wrong Answer
22
9,208
202
Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate B, and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally.
AV = input().split() BW = input().split() T = input().split() A = int(AV[0]) V = int(AV[1]) B = int(BW[0]) W = int(BW[1]) T = int(T[0]) if abs(A-B) < (V - W) * T: print("Yes") else: print("No")
s055121778
Accepted
23
9,188
203
AV = input().split() BW = input().split() T = input().split() A = int(AV[0]) V = int(AV[1]) B = int(BW[0]) W = int(BW[1]) T = int(T[0]) if abs(A-B) <= (V - W) * T: print("YES") else: print("NO")
s170554728
p03251
u722189950
2,000
1,048,576
Wrong Answer
18
3,060
368
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
#ABC110 B N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) isWar = True if not X < Y: isWar = False else: for Z in range(X+1,Y+1): if max(x) < Z and min(y) >= Z: isWar = True if isWar: print("War") else: print("NO War")
s784534990
Accepted
18
3,064
350
#ABC110 B N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) isnotWar = False if X < Y: for Z in range(X+1,Y+1): if max(x) < Z and min(y) >= Z: isnotWar = True if isnotWar: print("No War") else: print("War")
s385809240
p02612
u455381597
2,000
1,048,576
Wrong Answer
31
9,148
95
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
def main(): N = int(input()) print(int(N%1000)) if __name__ == "__main__": main()
s166796588
Accepted
29
9,176
145
def main(): N = int(input()) if N%1000==0: print(0) else : print(1000-N%1000) if __name__ == "__main__": main()
s255484041
p02612
u504348975
2,000
1,048,576
Wrong Answer
2,206
9,140
67
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
num = int(input()) while num < 1000: num = num % 1000 print(num)
s376449132
Accepted
30
9,088
85
num = int(input()) num = num % 1000 if num == 0: print(num) else: print(1000-num)
s443908255
p03999
u543954314
2,000
262,144
Wrong Answer
17
3,060
189
You are given a string S consisting of digits between `1` and `9`, inclusive. You can insert the letter `+` into some of the positions (possibly none) between two letters in this string. Here, `+` must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate all possible formulas, and print the sum of the results.
s = input() le = len(s) ans = 0 for i in range(le): amini = 10**(le-i-1) for j in range(le-i-1): amini += 10**j * 2**(le-i-j-1) amini *= int(s[i]) * 2**i ans += amini print(ans)
s263620679
Accepted
17
2,940
145
s = list(map(int,list(input()))) n = len(s) m = 0 for i in range(n): for j in range(n-i): m += s[i]*2**i*10**j*2**(max(n-i-j-2,0)) print(m)
s002553312
p04000
u884982181
3,000
262,144
Wrong Answer
2,314
198,116
483
We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column. Compute the following: * For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?
from collections import defaultdict h,w,n = map(int,input().split()) x = [] for i in range(n): x.append(list(map(int,input().split()))) d = defaultdict(int) for i in x: a = [] for j in range(3): for k in range(3): if (i[0]-j-1>=0 and i[1]-k-1 >= 0 and i[0]-j-1<=h-3 and i[1]-k-1 <= w-3): a.append((i[0]-j-1,i[1]-k-1)) for j in a: d[j] += 1 a = list(d.values()) ans = [0]*9 ans[0] = (h-2)*(w-2)-len(a) for i in a: ans[i-1] += 1 for i in ans: print(i)
s086522703
Accepted
2,206
198,116
482
from collections import defaultdict h,w,n = map(int,input().split()) x = [] for i in range(n): x.append(list(map(int,input().split()))) d = defaultdict(int) for i in x: a = [] for j in range(3): for k in range(3): if (i[0]-j-1>=0 and i[1]-k-1 >= 0 and i[0]-j-1<=h-3 and i[1]-k-1 <= w-3): a.append((i[0]-j-1,i[1]-k-1)) for j in a: d[j] += 1 a = list(d.values()) ans = [0]*10 ans[0] = (h-2)*(w-2)-len(a) for i in a: ans[i] += 1 for i in ans: print(i)
s137481553
p03636
u735069283
2,000
262,144
Wrong Answer
17
2,940
49
The word `internationalization` is sometimes abbreviated to `i18n`. This comes from the fact that there are 18 letters between the first `i` and the last `n`. You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
s = str(input()) print(s[0]+str(len(s)) + s[-1])
s514863995
Accepted
17
2,940
42
n=input() print(n[0]+str(len(n)-2)+n[-1])
s044107960
p03815
u758815106
2,000
262,144
Wrong Answer
29
9,088
47
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()) s = x // 11 * 2 + 1 print(s)
s044915645
Accepted
27
9,136
127
x = int(input()) s = x // 11 t = x % 11 if t > 6: print(s * 2 + 2) elif t > 0: print(s * 2 + 1) else: print(s * 2)
s746860400
p03693
u726439578
2,000
262,144
Wrong Answer
17
2,940
93
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
a,b,c=map(int,input().split()) n=int(a+b+c) if n%4==0: print("YES") else: print("NO")
s918732962
Accepted
17
2,940
98
a,b,c=map(str,input().split()) n=int(a+b+c) if n%4==0: print("YES") else: print("NO")
s148599051
p03860
u114687417
2,000
262,144
Wrong Answer
24
3,068
41
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
word = input() print("A"+word[1][0]+"C")
s480561268
Accepted
23
3,064
70
word = input() .split() print( word[0][0] + word[1][0] + word[2][0] )
s144253651
p03861
u513793759
2,000
262,144
Wrong Answer
2,132
447,084
126
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x?
a,b,x = map(int, input().split()) T = [] for i in range(a,b+1): if i%x==0: T.append(i) else: quit print(T) print(len(T))
s234228852
Accepted
18
2,940
70
import math a,b,x = map(int, input().split()) print(b//x-(a+x-1)//x+1)
s452363112
p02608
u394731058
2,000
1,048,576
Wrong Answer
2,205
9,280
520
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import sys input = sys.stdin.readline def calc(n): for i in range(1,int(n**0.5)): for j in range(1,int(n**0.5)): for k in range(1, int(n**0.5)): if (i+j+k)**2 - i*j - j*k - k*i == n: if i == j == k: return 1 else: return 3 return 0 def main(): ans = 0 n = int(input()) for i in range(1,n+1): print(calc(i)) print(ans) if __name__ == '__main__': main()
s329259086
Accepted
379
9,192
382
import sys input = sys.stdin.readline def main(): ans = [0]* 10010 n = int(input()) for x in range(1,101): for y in range(1,101): for z in range(1,101): v = (x+y+z)**2 - x*y - y*z - z*x if v <= n: ans[v] += 1 for i in range(1,n+1): print(ans[i]) if __name__ == '__main__': main()
s220837524
p02257
u424457654
1,000
131,072
Wrong Answer
30
7,688
160
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
n = int(input()) count = 0 for i in range(2, n): x = int(input()) if x == 2: count += 1 elif x % i == 0: break else: count += 1 print(count)
s934076803
Accepted
50
7,700
193
n = int(input()) count = 0 for i in range(n): x = int(input()) if x == 2: count += 1 elif x % 2 == 0: continue else: if pow(2, x - 1, x) == 1: count += 1 print(count)
s336933859
p02266
u742013327
1,000
131,072
Wrong Answer
30
7,576
1,329
Your task is to simulate a flood damage. For a given cross-section diagram, reports areas of flooded sections. Assume that rain is falling endlessly in the region and the water overflowing from the region is falling in the sea at the both sides. For example, for the above cross-section diagram, the rain will create floods which have areas of 4, 2, 1, 19 and 9 respectively.
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D import re def cal_puddle(puddle_list): depth = 0 score = 0 for symbol in puddle_list: if symbol == "\\": score += depth + 0.5 depth += 1 if symbol == "/": depth -= 1 score += depth + 0.5 if symbol == "_": score += depth return int(score) def get_puddle_index(diagram_list): depth = 0 for i, symbol in enumerate(diagram_list): if symbol == "\\": depth += 1 elif symbol == "/": depth = depth - 1 if depth == 0: return i return False def cal(diagram): puddle_areas = [] diagram_list = [] puddle_list = [] i = 0 while i < len(diagram): if diagram[i] == "\\": puddle_end = get_puddle_index(diagram[i:]) if puddle_end: puddle_list.append(diagram[i: i + puddle_end + 1]) i = i + puddle_end i += 1 for puddle in puddle_list: puddle_areas.append(cal_puddle(puddle)) return puddle_areas if __name__ == "__main__": a = input() result = cal(a) print(sum(result)) print(" ".join([str(a) for a in result]))
s361584012
Accepted
3,000
8,284
1,582
def cal_puddle(puddle): depth = 0 score = 0 for s in puddle: if s == "\\": score += depth + 0.5 depth += 1 elif s == "/": depth -= 1 score += depth + 0.5 elif s == "_": score += depth if depth == 0: return int(score) return int(score) def get_puddles(diagram): hight = 0 top_list = [] in_puddle = True for index, s in enumerate(diagram + "\\"): if s == "/": in_puddle = True hight += 1 if s == "\\": if in_puddle: in_puddle = False top_list.append([hight, index]) hight -= 1 puddles = [] prev_hight = 0 hight_list = [h for h, i in top_list] i = 0 while i < len(top_list) - 1: cur_top = top_list[i] next_tops = list(filter(lambda top:cur_top[0] <= top[0], top_list[i + 1:])) #print(next_tops) if next_tops: next_top = next_tops[0] puddles.append((cur_top[1], next_top[1])) i = top_list.index(next_top) else: cur_top[0] -= 1 cur_top[1] += diagram[cur_top[1] + 1:].index("\\") + 1 #print(hight_list) #print(top_list) #print(puddles) return puddles def main(): diagram = input() result = [] for s,e in get_puddles(diagram): result.append(cal_puddle(diagram[s:e])) print(sum(result)) print(str(len(result)) + "".join([" " + str(i) for i in result])) if __name__ == "__main__": main()
s553091963
p03448
u941753895
2,000
262,144
Wrong Answer
53
3,060
210
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()) cnt=0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if 500*A+100*B+50*C==X: cnt+=1 print(cnt)
s172110746
Accepted
52
3,060
210
A=int(input()) B=int(input()) C=int(input()) X=int(input()) cnt=0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if 500*i+100*j+50*k==X: cnt+=1 print(cnt)
s407291424
p02612
u345389118
2,000
1,048,576
Wrong Answer
28
9,144
88
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(N // 1000) else: print(N // 1000 + 1)
s471336155
Accepted
30
9,144
93
N = int(input()) if N % 1000 == 0: print(0) else: print((N // 1000 + 1) * 1000 - N)
s557254289
p03860
u089376182
2,000
262,144
Wrong Answer
17
2,940
45
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print('A', input().split()[1], 'C', sep = '')
s074478170
Accepted
17
2,940
69
temp = list(input().split()) print(temp[0][0]+temp[1][0]+temp[2][0])
s474567820
p03025
u111365362
2,000
1,048,576
Time Limit Exceeded
2,104
3,540
672
Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total. When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %. Find the expected number of games that will be played, and print it as follows. We can represent the expected value as P/Q with coprime integers P and Q. Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}. (Such an integer R always uniquely exists under the constraints of this problem.)
m = 10**9+7 def inv(x): m = 10**9+7 t = x y = 1 while True: if t == 1: break y *= m // t t = m % t y *= -1 y %= m return y def f(x): nn = x y = 1 while True: if nn == 1: break y *= nn nn -= 1 return y def cc(x,y): return f(x) // f(y) // f(x-y) n,a,b,c = map(int,input().split()) d = 100 - c awin = a * inv(d) bwin = b * inv(d) asc = 0 bsc = 0 for i in range(n): p = cc(n-1,i) * awin**(n-1) * bwin**i asc += p asc %= m for i in range(n): p = cc(n-1,i) * awin**i * bwin**(n-1) bsc += p bsc %= m sc0 = asc * awin + bsc * bwin sc0 %= m sc1 = sc0 * 100 * inv(d) sc1 %= m print(sc1)
s735098801
Accepted
927
3,064
596
#18:04 n,a,b,c = map(int,input().split()) mod = 10 ** 9 + 7 def inv(x): ans = 1 now = x while now != 1: ans *= mod // now + 1 ans %= mod now = now - mod % now return ans p = (a * inv(a+b)) % mod q = (b * inv(a+b)) % mod taka = 0 aoki = 0 tcom = 1 acom = 1 for i in range(n): taka += tcom * (n+i) tcom *= n+i tcom *= inv(i+1) tcom *= q tcom %= mod aoki += acom * (n+i) acom *= n+i acom *= inv(i+1) acom *= p acom %= mod for _ in range(n): taka *= p taka %= mod aoki *= q aoki %= mod ans = taka + aoki ans *= 100 ans *= inv(a+b) ans %= mod print(ans)
s993497167
p02393
u162598098
1,000
131,072
Wrong Answer
20
7,528
39
Write a program which reads three integers, and prints them in ascending order.
print(sorted(map(int,input().split())))
s634150899
Accepted
20
7,668
67
a,b,c=map(int,input().split()) [x,y,z]=sorted([a,b,c]) print(x,y,z)
s189080511
p02603
u860002137
2,000
1,048,576
Wrong Answer
34
9,004
328
To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: * A_1 yen on the 1-st day, A_2 yen on the 2-nd day, ..., A_N yen on the N-th day. In the i-th day, M-kun can make the following trade **any number of times** (possibly zero), **within the amount of money and stocks that he has at the time**. * Buy stock: Pay A_i yen and receive one stock. * Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally?
n = int(input()) tmp = list(map(int, input().split())) arr = [tmp[0]] for i in range(1, n): if arr[-1] != tmp[i]: arr.append(tmp[i]) m, s = 1000, 0 for i in range(1, len(arr)): if arr[i - 1] < arr[i]: s += m // arr[i - 1] m -= m // arr[i - 1] * arr[i - 1] m += s * arr[i] s = 0
s186296666
Accepted
32
9,192
554
n = int(input()) tmp = list(map(int, input().split())) arr = [tmp[0]] for i in range(1, n): if arr[-1] != tmp[i]: arr.append(tmp[i]) money, stock = 1000, 0 for i in range(1, len(arr)): if arr[i - 1] < arr[i]: buy, money = divmod(money, arr[i - 1]) stock += buy money += stock * arr[i] stock = 0 print(money)
s173995844
p03730
u483640741
2,000
262,144
Wrong Answer
17
2,940
130
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a,b,c=map(int,input().split()) s=a for i in range(b+1): if s%b==c: print("YES") else: s+=a print("NO")
s776319382
Accepted
17
2,940
144
a,b,c=map(int,input().split()) s=a for i in range(b+1): if s%b==c: print("YES") exit() else: s+=a print("NO")
s304186152
p04030
u653005308
2,000
262,144
Wrong Answer
17
2,940
110
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?
string=input() ans="" for x in string: if x!="b": ans+=x else: ans=ans[:-1] print(ans)
s455367147
Accepted
17
2,940
110
string=input() ans="" for x in string: if x!="B": ans+=x else: ans=ans[:-1] print(ans)
s567986324
p03448
u599547273
2,000
262,144
Wrong Answer
47
3,060
303
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, b, c, x = [int(input()) for i in range(4)] can_count = 0 for i in range(a): coins_price_500 = i * 500 for j in range(b): coins_price_100 = j * 100 for k in range(c): coins_price_50 = k * 50 if x == coins_price_500 * coins_price_100 * coins_price_50: can_count += 1 print(can_count)
s570756108
Accepted
45
3,060
309
a, b, c, x = [int(input()) for i in range(4)] can_count = 0 for i in range(a+1): coins_price_500 = i * 500 for j in range(b+1): coins_price_100 = j * 100 for k in range(c+1): coins_price_50 = k * 50 if x == coins_price_500 + coins_price_100 + coins_price_50: can_count += 1 print(can_count)
s656232281
p02408
u299798926
1,000
131,072
Wrong Answer
20
7,744
607
Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond.
n=int(input()) S=[int(0) for i in range(14)] H=[int(0) for i in range(14)] D=[int(0) for i in range(14)] C=[int(0) for i in range(14)] for i in range(n): K,y=[(i) for i in input().split()] if K=='S': S[int(y)]=1 elif K=='H': H[int(y)]=1 elif K=='D': D[int(y)]=1 else: C[int(y)]=1 for i in range(14): if S==0: print('S'," {0}".format(i)) for i in range(14): if H==0: print('H'," {0}".format(i)) for i in range(14): if D==0: print('D'," {0}".format(i)) for i in range(14): if C==0: print('C'," {0}".format(i))
s619759307
Accepted
30
7,804
667
n=int(input()) S=[int(0) for i in range(1,14)] H=[int(0) for i in range(1,14)] D=[int(0) for i in range(1,14)] C=[int(0) for i in range(1,14)] for i in range(n): K,y=[(i) for i in input().split()] if K=='S': S[int(y)-1]=1 elif K=='H': H[int(y)-1]=1 elif K=='D': D[int(y)-1]=1 else: C[int(y)-1]=1 for i in range(1,14): if S[int(i)-1]==0: print('S',"{0}".format(i)) for i in range(1,14): if H[int(i)-1]==0: print('H',"{0}".format(i)) for i in range(1,14): if C[int(i)-1]==0: print('C',"{0}".format(i)) for i in range(1,14): if D[int(i)-1]==0: print('D',"{0}".format(i))
s818309799
p02401
u876060624
1,000
131,072
Wrong Answer
20
5,596
158
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
a,b,c = map(str,input().split()) a,c =int(a),int(c) if b =='+': print(a+c) elif b == '-' : print(a-c) elif b == '*' : print(a*c) elif b == '/' : print(a/c)
s207461518
Accepted
20
5,596
195
while True : a,op,b = input().split() if op == '?' : break a,b = int(a),int(b) if op == '+' : print(a+b) if op == '-' : print(a-b) if op == '*' : print(a*b) if op == '/' : print(int(a/b))
s158970218
p03712
u588081069
2,000
262,144
Wrong Answer
19
3,060
204
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
H, W = list(map(int, input().split())) result = [["*"] * W] * (H + 2) for i in range(H): a = list(map(str, input())) result[i + 1] = a for i in range(len(result)): print("".join(result[i]))
s563528329
Accepted
19
3,060
196
H, W = list(map(int, input().split())) for i in range(H + 2): if i == 0 or i == (H + 1): print("#" * (W + 2)) else: print("#{}#".format("".join(list(map(str, input())))))
s363163723
p03545
u521866787
2,000
262,144
Wrong Answer
18
3,064
256
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
ABCD = input() for i in range(1,2**3): X = ABCD[0] for j in range(3): if 1 << j & i: X += '+' else: X += '-' X += ABCD[j+1] # print('eval: ',X) if eval(X) == 7: print(X) break
s191884498
Accepted
17
2,940
261
ABCD = input() for i in range(1,2**3): X = ABCD[0] for j in range(3): if 1 << j & i: X += '+' else: X += '-' X += ABCD[j+1] # print('eval: ',X) if eval(X) == 7: print(X+'=7') break
s093604953
p03645
u691018832
2,000
262,144
Wrong Answer
687
40,472
795
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, m = map(int, readline().split()) graph = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, readline().split()) graph[a].append(b) graph[b].append(a) def dfs(s): from collections import deque check = [0] * (n + 1) stack = deque([s]) check[s] = 0 while stack: now = stack.pop() for next in graph[now]: if check[next] != 0 and next != n: continue if next == n and check[now] == 1: print('POISSIBLE') exit() check[next] += check[now] + 1 stack.appendleft(next) dfs(1) print('IMPOSSIBLE')
s958614852
Accepted
575
40,420
794
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, m = map(int, readline().split()) graph = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, readline().split()) graph[a].append(b) graph[b].append(a) def dfs(s): from collections import deque check = [0] * (n + 1) stack = deque([s]) check[s] = 0 while stack: now = stack.pop() for next in graph[now]: if check[next] != 0 and next != n: continue if next == n and check[now] == 1: print('POSSIBLE') exit() check[next] += check[now] + 1 stack.appendleft(next) dfs(1) print('IMPOSSIBLE')
s868342406
p04043
u252745826
2,000
262,144
Wrong Answer
18
3,060
148
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 = list(map(int, input().split(" "))) if a+b+c == 17 and (a == b == 5 or b == c == 5 or c == a == 5): print("Yes") else: print("No")
s901637940
Accepted
17
2,940
168
a, b, c = list(map(int, input().split(" "))) if (a == b == 5 and c == 7) or (b == c == 5 and a == 7) or (c == a == 5 and b ==7): print("YES") else: print("NO")
s448434979
p03110
u044635590
2,000
1,048,576
Wrong Answer
17
2,940
226
Takahashi received _otoshidama_ (New Year's money gifts) from N of his relatives. You are given N values x_1, x_2, ..., x_N and N strings u_1, u_2, ..., u_N as input. Each string u_i is either `JPY` or `BTC`, and x_i and u_i represent the content of the otoshidama from the i-th relative. For example, if x_1 = `10000` and u_1 = `JPY`, the otoshidama from the first relative is 10000 Japanese yen; if x_2 = `0.10000000` and u_2 = `BTC`, the otoshidama from the second relative is 0.1 bitcoins. If we convert the bitcoins into yen at the rate of 380000.0 JPY per 1.0 BTC, how much are the gifts worth in total?
n = int(input()) summm = 0.0 for i in range(n): xu = list(map(str, input().split())) if xu[1] == "JPY": summm = summm + float(xu[0]) else: summm = summm + float(xu[0]) * 380000 print(int(summm))
s186389765
Accepted
17
3,060
221
n = int(input()) summm = 0.0 for i in range(n): xu = list(map(str, input().split())) if xu[1] == "JPY": summm = summm + float(xu[0]) else: summm = summm + float(xu[0]) * 380000.0 print(summm)
s785631420
p04012
u242580186
2,000
262,144
Wrong Answer
34
9,396
586
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
import sys from heapq import heappush, heappop, heapify import math from math import gcd import itertools as it from collections import deque input = sys.stdin.readline def inp(): return int(input()) def inpl(): return list(map(int, input().split())) INF = 1001001001 # --------------------------------------- def main(): s = input() dc = {} for st in s: if not st in dc: dc[st] = 1 else: dc[st] += 1 for k, v in dc.items(): if v % 2 == 1: print("No") return print("Yes") main()
s806258032
Accepted
31
9,348
170
import collections w = list(input()) cnt = collections.Counter(w) ans = "Yes" for v in cnt.values(): if v%2!=0: ans = "No" break print(ans)
s999647747
p02262
u938045879
6,000
131,072
Wrong Answer
20
5,600
548
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
n = int(input()) li = [int(input()) for i in range(n)] cnt = 0 def shell_sort(li, n): m = n//2 G = [i**2 for i in range(m, 0, -1)] for i in range(m): insertionSort(li, n, G[i]) return m, G def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i-g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j-g cnt += 1 A[j+g] = v m, G = shell_sort(li, n) print(m) strG = [str(i) for i in G] print(' '.join(strG)) for i in li: print(i)
s355599983
Accepted
19,810
45,588
609
import math n = int(input()) li = [int(input()) for i in range(n)] cnt = 0 def shell_sort(li, n): m = math.floor(math.log(2*n+1, 3)) G = [round((3**i-1)/2) for i in range(m, 0, -1)] for i in range(m): insertionSort(li, n, G[i]) return m, G def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i-g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j-g cnt += 1 A[j+g] = v m, G = shell_sort(li, n) print(m) strG = [str(i) for i in G] print(' '.join(strG)) print(cnt) for i in li: print(i)
s223870255
p03385
u754022296
2,000
262,144
Wrong Answer
17
2,940
61
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
if sorted(input())=="abc": print("Yes") else: print("No")
s578145577
Accepted
18
3,068
70
if sorted(input())==["a","b","c"]: print("Yes") else: print("No")
s095573358
p03827
u319690708
2,000
262,144
Wrong Answer
17
3,064
268
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`. Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).
N = int(input()) S = input().split() X = 0 S1 = list(S[0]) S1_mod = [-1 if i == "I" else i for i in S1] S1_mod = [1 if i == "D" else i for i in S1_mod] l = [] for i in S1_mod: if i == -1: X += -1 l.append(X) else: X+= 1 l.append(X) print(max(l))
s824121961
Accepted
17
3,064
305
N = int(input()) S = input().split() X = 0 S1 = list(S[0]) S1_mod = [1 if i == "I" else i for i in S1] S1_mod = [-1 if i == "D" else i for i in S1_mod] l = [] for i in S1_mod: if i == -1: X += -1 l.append(X) else: X+= 1 l.append(X) if max(l) < 0: print(0) else: print(max(l))
s960889794
p03494
u798557584
2,000
262,144
Wrong Answer
17
2,940
29
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.
print(input().count("1"))
s151121222
Accepted
19
3,060
235
import math n = int(input()) a = list(map(int,input().split())) cnt = 0 while True: flg = 0 for i in range(n): if a[i] % 2 == 1: flg = 1 break else: a[i] = a[i] / 2 if flg == 1: break cnt += 1 print(cnt)
s829384733
p03548
u882370611
2,000
262,144
Wrong Answer
17
2,940
51
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(int(x-z//y+z))
s770536303
Accepted
17
2,940
51
x,y,z=map(int,input().split()) print((x-z)//(y+z))
s730619305
p03992
u094191970
2,000
262,144
Wrong Answer
17
2,940
31
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.
s=input() print(s[:4]+''+s[4:])
s794395917
Accepted
17
2,940
32
s=input() print(s[:4]+' '+s[4:])
s129463325
p03693
u497952650
2,000
262,144
Wrong Answer
17
2,940
98
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this integer a multiple of 4?
a,b,c = map(int,input().split()) if (100*a+10*b+c)%4 == 0: print("Yes") else: print("No")
s588025433
Accepted
17
2,940
92
a,b,c = map(int,input().split()) if (10*b+c)%4 == 0: print("YES") else: print("NO")
s447526412
p02393
u586792237
1,000
131,072
Wrong Answer
20
5,592
182
Write a program which reads three integers, and prints them in ascending order.
x, y, z = map(int, input().split()) if x > y : x, y, z = y, x, z if x > z: x, y, z = z, y, x if y > z: x, y, z = x, y, z if x > y and y > z: x, y, z = z, y, x print(x, y, z)
s759635769
Accepted
20
5,588
71
a = list(map(int, input().split())) a.sort() print(a[0], a[1], a[2])
s552800703
p03337
u174523836
2,000
1,048,576
Wrong Answer
19
2,940
68
You are given two integers A and B. Find the largest value among A+B, A-B and A \times B.
x, y = [int(s) for s in input().split()] max([x + y, x - y, x * y])
s944734676
Accepted
17
2,940
75
x, y = [int(s) for s in input().split()] print(max([x + y, x - y, x * y]))
s820931307
p03657
u600402037
2,000
262,144
Wrong Answer
17
2,940
96
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()) print('Possible' if a%3==0 or b%3==0 or a+b%3==0 else 'Impossible')
s629580424
Accepted
17
2,940
98
a,b=map(int,input().split()) print('Possible' if a%3==0 or b%3==0 or (a+b)%3==0 else 'Impossible')
s468739068
p03796
u323680411
2,000
262,144
Wrong Answer
25
3,064
487
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.
from sys import stdin def main() -> int: n = next_int() m = 10 ** 9 + 7 ans = 1 for i in range(n): j = i % m ans = (ans * j) % m print(ans) return 0 def next_int() -> int: return int(next_str()) def next_str() -> str: result = "" while True: tmp = stdin.read(1) if tmp.strip() != "": result += tmp elif tmp != '\r': break return result if __name__ == '__main__': main()
s753684260
Accepted
31
3,064
495
from sys import stdin def main() -> int: n = next_int() m = 10 ** 9 + 7 ans = 1 for i in range(1, n + 1): j = i % m ans = (ans * j) % m print(ans) return 0 def next_int() -> int: return int(next_str()) def next_str() -> str: result = "" while True: tmp = stdin.read(1) if tmp.strip() != "": result += tmp elif tmp != '\r': break return result if __name__ == '__main__': main()
s459986205
p03478
u358791207
2,000
262,144
Wrong Answer
28
2,940
244
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
def sumcal(num): sum = 0 while(num != 0): sum += (num % 10) num = num // 10 return sum N, A, B = map(int, input().split()) count = 0 for i in range(N): sum = sumcal(N + 1) if sum >= A and sum <= B: count += 1 print(count)
s566000872
Accepted
26
3,060
248
def sumcal(num): sum = 0 while(num != 0): sum += (num % 10) num = num // 10 return sum N, A, B = map(int, input().split()) count = 0 for i in range(N): sum = sumcal(i + 1) if sum >= A and sum <= B: count += i + 1 print(count)
s796761170
p02534
u840649762
2,000
1,048,576
Wrong Answer
27
9,148
46
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
k = int(input()) ans = "ACL" * 5 print(ans)
s230762258
Accepted
29
9,040
46
k = int(input()) ans = "ACL" * k print(ans)
s923339936
p03377
u995062424
2,000
262,144
Wrong Answer
17
2,940
125
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
num = input().split() num_i = [int(s) for s in num] if(num_i[0]+num_i[2] < num_i[1]): print('YES') else: print('NO')
s645814704
Accepted
17
2,940
154
num = input().split() num_i = [int(s) for s in num] if(num_i[0]+num_i[1]-num_i[2] > 0) and (num_i[2] >= num_i[0]): print('YES') else: print('NO')
s453883937
p02678
u802180430
2,000
1,048,576
Wrong Answer
2,229
652,600
525
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
n,m = list(map(int,input().split())) dist = [[float("inf") for _ in range(n+1)]for _ in range(n+1)] for i in range(1,n+1): dist[i][i] = 0; for _ in range(m): a,b = list(map(int,input().split())) dist[a][b] = 1; dist[b][a] = 1; for k in range(1,n+1): for j in range(1,n+1): dist[1][j] = min(dist[1][j],dist[1][k] + dist[k][j]) flag = False; for i in range(2,n+1): if dist[1][i] == float("inf"): print("NO") flag = True break; if not flag: print("YES") for i in range(2,n+1): print(dist[1][i])
s553195456
Accepted
798
50,996
676
n,m = map(int,input().split()) g = [[] for _ in range(n)] for _ in range(m): a, b = [int(x) for x in input().split()] g[a-1].append(b-1) g[b-1].append(a-1) from collections import deque def bfs(u): queue = deque([u]) d = [None] * n d[u] = 0 l = [[] for _ in range(n)] dic = {} while queue: v = queue.popleft() for i in g[v]: if d[i] is None: d[i] = d[v] + 1 queue.append(i) l[i].append(v) dic[i] = v return d,l,dic d,l,dic = bfs(0) if None in d: print("No") else: print("Yes") l.remove(l[0]) [print(i[0]+1) for i in l]
s261635815
p02613
u688203790
2,000
1,048,576
Wrong Answer
155
16,244
309
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n = int(input()) s = [input() for _ in range(n)] ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): if s[i] == 'AC': ac += 1 elif s[i] == 'WA': wa += 1 elif s[i] == 'TLE': tle += 1 else: re += 1 print("AC ×" + str(ac)) print("WA ×" + str(wa)) print("TLE ×" + str(tle)) print("RE ×" + str(re))
s807830643
Accepted
153
16,268
322
n = int(input()) s = [input() for _ in range(n)] ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): if s[i] == 'AC': ac += 1 elif s[i] == 'WA': wa += 1 elif s[i] == 'TLE': tle += 1 elif s[i] == 'RE': re += 1 print("AC x " + str(ac)) print("WA x " + str(wa)) print("TLE x " + str(tle)) print("RE x " + str(re))
s306099417
p03563
u675919123
2,000
262,144
Wrong Answer
17
3,064
631
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
#coding: utf-8 SS = input() T = input() f = 0 if len(SS) < len(T): print('UNRESTORABLE') else: for i in range(0, len(SS)-len(T)+1): pSS = SS[i:len(T)+i] Tt = '' for j in range(0,len(T)): if pSS[j] == T[j]: Tt += T[j] elif pSS[j] == '?': Tt += T[j] else: break if Tt == T: f += 1 SS = SS.replace(SS[i:len(T)+i], Tt) ans = SS.replace('?','a') break else: f += 0 if f == 1: print(ans) else: print('UNRESTORABLE')
s345405706
Accepted
18
2,940
65
#coding: utf-8 R = int(input()) G = int(input()) print(2*G - R)
s382228291
p03545
u104005543
2,000
262,144
Wrong Answer
18
3,064
337
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
abcd = str(input()) a = int(abcd[0]) b = int(abcd[1]) c = int(abcd[2]) d = int(abcd[3]) for i in range(2 ** 3): op = [1, 1, 1] for j in range(3): if ((i >> j) & 1): op[j] = -1 if (a + b * op[0] + c * op[1] + d * op[2]) == 7: print(str(a) + str(b * op[0]) + str(c * op[1]) + str(d * op[2]) + '=7')
s251123832
Accepted
18
3,064
436
abcd = str(input()) a = int(abcd[0]) b = int(abcd[1]) c = int(abcd[2]) d = int(abcd[3]) for i in range(2 ** 3): op = ['+', '+', '+'] ans = a for j in range(3): if ((i >> j) & 1): op[j] = '-' ans -= int(abcd[j + 1]) else: ans += int(abcd[j + 1]) if ans == 7: print(str(a) + str(op[0]) + str(b) + str(op[1]) + str(c) + str(op[2]) + str(d) + '=7') exit()
s360369619
p03150
u811000506
2,000
1,048,576
Wrong Answer
17
2,940
137
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.
S = str(input()) for i in range(8): word = S[:i]+S[-7:][i:] if word == "keyence": print("Yes") exit() print("No")
s773621663
Accepted
17
2,940
137
S = str(input()) for i in range(8): word = S[:i]+S[-7:][i:] if word == "keyence": print("YES") exit() print("NO")
s799572239
p04043
u178963077
2,000
262,144
Wrong Answer
17
2,940
112
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
a = list(map(int, input().split())) if sum(a) == 17 and a.count(5) == 2: print("Yes") else: print("No")
s269613527
Accepted
17
2,940
112
a = list(map(int, input().split())) if sum(a) == 17 and a.count(5) == 2: print("YES") else: print("NO")
s547179767
p03729
u186838327
2,000
262,144
Wrong Answer
17
2,940
106
You are given three strings A, B and C. Check whether they form a _word chain_. More formally, determine whether both of the following are true: * The last character in A and the initial character in B are the same. * The last character in B and the initial character in C are the same. If both are true, print `YES`. Otherwise, print `NO`.
a, b, c = map(str, input().split()) if a[-1] == b[0] and b[-1] == c[0]: print('Yes') else: print('No')
s895547106
Accepted
18
2,940
106
a, b, c = map(str, input().split()) if a[-1] == b[0] and b[-1] == c[0]: print('YES') else: print('NO')
s506352413
p02928
u602252807
2,000
1,048,576
Wrong Answer
216
3,444
424
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}. Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2. Find the inversion number of B, modulo 10^9 + 7. Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
n,k = map(int,input().split()) a = list(map(int,input().split())) a2 = a + a def tentou (l): count = [0]*len(l) for i in range(len(l)-1): for j in range(i+1,len(l)): if l[i] > l[j]: count[i] += 1 return count v = tentou(a) vk = [0]*len(v) print(v) print(vk) for i in range(len(v)): vk[i] = v[i] * (k*(k+1))//2 print(vk) S = sum(vk) result = S % ((10**9) + 7) print(result)
s619509234
Accepted
999
3,336
635
n,k = map(int,input().split()) a = list(map(int,input().split())) a2 = a + a def tentou (l): count = [0]*len(l) for i in range(len(l)-1): for j in range(i+1,len(l)): if l[i] > l[j]: count[i] += 1 return count if n == 1: print(0) else: a_v = tentou(a) a2_v = tentou(a2) mergin = [x-y-y for (x,y) in zip(a2_v,a_v)] if k == 1: S = sum(a_v) result = S % ((10**9) + 7) else: for i in range(len(a_v)): a_v[i] = a_v[i]*(k*(k+1))//2 + mergin[i]*(k*(k-1))//2 S = sum(a_v) result = S % ((10**9) + 7) print(result)
s314365058
p02534
u751724075
2,000
1,048,576
Wrong Answer
23
9,012
24
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
print(input().strip()*3)
s920286532
Accepted
23
9,072
35
K = int(input()) print("ACL" * K)
s406825093
p03730
u794603719
2,000
262,144
Wrong Answer
21
3,316
199
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`.
a, b, c = map(int, input().split(" ")) print(a,b,c) flag = 1 for i in range(101): temp = a * i if(temp % b == c): print("YES") flag = 0 break if(flag): print("NO")
s702185955
Accepted
17
2,940
201
a, b, c = map(int, input().split(" ")) # print(a,b,c) flag = 1 for i in range(101): temp = a * i if(temp % b == c): print("YES") flag = 0 break if(flag): print("NO")
s753303710
p03635
u224156735
2,000
262,144
Wrong Answer
17
2,940
47
In _K-city_ , there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
S=input() a=str(len(S)-2) print(S[:1]+a+S[-1:])
s572270254
Accepted
17
2,940
47
a,b=map(int,input().split()) print((a-1)*(b-1))
s929850128
p03471
u414626225
2,000
262,144
Wrong Answer
263
9,148
378
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N, Y = map(int, input().split()) if (Y > N * 10000) or (Y < N * 1000): print("{} {} {}".format(-1, -1, -1)) found = False for x in range(Y//10000+2): for y in range(Y//5000+2): z = N - x - y if (x * 10000 + y * 5000 + z * 1000) == Y: print("{} {} {}".format(x, y, z)) found = True break if found: break
s268599835
Accepted
945
9,176
541
N, Y = map(int, input().split()) # if (Y > N * 10000) or (Y < N * 1000): # print("{} {} {}".format(-1, -1, -1)) found = False for x in range(N+1): for y in range(N+1): if (x + y) > N: continue z = N - x - y if z < 0: continue if (x * 10000 + y * 5000 + z * 1000) == Y: ans_x = x ans_y = y ans_z = z found = True if found: print("{} {} {}".format(ans_x, ans_y, ans_z)) else: print("{} {} {}".format(-1, -1, -1))
s222533217
p03352
u652081898
2,000
1,048,576
Wrong Answer
17
2,940
220
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.
x = int(input()) result = 0 for i in range(2, 32): for j in range(1,10): test = i**j if test <= x and test >= result: result = test else: pass print(result)
s064233705
Accepted
18
2,940
221
x = int(input()) result = 1 for i in range(2, 32): for j in range(2,10): test = i**j if test <= x and test >= result: result = test else: pass print(result)
s347186543
p04012
u723583932
2,000
262,144
Wrong Answer
17
3,060
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.
#abc044 b s=input() moji=dict() flag=True for i in range(len(s)): if i not in moji: moji[i]=1 else: moji[i]+=1 for i in moji.values(): if i%2==1: flag=False break print("Yes" if flag else "No")
s530315175
Accepted
17
2,940
226
#abc044 b s=input() moji=dict() flag=True for i in s: if i not in moji: moji[i]=1 else: moji[i]+=1 for i in moji.values(): if i%2==1: flag=False break print("Yes" if flag else "No")
s850165090
p03563
u790877102
2,000
262,144
Wrong Answer
23
2,940
58
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the _rating_ of the user (not necessarily an integer) changes according to the _performance_ of the user, as follows: * Let the current rating of the user be a. * Suppose that the performance of the user in the contest is b. * Then, the new rating of the user will be the avarage of a and b. For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000. Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest. Find the performance required to achieve it.
R = int(input()) G = int(input()) W = R + R - G print(W)
s164251043
Accepted
17
2,940
55
R = int(input()) G = int(input()) W = G+G-R print(W)
s566341134
p03457
u903959844
2,000
262,144
Wrong Answer
394
11,844
446
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()) t = [0] x = [0] y = [0] for i in range(N): a = input().split() t.append(int(a[0])) x.append(int(a[1])) y.append(int(a[2])) bool = False for i in range(N): if t[i+1]-t[i] >= abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]): t_EO = (t[i+1]-t[i]) % 2 xy_EO = (abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])) % 2 if t_EO == xy_EO: bool = True if bool == True: print("YES") else: print("NO")
s413396831
Accepted
352
11,816
409
N = int(input()) t = [0] x = [0] y = [0] for i in range(N): a = input().split() t.append(int(a[0])) x.append(int(a[1])) y.append(int(a[2])) bool = True for i in range(N): d_t = abs(t[i+1]-t[i]) d_xy = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]) if d_t < d_xy: bool = False elif d_t % 2 != d_xy % 2: bool = False if bool == True: print("Yes") else: print("No")
s040072075
p03433
u354527070
2,000
262,144
Wrong Answer
26
9,040
107
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
n = int(input()) a = int(input()) print(n) mod = n % 500 if mod < a: print("Yes") else: print("No")
s623281048
Accepted
26
9,100
99
n = int(input()) a = int(input()) mod = n % 500 if mod <= a: print("Yes") else: print("No")
s070918481
p03573
u467307100
2,000
262,144
Wrong Answer
17
2,940
100
You are given three integers, A, B and C. Among them, two are the same, but the remaining one is different from the rest. For example, when A=5,B=7,C=5, A and C are the same, but B is different. Find the one that is different from the rest among the given three integers.
a, b, c = map(int,input().split()) if a == b: print(a) if b == c: print(b) if a ==c: print(c)
s084810997
Accepted
17
2,940
100
a, b, c = map(int,input().split()) if a == b: print(c) if b == c: print(a) if a ==c: print(b)
s458392740
p02612
u937238023
2,000
1,048,576
Wrong Answer
28
9,152
51
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()) x = (n+999)/1000 print(x*1000 - n)
s408790800
Accepted
27
9,052
53
n = int(input()) x = (n+999)//1000 print(x*1000 - n)
s931151418
p03998
u396961814
2,000
262,144
Wrong Answer
17
3,064
584
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
SA = input() SB = input() SC = input() WIN = [0, 0, 0] SA_CNT = 0 SB_CNT = 0 SC_CNT = 0 card = SA[0] while True: if card == 'a': SA_CNT += 1 if SA_CNT == len (SA): print('a') break else: card = SA[SA_CNT] if card == 'b': SB_CNT += 1 if SB_CNT == len(SB): print('b') break else: card = SB[SA_CNT] if card == 'c': SC_CNT += 1 if SC_CNT == len (SC): print('c') break else: card = SC[SA_CNT]
s809892548
Accepted
17
3,064
577
SA = input() SB = input() SC = input() card = SA[0] SA_CNT = 1 SB_CNT = 0 SC_CNT = 0 while True: if card == 'a': if SA_CNT < len (SA): card = SA[SA_CNT] SA_CNT += 1 else: print('A') break if card == 'b': if SB_CNT < len (SB): card = SB[SB_CNT] SB_CNT += 1 else: print('B') break if card == 'c': if SC_CNT < len (SC): card = SC[SC_CNT] SC_CNT += 1 else: print('C') break
s838318553
p03228
u932465688
2,000
1,048,576
Wrong Answer
18
3,064
281
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
A,B,K = map(int,input().split()) c = 0 if K%2 == 0: while c <= K: B = B+A//2 A = A//2 c += 1 A = A+B//2 B = B//2 c += 1 else: while c < K-1: B = B+A//2 A = A//2 c += 1 A = A+B//2 B = B//2 c += 1 B = B+A//2 A = A//2 print(A,B)
s458922355
Accepted
18
3,064
280
A,B,K = map(int,input().split()) c = 0 if K%2 == 0: while c < K: B = B+A//2 A = A//2 c += 1 A = A+B//2 B = B//2 c += 1 else: while c < K-1: B = B+A//2 A = A//2 c += 1 A = A+B//2 B = B//2 c += 1 B = B+A//2 A = A//2 print(A,B)
s857333839
p03377
u287431190
2,000
262,144
Wrong Answer
17
2,940
119
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a,b,x = map(int, input().split()) if a > x: print('No') exit() if (a+b) > x: print('No') exit() print('Yes')
s675394146
Accepted
17
2,940
119
a,b,x = map(int, input().split()) if x < a: print('NO') exit() if (a+b) < x: print('NO') exit() print('YES')
s500792114
p02936
u517447467
2,000
1,048,576
Wrong Answer
2,107
56,180
545
Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i. Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0. Now, the following Q operations will be performed: * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j. Find the value of the counter on each vertex after all operations.
import copy N, Q = list(map(int, input().split())) nodes = dict() for i in range(N-1): r, e = list(map(int, input().split())) if r not in nodes: nodes[r] = [e] else: nodes[r].append(e) #print(nodes) result = [0] * N edges = [] for i in range(Q): r, s = list(map(int, input().split())) result[r-1] += s if r in nodes: edges = copy.copy(nodes[r]) while len(edges) != 0: r = edges.pop(0) result[r-1] += s if r in nodes: edges.extend(nodes[r]) #print(edges, nodes[r]) #print(result) print(result)
s962446109
Accepted
1,865
274,864
546
import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) N, Q = list(map(int, input().split())) nodes = [[] for i in range(N)] for i in range(N-1): r, e = list(map(int, input().split())) r, e = r - 1, e - 1 nodes[r].append(e) nodes[e].append(r) #print(nodes) result = [0] * N for i in range(Q): r, s = list(map(int, input().split())) result[r-1] += s def dfs(r, prev=-1): for i in nodes[r]: if i == prev: continue result[i] += result[r] dfs(i, r) if __name__ == "__main__": dfs(0) print(*result)
s008818401
p02613
u637874199
2,000
1,048,576
Wrong Answer
138
16,280
237
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()) data = [input() for _ in range(n)] a = data.count("AC") b = data.count("WA") c = data.count("TLE") d = data.count("RE") print("AC × " + str(a)) print("WA × " + str(b)) print("TLE × " + str(c)) print("RE × " + str(d))
s400339084
Accepted
138
16,208
233
n = int(input()) data = [input() for _ in range(n)] a = data.count("AC") b = data.count("WA") c = data.count("TLE") d = data.count("RE") print("AC x " + str(a)) print("WA x " + str(b)) print("TLE x " + str(c)) print("RE x " + str(d))
s199477260
p03338
u488934106
2,000
1,048,576
Wrong Answer
18
3,064
385
You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.
def CutandCount(n , s): ans = 0 for i in range(1 , n + 1): count = 0 for w in range(ord('a'), ord('z') + 1): if s[:i] in chr(w) and s[i:] in chr(w): count += 1 ans = max(ans , count) return ans def main(): n = int(input()) s = str(input()) print(CutandCount(n , s)) if __name__ == '__main__': main()
s365408365
Accepted
18
3,064
385
def CutandCount(n , s): ans = 0 for i in range(1 , n + 1): count = 0 for w in range(ord('a'), ord('z') + 1): if chr(w) in s[:i] and chr(w) in s[i:]: count += 1 ans = max(ans , count) return ans def main(): n = int(input()) s = str(input()) print(CutandCount(n , s)) if __name__ == '__main__': main()
s969454796
p03555
u106297876
2,000
262,144
Wrong Answer
17
2,940
86
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
a = list(input()) b = list(input()) if a == b[::-1]: print('Yes') else: print('No')
s476154983
Accepted
17
2,940
86
a = list(input()) b = list(input()) if a == b[::-1]: print('YES') else: print('NO')
s198474845
p02842
u511457539
2,000
1,048,576
Wrong Answer
17
2,940
91
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
N = int(input()) X = N/1.08 if X*1.08 //1 == N: print(X) else: print(X) print(":(")
s341961982
Accepted
17
2,940
104
import math N = int(input()) x = math.ceil(N/1.08) if x*1.08//1 == N: print(x) else: print(":(")
s485010444
p02613
u882765852
2,000
1,048,576
Wrong Answer
157
9,216
285
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n=int(input()) ac=0 wa=0 tle=0 re=0 for i in range(n) : s=str(input()) if s=="AC" : ac=ac+1 elif s=="WA" : wa=wa+1 elif s=="TLE" : tle=tle+1 else : re=re+1 print("AC ×",ac) print("WA ×",wa) print("TLE ×",tle) print("RE ×",re)
s642689967
Accepted
156
9,208
281
n=int(input()) ac=0 wa=0 tle=0 re=0 for i in range(n) : s=str(input()) if s=="AC" : ac=ac+1 elif s=="WA" : wa=wa+1 elif s=="TLE" : tle=tle+1 else : re=re+1 print("AC x",ac) print("WA x",wa) print("TLE x",tle) print("RE x",re)
s823031175
p03437
u010090035
2,000
262,144
Wrong Answer
2,103
3,060
154
You are given positive integers X and Y. If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it. If it does not exist, print -1.
l = list(map(int,input().split())) A = l[0]; B = l[1]; if(A%B == 0): print(-1) else: xa = A; while xa%B != 0: xa += A; print(xa);
s576131695
Accepted
17
3,060
234
l = list(map(int,input().split())) A = l[0]; B = l[1]; if(A%B == 0): print(-1) else: xa = A*2; while ((xa%B == 0) and (xa < 10**18)): xa += A; if(xa > 10**18): print(-1); else: print(xa);
s144334847
p03448
u276115223
2,000
262,144
Wrong Answer
18
3,060
304
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.
# ABC 087: B – Coins a, b, c, x = [int(input()) for _ in range(4)] number_of_ways = 0 for i in range(a + 1): for j in range(b + 1): if 0 <= (x - (500 * i + 100 * j)) // 50 <= c: print(i, j, (x - (500 * i + 100 * j)) // 50) number_of_ways += 1 print(number_of_ways)
s106827654
Accepted
54
3,060
254
# ABC 087: B – Coins a, b, c, x = [int(input()) for _ in range(4)] comb = 0 for i in range(0, a + 1): for j in range(0, b + 1): for k in range(0, c + 1): comb = comb + 1 if 500 * i + 100 * j + 50 * k == x else comb print(comb)
s459081490
p02742
u484052148
2,000
1,048,576
Wrong Answer
17
2,940
167
We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1-th row (from the top) and the c_1-th column (from the left) to the square at the r_2-th row and the c_2-th column if and only if exactly one of the following holds: * r_1 + c_1 = r_2 + c_2 * r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move:
h, w = map(int, input().split()) if h==1 or w==1: print(1) elif h%2 != w%2 != 0: print(h*w//2 + 1) else: print(h*w//2)
s779604844
Accepted
18
3,060
173
h, w = map(int, input().split()) if h==1 or w==1: print(1) elif h%2 != 0 and w%2 != 0: print(h*w//2 + 1) else: print(h*w//2)