problem_id
stringclasses
428 values
submission_id
stringlengths
10
10
status
stringclasses
2 values
code
stringlengths
5
816
p03471
s636303616
Accepted
a, b , c = -1,-1,-1 n, y = map(int,input().split()) for i in range(n+1): for j in range(n+1): if i+ j > n: break elif ((y - (i*10000 + j*5000))%1000 == 0) and ((i+j+(y - (i*10000 + j*5000))/1000) == n): if (y - (i*10000 + j*5000))/1000 >= 0: a,b,c = i, j, int((y - i*10000 - j*5000)/1000) break print(a, b, c)
p02555
s733930597
Accepted
S = int(input()) A = [0] * (2001) A[3] = 1 mod = 10**9+7 for i in range(4, S+1): A[i] = A[i-1] + A[i-3] A[i] %= mod print(A[S])
p02688
s718641288
Accepted
N,K = list(map(int,input().split())) lst = [0]*N for i in range(K): d = int(input()) for Ai in list(map(int,input().split())): lst[Ai-1] += 1 ans = 0 for num in lst: if num == 0: ans += 1 print(ans)
p02572
s089233411
Wrong Answer
import sys stdin = sys.stdin def ns(): return stdin.readline().rstrip() def ni(): return int(stdin.readline().rstrip()) def nm(): return map(int, stdin.readline().split()) def nl(): return list(map(int, stdin.readline().split())) def main(): n = ni() A = nl() mod = 10 ** 9 + 7 s = sum(A) % mod q = sum([a ** 2 % mod for a in A]) % mod ans = (((s * s) % mod - q) % mod) / 2 print(int(ans % mod)) if __name__ == '__main__': main()
p02873
s733318396
Wrong Answer
# A - >< S = input() N = len(S)+1 INF = 1000000 ans = [0]*N tmp = -INF for i in range(N-1): if S[i]=='<': tmp += 1 else: tmp = 0 ans[i+1] = tmp tmp = -INF for i in range(N-2,-1,-1): if S[i]=='>': tmp += 1 else: tmp = 0 ans[i] = max(ans[i],tmp) print(sum(ans))
p02866
s084024497
Wrong Answer
from collections import defaultdict n = int(input()) d = list(map(int, input().split())) d.sort() mod = 998244353 cnt = defaultdict(int) for i in range(n): cnt[d[i]] += 1 ans = 1 max_value = max(d) for i in range(1, max_value+1): ans = ans * pow(cnt[i-1], cnt[i], mod) % mod print(ans)
p03796
s834168091
Accepted
N=int(input()) a=1 for i in range(N): a*=(i+1) a%=1000000007 print(a)
p03274
s273824649
Wrong Answer
import itertools N,K=map(int, input().split()) x=list(map(int, input().split())) temp=0 ans=(abs(min(x))+abs(max(x)))*N xc=list(itertools.combinations(x,K)) for l in xc: if min(l)<=0 and max(l)>=0: ans=min(min(2*max(l)+abs(min(l)),max(l)+2*abs(min(l))),ans) elif min(l)<0 and max(l)<0: ans=min(ans,min(l)) elif min(l)>0 and max(l)>0: ans=min(ans,max(l)) print(ans)
p03359
s794401631
Accepted
m,d =map(int,input().split()) print(m if m<=d else m-1)
p03943
s810379046
Wrong Answer
s = map(int, input().split()) if(max(s) == sum(s)//2): print("Yes") else: print("No")
p02802
s208954500
Accepted
import numpy as np n, m = map(int,input().split()) questions = [0 for i in range(n)] clear = [0 for i in range(n)] for i in range(m): p,s = input().split() p = int(p) if s == 'WA': if clear[p-1] == 0: questions[p-1] += 1 else: clear[p-1] = 1 questions = np.array(questions) print(sum(clear), questions[np.where(np.array(clear) == 1)[0]].sum())
p02995
s091789651
Accepted
import fractions A,B,C,D = map(int,input().split()) U = B - A + 1 x = B // C - (A-1) // C y = B // D - (A-1) // D lcm = C*D // fractions.gcd(C,D) z = B // lcm - (A-1) // lcm print(U - (x + y - z))
p02623
s329800614
Accepted
from itertools import accumulate from bisect import bisect n, m, k = map(int, input().split()) a = accumulate(map(int, input().split()), initial=0) b = [*accumulate(map(int, input().split()))] print(max(i + bisect(b, k - x) for i, x in enumerate(a) if x <= k))
p02718
s130388775
Accepted
n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) sum_ = 0 for i in a: sum_ +=i if(a[m-1]>=sum_/(4*m)): print('Yes') else: print('No')
p04012
s462791193
Accepted
# 2020/04/29 # AtCoder Beginner Contest 044 - B # Input w = input() # Init d = dict() # Calc for i in range(len(w)): if d.get(w[i]) == None: d[w[i]] = 1 else: d[w[i]] = d[w[i]] + 1 ans = 'Yes' for key in d: if d[key] % 2 == 1: ans = 'No' break # Output print(ans)
p02571
s895013074
Accepted
s = input() t = input() s_l = len(s) t_l = len(t) max_count = 0 for i in range(0, s_l - t_l + 1): count = 0 for j in range(0, t_l): if s[i+j] == t[j]: count += 1 if count > max_count: max_count = count diff = t_l - max_count print(diff)
p03162
s433601700
Wrong Answer
N = int(input()) A = [] for i in range(N): A.append(list(map(int, input().split()))) dp = [[0]*3 for _ in range(N)] for i in range(3): dp[0][i] = A[0][i] for i in range(1, N): for j in range(3): for k in range(3): if i != k: dp[i][k] = max(dp[i-1][j] + A[i][k], dp[i][k]) print(max(dp[-1][0], dp[-1][1], dp[-1][2]))
p02578
s507265312
Accepted
def inp(): return input() def iinp(): return int(input()) def inps(): return input().split() def miinps(): return map(int,input().split()) def linps(): return list(input().split()) def lmiinps(): return list(map(int,input().split())) def lmiinpsf(n): return [list(map(int,input().split()))for _ in range(n)] n = iinp() a = lmiinps() ans = 0 for i in range(n-1): if a[i+1] < a[i]: ans += (a[i] - a[i+1]) a[i+1] = a[i] print(ans)
p02879
s848684200
Accepted
a, b = map(int,input().split()) if 9>=a>=1 and 9>=b>=1 : print(a*b) else : print(-1)
p02775
s404934353
Accepted
nl = list(input()) n = len(nl) ans = 0 dp = [[0, 0] for i in range(n+1)] for idx, i in enumerate(nl[::-1]): i = int(i) if idx == 0: dp[1][0] = dp[idx][0] + i dp[1][1] = dp[idx][0] + 10 - i else: dp[idx+1][0] = min(dp[idx][0] + i, dp[idx][1] + i + 1) dp[idx+1][1] = min(dp[idx][0] + 10 - i, dp[idx][1] + 10 - i - 1) print(min(dp[-1][0], dp[-1][1]+1))
p03371
s471116631
Wrong Answer
a,b,c,x,y = map(int,input().split()) a_b = (a+b) // 2 ans = 0 if a_b > c: ans += min(x,y)*c*2 if x > y: if a > c*2: ans += (x - y)*c*2 else: ans += (x - y)*a else: if b > c*2: ans += (y - x)*c*2 else: ans += (y - x)*b else: ans += x*a+y*b print(ans)
p02786
s814422601
Wrong Answer
N = int(input()) div = N//2 + 1 ans = (2**div-1) print(ans)
p02711
s486628333
Accepted
N = input() if N[0] == '7' or N[1] == '7' or N[2] == '7': print('Yes') else: print('No')
p02552
s784138924
Accepted
print(0 if int(input())==1 else 1)
p03479
s710201307
Accepted
x, y = map(int, input().split()) for i in range(100): if x * (2 ** i) > y: print(i) break
p02924
s285485367
Accepted
N = int(input()) if N == 1: print(0) else: print(N*(N-1)//2)
p04011
s906990727
Wrong Answer
n=int(input()) k=int(input()) x=int(input()) y=int(input()) f=0 if(n<=k): f=n*x else: f=n*x+(n-k)*y print(f)
p02570
s717979827
Wrong Answer
D,T,S= map(int,input().split()) if (S*T) <= D: print("Yes") else: print("No")
p02951
s110975322
Accepted
a, b, c = map(int,input().split()) print(max(0,c-(a-b)))
p03387
s221831856
Accepted
ABC = sorted(list(map(int,input().split()))) ans = ABC[2]-ABC[1] if (ABC[2]-(ABC[0]+ans))%2 == 0: ans += (ABC[2]-(ABC[0]+ans))//2 else: ans += (ABC[2]-(ABC[0]+ans))//2+2 print(ans)
p02578
s505804778
Accepted
n=int(input()) A = list(map(int,input().split())) max_value = max(A) max_index = A.index(max_value) c=0 for i in range(max_index,n): c+=(max_value-A[i]) for i in range(1,max_index): if A[i-1]>A[i]: c+=(A[i-1]-A[i]) A[i]=A[i-1] print(c)
p02639
s515102291
Accepted
x = map(int, input().split()) for i, j in enumerate(x): if j == 0: print(i+1)
p02547
s249030121
Accepted
n=int(input()) score=[] point=0 for i in range(n): d=input().split() if d[0]==d[1]: point+=1 score.append(point) else: point=0 score.append(point) if max(score)>=3: print("Yes") else: print("No")
p03657
s420777542
Wrong Answer
a,b=[int(i) for i in input().split()] if a%3==0 and b%3==0 and (a+b)%3==0: print('Impossible') else: print('Possible')
p03838
s394075603
Accepted
x,y=map(int,input().split()) ans=abs(abs(x)-abs(y)) if (x<0 and y<0) or (x>0 and y>0): if x>y :ans+=2 elif x!=0 and y!=0: ans+=1 else: if y<=0 and x>y: ans+=1 print(ans)
p02732
s967216419
Wrong Answer
N = int(input()) A = list(map(int,input().split())) count = 0 for i in range(N): for j in range(N): if A[i] == A[j]: count += 1 else: count += 0 print(count-i-1)
p02624
s648276764
Wrong Answer
import sys read = sys.stdin.read def main(): n = int(input()) if n == 1: print(1) sys.exit() # nd:num of div r = 0 for i1 in range(1, n): y = n // i1 r += y * (y + 1) * i1 / 2 print(int(r)) if __name__ == '__main__': main()
p02705
s070977114
Accepted
import math r=int(input()) print(2*r*math.pi)
p02817
s294571467
Accepted
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 s, t = list(map(str, str(input().rstrip('\n')).split())) print(t + s) if __name__ == '__main__': solve()
p03673
s298634771
Accepted
n = int(input()) a = [int(x) for x in input().split()] even = [] odd = [] for i in range(n): if i % 2 == 0: odd.append(a[i]) else: even.append(a[i]) if n % 2 == 0: even.reverse() ans = even + odd print(*ans) else: odd.reverse() ans = odd + even print(*ans)
p03799
s211133147
Accepted
n, m = map(int, input().split()) ans = min(n, m//2) m -= ans*2 ans += m//4 print(ans)
p03127
s420257016
Wrong Answer
n = int(input()) #n, m = list(map(int, input().split())) a = list(map(int, input().split())) #abc = [int(input()) for i in range(5)] a.sort() for i in range(1, n): a[i] %= a[0] a.sort(reverse=True) ans = a[-1] if ans == 0: for i in range(n-1, -1, -1): if a[i] != 0: print(a[i]) exit() print(ans)
p03293
s487083434
Wrong Answer
S=input() T=input() ans = "No" for i in range(len(S)): if S[:i] + S[0:1] == T: ans = "Yes" print(ans)
p02953
s354710614
Accepted
import sys import math import itertools import collections import heapq import re import numpy as np rr = lambda: sys.stdin.readline().rstrip() rs = lambda: map(str, sys.stdin.buffer.readline().split()) ri = lambda: int(sys.stdin.buffer.readline()) rm = lambda: map(int, sys.stdin.buffer.readline().split()) rl = lambda: list(map(int, sys.stdin.buffer.readline().split())) n = ri() h = rl() temp = 0 for i in h: if temp == i: continue elif temp < i: temp = i-1 continue else: print('No') exit() else: print('Yes')
p03254
s241954318
Accepted
N, x = map(int, input().split(" ")) a = list(map(int, input().split(" "))) children = [0] * N a.sort() kashi = 0 n = N if a[0] > x: print(0) elif sum(a) == x: print(N) else: for i in range(0,n): if kashi > x: break kashi += a[i] children[i] += 1 # print(kashi) if kashi == x : print(N - children.count(0)) else: print(N - children.count(0) - 1)
p02724
s362444103
Accepted
n = int(input()) y = 0 if(n==0): print(y) elif(n%500==0): y = int(n/500)*1000 print(y) else: j = n%500 y = int(n//500)*1000 + int(j//5)*5 print(y)
p03251
s779748458
Accepted
N, M, X, Y = map(int,input().split()) x = [int(x) for x in input().split()] y = [int(y) for y in input().split()] x.append(X) y.append(Y) x_max = max(x) y_min = min(y) if x_max < y_min: print('No War') else: print('War')
p03136
s187129476
Wrong Answer
def main(): N = input() L = map(int, input().split()) a = max(L) b = sum(L) - a if a > b: print("Yes") else: print("No") if __name__ == '__main__': main()
p02832
s119355560
Accepted
n = int(input()) lis = list(map(int, input().split())) res = 0 cnt = 0 flg = False for i in lis: if i == 1: flg = True res = max(res, cnt) cnt = 1 elif i == cnt + 1: cnt += 1 if not flg: print(-1) else: print(n - max(res, cnt))
p02832
s497258268
Accepted
n = int(input()) a = list(map(int, input().split())) num = 1 b_num = 0 for i in range(n): if num != a[i]: b_num += 1 else: num += 1 if b_num == n: b_num = -1 print(b_num)
p03774
s772737571
Accepted
n,m=map(int,input().split()) std = [list(map(int,input().split())) for _ in range(n)] chk = [list(map(int,input().split())) for _ in range(m)] for i in range(n): chk_id = 0 d = float("inf") for j in range(m): d1 = abs(std[i][0] - chk[j][0]) + abs(std[i][1] - chk[j][1]) if d1 < d: d = d1 chk_id = j+1 print(chk_id)
p02548
s224706862
Wrong Answer
N = int(input()) count = 0 for a in range(1, N+1): tmp = (N-1) // a if a == tmp: count += 1 if a < N // 2: count += tmp else: count += 1 print(count-1)
p02659
s007189919
Wrong Answer
import math a,b = map(float, input().split()) print(math.floor(a * b))
p02814
s121068934
Wrong Answer
import math def lcm(x,y): return(x*y)//math.gcd(x,y) n,m=map(int,input().split()) l=list(map(int,input().split())) a=l[0]//2 for i in range(n-1): a=lcm(a,l[i+1]//2) if m>=a: print(((m//a)+1)//2) else: print(0)
p03485
s988578392
Wrong Answer
# -*- coding: <encoding name> -*- import math a, b = map(int, input().split()) x = math.ceil(a * b / 2) print(x)
p02989
s430738589
Accepted
n,*l=map(int,open(0).read().split()) n//=2 l.sort() print(l[n]-l[~n])
p03109
s097543407
Wrong Answer
import datetime s = input() dt = datetime.datetime.strptime(s, '%Y/%m/%d') if dt.year >= 2019 and dt.month >= 4 and dt.day >= 30: print('Heisei') else: print('TBD')
p03161
s156976773
Accepted
N,K=map(int,input().split()) H=list(map(int,input().split())) DP=[0]*(N+1) for i in range(2,N+1): L=[DP[i-j-1]+abs(H[i-1]-H[i-j-2])for j in range(min(K,i-1))] DP[i]=min(L) print(DP[-1])
p02693
s648937258
Accepted
import sys k = int(input()) a,b = map(int, input().split()) for i in range(a, b+1): if i % k == 0: print('OK') sys.exit(0) print('NG')
p02726
s271408909
Accepted
n, x, y = list(map(int, input().split())) count = [0]*n for i in range(n-1): for j in range(i+1, n): ans_1 = j-i ans_2 = abs(x-(i+1))+1+abs(y-(j+1)) count[min(ans_1,ans_2)] += 1 # print(count) [print(k) for k in count[1:]]
p03719
s100631273
Accepted
a,b,c=map(int,input().split()) print("Yes" if a<=c<=b else "No")
p02818
s414510923
Wrong Answer
A, B, K = map(int, input().split()) if K <= A: print(K-A, B) else: if K <= A + B: print(0, B-K-A) else: print(0, 0)
p03359
s459788730
Accepted
a, b = map(int, input().split()) cnt = a - 1 ans = cnt + 1 if a <= b else cnt print(ans)
p03371
s585290603
Wrong Answer
a, b, c, x, y = map(int, input().split()) half = min(x, y) * 2 * c + (max(x, y) - min(x, y)) * min(a, b) a_b = a * x + b * y halfOnly = max(x, y) * 2 * c print(min(min(half, a_b), halfOnly))
p03644
s156515229
Accepted
N = int(input()) cnt = 0 while 2**cnt <= N: cnt+=1 print(2**(cnt-1))
p03557
s087689361
Accepted
from bisect import bisect_left, bisect_right def main(): n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] a.sort() b.sort() c.sort() cnt = 0 for i in range(n): v = b[i] idx_a = bisect_left(a, v) idx_b = bisect_right(c, v) cnt += idx_a * (n-idx_b) print(cnt) main()
p02947
s620517462
Accepted
N=int(input()) S=["".join(sorted(input())) for _ in range(N)] d={} ans=0 for s in S: if s in d: ans+=d[s] d[s]+=1 else: d[s]=1 print(ans)
p02713
s115018005
Accepted
from math import gcd k = int(input()) ans = 0 for a in range(1,k+1): for b in range(1,k+1): p = gcd(a,b) for c in range(1,k+1): ans += gcd(p,c) print(ans)
p02577
s760254592
Accepted
n = input() val = 0 for i in n: val += int(i) if val%9 == 0: print('Yes') else: print('No')
p02933
s100808827
Accepted
def main(): a = int(input()) s = input() if a >= 3200: print(s) else: print("red") if __name__ == "__main__": main()
p02570
s534017260
Accepted
d, t ,s = map(int, input().split( )) di = s*t if di >= d: print('Yes') else: print('No')
p03681
s861362998
Accepted
import math n,m = map(int, input().split()) a = math.factorial(m) b = math.factorial(n) if 1 < abs(n-m): print(0) elif abs(n-m) == 0: print((a*b*2)%1000000007) elif abs(m-n) == 1: print((a*b)%1000000007)
p03745
s978604663
Accepted
n = int(input()) A = list(map(int, input().split())) ans = 1 up = dn = False pre = A[0] for a in A[1:]: if pre < a: up = True elif pre > a: dn = True if up and dn: ans += 1 up = dn = False pre = a print(ans)
p03478
s285571902
Wrong Answer
N, A, B = map(int, input().split()) def keta_sum(x): sum = 0 while x%10 !=0: sum += x%10 x = x//10 return(sum) res = 0 for i in range(N+1): if A <= keta_sum(i) <= B: res += i print(res)
p03328
s823083703
Accepted
a, b = map(int, input().split()) c = b - a t = [1] for i in range(1100): t.append(t[i]+i+2) idx = 0 for i in range(1000): if t[i+1] - t[i] == c: idx = i + 1 break print(idx * (idx+1)//2-a)
p03433
s295501954
Wrong Answer
N = int(input()) A = int(input()) N = N // 500 if N <= A: print("Yes") else: print("No")
p02793
s166574493
Accepted
from math import * def gcd(x, y): while y != 0: (x, y) = (y, x % y) return x def lcm(x,y): return x*y//gcd(x,y) n = int(input()) a = [int(x) for x in input().split()] mod = 1000000000+7 k = 1 for x in a: k = lcm(k,x) ans = 0 for x in a: ans += k//x print(ans%mod)
p03773
s076581205
Accepted
a, b = map(int, input().split()) print((a+b) % 24)
p02615
s846752179
Wrong Answer
# 整数の入力 import numpy as np N = int(input()) A_list = list(map(int, input().split())) A = np.array(A_list) ans = np.sum(A) - np.max(A) print(ans)
p03557
s520343853
Accepted
import bisect N=int(input()) L1=list(map(int,input().split())) L2=list(map(int,input().split())) L3=list(map(int,input().split())) L1.sort() L2.sort() L3.sort() ans=0 for l2 in L2: l1_idx=bisect.bisect_left(L1,l2) l3_idx=bisect.bisect_right(L3,l2) ans+=l1_idx*(N-l3_idx) print(ans)
p03944
s082264316
Accepted
import numpy as np import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) W, H, N = map(int, input().split()) grid = np.zeros((H, W), dtype=int) for _ in range(N): x, y, a = map(int, input().split()) if a == 1: grid[:, :x] = 1 elif a == 2: grid[:, x:] = 1 elif a == 3: grid[:y, :] = 1 else: grid[y:, :] = 1 ans = H * W - np.count_nonzero(grid) print(ans)
p02554
s588533659
Accepted
n = int(input()) p = 10**9+7 print((pow(10, n, p) - 2*pow(9, n, p) + pow(8, n, p)) % p)
p02789
s544224897
Accepted
N, M = map(int, input().split()) print("Yes") if N == M else print("No")
p02861
s487329167
Accepted
N = int(input()) xy = [list(map(int, input().split())) for _ in range(N)] print(sum([((a[0] - b[0]) ** 2 +(a[1] - b[1]) ** 2) ** 0.5 for b in xy for a in xy]) / N)
p02600
s412246129
Accepted
x = int(input()) if x <= 599: print(8,"\n") elif x <= 799: print(7,"\n") elif x <= 999: print(6,"\n") elif x <= 1199: print(5,"\n") elif x <= 1399: print(4,"\n") elif x <= 1599: print(3,"\n") elif x <= 1799: print(2,"\n") elif x <= 1999: print(1,"\n")
p02606
s652255540
Accepted
l,r,d = map(int,input().split()) mod = l % d cnt = 0 for i in range(1,100//d + 1): if l <= i*d and r >= i*d: cnt += 1 print(cnt)
p03557
s116791272
Wrong Answer
import bisect n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() c.sort() ans = 0 print(a) print(b) print(c) for i in range(n): ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i])) print(ans)
p02972
s176491865
Wrong Answer
n=int(input()) bits = list(map(int,input().split())) ans = set() for i in reversed(range(n)): for j in range(i+(i+1),n,i+1): bits[i] ^= bits[j] if bits[i] == 1: ans.add(i+1) print(len(ans)) print(*ans) n= 3 for i in reversed(range(n)): for j in range(i+(i+1),n,i+1): print(i,j)
p03971
s529716338
Accepted
N, A, B = map(int, input().split()) S = list(input()) cntA = 0; cntB = 0 for s in S: if s == 'a' and cntA+cntB < A+B: print('Yes') cntA += 1 elif s == 'b' and cntA+cntB < A+B and cntB < B: print('Yes') cntB += 1 else: print('No')
p03131
s732212805
Accepted
K, A, B = map(int, input().split()) if B-1 <= A: print(K+1) exit() count = max(0, (K - (A-1))//2) ans = (K+1) - 2*count + (B-A)*count print(ans)
p03698
s868842329
Accepted
s = input() s = list(s) c = set(s) if len(s) != len(c): print("no") else: print("yes")
p03624
s485827913
Accepted
import sys S = list(input()) s = list(set(S)) s.sort() alfa = list('abcdefghijklmnopqrstuvwxyz') ans = 0 if(len(s)==len(alfa)): print('None') sys.exit() else: for i in range(len(s)): if(s[i]!=alfa[i]): print(alfa[i]) sys.exit() print(alfa[len(s)])
p03796
s756098941
Accepted
# -*- coding: utf-8 -*- n = int(input()) ans = 1 for i in range(1, n + 1): ans = (ans * i) % (pow(10, 9) + 7) print(ans)
p03625
s084434356
Wrong Answer
import collections n=int(input()) c=collections.Counter(list(map(int,input().split()))) p=-1 for x in sorted(c.keys())[::-1]: if p==-1 and c[x]>=2:p=x elif p!=-1 and c[x]>=2: print(p*x) break else:print(0)
p02916
s599460296
Wrong Answer
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) print(sum([b[i-1] for i in a])+sum([c[i-1] for i in range(n-1) if a[i+1]-a[i]==1]))
p03408
s091667809
Accepted
from collections import Counter def main(): n = int(input()) s = [] for _ in range(n): s.append(input()) m = int(input()) t = [] for _ in range(m): t.append(input()) sc = Counter(s) tc = Counter(t) r = 0 for sce in sc: r = max(r, sc[sce] - tc[sce]) print(r) if __name__ == '__main__': main()
p03261
s441222543
Accepted
import sys import math n = int(input()) li = [n] li[0] = input() isGood=True for i in range(n-1): tmp = input() if (not isGood): continue if (tmp not in li): if (li[i][-1] != tmp[0]): isGood = False else: li.append(tmp) else: isGood = False if (isGood): print('Yes') else: print('No')
p02761
s723369764
Accepted
n, m = map(int, input().split()) a = [list(map(int, input().split())) for i in range(m)] ans = -1 for i in range(1000): s = str(i) if len(s) == n: flag = 0 for (x, y) in a: if int(s[x-1]) != y: flag = 1 if flag == 0: ans = i break print(ans)
p03161
s666088038
Accepted
n, k = map(int, input().split()) h = list(map(int, input().split())) ans = [0] * n for i in range(1, n): l = min(i, k) hs = h[i] ans[i] = min([abs(hs - h[i - j])+ans[i-j] for j in range(1, l+1)]) # j : 戻り幅 #print(ans) print(ans[-1])
p02922
s228498509
Accepted
a,b = map(int,input().split()) sumA = a count =1 ans = 0 while count < b: count -=1 count +=a ans +=1 print(ans)