code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
print(len(list(set([input() for _ in range(int(input()))])))) | import math as mt
a, b, c = map(int, input().split())
d = c - a - b
if d>0 and d**2 > 4*a*b:
print("Yes")
else:
print("No")
| 0 | null | 40,979,759,364,300 | 165 | 197 |
import numpy as np
n = int(input())
li_a = list(map(int, input().split()))
m = max(li_a)
e = np.zeros(m)
dup = []
for a in li_a:
if(e[a-1]==1):
dup.append(a-1)
continue
e[a-1] = 1
for i in dup:
e[i] = 0
for a in set(li_a):
origin = a
while a <= m:
if a==origin:
a += origin
continue
e[a-1]=0
a += origin
print(int(sum(e))) | import string
n = int(input())
alphabet = list(string.ascii_lowercase)
ans = ''
while n > 0:
ans = alphabet[(n-1) % 26] + ans
n = (n-1) // 26
print(ans)
| 0 | null | 13,128,099,349,290 | 129 | 121 |
input_line = input().split()
a = int(input_line[0])
b = int(input_line[1])
if a > b:
symbol = ">"
elif a < b:
symbol = "<"
else:
symbol = "=="
print("a",symbol,"b") | #k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
n, k = map(int, input().split())
temp = [0] * n
for i in range(k):
d = int(input())
l = list(map(int, input().split()))
for j in l:
temp[j-1] += 1
ans = 0
for i in temp:
if (i == 0):
ans += 1
print (ans)
| 0 | null | 12,371,862,700,900 | 38 | 154 |
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, M = list(map(int, input().split()))
paths = [list(map(int, input().split())) for _ in range(M)]
result = solve(N, paths)
print(result)
def solve(N, paths) -> int:
uf = UnionFind(N)
for x, y in paths:
uf.union(x - 1, y - 1)
return uf.group_count() - 1
if __name__ == '__main__':
main()
| class UnionFind():
def __init__(self,size):
self.table = [-1 for _ in range(size)]
self.member_num = [1 for _ in range(size)]
#representative
def find(self,x):
while self.table[x] >= 0:
x = self.table[x]
return x
def union(self,x,y):
s1 = self.find(x)
s2 = self.find(y)
m1=self.member_num[s1]
m2=self.member_num[s2]
if s1 != s2:
if m1 != m2:
if m1 < m2:
self.table[s1] = s2
self.member_num[s2]=m1+m2
return [m1,m2]
else:
self.table[s2] = s1
self.member_num[s1]=m1+m2
return [m1,m2]
else:
self.table[s1] = -1
self.table[s2] = s1
self.member_num[s1] = m1+m2
return [m1,m2]
return [0,0]
N,M = list(map(int,input().split()))
uf = UnionFind(N)
count = 0
for i in range(M):
A,B = list(map(int,input().split()))
A,B = A-1,B-1
if uf.find(A)!=uf.find(B):
uf.union(A,B)
count+=1
B = set()
for i in range(N):
B.add(uf.find(i))
print(len(B)-1) | 1 | 2,287,022,236,100 | null | 70 | 70 |
N,M,K=map(int,input().split())
adj=[set() for _ in range(N)]
for _ in range(M):
A,B=map(int,input().split())
A,B=A-1,B-1
adj[A].add(B)
adj[B].add(A)
blk=[{*()} for _ in range(N)]
for _ in range(K):
A,B=map(int,input().split())
A,B=A-1,B-1
blk[A].add(B)
blk[B].add(A)
#print(adj)
#print(blk)
colors=[-1]*N
ct={}
color=-1
for u in range(N):
if colors[u]!=-1:
continue
color+=1
colors[u]=color
stk=[u]
while stk:
u=stk.pop()
ct[color]=ct.get(color,0)+1
for v in adj[u]:
if colors[v]==-1:
colors[v]=color
stk.append(v)
ans=[0]*N
for u in range(N):
c=colors[u]
k=ct[c]-1-len(adj[u])
for v in blk[u]:
if colors[v]==c:
k-=1
ans[u]=k
print(*ans)
| class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):#要素xが属するグループの根を返す
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):#要素xが属するグループと要素yが属するグループとを併合する
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):#要素xが属するグループのサイズ(要素数)を返す
return -self.parents[self.find(x)]
def same(self, x, y):#要素x, yが同じグループに属するかどうかを返す
return self.find(x) == self.find(y)
def members(self, x):#要素xが属するグループに属する要素をリストで返す
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):#すべての根の要素をリストで返す
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):#グループの数を返す
return len(self.roots())
def all_group_members(self):#{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
return {r: self.members(r) for r in self.roots()}
def __str__(self):#print()での表示用 ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
uf = UnionFind(N)
edge1 = []
edge2 = []
for i in range(M):
a,b = map(int,input().split())
edge1.append((a-1,b-1))
for i in range(K):
c,d = map(int,input().split())
edge2.append((c-1,d-1))
for a,b in edge1:
uf.union(a,b)
#同じグループに属する人数(自分を除く)
ans = [uf.size(i)-1 for i in range(0,N)]
for a,b in edge1:#すでに友達なら削る
ans[a] -= 1
ans[b] -= 1
for c,d in edge2:
if uf.same(c,d): #ブロック関係かつ同じグループに属しているなら
ans[c] -= 1
ans[d] -= 1
print(*ans) | 1 | 61,614,300,805,068 | null | 209 | 209 |
h = int(input())
def rc(h):
if h == 1:
return 1
t = rc(h//2)*2
return t + 1
print(rc(h)) | import math
while(1):
a=0
n=int(input())
if n==0: break;
s=list(map(int,input().split()))
m=sum(s)/len(s)
for i in range(n):
a=a+pow(s[i]-m,2)
print(math.sqrt(a/n)) | 0 | null | 40,218,636,141,980 | 228 | 31 |
n = int(input())
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]
abs_list = [abs(a-b) for a,b in zip(x,y)]
p1 = p2 = p3 = p4 = 0
for a in abs_list:
p1 += a
p2 += a**2
p3 += a**3
p2 = p2 **(1/2)
p3 = p3 **(1/3)
p4 = max(abs_list)
preanswer = [p1,p2,p3,p4]
answer = ['{:.6f}'.format(i) for i in preanswer]
for a in answer:
print(a)
| n = int(input())
x = map(float, input().strip().split())
y = map(float, input().strip().split())
d = tuple(map(lambda x,y:abs(x-y), x, y))
print(sum(d))
print(sum(map(pow, d, [2]*n))**0.5)
print(sum(map(pow, d, [3]*n))**(1/3))
print(max(d)) | 1 | 217,750,103,900 | null | 32 | 32 |
def main():
N = input()
L = len(N)
K = int(input())
dp = [[0 for _ in range(L + 1)] for _ in range(K + 1)]
dpp = [[0 for _ in range(L + 1)] for _ in range(K + 1)]
dpp[0][0] = 1
for i in range(1, L + 1):
n = int(N[i - 1])
for k in range(K + 1):
# from dpp
kk = k + (1 if n > 0 else 0)
if kk <= K:
dpp[kk][i] = dpp[k][i - 1]
if n > 0:
dp[k][i] += dpp[k][i - 1]
if k + 1 <= K:
dp[k + 1][i] += (n - 1) * dpp[k][i - 1]
# from dp
dp[k][i] += dp[k][i - 1]
if k + 1 <= K:
dp[k + 1][i] += 9 * dp[k][i - 1]
print(dp[K][L] + dpp[K][L])
if __name__ == '__main__':
main() | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce, lru_cache
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def MAP1() : return map(lambda x:int(x)-1,input().split())
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
n = INT()
k = INT()
@lru_cache(None)
def F(n, k):
# n以下で0でないものがちょうどk個ある数字の個数
if n < 10:
if k == 0:
return 1
if k == 1:
return n
return 0
q, r = divmod(n, 10)
ret = 0
if k >= 1:
ret += F(q, k-1) * r
ret += F(q-1, k-1) * (9-r)
ret += F(q, k)
return ret
print(F(n, k)) | 1 | 75,961,275,458,012 | null | 224 | 224 |
import math
n = int(input())
# nが奇数ならば必ず0
if n % 2 == 1:
print(0)
else:
s = 0
p = 0
while 10 * (5 ** p) <= n:
s += n // (10 * (5 ** p))
p += 1
print(s)
| n = int(input())
A = list(map(int,input().split()))
smallest = A[0]
ans = 0
for x in range(len(A)-1):
if A[x] > A[x+1]:
ans += A[x] - A[x+1]
A[x+1] = A[x]
print(ans)
| 0 | null | 60,466,104,610,098 | 258 | 88 |
import numpy as np
count = 0
n,d = map(int,input().split())
for _ in range(n):
p,q = map(int, input().split())
if np.sqrt(p**2+q**2) <= d:
count += 1
print(count) | n,d = map(int,input().split())
cnt = 0
md = d**2
for _ in range(n):
a,b = map(int,input().split())
if md >= (a**2+b**2):
cnt += 1
print(cnt)
| 1 | 5,907,507,205,280 | null | 96 | 96 |
n=int(input())
edges=[[] for i in range(1+n)]
e={}
for i in range(n-1):
"""#weighted->erase_,__,___=map(int,input().split())
edges[_].append((__,___))
edges[__].append((_,___))
"""
_,__=map(int,input().split())
edges[_].append(__)
edges[__].append(_)
e[(_,__)]=i
e[(__,_)]=i
"""
"""#weighted->erase
f=max(len(j)for j in edges)
print(f)
ret=[0]*(n-1)
from collections import deque
dq=deque([(1,1)])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
while dq:
a,c=dq.popleft()
for to in edges[a]:
if ret[e[(a,to)]]:continue
ret[e[(a,to)]]=c
c=c%f+1
dq.append((to,c))
print(*ret,sep="\n") | import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
def main():
n = int(input())
k = n / 3
print(k**3)
if __name__=="__main__":
main()
| 0 | null | 91,578,803,337,268 | 272 | 191 |
n = list(input())
if n[0] == "7" or n[1] == "7" or n[2] == "7":
print("Yes")
else:
print("No") | r = int(input())
answer = r ** 2
print(answer)
| 0 | null | 90,053,909,115,812 | 172 | 278 |
import string
import sys
text = sys.stdin.read().lower()
for char in string.ascii_lowercase:
print(char, ':', text.count(char))
| a = int(input())
b = a * a * a
print(b)
| 0 | null | 949,461,266,468 | 63 | 35 |
# Aizu Problem 0000: QQ
#
import sys, math, os
# read input:
#PYDEV = os.environ.get('PYDEV')
#if PYDEV=="True":
# sys.stdin = open("sample-input2.txt", "rt")
for i in range(1, 10):
for j in range(1, 10):
print("%dx%d=%d" % (i, j, i*j)) | y = 1
while y<10:
x = 1
while x<10:
print str(y)+'x'+str(x)+'='+str(y*x)
x += 1
y += 1 | 1 | 4,036,582 | null | 1 | 1 |
import numpy as np
X = int(input())
x = np.arange(-300, 300, dtype=np.int64)
x5 = x**5
diff = np.subtract.outer(x5, x5)
i = np.where(diff == X)
x, y = i[0][0], i[0][1]
x -= 300
y -= 300
print(x, -y)
| N = int(input())
a = [int(x) for x in input().split()]
def selectionSort(A, N):
count = 0
for i in range(0,N):
minj = i
for j in range(i,N):
if A[minj] > A[j]:
minj = j
if i != minj:
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
count += 1
return A,count
ans,c = selectionSort(a,N)
print(*ans)
print(c) | 0 | null | 12,919,460,648,148 | 156 | 15 |
import sys
import heapq
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N, K = inm()
A = inl()
F = inl()
A.sort()
F.sort(reverse=True)
def check(val):
k = K
for i in range(N):
tmp = A[i] * F[i]
if tmp <= val:
continue
dec = ((tmp - val) + F[i] - 1) // F[i]
assert A[i] >= dec
assert (A[i] - dec) * F[i] <= val
k -= dec
if k < 0:
return False
return True
def solve():
ng, ok = -1, max([A[i] * F[i] for i in range(N)])
while ok - ng > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
return ok
print(solve())
| N,K = map(int,input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if sum(A) <= K:
print(0)
exit()
A.sort()
F.sort(reverse=True)
def check(x):
k = 0
for a,f in zip(A, F):
k += max(0, a-(x//f))
return k <= K
# AをX以下にできるか??
ng,ok = 0, 10**18+1
while ok-ng > 1:
x = (ok+ng)//2
if check(x):
ok = x
else:
ng = x
print(ok)
| 1 | 164,831,106,579,648 | null | 290 | 290 |
n = int(input())
#n, m = map(int, input().split())
al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
mod = 10**9+7
add = 0
ans = 0
for i in range(n-1, 0, -1):
add = (add+al[i]) % mod
ans = (ans+add*al[i-1]) % mod
print(ans)
| N = int(input())
A = list(map(int, input().split()))
P = sum(A)**2
Q = 0
for i in range (0, N):
Q+=(A[i])**2
print(((P-Q)//2)%(10**9+7)) | 1 | 3,848,484,565,728 | null | 83 | 83 |
import math
N,D,A = map(int,input().split())
l = []
for i in range(N):
l.append(list(map(int,input().split())))
l.sort()
lx = []
lc = []
for i in l:
X,H = i[0],i[1]
lx.append(X)
lc.append(math.ceil(H/A))
migi = []
m = 0
i = 0
while i <= N-1:
if lx[m] - lx[i] > 2*D:
migi.append(m)
i += 1
elif m != N-1:
m += 1
elif m == N-1:
migi.append(-1)
i += 1
cnt = 0
dam = [0 for i in range(N)]
for i in range(N):
if dam[i] < lc[i]:
c = lc[i] - dam[i]
dam[i] += c
if migi[i] >= 0:
dam[migi[i]] -= c
cnt += c
if i <=N-2:
dam[i+1] += dam[i]
print(cnt) | import math
n, d, a = map(int,input().split())
e = [[] for i in range(n)]
for i in range(n):
x, h = map(int,input().split())
e[i] = [x,h]
num = 0
e.sort()
sd = [0 for i in range(n)]
l = [i for i in range(n)]
for i in range(n):
for j in range(l[i-1],i):
if e[i][0]-e[j][0] <= 2*d:
l[i] = j
break
for i in range(n):
res = e[i][1] - sd[i-1] + sd[l[i]-1]
if res < 0:
sd[i] = sd[i-1]
else:
k = math.ceil(res/a)
sd[i] = sd[i-1]+k*a
num += k
print(num)
| 1 | 81,881,114,670,252 | null | 230 | 230 |
k = int(input())
ans = 0
def gcd(a,b):
if a % b == 0:
return b
c = a % b
return gcd(b,c)
for l in range(1,k+1):
for m in range(l,k+1):
for n in range(m,k+1):
tmp1 = gcd(l,n)
tmp2= gcd(tmp1,m)
if (l==m==n):
ans+=tmp2
elif(l==m or m==n):
ans+= 3*tmp2
else:
ans += 6*tmp2
print(ans) | n = input()
i = 1
num = []
while i <= n:
if i % 3 == 0:
num.append(i)
i +=1
else:
x = i
while x > 0:
if x % 10 == 3:
num.append(i)
break
else:
x /= 10
i += 1
print("{}".format(str(num)).replace("["," ").replace("]","").replace(",","")) | 0 | null | 18,210,296,547,520 | 174 | 52 |
# A - DDCC Finals
def main():
X, Y = map(int, input().split())
prize = 0
for i in (X, Y):
if i == 1:
prize += 300000
elif i == 2:
prize += 200000
elif i == 3:
prize += 100000
if X == Y and X == 1:
prize += 400000
print(prize)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
n, x, m = map(int, input().split())
ans = 0
aa = x
ans += aa
aset = set([aa])
alist = [aa]
for i in range(1,n):
aa = pow(aa,2,m)
if aa in aset:
offset = alist.index(aa)
loop = alist[offset:i]
nloop, tail = divmod(n-offset, len(loop))
ans += sum(loop)*(nloop-1)
ans += sum(loop[0:tail])
break
else:
ans += aa
aset.add(aa)
alist.append(aa)
print(ans)
| 0 | null | 71,769,212,909,218 | 275 | 75 |
n = int(input())
s = [input() for _ in range(n)]
print(len(list(set(s)))) | import sys
from io import StringIO
import unittest
import os
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def prepare_simple(n, mod=pow(10, 9) + 7):
# n! の計算
f = 1
for m in range(1, n + 1):
f *= m
f %= mod
fn = f
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return fn, invs
def prepare(n, mod=pow(10, 9) + 7):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= mod
factorials.append(f)
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return factorials, invs
# 実装を行う関数
def resolve(test_def_name=""):
x, y = map(int, input().split())
all_move_count = (x + y) // 3
x_move_count = all_move_count
y_move_count = 0
x_now = all_move_count * 2
y_now = all_move_count
canMake= False
for i in range(all_move_count+1):
if x_now == x and y_now == y:
canMake = True
break
x_move_count -= 1
y_move_count += 1
x_now -= 1
y_now += 1
if not canMake:
print(0)
return
fns, invs = prepare(all_move_count)
ans = (fns[all_move_count] * invs[x_move_count] * invs[all_move_count - x_move_count]) % (pow(10, 9) + 7)
print(ans)
# fn, invs = prepareSimple(10)
# ans = (fn * invs[3] * invs[10 - 3]) % (pow(10, 9) + 7)
# print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 3"""
output = """2"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """2 2"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """999999 999999"""
output = """151840682"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 0 | null | 90,178,709,975,422 | 165 | 281 |
from sys import stdin
input = stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
order = sorted(range(1, N+1), key=lambda i: A[i-1])
print(*order, sep=' ')
if(__name__ == '__main__'):
main()
| import itertools as it
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
r = list(it.permutations(range(1, n+1)))
a = 0
b = 0
for i in range(len(r)):
if r[i] == p:
a = i
if r[i] == q:
b = i
print(abs(a-b))
| 0 | null | 140,316,996,603,872 | 299 | 246 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N = int(readline())
S = readline().strip()
ans = 0
for i in range(N - 2):
if S[i : i + 3] == 'ABC':
ans += 1
print(ans)
return
if __name__ == '__main__':
main()
| #import numpy as np
#import math
#from decimal import *
#from numba import njit
#@njit
def main():
N = int(input())
A = list(map(int, input().split()))
A = sorted(enumerate(A), key = lambda x: x[1])[::-1]
#dp = np.zeros((N+1,N+1), dtype='int64')
dp = [[0]*(N+1-i) for i in range(N+1)]
m = 0
for i in range(1,len(A)+1):
index,a = A[i-1]
for j in range(i+1):
if (i-j,j) == (0,0):
dp[i-j][j] = 0
elif i-j == 0:
dp[i-j][j] = dp[i-j][j-1] + (N-j-index)*a
elif j == 0:
dp[i-j][j] = dp[i-j-1][j] + (abs(index-(i-j-1)))*a
else:
dp[i-j][j] = max(dp[i-j][j-1] + (N-j-index)*a, dp[i-j-1][j] + (abs(index-(i-j-1)))*a)
if i == len(A):
m = max(m, dp[i-j][j])
#print(dp)
#print(np.max(dp))
print(m)
main()
| 0 | null | 66,881,912,887,648 | 245 | 171 |
from sys import stdin
operate = {
'+': lambda lhs, rhs: lhs + rhs,
'-': lambda lhs, rhs: lhs - rhs,
'*': lambda lhs, rhs: lhs * rhs,
'/': lambda lhs, rhs: lhs // rhs,
}
while True:
arr = (stdin.readline().rstrip().split())
a, op, b = int(arr[0]), arr[1], int(arr[2])
if op == '?':
break
answer = operate[op](a, b)
print(answer)
| # -*- coding: utf-8 -*-
import sys
import os
#input_text_path = __file__.replace('.py', '.txt')
#fd = os.open(input_text_path, os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())
a, b = list(map(int, input().split()))
if a > b:
print('a > b')
elif a == b:
print('a == b')
else:
print('a < b') | 0 | null | 529,960,038,440 | 47 | 38 |
w = input().lower()
count = 0
while True:
s = input()
if s == "END_OF_TEXT":
break
count += s.lower().split().count(w)
print(count) | n = int(input())
dp = [0] * (n + 1)
for x in range(1, n + 1):
for y in range(x, n + 1, x):
dp[y] += 1
print(sum(dp[1:n])) | 0 | null | 2,192,209,475,510 | 65 | 73 |
import math
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
a,b=MI()
print(max(0,a-2*b))
| a = input().split()
if int(a[0]) <= int(a[1]) * 2:
print("0")
else:
print(int(int(a[0]) - int(a[1]) * 2)) | 1 | 166,226,122,310,428 | null | 291 | 291 |
import math
n=int(input())
m=((10**n)-(2*(9**n))+(8**n))%1000000007
print(m)
| mod = 1000000007
n = int(input())
ans = pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod)
print(ans % mod)
| 1 | 3,136,775,875,090 | null | 78 | 78 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(input())
l1=[]
l2=[]
for i in range(n):
a,b=nii()
l1.append(a)
l2.append(b)
l1.sort()
l2.sort()
if n%2==1:
ans=l2[n//2]-l1[n//2]
else:
m1=(l2[n//2]+l2[n//2-1])
m2=(l1[n//2]+l1[n//2-1])
ans=m1-m2
print(ans+1) | N = int(input())
t = N//2
la, lb = [], []
for _ in range(N):
A, B = map(int, input().split())
la.append(A)
lb.append(B)
la.sort()
lb.sort()
print(lb[t]-la[t]+1 if N%2 else lb[t-1]-la[t]+lb[t]-la[t-1]+1)
| 1 | 17,269,373,958,372 | null | 137 | 137 |
class uf():
def __init__(self,n):
self.size=n
self.parents=list(range(n))
def find(self,x):
if self.parents[x]==x:
return x
self.parents[x]=self.find(self.parents[x])
return self.find(self.parents[x])
def union(self,a,b):
x=self.find(a)
y=self.find(b)
if x==y:
return
if x>y:
x,y=y,x
self.parents[y]=x
def roots(self):
s=0
for c in range(self.size):
if self.find(c)==c:
s+=1
return s-1
n,m=map(int,input().split())
city=uf(n)
for c in range(m):
a,b=map(int,input().split())
a-=1
b-=1
city.union(a,b)
print(city.roots()) | import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
import os
import re
with open(__file__) as f:
source = f.read().split('###''nbacl')
for s in source[1:]:
s = re.sub("'''.*", '', s)
sp = s.split(maxsplit=1)
if os.path.dirname(sp[0]):
os.makedirs(os.path.dirname(sp[0]), exist_ok=True)
with open(sp[0], 'w') as f:
f.write(sp[1])
from nbmodule import cc
cc.compile()
import numpy as np
from numpy import int64
from nbmodule import solve
f = open(0)
N, M = [int(x) for x in f.readline().split()]
AB = np.fromstring(f.read(), dtype=int64, sep=' ').reshape((-1, 2))
ans = solve(N, AB)
print(ans)
'''
###nbacl nbmodule.py
import numpy as np
from numpy import int64
from numba import njit
from numba.types import i8
from numba.pycc import CC
import nbacl.dsu as dsu
cc = CC('nbmodule')
@cc.export('solve', (i8, i8[:, ::1]))
def solve(N, AB):
t = np.full(N, -1, dtype=int64)
for i in range(AB.shape[0]):
dsu.merge(t, AB[i, 0] - 1, AB[i, 1] - 1)
ret = 0
for _ in dsu.groups(t):
ret += 1
return ret - 1
if __name__ == '__main__':
cc.compile()
###nbacl nbacl/dsu.py
import numpy as np
from numpy import int64
from numba import njit
@njit
def dsu(t):
t = -1
@njit
def merge(t, x, y):
u = leader(t, x)
v = leader(t, y)
if u == v:
return u
if -t[u] < -t[v]:
u, v = v, u
t[u] += t[v]
t[v] = u
return u
@njit
def same(t, x, y):
return leader(t, x) == leader(t, y)
@njit
def leader(t, x):
if t[x] < 0:
return x
t[x] = leader(t, t[x])
return t[x]
@njit
def size(t, x):
return -t[leader(t, x)]
@njit
def groups(t):
for i in range(t.shape[0]):
if t[i] < 0:
yield i
''' | 1 | 2,291,872,463,438 | null | 70 | 70 |
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
N = II()
A = LMIIS()
print('YES' if len(A) == len(set(A)) else 'NO')
if __name__ == '__main__':
main() | n = int(input())
sum = 0
for i in range(1, n+1):
if((i % 3 * i % 5 * i % 15) != 0):
sum += i
print(sum) | 0 | null | 54,745,416,725,490 | 222 | 173 |
R = int(input())
print(2 * R * 3.14159265359) | T=input()
print(T.replace("?","D"))
| 0 | null | 24,798,756,811,620 | 167 | 140 |
n, m = map(int, input().split())
a = map(int, input().split())
res = n - sum(a)
if res < 0:
print(-1)
else:
print(res) | # 163_b
N,M=map(int,input().split())
A=input().split()
for i in range(len(A)):
A[i]=int(A[i])
if (1<=N and N<=10**6)and(1<=M and M<= 10**4):
for j in range(len(A)):
N-=A[j]
if N >= 0:
print(N)
if N < 0:
print('-1') | 1 | 31,966,026,142,470 | null | 168 | 168 |
D,T,S = map(int, input().split())
if T-D/S >= 0:
print("Yes")
else:
print("No") | import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy
def main():
d,t,s = map(int, input().split())
if d <= t*s:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 1 | 3,583,267,383,618 | null | 81 | 81 |
n = int(input())
c = list(input())
r = 0
w = 0
for i in range(len(c)):
if(c[i]=="R"):
r += 1
ans = max(r,w)
for i in range(len(c)):
if(c[i]=="R"):
r -= 1
else:
w += 1
now = max(r,w)
ans = min(ans,now)
print(ans) | N = int(input())
c = input()
num_red = c.count('R')
print(num_red - c[:num_red].count('R')) | 1 | 6,368,624,363,712 | null | 98 | 98 |
import math
def primes(N):
p = [False, False] + [True] * (N - 1)
for i in range(2, int(N ** 0.5) + 1):
if p[i]:
for j in range(i * 2, N + 1, i):
p[j] = False
return [i for i in range(N + 1) if p[i]]
N = int(input())
A = list(map(int, input().split()))
maxA = max(A) + 1
g, Ac = A[0], [0] * maxA
P = primes(maxA)
for a in A:
Ac[a] += 1
ans = "pairwise"
for p in P:
if sum(Ac[p:maxA:p]) > 1:
ans = "setwise"
for a in A:
g = math.gcd(g, a)
print(ans if g == 1 else "not", "coprime")
| from sys import stdin
n = int(stdin.readline().rstrip())
x = [float(x) for x in stdin.readline().rstrip().split()]
y = [float(x) for x in stdin.readline().rstrip().split()]
def minkowski_dist(x, y, p="INF"):
if p == "INF":
return max([abs(x[i]-y[i]) for i in range(n)])
elif isinstance(p, int):
return (sum([(abs(x[i]-y[i]))**p for i in range(n)]))**(1/p)
print(minkowski_dist(x, y, 1))
print(minkowski_dist(x, y, 2))
print(minkowski_dist(x, y, 3))
print(minkowski_dist(x, y))
| 0 | null | 2,137,274,114,492 | 85 | 32 |
INF = 1 << 60
n = int(input())
x = [0 for i in range(n)]
l = [0 for i in range(n)]
for i in range(n):
x[i], l[i] = map(int, input().split())
itv = [[x[i] - l[i], x[i] + l[i]] for i in range(n)]
itv.sort(key=lambda x:x[1])
# print("itv =", itv)
ans = 0
t = -INF
for i in range(n):
if t <= itv[i][0]:
ans += 1
t = itv[i][1]
print(ans)
| N = int(input())
X = []
L = []
for i in range(N):
x, l = map(int, input().split())
X.append(x)
L.append(l)
# できるだけ少ないロボットを取り除いて条件を満たすようにしたい
ranges = [[x - l, x + l] for x, l in zip(X, L)]
ranges = sorted(ranges, key=lambda x:x[1])
ans = N
for i in range(1, N):
if ranges[i][0] < ranges[i - 1][1]:
ranges[i][1] = ranges[i - 1][1]
ans -= 1
print(ans)
| 1 | 89,879,432,642,538 | null | 237 | 237 |
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
sys.setrecursionlimit(100000000)
def input(): return sys.stdin.readline().rstrip()
N, K, C = map(int, input().split())
S = input()
L = [None] * K
R = [None] * K
i = 0
for j in range(N):
if S[j] == 'o' and i < K and (i == 0 or j - L[i - 1] > C):
L[i] = j
i += 1
i = K - 1
for j in reversed(range(N)):
if S[j] == 'o' and i >= 0 and (i == K - 1 or R[i + 1] - j > C):
R[i] = j
i -= 1
for l, r in zip(L, R):
if l == r:
print(l + 1)
| # import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, ABs):
tree_top = [[] for _ in range(N + 1)]
for i in range(N - 1):
tree_top[ABs[i][0]].append(i)
tree_top[ABs[i][1]].append(i)
max_color = 0
for tt in tree_top:
max_color = max(max_color, len(tt))
ans = [0 for _ in range(N - 1)]
for tt in tree_top:
colored = []
for i in tt:
if ans[i] != 0:
colored.append(ans[i])
colored.sort()
now_color = 1
colored_point = 0
for i in tt:
if ans[i] != 0:
continue
if colored_point < len(colored) \
and now_color == colored[colored_point]:
now_color += 1
colored_point += 1
ans[i] = now_color
now_color += 1
print(max_color)
for a in ans:
print(a)
if __name__ == '__main__':
# S = input()
N = int(input())
# N, M = map(int, input().split())
# As = [int(i) for i in input().split()]
# Bs = [int(i) for i in input().split()]
ABs = [[int(i) for i in input().split()] for _ in range(N - 1)]
solve(N, ABs)
| 0 | null | 88,654,289,464,872 | 182 | 272 |
"""
Given N, D, A, N means no. of monsters, D means distances of bombs, A attack of the bombs
Find the minimum of bombs required to win.
Each monster out of N pairs - pair[0] = position, pair[1] = health
"""
from collections import deque
mod = 1e9+7
def add(a, b):
c = a + b
if c >= mod:
c -= mod
return c
def main():
N, D, A = [int(x) for x in raw_input().split()]
D *= 2
monsters = []
for _ in range(N):
pos, health = [int(x) for x in raw_input().split()]
monsters.append([pos, health])
monsters.sort(key = lambda x : x[0])
remain_attacks_queue = deque([])
remain_attack = 0
ans = 0
for monster in monsters:
# monster[0] - pos, monster[1] - health
# queue[0] - position, queue[1] - attack points
while len(remain_attacks_queue) and monster[0] - D > remain_attacks_queue[0][0]:
remain_attack -= remain_attacks_queue.popleft()[1]
if remain_attack < monster[1]:
remained_health = monster[1] - remain_attack
times = remained_health / A if remained_health % A == 0 else remained_health // A + 1
#print(times)
attack = times * A
remain_attacks_queue.append([monster[0], attack])
ans += times
remain_attack += attack
print(ans)
main() | from bisect import bisect_left
def main():
n, dis, dam = map(int, input().split())
mon = [list(map(int, input().split())) for _ in range(n)]
mon.sort(key=lambda x: x[0])
p = [v[0] for v in mon]
imos = [0]*(n+1)
dis = 2*dis + 1
ans = 0
for i in range(n):
if 0 < i:
imos[i] += imos[i-1]
if imos[i] < mon[i][1]:
tmp = (mon[i][1] - imos[i] + dam - 1) // dam
ans += tmp
tmp *= dam
imos[i] += tmp
idx = bisect_left(p, p[i]+dis)
imos[idx] -= tmp
print(ans)
if __name__ == "__main__":
main() | 1 | 82,252,663,806,910 | null | 230 | 230 |
dice = [int(i) for i in input().split()]
directions = str(input())
for direction in directions:
if direction == "N":
dice = [dice[1], dice[5], dice[2], dice[3], dice[0], dice[4]]
elif direction == "S":
dice = [dice[4], dice[0], dice[2], dice[3], dice[5], dice[1]]
elif direction == "E":
dice = [dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]]
else:
dice = [dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]]
print(dice[0])
| import sys
import collections
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
n = int(input())
#b , c = tin()
#s = input()
al = lin()
aal=[i-v for i,v in enumerate(al)]
ccl = collections.Counter(aal)
ret = 0
for i, v in enumerate(al):
ccl[i-v] -= 1
if i+v in ccl:
ret += ccl[i+v]
print(ret)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret) | 0 | null | 13,099,380,571,680 | 33 | 157 |
l,r,f = map(int,input().split())
count = 0
for i in range(l,r+1):
if i % f == 0 :
count = count + 1
print(count) | # -*- coding: utf-8 -*-
# 標準入力を取得
L, R, d = list(map(int, input().split()))
# 求解処理
ans = R // d - (L - 1) // d
# 結果出力
print(ans)
| 1 | 7,532,616,035,660 | null | 104 | 104 |
n=int(input())
s={}
for i in range(n):
si = input()
if si not in s:
s[si] = 1
else:
s[si]+=1
sa = sorted(s.items())
ma = max(s.values())
for a in sorted(a for a in s if s[a]==ma):
print(a) | #!/usr/bin/env python3
def main():
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for s in S:
d[s] += 1
# d = sorted(d.items())
d = sorted(d.items(), key=lambda d: d[1], reverse=True)
res = d[0][1]
lst = []
for i in d:
if res > i[1]:
break
lst.append(i[0])
res = i[1]
for i in sorted(lst):
print(i)
if __name__ == '__main__':
main()
| 1 | 70,037,481,604,530 | null | 218 | 218 |
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a * b // gcd(a, b)
n = int(input())
a = list(map(int, input().split(" ")))
alcm = a[0]
for i in a:
alcm = lcm(alcm, i)
tot = 0
for num in a:
tot += alcm // num
print(tot % 1000000007)
| def gcd(n, m):
if m == 0:
return n
return gcd(m, n % m)
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
kbs = A[0]
for i in range(1,N):
kbs = kbs*A[i]//gcd(kbs,A[i])
kbs %= mod
ans = 0
for i in range(N):
ans += pow(A[i],mod-2,mod)
ans %= mod
print(kbs*ans%mod) | 1 | 87,921,689,866,162 | null | 235 | 235 |
N = int(input())
A = list(map(int, input().split()))
i = 0
for i in range(len(A)):
if (A[i] % 2 == 0):
if A[i] % 3 != 0 and A[i] % 5 != 0:
print('DENIED')
exit()
else:
continue
else:
continue
print('APPROVED') | n = int(input())
a = list(map(int,input().split(" ")))
answer = 0
for i in range(1,n):
if a[i] < a[i - 1]:
answer += a[i-1] - a[i]
a[i]= a[i - 1]
print(answer) | 0 | null | 36,578,870,102,400 | 217 | 88 |
import os, sys, re, math
(N, K) = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]
H = sorted(H, reverse=True)[K:]
print(sum(H))
| def main():
n, k = map(int, input().split())
h_list = list(map(int, input().split()))
h_list.sort(reverse=True)
if n <= k:
ans = 0
else:
ans = sum(h_list[k:])
print(ans)
if __name__ == "__main__":
main()
| 1 | 78,806,057,468,974 | null | 227 | 227 |
# -*- coding:utf-8 -*-
import sys
import math
array =[]
for line in sys.stdin:
array.append(line)
for i in range(len(array)):
num = array[i].split(' ')
a = int(num[0])
b = int(num[1])
n = a + b
print(int(math.log10(n) + 1)) | class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def same(self, x, y):
return self.find(x) == self.find(y)
N, M = map(int, input().split())
u = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
u.union(a, b)
h = {}
for i in range(N):
h[u.find(i)] = True
print(len(h)-1)
| 0 | null | 1,151,708,710,950 | 3 | 70 |
n = int(input())
A = []
B = []
for i in range(n):
a,b = list(map(int, input().split()))
A.append(a)
B.append(b)
A.sort()
B.sort()
j = n//2
if n%2 == 0:
print((B[j]+B[j-1])-(A[j]+A[j-1])+1)
else:
print(B[j]-A[j]+1) | import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
N = INT()
A = [0] * N
B = [0] * N
for i in range(N):
A[i], B[i] = MAP()
A.sort()
B.sort()
if N % 2 == 0:
mn = (A[N//2-1]+A[N//2]) / 2
mx = (B[N//2-1]+B[N//2]) / 2
ans = int((mx-mn)*2) + 1
else:
mn = A[N//2]
mx = B[N//2]
ans = (mx-mn) + 1
print(ans)
| 1 | 17,278,262,544,932 | null | 137 | 137 |
N = int(input())
A = sorted(list(map(int,input().split())))
ans = A[0]
if ans == 0:
print(ans)
exit()
else:
for i in range(1,N):
ans = ans * A[i]
if ans > 10**18:
ans = -1
break
print(ans) | n = int(input())
a = list(map(int,input().split()))
dota = 1
if 0 in set(a):
dota = 0
else:
for ai in a:
dota *= ai
if dota > 10**18:
dota = -1
break
print(dota) | 1 | 16,199,005,915,520 | null | 134 | 134 |
n,m = map(int,input().split())
if 0 < n and n < 10 and 0 < m and m < 10:
print(n*m)
else:
print(-1) | # -*- coding: utf-8 -*-
while True:
x, y = map(int, raw_input().split())
if x+y:
if x < y:
print "%d %d" %(x, y)
else:
print "%d %d" %(y, x)
else:
break; | 0 | null | 79,333,921,121,500 | 286 | 43 |
from collections import deque
n, d, a = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(n)]
XH.sort()
# X:座標、 C:倒すための必要爆発回数
XC = [[x, (h - 1) // a + 1] for x, h in XH]
q = deque([])
accum_dmg = 0
ans = 0
for x, c in XC:
# q[-][0]は爆発が届く右端の座標
# 爆発が届いていない地点に来たら累積ダメージを減らす
while q and x > q[0][0]:
_, dmg = q.popleft()
accum_dmg -= dmg
cnt = max(0, c - accum_dmg)
ans += cnt
accum_dmg += cnt
if cnt:
q.append([x + 2 * d, cnt])
print(ans) | import math
r = float(input())
print("{:.6f}".format(r*r*math.pi), "{:.6f}".format(2*r*math.pi))
| 0 | null | 41,219,987,923,030 | 230 | 46 |
a,b,x=list(map(int,input().split()))
import math
x=x/a
if a*b/2<x:
print(math.degrees(math.atan(2*(a*b-x)/a**2)))
else:
print(math.degrees(math.atan(b**2/(2*x)))) | import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop
input = sys.stdin.buffer.readline
def sRaw():
return input().rstrip("\r")
def iRaw():
return int(input())
def ssRaw():
return input().split()
def isRaw():
return list(map(int, ssRaw()))
INF = 1 << 29
DIV = (10**9) + 7
#DIV = 998244353
def mod_inv_prime(a, mod=DIV):
return pow(a, mod-2, mod)
def mod_inv(a, b):
r = a
w = b
u = 1
v = 0
while w != 0:
t = r//w
r -= t*w
r, w = w, r
u -= t*v
u, v = v, u
return (u % b+b) % b
def CONV_TBL(max, mod=DIV):
fac, finv, inv = [0]*max, [0]*max, [0]*max
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, max):
fac[i] = fac[i-1]*i % mod
inv[i] = mod - inv[mod % i] * (mod//i) % mod
finv[i] = finv[i-1]*inv[i] % mod
class CONV:
def __init__(self):
self.fac = fac
self.finv = finv
pass
def ncr(self, n, k):
if(n < k):
return 0
if(n < 0 or k < 0):
return 0
return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
return CONV()
def cumsum(As):
s = 0
for a in As:
s += a
yield s
sys.setrecursionlimit(200005)
def dijkstra(G,start=0):
heap = []
cost = [INF]*len(G)
heappush(heap,(0,start))
while len(heap)!=0:
c,n = heappop(heap)
if cost[n] !=INF:
continue
cost[n]=c
for e in G[n]:
ec,v = e
if cost[v]!=INF:
continue
heappush(heap,(ec+c,v))
return cost
def main():
R,C,K = isRaw()
mas = [[0 for _ in range(C)]for _ in range(R)]
for k in range(K):
r,c,v = isRaw()
mas[r-1][c-1]=v
dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)]
dp0 = dp[0]
dp1 = dp[1]
dp2 = dp[2]
dp0[0][0]=mas[0][0]
dp1[0][0]=mas[0][0]
dp2[0][0]=mas[0][0]
for r in range(R):
for c in range(C):
mrc = mas[r][c]
dp0[r][c] = mrc
dp1[r][c] = mrc
dp2[r][c] = mrc
if r>0:
dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
if c>0:
dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)
print(max([dp[ni][-1][-1] for ni in range(3)]))
main()
| 0 | null | 84,454,641,769,300 | 289 | 94 |
x = list(map(int,input().split()))
ans = 0
for y in x:
if y == 1:
ans+=3
elif y == 2:
ans+=2
elif y == 3:
ans+=1
if sum(x)==2:
ans += 4
print(ans * 100000) | N, X, M = map(int, input().split())
flag = [False for _ in range(M)]
record = list()
record.append(X)
flag[X] = 1
An = X
for i in range(M + 1):
An = pow(An, 2, M)
if flag[An]:
start = flag[An]
cnt = i + 2 - start
cost = record[-1] - record[start - 2] if start > 1 else record[-1]
break
else:
record.append(An + record[-1])
flag[An] = i + 2
if start >= N:
print(record[N - 1])
else:
print(((N - start) // cnt) * cost
+ record[(N - start) % cnt + start - 1])
| 0 | null | 71,359,129,375,404 | 275 | 75 |
S = int(input())
mod = 10**9 + 7
MN = 3
N = S//3 + S % 3
dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
for j in range(0, (i-3)+1):
dp[i] += dp[j]
dp[i] %= mod
print(dp[S]) | s = input()
cnt = 0
if s == 'RSR':
cnt = 1
else:
for i in range(3):
if s[i] == 'R':
cnt += 1
print(cnt) | 0 | null | 4,081,624,207,840 | 79 | 90 |
n = int(input())
a = [n]
if n != 2:
a.append(n - 1)
def div_(N, k):
while N % k == 0:
N /= k
if N % k == 1:
a.append(k)
for k in range(2, int(n ** 0.5) + 1):
if n % k == 0:
div_(n,k)
if k != n / k:
div_(n, n // k)
if (n - 1) % k == 0:
a.append(k)
if k != (n - 1) / k:
a.append((n - 1) // k)
print(len(a)) | def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
n = int(input())
l = make_divisors(n - 1)
l2 = make_divisors(n)
del l2[0]
ans = len(l) - 1
for i in l2:
k2 = n
while True:
if k2 % i == 1:
ans += 1
k2 /= i
if k2 % 1 != 0:
break
print(ans) | 1 | 41,374,243,171,866 | null | 183 | 183 |
N = int(input())
if N%2==1:
print(0)
else:
counter = 0
tmp = 1
while True:
tmp *= 5
if tmp>N:
print(counter)
break
counter += N//(tmp*2) | import numpy as np
n = int(input())
count = np.zeros(n, dtype=np.int)
for d in range(1, n):
count[d::d] += 1
print(count.sum()) | 0 | null | 59,544,754,177,920 | 258 | 73 |
s = input()
for _ in range(int(input())):
o = input().split()
a, b = map(int, o[1:3])
b += 1
c = o[0][2]
if c == 'p':
s = s[:a]+o[3]+s[b:]
elif c == 'i':
print(s[a:b])
elif c == 'v':
s = s[:a]+s[a:b][::-1]+s[b:]
| import sys
input = sys.stdin.readline
def main():
text = input().rstrip()
n = int(input().rstrip())
for i in range(n):
s = input().split()
if s[0] == "print":
print(text[int(s[1]):int(s[2])+1])
elif s[0] == "replace":
new_text = ""
new_text += text[:int(s[1])]
new_text += s[3]
new_text += text[int(s[2])+1:]
text = new_text
elif s[0] == "reverse":
new_text = ""
new_text += text[:int(s[1])]
for i in range(int(s[2])-int(s[1]) + 1):
new_text += text[int(s[2]) - i]
new_text += text[int(s[2])+1:]
text = new_text
if __name__ == "__main__":
main()
| 1 | 2,084,716,736,516 | null | 68 | 68 |
n, k = map(int, input().split())
ans = 1
while(True):
n = n//k
if(n == 0):
break
ans += 1
print(ans) | T=input()
for i in range(len(T)):
T=T.replace(T[i],'x')
print(T) | 0 | null | 68,359,190,259,520 | 212 | 221 |
N = int(input())
hen = []
hen = list(int(x) for x in input().split())
hen.sort()
#print(hen)
#hen_u = set(hen)
#print(hen_u)
tri = 0
for a in hen:
for b in hen:
if(a == b)or (a > b):
continue
for c in hen:
if(a == c)or(b == c) or (a > c) or (b > c):
continue
if(a+b >c)and(b+c >a)and(c+a >b):
tri += 1
print(tri) | N = int(input())
L = list(map(int, input().split()))
counter = 0
if N < 3:
print(counter)
else:
for x in range(0, N - 2):
for y in range(x + 1, N):
for z in range(y + 1, N):
if L[x] != L[y] and L[x] != L[z] and L[y] != L[z]:
if L[x] + L[y] > L[z] and L[x] + L[z] > L[y] and L[y] + L[z] > L[x]:
counter += 1
print(counter)
| 1 | 5,011,516,226,820 | null | 91 | 91 |
N,K = map(int,input().split())
h = list(map(int,input().split()))
cnt = 0
hei = 0
for i in range(N):
hei = h[i]
if hei >= K:
cnt += 1
print(cnt) | # -*- coding: utf-8 -*-
n, k = map(int, input().split())
cnt = 0
h = list(map(int, input().split()))
for high in h:
if high >= k:
cnt += 1
print(cnt)
| 1 | 179,493,909,040,992 | null | 298 | 298 |
import sys
input = sys.stdin.readline
N = [int(x) for x in input().rstrip()][::-1] + [0]
L = len(N)
dp = [[10 ** 18, 10 ** 18] for _ in range(L)]
dp[0] = [N[0], 10 - N[0]]
for i in range(1, L):
n = N[i]
dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (n + 1))
dp[i][1] = min(dp[i - 1][0] + (10 - n), dp[i - 1][1] + (10 - (n + 1)))
print(dp[-1][0]) | import sys
input = sys.stdin.readline
N = [int(x) for x in input().rstrip()][::-1] + [0]
L = len(N)
dp = [[10 ** 18, 10 ** 18] for _ in range(L + 1)]
dp[0] = [0, 0]
dp[1] = [N[0], 10 - N[0]]
for i in range(2, L + 1):
n = N[i - 1]
dp[i][0] = min(dp[i - 1][0] + n, dp[i - 1][1] + (n + 1))
dp[i][1] = min(dp[i - 1][0] + (10 - n), dp[i - 1][1] + (10 - (n + 1)))
print(dp[-1][0])
| 1 | 70,925,008,154,092 | null | 219 | 219 |
N=int(input())
print(sum((N-1)//a for a in range(1,N+1)))
| import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
n = int(input())
sieve = list(range(n + 1))
primes = []
for i in range(2, n + 1):
if sieve[i] == i:
primes.append(i)
for p in primes:
if p * i > n or sieve[i] < p:
break
sieve[p * i] = p
ans = 0
for i in range(1, n):
C = Counter()
while i > 1:
C[sieve[i]] += 1
i //= sieve[i]
score = 1
for val in C.values():
score *= val + 1
ans += score
print(ans)
resolve() | 1 | 2,574,768,939,158 | null | 73 | 73 |
n,k,c = map(int,input().split())
S = list(input())
L = [0]*k
nx = -1
cnt = 0
for i,s in enumerate(S):
if i <=nx: continue
if s =='o':
L[cnt] = i
nx = i + c
cnt += 1
if cnt ==k: break
R = [0]*k
nx = -1
cnt = 0
for i,s in enumerate(S[::-1]):
if i <=nx: continue
if s =='o':
R[cnt] = n-i-1
nx = i + c
cnt += 1
if cnt ==k: break
for l,r in zip(L,R[::-1]):
if l ==r:print(l+1) | # input
N, K, C = map(int, input().split())
S = input()
# process
l = [i+1 for i in range(N) if S[i] == 'o']
left = [l[0]]
right = [l[-1]]
for i in range(1, len(l)):
if l[i] > left[-1]+C:
left.append(l[i])
if l[-i-1] < right[-1]-C:
right.append(l[-i-1])
# output
# print(l)
# print(left)
# print(right)
if len(left) == K:
for i in range(len(left)):
if left[i] == right[-i-1]:
print(left[i])
| 1 | 40,491,990,250,980 | null | 182 | 182 |
d,t,s = input().split()
if(int(s) * int(t) >= int(d)):
print('Yes')
else:
print('No') | n = int(input())
l = list(map(int, input().split()))
ans = [0]*n
for i in l:
ans[i-1] += 1
print("\n".join(map(str,ans)))
| 0 | null | 18,013,195,295,442 | 81 | 169 |
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
minj=i
for j in range(i,n):
if a[j]<a[minj]:
j,minj=minj,j
if i!=minj:
a[i],a[minj]=a[minj],a[i]
ans+=1
print(' '.join(map(str,a)))
print(ans)
| S = input()
l = len(S)
a = ''
for i in range(len(S)):
a = a + 'x'
print(a) | 0 | null | 36,327,133,587,442 | 15 | 221 |
MON = list(map(int,input().split()))
while 1:
MON[2] = MON[2] - MON[1]
if(MON[2] <= 0):
print("Yes")
break
MON[0] = MON[0] - MON[3]
if (MON[0] <= 0 ):
print("No")
break | A, B, C, D = list(map(int, input().split()))
import math
if math.ceil(A / D) >= math.ceil(C / B):
print('Yes')
else:
print('No') | 1 | 29,737,946,057,180 | null | 164 | 164 |
def i():
return int(input())
def i2():
return map(int,input().split())
def s():
return str(input())
def l():
return list(input())
def intl():
return list(int(k) for k in input().split())
n = i()
a = intl()
for i in range(n):
if a[i]%2 == 0:
if a[i]%3 != 0 and a[i]%5 !=0:
print("DENIED")
exit()
print("APPROVED") | n = int(input())
lst = list(map(int,input().split()))
c = 0
for i in range(n):
if (lst[i]%2 == 0):
if (lst[i]%3 != 0 and lst[i]%5 != 0):
c = 1
if (c == 0):
print("APPROVED")
else:
print("DENIED")
| 1 | 68,814,962,468,900 | null | 217 | 217 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
ST = [tuple(map(str,S().split())) for _ in range(N)]
X = S()
ans = 0
for i in range(N):
s,t = ST[i]
ans += int(t)
if s == X:
break
print(sum(int(ST[i][1]) for i in range(N))-ans)
| n=int(input())
s=[""]*n
t=[0]*n
for i in range(n):
s[i],t[i]=input().split()
t[i]=int(t[i])
x=input()
c=0
for i in range(n):
if s[i]==x:
c=i
break
ans=0
for i in range(c+1,n):
ans+=t[i]
print(ans) | 1 | 97,302,226,842,740 | null | 243 | 243 |
S = input()
mod = 2019
array = []
for i in range(len(S)):
x = (int(S[len(S)-1-i])*pow(10,i,mod))%mod
array.append(x)
array2 = [0]
y = 0
for i in range(len(S)):
y = (y+array[i])%mod
array2.append(y)
array3 = [0] * 2019
ans = 0
for i in range(len(array2)):
z = array2[i]
ans += array3[z]
array3[z] += 1
print(ans)
#3*673
| import collections
s = input()
mod = 2019
n = len(s)
t = [0]*(n+1)
for i in range(1,n+1):
t[i] = (t[i-1] + int(s[n-i]) * pow(10, i-1, mod)) % mod
c = collections.Counter(t)
num = c.values()
ans = 0
for i in num:
ans += i*(i-1) // 2
print(ans) | 1 | 30,705,712,699,292 | null | 166 | 166 |
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
dp=[0]*N
data={'r':P,'s':R,'p':S}
ans=0
for i in range(N):
if 0<=i-K:
if T[i-K]==T[i]:
if dp[i-K]==0:
ans+=data[T[i]]
dp[i]=1
else:
ans+=data[T[i]]
dp[i]=1
else:
dp[i]=1
ans+=data[T[i]]
print(ans) | x = list(input().split())
y = list(map(int, input().split()))
z = input()
y[x.index(z)] -= 1
print("{0} {1}".format(y[0], y[1]))
| 0 | null | 89,110,092,656,342 | 251 | 220 |
import math
print reduce(lambda a, b: int(math.ceil(a * 1.05 / 1000)) * 1000, range(input()), 100000) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
n = int(sys.stdin.readline())
debt = 100000
for i in range(n):
debt += debt // 20
fraction = debt % 1000
if fraction > 0:
debt += 1000 - fraction
print(debt) | 1 | 1,216,861,020 | null | 6 | 6 |
def main():
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = map(int, input().split())
if n==m:
print("Yes")
else:
print("No")
main() | N, M = map(int, input().split())
if N - M == 0 :
print('Yes')
else :
print('No')
| 1 | 83,275,317,246,280 | null | 231 | 231 |
n = int(input())
x = input()
init_pop_cnt = x.count('1')
init_pop_cnt_less = init_pop_cnt - 1
init_pop_cnt_more = init_pop_cnt + 1
valid_l = init_pop_cnt_less != 0
# x's state after f
init_res_less = 0
init_res_more = 0
seed_more = 1
seed_less = 1
for i in range(1, n+1):
xp = x[-1 * i]
if xp == '1':
if valid_l:
init_res_less += seed_less % init_pop_cnt_less
init_res_more += seed_more % init_pop_cnt_more
if valid_l:
seed_less = (seed_less * 2) % init_pop_cnt_less
seed_more = (seed_more * 2) % init_pop_cnt_more
dif_less = [0] * (2 * 10**5 + 100)
dif_more = [0] * (2 * 10**5 + 100)
if valid_l:
dif_less[0] = 1 % init_pop_cnt_less
dif_more[0] = 1 % init_pop_cnt_more
for i in range(1, n+1):
if valid_l:
dif_less[i] = (dif_less[i-1] * 2) % init_pop_cnt_less
dif_more[i] = (dif_more[i-1] * 2) % init_pop_cnt_more
def get_pc(dec):
out = 0
while dec > 0:
if dec % 2 == 1:
out+=1
dec = dec // 2
return out
def f(dec):
pc = get_pc(dec)
return dec % pc
cnt = [0] * (2 * 10**5 + 200)
for i in range(1, 2 * 10**5 + 100):
c = 0
cur = i
while cur > 0:
c += 1
cur = f(cur)
cnt[i] = c
for i in range(n):
xi = x[i]
if xi == '1':
if valid_l:
lx = init_res_less
lx -= dif_less[n-i-1]
lx %= init_pop_cnt_less
print((cnt[lx] % init_pop_cnt_less) + 1)
else:
print(0)
else:
lx = init_res_more
lx += dif_more[n-i-1]
lx %= init_pop_cnt_more
print((cnt[lx] % init_pop_cnt_more) + 1)
| def main():
n = int(input())
bit = input()[::-1]
count = bit.count("1")
count_plus = count+1
count_minus = count-1
pow_plus = [1 % count_plus]
for i in range(n):
pow_plus.append(pow_plus[-1]*2 % count_plus)
if count_minus != 0:
pow_minus = [1 % count_minus]
for i in range(n):
pow_minus.append(pow_minus[-1]*2 % count_minus)
else:
pow_minus = []
bit_plus = 0
bit_minus = 0
for i in range(n):
if bit[i] == "1":
bit_plus = (bit_plus+pow_plus[i]) % count_plus
if count_minus != 0:
for i in range(n):
if bit[i] == "1":
bit_minus = (bit_minus+pow_minus[i]) % count_minus
ans = []
for i in range(n):
if bit[i] == "1":
if count_minus == 0:
ans.append(0)
continue
bit_ans = (bit_minus-pow_minus[i]) % count_minus
count = count_minus
else:
bit_ans = (bit_plus+pow_plus[i]) % count_plus
count = count_plus
cnt = 1
while bit_ans:
b = str(bin(bit_ans)).count("1")
bit_ans = bit_ans % b
cnt += 1
ans.append(cnt)
for i in ans[::-1]:
print(i)
main()
| 1 | 8,139,900,723,948 | null | 107 | 107 |
n=int(input());
print(10-(n//200)); | x=int(input())
if x>=400 and x<=599:
print(8)
exit()
if x>=600 and x<=799:
print(7)
exit()
if x>=800 and x<=999:
print(6)
exit()
if x>=1000 and x<=1199:
print(5)
exit()
if x>=1200 and x<=1399:
print(4)
exit()
if x>=1400 and x<=1599:
print(3)
exit()
if x>=1600 and x<=1799:
print(2)
exit()
if x>=1800 and x<=1999:
print(1)
exit()
| 1 | 6,722,366,632,532 | null | 100 | 100 |
import sys
count = [0 for _ in range(ord("a"), ord("z") + 1)]
for line in sys.stdin:
for c in list(line.lower()):
if "a" <= c <= "z":
count[ord(c) - ord("a")] += 1
for i, n in enumerate(count):
print("{ch} : {cnt}".format(ch = chr(ord("a") + i), cnt = n))
| #!/usr/bin/env python3
import sys
def solve(S: str, T: str):
min_change = 100000000
S = [s for s in S]
T = [t for t in T]
for i, s in enumerate(S):
for j, t in enumerate(T):
if j == 0:
c = 0
if len(S) <= i + j:
break
if S[i+j] != t:
c += 1
if len(T) == j + 1:
min_change = min(min_change, c)
print(min_change)
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
solve(S, T)
if __name__ == '__main__':
main()
| 0 | null | 2,711,366,070,790 | 63 | 82 |
x = int(input())
money = 100
k = 1
cnt = 0
while money < x:
money += k
k = money // 100
cnt += 1
print(cnt) | X = int(input())
ans = 0
money = 100
for i in range(1, 10**18):
money = (money * 101) // 100
if money >= X:
ans = i
break
print(ans) | 1 | 27,006,832,802,948 | null | 159 | 159 |
def main():
s,w = list(map(int,input().split()))
if s>w:
print("safe")
else:
print("unsafe")
main()
| from sys import stdin, stdout
n, m = map(int, stdin.readline().strip().split())
if m>=n:
print('unsafe')
else:
print('safe') | 1 | 29,221,820,724,732 | null | 163 | 163 |
print(int(input().strip('\n'))**2) | H, W = input().split(' ')
H = int(H)
W = int(W)
if H==1 or W ==1:
print(1)
elif (H%2)==0 and (W%2)==0:
print(int((H/2) * W))
elif (H%2)==1 and (W%2)==0:
print(int((W/2) * H))
elif (H%2)==0 and (W%2)==1:
print(int((H/2) * W))
elif (H%2)==1 and (W%2)==1:
print(int((H*W//2)+1)) | 0 | null | 98,080,365,361,622 | 278 | 196 |
import heapq
import sys
input = sys.stdin.readline
n = int(input())
sss = [input()[:-1] for _ in range(n)]
a = []
b = []
ss = 0
ii = 0
for i in sss:
mi = 0
ma = 0
s = 0
for j in i:
if j == "(":
s += 1
else:
s -= 1
mi = min(mi, s)
ma = max(ma, s)
ss += s
if s >= 0:
a.append([s, mi, ma, ii])
else:
mi = 0
ma = 0
s = 0
for j in reversed(i):
if j == ")":
s += 1
else:
s -= 1
mi = min(mi, s)
ma = max(ma, s)
b.append([s, mi, ma, ii])
ii += 1
if ss != 0:
print("No")
exit()
a.sort(reverse=1, key=lambda x: x[1])
b.sort(reverse=1, key=lambda x: x[1])
def ok(a):
s = 0
for i, j, _, _ in a:
if s + j < 0:
print("No")
exit()
s += i
ok(a)
ok(b)
print("Yes")
| N=int(input())
A=list(map(int,input().split()))
for i in A:
if i %2==0:
if i %3==0 or i %5==0:
pass
else:
print('DENIED')
exit()
print('APPROVED') | 0 | null | 46,631,532,394,678 | 152 | 217 |
num_cnt = int(input().rstrip())
nums = list(map(int, input().rstrip().split(" ")))
for i in range(num_cnt):
tmpNum = nums[i]
j = i -1
while j >=0:
if nums[j] <= tmpNum:
break
nums[j+1] = nums[j]
j = j-1
nums[j+1] = tmpNum
print (" ".join(map(str,nums))) | _, lis = input(), list(input().split())[::-1]
print(*lis)
| 0 | null | 496,681,184,060 | 10 | 53 |
s = input()
n = int(input())
for i in range(n):
command = input().split()
if command[0] == 'replace':
a,b = map(int,command[1:3])
s = s[:a]+ command[3] + s[b+1:]
elif command[0] == 'reverse':
a,b = map(int,command[1:3])
s = s[0:a] + s[a:b+1][::-1] + s[b+1:]
elif command[0] == 'print':
a,b = map(int,command[1:3])
print(s[a:b+1])
| N = int(input())
A = list(map(int, input().split()))
DP_odd = [0, 0, A[0]]
DP_even = [0, max(A[0], A[1])]
if N >= 3:
DP_odd = [DP_even[0], max(DP_odd[1] + A[2], DP_even[1]), DP_odd[2] + A[2]]
for i in range(3, N):
if (i + 1) % 2 == 1:
DP_odd = [max(DP_odd[0] + A[i], DP_even[0]), max(DP_odd[1] + A[i], DP_even[1]), DP_odd[2] + A[i]]
else:
DP_even = [max(DP_even[0] + A[i], DP_odd[1]), max(DP_even[1] + A[i], DP_odd[2])]
if N % 2 == 1:
ans = DP_odd[1]
else:
ans = DP_even[1]
print(ans) | 0 | null | 19,758,904,860,292 | 68 | 177 |
import sys
S = int(sys.stdin.readline())
h = S / 3600
m = (S - h*3600)/60
s = S - h*3600 - m*60
print("%d:%d:%d" % (h,m,s)) | a, b = map(int, input().split())
x = 300000
y = 200000
z = 100000
A = [x, y, z]
for i in range(1000):
A.append(0)
a_ = A[a-1]
b_ = A[b-1]
if a == 1 and b == 1:
print(a_ + b_ + 400000)
else:
print(a_ + b_) | 0 | null | 70,539,848,114,944 | 37 | 275 |
import sys
input = sys.stdin.readline
# 文字列をinput()した場合、末尾に改行が入るので注意
def main(R,C,K,rcv):
inf=float('inf')
dp0=[[-inf,-inf,-inf,0] for _ in range(C)]
dp1=[[-inf]*4 for _ in range(C)]
dp0[0][3]=0
rcv.sort(key=lambda x:C*R*x[0]+x[1])
i=0
nowc=0
while i<K and rcv[i][0]==1:
nextc=rcv[i][1]-1
for j in range(nowc+1,nextc+1):
dp0[j][0]=dp0[nowc][0]
dp0[j][1]=dp0[nowc][1]
dp0[j][2]=dp0[nowc][2]
v=rcv[i][2]
dp0[nextc][0]=max(dp0[nextc][0],dp0[nextc][1]+v)
dp0[nextc][1]=max(dp0[nextc][1],dp0[nextc][2]+v)
dp0[nextc][2]=max(dp0[nextc][2],dp0[nextc][3]+v)
i+=1
nowc=nextc
for j in range(nowc+1,C):
dp0[j][0]=dp0[nowc][0]
dp0[j][1]=dp0[nowc][1]
dp0[j][2]=dp0[nowc][2]
for j in range(1,R):
for c in range(C):
dp0[c][3]=max(dp0[c])
dp0[c][2]=-inf
dp0[c][1]=-inf
dp0[c][0]=-inf
nowc=0
while i<K and rcv[i][0]==j+1:
nextc=rcv[i][1]-1
for k in range(nowc+1,nextc+1):
dp0[k][0]=dp0[nowc][0]
dp0[k][1]=dp0[nowc][1]
dp0[k][2]=dp0[nowc][2]
v=rcv[i][2]
dp0[nextc][0]=max(dp0[nextc][0],dp0[nextc][1]+v)
dp0[nextc][1]=max(dp0[nextc][1],dp0[nextc][2]+v)
dp0[nextc][2]=max(dp0[nextc][2],dp0[nextc][3]+v)
i+=1
nowc=nextc
for j in range(nowc+1,C):
dp0[j][0]=dp0[nowc][0]
dp0[j][1]=dp0[nowc][1]
dp0[j][2]=dp0[nowc][2]
#print(dp0)
print(max(dp0[-1]))
if __name__=='__main__':
R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]
#import datetime
#print(datetime.datetime.now())
main(R,C,K,rcv)
#print(datetime.datetime.now())
| import sys,heapq
input = sys.stdin.readline
def main():
n,u,v = map(int,input().split())
u,v = u-1,v-1
edge = [[] for _ in range(n)]
for _ in [0]*(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
#cost:vからの距離
cost = [0]*n
new = [v]
c = 1
while len(new):
tank = []
for e in new:
for go in edge[e]:
if go != v and cost[go] == 0:
cost[go] = c
tank.append(go)
c += 1
new = tank
if cost[u]%2 == 1:
res = cost[u]//2
now = u
for _ in [0]*res:
for e in edge[now]:
if cost[now] > cost[e]:
now = e
new = [now]
while len(new):
tank = []
for e in new:
for go in edge[e]:
if cost[go] > cost[e]:
tank.append(go)
res += 1
new = tank
print(res-1)
else:
res = cost[u]//2-1
now = u
for _ in [0]*res:
for e in edge[now]:
if cost[now] > cost[e]:
now = e
new = [now]
while len(new):
tank = []
for e in new:
for go in edge[e]:
if cost[go] > cost[e]:
tank.append(go)
res += 1
new = tank
print(res)
if __name__ == '__main__':
main() | 0 | null | 61,629,963,364,778 | 94 | 259 |
# C - Slimes
def main():
n = int(input())
s = input()
p = ''
ans = ''
for v in s:
if v != p:
ans += v
p = v
else:
continue
print(len(ans))
if __name__ == "__main__":
main() | n = int(input())
s = input()
for i in range(n-1):
if s[i] == s[i+1]:
s = s[:i] + " " + s[i+1:]
print(len(s.replace(" ", ""))) | 1 | 170,066,175,445,152 | null | 293 | 293 |
#!/usr/bin/env python
# coding: utf-8
def ri():
return int(input())
def rl():
return list(input().split())
def rli():
return list(map(int, input().split()))
def main():
t = input()
bef = '!'
s = ""
for c in t:
nc = c
if c == '?':
nc = "D"
bef = nc
s += nc
print(s)
if __name__ == '__main__':
main()
| S = input()
ans=""
for i in range(len(S)):
if S[i] == "?":
ans += "D"
else:
ans += S[i]
print(ans) | 1 | 18,367,826,088,210 | null | 140 | 140 |
def abc170_c_2():
"""
もっとシンプルに考えると
Xから-1、+1と順番に探索して、見つかったものをリターンすればOKなはず。
±0~99までを調べる?
"""
def solve():
x, n = map(int, input().split(' '))
if n == 0:
return x
p = list(map(int, input().split(' ')))
for i in range(100):
for s in [-1, +1]:
a = x + i * s
if a not in p:
return a
print(solve())
if __name__ == '__main__':
abc170_c_2() | # -*- coding:utf-8 -*-
import sys
class Hash(object):
def __init__(self, size):
self._array = [None] * size
self._size = size
def _hash(self, key):
return key % self._size
def insert(self, key, value):
j = self._hash(key)
if self._array[j] is None:
self._array[j] = [value]
else:
self._array[j].append(value)
def find(self, key, value):
j = self._hash(key)
if self._array[j] is None:
return False
elif value in self._array[j]:
return True
else:
return False
def stoi(s):
ret = 0
p = 1
ctoi = {"A": 1, "C": 2, "G": 3, "T": 4}
for c in s:
ret += ctoi[c] * p
p *= 7
return ret
def dictionary(lst):
h = Hash(1046527)
ret = []
for val in lst:
if val[0] == "insert":
h.insert(stoi(val[1]), val[1])
elif val[0] == "find":
if h.find(stoi(val[1]), val[1]):
ret.append("yes")
else:
ret.append("no")
else:
raise ValueError
return ret
if __name__ == "__main__":
lst = [val.split() for val in sys.stdin.read().splitlines()]
n = int(lst.pop(0)[0])
print("\n".join(dictionary(lst))) | 0 | null | 7,047,334,664,348 | 128 | 23 |
n = input()
a = map(str,raw_input().split())
print ' '.join(a[::-1]) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def calc(lst):
ret = 0
for a, b, c, d in abcd:
if lst[b-1] - lst[a-1] == c:
ret += d
return ret
def dfs(lst):
if len(lst) == n:
return calc(lst)
x = lst[-1]
ret = 0
for i in range(x, m+1):
ret = max(ret, dfs(lst + [i]))
return ret
n, m, q = LI()
abcd = [LI() for _ in range(q)]
ans = dfs([1])
print(ans) | 0 | null | 14,404,774,272,132 | 53 | 160 |
import sys
def main():
s,w = list(map(int,(input().split())))
if s<=w:
print('unsafe')
sys.exit()
else:
print('safe')
sys.exit()
if __name__ == '__main__':
main()
| n = int(raw_input())
for i in range(n):
num = map(int, raw_input().split())
num.sort(reverse=True)
if num[0]**2 == num[1]**2 + num[2]**2:
print "YES"
else:
print "NO"
| 0 | null | 14,528,713,233,792 | 163 | 4 |
import sys
input = sys.stdin.readline
def main():
N = int(input())
S = set([input().rstrip() for _ in range(N)])
print(len(S))
if __name__ == '__main__':
main()
| x,y = map(int,input().split())
ans = 0
for n in range(x+1):
kame = x - n
tsuru_leg = n*2
kame_leg = kame*4
if y == (tsuru_leg+kame_leg):
ans = ans + 1
if ans == 0:
print('No')
else:
print('Yes') | 0 | null | 22,030,009,952,962 | 165 | 127 |
X , Y = map(int,input().split())
a = 0
ans = "No"
for a in range(0,X+1):
if (a * 2)+((X-a) * 4)==Y:
ans = "Yes"
print(ans) | x, y = map(int,input().split())
ans = 0
for i in range(x+1):
for j in range(x+1):
if 2*i + 4 * j == y and i + j == x:
ans += 1
if ans > 0:
print('Yes')
else:
print('No') | 1 | 13,731,060,467,488 | null | 127 | 127 |
import os, sys, re, math
N = int(input())
P = [int(n) for n in input().split()]
answer = 0
m = 2 * 10 ** 5
for p in P:
if p <= m:
answer += 1
m = p
print(answer)
| n,p = map(int,input().split())
s = input()
ans = 0
if p == 2 or p == 5:
for i,c in enumerate(s,1):
if int(c)%p == 0: ans += i
else:
cnt = [0]*p
cnt[0] = 1
x = 0
d = 1
for c in s[::-1]:
x += d*int(c)
x %= p
cnt[x%p] += 1
d *= 10
d %= p
# print(cnt)
for v in cnt: ans += v*(v-1)//2
print(ans) | 0 | null | 71,585,984,237,160 | 233 | 205 |
def selectionSort(a, n):
count = 0
for i in range(0, n):
minj = i
for j in range(i, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if i != minj:
count += 1
return count
def main():
n = int(input())
a = [int(x) for x in input().split(' ')]
count = selectionSort(a, n)
print(' '.join([str(x) for x in a]))
print(count)
if __name__ == '__main__':
main() | h,n = map(int,input().split())
a = list(map(int,input().split()))
x = sum(a)
if h <= x: print('Yes')
else: print('No') | 0 | null | 38,750,842,412,130 | 15 | 226 |
N, M, Q = map(int, input().split())
G = []
for i in range(Q):
a, b, c, d = map(int, input().split())
G.append([a, b, c, d])
ans = 0
def dfs(s):
global ans
if len(s) == N:
now = 0
for a, b, c, d in G:
if s[b - 1] - s[a - 1] == c:
now += d
ans = max(ans, now)
return
for i in range(s[-1], M):
dfs(s + [i])
s = [0]
dfs(s.copy())
print(ans)
| N = int(input())
A = list(map(int, input().split()))
m = set(A)
M = len(m)
if N == M:
print("YES")
else:
print('NO') | 0 | null | 50,737,611,100,900 | 160 | 222 |
import math
a = float(input())
area = a * a * math.pi
cir = (a * 2) * math.pi
print(area,cir) | import math
t = float(input())
a = math.pi * t**2
b = 2 * t * math.pi
print(str("{0:.8f}".format(a)) + " " + "{0:.8f}".format(b)) | 1 | 639,451,861,400 | null | 46 | 46 |
class Dice(object):
def __init__(self):
self.number = [0 for _ in range(6)]
self.before = [0 for _ in range(6)]
def set_number(self, l):
for i in range(6):
self.number[i] = l[i]
def roll(self, loc):
d = {
'N': (1, 5, 2, 3, 0, 4),
'S': (4, 0, 2, 3, 5, 1),
'E': (3, 1, 0, 5, 4, 2),
'W': (2, 1, 5, 0, 4, 3)
}
for i in range(6):
self.before[i] = self.number[i]
for i, j in enumerate(d[loc]):
self.number[i] = self.before[j]
def get_Top(self):
return self.number[0]
if __name__ == '__main__':
l = list(map(int, input().split()))
dice = Dice()
dice.set_number(l)
s = input()
for i in s:
dice.roll(i)
print(dice.get_Top())
| import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N = int(readline())
A = list(map(int, readline().split()))
lcmnum = 1
def gcd(a, b):
if (a == 0):
return b
return gcd(b%a, a)
def lcm(x, y):
return (x * y) // gcd(x, y)
for a in A:
lcmnum = lcm(lcmnum, a)
ans = 0
for a in A:
a = lcmnum // a
ans += a
ans %= mod
print(ans)
if __name__ == '__main__':
solve()
| 0 | null | 44,232,257,966,820 | 33 | 235 |
N, S=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[0]+A
dp=[[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0]=1
for i in range(1,N+1):
for j in range(S+1):
dp[i][j]=(dp[i][j]+2*dp[i-1][j]) %998244353 # x[i]を入れないが、大きい方に入れるか入れないかが二通り
for j in range(S-A[i]+1):
dp[i][j+A[i]]=(dp[i][j+A[i]]+dp[i-1][j]) %998244353 # x[i]を入れる
print(dp[N][S]) | import numpy as np
mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
for num, a in enumerate(A):
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP[a] += pow(2, num, mod)
DP %= mod
print(DP[s])
| 1 | 17,666,415,829,050 | null | 138 | 138 |
N = int(input())
S = set([])
for i in range(N):
temp = str(input())
S.add(temp)
ans = len(S)
print(ans) | x = int(input())
s = [0]*x
for i in range(x):
s[i-1] = input()
l = set (s)
length = len(l)
print(length) | 1 | 30,329,328,804,320 | null | 165 | 165 |
from math import *
K=int(input())
ans=0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
ans+=gcd(gcd(a,b),c)
print(ans) | T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
diff1 = (A1 - B1) * T1
diff2 = (A2 - B2) * T2
if diff1 > 0:
diff1, diff2 = -1 * diff1, -1 * diff2
if diff1 + diff2 < 0:
print(0)
elif diff1 + diff2 == 0:
print('infinity')
else:
q, r = divmod(-diff1, diff1 + diff2)
print(2*q + (1 if r != 0 else 0)) | 0 | null | 83,443,891,383,478 | 174 | 269 |
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))[::-1]
# 成績 Σ{i=1~n}a[i]*f[i]
# a[i]小さいの、f[i]でかいの組み合わせるとよい(交換しても悪化しない)
def c(x):
need = 0
for i in range(n):
if a[i] * f[i] > x:
# f[i]を何回減らしてx以下にできるか
diff = a[i] * f[i] - x
need += 0 - - diff // f[i]
return need <= k
l = 0
r = 1 << 60
while r != l:
mid = (l + r) >> 1
if c(mid):
r = mid
else:
l = mid + 1
print(l)
| s = input()
s = s.split()
n = []
for i in s:
n.append(int(i))
a = n[0]
b = n[1]
print("a",end = " ")
if a > b:
print(">",end = " ")
elif a < b:
print("<",end = " ")
else:
print("==",end = " ")
print("b")
| 0 | null | 82,493,270,045,536 | 290 | 38 |
S=input();
if(S=="hi" or S=="hihi" or S=="hihihi" or S=="hihihihi" or S=="hihihihihi"):
print("Yes");
else:
print("No"); | n = int(input())
s = str(input())
ans = n
for i in range(1,n):
if s[i-1] == s[i]:
ans -= 1
print(ans) | 0 | null | 111,898,033,344,190 | 199 | 293 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 9
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353
n = I()
A = LI()
S = sorted([(A[k], k + 1) for k in range(n)], reverse=True)
ans = 0
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(n):
if i and i <= S[i + j - 1][1]:
dp[i][j] = max(dp[i][j], dp[i - 1][j] + S[i + j - 1][0] * abs(i - S[i + j - 1][1]))
if j and S[i + j - 1][1] <= n - j + 1:
dp[i][j] = max(dp[i][j], dp[i][j - 1] + S[i + j - 1][0] * abs(n - j + 1 - S[i + j - 1][1]))
if i + j == n:
ans = max(ans, dp[i][j])
break
print(ans)
| n = int(input())
a = list(map(int,input().split()))
a = [(num,i) for i,num in enumerate(a)]
a.sort(reverse=True)
dp=[[0]*(n+1) for _ in range(n+1)]
for i in range(n+1):
for j in range(n-i+1):
if i>0:
dp[i][j] = max(dp[i][j],dp[i-1][j]+a[i+j-1][0]*abs(a[i+j-1][1]-(i-1)))
if j>0:
dp[i][j] = max(dp[i][j],dp[i][j-1]+ a[i+j-1][0]*abs(a[i+j-1][1]-(n-j)))
ans = max(dp[i][n-i] for i in range(n+1))
print(ans)
| 1 | 33,844,287,520,540 | null | 171 | 171 |
total = 0
for ch in input().strip():
total = (total + int(ch)) % 9
print('No' if total else 'Yes') | import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from math import ceil
def main():
n = tuple(map(int, tuple(input())))
if sum(n) % 9 == 0:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main() | 1 | 4,405,174,708,188 | null | 87 | 87 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.