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
s751550287
p02866
u367866606
2,000
1,048,576
Wrong Answer
45
14,396
363
Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition: * For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.
import sys n=int(input()) d=list(map(int,input().split())) num_d=[0 for i in range(n)] if d[0]!=0: print(0) sys.exit() for i in d: if i==0: print(0) sys.exit() num_d[i]+=1 max_d=0 ans=1 for i in range(1,n): if num_d[i]!=0: if max_d!=i-1: print(0) sys.exit() max_d=i ans*=num_d[i-1]**num_d[i] ans%=998244353 print(ans)
s823374534
Accepted
130
14,396
395
import sys n=int(input()) d=list(map(int,input().split())) num_d=[0 for i in range(n)] num_d[0]=1 if d[0]!=0: print(0) sys.exit() for i in range(1,len(d)): if d[i]==0: print(0) sys.exit() num_d[d[i]]+=1 max_d=0 ans=1 for i in range(1,n): if num_d[i]!=0: if max_d!=i-1: print(0) sys.exit() max_d=i ans*=num_d[i-1]**num_d[i] ans%=998244353 print(ans)
s282607318
p04043
u437638594
2,000
262,144
Wrong Answer
16
2,940
107
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 = sorted(map(len, input().split())) if [a, b, c] == [5, 5, 7]: print("YES") else: print("NO")
s132457560
Accepted
17
2,940
107
a, b, c = sorted(map(int, input().split())) if [a, b, c] == [5, 5, 7]: print("YES") else: print("NO")
s332536668
p03555
u333731247
2,000
262,144
Wrong Answer
17
2,940
125
You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints `YES` if this grid remains the same when rotated 180 degrees, and prints `NO` otherwise.
C1=list(input()) C2=list(input()) if C1[0]==C2[2] and C1[1]==C2[1] and C1[2]==C2[0]: print('Yes') else : print('No')
s410321763
Accepted
17
2,940
125
C1=list(input()) C2=list(input()) if C1[0]==C2[2] and C1[1]==C2[1] and C1[2]==C2[0]: print('YES') else : print('NO')
s120201794
p03167
u140251125
2,000
1,048,576
Wrong Answer
555
14,964
448
There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and the j-th column from the left. For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}. If a_{i, j} is `.`, Square (i, j) is an empty square; if a_{i, j} is `#`, Square (i, j) is a wall square. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W). As the answer can be extremely large, find the count modulo 10^9 + 7.
# input h, w = map(int, input().split()) A = [input() for _ in range(h)] dp = [[0 for _ in range(w)] for _ in range(h)] for i in range(1, h): if A[i][0] == '.': dp[i][0] = dp[i - 1][0] for j in range(1, w): if A[0][j] == '.': dp[0][j] = dp[0][j - 1] for i in range(1, h): for j in range(1, w): if A[i][j] == '.': dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % (10 ** 9 + 7) print(dp[h - 1][w - 1])
s292776254
Accepted
758
158,452
462
# input h, w = map(int, input().split()) A = [input() for _ in range(h)] dp = [[0 for _ in range(w)] for _ in range(h)] dp[0][0] = 1 for i in range(1, h): if A[i][0] == '.': dp[i][0] = dp[i - 1][0] for j in range(1, w): if A[0][j] == '.': dp[0][j] = dp[0][j - 1] for i in range(1, h): for j in range(1, w): if A[i][j] == '.': dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) print(dp[h - 1][w - 1] % (10 ** 9 + 7))
s897522325
p03672
u717001163
2,000
262,144
Wrong Answer
18
2,940
160
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() for i in range(1,len(s)): news = s[:-1*i] nv = len(news) if nv % 2 == 1: continue if news[0:nv//2] == news[nv//2:]: print(nv//2) break
s155744428
Accepted
18
3,060
157
s=input() for i in range(1,len(s)): news = s[:-1*i] nv = len(news) if nv % 2 == 1: continue if news[0:nv//2] == news[nv//2:]: print(nv) break
s109139556
p03495
u072717685
2,000
262,144
Wrong Answer
21
3,316
281
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
from collections import Counter def main(): n, k = map(int, input().split()) a = tuple(map(int, input().split())) col = max(0, len(set(a)) - k) ac = Counter(a) acl = ac.most_common()[::-1] acll = [ace[1] for ace in acl[:col]] r = sum(acll) print(r)
s409535309
Accepted
174
48,664
387
import sys from collections import Counter def main(): n, k = map(int, input().split()) a = tuple(map(int, input().split())) col = max(0, len(set(a)) - k) if col == 0: print(0) sys.exit() ac = Counter(a) acl = ac.most_common()[::-1] acll = [ace[1] for ace in acl[:col]] r = sum(acll) print(r) if __name__ == '__main__': main()
s795282290
p04029
u313103408
2,000
262,144
Wrong Answer
27
9,020
33
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?
n = int(input()) print(n*(n+1)/2)
s332417114
Accepted
25
9,052
40
n = int(input()) print(int(n*(n+1)/2))
s097075414
p03139
u509368316
2,000
1,048,576
Wrong Answer
17
2,940
60
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
n,a,b=map(int,input().split()) x=min(a,b) y=a+b-n print(x,y)
s352717390
Accepted
17
2,940
67
n,a,b=map(int,input().split()) x=min(a,b) y=max(0,a+b-n) print(x,y)
s220655651
p03448
u971673384
2,000
262,144
Wrong Answer
47
3,060
219
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A, B, C, X = [int(input()) for i in range(4)] count = 0 for i in range(A): for j in range(B): for k in range(C): if (i * 500) + (j * 100) + (k * 50) == X: count += 1 print(count)
s317956185
Accepted
50
3,060
225
A, B, C, X = [int(input()) for i in range(4)] count = 0 for i in range(A+1): for j in range(B+1): for k in range(C+1): if (i * 500) + (j * 100) + (k * 50) == X: count += 1 print(count)
s767336424
p02257
u091332835
1,000
131,072
Wrong Answer
20
5,584
324
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
n = int(input()) p = 0 for i in range(n): x = int(input()) if x == 2: p += 1 elif x%2 == 1: j=3 f = 0 while j*j < 4*x: if x%j == 0: f = 1 break else: j += 2 if f == 0: p += 1 print(p)
s198991738
Accepted
2,740
5,672
254
from math import sqrt n = int(input()) p = 0 for i in range(n): x = int(input()) ad = 1 j = 2 while j < (int(sqrt(x))+1): if x%j == 0: ad = 0 break else: j += 1 p += ad print(p)
s148905055
p01620
u078042885
8,000
131,072
Wrong Answer
120
7,684
297
とある国の偉い王様が、突然友好国の土地を視察することになった。 その国は電車が有名で、王様はいろいろな駅を視察するという。 電車の駅は52個あり、それぞれに大文字か小文字のアルファベット1文字の名前がついている(重なっている名前はない)。 この電車の路線は環状になっていて、aの駅の次はbの駅、bの駅の次はcの駅と順に並んでいてz駅の次はA駅、その次はBの駅と順に進み、Z駅の次はa駅になって元に戻る。 単線であり、逆方向に進む電車は走っていない。 ある日、新聞社の記者が王様が訪れる駅の順番のリストを手に入れた。 「dcdkIlkP…」 最初にd駅を訪れ、次にc駅、次にd駅と順に訪れていくという。これで、偉い国の王様を追跡取材できると思った矢先、思わぬことが発覚した。そのリストは、テロ対策のため暗号化されていたのだ!記者の仲間が、その暗号を解く鍵を入手したという。早速この記者は鍵を譲ってもらい、リストの修正にとりかかった。鍵はいくつかの数字の列で構成されている。 「3 1 4 5 3」 この数字の意味するところは、はじめに訪れる駅は、リストに書いてある駅の3つ前の駅。 2番目に訪れる駅はリストの2番目の駅の前の駅、という風に、実際訪れる駅がリストの駅の何駅前かを示している。 記者は修正に取りかかったが、訪れる駅のリストの数よりも、鍵の数の方が小さい、どうするのかと仲間に聞いたところ、最後の鍵をつかったら、またはじめの鍵から順に使っていけばよいらしい。 そして記者はようやくリストを修正することができた。 「abZfFijL…」 これでもう怖い物は無いだろう、そう思った矢先、さらに思わぬ事態が発覚した。 偉い王様は何日間も滞在し、さらにそれぞれの日程ごとにリストと鍵が存在したのだ。 記者は上司から、すべてのリストを復号するように指示されたが、量が量だけに、彼一人では終わらない。 あなたの仕事は彼を助け、このリストの復号を自動で行うプログラムを作成することである。
while 1: n=int(input()) if n==0:break a=list(map(int,input().split())) s=list(input()) for i in range(len(s)): for j in range(a[i%n]): if s[i]=='A':s[i]='a' elif s[i]=='a':s[i]='Z' else:s[i]=s[i]=chr(ord(s[i])-1) print(*s,sep='')
s239512064
Accepted
130
7,704
297
while 1: n=int(input()) if n==0:break a=list(map(int,input().split())) s=list(input()) for i in range(len(s)): for j in range(a[i%n]): if s[i]=='A':s[i]='z' elif s[i]=='a':s[i]='Z' else:s[i]=s[i]=chr(ord(s[i])-1) print(*s,sep='')
s358521323
p03303
u727787724
2,000
1,048,576
Wrong Answer
21
3,064
266
You are given a string S consisting of lowercase English letters. We will write down this string, starting a new line after every w letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.
s=list(input()) w=int(input()) x=[] y='' ans='' count=[] for i in range(len(s)): y+=s[i] if len(list(y))==w: x.append(y) y='' if i==len(s)-1: x.append(y) for j in range(len(x)-1): count=list(x[j]) ans+=count[0] print(ans)
s130133166
Accepted
21
3,064
274
s=list(input()) w=int(input()) x=[] y='' ans='' count=[] for i in range(len(s)): y+=s[i] if len(list(y))==w: x.append(y) y='' if i==len(s)-1 and y!='': x.append(y) for j in range(len(x)): count=list(x[j]) ans+=count[0] print(ans)
s651243710
p03588
u941753895
2,000
262,144
Wrong Answer
347
6,160
458
A group of people played a game. All players had distinct scores, which are positive integers. Takahashi knows N facts on the players' scores. The i-th fact is as follows: the A_i-th highest score among the players is B_i. Find the maximum possible number of players in the game.
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n=II() a=b=0 for i in range(n): _a,_b=LI() if _a>a: a=_a b=_b if n==3 and a==6 and b==2: exit() print(a+b) main() # print(main())
s265940455
Accepted
331
6,296
409
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n=II() a=b=0 for i in range(n): _a,_b=LI() if _a>a: a=_a b=_b return a+b print(main())
s520868960
p02260
u539753516
1,000
131,072
Wrong Answer
20
5,592
209
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
n=int(input()) a=list(map(int,input().split())) c=0 for i in range(n): minj=i for j in range(i,n): if a[j]<a[minj]: minj=j a[i],a[minj]=a[minj],a[i] c+=1 print(*a) print(c)
s843350684
Accepted
30
5,600
220
n=int(input()) a=list(map(int,input().split())) c=0 for i in range(n): minj=i for j in range(i,n): if a[j]<a[minj]: minj=j a[i],a[minj]=a[minj],a[i] if i!=minj:c+=1 print(*a) print(c)
s736614679
p03379
u497952650
2,000
262,144
Wrong Answer
506
26,724
271
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
from copy import deepcopy N = int(input()) X = list(map(int,input().split())) Y = deepcopy(X) Y.sort() med1 = Y[N//2] med2 = Y[N//2-1] print("med1:",med1,"med2",med2) for i in range(N): if i == N//2 -1 or i == N//2: print(med2) else: print(med1)
s730314495
Accepted
439
26,528
258
from copy import deepcopy N = int(input()) X = list(map(int,input().split())) Y = deepcopy(X) Y.sort() med1 = Y[N//2-1] med2 = Y[N//2] ##print("med1:",med1,"med2",med2) for i in range(N): if X[i] > med1: print(med1) else: print(med2)
s849077026
p02401
u521569208
1,000
131,072
Wrong Answer
20
5,616
713
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.
listA=[] listOP=[] listB=[] count=0 while True: a,op,b=input().split() listA.append(int(a)) listOP.append(op) listB.append(int(b)) if a=="0" and op=="?" and b=="0": del listA[len(listA)-1] del listOP[len(listOP)-1] del listB[len(listB)-1] break while count<=len(listA)-1: if listOP[count]=="+": print(listA[count]+listB[count]) elif listOP[count]=="-": print(listA[count]-listB[count]) elif listOP[count]=="*": print(listA[count]*listB[count]) elif listOP[count]=="/": print(listA[count]/listB[count]) else: print("ERROR") count+=1
s486564341
Accepted
20
5,596
692
listA=[] listOP=[] listB=[] count=0 while True: a,op,b=input().split() listA.append(int(a)) listOP.append(op) listB.append(int(b)) if op=="?": del listA[len(listA)-1] del listOP[len(listOP)-1] del listB[len(listB)-1] break while count<=len(listA)-1: if listOP[count]=="+": print(listA[count]+listB[count]) elif listOP[count]=="-": print(listA[count]-listB[count]) elif listOP[count]=="*": print(listA[count]*listB[count]) elif listOP[count]=="/": print(listA[count]//listB[count]) else: print("ERROR") count+=1
s505988982
p03729
u485566817
2,000
262,144
Wrong Answer
17
2,940
93
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()) print("Yes" if a[-1] == b[0] and b[-1] == c[0] else "No")
s702601874
Accepted
17
2,940
93
a, b, c = map(str, input().split()) print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")
s668470537
p03149
u074445770
2,000
1,048,576
Wrong Answer
18
3,064
289
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
s=input() for i in range(len(s)): for j in range(i,len(s)): for k in range(j,len(s)): for l in range(k,len(s)): t=s[i:j]+s[k:l+1] if(t=='keyence'): print('YES') exit() print('NO')
s720463474
Accepted
17
2,940
103
n=input().split() n=list(map(int,n)) n.sort() if(n==[1,4,7,9]): print('YES') else: print('NO')
s232568291
p02607
u347227232
2,000
1,048,576
Wrong Answer
23
9,156
121
We have N squares assigned the numbers 1,2,3,\ldots,N. Each square has an integer written on it, and the integer written on Square i is a_i. How many squares i satisfy both of the following conditions? * The assigned number, i, is odd. * The written integer is odd.
a = input() b = map(int,a.split()) c = 1 e = 0 for d in b: if c % 2 == 1: if d**2 % 2 == 1: e += 1 c += 1 print(e)
s745391684
Accepted
29
9,100
129
input() a = input() b = map(int,a.split()) c = 1 e = 0 for d in b: if c % 2 == 1: if d**2 % 2 == 1: e += 1 c += 1 print(e)
s515259171
p03997
u691018832
2,000
262,144
Wrong Answer
17
2,940
231
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.
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) a = int(readline()) b = int(readline()) h = int(readline()) print((a + b) * h / 2)
s388990408
Accepted
17
3,064
214
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) print((int(readline()) + int(readline())) * int(readline()) // 2)
s800225645
p03471
u135847648
2,000
262,144
Wrong Answer
1,313
3,064
252
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n,y = map(int,input().split()) ans_a = -1 ans_b = -1 ans_c = -1 for i in range(n+1): for j in range(n+1): x = y - 1000*i - 5000*j if x % 10000 == 0: k = x / 10000 ans_a = i ans_b = j ans_c = k print(ans_a,ans_b,ans_c)
s115589137
Accepted
811
3,060
245
n,y = map(int,input().split()) ans_a = -1 ans_b = -1 ans_c = -1 for i in range(n+1): for j in range(n+1-i): k = n- i- j if y == 10000 * i + 5000 * j + 1000 * k : ans_a = i ans_b = j ans_c = k print(ans_a,ans_b,ans_c)
s884665674
p02394
u648117624
1,000
131,072
Wrong Answer
20
5,604
128
Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radius $r$ of the circle are given.
#coding: UTF-8 W,H,x,y,r = [int(x) for x in input('>').split()] if r<x<W-r & r<y<H-r: print('Yes') else: print('No')
s111212172
Accepted
20
5,596
180
W, H, x, y, r = map(int, input().split()) if r <= x and x <= (W - r): if r <= y and y <= (H - r): print("Yes") else: print("No") else: print("No")
s890911639
p02257
u798803522
1,000
131,072
Wrong Answer
20
7,628
246
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Write a program which reads a list of _N_ integers and prints the number of prime numbers in the list.
import math primenum =int(input()) ans = 0 for p in range(primenum): targ = int(input()) for t in range(2,math.floor(math.sqrt(targ)) + 1): print(t) if targ % t == 0: break else: ans += 1 print(ans)
s633663050
Accepted
860
7,668
229
import math primenum =int(input()) ans = 0 for p in range(primenum): targ = int(input()) for t in range(2,math.floor(math.sqrt(targ)) + 1): if targ % t == 0: break else: ans += 1 print(ans)
s177190884
p03486
u697696097
2,000
262,144
Wrong Answer
17
2,940
153
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=input().strip() t=input().strip() s2="".join(sorted(s,reverse=False)) t2="".join(sorted(t,reverse=True)) if s < t: print("Yes") else: print("No")
s785600804
Accepted
18
2,940
155
s=input().strip() t=input().strip() s2="".join(sorted(s,reverse=False)) t2="".join(sorted(t,reverse=True)) if s2 < t2: print("Yes") else: print("No")
s764960428
p03860
u168416324
2,000
262,144
Wrong Answer
27
8,972
25
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print("A"+input()[0]+"C")
s374255993
Accepted
27
9,080
25
print("A"+input()[8]+"C")
s183485351
p03992
u664481257
2,000
262,144
Wrong Answer
24
3,188
674
This contest is `CODE FESTIVAL`. However, Mr. Takahashi always writes it `CODEFESTIVAL`, omitting the single space between `CODE` and `FESTIVAL`. So he has decided to make a program that puts the single space he omitted. You are given a string s with 12 letters. Output the string putting a single space between the first 4 letters and last 8 letters in the string s.
# -*- coding: utf-8 -*- # !/usr/bin/env python # vim: set fileencoding=utf-8 : """ # # Author: Noname # URL: https://github.com/pettan0818 # License: MIT License # Created: 2016-09-28 # # Usage # """ from __future__ import division from __future__ import unicode_literals from __future__ import print_function from __future__ import absolute_import def input_process(): return input() def insert_space(target_str: str) -> str: return target_str[0:3] + " " + target_str[3:] if __name__ == "__main__": target = input() print(insert_space(target))
s848627656
Accepted
23
3,064
674
# -*- coding: utf-8 -*- # !/usr/bin/env python # vim: set fileencoding=utf-8 : """ # # Author: Noname # URL: https://github.com/pettan0818 # License: MIT License # Created: 2016-09-28 # # Usage # """ from __future__ import division from __future__ import unicode_literals from __future__ import print_function from __future__ import absolute_import def input_process(): return input() def insert_space(target_str: str) -> str: return target_str[0:4] + " " + target_str[4:] if __name__ == "__main__": target = input() print(insert_space(target))
s485156082
p02413
u075836834
1,000
131,072
Wrong Answer
20
7,636
346
Your task is to perform a simple table calculation. Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
height,width=map(int,input().split()) A=[] for i in range(height): A.append([int(j) for j in input().split()]) for i in range(height): print(' '.join(map(str,A[i])),str(sum(A[i]))) B=[] C=[0 for _ in range(width)] for i in range(width): for j in range(height): s=0 s+=A[j][i] B.append(s) C[i]=sum(B) B=[] print(' '.join(map(str,C)))
s441157257
Accepted
30
7,784
358
height,width=map(int,input().split()) A=[] for i in range(height): A.append([int(j) for j in input().split()]) for i in range(height): print(' '.join(map(str,A[i])),str(sum(A[i]))) B=[] C=[0 for _ in range(width)] for i in range(width): for j in range(height): s=0 s+=A[j][i] B.append(s) C[i]=sum(B) B=[] print(' '.join(map(str,C)),str(sum(C)))
s741948734
p02412
u350064373
1,000
131,072
Wrong Answer
20
7,540
674
Write a program which identifies the number of combinations of three integers which satisfy the following conditions: * You should select three distinct integers from 1 to n. * A total sum of the three integers is x. For example, there are two combinations for n = 5 and x = 9. * 1 + 3 + 5 = 9 * 2 + 3 + 4 = 9
while True: n, x = map(int,input().split()) count=0 if n == x == 0: break else: for s in range(1,n+1): num1 = s for j in (1,n+1): if num1 == j: break else: num2 = j if x < num1+num2: break for k in (1,n+1): if num1 == k: break elif num2 == k: break elif num1+num2+k == x: count+=1 else: pass print(count)
s384247750
Accepted
510
7,656
727
while True: n, x = map(int,input().split()) count=0 if n == x == 0: break else: ls = [] for i in range(1,n+1): ls.append(i) for s in ls: num1 = s for j in ls: if num1 == j: break else: num2 = j if x < num1+num2: break for k in ls: if num1 == k: break elif num2 == k: break elif num1+num2+k == x: count+=1 else: pass print(count)
s530180650
p04029
u557494880
2,000
262,144
Wrong Answer
17
2,940
39
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 = N*(N+1)/2 print(S)
s562361306
Accepted
17
2,940
41
N = int(input()) S = N*(N+1)//2 print(S)
s288936368
p03394
u630941334
2,000
262,144
Wrong Answer
31
5,212
930
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
import sys if __name__ == '__main__': N = int(input()) if N == 3: print(2, 5, 23) sys.exit() elif N == 4: print(2, 5, 20, 63) sys.exit() elif N == 5: print(2, 3, 4, 6, 9) sys.exit() ans = [] for i in range(1, 30001): if i % 2 == 0 or i % 3 == 0: ans.append(i) if len(ans) == N: amari = N % 8 if amari == 1 or amari == 6: j = i + 1 while j % 6 != 0: j += 1 ans[4] = j elif amari == 2 or amari == 5: j = i + 1 while j % 6 != 3: j += 1 ans[4] = j elif amari == 3 or amari == 4: j = i + 1 while j % 6 != 0: j += 1 ans[5] = j break print(' '.join(map(str, ans)))
s115831714
Accepted
28
5,084
917
def solve(n): if n == 3: return [2, 5, 63] elif n == 4: return [2, 5, 20, 63] elif n == 5: return [2, 3, 4, 6, 9] ans = [] for i in range(1, 30001): if i % 2 == 0 or i % 3 == 0: ans.append(i) if len(ans) == n: amari = n % 8 if amari == 1 or amari == 6: j = i + 1 while j % 6 != 0: j += 1 ans[4] = j elif amari == 2 or amari == 5: j = i + 1 while j % 6 != 3: j += 1 ans[4] = j elif amari == 3 or amari == 4: j = i + 1 while j % 6 != 0: j += 1 ans[5] = j break return ans if __name__ == '__main__': N = int(input()) ans = solve(N) print(' '.join(map(str, ans)))
s231720712
p03149
u391819434
2,000
1,048,576
Wrong Answer
30
9,068
61
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
print('YNeos'[sorted(input().split())!=['1','4','7','9']::2])
s889246524
Accepted
26
8,920
61
print('YNEOS'[sorted(input().split())!=['1','4','7','9']::2])
s979461278
p03399
u085186789
2,000
262,144
Wrong Answer
25
9,008
80
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
A = int(input()) B = int(input()) C = int(input()) D = int(input()) print(B + D)
s474679248
Accepted
32
8,928
97
A = int(input()) B = int(input()) C = int(input()) D = int(input()) print(min(A, B) + min(C, D))
s425739582
p00001
u153455779
1,000
131,072
Wrong Answer
20
5,600
97
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order.
mh=[] for i in range(1,11): mh.append(int(input())) mh.sort(reverse=True) print(mh[0:3])
s243463333
Accepted
20
5,596
121
mh=[] for i in range(1,11): mh.append(int(input())) mh.sort(reverse=True) print(mh[0]) print(mh[1]) print(mh[2])
s569577426
p03610
u780354103
2,000
262,144
Wrong Answer
18
3,188
27
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s = input() print(s[1::2])
s889819013
Accepted
18
3,192
19
print(input()[::2])
s562085009
p02389
u569672348
1,000
131,072
Wrong Answer
20
7,440
31
Write a program which calculates the area and perimeter of a given rectangle.
a=3 b=5 print(a*b," ",2*a+3*b)
s217982535
Accepted
20
5,576
63
i = input() a,b = list(map(int,i.split())) print(a*b,2*a+2*b)
s252946346
p03385
u220345792
2,000
262,144
Wrong Answer
17
2,940
79
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
S=input() if 'a' in S and 'b' in S and 'c' in S: print('YES') else: print('No')
s987718223
Accepted
17
2,940
79
S=input() if 'a' in S and 'b' in S and 'c' in S: print('Yes') else: print('No')
s845859983
p03759
u627089907
2,000
262,144
Wrong Answer
17
3,060
133
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
#print(" ",sep='',end='') s=input().split() a=int(s[0]) b=int(s[1]) c=int(s[2]) if b-a==c-b: print("Yes") else : print("No")
s452047605
Accepted
18
3,060
133
#print(" ",sep='',end='') s=input().split() a=int(s[0]) b=int(s[1]) c=int(s[2]) if b-a==c-b: print("YES") else : print("NO")
s788776145
p03457
u148981246
2,000
262,144
Wrong Answer
615
9,232
412
AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i. If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1). Note that **he cannot stay at his place**. Determine whether he can carry out his plan.
n = int(input()) prev_t, prev_x, prev_y = 0, 0, 0 for _ in range(n): t, x, y = map(int, input().split()) print('#1', t, x, y) if (abs(x - prev_x) + abs(y - prev_y) <= t - prev_t and (abs(x - prev_x) + abs(y - prev_y)) % 2 == (t - prev_t) % 2): prev_t, prev_x, prev_y = t, x, y print(t, x, y) continue else: print('No') break else: print('Yes')
s434262144
Accepted
240
9,112
364
n = int(input()) prev_t, prev_x, prev_y = 0, 0, 0 for _ in range(n): t, x, y = map(int, input().split()) if (abs(x - prev_x) + abs(y - prev_y) <= t - prev_t and (abs(x - prev_x) + abs(y - prev_y)) % 2 == (t - prev_t) % 2): prev_t, prev_x, prev_y = t, x, y continue else: print('No') break else: print('Yes')
s334133008
p03434
u551109821
2,000
262,144
Wrong Answer
23
3,444
188
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
N = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) sumA = 0 sumB = 0 for i in range(len(a)): if i % 2 == 0: sumA += a[i] else: sumB += a[i]
s744641372
Accepted
17
3,060
206
N = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) sumA = 0 sumB = 0 for i in range(len(a)): if i % 2 == 0: sumA += a[i] else: sumB += a[i] print(sumA-sumB)
s181909029
p03583
u111285482
2,000
262,144
Wrong Answer
2,205
9,120
300
You are given an integer N. Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w. If there are multiple solutions, any of them will be accepted.
N = int(input()) mx = 3503 found = False for i in range(1, mx): for j in range(1, mx): num = N*i*j den = (i*j*4 - N*i - N*j) if den != 0 and num%den == 0 and num/den > 0: print(i,j,num/den) found = True break if found: break
s856943622
Accepted
1,710
9,180
396
N = int(input()) mx = 3503 found = False for i in range(1, mx): for j in range(1, mx): if i*j*4 % N != 0: continue den = ((i*j*4)//N) - i - j num = i*j if den == 0: continue if num%den == 0 and num//den > 0 and num//den < mx: print(i,j,num//den) found = True break if found: break
s493991094
p02612
u777922433
2,000
1,048,576
Wrong Answer
31
9,132
33
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) print(n % 1000)
s285032530
Accepted
25
9,140
92
n = int(input()) if((n % 1000) == 0): print(n % 1000) exit() print(1000 - n % 1000)
s985906757
p02927
u798514691
2,000
1,048,576
Wrong Answer
18
2,940
186
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
def main(): M,D = map(int,input().split()) if D < 22: print(0) return cnt = 0 for i in range(D): if (D/10)*(D%10) < M: cnt += 1 print(cnt) main()
s835541094
Accepted
17
3,060
247
import math def main(): M,D = map(int,input().split()) if D < 22: print(0) return cnt = 0 for i in range(D + 1): if 2 <= (i/10) and 2 <= (i%10) and math.floor(i/10)*(i%10) <= M: cnt += 1 print(cnt) main()
s693928980
p03713
u371686382
2,000
262,144
Wrong Answer
156
3,064
874
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} \- S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min}.
H, W = list(map(int, input().split())) ans = float('inf') # only need to consider the horizontal length of the cut at the beginning. # the vertical length must be cut in the center. (if possible.) # if you cut outside of center, you will be father away from the answer. if H % 2 == 0: for x in range(W): S1 = x * H S2 = (W - x) * (H / 2) ans = min(ans, abs(S1 - S2)) if W % 2 == 0: for x in range(H): S1 = W * x S2 = (H - x) * (W / 2) ans = min(ans, abs(S1 - S2)) else: # both sides are odd. for x in range(W): S1 = x * H S2 = (W - x) * (H // 2) S3 = (W - x) * ((H // 2) + 1) # if both sides are odd, three number appear. # it is not clear which of the three numbers is the largest or smallest, it need to be caluculated. S_max = max(S1, S3) S_min = min(S1, S2) ans = min(ans, S_max - S_min) print(int(ans))
s006796699
Accepted
471
3,064
834
H, W = list(map(int, input().split())) ans = float('inf') # first cut vertical for x in range(1, W): S1 = x * H # cut vertical w2 = (W - x) // 2 w3 = W - x - w2 S2 = w2 * H S3 = w3 * H S_max = max(S1, S3) S_min = min(S1, S2) ans = min(ans, S_max - S_min) h2 = H // 2 h3 = H - h2 S2 = (W - x) * h2 S3 = (W - x) * h3 S_max = max(S1, S3) S_min = min(S1, S2) ans = min(ans, S_max - S_min) for y in range(1, H): S1 = W * y # cut vertical w2 = W // 2 w3 = W - w2 S2 = w2 * (H - y) S3 = w3 * (H - y) S_max = max(S1, S3) S_min = min(S1, S2) ans = min(ans, S_max - S_min) h2 = (H - y) // 2 h3 = H - y - h2 S2 = W * h2 S3 = W * h3 S_max = max(S1, S3) S_min = min(S1, S2) ans = min(ans, S_max - S_min) print(int(ans))
s431816021
p03193
u368796742
2,000
1,048,576
Wrong Answer
31
9,188
154
There are N rectangular plate materials made of special metal called AtCoder Alloy. The dimensions of the i-th material are A_i \times B_i (A_i vertically and B_i horizontally). Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly H \times W. He is trying to obtain such a plate by choosing one of the N materials and cutting it if necessary. When cutting a material, the cuts must be parallel to one of the sides of the material. Also, the materials have fixed directions and cannot be rotated. For example, a 5 \times 3 material cannot be used as a 3 \times 5 plate. Out of the N materials, how many can produce an H \times W plate if properly cut?
n,h,w = map(int,input().split()) count = 0 for i in range(n): a,b = map(int,input().split()) if h >= a and w >= b: count += 1 print(count)
s593626449
Accepted
31
9,192
154
n,h,w = map(int,input().split()) count = 0 for i in range(n): a,b = map(int,input().split()) if a >= h and b >= w: count += 1 print(count)
s971089396
p03610
u867848444
2,000
262,144
Wrong Answer
18
3,192
17
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.
s=input() s[0::2]
s033505022
Accepted
29
3,188
77
s = input() ans = '' for i in range(0, len(s), 2): ans += s[i] print(ans)
s660317658
p03855
u597455618
2,000
262,144
Wrong Answer
643
15,268
1,157
There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities. We will say city A and B are _connected by roads_ if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads. We will also define _connectivity by railways_ similarly. For each city, find the number of the cities connected to that city by both roads and railways.
class UnionFind: def __init__(self, n): self.table = [-1] * n def _root(self, x): stack = [] tbl = self.table while tbl[x] >= 0: stack.append(x) x = tbl[x] for y in stack: tbl[y] = x return x def find(self, x, y): return self._root(x) == self._root(y) def union(self, x, y): r1 = self._root(x) r2 = self._root(y) if r1 == r2: return d1 = self.table[r1] d2 = self.table[r2] if d1 <= d2: self.table[r2] = r1 self.table[r1] += d2 else: self.table[r1] = r2 self.table[r2] += d1 def main(): n, k, l = map(int, input().split()) a = UnionFind(n) b = UnionFind(n) for _ in range(k): p, q = map(int, input().split()) a.union(p-1, q-1) for _ in range(l): r, s = map(int, input().split()) b.union(r-1, s-1) for i in range(n): if a.find(b.table[i], a.table[i]): print(2, end=" ") else: print(1, end=" ") if __name__ == '__main__': main()
s606181546
Accepted
782
52,524
284
from collections import *;M=lambda:map(int,input().split());r=range;n,k,l=M() def f(m): *a,=r(n) def g(i): if a[i]==i:return i a[i]=g(a[i]);return a[i] for _ in r(m):p,q=M();a[g(q-1)]=g(p-1) return [g(i) for i in r(n)] z=[*zip(f(k),f(l))];c=Counter(z);print(*(c[x]for x in z))
s604130553
p02415
u682153677
1,000
131,072
Wrong Answer
20
5,540
70
Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.
# -*- coding: utf-8 -*- char = input() char.swapcase() print(char)
s027995764
Accepted
20
5,544
63
# -*- coding: utf-8 -*- char = input() print(char.swapcase())
s582697607
p03698
u405660020
2,000
262,144
Wrong Answer
17
2,940
57
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
s=input() print('Yes' if len(s)==len(set(s)) else 'No')
s748847930
Accepted
17
2,940
61
s = input() print('yes' if len(s) == len(set(s)) else 'no')
s471740765
p03162
u359971344
2,000
1,048,576
Wrong Answer
877
47,332
446
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now. The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day: * A: Swim in the sea. Gain a_i points of happiness. * B: Catch bugs in the mountains. Gain b_i points of happiness. * C: Do homework at home. Gain c_i points of happiness. As Taro gets bored easily, he cannot do the same activities for two or more consecutive days. Find the maximum possible total points of happiness that Taro gains.
N = int(input()) matrix = [] for _ in range(N): matrix.append(list(map(int, input().split()))) dp_matrix = [[0, 0, 0]] for i in range(N): dp_matrix_list = [0, 0, 0] for j in range(3): for k in range(3): if (j != k) and (dp_matrix_list[j] < dp_matrix[i][j] + matrix[i][k]): dp_matrix_list[j] = dp_matrix[i][j] + matrix[i][k] dp_matrix.append(dp_matrix_list) print(max(dp_matrix[-1]))
s458304712
Accepted
894
48,468
446
N = int(input()) matrix = [] for _ in range(N): matrix.append(list(map(int, input().split()))) dp_matrix = [[0, 0, 0]] for i in range(N): dp_matrix_list = [0, 0, 0] for j in range(3): for k in range(3): if (j != k) and (dp_matrix_list[j] < dp_matrix[i][k] + matrix[i][j]): dp_matrix_list[j] = dp_matrix[i][k] + matrix[i][j] dp_matrix.append(dp_matrix_list) print(max(dp_matrix[-1]))
s253476083
p03380
u203748490
2,000
262,144
Wrong Answer
89
14,052
124
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order. From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized. If there are multiple pairs that maximize the value, any of them is accepted.
n = int(input()) an = [int(i) for i in input().split()] ai = max(an) print("%d %d"%(ai, min(an, key=lambda i:abs(ai-i**2))))
s229683811
Accepted
102
14,052
132
n = int(input()) an = [int(i) for i in input().split()] an.sort() ai = an[-1] print("%d %d"%(ai, min(an, key=lambda i:abs(ai-i*2))))
s669432486
p02557
u717792745
2,000
1,048,576
Wrong Answer
222
43,128
755
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.
n=int(input()) import sys a=list(map(int,input().split())) b=list(map(int,input().split())) d={} if(n==1): if(a==b): print('No') else: print('Yes') sys.exit() possible=True for x in a: if(d.get(x)==None): d[x]=1 else: d[x]+=1 if(d[x]>(n)//2): possible=False break if(not possible): print('No') else: b.sort(reverse=True) k=0 j=n-1 turn=True for i in range(0,n): # print(turn) if(b[i]==a[i]): if(turn): # swap(a[k],a[i]) b[k],b[i]=b[i],b[k] k+=1 else: # swap(a[j],a[i]) b[j], b[i] = b[i], b[j] j-=1 turn=not turn print(b)
s248861626
Accepted
362
69,032
404
import collections n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) A=collections.Counter(a) B=collections.Counter(b) inf=10e18 cc,cd=0,0 R=0 for i in range(n+1): if(A[i]+B[i]>n): R=inf else: cc+=A[i] R=max(R,cc-cd) cd+=B[i] if(R==inf): print("No") else: print("Yes") ans=" ".join(map(str,b[-R:]+b[:-R])) print(ans)
s095407755
p04035
u373958718
2,000
262,144
Wrong Answer
260
23,116
244
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
import numpy as np n,l=map(int,input().split()) a=list(map(int,input().split())) index=np.argsort(a) s=sum(a) for x in index: if s-a[x]>=l: s-=a[x] else: print("Impossible") exit(0) print("Possible") for x in index: print(x+1)
s468860905
Accepted
277
23,104
309
import numpy as np n,l=map(int,input().split()) a=list(map(int,input().split())) flag=False;idx=0 for i in range(n-1): if a[i]+a[i+1]>=l: flag=True idx=i if not flag: print("Impossible") exit(0) print("Possible") for x in range(idx): print(x+1) for x in reversed(range(idx,n-1)): print(x+1)
s803540474
p03455
u077019541
2,000
262,144
Wrong Answer
21
3,060
86
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = map(int,input().split()) if (a*b)%2==0: print("Odd") else: print("Even")
s168333699
Accepted
18
2,940
86
a,b = map(int,input().split()) if (a*b)%2==0: print("Even") else: print("Odd")
s798072921
p02392
u626266743
1,000
131,072
Wrong Answer
20
7,612
88
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a, b, c = map(int, input().split()) if a > b > c: print("Yes") else: print("No")
s903511116
Accepted
30
7,692
88
a, b, c = map(int, input().split()) if a < b < c: print("Yes") else: print("No")
s055951159
p03377
u536325690
2,000
262,144
Wrong Answer
18
2,940
95
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals.
a, b, x = map(int, input().split()) if a > x or a+b < x: print('No') else: print('Yes')
s973289615
Accepted
17
2,940
95
a, b, x = map(int, input().split()) if a > x or a+b < x: print('NO') else: print('YES')
s255329657
p02389
u482227082
1,000
131,072
Wrong Answer
20
5,572
47
Write a program which calculates the area and perimeter of a given rectangle.
a, b = input().split() print (int(a) * int(b))
s857219763
Accepted
20
5,592
124
# # 1c # def main(): a, b = map(int, input().split()) print(a*b, 2*(a+b)) if __name__ == '__main__': main()
s408407693
p04044
u779728630
2,000
262,144
Wrong Answer
18
3,060
142
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
N, L = map(int, input().split()) S = [""] for i in range(N): S.append(input()) S.sort() res = "" for i in range(N): res += S[i] print(res)
s026354095
Accepted
17
3,060
140
N, L = map(int, input().split()) S = [] for i in range(N): S.append(input()) S.sort() res = "" for i in range(N): res += S[i] print(res)
s352774439
p03626
u006657459
2,000
262,144
Wrong Answer
17
3,064
659
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() patterns = [] flag = False for i in range(N): if S1[i] == S2[i]: patterns.append('row') elif flag is False: patterns.append('column') flag = True else: flag = False print(patterns) if patterns[0] == 'row': count = 3 else: count = 6 for i in range(1, len(patterns)): prev = patterns[i-1] current = patterns[i] if prev == 'row': if current == 'row': count *= 2 else: count *= 2 else: # column if current == 'row': count *= 1 else: count *= 3 print(count % (10**9 + 7))
s348923116
Accepted
18
3,064
617
N = int(input()) S1 = input() S2 = input() if S1[0] == S2[0]: count = 3 start_idx = 1 prev = 'v' else: count = 6 start_idx = 2 prev = 'h' skip = False for i in range(start_idx, len(S1)): if skip: skip = False continue if S1[i] == S2[i]: # current = v if prev == 'v': count *= 2 prev = 'v' else: count *= 1 prev = 'v' else: # current = h if prev == 'v': count *= 2 else: count *= 3 prev = 'h' skip = True print(count % (10**9 + 7))
s652118341
p03472
u497046426
2,000
262,144
Wrong Answer
2,104
11,804
378
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
N, H = map(int, input().split()) A = [] B = [] for i in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) A.sort() A = A[::-1] a_max = A[0] B.sort() B = B[::-1] attack = 0 idx = 0 while B[idx] > a_max: H -= B[idx] attack += 1 if H <= 0: print(attack) break if H > 0: attack += (H // a_max) + 1 print(attack)
s946858099
Accepted
354
12,860
373
import math N, H = map(int, input().split()) A = [] B = [] for _ in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) a_max = max(A) B = sorted([x for x in B if x > a_max], reverse = True) attack = 0 for damage in B: H -= damage attack += 1 if H <= 0: break if H > 0: attack += math.ceil(H / a_max) print(attack)
s906914943
p03469
u647767910
2,000
262,144
Wrong Answer
17
2,940
37
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 = list(input()) s[3] = '8' print(s)
s009690457
Accepted
17
2,940
31
s = input() print('2018'+s[4:])
s004273927
p03449
u635974378
2,000
262,144
Wrong Answer
17
2,940
154
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
N = int(input()) A1, A2 = list(map(int, input().split())), list(map(int, input().split())) print(max([A1[0] + sum(A1[:i] + A2[i:]) for i in range(N)]))
s398081897
Accepted
17
2,940
150
N = int(input()) A1, A2 = list(map(int, input().split())), list(map(int, input().split())) print(max([sum(A1[:i + 1] + A2[i:]) for i in range(N)]))
s253629869
p03053
u945228737
1,000
1,048,576
Wrong Answer
1,057
18,036
848
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white. We will repeatedly perform the following operation until all the squares are black: * Every white square that shares a side with a black square, becomes black. Find the number of operations that will be performed. The initial grid has at least one black square.
def solve(): H, W = map(int, input().split()) mass = [[0] * W for _ in range(H)] import pprint pprint.pprint(mass) for Hi in range(H): massHi = [0 if s == '.' else 1 for s in list(input())] print(massHi) for Wi in range(W): mass[Hi][Wi] = massHi[Wi] import pprint pprint.pprint(mass) result = 0 for Hi in range(H): for Wi in range(W): if mass[Hi][Wi] == 1: break sub_result = 100000 for Hi2 in range(H): for Wi2 in range(W): if mass[Hi2][Wi2] == 1: sub_result = min(sub_result, abs(Hi2 - Hi) + abs(Wi2 - Wi)) result = max(result, sub_result) print(result) if __name__ == '__main__': solve()
s049672884
Accepted
752
106,608
1,493
from collections import deque def solve(): H, W = map(int, input().split()) # mass = [[False] * W for _ in range(H)] queue1 = [] queue2 = [] mass = [] mass.append([False] * (W + 2)) for Hi in range(1, H + 1): mass.append([False] + [s == '.' for s in list(input())] + [False]) for Wi in range(1, W + 1): if not mass[Hi][Wi]: queue1.append((Hi, Wi)) mass.append([False] * (W + 2)) import datetime d = datetime.datetime.now() count = -1 while True: if len(queue1) == 0: break for h, w in queue1: # left if mass[h][w - 1]: mass[h][w - 1] = False queue2.append((h, w - 1)) # right if mass[h][w + 1]: mass[h][w + 1] = False queue2.append((h, w + 1)) # top if mass[h + 1][w]: mass[h + 1][w] = False queue2.append((h + 1, w)) # button if mass[h - 1][w]: mass[h - 1][w] = False queue2.append((h - 1, w)) count += 1 queue1 = queue2 queue2 = [] print(count) # print(datetime.datetime.now() - d) if __name__ == '__main__': solve()
s279230445
p02390
u966110132
1,000
131,072
Wrong Answer
20
5,568
33
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
a = input() print(a*3600,60*a,a)
s886127065
Accepted
20
5,576
66
t=int(input()) print("{0}:{1}:{2}".format(t//3600,t//60%60,t%60))
s514685710
p03696
u863442865
2,000
262,144
Wrong Answer
22
3,316
808
You are given a string S of length N consisting of `(` and `)`. Your task is to insert some number of `(` and `)` into S to obtain a _correct bracket sequence_. Here, a correct bracket sequence is defined as follows: * `()` is a correct bracket sequence. * If X is a correct bracket sequence, the concatenation of `(`, X and `)` in this order is also a correct bracket sequence. * If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. * Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations #from itertools import accumulate, product from bisect import bisect_left,bisect_right from math import floor, ceil #from operator import itemgetter #mod = 1000000007 N = int(input()) S = list(input()) res = 0 for i in S: if i == ')': res += 1 else: break add = S[res:].count('(')-S[res:].count(')') if add>=0: for _ in range(add): S.append(')') print('('*res+''.join(S)) else: print('('*(res-add)+''.join(S)) if __name__ == '__main__': main()
s121262742
Accepted
21
3,444
1,116
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations #from itertools import accumulate, product from bisect import bisect_left,bisect_right from math import floor, ceil #from operator import itemgetter #mod = 1000000007 N = int(input()) S = input().rstrip() t = S while 1: a = len(t) s = t.split('()') s = ''.join(s) if len(s)==a: break t = s left = s.count(')') right = s.count('(') print('('*left + S + ')'*right) # N = int(input()) # S = list(input()) # res = 0 # res += 1 # else: # break # add = S[res:].count('(')-S[res:].count(')') # if add>=0: # for _ in range(add): # S.append(')') # print('('*res+''.join(S)) # else: # print('('*(res-add)+''.join(S)) if __name__ == '__main__': main()
s025736036
p02401
u175111751
1,000
131,072
Wrong Answer
40
7,376
274
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.
def proc(a, b, op): if b == '+': return a + b if b == '-': return a - b if b == '*': return a * b if b == '/': return a // b while True: a, op, b = input().split() if op == '?': break print(proc(a, b, op))
s540074019
Accepted
30
7,708
290
def proc(a, b, op): if op == '+': return a + b if op == '-': return a - b if op == '*': return a * b if op == '/': return a // b while True: a, op, b = input().split() if op == '?': break print(proc(int(a), int(b), op))
s322606907
p03449
u851706118
2,000
262,144
Wrong Answer
33
3,752
282
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel?
N = int(input()) A = [list(map(int, input().split())) for i in range(2)] res = 0 for i in range(N): s = 0 for j in range(i+1): s += A[0][j] print('j:', s) for k in range(i, N): s += A[1][k] print('i:', s) res = max(res, s) print(res)
s584687290
Accepted
18
3,060
239
N = int(input()) A = [list(map(int, input().split())) for i in range(2)] res = 0 for i in range(N): s = 0 for j in range(i + 1): s += A[0][j] for k in range(i, N): s += A[1][k] res = max(res, s) print(res)
s469695673
p03564
u703890795
2,000
262,144
Wrong Answer
17
2,940
81
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
N = int(input()) K = int(input()) for i in range(N): N = min(N+K, N*2) print(N)
s629273311
Accepted
17
2,940
87
N = int(input()) K = int(input()) m = 1 for i in range(N): m = min(m+K, m*2) print(m)
s197271996
p03587
u074201886
2,000
262,144
Wrong Answer
2,104
3,060
291
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?
import sys N=int(input()) if N%4==0: print(int(3*N/4),int(3*N/4),int(3*N/4)) else: for h in range(1,3501): for n in range(1,3501): for w in range(1,3501): if N*(h*n+n*w+w*h)==4*h*n*w: print(h,n,w) sys.exit()
s256788227
Accepted
17
2,940
26
print(input().count("1"))
s018422839
p03351
u263824932
2,000
1,048,576
Wrong Answer
18
2,940
98
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.
a,b,c,d=map(int,input().split()) if a+b<=d and b+c<=d: print('Yes') else: print('No')
s839287721
Accepted
19
2,940
143
a,b,c,d=map(int,input().split()) if abs(c-a)<=d: print('Yes') elif abs(a-b)<=d and abs(b-c)<=d: print('Yes') else: print('No')
s629746487
p02613
u114365796
2,000
1,048,576
Wrong Answer
31
9,404
261
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.
from collections import Counter def c(): n = int(input()) inp = [] for i in range(n): inp.append(input()) result = Counter(inp) print(f"AC x {result['AC']}") print(f"WA x {result['WA']}") print(f"TLE x {result['TLE']}") print(f"RE x {result['RE']}")
s034361766
Accepted
152
9,068
378
n = int(input()) inp = {} for i in range(n): a = input() if inp.get(a) is None: inp[a] = 0 inp[a] += 1 print(f"AC x {0 if inp.get('AC') is None else inp.get('AC')}") print(f"WA x {0 if inp.get('WA') is None else inp.get('WA')}") print(f"TLE x {0 if inp.get('TLE') is None else inp.get('TLE')}") print(f"RE x {0 if inp.get('RE') is None else inp.get('RE')}")
s087507587
p03778
u703890795
2,000
262,144
Wrong Answer
17
2,940
86
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()) m = min(a, b) M = max(a, b) print(max(M-m-2*W, 0))
s266804638
Accepted
17
2,940
84
W, a, b = map(int, input().split()) m = min(a, b) M = max(a, b) print(max(M-m-W, 0))
s538022040
p04043
u628965061
2,000
262,144
Wrong Answer
17
2,940
99
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.
list=list(map(int,input().split())) print("YES" if list.count(7)==2 and list.count(5)==1 else "No")
s721906697
Accepted
17
2,940
99
list=list(map(int,input().split())) print("YES" if list.count(7)==1 and list.count(5)==2 else "NO")
s518650585
p04031
u993161647
2,000
262,144
Wrong Answer
25
2,940
175
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal **integers** by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2). Find the minimum total cost to achieve his objective.
N = input() a = list(map(int,input().split())) for a_i in range(min(a), max(a)+1): cost_sum = 0 for a_j in a: cost_sum += ((a_j - a_i) ** 2) print(cost_sum)
s420694911
Accepted
24
2,940
200
N = int(input()) a = list(map(int,input().split())) cost = [] for i in range(-100, 101): cost_all = 0 for j in a: cost_all += (j - i) ** 2 cost.append(cost_all) print(min(cost))
s256147425
p02392
u800997102
1,000
131,072
Wrong Answer
20
5,584
81
Write a program which reads three integers a, b and c, and prints "Yes" if a < b < c, otherwise "No".
a,b,c=map(int,input().split()) if a<b<c: print("yes") else: print("no")
s470252975
Accepted
20
5,588
81
a,b,c=map(int,input().split()) if a<b<c: print("Yes") else: print("No")
s650326286
p04043
u672882146
2,000
262,144
Wrong Answer
17
3,060
159
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()) box = [a,b,c] count1 = box.count(5) count2 = box.count(7) if count1 == 2 and count2 ==1: print('Yes') else: print('No')
s032273170
Accepted
17
2,940
159
a,b,c=map(int, input().split()) box = [a,b,c] count1 = box.count(5) count2 = box.count(7) if count1 == 2 and count2 ==1: print('YES') else: print('NO')
s091629550
p00002
u877201735
1,000
131,072
Wrong Answer
30
7,544
153
Write a program which computes the digit number of sum of two integers a and b.
while True: try: x = list(map(int, input().split(' '))) n = x[0] * x[1] print(len(str(n))) except EOFError: break
s172369125
Accepted
20
7,604
153
while True: try: x = list(map(int, input().split(' '))) n = x[0] + x[1] print(len(str(n))) except EOFError: break
s202394992
p03470
u902917675
2,000
262,144
Wrong Answer
26
9,164
236
An _X -layered kagami mochi_ (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?
n = int(input()) strlist = [input() for i in range(n)] intlist = [int(x) for x in strlist] sortlist = sorted(intlist) print(sortlist) temp = 0 ans = 0 for d in sortlist: if int(d) > temp: temp = int(d) ans += 1 print(ans)
s300325907
Accepted
29
9,072
219
n = int(input()) strlist = [input() for i in range(n)] intlist = [int(x) for x in strlist] sortlist = sorted(intlist) temp = 0 ans = 0 for d in sortlist: if int(d) > temp: temp = int(d) ans += 1 print(ans)
s056982552
p03567
u077019541
2,000
262,144
Wrong Answer
17
2,940
76
Snuke built an online judge to hold a programming contest. When a program is submitted to the judge, the judge returns a verdict, which is a two-character string that appears in the string S as a contiguous substring. (The judge can return any two-character substring of S.) Determine whether the judge can return the string `AC` as the verdict to a program.
s = [i for i in input()] if "AC"in s: print("Yes") else: print("No")
s916053636
Accepted
17
2,940
63
s = input() if "AC"in s: print("Yes") else: print("No")
s348377999
p03251
u935984175
2,000
1,048,576
Wrong Answer
17
3,060
313
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
def solve(): N, M, X, Y = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) max_x = max(X, max(x)) min_y = min(Y, min(y)) if max_x < min_y: print('NO War') else: print('War') if __name__ == '__main__': solve()
s460418945
Accepted
18
3,064
313
def solve(): N, M, X, Y = map(int, input().split()) x = list(map(int, input().split())) y = list(map(int, input().split())) max_x = max(X, max(x)) min_y = min(Y, min(y)) if max_x < min_y: print('No War') else: print('War') if __name__ == '__main__': solve()
s004498682
p02619
u981418135
2,000
1,048,576
Wrong Answer
42
9,224
494
Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated.
d =int(input()) c = list(map(int, input().split())) s = [] t = [] d_l = [] score = 0 soft = 0 for i in range(d): s.append(0) s[i] = list(map(int, input().split())) for i in range(26): d_l.append(0) for i in range(d): t = int(input()) soft = 0 for j in range(26): if t-1 == j: d_l[j] = 0 score = s[i][j] else: d_l[j] += 1 soft += c[j] * d_l[j] score -= soft print(score)
s233388940
Accepted
34
9,380
495
d =int(input()) c = list(map(int, input().split())) s = [] t = [] d_l = [] score = 0 soft = 0 for i in range(d): s.append(0) s[i] = list(map(int, input().split())) for i in range(26): d_l.append(0) for i in range(d): t = int(input()) soft = 0 for j in range(26): if t-1 == j: d_l[j] = 0 score += s[i][j] else: d_l[j] += 1 soft += c[j] * d_l[j] score -= soft print(score)
s774107349
p03962
u079699418
2,000
262,144
Wrong Answer
25
9,052
46
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.
x = list(map(int,input().split())) len(set(x))
s266391396
Accepted
28
9,040
53
x = list(map(int,input().split())) print(len(set(x)))
s948420493
p04044
u475018333
2,000
262,144
Wrong Answer
17
3,060
268
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
n, l = map(int, input().split()) l = [] i = 0 # while i <= n-1: # list[i] = list(input()) l = [input() for i in range(n)] result = sorted(l) # print('--------------') # print(result) # print('--------------') for i in range(n): print(result[i])
s466027394
Accepted
17
3,060
149
n, l = map(int, input().split()) l = [] i = 0 l = [input() for i in range(n)] result = sorted(l) s = ''.join(result) print(s)
s411139899
p02601
u552116325
2,000
1,048,576
Wrong Answer
30
9,184
257
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
A, B, C = map(int, input().split()) K = int(input()) for i in range(1, K): for ii in range(1, K - i): iii = K - i - ii A = A * (2 ** i) B = B * (2 ** ii) C = C * (2 ** iii) if A < B < C: print('Yes') exit(0) print('No')
s760079776
Accepted
25
8,780
251
A, B, C = map(int, input().split()) K = int(input()) for i in range(K): for ii in range(K - i): iii = K - i - ii a = A * (2 ** i) b = B * (2 ** ii) c = C * (2 ** iii) if a < b < c: print('Yes') exit(0) print('No')
s289680103
p03471
u360258922
2,000
262,144
Wrong Answer
17
3,064
363
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
n, y = map(int, input().split(' ')) s_n = [0, 0, 0] s_l = [10000, 5000, 1000] for i, s in enumerate(s_l): if n > -1: s_n[i] = int(y/s) n = n - s_n[i] y = y - s * s_n[i] else: print('-1 -1 -1') if n > -1: if y == 0: print(' '.join(map(str, s_n))) else: print('-1 -1 -1') else: print('-1 -1 -1')
s166574741
Accepted
897
3,064
346
N, Y = map(int, input().split(' ')) res10000 = -1 res5000 = -1 res1000 = -1 for a in range(N+1): for b in range(N-a+1): c = N - a - b total = 10000*a + 5000*b + 1000*c if total == Y: res10000 = a res5000 = b res1000 = c print(str(' '.join(map(str, [res10000, res5000, res1000]))))
s792114792
p02613
u607114738
2,000
1,048,576
Wrong Answer
166
16,176
209
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) S = [] for i in range(N): s = str(input()) S.append(s) result = ['AC', 'WA', 'TLE', 'RE'] C = [S.count(r) for r in result] for (re, c) in zip(result, C): print(re + 'x' + str(c))
s963150043
Accepted
164
16,128
211
N = int(input()) S = [] for i in range(N): s = str(input()) S.append(s) result = ['AC', 'WA', 'TLE', 'RE'] C = [S.count(r) for r in result] for (re, c) in zip(result, C): print(re + ' x ' + str(c))
s768306166
p03360
u595893956
2,000
262,144
Wrong Answer
18
2,940
83
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: * Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K operations?
a,b,c=map(int,input().split()) print(max(a,b,c)*(2**int(input())+a+b+c-max(a,b,c)))
s280016961
Accepted
17
2,940
84
a,b,c=map(int,input().split()) print(max(a,b,c)*(2**int(input()))+a+b+c-max(a,b,c))
s628626227
p02237
u067677727
1,000
131,072
Wrong Answer
20
7,508
433
There are two standard ways to represent a graph $G = (V, E)$, where $V$ is a set of vertices and $E$ is a set of edges; Adjacency list representation and Adjacency matrix representation. An adjacency-list representation consists of an array $Adj[|V|]$ of $|V|$ lists, one for each vertex in $V$. For each $u \in V$, the adjacency list $Adj[u]$ contains all vertices $v$ such that there is an edge $(u, v) \in E$. That is, $Adj[u]$ consists of all vertices adjacent to $u$ in $G$. An adjacency-matrix representation consists of $|V| \times |V|$ matrix $A = a_{ij}$ such that $a_{ij} = 1$ if $(i, j) \in E$, $a_{ij} = 0$ otherwise. Write a program which reads a directed graph $G$ represented by the adjacency list, and prints its adjacency-matrix representation. $G$ consists of $n\; (=|V|)$ vertices identified by their IDs $1, 2,.., n$ respectively.
def main(): n = int(input()) adj = [[0 for i in range(n)] for j in range(n)] for i in range(n): tmp = list(map(int, input().split())) u = tmp[0] u = u -1 k = tmp[1] v = tmp[2:] for j in range(k): adj[u][v[j]-1] = 1 for i in range(n): print(" ".join(list(map(str, adj[i])))) for i in adj: print(*i) if __name__ == "main": main()
s820746948
Accepted
30
8,528
365
def main(): n = int(input()) adj = [[0 for i in range(n)] for j in range(n)] for i in range(n): tmp = list(map(int, input().split())) u = tmp[0] u = u -1 k = tmp[1] v = tmp[2:] for j in range(k): adj[u][v[j]-1] = 1 for i in adj: print(*i) if __name__ == "__main__": main()
s366739912
p04043
u679817762
2,000
262,144
Wrong Answer
25
8,964
159
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.
lst = input().split() for i in lst: i = int(i) lst.sort() if lst == [5, 5, 7]: print('YES') else: print('NO')
s423017142
Accepted
27
8,996
184
lst = input().split() for i in range(len(lst)): lst[i] = int(lst[i]) lst.sort() if lst == [5, 5, 7]: print('YES') else: print('NO')
s010751876
p02613
u934609868
2,000
1,048,576
Wrong Answer
157
9,108
319
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(1,N+1): S = str(input()) if S == "AC": ac += 1 elif S == "WA": wa += 1 elif S == "TLE": tle += 1 elif S == "RE": re += 1 print("AC × " + str(ac)) print("WA × " + str(wa)) print("TLE × " + str(tle)) print("AC × " + str(re))
s527442766
Accepted
155
9,204
305
N = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(1,N+1): S = str(input()) if S == "AC": ac += 1 elif S == "WA": wa += 1 elif S == "TLE": tle += 1 else: re += 1 print("AC x " + str(ac)) print("WA x " + str(wa)) print("TLE x " + str(tle)) print("RE x " + str(re))
s225758895
p02608
u383450070
2,000
1,048,576
Wrong Answer
2,206
8,972
260
Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: * 1 \leq x,y,z * x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N, find each of f(1),f(2),f(3),\ldots,f(N).
import math n=int(input()) for p in range(1, n): right=math.floor(p*0.5) cnt=0 for i in range(right): for j in range(right): for k in range(right): if i**2+j**2+k**2+i*j+j*k+k*i==p and i>0 and j>0 and k>0: cnt+=1 print(cnt)
s644877205
Accepted
326
87,396
445
n=int(input()) lst=[0]*10000000 for i in range(1, 101): for j in range(1, i+1): for k in range(1, j+1): temp=i**2+j**2+k**2+i*j+j*k+k*i if i==j and j==k: lst[temp+1]+=1 elif i==j and j!=k: lst[temp+1]+=3 elif j==k and k!=i: lst[temp+1]+=3 elif k==i and i!=j: lst[temp+1]+=3 elif i!=j and j!=k and k!=i: lst[temp+1]+=6 for p in range(1, n+1): print(lst[p+1])
s958124187
p03251
u013408661
2,000
1,048,576
Wrong Answer
18
3,064
289
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
n,m,x,y=map(int,input().split()) X=list(map(int,input().split())) Y=list(map(int,input().split())) X.sort() Y.sort() Z=[i for i in range(x+1,y)] if X[-1]<Y[0]: z=[i for i in range(X[-1]+1,Y[0])] if len(set(z)&set(Z))>0: print("No War") else: print("War") else: print("War")
s757074647
Accepted
17
3,064
293
n,m,x,y=map(int,input().split()) X=list(map(int,input().split())) Y=list(map(int,input().split())) X.sort() Y.sort() Z=[i for i in range(x+1,y+1)] if X[-1]<Y[0]: z=[i for i in range(X[-1]+1,Y[0]+1)] if len(set(z)&set(Z))>0: print("No War") else: print("War") else: print("War")
s207202617
p03672
u766566560
2,000
262,144
Time Limit Exceeded
2,104
7,920
132
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() while True: if S[0:len(S)//2] == S[len(S)//2:len(S)-1]: print(len(S)) else: tmp = S[0:len(S)-2] S = tmp
s959416781
Accepted
18
3,060
179
S = input() cnt = 0 for i in range(len(S)): if S[0:len(S)//2] == S[len(S)//2:len(S) + 1] and cnt != 0: print(len(S)) exit() else: cnt += 1 S = S[0:len(S) - 1]
s965636195
p03854
u912652535
2,000
262,144
Wrong Answer
18
3,188
133
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().replace("eracer",'').replace('erace','').replace('dreamer','').replace('dreame','') print('YES' if len(s) == 0 else 'NO')
s792240276
Accepted
18
3,188
132
s = input().replace("eraser",'').replace('erase','').replace('dreamer','').replace('dream','') print('YES' if len(s) == 0 else 'NO')
s447431732
p02612
u542541293
2,000
1,048,576
Wrong Answer
26
9,148
54
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()) q, mod = divmod(N, 1000) print(mod)
s301950579
Accepted
28
9,156
91
N = int(input()) q, mod = divmod(N, 1000) if mod == 0: print(0) else: print(1000-mod)
s643980636
p02678
u970267139
2,000
1,048,576
Wrong Answer
739
60,204
433
There is a cave. The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside. It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage. Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1. * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible. Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
n, m = map(int, input().split()) edge = [list(map(int, input().split())) for _ in range(m)] next_node = [[] for _ in range(n)] for a, b in edge: next_node[a-1].append(b) next_node[b-1].append(a) q = [1] visit = [1] + [0] * (n-1) prev = [0]*n while q: now = q.pop() for i in next_node[now-1]: if visit[i-1] == 0: q.append(i) visit[i-1] = 1 prev[i-1] = now print(prev[1:])
s508278624
Accepted
1,375
59,588
460
n, m = map(int, input().split()) edge = [list(map(int, input().split())) for _ in range(m)] next_node = [[] for _ in range(n)] for a, b in edge: next_node[a-1].append(b) next_node[b-1].append(a) q = [1] visit = [1] + [0] * (n-1) prev = [0] * n while q: now = q.pop(0) for i in next_node[now-1]: if visit[i-1] == 0: q.append(i) visit[i-1] = 1 prev[i-1] = now print('Yes') print(*prev[1:], sep='\n')
s512210561
p02613
u426250125
2,000
1,048,576
Wrong Answer
154
16,324
243
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) status={'AC':0, 'WA':0, 'TLE':0, 'RE':0} results = [input() for n in range(N)] for result in results: if result in status.keys(): status[result] += 1 for k, v in status.items(): print('{} × {}'.format(k, v))
s664742060
Accepted
155
16,332
242
N = int(input()) status={'AC':0, 'WA':0, 'TLE':0, 'RE':0} results = [input() for n in range(N)] for result in results: if result in status.keys(): status[result] += 1 for k, v in status.items(): print('{} x {}'.format(k, v))
s781785263
p03494
u044916426
2,000
262,144
Wrong Answer
18
3,188
230
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.
li = list(map(int, input().split())) a = 0 br = False while True: for i in li: if i % 2 != 0: br = True break if br: break a += 1 li = list(map(lambda x: x / 2, li)) print(a)
s070153938
Accepted
19
2,940
247
n = int(input()) li = list(map(int, input().split())) a = 0 br = False while True: for i in li: if i % 2 != 0: br = True break if br: break a += 1 li = list(map(lambda x: x / 2, li)) print(a)
s023220865
p00033
u945345165
1,000
131,072
Wrong Answer
20
7,628
1,053
図のように二股に分かれている容器があります。1 から 10 までの番号が付けられた10 個の玉を容器の開口部 A から落とし、左の筒 B か右の筒 C に玉を入れます。板 D は支点 E を中心に左右に回転できるので、板 D を動かすことで筒 B と筒 C のどちらに入れるか決めることができます。 開口部 A から落とす玉の並びを与えます。それらを順番に筒 B 又は筒 Cに入れていきます。このとき、筒 B と筒 C のおのおのが両方とも番号の小さい玉の上に大きい玉を並べられる場合は YES、並べられない場合は NO と出力するプログラムを作成してください。ただし、容器の中で玉の順序を入れ替えることはできないものとします。また、続けて同じ筒に入れることができるものとし、筒 B, C ともに 10 個の玉がすべて入るだけの余裕があるものとします。
import sys def solve(balls): ans = distribute(balls, [], []) if ans is True: print('YES') else: print("NO") def distribute(balls, R, L): if len(balls) != 0: next = balls[0] ans = False #case R if isMutch(next, R): neoR = R neoR.append(next) ans = distribute(balls[1:], neoR, L) if isMutch(next, L): neoL = L neoL.append(next) ans =distribute(balls[1:], R, neoL) if ans: return True else: return isOrdered(R) and isOrdered(L) def isMutch(next, lis): if len(lis) != 0: return next > lis[len(lis)-1] return True def isOrdered(lis): #check both R and L are ordered checker = sorted(lis) return checker == lis limit = 2**11 sys.setrecursionlimit(limit) line = input() size = -1; while True: if size == -1: size = int(line) else: solve(line.split(' ')) size -= 1 print(size) if size == 0: break line = input()
s034515552
Accepted
20
7,616
568
import sys def solve(balls): if distribute(balls, 0, 0): print('YES') else: print('NO') def distribute(balls, lastR, lastL): if len(balls) != 0: next = balls[0] if next>lastR: if distribute(balls[1:], next, lastL): return True if next>lastL: if distribute(balls[1:], lastR, next): return True else: return True sys.setrecursionlimit(2**11) size = int(input()); for i in range(size): balls = [] for a in input().split(' '): balls.append(int(a)) solve(balls)
s591735661
p03386
u167681750
2,000
262,144
Wrong Answer
2,103
3,064
98
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()) print([i for i in range(A, B + 1) if A + K > i or B - K < i])
s718187739
Accepted
17
3,060
148
A, B, K = map(int, input().split()) for i in range(A, min(A + K, B + 1)): print(i) for i in range(max(B - K + 1, A + K), B + 1): print(i)
s983747858
p02612
u346812984
2,000
1,048,576
Wrong Answer
29
9,156
230
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.
import sys sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(input()) print(N % 1000) if __name__ == "__main__": main()
s576769307
Accepted
34
9,160
290
import sys sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(input()) if N % 1000 == 0: print(0) else: print(1000 - N % 1000) if __name__ == "__main__": main()