code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
n = int(input())
if n%2 == 1:
print(0)
exit()
num = 5
i = 1
ans = 0
while num**i < n:
ans += n//num**i//2
i += 1
print(ans)
|
k,n,*a=map(int,open(0).read().split())
dist=10**7
for i in range(n):
if i==0:
# print(a[-1]-a[0])
dist=min(dist,a[-1]-a[0])
else:
# print(a[-1+i]+k-a[i])
dist=min(dist,a[-1+i]+k-a[i])
print(dist)
| 0 | null | 80,032,246,188,280 | 258 | 186 |
x,y=map(int,input().split());print(('No','Yes')[2*x<=~y%2*y<=4*x])
|
def main():
n = set(map(int, input().split()))
if len(n) == 2:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 0 | null | 40,967,602,247,430 | 127 | 216 |
import math
m,n = map(int,input().split())
print(m*n//(math.gcd(m, n)))
|
from math import gcd
def snack(a, b):
icm = (a*b // gcd(a, b))
return icm
def main():
a, b = map(int, input().split())
print(snack(a, b))
if __name__ == '__main__':
main()
| 1 | 113,175,455,228,608 | null | 256 | 256 |
from collections import deque
s = input()
n = int(input())
q_list = [input().split() for _ in range(n)]
d = deque(list(s))
r_flag = False
for q in q_list:
if q[0] == "1":
r_flag = not r_flag
elif q[0] == "2":
if q[1] == "1":
if r_flag:
d.append(q[2])
else:
d.appendleft(q[2])
elif q[1] == "2":
if r_flag:
d.appendleft(q[2])
else:
d.append(q[2])
if r_flag:
d.reverse()
print("".join(d))
|
import numpy as np
n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**18
f = np.array([0]*d)
for i in a:
f[i]+=1
tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]
ans=0
for i in range(len(f)-1,0,-1):
if f[i]<=m:
ans+=i*f[i]
m-=f[i]
elif f[i]>m:
ans+=i*m
break
print(ans)
| 0 | null | 82,681,871,602,088 | 204 | 252 |
def LI():
return list(map(int, input().split()))
X, Y, A, B, C = LI()
red = LI()
green = LI()
mu = LI()
red.sort(reverse=True)
green.sort(reverse=True)
ans = red[:X]+green[:Y]+mu
ans.sort(reverse=True)
total = 0
for i in range(X+Y):
total += ans[i]
print(total)
|
import math
d=100
for _ in[0]*int(input()):d=math.ceil(d*1.05)
print(int(d*1e3))
| 0 | null | 22,514,877,271,460 | 188 | 6 |
from collections import deque
N = int(input())
g = {i: deque() for i in range(1,N+1)} #1-index
for i in range(1, N+1):
u, k, *v = map(int, input().split())
for j in v:
g[u].append(j)
seen = [0]*(N+1) #1-index
que = deque([])
dist = [-1]*(N+1) #1-index
seen[1] = 1
que.append(1)
dist[1] = 0
while que: #queが空になるまで
q_no = que.popleft()
if not g[q_no]: continue #点q-noから他の点に伸びていない
for next_v in g[q_no]:
if seen[next_v] == 1: continue #訪問済
seen[next_v] = 1 #訪問済にする
dist[next_v] = dist[q_no] + 1 #距離情報を格納
que.append(next_v) #queに追加
for i in range(1, N+1):
print(i, dist[i])
|
import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(")
| 0 | null | 62,568,371,093,248 | 9 | 265 |
n, x, t = map(int, input().split())
i = 0
while True:
i += 1
if i*x >= n :
break
print(i*t)
|
H,W,s=list(map(int,input().split()))
l=[list(input()) for i in range(H)]
l_h=[0]*H
for i in range(H):
if "#" in set(l[i]):
l_h[i]=1
cnt=0
bor=sum(l_h)-1
for i in range(H):
if cnt==bor:
break
if l_h[i]==1:
l_h[i]=-1
cnt+=1
cnt=1
import numpy as np
tmp=[]
st=0
ans=np.zeros((H,W))
for i in range(H):
tmp.append(l[i])
if l_h[i]==-1:
n_tmp=np.array(tmp)
s_count=np.count_nonzero(n_tmp=="#")-1
for j in range(W):
ans[st:i+1,j]=cnt
if "#" in n_tmp[:,j] and s_count>0:
cnt+=1
s_count-=1
st=i+1
cnt+=1
tmp=[]
n_tmp=np.array(tmp)
s_count=np.count_nonzero(n_tmp=="#")-1
for j in range(W):
ans[st:i+1,j]=cnt
if "#" in n_tmp[:,j] and s_count>0:
cnt+=1
s_count-=1
for i in ans:
print(*list(map(int,i)))
| 0 | null | 74,145,527,994,240 | 86 | 277 |
import math
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = math.floor(a * x / b) - a * math.floor(x / b)
print(ans)
|
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
d.append(int(input()))
A.append(list(map(int, input().split())))
sunuke = [0] * N
for i in range(K):
for j in range(d[i]):
sunuke[A[i][j] - 1] += 1
ans = 0
for i in range(N):
if sunuke[i] == 0:
ans += 1
print(ans)
| 0 | null | 26,414,313,611,928 | 161 | 154 |
N = input()
def f(x):
p = 1
i = 1
cnt = 0
while p > 0:
p = x // (5**i) // 2
cnt += p
i += 1
return cnt
if int(N[-1])%2 == 1:
print(0)
else:
print(f(int(N)))
|
val = input().split()
N = int(val[0])
M = int(val[1])
if N - M == 0:
print("Yes")
else:
print("No")
| 0 | null | 99,499,182,395,600 | 258 | 231 |
# -*- coding: utf-8 -*-
"""
B - TAKOYAKI FESTIVAL 2019
https://atcoder.jp/contests/abc143/tasks/abc143_b
"""
import sys
from itertools import combinations
def solve(takoyaki):
return sum(x * y for x, y in combinations(takoyaki, 2))
def main(args):
_ = input()
takoyaki = map(int, input().split())
ans = solve(takoyaki)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
|
from itertools import combinations
n = int(input())
d = list(map(int, input().split()))
ans = 0
sum = sum(d)
for i in d:
sum -= i
ans += i*sum
print(ans)
| 1 | 168,389,380,285,586 | null | 292 | 292 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
def cut(x):
cut_count = 0
for i in range(n):
cut_count += (a[i]-1)//x
return cut_count
l = 0
r = 10**9
while r-l > 1:
mid = (l+r)//2
if k >= cut(mid):
r = mid
else:
l = mid
print(r)
|
from sys import stdin
rs = stdin.readline
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))
from functools import reduce
def main():
N, K = ril()
A = ril()
l = 1
r = 1000000000
while l < r:
m = (l + r) // 2
f = lambda i, j : i + (j - 1) // m
k = reduce(f, A, 0)
if k <= K:
r = m
else:
l = m + 1
print(r)
if __name__ == '__main__':
main()
| 1 | 6,481,813,204,084 | null | 99 | 99 |
import math
h,a = map(int,input().split())
print(str(math.ceil(h/a)))
|
H,A = map(int,input().split())
div,mod = divmod(H,A)
print(div if mod==0 else div+1)
| 1 | 77,136,505,465,646 | null | 225 | 225 |
result = []
while True:
line = input()
if line is "-":
break
count = int(input())
for _ in range(count):
n = int(input())
line = line[n:] + line[:n]
result.append(line)
print("\n".join(result))
|
while True:
string = input()
if string == "-":
break
times = int(input())
for i in range(times):
cut=int(input())
string = string[cut:]+string[:cut]
print(string)
| 1 | 1,911,638,622,168 | null | 66 | 66 |
x = []
try:
while True:
a, b = map(int, raw_input().split())
x.append(len(list(str(a + b))))
except EOFError:
for i in x:
print(i)
|
def prime_factors(n):
d = {}
while n%2 == 0:
d[2] = d.get(2, 0) + 1
n //= 2
i = 3
while i*i <= n:
while n%i == 0:
d[i] = d.get(i, 0) + 1
n //= i
i += 2
if n > 2:
d[n] = d.get(n, 0) + 1
return d
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
G = {}
for a in A:
pf = prime_factors(a)
for k,v in pf.items():
G[k] = max(G.get(k, 0), v)
lcm = 1
for k,v in G.items():
lcm *= pow(k, v, MOD)
lcm %= MOD
ans = 0
for a in A:
ans += lcm * pow(a, MOD-2, MOD) % MOD
ans %= MOD
print(ans)
| 0 | null | 43,748,236,411,362 | 3 | 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 # cumsum
# from bisect import bisect_left, bisect_right
def solve():
H, W, K = MI()
G = np.array(LLS(H))
# print(G)
ans = np.zeros((H, W), np.int)
i = 0
cnt = 0
num = 1
for h in range(H):
g = G[h]
if '#' in g:
cnt += 1
if cnt == 2:
# print('tmp', i, h, cnt,)
l = h-i
c2 = 0
for w in range(W):
gw = G[i:h, w]
# print(gw)
if '#' in gw:
c2 += 1
if c2 == 2:
num += 1
c2 = 1
for j in range(l):
ans[i+j, w] = num
num += 1
i = h
cnt = 1
tmp = []
# print(i, h)
# print('tmp', i, h, cnt, )
c2 = 0
for w in range(W):
gw = G[i:h+1, w]
# print(gw)
if '#' in gw:
c2 += 1
if c2 == 2:
num += 1
c2 = 1
for j in range(h+1-i):
ans[i + j, w] = num
for a in ans:
print(*a)
if __name__ == '__main__':
solve()
|
arr = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".split(", ")
K = int(input())
print(arr[K-1])
| 0 | null | 96,969,225,114,500 | 277 | 195 |
n = int(input())
added_strings = set()
for i in range(n):
com, s = input().split()
if com == 'insert':
added_strings.add(s)
elif com == 'find':
print('yes' if (s in added_strings) else 'no')
|
# AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u
dic = {}
n = int(input())
for i in range(n):
id, s = input().split()
if id == "insert": dic[s] = 1
else: print("yes" if s in dic else "no")
| 1 | 78,610,173,980 | null | 23 | 23 |
import numpy as np
from copy import deepcopy
from heapq import heappop, heappush
from bisect import bisect_left, bisect
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
H, W, K = map(int, input().split())
c = np.zeros((W, H))
for h in range(H):
s = list(input())
for w in range(W):
if s[w] == ".":
c[w, h] = 0
else:
c[w, h] = 1
n = 0
for wt in product([1, 0], repeat=W):
for ht in product([1, 0], repeat=H):
d = deepcopy(c)
for i in range(W):
if wt[i] == 1:
d[i, :] = 0
for i in range(H):
if ht[i] == 1:
d[:, i] = 0
if np.count_nonzero(d) == K:
n += 1
print(n)
exit()
|
h,w,k = map(int, input().split())
grid = [input() for _ in range(h)]
ans = 0
for i in range(2**h):
for j in range(2**w):
count = 0
for m in range(h):
for l in range(w):
if (i>>m)&1==0 and (j>>l)&1==0 and grid[m][l] == "#":
count+=1
if count == k: ans+=1
print(ans)
| 1 | 8,964,664,758,720 | null | 110 | 110 |
import sys
readline = sys.stdin.readline
H,W = map(int,readline().split())
if H == 1 or W == 1:
print(1)
exit(0)
if (H * W) % 2 == 1:
print((H * W) // 2 + 1)
else:
print((H * W) // 2)
|
num = int(input())
print('ACL'*num)
| 0 | null | 26,504,321,163,320 | 196 | 69 |
import math
def abc173a_payment():
n = int(input())
print(math.ceil(n/1000)*1000 - n)
abc173a_payment()
|
import math
X,Y= list(map(int, input().split()))
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
if((X+Y) % 3 != 0):
print(0)
exit()
s = (-X + 2 * Y) // 3
t = (-Y + 2 * X) // 3
#print(s,t)
ans = cmb(s+t, s, 10**9+7)
print(ans)
| 0 | null | 79,492,772,786,236 | 108 | 281 |
# coding: utf-8
s = input()
print("x" * len(s))
|
n = int(input())
s = set()
for i in range(10):
for j in range(i, 10):
s.add(i*j)
print('Yes' if n in s else 'No')
| 0 | null | 116,797,183,852,412 | 221 | 287 |
n,r = input().split()
if int(n) >= 10:
print(r)
else:
k = (-int(r) - 100 * (10 - int(n) )) * -1
print(k)
|
N,R = map(int,input().split())
if N < 10:
R += 100*(10-N)
print(R)
| 1 | 63,556,713,262,328 | null | 211 | 211 |
N,M,X=map(int,input().split())
B=[list(map(int,input().split())) for _ in range(N)]
inf=(10**5)*12+1
ans=inf
for i in range(1,2**N):
tmp=[0]*M
c=0
for j in range(N):
if i>>j&1:
for k in range(M):
tmp[k]+=B[j][k+1]
c+=B[j][0]
if len([i for i in tmp if i>=X])==M:
ans=min(c,ans)
print(ans if ans<inf else -1)
|
n, m, x = map(int, input().split())
books_info = []
price_info = []
for i in range(n):
c, *a = map(int, input().split())
books_info.append(a)
price_info.append(c)
pattern_list = []
for j in range(2 ** n):
tmp_list = []
for k in range(n):
if ((j >> k) & 1):
tmp_list.append(k)
else:
pass
pattern_list.append(tmp_list)
book_price = 10 ** 5 * 12 + 1
for pattern in pattern_list:
# 全ての参考書を買わない=len(pattern)が0の場合はスキップする
if len(pattern) == 0:
continue
is_ok = False
price = 0
for j in range(m):
m_sum = 0
price_sum = 0
for k in pattern:
m_sum += books_info[k][j]
price_sum += price_info[k]
if m_sum >= x:
is_ok = True
else:
is_ok = False
break
price = price_sum
if is_ok == True:
book_price = min(price, book_price)
else:
pass
print(book_price if book_price != 10 ** 5 * 12 + 1 else -1)
| 1 | 22,364,753,567,232 | null | 149 | 149 |
string = input()
num = int(input())
orders = [input().split() for _ in range(num)]
for order in orders:
start = int(order[1])
end = int(order[2]) + 1
if order[0] == "reverse":
string = string[:start] + string[start:end][::-1] + string[end:]
elif order[0] == "replace":
string = string[:start] + order[3] + string[end:]
elif order[0] == "print":
print(string[start:end])
|
s = list(input().replace("\r", "").replace("\n", ""))
n = int(input())
for i in range(n):
li = list(input().split())
if li[0] == "print":
a = int(li[1])
b = int(li[2])
print("".join(s[a:b+1]))
elif li[0] == "replace":
a = int(li[1])
b = int(li[2])
p = list(li[3])
s[a:b+1] = p
elif li[0] == "reverse":
a = int(li[1])
b = int(li[2])
p = s[a:b+1]
p.reverse()
s[a:b+1] = p
| 1 | 2,102,330,436,710 | null | 68 | 68 |
def counter(a, b, c):
count = 0
for n in range(a, b+1):
if c % n == 0:
count += 1
print(count)
a, b, c = list(map(int, input().split()))
counter(a, b, c)
|
# 数値で入力ではなく, 文字列で入力しlist関数を使う
k = int(input())
s = input()
n = len(s)
list_s = list(s)
# リストのスライス機能を使用
if n > k:
tmp = list_s[0:k]
print(''.join(tmp) + '...')
else: print(''.join(list_s))
| 0 | null | 10,171,831,038,340 | 44 | 143 |
N,M = map(int,input().split())
S = input()
ans = []
i = N
while i > 0:
for m in range(M,0,-1):
if i-m <= 0:
ans.append(i)
i = 0
break
if S[i-m]=='0':
ans.append(m)
i -= m
break
else:
print(-1)
exit()
print(*ans[::-1])
|
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]
INF = 10 ** 20
ans = INF
for div in range(1 << (h - 1)):
id = []
g = 0
for i in range(h):
id.append(g)
if div >> i & 1:
g += 1
g += 1
c = [[0 for _ in range(w)] for _ in range(g)]
for i in range(h):
for j in range(w):
c[id[i]][j] += (s[i][j] == "1")
tmp_ans = g - 1
now = [0] * g
def add(j):
for i in range(g):
now[i] += c[i][j]
if now[i] > k:
return False
return True
for j in range(w):
if not add(j):
tmp_ans += 1
now = [0] * g
if not add(j):
tmp_ans = INF
break
# impossible = 0
# for j in range(w):
# if impossible:
# tmp_ans = INF
# break
# for i in range(g):
# if c[i][j] > k:
# impossible = 1
# break
# now[i] += c[i][j]
# if now[i] > k:
# now = [c[gi][j] for gi in range(g)]
# tmp_ans += 1
# continue
ans = min(ans, tmp_ans)
print(ans)
| 0 | null | 93,560,235,049,920 | 274 | 193 |
#!/usr/bin/env python3
import sys
def solve(A: int, B: int):
print(A*B)
# 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()
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
solve(A, B)
if __name__ == '__main__':
main()
|
def main():
import sys
input = sys.stdin.readline
x, y = map(int, input().split())
print(x*y)
return
if __name__ == '__main__':
main()
| 1 | 15,864,979,023,118 | null | 133 | 133 |
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
A_sort = np.sort(A)
#print(A_sort)
score = 0
score += A_sort[-1]
for i in range(0, (N-2)//2):
score += A_sort[-2-i] * 2
if (N-2) % 2 == 1:
score += A_sort[-3-i]
print(score)
|
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=A[0]
if N%2==1:
n=int((N-1)/2)
ans+=A[n]
for i in range(1,n):
ans+=2*A[i]
elif N==2:
ans+=0
elif N%2==0 and N>2:
n=int((N-2)/2)
for i in range(1,n+1):
ans+=2*A[i]
print(ans)
| 1 | 9,099,124,663,360 | null | 111 | 111 |
n, t = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0] * t for _ in range(n)]
ans = 0
a.sort()
for i in range(n-1):
for j in range(t):
if j - a[i][0] < 0:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i][0]] + a[i][1])
ans = max(ans, dp[i + 1][-1] + a[i+1][1])
print(ans)
|
import sys
n = input()
for a,b,c in map(lambda x: sorted(map(int,x.split())),sys.stdin.readlines()):
print("YES" if a*a+b*b==c*c else "NO")
| 0 | null | 75,880,564,981,342 | 282 | 4 |
x = int(input()) - 400
ans = x // 200
print(8 - ans)
|
N = int(input())
num_list = [int(i) for i in input().split()]
result = 0
mod = 10 ** 9 + 7
right = sum(num_list)
for number in num_list:
#A*B + A * C = A*(B+C)で計算
right -= number
result += (number * right) % mod
print(result % mod)
| 0 | null | 5,296,760,936,310 | 100 | 83 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")
def lcm(a, b): return a * b // math.gcd(a, b)
sys.setrecursionlimit(1000000)
class Eratosthenes:
# https://cp-algorithms.com/algebra/prime-sieve-linear.html
def __init__(self, n):
primes, lp = [], [0] * (n + 1)
for i in range(2, n + 1):
if lp[i] == 0:
primes.append(i)
lp[i] = i
for pj in primes:
if pj > lp[i] or i * pj > n: break
lp[i * pj] = pj
self.primes, self.lp = primes, lp
def is_prime(self, x): return self.lp[x] == x
def factors(self, x):
ret = []
while x > 1:
ret.append(self.lp[x])
x //= self.lp[x]
return ret
def main():
N = I()
A = LI()
era = Eratosthenes(1 + 10 ** 6)
cumgcd = reduce(lambda x,y: math.gcd(x, y), A)
s = set()
for ai in A:
for i in set(era.factors(ai)):
if i in s:
break
s.add(i)
else:
continue
break
else:
print("pairwise coprime")
return
if cumgcd == 1:
print("setwise coprime")
else:
print("not coprime")
if __name__ == '__main__':
main()
|
import math
#import matplotlib.pyplot as plt
def kock(n,p1,p2):
#global x
#global y
if n==0:
return
s=[0,0]
t=[0,0]
u=[0,0]
s[0]=(float((2*p1[0]+p2[0])/3))
s[1]=(float((2*p1[1]+p2[1])/3))
t[0]=(float((p1[0]+2*p2[0])/3))
t[1]=(float((p1[1]+2*p2[1])/3))
u[0]=((t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0])
u[1]=((t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1])
kock(n-1,p1,s)
print(*s)
# x.append(s[0])
#y.append(s[1])
kock(n-1,s,u)
print(*u)
#x.append(u[0])
#y.append(u[1])
kock(n-1,u,t)
print(*t)
#x.append(t[0])
#y.append(t[1])
kock(n-1,t,p2)
n=int(input())
p1=[0.0,0.0]
p2=[100.0,0.0]
#x=[]
#y=[]
print(*p1)
#x.append(p1[0])
#y.append(p1[1])
kock(n,p1,p2)
print(*p2)
| 0 | null | 2,151,855,599,172 | 85 | 27 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
a, v = rl()
b, w = rl()
t = ri()
d = abs(a - b)
s = v - w
if t * s >= d:
print ("YES")
else:
print ("NO")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
|
a, v = list(map(int, input().split(' ')))
b, w = list(map(int, input().split(' ')))
time = int(input())
if a>b:
x1 = a - v*time
x2 = b - w*time
if x1 <= x2:
print('YES')
else:
print('NO')
elif a<b:
x1 = a + v*time
x2 = b + w*time
if x1 >= x2:
print('YES')
else:
print('NO')
| 1 | 15,099,847,680,890 | null | 131 | 131 |
S = input()
if S == ("ABC"):
output = ("ARC")
elif S == ("ARC"):
output = ("ABC")
print(output)
|
S = input()
if S == "ABC":
print("ARC")
elif S == "ARC":
print("ABC")
else:
pass
| 1 | 24,130,371,110,468 | null | 153 | 153 |
n, x, m = map(int, input().split())
mn = min(n, m)
S = set()
A = []
a = x
sum_9 = 0 # sum of pre + cycle
for _ in range(mn):
if a in S: break
S.add(a)
A.append(a)
sum_9 += a
a = a*a % m
if a == 0:
print(sum_9)
exit()
if len(A) >= mn:
print(sum_9)
exit()
st_len = A.index(a)
cyc_len = len(A) - st_len
ed_len = (n - st_len) % cyc_len
cyc_num = (n - st_len) // cyc_len
pre = sum(A[:st_len])
cyc = sum_9 - pre
btm = sum(A[st_len: st_len + ed_len])
print(pre + cyc * cyc_num + btm)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, X, mod = mapint()
doubling = [[i*i%mod for i in range(mod)]]
accu = [doubling[0][:]]
for i in range(40):
tmp1 = [None]*mod
tmp2 = [None]*mod
for j in range(mod):
tmp1[j] = doubling[-1][doubling[-1][j]]
tmp2[j] = accu[-1][doubling[-1][j]] + accu[-1][j]
doubling.append(tmp1)
accu.append(tmp2)
now = X
ans = X
for i in range(40):
if (N-1)>>i&1:
ans += accu[i][now]
now = doubling[i][now]
print(ans)
| 1 | 2,810,834,810,588 | null | 75 | 75 |
from collections import deque
N,K = map(int,input().split())
R,S,P = map(int,input().split())
Tlist = input()
Answer = 0
def po(x):
if x == 's':
return R
elif x == 'r':
return P
else:
return S
for i in range(K):
TK = list(Tlist[i::K]).copy()
TK.append('')
T2 = TK[0]
sig = 2
for i in range(1,len(TK)):
T1 = T2
T2 = TK[i]
if T1 == T2 and i != len(TK)-1:
sig += 1
else:
Answer += po(T1)*(sig//2)
sig = 2
print(Answer)
|
n = int(input())
graph = [[0] * 9 for i in range(9)]
for i in range(1, n + 1):
if i % 10 != 0:
i = str(i)
sentou = int(i[0])
matubi = int(i[-1])
graph[sentou - 1][matubi - 1] += 1
import numpy as np
graph = np.array(graph)
print(np.trace(np.dot(graph, graph)))
| 0 | null | 97,200,070,471,284 | 251 | 234 |
n,a,b = list(map(int,input().split()))
ans = n // (a+b) * a
n %= (a+b)
if n > a:
print(ans + a)
else:
print(ans + n)
|
def main():
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7
ans=((sum(a)%mod)**2)%mod
for i in range(n):
ans-=a[i]**2
ans%=mod
m=pow(2,mod-2,mod)
print(ans*m%mod)
main()
| 0 | null | 29,575,895,288,222 | 202 | 83 |
S = input()
h = S/3600
m = (S - 3600*h)/60
s = S -3600*h -60*m
print "%d:%d:%d" %(h, m, s)
|
def main():
import copy
from heapq import heappop, heapify, heappush
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
F = [int(i) for i in input().split()]
ans = 0
A.sort(reverse=True)
F.sort()
s = []
for i in range(N):
s.append([A[i]*F[i], A[i], F[i]])
s.sort(reverse=True, key=lambda x: x[0])
def f(S, T):
cur = 0
num = 0
while cur <= K:
if num == N:
break
a, b, c = S[num]
if a <= T:
break
cur += math.ceil((a - T)/c)
num += 1
if cur <= K:
return True
else:
return False
ok, ng = s[0][0], -1
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if f(s, mid) == True:
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| 0 | null | 82,309,519,134,600 | 37 | 290 |
s=input()
t=input()
ans=0
for i in range(len(s)):
if s[i]!=t[i]:
ans+=1
print(ans)
|
a = list(str(input()))
b = list(str(input()))
count=0
for i in range(len(a)):
if a[i] != b[i]:
count +=1
print(count)
| 1 | 10,432,025,145,640 | null | 116 | 116 |
# coding: utf-8
a, b = map(int, input().split(' '))
menseki = a * b
print(menseki, a*2 + b*2)
|
from collections import deque
n,m,*ab = map(int, open(0).read().split())
to = [[] for _ in range(n+1)]
for i in range(0, m*2, 2):
a = ab[i]
b = ab[i+1]
to[a].append(b)
to[b].append(a)
ans = [None]*(n+1)
q = deque([1])
while q:
p = q.pop()
children = to[p]
for child in children:
if ans[child] is None:
ans[child] = p
q.appendleft(child)
print("Yes")
print("\n".join(map(str, ans[2:])))
| 0 | null | 10,429,432,419,002 | 36 | 145 |
a,b=[int(i) for i in input().split()]
if(a%b==0):
print(a//b)
else:
print((a//b)+1)
|
h, w, m = map(int, input().split())
a_list = []
b_list = []
h_list = [0 for _ in range(h)]
w_list = [0 for _ in range(w)]
for i in range(m):
a, b = map(int, input().split())
a_list.append([a,b])
h_list[a - 1] += 1
w_list[b - 1] += 1
h_max = max(h_list)
w_max = max(w_list)
w_flag = [0 for _ in range(w)]
for i in range(w):
if w_list[i] == w_max:
w_flag[i] = 1
h_flag = [0 for _ in range(h)]
for i in range(h):
if h_list[i] == h_max:
h_flag[i] = 1
flag = 0
for i in range(m):
if h_flag[a_list[i][0] - 1] == 1 and w_flag[a_list[i][1] - 1] == 1:
flag += 1
s = sum(h_flag) * sum(w_flag)
print(h_max + w_max - 1 if flag == s else h_max + w_max)
| 0 | null | 40,630,539,434,956 | 225 | 89 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A-B)
if d-(V-W)*T<=0:
print("YES")
else:
print("NO")
|
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
w = abs(A-B)
if w <= (V-W)*T:
print('YES')
else:
print('NO')
| 1 | 15,109,944,057,740 | null | 131 | 131 |
from scipy.special import comb
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
x = 0
for c in C.values():
x += comb(c, 2, exact=True)
for i in range(N):
y = x - comb(C[A[i]], 2, exact=True) + comb(C[A[i]] - 1, 2, exact=True)
print(y)
|
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
total = sum([v*(v-1)//2 for v in c.values()])
for i in a:
print(total-(c[i]-1))
| 1 | 47,646,833,509,900 | null | 192 | 192 |
length = int(input())
targ = [n for n in input().split(' ')]
selecttarg = targ[:]
#bubbleflag = 0
for l in range(length):
for init in range(l):
if targ[l - init][1] < targ[l - init - 1][1]:
disp = targ[l-init]
targ[l-init] = targ[l-init-1]
targ[l-init-1] = disp
print(' '.join([str(n) for n in targ]))
print("Stable")
selectflag = 0
for l in range(length):
value = l
samevalue = l
for init in range(l+1,length):
if selecttarg[value][1] > selecttarg[init][1]:
value = init
elif selectflag != 1 and selecttarg[l][1] == selecttarg[init][1]:
samevalue = init
if samevalue != l and value != l and value > samevalue:
selectflag = 1
disp = selecttarg[l]
selecttarg[l] = selecttarg[value]
selecttarg[value] = disp
print(' '.join([str(n) for n in selecttarg]))
if selectflag == 0:
print("Stable")
else:
print("Not stable")
|
n={i:0 for i in range(int(input()))}
for i in list(map(int,input().split())):
n[i-1]+=1
[print(i) for i in n.values()]
| 0 | null | 16,280,889,258,080 | 16 | 169 |
from math import cos, radians, sin, sqrt
def g(a, b, c):
c_rad = radians(c)
yield a * b * sin(c_rad) / 2
yield a + b + sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(c_rad))
yield b * sin(c_rad)
a, b, c = list(map(int, input().split()))
for i in g(a, b, c):
print("{:.8f}".format(i))
|
n,m = map(int,input().split())
a = list(map(int,input().split()))
m_count = 0
a_sum = sum(a)
for i in a:
if i >= (a_sum/(4*m)):
m_count += 1
else:
continue
if m_count >= m:
print("Yes")
else:
print("No")
| 0 | null | 19,311,784,103,908 | 30 | 179 |
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
visited = [[False for i in range(3)] for j in range(3)]
for i in b:
for j in range(3):
for k in range(3):
if i==a[j][k]:
visited[j][k] = True
ans = "No"
for i in visited:
if i==[True,True,True]:
ans = "Yes"
for i in range(3):
flag = True
for j in range(3):
if visited[j][i]==False:
flag = False
break
if flag:
ans = "Yes"
if visited[0][0] and visited[1][1] and visited[2][2]:
ans = "Yes"
if visited[2][0] and visited[1][1] and visited[0][2]:
ans = "Yes"
print(ans)
|
n = int(input())
lst = sorted(list(map(int, input().split())))
mult = 1
for i in lst:
mult *= i
if 10**18 < mult:
print(-1)
exit()
else:
print(mult)
| 0 | null | 37,873,014,181,218 | 207 | 134 |
import math
r = input()
r = float(r)
S = math.pi * r * r
L = 2 * math.pi * r
print("{0} {1}".format(round(S,6), round(L,6)))
|
r=int(input())
print(r**2//1)
| 0 | null | 72,633,112,583,082 | 46 | 278 |
L = []
n,x = map(int, input().split())
while not(n == 0 and x == 0):
L.append([n, x])
n, x = map(int, input().split())
for i in L:
ans = 0
for j in range(1, i[0] - 1):
if j > i[1] - 3:
break
else:
for k in range(j + 1, i[0]):
m = i[1] - (j + k)
if m <= k:
break
elif m <= i[0]:
ans += 1
else:
continue
print(ans)
|
# coding: utf-8
import itertools
data_set = []
answer = []
while (1):
n,x = map(int, input().split())
if (n == 0 and x == 0):
break
data_set.append([n,x])
for d in data_set:
num = list(range(d[0] + 1))[1:]
counter = 0
for i in itertools.combinations(num, 3):
if (sum(i) == d[1]):
counter += 1
answer.append(counter)
for ans in answer:
print(ans)
| 1 | 1,286,812,413,338 | null | 58 | 58 |
mod=1000000007
dp=[1]*2001
for i in range(3,2001):
for j in range(i+3,2001):
dp[j]=(dp[j]+dp[i])%mod
n=int(input())
if n<3:print(0)
else:print(dp[n])
|
k = int(input())
s =str(input())
s_print = ''
if k >= len(s):
print(s)
exit()
else:
for i in range(k):
s_print += s[i]
s_print += '...'
print(s_print)
| 0 | null | 11,430,718,787,812 | 79 | 143 |
n=int(input())
dic={}
for i in range(1,50001):
p=int(i*1.08)
dic[p]=i
if n in dic:
print(dic[n])
else:
print(":(")
|
print(['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1].index(input())+1)
| 0 | null | 129,037,617,809,462 | 265 | 270 |
n,k=map(int,input().split())
p=[0]+list(map(int,input().split()))
for i in range(n+1):
p[i]=(p[i]+1)/2
for i in range(n):
p[i+1]+=p[i]
ans=0
for i in range(n-k+1):
ans=max(ans,p[i+k]-p[i])
print(ans)
|
from collections import deque
s,q=deque([*input()]),int(input())
judge=False
for i in range(q):
t=input().split()
if len(t)==1:
judge = not judge
else:
t,f,c=t
if not judge and f=='1': s.appendleft(c)
elif not judge and f=='2': s.append(c)
elif judge and f=='1': s.append(c)
else: s.appendleft(c)
if judge: s.reverse()
print(*s,sep='')
| 0 | null | 65,972,698,559,740 | 223 | 204 |
x, y, z = input().split()
a = int(x)
b = int(y)
c = int(z)
count = 0
num = a
while num <= b:
if c % num == 0:
count += 1
else:
pass
num += 1
print(count)
|
a,b,c=map(int,input().split(" "))
count=0
while(a<=b):
if c%a==0:
count+=1
a+=1
print(count)
| 1 | 562,731,032,690 | null | 44 | 44 |
n = int(input())
if n<2:
ans = 0
else:
ans =(10**n-(9**n)*2+8**n)%(10**9+7)
print(ans)
|
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 | 55,106,711,828,340 | 78 | 251 |
from math import ceil
print(ceil(int(input())/2))
|
n = int(input())
ans = 0
if n%2 == 0:
ans = n//2
print(ans)
else:
ans = n//2 +1
print(ans)
| 1 | 58,778,498,123,360 | null | 206 | 206 |
n = int(input())
product_list = list()
for i in range(1, 10):
for j in range(1, 10):
product_list.append(i * j)
if n in product_list:
print('Yes')
else:
print('No')
|
from sys import stdin
r, c = [int(x) for x in stdin.readline().rstrip().split()]
table = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(r)]
for row in range(r):
table[row] += [sum(table[row])]
print(*table[row])
col_sum = [sum(x) for x in zip(*table)]
print(*col_sum)
| 0 | null | 80,763,508,546,640 | 287 | 59 |
import sys
n, k = map(int, input().split())
P = int(1e9+7)
def cmb(n, r, P):
r = min(r, n - r)
inv_y = 1
for i in range(1, r + 1):
inv_y = (inv_y * i) % P
inv_y = pow(inv_y, P - 2, P)
x = 1
for i in range(n - r + 1, n + 1):
x = x * i % P
return (x * inv_y) % P
if k >= n:
print(cmb(2*n-1, n, P))
sys.exit()
if k == 1:
print((n * n - 1) % P)
sys.exit()
ans = 1
comb1 = 1
comb2 = 1
for i in range(1, k + 1):
iinv = pow(i, P-2, P)
comb1 = ((comb1 * (n - i)) * (iinv)) % P
comb2 = ((comb2 * (n - i + 1)) * (iinv)) % P
ans = (ans + comb1*comb2) % P
print(ans)
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
SIZE=4*10**5+1; MOD=10**9+7 #998244353 #ここを変更する
SIZE += 1
inv = [0]*SIZE # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD
fac[i] = fac[i-1]*i%MOD
finv[i]= finv[i-1]*inv[i]%MOD
def choose(n,r): # nCk mod MOD の計算
if 0 <= r <= n:
return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
else:
return 0
def resolve():
n, k = lr()
ans = choose(2*n-1, n)
if n-1 > k:
for i in range(1, n-k):
ans -= choose(n, i)*choose(n-1, n-i)
ans %= MOD
print(ans)
resolve()
| 1 | 67,459,206,872,160 | null | 215 | 215 |
while True:
H, W = map(int, input().split())
if H == W == 0:
break
for i in range(W):
print('#', end='')
print('')
for i in range(H - 2):
print('#', end='')
for j in range(W - 2):
print('.', end='')
print('#')
for i in range(W):
print('#', end='')
print('\n')
|
#!/usr/bin/env python3
import sys
def main():
input = sys.stdin.readline
d, t, s = map(int, input().split())
if d / s <= t:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 0 | null | 2,174,833,532,742 | 50 | 81 |
ch = raw_input()
print(chr(ord(ch) + 1))
|
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
base = os.path.dirname(os.path.abspath(__file__))
name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
#print(name)
sys.stdin = open(name)
a = str(input())
print(chr(ord(a)+1))
| 1 | 92,146,626,154,552 | null | 239 | 239 |
a,b,k=map(int,input().split())
if a>=k:
a-=k
elif a+b>=k:
b-=k-a
a=0
else:
a=0
b=0
print('{} {}'.format(a,b))
|
a, b, k = map(int,input().split())
if k >= a + b:
print("0 0")
elif k>a:
print ("0 "+str(a+b-k))
else:
print(str(a-k)+" "+str(b))
| 1 | 104,648,271,776,970 | null | 249 | 249 |
import sys
import math
N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))
F = list(map(int, sys.stdin.readline().rstrip().split()))
A.sort()
A = A[::-1]
F.sort()
def test(x):
res = 0
for i in range(N):
t = A[i] * F[i]
if t > x:
res += math.ceil((t - x) / F[i])
return res <= K
ng = -1
ok = 10**18
while ng + 1 < ok:
mid = (ng + ok) // 2
if test(mid):
ok = mid
else:
ng = mid
print(ok)
|
N, M = map(int, input().split())
S = []
C = []
for m in range(M):
s, c = map(int, input().split())
S.append(s)
C.append(c)
tmp_ans = []
for n in range(10**N):
n = str(n)
if len(n)<N:
continue
flag = True
for s, c in zip(S,C):
if int(n[s-1]) != c:
flag = False
break
if flag:
tmp_ans.append(n)
if len(tmp_ans)>0:
print(min(tmp_ans))
else:
print(-1)
| 0 | null | 112,285,829,853,120 | 290 | 208 |
n,k=map(int,input().split())
print(min(n%k,-n%k))
|
import math
ni = int(input())
xi = map(int, raw_input().split())
yi = map(int, raw_input().split())
p1 = []
p2 = []
p3 = []
p4 = []
for x, y in zip(xi, yi):
p1.append(abs(x - y))
p2.append(abs(x - y)**2)
p3.append(abs(x - y)**3)
p4.append(abs(x - y))
print '%.8f' % reduce(lambda x, y: x + y, p1)
print '%.8f' % reduce(lambda x, y: x + y, p2) ** (1.0/2.0)
print '%.8f' % reduce(lambda x, y: x + y, p3) ** (1.0/3.0)
print '%.8f' % max(p4)
| 0 | null | 19,784,520,811,290 | 180 | 32 |
n, quantum = list(map(int, input().split()))
queue = []
sumOfTime = 0
for _ in range(n):
name, time = input().split()
queue.append([name, int(time)])
while len(queue) > 0:
name, time = queue.pop(0)
if time > quantum:
sumOfTime += quantum
queue.append([name, time - quantum])
else:
sumOfTime += time
print(name, sumOfTime)
|
n,q=map(int,input().split())
#print(n,p)
round_robin=[]
for i in range(n):
x=input().split()
name=x[0]
t=int(x[1])
round_robin.append([name,t])
#print(round_robin)
finished=[]
counter=0
while round_robin:
left_time=round_robin[0][1]
if left_time<=q:
counter+=left_time
finished.append([round_robin[0][0],counter])
del round_robin[0]
else:
counter+=q
left_time-=q
round_robin[0]=[round_robin[0][0],left_time]
round_robin.append(round_robin.pop(0))
for i in finished:
print(*i)
| 1 | 44,403,325,582 | null | 19 | 19 |
import math
def kochcurve(n,p1x,p1y,p2x,p2y):
if n==0:
print("%5f %5f"%(p2x,p2y))
return
sx=(p2x-p1x)/3.0+p1x
sy=(p2y-p1y)/3.0+p1y
tx=(p2x-p1x)*2.0/3+p1x
ty=(p2y-p1y)*2.0/3+p1y
ux=math.cos(math.pi/3)*(tx-sx)-math.sin(math.pi/3)*(ty-sy)+sx
uy=math.sin(math.pi/3)*(tx-sx)+math.cos(math.pi/3)*(ty-sy)+sy
kochcurve(n-1,p1x,p1y,sx,sy)
kochcurve(n-1,sx,sy,ux,uy)
kochcurve(n-1,ux,uy,tx,ty)
kochcurve(n-1,tx,ty,p2x,p2y)
n=input()
p1x=0.0
p1y=0.0
p2x=100.0
p2y=0.0
print("%5f %5f"%(p1x,p1y))
kochcurve(n,p1x,p1y,p2x,p2y)
|
import math
def kock(n,p1,p2):
a=math.radians(60)
if n==0:
return 0
s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
u=[((t[0]-s[0])*math.cos(a)-(t[1]-s[1])*math.sin(a))+s[0],(t[0]-s[0])*math.sin(a)+(t[1]-s[1])*math.cos(a)+s[1]]
kock(n-1,p1,s)
print(" ".join(map(str,s)))
kock(n-1,s,u)
print(" ".join(map(str,u)))
kock(n-1,u,t)
print(" ".join(map(str,t)))
kock(n-1,t,p2)
n=int(input())
start=[float(0),float(0)]
end=[float(100),float(0)]
print(" ".join(map(str,start)))
kock(n,start,end)
print(" ".join(map(str,end)))
| 1 | 127,474,896,678 | null | 27 | 27 |
from __future__ import absolute_import, print_function, unicode_literals
import sys
def judge(a, b, c):
print('YES' if (a == b + c or b == c + a or c == a + b) else 'NO')
sys.stdin.readline()
for line in sys.stdin:
judge(*(int(n) ** 2 for n in line.split()))
|
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]
ans = 0
for R in range(2**H):
for C in range(2**W):
n = 0
for y in range(H):
if R>>y&1:
for x in range(W):
if C>>x&1:
if c[y][x]=="#":
n += 1
if n==K:
ans += 1
print(ans)
| 0 | null | 4,449,943,445,250 | 4 | 110 |
n = int(input())
X = list(map(int, input().split()))
x_min = min(X)
x_max = max(X)
min_val = 10**6 + 1
for i in range(x_min, x_max + 1):
min_val = min(min_val, sum(map(lambda x: (x-i)**2, X)))
print(min_val)
|
N, M, X = map(int, input().split())
C = []
A = []
for _ in range(N):
c, *a = map(int, input().split())
C.append(c)
A.append(a)
ans = 10**18
for s in range(1<<N):
an = 0
L = [0] * M
for i, (c, a) in enumerate(zip(C, A)):
if s>>i&1:
an += c
for j, a_ in enumerate(a):
L[j] += a_
if all(l >= X for l in L):
if an < ans:
ans = an
if ans == 10**18:
print(-1)
else:
print(ans)
| 0 | null | 43,933,532,825,710 | 213 | 149 |
import math
A, B = map(int, input().split())
AA = A * 100 / 8
BB = B * 100 / 10
L = []
for i in range(10000):
if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
L.append(i)
L = sorted(L)
if L == []:
print(-1)
exit()
print(L[0])
|
N, K = map(int, input().split())
W = []
for i in range(N):
W.append(int(input()))
def f(N, K, W, p):
cnt = 0
k = 1
c_k = 0
for w in W:
if c_k + w <= p:
c_k = c_k + w
cnt = cnt + 1
elif k < K and w <= p:
k = k + 1
c_k = w
cnt = cnt + 1
elif k < K and w > p:
pass
else:
break
return cnt
start = 0
end = 1000000000
while start != end:
center = (start + end)//2
if f(N, K, W, center) < N:
start = center + 1
else:
end = center
print(start)
| 0 | null | 28,183,208,929,252 | 203 | 24 |
H = int(input())
W = int(input())
N = int(input())
longer = H
if longer < W:
longer = W
print(((N-1)//longer)+1)
|
while True:
n = int(raw_input())
if n == 0: break
x = map(int, raw_input().split())
ave = sum(x) / float(n)
std = (sum([(e-ave)**2 for e in x])/n)**0.5
print std
| 0 | null | 44,670,254,703,102 | 236 | 31 |
n = int(input())
s = input()
if n % 2 != 0:
print("No")
else:
t = s[:int((n / 2))]
u = t + t
print("Yes" if s == u else "No")
|
import sys
n=int(input())
s=list(input())
if n%2!=0:
print('No')
sys.exit()
a=s[:n//2]
b=s[n//2:]
cnt=0
for i in range(n//2):
if a[i]!=b[i]:
cnt+=1
if cnt==0:
print('Yes')
else:
print('No')
| 1 | 146,994,132,631,808 | null | 279 | 279 |
k=int(input())
if k%2==0 or k%5==0:
print(-1)
else:
i=1
t=7
while t%k!=0:
i+=1
t=(t*10+7)%k
print(i)
|
n, k = map(int, input().split())
mod = 998244353
m_list = []
for _ in range(k):
m_list.append(list(map(int, input().split())))
dp = [0]*n
dp[0] = 1
dp_sum = [0]*n
dp_sum[0] = 1
for i in range(1, n):
for j in range(k):
l, r = m_list[j]
il = i-l
ir = i-r-1
if il < 0:
continue
else:
if ir < 0 :
dp[i] += dp_sum[il]
else:
dp[i] += dp_sum[il] - dp_sum[ir]
dp[i] %= mod
dp_sum[i] = dp_sum[i-1] + dp[i]
dp_sum[i] %= mod
print(dp[n-1] % mod)
| 0 | null | 4,453,828,287,680 | 97 | 74 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import pdb
import sys
F = sys.stdin
N = int(F.readline())
count = 0
A = N // 2
for i in range(1, A+1):
if i*2 != N:
count += 1
print(count)
|
a,b,n = list(map(int,input().split()))
if n < b :
x = n
else :
x = b-1
print(a*x//b-a*(x//b))
| 0 | null | 90,797,171,157,920 | 283 | 161 |
mlist = list([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51])
b = int(input())
print(mlist[b-1])
|
def insertionSort(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt = cnt + 1
a[j+g] = v
def shellSort(a, n):
global cnt
global G
global m
cnt = 0
G = [1]
while 3 * G[0] + 1 <= n:
G = [ 3*G[0]+1 ] + G
m = len(G)
for i in range(0, m):
insertionSort(a, n, G[i])
n = int(input())
a = [int(input()) for i in range(0, n)]
shellSort(a, n)
print(m)
print(*G)
print(cnt)
for i in range(0, n):
print(a[i])
| 0 | null | 25,135,014,914,492 | 195 | 17 |
n,m,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
from itertools import accumulate
import bisect
cumsum_a = list(accumulate(a))
cumsum_b = list(accumulate(b))
ans = 0
for i in range(1, n+1):
if cumsum_a[i-1] > k:
break
cnt_b = bisect.bisect(cumsum_b, k - cumsum_a[i-1])
ans = max(ans, i + cnt_b)
for i in range(1, m+1):
if cumsum_b[i-1] > k:
break
cnt_a = bisect.bisect(cumsum_a, k - cumsum_b[i-1])
ans = max(ans, i + cnt_a)
print(ans)
|
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
for i in range(n):
asum.append(asum[-1]+a[i])
for i in range(m):
bsum.append(bsum[-1]+b[i])
ans=0
for i in range(n+1):
if asum[i]>k:
break
while asum[i]+bsum[m]>k and m>0:
m-=1
ans=max(ans,i+m)
print(ans)
| 1 | 10,708,686,874,608 | null | 117 | 117 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
At = [0]*(N+1)
Bt = [0]*(M+1)
for i in range(N):
At[i+1] = At[i] + A[i]
for i in range(M):
Bt[i+1] = Bt[i] + B[i]
j = M
ans = 0
for i in range(N+1):
if At[i] > K:
break
while At[i] + Bt[j] > K:
j = j - 1
if ans < i + j:
ans = i+j
print(ans)
|
N, M, K = map(int, input().split())
A_list=list(map(int, input().split()))
B_list=list(map(int, input().split()))
import itertools
A_acum=list(itertools.accumulate(A_list))
B_acum=list(itertools.accumulate(B_list))
A_acum.insert(0, 0)
B_acum.insert(0, 0)
"""
A_acum=[0]
B_acum=[0]
for i in range(1, N+1):
A_acum[i]=A_acum[i-1]+A_list[i-1]
for j in range(1, M+1):
B_acum[i]=B_acum[i-1]+B_list[i-1]
"""
ans=0
j=M
for i in range(len(A_acum)): #iは読んだAの本の数
if K<A_acum[i]:
break
res = K - A_acum[i] #残り時間
while res<B_acum[j] and j>0:
j-=1
ans=max(ans, i+j)
print(ans)
| 1 | 10,789,033,609,668 | null | 117 | 117 |
import sys
input_str = sys.stdin.read()
table = [0]*26
letters = "abcdefghijklmnopqrstuvwxyz"
for A in input_str:
index = 0
for B in letters:
if A == B or A == B.upper():
table[index] += 1
break
index += 1
for i in range(len(letters)):
print("{} : {}".format(letters[i],table[i]))
|
#! python3
# counting_characters.py
import sys
sents = [line.strip() for line in sys.stdin.readlines()]
dic = {chr(x):0 for x in range(ord('a'), ord('z')+1)}
for sent in sents:
for c in sent:
x = c.lower()
if ord('a') <= ord(x) and ord(x) <= ord('z'):
dic[x] += 1
for k, v in dic.items():
print(k + ' : ' + str(v))
| 1 | 1,671,908,247,840 | null | 63 | 63 |
def main():
a, b = map(int, input().split())
for i in range(1, 2000):
if i * 8 // 100 == a and i * 10 // 100 == b:
print(i)
break
else:
print(-1)
if __name__ == "__main__":
main()
|
N = int(input())
X = [int(x) for x in input().split()]
G = int(sum(X)/N + 0.5)
ans = sum((x-G)**2 for x in X)
print(ans)
| 0 | null | 61,034,034,947,072 | 203 | 213 |
m1, d1 = [int(i) for i in input().split()]
m2, d2 = [int(i) for i in input().split()]
if m1 == m2:
print(0)
else:
print(1)
|
import sys
while True:
try:
a,b = map(int,raw_input().split())
tempa = a
tempb = b
while tempa % tempb != 0 :
tempa , tempb = (tempb,tempa%tempb)
gcd = tempb
lcm = a * b / gcd
print "%d %d" % ( gcd, lcm)
except EOFError:
break
| 0 | null | 61,958,345,709,848 | 264 | 5 |
n = int(input())
x = input().split()
y = input().split()
import math
for i in range(4):
D = 0
for j in range(n):
if i != 3:
D = D + math.pow(math.fabs(int(x[j]) - int(y[j])),i+1)
else:
compare = math.fabs(int(x[j]) - int(y[j]))
if D < compare:
D = compare
if i != 3:
print('{0:.6f}'.format(math.pow(D,1/(i+1))))
else:
print('{0:.6f}'.format(D))
|
N,M = map(int,input().split())
ac = (N+1)*[0]
wa = (N+1)*[0]
pt = 0
for i in range(M):
p,s = input().split()
p = int(p)
if ac[p] == 0 and s == "AC":
ac[p] = 1
pt += wa[p]
wa[p] += 1
print(sum(ac),pt)
| 0 | null | 46,734,144,013,440 | 32 | 240 |
a,b,c = map(int, input().split())
if a==b==c:
print('No')
elif a==b or b==c or c==a:
print('Yes')
else:
print('No')
|
A, B, C = map(int, input().split())
if A == B or B == C or C == A:
if A == B and B == C:
print('No')
else:
print('Yes')
else:
print('No')
| 1 | 68,393,632,531,680 | null | 216 | 216 |
#nord_aで使っている色の+1
#初期入力
import sys
input = sys.stdin.readline
#from collections import deque
import heapq
N = int(input())
connection ={i:set() for i in range(1,N+1)}
A =[[i] for i in range(N-1)]
A_sort =sorted(A)
for i in range(N-1):
a,b = (int(x) for x in input().split())
connection[a].add(b) # つながりを逆向きも含めて入力
connection[b].add(a) #
A_sort[i].append((a,b)) #色を出力するため
A_sort.sort(key=lambda x:x[1])
#色の数(各頂点の最大値)
color_max =0
for i in connection.values():
color_max =max(color_max, len(i) )
#各頂点に色を準備⇒辺の色決定
aa=[]
hq_none =heapq.heapify(aa)
color_node ={i:[] for i in range(1,N+1)} #頂点に使った色の管理,dequeで高速?
for i in range(1,N+1):
heapq.heapify(color_node[i])
color_edge =[0]*(N-1)
for i in range(N-1):
n_a,n_b = A_sort[i][1] #i番目の辺とつながっている頂点
if color_node[n_a] ==[]:
color =0
else:
color =(color_node[n_a][0]) -1
while True:
#color +=1
q,color =divmod(color,(-1)*color_max)
if color not in color_node[n_a] and color not in color_node[n_b]:
#color_edge[i] =color+1 #辺の色を出力用に決める。1~color_max
A_sort[i].append((-1)*color+1) #辺の色を出力用に決める。1~color_max,A_sortに入れて、再度ソート
heapq.heappush(color_node[n_a],color) #前の頂点に使った色を追加、
heapq.heappush(color_node[n_b],color) #heapqの最大値出したいので*(-1)
break
else:
color -=1
#出力
print(color_max)
A_sort.sort()
for i in A_sort:
print(i[2])
|
n = int(input())
G = [[] for _ in range(n)]
edge = []
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
G[a].append(b)
edge.append(b)
from collections import deque
q = deque()
color = [0]*n
q.append(0)
while q:
cur = q.popleft()
c = 1
for nx in G[cur]:
if color[cur] == c:
c += 1
color[nx] = c
c += 1
q.append(nx)
print(max(color))
for e in edge:
print(color[e])
| 1 | 135,720,140,446,304 | null | 272 | 272 |
import sys
from itertools import accumulate
n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
aa = list(accumulate(a))
MOD = 10**9+7
ans = 0
for i in range(n):
ans += a[i]*(aa[n-1] - aa[i])
print(ans%MOD)
|
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c)
| 1 | 3,815,555,057,270 | null | 83 | 83 |
a, b = map(int, input().split())
if (a < 10):
if (b < 10):
ans = a * b
else:
ans = -1
else:
ans = -1
print(ans)
|
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 8 20:45:37 2020
@author: liang
"""
def gcc(a,b):
if b == 0:
return a
return gcc(b, a%b)
A, B = map(int, input().split())
if A < B:
A ,B = B, A
print(A*B//gcc(A,B))
| 0 | null | 135,929,495,657,602 | 286 | 256 |
r = int(input())
r2 = r**2
ans = r**2 / 1
print(int(ans))
|
x, y = map(int, input().split())
prise_dict = {3: 100000, 2: 200000, 1: 300000}
ans = 0
if x in prise_dict.keys():
ans += prise_dict[x]
if y in prise_dict.keys():
ans += prise_dict[y]
if x == y == 1:
ans += 400000
print(ans)
| 0 | null | 142,503,135,160,818 | 278 | 275 |
N=int(input())
import math
X=math.ceil(N/1.08)
if int(X*1.08)==N:
print(X)
else:
print(':(')
|
import math
import sys
n = int(input())
found = False
if(n <= 12):
print(n)
sys.exit()
for y in range(n):
if n == math.floor(y*1.08):
print(y)
found = True
break
if (found == False):
print(":(")
| 1 | 126,298,808,251,788 | null | 265 | 265 |
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
def mod_pow(x, n, mod=10**9 + 7) -> int:
"""
O(log n)
"""
if n == 0:
return 1
K = 1
while n > 1:
if n % 2 != 0:
K *= x
K %= mod
x *= x
x %= mod
n //= 2
return (K * x) % mod
MOD = 998244353
n = int(input())
D = [int(i) for i in input().strip().split()]
_max = max(D)
counts = defaultdict(int)
if D[0] != 0:
print(0)
sys.exit()
for d in D:
counts[d] += 1
if counts[0] != 1:
print(0)
sys.exit()
ans = 1
for i in range(1, _max + 1):
if i not in counts.keys():
print(0)
sys.exit()
elif i == 1:
continue
else:
x = counts[i - 1]
k = counts[i]
ans = (ans * mod_pow(x, k, MOD)) % MOD
print(ans)
|
N,D=open(0)
*D,=map(int,D.split())
c=[0]*-~max(D)
for i in D:c[i]+=1
a=D[0]<1==c[0]
for i,j in zip(c,c[1:]):a*=i**j
print(a%998244353)
| 1 | 154,786,552,444,952 | null | 284 | 284 |
n = input()
for i in xrange(n):
tmp = map(int, raw_input().split())
if tmp[0]**2 + tmp[1]**2 == tmp[2]**2 or tmp[1]**2 + tmp[2]**2 == tmp[0]**2 or tmp[2]**2 + tmp[0]**2 == tmp[1]**2:
print "YES"
else:
print "NO"
|
N,A,B=map(int,input().split())
ans=0
if (B-A)%2==0:
ans=(B-A)//2
else:
if A-1<N-B:
if B-A==1:
ans=B-1
else:
ans=A+(B-A-1)//2
else:
if B-A==1:
ans=N-A
else:
ans=N-B+1+(N-(A+N-B+1))//2
print(ans)
| 0 | null | 54,954,477,987,008 | 4 | 253 |
import math
while 1:
n = input()
if n == 0:
break
x = map(float,raw_input().split())
m = float(sum(x)/n)
s = 0
for i in x:
s += (i-m) ** 2
print math.sqrt(s/n)
|
import statistics as st
while(1):
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
print(st.pstdev(s))
| 1 | 194,314,574,002 | null | 31 | 31 |
def calc_divisor(x):
divisor = []
for i in range(1, int(x ** 0.5) + 1):
if x % i == 0:
divisor.append(i)
if i != x // i:
divisor.append(x // i)
return divisor
N = int(input())
ans = len(calc_divisor(N - 1)) - 1
cand = sorted(calc_divisor(N))[1:]
for k in cand:
x = N
while x % k == 0:
x //= k
if x % k == 1:
ans += 1
print(ans)
|
"""
Nが1になるようなKは、
・K^x = NになるようなKか
・K^x(K*y+1) = N になるようなKである。
後者は前者を包括するので、後者についてのみカウントすればよい。
Kの数を求めるために、後者をさらに2種類に分ける
・x > 0の場合
・x == 0の場合
前者の場合、KはNの約数なので、Nの約数全部に関して条件を満たすか調べればよい。Nの約数はそんなに多くならないので、時間はかからない。
後者の場合だと、KはN-1の約数の数だけ存在するのでN-1の約数の数を求めればよい。
"""
from collections import Counter
def gcd(a,b):
return a if b==0 else gcd(b,a%b)
N = int(input())
ans = 0
#x>0の場合を調べる
#Nを素因数分解する
devisers = []
d = 2
while d*d < N:
if N % d == 0:
devisers.append(d)
devisers.append(N//d)
d += 1
if d*d == N:
devisers.append(d)
for d in devisers:
dummyN = N
while dummyN % d == 0:
dummyN //= d
if dummyN%d == 1:
ans += 1
#x == 0 になるようなKの数を調べる。
#N-1を素因数分解する。
tmp = []
dummyN = N-1
ceil = int(dummyN**0.5)
for d in range(2,ceil+1):
while dummyN % d == 0:
tmp.append(d)
dummyN //= d
if dummyN != 1:
tmp.append(dummyN)
dummyN //= dummyN
divideN = Counter(tmp)
commonDCnt = 1
for v in divideN.values():
commonDCnt *= (v+1)
ans += commonDCnt
print(ans)
| 1 | 41,315,317,452,068 | null | 183 | 183 |
def main():
N, K = input_ints()
A = input_int_list_in_line()
for i in range(N-K):
if A[i] < A[i+K]:
print('Yes')
else:
print('No')
def input_ints():
line_list = input().split()
if len(line_list) == 1:
return int(line_list[0])
else:
return map(int, line_list)
def input_int_list_in_line():
return list(map(int, input().split()))
def input_int_tuple_list(n: int):
return [tuple(map(int, input().split())) for _ in range(n)]
main()
|
m, n = map(int, input().split())
l = list(map(int, input().split()))
for i in range(m-n):
if l[i] < l[i+n]:
print('Yes')
else:
print('No')
| 1 | 7,108,978,063,890 | null | 102 | 102 |
a = str(input())
a = a.swapcase()
print(a)
|
import numpy as np
from numba import njit
@njit("i8[:](i8, i8[:], i8[:])", cache=True)
def cumsum(K, A, cA):
for i, a in enumerate(A):
cA[i] += cA[i - 1] + A[i]
if cA[i] > K:
break
cA = cA[cA != 0]
cA = np.append(0, cA)
return cA
@njit("i8(i8, i8[:], i8[:])", cache=True)
def solve(K, cA, cB):
ans = np.searchsorted(cA, K - cB, side="right") - 1
ans += np.arange(len(cB))
return ans.max()
N, M, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
cA = np.zeros(N, dtype=np.int64)
cB = np.zeros(M, dtype=np.int64)
# np.cumsumだとoverflowする
cA = cumsum(K, A, cA)
cB = cumsum(K, B, cB)
ans = solve(K, cA, cB)
print(ans)
| 0 | null | 6,169,747,948,900 | 61 | 117 |
#!/usr/bin/env python3
import sys
import heapq
MOD = 1000000007 # type: int
def containPositive(arr):
for a in arr:
if a >= 0:
return True
return False
def solve(N: int, K: int, A: "List[int]"):
if N == K:
m = 1
for a in A:
m = m*a%MOD
print(m)
elif not containPositive(A) and K%2 == 1:
A = list(reversed(sorted(A)))
m = 1
for i in range(K):
m = m*A[i]%MOD
print(m)
else:
m = 1
B = [(abs(a),a) for a in A]
B = list(reversed(sorted(B)))
lastNegative = 0
lastPositive = 1
hadPositive = False
for i in range(K):
a = B[i][1]
if a < 0:
if lastNegative == 0:
lastNegative = a
else:
m = m*lastNegative*a%MOD
lastNegative = 0
else:
if a > 0 and lastPositive != 1:
m = m*lastPositive%MOD
if a > 0:
lastPositive = a
hadPositive = True
else:
m=m*a%MOD
if lastNegative == 0:
print(m*lastPositive%MOD)
else:
nextNegative = 0
for i in range(K,N):
b = B[i][1]
if b < 0:
nextNegative = b
break
if nextNegative == 0:
m = m*B[K][1]
print(m*lastPositive%MOD)
else:
c1 = lastNegative*nextNegative
nextPositive = 0
k = K
while k < N:
a = B[k][1]
if a >=0:
nextPositive = a
break
k+=1
c2 = nextPositive*lastPositive
if not hadPositive: # This array contain some non-negative value. This means the result value could be positive. But if there were no positive values in the first K values sorted by the absolute value, use just next positive value instead of the last negative values.
m = m*nextPositive%MOD
print(m)
exit()
if c1 > c2:
m = m*lastNegative*nextNegative%MOD
print(m)
else:
m =m*nextPositive*lastPositive%MOD
print(m)
# 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()
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, K, A)
if __name__ == '__main__':
main()
|
def insertionSort(A, n, g):
ret=0
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
ret+=1
A[j+g] = v
return ret
n=int(input())
arr=[int(input()) for _ in range(n)]
cnt=0
g=[]
h=1
while h<=n:
g.append(h)
h=h*3+1
g=sorted(g,reverse=True)
m=len(g)
for i in range(m):
cnt+=insertionSort(arr, n, g[i])
print(m)
print(' '.join(map(str,g)))
print(cnt)
for i in range(n):
print(arr[i])
| 0 | null | 4,711,015,621,490 | 112 | 17 |
def Is_ToPut(p,w,k):
count =1
temp =p
for i in w:
if temp >= i:
temp -=i
elif i > p :
return 0
else:
count +=1
temp =p-i
if count <= k:return 1
else:return 0
n,k = list(map(int,input().split(' ')))
w =[]
for _ in range(n):
w.append(int(input()))
ans =100000*10000
left = 0
right = 100000*10000
while left < right:
p = (left+right)//2
if Is_ToPut(p,w,k):
if ans > p:ans =p
right=p
else:
left = p +1
print(ans)
|
import sys
sys.setrecursionlimit(10**6)
def solve(n,a):
wa=0
for i in range(n):
if(i%2==0):
wa+=a[i]
kotae=wa
for i in range(n//2):
wa+=a[(n//2-i-1)*2+1]
wa-=a[(n//2-i-1)*2]
if(wa>kotae):
kotae=wa
return kotae
def dfs(n,a,k):
global zen
zen.append([n,k])
if(k==1):
return max(a)
ari=a[n-1]+dfs(n-2,a[:n-2],k-1)
if(n==k*2-1):
return ari
nasi=dfs(n-1,a[:n-1],k)
return max(ari,nasi)
n=int(input())
a=list(map(int,input().split()))
if(n%2==0):
print(solve(n,a))
else:
data=[[a[0],a[0]],[max(a[:2]),max(a[:2])]]
#data.append([max(a[:3]),sum(a[:3])-min(a[:3])])
data.append([max(a[:3]),a[0]+a[2]])
for i in range(3,n):
if(i%2==1):
ari=a[i]+data[i-2][0]
nasi=data[i-1][1]
saiyo=max(ari,nasi)
data.append([saiyo,saiyo])
else:
ooi=a[i]+data[i-2][1]
nasi=data[i-1][1]
ari=a[i]+data[i-2][0]
sukunai=max(ari,nasi)
data.append([sukunai,ooi])
print(data[n-1][0])
| 0 | null | 18,673,066,964,288 | 24 | 177 |
H, A = map(int, input().split())
print(H//A + 1 if H%A else H//A)
|
a = input().split()
b = list(map(int, input().split()))
c = input()
if a[0]==c:
print(b[0]-1, b[1])
else:
print(b[0], b[1]-1)
| 0 | null | 74,239,580,750,852 | 225 | 220 |
_ = input()
a = list(input())
cnt = 0
word = 0
for i in a:
if word == 0 and i == 'A':
word = 1
elif word == 1 and i =='B':
word = 2
elif word == 2 and i =='C':
word = 0
cnt += 1
else:
if i == 'A':
word = 1
else:
word = 0
print(cnt)
|
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()
def main():
x, k, d = map(int, input().split())
desired = abs(x) // d
if k <= desired:
if x < 0:
x += k * d
else:
x -= k * d
print(abs(x))
return
if x < 0:
x += desired * d
else:
x -= desired * d
if (k - desired) % 2 == 0:
print(abs(x))
return
if x == 0:
print(d)
elif x > 0:
x -= d
print(abs(x))
elif x < 0:
x += d
print(abs(x))
if __name__ == '__main__':
main()
| 0 | null | 52,048,468,324,072 | 245 | 92 |
N,M = list(map(int,input().strip().split()))
K = N//2
ans = []
if N == 3:
ans = [(1,2)]
elif N == 4:
ans = [(1,2)]
elif N == 5:
ans = [(1,2),(3,5)]
else:
left = 1
right = K
while left<right:
ans += [(left,right)]
left+=1
right-=1
left = K+1
right = N
if (right-left)%2 == (K-1)%2:
right -= 1
while left<right:
ans += [(left,right)]
left += 1
right -= 1
for i in range(M):
print(ans[i][0],ans[i][1])
|
n = raw_input()
A = map(int, raw_input().split())
for i, key in enumerate(A):
j = i - 1
while(j >= 0 and A[j] > key):
A[j+1] = A[j]
j -= 1
A[j+1] = key
for x in A:
print x,
print
| 0 | null | 14,339,446,801,050 | 162 | 10 |
#!/usr/bin/env python3
import sys
def solve(r: int):
print(pow(r, 2))
return
# Generated by 1.1.6 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()
r = int(next(tokens)) # type: int
solve(r)
if __name__ == '__main__':
main()
|
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
H_sort = sorted(H,reverse=True)
print(sum(H_sort[K:]))
| 0 | null | 112,179,727,337,380 | 278 | 227 |
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))
if __name__ == "__main__":
x = I()
n = x//100
a = x%100
print(1 if a <= 5*n else 0)
|
#!/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()))
x = I()
y = x // 100
z = x % 100
if 0 <= z <= 5*y:
print(1)
else:
print(0)
| 1 | 127,391,669,287,622 | null | 266 | 266 |
import math
K = int(input())
ans = 0
A = {}
for a in range(1, K+1):
A[a] = 0
for a in range(1, K+1):
for b in range(1, K+1):
num = math.gcd(a, b)
A[num] += 1
for c in range(1, K+1):
for k in A.keys():
num = math.gcd(c, k) * A[k]
ans += num
print(ans)
|
n,m=map(int,input().split())
for i in range(m):
print(i+1,n-i-((i>=m/2)&~n))
| 0 | null | 32,140,966,371,812 | 174 | 162 |
num_employees = int(input())
bosses = list(map(int, input().split()))
counter = [0] * num_employees
for boss in bosses:
counter[boss - 1] += 1
print('\n'.join(map(str, counter)))
|
# dfs
import collections,sys
sys.setrecursionlimit(10**9)
n,m,k = map(int, input().split())
friend = [[]*(n+1) for _ in range(n+1)]
block = [[]*(n+1) for _ in range(n+1)]
teams = [0]*(n+1)
for _ in range(m):
a,b = map(int, input().split())
friend[a].append(b)
friend[b].append(a)
for _ in range(k):
c,d = map(int, input().split())
block[c].append(d)
block[d].append(c)
def dfs(i):
teams[i] = team
for j in friend[i]:
if teams[j] != 0:
continue
dfs(j)
team=1
for i in range(1,n+1):
if teams[i] != 0:
continue
dfs(i)
team+=1
c = collections.Counter(teams)
for i in range(1,n+1):
temp = c[teams[i]]-len(friend[i])-1
for j in block[i]:
if teams[j] == teams[i]:
temp -= 1
print(temp, end='')
if i != n:
print(" ", end='')
| 0 | null | 47,305,583,773,162 | 169 | 209 |
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
def ceiler(a,b):
return -((-a)//b)
n,k=MI()
costs=LI()
difs=LI()
costs.sort()
difs.sort(reverse=True)
lis=[0 for i in range(n)]
#print(costs)
#print(difs)
for i in range(n):
lis[i]=costs[i]*difs[i]
#print(lis)
def judge(x):
times=0
for i in range(n):
u=ceiler(lis[i]-x,difs[i])
times+=max(0,u)
#print(u)
#print(x,times<=k)
return times<=k
l,r=-1,10**13
while l+1<r:
mid=(l+r)//2
if judge(mid):
r=mid
else:
l=mid
print(r)
|
import sys
input = sys.stdin.readline
import numpy as np
def main():
n, k = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
def is_time(x):
c = np.maximum(A - x//F, 0).sum()
if c <= k:
return True
return False
ng = -1
ok = max(A*F)
while ok - ng > 1:
m = (ng + ok)//2
if is_time(m):
ok = m
else:
ng = m
print(ok)
if __name__ == "__main__":
main()
| 1 | 165,455,949,587,122 | null | 290 | 290 |
import sys
import string
s = sys.stdin.read().lower()
for a in string.ascii_lowercase:
print('{0} : {1}'.format(a, s.count(a)))
|
c=[0]*26
while 1:
try:
t=list(raw_input().lower())
for i in range(len(t)):
if 0<=ord(t[i])-ord("a")<=25:
c[ord(t[i])-ord("a")]+=1
except EOFError:
break
for i in range(26):
print chr(ord("a")+i),":",c[i]
| 1 | 1,685,946,705,940 | null | 63 | 63 |
x = tuple(input().split())
a = int(x[0])
b = int(x[1])
c = int(x[2])
k = 0
for n in range(1, c+1):
if divmod(c, n)[1] == 0 and a <= divmod(c, n)[0] <= b:
k += 1
print(k)
|
x = raw_input().split()
a = x[0]
b = x[1]
c = x[2]
A = 0
for i in range(int(a),int(b)+1):
if int(c) % int(i) ==0:
A += 1
elif int(c) % int(i) != 0:
A += 0
print A
| 1 | 558,456,618,918 | null | 44 | 44 |
X,N=map(int,input().split())
if N>0:
P=list(map(int,input().split()))
for i in range(N+1):
if X-i not in P:
print(X-i)
break
elif X+i not in P:
print(X+i)
break
else:
print(X)
|
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(N!=0):
for a in lst:
fl.append(int(a))
for a in range(101):
if(X-a not in fl):
print(X-a)
break
if(X+a not in fl):
print(X+a)
break
| 1 | 14,121,551,525,602 | null | 128 | 128 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.