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
|
---|---|---|---|---|---|---|
while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
square = [['#'] * W] * H
for row in square:
print(''.join(row))
print()
|
H,N = map(int,input().split())
A = list(map(int,input().split()))
All = sum(A)
if H - All > 0:
print("No")
else:
print("Yes")
| 0 | null | 39,153,529,084,906 | 49 | 226 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
n=k()
l=l()
a=[]
for i in range(n):
a.append(0)
for i in range(n-1):
a[l[i]-1]+=1
for i in range(n):
print(a[i])
|
N = int(input())
A = list(map(int, input().split()))
result = [0] * N
for a in A:
result[a-1] += 1
for i in range(N):
print(result[i])
| 1 | 32,482,790,431,872 | null | 169 | 169 |
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:X]
q = q[:Y]
all = p + q + r
all.sort(reverse=True)
ans = sum(all[:X + Y])
print(ans)
|
def solve(x, y, a, b, c, p, q, r):
p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]
v = sorted(p[:x] + q[:y])
n = len(v)
t = sum(v)
for i in range(min(n,c)):
if v[i] < r[i]:
t += r[i] - v[i]
return t
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
print(solve(x, y, a, b, c, p, q, r))
| 1 | 44,835,498,944,476 | null | 188 | 188 |
def grade(m, f, r):
if m == -1 or f == -1:
return 'F'
s = m + f
if s >= 80:
return 'A'
elif s >= 65:
return 'B'
elif s >= 50:
return 'C'
elif s < 30:
return 'F'
elif r >= 50:
return 'C'
else:
return 'D'
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
print(grade(m, f, r))
|
n,k=map(int,input().split())
p=[0]+list(map(int,input().split()))
for i in range(n+1):
p[i]=(p[i]+1)/2
for i in range(n):
p[i+1]+=p[i]
ans=0
for i in range(n-k+1):
ans=max(ans,p[i+k]-p[i])
print(ans)
| 0 | null | 38,063,217,639,680 | 57 | 223 |
A = input().split(" ")
B = input().split(" ")
if A[0] == B[0]:
print("0")
else:
print("1")
|
a,b = map (int,input().split())
print(a*b,a+a+b+b)
| 0 | null | 62,511,200,685,570 | 264 | 36 |
w = input()
t = ""
while 1:
try:
t += input().lower()
t += " "
except EOFError:
break
s = t.split()
count = 0
for i in s:
if i == w:
count += 1
print(count)
|
import sys
p = 0
s = 0
for line in sys.stdin:
ls = line.strip('\n')
if ls == 'END_OF_TEXT': break
ls = ls.lower()
if p == 0:
w = ls
p = 1
else:
for word in ls.split():
if word == w: s += 1
print s
| 1 | 1,831,324,169,680 | null | 65 | 65 |
MOD = 10 ** 9 + 7
N = int(input())
A = [int(i) for i in input().split()]
sums = [[0] * 3 for _ in range(N + 1)]
ans = 1
for i, a in enumerate(A):
f = True
count = 0
for j in range(3):
sums[i + 1][j] = sums[i][j]
if sums[i][j] == a:
count += 1
if f:
sums[i + 1][j] += 1
f = False
ans = ans * count % MOD
#print(sums)
print(ans)
|
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
n = int(input())
nums = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(n + 1)]
for num in nums:
ans = ans * cnt[num] % MOD
if ans == 0:
break
cnt[num] -= 1
cnt[num+1] += 1
print(ans)
| 1 | 129,789,097,889,282 | null | 268 | 268 |
from math import gcd
from collections import defaultdict
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
MOD = 1000000007
box = defaultdict(int)
zeros = 0
for a, b in AB:
if a == b == 0:
zeros += 1
else:
if a != 0 and b == 0:
box[(-1, 1, 0)] += 1
elif a == 0 and b != 0:
box[(1, 0, 1)] += 1
else:
g = gcd(a, b)
ga = a // g
gb = b // g
if (a // b) < 0:
s = -1
else:
s = 1
box[(s, abs(ga), abs(gb))] += 1
nakawaru = dict()
others = 0
for (s, i, j), v in box.items():
if (-s, j, i) in box.keys():
if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys():
nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)])
else:
others += v
seed = 1
for i, j in nakawaru.values():
seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1)
seed %= MOD
ans = zeros + pow(2, others, MOD) * seed - 1
ans %= MOD
print(ans)
|
import sys, bisect, collections, math
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def resolve():
N = I()
AB = [LI() for _ in range(N)]
# A, Bを標準化 互いに疎でAは正
def normalize(AB):
A = AB[0]
B = AB[1]
if A==B==0:
return (0, 0)
elif A==0:
return(0, 1)
elif B==0:
return(1, 0)
else:
gcd = math.gcd(A, B)
A //= gcd
B //= gcd
if A<0:
A, B = -A, -B
return (A, B)
def orthogonal(AB):
A = AB[0]
B = AB[1]
if B>0:
return (B, -A)
else:
return(-B, A)
AB_n = [normalize(i) for i in AB]
counter = collections.Counter(AB_n)
# 場合の数を求める
used = set()
ans = 1
# (0, 0)以外について
for A, B in AB_n:
if not (A, B) in used:
if (A, B)!=(0, 0):
ans *= pow(2, counter[(A, B)], MOD) + pow(2, counter[orthogonal((A, B))], MOD) - 1
ans %= MOD
used.add((A, B))
used.add(orthogonal((A, B)))
ans -= 1
# (0, 0)について
ans += counter[(0, 0)]
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
| 1 | 20,826,221,958,852 | null | 146 | 146 |
a = []
while True:
d = list(map(int,input().split()))
if d == [-1,-1,-1]:
break
a.append(d)
def Point2Grade(d):
m,f,r = d
if (m==-1)|(f==-1):
return 'F'
elif m+f >= 80:
return 'A'
elif m+f >= 65:
return 'B'
elif m+f >= 50:
return 'C'
elif m+f >= 30:
if r >=50: return 'C'
else: return 'D'
else: return 'F'
for x in a:
print(Point2Grade(x))
|
N = int(input())
S = input()
abc = S.count('R')*S.count('G')*S.count('B')
L = (N-1)//2
for i in range(1,L+1):
for j in range(N-2*i):
if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
abc -= 1
print(abc)
| 0 | null | 18,571,794,891,398 | 57 | 175 |
n,m=map(int,input().split())
ans=[0 for i in range(n+1)]
list_tonari=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
list_tonari[a].append(b)
list_tonari[b].append(a)
const=list()
const.append(1)
const_vary=list()
while True:
const_vary=const
const=[]
while len(const_vary):
get=const_vary.pop()
for n in list_tonari[get]:
if ans[n] ==0:
ans[n]=get
list_tonari[n].remove(get)
const.append(n)
if len(const)==0:
break
print("Yes")
for n in ans[2:]:
print(n)
|
import sys
from sys import stdin
def I():
return stdin.readline().rstrip()
def MI():
return map(int,stdin.readline().rstrip().split())
def LI():
return list(map(int,stdin.readline().rstrip().split()))
#main part
from collections import deque
n, m =MI()
ans = [-1 for _ in range(n+1)]
ans[0] = 0
ans[1] = 0
V = [[] for _ in range(n+1)]
for _ in range(m):
x, y = MI()
V[x].append(y)
V[y].append(x)
d = deque([1])
while d:
l = d.popleft()
for v in V[l]:
if ans[v] != -1:
continue
ans[v] = l
d.append(v)
if ans.count(-1) > 0:
print('No')
else :
print('Yes')
for i in ans[2:]:
print(i)
| 1 | 20,460,653,479,178 | null | 145 | 145 |
def print0():
print(0)
exit()
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
ans = 1
maxd = max(d)
numcnt = [0] * (maxd + 1)
for i in d:
numcnt[i] += 1
if not d[0] == 0 or not numcnt[0] == 1:
print0()
for i in range(1, maxd + 1):
if numcnt[i] == 0:
print0()
ans *= pow(numcnt[i - 1], numcnt[i], mod)
ans %= mod
print(ans)
|
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
res = 0
else:
dict_D = {}
for d in D:
if d not in dict_D:
dict_D[d] = 0
dict_D[d] += 1
max_D = sorted(D)[-1]
res = 1
parent = 1
for i in range(max_D+1):
if i == 0:
if dict_D[0] != 1:
res = 0
break
else:
if i not in dict_D:
res = 0
break
else:
if i != 1:
res *= (parent**dict_D[i])
res %= mod
parent = dict_D[i]
print(res)
| 1 | 154,595,833,494,880 | null | 284 | 284 |
S=input()
cnt=0
for i in range(len(S)//2):
cnt+=S[i]!=S[-i-1]
print(cnt)
|
S = input()
n = len(S)
c = 0
for i in range(n // 2):
if S[i] != S[n - i - 1]:
c += 1
print(c)
| 1 | 120,072,148,760,090 | null | 261 | 261 |
a,b = map(int,input().split())
for i in range(1,100000):
x = i*8
y = i*10
if x//100 == a and y//100 == b:
print(i)
exit()
print(-1)
|
N = int(input())
A= [0]*110000
sum = 0
for i in map(int, input().split()):
sum += i
A[i] += 1
Q = int(input())
for i in range(Q):
B,C = map(int,input().split())
sum += (C-B)*A[B]
A[C] += A[B]
A[B] = 0
print(sum)
| 0 | null | 34,258,435,450,408 | 203 | 122 |
clr = list(map(int, input().split()))
k = int(input())
for i in range(k):
if clr[2] <= clr[1] :
clr[2] *= 2
elif clr[1] <= clr[0]:
clr[1] *= 2
else:
break
if clr[2] > clr[1] > clr[0] :
print("Yes")
else:
print("No")
|
import sys
n, a, b = map(int, input().split())
mod = 10**9 + 7
sys.setrecursionlimit(10**9)
def f(x):
if x == 0:
return 1
elif x % 2 == 0:
return (f(x // 2) ** 2) % mod
else:
return (f(x - 1) * 2) % mod
def comb(n,k,p):
"""power_funcを用いて(nCk) mod p を求める"""
from math import factorial
if n<0 or k<0 or n<k: return 0
if n==0 or k==0: return 1
a=factorial(n) %p
b=factorial(k) %p
c=factorial(n-k) %p
return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
# 互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a, b):
r = [1, 0, a]
w = [0, 1, b]
while w[2] != 1:
q = r[2] // w[2]
r2 = w
w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
r = r2
w = w2
# [x,y]
return [w[0], w[1]]
# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a, m):
x = extgcd(a, m)[0]
return (m + x % m) % m
def nCm(a):
ans = 1
for i in range(a):
ans *= n - i
ans %= mod
for i in range(1, a+1):
ans *= mod_inv(i, mod)
ans %= mod
return ans
base = f(n)
comb_a = nCm(a)
comb_b = nCm(b)
print((base - comb_a - comb_b - 1) % mod)
| 0 | null | 36,626,783,671,580 | 101 | 214 |
n=int (input())
a=list(input().split(" "))
for i in range(0,n):
print(a[0][i]+a[1][i],end="")
|
import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = map(int, readline().split())
S = [[0] * W for _ in range(H)]
for i in range(H):
S[i] = readline().strip()
dxdy4 = ((-1, 0), (0, -1), (0, 1), (1, 0))
ans = 0
for i in range(H):
for j in range(W):
if S[i][j] == '#':
continue
dist = [[-1] * W for _ in range(H)]
dist[i][j] = 0
queue = deque([(i, j)])
res = 0
while queue:
x, y = queue.popleft()
for dx, dy in dxdy4:
nx, ny = x + dx, y + dy
if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.' and dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
if res < dist[nx][ny]:
res = dist[nx][ny]
queue.append((nx, ny))
if ans < res:
ans = res
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 103,144,993,407,800 | 255 | 241 |
n=int(input())
if n%2==0:
r=0
i=1
while 2*5**i<=n:
r+=n//(2*5**i)
i+=1
print(r)
else:
print(0)
|
n = int(input())
if n%2!=0:
print(0)
else:
cnt = 0
n = n//2
while n>0:
cnt = cnt + (n//5)
n = n//5
print(cnt)
| 1 | 115,732,837,162,812 | null | 258 | 258 |
n,k=map(int,input().split())
r,s,p = map(int,input().split())
T=list(input())
a=[[] for i in range(k)]
for i in range(n):
a[i%k].append(T[i])
score=0
for j in range(k):
b=a[j]
flg=0
for l in range(len(b)):
if l==0:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
else:
if b[l-1]==b[l] and flg==0:
flg=1
continue
elif b[l-1]==b[l] and flg==1:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
elif b[l-1]!=b[l]:
if b[l]=='r':
score+=p
elif b[l]=='s':
score+=r
elif b[l]=='p':
score+=s
flg=0
print(score)
|
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
l = []
for i in range(1, n+1):
l.append(i)
m = []
for j in itertools.permutations(l, n):
m.append(list(j))
for a in range(9*8*7*6*5*4*3*2):
if p == m[a]:
x = a
break
for b in range(9*8*7*6*5*4*3*2):
if q == m[b]:
y = b
break
print(abs(x-y))
| 0 | null | 103,259,784,768,460 | 251 | 246 |
from collections import deque
K = int(input())
q = deque([i for i in range(1, 10)])
for _ in range(K - 1):
# 13print(q)
num = q.popleft()
for i in range(-1,2):
if 0 <= int(str(num)[-1]) + i <= 9:
q.append(num * 10 + int(str(num)[-1]) + i)
print(q[0])
|
from collections import deque
k = int(input())
q = deque(list(range(1,10)))
for i in range(k):
x = q.popleft()
if x%10:
q.append(10*x+(x%10)-1)
q.append(10*x+(x % 10))
if x%10 != 9:
q.append(10*x+(x%10)+1)
print(x)
| 1 | 40,098,988,445,760 | null | 181 | 181 |
#B
A, B, C, D=map(int, input().split())
A_survive=0
C_survive=0
while A>0:
A-=D
A_survive+=1
while C>0:
C-=B
C_survive+=1
if A_survive >= C_survive:
print('Yes')
else:
print('No')
|
A, B, C, D = map(int, input().split())
takahashi = 0
aoki = 0
while C > 0:
C -= B
takahashi += 1
while A > 0:
A -= D
aoki += 1
if takahashi <= aoki:
print("Yes")
else:
print("No")
| 1 | 29,724,881,316,270 | null | 164 | 164 |
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
N, M = mi()
C = li()
'''
# 二次元DP
dp = dp2(float('inf'), N+1, M+1)
dp[0][0] = 0
for i in range(1, M+1):
for j in range(N+1):
#if j == 0:
#dp[i][j] = 0
dp[i][j] = min(dp[i-1][j], dp[i][j])
c = C[i-1]
if j+c <= N:
dp[i][j+c] = min(dp[i][j]+1, dp[i-1][j+c])
#print(dp)
print(dp[M][N])
'''
# 1次元DP
dp = [float('inf') for i in range(N+1)]
dp[0] = 0
for i in range(M):
for j in range(N+1):
c = C[i]
if j+c <= N:
dp[j+c] = min(dp[j]+1, dp[j+c])
print(dp[N])
|
n, m = map(int, input().split())
c = list(map(int, input().split()))
# dp[i][j] = i 番目までを使用して総和がj になる組み合わせ
INF = 5 * 10 ** 4
dp = [[INF] * (n + 1) for _ in range(m + 1)]
dp[0][0] = 0
for i in range(1, m + 1):
for j in range(n + 1):
if j >= c[i - 1]:
dp[i][j] = min(
dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1
)# dp[i - 1][j - c[i - 1]] だと、複数回 コインを使う場合に対応していない
else:
dp[i][j] = dp[i - 1][j]
print(dp[m][n])
| 1 | 137,641,001,280 | null | 28 | 28 |
from sys import exit
from math import gcd
n, m = map(int, input().split())
A = list(map(int, input().split()))
Count = [0] * n
div_A = [a // 2 for a in A]
def lcm(x, y):
return (x * y) // gcd(x, y)
for i, a in enumerate(div_A):
while a % 2 == 0:
Count[i] += 1
a //= 2
if len(set(Count)) != 1:
print(0)
exit()
lcm_num = 1
for div_a in div_A:
lcm_num = lcm(div_a, lcm_num)
if lcm_num > m:
print(0)
exit()
else:
print((m + lcm_num) // (2 * lcm_num))
|
n,m=map(int, input().split())
a=[int(x) for x in input().split()]
kaisuu=0
for i in a:
zantei=0
while True:
if i%2==0:
zantei+=1
i//=2
else:
break
if kaisuu==0:
kaisuu=zantei
else:
if kaisuu!=zantei:
print(0)
exit()
sks=a[0]//2
import math
for i in range(1,len(a)):
sks=sks*(a[i]//2)//(math.gcd(sks,a[i]//2))
ans=int(m/(2*sks)+(1/2))
print(ans)
| 1 | 102,030,752,880,320 | null | 247 | 247 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
mod=10**9+7
inv_t=[0,1]
factorial=[1,1]
factorial_re=[1,1]
for i in range(2,N+1):
inv_t.append(inv_t[mod%i]*(mod-mod//i)%mod)
for i in range(2,N+1):
factorial.append(factorial[i-1]*i%mod)
factorial_re.append(factorial_re[i-1]*inv_t[i]%mod)
ans=0
for i in range(N-K+1):
if i==N-K:
ans+=A[i]
ans%=mod
break
ans+=A[i]*factorial[N-1-i]*factorial_re[K-1]*factorial_re[N-K-i]%mod
ans%=mod
for i in range(N-K+1):
if i==N-K:
ans-=A[N-i-1]
ans%=mod
break
ans-=A[N-i-1]*factorial[N-1-i]*factorial_re[K-1]*factorial_re[N-K-i]%mod
ans%=mod
print(ans)
|
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N, K = map(int,input().split())
As = list(map(int,input().split()))
As.sort()
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
rlt = 0
for i in range(N-K+1):
rlt += (As[-i-1] - As[i])*cmb(N-i-1,K-1,p)
rlt %= p
print(rlt)
| 1 | 95,419,595,992,130 | null | 242 | 242 |
n = int(input())
lis=[]
for _ in range(n):
x,l = map(int,input().split())
lis.append([x+l,x-l])
lis.sort()
m = -(10**9+7)
ans = 0
for i in range(n):
a ,b = lis[i]
if m <= b:
ans += 1
m = a
print(ans)
|
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)
| 1 | 90,054,373,303,088 | null | 237 | 237 |
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions import gcd
#input=sys.stdin.readline
import bisect
s=input()
t=input()
n=len(s)
ans=0
for i in range(n):
if s[i]!=t[i]:
ans+=1
print(ans)
|
s=input()
t=input()
count=0
for i in range(0,len(s)):
if(s[i]==t[i]):
continue
else:
count+=1
print(count)
| 1 | 10,387,814,376,800 | null | 116 | 116 |
x,y,z = map(int, input().split())
x = x^y
y = x^y
x = x^y
x = z^x
z = z^x
x = z^x
print("{} {} {}".format(x,y,z))
|
x = [int(x) for x in input().split()]
print(x[2],x[0],x[1])
| 1 | 37,978,854,913,572 | null | 178 | 178 |
N, K = map(int, input().split())
if N < K:
print(min(abs(N - K), N))
else:
div, mod = divmod(N, K)
print(min(abs(mod-K), mod))
|
n,k=map(int,input().split())
print(min(n%k,-n%k))
| 1 | 39,304,827,536,020 | null | 180 | 180 |
from itertools import *
N = int(input())
H = []
A = []
for i in range(N):
for j in range(int(input())):
x,y = map(int, input().split())
H+=[[i,x-1,y]]
for P in product([0,1],repeat=N):
for h in H:
if P[h[0]]==1 and P[h[1]]!=h[2]:
break
else:
A+=[sum(P)]
print(max(A))
|
import sys
sys.setrecursionlimit(200001)
N, M = [int(n) for n in input().split()]
S = input()
p1 = False
x1 = 0
m1 = N
c1 = 0
for n in S:
if n == "1":
if p1:
c1 += 1
else:
c1 = 1
p1 = True
else:
p1 = False
if c1 > 0:
if c1 > x1:
x1 = c1
if c1 < m1:
m1 = c1
def rest(l, ans):
s = M
while s > 0:
if s >= l:
ans.append(l)
return ans
if S[l-s] == "1":
if s == 1:
return -1
s -= 1
continue
l -= s
if rest(l, ans) == -1:
s -= 1
else:
ans.append(s)
return ans
return -1
if x1 > M - 1:
ans = -1
else:
ans = rest(N, [])
if ans == -1:
print(-1)
else:
print(" ".join([str(n) for n in ans]))
| 0 | null | 130,407,033,436,410 | 262 | 274 |
N, K = map(int, input().split())
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7
pos = sorted(v for v in X if v >= 0)
neg = sorted(-v for v in X if v < 0)
if N == K:
ans = 1
for x in X:
ans *= x
ans %= MOD
print(ans % MOD)
exit()
ok = False # True: ans>=0, False: ans<0
if pos:
#正の数があるとき
ok = True
else:
#全部負-> Kが奇数なら負にならざるをえない。
ok = (K % 2 == 0)
ans = 1
if ok:
# ans >= 0
if K % 2 == 1:
#Kが奇数の場合初めに1つ正の数を掛けておく
#こうすれば後に非負でも負でも2つずつのペアで
#考えられる
ans = ans * pos.pop() % MOD
# 答えは非負になる→二つの数の積は必ず非負になる.
cand = []
while len(pos) >= 2:
x = pos.pop() * pos.pop()
cand.append(x)
while len(neg) >= 2:
x = neg.pop() * neg.pop()
cand.append(x)
cand.sort(reverse=True) # ペアの積が格納されているので必ず非負
# ペア毎に掛けていく
for i in range(K // 2):
ans = ans * cand[i] % MOD
else:
# ans <= 0
cand = sorted(X, key=lambda x: abs(x))
for i in range(K):
ans = ans * cand[i] % MOD
print(ans)
|
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
ans=1
i=0
j=-1
k_1=k
while k_1>1:
if a[i]*a[i+1]>a[j]*a[j-1]:
ans=ans*a[i]*a[i+1]%mod
i+=2
k_1-=2
else:
ans=ans*a[j]%mod
j-=1
k_1-=1
if k_1==1:
ans=ans*a[j]%mod
if a[-1]<0 and k%2==1:
ans=1
for i in a[n-k:]:
ans=ans*i%mod
print(ans)
| 1 | 9,378,773,846,788 | null | 112 | 112 |
a = [int(input()) for i in range(2)]
if a[0] == 1:
if a[1] == 2:
my_result = 3
else:
my_result = 2
elif a[0] == 2:
if a[1] == 1:
my_result = 3
else:
my_result = 1
else:
if a[1] == 1:
my_result = 2
else:
my_result = 1
print(my_result)
|
a = input()
b = input()
if '1' not in [a, b]:
print('1')
if '2' not in [a, b]:
print('2')
if '3' not in [a, b]:
print('3')
| 1 | 110,421,188,402,108 | null | 254 | 254 |
a,b,c = map(int, input().split())
print("Yes") if b * c >= a else print("No")
|
import numpy as np
N, T = map(int, input().split())
menu = []
for _ in range(N):
m = tuple(map(int, input().split()))
menu.append(m)
menu = sorted(menu, key=lambda m: m[0])
# 料理i-1をj-1分までに完食するときの満足度最大値
dp = np.zeros((N, T), dtype='int64')
anss = []
for i in range(1, N):
# 一つまえのメニューについて
ai, bi = menu[i-1]
dp[i][:ai] = dp[i-1][:ai] # 時間が足りないので注文しない
dp[i][ai:] = np.fmax(
dp[i-1][ai:], # 何も注文しない
dp[i-1][:-ai] + bi # 注文した場合, ai分かかっても大丈夫な範囲から取得
)
# 加えて自身を最後に食べた場合を記録
anss.append(dp[i][-1] + menu[i][1])
print(max(anss))
| 0 | null | 77,260,711,009,388 | 81 | 282 |
n,k=map(int,input().split())
result=''
while n>=1:
b=n%k
result+=str(b)
n//=k
print(len(result))
|
X,n = map(int,input().split(" "))
def Base_10_to_n(X, n):
if (int(X/n)):
return Base_10_to_n(int(X/n), n)+str(X%n)
return str(X%n)
a=Base_10_to_n(X, n)
print(len(str(a)))
| 1 | 64,591,331,645,012 | null | 212 | 212 |
import math
r = float(input())
area = math.pi*r**2
circuit = 2*math.pi*r
print"%f %f" % (area, circuit)
|
num=input()
numline=list(num)
a=int(numline[len(numline)-1])
if(a==3):
print("bon")
elif(a==0 or a==1 or a==6 or a==8):
print("pon")
else:
print("hon")
| 0 | null | 10,047,338,565,352 | 46 | 142 |
a=input()
print(a+"e"*(a[-1]=='s')+'s')
|
#
# 179A
#
s = input()
s1 = list(s)
if s1[len(s)-1]=='s':
print(s+'es')
else:
print(s+'s')
| 1 | 2,390,164,785,568 | null | 71 | 71 |
def main():
n = int(input())
s = input()
one_set = set([])
two_set = set([])
three_set = set([])
count = 0
for i in range(n):
if i==0:
one_set.add(s[0])
continue
if 2<=i:
for two in two_set:
if two + s[i] not in three_set:
three_set.add(two + s[i])
count+=1
for one in one_set:
two_set.add(one + s[i])
one_set.add(s[i])
print(count)
if __name__=="__main__":
main()
|
n,x,y = map(int,input().split())
l= [0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
k = min(abs(j-i),abs(x-i)+1+abs(j-y))
l[k] += 1
for k in range(1,n):
print(l[k])
| 0 | null | 86,758,553,888,090 | 267 | 187 |
X, Y =map(int,input().split())
a = 0
for i in range(X+1):
if 2*i+4*(X-i)==Y:
print('Yes')
else:
a +=1
if a ==X+1:
print('No')
|
# -*- coding: utf-8 -*-
N=input()
#約数列挙
def make_divisors(n):
divisors=[]
for i in range(1, int(n**0.5)+1):
if n%i==0:
divisors.append(i)
if i!=n/i:
divisors.append(n/i)
return divisors
#整数N-1の約数は全て答えにカウントして良い
ans=set(make_divisors(N-1))
wrong_ans=set(make_divisors(N-1))
K=make_divisors(N) #Nの約数の集合
#整数Nの約数について条件にマッチングするかを1つ1つ調べる
for k in K:
if k==1: continue
n=N
while n%k==0:
n/=k
else:
if n==1 or n%k==1:
ans.add(k)
print len(ans)-1
| 0 | null | 27,618,715,138,612 | 127 | 183 |
a = input()
b = input()
print(a == b[:-1] and "Yes" or "No")
|
N=int(input())
C=10000-N
Ch=C%1000
print(Ch)
| 0 | null | 14,891,966,694,738 | 147 | 108 |
# import math
# import statistics
# a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
# c.append(i)
e1,e2,e3 = map(int,input().split())
# f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
# h = []
# for i in range(e1):
# h.append(list(map(int,input().split())))
ba1=e1//(e2+e3)
ba2=e1-ba1*(e2+e3)
if ba2<=e2:
print(ba2+ba1*e2)
elif ba2>e2:
print(e2+ba1*e2)
|
X = list(map(int, input().split()))
if X[0] == 0:
print(1)
elif X[1] == 0:
print(2)
elif X[2] == 0:
print(3)
elif X[3] == 0:
print(4)
else:
print(5)
| 0 | null | 34,587,570,965,402 | 202 | 126 |
import sys
sys.setrecursionlimit(10**7)
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return 0
for x in map(chr, range(97, ord(max(s))+2)):
dfs(s+x)
dfs('a')
|
s="abcdefghij"
n=int(input())
ans=[["a",1]]
c=1
while(c<n):
an=[]
for i in ans:
lim=min(i[1]+1,10)
for j in range(lim):
if (j==i[1]) and (j!=10):
an.append([i[0]+s[j],i[1]+1])
else:
an.append([i[0]+s[j],i[1]])
ans=an
c+=1
for i in ans:
print(i[0])
| 1 | 52,476,019,986,180 | null | 198 | 198 |
a = int(input())
b =int(input())
set_ = set([1,2,3])
set_.remove(a)
set_.remove(b)
print(set_.pop())
|
a = int(input())
b = int(input())
ab = a + b
if ab == 3:
print(3)
elif ab == 4:
print(2)
else:
print(1)
| 1 | 110,712,876,202,810 | null | 254 | 254 |
def main():
global s,ide_ele,num,seg
n = int(input())
s = list(input())
for i in range(n):
s[i] = ord(s[i])-97
ide_ele = 0
num = 2**(n-1).bit_length()
seg = [[ide_ele for _ in range(2*num)] for _ in range(26)]
for i in range(n):
seg[s[i]][i+num-1] = 1
for a in range(26):
for i in range(num-2,-1,-1) :
seg[a][i] = max(seg[a][2*i+1],seg[a][2*i+2])
q = int(input())
for _ in range(q):
QUERY = list(input().split())
QUERY[0], QUERY[1] = int(QUERY[0]), int(QUERY[1])
if QUERY[0] == 1:
x = ord(QUERY[2])-97
k = QUERY[1]-1
pre = s[k]
s[k] = x
k += num-1
seg[pre][k] = 0
seg[x][k] = 1
while k:
k = (k-1)//2
seg[pre][k] = max(seg[pre][k*2+1],seg[pre][k*2+2])
seg[x][k] = max(seg[x][k*2+1],seg[x][k*2+2])
if QUERY[0] == 2:
P, Q = QUERY[1]-1, int(QUERY[2])
if Q <= P:
print(ide_ele)
break
P += num-1
Q += num-2
ans = ide_ele
for i in range(26):
res = ide_ele
p,q = P,Q
while q-p > 1:
if p&1 == 0:
res = max(res,seg[i][p])
if q&1 == 1:
res = max(res,seg[i][q])
q -= 1
p = p//2
q = (q-1)//2
if p == q:
res = max(res,seg[i][p])
else:
res = max(max(res,seg[i][p]),seg[i][q])
ans += res
print(ans)
if __name__ == "__main__":
main()
|
import sys
readline = sys.stdin.readline
from bisect import bisect_left, insort_left
def main():
n = int(readline())
s = list(readline().rstrip())
q = int(readline())
chk_abc = [[] for i in range(26)]
for i, si in enumerate(s):
ci = ord(si) - 97
chk_abc[ci].append(i)
ans = []
for _ in range(q):
cmd, i, j = readline().rstrip().split()
i = int(i) - 1
if cmd == "1":
if s[i] == j:
continue
c1 = ord(s[i]) - 97
prev = chk_abc[c1]
c2 = ord(j) - 97
prev.pop(bisect_left(prev, i))
s[i] = j
insort_left(chk_abc[c2], i)
else:
j = int(j) - 1
num = 0
for chk in chk_abc:
le = len(chk)
k = bisect_left(chk, i, 0, le)
if k == le:
continue
if i <= chk[k] <= j:
num += 1
ans.append(num)
print(*ans, sep="\n")
if __name__ == "__main__":
main()
| 1 | 62,542,370,843,930 | null | 210 | 210 |
s=int(raw_input())
print str(s//3600)+':'+str(s//60%60)+':'+str(s%60)
|
n = input()
ans = 0
for i,j in enumerate(map(int,input().split())):
ans += (~i&1 and j&1)
print(ans)
| 0 | null | 3,999,109,769,392 | 37 | 105 |
from operator import mul
from functools import reduce
def comb(n, r):
if n<r:
return 0
r = min(r, n - r)
numer = reduce(mul, range(n, n - r, -1), 1)
denom = reduce(mul, range(1, r + 1), 1)
return numer // denom
N,M=map(int,input().split())
# odd+odd
odd_odd = comb(M,2)
# even+even
even_even = comb(N,2)
print(odd_odd+even_even)
|
n,m=map(int,input().split())
ans=0
ans+=n*(n-1)//2
ans+=m*(m-1)//2
print(ans)
| 1 | 45,752,301,122,700 | null | 189 | 189 |
# Bubble sort: ALDS1_2_A
def bsort(A, N):
flag = 1
swap = 0
while flag:
flag = 0
for j in reversed(range(1, N)):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
flag = 1
swap += 1
return swap
N = int(raw_input())
A = [int(i) for i in raw_input().split()]
swap = bsort(A, N)
print " ".join([repr(i) for i in A])
print swap
|
N, A, B = map(int, input().split(' '))
if N - N // (A + B) * (A + B) > A:
tail = A
else:
tail = N - N // (A + B) * (A + B)
print(N // (A + B) * A + tail)
| 0 | null | 27,958,398,398,800 | 14 | 202 |
from functools import lru_cache
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int,read().split())
@lru_cache(None)
def F(N, K):
if N < 10:
if K == 0:
return 1
if K == 1:
return N
return 0
q, r = divmod(N, 10)
ret = 0
if K >= 1:
ret += F(q, K-1) * r
ret += F(q-1, K-1) * (9-r)
ret += F(q, K)
return ret
print(F(N, K))
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def solve(N: int, K: int):
NL = list(map(int, N))
useMaxDigits = [[0 for i in range(K+1)] for j in range((len(N)+1))]
noUseMaxDigits = [[0 for i in range(K+1)]
for j in range((len(N)+1))]
useMaxDigits[0][0] = 1
for digit in range(1, len(N)+1):
D = NL[digit-1]
# Use Max continueingly
if D != 0:
for i in range(1, K+1):
useMaxDigits[digit][i] = useMaxDigits[digit-1][i-1]
for i in range(0, K+1):
noUseMaxDigits[digit][i] = useMaxDigits[digit-1][i]
else:
for i in range(0, K+1):
useMaxDigits[digit][i] = useMaxDigits[digit-1][i]
# Use non max
for i in range(0, K+1):
# if use zero
noUseMaxDigits[digit][i] += noUseMaxDigits[digit-1][i]
for i in range(1, K+1):
noUseMaxDigits[digit][i] += noUseMaxDigits[digit-1][i-1]*9
for i in range(1, K+1):
noUseMaxDigits[digit][i] += useMaxDigits[digit -
1][i-1]*max(0, D-1)
print(useMaxDigits[-1][-1]+noUseMaxDigits[-1][-1])
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = next(tokens) # type: int
K = int(next(tokens)) # type: int
solve(N, K)
if __name__ == '__main__':
main()
| 1 | 76,151,005,320,852 | null | 224 | 224 |
a,b=map(int,input().split())
for i in range(2000):
if int(i*0.08)==a and int(i*0.1)==b:
print(i)
exit()
print("-1")
|
class Combination:
def __init__(self, n_max, mod=10 ** 9 + 7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max + 1):
f = f * i % mod
fac.append(f)
f = pow(f, mod - 2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def nCr(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def resolve():
# 各集合Sのmax(S) - min(S)の合計を求める
# 各A[i]が最大値になる回数、最小値になる回数を求め、それを計算する
MOD = 10**9+7
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
Comb = Combination(N)
ans = 0
for i in range(N):
# 最大値になる組み合わせは、A[j]: 0 < j < iからK - 1個を選ぶ組み合わせ
ans += Comb.nCr(i, K-1) * A[i] % MOD
ans %= MOD
# 最小値になる組み合わせは、A[j]: i < j < nからK-1個を選ぶ組み合わせ
ans -= Comb.nCr(N-i-1, K - 1) * A[i]% MOD
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
| 0 | null | 76,076,985,033,210 | 203 | 242 |
A = []
hit = []
for _ in range(3):
A.append(list(map(int, input().split())))
hit.append([False]*3)
N=int(input())
for _ in range(N):
b = int(input())
for i in range(3):
for j in range(3):
if A[i][j] == b:
hit[i][j] = True
break
for i in range(3):
if hit[i][0] and hit[i][1] and hit[i][2]:
print('Yes')
exit()
if hit[0][i] and hit[1][i] and hit[2][i]:
print('Yes')
exit()
if hit[1][1]:
if hit[0][0] and hit[2][2] or hit[2][0] and hit[0][2]:
print('Yes')
exit()
print('No')
|
# coding: utf-8
def solve(*args: str) -> str:
k = int(args[0])
l = 9*(k//7 if k % 7 == 0 else k)
if l % 2 == 0 or l % 5 == 0:
return '-1'
r = phi = l
for i in range(2, int(-pow(l, 1/2))):
if r % i == 0:
phi = phi//i*(i-1)
while r % i:
r //= i
a = 10 % l
ret = 1
while(a != 1):
a = a*10 % l
ret += 1
if phi < ret:
ret = -1
break
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
| 0 | null | 32,789,858,375,648 | 207 | 97 |
def is_ok(x):
trainings = 0
for i in range(N):
t = A[i] - x // F[i]
if t > 0:
trainings += t
return trainings <= K
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 = A[-1] * F[0]
while ok - ng > 1:
m = ng + (ok - ng) // 2
if is_ok(m):
ok = m
else:
ng = m
print(ok)
|
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 = -1
r = 10 ** 13
while r - l > 1:
m = (l + r) // 2
if sum([(a - m // f) if a * f > m else 0 for a, f in zip(A, F)]) <= k:
r = m
else:
l = m
print(r)
| 1 | 164,586,078,734,362 | null | 290 | 290 |
# -*- coding: utf-8 -*-
from collections import deque
n = int(raw_input())
que = deque()
for i in range(n):
com = str(raw_input())
if com == "deleteFirst":
del que[0]
elif com == "deleteLast":
del que[-1]
else:
c, p = com.split()
if c == "insert":
que.appendleft(p)
else:
try: que.remove(p)
except: pass
print " ".join(map(str, que))
|
W,H,x,y,r = [int(s) for s in input().split()]
if 0 <= (x-r) <= (x+r) <= W:
if 0 <= (y-r) <= (y+r) <= H:
print("Yes")
else:
print("No")
else:
print("No")
| 0 | null | 247,747,218,588 | 20 | 41 |
'''
l = input().split()
l = list(map(int, l))
a,b,c = l[0],l[1],l[2]
'''
a,b,c = map(int, input().split())
if a > b:
a,b = b,a
if b > c:
b,c = c,b
if a > b:
a,b = b,a
print(a,b,c)
|
x = map(int, raw_input().split())
x.sort()
print "%d %d %d" %(x[0],x[1],x[2])
| 1 | 412,253,664,900 | null | 40 | 40 |
while True:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for i in range(H):
if i == 0 or i == H -1:
print "#" * W
else:
print "#" + "."*(W-2) + "#"
print
|
import math
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**5+5
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 )
N,K = list(map(int,input().split()))
A = sorted(tuple(map(int,input().split())))
B = tuple(A[i+1]-A[i] for i in range(len(A)-1))
lim = math.ceil(len(B)/2)
L = 10**9+7
ans = 0
multi = cmb(N,K,mod)
for j in range(lim):
front = j + 1
back = N - front
tmp_b = 0
tmp_f = 0
if front >= K:
tmp_f = cmb(front,K,mod)
if back >= K:
tmp_b = cmb(back,K,mod)
if j == (len(B)-1)/2:
ans += (multi - tmp_b - tmp_f)*(B[j]) % L
else:
ans += (multi - tmp_b - tmp_f)*(B[j]+B[len(B)-1-j]) % L
print(ans%L)
| 0 | null | 48,050,013,872,670 | 50 | 242 |
n=int(input())
a=list(map(int,input().split()))
for i in a:
if i%2==0 and i%3!=0 and i%5!=0:
print("DENIED")
exit()
print("APPROVED")
|
n=int(input())
num=list(map(int,input().split()))
num2=[]
for i in num:
if i%2==0:
num2.append(i)
num3=[]
for j in num2:
if j%3==0 or j%5==0:
num3.append(0)
elif j%3!=0 or j%5!=0:
num3.append(1)
a=sum(num3)
if a==0:
print("APPROVED")
elif a!=0:
print("DENIED")
| 1 | 68,776,845,359,420 | null | 217 | 217 |
import numpy as np
N, M = list(map(int, input().split()))
A = [int(_) for _ in input().split()]
x = np.zeros(2 ** 18)
for a in A:
x[a] += 1
y = np.fft.fft(x)
for k in range(len(y)):
y[k] *= y[k]
x = np.fft.ifft(y).real
happiness = 0
for i in reversed(range(0, len(x))):
happiness += i * min(int(x[i] + 0.5), M)
M -= int(x[i] + 0.5)
if M <= 0:
break
print(happiness)
|
h,w,k=map(int,input().split())
ans=10**9
choco=[list(input()) for i in range(h)]
sumL=[[0 for i in range(w+1)] for j in range(h+1)]
for i in range(h):
for j in range(w):
sumL[i][j]=sumL[i-1][j]+sumL[i][j-1]-sumL[i-1][j-1]+int(choco[i][j])
for stat in range(2**(h-1)):
cnt=0;previous=-1
flg=0
cut=format(stat,"b").zfill(h-1)
cutl=[]
for hi in range(h-1):
if cut[hi]=="1":
cutl.append(hi)
cnt+=1
cutl.append(h-1)
cutl.append(-1)
for yoko in range(w):
for seg in range(len(cutl)):
if sumL[cutl[seg]][yoko]-sumL[cutl[seg]][previous]-sumL[cutl[seg-1]][yoko]+sumL[cutl[seg-1]][previous]>k and yoko-previous<=1:flg=1
elif sumL[cutl[seg]][yoko]-sumL[cutl[seg]][previous]-sumL[cutl[seg-1]][yoko]+sumL[cutl[seg-1]][previous]>k:previous=yoko-1;cnt+=1
if not flg and cnt < ans:ans=cnt
print(ans)
| 0 | null | 78,120,104,903,804 | 252 | 193 |
import bisect
from math import ceil
class BinaryIndexedTree():
def __init__(self, max_n):
self.size = max_n + 1
self.tree = [0] * self.size
self.depth = self.size.bit_length()
def initialize(self, seq):
for i, x in enumerate(seq[1:], 1):
self.tree[i] += x
j = i + (i & (-i))
if j < self.size:
self.tree[j] += self.tree[i]
def __repr__(self):
return self.tree.__repr__()
def get_sum(self, i):
s = 0
while i:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i < self.size:
self.tree[i] += x
i += i & -i
def find_kth_element(self, k):
x, sx = 0, 0
dx = (1 << self.depth)
for i in range(self.depth - 1, -1, -1):
dx = (1 << i)
if x + dx >= self.size:
continue
y = x + dx
sy = sx + self.tree[y]
if sy < k:
x, sx = y, sy
return x + 1
n,d,a = map(int,input().split())
monster = sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[0])
x_list = [0]+[monster[i][0] for i in range(n)]+[float("inf")]
h_list = [0]+[monster[i][1] for i in range(n)]+[float("inf")]
bit = BinaryIndexedTree(n+2)
ans = 0
for i in range(1,n+1):
hp = h_list[i] - bit.get_sum(i)
if hp < 0:
continue
atk_time = ceil(hp/a)
ans += atk_time
top = bisect.bisect_right(x_list, x_list[i]+2*d)
bit.add(i, atk_time*a)
bit.add(top, -atk_time*a)
print(ans)
|
def resolve():
N, X, Y = list(map(int, input().split()))
X -= 1
Y -= 1
dists = [[0 for _ in range(N)] for __ in range(N)]
for i in range(N):
for j in range(i+1, N):
dists[i][j] = min(j-i, abs(X-i)+abs(Y-j)+1)
counts = [0 for _ in range(N)]
for i in range(N):
for j in range(i+1, N):
counts[dists[i][j]] += 1
for i in range(1, N):
print(counts[i])
if '__main__' == __name__:
resolve()
| 0 | null | 63,094,545,964,802 | 230 | 187 |
a, b = map(int, raw_input().split())
print a*b
|
n = int(input())
s = input()
rs = s.count('R')
oks = s[:rs].count('R')
print(rs - oks)
| 0 | null | 11,093,005,940,992 | 133 | 98 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
mod=10**9+7
inv_t=[0,1]
factorial=[1,1]
factorial_re=[1,1]
for i in range(2,N+1):
inv_t.append(inv_t[mod%i]*(mod-mod//i)%mod)
for i in range(2,N+1):
factorial.append(factorial[i-1]*i%mod)
factorial_re.append(factorial_re[i-1]*inv_t[i]%mod)
ans=0
for i in range(N-K+1):
if i==N-K:
ans+=A[i]
ans%=mod
break
ans+=A[i]*factorial[N-1-i]*factorial_re[K-1]*factorial_re[N-K-i]%mod
ans%=mod
for i in range(N-K+1):
if i==N-K:
ans-=A[N-i-1]
ans%=mod
break
ans-=A[N-i-1]*factorial[N-1-i]*factorial_re[K-1]*factorial_re[N-K-i]%mod
ans%=mod
print(ans)
|
#!/usr/bin/env python3
from itertools import accumulate
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
p = 10**9 + 7
if K == 1:
print(0)
exit()
a = [None] * (N+1)
inva = [None] * (N+1)
a[0] = 1
for i in range(1, N+1):
a[i] = i * a[i-1] % p
inva[N] = pow(a[N],p-2,p)
for i in range(N):
inva[N-i-1] = inva[N-i] * (N-i) % p
ans = 0
maxA = list(accumulate(A[::-1]))
minA = list(accumulate(A))
# print(A)
# print(maxA)
# print(minA)
# if K > 2:
# maxA = sum(A[N-(K-2):])
# minA = sum(A[:K-2])
for i in range(K-1,N):# 1つ隣どうしからN-1つ隣まで
j = min(i,N-i)
# print(i,j,maxA[j-1],minA[j-1])
tmp = (a[i-1]*inva[K-2] % p) * inva[i-K+1] % p
ans += (maxA[j-1]-minA[j-1]) * tmp % p
ans %= p
print(ans)
if __name__ == "__main__":
main()
| 1 | 95,285,332,264,248 | null | 242 | 242 |
alphabet = input()
if alphabet.isupper():
print('A')
else:
print('a')
|
def main():
n = int(input())
dictionary = set()
for _ in range(n):
order, code = input().split()
if order == 'insert':
dictionary.add(code)
elif order == 'find':
if code in dictionary:
print('yes')
else:
print('no')
else:
raise Exception('InputError')
if __name__ == '__main__':
main()
| 0 | null | 5,750,715,218,960 | 119 | 23 |
import bisect,collections,copy,heapq,itertools,math,numpy,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())
N = I()
A = LI()
ans_list = [0] * N
for a in A:
ans_list[a - 1] += 1
for i in range(N):
print(ans_list[i])
|
n = int(input())
s = str(input())
ok = "Yes"
if n == 1:
ok = "No"
if n % 2 == 1:
ok = "No"
for i in range (0, n//2):
if s[i] != s[i + n // 2] :
ok = "No"
print(ok)
| 0 | null | 89,766,036,559,060 | 169 | 279 |
floor = [
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
]
s = '####################'
n = int(input())
for c in range(n):
(b,f,r,v) = [int(x) for x in input().split()]
if 1 > b > 5 and 1 > f > 4 and 1 > r > 10:
break
floor[b-1][f-1][r-1] += v
for z in range(4):
for i in range(len(floor[z])):
for v in floor[z][i]:
print(end=' ')
print(v, end='')
print()
if not z == 3:
print(s)
|
n = int(input())
room_list = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
b, f, r, v = map(int, input().split())
room_list[b - 1][f - 1][r - 1] += v
output =[]
for i in range(4):
for j in range(3):
output = list(map(str, room_list[i][j]))
print(" " + " ".join(output))
if i < 3:
print("#" * 20)
| 1 | 1,106,390,664,676 | null | 55 | 55 |
def gcd(aa,bb):
while bb!=0:
r=bb
bb=aa%bb
aa=r
return aa
a,b=map(int,raw_input().strip().split())
#print a,b
print gcd(a,b)
|
s = input()
a = [-1] * (len(s) + 1)
if s[0] == "<":
a[0] = 0
if s[-1] == ">":
a[-1] = 0
for i in range(len(s) - 1):
if s[i] == ">" and s[i + 1] == "<":
a[i + 1] = 0
for i in range(len(a)):
if a[i] == 0:
l = i - 1
while 0 <= l - 1:
if s[l] == ">" and s[l - 1] == ">":
a[l] = a[l + 1] + 1
else:
break
l -= 1
r = i + 1
while r + 1< len(a):
if s[r - 1] == "<" and s[r] == "<":
a[r] = a[r - 1] + 1
else:
break
r += 1
for i in range(len(a)):
if a[i] == -1:
if i == 0:
a[i] = a[i + 1] + 1
elif i == len(a) - 1:
a[i] = a[i - 1] + 1
else:
a[i] = max(a[i - 1], a[i + 1]) + 1
ans = sum(a)
print(ans)
| 0 | null | 77,852,773,331,228 | 11 | 285 |
N = int(input())
ans = 'No'
for i in range(1,10):
if N%i == 0:
tmp = str(int(N/i))
if len(tmp) >= 2:
continue
else:
ans = 'Yes'
break
else:
continue
print(ans)
|
A,B,C = map(int, input().split())
print('{} {} {}'.format(C,A,B))
| 0 | null | 99,113,730,230,974 | 287 | 178 |
import bisect, copy, heapq, math, 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))
def celi(a,b):
return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
a,b=map(int,input().split())
ans=1
while ans*8//100!=a or ans//10!=b:
ans+=1
if ans>2*10**5:
print(-1)
exit()
print(ans)
|
def main():
a, b = map(int, input().split(" "))
for i in range(1,1010):
ta = i*8//100
tb = i*10//100
if ta == a and tb == b:
print(i)
return
print(-1)
if __name__ == "__main__":
main()
| 1 | 56,344,528,802,912 | null | 203 | 203 |
n = int(input())
def aa(str, chrMax):
if len(str) == n:
print(str)
return
for i in range(ord("a"), ord(chrMax)+2):
if i > ord(chrMax):
aa(str+chr(i), chr(i))
else:
aa(str+chr(i), chrMax)
aa("a", "a")
|
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
if n % 2 == 1:
print(b[n//2] - a[n//2] + 1)
else:
print(b[n//2] + b[n//2-1] - a[n//2] - a[n//2-1] + 1)
| 0 | null | 34,947,670,824,892 | 198 | 137 |
a,b,c,d = (int(x) for x in input().split())
ans = max(a*c,a*d,b*c,b*d)
print(ans)
|
from math import sqrt
def isprime(inlst, chk, sq):
for i in range(3, sq, 2):
inlst = [x for x in inlst if x%i > 0 or x == i]
i += 2
return inlst
n = int(input())
inlst = [input() for i in range(n)]
inlst = [int(i) for i in inlst]
inlst = [x for x in inlst if x%2 > 0 or x == 2]
inlst = isprime(inlst, 3, int(sqrt(max(inlst))) + 1)
print(len(inlst))
| 0 | null | 1,538,866,231,372 | 77 | 12 |
S=input()
N=len(S)
S=list(S)
ct=0
for i in range(N//2):
if S[i]!=S[-i-1]:
ct+=1
print(ct)
|
n=int(input())
dict={}
res=[]
for i in range(n):
ss=input().split()
if ss[0]=='insert':
dict[ss[1]]=i
elif ss[0]=='find':
if dict.__contains__(ss[1]):
res.append('yes')
else:
res.append('no')
for i in res:
print(i)
| 0 | null | 59,792,396,706,460 | 261 | 23 |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import cmath
pi = cmath.pi
exp = cmath.exp
def fft(a, inverse=False):
n = len(a)
h = n.bit_length() - 1
# Swap
for i in range(n):
j = 0
for k in range(h):
j |= (i >> k & 1) << (h - 1 - k)
if i < j:
a[i], a[j] = a[j], a[i]
# Butterfly calculation
if inverse:
sign = 1.0
else:
sign = -1.0
b = 1
while b < n:
for j in range(b):
w = exp(sign * 2.0j * pi / (2.0 * b) * j)
for k in range(0, n, b*2):
s = a[j + k]
t = a[j + k + b] * w
a[j + k] = s + t
a[j + k + b] = s - t
b *= 2
if inverse:
for i in range(n):
a[i] /= n
return a
def ifft(a):
return fft(a, inverse=True)
def convolve(f, g):
n = 2**((len(f) + len(g) - 1).bit_length())
f += [0] * (n - len(f))
g += [0] * (n - len(g))
F = fft(f)
G = fft(g)
FG = [Fi * Gi for Fi, Gi in zip(F, G)]
fg = [int(item.real + 0.5) for item in ifft(FG)]
return fg
if __name__ == "__main__":
n, m = map(int, input().split())
a = [int(item) for item in input().split()]
max_a = max(a)
freq = [0] * (max_a + 1)
for item in a:
freq[item] += 1
f = freq[:]; g = freq[:]
fg = convolve(f, g)
total = sum(a) * n * 2
cnt = n * n - m
for i, item in enumerate(fg):
use = min(cnt, item)
total -= i * use
cnt -= use
if cnt == 0:
break
print(total)
|
import sys
import bisect
import itertools
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
a.sort()
cor_v = -1
inc_v = a[-1] * 2 + 1
while - cor_v + inc_v > 1:
bin_v = (cor_v + inc_v) // 2
cost = 0
#条件を満たすcostを全検索
p = n
for v in a:
p = bisect.bisect_left(a, bin_v - v, 0, p)
cost += n - p
if cost > m:
break
#costが制約を満たすか
if cost >= m:
cor_v = bin_v
else:
inc_v = bin_v
acm = [0] + list(itertools.accumulate(a))
c = 0
t = 0
for v in a:
p = bisect.bisect_left(a, cor_v - v)
c += n - p
t += acm[-1] - acm[p] + v * (n - p)
print(t - (c - m) * cor_v)
if __name__ == '__main__':
solve()
| 1 | 108,522,613,079,550 | null | 252 | 252 |
if __name__=="__main__":
dataset = []
for i in range(10):
a = int(input())
dataset.append(a)
for j in range(3):
print(max(dataset))
dataset.remove(max(dataset))
|
n = int(input())
l = [input() for i in range(n)]
d = {k: 0 for k in ['AC', 'WA', 'TLE', 'RE']}
for s in l:
d[s] += 1
for s in ['AC', 'WA', 'TLE', 'RE']:
print('{} x {}'.format(s, d[s]))
| 0 | null | 4,380,377,454,450 | 2 | 109 |
import sys
A,B,C,K=map(int, sys.stdin.readline().split())
ans=0
a_cards=min(K,A)
K-=a_cards
ans+=a_cards*1
b_cards=min(K,B)
K-=b_cards
ans+=b_cards*0
c_cards=min(K,C)
K-=c_cards
ans+=c_cards*-1
print ans
|
#!usr/bin/env python3
import math
import sys
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LIR(n):
return [LI() for i in range(n)]
class SegmentTree:
def __init__(self, size, f=lambda x,y : x+y, default=0):
self.size = 2**(size-1).bit_length()
self.default = default
self.dat = [default]*(self.size*2)
self.f = f
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
def get(self, a, b=None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
lres, rres = self.default, self.default
while l < r:
if l & 1:
lres = self.f(lres, self.dat[l])
l += 1
if r & 1:
r -= 1
rres = self.f(self.dat[r], rres)
l >>= 1
r >>= 1
res = self.f(lres, rres)
return res
def solve():
n,d,a = LI()
g = LIR(n)
g.sort()
X = [i for (i,_) in g]
s = SegmentTree(n)
ans = 0
for i in range(n):
x = g[i][0]
j = bisect.bisect_left(X,x-2*d)
h = g[i][1]-s.get(j,i)
if h <= 0:
continue
k = math.ceil(h/a)
ans += k
s.update(i,k*a)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 0 | null | 51,855,973,315,868 | 148 | 230 |
import sys , math
from bisect import bisect
N=int(input())
alp="abcdefghijklmnopqrstuvwxyz"
R=[]
i=1
tot = 0
while tot < 1000000000000001:
tar = 26**i
tot+=tar
R.append(tot+1)
i+=1
keta = bisect(R , N)+1
if keta == 1:
print(alp[N-1])
sys.exit()
ans = ""
M = N - R[keta - 1]
for i in range(keta):
j = keta - i - 1
ind = M // (26**j)
M -= ind * (26**j)
ans+=alp[ind]
print(ans)
|
n,m=map(int,input().split())
matA=[list(map(int,input().split())) for i in range(n)]
matB=[int(input()) for i in range(m)]
for obj in matA:
print(sum(obj[i] * matB[i] for i in range(m)))
| 0 | null | 6,572,804,018,080 | 121 | 56 |
w = str(input())
s = []
for k in(list(w)):
s.append(k)
if s[2] == s[3]:
if s[4] == s[5]:
print("Yes")
else:
print("No")
else:
print("No")
|
s = input()
if s[2] == s[3]:
if s[4] == s[5]:
print("Yes")
exit(0)
print("No")
| 1 | 41,960,094,095,592 | null | 184 | 184 |
NN=raw_input()
N=raw_input()
A = [int(i) for i in N.split()]
swap=0
for i in range(int(NN)):
mini = i
for j in range(i,int(NN)):
if A[j] < A[mini]:
mini = j
if i != mini:
t = A[i]
A[i] = A[mini]
A[mini] = t
swap+=1
print ' '.join([str(k) for k in A])
print swap
|
def selection_sort(A, N):
count = 0
for i in range(N):
min_j = i
for j in range(i, N):
if A[j] < A[min_j]:
min_j = j
if i != min_j:
A[i], A[min_j] = A[min_j], A[i]
count += 1
print " ".join(map(str, A))
print count
N = input()
A = map(int, raw_input().split())
selection_sort(A, N)
| 1 | 21,137,239,662 | null | 15 | 15 |
def gcd(x,y):
if y==0:
return x
else:
x=x%y
return gcd(y,x)
A=list(map(int,input().split(' ')))
print(gcd(A[0],A[1]))
|
a, b = [int(tem) for tem in input().split()]
def mak(A, B) :
while B != 0 :
q, r = divmod(A, B)
A = int((A - r) / q)
B = r
return A
if a > b : print(mak(a, b))
else : print(mak(b, a))
| 1 | 8,157,329,522 | null | 11 | 11 |
def main():
A1, A2, A3 = map(int, input().split())
if A1 + A2 + A3 >= 22:
ans = "bust"
else:
ans = "win"
print(ans)
if __name__ == "__main__":
main()
|
#import numpy as np
#def area--------------------------#
#ryouno syokiti
class ryou:
def flinit(self):
room=list()
for i in range(10):
room+=[0]
return room
#def kaijo([a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9,a_10]):
#def kaijo(x):
# y=[]
# for i in x:
# y=y+ " "+x[i]
# return y
def kaijo(x):
print "",
for i in range(len(x)-1):
print str(x[i]),
print str(x[len(x)-1])
#----------------------------------#
floor_11=ryou().flinit()
floor_12=ryou().flinit()
floor_13=ryou().flinit()
floor_21=ryou().flinit()
floor_22=ryou().flinit()
floor_23=ryou().flinit()
floor_31=ryou().flinit()
floor_32=ryou().flinit()
floor_33=ryou().flinit()
floor_41=ryou().flinit()
floor_42=ryou().flinit()
floor_43=ryou().flinit()
fldic={"11":floor_11,
"12":floor_12,
"13":floor_13,
"21":floor_21,
"22":floor_22,
"23":floor_23,
"31":floor_31,
"32":floor_32,
"33":floor_33,
"41":floor_41,
"42":floor_42,
"43":floor_43
}
#----------------------------------#
#1kaime yomikomi
n=int(raw_input())
#nkaime syusyori
for l in range(n):
list_mojiretsu=raw_input().split(" ")
henka=map(int,list_mojiretsu)
fldic[str(henka[0])+str(henka[1])][henka[2]-1]+=henka[3]
kaijo(floor_11)
kaijo(floor_12)
kaijo(floor_13)
print "####################"
kaijo(floor_21)
kaijo(floor_22)
kaijo(floor_23)
print "####################"
kaijo(floor_31)
kaijo(floor_32)
kaijo(floor_33)
print "####################"
kaijo(floor_41)
kaijo(floor_42)
kaijo(floor_43)
| 0 | null | 59,672,859,447,708 | 260 | 55 |
alphabet = input()
if alphabet.isupper():
print('A')
else:
print('a')
|
tmp = input().split(" ")
A = int(tmp[0])
B = int(tmp[1])
if A <= 9 and B <= 9:
print(A * B)
else:
print("-1")
| 0 | null | 84,615,250,211,612 | 119 | 286 |
modulo = 10**9+7
def modpow(base, n):
ans = 1
while n:
if n&1:
ans = (ans*base)%modulo
base = (base*base)%modulo
n >>= 1
return ans
factorials = [1]
N = 10**5
for i in range(1, N+1):
factorials.append((factorials[-1]*i)%modulo)
inv = [0]
for i in range(1, N+1):
inv.append(modpow(factorials[i], modulo-2))
def nCr(n, r):
if r == 0 or r == n:
return 1
return (factorials[n]*inv[n-r]*inv[r])%modulo
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N, K = read_ints()
A = read_ints()
A.sort()
max_sum = 0
for i in range(K-1, N):
max_sum = (max_sum+A[i]*nCr(i, K-1))%modulo
min_sum = 0
for i in range(N-K+1):
min_sum = (min_sum+A[i]*nCr(N-i-1, K-1))%modulo
return (max_sum-min_sum)%modulo
if __name__ == '__main__':
print(solve())
|
import math
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
for p in [1.0, 2.0, 3.0]:
a = 0
for i in range(n):
a += abs(x[i] - y[i]) ** p
D = a ** (1/p)
print(D)
inf_D = float("-inf")
for i in range(n):
if abs(x[i] - y[i]) > inf_D:
inf_D = abs(x[i] - y[i])
print(inf_D)
| 0 | null | 47,693,030,643,412 | 242 | 32 |
n = int(input())
A = [0] + [*map(int, input().split())]
dp_stock = [0]*(n+1)
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(1, n+1):
dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1] // A[day])
remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1]
dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day])
print(dp_yen[n])
|
n, k = (int(i) for i in input().split())
w = [int(input()) for i in range(n)]
total_weght = sum(w)
def check(p):
track = [0 for i in range(k)]
target = 0
for i in range(k):
while (track[i] + w[target]) <= p:
track[i] += w[target]
target += 1
if target not in range(n):
break
if target not in range(n):
break
return(target)
def solve(n):
left = 0
right = 100000 * 100000
while left < right:
mid = (left + right) // 2
if n == check(mid):
right = mid
else:
left = mid + 1
return(right)
if __name__ == "__main__":
ans = solve(n)
print(ans)
| 0 | null | 3,702,312,786,592 | 103 | 24 |
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))
C = 0
for i in range(Q):
if T[i] in S:
C+=1
print(C)
|
def linear_search(A, n, key):
A.append(key)
i = 0
while A[i] != key:
i += 1
A.pop()
return i != n
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0
for t in T:
if linear_search(S, n, t):
ans += 1
print(ans)
| 1 | 69,691,736,960 | null | 22 | 22 |
import math
h = int(input())
n = int(math.log2(h))
a = 2
r = 2
S = (a*(r**n)-a) // (r-1)
print(S + 1)
|
listSi = [0,0,0,0]
ic = int(input())
icz = 0
while True:
icz += 1
i = input()
if i == "AC":
listSi[0] += 1
elif i == "WA":
listSi[1] += 1
elif i == "TLE":
listSi[2] += 1
elif i == "RE":
listSi[3] += 1
if icz == ic:
break
print(f"AC x {listSi[0]}")
print(f"WA x {listSi[1]}")
print(f"TLE x {listSi[2]}")
print(f"RE x {listSi[3]}")
| 0 | null | 44,336,741,192,004 | 228 | 109 |
def main():
S = input().rstrip()
if S[-1] == "s":
S = S + "es"
else:
S = S + "s"
print(S)
main()
|
from enum import Enum
from queue import Queue
import collections
import sys
import math
class Info:
def __init__(self,arg_start,arg_end,arg_S):
self.start = arg_start
self.end = arg_end
self.S = arg_S
LOC=[]
POOL=[]
line = input()
loc = 0
sum_S = 0
for ch in line:
if ch == '\\':
LOC.append(loc)
elif ch == '/':
if len(LOC) ==0:
continue
tmp_start = int(LOC.pop())
tmp_end = loc
tmp_S = tmp_end-tmp_start
sum_S += tmp_S
while len(POOL) > 0:
if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
tmp_S += POOL[-1].S
POOL.pop()
else:
break
POOL.append(Info(tmp_start,tmp_end,tmp_S))
else:
pass
loc += 1
print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")
while len(POOL) > 0:
print(" %d"%(POOL[0].S),end = "") #先頭から
POOL.pop(0)
print()
| 0 | null | 1,210,043,181,062 | 71 | 21 |
import numpy as np
import math
from decimal import *
#from numba import njit
def getVar():
return map(int, input().split())
def getArray():
return list(map(int, input().split()))
def getNumpy():
return np.array(list(map(int, input().split())), dtype='int64')
def factorization(n):
d = {}
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
d.update({i: cnt})
if temp!=1:
d.update({temp: 1})
if d==[]:
d.update({n:1})
return d
def main():
N = int(input())
d = factorization(N)
count = 0
for v in d.values():
i = 1
while(v >= i):
v -= i
i += 1
count += 1
print(count)
main()
|
n=int(input())
def f(x):
z=1
while not(z*(z+1)<=2*x<(z+1)*(z+2)):
z+=1
return z
x=[-1]*(10**6+1) #2以上の自然数に対して最小の素因数を表す
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**6:
if x[i]==-1:
x[i]=i
prime.append(i)
for j in prime:
if i*j>10**6 or j>x[i]:break
x[j*i]=j
i+=1
if n==1:
print(0)
exit()
y=0
j=2
while j*j<=n:
if n%j==0:
y=1
j+=1
if y==0:
print(1)
exit()
a=[]
q=0
for i in range(len(prime)):
p=prime[i]
while n%p==0:
q+=1
n=n//p
if q>0:a.append(q)
q=0
ans=0
for i in range(len(a)):
ans+=f(a[i])
print(ans if n==1 else ans+1)
| 1 | 16,895,879,032,186 | null | 136 | 136 |
class Dice:
def __init__(self, faces):
self.faces = tuple(faces)
def roll_north(self):
self.faces = (self.faces[1], self.faces[5], self.faces[2],
self.faces[3], self.faces[0], self.faces[4])
def roll_south(self):
self.faces = (self.faces[4], self.faces[0], self.faces[2],
self.faces[3], self.faces[5], self.faces[1])
def roll_west(self):
self.faces = (self.faces[2], self.faces[1], self.faces[5],
self.faces[0], self.faces[4], self.faces[3])
def roll_east(self):
self.faces = (self.faces[3], self.faces[1], self.faces[0],
self.faces[5], self.faces[4], self.faces[2])
def number(self, face_id):
return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
commands = input()
for c in commands:
if c == "N":
dice.roll_north()
elif c == "S":
dice.roll_south()
elif c == "W":
dice.roll_west()
elif c == "E":
dice.roll_east()
print(dice.number(1))
|
import enum
class Direction(enum.Enum):
N = "N"
E = "E"
W = "W"
S = "S"
@classmethod
def value_of(cls, value):
return [v for v in cls if v.value == value][0]
class Dice:
def __init__(self, *value_list):
self.__value_list = list(value_list)
def rotate(self, direction):
l = self.__value_list
if direction == Direction.N:
l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0]
elif direction == Direction.E:
l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5]
elif direction == Direction.W:
l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0]
elif direction == Direction.S:
l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5]
def top_value(self):
return self.__value_list[0]
dice = Dice(*input().split())
for i in input():
dice.rotate(Direction.value_of(i))
print(dice.top_value())
| 1 | 229,803,105,000 | null | 33 | 33 |
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
queue = deque()
def main():
k = int(input())
queue.extend([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k-1):
x = queue[0]
queue.popleft()
if x % 10 != 0:
queue.append(10 * x + x % 10 - 1)
queue.append(10 * x + x % 10)
if x % 10 != 9:
queue.append(10 * x + x % 10 + 1)
print(queue[0])
if __name__ == '__main__':
main()
|
import sys
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007
#+++++
def main():
k = int(input())
#b , c = tin()
#s = input()
l=['_']*50
l[0]=0
for _ in range(k):
for i, v in enumerate(l):
l[i]+=1
if l[i] == 10 and l[i+1]=='_':
l[i+1]=1
l[:i+1]=[0]*(i+1)
break
elif l[i] == 10:
l[i]=l[i+1]
elif l[i+1]=='_':
#l[:i]=[l[i]-1]*(i)
for j in range(1,i+1):
l[i-j]=max(0, l[i-j+1]-1)
break
elif l[i] <= l[i+1]+1:
#l[:i]=[l[i]-1]*i
for j in range(1,i+1):
l[i-j]=max(0, l[i-j+1]-1)
break
#print(*l)
print(''.join([str(c) for c in l[::-1] if c != '_']))
#+++++
isTest=False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text=clipboard.get()
input_l=input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform =='ios':
if input_method==input_methods[0]:
ic=input_clipboard()
input = lambda : ic.__next__()
elif input_method==input_methods[1]:
sys.stdin=open('inputFile.txt')
else:
pass
isTest=True
else:
pass
#input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| 1 | 40,262,841,589,780 | null | 181 | 181 |
s = input()
ls = ['SUN','MON','TUE','WED','THU','FRI','SAT']
for i, x in enumerate(ls):
if s == x:
print(7-i)
|
D = input()
W = ['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7 - W.index(D))
| 1 | 133,441,842,216,476 | null | 270 | 270 |
n = int(input())
l = list(map(int, input().split()))
array = [0] * n
for i in l:
array[i-1] += 1
for i in array:
print(i)
|
h,n = map(str,input().split())
#li = [int(x) for x in input().split()]
print(n+h)
| 0 | null | 67,843,943,789,632 | 169 | 248 |
# import math
# import statistics
a=input()
b=input()
#b,c=int(input()),int(input())
c,d=[],[]
for i in a:
c.append(i)
for i in b:
d.append(i)
#e1,e2 = map(int,input().split())
# f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
# h = []
# for i in range(e1):
# h.append(list(map(int,input().split())))
ma=[]
if b in a:
print(0)
else:
for i in range(len(c)-len(d)+1):
count=0
for k in range(len(d)):
if c[i:len(d)+i][k]!=d[k]:
count+=1
ma.append(count)
print(min(ma))
|
def main():
s = input()
t = input()
for i in range(len(s)):
if s[i] != t[i]:
print('No')
return
print('Yes')
main()
| 0 | null | 12,581,473,566,220 | 82 | 147 |
n = int(input())
L, R = [], []
for i in range(n):
a, b = 0, 0
for c in input():
if c == '(':
b += 1
if c == ')':
if b > 0:
b -= 1
else:
a += 1
if -a + b > 0:
L.append((a, b))
else:
R.append((a, b))
L.sort(key=lambda x: x[0])
R.sort(key=lambda x: x[1], reverse=True)
x = 0
for a, b in L + R:
x -= a
if x < 0:
print('No')
exit()
x += b
if x == 0:
print('Yes')
else:
print('No')
|
import math
if __name__ == '__main__':
x1, y1, x2, y2 = [float(i) for i in input().split()]
d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
print("{0:.5f}".format(d))
| 0 | null | 12,026,914,887,988 | 152 | 29 |
X, Y = map(int, input().split())
n = (2 * X - Y) // 3
m = (-X + 2 * Y) // 3
if n < 0 or m < 0 or (2 * X - Y) % 3 != 0 or (-X + 2 * Y) % 3 != 0:
print(0)
else:
# (n+m)Cn 通り
fac = [1, 1]
finv = [1, 1]
inv = [1, 1]
MOD = 10 ** 9 + 7
for i in range(2, n + m + 1):
fac.append(fac[i - 1] * i % MOD)
inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
finv.append(finv[i - 1] * inv[i] % MOD)
print(fac[n+m] * (finv[n] * finv[m] % MOD) % MOD)
|
def COMinit():
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,max):
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 COM(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
mod = 10**9+7
X, Y = map(int,input().split())
a = X%2 #1の数
b = X//2 #2の数
for i in range(b+1):
if a*2 + b*1 == Y:
break
a += 2
b -= 1
if a*2 + b*1 != Y:
print(0)
else:
max = a+b+1
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
print(COM(a+b,a))
| 1 | 149,881,246,165,530 | null | 281 | 281 |
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)
|
a = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')
print(a[int(input()) - 1])
| 0 | null | 31,831,272,912,552 | 127 | 195 |
from decimal import Decimal
X=int(input())
c =Decimal(100)
C=0
while c<X:
c=Decimal(c)*(Decimal(101))//Decimal(100)
C+=1
print(C)
|
import math
x = int(input())
initial = 100
count = 0
while initial < x:
initial += initial//100
count += 1
print(count)
| 1 | 27,172,101,014,032 | null | 159 | 159 |
n, k = map(int, input().split(" "))
MOD = (10**9) + 7
def dSum(s, e):
s -= 1
_s = s * (s + 1) // 2
_e = e * (e + 1) // 2
return _e - _s
ans = 0
for i in range(k, n + 1):
# _sum = dSum(n - i - 1, n) - dSum(0, i - 1) + 1
ans += dSum(i, n) - dSum(0, n - i) + 1
print((ans + 1) % MOD)
|
n,K = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for k in range(K,n+2):
#ans += (n+1)*n//2 -(n+1-k)*(n-k)//2-k*(k-1)//2 + 1
#ans += (n**2+n)//2 - (n**2-n*k+n-k-n*k+k**2)//2 - (k**2-k)//2 + 1
#ans += (n**2+n - (n**2-n*k+n-k-n*k+k**2) -k**2 + k)//2 + 1
#ans += (n**2 + n - n**2 + n*k - n + k + n*k - k**2 - k**2 + k)//2 + 1
#ans += (2*n*k + 2*k - 2*k**2)//2 + 1
ans += n*k - k**2 + k + 1
print(ans%mod)
| 1 | 33,211,584,385,850 | null | 170 | 170 |
n = int(input()) % 10
if n == 3:
print('bon')
elif n == 0 or n == 1 or n == 6 or n == 8:
print('pon')
else:
print('hon')
|
while True:
try:
a,b = map(int,raw_input().split())
c=str(a+b)
print len(c)
except EOFError:
break
| 0 | null | 9,534,909,144,722 | 142 | 3 |
s = list(map(int, input().split()))
print(s.index(0) + 1)
|
n,m=map(int,input().split())
ans=[0 for i in range(n+1)]
list_tonari=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
list_tonari[a].append(b)
list_tonari[b].append(a)
const=list()
const.append(1)
const_vary=list()
while True:
const_vary=const
const=[]
while len(const_vary):
get=const_vary.pop()
for n in list_tonari[get]:
if ans[n] ==0:
ans[n]=get
list_tonari[n].remove(get)
const.append(n)
if len(const)==0:
break
print("Yes")
for n in ans[2:]:
print(n)
| 0 | null | 17,003,134,489,070 | 126 | 145 |
#!/usr/bin/env python3
def main():
n = int(input())
a = list(map(int, input().split()))
ans = [None] * n
allxor = 0
for i in range(n):
allxor ^= a[i]
for i in range(n):
ans[i] = allxor ^ a[i]
print(*ans)
if __name__ == "__main__":
main()
|
N = int(input())
a = list(map(int,input().split()))
sum = 0
for i in a:
sum = i^sum
for i in a:
print(sum^i,end=' ')
| 1 | 12,498,712,637,752 | null | 123 | 123 |
# -*- coding: utf-8 -*-
import functools
@functools.lru_cache(maxsize=None)
def fib(n):
if n <= 1:
return 1
else:
return fib(n - 1) + fib(n - 2)
if __name__ == '__main__':
n = int(input())
print(fib(n))
|
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
class Fibonacci(object):
memo = [1, 1]
def get_nth(self, n):
if n < len(Fibonacci.memo):
return Fibonacci.memo[n]
# print('fib({0}) not found'.format(n))
for i in range(len(Fibonacci.memo), n+1):
result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
Fibonacci.memo.append(result)
# print('fib({0})={1} append'.format(i, result))
return Fibonacci.memo[n]
if __name__ == '__main__':
# ??????????????\???
num = int(input())
# ?????£??????????????°????¨????
#f = Fibonacci()
#result = f.get_nth(num)
result = fib(num+1)
# ???????????????
print('{0}'.format(result))
| 1 | 1,833,900,550 | null | 7 | 7 |
a,b=input().split()
c,d=input().split()
b=int(b)
d=int(d)
if d-b==1:
print("0")
else:
print("1")
|
M1,D1 = map(int, input().split())
M2,D2 = map(int, input().split())
if M1==12 and M2==1 or M1+1==M2:
print(1)
else:
print(0)
| 1 | 124,820,359,926,900 | null | 264 | 264 |
def cubic(x):
return x ** 3
def main():
x = int(input())
y = cubic(x)
return y
print(main())
|
n, W = map(int, input().split())
ab = [tuple(map(int, input().split()))for _ in range(n)]
ab.sort()
ans = 0
dp = [0]*W
for a, b in ab:
if ans < dp[-1]+b:
ans = dp[-1]+b
for j in reversed(range(W)):
if j-a < 0:
break
if dp[j] < dp[j-a]+b:
dp[j] = dp[j-a]+b
print(ans)
| 0 | null | 75,599,192,828,160 | 35 | 282 |
a,b,c=map(int,input().split())
ans="Yes"
if a==b==c :
ans="No"
elif a!=b and b!=c and a!=c:
ans="No"
print(ans)
|
n = int(input())
s = input()
ans = 0
for i in range(10):
if str(i) in s:
index_i = s.index(str(i))
for j in range(10):
if str(j) in s[index_i + 1:]:
index_j = s[index_i + 1:].index(str(j)) + index_i + 1
for k in range(10):
if str(k) in s[index_j + 1:]:
ans += 1
print(ans)
| 0 | null | 98,622,175,469,892 | 216 | 267 |
N = int(input())
A = list(map(int,input().split()))
K = 2 if N%2 else 1
INF = float('inf')
dp = [[[-INF]*2 for _ in range(K+1)] for _ in range(N+1)]
dp[0][K][0] = 0 #dp[i][can_skip][must_skip]
for i,a in enumerate(A):
for k in range(K,-1,-1):
dp[i+1][k][0] = max(dp[i+1][k][0], dp[i][k][1])
dp[i+1][k][1] = max(dp[i+1][k][1], dp[i][k][0] + a)
if k:
dp[i+1][k-1][0] = max(dp[i+1][k-1][0], dp[i][k][0])
print(max(max(row) for row in dp[-1][:2]))
|
k,n = map(int, input().split())
arr = list(map(int, input().split()))
prev = 0
m = 0
for i in arr:
m = max(m, abs(prev-i))
prev = i
m = max(m, k+arr[0]-arr[n-1])
ans = k-m
print(ans)
| 0 | null | 40,482,787,874,152 | 177 | 186 |
A, B, M = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
xyc = [[int(_) for _ in input().split()] for i in range(M)]
rets = [min(a) + min(b)]
for x, y, c in xyc:
rets += [a[x-1] + b[y-1] - c]
print(min(rets))
|
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
# N に向かうことを考える
A_to_N_dis = N - B + 1
A_to_N = A + A_to_N_dis
tmp_ans = (N - A_to_N) // 2 + A_to_N_dis
# 1に向かうことを考える
B_to_1_dis = A - 1 + 1
B_to_1 = B - B_to_1_dis
ans = (B_to_1 - 1) // 2 + B_to_1_dis
print(min(tmp_ans, ans))
| 0 | null | 81,500,793,937,540 | 200 | 253 |
N,K = map(int,input().split())
m = N%K
print(min(m,K-m))
|
n,k=map(int,input().split());print(min(n%k,k-n%k))
| 1 | 39,311,747,119,300 | null | 180 | 180 |
n,k=map(int,input().split());s=set(range(1,-~n))
for _ in range(k):
input();s-=set(map(int,input().split()))
print(len(s))
|
N,K=map(int,input().split())
ans=list()
for i in range(K):
D=int(input())
L=list(map(int,input().split()))
ans+=L
ans=list(set(ans))
print(N-len(ans))
| 1 | 24,400,717,132,580 | null | 154 | 154 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.