problem_id
stringclasses
428 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
5
816
p03317
s146139589
Accepted
N, K = map(int, input().split()) A = list(map(int, input().split())) if((N-1)%(K-1) == 0): print((N-1)//(K-1)) else: print((N-1)//(K-1) + 1)
p02658
s269623824
Accepted
input();ans,a=1,[*map(int,input().split())] if 0 in a: print(0) else: for i in a: ans*=i if ans>10**18: print(-1);break else: print(ans)
p04012
s809159191
Accepted
e = input() set_e = set(e) is_beautiful = 'Yes' for i in set_e: if e.count(i)%2 == 1: is_beautiful = 'No' break else: pass print(is_beautiful)
p02910
s864405058
Wrong Answer
a=input() if a[1::2] in ['R','U','D'] and a[2::2] in ['L','U','D']: print('Yes') else: print('No')
p02797
s287414896
Accepted
#!python3 iim = lambda: map(int, input().rstrip().split()) def NKS(N, K, S): M5 = 10**5 M9 = 10**9 for i in range(K): yield S tmp = S + 1 if S < M9 else 1 for i in range(N-K): yield tmp def resolve(): N, K, S = iim() it = NKS(N, K, S) for i in range(N-1): print(next(it), end=" ") print(next(it)) if __name__ == "__main__": resolve()
p03778
s340313600
Accepted
W, A, B = [int(i) for i in input().split()] if B <= A <= B+W or B <= A+W <= B+W or A <= B <= A+W or A <= B+W <= A+W: print(0) elif W + A <= B: print(B - (W + A)) else: print(A - (B + W))
p04031
s542854024
Accepted
num = int(input()) input_num = input() num_list = [int(i) for i in input_num.split(" ")] num_list.sort() min = num_list[0] max = num_list[num-1] if min== max: print(0) exit() min_sum = 100**3 for i in range(min,max): temp_sum = 0 for j in range(0,num): temp_sum += (num_list[j] - i)**2 if min_sum>temp_sum: min_sum = temp_sum print(min_sum)
p03779
s565325249
Wrong Answer
x = int(input()) for i in range(0,10000): ix = i*(i+1)/2 if x <= ix : print(i) exit()
p03852
s318620256
Wrong Answer
c = input() if "c" == "a" or "c" == "e" or "c" == "i" or "c" == "o" or "c" == "u": print("vowel") else: print("consonant")
p03012
s721363296
Wrong Answer
n = int(input()) w = list(map(int, input().split())) x = 0 for i in range(n): x += w[i] y = w[0] for j in range(n - 1): if abs(2 * y - x) >= abs(2 * (y + w[j + 1]) - x): y += w[j + 1] print(abs(2 * y - x))
p03417
s879483321
Wrong Answer
n,m = map(int,input().split()) print((n-2)*(m-2))
p02813
s835193894
Wrong Answer
import math N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) def calc_bango(lst): ban = 0 for i in range(N): ban += lst[i]*math.factorial(N-i-1) return(ban) a = calc_bango(P) b = calc_bango(Q) print(abs(a-b))
p02935
s930467467
Accepted
a = list(map(int,input().split())) b = list(map(int,input().split())) a=a[0] p = 0 a=a-1 b.sort() for i in range(a): p=(b[i]+b[i+1])/2 b[i+1]=p print(b[a])
p04011
s608971733
Wrong Answer
n=int(input()) k=int(input()) x=int(input()) y=int(input()) fees=0 if(k>n): for i in range(0,n): fees+=x elif(k<n): diff=n-k for j in range(0,k): fees+=x for k in range(0,diff): fees+=y print(fees)
p02553
s293634615
Accepted
a,b,c,d = map(int,input().split()) ans = [a*c, a*d, b*c, b*d] print(max(ans))
p03274
s098841211
Accepted
N,K = [int(x) for x in input().split()] l = [int(x) for x in input().split()] ans = 100000000000 for i in range(N-K+1): le = l[i] ri = l[i+K-1] ans = min(ans,abs(le)+abs(ri-le),abs(ri)+abs(ri-le)) print(ans)
p02725
s096144109
Accepted
n,m=map(int,input().split()) lis=list(map(int,input().split())) li=[lis[i+1]-lis[i] for i in range(m-1)] li.append(n-lis[-1]+lis[0]) print(sum(li)-max(li))
p04005
s011862912
Accepted
A,B,C = map(int,input().split()) if A%2 == 0 or B%2 ==0 or C%2 ==0: print(0) else: print(min(A*B,B*C,A*C))
p04033
s343611657
Accepted
a, b = map(int, input().split()) if b < 0: if (b - a) % 2 == 0: print("Negative") else: print("Positive") elif a <= 0: print("Zero") else: print("Positive")
p02987
s602976800
Wrong Answer
l = input() if l[0]==l[2] and l[1]==l[3]: print('Yes') elif l[0]==l[3] and l[1]==l[2]: print('Yes') elif l[0]==l[1] and l[2]==l[3]: print('Yes') else: print('No')
p03328
s235510695
Accepted
a, b = map(int, input().split()) n = b-a-1 num = 0 for i in range(1,n+1): num += i print(num-a)
p02833
s534267857
Accepted
N = int(input()) count = 0 div = 10 if N % 2 == 0: for i in range(1, 26): count += N // div div *= 5 print(count)
p02630
s974203898
Wrong Answer
# coding: utf-8 n = int(input()) list_a = map(int, input().split()) q = int(input()) for i in range(q): b, c = map(int, input().split()) list_a = list(map(lambda a: c if a==b else a, list_a)) print(sum(list_a))
p02699
s991594124
Accepted
s,w=map(int,input().split()) if w>=s: print("unsafe") exit() print("safe")
p02723
s605267358
Accepted
a = input() b = [] for z in a: b.append(z) if b[2]==b[3]: if b[4]==b[5]: print("Yes") else: print("No") else: print("No")
p03997
s885226648
Accepted
a = int(input()) b = int(input()) h = int(input()) answer = int((a + b) * h / 2) print(answer)
p03087
s407191316
Accepted
N, Q = map(int, input().split()) S = input() C=[0]*(N) c=0 for i in range(len(S)-1): if S[i:i+2]=="AC": c += 1 C[i] = c #print(C) for q in range(Q): l, r = map(int, input().split()) l, r = l-1, r-1 ans = C[r-1] - C[l-1] print(ans)
p02628
s477497521
Wrong Answer
n,k=map(int,input().split()) P=list(map(int,input().split())) P.sort() print(sum(P[0:3]))
p02787
s517060938
Accepted
h, n = map(int, input().split()) dp = [float('inf')] * (h+1) for _ in range(n): damage, mp = map(int, input().split()) for i in range(h+1): if i <= damage: dp[i] = min(dp[i], mp) else: dp[i] = min(dp[i], dp[i-damage] + mp) print(dp[h])
p03359
s388384459
Wrong Answer
a,b=map(int,input().split()) print(min(a,b))
p02602
s880742470
Wrong Answer
n=list(map(int,input().strip().split())) m=list(map(int,input().strip().split())) for i in range(n[1],n[0]): if(m[i]>m[i-1]): print("Yes") else: print("No")
p03427
s078032135
Wrong Answer
n = input() n_list = [int(i) for i in n] ans = 0 if len(n) == 1: print(n) else: if sum(n_list[1:]) == (len(n)-1)*9: ans = sum(n_list) else: ans = n_list[0]-1 + (len(n_list)-1)*9 print(ans)
p03796
s832416146
Accepted
n = int(input()) ans = 1 for i in range(n): ans *= i + 1 ans %= 10**9 + 7 print(ans)
p02811
s420496880
Wrong Answer
x,y = map(int,input().split()) if(x*500<y): print("NO") else: print("YES")
p03817
s236799410
Accepted
import sys def I(): return int(sys.stdin.readline().rstrip()) x = I()-1 print(x//11*2+1+(x%11)//6)
p02897
s892674365
Accepted
n = int(input()) if n % 2 == 0: print(0.5) else: print(((n - 1) // 2 + 1) / n)
p03545
s724735020
Wrong Answer
s=input() a=int(s[0]) b=int(s[1]) c=int(s[2]) d=int(s[3]) if a+b+c+d==7: print("%d+%d+%d+%d=7"%(a,b,c,d)) exit()
p02860
s669720881
Wrong Answer
N = int(input()) S = list(input()) a = 0 if N == 1: print("No") else: for i in range(len(S)//2): if S[i] != S[i+(len(S)//2)]: a = a+1 if a == 0: print("Yes") else: print("No")
p02994
s384609781
Accepted
n,l = map(int,input().split()) t = n*l-n+(1+n)*n//2 a = l+n-1 if 0 < l: print(t-l) elif a < 0: print(t-a) else: print(t)
p03360
s628810654
Accepted
A=list(map(int,input().split())) K=int(input()) A.sort(reverse=True) ans=sum(A) for i in range(K): ans+=A[0] A[0]*=2 print(ans)
p03804
s360720373
Accepted
import numpy as np n, m = map(int, input().split()) X = [input() for _ in range(n)] np_x = np.zeros((n, n), dtype=int) for i in range(n): for j in range(n): np_x[i, j] = X[i][j] == '.' Y = [input() for _ in range(m)] np_y = np.zeros((m, m), dtype=int) for i in range(m): for j in range(m): np_y[i, j] = Y[i][j] == '.' for i in range(n-m+1): for j in range(n-m+1): if np.all(np_x[i:i+m, j:j+m] == np_y): print('Yes') exit() else: print('No')
p03469
s917648291
Wrong Answer
import sys input = sys.stdin.readline s=input().strip() print("2017"+s[4:])
p02664
s338994454
Wrong Answer
T = input() for i in range(0, len(T)): if T[0] == "P": first = "P" second = "D" else: first = "D" second = "P" for i in range(0, len(T)): if T[i] == "?": if i % 2 == 0: T = T.replace("?", first) else: T = T.replace("?", second) print(T)
p02615
s509434323
Accepted
import copy from collections import deque N = int(input()) A = list(map(int, input().split())) A.sort(reverse = True) d = deque() c = 0 count = 2 ans = 0 for k in range(N-1): ans += A[ (k+1) // 2] print(ans)
p02556
s872082397
Wrong Answer
n=int(input()) xy=[list(map(int,input().split())) for _ in range(n)] d=[x+y for x,y in xy] d.sort() ans=d[-1]-d[0] maxy=max([y for x,y in xy]) dr=[x+(maxy-y) for x,y in xy] ans=max(ans,dr[-1]-dr[0]) print(ans)
p02835
s577762853
Accepted
a, b, c = map(int, input().split()) ans = a + b + c if ans > 21: print('bust') else: print('win')
p02860
s215821083
Wrong Answer
n=int(input()) s=input() if(n%2==1): print('No') exit() else: if s[0:n//2]==s[(n//2)+1:n]: print('Yes') else: print("No")
p02684
s837511093
Accepted
import sys n, k = map(int, input().split()) ara = [0] ara += list( map(int, input().split()) ) now = 1 vis = [] taken = [0]*(n+1) while taken[now] == 0: vis.append(now) taken[now] = 1 now = ara[now] cycleLen = len(vis) - vis.index(now) if k < vis.index(now): print(vis[k]) sys.exit() k -= vis.index(now) k %= cycleLen print(vis[k + vis.index(now) ])
p04033
s221709869
Accepted
a,b = map(int,input().split()) if 0 < a <= b: print("Positive") elif a <= b < 0: if (b - a + 1) % 2 == 0: print("Positive") else: print("Negative") else: print("Zero")
p02787
s420266376
Wrong Answer
import numpy as np W, N = map(int,input().split()) items = [[int(x) for x in reversed(input().split())] for _ in range(N)] INF = 10 ** 4 dp = [[INF for i in range(W+1)] for j in range(N+1)] for i in range(N+1): dp[i][0] = 0 for i in range(1,N+1): #1<= i <= N for j in range(1, W+1): # 1 <= j <= W dp[i][j] = min(dp[i-1][j], dp[i-1][max(j - items[i-1][1],0)] + items[i-1][0], dp[i][max(j - items[i-1][1],0)] + items[i-1][0]) print(dp[N][W])
p03417
s893805541
Accepted
N,M=map(int,input().split()) if N==1: if M==1: print(1) else: print(M-2) elif M==1: print(N-2) else: print(N*M+4-2*N-2*M)
p02817
s902689021
Wrong Answer
print(input().replace(' ', ''))
p03672
s129837876
Accepted
s=input() n=len(s) for i in range(1,n): if (n-i)%2==0: m=(n-i)//2 if s[:m]==s[m:n-i]: print(n-i) exit()
p03038
s219831267
Accepted
n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() bc=[list(map(int,input().split())) for i in range(m)] bc.sort(key=lambda x:x[1],reverse=True) d=[] i=0 while i<m and len(d)<n: d+=[bc[i][1]]*bc[i][0] i+=1 d=d[:n] s=sum(a) ans=s for x in range(min(n,len(d))): s+=d[x]-a[x] ans=max(ans,s) print(ans)
p03243
s672793043
Accepted
N = int(input()) a = 0 for i in range(N,1000): if i == 111 or i == 222 or i == 333 or i ==444 or i ==555 or i == 666 or i ==777 or i ==888 or i == 999: a = i break print(a)
p03211
s968790149
Accepted
S = input() masterNum = 753 minNum = 1000 for i in range(len(S)-2): digit = int(S[i:i+3]) diff = abs(digit - masterNum) if diff < minNum: minNum = diff print(minNum)
p03206
s653413807
Accepted
D=int(input()) if D==25: print('Christmas') elif D==24: print('Christmas Eve') elif D==23: print('Christmas Eve Eve') elif D==22: print('Christmas Eve Eve Eve')
p02766
s422965733
Accepted
inputs = input().split() n = int(inputs[0]) k = int(inputs[1]) cnt = 1 while n >= k: n = n // k cnt += 1 print(cnt)
p02701
s799834881
Accepted
def prb2(): a,b,c,d = map(int,input().split()) t = (a+b) ak = (c+d) print('Yes' if t>ak else "No") def prb3(): n = int(input()) d = set() for i in range(n): s = input() d.add(s) print(len(d)) #prb1() #prb2() prb3()
p02713
s124293416
Accepted
import math n = int(input()) sum = 0 memo = {'1,1':1} for i in range(1, n+1): for j in range(1, n+1): if str(i)+','+str(j) in memo: ret = memo[str(i)+','+str(j)] elif str(j)+','+str(i) in memo: ret = memo[str(j)+','+str(i)] else: ret = math.gcd(i, j) memo[str(i)+','+str(j)] = ret memo[str(j)+','+str(i)] = ret for i in memo.values(): for j in range(1, n+1): sum += math.gcd(i, j) print(sum)
p03328
s748977337
Accepted
a, b = map(int, input().split()) nb = b - a lb = nb*(nb + 1)//2 print(lb - b)
p03073
s243025272
Accepted
S = list(input()) a=0 b=0 for i in S[::2]: if i=="1": a+=1 for k in S[1::2]: if k=="0": a+=1 for i in S[::2]: if i=="0": b+=1 for k in S[1::2]: if k=="1": b+=1 print(min(a,b))
p02612
s064243069
Accepted
n=int(input()) t=n%1000 if t==0: print(0) else: print(1000-t)
p02645
s024104659
Accepted
a=input() b=list(a) c=b[0:3] d="".join(c) print(d)
p02748
s420894335
Accepted
A, B, M = map(int, input().split()) al = list(map(int, input().split())) bl = list(map(int, input().split())) ans = min(al) + min(bl) for _ in range(M): a, b, m = list(map(int, input().split())) ans = min(ans, al[a-1]+bl[b-1]-m) print(ans)
p02546
s839278517
Accepted
s= input() if s.endswith('s'): print(s+'es') else: print(s+'s')
p02682
s838085553
Accepted
A, B, C, K = map(int, input().split()) count = 0 if K >= A: count += A K -= A else: count = K K = 0 if K != 0: if K>=B: K -= B else: K= 0 if K != 0: count -= K print(count)
p03760
s272768683
Wrong Answer
O = input() E = input() ans = "" for o, e in zip(O, E): ans += o + e print(ans)
p02918
s224693359
Accepted
n,k = map(int, input().split()) S = input() ans = [] c = 1 # RL圧縮 for i in range(1,n): if S[i-1] == S[i]: c += 1 else: ans.append(c) c = 1 ans.append(c) # ansの個数は1個毎に減っていく if len(ans) // 2 <= k: print(n-1) else: d = len(ans) - 2*k print(n-d)
p04045
s548416614
Accepted
def solve(): n,k = map(int,input().split()) d = set(map(int,input().split())) for i in range(n,100000): s = map(int,str(i)) flag = True for j in s: if j in d: flag = False if flag: print(i) return if __name__ == "__main__": solve()
p02547
s693693967
Accepted
n = int(input()) ans = 0 f1, f2, f3 = 0, 0, 0 for i in range(n): f3 = f2 f2 = f1 d1, d2 = map(int, input().split()) f1 = d1 == d2 if f1 == f2 == f3 == 1: ans = 1 print('Yes' if ans else 'No')
p02682
s242933034
Accepted
a, b, c, k = map(int, input().split()) if k <= a+b: print(min(a, k)) else: print(a-(k-a-b))
p03565
s280979093
Accepted
S = input() T = input() length = len(T) results = [] for i in range(len(S)-length+1): flag = True for s, t in zip(S[i:i+length], T): if s == "?": continue if s != t: flag = False break if flag: results.append(S[:i] + T + S[i+length:]) if len(results) == 0: print("UNRESTORABLE") else: results = [res.replace("?", "a") for res in results] results.sort() print(results[0])
p03012
s105013403
Accepted
n=int(input()) w=tuple(map(int,input().split())) t=sum(w) key = 0 while t > 0: prev = t t -= w[key]*2 key += 1 print(min(abs(t), prev))
p03986
s552826289
Wrong Answer
s = input() s_cnt, t_cnt = 0, 0 ans = 0 for i in range(len(s)): if s[i] == "S": s_cnt += 1 else: t_cnt += 1 if i == len(s) - 1 or s[i + 1] == "S": ans += min(t_cnt, s_cnt) t_cnt = 0 s_cnt = max(0, s_cnt - t_cnt) print(len(s) - ans * 2)
p03037
s695751627
Wrong Answer
n,m = map(int, input().split()) minn, maxn = 1, n for i in range(m): l, r = map(int,input().split()) minn, maxn = max(minn, l), min(maxn, r) print(maxn-minn+1)
p02675
s499197884
Wrong Answer
chk = input() if str(chk)[-1] == '3': print('bon') if str(chk)[-1] in ('0', '1', '6', '8'): print('pon') else: print('hon')
p02646
s978027966
Accepted
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if v <= w: print('NO') else: if abs(a - b) /(v - w) <= t: print('YES') else: print('NO')
p02911
s552251726
Wrong Answer
n,k,q=map(int,input().split()) life=[k-q]*n for i in range(q): tem=int(input()) life[tem-1]+=1 for j in life: print('YNEOS'[j<=0::2])
p02693
s566408926
Accepted
k = int(input()) a,b = map(int, input().split()) flg = False for i in range(a,b+1): if i%k == 0: flg = True if flg: print('OK') else: print('NG')
p02787
s712867773
Accepted
import sys input = sys.stdin.readline H, N = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] dp = [10**14]*(H+1) dp[0] = 0 for a, b in AB: for i in range(H+1): if i < a: if dp[i] > b: dp[i] = b else: if dp[i] > dp[i-a]+b: dp[i] = dp[i-a]+b print(dp[H])
p03433
s079398266
Wrong Answer
N = int(input()) A = int(input()) N //= 500 print("Yes" if N <= A else "No")
p02970
s842613993
Wrong Answer
a,b=map(int,input().split()) for i in range(21): l=(b+1)*i if l>=a: print(i)
p02631
s676982789
Accepted
t=int(input()) n=list(map(int,input().split())) xor=0 for x in n: xor^=x for x in n: print(x^xor,end=" ")
p02888
s458546576
Wrong Answer
import bisect n = int(input()) l_list = list(map(int,input().split())) ans = 0 for i in range(n): for j in range(i+1 , n): ans += bisect.bisect_left(l_list,l_list[i] + l_list[j]) -j -1 print(ans)
p03041
s086604696
Wrong Answer
a,b=map(int,input().split()) c=list(input()) if c[b-1]=='A': c[b-1]='a' elif c[b-1]=='B': c[b-1]='b' else: c[b-1]='c' print(c)
p03607
s853912121
Wrong Answer
N = int(input()) A = [int(input()) for i in range(N)] B = 0 for i in A: if A.count(i)%2 == 1: B += 1 else: while i in A:A.remove(i) print(B)
p02718
s544993614
Wrong Answer
n,m=map(int,input().split()) l=list(map(int,input().split())) s=sum(l)//(4*m) c=0 for i in range(n): if(l[i]>=s): c=c+1 if(c>=m): print("Yes") else: print("No")
p03162
s770779162
Accepted
N=int(input()) abc=[[] for _ in range(N)] for i in range(N): abc[i]=list(map(int,input().split())) dp=[[0,0,0] for _ in range(N+1)] for i in range(1,N+1): for j in range(3):#新しく選ぶもの for k in range(3):#選ぶもの if k!=j: dp[i][j]=max(dp[i][j] , dp[i-1][k]+abc[i-1][k]) print(max(dp[-1]))
p03495
s381803913
Accepted
from collections import defaultdict N, K = map(int, input().split()) nums = [int(i) for i in input().split()] num_freq = defaultdict(int) for num in nums: num_freq[num] += 1 _sorted_nums = [[i] * j for i, j in sorted(num_freq.items(), key=lambda x:x[1])] sorted_nums = [] for i in _sorted_nums: sorted_nums += i borders = [] for i in range(1, N): if sorted_nums[i-1] != sorted_nums[i]: borders.append(i) if len(num_freq) <= K: print(0) else: print(borders[-K])
p03379
s580982954
Accepted
N = int(input()) X = [int(i) for i in input().split()] indexes = [i for i in range(N)] sorted_indexes = sorted(indexes, key=lambda i: X[i]) for i in range(N): if X[i] <= X[sorted_indexes[int(N / 2)-1]]: print(X[sorted_indexes[int(N / 2)]]) else: print(X[sorted_indexes[int(N / 2)-1]])
p02570
s964068231
Wrong Answer
d,t,s=map(int,input().split()) temp1=d//t if temp1==s: print("YES") else: print("NO")
p02615
s614853741
Wrong Answer
input = raw_input n = int(input()) nums = map(int, input().split(" ")) out = sum(nums) - min(nums) print(out)
p03352
s442995065
Wrong Answer
x = int(input()) if x == 1: print("1") exit() ans = 0 for b in range(2,int(x**(1/2)+1)): for p in range(2,1000): tmp = pow(b,p) if tmp<=x: ans = max(ans,pow(b,p)) break print(ans)
p02775
s608619067
Accepted
n=input() k=len(n) dp=[[0]*2 for _ in range(k)] dp[0][0]=min(int(n[0]),11-int(n[0])) dp[0][1]=min(int(n[0])+1,11-(int(n[0])+1)) for i in range(1,k): dig=int(n[i]) dp[i][0]=min(dp[i-1][0]+dig,dp[i-1][1]+10-dig) dp[i][1]=min(dp[i-1][0]+dig+1,dp[i-1][1]+10-(dig+1)) print(dp[k-1][0])
p03797
s195967972
Accepted
N, M = map(int, input().split()) ans = min(M//2, N) M = M - 2*ans ans += M//4 print(ans)
p02789
s102456043
Accepted
N,M = map(int,input().split()) if N==M: print("Yes") else: print("No")
p03796
s111625720
Accepted
import math n = int(input()) print(math.factorial(n) % (10**9 + 7))
p02725
s162300903
Accepted
k, n = map(int, input().split()) a = [int(x) for x in input().split()] diff = [a[i + 1] - a[i] for i in range(n - 1)] + [k - a[-1] + a[0]] ans = sum(diff) - max(diff) print(ans)
p02639
s245868145
Accepted
a=list(map(int,input().split())) for num in range(len(a)): if a[num]==0: print(num+1)