code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,629B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
from math import sqrt
def div(n):
s = set()
for i in range(1, int(sqrt(n))+2):
if n%i == 0:
s.add(i)
s.add(n//i)
return s
def solve(x, n):
while n % x == 0:
n //= x
if n % x == 1:
return True
return False
def main():
n = int(input())
t = div(n) | div(n-1)
ans = 0
for v in t:
if v != 1 and solve(v, n):
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
def divisor(n):
res = []
i = 1
while i*i <= n:
if not n % i:
res.append(i)
if (i*i != n): res.append(n//i)
i += 1
return res
N = int(input())
ans = 0
for d in divisor(N):
if d == 1: continue
n = N
while not n % d:
n //= d
if n%d == 1: ans += 1
print(ans + len(divisor(N-1))-1)
| 1 | 41,419,612,546,180 | null | 183 | 183 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m,k=map(int,input().split())
uf=UnionFind(n)
fr=[set() for _ in range(n)]
for i in range(m):
a,b=map(int,input().split())
fr[a-1].add(b-1)
fr[b-1].add(a-1)
uf.union(a-1,b-1)
br=[set() for _ in range(n)]
for i in range(k):
a,b=map(int,input().split())
br[a-1].add(b-1)
br[b-1].add(a-1)
ans=[0]*n
for i in range(n):
t=uf.size(i)-len(fr[i])-1
for j in br[i]:
if uf.same(i,j):
t-=1
ans[i]=t
print(*ans)
|
def main():
n,m = map(int, input().split())
a = sorted(list(map(int, input().split())),reverse = True)
all = sum(a)
cnt = 0
for i in(a):
if(i * 4 * m >= all and cnt < m):
cnt += 1
if cnt >= m:
print('Yes')
else:
print('No')
main()
| 0 | null | 50,338,922,589,942 | 209 | 179 |
# coding=utf-8
a, b = map(int, input().split())
if a > b:
big_num = a
sml_num = b
else:
big_num = b
sml_num = a
while True:
diviser = big_num % sml_num
if diviser == 0:
break
else:
big_num = sml_num
sml_num = diviser
print(sml_num)
|
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
x, y = [int(n) for n in input().split()]
print(gcd(x, y))
| 1 | 7,871,368,412 | null | 11 | 11 |
print('10'[int(input())])
|
x=int(input())
if 0<=x<=1:
if x==1:
print("0")
else:
print("1")
| 1 | 2,969,337,326,240 | null | 76 | 76 |
# 解説放送の方針
# ダメージが消える右端をキューで管理
# 右端を超えた分は、累積ダメージから引いていく
from collections import deque
N,D,A=map(int,input().split())
XH = [tuple(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
que=deque()
cum = 0
ans = 0
for i in range(N):
x,h = XH[i]
if i == 0:
r,n = x+2*D,(h+A-1)//A
d = n*A
cum += d
que.append((r,d))
ans += n
continue
while que and que[0][0]<x:
r,d = que.popleft()
cum -= d
h -= cum
if h<0:
continue
r,n = x+2*D,(h+A-1)//A
d = n*A
cum += d
que.append((r,d))
ans += n
print(ans)
|
def main():
S = ''
while True:
try:
S = S + input()
except:
break
s = S.lower()
for i in range(97, 123):
c = chr(i)
n = s.count(c)
print('{} : {}'.format(c, n))
main()
| 0 | null | 41,771,743,641,408 | 230 | 63 |
# -*- coding: utf-8 -*-
"""
全探索
・再帰で作る
・2^20でTLEするからメモ化した
"""
N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))
def dfs(cur, depth, ans):
# 終了条件
if cur == ans:
return True
# memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない
if cur in memo[depth]:
return False
memo[depth].add(cur)
# 全探索
for i in range(depth, N):
if dfs(cur+aN[i], i+1, ans):
return True
# 見つからなかった
return False
for i in range(Q):
memo = [set() for j in range(N+1)]
if dfs(0, 0, mQ[i]):
print('yes')
else:
print('no')
|
#coding: UTF-8
def isPrime(n):
if n == 1:
return False
import math
m = math.floor(math.sqrt(n))
for i in range(2,m+1):
if n % i == 0:
return False
return True
n = int(input())
count = 0
for j in range(n):
m = int(input())
if isPrime(m):
count += 1
print(count)
| 0 | null | 57,577,319,940 | 25 | 12 |
k, y = [int(i) for i in input().split()]
print('Yes' if 500 * k >= y else 'No')
|
def bubbleSort(A, N):
count = 0
for j in range(N - 1):
for i in reversed(range(j + 1, N)):
if A[i - 1] > A[i]:
temp = A[i]
A[i] = A[i - 1]
A[i - 1] = temp
count = count + 1
for i in range(N):
print A[i],
print
print count
N = input()
A = map(int, raw_input().split())
bubbleSort(A, N)
| 0 | null | 49,101,170,126,564 | 244 | 14 |
# https://atcoder.jp/contests/abc153/tasks/abc153_f
# 座標圧縮、貪欲法、imos法
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
def read_tuple(H):
'''
H is number of rows
'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
# まず、何回攻撃すればいいのかを計算する。これがとにかく必要だ(なくてもいいけど)。
#
# 素直な戦略として、左から倒せるギリギリの爆弾を投下して倒すのが最適
# だけどナイーブに実装すると、O(N^2)。だから体力を管理するのが重要。
# どこにどれだけダメージが蓄積したのかはimos法(デルタ関数をおいてから累積和)で管理できる。
from bisect import bisect_left
N, D, A = read_ints()
XH = read_tuple(N)
XH.sort() # 座標でソート
n_atk = [] # 何回攻撃するのが必要か
X = [] # 座標アクセス用配列
for x, h in XH:
n_atk.append((h - 1) // A + 1)
X.append(x)
damege = [0] * (N + 10) # ダメージ管理用、配列外アクセスがめんどくさいので長めに取る
ans = 0
# j = 0 # 次のxが、今のx+2d以下でもっとも大きなidx
for i, (x, n) in enumerate(zip(X, n_atk)):
damege[i] += damege[i - 1] # 積分して、現時点の蓄積回数を表示
atk = max(0, n - damege[i]) # iには何回攻撃したか
ans += atk
# 攻撃下回数を記録
damege[i] += atk
# 効果が切れる点を予約 # 尺取ならO(1)で次に行けるけど二分探索でも間に合うか
damege[bisect_left(X, x + 2 * D + 1, lo=i)] -= atk # 効果切れを予約
print(ans)
|
def solve():
N = int(input())
cnt = {}
for i in range(N):
result = input()
cnt[result] = cnt.get(result, 0) + 1
for result in ("AC", "WA", "TLE", "RE"):
print("{} x {}".format(result, cnt.get(result, 0)))
if __name__ == "__main__":
solve()
| 0 | null | 45,572,785,058,350 | 230 | 109 |
"""D."""
import sys
def input() -> str: # noqa: A001
"""Input."""
return sys.stdin.readline()[:-1]
class UnionFindTree:
"""Union-find."""
def __init__(self, n: int) -> None:
"""Init."""
self.n = n
self.rank = [-1] * n
def find_root(self, x: int) -> int:
"""Find root."""
if self.rank[x] < 0:
return x
self.rank[x] = self.find_root(self.rank[x])
return self.rank[x]
def union(self, x: int, y: int) -> None:
"""Unite two trees."""
x_root = self.find_root(x)
y_root = self.find_root(y)
if x_root == y_root:
return
if x_root > y_root:
x_root, y_root = y_root, x_root
self.rank[x_root] += self.rank[y_root]
self.rank[y_root] = x_root
def get_size(self, x: int) -> int:
"""Get size."""
return self.rank[self.find_root(x)] * -1
def is_same(self, x: int, y: int) -> bool:
"""Is same group."""
return self.find_root(x) == self.find_root(y)
n, m = map(int, input().split(' '))
tree = UnionFindTree(n)
for _ in range(m):
a, b = map(int, input().split(' '))
tree.union(a - 1, b - 1)
ans = 0
for i in range(n):
ans = max(ans, tree.get_size(i))
print(ans)
|
#D
from queue import Queue
N,M=map(int,input().split())
Friend=[[] for i in range(N+1)]
for i in range(M):
a,b=map(int,input().split())
Friend[a].append(b)
Friend[b].append(a)
Flag=[False for i in range(N+1)]
ans=1
for i in range(1,N+1):
if Flag[i]:
continue
q=Queue()
q.put(i)
cnt=1
while not q.empty():
st=q.get()
Flag[st]=True
for j in Friend[st]:
if Flag[j]:
continue
cnt+=1
Flag[j]=True
q.put(j)
ans=max(ans,cnt)
print(ans)
| 1 | 3,921,809,063,612 | null | 84 | 84 |
#! /usr/bin/python3
k = int(input())
print('ACL'*k)
|
print('ACL'*int(input()))
| 1 | 2,157,883,168,492 | null | 69 | 69 |
a,b,c,d = list(map(int,input().split()))
t_win_turn = c // b
if c % b > 0:
t_win_turn += 1
a_win_turn = a // d
if a % d > 0:
a_win_turn += 1
if t_win_turn <= a_win_turn:
print('Yes')
else:
print('No')
|
A,B,C,D= map(int, input().split())
while (True):
C = C - B
if ( C <= 0 ):
result = "Yes"
break
A = A - D
if ( A <= 0 ) :
result = "No"
break
print ( result )
| 1 | 29,994,086,158,028 | null | 164 | 164 |
# 高橋くんのモンスターは体力Aで攻撃力B
# 青木くんのモンスターは体力Cで攻撃力D
# 高橋くんが勝つならYes、負けるならNoを出力する
A, B, C, D = map(int, input().split())
while A > 0 and C > 0:
C -= B
A -= D
if C <= 0:
print('Yes')
elif A <= 0:
print('No')
|
a,b,c,d = map(int, input().split())
z = 'BATTLE'
while z == 'BATTLE':
c -= b
if c <= 0:
z = 'Yes'
break
a -= d
if a <= 0:
z ='No'
break
print(z)
| 1 | 29,484,339,453,520 | null | 164 | 164 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(min(50, k)):
l = [0]*(n+1)
for i in range(n):
l[max(i-a[i], 0)] += 1 #光の届く距離(後ろ)
l[min(i+a[i]+1, n)] -= 1 #光が届かなくなる距離(前)
add = 0
for i in range(n):
add += l[i] #光の届いている電球の数を累積
a[i] = add
print(*a)
|
import sys
input()
numbers = map(int, input().split())
evens = [number for number in numbers if number % 2 == 0]
if len(evens) == 0:
print('APPROVED')
sys.exit()
for even in evens:
if even % 3 != 0 and even % 5 != 0:
print('DENIED')
sys.exit()
print('APPROVED')
| 0 | null | 42,417,291,484,400 | 132 | 217 |
for num1 in range(1,10):
for num2 in range(1,10):
i = num1 * num2
print(str(num1) + "x" + str(num2) + "=" + str(i))
|
H, W, M = map(int, input().split())
hw = []
sh = [0] * H
sw = [0] * W
for i in range(M):
h, w = map(int, input().split())
hw.append((h - 1, w - 1))
sh[h - 1] += 1
sw[w - 1] += 1
mh = max(sh)
mw = max(sw)
count = 0
for i in range(M):
if sh[hw[i][0]] == mh and sw[hw[i][1]] == mw:
count += 1
if sh.count(mh) * sw.count(mw) > count:
print(mh + mw)
else:
print(mh + mw - 1)
| 0 | null | 2,396,420,902,990 | 1 | 89 |
def myfindall(s,ps):
# start = 0
matchlist =[]
while True:
tmp = s.find(ps)
if tmp < 0 :
break
if len(matchlist)>0:
matchlist.append(tmp+matchlist[-1]+1)
else:
matchlist.append(tmp)
s = s[tmp+1:]
return matchlist
instr = raw_input()
findstr = raw_input()
matchlist = myfindall(instr,findstr[0])
matchflag = False
y=0
for x in matchlist:
if matchflag:
break
while True:
if y >= len(findstr):
print "Yes"
matchflag = True
break
if x >= len(instr):
x = 0
if instr[x]==findstr[y]:
x+=1
y+=1
else:
y=0
break
if not matchflag:
print "No"
|
a = ord(input())
if ord("a") <= a <= ord("z"):
print("a")
else:
print("A")
| 0 | null | 6,493,771,925,340 | 64 | 119 |
int(input())
s = list(input())
ans = 0
for i in range(10):
if str(i) in s:
ss = s[s.index(str(i))+1:]
for j in range(10):
if str(j) in ss:
sss = ss[ss.index(str(j))+1:]
for k in range(10):
if str(k) in sss:
ans += 1
print(ans)
|
a = list(map(int, input().split()))
suma = a[0] + a[1] + a[2]
if suma >= 22:
print('bust')
else:
print('win')
| 0 | null | 123,597,803,954,170 | 267 | 260 |
n = int(input())
adj = [None]
for i in range(n):
adji = list(map(int, input().split()[2:]))
adj.append(adji)
isSearched = [None] + [False] * n
distance = [None] + [-1] * n
def BFS(u):
d = 0
isSearched[u] = True
distance[u] = d
edge = [u]
while edge:
q = list(edge)
edge = []
d += 1
for ce in q:
for ne in adj[ce]:
if not isSearched[ne]:
isSearched[ne] = True
edge.append(ne)
distance[ne] = d
BFS(1)
for i, x in enumerate(distance[1:], start=1):
print(i, x)
|
import sys
from math import sqrt
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int
nl = lambda: list(map(int, readline().split())) # input multiple int to list
a, b, c = nm()
if 4*a*b < (c-a-b)**2 and c-a-b>0:
print('Yes')
else:
print('No')
| 0 | null | 25,656,494,096,740 | 9 | 197 |
all = [suit + ' ' + str(rank) for suit in 'SHCD' for rank in range(1, 14)]
for _ in range(int(input())):
all.remove(input())
for card in all:
print(card)
|
import math
a,b,x = map(int,input().split())
if x >= 0.5 * a**2 * b:
tan_x = 2*(b*a**2 -x)/a**3
else:
tan_x = (b**2 * a)/(2*x)
print(math.degrees(math.atan(tan_x)))
| 0 | null | 82,534,616,859,432 | 54 | 289 |
def main():
n = int(input())
inlis = list(map(int, input().split()))
inset = set(inlis)
if len(inlis) == len(inset):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
|
n = int(input())
a = n/3
print(a**3)
| 0 | null | 60,747,919,377,948 | 222 | 191 |
hon=[2,4,5,7,9]
pon=[0,1,6,8]
bon=[3]
N=int(input())
if N%10 in hon:
print('hon')
elif N%10 in pon:
print('pon')
else:
print('bon')
|
N = int(input())
judge = N%10
hon = [2,4,5,7,9]
pon = [0,1,6,8]
bon = [3]
if judge in hon:
print("hon")
elif judge in pon:
print("pon")
elif judge in bon:
print("bon")
| 1 | 19,145,445,415,772 | null | 142 | 142 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache
n, k = map(int, read().split())
@lru_cache()
def check(n, k):
if n < 10:
if k == 0:
return 1
if k == 1:
return n
return 0
a, b = divmod(n, 10)
cnt = 0
if k >= 1:
cnt += check(a, k - 1) * b
cnt += check(a - 1, k - 1) * (9 - b)
cnt += check(a, k)
return cnt
print(check(n, k))
|
import sys
import math
sys.setrecursionlimit(1000000)
N = int(input())
K = int(input())
from functools import lru_cache
@lru_cache(maxsize=10000)
def f(n,k):
# print('n:{},k:{}'.format(n,k))
if k == 0:
return 1
if k== 1 and n < 10:
return n
keta = len(str(n))
if keta < k:
return 0
h = n // (10 ** (keta-1))
b = n % (10 ** (keta-1))
ret = 0
for i in range(h+1):
if i==0:
ret += f(10 ** (keta-1) - 1, k)
elif 1 <= i < h:
ret += f(10 ** (keta-1) - 1, k-1)
else:
ret += f(b,k-1)
return ret
print(f(N,K))
| 1 | 76,263,178,880,760 | null | 224 | 224 |
n, m = map(int, input().split())
a =[[0 for i in range(m)]for j in range(n)]
for i in range(n):
a[i] = list(map(int, input().split()))
b = [0 for j in range(m)]
for j in range(m):
b[j] = int(input())
c = [0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
print(c[i])
|
#!/usr/bin/env python3
import sys
import collections
input = sys.stdin.readline
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
N = I()
A = LI()
A.sort()
cnt = collections.Counter(A)
end = A[-1] + 1
for a in A:
if cnt[a] >= 2:
del cnt[a]
for i in range(a * 2, end, a):
del cnt[i]
print(sum(cnt.values()))
| 0 | null | 7,798,854,367,834 | 56 | 129 |
def resolve():
N, K = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:K]))
if __name__ == "__main__":
resolve()
|
N,K=input().split()
N=int(N)
K=int(K)
a=[]
a=[int(a) for a in input().split()]
a.sort()
print(sum(a[0:K]))
| 1 | 11,678,738,050,140 | null | 120 | 120 |
import math
N = input()
c = 0
p = [0 for i in range(N)]
for i in range(0,N):
p[i] = input()
for i in range(N):
s = math.sqrt(p[i])
j = 2
while(j <= s):
if(p[i]%j == 0):
break
j += 1
if(j > s):
c += 1
print c
|
count = 0
for _ in range(int(input())):
n = int(input())
if n == 2 or pow(2,n-1,n) == 1:
count += 1
print(count)
| 1 | 10,342,467,072 | null | 12 | 12 |
from collections import deque
n , d , a = map(int,input().split())
mon = [tuple(map(int,input().split())) for i in range(n)]
mon.sort()
p = deque(mon)
baku = deque()
cou = 0
ans = 0
while p:
nowx , nowh = p.popleft()
while baku:
bx , bh = baku.popleft()
if bx >= nowx:
baku.appendleft((bx,bh))
break
elif bx < nowx:
cou -= bh
if nowh <= cou:
continue
elif nowh > cou:
k = -((-nowh+cou)//a)
ans += k
cou += a*k
baku.append((nowx+2*d,a*k))
print(ans)
|
def penalty(day, last, c):
val = 0
for i in range(26):
val += c[i] * (day - last[i])
return val
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
last = [-1]*26
ans = [0]*(d+1)
for day in range(d):
ans[day+1] = ans[day] + s[day][t[day]-1]
last[t[day]-1] = day
ans[day+1] -= penalty(day, last, c)
for v in ans[1:]:
print(v)
| 0 | null | 46,298,279,680,508 | 230 | 114 |
n,k = map(int,input().split())
a = n%k
b = k-a
print(min(a,b))
|
from sys import stdin
input = stdin.readline
def main():
N, K = list(map(int, input().split()))
surp = N % K
print(min(surp, abs(surp-K)))
if(__name__ == '__main__'):
main()
| 1 | 39,648,797,916,672 | null | 180 | 180 |
def pc(x):
return format(x, 'b').count('1')
N = int(input())
X = input()
Xo = int(X, 2)
count = 0
ans = 0
ori = pc(Xo)
X = list(X)
Xp = Xo%(ori + 1)
if ori == 1:
Xm = 0
else:
Xm = Xo % (ori - 1)
# for i in range(N-1, -1, -1):
for i in range(N):
if ori == 1 and X[i] == '1':
print(0)
continue
else:
if X[i] == '1':
# ans = Xm - pow(2, i, ori - 1)
ans = Xm - pow(2, N-1-i, ori - 1)
ans %= ori - 1
else:
# ans = Xp - pow(2, i, ori + 1)
ans = Xp + pow(2, N-1-i, ori + 1)
ans %= ori + 1
count = 1
while ans > 0:
# count += 1
# if ans == 1:
# break
ans %= pc(ans)
count += 1
print(count)
count = 1
|
import math
from copy import copy
di = {}
di[0] = 0
for i in range(1, 2*(10**5)+1):
di[i] = 0
for i in range(1, 2*(10**5)+1):
count = 0
for j in range(int(math.log2(i))+4):
if (i>>j)&1:
count += 1
di[i] = di[i%count] + 1
n = int(input())
x = list(input())
x.reverse()
count = 0
for i in x:
if i =='1':
count += 1
mod_p = count + 1
mod_m = count - 1
di_p = {}
di_m = {}
for i in range(n):
di_p[i] = pow(2, i, mod_p)
if mod_m >= 1:
di_m[i] = pow(2, i, mod_m)
s_p = 0
s_m = 0
for i in range(n):
if x[i] == '1':
s_p += di_p[i]
if mod_m >= 1:
s_m += di_m[i]
else:
continue
for i in range(n-1, -1, -1):
sm = copy(s_m)
sp = copy(s_p)
if x[i] == '1' and (mod_m == 0 or mod_m == -1):
print(0)
elif x[i] == '1':
sm -= di_m[i]
sm %= mod_m
print(di[sm]+1)
else:
sp += di_p[i]
sp %= mod_p
print(di[sp]+1)
| 1 | 8,168,989,393,930 | null | 107 | 107 |
n=int(input()); s=""
for i in range(n):
s+='ACL'
print(s)
|
def DFS(s, t):
t += 1
flag[s] = 1
d[s] = t
for i in range(1, n+1):
if G[s][i] == 1:
if flag[i] == 0:
DFS(i, t)
t = f[i]
f[s] = t + 1
n = int(raw_input())
G = [[0 for i in range(n+1)] for j in range(n+1)]
d = [0 for i in range(n+1)]
f = [0 for i in range(n+1)]
for i in range(n):
v = map(int, raw_input().split())
for j in range(v[1]):
G[v[0]][v[2+j]] = 1
flag = [0 for i in range(n+1)]
for i in range(1, n+1):
if flag[i] == 0:
DFS(i, max(f))
for i in range(1, n+1):
print(str(i) + " " + str(d[i]) + " " + str(f[i]))
| 0 | null | 1,105,589,515,900 | 69 | 8 |
H,W,M=map(int,input().split())
#二次元リストではなく列行を一個のボムで消してくれるためそれぞれのリストを用意。
sumh = [0] * H
sumw = [0] * W
bomb=[]
for i in range(M):
h,w=map(int,input().split())
sumh[h-1]+=1
sumw[w-1]+=1
bomb.append((h,w))
#爆弾の個数の最大値とその最大値がいくつずつあるか(ch,cw)に保存。最大の列と最大の行のいずれかの組み合わせに置くことで爆破数を最大化できる。
maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)
#print(maxh,maxw,ch,cw)
#爆弾のある場所がH,Wの座標で両方共で最大個数の場所であった場合その数を加算
count=0
for h,w in bomb:
if sumh[h-1]==maxh and sumw[w-1]==maxw:
count+=1
#print(count)
#破壊できる数は、そのマスに爆破対象があるとき一つ減ってしまう。
if count==ch*cw:
print(maxh+maxw-1)
else:
print(maxh+maxw)
|
N,K,C=map(int,input().split())
S=input()
L=[0 for i in range(K)]
R=[0 for i in range(K)]
n=0
rc=0
lc=0
while True:
if lc==K:
break
if S[n]=="o":
L[lc]=n+1
n+=C+1
lc+=1
else:
n+=1
n=N-1
while True:
if rc==K:
break
if S[n]=="o":
R[K-1-rc]=n+1
n-=C+1
rc+=1
else:
n-=1
for i in range(K):
if R[i]==L[i]:
print(R[i])
| 0 | null | 22,670,256,139,208 | 89 | 182 |
s = raw_input()
r = ''
for c in s:
d = c
if c >= 'a' and c <= 'z':
d = chr(ord(c) - ord('a') + ord('A'))
if c >= 'A' and c <= 'Z':
d = chr(ord(c) - ord('A') + ord('a'))
r = r + d
print r
|
S, T = map(str, input().split())
A, B = map(int, input().split())
U = input()
a = A - 1
b = B - 1
if U == S:
print('{} {}'.format(a,B))
else:
print('{} {}'.format(A,b))
| 0 | null | 36,562,105,042,540 | 61 | 220 |
n,r=map(int,input().split())
def rate(n,r):
if n>=10:
return r
else:
return r+100*(10-n)
print(rate(n,r))
|
def resolve():
N = int(input())
A = list(map(int, input().split()))
ords = []
for i, a in enumerate(A):
ords.append((i, a))
ans = list(map(lambda x: x[0]+1, sorted(ords, key=lambda x: x[1])))
print(*ans)
if '__main__' == __name__:
resolve()
| 0 | null | 122,090,440,322,662 | 211 | 299 |
N = int(input())
list = input().split()
answer = [0] * N
for i in range(N):
answer[int(list[i]) - 1] = str(i + 1)
print(' '.join(answer))
|
data = input().split()
print(int(data[0])*int(data[1]))
| 0 | null | 98,660,537,870,168 | 299 | 133 |
import copy
from collections import deque
n, st, sa = map(int,input().split())
st -= 1
sa -= 1
e = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
visited = [False] * n
visited[st] = True
d = deque()
d.append([st, 0])
tx = {}
if len(e[st]) == 1:
tx[st] = 0
cnt = 0
while d:
f, cnt = d.popleft()
flg = True
for t in e[f]:
if not visited[t]:
flg = False
d.append([t, cnt+1])
visited[t] = True
if flg:
tx[f] = cnt
visited = [False] * n
visited[sa] = True
d = deque()
d.append([sa, 0])
ax = {}
if len(e[sa]) == 1:
ax[sa] = 0
cnt = 0
while d:
f, cnt = d.popleft()
flg = True
for t in e[f]:
if not visited[t]:
flg = False
d.append([t, cnt+1])
visited[t] = True
if flg:
ax[f] = cnt
ax = sorted(ax.items(), key=lambda x:x[1], reverse=True)
for i in range(len(ax)):
x, d = ax[i][0], ax[i][1]
if d > tx[x]:
ans = d - 1
break
print(ans)
|
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
a = [_ab[0] for _ab in ab]
b = [_ab[1] for _ab in ab]
a.sort()
b.sort()
if n % 2 == 1:
m = a[n // 2]
M = b[n // 2]
print(M - m + 1)
else:
m = (a[n // 2 - 1] + a[n // 2]) / 2
M = (b[n // 2 - 1] + b[n // 2]) / 2
print(int((M - m) * 2 + 1))
| 0 | null | 67,225,908,945,492 | 259 | 137 |
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
L=[-1]*n
for i in range(m):
s,c = map(int,input().split())
s-=1
if s>n-1:
continue
if L[s] ==-1 and s<=n-1:
L[s] = c
else:
if L[s]!=c:
print(-1)
sys.exit()
if L[0]==0 and n>1:
print(-1)
sys.exit()
if len(L)==1 and L[0]==-1:
L[0]=0
elif L[0]==-1:
L[0]=1
for i in range(n):
if L[i]==-1:
L[i]=0
print("".join(map(str,L)))
|
N, D = map(int, input().split())
ans = 0
for _ in range(N):
x, y = map(int, input().split())
if x**2 + y**2 <= D**2:
ans += 1
print(ans)
| 0 | null | 33,569,041,537,212 | 208 | 96 |
S = input().rstrip()
print('x' * len(S))
|
s= input()
x = "x" * len(s)
print(x)
| 1 | 72,889,225,468,638 | null | 221 | 221 |
a = input()
t = list(a)
if t[len(t)-1] == "?":
t[len(t)-1] = "D"
if t[0] == "?":
if t[1] == "D" or t[1] == "?":
t[0] = "P"
else:
t[0] = "D"
for i in range(1, len(t)-1):
if t[i] == "?" and t[i-1] == "P":
t[i] = "D"
elif t[i] == "?" and t[i+1] == "D":
t[i] = "P"
elif t[i] == "?" and t[i+1] == "?":
t[i] = "P"
elif t[i] == "?":
t[i] = "D"
answer = "".join(t)
print(answer)
|
def isPrime(num):
if num <= 1:
return False
elif num == 2 or num == 3:
return True
elif num % 2 == 0:
return False
else:
count = 3
while True:
if num % count and count ** 2 <= num:
count += 2
continue
elif num % count == 0:
return False
else:
break
return True
if __name__ == '__main__':
count = 0
N = int(input())
for i in range(N):
i = int(input())
if isPrime(i):
count += 1
print(count)
| 0 | null | 9,185,817,429,188 | 140 | 12 |
class Stack:
def __init__(self, n):
self.n = n
self._l = [None for _ in range(self.n + 1)]
self._top = 0
def push(self, x):
if self.isFull():
raise IndexError("stack is full")
else:
self._top += 1
self._l[self._top] = x
def pop(self):
if self.isEmpty():
raise IndexError("pop from empty stack")
else:
e = self._l[self._top]
self._l[self._top] = None
self._top -= 1
return e
def isEmpty(self):
return self._top == 0
def isFull(self):
return self._top == self.n
def poland_calculator(s):
n = len(s)
stack = Stack(n)
i = 0
while i < n:
if s[i] == ' ':
i += 1
continue
elif s[i].isdigit():
sn = ''
while s[i].isdigit():
sn += s[i]
i += 1
stack.push(int(sn))
else:
b = stack.pop()
a = stack.pop()
if s[i] == '+':
e = a + b
elif s[i] == '-':
e = a - b
else:
e = a * b
stack.push(e)
i +=1
return stack.pop()
if __name__ == '__main__':
s = input()
res = poland_calculator(s)
print(res)
|
import sys
input = sys.stdin.readline
N = int(input())
op = []
ed = []
mid = [0]
dg = 10**7
for _ in range(N):
s = list(input())
n = len(s)-1
a,b,st = 0,0,0
for e in s:
if e == '(':
st += 1
elif e == ')':
if st > 0:
st -= 1
else:
a += 1
st = 0
for i in range(n-1,-1,-1):
if s[i] == ')':
st += 1
else:
if st > 0:
st -= 1
else:
b += 1
if a > b:
ed.append(b*dg + a)
elif a == b:
mid.append(a)
else:
op.append(a*dg + b)
op.sort()
ed.sort()
p = 0
for e in op:
a,b = divmod(e,dg)
if p < a:
print('No')
exit()
p += b-a
q = 0
for e in ed:
b,a = divmod(e,dg)
if q < b:
print('No')
exit()
q += a-b
if p == q and p >= max(mid):
print('Yes')
else:
print('No')
| 0 | null | 11,771,111,419,960 | 18 | 152 |
import math
x1,y1,x2,y2=map(float,input().split())
print(round(math.sqrt((x1-x2)**2+(y1-y2)**2),7))
|
import math
x1,y1,x2,y2= map(float,(input().split()))
D=(x2-x1)**2+(y2-y1)**2
d= math.sqrt(D)
print(d)
| 1 | 153,452,380,060 | null | 29 | 29 |
N = int(input())
P = list(map(int, input().split()))
ans = 1
cnt = [0] * 3
mod = 10**9+7
for i in range(N):
opt = 0
cond = 1
for j in range(3):
if cnt[j] == P[i]:
opt += 1
if cond:
cnt[j] += 1
cond = 0
ans *= opt
ans %= mod
ans %= mod
print(ans)
|
# coding: utf-8
n = int(input())
a_array = list(map(int, input().split()))
count = 0
for i, a in enumerate(a_array):
if i % 2 == 0 and a % 2 != 0:
count += 1
print(count)
| 0 | null | 68,673,643,681,888 | 268 | 105 |
N=int(input())
S,T=input().split()
ans=S[0]+T[0]
for i in range(1,N):
ans=ans+S[i]+T[i]
print(ans)
|
n = int(input())
s,t = input().split()
for i in range(n):
print(s[i]+t[i],end="")
| 1 | 111,858,870,875,610 | null | 255 | 255 |
N, K = map(int, input().split())
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7
pos = sorted(v for v in X if v >= 0)
neg = sorted(-v for v in X if v < 0)
if N == K:
ans = 1
for x in X:
ans *= x
ans %= MOD
print(ans % MOD)
exit()
ok = False # True: ans>=0, False: ans<0
if pos:
#正の数があるとき
ok = True
else:
#全部負-> Kが奇数なら負にならざるをえない。
ok = (K % 2 == 0)
ans = 1
if ok:
# ans >= 0
if K % 2 == 1:
#Kが奇数の場合初めに1つ正の数を掛けておく
#こうすれば後に非負でも負でも2つずつのペアで
#考えられる
ans = ans * pos.pop() % MOD
# 答えは非負になる→二つの数の積は必ず非負になる.
cand = []
while len(pos) >= 2:
x = pos.pop() * pos.pop()
cand.append(x)
while len(neg) >= 2:
x = neg.pop() * neg.pop()
cand.append(x)
cand.sort(reverse=True) # ペアの積が格納されているので必ず非負
# ペア毎に掛けていく
for i in range(K // 2):
ans = ans * cand[i] % MOD
else:
# ans <= 0
cand = sorted(X, key=lambda x: abs(x))
for i in range(K):
ans = ans * cand[i] % MOD
print(ans)
|
import sys
In=sys.stdin.readline
print(int(In())**2)
| 0 | null | 77,669,237,075,038 | 112 | 278 |
from _collections import deque
from _ast import Num
def parser():
while 1:
data = list(input().split(' '))
for number in data:
if len(number) > 0:
yield (number)
input_parser = parser()
def gw():
global input_parser
return next(input_parser)
def gi():
data = gw()
return int(data)
MOD = int(1e9 + 7)
import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc145/tasks/abc145_e
# E - All-you-can-eat
"""
DP1[i][j] =the maximum sum of deliciousness of dishes, which are chosen from 1st- to i-th dishes,
such that he can finish them in j minutes
still WA!!!
"""
t1 = gi()
t2 = gi()
a1 = gi()
a2 = gi()
b1 = gi()
b2 = gi()
if a1 < b1:
a1, b1 = b1, a1
a2, b2 = b2, a2
#print(a1, a2, b1, b2)
d1 = (a1 - b1) * t1
d2 = (a2 - b2) * t2
net = d1 + d2
def run():
if d1 == 0 or net == 0:
print('infinity')
return
elif net > 0:
print(0)
return
d = abs(net)
ans = 0
p2 = (d1 // d)
if (d1 % d == 0):
ans = 2 * p2
else:
ans = 2 * p2 + 1
print(ans)
run()
|
print(int(input()=="0"))
| 0 | null | 67,128,472,016,192 | 269 | 76 |
#!usr/bin/env python3
import sys
import copy
def main():
n = int(sys.stdin.readline())
separator = '####################'
room, floor = 10, 3;
building1 = [[0 for col in range(room)] for row in range(floor)]
building2 = copy.deepcopy(building1)
building3 = copy.deepcopy(building1)
building4 = copy.deepcopy(building1)
buildings = {1 : building1,
2 : building2,
3 : building3,
4 : building4
}
for i in range(n):
lst = [int(num) for num in sys.stdin.readline().split()]
buildings[lst[0]][lst[1]-1][lst[2]-1] += lst[3]
for idx, (key, value) in enumerate(buildings.items()):
for floor in value:
print(' %s %s %s %s %s %s %s %s %s %s' % tuple(floor))
if idx < 3:
print(separator)
if __name__ == '__main__':
main()
|
x = int(input())
ans, r = divmod(x, 500)
ans *= 1000
ans += (r//5)*5
print(ans)
| 0 | null | 21,848,095,782,980 | 55 | 185 |
import itertools
n = int(input())
d = list(map(int,input().split()))
ans = 0
for v in itertools.combinations(d, 2):
ans += v[0]*v[1]
print(ans)
|
import itertools
N = int(input())
D = [int(x) for x in input().split()]
ans = 0
for v in itertools.combinations(D,2):
ans += v[0]*v[1]
print(ans)
| 1 | 168,533,491,620,280 | null | 292 | 292 |
import itertools
##print(ord("A"))
a,b,= map(int,input().split())
ans= a-b*2
if ans <=0:
print(0)
else:
print(ans)
|
a,b = [int(x) for x in input().split()]
print(max(0,a-2*b))
| 1 | 166,826,770,940,050 | null | 291 | 291 |
import math
while True:
n = int(input());
if n == 0:
break;
A = list(map(int, input().split()));
h = sum(A) / len(A);
k = 0;
for j in range(0,n):
k += (A[j] - h)**2;
print(math.sqrt(k/n));
|
from collections import defaultdict
N=int(input())
S=input()
d = defaultdict(list)
for i in range(N):
d[int(S[i])].append(i)
ans = 0
for n1 in range(10):
if not d[n1]:continue
for n2 in range(10):
if not d[n2]:continue
if d[n1][0]>d[n2][-1]: continue
for n3 in range(10):
if not d[n3]:continue
if d[n1][0]>d[n3][-1] or d[n2][0]>d[n3][-1]:continue
for idx in d[n2]:
if idx>d[n1][0] and idx<d[n3][-1]:
ans += 1
break
print(ans)
| 0 | null | 64,386,083,397,522 | 31 | 267 |
n = int(input())
a = list(map(int, input().split()))
a = a + [0]
state = a[0]
money = 1000
stock = 0
for i in range(1, n+1):
if state < a[i] and stock == 0:
stock += (money // state)
money %= state
elif state > a[i] and stock > 0:
money += (stock * state)
stock = 0
state = a[i]
print(money)
|
# 7
# 100 130 130 130 115 115 150
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
m = 1000
kabu = 0
buy = True
buy_val = 100000
for i in range(len(a)):
if i == len(a)-1:
m += kabu * a[i]
kabu = 0
elif not buy and a[i] > a[i+1]:
m += kabu * a[i]
kabu=0
buy=True
elif buy and a[i] < a[i+1]:
kabu=int(m/a[i])
m -= kabu * a[i]
buy=False
print(m)
| 1 | 7,405,338,431,518 | null | 103 | 103 |
n = int(input())
d = list(map(int, input().split()))
ans = float('inf')
fh = 0
lh = sum(d)
for i in range(0,n):
fh += d[i]
lh -= d[i]
ans = min(abs(fh - lh), ans)
print(ans)
|
N = int(input())
arr = list(map(int, input().split()))
first = 0
second = sum(arr)
min_delta = second - first
for i in range(N):
first += arr[i]
second -= arr[i]
min_delta = min(abs(second - first), min_delta)
print(min_delta)
| 1 | 142,024,056,514,302 | null | 276 | 276 |
mod=998244353
n,s=map(int,input().split())
ar=list(map(int,input().split()))
dp=[0 for y in range(s+1)]
dp[0]=1
for i in range(n):
for j in range(s,-1,-1):
if j+ar[i]<=s:
dp[j+ar[i]]=(dp[j]+dp[j+ar[i]])%mod
dp[j]=(dp[j]*2)%mod
print(dp[s])
|
#!python3
LI = lambda: list(map(int, input().split()))
# input
N, S = LI()
A = LI()
MOD = 998244353
def main():
dp = [0] * (S + 1)
dp[0] = 1
for i in range(N):
dp, l = [0] * (S + 1), dp
for j in range(S + 1):
dp[j] = (dp[j] + 2 * l[j]) % MOD
if A[i] + j <= S:
dp[A[i] + j] = (dp[A[i] + j] + l[j]) % MOD
ans = dp[-1]
print(ans)
if __name__ == "__main__":
main()
| 1 | 17,780,662,952,800 | null | 138 | 138 |
from copy import deepcopy
N, M, X = [int(i) for i in input().split()]
CAS = [[int(i) for i in input().split()] for _ in range(N)]
ok = False
mi = [float('inf'), *[0]*(M)]
for i in range(2**N):
t = [0]*(M+1)
for j in range(N):
if (i >> j) & 1:
t = [a+b for a, b in zip(CAS[j], t)]
if all(a >= X for a in t[1:]) and mi[0] > t[0]:
mi = t
ok = True
if ok:
print(mi[0])
else:
print(-1)
|
H=int(input())
W=int(input())
N=int(input())
K=H
if K<W: K=W
sum = 0
ans= 0
for i in range(1,K+1):
if sum < N:
sum += K
ans = i
#print(ans, K)
print(ans)
| 0 | null | 55,775,557,258,570 | 149 | 236 |
import math
from math import cos, sin, pi
class Point:
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def koch(n,a,b):
if n == 0:
return 0
th = pi * 60.0 / 180.0
s, t, u = Point(0.0, 0.0), Point(0.0, 0.0), Point(0.0, 0.0)
s.x = (2.0 * a.x + 1.0 * b.x) / 3.0
s.y = (2.0 * a.y + 1.0 * b.y) / 3.0
t.x = (1.0 * a.x + 2.0 * b.x) / 3.0
t.y = (1.0 * a.y + 2.0 * b.y) / 3.0
u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x
u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y
koch(n - 1, a, s)
print(f'{s.x:,.8f} {s.y:,.8f}')
koch(n - 1, s, u)
print(f'{u.x:,.8f} {u.y:,.8f}')
koch(n - 1, u, t)
print(f'{t.x:,.8f} {t.y:,.8f}')
koch(n - 1, t, b)
a = Point(0.0, 0.0)
b = Point(100.0, 0.0)
n = int(input())
print(f'{a.x:,.8f} {a.y:,.8f}')
koch(n,a,b)
print(f'{b.x:,.8f} {b.y:,.8f}')
|
import math
cos60=math.cos(math.radians(60))
sin60=math.sin(math.radians(60))
def koch(d,p1_x,p2_x,p1_y,p2_y):
if d==0:
return
s_x=(2*p1_x+1*p2_x)/3
s_y=(2*p1_y+1*p2_y)/3
t_x=(1*p1_x+2*p2_x)/3
t_y=(1*p1_y+2*p2_y)/3
u_x=(t_x-s_x)*cos60-(t_y-s_y)*sin60+s_x
u_y=(t_x-s_x)*sin60+(t_y-s_y)*cos60+s_y
koch(d-1,p1_x,s_x,p1_y,s_y)
print(s_x,s_y)
koch(d-1,s_x,u_x,s_y,u_y)
print(u_x,u_y)
koch(d-1,u_x,t_x,u_y,t_y)
print(t_x,t_y)
koch(d-1,t_x,p2_x,t_y,p2_y)
d=int(input())
p1_y=0
p1_x=0
p2_x=100
p2_y=0
print(float(p1_x),float(p1_y))
koch(d,p1_x,p2_x,p1_y,p2_y)
print(float(p2_x),float(p2_y))
| 1 | 130,175,951,920 | null | 27 | 27 |
s=input()
if s.count('A') and s.count('B'): print('Yes')
else: print('No')
|
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline().strip()
h, w = [int(x) for x in input().split()]
g = [input() for _ in range(h)]
ans = 0
for si in range(h):
for sj in range(w):
if g[si][sj] != '#':
d = [[-1 for j in range(w)] for i in range(h)]
d[si][sj] = 0
q = [(si, sj)]
for i, j in q:
ans = max(ans, d[i][j])
for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
ni, nj = i + di, j + dj
if 0 <= ni < h and 0 <= nj < w and g[ni][nj] != '#' and d[ni][nj] == -1:
d[ni][nj] = d[i][j] + 1
q.append((ni, nj))
print(ans)
| 0 | null | 74,650,894,097,792 | 201 | 241 |
#ARC162 C:Sum of gcd of Tuples(Easy)
import math
import numpy as np
import itertools
k = int(input())
ans = 0
if k == 1:
ans = 1
else:
for i in range(1,k+1):
for j in range(1,k+1):
a = math.gcd(i,j)
for k in range(1,k+1):
b = math.gcd(a,k)
ans += b
print(ans)
|
n,m=map(int,input().split());print('YNeos'[n!=m::2])
| 0 | null | 59,279,596,228,538 | 174 | 231 |
from itertools import combinations
input()
d = list(map(int,input().split()))
comb = combinations(d,2)
dsum = 0
for a,b in comb:
dsum += a*b
print(dsum)
|
a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
tmp = 0
if c < b:
tmp = b
b = c
c = tmp
if b < a:
tmp = a
a = b
b = tmp
if c < b:
tmp = b
b = c
c = tmp
print (str(a) + " " + str(b) + " " + str(c))
| 0 | null | 84,146,843,038,208 | 292 | 40 |
import collections
import sys
sys.setrecursionlimit(10 ** 8)
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]
class edge:
def __init__(self, to, id): self.to, self.id = to, id
def main():
N = Z()
col = [0] * (N-1)
G = collections.defaultdict(list)
for i in range(N-1):
a, b = ZZ()
G[a].append(edge(b, i))
G[b].append(edge(a, i))
numCol = 0
for i in range(1, N+1): numCol = max(numCol, len(G[i]))
def dfs(v):
colSet = set()
for ed in G[v]:
if col[ed.id] != 0: colSet.add(col[ed.id])
c = 1
for ed in G[v]:
if col[ed.id] != 0: continue
while c in colSet: c += 1
col[ed.id] = c
c += 1
dfs(ed.to)
dfs(1)
print(numCol)
for i in range(N-1): print(col[i])
return
if __name__ == '__main__':
main()
|
N, K, C = map(int, input().split())
S = input()
def get_positions():
res = []
i = 0
while i < N and len(res) < K:
if S[i] == "o":
res.append(i)
i = i + C + 1
else:
i += 1
return res
l = get_positions()
S = S[::-1]
r = get_positions()
for i in range(K):
r[i] = N - 1 - r[i]
S = S[::-1]
lastl = [-1] * (N + 1)
for i in range(K):
lastl[l[i] + 1] = i
for i in range(N):
if lastl[i + 1] == -1:
lastl[i + 1] = lastl[i]
lastr = [-1] * (N + 1)
for i in range(K):
lastr[r[i]] = i
for i in range(N-1, -1, -1):
if lastr[i] == -1:
lastr[i] = lastr[i + 1]
for i in range(N):
if S[i] == "x":
continue
li = lastl[i]
ri = lastr[i + 1]
cnt = 0
if li != -1:
cnt += (li + 1)
if ri != -1:
cnt += (ri + 1)
if li != -1 and ri != -1 and r[ri] - l[li] <= C:
cnt -= 1
if cnt >= K:
continue
print(i + 1)
| 0 | null | 88,013,924,920,028 | 272 | 182 |
N = int(input())
a = list(map(int,input().split()))
sum = 0
for i in a:
sum = i^sum
for i in a:
print(sum^i,end=' ')
|
n = int(input())
a = list(map(int, input().split()))
x = 0
for ai in a:
x ^= ai
for ai in a:
print(x ^ ai, end=' ')
| 1 | 12,571,088,832,740 | null | 123 | 123 |
a, b, c = list(map(int, input().split()))
if a == b == c:
print('No')
elif a == b:
print('Yes')
elif b == c:
print('Yes')
elif a == c:
print('Yes')
else:
print('No')
|
from collections import Counter
abc = Counter(input().split())
if len(abc) == 2:
print('Yes')
else:
print('No')
| 1 | 67,876,675,654,580 | null | 216 | 216 |
n, a, b = map(int, input().split())
print((b-a)//2 + min(a-1,n-b) + 1 if (b-a)%2 else (b-a)//2)
|
N, A, B = map(int, input().split())
distance = abs(A - B)
if distance % 2 == 1:
print(min(A - 1, N - B) + 1 + (distance - 1) // 2)
else:
print(distance // 2)
| 1 | 109,744,279,376,000 | null | 253 | 253 |
def main():
A, B, C = map(int, input().split())
K = int(input())
while B <= A:
B *= 2
K -= 1
while C <= B:
C *= 2
K -= 1
if K >= 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
a, b, c = map(int,input().split())
k = int(input())
cunt = 0
while a >= b:
b *= 2
cunt += 1
while b >= c:
c *= 2
cunt += 1
if cunt > k:
print("No")
else:
print("Yes")
if __name__=='__main__':
main()
| 1 | 6,905,281,569,252 | null | 101 | 101 |
import sys
import collections
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
n = int(input())
#b , c = tin()
#s = input()
al = lin()
aal=[i-v for i,v in enumerate(al)]
ccl = collections.Counter(aal)
ret = 0
for i, v in enumerate(al):
ccl[i-v] -= 1
if i+v in ccl:
ret += ccl[i+v]
print(ret)
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
|
n = int(input())
base = [mark + str(rank) for mark in ["S ", "H ", "C ", "D "] for rank in range(1,14)]
for card in [input() for i in range(n)]:
base.remove(card)
for elem in base:
print(elem)
| 0 | null | 13,522,414,574,734 | 157 | 54 |
import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(")
|
S = input()
if S[2] == S[3] and S[4] == S[5]:
print('Yes')
else:
print('No')
| 0 | null | 83,440,152,825,636 | 265 | 184 |
N,K=map(int,input().split())
P=list(map(int,input().split()))
from itertools import accumulate
acc=[0]+list(accumulate(P))
print((max(b-a for a,b in zip(acc,acc[K:]))+K)/2)
|
import sys
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v==w or w>v:
print('NO')
sys.exit()
else:
tp=(b-a)/(v-w)
tm=(a-b)/(v-w)
if b>a:
if t>=tp:
print('YES')
else:
print('NO')
else:
if t>=tm:
print('YES')
else:
print('NO')
| 0 | null | 44,823,760,933,732 | 223 | 131 |
a= list(map(int,input().split()))
n=a[0]
m=a[1]
if n==m:
print("Yes")
else:
print("No")
|
n, m = map(int, input().split())
print('Yes' if m >= n else 'No')
| 1 | 83,340,102,199,090 | null | 231 | 231 |
N = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 + 7
ans = 1
lst = [0] * 3
for aa in a:
cnt = 0
j = -1
for i, l in enumerate(lst):
if l == aa:
cnt += 1
j = i
if j == -1:
ans = 0
break
ans *= cnt
ans %= MOD
lst[j] += 1
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
m = 1000000007
result = 1
t = [0, 0, 0]
for i in range(N):
a = A[i]
f = -1
k = 0
for j in range(3):
if t[j] == a:
k += 1
if f == -1:
t[j] += 1
f = j
result *= k
result %= m
print(result)
| 1 | 130,235,291,921,802 | null | 268 | 268 |
X = int(input())
n = X % 100
m = X // 100
cnt = 0
for a in reversed(range(1, 6)):
while n - a >= 0:
n -= a
cnt += 1
if cnt <= m:
print(1)
else:
print(0)
|
def main():
N = input()
L = len(N)
K = int(input())
dp = [[0 for _ in range(L + 1)] for _ in range(K + 1)]
dpp = [[0 for _ in range(L + 1)] for _ in range(K + 1)]
dpp[0][0] = 1
for i in range(1, L + 1):
n = int(N[i - 1])
for k in range(K + 1):
# from dpp
kk = k + (1 if n > 0 else 0)
if kk <= K:
dpp[kk][i] = dpp[k][i - 1]
if n > 0:
dp[k][i] += dpp[k][i - 1]
if k + 1 <= K:
dp[k + 1][i] += (n - 1) * dpp[k][i - 1]
# from dp
dp[k][i] += dp[k][i - 1]
if k + 1 <= K:
dp[k + 1][i] += 9 * dp[k][i - 1]
print(dp[K][L] + dpp[K][L])
if __name__ == '__main__':
main()
| 0 | null | 101,134,525,625,402 | 266 | 224 |
N = int(input())
from math import sin, cos, pi
th = pi/3
def koch(d, p1, p2):
if d == 0:
return
s = [0, 0]
t = [0, 0]
u = [0, 0]
s[0] = (2 * p1[0] + p2[0])/3
s[1] = (2 * p1[1] + p2[1])/3
t[0] = (2 * p2[0] + p1[0])/3
t[1] = (2 * p2[1] + p1[1])/3
u[0] = (t[0] - s[0]) * cos(th) - (t[1] - s[1]) * sin(th) + s[0]
u[1] = (t[0] - s[0]) * sin(th) + (t[1] - s[1]) * cos(th) + s[1]
koch(d-1, p1, s)
print(*s)
koch(d-1, s, u)
print(*u)
koch(d-1, u, t)
print(*t)
koch(d-1, t, p2)
p_start = [0.0, 0.0]
p_end = [100.0, 0.0]
print(*p_start)
koch(N, p_start, p_end)
print(*p_end)
|
import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
S = rl().rstrip()
print(S[:3])
if __name__ == '__main__':
solve()
| 0 | null | 7,392,900,248,968 | 27 | 130 |
a = int(input())
if a == 1:
print(3)
else:
print(int((a**3-1)*a/(a-1)))
|
import math
a = int(input())
print(a + a ** 2 + a ** 3)
| 1 | 10,186,031,889,660 | null | 115 | 115 |
N, K = map(int, input().split())
ans = 0
for height in map(int, input().split()):
if height >= K:
ans += 1
print(ans)
|
N=int(input())
flag=0
for i in range(1,10):
for j in range(1,10):
if N==i*j:
flag+=1
if flag==0:
print('No')
else:
print('Yes')
| 0 | null | 169,662,672,040,480 | 298 | 287 |
# Aizu Problem 0000: QQ
#
import sys, math, os
# read input:
#PYDEV = os.environ.get('PYDEV')
#if PYDEV=="True":
# sys.stdin = open("sample-input2.txt", "rt")
for i in range(1, 10):
for j in range(1, 10):
print("%dx%d=%d" % (i, j, i*j))
|
import queue
N = int(input())
ab = []
deg = [0 for i in range(N)]
child = [[] for _ in range(N)]
edge = {}
color = [0 for _ in range(N-1)]
for i in range(N-1):
tmp = list(map(int, input().split()))
deg[tmp[0]-1] += 1
deg[tmp[1]-1] += 1
child[tmp[0]-1].append(tmp[1]-1)
child[tmp[1]-1].append(tmp[0]-1)
tmp = [tmp[0]-1, tmp[1]-1]
edge[tuple(tmp)] = i
q = queue.Queue()
q.put([None, 0, None])
used = [0]
# parent, self, color
while not q.empty():
current = q.get()
if current[0] is not None:
cnt = 1
for c in child[current[1]]:
# if c in used:
# continue
used.append(c)
if cnt == current[2]:
cnt += 1
q.put([current[1], c, cnt])
ind = [current[1], c] if current[1] < c else [c, current[1]]
color[edge[tuple(ind)]] = cnt
child[c].remove(current[1])
cnt += 1
else:
for i, c in enumerate(child[current[1]]):
used.append(c)
q.put([current[1], c, i+1])
ind = [current[1], c] if current[1] < c else [c, current[1]]
#print(edge[tuple(ind)], i+1)
color[edge[tuple(ind)]] = i+1
child[c].remove(current[1])
print(max(deg))
for c in color:
print(c)
| 0 | null | 67,907,326,211,380 | 1 | 272 |
N,A,B=map(int,input().split())
if (B-A)%2==0:
ans =(B-A)//2
else:
if A-1 > N-B:
ans = N-B+1
A+=ans
ans+=(N-A)//2
else:
ans =A
B-=ans
ans+=(B-1)//2
print(ans)
|
A,B= map(int,input().split())
res = A*B
print(res)
| 0 | null | 62,909,173,712,590 | 253 | 133 |
N,M=map(int,input().split())
ans=0
if N>1:
ans += N*(N-1)//2
else:
pass
if M>1:
ans += M*(M-1)//2
else:
pass
print(ans)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, M = map(int, readline().split())
ans = (N + M) * (N + M - 1) // 2 - N * M
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 45,347,204,379,174 | null | 189 | 189 |
def fibonum():
global F
F[0]=1
F[1]=1
for i in xrange(2,n+1):
F[i]=F[i-1]+F[i-2]
return F[n]
n=input()
F=[0]*(n+1)
num=fibonum()
print(num)
|
def fibonacci(n):
if n == 0 or n == 1:
F[n] = 1
return F[n]
if F[n] is not None:
return F[n]
F[n] = fibonacci(n - 1) + fibonacci(n - 2)
return F[n]
n = int(input())
F = [None]*(n + 1)
print(fibonacci(n))
| 1 | 1,627,967,990 | null | 7 | 7 |
s=int(input())
p=10**9+7
if s<=2:
print(0)
exit()
n=s//3
ans=0
x=[0]*(s+1)
x[0]=1
x[1]=1
y=[0]*(s+1)
for i in range(2,s+1):
x[i]=x[i-1]*i%p
y[s]=pow(x[s],p-2,p)
for i in range(s):
y[s-1-i]=y[s-i]*(s-i)%p
for k in range(1,n+1):
ans+=x[s-2*k-1]*y[k-1]*y[s-3*k]%p
print(ans%p)
|
s = int(input())
mod = 10**9 + 7
dp = [0 for i in range(s+1)]
dp[0] = 1
for cp in range(1, s+1):
dp[cp] = sum(dp[0:max(cp-2, 0)]) % mod
print(dp[s])
| 1 | 3,263,584,217,698 | null | 79 | 79 |
'''
ITP-1_6-B
????¶???????????????????????????????
???????????±?????¨?????????????????????????????????????????¨????????¨?????????52?????????????????????????????? n ???????????????????????????????????????????????????????????? n ????????????????????\?????¨??????????¶??????????????????????????????????????????°?????????????????????????????????
???????????????????????£?????????????????????????????§??????????????????52?????????????????§??????
52??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????13??????????????????????????????
???Input
?????????????????????????????£??????????????????????????° n (n ??? 52)????????????????????????
?¶??????? n ??????????????????????????????????????????????????????????????????????????????????????§???????????????????????¨??´??°??§??????
????????????????????????????????¨?????????????????????'S'???????????????'H'???????????????'C'???????????????'D'??§??¨?????????????????????
??´??°??????????????????????????????(1 ??? 13)?????¨??????????????????
???Output
?¶??????????????????????????????????1???????????????????????????????????????????????\?????¨????§?????????????????????§???????????????????????¨??´??°??§?????????????????????????????????????????\????????¨????????¨????????????
???????????????????????????????????????????????????????????????????????§???????????????????????????
????????????????????´??????????????????????°????????????????????????????
'''
# import
# ?????°??????????????????
trumpData = {
"S": list(range(1,14)),
"H": list(range(1,14)),
"C": list(range(1,14)),
"D": list(range(1,14)),
}
taroCard = int(input())
# ??????????????§??????????????????????????????????????????
for nc in range(taroCard):
(trumpDataLostMark, trumpDataLostCnt) = input().split()
index = trumpData[trumpDataLostMark].index(int(trumpDataLostCnt))
del trumpData[trumpDataLostMark][index]
# ????¶???????????????????????????????
for trumpDataMark in ['S', 'H', 'C', 'D']:
for trumpDataCnt in trumpData[trumpDataMark]:
# Output
print(trumpDataMark, trumpDataCnt)
|
N = int(input())
a = 0
k = 2*(N-2)+1
for i in range(2,N):
for j in range(i,N):
if (i*j<N)and(i!=j):
a+=2
elif(i*j<N)and(i==j):
a+=1
else:
break
print(a+k)
| 0 | null | 1,821,680,377,832 | 54 | 73 |
turn = int(input())
tp, hp = 0, 0
for i in range(turn):
t, h = input().split()
if t == h:
tp += 1
hp += 1
elif t > h:
tp += 3
elif t < h:
hp += 3
print(tp, hp)
|
n = int(input())
tp = hp = 0
while n:
t, h = input().split()
if t > h:
tp += 3
elif t < h:
hp += 3
else:
tp += 1
hp += 1
n -= 1
print(tp, hp)
| 1 | 1,999,002,059,612 | null | 67 | 67 |
string = input()
a, b, c = map(int, (string.split(' ')))
if a < b & b < c :
print('Yes')
else:
print('No')
|
if __name__ == '__main__':
a, b, c = input().split()
a, b, c = int(a), int(b), int(c)
if a < b and b < c:
print("Yes")
else:
print("No")
| 1 | 393,362,862,510 | null | 39 | 39 |
arr = [int(x) for x in input().split()]
print( max( max(arr[0]*arr[2], arr[0]*arr[3]), max(arr[1]*arr[2], arr[1]*arr[3]) ))
|
def prod(int_list):
p = 1
for i in int_list:
p *= i
return p
int_ary = [int(s) for s in input().split(" ")]
print(prod(int_ary), 2 * sum(int_ary))
| 0 | null | 1,704,185,104,380 | 77 | 36 |
n, k = map(int, input().split())
ans = 0
a = []
for _ in range(n):
a.append(0)
for i in range(k):
d = int(input())
treat = list(map(int, input().split()))
for snuke in treat:
a[snuke-1] += 1
for j in range(n):
if a[j] == 0:
ans += 1
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
mon = 1000
kabu = 0
for i in range(N-1):
if A[i] <= A[i+1]:
kabu, mon = divmod(mon, A[i])
mon += kabu * A[i+1]
print(mon)
| 0 | null | 15,993,296,319,616 | 154 | 103 |
A, B, K = list(map(int, input().split()))
A -= K
if A < 0:
B += A
A = 0
if B < 0:
B = 0
print(A, B)
|
from itertools import combinations
N = int(input())
d = list(map(int, input().split()))
info = list(combinations(d, 2))
ans = 0
for x, y in info:
ans += x*y
print(ans)
| 0 | null | 136,383,729,653,060 | 249 | 292 |
import sys
input = sys.stdin.readline
def readstr():
return input().strip()
def readint():
return int(input())
def readnums():
return map(int, input().split())
def readstrs():
return input().split()
def main():
N = readint()
X = readstr()
s = sum(tuple(map(int, X)))
s1 = s + 1
s2 = s - 1 if s != 1 else 1
m1 = int(X, 2) % s1
m2 = int(X, 2) % s2
t1 = [1]
t2 = [1]
for i in range(N):
t1.append(t1[i] * 2 % s1)
t2.append(t2[i] * 2 % s2)
for i in range(N):
ans = 0
if X[i] == '0':
x = (m1 + t1[(N - i - 1)]) % s1
else:
if s == 1:
print(0)
continue
else:
x = (m2 - t2[(N - i - 1)]) % s2
d = sum(tuple(map(int, bin(x)[2:])))
ans += 1
while x:
x %= d
d = sum(tuple(map(int, bin(x)[2:])))
ans += 1
print(ans)
if __name__ == "__main__":
main()
|
while True:
s = sum([int(i) for i in list(input())])
if s:
print(s)
else:
break
| 0 | null | 4,866,745,261,910 | 107 | 62 |
import math
while True:
n = int(input());
if n == 0:
break;
A = list(map(int, input().split()));
h = sum(A) / len(A);
k = 0;
for j in range(0,n):
k += (A[j] - h)**2;
print(math.sqrt(k/n));
|
import statistics
def stddev(values):
""" calculate standard deviation
>>> s = stddev([70, 80, 100, 90, 20])
>>> print('{:.5f}'.format(s))
27.85678
>>> s = stddev([80, 80, 80])
>>> print('{:.5f}'.format(s))
0.00000
"""
return statistics.pstdev(values)
def run():
while True:
c = int(input()) # flake8: noqa
if c == 0:
break
values = [int(i) for i in input().split()]
print(stddev(values))
if __name__ == '__main__':
run()
| 1 | 187,157,259,640 | null | 31 | 31 |
num = int(input())
inVal = input().split()
sum = 0
result = []
for n in range(num):
result.append(int(inVal[n]))
sum = sum + int(inVal[n])
print(str(min(result)) + " " + str(max(result)) + " " + str(sum))
|
n,k = map(int,input().split())
h = list(map(int, input().split()))
if n <= k:
print(0)
exit()
h.sort()
print(sum(h[:n-k]))
| 0 | null | 39,825,906,131,662 | 48 | 227 |
M = 10 ** 9 + 7
# inverse
def calc_inverse(n, law):
if n == 1:
return 1
pre_r = law
pre_x = 0
pre_y = 1
cur_r = n
cur_x = 1
cur_y = 0
while True:
d = pre_r // cur_r
r = pre_r % cur_r
nxt_r = r
nxt_x = pre_x - d * cur_x
nxt_y = pre_y - d * cur_y
if nxt_r == 1:
ret = nxt_x
while ret < 0:
ret += law;
return ret;
elif nxt_r == 0:
return None
pre_r = cur_r;
pre_x = cur_x;
pre_y = cur_y;
cur_r = nxt_r;
cur_x = nxt_x;
cur_y = nxt_y;
facts = [1]
facts_i = [1]
def cache_facts(n, M):
f = 1
fi = 1
for i in range(1, n):
f = (f * i) % M
fi = (fi * calc_inverse(i, M)) % M
facts.append(f)
facts_i.append(fi)
def cached_C(a, b, M):
return facts[a] * facts_i[a - b] * facts_i[b] % M
K = int(input())
S = input().strip()
L = len(S)
cache_facts(K + L + 1, M)
total = pow(26, K, M)
#print(total)
for i in range(1, K + 1):
total = (total + (pow(25, i, M) * cached_C(L + i - 1, L - 1, M) % M) * pow(26, K - i, M)) % M
print(total)
|
# ABC 173 D
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ind=[(i+1)//2 for i in range(N-1)]
print(sum([A[i] for i in ind]))
| 0 | null | 11,024,180,319,308 | 124 | 111 |
if __name__ == '__main__':
A = []
for i in range(3):
row = list(map(int, input().split()))
A.append(row)
N = int(input())
B = []
for i in range(N):
B.append(int(input()))
for i in range(3):
cnt = 0
for j in range(3):
if A[i][j] in B:
cnt += 1
if cnt==3:
print('Yes')
quit()
for i in range(3):
cnt = 0
for j in range(3):
if A[j][i] in B:
cnt += 1
if cnt==3:
print('Yes')
quit()
if A[0][0] in B and A[1][1] in B and A[2][2] in B:
print('Yes')
quit()
if A[0][2] in B and A[1][1] in B and A[2][0] in B:
print('Yes')
quit()
print('No')
|
A = [0 for i in range(9)]
for i in range(3):
A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
N = int(input())
b = [0 for i in range(N)]
for i in range(N):
b[i] = int(input())
#Check matching numbers
for i in range(9):
for j in range(N):
if A[i] == b[j]:
A[i] = 0
# Check bingo or not
flag = 0
# Check rows
for i in [0, 3, 6]:
if A[i]==A[i+1] and A[i+1]==A[i+2]:
flag += 1
# Check colums
for j in range(3):
if A[j]==A[j+3] and A[j+3]==A[j+6]:
flag += 1
# Check naname?
if (A[0]==A[4] and A[4]==A[8]) or (A[2]==A[4] and A[4]==A[6]):
flag += 1
if flag >= 1:
print("Yes")
else:
print("No")
| 1 | 59,778,461,932,832 | null | 207 | 207 |
n = int(input())
a = list(map(int,input().split()))
even_list = []
for i in range(n):
if a[i] % 2 == 0:
even_list.append(a[i])
x = 0
for m in range(len(even_list)):
if even_list[m] % 3 == 0 or even_list[m] % 5 == 0:
x += 1
if x == len(even_list):
print('APPROVED')
else:
print('DENIED')
|
N,K = map(int,input().split())
a = sorted(list(map(int,input().split())),reverse=True)
del a[0:K]
print(sum(a))
| 0 | null | 73,888,843,189,008 | 217 | 227 |
n = int(input())
S = list(map(int, input(). split()))
q = int(input())
T = list(map(int, input(). split()))
Sum = 0
for i in T:
if i in S:
Sum += 1
print(Sum)
|
# encoding: utf-8
class Solution:
@staticmethod
def linear_search():
array_length_1 = int(input())
array_1 = [int(x) for x in input().split()]
array_length_2 = int(input())
array_2 = [int(x) for x in input().split()]
# print(len(set(array_1).intersection(set(array_2))))
count = 0
for i in range(array_length_2):
if array_2[i] in array_1:
count += 1
print(count)
if __name__ == '__main__':
solution = Solution()
solution.linear_search()
| 1 | 68,852,197,762 | null | 22 | 22 |
#!/usr/bin/env python3
import sys
# from scipy.special import comb
sys.setrecursionlimit(10**4)
from math import factorial
def comb(n, r):
'''
>>> comb(2, 1)
2
>>> comb(3, 2)
3
'''
if r == 0:
return 1
if n == 0 or r > n:
return 0
return factorial(n) // factorial(n - r) // factorial(r)
def f(S, i, k):
# ここに来るのは繰り下がりが発生していない状態...
if k == 0:
# 以降は0を選び続けるしかない
return 1
if len(S) <= i:
# 走破したのにK個使いきれていない
return 0
n = int(S[i])
if n == 0:
# 注目する桁が0の場合、0を選ぶしかない
return f(S, i+1, k)
# 注目する桁の数値nより小さい値を選べば、以降は繰り下げで選び放題
ret = (n - 1) * comb(len(S)-i-1, k-1) * pow(9, k-1)
ret += comb(len(S)-i-1, k) * pow(9, k)
# 注目する桁の数値nを選んだ場合、繰り下げができない状態が続行
ret += f(S, i+1, k-1)
return ret
def solve(S: str, K: int):
return f(S, 0, K)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = next(tokens) # type: str
K = int(next(tokens)) # type: int
print(solve(N, K))
def test():
import doctest
doctest.testmod()
if __name__ == '__main__':
test()
main()
|
n = input()
A = map(int, raw_input().split())
q = input()
m = map(int, raw_input().split())
def solve(i, m):
if m == 0:
return True
if i >= n or m > sum(A):
return False
res = solve(i+1, m) or solve(i+1, m-A[i])
return res
for j in range(0, q):
if solve(0, m[j]):
print 'yes'
else:
print 'no'
| 0 | null | 37,863,465,910,720 | 224 | 25 |
l = int(input())
x = l/3
print(x**3)
|
from itertools import accumulate
N, K = map(int, input().split())
P = list(map(int, input().split()))
A = list(accumulate(P))
largest = A[K-1]
point = 0
for i in range(K, N):
if largest < A[i] - A[i-K]:
largest = A[i] - A[i-K]
point = i
ans = 0
for j in range(point - K + 1, point+1):
p = P[j]
ans += (((p + 1) * p) / 2) / p
print(ans)
| 0 | null | 60,874,037,073,470 | 191 | 223 |
#!/usr/bin/env python
# coding: utf-8
# In[15]:
N = int(input())
# In[16]:
ans = 0
if N%2 != 0:
print(ans)
else:
i = 1
while 1:
tmp = (5**i)*2
if tmp <= N:
ans += N//tmp
i += 1
else:
break
print(ans)
# In[ ]:
|
import sys
n = int(input())
if n%2 == 1:
print(0)
sys.exit()
else:
cur_two, cur_ten = 2, 10
num_two, num_ten = 0, 0
while cur_two <= n:
num_two += n//cur_two
cur_two *= 2
while cur_ten <= n:
num_ten += n//cur_ten
cur_ten *= 5
print(min(num_two, num_ten))
| 1 | 116,038,873,703,338 | null | 258 | 258 |
def main():
alphabets_table = [0 for i in range(26)]
while True:
try:
input_string = input()
lower_string = input_string.lower()
for i, _letter in enumerate("abcdefghijklmnopqrstuvwxyz"):
alphabets_table[i] += lower_string.count(_letter)
except EOFError:
break
for i, _letter in enumerate("abcdefghijklmnopqrstuvwxyz"):
print('%s : %s' % (_letter, alphabets_table[i]))
main()
|
n = int(input())
a = list(map(int, input().split()))
tmp = 0
sum = 0
for i in a:
if tmp > i:
dif = tmp - i
sum += dif
else:
tmp = i
print(sum)
| 0 | null | 3,094,189,118,880 | 63 | 88 |
n, m = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n):
a[i] = list(map(int, input().split()))
b = [0] * m
for i in range(m):
b[i] = int(input())
for ai in a:
cnt = 0
for j, bj in enumerate(b):
cnt += ai[j] * bj
print(cnt)
|
def DFS(G):
ans = [0] + [[0,0,0] for _ in range(len(G))]
def main(G,i):
ans[0] += 1
ans[i] = [i, ans[0], ans[0]]
for j in sorted(G[i-1][2:]):
if ans[j][0] == 0: main(G,j)
ans[0] += 1
ans[i][2] = ans[0]
for u in G:
if ans[u[0]][0] == 0: main(G,u[0])
return ans[1:]
if __name__=='__main__':
n = int(input())
G = [list(map(int,input().split())) for _ in range(n)]
for out in DFS(G): print(*out)
| 0 | null | 590,106,861,332 | 56 | 8 |
#!/usr/bin/env python3
import sys
from functools import reduce
from operator import mul
MOD = 998244353 # type: int
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x) if isinstance(other, ModInt) else
ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x) if isinstance(other, ModInt) else
ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x) if isinstance(other, ModInt) else
ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
ModInt(other.x - self.x) if isinstance(other, ModInt) else
ModInt(other - self.x)
)
__rmul__ = __mul__
def __rtruediv__(self, other):
return (
ModInt(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(other, self.x, MOD))
)
def combinations_count(n, r):
r = min(r, n - r)
numer = reduce(mul, range(n, n - r, -1), 1)
denom = reduce(mul, range(1, r + 1), 1)
return numer // denom
def solve(N: int, M: int, K: int):
SUM = ModInt(0)
n_1Ck = [ModInt(1) for k in range(K + 1)]
for i in range(1, K + 1):
n_1Ck[i] = n_1Ck[i-1] * (N-i) / i
for k in range(0, K + 1):
SUM += M * n_1Ck[k] * (pow(M - 1, N - 1 - k, MOD))
print(SUM)
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()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
solve(N, M, K)
if __name__ == '__main__':
main()
|
N, M, K = map(int, input().split())
ans = 0
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 998244353
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
for i in range(K+1):
res_i = (M * pow(M-1, N-i-1, p)) % p
res_i = (res_i * cmb(N-1, i, p)) % p
ans = (ans + res_i) % p
print(ans)
| 1 | 23,207,615,522,442 | null | 151 | 151 |
S = input()
if S[-1] != 's':
S = S + 's'
elif S[-1] == 's':
S = S + 'es'
print(S)
|
import numpy as np
import sys
i4 = np.int32
i8 = np.int64
u4 = np.uint32
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
from numba import njit
from numba.types import int64, Array, uint32
cc = CC('my_module')
@cc.export('factorization', (uint32, ))
@njit
def factorization(N):
p = np.zeros(N + 1, u4)
n_max = int(np.sqrt(N)) + 1
p[0] = 1
p[1] = 1
for i in range(2, n_max):
if p[i] == 0:
j = i
while j <= N:
p[j] = i
j += i
for i in range(n_max, N + 1):
if p[i] == 0:
p[i] = i
return p
@cc.export('solve', (Array(uint32, 1, 'C'),))
def solve(A):
a = np.sort(A)
p_max = a[-1]
p = factorization(p_max)
primes_num = 0
for i in range(p.shape[0]):
if i == p[i]:
primes_num += 1
a_start = 0
while a[a_start] == 1:
a_start += 1
if a_start == a.shape[0]:
return 0
a = a[a_start:]
if len(a) > primes_num:
return 1
check = np.zeros(p_max + 1, u4)
stack = np.empty(20, u4)
p_stack = 0
for d in a:
while d > 1:
x = p[d]
for i in range(p_stack):
if stack[i] == x:
break
else:
stack[p_stack] = x
p_stack += 1
d //= x
while p_stack > 0:
p_stack -= 1
check[stack[p_stack]] += 1
if check.max() > 1:
return 1
else:
return 0
cc.compile()
from my_module import solve, factorization
exit()
from my_module import solve, factorization
def main(in_file):
stdin = open(in_file)
stdin.readline()
A = np.fromstring(stdin.readline(), u4, sep=' ')
ans = solve(A)
if ans:
g = np.gcd.reduce(A)
if g > 1:
ans = 2
else:
ans = 1
p = ['pairwise coprime', 'setwise coprime', 'not coprime']
print(p[ans])
if __name__ == '__main__':
main('/dev/stdin')
| 0 | null | 3,267,923,377,728 | 71 | 85 |
from collections import defaultdict
import math
def ggg(a, b):
"""規約分数を作る。n/0, 0/n は n=1,-1 にして返す。"""
if a == b == 0:
return 0, 0
denominator = math.gcd(a, b)
x, y = a // denominator, b // denominator
return x, y
def main():
n = int(input())
mod = 1000000007
zeroes = 0
counter = defaultdict(lambda: defaultdict(int))
for _ in range(n):
a, b = [int(x) for x in input().split()]
x, y = ggg(a, b)
if x == y == 0:
zeroes += 1
continue
if y < 0:
# quadrant III, IV -> I, II
x, y = -x, -y
if x <= 0:
# round 90° from quadrant II to I
x, y = y, -x
counter[(x, y)][1] += 1
else:
counter[(x, y)][0] += 1
ans = 1
for v in counter.values():
now = 1
now += pow(2, v[0], mod) - 1
now += pow(2, v[1], mod) - 1
ans = ans * now % mod
ans += zeroes
ans -= 1 # choose no fish
return ans % mod
if __name__ == '__main__':
print(main())
|
from math import gcd
N = int(input())
mod = 10 ** 9 + 7 # 1000000007
d = dict()
zeros = 0
for _ in range(N):
a, b = map(int, input().split()) # Ai, Bi
# どちらか一方でも0であれば特殊なケースとなる
# 下記のd[p]でd[(0, 0)]のような形になるため分ける(zeros)
# d[(0, 0)]同士では組み合わせが作れないため、単純に+1していく
if not any((a,b)):
zeros += 1
continue
if all((a, b)):
g = gcd(a, b) * (a//abs(a)) # //は切り捨て除算
elif a:
g = a
else:
g = b
p = a//g, b//g # p is (tuple)
d[p] = d.get(p, 0) + 1 # count
ans = 1 # 掛け算するため0ではなく1としておき、最後の出力時に1を引くようにする
done = set()
for (a,b), val in d.items():
if (-b, a) in done or (b, -a) in done: # if already counted, then continue
continue
done.add((a, b))
w = d.get((-b, a), 0) + d.get((b, -a), 0)
# (a, b)とそれに垂直な(-b, a), (b, -a)のそれぞれの組み合わせを足す
# そして何も選ばなかったときの場合を引くため、最後に-1とする
ans *= (pow(2, val) + pow(2, w) -1)
ans %= mod
print((ans + zeros -1) % mod)
| 1 | 20,945,215,698,400 | null | 146 | 146 |
def gotoS(org, n):
res = [0] * n
for i in range(1, n+1):
res[org[i-1]-1] = i
return res
n = int(input())
org = list(map(int, input().split()))
print(*gotoS(org, n))
|
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
# N = int(input())
S = input()
T = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()
# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)
# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)
# def dfs(tree, s):
# for l in tree[s]:
# if depth[l[0]] == -1:
# depth[l[0]] = depth[s] + l[1]
# dfs(tree, l[0])
# dfs(tree, 1)
# def factorization(n):
# arr = []
# temp = n
# for i in range(2, int(-(-n**0.5//1))+1):
# if temp%i==0:
# cnt=0
# while temp%i==0:
# cnt+=1
# temp //= i
# arr.append([i, cnt])
# if temp!=1:
# arr.append([temp, 1])
# if arr==[]:
# arr.append([n, 1])
# return arr
ma = 0
s = len(S)
t = len(T)
for i in range(s - t + 1):
cnt = 0
for j in range(t):
if S[i + j] == T[j]:
cnt += 1
if cnt > ma:
ma = cnt
print(t - ma)
| 0 | null | 92,591,608,894,510 | 299 | 82 |
def answer(n: int, s: str, t: str) -> str:
new_str = ''
for i in range(n):
new_str += f'{s[i]}{t[i]}'
return new_str
def main():
n = int(input())
s, t = input().split()
print(answer(n, s, t))
if __name__ == '__main__':
main()
|
T=input()
print(T.replace("?","D"))
| 0 | null | 65,373,975,463,302 | 255 | 140 |
N = int(input())
A = [int(x) for x in input().split()]
num_c = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if(i != minj):
A[i], A[minj] = A[minj], A[i]
num_c += 1
print((" ").join(str(x) for x in A))
print(num_c)
|
n = int(input())
a = [int(i) for i in input().split()]
counter = 0
for i in range(n):
minj = i
for j in range(i, n):
if a[j] < a[minj]:
minj = j
if minj != i:
a[i], a[minj] = a[minj], a[i]
counter += 1
print(*a)
print(counter)
| 1 | 20,908,538,628 | null | 15 | 15 |
# 161 B
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))
list.sort(A, reverse=True)
print('Yes') if A[M-1] >= (sum(A)/(4*M)) else print('No')
|
n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
table = [[0] * n for _ in [0] * 64]
table[0] = a
for i in range(61):
for j in range(n):
table[i + 1][j] = table[i][table[i][j]]
ans = 0
for i in range(61, -1, -1):
if k >> i & 1:
ans = table[i][ans]
print(ans + 1)
| 0 | null | 30,661,144,710,798 | 179 | 150 |
N = int(input())
A = list(map(int, input().split()))
max_a = max(A) + 1
counter = [0 for _ in range(max_a)]
for i in A:
for j in range(i, max_a, i):
counter[j] += 1
res = 0
for a in A:
if counter[a] == 1:
res += 1
#print(counter)
print(res)
|
r, c = map(int, input().split())
a, btm = [], []
for i in range(r):
a.append(list(map(int, input().split())))
a[i].append(sum(a[i]))
print(*a[i])
rotate = list(zip(*a))
for i in range(len(rotate)):
btm.append(sum(rotate[i]))
print(*btm)
| 0 | null | 7,828,074,669,240 | 129 | 59 |
ans_list=[]
while True:
try:
k=list(map(int,input().split(" ")))
ans_list.append(k[0]+k[1])
except:
for i in ans_list:
print(len(str(i)))
break
|
C = input()
i = ord(C)
print(chr(i+1))
| 0 | null | 45,936,591,472,896 | 3 | 239 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.