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 math
import sys
from collections import Counter
readline = sys.stdin.readline
def main():
n, k = map(int, readline().rstrip().split())
P = sorted(list(map(int, readline().rstrip().split())))
print(sum(P[0: k]))
if __name__ == '__main__':
main()
| n,k = map(int, input().split())
price = list(map(int, input().split()))
count = 0
sum = 0
while count < k:
abc = min(price)
sum += abc
price.pop(price.index(abc))
count += 1
print(sum) | 1 | 11,558,405,473,990 | null | 120 | 120 |
def sell(rate, kabu):
return rate * kabu
def buy(rate, money):
kabu = money//rate
otsuri = money % rate
return kabu, otsuri
N,*A = map(int, open(0).read().split())
money = 1000
have_kabu = 0
for i in range(N):
#売る
money += sell(A[i], have_kabu)
have_kabu = 0
#買う
if i != N-1 and A[i] < A[i+1]:
have_kabu, money = buy(A[i], money)
print(money) | n = int(input())
a = list(map(int,input().split()))
b = [0]*n
for i in range(n-1):
if(a[i] < a[i+1]):
#if(b[i-1] < 1):
b[i] = 1
#else:
# b[i] = 2
if(a[i] > a[i+1]):
#if(b[i-1] > -1):
b[i] = -1
#else:
# b[i] = -2
#else:
#if(b[i-1] > 0):
# b[i] = 2
# else:
# b[i] = -2
b[-1] = -1
#print(b)
h = [1000,0]
for i in range(n):
if(b[i] == 1):
h[1] += h[0]//a[i]
h[0] %= a[i]
elif(b[i] == -1):
h[0] += h[1]*a[i]
h[1] *= 0
#print(h)
print(h[0]) | 1 | 7,292,665,823,592 | null | 103 | 103 |
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(n-k):
if a[i+k] > a[i]:
print("Yes")
else:
print("No") | from typing import List
def count_loadable_baggage_num(baggage_num: int, truck_num: int, baggages: List[int], truck_capacity: int) -> int:
loaded_baggage_num: int = 0
for _ in range(truck_num):
current_weight: int = 0
while current_weight + baggages[loaded_baggage_num] <= truck_capacity:
current_weight += baggages[loaded_baggage_num]
loaded_baggage_num += 1
if loaded_baggage_num == baggage_num:
return baggage_num
return loaded_baggage_num
def calc_turck_min_capacity(baggage_num: int, truck_num: int, baggages: List[int]) -> int:
ng: int = max(baggages) - 1
ok: int = sum(baggages) + 1
while ok - ng > 1:
mid = (ng + ok) // 2
loadable_baggage_num = count_loadable_baggage_num(baggage_num, truck_num, baggages, mid)
if loadable_baggage_num >= baggage_num:
ok = mid
else:
ng = mid
return ok
def main():
n, k = map(int, input().split())
w: List[int] = []
for _ in range(n):
w.append(int(input()))
P = calc_turck_min_capacity(n, k, w)
print(P)
if __name__ == "__main__":
main()
| 0 | null | 3,550,647,005,420 | 102 | 24 |
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
"""
def exhaustive_search(m, i):
if i == n:
return 0
if m < 0:
return 0
if m == A[i]:
return 1
return max(exhaustive_search(m, i + 1), exhaustive_search(m - A[i], i + 1))
"""
def dp_search(m):
dp = [[1] + [0] * m for _ in range(n + 1)] # dp[i][j] i番目まででjを作れるか
for i in range(1, n+1):
for j in range(1, m+1):
if j >= A[i-1]:
dp[i][j] = max(dp[i-1][j], dp[i-1][j - A[i-1]])
else:
dp[i][j] = dp[i-1][j]
return dp[n][m]
for mi in m:
if dp_search(mi):
print("yes")
else:
print("no")
| n=int(input())
A=list(map(int,input().split()))
q=int(input())
M=list(map(int,input().split()))
pattern=[]
for i in range(2**n):
s=0
for j in range(n):
if i >> j & 1:
s+=A[j]
pattern.append(s)
P=set(pattern)
for m in M:
print('yes' if m in P else 'no')
| 1 | 101,226,575,070 | null | 25 | 25 |
x=int(input())
i=0
while (i+1)*100 <= x:
i+=1
nokori = x-i*100
num = ((nokori - 1) // 5) + 1
if num <= i:
print(1)
exit()
print(0) | X=int(input())
maisu_max=X//100
if X<100:
print(0)
exit()
else:
X=str(X)
X=int(X[-2:])
if X==0:
print(1)
exit()
ans=100
for i in range(2):
for j in range(2):
for k in range(2):
for l in range(2):
for m in range(20):
tmp=i+j*2+k*3+l*4+m*5
if tmp==X:
if i+j+k+l+m<ans:
ans=i+j+k+l+m
if maisu_max>=ans:
print(1)
else:
print(0)
| 1 | 126,908,793,695,068 | null | 266 | 266 |
N = int(input())
multiple_list = {i*j for i in range(1,10) for j in range(1,10)}
print(['No','Yes'][N in multiple_list]) | N = int(input())
for i in range(1, 10):
m = N/i
if(m.is_integer() and m <= 9):
print("Yes")
break
else:
print("No")
| 1 | 159,241,536,108,548 | null | 287 | 287 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
def dfs(i):
if 0 <= visited[i]:
return
visited[i] = idx
cycle.append(i)
global csum
csum += C[i]
dfs(P[i])
visited = [-1]*n
idx = 0
cycles = []
for i in range(n):
if 0 <= visited[i]:
continue
cycle = []
csum = 0
dfs(i)
cycles.append((cycle, csum))
idx += 1
INF = 10**18
ans = -INF
for i in range(n):
cycle, csum = cycles[visited[i]]
cmem = len(cycle)
if 0 < csum:
a, b = divmod(k, cmem)
scoreA = csum*(a-1)
b += cmem
score = 0
scoreB = 0
for _ in range(b):
i = P[i]
score += C[i]
if scoreB < score:
scoreB = score
X = scoreA+scoreB
else:
b = min(k, cmem)
score = 0
INF = 10**18
X = -INF
for _ in range(b):
i = P[i]
score += C[i]
if X < score:
X = score
if ans < X:
ans = X
print(ans)
| h = int(input())
w = int(input())
n = int(input())
print(int((n-1)/max(h, w))+1) | 0 | null | 47,157,491,967,084 | 93 | 236 |
S = input()
N = len(S)
ans = 0
for i in range(N//2):
if S[i] != S[N-i-1]: ans += 1
print(ans) | S = input()
N = len(S)
if N % 2 == 0:
tmp = N // 2
else:
tmp = (N + 1) // 2
ans = 0
for i in range(tmp, N):
if S[i] != S[N - i - 1]:
ans += 1
print(ans)
| 1 | 120,256,737,885,592 | null | 261 | 261 |
n=int(input())
for m in range(1,n+1):
if int(m*1.08)==n:
print(m)
break
else:print(":(")
| n = int(input())
s = list(input())
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r * g * b
for i in range(n-2):
for j in range(i+1,n-1):
if (j - i) + j < n:
k = (j - i) + j
if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
ans -= 1
print(ans) | 0 | null | 80,929,938,399,268 | 265 | 175 |
h,a=map(int,input().split())
for i in range(1,10001):
if a*i >= h:
print(i)
break | h,a = map(int,input().split())
print(-1*(h//(-1*a))) | 1 | 77,146,776,175,712 | null | 225 | 225 |
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
s = S()
ans = not(len(set(list(s)))==1)
print("Yes" if ans else "No")
main()
| s=list(input())
a=list(set(s))
print('Yes') if 'A' in a and 'B' in a else print('No') | 1 | 54,805,879,677,858 | null | 201 | 201 |
k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print k[input()-1] | # A - Kth Term
def main():
orig = "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"
seq = list(map(lambda s: s.strip(), orig.split(",")))
K = int(input()) - 1
print(seq[K])
if __name__ == "__main__":
main()
| 1 | 49,940,549,553,748 | null | 195 | 195 |
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)) | import sys
def readint():
for line in sys.stdin:
yield map(int,line.split())
def gcd(x,y):
[x,y] = [max(x,y),min(x,y)]
while 1:
z = x % y
if z == 0:
break
[x,y] = [y,z]
return y
for [x,y] in readint():
GCD = gcd(x,y)
mx = x/GCD
print GCD,mx*y | 0 | null | 26,654,045,120 | 20 | 5 |
data = [int(i) for i in input().split()]
if data[0] < data[1]:
print('a < b')
elif data[0] > data[1]:
print('a > b')
else:
print('a == b')
| a,b = map(int,input().split())
if a<b:
print("a < b")
elif a==b:
print("a == b")
elif a>b:
print("a > b")
| 1 | 357,517,024,028 | null | 38 | 38 |
class Combination:
def __init__(self, n_max, mod=10 ** 9 + 7):
# O(n_max + log(mod))
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max + 1):
f = f * i % mod
fac.append(f)
f = pow(f, mod - 2, mod)
self.facinv = facinv = [f]
for i in range(n_max, 0, -1):
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def nCr(self, n, r):
if not 0 <= r <= n:
return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def resolve():
# 各集合Sのmax(S) - min(S)の合計を求める
# 各A[i]が最大値になる回数、最小値になる回数を求め、それを計算する
MOD = 10**9+7
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
Comb = Combination(N)
ans = 0
for i in range(N):
# 最大値になる組み合わせは、A[j]: 0 < j < iからK - 1個を選ぶ組み合わせ
ans += Comb.nCr(i, K-1) * A[i] % MOD
ans %= MOD
# 最小値になる組み合わせは、A[j]: i < j < nからK-1個を選ぶ組み合わせ
ans -= Comb.nCr(N-i-1, K - 1) * A[i]% MOD
ans %= MOD
print(ans)
if __name__ == "__main__":
resolve()
| #comb_mod(n, r, mod) = nCr % mod
def comb_mod(n, r, mod):
ans = 1
if r <= n/2:
for i in range(n-r+1, n+1):
ans *= i
ans %= mod
for i in range(1, r+1):
ans *= pow(i, mod-2, mod)
ans %= mod
else:
for i in range(r+1, n+1):
ans *= i
ans %= mod
for i in range(1, n-r+1):
ans *= pow(i, mod-2, mod)
ans %= mod
return ans
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
pattern = comb_mod(n-1, k-1, 10**9+7)
for i in range(n-k+1):
ans += (a[-(i+1)] - a[i]) * pattern
pattern *= (n-k-i) * pow(n-1-i, 10**9+5, 10**9+7)
pattern %= 10**9 + 7
print(ans % (10**9+7)) | 1 | 96,072,077,966,300 | null | 242 | 242 |
import math
def prime(x):
for i in range(2, int(math.sqrt(x))+1):
if x % i == 0:
return False
return True
n = int(raw_input())
a = []
for i in range(n):
a.append(int(raw_input()))
num = 0
for i in range(n):
if prime(a[i]):
num += 1
print num | def composite(d,n,s):
for a in (2,3,5,7):
probably_prime = False
if pow(a,d,n) == 1:
continue
for i in range(s):
if pow(a, 2**i * d, n) == n-1:
probably_prime = True
break
return not probably_prime
return False
def is_prime(n):
if n == 2:
return True
elif n % 2 == 0:
return False
else:
d,s = n-1, 0
while not d%2:
d, s = d>>1, s+1
return not composite(d,n,s)
r = []
n = int(input())
for i in range(n):
n = int(input())
if is_prime(n):
if n not in r:
r.append(n)
print(len(r)) | 1 | 11,041,339,812 | null | 12 | 12 |
n, xs = int(input()), map(int,raw_input().split())
print min(xs), max(xs), sum(xs) | a = []
for i in range(0,2):
a.append(input())
d = list(map(int,a[1].split()))
print('{} {} {}'.format(min(d),max(d),sum(d))) | 1 | 729,985,417,076 | null | 48 | 48 |
n = int(input())
L = list(map(int, input().split()))
a = L[0]
b = 0
for i in range(n-1):
if L[i+1] < a:
b = b + (a - L[i+1])
else:
a = L[i+1]
print(b) | def roundone(a, b):
abc = "123"
return abc.replace(a, "").replace(b, "")
def main():
a = str(input())
b = str(input())
print(roundone(a, b))
if __name__ == '__main__':
main() | 0 | null | 57,865,397,937,230 | 88 | 254 |
s = list(str(input()))
q = int(input())
o = ['']*q
for i in range(q):
o[i] = str(input())
for i in range(q):
order = o[i].split(' ')
if order[0] == 'print':
a,b = int(order[1]),int(order[2])
for i in range(a,b+1):
print(s[i],end = '')
print('')
elif order[0] == 'reverse':
a,b = int(order[1]),int(order[2])
tmp = s[a:b+1]
tmp.reverse()
s[a:b+1] = tmp
elif order[0] == 'replace':
a,b,p = int(order[1]),int(order[2]),list(order[3])
for i in range(b-a+1):
s[a+i] = p[i] | sum = 0
num = [0] * (10 ** 5 + 1)
N = int(input())
A = [int(a) for a in input().split()]
for i in range(0, N):
sum += A[i]
num[A[i]] += 1
Q = int(input())
for i in range(0, Q):
B, C = (int(x) for x in input().split())
sum += (C - B) * num[B]
num[C] += num[B]
num[B] = 0
print(sum) | 0 | null | 7,092,191,946,938 | 68 | 122 |
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, a, b = MI()
d = b - a
ans = 0
if d%2:
temp = min(a-1, n-b)
ans = (d-1)//2 + temp + 1
else:
ans = d//2
print(ans)
if __name__ == '__main__':
main() | import sys
def input(): return sys.stdin.readline().strip()
def resolve():
n,a,b=map(int, input().split())
if (abs(a-b))%2==0:
print((abs(a-b))//2)
else:
ue=max(a,b)-1
sita=n-min(a,b)
hokasita=((n-max(a,b))*2+1+abs(b-a))//2
hokaue=(((min(a,b))-1)*2+1+abs(b-a))//2
print(min(ue,sita,hokasita,hokaue))
resolve()
| 1 | 109,376,447,334,210 | null | 253 | 253 |
import math
def main(n: int, x: int, t: int):
print(math.ceil(n / x) * t)
if __name__ == '__main__':
n, x, t = map(int, input().split())
main(n, x, t)
| S = int(input())
q , mod = divmod(S , 2)
print(q+mod) | 0 | null | 31,617,065,935,872 | 86 | 206 |
print "\n".join(['%dx%d=%d'%(x,y,x*y) for x in range(1,10) for y in range(1,10)]) | r=range(1,10)
[print('%dx%d=%d'%(i,j,i*j))for i in r for j in r]
| 1 | 208,472 | null | 1 | 1 |
from math import gcd
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
def main():
N,*ab = map(int, read().split())
ab_zero = 0
ratio = []
for a, b in zip(*[iter(ab)]*2):
if a == 0 and b == 0:
ab_zero += 1
else:
if b < 0:
a, b = -a, -b
if b == 0:
a = 1
g = gcd(a, b)
a //= g
b //= g
ratio.append((a, b))
s = Counter(ratio)
bad = 1
no_pair = 0
for k, v in s.items():
a, b = k
if a > 0:
if (-b, a) in s:
bad *= pow(2, v, MOD) + pow(2, s[(-b, a)], MOD) -1
bad %= MOD
else:
no_pair += v
elif (b, -a) not in s:
no_pair += v
bad *= pow(2, no_pair, MOD)
bad %= MOD
ans = (bad + ab_zero -1) % MOD
print(ans)
if __name__ == "__main__":
main()
| def main():
from collections import defaultdict
from math import gcd
import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero_zero += 1
elif a == 0:
zero += 1
elif b == 0:
inf += 1
else:
div = gcd(a, b)
a //= div
b //= div
if b < 0:
a *= -1
b *= -1
key = (a, b)
fishes[key] += 1
def get_bad_pair(fish):
a, b = fish
if a < 0:
a *= -1
b *= -1
return (-b, a)
ans = 1
counted_key = set()
for fish_key, count in fishes.items():
if fish_key in counted_key:
continue
bad_pair = get_bad_pair(fish_key)
if bad_pair in fishes:
pair_count = fishes[bad_pair]
pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
counted_key.add(bad_pair)
else:
pattern = pow(2, count, mod)
ans = ans * pattern % mod
ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
ans += zero_zero
ans -= 1
print(ans % mod)
if __name__ == "__main__":
main()
| 1 | 20,992,575,592,420 | null | 146 | 146 |
'''
Created on 2020/08/29
@author: harurun
'''
def main():
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
A,B,N=map(int,pin().split())
x=min(B-1,N)
ans=int(A*x/B)-A*int(x/B)
print(ans)
return
main()
#解説AC | a,b,c=map(int,input().split())
if a>c:
print(a-c,b)
elif a<=c and b<=(c-a):
print(0,0)
else:
print(0,b-(c-a)) | 0 | null | 66,441,476,210,720 | 161 | 249 |
A, B = map(int,input().split())
for i in range(max(A,B),0,-1):
if A%i==0 and B%i==0:
print(A*B//i)
break | import itertools
N, M, Q = map(int, input().split())
l = [i for i in range(1, M+1)]
qus = []
As = []
for _ in range(Q):
b = list(map(int, input().split()))
qus.append(b)
for v in itertools.combinations_with_replacement(l, N):
a = list(v)
A = 0
for q in qus:
pre = a[q[1]-1] - a[q[0]-1]
if pre == q[2]:
A += q[3]
As.append(A)
print(max(As)) | 0 | null | 70,291,353,431,740 | 256 | 160 |
def main():
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
ptn = len(c)
last = [0]*ptn
res = 0
for i in range(d):
sel = t[i] - 1
last[sel] = i+1
mns = 0
for j in range(ptn):
mns += c[j] * (i+1 - last[j])
res += s[i][sel] - mns
print(res)
if __name__ == '__main__':
main()
| N = 26
D = int(input())
c_list = list(map(int, input().split()))
s_table = []
for _ in range(D):
s_table.append(list(map(int, input().split())))
data = []
for _ in range(D):
data.append(int(input()) - 1)
def calc(data):
last = [-1] * N
satisfaction = 0
for i in range(D):
j = data[i]
satisfaction += s_table[i][j]
last[j] = i
for k in range(N):
satisfaction -= c_list[k] * (i - last[k])
print(satisfaction)
return satisfaction
calc(data)
| 1 | 9,848,579,283,708 | null | 114 | 114 |
N,K = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
plist = P[0:K]
a = 0
for p in plist:
a+=p
print(a) | s = list(input())
count = len(s)
for i in range(count):
s[i] = "x"
changed = "".join(s)
print(changed) | 0 | null | 42,487,287,909,668 | 120 | 221 |
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
good = [1]*N
for k in range(M):
A, B = map(int, input().split())
if H[A - 1] >= H[B - 1]:
good[B - 1] = 0
if H[A - 1] <= H[B - 1]:
good[A - 1] = 0
print(sum(good))
| n,m = map(int,input().split())
h = list(map(int,input().split()))
h.insert(0,0)
good = [0] + [1] * n
for i in range(m):
x,y = map(int,input().split())
if h[x] > h[y]:
good[y] = 0
elif h[x] < h[y]:
good[x] = 0
else:
good[x] = 0
good[y] = 0
print(sum(good))
| 1 | 24,971,307,741,732 | null | 155 | 155 |
import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N = int(readline())
if N % 2 == 1:
print(0)
else:
count2 = 0
count5 = 0
compare = 1
while N >= compare * 2:
compare *= 2
count2 += N // compare
compare = 1
N //= 2
while N >= compare * 5:
compare *= 5
count5 += N // compare
ans = min(count2, count5)
print(ans)
if __name__ == '__main__':
solve() | N=int(input());a=10;b=0
if N&1==0:
while a<=N:b+=N//a;a*=5
print(b) | 1 | 115,790,965,668,098 | null | 258 | 258 |
f = [0 for i in range(0, 10001)]
for x in range(1,100):
for y in range(1,100):
for z in range(1,100):
n = x**2 + y**2 + z**2 + x*y + y*z + z*x
if n <= 10000:
f[n] += 1
N = int(input())
for n in range(1, N+1):
print(f[n]) | ri = lambda S: [int(v) for v in S.split()]
N, A, B = ri(input())
q, r = divmod(N, A+B)
blue = (A * q) + r if r <= A else (A * q) + A
print(blue) | 0 | null | 31,649,762,256,898 | 106 | 202 |
N = int(input())
table = sorted(list(map(int, input().split())), reverse=True)
ans = table[0]
rst = N - 2
for ti in table[1:]:
if rst == 0:
break
if rst == 1:
ans = ans + ti
break
ans = ans + 2 * ti
rst = rst - 2
print(ans)
| i = str(input())
w =''
for let in i:
if(let == let.upper()):
w = w + let.lower()
elif(let == let.lower()):
w = w + let.upper()
else:
w = w + let
print(w)
| 0 | null | 5,331,422,566,812 | 111 | 61 |
def getval():
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [A[0]]
b = [B[0]]
for i in range(0,n-1):
a.append(a[i]+A[i+1])
for i in range(0,m-1):
b.append(b[i]+B[i+1])
return n,m,k,a,b
def main(n,m,k,a,b):
idxa = 0
ans = 0
t = 0
while a[idxa]<=k and idxa<n:
idxa += 1
if idxa==n:
break
ans = idxa
idxa -= 1
t = a[idxa]
for i in range(m):
t = a[idxa] + b[i]
if t<=k:
ans = max(ans,idxa+i+2)
else:
flag = False
while t>k:
idxa -= 1
if idxa<0:
a.append(0)
break
t = a[idxa]+b[i]
ans = max(ans,idxa+i+2)
print(ans)
if __name__=="__main__":
n,m,k,a,b = getval()
main(n,m,k,a,b) | def abc172c_tsundoku():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0] * (n + 1)
B = [0] * (m + 1)
for i in range(1, n + 1):
A[i] = A[i - 1] + a[i - 1]
if A[i] > k:
n = i - 1
break
for i in range(1, m + 1):
B[i] = B[i - 1] + b[i - 1]
if B[i] > k:
m = i - 1
break
ans = 0
for i in range(0, n + 1):
j = max(ans - i, 0)
if j > m or A[i] + B[j] > k: continue
while j <= m:
if A[i] + B[j] > k:
j -= 1
break
j += 1
j = min(m,j)
ans = max(i + j, ans)
print(ans)
abc172c_tsundoku() | 1 | 10,681,243,092,192 | null | 117 | 117 |
import math
A,B,H,M = map(int,input().split())
V1 = 30
V2 = 30/60
v = 6
d = abs( (V1*H + V2*M) - v*M)
if d == 0:
print(abs(A-B))
else:
print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(math.radians(d)))) | N = int(input())
S = list(input())
print("".join(chr(65+(ord(s)-65+N)%26) for s in S)) | 0 | null | 77,249,429,619,872 | 144 | 271 |
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
print(-(-(b - a) // 2))
else:
print(min(a - 1 + -(-(b - a + 1) // 2), n - b + -(-(b - a) // 2))) | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
MOD = 10 ** 4 + 7
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A - 1, N - B) + 1 + (B - A - 1) // 2) | 1 | 109,117,344,527,490 | null | 253 | 253 |
k=int(input())
a=7%k
for i in range(k+1):
if a==0:
print(i+1)
break
a=(a*10+7)%k
else:
print(-1) | n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
s = min(k, n)
if s:
answer = sum(h[:-s])
else:
answer = sum(h)
print(answer)
| 0 | null | 42,490,598,314,200 | 97 | 227 |
# -*- coding: utf-8 -*-
import math
x = int(input())
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return True
return False
while is_prime(x):
x += 1
print(x)
| import sys, math
for line in sys.stdin:
print int(math.log10(sum(map(int, line.split())))) + 1 | 0 | null | 52,763,943,355,162 | 250 | 3 |
i=1
k=1
for k in range(1,10):
for i in range(1,10):
print(str(k)+"x"+str(i)+"="+str(k*i)) | a = [i for i in range(1,10)]
for b in a:
for c in a:
print('{}x{}={}'.format(b,c,b*c))
| 1 | 312,898 | null | 1 | 1 |
N = int(input()) #入力する整数
A = list(map(int,input().split())) #入力する数列A
SUMA = sum(A) #数列の和
MOD = 10**9 + 7 # mod
C = [0] * (N-1) #累積和数列
for i in range(N-1): #\sum_{j = i+1}^{N}を求めて数列に代入する
SUMA -= A[i]
C[i] = SUMA
ans = 0 #求める答え
for i in range(N-1):
ans += A[i]*C[i]
ans %= MOD #その都度modで割った余りにする
print(ans) #答えを出力する | from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n = readInt()
a = readInts()
v = sum(a)/2
t = 0
for i in range(len(a)):
t+=a[i]
if t>v:
break
z1 = sum(a[:i])
k1 = sum(a[i:])
z2 = sum(a[:i+1])
k2 = sum(a[i+1:])
if abs(z1-k1)<abs(z2-k2):
z = z1
k = k1
else:
z = z2
k = k2
print(abs(z-k))
| 0 | null | 72,695,321,494,080 | 83 | 276 |
H,A = map(int,input().split())
cnt = 0
while(True) :
H = H - A
cnt += 1
if H <= 0 :
break
print(cnt) | a,b,c = [int(s) for s in input().split(" ")]
if a < b and b < c:
print("Yes")
else:
print("No") | 0 | null | 38,774,177,061,532 | 225 | 39 |
n = int(input())
l = list(map(int, input().split()))
w = list(set(l))
r = {w[i]:0 for i in range(len(w))}
for i in range(n):
r[l[i]] += 1
t = list(r.items())
ans = 0
for i in range(len(t)-2):
for j in range(i+1, len(t)-1):
for k in range(j+1, len(t)):
y = sum([t[i][0], t[j][0], t[k][0]])
x = max([t[i][0], t[j][0], t[k][0]])
if 2*x < y:
ans += t[i][1] * t[j][1] * t[k][1]
print(ans) | import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
n = readint()
mod = 10**9+7
print((pow(10,n,mod)-pow(9,n,mod)*2+pow(8,n,mod)+mod*2)%mod)
| 0 | null | 4,058,262,322,170 | 91 | 78 |
n = int(input())
x = list(map(int, input().split()))
result = 0
for i in range(n - 1):
if x[i] > x[i + 1]:
result += (x[i] - x[i + 1])
x[i + 1] = x[i]
print(result) | n = int(input())
aas = list(map(int, input().split()))
res = 0
pre = aas[0]
for i in range(1,len(aas)):
if pre > aas[i]:
res += pre - aas[i]
else:
pre = aas[i]
print(res) | 1 | 4,523,019,664,768 | null | 88 | 88 |
while True:
s = input().rstrip().split(" ")
h=int(s[0])
w=int(s[1])
if (h == 0) & (w == 0):
break
for i in range(h):
print("#"*w)
print() | import numpy as np
import numpy.linalg as linalg
X, Y = map(int, input().split())
if Y%2 == 1:
print('No')
else:
A = np.array([[1, 1],
[2, 4]])
A_inv = linalg.inv(A)
B = np.array([X , Y])
C = np.dot(A_inv, B)
if C[0] >= 0 and C[1] >= 0 :
print('Yes')
else:
print('No')
| 0 | null | 7,307,177,179,240 | 49 | 127 |
s, t = input().split()
a, b = map(int, input().split())
u = input()
if s == u:
a -= 1
else:
b -= 1
print('{} {}'.format(a, b)) | a,b=map(int, raw_input().split())
d=a/b
e=a%b
print ('%d %d %f' % (a/b,a%b,float(a)/b)) | 0 | null | 36,352,876,006,500 | 220 | 45 |
while True:
[n, m] = [int(x) for x in raw_input().split()]
if [n, m] == [0, 0]:
break
data = []
for x in range(n, 2, -1):
for y in range(x - 1, 1, -1):
for z in range(y - 1, 0, -1):
s = x + y + z
if s < m:
break
if s == m:
data.append(s)
print(len(data)) | n, m, l = list(map(int, input().split()))
a = [[int(j) for j in input().split()] for i in range(n)]
b = [[int(j) for j in input().split()] for i in range(m)]
c = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
for j in range(l):
value = 0
for k in range(m):
value = value + a[i][k] * b[k][j]
c[i][j] = value
for i in c:
print(*i)
| 0 | null | 1,367,136,753,970 | 58 | 60 |
N = int(input())
def calc(start, end):
n = end // start
return (n * (n+1) // 2) * start
ans = 0
for i in range(1, N+1):
ans += calc(i, N//i * i)
print(ans) | import fractions
a, b = map(int, input().split())
print(int(a*b / fractions.gcd(a,b)))
| 0 | null | 62,404,732,724,688 | 118 | 256 |
X = input()
ans = "1"
if int(X) < 100:
ans = "0"
elif not int(X[:-2])*5 >= int(X[-2:]):
ans = "0"
print(ans)
| x = int(open(0).read().split()[0])
import heapq
s = {0}
hq = [0]
prices = list(range(100, 106))
tmp = 0
while tmp<x:
tmp = heapq.heappop(hq)
for price in prices:
new = tmp+price
if new not in s:
s.add(new)
heapq.heappush(hq, new)
print(int(tmp == x)) | 1 | 127,478,030,849,078 | null | 266 | 266 |
a=int(input())
print(-(-a//2)) | import math
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
n, m = map(int, input().split())
if n < 2:
even = 0
else:
even = combinations_count(n, 2)
if m < 2:
odd = 0
else:
odd = combinations_count(m, 2)
print(even + odd)
if __name__ == "__main__":
main()
| 0 | null | 52,322,084,551,880 | 206 | 189 |
# Binary Search
def isOK(i, key):
'''
問題に応じて返り値を設定
'''
cnt = 0
for v in a:
cnt += (v + i - 1) // i - 1
return cnt <= key
def binary_search(key):
'''
条件を満たす最小/最大のindexを求める
O(logN)
'''
ok = 10 ** 9 # 条件を満たすindexの上限値/下限値
ng = 0 # 条件を満たさないindexの下限値-1/上限値+1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid, key): # midが条件を満たすか否か
ok = mid
else:
ng = mid
return ok
n, k = map(int, input().split())
a = list(map(int, input().split()))
print(binary_search(k)) | n,k,*a = map(int,open(0).read().split())
def func(b):
c = k
for i in a:
c -= (i-1)//b
if c < 0:
return False
return True
l = 1
r = max(a)
while(r>l):
lr = (l+r)//2
if func(lr):
r = lr
else:
l = lr + 1
print(r) | 1 | 6,485,574,261,502 | null | 99 | 99 |
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [int(input()) - 1 for _ in range(D)]
def cal_score():
S = 0
last = [-1] * 26
score = 0
for d in range(D):
S += s[d][t[d]]
last[t[d]] = d
for i in range(26):
S -= c[i] * (d - last[i])
score += max(10 ** 6 + S, 0)
print(S)
if __name__ == "__main__":
cal_score() | import itertools
n_even, n_odd = map(int, input().split())
# 偶数になるのは、(偶数+偶数) と (奇数+奇数)
count1 = len(list(itertools.combinations(range(n_even), r=2)))
count2 = len(list(itertools.combinations(range(n_odd), r=2)))
print(count1 + count2)
| 0 | null | 27,687,537,792,996 | 114 | 189 |
d,t,s = input().split()
d,t,s=int(d),int(t),int(s)
if t>=(d/s):
print("Yes")
else:
print("No")
| N=int(input())
MOD=10**9+7
in_9=10**N-9**N
in_0=10**N-9**N
nine_and_zero=10**N-8**N
ans=int(int(in_0+in_9-nine_and_zero)%MOD)
print(ans) | 0 | null | 3,408,869,154,820 | 81 | 78 |
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
#約数列挙
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
ans=set(make_divisors(N-1))
ans=ans - set([1])
ans.add(2)
L=make_divisors(N)
for i in range(1,len(L)):
temp=L[i]
N2=N
while N2>=temp:
if N2%temp==0:
N2=N2//temp
else:
N2=N2%temp
if N2==1:
ans.add(temp)
print(len(ans))
main()
| def main():
c = ord(input())
print(chr(c+1))
main()
| 0 | null | 66,599,978,100,496 | 183 | 239 |
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
max_a = max(a)
mod = 10**9 + 7
inverse = [1] * (max_a + 1)
for i in range(2, max_a + 1):
inverse[i] = -inverse[mod % i] * (mod // i) % mod
lcm = 1
for i in range(n):
lcm = lcm * a[i] // gcd(lcm, a[i])
lcm %= mod
sum_b = 0
for i in range(n):
sum_b = (sum_b + lcm * inverse[a[i]]) % mod
print(sum_b) | from functools import reduce
from fractions import gcd
from collections import defaultdict,Counter
import copy
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
dic = defaultdict(int)
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
for i in a:
c = Counter(prime_factorize(i))
for j,k in c.items():
if dic[j] < k:
dic[j] = k
l = 1
for i,j in dic.items():
l *= pow(i,j,mod)
l %= mod
point = 0
for i in a:
point += l*pow(i,mod-2,mod)
point %= mod
print(point%mod) | 1 | 87,929,224,431,020 | null | 235 | 235 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k-1, n-1):
print("Yes" if a[i+1] > a[i-k+1] else "No") | import sys
import math
lines = sys.stdin.readlines()
# print(lines)
n = int(lines[0].rstrip())
heights = [int(x) for x in lines[1].rstrip().split()]
# print(heights)
tot = 0
for i in range(n-1):
if heights[i] <= heights[i+1]:
continue
else:
diff = heights[i] - heights[i+1]
heights[i+1] += diff
tot += diff
print(tot) | 0 | null | 5,772,256,785,678 | 102 | 88 |
N,M,K=map(int,input().split())
mod=998244353
fact=[1 for i in range(N+1)]
for i in range(1,N):
fact[i+1]=(fact[i]*(i+1))%mod
def nCk(n,k):
return fact[n]*pow(fact[n-k]*fact[k],mod-2,mod)
result=0
for k in range(K+1):
result+=nCk(N-1,k)*M*pow(M-1,N-k-1,mod)
result=int(result)%mod
print(result) | import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 998244353
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
res = [1]
for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
return res
N,M,K=LI()
FACT=FLIST(N+M+1)
FINV=[]
for i in FACT: FINV.append(INV(i))
if N == 1:
print(M)
exit()
if M == 1:
if N - 1 == K: print(M)
else: print(0)
exit()
res = 0
def ncr(n, r):
res = 1
res *= FACT[n]
res *= FINV[n-r]
res %= DVSR
res *= FINV[r]
res %= DVSR
return res
for k in range(K+1):
v = ncr(N-1, k)*M
v %= DVSR
v *= POW(M-1, N-1-k)
v %= DVSR
res += v
print(res%DVSR)
| 1 | 23,250,797,222,924 | null | 151 | 151 |
import math
n=int(input())
print( (pow(10,n)-pow(9,n)*2+pow(8,n))%1000000007)
| mod = 1000000007
n = int(input())
ans = pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod)
print(ans % mod)
| 1 | 3,131,936,724,550 | null | 78 | 78 |
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
sum_res = sum(A)
counter = [0 for _ in range(10 ** 5 + 1)]
for a in A:
counter[a] += 1
for _ in range(Q):
B, C = map(int, input().split())
sum_res = sum_res - (counter[B] * B)
sum_res = sum_res + (counter[B] * C)
counter[C] += counter[B]
counter[B] = 0
print(sum_res)
| N = int(input())
A = list(map(int,input().split()))
a = {}
for i in A:
if i in a:
a[i] += 1
else:
a[i] = 1
Q = int(input())
ans = sum(A)
for i in range(Q):
B,C = map(int,input().split())
if B in a:
ans += (C-B) * a[B]
if C in a:
a[C] += a[B]
else:
a[C] = a[B]
a[B] = 0
print(ans) | 1 | 12,229,221,259,168 | null | 122 | 122 |
if __name__ == "__main__":
a, b, c = map( int, input().split() )
if a < b < c:
print("Yes")
else:
print("No") | import itertools
n_even, n_odd = map(int, input().split())
# nC2 なので、combinations使わなくてもいいと思う
count1 = n_even * (n_even - 1) // 2
count2 = n_odd * (n_odd - 1) // 2
print(count1 + count2)
# itertools.combinations を使ってもOK
count1 = len(list(itertools.combinations(range(n_even), r=2)))
count2 = len(list(itertools.combinations(range(n_odd), r=2)))
| 0 | null | 22,981,558,110,402 | 39 | 189 |
from sys import stdin
stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]
a.reverse()
print(*a)
| import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
mat = [[0]*W for i in range(H)]
for i in range(K):
r, c, v = map(int, input().split())
r, c = r-1, c-1
mat[r][c] = v
dp0 = [[-1 for i in range(W)] for i in range(H)]
dp1 = [[-1 for i in range(W)] for i in range(H)]
dp2 = [[-1 for i in range(W)] for i in range(H)]
dp3 = [[-1 for i in range(W)] for i in range(H)]
dp0[0][0] = 0
if mat[0][0] != 0:
dp1[0][0] = mat[0][0]
for i in range(H):
for j in range(W):
m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])
if i+1 < H:
dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j])
dp0[i+1][j] = max(dp0[i+1][j], m)
if j+1 < W:
dp0[i][j+1] = 0
dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1])
dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1])
dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1])
print(max(dp0[H-1][W-1], dp1[H-1][W-1], dp2[H-1][W-1], dp3[H-1][W-1]))
| 0 | null | 3,288,279,000,004 | 53 | 94 |
N=int(input())
S=list(input())
if N%2==1:
print("No")
else:
n=int(N/2)
if S[0:n]==S[n:N]:
print("Yes")
else:
print("No")
| n=int(input())
s=input()
if n%2==1:
print("No")
exit()
half=n//2
if s[:half]==s[half:]:
print("Yes")
else:
print("No")
| 1 | 147,193,902,230,748 | null | 279 | 279 |
if input() == '0':
print(1)
else:
print(0) | # URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
print(int(input()) ^ 1)
| 1 | 2,947,163,231,672 | null | 76 | 76 |
S = input(str(""))
if 3 <= len(S) <= 20:
print(S[:3].lower())
| name = str(input())
print(name[0:3])
| 1 | 14,792,152,593,390 | null | 130 | 130 |
x = raw_input()
print int(x) ** 3 | def cube(x):
return x**3
def main():
x = int(input())
ans = cube(x)
print(ans)
if __name__=='__main__':
main() | 1 | 276,013,000,380 | null | 35 | 35 |
n, m, K = map(int, input().split())
mod = 998244353
fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
fac[j] = fac[j - 1] * j % mod
inv[n] = pow(fac[n], mod - 2, mod)
for j in range(n - 1, -1, -1):
inv[j] = inv[j + 1] * (j + 1) % mod
def comb(n, r):
if r > n or n < 0 or r < 0:
return 0
return fac[n] * inv[n - r] * inv[r] % mod
def paint(k):
res = (m * comb(n-1, k)) % mod * pow(m-1, n-1-k, mod)
res %= mod
return res
ans = 0
for k in range(K+1):
ans += paint(k)
ans %= mod
print(ans) | import sys, math, itertools
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 998244353
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def factorialMod(n, p):
fact = [0] * (n+1)
fact[0] = fact[1] = 1
factinv = [0] * (n+1)
factinv[0] = factinv[1] = 1
inv = [0] * (n+1)
inv[1] = 1
for i in range(2, n + 1):
fact[i] = (fact[i-1] * i) % p
inv[i] = (-inv[p % i] * (p // i)) % p
factinv[i] = (factinv[i-1] * inv[i]) % p
return fact, factinv
def combMod(n, r, fact, factinv, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
def resolve():
N, M, K = LI()
ans = 0
fact, factinv = factorialMod(N, MOD)
for i in range(K + 1):
ans += combMod(N - 1, i, fact, factinv, MOD) * M * pow(M - 1, N - 1 - i, MOD)
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
| 1 | 22,979,261,854,130 | null | 151 | 151 |
n = int(input())
ai = list(map(int, input().split()))
# n=3
# ai = np.array([1, 2, 3])
# ai = ai[np.newaxis, :]
#
# ai2 = ai.T.dot(ai)
# ai2u = np.triu(ai2, k=1)
#
# s = ai2u.sum()
l = len(ai)
integ = [ai[0]] * len(ai)
for i in range(1, len(ai)):
integ[i] = integ[i-1] + ai[i]
s = 0
for j in range(l):
this_s = integ[-1] - integ[j]
s += ai[j] * this_s
ans = s % (1000000000 + 7)
print(ans)
| n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
def cumsum(num, lst):
cumsumlst = [0] * num
for hoge in range(1, n):
cumsumlst[hoge] = (cumsumlst[hoge-1] + lst[hoge]) % mod
return cumsumlst
lst = cumsum(n, a)
ans = 0
for i in range(n-1):
ans += (a[i] * (lst[n-1] - lst[i])) % mod
ans %= mod
print(ans) | 1 | 3,822,984,231,928 | null | 83 | 83 |
import sys
def input(): return sys.stdin.readline().rstrip()
class UnionFind():
def __init__(self, n):
self.n=n
self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
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 unite(self,x,y):
#要素x,yのグループを併合
x,y=self.find(x),self.find(y)
if x==y:return
if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
x,y=y,x
self.parents[x]+=self.parents[y]
self.parents[y]=x #要素数が大きい方に併合
def size(self,x):
#xが属するグループの要素数
return -self.parents[self.find(x)]
def same(self,x,y):
#xとyが同じグループ?
return self.find(x)==self.find(y)
def members(self,x):
#xと同じグループに属する要素のリスト
root=self.find(x)
return [i for i in range(self.n) if self.find(i)==root]
def roots(self):
#全ての根の要素のリスト
return [i for i, x in enumerate(self.parents) if x<0]
def all_group_members(self):
#各ルート要素のグループに含まれる要素のリストの辞書
return {r: self.members(r) for r in self.roots()}
def all_group_members_list(self):
#各ルート要素のグループに含まれる要素のリストのリスト
#[[0, 2], [1, 3, 4, 5]]
return list(self.all_group_members().values())
def main():
n, m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int,input().split())
a -= 1
b -= 1
uf.unite(a, b)
uf_lis = uf.parents
ans = 0
for p in uf_lis:
if p < 0:
ans = max(ans, -p)
print(ans)
if __name__=='__main__':
main() | def gcd(a, b):
if b == 0: return a
else: return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
while True:
try:
a, b = map(int, input().split())
print(int(gcd(a, b)), int(lcm(a, b)))
except EOFError:
break | 0 | null | 1,985,559,556,080 | 84 | 5 |
x=int(input())
print(x*x) | import sys
r = int(sys.stdin.readline().rstrip())
def main():
print(r ** 2)
if __name__ == '__main__':
main() | 1 | 144,851,389,662,240 | null | 278 | 278 |
import itertools
N=int(input())
L=list(map(int,input().split()))
c=0
if len(L) >=3:
for v in itertools.combinations(L, 3):
if (v[0] != v[1] and v[1] != v[2]) and v[0] != v[2]:
if sorted(v)[-2]+min(v) > max(v):
c=c+1
else:
c=c
else:
c=c
else:
c=0
print(c) | N,X,Y=map(int,input().split())
#i<X<Y<j
#このときはX->を通るほうが良い
#X<=i<j<=Y
#このときはループのどちらかを通れば良い
#X<=i<=Y<j
#このときはiとYの最短距離+Yとjの最短距離
#i<X<=j<=Y
#同上
#i<j<X
#パスは1通りしか無い
def dist(i,j):
if i>j:
return dist(j,i)
if i==j:
return 0
if i<X:
if j<X:
return j-i
if X<=j and j<=Y:
return min(j-i,(X-i)+1+(Y-j))
if Y<j:
return (X-i)+1+(j-Y)
if X<=i and i<=Y:
if j<=Y:
return min(j-i,(i-X)+1+(Y-j))
if Y<j:
return min((i-X)+1+(j-Y),j-i)
if Y<i:
return (j-i)
ans=[0 for i in range(N)]
for i in range(1,N+1):
for j in range(i+1,N+1):
ans[dist(i,j)]+=1
for k in range(1,N):
print(ans[k]) | 0 | null | 24,420,024,978,592 | 91 | 187 |
N=input()
N=N[::-1]+"0"
ans=0
up=0
for i,n in enumerate(N):
d=int(n)+up
if d>5 or (d==5 and i<len(N)-1 and int(N[i+1])>=5):
ans+=(10-d)
up=1
else:
ans+=d
up=0
print(ans) | n = list(map(int, list(input())))
ln = len(n)
ans = 0
for i in range(-1, -ln, -1):
if n[i] == 10:
n[i-1] += 1
continue
elif n[i] < 5:
ans += n[i]
elif n[i] > 5:
ans += 10 - n[i]
n[i-1] += 1
else:
if n[i-1] < 5:
ans += 5
else:
ans += 5
n[i-1] += 1
if n[0] == 10:
ans += 1
elif n[0] <= 5:
ans += n[0]
else:
ans += 11 - n[0]
print(ans) | 1 | 70,533,160,571,858 | null | 219 | 219 |
a = list(input().split())
n = len(a)
s = []
for i in a:
if i=="+":
a = s.pop()
b = s.pop()
s.append(b + a)
elif i=="-":
a = s.pop()
b = s.pop()
s.append(b - a)
elif i=="*":
a = s.pop()
b = s.pop()
s.append(b * a)
else:
s.append(int(i))
print(s[0]) | X,K,D=list(map(int,input().split()))
X=abs(X)
import sys
if X > 0 and X-K*D>=0:
print(X-K*D)
sys.exit()
M=X//D
Q=X%D
if M%2 == K%2:
print(Q)
else:
print(D-Q)
| 0 | null | 2,655,663,919,168 | 18 | 92 |
import sys
S = input()
if S == "ABC":
print("ARC")
sys.exit()
else:
print("ABC")
sys.exit()
| n, k = map(int, input().split())
m = 0
while True:
m += 1
if k**m > n:
print(m)
break | 0 | null | 44,347,442,549,218 | 153 | 212 |
S = int(input())
h = S//3600
m = (S%3600)//60
s = S%60
print(h,":",m,":",s,sep='')
| S = int(input())
S = S % (24 * 3600)
hour = S // 3600
S %= 3600
minutes = S // 60
S %= 60
seconds = S
print("%d:%d:%d" % (hour, minutes, seconds))
| 1 | 329,424,038,748 | null | 37 | 37 |
from itertools import accumulate
from bisect import bisect
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
if a[i] > k:
break
ans = max(ans, i+bisect(b, k-a[i])-1)
print(ans) | class Node:
def __init__(self,key):
self.key = key
self.prev = None
self.next = None
class DoublyLinkedList:
def __init__(self):
self.nil = Node(None)
self.nil.prev = self.nil
self.nil.next = self.nil
def insert(self,key):
new = Node(key)
new.next = self.nil.next
self.nil.next.prev = new
self.nil.next = new
new.prev = self.nil
def listSearch(self,key):
cur = self.nil.next
while cur != self.nil and cur.key != key:
cur = cur.next
return cur
def deleteNode(self, t):
if t == self.nil:
return
t.prev.next = t.next
t.next.prev = t.prev
def deleteFirst(self):
self.deleteNode(self.nil.next)
def deleteLast(self):
self.deleteNode(self.nil.prev)
def deleteKey(self, key):
self.deleteNode(self.listSearch(key))
if __name__ == '__main__':
import sys
input = sys.stdin.readline
n = int(input())
d = DoublyLinkedList()
for _ in range(n):
c = input().rstrip()
if c[0] == "i":
d.insert(c[7:])
elif c[6] == "F":
d.deleteFirst()
elif c[6] =="L":
d.deleteLast()
else:
d.deleteKey(c[7:])
ans = []
cur = d.nil.next
while cur != d.nil:
ans.append(cur.key)
cur = cur.next
print(" ".join(ans))
| 0 | null | 5,338,338,056,240 | 117 | 20 |
a,b,k = map(int,input().split())
if a < k:
print(max(0,a-k),max(0,b+a-k))
else:
print(max(0,a-k),b)
| def bubble_sort(A):
count = 0
for i in range(len(A)):
for j in range(len(A)-1):
if A[j+1] < A[j]:
A[j+1], A[j] = A[j], A[j+1]
count += 1
return count
n = int(input())
A = list(map(int, input().split()))
count = bubble_sort(A)
print(*A)
print(count)
| 0 | null | 52,158,529,893,042 | 249 | 14 |
num = list(map(int,input().split()))
sum = 500*num[0]
if num[1] <= sum:
print("Yes")
else:
print("No") | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
K, X = map(int, readline().split())
if 500 * K >= X:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
| 1 | 97,987,815,804,560 | null | 244 | 244 |
n = int(input())
M = int(n**(0.5))
ans = [0]*(n+1)
for x in range(1,M+1):
for y in range(1,10**2):
for z in range(1,10**2):
if x**2+y**2+z**2+x*y+y*z+z*x > n:
break
ans[x**2+y**2+z**2+x*y+y*z+z*x] += 1
if x**2+y**2 > n:
break
for i in range(n):
print(ans[i+1]) | N = int(input())
lis = [0]*N
for x in range(1, 100):
for y in range(1, 100):
for z in range(1, 100):
ans = x**2 + y**2 + z**2 + x*y + y*z + z*x -1
if ans >= N:
pass
else:
lis[ans] += 1
for i in range(N):
print(lis[i]) | 1 | 7,948,780,773,120 | null | 106 | 106 |
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
INF=10**9+7
l=[0]*k
ans=0
for i in range(k-1,-1,-1):
x=i+1
temp=pow(k//x,n,INF)
for j in range(2,k//x+1):
temp=(temp-l[j*x-1])%INF
l[i]=temp
ans=(ans+x*temp)%INF
print(ans)
| import math
def pow(p,n):
bin_n=bin(n)[2:][::-1]
tmp=p;pn=1
for i in range(len(bin_n)):
if bin_n[i]=="1": pn=(pn*tmp)%mod
tmp=tmp*tmp%mod
return pn
mod=10**9+7
n,k=map(int,input().split())
ans=[0]*(k+1)
for i in range(k,0,-1):
div=set()
for x in range(1,int(i**0.5)+1):
if i%x==0: div.add(x);div.add(i//x)
ans[i]=pow(k//i,n)-sum([ans[j*i] for j in range(k//i,1,-1)])
ans[i]%=mod
print(sum(ans[i]*i for i in range(k+1))%mod) | 1 | 36,772,855,255,570 | null | 176 | 176 |
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
MAX = float('inf')
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L, R = [0] * (n1 + 1), [0] * (n2 + 1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = float('INF')
R[n2] = float('INF')
i, j = 0, 0
compare_cnt = 0
for k in range(left, right):
compare_cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return compare_cnt
def merge_sort(A, left, right):
cnt = 0
if left + 1 < right:
mid = (left + right) // 2
cnt += merge_sort(A, left, mid)
cnt += merge_sort(A, mid, right)
cnt += merge(A, left, mid, right)
return cnt
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
A = il()
cnt = merge_sort(A, 0, N)
print(*A)
print(cnt)
if __name__ == '__main__':
main()
| def merge(a, left, mid, right):
INF = int(1e+11)
l = a[left:mid]
r = a[mid:right]
l.append(INF)
r.append(INF)
i = 0
j = 0
ans = 0
for k in range(left, right):
ans += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
return ans
def merge_sort(a, left, right):
ans = 0
if left + 1 < right:
mid = (left + right) // 2
ans += merge_sort(a, left, mid)
ans += merge_sort(a, mid, right)
ans += merge(a, left, mid, right)
return ans
def print_list_split_whitespace(s):
for x in s[:-1]:
print(x, end=" ")
print(s[-1])
n = int(input())
s = [int(x) for x in input().split()]
ans = merge_sort(s, 0, len(s))
print_list_split_whitespace(s)
print(ans)
| 1 | 113,645,511,408 | null | 26 | 26 |
s = input()
n = int(input())
for i in range(n):
command = input().split()
if command[0] == 'replace':
a,b = map(int,command[1:3])
s = s[:a]+ command[3] + s[b+1:]
elif command[0] == 'reverse':
a,b = map(int,command[1:3])
s = s[0:a] + s[a:b+1][::-1] + s[b+1:]
elif command[0] == 'print':
a,b = map(int,command[1:3])
print(s[a:b+1])
| h, w, k = map(int, input().split())
s = []
for _ in range(h):
s.append(input())
cnt = 1
rflg = False
rcnt = 1
for r in s:
if r.count('#')>0:
if rflg:
cnt += 1
rcnt = 1
rflg = True
elif rflg:
print(*ans)
continue
else:
rcnt += 1
continue
cflg = False
ans = []
for e in r:
if e=='#':
if cflg:
cnt += 1
cflg = True
ans.append(cnt)
for _ in range(rcnt):
print(*ans) | 0 | null | 73,178,737,635,578 | 68 | 277 |
# ABC158
# D - String Formation
from collections import deque
def ChangeState(Is_normal):
if Is_normal==True:
return False
else:
return True
S=deque(input().split())
Q=int(input())
Is_normal=True
for _ in range(Q):
q = input()
if len(q)== 1 :
Is_normal = ChangeState(Is_normal)
else:
if q[2]=='1':
if Is_normal==True:
# S=q[4]+S
S.appendleft(q[4])
else :
# S=S+q[4]
S.append(q[4])
else :
if Is_normal==True:
# S=S+q[4]
S.append(q[4])
else:
# S=q[4]+S
S.appendleft(q[4])
# print(Is_normal, S)
S=''.join(S)
if Is_normal==False:
S=S[::-1]
print(S)
| import sys
from math import gcd
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
A = list(map(int, input().split()))
nowgcd = A[0]
# 全体のGCDを取る
for i in A:
nowgcd = gcd(nowgcd, i)
if nowgcd != 1:
print('not coprime')
exit()
# osa_k法で前処理
MAXN = 10**6 + 5
sieve = [i for i in range(MAXN + 1)]
p = 2
while p * p <= MAXN:
# まだチェックされていないなら
if sieve[p] == p:
# 次のqの倍数からp刻みでチェック入れていく
for q in range(2 * p, MAXN + 1, p):
if sieve[q] == q:
sieve[q] = p
p += 1
check = set()
for a in A:
tmp = set()
while (a > 1):
tmp.add(sieve[a])
a //= sieve[a]
for p in tmp:
if p in check:
print('setwise coprime')
exit()
check.add(p)
print('pairwise coprime')
| 0 | null | 30,684,631,775,980 | 204 | 85 |
_ = input()
a = list(input())
cnt = 0
word = 0
for i in a:
if word == 0 and i == 'A':
word = 1
elif word == 1 and i =='B':
word = 2
elif word == 2 and i =='C':
word = 0
cnt += 1
else:
if i == 'A':
word = 1
else:
word = 0
print(cnt) | n=int(input())
s=str(input())
print(s.count("ABC")) | 1 | 99,031,549,186,570 | null | 245 | 245 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #
n, a, b = Is()
if (a + b) % 2 == 0:
print((b-a)//2)
else:
print(min(n-b, a-1)+1+(b-a-1)//2)
| N = int(input())
for i in range(1,10):
for j in range(1,10):
if i * j == N:
print("Yes")
exit(0)
else:
print("No") | 0 | null | 135,030,949,883,136 | 253 | 287 |
class SegmentTree():
"""A segment Tree.
This is a segment tree without recursions.
This can support queries as follows:
- update a single value in O(logN).
- get the folded value of values in a segment [l, r) in O(logN)
N is the length of the given iterable value.
Parameters
----------
iterable : Iterable[_T]
An iterable value which will be converted into a segment tree
func : Callable[[_T, _T], _T]
A binary function which returns the same type as given two.
This has to satisfy the associative law:
func(a, func(b, c)) = func(func(a, b), c)
e : _T
The identity element of the given func.
In other words, this satisfies:
func(x, e) = func(e, x) = x
"""
def __init__(self, iterable, func, e):
self.func = func
self.e = e
ls = list(iterable)
self.n = 1 << len(ls).bit_length()
ls.extend( [self.e] * (self.n - len(ls)) )
self.data = [self.e] * self.n + ls
for i in range(self.n-1, 0, -1):
self.data[i] = self.func(self.data[2*i], self.data[2*i+1])
def replace(self, index, value):
"""replace the old value of the given index with the given new value.
This replaces the old value of the given index with the given new value in O(logN).
This is like "list[index] = value".
Parameters
----------
index : int
The index of the value which will be replaced.
value : _T
The new value with which the old value will be replaced.
"""
index += self.n
self.data[index] = value
index //= 2
while index > 0:
self.data[index] = self.func(self.data[2*index], self.data[2*index+1])
index //= 2
def folded(self, l, r):
"""get the folded value of values in a segment [l, r).
This get the folded value of values in a segment [l, r) in O(logN).
If func is add, it returns the sum of values in [l, r).
In other words, this is eqivalent to "sum(list[l:r])".
If func is other functions, then this is equivalent to "accumulate(list[l:r], func)".
Parameters
----------
l : int
The left edge.
r : int
The right edge.
Returns
-------
_T(the same type as the type of the element of the given iterable)
This is equivalent to func(list[l], func(list[l+1], ... ) ).
If func is represented as '*', then it's:
list[l] * list[l+1] * ... * list[r-1]
"""
left_folded = self.e
right_folded = self.e
l += self.n
r += self.n
while l < r:
if l % 2:
left_folded = self.func(left_folded, self.data[l])
l += 1
if r % 2:
r -= 1
right_folded = self.func(self.data[r], right_folded)
l //= 2
r //= 2
return self.func(left_folded, right_folded)
from operator import or_
N = int(input())
S = input()
ls = [1 << (ord(c) - ord('a')) for c in S]
segtree = SegmentTree(ls, or_, 0)
Q = int(input())
for _ in range(Q):
s = input()
if s[0] == '1':
i, c = s[2:].split()
segtree.replace(int(i)-1, 1 << (ord(c) - ord('a')))
else:
l, r = map(int, s[2:].split())
value = segtree.folded(l-1, r)
print(format(value, 'b').count('1'))
| N, *A = map(int, open(0).read().split())
mod = 10**9 + 7
batch = 8
rg = tuple(range((63//batch)+1))
mask = (1<<batch) - 1
B = [[0]*(1<<batch) for _ in rg]
for a in A:
for i in rg:
B[i][a & mask] += 1
a >>= batch
xr = [[] for _ in [0]*(1<<batch)]
for i in range(1<<batch):
for j in range(i+1, 1<<batch):
xr[i].append(i^j)
ans = 0
shift = 1
for b in B:
x = sum(xr[i][j]*bi*bj for i, bi in enumerate(b) for j, bj in enumerate(b[i+1:]))
x %= mod
x *= shift
x %= mod
shift <<= batch
shift %= mod
ans += x
ans %= mod
print(ans) | 0 | null | 92,677,691,126,212 | 210 | 263 |
N = int(input())
P = list(map(int,input().split()))
n = float("INF")
count = 0
for i in P:
if n >= i:
n = i
count += 1
print(count) | n=int(input())
a=list(map(int,input().split()))
ans=0
t=10**6
for i in range(n):
if a[i]<t:
ans+=1
t=a[i]
print(ans) | 1 | 85,618,120,926,752 | null | 233 | 233 |
n, t = map(int, input().split())
lst = [0 for _ in range(t)]
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a, b in ab:
ans = max(ans, lst[-1] + b)
for i in range(t - 1, a - 1, -1):
lst[i] = max(lst[i], lst[i - a] + b)
print(ans) | #!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def main():
N,T = map(int,input().split())
AB = [(0,0)] + [tuple(map(int,input().split())) for _ in range(N)]
# 最後に食べるものを全探索し, それ以外でDPしたくなる
# 普通にやると TLE だが, 左から,右から で事前にDPしておくことで計算量を落とせる
# このとき, 配列添字を 1〜N にしておくと楽
# 1番目の料理を最後に食べるとき : dp1[0][] + b + dp2[2][], このときに index out of range しないのが嬉しい
# 2番目の料理を最後に食べるとき : dp1[1][] + b + dp2[3][]
# ...
# N番目の料理を最後に食べるとき : dp1[N-1][] + b + dp2[N+1][], dp2 は N+2 の長さがあると良さそう
# dp1[i][j] : 1〜i 番目の料理から選んで T 分以内に食べるときの美味しさの和の最大値
dp1 = [[0 for _ in range(T+1)] for _ in range(N+1)]
for i in range(1,N+1):
a,b = AB[i]
for j in range(T+1):
# 食べる
if j >= a:
dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-a] + b)
# 食べない
else:
dp1[i][j] = dp1[i-1][j]
# dp2[i][j] : i〜N 番目の料理から選んで T 分以内に食べるときの美味しさの和の最大値
dp2 = [[0 for _ in range(T+1)] for _ in range(N+2)]
for i in range(N,0,-1):
a,b = AB[i]
for j in range(T+1):
# 食べる
if j >= a:
dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-a] + b)
# 食べない
else:
dp2[i][j] = dp2[i+1][j]
# 最後に食べる料理で全探索
ans = 0
for i in range(1,N+1):
a,b = AB[i]
for j in range(T):
ans = max(ans, dp1[i-1][j] + b + dp2[i+1][T-1-j])
print(ans)
if __name__ == "__main__":
main() | 1 | 151,460,284,036,712 | null | 282 | 282 |
n,k=map(int,input().split())
p=list(map(int,input().split()))
dp=[0]*(n-k+1)
dp[0]=sum(p[:k])
for i in range(n-k):
dp[i+1]=dp[i]+p[k+i]-p[i]
print((max(dp)+k)/2) | n = int(input())
titles = []
times = []
for i in range(n):
title,m = input().split()
titles.append(title)
times.append(int(m))
print(sum(times[titles.index(input())+1:])) | 0 | null | 85,788,228,654,090 | 223 | 243 |
x = int(input())
cx = int(x/100)
dx = x%100
while cx>0:
cx-=1
if dx>5:
dx-=5
else:
print(1)
exit()
print(0)
| def main():
a = int(input())
print(a + a**2 + a**3)
if __name__ == '__main__':
main() | 0 | null | 69,004,443,616,262 | 266 | 115 |
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
bc=[]
for i in range(q):
bc.append([int(x) for x in input().split()])
a_cnt=[0]*(10**5+1)
for i in range(len(a)):
a_cnt[a[i]]+=1
a_goukei=sum(a)
for gyou in range(q):
a_goukei+=(bc[gyou][1]-bc[gyou][0])*a_cnt[bc[gyou][0]]
print(a_goukei)
a_cnt[bc[gyou][1]]+=a_cnt[bc[gyou][0]]
a_cnt[bc[gyou][0]]=0 | n=int(input())
A=list(map(int,input().split()) )
q=int(input())
B=[]
C=[]
a_sum = sum(A)
counter = [0]*10**5
for a in A:
counter[a-1] += 1
for i in range(q):
b,c = map(int,input().split())
a_sum += (c-b) * counter[b-1]
counter[c-1]+=counter[b-1]
counter[b-1]=0
print(a_sum)
| 1 | 12,189,320,347,124 | null | 122 | 122 |
N, K = map(int, input().split())
count = 0
while N != 0:
N //= K
count += 1
print(count)
| input_line = input()
a,b = input_line.strip().split(' ')
a = int(a)
b = int(b)
if a < b:
print("a < b")
elif a > b:
print("a > b")
elif a == b:
print("a == b") | 0 | null | 32,358,928,123,650 | 212 | 38 |
def main():
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
"""
ruiseki = [1]
for i in range(n):
ruiseki.append(ruiseki[-1]*a[i])
#ruiseki.pop(0)
ans = [ruiseki[k]/ruiseki[0]]
for i in range(k+1,n+1):
tmp = ruiseki[i]/ruiseki[i-k]
if ans[-1] >= tmp:
print('No')
else:
print('Yes')
ans.append(tmp)
"""
for i in range(k,n):
if a[i]>a[i-k]:
print('Yes')
else:
print('No')
main() | N,M,K=list(map(int,input().split()))
root=[i for i in range(N)]
height=[1 for i in range(N)]
l=[set() for i in range(N)]
mem=[0]*N
def find(n):
f=n
while n != root[n]:
n=root[n]
root[f]=n
return n
def union(a,b):
A=find(a)
B=find(b)
if A==B:
return
elif height[A]<height[B]:
height[B]+=height[A]
height[A]=0
root[A]=B
else:
root[B]=A
height[A]+=height[B]
height[B]=0
def same(a,b):
A=find(a)
B=find(b)
if A==B:
l[a].add(b)
l[b].add(a)
for i in range(M):
a,b=list(map(int,input().split()))
a-=1;b-=1
l[a].add(b)
l[b].add(a)
union(a,b)
for j in range(K):
a,b=list(map(int,input().split()))
a-=1;b-=1
same(a,b)
for i in range(N):
print(height[find(i)]-len(l[i])-1,end=" ")
| 0 | null | 34,239,952,948,830 | 102 | 209 |
from collections import defaultdict as dd
N = int(input())
graph = dd(list)
seen = dd(int)
u = []
d, f = dd(int), dd(int)
ts = 1
for _ in range(N):
info = list(map(int, input().split()))
u.append(info[0])
graph[info[0]] = info[2:]
def dfs(v):
global ts
d[v] = ts
ts += 1
seen[v] = 1
for next_v in graph[v]:
if seen[next_v]:
continue
dfs(next_v)
f[v] = ts
ts += 1
for key in u:
if seen[key]:
continue
dfs(key)
for id in u:
print("{} {} {}".format(id, d[id], f[id]))
| d = {}
m = [[False]*3 for _ in range(3)]
for i in range(3):
for j, val in enumerate(list(map(int,input().split()))):
d[val] = (i,j)
N = int(input())
for _ in range(N):
key = int(input())
if key in d:
i,j = d[key]
m[i][j] = True
def main():
if m[0][0] and m[1][1] and m[2][2]:
return True
if m[0][2] and m[1][1] and m[2][0]:
return True
for i in range(3):
if m[i][0] and m[i][1] and m[i][2]:
return True
if m[0][i] and m[1][i] and m[2][i]:
return True
return False
ans = main()
if ans:
print("Yes")
else:
print("No") | 0 | null | 29,769,384,880,610 | 8 | 207 |
n, x, m = map(int, input().split())
a = []
check = [-1] * m
i = 0
while check[x] == -1:
a.append(x)
check[x] = i
x = x * x % m
i += 1
if n <= i:
print(sum(a[:n]))
else:
print(
sum(a[:check[x]])
+ (n - check[x]) // (i - check[x]) * sum(a[check[x]:])
+ sum(a[check[x] : check[x] + (n - check[x]) % (i - check[x])])) | n, x, m = map(int, input().split())
ans = 0
prev_set = set()
prev_list = list()
ans_hist = list()
r = x
for i in range(n):
if i == 0:
pass
else:
r = (r * r) % m
if r == 0:
break
if r in prev_set:
index = prev_list.index(r)
period = i - index
count = (n - index) // period
rest = (n - index) % period
ans = sum(prev_list[:index])
ans += sum(prev_list[index:i]) * count
# ans += (ans - ans_hist[index - 1]) * (count - 1)
ans += sum(prev_list[index:index+rest])
# ans += (ans_hist[index + rest - 1] - ans_hist[index - 1])
break
else:
ans += r
prev_set.add(r)
prev_list.append(r)
ans_hist.append(ans)
print(ans)
| 1 | 2,862,492,623,562 | null | 75 | 75 |
import collections
n = int(input())
adj_list = []
for _ in range(n):
adj = list(map(int, input().split(" ")))
adj_list.append([c - 1 for c in adj[2:]])
distances = [-1 for _ in range(n)]
queue = collections.deque()
queue.append(0)
distances[0] = 0
while queue:
p = queue.popleft()
for next_p in adj_list[p]:
if distances[next_p] == -1:
distances[next_p] = distances[p] + 1
queue.append(next_p)
for i in range(n):
print(i+1, distances[i])
| import queue
N = int(input())
G = []
for _ in range(N):
u, n, *K = map(int, input().split())
G.append((u - 1, [k - 1 for k in K]))
Q = queue.Queue()
Q.put(G[0])
dist = [-1] * N
dist[0] = 0
while not Q.empty():
U = Q.get()
for u in U[1]:
if dist[u] == -1:
Q.put(G[u])
dist[u] = dist[U[0]] + 1
for i, time in enumerate(dist):
print(i + 1, time)
| 1 | 3,543,480,160 | null | 9 | 9 |
l, r, d = map(int, input().split())
rest = l%d
if(rest == 0):
num = int(r/d) - int(l/d) + 1
else:
num = int(r/d) - int(l/d)
print(num) | L, R, d = map(int, input().split())
pq = 0
for x in range(R+1):
y = d * x
if y>=L and y<=R:
pq += 1
print(pq) | 1 | 7,495,428,428,978 | null | 104 | 104 |
k = int(input())
start = 7 % k
ans = start
con = 1
if k % 2 == 0 or k % 5 == 0:
print("-1")
exit()
while True:
if ans == 0:
print(con)
break
else:
con += 1
ans = ans * 10 + 7
ans = ans % k
if ans == start:
print("-1")
break
| k = int(input())
def gcd1 (a, b):
while True:
if (a < b):
a, b = b, a
c = a%b
if (c == 0):
return (b)
else:
a = b
b = c
count = 0
for i in range(k):
for j in range(k):
tmp = gcd1(i + 1, j + 1)
if (tmp == 1):
count = count + k
else:
for l in range(k):
tmp2 = gcd1(tmp, l + 1)
count = count + tmp2
print(count)
| 0 | null | 20,735,552,036,048 | 97 | 174 |
s = input()
s = s[::-1]
n = len(s)
m = [0] * 2019
m[0] = 1
a = 0
d = 1
for i in range(n):
a = (a + int(s[i]) * d) % 2019
d = (d * 10) % 2019
m[a] += 1
print(sum([int(x * (x - 1) / 2) for x in m if x > 1]))
| from collections import Counter
S = input()
C = Counter()
MOD = 2019
n = 0
for i, s in enumerate(S[::-1]):
s = int(s)
n += pow(10, i, MOD) * s % MOD
C[n % MOD] += 1
C[0] += 1
ans = 0
for v in C.values():
ans += v * (v - 1) // 2
print(ans)
| 1 | 30,713,197,687,744 | null | 166 | 166 |
a, b = list(map(int, input().split()))
if a <= b:
my_result = 'unsafe'
else:
my_result = 'safe'
print(my_result) | N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = float("INF")
LS = [0]*(N+1)
LS[0] = 0
for i in range(N-1):
LS[i+1] = A[i] + LS[i]
ans = min(ans, abs(LS[i+1] - (S - LS[i+1])))
print(ans) | 0 | null | 85,363,870,503,712 | 163 | 276 |
n, x, m = map(int, input().split())
a = []
check = [-1] * m
i = 0
while check[x] == -1:
a.append(x)
check[x] = i
x = x * x % m
i += 1
if n <= i:
print(sum(a[:n]))
else:
print(
sum(a[:check[x]])
+ (n - check[x]) // (i - check[x]) * sum(a[check[x]:])
+ sum(a[check[x] : check[x] + (n - check[x]) % (i - check[x])])) | A = sum([list(map(int,input().split()))for _ in range(3)],[])
N = int(input())
b = [int(input()) for _ in range(N)]
f=0
for i in range(9):
if A[i]in b:f|=1<<i
ans=[v for v in [7,56,73,84,146,273,292,448]if f&v==v]
print('Yes' if ans else 'No')
| 0 | null | 31,182,306,525,500 | 75 | 207 |
import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, X, Y = NMI()
counts = [0] * N
for i in range(1, N):
for j in range(i+1, N+1):
dist = min(abs(j-i), abs(i-X) + 1 + abs(Y-j))
counts[dist] += 1
for d in counts[1:]:
print(d)
if __name__ == "__main__":
main() | from math import gcd, ceil
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = [a//2 for a in A]
B = 1
for a in A:
B*=a//gcd(B,a)
for a in A:
if B//a%2==0:
print(0)
exit()
print(ceil((M//B)/2)) | 0 | null | 72,889,862,940,300 | 187 | 247 |
n=list(input())
a=0
for i in n:
a+=int(i)
if a%9==0:
print('Yes')
else:
print('No') | s = input()
p = input()
if p in s + s:
print('Yes')
else:
print('No') | 0 | null | 3,061,550,475,160 | 87 | 64 |
n = int(input())
c = 0
for i in range(1,n):
if (i%2==1):
c+=1
print("{0:.10f}".format(1-(c/n)))
| #!/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 LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
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')
#A
def A():
return
#B
def B():
return
#C
def C():
return
#D
def D():
return
#E
def E():
n, m, l = LI()
dist = [[inf] * n for i in range(n)]
for _ in range(m):
a, b, c = LI_()
c += 1
if c > l:
continue
dist[a][b] = c
dist[b][a] = c
supply = [[n] * n for i in range(n)]
for k in range(n):
distk = dist[k]
for i in range(n):
if i == k:
continue
disti = dist[i]
distik = dist[i][k]
for j in range(i + 1, n):
if distik + distk[j] < disti[j]:
disti[j] = distik + distk[j]
dist[j][i] = disti[j]
lis = [[] for i in range(n)]
for i in range(n):
for j in range(i + 1, n):
if dist[i][j] <= l:
supply[i][j] = 0
supply[j][i] = 0
lis[i].append(j)
lis[j].append(i)
for i in range(n):
q = []
for k in lis[i]:
heappush(q, (0, k))
supplyi = supply[i]
while q:
time, p = heappop(q)
for k in lis[p]:
if supplyi[k] > time + 1:
supplyi[k] = time + 1
heappush(q, (time + 1, k))
q = II()
for _ in range(q):
s, t = LI_()
if dist[s][t] == inf:
print(-1)
continue
else:
print(supply[s][t])
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == '__main__':
E()
| 0 | null | 174,969,411,290,560 | 297 | 295 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.