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
|
---|---|---|---|---|---|---|
if __name__ == '__main__':
W, H, x, y, r = map(int, raw_input().split())
ret = "Yes"
if W < x + r or x - r < 0 or H < y + r or y - r < 0:
ret = "No"
print ret
|
W, H, x, y, r = map(int, input().split())
if x == 0 or y == 0 or x < 0 or y < 0:
print("No")
elif W == x or H == y:
print("No")
elif W < x or H < y:
print("No")
elif W < x+r or H < y+r:
print("No")
else:
print("Yes")
| 1 | 462,623,166,254 | null | 41 | 41 |
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = map(int, input().split())
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def bfs(cnt, lis):
nextvisit = []
for j in lis:
for item in nextcity[j]:
if sgn[item] == 0:
nextvisit.append(item)
sgn[item] = cnt
if nextvisit:
bfs(cnt, nextvisit)
return None
else:
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
bfs(cnt, [k])
print(cnt -1)
|
a=int(input())
c=100
x=0
while c<a:
c=c+c//100
x=x+1
print(x)
| 0 | null | 14,756,934,840,444 | 70 | 159 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
s = S()
rgb = [None for _ in range(n)]
rgb_acc = [None for _ in range(n)]
rgb_st = {"R","G","B"}
rgb_lst = ["R","G","B"]
for i, char in enumerate(s):
if char == "R":
rgb[i] = [1,0,0]
elif char == "G":
rgb[i] = [0,1,0]
else:
rgb[i] = [0,0,1]
rgb_acc[0] = rgb[0]
for i in range(1, n):
rgb_acc[i] = rgb_acc[i-1][:]
index = 0 if s[i]=="R" else 1 if s[i]=="G" else 2
rgb_acc[i][index] += 1
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
if s[i]!=s[j]:
ex = rgb_st - {s[i], s[j]}
ex = ex.pop()
index = 0 if ex=="R" else 1 if ex=="G" else 2
cnt = rgb_acc[n-1][index]-rgb_acc[j][index]
if j+1 <= 2*j-i < n:
if s[2*j-i] == ex:
cnt -= 1
ans += cnt
print(ans)
main()
|
def main():
N = int(input())
S = input()
ans=S.count('R')*S.count('G')*S.count('B')
for i in range(N):
for j in range(i+1, N):
k = 2*j-i
if k>=N:
break
if (S[i]!=S[j]) and (S[j]!=S[k]) and(S[i]!=S[k]):
ans-=1
print(ans)
if __name__=='__main__':
main()
| 1 | 36,163,478,021,190 | null | 175 | 175 |
N = int(input())
music_list = [input().split(' ') for i in range(N)]
X = input()
sleep_switch = False
total_time = 0
for music in music_list:
if not sleep_switch:
if music[0] == X:
sleep_switch = True
else:
total_time += int(music[1])
print(total_time)
|
import sys, math
from functools import lru_cache
sys.setrecursionlimit(500000)
MOD = 10**9+7
def input():
return sys.stdin.readline()[:-1]
def mi():
return map(int, input().split())
def ii():
return int(input())
def i2(n):
tmp = [list(mi()) for i in range(n)]
return [list(i) for i in zip(*tmp)]
def main():
N = ii()
s, t = [list(i) for i in zip(*[input().split() for i in range(N)])]
t = list(map(int, t))
k = s.index(input())
print(sum(int(t[i]) for i in range(k+1, N)))
if __name__ == '__main__':
main()
| 1 | 96,938,979,706,902 | null | 243 | 243 |
import collections
zzz = 1
nn = int(input())
ans = 0
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
for i in range(1,nn):
zzz = 1
cc = collections.Counter(prime_factorize(i))
hoge = cc.values()
for aaa in hoge:
zzz *= aaa + 1
ans += zzz
print(ans)
|
N = int(input())
a = list(map(int, input().split()))
count = 1
bk = 0
for i in a:
if i == count:
count += 1
else:
bk += 1
if bk == N:
ans = -1
else:
ans = bk
print(ans)
| 0 | null | 58,896,029,799,518 | 73 | 257 |
#!/usr/bin/env python3
from networkx.utils import UnionFind
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
n,m=map(int, input().split())
uf = UnionFind()
for i in range(1,n+1):
_=uf[i]
for _ in range(m):
a,b=map(int, input().split())
uf.union(a, b) # aとbをマージ
print(len(list(uf.to_sets()))-1)
#for group in uf.to_sets(): # すべてのグループのリストを返す
#print(group)
if __name__ == '__main__':
main()
|
import sys
from bisect import *
from collections import deque
pl=1
#from math import *
from copy import *
#sys.setrecursionlimit(10**6)
if pl:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('outpt.txt','w')
def li():
return [int(xxx) for xxx in input().split()]
def fi():
return int(input())
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def find(i):
if i==a[i]:
return i
a[i]=find(a[i])
return a[i]
def union(x,y):
xs=find(x)
ys=find(y)
if xs!=ys:
if rank[xs]<rank[ys]:
xs,ys=ys,xs
rank[xs]+=1
a[ys]=xs
t=1
while t>0:
t-=1
n,m=mi()
a=[i for i in range(n+1)]
rank=[0 for i in range(n+1)]
for i in range(m):
x,y=mi()
union(x,y)
s=set()
for i in range(1,n+1):
a[i]=find(i)
s.add(a[i])
print(len(s)-1)
| 1 | 2,256,225,424,320 | null | 70 | 70 |
from numpy import cumsum
N = int(input())
A = list(map(int, input().split()))
a_cum = cumsum(A)
cand = [abs(a_cum[i] - (a_cum[-1] - a_cum[i])) for i in range(N)]
print(min(cand))
|
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=10007
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n=int(input())
a=list(map(int,input().split()))
lst=ruiseki(a)
asum=sum(a)
# print(asum)
# print(lst)
cnt=bisect.bisect_left(lst,asum/2)
# print(cnt)
if asum//2==lst[cnt]:
print(0)
else:
if asum%2==0:
print(2*min(asum//2-lst[cnt-1],lst[cnt]-asum//2))
else:
print(min((asum//2-lst[cnt-1])*2+1,(lst[cnt]-asum//2)*2-1))
| 1 | 141,905,747,646,140 | null | 276 | 276 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
import bisect
from functools import reduce
def main():
def comb(n, r):
numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
return numerator * pow(denominator, mod - 2, mod) % mod
mod = 10 ** 9 + 7
N, A, B = MI()
p = pow(2, N, mod) - 1
a = comb(N, A)
b = comb(N, B)
ans = (p - a - b) % mod
print(ans)
if __name__ == "__main__":
main()
|
t = 0
h = 0
for i in range(int(input())):
cards = input().split()
if cards[0] > cards[1]:
t += 3
elif cards[0] == cards[1]:
t += 1
h += 1
else:
h += 3
print(str(t) + " " + str(h))
| 0 | null | 34,174,769,599,560 | 214 | 67 |
A,B=map(int,input().split())
c=-1
for i in range(1,10**5):
if int(i*0.08)==A and int(i*0.1)==B:
c=i
break
print(c)
|
N,M=map(int,input().split())
x=max(N//0.08+1,M//0.1+1)
y=min((N+1)//0.08, (M+1)//0.1)
print( -1 if y<x else int(x))
| 1 | 56,876,516,444,538 | null | 203 | 203 |
apple = [1, 2, 3]
apple.remove(int(input()))
apple.remove(int(input()))
print(apple[0])
|
a = int(input())
b = int(input())
ans = list(filter(lambda x: x != a and x != b, [1, 2, 3]))
print(ans[0])
| 1 | 110,709,339,197,084 | null | 254 | 254 |
D, T, S = [int(x) for x in input().split()]
print("Yes" if D <= (T * S) else "No")
|
K=int(input())
x=7
c=1
visited={7}
while x%K:
x*=10
x+=7
x%=K
c+=1
z=x%K
if z in visited:
print(-1)
exit()
visited.add(x%K)
print(c)
| 0 | null | 4,815,772,439,058 | 81 | 97 |
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
MOD = 10**9+7
N = int(input())
d = {}
zero = 0
for _ in range(N):
a, b = map(int, input().split())
if a == b == 0:
zero += 1
continue
# 正規化する
if b < 0:
b = -b
a = -a
g = gcd(a, b)
b //= g
a //= g
# 入力のbが0の時はaの値を正の1に統一する
if b == 0 and a == -1:
a = 1
# 今bは必ず正
# aも正,すなわち傾きが正のとき
if a > 0:
if (a, b) in d:
d[(a, b)][0] += 1
else:
d[(a, b)] = [1, 0]
else:
# aが負,すなわち傾きが負の時
if (b, -a) in d:
d[(b, -a)][1] += 1
else:
d[(b, -a)] = [0, 1]
ans = 1
for (a, b), (k, l) in d.items():
ans *= (pow(2, k, MOD)-1 + pow(2, l, MOD)-1 + 1) # 最後の+1はどちらからも選ばなかったパターン
ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)
| 1 | 20,976,922,016,868 | null | 146 | 146 |
import sys
input()
d = set()
for l in sys.stdin:
c,s = l.split()
if c[0] == 'i':
d.add(s)
else:
print('yes' if s in d else 'no')
|
def solve():
X, Y, Z = map(int, input().split())
print(Z, X, Y)
if __name__ == '__main__':
solve()
| 0 | null | 18,905,394,226,624 | 23 | 178 |
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]
res = 0
for num in T:
if num in S:
res += 1
print(res)
|
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
count = 0
for item in t:
if item in s:
count += 1
print(count)
| 1 | 67,780,589,384 | null | 22 | 22 |
import sys
import math
def main():
r = float(sys.stdin.readline())
print(math.pi * r**2, 2 * math.pi * r)
return
if __name__ == '__main__':
main()
|
import math
r = float(input())
S = math.pi * (r**2)
l = 2 * math.pi * r
print("{} {}".format(S, l))
| 1 | 633,400,042,560 | null | 46 | 46 |
#!/usr/bin/env python
"""AtCoder Beginner Contest 169: A - Multiplication 1
https://atcoder.jp/contests/abc169/tasks/abc169_a
"""
def main():
A, B = list(map(int, input().split()))
print(A * B)
if __name__ == '__main__':
main()
|
data = input().split(" ")
a ,b= int(data[0]) , int(data[1])
print(a*b)
| 1 | 15,958,036,809,220 | null | 133 | 133 |
import sys
N, T = map(int, input().split())
S = sys.stdin.readlines()
A = []
B = []
for s in S:
a, b = map(int, s.split())
A.append(a)
B.append(b)
dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
for j in range(T):
here = dp1[i][j]
if j < A[i]:
dp1[i + 1][j] = here
else:
dp1[i + 1][j] = max(here, dp1[i][j - A[i]] + B[i])
dp2 = [[0] * T for _ in range(N + 2)]
for i in range(N, 0, -1):
for j in range(T):
here = dp2[i + 1][j]
if j < A[i - 1]:
dp2[i][j] = here
else:
dp2[i][j] = max(here, dp2[i + 1][j - A[i - 1]] + B[i - 1])
ans = 0
for i in range(1, N + 1):
t = 0
for j in range(T):
t2 = dp1[i - 1][j] + dp2[i + 1][T - 1 - j]
t = max(t, t2)
ans = max(ans, t + B[i - 1])
print(ans)
|
import numpy as np
N, T = map(int, input().split())
data = []
for i in range(N):
a, b = map(int, input().split())
data.append((a,b))
data.sort()
data = np.array(data)
dp = np.zeros(T)
ans = 0
for a, b in data:
ans = max(ans,dp[-1]+b)
if a< T:
newtable = dp[:T-a] + b
dp[a:] = np.maximum(dp[a:], newtable)
print(int(ans))
| 1 | 151,229,101,189,122 | null | 282 | 282 |
input()
X_vec = map(float, input().split())
Y_vec = map(float, input().split())
pair = list(zip(X_vec, Y_vec))
D1 = sum(abs(x-y) for x,y in pair)
D2 = (sum((x-y)**2 for x,y in pair)) ** .5
D3 = (sum(abs(x-y)**3 for x,y in pair)) ** (1/3)
Dinf = max(abs(x-y) for x,y in pair)
print("{0:.6f}\n{1:.6f}\n{2:.6f}\n{3:.6f}\n".format(D1,D2,D3,Dinf))
|
import math
def dist(a,b,n):
s=0
m=0
for i in range(len(a)):
d=math.fabs(b[i]-a[i])
m=max(m,d)
s+=d**n
return (s**(1/n),m)
n=int(input())
a=list(map(float,input().split()))
b=list(map(float,input().split()))
print('%.6f'%(dist(a,b,1)[0]))
print('%.6f'%(dist(a,b,2)[0]))
print('%.6f'%(dist(a,b,3)[0]))
print('%.6f'%(dist(a,b,1)[1]))
| 1 | 213,667,625,210 | null | 32 | 32 |
def check(P):
global w, k
t=1
wt=0
for wi in w:
if wt+wi>P:
wt=wi
t+=1
else:
wt+=wi
if t>k:
return False
return True
def search(l, r):
if r-l==1:
return r
else:
m=(l+r)//2
if not check(m):
return search(m,r)
else:
return search(l,m)
n,k=map(int,input().split())
w=[]
for i in range(n):
w.append(int(input()))
S=sum(w);M=max(w)
#print(S,M)
P0=M-1
#print(P0)
print(search(M-1,S))
|
n,k = map(int,input().split())
w = []
for loop in range(n):
w.append(int(input()))
left = max(w)
right = 100000 * 10000
mid = (left+right)//2
ans = right
def check(P):
tmp_sum = 0
cnt = 1
for loop in range(n):
if tmp_sum + w[loop] <= P:
tmp_sum += w[loop]
else:
tmp_sum = w[loop]
cnt += 1
if cnt > k:
return False
return True
while left <= right:
if check(mid):
ans = mid
right = mid - 1
else:
left = mid + 1
mid = (left+right)//2
print(ans)
| 1 | 85,713,519,462 | null | 24 | 24 |
a,b,c,d=map(float,input().split())
import math
x=math.sqrt((c-a)**2+(d-b)**2)
print("{:.5f}".format(x))
|
import math
x1,y1,x2,y2=map(float,input().split(' '))
res=math.sqrt((x1-x2)**2+(y1-y2)**2)
print(res)
| 1 | 160,456,032,750 | null | 29 | 29 |
input()
data = input().split()
data.reverse()
print(' '.join(data))
|
n = int(raw_input())
num = map(int, raw_input().split())
num.reverse()
print " ".join(map(str, num))
| 1 | 996,226,073,788 | null | 53 | 53 |
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 998244353
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
res = [1]
for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
return res
N,M,K=LI()
FACT=FLIST(N+M+1)
FINV=[]
for i in FACT: FINV.append(INV(i))
if N == 1:
print(M)
exit()
if M == 1:
if N - 1 == K: print(M)
else: print(0)
exit()
res = 0
def ncr(n, r):
res = 1
res *= FACT[n]
res *= FINV[n-r]
res %= DVSR
res *= FINV[r]
res %= DVSR
return res
for k in range(K+1):
v = ncr(N-1, k)*M
v %= DVSR
v *= POW(M-1, N-1-k)
v %= DVSR
res += v
print(res%DVSR)
|
N=10**9+7
x , y = map(int, input().split())
a=(2*x-y)//3
b=(2*y-x)//3
if 2*a+b!=x:
print(0)
exit()
n=a+b
r=a
def fac(n,r,N):
ans=1
for i in range(r):
ans=ans*(n-i)%N
return ans
def combi(n,r,N):
if n<r or n<0 or r<0:
ans = 0
return ans
r= min(r, n-r)
ans = fac(n,r,N)*pow(fac(r,r,N),N-2,N)%N
return ans
ans = combi(n,r,N)
print(ans)
| 0 | null | 86,318,105,039,044 | 151 | 281 |
w,h,x,y,r = map(int, input().split())
if x>= r and y >= r and x+r <= w and y+r <= h:
print('Yes')
else:
print('No')
|
N = int(input())
S = [int(x) for x in input().split()]
T = int(input())
Q = [int(x) for x in input().split()]
c = set()
for s in S:
for q in Q:
if s == q:
c.add(s)
print(len(c))
| 0 | null | 257,772,578,462 | 41 | 22 |
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
sum = sum(A) ** 2
squ = 0
for i in range(N):
squ += A[i] ** 2
answer = int(((sum - squ) // 2 ) % mod)
print(answer)
|
def main():
n = int(input())
# d,t,s = map(int, input().split())
a = list(map(int, input().split()))
# s = input()
mod = 10**9+7
s = sum(a)
sm = 0
for i in a:
s -= i
sm += i * s % mod
print(sm % mod)
if __name__ == '__main__':
main()
| 1 | 3,878,193,144,320 | null | 83 | 83 |
# -*= coding: utf-8 -*-
K, N = map(int, input().split())
A = list(map(int, input().split()))
d = [0] * N
for i in range(len(A)):
if i == 0:
d[0] = A[0] + (K - A[N-1]) if A[0] + (K - A[N-1]) <= A[N-1] else A[N-1]
continue
d[i] = A[i] - A[i-1]
d_max = max(d)
print(K - d_max)
|
if __name__ == '__main__':
a, b, c, k = map(int, input().split())
if k <= a:
print(k)
elif a < k and k <= (a+b):
print(a)
else:
print(a - (k-a-b))
| 0 | null | 32,813,130,179,808 | 186 | 148 |
def cmb(n, r):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
k=int(input())
n=len(input())
ans=0
for i in range(k,-1,-1):
ans=(ans+cmb(k+n,i)*pow(25,i,mod))%mod
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
iStock = 0
iMoney = 1000
for i in range(N-1):
if A[i] < A[i + 1]:
# A[i]Day 株購入 & A[i+1]Day 株売却
iStock = iMoney // A[i]
iMoney %= A[i]
iMoney += iStock * A[i+1]
print(iMoney)
| 0 | null | 10,148,820,508,320 | 124 | 103 |
n = int(input())
a = list(map(int, input().split()))
last = 0
count = 0
flag = True
while flag:
flag = False
for i in range( n-1, last, -1 ):
if a[i] < a[i-1]:
t = a[i]
a[i] = a[i-1]
a[i-1] = t
count += 1
flag = True
last += 1
print(*a)
print(count)
|
import bisect
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N):
for j in range(i+1,N):
k=bisect.bisect_left(L,L[i]+L[j])
ans+=k-j-1
print(ans)
| 0 | null | 85,744,574,314,670 | 14 | 294 |
N, K = map(int, input().split())
data = list(map(int, input().split()))
for x in range(K):
# print(data)
raise_data = [0] * (N + 1)
for i, d in enumerate(data):
raise_data[max(0, i - d)] += 1
raise_data[min(N, i + d + 1)] -= 1
height = 0
ended = 0
for i in range(N):
height += raise_data[i]
data[i] = height
if height == N:
ended += 1
if ended == N:
# print(x)
break
print(*data)
|
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
n_line = int(input())
l = set([])
for i in range(n_line):
input_line = input().split()
if input_line[0] == "insert":
l.add(input_line[1])
else:
if input_line[1] in l:
print("yes")
else:
print("no")
| 0 | null | 7,744,005,446,980 | 132 | 23 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
S = input()
n = 0
for s in S:
n += int(s)
if n%9 == 0:
print("Yes")
else:
print("No")
if __name__=='__main__':
main()
|
def main() :
N = input()
sum = 0
for i in range(len(N)):
sum += int(N[i])
if sum % 9 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 1 | 4,390,025,121,288 | null | 87 | 87 |
def ABC_142_A():
N = int(input())
guusuu=0
for i in range(N+1):
if i%2 == 0 and i !=0:
guusuu+=1
print(1-(guusuu/N))
if __name__ == '__main__':
ABC_142_A()
|
N=int(input())
if N==1:
print('{:.10f}'.format(1))
elif N%2==0:
print('{:.10f}'.format(0.5))
else:
print('{:.10f}'.format((N+1)/(2*N)))
| 1 | 177,701,918,279,210 | null | 297 | 297 |
from itertools import permutations
from math import factorial
N = int(input())
data = []
for _ in range(N):
x, y = map(int, input().split())
data.append((x,y))
res = 0
for a in permutations(data,N):
x0, y0 = a[0]
for x, y in a[1:]:
res += ((x-x0)**2 + (y-y0)**2)**(0.5)
x0, y0 = x, y
print(res/factorial(N))
|
n=int(input())
x=[]
y=[]
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
p=1
for i in range(n):
p*=i+1
def D(a,b):
a=a-1
b=b-1
return ((x[a]-x[b])**2+(y[a]-y[b])**2)**(0.5)
def f(x):
ans=0
while x>0:
ans+=x%2
x=x//2
return ans
def r(x):
ans=1
for i in range(x):
ans*=(i+1)
return ans
dp=[[0]*(n+1) for _ in range(2**n)]
for i in range(1,2**n):
for j in range(1,n+1):
for k in range(1,n+1):
if (i>>(j-1))&1 and not (i>>(k-1)&1):
dp[i+2**(k-1)][k]+=dp[i][j]+r((f(i)-1))*D(j,k)
print(sum(dp[2**n-1])/p)
| 1 | 148,281,865,538,080 | null | 280 | 280 |
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
S = 0
ans = 0
for a in A:
ans = (ans + a * S) % MOD
S += a
print(ans)
|
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
x=sum(a)%mod
y=0
for i in range(n):
y+=a[i]**2
y%=mod
z=pow(2,mod-2,mod)
print(((x**2-y)*z)%mod)
| 1 | 3,816,479,403,318 | null | 83 | 83 |
N, K = map(int, input().split())
mod = 10 ** 9 + 7
print(((N+1)*(N*N+2*N+6)//6+(K-1)*(2*K*K-(3*N+4)*K-6)//6) % mod)
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,k = map(int, input().split())
mod = 10**9+7
ans = 0
for i in range(k, n + 2):
mi = (i - 1) * i // 2
ma = (n + n - i + 1) * i // 2
ans += ma - mi + 1
print(ans % mod)
| 1 | 33,291,733,800,258 | null | 170 | 170 |
import statistics
import math
N = int(input())
listA = [0] * N
listB = [0] * N
idx = 0
for i in range(N):
listA[idx],listB[idx] = map(int, input().split())
idx += 1
medianA = 0
medianB = 0
ans = 0
if N%2 == 0:
medianA = statistics.median(listA)
medianB = statistics.median(listB)
ans = (medianB - medianA) * 2 + 1
else:
medianA = statistics.median(listA)
medianB = statistics.median(listB)
ans = medianB - medianA + 1
print(int(ans))
|
n = int(input())
a= [0]*n
b= [0]*n
for i in range(n):
a[i], b[i] = map(int, input().split())
if n%2 ==1:
a.sort()
b.sort()
xmin= a[int((n-1)/2)]
xmax= b[int((n - 1) / 2)]
print(int(xmax-xmin+1))
if n%2 ==0:
a.sort()
b.sort()
xmin = a[int(n/2-1)]+a[int(n/2)]
xmax = b[int(n / 2 - 1)] + b[int(n / 2)]
print(int((xmax-xmin)+1))
| 1 | 17,293,868,869,700 | null | 137 | 137 |
import fractions
import math
def divide_two(x):
ans = 0
while x > 0:
if x % 2 == 0:
ans += 1
x = x // 2
else:
break
return ans
n, m = map(int, input().split())
a = list(map(int, input().split()))
flag = [divide_two(i) for i in a]
if sum(flag) != flag[0] * n:
ans = 0
else:
# 最小公倍数求める
lcm = a[0]
for i in range(1, n):
lcm = lcm * a[i] // fractions.gcd(lcm, a[i])
ans = math.floor(m / lcm + 0.5)
print(ans)
|
a, b, c, k = map(int,input().split())
if k <= a:
print(k)
elif a < k <= a + b:
print(a)
elif a + b <= k:
print(a*2 - k + b)
| 0 | null | 61,874,424,079,802 | 247 | 148 |
N = int(input())
A = list(map(int, input().split()))
dp = [{} for _ in range(N + 2)]
dp[0][0] = 0
dp[-1][0] = 0
for i in range(1, N + 1):
f = (i - 1) // 2
t = (i + 1) // 2
for j in range(f, t + 1):
var1 = dp[i - 2][j - 1] + A[i - 1] if j - 1 in dp[i - 2] else -float('inf')
var2 = dp[i - 1][j] if j in dp[i - 1] else -float('inf')
dp[i][j] = max(var1, var2)
print(dp[N][N // 2])
|
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
a = inl()
if n<=3:
print(max(a))
exit()
lacc = [0]*n
racc = [0]*n
lacc[0] = a[0]
lacc[1] = a[1]
racc[n-1] = a[n-1]
racc[n-2] = a[n-2]
for i in range(2,n):
if i%2==0:
lacc[i] = lacc[i-2]+a[i]
else:
lacc[i] = max(lacc[i-3],lacc[i-2])+a[i]
if n%2==0:
print(max(lacc[n-2],lacc[n-1]))
exit()
for i in range(n-3,-1,-1):
if (n-1-i)%2==0:
racc[i] = racc[i+2]+a[i]
else:
racc[i] = max(racc[i+3],racc[i+2])+a[i]
mx = max(racc[2],lacc[n-3])
for i in range(1,n-2):
if i%2==0:
mx = max(mx, max(lacc[i-2],lacc[i-1])+racc[i+2])
else:
mx = max(mx, max(racc[i+2],racc[i+3])+lacc[i-1])
print(mx)
| 1 | 37,337,416,420,160 | null | 177 | 177 |
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
import base64
import subprocess
import zlib
exe_bin = "c$~dk4Rlo1wLW)dk_;i48#N#xNVH>36vm7MOlr_fn1nlaf(XP?3%!QPgiOufOKuR5r;tf_T*pzKcD1ZlEA{6srCO2KMS<tzB?ber=tEnn6@RD|oH2^=hY$oZZ|`%@nYnW_)1SBAdY3iX_k3sXef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b85decode(exe_bin)))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)
|
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)
| 0 | null | 2,127,867,796,770 | 84 | 37 |
x = input()
if x == "1": print(0)
else: print(1)
|
import sys
input = sys.stdin.readline
def main():
x = int(input())
print(1-x)
if __name__ == "__main__":
main()
| 1 | 2,900,775,865,478 | null | 76 | 76 |
while True:
try:
h,w = map(int,input().split(" "))
if h == 0 and w == 0:
break
for i in range(h):
for j in range(w):
print("#",end="")
print()
print()
except:
break
|
from math import pi
def main():
S = int(input())
print(2 * pi * S)
if __name__ == "__main__":
main()
| 0 | null | 16,038,584,404,470 | 49 | 167 |
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N, K, C = map(int, input().split())
S = list(input())
mae = [-1] * N
i = 0
count = 0
while i < N and count < K:
if S[i] == 'o':
mae[i] = count
count += 1
i += C + 1
else:
i += 1
ushiro = [-1] * N
i = N - 1
count = 0
while i >= 0 and count < K:
if S[i] == 'o':
ushiro[i] = K - count - 1
count += 1
i -= (C + 1)
else:
i -= 1
for i in range(N):
if mae[i] == ushiro[i] and mae[i] != -1:
print (i + 1)
|
x,y,z = map(int,input().split())
tmp = x
x = y
y = tmp
tmp = x
x = z
z = tmp
print(x,y,z)
| 0 | null | 39,327,993,879,662 | 182 | 178 |
X = int(input())
ans, rem = divmod(X, 500)
ans *= 1000
ans += rem // 5 * 5
print(ans)
|
h1, m1, h2, m2, k = map(int, input().split())
st = h1 * 60 + m1
ed = h2 * 60 + m2
ans = ed - st - k
if ans < 0:
ans = 0
print(ans)
| 0 | null | 30,415,238,792,540 | 185 | 139 |
N,M=map(int,input().split())
a = list(map(int,input().split()))
if N-sum(a)>=0:
print(N-sum(a))
else:
print("-1")
|
H, M = map(int, input().split())
A = list(map(int, input().split()))
for i in A:
H -= i
if H < 0:
print("-1")
else:
print(H)
| 1 | 31,880,448,151,332 | null | 168 | 168 |
N,K = map(int, input().split())
if N % K == 0:
print(0)
elif N > K:
hako1 = N%K
hako2 = abs(hako1-K)
if hako1 > hako2:
print(hako2)
else:
print(hako1)
else:
if N >= abs(N-K):
print(abs(N-K))
else:
print(N)
|
def resolve():
S = input()
print("No" if S in ["AAA", "BBB"] else "Yes")
if '__main__' == __name__:
resolve()
| 0 | null | 47,079,345,369,074 | 180 | 201 |
from numpy import zeros, maximum
N, T, *AB = map(int, open(0).read().split())
dp = zeros(6010, int)
for w, v in sorted(zip(*[iter(AB)] * 2)):
dp[w:T + w] = maximum(dp[w:T + w], dp[:T] + v)
print(dp.max())
|
from copy import deepcopy
# 多次元配列を作成する
def make_multi_list(initial, degree):
ans = [initial for _ in range(degree[-1])]
for d in reversed(degree[:-1]):
ans = [deepcopy(ans) for _ in range(d)]
return ans
N, T = map(int, input().split())
AB = []
for i in range(N):
a, b = map(int, input().split())
AB.append((a, b))
AB.sort()
ans = 0
dp = make_multi_list(0, [3005, 3005])
for i in range(N):
a, b = AB[i]
for j in range(T):
# iを使わないパターン
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
# iを使うパターン
nj = j + a
if nj < T:
dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + b)
now = dp[i][T - 1] + b
ans = max(ans, now)
print(ans)
| 1 | 151,476,495,424,082 | null | 282 | 282 |
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort(reverse=True)
l, r = -1, 10 ** 12 + 1
while r - l > 1:
m = (l + r) // 2
cnt = 0
for i in range(n):
cnt += max(0, a[i] - (m // f[i]))
if cnt <= k:
r = m
else:
l = m
print(r)
|
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
ng = -1
ok = 10**12+100
while ok - ng > 1:
mid = (ok + ng) // 2
if sum(max(0,a-mid//f) for a,f in zip(A,F)) <= K:
ok = mid
else:
ng = mid
print(ok)
| 1 | 164,979,062,978,494 | null | 290 | 290 |
A, B, C, K = map(int ,input().split())
Xa = min(K,A)
K2 = K - Xa
Xb = min(K2,B)
Xc = K2 - Xb
print(Xa - Xc)
|
N=int(input())
for num in range(1,10):
if (N/num).is_integer() and 1<=(N/num)<=9:
print("Yes")
break
else:
print("No")
| 0 | null | 90,580,699,106,830 | 148 | 287 |
def selectionSort(A, N):
global cnt
for i in range(N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
cnt = cnt + 1 #
return A
if __name__ == '__main__':
n = int(input())
R = list(map(int, input().split()))
cnt = 0
R = selectionSort(R, n)
print(" ".join(map(str, R)))
print(cnt)
|
import math
N = int(input())
A = list(map(int, input().split()))
count = 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:
count += 1
temp = A[i]
A[i] = A[minj]
A[minj] = temp
print(' '.join(map(str, A)))
print(count)
| 1 | 19,685,413,702 | null | 15 | 15 |
def resolve():
n, k = map(int, input().split())
S = []
L, R = [], []
for _ in range(k):
l1, r1 = map(int, input().split())
L.append(l1)
R.append(r1)
dp = [0 for i in range(n + 1)]
dpsum = [0 for i in range(n + 1)]
dp[1] = 1
dpsum[1] = 1
for i in range(2, n + 1):
for j in range(k):
Li = i - R[j]
Ri = i - L[j]
if Ri < 0:
continue
Li = max(1, Li)
dp[i] += dpsum[Ri] - dpsum[Li - 1] # dp[Li] ~ dp[Ri]
dp[i] %= 998244353
dpsum[i] = (dpsum[i - 1] + dp[i]) % 998244353
print(dp[n])
resolve()
|
MOD = int(1e+9 + 7)
N, K = map(int, input().split())
cnt = [0] * (K + 1) # 要素が全てXの倍数となるような数列の個数をXごとに求める
for x in range(1, K + 1):
cnt[x] = pow(K // x, N, MOD)
for x in range(K, 0, -1): # 2X, 3Xの個数を求めてひく
for i in range(2, K // x + 1):
cnt[x] -= cnt[x * i]
ans = 0
for k in range(K+1):
ans += cnt[k] * k
ans = ans % MOD
print(ans)
| 0 | null | 19,661,442,745,718 | 74 | 176 |
import sys
s = input().lower()
t = sys.stdin.read().lower().split()
print(t.count(s))
|
W = raw_input().lower()
T= []
while True:
t = raw_input()
if t == "END_OF_TEXT":
break
else:
T += t.lower().split()
print(T.count(W))
| 1 | 1,819,188,695,972 | null | 65 | 65 |
h, w, k = map(int, input().split())
c = []
for i in range(h):
c.append(input())
t = 2**(h+w)
ans = 0
for i in range(t):
tc = c[:]
b = format(i, 'b').zfill(h+w)
for j in range(len(b)):
if b[j] == "1":
if j < h:
tc[j] = "?"*w
else:
for l in range(h):
tc[l] = tc[l][:(j-h)] + "?" + tc[l][(j-h+1):]
cn = 0
for j in range(h):
cn += tc[j].count("#")
if cn == k:
ans += 1
print(ans)
|
#!/usr/bin/env python3
import sys
from itertools import combinations as comb
from itertools import chain
import numpy as np
# form bisect import bisect_left, bisect_right, insort_left, insort_right
# from collections import Counter
def solve(H, W, K, C):
answer = 0
for hn in range(H + 1):
for wn in range(W + 1):
for h_idxs in comb(range(H), hn):
for w_idxs in comb(range(W), wn):
cs = C.copy()
cs[h_idxs, :] = 0
cs[:, w_idxs] = 0
answer += cs.sum() == K
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
H = int(next(tokens))
W = int(next(tokens))
K = int(next(tokens))
C = np.array(
[
list(map(lambda x: {"#": 1, ".": 0}[x], line))
for line in tokens
]
)
answer = solve(H, W, K, C)
print(answer)
if __name__ == "__main__":
main()
| 1 | 8,911,189,650,660 | null | 110 | 110 |
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
mass = [0]*(N+1)
for i in range(N):
mass[i+1] = mass[i] + A[i]
answer = 0
for i in range(N-1):
answer += (A[i]*(mass[N]-mass[i+1]))
print(answer % (10**9 + 7))
|
def solve(string):
x, k, d = map(int, string.split())
if k % 2:
x = min(x - d, x + d, key=abs)
k -= 1
x, k, d = abs(x), k // 2, d * 2
return str(min(x % d, abs((x % d) - d))) if x < k * d else str(x - k * d)
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 0 | null | 4,485,725,512,318 | 83 | 92 |
b = input()
a = input()
print(int(a[-2:]==' 1'))
|
M_1, D_1 = map(int, input().split())
M_2, D_2 = map(int, input().split())
if (M_1 != M_2):
print('1')
else:
print('0')
| 1 | 124,240,620,121,722 | null | 264 | 264 |
x = float(input())
if 1 >= x >= 0:
if x == 1:
print(0)
elif x == 0:
print(1)
|
if int(input()) == 0:
print('1')
else:
print('0')
| 1 | 2,932,732,887,712 | null | 76 | 76 |
x = int(input())
print(8 - ((x - 400) // 200))
|
while True:
h, w = map(int, input().split())
if h == w == 0: break
print('#' * w + '\n' + (('#' + '.' * (w-2) + '#') + '\n') * (h-2) + '#' * w)
print('')
| 0 | null | 3,773,060,453,758 | 100 | 50 |
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
f=lambda:map(int,input().split())
N,M,L=f()
G=[[0]*N for _ in [0]*N]
for _ in [0]*M:
a,b,c=f()
G[a-1][b-1]=c
G[b-1][a-1]=c
csr=csr_matrix(G)
D=floyd_warshall(csr)
INF=float('inf')
G=[[INF]*N for _ in [0]*N]
for i in range(N):
for j in range(N):
if i!=j and D[i][j]<=L:
G[i][j]=1
G[j][i]=1
csr=csr_matrix(G)
res=floyd_warshall(csr)
Q=int(input())
for _ in [0]*Q:
s,t=f()
r=res[s-1][t-1]
print(int(r-1) if r<INF else -1)
|
INF = 10 ** 9
n, m, l = map(int, input().split())
d = [[INF for j in range(n + 1)] for i in range(n + 1)]
d2 = [[INF for j in range(n + 1)] for i in range(n + 1)]
for _ in range(m):
i, j, c = map(int, input().split())
d[i][j] = c
d[j][i] = c
if c <= l:
d2[i][j] = 1
d2[j][i] = 1
q = int(input())
Q = [list(map(int, input().split())) for _ in range(q)]
for k in range(1, n + 1):
for i in range(1, n):
for j in range(i, n + 1):
dk = d[i][k] + d[k][j]
if d[i][j] > dk:
d[i][j] = dk
d[j][i] = dk
if dk <= l:
d2[i][j] = 1
d2[j][i] = 1
for k in range(1, n + 1):
for i in range(1, n):
for j in range(i, n + 1):
dk = d2[i][k] + d2[k][j]
if d2[i][j] > dk:
d2[i][j] = dk
d2[j][i] = dk
for i in range(q):
s, t = Q[i]
di = d2[s][t]
if di >= INF:
print(-1)
else:
print(di - 1)
| 1 | 173,388,826,035,568 | null | 295 | 295 |
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
mod = 10**9 + 7
fac = [0] * (N+1)
facinv = [0] * (N+1)
fac[0] = 1
facinv[0] = 1
for i in range(N):
fac[i+1] = (fac[i] * (i + 1)) % mod
facinv[i+1] = (facinv[i] * pow(i+1, -1, mod)) % mod
def nCk(n, k):
return (fac[n] * facinv[k] * facinv[n-k]) % mod
p = 0
m = 0
for i in range(K-1, N):
p = (p + A[i] * nCk(i, K-1)) % mod
m = (m + A[N-i-1] * nCk(i, K-1)) % mod
#print(A[i-K+1] , nCk(N-i+1, K-1))
print((p - m) % mod)
|
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
N = int(input())
C = input()
left = 0
right = N-1
count = 0
while left < right:
if C[left] == 'W' and C[right] == 'R':
count += 1
left += 1
right -= 1
if C[left] == 'R':
left += 1
if C[right] == 'W':
right -= 1
print(count)
| 0 | null | 50,962,892,354,202 | 242 | 98 |
a, b = [int(input()) for _ in range(2)]
c = [1, 2, 3]
c.remove(a)
c.remove(b)
print(*c)
|
N=int(input())
M=1000
if N%M==0:
print(0)
else:
print(M-N%M)
| 0 | null | 59,709,161,428,690 | 254 | 108 |
import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]
INF = 10**20
g = [[INF]*N for _ in range(N)]
for a,b,c in ABC:
a,b = a-1,b-1
g[a][b] = g[b][a] = c
for i in range(N):
g[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if g[i][j] > g[i][k] + g[k][j]:
g[i][j] = g[i][k] + g[k][j]
h = [[N]*N for _ in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if g[i][j] <= L:
h[i][j] = h[j][i] = 1
for i in range(N):
h[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if h[i][j] > h[i][k] + h[k][j]:
h[i][j] = h[i][k] + h[k][j]
ans = []
for s,t in ST:
s,t = s-1,t-1
if h[s][t] == N:
ans.append(-1)
else:
ans.append(h[s][t] - 1)
print(*ans, sep='\n')
|
"""
気付き
1、float('inf')はちょい遅いみたい
2、input()よりもinput = sys.stdin.readlineの方が爆速らしい(知らんがな)
"""
import sys
inf = 10 ** 15
input = sys.stdin.readline
N, M, L = map(int, input().split())
dp = [[inf] * N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
dp[a-1][b-1] = c
dp[b-1][a-1] = c
for i in range(N):
dp[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
#print('distance={}'.format(dp))
dp2 = [[inf] * N for _ in range(N)]
for a in range(N - 1):
for b in range(a+1, N):
if dp[a][b] <= L:
dp2[a][b] = 1
dp2[b][a] = 1
for k in range(N):
for i in range(N):
for j in range(N):
dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])
#print('times={}'.format(dp2))
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
cost = dp2[s-1][t-1]
if cost != inf:
print(cost - 1)
else:
print(-1)
| 1 | 173,976,921,333,714 | null | 295 | 295 |
from functools import reduce
def comb(n, max_k, mod):
"""
(n,k) := n個からk個選ぶ組み合わせ
k = 0~max_Kまでを計算して返す
"""
res = [1]*(max_k+1)
t = 1
for i in range(max_k+1):
res[i] *= t
t *= n-i
t %= mod
n = reduce(lambda x,y: (x*y)%mod, range(1,max_k+1), 1)
n = pow(n, mod-2, mod)
for i in reversed(range(max_k+1)):
res[i] *= n
res[i] %= mod
n *= i
n %= mod
return res
X,Y = map(int,input().split())
d = X+Y
if d%3 != 0:
print(0)
else:
n = d//3
if X < n or 2*n < X:
res = 0
else:
res = comb(n,X-n, 10**9+7)[X-n]
print(res)
|
import sys
from io import StringIO
import unittest
import os
# 検索用タグ、10^9+7 組み合わせ、スプレッドシートでのトレース
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def cmb(n, r):
mod = 10 ** 9 + 7
ans = 1
for i in range(r):
ans *= n - i
ans %= mod
for i in range(1, r + 1):
ans *= pow(i, mod - 2, mod)
ans %= mod
return ans
def prepare_simple(n, mod=pow(10, 9) + 7):
# n! の計算
f = 1
for m in range(1, n + 1):
f *= m
f %= mod
fn = f
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return fn, invs
def prepare(n, mod=pow(10, 9) + 7):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= mod
factorials.append(f)
# n!^-1 の計算
inv = pow(f, mod - 2, mod)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= mod
invs[m - 1] = inv
return factorials, invs
# 実装を行う関数
def resolve(test_def_name=""):
x, y = map(int, input().split())
all_move_count = (x + y) // 3
x_move_count = all_move_count
y_move_count = 0
x_now = all_move_count * 2
y_now = all_move_count
canMake= False
for i in range(all_move_count+1):
if x_now == x and y_now == y:
canMake = True
break
x_move_count -= 1
y_move_count += 1
x_now -= 1
y_now += 1
if not canMake:
print(0)
return
ans = cmb(all_move_count,x_move_count)
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 3"""
output = """2"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """2 2"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """999999 999999"""
output = """151840682"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
| 1 | 149,679,102,093,152 | null | 281 | 281 |
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, k = map(int, readline().split())
p = list(map(int, readline().split()))
tmp = [(i+1)/2 for i in p]
cs = list(np.cumsum(tmp))
if n == k:
print(cs[-1])
exit()
ans = 0
for i in range(n - k):
ans = max(ans, cs[i + k] - cs[i])
print(ans)
|
n,m,l = map(int, input().split())
A = [[0 for j in range(m)] for i in range(n)]
B = [[0 for j in range(l)] for i in range(m)]
C = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
A[i] = list(map(int, input().split()))
for i in range(m):
B[i] = list(map(int, input().split()))
for i in range(n):
for j in range(l):
for k in range(m):
C[i][j] += A[i][k] * B[k][j]
for i in range(n):
for j in range(l-1):
print(C[i][j],end=' ')
print(C[i][l-1],sep='')
| 0 | null | 38,384,725,933,102 | 223 | 60 |
# -*- coding: utf-8 -*-
import math
def abs(num):
if num < 0:
return -num
else:
return num
def abc163e(n, a):
hap_dict = dict()
hap_list = []
for elem in range(n):
if a[elem] in hap_dict:
hap_dict[a[elem]].append(elem)
else:
tmp_list = [elem]
hap_dict[a[elem]] = tmp_list
hap_list.append(a[elem])
hap_list.sort(reverse=True)
left = 0
right = n-1
num = 0
dp = [[0 for re in range(n+1)] for le in range(n+1)]
for hap in hap_list:
pos_list = hap_dict[hap]
while len(pos_list) != 0:
tgt = pos_list.pop()
num += 1
for left in range(num+1):
right = num-left
if left == num: # left end
dp[left][right] = dp[left-1][right] + hap * abs(tgt-left+1)
elif left == 0: # right end
dp[left][right] = dp[left][right-1] + hap * abs(n-right-tgt)
else:
left_dp = dp[left-1][right] + hap * abs(tgt-left+1)
right_dp = dp[left][right-1] + hap * abs(n-right-tgt)
dp[left][right] = max(left_dp, right_dp)
#print("[",str(left),"][",str(right),"]=",str(dp[left][right]))
ans_list = []
for i in range(num+1):
ans_list.append(dp[i][num-i])
return max(ans_list)
###
# main
if(__name__ == '__main__'):
# input
n = int(input())
a = list(map(int, input().split(" ")))
ans = abc163e(n, a)
# output
print(ans)
# else:
# do nothing
|
while True:
x = int(input())
if x == 0:
break
SCORE = len(str(x))
ans = 0
amari=x
for i in range(SCORE+1):
ans += amari//10**(SCORE-i)
amari = amari%10**(SCORE-i)
print(ans)
| 0 | null | 17,549,469,912,800 | 171 | 62 |
n=int(input())
s=set([])
for i in range(n):
s_=input()
s.add(s_)
print(len(s))
|
N = int(input())
S = [None] * N
for i in range(N):
S[i] = input()
S = set(S)
print(len(S))
| 1 | 30,281,646,979,012 | null | 165 | 165 |
n=int(input())
sums=0
for i in str(n):
sums+=int(i)
print('Yes' if sums%9==0 else 'No')
|
k=int(input())
num=7
i=1
while True:
if k%2==0 or k%5==0:
i=-1
break
num%=k
if num==0:
break
else:
num*=10
num+=7
i+=1
print(i)
| 0 | null | 5,321,690,866,622 | 87 | 97 |
from math import sqrt;
count = int(input());
data = [];
for n in range(count):
data.append(int(input()));
def prime_number(data):
max_divisor = get_max_divisor(data);
divisor_primes = get_prime(max_divisor);
count = 0;
for n in data:
ok = 1;
for p in divisor_primes:
if n < p:
ok = 0;
break;
elif n == p:
break;
elif n % p == 0:
ok = 0;
break;
count += ok;
return count;
def get_max_divisor(data):
maxN = data[0];
for n in data[1:]:
if n > maxN:
maxN = n;
return int(sqrt(maxN)) + 1;
def get_prime(max_divisor):
primes = [];
for n in range(2, max_divisor + 1):
is_prime = True;
for p in primes:
if n % p == 0:
is_prime = False;
if is_prime:
primes.append(n);
return primes;
print(prime_number(data));
|
def isprime(n):
divider = 2
while divider ** 2 <= n:
if n % divider == 0:
return False
divider += 1
return True
result = 0
n = int(input())
for n in range(n):
result += isprime(int(input()))
print(result)
| 1 | 9,852,161,420 | null | 12 | 12 |
a = [int(v) for v in input().rstrip().split()]
r = 'bust' if sum(a) >= 22 else 'win'
print(r)
|
X= raw_input().split()
if float(X[2]) + float(X[4]) <= float(X[0])and float(X[2]) - float(X[4]) >= 0 and float(X[3]) + float(X[4]) <= float(X[1]) and float(X[3]) - float(X[4]) >= 0:
print "Yes"
else:
print "No"
| 0 | null | 59,596,230,407,372 | 260 | 41 |
import sys
n = int(input())
for i in range(1,10):
for j in range(1,10):
if i * j == n :
print('Yes')
sys.exit()
print('No')
|
def atc_144b(input_value: int) -> str:
for i in range(1, 9 + 1):
if input_value % i == 0 and input_value / i <= 9:
return "Yes"
return "No"
input_value = int(input())
print(atc_144b(input_value))
| 1 | 159,202,709,824,548 | null | 287 | 287 |
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
S = sys.stdin.buffer.readline().decode().rstrip()
N = len(S)
# ピッタリ払う
dp0 = [INF] * (N + 1)
# 1 多く払う
dp1 = [INF] * (N + 1)
dp0[0] = 0
dp1[0] = 1
for i, c in enumerate(S):
dp0[i + 1] = min(dp0[i] + int(c), dp1[i] + 10 - int(c))
dp1[i + 1] = min(dp0[i] + int(c) + 1, dp1[i] + 10 - int(c) - 1)
# print(dp0)
# print(dp1)
print(dp0[-1])
|
N,M,K=map(int,input().split())
MOD=998244353
def inv(a):
return pow(a,MOD-2,MOD)
fact=[0,1]
for i in range(2,N+1):
fact.append((fact[-1]*i)%MOD)
def choose(n,r):
if r==0 or r==n:
return 1
else:
return fact[n]*inv(fact[r])*inv(fact[n-r])%MOD
exp=[1]
def pow_k(x,n):
if n==0:
return 1
K=1
while n>1:
if n%2!=0:
K=K*x%MOD
x=x**2%MOD
n=(n-1)//2
else:
x=x**2%MOD
n=n//2
return K*x%MOD
ans=0
for i in range(K+1):
ans+=(M*choose(N-1,i)*pow_k(M-1,N-1-i)%MOD)
ans%=MOD
print(ans)
| 0 | null | 46,773,101,836,928 | 219 | 151 |
from collections import Counter
def mpow(a,b,mod):
ret=1
while b>0:
if b&1:
ret=(ret*a)%mod
a=(a*a)%mod
b>>=1
return ret
n,p=map(int,input().split())
s=[int(i) for i in input()]
if p==2 or p==5:
ans=0
for i in range(n):
if s[i]%p==0:
ans+=i+1
print(ans)
else:
ans=0
d=Counter()
d[0]+=1
num=0
for i in range(n-1,-1,-1):
num=(num+s[i]*mpow(10,n-1-i,p))%p
ans+=d[num]
d[num]+=1
print(ans)
|
N, P = map(int, input().split())
S = input()
total = 0
if P == 2:
for idx, right_value in enumerate(S, 1):
if int(int(right_value)%2==0):
total += idx
elif P == 5:
valid_options = (0, 5)
for idx, right_value in enumerate(S, 1):
if int(int(right_value) in valid_options):
total += idx
else:
histo_modsuffix = [0]*P
previous = 0
for i, val in enumerate(reversed(S)):
scale = pow(10, i, P)
new_val = (previous + scale*int(val))%P
histo_modsuffix[new_val] += 1
previous = new_val
for val in histo_modsuffix:
total += val*(val-1)//2
total += histo_modsuffix[0] # when right hand side is at far end
print(total)
| 1 | 58,288,408,380,060 | null | 205 | 205 |
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[input().split() for l in range(M)]
tot_1=min(a)+min(b)
lis=[]
for i in range(M):
tot=a[int(x[i][0])-1]+b[int(x[i][1])-1]-int(x[i][2])
lis.append(tot)
if tot_1<=min(lis):
print(tot_1)
else:
print(min(lis))
|
a,b,m = map(int,input().split())
r = tuple(map(int,input().split()))
d = tuple(map(int,input().split()))
ans = min(r)+min(d)
for i in range(m):
x,y,c = map(int,input().split())
ans = min(ans,r[x-1]+d[y-1]-c)
print(ans)
| 1 | 53,925,061,622,080 | null | 200 | 200 |
s = input()
if "B" in s:
print("ARC")
else:
print("ABC")
|
S = input()
if S.upper() == "ABC":
print("ARC")
else:
print("ABC")
| 1 | 24,136,867,193,500 | null | 153 | 153 |
def a172(a):
return a + a**2 + a**3
def main():
a = int(input())
print(a172(a))
if __name__ == '__main__':
main()
|
a = int(input().strip())
print(a+a*a+a*a*a)
| 1 | 10,216,225,144,928 | null | 115 | 115 |
N = int(input())
N_List = {i:0 for i in range(1,N+1)}
E_List = list(map(int,input().split()))
for i in E_List:
N_List[i] += 1
for i in N_List.values():
print(i)
|
from math import inf
n = int(input())
A = list(map(int, input().split()))
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] = 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 | 35,176,153,152,890 | 169 | 177 |
x,k,d = list(map(int, input().split()))
amari = abs(x) % d
shou = abs(x) // d
amari_ = abs(amari - d)
if k < shou:
print(abs(x) - d * k)
else:
if (k - shou) % 2 == 0:
print(amari)
else:
print(amari_)
|
import sys
X, K, D = map(int, input().split())
X = abs(X)
if X // D >= K:
print(X - K*D)
sys.exit()
K = K - (X // D)
A = X - X//D*D
if K % 2 == 0:
print(A)
else:
print(abs(A - D))
| 1 | 5,267,588,735,680 | null | 92 | 92 |
def main():
N = int(input())
cnt = 0
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
cnt += 1
else:
cnt = 0
if cnt >= 3:
print("Yes")
return
print("No")
if __name__ == "__main__":
main()
|
n = int(input())
count = 0
for i in range(n):
a,b = map(int,input().split())
if count >2 :
break
elif a==b:
count += 1
else:
count = 0
print('Yes' if count > 2 else 'No')
| 1 | 2,524,327,114,972 | null | 72 | 72 |
n=int(input())
a=list(map(int,input().split()))
sum=[0]*(len(a)+1)
for i in range(len(a)):
sum[i+1]=sum[i]+a[i]
# print(sum)
mini=2020202020
for i in range(len(sum)):
mini=min(mini, abs(sum[i] - (sum[-1] - sum[i])))
print(mini)
|
A=int(input())
l=list(map(int,input().split()))
right=l[0]
left=sum(l[1:])
ans=left-right
for i in range(A-2):
right+=l[i+1]
left-=l[i+1]
ans=min(ans,abs(right-left))
print(ans)
| 1 | 141,720,717,644,738 | null | 276 | 276 |
def north(d):
d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
def west(d):
d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]
def east(d):
d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
def south(d):
d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
F = {'N': north, 'W': west, 'E': east, 'S': south}
d, os = list(map(int, input().split())), input()
for o in os:
F[o](d)
print(d[0])
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????? I
?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
+--+
???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
???|???|
+--+
"""
class Dice:
""" ????????????????????? """
def __init__(self): # ?????????????????????
self.side = [1, 2, 3, 4, 5, 6]
def setDice(self, arr): # ??¢??????????????????
self.side = arr[0:6]
def Turn(self, dir):
s = self.side
if dir == "N": # ????????¢??????
t = [s[1],s[5],s[2],s[3],s[0],s[4]]
elif dir == "S": # ????????¢??????
t = [s[4],s[0],s[2],s[3],s[5],s[1]]
elif dir == "E": # ??±?????¢??????
t = [s[3],s[1],s[0],s[5],s[4],s[2]]
elif dir == "W": # ?\??????¢??????
t = [s[2],s[1],s[5],s[0],s[4],s[3]]
self.side = t
num = list(map(int,input().strip().split()))
cmd = input().strip()
d = Dice()
d.setDice(num)
for c in cmd:
d.Turn(c)
# print("{0} {1}".format(c,d.side[0]))
print(d.side[0])
| 1 | 231,209,506,598 | null | 33 | 33 |
nm = list(map(lambda x:int(x),input().split(" ")))
a = list()
b = list()
count = nm[0]
while count > 0:
a += list(map(lambda x:int(x), input().split(" ")))
count -= 1
count = nm[1]
while count > 0:
b += {int(input())}
count -= 1
for m in range(nm[0]):
c = 0
for k in range(nm[1]):
c += a[k+m*nm[1]]*b[k]
print(c)
|
n,m = [int(i) for i in input().split()]
a = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
a[i] = [int(j) for j in input().split()]
b = [0 for i in range(m)]
for i in range(m):
b[i] = int(input())
for i in range(n):
sum = 0
for j in range(m):
sum += a[i][j] * b[j]
print(sum)
| 1 | 1,169,028,147,258 | null | 56 | 56 |
# -*- coding: utf-8 -*-
"""
A - Can't Wait for Holiday
https://atcoder.jp/contests/abc146/tasks/abc146_a
"""
import sys
def solve(S):
return {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}[S]
def main(args):
S = input()
ans = solve(S)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
|
s = input()
days = ["", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"]
print(days.index(s))
| 1 | 132,909,778,623,140 | null | 270 | 270 |
"""from collections import *
from itertools import *
from bisect import *
from heapq import *
import math
from fractions import gcd"""
import sys
#input = sys.stdin.readline
from heapq import*
N,M=map(int,input().split())
S=list(input())
S.reverse()
idx=0
lst=[]
while idx<N:
for i in range(1,M+1)[::-1]:
if i+idx<=N:
if S[i+idx]=="0":
idx+=i
lst.append(i)
break
else:
print(-1)
exit()
lst.reverse()
print(" ".join([str(i) for i in lst]))
|
h,w,k = map(int,input().split())
s = [list(input()) for i in range(h)]
a = [[0]*w for i in range(h)]
num = 1
for i in range(h):
b = s[i]
if "#" in b:
t = b.count("#")
for j in range(w):
c = b[j]
# print(c)
if c=="#" and t!=1:
a[i][j] = num
num += 1
t -= 1
elif c=="#" and t==1:
a[i][j] = num
t = -1
else:
a[i][j] = num
if t==-1:
num += 1
else:
if i==0:
continue
else:
for j in range(w):
a[i][j] = a[i-1][j]
index = 0
for i in range(h):
if "#" not in s[i]:
index += 1
else:
break
for j in range(index):
for k in range(w):
a[j][k] = a[index][k]
for j in a:
print(*j)
| 0 | null | 141,537,559,149,600 | 274 | 277 |
N = int(input())
locs = []
S = 0
for _ in range(N):
locs.append(list(map(int,input().split())))
for i in range(N):
for j in range(i+1,N):
dis = ((locs[i][0]-locs[j][0])**2 + (locs[i][1]-locs[j][1])**2)**(1/2)
S += dis
print(2*S/N)
|
# -*- coding: utf-8 -*-
import sys
def main():
N = int( sys.stdin.readline() )
c_list = list(sys.stdin.readline().rstrip())
cnt = 0
L = 0
R = len(c_list) - 1
while L < R:
if (c_list[L] == "W") and (c_list[R] == "R"):
c_list[L], c_list[R] = c_list[R], c_list[L]
cnt += 1
L += 1
R -= 1
elif c_list[L] == "R":
L += 1
elif c_list[R] == "W":
R -= 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 77,383,713,348,422 | 280 | 98 |
a = int(raw_input())
b, c = divmod(a, 3600)
d, e = divmod(c, 60)
print ("%d:%d:%d") % (b,d,e)
|
minute = int(input())
print('{}:{}:{}'.format(minute // 3600, (minute % 3600) // 60, (minute % 3600) % 60))
| 1 | 332,872,804,000 | null | 37 | 37 |
num_cnt = int(input().rstrip())
nums = list(map(int, input().rstrip().split(" ")))
for i in range(num_cnt):
tmpNum = nums[i]
j = i -1
while j >=0:
if nums[j] <= tmpNum:
break
nums[j+1] = nums[j]
j = j-1
nums[j+1] = tmpNum
print (" ".join(map(str,nums)))
|
def input_data():
num = raw_input()
array = []
array = num.strip().split(" ")
array = map(int, array)
return array
def main():
n = raw_input()
count = 0
array = input_data()
flag = True
i = 0
while flag:
flag = False
for j in reversed(xrange(i + 1, int(n))):
if array[j] < array[j - 1]:
v = array[j]
array[j] = array[j - 1]
array[j - 1] = v
flag = True
count += 1
i += 1
array = map(str, array)
print " ".join(array)
print str(count)
if __name__ == '__main__':
main()
| 0 | null | 11,213,002,172 | 10 | 14 |
# E - Payment
S = input()
N = len(S)
# 先頭からi桁目までの金額のやり取りに必要な紙幣の枚数
dp = [0]
dp_plus1 = [1]
for i in range(N):
x = int(S[i])
dp.append(min(dp[i] + x, dp_plus1[i] + (10 - x)))
dp_plus1.append(min(dp[i] + (x + 1), dp_plus1[i] + (10 - (x + 1))))
print(dp[-1])
|
'''
Created on 2020/08/20
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
A,B,M=map(int,pin().split())
a=list(map(int,pin().split()))
b=list(map(int,pin().split()))
ans=min(a)+min(b)
for _ in [0]*M:
x,y,c=map(int,pin().split())
t=a[x-1]+b[y-1]-c
if t<ans:
ans=t
print(ans)
return
main()
| 0 | null | 62,495,654,386,748 | 219 | 200 |
import math
def abc158c_tax_increase():
a, b = map(int, input().split())
for i in range(1001):
if math.floor(i*0.08) == a and math.floor(i*0.1) == b:
print(i)
return
print('-1')
abc158c_tax_increase()
|
n = int(input())
# 動的計画法
def fibonacci(n):
F = [0]*(n+1)
F[0] = 1
F[1] = 1
for i in range(2, n+1):
F[i] = F[i-2] + F[i-1]
return F
f = fibonacci(n)
print(f[n])
| 0 | null | 28,192,467,264,608 | 203 | 7 |
# Sheep and Wolves
S, W = map(int, input().split())
print(['safe', 'unsafe'][W >= S])
|
x = [int(x) for x in input().split()]
if (x[1]<x[0]):
print("safe")
else:
print("unsafe")
| 1 | 29,327,702,158,540 | null | 163 | 163 |
last=input()
if last=="ABC":
print("ARC")
elif last=="ARC":
print("ABC")
|
# coding: utf-8
# Here your code !
for i in range(9):
for j in range(9):
print('%sx%s=%s' % ((i+1), (j+1), (i+1)*(j+1)))
| 0 | null | 11,982,264,128,700 | 153 | 1 |
N, K = map(int, input().split())
s = N//K
s1 = abs(N - K*s)
s2 = abs(N - K*(s+1))
print(min(s1, s2))
|
def solve():
N, K = list(map(int, input().split()))
if(N >= K):
tmp = N - ((N // K) * K)
ans = min(tmp, abs(abs(tmp) - K))
elif(N < K):
if(K <= 2*N):
ans = abs(N - K)
else:
ans = abs(N)
print(ans)
if __name__ == "__main__":
solve()
| 1 | 39,091,086,350,172 | null | 180 | 180 |
from collections import deque
H, W = [int(x) for x in input().split()]
field = []
for i in range(H):
field.append(input())
conn = [[[] for _ in range(W)] for _ in range(H)]
for i in range(H):
for j in range(W):
if field[i][j] == '.':
for e in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
h, w = i + e[0], j + e[1]
if 0 <= h < H and 0 <= w < W and field[h][w] == '.':
conn[i][j].append([h, w])
d = 0
for i in range(H):
for j in range(W):
l = 0
q = deque([[i, j]])
dist = [[-1 for _ in range(W)] for _ in range(H)]
dist[i][j] = 0
while q:
v = q.popleft()
for w in conn[v[0]][v[1]]:
if dist[w[0]][w[1]] == -1:
q.append(w)
dist[w[0]][w[1]] = dist[v[0]][v[1]] + 1
l = dist[w[0]][w[1]]
d = max(d, l)
print(d)
|
input()
print('APPROVED' if all(map(lambda x: x % 3 == 0 or x % 5 == 0, filter(lambda x: x % 2 == 0, map(int, input().split())))) else 'DENIED')
| 0 | null | 81,885,961,592,768 | 241 | 217 |
H, W = map(int, input().split())
S = [input() for _ in range(H)]
vis = [[-1 for i in range(W)] for j in range(H)]
que = [(0,0)]
itr = 0
color = "."
if S[0][0]=="#":
itr=1
color="#"
vis[0][0]=itr
while len(que)>0:
v, h = que.pop(0)
itr = vis[v][h]
if itr%2==0:
color="."
else:
color="#"
que2 = []
if v+1 < H:
if S[v+1][h]==color and vis[v+1][h]==-1:
vis[v+1][h] = itr
que2.append((v+1,h))
elif vis[v+1][h]==-1:
vis[v+1][h] = itr +1
que.append((v+1,h))
if h+1 < W:
if S[v][h+1]==color and vis[v][h+1]==-1:
vis[v][h+1] = itr
que2.append((v,h+1))
elif vis[v][h+1]==-1:
vis[v][h+1] = itr+1
que.append((v, h+1))
while len(que2)>0:
v, h = que2.pop(0)
if v+1 < H:
if S[v+1][h]==color and vis[v+1][h]==-1:
vis[v+1][h] = itr
que2.append((v+1,h))
elif vis[v+1][h]==-1:
vis[v+1][h] = itr +1
que.append((v+1,h))
if h+1 < W:
if S[v][h+1]==color and vis[v][h+1]==-1:
vis[v][h+1] = itr
que2.append((v,h+1))
elif vis[v][h+1]==-1:
vis[v][h+1] = itr+1
que.append((v, h+1))
if vis[H-1][W-1]%2 == 0:
print(vis[H-1][W-1]//2)
else:
print((vis[H-1][W-1]+1)//2)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
def main():
INF = 10**9
H, W = input_nums()
ss = [input() for _ in range(H)]
dp = [[0]*W for _ in range(H)]
if ss[0][0] == '#': dp[0][0] = 1
for h in range(H):
for w in range(W):
if (h, w) == (0, 0): continue
u = l = INF
if h-1>=0:
u = dp[h-1][w]
if ss[h][w] == '#' and ss[h-1][w] == '.': u += 1
if w-1>=0:
l = dp[h][w-1]
if ss[h][w] == '#' and ss[h][w-1] == '.': l += 1
dp[h][w] = min(u, l)
print(dp[H-1][W-1])
if __name__ == '__main__':
main()
| 1 | 49,010,484,611,040 | null | 194 | 194 |
x = int(input())
x_ = divmod(x, 100)
if 5*x_[0] >= x_[1]:
print(1)
else:
print(0)
|
n = int(input())
a = n // 100
b = n % 100
check = a > 20 or b / 5 <= a
print("1" if check else "0")
| 1 | 126,746,520,203,906 | null | 266 | 266 |
downs, ponds = [], []
for i, s in enumerate(input()):
if s == "\\":
downs.append(i)
elif s == "/" and downs:
i_down = downs.pop()
area = i - i_down
while ponds and ponds[-1][0] > i_down:
area += ponds.pop()[1]
ponds.append([i_down, area])
print(sum(p[1] for p in ponds))
print(len(ponds), *(p[1] for p in ponds))
|
X = int(input())
def is_prime(n):
if n == 2: return True
if n < 2 or n%2 == 0: return False
m = 3
while m*m <= n:
if n%m == 0: return False
m += 2
return True
while 1:
if is_prime(X):
print(X)
exit()
X += 1
| 0 | null | 52,549,388,844,128 | 21 | 250 |
from numpy import cumsum
N = int(input())
A = list(map(int, input().split()))
a_cum = cumsum(A)
cand = [abs(a_cum[i] - (a_cum[-1] - a_cum[i])) for i in range(N)]
print(min(cand))
|
N=int(input())
A=list(map(int,input().split()))
B=sum(A)
b=0
ans=202020202020
for a in A:
b+=a
ans=min(ans,abs(B-b*2))
print(ans)
| 1 | 142,029,361,513,820 | null | 276 | 276 |
while True:
x = input()
if x == '0':
break
print(sum(int(c) for c in str(x)))
|
N = int(input())
ans = N // 2
if N % 2 == 0: ans -= 1
print(ans)
| 0 | null | 77,653,863,151,030 | 62 | 283 |
n = int(input())
str = ""
while 1:
n, mod = divmod(n, 26)
if mod == 0:
str = 'z' + str
n -=1
else:
str = chr(96+mod) + str
if n == 0:
break
print(str)
|
n = int(input())
s=""
keta=0
n-=1
while 1 :
c = n%26
s=chr( 97+c )+s
if n//26>0 :
n=n//26
n-=1
keta+=1
else:
break
print(s)
| 1 | 11,876,312,756,414 | null | 121 | 121 |
n,k,c = map(int,raw_input().split())
s = raw_input()
most = [0]*(n+1)
i = n
days = 0
while i > 0:
if s[i-1] == 'o':
days += 1
for j in xrange(min(max(1,c),i-1)):
#print days
#print i,j,1,days
most[i-j-1] = days
i -= (c+1)
else:
i -= 1
if i<n:
most[i] = most[i+1]
remain = k
i = 1
while i<=n:
if s[i-1] == 'o':
if most[i] < remain:
print i
remain -= 1
i += c+1
else:
i += 1
|
N, K, C = [int(input_) for input_ in input().split(" ")]
tick_cross = input()
def find_earliest_work_days(K, C, tick_cross):
"""
Find the list of the earliest day in all possible days for the n-th
work day.
Parameters:
K (int): The number of work days.
C (int): Minimum interval between the previous work day and the
next work day.
tick_cross (str): The character string of days he can go to work.
Returns:
List[int]: The list of the earliest day in all possible days for
the n-th work day.
"""
N = len(tick_cross)
day = 0
earliest_work_days = []
number_of_work_days = len(earliest_work_days)
while (day < N) and (number_of_work_days < K):
if tick_cross[day] == "o":
earliest_work_days.append(day+1)
number_of_work_days = len(earliest_work_days)
day += C + 1
else:
day += 1
return earliest_work_days
def find_latest_work_days(K, C, tick_cross):
"""
Find the list of the latest day in all possible days for the n-th
work day.
Parameters
K (int): The number of work days.
C (int): Minimum interval between the previous work day and the
next work day.
tick_cross (str): The character string of days he can go to work.
Returns:
List[int]: The list of the latest day in all possible days for
the n-th work day.
"""
N = len(tick_cross)
day = N - 1
latest_work_days = []
number_of_work_days = len(latest_work_days)
while (day >= 0) and (number_of_work_days < K):
if tick_cross[day] == "o":
latest_work_days.append(day+1)
number_of_work_days = len(latest_work_days)
day -= (C + 1)
else:
day -= 1
return sorted(latest_work_days)
earliest_work_days = find_earliest_work_days(K, C, tick_cross)
latest_work_days = find_latest_work_days(K, C, tick_cross)
for earliest, latest in zip(earliest_work_days, latest_work_days):
if earliest == latest:
print(earliest)
| 1 | 40,802,588,444,198 | null | 182 | 182 |
# 2butan renshuu 0812
def f(m):
cut=0
for aa in a:
cut+=(aa-1)//m
if cut > k:
return False
return True
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=10**9+1
while r-l>1:
m=(l+r)//2
# right move
if f(m):
r=m
else:
l=m
print(r)
|
import sys; input = sys.stdin.readline
from math import ceil
d, t, s = map(int, input().split())
u, l = ceil(d/t), d//t
if u == l:
if u <= s: print("Yes")
else: print("No")
else:
if d/t <= s: print("Yes")
else:print("No")
| 0 | null | 4,963,093,103,620 | 99 | 81 |
X = int(input())
dp = [False]*(X+1)
dp[0] = True
for i in range(100, X+1):
if i < 106:
dp[i] = True
continue
if dp[i-100] or dp[i-101] or dp[i-102] or dp[i-103] or dp[i-104] or dp[i-105]:
dp[i] = True
print(1) if dp[len(dp)-1] else print(0)
|
x = int(input())
q = x // 100
r = x % 100
r -= 5 * q
print(1 if r <= 0 else 0)
| 1 | 127,415,293,624,452 | null | 266 | 266 |
N = int(input())
ans = [0] * N
for i in range(1, 101):
for j in range(1, 101):
for k in range(1, 101):
tmp = i**2+j**2+k**2+i*j+j*k+k*i
if tmp <= N:
ans[tmp-1] += 1
print(*ans, sep='\n')
|
S=input()
T=input()
s=len(S)
t=len(T)
A=[]
for i in range(s-t+1):
word=S[i:i+t]
a=0
for j in range(t):
if word[j]==T[j]:
a+=1
else:
a+=0
A.append(t-a)
print(min(A))
| 0 | null | 5,884,644,492,520 | 106 | 82 |
for i in range(1, 10):
for j in range(1, 10):
print('%dx%d=%d' % (i, j, i*j))
|
import itertools
for i,j in itertools.product(xrange(1,10),repeat=2):
print '{0}x{1}={2}'.format(i,j,i*j)
| 1 | 915,068 | null | 1 | 1 |
s, t = input().split()
print("%s%s" %(t,s))
|
st = input().split(' ')
print(st[1]+st[0])
| 1 | 103,228,147,121,770 | null | 248 | 248 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.