code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
import numpy as np
n,m=map(int, input().split())
AC=[0]*(n+1)
WA=[0]*(n+1)
for _ in range(m):
p,s=input().split()
if s=='AC':
AC[int(p)]=1
elif s=='WA' and AC[int(p)]==0:
WA[int(p)] +=1
ACn=np.array(AC)
WAp=np.array(WA)
print(sum(AC),sum(ACn*WAp))
|
n,m=map(int,input().split())
cnt = [0]*n
total = [0]*n
for i in range(m):
P=list(input().split())
p = int(P[0]) - 1
if P[1] == 'WA' and cnt[p] == 0:
total[p] += 1
if P[1] == 'AC' and cnt[p] == 0:
cnt[p] = True
ans = 0
for i in range(n):
if cnt[i] == True:
ans += total[i]
print(sum(cnt),ans)
| 1 | 93,067,410,666,528 | null | 240 | 240 |
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i, a in enumerate(L[2:]):
k = i + 1
for j, b in enumerate(L[:i + 2]):
while j < k and a - b < L[k]:
k -= 1
ans += i - max(k, j) + 1
print(ans)
|
def L():
return list(map(int, input().split()))
import math
[n,k]=L()
print(math.floor(math.log(n,k))+1)
| 0 | null | 117,508,049,988,748 | 294 | 212 |
def resolve():
N, M, X = list(map(int, input().split()))
C = []
A = []
for i in range(N):
ins = list(map(int, input().split()))
C.append(ins[0])
A.append(ins[1:])
minprice = float("inf")
for bits in range(1<<N):
comps = [0 for _ in range(M)]
price = 0
for odr in range(N):
if (bits & (1<<odr)):
price += C[odr]
for i in range(M):
comps[i] += A[odr][i]
for i in range(M):
if comps[i] < X:
break
else:
minprice = min(minprice, price)
print(minprice if minprice < float("inf") else -1)
if '__main__' == __name__:
resolve()
|
n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
xs = list(map(int, input().split()))
c[i] = xs[0]
a[i] = xs[1:]
ans = 10 ** 9
for i in range(2 ** n):
csum = 0
asum = [0] * m
for j in range(n):
if (i >> j) & 1:
csum += c[j]
for k in range(m):
asum[k] += a[j][k]
if len(list(filter(lambda v: v >= x, asum))) == m:
ans = min(ans, csum)
print(-1 if ans == 10 ** 9 else ans)
| 1 | 22,218,365,122,628 | null | 149 | 149 |
n, k = map(int,input().split())
r, s, p = map(int,input().split())
r_s_p_points = [r, s, p]
t = input()
my_hands = []
points = 0
r_s_p = [0, 1, 2]
t_num_list = []
for i in range(n):
if t[i] == "r":
t_num_list.append(0)
elif t[i] == "s":
t_num_list.append(1)
else:
t_num_list.append(2)
for i in range(k):
if t_num_list[i] == 0:
my_hands.append(2)
points += p
elif t_num_list[i] == 1:
my_hands.append(0)
points += r
else:
my_hands.append(1)
points += s
for i in range(k, n):
if r_s_p[(t_num_list[i] - 1) % 3] != my_hands[i - k]:
my_hands.append(r_s_p[(t_num_list[i] - 1) % 3])
points += r_s_p_points[r_s_p[(t_num_list[i] - 1) % 3]]
else:
if i + k <= n-1:
for j in range(3):
if j == r_s_p[(t_num_list[i] - 1) % 3]:
continue
elif j == r_s_p[(t_num_list[i + k] - 1) % 3]:
continue
else:
my_hands.append(j)
break
else:
my_hands.append(0)
print(points)
|
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
divided_T = [[] for _ in range(K)]
for i in range(N):
divided_T[i%K].append(T[i])
ans = 0
for target in divided_T:
dp = [[0]*3 for _ in range(len(target))]
dp[0][0] = R if target[0] == 's' else 0
dp[0][1] = P if target[0] == 'r' else 0
dp[0][2] = S if target[0] == 'p' else 0
for i in range(1,len(target)):
dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + (R if target[i] == 's' else 0)
dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + (P if target[i] == 'r' else 0)
dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + (S if target[i] == 'p' else 0)
ans += max(dp[-1])
print(ans)
| 1 | 106,650,165,819,072 | null | 251 | 251 |
n = int(input())
lst = list(map(int,input().split()))
lst = sorted(lst)
ans = 1
for i in range (n):
ans = ans*lst[i]
if (ans > 10**18):
ans = -1
break
print(ans)
|
S=input()
T=input()
N = len(S)
count = 0
for n in range(N):
if S[n]!=T[n]:
count+=1
print(count)
| 0 | null | 13,399,147,028,210 | 134 | 116 |
import math
a,b, A = map(float, input().split())
h = b*math.sin(math.radians(A))
S = a*h*0.5
L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*math.cos(math.radians(A)))
print(S)
print(L)
print(h)
|
def main():
n = int(input())
# a, b, c, d = map(int, input().split())
a = list(map(int, input().split()))
# s = input()
mx = 0
result = 0
for num in a:
mx = max(mx, num)
if mx > num:
result += mx - num
print(result)
if __name__ == '__main__':
main()
| 0 | null | 2,331,293,294,142 | 30 | 88 |
N = int(input())
for i in range(10):
ans = (i+1)*1000-N
if ans >= 0:
print(ans)
exit()
|
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 998244353
# 処理内容
def main():
N, S = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
for j in range(S+1):
dp[i+1][j] += dp[i][j] * 2
dp[i+1][j] %= MOD
if j + A[i] > S:
continue
dp[i+1][j+A[i]] += dp[i][j]
dp[i+1][j+A[i]] %= MOD
print(dp[N][S])
if __name__ == '__main__':
main()
| 0 | null | 13,191,212,271,008 | 108 | 138 |
h,w,k = map(int,input().split())
s = [list(input()) for i in range(h)]
a = [[0]*w for i in range(h)]
num = 1
for i in range(h):
b = s[i]
if "#" in b:
t = b.count("#")
for j in range(w):
c = b[j]
# print(c)
if c=="#" and t!=1:
a[i][j] = num
num += 1
t -= 1
elif c=="#" and t==1:
a[i][j] = num
t = -1
else:
a[i][j] = num
if t==-1:
num += 1
else:
if i==0:
continue
else:
for j in range(w):
a[i][j] = a[i-1][j]
index = 0
for i in range(h):
if "#" not in s[i]:
index += 1
else:
break
for j in range(index):
for k in range(w):
a[j][k] = a[index][k]
for j in a:
print(*j)
|
h,w,k = map(int, input().split())
ls = [list(input()) for i in range(h)]
ansls = [[0]*w for _ in range(h)]
absent = []
idx = 1
for i in range(h):
if ls[i] == ['.']*w:
absent.append(i)
else:
count=0
for j in range(w):
if ls[i][j] == "#":
if count>0:
idx+=1
count+=1
ansls[i][j] = idx
idx+=1
for i in absent:
idx = i
while idx in absent:
idx+=1
if idx>=h:
idx = i
while idx in absent:
idx-=1
ansls[i] = ansls[idx]
for l in ansls:
print(*l)
| 1 | 143,303,557,333,888 | null | 277 | 277 |
n = input()
print('Yes' if '7' in n else 'No')
|
import math
r = float(input())
s = '{:.6f}'.format(r * r * math.pi)
l = '{:.6f}'.format(2 * r * math.pi)
print(s,l)
| 0 | null | 17,586,172,041,952 | 172 | 46 |
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0]*s for _ in range(n)]
tmp=1
for i in range(n):
if a[i]<=s:
dp[i][a[i]-1]=tmp
for j in range(s):
if i>0:
dp[i][j]+=dp[i-1][j]*2
dp[i][j]%=mod
if j+a[i]<s:
dp[i][j+a[i]]+=dp[i-1][j]
dp[i][j+a[i]]%=mod
tmp*=2
tmp%=mod
print(dp[n-1][s-1])
|
a, b, n = map(int, input().split())
def calc(x):
return int(a * x / b) - a * int(x / b)
if n < b:
print(calc(n))
else:
print(calc(b-1))
| 0 | null | 22,701,838,189,292 | 138 | 161 |
import sys
for v in iter(sys.stdin.readline,""):
a,op,b = v.split()
a = int(a)
b = int(b)
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
elif op == '?':
break
|
def solve():
s = input()
if s == 'SUN':
print(7)
elif s == 'MON':
print(6)
elif s == 'TUE':
print(5)
elif s == 'WED':
print(4)
elif s == 'THU':
print(3)
elif s == 'FRI':
print(2)
elif s == 'SAT':
print(1)
if __name__ == '__main__':
solve()
| 0 | null | 66,519,621,934,940 | 47 | 270 |
n = int(input())
C = list(input())
if "R" not in C:
print(0)
exit()
W = C.count("W")
R = C.count("R")
w = 0
r = R
ans = float('inf')
for c in C:
if c == "W":
w += 1
else:
r -= 1
ans = min(ans, max(w, r))
print(ans)
|
n=int(input())
c=list(input())
r=[]
w=[]
for i in range(n):
if c[i]=='R':
r.append(i)
else:
w.append(i)
r.reverse()
ans=0
for i in range(min(len(r),len(w))):
if r[i]>w[i]:
ans+=1
print(ans)
| 1 | 6,335,560,593,312 | null | 98 | 98 |
S = input()
ans = 0
l, r = 0, 0
i = 0
while i < len(S):
while i < len(S) and S[i] == "<":
l += 1
i += 1
while i < len(S) and S[i] == ">":
r += 1
i += 1
ans += l * (l + 1) // 2
ans += r * (r + 1) // 2
ans -= min(l, r)
l, r = 0, 0
print(ans)
|
while True:
h, w = map(int, input().split())
if w+h == 0:
break
line = "#"*w
for y in range(h):
print(line)
print()
| 0 | null | 78,750,231,275,160 | 285 | 49 |
#!/usr/bin/env python3
def main():
N = int(input())
print(-(-N // 2))
main()
|
import math
a = int(input())
print(math.ceil(a/2))
| 1 | 59,099,249,431,840 | null | 206 | 206 |
import itertools
n,k=map(int,input().split())
d=[]
a=[]
for i in range(k):
p=int(input())
d.append(p)
q=list(map(int,input().split()))
a.append(q)
c=list(itertools.chain.from_iterable(a))
c.sort()
c_set=set(c)
c=list(c_set)
print(n-len(c))
|
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
cnt = [0]*N
for _ in range(K):
d = int(input())
for a in list(map(int, input().split())):
a -= 1
cnt[a] += 1
ans = 0
for c in cnt:
ans += c == 0
print(ans)
| 1 | 24,643,180,530,852 | null | 154 | 154 |
a, b, c, k = map(int,input().split())
ans = 0
if a > k:
print(k)
elif a+b > k:
print(a)
else:
print(a-(k-a-b))
|
while True:
a,b,c = input().split()
if b=='?':
break
elif b =='+':
d = int(a) + int(c)
elif b=='-':
d = int(a) - int(c)
elif b=='*':
d = int(a)*int(c)
else :
d = int(a)/int(c)
print(int(d))
| 0 | null | 11,213,970,066,492 | 148 | 47 |
MOD = 10**9 + 7
N, K = map(int, input().split())
def getFacts(n, MOD):
facts = [1] * (n+1)
for x in range(2, n+1):
facts[x] = (facts[x-1] * x) % MOD
return facts
facts = getFacts(2*N, MOD)
def getInvFacts(n, MOD):
invFacts = [0] * (n+1)
invFacts[n] = pow(facts[n], MOD-2, MOD)
for x in reversed(range(n)):
invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
return invFacts
invFacts = getInvFacts(2*N, MOD)
def getComb(n, k, MOD):
if n < k:
return 0
return facts[n] * invFacts[k] * invFacts[n-k] % MOD
ans = 0
for x in range(min(K, N-1)+1):
ans += getComb(N, x, MOD) * getComb(N-1, x, MOD)
ans %= MOD
print(ans)
|
# coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 10 ** 9 + 7
# K回の移動が終わった後、人がいる部屋の数はNからN-K
def cmb(n, k):
if k < 0 or k > n: return 0
return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD
def cumprod(arr, MOD):
L = len(arr); Lsq = int(L**.5+1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n-1, -1]; arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64); x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = 10 ** 6 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
N, K = lr()
answer = 0
for x in range(N, max(0, N-K-1), -1):
# x個の家には1人以上いるのでこの人たちは除く
can_move = N - x
# x-1の壁をcan_move+1の場所に入れる
answer += cmb(N, x) * cmb(x - 1 + can_move, can_move)
answer %= MOD
print(answer % MOD)
# 31
| 1 | 67,355,906,693,520 | null | 215 | 215 |
from sys import stdin
readline = stdin.readline
R, C, K = map(int, readline().split())
goods = [[0] * C for _ in range(R)]
for _ in range(K):
r, c, v = map(int, readline().split())
goods[r - 1][c - 1] = v
n = [0] * (C + 1)
for i in range(R):
c = [0] * 4
c[0] = n[0]
for j in range(C):
if goods[i][j] != 0:
for k in range(2, -1, -1):
if c[k] + goods[i][j] > c[k + 1]:
c[k + 1] = c[k] + goods[i][j]
for k in range(4):
if c[k] > n[j]:
n[j] = c[k]
if n[j + 1] > c[0]:
c[0] = n[j + 1]
print(max(c))
|
import sys
input = sys.stdin.readline
R, L, K = map(int, input().split())
V = [0]*(R*L)
for _ in range(K):
r, c, v = map(int, input().split())
V[(c-1)*R+(r-1)] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
for j in range(R):
A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
v = V[i*R+j]
if v != 0:
D[j], C[j], B[j] = max(C[j]+v,D[j]), max(B[j]+v,C[j]), max(A[j]+v,B[j])
print(max(A[-2],B[-2],C[-2],D[-2]))
| 1 | 5,554,872,128,310 | null | 94 | 94 |
from collections import Counter
from operator import itemgetter
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
class Mint:
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def __init__(self, val, mod=10**9+7):
val = Mint.get_value(val)
self.__mod = mod
self.__val = val % self.__mod
@property
def value(self): return self.__val
@property
def inverse(self): return pow(self.__val, self.__mod - 2, self.__mod)
def __eq__(self, other): return self.__val == other.val
def __ne__(self, other): return self.__val != other.val
def __neg__(self): return Mint(self.__val, self.__mod)
def __iadd__(self, other):
other = Mint.get_value(other)
self.__val = (self.__val + other) % self.__mod
return self
def __add__(self, other):
new = Mint(self.__value, self.__mod)
new += other
return new
def __radd__(self, other): return self + other
def __isub__(self, other):
other = Mint.get_value(other)
self.__val = (self.__val - other + self.__mod) % self.__mod
return self
def __sub__(self, other):
new = Mint(self.__value, self.__mod)
new -= other
return new
def __rsub__(self, other):
new = Mint(Mint.get_value(other), self.__mod)
new -= self
return new
def __imul__(self, other):
other = Mint.get_value(other)
self.__val = self.__val * other % self.__mod
return self
def __mul__(self, other):
new = Mint(self.__value, self.__mod)
new *= other
return new
def __rmul__(self, other): return self * other
def __ifloordiv__(self, other):
other = Mint(other, self.__mod)
self *= other.inverse
return self
def __floordiv__(self, other):
new = Mint(self.__value, self.__mod)
new //= other
return new
def __rfloordiv__(self, other):
new = Mint(Mint.get_value(other), self.__mod)
new //= self
return new
C = Counter(D)
if D[0] != 0 or C[0] != 1:
print(0)
exit()
ans = Mint(1, MOD)
expected = 0
for i,c in sorted(C.items(), key=itemgetter(0)):
if i == 0: continue
expected += 1
if i != expected:
print(0)
exit()
ans *= pow(C[i-1], c, MOD)
print(ans.value)
|
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
li = [-1]*N #グー、チョキ、パー
se = set(["r","s","p"])
dic = {"r":"p","s":"r","p":"s"}
score = {"r":0,"s":0,"p":0}
#iはあまりでi+k*a
num = N//K
for i in range(K):
for a in range(num+1):
nex = i + K*a
if nex>N-1:
break
rival = T[nex]
kati = dic[rival]
if nex<K:
li[nex]=kati
score[kati]+=1
elif not kati==li[nex-K]:
li[nex]=kati
score[kati]+=1
#elif kati==li[nex-k]:
# if nex+k>N-1:
# else:
print(score["r"]*R+score["s"]*S+score["p"]*P)
| 0 | null | 130,629,110,968,530 | 284 | 251 |
def to_fizzbuzz(num: int) -> str:
if num % 15 == 0:
return 'FizzBuzz'
if num % 3 == 0:
return 'Fizz'
if num % 5 == 0:
return 'Buzz'
return str(num)
N = int(input())
answer = 0
for i in range(1, N + 1):
fb_str = to_fizzbuzz(i)
if fb_str.isdecimal():
answer += int(fb_str)
print(answer)
|
n=int(input())
a=[0,1,3,3,7,7,7,14,22,22,22,33,33,46,60]
b=[0,1,2,2,3,3,3,4,5,5,5,6,6,7,8]
print(60*((n//15)**2)+b[n%15]*(15*(n//15))+a[n%15])
| 1 | 34,897,117,015,898 | null | 173 | 173 |
n = int(input())
ls = list(map(int, input().split()))
count = 0
flag = 1
while flag:
flag = 0
for i in range(len(ls)-1, 0, -1):
if ls[i] < ls[i-1]:
ls[i], ls[i-1] = ls[i-1], ls[i]
count += 1
flag = 1
print(' '.join(map(str, ls)))
print(count)
|
def bubbleSort(A, N):
global count
flag = True
while flag:
flag = False
for j in range(N-1, 0, -1):
if A[j] < A[j-1]:
A[j], A[j-1] = A[j-1], A[j]
flag = True
count += 1
N = int(input())
A = [int(i) for i in input().split()]
count = 0
bubbleSort(A, N)
print(*A)
print(count)
| 1 | 16,193,544,112 | null | 14 | 14 |
n=int(input())
a=list(map(int,input().split()))
a.sort()
# 小さい側から処理する。a[i]について、10**6 以下のすべての倍数をset()として持つ。
# ただし、set内に存在しない==初出の約数のみ倍数計算をしてカウントする。
# 例えば、2,6,... となった場合、(6の倍数セットは2の倍数セットの下位集合となるため計算不要)
s=set()
cnt=0
for i,aa in enumerate(a):
if aa not in s:
# 同値が複数ある場合、カウントしない。sortしているため、同値は並ぶ
if i+1 == len(a) or aa != a[i+1]:
cnt+=1
for i in range(1,10**6+1):
ma=aa*i
if ma > 10**6:
break
s.add(ma)
print(cnt)
|
#!/usr/bin/env python3
import sys
from math import gcd
from collections import defaultdict
sys.setrecursionlimit(10**8)
MOD = 1000000007 # type: int
def solve(N: int, A: "List[int]", B: "List[int]"):
def quadrant(a, b):
if a > 0 and b >= 0:
return 0
elif a <= 0 and b > 0:
return 1
elif a < 0 and b <= 0:
return 2
elif a >= 0 and b < 0:
return 3
else:
return None
def norm(a, b):
g = gcd(a, b)
a //= g
b //= g
while quadrant(a, b) != 0:
a, b = -b, a
return a, b
d = defaultdict(lambda: [0, 0, 0, 0])
kodoku = 0
for i, (a, b) in enumerate(zip(A, B)):
if (a, b) == (0, 0):
kodoku += 1
else:
d[norm(a, b)][quadrant(a, b)] += 1
ans = 1
for v in d.values():
buf = pow(2, v[0]+v[2], MOD)
buf += pow(2, v[1]+v[3], MOD)
buf = (buf-1) % MOD
ans *= buf
ans %= MOD
print((ans-1+kodoku) % MOD)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
A = [int()] * (N) # type: "List[int]"
B = [int()] * (N) # type: "List[int]"
for i in range(N):
A[i] = int(next(tokens))
B[i] = int(next(tokens))
solve(N, A, B)
if __name__ == '__main__':
main()
| 0 | null | 17,657,893,361,948 | 129 | 146 |
MAX=200000
def get_prime(x):
is_prime = [True] * 200000
for i in range(2,MAX):
if is_prime[i] and i >= x:
return i
elif is_prime[i]:
for j in range(2 * i, MAX, i):
is_prime[j] = False
print(get_prime(int(input())))
|
import itertools
import collections
class PrimeFactorize:
def __init__(self, n):
self.prime_factor_table = self.create_prime_factor_table(n)
# O(NloglogN)
def create_prime_factor_table(self, n):
self.table = [0] * (n + 1)
for i in range(2, n + 1):
if self.table[i] == 0:
for j in range(i + i, n + 1, i):
self.table[j] = i
return self.table
def prime_factor(self, n):
prime_count = collections.Counter()
while self.prime_factor_table[n] != 0:
prime_count[self.prime_factor_table[n]] += 1
n //= self.prime_factor_table[n]
prime_count[n] += 1
return prime_count
N = int(input())
pf = PrimeFactorize(10**5+5)
for i in range(N,10**5+5):
if pf.prime_factor_table[i]==0:
print(i)
break
| 1 | 105,207,403,965,170 | null | 250 | 250 |
N,K = map(int, input().split())
if N % K == 0:
print(0)
elif N > K:
hako1 = N%K
hako2 = abs(hako1-K)
if hako1 > hako2:
print(hako2)
else:
print(hako1)
else:
if N >= abs(N-K):
print(abs(N-K))
else:
print(N)
|
from sys import stdin
input = stdin.readline
def main():
N, K = list(map(int, input().split()))
surp = N % K
print(min(surp, abs(surp-K)))
if(__name__ == '__main__'):
main()
| 1 | 39,633,421,369,234 | null | 180 | 180 |
from collections import deque
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
ls = deque([0])
ans = [-1] * N
ans[0] = 0
while len(ls) > 0:
v = ls.popleft()
for next_v in G[v]:
if ans[next_v] != -1:
continue
ans[next_v] = v
ls.append(next_v)
if -1 in ans:
print("No")
else:
print("Yes")
for i in range(1, N):
print(ans[i]+1)
|
S = input()
Q= int(input())
r = False
h = []
t = []
for i in range(Q):
Query = input().split()
if int(Query[0]) == 1:
r = not r
else:
if int(Query[1]) == 1 and not r or int(Query[1]) == 2 and r:
h.append(Query[2])
else:
t.append(Query[2])
if not r:
print(''.join(reversed(h))+S+''.join(t))
else:
print(''.join(reversed(t))+S[::-1]+''.join(h))
| 0 | null | 38,892,094,827,952 | 145 | 204 |
import sys
def check(p):
s = w[0]
track = 1
for i in range(1, n):
if s + w[i] <= p:
s += w[i]
else:
track += 1
if track > k: return False
s = w[i]
return True
n, k = map(int, sys.stdin.readline().strip().split())
w = []
for i in range(n):
w.append(int(sys.stdin.readline()))
L = max(w)
if check(L):
print(L)
else:
R = sum(w)
assert check(R)
while L + 1 < R:
M = (L + R) // 2
if check(M):
R = M
else:
L = M
print(R)
|
# coding:utf-8
n, k = map(int,raw_input().split())
ws = []
for _ in xrange(n):
ws.append(int(raw_input()))
def possible_put_p(p):
# P??\?????????????????????????????????
current = 1
weight = 0
for w in ws:
if weight + w <= p:
weight += w
else:
current += 1
if current > k:
return False
weight = w
if current <= k:
return True
else:
return False
low = max(ws)
high = sum(ws)
while(high - low > 0):
mid = (low + high) / 2
if(possible_put_p(mid)):
high = mid
else:
low = mid + 1
print high
| 1 | 88,397,526,678 | null | 24 | 24 |
#!/usr/bin/env python3
import numpy as np
# def input():
# return sys.stdin.readline().rstrip()
def main():
n, k = map(int, input().split())
warps = list(map(int, input().split()))
warps = [0] + warps
warps = np.array(warps, dtype=int)
dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)
dp[0, :] = warps
for h in range(1, len(dp)):
# dp[h] = dp[h - 1][dp[h - 1]]
dp[h] = np.take(dp[h - 1], dp[h - 1])
node = 1
# for i in reversed(range(k.bit_length())):
for i in range(k.bit_length(), -1, -1):
if k >> i & 1:
node = dp[i][node]
print(node)
main()
|
n,k = map(int,input().split())
A = [0]
A.extend(list(map(int,input().split())))
town = 1
once = [0]*(n+1)
for i in range(n):
if once[town]==0:
once[town] = 1
else:
break
town = A[town]
rt = A[town]
roop = 1
while rt != town:
rt = A[rt]
roop += 1
rt = 1
bf = 0
while rt != town:
rt = A[rt]
bf += 1
if bf<k:
K = (k-bf)%roop + bf
else:
K = k
town = 1
for _ in range(K):
town = A[town]
print(town)
| 1 | 22,528,559,724,836 | null | 150 | 150 |
k = int(input())
ans = k * "ACL"
print(ans)
|
s = ''
for i in range(int(input())):
s += 'ACL'
print(s)
| 1 | 2,173,485,750,810 | null | 69 | 69 |
A = input()
B = input()
print('Yes' if A == B[:-1] else 'No')
|
def solve():
X = [int(i) for i in input().split()]
for i in range(len(X)):
if X[i] == 0:
print(i+1)
break
if __name__ == "__main__":
solve()
| 0 | null | 17,350,943,840,298 | 147 | 126 |
s = input()
if s.count('A') == 0 or s.count('B') == 0:
print('No')
else:
print('Yes')
|
S=list(input())
countA=0
countB=0
for i in range(3):
if S[i]=="A":
countA+=1
else:
countB+=1
if countA!=0 and countB!=0:
print("Yes")
else:
print("No")
| 1 | 54,691,567,034,130 | null | 201 | 201 |
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
h, w, m = map(int,input().split())
h_lis = [0] * (h+1)
w_lis = [0] * (w+1)
bombs = set([tuple(map(int,input().split())) for i in range(m)])
for hh, ww in bombs:
h_lis[hh] += 1
w_lis[ww] += 1
max_h = max(h_lis)
max_w = max(w_lis)
h_max_index = [i for i, h in enumerate(h_lis) if h == max_h]
w_max_index = [i for i, w in enumerate(w_lis) if w == max_w]
for h_i in h_max_index:
for w_i in w_max_index:
if not (h_i, w_i) in bombs:
print(h_lis[h_i] + w_lis[w_i])
sys.exit()
else:
print(h_lis[h_i] + w_lis[w_i] - 1)
if __name__=='__main__':
main()
|
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]
k = int(input())
print(s[k-1])
| 0 | null | 27,403,096,616,900 | 89 | 195 |
import math
a = input()
N = int(a)
X = N//1.08 + 1
x = math.floor(X*1.08)
if x == N:
print(int(X))
else:
print(':(')
|
n=int(input())
for x in range(n+1):
if int(x*1.08)==n:
print(x)
exit()
print(":(")
| 1 | 125,923,500,624,910 | null | 265 | 265 |
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)
|
n = int(input())
a = map(int, input().split())
ans = 0
i = 1
for x in a:
if i % 2 == x % 2 == 1: ans += 1
i += 1
print(ans)
| 0 | null | 10,722,127,100,188 | 127 | 105 |
x, k, d = [int(i) for i in input().split()]
if x < 0:
x = -x
l = min(k, x // d)
k -= l
x -= l * d
if k % 2 == 0:
print(x)
else:
print(d - x)
|
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n, t = LI()
ab = [LI() for _ in range(n)]
ab.sort(key = itemgetter(0))
dp = [[0] * (t+3001) for _ in range(n+1)]
for i in range(1, n+1):
a, b = ab[i-1]
for j in range(t + 3001):
dp[i][j] = dp[i-1][j]
for j in range(t):
dp[i][j+a] = max(dp[i-1][j+a], dp[i-1][j] + b)
ans = 0
for i in range(t-1, t + 3001):
ans = max(ans, dp[n][i])
print(ans)
| 0 | null | 78,640,538,143,118 | 92 | 282 |
h1,m1,h2,m2,k =(int(x) for x in input().split())
hrtom= (h2-h1)
if (m2-m1 < 0) and (h2-h1 >=0) :
min = (h2-h1)*60 + (m2-m1) - k
print(min)
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
min = (h2-h1)*60 + (m2-m1) - k
print(min)
else:
print('0')
|
h1,m1,h2,m2,k=input().split()
h1 = int(h1)
m1 = int(m1)
h2 = int(h2)
m2 = int(m2)
k = int(k)
if h1 > h2:
h2 += 24
h = h2 - h1
hm = h * 60
print(hm - m1 + m2 - k)
| 1 | 17,923,982,091,676 | null | 139 | 139 |
N = int(input())
n = input().split()
line = '{0}'.format(n[-1])
for i in range(1,N):
line += ' {0}'.format(n[N-i-1])
print(line)
|
a=[]
n = int(input())
s = input().rstrip().split(" ")
for i in range(n):
a.append(int(s[i]))
a=a[::-1]
for i in range(n-1):
print(a[i],end=' ' )
print(a[n-1])
| 1 | 992,841,693,952 | null | 53 | 53 |
import math
S = list(map(int, input().split()))
a = (S[2]-S[0])*60+(S[3]-S[1])
b = a - S[4]
if(b>0):
print(b)
else:
print(0)
|
data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
divisor = list()
for i in range(a,b+1):
if c % i == 0:
divisor.append(i)
print(str(len(divisor)))
| 0 | null | 9,380,200,842,320 | 139 | 44 |
N, M = map(int, input().split())
assert 2*M+1 <= N
if M % 2 == 1:
step_m1 = M
step_m2 = M - 1
else:
step_m1 = M - 1
step_m2 = M
assert step_m1 + 1 + step_m2 + 1 <= N
ans = []
a = 0
for step in range(step_m1, -1, -2):
# print(step)
# print(a, a+step)
ans.append([a+1, a+step+1])
a += 1
a = step_m1 + 1
for step in range(step_m2, 0, -2):
# print(step)
# print(a, a+step)
ans.append([a+1, a+step+1])
a += 1
print('\n'.join(map(lambda L: ' '.join(map(str, L)), ans)))
|
n, m = map(int, input().split())
if n % 2 == 1:
a = [i for i in range(1, m+1)]
b = [i for i in reversed(range(m+1, 2*m+1))]
ab = [(x, y) for x, y in zip(a, b)]
else:
ab = []
x, y = (n-1)//2, n//2
if x % 2 != 0:
x, y = y, x
evenl = 1
evenr = x
while evenl < evenr:
ab.append((evenl, evenr))
evenl += 1
evenr -= 1
oddl = x+1
oddr = n-1
while oddl < oddr:
ab.append((oddl, oddr))
oddl += 1
oddr -= 1
ab = ab[:m]
for a, b in ab:
print(a, b)
| 1 | 28,616,487,433,732 | null | 162 | 162 |
n, k = map(int, input().split())
sunuke = []
for s in range(n):
sunuke.append(str(s+1))
for t in range(k):
d = int(input())
hito = input().split(" ")
for u in range(d):
for v in range(n):
if hito[u] == sunuke[v]:
sunuke[v] = 0
else:
pass
m = sunuke.count(0)
print(n-m)
|
K = int(input())
r = 7 % K
ans = -2
for i in range(K):
if r == 0:
ans = i
break
r = 10*r + 7
r = r % K
print(ans+1)
| 0 | null | 15,337,125,350,782 | 154 | 97 |
N=int(input())
d=list(map(int, input().split()))
ans=0
for i in range(N):
for j in range(N):
if i == j:
continue
elif i < j:
ans += d[i]*d[j]
print(ans)
|
n,k =map(int,input().split())
l = list(map(int,input().split()))
l = sorted(l)
print(sum(l[0:k]))
| 0 | null | 89,657,050,558,948 | 292 | 120 |
N = int(input())
D = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
cnt = cnt + 1 if D[i][0] == D[i][1] else 0
if cnt == 3:
print('Yes')
exit()
print('No')
|
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0 and n >= 4:
dp = [[0, 0] for i in range(n)]
dp[0][0] = a[0]
dp[1][1] = a[1]
dp[2][0] = a[0] + a[2]
for i in range(3, n):
dp[i][0] = dp[i - 2][0] + a[i]
dp[i][1] = max(dp[i - 3][0], dp[i - 2][1]) + a[i]
print(max(dp[n - 2][0], dp[n - 1][1]))
elif n % 2 != 0 and n >= 5:
dp = [[0, 0, 0] for i in range(n)]
dp[0][0] = a[0]
dp[1][1] = a[1]
dp[2][0] = a[0] + a[2]
dp[2][2] = a[2]
dp[3][1] = a[1] + a[3]
dp[3][2] = a[0] + a[3]
for i in range(3, n):
dp[i][0] = dp[i - 2][0] + a[i]
dp[i][1] = max(dp[i - 3][0], dp[i - 2][1]) + a[i]
dp[i][2] = max(dp[i - 4][0], dp[i - 3][1], dp[i - 2][2]) + a[i]
print(max(dp[n - 3][0], dp[n - 2][1], dp[n - 1][2]))
elif n == 2:
print(max(a[0], a[1]))
else:
print(max(a[0], a[1], a[2]))
| 0 | null | 19,843,367,773,150 | 72 | 177 |
import sys
from math import gcd
from collections import defaultdict
sys.setrecursionlimit(10**7)
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 LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
mod = 10**9+7
plus = defaultdict(int)
minus = defaultdict(int)
flag = defaultdict(int)
A_zero,B_zero = 0,0
zero_zero = 0
for i in range(N):
a,b = MI()
if a == b == 0:
zero_zero += 1
elif a == 0:
A_zero += 1
elif b == 0:
B_zero += 1
else:
if a < 0:
a,b = -a,-b
a,b = a//gcd(a,b),b//gcd(a,b)
if b > 0:
plus[(a,b)] += 1
else:
minus[(a,b)] += 1
flag[(a,b)] = 1
ans = 1
for a,b in plus.keys():
ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1
ans %= mod
flag[(b,-a)] = 0
for key in minus.keys():
if flag[key] == 1:
ans *= pow(2,minus[key],mod)
ans %= mod
ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1
ans %= mod
ans += zero_zero-1
ans %= mod
print(ans)
|
n, m = map(int, input().split())
s=[]
c=[]
num=[]
for i in range(m):
S, C = map(int, input().split())
s.append(S)
c.append(C)
for i in range(10**(n+1)):
String=str(i)
if len(String) == n and all([String[s[j]-1] == str(c[j]) for j in range(m)]):
print(str(i))
exit()
print('-1')
| 0 | null | 40,831,768,040,858 | 146 | 208 |
from collections import deque
class SegmentTree():
def __init__(self,n,ide_ele,merge_func,init_val):
self.n=n
self.ide_ele=ide_ele
self.merge_func=merge_func
self.val=[0 for i in range(1<<n)]
self.merge=[0 for i in range(1<<n)]
self.parent=[-1 for i in range(1<<n)]
deq=deque([1<<(n-1)])
res=[]
while deq:
v=deq.popleft()
res.append(v)
if not v&1:
gap=(v&-v)//2
self.parent[v-gap]=v
deq.append(v-gap)
self.parent[v+gap]=v
deq.append(v+gap)
for v in res[::-1]:
if v-1<len(init_val):
self.val[v-1]=init_val[v-1]
self.merge[v-1]=self.val[v-1]
if not v&1:
gap=(v&-v)//2
self.merge[v-1]=self.merge_func(self.merge[v-1],self.merge[v-gap-1],self.merge[v+gap-1])
def update(self,id,x):
self.val[id]=x
pos=id+1
while pos!=-1:
if pos&1:
self.merge[pos-1]=self.val[pos-1]
else:
gap=(pos&-pos)//2
self.merge[pos-1]=self.merge_func(self.val[pos-1],self.merge[pos+gap-1],self.merge[pos-gap-1])
pos=self.parent[pos]
def cnt(self,k):
lsb=(k)&(-k)
return (lsb<<1)-1
def lower_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(l)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
id=r
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[l-1])
return res
else:
id=l
else:
res=self.merge_func(res,self.val[id-1])
return res
def upper_kth_merge(self,nd,k):
res=self.ide_ele
id=nd
if k==-1:
return res
while True:
if not id%2:
gap=((id)&(-id))//2
l=id-gap
r=id+gap
cnt=self.cnt(r)
if cnt<k:
k-=cnt+1
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
id=l
elif cnt==k:
res=self.merge_func(res,self.val[id-1],self.merge[r-1])
return res
else:
id=r
else:
res=self.merge_func(res,self.val[id-1])
return res
def query(self,l,r):
id=1<<(self.n-1)
while True:
if id-1<l:
id+=((id)&(-id))//2
elif id-1>r:
id-=((id)&(-id))//2
else:
res=self.val[id-1]
if id%2:
return res
gap=((id)&(-id))//2
L,R=id-gap,id+gap
#print(l,r,id,L,R)
left=self.upper_kth_merge(L,id-1-l-1)
right=self.lower_kth_merge(R,r-id)
return self.merge_func(res,left,right)
ide_ele=0
def seg_func(*args):
res=ide_ele
for val in args:
res|=val
return res
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
return x & 0x0000007f
import sys
input=sys.stdin.readline
N=int(input())
S=input().rstrip()
init_val=[1<<(ord(S[i])-97) for i in range(N)]
test=SegmentTree(19,ide_ele,seg_func,init_val)
for _ in range(int(input())):
t,l,r=input().split()
t,l=int(t),int(l)
if t==1:
val=ord(r)-97
test.update(l-1,1<<val)
else:
r=int(r)
res=test.query(l-1,r-1)
print(popcount(res))
|
N = input()
if '7' in N:
print('Yes')
else:
print('No')
| 0 | null | 48,470,429,048,420 | 210 | 172 |
import random
s = input()
num = random.randint(0,len(s)-3)
print(s[num:num+3])
|
# coding: utf-8
"""this is python work script"""
def solver(trip_records):
"""solve this problem"""
answer = True
return answer
def main():
"""main function"""
name = input().rstrip()
print(name[:3])
if __name__ == '__main__':
main()
| 1 | 14,813,005,620,030 | null | 130 | 130 |
k = int(input())
ans = 0
s = 7
for i in range(1, 10**6 + 1):
s %= k
if s == 0:
print(i)
exit()
s = s*10 +7
print(-1)
|
k = int(input())
a = [None for i in range(10**7) ]
ans = -1
a[1] = 7%k
for i in range(2,k+1):
a[i] = (a[i-1]*10 + 7)%k
for i in range(1,k+1):
if a[i] == 0:
ans = i
break
print(ans)
| 1 | 6,166,938,304,580 | null | 97 | 97 |
# import math
# import statistics
# import itertools
# a=int(input())
# b,c=int(input()),int(input())
# c=[]
# for i in a:
# c.append(int(i))
A,B= map(int,input().split())
f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
# h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen
kyori=[]
for i in range(len(f)-1):
an=f[i+1]-f[i]
kyori.append(an)
an2=A-f[-1]+f[0]
ans=max(max(kyori),an2)
print(A-ans)
|
k, n = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0]+k)
l = 0
for i in range(n):
l = max(l, A[i+1]-A[i])
ans = k - l
print(ans)
| 1 | 43,442,410,725,516 | null | 186 | 186 |
#import time
def main():
N, K = map(int, input().split())
matrix = [list(map(int, input().split())) for i in range(2*K)]
sunuke = [0]*(N+1)
for i in range(K):
for j in matrix[2*i+1]:
sunuke[j] += 1
ans = sunuke.count(0) -1
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")
|
#! env/bin/local python3
# -*- coding: utf-8 -*-
print((float(input()) / 3) ** 3)
| 0 | null | 36,063,932,854,208 | 154 | 191 |
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 i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
S = input()
N = len(S)
cnt = 0
for i in range(N//2):
if S[i] != S[-1-i]:
cnt += 1
print(cnt)
|
# coding: utf-8
# Your code here!
n = int(input())
sum = 100000
for i in range(n):
sum += sum * 0.05
if sum % 1000 > 0:
sum -= sum % 1000
sum += 1000
print(int(sum))
| 0 | null | 60,218,438,722,042 | 261 | 6 |
N = int(input())
A = list(map(int, input().split()))
d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
d[i+1] = d[i] * 2 - A[i+1]
if d[-1] < 0:
print(-1)
exit()
d[-1] = A[-1]
for i in range(N, 0, -1):
d[i-1] = min(d[i]+A[i-1], d[i-1]+A[i-1])
print(sum(d))
|
A, B = map(int, input().split())
#最大公約数
def gcd(x, y):
while y:
x, y = y, x % y
return x
#最小公倍数
def lcm(x, y):
return x * y // gcd(x, y)
print(lcm(A, B))
| 0 | null | 65,765,791,257,312 | 141 | 256 |
h,w,m=map(int,input().split())
r=[0]*h
c=[0]*w
s=set()
for _ in range(m):
i,j=map(int,input().split())
i-=1
j-=1
r[i]+=1
c[j]+=1
s.add(i*w+j)
rmx=max(r)
cmx=max(c)
rc=[i for i in range(h) if r[i]==rmx]
cc=[j for j in range(w) if c[j]==cmx]
ans=rmx+cmx-1
for i in rc:
for j in cc:
if i*w+j not in s:
print(ans+1)
exit()
print(ans)
|
import numpy as np
from numpy.fft import rfft,irfft
def main():
n,m=map(int,input().split())
A=np.array(list(map(int,input().split())))
F=np.bincount(A)
fft_len=2*10**5+1
Ff=rfft(F,fft_len)
G=np.rint(irfft(Ff*Ff,fft_len)).astype(np.int64)
G_acc=G.cumsum()
remove_cnt=n**2-m
border=np.searchsorted(G_acc,n**2-m)
x=n**2-m-G_acc[border-1]
remove_sum=(G[:border]*np.arange(border)).sum()+border*x
ans=A.sum()*2*n-remove_sum
print(ans)
if __name__=='__main__':
main()
| 0 | null | 56,617,421,975,168 | 89 | 252 |
mod = 10 ** 9 + 7
k = int(input())
s = len(input())
n = s + k
fac = [1] * (n+1)
for i in range(1, n+1):
fac[i] = fac[i-1] * i % mod
ans = 0
for i in range(s, n+1):
ncr = fac[i-1] * pow(fac[i-s]*fac[s-1] % mod, mod-2, mod) % mod
res = pow(26, n-i, mod)* pow(25, i-s, mod) % mod
ans = (ans + res * ncr) % mod
print(ans)
|
#!python3
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
def _cmb(N, mod):
N1 = N + 1
fact = [1] * N1
inv = [1] * N1
for i in range(2, N1):
fact[i] = fact[i-1] * i % mod
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N-1, 1, -1):
inv[i] = inv[i+1]*(i+1) % mod
def cmb(a, b):
return fact[a] * inv[b] * inv[a-b] % mod
return cmb
def resolve():
K = int(input())
s = input()
ls = len(s) - 1
mod = 10**9+7
cmb = _cmb(ls+K, mod)
ans = 0
p25 = 1
p26 = pow(26, K, mod)
p26inv = pow(26, mod-2, mod)
for i in range(K+1):
ans += cmb(ls+i, ls) * p25 * p26
ans %= mod
p25 = p25 * 25 % mod
p26 = p26 * p26inv % mod
print(ans)
if __name__ == "__main__":
resolve()
| 1 | 12,831,350,917,252 | null | 124 | 124 |
import queue
N=int(input())
G=[[] for index1 in range(N+1)]
for index in range(1,N):
a,b=map(int,input().split())
G[a].append((b,index))
G[b].append((a,index))
#A[i]=辺iの色
A=[0]*N
q=queue.Queue()
#bfs
#(ノード、色、親)
q.put((1,0,0))
while not q.empty():
now=q.get()
i=1 #色
for next in G[now[0]]:
if next[0]==now[2]: #親
continue
else:
if i==now[1]:
i+=1
A[next[1]]=i #色を定める
q.put((next[0],i,now[0]))
i+=1
#print(now,(next[0],i,now[0]))
print(max(A))
for j in range(N-1):
print(A[j+1])
|
def BubbleSort(C,N):
for i in range(N):
for j in range(i+1, N)[::-1]:
if int(C[j][1]) < int(C[j - 1][1]):
C[j],C[j-1] = C[j-1],C[j]
def SelectionSort(C,N):
for i in range(N):
minj = i
for j in range(i,N):
if int(C[j][1]) < int(C[minj][1]):
minj = j
C[i],C[minj] = C[minj],C[i]
N = int(input())
C = (input()).split()
ORG = C[:]
BubbleSort(C,N)
print (" ".join(C))
print ("Stable")
C2=ORG
SelectionSort(C2,N)
print(" ".join(C2))
if C == C2:
print ("Stable")
else:
print ("Not stable")
| 0 | null | 68,244,869,960,260 | 272 | 16 |
n,m = map(int,input().split())
if n%2:
for i in range(1,m+1):
print(i,n-i+1)
else:
for i in range(1,m+1):
if n-2*i+1>n//2:
print(i,n-i+1)
else:
print(i,n-i)
|
n = str(input())
s = 0
for x in n:
s += int(x)
if s % 9 == 0:
print('Yes')
else :
print('No')
| 0 | null | 16,613,133,431,620 | 162 | 87 |
l = int(input())
ans = l * l * l / 27
print(ans)
|
def ifTriangle(a, b, c):
if (a**2) + (b**2) == c**2: print("YES")
else: print("NO")
n=int(input())
for i in range(n):
lines=list(map(int, input().split()))
lines.sort()
ifTriangle(lines[0], lines[1], lines[2])
| 0 | null | 23,679,572,786,892 | 191 | 4 |
H, W = map(int, input().split())
Maze = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]
DP = [[float('inf')] * W for _ in range(H)]
if Maze[0][0] == 1:
DP[0][0] = 1
else:
DP[0][0] = 0
for i in range(H):
for j in range(W):
if Maze[i][j] == 1:
if i + 1 < H:
DP[i+1][j] = DP[i][j]
if j + 1 < W:
DP[i][j+1] = min(DP[i][j+1], DP[i][j])
if Maze[i][j] == 0:
if i + 1 < H:
if Maze[i+1][j] != 1:
DP[i + 1][j] = DP[i][j]
else:
DP[i + 1][j] = DP[i][j] + 1
if j + 1 < W:
if Maze[i][j + 1] != 1:
DP[i][j + 1] = min(DP[i][j + 1], DP[i][j])
else:
DP[i][j + 1] = min(DP[i][j + 1], DP[i][j]+1)
print(DP[H-1][W-1])
|
h, w = map(int, input().split())
S = []
for _ in range(h):
s = str(input())
S.append(s)
DP = [[0 for _ in range(w)] for _ in range(h)]
if S[0][0] == '.':
DP[0][0] = 0
else:
DP[0][0] = 1
ren = False
if DP[0][0] == 1:
ren = True
for i in range(1,h):
if S[i][0] == '.':
DP[i][0] = DP[i-1][0]
ren = False
elif ren == False and S[i][0] == '#':
DP[i][0] = DP[i-1][0] + 1
ren = True
elif ren == True and S[i][0] == '#':
DP[i][0] = DP[i-1][0]
ren = True
ren = False
if DP[0][0] == 1:
ren = True
for j in range(1,w):
if S[0][j] == '.':
DP[0][j] = DP[0][j-1]
ren = False
elif ren == False and S[0][j] == '#':
DP[0][j] = DP[0][j-1] + 1
ren = True
elif ren == True and S[0][j] == '#':
DP[0][j] = DP[0][j-1]
ren = True
for i in range(1,h):
for j in range(1,w):
if S[i][j] == '.':
DP[i][j] = min(DP[i-1][j], DP[i][j-1])
elif S[i][j] == '#':
res_i = 0
res_j = 0
if S[i-1][j] == '.':
res_i = 1
if S[i][j-1] == '.':
res_j = 1
DP[i][j] = min(DP[i-1][j] + res_i, DP[i][j-1] + res_j)
print(DP[h-1][w-1])
| 1 | 49,510,788,398,302 | null | 194 | 194 |
H, N = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
dp = [0]*(H+1)
for i in range(1, H+1):
for j in range(N):
if j == 0:
if ls[j][0] <= i:
dp[i] = dp[i-ls[j][0]] + ls[j][1]
else:
dp[i] = ls[j][1]
else:
if ls[j][0] <= i:
dp[i] = min([dp[i], dp[i-ls[j][0]] + ls[j][1]])
else:
dp[i] = min([dp[i], ls[j][1]])
print(dp[H])
|
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import defaultdict
def resolve():
N = ir()
A = lr()
dp = defaultdict(lambda: -float('inf'))
dp[0, 0, 0] = 0
for i in range(N):
for j in range(max(i//2-1, 0), i//2+2):
dp[i+1, j+1, 1] = dp[i, j, 0]+A[i]
dp[i+1, j, 0] = max(dp[i, j, 0], dp[i, j, 1])
# print(dp)
print(max(dp[N, N//2, 1], dp[N, N//2, 0]))
resolve()
| 0 | null | 59,450,817,416,800 | 229 | 177 |
def main():
s = (input())
l = ['x' for i in range(len(s))]
print(''.join(l))
main()
|
#%%
from collections import Counter
n = input()
d = list(map(int, input().split()))
#%%
d_cnt =Counter(d)
d_cnt = dict(d_cnt)
d_cnt_keys = list(d_cnt.keys())
d_cnt_keys.sort()
if d[0] != 0 or d_cnt[0] != 1 or len(d_cnt_keys)!= d_cnt_keys[-1]+1:
print(0)
exit()
#%%
ans = 1
p = 998244353
for key in d_cnt_keys:
if key == 0:
continue
ans =ans*pow(d_cnt[key-1], d_cnt[key],p)%p
print(ans)
| 0 | null | 114,190,653,148,598 | 221 | 284 |
from sys import stdin, setrecursionlimit
def main():
input = stdin.buffer.readline
a, b = map(int, input().split())
if 1 <= a <= 9 and 1 <= b <= 9:
print(a * b)
else:
print(-1)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
|
a,b=map(int,input().split())
print(a*b if a<10 and b<10 else '-1')
| 1 | 158,714,708,142,130 | null | 286 | 286 |
N = int(input())
A = list(map(int,input().split()))
d = {}
ans = 0
for i in range(N):
sa = i-A[i]
if sa in d:
ans += d[sa]
wa = i+A[i]
if wa in d:
d[wa] += 1
else:
d[wa] = 1
print(ans)
|
# Author: cr4zjh0bp
# Created: Mon Mar 23 15:10:04 UTC 2020
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
from decimal import *
a, b, c = na()
d, e, f = Decimal(a), Decimal(b), Decimal(c)
if d.sqrt() + e.sqrt() < f.sqrt():
print("Yes")
else:
print("No")
| 0 | null | 39,069,036,603,168 | 157 | 197 |
import math
X, N = map(int, input().split())
if N == 0:
print(X)
else:
p = list(map(int, input().split()))
q = [int(i)-10 for i in range(121)]
#print(q)
for i in p:
q.remove(i)
ans = 0
r0 = 100000
for j in q:
r = abs(j-X)
if r0 > r:
r0 = r
ans = j
print(ans)
|
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
integer = [i for i in range(102)]
for i in range(N):
integer.remove(p[i])
l = len(integer)
ans = -200
for i in range(l):
if abs(ans) > abs(integer[i]-X):
ans = integer[i] - X
print(ans + X)
| 1 | 14,076,306,363,192 | null | 128 | 128 |
import math
def canMakeTriangle(a, b, c):
return abs(b - c) < a
N = int(input())
L = list(map(int, input().split()))
L.sort()
res = 0
for i in range(1, N):
for j in range(i + 1, N):
a = 0
b = i
c = 0
while b - a >= 1:
c = (a + b) / 2
if canMakeTriangle(L[math.floor(c)], L[i], L[j]):
b = c
else:
a = c
c = math.floor(c)
if canMakeTriangle(L[c], L[i], L[j]):
res += i - c
else:
res += i - c - 1
print(res)
|
K=int(input())
S=input()
if K>=len(S):
print(S)
else:
for i in range(K):
print(S[i],end='')
print("...")
| 0 | null | 95,864,148,610,840 | 294 | 143 |
n=int(input())
d=list(map(int,input().split()))
if d[0] != 0:
print(0)
exit()
d.sort()
if d[1] == 0:
print(0)
exit()
cnt = 1
pre = 1
ans =1
i = 1
mod = 998244353
while i < n:
if d[i]-1 != d[i-1]:
ans = 0
while i!=n-1 and d[i+1] == d[i]:
i+=1
cnt+=1
ans *= pow(pre,cnt,mod)
ans %= mod
pre =cnt
cnt = 1
i+=1
print(ans)
|
import sys
import collections
input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]
tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=998244353
#+++++
def main():
n = int(input())
#b , c = tin()
#s = input()
al = lin()
if al[0] != 0:
return 0
if al.count(0) != 1:
return 0
alc = collections.Counter(al)
mm = max(alc.keys())
b = alc.keys()
b=list(b)
b.sort()
if list(range(mm+1)) != b:
#pa('rrrr')
return 0
v = 1
p=1
for k in range(1, mm+1):
num = alc[k]
add = pow(p, num, mod)
v *= add
v %= mod
p = num
return v
#+++++
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 | 154,568,845,557,708 | null | 284 | 284 |
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = []
a,b,c = 0,0,0
for i in range(n):
if i>=k:
if t[i]==ans[i-k]:
ans.append('X')
continue
if t[i] =='r':
ans.append('r')
c += 1
elif t[i]=='s':
ans.append('s')
a += 1
else:
ans.append('p')
b += 1
print(a*r+b*s+c*p)
|
n, k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans = 0
for i in range(len(t)):
tmp = t[i]
if i >= k:
if tmp == t[i-k]:
t[i] = "c"
continue
if tmp == "r":
ans += p
elif tmp == "s":
ans += r
elif tmp == "p":
ans += s
print(ans)
| 1 | 107,011,842,067,328 | null | 251 | 251 |
import math
H = int(input())
W = int(input())
N = int(input())
print(math.ceil(N/max(H,W)))
|
H = int(input())
W = int(input())
N = int(input())
answer = 0
if H >= W:
answer = N // H
if N % H != 0:
answer += 1
else:
answer = N // W
if N % W != 0:
answer += 1
print(answer)
| 1 | 88,893,491,753,220 | null | 236 | 236 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
N, T = LI()
AB = []
for i in range(N):
_a, _b = LI()
AB.append((_a, _b))
AB = sorted(AB, key=lambda x: (x[0], x[1]))
a = [elem[0] for elem in AB]
b = [elem[1] for elem in AB]
dp = [[0 for _ in range(T + 3001)] for _ in range(N+1)]
for i in range(N):
for t in range(T):
dp[i+1][t+a[i]] = max(dp[i+1][t+a[i]], dp[i][t] + b[i])
dp[i+1][t] = max(dp[i+1][t], dp[i][t])
ans = 0
for i in range(N+1):
for j in range(T + 3001):
ans = max(dp[i][j], ans)
print(ans)
main()
|
def solve():
import numpy as np
from sys import stdin
f_i = stdin
N, T = map(int, f_i.readline().split())
AB = [tuple(map(int, f_i.readline().split())) for i in range(N)]
AB.sort()
max_Ai = AB[-1][0]
dp = [[0] * T for i in range(N + 1)]
dp = np.zeros(max_Ai + T, dtype=int)
for A_i, B_i in AB:
dp[A_i:A_i+T] = np.maximum(dp[A_i:A_i+T], dp[:T] + B_i)
print(max(dp))
solve()
| 1 | 151,943,952,821,210 | null | 282 | 282 |
n,k=map(int,input().split())
s=n//k
m=min((n-s*k),((s+1)*k-n))
print(m)
|
N, K = map(int, input().split(' '))
print(min(N % K, abs(N % K - K)))
| 1 | 39,239,445,761,950 | null | 180 | 180 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
print('Yes' if n==m else 'No')
|
x=int(input())
print(int(x*x*x))
| 0 | null | 41,671,520,549,842 | 231 | 35 |
import fractions
from sys import stdin
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
sa = set(a)
lcm = 1
for ai in sa:
lcm = (ai * lcm) // fractions.gcd(ai, lcm)
ans = 0
for ai in a:
ans += lcm // ai
ans %= 10 ** 9 + 7
print(ans)
if __name__ == "__main__":
main()
|
import math
import sys
def lcm(a, b):
return a * b // math.gcd(a, b)
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LCM = 1
ans = 0
MOD = 1000000007
for x in A:
LCM = lcm(LCM, x)
for x in A:
ans += LCM // x
print(ans%MOD)
| 1 | 87,899,331,810,820 | null | 235 | 235 |
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
# Original source code :
"""
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
#define all($) begin($), end($)
#define rall($) rbegin($), rend($)
class UnionFind {
public:
UnionFind(int n) : n_(n) { init(); }
int root(int x) {
assert(0 <= x && x < n_);
if (par_[x] == -1)
return x;
else
return par_[x] = root(par_[x]);
}
bool same(int x, int y) {
assert(0 <= x && x < n_ && 0 <= y && y < n_);
return root(x) == root(y);
}
void unite(int x, int y) {
assert(0 <= x && x < n_ && 0 <= y && y < n_);
x = root(x);
y = root(y);
if (x == y) return;
if (rank_[x] < rank_[y]) std::swap(x, y);
if (rank_[x] == rank_[y]) ++rank_[x];
par_[y] = x;
return;
}
private:
const int n_;
std::vector<int> par_;
std::vector<int> rank_;
void init() {
par_.assign(n_, -1);
rank_.assign(n_, 0);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
UnionFind uf(n);
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
--a;
--b;
uf.unite(a, b);
}
set<int> st;
for (int i = 0; i < n; ++i) {
st.emplace(uf.root(i));
}
cout << (int)st.size() - 1 << endl;
return 0;
}
"""
import base64
import subprocess
import zlib
exe_bin = "c%0>1eRxw<n!oud4YVXd3l;^5ZeR;YY@lERGB#}kH=05hiZTjb(j=vkG^xoA6xNT<wngrQKp%HTSyxAPbf0Br$7h&b_YvKFlv2K&QKx=9E<276vomTUepFE8OS12K?m5Z5w~6!d%zt}%()Yf<`+l7FJ?}a9-g6HRdVI_DIvvLj1NSWsxsz2g-$3zwH|9kEtLMhU-)p()+&JKk3OOx3r&Ci?-jA$Tua|i(oyMuDPC?7K(uZl9nsS^iuZL~5O{eH|n~I*Jem9h<_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R=G!(Wn8M?6O6A4jN@PPU!Fc!2}!fq)R|352>uK_u}z3Nxo{gPns<e^)pFC&VCBB<Fy801k*^x4A#{z{hvIWwZNvsr~ls&}n%5c%$6IrrpnO)5vSrS)3Yu_I}T({SWBl`smqQF2?lPIsl_J6lbsd+Sm0JoV>=x^x1j=qYaeeI+;$P&mMno=hS=H^NuLppjm&==I?G!UZY}SZ2f^zwvfWi>NRu|C$D)io~=_b+RGK%Z{Wtpzm1b~%JkWK2BT~pPMbd#e?Qf4q&!>qV6;`Ce^n9vU7T_+e_<VzQRQArjvL$ml187cqcA$Ek+*8-_cZ!!y@gS2zDyeWgw}tBn!cgj1j(uQu;THQMxVV`F{)ig(#HQIPCb6vduX0&<ZT-MXBz!d|F5K!|CcoSY~6^_22K5I^ZBwypRF%3s%@`!{Jg`-`*Yd)ZsGr_$h<b++Wy1+{}zQlTW_eHUc9|p{WDx)Y~fM(e?Zi~V*XI-v3BjDF=^M)`57|LwoR7ue@UaCe;=hpyX>cpM^6{dnLc~Zt)}|g{%g?am+NHz+67;xKU;$r`#w_aKkM*Re+O;wH0nb;e~eeOU3rYqiT{XZomX2wlS=4+pDyfKH40k&{{yGp2ZR"
open("./kyomu", 'wb').write(zlib.decompress(base64.b85decode(exe_bin)))
subprocess.run(["chmod +x ./kyomu"], shell=True)
subprocess.run(["./kyomu"], shell=True)
|
s = list( raw_input( ) )
n = int( raw_input( ) )
for i in range( n ):
cmd = raw_input( ).split( " " )
a = int( cmd[1] )
b = int( cmd[2] ) + 1
if "print" == cmd[0]:
print( "".join( s[ a:b ] ) )
elif "reverse" == cmd[0]:
for i in reversed( s[ a:b ] ):
s[ a ] = i
a += 1
elif "replace" == cmd[0]:
for i in cmd[3]:
s[ a ] = i
a += 1
| 0 | null | 2,191,563,614,472 | 70 | 68 |
def chk(x):
cur = 0
cnt = 0
while cur<N:
if S[cur]==str(x[cnt]):
cnt += 1
if cnt==3:
break
cur += 1
if cnt==3:
return 1
else:
return 0
N = int(input())
S = input().strip()
cnt = 0
for i in range(0,10):
for j in range(0,10):
for k in range(0,10):
cnt += chk((i,j,k))
print(cnt)
|
N = int(input())
S = input()
count = 0
for p in range(10):
s = S.find(str(p))
if s == -1:
continue
for q in range(10):
t = S.find(str(q), s + 1)
if t == -1:
continue
for r in range(10):
u = S.find(str(r), t + 1)
if u != -1:
count += 1
print(count)
| 1 | 129,112,006,326,160 | null | 267 | 267 |
def main():
n = int(input())
a_list = list(map(int, input().split()))
num = 1
for a in a_list:
if a == num:
num += 1
if num == 1:
print(-1)
else:
print(n - num + 1)
if __name__ == "__main__":
main()
|
N=int(input())
lst=list(map(int,input().split(" ")))
now=0
for i in range(N):
if lst[i]==now+1:
now+=1
if now == 0:
print(-1)
else:
print(N-now)
| 1 | 114,534,458,380,420 | null | 257 | 257 |
count = int(input())
for i in range(count):
a = map(int,raw_input().split())
a.sort()
if a[0]**2+a[1]**2 == a[2]**2: print "YES"
else: print "NO"
|
import sys
import math
#from queue import *
#import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
l,r,d=invr()
ans=0
for i in range(l,r+1):
if i%d==0:
ans+=1
print(ans)
| 0 | null | 3,761,675,004,740 | 4 | 104 |
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 15:58:15 2020
@author: Aruto Hosaka
"""
N = int(input())
n15 = (N-1)//15
d15 = (N-1)%15
A = [1,2,0,4,0,0,7,8,0,0,11,0,13,14,0]
d = sum(A) - sum(A[d15+1:])
n = (n15-1)*n15//2*120+n15*60
ans = d+n
for a in A[:d15+1]:
if a != 0:
ans += n15*15
print(ans)
|
a=int(input())
print(a * a)
| 0 | null | 89,914,121,264,110 | 173 | 278 |
X, K, D =map(int,input().split())
X = abs(X)
if X > K*D:
print(X-K*D)
else:
greed = X//D
if (K - greed)%2 == 0:
print(X-greed*D)
else:
print((1+greed)*D -X)
|
def solve(string):
x, k, d = map(int, string.split())
if k % 2:
x = min(x - d, x + d, key=abs)
k -= 1
x, k, d = abs(x), k // 2, d * 2
return str(min(x % d, abs((x % d) - d))) if x < k * d else str(x - k * d)
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 5,203,199,198,658 | null | 92 | 92 |
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
# sys.setrecursionlimit(10**5)
def main():
h, a = geta(int)
print((h + a - 1) // a)
if __name__ == "__main__":
main()
|
#D - Chat in a Circle
N = int(input())
A = list(map(int,input().split()))
#ソート
arr = []
arr = sorted(A,reverse = True)
Friend_min_max_wa = 0
i =0
j = 0
for i in range(N -1):
if i % 2 != 0 : j = j + 1
Friend_min_max_wa = Friend_min_max_wa + arr[j]
# 出力
print(Friend_min_max_wa)
| 0 | null | 42,886,609,046,230 | 225 | 111 |
#93 B - Iron Bar Cutting WA (hint)
N = int(input())
A = list(map(int,input().split()))
# 差が最小の切れ目を見つける
length = sum(A)
left = 0
dist = 0
mdist = length
midx = 0
for i,a in enumerate(A):
left += a
right = length - left
dist = abs(left - right)
if dist < mdist:
mdist = dist
midx = i
ans = mdist
print(ans)
|
def Binary_Search_Count(A,x,sort=True,equal=False):
"""2分探索によって,x未満の要素の個数を調べる.
A:リスト
x:調べる要素
sort:ソートをする必要があるかどうか(Trueで必要)
equal:Trueのときはx"未満"がx"以下"になる
"""
if sort:
A.sort()
N=len(A)
if A[-1]<=x:
return N
elif x<A[0] or (not equal and x==A[0]):
return 0
L,R=0,N
while R-L>1:
C=L+(R-L)//2
if x<A[C] or (not equal and x==A[C]):
R=C
else:
L=C
return R
def Binary_Search_High_Value(A,x,sort=True,equal=False):
"""Aのxを超える要素の中で最小のものを出力する.
A:リスト
x:調べる要素
sort:ソートをする必要があるかどうか(Trueで必要)
equal:Trueのときはx"を超える"がx"以上"になる
※全ての要素がx以下(未満)場合はNoneが返される.
"""
if sort:
A.sort()
K=Binary_Search_Count(A,x,sort=False,equal=not equal)
if K==len(A):
return None
else:
return A[K]
N=int(input())
T={i:[] for i in range(10)}
S=input()
for i in range(N):
T[int(S[i])].append(i)
X=0
for k in range(10**3):
a,b,c=(k//100),(k//10)%10,k%10
if T[a]:
x=T[a][0]
if T[b]:
y=Binary_Search_High_Value(T[b],x,False,False)
if y!=None and T[c]:
z=Binary_Search_High_Value(T[c],y,False,False)
if z!=None:
X+=1
print(X)
| 0 | null | 135,476,485,450,282 | 276 | 267 |
import math
import sys
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
if n % 2 == 1:
print(0)
else:
n = n // 2
num = 0
for i in range(1, 100):
num += n // (5 ** i)
print(num)
if __name__ == '__main__':
main()
|
n, m, k = list(map(int, input().split()))
mod = 998244353
m_ = m - 1
n_ = n - 1
m_p = {0: 1}
ans = 0
fac = {0: 1, 1: 1}
finv = {0: 1, 1: 1}
inv = {1: 1}
def comb_init():
for i in range(2, n + 1):
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 comb(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
def pow_init(m):
for i in range(1, m):
m_p[i] = m_p[i - 1] * m_
m_p[i] %= mod
comb_init()
pow_init(n_ - k)
for i in range(k, -1, -1):
if n_ - i not in m_p:
m_p[n_ - i] = m_p[n_ - i - 1] * m_ % mod
d = m * comb(n_, i) % mod
d *= m_p[n_ - i]
ans += d % mod
ans %= mod
print(ans)
| 0 | null | 69,900,413,860,628 | 258 | 151 |
from math import ceil
H, K = list(map(int, input().split()))
print(ceil(H/K))
|
n = int(input())
C = list(input())
if "R" not in C:
print(0)
exit()
W = C.count("W")
R = C.count("R")
w = 0
r = R
ans = float('inf')
for c in C:
if c == "W":
w += 1
else:
r -= 1
ans = min(ans, max(w, r))
print(ans)
| 0 | null | 41,574,066,094,990 | 225 | 98 |
N, K = list(map(int, input().split()))
ans = min(N % K, K - (N % K))
print(ans)
|
N, K = map(int, input().split(' '))
print(min(N % K, abs((N % K) - K)))
| 1 | 39,326,893,494,390 | null | 180 | 180 |
n = int(input())
a = list(map(int, input().split()))
ret = 0
if n % 2 == 0:
dp = [[0] * 2 for _ in range(n)]
dp[0][0] = a[0]
for i in range(1, n):
dp[i][0] = dp[i-1][0] if i % 2 == 1 else dp[i-1][0] + a[i]
dp[i][1] = dp[i - 1][1] if i % 2 == 0 \
else max(dp[i-2][0], dp[i-2][1]) + a[i]
ret = max(dp[-1])
else:
dp = [[0] * 3 for _ in range(n)]
dp[0][0] = a[0]
for i in range(1, n):
dp[i][0] = dp[i-1][0] if i % 2 == 1 else dp[i-1][0] + a[i]
dp[i][1] = dp[i - 1][1] if i % 2 == 0 \
else max(dp[i-2][0], dp[i-2][1]) + a[i]
dp[i][2] = dp[i - 1][1] if i % 2 == 1 \
else max(dp[i-3][0], dp[i-2][1], dp[i-2][2]) + a[i]
ret = max(dp[-1][1], dp[-1][2], dp[-2][0])
print(ret)
|
n = int(input())
a = list(map(int,input().split()))
# i個使う時の要素の和の最大値
dp = [0]*(n+1)
dp[1] = 0
dp[2] = max(a[0],a[1])
# 奇数の番号の累積和
b = [0]*(n+1)
b[1] = a[0]
for i in range(1,n-1,2):
b[i+2] = b[i] + a[i+1]
# print(b)
for i in range(3,n+1):
if i % 2 == 0:
dp[i] = max(dp[i-2] + a[i-1], b[i-1])
else:
dp[i] = max(dp[i-2] + a[i-1], dp[i-3] + a[i-2], b[i-2])
# print(dp)
print(dp[n])
| 1 | 37,631,588,627,320 | null | 177 | 177 |
from math import *
a, b, x = map(int, input().split())
areatotal = a*a*b
if areatotal / 2 == x: print(45.0)
elif x > areatotal/2:
left = 0.0
right = 90.0
while right-left > 0.00000001:
current = (right+left)/2
if a**2 * tan(radians(current)) / 2 * a < (areatotal - x):
left = current
else:
right = current
print(left)
else:
left = 0.0
right = 90.0
while right-left > 0.00000001:
current = (right+left)/2
if b**2 * tan(radians(90-current))/2*a > x:
left = current
else:
right = current
print(left)
|
N=int(input())
x=list(map(int,input().split()))
sum=0
for i in range(1,N):
if x[i]<x[i-1]:
t=x[i-1]-x[i]
sum+=t
x[i]=x[i-1]
print(sum)
| 0 | null | 83,855,637,308,122 | 289 | 88 |
n=int(input())
count=0
for i in range(n):
x,y = map(int,input().split())
if x==y:
count+=1
else:
count=0
if count==3:
print('Yes')
exit()
print('No')
|
a, b = map(int, input().split())
x = int(a*(a-1)/2)
y = int(b*(b-1)/2)
print(x+y)
| 0 | null | 24,015,868,725,892 | 72 | 189 |
#!/usr/bin/env python3
import sys
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 main():
N = II()
A = LI()
A.sort()
MAX = 10**6+1
All = [0] * MAX
setA = set(A)
for i in A:
k = i
All[k] += 1
k += i
if All[i] >= 2:
continue
while k < MAX:
All[k] += 1
k += i
ans = 0
for i in range(1, MAX):
if All[i] == 1 and i in setA:
ans += 1
print(ans)
# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()
|
A=[]
for _ in range(3):
A+=map(int,input().split())
N=int(input())
for _ in range(N):
b=int(input())
if b in A:
A[A.index(b)]=0
for i,j,k in [
(0,1,2),(3,4,5),(6,7,8),
(0,3,6),(1,4,7),(2,5,8),
(0,4,8),(2,4,6),
]:
if A[i]==A[j]==A[k]:
print('Yes')
break
else:
print('No')
| 0 | null | 37,186,340,432,160 | 129 | 207 |
import sys
import math
count = 0
judge = 0
for line in sys.stdin.readlines():
num = int(line.strip())
if judge == 0:
judge = 1
else:
flag = 0
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
flag = 1
break
if flag == 0:
count += 1
print count
|
while 1:
num = input()
if num == "0":
break
a = []
for i in range(len(num)):
a.append(int(num[i:i+1]))
print(sum(a))
| 0 | null | 786,081,746,308 | 12 | 62 |
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()
s = list(input())
r = s.count('R')
g = s.count('G')
b = s.count('B')
cnt = r*g*b
for i in range(n):
for j in range(i+1, n):
k = 2*j - i
if k >= n:
break
if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
cnt -= 1
print(cnt)
if __name__ == '__main__':
main()
|
N, A, B = input().split(' ')
N = int(N)
A = int(A)
B = int(B)
a = A * (N // (A+B))
if (N%(A+B)) > A:
a += A
else:
a += (N%(A+B))
print(a)
| 0 | null | 45,981,363,233,060 | 175 | 202 |
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
v=V-W
l=abs(A-B)
if l<=v*T:
print("YES")
else:
print("NO")
|
h, w, k = map(int, input().split())
fi = []
for _ in range(h):
s = input()
fi.append(s)
a = 1 << h
b = 1 << w
ans = 0
for i in range(a * b):
lh = [0 for _ in range(h)]
lw = [0 for _ in range(w)]
for j in range(h):
if i & (1 << j):
lh[j] += 1
for j in range(w):
if i & (1 << (j + h)):
lw[j] += 1
cnt = 0
for j in range(h):
for l in range(w):
if lh[j] == 1:
continue
if lw[l] == 1:
continue
if fi[j][l] == '#':
cnt += 1
if cnt == k:
ans += 1
print(ans)
| 0 | null | 11,984,206,029,852 | 131 | 110 |
n = int(input())
mod = 10**9+7
ans = pow(10,n)
ans -= pow(9,n)*2
ans += pow(8,n)
print(ans%mod)
|
N = int(input())
ans = 0
MOD = 10**9+7
ans = 10**N-2*9**N+8**N
ans %= MOD
print(ans)
| 1 | 3,174,160,770,170 | null | 78 | 78 |
name = str(input())
print(name[0:3])
|
X,Y = map(int,input().split())
prize = [0]*206
prize[1] = 300000
prize[2] = 200000
prize[3] = 100000
money = 0
if X == 1 and Y == 1:
money += 400000
print(money+prize[X]+prize[Y])
| 0 | null | 77,496,581,640,100 | 130 | 275 |
from collections import defaultdict
def gcd(a, b):
return gcd(b, a%b) if b else a
mod = 10 ** 9 + 7
N = int(input())
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
a, b = map(int, input().split())
g = abs(gcd(a, b))
if a * b > 0:
X[(abs(a) // g, abs(b) // g)][0] += 1
elif a * b < 0:
X[(abs(b) // g, abs(a) // g)][1] += 1
else:
if a:
x += 1
elif b:
y += 1
else:
z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
ans *= pow2[i[0]] + pow2[i[1]]- 1
ans %= mod
ans *= pow2[x] + pow2[y] - 1
print((ans+z-1)%mod)
|
import math
from collections import defaultdict
n = int(input())
p = defaultdict(int)
mod = 10 ** 9 + 7
ori = 0
for _ in range(n):
a,b = map(int,input().split())
if a == b == 0:
ori += 1
continue
elif b < 0:
a *= -1
b *= -1
elif b == 0 and a < 0:
a *= -1
if a == 0:
p[(0,1)] += 1
elif b == 0:
p[(1,0)] += 1
else:
g = math.gcd(a,b)
p[(a//g, b//g)] += 1
k = n - ori
ans = ori-1
tmp = 1
l = k
for q,num in sorted(p.items(), reverse=True):
x,y = q
if x <= 0:
break
if p[(-y, x)] >= 1:
a,b = p[(x,y)], p[(-y, x)]
tmp *= pow(2,a,mod) + pow(2,b,mod) - 1
l -= a+b
tmp *= pow(2,l,mod)
print((ans+tmp) % mod)
| 1 | 20,907,960,426,432 | null | 146 | 146 |
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
if N==1:
print('a')
exit()
d = deque(['a'])
ans = []
while d:
s = d.popleft()
last = ord(max(s))
for i in range(97,last+2):
S = s + chr(i)
if len(S)==N:
ans.append(S)
else:
d.append(S)
ans.sort()
for s in ans:
print(s)
if __name__ == '__main__':
main()
|
x,y = map(int,input().split())
A = y//2
B = (x-A)
while A>-1:
if y==2*A + 4*B:
print("Yes")
break
A = A-1
B = B+1
if A==-1:
print("No")
| 0 | null | 33,018,354,772,982 | 198 | 127 |
st = set()
n = int(input())
ls = [int(x) for x in input().split()]
for i in ls:
st.add(i)
if len(st) == n:
print("YES")
else:
print("NO")
|
#import math
import collections
#n,k = map(int, input().split( ))
#A = list(map(int, input().split( )))
n = int(input())
A = list(map(int, input().split( )))
c = collections.Counter(A)
a = c.most_common()[0][1]
if a != 1:
print('NO')
else:
print('YES')
| 1 | 73,978,946,701,660 | null | 222 | 222 |
string = list(map(str, input()))
ans =[]
for char in string:
if char.islower():
ans.append(char.upper())
elif char.isupper():
ans.append(char.lower())
else:
ans.append(char)
print(ans[-1], end="")
print()
|
i = input()
print(i.swapcase())
| 1 | 1,470,183,853,450 | null | 61 | 61 |
import math
from numpy.compat.py3k import asstr
a, b = map(int, input().split())
ans = int(a * b / math.gcd(a, b))
print(str(ans))
|
N, K = map(int, input().split())
P = list(map(int, input().split()))
S = [0]
sum_ = 0
for i, p in enumerate(P):
sum_ += p
S.append(sum_)
max_sum = 0
for i in range(N-K+1):
max_sum = max(max_sum, S[i+K] - S[i])
res = (max_sum + K) / 2
print(res)
| 0 | null | 94,068,579,057,920 | 256 | 223 |
N = int(input())
X = [int(x) for x in list(input().split())]
max_x = max(X)
min_x = min(X)
d = max_x - min_x
middle = (d//2)
P = middle + min_x
ans = 0
for i in range(N):
ans += (max_x-X[i])**2
for i in range(d):
n_ans = 0
P = min_x + i
for j in range(N):
n_ans += (P-X[j])**2
if (n_ans < ans):
ans = n_ans
print(int(ans))
|
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.int32(A)
vals, cnts = np.unique(A, return_counts=True)
if len(vals) == 1:
print(0 if cnts[0] > 1 else 1)
elif vals[0] == 1:
print(0 if cnts[0] > 1 else 1)
else:
sat = np.ones(vals.max() + 1, dtype=int)
for x in vals:
sat[2 * x::x] = 0
ans = ((sat[vals] == 1) & (cnts == 1)).sum().item()
print(ans)
# 1
# 1
# 5
# 2 2 2 3 3
# 5
# 2 2 2 4 4
# 5
# 1 1 1 1 2
| 0 | null | 39,655,936,936,330 | 213 | 129 |
import math
a,b,x = (int(a) for a in input().split())
if 2 * x <= a**2 * b :
t = b
s = 2 * x / (a*b)
r = s / t
print(90 - math.degrees(math.atan(r)))
else :
t = a
s = 2 * b - 2 * x / (a ** 2)
r = s / t
print(math.degrees(math.atan(r)))
|
from math import atan, degrees
def angle(a, b, x):
return degrees(atan(((a * b ** 2) / ( 2 * x)) if x <= 0.5 * b * a ** 2 else ((2 * (b - (x / (a ** 2)))) / a)))
print(angle(*map(int, input().split())))
| 1 | 163,205,234,793,458 | null | 289 | 289 |
N, K = map(int, input().split())
A = list(map(int, input().split()))
# 丸太がすべてxの長さ以下になる回数を出し、それがK回以下か判定する
def f(x):
now = 0
for i in range(N):
now += (A[i]-1)//x
return now <= K
l = 0
r = 10**9
while r-l > 1:
mid = (r+l)//2
if f(mid):
r = mid
else:
l = mid
print(r)
|
def solver(n ,m, coins):
dp = [[100000] * (n + 1) for i in range(m + 1)]
for i in range(m + 1): dp[i][0] = 0
for r in range(1, m + 1):
for c in range(1, n + 1):
if 0 > c - coins[r - 1]:
dp[r][c] = dp[r - 1][c]
else:
dp[r][c] = min(dp[r - 1][c], dp[r][c - coins[r - 1]] + 1)
print(dp[m][n])
n, m = map(int, input().split())
coins = sorted(list(map(int, input().split())))
solver(n, m, coins)
| 0 | null | 3,287,372,042,860 | 99 | 28 |
# -*- 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))
|
N=int(input())
for i in range(50000):
if int(i*1.08)==N:
print(i)
exit()
print(':(')
| 0 | null | 63,055,408,274,848 | 20 | 265 |
import sys
import math # noqa
import bisect # noqa
import queue # noqa
def input():
return sys.stdin.readline().rstrip()
def main():
N = int(input())
que = queue.Queue()
que.put(('a', ord('a')))
while not que.empty():
res, m = que.get()
if len(res) < N:
for i in range(ord('a'), min(ord('z'), m + 1) + 1):
que.put((res + chr(i), max(m, i)))
elif len(res) == N:
print(res)
else:
break
if __name__ == '__main__':
main()
|
N=int(input())
A=[int(a) for a in input().split()]
dp=[-1 for _ in range(N)]
dp[0]=1000
for i in range(1,N):
tmp=dp[i-1]
for j in range(i):
K=dp[j]//A[j]
res=dp[j]-K*A[j]
tmp=max(tmp,res+A[i]*K)
dp[i]=tmp
print(dp[-1])
| 0 | null | 29,763,237,784,568 | 198 | 103 |
n = input()
k = input()
a = k.count("R")
print(k[:a].count("W"))
|
x,y = map(int,input().split())
A =(-y+4.0*x)/2.0
B = (y-2.0*x)/2.0
if A>=0 and B>=0 and A.is_integer() and B.is_integer():
print("Yes")
else:
print("No")
| 0 | null | 10,104,177,427,392 | 98 | 127 |
# 7
from collections import Counter
import collections
import sys
def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()
INF = float('inf')
n = I()
d = LI()
mod = 998244353
if d[0] != 0:
print(0)
exit(0)
# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
counts = [0] * (max(d)+1)
for k, v in c.items():
counts[k] = v
if counts[0] > 1:
print(0)
exit(0)
ans = 1
for i in range(1, len(counts)):
ans *= pow(counts[i-1], counts[i])
ans %= mod
print(ans)
|
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
depth = defaultdict(int)
for d in D:
depth[d] += 1
# つながらない
if D[0] != 0 or depth[0] != 1:
print(0)
exit()
mod = 998244353
ans = 1
for d in range(1, max(D) + 1):
ans *= pow(depth[d - 1], depth[d], mod)
ans %= mod
print(ans)
| 1 | 154,738,247,148,830 | null | 284 | 284 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.