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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s956722580
|
p04029
|
u324508508
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 46 |
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
N=int(input())
s=0
for i in range(0,N):
s=s+i
|
s737109999
|
Accepted
| 17 | 2,940 | 57 |
N=int(input())
s=0
for i in range(0,N+1):
s=s+i
print(s)
|
s438772121
|
p03150
|
u970198631
| 2,000 | 1,048,576 |
Wrong Answer
| 29 | 9,028 | 191 |
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 = input()
a = len(S)
count=0
for i in range(a):
for j in range(i+1,a):
XX= S[:i] +S[j:a]
if XX == 'keyence':
count +=1
if count == 0:
print('No')
else:
print('Yes')
|
s244639999
|
Accepted
| 31 | 9,080 | 189 |
S = input()
a = len(S)
count=0
for i in range(a):
for j in range(i,a):
XX= S[:i] +S[j:a]
if XX == 'keyence':
count +=1
if count == 0:
print('NO')
else:
print('YES')
|
s063225129
|
p03486
|
u181195295
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 82 |
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
s = sorted(input())
t = sorted(input())
if s < t:
print("Yes")
else:print("No")
|
s870778564
|
Accepted
| 17 | 2,940 | 89 |
s = sorted(input())
t = sorted(input())[::-1]
if s < t:
print("Yes")
else:print("No")
|
s757547964
|
p03862
|
u106778233
| 2,000 | 262,144 |
Wrong Answer
| 89 | 14,060 | 163 |
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: * Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: * Any two neighboring boxes contain at most x candies in total. Find the minimum number of operations required to achieve the objective.
|
n,x=map(int,input().split())
A=list(map(int,input().split()))
A=[0]+A
cnt=0
for i in range(n):
use=(A[i]+A[i+1])-x
cnt+=use
A[i+1]-=use
print(cnt)
|
s932126861
|
Accepted
| 85 | 14,092 | 85 |
n,x,*a=map(int,open(0).read().split());t=r=0
for i in a:t=min(i,x-t);r+=i-t
print(r)
|
s200178400
|
p02936
|
u325282913
| 2,000 | 1,048,576 |
Wrong Answer
| 1,898 | 112,236 | 340 |
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.
|
N, Q = map(int, input().split())
ki = []
action = []
ans = [0] * (N+1)
for _ in range(N-1):
array = list(map(int, input().split()))
ki.append(array)
for i in range(Q):
array = list(map(int, input().split()))
action.append(array)
ans[array[0]] += array[1]
for k in range(N-1):
ans[ki[k][1]] += ans[ki[k][0]]
print(ans)
|
s092539129
|
Accepted
| 1,397 | 228,020 | 549 |
import sys
sys.setrecursionlimit(10**7)
N, Q = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(int, input().split())
edges[a - 1].append(b - 1)
edges[b - 1].append(a - 1)
Query = [0]*N
for _ in range(Q):
p, x = map(int, input().split())
Query[p-1] += x
ans = [0]*N
past = [0]*N
def dfs(start,point):
past[start] = 1
point = point + Query[start]
ans[start] = point
for target in edges[start]:
if past[target] == 0:
dfs(target,point)
dfs(0,0)
print(*ans)
|
s345127797
|
p02842
|
u193927973
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 78 |
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())
a=n//1.08
b=int(a*1.08)
if a==b:
print(a)
else:
print(":(")
|
s974865176
|
Accepted
| 17 | 3,064 | 227 |
n=int(input())
a=int(n/1.08)
aa=a-1
aaa=a+1
b=int(a*1.08)
bb=int(aa*1.08)
bbb=int(aaa*1.08)
A=[a,aa,aaa]
B=[b,bb,bbb]
f=0
for i in range(3):
if B[i]==n:
f=1
ans=A[i]
break
if f==0:
print(":(")
else:
print(ans)
|
s792583981
|
p04012
|
u653005308
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 107 |
Let w be a string consisting of lowercase letters. We will call w _beautiful_ if the following condition is satisfied: * Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful.
|
w=input()
for alphabet in w:
if w.count(alphabet)%2!=0:
print("NO")
exit()
print("YES")
|
s434324241
|
Accepted
| 17 | 2,940 | 107 |
w=input()
for alphabet in w:
if w.count(alphabet)%2!=0:
print("No")
exit()
print("Yes")
|
s221921831
|
p03597
|
u960513073
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 36 |
We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black?
|
print(int(input())^2 - int(input()))
|
s360447331
|
Accepted
| 18 | 2,940 | 37 |
print(int(input())**2 - int(input()))
|
s305764561
|
p02865
|
u571173211
| 2,000 | 1,048,576 |
Wrong Answer
| 20 | 3,060 | 30 |
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
|
a = (int)(input())
print(a//2)
|
s664969442
|
Accepted
| 17 | 2,940 | 34 |
a = (int)(input())
print((a-1)//2)
|
s807040860
|
p03643
|
u451017206
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 63 |
This contest, _AtCoder Beginner Contest_ , is abbreviated as _ABC_. When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC. What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
|
N=int(input())
a = 1
while a <= N:
a *= 2
print (int(a/2))
|
s912591076
|
Accepted
| 17 | 2,940 | 24 |
N=input()
print('ABC'+N)
|
s999458126
|
p03998
|
u131464432
| 2,000 | 262,144 |
Wrong Answer
| 30 | 9,160 | 440 |
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 = list(input())
SB = list(input())
SC = list(input())
turn = "a"
for i in range(300):
if turn == "a":
if not SA:
print("a")
exit()
turn = SA[0]
SA.pop(0)
elif turn == "b":
if not SB:
print("b")
exit()
turn = SB[0]
SB.pop(0)
else:
if not SC:
print("c")
exit()
turn = SC[0]
SC.pop(0)
|
s651291591
|
Accepted
| 26 | 8,956 | 440 |
SA = list(input())
SB = list(input())
SC = list(input())
turn = "a"
for i in range(300):
if turn == "a":
if not SA:
print("A")
exit()
turn = SA[0]
SA.pop(0)
elif turn == "b":
if not SB:
print("B")
exit()
turn = SB[0]
SB.pop(0)
else:
if not SC:
print("C")
exit()
turn = SC[0]
SC.pop(0)
|
s205731659
|
p02843
|
u970523279
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 101 |
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
|
x = int(input())
y = x % 100
z = x // 100
print(y, z)
if z * 5 >= y:
print(1)
else:
print(0)
|
s897136979
|
Accepted
| 17 | 2,940 | 89 |
x = int(input())
y = x % 100
z = x // 100
if z * 5 >= y:
print(1)
else:
print(0)
|
s895553667
|
p03085
|
u708255304
| 2,000 | 1,048,576 |
Wrong Answer
| 19 | 3,060 | 204 |
On the Planet AtCoder, there are four types of bases: `A`, `C`, `G` and `T`. `A` bonds with `T`, and `C` bonds with `G`. You are given a letter b as input, which is `A`, `C`, `G` or `T`. Write a program that prints the letter representing the base that bonds with the base b.
|
import sys
for line in sys.stdin.readlines():
if line == 'A':
print('T')
if line == 'T':
print('A')
if line == 'C':
print('G')
if line == 'G':
print('C')
|
s781621526
|
Accepted
| 17 | 2,940 | 226 |
import sys
for line in sys.stdin.readlines():
line=line.strip()
if line == 'A':
print('T')
if line == 'T':
print('A')
if line == 'C':
print('G')
if line == 'G':
print('C')
|
s224657044
|
p03693
|
u972892985
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 97 |
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())
x = (r+g+b)
if x % 4 == 0:
print("YES")
else:
print("NO")
|
s651343957
|
Accepted
| 17 | 2,940 | 98 |
r, g, b = list(input().split())
x = int(r+g+b)
if x % 4 == 0:
print("YES")
else:
print("NO")
|
s129620407
|
p03729
|
u278143034
| 2,000 | 262,144 |
Wrong Answer
| 30 | 9,116 | 257 |
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())
cnt = 3
set_list = set([A[-1],B[0],B[-1],C[0],C[-1]])
if len(set_list) == cnt:
print("Yes")
else:
print("No")
|
s815233531
|
Accepted
| 26 | 9,092 | 381 |
word_list = input().split()
w_cnt = len(word_list)
s_list = []
e_list = []
for cnt in range(0,w_cnt,1):
s_list.append(word_list[cnt][0])
e_list.append(word_list[cnt][-1])
judge = "YES"
for cnt in range(1,w_cnt,1):
if s_list[cnt] != e_list[cnt-1]:
judge = "NO"
print(judge)
|
s427105513
|
p02831
|
u357630630
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 112 |
Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
|
A, B = map(int, input().split())
for i in range(B):
if A * i % B == 0:
print(A * i)
exit(0)
|
s105176680
|
Accepted
| 38 | 2,940 | 124 |
A, B = map(int, input().split())
i = 1
while True:
if (A * i) % B == 0:
print(A * i)
exit(0)
i += 1
|
s042654745
|
p03854
|
u518064858
| 2,000 | 262,144 |
Wrong Answer
| 19 | 3,188 | 102 |
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
|
s=input()
print(s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream",""))
|
s799771475
|
Accepted
| 19 | 3,188 | 152 |
s=input()
S=s.replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if len(S)==0:
print("YES")
else:
print("NO")
|
s343260633
|
p03698
|
u240793404
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 65 |
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
|
s = input()
a = set(s)
print("Yes" if len(s) == len(a) else "No")
|
s128124060
|
Accepted
| 17 | 2,940 | 65 |
s = input()
a = set(s)
print("yes" if len(s) == len(a) else "no")
|
s187888148
|
p03480
|
u786020649
| 2,000 | 262,144 |
Wrong Answer
| 34 | 10,924 | 146 |
You are given a string S consisting of `0` and `1`. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into `0` by repeating the following operation some number of times. * Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is `0`, replace it with `1`; if S_i is `1`, replace it with `0`.
|
import sys
readline=sys.stdin.readline
s=readline().strip()
s=s.replace('01','0 1')
s=s.replace('10','1 0')
s=s.split()
print(max(map(len,s)))
|
s446778169
|
Accepted
| 47 | 9,860 | 215 |
import sys
readline=sys.stdin.readline
s=list(readline().strip())
n=len(s)
f=n%2
mid=s[n//2]
for i in range(n//2):
if s[n//2-i-1]!=mid or s[(n+1)//2+i]!=mid:
print((n+1)//2+i)
break
else:
print(n)
|
s303712332
|
p03456
|
u410118019
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 106 |
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
|
a,b=map(int,input().split())
c=int(str(a)+str(b))
if type(c**0.5)==int:
print('Yes')
else:
print('No')
|
s432192024
|
Accepted
| 18 | 2,940 | 150 |
a,b=map(int,input().split())
c=int(str(a)+str(b))
d=0
for num in range(317):
if num**2==c:
d=1
print('Yes')
break
if d==0:
print('No')
|
s514861376
|
p02647
|
u136843617
| 2,000 | 1,048,576 |
Wrong Answer
| 2,207 | 51,544 | 381 |
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row: * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i. Find the intensity of each bulb after the K operations.
|
import numpy as np
def solve():
N,K = map(int, input().split())
A = list(map(int, input().split()))
br = np.zeros(N, dtype=np.int64)
for i in range(K):
br = np.zeros(N, dtype=np.int64)
for ind, rux in enumerate(A):
br[max(ind-rux,0) : min(ind+rux+1,N+1)] += 1
print(br)
A = br
if __name__ == "__main__":
solve()
|
s222126899
|
Accepted
| 708 | 128,936 | 547 |
import numpy as np
from numba import njit
@njit('i8,i8,i8[::1]',cache=True)
def solve(N,K,A):
for i in range(K):
br = np.zeros(N+1, dtype=np.int64)
for ind, rux in enumerate(A):
br[max(ind-rux,0)] += 1
br[min(ind+rux+1,N)] -= 1
A = br.cumsum()[:-1]
if br[0] == N and br[-1] == -N:
return A
return A
if __name__ == "__main__":
n,k = map(int, input().split())
a = np.array(list(map(int, input().split())),dtype=np.int64)
ans = solve(n,k,a)
print(*ans)
|
s597062308
|
p02408
|
u447630054
| 1,000 | 131,072 |
Wrong Answer
| 30 | 6,720 | 395 |
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.
|
cards = {
'S': [r for r in range(1,13+1)],
'H': [r for r in range(1,13+1)],
'C': [r for r in range(1,13+1)],
'D': [r for r in range(1,13+1)],
}
n = int(input())
for nc in range(n):
(s, r) = input().split()
index = cards[s].index(int(r))
del cards[s][index]
for s in ['S', 'H', 'C', 'D']:
for r in cards[s]:
print(s, r)
|
s602257261
|
Accepted
| 30 | 6,724 | 366 |
cards = {
'S':[0 for _ in range(13)],
'H':[0 for _ in range(13)],
'C':[0 for _ in range(13)],
'D':[0 for _ in range(13)],
}
n = int(input())
for _ in range(n):
(s, r) = input().split()
cards[s][int(r) - 1] = 1
for s in ['S','H','C','D']:
for r in range(13):
if cards[s][r] == 0:
print(s, r+1)
|
s162548178
|
p03798
|
u839537730
| 2,000 | 262,144 |
Wrong Answer
| 251 | 3,572 | 1,275 |
Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1. There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies. Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is `o`, the animal said that the two neighboring animals are of the same species, and if s_i is `x`, the animal said that the two neighboring animals are of different species. More formally, a sheep answered `o` if the two neighboring animals are both sheep or both wolves, and answered `x` otherwise. Similarly, a wolf answered `x` if the two neighboring animals are both sheep or both wolves, and answered `o` otherwise. Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print `-1`.
|
N = int(input())
s = input()
ans_first = ["SS", "SW", "WS", "WW"]
cand_oo = ["SSSS", "SWWS", "WWSW", "WSWW"]
cand_ox = ["SSSW", "SWWW", "WWSS", "SSWS"]
cand_xo = ["WSSS", "WWWS", "SWSW", "SSWW"]
cand_xx = ["WSSW", "WWWW", "SWSS", "WSWS"]
answered = False
for a in ans_first:
for i in range(1, N-1):
if (s[i] == "o" and a[i] == "S") or (s[i] == "x" and a[i] == "W"):
a = a + a[i-1]
elif (s[i] == "o" and a[i] == "W") or (s[i] == "x" and a[i] == "S") :
if a[i-1] == "S":
a = a + "W"
else:
a = a + "S"
if s[-1] + s[0] == "oo":
for can in cand_oo:
if can == a[-2:] + a[:2]:
print(a)
break
elif s[-1] + s[0] == "ox":
for can in cand_ox:
if can == a[-2:] + a[:2]:
print(a)
break
elif s[-1] + s[0] == "xo":
for can in cand_xo:
if can == a[-2:] + a[:2]:
print(a)
break
elif s[-1] + s[0] == "xx":
for can in cand_xx:
if can == a[-2:] + a[:2]:
print(a)
break
if answered == False:
print(-1)
|
s920806825
|
Accepted
| 253 | 3,572 | 1,460 |
N = int(input())
s = input()
ans_first = ["SS", "SW", "WS", "WW"]
cand_oo = ["SSSS", "SWWS", "WWSW", "WSWW"]
cand_ox = ["SSSW", "SWWW", "WWSS", "SSWS"]
cand_xo = ["WSSS", "WWWS", "SWSW", "SSWW"]
cand_xx = ["WSSW", "WWWW", "SWSS", "WSWS"]
answered = False
for a in ans_first:
if answered == True:
break
for i in range(1, N-1):
if (s[i] == "o" and a[i] == "S") or (s[i] == "x" and a[i] == "W"):
a = a + a[i-1]
elif (s[i] == "o" and a[i] == "W") or (s[i] == "x" and a[i] == "S") :
if a[i-1] == "S":
a = a + "W"
else:
a = a + "S"
if s[-1] + s[0] == "oo":
for can in cand_oo:
if can == a[-2:] + a[:2]:
print(a)
answered = True
break
elif s[-1] + s[0] == "ox":
for can in cand_ox:
if can == a[-2:] + a[:2]:
print(a)
answered = True
break
elif s[-1] + s[0] == "xo":
for can in cand_xo:
if can == a[-2:] + a[:2]:
print(a)
answered = True
break
elif s[-1] + s[0] == "xx":
for can in cand_xx:
if can == a[-2:] + a[:2]:
print(a)
answered = True
break
if answered == False:
print(-1)
|
s271529374
|
p02617
|
u197457087
| 2,000 | 1,048,576 |
Wrong Answer
| 600 | 54,704 | 326 |
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i. For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows: * Let S be the set of the vertices numbered L through R. f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S. Compute \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R).
|
N = int(input())
es = [[] for _ in range(N)]
H = []
for i in range(N-1):
a,b = map(int,input().split())
if a > b:
a,b = b,a
a-=1;b-=1
#es[a].append(b)
#es[b].append(a)
H.append([a,b])
print(es)
ten = N*(N+1)*(N+2)//6
hen = 0
for i in range(N-1):
p,q = H[i]
hen += (p+1)*(N-1-q+1)
ans = ten -hen
print(ans)
|
s975562385
|
Accepted
| 574 | 53,448 | 316 |
N = int(input())
es = [[] for _ in range(N)]
H = []
for i in range(N-1):
a,b = map(int,input().split())
if a > b:
a,b = b,a
a-=1;b-=1
#es[a].append(b)
#es[b].append(a)
H.append([a,b])
ten = N*(N+1)*(N+2)//6
hen = 0
for i in range(N-1):
p,q = H[i]
hen += (p+1)*(N-1-q+1)
ans = ten -hen
print(ans)
|
s160681825
|
p03795
|
u864667985
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 38 |
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
n=int(input())
print(n*80-200*(n//15))
|
s830600823
|
Accepted
| 17 | 2,940 | 39 |
n=int(input())
print(n*800-200*(n//15))
|
s519358517
|
p03457
|
u673355261
| 2,000 | 262,144 |
Wrong Answer
| 457 | 32,884 | 388 |
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.
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
L.insert(0, [0, 0, 0])
print(N, L)
for i in range(1, len(L)):
t = L[i][0] - L[i-1][0]
x = L[i][1] - L[i-1][1]
y = L[i][2] - L[i-1][2]
num = t - abs(x) - abs(y)
if num < 0 or num % 2:
print('No')
sys.exit()
print('Yes')
|
s911187398
|
Accepted
| 415 | 27,300 | 376 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
L.insert(0, [0, 0, 0])
for i in range(1, len(L)):
t = L[i][0] - L[i-1][0]
x = L[i][1] - L[i-1][1]
y = L[i][2] - L[i-1][2]
num = t - abs(x) - abs(y)
if num < 0 or num % 2:
print('No')
sys.exit()
print('Yes')
|
s248416376
|
p03605
|
u617525345
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 93 |
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
N = int(input())
a = N/10
b = N-10*a
if a == 9 or b == 9:
print('Yes')
else:
print('No')
|
s126260548
|
Accepted
| 17 | 2,940 | 128 |
N = int(input())
a = int(N/10)
b = N%10
#print(N)
#print(a)
#print(b)
if a == 9 or b == 9:
print('Yes')
else:
print('No')
|
s641331105
|
p02255
|
u728137020
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,596 | 390 |
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
n=int(input())
def insertionSort(A,N):
for i in range(1,N):
v=A[i]
j=i-1
while j>=0 and A[j]>v:
A[j+1]=A[j]
j=j-1
A[j+1]=v
for i in range(len(A)):
if i!=len(A)-1:
print(A[i],end=' ')
else :
print(A[i])
list=list(map(int,input().split()))
insertionSort(list,n)
|
s227400991
|
Accepted
| 30 | 5,980 | 443 |
n=int(input())
list=list(map(int,input().split()))
for i2 in range(len(list)):
if i2!=len(list)-1:
print(list[i2],end=' ')
else :
print(list[i2])
for i in range(1,n):
v=list[i]
j=i-1
while j>=0 and list[j]>v:
list[j+1]=list[j]
j=j-1
list[j+1]=v
for i2 in range(len(list)):
if i2!=len(list)-1:
print(list[i2],end=' ')
else :
print(list[i2])
|
s543283678
|
p04029
|
u103341055
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 68 |
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
N = int(input())
C = 0
for i in range(1,N+1):
C += 1
print(C)
|
s084347174
|
Accepted
| 17 | 3,060 | 118 |
N = int(input())
def Counter(n):
if n <= 0:
return n
return n + Counter(n-1)
print(Counter(N))
|
s955491451
|
p03679
|
u410118019
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 88 |
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
|
x,a,b=map(int,input().split())
if b-a>x:
print("delicious")
else:
print("dangerous")
|
s943626165
|
Accepted
| 17 | 2,940 | 118 |
x,a,b = map(int,input().split())
if b<=a:
print('delicious')
elif b<=a+x:
print('safe')
else:
print('dangerous')
|
s812971485
|
p02467
|
u445032255
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,592 | 363 |
Factorize a given integer n.
|
def main():
n = int(input())
primes = []
factor = 2
while True:
if n == 1:
break
if n % factor == 0:
n //= factor
primes.append(factor)
continue
else:
factor += 1
print("{}: {}".format(
n,
" ".join(list(map(str, primes)))
))
main()
|
s326387365
|
Accepted
| 20 | 5,680 | 657 |
import math
def make_divisors(n):
divisors = []
for k in range(2, math.floor(math.sqrt(n))+1):
if n % k == 0:
divisors.append(k)
divisors.append(n // k)
divisors.append(n)
return sorted(divisors)
def main():
n = int(input())
original_n = n
factors = []
divisors = make_divisors(n)
i = 0
while True:
if n == 1:
break
if n % divisors[i] == 0:
n //= divisors[i]
factors.append(divisors[i])
else:
i += 1
print("{}: {}".format(
original_n,
" ".join(list(map(str, factors)))
))
main()
|
s655686919
|
p00034
|
u905313459
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,544 | 246 |
複線(上りと下りが別の線路になっていてどこででもすれ違える)の鉄道路線があります。この路線には終端駅を含めて11 の駅があり、それぞれの駅と駅の間は図で示す区間番号で呼ばれています。 この路線の両方の終端駅から列車が同時に出発して、途中で停まらずに走ります。各区間の長さと2 本の列車の速度を読み込んで、それぞれの場合について列車がすれ違う区間の番号を出力するプログラムを作成してください。ただし、ちょうど駅のところですれ違う場合は、両側の区間番号のうち小さいほうの数字を出力します。また、列車の長さ、駅の長さは無視できるものとします。
|
import sys
for line in sys.stdin:
v = list(map(int, line.split(",")))
k = [sum(v[:i]) for i,j in enumerate(v[:-1])]
l = v[-2]/(v[-1]+v[-2]) * k[-1]
n = [a-l if a-l >= 0 else 1e10 for a in k]
print(n)
print(n.index(min(n)))
|
s212297634
|
Accepted
| 20 | 7,596 | 233 |
import sys
for line in sys.stdin:
v = list(map(int, line.split(",")))
k = [sum(v[:i]) for i,j in enumerate(v[:-1])]
l = v[-2]/(v[-1]+v[-2]) * k[-1]
n = [a-l if a-l >= 0 else 1e10 for a in k]
print(n.index(min(n)))
|
s061718356
|
p03474
|
u030879708
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 216 |
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen `-`, and the other characters are digits from `0` through `9`. You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.
|
A,B=map(int, input().split())
S=input()
flag=True
if S[A]!='-':
flag=False
a=S[:A]
b=S[A+1:]
print(a)
print(b)
if not(a.isdigit() and b.isdigit()):
flag=False
if flag:
print('Yes')
else:
print('No')
|
s068785385
|
Accepted
| 17 | 3,060 | 198 |
A,B=map(int, input().split())
S=input()
flag=True
if S[A]!='-':
flag=False
a=S[:A]
b=S[A+1:]
if not(a.isdigit() and b.isdigit()):
flag=False
if flag:
print('Yes')
else:
print('No')
|
s896727160
|
p03469
|
u086503932
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 32 |
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
|
s=input();print(s[:2]+'8'+s[4:])
|
s834437025
|
Accepted
| 19 | 2,940 | 33 |
s=input();print(s[:3]+'8'+s[4:])
|
s491208128
|
p02796
|
u370721525
| 2,000 | 1,048,576 |
Wrong Answer
| 826 | 56,272 | 377 |
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
|
import numpy as np
N = int(input())
nums = [list(map(int, input().split())) for _ in range(N)]
for row in nums:
row.append(row[0]+row[1])
row.append(row[0]-row[1])
print(nums)
nums.sort(key=lambda x: x[2])
ans = N
point = nums[0][2]
for j in range(N-1):
if nums[j+1][3] < point:
ans -= 1
print(nums[j+1][3], nums[j][2])
else:
point = nums[j][2]
print(ans)
|
s440374500
|
Accepted
| 303 | 25,336 | 243 |
N = int(input())
l = []
for i in range(N):
X, L = map(int, input().split())
l.append([X-L, X+L])
l.sort(key=lambda x: x[1])
pin = l[0][1]
ans = 1
for i in range(1, N):
if pin <= l[i][0]:
ans += 1
pin = l[i][1]
print(ans)
|
s491435575
|
p03861
|
u507116804
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 89 |
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())
m=a//x
n=b//x
if n==0:
print(m-n+1)
else:
print(m-n)
|
s109243720
|
Accepted
| 17 | 2,940 | 95 |
a,b,x=map(int,input().split())
m=b//x
n=a//x
k=a%x
if k==0:
print(m-n+1)
else:
print(m-n)
|
s207525766
|
p00005
|
u175111751
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,568 | 262 |
Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b.
|
def gcd(a, b):
if a == 0 or b == 0:
return 0
while b != 0:
a, b = b, a%b
return a
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
else:
g = gcd(a,b)
print(g, a*b/g)
|
s229235272
|
Accepted
| 20 | 7,604 | 263 |
def gcd(a, b):
if a == 0 or b == 0:
return 0
while b != 0:
a, b = b, a%b
return a
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
else:
g = gcd(a,b)
print(g, a*b//g)
|
s383951289
|
p03672
|
u266874640
| 2,000 | 262,144 |
Wrong Answer
| 19 | 3,060 | 284 |
We will call a string that can be obtained by concatenating two equal strings an _even_ string. For example, `xyzxyz` and `aaaaaa` are even, while `ababab` and `xyzxy` are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S. It is guaranteed that such a non-empty string exists for a given input.
|
s = input()
s_list = []
for i in s:
s_list.append(i)
del s_list[-1]
while True:
s_half = int(len(s_list)/2)
s1 = s_list[:s_half]
s2 = s_list[s_half:]
print(s1)
print(s2)
if s1 == s2:
print(s_half*2)
break
else:
del s_list[-1]
|
s297849746
|
Accepted
| 17 | 3,060 | 256 |
s = input()
s_list = []
for i in s:
s_list.append(i)
del s_list[-1]
while True:
s_half = int(len(s_list)/2)
s1 = s_list[:s_half]
s2 = s_list[s_half:]
if s1 == s2:
print(s_half*2)
break
else:
del s_list[-1]
|
s104615207
|
p03997
|
u981206782
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 63 |
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively. An example of a trapezoid Find the area of this trapezoid.
|
a=int(input())
b=int(input())
h=int(input())
print(((a+b)*h)/2)
|
s035216931
|
Accepted
| 17 | 2,940 | 68 |
a=int(input())
b=int(input())
h=int(input())
print(int(((a+b)*h)/2))
|
s005224462
|
p04043
|
u452015170
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 105 |
Iroha loves _Haiku_. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.
|
a, b,c = map(int, input().split())
if [5,5,7] == [a,b,c].sort() :
print("YES")
else :
print("NO")
|
s124469541
|
Accepted
| 17 | 2,940 | 114 |
a, b,c = map(int, input().split())
list = sorted([a,b,c])
if [5,5,7] == list :
print("YES")
else :
print("NO")
|
s744850821
|
p02694
|
u529272843
| 2,000 | 1,048,576 |
Wrong Answer
| 2,205 | 9,164 | 74 |
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
|
x=int(input())
year=0
for i in range(0,x+1):
year+=(x*1/100)
print(year)
|
s584061752
|
Accepted
| 21 | 9,192 | 101 |
x=int(input())
c=100
year=0
while (c<=x):
if(c==x):
break
year+=1
c+=(c*1//100)
print(year)
|
s869090298
|
p03729
|
u532966492
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 69 |
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();print("YNeos"[a[-1]!=b[0] or b[-1]!=c[0]::2])
|
s015596460
|
Accepted
| 17 | 2,940 | 69 |
a,b,c = input().split();print("YNEOS"[a[-1]!=b[0] or b[-1]!=c[0]::2])
|
s675240523
|
p03067
|
u513094698
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 112 |
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
|
a,b,c = map(int, input().split())
l = [a,b,c]
if (min(l)==c)|(max(l)==c):
print('Yes')
else:
print('No')
|
s747857102
|
Accepted
| 17 | 2,940 | 112 |
a,b,c = map(int, input().split())
l = [a,b,c]
if (min(l)==c)|(max(l)==c):
print('No')
else:
print('Yes')
|
s827809396
|
p03605
|
u652656291
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 78 |
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
s = str(input())
if s[0]=='9' or s[1]=='9':
print('YES')
else:
print('NO')
|
s529813458
|
Accepted
| 18 | 2,940 | 78 |
s = str(input())
if s[0]=='9' or s[1]=='9':
print('Yes')
else:
print('No')
|
s328062915
|
p03673
|
u227085629
| 2,000 | 262,144 |
Wrong Answer
| 2,104 | 26,020 | 181 |
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
|
n = int(input())
a = list(map(int,input().split()))
ans = []
for i in range(n):
if i%2 == 0:
ans.append(a[i])
else:
ans.insert(0,a[i])
for an in ans:
print(an,end=' ')
|
s571461374
|
Accepted
| 164 | 33,940 | 261 |
n = int(input())
a = list(map(int,input().split()))
odd = []
even = []
o = 0
e = 1
while o < n:
odd.append(str(a[o]))
o += 2
while e < n:
even.append(str(a[e]))
e += 2
if n%2 == 0:
ans = even[::-1]+odd
else:
ans = odd[::-1]+even
print(' '.join(ans))
|
s319165128
|
p02612
|
u014139588
| 2,000 | 1,048,576 |
Wrong Answer
| 27 | 9,148 | 38 |
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
|
n = int(input())
print(n-n//1000*1000)
|
s275248499
|
Accepted
| 33 | 9,084 | 67 |
n = int(input())
print(1000-(n-n//1000*1000) if n%1000 != 0 else 0)
|
s153123533
|
p00004
|
u553148578
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,608 | 146 |
Write a program which solve a simultaneous equation: ax + by = c dx + ey = f The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b, c, d, e, f ≤ 1,000). You can suppose that given equation has a unique solution.
|
while True:
try:
a,b,c,d,e,f = map(int, input().split())
x = (c*d-a*f)/(b*d-a*e)
print("{:.3f} {:.3f}".format(x,c-b*x/a))
except:
break
|
s232814476
|
Accepted
| 20 | 5,612 | 150 |
while True:
try:
a,b,c,d,e,f = map(int, input().split())
x = (c*d-a*f)/(b*d-a*e)
print("{:.3f} {:.3f}".format((c-b*x)/a, x))
except:
break
|
s400292072
|
p03592
|
u075012704
| 2,000 | 262,144 |
Wrong Answer
| 274 | 3,060 | 146 |
We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
|
N, M, K = map(int, input().split())
cnt = 1
for i in range(100000):
cnt *= 2
if cnt == K:
print("Yes")
else:
print("No")
|
s564815337
|
Accepted
| 276 | 2,940 | 175 |
N, M, K = map(int, input().split())
for i in range(N+1):
for j in range(M+1):
if K == (N-i)*j + (M-j)*i:
print("Yes")
exit()
print("No")
|
s193095379
|
p04030
|
u859897687
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 147 |
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?
|
n =input()
ans=""
for i in range(len(n)):
if n[i] == " ":
if ans:
ans = ans[:-1]
else:
ans +=n[i]
print(ans)
|
s817198177
|
Accepted
| 17 | 2,940 | 147 |
n =input()
ans=""
for i in range(len(n)):
if n[i] == "B":
if ans:
ans = ans[:-1]
else:
ans +=n[i]
print(ans)
|
s722161458
|
p03737
|
u272377260
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 66 |
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words.
|
s1, s2, s3 = input().capitalize().split()
print(s1[0]+s2[0]+s3[0])
|
s301722087
|
Accepted
| 18 | 2,940 | 61 |
s1, s2, s3 = input().upper().split()
print(s1[0]+s2[0]+s3[0])
|
s471861195
|
p02557
|
u098012509
| 2,000 | 1,048,576 |
Wrong Answer
| 250 | 57,664 | 670 |
Given are two sequences A and B, both of length N. A and B are each sorted in the ascending order. Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.
|
import sys
import collections
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ac = collections.Counter(A)
bc = collections.Counter(B)
for k in ac.keys():
if N - bc[k] < ac[k]:
print("No")
return
ans = []
q = collections.deque()
print("Yes")
for i in range(N):
b = B.pop()
if A[i] != b:
ans.append(b)
else:
c = B.pop()
ans.append(c)
B.append(b)
print(*ans)
if __name__ == '__main__':
main()
|
s329707486
|
Accepted
| 337 | 57,884 | 637 |
import sys
import collections
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def main():
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ac = collections.Counter(A)
bc = collections.Counter(B)
for i in range(1, N + 1):
if ac[i] + bc[i] > N:
print("No")
return
ma = 0
cnta = 0
cntb = 0
for i in range(1, N + 1):
cnta += ac[i]
cntb += bc[i - 1]
ma = max(ma, cnta - cntb)
print("Yes")
ans = B[N - ma:] + B[:N - ma]
print(*ans)
if __name__ == '__main__':
main()
|
s772550548
|
p02401
|
u547492399
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,340 | 85 |
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
while True:
t = input()
if t.find("?") > 0:
break
print(eval(t))
|
s024717360
|
Accepted
| 20 | 7,348 | 89 |
while True:
t = input()
if t.find("?") > 0:
break
print(int(eval(t)))
|
s413379844
|
p00123
|
u214404619
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,436 | 375 |
スピードスケートバッジテストでは、2 種類の距離で規定されたタイムを上回った場合に級が認定されます。例えば A 級になるには 500 M で 40.0 秒未満、かつ 1000 M で 1 分 23 秒未満であることが求められます。 スピードスケート大会 (500 M と 1000 M) で記録したタイムを入力とし、スピードスケートバッジテストで何級に相当するかを出力するプログラムを作成して下さい。500 M と1000 M のバッジテスト規定タイムは下表のとおりです。 E 級に満たなかった場合には、NA と出力してください。 | 500 M| 1000 M ---|---|--- AAA 級| 35 秒 50| 1 分 11 秒 00 AA 級 | 37 秒 50| 1 分 17 秒 00 A 級 | 40 秒 00| 1 分 23 秒 00 B 級 | 43 秒 00| 1 分 29 秒 00 C 級 | 50 秒 00| 1 分 45 秒 00 D 級 | 55 秒 00| 1 分 56 秒 00 E 級 | 1分10 秒 00 | 2 分 28 秒 00
|
[a, b] = [float(num) for num in input().split()];
if (a < 35.5) & (b < 71.0):
print('AAA');
elif (a < 37.5) & (b < 77.0):
print('AA');
elif (a < 40.0) & (b < 83.0):
print('A');
elif (a < 43.0) & (b < 89.0):
print('B');
elif (a < 50.0) & (b < 105.0):
print('C');
elif (a < 55.0) & (b < 116.0):
print('D');
elif (a < 70.0) & (b < 148.0):
print('E');
else:
print('NA');
|
s390059377
|
Accepted
| 30 | 7,392 | 431 |
import sys
for line in sys.stdin:
[p, q] = line.split();
a = float(p);
b = float(q);
if (a < 35.5) & (b < 71.0):
print('AAA');
elif (a < 37.5) & (b < 77.0):
print('AA');
elif (a < 40.0) & (b < 83.0):
print('A');
elif (a < 43.0) & (b < 89.0):
print('B');
elif (a < 50.0) & (b < 105.0):
print('C');
elif (a < 55.0) & (b < 116.0):
print('D');
elif (a < 70.0) & (b < 148.0):
print('E');
else:
print('NA');
|
s877515530
|
p02255
|
u867503285
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,652 | 517 |
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
|
def insertion_sort(target_list):
'????????????????????????????????\???????????§??????????????????????????¨?????????'
sorted_list = list()
for target in target_list[:]:
for i, num in enumerate(sorted_list):
if num > target:
sorted_list[i:i] = [target]
break
else:
sorted_list.append(target)
target_list.pop(0)
print(sorted_list + target_list)
N = int(input())
A = [int(s) for s in input().split()]
insertion_sort(A)
|
s725382810
|
Accepted
| 30 | 7,740 | 453 |
def insertion_sort(target_list):
sorted_list = list()
for target in target_list[:]:
for i, num in enumerate(sorted_list):
if num > target:
sorted_list[i:i] = [target]
break
else:
sorted_list.append(target)
target_list.pop(0)
print(' '.join(str(s) for s in sorted_list + target_list))
N = int(input())
A = [int(s) for s in input().split()]
insertion_sort(A)
|
s234145028
|
p02278
|
u724548524
| 1,000 | 131,072 |
Wrong Answer
| 30 | 6,340 | 624 |
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number of times. Write a program which reports the minimal total cost to sort the given integers.
|
import copy
n = int(input())
a = list(map(int, input().split()))
b = copy.deepcopy(a)
b.sort()
loop = []
minp = min(a)
t = [0 for i in range(n)]
while True:
i = t.index(0)
j = len(loop)
loop.append([a[i]])
t[i] = 1
while True:
i = b.index(a[i])
if t[i] == 1:
break
t[i] = 1
loop[j].append(a[i])
if sum(t) == n:
break
j += 1
print(loop)
cost = 0
for i in loop:
if len(i) == 1:
continue
ps = sum(i)
pl = len(i)
pm = min(i)
p1 = ps + (pl - 2) * pm
p2 = ps + pm + (pl + 1) * minp
cost += min(p1, p2)
print(cost)
|
s007895523
|
Accepted
| 70 | 6,384 | 612 |
import copy
n = int(input())
a = list(map(int, input().split()))
b = copy.deepcopy(a)
b.sort()
loop = []
minp = min(a)
t = [0 for i in range(n)]
while True:
i = t.index(0)
j = len(loop)
loop.append([a[i]])
t[i] = 1
while True:
i = b.index(a[i])
if t[i] == 1:
break
t[i] = 1
loop[j].append(a[i])
if sum(t) == n:
break
j += 1
cost = 0
for i in loop:
if len(i) == 1:
continue
ps = sum(i)
pl = len(i)
pm = min(i)
p1 = ps + (pl - 2) * pm
p2 = ps + pm + (pl + 1) * minp
cost += min(p1, p2)
print(cost)
|
s349844954
|
p02842
|
u738898077
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 98 |
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())
if n // 1.08 == int((n // 1.08) * 1.08):
print(n//1.08)
else:
print(":(")
|
s726215574
|
Accepted
| 31 | 2,940 | 142 |
import sys
import math
n = int(input())
for i in range(n+1):
if math.floor(i * 1.08) == n:
print(i)
sys.exit()
print(":(")
|
s306017289
|
p03712
|
u633450100
| 2,000 | 262,144 |
Wrong Answer
| 30 | 9,144 | 156 |
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 = [int(i) for i in input().split()]
print('#' * (w + 2))
for i in range(h):
str = input()
str = '*' + str + '*'
print(str)
print('#' * (w + 2))
|
s247413602
|
Accepted
| 28 | 9,172 | 157 |
h,w = [int(i) for i in input().split()]
print('#' * (w + 2))
for i in range(h):
str = input()
str = '#' + str + '#'
print(str)
print('#' * (w + 2))
|
s412105159
|
p03494
|
u401487574
| 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.
|
lis = list(map(int,input().split()))
def counter(x):
count = 0
while x%2 ==0:
x = x/2
count += 1
return count
ans = 0
for i in lis:
if counter(i) > ans:
ans = counter(i)
print(counter(i))
|
s133905034
|
Accepted
| 21 | 3,060 | 177 |
def counter(a):
count = 0
while a%2 ==0:
a /= 2
count += 1
return count
N = int(input())
s = [int(n) for n in input().split()]
print(min([counter(a) for a in s]))
|
s170176695
|
p03971
|
u856232850
| 2,000 | 262,144 |
Wrong Answer
| 100 | 4,016 | 316 |
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
|
n,a,b = list(map(int,input().split()))
s = input()
for i in s:
if i == 'c':
print('no')
elif i == 'a' and (a+b>=1):
if a>0:
a -= 1
else:
b -= 1
print('yes')
elif i =='b' and b > 0:
b -= 1
print('yes')
else:
print('no')
|
s295464054
|
Accepted
| 95 | 4,016 | 316 |
n,a,b = list(map(int,input().split()))
s = input()
for i in s:
if i == 'c':
print('No')
elif i == 'a' and (a+b>=1):
if a>0:
a -= 1
else:
b -= 1
print('Yes')
elif i =='b' and b > 0:
b -= 1
print('Yes')
else:
print('No')
|
s858858083
|
p03494
|
u952708174
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 475 |
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
|
def b_shift_only(N, A):
a_min = float('inf')
for a in A:
if a % 2 == 1:
return 0
a_min = min(a_min, a)
ans = 0
while a_min % 2 == 0:
a_min //= 2
ans += 1
return ans
N = int(input())
A = [int(i) for i in input().split()]
print(b_shift_only(N, A))
|
s992981453
|
Accepted
| 17 | 3,060 | 374 |
def b_shift_only(N, A):
bitwise_or = 0
for a in A:
bitwise_or |= a
ans = 0
while bitwise_or % 2 == 0:
bitwise_or //= 2
ans += 1
return ans
N = int(input())
A = [int(i) for i in input().split()]
print(b_shift_only(N, A))
|
s837124375
|
p03711
|
u859897687
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 280 |
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
|
g1=[1,3,5,7,8,10,12]
g2=[4,6,9,11]
g3=[2]
a,b=map(int,input().split())
for i in g1:
if a==i:
n1=1
if b==i:
n2=2
for i in g2:
if a==i:
n1=2
if b==i:
n2=2
for i in g3:
if a==i:
n1=3
if b==i:
n2=3
if n1==n2:
print("Yes")
else:
print("No")
|
s755075625
|
Accepted
| 17 | 2,940 | 114 |
m=[1,3,1,2,1,2,1,1,2,1,2,1]
a,b=map(int,input().split())
if m[a-1]==m[b-1]:
print("Yes")
else:
print("No")
|
s954207430
|
p03962
|
u125269142
| 2,000 | 262,144 |
Wrong Answer
| 24 | 9,088 | 74 |
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
|
colors = list(map(int, input().split()))
kinds = set(colors)
print(kinds)
|
s423874364
|
Accepted
| 26 | 9,108 | 79 |
colors = list(map(int, input().split()))
kinds = len(set(colors))
print(kinds)
|
s199270549
|
p04029
|
u340947941
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 55 |
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
|
N=int(input())
print((N+1)*N/2)
|
s125764726
|
Accepted
| 17 | 2,940 | 60 |
N=int(input())
print(int((N+1)*N/2))
|
s117622120
|
p02401
|
u485986915
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,604 | 261 |
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part.
|
while True:
a,op,b = input().split()
A = int(a)
B = int(b)
if op == '?': break
elif op == '+':
print(A+B)
elif op == '-':
print(A-B)
elif op == '*':
print(A*B)
elif op == '/':
print(A/B)
|
s375369262
|
Accepted
| 20 | 5,596 | 254 |
while True:
a,op,b = input().split()
A = int(a)
B = int(b)
if op == '?': break
elif op == '+':
print(A+B)
elif op == '-':
print(A-B)
elif op == '*':
print(A*B)
elif op == '/':
print(A//B)
|
s876033836
|
p02613
|
u375234305
| 2,000 | 1,048,576 |
Wrong Answer
| 145 | 9,148 | 202 |
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.
|
data = {'AC':0,'WA':0,'TLE':0,'RE':0}
N = int(input())
for i in range(N):
inputSTR = input()
data[inputSTR] = data[inputSTR] + 1
for key,value in data.items():
print(key + ' × ' + str(value))
|
s356128326
|
Accepted
| 145 | 9,132 | 200 |
data = {'AC':0,'WA':0,'TLE':0,'RE':0}
N = int(input())
for i in range(N):
inputSTR = input()
data[inputSTR] = data[inputSTR] + 1
for key,value in data.items():
print(key + ' x ' + str(value))
|
s106846165
|
p03493
|
u249685005
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 90 |
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
str=list(input())
print(str)
s1=int(str[0])
s2=int(str[1])
s3=int(str[2])
print(s1+s2+s3)
|
s289867194
|
Accepted
| 17 | 2,940 | 79 |
str=list(input())
s1=int(str[0])
s2=int(str[1])
s3=int(str[2])
print(s1+s2+s3)
|
s826335518
|
p03778
|
u994988729
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 90 |
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W. If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved.
|
w,a,b=map(int,input().split())
if a>b:
print(min(0, a-b-w))
else:
print(min(0, b-a-w))
|
s512557300
|
Accepted
| 17 | 3,060 | 143 |
w,a,b=map(int,input().split())
if a+w<=b:
print(b-a-w)
elif a<=b and b<=a+w:
print(0)
elif b<=a and a<=b+w:
print(0)
else:
print(a-b-w)
|
s923010997
|
p03998
|
u695811449
| 2,000 | 262,144 |
Wrong Answer
| 22 | 3,316 | 331 |
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.
|
from collections import deque
A=deque(input())
B=deque(input())
C=deque(input())
NOW="a"
while True:
#print(NOW,A,B,C)
if NOW=="a" and len(A)>=1:
NOW=A.popleft()
elif NOW=="b" and len(B)>=1:
NOW=B.popleft()
elif NOW=="c" and len(C)>=1:
NOW=C.popleft()
else:
break
print(NOW)
|
s628718782
|
Accepted
| 23 | 3,316 | 339 |
from collections import deque
A=deque(input())
B=deque(input())
C=deque(input())
NOW="a"
while True:
#print(NOW,A,B,C)
if NOW=="a" and len(A)>=1:
NOW=A.popleft()
elif NOW=="b" and len(B)>=1:
NOW=B.popleft()
elif NOW=="c" and len(C)>=1:
NOW=C.popleft()
else:
break
print(NOW.upper())
|
s915876861
|
p03587
|
u214380782
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 80 |
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not. You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem prepared by Snuke is accepted to be used; `0` means that the problem is not accepted. How many problems prepared by Snuke are accepted to be used in the contest?
|
s = input()
count = 0
for x in s:
if x == 1:
count += 1
print(count)
|
s393271224
|
Accepted
| 17 | 2,940 | 92 |
s = input()
count = 0
for i in range(6):
if s[i] == "1":
count += 1
print(count)
|
s519060775
|
p02258
|
u535719732
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,592 | 105 |
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ .
|
n = int(input())
r = []
for i in range(n):
r.append(int(input()))
diff = max(r) - min(r)
print(diff)
|
s155602560
|
Accepted
| 620 | 5,632 | 107 |
a,b = -1e11,1e11
for _ in range(int(input())):
c = int(input())
a,b = max(a,c-b),min(b,c)
print(a)
|
s419288429
|
p03436
|
u545411641
| 2,000 | 262,144 |
Wrong Answer
| 1,021 | 3,700 | 1,167 |
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j). Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares. Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game. When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares. The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is `.`; if square (i, j) is initially painted by black, s_{i, j} is `#`.
|
H, W = (int(i) for i in input().split())
S = []
for i in range(H):
row = input()
S.append([(0 if row[j]=="." else 1) for j in range(W)])
D = [[10000 for j in range(W)] for i in range(H)]
R = [[False for j in range(W)] for i in range(H)]
N_black = 0
for i in range(H):
for j in range(W):
if S[i][j] == 1:
D[i][j] == -1
R[i][j] == True
N_black += 1
def update(i0, j0, i1, j1):
global D
center = D[i0][j0]
adj = D[i1][j1]
r = R[i1][j1]
if adj != -1 and r == False and center + 1 < adj:
D[i1][j1] = center + 1
def check_around(i ,j):
# UP
if i != 0:
update(i, j, i-1, j)
# LEFT
if j != 0:
update(i, j, i, j-1)
# DOWN
if i != H-1:
update(i, j, i+1, j)
# RIGHT
if j != W-1:
update(i, j, i, j+1)
def minimum_point():
global H, W
m = 10000
ni = 0
nj = 0
for i in range(H):
for j in range(W):
d = D[i][j]
if d != -1 and R[i][j] == False and d < m:
m = d
ni = i
nj = j
return (ni, nj)
D[0][0] = 1
R[0][0] = True
pi = 0
pj = 0
for idx in range(W*H):
check_around(pi, pj)
pi, pj = minimum_point()
R[pi][pj] = True
print(pi, pj)
if D[H-1][W-1] == 10000:
print(-1)
else:
print(W*H-D[H-1][W-1]-N_black)
|
s825977663
|
Accepted
| 1,014 | 3,192 | 1,150 |
H, W = (int(i) for i in input().split())
S = []
for i in range(H):
row = input()
S.append([(0 if row[j]=="." else 1) for j in range(W)])
D = [[10000 for j in range(W)] for i in range(H)]
R = [[False for j in range(W)] for i in range(H)]
N_black = 0
for i in range(H):
for j in range(W):
if S[i][j] == 1:
D[i][j] = -1
R[i][j] = True
N_black += 1
def update(i0, j0, i1, j1):
global D
center = D[i0][j0]
adj = D[i1][j1]
r = R[i1][j1]
if adj != -1 and r == False and center + 1 < adj:
D[i1][j1] = center + 1
def check_around(i ,j):
# UP
if i != 0:
update(i, j, i-1, j)
# LEFT
if j != 0:
update(i, j, i, j-1)
# DOWN
if i != H-1:
update(i, j, i+1, j)
# RIGHT
if j != W-1:
update(i, j, i, j+1)
def minimum_point():
global H, W
m = 10001
ni = 0
nj = 0
for i in range(H):
for j in range(W):
d = D[i][j]
if d != -1 and R[i][j] == False and d < m:
m = d
ni = i
nj = j
return (ni, nj)
D[0][0] = 1
R[0][0] = True
pi = 0
pj = 0
for idx in range(W*H):
check_around(pi, pj)
pi, pj = minimum_point()
R[pi][pj] = True
if D[H-1][W-1] == 10000:
print(-1)
else:
print(W*H-D[H-1][W-1]-N_black)
|
s193404983
|
p03795
|
u740284863
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 60 |
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.
|
N = int(input())
cashback = N % 15
print(N*800-cashback*200)
|
s374389429
|
Accepted
| 18 | 2,940 | 61 |
N = int(input())
cashback = N // 15
print(N*800-cashback*200)
|
s627792263
|
p03545
|
u614314290
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,060 | 303 |
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.
|
# -*- coding: utf-8 -*-
def func(S):
for i in range(1 << 3):
v = S[0]
for j in range(3):
v += ("+" if i >> j & 0x01 else "-") + S[j + 1]
if eval(v) == 7:
return v + "=7"
def main():
print(func("1222"))
print(func("0290"))
print(func("3242"))
return
if __name__ == '__main__':
main()
|
s620015183
|
Accepted
| 18 | 2,940 | 159 |
S = input()
for i in range(8):
t = ""
for j in range(3):
t += S[j] + ["+", "-"][not (1 & i >> j)]
t += S[-1]
if 7 == eval(t):
print(t + "=7")
break
|
s196396036
|
p03493
|
u098834195
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 46 |
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i. Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.
|
s = list(input())
print(s)
print(s.count("1"))
|
s636185961
|
Accepted
| 17 | 2,940 | 37 |
s = list(input())
print(s.count("1"))
|
s575900714
|
p04000
|
u607563136
| 3,000 | 262,144 |
Wrong Answer
| 1,485 | 126,236 | 562 |
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?
|
h, w, n = map(int,input().split())
xy_pos = dict()
for i in range(n):
a, b = map(int, input().split())
for k in range(-2,1):
for l in range(-2,1):
x = (a-1) + k
y = (b-1) + l
if (0 <= x <=(h-1)-2) and (0 <= y <=(w-1)-2):
xy = str(x) + "x" + str(y)
if xy in xy_pos:
xy_pos[xy] += 1
else:
xy_pos[xy] = 1
ans = [0]*10
for v in xy_pos.values():
ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans)
print(ans)
|
s760232538
|
Accepted
| 1,453 | 126,228 | 589 |
h, w, n = map(int,input().split())
xy_pos = dict()
for i in range(n):
a, b = map(int, input().split())
for k in range(-2,1):
for l in range(-2,1):
x = (a-1) + k
y = (b-1) + l
if (0 <= x <=(h-1)-2) and (0 <= y <=(w-1)-2):
xy = str(x) + "x" + str(y)
if xy in xy_pos:
xy_pos[xy] += 1
else:
xy_pos[xy] = 1
ans = [0]*10
for v in xy_pos.values():
ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans)
for i in range(10):
print(ans[i])
|
s794072329
|
p00002
|
u905313459
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,604 | 147 |
Write a program which computes the digit number of sum of two integers a and b.
|
import fileinput
if __name__ == "__main__":
for line in fileinput.input():
v = line.split(" ")
print(sum([int(i) for i in v]))
|
s512932089
|
Accepted
| 30 | 7,604 | 157 |
import fileinput
if __name__ == "__main__":
for line in fileinput.input():
v = line.split(" ")
print(len(str(sum([int(i) for i in v]))))
|
s390686962
|
p03626
|
u528825252
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 285 |
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors. Find the number of such ways to paint the dominoes, modulo 1000000007. The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner: * Each domino is represented by a different English letter (lowercase or uppercase). * The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.
|
N = int(input())
S1 = input()
S2 = input()
result = 3
if N != 1:
i=1
while i < N:
if S1[i-1] == S2[i-1]:
result *= 2
elif S1[i-1] != S1[i]:
if S1[i] != S2[i]:
result *= 3
i += 1
print(result%1000000007)
|
s641105654
|
Accepted
| 17 | 3,064 | 325 |
N = int(input())
S1 = input()
S2 = input()
result = 3
if N != 1:
i=1
while i < N:
if S1[i-1] == S2[i-1]:
result *= 2
elif S1[i-1] != S1[i]:
if S1[i] != S2[i]:
result *= 3
elif i == 1:
result *= 2
i += 1
print(result%1000000007)
|
s914625325
|
p03623
|
u350997995
| 2,000 | 262,144 |
Wrong Answer
| 18 | 2,940 | 92 |
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
|
x,a,b = map(int,input().split())
if abs(x-a) > abs(x-b):
print("A")
else:
print("B")
|
s076821201
|
Accepted
| 18 | 2,940 | 92 |
x,a,b = map(int,input().split())
if abs(x-a) > abs(x-b):
print("B")
else:
print("A")
|
s084435601
|
p03644
|
u046136258
| 2,000 | 262,144 |
Wrong Answer
| 20 | 3,060 | 84 |
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.
|
li=[2,4,8,16,32,64,128]
n=int(input())
for i in li:
if n<i:
print(i//2)
|
s195397487
|
Accepted
| 17 | 2,940 | 131 |
li=[2,4,8,16,32,64,128]
n=int(input())
if n<2:
print(n)
quit()
for i in li:
if n<i:
print(i//2)
quit()
|
s546418601
|
p03826
|
u434148038
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 81 |
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area.
|
def a(a,b,c,d):
if a*b > c*d:
return a*b
else:
return c*d
|
s137209499
|
Accepted
| 17 | 2,940 | 55 |
a,b,c,d = map(int,input().split())
print(max(a*b, c*d))
|
s572354538
|
p02361
|
u397460030
| 3,000 | 131,072 |
Wrong Answer
| 30 | 7,828 | 763 |
For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path).
|
import heapq
l = input().split()
V = int(l[0])
E = int(l[1])
r = int(l[2])
graph = [[0 if i==j else -1 for j in range(V)] for i in range(V)] # [[source, target, cost]]
for i in range(E):
l = input().split()
graph[int(l[0])][int(l[1])] = int(l[2])
heap = [(0,r)]
dist = [float("inf") for _ in range(V)]
visited = [False for _ in range(V)]
while heap:
pop = heapq.heappop(heap)
if dist[pop[1]] > pop[0]:
dist[pop[1]] = pop[0]
edges = [(w,i) for (i,w) in enumerate(graph[pop[1]]) if i != pop[1] and w > 0 and not visited[i]]
for (weight, target) in edges:
heapq.heappush(heap, (pop[0]+weight, target))
visited[target] = True
for d in dist:
if d == float("inf"):
print("INF")
else:
print(d)
|
s068866572
|
Accepted
| 3,060 | 101,972 | 604 |
import heapq
l = input().split()
V = int(l[0])
E = int(l[1])
r = int(l[2])
graph = [[] for _ in range(V)]
for i in range(E):
l = input().split()
graph[int(l[0])].append((int(l[2]),int(l[1])))
heap = [(0,r)]
dist = [float("inf") for _ in range(V)]
while heap:
pop = heapq.heappop(heap)
if dist[pop[1]] < pop[0]:
continue
dist[pop[1]] = pop[0]
for (w,i) in graph[pop[1]]:
if i!= pop[1] and w >= 0 and dist[i] == float("inf"):
heapq.heappush(heap, (pop[0]+w, i))
for d in dist:
if d == float("inf"):
print("INF")
else:
print(d)
|
s438025609
|
p03693
|
u945065638
| 2,000 | 262,144 |
Wrong Answer
| 28 | 9,008 | 115 |
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())
ans = 100*r + 10 *g + b
if ans % 4 == 0:
print('Yes')
else :
print('No')
|
s183092333
|
Accepted
| 28 | 9,116 | 115 |
r, g, b = map(int,input().split())
ans = 100*r + 10 *g + b
if ans % 4 == 0:
print('YES')
else :
print('NO')
|
s472565720
|
p03400
|
u209620426
| 2,000 | 262,144 |
Wrong Answer
| 17 | 3,064 | 128 |
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
|
n = int(input())
d,x = map(int,input().split())
a = [int(input()) for i in range(n)]
c = 0
for i in a:
c += d//i
print(c+n)
|
s374835380
|
Accepted
| 17 | 2,940 | 139 |
n = int(input())
d,x = map(int,input().split())
a = [int(input()) for i in range(n)]
c = 0
for i in a:
c += d//i + (d%i!=0)
print(c+x)
|
s832004379
|
p02407
|
u605451279
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,588 | 122 |
Write a program which reads a sequence and prints it in the reverse order.
|
n = input()
l = input().split()
for a in l:
a = int(a)
x = list()
for i in (reversed(l)):
x.append(i)
print(x)
|
s272989465
|
Accepted
| 20 | 5,592 | 140 |
n = input()
l = input().split()
for a in l:
a = int(a)
x = list()
for i in (reversed(l)):
x.append(i)
x = ' '.join(x)
print(x)
|
s925476164
|
p02615
|
u884323674
| 2,000 | 1,048,576 |
Wrong Answer
| 167 | 31,596 | 136 |
Quickly after finishing the tutorial of the online game _ATChat_ , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the **friendliness** of Player i is A_i. The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets **comfort** equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0. What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?
|
N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
ans = 0
for i in range(N):
ans += A[i]
print(ans)
|
s409870294
|
Accepted
| 155 | 31,688 | 134 |
N = int(input())
A = sorted([int(i) for i in input().split()])
ans = 0
for i in range(1, N):
ans += A[(N-1) - (i // 2)]
print(ans)
|
s010047699
|
p03624
|
u535258729
| 2,000 | 262,144 |
Wrong Answer
| 30 | 4,004 | 157 |
You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
|
n = list(map(str, input()))
Alpha = 'abcdefghijklmnopqrstuvwxyz'
s = list(map(str, Alpha))
ans = 'None'
for i in s:
if i not in n:
ans = i
print(ans)
|
s535212384
|
Accepted
| 67 | 5,092 | 180 |
n = sorted(list(map(str, input())))
alpha = [chr(ord('a') + i) for i in range(26)]
ans = 'None'
for i in range(26):
if alpha[i] not in n:
ans = alpha[i]
break
print(ans)
|
s241285659
|
p03657
|
u713627549
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 132 |
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
|
a, b = map(int, input().split())
if a % 3 == 0 or b % 3 == 0 or a + b % 3 == 0:
print("Possible")
else:
print("Impossible")
|
s143324593
|
Accepted
| 17 | 2,940 | 133 |
a, b = map(int, input().split())
if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0:
print("Possible")
else:
print("Impossible")
|
s743087263
|
p03636
|
u037449077
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 219 |
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.
|
import sys
lines = sys.stdin.readlines()
res = ''
cnt = 0
for n, c in enumerate(lines[0]):
if n == 0:
res += c
elif n == len(lines[0]) - 1:
res += str(cnt)
res += c
else:
cnt += 1
print(res)
|
s019750062
|
Accepted
| 17 | 2,940 | 67 |
line = input()
print('{}{}{}'.format(line[0],len(line)-2,line[-1]))
|
s928065432
|
p03760
|
u535659144
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,060 | 160 |
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
|
o=list(input())
e=list(input())
p=[]
for a in range(len(o)-1):
p.append(o.pop(0))
p.append(e.pop(0))
if len(o):
p.append(o.pop(0))
print("".join(p))
|
s698571362
|
Accepted
| 17 | 3,060 | 149 |
o=list(input())
e=list(input())
p=[]
l=len(o)
while len(o)+len(e):
p.append(o.pop(0))
if len(e):
p.append(e.pop(0))
print("".join(p))
|
s947985253
|
p03605
|
u050641473
| 2,000 | 262,144 |
Wrong Answer
| 17 | 2,940 | 24 |
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
|
N = input()
print(N[1])
|
s211643838
|
Accepted
| 17 | 2,940 | 60 |
N = input()
if "9" in N:
print("Yes")
else:
print("No")
|
s282556043
|
p03160
|
u087443256
| 2,000 | 1,048,576 |
Wrong Answer
| 119 | 20,704 | 375 |
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N.
|
def solution(h):
n = len(h)
if n == 1:
return 0
elif n == 2:
return abs(h[1]-h[0])
dp = [0]*(n)
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
dp[i] = min( dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]) )
print(*dp)
return dp[n-1]
N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)
|
s582877665
|
Accepted
| 140 | 20,644 | 331 |
def solution(h):
n = len(h)
INF = float('inf')
dp = [INF]*n
dp[0] = 0
for i in range(n):
for j in range(i+1,i+3):
if j < n:
dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
return dp[n-1]
N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)
|
s906899727
|
p03339
|
u381246791
| 2,000 | 1,048,576 |
Wrong Answer
| 2,104 | 12,420 | 231 |
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
|
# -*- coding:utf-8 -*-
N=int(input())
S=input()
S=list(S)
number=0
ans=0
for i in range(N):
Left=S[:i]
Right=S[i+1:]
number+=Left.count('W')
number+=Right.count('E')
if ans>number:
ans=number
number=0
print(number)
|
s058214518
|
Accepted
| 300 | 29,260 | 297 |
# -*- coding:utf-8 -*-
N=int(input())
S=input()
S=list(S)
East_number=0
East=[]
for i in S:
if i=='E':
East_number+=1
East.append(East_number)
number=0
ans=[]
for i in range(N):
if i >0:
number+=i-East[i-1]
number+=East[N-1]-East[i]
ans.append(number)
number=0
print(min(ans))
|
s794413776
|
p03486
|
u979060189
| 2,000 | 262,144 |
Wrong Answer
| 18 | 3,064 | 606 |
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
|
s,t = map(str, [input() for i in range(2)])
S = [s[i] for i in range(len(s))]
T = [t[i] for i in range(len(t))]
def XY(x, y):
x.sort()
y.sort(reverse=True)
c = 0
D = True
while c < len(x) and c < len(y):
if x[c] < y[c]:
break
elif x[c] == y[c]:
c += 1
elif x[c] > y[c]:
D = False
break
if len(x) >= len(y) and c == len(y)-1 and x[c] >= y[c]:
D = False
return D
Result = XY(S, T)
if Result:
print('YES')
else:
print('NO')
|
s125532250
|
Accepted
| 18 | 3,064 | 551 |
s,t = map(str, [input() for i in range(2)])
S = [s[i] for i in range(len(s))]
T = [t[i] for i in range(len(t))]
def XY(x, y):
x.sort()
y.sort(reverse=True)
c = 0
D = True
while c < len(x) and c < len(y):
if x[c] < y[c]:
break
elif x[c] == y[c]:
c += 1
elif x[c] > y[c]:
D = False
break
if len(x) >= len(y) and c == len(y)-1 and x[c] >= y[c]:
D = False
return D
Result = XY(S, T)
if Result:
print('Yes')
else:
print('No')
|
s737936632
|
p02406
|
u986478725
| 1,000 | 131,072 |
Wrong Answer
| 20 | 5,596 | 286 |
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; }
|
def is_correct(i):
if i % 3 == 0: return True
while i > 0:
if i % 10 == 3: return True
i = i // 10
return False
def main():
n = int(input())
for i in range(1, n + 1):
if is_correct(i): print(' %d' % i)
if __name__ == "__main__":
main()
|
s074107892
|
Accepted
| 20 | 5,636 | 332 |
def is_correct(i):
if i % 3 == 0: return True
while i > 0:
if i % 10 == 3: return True
i = i // 10
return False
def main():
n = int(input())
answer = ""
for i in range(1, n + 1):
if is_correct(i): answer += " " + str(i)
print(answer)
if __name__ == "__main__":
main()
|
s335691443
|
p03502
|
u855057563
| 2,000 | 262,144 |
Wrong Answer
| 27 | 9,160 | 102 |
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
|
n=int(input())
c=0
for i in str(n):
c+=int(i)
if n%c==0:
print("Yes")
else:
print("No")
|
s213319329
|
Accepted
| 31 | 9,156 | 95 |
n=int(input())
c=0
for i in str(n):
c+=int(i)
if n%c==0:
print("Yes")
else:
print("No")
|
s363628901
|
p03386
|
u083960235
| 2,000 | 262,144 |
Wrong Answer
| 2,147 | 647,320 | 243 |
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())
l=[]
for i in range(A,B+1):
l.append(i)
print(l)
if 2*K>=len(l):
for i in l:
print(i)
else:
for i in l[0:K]:
print(i)
for i in l[B-A-1:B+1]:
print(i)
|
s358196753
|
Accepted
| 17 | 3,060 | 189 |
A,B,K=map(int,input().split())
l=[]
if 2*K>=B-A+1:
for i in range(A,B+1):
print(i)
else:
for i in range(K):
print(i+A)
for i in range(K):
print(B-K+1+i)
|
s157215355
|
p02419
|
u801346721
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,360 | 107 |
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
|
a = []
while 1:
s = input()
if s == 'END_OF_TEXT':
break
else:
a.append(s)
print(a.count(a[0]) - 1)
|
s014382424
|
Accepted
| 30 | 7,484 | 193 |
word = input()
counter = 0
while 1:
s = input()
if s == 'END_OF_TEXT':
break
else:
s = list(s.lower().split())
counter += s.count(word)
counter += s.count(word + '.')
print(counter)
|
s126762434
|
p02419
|
u731896389
| 1,000 | 131,072 |
Wrong Answer
| 20 | 7,532 | 72 |
Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
|
w = str(input())
t = [str(c) for c in input().split()]
print(t.count(w))
|
s435687086
|
Accepted
| 30 | 7,472 | 183 |
cnt = 0
s = input().lower()
while 1:
line = input()
if line == "END_OF_TEXT":
break
for w in line.lower().split():
if w == s:
cnt+=1
print(cnt)
|
s990807311
|
p03305
|
u364862909
| 2,000 | 1,048,576 |
Wrong Answer
| 1,862 | 71,796 | 1,789 |
Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n, and the i-th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains. Two currencies are used in the country: yen and snuuk. Any train fare can be paid by both yen and snuuk. The fare of the i-th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk. In a city with a money exchange office, you can change 1 yen into 1 snuuk. However, when you do a money exchange, you have to change all your yen into snuuk. That is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk. Currently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year. Kenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t, and change his yen into snuuk in some city while traveling. It is acceptable to do the exchange in City s or City t. Kenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange. For each i=0,...,n-1, find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years. You can assume that the trip finishes within the year.
|
from heapq import heapify,heappush,heappop
n,m,s,t = map(int,input().split())
adj_list = [[]for i in range(0,(n+1),1,)]
for i in range(0,m,1):
u,v,a,b = map(int,input().split())
adj_list[u].append([v,a,b])
adj_list[v].append([u,a,b])
D_INF = 10**15
d = [D_INF]*(n+1)
d[s] = 0
que = []
heapify(que)
heappush(que,(d[s],s))
while(len(que)):
time,place = heappop(que)
if time > d[place]:
continue
for i in range(0,len(adj_list[place]),1):
if d[adj_list[place][i][0]] > time + adj_list[place][i][1]:
d[adj_list[place][i][0]] = time + adj_list[place][i][1]
heappush(que,(d[adj_list[place][i][0]],adj_list[place][i][0]))
d_sn = [D_INF]*(n+1)
d_sn[t] = 0
heappush(que,(d_sn[t],t))
while(len(que)):
time,place = heappop(que)
if time > d_sn[place]:
continue
for i in range(0,len(adj_list[place]),1):
if d_sn[adj_list[place][i][0]] > time + adj_list[place][i][2]:
d_sn[adj_list[place][i][0]] = time + adj_list[place][i][2]
heappush(que,(d_sn[adj_list[place][i][0]],adj_list[place][i][0]))
print(d)
print(d_sn)
for i in range(1,n+1,1):
d[i]=d[i]+d_sn[i]
heappush(que,(d[i],i))
minimum,minimum_place = heappop(que)
print()
for i in range(0,n,1):
if minimum_place <= i:
while(len(que)):
minimum,minimum_place = heappop(que)
if minimum_place > i:
break
print(10**15-minimum)
|
s815839844
|
Accepted
| 1,639 | 67,956 | 1,759 |
from heapq import heapify,heappush,heappop
n,m,s,t = map(int,input().split())
adj_list = [[]for i in range(0,(n+1),1,)]
for i in range(0,m,1):
u,v,a,b = map(int,input().split())
adj_list[u].append([v,a,b])
adj_list[v].append([u,a,b])
D_INF = 10**15
d = [D_INF]*(n+1)
d[s] = 0
que = []
heapify(que)
heappush(que,(d[s],s))
while(len(que)):
time,place = heappop(que)
if time > d[place]:
continue
for i in range(0,len(adj_list[place]),1):
if d[adj_list[place][i][0]] > time + adj_list[place][i][1]:
d[adj_list[place][i][0]] = time + adj_list[place][i][1]
heappush(que,(d[adj_list[place][i][0]],adj_list[place][i][0]))
d_sn = [D_INF]*(n+1)
d_sn[t] = 0
heappush(que,(d_sn[t],t))
while(len(que)):
time,place = heappop(que)
if time > d_sn[place]:
continue
for i in range(0,len(adj_list[place]),1):
if d_sn[adj_list[place][i][0]] > time + adj_list[place][i][2]:
d_sn[adj_list[place][i][0]] = time + adj_list[place][i][2]
heappush(que,(d_sn[adj_list[place][i][0]],adj_list[place][i][0]))
for i in range(1,n+1,1):
d[i]=d[i]+d_sn[i]
heappush(que,(d[i],i))
minimum,minimum_place = heappop(que)
for i in range(0,n,1):
if minimum_place <= i:
while(len(que)):
minimum,minimum_place = heappop(que)
if minimum_place > i:
break
print(10**15-minimum)
|
s679849755
|
p03351
|
u829316025
| 2,000 | 1,048,576 |
Wrong Answer
| 17 | 2,940 | 164 |
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
|
a,b,c,d = map(int, input().split())
if abs(a-c)<=d:
print("yes")
else:
if abs(a-b)<=d and abs(b-c)<=d:
print("yes")
else:
print("no")
|
s200367072
|
Accepted
| 17 | 2,940 | 162 |
a,b,c,d = map(int, input().split())
if abs(a-c)<=d:
print("Yes")
else:
if abs(a-b)<=d and abs(b-c)<=d:
print("Yes")
else:
print("No")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.