code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
s = input()*2 p = input() print("Yes" if p in s else "No")
s = input() p = input() s *= 2 if p in s: print('Yes') else: print('No')
1
1,768,921,190,180
null
64
64
line = input() num_query = int(input()) for loop in range(num_query): input_str = list(input().split()) if input_str[0] == 'replace': left = int(input_str[1]) right = int(input_str[2]) right += 1 line = line[:left] + input_str[3] + line[right:] elif input_str[0] == 'reverse': left = int(input_str[1]) right = int(input_str[2]) right += 1 line = line[:left] + line[left:right][::-1] + line[right:] else: # print left = int(input_str[1]) right = int(input_str[2]) right += 1 for i in range(left, right): print(line[i], end="") print()
import math as mt a, b, c = map(int, input().split()) d = c - a - b if d>0 and d**2 > 4*a*b: print("Yes") else: print("No")
0
null
26,888,619,257,708
68
197
import heapq from collections import deque must_red, must_green, a,b,c = map(int,input().split()) delicious_red_ls = list(map(int, input().split())) delicious_green_ls = list(map(int, input().split())) delicious_free_ls = list(map(int, input().split())) delicious_red_ls.sort(reverse=True) delicious_green_ls.sort(reverse=True) first_red = delicious_red_ls[:must_red] first_green = delicious_green_ls[:must_green] first_set = first_green + first_red first_set.sort() delicious_free_ls.sort() while delicious_free_ls: to_be_erased = heapq.heappop(first_set) erase = delicious_free_ls[-1] if to_be_erased < erase: new = delicious_free_ls.pop() heapq.heappush(first_set, new) else: heapq.heappush(first_set, to_be_erased) break print(sum(first_set))
weekdays = ["", "SAT", "FRI", "THU", "WED","TUE","MON", "SUN"] w = input() print(weekdays.index(w))
0
null
89,085,357,941,310
188
270
import itertools n,k = map(int, input().split()) di = [0] * k Ai_di = [] for i in range(k): di[i] = int(input()) Ai_di.append(list(map(int, input().split()))) ans_set = set(list(itertools.chain.from_iterable(Ai_di))) print(n - len(ans_set))
n, k = map(int, input().split()) a = set() for i in range(k): d = input() a |= set(map(int, input().split())) print(n - len(a))
1
24,494,709,254,070
null
154
154
n = int(input()) res = -1 for x in range(1, n+1): if int(x * 1.08) == n: res = x if res == -1: print(":(") else: print(res)
a, b, k = map(int, input().split()) if k <= a: a -= k elif a < k <= a + b: temp = a a = 0 b -= k - temp else: a = 0 b = 0 print('{} {}'.format(a, b))
0
null
115,317,241,084,252
265
249
print(sum([i for i in range(1,int(input())+1) if not ((i%3==0 and i%5==0) or i%3==0 or i%5==0)]))
num = int(input()) result = num + num**2 + num**3 print(result)
0
null
22,372,652,790,756
173
115
n = input() if n.isupper(): print("A") else: print("a")
x=input() if ((x>='A') and (x<='Z')): print('A') elif (x>='a') and (x<='z'): print('a')
1
11,292,863,666,822
null
119
119
def resolve(): s = input() print(s[:3]) if 'unittest' not in globals(): resolve()
# -*- coding: utf-8 -*- """ Created on Sat Jun 13 21:27:14 2020 @author: NEC-PCuser """ print(input()[0:3])
1
14,842,317,306,208
null
130
130
N=int(input()) List = list(map(int, input().split())) res = 1000000000000 mid = 0 for i in range(101): for j in range(N): mid += (i-List[j])**2 res = min(res,mid) mid = 0 print(res)
import math from sys import stdin a, b, c = map(int, stdin.readline().rstrip().split()) if (c - a - b) > 0: if (c - a - b) ** 2 > 4 * a * b: print('Yes') else: print('No') else: print('No')
0
null
58,358,184,180,550
213
197
# coding=utf-8 import sys if __name__ == '__main__': N = int(input()) li_A = list(map(int, input().split())) ans = li_A[0] if 0 in li_A: print('0') sys.exit() for i in range(1, N): if ans * li_A[i] > 1000000000000000000: print('-1') sys.exit() else: ans *= li_A[i] print(ans)
n, m = map (int, input().split()) ex1 = n*(n-1)//2 ex2 = m*(m-1)//2 ans = ex1 + ex2 print(ans)
0
null
30,791,544,715,932
134
189
import decimal def main(): A, B = map(decimal.Decimal,input().split()) if A == 0: return 0 else: AB = A*B return int(AB) print(main())
def main(): a, b = map(lambda x: int(x.replace('.','')), input().split()) print(a*b//100) if __name__ == '__main__': main()
1
16,448,259,706,780
null
135
135
x,y = map(int, input().split()) ans = 0 dic = {1:300000, 2:200000, 3:100000} if x in dic: ans = dic[x] if y in dic: ans += dic[y] if x==1 and y==1: ans += 400000 print(ans)
#DISCO presents ディスカバリーチャンネル コードコンテス a def get_money(num): if num==3: return 100000 elif num==2: return 200000 elif num==1: return 300000 else: return 0 x,y=map(int,input().split()) money=get_money(x)+get_money(y) if x==y and x==1: money+=400000 print(money)
1
140,573,116,444,420
null
275
275
# -*-coding:utf-8 import math def main(): a, b, degree = map(int, input().split()) radian = math.radians(degree) S = 0.5*a*b*math.sin(radian) x = a + b + math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(radian)) print('%.8f' % S) print('%.8f' % x) print('%.8f' % ((2*S)/a)) if __name__ == '__main__': main()
N=int(input()) n=len(str(N)) res=0 for a in range(1,N+1): a0=str(a)[0] a1=str(a)[-1] if a0=='0' or a1=='0': a_res=res continue for i in range(1,n+1): if i==1: if a0==a1: res+=1 elif i==2: if 10*int(a1)+int(a0)<=N: res+=1 elif i==n: n0=str(N)[0] n1=str(N)[-1] if n0<a1: res+=0 elif n0>a1: res+=10**(i-2) else: res+=(N-int(a1)*10**(i-1))//10+1 if n1<a0: res-=1 else: res+=10**(i-2) print(res)
0
null
43,196,221,588,758
30
234
N, k = map(int, input().split()) dp = [0] * (N+1) dp[1] = 1 S = [] for i in range(k): S.append(list(map(int, input().split()))) for i in range(2, N+1): for l, r in S: dp[i] += (dp[max(i-l, 0)] - dp[max(i-r-1, 0)]) dp[i] += dp[i-1] dp[i] %= 998244353 print((dp[N] - dp[N-1])%998244353)
# -*- coding: utf-8 -*- import sys N=input() S=["None"]+list(raw_input()) Q=input() query=[ sys.stdin.readline().split() for _ in range(Q) ] #BIT bit=[ [ 0 for _ in range(N+1) ] for _ in range(27) ] #1-indexed bit[1]:aのbit, bit[2]:bのbit ... def add(idx,a,w): while a<=N: bit[idx][a]+=w a+=a&-a def sum(idx,a): ret=0 while 0<a: ret+=bit[idx][a] a-=a&-a return ret for i,x in enumerate(S): if i==0: continue add(ord(x)-96,i,1) #a~zのどのbit配列か,特定文字のbit配列の何番目,bitに代入する値 for q1,q2,q3 in query: q1=int(q1) q2=int(q2) if q1==1: before_q3=S[q2] #文字列Sの変更前の文字をbefore_q3に代入 S[q2]=q3 #文字列Sの変更部分1文字を更新 q3=ord(q3)-96 #変更後の文字をアスキーコード10進数で表現 before_q3=ord(before_q3)-96 #変更前の文字をアスキーコード10進数で表現 add(q3,q2,1) #a~zのどのbit配列か,特定文字のbit配列の何番目,bitに代入する値 add(before_q3,q2,-1) #置き代えた文字は-1しなきゃいけない elif q1==2: q3=int(q3) cnt=0 for i in range(1,27): if 0<sum(i,q3)-sum(i,q2-1): cnt+=1 print cnt
0
null
32,708,888,634,620
74
210
N = int(input()) line = input() R_ = line.count("R") W_ = line.count("W") final_line = "R" * R_ + "W" * W_ dic = {"W":0, "R":0} for idx, c in enumerate(line): if c != final_line[idx]: dic[c] += 1 print(max(dic.values()))
n = int(input()) c = input() t = n lw, rr = 0, c.count('R') for ci in c+'Z': swap = min(lw, rr) wtor, rtow = max(0, lw-swap), max(0, rr-swap) t = min(t, swap + wtor + rtow) lw = lw + (ci == 'W') rr = rr - (ci == 'R') print(t)
1
6,256,323,274,500
null
98
98
import sys input = sys.stdin.buffer.readline N, K = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(K)] mod = 998244353 dp = [0]*(N+1) tmp = 1 for i in range(N-1): tmp = (tmp + dp[i]) % mod # dp[i] = tmp for l, r in LR: dp[min(i+l, N)] = (dp[min(i+l, N)] + tmp) % mod dp[min(i+r+1, N)] = (dp[min(i+r+1, N)] - tmp) % mod print(dp[N-1])
n, m = [int(i) for i in input().split()] C = [int(i) for i in input().split()] dp = [100000] * (n + 1) dp[0] = 0 for k in C: for j in range(k, n + 1): if dp[j] > dp[j - k] + 1: dp[j] = dp[j - k] + 1 print(dp[n])
0
null
1,420,480,270,248
74
28
def solve(N): N = [0] + N k = 0 # 繰り上がり ans = 0 for d, d_next in zip(N[::-1], N[-2::-1]): d += k if d <= 4 or (d==5 and d_next<5): k = 0 ans += d else: k = 1 ans += 10 - d if k: ans += 1 return ans def test(N, ans): for i in range(N, 10000): rem = i - N if sum(map(int, str(i))) + sum(map(int, str(rem))) < ans: print(f"!!! N={N}, ans={ans}, trueans={i, rem}") def main(): N = list(map(int, input())) print(solve(N)) # for i in range(1, 10000): # ans = solve(list(map(int, str(i)))) # test(i, ans) main()
N = int(input()) A = list(map(int,input().split())) a = {} for i in A: if i in a: a[i] += 1 else: a[i] = 1 Q = int(input()) ans = sum(A) for i in range(Q): B,C = map(int,input().split()) if B in a: ans += (C-B) * a[B] if C in a: a[C] += a[B] else: a[C] = a[B] a[B] = 0 print(ans)
0
null
41,443,206,310,620
219
122
X,Y=map(int,input().split()) if X==1 : x=300000 elif X==2 : x=200000 elif X==3 : x=100000 else : x=0 if Y==1 : y=300000 elif Y==2 : y=200000 elif Y==3 : y=100000 else : y=0 if X==1 and Y==1 : print(x+y+400000) else : print(x+y)
#!/usr/bin/env python3 # from numba import njit # from collections import Counter # from itertools import accumulate # import numpy as np # from heapq import heappop,heappush # from bisect import bisect_left INF = pow(10,6) # @njit def solve(n,a): res = INF for i in range(1,101): res = min(res,sum(pow(i-x,2) for x in a)) return res def main(): N = int(input()) # N,M = map(int,input().split()) a = list(map(int,input().split())) print(solve(N,a)) return if __name__ == '__main__': main()
0
null
102,676,540,191,150
275
213
import math def isprime(x): if x == 2: return True if x < 2 or x % 2 == 0: return False i = 3 while(i <= math.sqrt(x)): if x % i == 0: return False i += 2 return True num = raw_input() count = 0 for i in range(int(num)): x = raw_input() if isprime(int(x)): count += 1 print count
from collections import Counter n=int(input()) stri=list(input()) cc=Counter(stri) count=cc['R']*cc['G']*cc['B'] for i in range(n-2): for j in range(i+1,n-1): if stri[j]==stri[i]:continue lib=['R','G','B'] lib.remove(stri[i]) lib.remove(stri[j]) t=lib.pop() skip_k=2*j-i #print(i,j,skip_k) if skip_k>n-1:continue if stri[skip_k]==t: count-=1 print(count)
0
null
18,080,578,810,748
12
175
n,m = map(int,input().split()) graph = [[] for i in range(n)] for i in range(m): a,b = map(lambda z:int(z)-1,input().split()) graph[a].append(b) graph[b].append(a) size = [0 for i in range(n)] check = [True for i in range(n)] for i in range(n): if check[i]: tmp = 1 stack = [i] check[i] = False while stack: now = stack.pop() size[now] = tmp tmp+=1 for to in graph[now]: if check[to]: check[to] = False stack.append(to) print(max(size))
import sys input = sys.stdin.readline mm = 10**10 k = mm.bit_length() K = 1<<k nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2) st = lambda n: bin(n)[2:] + "0" li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(200001)]] n,m = map(int, input().split()) a = [int(i) for i in input().split()] b = [0]*100001 for i in a: b[i] += 1 c = li(st(nu(b)*nu(b))) ans = 0 for i in range(200001)[::-1]: if c[i] > 0: p = min(m,c[i]) m -= p ans += i*p if m == 0: break print(ans)
0
null
56,294,192,846,180
84
252
n=int(input()) A=[int(i) for i in input().split()] mod=10**9+7 ans=0 cnt=[0 for i in range(61)] for i in range(n): now=A[i] bek=1 for q in range(61): if now&1==0: ans+=cnt[q]*bek else: ans+=(i-cnt[q])*bek bek=bek*2%mod cnt[q]+=now&1 now>>=1 ans=ans%mod #print(ans) print(ans)
n, s = map(int, input().split()) a = list(map(int, input().split())) mod = 998244353 ans = 0 inv_2 = pow(2, mod-2, mod) dp = [[0 for _ in range(s+1)] for _ in range(n+1)] dp[0][0] = pow(2, n, mod) for i in range(n): for j in range(s+1): dp[i+1][j] += dp[i][j] dp[i+1][j] %= mod if j + a[i] <= s: dp[i+1][j+a[i]] += dp[i][j] * inv_2 dp[i+1][j+a[i]] %= mod #print(dp) print(dp[n][s])
0
null
70,422,737,831,072
263
138
from itertools import accumulate N, K = map(int, input().split()) P = tuple(accumulate(map(int, input().split()))) ans = P[K - 1] for i in range(N - K): ans = max(P[i + K] - P[i], ans) print((ans + K) / 2)
N, K = map(int, input().split()) P = list(map(int, input().split())) pos = 0 n = m = sum(P[0:K]) for i in range(1,N): if i+K > N: break n = n - P[i-1] + P[K-1+i] if n > m: pos = i m = n print((sum(P[pos:pos+K]) + K) / 2)
1
74,837,969,679,860
null
223
223
import copy class Dice2: def __init__(self, nums): self.nums = nums self.dic = \ {(1,2):3, (1,3):5, (1,4):2, (1,5):4, (2,3):1, (2,4):6, (2,6):3, (3,5):1, (3,6):5, (4,5):6, (4,6):2, (5,6):4} def output_right(self, x): x[0] = self.nums.index(x[0]) + 1 x[1] = self.nums.index(x[1]) + 1 nums = self.nums y = copy.deepcopy(x) x.sort() key = tuple(x) if tuple(y)==key: return nums[self.dic[key]-1] else: return nums[6-self.dic[key]] dice = Dice2(list(map(int, input().split()))) q = int(input()) for i in range(q): print(dice.output_right(list(map(int, input().split()))))
inp = [i for i in input().split()] n = int(input()) array = [[i for i in input().split()] for i in range(n)] for i2 in range(n): fuck ="" for i in range(1,33): if (i<=20 and i%5==0) or i==22 or i==27 or i==28: s = "N" else: s = "E" if s == "E": a = [] a.append(inp[3]) a.append(inp[1]) a.append(inp[0]) a.append(inp[5]) a.append(inp[4]) a.append(inp[2]) inp = a if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck: print(inp[2]) fuck = inp[2] elif s == "N": a = [] a.append(inp[1]) a.append(inp[5]) a.append(inp[2]) a.append(inp[3]) a.append(inp[0]) a.append(inp[4]) inp = a if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck: print(inp[2]) fuck = inp[2]
1
251,084,196,438
null
34
34
def main(): N, K = map(int, input().split()) R, S, P = map(int, input().split()) T = input() l = ["" for i in range(K)] s = 0 for i in range(N): # print(l) if l[i%K] == T[i]: l[i%K]="" continue if l[i%K] == "": if T[i] == "r": s = s+P l[i%K] = "r" elif T[i] == "s": s = s+R l[i%K] = "s" else: s = s+S l[i%K] = "p" elif T[i]=="r": s = s+P l[i%K] = "r" elif T[i]=="s": s = s+R l[i%K] = "s" else: s = s+S l[i%K] = "p" print(s) if __name__ == "__main__": main()
nMonsters, nSpecial = [int(x) for x in input().split()] monst = [int(x) for x in input().split()] monst.sort() nMonsters -= nSpecial if nMonsters < 0: print(0) else: print(sum(monst[0:nMonsters]))
0
null
92,601,032,041,002
251
227
s = list(input()) k = int(input()) n = len(s) if s == [s[0]]*n: print(n*k//2) else: ss = s*2 ans1 = 0 for i in range(1, n): if s[i] == s[i -1]: s[i] = "" ans1 += 1 ans2 = 0 for i in range(1, 2*n): if ss[i] == ss[i - 1]: ss[i] = "" ans2 += 1 j = ans2 - ans1 print(ans1 + j*(k - 1))
S=input() N=len(S) K=int(input()) s="".join((S,S)) cnt1=0 cnt2=0 buf=0 piv="" if len(set(S))!=1: for i in range(N): if S[i]==piv: buf=buf+1 else: piv=S[i] cnt1=cnt1+(buf+1)//2 buf=0 cnt1=cnt1+(buf+1)//2 buf=0 piv="" for i in range(2*N): if s[i]==piv: buf=buf+1 else: piv=s[i] cnt2=cnt2+(buf+1)//2 buf=0 #print(buf) cnt2 = cnt2 + (buf + 1) // 2 x = cnt2 - cnt1 print(cnt1 + (K - 1) * x) else: print((len(S)*K)//2)
1
175,358,954,526,798
null
296
296
import sys import math import fractions from collections import defaultdict stdin = sys.stdin ns = lambda: stdin.readline().rstrip() ni = lambda: int(stdin.readline().rstrip()) nm = lambda: map(int, stdin.readline().split()) nl = lambda: list(map(int, stdin.readline().split())) S=ns().split() print(S[1]+S[0])
def solve(): s, t = input().split() print(t+s) if __name__ == '__main__': solve()
1
102,999,522,456,530
null
248
248
n = int(input()) l = list(map(int,input().split())) min_sum = 10**9 for i in range(min(l),max(l)+1): min_sum = min(min_sum,sum([(j-i)**2 for j in l])) print(min_sum)
hankei = input() print(int(hankei)**2)
0
null
104,946,402,343,972
213
278
S = input() N = len(S) print("x" * N)
from itertools import accumulate N, K = map(int, input().split()) *A, = map(int, input().split()) for i in range(K): a = [0]*N allN = True for j in range(N): l, r = max(j-A[j], 0), (j+A[j]+1) a[l] += 1 if r < N: a[r] -= 1 if A[j] != N: allN = False A = list(accumulate(a)) if allN: break print(*A)
0
null
44,141,426,435,858
221
132
a = int(input()) b = input() if len(b) <= a: print(b) else: print(b[:a]+'...')
K = int(input()) S = str(input()) if K >= len(S): answer = S else: answer = (S[:K]+'{}'.format('...')) print(answer)
1
19,702,839,865,202
null
143
143
n, m = map(int,input().split()) a = list(map(int,input().split())) a.sort(reverse=True) total = sum(a) flg = True for i in range(m): if a[i] * 4 * m < total: flg = False print('Yes') if flg else print('No')
n, m = map(int, input().split()) a = list(map(int, input().split())) total = sum(a) cnt = 0 for _a in a: if _a * 4 * m >= total: cnt += 1 if cnt >= m: print("Yes") else: print("No")
1
38,467,537,360,668
null
179
179
from collections import deque S=deque(input()) Q=int(input()) ans=0 for i in range(Q): q=input() if q[0]=='2': if ans%2==0: if q[2]=='1': S.appendleft(q[4]) else: S.append(q[4]) else: if q[2]=='1': S.append(q[4]) else: S.appendleft(q[4]) else: ans+=1 S="".join(S) print(S if ans%2==0 else S[::-1])
import sys from collections import deque def LS(): return list(input().split()) S = deque(input()) Q = int(input()) rev = 0 for i in range(Q): A = LS() if A[0] == "1": rev += 1 rev %= 2 else: if A[1] == "1": if rev == 0: S.appendleft(A[2]) else: S.append(A[2]) else: if rev == 0: S.append(A[2]) else: S.appendleft(A[2]) if rev == 0: print(''.join(S)) else: S.reverse() print(''.join(S))
1
57,193,076,042,080
null
204
204
X, Y, A, B, C = map(int, input().split()) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) p = p[:X] q = q[:Y] all = p + q + r all.sort(reverse=True) ans = sum(all[:X + Y]) print(ans)
def function(arg): xyabc, pa, qb, rc = arg.split('¥n') X,Y,A,B,C = map(int, xyabc.split()) oishisa_A = list(map(int, pa.split())) oishisa_B = list(map(int, qb.split())) oishisa_C = list(map(int, rc.split())) oishisa_A.sort(reverse=True) oishisa_A = oishisa_A[:X] # at most X oishisa_B.sort(reverse=True) oishisa_B = oishisa_B[:Y] # at most Y oishisa_C.sort(reverse=True) oishisa = oishisa_A + oishisa_B + oishisa_C oishisa.sort(reverse=True) results = 0 for i in range(X+Y): results += oishisa[i] return results if __name__ == '__main__': xyabc = input() pa = input() qb = input() rc = input() print(function(xyabc+'¥n'+pa+'¥n'+qb+'¥n'+rc))
1
44,696,832,571,040
null
188
188
N=int(input()) A=list(map(int,input().split())) count=[0 for i in range(N)] for i in A: count[i-1]+=1 def chose(n): return int(n*(n-1)/2) total=0 for i in count: total+=chose(i) for i in range(N): ans=total ans-=chose(count[A[i]-1]) count[A[i]-1]-=1 ans+=chose(count[A[i]-1]) count[A[i]-1]+=1 print(ans)
from collections import Counter N = int(input()) A = list(map(int, input().split())) kosu = Counter(A) tempSum = 0 for v in kosu.values(): tempSum += v * (v - 1) // 2 for a in A: print(tempSum - kosu[a]+1)
1
47,626,634,157,060
null
192
192
A = int(input()) B = int(input()) ans = 6 - (A+B) print(ans)
N,R = map(int,input().split(" ")) if N>10: print(R) else: print(R+100*(10-N))
0
null
86,871,945,696,158
254
211
N, M, L = map(int, raw_input().split()) nm = [map(int, raw_input().split()) for n in range(N)] ml = [map(int, raw_input().split()) for m in range(M)] ml_t = [] for l in range(L): tmp = [] for m in range(M): tmp.append(ml[m][l]) ml_t.append(tmp) for n in range(N): tmp1 = nm[n] col = [0]*L for l in range(L): tmp2 = ml_t[l] for m in range(M): col[l] += tmp1[m] * tmp2[m] print ' '.join(map(str, col))
n = int(input()) out = '' for i in range(3,n+1): if i % 3 == 0: out += ' {0}'.format(i) continue elif i % 10 == 3: out += ' {0}'.format(i) continue n = i while n // 10: n = n // 10 if n % 10 == 3: out += ' {0}'.format(i) n = 0 print(out)
0
null
1,171,919,596,192
60
52
S = input().split("S") S_len = [len(S_each) for S_each in S] print(max(S_len))
r, c = map(int, input().split()) a = [0]*(c+1) for _ in range(r): v = list(map(int, input().split())) s = 0 for i, e in enumerate(v): s+=e a[i]+=e v.append(s) print(*v) a[-1]+=s print(*a)
0
null
3,121,220,301,820
90
59
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): h = gete(int) w = gete(int) n = gete(int) if h < w: h, w = w, h print((h + n - 1) // h) if __name__ == "__main__": main()
n = int(raw_input()) a = map(int,raw_input().split(' ')) nswap=0 for i in range(n): min_v = a[i] min_p = i for j in range(i,n): if min_v > a[j]: min_v = a[j] min_p = j if min_p != i: a[i],a[min_p]=a[min_p],a[i] nswap+=1 print ' '.join([str(v) for v in a]) print nswap
0
null
44,486,074,027,612
236
15
import collections import math def c2(x): c = math.factorial(x) // (math.factorial(x-2)*2) return c n = int(input()) a = list(map(int, input().split())) adic = collections.Counter(a) cnt = 0 for i in adic: num = adic[i] if num > 1: cnt += c2(num) for i in a: num = adic[i] if num == 1: print(cnt) else: print(cnt - (num-1))
#!/usr/bin/python3 import sys from collections import Counter input = lambda: sys.stdin.readline().strip() n = int(input()) a = [int(x) for x in input().split()] c = Counter(a) def c2(n): return n * (n - 1) // 2 ans = sum(c2(v) for v in c.values()) for x in a: print(ans - (c[x] - 1))
1
47,748,385,063,862
null
192
192
n, k = map( int, input().split() ) p = list( map( int, input().split() ) ) sum_k = sum( p[ : k ] ) max_sum_k = sum_k for i in range( k, n ): sum_k += p[ i ] - p[ i - k ] if sum_k > max_sum_k: max_sum_k = sum_k print( ( max_sum_k + k ) / 2 )
N,K = map(int, input().split()) H = list(map(int, input().split())) H_sort = sorted(H) #print (H) if K > N: print(0) else: ans = sum(H_sort[0:N-K]) print(ans)
0
null
77,221,267,779,208
223
227
# -*- coding: utf-8 -*- # B import sys from collections import defaultdict, deque from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) h,w = map(int, input().split()) if h == 1 or w == 1: print(1) elif (h%2==1) and (w%2==1): print(int((h * w // 2)+1)) else: print(int(h*w/2))
H, W = map(int, input().split()) ans = H * W if H * W in [H, W]: print(1) exit() if ans % 2 == 1: ans += 1 print(ans // 2)
1
50,723,305,044,102
null
196
196
n = int(input()) A = sorted(list(map(int, input().split()))) from collections import Counter c = Counter(A) MAX = 10 ** 6 + 1000 dp = [True] * MAX for k, v in c.items(): if dp[k] == False: continue if v > 1: dp[k] = False for x in range(k + k, MAX, k): dp[x] = False res = 0 for x in range(n): if dp[A[x]]: res += 1 print(res)
#A - Payment N = int(input()) #おつり out = 1000 - (N % 1000) if out == 1000: out = 0 # 出力 print(out)
0
null
11,463,605,642,720
129
108
n,a,b=map(int,input().split()) if a+b ==0: print(0) else: c = n//(a+b) d = n%(a+b) if d <= a: print(a*c+d) else: print(a*c+a)
r=input().split() N=int(r[0]) A=int(r[1]) B=int(r[2]) x=N//(A+B) y=N%(A+B) if y<=A: print(A*x+y) else: print(A*(x+1))
1
55,699,626,725,920
null
202
202
n, a, b = map(int, input().split()) mod = 10**9+7 ans = pow(2, n, mod) - 1 up = 1 bo = 1 for i in range(b): up = up*(n-i)%mod bo = bo*(i+1)%mod if i == a-1: acombs = up*pow(bo, mod-2, mod)%mod bcombs = up*pow(bo, mod-2, mod)%mod print((ans - acombs - bcombs)%mod)
n,a,b=map(int,input().split()) p=10**9+7 def cmb(n, r): # 分子(n*(n-1)*...*(n-r+1)) nume = 1 for i in range(n-r+1, n+1): nume = nume * i % p # 分母(1*2*...*r) deno = 1 for j in range(1, r+1): deno = deno * j % p d = pow(deno, p-2, p) return nume * d nca = cmb(n, a) ncb = cmb(n, b) res = pow(2, n, p) - nca - ncb - 1 print(res%p)
1
66,316,318,037,200
null
214
214
n, k = [int(i) for i in input().split()] h = sorted([int(i) for i in input().split()]) if k > len(h): print(0) elif k == 0: print(sum(h)) else: print(sum(h[0:-k]))
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(N: int, P: "List[int]"): ans = 0 l = INF for pi in P: l = min(l, pi) if pi <= l: ans += 1 return ans def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int P = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(f'{solve(N, P)}') if __name__ == '__main__': main()
0
null
82,011,496,718,490
227
233
# import itertools # import math import sys # sys.setrecursionlimit(500*500) # import numpy as np # N = int(input()) # S = input() # n, *a = map(int, open(0)) N, K = map(int, input().split()) A = list(map(int, input().split())) # B = list(map(int, input().split())) # tree = [[] for _ in range(N + 1)] # B_C = [list(map(int,input().split())) for _ in range(M)] # S = input() # B_C = sorted(B_C, reverse=True, key=lambda x:x[1]) # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # def dfs(tree, s): # for l in tree[s]: # if depth[l[0]] == -1: # depth[l[0]] = depth[s] + l[1] # dfs(tree, l[0]) # dfs(tree, 1) A.insert(0, 0) cnt = [0] * (N + 1) j = 1 times_s = 0 times_e = 0 cycle = 0 for i in range(N + 1): if i == K: print(j) sys.exit() cnt[j] += 1 if cnt[j] == 2: times_e = i cycle = j break j = A[j] j = 1 for i in range(N + 1): if j == cycle: times_s = i break j = A[j] #print(A, cnt) #print(times_s, times_e, cycle) K_eff = (K - times_s) % (times_e - times_s) for i in range(N + 1): if i == K_eff: print(j) sys.exit() j = A[j]
import sys input = sys.stdin.readline from collections import defaultdict (n, k), s = map(int, input().split()), list(map(int, input().split())) x, c = [1, s[0]], 0 for i in range(n): x.append(s[x[-1] - 1]) if len(x) > k: print(x[k]); exit() while x[c] != s[x[-1] - 1]: c += 1 print(x[((k - c) % (len(x) - c)) + c])
1
22,731,423,306,150
null
150
150
import sys n = int(input()) a = [int(x) for x in input().split()] d = set() for i in a: if i in d: print("NO") exit() d.add(i) print("YES")
class UnionFind: def __init__(self, n=0): self.d = [-1]*n def find(self, x): if self.d[x] < 0: return x else: self.d[x] = self.find(self.d[x]) return self.d[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.d[x] > self.d[y]: x, y = y, x self.d[x] += self.d[y] self.d[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.d[self.find(x)] n, m, k = map(int, input().split()) deg = [0]*100005 uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 deg[a] += 1 deg[b] += 1 uf.unite(a, b) for _ in range(k): c, d = map(int, input().split()) c -= 1 d -= 1 if uf.same(c, d): deg[c] += 1 deg[d] += 1 for i in range(n): print(uf.size(i) - 1 - deg[i], end="") if i == n-1: print() else: print(" ", end="")
0
null
67,419,373,888,900
222
209
X, K, D = map(int, input().split()) if X - K * D >= 0: ans = abs(X - K * D) elif X + K * D <= 0: ans = abs(X + K * D) else: n = int(abs(X - K * D) / (2 * D)) ans = min(abs(X - K * D + n * 2 * D), abs(X - K * D + (n + 1) * 2 * D)) print(ans)
x, k, d = map(int, input().split()) x = abs(x) if x//d >= k: print(x-k*d) else: k -= x//d x -= d*(x//d) if k%2==0: print(abs(x)) else: print(abs(x-d))
1
5,195,280,838,172
null
92
92
n = int(input()) L = list(map(int, input().split())) L.sort() count = 0 for i in range(n - 2): a = L[i] for j in range(i + 1, n - 1): b = L[j] l = j r = n while r - l > 1: p = (l + r) // 2 if L[p] < a + b: l = p else: r = p count += l - j print(count)
import re print(re.sub(r"\?","D",input()))
0
null
95,256,960,769,432
294
140
#!/usr/bin/env python3 def main(): N, K = map(int, open(0).read().split()) i = 0 while N != 0: N = N // K i += 1 print(i) main()
n,k=map(int,input().split()) a=0 b=n while b>=k: b=b//k a+=1 print(a+1)
1
64,597,485,439,872
null
212
212
N = int(input()) A = [int(i) for i in input().split()] ans = [0 for i in range(N)] for i in A: ans[i-1] += 1 for i in ans: print(i)
import sys import itertools # import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) can_make = [False] * 2001 for bit in range(2 ** n): total = 0 for i in range(n): if bit & 1 << i > 0: total += A[i] if total <= 2000: can_make[total] = True for m in M: if can_make[m]: print("yes") else: print("no")
0
null
16,420,565,283,460
169
25
n = int(input()) ab = [list(map(int, input().split())) for _ in range(n)] ab_a = sorted(ab, key=lambda x:int(x[0])) ab_b = sorted(ab, key=lambda x:int(x[1])) if n%2 == 1: print(ab_b[n//2][1]-ab_a[n//2][0]+1) else: print(int(((ab_b[n//2][1]+ab_b[n//2-1][1])/2.0-(ab_a[n//2][0]+ab_a[n//2-1][0])/2.0)*2+1))
def main(): n = int(input()) A = [0]*n B = [0]*n for i in range(n): a,b = map(int,input().split()) A[i] = a B[i] = b A.sort() B.sort() if n%2 == 0: m1 = (A[n//2-1]+A[n//2])/2 m2 = (B[n//2-1]+B[n//2])/2 print(int(2*(m2-m1))+1) else: print(B[(n+1)//2-1]-A[(n+1)//2-1]+1) main()
1
17,225,424,483,812
null
137
137
import sys import os # import math # input = sys.stdin.readline def int_array(): return list(map(int, input().strip().split())) def str_array(): return input().strip().split() def gcd(a,b): if b == 0: return a return gcd(b, a % b);x def take_input(): if os.environ.get("check"): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') take_input() ######################### TEMPLATE ENDS HERE ################################# for _ in range(int(input())): print("ACL", end="")
s = "0" + input() keta = len(s) dp = [0] * (keta + 1) kuri = 0 for i in range(keta): ni = i + 1 num = int(s[-i - 1]) if kuri: num += 1 kuri = 0 if num == 10: kuri = 1 dp[ni] = dp[i] elif num < 5: dp[ni] = dp[i] + num elif num > 5: num %= 10 kuri = 1 dp[ni] = dp[i] + 10 - num else: nn = int(s[-ni - 1]) if nn < 5: dp[ni] = dp[i] + num else: kuri = 1 dp[ni] = dp[i] + 10 - num print(dp[keta] + kuri)
0
null
36,604,541,057,480
69
219
import sys def input(): return sys.stdin.readline().rstrip() # ライブラリ参照https://atcoder.jp/contests/practice2/submissions/16580070 class SegmentTree: __slots__ = ["func", "e", "original_size", "n", "data"] def __init__(self, length_or_list, func, e): self.func = func self.e = e if isinstance(length_or_list, int): self.original_size = length_or_list self.n = 1 << ((length_or_list - 1).bit_length()) self.data = [self.e] * self.n else: self.original_size = len(length_or_list) self.n = 1 << ((self.original_size - 1).bit_length()) self.data = [self.e] * self.n + length_or_list + \ [self.e] * (self.n - self.original_size) for i in range(self.n-1, 0, -1): self.data[i] = self.func(self.data[2*i], self.data[2*i+1]) def replace(self, index, value): index += self.n self.data[index] = value index //= 2 while index > 0: self.data[index] = self.func( self.data[2*index], self.data[2*index+1]) index //= 2 def folded(self, l, r): left_folded = self.e right_folded = self.e l += self.n r += self.n while l < r: if l % 2: left_folded = self.func(left_folded, self.data[l]) l += 1 if r % 2: r -= 1 right_folded = self.func(self.data[r], right_folded) l //= 2 r //= 2 return self.func(left_folded, right_folded) def all_folded(self): return self.data[1] def __getitem__(self, index): return self.data[self.n + index] def max_right(self, l, f): # assert f(self.e) if l >= self.original_size: return self.original_size l += self.n left_folded = self.e while True: # l //= l & -l while l % 2 == 0: l //= 2 if not f(self.func(left_folded, self.data[l])): while l < self.n: l *= 2 if f(self.func(left_folded, self.data[l])): left_folded = self.func(left_folded, self.data[l]) l += 1 return l - self.n left_folded = self.func(left_folded, self.data[l]) l += 1 if l == l & -l: break return self.original_size # 未verify def min_left(self, r, f): # assert f(self.e) if r == 0: return 0 r += self.n right_folded = self.e while True: r //= r & -r if not f(self.func(self.data[r], right_folded)): while r < self.n: r = 2 * r + 1 if f(self.func(self.data[r], right_folded)): right_folded = self.func(self.data[r], right_folded) r -= 1 return r + 1 - self.n if r == r & -r: break return 0 def orr(x, y): return x | y def main(): N = int(input()) S = input() S = list(map(lambda c: 2**(ord(c) - ord('a')), list(S))) Q = int(input()) seg = SegmentTree(S, orr, 0) for _ in range(Q): num, x, y = input().split() if num == '1': seg.replace(int(x)-1, 2**(ord(y) - ord('a'))) else: bits = seg.folded(int(x)-1, int(y)) print(sum(map(int, list(bin(bits))[2:]))) if __name__ == '__main__': main()
class SegmentTree: def __init__(self, n, init_value, segfunc, ide_ele): self.N0 = 2 ** (n - 1).bit_length() self.ide_ele = ide_ele self.data = [ide_ele] * (2 * self.N0) self.segfunc = segfunc for i in range(n): self.data[i + self.N0 - 1] = init_value[i] for i in range(self.N0 - 2, -1, -1): self.data[i] = self.segfunc(self.data[2 * i + 1], self.data[2 * i + 2]) def update(self, _k, x): k = _k + self.N0 - 1 self.data[k] = x while k: k = (k - 1) // 2 self.data[k] = self.segfunc(self.data[k * 2 + 1], self.data[k * 2 + 2]) def query(self, _p, _q): p = _p q = _q if q <= p: return self.ide_ele p += self.N0 - 1 q += self.N0 - 2 res = self.ide_ele while 1 < q - p: if p & 1 == 0: res = self.segfunc(res, self.data[p]) if q & 1 == 1: res = self.segfunc(res, self.data[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.data[p]) else: res = self.segfunc(self.segfunc(res, self.data[p]), self.data[q]) return res def popcount(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def solve(): N = int(input()) S = input() Q = int(input()) init_val = [1 << ord(S[i]) - ord('a') for i in range(N)] def segfunc(a, b): return a | b seg_tree = SegmentTree(N, init_val, segfunc, 0) for _ in range(Q): cmd, *query = input().split() cmd = int(cmd) if cmd == 1: i = int(query[0]) - 1 c = query[1] seg_tree.update(i, 1 << ord(c) - ord('a')) else: l = int(query[0]) - 1 r = int(query[1]) kind = seg_tree.query(l, r) print(popcount(kind)) if __name__ == '__main__': solve()
1
62,491,436,001,526
null
210
210
import numpy as np from numba import njit from numba.types import i8 ni8 = np.int64 MOD = 998244353 @njit((i8[:,::-1], i8[:], i8, i8), cache=True) def solve(lr, dp, n, k): acc_dp = np.ones_like(dp) for i in range(1, n): val = 0 for j in range(k): a = i - lr[j, 0] if a < 0: continue b = i - lr[j, 1] - 1 val += acc_dp[a] - (acc_dp[b] if b >= 0 else 0) dp[i] = val % MOD acc_dp[i] = (acc_dp[i - 1] + dp[i]) % MOD return dp[n - 1] def main(): f = open(0) n, k = [int(x) for x in f.readline().split()] lr = np.fromstring(f.read(), ni8, sep=' ').reshape((-1, 2)) dp = np.zeros(n, ni8) dp[0] = 1 ans = solve(lr, dp, n, k) print(ans) main()
# -*- coding: utf-8 -*- import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 998244353 class BIT2: def __init__(self, N): self.N = (N+1) self.data0 = [0] * (N+1) self.data1 = [0] * (N+1) def _add(self, data, k, x): while k < self.N: #k <= Nと同義 data[k] += x k += k & -k def _sum(self, data, k): s = 0 while k: s += data[k] k -= k & -k return s def add(self, l, r, x): self._add(self.data0, l, -x*(l-1)) self._add(self.data0, r, x*(r-1)) self._add(self.data1, l, x) self._add(self.data1, r, -x) def sum(self, l, r): return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1) N, K = map(int, readline().split()) bit = BIT2(N) d = [] for _ in range(K): L,R = map(int, readline().split()) d.append((L,R)) bit.add(1,2,1) for i in range(2,N+1): for k in range(K): L,R = d[k] tmp = bit.sum(max(1,i-R),max(1,i-L+1))%MOD bit.add(i,i+1,tmp) print(bit.sum(N,N+1)%MOD)
1
2,719,432,349,074
null
74
74
K,N=map(int, input().split()) A=list(map(int, input().split())) B=[0]*N for i in range(N-1): B[i]=A[i+1]-A[i] B[-1]=A[0]+K-A[-1] B=sorted(B) ans = sum(B[0:-1]) print(ans)
k, n = map(int, input().split()) a = list(map(int, input().split())) a += [k + a[0]] print(k - max([a[i + 1] - a[i] for i in range(n)]))
1
43,330,328,654,130
null
186
186
import sys sys.setrecursionlimit(int(1e9)) class uft: def __init__(self, N): self.__N = N self.__arr = [-1] * (N + 1) def fp(self, x): if self.__arr[x] < 0: return x else: self.__arr[x] = self.fp(self.__arr[x]) return self.__arr[x] def add(self, x, y): px = self.fp(x) py = self.fp(y) if px > py: px, py = py, px if px == py: return 1 self.__arr[px] += self.__arr[py] self.__arr[py] = px def groups(self): ret = -1 for i in self.__arr: if i < 0: ret += 1 return ret def show_arr(self): print(self.__arr) N, M = map(int, input().split()) UFT = uft(N) for i in range(M): A, B = map(int, input().split()) UFT.add(A,B) print(UFT.groups() -1)
N,M=map(int,input().split()) #brr=[list(map(int,input().split())) for i in range(M)] arr=[[] for i in range(N)] check=[0]*N ans=[] for i in range(M): a,b=map(int,input().split()) arr[a-1].append(b-1) arr[b-1].append(a-1) q=[] cnt=0 for i in range(N): if check[i]==0: cnt+=1 q.append(i) #print(cnt,q) while q: x=q.pop() if check[x]==0: check[x]=1 for j in arr[x]: q.append(j) print(cnt-1)
1
2,270,581,299,712
null
70
70
A, B, C, K = [int(i) for i in input().split(' ')] print(min(A, K) - max(K - B - A, 0))
A, B, C, K = map(int, input().split()) # 1:A枚, 0:B枚, -1:C枚, K枚を選ぶ A = min(A, K) B = min(K - A, B) C = min(K - A - B, C) assert A + B + C >= K #print(A, B, C) print(A - C)
1
21,878,027,891,784
null
148
148
import numpy as np import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines from collections import defaultdict N, *A = map(int, read().split()) INF = 10**18 dp_not = defaultdict(lambda : -INF) dp_take = defaultdict(lambda: -INF) dp_not[(0,0)] = 0 for i,x in enumerate(A,1): j = (i-1)//2 for n in (j,j+1): dp_not[(i,n)] = max(dp_not[(i-1,n)], dp_take[(i-1,n)]) dp_take[(i,n)] = dp_not[(i-1,n-1)] + x print(max(dp_not[(N, N//2)], dp_take[(N, N//2)]))
k = int(input().split(' ')[1]) print(sum( sorted([int(n) for n in input().split(' ')])[0:k]))
0
null
24,610,897,584,240
177
120
H,A=input().split() print('Yes' if H==A else 'No')
#!/usr/bin/env python3 # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): N = int(input()) C = list(input()) Rc = len(list(filter(lambda x:x=="R",C))) Wc = len(C) - Rc c = 0 for i in range(Rc): if C[i] == "W": c+=1 # print(Rc) # print(Wc) print(c) pass if __name__ == '__main__': main()
0
null
45,045,706,732,972
231
98
n = int(input()) s = input() # 3桁の番号を作るにあたり、文字列から抽出して作るのではなく、000〜999までの組み合わせが存在するかを確認する。 ans = 0 for i in range(10): a = s.find(str(i)) for j in range(10): b = s.find(str(j), a+1) # aの取得位置の次から検索を行う for k in range(10): c = s.find(str(k), b+1) # bの取得位置の次から検索を行う if a == -1 or b == -1 or c == -1: continue else: ans += 1 print(ans)
N=int(input()) S=input() ans=0 for i in range(10): for j in range(10): for k in range(10): p,q,r=str(i),str(j),str(k) if p in S: x=S.index(p) S_=S[x+1:] if q in S_: y=S_.index(q) S__=S_[y+1:] if r in S__: ans+=1 print(ans)
1
128,808,672,155,680
null
267
267
N, S = map(int,input().split()) A = [int(s) for s in input().split()] DP = [[0 for j in range(S + 1)] for i in range(N + 1)] mod = 998244353 DP[0][0] = 1 for i in range(N): for j in range(S + 1): DP[i + 1][j] += 2 * DP[i][j] DP[i + 1][j] %= mod if j + A[i] <= S: DP[i + 1][j + A[i]] += DP[i][j] DP[i + 1][j + A[i]] %= mod print(DP[N][S])
from copy import copy C,R,K=map(int,input().split()) dp=[[0]*(R+1) for i1 in range(4)] M=[[0]*R for i in range(C)] for i in range(K): r,c,v=map(int,input().split()) M[r-1][c-1]=v for i,l in enumerate(M): for num in range(1,4): for j in range(R): if num==1: dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j]) else: dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j]) dp[0]=dp[-1][1:-1]+[0,dp[-1][0]] print(dp[-1][-2])
0
null
11,648,802,360,548
138
94
a, b, k = map(int, input().split()) if k <= a: a -= k elif a < k <= a + b: temp = a a = 0 b -= k - temp else: a = 0 b = 0 print('{} {}'.format(a, b))
a, b, k = map( int, input().split() ) if a + b < k: print( "0 0" ) elif a < k: print( "0 " + str( a + b - k ) ) else: print( str( a - k ) + " " + str( b ) )
1
104,325,424,802,720
null
249
249
n = input() print("Yes" if n.find('7') != -1 else "No")
N=list(input()) ans=False if N[0]=="7": ans=True if N[1]=="7": ans=True if N[2]=="7": ans=True if ans: print("Yes") else: print("No")
1
34,273,223,502,562
null
172
172
def mod_pow(a, n, mod): """ 二分累乗法による a^n (mod m)の実装 :param a: 累乗の底 :param n: 累乗の指数 :param mod: 法 :return: a^n (mod m) """ result = 1 a_n = a while n > 0: if n & 1: result = result * a_n % mod a_n = a_n * a_n % mod n >>= 1 return result def mod_inverse(a, mod): """ フェルマーの小定理による a^-1 ≡ 1 (mod m)の実装 aの逆元を計算する a^-1 ≡ 1 (mod m) a * a^-2 ≡ 1 (mod m) a^-2 ≡ a^-1 (mod m) :param a: 逆元を計算したい数 :param mod: 法 :return: a^-1 ≡ 1 (mod m) """ return mod_pow(a=a, n=mod - 2, mod=mod) def mod_combination(n, k, mod): fact_n = 1 fact_k = 1 for i in range(k): fact_n *= (n - i) fact_n %= mod fact_k *= (i + 1) fact_k %= mod fact_n *= mod_inverse(fact_k, mod) return fact_n % mod N, A, B = map(int, input().split(' ')) MOD = 10 ** 9 + 7 print((mod_pow(2, N, MOD) - 1 - mod_combination(N, A, MOD) - mod_combination(N, B, MOD)) % MOD)
Nsum = 0 while True: I = input() if int(I) == 0: break for i in I: Nsum += int(i) print(Nsum) Nsum = 0
0
null
33,991,423,917,692
214
62
input();x=map(int,raw_input().split());print min(x),max(x),sum(x)
n=input() lst=[int(x) for x in input().split()] print(min(lst),max(lst),sum(lst))
1
726,164,609,376
null
48
48
import sys n,m,l=map(int,input().split()) e=[list(map(int,e.split()))for e in sys.stdin] for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])
n, m, l = map(int, input().split()) A = [] B = [] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): B.append([int(j) for j in input().split()]) # ??????????????????????????????B?????¢??????????????¨??????????????? B_T = list(map(list, zip(*B))) C = [[0 for j in range(l)] for i in range(n)] for i in range(n): for j in range(l): C[i][j] = sum([a * b for (a, b) in zip(A[i], B_T[j])]) for i in range(n): print(*C[i])
1
1,408,782,245,860
null
60
60
N,A,B=list(map(int, input().split())) ct=N//(A+B) res=N%(A+B) print(A*ct + min(A,res))
import numpy as np from scipy.sparse.csgraph import floyd_warshall N,M,L = map(int,input().split()) gurahu = np.zeros((N,N)) for k in range(M): a,b,c = map(int,input().split()) gurahu[a-1,b-1] = c gurahu[b-1,a-1] = c gurahu = floyd_warshall(gurahu, directed=False) gurahu = np.where((gurahu <= L) & (gurahu > 0), 1, 0) gurahu = floyd_warshall(gurahu) - np.ones((N, N)) Q = int(input()) for k in range(Q): s,t = map(int,input().split()) ans = gurahu[s-1,t-1] if ans == float('inf'): print(-1) else: print(int(ans))
0
null
114,746,564,069,720
202
295
s = list(input()) if s.count('R') == 3: print(3) elif s.count('R') == 1: print(1) elif s.count('R') == 0: print(0) else: if s[1] == 'R': print(2) else: print(1)
N = int(input("")) a = input("").split(" ") a = [int(i) for i in a] m = 1000 list_ = [] for j in range(0, N-1): if a[j] < a[j + 1]: n = m // a[j] k = (a[j + 1] - a[j]) * n m = m + k print(m)
0
null
6,119,196,370,478
90
103
import math INFTY=100000000 n=int(input()) def kock(p1,p2,n): s=[(p1[0]*2+p2[0])/3, (p1[1]*2+p2[1])/3] t=[(p1[0]+p2[0]*2)/3, (p1[1]+p2[1]*2)/3] u=[(t[0]-s[0])/2-(t[1]-s[1])/2*math.sqrt(3)+s[0], (t[0]-s[0])/2*math.sqrt(3)+(t[1]-s[1])/2+s[1]] if n==0: print("%.8f %.8f"%(p1[0],p1[1])) else: kock(p1,s,n-1) kock(s,u,n-1) kock(u,t,n-1) kock(t,p2,n-1) start=[0.0,0.0] end=[100.0, 0.0] if n==0: print("%.8f %.8f"%(start[0],start[1])) print("%.8f %.8f"%(end[0],end[1])) else: kock(start,end,n) print("%.8f %.8f"%(end[0],end[1]))
def main(): N, K = map(int, input().split()) N %= K ans = abs(N-K) print(ans if ans < N else N) if __name__ == '__main__': main()
0
null
19,677,248,962,670
27
180
N = int(input()) A = list(map(int,input().split())) minm = A[0] ans = 0 for i in range(1,N): if A[i] < minm: ans += minm - A[i] if A[i] > minm: minm = A[i] print(ans)
l,r,d= map(int,input().split()) print(sum([1 if t%d==0 else 0 for t in range(l,r+1)]))
0
null
6,037,385,473,764
88
104
n, m = [int(i) for i in input().split()] n_list = [10] * n for _ in range(m): si, ci = [int(i) for i in input().split()] if n_list[si - 1] == 10: n_list[si - 1] = ci elif n_list[si - 1] != ci: print(-1) exit() if n != 1: ans = n_list[0] if n_list[0] != 10 else 1 else: ans = n_list[0] if n_list[0] != 10 else 0 if ans == 0 and n != 1: print(-1) exit() for ai in n_list[1:]: if ai != 10: ans = ans * 10 + ai else: ans = ans * 10 print(ans)
N=int(input()) for line in range(N): a,b,c = (int(i) for i in input().split()) if (a**2+b**2==c**2) or (b**2+c**2==a**2) or (c**2+a**2==b**2): print('YES') else: print('NO')
0
null
30,526,582,984,928
208
4
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): C = readline().rstrip().decode() print(chr(ord(C) + 1)) if __name__ == '__main__': main()
S = input() T = input() s = len(S) t = len(T) ans = t for j in range(s - t + 1): val = 0 for i in range(t): if S[j:j + t][i] != T[i]: val += 1 ans = min(ans, val) print(ans)
0
null
47,794,930,066,132
239
82
x = int(input()) def f(a,b): return a**5-b**5 for a in range(-120,120): for b in range(-120,120): if f(a,b)==x: print(a,b) exit()
import math X= int(input()) for A in range(-120,121): for B in range(-120,A+1): if A**5-B**5 == X: print(A,B) exit()
1
25,455,349,947,872
null
156
156
import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) if N % 2 == 0: dp = [[0, 0] for i in range(N)] dp[1] = [A[0], A[1]] for i in range(3, N, 2): dp[i][0] = dp[i - 2][0] + A[i - 1] dp[i][1] = max(dp[i - 2][0] + A[i], dp[i - 2][1] + A[i]) print(max(dp[N - 1])) else: dp = [[0, 0, 0] for i in range(N)] dp[0] = [A[0], 0, 0] for i in range(2, N, 2): dp[i][0] = dp[i - 2][0] + A[i] dp[i][1] = max(dp[i - 2][0], dp[i - 2][1] + A[i - 1]) dp[i][2] = max(dp[i - 2][1] + A[i], dp[i - 2][2] + A[i]) print(max(dp[N - 1]))
import copy n = int(input()) a = list(map(int, input().split())) k = 1 + n%2 INF = 10**18 dp = [[-INF]*4 for i in range(n+5)] dp[0][0] = 0 for i in range(n): for j in range(k+1): dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]) now = copy.deepcopy(dp[i][j]) if (i+j) % 2 == 0: now += a[i] dp[i+1][j] = max(dp[i+1][j], now) print(dp[n][k])
1
37,468,752,455,862
null
177
177
import math a, b, C = map(float, input().split()) h = b * math.sin(math.radians(C)) S = a * h / 2 a1 = b * math.cos(math.radians(C)) cc = math.sqrt(h * h + (a - a1) * (a - a1)) print("{a:5f}".format(a=S)) print("{a:5f}".format(a=a + b + cc)) print("{a:5f}".format(a=h))
import math a, b, C=map(int, input().split()) print("{0:.5f}".format((1/2)*a*b*math.sin(C*math.pi/180.0))) print("{0:.5f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180)))) print("{0:.5f}".format(b*math.sin(C*math.pi/180.0)))
1
170,331,376,362
null
30
30
N = int(input()) c = 0 for _ in range(N): D1, D2 = map(int, input().split()) if D1 == D2: c += 1 if c == 3: print('Yes') exit() else: c = 0 print('No')
n = int(input()) count = 0 ans = 'No' for i in range(n): a , b = map(int,input().split(' ')) if a!=b: count = 0 else: count += 1 if count == 3: ans = 'Yes' print(ans)
1
2,442,539,755,740
null
72
72
#!/usr/bin/env python3 from functools import reduce x, y = map(int, input().split()) mod = 10**9 + 7 def cmb(n, r, m): def mul(a, b): return a * b % m r = min(n - r, r) if r == 0: return 1 over = reduce(mul, range(n, n - r, -1)) under = reduce(mul, range(1, r + 1)) return (over * pow(under, m - 2, m))%m r = abs(x - y) l = (min(x, y) - r) // 3 r += l if (x+y)%3 < 1 and l >= 0: print(cmb(r + l, l, mod)) else: print(0)
X, Y = map(int, input().split()) if (2*X-Y)%3==0 and (2*Y-X)%3==0: a = (2*X-Y)//3 b = (2*Y-X)//3 if a>=0 and b>=0: MOD = 10**9+7 n = a+b+1 fac = [1]*(n+1) rev = [1]*(n+1) for i in range(1,n+1): fac[i] = i*fac[i-1]%MOD rev[i] = pow(fac[i], MOD-2, MOD) comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD print(comb(a+b, a)) else: print(0) else: print(0)
1
149,550,881,343,878
null
281
281
def l_in(type_): return list(map(type_, input().split())) def i_in(): return int(input()) def m_in(type_): return map(type_, input().split()) def r_in(n, type_): return [type_(input()) for _ in range(n)] ans = None def absmax(a, b): if abs(a) > abs(b): return a return b def absmin(a, b): if abs(a) < abs(b): return a return b a, b, c, d = m_in(int) aa, bb, cc, dd = abs(a), abs(b), abs(c), abs(d) x, y = 0, 0 abm = absmax(a, b) cdm = absmax(c, d) if (abm>0) == (cdm>0): ans = abm*cdm else: abi = absmin(a, b) cdi = absmin(c, d) if (abi>0) == (cdm>0): k = abi*cdm if ans is None or k > ans: ans = k if (abm>0) == (cdi>0): k = abm*cdi if ans is None or k > ans: ans = k k = abi*cdi if ans is None: ans = k print(ans)
num = list(map(int,input().split())) max_num = 0 max_num = num[0] * num[2] max_num = max(max_num, num[0] * num[3]) max_num = max(max_num, num[1] * num[2]) max_num = max(max_num, num[1] * num[3]) print(max_num)
1
3,054,538,940,768
null
77
77
import math def GCD(a): gcd = a[0] N = len(a) for i in range(1, N): gcd = math.gcd(gcd, a[i]) return gcd # 素因数分解 def fact(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr n = int(input()) A = list(map(int, input().split())) hst = [0] * (max(A) + 1) for a in A: F = fact(a) for f in F: hst[f[0]] += 1 if hst[f[0]] > 1 and f[0] != 1: # ここでpairwise じゃないことが確定する if GCD(A) == 1: print("setwise coprime") else: print("not coprime") exit() print("pairwise coprime")
s=list(input()) s.reverse() mod=2019 n=[0]*len(s) n[0]=1 cnt=[0]*len(s) cnt[0]=int(s[0]) ans=[0]*2019 answer=0 for i in range(1,len(s)): n[i]+=(n[i-1]*10)%mod for i in range(1,len(s)): cnt[i]=(cnt[i-1]+int(s[i])*n[i])%mod for i in cnt: ans[i]+=1 for i in range(len(ans)): answer+=(ans[i]*(ans[i]-1))//2 answer+=ans[0] print(answer)
0
null
17,629,801,787,290
85
166
def sumitrust2019_d(): n = int(input()) s = input() ans = 0 for i in range(1000): # 確認するpinの数字の組み合わせと桁の初期化 # pin = list(str(i).zfill(3)) current_digit = 0 pin = f'{i:0>3}' search_num = pin[current_digit] for num in s: # 見つけると桁を右に一つずらす # 毎回リストにアクセスするより変数に取り出しておくほうがいいかも。 # if num == pin[current_digit]: if num == search_num: current_digit += 1 # indexが3(桁が3→2→1→0)になったときはそのPINは作れる if current_digit == 3: ans += 1 break # 見つけ終わるまではチェックする数字を置き換え。 elif current_digit < 3: search_num = pin[current_digit] print(ans) if __name__ == '__main__': sumitrust2019_d()
n=int(input()) d=list(map(int,input().split())) sum=0 for i in range(n): for j in range(n): if j<=i: continue else: sum+=d[i]*d[j] print(sum)
0
null
147,889,853,289,692
267
292
s=0 j=0 a=[] k=[] l=[] for i,x in enumerate(input()): if x=='\\': a+=[i] elif x=='/' and a: j=a.pop() y=i-j;s+=y while k and k[-1]>j: y+=l.pop() k.pop() k+=[j] l+=[y] print(s) print(len(k),*(l))
x, k, d = [int(i) for i in input().split()] if x < 0: x = -x l = min(k, x // d) k -= l x -= l * d if k % 2 == 0: print(x) else: print(d - x)
0
null
2,669,598,150,466
21
92
l=list(map(int,input().split())) l.sort() if l[0]==l[1]==l[2] or l[0]!=l[1]!=l[2]: print("No") else: print("Yes")
a,b,c = map(int, input().split()) print(str(c)+" "+str(a)+" "+str(b))
0
null
52,873,759,481,660
216
178
import itertools N,M,Q=map(int,input().split()) A=[] for i in range(Q): A.append(list(map(int,input().split()))) A[i][0] -= 1 A[i][1] -= 1 score = 0 max = 0 for iter in itertools.combinations_with_replacement(range(1,M+1),N): score = 0 for i in range(Q): if iter[A[i][1]] - iter[A[i][0]] == A[i][2]: score += A[i][3] if max < score: max = score print(max)
from itertools import combinations_with_replacement N, M, Q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(Q)] ans = 0 for i in combinations_with_replacement(range(1, M+1), N): tmp = 0 for a, b, c, d in A: if i[b-1] - i[a-1] == c: tmp += d ans = max(ans, tmp) print(ans)
1
27,660,105,913,274
null
160
160
a = [list(map(int, input().split())) for i in range(3)] n = int(input()) b = [int(input()) for i in range(n)] for i in b: for j in range(0,3): for k in range(0,3): if i == a[j][k]: a[j][k] = 0 if a[0][0]==0 and a[0][1]==0 and a[0][2]==0: print("Yes") elif a[1][0]==0 and a[1][1]==0 and a[1][2]==0: print("Yes") elif a[2][0]==0 and a[2][1]==0 and a[2][2]==0: print("Yes") elif a[0][0]==0 and a[1][0]==0 and a[2][0]==0: print("Yes") elif a[0][1]==0 and a[1][1]==0 and a[2][1]==0: print("Yes") elif a[0][2]==0 and a[1][2]==0 and a[2][2]==0: print("Yes") elif a[0][0]==0 and a[1][1]==0 and a[2][2]==0: print("Yes") elif a[0][2]==0 and a[1][1]==0 and a[2][0]==0: print("Yes") else: print("No")
# coding: utf-8 def main(): A, B = map(int, input().split()) ans = -1 for i in range(10001): if i * 8 // 100 == A and i // 10 == B: ans = i break print(ans) if __name__ == "__main__": main()
0
null
58,160,467,622,962
207
203
a,b = input().split() a = int(a) b = int(b) if a >= 10 or b >=10: print ('-1') else: print (a * b)
import math n =int(input()) x = [int (x) for x in input().split()] y = [int (y) for y in input().split()] for p in range(1,4): s =sum([abs(x[i]-y[i])**p for i in range(n)]) s = s**(1/p) print("%.6f" % s) s = max([abs(x[i]-y[i]) for i in range(n)]) print("%.6f" % s)
0
null
79,399,496,003,548
286
32
S = input() q = int(input()) for i in range(q): L = input().split() a = int(L[1]) b = int(L[2]) slice1 = S[:a] slice2 = S[a:b+1] slice3 = S[b+1:] if L[0] == 'print': print(slice2) elif L[0] == 'reverse': S = slice1 + slice2[::-1] + slice3 elif L[0] == 'replace': S = slice1 + L[3] + slice3
n,m = map(int,input().split()) if(n%2==1): for i in range(1,m+1): print(' '.join(map(str,[i,n+1-i]))) exit() m1,m2 = (m+1)//2 ,m//2 sum1 = 1 + n//2 sum2 = (n//2+1) + (n-1) for i in range(m1): print(' '.join(map(str,[1+i,n//2 -i]))) for i in range(m2): print(' '.join(map(str,[n//2+1+i,n-1-i])))
0
null
15,456,908,278,162
68
162
n=map(int,input().split()) *p,=map(int,input().split()) lmin=10**10 ans=0 for pp in p: ans+=1 if pp<=lmin else 0 lmin=min(pp,lmin) print(ans)
def solve(): s = input() if s == 'SUN': print(7) elif s == 'MON': print(6) elif s == 'TUE': print(5) elif s == 'WED': print(4) elif s == 'THU': print(3) elif s == 'FRI': print(2) elif s == 'SAT': print(1) if __name__ == '__main__': solve()
0
null
108,696,488,237,600
233
270
hankei = input() print(int(hankei)**2)
from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): S = input() if S == "ABC": print ("ARC") else: print ("ABC") mode = 's' if mode == 'T': t = ri() for i in range(t): solve() else: solve()
0
null
84,539,499,935,340
278
153
v=raw_input() a=int(v[:v.find(" ")]) b=int(v[v.find(" "):]) if(a>b): print "a > b" elif(a<b): print "a < b" else: print "a == b"
input_line = input().split() a = int(input_line[0]) b = int(input_line[1]) if a > b: symbol = ">" elif a < b: symbol = "<" else: symbol = "==" print("a",symbol,"b")
1
358,615,817,280
null
38
38
k=int(input()) a,b=map(int,input().split(' ')) flag=0 for i in range(a,b+1): if i%k==0: flag=1 if flag==1: print('OK') else: print('NG')
print("No" if input() in ["AAA","BBB"] else "Yes")
0
null
40,677,227,793,800
158
201
import bisect N=int(input()) L=[int(i) for i in input().split()] L.sort() ans=0 for i in range(N-2): for j in range(i+1,N-1): x=L[i]+L[j] ans+=(bisect.bisect_left(L,x)-j-1) print(ans)
import math print((int)(math.ceil((int)(input())/2)))
0
null
115,648,597,228,262
294
206
n = int(input()) a = ["a","b","c","d","e","f","g","h","i","j"] def dfs(s, max_x, LEN): if LEN == n: print(s) else: for c in a[:a.index(max_x)+2]: dfs(s+c, max(max_x,c), LEN+1) dfs("a", "a", 1)
s = input() t = input() ans = 10**8 for i in range(len(s)-len(t)+1): cnt = 0 for j in range(len(t)): if s[i+j] != t[j]: cnt += 1 ans = min(ans, cnt) print(ans)
0
null
28,089,202,782,280
198
82
kuku = [] for i in range(1,10): for j in range(1,10): if i * j not in kuku: kuku.append(i*j) n = int(input()) if n in kuku: print('Yes') else: print('No')
def resolve(): n = int(input()) ans = 'No' for i in range(1,10): for j in range(1,10): if i*j == n: ans = 'Yes' print(ans) resolve()
1
160,332,384,903,910
null
287
287
def main(): import sys input = sys.stdin.readline h,w,m = map(int, input().split()) h_count = [0 for _ in range(h)] w_count = [0 for _ in range(w)] pairs = set() for i in range (m): hi, wi = map(int, input().split()) hi -= 1 wi -= 1 h_count[hi] += 1 w_count[wi] += 1 pairs.add((hi,wi)) h_max = max(h_count) w_max = max(w_count) hk = list() wk = list() for index , hj in enumerate(h_count): if hj == h_max: hk.append(index) for index, wj in enumerate(w_count): if wj == w_max: wk.append(index) ans = h_max + w_max for _h in hk: for _w in wk: hw = (_h, _w) if hw in pairs: continue print(ans) exit() print(ans -1) if __name__ == '__main__': main()
H, W, M = map(int, input().split()) h_list = [0] * H w_list = [0] * W target = [] for _ in range(M): h, w = map(int, input().split()) h_list[h-1] += 1 w_list[w-1] += 1 target += [[h-1,w-1]] h_max = max(h_list) w_max = max(w_list) h_max_list = set([i for i, v in enumerate(h_list) if v == h_max]) w_max_list = set([i for i, v in enumerate(w_list) if v == w_max]) place = len(h_max_list) * len(w_max_list) candidate = 0 for h,w in target: if (h in h_max_list) and (w in w_max_list): candidate +=1 print(h_max+w_max-(place == candidate))
1
4,719,789,387,790
null
89
89
n = int(input()) a = list(map(int, input().split())) m = 1 if 0 in a: print(0) else: for i in range(n): m = m * a[i] if m > 10 ** 18: print(-1) break elif i == n - 1: print(m)
#!/usr/bin/env python3 import sys from itertools import chain MAX = 10 ** 18 def solve(N: int, A: "List[int]"): A = sorted(A) answer = 1 for a in A: answer *= a if answer > MAX: return -1 return answer def main(): tokens = chain(*(line.split() for line in sys.stdin)) # N, A = map(int, line.split()) N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" answer = solve(N, A) print(answer) if __name__ == "__main__": main()
1
16,072,125,399,980
null
134
134
DP = [False]*100001 DP[0] = True for TN in range(0,100001): if TN>=100 and DP[TN-100]: DP[TN] = True continue if TN>=101 and DP[TN-101]: DP[TN] = True continue if TN>=102 and DP[TN-102]: DP[TN] = True continue if TN>=103 and DP[TN-103]: DP[TN] = True continue if TN>=104 and DP[TN-104]: DP[TN] = True continue if TN>=105 and DP[TN-105]: DP[TN] = True continue print([0,1][DP[int(input())]])
n = int(input()) a = n // 100 b = n % 100 check = a > 20 or b / 5 <= a print("1" if check else "0")
1
126,770,360,271,276
null
266
266
n,m = map(int,input().split()) print("Yes" if n == m else "No")
N, M = [int(_) for _ in input().split()] if N == M: print('Yes') else: print('No')
1
83,106,357,018,912
null
231
231
N, = map(int, input().split()) X = [(i+1, x) for i, x in enumerate(map(int, input().split()))] dp = [[0]*(N+1) for _ in range(N+1)] X = sorted(X, key=lambda x:x[1])[::-1] for i in range(1, N+1): ai, a = X[i-1] dp[i][0] = dp[i-1][0]+a*abs(ai-(N-i+1)) for j in range(1, i): dp[i][j] = max(dp[i-1][j-1]+a*abs(ai-j), dp[i-1][j]+a*abs(ai-(N-(i-j)+1))) dp[i][i] = dp[i-1][i-1]+a*abs(ai-i) print(max(dp[-1]))
import sys read = sys.stdin.read #readlines = sys.stdin.readlines def main(): n = int(input()) rc = tuple(input()) rc2 = [c == 'W' for c in rc] r1 = sum(rc2) # 白をすべて赤にした場合 r2 = n - r1 # 赤をすべて白にした場合。 r3 = sum(rc2[:r2]) # 赤を左につめるのに邪魔になる白の数 print(min(r1, r2, r3)) if __name__ == '__main__': main()
0
null
19,922,868,833,530
171
98
S = input() T = input() ans = '' if len(T) != len(S) + 1: ans = 'No' else: ans = 'Yes' for i in range(len(S)): if S[i] != T[i]: ans = 'No' print(ans)
s = input() t = input() if s == t[:-1]: print('Yes') else: print('No')
1
21,422,624,277,958
null
147
147
def main(): import math s = int(input()) mod = 10**9+7 c = s//3 ans = 0 for i in range(1,c+1): l = s - i*3 ans += (math.factorial(l+i-1)//math.factorial(l)//math.factorial(i-1)) % mod print(ans%mod) if __name__ == "__main__": main()
S = int(input()) p = 10**9 +7 def pow_mod(p,a,n): res = 1 while n > 0: if n % 2 == 1: res = (res * a) % p n = n // 2 a = (a*a)%p return res n = 2000 fac = [1] foo = 1 for i in range(1,n+1): foo = (foo*i)%p fac.append(foo) #コンビネーションのmod def comb_mod(n,k): res = (fac[n] * pow_mod(p,fac[k],p-2) * pow_mod(p,fac[n-k],p-2)) % p return res ans = 0 for i in range(1,1+S//3): t = S - 3*i ans = (ans + comb_mod(t+i-1,t)) %p print(ans)
1
3,296,115,448,480
null
79
79