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
|
---|---|---|---|---|---|---|
n = int(input())
S = input()
rs = [s=="R" for s in S]
gs = [s=="G" for s in S]
bs = [s=="B" for s in S]
ind_r = [i for i,s in enumerate(rs) if s == 1]
ind_g = [i for i,s in enumerate(gs) if s == 1]
ind_b = [i for i,s in enumerate(bs) if s == 1]
ans = 0
ng = sum(gs)
for i in ind_r:
for j in ind_b:
# print(i,j)
kM = max(i,j) + abs(i-j)
km = min(i,j) - abs(i-j)
ans += ng
if (max(i,j) - min(i,j))%2==0:
# print("aaa",(max(i,j)+min(i,j))//2)
ans -= gs[(max(i,j)+min(i,j))//2]
if kM < n:
ans -= gs[kM]
if 0 <= km:
ans -= gs[km]
print(ans) | import math
r = float(input())
m = r ** 2 * math.pi
l = r * 2 * math.pi
print('{:.6f} {:.6f}'.format(m, l)) | 0 | null | 18,480,603,846,052 | 175 | 46 |
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
for i in range(len(A)-1):
for k in range(i+1,len(A)):
ans.append(np.sqrt(((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2))
print(sum(ans)*2/N) | import sys
import collections
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
d = collections.defaultdict(int)
d[-1] = 3
mt = 1
for v in a:
mt *= d[v-1]
mt %= mod
d[v-1] -= 1
d[v] += 1
print(mt)
if __name__ == '__main__':
solve()
| 0 | null | 139,743,555,372,762 | 280 | 268 |
#coding:utf-8
def seki(a, b):
c = []
gou = 0
d = []
for i in range(len(a)):
for j in range(len(b[0])):
for k in range(len(b)):
gou += a[i][k] * b[k][j]
d.append(gou)
gou = 0
c.append(d)
d=[]
return c
n, m, l = [int(i) for i in input().rstrip().split()]
a = [list(map(int , input().rstrip().split())) for i in range(n)]
b = [list(map(int , input().rstrip().split())) for i in range(m)]
c = seki(a,b)
for i in c:
print(" ".join(list(map(str,i)))) | n, m, l = [int (x) for x in input().split(' ')]
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(l)] for j in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for s in range(0,n):
a[s] = [int (x) for x in input().split(' ')]
for s in range(0,m):
b[s] = [int (x) for x in input().split(' ')]
for i in range(0,n):
for k in range(0,l):
result = 0
for j in range(0,m):
result += a[i][j] * b[j][k]
c[i][k] = result
for i in range(0,n):
c[i] = [str(c[i][j]) for j in range(0,l)]
print(' '.join(c[i])) | 1 | 1,424,761,519,038 | null | 60 | 60 |
N=int(input())
ls={}
max_ch=0
for i in range(N):
ch=input()
if not ch in ls:
ls[ch]=1
else:
ls[ch]+=1
if max_ch<ls[ch]:
max_ch=ls[ch]
S=[]
for j in ls:
if max_ch==ls[j]:
S.append(j)
S=sorted(S)
for i in S:
print(i) | from collections import Counter
n = int(input())
s = Counter([str(input()) for _ in range(n)])
l = []
c = 1
for stri, count in s.items():
if count == c:
c = count
l.append(stri)
elif count > c:
c = count
l.clear()
l.append(stri)
sort_l = sorted(l)
for i in sort_l:
print(i)
| 1 | 70,111,794,427,072 | null | 218 | 218 |
import sys
li = []
for line in sys.stdin:
li.append(int(line))
if len(li) == 10:
break
li.sort(reverse=True)
li = li[0:3]
for i in li:
print(i) | first=0
second=0
third=0
for i in range(10):
mountain=int(input())
if mountain>first:
third=second
second=first
first=mountain
elif mountain>second:
third=second
second=mountain
elif mountain>third:
third=mountain
print(first)
print(second)
print(third) | 1 | 16,242,810 | null | 2 | 2 |
#!/usr/bin/env python3
#ABC146 E
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
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()))
"""
S := aの累積和
(Sj - Si) % k = j - i
ある整数mに対して
Sj - Si = m*k + j - i
Sj - j = m*k + Si - i
(Sj - j) - (Si - i) Ξ 0 (mod k)
(Sj - j) Ξ (Si - i) (mod k)
"""
n,k = LI()
a = LI()
s = [0] + list(accumulate(a))
ans = 0
d = defaultdict(int)
for j in range(n+1):
t = (s[j] - j) % k
if j >= k:
x = (s[j-k] - (j-k)) % k
d[x] -= 1
ans += d[t]
d[t] += 1
print(ans)
| N = int(input())
S = list(input())
S.append("test")
i = 0
while N > 0:
if S[i] == S[i+1]:
S.pop(i)
i = i - 1
i = i + 1
N = N - 1
print(len(S)-1)
| 0 | null | 154,041,884,400,640 | 273 | 293 |
S, W = [int(n) for n in input().split()]
print('unsafe' if S <= W else 'safe') | S, W = [int(x) for x in input().split()]
if S > W:
print("safe")
else:
print("unsafe") | 1 | 29,155,499,761,180 | null | 163 | 163 |
def bubblesort(A):
tot = 0
flag = 1
N = len(A)
while flag:
flag = 0
for j in xrange(N-1,0,-1):
if A[j] < A[j-1]:
A[j],A[j-1] = A[j-1],A[j]
flag = 1
tot += 1
return A,tot
while True:
try:
N = int(raw_input())
except EOFError:
break
A = map(int,raw_input().split())
A,tot = bubblesort(A)
print ' '.join(map(str,A))
print tot | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
cnt = Counter(a)
q = int(input())
for i in range(q):
b, c = map(int, input().split())
s += (c - b)*cnt[b]
cnt[b], cnt[c] = 0, cnt[c] + cnt[b]
print(s) | 0 | null | 6,171,305,072,800 | 14 | 122 |
import math
a,b,c=map(float,raw_input().split())
c = c / 180 * math.pi
print "%.10f" % float(a*b*math.sin(c)/2)
x = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(c))
print "%.10f" % float(a + b + x)
print "%.10f" % float(b*math.sin(c)) | # 各行の所属するグループを配列として持たせる実装。列ごと見ていってダメなら垂直線追加していく
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = 10**9
for bit in range((1 << (H-1))):
vidx = []
gok = True
g = 0
gid = [0] * H
for i in range(H-1):
if (bit >> i) & 1:
g += 1
gid[i+1] = g
g += 1
gnum = [0]*g
vertical = 0
for w in range(W):
ok = True
one = [0]*g
for h in range(H):
one[gid[h]] += int(S[h][w])
gnum[gid[h]] += int(S[h][w])
if one[gid[h]] > K:
gok = False
if gnum[gid[h]] > K:
ok = False
if not ok:
vertical += 1
vidx.append(w)
gnum = one
# if bit == 2:
# print('aaaaa')
# print(gid)
# print(vidx)
# print(bin(bit), g-1, vertical)
# print('aaaaa')
if gok:
if ans > g-1 + vertical:
ans = g-1 + vertical
# print(bin(bit), g-1, vertical)
# print(vidx)
# print(ans)
# ans = min(ans, g-1 + vertical)
if ans == 10**9:
print(-1)
else:
print(ans)
| 0 | null | 24,525,744,671,520 | 30 | 193 |
def f(x, m):
return x * x % m
def main():
N, X, M = map(int, input().split())
pre = set()
pre.add(X)
cnt = 1
while cnt < N:
X = f(X, M)
if X in pre: break
cnt += 1
pre.add(X)
if cnt == N:
return sum(pre)
ans = sum(pre)
N -= cnt
loop = set()
loop.add(X)
while cnt < N:
X = f(X, M)
if X in loop: break
loop.add(X)
left = N % len(loop)
ans += sum(loop) * (N // len(loop))
for i in range(left):
ans += X
X = f(X, M)
return ans
print(main())
| from collections import deque
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
q = deque([])
points = 0
for i in range(n):
if i <= k-1:
if t[i] == 'r':
points += p
q.append('p')
elif t[i] == 's':
points += r
q.append('r')
elif t[i] == 'p':
points += s
q.append('s')
else:
ban = q.popleft()
if t[i] == 'r':
if ban != 'p':
points += p
q.append('p')
else:
q.append('x')
elif t[i] == 's':
if ban != 'r':
points += r
q.append('r')
else:
q.append('x')
elif t[i] == 'p':
if ban != 's':
points += s
q.append('s')
else:
q.append('x')
print(points) | 0 | null | 54,929,748,152,500 | 75 | 251 |
import sys
sys.setrecursionlimit(10**8)
def line_to_int(): return int(sys.stdin.readline())
def line_to_each_int(): return map(int, sys.stdin.readline().split())
def line_to_list(): return list(map(int, sys.stdin.readline().split()))
def line_to_list_in_iteration(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
# def dp(init, i, j): return [[init]*i for i2 in range(j)]
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #A = [0]+list(accumulate(A))
# import bisect #bisect.bisect_left(B, a), bisect.bisect_right(B,a)
x = line_to_list()
print(x.index(0)+1) | lst = [int(i) for i in input().split()]
for i in range(5):
if lst[i] == 0:
print(i + 1)
break | 1 | 13,425,736,828,032 | null | 126 | 126 |
import sys
for line in sys.stdin:
a = int(line.split()[0])
b = int(line.split()[1])
s = a + b
print(len(str(s))) | a, b = map(int, input().split())
if a < b:
print('a < b')
elif a == b:
print('a == b')
else:
print('a > b')
| 0 | null | 176,644,253,172 | 3 | 38 |
N = int(input())
A = list(map(int, input().split()))
ans = 0
mod = int(1e9 + 7)
s = sum(A) % mod
for a in A:
s -= a
ans += (a * s) % mod
ans %= mod
print(int(ans)) | l = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
s = input()
for i, day in enumerate(l):
if day == s:
if i == 0:
print(7)
else:
print(7-i) | 0 | null | 68,490,793,269,052 | 83 | 270 |
#B
N, K = map(int,input().split())
num=[]
while N >= K:
num.append(N%K)
N=N//K
num.append(N)
print(len(num)) | def subset_sum(s, a):
dict = {}
return subset_rec(0, s, a, dict)
def subset_rec(i, s, a, dict):
key = str(i) + '-' + str(s)
ret = False
if key in dict:
ret = dict[key]
elif s == 0:
ret = True
elif i >= len(a):
ret = False
else:
ret = subset_rec(i+1, s-a[i], a, dict) or subset_rec(i+1, s, a, dict)
dict[key] = ret
return ret
n = int(input())
a = list(map(int, input().split()))
p = int(input())
q = list(map(int, input().split()))
for i in range(p):
if subset_sum(q[i], a):
print('yes')
else:
print('no')
| 0 | null | 32,263,415,247,008 | 212 | 25 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, m = map(int, readline().split())
if n == m:
print('Yes')
else:
print('No')
| import sys
lines = [list(map(int,line.split())) for line in sys.stdin]
n,m,l = lines[0]
A = lines[1:n+1]
B = [i for i in zip(*lines[n+1:])]
for a in A:
row = []
for b in B:
row.append(sum([i*j for i,j in zip(a,b)]))
print (" ".join(map(str,row))) | 0 | null | 42,467,807,700,952 | 231 | 60 |
point = int(input())
rank = 1
for val in range(1800, 200, -200):
if point >= val:
break
else:
rank += 1
print(rank) | from itertools import accumulate
N, K, *PC = map(int, open(0).read().split())
P, C = [0] + PC[:N], [0] + PC[N:]
ans = float("-inf")
for start in range(1, N + 1):
path = []
cur = P[start]
path = [C[start]]
while cur != start:
path.append(C[cur])
cur = P[cur]
A = list(accumulate(path))
q, r = divmod(K, len(path))
res = 0
if A[-1] >= 0:
if r == 0:
q -= 1
r += len(path)
res += A[-1] * q
elif q >= 1:
r = len(path)
ans = max(ans, res + max(A[:r]))
print(ans) | 0 | null | 6,106,305,649,938 | 100 | 93 |
H=int(input())
W=int(input())
N=int(input())
K=H
if K<W: K=W
sum = 0
ans= 0
for i in range(1,K+1):
if sum < N:
sum += K
ans = i
#print(ans, K)
print(ans) | H,W = (int(x) for x in input().split())
if H==1 or W==1:
print(1)
elif (H*W)%2:
print((H*W-1)//2 + 1)
else:
print((H*W)//2) | 0 | null | 69,982,353,382,300 | 236 | 196 |
N=int(input())
S={}
for n in range(N):
s=input()
S[s]=S.get(s,0)+1
maxS=max(S.values())
S={k:v for k, v in S.items() if v==maxS}
S=sorted(S.items(), key=lambda x:(-x[1],x[0]))
for k,cnt in S:
print(k)
| n = int(input())
A = input()
A = A.split()
A = [int(i) for i in A]
A = sorted(A, reverse = True)
#print(A)
ans = 0
for i in range(int(n/2)):
ans += A[i]*2
ans -= A[0]
#print(ans)
if n&1:
ans += A[int(n/2)]
print(ans) | 0 | null | 39,387,499,346,570 | 218 | 111 |
X, N = map(int, input().split())
ans = 0
if N > 0:
p = list(map(int, input().split()))
r = [i for i in range(102) if i not in p]
d = [abs(X-i) for i in r]
ans = r[d.index(min(d))]
else:
ans = X
print(ans) | def ri():
return int(input())
def rii():
return [int(v) for v in input().split()]
def solve():
X, N = rii()
P = set(rii())
n = m = float("inf")
if not P:
print(X)
return
for i in range(min(P)-1, max(P)+2):
if i not in P:
d = abs(i - X)
if d == m:
n = min(n, i)
elif d < m:
m = d
n = i
print(n)
if __name__ == "__main__":
solve() | 1 | 14,181,364,635,592 | null | 128 | 128 |
count = 1
while True:
x = input().strip()
if x == '0':
break
else:
print('Case %s: %s' %(count, x))
count = count + 1 | a = []
while True:
n = int(raw_input())
if n == 0:
break
a.append(n)
for i in range(len(a)):
print "Case " + str(i +1) + ": " + str(a[i]) | 1 | 475,987,665,890 | null | 42 | 42 |
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
wins = {"p":"s", "r":"p", "s":"r"}
points = {"p":S, "r":P, "s":R}
hands = []
ans = 0
for i in range(N):
if i - K < 0:
hands.append(wins[T[i]])
ans += points[T[i]]
else:
if hands[i-K] == wins[T[i]]:
#あいこにするしか無い時
hands.append("-")
else:
#勝てる時
hands.append(wins[T[i]])
ans += points[T[i]]
print(ans)
| n,k=map(int,input().split())
r,s,p=map(int,input().split())
d={'r':p,'s':r,'p':s}
t=input()
ans=0
for i in range(k):
a=t[i::k]
flag=a[0]
cnt=2
for j in a[1:]:
if j!=flag:
ans+=d[flag]*(cnt//2)
flag=j
cnt=2
else:cnt+=1
ans+=d[flag]*(cnt//2)
print(ans) | 1 | 107,156,891,468,740 | null | 251 | 251 |
N = int(input())
A = list(map(int,input().split()))
check = True
for a in A:
if a % 2 == 0:
if a % 3 != 0 and a % 5 != 0:
check = False
if check:
print("APPROVED")
else:
print("DENIED") | def perm(n, k, p):
ret = 1
for i in range(n, n-k, -1):
ret = (ret * i)%p
return ret
def comb(n, k, p):
a = perm(n, k, p)
b = perm(k, k, p)
return (a*pow(b, -1, p))%p
S = int(input())
ans = 0
S -= 3
t = 0
while S >= 0:
ans += comb(S+t,t, 10**9+7)
S -= 3
t += 1
print(ans%(10**9+7)) | 0 | null | 36,203,770,869,578 | 217 | 79 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys
INF = float('inf')
def solve(K: int, S: str):
return S[:K] + ['...', ''][len(S) <= K]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
S = next(tokens) # type: str
print(solve(K, S))
if __name__ == '__main__':
main()
| class Stack:
def __init__(self):
self.values = []
self.n = 0
def pop(self):
if self.n == 0:
raise Exception("stack underflow")
else:
v = self.values[-1]
del self.values[-1]
self.n -= 1
return v
def push(self,x):
self.values.append(x)
self.n += 1
operators = set(['+', '-', '*'])
stack = Stack()
for op in raw_input().split(' '):
if op in operators:
b = stack.pop()
a = stack.pop()
if op == '+':
stack.push(a+b)
elif op == '-':
stack.push(a-b)
elif op == '*':
stack.push(a*b)
else:
raise Exception("Unkown operator")
else:
stack.push(int(op))
print stack.pop() | 0 | null | 9,780,369,905,440 | 143 | 18 |
r = int(input())
print(2 * r * 3.1415) | N = int(input())
pl = []
mi = []
for i in range(N):
_m = 0
_t = 0
s = input()
for c in s:
if c == ")":
_t -= 1
_m = min(_m, _t)
else:
_t += 1
if _t > 0:
pl.append([-_m, -_t]) # sortの調整のために負にしている
else:
mi.append([- _t + _m, _m, _t])
pl = sorted(pl)
mi = sorted(mi)
#import IPython;IPython.embed()
if len(pl) == 0:
if mi[0][0] == 0:
print("Yes")
else:
print("No")
exit()
if len(mi) == 0:
print("No")
exit()
tot = 0
for m, nt in pl:
if tot - m < 0: # これはひくではないのでは?
print("No")
exit()
else:
tot -= nt
for d, m, nt in mi:
if tot + m <0:
print("No")
exit()
else:
tot += nt
if tot != 0:
print("No")
else:
print("Yes")
# どういう時できるか
# で並べ方
# tot, minの情報が必要
# totが+のものはminとtotを気をつける必要がある
# minがsum以上であればどんどん足していけばいい.
# なのでminが大きい順にsortし,totの大きい順にsort
# その次はtotがminusの中ではminが小さい順に加える
# 合計が0になる時Yes,それ意外No. | 0 | null | 27,510,457,836,462 | 167 | 152 |
h,w,m=map(int,input().split())
H,W=[0]*h,[0]*w
P=set()
for i in range(m):
y,x=map(int,input().split())
H[~-y]+=1
W[~-x]+=1
P.add(~-y*w+~-x)
mh,mw=max(H),max(W)
MH=[i for i,h in enumerate(H) if h==mh]
MW=[i for i,v in enumerate(W) if v==mw]
for y in MH:
for x in MW:
if y*w+x not in P:
print(mh+mw)
exit()
print(mh+mw-1)
| count = int(raw_input())
S = []
H = []
C = []
D = []
while count:
arr = map(str, raw_input().split(" "))
if arr[0] == "S":
S.append(int(arr[1]))
elif arr[0] == "H":
H.append(int(arr[1]))
elif arr[0] == "C":
C.append(int(arr[1]))
else:
D.append(int(arr[1]))
count -= 1
S.sort()
H.sort()
C.sort()
D.sort()
ans_s = []
ans_h = []
ans_c = []
ans_d = []
for x in range(1, 14):
if not x in S:
ans_s.append(x)
if not x in H:
ans_h.append(x)
if not x in C:
ans_c.append(x)
if not x in D:
ans_d.append(x)
def answer(arr, value):
for x in arr:
print "%s %s" % (value, str(x))
answer(ans_s, 'S')
answer(ans_h, 'H')
answer(ans_c, 'C')
answer(ans_d, 'D') | 0 | null | 2,866,967,334,410 | 89 | 54 |
n = int(input())
ret = ''
for i in range(1,n+1):
str = repr(i)
if (i % 3 == 0): ret += ' ' + repr(i)
elif ('3' in str): ret += ' ' + repr(i)
print(ret) | import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N, K = LI()
A = LI()
# 最大の長さがxになるような切断回数
def cut_num(x):
ret = sum([math.ceil(i / x) - 1 for i in A])
return ret
ng = 0
ok = max(A)
while abs(ok-ng)>10**(-6):
m = (ng+ok)/2
if cut_num(m) <= K:
ok = m
else:
ng = m
print(math.ceil(ok))
if __name__ == '__main__':
resolve()
| 0 | null | 3,674,902,583,682 | 52 | 99 |
from collections import Counter
N=int(input())
if N==1:
print(0)
exit()
def factorize(n):
out=[]
i = 2
while 1:
if n%i==0:
out.append(i)
n //= i
else:
i += 1
if n == 1:break
if i > int(n**.5+3):
out.append(n)
break
return out
c = Counter(factorize(N))
def n_unique(n):
out = 0
while 1:
if out*(out+1)//2 > n:
return out-1
out += 1
ans = 0
for k in c.keys():
ans += n_unique(c[k])
print(ans) | import sys
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
k = Ii()
a,b = Mi()
for i in range(a,b+1):
if i%k == 0:
print('OK')
exit(0)
print('NG') | 0 | null | 21,734,566,735,660 | 136 | 158 |
n = input()
a = list(map(int, input().split()))
print(' '.join(map(str, reversed(a))))
| n = int(input())
l = list(map(int, input().split()))
sum = 0
for i in range(n):
sum += l[i]
print(min(l), max(l), sum)
| 0 | null | 838,435,001,280 | 53 | 48 |
A,B,C=[int(s) for s in input().split()]
X=int(input())
count=0
while A>=B:
B*=2
count+=1
while B>=C:
C*=2
count+=1
if count<=X:
print('Yes')
else:
print('No')
| # -*- coding: utf-8 -*-
def check(r,g,b):
if g > r and b > g:
return True
else:
return False
A,B,C = map(int, input().split())
K = int(input())
for i in range(K+1):
for j in range(K+1-i):
for k in range(K+1-i-j):
if i+j+k==0:
continue
r = A*(2**i)
g = B*(2**j)
b = C*(2**k)
if check(r, g, b):
print("Yes")
exit()
print("No")
| 1 | 6,888,050,029,816 | null | 101 | 101 |
N = int(input())
if N % 1000 == 0:
ans = 0
else:
ans = 1000 - (N % 1000)
print(ans) | import sys
input = sys.stdin.readline
def main():
n, k = input_list()
# R = グー, S = チョキ, P = パー
R, S, P = input_list()
t = input()
tt = list(t)
for i in range(n - k):
if tt[i] == t[i+k]:
tt[i+k] = "x"
r = tt.count("r") * P
s = tt.count("s") * R
p = tt.count("p") * S
print(r + s + p)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 0 | null | 57,505,649,940,480 | 108 | 251 |
l = int(input())
squre = (l/3)**3
print(squre)
| import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for i in range(1, n):
ans += (n-1) // i
print(ans) | 0 | null | 24,755,762,677,728 | 191 | 73 |
n=input()
L1=[[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]]
L2=[[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]]
L3=[[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]]
L4=[[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]]
Mantion=[L1,L2,L3,L4]
for i in range(n):
b,f,r,v=map(int, raw_input().split())
Mantion[b-1][f-1][r-1]+=v
for j in range(3):
L1_str=map(str, L1[j])
print "",
print " ".join(L1_str)
print "#"*20
for j in range(3):
L2_str=map(str, L2[j])
print "",
print " ".join(L2_str)
print "#"*20
for j in range(3):
L3_str=map(str, L3[j])
print "",
print " ".join(L3_str)
print "#"*20
for j in range(3):
L4_str=map(str, L4[j])
print "",
print " ".join(L4_str) | # -*- coding: utf-8 -*-
class residence(object):
def __init__(self):
one = [0] * 10
two = [0] * 10
three = [0] * 10
self.all = [one, two, three]
residences = [ ]
for i in xrange(4):
residences.append(residence())
n = int(raw_input())
for i in xrange(n):
b, f, r, v = map(int, raw_input().split())
residences[b-1].all[f-1][r-1] += v
for i, residence in enumerate(residences):
for floor in residence.all:
print '',
for index, num in enumerate(floor):
if index == len(floor) - 1:
print num
else:
print num,
if i != len(residences) - 1:
print '####################' | 1 | 1,101,750,459,630 | null | 55 | 55 |
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
F = sorted(list(map(int,input().split())),reverse=True)
if K>=sum(A):
ans = 0
else:
low = 0
high = 10**12
while high-low>1:
mid = (high+low)//2
B = A[:]
cnt = 0
for i in range(N):
if B[i]*F[i]>mid:
cnt += (B[i]-mid//F[i])
if cnt<=K:
high = mid
else:
low = mid
ans = high
print(ans) | from decimal import*
l=Decimal(input())
ans=(l/3)**3
print(ans)
| 0 | null | 106,272,631,437,408 | 290 | 191 |
# coding: utf-8
# Your code here!
N=int(input())
count=-1
for i in range(N//2+1):
count+=1
if N%2==0:
print(count-1)
else:
print(count) | from collections import deque
def init_tree(x, par):
for i in range(x + 1):
par[i] = i
def find(x, par):
q = deque()
q.append(x)
while len(q) > 0:
v = q.pop()
if v == par[v]:
return v
q.append(par[v])
def union(x, y, par, rank):
px, py = find(x, par), find(y, par)
if px == py:
return
if rank[px] < rank[py]:
par[px] = py
return
elif rank[px] == rank[py]:
rank[px] += 1
par[py] = px
n, m, k = map(int, input().split())
par = [0] * (n + 1)
rank = [0] * (n + 1)
init_tree(n, par)
eg = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = map(int, input().split())
union(a, b, par, rank)
eg[a].append(b)
eg[b].append(a)
for _ in range(k):
a, b = map(int, input().split())
eg[a].append(b)
eg[b].append(a)
xs = [0] * (n + 1)
ys = [0] * (n + 1)
for i in range(1, n + 1):
p = find(i, par)
xs[p] += 1
for v in eg[i]:
if p == find(v, par):
ys[i] += 1
ans = [-1] * (n + 1)
for i in range(1, n + 1):
ans[i] += xs[find(i, par)] - ys[i]
ans = [-1] * (n + 1)
for i in range(1, n + 1):
ans[i] += xs[find(i, par)] - ys[i]
print(*ans[1:])
| 0 | null | 107,384,721,997,420 | 283 | 209 |
import numpy as np
from numba import njit
def main():
R, C, K = map(int, input().split())
field = np.full((R+1,C+1), 0, dtype='int64')
dpt = np.full((R+1,C+1,4), 0, dtype='int64')
for i in range(K):
r, c, v = map(int, input().split())
field[r][c] = v
dp(R, C, field, dpt)
print(max(dpt[-1][-1]))
@njit('i4(i4,i4,i8[:,:],i8[:,:,:])', cache=True)
def dp(R, C, field, dpt):
for r in range(1, R+1):
for c in range(1, C+1):
for taken in range(4):
max_v = 0
if taken == 0:
max_v = max(dpt[r-1][c])
max_v = max(dpt[r][c-1][0], max_v)
elif taken == 1:
max_v = max(dpt[r][c-1][taken-1] + field[r][c],
dpt[r][c-1][taken],
max(dpt[r-1][c]) + field[r][c])
else:
max_v = max(dpt[r][c-1][taken-1] + field[r][c],
dpt[r][c-1][taken])
dpt[r][c][taken] = max_v
return 1
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.buffer.readline
R, C, K = map(int, input().split())
G = [[None for j in range(C)] for i in range(R)]
for _ in range(K):
r, c, v = map(int, input().split())
G[r - 1][c - 1] = v
dp = [[0, 0, 0, 0] for _ in range(C)]
for i in range(R):
for j in range(C):
if G[i][j] is not None:
dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
dp[j][2], dp[j][3] = 0, 0
else:
dp[j][0] = max(dp[j])
dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
for j in range(1, C):
if G[i][j] is not None:
dp[j][0] = max(dp[j - 1][0], dp[j][0])
dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
if dp[j - 1][1] != 0:
dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
if dp[j - 1][2] != 0:
dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
else:
dp[j][0] = max(dp[j - 1][0], dp[j][0])
dp[j][1] = max(dp[j - 1][1], dp[j][1])
dp[j][2] = max(dp[j - 1][2], dp[j][2])
dp[j][3] = max(dp[j - 1][3], dp[j][3])
print(max(dp[-1])) | 1 | 5,595,218,118,922 | null | 94 | 94 |
x = int(input())
a = 100
i = 0
while a < x:
i += 1
a += a // 100
print(i)
| import bisect
n, m, k = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
sum_a = [0] * (n + 1)
sum_b = [0] * (m + 1)
for i in range(n):
sum_a[i + 1] = sum_a[i] + aaa[i]
for j in range(m):
sum_b[j + 1] = sum_b[j] + bbb[j]
ans = 0
for i in range(n + 1):
if sum_a[i] > k:
break
tmp = bisect.bisect_right(sum_b, k - sum_a[i])
ans = max(ans, i + tmp - 1)
print(ans) | 0 | null | 18,995,349,021,958 | 159 | 117 |
import sys
read = sys.stdin.buffer.read
n, k, *p = map(int, read().split())
p.sort()
print(sum(p[:k])) | [n, k] = map(int, input().split())
p_list = input().split()
p_list = [int(x) for x in p_list]
p_list.sort()
ans = 0
for i in range(k):
ans += p_list[i]
print(ans) | 1 | 11,646,523,577,124 | null | 120 | 120 |
a,b = list(map(int, input().split()))
if a > b:
sep = '>'
elif a < b:
sep = '<'
else:
sep = '=='
print('a', sep, 'b') | from array import array
def readinput():
n=int(input())
a=array('L',list(map(int,input().split())))
return n,a
count=0
def merge(a,left,mid,right):
INFTY=10**9+1
global count
n1=mid-left
n2=right-mid
#L=[a[left+i] for i in range(n1)]
L=a[left:mid]
L.append(INFTY)
#R=[a[mid+i] for i in range(n2)]
R=a[mid:right]
R.append(INFTY)
i=0;j=0
for k in range(left,right):
if(L[i]<=R[j]):
a[k]=L[i]
i+=1
else:
a[k]=R[j]
j+=1
count+=1
def mergeSort(a,left,right):
if(left+1<right):
mid=(left+right)//2
mergeSort(a,left,mid)
mergeSort(a,mid,right)
merge(a,left,mid,right)
return
def main(n,a):
global count
mergeSort(a,0,n)
return a,count
if __name__=='__main__':
n,a=readinput()
a,count=main(n,a)
print(' '.join(map(str,a)))
print(count)
| 0 | null | 238,729,386,052 | 38 | 26 |
def main():
s = int(input())
mod = 10**9+7
dp = [0] * (s+1)
dp[0] = 1
x = 0
for i in range(1, s+1):
if i-3 >= 0:
x += dp[i-3]
x %= mod
dp[i] = x
print(dp[s])
if __name__ == "__main__":
main()
| S=int(input())
a = [0]*(2000+1)
a[3]=1
for i in range(4, S+1):
a[i] = a[i-3] + a[i-1]
mod=10**9+7
print(a[S]%mod) | 1 | 3,308,674,330,270 | null | 79 | 79 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input().rstrip()
memo = [None] * n
ans = 0
for i in range(n):
if t[i] == 'r':
if i - k < 0 or (0 <= i - k and memo[i - k] != 'p'):
ans += p
memo[i] = 'p'
elif n <= i + k or (i + k < n and t[i + k] != 's'):
memo[i] = 'r'
else:
memo[i] = 's'
if t[i] == 's':
if i - k < 0 or (0 <= i - k and memo[i - k] != 'r'):
ans += r
memo[i] = 'r'
elif n <= i + k or (i + k < n and t[i + k] != 'p'):
memo[i] = 's'
else:
memo[i] = 'p'
if t[i] == 'p':
if i - k < 0 or (0 <= i - k and memo[i - k] != 's'):
ans += s
memo[i] = 's'
elif n <= i + k or (i + k < n and t[i + k] != 'r'):
memo[i] = 'p'
else:
memo[i] = 'r'
print(ans)
| n, m = map( int, input().split() )
a = list( map( int, input().split() ) )
def f( a_k ): # 2で割り切れる回数
count = 0
while a_k % 2 == 0:
count += 1
a_k = a_k // 2
return count
b = []
f_0 = f( a[ 0 ] )
for a_k in a:
f_k = f( a_k )
if f_k != f_0:
print( 0 )
exit()
b.append( a_k // pow( 2, f_k ) )
import math
def lcm( x, y ):
return x * y // math.gcd( x, y )
b_lcm = 1
for b_k in b:
b_lcm = lcm( b_lcm, b_k )
a_lcm = b_lcm * pow( 2, f_0 )
# print( b_lcm, f_0, b )
print( ( m + a_lcm // 2 ) // a_lcm ) | 0 | null | 104,188,485,440,468 | 251 | 247 |
x, y = map(int, input().split())
if(x < y):
for i in range(0, y):
print(x, end = '')
else:
for i in range(0, x):
print(y, end = '')
| a, b = input().split()
na = int(a)
nb = int(b)
sa = a * nb
sb = b * na
print(sa if sa < sb else sb)
| 1 | 84,623,183,726,368 | null | 232 | 232 |
r,c = [int(i) for i in input().split()]
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
a[i] = [int(j) for j in input().split()]
for i in range(r):
rowSum = 0
for j in range(c):
rowSum += a[i][j]
a[i].append(rowSum)
for i in range(c+1):
columnSum = 0
for j in range(r):
columnSum += a[j][i]
a[r][i] = columnSum
for i in range(r+1):
for j in range(c):
print(a[i][j],end=' ')
print(a[i][c]) | r, c = map(int, input().split())
element = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
element[i].append(sum(element[i]))
for i in range(r):
for j in range(c):
print(element[i][j],end="")
print(' ',end="")
print(element[i][c])
for i in range(c):
num = 0
for j in range(r):
num += element[j][i]
print(num, end="")
print(' ',end="")
b = 0
for i in range(r):
b += element[i][c]
print(b)
| 1 | 1,353,673,164,440 | null | 59 | 59 |
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
for i in range(1, N+1):
A[i] += A[i-1]
i = N
total = 0
ans = 0
for j in range(M+1):
total += B[j]
while i >= 0 and A[i]+total > K:
i -= 1
if A[i]+total <= K:
ans = max(ans, i+j)
print(ans) | n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0 for i in range(n)]
B=[0 for i in range(m)]
A[0]=a[0]
B[0]=b[0]
for i in range(n-1):
A[i+1]=a[i+1]+A[i]
for i in range(m-1):
B[i+1]=b[i+1]+B[i]
ans=0
A.insert(0,0)
B.insert(0,0)
for i in range(n+1):
x=0
y=m
j=(x+y)//2
if A[i]+B[m]<=k:
ans=max(ans,i+m)
elif not A[i]+B[0]>k:
while y-x>1:
if A[i]+B[j]<=k:
x=j
else:
y=j
j=(x+y)//2
ans=max(ans,i+x)
print(ans)
| 1 | 10,732,543,100,890 | null | 117 | 117 |
import sys
n = int(input())
for a in range(-200, 201):
for b in range(-200, 201):
if a * a * a * a * a - b * b * b * b * b == n:
print(a, b)
sys.exit(0) | n = int(input())
for i in range(1000):
for j in range(-1000,1000):
if (i**5-j**5)==n:
print(i,j)
exit() | 1 | 25,625,843,989,200 | null | 156 | 156 |
import sys
N = int(input())
if N % 2 != 0:
print(0)
sys.exit()
N //= 2
ans = 0
while N != 0:
ans += N//5
N //= 5
print(ans)
| N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
def count_bigger_x(x):
cnt = 0
piv = N-1
for a in A:
while piv >= 0 and a + A[piv] >= x:
piv -= 1
cnt += N - piv - 1
return cnt
def is_ok(x):
cnt = count_bigger_x(x)
return cnt >= M
def bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
x = bisect(2 * A[-1] + 1, 2 * A[0] - 1)
ans = 0
piv = N-1
for a in A:
while piv >= 0 and a + A[piv] >= x:
piv -= 1
ans += (N - piv - 1) * a
ans *= 2
ans -= 1 * x * (count_bigger_x(x) - M)
print(ans)
| 0 | null | 111,992,754,166,112 | 258 | 252 |
import math
n = int(input())
a = list(map(int, input().split()))
mod = int(1e+9+7)
max_val = int(1e+6+1)
def make_kago(x):
kago = [0 for _ in range(x+1)]
sosuu = []
for i in range(2,x+1):
if kago[i] != 0:
continue
sosuu.append(i)
for j in range(i, x+1, i):
if kago[j] == 0:
kago[j] = i
return kago, sosuu
kago, sosuu = make_kago(max_val)
def prime_factorization(x):
if x==0 or x==1:
return None
soinsuu = []
while x!=1:
soinsuu.append(kago[int(x)])
x = x/kago[int(x)]
soinsuu_dict = dict()
for i in range(len(soinsuu)):
if soinsuu[i] not in soinsuu_dict:
soinsuu_dict[soinsuu[i]] = 1
else:
soinsuu_dict[soinsuu[i]]+=1
return soinsuu_dict
#%%
max_soinsuu = [0 for _ in range(int(1e+6+1))]
#%%
for i in range(n):
soinsuu_dict = prime_factorization(a[i])
if soinsuu_dict == None:
continue
for k, v in soinsuu_dict.items():
if max_soinsuu[k] < v:
max_soinsuu[k] = v
lcm = 1
for i in range(max_val):
if max_soinsuu[i] != 0:
lcm = (lcm*i**max_soinsuu[i])%mod
answer = 0
for i in range(n):
answer = (answer + lcm*pow(a[i],mod-2,mod))%mod
print(answer) | from functools import reduce
from fractions import gcd
mod = 10**9 + 7
n, *A = map(int, open(0).read().split())
if len(A) == 1:
print(1)
else:
l = reduce(lambda x, y: x*y // gcd(x, y), A) % mod
s = 0
for a in A:
s += l * pow(a, mod-2, mod)
s %= mod
print(s) | 1 | 88,048,782,177,180 | null | 235 | 235 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum # accumulate
def solve():
A, B, C, K = MI()
na = min(A, K)
K -= na
nb = min(B, K)
K -= nb
nc = min(C, K)
print(na - nc)
if __name__ == '__main__':
solve()
| a,b,c,k = map(int, input().split())
goukei = 0
if k>=a:
k -= a
goukei += a
else:
goukei += k
k = 0
if k>=b:
k -= b
else:
k = 0
if k>0:
goukei -= k
print(goukei) | 1 | 21,792,130,771,000 | null | 148 | 148 |
def prime_numbers(n):
cnds = [True] * n
for x in xrange(2, int(n**0.5 + 1)):
if cnds[x]:
for m in xrange(2*x, n, x):
cnds[m] = False
return [i for i in xrange(2, n) if cnds[i]]
def is_prime(n):
return all(n % m for m in primes if m < n)
primes = prime_numbers(10**4)
N = input()
print sum(is_prime(input()) for i in range(N)) | def is_prime(x):
if x == 1:
return False
l = x ** 0.5
n = 2
while n <= l:
if x % n == 0:
return False
n += 1
return True
import sys
def solve():
file_input = sys.stdin
N = file_input.readline()
cnt = 0
for l in file_input:
x = int(l)
if is_prime(x):
cnt += 1
print(cnt)
solve() | 1 | 10,256,094,240 | null | 12 | 12 |
A = int(input())
B = int(input())
AB = [A,B]
Ans = [x for x in range(1,4) if x not in AB]
print(Ans[0]) | n = 6
a = int(input())
b = int(input())
print(n - a - b) | 1 | 110,813,548,146,542 | null | 254 | 254 |
str1 = list(input())
str2 = list(input())
answer = len(str2)
for i in range(len(str1)-len(str2)+1):
count = 0
for j in range(len(str2)):
if not str1[i+j] == str2[j]:
count += 1
if count < answer:
answer = count
print(answer)
| S = input()
T = input()
m = 0
for i in range(len(S) - len(T) + 1):
cnt = 0
for j in range(len(T)):
if S[i+j] == T[j]:
cnt += 1
m = max(m, cnt)
ANS = len(T) - m
print(ANS) | 1 | 3,691,178,726,624 | null | 82 | 82 |
n = int(input())
count = 0
ans = 'No'
for i in range(n):
a , b = map(int,input().split(' '))
if a!=b:
count = 0
else:
count += 1
if count == 3:
ans = 'Yes'
print(ans) | N = int(input())
cnt = 0
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
cnt += 1
else:
cnt = 0
if cnt == 3:
print("Yes")
break
else:
print("No")
| 1 | 2,470,830,920,960 | null | 72 | 72 |
n = int(input())
a = list(map(int, input().split()))
que = [-1, -1, -1]
ans = 1
for i in range(n):
if que[0]+1 == a[i]:
if que[0] == que[1] and que[0] == que[2]:
ans *= 3
ans %= (10**9 + 7)
elif que[0] == que[1]:
ans *= 2
ans %= (10**9 + 7)
que[0] = a[i]
elif que[1]+1 == a[i]:
if que[1] == que[2]:
ans *= 2
ans %= (10**9 + 7)
que[1] = a[i]
elif que[2]+1 == a[i]:
que[2] = a[i]
else:
ans = 0
break
print(ans)
| N,M = map(int,input().split())
a = [-1]*N
ans = 0
for i in range(M):
s,c = map(int,input().split())
if a[s-1] == -1:
a[s-1] = c
elif a[s-1] != c:
ans = -1
break
if a[0] == 0 and N>1:
ans = -1
if ans != -1:
if a[0] == -1 and N>1:
a[0] = 1
if a[0] == -1 and N == 1:
a[0] = 0
for i in range(N):
if a[i] == -1:
a[i] = 0
a[i] = str(a[i])
ans = "".join(a)
print(ans)
| 0 | null | 95,025,625,591,748 | 268 | 208 |
def main():
n=int(input())
u,k,v=0,0,[[] for _ in range(n+1)]
for i in range(n):
l=list(map(int,input().split()))
u=l[0]
for j in l[2:]:
v[u].append(j)
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(s,t):
d[s]=t
for i in v[s]:
if d[i]==0:
t=dfs(i,t+1)
f[s]=t+1
return t+1
s,t=1,1
while 0 in d[1:]:
T=dfs(s,t)
for i in range(1,n+1):
if d[i]==0:
s=i
t=T+1
break
for i in range(1,n+1):
print(i,d[i],f[i])
if __name__ == '__main__':
main()
| import sys
def input():
return sys.stdin.readline().rstrip()
def dfs(c, n, G, ans):
count = c
for i, flag in enumerate(G[n]):
if flag == 1 and ans[i][0] == 0:
count += 1
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
count = ans[i][2]
else:
return count + 1
def main():
n = int(input())
G = [[0] * n for _ in range(n)]
ans = [[0] * 3 for _ in range(n)]
for i in range(n):
u, k, *v = map(int, input().split())
for j in range(k):
G[u-1][v[j]-1] = 1
count = 1
for i in range(n):
if ans[i][0] == 0:
ans[i][0] = i + 1
ans[i][1] = count
ans[i][2] = dfs(count, i, G, ans)
count = ans[i][2] + 1
for i in range(n):
print(*ans[i])
if __name__ == '__main__':
main()
| 1 | 2,806,877,220 | null | 8 | 8 |
n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
print("{0} {1} {2}".format(min(a), max(a), sum(a))) | _, lis = input(), list(map(int, input().split()))
print("{} {} {}".format(min(lis), max(lis), sum(lis)))
| 1 | 726,550,970,980 | null | 48 | 48 |
def med(l):
t = len(l)
if t%2:
return l[t//2]
else: return (l[t//2]+l[t//2-1])/2
n = int(input())
a = []
b = []
for i in range(n):
x,y = map(int,input().split())
a+=[x]
b+=[y]
a.sort()
b.sort()
if n%2==0:
print(int((med(b)-med(a))*2)+1)
else:
print(med(b)-med(a)+1)
| n, *AB = map(int, open(0).read().split())
a = sorted(AB[::2])
b = sorted(AB[1::2])
if n % 2 == 0:
print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)
else:
print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1) | 1 | 17,264,312,989,630 | null | 137 | 137 |
n = int(input())
p = []
q = []
r = []
for i in range(2,(int(n**0.5)+1)):
N = n
if N%i == 0:
p.append(i)
for i in range(2,(int(n**0.5)+1)):
N = n - 1
if N%i == 0:
r.append(i)
if i != N//i:
r.append(N//i)
for i in range(len(p)):
N = n
while N % p[i] == 0:
N = N / p[i]
if N % p[i] == 1:
q.append(p[i])
for i in range(len(r)):
if n % r[i] == 1:
q.append(r[i])
if n == 2:
print(1)
else:
print(len(q)+2) | n,m,k = list(map(int,input().split(" ")))
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
cnt = 0
ans = 0
j = m
t = sum(b)
for i in range(n+1):
while j>0:
if t>k: #aのみの場合の処理が足りない(常にjでスキップされてしまう)
j -= 1
t -= b[j]
else:break
if t<=k:ans = max(ans,i+j)
if i==n:break
t += a[i]
print(ans) | 0 | null | 25,942,976,936,948 | 183 | 117 |
S=input()
N=len(S)
M=[]
for i in range(N):
M.append('x')
L=''.join(M)
print(L) | s = input()
x = ""
for i in range(len(s)):
x += "x"
print(x) | 1 | 73,202,008,565,920 | null | 221 | 221 |
import numpy as np
N = int(input())
X = np.zeros([N,4], dtype=int)
for i in range(N):
X[i,0], X[i,1] = map(int, input().split())
X[i,2], X[i,3] = X[i,0] - X[i,1], X[i,0] + X[i,1]
col_num = 3
X = X[np.argsort(X[:, col_num])]
cnt = 1
r_min = X[0,3]
for i in range(1,N):
if X[i,2] >= r_min:
cnt += 1
r_min = X[i,3]
print(cnt) | N, *A = map(int, open(0).read().split())
X = [(x-l, x+l) for x, l in zip(*[iter(A)]*2)]
X.sort()
ans = 1
L, R = X[0]
for l, r in X[1:]:
if R <= l:
ans += 1
L = l
R = r
elif R > r:
R = r
print(ans)
| 1 | 90,038,571,576,492 | null | 237 | 237 |
import sys
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()
H = inl()
H.sort()
def solve():
if k >= n:
return 0
return sum(H[: n - k])
print(solve())
| '''
def main():
S = input()
cnt = 0
ans = 0
f = 1
for i in range(3):
if S[i] == 'R':
cnt += 1
else:
cnt = 0
ans = max(ans, cnt)
print(ans)
'''
def main():
S = input()
p = S[0] == 'R'
q = S[1] == 'R'
r = S[2] == 'R'
if p and q and r :
print(3)
elif (p and q) or (q and r):
print(2)
elif p or q or r:
print(1)
else:
print(0)
if __name__ == "__main__":
main() | 0 | null | 42,172,624,954,440 | 227 | 90 |
N, M = map(int, input().split())
A = sorted(list(map(int,input().split())), reverse=True)
# jとの組み合わせがx以上になるiの個数
def combinations(x):
s = 0
i = 0
for j in reversed(range(N)):
while i<N and A[i]+A[j]>=x:
i += 1
s += i
return s
#↑のような組み合わせの合計幸福度
def koufukudo(x):
s = 0
si = 0
i = 0
for j in reversed(range(N)):
while i<N and A[i]+A[j]>=x:
si += A[i]
i += 1
s += si + A[j]*i
return s
#
def bsearch(l, u):
m = (l+u)//2
c = combinations(m)
# print(f"m{m}, c{c},c-M{c-M}")
if c<M:
return bsearch(l, m)
else:
if l==m:
return (l, c-M)
return bsearch(m, u)
x, dm = bsearch(0, A[0]*2+1)
print(koufukudo(x)-dm*x) | x = input()
y = x.split(" ")
y = [int(z) for z in y]
w = y[0]
h = y[1]
x = y[2]
r = y[4]
y = y[3]
if (x <= w-r and x >= r) and (y <= h-r and y >= r):
print("Yes")
else:
print("No") | 0 | null | 54,374,194,651,490 | 252 | 41 |
n,m = map(int,input().split())
coins = list(map(int,input().split()))
dp = [20**10]*(n+1)
dp[0] = 0
for coin in coins:
for price in range(coin,n+1):
dp[price] = min(dp[price],dp[price-coin]+1)
print(dp[n])
| import string
N = int(input())
S = input()
# string.ascii_uppercase を覚えよう
a = string.ascii_uppercase
# a = ABCDEFGHIJKLMNOPQRSTUVWXYZ
ans = ''
for s in S:
num = (a.index(s) + N) % len(a)
ans += a[num]
print(ans)
| 0 | null | 67,647,032,159,872 | 28 | 271 |
a, b = map(int, input().split())
print("{0} {1} {2:.12f}".format(a // b, a % b, a / b))
| # -*- coding: utf-8 -*-
def bubbleSort(A, N):
flag = True # 未ソートの可能性があるか
i = 0 # 未ソート部分の先頭
inv_num = 0 # 転倒数
while flag:
flag = False
for j in range(N - 1, i, -1):
if A[j] < A[j - 1]:
A[j], A[j - 1] = A[j - 1], A[j]
flag = True
inv_num += 1
i += 1
return A, inv_num
if __name__ == '__main__':
N = int(input())
A = [int(a) for a in input().split(" ")]
A, inv_num = bubbleSort(A, N)
print(" ".join(map(str, A)))
print(inv_num)
| 0 | null | 298,010,107,288 | 45 | 14 |
str = input()
s_ans = 'Yes'
if len(str)%2 == 1:
s_ans ='No'
else:
for i in range(0,len(str),2):
moji = str[i:i+2]
if str[i:i+2] != 'hi':
s_ans = 'No'
break
print(s_ans) | S=input()
if len(S)%2==1: print('No'); exit()
for i in range(len(S)//2):
if S[(i*2)]+S[(i*2)+1]!='hi':print('No'); exit()
print('Yes') | 1 | 53,173,145,856,668 | null | 199 | 199 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
cnt = [0] * (max(A)+2)
cnt[0] = 3
ans = 1
for a in A:
ans *= cnt[a]-cnt[a+1]
cnt[a+1] += 1
ans %= mod
print(ans)
| import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def resolve():
N = I()
A = LI()
# color_number[i][j]: [0, i)でj番目に多い色の人数
color_number = [[0, 0, 0] for _ in range(N)]
for i in range(N-1):
if A[i] in color_number[i]:
idx = color_number[i].index(A[i])
else:
idx = -1
for j in range(3):
if j==idx:
color_number[i+1][j] = color_number[i][j] + 1
else:
color_number[i+1][j] = color_number[i][j]
ans = 1
for i in range(N):
ans *= color_number[i].count(A[i])
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve() | 1 | 129,784,242,174,660 | null | 268 | 268 |
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
def run():
H, N = map(int, sysread().split())
AB = list(map(int, read().split()))
A = AB[::2]
B = AB[1::2]
Amax = max(A)
INF = float('inf')
dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
for j in range(H+Amax+1):
tmp = j - A[i]
if tmp >= 0:
dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
elif j == H and tmp < 0:
dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
else:
dp[i+1][j] = dp[i][j]
ret = min(dp[N][H:])
print(ret)
if __name__ == "__main__":
run() | INF = 1 << 60
h, n = map(int, input().split())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
a[i], b[i] = map(int, input().split())
MAX = h - 1 + max(a)
dp = [[INF for j in range(MAX + 1)] for i in range(n)]
dp[0][0] = 0
if 0 <= a[0] < MAX + 1:
dp[0][a[0]] = b[0]
for j in range(MAX + 1):
if 0 <= j - a[0] < MAX + 1:
dp[0][j] = min(dp[0][j], dp[0][j - a[0]] + b[0])
for i in range(1, n):
for j in range(MAX + 1):
dp[i][j] = min(dp[i][j], dp[i - 1][j])
if 0 <= j - a[i] < MAX + 1:
dp[i][j] = min(dp[i][j], dp[i][j - a[i]] + b[i])
ans = INF
for j in range(h, MAX + 1):
ans = min(ans, dp[-1][j])
print(ans) | 1 | 81,138,813,972,380 | null | 229 | 229 |
n = int(raw_input())
ls = []
for i in range(3,n+1):
if i%3==0 or "3" in str(i) :
ls.append(i)
print " " + " ".join(map(str,ls)) |
N = int(input())
S = input()
ris = [i for i, s in enumerate(S) if s == "R"]
gis = [i for i, s in enumerate(S) if s == "G"]
bis = [i for i, s in enumerate(S) if s == "B"]
all = len(ris) * len(gis) * len(bis)
cnt = 0
for i in range(N):
for j in range(i+1, N):
k = 2*j - i
if 0 <= k < N:
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
ans = all - cnt
print(ans)
| 0 | null | 18,430,709,030,162 | 52 | 175 |
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())
x = I()
A = []
As = []
B = []
Bs = []
for i in range(250):
n = i ** 5
A.append(i)
As.append(n)
B.append(i)
Bs.append(n)
B.append(-i)
Bs.append(-n)
xs = [a-x for a in As]
for i, x in enumerate(xs):
if x in Bs:
print(A[i], B[Bs.index(x)])
break
| K = int(input())
S = input()
if len(S) > K:
S_short = S[:K]
print("{}...".format(S_short))
else:
print(S) | 0 | null | 22,789,278,685,150 | 156 | 143 |
# usr/bin/python
# coding: utf-8
################################################################################
#Write a program which prints multiplication tables in the following format:
#
#1x1=1
#1x2=2
#.
#.
#9x8=72
#9x9=81
#
################################################################################
if __name__ == "__main__":
for i in range(1, 10):
for j in range(1, 10):
print("{0}x{1}={2}".format(i,j,i*j))
exit(0) | for j in range(1,10,1):
for k in range(1,10,1):
print("{}x{}={}".format(j,k,j*k))
| 1 | 3,124,808 | null | 1 | 1 |
def main():
N = int(input())
print(int((N+1)/2))
main()
| n,k,s = map(int,input().split())
u = []
if n == k:
for i in range(n):
u.append(s)
else:
if s%2==0:
for i in range(k+1):
u.append(int(s/2))
for i in range(n-k-1):
u.append(10**9-1)
else:
if s==1:
for i in range(k):
u.append(1)
for i in range(n-k):
u.append(10**9)
else:
if k%2==0:
u.append(int((s-1)/2))
for i in range(int(k/2)):
u.append(int((s+1)/2))
u.append(int((s-1)/2))
for i in range(n-k-1):
u.append(10**9)
else:
for i in range(int((k+1)/2)):
u.append(int((s+1)/2))
u.append(int((s-1)/2))
for i in range(n-k-1):
u.append(10**9)
print(' '.join(map(str,u))) | 0 | null | 74,941,312,370,820 | 206 | 238 |
n=int(input())
if n%2==1:
print("0")
exit()
count=0
for i in range(1,30):
count+=n//(2*5**i)
print(count) | n=int(input())
ans=0
d=5
for i in range(36):
ans+=n//d//2
d*=5
print(0 if n%2 else ans) | 1 | 116,196,215,205,992 | null | 258 | 258 |
import math
h,w=map(int,input().split())
if h>2 and w>1:
print(math.ceil(h*w/2))
if h==1 or w==1:
print(1) | from heapq import heappush,heappop
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
heappush(b,(a[i],i+1))
a=[]
for i in range(n):
c,d=heappop(b)
a.append(d)
print(*a) | 0 | null | 115,680,105,602,600 | 196 | 299 |
X = int(input())
a = X // 500
X -= a * 500
b = X // 5
print(a * 1000 + b * 5) | def main():
X = int(input())
p, r = divmod(X, 500)
q, r = divmod(r, 5)
print(p * 1000 + q * 5)
if __name__ == '__main__':
main()
| 1 | 42,778,213,080,064 | null | 185 | 185 |
while 1 :
a,b = map(int,raw_input().split())
if not a and not b:
break
if a < b:
print "%d %d" % (a , b)
else :
print "%d %d" % (b , a) | import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
N, K = NMI()
A = NLI()
F = NLI()
A.sort()
F.sort(reverse=True)
ok = 10**13
ng = 0
for i in range(100):
mid = (ok+ng) // 2
limits = [mid//f for f in F]
ks = [max(a-l, 0) for a, l in zip(A, limits)]
if sum(ks) <= K:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
main() | 0 | null | 82,476,335,540,830 | 43 | 290 |
a,b= map(int,input().split());
if a < b :
print("a < b" );
elif a > b :
print("a > b" );
elif a == b :
print("a == b") ; | from collections import deque
s = input()
q = int(input())
#flag=0 でleft, flag=1でrightが先頭
flag = 0
cnt = 0
d = deque(s)
for _ in range(q):
lis = list(input().split())
if lis[0] == "1":
if flag:
flag = 0
else:
flag = 1
cnt += 1
else:
if lis[1] == '1':
if flag:
d.append(lis[2])
else:
d.appendleft(lis[2])
else:
if flag:
d.appendleft(lis[2])
else:
d.append(lis[2])
d = list(d)
if cnt % 2 != 0:
d = d[::-1]
print(''.join(d)) | 0 | null | 28,993,463,008,752 | 38 | 204 |
import math
a, b, x = map(float, input().split())
if a * a * b <= x * 2:
h = 2 * (b - x / a / a)
ret = math.degrees(math.atan2(h, a))
else:
h = 2 * x / a / b
ret = 90 - math.degrees(math.atan2(h, b))
print(ret)
| from enum import IntEnum
class Direction(IntEnum):
NORTH = 0
EAST = 1
SOUTH = 2
WEST = 3
class Dice:
"""Dice class implements the structure of a dice
having six faces.
"""
def __init__(self, v1, v2, v3, v4, v5, v6):
self.top = 1
self.heading = Direction.NORTH
self.values = [v1, v2, v3, v4, v5, v6]
def to_dice_axis(self, d):
return (d - self.heading) % 4
def to_plain_axis(self, d):
return (self.heading + d) % 4
def roll(self, d):
faces = [[(2, Direction.NORTH), (6, Direction.NORTH),
(6, Direction.WEST), (6, Direction.EAST),
(6, Direction.SOUTH), (5, Direction.SOUTH)],
[(4, Direction.EAST), (4, Direction.NORTH),
(2, Direction.NORTH), (5, Direction.NORTH),
(3, Direction.NORTH), (4, Direction.WEST)],
[(5, Direction.SOUTH), (1, Direction.NORTH),
(1, Direction.EAST), (1, Direction.WEST),
(1, Direction.SOUTH), (2, Direction.NORTH)],
[(3, Direction.WEST), (3, Direction.NORTH),
(5, Direction.NORTH), (2, Direction.NORTH),
(4, Direction.NORTH), (3, Direction.EAST)]]
f, nd = faces[self.to_dice_axis(d)][self.top-1]
self.top = f
self.heading = self.to_plain_axis(nd)
def value(self):
return self.values[self.top-1]
def run():
values = [int(v) for v in input().split()]
dice = Dice(*values)
for d in input():
if d == 'N':
dice.roll(Direction.NORTH)
if d == 'E':
dice.roll(Direction.EAST)
if d == 'S':
dice.roll(Direction.SOUTH)
if d == 'W':
dice.roll(Direction.WEST)
print(dice.value())
if __name__ == '__main__':
run()
| 0 | null | 81,965,754,808,728 | 289 | 33 |
x=input()
i=1
while (x!='0'):
print("Case {0}: {1}".format(i,x));
i+=1;
x=input()
| N = int(input())
A = list(map(int,input().split()))
A.sort()
if N==2:
print(max(A))
exit()
ans = A.pop()
n = N-2
while A:
a = A.pop()
for _ in range(2):
n -= 1
ans += a
if n==0:
print(ans)
exit() | 0 | null | 4,833,438,315,402 | 42 | 111 |
for i in range(1, 10):
for j in range(1, 10):
print '%dx%d=%d' % (i, j, i * j) | import sys
def resolve(in_):
N = int(next(sys.stdin.buffer))
P = map(int, next(sys.stdin.buffer).split())
min_ = 200001
ans = 0
for p in P:
if p <= min_:
ans += 1
min_ = p
return ans
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| 0 | null | 42,823,571,872,062 | 1 | 233 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
D = int(readline())
C = list(map(int,readline().split()))
score = []
for i in range(D):
s = list(map(int,readline().split()))
score.append(s)
t = list(map(int,read().split()))
last = [0] * 26
S = 0
for d in range(D):
select = t[d]-1
S += score[d][select]
last[select] = d+1
for i in range(26):
S -= C[i] * (d+1-last[i])
print(S) | D = int(input())
c = list(map(int, input().split()))
#増加する満足度表 [日数][種類]
s = []
for i in range(D):
l = list(map(int, input().split()))
s.append(l)
#開催するコンテストタイプ[日数]
t = [int(input()) for j in range(D)]
last = [0]*26 #最後に開催した日
SP = 0
dis = 0
for k in range(D): #満足度の計算
SP += s[k][t[k]-1]
last[t[k]-1] = k + 1 #開催日の更新
for m in range(26):
SP -= c[m] * (k + 1 - last[m])
print(SP) | 1 | 9,971,501,393,658 | null | 114 | 114 |
N = int(input())
A = [int(i) for i in input().split()]
A1 = 1
if 0 in A:
print(0)
else:
for j in range(N):
A1 *= A[j]
if A1>10**18:
print(-1)
break
else:
print(A1) | input()
a=1
d=1000000000000000000
for i in input().split():
a=min(a*int(i),d+1)
print([a,-1][a>d]) | 1 | 16,287,305,748,406 | null | 134 | 134 |
x,y=list(map(int, input().split()))
x,y=list(map(int, input().split()))
if y==1:
print(1)
else:
print(0) | for n in range(1, 10):
for m in range(1, 10):
print(str(n) + "x" + str(m) + "=" + str(n*m)) | 0 | null | 62,296,933,858,910 | 264 | 1 |
def main():
S = input()
def an_area(S):
ans = 0
stack_in = []
stack_out = []
for i,ch in enumerate(S):
if ch == '\\':
stack_in.append(i)
elif stack_in and ch == '/':
j = stack_in.pop()
cur = i - j
stack_out.append((j,i,cur))
ans += cur
return ans,stack_out
ans, l = an_area(S)
if ans == 0:
print(ans)
print(len(l))
return
l.sort()
pre_le, pre_ri = l[0][0], l[0][1]
pre_ar = 0
areas = []
for le,ri,ar in l:
if pre_le <= ri <= pre_ri:
pre_ar += ar
else:
areas.append(pre_ar)
pre_ar = ar
pre_le, pre_ri = le, ri
else:
areas.append(pre_ar)
print(ans)
print(len(areas),*areas)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
def main():
t = input().strip()
s = []
# A = 0
ans = []
prevA = 0
for i in range(len(t)):
if t[i] == '\\':
s.append(i)
elif len(s) > 0 and t[i] == '/':
p = s.pop()
k = i - p
ans.append((p, k))
q = 0
while len(ans) > 0:
# print(ans)
g, h = ans[-1]
if g >= p:
q += h
ans.pop()
else:
break
# for j in range(len(ans) - len(s)):
# print('i: ', i)
# print('j: ', j)
# print('ans: ', ans)
# q += ans.pop()
# print('q: ', q)
if q != 0:
ans.append((p, q))
# elif len(s) > 0 and t[i] == '_':
# A += 1
v = 0
for i in range(len(ans)):
v += ans[i][1]
print(v)
print(len(ans), end='')
for i in range(len(ans)):
print(' {}'.format(ans[i][1]), end='')
print('')
if __name__ == '__main__':
main()
| 1 | 55,558,619,910 | null | 21 | 21 |
s = input()
q = int(input())
for _ in range(q):
query = list(input().split())
l,r = map(int,query[1:3])
if query[0] == 'replace':
p = query[3]
s = s[:l] + p + s[r+1:]
elif query[0] == 'reverse':
s = s[:l] + ''.join(list(reversed(s[l:r+1]))) + s[r+1:]
else:
print(s[l:r+1])
| #!/usr/bin/env python3
def main():
N, K = map(int, input().split())
for i in range(10 ** 9):
if N <= K ** i - 1:
print(i)
break
if __name__ == '__main__':
main()
| 0 | null | 33,135,956,993,370 | 68 | 212 |
import sys
input = sys.stdin.readline
n = int(input())
print(8 - int((n - 400) / 200))
| from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")
# 処理内容
def main():
X = int(input())
print(10 - X // 200)
if __name__ == '__main__':
main() | 1 | 6,727,791,080,220 | null | 100 | 100 |
class UnionFindTree():
def __init__(self, N):
self.N = N
self.__parent_of = [None] * N
self.__rank_of = [0] * N
self.__size = [1] * N
def root(self, value):
if self.__parent_of[value] is None:
return value
else:
self.__parent_of[value] = self.root(self.__parent_of[value])
return self.__parent_of[value]
def unite(self, a, b):
r1 = self.root(a)
r2 = self.root(b)
if r1 != r2:
if self.__rank_of[r1] < self.__rank_of[r2]:
self.__parent_of[r1] = r2
self.__size[r2] += self.__size[r1]
else:
self.__parent_of[r2] = r1
self.__size[r1] += self.__size[r2]
if self.__rank_of[r1] == self.__rank_of[r2]:
self.__rank_of[r1] += 1
def is_same(self, a, b):
return self.root(a) == self.root(b)
def size(self, a):
return self.__size[self.root(a)]
def groups(self):
groups = {}
for k in range(self.N):
r = self.root(k)
if r not in groups:
groups[r] = []
groups[r].append(k)
return [groups[x] for x in groups]
def main():
N, M = map(int, input().split())
uft = UnionFindTree(N)
for _ in range(M):
A, B = map(int, input().split())
uft.unite(A-1, B-1)
ans = 0
for g in uft.groups():
ans = max(ans, len(g))
print(ans)
if __name__ == "__main__":
main()
| n, p = map(int, input().split())
s = input()
if 10%p==0:
ans = 0
for r in range(n):
if int(s[r])%p == 0:
ans += r+1
print(ans)
exit()
d = [0]*(n+1)
ten = 1
for i in range(n-1, -1, -1):
a = int(s[i])*ten%p
d[i] = (d[i+1]+a)%p
ten *= 10
ten %= p
cnt = [0]*p
ans = 0
for i in range(n, -1, -1):
ans += cnt[d[i]]
cnt[d[i]] += 1
print(ans) | 0 | null | 31,280,190,606,860 | 84 | 205 |
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
s=sum(A)
SA=[0]
for a in A:
SA.append(SA[-1]+a)
for i in range(n+1):
SA[i]=s-SA[i]
l,r=0,2*max(A)+1
import bisect
def chk(x):
ct=0
for a in A:
ct+=n-bisect.bisect_left(A,max(x-a,0))
if ct>=m:
return True
else:
return False
def count(x):
ct=0
for a in A:
ct+=n-bisect.bisect_left(A,max(x-a,0))
return ct
while r-l>1:
mid=(l+r)//2
if chk(mid):
l=mid
else:
r=mid
ans=0
for a in A:
aa=bisect.bisect_left(A,max(l-a,0))
ans+=SA[aa]+a*(n-aa)
print(ans-l*(count(l)-m))
| import bisect
if __name__ == '__main__':
def check(mid):
count = 0
for i in range(n):
position = bisect.bisect_left(a, (mid - a[i]))
count += (n - position)
return count < m
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
# 左手でa[i]の手を握るとする
# a[i]を持っているときに和がx未満になるときの右手の数字はx - a[i]未満の数字である
# lower_bound
# この値をNから引くことで和がx以上になるペアの個数がわかる
# この値の合計がM未満になればそこが最大の幸福度である
# 要するに、M個のペアを作るためには最大いくらの和を採用できるかを二分探索する
ng = 0
ok = 10 ** 5 * (n + 1)
while 1 < abs(ok - ng):
# mid -> boundとなる和。これより大きい和をもつペアをM個作れるかを判定する
mid = (ok + ng) // 2
c = check(mid)
# ペアの個数がmより小さい場合は、okの範囲を下げる
if c:
ok = mid
# そうでない場合はまだ余裕があるので、ngをあげる
else:
ng = mid
# ここが終了した時点でngにはm個以上のペアを作るための最大のboundが入っている
# upper_boundで左手にa[i]がある場合のng - a[i]の数を判定する
# ansに求めた数 * a[i] + 右手に持つ幸福度の総和を足す
# mから求めた数を引く
ans = 0
sum_array = [0] * (n + 1)
# 累積和で高速化をする
# (x + a[i]) + (x + a[i + 1) + (x + a[i + 2]).....
# -> (x * 個数) * (a[i] + a[i + 1] + a[i + 2])
for i in range(n):
sum_array[i + 1] = sum_array[i] + a[i]
for i in range(n):
position = bisect.bisect_right(a, ng - a[i])
ans += (n - position) * a[i] + sum_array[n] - sum_array[position]
m -= (n - position)
ans += ng * m
print(ans)
| 1 | 108,295,560,315,200 | null | 252 | 252 |
a,b,c,d=map(float,input().split())
e=(c-a)**2
f=(d-b)**2
print(f"{(e+f)**(1/2):.8f}")
| import math
x1,y1,x2,y2 = map(float,raw_input().split(' '))
x = abs(x1-x2);
y = abs(y1-y2);
a = math.sqrt(x**2 + y**2)
print a | 1 | 158,787,880,560 | null | 29 | 29 |
from collections import Counter
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
temp_s = list(map(int, input().split()))
s.append(temp_s)
my_count = Counter()
t = list(int(input()) for i in range(D))
c_sum = sum(c)
my_sum = 0
my_minus = 0
for d in range(D):
my_count [t[d]] = c[t[d] - 1] * (d + 1)
my_sum += s[d][t[d] - 1]
my_minus += sum(dict(my_count).values()) - c_sum * (d + 1)
print(my_sum + my_minus) | #!/usr/bin/env python3
import sys
from typing import NamedTuple, List
class Game(NamedTuple):
c: List[int]
s: List[List[int]]
def solve(D: int, c: "List[int]", s: "List[List[int]]", t: "List[int]"):
from functools import reduce
ans = [0]
lasts = [0] * 26
adjust = 0
sum_c = sum(c)
daily_loss = sum_c
for day, tt in enumerate(t, 1):
a = s[day-1][tt-1]
adjust += day * c[tt-1] - lasts[tt-1] * c[tt-1]
lasts[tt-1] = day
a -= daily_loss
a += adjust
ans.append(ans[-1]+a)
daily_loss += sum_c
return ans[1:]
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
D = int(next(tokens)) # type: int
c = [int(next(tokens)) for _ in range(26)] # type: "List[int]"
s = [[int(next(tokens)) for _ in range(26)] for _ in range(D)] # type: "List[List[int]]"
t = [int(next(tokens)) for _ in range(D)] # type: "List[int]"
print(*solve(D, c, s, t), sep="\n")
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
#test()
main()
| 1 | 9,923,469,387,520 | null | 114 | 114 |
n=int(input())
a=list(map(int,input().split()))
dp=[0]*(n+1)
for i in range(n-1):
dp[a[i]]+=1
for i in range(n):
print(dp[i+1]) | N = int(input())
A = {}
for i in range(N):
s = input()
if s in A:
A[s] += 1
else:
A[s] = 1
s_max = max(A.values())
for j in sorted(k for k in A if A[k] == s_max):
print(j) | 0 | null | 50,917,440,513,058 | 169 | 218 |
a,b = map(int,input().split())
if a <= b or a - (b * 2) <= 0:
print("0")
else:
print(a - (b * 2))
| n=int(input())
s=[]
t=[]
for i in range(n):
st,tt=input().split()
s.append(st)
t.append(int(tt))
x=str(input())
temp=0
ans=sum(t)
for i in range(n):
temp=temp+t[i]
if s[i]==x:
break
print(ans-temp) | 0 | null | 131,800,231,775,460 | 291 | 243 |
n,m = map(int, input().split())
num = [0]*n
tf = True
for _ in range(m):
d = list(map(int, input().split()))
if d[0]==1 and d[1]==0 and n>1:
tf = False
break
if num[d[0]-1] == 0:
num[d[0]-1] = d[1]
continue
if num[d[0]-1] != d[1]:
tf = False
if num[0]==0 and n>1:
num[0] = 1
if tf:
ans = 0
for i in range(n-1,-1,-1):
ans += num[(n-1)-i]*(10**i)
print(ans)
else: print(-1) | n = int(input())
l = sorted([int(i) for i in input().split(' ')])
if len(l) < 3:
print(0)
exit()
count = 0
for i in range(0, (n - 2)):
for j in range((i + 1), (n - 1)):
if l[i] == l[j]:
continue
for k in range((j + 1), n):
if l[j] == l[k]:
continue
if l[i] + l[j] > l[k]:
count += 1
print(count) | 0 | null | 32,993,881,097,070 | 208 | 91 |
N,D = map(int,input().split())
ans = 0
for i in range(N):
X1,Y1 = map(int,input().split())
if X1*X1+Y1*Y1 <= D*D:
ans += 1
print(ans) | #B問題
import math
distance = 0
ans = 0
n, d = map(int, input().split())
x = [input().split() for l in range(n)]
#リストの中にリストがある時→A[i][j]のように表現
for i in range(n):
distance = math.sqrt(pow(int(x[i][0]),2)+pow(int(x[i][1]),2))
if distance <= d:
ans += 1
print(ans) | 1 | 5,970,748,923,062 | null | 96 | 96 |
import math
H = int(input())
W = int(input())
N = int(input())
print(math.ceil(N/max(H,W))) | import sys
def merge(A, left, mid, right, num_compare):
n1 = mid - left
n2 = right - mid
L = A[left:mid] + [SENTINEL]
R = A[mid:right] + [SENTINEL]
i = 0
j = 0
num_compare += right - left
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return num_compare
def merge_sort(A, left, right, num_compare):
if left + 1 < right:
mid = (left + right) // 2
num_compare = merge_sort(A, left, mid, num_compare)
num_compare = merge_sort(A, mid, right, num_compare)
num_compare = merge(A, left, mid, right, num_compare)
return num_compare
#fin = open("test.txt", "r")
fin = sys.stdin
SENTINEL = float("inf")
n = int(fin.readline())
S = list(map(int, fin.readline().split()))
num_compare = 0
num_compare = merge_sort(S, 0, n, num_compare)
print(S[0], end = "")
for s in S[1:]:
print(" " + str(s), end = "")
print("")
print(num_compare) | 0 | null | 44,321,270,606,258 | 236 | 26 |
import sys
for stdin in sys.stdin:
inlist = stdin.split()
a = int(inlist[0])
b = int(inlist[2])
op = inlist[1]
if op == "?":
break
elif op == "+":
print(a + b)
elif op == "-":
print(a - b)
elif op == "/":
print(a // b)
elif op == "*":
print(a * b) | a,b,c = map(int,input().split())
tmp = a
a = b
b = tmp
tmp = a
a = c
c = tmp
print(a,b,c) | 0 | null | 19,389,594,991,820 | 47 | 178 |
n=int(input())
s=input()
r=0
for i in s:
if(i=="R"):
r+=1
ans=0
for j in range(r):
if(s[j]=="W"):
ans+=1
print(ans) | # coding:utf-8
import sys
# ??\???
n = int(input())
display = []
for i in range(n):
num = i + 1
# 3??§?????????????????´???
if (num % 3 == 0):
display.append(num)
continue
# ????????????????????????3????????????????????´???
original = num
while (num != 0):
last_digit = int(num % 10)
if (last_digit == 3):
display.append(original)
num = 0
num = int(num / 10)
for x in display:
sys.stdout.write(' ' + str(x))
print('') | 0 | null | 3,589,505,560,572 | 98 | 52 |
def insertionSort(A, n, g):
local_cnt = 0
for i in range(g, n):
# print(i, local_cnt)
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
# print(i, j, local_cnt)
A[j + g] = A[j]
j -= g
local_cnt += 1
A[j + g] = v
return A, local_cnt
def shellSort(A, n):
cnt = 0
m = 1
G = []
h = 1
while (h < n // 3):
h = h * 3 + 1
m += 1
# print(f'm: {m}')
while True:
G.append(h)
if h == 1:
break
h //= 3
# print(f'G: {G}')
for i in range(m):
ans = insertionSort(A, n, G[i])
# print(ans)
A = ans[0]
cnt += ans[1]
return m, G, A, cnt
n = int(input())
A = [int(input()) for _ in range(n)]
m, G, A, cnt = shellSort(A, n)
print(m)
print(' '.join(str(g) for g in G))
print(cnt)
for a in A:
print(a)
| N, K = [int(_) for _ in input().split()]
mod = 10 ** 9 + 7
ans = 0
for i in range(K, N + 2):
ans += i * (N - i + 1) + 1
ans %= mod
print(ans)
| 0 | null | 16,668,490,095,140 | 17 | 170 |
def sol():
x, y = map(int, input().split())
for i in range(x+1):
for j in range(x+1):
if (i+j) == x and 4*i + 2*j == y:
print("Yes")
return
print("No")
if __name__ == "__main__":
sol()
| def main():
X,Y = map(int,input().split())
for x in range(101):
for y in range(101):
if x+y==X and 2*x+4*y==Y:
return True
return False
if __name__ == '__main__':
print("Yes" if main() else "No") | 1 | 13,626,159,014,960 | null | 127 | 127 |
import math
def is_prime(n):
global primes
if n == 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
s = int(math.sqrt(n))
for x in range(3, s + 1, 2):
if n % x == 0:
return False
else:
return True
N = int(input())
d = [int(input()) for _ in range(N)]
d.sort()
print([is_prime(x) for x in d].count(True)) | #encoding=utf-8
import sys
num = []
ans = []
def prime(q):
q = abs(q)
if q == 2: return True
if q < 2 or q&1 == 0: return False
return pow(2, q-1, q) == 1
for i in sys.stdin:
inp = map(int , i.split())
if prime(inp[0]):
num.append(inp)
num.sort()
for i in xrange(1, len(num)):
if num[i - 1] != num[i]:
ans.append(num[i][0])
print len(ans) + 1 | 1 | 9,374,344,540 | null | 12 | 12 |
S = input()
K = int(input())
if S.count(S[0]) == len(S):
print(len(S)*K//2)
exit()
count = 0
i = 1
flg = [False] * len(S)
while i < len(S):
if S[i] == S[i-1]:
count += 1
flg[i] = True
i += 2
else:
i += 1
count *= K
if (not flg[len(S)-1]) and S[0] == S[-1]:
a = 1
for i in range(1, len(S)):
if S[0] == S[i]:
a += 1
else:
break
if a % 2 == 1:
count += (K-1)
print(count)
| row = int(input())
colmun = int(input())
top = int(input())
low, high = 0,0
if row <= colmun:
low, high = row, colmun
else:
low, high = colmun, row
for n in range(low):
if (n + 1) * high >= top:
print(n + 1)
break | 0 | null | 132,074,654,709,268 | 296 | 236 |
#!/usr/bin/env python3
def main():
n = int(input())
a = list(map(int, input().split()))
ans = [None] * n
allxor = 0
for i in range(n):
allxor ^= a[i]
for i in range(n):
ans[i] = allxor ^ a[i]
print(*ans)
if __name__ == "__main__":
main()
| A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
tmp=min(a)+min(b)
for i in range(m):
x,y,c=map(int,input().split())
if a[x-1]+b[y-1]-c<tmp:
tmp=a[x-1]+b[y-1]-c
print(tmp) | 0 | null | 33,116,924,130,228 | 123 | 200 |
def gcd(a,b):
while b:
a,b = b,a%b
return abs(a)
K=int(input())
#余裕でTLE?
ans=0
for a in range(1, K+1):
for b in range(1, K+1):
for c in range(1, K+1):
temp=a
temp=gcd(temp, b)
temp=gcd(temp, c)
ans+=temp
print(ans) | def main():
K = int(input())
from math import gcd
ans = 0
for i in range(1, K+1):
for j in range(1, K+1):
g = gcd(i, j)
for k in range(1, K+1):
ans += gcd(g, k)
print(ans)
if __name__ == '__main__':
main()
| 1 | 35,446,934,329,180 | null | 174 | 174 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.