code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
X = list(map(int, input().split()))
if X[0] == 0:
print(1)
elif X[1] == 0:
print(2)
elif X[2] == 0:
print(3)
elif X[3] == 0:
print(4)
else:
print(5) | N = int(input())
A = [[0]*10 for _ in range(10)]
for i in range(1,N+1):
a = i%10 #1の位
b = i // (10**(len(str(i))-1))
if a!= 0:
A[a][b] += 1
t = 0
for i in range(1,10):
s = A[i][i]
if s != 0:
t += int(s + (s*(s-1)))
for i in range(1,9):
for j in range(i+1,10):
t += A[i][j] * A[j][i]*2
print(t) | 0 | null | 50,093,240,183,930 | 126 | 234 |
data = input()
data = data.split()
print("Yes") if int(data[0]) / int(data[2]) <= int(data[1]) else print("No") | a = input().split()
D = int(a[0])
T = int(a[1])
S = int(a[2])
jikan = D / S
if(jikan > T):
print("No")
else:
print("Yes") | 1 | 3,523,083,648,188 | null | 81 | 81 |
N, X, Y = map(int, input().split())
ans = [0] * (N + 1)
for i in range(1, N):
for j in range(i+1, N+1):
dis1 = j-i
dis2 = abs(X-i) + 1 + abs(Y - j)
dis3 = abs(Y-i) + 1 + abs(X - j)
d = min(dis1,dis2,dis3)
ans[d] += 1
for i in range(1, N):
print(ans[i]) | import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
H, W = map(int, readline().split())
import math
if H == 1 or W == 1:
print(1)
exit()
total = H * W
ans = (total + 2 - 1) // 2
print(ans) | 0 | null | 47,456,617,397,692 | 187 | 196 |
N, M, K = map(int, input().split())
MOD = 998244353
n = N
fac = [1]*(n+1)
rev = [1]*(n+1)
for i in range(1,n+1):
fac[i] = i*fac[i-1]%MOD
rev[i] = pow(fac[i], MOD-2, MOD)
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
ans = 0
for i in range(K+1):
ans += comb(N-1, N-1-i) * M * pow(M-1, N-1-i, MOD)
ans %= MOD
print(ans)
| import math
import sys
import os
from operator import mul
import bisect
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
N = I()
S = list(_S())
ans = 0
r = []
g = []
b = []
for i,s in enumerate(S):
if s == 'R':
r.append(i)
if s == 'G':
g.append(i)
if s == 'B':
b.append(i)
# j = bisect.bisect_right(<list>,<value>)
# print(r)
# print(g)
# print(b)
# for i in r:
# for j in g:
# for k in b:
# tmp = sorted([i,j,k])
# if not tmp[1]-tmp[0]==tmp[2]-tmp[1]:
# ans += 1
ans = len(r)*len(g)*len(b)
for i in range(N):
for j in range(i,N):
k = j + (j-i)
if k > N-1:
break
if S[i]==S[j]:
continue
if S[i]==S[k] or S[j]==S[k]:
continue
ans -= 1
print(ans)
# R G B
# R B G
# G B R
# G R B
# B G R
# B R G
# i j k
# - != -
# RBRBGRBGGB
# 1122233333
# 0000111233
# 0112223334
# B*3
# G*4
# GB系: (2,4), (4,5)
# RB系: (1,3), | 0 | null | 29,817,096,265,012 | 151 | 175 |
n = int(input())
a = input().split()
a.reverse()
print(' '.join(a)) | a=[]
n = int(input())
s = input().rstrip().split(" ")
for i in range(n):
a.append(int(s[i]))
a=a[::-1]
for i in range(n-1):
print(a[i],end=' ' )
print(a[n-1]) | 1 | 993,591,941,760 | null | 53 | 53 |
print([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][int(input())-1])
| # coding: utf-8
num_array = [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]
k = int(input())
print("{}".format(num_array[k-1]))
| 1 | 50,294,645,234,230 | null | 195 | 195 |
X=int(input())
maisu_max=X//100
if X<100:
print(0)
exit()
else:
X=str(X)
X=int(X[-2:])
if X==0:
print(1)
exit()
ans=100
for i in range(2):
for j in range(2):
for k in range(2):
for l in range(2):
for m in range(20):
tmp=i+j*2+k*3+l*4+m*5
if tmp==X:
if i+j+k+l+m<ans:
ans=i+j+k+l+m
if maisu_max>=ans:
print(1)
else:
print(0)
| X = int(input())
num_item = int(X // 100)
remain = X - num_item * 100
if remain <= num_item * 5:
print(1)
else:
print(0) | 1 | 127,372,452,072,258 | null | 266 | 266 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def f(x):
cnt = 0
while x%2 == 0:
cnt += 1
x //= 2
return cnt
def lcm(x,y):
return x*y//math.gcd(x,y)
n,m = inpl()
a = inpl()
a = list(set(a))
c = list(set([f(x) for x in a]))
if len(c) != 1:
print(0)
quit()
c = c[0]
x = 1
for i in range(len(a)):
x = lcm(a[i]//2, x)
# print(x)
print((m+x)//(2*x)) | import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import reduce
# from math import *
from fractions import *
N, M = map(int, readline().split())
A = list(map(lambda x: int(x) // 2, readline().split()))
def f(n):
cnt = 0
while n % 2 == 0:
n //= 2
cnt += 1
return cnt
t = f(A[0])
for i in range(N):
if f(A[i]) != t:
print(0)
exit(0)
A[i] >>= t
M >>= t
lcm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
if lcm > M:
print(0)
exit(0)
print((M // lcm + 1) // 2)
| 1 | 101,441,703,960,136 | null | 247 | 247 |
input_line = int(input())
if input_line > 1 :
count = 10**input_line - 8**input_line - (9**input_line - 8**input_line) * 2
print(count % (10**9 + 7))
else :
print(0) | s = input()
l = len(s)
ans = 'x' * l
print(ans) | 0 | null | 38,057,309,802,348 | 78 | 221 |
S =input()
ans = chr(ord(S) + 1)
print(ans) | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
c = input()
c = chr(ord(c)+1)
print(c) | 1 | 92,428,402,471,008 | null | 239 | 239 |
S = input()
if S == 'ABC':
answer = 'ARC'
elif S == 'ARC':
answer = 'ABC'
else:
answer = '入力間違い【ABC】【ARC】を入力'
print(answer) | def resolve():
S = input()
if S[1] == "B":
print("ARC")
else:
print("ABC")
if __name__ == "__main__":
resolve() | 1 | 24,159,850,604,890 | null | 153 | 153 |
print(len(set(input()))%2*'Yes'or'No') | A,B,C = map(int,input().split())
if (A==B) and A !=C:
print("Yes")
elif (B==C ) and B !=A:
print("Yes")
elif (C==A ) and C !=B:
print("Yes")
else:
print("No") | 1 | 68,071,699,415,940 | null | 216 | 216 |
from collections import deque
dq = deque()
for _ in [None]*int(input()):
s = input()
if s == "deleteFirst":
dq.popleft()
elif s == "deleteLast":
dq.pop()
else:
a, b = s.split()
if a == "insert":
dq.appendleft(b)
else:
if b in dq:
dq.remove(b)
print(" ".join(dq))
| import sys
from collections import deque
n = int(input())
ary = deque([])
for line in sys.stdin:
op = line.strip().split()
cmd = op[0]
if cmd[0] == 'i':
x = op[1]
ary.appendleft(x)
elif len(cmd) == 6:
x = op[1]
if x in ary:
ary.remove(x)
elif len(cmd) == 10:
ary.pop()
else:
ary.popleft()
print(*ary)
| 1 | 48,215,096,188 | null | 20 | 20 |
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
H,W = map(int, input().split())
s = [None for _ in range(H)]
for i in range(H):
s[i] = input()
dp = [[0]*(W+1) for _ in range(H+1)]
if s[0][0] == '#':
dp[1][1] += 1
for i in range(H):
for j in range(W):
if (i,j) == (0,0):
continue
tmp = []
if i > 0:
if s[i][j] == '#' and s[i-1][j] == '.':
tmp.append(dp[i][j+1]+1)
else:
tmp.append(dp[i][j+1])
if j > 0:
if s[i][j] == '#' and s[i][j-1] == '.':
tmp.append(dp[i+1][j]+1)
else:
tmp.append(dp[i+1][j])
dp[i+1][j+1] = min(tmp)
print(dp[H][W]) | def main2():
K = int(input())
rem = set()
n = ans = 0
while True:
n = n * 10 + 7
ans += 1
if n % K == 0:
print(ans)
break
else:
n = n % K
if n in rem:
print(-1)
break
else:
rem.add(n)
if __name__ == "__main__":
main2() | 0 | null | 27,724,641,013,410 | 194 | 97 |
import sys
input = sys.stdin.readline
def inpl():
return list(map(int, input().split()))
N, M = inpl()
coins = inpl()
dp = [i for i in range(N + 1)]
coins.sort()
for n in range(coins[1], N + 1):
for c in coins[1:]:
if c > n:
continue
dp[n] = min(dp[n], dp[n - c] + 1)
# print(dp[N])
print(dp[N])
| from decimal import (Decimal, ROUND_DOWN)
x=Decimal(input())
year = 0
money = 100
while money < x:
money += Decimal(money / 100).quantize(Decimal('0'), rounding=ROUND_DOWN)
year += 1
print(year)
| 0 | null | 13,655,065,243,820 | 28 | 159 |
"""
方針:
幸福度が一定以上のつなぎ方の数→NlogNで二分探索可能
採用するうち最小の幸福度を NlogNlogNで探索
累積和を用いて合計を算出
2 3
5 2
10 + 7 + 7 = 24
"""
import bisect
def wantover(n): #n以上の幸福度のつなぎ方の数がM以上ならTrueを返す
ret = 0
for i in range(N):
serchnum = n - A[i]
ret += (N - bisect.bisect_left(A,serchnum))
#print ("over",n,"is",ret)
if ret >= M:
return True
else:
return False
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
#print (wantover(7))
hpl = 0
hpr = A[-1] * 2 + 1
while hpr - hpl != 1:
mid = (hpr + hpl) // 2
if wantover(mid):
hpl = mid
else:
hpr = mid
#ここで最小の幸福度はhpl
#print (hpl,hpr)
B = [0] #累積和行列
for i in range(N):
B.append(B[-1] + A[-1 - i])
#print (A)
#print (B)
ans = 0
plnum = 0 #つないだ手の回数
for i in range(N):
i = N-i-1
ind = bisect.bisect_left(A,hpl - A[i])
#print (hpl,A[i],N-ind)
plnum += N - ind
ans += B[N - ind] + A[i] * (N-ind)
#print (ans,plnum)
print (ans - hpl * (plnum - M))
| def run(N, M, A):
'''
Aiが10^5なので、searchを以下に変えられる
サイズ10**5のリストで、その満足度を持つ数の件数を事前計算しておけばO(1)で求められる
'''
A = sorted(A, reverse=True)
cnt_A = [len(A)]
pre_a = 0
cnt_dict_A = {}
for a in sorted(A):
cnt_dict_A[a] = cnt_dict_A.get(a, 0) + 1
next_cnt = cnt_A[-1]
for a in sorted(cnt_dict_A.keys()):
cnt_A.extend([next_cnt]*(a-pre_a))
pre_a = a
next_cnt = cnt_A[-1]-cnt_dict_A[a]
right = A[0] * 2
left = 0
while left <= right:
X = (left + right) // 2
# 左手の相手がaで、満足度がX以上となる組合せの数
cnt = 0
for a in A:
# cnt += search(A, X - a)
if X - a <= A[0]:
if X - a >= 0:
cnt += cnt_A[X - a]
else:
cnt += cnt_A[0]
if cnt >= M:
res = X
left = X + 1
else:
right = X - 1
X = res
# Xが決まったので、累積和で組合せの数分の値を求める
sum_A = [0]
for a in sorted(A):
sum_A.append(sum_A[-1] + a)
sum_cnt = 0
ans = 0
for a in A:
cnt = search(A, X - a)
sum_cnt += cnt
if cnt > 0:
ans += cnt * a + sum_A[-1] - sum_A[-cnt-1]
if sum_cnt > M:
ans -= X * (sum_cnt - M)
return ans
def search(A, X):
'''
AのリストからX以上となる数値がいくつか探す
Aはソート済み(降順)
二分探索で実装O(logN)
leftとrightはチェック未
middleはループ終了後チェック済み
'''
left = 0
right = len(A) - 1
res = 0
while left <= right:
middle = (left + right) // 2
if A[middle] >= X:
res = middle + 1
left = middle + 1
else:
right = middle - 1
return res
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(run(N, M, A))
if __name__ == '__main__':
main()
| 1 | 107,605,086,178,900 | null | 252 | 252 |
# 全探索
n=int(input())
class People:
def __init__(self):
self.type=None
peoples=[People() for i in range(n+1)]
def change_10to2(i):
ans=format(i, '#0' + str(n + 3) + 'b')[2:]
return ans
def set_people_type(binary_list,peoples):
for i,people in enumerate(peoples):
if i!=0:
people.type=binary_list[i]
def get_statement():
shougen={}
for i in range(1,n+1):
ai=int(input())
ans=[]
for j in range(ai):
kumi=[int(k) for k in input().split()]
ans.append(kumi)
shougen[str(i)]=ans
return shougen
shougens=get_statement()
def shougen_dicide(peoples,shougens):
for i in range(1,n+1):
shougen=shougens[str(i)]
for shou in shougen:
people,type=shou
people=int(people)
type=str(type)
# 正直者のとき
if peoples[i].type=="1":
if peoples[people].type!=type:
return False
# #嘘つきのとき
# else:
# if peoples[people].type==type:
# return False
return True
ans=0
for i in range(2**n):
binary_list=change_10to2(i)
set_people_type(binary_list,peoples)
if shougen_dicide(peoples,shougens):
ans=max(ans,binary_list.count("1"))
print(ans)
| N = int( input( ) )
x = N % 1000
if x == 0 :
print( '0' )
else :
print( 1000 - int(x) ) | 0 | null | 65,126,934,385,628 | 262 | 108 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
p = 10**9+7
from math import gcd
from collections import Counter
from collections import defaultdict
used = defaultdict(list)
n = int(input())
ctr = Counter()
az = bz = zz = 0
for i in range(n):
a, b = map(int, input().split())
if a==b==0:
zz+=1
elif a==0:
az+=1
elif b==0:
bz+=1
else:
g = gcd(a,b)
a,b = a//g, b//g
if b < 0:
a*=-1
b*=-1
ctr[(a,b)]+=1
used[(a,b)]=False
ans = 1
# 仲の悪いグループ対ごとに処理する
for (a1,b1),v1 in ctr.items():
if used[(a1,b1)]:
continue
a2,b2=-b1,a1
if b2 < 0:
b2*=-1
a2*=-1
v2 = ctr[(a2,b2)]
r = (pow(2,v1,p)+pow(2,v2,p)-1)%p
ans*=r
ans%=p
used[(a1,b1)]=True
used[(a2,b2)]=True
# 片方が0のクループ対
r = (pow(2,az,p)+pow(2,bz,p)-1)%p
ans*=r
ans%=p
ans+=zz # 0匹のケースは禁止されている
ans-=1 # 0匹のケースは禁止されている
ans%=p
print(ans)
| h,w,k = map(int, input().split())
s = [[int(c) for c in input()] for i in range(h)]
ans = 114514893
for bit in range(1 << (h-1)):
cut = [-1]
for i in range(h-1):
if bit & (1 << i) : cut.append(i)
cut.append(h-1)
l = len(cut)-1
count = l-1
suml = [0 for i in range(l)]
ok = True
for i in range(w):
sumtemp = [0 for ii in range(l)]
flag2 = True #kを超えないかどうか
for j in range(l):
for kk in range(cut[j]+1,cut[j+1]+1):
sumtemp[j] = sumtemp[j] + s[kk][i]
if sumtemp[j] > k:
ok = False
break
if not ok : break
for j in range(l):
if suml[j]+sumtemp[j] > k:flag2 = False
if flag2:
for j in range(l):
suml[j] = suml[j]+sumtemp[j]
else:
count += 1
suml = sumtemp[:]
if not ok:continue
ans = min(ans,count)
print(ans) | 0 | null | 34,833,921,303,872 | 146 | 193 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, M, K = mapint()
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
uf = UnionFind(N)
blocks = set()
friends = [0]*N
possi = [0]*N
for _ in range(M):
a, b = mapint()
uf.union(a-1, b-1)
friends[a-1] += 1
friends[b-1] += 1
for _ in range(K):
a, b = mapint()
if uf.same(a-1, b-1):
friends[a-1] += 1
friends[b-1] += 1
for i in range(N):
possi[i] = uf.size(i)-friends[i]-1
print(*possi) | class UnionFind():
def __init__(self, n):
self.n = n
#親の添字、親自身は木の要素数*-1をもつ
self.root = [-1]*(n)
#枝の最大長さ
self.rank = [0]*(n)
def find_root(self, x):
if(self.root[x] < 0):
return x
else:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
#高さによる合併
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.rank[x] > self.rank[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if(self.rank[x] == self.rank[y]):
self.rank[y] += 1
def same(self, x, y):
return self.find_root(x) == self.find_root(y)
def count(self, x):
return -self.root[self.find_root(x)]
def members(self, x):
root = self.find_root(x)
return [i for i in range(self.n) if self.find_root(i) == root]
def roots(self):
return [i for i, x in enumerate(self.root) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
N, M, K = map(int,input().rstrip().split())
AB=[list(map(int,input().rstrip().split()))for _ in range(M)]
CD=[list(map(int,input().rstrip().split()))for _ in range(K)]
u = UnionFind(N)
for a,b in AB:
u.unite(a-1,b-1)
ans=[u.count(i)-1 for i in range(N)] #木の要素数から自分を引く
ans
for a,b in AB:
if u.same(a-1,b-1):
ans[a-1]-=1
ans[b-1]-=1
for c,d in CD:
if u.same(c-1,d-1):
ans[c-1]-=1
ans[d-1]-=1
print(*ans) | 1 | 61,797,133,725,868 | null | 209 | 209 |
A, B = map(int, input().split())
N = 1000
p1 = 0.08
p2 = 0.1
for i in range(1, N + 1):
if int(i * p1) == A and int(i * p2) == B:
print(i)
exit()
print("-1") | import sys
def resolve(in_):
H, W, K = map(int, next(in_).split())
# n_choco = ord(b'0')
w_choco = ord(b'1')
S = [[1 if v == w_choco else 0 for v in line.strip()] for line in in_]
# print(f'{H=} {W=} {K=}')
# print(S)
ans = 10000 # > (Hmax - 1) * (Wmax - 1)
choco = [0] * H
choco_temp = [0] * H
for v in range(2 ** (H - 1)):
# print(f'{v:04b}')
ans_temp = sum(1 if v & (0b01 << i) else 0 for i in range(H - 1))
for w in range(W):
index = 0
for h in range(H):
choco_temp[index] += S[h][w]
if v & (0b01 << h):
index += 1
# print(f'b {choco=} {choco_temp=} {ans_temp=}')
if all(a + b <= K for a, b in zip(choco, choco_temp[:index + 1])):
# for i in range(len(choco)):
for i in range(index + 1):
choco[i] += choco_temp[i]
choco_temp[i] = 0
elif max(choco_temp) > K:
ans_temp = 10000
break
else:
# for i in range(len(choco)):
for i in range(index + 1):
choco[i] = choco_temp[i]
choco_temp[i] = 0
ans_temp += 1
if ans_temp >= ans:
break
# print(f'a {choco=} {choco_temp=} {ans_temp=}')
# print(f'{v:09b} {choco=} {ans_temp=}')
ans = min(ans, ans_temp)
for i in range(len(choco)):
choco[i] = 0
choco_temp[i] = 0
return ans
def main():
ans = resolve(sys.stdin.buffer)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 52,611,804,733,472 | 203 | 193 |
N,M=map(int,input().split())
class UnionFind():
def __init__(self,n): #n:要素数
self.n=n
self.parents = [-1]*n
#parents:各要素の親要素番号を格納
#要素が根である場合、-(そのグループの要素数)を格納する
def find(self,x): #xが属する根を返す
if self.parents[x] < 0:
return x
else:
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def union(self,x,y): #xのグループとyのグループを併合する
x = self.find(x)
y = self.find(y)
if x==y:
return
if self.parents[x] > self.parents[y]: #|xのグループ|<|yのグループ|
x,y=y,x
self.parents[x] += self.parents[y]
self.parents[y] = x
#よりグループ数が多い方の根にもう一方のグループを接続
def size(self,x): #xの属するグループのサイズ
return -self.parents[self.find(x)]
uf=UnionFind(N)
for i in range(M):
a,b=map(lambda x:int(x)-1,input().split())
uf.union(a,b)
ans=0
for i in range(N):
if uf.size(i) > ans:
ans=uf.size(i)
print(ans) | class UnionFind():
def __init__(self, N):
# parent of each node
self.parent = [n for n in range(N)]
# number of nodes in union
self.rank = [1] * N
def find(self, u):
if self.parent[u] == u:
return u
else:
# recursive call
return self.find(self.parent[u])
def union(self, u, v):
pu = self.find(u)
pv = self.find(v)
# same union
if pu == pv:
return
# let pv join into pu union
if self.rank[pu] < self.rank[pv]:
pu, pv = pv, pu
self.rank[pu] += self.rank[pv]
self.parent[pv] = pu
N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
A, B = map(int, input().split())
A, B = A-1, B-1
UF.union(A, B)
ret = 0
for n in range(N):
ret = max(ret, UF.rank[n])
print(ret)
| 1 | 3,953,574,894,400 | null | 84 | 84 |
N = list(map(int, "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(", ")))
n = int(input())
print(N[n-1]) | n = '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'
nn = n.split(', ')
nn = list(map(int, nn))
K = int(input())
print(nn[K-1]) | 1 | 50,063,241,237,820 | null | 195 | 195 |
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
def main():
n = I()
ranges = []
for i in range(n):
x, l = LI()
ranges.append([x - l, x + l])
ranges.sort(key=lambda x: x[1])
ans = n
for i in range(1, n):
if ranges[i - 1][1] > ranges[i][0]:
ans -= 1
ranges[i][1] = ranges[i - 1][1]
print(ans)
if __name__ == "__main__":
main()
| N = int(input())
R = []
for i in range(N):
x, l = map(int, input().split())
R.append((x+l, x-l))
R.sort()
ans = 0
now = -(10 ** 9 + 1)
for (r, l) in R:
if now <= l:
ans += 1
now = r
print(ans)
| 1 | 89,848,898,076,740 | null | 237 | 237 |
import random
S = input()
x = random.randrange(len(S)-2)
print(S[x] + S[x + 1] + S[x + 2]) | import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
N = I()
a = IL()
b = []
for i in range(N):
b.append((a[i], i))
b.sort(reverse=True)
dp = [[0]*(N+1) for i in range(N+1)] # dp[i番目まで][左からj番目]
for i in range(N):
happy, ID = b[i]
#print(b[i])
for l in range(i+1):
lcnt = l
rcnt = i - lcnt
r = N-1 - rcnt
if i > l-1:
dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + happy*abs(ID - l))
dp[i+1][l] = max(dp[i+1][l], dp[i][l] + happy*abs(ID - r))
else:
break
#print(l,r)
#print(dp)
#print("---")
print(max(dp[-1])) | 0 | null | 24,163,153,271,418 | 130 | 171 |
import math
A,B,H,M=map(int,input().split())
b=30*H+30*(M/60)
c=6*M
d=math.fabs(b-c)
d=math.radians(d)
f=0
f=A**2+B**2-2*A*B*(math.cos(d))
print(math.fabs(math.sqrt(f)))
| N=int(input())
for i in range(N+1):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N+1))==True:
print(":(") | 0 | null | 72,814,260,114,398 | 144 | 265 |
import numpy as np
N,K = map(int,input().split())
import math
A = list(map(int,input().split()))
flag = 0
if 0 in A:
flag = 1
A.sort()
plus = list(filter(lambda x:x>0, A))[::-1]
plus = list(map(lambda x:np.longdouble(math.log(x,10000000)),plus))
from itertools import accumulate
acc_plu = [0] + list(accumulate(plus))
minu = filter(lambda x:x<0, A)
minu = list(map(lambda x:np.longdouble(math.log(-x,10000000)),minu))
acc_min = [0] + list(accumulate(minu))
if K % 2 == 0 : num = K // 2 + 1
else: num = (K + 1) // 2
cand = []
x = K
y = 0
MOD = 10**9 +7
for i in range(num):
try:
cand.append((acc_plu[x] + acc_min[y],x ,y ))
except: pass
x -= 2
y += 2
ans = 1
if cand == []:
if flag:
print(0)
exit()
cnt = 0
#マイナス確定
abss = sorted(list(map(lambda x :abs(x),A)))
for x in abss:
if cnt == K:break
ans *= x
ans %= MOD
cnt += 1
ans *= -1
ans %= MOD
print(ans)
else:
cand = sorted(cand)[::-1]
plus = list(filter(lambda x:x>0, A))[::-1]
minu = list(filter(lambda x:x<0, A))
c = cand[0]
ans = 1
for i in range(c[1]):
ans *= plus[i]
ans %= MOD
for i in range(c[2]):
ans *= minu[i]
ans %= MOD
print(ans)
| #!/usr/bin/python3
import sys
from functools import reduce
from operator import mul
input = lambda: sys.stdin.readline().strip()
n, k = [int(x) for x in input().split()]
a = sorted((int(x) for x in input().split()), key=abs)
sgn = [0 if x == 0 else x // abs(x) for x in a]
M = 10**9 + 7
def modmul(x, y):
return x * y % M
if reduce(mul, sgn[-k:]) >= 0:
print(reduce(modmul, a[-k:], 1))
else:
largest_unselected_neg = next(i for i, x in enumerate(reversed(a[:-k])) if x < 0) if any(x < 0 for x in a[:-k]) else None
largest_unselected_pos = next(i for i, x in enumerate(reversed(a[:-k])) if x > 0) if any(x > 0 for x in a[:-k]) else None
smallest_selected_neg = next(i for i, x in enumerate(a[-k:]) if x < 0) if any(x < 0 for x in a[-k:]) else None
smallest_selected_pos = next(i for i, x in enumerate(a[-k:]) if x > 0) if any(x > 0 for x in a[-k:]) else None
can1 = largest_unselected_neg is not None and smallest_selected_pos is not None
can2 = largest_unselected_pos is not None and smallest_selected_neg is not None
def ans1():
return list(reversed(a[:-k]))[largest_unselected_neg] * reduce(modmul, (x for i, x in enumerate(a[-k:]) if i != smallest_selected_pos), 1) % M
def ans2():
return list(reversed(a[:-k]))[largest_unselected_pos] * reduce(modmul, (x for i, x in enumerate(a[-k:]) if i != smallest_selected_neg), 1) % M
if can1 and not can2:
print(ans1())
elif can2 and not can1:
print(ans2())
elif can1 and can2:
if list(reversed(a[:-k]))[largest_unselected_neg] * a[-k:][smallest_selected_neg] > list(reversed(a[:-k]))[largest_unselected_pos] * a[-k:][smallest_selected_pos]:
print(ans1())
else:
print(ans2())
else:
print(reduce(modmul, a[:k], 1)) | 1 | 9,381,225,850,792 | null | 112 | 112 |
import collections
K = int(input())
l = collections.deque([1,2,3,4,5,6,7,8,9])
cnt = 0
while True:
n = l.popleft()
cnt +=1
if cnt ==K:
print(n)
exit()
if n%10 != 0:
l.append(10*n+n%10-1)
l.append(10*n+n%10)
if n%10 != 9:
l.append(10*n+n%10+1)
| from collections import deque
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k):
a = q.popleft()
b = a % 10
if b == 0:
q.append(a * 10)
q.append(a * 10 + b + 1)
elif b == 9:
q.append(a * 10 + b - 1)
q.append(a * 10 + b)
else:
q.append(a * 10 + b - 1)
q.append(a * 10 + b)
q.append(a * 10 + b + 1)
print(a) | 1 | 40,083,522,783,358 | null | 181 | 181 |
while True:
a, b = map(int, input().split())
if a == b == 0:
break
for i in range(a):
if i == 0 or i == a - 1:
print('#' * b)
continue
print('#', '.' * (b - 2), '#', sep = '')
print()
| import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
X = int(rl())
print(10 - X // 200)
if __name__ == '__main__':
solve()
| 0 | null | 3,789,089,231,418 | 50 | 100 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [0 for _ in range(N)]
first_visit = [0 for _ in range(N)]
now = 0
flag = True
for i in range(10 ** 5 * 5):
if first_visit[now] == 0:
first_visit[now] = i
visited[A[now] - 1] += 1
now = A[now] - 1
if i == K - 1:
print(now + 1)
flag = False
break
if flag:
num = 0
for i in range(N):
if visited[i] > 2:
num += 1
for i in range(N):
if visited[i] >= 2:
if K % num == first_visit[i] % num:
print(i + 1)
break
| import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
N,A = int(input()),lint()
S = dict()
for a in A:
S.setdefault(a,0)
S[a] += 1
ans = 0
for k in S:
ans += S[k]*(S[k]-1)//2
for a in A:
print(ans-(S[a]-1)) | 0 | null | 35,055,458,921,280 | 150 | 192 |
import sys
K=int(input())
if K%2==0 or K%5==0:
print('-1')
sys.exit()
i=1
K=9*K
ans=10-K
while(1):
if 7*(ans-1)%K==0:
print(i)
sys.exit()
i+=1
ans=ans*10%K | k = int(input())
if k % 2 == 0 or k % 5 == 0:
print(-1)
else:
ans = 7
cnt = 1
while 1:
if ans % k == 0:
break
else:
cnt += 1
ans *= 10
ans += 7
ans %= k
print(cnt)
| 1 | 6,148,491,487,372 | null | 97 | 97 |
x = int(input())
for i in range(2,10):
if i <= x/200 < i+1:
print(10-i) | S,W = map(int, input().split())
print("suanfsea f e"[S<=W::2]) | 0 | null | 17,824,211,298,332 | 100 | 163 |
N = int(input())
l = list(map(int, input().split()))
counter = 1
ans = 0
for j in l:
if j == counter:
counter += 1
else:
ans += 1
if counter==1:
print(-1)
else:
print(ans) | N = int(input())
A = list(map(int, input().split()))
ans = 0
now = 1
for i in range(N):
if A[i] == now:
now += 1
continue
else:
ans += 1
if now == 1 and ans == N:
print(-1)
else:
print(ans)
| 1 | 114,182,192,165,822 | null | 257 | 257 |
xyz = list(map(int,input().split()))
xyz[0] ,xyz[1] = xyz[1],xyz[0]
xyz[0], xyz[2] = xyz[2], xyz[0]
print(*xyz) | a, b, c = map(int, input().split())
t = a
a = b
b = t
tt = a
a =c
c = tt
print(a, b, c) | 1 | 38,074,747,270,182 | null | 178 | 178 |
[n,m,l] = map(int, input().split())
a = []
b = []
c = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
a.append(list(map(int, input().split())))
for j in range(m):
b.append(list(map(int, input().split())))
for i in range(n):
for k in range(l):
s = 0
for j in range(m):
s += a[i][j] * b[j][k]
c[i][k] = s
for i in range(n):
for k in range(l):
print(c[i][k],end='')
if k!= l-1:
print(' ',end='')
else:
print() | n, m, L = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[sum(ak * bk for ak, bk in zip(ai,bj)) for bj in zip(*b)] for ai in a]
for ci in c:
print(*ci) | 1 | 1,431,127,364,992 | null | 60 | 60 |
def check(T, K, A, F):
# check whether all members finish by the time T
counts = [max(0, (a * f - T + f - 1) // f) for a, f in zip(A, F)] # math.ceil((a * f - T) / f)
return sum(counts) <= K
def main():
N, K = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
A.sort()
F = list(map(int, input().split(' ')))
F.sort(reverse=True)
ok = 10 ** 12
ng = - 1
while ok - ng > 1:
mid = (ok + ng) // 2
if check(mid, K, A, F):
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| n = int(input())
print((n-1)//2)
| 0 | null | 159,013,122,987,740 | 290 | 283 |
H=int(input())
W=int(input())
N=int(input())
if N%max(H,W)==0:
print(N//max(H,W))
else:
print(N//max(H,W)+1) | a=int(input())
b=int(input())
c=int(input())
if a<b:
a,b=b,a
if c%a==0:
print(c//a)
else:
print(c//a+1)
| 1 | 89,119,065,622,440 | null | 236 | 236 |
n , k , c = map(int,input().split())
s = input()
L = []
R = []
i = 0
j = n-1
while i<n and len(L)<k :
if s[i] == "o" :
L.append(i)
i += c
i += 1
while j>-1 and len(R)<k :
if s[j] == "o" :
R.append(j)
j -= c
j -= 1
R.reverse()
for x in range(k):
if R[x] == L[x]:
print(R[x]+1) | nkc=input().split()
K=int(nkc[1])
C=int(nkc[2])
s=input()
workday_list=[]
for i,youso in enumerate(s) :
if youso=='o' :
workday_list.append(i+1)
s=1
current_num=0
current_num1=1
list1=[]
list1.append(workday_list[0])
while(s<K) :
if current_num1>=len(workday_list):
break
elif workday_list[current_num1]-workday_list[current_num]>C :
current_num=current_num1
list1.append(workday_list[current_num1])
s+=1
else :
current_num1=current_num1+1
m=1
current_num2=len(workday_list)-1
current_num3=len(workday_list)-2
list2=[]
list2.append(workday_list[-1])
while(m<K) :
if current_num3<0:
break
elif workday_list[current_num2]-workday_list[current_num3]>C :
current_num2=current_num3
list2.append(workday_list[current_num3])
m+=1
else :
current_num3=current_num3-1
list2.reverse()
flag=True
for i in range(len(list1)) :
if list1[i]==list2[i] :
flag=False
print(list1[i])
if flag :
print()
| 1 | 40,744,287,653,680 | null | 182 | 182 |
n = int(input())
lst = []
for i in range(n):
x, l = map(int, input().split())
left = x - l
right = x + l
lst.append([left, right])
lst = sorted(lst, key=lambda x: x[1])
ans = 1
limit = lst[0][1]
for i in range(n):
if lst[i][0] >= limit:
ans += 1
limit = lst[i][1]
print(ans) | L, R, D = map(int, input().split())
print(R//D-(L-1)//D) | 0 | null | 48,769,234,383,510 | 237 | 104 |
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)) | 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,322,308,480 | null | 12 | 12 |
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
visited = [0] * (N + 1)
route = [0] * (N + 1)
next_ = 1
count = 0
for i in range(K + 1):
if visited[next_] != 0:
x = visited[next_]
count = (K - (x - 1)) % (i + 1 - x) + x
print(route[count])
exit()
visited[next_] = i + 1
route[i + 1] = next_
next_ = A[next_]
print(route[K + 1])
| import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a - 1 for a in A]
log_K = 1
while 1 << log_K < K:
log_K += 1
# print(f'{log_K=}')
D = [[0] * N for _ in range(log_K)]
for i in range(N):
D[0][i] = A[i]
for k in range(log_K - 1):
for i in range(N):
D[k + 1][i] = D[k][D[k][i]]
# print(f'{D=}')
now = 0
k = 0
while K > 0:
if K & 1:
now = D[k][now]
K = K >> 1
k += 1
print(now + 1)
| 1 | 22,623,708,442,592 | null | 150 | 150 |
import math
A = []
N = int(input())
count = 0
for n in range(N):
x = int(input())
if x == 2:
A.append(x)
count += 1
elif x % 2 == 0:
pass
elif x > 2:
for i in range(3, int(math.sqrt(x))+2, 2):
if x % i == 0:
break
else:
count += 1
A.append(x)
print(count) | import sys
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
P = str(input()).upper()
line = []
while True:
tmp_line = str(input())
if tmp_line == 'END_OF_TEXT':
break
line += tmp_line.upper().split()
ans = 0
for tmp_word in line:
if tmp_word == P:
ans += 1
print("%d"%(ans))
| 0 | null | 929,081,153,690 | 12 | 65 |
k = int(input())
a, b = map(int, input().split())
cal = 0
while cal <= b:
if a <= cal <= b:
print('OK')
break
else:
cal += k
if cal > b:
print('NG') | def main():
N, K, C = map(int, input().split())
S = input()
i = 0
c = 0
p = [-1] * N
while c < K:
if S[i] == 'o':
p[i] = c
c += 1
i += C
i += 1
i = N - 1
c = K - 1
q = [-1] * N
while c >= 0:
if S[i] == 'o':
q[i] = c
c -= 1
i -= C
i -= 1
for i in range(N):
if ~p[i] and p[i] == q[i]:
print(i + 1)
if __name__ == '__main__':
main()
| 0 | null | 33,607,635,541,028 | 158 | 182 |
s_max = -float('inf')
s = 0
for i in range(int(input())):
r = int(input())
if i:
s = max(s, 0) + r - prev
s_max = max(s, s_max)
prev = r
print(s_max)
| a, b, c, d = map(int, input().split())
print(max(a * c, a * d, b * c, b * d))
| 0 | null | 1,529,221,158,940 | 13 | 77 |
def main():
N = input()
acc = 0
for idx in range(len(N)):
acc += (ord(N[idx]) - ord('0'))
print('Yes') if not acc % 9 else print('No')
if __name__ == '__main__':
main()
| n = list(map(int, list(input())))
n_sum = sum(n)
print("Yes" if n_sum % 9 == 0 else "No") | 1 | 4,373,754,013,640 | null | 87 | 87 |
import collections
N = int(input())
A = list(map(int, input().split()))
# ap+aq == p-q (p>q)
# p-ap = q+aq
mp = {}
ans = 0
for p in range(N):
if p-A[p]+1 in mp:
ans += mp[p-A[p]+1]
if p+A[p]+1 in mp:
mp[p+A[p]+1] += 1
else:
mp[p + A[p] + 1] = 1
print(ans)
| # -*- config: utf-8 -*-
if __name__ == '__main__':
while 1:
try:
nums = map(int,raw_input().split())
s = sum(nums)
print len(str(s))
except:
break | 0 | null | 13,109,245,413,478 | 157 | 3 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
h, w, k = list(map(int, readline().split()))
s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
cnt = 0
ls = []
lsd = -1
for i in range(h):
if s[i].count("#") != 0:
lsd = i
is_f = True
cnt += 1
for j in range(w):
if s[i][j] == "#":
if is_f:
is_f = False
else:
cnt += 1
s[i][j] = cnt
while ls:
ti = ls.pop()
for j in range(w):
s[ti][j] = s[i][j]
else:
ls.append(i)
if i == h - 1:
while ls:
ti = ls.pop()
for j in range(w):
s[ti][j] = s[lsd][j]
for i in range(len(s)):
print(*s[i])
if __name__ == '__main__':
solve()
| import numpy as np
H, W, K = map(int, input().split())
s = np.zeros((H, W), dtype=int)
num = 1
for i in range(H):
_s = input()
for j in range(W):
if _s[j] == '#':
s[i,j] = num
num += 1
else:
s[i,j] = 0
flg = False
for i in range(H):
if all(s[i,:] == 0):
if flg:
s[i,:] = s[i-1,:]
else:
flg = True
prej = 0
for j in range(W):
if s[i, j] != 0:
num = s[i, j]
s[i, prej:j] = num
prej = j+1
else:
s[i, prej:] = num
for i in range(H-1, -1, -1):
if all(s[i,:] == 0):
s[i,:] = s[i+1,:]
for i in range(H):
ans = ''
for j in range(W):
ans += str(s[i, j]) + ' '
print(ans)
| 1 | 143,770,227,326,818 | null | 277 | 277 |
n, m = map(int, input().split())
a = 1
b = m + 1
while a < b:
print(a, b)
a += 1
b -= 1
a = m + 2
b = 2 * m + 1
while a < b:
print(a, b)
a += 1
b -= 1 | n,m=map(int,input().split())
left=m//2
right=(m+1)//2
for i in range(left):
print(i+1,2*left+1-i)
for i in range(right):
print(2*left+1+i+1,2*left+1+2*right-i)
| 1 | 28,473,435,254,950 | null | 162 | 162 |
# coding: utf-8
# Your code here!
import math
num = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
result = 0
for i in range(num):
result += abs(y[i]-x[i])
print(result)
result = 0
for i in range(num):
result += abs(y[i] - x[i]) ** 2
result = math.sqrt(result)
print(result)
result = 0
for i in range(num):
result += abs(y[i] - x[i]) ** 3
result = math.pow(result,1.0/3.0)
print(result)
result = 0
for i in range(num):
if i == 0:
result = abs(y[i] - x[i])
else:
if abs(y[i] - x[i]) > result:
result = abs(y[i] - x[i])
print(result)
| n = int(input())
data = list(zip([int(n) for n in input().split()], [int(n) for n in input().split()]))
dist = []
for pair in data:
dist.append(abs(pair[0] - pair[1]))
print(sum(dist))
print(pow(sum(n ** 2 for n in dist), 1 / 2))
print(pow(sum(n ** 3 for n in dist), 1 / 3))
print(max(dist)) | 1 | 206,804,001,978 | null | 32 | 32 |
from itertools import product
datas=[]
num=0
N=int(input())
for i in range(N):
a=int(input())
for j in range(a):
x,y=map(int,input().split())
datas.append((num,x-1,y))
num+=1
#print(datas)
ans=0
for i in product([0,1],repeat=N):
ok=True
cnt=0
for j in datas:
if (i[j[0]]==1 and i[j[1]]!=j[-1]):
ok=False
break
if ok:
cnt=sum(i)
ans=max(ans,cnt)
print(ans) | #基本1つ飛ばしだが、パスも使える。
#奇数ならパス2回、偶数ならパス1回。
N = int(input())
A = [int(hoge) for hoge in input().split()]
DP = [[0]*3 for n in range(N)] #DP[n][y] = n桁目までみて、パスをy回使ったときの最大値
DP[0][0] = A[0]
for n in range(1,N):#n桁目までみる。
#「選ぶ」か「パスを使う」かの2択。
DP[n][0] = DP[n-2][0] + A[n]
DP[n][1] = max((DP[n-2][1]+A[n],DP[n-1][0]))
DP[n][2] = max((DP[n-2][2]+A[n],DP[n-1][1]))
if N%2:
print(DP[n][2])
else:
print(DP[n][1]) | 0 | null | 79,449,299,132,332 | 262 | 177 |
N, K = map(int, input().split())
nums = list(map(int, input().split()))
expect = 0
answer = 0
for i in range(N):
if i < K:
expect += (nums[i]+1)/2
else:
expect += (nums[i]+1)/2 - (nums[i-K]+1)/2
answer = max(answer, expect)
print(answer) | n, k = map(int, input().split())
p = list(map(int, input().split()))
q = [0]
m = 0
for i in p:
m += (1+i)/2
q.append(m)
ans = 0
for i in range(k, n+1):
ans = max(q[i]-q[i-k], ans)
#あまり深く事を考えずに
print(ans) | 1 | 74,841,209,288,512 | null | 223 | 223 |
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def f(a):
b = [0]*(n+1)
for i in range(n):
l = max(0,i-a[i])
r = min(n,i+a[i]+1)
b[l] += 1
b[r] -= 1
for i in range(n):
b[i+1] += b[i]
return b[:n]
n,k = LI()
a = LI()
while k:
if sum(a) == n**2:
break
a = f(a)
k -= 1
print(*a)
return
#Solve
if __name__ == "__main__":
solve()
| N = int(input())
for i in range(1,10):
if N % i == 0 and N // i < 10:
print("Yes")
break
else:
print("No") | 0 | null | 87,508,697,649,632 | 132 | 287 |
a = raw_input()
while a!='0':
s = 0
for i in range(len(a)):
s += int(a[i])
print s
a = raw_input() | import sys
def main():
for x in sys.stdin:
if x == "0\n":
break
else:
X = list(x)
total = 0
for i in range(len(X) - 1):
total += int(X[i])
print(total)
if __name__ == "__main__":
main() | 1 | 1,580,356,811,570 | null | 62 | 62 |
import math
def order(N,P):
value=0
N_ls=list(range(1,N+1))
score=0
for i in P:
score+=N_ls.index(i)*math.factorial(len(N_ls)-1)
N_ls.remove(i)
return score
N=int(input())
P=[int(x) for x in input().split()]
Q=[int(x) for x in input().split()]
print(abs(order(N,P)-order(N,Q))) | from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
p = sorted(list(permutations(P)))
q = sorted(list(permutations(Q)))
print(abs(p.index(P) - q.index(Q)))
| 1 | 100,197,167,027,438 | null | 246 | 246 |
n, s = open(0).read().split()
s = list(map(int, list(s)))
from itertools import product,repeat
ans = 0
for a,b,c in product(range(10), range(10), range(10)):
abc = [a,b,c]
tmp = 0
for dig in s:
if dig == abc[tmp]:
tmp += 1
if tmp == 3:
ans += 1
break
print(ans) | N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
if 0 <= i and i <= 9:
num = "00"+str(i)
elif 10 <= i and i <= 99:
num = "0"+str(i)
else:
num = str(i)
num_pos = 0
s_pos = 0
while True:
if S[s_pos] == num[num_pos]:
num_pos += 1
if num_pos == 3:
ans += 1
break
s_pos += 1
if s_pos == N:
break
print(ans)
| 1 | 128,967,546,713,698 | null | 267 | 267 |
import sys
X, Y, Z = map(int, sys.stdin.readline().split())
print(Z, X, Y) | x = [int(x) for x in input().split()]
print(x[2],x[0],x[1])
| 1 | 37,963,958,703,712 | null | 178 | 178 |
dice = list(map(int, input().split()))
command = str(input())
for c in command:
if (c == 'S'): ##2651 --> 1265
dice[1],dice[5],dice[4],dice[0] = dice[0],dice[1],dice[5],dice[4]
elif(c == 'N'):
dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
elif (c == 'W'): ##4631 -- > 1463
dice[3], dice[5], dice[2],dice[0] = dice[0], dice[3], dice[5], dice[2]
else:
dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2],dice[0]
print(dice[0])
| def main():
import sys
import math
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
ans = 0
node = 1
max_node = sum(A)
for i in range(n+1):
ans += node
max_node -= A[i]
node = min(max_node,(node-A[i])*2)
if node < 0:
print(-1)
exit(0)
print(ans)
if __name__ == '__main__':
main() | 0 | null | 9,456,578,077,948 | 33 | 141 |
sum = []
while True:
text = input()
if text == '0':
break
tmp = 0
for i in range(len(text)):
tmp += int(text[i])
sum.append(tmp)
for r in sum:
print(r) | N = int(input())
ans = ''
while True:
n = int(N / 26)
r = N % 26
if r == 0:
r = 26
n -= 1
ans = chr(96 + r) + ans
if n == 0:
break
else:
N = n
print(ans) | 0 | null | 6,663,124,447,012 | 62 | 121 |
a,b = input().split()
aa,bb = int(a),int(b)
print(a * bb if a * bb < b * aa else b * aa) |
# ABC152
a, b = map(int, input().split())
print(min(str(a)*b, str(b)*a))
| 1 | 84,277,496,923,884 | null | 232 | 232 |
class Dice:
def __init__(self, d1, d2, d3, d4, d5, d6):
self.d1 = d1
self.d2 = d2
self.d3 = d3
self.d4 = d4
self.d5 = d5
self.d6 = d6
def S(self):
tmp = self.d1
self.d1 = self.d5
self.d5 = self.d6
self.d6 = self.d2
self.d2 = tmp
def N(self):
tmp = self.d1
self.d1 = self.d2
self.d2 = self.d6
self.d6 = self.d5
self.d5 = tmp
def E(self):
tmp = self.d1
self.d1 = self.d4
self.d4 = self.d6
self.d6 = self.d3
self.d3 = tmp
def W(self):
tmp = self.d1
self.d1 = self.d3
self.d3 = self.d6
self.d6 = self.d4
self.d4 = tmp
def output(self):
print(self.d1)
d1, d2, d3, d4, d5, d6 = map(int, input().split())
dice = Dice(d1, d2, d3, d4, d5, d6)
M = input()
for i in range(len(M)):
if M[i] == 'S':
dice.S()
elif M[i] == 'N':
dice.N()
elif M[i] == 'E':
dice.E()
elif M[i] == 'W':
dice.W()
dice.output()
| class Dice:
def __init__(self,l1,l2,l3,l4,l5,l6):
self.l1 = l1
self.l2 = l2
self.l3 = l3
self.l4 = l4
self.l5 = l5
self.l6 = l6
self.top = 1
self.front = 2
self.right = 3
def get_top(self):
return eval("self." + 'l' + str(self.top))
def move(self, order):
if order == 'S':
pretop = self.top
self.top = 7 - self.front
self.front = pretop
elif order == 'E':
pretop = self.top
self.top = 7 - self.right
self.right = pretop
elif order == 'N':
pretop = self.top
self.top = self.front
self.front = 7 - pretop
elif order == 'W':
pretop = self.top
self.top = self.right
self.right = 7 - pretop
l = list(map(int,input().split()))
orders = input()
d = Dice(l[0],l[1],l[2],l[3],l[4],l[5])
for order in orders:
d.move(order)
print(d.get_top()) | 1 | 237,685,144,270 | null | 33 | 33 |
def main():
N, K = map(int, input().split())
R, S, P = map(int, input().split())
d = {'r': R, 's': S, 'p': P}
T = input()
scores = []
for t in T:
if t == 'r':
scores.append('p')
elif t == 's':
scores.append('r')
else:
scores.append('s')
for i in range(N-K):
if scores[i] == scores[i+K]:
scores[i+K] = 0
print(sum([d[v] for v in scores if v in ['p', 'r', 's']]))
if __name__ == '__main__':
main()
| N = input()
K = int(input())
def solve(N, K):
l = len(N)
dp = [[[0] * (10) for i in range(2)] for _ in range(l+1)]
dp[0][0][0] = 1
for i in range(l):
D = int(N[i])
for j in range(2):
for k in range(K+1):
for d in range(10):
if j == 0 and d > D: break
dp[i+1][j or (d < D)][k if d == 0 else k+1] += dp[i][j][k]
return dp[l][0][K] + dp[l][1][K]
print(solve(N,K))
| 0 | null | 91,238,616,219,552 | 251 | 224 |
S=input()
h=len(S)//2
l=S[0:h]
r=S[h:]
Rr=r[::-1]
ans=0
for i in range(h):
if l[i]==Rr[i]:
pass
else:
ans+=1
print(ans) | def main():
N = int(input())
comb_count = [[0 for i in range(10)] for j in range(10)]
res = 0
for i in range(1, N + 1):
s = str(i)
max, min = int(s[0]), int(s[-1])
comb_count[max][min] += 1
for l in range(1, 10):
for r in range(1, 10):
res += comb_count[l][r] * comb_count[r][l]
print(res)
if __name__ == '__main__':
main() | 0 | null | 103,545,283,137,098 | 261 | 234 |
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]
res = 0
for num in T:
if num in S:
res += 1
print(res) | n = int(input())
li1 = list(map(int,input().split()))
m = int(input())
li2 = list(map(int,input().split()))
cnt = 0
for i in li2:
if i in li1:
cnt +=1
print(cnt) | 1 | 68,646,454,382 | null | 22 | 22 |
n = int(input())
q = list(map(int,input().split()))
ans = 0
count = 0
for i in q:
if i%2 == 0:
alm = i
count += 1
if alm%3 == 0 or alm%5 == 0:
ans += 1
if ans == count:
print("APPROVED")
else:
print("DENIED") | N = int(input())
data = list(map(int,input().split()))
sw1 = 0
sw2 = 0
for i in range(0,len(data)):
if data[i] % 2 == 0:
sw1 += 1
if data[i] % 3 == 0 or data[i] % 5 == 0:
sw2 += 1
if sw1 >= 0 and sw1 == sw2:
print("APPROVED")
else:
print("DENIED") | 1 | 68,983,157,028,840 | null | 217 | 217 |
n, d, a = map(int, input().split())
xh = []
for _ in range(n):
x, h = map(int, input().split())
h = (h - 1) // a + 1
xh.append([x, h])
xh.sort()
damage = xh[0][1]
ans = damage
damage_lst = [[xh[0][0] + d * 2, damage]]
pos = 0
for i, (x, h) in enumerate(xh[1:], start = 1):
while x > damage_lst[pos][0]:
damage -= damage_lst[pos][1]
pos += 1
if pos == i:
break
damage_tmp = max(h - damage, 0)
ans += damage_tmp
damage += damage_tmp
damage_lst.append([x + d * 2, damage_tmp])
print(ans) | import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, d, a = map(int, input().split())
XH = sorted([list(map(int, input().split())) for _ in range(n)])
res = 0
tt_dmg = 0
que = deque()
for x, h in XH:
while que and que[0][1] < x:
dmg, rng = que.popleft()
tt_dmg -= dmg
if tt_dmg < h:
h -= tt_dmg
cnt = (h + a - 1) // a
res += cnt
dmg = cnt * a
tt_dmg += dmg
que.append((dmg, x + d * 2))
print(res)
if __name__ == '__main__':
resolve()
| 1 | 82,138,410,389,970 | null | 230 | 230 |
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
inf = 10 ** 16
if N % 2:
dp = [[-inf] * 3 for _ in range(N + 2)]
dp[0][0] = 0
dp[1][1] = 0
dp[2][2] = 0
if N > 4: dp[4][2] = a[0]
for i in range(N):
for j in range(3):
if dp[i][j] == -inf: continue
if i + 2 <= N + 1: dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i])
if i + 3 <= N + 1 and (j < 2): dp[i + 3][j + 1] = max(dp[i + 3][j + 1], dp[i][j] + a[i])
if i + 4 <= N + 1 and (j == 0): dp[i + 4][j + 1] = max(dp[i + 4][j + 1], dp[i][j] + a[i])
print(max(dp[-1][-1], dp[-2][-2], dp[-3][-3]))
#print(dp)
else:
dp = [[-inf] * 2 for _ in range(N + 2)]
dp[0][0] = 0
dp[1][1] = 0
for i in range(N):
for j in range(2):
if dp[i][j] == -inf: continue
if i + 2 <= N + 1: dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i])
if i + 3 <= N + 1 and (j < 1): dp[i + 3][j + 1] = max(dp[i + 3][j + 1], dp[i][j] + a[i])
print(max(dp[-1][-1], dp[-2][-2]))
#print(dp) | elements = [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]
K = int(input())
th = K-1
print(elements[th]) | 0 | null | 43,562,884,921,820 | 177 | 195 |
def bubble_sort(A):
flag = 1
count = 0
while flag:
flag = 0
for i in range(len(A) - 1, 0, -1):
if A[i - 1] > A[i]:
A[i - 1], A[i] = A[i], A[i - 1]
flag = 1
count += 1
return count
def show(A):
for i in range(len(A) - 1):
print(A[i], end=" ")
print(A[len(A) - 1])
n = int(input())
line = input()
A = list(map(int, line.split()))
count = bubble_sort(A)
show(A)
print(count) | def bubbleSort(A, N):
flag = 1
count = 0
while flag:
flag = 0
for j in xrange(N-1,0,-1):
if A[j] < A[j-1]:
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag += 1
count += 1
return A, count
def main():
N = int(raw_input())
A = map(int, raw_input().split())
new_A, count = bubbleSort(A, N)
print ' '.join(map(str,new_A))
print count
if __name__ == "__main__":
main() | 1 | 17,977,383,270 | null | 14 | 14 |
DP = [False]*100001
DP[0] = True
for TN in range(0,100001):
if TN>=100 and DP[TN-100]:
DP[TN] = True
continue
if TN>=101 and DP[TN-101]:
DP[TN] = True
continue
if TN>=102 and DP[TN-102]:
DP[TN] = True
continue
if TN>=103 and DP[TN-103]:
DP[TN] = True
continue
if TN>=104 and DP[TN-104]:
DP[TN] = True
continue
if TN>=105 and DP[TN-105]:
DP[TN] = True
continue
print([0,1][DP[int(input())]]) | h1,m1,h2,m2,k = map(int,input().split())
a = 60*h2 + m2
b = 60*h1 + m1
print(a-b-k) | 0 | null | 72,501,275,765,376 | 266 | 139 |
N=int(input())
s,t=[],[]
for i in range(N):
S,T=input().split()
s.append(S)
t.append(int(T))
X=input()
xs=s.index(X)
print(sum(t[xs:])-t[xs]) | n = int(input())
S = []
T = []
for _ in range(n):
s, t = input().split()
S.append(s)
T.append(int(t))
x = input()
index = S.index(x)
if index == n - 1:
print(0)
else:
print(sum(T[index+1:]))
| 1 | 96,891,966,284,742 | null | 243 | 243 |
n, k = (int(i) for i in input().split())
m = n % k
ans = min(m, k - m)
print(ans) | # C Replacing Integer
N, K = map(int, input().split())
while N >= K:
N = N % K
frag = 0
while frag == 0:
cand = abs(N - K)
if cand < N:
N = cand
else:
frag = 1
print(N) | 1 | 39,490,858,837,218 | null | 180 | 180 |
x, k, d = map(int, input().split())
x = abs(x)
num = x // d
if num >= k:
ans = x - k*d
else:
if (k-num)%2 == 0:
ans = x - num*d
else:
ans = min(abs(x - num*d - d), abs(x - num*d + d))
print(ans) | S = input()
T = input()
Nmax = len(T)
for i in range(len(S)-len(T)+1):
diff = 0
for j in range(len(T)):
if(S[i+j] != T[j]):
diff += 1
Nmax = min(diff, Nmax)
print(Nmax) | 0 | null | 4,408,751,947,992 | 92 | 82 |
from collections import deque
N,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = deque(A[:K])
for i in range(K,N):
if B.popleft() < A[i]:
print('Yes')
else:
print('No')
B.append(A[i])
| n, k = map(int, input().split())
A = list(map(int, input().split()))
now = 1000
for i in range(k, n):
#print(A[i], A[i-k])
if A[i] > A[i-k]:
print("Yes")
else:
print("No") | 1 | 7,161,082,330,668 | null | 102 | 102 |
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
def f(length, ls):
cur = 0
for a in ls:
if a%length == 0:
cur += a//length - 1
else:
cur += a//length
if cur <= K:
return True
else:
return False
ok, ng = max(A), 0
while abs(ok - ng) > 1:
z = (ok+ng)//2
if f(z, A) == True:
ok = z
else:
ng = z
print(ok) | def main():
n,k = map(int,input().split())
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=a//cent
if a%cent==0:
ct-=1
if ct <= k:
right=cent
else:
left=cent
print(right)
main()
| 1 | 6,572,054,818,052 | null | 99 | 99 |
A = input().split()
a = A.count(A[0])
b = A.count(A[1])
c = A.count(A[2])
if a == 2 or b == 2 or c == 2:
print("Yes")
else:
print("No")
| A = list(map(int, input().split()))
L = []
for i in A:
if i not in L:
L.append(i)
if len(L) == 2:
print('Yes')
else:
print('No') | 1 | 67,848,268,719,848 | null | 216 | 216 |
#!/usr/bin/env python3
N, K = [int(s) for s in input().split()]
h = [int(s) for s in input().split()]
print(len(list(filter(lambda x: x >= K, h)))) | import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
mod=10**9+7
n,d,a=map(int,input().split())
xh=[list(map(int,input().split())) for i in range(n)]
xh.sort()
r,tama=[],[0]
for i in range(n):
x,h=xh[i]
tmpr=bisect.bisect_left(r,x)
h-=(tama[-1]-tama[tmpr])*a
tmp=0
if h>0:
tmp=math.ceil(h/a)
tama.append(tmp)
tama[i+1]+=tama[i]
r.append(x+2*d)
print(tama[-1])
# print(r) | 0 | null | 130,497,556,234,980 | 298 | 230 |
def make_array_for_comb(N, mod=10**9+7):
fact = [1,1]
fact_inv = [1,1]
inv = [0,1]
for i in range(2, N+1):
fact.append((fact[-1]*i) % mod)
# モジュラ逆数の性質
inv.append((-inv[mod%i] * (mod//i)) % mod)
fact_inv.append((fact_inv[-1]*inv[i]) % mod)
return fact, fact_inv
def comb(n, r, mod=10**9+7):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * fact_inv[r] * fact_inv[n-r] % mod
import sys
input = sys.stdin.readline
mod = 10**9+7
n,k = [int(i) for i in input().split()]
fact, fact_inv = make_array_for_comb(n,mod)
a = [int(i) for i in input().split()]
a = sorted(a)
a = tuple(a)
ans = 0
for i in range(0,n-k+1):
p = a[i]*comb(n-1-i,k-1,mod)
ans -= (p%mod)
ans %= mod
for i in range(k-1,n):
q = a[i]*comb(i,k-1,mod)
ans += (q%mod)
ans %= mod
print(ans) | def input_number():
num = raw_input()
array = num.strip().split(" ")
int_array = map(int, array)
return int_array
def main():
n = raw_input()
count = 0
int_array = input_number()
for i in range(int(n)):
minj = i
for j in range(i, int(n)):
if int_array[j] < int_array[minj]:
minj = j
v = int_array[i]
int_array[i] = int_array[minj]
int_array[minj] = v
if minj != i:
count += 1
array = map(str, int_array)
print " ".join(array)
print count
if __name__ == '__main__':
main() | 0 | null | 47,780,165,216,828 | 242 | 15 |
n=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
for p in range(1,4):
z=0
for i in range(n):
z+=(abs(x[i]-y[i]))**p
print(f'{z**(1/p):.6f}')
c=[abs(x[i]-y[i]) for i in range(n)]
print(f'{max(c):.6f}')
| a,b,m = map(int,input().split())
a_list = [int(x.strip()) for x in input().split()]
b_list = [int(x.strip()) for x in input().split()]
ans = min(a_list)+min(b_list)
for i in range(m):
ai,bi,ci = map(int,input().split())
ch = a_list[ai-1]+b_list[bi-1]-ci
if ch < ans:
ans = ch
print(ans) | 0 | null | 27,074,062,063,708 | 32 | 200 |
import math
def main():
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
print(Minkowski(n, x, y, 1))
print(Minkowski(n, x, y, 2))
print(Minkowski(n, x, y, 3))
print(Chebyshev(n, x, y))
def Minkowski(n, x, y, p):
temp = 0
for i in range(n):
temp += abs(y[i] - x[i])**p
return temp**(1/p)
def Chebyshev(n, x, y):
temp = 0
for i in range(n):
temp = max(temp, abs(y[i] - x[i]))
return temp
if __name__ == '__main__':
main()
| def dist(A_lst, B_lst, p):
s = 0
for a, b in zip(A_lst, B_lst):
s += abs(a - b) ** p
return s ** (1 / p)
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
print("{:.6f}".format(dist(A, B, 1)))
print("{:.6f}".format(dist(A, B, 2)))
print("{:.6f}".format(dist(A, B, 3)))
chebyshev = max(abs(a - b) for a, b in zip(A, B))
print("{:.6f}".format(chebyshev))
| 1 | 212,386,815,102 | null | 32 | 32 |
import copy
def countKuro( t,p1,p2 ):
count=0
for i in range(h):
if p1 & (1<<i) :
for j in range(w):
if p2 & (1<<j) :
if t[i][j]=="#":
count+=1
return count
h,w,k=map(int, input().split())
s=[]
for i in range(h):
s.append( input() )
t=copy.copy(s)
ans=0
for i in range(1<<h):
for j in range(1<<w):
# print(i,j, countKuro(s,i,j))
if k==countKuro(s, i,j):
ans+=1
print(ans)
| import itertools
h, w, k = map(int, input().split())
c = []
ans = 0
for i in range(h):
c.append(list(input()))
for i in range(2 ** h - 1):
c2 = []
x = str(bin(i))[2:].zfill(h)
for a in range(h):
if x[a] == '0':
c2.append(c[a])
elif x[a] == '1':
c2.append(['*'] * w)
black = list(itertools.chain.from_iterable(c2)).count('#')
for j in range(2 ** w - 1):
black2 = black
y = str(bin(j))[2:].zfill(w)
for b in range(w):
if y[b] == '1':
for a in range(h):
if c2[a][b] == '#':
black2 -= 1
if black2 == k:
ans += 1
print(ans) | 1 | 8,979,433,667,802 | null | 110 | 110 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import math
DEG60 = math.pi/3
def repl_edge(n, edges):
# print('n=',n, 'edges=', len(edges))
if n == 0:
return edges
new_list = list()
for edge in edges: # single tupple
p1 = edge[0]
p2 = edge[1]
p_angle = edge[2]
s = ((p1[0]*2+p2[0])/3, (p1[1]*2+p2[1])/3)
t = ((p1[0]+p2[0]*2)/3, (p1[1]+p2[1]*2)/3)
r = abs((t[0]-s[0])**2 + (t[1]-s[1])**2) ** 0.5
angle = p_angle + DEG60
u = (s[0] + math.cos(angle)*r, s[1] + math.sin(angle)*r)
# print('r=', r, 'u=', u, 'angle=', angle)
new_list += [(p1, s, p_angle), (s, u, p_angle+DEG60), \
(u, t, p_angle-DEG60), (t, p2, p_angle)]
new_list = repl_edge(n-1, new_list)
return new_list
n = int(sys.stdin.readline())
p1 = (0.0, 0.0)
p2 = (100.0, 0.0)
edges = [(p1, p2, 0.0)]
edges = repl_edge(n, edges)
for edge in edges:
print(round(edge[0][0],6), round(edge[0][1],6))
print(round(edges[-1][1][0],6), round(edges[-1][1][1],6))
| N=int(input())
testimonies=[]
for i in range(N):
A=int(input())
testimony=[]
for j in range(A):
testimony.append(list(map(int,input().split())))
testimony[-1][0]-=1
testimonies.append(testimony)
ans=0
for i in range(2**N):
isContradiction=False
for j in range(N):
if not i&1<<j:continue
for x,y in testimonies[j]:
if i&1<<x:x=1
else:x=0
if not x==y:
isContradiction=True
break
if not isContradiction:
ans=max(ans,bin(i).count("1"))
print(ans) | 0 | null | 61,076,554,742,600 | 27 | 262 |
#j-i=Ai+Aj(j>i)
#j-Aj=Ai+i
#Lj=Ri=X
from bisect import bisect_left
def main():
N=int(input())
A=list(map(int,input().split()))
L={}
R={}
res=0
for i in range(N):
l=(i+1)-A[i]
r=A[i]+i+1
if (l in R.keys()):
res+=len(R[l])
if (r in R.keys()):
R[r].append(i+1)
else:
R[r]=[i+1]
print(res)
if __name__=="__main__":
main()
| n=int(input())
a=list(map(int,input().split()))
ans=[0]*(n+1)
for i in range(n-1):
ans[a[i]]+=1
ans.pop(0)
for j in ans:
print(j) | 0 | null | 29,184,827,901,060 | 157 | 169 |
num = int(input())
print(0 if num == 1 else 1) | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = c.copy()
k = c.keys()
for i in k:
d[i] = c[i]*(c[i]-1) // 2
s = sum(list(d.values()))
for i in a:
print(s - d[i] + max(0, (c[i]-1)*(c[i]-2)//2)) | 0 | null | 25,298,788,215,552 | 76 | 192 |
import math
a,b,C=list(map(int,input().split()))
C_radian=math.radians(C)
S=a*b*math.sin(C_radian)/2
L=a+b+(a**2+b**2-2*a*b*math.cos(C_radian))**0.5
h=b*math.sin(C_radian)
print(S)
print(L)
print(h) | import math
a, b, t = map(int, input().strip().split())
t = math.radians(t)
h = b * math.sin(t)
l = a + b + math.sqrt(a*a + b*b - 2*a*b*math.cos(t))
s = a * h / 2
print(s)
print(l)
print(h) | 1 | 176,345,472,672 | null | 30 | 30 |
n, W = map(int, input().split())
ab = [tuple(map(int, input().split()))for _ in range(n)]
ab.sort()
ans = 0
dp = [0]*W
for a, b in ab:
if ans < dp[-1]+b:
ans = dp[-1]+b
for j in reversed(range(W)):
if j-a < 0:
break
if dp[j] < dp[j-a]+b:
dp[j] = dp[j-a]+b
print(ans)
| import sys
input = sys.stdin.readline
I=lambda:int(input())
MI=lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
N,T=MI()
dp=[[0]*(T+1) for _ in [0]*(N+1)]
food=[tuple(MI()) for _ in [0]*N]
food.sort()
for n in range(N):
a,b=food[n]
for t in range(T+1):
if t<T:
# たべる
dp[n+1][min(t+a,T)]=max(dp[n][t]+b,dp[n+1][min(t+a,T)])
# たべない
dp[n+1][t]=max(dp[n][t],dp[n+1][t])
print(dp[N][T]) | 1 | 151,266,878,385,440 | null | 282 | 282 |
X= int(input())
if(X>=400 and X<=599):
print(8)
elif(X>599 and X<800):
print(7)
elif(X>=800 and X<1000):
print(6)
elif(X>=1000 and X<1200):
print(5)
elif(X>=1200 and X<1400):
print(4)
elif(X>=1400 and X<1600):
print(3)
elif(X>=1600 and X<1800):
print(2)
elif(X>=1800 and X<2000):
print(1) | elements = [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]
K = int(input())
th = K-1
print(elements[th]) | 0 | null | 28,257,536,561,660 | 100 | 195 |
def ABC_147_A():
A1,A2,A3 = map(int, input().split())
if A1+A2+A3>=22:
print('bust')
else:
print('win')
if __name__ == '__main__':
ABC_147_A() | a,b,c=[int(i) for i in input().split()]
if((a+b+c)>=22):
print('bust')
else:
print('win') | 1 | 119,049,183,701,970 | null | 260 | 260 |
def factorial(n, mod):
fac = [0] * (n + 1)
inv = [0] * (n + 1)
fac[0], inv[0] = 1, 1
for i in range(1, n + 1):
fac[i] = fac[i-1] * i % mod
inv[i] = inverse(fac[i], mod)
return fac, inv
def inverse(a, mod):
a %= mod # 除数が正なら正になる
p = mod
x, y = 0, 1
while a > 0:
n = p // a
p, a = a, p % a,
x, y = y, x - n * y
return x % mod # 除数が正なら正になる
mod = 10 ** 9 + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
fac, inv = factorial(n, mod)
ans = 0
for i in range(0, n-k+1):
m = n - i - 1
ans = (ans + (a[-i-1] - a[i]) % mod * fac[m] % mod * inv[m-k+1] % mod * inv[k-1]) % mod
print(ans)
| # !/usr/local/bin/python3
MOD = int(1e9+7)
def nCk(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n]*(finv[n-k]*finv[k]%MOD)%MOD
def solve():
a.sort()
for i in range(2, MAX_N):
fac[i] = fac[i-1]*i%MOD
inv[i] = MOD-(inv[MOD%i])*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
max_x = 0
for i in range(k-1, n):
max_x = (max_x+a[i]*nCk(i, k-1))%MOD
min_x = 0
for i in range(n-k+1):
min_x = (min_x+a[i]*nCk(n-i-1, k-1))%MOD
return((max_x-min_x)%MOD)
if __name__ == "__main__":
n, k = list(map(int, input().split()))
a = [(lambda x: int(x))(x) for x in input().split()]
MAX_N = n+5
fac = [1, 1]+[0 for _ in range(MAX_N)]
finv = [1, 1]+[0 for _ in range(MAX_N)]
inv = [0, 1]+[0 for _ in range(MAX_N)]
print(solve())
| 1 | 95,755,777,323,232 | null | 242 | 242 |
H,N = map(int,input().split())
i = map(int,input().split())
if sum(i) >= H :
print("Yes")
else :
print("No") | h,n = map(int,input().split())
xlist = list(map(int,input().split()))
if sum(xlist)>=h:
print("Yes")
else:
print("No") | 1 | 77,933,866,715,890 | null | 226 | 226 |
n, m, l =map(int, input().split())
A = []
B = []
C = []
for i in range(n):
i = list(map(int, input().split()))
A.append(i)
for i in range(m):
i = list(map(int, input().split()))
B.append(i)
#積を求める
for i in range(n):
line = []
for j in range(l):
c = 0
for k in range(m):
c += A[i][k] * B[k][j]
line.append(c)
C.append(line)
#形式に合わせて出力する
for line in C:
print(*line)
| from collections import deque
n,m=map(int,input().split())
data=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
data[a].append(b)
data[b].append(a)
que=deque()
que.append(1)
cnt=[0]*(n+1)
while que:
h=que.popleft()
for u in data[h]:
if cnt[u]!=0:
continue
cnt[u]=h
que.append(u)
print('Yes')
for i in range(2,n+1):
print(cnt[i]) | 0 | null | 11,071,380,323,978 | 60 | 145 |
import copy
H, W, K = map(int, input().split())
tiles = [list(input()) for _ in range(H)]
count = 0
for num in range(2**(H+W)):
copied_tiles = copy.deepcopy(tiles)
for i in range(H+W):
if num>>i&1:
if i < H:
for j in range(W):
copied_tiles[i][j] = 'R'
else:
for j in range(H):
copied_tiles[j][i-H] = 'R'
black_c = 0
for i in range(H):
for j in range(W):
if copied_tiles[i][j] == '#':
black_c += 1
if black_c == K:
count += 1
print(count) | import sys
nm = input().split()
N = int(nm[0])
M = int(nm[1])
As = [int(a) for a in input().split()]
s = sum(As)
if N >= s:
ans = N - s
print(ans)
else:
print("-1")
| 0 | null | 20,459,511,569,210 | 110 | 168 |
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x%y)
def lcm(x,y):
return x/gcd(x, y)*y
while True:
try:
x, y = map(int, raw_input().split())
except EOFError:
break
print "%d %d" % (gcd(x, y), lcm(x, y)) | import sys
def gcd(a,b):
if b == 0: return a
else: return gcd(b,a%b)
for i in sys.stdin:
a, b = map(int, i.split())
g = gcd(a,b)
print g, a/g*b | 1 | 613,235,220 | null | 5 | 5 |
n = int(input())
total = 0
out = 1
for _ in range(n):
a, b = map(int, input().split())
if a == b:
total += 1
else:
if total >= 3:
out = 0
else:
total = 0
if total >= 3:
out = 0
if out:
print("No")
else:
print("Yes") | x, y, z = map(int, raw_input().split())
cnt = 0
for i in range(x, y+1):
if z%i == 0:
cnt += 1
print cnt | 0 | null | 1,489,152,074,262 | 72 | 44 |
a, b = map(int, input().split())
print(str(a * b) + " " + str(2 * a + 2 * b))
| Station = []
Station = input()
if Station == "AAA":
print("No")
elif Station == "BBB":
print("No")
else:
print("Yes") | 0 | null | 27,367,910,773,698 | 36 | 201 |
from collections import Counter
N, K = map(int, input().split())
As = list(map(int, input().split()))
Ss = [0]
S = 0
for A in As:
S += A-1
S %= K
Ss.append(S)
ans = 0
cnt = Counter()
for i in range(N+1):
ans += cnt[Ss[i]]
cnt[Ss[i]] += 1
if i >= K-1:
cnt[Ss[i-K+1]] -= 1
print(ans)
| import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
n,k=map(int,input().split())
A=list(map(lambda x:int(x)-1,input().split()))
S=[0]*(n+1)
for i in range(n):
S[i+1]=S[i]+A[i]
S[i+1]%=k
C=defaultdict(int)
ans=0
for i in range(n+1):
ans+=C[S[i]]
C[S[i]]+=1
if(i-k+1>=0): C[S[i-k+1]]-=1
print(ans)
resolve() | 1 | 137,545,022,800,690 | null | 273 | 273 |
x, y, a, b ,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
sm=0
p.sort()
q.sort()
r.sort(reverse=True)
p=p[(a-x):]
q=q[(b-y):]
p.extend(q)
p.sort()
idx=0
for i in range(len(p)):
if p[i]>r[idx]:
break
else:
p[i]=r[idx]
idx+=1
if c==idx:
break
print(sum(p)) | n, m = (int(x) for x in input().split())
list_a = [int(x) for x in input().split()]
for i in range(0, m):
n -= list_a[i]
if n < 0:
print('-1')
exit()
print(n) | 0 | null | 38,447,922,396,572 | 188 | 168 |
x = input()
print(x ** 3) | n = int(input())
a = [int(an) for an in input().split()]
xor_all = 0
for an in a:
xor_all = xor_all ^ an
anss = [str(xor_all ^ an) for an in a]
print(" ".join(anss)) | 0 | null | 6,438,239,599,972 | 35 | 123 |
ha,sa,hb,sb = list(map(int, input().split()))
while ha>0 and hb>0:
hb -= sa
if hb<=0: break
ha -= sb
print('Yes' if ha>0 else 'No') |
A,B,C,D = map(int, input().split())
n = 0
if C%B ==0:
if A-(C//B-1)*D > 0:
print('Yes')
else:
print('No')
elif C%B != 0:
if A-(C//B)*D > 0:
print('Yes')
else:
print('No')
| 1 | 29,739,479,811,052 | null | 164 | 164 |
import math
a, b, degC = [ float( i ) for i in raw_input( ).split( " " ) ]
radC = degC*math.pi/ 180.0
h = math.sin( radC ) * b
S = (a*h)/2
x = math.cos( radC ) * b
x -= a
c = math.sqrt( x**2 + h**2 )
L = a + b + c
print( S )
print( L )
print( h ) | d,t,s = input().split()
gool = int(d) / int(s)
if gool <= int(t):
print('Yes')
else:
print('No') | 0 | null | 1,861,777,800,710 | 30 | 81 |
n = int(input())
given_list = list(map(int, input().split()))
for i in range(n):
if i == n-1:
print(given_list[n-i-1])
else:
print(given_list[n-i-1], end=" ") | x,y = map(str,input().split())
a = {'1':300000,'2':200000,'3':100000}
if int(x) > 3 or int(y) > 3:
if int(x) <= 3:
print(a[x])
elif int(y) <= 3:
print(a[y])
else:
print(0)
else:
if x == y == '1':
print(1000000)
else:
print(a[x]+a[y]) | 0 | null | 70,993,520,590,888 | 53 | 275 |
def resolve():
N = int(input())
s = set()
for _ in range(N):
a, b = input().split()
if a == "insert":
s.add(b)
else:
if b in s:
print("yes")
else:
print("no")
resolve()
| bingoSheet = [0 for x in range(9)]
for i in range(3):
bingoRow = input().split()
for j in range(3):
bingoSheet[i*3 + j] = int(bingoRow[j])
bingoCount = int(input())
responses = []
for i in range(bingoCount):
responses.append(int(input()))
hasBingo = False
step = 1
initialIndex = 0
for i in range(3):
firstIndex = i*3
subList = [bingoSheet[index] for index in [firstIndex, firstIndex+1, firstIndex+2]]
if (all(elem in responses for elem in subList)):
hasBingo = True
break
for i in range(3):
firstIndex = i
subList = [bingoSheet[index] for index in [firstIndex, firstIndex+3, firstIndex+6]]
if (all(elem in responses for elem in subList)):
hasBingo = True
break
subList = [bingoSheet[index] for index in [0, 4, 8]]
if (all(elem in responses for elem in subList)):
hasBingo = True
subList = [bingoSheet[index] for index in [2, 4, 6]]
if (all(elem in responses for elem in subList)):
hasBingo = True
if hasBingo:
print('Yes')
quit()
print('No')
quit()
| 0 | null | 29,826,298,031,440 | 23 | 207 |
# -*- coding: utf-8 -*-
x = []
while ( 1 ):
temp = int( input() )
if (temp == 0):
break
x.append(temp)
index = 1
for i in x:
print('Case {0}: {1}'.format(index, i))
index += 1 | for i in range(10000):
x=int(input())
if x==0:
break
print("Case "+str(i+1)+": "+str(x))
| 1 | 496,429,346,632 | null | 42 | 42 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.