code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
x = int(input())
r = 100
ans = 0
while r < x:
r = int(r * 101)//100
ans += 1
print(ans)
|
x = int(input())
n = 100
ans = 0
while True:
ans += 1
n += n // 100
if n >= x:
print(ans)
exit()
| 1 | 26,926,892,945,932 | null | 159 | 159 |
import numpy as np
from numba import njit
import itertools
@njit
def imos(N,K,A):
B=np.zeros((N+1),dtype=np.int64)
#B=np.zeros((N+1))
for i in range(N):
a=A[i]
start=max(0,i-a)
end=min(N,i+a+1)
B[start]+=1
B[end]-=1
#B=np.array(B)
return np.cumsum(B)[:N]
if __name__=="__main__":
N,K=map(int, input().split())
A=list(map(int, input().split()))
for _ in range(K):
A=imos(N,K,A)
if A.min()==N:
break
print(*A)
|
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
key = c.keys()
comb = 0
for i in key:
comb += (c[i]) * (c[i]-1) // 2
for i in A:
ans = comb - (c[i]-1)
print(ans)
| 0 | null | 31,665,283,448,512 | 132 | 192 |
x = input()
s = 0
for i in range(len(x)):
s = s + int(x[i])
if s % 9 == 0:
print("Yes")
else:
print("No")
|
r=int(input())
import math
c=2*r*math.pi
print("{0:.6}".format(c))
| 0 | null | 17,826,722,706,208 | 87 | 167 |
import sys
from itertools import product
def main():
input = sys.stdin.buffer.readline
card = [[0] * 3 for _ in range(3)]
for i in range(3):
line = list(map(int, input().split()))
card[i] = line
mark = [[0] * 3 for _ in range(3)]
n = int(input())
for _ in range(n):
b = int(input())
for i, j in product(range(3), repeat=2):
if card[i][j] == b:
mark[i][j] = 1
break
for i in range(3):
s = 0
for j in range(3):
s += mark[i][j]
if s == 3:
print("Yes")
sys.exit()
for j in range(3):
s = 0
for i in range(3):
s += mark[i][j]
if s == 3:
print("Yes")
sys.exit()
s = 0
for i in range(3):
s += mark[i][i]
if s == 3:
print("Yes")
sys.exit()
s = 0
for i in range(3):
s += mark[i][2 - i]
if s == 3:
print("Yes")
sys.exit()
print("No")
if __name__ == "__main__":
main()
|
def main():
bingo = []
for ss in range(3):
s = list(map(int,input().strip().split()))
bingo.append(s)
n = int(input())
nl = []
for nn in range(n):
nl.append(int(input()))
for i in range(3):
for j in range(3):
for n in nl:
if bingo[i][j] == n:
bingo[i][j] = -1
for i in range(3):
if bingo[0][i] == bingo[1][i] == bingo[2][i] == -1:
print("Yes")
return
if bingo[i][0] == bingo[i][1] == bingo[i][2] == -1:
print("Yes")
return
if bingo[0][0] == bingo[1][1] == bingo[2][2] == -1:
print("Yes")
return
if bingo[0][2] == bingo[1][1] == bingo[2][0] == -1:
print("Yes")
return
print("No")
return
main()
| 1 | 60,218,555,322,720 | null | 207 | 207 |
import sys
N,K = map(int,input().split())
H = sorted(list(map(int,input().split())),reverse = True)
for i in range(N):
if not H[i] >= K:
print(i)
sys.exit()
print(N)
|
n,k = map(int,input().split())
friend = list(map(int,input().split()))
count = 0
for x in friend:
if x >= k:
count += 1
print(count)
| 1 | 178,539,420,129,990 | null | 298 | 298 |
def main():
N,K=map(int,input().split())
res=0
MOD=10**9+7
for i in range(K,N+2):
MAX=(N+(N-i+1))*i//2
MIN=(i-1)*i//2
res+=MAX-MIN+1
res%=MOD
print(res%MOD)
if __name__=="__main__":
main()
|
import sys
import copy
from collections import deque
stdin = sys.stdin
mod = 10**9+7
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
n,k = na()
if n==k-1:
print(1)
exit(0)
prev_min = sum([i for i in range(k)])
prev_max = sum([i for i in range(n, n-k, -1)])
prev_num_min = k-1
prev_num_max = n-k+1
cnt = 0
for i in range(n-k+2):
# print("{} {}".format(prev_min, prev_max))
cnt += prev_max-prev_min+1
cnt %= mod
prev_num_min += 1
prev_num_max -= 1
prev_min += prev_num_min
prev_max += prev_num_max
print(cnt)
| 1 | 33,272,173,314,160 | null | 170 | 170 |
#!/usr/bin/env python3
from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
N = int(input())
A = list(map(int, input().split()))
# dp[i] := i日目の売却時の所持金の最大
# dp[i] = max(i-1のまま, j日目時点で買えるだけ買った株全て売却)
dp = [0] * (N+1)
dp[0] = 1000
for i in range(1, N+1):
# print(f'i = {i}')
max_j = 0
for j in range(1, i):
# print(f'j = {j}')
q, r = divmod(dp[j-1], A[j-1])
# print(f'q, r = {q}, {r}')
max_j = max(max_j, A[i-1] * q + r)
# print(f'dp[i-1] = {dp[i-1]}, max_j = {max_j}')
dp[i] = max(dp[i-1], max_j)
# pprint(dp)
print(dp[N])
|
A, B = map(int, input().split())
for x in range(10**3+1):
if int(x * 0.08) == A and int(x * 0.1) == B:
print(x)
exit()
print(-1)
| 0 | null | 31,927,147,600,160 | 103 | 203 |
from itertools import starmap
(lambda *_: None)(
*map(print,
starmap(lambda h, w: ''.join(['#'*w + '\n'] * h),
map(lambda ss: map(int, ss),
map(str.split, iter(input, '0 0'))))))
|
import sys
input = sys.stdin.readline
s,t=input().rstrip().split()
a,b=map(int,input().split())
u=input().rstrip()
if u == s:
print(a-1,b)
else:
print(a,b-1)
| 0 | null | 36,277,202,945,050 | 49 | 220 |
N,M=map(int, input().split())
peaks=list(map(int, input().split()))
flag=[1]*N
a=0
b=0
for i in range(M):
a,b=map(int,input().split())
a-=1
b-=1
if peaks[a]<=peaks[b]:
flag[a]=0
if peaks[a]>=peaks[b]:
flag[b]=0
ans=0
for i in flag:
ans+=i
print(ans)
|
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = T1 * (A1 - B1)
d2 = T2 * (A2 - B2)
if d1 > 0 and d1 + d2 > 0:
print(0)
elif d1 < 0 and d1 + d2 < 0:
print(0)
elif d1 + d2 == 0:
print("infinity")
else:
if d1 < 0:
d1 = -d1
d2 = -d2
ok = 0
ng = (d1 + d1) // (-d1 - d2) + 1
x = 0
while ok + 1 < ng:
mid = (ok + ng) // 2
s = mid * (d1 + d2)
if s + d1 > 0:
ok = mid
elif s + d1 == 0:
ok = mid
ng = ok + 1
x = -1
else:
ng = mid
print(ng * 2 - 1 + x)
| 0 | null | 78,134,228,289,376 | 155 | 269 |
def resolve():
# 十進数表記で1~9までの数字がK個入るN桁の数字の数を答える問題
S = input()
K = int(input())
n = len(S)
# dp[i][k][smaller]:
# i:桁数
# K:0以外の数字を使った回数
# smaller:iまでの桁で値以上になっていないかのフラグ
dp = [[[0] * 2 for _ in range(4)] for _ in range(105)]
dp[0][0][0] = 1
for i in range(n):
for j in range(4):
for k in range(2):
nd = int(S[i])
for d in range(10):
ni = i+1
nj = j
nk = k
if d != 0:
nj += 1
if nj > K:
continue
if k == 0:
if d > nd: # 値を超えている
continue
if d < nd:
nk += 1
dp[ni][nj][nk] += dp[i][j][k]
ans = dp[n][K][0] + dp[n][K][1]
print(ans)
if __name__ == "__main__":
resolve()
|
n = str(input())
p = int(input())
keta = len(n)
Dp = [[[0 for _ in range(2)] for _ in range(keta+1)]for _ in range(keta+1)]
Dp[0][0][1] = 1
10
for i in range(keta):
for j in range(i+1):
for k in range(10):
if k == 0:
if k < int(n[i]):
Dp[i+1][j][0] += Dp[i][j][0]
Dp[i+1][j][0] += Dp[i][j][1]
elif k == int(n[i]):
Dp[i+1][j][1] += Dp[i][j][1]
Dp[i+1][j][0] += Dp[i][j][0]
else:
Dp[i+1][j][0] += Dp[i][j][0]
else:
if k < int(n[i]):
Dp[i+1][j+1][0] += Dp[i][j][0]
Dp[i+1][j+1][0] += Dp[i][j][1]
elif k == int(n[i]):
Dp[i+1][j+1][1] += Dp[i][j][1]
Dp[i+1][j+1][0] += Dp[i][j][0]
else:
Dp[i+1][j+1][0] += Dp[i][j][0]
if p > keta:
print(0)
else:
print(sum(Dp[-1][p]))
| 1 | 76,167,945,043,600 | null | 224 | 224 |
import sys
def resolve(in_, out):
n = int(in_.readline())
b = [0] * (n + 1)
for a in map(int, in_.readline().split()):
b[a] += 1
out.write('\n'.join(map(str, b[1:])))
def main():
resolve(sys.stdin.buffer, sys.stdout)
if __name__ == '__main__':
main()
|
H = int(input())
W = int(input())
N = int(input())
N += max(H-1,W-1)
ans = N//max(H,W)
print(ans)
| 0 | null | 60,373,645,510,722 | 169 | 236 |
import sys
i = 1
while(True):
x = int(sys.stdin.readline())
if(x == 0):
break
print("Case %d: %d" % (i, x))
i += 1
|
k,n=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
if i<n-1:
b[i]=a[i+1]-a[i]
else:
b[n-1]=a[0]+k-a[n-1]
b.sort()
print(sum(b[:n-1]))
| 0 | null | 22,051,437,434,782 | 42 | 186 |
num1, num2 = map(int, input().split())
print(num1*num2)
|
def Next(): return input()
name = Next()
print(name[:3])
| 0 | null | 15,330,068,851,012 | 133 | 130 |
H = []
W = []
i = 0
while True:
h, w = map(int, input().split())
H.append(h)
W.append(w)
if H[i] == 0 and W[i] == 0:
break
i += 1
i = 0
while True:
if H[i] == 0 and W[i] == 0:
break
for j in range(H[i]):
for k in range(W[i]):
print("#", end="")
print()
print()
i += 1
|
while True:
H,W=[int(i) for i in input().split(" ")]
if H==W==0:
break
for h in range(H):
print("#"*W)
print()
| 1 | 777,562,484,050 | null | 49 | 49 |
n=int(input())
ans=0
for i in range(1000):
ans=n+i
if ans%1000==0:
print(i)
break
|
n = int(input())
a = [int(e) for e in input().split()]
ans = [0] * n
for i in range(n):
s = a[i]
ans[s-1] = i+1
print(*ans)
| 0 | null | 94,785,091,627,744 | 108 | 299 |
N=int(input())
print(-N%1000)
|
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.append(float("inf"))
Q.append(float("inf"))
ans=sum(P[:X]+Q[:Y])
rfinish=False
gfinish=False
r,g,f=X-1,Y-1,0
while f<C and (R[f]>P[r] or R[f]>Q[g]):
if P[r]<Q[g]:
ans=ans-P[r]+R[f]
r-=1
f+=1
else:
ans=ans-Q[g]+R[f]
g-=1
f+=1
print(ans)
| 0 | null | 26,427,636,147,624 | 108 | 188 |
n=int(input())
x = int(n/2)
if n%2 == 1:
ans = x + 1
else:
ans = x
print(ans)
|
k = int(input())
a, b = map(int, input().split())
ans = 0
for i in range(a, b+1, 1):
if i%k == 0:
ans = 1
break
if ans == 1:
print("OK")
else:
print("NG")
| 0 | null | 42,653,118,052,090 | 206 | 158 |
a = list(input().split())
print("Yes" if len(set(a)) == 2 else "No")
|
X, Y, A ,B, C = list(map(int, input().split()))
P = sorted(list(map(int, input().split())), reverse = True)[:X]
Q = sorted(list(map(int, input().split())), reverse = True)[:Y]
R = sorted(list(map(int, input().split())), reverse = True)
ans = 0
for i in range(C):
if(len(P) == 0):
if(len(Q) == 0):
break
elif(Q[-1] < R[i]):
Q.pop()
ans += R[i]
else:
break
elif(len(Q) == 0):
if(P[-1] < R[i]):
P.pop()
ans += R[i]
else:
break
else:
if(P[-1] < Q[-1] and P[-1] < R[i]):
P.pop()
ans += R[i]
elif(Q[-1] <= P[-1] and Q[-1] < R[i]):
Q.pop()
ans += R[i]
else:
break
ans += sum(P) + sum(Q)
print(ans)
| 0 | null | 56,533,320,943,222 | 216 | 188 |
H = int(input())
count = 0
answer = 0
while(H > 1):
H //= 2
answer += 2**count
count += 1
answer += 2**count
print(answer)
|
print(2**int(input()).bit_length()-1)
| 1 | 80,148,130,083,940 | null | 228 | 228 |
def main(X, Y):
for n_crane in range(X + 1):
n_turtle = X - n_crane
y = n_crane * 2 + n_turtle * 4
if y == Y:
print('Yes')
return
print('No')
if __name__ == "__main__":
X, Y = [int(s) for s in input().split(' ')]
main(X, Y)
|
x, y = [int(x) for x in input().split()]
flg = False
for c in range(x+1):
t = x-c
flg |= y == (2 * c + 4 * t)
print("Yes" if flg else "No")
| 1 | 13,724,646,831,388 | null | 127 | 127 |
N=int(input())
r=[0]*10000
for i in range(1,101):
for j in range(1,101):
for k in range(1,101):
v = i*i + j*j + k*k + i*j + i*k + k*j
if v <= 10000:
r[v-1] += 1
for i in range(N):
print(r[i])
|
n = int(input())
ans = [0] * (10**4 + 1)
for i in range(1,105):
for j in range(1,105):
for k in range(1,105):
v = i*i+j*j+k*k+i*j+j*k+k*i
if v < 10001:
ans[v]+=1
for i in range(n):
print(ans[i+1])
| 1 | 7,948,690,295,040 | null | 106 | 106 |
x, n = map(int, input().split())
lis = []
if n == 0:
print(x)
else:
lis = list(map(int, input().split()))
if x not in lis:
print(x)
else:
y = x + 1
z = x - 1
while True:
if y in lis and z in lis:
y += 1
z -= 1
elif z not in lis:
print(z)
break
elif y not in lis:
print(y)
break
|
'''
@sksshivam007 - Template 1.0
'''
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
toret = {}
for tup in temp:
toret[tup[0]] = tup[1]
return toret
def sortDictWithKey(passedDic):
return dict(OrderedDict(sorted(passedDic.items())))
INF = float('inf')
mod = 10 ** 9 + 7
n, k = MAP()
a = [0]*(k+1)
for i in range(k, 0, -1):
temp = pow((k//i), n, mod)
ans = temp%mod
for j in range(2, k//i + 1):
ans -= a[j*i]%mod
a[i] = ans%mod
final = 0
for i in range(len(a)):
final+=(a[i]*i)%mod
print(final%mod)
| 0 | null | 25,563,735,132,500 | 128 | 176 |
MAX = 100000
def check(p):
i = 0
for j in range(k):
s = 0
while s + T[i] <= p:
s = s + T[i]
i = i + 1
if i == n:
return n
return i
def solve():
left = 0
right = MAX * 10000
while (right - left > 1):
mid = (left + right) / 2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
return right
n, k = map(int, raw_input().split())
T = []
for i in range(n):
T.append(input())
ans = solve()
print ans
|
N, K = map(int, input().split())
W = [int(input()) for w in range(N)]
def check(p):
i = 0
for _ in range(K):
s = 0
while s + W[i] <= p:
s += W[i]
i += 1
if i == N:
return N
return i
left = 0
right = 100000 * 10000
mid = 0
while 1 < right - left:
mid = (left + right) / 2
v = check(mid)
if v >= N:
right = mid
else:
left = mid
print(int(right))
| 1 | 88,167,497,940 | null | 24 | 24 |
from collections import deque
n,limit = map(int,input().split())
total_time = 0
queue = deque()
for _ in range(n):
p,t = input().split()
queue.append([p,int(t)])
while len(queue) > 0:
head = queue.popleft()
if head[1] <= limit:
total_time += head[1]
print('{} {}'.format(head[0],total_time))
else:
head[1] -= limit
total_time += limit
queue.append(head)
|
n, quantum = list(map(int, input().split()))
queue = []
sumOfTime = 0
for _ in range(n):
name, time = input().split()
queue.append([name, int(time)])
while len(queue) > 0:
name, time = queue.pop(0)
if time > quantum:
sumOfTime += quantum
queue.append([name, time - quantum])
else:
sumOfTime += time
print(name, sumOfTime)
| 1 | 42,271,626,702 | null | 19 | 19 |
N, M = map(int, input().split())
A = list(map(int, input().split()))
print(max(-1, N-sum(A)))
|
mod = 10**9 + 7
X, Y = map(int, input().split())
if (X+Y) % 3 != 0:
print(0)
exit()
a = (2*Y-X)//3
b = (2*X-Y)//3
if a < 0 or b < 0:
print(0)
exit()
m = min(a, b)
ifact = 1
for i in range(2, m+1):
ifact = (ifact * i) % mod
ifact = pow(ifact, mod-2, mod)
fact = 1
for i in range(a+b, a+b-m, -1):
fact = (fact * i) % mod
print(fact*ifact % mod)
| 0 | null | 91,319,768,408,870 | 168 | 281 |
a,b,c = map(int,input().split()) ;
count = 0 ;
for i in range(a,b+1) :
d = c % i ;
if d == 0 :
count = count +1
print("%d" % count)
|
x = map(int, raw_input().split())
flag = 0
for i in range(x[0], x[1]+1):
if x[2] % i == 0:
flag += 1
print flag
| 1 | 560,242,832,590 | null | 44 | 44 |
class Reader:
def __init__(self):
self.l = 0
self.r = 0
def __call__(self, s):
l, r = s.split()
if l > r:
self.l += 3
elif l < r:
self.r += 3
else:
self.l += 1
self.r += 1
def __str__(self):
return "{} {}".format(self.l, self.r)
reader = Reader()
n = int(input())
for _ in range(n):
reader(input())
print(reader)
|
from __future__ import division, print_function
from sys import stdin
word = stdin.readline().rstrip().lower()
cnt = 0
for line in stdin:
if line.startswith('END_OF_TEXT'):
break
cnt += line.lower().split().count(word)
print(cnt)
| 0 | null | 1,887,013,295,360 | 67 | 65 |
while 1:
n,x=map(int,input().split())
if n+x==0:break
c=0
for i in range(3,n+1):
for j in range(2,x-i):
if x-i-j<j<i:
c+=1
print(c)
|
from itertools import combinations as comb
def get_ans(m, n):
ans = sum(1 for nums in comb(range(1, min(m+1,n-2)), 2) if ((n-sum(nums)>0) and (n-sum(nums) > max(nums)) and (n-sum(nums)<=m)))
return ans
while True:
m, n = (int(x) for x in input().split())
if m==0 and n==0:
quit()
ans = get_ans(m, n)
print(ans)
| 1 | 1,303,534,083,840 | null | 58 | 58 |
import math
A = int(input())
B = int(input())
N = int(input())
if A> B:
print(math.ceil(N/A))
else:
print(math.ceil(N/B))
|
import sys, math, operator, itertools, collections, heapq, bisect
# sys.setrecursionlimit(10**4)
class Solution:
def __init__(self):
pass
def solve(self, *Input):
ans = 0
h,w,k,matrix = Input
# print(matrix)
for r in range(h):
rows = list(itertools.combinations(range(h),r))
for c in range(w):
# print(r,c)
cols = list(itertools.combinations(range(w), c))
# print(list(rows), list(cols))
for row in rows:
for col in cols:
# print(row,col)
new_matrix = [[x for x in ROW] for ROW in matrix]
ans += self.create(h,w,k,new_matrix,row,col)
# print(ans)
return ans
def create(self, *Input):
h,w,k,matrix,rows,cols = Input
for i in range(h):
for j in cols:
matrix[i][j] = '.'
for r in rows:
matrix[r] = ['.'] * w
# print(matrix)
return self.check(k,matrix)
def check(self, *Input):
k,matrix = Input
cnt = 0
for row in matrix:
cnt += row.count('#')
return cnt == k
def sieve_classic(self,a,b):
self.primes = [True] * (b+1)
self.primes[0] = self.primes[1] = False
for i in range(2,b+1):
if self.primes[i] and i*i <= b:
for j in range(i*i,b+1,i):
self.primes[j] = False
self.primes = [x for x,y in enumerate(self.primes) if y]
ind = bisect.bisect_left(self.primes,a)
self.primes[:ind] = []
return None
if __name__=='__main__':
solution = Solution()
inputs = iter(sys.stdin.readlines())
h,w,k = map(int, next(inputs).split())
matrix = [list(next(inputs).rstrip()) for _ in range(h)]
ans = solution.solve(h,w,k,matrix)
print(ans)
| 0 | null | 48,790,422,627,840 | 236 | 110 |
st = str(input())
q = int(input())
com = []
for i in range(q):
com.append(input().split())
for k in com:
if k[0] == "print":
print(st[int(k[1]):int(k[2])+1])
elif k[0] == "reverse":
s = list(st[int(k[1]):int(k[2])+1])
s.reverse()
ss = "".join(s)
st = st[:int(k[1])] + ss + st[int(k[2])+1:]
else:
st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]
|
word = input()
n = int(input())
for _ in range(n):
meirei = input().split()
if meirei[0] == "print":
print(word[int(meirei[1]):int(meirei[2])+1])
elif meirei[0] == "reverse":
word = word[:int(meirei[1])] + word[int(meirei[1]):int(meirei[2])+1][::-1] + word[int(meirei[2])+1:]
elif meirei[0] == "replace":
word = word[:int(meirei[1])] + meirei[3] + word[int(meirei[2])+1:]
| 1 | 2,080,928,322,692 | null | 68 | 68 |
import math
def koch(n, p1_x, p1_y, p2_x, p2_y):
if n == 0:
print(f"{p1_x:.8f} {p1_y:.8f}")
return
# p1, p2からs, t, uを計算
# 与えられた線分(p1, p2) を3等分点s、tを求める
s_x = (2 * p1_x + 1 * p2_x) / 3
s_y = (2 * p1_y + 1 * p2_y) / 3
t_x = (p1_x + 2 * p2_x) / 3
t_y = (p1_y + 2 * p2_y) / 3
# 線分を3等分する2点 s,t を頂点とする正三角形 (s,u,t) を作成する
u_x = (
(t_x - s_x) * math.cos(math.pi / 3) - (t_y - s_y) * math.sin(math.pi / 3) + s_x
)
u_y = (
(t_x - s_x) * math.sin(math.pi / 3) + (t_y - s_y) * math.cos(math.pi / 3) + s_y
)
# 線分 (p1,s)、線分 (s,u)、線分 (u,t)、線分 (t,p2)に対して再帰的に同じ操作を繰り返す
koch(n - 1, p1_x, p1_y, s_x, s_y)
koch(n - 1, s_x, s_y, u_x, u_y)
koch(n - 1, u_x, u_y, t_x, t_y)
koch(n - 1, t_x, t_y, p2_x, p2_y)
n = int(input())
koch(n, 0, 0, 100, 0)
print("100.00000000 0.00000000")
|
S = input()
N = len(S)
ans = ["x" for i in range(N)]
print(*ans, sep="")
| 0 | null | 36,453,588,060,668 | 27 | 221 |
w,h,x,y,r = map(int,raw_input().split())
if w-r >= x and h-r >= y and x-r >= 0 and y-r >= 0:
print "Yes"
else:
print "No"
|
from collections import deque
N, M, K = map(int, input().split())
friend = [list(map(int, input().split())) for _ in range(M)]
block = [list(map(int, input().split())) for _ in range(K)]
f = [set() for _ in range(N + 1)]
b = [set() for _ in range(N + 1)]
for i, j in friend:
f[i].add(j)
f[j].add(i)
for i, j in block:
b[i].add(j)
b[j].add(i)
stack = deque()
ans = [0] * (N + 1)
visited = [0] * (N + 1)
for i in range(1, N + 1):
if visited[i]:
continue
# setは{}で書く
link = {i}
stack.append(i)
visited[i] = 1
while stack:
n = stack.pop()
# nのフレンド全員について
for j in f[n]:
if visited[j] == 0:
stack.append(j)
visited[j] = 1
# link(set)に追加
link.add(j)
for i in link:
# 全体-既にフレンドの人数-ブロックした人数-自分自身
# set同士で積集合をとる
ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1
print(*ans[1:])
| 0 | null | 31,117,977,757,852 | 41 | 209 |
n = [int(i) for i in input().split()]
print(max(n[0] - 2*n[1], 0))
|
x = list(map(int,input().split()))
a = x[0]
b = x[1]
if(2*b < a):
print(a-2*b)
else:
print(0)
| 1 | 166,610,115,017,796 | null | 291 | 291 |
import sys
n=int(input())
data=list(map(int,input().split()))
for i in data:
if i%2==1:
continue
if i%3!=0 and i%5!=0:
print("DENIED")
sys.exit()
print("APPROVED")
|
N = int(input())
data = list(map(int,input().split()))
sw1 = 0
sw2 = 0
for i in range(0,len(data)):
if data[i] % 2 == 0:
sw1 += 1
if data[i] % 3 == 0 or data[i] % 5 == 0:
sw2 += 1
if sw1 >= 0 and sw1 == sw2:
print("APPROVED")
else:
print("DENIED")
| 1 | 68,894,262,682,600 | null | 217 | 217 |
N=int(input())
*A,=map(int, input().split())
B=[(i+1,a) for i,a in enumerate(A)]
from operator import itemgetter
B.sort(reverse=True, key=itemgetter(1))
dp = [[-1] * (N+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
idx, act = B[i-1]
for j in range(i+1):
k = i-j
if 0<j: dp[j][k] = max(dp[j][k], dp[j-1][k] + act * abs(idx-j))
if 0<k: dp[j][k] = max(dp[j][k], dp[j][k-1] + act * abs(idx-(N-k+1)))
ans=0
for j in range(N+1):
ans = max(ans, dp[j][N-j])
print(ans)
|
import math
a,b,x=map(int,input().split())
if a*a*b==x:
ans=90
elif x>((a**2)*b)/2:
ans=math.degrees(math.atan(a/(2*(b-(x/(a**2))))))
else:
ans=math.degrees(math.atan((2*x)/(a*(b**2))))
print(90-ans)
| 0 | null | 98,625,893,313,700 | 171 | 289 |
A,B = input().split()
print((int(A)*round(100*float(B)))//100)
|
import math
def main() -> None:
a, b = input().split()
print((int(a)*int(b.replace('.', ''))) // 100)
return
if __name__ == '__main__':
main()
| 1 | 16,655,616,386,850 | null | 135 | 135 |
a=map(int,raw_input().split())
if 0<=a[2]-a[4] and a[2]+a[4]<=a[0] and 0<=a[3]-a[4] and a[3]+a[4]<=a[1]:
print "Yes"
else:
print "No"
|
__author__ = 'CIPHER'
_project_ = 'PythonLehr'
class BoundingBox:
def __init__(self, width, height):
self.width = width;
self.height = height;
def CalculateBox(self, x, y, r):
if x>= r and x<=(self.width-r) and y>=r and y<=(self.height-r):
print("Yes")
else:
print("No")
'''
width = int(input("Width of the Box: "))
height = int(input("Height of the Box: "))
x = int(input("location of x: "))
y = int(input("location of y: "))
r = int(input("radius of the circle; "))
'''
# alternative input
inputList = input()
inputList = inputList.split(' ')
inputList = [int(x) for x in inputList]
# print(inputList)
width = inputList[0]
height = inputList[1]
x = inputList[2]
y = inputList[3]
r = inputList[4]
Box = BoundingBox(width, height)
Box.CalculateBox(x, y, r)
| 1 | 453,376,846,468 | null | 41 | 41 |
# coding: utf-8
# Here your code !
import sys
n = [int(input()) for i in range (1,11)]
#t = [int(input()) for i in range(n)]
n.sort()
n.reverse()
for j in range (0,3):
print(n[j])
|
import math
def main():
a, b, x = map(int, input().split())
if x < a * a * b / 2:
tan = 2 * x / (b * b * a)
print(90 - math.degrees(math.atan(tan)))
else:
tan = (2 / a) * (b - x / a**2)
print(math.degrees(math.atan(tan)))
if __name__ == '__main__':
main()
| 0 | null | 81,791,740,242,770 | 2 | 289 |
S = input()
companies = {company for company in S}
if len(companies) > 1:
print('Yes')
else:
print('No')
|
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
s = input()
if s == 'AAA' or s == 'BBB':
ans = 'No'
else:
ans = 'Yes'
print(ans)
| 1 | 54,999,747,347,776 | null | 201 | 201 |
x = list(map(int, input().split()))
d = list(input())
for i in d:
if i == 'S':
t=x[1]
x[1]=x[0]
x[0]=x[4]
x[4]=x[5]
x[5]=t
elif i == 'N':
t=x[1]
x[1]=x[5]
x[5]=x[4]
x[4]=x[0]
x[0]=t
elif i == 'E':
t=x[2]
x[2]=x[0]
x[0]=x[3]
x[3]=x[5]
x[5]=t
elif i == 'W':
t=x[2]
x[2]=x[5]
x[5]=x[3]
x[3]=x[0]
x[0]=t
print(x[0])
|
while 1:
w,h=map(int,raw_input().split())
if(w==0):break
a,b="#\n";print a*h+b+(a+"."*(h-2)+a+b)*(w-2)+a*h+b
| 0 | null | 539,455,165,210 | 33 | 50 |
n=int(input())
a=[]
from collections import deque as dq
for i in range(n):
aaa=list(map(int,input().split()))
aa=aaa[2:]
a.append(aa)
dis=[-1]*n
dis[0]=0
queue=dq([0])
while queue:
p=queue.popleft()
for i in range(len(a[p])):
if dis[a[p][i]-1]==-1:
queue.append(a[p][i]-1)
dis[a[p][i]-1]=dis[p]+1
for i in range(n):
print(i+1,dis[i])
|
N=int(input())
a=list(map(int,input().split()))
count=0
for i in range(len(a)):
if ((i+1)%2==1)&(a[i]%2==1):
count+=1
print(count)
| 0 | null | 3,909,677,068,000 | 9 | 105 |
def main():
A, B, C = map(int, input().split())
if A == B and A != C:
print("Yes")
elif B == C and B != A:
print("Yes")
elif C == A and C != B:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
a,b,c=input().split()
if(a==b)+(b==c)+(c==a)==1:
print('Yes')
else:
print('No')
| 1 | 67,823,125,965,952 | null | 216 | 216 |
import sys
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]
def main():
a = II()
print(a + pow(a,2) + pow(a,3))
if __name__ == "__main__":
main()
|
N = int(input())
s = [input().split() for _ in range(N)]
X = input()
for i in range(N):
if X == s[i][0]:
break
ans = 0
for j in range(i+1, N):
ans += int(s[j][1])
print(ans)
| 0 | null | 53,536,264,578,272 | 115 | 243 |
import sys
for i in sys.stdin.readlines():
x = i.split(" ")
print len(str(int(x[0]) + int(x[1])))
|
num = list(map(int,input().split()))
circle_px = num[2] + num[4]
circle_mx = num[2] - num[4]
circle_py = num[3] + num[4]
circle_my = num[3] - num[4]
if(circle_px <= num[0] and circle_mx >= 0 and circle_py <= num[1] and circle_py >= 0): print("Yes")
else: print("No")
| 0 | null | 225,894,908,020 | 3 | 41 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
H, W, K = map(int, input().split())
grid = [[_ for _ in input()] for _ in range(H)]
ans = [[0] * W for _ in range(H)]
cnt = 0
for h in range(H):
for w in range(W):
if grid[h][w] == '#':
cnt += 1
ans[h][w] = cnt
now = -1
for h in range(H):
for w in range(W):
if ans[h][w] != 0:
now = ans[h][w]
if ans[h][w] == 0:
if now != -1:
ans[h][w] = now
now = -1
now = -1
for h in range(H):
for w in reversed(range(W)):
if ans[h][w] != 0:
now = ans[h][w]
if ans[h][w] == 0:
if now != -1:
ans[h][w] = now
now = -1
for h in range(1,H):
if ans[h][0] == 0:
for w in range(W):
ans[h][w] = ans[h - 1][w]
for h in reversed(range(H-1)):
if ans[h][0] == 0:
for w in range(W):
ans[h][w] = ans[h + 1][w]
for a in ans:
print(*a)
resolve()
|
A,B,C,D=map(int,input().split())
nT = 0
nA = 0
while C-B>0:
C -= B
nT += 1
while A-D>0:
A -= D
nA += 1
if nT <= nA:
print('Yes')
else:
print('No')
| 0 | null | 86,399,438,572,620 | 277 | 164 |
print((lambda x : x**3)(int(input())))
|
H,W = map(int,input().split())
grid = [[0] for _ in range(H)]
for i in range(H):
grid[i] = input()
dp = [[float('inf')]*W for _ in range(H)]
if grid[0][0] == '.':
dp[0][0] = 0
else:
dp[0][0] = 1
for y in range(H):
for x in range(W):
if x > 0:
if grid[y][x-1] == '.' and grid[y][x] == '#':
dp[y][x] = min(dp[y][x],dp[y][x-1]+1)
else:
dp[y][x] = min(dp[y][x],dp[y][x-1])
if y > 0:
if grid[y-1][x] == '.' and grid[y][x] == '#':
dp[y][x] = min(dp[y][x],dp[y-1][x]+1)
else:
dp[y][x] = min(dp[y][x],dp[y-1][x])
print(dp[-1][-1])
| 0 | null | 24,766,628,949,670 | 35 | 194 |
n,m = map(int,input().split())
alist = list(map(int,input().split()))
d = n - sum(alist)
if d < 0:
print(-1)
else:
print(d)
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = n - sum(a)
print(-1 if ans < 0 else ans)
| 1 | 32,124,279,458,788 | null | 168 | 168 |
s=input()
ans='No'
if s[2]==s[3] and s[4]==s[5]:
ans='Yes'
print(ans)
|
from sys import stdin
from math import ceil
def is_stackable(k,p,w):
if max(w) > p:
return False
s = w[0]
count = len(w)
for i in range(1, len(w)):
if s + w[i] <= p:
s += w[i]
count -= 1
else:
s = w[i]
return k >= count
def main():
n,k = map(int, stdin.readline().split())
w = [int(line) for line in stdin.readlines()]
left = max(max(w), ceil(sum(w)/k))
right = (max(w) * ceil(n/k)) + 1
while True:
mid = int((left + right) / 2)
if is_stackable(k, mid, w):
if not is_stackable(k, mid - 1, w):
print(mid)
break
right = mid
else:
if is_stackable(k, mid + 1, w):
print(mid + 1)
break
left = mid + 1
main()
| 0 | null | 20,891,483,862,432 | 184 | 24 |
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()
|
array = []
while True:
n = input()
if n == "0 0":
break
array.append(n.split())
for i in range(len(array)):
for i2 in range(int(array[i][0])):
for i3 in range(int(array[i][1])):
if i3 == int(array[i][1])-1:
print("#")
else:
print("#",end="")
print("")
| 1 | 778,836,804,020 | null | 49 | 49 |
import sys
lines = [list(map(int,line.split())) for line in sys.stdin]
n,m,l = lines[0]
A = lines[1:n+1]
B = [i for i in zip(*lines[n+1:])]
for a in A:
row = []
for b in B:
row.append(sum([i*j for i,j in zip(a,b)]))
print (" ".join(map(str,row)))
|
n,k=map(int,input().split())
A = list(map(int,input().split()))
C=[0]*n
C[0]=1
c=0
loopc=0
i=0
io=0
while c<k :
newi = A[i]-1
C[newi]+=1
if C[newi]>=3 :
rs=newi
break
elif C[newi]==2 :
loopc+=1
io=i
i=newi
c+=1
if (k-c)<0 or loopc==0 :
print(i+1)
exit()
mod = (k-c)%(loopc)
# print( k, c, loopc, i, mod)
# i=rs
while mod>0 :
newi = A[i]-1
i=newi
mod-=1
print( i+1 )
| 0 | null | 12,159,600,503,112 | 60 | 150 |
#E
#greedy
n = input()
n = n[::-1] + "0"
l = len(n)
ans = 0
kuriagari=0
for i,v in enumerate(n):
v = int(v)
if kuriagari:
v += 1
if v<5:
ans += v
kuriagari = 0
if v>5:
ans += 10 - v
kuriagari = 1
if v==5:
if int(n[i+1])<5:
#delete is better
ans += v
kuriagari = 0
if int(n[i+1])>=5:
#kuriagari is promising
ans += 10 - v
kuriagari = 1
print(ans)
|
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 deque
from collections import defaultdict
def main():
N = S()
N = N[::-1]
N += '0'
cnt = 0
next = 0
for i in range(len(N)):
num = int(N[i])
num += next
if num <= 4:
cnt += num
next = 0
elif num >= 6:
cnt += 10 - num
next = 1
else:
if int(N[i + 1]) <= 4:
cnt += num
next = 0
else:
cnt += 10 - num
next = 1
print(cnt)
if __name__ == "__main__":
main()
| 1 | 70,921,438,527,650 | null | 219 | 219 |
s=str(input())
s=list(s)
if s[len(s)-1]=="s":
print("".join(s)+"es")
else:
print("".join(s)+"s")
|
import sys
w = input().lower()
lines = sys.stdin.read()
line=lines[0:lines.find('END_OF_TEXT')].lower().split()
print(line.count(w))
| 0 | null | 2,091,595,306,408 | 71 | 65 |
x=list(map(int, input().split()))
L=x[0]
R=x[1]
d=x[2]
res=0
while L<=R:
if L%d==0:
res+=1
L+=1
print(res)
|
l,R, d = map(int, input().split())
a =0
for i in range(l,R+1):
if i % d == 0:
a = a+1
print(a)
| 1 | 7,583,513,939,794 | null | 104 | 104 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H,W = map(int,readline().split())
S = ''.join(read().decode().split())
INF = 10 ** 9
N = H*W
U = 250
dp = [[INF] * U for _ in range(N)]
# そのマスをいじる回数 → 総回数の最小値
dp[0] = list(range(U))
for n in range(H*W):
for i in range(U-1,0,-1):
if dp[n][i-1]> dp[n][i]:
dp[n][i-1] = dp[n][i]
for i in range(1,U):
if dp[n][i-1] + 1 < dp[n][i]:
dp[n][i] = dp[n][i-1] + 1
s = S[n]
if s == '#':
for i in range(0,U,2):
dp[n][i] = INF
else:
for i in range(1,U,2):
dp[n][i] = INF
x,y = divmod(n,W)
to = []
if y < W - 1:
to.append(n+1)
if x < H - 1:
to.append(n+W)
for m in to:
for i in range(U):
if dp[m][i] > dp[n][i]:
dp[m][i] = dp[n][i]
print(min(dp[-1]))
|
from itertools import product
from collections import deque
class ZeroOneBFS:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
assert weight in [0, 1]
self.E[init].append((end, weight))
if undirected: self.E[end].append((init, weight))
def distance(self, s):
INF = float('inf')
E, N = self.E, self.N
dist = [INF] * N # the distance of each vertex from s
prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
dist[s] = 0
dq = deque([(0, s)]) # (dist, vertex)
n_visited = 0 # #(visited vertices)
while dq:
d, v = dq.popleft()
if dist[v] < d: continue # (s,v)-shortest path is already calculated
for u, c in E[v]:
temp = d + c
if dist[u] > temp:
dist[u] = temp; prev[u] = v
if c == 0: dq.appendleft((temp, u))
else: dq.append((temp, u))
n_visited += 1
if n_visited == N: break
self.dist, self.prev = dist, prev
return dist
def shortest_path(self, t):
P = []
prev = self.prev
while True:
P.append(t)
t = prev[t]
if t == -1: break
return P[::-1]
H, W = map(int, input().split())
zobfs = ZeroOneBFS(H * W)
def vtx(i, j): return i*W + j
def coord(n): return divmod(n, W)
grid = [input() for _ in range(H)] # |string| = W
E = [[] for _ in range(H * W)]
ans = 0 if grid[0][0] == '.' else 1
for i, j in product(range(H), range(W)):
v = vtx(i, j)
check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1]
for u in check:
x, y = coord(u)
if grid[i][j] == '.' and grid[x][y] == '#':
zobfs.add_edge(v, u, 1)
else:
zobfs.add_edge(v, u, 0)
dist = zobfs.distance(0)
ans += dist[vtx(H-1, W-1)]
print(ans)
| 1 | 49,144,763,010,730 | null | 194 | 194 |
import sys
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
return int(readline())
def reads():
return map(int, readline().split())
x=read()
a=list(reads())
dic=[]
dic2=defaultdict(int)
for i in range(x):
dic.append(i+a[i])
dic2[i-a[i]]+=1
ans=0
#print(dic,dic2)
for i in dic:
ans+=dic2[i]
print(ans)
|
N,M = map(int,input().split())
A = [int(x) for x in input().split()]
if N - sum(A) >= 0 :
print(N-sum(A))
else :
print("-1")
| 0 | null | 29,009,039,793,608 | 157 | 168 |
def is_prime(num: int) -> bool:
# 6k +- 1 <= √n
if num <= 1:
return False
if num <= 3:
return True
if num % 2 == 0 or num % 3 == 0:
return False
i = 5
while i * i <= num:
if num % i == 0 or num % (i+2) == 0:
return False
i += 6
return True
x = int(input())
for i in range(x,1000000):
if is_prime(i):
print(i)
break
|
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
X = int(input())
while True:
if isPrime(X):
print(X)
break
X += 1
| 1 | 105,651,057,364,112 | null | 250 | 250 |
N = int(input())
if N%2:
N += 1
print(N//2-1)
|
s = input().split()
if s[0]==s[1] and s[0]!=s[2]:
print("Yes")
elif s[0]==s[2] and s[0]!=s[1]:
print("Yes")
elif s[2]==s[1] and s[0]!=s[2]:
print("Yes")
else:
print("No")
| 0 | null | 110,381,164,629,550 | 283 | 216 |
def main():
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()
n = int(input())
nd = defaultdict(int)
for i in range(1, n+1):
tmp = str(i)
h, t = int(tmp[0]), int(tmp[-1])
nd[(h, t)] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += nd[(i, j)]*nd[(j, i)]
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
A = list(map(int, input().split()))
ans = 10**18
total = sum(A)
acc = 0
for a in A:
acc += a
ans = min(ans, abs(total - acc * 2))
print(ans)
| 0 | null | 114,672,899,529,340 | 234 | 276 |
N=int(input())
ans=0
for i in range(1,int(N**(1/2))+1):
a=(N-1)//i
ans+=(a-i)*2+1
if int(N**(1/2))**2==N:
ans+=1
print(ans)
|
def function(a):
return a + pow(a,2) + pow(a, 3)
if __name__ == "__main__":
a = int(input())
print(function(a))
| 0 | null | 6,387,435,422,984 | 73 | 115 |
from itertools import permutations
def main():
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
As = list(permutations(A))
for i in range(len(As)):
a = As[i]
for j in range(len(a)):
if a[j] != P[j]:
break
else:
p_rank = i
break
for i in range(len(As)):
a = As[i]
for j in range(len(a)):
if a[j] != Q[j]:
break
else:
q_rank = i
break
print(abs(p_rank-q_rank))
if __name__ == '__main__':
main()
|
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
c = [i for i in range(1,n+1)]
v = list(itertools.permutations(c,n))
a = v.index(p)
b = v.index(q)
print(abs(a-b))
| 1 | 100,602,384,886,772 | null | 246 | 246 |
#!/usr/bin/env python3
import sys, math
sys.setrecursionlimit(300000)
def solve(H: int, W: int, N: int):
ret = min(math.ceil(N / H), math.ceil(N / W))
print(ret)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
H = int(next(tokens)) # type: int
W = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
solve(H, W, N)
if __name__ == '__main__':
main()
|
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
h, w, n = int(input()), int(input()), int(input())
print(min((n - 1) // h + 1, (n - 1) // w + 1))
resolve()
| 1 | 88,791,620,084,970 | null | 236 | 236 |
a,b= input().split()
print(str(min(int(a),int(b)))*int(str(max(int(a),int(b)))))
|
A,B = map(int, input().split())
A1,B1 = str(A), str(B)
A2 = int(str(A)*B)
B2 = int(str(B)*A)
if A2 >= B2:
print(A2)
else:
print(B2)
| 1 | 84,085,153,299,488 | null | 232 | 232 |
n,*aa = map(int, open(0).read().split())
from collections import Counter
c = Counter(aa)
for i in range(1,n+1):
print(c[i])
|
import sys
def I(): 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 main():
n = I()
A = LI()
sub = [0]*n
for a in A:
sub[a-1] += 1
for s in sub:
print(s)
if __name__ == '__main__':
main()
| 1 | 32,429,037,729,442 | null | 169 | 169 |
import sys
input = sys.stdin.readline
n, (s, t) = int(input()), input()[:-1].split()
print(''.join(s[i] + t[i] for i in range(n)))
|
n = int(input())
s, t = map(str, input().split())
for i in range(n):
print(s[i]+t[i], end="")
| 1 | 112,170,660,932,812 | null | 255 | 255 |
import numpy as np
from fractions import gcd
def lcm(a,b):
return a*b//gcd(a,b)
N,M=map(int,input().split())
a=[i//2 for i in map(int,input().split())]
b=np.array(a)
cnt=0
while all(b%2==0):
b//=2
if any(b%2==0):
print(0)
exit()
ans=1
for i in a:
ans=lcm(ans,i)
print((M//ans-1)//2+1)
|
s = input()
if s == "AAA" or s == "BBB" :
print ("No")
else : print ("Yes")
| 0 | null | 77,907,727,484,628 | 247 | 201 |
import sys
import itertools
sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()
dbg = lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)
N = ni()
A = nl()
assert len(A) == (N + 1)
def solve():
ar = list(itertools.accumulate(A[::-1]))
ar.reverse()
ar.append(0)
assert len(ar) == (N + 2)
if N == 0:
return 1 if A[0] == 1 else -1
if A[0] != 0:
return -1
inn = ans = 1
for i in range(1, N + 1):
b = 2 * inn - A[i]
if b < 0:
return -1
inn = min(b, ar[i + 1])
ans += inn + A[i]
return ans
print(solve())
|
x = []
for i in range(3):
a =input().split()
x.append(a)
n = int(input())
b =[input() for i in range(n)]
for i in range(3):
for j in range(3):
if x[i][j] in b:
x[i][j] = '*'
for i in range(3):
for j in range(3):
if x[i][0] == x[i][1] == x[i][2]:
print('Yes')
exit()
elif x[0][i] == x[1][i] == x[2][i]:
print('Yes')
exit()
elif x[0][0] == x[1][1] == x[2][2]:
print('Yes')
exit()
elif x[0][2] == x[1][1] == x[2][0]:
print('Yes')
exit()
print('No')
| 0 | null | 39,274,302,479,130 | 141 | 207 |
def area_cal(input_fig):
stack = []
# area = [[面積計算が始まった位置, 面積],・・・]
area = []
total = 0
for i in range(len(input_fig)):
fig = input_fig[i]
if fig == "\\":
stack.append(i)
elif fig == "/" and stack:
j = stack.pop()
width = i - j
total += width
while area and area[-1][0] > j:
width += area[-1][1]
area.pop()
area.append([i,width])
return area, total
input_fig = input()
area, total = area_cal(input_fig)
print(total)
if area:
print(len(area),*list(zip(*area))[1])
else:
print(0)
|
# ALDS1_3_D.
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def main():
data = list(input())
a = [] # '\\'の位置を格納していく。
b = [] # 同じだが、池の集約に使う。
ponds = [] # 池の面積のリスト(必要に応じて集約).
Area = 0 # 総面積
N = len(data)
for i in range(N):
if data[i] == '\\':
a.append(i); b.append(i)
elif data[i] == '/':
if len(a) == 0: continue
else:
left = a.pop() # '/'と対になる'\\'の位置
Area += i - left
ponds.append(i - left)
# leftより右にあるbの元を先頭から見てあればカット、
# その分だけpondsを集約する。
while left < b[len(b) - 1]:
b.pop()
x = ponds.pop(); y = ponds.pop(); ponds.append(x + y)
print(Area)
ponds.insert(0, len(ponds))
show(ponds)
if __name__ == "__main__":
main()
| 1 | 57,675,604,510 | null | 21 | 21 |
N, K = map(int,input().split())
ans = 0
while K <= N+1:
ans += ((N+1)*(N+2) - (N-K+1)*(N-K+2) - K*(K+1)) // 2 + 1
K += 1
print(ans % (10 ** 9 + 7))
|
def main():
H, W, K = map(int, input().split())
chocolate = [list(map(int,list(input()))) for _ in range(H)]
choco = [[0]*W for _ in range(H)]
ids = [0] * H
ans = 10 ** 9
for bit in range(1<<(H-1)):
group_id = 0
for i in range(H):
ids[i] = group_id
if (bit>>i)&1:
group_id += 1
group_id += 1
for i in range(group_id):
for j in range(W):
choco[i][j] = 0
for i in range(H):
for j in range(W):
choco[ids[i]][j] += chocolate[i][j]
if any(choco[i][j] > K for i in range(group_id) for j in range(W)):
continue
num = group_id - 1
now = [0] * group_id
def add(j):
for i in range(group_id):
now[i] += choco[i][j]
if any(now[i] > K for i in range(group_id)):
return False
else:
return True
for j in range(W):
if not add(j):
num += 1
now = [0] * group_id
add(j)
ans = min(ans, num)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 40,975,249,872,610 | 170 | 193 |
def solve():
N = int(input())
S = input()
C = [c for c in S]
left = 0
right = len(C) -1
ans = 0
while left < right:
while left < right and C[left] == 'R':
left += 1
while left < right and C[right] == 'W':
right -= 1
if left < right:
C[left] = 'R'
C[right] = 'W'
ans += 1
left += 1
right -= 1
print(ans)
if __name__ == "__main__":
solve()
|
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n=int(input())
ar=lis()
k=0
for i in ar:
k=(k^i)
for i in ar:
print(k^i,end=" ")
| 0 | null | 9,382,569,563,068 | 98 | 123 |
import sys
for i in sys.stdin.readlines():
m, f, r = [int(x) for x in i.split()]
if m == f == r == -1:
break
elif (m == -1 or f == -1) or (m + f < 30):
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50 or (30 <= m + f <= 50 and r >= 50):
print('C')
elif m + f >= 30:
print('D')
|
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort(); F = F[::-1]
def check(x):
cost = np.maximum(0, A - (x // F)).sum()
return cost <= K
ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
mid = (ok+ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)
| 0 | null | 82,645,691,038,690 | 57 | 290 |
W = input()
T = ""
while True:
x = input()
if x == "END_OF_TEXT":
break
T += x + " "
num = 0
for t in T.split():
if t.lower() == W.lower():
num += 1
print(num)
|
word = raw_input()
text = []
while True:
raw = raw_input()
if raw == "END_OF_TEXT":
break
text += raw.lower().split()
print(text.count(word))
# print(text.lower().split().count(word))
| 1 | 1,838,745,354,140 | null | 65 | 65 |
# -*- coding: utf-8 -*-
def check(r,g,b):
if g > r and b > g:
return True
else:
return False
A,B,C = map(int, input().split())
K = int(input())
for i in range(K+1):
for j in range(K+1-i):
for k in range(K+1-i-j):
if i+j+k==0:
continue
r = A*(2**i)
g = B*(2**j)
b = C*(2**k)
if check(r, g, b):
print("Yes")
exit()
print("No")
|
import itertools
N, M = map(int, input().split())
print( len([i for i in list(itertools.combinations(([2]*N)+([3]*M), 2)) if sum(i) % 2 == 0]) )
| 0 | null | 26,396,769,790,648 | 101 | 189 |
n,*a = map(int,open(0).read().split())
cnt = [3]+[0]*n
ans = 1
mod = 10**9+7
for i in a:
ans = ans * cnt[i] % mod
cnt[i] -= 1
cnt[i+1] += 1
print(ans)
|
import collections
n = int(input())
d = list(map(int,input().split()))
ma = max(d)
mod = 998244353
if d[0] != 0:
print(0)
exit()
p = [0 for i in range(ma+1)]
for i in range(n):
p[d[i]] += 1
if p[0] != 1:
print(0)
exit()
else:
ans = 1
for i in range(1,ma+1):
ans *= (p[i-1]**p[i])%mod
ans %= mod
print(ans)
| 0 | null | 141,862,229,520,102 | 268 | 284 |
# N=int(input())
A,B=[int(x) for x in input().rstrip().split()]
if A<=B*2:
print(0)
else:
print(A-B*2)
|
from sys import stdin
a, b = map(int, stdin.readline().rstrip().split())
ans = max(0, a - 2 * b)
print(ans)
| 1 | 167,073,214,477,188 | null | 291 | 291 |
import sys
for line in sys.stdin:
result = 0
a, b = map(int, line.rstrip('\n').split(' '))
x = a + b
while x > 0:
result += 1
x /= 10
print result
|
# -*- coding: utf-8 -*-
import sys
for s in sys.stdin:
print len(str(int(s.rstrip().split()[0])+int(s.rstrip().split()[1])))
| 1 | 94,301,380 | null | 3 | 3 |
n = int(input())
ranges = []
for i in range(n):
x, l = map(int, input().split())
ranges.append([max(x-l, 0), x+l])
ranges.sort(key=lambda x: x[1])
start = 0
ans = 0
for range in ranges:
if range[0] >= start:
start = range[1]
ans += 1
print(ans)
|
from functools import reduce
from operator import mul
N,K,*A = map(int,open(0).read().split())
base = sum(A[:K])
for i in range(K,N):
score = base - A[i-K] + A[i]
print("Yes" if base < score else "No")
base = score
| 0 | null | 48,734,356,179,700 | 237 | 102 |
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np
# A = input()
A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
li = [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]
print(li[A-1])
|
s = "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"
lst = s.split(", ")
print(lst[int(input()) - 1])
| 1 | 50,109,500,247,322 | null | 195 | 195 |
a,b = input().split()
t = a*int(b)
q = b*int(a)
if t < q:
print(t)
else:
print(q)
|
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
X=[]
Y=[]
C=[]
for m in range(M):
x,y,c=map(int,input().split())
X.append(x)
Y.append(y)
C.append(c)
no_coupon=min(a)+min(b)
sum=[]
for i in range(M):
sum.append(a[X[i]-1]+b[Y[i]-1]-C[i])
with_coupon=min(sum)
print(min(no_coupon,with_coupon))
| 0 | null | 69,296,706,841,994 | 232 | 200 |
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
# ある値以上のAiがいくつあるかの情報を累積和で保持
num_A_or_more = [0]*(10**5)
for a in A:
num_A_or_more[a-1] += 1
for i in range(1, 10**5):
j = 10**5 - i
num_A_or_more[j-1] += num_A_or_more[j]
# x以上となる手の組み合わせがM種類以上あるかどうかを判定
def check(x):
count = 0
for a in A:
idx = max(x-a-1, 0)
if idx >= 10**5:
continue
count += num_A_or_more[idx]
return count>=M
# 2分探索でM種類以上の手の組み合わせがある満足度の最大値を求める
left = 0
right = 2*10**5 + 1
mid = (left + right) // 2
while right - left > 1:
if check(mid):
left = mid
else:
right = mid
mid = (left + right)//2
# これがM種類以上の手の組み合わせがある満足度の最大値
x = left
# 降順に並べなおして累積和を求めておく
rev_A = A[::-1]
accum_A = [rev_A[0]]
for i, a in enumerate(rev_A):
if i == 0:
continue
accum_A.append(accum_A[-1] + a)
ans = 0
count = 0
surplus = 2*10**5 # M種類を超えた場合は、一番小さくなる握手の組を最後に削る
for ai in rev_A:
idx = bisect.bisect_left(A, x-ai)
if idx == N:
break
ans += (N-idx)*ai + accum_A[N-idx-1]
count += N - idx
surplus = min(surplus, ai+A[idx])
print(ans - (count-M)*surplus)
|
W,H,x,y,r = list(map(int,input().split()))
print("No" if x<r or x+r>W or y<r or y+r>H else "Yes")
| 0 | null | 54,278,982,299,202 | 252 | 41 |
a=int(input())
b=a//3
c=a//5
d=a//15
z=0
y=0
w=0
v=0
for x in range(a+1):
z=z+x
for x in range(b+1):
y=y+x*3
for x in range(c+1):
w=w+x*5
for x in range(d+1):
v=v+x*15
print(z-y-w+v)
|
n = int(input())
m = 0
a = n // 3
b = n // 5
c = n // 15
for i in range(1,n+1):
m = m+i
for j in range(1,a+1):
m = m-(3*j)
for k in range(1,b+1):
m = m-(5*k)
for l in range(1,c+1):
m = m+(15*l)
print(m)
| 1 | 34,915,925,295,602 | null | 173 | 173 |
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N = list(input())
n = len(N)
K = int(input())
dp1 = [[0] * (K + 1) for _ in range(n + 1)] #N以下が確定していて、0以外の数をk個使ったとき
dp2 = [0] * (n + 1) #N以下が確定していないときの0以外の数の個数
for i in range(n):
a = int(N[i])
if a != 0:
dp2[i + 1] = dp2[i] + 1
else:
dp2[i + 1] = dp2[i]
#0を使うことで0以外の数が増えないパターン
for k in range(K + 1):
dp1[i + 1][k] = dp1[i][k]
#0以外の数を使うことで0以外の数が増えるパターン
for k in range(K):
dp1[i + 1][k + 1] += dp1[i][k] * 9
#今回でN以下が確定するパターン
tmp = dp2[i] #確定する前までに0以外の数を何個使っているか
if a == 0: #今回でN以下が確定することはない
continue
else:
if tmp > K: #すでにK個以上の0以外の数を使っているとき
continue
else:
if tmp == K: #ちょうどK個使っている時
dp1[i + 1][tmp] += 1 #0を使うしかない
else:
dp1[i + 1][tmp] += 1 #0を使うしかない
dp1[i + 1][tmp + 1] += (a - 1) #N以下を確定させるためaは使えない
ans = dp1[n][K]
if dp2[n] == K:
ans += 1
print (ans)
# print (dp1)
# print (dp2)
|
import numpy as np
N = input()
K = int(input())
n = len(N)
dp0 = np.zeros((n, K+1), np.int64)
dp1 = np.zeros((n, K+1), np.int64)
dp0[0, 0] = 1
dp0[0, 1] = int(N[0]) - 1
dp1[0, 1] = 1
for i, d in enumerate(N[1:]):
dp0[i+1] += dp0[i]
dp0[i+1, 1:] += dp0[i, :-1] * 9
if int(d) == 0:
dp1[i+1] = dp1[i]
elif int(d) == 1:
dp0[i+1] += dp1[i]
dp1[i+1, 1:] = dp1[i, :-1]
elif int(d) >= 2:
dp0[i+1] += dp1[i]
dp0[i+1, 1:] += dp1[i, :-1] * (int(d) - 1)
dp1[i+1, 1:] = dp1[i, :-1]
print(dp0[-1, K] + dp1[-1, K])
| 1 | 75,968,025,224,220 | null | 224 | 224 |
tmp = 0
while True:
i = raw_input().strip().split()
a = int(i[0])
b = int(i[1])
if a == 0 and b == 0:
break
if a > b:
tmp = a
a = b
b = tmp
print a,b
|
import sys
for s in sys.stdin:
a,b = sorted(map(int, s.split()))
if a == 0 and b == 0:
break
print(a,b)
| 1 | 524,069,424,034 | null | 43 | 43 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n, d, a = list(map(int, readline().split()))
xh = [list(map(int, readline().split())) for _ in range(n)]
from operator import itemgetter, add
import bisect
xh.sort(key=itemgetter(0))
coordinate = [xh[i][0] for i in range(n)]
hp = [xh[i][1] for i in range(n)]
ans = 0
dmg_cur = 0
dmg_cum = [0] * (n + 1)
for i in range(n):
x = coordinate[i]
h = hp[i]
dmg_cur += dmg_cum[i]
h -= dmg_cur
if h > 0:
num = (h + a - 1) // a
ans += num
dmg = a * num
dmg_cur += dmg
range_left = x
range_right = x + 2 * d
index_right = bisect.bisect_right(coordinate, range_right)
dmg_cum[index_right] -= dmg
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
l = []
def f(n):
return chr(n+ord("a"))
def search(s: str, cnt: int) -> str:
if len(s) == n:
return s
cnt = len(set(list(s)))
for i in range(0, min(cnt, len(s)) + 1):
g = search("".join([s, f(i)]), cnt + max(0, i - len(s) + 1))
if g is not None:
l.append(g)
search("", 1)
l.sort()
for s in l:
print(s)
| 0 | null | 67,219,444,208,622 | 230 | 198 |
from collections import deque
n = int(input())
g = [[] for _ in range(n)]
for i in range(n):
_, _, *edge = map(lambda x: int(x)-1, input().split())
g[i] = edge
q = deque()
q.append(0)
dist = [-1 for _ in range(n)]
dist[0] = 0
while(len(q) > 0):
v = q.popleft()
for nv in g[v]:
if(dist[nv] != -1): continue
dist[nv] = dist[v] + 1
q.append(nv)
for i in range(n):
print(i+1, dist[i])
|
import random
def Nickname():
Name = str(input()) #入力回数を決める
num = random.randint(0, len(Name) - 3)
print(Name[num:num+3])
if __name__ == '__main__':
Nickname()
| 0 | null | 7,364,839,894,708 | 9 | 130 |
S = str(input())
print(S[0:3])
|
MOD = 10**9 + 7
N = 2 * 10**6 + 10 # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod MOD)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod MOD)
inv = [0, 1]
def nCr(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
for i in range(2, N + 1):
fact.append((fact[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
factinv.append((factinv[-1] * inv[-1]) % MOD)
k = int(input())
s = len(input())
ans = 0
for i in range(k+1):
ansp = pow(26,i,MOD) * pow(25,k-i,MOD) * nCr(s+k-1-i,s-1,MOD) % MOD
ans = (ans + ansp) % MOD
print(ans)
| 0 | null | 13,900,145,517,568 | 130 | 124 |
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
h, w, m = map(int, input().split())
R = [0]*h
C = [0]*w
YX = []
for i in range(m):
y, x = map(int, input().split())
y, x = y-1, x-1
R[y] +=1
C[x] +=1
YX.append((y, x))
max_r = max(R)
max_c = max(C)
cr = 0
cc = 0
for i in range(h):
if R[i] == max_r:
cr += 1
for i in range(w):
if C[i] == max_c:
cc +=1
c = 0
for y, x in YX:
if R[y] == max_r and C[x] == max_c:
c += 1
if c < cr*cc:
print(max_r+max_c)
else:
print(max_r+max_c-1)
|
h,w,m = map(int,input().split())
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
a,b = map(int,input().split())
row[a] += 1
col[b] += 1
bombs.add((a,b))
r,c = max(row),max(col)
rcnt,ccnt = 0,0
for v in row:
if v==r:
rcnt += 1
for v in col:
if v==c:
ccnt += 1
doubled = 0
for i,j in bombs:
if row[i]==r and col[j]==c:
doubled += 1
if doubled==rcnt*ccnt:
print(r+c-1)
else:
print(r+c)
| 1 | 4,714,047,805,728 | null | 89 | 89 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def LIST() : return list(MAP())
def dfs(s,d,i):
for j in range(i+1):
s[d] = chr(ord('a')+j)
if d < len(s) - 1:
dfs(s, d+1, max(j+1, i))
else:
a.add("".join(s))
n = INT()
s = ['a']*n
a = set()
dfs(s, 0, 0)
b = sorted(list(a))
for x in b:
print(x)
|
weatherS = input()
serial = 0
dayBefore = ''
for x in weatherS:
if dayBefore != 'R':
if x == 'R':
serial = 1
else:
if x == 'R':
serial += 1
dayBefore = x
print(serial)
| 0 | null | 28,628,494,577,242 | 198 | 90 |
while(True):
h,w=map(int,input().split())
if h==0 and w==0:
break
rect=('#'*w+'\n')*h
print(rect)
|
X, Y = map(int, input().split(' '))
print('Yes' if (X * 2 <= Y <= X * 4) and (Y % 2 == 0) else 'No')
| 0 | null | 7,209,669,403,420 | 49 | 127 |
from decimal import *
a,b = map(str,input().split())
a,b = Decimal(a),Decimal(b)
ans = a*b
print(int(ans))
|
def main():
S, W = map(int, input().split())
cond = S <= W
print('unsafe' if cond else 'safe')
if __name__ == '__main__':
main()
| 0 | null | 23,010,628,745,580 | 135 | 163 |
def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
mod=10**9+7
def bp(a,n):
r=1
while(n):
if n%2:
r=r*a%mod
a=a*a%mod
n>>=1
return r
[n,k]=i2()
if n<=k:
x=1
for i in range(n-1):
x*=2*n-1-i
x%=mod
y=1
for i in range(n-1):
y*=i+1
y%=mod
print((x*bp(y,10**9+5))%mod)
else:
x=1
y=1
t=1
for i in range(k):
t*=i+1
t%=mod
y*=n-1-i
y%=mod
y*=n-i
y%=mod
c=bp(t,10**9+5)
x+=y*c*c
x%=mod
print(x)
|
N = int(input())
A = list(map(int, input().split()))
ans = [0] * N
for i, a in enumerate(A):
ans[a-1] = i + 1
print(' '.join(map(str, ans)))
| 0 | null | 123,763,620,073,160 | 215 | 299 |
# 159 ########## dbt
n, m = map(int, input().split())
def factorial(a):
p = 1
for i in range(a, 0 , -1):
p *= i
return p
def combo(b, num):
ans = factorial(b) // (factorial(num) * factorial(b - num))
return ans
print(combo(n, 2) + combo(m, 2))
|
import sys
for m,n in [map(int,x.split()) for x in list(sys.stdin)]:
g,r = m,n
while r!=0:
g,r = r,g%r
print(g,m//g*n)
| 0 | null | 22,800,413,143,522 | 189 | 5 |
#!/usr/bin/env python3
N = int(input().split()[0])
xlt_list = []
for _ in range(N):
x, l = list(map(int, input().split()))
xlt_list.append((x, l, x + l))
xlt_list = sorted(xlt_list, key=lambda x: x[2])
count = 0
before_t = -float("inf")
for i, xlt in enumerate(xlt_list):
x, l, t = xlt
if x - l >= before_t:
count += 1
before_t = t
ans = count
print(ans)
|
N=int(input())
L=list(map(int,input().split()))
i=0
n=1
while True:
if i==N:
break
if L[i]==n:
n+=1
i+=1
if n==1:
print(-1)
else:
print(N-n+1)
| 0 | null | 102,461,189,329,150 | 237 | 257 |
mod = 10**9 + 7
def C():
N = int(input())
ans = 10**N - 2*9**N + 8**N
print(ans%mod)
def A():
N = int(input())
if( N == 0):
print(1)
else:
print(0)
A()
|
N=int(input());M=N//500;M*=1000;X=500*(N//500);N-=X;M+=(N//5)*5;print(M)
| 0 | null | 22,841,372,640,312 | 76 | 185 |
def count(word, text):
"""Count the word in text.
Counting is done case-insensitively.
>>> count('a', 'A b c a')
2
>>> count('computer', 'Nurtures computer scientists' \
+ ' and highly-skilled computer engineers' \
+ ' who will create and exploit "knowledge"' \
+ ' for the new era. Provides an outstanding' \
+ ' computer environment.')
3
"""
return (text
.lower()
.split()
.count(word.lower()))
def run():
word = input()
text = ""
line = input()
while line != "END_OF_TEXT":
text += line + "\n"
line = input()
print(count(word, text))
if __name__ == "__main__":
run()
|
# -*- coding: utf-8 -*-
import sys
w = sys.stdin.readline().strip()
count = 0
while True:
t = list(map(str, input().split()))
if 'END_OF_TEXT' in t:
break
for i in range(len(t)):
if t[i].lower() == w:
count += 1
print(count)
| 1 | 1,819,988,852,468 | null | 65 | 65 |
S = str(input())
T = str(input())
lenS = len(S)
lenT = len(T)
splitS = []
for i in range(lenS - lenT +1):
tempS = S[i : i+lenT]
splitS.append(tempS)
answer = lenT
for tempS in splitS:
count = 0
for i in range(lenT):
if tempS[i] != T[i]:
count += 1
answer = min(answer, count)
print(answer)
|
import math
a,b,C = map(float,input().split())
S = 1/2*a*b*math.sin(C*math.pi/180)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180))
L = a+b+c
h = 2*S/a
print(format(S,'.8f'))
print(format(L,'.8f'))
print(format(h,'.8f'))
| 0 | null | 1,911,305,796,328 | 82 | 30 |
p = 1000000007
n = int(input())
A = list(map(int, input().split()))
ans = 1
cnt = [3 if i == 0 else 0 for i in range(n+1)]
for a in A:
ans *= cnt[a]
ans %= p
cnt[a] -= 1
cnt[a+1] += 1
print(ans)
|
import sys
input = sys.stdin.readline
from bisect import *
H, W, K = map(int, input().split())
S = [input()[:-1] for _ in range(H)]
ans = [[-1]*W for _ in range(H)]
now = 1
l = []
for i in range(H):
cnt = 0
for j in range(W):
if S[i][j]=='#':
cnt += 1
if cnt==0:
continue
l.append(i)
c = 0
for j in range(W):
ans[i][j] = now
if S[i][j]=='#':
c += 1
if c<cnt:
now += 1
now += 1
for i in range(H):
if '#' not in S[i]:
j = bisect_left(l, i)
if j==len(l):
for k in range(W):
ans[i][k] = ans[l[-1]][k]
else:
for k in range(W):
ans[i][k] = ans[l[j]][k]
for ans_i in ans:
print(*ans_i)
| 0 | null | 136,927,259,222,468 | 268 | 277 |
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log,gcd #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod-2,mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N=I()
A,B=[],[]
for i in range(N):
a,b = MI()
A.append(a)
B.append(b)
both_zero_cnt = 0
num_of_group = defaultdict(int) ##既約分数にしてあげて、(分子,分母)がkeyで、負なら分子が負になる他は正
for i in range(N):
a,b = A[i], B[i]
if(a==b==0):
both_zero_cnt+=1
continue
elif(a==0):
num_of_group[-inf,inf] += 1
num_of_group[inf,inf] += 0
elif(b==0):
num_of_group[inf,inf] += 1
else:
if(a*b<0):
a,b=abs(a),abs(b)
g = gcd(a,b)
a//=g
b//=g
num_of_group[(-b,a)] += 1
num_of_group[(b,a)] += 0
else:
a,b=abs(a),abs(b)
g = gcd(a,b)
a//=g
b//=g
num_of_group[(a,b)] += 1
# print(num_of_group.items())
if(both_zero_cnt==N):
print(N)
return
##solve
ans = ModInt(1)
# two_pow = [1]
# for i in range(N):
# two_pow.append((2*two_pow[-1])%mod)
# print(two_pow,"#######")
for (a,b),cnt1 in num_of_group.items():
if(a<0):
continue
tmp = ModInt(2)**cnt1
if (-a,b) in num_of_group:
cnt2 = num_of_group[-a,b]
tmp += ModInt(2)**cnt2
tmp-=1
if(tmp):
ans *= tmp
ans -= 1 ##全部選ばない
ans += both_zero_cnt
print(ans)
if __name__ == '__main__':
main()
|
n, m = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
if n==u:
a=a-1
if m==u:
b=b-1
print(a ,b)
| 0 | null | 46,432,375,463,998 | 146 | 220 |
from typing import Generic, List, TypeVar
T = TypeVar('T')
class Stack(Generic[T]):
def __init__(self) -> None:
self._container: List[T] = []
@property
def empty(self) -> bool:
return not self._container # コンテナが空ならば真となる
def push(self, item: T) -> None:
self._container.append(item)
def pop(self) -> T:
return self._container.pop() # LIFO
def __repr__(self) -> str:
return repr(self._container)
if __name__ == "__main__":
stack1 = Stack()
stack2 = Stack()
string = input()
sum = 0
for i in range(len(string)):
if string[i] == "\\":
stack1.push(i)
elif string[i] == "_":
pass
elif string[i] == "/":
if not stack1.empty:
j = stack1.pop()
sum += i - j
a = i - j
while not stack2.empty:
item = stack2.pop()
if item[0] <= j:
stack2.push(item)
break
else:
a += item[1]
stack2.push((j, a))
print(sum)
b = []
while not stack2.empty:
b.append(str(stack2.pop()[1]))
b.append(str(len(b)))
b.reverse()
print(' '.join(b))
|
import math
from sys import stdin
input = stdin.readline
def prime_fatorization(n):
# O(sqrt(n))
from collections import defaultdict
# a = []
a = defaultdict(int)
while not(n % 2):
# a.append(2)
a[2] += 1
n //= 2
f = 3
while f * f <= n:
if not(n % f):
# a.append(f)
a[f] += 1
n //= f
else:
f += 2
if n != 1:
# a.append(n)
a[n] += 1
return a
def main():
N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x)//2, input().split()))
pre = A[0]
for i in range(1, N):
if pre % 2 != A[i] % 2:
print(0)
return
if not A[0] % 2:
fac2 = prime_fatorization(A[0])[2]
for i in range(1, N):
if not A[i]//(2**fac2) % 2:
print(0)
return
lcm = A[0]
for i in range(1, N):
lcm = lcm * A[i] // math.gcd(lcm, A[i])
print((M // lcm + 1) // 2)
if(__name__ == '__main__'):
main()
| 0 | null | 51,180,963,162,824 | 21 | 247 |
def resolve():
H, W, K = map(int, input().split())
C = [input() for _ in range(H)]
cnt = 0
for h in range(1 << H):
for w in range(1 << W):
black = 0
for i in range(H):
for j in range(W):
if h >> i & 1 or w >> j & 1:
continue
if C[i][j] == "#":
black += 1
if black == K:
cnt += 1
print(cnt)
resolve()
|
xyz=list(map(int,input().split()))
xyz[0],xyz[1]=xyz[1],xyz[0]
xyz[0],xyz[2]=xyz[2],xyz[0]
print(xyz[0],xyz[1],xyz[2])
| 0 | null | 23,463,171,218,848 | 110 | 178 |
N, M = map(int, input().split())
if M == 0:
print(1)
exit()
group_list = []
group_index = [0] * N
for _ in range(M):
a, b = map(int, input().split())
if group_index[a-1] == 0 and group_index[b-1] == 0:
group_index[a-1] = len(group_list) + 1
group_index[b-1] = len(group_list) + 1
group_list.append(set([a, b]))
elif group_index[a-1] == 0:
group_index[a-1] = group_index[b-1]
group_list[group_index[b-1] - 1].add(a)
elif group_index[b-1] == 0:
group_index[b-1] = group_index[a-1]
group_list[group_index[a-1] - 1].add(b)
elif group_index[a-1] != group_index[b-1]:
if len(group_list[group_index[a-1] - 1]) > len(group_list[group_index[b-1] - 1]):
group_id_b = group_index[b-1] - 1
for p in group_list[group_id_b]:
group_index[p-1] = group_index[a-1]
group_list[group_index[a-1] - 1].add(p)
group_list[group_id_b] = set()
else:
group_id_a = group_index[a-1] - 1
for p in group_list[group_id_a]:
group_index[p-1] = group_index[b-1]
group_list[group_index[b-1] - 1].add(p)
group_list[group_id_a] = set()
print(max([len(g) for g in group_list]))
|
import collections
n, m = map(int, input().split())
par = list(range(2 * n))
# print(par)
# union find(parには0も入れているので、par[1]=1になる)
def find(x):
while par[x] != x:
tmp = par[x]
par[x] = par[par[x]]
x = par[x]
return x
def union(x, y):
x1 = find(x)
y1 = find(y)
if x1 != y1:
par[x1] = y1
# 各要素をunionする
for j in range(m):
a, b = map(int, input().split())
union(a - 1, b - 1)
s = [0 for i in range(n + 5)]
# 1~nの親を探してsに入れていき、一番多い親を答えにする
for k in range(n):
s[find(k)] += 1
print(max(s))
| 1 | 3,938,320,398,252 | null | 84 | 84 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.