buggy stringlengths 15 618k | fixed stringlengths 22 618k | text stringlengths 70 1.24M |
|---|---|---|
N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]
shi = {}
for i in range(M):
p, y = map(int, input().split())
dic[p-1].insert(bisect_right(dic[p-1], y), y)
shi[i] = (p, y)
for j in range(M):
p, y = shi[j]
print('{:06}{:06}'.format(p, bisect_right(dic[p-... | N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]
shi = {}
for i in range(M):
p, y = map(int, input().split())
dic[p-1].append(y)
shi[i] = (p, y)
for i in range(N):
dic[i].sort()
for j in range(M):
p, y = shi[j]
print('{:06}{:06}'.format(p, bisect_r... | N, M = map(int, input().split())
from bisect import bisect_right
dic = [[] for i in range(N)]
shi = {}
for i in range(M):
p, y = map(int, input().split())
dic[p-1].insert(bisect_right(dic[p-1], y), y)
shi[i] = (p, y)
for j in range(M):
p, y = shi[j]
print('{:06}{:06}'.format(p, bisect_right(dic[p-... |
n,q =map(int,input().split())
s = input()
ans = []
for _ in range(q):
l,r = map(int,input().split())
tmp_str = s[l-1:r]
ans.append( tmp_str.count('AC') )
for i in ans:
print(i) | n,q =map(int,input().split())
s = input()
d= {}
for k in range(n):
d[k]=0
total = 0
for j in range(n-1):
if s[j]=='A' and s[j+1]=='C':
total+=1
d[j+1]+=total
else:
d[j+1]=total
# print(d)
ans = []
for _ in range(q):
l,r = map(int,input().split())
ans.append(d[r-... | n,q =map(int,input().split())
s = input()
ans = []
for _ in range(q):
l,r = map(int,input().split())
tmp_str = s[l-1:r]
ans.append( tmp_str.count('AC') )
for i in ans:
print(i)
### FIXED CODE ###
n,q =map(int,input().split())
s = input()
d= {}
for k in range(n):
d[k]=0
total = 0
for j in ra... |
n = int(input())
ans = 0
for i in range(n-1):
ans += (i+1)%(i+2)
print(ans)
| n = int(input())
print(((n-1)*n)//2)
| n = int(input())
ans = 0
for i in range(n-1):
ans += (i+1)%(i+2)
print(ans)
### FIXED CODE ###
n = int(input())
print(((n-1)*n)//2)
|
def XOR(A, B):
BA = bin(A)
BA = int(BA[2:])
BB = bin(B)
BB = int(BB[2:])
result = BA + BB
result = str(result)
result = result.replace('2', '0')
result = int(result, 2)
return result
L1 = input()
L2 = input()
L1 = L1.split()
L2 = L2.split()
for i, val in enumerate(L1):
L1[i] = ... | def XOR(A, B):
BA = int(A)
BB = int(B)
result = BA + BB
result = str(result)
result = result.replace('2', '0')
result = int(result, 2)
return result
L1 = input()
L2 = input()
L1 = L1.split()
L2 = L2.split()
for i, val in enumerate(L1):
L1[i] = int(val)
K = L1[1]
K = bin(K)
K = K[2:]
le... | def XOR(A, B):
BA = bin(A)
BA = int(BA[2:])
BB = bin(B)
BB = int(BB[2:])
result = BA + BB
result = str(result)
result = result.replace('2', '0')
result = int(result, 2)
return result
L1 = input()
L2 = input()
L1 = L1.split()
L2 = L2.split()
for i, val in enumerate(L1):
L1[i] = ... |
from functools import lru_cache
@lru_cache(maxsize=10 ** 5)
def factrial(n):
ans = 1
for i in range(1, n+1):
ans *= i
return ans
@lru_cache(maxsize=10 ** 5)
def combinations(n, r):
return factrial(n) // (factrial(n - r) * factrial(r))
def main():
n, k = map(int, input().split())
A ... | from functools import lru_cache
n, k = map(int, input().split())
A = sorted(map(int, input().split()))
mod = 10 ** 9 + 7
# 階乗とその逆元の計算
factrial = [0 for _ in range(n + 1)]
factrial[0] = 1
for i in range(1, n + 1):
factrial[i] = (factrial[i - 1] * i) % mod
inverse_factrial = list()
for f in factrial:
inverse_fact... | from functools import lru_cache
@lru_cache(maxsize=10 ** 5)
def factrial(n):
ans = 1
for i in range(1, n+1):
ans *= i
return ans
@lru_cache(maxsize=10 ** 5)
def combinations(n, r):
return factrial(n) // (factrial(n - r) * factrial(r))
def main():
n, k = map(int, input().split())
A ... |
from heapq import heappush, heappop
def read():
return int(input())
def reads():
return [int(x) for x in input().split()]
q = reads()
s = q[0] + q[1] * 1j
t = q[2] + q[3] * 1j
N = read()
p = []; r = []
for i in range(N):
q = reads()
p.append(q[0] + q[1] * 1j)
r.append(q[2])
# Nがsource, N+1がtarget
E = [[... | from heapq import heappush, heappop
def read():
return int(input())
def reads():
return [int(x) for x in input().split()]
q = reads()
s = q[0] + q[1] * 1j
t = q[2] + q[3] * 1j
N = read()
p = []; r = []
for i in range(N):
q = reads()
p.append(q[0] + q[1] * 1j)
r.append(q[2])
# Nがsource, N+1がtarget
E = [[... | from heapq import heappush, heappop
def read():
return int(input())
def reads():
return [int(x) for x in input().split()]
q = reads()
s = q[0] + q[1] * 1j
t = q[2] + q[3] * 1j
N = read()
p = []; r = []
for i in range(N):
q = reads()
p.append(q[0] + q[1] * 1j)
r.append(q[2])
# Nがsource, N+1がtarget
E = [[... |
def main():
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
ans = 0
for i in range(n):
if a.count(a[i]) >= 4:
ans = a[i]*a[i]
break
elif a.count(a[i]) >=2:
for j in range(i+a.count(a[i]),n):
if a.count(... | n = int(input())
a=list(map(int,input().split()))
a.sort(reverse = True)
ans = 0
b = a.copy()
b = list(set(b))
b.sort(reverse = True)
c = [0]*len(b)
j = 0
c[j] = 1
for i in range(1,n):
if a[i-1] == a[i]:
c[j] +=1
else:
j+=1
c[j] +=1
for i in range(len(b)):
if c[i] >= 4:
... | def main():
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
ans = 0
for i in range(n):
if a.count(a[i]) >= 4:
ans = a[i]*a[i]
break
elif a.count(a[i]) >=2:
for j in range(i+a.count(a[i]),n):
if a.count(... |
from heapq import heappush,heappop
n,q=map(int,input().split())
e=[]
for i in range(n):
s,t,x=map(int,input().split())
e.append([s-x,1,x])
e.append([t-x,-1,x])
for i in range(q):
d=int(input())
e.append([d,2,0])
e.sort()
s=set()
a=[]
for time_,type_,x_ in e:
if type_==1:
s.add(x_)
heappush(a,x_)
e... | import sys
from heapq import heappush,heappop
input=sys.stdin.readline
n,q=map(int,input().split())
e=[]
for i in range(n):
s,t,x=map(int,input().split())
e.append((s-x,1,x))
e.append((t-x,-1,x))
for i in range(q):
d=int(input())
e.append((d,2,0))
e.sort()
s=set()
a=[]
for time_,type_,x_ in e:
if type_==1:
... | from heapq import heappush,heappop
n,q=map(int,input().split())
e=[]
for i in range(n):
s,t,x=map(int,input().split())
e.append([s-x,1,x])
e.append([t-x,-1,x])
for i in range(q):
d=int(input())
e.append([d,2,0])
e.sort()
s=set()
a=[]
for time_,type_,x_ in e:
if type_==1:
s.add(x_)
heappush(a,x_)
e... |
from collections import namedtuple
Line = namedtuple('Line', ['lowest', 'end'])
def main():
N = int(input())
up_lines = []
down_lines = []
for i in range(N):
s = input()
now = 0
lowest = 0
for c in s:
if c == "(":
now += 1
else:
... | from collections import namedtuple
Line = namedtuple('Line', ['lowest', 'end'])
def main():
N = int(input())
up_lines = []
down_lines = []
for i in range(N):
s = input()
now = 0
lowest = 0
for c in s:
if c == "(":
now += 1
else:
... | from collections import namedtuple
Line = namedtuple('Line', ['lowest', 'end'])
def main():
N = int(input())
up_lines = []
down_lines = []
for i in range(N):
s = input()
now = 0
lowest = 0
for c in s:
if c == "(":
now += 1
else:
... |
#!/usr/bin python3
# -*- coding: utf-8 -*-
import numpy as np
def canReach(src, dst):
a = (dst[0] - src[0]) - np.sum(np.abs(src-dst)[1:3])
if a >= 0 and a % 2 == 0:
return True
return False
N = int(input())
dst = np.array([[int(x) for x in input().split(" ")] for z in range(N)])
available = True... | #!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
prev_dst = [0,0,0]
for n in range(N):
t, x, y = map(int, input().split(" "))
a = (t - prev_dst[0]) - (np.abs(prev_dst[1]-x) + np.abs(prev_dst[2]-y))
if a >= 0 and a % 2 == 0:
prev_dst = [t, x, y]
else:
prin... | #!/usr/bin python3
# -*- coding: utf-8 -*-
import numpy as np
def canReach(src, dst):
a = (dst[0] - src[0]) - np.sum(np.abs(src-dst)[1:3])
if a >= 0 and a % 2 == 0:
return True
return False
N = int(input())
dst = np.array([[int(x) for x in input().split(" ")] for z in range(N)])
available = True... |
a, b, n = map(int, input().split())
mx = 0
for i in range(n+1):
if a*i//b-a*(i//b) > mx:
mx = a*i//b-a*(i//b)
print(mx)
|
a, b, n = map(int, input().split())
mx = 0
nn = n//b
mm = (a*n)//b - a*(nn)
if nn > 0:
x = b*nn-1
mx = (a*x)//b - a*(nn-1)
mm = max(mm, mx)
print(mm) |
a, b, n = map(int, input().split())
mx = 0
for i in range(n+1):
if a*i//b-a*(i//b) > mx:
mx = a*i//b-a*(i//b)
print(mx)
### FIXED CODE ###
a, b, n = map(int, input().split())
mx = 0
nn = n//b
mm = (a*n)//b - a*(nn)
if nn > 0:
x = b*nn-1
mx = (a*x)//b - a*(nn-1)
mm = max(m... |
n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis=(sum(clis,[]))
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(alis):
ans__ = sum(alis[len(... | n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
for x in alis:
lis.append([1,x])
lis.sort(reverse=True,key=lambda x:x[1])
ans = 0
for x in lis:
(number,point) = x
if number >= n:
number = n
ans += number * point
... | n,m = map(int,input().split())
alis = list(map(int,input().split()))
lis = [list(map(int,input().split())) for x in range(m)]
clis = [[x[1]]*x[0] for x in lis]
clis=(sum(clis,[]))
clis.sort(reverse=True)
alis.sort()
ans_lis=[x if x>=y else y for x,y in zip(alis,clis)]
if len(clis) < len(alis):
ans__ = sum(alis[len(... |
import copy
s = str(input())
s_origin = copy.copy(s)
while len(s) > 0:
if "10" in s:
s = str(s).replace("10","")
elif "01" in s:
s = str(s).replace("01","")
else:
break
print(int(len(s_origin) - len(s))) | s = str(input())
ct1 = s.count('1')
ct0 = s.count('0')
print(int(min(ct1,ct0)*2)) | import copy
s = str(input())
s_origin = copy.copy(s)
while len(s) > 0:
if "10" in s:
s = str(s).replace("10","")
elif "01" in s:
s = str(s).replace("01","")
else:
break
print(int(len(s_origin) - len(s)))
### FIXED CODE ###
s = str(input())
ct1 = s.count('1')
ct0 = s.count('0')
... |
# -*- coding: utf-8 -*-
import numpy as np
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
ll, rr = map(int, input().split())
l.append(ll)
r.append(rr)
ans = 0
t = [[0] * n for i in range(m)]
for i in range(m):
for j in range(n):
if l[i]<=j+1 and r[i]>=j+1:
... | # -*- coding: utf-8 -*-
# import numpy as np
n, m = map(int, input().split())
l_min = 1
r_max = n+1
for i in range(m):
l, r = map(int, input().split())
l_min = max(l_min, l)
r_max = min(r_max, r)
ans = r_max - l_min + 1
if ans > 0:
print(ans)
else:
print(0)
| # -*- coding: utf-8 -*-
import numpy as np
n, m = map(int, input().split())
l = []
r = []
for i in range(m):
ll, rr = map(int, input().split())
l.append(ll)
r.append(rr)
ans = 0
t = [[0] * n for i in range(m)]
for i in range(m):
for j in range(n):
if l[i]<=j+1 and r[i]>=j+1:
... |
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
if i == 1:
dp[i] = abs(h[i]-h[i-1])
else:
res = float('inf')
for j in range(1, k+1):
if i-j>=0:
res = min(dp[i-j] + abs(h[i]-h[i-j]), res)
dp[i] = res
pri... | n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
dp[i] = min(dp[j]+abs(h[i]-h[j]) for j in range(max(0, i-k), i))
print(dp[n-1]) | n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(1, n):
if i == 1:
dp[i] = abs(h[i]-h[i-1])
else:
res = float('inf')
for j in range(1, k+1):
if i-j>=0:
res = min(dp[i-j] + abs(h[i]-h[i-j]), res)
dp[i] = res
pri... |
def main():
import sys
input = sys.stdin.readline
INF = 1
class SegTree():
def __init__(self, A):
n_ = len(A)
self.n = 1
while self.n < n_:
self.n *= 2
self.tree = [INF for _ in range(2 * self.n - 1)]
for k, a in enume... | def main():
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
stx = []
tmp = set([])
for _ in range(n):
s,t,x = map(int, input().split())
stx.append((s,t,x))
tmp.add(x-t)
tmp.add(x-s)
d = {}
for i in range(q):
di = -int(inp... | def main():
import sys
input = sys.stdin.readline
INF = 1
class SegTree():
def __init__(self, A):
n_ = len(A)
self.n = 1
while self.n < n_:
self.n *= 2
self.tree = [INF for _ in range(2 * self.n - 1)]
for k, a in enume... |
# ABC 055 B
N = int(input())
p = 1
for i in range(1, N+1):
p *= i
print(p % 1000000007) | # ABC 055 B
N = int(input())
p = 1
for i in range(1, N+1):
p = p * i % 1000000007
print(p) | # ABC 055 B
N = int(input())
p = 1
for i in range(1, N+1):
p *= i
print(p % 1000000007)
### FIXED CODE ###
# ABC 055 B
N = int(input())
p = 1
for i in range(1, N+1):
p = p * i % 1000000007
print(p) |
h, w, n = map(int, input().split())
a_list = [[0 for _ in range(w)] for _ in range(h)]
for _ in range(n):
a, b = map(int, input().split())
a -= 1
b -= 1
a_list[a][b] = 1
z_list = []
for center_x in range(1, h - 1):
for center_y in range(1, w - 1):
temp = a_list[center_x - 1: center_x + 2]
... | from collections import Counter, defaultdict
ans = defaultdict(lambda: 0)
h, w, n = map(int, input().split())
for _ in range(n):
a, b = map(int, input().split())
a -= 1
b -= 1
for a_i in range(a - 2, a + 1):
for b_i in range(b - 2, b + 1):
if (0 <= a_i < h - 2) & (0 <= b_i < w - 2):... | h, w, n = map(int, input().split())
a_list = [[0 for _ in range(w)] for _ in range(h)]
for _ in range(n):
a, b = map(int, input().split())
a -= 1
b -= 1
a_list[a][b] = 1
z_list = []
for center_x in range(1, h - 1):
for center_y in range(1, w - 1):
temp = a_list[center_x - 1: center_x + 2]
... |
n,k = map(int,input().split())
p = list(map(int,input().split()))
e_p = []
for i in range(n):
e_p.append(sum(range(1,p[i]+1)) / p[i])
max = 0
for i in range(n-k+1):
if sum(e_p[i:i+k]) > max:
max = sum(e_p[i:i+k])
print(max)
| n,k = map(int,input().split())
p = list(map(int,input().split()))
e_p = []
for i in range(n):
e_p.append(0.5*p[i]+0.5)
ans = []
s = sum(e_p[:k])
ans.append(s)
for i in range(1,n-k+1):
s -= e_p[i-1]
s += e_p[i+k-1]
ans.append(s)
print(max(ans))
| n,k = map(int,input().split())
p = list(map(int,input().split()))
e_p = []
for i in range(n):
e_p.append(sum(range(1,p[i]+1)) / p[i])
max = 0
for i in range(n-k+1):
if sum(e_p[i:i+k]) > max:
max = sum(e_p[i:i+k])
print(max)
### FIXED CODE ###
n,k = map(int,input().split())
p = list(map(int,input()... |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): r... | import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): r... | import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): r... |
import sys
import bisect
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
dp = [0] * 31
for i in range(28, -1, -1):
mdr = pow(2, i + 1)
fo... | import sys
import bisect
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
def f(md):
pos = n - 1
res = 0
for av in a:
while True:
if pos != -1 and av + b[pos] >= md:
... | import sys
import bisect
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
dp = [0] * 31
for i in range(28, -1, -1):
mdr = pow(2, i + 1)
fo... |
def power_func(a, b, p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
def comb(n, k, p, exp_table):
"""power_funcを用いて(nCk) mod p を求める"""
from math import factorial
if n<0 or k<0 or n<k: return 0
if n==0 o... | from functools import reduce
def comb(n, k, p):
"""power_funcを用いて(nCk) mod p を求める"""
a = reduce(lambda x,y: x*y%p, range(n,n-k,-1))
b = reduce(lambda x,y: x*y%p, range(1,k+1))
return (a*pow(b, p-2, p))%p
n, a, b = map(int, input().split())
MOD = 10**9 + 7
print((pow(2,n,MOD) - 1 - comb(n, a, MOD) - com... | def power_func(a, b, p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
def comb(n, k, p, exp_table):
"""power_funcを用いて(nCk) mod p を求める"""
from math import factorial
if n<0 or k<0 or n<k: return 0
if n==0 o... |
n = int(input())
a_list = list(map(int,input().split()))
print_list = []
for i in range(1,n+1):
print_list.append(a_list.index(i)+1)
for s in print_list:
print(s, end =" ") | # ABC 142 C go to school
n = int(input())
s = list(map(int,input().split()))
# ソートされたリストのインデックスを返す
s = sorted(range(len(s)), key=lambda k:s[k])
ans = [x+1 for x in s]
print(*ans) | n = int(input())
a_list = list(map(int,input().split()))
print_list = []
for i in range(1,n+1):
print_list.append(a_list.index(i)+1)
for s in print_list:
print(s, end =" ")
### FIXED CODE ###
# ABC 142 C go to school
n = int(input())
s = list(map(int,input().split()))
# ソートされたリストのインデックスを返す
s = sorted(range(len... |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug
from functools import lru_cache
import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atco... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug
from functools import lru_cache
import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atco... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug
from functools import lru_cache
import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atco... |
from collections import deque
INF = 10**18
def append_dq(i, x, dq, dp1):
while True:
if not len(dq):
dq.append(i)
break
lxi = dq[-1]
if x > dp1[lxi]:
dq.append(i)
break
dq.pop()
return dq
dq = deque()
N,M = map(int, input().split(... | from collections import deque
INF = 10**18
def append_dq(i, x, dq, dp1):
while True:
if not len(dq):
dq.append(i)
break
lxi = dq[-1]
if x > dp1[lxi]:
dq.append(i)
break
dq.pop()
return dq
dq = deque()
N,M = map(int, input().split()... | from collections import deque
INF = 10**18
def append_dq(i, x, dq, dp1):
while True:
if not len(dq):
dq.append(i)
break
lxi = dq[-1]
if x > dp1[lxi]:
dq.append(i)
break
dq.pop()
return dq
dq = deque()
N,M = map(int, input().split(... |
s=input()
N=int(input())
#s="atcoderandatcodeer"
#N=5
D={}
if(len(s)<=10):
for i in range(1,len(s)+1):
for j in range(len(s)):
if D.get(s[j:j+i],None) == None:
D[s[j:j+i]]=1
D=sorted(D)
print(D[N-1])
exit()
else:
t=sorted(s)
i=0
k=0
for c in t:
... | s=input()
N=int(input())
#s="atcoderandatcodeera"
#N=5
D={}
if(len(s)<=1):
for i in range(1,len(s)+1):
for j in range(len(s)):
if D.get(s[j:j+i],None) == None:
D[s[j:j+i]]=1
D=sorted(D)
print(D[N-1])
exit()
else:
t=sorted(s)
i=0
k=0
for c in t:
... | s=input()
N=int(input())
#s="atcoderandatcodeer"
#N=5
D={}
if(len(s)<=10):
for i in range(1,len(s)+1):
for j in range(len(s)):
if D.get(s[j:j+i],None) == None:
D[s[j:j+i]]=1
D=sorted(D)
print(D[N-1])
exit()
else:
t=sorted(s)
i=0
k=0
for c in t:
... |
r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
for j in range(3001):
if b==0:
if n==r*i+g*j:
ans+=1
else:
if (n-r*i-g*j)%b==0:
ans+=1
print(ans)
| r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
for j in range(3001):
if (n-r*i-g*j)>=0 and (n-r*i-g*j)%b==0:
ans+=1
print(ans)
| r,g,b,n=map(int,input().split())
ans=0
for i in range(3001):
for j in range(3001):
if b==0:
if n==r*i+g*j:
ans+=1
else:
if (n-r*i-g*j)%b==0:
ans+=1
print(ans)
### FIXED CODE ###
r,g,b,n=map(int,input().split())
ans=0
for ... |
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
A, B = [], []
for i in range(N):
a, b = map(int, input().split())
A.append([a, i])
B.append([b, i])
A.sort(reverse=True, key=itemgetter(1))
B.sort(reverse=True, key=itemgetter(1))
ate = []
apoint, apos = 0, 0
bpoint, b... | N = int(input())
A, B = [], []
for _ in range(N):
a, b = map(int, input().split())
A.append(a + b)
B.append(b)
A.sort(reverse=True)
print(sum([ab for i, ab in enumerate(A) if i % 2 == 0]) - sum(B))
| import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
A, B = [], []
for i in range(N):
a, b = map(int, input().split())
A.append([a, i])
B.append([b, i])
A.sort(reverse=True, key=itemgetter(1))
B.sort(reverse=True, key=itemgetter(1))
ate = []
apoint, apos = 0, 0
bpoint, b... |
h, w = map(int, input().split())
lsa = [list(map(int, input().split())) for i in range(h)]
lsb = [list(map(int, input().split())) for i in range(h)]
ls = [[abs(lsa[i][j] - lsb[i][j]) for j in range(w)] for i in range(h)]
dp = [[set() for _ in range(w)] for _ in range(h)]
dp[0][0].add(ls[0][0])
for i in range(h):
... | h, w = map(int, input().split())
lsa = [list(map(int, input().split())) for i in range(h)]
lsb = [list(map(int, input().split())) for i in range(h)]
ls = [[abs(lsa[i][j] - lsb[i][j]) for j in range(w)] for i in range(h)]
bias = 80*80*80
dp = [[0 for _ in range(w)] for _ in range(h)]
dp[0][0] = 1 << ls[0][0]+bias
for... | h, w = map(int, input().split())
lsa = [list(map(int, input().split())) for i in range(h)]
lsb = [list(map(int, input().split())) for i in range(h)]
ls = [[abs(lsa[i][j] - lsb[i][j]) for j in range(w)] for i in range(h)]
dp = [[set() for _ in range(w)] for _ in range(h)]
dp[0][0].add(ls[0][0])
for i in range(h):
... |
def myAnswer(N:int,S:list) -> int:
counter = 0
dic = {}
for s in S:
if(s in dic.keys()):
dic[s]+=1
else:
dic[s] = 0
for value in dic.values():
counter += (value * (value + 1)) // 2
return counter
def modelAnswer():
return
def main():
N = int(input())
S = ["".... | N=int(input())
s=[]
cnt=dict()
for _ in range(N):
tmp=list(input())
sotmp=sorted(tmp)
stmp=''.join(sotmp)
s.append(stmp)
ss=sorted(s)
for word in ss:
if((word in cnt.keys())==False):
cnt[word]=0
else:
cnt[word]+=1
total=0
for value in cnt.values():
total+=(1+value)*valu... | def myAnswer(N:int,S:list) -> int:
counter = 0
dic = {}
for s in S:
if(s in dic.keys()):
dic[s]+=1
else:
dic[s] = 0
for value in dic.values():
counter += (value * (value + 1)) // 2
return counter
def modelAnswer():
return
def main():
N = int(input())
S = ["".... |
def main():
S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
r=1
for i in range(len(S)):
new_dp=[0]*13
s=S[-1-i]
if s=="?":
for j in range(10):
rem=(j*r)%13
for k in range(13):
new_dp[(k+rem)%13]+=dp[k]
else:
... | S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
r=1
for i in range(len(S)):
new_dp=[0]*13
s=S[-1-i]
if s=="?":
for j in range(10):
rem=(j*r)%13
for k in range(13):
new_dp[(k+rem)%13]+=dp[k]
else:
rem=(int(s)*r)%13
for k in range(13):
ne... | def main():
S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
r=1
for i in range(len(S)):
new_dp=[0]*13
s=S[-1-i]
if s=="?":
for j in range(10):
rem=(j*r)%13
for k in range(13):
new_dp[(k+rem)%13]+=dp[k]
else:
... |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
n, m, *a = map(int, open(0).read().split())
dp = [0] * (n + 1)
ok = [True] * (n + 1)
for i in a:
ok[i] = False
def count(n):
if n < 2:
return 1
if dp[n] != 0:
return dp[n]
dp[n] = (count(n - 1) * ok[n - 1] + count(n - ... | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
memo = [0]*(10**5+1)
def count(n):
if n < 2:
return 1
if memo[n] != 0:
return memo[n]
memo[n] = count(n-1) + count(n-2)
return memo[n]
n, m, *a = map(int, open(0).read().split())
if sum(a[i + 1] == a[i] + 1 for i in ra... | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
n, m, *a = map(int, open(0).read().split())
dp = [0] * (n + 1)
ok = [True] * (n + 1)
for i in a:
ok[i] = False
def count(n):
if n < 2:
return 1
if dp[n] != 0:
return dp[n]
dp[n] = (count(n - 1) * ok[n - 1] + count(n - ... |
import bisect
n, q = (int(i) for i in input().split())
s = input()
l,r = [],[]
for i in range(q):
tmp = [int(i) for i in input().split()]
l.append(tmp[0]-1)
r.append(tmp[1]-1)
# AC_index = []
# while 'AC' in s:
# index = s.index('AC')
# AC_index.append(index + len(AC_index) * 2)
# if index < (le... | N, Q = map(int, input().split())
S = input()
L,R = [], []
for i in range(Q):
l, r = map(int, input().split())
L.append(l)
R.append(r)
AC = [0] * N
for i in range(1,N):
if S[i - 1] == 'A' and S[i] == 'C':
AC[i] = AC[i - 1] + 1
else:
AC[i] = AC[i - 1]
for l, r in zip(L, R):
prin... | import bisect
n, q = (int(i) for i in input().split())
s = input()
l,r = [],[]
for i in range(q):
tmp = [int(i) for i in input().split()]
l.append(tmp[0]-1)
r.append(tmp[1]-1)
# AC_index = []
# while 'AC' in s:
# index = s.index('AC')
# AC_index.append(index + len(AC_index) * 2)
# if index < (le... |
n = int(input())
sl = list(input() for _ in range(n))
sl_s = sorted(list(set(sl)))
# if len(sl_s) == 1:
# print(sl[0])
# else:
# ans = []
# count = 1
# for s in sl_s:
# if sl.count(s) == count and ans.count(s) == 0:
# ans.append(s)
# elif sl.count(s) > count and ans.count(s... | from collections import Counter
n = int(input())
sl = list(input() for _ in range(n))
cnt = Counter(sl)
# print('cnt:', cnt)
maxNum = max(cnt.values())
# print('maxNum:', maxNum)
ans = []
for k, v in cnt.items():
if v == maxNum:
ans.append(k)
ans.sort()
print('\n'.join(ans)) | n = int(input())
sl = list(input() for _ in range(n))
sl_s = sorted(list(set(sl)))
# if len(sl_s) == 1:
# print(sl[0])
# else:
# ans = []
# count = 1
# for s in sl_s:
# if sl.count(s) == count and ans.count(s) == 0:
# ans.append(s)
# elif sl.count(s) > count and ans.count(s... |
# -*- coding:utf-8 -*-
N = int(input())
n = [int(input()) for i in range(N)]
def Is_prime(n):
if n == 2:
return True
if n % 2 == 0:
return False
i = 3
while i < int(n ** (0.5))+ 1:
if n % i == 0:
return False
return True
count = 0
for j in n:
if Is_prime(j)... | N = int(input())
n = [int(input()) for i in range(N)]
def Is_prime(n):
if n == 2:
return True
if n == 1:
return False
if n % 2 == 0:
return False
i = 3
while i < int(n ** (0.5))+ 1:
if n % i == 0:
return False
i += 2
return True
count = 0
for... | # -*- coding:utf-8 -*-
N = int(input())
n = [int(input()) for i in range(N)]
def Is_prime(n):
if n == 2:
return True
if n % 2 == 0:
return False
i = 3
while i < int(n ** (0.5))+ 1:
if n % i == 0:
return False
return True
count = 0
for j in n:
if Is_prime(j)... |
import bisect
import collections
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62
def lmi():
return list(map(int, input().split()))
def llmi(n):
return [lmi() for _ in range(n)]
N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]
a = A
b = B
tot... | import bisect
import collections
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62
def lmi():
return list(map(int, input().split()))
def llmi(n):
return [lmi() for _ in range(n)]
N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]
a = A
b = B
tot... | import bisect
import collections
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62
def lmi():
return list(map(int, input().split()))
def llmi(n):
return [lmi() for _ in range(n)]
N, A, B, C = lmi()
S = [input().strip() for _ in range(N)]
a = A
b = B
tot... |
A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
m = []
for i in range(M):
x, y, z = map(int, input().split())
if min(a) + min(b) <= z or max(a) + max(b) >= z:
m.append([x, y, z])
m.sort(key = lambda x: x[2], reverse=True)
for j in m:
... | A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
m = []
am = min(a)
bm = min(b)
for i in range(M):
x, y, z = map(int, input().split())
m.append(a[x-1] + b[y-1] - z )
if am + bm > min(m):
print(min(m))
else:
print(am + bm) | A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
m = []
for i in range(M):
x, y, z = map(int, input().split())
if min(a) + min(b) <= z or max(a) + max(b) >= z:
m.append([x, y, z])
m.sort(key = lambda x: x[2], reverse=True)
for j in m:
... |
#https://atcoder.jp/contests/dp/tasks/dp_b
N,K = [int(x) for x in input().split()]
h = list(map(int,input().split()))
dp = [0] * (N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
tmp_dp = []
for i in range(2,N):
for k in range(1,K+1):
if k > i:
break
tmp_dp.append(dp[i-k] + abs(h[i]-h[i-k]))
# ... | # https://atcoder.jp/contests/dp/tasks/dp_b
def main():
N, K = map(int, input().split())
h = [int(x) for x in input().split()]
dp = [0] * (N)
dp[0] = 0
# 参考:https://atcoder.jp/contests/dp/submissions/10181844
for i in range(1, N):
tmp = [dp[k] + abs(h[i] - h[k]) for k in range(max(0, ... | #https://atcoder.jp/contests/dp/tasks/dp_b
N,K = [int(x) for x in input().split()]
h = list(map(int,input().split()))
dp = [0] * (N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
tmp_dp = []
for i in range(2,N):
for k in range(1,K+1):
if k > i:
break
tmp_dp.append(dp[i-k] + abs(h[i]-h[i-k]))
# ... |
# https://atcoder.jp/contests/abc123
# -*- coding: utf-8 -*-
n=int(input())
v = [int(input()) for i in range(5)]
city = [ n, 0, 0, 0, 0, 0]
counter = 0
while city[5] is not n:
counter += 1
for i in range(5)[::-1]:
if city[i] >= v[i]:
city[i+1] += v[i]
city[i] -= v[i]
e... | # https://atcoder.jp/contests/abc123
# -*- coding: utf-8 -*-
n=int(input())
v = [int(input()) for i in range(5)]
minimum = min(v)
if n % minimum is 0:
print((n // minimum)+4)
else:
print((n // minimum)+5) | # https://atcoder.jp/contests/abc123
# -*- coding: utf-8 -*-
n=int(input())
v = [int(input()) for i in range(5)]
city = [ n, 0, 0, 0, 0, 0]
counter = 0
while city[5] is not n:
counter += 1
for i in range(5)[::-1]:
if city[i] >= v[i]:
city[i+1] += v[i]
city[i] -= v[i]
e... |
import numpy as np
N, M = [int(x) for x in input().split(' ')]
price = [int(x) for x in input().split(' ')]
for m in range(M):
index = np.argmax(price)
price[index] = price[index]/2.
price = [int(x) for x in price]
print(sum(price)) | from heapq import heappush, heappop
import numpy as np
N, M = [int(x) for x in input().split()]
price = [int(x) for x in input().split()]
hq_price = []
for p in price:
heappush(hq_price, -p)
for m in range(M):
max_tmp = heappop(hq_price)
heappush(hq_price, max_tmp/2.)
price = [int(-x) for x in hq_price]
prin... | import numpy as np
N, M = [int(x) for x in input().split(' ')]
price = [int(x) for x in input().split(' ')]
for m in range(M):
index = np.argmax(price)
price[index] = price[index]/2.
price = [int(x) for x in price]
print(sum(price))
### FIXED CODE ###
from heapq import heappush, heappop
import numpy as np
... |
S = input()
N = len(S)
count = 0
for i in range(N):
for j in range(i,N):
if int(S[i:j+1]) % 2019 == 0:
count = count + 1
else:
continue
print(count) | S = input()[::-1]
N = len(S)
l = [0]*2019
l[0] = 1
n = 0
d = 1
for i in range(N):
n += int(S[i]) * d
r = n % 2019
l[r] += 1
d = 10*d % 2019
out = 0
for m in l:
out += (m*(m-1))//2
print(out) | S = input()
N = len(S)
count = 0
for i in range(N):
for j in range(i,N):
if int(S[i:j+1]) % 2019 == 0:
count = count + 1
else:
continue
print(count)
### FIXED CODE ###
S = input()[::-1]
N = len(S)
l = [0]*2019
l[0] = 1
n = 0
d = 1
for i in range(N):
n += int(S[i]) * d
... |
K, S = map(int, input().split())
count=0
for x in range(K+1):
for y in range(K+1):
for z in range(K+1):
if x+y+z == S:
count += 1
print(count) | K, S = map(int, input().split())
count=0
for x in range(K+1):
for y in range(K+1):
z = S - (x+y)
if (z <= K) & (z >= 0):
count += 1
print(count) | K, S = map(int, input().split())
count=0
for x in range(K+1):
for y in range(K+1):
for z in range(K+1):
if x+y+z == S:
count += 1
print(count)
### FIXED CODE ###
K, S = map(int, input().split())
count=0
for x in range(K+1):
for y in range(K+1):
z = S - (x+y)
if (z... |
"""
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...
N = 8
[青青青赤赤赤赤青]
return 青 = 4
"""
def count_balls():
# 入力
N, A, B = map(int, input().split())
# 例外
if A+B == 0:
return 0
# N以下の[青*A][赤*B]の組み合わせの個数
i = 1
while True:
if N >= (A+B) * i:
i += 1
else:
br... | """
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...
N = 8
[青青青赤赤赤赤青]
return 青 = 4
"""
def count_balls():
# 入力
N, A, B = map(int, input().split())
# [青青青赤赤赤赤]の個数と余り
comb_count = N // (A + B)
remainder = N % (A + B)
# 集計
if remainder <= A:
return A * comb_count + remainder
else:
r... | """
A = 3, B = 4
[青青青][赤赤赤赤][青青青][赤赤赤]...
N = 8
[青青青赤赤赤赤青]
return 青 = 4
"""
def count_balls():
# 入力
N, A, B = map(int, input().split())
# 例外
if A+B == 0:
return 0
# N以下の[青*A][赤*B]の組み合わせの個数
i = 1
while True:
if N >= (A+B) * i:
i += 1
else:
br... |
import bisect
n = int(input())
ans_head=[-1]
for i in range(n):
a=int(input())
if min(ans_head)>=a:
ans_head=[a]+ans_head
else:
insert_index = bisect.bisect_left(ans_head,a)
ans_head[insert_index-1]=a
#print(ans_head)
print(len(ans_head))
| import bisect
n=int(input())
A=[]
for i in range(n):
A.append(int(input()))
Ans=[A[-1]]
for i in reversed(range(n-1)):
a=A[i]
if a>=Ans[-1]:
Ans.append(a)
else:
Ans[bisect.bisect_right(Ans,a)]=a
print(len(Ans))
| import bisect
n = int(input())
ans_head=[-1]
for i in range(n):
a=int(input())
if min(ans_head)>=a:
ans_head=[a]+ans_head
else:
insert_index = bisect.bisect_left(ans_head,a)
ans_head[insert_index-1]=a
#print(ans_head)
print(len(ans_head))
### FIXED CODE ###
import bisect
n=int(input())
A=[]
for... |
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
for i in range(N):
b_idx = bisect.bisect_right(B, A[i])
for j in range(b_idx, N):
c_idx = bisect.bisect_right(C, B[j])
... | import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
BtoC = [0 for i in range(N+1)]
for i in range(N-1, -1, -1):
c_idx = bisect.bisect_right(C, B[i])
BtoC[i] = BtoC[i+1] + (N - c_idx)
count = 0
for ... | import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
for i in range(N):
b_idx = bisect.bisect_right(B, A[i])
for j in range(b_idx, N):
c_idx = bisect.bisect_right(C, B[j])
... |
n = int(input())
a = list(map(int, input().split()))
calc = 0
for i in range(n):
for j in range(i+1, n):
calc += (a[i] * a[j]) % 1000000007
calc %= 1000000007
print(calc) | n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
calc = 0
for i in range(n):
sum_a -= a[i]
calc += ((sum_a % 1000000007) * a[i]) % 1000000007
calc %= 1000000007
print(calc) | n = int(input())
a = list(map(int, input().split()))
calc = 0
for i in range(n):
for j in range(i+1, n):
calc += (a[i] * a[j]) % 1000000007
calc %= 1000000007
print(calc)
### FIXED CODE ###
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
calc = 0
for i in range(n):
sum_a -= a[i]
... |
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
while True:
if a[i] + a[i-1] > x:
a[i] -= 1
cnt += 1
else:
break
print(cnt)
| n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
while True:
if a[i] + a[i-1] > x:
if a[i] != 0:
t = min((a[i] + a[i-1] - x), a[i])
a[i] -= t
cnt += t
else:
t = min((a[i]... | n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, n):
while True:
if a[i] + a[i-1] > x:
a[i] -= 1
cnt += 1
else:
break
print(cnt)
### FIXED CODE ###
n, x = map(int, input().split())
a = list(map(int, input().split())... |
import itertools
import math
n = int(input())
for i in range(n):
cnt = 0
for x,y,z in itertools.product(range(1,int(math.sqrt(n))),repeat=3):
if x**2 + y**2 + z**2 + x*y + y*z + z*x == i+1:
cnt += 1
print(cnt)
| n = int(input())
ans = [0] * n
for x in range(1,int(n**0.5)):
for y in range(1,int(n**0.5)):
for z in range(1,int(n**0.5)):
a = x**2 + y**2 + z**2 + x*y + y*z + z*x
if a <= n:
ans[a-1] += 1
[print(x) for x in ans] | import itertools
import math
n = int(input())
for i in range(n):
cnt = 0
for x,y,z in itertools.product(range(1,int(math.sqrt(n))),repeat=3):
if x**2 + y**2 + z**2 + x*y + y*z + z*x == i+1:
cnt += 1
print(cnt)
### FIXED CODE ###
n = int(input())
ans = [0] * n
for x in range(1,int(n*... |
from collections import deque
n = int(input())
Ps = list(map(int, input().split()))
def hw(p):
h,w = divmod(p,n)
return h,w
def toP(h,w):
return h * n + w
fs = [[0]*n for i in range(n)]
## フロアフィールドを作る
for i in range(n):
x = min(i,n-1-i)
for j in range(n):
y = min(j,n-1-j)
fs[i][j]... | from collections import deque
n = int(input())
Ps = list(map(int, input().split()))
Ps = [p-1 for p in Ps]
fs = [0] * (n**2)
## フロアフィールドを作る
for x in range(n**2):
i,j = divmod(x,n)
x = min(i,n-1-i)
y = min(j,n-1-j)
fs[i*n+j] = min(x,y)
ans = 0
mvs = [1, -1, n, -n]
occupied = [1] * (n**2)
for p in Ps:
... | from collections import deque
n = int(input())
Ps = list(map(int, input().split()))
def hw(p):
h,w = divmod(p,n)
return h,w
def toP(h,w):
return h * n + w
fs = [[0]*n for i in range(n)]
## フロアフィールドを作る
for i in range(n):
x = min(i,n-1-i)
for j in range(n):
y = min(j,n-1-j)
fs[i][j]... |
import math
def sieve_of_erastosthenes(num):
input_list = [0 if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else 1 for i in range(num)]
input_list[0] = input_list[1] = 0
input_list[2] = input_list[3] = input_list[5] = 1
sqrt = math.sqrt(num)
for serial in range(3, num, 2):
if serial >= sqrt:
... | import math
def sieve_of_erastosthenes(num):
input_list = [0 if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else 1 for i in range(num)]
input_list[0] = input_list[1] = 0
input_list[2] = input_list[3] = input_list[5] = 1
sqrt = math.sqrt(num)
for serial in range(3, num, 2):
if serial >= sqrt:
... | import math
def sieve_of_erastosthenes(num):
input_list = [0 if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else 1 for i in range(num)]
input_list[0] = input_list[1] = 0
input_list[2] = input_list[3] = input_list[5] = 1
sqrt = math.sqrt(num)
for serial in range(3, num, 2):
if serial >= sqrt:
... |
N,M=map(int,input().split())
list1=list(map(int,input().split()))
for _ in range(M):
B,C=map(int,input().split())
list1+=[C]*B
list1.sort(reverse=True)
list1=list1[:N]
SUM=sum(list1)
print(SUM) | N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
for i in range(M):
B, C = listBC[i][0], listBC[i][1]
listA += [C]*B
countB += B
if countB >= ... | N,M=map(int,input().split())
list1=list(map(int,input().split()))
for _ in range(M):
B,C=map(int,input().split())
list1+=[C]*B
list1.sort(reverse=True)
list1=list1[:N]
SUM=sum(list1)
print(SUM)
### FIXED CODE ###
N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
listBC = [list... |
def main():
A,B,K = map(int,input().split())
for i in range(0,K):
if A > 0:
A = A - 1
elif B > 0:
B = B - 1
print(A,B)
if __name__ == '__main__':
main()
| def main():
A,B,K = map(int,input().split())
if A+B < K:
print(0,0)
else:
if A < K:
print(0, A+B-K)
else:
print(A-K, B)
if __name__ == '__main__':
main()
| def main():
A,B,K = map(int,input().split())
for i in range(0,K):
if A > 0:
A = A - 1
elif B > 0:
B = B - 1
print(A,B)
if __name__ == '__main__':
main()
### FIXED CODE ###
def main():
A,B,K = map(int,input().split())
if A+B < K:
print(0,0)
... |
# -*- coding: utf-8 -*-
"""
参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/
・ミニマックス法
・メモ化再帰
・先手と後手にそれぞれのメモを作る
"""
import sys
from collections import defaultdict
# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)
N, Z, W = map(int, input().split())
aN = list(map(int, input().split()))
# 先手番用メモ[残り山札数][... | # -*- coding: utf-8 -*-
"""
参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/
・ミニマックス法
・メモ化再帰
・先手と後手にそれぞれのメモを作る
"""
import sys
from collections import defaultdict
# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)
N, Z, W = map(int, input().split())
aN = list(map(int, input().split()))
# 先手番用メモ[残り山札数][... | # -*- coding: utf-8 -*-
"""
参考:https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/
・ミニマックス法
・メモ化再帰
・先手と後手にそれぞれのメモを作る
"""
import sys
from collections import defaultdict
# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)
N, Z, W = map(int, input().split())
aN = list(map(int, input().split()))
# 先手番用メモ[残り山札数][... |
MOD = 10**9 + 7 # 出力の制限
r1, c1, r2, c2 = list(map(int, input().split()))
# https://qiita.cmb/derodero24/items/91b6468e66923a87f39f
def cmb(n, r):
if (r < 0 or r > n):
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % MOD
N = 10**7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] ... | MOD = 10**9 + 7 # 出力の制限
r1, c1, r2, c2 = list(map(int, input().split()))
# https://qiita.cmb/derodero24/items/91b6468e66923a87f39f
def cmb(n, r):
if (r < 0 or r > n):
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % MOD
N = 2 * 10**6 + 3
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = ... | MOD = 10**9 + 7 # 出力の制限
r1, c1, r2, c2 = list(map(int, input().split()))
# https://qiita.cmb/derodero24/items/91b6468e66923a87f39f
def cmb(n, r):
if (r < 0 or r > n):
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % MOD
N = 10**7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] ... |
from math import sqrt
import heapq
def calc(arr, i, j):
d = sqrt((arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2)
if arr[i][2] + arr[j][2] <= d:
return d - arr[i][2] - arr[j][2]
else:
return 0
def main():
xs, ys, xt, yt = map(int, input().split())
n = int(input())
arr =... | from heapq import heappop,heappush
from math import sqrt
def distf(xyr,i,j):
x,y,r=xyr[i]
x1,y1,r1=xyr[j]
d=max(0,sqrt((x-x1)**2+(y-y1)**2)-r-r1)
return d
def main():
xs,ys,xt,yt=map(int,input().split())
n=int(input())
xyr=[list(map(int,input().split())) for _ in range(n)]
xyr.append([xs,ys,0])
xyr.a... | from math import sqrt
import heapq
def calc(arr, i, j):
d = sqrt((arr[i][0] - arr[j][0])**2 + (arr[i][1] - arr[j][1])**2)
if arr[i][2] + arr[j][2] <= d:
return d - arr[i][2] - arr[j][2]
else:
return 0
def main():
xs, ys, xt, yt = map(int, input().split())
n = int(input())
arr =... |
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
b[i], c[i] = map(int, input().split())
num_dict = dict()
for i in a:
if i in num_dict.keys():
num_dict[i] += 1
else:
num_dict[i] = 1
for i in range(q):
ans = 0
if b[i] i... | n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
b[i], c[i] = map(int, input().split())
num_dict = dict()
for i in a:
if i in num_dict.keys():
num_dict[i] += 1
else:
num_dict[i] = 1
ans = 0
for k, v in num_dict.items():... | n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
b[i], c[i] = map(int, input().split())
num_dict = dict()
for i in a:
if i in num_dict.keys():
num_dict[i] += 1
else:
num_dict[i] = 1
for i in range(q):
ans = 0
if b[i] i... |
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): retur... | import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): retur... | import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): retur... |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect... | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect... | # coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect... |
n = int(raw_input())
G = [[-1] * n] * n
d = [0] * n
for i in range(n):
v = map(int, raw_input().split())
for j in range(v[1]):
G[v[0]][v[2+2*j]] = int(v[3+2*j])
flag = [0] * n
tn = [1]
r = 0
while True:
for i in range(n):
if flag[i] == 0 and i in tn:
flag[i] = 1
d... | n = int(input())
G = [[-1 for i in range(n)] for j in range(n)]
d = [999999 for i in range(n)]
for i in range(n):
v = input().split()
for j in range(int(v[1])):
G[int(v[0])][int(v[2+2*j])] = int(v[3+2*j])
flag = [0] * n
tn = [0]
d[0] = 0
for k in range(n):
for i in range(n):
if i in tn:
... | n = int(raw_input())
G = [[-1] * n] * n
d = [0] * n
for i in range(n):
v = map(int, raw_input().split())
for j in range(v[1]):
G[v[0]][v[2+2*j]] = int(v[3+2*j])
flag = [0] * n
tn = [1]
r = 0
while True:
for i in range(n):
if flag[i] == 0 and i in tn:
flag[i] = 1
d... |
import numpy as np
H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
direction = [[0,1],[0,-1],[1,0],[-1,0]]
black = np.zeros((H,W))
que = []
for i in range(H):
for j in range(W):
if G[i][j] == '#':
que.append([i,j])
black[i][j] = 0
while que:
nh, nw = que.pop(0)
for dh, dw... | import copy
from collections import deque
def main():
H, W = map(int, input().split())
G = [['#' == x for x in input()] for _ in range(H)]
black = deque([(i, j) for i in range(H) for j in range(W) if G[i][j]])
ans = 0
while True:
ans += 1
next_black = deque()
while black:
bi, bj = black.... | import numpy as np
H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
direction = [[0,1],[0,-1],[1,0],[-1,0]]
black = np.zeros((H,W))
que = []
for i in range(H):
for j in range(W):
if G[i][j] == '#':
que.append([i,j])
black[i][j] = 0
while que:
nh, nw = que.pop(0)
for dh, dw... |
import math
tmp = input().split()
X = int(tmp[0])
Y = int(tmp[1])
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
print(0)
else:
n = (2 * Y - X) / 3
m = Y - 2 * n
if n < 0 or m < 0:
print(0)
exit()
total = math.factorial(n + m)
n = math.factorial(n)
m = math.factorial(m)
total /... | import math
tmp = input().split()
X = int(tmp[0])
Y = int(tmp[1])
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
print(0)
else:
n = int((2 * Y - X) / 3)
m = int(Y - 2 * n)
if n < 0 or m < 0:
print(0)
exit()
n %= mod
m %= mod
r = n
n = n+m
# if n - r < r:
# r = n - ... | import math
tmp = input().split()
X = int(tmp[0])
Y = int(tmp[1])
mod = 10 ** 9 + 7
if (X + Y) % 3 != 0:
print(0)
else:
n = (2 * Y - X) / 3
m = Y - 2 * n
if n < 0 or m < 0:
print(0)
exit()
total = math.factorial(n + m)
n = math.factorial(n)
m = math.factorial(m)
total /... |
from numba import njit
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
@njit
def f(S, N):
tmp = 0
for i in range(N):
for j in range(i+1, N):
k = j + (j - i)
if k >= N:
break
if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:... | N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
tmp = 0
for i in range(N):
for j in range(i+1, N):
k = j + (j - i)
if k >= N:
break
if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
tmp-=1
print(tmp + R*G*B) | from numba import njit
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = S.count('B')
@njit
def f(S, N):
tmp = 0
for i in range(N):
for j in range(i+1, N):
k = j + (j - i)
if k >= N:
break
if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:... |
import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(sumcost,(0,i,j,0,puz)))
global finding
while len(q):
c_dWithH, items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
_su... | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(sumcost,(0,i,j,0,puz)))
global finding
while len(q):
cost, items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
_sum_co... | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(sumcost,(0,i,j,0,puz)))
global finding
while len(q):
c_dWithH, items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
_su... |
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.stdin.read... | 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.stdin.read... | 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.stdin.read... |
n = int(input())
anstmp = ["a"]
cnt = 0
for i in anstmp:
t = ord(i[-1])-95
if cnt > 1000000:
break
for j in range(1,t+1):
anstmp.append(i+chr(j+96))
cnt += 1
ans = set()
for i in anstmp:
if len(i) == n:
ans.add(i)
ans = list(ans)
ans.sort()
print(*ans,sep="\n") | n = int(input())
anstmp = ["a"]
cnt = 0
for i in anstmp:
t = max(ord(k) for k in i)-95
if cnt > 100000:
break
for j in range(1,t+1):
anstmp.append(i+chr(j+96))
cnt += 1
ans = set()
for i in anstmp:
if len(i) == n:
ans.add(i)
ans = list(ans)
ans.sort()
print(*ans,sep="\n") | n = int(input())
anstmp = ["a"]
cnt = 0
for i in anstmp:
t = ord(i[-1])-95
if cnt > 1000000:
break
for j in range(1,t+1):
anstmp.append(i+chr(j+96))
cnt += 1
ans = set()
for i in anstmp:
if len(i) == n:
ans.add(i)
ans = list(ans)
ans.sort()
print(*ans,sep="\n")
### FIXED CODE ###
n = int(input()... |
s=input()
counter=[0]*2019
counter[0]=1
prefer=0
for i in range(len(s)):
prefer=(prefer+10**i*int(s[-(i+1)]))%2019
counter[prefer]+=1
ans=0
for i in range(2019):
c=counter[i]
ans+=c*(c-1)/2
print(int(ans))
| s=input()
counter=[0]*2019
counter[0]=1
num=0
t=1
prefer=0
for i in reversed(s):
num+=int(i)*t
num%=2019
t*=10
t%=2019
counter[num]+=1
ans=0
for i in range(2019):
c=counter[i]
ans+=c*(c-1)/2
print(int(ans))
| s=input()
counter=[0]*2019
counter[0]=1
prefer=0
for i in range(len(s)):
prefer=(prefer+10**i*int(s[-(i+1)]))%2019
counter[prefer]+=1
ans=0
for i in range(2019):
c=counter[i]
ans+=c*(c-1)/2
print(int(ans))
### FIXED CODE ###
s=input()
counter=[0]*2019
counter[0]=1
num=0
t=1
prefer=0
for i in re... |
a, b = input().split()
a, b = int(a), int(b)
n = 1
for i in range(a, b + 1):
n *= i
if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")
| a, b = input().split()
a, b = int(a), int(b)
if a < 0 < b:
print("Zero")
elif 0 < a < b:
print("Positive")
elif a < b < 0:
if (b - a + 1) % 2 == 0:
print("Positive")
else:
print("Negative")
| a, b = input().split()
a, b = int(a), int(b)
n = 1
for i in range(a, b + 1):
n *= i
if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")
### FIXED CODE ###
a, b = input().split()
a, b = int(a), int(b)
if a < 0 < b:
print("Zero")
elif 0 < a < b:
print("Positive")
el... |
n = int(input())
s = input()
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in reversed(range(n)):
for j in reversed(range(n)):
if s[i] == s[j]:
dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
for j in range(n):
ans = max(ans,min(dp[i][j],j-i))
... | n = int(input())
s = input()
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in reversed(range(n)):
for j in reversed(range(n)):
if s[i] == s[j]:
dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
for j in range(n):
ans = max(ans,min(dp[i][j],j-i))
... | n = int(input())
s = input()
dp = [[0 for i in range(n+1)] for j in range(n+1)]
for i in reversed(range(n)):
for j in reversed(range(n)):
if s[i] == s[j]:
dp[i][j] = dp[i+1][j+1] + 1
ans = 0
for i in range(n):
for j in range(n):
ans = max(ans,min(dp[i][j],j-i))
... |
S = input()[::-1]
dp = [[0]*13]
MOD = 10**9+7
for i in range(1,len(S)+1):
s = S[i-1]
dp += [[0]*13]
if s=='?':
if i==1:
for j in range(10):
dp[i][j] = 1
else:
for j in range(13):
for h in range(10):
x = h*(10**(i-1))%13
dp[i][j] += dp[i-1][(j-x)%13]
... | S = input()
con = 10**9 + 7
T = [s if s != "?" else "0" for s in S]
T = int(''.join(T))
SS = T % 13
def get_mod(S):
c = {}
iii = 1
for i in range(len(S)):
if S[len(S) - i - 1] != "?":
iii *= 10
iii %= 13
continue
c[i] = {(j * iii) % 13: 1 for j in range(... | S = input()[::-1]
dp = [[0]*13]
MOD = 10**9+7
for i in range(1,len(S)+1):
s = S[i-1]
dp += [[0]*13]
if s=='?':
if i==1:
for j in range(10):
dp[i][j] = 1
else:
for j in range(13):
for h in range(10):
x = h*(10**(i-1))%13
dp[i][j] += dp[i-1][(j-x)%13]
... |
def calc_exp(p):
result = 0
for n in p:
result += expectation(n)
return result
def expectation(p):
n = sum(p)
return 0.5 * n + 0.5 * len(p)
def main():
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_num = 0
max_idx = -1
for i in range(n-k+1):... | def expectation(p):
return 0.5 * sum(p) + 0.5 * len(p)
def main():
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_num = sum(p[0:k])
max_idx = 0
lst = [max_num]
for i in range(1, n-k+1):
num = lst[i-1] + p[i+k-1] - p[i-1]
lst.append(num)
if... | def calc_exp(p):
result = 0
for n in p:
result += expectation(n)
return result
def expectation(p):
n = sum(p)
return 0.5 * n + 0.5 * len(p)
def main():
n, k = map(int, input().split())
p = list(map(int, input().split()))
max_num = 0
max_idx = -1
for i in range(n-k+1):... |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, k = map(int, input().split())
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[a - 1].append(idx)
tree[idx].append(a - 1)
start = ... | import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, k = map(int, input().split())
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[idx].append(a - 1)
start = []
depth = [0 for _ in range... | import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, k = map(int, input().split())
A = list(map(int, input().split()))
tree = [[] for _ in range(n)]
for idx, a in enumerate(A):
tree[a - 1].append(idx)
tree[idx].append(a - 1)
start = ... |
import math
A, B, N = list(input().split())
A = float(A)
B = float(B)
N = int(N)
tmp_pre = 0
for i in range(1, N+1):
tmp = math.floor(A*i/B) - A*math.floor(i/B)
if tmp > tmp_pre:
tmp_pre = tmp
print(int(tmp_pre)) | A, B, N = list(map(int, input().split()))
if B==1:
print(0)
else:
tb = B - 1
tp_pre = 0
while(True):
tp = (A*tb)//B - A*(tb//B)
if tp > tp_pre:
tp_pre = tp
tb += B
if tb > N:
break
if (B > N):
print((A*N)//B - A*(N//B))
else:
print(int(tp_pre)) | import math
A, B, N = list(input().split())
A = float(A)
B = float(B)
N = int(N)
tmp_pre = 0
for i in range(1, N+1):
tmp = math.floor(A*i/B) - A*math.floor(i/B)
if tmp > tmp_pre:
tmp_pre = tmp
print(int(tmp_pre))
### FIXED CODE ###
A, B, N = list(map(int, input().split()))
if B==1:
print(0)
else:
tb = B... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 9