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
|
---|---|---|---|---|---|---|
n = int(input())
c = n-1
for i in range(1,int(n**0.5)+1):
if (n/i).is_integer():
j = n//i
c = min(c, i+j-2)
print(c)
|
n=int(input())
for i in range(int(n**0.5), 0, -1):
if n%i==0:
print(int(n/i+i-2))
exit()
| 1 | 161,120,061,945,220 | null | 288 | 288 |
s = input()
n = int(input())
for _ in range(n):
O = list(map(str, input().split()))
i = int(O[1])
j = int(O[2])
if O[0] == 'print':
print(s[i:j + 1])
elif O[0] == 'reverse':
ss = s[i:j + 1]
s = s[:i] + ss[::-1] + s[j + 1:]
else:
p = O[3]
s = s[:i] + p + s[j + 1:]
|
#coding: utf-8
#itp1_9d
def rev(s,a,b):
b=b+1
t=s[a:b]
u=t[::-1]
x=s[:a]
y=s[b:]
return x+u+y
def rep(s,a,b,w):
b=b+1
x=s[:a]
y=s[b:]
return x+w+y
s=raw_input()
n=int(raw_input())
for i in xrange(n):
d=raw_input().split()
a=int(d[1])
b=int(d[2])
if d[0]=="print":
print s[a:b+1]
elif d[0]=="reverse":
s=rev(s,a,b)
elif d[0]=="replace":
w=d[3]
s=rep(s,a,b,w)
| 1 | 2,111,583,270,470 | null | 68 | 68 |
import math
n=int(input())
m=((10**n)-(2*(9**n))+(8**n))%1000000007
print(m)
|
tmp = 10 ** 9 + 7
def div(n,T):
_ = 1
for t in range(T):
_ *= n
_ %= tmp
return _
N = int(input())
a = div(10,N)
b = div(9,N)
c = div(8,N)
print((a + c - 2 * b) % tmp)
| 1 | 3,162,098,388,398 | null | 78 | 78 |
def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(K, N):
if A[i-K] < A[i]:
print("Yes")
else:
print("No")
if '__main__' == __name__:
resolve()
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
if i < K:
continue
if A[i-K] < A[i]:
print('Yes')
else:
print('No')
| 1 | 7,093,982,666,970 | null | 102 | 102 |
"""
AtCoder :: Beginner Contest 175 :: C - Walking Takahashi
https://atcoder.jp/contests/abc175/tasks/abc175_c
"""
import sys
def solve(X, K, D):
"""Solve puzzle."""
# print('solve X', X, 'K', K, 'D', D)
if D == 0:
return X
X = abs(X)
soln = abs(X - (K * D))
steps_to_zero = abs(X) // D
# print('steps to zero', steps_to_zero, K - steps_to_zero)
# print('to zero', abs(X - (steps_to_zero * D)))
# Undershoot or get directly on to zero.
if steps_to_zero <= K and ((K - steps_to_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_to_zero * D)))
# Overshoot by one step
steps_past_zero = steps_to_zero + 1
# print('steps past zero', steps_past_zero, K - steps_past_zero)
# print('past zero', abs(X - (steps_past_zero * D)))
if steps_past_zero <= K and ((K - steps_past_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_past_zero * D)))
# Overshoot and return by one
steps_back_zero = steps_past_zero + 1
# print('steps back zero', steps_back_zero, K - steps_back_zero)
# print('back zero', abs(X - (steps_back_zero * D)))
if steps_back_zero <= K and ((K - steps_back_zero) % 2 == 0):
soln = min(soln, abs(X - (steps_back_zero * D)))
return soln
def main():
"""Main program."""
X, K, D = (int(i) for i in sys.stdin.readline().split())
print(solve(X, K, D))
if __name__ == '__main__':
main()
|
x, k, d = map(int, input().split())
if abs(x) // d >= k:
if x > 0:
print(x - k * d)
else:
print(abs(k * d + x))
exit()
div = abs(x) // d
k -= div
if x > 0:
x -= div * d
else:
x += div * d
if k % 2 == 0:
print(abs(x))
else:
print(abs(abs(x) - d))
| 1 | 5,195,427,815,750 | null | 92 | 92 |
#!/usr/bin/env python3
from sys import stdin
from collections import defaultdict
from math import gcd
def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))
def main():
MOD = 1000000007
N, *AB = map(int, stdin.buffer.read().split())
d = defaultdict(int)
zeros = 0
for a, b in zip(AB[::2], AB[1::2]):
if a == 0 and b == 0:
zeros += 1
else:
g = gcd(a, b)
a //= g
b //= g
if a < 0:
a *= -1
b *= -1
if a == 0 and b == -1:
b = 1
d[(a, b)] += 1
ans = 1
free = 0
for (a, b), n in d.items():
if b > 0:
if (b, -a) in d:
m = d[(b, -a)]
ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
else:
free += n
else:
if (-b, a) not in d:
free += n
ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)
if __name__ == '__main__':
main()
|
if __name__ == '__main__':
h,n = map(int,input().split())
A = list(map(int,input().split()))
sm = sum(A)
if h <= sm:
print("Yes")
else:
print("No")
| 0 | null | 49,444,714,611,540 | 146 | 226 |
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
zero = defaultdict(int)
one = defaultdict(int)
for a in A:
for i in range(61):
if a &(1<<i):
one[i] += 1
else:
zero[i] += 1
ans = 0
for i in range(61):
ans += pow(2,i,mod)*zero[i]*one[i]
ans %=mod
print(ans%mod)
|
from collections import deque
from math import ceil
n,d,a = map(int,input().split())
M = [list(map(int,input().split())) for i in range(n)]
M = sorted([(x,ceil(h/a)) for x,h in M])
que = deque()
ans = 0
atack = 0
for x,h in M:
while len(que) > 0 and que[0][0] < x:
tx,ta = que.popleft()
atack -= ta
bomb_num = max(0, h-atack)
atack += bomb_num
ans += bomb_num
if bomb_num > 0:
que.append([x+d*2,bomb_num])
print(ans)
| 0 | null | 102,730,585,941,390 | 263 | 230 |
s_list = input()
t_list = input()
n = len(s_list)
if s_list == t_list[:-1]:
print('Yes')
else:
print('No')
|
def main():
S = input()
T = input()
if S == T[:-1]:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 21,407,003,047,488 | null | 147 | 147 |
N = int(input())
def answer(N: int) -> str:
x = 0
for i in range(1, 10):
for j in range(1, 10):
if N == i * j:
x = 1
return 'Yes'
if x == 0:
return 'No'
print(answer(N))
|
def main():
N = int(input())
for i in range(1, 10):
if N // i < 10 and N % i == 0:
print('Yes')
return
print('No')
main()
| 1 | 159,247,100,530,738 | null | 287 | 287 |
def solve(sup,rest,digit,used1,used2):
if rest<0:
return 0
if digit==0:
if rest==0:
return 1
else:
return 0
sum=0
for i in range(1,sup+1):
if i!=used1 and i!=used2:
if used1==0:
sum+=solve(sup,rest-i,digit-1,i,used2)
elif used2==0:
sum+=solve(sup,rest-i,digit-1,used1,i)
else:
sum+=solve(sup,rest-i,digit-1,used1,used2)
return sum
N=[]
X=[]
while True:
n,x=map(int,raw_input().split())
if (n,x)==(0,0):
break
N.append(n)
X.append(x)
for i in range(len(N)):
print('%d'%(solve(N[i],X[i],3,0,0)/6))
|
K, N = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
max_dist = 0
for i in range(N):
nxt = (i + 1 ) % N
dist = A_ls[nxt] - A_ls[i]
if dist < 0:
dist += K
max_dist = max(max_dist, dist)
print(K - max_dist)
| 0 | null | 22,447,016,366,338 | 58 | 186 |
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
bunshi=1
bunbo=1
for i in range(r):
bunbo = bunbo*(i+1)%mod
bunshi = bunshi*(n-i)%mod
return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
n = I()
#graph[i]には頂点iと繋がっている頂点を格納する
graph = [[] for _ in range(n+1)]
prev_col = [0]*(n+1)
a_b = []
k=0
for i in range(n-1):
a,b = MI()
a_b.append(str(a)+" "+str(b))
graph[a].append(b)
graph[b].append(a)
#check[i] == -1ならば未探索
check = [-1]*(n+1)
check[0] = 0
check[1] = 0
for i in range(n+1):
k = max(len(graph[i]),k)
d = deque()
d.append(1)
ans = dict()
while d:
v = d.popleft()
check[v] = 1
cnt = 0
for i in graph[v]:
if check[i] != -1:
continue
cnt = cnt+1
if prev_col[v] == cnt:
cnt = cnt + 1
prev_col[i] = cnt
ans[str(min(i,v))+" "+str(max(i,v))]=cnt
d.append(i)
print(k)
for key in a_b:
print(ans[key])
|
N = int(input())
graph = [[] for _ in range(N+1)]
AB = []
for _ in range(N-1):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
AB.append((a, b))
root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
color = [-1] * (N+1)
K = -1
for x in order:
ng = color[x]
c = 1
for y in graph[x]:
if y == parent[x]:
continue
if c == ng:
c += 1
K = max(c, K)
color[y] = c
c += 1
ans = []
for a, b in AB:
if parent[a] == b:
ans.append(color[a])
else:
ans.append(color[b])
print(K)
for i in ans:
print(i)
| 1 | 135,724,793,578,066 | null | 272 | 272 |
S = input()
if S == 'MON':
print("6")
elif S == 'TUE':
print("5")
elif S == 'WED':
print("4")
elif S == 'THU':
print("3")
elif S == 'FRI':
print("2")
elif S == 'SAT':
print("1")
elif S == 'SUN':
print("7")
|
S = input()
DAY = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
for num in range(7):
if DAY[num] == S:
print(7-num)
| 1 | 132,791,380,233,788 | null | 270 | 270 |
N=int(input())
A=list(map(int,input().split()))
L={}
R={}
ans=0
for i in range(N):
if i+A[i] in L:
L[i+A[i]]+=1
else:
L[i+A[i]]=1
if A[i]<=i:
if i-A[i] in R:
R[i-A[i]]+=1
else:
R[i-A[i]]=1
for r in R:
if r in L:
ans+=L[r]*R[r]
print(ans)
|
# 解説
import sys
pin = sys.stdin.readline
pout = sys.stdout.write
perr = sys.stderr.write
N, M, K = map(int, pin().split())
A = list(map(int, pin().split()))
B = list(map(int, pin().split()))
a = [0]
b = [0]
for i in range(N):
a.append(a[i] + A[i])
for i in range(M):
b.append(b[i] + B[i])
ans = 0
for i in range(N + 1):
#Aの合計がKを超えるまで比較する
if a[i] > K:
break
# 超えていた場合に本の個数を減らす
while b[M] > K - a[i]:
M -= 1
ans = max(ans, M + i)
print(ans)
| 0 | null | 18,573,395,617,630 | 157 | 117 |
def is_prime(n):
if n == 2: return True
if n < 2 or n % 2 == 0: return False
return pow(2, n - 1, n) == 1
count = 0
for i in range(int(input())):
if is_prime(int(input())) : count += 1
print(count)
|
"""
方針:
幸福度が一定以上のつなぎ方の数→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))
| 0 | null | 53,749,340,142,740 | 12 | 252 |
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = 0
del_A = []
for i in range(N):
if(i==(N-1)):
del_A.append(A[0]+K-A[i])
else:
del_A.append(A[i+1]-A[i])
print(sum(del_A)-max(del_A))
|
n = int(input())
ab = []
for i in range(n-1):
a, b = map(int,input().split())
ab.append([a, b])
graph = [[] for _ in range(n+1)]
for a,b in ab:
graph[a].append(b)
graph[b].append(a)
root = 1
parent = [0] * (n+1)
order = []
stack = [root]
while stack:
x = stack.pop()
order.append(x)
for y in graph[x]:
if y == parent[x]:
continue
parent[y] = x
stack.append(y)
color = [-1] * (n+1)
for x in order:
ng = color[x]
c = 1
for y in graph[x]:
if y == parent[x]:
continue # 子に対応させる
if c == ng:
c += 1
color[y] = c
c += 1
print(max(color))
for a,b in ab:
if parent[a] == b:
print(color[a])
else:
print(color[b])
| 0 | null | 89,667,311,334,442 | 186 | 272 |
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
n, x, y = map(int, readline().split())
dists = [0 for _ in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(i - j), abs(x - i) + 1 + abs(y - j))
dists[d] += 1
for i in range(1, n):
print(dists[i])
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
H, M, h, m, K = map(int, read().split())
m -= M
h -= H
if m < 0:
m += 60
h -= 1
answer = h * 60 + m - K
print(answer)
| 0 | null | 31,055,972,454,780 | 187 | 139 |
A,B=map(int,input().split())
if A-2*B<0:
print(0)
exit(0)
print(A-2*B)
|
N = int(input()) % 10
if N in {2,4,5,7,9}:
print("hon")
elif N in {0,1,6,8}:
print("pon")
else:
print("bon")
| 0 | null | 92,477,656,526,948 | 291 | 142 |
n, k = map(int, input().split())
x = n % k
y = abs(x - k)
if x >= y:
print(y)
else:
print(x)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
v = N//K
print(min(N-v*K, K-(N-v*K)))
| 1 | 39,381,332,465,870 | null | 180 | 180 |
a,b,c,d=map(int,input().split())
X=[a,b]
Y=[c,d]
ans=-10**30
for x in X:
for y in Y:
if ans<x*y:
ans=x*y
print(ans)
|
k = int(input())
a, b = map(int, input().split())
if a <= k <= b or k <= b/2:
print('OK')
else:
print('NG')
| 0 | null | 14,720,400,847,748 | 77 | 158 |
import math
a,b = map(int,input().split())
if b>a:
a,b = b,a
l = (a*b)//(math.gcd(a,b))
print(l)
|
A,B = map(int,input().split(" "))
c = A-2*B
if c>0:
print(c)
else:
print(0)
| 0 | null | 140,177,836,986,108 | 256 | 291 |
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = list()
A.append("")
A.extend(A1)
A.extend(A2)
A.extend(A3)
n = int(input())
B = list()
for _ in range(n):
B.append(int(input()))
holes = [A.index(b) for b in B if (b in A)]
bingos = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
print("Yes" if any([(len(set(holes) & set(bingo)) == 3) for bingo in bingos]) else "No")
|
H,W,K = list(map(int, input().split()))
table = [input() for _ in range(H)]
ans = 0
for mask_h in range(2 ** H):
for mask_w in range(2 ** W):
black = 0
for i in range(H):
for j in range(W):
if ((mask_h >> i) & 1 == 0) and ((mask_w >> j) & 1 == 0) and table[i][j] == '#': # 塗り潰し行、列ではなくて、色が黒'#'の場合
black += 1
if black == K:
ans += 1
print(str(ans))
| 0 | null | 34,186,210,803,548 | 207 | 110 |
n = int(input())
arm = []
for _ in range(n):
x, l = map(int,input().split())
arm.append([x-l, x+l])
arm.sort(key=lambda x: x[1])
cnt = 0
pr = -float('inf')
for a in arm:
if pr <= a[0]:
cnt += 1
pr = a[1]
print(cnt)
|
from collections import deque, defaultdict
def main():
N, X, Y = map(int, input().split())
g = [[] for _ in range(N)]
for i in range(N-1):
g[i].append(i+1)
g[i+1].append(i)
g[X-1].append(Y-1)
g[Y-1].append(X-1)
ans = defaultdict(int)
for i in range(N):
q = deque()
q.append(i)
visit_time = [0 for _ in range(N)]
while len(q):
v = q.popleft()
time = visit_time[v]
for j in g[v]:
if visit_time[j] == 0 and j != i:
q.append(j)
visit_time[j] = time + 1
else:
visit_time[j] = min(time + 1, visit_time[j])
for v in visit_time:
ans[v] += 1
for i in range(1, N):
print(ans[i] // 2)
if __name__ == '__main__':
main()
| 0 | null | 67,461,518,615,480 | 237 | 187 |
import math
PI = math.pi
r = input()
men = r*r * PI
sen = r*2 * PI
print('%.6f %.6f' % (men, sen))
|
n = int(input())
A = list(map(int,input().split()))
f = 1
c = 0
while f == 1:
f = 0
for j in range(n-1,0,-1):
if A[j] < A[j-1]:
inc = A[j]
A[j] = A[j-1]
A[j-1] = inc
f = 1
c += 1
print(" ".join(map(str,A)))
print(c)
| 0 | null | 319,455,191,332 | 46 | 14 |
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
import fractions
gcd = fractions.gcd
a,b = ma()
print(a*b//gcd(a,b))
|
A, B = map(int,input().split())
import math
c = math.gcd(A,B)
d = (A*B) / c
print(int(d))
| 1 | 113,153,372,186,220 | null | 256 | 256 |
import sys
from itertools import accumulate
n = int(sys.stdin.buffer.readline())
a = list(map(int, sys.stdin.buffer.readline().split()))
aa = list(accumulate(a))
MOD = 10**9+7
ans = 0
for i in range(n):
ans += a[i]*(aa[n-1] - aa[i])
print(ans%MOD)
|
N = int(input())
A = list(map(int,input().split()))
sum_A = sum(A)
mod = 10**9+7
ans = 0
for i in range(N-1):
a = A[i]
sum_A-=a
ans+=a*sum_A
print(ans%mod)
| 1 | 3,816,016,672,132 | null | 83 | 83 |
import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
n = ini() % 10
if n in [2, 4, 5, 7, 9]:
print("hon")
elif n == 3:
print("bon")
else:
print("pon")
|
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
#from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
import sys
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
stdin = sys.stdin
ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
N = ni()
a = [2, 4, 5, 7, 9]
b = [0, 1, 6, 8]
c = [3]
r = N % 10
if r in a:
print('hon')
elif r in b:
print('pon')
else:
print('bon')
| 1 | 19,276,931,840,752 | null | 142 | 142 |
# encoding: utf-8
import sys
import math
_input = sys.stdin.readlines()
depth = int(_input[0])
sin_60, cos_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)
class Point(object):
def __init__(self, x=0.0, y=0.0):
"""
initialize the point
"""
self.x = float(x)
self.y = float(y)
def koch_curve(d, p1, p2):
if not d:
# print('end')
return None
# s, t, u = Point(), Point, Point()
s = Point()
t = Point()
u = Point()
s.x = (2 * p1.x + p2.x) / 3
s.y = (2 * p1.y + p2.y) / 3
t.x = (p1.x + 2 * p2.x) / 3
t.y = (p1.y + 2 * p2.y) / 3
u.x = (t.x - s.x) * cos_60 - (t.y - s.y) * sin_60 + s.x
u.y = (t.x - s.x) * sin_60 + (t.y - s.y) * cos_60 + s.y
koch_curve(d - 1, p1, s)
print(format(s.x, '.8f'), format(s.y, '.8f'))
koch_curve(d - 1, s, u)
print(format(u.x, '.8f'), format(u.y, '.8f'))
koch_curve(d - 1, u, t)
print(format(t.x, '.8f'), format(t.y, '.8f'))
koch_curve(d - 1, t, p2)
if __name__ == '__main__':
p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
print(format(p1_start.x, '.8f'), '', format(p1_start.y, '.8f'))
koch_curve(depth, p1_start, p2_end)
print(format(p2_end.x, '.8f'), '', format(p2_end.y, '.8f'))
|
import math
def koch(d,p1x,p1y,p2x,p2y):
if d == 0:
return 0
sin = math.sin(math.radians(60))
cos = math.cos(math.radians(60))
ax = (2 * p1x + 1 * p2x)/3
ay = (2 * p1y + 1 * p2y)/3
bx = (1 * p1x + 2 * p2x)/3
by = (1 * p1y + 2 * p2y)/3
ux = (bx - ax)* cos - (by - ay)*sin + ax
uy = (bx - ax)* sin + (by - ay)*cos + ay
koch(d-1,p1x,p1y,ax,ay)
print(ax,ay)
koch(d-1,ax,ay,ux,uy)
print(ux,uy)
koch(d-1,ux,uy,bx,by)
print(bx,by)
koch(d-1,bx,by,p2x,p2y)
d = int(input())
print(0,0)
koch(d,0,0,100,0)
print(100,0)
| 1 | 128,069,992,000 | null | 27 | 27 |
n=int(input())
num=[0]*60001
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
i=x*x+y*y+z*z+x*y+y*z+z*x
if i <= n:
num[i]+=1
for i in range(n):
print(num[i+1])
|
A, B, H, M = map(int, input().split())
import math
theta = (30 * H) - (5.5 * M)
d2 = A * A + B * B - 2 * A * B * math.cos(math.radians(theta))
d = math.sqrt(d2)
print(d)
| 0 | null | 14,025,194,708,668 | 106 | 144 |
import math
r = input()
print '%.10f %.10f' %(r*r*math.pi , r*2*math.pi)
|
import math
r = float(input())
pi =math.pi
print('%.10f %.10f'%(r*r*pi,2*r*pi))
| 1 | 641,467,251,828 | null | 46 | 46 |
# encoding: utf-8
def bubble_sort(A, N):
flag = 1
count = 0
while flag:
flag = 0
for j in xrange(N-1, 0, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
flag = 1
count += 1
return A, count
def main():
N = input()
A = map(int, raw_input().split())
A, count = bubble_sort(A, N)
print " ".join(map(str,A))
print count
main()
|
#coding:utf-8
#1_2_A
def bubble_sort(ary, n):
count = 0
flag = 1
i = 0
while flag:
flag = 0
for j in reversed(range(i+1, n)):
if ary[j] < ary[j-1]:
ary[j], ary[j-1] = ary[j-1], ary[j]
count += 1
flag = 1
i += 1
print(' '.join(map(str, ary)))
print(count)
n = int(input())
numbers = list(map(int, input().split()))
bubble_sort(numbers, n)
| 1 | 16,448,150,950 | null | 14 | 14 |
# Problem E - Almost Everywhere Zero
# input
N = list(input())
N = list(map(int, N))
K = int(input())
# initialization
dp = [[[0]*4 for i in range(2)] for j in range(len(N)+1)] # dp[keta][smaller][nums]
dp[0][0][0] = 1
# dp
for keta in range(len(N)): # keta loop
for smaller in range(2): # smaller loop
limit = 0
if smaller==0:
limit = N[keta]
else:
limit = 9
for n in range(limit + 1):
# not 0 update
if n==0:
for x in range(4):
dp[keta+1][smaller or n<limit][x] += dp[keta][smaller][x]
else:
for x in range(2, -1, -1):
dp[keta+1][smaller or n<limit][x+1] += dp[keta][smaller][x]
# output
ans = dp[len(N)][0][K] + dp[len(N)][1][K]
print(ans)
|
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,246,211,704,880 | null | 224 | 224 |
n,m=list(map(int,input().split(' ')))
am=[[0 for j in range(m)] for i in range(n)]
bm=[0 for l in range(m)]
cm=[0 for i in range(n)]
for i in range(n):
am[i]=list(map(int,input().split(' ')))
for j in range(m):
bm[j]=int(input())
for i in range(n):
for j in range(m):
cm[i]=cm[i]+am[i][j]*bm[j]
for i in range(n):
print(cm[i])
|
x = []
while True:
if 0 in x:
break
x.append(int(input()))
x.pop()
for i, v in enumerate(x):
print(('Case %d: %d') % (i+1, v))
| 0 | null | 837,621,732,428 | 56 | 42 |
n = int(input())
a = [0 for _ in range(n)]
a = [int(s) for s in input().split()]
st_num = 0
mny = 1000
for i in range(n-1):
now_mn = a[i]
next_mn = a[i+1]
#print(st_num,mny)
if(next_mn > now_mn):
st_num += mny//now_mn
mny = mny%now_mn
else:
mny += st_num*now_mn
st_num = 0
if(a[n-1] > a[n-2] and st_num > 0):
mny += st_num*a[n-1]
st_num = 0
print(mny)
|
n = int(input())
A = list(map(int, input().split()))
inf = 10 ** 18
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j])
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print(dp[n][k])
| 0 | null | 22,500,266,233,630 | 103 | 177 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[N-A[K-1]+A[0]]
for i in range(K-1):
b=A[i+1]-A[i]
B.append(b)
B.sort()
print(sum(B)-B[K-1])
|
s = input()
partition = s.replace('><','>|<').split('|')
ans=0
for sub in partition:
left = sub.count('<')
right = sub.count('>')
ans += sum(range(1, max(left, right) + 1))
ans += sum(range(1, min(left, right)))
print(ans)
| 0 | null | 100,140,093,403,570 | 186 | 285 |
[n, m] = [int(x) for x in raw_input().split()]
A = [[0] * m for x in range(n)]
B = [0] * m
counter = 0
while counter < n:
A[counter] = [int(x) for x in raw_input().split()]
counter += 1
counter = 0
while counter < m:
B[counter] = int(raw_input())
counter += 1
counter = 0
while counter < n:
result = 0
for j in range(m):
result += A[counter][j] * B[j]
print(result)
counter += 1
|
N = int(input()) % 10
print('hon' if N in [2, 4, 5, 7, 9] else 'pon' if N in [0, 1, 6, 8] else 'bon')
| 0 | null | 10,133,129,453,600 | 56 | 142 |
n, m = (int(i) for i in input().split())
tot = sum(int(i) for i in input().split())
if tot > n:
print(-1)
else:
print(n - tot)
|
n = int(input())
a = 0
b = 0
d1 = 0
d2 = 0
for i in range(n):
d1,d2 = map(int,input().split())
if(a==0 and d1 ==d2):
a+=1
elif(a==1 and d1 ==d2):
a+=1
elif(a==2 and d1 ==d2):
b +=1
break
else:
a =0
if(b>=1):
print("Yes")
else:
print("No")
| 0 | null | 17,141,626,326,152 | 168 | 72 |
n = int(input())
s = "abcdefghijklmnopqrstuvwxyz"
ans = ''
while n > 0:
n -= 1
ans = s[n % 26] + ans
#Floor division
n //= 26
print(ans)
|
(N,), *XL = [list(map(int, s.split())) for s in open(0)]
XL.sort(key=lambda x: x[0] + x[1])
curr = -float("inf")
ans = 0
for x, l in XL:
if x - l >= curr:
curr = x + l
ans += 1
print(ans)
| 0 | null | 50,897,381,707,420 | 121 | 237 |
x, y = map(int, input().split())
if y > x * 4:
print("No")
else:
for i in range(x + 1):
if 2 * i + 4 * (x - i) == y:
str = 'Yes'
break
else:
str = 'No'
print(str)
|
import sys
x,y = map(int,input().split())
for i in range(x+1):
for j in range(x-i+1):
if i+j == x and (i*2)+(j*4) == y:
print("Yes")
sys.exit()
print("No")
| 1 | 13,621,840,913,262 | null | 127 | 127 |
n = input()
R = []
for i in range(n):
R.append(input())
min_v = R[0]
max_v = -1000000000000
for i in range(1, n):
temp = R[i] - min_v
if (temp >= max_v):
max_v = temp
temp = R[i]
if (min_v >= temp):
min_v = temp
print max_v
|
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#from math import gcd
#inf = 10**17
#mod = 10**9 + 7
n,a,b = map(int, input().split())
if (b-a) % 2 == 0:
print((b-a)//2)
else:
if b-a == 1:
print(min(b-1, n-a))
else:
print(min(a-1+(b-a+1)//2, n-b+(b-a+1)//2))
if __name__ == '__main__':
main()
| 0 | null | 54,592,622,846,920 | 13 | 253 |
S=input()
T=input()
count=0
ans=0
for s in S:
t=T[count]
#print('t = %s, s = %s'%(t,s))
if(t!=s):
ans+=1
count+=1
print(ans)
|
s, t = open(0).read().split()
ans = 0
for ch_s, ch_t in zip(s, t):
if ch_s != ch_t:
ans += 1
print(ans)
| 1 | 10,518,185,963,840 | null | 116 | 116 |
n, a, b = map(int, input().split())
MOD = 10**9+7
def comb(n, k, MOD):
x = 1
for i in range(k):
x *= (n-i)
x *= pow(i+1, MOD-2, MOD)
x %= MOD
return x
ans = pow(2, n, MOD) - 1 - comb(n, a, MOD) - comb(n, b, MOD)
ans += MOD
ans %= MOD
print(ans)
|
def comb(n,r,m):
if 2*r > n:
r = n - r
nume,deno = 1,1
for i in range(1,r+1):
nume *= (n-i+1)
nume %= m
deno *= i
deno %= m
return (nume * pow(deno,m-2,m)) % m
def main():
N,M,K = map(int,input().split())
mod = 998244353
ans,comb_r = pow(M-1,N-1,mod),1
for r in range(1,K+1):
comb_r = (comb_r * (N-r) * pow(r,mod-2,mod)) % mod
ans = (ans + comb_r * pow(M-1,N-r-1,mod)) % mod
ans = (ans * M) % mod
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 44,605,002,878,308 | 214 | 151 |
import sys
input = sys.stdin.readline
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort()
ans = 0
if N & 1:
l = AB[N//2][0]
AB.sort(key=lambda x: x[1])
ans = AB[N // 2][1] - l + 1
else:
l = (AB[N // 2][0], AB[N // 2 - 1][0])
AB.sort(key=lambda x: x[1])
r = (AB[N // 2][1], AB[N // 2 - 1][1])
ans = sum(r) - sum(l) + 1
print(ans)
|
import statistics
N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
A,B = [list(i) for i in zip(*AB)]
if N%2 == 1:
low_med = statistics.median(A)
high_med = statistics.median(B)
print(high_med - low_med +1)
else:
low_med = statistics.median(A)
high_med = statistics.median(B)
print(int(2 * (high_med - low_med) +1))
| 1 | 17,445,482,389,130 | null | 137 | 137 |
def main():
from collections import deque
K = int(input())
if K <= 9:
print(K)
return
q = deque()
for i in range(1, 10):
q.append(i)
count = 9
while True:
get_num = q.popleft()
for i in range(-1, 2):
add_num = get_num % 10 + i
if 0 <= add_num and add_num <= 9:
q.append(get_num * 10 + add_num)
count += 1
if count == K:
print(q.pop())
return
if __name__ == '__main__':
main()
|
from collections import deque
N = int(input())
Q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(N - 1):
x = Q.popleft()
if x % 10 != 0:
y = 10 * x + x % 10 - 1
Q.append(y)
y = 10 * x + x % 10
Q.append(y)
if x % 10 != 9:
y = 10 * x + x % 10 + 1
Q.append(y)
ans = Q.popleft()
print(ans)
| 1 | 39,886,720,276,944 | null | 181 | 181 |
import math
x1, y1, x2, y2 = list(map(float, input().split()))
d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print("{:.5f}".format(d))
|
input()
a=list(map(int, input().split()))
a.reverse()
print(*a)
| 0 | null | 577,519,262,980 | 29 | 53 |
if __name__ == '__main__':
a, b, c = [int(i) for i in input().split()]
ans = [1 if c % i == 0 else 0 for i in range(a, b + 1)]
print(sum(ans))
|
H,W,N = map(int, open(0).read().split())
ans = 0
while N > 0:
A = max(H, W)
tmp = N // A
N = N % A
if tmp == 0 and N:
N = 0
ans += 1
break
if H == A:
W -= tmp
else:
H -= tmp
ans += tmp
print(ans)
| 0 | null | 44,833,215,376,992 | 44 | 236 |
X = int(input())
Y = X//200
print(10-Y)
|
n = int(input())
if n <= 599:
print(8)
elif 600 <= n <= 799:
print(7)
elif 800 <= n <= 999:
print(6)
elif 1000 <= n <= 1199:
print(5)
elif 1200 <= n <= 1399:
print(4)
elif 1400 <= n <= 1599:
print(3)
elif 1600 <= n <= 1799:
print(2)
elif 1800 <= n <= 1999:
print(1)
| 1 | 6,785,165,322,848 | null | 100 | 100 |
n=int(input())
a=[int(i) for i in input().split()]
c=1000
for i in range(n-1):
if a[i]<a[i+1]:
c += (c//a[i])*(a[i+1]-a[i])
print(c)
|
while 1:
x, y = map(int, raw_input().split())
if x == 0 and y == 0:
break
if x > y:
print "%d %d" % (y, x)
else:
print "%d %d" % (x, y)
| 0 | null | 3,920,555,533,412 | 103 | 43 |
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
dp = [0]*n
c = a[0]
dp[1] = max(a[0],a[1])
for i in range(2,n):
if i%2 == 0:
c += a[i]
dp[i] = max(dp[i-2]+a[i],dp[i-1])
else:
dp[i] = max(dp[i-2]+a[i],c)
print(dp[-1])
|
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')
def main():
N=int(input())
A=list(map(int,input().split()))
dp=[[-INF]*3 for _ in range(N+10)]
dp[0][0]=0
for i in range(N+1):
for j in range(3):
if j+1<3:
dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j])
if i<N:
dp[i+2][j]=max(dp[i+2][j],dp[i][j]+A[i])
if N%2:
print(dp[N+1][2])
else:
print(dp[N+1][1])
if __name__ == '__main__':
main()
| 1 | 37,498,342,822,780 | null | 177 | 177 |
n = int(input())
s = input().split()
q = int(input())
t = input().split()
res = 0
for i in t:
if i in s:
res +=1
print(res)
|
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
n,a,b = LMIIS()
def cmb(n,r):
if r == 0:
return 0
res = 1
r = min(r,n-r)
for i in range(n-r+1,n+1):
res *= i
res %= MOD
for i in range(1,r+1):
res *= pow(i,(MOD-2),MOD)
res %= MOD
return res
print((pow(2,n,MOD)-cmb(n,a)-cmb(n,b)-1)%MOD)
if __name__ == '__main__':
main()
| 0 | null | 33,142,435,108,160 | 22 | 214 |
price_list = []
t = raw_input()
for i in range(int(t)):
price_list.append(int(input()))
maxv = float("-inf")
minv = price_list[0]
for i in range(1, int(t)):
maxv = max([maxv, price_list[i] - minv])
minv = min([minv, price_list[i]])
print maxv
|
n, m, l = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in range(n)]
B = [tuple(map(int, input().split())) for _ in range(m)]
B_T = [tuple(r) for r in zip(*B)]
for L in ((sum((a*b for a, b in zip(ai, bj))) for bj in B_T) for ai in A):
print(*L)
| 0 | null | 721,359,141,814 | 13 | 60 |
def main():
h1, m1, h2, m2, k = map(int, input().split())
a = h1*60+m1
b = h2*60+m2
print(b-a-k)
if __name__ == "__main__":
main()
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
h1,m1,h2,m2,k=nii()
minute=(h2-h1)*60
minute+=m2-m1
minute-=k
print(minute)
| 1 | 18,061,854,691,812 | null | 139 | 139 |
from sys import stdin
from collections import defaultdict
N = int(stdin.readline().rstrip())
d = defaultdict(int)
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
v = x**2 + y**2 + z**2 + x*y + y*z + z*x
d[v] += 1
for i in range(1,N+1):
print(d[i])
|
n = int(input())
A = [0]*12000
for i in range(1,101):
for j in range(1, 101):
for k in range(1, 101):
val = i**2 + j**2 + k**2 + i*j + i*k + j*k
if val < 12000:
A[i**2 + j**2 + k**2 + i*j + i*k + j*k] += 1
for i in A[1:n+1]:
print(i)
| 1 | 7,947,293,960,420 | null | 106 | 106 |
import numpy as np
from numba import njit, prange
#'''
N, K = map(int, input().split())
As = list(map(int, input().split()))
'''
N = 200000
K = 100000
As = [0] * N
#'''
@njit("i8[:](i8[:],)", cache = True)
def update(A_array):
before_csum = np.zeros(N+1, np.int64)
for i, A in enumerate(A_array[:N]):
before_csum[max(0, i-A)] += 1
before_csum[min(N, i+A+1)] -= 1
return np.cumsum(before_csum)
A_array = np.array(As + [0], dtype = np.int64)
for k in range(min(K, 50)):
A_array = update(A_array)
print(*A_array.tolist()[:N])
|
a,b=map(int,input().split())
l=list(map(int,input().split()))
import itertools
b=min(b,50)
def ku(l):
y=[0]*a
for j,x in enumerate(l):
y[max(0,j-x)]+=1
r=min(j+x,a-1)
if r<a-1:
y[r+1]-=1
return itertools.accumulate(y)
for _ in range(b):
l=ku(l)
print(*l)
| 1 | 15,437,917,964,228 | null | 132 | 132 |
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
from math import gcd
mod = int(1e9+7)
n = ii()
cnd = {}
azero = 0
bzero = 0
allzero = 0
for _ in range(n):
a,b = iim()
if a*b == 0:
if a == 0 and b != 0:
azero += 1
elif a != 0 and b == 0:
bzero += 1
else:
allzero += 1
else:
g = gcd(a,b)
a //= g
b //= g
if a<0:
a *= -1
b *= -1
before = cnd.get((a,b),False)
if b > 0:
check = cnd.get((b,-a),False)
else:
check = cnd.get((-b,a),False)
if before:
cnd[(a,b)] = [before[0]+1,before[1]]
elif check:
if b > 0:
cnd[(b,-a)] = [check[0],check[1]+1]
else:
cnd[(-b,a)] = [check[0],check[1]+1]
else:
cnd[(a,b)] = [1,0]
cnd[0] = [azero,bzero]
noreg = 0
ans = 1
#print(cnd)
for item in cnd.values():
if item[0] == 0 or item[1] == 0:
noreg += max(item[0],item[1])
else:
ans *= (2**item[0]+2**item[1]-1)
ans %= mod
print((ans*((2**noreg)%mod)-1+allzero)%mod)
|
from collections import defaultdict
import sys
input = sys.stdin.readline
from math import gcd
MOD = 1000000007
dic1 = defaultdict(int)
All_zero = 0
S = set()
N = int(input())
ans = 0 #仲が悪い数を数える
for i in range(N):
a, b = map(int, input().split())
if a == 0 and b == 0: #なんでもOK
All_zero += 1
elif a == 0:
S.add((0, 1))
dic1[(0, 1)] += 1
elif b == 0:
S.add((1, 0))
dic1[(1, 0)] += 1
else:
GCD = gcd(a, b)
a //= GCD
b //= GCD
if a < 0: #aを必ず正にする
a *= -1
b *= -1
S.add((a, b))
dic1[(a, b)] += 1
lst = []
for a, b in S:
tmp11 = dic1[(a, b)]
A = a
B = b
if B <= 0:
B *= -1
A *= -1
tmp2 = dic1[(B, -A)]
# print (a, b, A, B)
dic1[(B, -A)] = 0
if tmp11 > 0:
lst.append((tmp11, tmp2))
# print (lst)
ans = 1
for a, b in lst:
tmp = (pow(2, a, MOD) - 1) + (pow(2, b, MOD) - 1) + 1 #左側を入れる、右側を入れる、両方入れない
ans *= tmp
ans %= MOD
ans = (ans - 1 + All_zero) % MOD
print (ans % MOD)
# print (S)
| 1 | 20,948,186,042,318 | null | 146 | 146 |
from collections import Counter
n, m = map(int, input().split())
group = [None for _ in range(n)]
connected = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
connected[a].append(b)
connected[b].append(a)
# print(connected)
for i in range(n):
if group[i] is not None: continue
newly_visited = [i]
group[i] = i
while len(newly_visited) > 0:
new = newly_visited.pop()
for j in connected[new]:
if group[j] is not None: continue
group[j] = i
newly_visited.append(j)
# print(Counter(group))
print(len(Counter(group)) - 1)
|
from collections import deque
def bfs(G,dist,s):
q = deque([])
dist[s] = 0
q.append(s)
while len(q) > 0:
v = q.popleft()
for nv in G[v]:
if dist[nv] != -1:
continue
dist[nv] = dist[v] + 1
q.append(nv)
n,m = map(int,input().split())
G = [[] for _ in range(n)]
for i in range(m):
a,b = map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
dist = [-1]*n
cnt = 0
for v in range(n):
if dist[v] != -1:
continue
bfs(G,dist,v)
cnt += 1
print(cnt-1)
| 1 | 2,265,013,458,084 | null | 70 | 70 |
x=int(input())
X=x
k=1
while X%360!=0:
k+=1
X+=x
print(k)
|
X,K,D=(int(x) for x in input().split())
x=abs(X)
a=x//D
b=x-a*D
B=abs(x-(a+1)*D)
if b>B:
a=a+1
if a>=K:
print(abs(x-K*D))
else:
c=K-a
if c%2 == 0:
print(abs(x-a*D))
else:
d=abs(x-(a-1)*D)
e=abs(x-(a+1)*D)
print(min(d,e))
| 0 | null | 9,060,015,623,428 | 125 | 92 |
import bisect
N = int(input())
L = sorted(map(int, input().split(' ')))
ans = 0
for i in range(len(L)):
for j in range(i + 1, len(L)):
a = L[i]
b = L[j]
ans += max(0, bisect.bisect_right(L, a + b - 1) - (j + 1))
print(ans)
|
parent_list = []
while True:
parent_list.append(input())
if parent_list[-1] == '0':
break
for n in parent_list[:-1]:
sum = 0
for c in n:
sum += int(c)
print(sum)
| 0 | null | 86,640,509,009,390 | 294 | 62 |
n,m = map(int,input().split())
ans = 0
class UnionFind:
def __init__(self,n):
self.root = [i for i in range(n+1)]
def Root_Find(self,x):
if self.root[x] == x:
return x
else:
self.root[x] = self.Root_Find(self.root[x])
return self.root[x]
def Unite(self,x,y):
x = self.Root_Find(x)
y = self.Root_Find(y)
if x == y:
return
self.root[y] = x
tree = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
tree.Unite(a,b)
for i in range(n+1):
tree.Root_Find(i)
ans = len(list(set(tree.root))) - 2
print(ans)
|
n = int(input())
al = list(map(int, input().split()))
s = sum(al)
acc = 0
res = 10**18
for a in al:
acc += a
res = min(res, abs((s-acc)-acc))
print(res)
| 0 | null | 72,400,402,860,960 | 70 | 276 |
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
def floor(a,b):
return a//b
N,X,M = LI()
# 繰り返しの1回目が終わるまで
used = [-1]*M
end_index = -1
A = [X]
sum_ = 0
for i in range(N):
if i == 0:
sum_ += A[0]
else:
val = pow(A[i-1],2,M)
A.append(val)
if used[val] == -1:
used[val] = i
sum_ += val
else:
end_index = i
start_val = val
start_index = used[val]
break
if end_index == -1:
print(sum_)
exit()
else:
ans = sum_
# 繰り返し全体が終わるまで
n = floor(N-start_index,end_index-start_index)
sum_ = 0
A2 = [start_val]
for j in range(end_index-start_index):
if j == 0:
val2 = start_val
sum_ += val2
else:
val2 = pow(A2[j-1],2,M)
A2.append(val2)
sum_ += val2
ans += (n-1)*sum_
# 残りの部分
sum_ = 0
A2 = [start_val]
for j in range(N-n*end_index+(n-1)*start_index):
if j == 0:
val2 = start_val
sum_ += val2
else:
val2 = pow(A2[j-1],2,M)
A2.append(val2)
sum_ += val2
ans += sum_
print(ans)
|
# -*- coding: utf-8 -*-
import math
def main():
N = int(input())
if N % 1.08 == 0:
print(N/1.08)
else:
x = math.ceil(N/1.08)
if x < (N+1)/1.08:
print(x)
else:
print(':(')
return
if __name__ == '__main__':
main()
| 0 | null | 64,031,409,537,678 | 75 | 265 |
N=int(input())
k=N%1000
if k==0:
t=0
else:
t=1000-k
print(t)
|
X = int(input())
lack = X % 1000
if lack == 0:
print(0)
else:
print(1000 - lack)
| 1 | 8,384,036,912,480 | null | 108 | 108 |
import sys
from collections import deque
def input():
return sys.stdin.readline().strip()
def main():
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
dp = [[float('inf') for _ in range(W)] for _ in range(H)]
def bfs(x,y):
que = deque()
que.append((x,y))
if S[y][x] == '.':
dp[y][x] = 0
else:
dp[y][x] = 1
while que.__len__():
x,y = que.popleft()
for dx,dy in ((1,0),(0,1)):
sx = x + dx
sy = y + dy
if sx == W or sy == H:
continue
if S[y][x] == '.' and S[sy][sx] == '#':
tmp = 1
else:
tmp = 0
dp[sy][sx] = min(dp[y][x]+tmp,dp[sy][sx])
if (sx,sy) not in que:
que.append((sx,sy))
bfs(0,0)
print(dp[H-1][W-1])
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
H, W = map(int, readline().split())
masu = []
for _ in range(H):
masu.append(readline().rstrip().decode('utf-8'))
# print(masu)
dp = [[INF]*W for _ in range(H)]
dp[0][0] = int(masu[0][0] == "#")
dd = [(1, 0), (0, 1)]
# 配るDP
for i in range(H):
for j in range(W):
for dx, dy in dd:
ni = i + dy
nj = j + dx
# はみ出す場合
if (ni >= H or nj >= W):
continue
add = 0
if masu[ni][nj] == "#" and masu[i][j] == ".":
add = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add)
# print(dp)
ans = dp[H-1][W-1]
print(ans)
| 1 | 49,391,503,105,098 | null | 194 | 194 |
n, x, y = list(map(int, input().split()))
x = x-1
y = y-1
ans = [0] * (n-1)
for i in range(n):
for j in range(i+1, n):
shortest = min(abs(j-i), abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1)
ans[shortest-1] += 1
for a in ans:
print(a)
|
from functools import reduce
n,a,b=map(int,input().split())
mod=10**9+7
def nCk(n,k):
c=reduce(lambda x,y: x*y%mod, range(n,n-k,-1))
m=reduce(lambda x,y: x*y%mod, range(1,k+1))
return c*pow(m,mod-2,mod)%mod
all=pow(2,n,mod)
nCa=nCk(n,a)
nCb=nCk(n,b)
print((all-nCa-nCb-1)%mod)
| 0 | null | 55,210,678,213,060 | 187 | 214 |
S = input()
T = input()
ans = len(T)
for i in range(len(S)-len(T)+1):
count = 0
#print(S[i:i+len(T)], T)
for s, t in zip(S[i:i+len(T)], T):
if s != t:
count += 1
ans = min(count, ans)
print(ans)
|
X,K,D=map(int, input().split())
if 0<abs(X)<K*D:
a=X//D
K-=a
if K%2==0:
ans=X-D*a
else:
ans=X-D*(a+1)
else:
ans=abs(X)-K*D
print(abs(ans))
| 0 | null | 4,482,533,049,010 | 82 | 92 |
n=int(input())
a=input()
s=list(a)
b=list(a)
j=0
for i in range(0,n-1):
if s[i]==s[i+1]:
b.pop(i-j)
j=j+1
else:
pass
print(len(b))
|
x = int(input())
for i in range(1, 10**5):
if 360 * i % x == 0:
print(360 * i // x)
break
| 0 | null | 91,324,217,085,860 | 293 | 125 |
S = input()
ss = S[::-1]
if ss[0]=='s':
S += 'es'
else:
S += 's'
print(S)
|
a=input()
e=a[len(a)-1:len(a)]
if e == "s":
print(a+"es")
else:
print(a+"s")
| 1 | 2,386,900,889,468 | null | 71 | 71 |
n, k = map(int,input().split())
a = list(map(int, input().split()))
flg = [True] * n
dst = [1]
twn = 0
for _ in range(k):
if flg[twn]:
dst.append(a[twn])
flg[twn] = False
twn = a[twn] - 1
else:
index = dst.index(a[twn])
ld = len(dst[:index])
cyc = len(dst[index:])
print(dst[(ld - 1) + (k + 1 - ld) % cyc] if (k + 1 - ld) % cyc != 0 else dst[-1])
exit()
print(dst[-1])
|
K=int(input())
a_i=7%K
i=1
if a_i==0:
exit(print(1))
while True:
i+=1
a_i=(10*a_i+7)%K
if a_i==0:
print(i)
exit()
if i>=K:
print(-1)
exit()
| 0 | null | 14,387,190,408,158 | 150 | 97 |
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
import bisect
# import heapq # priolity-queue
# from time import time
# from itertools import product,permutations,\
# combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce
# mod = int(1e9+7)
mod = 998244353
INF = 1<<50
def readInt():
return list(map(int,input().split()))
def main():
n,k = readInt()
l = []
r = []
for i in range(k):
a,b = readInt()
l.append(a)
r.append(b)
dp = [0 for i in range(n+1)]
dp[1] = 1
dpsum = [0 for i in range(n+1)]
dpsum[1] = 1
for i in range(2,n+1):
for j in range(k):
lj = max(1,i - r[j])
rj = i - l[j]
if rj<1:
continue
dp[i] += dpsum[rj] - dpsum[lj-1]
dp[i] %= mod
dpsum[i] = dpsum[i-1] + dp[i]
print(dp[n])
return
if __name__=='__main__':
main()
|
def main():
N = int(input())
A = list(map(int, input().split()))
if 1 not in A:
print(-1)
exit()
next = 1
for a in A:
if a == next:
next += 1
print(N - next + 1)
if __name__ == '__main__':
main()
| 0 | null | 58,502,085,136,248 | 74 | 257 |
import sys
from collections import deque
N = int(sys.stdin.readline())
lines = sys.stdin.readlines()
l = deque()
for i in range(N):
command = lines[i].split()
if command[0] == 'deleteFirst':
l.popleft()
elif command[0] == 'deleteLast':
l.pop()
elif command[0] == 'insert':
l.appendleft(command[1])
else:
if command[1] in l:
l.remove(command[1])
print(' '.join(map(str, l)))
|
from collections import deque
n = int(input())
q = deque()
for i in range(n):
c = input()
if c[0] == 'i':
q.appendleft(c[7:])
elif c[6] == ' ':
try:
q.remove(c[7:])
except:
pass
elif c[6] == 'F':
q.popleft()
else:
q.pop()
print(*q)
| 1 | 50,366,081,244 | null | 20 | 20 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
result = []
for i in range(K, N):
if A[i] > A[i - K]:
result.append('Yes')
else:
result.append('No')
print(*result, sep='\n')
|
n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
for j in range(i+1, n-1):
k = 2*j-i
if k < n:
if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
ans -= 1
else:
break
print(ans)
| 0 | null | 21,510,058,457,088 | 102 | 175 |
class itp1_1d:
def cal(self,time):
h=time/3600
time%=3600
m=time/60
time%=60
s=time
print str(h)+":"+str(m)+":"+str(s)
if __name__=="__main__":
time=input()
run=itp1_1d()
run.cal(time)
|
N = int(input())
ans = (N * 100 + 99) // 108
if N==int(ans*1.08):
print(ans)
else:
print(':(')
| 0 | null | 62,834,498,470,250 | 37 | 265 |
def main():
N=10
l = list()
for i in range(N):
l.append(int(input()))
l.sort(reverse=True)
for x in l[:3]:
print(x)
if __name__=='__main__':
main()
|
print(*sorted([int(input()) for _ in [0]*10])[:6:-1], sep="\n")
| 1 | 12,159,610 | null | 2 | 2 |
s="ACL"*int(input())
print(s)
|
import sys
def resolve(in_):
n, k = map(int, in_.readline().split())
a = list(map(int, in_.readline().split()))
mod = 10 ** 9 + 7
assert n == len(a)
# print(f'{n=} {k=} {len(a)=}')
m = sorted(filter(lambda x: x < 0, a))
p = sorted(filter(lambda x: x >= 0, a), reverse=True)
if len(p) == 0:
# print(f'{m=}')
if k % 2:
ans = m[-1] % mod
for v in m[-k:-1]:
v %= mod
ans *= v
ans %= mod
return ans
else:
ans = m[0] % mod
for v in m[1:k]:
v %= mod
ans *= v
ans %= mod
return ans
elif len(m) == 0:
ans = p[0] % mod
for v in p[1:k]:
v %= mod
ans *= v
ans %= mod
return ans
values = []
p_index = 0
m_index = 0
for _ in range(k):
if p_index < len(p) and m_index < len(m):
if p[p_index] >= abs(m[m_index]):
values.append(p[p_index])
p_index += 1
else:
values.append(m[m_index])
m_index += 1
elif p_index >= len(p):
values.append(m[m_index])
m_index += 1
elif m_index >= len(m):
values.append(p[p_index])
p_index += 1
else:
raise ValueError(f'{p_index=} {m_index=}')
# print(f'{values[:10]=} {p[:10]=} {m[:10]=}')
if any(v == 0 for v in values):
return 0
minus_values = sum(1 for v in values if v < 0)
# print(f'{minus_values > 0 and minus_values % 2=}')
if minus_values > 0 and minus_values % 2:
x = None
y = None
minus_max = max((value for value in values if value < 0), default=None)
plus_min = min((value for value in values if value >= 0), default=None)
if len(p) > p_index and minus_max:
# print(f'{p[p_index]=}')
x = abs(p[p_index] + minus_max)
if len(m) > m_index and plus_min:
# print(f'{m[m_index]=}')
y = abs(m[m_index] + plus_min)
# print(f'{x=} {y=} {minus_max=} {plus_min=}')
if x is None and y is None:
pass
elif x is None or y is None:
if x is None:
values.remove(plus_min)
values.append(m[m_index])
elif y is None:
values.remove(minus_max)
values.append(p[p_index])
else:
if x < y:
values.remove(minus_max)
values.append(p[p_index])
elif x > y:
values.remove(plus_min)
values.append(m[m_index])
elif abs(minus_max) < plus_min:
values.remove(plus_min)
values.append(m[m_index])
else:
values.remove(minus_max)
values.append(p[p_index])
ans = values[0] % mod
for v in values[1:k]:
v %= mod
ans *= v
ans %= mod
return ans
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
| 0 | null | 5,790,841,381,362 | 69 | 112 |
from collections import defaultdict
n, k = map(int, input().split())
seq = list(map(int, input().split()))
count = defaultdict(int)
count[0] = 1
prefix = [0]*(n+1)
ans = 0
for i in range(n):
pre = prefix[i+1] = (prefix[i] + seq[i] - 1)%k
if i >= k - 1:
count[prefix[i - k + 1]] -= 1
ans += count[pre]
count[pre] += 1
print(ans)
|
#!/usr/bin/env python3
from itertools import accumulate
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = [0] + list(accumulate(a))
def f(x):
return (x + n * k) % k
ans = 0
dic = {}
for i in range(n + 1):
if i >= k:
prev = f(s[i - k] - (i - k))
dic[prev] -= 1
cur = f(s[i] - i)
if cur in dic:
ans += dic[cur]
dic[cur] += 1
else:
dic[cur] = 1
print(ans)
| 1 | 137,832,093,657,622 | null | 273 | 273 |
N = int(input())
judge = []
for i in range(N):
judge.append(input())
counter = [0, 0, 0, 0]
for i in range(N):
if judge[i] == "AC":
counter[0] += 1
if judge[i] == "WA":
counter[1] += 1
if judge[i] == "TLE":
counter[2] += 1
if judge[i] == "RE":
counter[3] += 1
print("AC x " + str(counter[0]))
print("WA x " + str(counter[1]))
print("TLE x " + str(counter[2]))
print("RE x " + str(counter[3]))
|
dic = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
N = int(input())
for i in range(N):
dic[input()] += 1
for i in dic:
print(i, 'x', dic[i])
| 1 | 8,662,428,662,520 | null | 109 | 109 |
N = int(input())
u = []
v = []
for _ in range(N):
x,y = map(int,input().split())
u.append(x+y)
v.append(x-y)
umax = max(u)
umin = min(u)
vmax = max(v)
vmin = min(v)
print(max(umax-umin,vmax-vmin))
|
N = int(input())
cnt = [[0 for i in range(10)] for j in range(10)]
for i in range(1, N+1):
i_str = str(i)
cnt[int(i_str[0])][int(i_str[-1])] += 1
ans = 0
for i in range(10):
for j in range(10):
ans += cnt[i][j] * cnt[j][i]
print(ans)
| 0 | null | 44,726,751,674,880 | 80 | 234 |
import sys,math
n=0
max_v=-math.pow(10,10)
s=math.pow(10,10)
for line in sys.stdin:
l=int(line)
if n == 0:
n=l
continue
diff=l-s
if diff>max_v:
max_v=diff
if diff<0:
s=l
print max_v
|
n = int(input())
a = int(input())
b = int(input())
interest = b - a
min = min(a,b)
for i in range(n-2):
f = int(input())
if f - min > interest:
interest = f - min
elif f < min:
min = f
print(interest)
| 1 | 12,980,776,730 | null | 13 | 13 |
X,Y = map(int,input().split())
MAX_NUM = 10**6 + 1
MOD = 10**9+7
fac = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv = [0 for _ in range(MAX_NUM)]
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
fac[i] = fac[i-1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i-1] * inv[i] % MOD
def combinations(n,k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
if (X+Y)%3 != 0:
answer = 0
else:
up = -(X+Y)//3+Y
right = -(X+Y)//3+X
answer = combinations(up+right,up)
print(answer)
|
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
n,k=MI()
p=LI()
for i in range(n):
p[i]=p[i]/2+0.5
#print(p)
ans=sum(p[:k])
now=sum(p[:k])
for i in range(n-k):
now=now-p[i]+p[i+k]
ans=max(ans,now)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 112,501,079,222,360 | 281 | 223 |
a, b, c = map(int, input().split())
divisors = []
i = 1
while(i * i < c):
if(c % i == 0):
divisors.append(i)
divisors.append(c // i)
i += 1
if(i * i == c):
divisors.append(i)
ans = 0
for i in range(len(divisors)):
if(a <= divisors[i] <= b):
ans += 1
print(ans)
|
x = int(input())
a = x%100
b = x//100
if 0<=a and a<=5*b:
print(1)
else:
print(0)
| 0 | null | 64,081,930,687,610 | 44 | 266 |
import sys
W = input().lower()
T = sys.stdin.read().lower()
print(T.split().count(W))
|
#ALDS1_3-B Elementary data structures - Queue
n,q = [int(x) for x in input().split()]
Q=[]
for i in range(n):
Q.append(input().split())
t=0
res=[]
while Q!=[]:
if int(Q[0][1])<=q:
res.append([Q[0][0],int(Q[0][1])+t])
t+=int(Q[0][1])
else:
Q.append([Q[0][0],int(Q[0][1])-q])
t+=q
del Q[0]
for i in res:
print(i[0]+" "+str(i[1]))
| 0 | null | 924,153,079,128 | 65 | 19 |
def aizu006():
while True:
xs = map(int,raw_input().split())
if xs[0] == 0 and xs[1] == 0: break
else:
xs.sort()
for i in range(0,2):
print xs[i],
print
aizu006()
|
while True:
deck = input()
if deck == "-":
break
m = int(input())
for i in range(m):
h = int(input())
deck += deck[:h]
deck = deck[h:]
print(deck)
| 0 | null | 1,230,923,940,478 | 43 | 66 |
if __name__ == '__main__':
from collections import deque
n = int(input())
dic = {}
for i in range(n):
x = input().split()
if x[0] == "insert":
dic[x[1]] = 1
if x[0] == "find":
if x[1] in dic:
print('yes')
else:
print('no')
|
n = int(input())
d = {}
for i in range(n):
order = input().split()
if order[0] == 'insert':
d[order[1]] = i
else:
if order[1] in d:
print("yes")
else:
print("no")
| 1 | 76,742,950,730 | null | 23 | 23 |
a,b,c=list(map(int,input().split()))
print(c,a,b)
|
x,y,z=map(int,input().split())
a=x
b=y
c=z
temp=a
a=b
b=temp
temp=a
a=c
c=temp
print(a,b,c)
| 1 | 38,079,108,883,420 | null | 178 | 178 |
#!/usr/bin/env python
size = int(input())
line = list(map(int, input().split()))
def insertionSort(A, N):
ans = " ".join(map(str, line))
print(ans)
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
ans = " ".join(map(str, line))
print(ans)
def main():
insertionSort(line, size)
if __name__ == '__main__':
main()
|
def insertionSort(R, n):
for i in range(1, n):
Now = R[i]
j = i - 1
while j >= 0 and R[j] > Now:
R[j + 1] = R[j]
j = j - 1
R[j + 1] = Now
trace(R, n)
def trace(R, n):
for i in range(n):
print R[i],
print
n = input()
R = map(int, raw_input().split())
trace(R, n)
insertionSort(R, n)
| 1 | 6,530,871,390 | null | 10 | 10 |
def ac_control(q):
if q >= 30:
print("Yes")
else:
print("No")
if __name__ == '__main__':
q = int(input())
ac_control(q)
|
import math
A,B=map(int,input().split())
print(A*B//math.gcd(A,B))
| 0 | null | 59,824,964,827,496 | 95 | 256 |
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
a=LI()
A=0
for elem in a:
A^=elem
ans=[A^elem for elem in a]
print(*ans)
|
N = int(input())
A = list(map(int, input().split()))
t = 0
for c in A:
t ^= c
ans = []
for b in A:
ans.append(t^b)
print(*ans)
| 1 | 12,486,855,910,228 | null | 123 | 123 |
# -*- coding: utf-8 -*-
import sys
def main():
N,K = list(map(int, sys.stdin.readline().split()))
A_list = list(map(int, sys.stdin.readline().split()))
for i in range(K, len(A_list)):
if A_list[i] > A_list[i-K]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
# -*- coding: utf-8 -*-
def main():
A, B, C, K = map(int, input().split())
ans = 0
if K <= A:
ans = K
else:
if K <= A + B:
ans = A
else:
ans = A + (-1 * (K - A - B))
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 14,428,170,829,268 | 102 | 148 |
n = int(input())
a = list(map(int, input().split()))
b = list(enumerate(a))
c = sorted(b, key=lambda x:x[1])
print(*[c[i][0]+1 for i in range(n)])
|
N = int(input())
A = [int(a) for a in input().split()]
attend = [0] * N
for i in range(N):
attend[A[i]-1] = str(i+1)
res = ' '.join(attend)
print(res)
| 1 | 181,086,173,933,712 | null | 299 | 299 |
h,w = map(int,input().split())
s = h*w
if h == 1 or w == 1:
print(1)
elif s%2 == 1:
print((s//2)+1)
else:
print(s//2)
|
# -*- coding: utf-8 -*-
import sys
from collections import deque
N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()
q=deque() #(攻撃が無効となる座標、攻撃によるポイント)
ans=0
cnt=0
attack_point=0
for x,h in XH:
while q:
if x<q[0][0]:break #無効となる攻撃がない場合はwhileを終了
end_x,end_point=q.popleft()
attack_point-=end_point #攻撃が無効となる座標<=現在の座標があれば、その攻撃のポイントを引く
if h<=attack_point: #モンスターの体力よりも攻撃で減らせるポイントの方が大きければ新規攻撃は不要
pass
else: #新規攻撃が必要な場合
if h%A==0:
cnt=(h-attack_point)/A #モンスターの大量をゼロ以下にするために何回攻撃が必要か
else:
cnt=(h-attack_point)/A+1
attack_point+=cnt*A
q.append((x+2*D+1,cnt*A)) #(攻撃が無効となる座標、攻撃によるポイント)をキューに入れる
ans+=cnt
print ans
| 0 | null | 66,480,001,106,620 | 196 | 230 |
b, c = map(int, input().split())
print(b * c)
|
if __name__ == "__main__":
a,b = map(int, input().split(" "))
print(a*b)
| 1 | 15,916,161,448,770 | null | 133 | 133 |
k = int(input())
value = 7
for i in range(1, 10 ** 6):
if value % k == 0:
print(i)
exit()
value = (value * 10 + 7) % k
print(-1)
|
x, y = map(int, input().split())
def gcd(x, y):
if x % y == 0:
return y
elif x % y == 1:
return 1
else:
return gcd(y, x % y)
if x >= y:
n = gcd(x, y)
print(n)
else:
n = gcd(y, x)
print(n)
| 0 | null | 3,019,595,763,380 | 97 | 11 |
import sys
H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H # X:各行の爆破対象の個数
Y = [0] * W # Y:各列の爆破対象の個数
for h, w in bomb:
X[h] += 1
Y[w] += 1
maxX = max(X)
maxY = max(Y)
R = [h for h, x in enumerate(X) if x == maxX] # R:爆破対象の数が最大となる行の番号
C = [w for w, y in enumerate(Y) if y == maxY] # C:爆破対象の数が最大となる列の番号
bomb = set(bomb)
for r in R:
for c in C:
if (r, c) not in bomb:
# (r, c)に爆破対象が存在しないとき, maxX + maxY が答えとなることが確定するため,
# 即座に探索を終了する. これによりループの回数は最大でもM+1回となる.
print(maxX + maxY)
exit()
print(maxX + maxY - 1)
|
N=int(input())
list1 = list(map(int, input().split()))
list2=[]
for i in list1:
if i%2==0:
list2.append(i)
else:
continue
list3=[]
for j in list2:
if j%3==0 or j%5==0:
list3.append(j)
else:
continue
x=len(list2)
y=len(list3)
if x==y:
print('APPROVED')
else:
print('DENIED')
| 0 | null | 36,957,266,486,658 | 89 | 217 |
C = input()
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
j = 0
for i in alpha:
if i == C:
print(alpha[j+1])
j += 1
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def main():
c = input()
str = list('abcdefghijklmnopqrstuvwxyz')
print(str[str.index(c)+1])
if __name__ == '__main__':
main()
| 1 | 92,447,674,223,050 | null | 239 | 239 |
x=int(input())
i=0
while (i+1)*100 <= x:
i+=1
nokori = x-i*100
num = ((nokori - 1) // 5) + 1
if num <= i:
print(1)
exit()
print(0)
|
#70 C - 100 to 105 WA
X = int(input())
dp = [0]*(100010)
lst = [100,101,102,103,104,105]
for i in range(100,106):
dp[i] = 1
# dp[v] が存在するなら 1, しないなら 0
for v in range(100,X+1):
for w in range(6):
n = lst[w]
if dp[v-n] == 1:
dp[v] = 1
print(dp[X])
| 1 | 127,334,894,539,550 | null | 266 | 266 |
h = int(input())
ans = 0
i = 0
while True:
if(2**i>=h):
break
i+=1
if(i == 0):
print(1)
elif(2**i==h):
print(2**(i+1)-1)
else:
print(2**i-1)
|
x,y=map(int,input().split())
flag=0
for i in range(x+1):
if i*2+(x-i)*4==y:
print("Yes")
flag=1
break
if flag==0:
print("No")
| 0 | null | 46,752,635,962,788 | 228 | 127 |
import sys
input = sys.stdin.readline
n, u, v = [int(x) for x in input().split()]
import heapq
def dijkstra_heap(s):
#始点sから各頂点への最短距離
d = [float("inf")] * n
used = [True] * n #True:未確定
d[s] = 0
used[s] = False
edgelist = []
for e in edge[s]:
heapq.heappush(edgelist,e)
while len(edgelist):
minedge = heapq.heappop(edgelist)
#まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge[1]]:
continue
v = minedge[1]
d[v] = minedge[0]
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist,[e[0]+d[v],e[1]])
return d
################################
n, w = n, n - 1 #n:頂点数 w:辺の数
edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
x,y = map(int,input().split())
z = 1
edge[x - 1].append([z,y - 1])
edge[y - 1].append([z,x - 1])
takahashi = dijkstra_heap(u - 1)
aoki = dijkstra_heap(v - 1)
ans = -1
for i, j in zip(takahashi, aoki):
if j - i > 0:
ans = max(ans, j - 1)
print(ans)
|
s = "#."
while True:
H,W= map(int, input().split())
if H==0 and W==0:
break
elif W%2==0 :
w1=s*(W//2)
w2="."+s*(W//2-1)+"#"
elif W%2==1:
w1=s*((W-1)//2)+"#"
w2="."+s*((W-1)//2)
for i in range(H):
if i%2==0:
print(w1)
elif i%2==1:
print(w2)
print("")
| 0 | null | 58,821,499,160,490 | 259 | 51 |
import sys
input = sys.stdin.readline
# 二分木
import bisect
n,d,a = map(int,input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()
x = [ tmp[0] for tmp in xh]
damage = [0] * (n+1)
ans = 0
for i in range(n):
damage[i+1] += damage[i]
if( damage[i+1] >= xh[i][1] ):
continue
atk_num = (xh[i][1] - damage[i+1] - 1)//a +1
ans += atk_num
damage[i+1] += atk_num * a
right = bisect.bisect_right(x, xh[i][0] + 2*d)
if( right < n):
damage[right+1] -= atk_num * a
print(ans)
|
import sys
read = sys.stdin.buffer.read
def main():
N, D, A, *XH = map(int, read().split())
monster = [0] * N
for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)):
monster[i] = (x, (h + A - 1) // A)
monster.sort()
X = [x for x, h in monster]
S = [0] * (N + 1)
idx = 0
ans = 0
for i, (x, h) in enumerate(monster):
d = h - S[i]
if d > 0:
right = x + 2 * D
while idx < N and X[idx] <= right:
idx += 1
S[i] += d
S[idx] -= d
ans += d
S[i + 1] += S[i]
print(ans)
return
if __name__ == '__main__':
main()
| 1 | 81,852,754,234,070 | null | 230 | 230 |
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(N):
i+=1
D.update([(A[i-1], i)])
ans = []
for i in range(1, N+1):
ans.append(D[i])
str_ans = list(map(str, ans))
print(' '.join(str_ans))
|
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
for i, a in enumerate(A):
ans[a-1] = i + 1
print(' '.join(map(str, ans)))
| 1 | 180,433,581,525,600 | null | 299 | 299 |
n,a,b = map(int,input().split())
s = abs(a-b)
if s % 2 == 0:
print(s // 2)
else:
print(min(a-1,n-b)+1+((b-a-1) // 2))
|
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n,a,b = map(int, input().split())
if (b-a)%2==0:
ans = (b-a)//2
else:
m = b-1
M = n-a
m1 = (n-b) + 1 + (b-a-1)//2
m2 = (a-1) + 1 + (b-a-1)//2
ans = min(m,M, m1, m2)
print(ans)
| 1 | 109,277,137,373,108 | null | 253 | 253 |
pi = 3.14159265359
r = float(input())
a,d = r*r*pi,2*r*pi
print(a,d,sep=' ')
|
import math
import fpformat
r=0.0
r=input()
print fpformat.fix(r*r*math.pi,6),fpformat.fix(r*2*math.pi,6)
| 1 | 650,526,197,698 | null | 46 | 46 |
n = int(input())
d = 10**9 + 7
if n == 1:
print(0)
else:
ans = 10 ** n - 9 ** n - 9 ** n + 8 ** n
print(ans % d)
|
n = int(input())
all_result = 10 ** n
nothing = 8 ** n
only_1 = 9 ** n
result = all_result + nothing - 2 * only_1
print(result % (10**9+7))
| 1 | 3,155,117,154,490 | null | 78 | 78 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.