code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N = int(input())
if N >=30:
print('Yes')
else :
print('No')
|
def ac_control(q):
if q >= 30:
print("Yes")
else:
print("No")
if __name__ == '__main__':
q = int(input())
ac_control(q)
| 1 | 5,729,827,172,420 | null | 95 | 95 |
n = int(input())
s,t = input().split()
res = ""
for i in range(0,n):
res += s[i]
res += t[i]
print(res)
|
x, k, d = map(int, input().split())
if x < 0:
target = abs(x) // d
x = x + d * min(target, k)
k -= min(target, k)
else:
target = x // d
x = x - d * min(target, k)
k -= min(target, k)
if k % 2 != 0:
if x < 0:
x += d
else:
x -= d
print(abs(x))
| 0 | null | 58,886,517,985,760 | 255 | 92 |
if __name__ == '__main__':
n = int(input())
a = list(map(lambda x: int(x) + 1, input().split()))
counts = [0] * (n + 1)
counts[0] = 3
ans = 1
for i in range(n):
ans *= counts[a[i] - 1]
ans %= (10 ** 9 + 7)
counts[a[i] - 1] -= 1
counts[a[i]] += 1
print(ans)
|
h, w, k = map(int, input().split())
s = [list(map(int, list(input()))) for _ in range(h)]
result = []
if h*w<=k:
result.append(0)
else:
for i in range(2**(h-1)):
checker, num, p = 0, i ,[0]
for _ in range(h):
p.append(p[-1]+num%2)
checker += num%2
num >>= 1
x = 0
c = [0 for _ in range(checker+1)]
for j in range(w):
num = i
nex = [0 for _ in range(checker+1)]
for m in range(h):
nex[p[m]] += s[m][j]
if max(nex) > k:
x = float('inf')
break
if all(nex[m]+c[m] <= k for m in range(checker+1)):
c = [c[I]+nex[I] for I in range(checker+1)]
else:
x += 1
c = nex
result.append(checker+x)
print(min(result))
| 0 | null | 89,094,364,281,780 | 268 | 193 |
import heapq
N, D, A = map(int, input().split(" "))
proc_que = []
for _ in range(N):
x, h = map(int, input().split(" "))
heapq.heappush(proc_que, (x, h))
damaged = 0
ans = 0
while len(proc_que) > 0:
x, h = heapq.heappop(proc_que)
if h > 0:
# monster
num_bomb_use = max(0, (h - damaged + A - 1) // A)
ans += num_bomb_use
damaged += num_bomb_use * A
heapq.heappush(proc_que, (x + 2 * D + 1, -num_bomb_use * A))
else:
# damaged end
damaged += h
print(ans)
|
# -*- coding: utf-8 -*-
H, N = map(int, input().split(' '))
nums = [float('inf') for _ in range(H+1)]
nums[0] = 0
for _ in range(N):
a, b = map(int, input().split(' '))
for i in range(H + 1):
j = min(H, i+a)
nums[j] = min(nums[j], nums[i] + b)
print(nums[H])
| 0 | null | 81,519,468,839,988 | 230 | 229 |
N, K = map(int, input().split())
mod1 = N % K
mod2 = (K - mod1)
print(mod1 if mod1 < mod2 else mod2)
|
from itertools import accumulate
N,K = map(int,input().split())
acc = list(accumulate(range(N+1), lambda x,y:x+y))
ans = 0
mod = 10**9+7
for i in range(K, N+1):
r = acc[N] - acc[N-i]
l = acc[i-1]
ans = (ans+r-l+1) % mod
ans += 1
print(ans % mod)
| 0 | null | 36,161,966,042,652 | 180 | 170 |
pi = 3.141592653589
r = float(input())
c = pi*r**2
s = 2*pi*r
print('%.5f %.5f' % (c,s))
|
import math
r = float(input())
print('%.5f' % (r * r * math.pi), '%.5f' % (2 * math.pi * r))
| 1 | 653,027,915,584 | null | 46 | 46 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N):
for j in range(i+1,N):
p = L[i]+L[j]
k = bisect.bisect_left(L[j+1:], p)
ans += k
print(ans)
|
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def solve():
n = int(input())
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(n):
for j in range(i+1, n):
k = bisect.bisect_left(l, l[i]+l[j])
res += max(k-(j+1), 0)
print(res)
return 0
if __name__ == "__main__":
solve()
| 1 | 171,427,244,837,508 | null | 294 | 294 |
M1,D1 = map(int,input().split())
M2,D2 = map(int,input().split())
if M1<M2:print(1)
else:print(0)
|
A,B = map(int, input().split())
C,D = map(int, input().split())
if D == 1:
print("1")
else:
print("0")
| 1 | 123,836,386,368,002 | null | 264 | 264 |
X = int(input())
while True:
flag = True
for i in range(2, X):
if X % i == 0:
flag = False
if flag: break
X += 1
print(X)
|
N=int(input())
B=[int(a) for a in input().split()]
sum=0
ans=0
for i in range(len(B)-1):
sum+=B[i]
ans+=sum*B[i+1]
print(ans%1000000007)
| 0 | null | 54,420,442,015,772 | 250 | 83 |
from sys import stdin,stdout #
import math #
import heapq #
#
t = 1 #
def aint(): #
return int(input().strip()) #
def lint(): #
return list(map(int,input().split())) #
def fint(): #
return list(map(int,stdin.readline().split())) #
#
########################################################
def main():
n=aint()
l=lint()
ans=0
for i in range(0,n,2):
if l[i]%2:
ans+=1
print(ans)
return
#t=int(input())
########################################################
for i in range(t): #
#print("Case #"+str(i+1)+":",end=" ") #
main() #
|
from collections import*
(n,m),*c = [[*map(int,i.split())]for i in open(0)]
g = [[]for _ in range(n+1)]
for a,b in c:
g[a]+=[b]
g[b]+=[a]
q=deque([1])
r=[0]*(n+1)
while q:
v=q.popleft()
for i in g[v]:
if r[i]==0:
r[i]=v
q.append(i)
print("Yes",*r[2:],sep="\n")
| 0 | null | 14,194,931,487,780 | 105 | 145 |
a=b=1
for _ in range(int(input())):a,b=b,a+b
print(a)
|
s = input()
if s[-1] == 's':
s = s + 'e'
s = s + 's'
print(s)
| 0 | null | 1,205,623,897,488 | 7 | 71 |
import math
a,b,x=[int(x) for x in input().rstrip().split()]
S=x/a
if S==a*b:
print(0)
else:
if S<=(a*b)/2:
a1=S/b
tan=(b**2)/(2*S)
print(math.degrees(math.atan(tan)))
else:
tan=(2*a*b-2*S)/a**2
print(math.degrees(math.atan(tan)))
|
import math
a,b,x=map(int,input().split())
t=a*b*b/2/x if 2*x<a*a*b else 2/a*(b-x/a/a)
print(math.degrees(math.atan(t)))
| 1 | 162,714,672,002,270 | null | 289 | 289 |
import sys
# ## COMBINATION (MOD) ## #
MOD = 10**9 + 7 # , N = 2*10**5 で 0.3s
N_MAX = 10**5 + 1 # 問題サイズに合わせて変えておく
fac = [1, 1] # 元テーブル
facinv = [1, 1] # 逆元テーブル
inv = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N_MAX + 1):
fac.append((fac[-1] * i) % MOD)
inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
facinv.append((facinv[-1] * inv[-1]) % MOD)
def cmb(n, r):
if (r < 0 or r > n):
return 0
# r = min(r, n-r)
return fac[n] * facinv[r] * facinv[n - r] % MOD
def main():
N, K = map(int, sys.stdin.readline().rstrip().split())
A = [int(x) for x in sys.stdin.readline().rstrip().split()]
A.sort() # 小 -> 大
# 左から i 番目が選ばれて、i+1番目以降が選ばれない
sum = 0
for i in range(N - K + 1):
sum += cmb(N - i - 1, K - 1) * (A[-(i + 1)] - A[i]) % MOD
sum %= MOD
print(sum)
main()
|
#!/usr/bin/env python3
from collections import Counter
def main():
S = input()
N = len(S)
T = [0] * (N+1)
for i in range(N-1,-1,-1):
T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019
l = Counter(T)
ans = 0
for v in l.values():
ans += v * (v-1) // 2
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 63,485,798,651,512 | 242 | 166 |
from itertools import permutations
n = int(input())
x = [i+1 for i in range(n)]
x = list(map(str, x))
pt = [''.join(p) for p in permutations(x)]
a = pt.index(''.join(input().split()))
b = pt.index(''.join(input().split()))
print(abs(a-b))
|
N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
if x!=par[x]:
par[x]=find(par[x])
return par[x]
def union(x,y):
if find(x)!=find(y):
x, y = par[x], par[y]
par[y] = par[x]
size[x] += size[y]
res=N
for i in range(M):
s,e=map(int,input().split())
union(s,e)
print(max(size))
| 0 | null | 52,298,196,102,020 | 246 | 84 |
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
#solve
def solve():
n, k = LI()
a = LI()
a.sort(key=abs, reverse=True)
ans = 1
if n - a.count(0) < k:
print(0)
return
t = 0
L = None
R= inf
for ai in a[:k]:
if ai < 0:
t ^= 1
L = ai
if ai > 0:
R = ai
ans *= ai
ans %= mod
if k == n:
print(ans)
return
if t:
if max(a) <= 0:
ans = 1
for i in range(k):
ans *= a[-i - 1]
ans %= mod
print(ans)
else:
A = min(a[k:])
B = max(a[k:])
if A >= 0:
ans *= pow(L, mod - 2, mod)
ans *= B
else:
if A * L > B * R:
ans *= pow(R, mod - 2, mod)
ans *= A
else:
ans *= pow(L, mod - 2, mod)
ans *= B
print(ans % mod)
else:
print(ans)
return
#main
if __name__ == '__main__':
solve()
|
mountains = []
for x in range(10):
mountains.append(int(raw_input()))
mountains.sort()
mountains.reverse()
print mountains[0]
print mountains[1]
print mountains[2]
| 0 | null | 4,675,062,049,272 | 112 | 2 |
# coding: utf-8
#Name: List of Top 3 Hills
#Level: 1
#Category: ????????????
#Note:
s = [int(raw_input()) for i in range(10)]
s.sort()
for i in range(3):
print s[9-i]
|
a, b, m = map(int, input().split())
re = list(map(int, input().split()))
de = list(map(int, input().split()))
mre = min(re)
mde = min(re)
list1 = []
for i in range(m):
x, y, c = map(int, input().split())
price = re[x-1] + de[y-1] -c
list1.append(price)
mlist = min(list1)
m1 = mre + mde
if m1 < mlist:
print(m1)
else:
print(mlist)
| 0 | null | 26,929,872,861,616 | 2 | 200 |
k=int(input())
a,b= map(int, input().split())
q=0
for i in range(1,1000):
if a<=k*i and k*i<=b:
print('OK')
q=1
break
if q==0:
print('NG')
|
k = int(input())
a,b = map(int,input().split())
for i in range(a,b+1):
if(i % k == 0):
print("OK")
exit()
print("NG")
| 1 | 26,676,385,392,410 | null | 158 | 158 |
# coding: utf-8
# Here your code !
def func():
try:
(n,m,l) = [ int(item) for item in input().rstrip().split(" ") ]
matrix_A = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(n) ]
matrix_B = [ [ int(item) for item in input().rstrip().split(" ") ] for i in range(m) ]
except:
return inputError()
matrix_C = [ [ sum([ matrix_A[i][j]*matrix_B[j][k] for j in range(m) ]) for k in range(l) ] for i in range(n) ]
result=""
for vector in matrix_C:
for item in vector:
result+=str(item)+" "
result=result.rstrip()
result+="\n"
print(result.rstrip())
def inputError():
'''
print("input Error")
return -1
'''
print("input Error")
return -1
func()
|
house1 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house2 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house3 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
house4 = [[0 for x in range(10)], [0 for x in range(10)], [0 for x in range(10)]]
houses = [house1, house2, house3, house4]
n = int(input())
for i in range(n):
b, f, r, v = [int(x) for x in input().split()]
houses[b - 1][f - 1][r - 1] += v
cnt = 0
for house in houses:
for floor in house:
floor = [str(x) for x in floor]
print(' ' + ' '.join(floor))
if cnt != 3:
print('#' * 20)
cnt += 1
| 0 | null | 1,289,833,784,250 | 60 | 55 |
import sys
num = []
for i in sys.stdin:
H, W = i.split()
if H == W == '0':
break
num.append((int(H), int(W)))
for cnt in range(len(num)):
for h in range(num[cnt][0]):
for w in range(num[cnt][1]):
print('#',end='')
print()
print()
|
while True:
H,W = map(int, input().split())
if H == 0 and W == 0:
break
a = "#" * W
for i in range(H):
print(a)
print()
| 1 | 782,362,452,358 | null | 49 | 49 |
n,k =list(map(int,input().split()))
for i in range(31):
if n < k ** i:
print(i)
break
|
s = input()
n = len(s) // 2
j = -1
t = 0
for i in range(n):
if s[i] != s[j]:
t += 1
j -= 1
print(t)
| 0 | null | 91,845,340,104,100 | 212 | 261 |
import math
n = int(input())
og = n
n /= 1.08
n = math.ceil(n)
if int(n * 1.08) == og:
print(n)
else:
print(":(")
|
n=int(input())
flag = False
for i in range(100*n,100*(n+1)):
if i%108 == 0:
x = int(i//108)
print(x)
flag = True
break
if flag == False:
print(':(')
| 1 | 125,724,192,221,770 | null | 265 | 265 |
from collections import deque
N,M = (int(a) for a in input().split())
g = [[] for _ in range(N)]
s = [0]*N
for i in range(M) :
A,B = (int(a) for a in input().split())
g[A-1].append(B)
g[B-1].append(A)
visited = {0}
stack = [0]
for i in stack :
for j in g[i] :
if j-1 in visited :
continue
stack.append(j-1)
visited.add(j-1)
s[j-1] = i + 1
if s.count(0) > 1 :
print("No")
else :
print("Yes")
print(*s[1:])
|
from collections import defaultdict
G = defaultdict(set)
N, M = [int(_) for _ in input().split()]
for _ in range(M):
A, B = [int(_) for _ in input().split()]
G[A].add(B)
G[B].add(A)
f = [-1 for _ in range(N+1)]
f[1] = 0
pool = set([1])
np = set()
cnt = 0
while pool:
np = set()
for p in pool:
for v in G[p]:
if f[v] == -1:
f[v] = p
cnt += 1
np.add(v)
pool = np
print("Yes")
for i in range(2, N+1):
print(f[i])
| 1 | 20,519,109,028,572 | null | 145 | 145 |
def f():
n=int(input())
l=[0,0,0]
ans=1
mod=10**9+7
for i in list(map(int,input().split())):
if i not in l:print(0);exit()
ans=ans*l.count(i)%mod
l[l.index(i)]+=1
print(ans)
if __name__ == "__main__":f()
|
N, K, *A = map(int, open(0).read().split())
MAX = 10 ** 5 + 1
MOD = 10 ** 9 + 7
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
fac[i] = fac[i - 1] * i % MOD
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
finv[i - 1] = finv[i] * i % MOD
def comb(n, k):
if n < k or k < 0:
return 0
return (fac[n] * finv[k] * finv[n - k]) % MOD
A.sort()
ans = 0
for i in range(N):
if i >= K - 1:
ans += comb(i, K - 1) * A[i]
if i + K - 1 < N:
ans -= comb(N - i - 1, K - 1) * A[i]
ans %= MOD
print(ans)
| 0 | null | 112,844,005,278,640 | 268 | 242 |
n,k = map(int, input().split())
ans = 0
while n > 0:
n /= k
n = int(n)
ans += 1
print(ans)
|
n,k = [int(x) for x in input().split()]
res = 0
while n > 0:
n //= k
res += 1
print(res)
| 1 | 64,494,125,105,752 | null | 212 | 212 |
import sys
input = sys.stdin.readline
def p_count(n):
return bin(n)[2:].count('1')
n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)
pop_cnt = x.count('1')
pop_cnt_0 = (pop_cnt + 1)
pop_cnt_1 = (pop_cnt - 1)
x_0 = pow(x_dec,1,pop_cnt_0)
x_1 = pow(x_dec,1,pop_cnt_1) if pop_cnt_1 > 0 else 0
x_bit = [0]*n
for i in range(n-1,-1,-1):
if x[i] == '0':
x_bit[i] = (x_0 + pow(2,n-1-i,pop_cnt_0))%pop_cnt_0
#x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
else:
if pop_cnt_1 > 0:
x_bit[i] = (x_1 - pow(2,n-1-i,pop_cnt_1))
x_bit[i] = x_bit[i] if x_bit[i] >= 0 else x_bit[i] + pop_cnt_1
else:
x_bit[i] = -1
anslist = []
for i in range(n):
if x_bit[i] == -1:
anslist.append(0)
continue
ans = 1
now = x_bit[i]
while True:
if now == 0:
break
now = now%p_count(now)
ans += 1
anslist.append(ans)
for ans in anslist:
print(ans)
|
import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *
def r():
return int(input())
def rm():
return map(int,input().split())
def rl():
return list(map(int,input().split()))
'''D Anything Goes to zero'''
twoPowM1=[0]*(300000)
twoPowM2=[0]*(300000)
stepsSmall=[0]*(300000)
n=r()
s=input()
bitcount=0
for i in range(n):
if s[i]=='1':
bitcount+=1
mod=bitcount-1
if mod>0:
twoPowM1[0]=1
for i in range(1,len(twoPowM1)):
twoPowM1[i]=(twoPowM1[i-1]+twoPowM1[i-1])%mod
mod=bitcount+1
twoPowM2[0]=1
for i in range(1,len(twoPowM2)):
twoPowM2[i]=(twoPowM2[i-1]+twoPowM2[i-1])%mod
for i in range(1,len(stepsSmall)):
stepsSmall[i]=1+stepsSmall[i%bin(i).count('1')]
valM1=0;valM2=0
for i in range(n):
mod=bitcount-1
if mod>0:
valM1=((valM1*2)%mod+int(s[i]))%mod
mod=bitcount+1
valM2=((valM2*2)%mod+int(s[i]))%mod
for i in range(n):
pow=n-1-i
if s[i]=='0':
mod=bitcount+1
newVal=(valM2+twoPowM2[pow])%mod
print(stepsSmall[newVal]+1)
else:
mod=bitcount-1
if mod==0:
print(0)
else:
newVal=(valM1-twoPowM1[pow])%mod
print(stepsSmall[newVal]+1)
| 1 | 8,123,075,781,340 | null | 107 | 107 |
import math
n=int(input())
m=int(math.sqrt(n))+1
for i in range(m):
if n%(m-i)==0:
k=m-i
l=n//(m-i)
break
print(k+l-2)
|
n = int(input())
k = 1000000007
if n == 1:
print(0)
else:
print(((10**n)%k - (2* 9**n)%k+(8**n)%k)%k)
| 0 | null | 82,616,353,619,940 | 288 | 78 |
n = input()
a = list(n)
k = int(input())
n = len(a)
for i in range(n):
a[i] = int(a[i])
dp = [[[0 for i in range(2)] for i in range(k+2)]for i in range(n)]
dp[0][0][0] = 1
dp[0][1][0] = a[0]-1
dp[0][1][1] = 1
for i in range(n-1):
for j in range(k+1):
if a[i+1] == 0:
dp[i+1][j][1] += dp[i][j][1]
dp[i+1][j][0] += dp[i][j][0]
dp[i+1][j+1][0] += dp[i][j][0]*9
else:
dp[i+1][j][0] += dp[i][j][0]+dp[i][j][1]
dp[i+1][j+1][0] += dp[i][j][1]*(a[i+1]-1)+dp[i][j][0]*9
dp[i+1][j+1][1] += dp[i][j][1]
print(dp[n-1][k][0]+dp[n-1][k][1])
|
# from collections import defaultdict
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
K = int(input())
keta = len(str(N))
dp = [[0]*(keta) for i in range(4)]
ans = 0
for k in range(1, 4):
for i in range(1, keta):
if i<k:
continue
else:
dp[k][i] = comb(i-1, i-k)*(9**k)
#print(dp)
# dp[k][i]: i桁で、k個の0でない数
ans += sum(dp[K]) # (N の桁)-1 までの累積和
count = 0
for j in range(keta):
t = int(str(N)[j])
if j==0:
count+=1
ans += sum(dp[K-count])*(t-1)
if count == K: # K==1
ans+=t
break
continue
elif j==keta-1:
if t!=0:
count+=1
if count==K:
ans+=t
break
if t !=0:
count+=1
if count==K:
ans+=sum(dp[K-count+1][:keta-j]) #0のとき
ans+=t
break
ans += sum(dp[K-count][:keta-j])*(t-1) #0より大きいとき
ans += sum(dp[K-count+1][:keta-j]) #0のとき
print(ans)
| 1 | 76,049,489,754,942 | null | 224 | 224 |
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
A, B, N = map(int, input().split())
if N >= B-1:
print(A*(B-1)//B)
else:
print(A*N//B)
|
import math
def myceil(x,n):
return math.pow(10,-n)*math.ceil(x*math.pow(10,n))
def debt(principal,w):
if w==1:
return int(myceil(principal*1.05,-3))
else:
return int(debt(myceil(principal*1.05,-3),w-1))
w=int(input())
print(debt(100000,w))
| 0 | null | 14,078,545,212,314 | 161 | 6 |
X,Y=map(int,input().split())
if X==1 :
x=300000
elif X==2 :
x=200000
elif X==3 :
x=100000
else :
x=0
if Y==1 :
y=300000
elif Y==2 :
y=200000
elif Y==3 :
y=100000
else :
y=0
if X==1 and Y==1 :
print(x+y+400000)
else :
print(x+y)
|
x,y=map(int,input().split())
d={3:100000,2:200000,1:300000}
r=0
if x<=3:
r+=d[x]
if y<=3:
r+=d[y]
if x+y==2:
r+=400000
print(r)
| 1 | 140,665,582,086,460 | null | 275 | 275 |
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
nextcity = [[] for _ in range(N)]
sgn = [0 for _ in range(N)]
while M:
M -= 1
A, B = map(int, input().split())
A -= 1
B -= 1
nextcity[A].append(B)
nextcity[B].append(A)
def bfs(cnt, lis):
nextvisit = []
for j in lis:
for item in nextcity[j]:
if sgn[item] == 0:
nextvisit.append(item)
sgn[item] = cnt
if nextvisit:
bfs(cnt, nextvisit)
return None
else:
return None
cnt = 0
for k in range(N):
if sgn[k] == 0:
cnt += 1
sgn[k] = cnt
bfs(cnt, [k])
print(cnt -1)
|
# Connect Cities
# Union Findデータ構造(素集合データ構造)
#入力:N,M(int:整数)
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
class UnionFind():
"""docstring for UnionFind"""
def __init__(self, n):
self.parents = [-1]*n
def find(self,x):
if self.parents[x] < 0: #自分が親である時
return x
else: #自分が子供である時
self.parents[x]=self.find(self.parents[x])
return self.parents[x]
def union(self,x,y):
# 各要素の親要素を返す
x=self.find(x)
y=self.find(y)
if x==y:
return
if self.parents[x] > self.parents[y]:
x,y=y,x
self.parents[y]=x
n,m=input2()
AB=[input_array() for _ in range(m)]
uf = UnionFind(n)
for ab in AB:
a=ab[0]
b=ab[1]
uf.union(a-1,b-1)
ans=0
for i in uf.parents:
if i < 0:
ans+=1
print(ans-1)
| 1 | 2,320,231,979,610 | null | 70 | 70 |
def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import sys
import numpy as np
from math import gcd
mod = 10**9+7
def pow_mod(base, exp): # [pow_mod, "i8(i8,i8)"],
# mod はグローバル変数を参照
exp %= mod - 1
res = 1
while exp:
if exp % 2:
res = res * base % mod
base = base * base % mod
exp //= 2
return res
def solve(N, AB):
n = 0
na = nb = nab = 0
Cnt = {}
for a, b in zip(AB[::2], AB[1::2]):
if (a, b) == (0, 0):
nab += 1
elif a == 0:
na += 1
elif b == 0:
nb += 1
else:
if b < 0:
a, b = -a, -b
g = gcd(a, b)
a //= g
b //= g
ab_fr = (a, b)
n += 1
if ab_fr in Cnt:
Cnt[ab_fr] += 1
else:
Cnt[ab_fr] = 1
inv = (-b, a) if a > 0 else (b, -a)
if inv not in Cnt:
Cnt[inv] = 0
ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
A = []
for ab_fr, cnt in Cnt.items():
a, b = ab_fr
inv = (-b, a) if a > 0 else (b, -a)
cnt2 = Cnt[inv]
p = pow_mod(2, cnt)
p2 = pow_mod(2, cnt2)
A.append((p + p2 - 1) % mod)
A.sort()
for a in A[::2]:
ans = ans * a % mod
ans += nab - 1
return ans % mod
numba_compile([
[pow_mod, "i8(i8,i8)"],
[solve, "i8(i8,i8[:])"],
])
def main():
N = int(sys.stdin.buffer.readline())
m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
ans = solve(N, m)
print(ans)
main()
|
#!python3
import sys
from collections import defaultdict
from math import gcd
iim = lambda: map(int, input().rstrip().split())
def resolve():
N = input()
it = map(int, sys.stdin.read().split())
mod = 10**9 + 7
d1 = [defaultdict(int), defaultdict(int)]
z0 = za = zb = 0
for ai, bi in zip(it, it):
t = ai * bi
if t == 0:
if ai != 0:
za += 1
elif bi != 0:
zb += 1
else:
z0 += 1
continue
ci = gcd(ai, bi)
ai, bi = ai // ci, bi // ci
t = t < 0
if ai < 0:
ai, bi = -ai ,-bi
d1[t][(ai, bi)] += 1
a1, a2 = d1
ans = 1
z1 = 0
for (ai, bi), v in a1.items():
k2 = (bi, -ai)
if k2 in a2:
v2 = a2[k2]
ans *= pow(2, v, mod) + pow(2, v2, mod) - 1
ans %= mod
else:
z1 += v
for (ai, bi), v in a2.items():
k2 = (-bi, ai)
if k2 in a1: continue
z1 += v
ans *= pow(2, za, mod) + pow(2, zb, mod) - 1
ans %= mod
ans *= pow(2, z1, mod)
print((ans-1+z0) % mod)
if __name__ == "__main__":
resolve()
| 1 | 20,823,343,271,840 | null | 146 | 146 |
n=int(input())
f = False
match=0
for i in range(n):
a,b=map(int,input().split())
if a==b:
match+=1
f |= (match == 3)
else:
match=0
if f:
print("Yes")
else:
print("No")
|
from collections import Counter
def read():
N, K = list(map(int, input().strip().split()))
return N, K
def n_gcd(k, N, K, cache, MOD=10**9+7):
if cache[k] != -1:
return cache[k]
n = pow(K // k, N, MOD)
for j in range(2*k, K+1, k):
n -= n_gcd(j, N, K, cache)
n %= MOD
cache[k] = n
return n
def solve(N, K, MOD=10**9+7):
cache = [-1 for k in range(K+1)]
ans = 0
for k in range(K, 0, -1):
ans += n_gcd(k, N, K, cache) * k
ans %= MOD
return ans
if __name__ == '__main__':
inputs = read()
print("{}".format(solve(*inputs)))
| 0 | null | 19,687,207,341,348 | 72 | 176 |
import sys
def resolve(in_):
n, k = map(int, in_.readline().split())
a = list(map(int, in_.readline().split()))
mod = 10 ** 9 + 7
assert n == len(a)
# print(f'{n=} {k=} {len(a)=}')
m = sorted(filter(lambda x: x < 0, a))
p = sorted(filter(lambda x: x >= 0, a), reverse=True)
if len(p) == 0:
# print(f'{m=}')
if k % 2:
ans = m[-1] % mod
for v in m[-k:-1]:
v %= mod
ans *= v
ans %= mod
return ans
else:
ans = m[0] % mod
for v in m[1:k]:
v %= mod
ans *= v
ans %= mod
return ans
elif len(m) == 0:
ans = p[0] % mod
for v in p[1:k]:
v %= mod
ans *= v
ans %= mod
return ans
values = []
p_index = 0
m_index = 0
for _ in range(k):
if p_index < len(p) and m_index < len(m):
if p[p_index] >= abs(m[m_index]):
values.append(p[p_index])
p_index += 1
else:
values.append(m[m_index])
m_index += 1
elif p_index >= len(p):
values.append(m[m_index])
m_index += 1
elif m_index >= len(m):
values.append(p[p_index])
p_index += 1
else:
raise ValueError(f'{p_index=} {m_index=}')
# print(f'{values[:10]=} {p[:10]=} {m[:10]=}')
if any(v == 0 for v in values):
return 0
minus_values = sum(1 for v in values if v < 0)
# print(f'{minus_values > 0 and minus_values % 2=}')
if minus_values > 0 and minus_values % 2:
x = None
y = None
minus_max = max((value for value in values if value < 0), default=None)
plus_min = min((value for value in values if value >= 0), default=None)
if len(p) > p_index and minus_max:
# print(f'{p[p_index]=}')
x = abs(p[p_index] + minus_max)
if len(m) > m_index and plus_min:
# print(f'{m[m_index]=}')
y = abs(m[m_index] + plus_min)
# print(f'{x=} {y=} {minus_max=} {plus_min=}')
if x is None and y is None:
pass
elif x is None or y is None:
if x is None:
values.remove(plus_min)
values.append(m[m_index])
elif y is None:
values.remove(minus_max)
values.append(p[p_index])
else:
if x < y:
values.remove(minus_max)
values.append(p[p_index])
elif x > y:
values.remove(plus_min)
values.append(m[m_index])
elif abs(minus_max) < plus_min:
values.remove(plus_min)
values.append(m[m_index])
else:
values.remove(minus_max)
values.append(p[p_index])
ans = values[0] % mod
for v in values[1:k]:
v %= mod
ans *= v
ans %= mod
return ans
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
|
s = str(input())
p = str(input())
if p[0] not in s:
print("No")
elif p in s:
print("Yes")
else:
for i in range(len(s)):
s = s[1:] + s[:1]
if p in s:
print("Yes")
break
else:
print("No")
| 0 | null | 5,564,569,251,540 | 112 | 64 |
#!/usr/bin/env python3
import math
from decimal import *
def main():
h,w = map(int, input().split())
if h == 1:
print(1)
exit()
elif w ==1:
print(1)
exit()
else:
print(math.ceil(h*w/2))
if __name__ == '__main__':
main()
|
H, W = map(int, input().split())
if H == 1 or W == 1:
r = 1
else:
r = (H*W +2-1)//2
print(r)
| 1 | 50,625,115,564,562 | null | 196 | 196 |
a,b,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = []
for i in range(m):
x,y,c = map(int, input().split())
ans += [A[x-1] + B[y-1] - c]
ans += [min(A) + min(B)]
print(min(ans))
|
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(M)]
ans = [min(a) + min(b)]
for x in X:
a_idx, b_index, c = x
ans.append(a[a_idx - 1] + b[b_index - 1] - c)
print(min(ans))
| 1 | 54,130,118,819,472 | null | 200 | 200 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
s = input()
if s[0] != s[1] or s[1] != s[2] or s[0] != s[2]:
print ("Yes")
else:
print("No")
|
n = int(input())
if n%2:
print(0)
else:
ans = 0
for i in range(1,100):
ans += (n//(5**i*2))
if n < 5**i:
break
print(ans)
| 0 | null | 85,456,705,942,752 | 201 | 258 |
#
# m_solutions2020 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """7 2 5
3"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 4 2
3"""
output = """No"""
self.assertIO(input, output)
def resolve():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print("Yes")
break
else:
print("No")
if __name__ == "__main__":
# unittest.main()
resolve()
|
A, B, C, D = map(int, input().split())
T_HP = A
T_AT = B
A_HP = C
A_AT = D
T_count = 0
A_count = 0
while T_HP > 0:
T_HP -= A_AT
T_count += 1
while A_HP > 0:
A_HP -= T_AT
A_count += 1
if T_count > A_count:
print('Yes')
elif T_count == A_count:
print('Yes')
else:
print('No')
| 0 | null | 18,331,018,608,800 | 101 | 164 |
from sys import exit
from collections import deque
N = int(input())
D = deque(map(int, input().split()))
if N == 0:
d = D.pop()
if d == 1:
print(1)
else:
print(-1)
exit()
R = [[] for i in range(N + 1)]
leaf = D.pop()
R[-1].append(leaf)
R[-1].append(leaf)
for i in range(N - 1, -1, -1):
leaf = D.pop()
R[i].append(R[i + 1][0]//2 + R[i + 1][0] % 2 + leaf)
R[i].append(R[i + 1][1] + leaf)
R[i].append(leaf)
if not(R[0][0] <= 1 <= R[0][1]):
print(-1)
exit()
node = 1
ans = 1
for i in range(1, N + 1):
node = min(R[i][1], 2 * (node - R[i-1][2]))
ans += node
print(ans)
|
import sys
input = sys.stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
node_count = [0] * (N+1)
for i, a in enumerate(A[::-1]):
if i == 0:
node_count[N] = a
continue
node_count[N-i] = node_count[N-i+1] + a
can_build = True
for i, a in enumerate(A):
if i == 0:
if N > 0 and a > 0:
can_build = False
break
if N == 0 and a > 1:
can_build = False
break
node_count[0] = min(node_count[0], 1)
continue
if (i < N and a >= node_count[i-1]*2) or (i == N and a > node_count[i-1]*2):
can_build = False
break
node_count[i] = min(node_count[i], node_count[i-1]*2-A[i-1]*2)
if can_build:
ans = sum(node_count)
else:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| 1 | 18,932,535,536,320 | null | 141 | 141 |
def main():
X = int(input())
p, r = divmod(X, 500)
q, r = divmod(r, 5)
print(p * 1000 + q * 5)
if __name__ == '__main__':
main()
|
def main():
N = int(input())
st = [list(input().split()) for i in range(N)]
X = input()
ans = 0
for i in range(N):
if st[i][0] == X:
i += 1
break
for j in range(i,N,1):
ans += int(st[j][1])
return ans
print(main())
| 0 | null | 69,750,935,499,772 | 185 | 243 |
x = list(map(int, input().split()))
h = list(map(int, input().split()))
count = 0
for i in h:
if x[1] <= i:
count += 1
print(count)
|
import bisect
def roller_coaster(n, k, hli):
hli.sort()
lenght = len(hli)
ans = lenght - bisect.bisect_left(hli, k)
return ans
def main():
n, k = map(int, input().split())
hli = list(map(int, input().split()))
print(roller_coaster(n, k, hli))
if __name__ == '__main__':
main()
| 1 | 178,803,171,795,532 | null | 298 | 298 |
values = input()
a, b, c = [int(x) for x in values.split()]
cnt = 0
for i in range(a, b + 1):
if 0 == c % i:
cnt += 1
print(cnt)
|
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
h,n = readInts()
A = [readInts() for _ in range(n)]
dp = [INF] * (h+1)
dp[h] = 0
for idx in range(h,-1,-1):
for i in range(n):
a,b = A[i]
dp[max(0,idx-a)] = min(dp[max(0,idx-a)], dp[idx] + b)
print(dp[0])
| 0 | null | 40,778,557,011,420 | 44 | 229 |
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
import math
#inf = 10**17
#mod = 10**9 + 7
n = input().rstrip()
k = int(input())
ln = len(n)
# dp[i][j]:左からi桁まで見たとき0でない桁がj個ある場合の数
dp1 = [[0]*(k+1) for _ in range(ln+1)]
dp2 = [[0]*(k+1) for _ in range(ln+1)]
dp2[0][0] = 1
cnt = 0
for i in range(ln):
if n[i] != '0':
if cnt < k:
cnt += 1
dp2[i+1][cnt] = 1
else:
dp2[i+1][cnt] = dp2[i][cnt]
for i in range(ln):
dp1[i+1][0] = 1
for j in range(1, k+1):
dp1[i+1][j] += dp1[i][j] + dp1[i][j-1] * 9
if n[i] != '0':
dp1[i+1][j] += dp2[i][j-1] * (int(n[i])-1)
if j < k:
dp1[i+1][j] += dp2[i][j]
print(dp1[-1][k] + dp2[-1][k])
if __name__ == '__main__':
main()
|
h,w,k = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = 0
for row in range(2**h):
for col in range(2**w):
c = 0
for i in range(h):
for j in range(w):
if (row >> i)&1 == 0 and (col >> j)&1 == 0:
if s[i][j]=='#':
c += 1
if c == k:
ans += 1
print(ans)
| 0 | null | 42,647,931,206,720 | 224 | 110 |
from scipy.sparse import*
f=csgraph.johnson
n,m,l,*t=map(int,open(0).read().split())
m*=3
[*map(print,f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1)]
|
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, M, L = map(int, input().split())
dist = [[INF] * N for _ in range(N)]
for i in range(M):
a, b, c = map(int, input().split())
if c > L:
continue
a -= 1
b -= 1
dist[a][b] = c
dist[b][a] = c
Q = int(input())
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
fuel = [[INF] * N for _ in range(N)]
for i in range(N):
for j in range(N):
fuel[i][j] = 1 if dist[i][j] <= L else INF
for k in range(N):
for i in range(N):
for j in range(N):
fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j])
for i in range(Q):
s,t = map(int, input().split())
if fuel[s - 1][t - 1] != INF:
print(fuel[s - 1][t - 1] - 1)
else:
print(-1)
| 1 | 173,323,800,360,018 | null | 295 | 295 |
n = int(input())
a = input().split()
a.reverse()
print(' '.join(a))
|
H,W = map(int, input().split())
S = [input() for _ in range(H)]
inf = 10**6
L = [[inf]*W for _ in range(H)]
if S[0][0] == ".":
L[0][0] = 0
else:
L[0][0] = 1
for i in range(H):
for j in range(W):
n1 = inf
n2 = inf
if i > 0:
if S[i-1][j] == "." and S[i][j] == "#":
n1 = L[i-1][j] + 1
else:
n1 = L[i-1][j]
if j > 0:
if S[i][j-1] == "." and S[i][j] == "#":
n2 = L[i][j-1] + 1
else:
n2 = L[i][j-1]
L[i][j] = min(L[i][j], n1, n2)
print(L[-1][-1])
| 0 | null | 25,136,897,027,438 | 53 | 194 |
#!/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, k = LI()
a = LI()
check_num = [-1] * n
idx = 0
cnt = 1
while 1:
idx = a[idx] - 1
if check_num[idx] != -1:
s = check_num[idx] - 1
cnt -= 1
break
check_num[idx] = cnt
cnt += 1
if cnt >= k:
for i in range(n):
if check_num[i] == k:
print(i+1)
quit()
else:
roop_num = cnt - s
x = (k - (s + 1)) % roop_num
for i in range(n):
if check_num[i] - s - 1 == x:
print(i+1)
quit()
|
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,k=nii()
a=lnii()
x=0
x_list=[1]
x_table=[0 for i in range(n+1)]
x_table[1]=1
for i in range(k):
nx=a[x]
if x_table[nx]!=0:
inx=x_list.index(nx)
loop=x_list[inx:]
zan=k-i
q=zan%len(loop)
nx=loop[q-1]
break
else:
x=nx-1
x_list.append(nx)
x_table[nx]+=1
print(nx)
| 1 | 22,787,520,542,348 | null | 150 | 150 |
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
for i in range(n-k):
if t[k+i] == t[i]:
t[k+i] = 0
x = t.count('r')*p+ t.count('s')*r+t.count('p')*s
print(x)
|
#!/usr/bin/env python3
import collections as cl
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 battle(enemy, r, s, p):
if enemy == "r":
return p
if enemy == "s":
return r
if enemy == "p":
return s
def main():
N, K = MI()
r, s, p = MI()
t = input()
splited_t = [[] for i in range(K)]
for i in range(N):
amari = i % K
splited_t[amari].append(t[i])
ans = 0
for i in range(K):
targets = splited_t[i]
score = battle(targets[0], r, s, p)
ans += score
won = True
for j in range(1, len(targets)):
if targets[j] == targets[j - 1] and won:
won = False
continue
score = battle(targets[j], r, s, p)
won = True
ans += score
print(ans)
main()
| 1 | 106,727,486,841,678 | null | 251 | 251 |
K = int(input())
A, B = map(int, input().split())
if B // K * K >= A:
print('OK')
else:
print('NG')
|
N = int(input())
S = input()
count = 1
check = S[0]
for c in S:
if c != check:
count += 1
check = c
print(count)
| 0 | null | 98,540,798,780,298 | 158 | 293 |
K = int(input())
S = input()
m = 1000000007
result = 0
t = pow(26, K, m)
u = pow(26, m - 2, m) * 25 % m
l = len(S)
for i in range(K + 1):
# result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
result = (result + t) % m
t = (t * u) % m * (l + i) % m * pow(i + 1, m - 2, m) % m
print(result)
|
a, b = map(int, input().split())
x = 300000
y = 200000
z = 100000
A = [x, y, z]
for i in range(1000):
A.append(0)
a_ = A[a-1]
b_ = A[b-1]
if a == 1 and b == 1:
print(a_ + b_ + 400000)
else:
print(a_ + b_)
| 0 | null | 76,741,011,641,852 | 124 | 275 |
x=int(input())
if 29>x>(-40):
print('No')
elif x>=30:
print('Yes')
elif x<-40:
print('No')
else:
print('No')
|
n = list(map(int, list(input())))
k = int(input())
dp = [[0,0,0] for _ in range(len(n))]
counter = 0
for i in range(len(n)):
dp[i][0] += dp[i-1][0] + 9*(counter > 0)
dp[i][1] += dp[i-1][0]*9 + dp[i-1][1]
dp[i][2] += dp[i-1][1]*9 + dp[i-1][2]
if n[i] > 0:
if counter >= 1 and counter <= 3:
dp[i][counter-1] += 1
counter += 1
if counter <= 3:
dp[i][counter-1] += n[i]-1
print(dp[len(n)-1][k-1]+(counter==k))
| 0 | null | 41,053,928,698,240 | 95 | 224 |
N = int(input())
x = input().strip()
cnt = 0
for i in range(N):
if x[i]=="R":
cnt += 1
if cnt==0 or cnt==N:
print(0)
else:
ans = 0
for i in range(cnt):
if x[i]=="W":
ans += 1
print(ans)
|
n = int(input())
c = input()
r = c.count("R")
ans = 0
for i in range(r):
if c[i] == "W": ans += 1
print(ans)
| 1 | 6,272,358,100,700 | null | 98 | 98 |
n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]
mod=998244353
dp=[0]*(n+1)
csum=[0]*(n+2)
dp[0]=1
for i in range(n):
for j in range(k):
l,r=lr[j]
dp[i]+=csum[max(i+1-l,0)]-csum[max(i-r,0)]
dp[i]%=mod
csum[i+1]+=dp[i]+csum[i]
csum[i+1]%=mod
print(dp[n-1])
|
def N():
return int(input())
def L():
return list(map(int,input().split()))
def NL(n):
return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
import numpy as np
#import sympy
import math
md = 998244353
n,k = L()
lr = NL(k)
s = set()
for l,r in lr:
s |= set(range(l,r+1))
dp = [0]*(n+1)
dp[1]=1
#dp[2]=-1
c = [0]*(n+1)
for i in range(1,n+1):
dp[i] = (dp[i]+dp[i-1])%md
for l,r in lr:
if i+l < n+1:
dp[i+l] += dp[i]
dp[i+l] %= md
if i+r+1 < n+1:
dp[i+r+1] -= dp[i]
dp[i+r+1] %= md
print((dp[n] - dp[n-1])%md)
| 1 | 2,727,162,236,890 | null | 74 | 74 |
N,M=map(int,input().split())
x=list(range(1,N+1,1))
if N%2==1:
for i in range(M):
print(x.pop(0),x.pop(-1))
else:
x_f=x[1:int(N/2+1)]
x_l=x[int(N/2+1):]
count=0
for i in range(M):
if len(x_f)>1:
print(x_f.pop(0),x_f.pop(-1))
count+=1
if count==M:
break
if len(x_l)>1:
print(x_l.pop(0),x_l.pop(-1))
count+=1
if count==M:
break
|
n,m = map(int,input().split())
if m%2 == 1:
a = 1
b = a+2*(m//2)+2
for i in range(m//2+1):
print(a,a+2*(m//2-i)+1)
a += 1
for i in range(m//2):
print(b,b+2*(m//2-i))
b += 1
else:
a = 1
b = a+2*(m//2)+1
for i in range(m//2):
print(a,a+2*(m//2-i))
a += 1
for i in range(m//2):
print(b,b+2*(m//2-i-1)+1)
b += 1
| 1 | 28,774,073,973,680 | null | 162 | 162 |
import math
r = input()
print '%.6f' % (r*r*math.pi), '%.6f' % (2*r*math.pi)
|
N = int(input())
A = list(map(int, input().split()))
flag = 1
cnt = 0
while flag:
flag = 0
# ????????????????????????
for j in reversed(range(1, N)):
# 1?????????????´???¨??????
if A[j] < A[j-1]:
# 1???????????????????°????????????°??????
A[j], A[j-1] = A[j-1], A[j]
flag = 1
cnt += 1
print(' '.join(map(str, A)))
print(cnt)
| 0 | null | 326,324,967,900 | 46 | 14 |
def gcd(a,b):
if a%b==0:
return b
else :
return gcd(b,a%b)
def main():
a,b=map(int,raw_input().split())
print(gcd(a,b))
if __name__=='__main__':
main()
|
n,a,b = map(int, input().split())
MOD = 10 ** 9 + 7
def comb(n, k):
nCk = 1
for i in range(n - k + 1, n + 1):
nCk *= i
nCk %= MOD
for i in range(1, k + 1):
nCk *= pow(i, MOD - 2, MOD)
nCk %= MOD
return nCk
print((((pow(2,n,MOD)-1-comb(n,a))%MOD)-comb(n,b))%MOD)
| 0 | null | 32,966,106,160,650 | 11 | 214 |
a = int(input())
x = a
while x%360:
x += a
print(x//a)
|
X = int(input())
K = 1
d = X
while d % 360 != 0:
d += X
K += 1
print(K)
| 1 | 13,149,973,742,876 | null | 125 | 125 |
n = input()
x = map(int, input().split())
y = map(int, input().split())
x_y = [abs(xi - yi) for xi, yi in zip(x, y)]
for p in range(1, 4):
print(sum(i ** p for i in x_y) ** (1 / p))
print(max(x_y))
|
s = input()
p = input()
s = s * 2
for i in range(len(s) - len(p) + 1):
#print(s[i:i + len(p)])
if p == s[i:i + len(p)]:
print("Yes")
exit()
print("No")
| 0 | null | 964,134,973,648 | 32 | 64 |
# -*- coding: utf-8 -*-
import math
def abs(num):
if num < 0:
return -num
else:
return num
def abc163e(n, a):
hap_dict = dict()
hap_list = []
for elem in range(n):
if a[elem] in hap_dict:
hap_dict[a[elem]].append(elem)
else:
tmp_list = [elem]
hap_dict[a[elem]] = tmp_list
hap_list.append(a[elem])
hap_list.sort(reverse=True)
left = 0
right = n-1
num = 0
dp = [[0 for re in range(n+1)] for le in range(n+1)]
for hap in hap_list:
pos_list = hap_dict[hap]
while len(pos_list) != 0:
tgt = pos_list.pop()
num += 1
for left in range(num+1):
right = num-left
if left == num: # left end
dp[left][right] = dp[left-1][right] + hap * abs(tgt-left+1)
elif left == 0: # right end
dp[left][right] = dp[left][right-1] + hap * abs(n-right-tgt)
else:
left_dp = dp[left-1][right] + hap * abs(tgt-left+1)
right_dp = dp[left][right-1] + hap * abs(n-right-tgt)
dp[left][right] = max(left_dp, right_dp)
#print("[",str(left),"][",str(right),"]=",str(dp[left][right]))
ans_list = []
for i in range(num+1):
ans_list.append(dp[i][num-i])
return max(ans_list)
###
# main
if(__name__ == '__main__'):
# input
n = int(input())
a = list(map(int, input().split(" ")))
ans = abc163e(n, a)
# output
print(ans)
# else:
# do nothing
|
n,*a=map(int,open(0).read().split())
dp=[[0]*(n+1)for _ in range(n+1)]
for t,(c,k) in enumerate(sorted((c,k) for k,c in enumerate(a))[::-1]):
for i in range(t+1):
j=t-i
if dp[i+1][j]<dp[i][j]+c*abs(i-k):dp[i+1][j]=dp[i][j]+c*abs(i-k)
if dp[i][j+1]<dp[i][j]+c*abs(n-1-k-j):dp[i][j+1]=dp[i][j]+c*abs(n-1-k-j)
print(max(dp[i][~i]for i in range(n+1)))
| 1 | 33,678,809,313,550 | null | 171 | 171 |
h, n = map(int, input().split())
ab = []
for _ in range(n):
ab.append(map(int, input().split()))
m = 20010
dp = [1000000000] * m
dp[0] = 0
for a, b in ab:
for i in range(m):
if i - a >= 0:
dp[i] = min(dp[i], dp[i - a] + b)
print(min(dp[h:]))
|
n, k = map(int, input().split())
pack = []
for i in range(n):
pack.append(int(input()))
def trucks(p, k):
t = 0
c = 1
for i in range(len(p)):
if p[i] > k:
return 1000000
elif t + p[i] <= k:
t += p[i]
else:
t = p[i]
c += 1
return c
minp = int(sum(pack) / k)
maxp = max(pack) * n
while minp < maxp - 1:
p = int((maxp + minp) / 2)
if trucks(pack, p) <= k:
maxp = p
else:
minp = p
if trucks(pack, maxp - 1) <= k:
print(maxp - 1)
else:
print(maxp)
| 0 | null | 40,341,674,269,316 | 229 | 24 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s = input()
t = input()
cunt=0
for i, ss in enumerate(s):
if ss != t[i]:
cunt+=1
print(cunt)
if __name__=='__main__':
main()
|
number = list(map(int, input().split()))
print(number[0]*number[1])
| 0 | null | 13,140,274,329,952 | 116 | 133 |
A,B,C,D,E=map(int,input().split())
if A==0 :
print(1)
elif B==0:
print(2)
elif C==0:
print(3)
elif D==0:
print(4)
else :
print(5)
|
ans = list(map(int,input().split()))
print(15-sum(ans))
| 1 | 13,422,673,758,300 | null | 126 | 126 |
print('ACL'*int(input()))
|
print(eval("'ACL'*"+input()))
| 1 | 2,178,823,850,320 | null | 69 | 69 |
n = input()
taro = 0
hanako = 0
for i in xrange(n):
t_card, h_card = raw_input().split(" ")
if t_card < h_card:
hanako += 3
elif t_card > h_card:
taro += 3
elif t_card == h_card:
taro += 1
hanako += 1
print taro, hanako
|
#9_C
class player:
def __init__(self):
self.my_cards=[]
self.point=0
def draw(self,letter):
self.my_cards.append(letter)
def open(self,num):
return self.my_cards[num]
def buttle(self,letter,num):
if(self.my_cards[num]>letter):
self.point+=3
elif(self.my_cards[num]==letter):
self.point+=1
def show(self):
return self.point
def check(self):
return self.my_cards
##main##
n=int(input())
taro=player()
hanako=player()
for i in range(n):
val=input().split()
taro.draw(val[0])
hanako.draw(val[1])
for i in range(n):
taro.buttle(hanako.open(i),i)
hanako.buttle(taro.open(i),i)
print(taro.show(),hanako.show())
| 1 | 2,035,002,793,472 | null | 67 | 67 |
while True:
text = input()
if text == '-':
break
count = int(input())
for c in range(count):
index = int(input())
text = text[index:] + text[:index]
print(text)
|
while True:
deck = input()
if deck == "-":
break
m = int(input())
for i in range(m):
h = int(input())
deck += deck[:h]
deck = deck[h:]
print(deck)
| 1 | 1,928,074,645,108 | null | 66 | 66 |
N=int(input())
XY=[[] for _ in range(N)]
for i in range(N):
A=int(input())
for _ in range(A):
x,y = map(int, input().split())
x-=1
XY[i].append([x,y])
ans=0
for bit_state in range(2**N):
flag=True
for i in range(N):
if (bit_state>>i)&1:
for x, y in XY[i]:
if (bit_state >>x)&1 != y:
flag=False
if flag:
ans=max(ans, bin(bit_state).count("1"))
print(ans)
|
N = int(input())
T = []
try:
while True:
t = input()
t=int(t)
T_temp=[]
for t_ in range(t) :
temp = list(map(int,input().split()))
T_temp.append(temp)
T.append(T_temp)
except EOFError:
pass
def check_Contradiction(true_list):
S = {}
for n in range(N):
if n in true_list:
S[n]=set([1])
else:
S[n]=set([0])
for t in true_list:
for T_ in T[t]:
S[T_[0]-1].add(T_[1])
ok=True
for s in S.keys():
if len(S[s])!=1:
ok='False'
break
return ok
ok_max = -1
for i in range(2**N):
# print('=====',i)
true_list=[]
for j in range(N):
if i>>j&1 ==True:
true_list.append(j)
# print(true_list)
# print(check_Contradiction(true_list))
if check_Contradiction(true_list)==True:
if ok_max < len(true_list):
ok_max=len(true_list)
print(ok_max)
| 1 | 121,123,808,650,508 | null | 262 | 262 |
import sys
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()
#import numpy as np
def main():
n=II()
A=LI()
B=[0]*(n+1)
ans=1
B[0]=3
for i in range(n):
ans*=(B[A[i]])-(B[A[i]+1])
ans%=10**9+7
B[A[i]+1]+=1
print(ans)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
ans = 1
d[-1] = 3
for a in A:
ans *= (d[a - 1] - d[a])
ans %= 1000000007
d[a] += 1
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
| 1 | 130,026,656,885,920 | null | 268 | 268 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [-1 for _ in range(N)]
R = [-1 for _ in range(N)]
for i in range(N):
L[i] = A[i] - i-1
R[i] = A[i] + i+1
# L = -R となる物のうち、i>jになりゃいいんだけど、最後にいくつかで破れば良い気がす
# i > 0 なので、自分自身を2回選んでL=Rみたいにはならない・・・?
LC = Counter(L)
RC = Counter(R)
ans = 0
for k,v in LC.items():
if (-1) * k in RC:
ans += v * RC[(-1)*k]
#print(k,v,(-1)*k,RC[(-1)*k], ans)
print(ans)
|
import string
n = int(input())
alphabet = list(string.ascii_lowercase)
ans = ''
while n > 0:
ans = alphabet[(n-1) % 26] + ans
n = (n-1) // 26
print(ans)
| 0 | null | 19,059,382,803,528 | 157 | 121 |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
''' ??????????????? '''
# ????????????????????°?????????N(N-1)/2????????§???
# ?¨???????:O(n^2)
def selection_sort(A, N):
swap_num = 0 # ???????????°
for i in range(N):
minj = i
for j in range(i, N, 1):
if A[j] < A[minj]:
minj = j
# swap
if i != minj:
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
swap_num += 1
return (A, swap_num)
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
# A = [5, 2, 4, 6, 1, 3]
# N = len(A)
array_sorted, swap_num = selection_sort(A, N)
print(' '.join(map(str, array_sorted)))
print(swap_num)
|
input()
num_list = raw_input().split()
num_list = map(int, num_list)
def selection_sort(num_list, count):
for i in range(0, len(num_list)):
minj = i
for j in range(i, len(num_list)):
if num_list[j] < num_list[minj]:
minj = j
temp = num_list[minj]
if minj != i:
num_list[minj] = num_list[i]
num_list[i]= temp
count += 1
i += 1
return count, num_list
count = 0
count, num_list = selection_sort(num_list, count)
num_list = map(str, num_list)
print " ".join(num_list)
print count
| 1 | 20,383,922,552 | null | 15 | 15 |
a, b, c, d= map(int, input().split())
if a <= 0 and b <= 0 and c<= 0 and d<= 0:
print(a * c)
elif a <= 0 and b<= 0 and c > 0 and d > 0:
print(b * c)
elif a > 0 and b > 0 and c <= 0 and d <= 0:
print(a * d)
elif a * c >= b * d:
print(a * c)
elif a * c < b * d:
print(b * d)
|
a, b, c, d = map(int, input().split())
if b >= 0 and d >= 0 and a <= 0 and c <= 0:# - + - +
e = b*d
f = a*c
if e > f:
print(e)
else:
print(f)
elif a >= 0 and b >= 0 and c >= 0 and d >= 0: #+ + + +
print(b*d)
elif a <= 0 and b <= 0 and c <= 0 and d <= 0: #- - - -
print(a*c)
elif a >= 0 and b >= 0 and c <= 0 and d <= 0: #+ + - -
print(a*d)
elif a >= 0 and b >= 0 and c <= 0 and d >= 0: # + + - +
print(b*d)
elif a <= 0 and b <= 0 and c >= 0 and d >= 0: # - - + +
print(b*c)
elif a <= 0 and b <= 0 and c <= 0 and d >= 0: # - - - +
print(a*c)
elif a <= 0 and b >= 0 and c >= 0 and d >= 0: # - + + +
print(b*d)
elif a <= 0 and b >= 0 and c <= 0 and d <= 0: # - + - -
print(a*c)
| 1 | 3,037,970,742,620 | null | 77 | 77 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K = map(int,readline().split())
H = list(map(int,readline().split()))
ans = 0
for h in H:
if h >= K:
ans += 1
print(ans)
|
import collections
import sys
n,q = map(int,input().split())
data = [[i for i in input().split()]for i in range(n)]
time = 0
while data:
task = data[0]
del data[0]
if int(task[1]) <= q:
time += int(task[1])
print(task[0],time)
else:
time += q
task[1] = str(int(task[1]) - q)
data.append(task)
| 0 | null | 89,595,458,478,240 | 298 | 19 |
# -*- coding: utf-8 -*-
def main():
dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
command, key = raw_input().split(' ')
if command == 'insert':
dictionary[key] = True
else:
if key in dictionary:
print 'yes'
else:
print 'no'
counter += 1
if __name__ == '__main__':
main()
|
import sys
n = int(input())
dic = {}
input_ = [x.split() for x in sys.stdin.readlines()]
for c, s in input_:
if c == 'insert':
dic[s] = 0
else:
if s in dic:
print('yes')
else:
print('no')
| 1 | 79,094,711,078 | null | 23 | 23 |
N = int(input())
print('Yes' if N >= 30 else 'No')
|
from sys import stdin
input = stdin.buffer.readline
print('No' if int(input()) < 30 else 'Yes')
| 1 | 5,732,135,577,562 | null | 95 | 95 |
N, M = map(int, input().split())
ans = []
n = M // 2
m = 2 * n + 1
l = 2 * M + 1
for i in range(n):
ans.append([i + 1, m - i])
for i in range(M - n):
ans.append([m + i + 1, l - i])
for v in ans:
print(*v)
|
def resolve():
n, a, b = list(map(int, input().split()))
MOD = 10**9+7
ntoa = 1
ato1 = 1
ntob = 1
bto1 = 1
for i in range(a):
ntoa *= (n-i)
ntoa %= MOD
ato1 *= (a-i)
ato1 %= MOD
for i in range(b):
ntob *= (n-i)
ntob %= MOD
bto1 *= (b-i)
bto1 %= MOD
def pow(x, n, MOD=10**9+7):
ret = 1
while n > 0:
if n & 1:
ret = (ret*x)%MOD
x = (x*x)%MOD
n >>= 1
return ret
nca = ntoa*pow(ato1, MOD-2)%MOD
ncb = ntob*pow(bto1, MOD-2)%MOD
print((pow(2, n)%MOD-1-nca-ncb)%MOD)
if '__main__' == __name__:
resolve()
| 0 | null | 47,285,461,564,980 | 162 | 214 |
turn = int(input())
point_taro = point_hanako = 0
for i in range(turn):
taro,hanako = input().split()
if taro > hanako:
point_taro += 3
elif hanako > taro:
point_hanako += 3
else:
point_taro += 1
point_hanako += 1
print("{} {}".format(point_taro,point_hanako))
|
n=int(input())
score=[0,0,0]
for _ in range(n):
tc,hc=map(str,input().split())
if tc==hc:
score[1]+=1
score[-1]+=1
continue
i=0
ml=min(len(tc),len(hc))
while tc[i]==hc[i]:
i+=1
if i>=ml:
tc+="0"
hc+="0"
break
r=ord(tc[i])-ord(hc[i])
r=r//abs(r)
score[r]+=3
print("{} {}".format(score[1],score[-1]))
| 1 | 1,965,703,398,530 | null | 67 | 67 |
import sys
import numpy as np
import numba
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@jit
def main(n, a):
ans = np.zeros(n)
for i, j in enumerate(a):
ans[j-1] = i+1
for i in ans:
print(int(i), end=' ')
n = int(readline())
a = np.array(readline().split(), np.int64)
main(n,a)
|
print(int(input()) * 'ACL')
| 0 | null | 91,734,869,057,520 | 299 | 69 |
n = int(input())
found = False
for i in range(1, n + 1):
x = int ( i * 1.08 )
if x == n :
print(i)
found = True
break
if not found:
print(":(")
|
n = int(input())
for i in range(1, 50000):
if i * 108 // 100 == n:
print(i)
exit()
print(':(')
| 1 | 125,714,560,594,272 | null | 265 | 265 |
def main():
L, R, d = map(int,input().split())
if L%d==0 and R%d==0:
print(int((R-L)/d) + 1)
return
else:
l = L - L % d
r = R - R % d
print(int((r - l)/d))
return
if __name__=='__main__':
main()
|
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
MOD = 998244353
N, K = map(int, input().split())
S = [0] * K
for i in range(K):
l, r = map(int, input().split())
S[i] = (l, r)
dp = [0] * (N + 2)
acc = [0] * (N + 2)
dp[1] = 1
acc[1] = 1
for i in range(1, N + 1):
for j in range(K):
li = i - S[j][1]
ri = i - S[j][0]
if ri < 0:
continue
li = max(li, 0)
dp[i] += (acc[ri] - acc[li - 1]) % MOD
acc[i] = (acc[i - 1] + dp[i]) % MOD
print(dp[N] % MOD)
| 0 | null | 5,108,837,523,780 | 104 | 74 |
N = int(input())
s = input()
ans = 1
for i in range(1, len(s)):
if s[i-1] != s[i]:
ans += 1
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
kabu = 0
yen = 1000
for i in range(N-1):
if A[i] < A[i+1]:
buy = yen//A[i]
kabu += buy
yen -= buy * A[i]
elif A[i] > A[i+1]:
yen += kabu * A[i]
kabu = 0
if kabu > 0:
yen += A[-1] * kabu
kabu = 0
print(yen)
| 0 | null | 89,048,910,082,260 | 293 | 103 |
x = int(input())
if x <= 599:
print(8,"\n")
elif x <= 799:
print(7,"\n")
elif x <= 999:
print(6,"\n")
elif x <= 1199:
print(5,"\n")
elif x <= 1399:
print(4,"\n")
elif x <= 1599:
print(3,"\n")
elif x <= 1799:
print(2,"\n")
elif x <= 1999:
print(1,"\n")
|
x = int(input())
y = x - 400
print(8 - y//200)
| 1 | 6,728,016,551,928 | null | 100 | 100 |
n, m = map(int, input().split())
def solve(n):
if n == 0:
return 1
return n * solve(n - 1)
if n <= 1:
n_ans = 0
else:
n_ans = solve(n) // (solve(n - 2) * 2)
if m <= 1:
m_ans = 0
else:
m_ans = solve(m) // (solve(m - 2) * 2)
ans = n_ans + m_ans
print(ans)
|
def resolve():
N = int(input())
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
a = prime_factorize(N)
count_dict = {}
total_key = 0
for i in range(1024):
total_key += i
for j in range(total_key-i, total_key):
count_dict[j] = i-1
a_element_counter = {}
for i in a:
if i not in a_element_counter:
a_element_counter[i] = 0
a_element_counter[i] += 1
ans = 0
for e in a_element_counter.values():
ans += count_dict[e]
print(ans)
if __name__ == "__main__":
resolve()
| 0 | null | 31,434,987,369,060 | 189 | 136 |
N=int(input())
resurt=''
for i in range(1,10):
if N%i ==0 and N//i<=9:
result='Yes'
break
else:
result='No'
print(result)
|
N = int(input())
for i in range(10):
if i==0:
continue
else:
i_pair = N / i
if N % i == 0 and i_pair < 10:
print("Yes")
exit()
print("No")
| 1 | 160,103,766,532,512 | null | 287 | 287 |
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)
|
# E - Yutori
N,K,C = map(int,input().split())
S = input()
L = [0]*K
R = [0]*K
i = 0
for j in range(K):
while S[i]!='o':
i += 1
L[j] = i
i += C+1
i = N-1
for j in range(K-1,-1,-1):
while S[i]!='o':
i -= 1
R[j] = i
i -= C+1
for j in range(K):
if L[j]==R[j]:
print(L[j]+1)
| 0 | null | 28,223,177,250,564 | 132 | 182 |
def main():
N = int(input())
S = input()
dict = {'R':0, 'B':0, 'G':0}
for i in range(N):
dict[S[i]] += 1
ans = dict['R']*dict['B']*dict['G']
for i in range(N-2):
if (N-i)%2 == 0:
tmp = int((N-i)/2)-1
else:
tmp = (N-i)//2
for j in range(1,tmp+1):
if S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
ans = ans - 1
return ans
print(main())
|
a, b = int(input()), int(input())
l = [1,2,3]
l.remove(a)
l.remove(b)
print(l[0])
| 0 | null | 73,871,525,547,530 | 175 | 254 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline.rstrip()
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return tuple(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
P = inpl()
Q = inpl()
i = 0
a = 0
b = 0
for p in permutations(range(1,n+1)):
i += 1
if p == P:
a = i
if p == Q:
b = i
print(abs(a-b))
|
import itertools
import math
N = int(input())
M = math.factorial(N)
X = [i for i in range(1, N + 1)]
Y = list(itertools.permutations(X))
P = tuple([int(x) for x in input().split()])
Q = tuple([int(x) for x in input().split()])
for i in range(M):
if Y[i] == P:
a = i
if Y[i] == Q:
b = i
ans = abs(a - b)
print(ans)
| 1 | 100,687,110,382,562 | null | 246 | 246 |
n = input()
s = input()
if n == s[:-1] and len(n) == len(s)-1:
print('Yes')
else :
print('No')
|
import sys
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def MAP(): return map(int, input().split())
inf = sys.maxsize
h, w, k = MAP()
s = [[int(i) for i in STR()] for _ in range(h)]
ans = inf
for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(500)
hdiv = [1 for _ in range(h)]
for j in range(h - 1):
tmp = 2 ** j
hdiv[j] = 1 if i & tmp else 0
sh = sum(hdiv)
tmpans = sh - 1
wdiv = [0 for _ in range(w - 1)]
partsum = [0 for _ in range(sh + 1)]
j = 0
cnt = 0
while j < w: #O(2 * 10 ** 4)
tmp = 0
idx = 0
for kk in range(h): #O(10)
tmp += s[kk][j]
if hdiv[kk]:
partsum[idx] += tmp
tmp = 0
idx += 1
flag = True
for kk in range(sh + 1):
if partsum[kk] > k:
tmpans += 1
partsum = [0 for _ in range(sh + 1)]
flag = False
if flag:
j += 1
cnt = 0
else:
cnt += 1
if cnt > 2:
tmpans = inf
break
ans = min(ans, tmpans)
print(ans)
| 0 | null | 34,820,040,590,480 | 147 | 193 |
MOD = 10 ** 9 + 7
n, k = map(int ,input().split())
mn = 0
mx = 0
for i in range(k):
mn += i
mx += (n-i)
ans = 0
for i in range(k,n+2):
ans += mx - mn + 1
ans %= MOD
mn += i
mx += (n-i)
print(ans)
|
nn, kk = list(map(int,input().split()))
sum = 0
for i in range(kk, nn+2):
min = (0+i-1)*i/2
max = (nn+nn-i+1)*i/2
sum += (max-min)+1
sum = sum % (10**9+7)
print(int(sum))
| 1 | 33,078,996,634,528 | null | 170 | 170 |
N, K = map(int,input().split())
n_mod = N % K
print(min(n_mod, K-n_mod))
|
N,K = map(int, input().split())
N = N%K
while(abs(N-K) < N):
N = abs(N-K)
print(N)
| 1 | 39,342,344,813,798 | null | 180 | 180 |
n = int(input())
a, b = map(list, input().split())
if len(a) == len(b):
for i in range(0, len(a)):
print(a[i] + b[i], end = "")
|
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n = ii()
s,t = input().split()
for i in range(len(s)):
print(s[i] + t[i] ,end = "")
| 1 | 112,570,768,427,934 | null | 255 | 255 |
# -*- coding: utf-8 -*-
a = list(map(int, input().split()))
ans = 0
for i in a:
if i == 1:
ans += 300000
elif i == 2:
ans += 200000
elif i == 3:
ans += 100000
if a[0] == a[1] == 1:
ans += 400000
print(ans)
|
from sys import stdin
cards = {}
n = int(input())
for line in stdin:
m, num = line.rstrip().split(' ')
cards[(m, int(num))] = True
for s in ['S','H','C','D']:
for i in range(1, 14):
if not (s, i) in cards:
print("{} {}".format(s, i))
| 0 | null | 70,789,437,071,218 | 275 | 54 |
N = int(input())
A = list(map(int, input().split()))
if N == 2:
print(max(A[0], A[1]))
exit()
DP = [[- 10 ** 10] * 3 for _ in range(N)]
DP[0][0] = A[0]
DP[1][0] = A[1]
DP[2][0] = A[0] + A[2]
DP[2][1] = A[2]
for i in range(3, N):
DP[i][0] = DP[i - 2][0] + A[i]
DP[i][1] = DP[i - 2][1] + A[i]
DP[i][2] = DP[i - 2][2] + A[i]
if i - 3 >= 0:
DP[i][1] = max(DP[i][1], DP[i - 3][0] + A[i])
DP[i][2] = max(DP[i][2], DP[i - 3][1] + A[i])
if i - 4 >= 0:
DP[i][2] = max(DP[i][2], DP[i - 4][0] + A[i])
ans = 0
if N % 2 == 0:
ans = max(DP[-1][0], DP[-1][1])
ans = max(ans, DP[-2][0])
else:
ans = max(DP[-1][1], DP[-1][2])
ans = max(ans, DP[-2][0])
ans = max(ans, DP[-2][1])
ans = max(ans, DP[-3][0])
print(ans)
|
A, B = list(map(int, input().split()))
x = 1
while True:
a = A * x
if a % B == 0:
print(a)
break
x += 1
| 0 | null | 75,643,981,146,270 | 177 | 256 |
#! /usr/bin/env python3
import sys
import numpy as np
from itertools import groupby
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
S = readline().decode().rstrip()
cnt = [0] * (len(S) + 1)
for i in range(len(S)):
if S[i] == '<':
cnt[i + 1] = max(cnt[i + 1], cnt[i] + 1)
for i in range(len(S) - 1, -1, -1):
if S[i] == '>':
cnt[i] = max(cnt[i], cnt[i + 1] + 1)
print(sum(cnt))
|
n=int(input())
c=0
for i in range(1,n+1):
if i%2!=0:
c+=1
print("{0:.10f}".format(c/n))
| 0 | null | 166,876,231,595,260 | 285 | 297 |
from collections import deque
q = deque()
for i in range(int(input())):
command_line = input().split(" ")
command = command_line[0]
arg = ""
if len(command_line) > 1: arg = command_line[1]
if command == "insert":
q.appendleft(arg)
elif command == "delete":
try:
q.remove(arg)
except ValueError:
pass
elif command == "deleteFirst":
q.popleft()
else:
q.pop()
print(" ".join(q))
|
# -*- coding: utf-8 -*-
from collections import deque
N = int(input())
q = deque()
for i in range(N):
lst = input().split()
command = lst[0]
if command == 'insert':
q.appendleft(lst[1])
elif command == 'delete':
try:
q.remove(lst[1])
except Exception:
pass
elif command == 'deleteFirst':
q.popleft()
elif command == 'deleteLast':
q.pop()
print(*q)
| 1 | 53,463,974,720 | null | 20 | 20 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
a, b, c = map(int, sys.stdin.readline().split())
num_div = 0
for x in range(a, b+1):
if c % x == 0:
num_div += 1
print(num_div)
|
import sys
data = sys.stdin.readline().strip().split(' ')
a = int(data[0])
b = int(data[1])
c = int(data[2])
cnt = 0
for i in range(a, b+1):
if c % i == 0:
cnt += 1
print(cnt)
| 1 | 560,055,415,542 | null | 44 | 44 |
Moji = 'ACL'
K = int(input())
Answer = (Moji * K)
print(Answer)
|
a, b = map(int, input().split())
x = a // 0.08
y = b // 0.10
x, y = int(x), int(y)
minv = min(x, y)
maxv = max(x, y)
ans = []
for i in range(minv, maxv+2):
if int(i * 0.08) == a and int(i * 0.1) == b:
ans.append(i)
if len(ans) == 0:
print(-1)
else:
print(min(ans))
| 0 | null | 29,291,315,627,978 | 69 | 203 |
mod=10**9+7
k=int(input())
s=input()
l=len(s)
fact=[1]
for i in range(1,k+l+1):
fact.append((fact[-1]*i)%mod)
revfact=[]
for i in range(k+l+1):
revfact.append(pow(fact[i],mod-2,mod))
pow1=[1]
pow2=[1]
for i in range(1,k+l+1):
pow1.append((pow1[-1]*25)%mod)
pow2.append((pow2[-1]*26)%mod)
ans=0
for i in range(k+l):
coef1=(pow1[k-i]*pow2[i])%mod
if i<=k:
coef2=(fact[k+l-1-i]*revfact[l-1]*revfact[k-i])%mod
else:
coef2=0
ans+=coef1*coef2
ans%=mod
print(ans)
|
K = int(input())
S = input()
mod = 10**9 + 7
class Combination:
def __init__(self, n):
self.facts = [1 for i in range(n+1)]
self.invs = [1 for i in range(n+1)]
for i in range(1, n+1):
self.facts[i] = self.facts[i-1] * i % mod
self.invs[i] = pow(self.facts[i], mod-2, mod)
def ncr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.facts[n] * self.invs[r] * self.invs[n-r] % mod
def nhr(self, n, r):
if n < r:
return 0
if n < 0 or r < 0:
return 0
else:
return self.ncr(n+r-1, n-1)
N = K+len(S)
comb = Combination(K+len(S))
ans = 0
for i in range(K+1):
ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow(25, N-i-len(S), mod) * pow(26, i, mod)) % mod
print(ans)
| 1 | 12,817,183,717,338 | null | 124 | 124 |
s = input()
li = list(s)
if sum([int(n) for n in li]) % 9 == 0:
print("Yes")
else:
print("No")
|
import sys
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, sys.stdin.readline().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
ars = [0] * N
todo = deque([0])
done = {0}
while todo:
p = todo.popleft()
for np in G[p]:
if np in done:
continue
todo.append(np)
ars[np] = p + 1
done.add(np)
if len(done) == N:
print("Yes")
for i in range(1, N):
print(ars[i])
else:
print("No")
| 0 | null | 12,340,998,591,200 | 87 | 145 |
if(int(input())== 1):
print(0)
exit()
print(1)
|
from collections import defaultdict
N, K, *A = map(int, open(0).read().split())
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = S[i] + A[i]
d = defaultdict(int)
ans = 0
for j in range(N + 1):
v = (S[j] - j) % K
ans += d[v]
d[v] += 1
if j >= K - 1:
d[(S[j - K + 1] - (j - K + 1)) % K] -= 1
print(ans)
| 0 | null | 70,332,354,515,654 | 76 | 273 |
tp,tf,ap,af = map(int,input().split())
from math import ceil
takahashi = ceil(tp/af)
aoki = ceil(ap/tf)
if takahashi >= aoki :
print('Yes')
else :
print('No')
|
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
q = int(input())
dict_A = Counter(A)
sum_list = sum(A)
for i in range(q):
b, c = map(int, input().split())
if b not in dict_A:
print(sum_list)
else:
b_num = dict_A[b]
dict_A[c] += dict_A[b]
dict_A[b] = 0
sum_list = sum_list + (c - b) * b_num
print(sum_list)
| 0 | null | 20,876,592,965,932 | 164 | 122 |
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
def value(v):
cnt = 0
for i in a:
cnt += (i-1)//v
if cnt > k:
return False
else:
return True
def b_search(ok, ng, value):
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if value(mid):
ok = mid
else:
ng = mid
return ok
print(b_search(10**16, 0, value))
main()
|
d,t,s=map(int,input().split())
if(d<=t*s): print("Yes")
else: print("No")
| 0 | null | 4,991,254,463,780 | 99 | 81 |
N, K, C = map(int, input().split())
S = input()
mae = [0] * (2 * N)
ato = [0] * (2 * N)
cnt = 0
n = 0 - N - 100
for i in range(N):
if i - n <= C:
continue
if S[i] == 'o':
mae[cnt] = i
cnt += 1
n = i
cnt = K - 1
n = 2 * N + 100
for i in range(N-1, -1, -1):
if n - i <= C:
continue
if S[i] == 'o':
ato[cnt] = i
cnt -= 1
n = i
for i in range(K):
if mae[i] == ato[i]:
print(mae[i]+1)
|
# 入力
s = str(input())
# 処理
if s == "ABC":
answer = "ARC"
elif s == "ARC":
answer = "ABC"
print(answer)
| 0 | null | 32,323,904,941,318 | 182 | 153 |
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
def main():
num = int(input())
data = list(map(int, input().split()))
now_ind = 1
break_num = 0
for i in range(num):
if data[i] == now_ind:
now_ind += 1
else:
break_num += 1
if break_num == num:
print(-1)
else:
print(break_num)
if __name__ == '__main__':
main()
|
import collections
a=int(input())
b=list(map(int,input().split()))
c=collections.Counter(b)
n,m=zip(*c.most_common())
n,m=list(n),list(m)
o=c.most_common()
result=[0]*a
for i in range(len(o)):
result[o[i][0]-1]=o[i][1]
for i in result:
print(i)
| 0 | null | 73,434,149,210,300 | 257 | 169 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.