input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdi...
import sys sys.setrecursionlimit(10**7) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdi...
p02937
import collections s = input() t = input() i = 0 c = 0 while(True): progress = False j = 0 for j in range(len(s)): if s[j] == t[i]: i+=1 progress = True if i == len(t): break if progress is False: break if i == len(t): break c += 1 print(c * len(s) + j + 1 if progress else -1)
import collections s = input() t = input() sb = s + s h = {chr(ord('a') + i):-1 for i in range(26)} dp = [] for j in range(len(sb)-1,-1,-1): dp.append({k:h[k] for k in h}) h[sb[j]] = j special = h dp = dp[::-1] i = -1 j = 0 c = 0 while(j < len(t)): ha = dp[i] if i >= 0 else special letter = t[j] i...
p02937
import sys def SI(): return sys.stdin.readline().strip() def main(): s = SI() t = SI() import collections didx = collections.defaultdict(int) d = collections.defaultdict(list) for i, c in enumerate(s): d[c].append(i) keys = list(d.keys()) for c in set(t): ...
import sys def SI(): return sys.stdin.readline().strip() def main(): s = SI() t = SI() import collections d = collections.defaultdict(list) for i, c in enumerate(s): d[c].append(i) keys = list(d.keys()) for c in set(t): if c not in keys: print((-...
p02937
import sys readline = sys.stdin.readline S = readline().rstrip() T = readline().rstrip() if len(set(T) - set(S)) > 0: print((-1)) exit(0) import bisect # Tの各文字を探す S2 = S * 2 from collections import defaultdict # ある文字が何文字目にあるか辞書 dic = defaultdict(list) for i in range(len(S2)): dic[S2[i]] +=...
import sys readline = sys.stdin.readline S = readline().rstrip() T = readline().rstrip() if len(set(T) - set(S)) > 0: print((-1)) exit(0) import bisect S2 = S * 2 from collections import defaultdict dic = defaultdict(list) for i in range(len(S2)): dic[S2[i]] += [i] ind = -1 ans = 0 for ...
p02937
from collections import defaultdict s=input().strip() t=input().strip() def gg(cc, c, l, d): if d[c][-1] <= cc: return d[c][1], l+1 ll = d[c] mx, mn = len(ll)-2, 0 x = (mx - mn)//2 while True: if ll[x] <= cc and cc < ll[x+1]: return ll[x+1], l if cc < ...
from collections import defaultdict s=input().strip() t=input().strip() def gg(cc, c, l, d): if d[c][-1] <= cc: return d[c][1], l+1 ll = d[c] mx, mn = len(ll)-1, 0 x = (mx + mn)//2 while True: # print(x,cc,mx,mn,ll) if ll[x] <= cc and cc < ll[x+1]: retu...
p02937
from collections import defaultdict as dd N, M = list(map(int, input().split())) c = list(map(int, input().split())) c.sort() m = dd(int) d = dd(int) for n in c: d[n] += 1 m[n % M] += 1 res = 0 for i in range(M): temp = min(m[i], m[(M - i) % M]) if i == (M - i) % M: temp = m[i] // 2 m[i] -= ...
import sys input = sys.stdin.readline N, M = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() m = [0] * M d = [0] * (max(a) + 1) for x in a: d[x] += 1 m[x % M] += 1 res = 0 for i in range(M): t = min(m[i], m[(M - i) % M]) if i == (M - i) % M: t = m[i] // 2 m[i]...
p03912
n,m=list(map(int,input().split())) a=list(map(int,input().split())) from collections import Counter mo=[[]for _ in range(m)] for i in a:mo[i%m].append(i) ans=len(mo[0])//2 if m%2==0:ans+=len(mo[m//2])//2 for i in range(1,0--m//2): if len(mo[i])>len(mo[m-i]):d=Counter(mo[i]) elif len(mo[i])==len(mo[m-i]): ...
n,m=list(map(int,input().split())) x=list(map(int,input().split())) a=[[]for _ in range(m)] for i in x:a[i%m].append(i) b=[] from collections import Counter for i in range(m): d=Counter(a[i]) ans=0 for j in d:ans+=2*(d[j]//2) b.append([len(a[i]),ans]) ans=0 if m%2==0:ans+=len(a[m//2])//2 ans+=len(a...
p03912
from collections import defaultdict, Counter N, M = list(map(int, input().split())) X = list(map(int, input().split())) d = defaultdict(int) #mod Mで見たときの個数 for x in X: d[x % M] += 1 ans = 0 #Mの倍数//2 組の和はすべてMの倍数となる # ans += d[0] // 2 lst = [0] * M for m in range(1, M): ans += min(d[m], d[M - ...
#違う数との組-->同じ数での組の順に考える from collections import defaultdict, Counter N, M = list(map(int, input().split())) X = list(map(int, input().split())) d = defaultdict(int) #mod Mで見たときの個数 for x in X: d[x % M] += 1 ans = 0 #Mの倍数//2 組の和はすべてMの倍数となる lst = [0] * M for m in range(1, M): ans += min(d[m], ...
p03912
from collections import Counter N, M = list(map(int, input().split())) X = list(map(int, input().split())) modGrp = [[] for _ in range(M)] for x in X: modGrp[x % M].append(x) ans = len(modGrp[0]) // 2 modGrp[0] = [] if M % 2 == 0: ans += len(modGrp[M // 2]) // 2 modGrp[M // 2] = [] fo...
from collections import Counter, defaultdict N, M = list(map(int, input().split())) X = list(map(int, input().split())) cntMod = defaultdict(int) cntDup = defaultdict(int) for x, c in list(Counter(X).items()): cntMod[x % M] += c cntDup[x % M] += c // 2 ans = 0 for m in range(M): if m > M /...
p03912
from collections import Counter N, M = list(map(int, input().split())) cntX = Counter(list(map(int, input().split()))) cntMod = Counter() cntDup = Counter() for x, c in list(cntX.items()): cntMod[x % M] += c cntDup[x % M] += c // 2 ans = 0 for n in range(M // 2 + 1): m = (M - n) % M if m ...
from collections import Counter N, M = list(map(int, input().split())) X = list(map(int, input().split())) dupCnt = Counter() modCnt = Counter() for x, c in list(Counter(X).items()): x %= M dupCnt[x] += c // 2 modCnt[x] += c ans = 0 for i in range(M): j = M - i if i > j: ...
p03912
MAX_X = 10 ** 5 + 100 def main(): N, M = [int(i) for i in input().split()] X = [0] * (MAX_X + 1) for i in map(int, input().split()): X[i] += 1 Y = [sum(X[i::M]) for i in range(min(M, MAX_X))] # Mの倍数 ans = Y[0] // 2 Y[0] = 0 # M%2==0のM/2 if M % 2 == 0: ...
MAX_X = 10 ** 5 + 100 def main(): N, M = [int(i) for i in input().split()] X = [0] * (MAX_X + 1) for i in map(int, input().split()): X[i] += 1 Y = [sum(X[i::M]) for i in range(min(M, MAX_X))] # Mの倍数 ans = Y[0] // 2 Y[0] = 0 # M%2==0のM/2 try: if M % 2...
p03912
from collections import Counter n,m=list(map(int,input().split())) x=[int(i) for i in input().split()] v=[[] for i in range(m)] for i in x:v[i%m].append(i) a=0 for i in range(1,m//2+1*(m%2==1)): d=len(v[i])-len(v[m-i]) if d<0: d=-d v[i],v[m-i]=v[m-i],v[i] c=sorted(list(Counter(v[i]).items()),ke...
from collections import Counter n,m=list(map(int,input().split())) x=[int(i) for i in input().split()] v=[[] for i in range(m)] for i in x:v[i%m].append(i) a=0 for i in range(1,m//2+1*(m%2==1)): x,y=v[i],v[m-i] d=len(x)-len(y) if d<0: d=-d x,y=y,x c=sorted(list(Counter(x).items()),key=lambda...
p03912
from collections import defaultdict, Counter N, M = list(map(int, input().split())) #X = list(map(int, input().split())) C = Counter(list(map(int, input().split()))) D = defaultdict(int) E = defaultdict(int) for k, v in list(C.items()): D[k%M] += v E[k%M] += v//2 ans = D[0] // 2 for i in range(1, ...
from collections import defaultdict, Counter N, M = list(map(int, input().split())) C = Counter(list(map(int, input().split()))) #D = defaultdict(int) #E = defaultdict(int) D = [0]*M E = [0]*M for k, v in list(C.items()): D[k%M] += v E[k%M] += v//2 ans = D[0] // 2 for i in range(1, M): j = M...
p03912
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) from collections import deque def getN(): return int(eval(input())) def getList(): return list(map(int, input().split())) import math n, m = getList() nums = getList() n_mods = [0 for i in range(m)] pair_mods = [0 for i in range(...
import sys input = sys.stdin.buffer.readline def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getlist(): return list(map(int, input().split())) import math import heapq from collections import defaultdict, Counter, deque MOD = 10**9 + 7 INF = 10**15 ...
p03912
# 大混乱したので乱択 from random import randint def main(): import sys sys.setrecursionlimit(500000) N = int(eval(input())) if N==2: print((1)) exit() E = [[] for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) E[a].append(b) ...
# 大混乱したので乱択 # これ嘘じゃないのか??? def main(): import sys sys.setrecursionlimit(500000) N = int(eval(input())) if N==2: print((1)) exit() E = [[] for _ in range(N)] for _ in range(N-1): a, b = list(map(int, input().split())) E[a].append(b) E[b].appe...
p03441
from itertools import accumulate def solve(): MOD = 10 ** 9 + 7 def max2(x, y): return x if x >= y else y N, K = list(map(int, input().split())) As = list(map(int, input().split())) dp = [0] * (K+1) dp[0] = 1 for A in As: accDP = [0] + list(accumulate(dp)) a...
from itertools import accumulate def solve(): MOD = 10**9 + 7 N, K = list(map(int, input().split())) As = list(map(int, input().split())) dp = [0] * (K+1) dp[0] = 1 for A in As: dp = list(accumulate(dp)) for j, d in enumerate(dp[:K-A], start=A+1): dp[j...
p03172
N, K = list(map(int, input().split())) a = tuple(map(int, input().split())) def main(): l = [[0] * (K+1) for _ in range(N)] for i in range(N): t = 0 for j in range(K+1): if i == 0: if a[i] >= j: l[i][j] = 1 elif j == 0: ...
N, K = list(map(int, input().split())) a = tuple(map(int, input().split())) def main(): l = [0] * (K+1) for i in range(N): t = 0 lt = l l = [0] * (K + 1) for j in range(K+1): if i == 0: if a[i] >= j: l[j] = 1 ...
p03172
N, K = list(map(int, input().split())) a = tuple(map(int, input().split())) def main(): l = [1 if a[0] >= j else 0 for j in range(K+1)] lt= [1 if a[0] >= j else 0 for j in range(K+1)] s = a[0] for i in range(1,N): lt, l = l, lt s += a[i] l[0] = 1 t = 1 ...
N, K = list(map(int, input().split())) a = tuple(map(int, input().split())) def main(): l = [1 if a[0] >= j else 0 for j in range(K+1)] lt= [0] * (K+1) s = a[0] for i in range(1,N): lt, l = l, lt s += a[i] l[0] = 1 t = 1 for j in range(1, a[i]+1): ...
p03172
# coding: utf-8 from itertools import accumulate as accum import sys input = sys.stdin.readline def f(n, k, ai): mod = int(1e9 + 7) dp = [0] * (k + 1) dp[0] = 1 for a in ai: # csum: Cumulative sum # dp[j] = dp[0] + dp[1] + ... + dp[j] dp = list(accum(dp, lambda x, ...
# coding: utf-8 from itertools import accumulate as accum import sys input = sys.stdin.readline def f(n, k, ai): mod = int(1e9 + 7) dp = [0] * (k + 1) dp[0] = 1 for a in ai: # csum: Cumulative sum # dp[j] = dp[0] + dp[1] + ... + dp[j] # dp = list(accum(dp, lambda x...
p03172
N, K = list(map(int, input().split())) *a, = list(map(int, input().split())) MOD = 10**9+7 dp = [[0]*(K+1) for _ in range(N+1)] for i in range(N+1): dp[i][0] = 1 sums = [0]*(K+2) for i in range(1, N+1): sums[0] = 0 for j in range(1, K+2): sums[j] = (dp[i-1][j-1]+sums[j-1]) % MOD ...
N, K = list(map(int, input().split())) *a, = list(map(int, input().split())) MOD = 10**9+7 dp = [0]*(K+1) sums = [0]*(K+2) dp[0] = 1 for i in range(1, N+1): sums[0] = 0 for j in range(1, K+2): sums[j] = (dp[j-1]+sums[j-1]) % MOD for j in range(1, K+1): sj = max([0, j-a[i-1...
p03172
def f(k, a_s): md = 10 ** 9 + 7 dp = [[0] * (k + 1) for _ in range(n)] dp[0][0] = 1 for i, a in enumerate(a_s[:-1]): dp[i + 1][0] = s = dp[i][0]% md for j in range(1, a + 1): dp[i + 1][j] = s = (s + dp[i][j])% md for j in range(a + 1, k + 1): dp[i...
def f(k, a_s): md = 10 ** 9 + 7 dp = [[0] * (k + 1) for _ in range(n)] dp[0][0] = 1 for i, a in enumerate(a_s[:-1]): dpi1 = dp[i + 1] dpi = dp[i] dpi1[0] = s = dp[i][0] % md for j in range(1, a + 1): dpi1[j] = s = (s + dpi[j]) % md for j in r...
p03172
def f(n, k, a_s): md = 10 ** 9 + 7 dp = [[0] * (k + 1) for _ in range(n)] dp[0][0] = 1 dpi = dp[0] for i, a in enumerate(a_s[:-1]): dpi1 = dp[i + 1] dpi1[0] = dp[i][0] % md for j in range(1, a + 1): dpi1[j] = (dpi1[j - 1] + dpi[j]) % md for j in ...
def f(k, a_s): md = 10 ** 9 + 7 dp = [[0] * (k + 1) for _ in range(n)] dp[0][0] = 1 dpi = dp[0] for dpi1, a in zip(dp[1:],a_s[:-1]): dpi1[0] = s = dpi[0] % md for j in range(1, a + 1): dpi1[j] = s = (s + dpi[j]) % md for j in range(a + 1, k + 1): ...
p03172
class BIT(object): def __init__(self, N, init=0, mod=1): self.N = N self.bit = [init for _ in range(N)] self.mod = mod def add(self, k, w): x = k while x < self.N: self.bit[x] += w % self.mod self.bit[x] %= self.mod x |= x +...
MOD = 10 ** 9 + 7 n, k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [0 for _ in range(k + 1)] dp[0] = 1 b = [1 for _ in range(k + 2)] b[0] = 0 for ai in a: for i in range(k, -1, -1): dp[i] += (b[i] - b[i - min(ai, i)]) % MOD dp[i] %= MOD for i in rang...
p03172
import sys input=sys.stdin.readline n,k=list(map(int,input().split())) a=list(map(int,input().split())) def main(): dp=[[0]*(k+1) for _ in range(n+1)] mod=1000000007 #i人目までに0個配る方法は1通り #for i in range(n+1): # dp[i][0]=1 for i in range(0,n+1): for j in range(0,k+1): if i==0 and j==0...
import sys from itertools import accumulate def main(): input=sys.stdin.readline n,k=list(map(int,input().split())) A=list(map(int,input().split())) mod=10**9+7 dp=[0]*(k+1) dp[0]=1 for a in A: dp=list(accumulate(dp)) #print("accumulated",dp) for j,d in enumerate(dp[:k-a],start=a...
p03172
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [[0]*(k+1) for _ in range(n+1)] cum = [1]*(k+2) M = 10**9+7 for i in range(n+1): ...
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,k = list(map(int, input().split())) a = list(map(int, input().split())) dp = [0]*(k+1) cum = [1]*(k+2) M = 10**9+7 dp[0] = 1 cum[0] = 0 for i in range(1,n+1): ...
p03172
# -*- coding: utf-8 -*- """ 参考:https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035    https://www.hamayanhamayan.com/entry/2019/01/10/235150    http://anctgcc.hatenablog.com/entry/2014/12/03/194140    https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree ・数え上げDP ・累積和の代わりにB...
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect i...
p03172
# -*- coding: utf-8 -*- import sys, re from collections import deque, defaultdict, Counter from math import sqrt, hypot, factorial, pi, sin, cos, radians if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd from heapq import heappop, heappush, heapify, heappushpop from bisect i...
# -*- coding: utf-8 -*- import sys from functools import reduce def input(): return sys.stdin.readline().strip() def ceil(a, b=1): return int(-(-a // b)) def round(x): return int((x*2+1) // 2) def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD def lcm(x, y): return (x * y) // gcd(x, y) def lcm_list(n...
p03172
import sys def solve(): input = sys.stdin.readline N, K = list(map(int, input().split())) A = [int(a) for a in input().split()] mod = 7 + 10 ** 9 DP = [[0 for j in range(K + 1)] for i in range(N)] for i in range(A[0] + 1): DP[0][i] = 1 for i in range(1, N): cum = [0] * (K ...
import sys def solve(): input = sys.stdin.readline N, K = list(map(int, input().split())) A = [int(a) for a in input().split()] mod = 7 + 10 ** 9 DP = [[0 for j in range(K + 1)] for i in range(N)] for i in range(A[0] + 1): DP[0][i] = 1 cum = [0] * (K + 2) for i in range(1, N):...
p03172
# -*- coding: utf-8 -*- import sys N,K=list(map(int, sys.stdin.readline().split())) A=list(map(int, sys.stdin.readline().split())) dp=[ [] for i in range(N+1) ] dp[0]=[1] mod=10**9+7 for n in range(N): W=[0] #WA:累積和 L=dp[n] l=len(L) a=A[n] for j,x in enumerate(L): if j==0: W.append(x) ...
# -*- coding: utf-8 -*- import sys N,K=list(map(int, sys.stdin.readline().split())) A=list(map(int, sys.stdin.readline().split())) mod=10**9+7 T=[1] for n in range(N): W=[0] #WA:累積和 L=T l=len(L) a=A[n] for j,x in enumerate(L): if j==0: W.append(x) else: W.append( W[-1]+x ) T=[] #Temp...
p03172
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in s...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in s...
p03172
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 dp = [[0] * (k + 1) for _ in range(n + 1)] dp[0][0] = 1 for i in range(n): dp[i + 1][0] = dp[i][0] for j in range(1, k+1): dp[i + 1][j] = (dp[i + 1][j - 1] + dp[i][j]) % mod for j in range(k, a[i]...
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 f = [0] * (k + 1) f[0] = 1 for i in range(n): for j in range(1, k+1): f[j] = (f[j] + f[j - 1]) % mod # 1/(1-x):累積和 for j in range(k, a[i], -1): # 1-x^(a[i]+1) a[i]+1次したの項を引く f[j] = (f[j] - f[j...
p03172
def main(): e,M=enumerate,10**9+7 n,k,*a=list(map(int,open(0).read().split())) dp=[[0]*(k+1)for _ in range(n+1)] dp[0][0]=1 for b,d,a in zip(dp,dp[1:],a): a+=1 t=0 for j,v in e(b[:a]): t+=v t%=M d[j]=t for j,(w,v)in e(list(zip(b,b[a:])),a): t+=v-w t%...
def main(): M=10**9+7 n,k,*a=list(map(int,open(0).read().split())) dp=[[1]+[0]*k] for b,i in zip(dp,a): t,d=0,[] for v in b[:i+1]: t+=v t%=M d+=t, for w,v in zip(b,b[i+1:]): t+=v-w t%=M d+=t, dp+=d, print(t) main()
p03172
from sys import stdin from itertools import accumulate input = stdin.readline MOD = 10**9+7 N, K = list(map(int,input().split())) a = list(map(int,input().split())) p = list(accumulate(a)) dp = [0] * (K+1) dp[0] = 1 prefix = [0]+[1]*(K+1) for i in range(N): new_dp = [0]*(K+1) for j in range(mi...
from sys import stdin from itertools import accumulate input = stdin.readline MOD = 10**9+7 N, K = list(map(int,input().split())) *a, = list(map(int,input().split())) p = list(accumulate(a)) dp = [0] * (K+1) dp[0] = 1 prefix = [0]+[1]*(K+1) for i in range(N): new_dp = [0]*(K+1) for j in range(...
p03172
def main(): N, K = list(map(int, input().split())) a = list(map(int, input().split())) dp = [[0]*(K+1) for i in range(N+1)] import collections mod = 10**9 + 7 # dp[i][j] i人目まで配って、残りがj個の方法の数 s = [1]*(K+2) s[-1] = 0 tmp = 0 for i in range(1, N+1): next = [0]*(K...
def main(): N, K = list(map(int, input().split())) a = list(map(int, input().split())) dp = [[0]*(K+1) for i in range(N+1)] import collections dp[0][K] = 1 mod = 10**9 + 7 # dp[i][j] i人目まで配って、残りがj個の方法の数 s = [0]*(K+2) for i in range(1, N+1): tmp = 0 for j ...
p03172
def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) u = [1] + [0] * K v = [1] + [0] * K s = 0 for i in A: u, v = v, u s += i t = 0 for k in range(i): t += u[k] v[k] = t for k in range(...
def main(): N, K = list(map(int, input().split())) A = list(map(int, input().split())) u = [1] + [0] * K v = [1] + [0] * K s = 1 for a in A: u, v = v, u s += a c = 0 for i, t in enumerate(u[:a + 1]): c += t v[i] = c for...
p03172
import sys readline = sys.stdin.readline N,K = list(map(int, readline().split())) A = list(map(int,readline().split())) DIV = 10 ** 9 + 7 # dp[i][j] : i人目までにj個配るときの場合の数 # 数式変形で以下 # dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - Ai-1 - 1] dp = [[0] * (K + 1) for i in range(N + 1)] for i in range(N...
import sys readline = sys.stdin.readline N,K = list(map(int, readline().split())) A = list(map(int,readline().split())) DIV = 10 ** 9 + 7 # dp[i][j] : i人目までにj個配るときの場合の数 # dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + ... + dp[i - 1][j - A[i - 1]] # j に j - 1を代入 # dp[i][j - 1] = dp[i - 1][j - 1] + dp[i - 1][j...
p03172
import sys input = sys.stdin.readline n,k=list(map(int, input().split())) a=list(map(int, input().split())) mod=10**9+7 dp=[[0]*(k+1) for i in range(n+1)] for i in range(n+1): dp[i][0]=1 for i in range(1,n+1): for j in range(1,k+1): if j-1-a[i-1]>=0: dp[i][j]=dp[i][j-1]...
import sys input = sys.stdin.readline n,k=list(map(int, input().split())) a=list(map(int, input().split())) mod=10**9+7 dp=[[0]*(k+1) for i in range(n+1)] for i in range(n+1): dp[i][0]=1 for i in range(1,n+1): for j in range(1,k+1): if j-1-a[i-1]>=0: dp[i][j]=(dp[i][j-1...
p03172
import collections def solve(): A, B = list(map(int, input().split())) print((A*B-(A+B-1))) if __name__ == "__main__": solve()
A, B = list(map(int, input().split())) print(((A-1)*(B-1)))
p03280
a,b=list(map(int, input().split())) print(((a-1)*(b-1)))
a,b=list(map(int,input().split())) print((~-a*~-b))
p03280
import subprocess A,B = list(map(int, subprocess.check_output("dd").split())) print((A-1)*(B-1))
import sys A,B = list(map(int, sys.stdin.read().split())) print((A-1)*(B-1))
p03280
a,b=list(map(int,input().split())) print((~-a*~-b))
A, B = list(map(int, input().split())) print((A*B-(A+B-1)))
p03280
import sys # 関数 solve は,もちろん,問題に応じて書き換える def solve(a, b): s=int(a)-1 r=int(b)-1 return s*r # ここから下は,入力・出力形式が同じであれば,変えなくて良い. def readQuestion(): line = sys.stdin.readline().rstrip() [str_a, str_b] = line.split(' ') return (int(str_a), int(str_b)) def main(): a, b = readQuest...
import sys def solve(a, b): # Uncomment the following if you want to check the input. # print('a =', a) # print('b =', b) s=int(a)-1 r=int(b)-1 return s*r def readQuestion(): ws = sys.stdin.readline().strip().split() a = int(ws[0]) b = int(ws[1]) return (a, b) ...
p03280
a,b=list(map(int,input().split())) c=(a*b)-(b+a-1) print(c)
a,b=list(map(int,input().split())) print((a*b-a-b+1))
p03280
eval('print(('+input().replace(' ','-1)*(')+'-1))')
a,b=list(map(int,input().split()));print((~-a*~-b))
p03280
print((eval('~-'+'*~-'.join(input().split()))))
a,b=list(map(int,input().split())) print((~-a*~-b))
p03280
A,B=list(map(int,input().split())) print(((A-1) * (B-1)))
print((eval('('+input().replace(' ','-1)*(')+'-1)')))
p03280
a, b = list(map(int, input().split())) print(((a-1) * (b-1)))
a,b=list(map(int,input().split()));print((a*b-a-b+1))
p03280
a,b=list(map(int,input().split())) print((a*b-a-b+1))
A,B=list(map(int,input().split())) print((A*B-A-B+1))
p03280
a, b = list(map(int, input().split())) print(((a - 1) * (b - 1)))
A, B = list(map(int, input().split())) print(((A - 1) * (B - 1)))
p03280
import sys sys.setrecursionlimit(100000) S = input() T = "" t = ['dream','dreamer','erase','eraser'] def rec(T,S): if len(S) < len(T): return False if S==T: return True elif S[len(T)] == "e": return rec(T+t[2],S) or rec(T+t[3],S) elif S[len(T)] == "d": return...
S = input().split()[0] t = ['dreameraser','dreamerase','dreamer','dream','eraser','erase'] while len(S) > 0: for i in t: if S[-len(i):]==i: S = S[:-len(i)] break elif i == t[-1]: print("NO") exit() print("YES")
p03856
N=int(input()) A=list(map(int,input().split())) B=[] for i in range(N): if(N%2==0): if(i%2==0): B.append(A[i]) else: B.insert(0,A[i]) else: if(i%2==0): B.insert(0,A[i]) else: B.append(A[i]) for i in range(N): ...
N=int(input()) A=list(map(int,input().split())) B=[] C=[] for i in range(N): if(N%2==0): if(i%2==0): B.append(A[i]) else: C.append(A[i]) else: if(i%2==0): C.append(A[i]) else: B.append(A[i]) C.reverse() for i i...
p03675
N = int(eval(input())) A = list(map(int, input().split())) ans = [A[0]] for i in range(1, N): if i % 2 == 0: ans.append(A[i]) else: ans.insert(0, A[i]) if N % 2 == 1: ans = ans[::-1] print((" ".join(list(map(str, ans)))))
N = int(eval(input())) A = list(map(int, input().split())) ans = [] if N % 2 == 0: l1 = A[0::2] l2 = A[1::2] l2 = l2[::-1] ans = l2+l1 else: l1 = A[0::2] l2 = A[1::2] l1 = l1[::-1] ans = l1+l2 print((" ".join(list(map(str, ans)))))
p03675
N = int(eval(input())) A = list(map(int, input().split())) ans = [] if N % 2 == 0: l1 = A[0::2] l2 = A[1::2] l2 = l2[::-1] ans = l2+l1 else: l1 = A[0::2] l2 = A[1::2] l1 = l1[::-1] ans = l1+l2 print((" ".join(list(map(str, ans)))))
N = int(eval(input())) A = list(map(int, input().split())) ans = [] l1 = A[0::2] l2 = A[1::2] if N % 2 == 0: l2 = l2[::-1] ans = l2+l1 else: l1 = l1[::-1] ans = l1+l2 print((" ".join(list(map(str, ans)))))
p03675
N = int(eval(input())) A = list(map(int, input().split())) ans = [] l1 = A[0::2] l2 = A[1::2] if N % 2 == 0: l2 = l2[::-1] ans = l2+l1 else: l1 = l1[::-1] ans = l1+l2 print((" ".join(list(map(str, ans)))))
N = int(eval(input())) A = list(input().split()) ans = [] l1 = A[0::2] l2 = A[1::2] if N % 2 == 0: l2 = l2[::-1] ans = l2+l1 else: l1 = l1[::-1] ans = l1+l2 print((" ".join(ans)))
p03675
N = int(eval(input())) a = list(map(int,input().split())) ans = [a[0]] for i,j in enumerate(a[1:]): if(N%2==0): if(i%2==0): ans.insert(0,j) else: ans.append(j) else: if(i%2==1): ans.insert(0,j) else: ans.append(j) prin...
N = int(eval(input())) a = list(map(int,input().split())) ans = [a[0]] check = N%2==0 for i,j in enumerate(a[1:]): if(check): if(i%2==0): ans.insert(0,j) else: ans.append(j) else: if(i%2==1): ans.insert(0,j) else: an...
p03675
import sys import collections import math n = int(eval(input())) A = [int(x) for x in input().split()] R = [0] * n idx = 0 for i in range(n-1, -1, -2): R[idx] = A[i] idx += 1 for i in range(n % 2, n, +2): R[idx] = A[i] idx += 1 print((" ".join([str(i) for i in R]))) sys.exit(0)...
import sys import collections import math from collections import Counter from collections import deque n = int(eval(input())) A = [int(x) for x in input().split()] Q = deque() f = True if n % 2 == 0: f = not f for a in A: if f: Q.appendleft(a) else: Q.append(a) ...
p03675
n = int(eval(input())) a = list(map(int,input().split())) even = [] odd = [] for i in range(0,n): if i % 2 == 0: odd.append(a[i]) else: even.append(a[i]) res = [] if n % 2 == 0: even = reversed(even) res.extend(even) res.extend(odd) else: odd = reversed(odd) res.extend(odd) res.extend(e...
n = int(eval(input())) a = list(map(int,input().split())) if n == 1: print((a[0])) elif n % 2 == 0: print((" ".join(map(str, a[1::2][::-1] + a[0::2])))) else: print((" ".join(map(str, a[0::2][::-1] + a[1::2]))))
p03675
n = int(eval(input())) *a, = list(map(int, input().split())) b = [] for i in range(n): b.append(a[i]) b.reverse() print((" ".join(map(str, b))))
n = int(eval(input())) *a, = list(map(int, input().split())) b = list(reversed(a[1::2]))+a[0::2] print((" ".join(map(str, b if n%2 == 0 else reversed(b)))))
p03675
N=input() b=[] P=input().split() for i in P: b.append(i) b=b[::-1] print(" ".join(b))
N=int(input()) P=input().split() b=P[-1::-2]+P[N%2::2] print(" ".join(b))
p03675
a = int(input()) ar = list(map(int,input().split(" "))) br = [] if a % 2 == 0: for i in range(len(ar)-1,0,-2): br.append(ar[i]) for i in range(0,len(ar)-1,+2): br.append(ar[i]) else: for i in range(len(ar)-1,-1,-2): br.append(ar[i]) for i in range(1,len(ar)-1,+2): ...
a = int(input()) ar = list(map(int,input().split(" "))) br = [] for i in range(a-1,-1,-2): br.append(ar[i]) if a % 2 == 0: n = 0 else: n = 1 for i in range(n,a-1,2): br.append(ar[i]) for i in range(a-1): print(br[i],end=" ") print(br[a-1])
p03675
n = int(input()) a = input().split() b = [] for i in range(n): if i % 2: b.append(a[i]) else: b.insert(0, a[i]) if n % 2: print(" ".join(b)) else: print(" ".join(b[::-1]))
n = int(input()) a = input().split() b = [] c = [] for i in range(n): if i % 2: b.append(a[i]) else: # b.insert(0, a[i]) c.append(a[i]) b = c[::-1] + b if n % 2: print(" ".join(b)) else: print(" ".join(b[::-1]))
p03675
from itertools import count def get_weed(h): d10 = h[1] - h[0] d21 = h[2] - h[1] d32 = h[3] - h[2] if d10 == d21 == d32: for hi, expect in zip(h, count(h[0], d10)): if hi != expect: return hi d43 = h[4] - h[3] if d21 == d32 == d43: retur...
from itertools import count def get_weed(h): d = [h[i + 1] - h[i] for i in range(3)] if d[0] == d[1] == d[2]: for hi, expect in zip(h, count(h[0], d[0])): if hi != expect: return hi for i in range(4): hh = h[:i] + h[i + 1:] d = [hh[i + 1] - hh[i...
p00253
from collections import defaultdict from heapq import * from array import * def read(): return int(eval(input())) def reads(sep=None): return list(map(int, input().split(sep))) def mst_prim(adj, n): pred = defaultdict(lambda: -1) key = defaultdict(lambda: float('inf')) key[0] = 0 ...
def read(): return int(eval(input())) def reads(sep=None): return list(map(int, input().split(sep))) def main(): w, h = reads() p = sorted([read() for _ in range(w)])[::-1] q = sorted([read() for _ in range(h)])[::-1] pi = w-1 qi = h-1 res = 0 while 0<=pi and 0<=qi: ...
p03972
W, H = list(map(int, input().split())) P = [(int(eval(input())), 0) for i in range(W)] Q = [(int(eval(input())), 1) for i in range(H)] E = sorted(P + Q) used = [W + 1, H + 1] ans = 0 for e, f in E: ans += e * used[1 - f] used[f] -= 1 print(ans)
from itertools import accumulate from bisect import bisect_left W, H = list(map(int, input().split())) W_cost = sorted([int(eval(input())) for i in range(W)]) H_cost = [int(eval(input())) for i in range(H)] # 横は全部辺を張り、縦は各区間1本 W_cost_sum = sum(W_cost) ans = W_cost_sum * (H + 1) + sum(H_cost) W_acc_cost =...
p03972
w, h = list(map(int, input().split())) p = [] q = [] for i in range(w): p.append(int(input())) for i in range(h): q.append(int(input())) wl = w hl = h cost = 0 p.sort() q.sort() p.append(10 ** 8 + 1) q.append(10 ** 8 + 1) while(wl + hl > 0): if p[0] < q[0]: cost += (hl + 1)...
w, h = list(map(int, input().split())) p = [] q = [] for i in range(w): p.append(int(input())) for i in range(h): q.append(int(input())) wl = w hl = h cost = 0 p.sort() q.sort() p.append(10 ** 8 + 1) q.append(10 ** 8 + 1) pc = 0 qc = 0 while(wl + hl - pc - qc> 0): if p[pc] < q[q...
p03972
W,H=list(map(int,input().split())) P=[int(eval(input())) for i in range(W)] Q=[int(eval(input())) for j in range(H)] P.append(float('inf')) Q.append(float('inf')) P.sort(reverse=True) Q.sort(reverse=True) now_W=W+1 now_H=H+1 cost=0 while now_W>1 or now_H>1: if P[-1]<Q[-1]: cost+=P.pop()*now_H ...
import sys input=sys.stdin.readline W,H=list(map(int,input().split())) P=[int(eval(input())) for _ in range(W)]+[float('inf')] Q=[int(eval(input())) for _ in range(H)]+[float('inf')] P.sort(reverse=True) Q.sort(reverse=True) ans=0 W+=1 H+=1 while True: if W==H==1: break elif Q[-1]<P[-1] or ...
p03972
W,H = list(map(int,input().split())) side = [] for i in range(W): side.append({"cost":int(eval(input())),"num":i,"dir":0}) for i in range(H): side.append({"cost":int(eval(input())),"num":i,"dir":1}) side = sorted(side,key = lambda x:x["cost"]) node =[[{"v":j,"men":[j]} for j in range(i*(W+1),(i+1)*(W...
W, H = list(map(int, input().split())) side = [{"cost":int(eval(input())), "di":0}for i in range(W)] + [{"cost":int(eval(input())), "di":1}for i in range(H)] side = sorted(side, key=lambda x:x["cost"]) ans = 0 ty = [H+1,W+1] for s in side: cost, di = s["cost"], s["di"] ans += ty[di] * cost ty[(di+...
p03972
def main(): import sys input = sys.stdin.readline from bisect import bisect_left, bisect_right W, H = list(map(int, input().split())) P = [int(eval(input())) for _ in range(W)] P.sort() P_count = [0] * (W + 2) Q = [int(eval(input())) for _ in range(H)] Q.sort() ...
def main(): import sys input = sys.stdin.readline from bisect import bisect_right W, H = list(map(int, input().split())) P = [int(eval(input())) for _ in range(W)] P.sort() P_count = [0] * (W + 2) Q = [int(eval(input())) for _ in range(H)] Q.sort() ans = 0 fo...
p03972
ss=input().split() w=int(ss[0]) h=int(ss[1]) a=[] b=[] for i in range( w): p=eval(input()) a.append( p) for i in range( h): p=eval(input()) b.append( p) a.sort() b.sort() h1=0 h2=0 ans=0 while ((h1<w) and (h2<h)): if a[h1]<b[h2]: ans+=a[h1]*(h - h2+1) h1+=1 el...
ss=input().split() w=int(ss[0]) h=int(ss[1]) a=[] b=[] for i in range(w): p=eval(input()) a.append(p) for i in range(h): p=eval(input()) b.append(p) a.sort() b.sort() h1=0 h2=0 res=0 while h1 < w and h2 < h: if a[h1]<b[h2]: res += a[h1] * (h - h2 + 1) h1 ...
p03972
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
p03972
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
p03972
import itertools import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 class UnionFind: def __init__(self, size=None, nodes=None): """ size か nodes どっちか指定。 n...
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 # あああああああああああくそHとWぎゃくだ W,H = list(map(int, sys.stdin.readline().split())) P = [int(sys.stdin.readline()) for _ in range(W)] Q = [int(sy...
p03972
W,H = list(map(int,input().split())) PQ = [(int(eval(input())),0,i) for i in range(W)] + [(int(eval(input())),1,i) for i in range(H)] PQ.sort() import sys sys.setrecursionlimit(10**7) class UnionFind: def __init__(self): self.Parent = {} def add(self,k): self.Parent[k] = k def ...
W,H = list(map(int,input().split())) PQ = [(int(eval(input())),0) for _ in [0]*W] + [(int(eval(input())),1) for _ in [0]*H] PQ.sort() r = H+1 c = W+1 ans = 0 for d,pq in PQ: if pq==0: ans += d*r c -=1 else: ans += d*c r -=1 print(ans)
p03972
t = input() W, H = list(map(int, t.split(' '))) p, q = [], [] for i in range(W): p.append(int(input())) for j in range(H): q.append(int(input())) node = [ (i, j, min(p[i-1] if i > 0 else 100000005, q[j-1] if j > 0 else 100000005)) for i in range(W+1) for j in range(H+1) ] cost = 0 for i in rang...
t = input() W, H = list(map(int, t.split(' '))) p, q = [], [] for i in range(W): p.append(int(input())) for j in range(H): q.append(int(input())) cost = 0 for i in range(W+1): for j in range(H+1): if i == 0 and j == 0: continue cost += min(p[i-1] if i > 0 else 100000005, q[j-1] ...
p03972
t,*p=open(0) w,h=list(map(int,t.split())) c=0 for v,f in sorted((t,i<w)for i,t in enumerate(map(int,p))): c-=~h*v*f or~w*v w-=f h-=1^f print(c)
t,*p=open(0) w,h=list(map(int,t.split())) c=0 for v,f in sorted((int(t),i<w)for i,t in enumerate(p)): c-=~h*v*f or~w*v w-=f h-=1^f print(c)
p03972
W, H = list(map(int, input().split())) p = sorted([(i, int(input())) for i in range(W)], key=lambda x:-x[1]) q = sorted([(i, int(input())) for i in range(H)], key=lambda x:-x[1]) class UnionFind(object): def __init__(self, n): self.uf = [-1 for _ in range(n)] def union(self, x, y): x ...
W, H = list(map(int, input().split())) p = sorted([(i, int(input())) for i in range(W)], key=lambda x:-x[1]) q = sorted([(i, int(input())) for i in range(H)], key=lambda x:-x[1]) ans = 0 pe, qe, ae = 0, 0, (W+1)*(H+1)-1 while len(p)> 0 or len(q) > 0: if len(q) == 0 or (len(p) > 0 and p[-1][1] <= q[-1][1]): ...
p03972
n,q=list(map(int,input().split())) exist=set([1]) cup=list(range(n+2)) now=1 exist.add(cup[now-1]) exist.add(cup[now+1]) for i in range(q): a,b=list(map(int,input().split())) if now==a:now=b elif now==b:now=a tmp=cup[a] cup[a]=cup[b] cup[b]=tmp exist.add(cup[now-1]) exist.a...
n,q=list(map(int,input().split())) exist=[False]*(n+2) exist[1]=True cup=list(range(n+2)) now=1 exist[cup[now-1]]=True exist[cup[now+1]]=True for i in range(q): a,b=list(map(int,input().split())) if now==a:now=b elif now==b:now=a tmp=cup[a] cup[a]=cup[b] cup[b]=tmp exist[cup[no...
p03894
j=lambda:list(map(int,input().split())) n,q=j() c=[1,-1,1]+[0]*(n-2)+[1] for p in[-1]*q:a,b=j();c[a],c[b]=c[b],c[a];i=c.index(p);c[i-1]=c[i+1]=1 print(sum(c))
j=lambda:list(map(int,input().split())) n,q=j() u=1 c=[1]*3+[0]*(n-2)+[1] for p in[-1]*q:a,b=d=j();u+=u in d and a+b-2*u;c[a],c[b]=c[b],c[a];c[u-1]=c[u+1]=1 print(sum(c)-2)
p03894
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) while True: S_ = input() if S_ == '.': break ans = 0 for p, q, r in it.product([0, 1, 2], repeat = 3): S = S_ S = S.replace("P", str(p)).replac...
#!/usr/bin/env python from collections import deque import itertools as it import sys sys.setrecursionlimit(1000000) while True: S_ = input() if S_ == '.': break ans = 0 for p, q, r in it.product([0, 1, 2], repeat = 3): S = S_ S = S.replace("P", str(p)).replac...
p00736
import sys import itertools input = sys.stdin.readline sys.setrecursionlimit(100000) mod = 10 ** 9 + 7 def read_values(): return list(map(int, input().split())) def read_index(): return [int(x) - 1 for x in input().split()] def read_list(): return list(read_values()) def read_lists(N): return [read_list() for...
import sys import itertools input = sys.stdin.readline sys.setrecursionlimit(100000) mod = 10 ** 9 + 7 def read_values(): return list(map(int, input().split())) def read_index(): return [int(x) - 1 for x in input().split()] def read_list(): return list(read_values()) def read_lists(N): return [read_list() for...
p03034
N = int(eval(input())) *S, = list(map(int, input().split())) ans = 0 for a in range(1, N): d = 1 while d*d <= N-1-a: if (N-1-a) % d == 0: if a > d and (a % d > 0 or N-1-a < a): k = (N-1-a) // d s = 0 for i in range(k): ...
N = int(eval(input())) *S, = list(map(int, input().split())) ans = 0 for d in range(1, N): r = k = 0 while k*d <= N-1: a = N-1-k*d if a <= d or (a <= k*d and a % d == 0): break r += S[N-1-k*d] + S[k*d] k += 1 ans = max(ans, r) print(ans)
p03034
import sys sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().spl...
import sys sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().spl...
p03034
N = int(eval(input())) s = list(map(int, input().split())) ans = 0 for C in range(1,N): t = 0 for x in range(C, N-1-C if (N-1)%C != 0 else N//2, C): t += s[x] + s[-x-1] ans = max(ans, t) print(ans)
n,*s=list(map(int,open(0).read().split()));a=0 for i in range(1,n): t=0 for j in range(0,[n//2,n+~i][(n-1)%i>0],i):t+=s[j]+s[~j];a=max(a,t) print(a)
p03034
N = int(eval(input())) s = [int(i) for i in input().split()] ret = 0 for i in range(2, N - 1) : for j in range(1, i) : if (i % (i - j) == 0 and 2 * i < N) or (N - 1 - i) % (i - j) != 0 : continue ret = max(ret, sum(s[i::i-j]) + sum(s[i-j:-j-1:i-j])) print((max(ret, ...
N = int(eval(input())) s = [int(i) for i in input().split()] ret = 0 for c in range(1, N) : k = 1 tmp = 0 flag = (N - 1) % c == 0 while c * k < N - 1 : l = c * k r = N - 1 - l if (flag and r <= l) or r <= c: break tmp += s[l] + s[r] ...
p03034
N = int(eval(input())) slist = list(map(int, input().split())) ans = 0 for C in range(1,N-1,1): flg = [False for i in range(N)] score = 0 for k in range((N-1)//C): if (k-1)*C == N-1-k*C: #一つ前に選んだところ break if 2*k*C == N-1: #今から選ぶ二つが同じところ break score ...
N = int(eval(input())) slist = list(map(int, input().split())) ans = 0 for C in range(1,N-1,1): score = 0 for k in range((N-1)//C): if (k-1)*C == N-1-k*C: #一つ前に選んだところ break if 2*k*C == N-1: #今から選ぶ二つが同じところ break score += slist[k*C]+slist[N-1-k*C] ...
p03034
n = int(eval(input())) s = list(map(int, input().split())) ans = s[n-1] for c in range(1, n-1): dp = s[n-1] for k in range(n-1): if (k+1) * c >= n-1: break else: dp += s[n - 1 - k * c] + s[k * c] if dp > ans: if k <= 1: ...
n = int(eval(input())) s = list(map(int, input().split())) ans = 0 for d in range(1, n): temp = 0 L = 0 R = n-1 if (n-1) % d == 0: while L < R: temp += s[L] + s[R] ans = max(ans, temp) L += d R -= d else: while L + d <...
p03034
N, = list(map(int, input().split())) xs = list(map(int, input().split())) r = 0 for a in range(1, N-1): for b in range(1, N-2): if a <= b: continue if (N-1-a)%(a-b): continue n = (N-1-a)//(a-b) if a%(a-b) == 0: if a <= (a-b)*n: ...
N, = list(map(int, input().split())) xs = list(map(int, input().split())) r = 0 for k in range(1, N): a = (N-1) % k b = a - k n = (N-1-a)//k if a <= k: a += k if a <= k: a += k for _ in range((N-1-a)//k): b = a - k n = (N-1-a)//k if a <= b:...
p03034
N, = list(map(int, input().split())) xs = list(map(int, input().split())) r = 0 for k in range(1, N): a = (N-1) % k b = a - k n = (N-1-a)//k if a <= k: a += k if a <= k: a += k for _ in range((N-1-a)//k): b = a - k n = (N-1-a)//k if a <= b:...
N, = list(map(int, input().split())) xs = list(map(int, input().split())) r = 0 for k in range(1, N): a = (N-1) % k for _ in range(1+(N-1-a)//k): b = a - k n = (N-1-a)//k if a <= b or a <= k: a += k continue if a%(a-b) == 0: if a <=...
p03034
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() bi = bisect.bisect_right result = 0 for i in range(n): a_bi_in_b = bi(b, a[i]) for j in range(a_bi_in_b, n): ...
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() result = 0 for i in range(n): b_bisect_in_a = bisect.bisect_left(a, b[i]) b_bisect_in_c = bisect.bisect_right(c, b[i]) ...
p03557
import bisect def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # print(A,B,C) A.sort() B.sort() C.sort() def f(b): """ bより大きい数がいくつあるか """ p = b...
import bisect def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # print(A,B,C) A.sort() B.sort() C.sort() def get_a(b): p = bisect.bisect_left(A, b) retu...
p03557
inf=10**9+1 n=int(eval(input())) array_a=sorted([a for a in map(int, input().split())])+[inf] array_b=sorted([a for a in map(int, input().split())])+[inf] array_c=sorted([a for a in map(int, input().split())]) nums_b=[0 for _ in range(n)] cur=0 for (idx,b) in enumerate(array_b[:-1]): while(array_a[cur]<...
inf=10**9+1 n=int(eval(input())) array_a=sorted([a for a in map(int, input().split())])+[inf] array_b=sorted([a for a in map(int, input().split())])+[inf] array_c=sorted([a for a in map(int, input().split())]) nums_b=[0 for _ in range(n)] cur=0 for (idx,b) in enumerate(array_b[:-1]): while(array_a[cur]<...
p03557
import bisect n = int(eval(input())) list_A = list(map(int, input().split())) list_B = list(map(int, input().split())) list_C = list(map(int, input().split())) list_A.sort() list_B.sort() list_C.sort() ans = 0 list_U = [] list_D = [] for i in range(n): b = list_B[i] index = bisect.bisect_left(lis...
import bisect n = int(eval(input())) list_A = list(map(int, input().split())) list_B = list(map(int, input().split())) list_C = list(map(int, input().split())) list_A.sort() list_B.sort() list_C.sort() ans = 0 for i in range(n): b = list_B[i] left = bisect.bisect_left(list_A, b) right = n - bi...
p03557
# coding: utf-8 # Your code here! N=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort() B.sort() C.sort() A.reverse() B.reverse() C.reverse() ue=0 naka=0 sita=0 count=0 for i in range(N): ue=A[i] for j in range(N): ...
N=int(eval(input())) S=list(map(int,input().split())) T=list(map(int,input().split())) U=list(map(int,input().split())) S.sort() T.sort() U.sort() #print(S) #print(T) #print(U) count=0 def is_ok(index,key): if key>S[index]: return True else: return False def meguru_bisect...
p03557
def main(): import bisect N = int(eval(input())) upper = list(map(int, input().split())) middle = list(map(int, input().split())) lower = list(map(int, input().split())) upper.sort() middle.sort() lower.sort() cnt = 0 index_mid = 0 index_low = 0 for ...
def main(): import bisect N = int(eval(input())) upper = list(map(int, input().split())) middle = list(map(int, input().split())) lower = list(map(int, input().split())) upper.sort() middle.sort() lower.sort() cnt = 0 for i in range(N): mid = middle[i] ...
p03557
import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ct = 0 for i in C: b_max = bisect.bisect_left(B, i) for j in B[: b_max]: ct += bisect.bisect_left(A, j) print(ct)
import bisect n = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ct = 0 for j in B: a_max = bisect.bisect_left(A, j) c_min = bisect.bisect_right(C, j) ct += a_max * (n - c_min) print(ct)
p03557
import sys def fastio(): from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() IN...
inp=lambda:list(map(int,input().split())) import bisect as bi n=int(eval(input())) a=inp() b=inp() c=inp() a.sort() b.sort() c.sort() ans=0 for i in range(n): x=bi.bisect_left(a,b[i]) y=n-bi.bisect_right(c,b[i]) ans+=x*y print(ans)
p03557
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() count=0 for i in a: for j in b: for k in c: if i<j<k: count=count+1 print(count)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() A = 0 for x in b: i = bisect.bisect_left(a, x) j = bisect.bisect_right(c, x) if i > 0 and j != len(c): A += i * (n - j) pr...
p03557
#!/usr/bin/env python3 import sys import bisect def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"): answer = 0 A.sort() B.sort() C.sort() for i in range(N): B_index = bisect.bisect_left(B,A[i]+1) for j in range(B_index,N): C_index = bisect.bise...
#!/usr/bin/env python3 import sys import bisect def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"): A.sort() B.sort() C.sort() answer = 0 for i in range(N): A_index = bisect.bisect_left(A,B[i]) C_index = bisect.bisect_left(C,B[i]+1) answer += (N-C...
p03557
n=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort() ; B.sort() ; C.sort() def isOK(A,mid,target): #条件を満たす領域とそうでない領域の境目! return target<A[mid] #条件を満たす中で最小 #return A[mid]<=target #条件を満たす中で最大 def aa(A,target): ng=-1 ; ...
n=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort() ; B.sort() ; C.sort() import bisect as bi ans=0 for i in B: ans+= bi.bisect_left(A,i) * (n-bi.bisect_right(C,i)) print(ans)
p03557
n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) x = 0 for i in range(n): for j in range(n): for k in range(n): if a[i] < b[j] < c[k]: x += 1 print(x)
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ans = 0 for i in b: aa = bisect.bisect_left(a, i) cc = n-bisect.bisect_right(c, i) ans += aa*cc print(ans)
p03557