code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n, m = map(int, input().split())
C = list(map(int, input().split()))
dp = [f_inf] * (n + 1)
dp[0] = 0
for c in C:
for i in range(1, n + 1):
if i - c >= 0:
dp[i] = min(dp[i], dp[i - c] + 1)
print(dp[-1])
if __name__ == '__main__':
resolve()
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')
N,M=MAP()
C=LIST()
dp=[INF]*(N+1)
dp[0]=0
for i in range(N):
for j in range(M):
if i+C[j]<=N:
dp[i+C[j]]=min(dp[i+C[j]], dp[i]+1)
print(dp[N])
| 1 | 141,660,006,350 | null | 28 | 28 |
import sys
def swap(a, i, j):
tmp = a[j]
a[j] = a[i]
a[i] = tmp
return a
def list_to_string(a):
s = ""
for n in a:
s += str(n) + " "
return s.strip()
num = int(sys.stdin.readline().strip())
array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
flag = True
swap_num = 0
while flag:
flag = False
for i in reversed(range(1, len(array))):
if array[i] < array[i - 1]:
swap(array, i, i-1)
flag = True
swap_num += 1
print list_to_string(array)
print str(swap_num) |
def print_array(A, N):
for i in xrange(N - 1):
print str(A[i]),
print A[N - 1]
def bubbleSort(A, N):
swap_num = 0
flag = 1
while flag == 1:
flag = 0
for j in xrange(N - 1, 0, -1):
if A[j] < A[j - 1]:
swap_num += 1
temp = A[j]
A[j] = A[j - 1]
A[j - 1] = temp
flag = 1
return swap_num
def main():
N = int(raw_input())
A = []
for num in raw_input().split():
A.append(int(num))
temp = bubbleSort(A, N)
print_array(A, N)
print temp
if __name__ == "__main__":
main() | 1 | 17,618,390,020 | null | 14 | 14 |
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
if a1>b1 and a2>b2:
print(0)
elif b1>a1 and b2>a2:
print(0)
elif a1*t1+a2*t2==b1*t1+b2*t2:
print("infinity")
else:
ans=-1
num2=-1
num3=-1
if a1*t1+a2*t2>b1*t1+b2*t2:
if a1>b1:
ans=0
else:
num2=(b1-a1)*t1
num3=((a1-b1)*t1)+((a2-b2)*t2)
if num2//num3==num2/num3:
ans=(num2//num3)*2
else:
ans=(num2//num3)*2+1
else:
if b1>a1:
ans=0
else:
num2=(a1-b1)*t1
num3=((b1-a1)*t1)+((b2-a2)*t2)
if num2//num3==num2/num3:
ans=(num2//num3)*2
else:
ans=(num2//num3)*2+1
print(ans)
| s,w=list(map(int, input().split()))
a=''
if s<=w:
a='un'
print(a+'safe') | 0 | null | 80,112,994,016,520 | 269 | 163 |
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
import os, zlib, base64
open('tourist.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${TY%Wi`(5WFMt58Fc(Xq*VD9x7D&BPj>l7_bTkIj*Ai>${5yulNExGoBr<UD>{aRttH)I;%|$Qg=gd9dxR@Di;P73FNP9dUGDQ<!!6lSu|K~YBh-_ms0mLUn?gYZW#)-aa9<|QdNMzm)C?=0Ye!0PSL>Nlrr!HyueleslJL(9LLK>v^G%;rmuCIg#qB2DZxNO4vB|vjcygBlZci;a!M4%3#=<-KH%*=17Q{aUKnzd7$r^Mh?)~>JZY8tu?FNSSF3obEX4)B&4>QOg%{W&$?iM3r$#)#@1-i<G$3Tv!!YO=a7HK93>>2bH|?5DKSQZ$O1|v2Wz}2I=r-M5)Wxd_@vZhgv>n8k$Q*}~?$i?{b`*|*!&44o)o(qXPyC2tN78cW$sb`#As%5$;I{B+f6Pb!JtGS5K99vu#l*|yora61crqIw#8`%bf6>w5x%@H*ya+t$KlVq{`2")))
os.system('cythonize -i -3 -b tourist.pyx')
import tourist | N,M=list(map(int, input().split()))
src=[i+1 for i in range(M*2+1)]
if M%2==0:
for m in range(M//2):
a=src[m]
b=src[M-m]
print('{} {}'.format(a,b))
for m in range(M//2):
a=src[M+1+m]
b=src[-(m+1)]
print('{} {}'.format(a,b))
else:
for m in range(M//2):
a=src[m]
b=src[M-1-m]
print('{} {}'.format(a,b))
for m in range(M-(M//2)):
a=src[M+m]
b=src[-(m+1)]
print('{} {}'.format(a,b)) | 0 | null | 16,425,156,638,716 | 84 | 162 |
A, B = map(int, input().split())
print(A * B) if len(str(A)) == 1 and len(str(B)) == 1 else print(-1) | #!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def main():
A,B = map(int,input().split())
if A < 10 and B < 10:
print(A*B)
else:
print(-1)
if __name__ == "__main__":
main() | 1 | 157,868,535,781,750 | null | 286 | 286 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
import math
from functools import reduce
n = int(readline())
a = list(map(int,readline().split()))
def lcm(x, y):
return (x * y) // math.gcd(x, y)
x = reduce(lcm, a)
ans = 0
for i in range(n):
ans += x // a[i]
print(ans%1000000007) | x = list(map(int, input().split()))
for i in range(len(x)):
if x[i] is 0:
print(i+1)
| 0 | null | 50,359,834,594,140 | 235 | 126 |
print(2**int(input()).bit_length()-1)
| import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
H = ri()
cnt = 1
while H > 1:
H = H // 2
cnt += 1
print(sum([2 ** i for i in range(cnt)])) | 1 | 80,520,297,107,070 | null | 228 | 228 |
K = int(input())
S = input()
len_S = len(S)
if len_S <= K:
print(S)
else:
print(S[:K] + '...') | def main():
H, W, M = [int(s) for s in input().split()]
cols = [0] * W
rows = [0] * H
bombs = set()
for _ in range(M):
x, y = [int(s)-1 for s in input().split()]
bombs.add((x, y))
cols[y] += 1
rows[x] += 1
sc = sorted([(c, i) for i, c in enumerate(cols)], reverse=True)
sr = sorted([(c, i) for i, c in enumerate(rows)], reverse=True)
best = 0
for v1, c in sc:
for v2, r in sr:
if v1 + v2 <= best:
break
score = v1 + v2
if (r, c) in bombs:
score -= 1
best = max(best, score)
print(best)
main() | 0 | null | 12,120,320,913,760 | 143 | 89 |
def ri():
return int(input())
def rii():
return [int(v) for v in input().split()]
def solve():
X, N = rii()
P = set(rii())
n = m = float("inf")
if not P:
print(X)
return
for i in range(min(P)-1, max(P)+2):
if i not in P:
d = abs(i - X)
if d == m:
n = min(n, i)
elif d < m:
m = d
n = i
print(n)
if __name__ == "__main__":
solve() | import queue
import numpy as np
import math
n = int(input())
A = list(map(int, input().split()))
A = np.array(A,np.int64)
ans = 0
for i in range(60 + 1):
a = (A >> i) & 1
count1 = np.count_nonzero(a)
count0 = len(A) - count1
ans += count1*count0 * pow(2, i)
ans%=1000000007
print(ans) | 0 | null | 68,623,115,241,764 | 128 | 263 |
def main():
import sys
readline = sys.stdin.buffer.readline
n, x, y = map(int, readline().split())
l = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
s = min(j-i, abs(x-i)+abs(j-y)+1)
l[s-1] += 1
for i in l:
print(i)
main() | n=int(input())
a=[]
for i in range(1,n+1):
if not(i%3==0 or i%5==0):
a.append(i)
print(sum(a)) | 0 | null | 39,214,621,617,148 | 187 | 173 |
N=int(input())
s=0
for i in range(1,N+1):
s+=int(N/i)
if N%i==0:
s-=1
print(s)
| N=int(input())
ans=0
for a in range(1,N):
q,m=divmod(N,a)
ans+=(N//a)-(m==0)
print(ans) | 1 | 2,579,908,522,428 | null | 73 | 73 |
L = int(input())
l3 = L/3
print(l3*l3*l3) | n = int(input())
A = list(map(int, input().split()))
dp = [0] * (n+1)
dp[2] = max(A[0], A[1])
s = A[0]
for i, a in enumerate(A, 1):
if i <= 2:
continue
if i%2: # 奇数
dp[i] = max(dp[i-1], a+dp[i-2])
s += a
else: # 偶数
dp[i] = max(a+dp[i-2], s)
print(dp[-1]) | 0 | null | 42,277,664,321,452 | 191 | 177 |
# ()の問題は折れ線で捉えると良い
N = int(input())
ls = [] # 増減が正のもの(0を含む)
rs = [] # 増減が負のもの
tot = 0
for i in range(N):
s = input()
h = 0
b = 0
for c in s:
if c == "(":
h += 1
else:
h -= 1
b = min(b, h)
if h >= 0:
# 折れ線に対して上っていく奴ら
ls.append([b, h])
else:
# 折れ線に対して下っていく奴ら
# 右から(hから見るので、最下点は-hする)
rs.append([b-h, -h])
tot += h
ls.sort(key = lambda x:x[0], reverse=True)
rs.sort(key = lambda x:x[0], reverse=True)
def check(s):
h = 0
for p in s:
if h+p[0] < 0:
return False
h += p[1]
return True
if check(ls) and check(rs) and tot == 0:
print("Yes")
else:
print("No") | MOD = 1e9 + 7
n = int(input())
ans = [[0, 1, 1, 8]]
for i in range(n-1):
a, b, c, d = ans.pop()
a = (a * 10 + b + c) % MOD
b = (b * 9 + d) % MOD
c = (c * 9 + d) % MOD
d = (d * 8) % MOD
ans.append([a, b, c, d])
a, b, c, d = ans.pop()
print(int(a)) | 0 | null | 13,400,720,582,382 | 152 | 78 |
L = int(input(""))
a = L / 3.0
print(pow(a,3)) | L = int(input())
r = (L/3)**3
print(r)
| 1 | 46,767,759,427,680 | null | 191 | 191 |
N, P = map(int, input().split())
S = input()
ans = 0
if P == 2 or P == 5 :
for i in range(N) :
if int(S[i])%P == 0 :
ans += i+1
print(ans)
exit()
modP = [0 for _ in range(P)]
modP[0] = 1
now = 0
t = 1
for i in range(N) :
now += int(S[-1-i]) * t
now %= P
modP[now] += 1
t = t * 10 % P
for r in modP :
ans += r*(r-1)//2
print(ans)
| S = int(input())
h = S//3600
m = S%3600//60
s = S%60
print(f"{h}:{m}:{s}")
| 0 | null | 29,310,852,348,792 | 205 | 37 |
i = 1
while True:
n = input()
if n == 0:
break
else:
print "Case %d: %d" % (i, n)
i = i + 1 | if __name__ == "__main__":
i = 0
while True:
v = int(raw_input())
if v == 0:
break
i += 1
print "Case {0}: {1}".format(i,v) | 1 | 477,845,920,690 | null | 42 | 42 |
from numba import njit
@njit("i8(i8)")
def f(n):
l = [1]*(n+1)
l[0] = 0
ans = l[1]
for i in range(2,n+1):
for j in range(i,n+1,i):
l[j] += 1
ans += (l[i]*i)
return ans
n = int(input())
print(f(n))
| for a in range(1,10):
for b in range(1,10):
ans=str(a*b)
print(str(a)+'x'+str(b)+'='+ans)
| 0 | null | 5,559,345,479,100 | 118 | 1 |
import queue
def main():
n = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
q = queue.PriorityQueue()
q.put([-1*A[0],-1*A[0]])
ans = 0
for a in A[1:]:
_min, _max = map(lambda x:-1*x,q.get())
ans += _min
q.put([-1*a,-1*_min])
q.put([-1*a,-1*_max])
print(ans)
return
if __name__ == "__main__":
main() | N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
n = N // 2
if N % 2 == 1:
ans = sum(A[:n]) + sum(A[1:n+1])
else:
ans = sum(A[:n]) + sum(A[1:n])
print(ans) | 1 | 9,148,767,727,600 | null | 111 | 111 |
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i, a in enumerate(a):
ans[a-1] += 1
print(*ans, sep="\n") | n=int(input())
s = input()
ans = 0
if n%2 != 0:
print('No')
if n%2 == 0:
for i in range(n//2):
if s[i] == s[i+n//2]:
ans += 1
if ans == n//2:
print('Yes')
if ans != n//2:
print('No') | 0 | null | 89,182,761,438,158 | 169 | 279 |
import numpy as np
N = int(input())
X = []
L = []
for _ in range(N):
Xi, Li = map(int, input().split())
X.append(Xi)
L.append(Li)
begins = []
ends = []
for i in range(N):
begins.append(X[i] - L[i])
ends.append(X[i] + L[i])
b = []
e = []
for i in np.argsort(ends):
b.append(begins[i])
e.append(ends[i])
begins = b
ends = e
now = -1e9
cnt = 0
for i in range(N):
if now <= begins[i]:
cnt += 1
now = ends[i]
print(cnt) | import sys
N = int(sys.stdin.readline().rstrip())
sec = []
for _ in range(N):
x, l = map(int, sys.stdin.readline().rstrip().split())
sec.append((x - l + 1, x + l - 1))
sec = sorted(sec, key=lambda x: x[1])
r = -10**10
ans = 0
for s, t in sec:
if r + 1 < s:
ans += 1
r = t
print(ans) | 1 | 89,735,089,296,512 | null | 237 | 237 |
input()
a = list(map(int, input().split()))
c = 1000000007
print(((sum(a)**2-sum(map(lambda x: x**2, a)))//2)%c) | # input here
_INPUT = """\
4
141421356 17320508 22360679 244949
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
def main():
n = int(input())
a = list(map(int, input().split()))
cumsum = list(itertools.accumulate(a))
sum1 = 0
for i in range(len(a)):
mult = a[i] * (cumsum[n-1] - cumsum[i])
sum1 += mult
print((sum1 % (10**9 + 7)))
if __name__ == '__main__':
import io
import sys
import math
import itertools
from collections import deque
# sys.stdin = io.StringIO(_INPUT)
main() | 1 | 3,823,408,838,718 | null | 83 | 83 |
from collections import defaultdict
def combination(a, b):
if b > a - b:
return combination(a, a - b)
return fact[a] * ifact[b] * ifact[a-b]
MOD = 10**9+7
n, k = map(int, input().split())
k = min(k, n-1)
# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, n+1):
fact[i] = fact[i-1] * i
fact[i] %= MOD
# 階乗の逆元を前処理
ifact = defaultdict(int)
ifact[n] = pow(fact[n], MOD-2, MOD)
for i in reversed(range(1, n + 1)):
ifact[i-1] = ifact[i] * i
ifact[i-1] %= MOD
ans = 0
for i in range(k+1):
ans += combination(n, i) * combination((n-i-1)+i, i)
ans %= MOD
print(ans % MOD)
| n,k=map(int,input().split())
mod=10**9+7
f=[1]
for i in range(2*n):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod
ans=comb(2*n-1,n-1)
for i in range(n-1,k,-1):ans=(ans-comb(n,n-i)*comb(n-1,i))%mod
print(ans)
| 1 | 67,012,339,061,108 | null | 215 | 215 |
H=int(input())
Q=[]
import math
for i in range(10000):
if H>1:
H=H//2
Q.append(H)
elif H==1:
break
Q.sort()
S=0
a=1
for i in range(len(Q)):
a=2*a+1
print(a) | n = int(input())
s = list(map(int, input().split()))
cnt = 0
def merge(A, left, mid, right):
L = A[left:mid]
R = A[mid:right]
L.append(float('inf'))
R.append(float('inf'))
i = 0
j = 0
global cnt
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
def mergeSort(A, left, right):
if left+1 < right:
mid = (left+right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
mergeSort(s, 0, n)
print(' '.join(map(str, s)))
print(cnt)
| 0 | null | 39,835,903,065,910 | 228 | 26 |
# A - 9x9
# 九九の計算
# 九九以外は -1 を返す
# 整数 a b を入力
a, b = map(int, input().split())
# print(a, b)
# a b が9以下の数字か判定し結果を代入
if a <= 9:
if b <= 9:
answer = a * b
else:
answer = -1
else:
answer = -1
# 結果の表示
print(answer)
| A,B = map(int,input().split())
answer = -1
if A<=9 and B<=9:
answer= A*B
print(answer) | 1 | 158,559,843,586,172 | null | 286 | 286 |
N, M = map(int, input().split())
# 左パート
l, r = 1, N // 2
while M and l < r :
print(l, r)
l += 1
r -= 1
M -= 1
# 右パート
l, r = N // 2 + 2 - N % 2, N
while M :
print(l, r)
l += 1
r -= 1
M -= 1 | n = int(input())
a = list(map(int, input().split()))
m = [0] * (n+1)
mx = 1
for i in range(n+1):
mx -= a[i]
m[i] = mx
if (mx <= 0 and i != n) or (mx < 0 and i == n):
print(-1)
exit()
mx *= 2
a.reverse()
m.reverse()
m[0] = a[0]
for i in range(1, n+1):
m[i] = min(m[i], m[i-1]) + a[i]
print(sum(m))
| 0 | null | 23,668,478,567,788 | 162 | 141 |
#a問題(できなかった)
s = input()
p=s[0]=='R'
q=s[1]=='R'
r=s[2]=='R'
if p and q and r==True:
print(3)
elif (p and q)or(q and r)==True:
print(2)
elif p or q or r ==True:
print(1)
else:
print(0)
| s = input()
count = 0
max = 0
for i in range(len(s)):
if s[i] == 'S':
count =0
else:
count += 1
if count > max:
max = count
print(max) | 1 | 4,920,204,937,438 | null | 90 | 90 |
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
X = int(input())
return X
def main(X: int) -> None:
"""
メイン処理.
Args:\n
X (int): 最高レーティング(400 <= X <= 1999)
"""
# 求解処理
ans = 10 - (X // 200)
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
X = get_input()
# メイン処理
main(X)
| a = int(input())
ans = a >= 30 and 'Yes' or 'No'
print(ans) | 0 | null | 6,258,509,958,960 | 100 | 95 |
def main():
s = str(input())
dic = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}
print(dic.get(s))
main() | import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
d = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1}
print(d[gete()])
if __name__ == "__main__":
main() | 1 | 133,052,252,293,632 | null | 270 | 270 |
temp=int(input())
if temp<30:
print('No')
else:
print('Yes') | import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()
N = I()
ST = [tuple(map(str,S().split())) for _ in range(N)]
X = S()
ans = 0
for i in range(N):
s,t = ST[i]
ans += int(t)
if s == X:
break
print(sum(int(ST[i][1]) for i in range(N))-ans)
| 0 | null | 51,495,255,137,620 | 95 | 243 |
n = input()
s = list(n)
sm = 0
for i in range(len(s)):
sm += int(s[i])
if sm%9 == 0:
print("Yes")
else:
print("No")
|
strN = input()
s = 0
for c in strN:
s += int(c)
if s % 9 == 0:
print("Yes")
else:
print("No") | 1 | 4,389,096,960,260 | null | 87 | 87 |
import numpy as np
H,W,M = map(int,input().split())
#h = np.empty(M,dtype=np.int)
#w = np.empty(M,dtype=np.int)
bomb = set()
hh = np.zeros(H+1,dtype=np.int)
ww = np.zeros(W+1,dtype=np.int)
for i in range(M):
h,w = map(int,input().split())
bomb.add((h,w))
hh[h] += 1
ww[w] += 1
#print(bomb)
h_max = np.max(hh)
w_max = np.max(ww)
h_max_ids = list()
w_max_ids = list()
for i in range(1,H+1):
if hh[i] == h_max:
h_max_ids.append(i)
for j in range(1,W+1):
if ww[j] == w_max:
w_max_ids.append(j)
for i in h_max_ids:
for j in w_max_ids:
if not (i,j) in bomb:
print(h_max + w_max)
exit()
#print("hmax:{} wmax:{}".format(h_max_id, w_max_id))
#print("hmax:{} wmax:{}".format(hh[h_max_id], ww[w_max_id]))
print(h_max + w_max - 1)
| X = int(input())
answer = (X // 500) * 1000
X %= 500
answer += (X // 5) * 5
print(answer) | 0 | null | 23,799,145,656,820 | 89 | 185 |
n,*s=open(0).read().split()
for t in['AC','WA','TLE','RE']:print(f'{t} x {s.count(t)}') | n=int(input())
l = [input() for i in range(n)]
ac = 0
wa = 0
tle = 0
re = 0
for i in l:
if i == 'AC':
ac += 1
if i == 'WA':
wa += 1
if i == 'TLE':
tle += 1
if i == 'RE':
re += 1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re)) | 1 | 8,720,693,638,682 | null | 109 | 109 |
import math
n = int(input())
#探索範囲
sqrt_n = int(math.sqrt(n))
num_i = 0
for i in range(1, sqrt_n+1):
if n % i == 0:
num_i = i
num_j = n // num_i
ans = (num_i - 1) + (num_j - 1)
print(ans)
| NN=raw_input()
N=raw_input()
A = [int(i) for i in N.split()]
swap=0
for i in range(int(NN)):
for j in reversed(range(i+1,int(NN))):
if A[j] < A[j-1] :
t = A[j]
A[j] = A[j-1]
A[j-1] = t
swap+=1
print ' '.join([str(k) for k in A])
print swap | 0 | null | 80,752,413,120,300 | 288 | 14 |
A,B=map(int,input().split())
ma,mi=0,0
ma=max(A,B)
mi=min(A,B)
if A%B==0 or B%A==0:
print(ma)
else :
for i in range(2,ma+1):
if (ma*i)%mi==0:
print(ma*i)
break
i+=(mi-1)
| def lcm(x, y):
import math
return (x * y) // math.gcd(x, y)
def main():
A, B = map(int, input().split())
ans = lcm(A, B)
print(ans)
main() | 1 | 113,525,141,564,406 | null | 256 | 256 |
N=int(input())
A=list(map(int,input().split()))
B=[]
for k in range(N):
B.append([A[k],k+1])
B.sort(key=lambda x: x[0], reverse=True)
dp=[[0 for k in range(N+1)]for k in range(N+1)]
dp[1][0]=dp[0][0]+B[0][0]*(B[0][1]-1)
dp[0][1]=dp[0][0]+B[0][0]*(N-B[0][1])
for k in range(1,N):
#j=0
dp[0][k+1]=dp[0][k]+B[k][0]*(N-k-B[k][1])
dp[1][k]=max(dp[0][k]+B[k][0]*(B[k][1]-1), dp[1][k-1]+B[k][0]*(N-k+1-B[k][1]))
#j=k
dp[k+1][0]=dp[k][0]+B[k][0]*(B[k][1]-k-1)
dp[k][1]=max(dp[k-1][+1]+B[k][0]*(B[k][1]-k), dp[k][0]+B[k][0]*(N-B[k][1]))
for j in range(1,k):
dp[j+1][k-j]=max(dp[j][k-j]+B[k][0]*(B[k][1]-j-1), dp[j+1][k-j-1]+B[k][0]*(N-k+j+1-B[k][1]))
dp[j][k-j+1]=max(dp[j-1][k-j+1]+B[k][0]*(B[k][1]-j), dp[j][k-j]+B[k][0]*(N-k+j-B[k][1]))
ans=[]
for k in range(N+1):
ans.append(dp[k][N-k])
print(max(ans)) | n = int(input())
a = [(int(x), i) for i, x in enumerate(input().split())]
a.sort(reverse=True)
aval, ai = zip(*a)
dp = [[0] * (n+1) for _ in range(n+1)]
for l in range(n):
for r in range(n):
if l + r >= n: break
dp[l+1][r] = max(dp[l+1][r], dp[l][r] + aval[l+r] * abs(ai[l+r]-l))
dp[l][r+1] = max(dp[l][r+1], dp[l][r] + aval[l+r] * abs(ai[l+r]-(n-r-1)))
print(max([dp[i][n-i] for i in range(n+1)]))
| 1 | 33,704,243,558,112 | null | 171 | 171 |
import math
def triangle(a, b, deg):
result = {}
rad = math.radians(deg)
c = math.sqrt(a*a+b*b-(2*a*b*math.cos(rad)))
s = (a+b+c)/2
result['area'] = math.sqrt(s*(s-a)*(s-b)*(s-c))
result['perimeter'] = a+b+c
result['height'] = result['area'] * 2 / a
return result
if __name__ == '__main__':
a, b, deg = map(int, input().split())
triangle = triangle(a, b, deg)
print(triangle['area'])
print(triangle['perimeter'])
print(triangle['height'])
| Spades = 0
Hearts = 1
Clovers = 2
Diamonds = 3
Cards = [[Spades, Hearts, Clovers, Diamonds] for j in range(13)]
for i in range(4):
for j in range(13):
Cards[j][i] = True
n = input()
for i in range(n):
Input = raw_input().split()
Numb = int(Input[1])
if Input[0] == 'S':
Mark = Spades
if Input[0] == 'H':
Mark = Hearts
if Input[0] == 'C':
Mark = Clovers
if Input[0] == 'D':
Mark = Diamonds
Cards[Numb - 1][Mark] = False
for i in range(4):
for j in range(13):
if Cards[j][i]:
if i == Spades:
print 'S', j + 1
if i == Hearts:
print 'H', j + 1
if i == Clovers:
print 'C', j + 1
if i == Diamonds:
print 'D', j + 1 | 0 | null | 596,729,315,324 | 30 | 54 |
# F - Playing Tag on Tree
# https://atcoder.jp/contests/abc148/tasks/abc148_f
from heapq import heappop, heappush
INF = float("inf")
def dijkstra(n, G, s):
dist = [INF] * n
dist[s] = 0
hq = [(0, s)]
while hq:
d, v = heappop(hq)
if dist[v] < d:
continue
for child, child_d in G[v]:
if dist[child] > dist[v] + child_d:
dist[child] = dist[v] + child_d
heappush(hq, (dist[child], child))
return dist
n, u, v = map(int, input().split())
graph = [[] for _ in range(n)]
edge = [list(map(int, input().split())) for _ in range(n - 1)]
for a, b in edge:
graph[a - 1].append((b - 1, 1))
graph[b - 1].append((a - 1, 1))
from_u = dijkstra(n, graph, u - 1)
from_v = dijkstra(n, graph, v - 1)
# print(from_u)
# print(from_v)
fil = filter(lambda x : x[0] < x[1], [[fu, fv] for fu, fv in zip(from_u, from_v)])
sfil = sorted(list(fil), key=lambda x: [-x[1], -x[0]])
# print(sfil)
print(sfil[0][1] - 1)
| from collections import deque
n, u, v = map(int, input().split())
u-=1; v-=1;
a = []; b = [];
dist = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a -= 1; b -= 1
dist[a].append(b)
dist[b].append(a)
def bfs(u):
d = [-1]*n
stack = deque([u])
d[u] = 0
while len(stack)!=0:
s = stack.popleft()
for t in dist[s]:
if d[t]==-1:
d[t] = d[s]+1
stack.append(t)
return d
A = bfs(v)
T = bfs(u)
ans=0
for i in range(n):
if A[i]>T[i]:
ans = max(A[i]-1, ans)
print(ans) | 1 | 117,057,152,222,208 | null | 259 | 259 |
numbers = []
while True:
x=int(input())
if x==0:
break
numbers.append(x)
for i in range(len(numbers)):
print("Case ",i+1,": ",numbers[i],sep="")
| i=1
while True:
line = int(input())
if line==0: break
print('Case {i}: {line}'.format(i=i,line=line))
i+=1 | 1 | 482,656,814,402 | null | 42 | 42 |
import math
H, W = map(int, input().split())
A = math.ceil((H * W)/2)
if H == 1 or W == 1:
print(1)
else:
print(A)
| import math
h, w = map(int, input().split())
print(math.ceil((h * w) / 2) if h != 1 and w != 1 else 1) | 1 | 50,972,326,878,174 | null | 196 | 196 |
from collections import deque
N = int(input())
graph = [deque([]) for _ in range((N + 1))]
for _ in range(N):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
time = 0
arrive_time = [-1] * (N + 1)
finish_time = [-1] * (N + 1)
def dfs(v):
global time
time += 1
stack = [v]
arrive_time[v] = time
while stack:
v = stack[-1]
if graph[v]:
w = graph[v].popleft()
if arrive_time[w] < 0:
time += 1
arrive_time[w] = time
stack.append(w)
else:
time += 1
finish_time[v] = time
stack.pop()
return [arrive_time, finish_time]
for i in range(N):
if arrive_time[i + 1] < 0:
ans = dfs(i + 1)
for j in range(N):
temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
print(*temp)
| import math
n,D = map(int,input().split())
cnt = 0
for i in range(n):
p,q = map(int,input().split())
d = math.sqrt(p**2 + q ** 2)
if D >= d:
cnt += 1
print(cnt) | 0 | null | 2,937,131,165,708 | 8 | 96 |
# coding: utf-8
# Your code here!
import itertools
import numpy as np
def main():
N, M, X = map(int, input().split())
for i in range(N):
row = np.array(list(map(int, input().split())))
# print(row)
if i == 0:
c_array = row[0].reshape(1, 1)
a_matrix = row[1:].reshape(1, len(row[1:]))
else:
c_array = np.append(c_array, row[0])
a_matrix = np.vstack([a_matrix, row[1:].reshape(1, len(row[1:]))])
# print(c_array)
# print(a_matrix)
min_cost = float("inf")
for i in range(1, N+1):
for v in itertools.combinations(np.arange(N), i):
tmp = a_matrix[v, :].sum(axis=0)
cost = c_array[list(v)].sum()
# print(tmp)
if tmp.min() >= X and cost <= min_cost:
min_cost = cost
if min_cost == float("inf"):
print("-1")
else:
print(min_cost)
main() | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
if s=="1":
cnt += 1
A[i] = cnt
else:
cnt = 0
dp = 0
res = []
while dp+M <= N-1:
t = M - A[dp+M]
if t>0:
dp += t
else:
print(-1)
exit()
res.append(t)
res.append(N-dp)
res.reverse()
print(*res) | 0 | null | 80,791,609,890,812 | 149 | 274 |
from collections import deque
n=int(input())
e=[]
edge=[[] for _ in range(n)]
for i in range(n-1):
x,y=map(int,input().split())
edge[x-1].append(y-1)
edge[y-1].append(x-1)
e.append(str(x-1)+" "+str(y-1))
par=[0]*n #自分の親と何番でつながっているか
visited=[0]*n
visited[0]=1
que=deque([0])
ans=dict()
K=0
while que:
now=que.popleft()
color=1
for x in edge[now]:
if visited[x]:
continue
visited[x]=1
que.append(x)
if color==par[now]:
color+=1
par[x]=color
ans[str(min(x,now))+" "+str(max(x,now))]=color
color+=1
print(max(ans.values()))
for i in e:
print(ans[i]) | import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
tree = [[] for _ in range(n)]
dic = {}
for i in range(n - 1):
a, b = map(int, input().split())
tree[a - 1].append(b - 1)
tree[b - 1].append(a - 1)
dic[(a - 1, b - 1)] = i
ans = [0 for _ in range(n - 1)]
max_color = 0
def dfs(pos, before_pos, before_color):
global max_color
color = 1
for next_pos in tree[pos]:
if color == before_color:
color += 1
if next_pos == before_pos:
continue
before = min(pos, next_pos)
after = max(pos, next_pos)
ans_ind = dic[(before, after)]
if pos < next_pos:
ans[ans_ind] = color
else:
ans[ans_ind] = color
max_color = max(color, max_color)
dfs(next_pos, pos, color)
color += 1
dfs(0, -1, -1)
print(max_color)
for i in ans:
print(i)
| 1 | 135,990,610,216,010 | null | 272 | 272 |
MOD = 10**9 + 7
N = int(input())
A = list(map(int, input().split()))
modS = [0]
for i in A:
modS.append((modS[-1] + i) % MOD)
ans = 0
for i in range(1, N + 1):
count = modS[-1] - modS[i]
if count < 0:
count = MOD + count
ans = (ans + (A[i - 1] * count % MOD)) % MOD
print(ans) | a = input().split()
b = str(a[0])
c = str(a[1])
print(c+b) | 0 | null | 53,694,764,458,712 | 83 | 248 |
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
n = int(readline())
# O(N)解法
ans = 0
for i in range(1,n+1):
a = n//i
ans += a*(a+1)*i//2
print(ans)
| def main():
N = int(input())
ans = 0
for n in range(1, N + 1):
d = N // n
ans += d * (d + 1) / 2 * n
print(int(ans))
if __name__ == '__main__':
main() | 1 | 11,024,051,550,512 | null | 118 | 118 |
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
u, k, *v = [int(i) for i in input().split()]
G[u - 1] = v
NIL = 100
Q = [[1, 0]]
F = []
D = [NIL for _ in range(n)]
while Q != []:
u, d = Q.pop(0)
if d < D[u-1]:
D[u-1] = d
if u not in F:
F.append(u)
for v in G[u-1]:
if v not in F:
Q.append([v, d+1])
'''
for ni in range(1, n):
Q = [[ni+1, 0]]
F = []
while Q != []:
u, d = Q.pop(0)
if u == 1 and d < D[ni]:
D[ni] = d
if u not in F:
F.append(u)
for v in G[u-1]:
if v not in F:
Q.append([v, d+1])
'''
for ni in range(n):
if D[ni] == NIL:
print(ni+1, -1)
else:
print(ni+1, D[ni])
| # B - Battle
import sys
a,b,c,d = map(int,input().split())
while True:
if c - b <= 0:
print('Yes')
sys.exit()
c = c - b
if a - d <= 0:
print('No')
sys.exit()
a = a - d
| 0 | null | 14,749,829,260,500 | 9 | 164 |
N = int(input())
A = list(map(int, input().split()))
dp = [0]*N
cum = A[0]
for i in range(N):
if i == 0:
dp[i] = 0
continue
if i == 1:
dp[i] = max(A[0],A[1])
continue
if i%2==0: #奇数の時
cum += A[i]
dp[i] = max(dp[i-1],dp[i-2]+A[i])
if i%2==1: #偶数の時
dp[i] = max(dp[i-2]+A[i],cum)
ans = dp[-1]
print(ans)
#print(*ans, sep='\n') | import sys
import itertools
def main():
N = int(input())
songs = []
time = []
for _ in range(N):
s, t = input().split()
t = int(t)
songs.append(s)
time.append(t)
X = input()
time = list(itertools.accumulate(time))
ans = time[-1] - time[songs.index(X)]
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 67,141,044,062,040 | 177 | 243 |
N=int(input())
S,T=input().split()
list=[]
for i in range(N):
list.append(S[i]+T[i])
print(''.join(list))
| n = int(input())
s,t = map(str, input().split())
res = str()
for i in range(n):
res += s[i]
res += t[i]
print(res) | 1 | 112,597,171,518,330 | null | 255 | 255 |
a = int(input())
if (a >= 400) and (a <= 599) :
print(8)
if (a >= 600) and (a <= 799) :
print(7)
if (a >= 800) and (a <= 999) :
print(6)
if (a >= 1000) and (a <= 1199) :
print(5)
if (a >= 1200) and (a <= 1399) :
print(4)
if (a >= 1400) and (a <= 1599) :
print(3)
if (a >= 1600) and (a <= 1799) :
print(2)
if (a >= 1800) and (a <= 1999) :
print(1) | import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
X = int(rl())
print(10 - X // 200)
if __name__ == '__main__':
solve()
| 1 | 6,751,373,161,540 | null | 100 | 100 |
import math
a, b, x = map(int, input().split())
if a*a*b == x:
print(0)
elif a*a*b <= 2*x:
print(90-math.degrees(math.atan(a*a*a/(2*a*a*b-2*x))))
else:
print(90-math.degrees(math.atan(2*x/(a*b*b))))
| import math
a, b, x = map(int,input().split())
s = a
t = 2*(b-x/(a*a))
u = x*2/(b*a)
if t<=b:
print(math.degrees(math.atan(t/s)))
else:
print(math.degrees(math.atan(b/u))) | 1 | 163,549,771,670,290 | null | 289 | 289 |
ans = []
while True:
tmp = input().split()
a, b = map(int, [tmp[0], tmp[2]])
op = tmp[1]
if op == "?":
break
if op == "+":
ans.append(a + b)
if op == "-":
ans.append(a - b)
if op == "*":
ans.append(a * b)
if op == "/":
ans.append(a // b)
print("\n".join(map(str, ans)))
| N,K=list(map(int,input().split()))
l=[0]*(K+1)
ans=0
mod=10**9+7
for x in range(K,0,-1):
l[x]=pow((K//x),N,mod)
for y in range(2*x,K+1,x):
l[x]-=l[y]
l[x]=pow(l[x],1,mod)
ans+=l[x]*x
ans=pow(ans,1,mod)
print(ans) | 0 | null | 18,754,194,204,720 | 47 | 176 |
#!/usr/bin/env python3
class UnionFind:
"""Union-Find(素集合データ構造)"""
def __init__(self, n: int):
"""
Constructer(Initialize parameter in this class)
Parameters
----------
n : int
Number of node
Yields
-----
root : list
When value is postive, express root of the node.
When it is negative, express this node is root and size of set.
"""
self.root = [-1] * n
def find(self, x: int):
"""
Search root of node x
Parameters
----------
x : int
node x
Returns
-------
x : int
Root of node x
"""
if self.root[x] < 0:
return x
self.root[x] = self.find(self.root[x])
return self.root[x]
def unite(self, x: int, y: int):
"""
Unite two set including node x and node y into one set.
Parameters
----------
x, y : int
Node number
Returns
-------
unite_result : bool
False : Already two node include same set.
True : United
"""
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.root[x] > self.root[y]:
x, y = y, x
self.root[x] += self.root[y]
self.root[y] = x
return True
def same(self, x: int, y: int):
"""
Determine if x and y are in same set.
Parameters
----------
x, y : int
Node number
Returns
-------
result : bool
Determining result
"""
return self.find(x) == self.find(y)
def size(self, x: int) -> bool:
"""
Return size of set including node x.
Parameters
----------
x : int
Node number
Returns
-------
Size of set : int
"""
return self.root[self.find(x)] * -1
def main():
N, M = map(int, input().split())
lst = UnionFind(N)
for _ in range(M):
a, b = map(int, input().split())
lst.unite(a - 1, b - 1)
ans = -1
for i in lst.root:
if i < 0:
ans += 1
print(ans)
# print(lst.root)
if __name__ == '__main__':
main()
| k,x = [int(i) for i in input().split()]
ans=''
if k*500 >= x: ans = 'Yes'
else: ans='No'
print(ans)
| 0 | null | 50,113,359,139,052 | 70 | 244 |
N = int(input())
dic = {}
ans = 0
A = list(map(int, input().split()))
for i in range(N):
dic[i] = 0
for i in range(N):
b = A[i]+N-i-1
if A[i] < N-i:
a = N-i-A[i]-1
dic[a] += 1
if b < N:
ans += dic[b]
print(ans) | from collections import Counter
N = int(input())
A = list(map(int, input().split()))
p = [i+Ai for i, Ai in zip(range(1, N+1), A)]
q = [j-Aj for j, Aj in zip(range(1, N+1), A)]
pc = Counter(p)
qc = Counter(q)
r = sum(pc[k]*qc[k] for k in pc.keys() & qc.keys())
print(r) | 1 | 25,960,726,571,890 | null | 157 | 157 |
from random import random
class Node:
def __init__(self, key, value:int=-1):
self.left = None
self.right = None
self.key = key
self.value = value
self.priority = int(random()*10**7)
# self.count_partial = 1
self.sum_partial = value
class Treap:
#Node [left, right, key, value, priority, num_partial, sum_partial]
def __init__(self):
self.root = None
def update(self, node) -> Node:
if node.left is None:
# left_count = 0
left_sum = 0
else:
# left_count = node.left.count_partial
left_sum = node.left.sum_partial
if node.right is None:
# right_count = 0
right_sum = 0
else:
# right_count = node.right.count_partial
right_sum = node.right.sum_partial
# node.count_partial = left_count + right_count + 1
node.sum_partial = left_sum + node.value + right_sum
return node
def merge(self, left :Node, right:Node):
if left is None or right is None:
return left if right is None else right
if left.priority > right.priority:
left.right = self.merge(left.right,right)
return self.update(left)
else:
right.left = self.merge(left,right.left)
return self.update(right)
# def node_size(self, node:Node) -> int:
# return 0 if node is None else node.count_partial
def node_key(self, node: Node) -> int:
return -1 if node is None or node.key is None else node.key
def node_sum(self, node: Node) -> int:
return 0 if node is None else node.sum_partial
#指定された場所のノードは右の木に含まれる
def split(self, node:None, key:int) -> (Node, Node):
if node is None:
return None,None
if key <= self.node_key(node):
left,right = self.split(node.left, key)
node.left = right
return left, self.update(node)
else:
left,right = self.split(node.right, key)
node.right = left
return self.update(node),right
def insert(self, key:int, value:int =-1):
value = value if value > 0 else key
left, right = self.split(self.root, key)
new_node = Node(key,value)
self.root = self.merge(self.merge(left,new_node),right)
def erase(self, key:int):
# print('erase pos=',pos,'num=',self.search(pos),'num_nodes=',self.root.count_partial)
middle,right = self.split(self.root, key+1)
# print(middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,right.value if right is not None else -1,right.count_partial if right is not None else -1)
left,middle = self.split(middle, key)
# print(left.value if left is not None else -1,left.count_partial if left is not None else -1, middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,)
self.root = self.merge(left,right)
def printTree(self, node=None, level=0):
node = self.root if node is None else node
if node is None:
print('level=',level,'root is None')
return
else:
print('level=',level,'k=',node.key,'v=',node.value, 'p=',node.priority)
if node.left is not None:
print('left')
self.printTree(node.left,level+1)
if node.right is not None:
print('right')
self.printTree(node.right,level+1)
def find(self, key):
#return self.search_recursively(pos,self.root)
v = self.root
while v:
v_key = self.node_key(v)
if key == v_key:
return v.value
elif key < v_key:
v = v.left
else:
v = v.right
return -1
def interval_sum(self, left_key, right_key):
lt_left, ge_left = self.split(self.root,left_key)
left_to_right, gt_right = self.split(ge_left, right_key + 1)
res = self.node_sum(left_to_right)
self.root = self.merge(lt_left, self.merge(left_to_right, gt_right))
return res
def main():
from sys import setrecursionlimit, stdin, stderr
from os import environ
from collections import defaultdict, deque, Counter
from math import ceil, floor
from itertools import accumulate, combinations, combinations_with_replacement
setrecursionlimit(10**6)
dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
input = lambda: stdin.readline().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
P = 10**9+7
INF = 10**18+10
N,D,A = LMIIS()
enemies = []
for i in range(N):
x, h = LMIIS()
enemies.append((x, ceil(h/A)))
enemies.sort()
bomb = Treap()
ans = 0
for i, (x, h) in enumerate(enemies):
left = x - D
right = x + D
remain_h = h - bomb.interval_sum(left, right)
if remain_h <= 0:
continue
ans += remain_h
bomb.insert(x + D, remain_h)
print(ans)
main() | #problems2
#silver fox vs monster
import math
N,D,A=map(int,input().split())
d=[]
for _ in range(N):
x,h=map(int,input().split())
d.append((x,h))
d.sort(key=lambda x:x[0])
now_damage=0
from collections import deque
d=deque(d)
ans=0
d_field=deque()
while d:
x=d.popleft()
place,life=x
if d_field:
while (d_field and d_field[0][0]<place) :
now_damage-=A*d_field[0][1]
d_field.popleft()
if life<=now_damage:
pass
elif life>now_damage:
K=math.ceil((life-now_damage)/A)
ans+=K
now_damage+=K*A
d_field.append((2*D+place,K))
print(ans)
| 1 | 82,241,686,356,520 | null | 230 | 230 |
import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
N0 = 2**(N.bit_length())
st = [0] * (N0*2)
def gindex(l, r):
L = l + N0; R = r + N0
lm = (L // (L & -L)) // 2
rm = (R // (R & -R)) // 2
while L < R:
if R <= rm:
yield R - 1
if L <= lm:
yield L - 1
L //= 2; R //= 2
while L > 0:
yield L - 1
L //= 2
def update(i,s):
x = 2 ** (ord(s) - ord('a'))
i += N0-1
st[i] = x
while i > 0:
i = (i-1) // 2
st[i] = st[i*2+1] | st[i*2+2]
def query(l,r):
l += N0
r += N0
ret = 0
while l < r:
if l % 2:
ret |= st[l-1]
l += 1
if r % 2:
r -= 1
ret |= st[r-1]
l //= 2 ; r //= 2
return ret
for i,s in enumerate(sys.stdin.readline().rstrip()):
update(i+1,s)
Q = NI()
for _ in range(Q):
c,a,b = sys.stdin.readline().split()
if c == '1':
update(int(a),b)
else:
ret = query(int(a),int(b)+1)
cnt = 0
b = 1
for i in range(26):
cnt += (b & ret) > 0
b <<= 1
print(cnt)
if __name__ == '__main__':
main() | n = int(input())
L = [0]*n
for i in range(n):
L[i] = chr(i+ord('a'))
#print(L)_
ans = []
def dfs(A):
if len(A) == n:
ans.append(''.join(A))
return
for v in L[0:len(set(A))+1]:
A.append(v)
dfs(A)
A.pop()
dfs([])
ans.sort()
for i in range(len(ans)):
print(ans[i])
| 0 | null | 57,674,891,962,240 | 210 | 198 |
# -*- coding: utf-8 -*-
import sys
N=input()
bit=[ [ 0 for _ in range(N+1) ] for __ in range(27) ]
def add(i,a,w):
while a<=N:
bit[i][a]+=w
a+=a&-a
def sum(i,a):
ret=0
while 0<a:
ret+=bit[i][a]
a-=a&-a
return ret
S=sys.stdin.readline().strip()
S=[None]+list(S) #1-indexed
for j,x in enumerate(S):
if j==0: continue
i=ord(x)-96
add(i,j,1)
Q=input()
for _ in range(Q):
q1,q2,q3=sys.stdin.readline().split()
if q1=="1":
q1=int(q1)
q2=int(q2)
current_s=q3
former_s=S[q2]
former_s=ord(former_s)-96 #1-indexed
S[q2]=current_s #文字列で更新された1文字を置き換える
current_s=ord(current_s)-96
add(current_s,q2,1)
add(former_s,q2,-1)
if q1=="2":
q2=int(q2)
q3=int(q3)
begin,end=q2,q3
cnt=0
for i in range(1,27):
if 0<sum(i,end)-sum(i,begin-1):
cnt+=1
print cnt | L, R, D = map(int, input().split())
counter = 0
for i in range(L, R + 1):
if i % D == 0:
counter+= 1
print(counter) | 0 | null | 35,073,578,501,078 | 210 | 104 |
print(len(max((input().split('S'))))) | from sys import stdin
N = int(stdin.readline().rstrip())
C = stdin.readline().rstrip()
rc = C.count('R')
ans = 0
for i in range(rc):
if C[i] == 'W':
ans += 1
print(ans) | 0 | null | 5,625,569,047,100 | 90 | 98 |
X = int(input())
i = 1
while (360*i) % X != 0:
i += 1
ans = 360*i//X
print(ans)
| a = int(input())
if a % 2 == 0 :
print((a - a / 2 ) / a)
else:
print((a - a // 2) / a)
# 5 ,4 ,3 ,2 ,1
# 3 /5 | 0 | null | 94,766,268,839,802 | 125 | 297 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
G = [0]*3
ans = 1
for i in range(N):
x = 0
cnt = 0
for j, g in enumerate(G):
if g == A[i]:
x = j if cnt == 0 else x
cnt += 1
G[x] += 1
ans *= cnt
ans = ans % mod
print(ans) | A,B = map(int, input().split())
C,D = map(int, input().split())
if D == 1:
print("1")
else:
print("0") | 0 | null | 126,942,768,326,780 | 268 | 264 |
from itertools import permutations
from math import sqrt, pow, factorial
N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]
def calc(a, b):
[x1, y1] = a
[x2, y2] = b
return sqrt(pow(x1 - x2, 2) + pow(y1 -y2, 2))
ans = 0
for order in permutations(range(N)):
tmp = 0
for i in range(1, N):
tmp += calc(l[order[i]], l[order[i-1]])
ans += tmp
print(ans/factorial(N))
| from collections import deque
h,w=map(int,input().split())
s=[input() for _ in range(h)] #マップ
vi=[ [-1 for _ in range(w)] for _ in range(h)]#visit
st=deque()
d=[[0,1],[-1,0],[1,0],[0,-1]]
mx=0
for i in range(h):
for j in range(w):
vi=[ [-1 for _ in range(w)] for _ in range(h)]
st.append([i,j,0])
while st:
h1,w1,k=st.popleft()
if 0<=h1<h and 0<=w1<w and vi[h1][w1]==-1 and s[h1][w1]==".":
vi[h1][w1]=k
for m in d:
st.append([h1+m[0],w1+m[1],k+1])
for m in vi:
mx=max(mx,max(m))
print(mx) | 0 | null | 121,425,772,414,940 | 280 | 241 |
while True:
a,b=map(int,input().split())
if (a==0 and b==0):
break
if a>b:
swap=a
a=b
b=swap
print('%d %d'%(a,b))
| # -*- 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) | 0 | null | 70,513,618,753,578 | 43 | 275 |
X,Y,Z = map(str, input().split())
ans = [Z,X,Y]
print(" ".join(ans)) | x, y, z = map(int,input().split())
x, y = y, x
x, z = z, x
print(str(x) + " " + str(y) + " " + str(z)) | 1 | 38,171,344,054,560 | null | 178 | 178 |
input()
A = list([int(i) for i in input().split()])
print(min(A),max(A),sum(A)) | num = int(input())
inVal = input().split()
sum = 0
result = []
for n in range(num):
result.append(int(inVal[n]))
sum = sum + int(inVal[n])
print(str(min(result)) + " " + str(max(result)) + " " + str(sum))
| 1 | 719,619,677,050 | null | 48 | 48 |
s=input()
if s[-1]!='s':print(s+'s')
else:print(s+'es') | import math
while True:
n = int(input())
if n == 0: break
s = list(map(int, input().split()))
ave = sum(s) / n
S = []
for i in range(n):
key = ave - s[i]
S.append(key * key)
print('{:.5f}'.format(math.sqrt(sum(S) / n)))
| 0 | null | 1,289,284,048,140 | 71 | 31 |
n = int(input())
s, t = map(str, input().split())
ans = ''
for a, b in zip(s, t):
ans += a+b
print(ans) | N = int(input())
S, T = input().split()
A = ""
for i in range(N):
A += S[i] + T[i]
print(A) | 1 | 111,924,667,116,000 | null | 255 | 255 |
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function,division
from itertools import combinations
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
def enum_sum_numbers(sets, s_range, r):
for cmb in combinations(sets,r):
yield sum(cmb)
if r <=s_range:
for s in enum_sum_numbers(sets,s_range, r+1):
yield s
sys.stdin.readline()
a=[int(s) for s in sys.stdin.readline().split()]
sys.stdin.readline()
ms=[int(s) for s in sys.stdin.readline().split()]
sets={s for s in enum_sum_numbers(a,len(a),1)}
for m in ms:
print('yes' if m in sets else 'no') | # coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
myhand = [None] * n
point = 0
for i in range(n):
if t[i] == "r":
if myhand[i] != "np":
point += p
if i+k < n:
myhand[i+k] = "np"
else:
if i+k < n:
myhand[i + k] = None
elif t[i] == "s":
if myhand[i] != "nr":
point += r
if i+k < n:
myhand[i+k] = "nr"
else:
if i+k < n:
myhand[i + k] = None
elif t[i] == "p":
if myhand[i] != "ns":
point += s
if i+k < n:
myhand[i+k] = "ns"
else:
if i+k < n:
myhand[i + k] = None
print(point)
if __name__ == '__main__':
main()
| 0 | null | 53,719,517,612,490 | 25 | 251 |
rStr = input()
N = int(rStr.split(' ')[0])
M = int(rStr.split(' ')[1])
if N == M :
print("Yes")
else :
print("No")
| print("Yes" if len(set(input().split()))==1 else "No") | 1 | 83,033,967,632,066 | null | 231 | 231 |
def main():
n = int(input())
a_lst = list(map(int, input().split()))
q = int(input())
bc_lst = [list(map(int, input().split())) for _ in range(q)]
a_max = max(a_lst)
bc_max = 0
for i in range(q):
b = bc_lst[i][0]
c = bc_lst[i][1]
bc_max = max(b, bc_max)
bc_max = max(c, bc_max)
maximum = max(a_max, bc_max)
count_lst = [0] * maximum
for i in range(n):
a = a_lst[i]
count_lst[a - 1] += 1
tmp = sum(a_lst)
for i in range(q):
b = bc_lst[i][0]
c = bc_lst[i][1]
count = count_lst[b - 1]
tmp += count * (c - b)
count_lst[b - 1] = 0
count_lst[c - 1] += count
print(tmp)
if __name__ == '__main__':
main() | S = raw_input()
S1, S2 = [], []
ans = pool = 0
for i in xrange(len(S)):
if S[i] == "/" and len(S1) > 0:
j = S1.pop()
ans += i - j
a = i - j
while (len(S2) > 0 and S2[-1][0] > j):
a += S2.pop()[1]
S2.append([j, a])
if S[i] == "\\":
S1.append(i)
print ans
if len(S2) > 0:
print len(S2), " ".join(map(str, [a for j, a in S2]))
else:
print 0 | 0 | null | 6,060,967,452,220 | 122 | 21 |
N=int(raw_input())
max=(-1)*(10**9)
x1=input()
min=x1
for i in range(N-1):
x=int(raw_input())
if max < x-min:
max=x-min
if min>x:
min=x
print max | n=int(input())
if(n//2==n/2):
m=n//2
else:
m=n//2+1
print(m) | 0 | null | 29,701,901,848,572 | 13 | 206 |
A, B = map(int, input().split())
n = 1
while True:
A_ = A * n
if A_ % B == 0:
print(A_)
exit()
n += 1 | import math , sys
N = int( input() )
A = list( map( int, input().split() ) )
Q = int( input() )
count = [0 for _ in range( 10**5 + 1)]
for each in A:
count[each]+=1
ans = sum(A)
for _ in range(Q):
B , C = list( map( int , input().split() ) )
D = count[B]
ans += (C-B) * D
count[B] = 0
count[C] += D
print(ans)
| 0 | null | 63,031,431,521,500 | 256 | 122 |
N = int(input())
def isnot_fizzbuzz(number: int) -> bool:
if (number) % 3 != 0 and (number) % 5 != 0:
return True
return False
def main():
sum = 0
for number in range(1, N + 1):
if isnot_fizzbuzz(number) == True:
sum += number
print(sum)
if __name__ == "__main__":
main() | import sys,math,collections,itertools
input = sys.stdin.readline
N,K=list(map(int,input().split()))
R,S,P=list(map(int,input().split()))
T = input().rstrip()
s =T.replace('r','P') #P
ss=s.replace('s','R') #R
sss=ss.replace('p','S') #S
sl = list(sss)
for i in range(K,N):
if sl[i]==sl[i-K]:
sl[i] = '0'
sc = collections.Counter(sl)
print(sc['R']*R + sc['P']*P + sc['S']*S)
| 0 | null | 70,609,754,208,960 | 173 | 251 |
# input here
_INPUT = """\
2 5
1 WA
1 AC
2 WA
2 AC
2 WA
2 AC
"""
def main():
n, m= map(int, input().split())
ps = [list(map(str,input().split())) for _ in range(m)]
str_l = ["WA"]*n
int_l = [0]*n
num = 0
ac = 0
for pp, s in ps:
p = int(pp)-1
if s == "AC":
str_l[p] = "AC"
else:
if str_l[p] != "AC":
int_l[p] += 1
for i in range(n):
if str_l[i] == "AC":
num += int_l[i]
ac += 1
print(ac,num)
# n, m = map(int, input().split())
# seikai = [False] * n
# matigai = [0] * n
# for i in range(m):
# p,q = map(str, input().split())
# p = int(p)-1
# if q == "AC":
# seikai[p] = True
# else:
# if seikai[p] != True:
# matigai[p] += 1
# correct = seikai.count(True)
# mistake = sum(matigai)
# print(correct, mistake)
if __name__ == '__main__':
import io
import sys
import math
import itertools
from collections import deque
# sys.stdin = io.StringIO(_INPUT)
main() | # -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 01:13:08 2020
@author: liang
"""
"""
ABC 171 D 差分更新 パケット変換
【無駄な探索は行わない(メモリ化) ⇒ パケット変換】
パケット
値vが出現する回数を記録しておく
dict()方式 ⇒ 探索にO(logn) or O(n)がかかる
配列方式 ⇒ 探索がO(1)となる!
【差分更新】
値Bが全て値Cになる
⇒ (C - B) * 値Bの個数だけ増加する
⇒ 値Cの個数 += 値Bの個数
⇒ 値Bの個数 = 0
"""
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
d = [0]*(10**5)
for i in A:
d[i-1] += 1
ans = sum(A)
for i in range(Q):
b, c = map(int,input().split())
ans += (c-b)*d[b-1]
d[c-1] += d[b-1]
d[b-1] = 0
print(ans) | 0 | null | 52,954,421,725,830 | 240 | 122 |
MOD = 10**9 + 7
MAX = int(2e5)
def div(a, b):
return a * pow(b, MOD-2, MOD) % MOD
FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
INV[i-1] = (INV[i] * i) % MOD
def main():
n, k = map(int, input().split())
ans = 0
for i in range(min(n-1, k)+1):
# iCn
# (n-i-1)C(n-1)
tmp = FACT[n] * INV[i] * INV[n-i] % MOD
tmp = (tmp * FACT[n-1] * INV[n-i-1] * INV[i]) % MOD
ans = (ans + tmp) % MOD
print(ans)
if __name__ == "__main__":
main()
| n, k = map(int, input().split())
mod = 10 ** 9 + 7
class ModInt:
def __init__(self, num, mod):
self.num = num
self.mod = mod
def __str__(self):
return str(self.num)
def __repr__(self):
return "ModInt(num: {}, mod: {}".format(self.num, self.mod)
def __add__(self, other):
ret = self.num + other.num
ret %= self.mod
return ModInt(ret, self.mod)
def __sub__(self, other):
ret = self.num - other.num
ret %= self.mod
return ModInt(ret, self.mod)
def __mul__(self, other):
ret = self.num * other.num
ret %= self.mod
return ModInt(ret, self.mod)
def pow(self, times):
pw = pow(self.num, times, self.mod)
return ModInt(pw, self.mod)
def inverse(self):
return self.pow(self.mod - 2)
def __truediv__(self, other):
num = self * other.inverse()
return ModInt(num, self.mod)
class Combination:
def __init__(self, n, mod):
self.mod = mod
self.fact = [ModInt(1, mod)]
self.inverse = [ModInt(1, mod)]
for i in range(1, n + 1):
self.fact.append(self.fact[-1] * ModInt(i, mod))
self.inverse.append(self.inverse[-1] * ModInt(i, mod).inverse())
def comb(self, n, k):
if k < 0 or n < k:
return ModInt(0, self.mod)
return self.fact[n] * self.inverse[k] * self.inverse[n-k]
mx = min(k, n - 1)
comb = Combination(n, mod)
ans = ModInt(0, mod)
for i in range(mx + 1):
ans += comb.comb(n, i) * comb.comb(n - 1, i)
print(ans)
| 1 | 67,075,245,904,008 | null | 215 | 215 |
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
a = max(A)
prime_num = [2]
sgn = [0 for _ in range(max(int(a**0.5)+1, 4))]
sgn[2] = 1
for k in range(3, len(sgn), 2):
if sgn[k] == 0:
prime_num.append(k)
for j in range(k, a+1, k**2):
sgn[k] = 1
baisu = []
count = [0 for _ in range(a+1)]
for k in range(N):
b = 0 + A[k]
for p in prime_num:
if p**2 <= b:
if b%p == 0:
if count[p] == 0:
baisu.append(p)
c = 0
while b % p == 0:
b //= p
c += 1
if c > count[p]:
count[p] = c
else:
break
if b != 1:
if count[b] == 0:
count[b] = 1
baisu.append(b)
product = 1
for item in baisu:
product *= pow(item, count[item], mod)
product %= mod
b = mod-2
blis = []
c = 0
while b >0:
if b & 1 == 1:
blis.append(c)
c += 1
b >>= 1
def modinv(a):
if a == 1:
return 1
else:
res = 1
li = []
for _ in range(c):
li.append(a%mod)
a = a*a%mod
for item in blis:
res = res *li[item] %mod
return res
ans = 0
for k in range(N):
ans += product*modinv(A[k])
ans %= mod
print(ans)
| import collections
n = int(input())
A = list(map(int, input().split()))
q = int(input())
CNT = collections.Counter(A)
ANS = []
ans = sum(A)
for i in range(q):
b, c = map(int, input().split())
t = CNT[b]
ans +=(c - b) * t
ANS.append(ans)
CNT[c] += t
CNT[b] = 0
for i in ANS:
print(i) | 0 | null | 50,182,467,867,210 | 235 | 122 |
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
########################################################
F=[1]*(10**6+1)
for i in range(2,10**6+1):
for j in range(i,10**6+1,i):
F[j]+=1
ans=0
n=int(input())
for c in range(1,n):
ans+=F[n-c]
print(ans)
| from math import log2, ceil
H = int(input())
print(2**(ceil(log2(H))+1 if log2(H).is_integer() else ceil(log2(H))) - 1) | 0 | null | 41,167,333,310,778 | 73 | 228 |
S=input()
l=["SUN","MON","TUE","WED","THU","FRI","SAT"]
for i in range(len(l)):
if S==l[i]:
print(7-i)
break | A, B, C, D = map(int, input().split())
def battle(x_hp, x_atk, y_hp, y_atk):
turn = 0
while 1:
if turn == 0:
y_hp -= x_atk
if y_hp < 1:
return "Yes"
else:
x_hp -= y_atk
if x_hp < 1:
return "No"
turn = 1 - turn
print(battle(A, B, C, D)) | 0 | null | 81,261,973,879,398 | 270 | 164 |
a,b = input().split()
aa,bb = int(a),int(b)
print(a * bb if a * bb < b * aa else b * aa) | a,b=map(int,input().split())
a1=f"{a}"*b
b1=f"{b}"*a
print(a1 if a1<b1 else b1) | 1 | 84,324,761,420,540 | null | 232 | 232 |
n = int(input())
A = list(map(int, input().split()))
ans = 1
A = sorted(A)
for i in range(n):
ans *= A[i]
if ans > 10**(18):
print('-1')
exit()
print(ans) | n = int(input())
a = list(map(int,input().split()))
a.sort()
t = 1
for i in range(len(a)):
t *= a[i]
if t > 10**18:
break
if t > 10**18 :
print("-1")
else:
print(str(t)) | 1 | 16,162,608,360,260 | null | 134 | 134 |
M=10**9+7
n,k=map(int,input().split())
l=[1]
f=1
for i in range(n):
f=f*(i+1)%M
l+=[f]
a=0
for i in range(min(n,k+1)):
c=l[n]*l[n-1]%M
p=l[i]**2*l[n-i]*l[n-i-1]%M
a+=c*pow(p,M-2,M)
print(a%M) | """
E
"""
mod=10**9+7
MAX=4*10**5+100
g1=[1,1]
for i in range(2,MAX+1):
num_1=g1[-1]*i%mod
g1.append(num_1)
def cmb(n,r):
return g1[n]*pow(g1[r],mod-2,mod)*pow(g1[n-r],mod-2,mod)%mod
N,K=map(int,input().split())
ans=cmb(2*N-1,N)
if K>=N:
print(ans)
else:
num=cmb(N,N-K-1)
S=0
for i in range(N-K-1,0,-1):
S=(S+cmb(N-1,i-1)*cmb(N,i))%mod
ans=(ans-S)%mod
print(ans) | 1 | 67,259,255,192,812 | null | 215 | 215 |
n, m = map(int, input().split())
a = list(map(int, input().split()))
print("Yes" if len([i for i in a if i/sum(a) >= 1/(4 * m)]) >= m else "No") | import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N,M=mi()
A=list(mi())
sum_vote = sum(A)
count = 0
for a in A:
if a >= sum_vote / (4*M):
count +=1
print("Yes" if count >= M else "No")
if __name__ == "__main__":
main() | 1 | 38,731,183,959,820 | null | 179 | 179 |
# def f(n):
# if n < 2:
# return 1
# else:
# return n * f(n - 2)
# for i in range(2, 150, 2):
# print(i, f(i))
N = int(input())
if N % 2 == 1:
print(0)
exit()
k = 10
cnt = 0
while k <= N:
cnt += N // k
k *= 5
print(cnt)
| n = int(input())
res = 0
if n % 2 == 0:
for i in range(1,30):
p = n // (5 ** i)
#print(i,p)
if p % 2 == 1:
res += (p-1) // 2
else:
res += p // 2
print(res) | 1 | 115,818,355,850,198 | null | 258 | 258 |
h = int(input())
for i in range(100):
if 2**i > h:
print(2**i - 1)
exit() | h = int(input())
cnt = 0
num = 1
while h!=1:
cnt += num
num *= 2
h = h//2
else:
cnt += num
print(cnt)
| 1 | 80,326,677,338,464 | null | 228 | 228 |
import sys
MOD = 10**9+7
def main():
input = sys.stdin.readline
N,K=map(int, input().split())
ans=Mint()
cnt=[Mint() for _ in range(K+1)]
for g in range(K,0,-1):
cnt[g]+=pow(K//g,N,MOD)
for h in range(g+g,K+1,g):
cnt[g]-=cnt[h]
ans+=g*cnt[g]
print(ans)
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0: self.value += MOD
@staticmethod
def get_value(x): return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0: u += MOD
return u
def __repr__(self): return str(self.value)
def __eq__(self, other): return self.value == other.value
def __neg__(self): return Mint(-self.value)
def __hash__(self): return hash(self.value)
def __bool__(self): return self.value != 0
def __iadd__(self, other):
self.value = (self.value + Mint.get_value(other)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0: self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
if __name__ == '__main__':
main() | n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
m = arr[-1]
li = [0]*(m+1)
cnt = 0
for i in arr:
for j in range(i, m+1, i):
li[j] += 1
for i in arr:
if li[i] == 1:
cnt += 1
print(cnt) | 0 | null | 25,519,947,072,270 | 176 | 129 |
from itertools import product
[N, M, X] = [int(i) for i in input().split()]
bk = [[int(i) for i in input().split()] for _ in range(N)]
ans = 12*10**5 + 1
for seq in product(range(2), repeat=N):
S = [0]*(M+1)
for i in range(N):
for j in range(M+1):
S[j] += seq[i]*bk[i][j]
if min(S[1:M+1]) >= X:
ans = min(ans, S[0])
if ans == 12*10**5 + 1:
print(-1)
else:
print(ans) | n, m, x = map(int, input().split())
books_info = []
price_info = []
for i in range(n):
c, *a = map(int, input().split())
books_info.append(a)
price_info.append(c)
pattern_list = []
for j in range(2 ** n):
tmp_list = []
for k in range(n):
if ((j >> k) & 1):
tmp_list.append(k)
else:
pass
pattern_list.append(tmp_list)
book_price = 10 ** 5 * 12 + 1
for pattern in pattern_list:
# 全ての参考書を買わない=len(pattern)が0の場合はスキップする
if len(pattern) == 0:
continue
is_ok = False
price = 0
for j in range(m):
m_sum = 0
price_sum = 0
for k in pattern:
m_sum += books_info[k][j]
price_sum += price_info[k]
if m_sum >= x:
is_ok = True
else:
is_ok = False
break
price = price_sum
if is_ok == True:
book_price = min(price, book_price)
else:
pass
print(book_price if book_price != 10 ** 5 * 12 + 1 else -1)
| 1 | 22,296,065,961,052 | null | 149 | 149 |
l = [i for i in range(1,10)]
for i in l:
for j in l:
print(str(i)+ 'x' + str(j) + '=' + str(i*j)) | # usr/bin/python
# coding: utf-8
################################################################################
#Write a program which prints multiplication tables in the following format:
#
#1x1=1
#1x2=2
#.
#.
#9x8=72
#9x9=81
#
################################################################################
if __name__ == "__main__":
for i in range(1, 10):
for j in range(1, 10):
print("{0}x{1}={2}".format(i,j,i*j))
exit(0) | 1 | 1,839,640 | null | 1 | 1 |
n, m = map(int, input().split())
temp = list(['?'] * n)
# print(temp)
if (m == 0):
if (n == 1):
ans = 0
else:
ans = '1' + '0' * (n - 1)
else:
for _ in range(m):
s, c = map(int, input().split())
if (s == 1 and c == 0 and n >= 2):
print(-1)
exit()
else:
pass
if (temp[s-1] == '?'):
temp[s - 1] = str(c)
elif (temp[s - 1] == str(c)):
pass
else:
print(-1)
exit()
if (temp[0] == '?'):
temp[0] = '1'
ans01 = ''.join(temp)
ans = ans01.replace('?', '0')
print(ans)
| N = int(input())
if N % 1000 == 0:
print(0)
else:
payment = N // 1000 + 1
change = payment*1000 - N
print(change)
| 0 | null | 34,420,295,412,628 | 208 | 108 |
def main():
a = int(input())
b = int(input())
if a == 1 and b == 2 or a == 2 and b == 1:
print(3)
elif a == 2 and b == 3 or a == 3 and b == 2:
print(1)
elif a == 3 and b == 1 or a == 1 and b == 3:
print(2)
if __name__ == '__main__':
main() | f = list(map(str, [1, 2, 3]))
f.remove(input())
f.remove(input())
print(f[0]) | 1 | 111,088,186,728,998 | null | 254 | 254 |
import itertools
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sum_a=list(itertools.accumulate(a))
sum_b=list(itertools.accumulate(b))
result=bisect.bisect_right(sum_b,k)
for i in range(n):
if sum_a[i]<=k:
result=max(result,i+1+bisect.bisect_right(sum_b,k-sum_a[i]))
print(result) | print("Yes" if int(input())%9 == 0 else "No") | 0 | null | 7,624,807,693,438 | 117 | 87 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n=int(input())
l=[input().split() for i in range(n)]
x=input()
ans=0
c=False
for s,t in l:
if c:
ans+=int(t)
if x==s:
c=True
print(ans) | # coding: utf-8
from math import sqrt
def solve(*args: str) -> str:
k = int(args[0])
l = 9*(k//7 if 0 == k % 7 else k)
if 0 == l % 2 or 0 == l % 5:
return '-1'
r = phi = l
for i in range(2, int(sqrt(l)+1)):
if 0 == r % i:
phi = phi*(i-1)//i
while 0 == r % i:
r //= i
if 1 < r:
phi = phi*(r-1)//r
D = set()
for d in range(1, int(sqrt(phi)+1)):
if 0 == phi % d:
D.add(d)
D.add(phi//d)
ret = -1
for m in sorted(D):
if 1 == pow(10, m, l):
ret = m
break
return str(ret)
if __name__ == "__main__":
print(solve(*(open(0).read().splitlines())))
| 0 | null | 51,387,501,112,428 | 243 | 97 |
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**6
for i in range(m):
x,y,c=map(int,input().split())
ans=min(ans,a[x-1]+b[y-1]-c)
print(min(ans,min(a)+min(b))) | import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
A,B,M = II()
a = LI()
b = LI()
ticket = [LI() for _ in range(M)]
cost = min(a) + min(b)
costl = [a[t[0]-1] + b[t[1]-1] - t[2] for t in ticket]
print(min(cost,min(costl))) | 1 | 53,784,294,403,280 | null | 200 | 200 |
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
for j in range(i-1, 0, -1):
a, b = L[i], L[j]
c = a - b + 1
if c > b: continue
ans += (j - bisect.bisect_left(L, c))
print(ans) | a=sorted(list(map(int,input().split())));print(*a)
| 0 | null | 85,919,179,181,540 | 294 | 40 |
n = int(input())
x = list(input())
sx = len(set(x))
if sx == 1:
print(0)
exit()
cnt_r = x.count("R")
cnt = 0
for i in range(cnt_r):
if x[i] == "W":
cnt += 1
print(cnt) | N = int(input())
C = list(input())
Rn = C.count('R')
print(C[:Rn].count('W')) | 1 | 6,293,620,113,212 | null | 98 | 98 |
listA=[]
listOP=[]
listB=[]
count=0
while True:
a,op,b=input().split()
listA.append(int(a))
listOP.append(op)
listB.append(int(b))
if op=="?":
del listA[len(listA)-1]
del listOP[len(listOP)-1]
del listB[len(listB)-1]
break
#入力パートここまで。計算出力パートここから
while count<=len(listA)-1:
if listOP[count]=="+":
print(listA[count]+listB[count])
elif listOP[count]=="-":
print(listA[count]-listB[count])
elif listOP[count]=="*":
print(listA[count]*listB[count])
elif listOP[count]=="/":
print(listA[count]//listB[count])
else:
print("ERROR")
count+=1
| #!/usr/bin python3
# -*- coding: utf-8 -*-
mod = 10**9+7
n = int(input())
ret = 0
ret += pow(10,n,mod)
ret -= 2 * pow(9,n,mod)
ret %= mod
ret += pow(8,n,mod)
ret %= mod
print(ret)
| 0 | null | 1,895,905,016,738 | 47 | 78 |
def main():
x = int(input())
print((2199 - x) // 200)
if __name__ == '__main__':
main()
| x=float(input())
for i in range(8):
if 400+200*i<=x<400+200*(i+1):
print(8-i) | 1 | 6,758,809,648,910 | null | 100 | 100 |
#create date: 2020-06-30 22:48
import sys
stdin = sys.stdin
from itertools import product
def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def main():
n = ni()
t = [[-1] * n for _ in range(n)]
for j in range(n):
a = ni()
for i in range(a):
x, y = na()
t[j][x-1] = y
l = list(product([0, 1], repeat=n))
ans = 0
#print(t)
for li in l:
f = True
for i in range(n):
people = li[i]
if people:
for j in range(n):
if t[i][j] == 1 and li[j] == 0:
f = False
if t[i][j] == 0 and li[j] == 1:
f = False
if f:
#print(li, f)
ans = max(ans, sum(li))
print(ans)
if __name__ == "__main__":
main() | a,b,c,d=map(float,input().split())
x=abs(a-c)
y=abs(b-d)
z=x**2+y**2
print(pow(z,0.5))
| 0 | null | 61,023,592,256,000 | 262 | 29 |
N = int(input())
a = [list(map(int,input().split())) for i in range(N)]
d = 0
for i in range(N-1):
for j in range(i+1,N):
d += ((a[i][0]-a[j][0])**2 + (a[i][1]-a[j][1])**2)**(1/2)
print(2*d/N) | import itertools
import math
def calc_dist(pos1, pos2):
x1,y1=pos1
x2,y2=pos2
return math.sqrt(pow(x1-x2, 2)+pow(y1-y2, 2))
N=int(input())
distance_mat = [[-1000 for _ in range(N)] for _ in range(N)]
pos = []
for _ in range(N):
pos.append(list(map(int, input().split())))
perms = itertools.permutations(list(range(N)), N)
result=[]
for perm in perms:
dist_sum = 0
for i in range(1, N):
source = perm[i-1]
sink = perm[i]
if distance_mat[source][sink]==-1000:
dist = calc_dist(pos[source], pos[sink])
distance_mat[source][sink] = dist
distance_mat[sink][source] = dist
else:
dist = distance_mat[source][sink]
dist_sum+=dist
result.append(dist_sum)
import numpy as np
print(np.average(result))
| 1 | 148,133,768,906,264 | null | 280 | 280 |
raw_input()
num_list = map(int, raw_input().split(" "))
print "%d %d %d" % (min(num_list), max(num_list), sum(num_list)) | from scipy.special import comb
S = int(input())
ans = 0
mod = 10**9+7
for i in range(3, S+1, 3):
ans = (ans +comb(S-2*(i//3)-1, i//3-1, exact=True)) % mod
print(ans)
| 0 | null | 1,977,845,581,920 | 48 | 79 |
def main():
N = input()
a = map(int, raw_input().split())
print ' '.join(map(str,a))
for i in xrange(1,len(a)):
v = a[i]
j = i - 1
while (j >= 0) & (a[j] > v):
a[j+1] = a[j]
j -= 1
a[j+1] = v
print ' '.join(map(str,a))
return 0
main() | n = input()
k = int(input())
digit = len(n)
dp0 = [[0 for i in range(k+1)] for j in range(digit+1)]
dp1 = [[0 for i in range(k+1)] for j in range(digit+1)]
dp1[1][1] = 1
dp0[1][1] = int(n[0])-1
for i in range(1, digit+1):
dp0[i][0] = 1
for i in range(2, digit+1):
for j in range(1, k+1):
num = int(n[i-1])
if num == 0:
dp0[i][j] = dp0[i-1][j-1]*9 + dp0[i-1][j]
dp1[i][j] = dp1[i-1][j]
else:
dp0[i][j] = dp0[i-1][j-1]*9 + dp0[i-1][j] + dp1[i-1][j-1] * (num-1) + dp1[i-1][j]
dp1[i][j] = dp1[i-1][j-1]
print(dp0[digit][k] + dp1[digit][k]) | 0 | null | 37,797,142,762,260 | 10 | 224 |
while 1:
(a,b,c) = map(int,raw_input().split())
if a == -1 and b == -1 and c == -1:
break
if a == -1 or b == -1:
print 'F'
elif a+b >= 80:
print 'A'
elif a+b >= 65:
print 'B'
elif a+b >= 50:
print 'C'
elif a+b >= 30:
if c >= 50:
print 'C'
else:
print 'D'
else:
print 'F' | from sys import stdin
for line in stdin:
mid, final, make = map(int, line.split())
if mid == -1 and final == -1 and make == -1:
break
elif mid == -1 or final == -1:
print('F')
elif mid + final >= 80:
print('A')
elif mid + final >= 65:
print('B')
elif mid + final >= 50:
print('C')
elif mid + final >= 30:
if make >= 50:
print('C')
else:
print('D')
else:
print('F')
| 1 | 1,227,612,106,112 | null | 57 | 57 |
import itertools
n = int(input())
a = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
able = [0] * (max(n * max(a) + 1, 2001))
for item in itertools.product([0, 1], repeat=n):
total = sum([i * j for i, j in zip(a, item)])
able[total] = 1
for m in M:
print('yes' if able[m] else 'no')
| from collections import Counter
n = int(input())
A = list(map(int, input().split()))
X = Counter([i - a for i, a in enumerate(A)])
ans = 0
for i, a in enumerate(A):
X[i - a] -= 1
ans += X[i + a]
print(ans)
| 0 | null | 13,099,655,726,458 | 25 | 157 |
import numpy
n=int(input())
l=list(map(int, input().split()))
res=0
mod=10**9+7
l.append(0)
l.reverse()
cum=numpy.cumsum(l)%mod
for i in range(n):
res+=((l[n-i]%mod)*cum[n-i-1])%mod
print(res%mod) | import math
n = []
score = []
scores = []
while True:
input_n = int(input())
if input_n == 0:
break
n.append(input_n)
input_score = [int(i) for i in input().split()]
score.append(input_score)
def total(scorelist):
total = 0
for i in range(len(scorelist)):
total = total + scorelist[i]
return total
def ave(total,n):
return float(total / n)
def variance(scorelist,ave,n):
total = 0
for i in range(len(scorelist)):
total = total + math.pow(scorelist[i]-ave,2)
return total / n
for i in range(len(n)):
total_score = total(score[i])
average = ave(total_score,n[i])
var = variance(score[i],average,n[i])
print(math.sqrt(var)) | 0 | null | 2,022,387,320,618 | 83 | 31 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.