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
|
---|---|---|---|---|---|---|
a,b,c=map(int,input().split())
if a+b+c>21:print('bust')
else:print('win') | n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
a[i], b[i] = [int(j) for j in input().split()]
a.sort()
b.sort()
if n % 2 == 1:
print(b[n//2] - a[n//2] + 1)
else:
print(b[n//2] + b[n//2-1] - a[n//2] - a[n//2-1] + 1) | 0 | null | 68,261,086,387,560 | 260 | 137 |
x = input().split()
x_int = [int(i) for i in x]
d = x_int[0]//x_int[1]
r = x_int[0] % x_int[1]
f = (x_int[0]) / (x_int[1])
print('{0} {1} {2:f}'.format(d,r,f)) | a= int(input())
b= int(input())
lista=[1, 2, 3]
for x in range(3):
if lista[x] != a and lista[x] != b:
print(lista[x]) | 0 | null | 55,725,417,266,792 | 45 | 254 |
import collections
import sys
S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()
for i, j in enumerate(sys.stdin.readline()):
if j == '\\':
S1.append(i)
elif j == '/':
if S1:
left_edge = S1.pop()
new_puddle = i - left_edge
while S2 and (S2[-1] > left_edge):
if S2[-1] > left_edge:
S2.pop()
new_puddle += S3.pop()
S2.append(left_edge)
S3.append(new_puddle)
else:
pass
print(sum(S3))
print(len(S3), *S3) | from collections import *
N = int(input())
A = list(map(int, input().split()))
ans = 0
c = Counter()
for i in range(1, N+1):
ans += c[i-A[i-1]]
c[i+A[i-1]] += 1
print(ans) | 0 | null | 12,967,570,136,790 | 21 | 157 |
N, M = map(int, input().split())
if N == 1:
min_range = 0
max_range = 10
else:
min_range = 10 ** (N-1)
max_range = 10 ** N
digits_lis = ['not defined' for _ in range(N+1)]
for _ in range(M):
s, c = map(int, input().split())
if digits_lis[s] == 'not defined':
digits_lis[s] = c
else:
if digits_lis[s] != c:
print('-1')
break
if digits_lis[1] == 0 and N != 1:
print('-1')
break
else:
for i in range(min_range, max_range):
for idx, check in enumerate(digits_lis):
if check == 'not defined':
continue
if (i // 10 ** (N - idx)) % 10 != check:
break
else:
print(i)
break
| cnt = int(input())
taro = 0
hanako = 0
for i in range(cnt):
li = list(input().split())
if li[0]>li[1]:
taro +=3
elif li[0]==li[1]:
taro +=1
hanako +=1
else:
hanako +=3
print(taro,hanako)
| 0 | null | 31,307,437,077,058 | 208 | 67 |
N = int(input())
d = list(map(int, input().split()))
import itertools
ans = 0
pairs = list(itertools.combinations(d, 2))
for pair in pairs:
ans += pair[0] * pair[1]
print(ans) | import math
import itertools
n = int(input())
d =list(map(int,input().split()))
p = list(itertools.combinations(d, 2))
ans = 0
for i in range(len(p)):
d = p[i][0] * p[i][1]
ans = ans + d
print(ans) | 1 | 168,977,916,144,080 | null | 292 | 292 |
n=int(input())
dict={}
res=[]
for i in range(n):
ss=input().split()
if ss[0]=='insert':
dict[ss[1]]=i
elif ss[0]=='find':
if dict.__contains__(ss[1]):
res.append('yes')
else:
res.append('no')
for i in res:
print(i)
| n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
s = input()
if s == 'AC':
ac += 1
elif s == 'WA':
wa += 1
elif s == 'TLE':
tle += 1
else:
re += 1
print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re)) | 0 | null | 4,438,512,221,832 | 23 | 109 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c0 = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
x -= 1
y -= 1
cnext = a[x] + b[y] - c
c0 = min(c0, cnext)
print(c0) | A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(M)]
buy = [min(a)+min(b)]
for i in range(M):
C = a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
buy.append(C)
print(min(buy))
| 1 | 54,051,344,440,640 | null | 200 | 200 |
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
@njit((i8,i8,i8[:],i8[:]), cache=True)
def main(H,N,A,B):
INF = 1<<30
dp = np.full(H+1,INF,np.int64)
dp[0] = 0
for i in range(N):
for h in range(A[i],H):
dp[h] = min(dp[h],dp[h-A[i]]+B[i])
dp[H] = min(dp[H],min(dp[H-A[i]:H]+B[i]))
ans = dp[-1]
return ans
H, N = map(int, input().split())
A = np.zeros(N,np.int64)
B = np.zeros(N,np.int64)
for i in range(N):
A[i],B[i] = map(int, input().split())
print(main(H,N,A,B)) | H,N = map(int,input().split());INF = float("inf")
A=[];B=[]
for i in range(N):
a,b = map(int,input().split())
A.append(a);B.append(b)
#print(A,B)
dp = [INF for _ in range(H+1)] #dp[i] HPがi残っているときの、魔力の消費最小
dp[H] = 0
for i in reversed(range(H+1)):
#print(i)
#print(dp)
for j in range(N):
if i - A[j] >= 0:
dp[i-A[j]] = min(dp[i-A[j]], dp[i] + B[j])
else:
dp[0] = min(dp[0], dp[i] + B[j])
ans = dp[0]
print(ans) | 1 | 80,869,840,036,572 | null | 229 | 229 |
import sys
def main():
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
c = [0] + list(map(int, input().split()))
dp = [list(range(n + 1)) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(n + 1):
if j - c[i] >= 0:
dp[i][j] = min(dp[i - 1][j], dp[i][j - c[i]] + 1)
else:
dp[i][j] = dp[i - 1][j]
print(dp[m][n])
if __name__ == "__main__":
main()
| a,b=(int(x) for x in input().split())
print(a//b,a%b,"{0:.5f}".format(a/b))
| 0 | null | 367,107,869,970 | 28 | 45 |
def readinput():
n=input()
return n
def main(n):
if n[0]=='7' or n[1]=='7' or n[2]=='7':
return 'Yes'
else:
return 'No'
if __name__=='__main__':
n=readinput()
ans=main(n)
print(ans)
| import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
d = list(map(int, input().split()))
ans = (sum(d)**2 - sum(item**2 for item in d))//2
print(ans) | 0 | null | 101,302,813,084,800 | 172 | 292 |
n,x,m=map(int,input().split())
def f(ai,m):
return (ai*ai)%m
if x==0:
print(0)
elif x==1:
print(n)
elif m==1:
print(0)
elif n<=m*2:
asum=x
ai=x
for i in range(1,n):
ai=f(ai,m)
asum+=ai
print(asum)
else:
chk=[-1]*m
asum00=[0]*m
ai,asum=x,0
for i in range(m):
if chk[ai]!=-1:
icnt0=chk[ai]
break
else:
chk[ai]=i
asum00[i]=asum
asum+=ai
ai=f(ai,m)
icnt=i
asum0=asum00[icnt0]
icntk=icnt-icnt0
n0=n-1-icnt0
nk=n0//icntk
nr=n0%icntk
asumk=asum-asum0
air,asumr=ai,0
for i in range(nr):
asumr+=air
air=f(air,m)
asumr+=air
ans=asum0+asumk*nk+asumr
print(ans)
| #!/usr/local/bin/python3
N, X, M = map(int, input().split())
def f(x, m):
return x**2 % m
check = [False for _ in range(M)]
d = [X]
max_x = 0
for _ in range(1, N+1):
X = f(X, M)
if check[X]:
break
else:
check[X] = True
d.append(X)
idx = d.index(X)
ans = sum(d[:idx])
N -= idx
d = d[idx:]
sumd = sum(d)
ans += N//len(d) * sumd
ans += sum(d[:N%len(d)])
print(ans)
| 1 | 2,810,686,419,740 | null | 75 | 75 |
n = int(input())
word = input()
count = word.count("ABC")
print(count) | import sys
N = int(input())
S = list(input())
if len(S)%2 != 0:
print("No")
sys.exit(0)
else:
i = int(len(S)/2)
T = S[0:i]
if T*2 == S:
print("Yes")
else:
print("No") | 0 | null | 122,736,792,763,288 | 245 | 279 |
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
ave_a = t1 * a1 + t2 * a2
ave_b = t1 * b1 + t2 * b2
if ave_a == ave_b:
print('infinity')
exit()
half, all = t1 * (b1 - a1), ave_a - ave_b
ans = half // all * 2 + (half % all != 0)
print(max(0, ans))
| numbers = []
n = raw_input()
numbers = n.split(" ")
for i in range(2):
numbers[i] = int(numbers[i])
if numbers[0] > numbers[1]:
print "a > b"
elif numbers[0] < numbers[1]:
print "a < b"
elif numbers[0] == numbers[1]:
print "a == b" | 0 | null | 65,663,647,481,942 | 269 | 38 |
n = int(input())
ans = 0
for a in range (1,n):
for b in range(a, n, a):
ans += 1
print(ans) | import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for i in range(1, n):
ans += (n-1) // i
print(ans) | 1 | 2,588,860,179,008 | null | 73 | 73 |
s = input()
num = int(s)
print(str(num**3))
| import sys
data=int(input())
print(data*data*data)
| 1 | 281,056,920,996 | null | 35 | 35 |
N,K=list(map(int, input().split()))
A=[0]*(N+1)
for _ in range(K):
k=int(input())
a=list(map(int, input().split()))
for i in a:
A[i]+=1
c=0
for i in range(1,N+1):
c+=not A[i]
print(c) | s=input()
t=input()
ans=10**8
n=len(s)
m=len(t)
for i in range(n-m+1):
cnt=0
for j in range(m):
if s[i+j]!=t[j]:
cnt+=1
ans=min(ans,cnt)
print(ans) | 0 | null | 14,157,846,340,260 | 154 | 82 |
search = raw_input().upper()
sentence = []
while 1:
input_data = raw_input()
if input_data == 'END_OF_TEXT':
break
sentence += [s.upper() for s in input_data.split()]
ret = 0
for word in sentence:
ret += 1 if word == search else 0
print ret | w=input()
c=0
while True:
t=input()
if t=='END_OF_TEXT':
print(c)
break
c+=t.lower().split().count(w)
| 1 | 1,802,857,932,960 | null | 65 | 65 |
import sys
from itertools import combinations_with_replacement, product
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def main():
n, m, x = map(int, input().split())
data = np.zeros((n,m),int)
clist = np.zeros(n, int)
ans=10**10
for i in range(n):
ca = list(map(int, input().split()))
clist[i]=ca[0]
data[i]=np.array(ca[1:])
for bit in list(product([0,1],repeat=n)):
if all(np.dot(np.array(bit), data)>=x):
ans=min(ans,np.dot(np.array(bit),clist.T))
if ans==10**10:
print(-1)
else:
print(ans)
if __name__ == '__main__':
main() | n, m, x = map(int, input().split())
A = [list(map(int, input().split())) for j in range(n)]
ans = 10 ** 7
for i in range(1 << n):
s = [0] * (m + 1)
for j in range(n):
if i >> j & 1:
for k in range(m+1):
s[k] += A[j][k]
if min(s[1:]) >= x:
ans = min(ans, s[0])
print(-1) if ans == 10 ** 7 else print(ans) | 1 | 22,201,519,922,860 | null | 149 | 149 |
H,W=list(map(int,input().split()))
l=[list(input()) for i in range(H)]
inf=10**9
DP=[[inf]*W for i in range(H)]
DP[0][0]=0 if l[0][0]=="." else 1
for i in range(H):
for j in range(W):
if i>0:
DP[i][j]=min(DP[i][j],DP[i-1][j]+1) if l[i-1][j] == "." and l[i][j]=="#" else min(DP[i][j],DP[i-1][j])
if j>0:
DP[i][j]=min(DP[i][j],DP[i][j-1]+1) if l[i][j-1] == "." and l[i][j]=="#" else min(DP[i][j],DP[i][j-1])
print(DP[H-1][W-1]) | def agc043_a():
''' 解説放送見てやってみた '''
H, W = map(int, input().split())
grid = []
grid.append(['#'] * (W+2)) # 周辺埋め
for _ in range(H):
grid.append(['#'] + [c for c in str(input())] + ['#'])
grid.append(['#'] * (W+2))
grid[1][0] = grid[H][W+1] = '.' # グリッド外側に白を置く, (1,1)(H,W)が黒の場合に反転カウントするため
# 白黒が反転する回数を数える
cost = [[10**6] * (W+2) for _ in range(H+2)]
cost[1][0] = 0
for i in range(1, H+1):
for j in range(1, W+2):
if i != H and j == W+1: continue # ゴールの外側のときだけ通過
rt = cost[i][j-1]
if grid[i][j-1] != grid[i][j]: rt += 1
dw = cost[i-1][j]
if grid[i-1][j] != grid[i][j]: dw += 1
cost[i][j] = min(rt, dw)
ans = cost[H][W+1] // 2 # 区間の始まりと終わりを両方カウントしているので半分にする
print(ans)
agc043_a() | 1 | 49,518,432,840,448 | null | 194 | 194 |
K = int(input())
[A, B] = [int(i) for i in input().split()]
for num in range(A, B+1):
if num % K == 0:
print("OK")
exit()
print("NG") | import sys
k = int(input())
a,b = list(map(int,input().split()))
for i in range(a,b+1):
if i % k == 0:
print("OK")
sys.exit()
print("NG") | 1 | 26,646,028,242,680 | null | 158 | 158 |
A=[0 for i in range(45)]
A[0]=1
A[1]=1
for i in range(2,45):
A[i]=A[i-1]+A[i-2]
B=int(input())
print(A[B])
| import sys
from collections import defaultdict
import bisect
import itertools
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():
N, M = geta(int)
A = list(geta(int))
A.sort()
def c(x):
"""
@return # of handshake where hapiness >= x
"""
ret = 0
for a in A:
ret += bisect.bisect_left(A, x - a)
return N * N - ret
left, right = 0, 2 * A[-1] + 1
while left + 1 < right:
middle = (left + right) // 2
if c(middle) >= M:
left = middle
else:
right = middle
ans = 0
Acum = list(itertools.accumulate(A[::-1]))[::-1]
for a in A:
idx = bisect.bisect_left(A, right - a)
if idx < N:
ans += Acum[idx] + a * (N - idx)
ans += left * (M - c(right))
print(ans)
if __name__ == "__main__":
main() | 0 | null | 54,139,904,703,680 | 7 | 252 |
n = int(input())
s,t = input().split()
ans = ''
for i in range(n):
ans += s[i]
ans += t[i]
print(ans) | import math
n = int(input())
K = int(input())
def calk1(n):
if n == 0: return 0
m = int(math.log10(n))
num = m * 9
num += n//(10**m)
return num
def calk2(n):
m = int(math.log10(n))
num = m * (m - 1) // 2 * 9**2
num += (n//(10**m)-1) * m * 9
num += calk1(n - (n//(10**m)*10**m))
return num
def calk3(n):
m = int(math.log10(n))
num = m * (m - 1) * (m - 2) // 6 * 9**3
num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
num += calk2(n - (n//(10**m)*10**m))
return num
if n < 10 ** (K - 1): print(0)
else:
if K == 1: print(calk1(n))
elif K == 2: print(calk2(n))
else: print(calk3(n))
| 0 | null | 94,156,058,095,008 | 255 | 224 |
import copy
n = int(input())
a = list(map(int, input().split()))
k = 1 + n%2
INF = 10**18
dp = [[-INF]*4 for i in range(n+5)]
dp[0][0] = 0
for i in range(n):
for j in range(k+1):
dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j])
now = copy.deepcopy(dp[i][j])
if (i+j) % 2 == 0:
now += a[i]
dp[i+1][j] = max(dp[i+1][j], now)
print(dp[n][k])
| from collections import defaultdict
n = int(input())
m = n//2
INF = 10**18
dp = [defaultdict(lambda: -INF)for _ in range(n+2)]
for i, a in enumerate(map(int, input().split()), 2):
for j in range(max(1, i//2-1), -(-i//2)+1):
if j-1 == 0:
dp[i-2][j-1] = 0
dp[i][j] = max(dp[i-1][j], dp[i-2][j-1]+a)
print(dp[n+1][m])
| 1 | 37,688,914,319,134 | null | 177 | 177 |
# -*- coding: utf-8 -*-
mat1 = {}
mat2 = {}
n, m, l = map(int, raw_input().split())
for i in range(1, n+1):
list = map(int, raw_input().split())
for j in range(1, m+1):
mat1[(i, j)] = list[j-1]
for j in range(1, m+1):
list = map(int, raw_input().split())
for k in range(1, l+1):
mat2[(j, k)] = list[k-1]
for i in range(1, n+1):
buf = ""
for k in range(1, l+1):
res = 0
for j in range(1, m+1):
res += mat1[(i, j)]*mat2[(j, k)]
buf += str(res) +" "
buf = buf.rstrip()
print buf | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
n = int(input())
ans = float("inf")
for i in range(1, n+1):
if n%i==0:
ans = min(ans, i+n//i)
if i*i>n:
break
print(ans-2) | 0 | null | 81,473,891,030,266 | 60 | 288 |
def main():
s = list(input())
k = int(input())
lst = []
cnt = 1
flg = 0
ans = 0
prev = s[0]
for i in range(1, len(s)):
if prev == s[i]:
cnt += 1
else:
lst.append(cnt)
cnt = 1
prev = s[i]
flg = 1
lst.append(cnt)
if len(lst) == 1:
ans = len(s) * k // 2
else:
ans += sum(map(lambda x: x // 2, lst[1:len(lst)-1])) * k
# for l in lst[1: len(lst) - 1]:
# ans += l // 2 * k
if s[-1] == s[0]:
ans += (lst[0] + lst[-1]) // 2 * (k - 1)
ans += lst[0] // 2 + lst[-1] // 2
else:
ans += (lst[0] // 2 + lst[-1] // 2) * k
print(ans)
if __name__ == "__main__":
main()
| # https://atcoder.jp/contests/agc039/tasks/agc039_a
s = list(input())
k = int(input())
i = 0
a = 0
while i < len(s):
if i == len(s) - 1:
break
if s[i] == s[i+1]:
a += 1
i += 2
else:
i += 1
else:
print(a * k)
exit()
i = -1
b = 0
while i < len(s):
if i == len(s) - 1:
print(a + b * (k - 1))
exit()
if s[i] == s[i + 1]:
b += 1
i += 2
else:
i += 1
else:
print(a * ((k + 1) // 2) + b * ((k - 1) // 2))
exit() | 1 | 175,240,485,772,172 | null | 296 | 296 |
s=list(input())
l=[0]*2019
t=0
ans=0
for i in range(len(s)):
t=(t+pow(10,i,2019)*int(s[-1-i]))%2019
l[t]+=1
for i in l:
ans+=(i*(i-1))//2
print(ans+l[0]) | import sys
import bisect
from functools import lru_cache
from collections import defaultdict
from collections import deque
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
return int(readline())
def reads():
return map(int, readline().split())
s=input()
n=len(s)
ten=[1]
mod=2019
for i in range(n-1):
ten.append((ten[i]*10)%mod)
modls=[0]*n
modls[n-1]=int(s[n-1])
dic=defaultdict(int)
dic[modls[n-1]]+=1
dic[0]=1
for i in range(n-2,-1,-1):
modls[i]=int(s[i])*ten[n-1-i]+modls[i+1]
modls[i]%=mod
dic[modls[i]]+=1
ans=0
#print(dic)
for num in dic.values():
ans+=num*(num-1)//2
#ans+=dic[0]
print(ans) | 1 | 31,018,083,504,992 | null | 166 | 166 |
n = int(input())
for i in range(1,n+1):
x = i
if x % 3 == 0:
print(' {}'.format(i), end='')
else:
while x:
if x % 10 == 3:
print(' {}'.format(i), end='')
break
else:
x //= 10
print('') | h,n = map(int,input().split())
A= list(map(int,input().split()))
for i in range(n):
h-= A[i]
if h>0:
print("No")
else:
print("Yes") | 0 | null | 39,580,296,722,680 | 52 | 226 |
K = int(input())
A, B = map(int, input().split())
a, mod_a = divmod(A, K)
b, mod_b = divmod(B, K)
if mod_a == 0 or mod_b == 0:
print('OK')
exit()
if a == b:
print('NG')
else:
print('OK')
| # D - Friend Suggestions
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def root(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.root(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.parents[self.root(x)]
N,M,K = map(int,input().split())
friend = UnionFind(N+1)
block = [1]*(N+1)
for _ in range(M):
x,y = map(int,input().split())
block[x] += 1
block[y] += 1
friend.union(x,y)
for _ in range(K):
x,y = map(int,input().split())
if friend.same(x,y):
block[x] += 1
block[y] += 1
ans = [friend.size(i)-block[i] for i in range(1,N+1)]
print(*ans) | 0 | null | 43,972,550,076,434 | 158 | 209 |
m1, d1 = [int(i) for i in input().split()]
m2, d2 = [int(i) for i in input().split()]
if m1 == m2:
print(0)
else:
print(1) | x,n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(102)]
for j in p:
l.remove(j)
m = []
for k in l:
m.append(abs(k-x))
print(l[m.index(min(m))]) | 0 | null | 68,936,929,582,680 | 264 | 128 |
# 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)
| 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)
| 0 | null | 62,190,262,810,496 | 204 | 215 |
def solve():
S, W = map(int, input().split())
if S <= W:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
solve()
| a,b = map(int,input().split())
print('safe') if a>b else print('unsafe') | 1 | 29,223,793,602,080 | null | 163 | 163 |
import numpy as np
mod = 998244353
n, s = map(int, input().split())
dp = np.zeros((n+1, s+1), dtype=int)
dp[0, 0] = 1
for i, a in enumerate(map(int, input().split())):
dp[i+1] = dp[i] * 2 % mod
dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod
print(dp[-1, -1]) | K = int(input())
a = 7
flag = True
for i in range(K):
if a % K == 0:
print(i+1)
flag = False
break
a = (a * 10 + 7) % K
if flag:
print(-1)
| 0 | null | 11,906,803,834,562 | 138 | 97 |
n,q = map(int,input().split())
queue = []
for i in range(n):
p,t = map(str,(input().split()))
t = int(t)
queue.append([p,t])
total_time = 0
while len(queue) > 0:
x = queue.pop(0)
if x[1] > q :
total_time += q
x[1] -= q
queue.append(x)
else:
total_time += x[1]
print(x[0],total_time) | #ALDS_3_B 16D8103010K Ko Okasaki
from collections import deque
n,q=map(int,input().split())
que=deque()
for i in range(n):
name,time=input().split()
time=int(time)
que.append([name,time])
t=0
while len(que)>0:
que_t=que.popleft()
if que_t[1]>q:
que_t[1]-=q
t+=q
que.append(que_t)
else:
t+=que_t[1]
print(que_t[0],t)
| 1 | 43,477,133,580 | null | 19 | 19 |
for _ in[0]*int(input()):a,b,c=sorted(map(int,input().split()));print(['NO','YES'][a*a+b*b==c*c]) | a = {}
for s in ["S", "H", "C", "D"]:
a.update({f'{s} {i}': 0 for i in range(1, 14)})
n = int(input())
for _ in range(n):
s = input()
del a[s]
a = list(a)
for i in range(len(a)):
print(a[i])
| 0 | null | 533,741,731,252 | 4 | 54 |
n = input()
s = []
h = []
c = []
d = []
for i in range(n):
spare = raw_input().split()
if spare[0]=='S':
s.append(int(spare[1]))
elif spare[0]=='H':
h.append(int(spare[1]))
elif spare[0]=='C':
c.append(int(spare[1]))
else :
d.append(int(spare[1]))
for j in range(1,14):
judge = True
for k in range(len(s)):
if j==s[k] :
judge = False
break
if judge :
print 'S %d' %j
for j in range(1,14):
judge = True
for k in range(len(h)):
if j==h[k] :
judge = False
break
if judge :
print 'H %d' %j
for j in range(1,14):
judge = True
for k in range(len(c)):
if j==c[k] :
judge = False
break
if judge :
print 'C %d' %j
for j in range(1,14):
judge = True
for k in range(len(d)):
if j==d[k] :
judge = False
break
if judge :
print 'D %d' %j | n=input()
S=['S 1','S 2','S 3','S 4','S 5','S 6','S 7','S 8','S 9','S 10','S 11','S 12','S 13']
H=['H 1','H 2','H 3','H 4','H 5','H 6','H 7','H 8','H 9','H 10','H 11','H 12','H 13']
C=['C 1','C 2','C 3','C 4','C 5','C 6','C 7','C 8','C 9','C 10','C 11','C 12','C 13']
D=['D 1','D 2','D 3','D 4','D 5','D 6','D 7','D 8','D 9','D 10','D 11','D 12','D 13']
cards=[S,H,C,D]
for i in range(n):
exist=raw_input()
if 'S' in exist:
cards[0].remove(exist)
if 'H' in exist:
cards[1].remove(exist)
if 'C' in exist:
cards[2].remove(exist)
if 'D' in exist:
cards[3].remove(exist)
for j in range(4):
for i in cards[j]:
print i | 1 | 1,023,816,775,452 | null | 54 | 54 |
n = int(input())
a = []
xy = []
for i in range(n):
temp_a = int(input())
s = [list(map(int, input().split())) for _ in range(temp_a)]
a.append(temp_a)
xy.append(s)
ans = 0
for bit in range(1<<n):
h = [0]*n
flag = True
sum = 0
for i in range(n):
if (bit>>i) & 1:
h[i] = 1
sum += 1
for i in range(n):
if (bit>>i) & 1:
for j in range(a[i]):
if xy[i][j][1] != h[xy[i][j][0]-1]:
flag =False
if flag:
ans = max((ans, sum))
print(ans)
| N = int(input())
x, y = map(int, input().split())
d = [x - y, x - y, x + y, x + y]
for i in range(1,N):
x, y = map(int, input().split())
d[0] = max(d[0], x-y)
d[1] = min(d[1], x-y)
d[2] = max(d[2], x+y)
d[3] = min(d[3], x+y)
print(max(d[0]-d[1], d[2]-d[3])) | 0 | null | 62,204,166,061,532 | 262 | 80 |
n=int(input())
l=list(map(int,input().split()))
a=[]
for i in range(n):
a.append(0)
for i in range(n-1):
a[l[i]-1]+=1
for i in range(n):
print(a[i]) | n = int(input())
a = list(map(int, input().split()))
number_buka = [0]*n
for i in a:
number_buka[i-1] += 1
for j in number_buka:
print(j) | 1 | 32,556,390,365,590 | null | 169 | 169 |
#!/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')
#solve
def solve():
n, k = LI()
a = LI_()
ab = a[::1]
a[0] = a[0] % k
for i in range(n - 1):
a[i + 1] = (a[i] + a[i + 1]) % k
ans = 0
q = deque([0])
d = defaultdict(int)
d[0] += 1
for x, i in enumerate(a):
q.append(i)
if len(q) == k+1:
x = q.popleft()
d[x] -= 1
ans += d[i]
d[i] += 1
print(ans)
return
#main
if __name__ == '__main__':
solve() | n = int(input())
word = 'ACL'
print(word * n) | 0 | null | 69,907,379,043,140 | 273 | 69 |
K = int(input())
acl = 'ACL'
op = ''
for k in range(K):
op += acl
print(op) | 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 | 2,641,855,827,432 | 69 | 78 |
S = input()
n = len(S)
c = 0
for i in range(n // 2):
if S[i] != S[n - i - 1]:
c += 1
print(c) | s = input()
if len(s) == 1:
print(0)
exit()
ans = 0
for i in range(len(s)//2):
if s[i] != s[(-1)*(i+1)]:
ans += 1
else:
pass
print(ans)
| 1 | 120,574,181,820,100 | null | 261 | 261 |
import bisect
n, k = map(int, input().split())
h = sorted(list(map(int, input().split())))
print(n - bisect.bisect_left(h, k)) | a = int(input())
b_list = list(map(int, input().split()))
count = 0
mini=a
for i in range(len(b_list)):
if b_list[i] <= mini:
count += 1
mini = b_list[i]
print(count) | 0 | null | 132,614,313,348,792 | 298 | 233 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
var = int(raw_input())
sum = var*var*var
print sum | # coding=utf-8
def fib(number):
if number == 0 or number == 1:
return 1
memo1 = 1
memo2 = 1
for i in range(number-1):
memo1, memo2 = memo1+memo2, memo1
return memo1
if __name__ == '__main__':
N = int(input())
print(fib(N))
| 0 | null | 136,447,851,710 | 35 | 7 |
L=[]
R=[]
N,K,C=map(int,input().split())
S=list(input())
s=S[::-1]
i=0
while len(L)<K:
if S[i]=='o':
L.append(i+1)
if i+C<N:
for j in range(1,C+1):
S[i+j]='x'
i+=1
k=0
while len(R)<K:
if s[k]=='o':
R.append(N-k)
if k+C<N:
for l in range(1,C+1):
s[k+l]='x'
k+=1
R=R[::-1]
ans=[]
for i in range(K):
if L[i]==R[i]:
ans.append(L[i])
print(*ans) | input()
a = set(input().split())
input()
b = set(input().split())
print(len(a & b))
| 0 | null | 20,500,629,904,272 | 182 | 22 |
import sys
N,K = map(int,input().split())
H = sorted(list(map(int,input().split())),reverse = True)
for i in range(N):
if not H[i] >= K:
print(i)
sys.exit()
print(N) | W,H,x,y,r = map(int ,raw_input().split())
#print ' '.join(map(str,[W,H,x,y,r]))
if x < W and 0 < x and 0<y and y < H and r <= x and r <= (H - x) :
print "Yes"
else:
print "No" | 0 | null | 89,400,621,001,702 | 298 | 41 |
X,Y = map(int,input().split())
M = max(X,Y)
m = min(X,Y)
mod = 10 ** 9 + 7
con = (X + Y) // 3
dif = M - m
n = (con - dif) // 2
if (X + Y) % 3 != 0 or n < 0:
print(0)
else:
def comb(n, r):
n += 1
over = 1
under = 1
for i in range(1,r + 1):
over = over * (n - i) % mod
under = under * i % mod
#powでunder ** (mod - 2) % modを実現、逆元を求めている
return over * pow(under,mod - 2,mod) % mod
ans = comb(con,n)
print(ans) | #! python3
# dice_i.py
class dice():
def __init__(self, arr):
self.top = arr[0]
self.south = arr[1]
self.east = arr[2]
self.west = arr[3]
self.north = arr[4]
self.bottom = arr[5]
def rotate(self, ope):
if ope == 'S':
self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
elif ope == 'N':
self.top, self.south, self.bottom, self.north = self.south, self.bottom, self.north, self.top
elif ope == 'E':
self.top, self.west, self.bottom, self.east = self.west, self.bottom, self.east, self.top
elif ope == 'W':
self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
elif ope == 'R': # clockwise
self.south, self.east, self.north, self.west = self.east, self.north, self.west, self.south
elif ope == 'L': # reversed clockwise
self.south, self.east, self.north, self.west = self.west, self.north, self.east, self.south
dc = dice([int(x) for x in input().split(' ')])
q = int(input())
top_souths = [[int(x) for x in input().split(' ')] for i in range(q)]
for top, south in top_souths:
if dc.top != top:
opes = ['S', 'E', 'S', 'E', 'S']
for op in opes:
dc.rotate(op)
if dc.top == top: break
for i in range(4):
if dc.south == south:
break
dc.rotate('R')
print(dc.east)
| 0 | null | 75,088,344,219,360 | 281 | 34 |
N,M=map(int,input().split())
a=N//2
b=a+1
print(a,b)
if M==1:
exit(0)
c=1
d=N-1
print(c,d)
for i in range(M-2):
if i%2==0:
a,b=a-1,b+1
print(a,b)
else:
c,d=c+1,d-1
print(c,d)
| n, m = map(int, input().split())
x, y = (m+1) // 2, m // 2
for i in range(x):
print(1+i, 2*x-i)
for i in range(y):
print(2*x+1+i, 2*x+1+2*y-i) | 1 | 28,751,260,710,990 | null | 162 | 162 |
n=int(input())
s=input()
judge=''
for i in range(n):
if s[i]==judge:
n-=1
judge=s[i]
print(n) | n = int(input())
s = input()
count = 1
i = 0
while i < n-1:
if s[i] == s[i+1]:
i += 1
else:
count += 1
i += 1
print(count) | 1 | 170,263,617,097,958 | null | 293 | 293 |
k = int(input())
s = input()
if k >= len(s):
print(s)
else:
print(f"{s[:k]}...") | K = int(input())
S = str(input())
SK = S[0: (K)]
if len(S) <= K:
print(S)
else:
print(SK + '...') | 1 | 19,734,283,717,248 | null | 143 | 143 |
a, b, c, d = map(int,input().split())
while True:
c = c - b
a = a - d
if c <= 0:
print('Yes')
break
elif a <= 0:
print('No')
break
else:
pass | INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
import itertools, math
def distance(x1,y1,x2,y2):
return(((x2-x1)**2+(y2-y1)**2)**0.5)
def do():
xs=[]
ys=[]
per=[]
n=INT()
ans=0
for i in range(n):
x,y=INTM()
xs.append(x)
ys.append(y)
per.append(i)
for i in itertools.permutations(per, n):
for k in range(n-1):
ans+=distance(xs[i[k]],ys[i[k]],xs[i[k+1]],ys[i[k+1]])
#print(ans)
print(ans/math.factorial(n))
if __name__=='__main__':
do() | 0 | null | 89,332,436,348,100 | 164 | 280 |
n = int( input() )
s = str( input() )
s = s + "x"
ABC_count = 0
for i in range( n + 1 - 3 ):
if s[i:i+3] == "ABC":
ABC_count += 1
print( ABC_count ) | N=int(input())
S=input()
ans=0
for i in range(N-2):
if S[i]=='A':
i+=1
if S[i]=='B':
i+=1
if S[i]=='C':
ans+=1
print(ans) | 1 | 99,420,573,099,130 | null | 245 | 245 |
N = [0] + list(map(int, list(input())))
L = len(N)
ans = 0
for i in range(L-1, -1, -1):
if N[i] == 10:
if i == 0:
ans += 1
else:
N[i-1] += 1
N[i] = 0
if N[i] < 5:
ans += N[i]
elif N[i] > 5:
ans += 10 - N[i]
N[i-1] += 1
else:
if i == 0:
ans += N[i]
else:
if N[i-1] >= 5:
N[i-1] += 1
ans += 5
else:
ans += N[i]
print(ans)
| N=input()
L=[int(N[i]) for i in range(len(N))]
P=0
OT=0
for i in range(len(L)-1):
if 0 <= L[i] <= 3:
P += L[i] + OT
OT = 0
elif L[i] == 4:
if OT == 1 and L[i+1]>=5:
P += 5
else:
P += OT+L[i]
OT = 0
elif L[i] == 5:
if OT == 1:
P += 4
else:
if L[i+1] >= 5:
P += 1 + 4
OT = 1
else:
P += 5
else:
if OT == 1:
P += 9-L[i]
OT = 1
else:
P += 10 - L[i]
OT = 1
Pone = 0
if OT==0:
Pone = min(L[-1],11-L[-1])
elif OT==1 and L[-1]<=4:
Pone = 1+L[-1]
else:
Pone = 10-L[-1]
print(P+Pone) | 1 | 70,720,442,167,660 | null | 219 | 219 |
n = int(input())
s = input()
if len(s) <= n:
print(s)
else:
print(s[0:n],'...', sep='') | class UnionFindTree():
def __init__(self, N):
self.N = N
self.__parent_of = [None] * N
self.__rank_of = [0] * N
self.__size = [1] * N
def root(self, value):
if self.__parent_of[value] is None:
return value
else:
self.__parent_of[value] = self.root(self.__parent_of[value])
return self.__parent_of[value]
def unite(self, a, b):
r1 = self.root(a)
r2 = self.root(b)
if r1 != r2:
if self.__rank_of[r1] < self.__rank_of[r2]:
self.__parent_of[r1] = r2
self.__size[r2] += self.__size[r1]
else:
self.__parent_of[r2] = r1
self.__size[r1] += self.__size[r2]
if self.__rank_of[r1] == self.__rank_of[r2]:
self.__rank_of[r1] += 1
def is_same(self, a, b):
return self.root(a) == self.root(b)
def size(self, a):
return self.__size[self.root(a)]
def groups(self):
groups = {}
for k in range(self.N):
r = self.root(k)
if r not in groups:
groups[r] = []
groups[r].append(k)
return [groups[x] for x in groups]
def main():
N, M = map(int, input().split())
uft = UnionFindTree(N)
for _ in range(M):
A, B = map(int, input().split())
uft.unite(A-1, B-1)
ans = 0
for g in uft.groups():
ans = max(ans, len(g))
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 11,876,906,412,062 | 143 | 84 |
while True:
m,f,r = [int(x) for x in input().split()]
if (m,f,r)==(-1,-1,-1): break
s_mf = m + f
if m < 0 or f < 0: print('F')
elif s_mf < 30: print('F')
elif s_mf >= 80: print('A')
elif s_mf >= 65: print('B')
elif s_mf >= 50: print('C')
elif r >= 50: print('C')
else: print('D')
| from collections import deque
slope = input()
down_slope = deque()
total_slopes = deque()
for i in range(len(slope)):
if slope[i] == '\\':
down_slope.append(i)
elif slope[i] == '/':
area = 0
if len(down_slope) > 0:
while len(total_slopes) > 0 and total_slopes[-1][0] > down_slope[-1]:
area += total_slopes[-1][1]
total_slopes.pop()
area += i-down_slope[-1]
total_slopes.append([down_slope[-1],area])
down_slope.pop()
if len(total_slopes) > 0:
total_slopes = [i[1] for i in total_slopes]
print(sum(total_slopes))
print(len(total_slopes),end=' ')
print(' '.join(map(str,total_slopes)))
else:
print(0)
print(0)
| 0 | null | 647,740,721,768 | 57 | 21 |
k = int(input().split(' ')[1])
print(sum( sorted([int(n) for n in input().split(' ')])[0:k])) | import math
r = float(input())
a = math.pi * r**2
b = math.pi * r * 2
print(str(a) + " " + str(b)) | 0 | null | 6,184,353,268,800 | 120 | 46 |
def solve(N, A):
a = [(i, ai) for i, ai in enumerate(A)]
a.sort(key=lambda x: x[1], reverse=True)
# import numpy as np
# dp = np.zeros((N+1, N+1), np.int8)
dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i, ai in enumerate(a):
for l in range(i+1):
r = i - l
dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ai[1] * ((N-1-r) - ai[0]))
dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + ai[1] * (ai[0] - l))
print(max(dp[N]))
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split()))
solve(N, A)
| import collections
n, m = map(int, input().split())
par = list(range(2 * n))
# print(par)
# union find(parには0も入れているので、par[1]=1になる)
def find(x):
while par[x] != x:
tmp = par[x]
par[x] = par[par[x]]
x = par[x]
return x
def union(x, y):
x1 = find(x)
y1 = find(y)
if x1 != y1:
par[x1] = y1
# 各要素をunionする
for j in range(m):
a, b = map(int, input().split())
union(a - 1, b - 1)
s = [0 for i in range(n + 5)]
# 1~nの親を探してsに入れていき、一番多い親を答えにする
for k in range(n):
s[find(k)] += 1
print(max(s))
| 0 | null | 18,839,107,805,530 | 171 | 84 |
import math
def solve():
N = int(input())
if math.floor(math.ceil(N / 1.08) * 1.08) == N:
print(math.ceil(N / 1.08))
else:
print(':(')
if __name__ == "__main__":
solve() | N = int(input())
for i in range(1, N + 1):
if i + (i * 8) // 100 == N:
print(i)
break
else:
print(":(") | 1 | 125,961,751,542,146 | null | 265 | 265 |
num = int(input())
A = input().split(" ")
B = A.copy()
#bubble sort
for i in range(num):
for j in range(num-1,i,-1):
#英字ではなく、数字で比較する
m1 = int(A[j][1:])
m2 = int(A[j-1][1:])
if m1 < m2:
A[j],A[j-1] = A[j-1],A[j]
print(*A)
print("Stable")
#selection sort
for i in range(num):
minv = i
for j in range(i+1,num):
m1 = int(B[minv][1:])
m2 = int(B[j][1:])
if m1 > m2:
minv = j
B[i],B[minv] = B[minv],B[i]
print(*B)
if A == B:
print("Stable")
else:
print("Not stable")
| import copy
def BubbleSort(C, N):
for i in range(N):
for j in reversed(range(i+1, N)):
if C[j][1:2] < C[j-1][1:2]:
C[j], C[j-1] = C[j-1], C[j]
print(*C)
stableCheck(C, N)
def SelectionSort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j][1:2] < C[minj][1:2]:
minj = j
C[i], C[minj] = C[minj], C[i]
print(*C)
stableCheck(C, N)
def stableCheck(C, N):
global lst
flag = 1
for i in range(N):
for j in range(i+1, N):
if lst[i][1:2] == lst[j][1:2]:
fir = lst[i]
sec = lst[j]
for k in range(N):
if C[k] == fir:
recf = k
if C[k] == sec:
recs = k
if recf > recs:
print("Not stable")
flag = 0
break
if flag ==0:
break
if flag :
print("Stable")
N = int(input())
lst = list(map(str, input().split()))
lst1 = copy.deepcopy(lst)
lst2 = copy.deepcopy(lst)
BubbleSort(lst1, N)
SelectionSort(lst2, N)
| 1 | 25,413,140,428 | null | 16 | 16 |
# -*- coding: utf-8 -*-
from collections import deque
n = int(raw_input())
que = deque()
for i in range(n):
com = str(raw_input())
if com == "deleteFirst":
del que[0]
elif com == "deleteLast":
del que[-1]
else:
c, p = com.split()
if c == "insert":
que.appendleft(p)
else:
try: que.remove(p)
except: pass
print " ".join(map(str, que)) | from collections import deque
n = int(input())
dq = deque()
for _ in range(n):
query = input()
if query == "deleteFirst":
dq.popleft()
elif query == "deleteLast":
dq.pop()
else:
op, arg = query.split()
if op == "insert":
dq.appendleft(arg)
else:
tmp = deque()
while dq:
item = dq.popleft()
if item == arg:
break
else:
tmp.append(item)
while tmp:
dq.appendleft(tmp.pop())
print(*dq)
| 1 | 51,016,706,678 | null | 20 | 20 |
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
m = (l + r) // 2
res = 0
for x in a:
res += n - bisect_left(a, m - x)
if res >= k:
l = m
else:
r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
t = n - bisect_left(a, l - x)
ans += b[t] + x * t
cnt += t
print(ans - (cnt - k) * l)
| n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
import bisect
def func(x):
C = 0
for p in l:
q = x -p
j = bisect.bisect_left(l, q)
C += n-j
if C >= m:
return True
else:
return False
l_ = 0
r_ = 2*10**5 +1
while l_+1 < r_:
c_ = (l_+r_)//2
if func(c_):
l_ = c_
else:
r_ = c_
ans = 0
cnt = 0
lr = sorted(l, reverse=True)
from itertools import accumulate
cum = [0] + list(accumulate(lr))
for i in lr:
j = bisect.bisect_left(l, l_-i)
ans += i*(n-j) + cum[n-j]
cnt += n -j
ans -= (cnt-m)*l_
print(ans) | 1 | 108,196,282,936,102 | null | 252 | 252 |
A,B,C,D,E=map(int,input().split())
if A==0 :
print(1)
elif B==0:
print(2)
elif C==0:
print(3)
elif D==0:
print(4)
else :
print(5)
| X = list(map(int,input().split()))
num = 1
for i in X:
if i == 0:
print(num)
num += 1
| 1 | 13,440,942,592,060 | null | 126 | 126 |
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
s_l = []
for i in range(q):
s = list(map(int, input().split()))
s_l.append(s)
A = []
for v in combinations_with_replacement(range(1,m+1), n):
A.append(v)
ans = 0
for a in A:
cnt = 0
for i in range(q):
if a[s_l[i][1] - 1] - a[s_l[i][0] - 1] == s_l[i][2]:
cnt += s_l[i][3]
ans = max(ans, cnt)
print(ans) | X = input().split()
ans = X.index('0')
print(int(ans)+1) | 0 | null | 20,477,543,081,852 | 160 | 126 |
X=int(input())
flagp=False
flagm=False
flage=True
for A in range(-10**3,10**3):
B5=A**5-X
for B in range(10**3):
if B5==B**5:
flagp=True
flage=False
break
elif B5==-B**5:
flagm=True
flage=False
break
else:
continue
break
if flagp:
print(A,B)
elif flage:
raise Exception
else:
print(A,-B) | N = int(input())
A = list(map(int, input().split()))
bottom = sum(A)
if N == 0:
if A[0] != 1:
print(-1)
else:
print(1)
exit()
ret = 1
children = 1 - A[0]
bottom -= A[0]
for i in range(N):
children = children * 2 - A[i+1]
if children <= -1:
ret = -1
break
bottom -= A[i+1]
if children >= bottom:
children = bottom
ret += children + A[i+1]
print(ret) | 0 | null | 22,281,229,641,660 | 156 | 141 |
n = int(input())
a = list(map(int, input().split()))
max_node = [0 for _ in range(n+1)]
for i in range(n-1, -1, -1):
max_node[i] = max_node[i+1] + a[i+1]
ans = 1
node = 1
for i in range(n+1):
node -= a[i]
if (i < n and node <= 0) or node < 0:
print(-1)
exit(0)
node = min(node * 2, max_node[i])
ans += node
print(ans) | from sys import exit
from collections import deque
N = int(input())
D = deque(map(int, input().split()))
if N == 0:
d = D.pop()
if d == 1:
print(1)
else:
print(-1)
exit()
R = [[] for i in range(N + 1)]
leaf = D.pop()
R[-1].append(leaf)
R[-1].append(leaf)
for i in range(N - 1, -1, -1):
leaf = D.pop()
R[i].append(R[i + 1][0]//2 + R[i + 1][0] % 2 + leaf)
R[i].append(R[i + 1][1] + leaf)
R[i].append(leaf)
if not(R[0][0] <= 1 <= R[0][1]):
print(-1)
exit()
node = 1
ans = 1
for i in range(1, N + 1):
node = min(R[i][1], 2 * (node - R[i-1][2]))
ans += node
print(ans) | 1 | 18,868,114,977,280 | null | 141 | 141 |
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
for i in range(n-k):
if a[i]<a[i+k]:
print("Yes")
else:
print("No") | 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
n=int(input())
nlist=make_divisors(n)
n1list=make_divisors(n-1)
# print(nlist)
# print(n1list)
answer=len(n1list)-1#1を除きます
for i in nlist[1:len(nlist)]:
pra=n
while (pra%i==0):
pra=pra/i
if pra%i==1:
answer+=1
print(answer)
| 0 | null | 24,314,679,038,392 | 102 | 183 |
import itertools
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
A.sort()
ac = list(itertools.accumulate(A))
ans = 0
for i in range(N):
ans += A[i]*(ac[-1]-ac[i])
print(ans % MOD)
| N, K = map(int, input().split())
P = int(1e9+7)
cnt = [0]*(K+1)
ans = 0
for i in range(K, 0, -1):
c = pow(K//i, N, P) - sum(cnt[::i])
cnt[i] = c
ans = (ans+i*c)%P
print(ans%P)
| 0 | null | 20,347,660,418,250 | 83 | 176 |
def main():
N = int(input())
S = list(input())
R = []
G = []
B = []
cnt = 0
for i in range(len(S)):
if S[i] == "R":
R.append(i)
elif S[i] == "G":
G.append(i)
elif S[i] == "B":
B.append(i)
l = len(B)
for i in range(len(R)):
r = R[i]
for j in range(len(G)):
g = G[j]
cnt += l
if g > r:
M = g
m = r
elif r > g:
M = r
m = g
d = M - m
if (M + d) < N and S[M + d] == "B":
cnt -= 1
if (m - d) >= 0 and S[m - d] == "B":
cnt -= 1
if (M + m) % 2 == 0 and S[int((M + m) / 2)] == "B":
cnt -= 1
print(cnt)
main() | import sys
readline = sys.stdin.buffer.readline
import math
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
N = int(readline())
S = readline().decode('utf-8')
total = S.count('R') * S.count('G') * S.count('B')
for stride in range(1, math.ceil(N / 2) + 1):
for start in range(N):
if start + stride * 2 >= N:
break
else:
if S[start] != S[start + stride] and S[start + stride] != S[start + stride * 2] and S[start + stride * 2] != S[start]:
total -= 1
print(total)
if __name__ == '__main__':
main()
| 1 | 36,052,052,844,120 | null | 175 | 175 |
import sys
MOD = 998244353
def main():
input = sys.stdin.buffer.readline
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[None] * (s + 1) for _ in range(n + 1)]
# dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
for i in range(n + 1):
for j in range(s + 1):
if i == 0 or j == 0:
dp[i][j] = 0
continue
if j > a[i - 1]:
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
elif j == a[i - 1]:
dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
else:
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= MOD
print(dp[n][s])
if __name__ == '__main__':
main()
| N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
for s in range(S+1):
if s-A[i-1] >= 0:
dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-A[i-1]]) % MOD
else:
dp[i][s] = dp[i-1][s] * 2 % MOD
print(dp[N][S])
| 1 | 17,698,923,385,400 | null | 138 | 138 |
# ####################################################################
# import io
# import sys
# _INPUT = """\
# 1001
# 1079
# 432
# 12 5 2
# cabbabaacaba
# 10 2 3
# abccabaabb
# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################
import sys
def p(*_a):
return
_s=" ".join(map(str,_a))
#print(_s)
sys.stderr.write(_s+"\n")
####################################################################
yn = lambda b: print('Yes') if b else print('No')
####################################################################
N = int(input())
NO = ":("
a = (N-1) // 1.08
for i in range(100):
b = a + i
if int(b * 1.08) == N:
print( int(b) )
exit()
print(NO)
| class UnionFind:
def __init__(self, n):
self.par = [i for i in range(n+1)]
self.rank = [0] * (n+1)
self.size = [1] * (n+1)
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self, x, y):
return self.find(x) == self.find(y)
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
a, b = map(int, input().split())
uf.union(a, b)
max = 1
for size in uf.size:
if size > max:
max = size
print(max) | 0 | null | 64,590,509,920,992 | 265 | 84 |
a= list(map(int,input().split()))
N = a[0]
K = a[1]
a = [0]*K
mod = 10**9+7
for x in range(K,0,-1):
a[x-1] = pow(K//x, N,mod)
for t in range(2,K//x+1):
a[x-1] -= a[t*x-1]
s = 0
for i in range(K):
s += (i+1)*a[i]
ans = s%mod
print(ans) | n=int(input())
l=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
a=int(input())
for j in range(a):
x,y = map(int,input().split())
l[i][x-1]=y
ans=0
for i in range(2**n):
d=[0 for x in range(n)]
for j in range(n):
if i>>j & 1:
d[j]=1
flag=1
for j in range(n):
for s in range(n):
if d[j]==1:
if l[j][s]==-1:
continue
if l[j][s]!=d[s]:
flag=0
break
if flag:
ans=max(ans,sum(d))
print(ans) | 0 | null | 78,942,154,753,610 | 176 | 262 |
A, B, C, K = map(int, input().split())
if A >= K:
print(K)
else:
K = K - A
if B >= K:
print(A)
else:
K = K - B
print(A - K) | a, b, c, k = map(int, input().split())
if k >= a + b + c:
print(a - c)
exit()
elif k <= a:
print(k)
elif k <= a + b:
print(a)
exit()
else:
print(a - (k - a - b))
exit() | 1 | 21,880,621,586,908 | null | 148 | 148 |
N,K = map(int,input().split())
RST = list(map(int,input().split()))
#r:0 s:1 p:2
# a mod K != b mod Kならばaとbは独立に選ぶことができる。
# よってN個の手をmod KによるK個のグループに分け、各グループにおける最大値を求め、最終的にK個のグループの和が答え
T = [0 if i=="r" else 1 if i=="s" else 2 for i in input()]
dp = [[0]*3 for i in range(N)]
#直後の手を見て決める
for i in range(N):
if i<K:
for j in range(3):
# j:1,2,0
# j==0 -> RST[0]
#初期値は勝つ手を出し続ける
if (j+1)%3==T[i]:
dp[i][j]=RST[j]
else:
#現在の出す手
for j in range(3):
#K回前に出した手
for l in range(3):
if j!=l:
if (j+1)%3 == T[i]:
dp[i][j] = max(dp[i][j],RST[j]+dp[i-K][l])
else:
dp[i][j] = max(dp[i][j],dp[i-K][l])
ans = 0
for i in range(N-K,N):
ans += max(dp[i])
print(ans) | def decide_hand2(T, hand, i, K, N):
if T[i] == "r":
if i <= K - 1:
hand[i] = "p"
else:
if hand[i - K] == "p":
hand[i] = "-"
else:
hand[i] = "p"
elif T[i] == "p":
if i <= K - 1:
hand[i] = "s"
else:
if hand[i - K] == "s":
hand[i] = "-"
else:
hand[i] = "s"
elif T[i] == "s":
if i <= K - 1:
hand[i] = "r"
else:
if hand[i - K] == "r":
hand[i] = "-"
else:
hand[i] = "r"
def main():
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
hand = ["" for _ in range(N)]
for i in range(N):
decide_hand2(T, hand, i, K, N)
ans = 0
for i in range(N):
if hand[i] == "r":
ans += R
elif hand[i] == "s":
ans += S
elif hand[i] == "p":
ans += P
print(ans)
if __name__ == "__main__":
main() | 1 | 106,616,325,934,328 | null | 251 | 251 |
#個数が無制限のナップザックの問題(ただし、上限に注意)です(どの魔法を順番に選べば良いなどの制約がないのでナップザックDPを選択しました。)。
#dpの配列にはi番目の要素にモンスターの体力をi減らすために必要な最小の魔力を保存します。
#この配列は個数制限がないことに注意してinfではない要素のみを順に更新していけば良いです。
#また、最終的にモンスターの体力を最小の魔力で0以下にすれば良いので、モンスターの体力をh以上減らせる最小の魔力を求めれば良いです。
h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
a_sub,b_sub=map(int,input().split())
a.append(a_sub)
b.append(b_sub)
inf=10000000000000
ma=max(a)#ダメージの最大値
dp=[inf]*(h+1+ma)#与えるダメージの最大値を考慮したDP
dp[0]=0#初期値
for i in range(h+1+ma):# 与えるダメージ合計:0ーH+1+maまで
if dp[i] == inf:#更新してきて、ダメージiになる組み合わせが存在しない場合は飛ばす
continue
for j in range(n): #N個の魔法を試す
ni = i + a[j] #今の状態から新しく与えた場合のダメージ合計
if ni<h+ma:#オーバーキルの範囲を超えるなら、無視
dp[ni] = min(dp[ni], dp[i] + b[j]) #ダメージniを与えるのにより小さい魔力で実現できる場合は更新
print(min(dp[h:]))
| h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
aa,bb=map(int,input().split())
a.append(aa)
b.append(bb)
inf=10**10
f=h+max(a)+1
dp=[f*[inf]for _ in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
dp[i]=dp[i-1]
for j in range(f):
if j+a[i-1]<f:
dp[i][j+a[i-1]]=min(dp[i][j+a[i-1]],dp[i][j]+b[i-1])
for j in range(f-1,0,-1):
dp[i][j-1]=min(dp[i][j-1],dp[i][j])
print(dp[-1][h])
| 1 | 81,021,923,940,188 | null | 229 | 229 |
def count(i, s):
left = right = 0
for e in s:
if e == "(":
left += 1
else:
if left == 0:
right += 1
else:
left -= 1
return left-right, left, right, i
n = int(input())
S = [input() for i in range(n)]
s1 = []
s2 = []
for i, e in enumerate(S):
c = count(i, e)
# print(i, c)
if c[0] >= 0:
s1.append((c[2], c[3]))
else:
s2.append((-c[1], c[3]))
s1.sort()
s2.sort()
# print(s1, s2)
s = []
for e in s1:
s.append(S[e[1]])
for e in s2:
s.append(S[e[1]])
# print(s)
_, left, right, _ = count(0, "".join(s))
if left == right == 0:
print("Yes")
else:
print("No")
| n=int(input())
lipp = []
lipm = []
limm = []
allcnt = 0
for _ in range(n):
s = input()
cnt = 0
mi = 0
for x in s:
cnt += 1 if x == '(' else -1
mi = min(mi,cnt)
if cnt >= 0:
lipm.append([mi,cnt])
else:
limm.append([mi - cnt, -cnt])
allcnt += cnt
if allcnt != 0:
print('No')
exit()
lipm.sort(reverse = True)
limm.sort(reverse = True)
def solve(l):
now = 0
for mi, cnt in l:
if mi + now < 0:
print('No')
exit()
now += cnt
solve(lipm)
solve(limm)
print("Yes") | 1 | 23,703,144,867,592 | null | 152 | 152 |
k = int(input())
a,b = map(int, input().split())
for i in range(1,1000):
if a<= k*i <= b:
print("OK")
exit()
else:
pass
print("NG") | k = int(input())
a, b = map(int, input().split())
i = 1
ans = "NG"
while k*i <= b:
if a <= k*i:
ans = "OK"
break
i += 1
print(ans) | 1 | 26,644,349,217,600 | null | 158 | 158 |
import sys
youbi = ["MON", "TUE", "WED", "THU", "FRI", "SAT"]
S = input()
if S == "SUN":
print(7)
sys.exit()
for i, youbi in enumerate(youbi):
if S == youbi:
print(6-i)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = input()
day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - day.index(s)) | 1 | 133,126,498,893,348 | null | 270 | 270 |
n = int(input())
XY = [[] for _ in range(n)]
ans = 0
for i in range(n):
a = int(input())
for _ in range(a):
x, y = map(int, input().split())
XY[i].append((x-1, y))
for i in range(2**n):
correct = [False]*n
tmp_cnt = 0
flag = True
for j in range(n):
if i&(1<<j):
correct[j] = True
tmp_cnt += 1
for j in range(n):
if correct[j]:
for x, y in XY[j]:
if (y==0 and correct[x]) or (y==1 and not correct[x]):
flag = False
if flag:
ans = max(tmp_cnt, ans)
print(ans) | n = int(input())
s, t = input().split()
ans = ""
for x in range(n):
ans = ans + s[x]
ans = ans + t[x]
print(ans) | 0 | null | 116,876,004,918,400 | 262 | 255 |
n = input()
arr = [map(int,raw_input().split()) for _ in range(n)]
tou = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for line in arr:
b,f,r,v = line
tou[b-1][f-1][r-1] = tou[b-1][f-1][r-1] + v
for i in range(4):
for j in range(3):
print ' '+' '.join(map(str,tou[i][j]))
if i < 3 :
print '#'*20 | #coding:utf-8
a,b=map(int,input().split())
print(str(a//b)+" "+str(a%b)+" "+"%.6f"%(a/b)) | 0 | null | 863,012,430,180 | 55 | 45 |
W = input().lower()
ans = 0
while 1:
T = input()
if T == "END_OF_TEXT":
break
ans += T.lower().split().count(W)
print(ans)
| S = list(input())
K = int(input())
S.extend(S)
prev = ''
cnt = 0
for s in S:
if s == prev:
cnt += 1
prev = ''
else:
prev = s
b = 0
if K % 2 == 0:
b += 1
if K > 2 and S[0] == S[-1]:
mae = 1
while mae < len(S) and S[mae] == S[0]:
mae += 1
if mae % 2 == 1 and mae != len(S):
usiro = 1
i = len(S) - 2
while S[i] == S[-1]:
usiro += 1
i -= 1
if usiro % 2 == 1:
b = K // 2
if K % 2 == 0:
res = cnt * (K // 2) + (b - 1)
else:
res = cnt * (K // 2) + cnt // 2 + b
print(res)
| 0 | null | 88,934,834,198,730 | 65 | 296 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
S = input()
T = input()
#TがSの部分文字列になるようにSを書き換える
N = len(S)
M = len(T)
L = N - M #Sを調べるループの回数
#二重ループが許される
ans = M
for i in range(L+1):
#最大M個一致していない。
cnt = M
for j in range(M):
if S[i+j] == T[j]:
cnt -= 1
#最小を取る
ans = min(ans, cnt)
print(ans)
if __name__ == '__main__':
main()
| import math
n=int(input())
xs=list(map(float,input().split()))
ys=list(map(float,input().split()))
ds=[ abs(x - y) for (x,y) in zip(xs,ys) ]
print('{0:.6f}'.format(sum(ds)))
print('{0:.6f}'.format((sum(map(lambda x: x*x,ds)))**0.5))
print('{0:.6f}'.format((sum(map(lambda x: x*x*x,ds)))**(1./3.)))
print('{0:.6f}'.format(max(ds))) | 0 | null | 1,971,937,657,440 | 82 | 32 |
N = int(input())
P = list(map(int, input().split()))
Q = []
for i in range(N):
if i == 0:
Q.append(P[i])
else:
Q.append(min(Q[-1], P[i]))
cnt = 0
for i in range(N):
if P[i] <= Q[i]:
cnt += 1
print(cnt) | n = int(input())
l = list(map(int, input().split()))
s = 0
m = l[0]
for i in range(n):
if m >= l[i]:
m = l[i]
s += 1
print(s)
| 1 | 85,581,145,080,420 | null | 233 | 233 |
x, y = map(int, input().split())
for i in range(x + 1):
if 2 * (x - i) + 4 * i == y:
print("Yes")
break
else:
print("No") | import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")
s = s()
k = k()
if s[0]*len(s) == s:
print(len(s)*k // 2)
sys.exit()
res = [1]
for i in range(len(s)-1):
if s[i] == s[i+1]:
res[-1] += 1
else:
res.append(1)
for i in res:
ans += (i//2)*k
if s[0] == s[-1]:
diff = (res[0]+res[-1])//2 - (res[0]//2 + res[-1]//2)
ans += diff*(k-1)
print(ans)
| 0 | null | 94,142,477,107,100 | 127 | 296 |
buf = str(input())
print(buf.swapcase())
| word = input()
print(word.swapcase()) | 1 | 1,483,434,011,488 | null | 61 | 61 |
n = int(input())
mod = 10**9+7
ans = 0
ans += pow(10, n, mod)
ans -= pow(9, n, mod)
ans -= pow(9, n, mod)
ans += pow(8, n, mod)
ans %= mod
print(ans) | def main():
n = int(input())
a_list = list(map(int, input().split()))
current = a_list[0]
answer = 0
for a in a_list:
if a < current:
answer += current - a
current = max(a, current)
print(answer)
if __name__ == '__main__':
main()
| 0 | null | 3,828,661,753,900 | 78 | 88 |
N, K, C = map(int, input().split())
S = input()
mae = [0] * (2 * N)
ato = [0] * (2 * N)
cnt = 0
n = 0 - N - 100
for i in range(N):
if i - n <= C:
continue
if S[i] == 'o':
mae[cnt] = i
cnt += 1
n = i
cnt = K - 1
n = 2 * N + 100
for i in range(N-1, -1, -1):
if n - i <= C:
continue
if S[i] == 'o':
ato[cnt] = i
cnt -= 1
n = i
for i in range(K):
if mae[i] == ato[i]:
print(mae[i]+1)
| n,k,c=map(int,input().split())
s=input()
x,y=[0]*n,[0]*n
work1,work2=[],[]
last=-10**9;cnt=0
for i in range(n):
if s[i]=="o" and i-last>c:
cnt+=1
last=i
work1.append(i)
if cnt==k: break
nextw=10**9;cnt=0
for i in range(n-1,-1,-1):
if s[i]=="o" and nextw-i>c:
work2.append(i)
cnt+=1
nextw=i
if cnt==k: break
work2.reverse()
for i in range(k):
if work1[i]==work2[i]: print(work1[i]+1) | 1 | 40,775,620,637,048 | null | 182 | 182 |
import math
a, b, C = map(int, input().split())
C = math.radians(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
S = a * b * math.sin(C) / 2
print(f"{S:0.9f}")
print(f"{a+b+c:0.9f}")
print(f"{S*2/a:0.9f}")
| N = input()
K = int(input())
if len(N) < K:
print(0)
exit()
ans = [1, int(N[-1]), 0, 0];
nine = [1, 9, 81, 729]
def combination(N,K):
if N < K:
return 0
elif K == 0:
return 1
elif K == 1:
return N
elif K == 2:
return N*(N-1)//2
else:
return N*(N-1)*(N-2)//6
for k in range(1, len(N)):
if int(N[-k-1]) > 0:
a = [1, 0, 0, 0]
for j in range(1, K+1):
a[j] += nine[j]*combination(k, j)
a[j] += (int(N[-k-1])-1)*combination(k, j-1)*nine[j-1] + ans[j-1]
ans = a
print(ans[K]) | 0 | null | 37,874,384,833,560 | 30 | 224 |
def main():
n = int(input())
# a, b, c, d = map(int, input().split())
a = list(map(int, input().split()))
# s = input()
mx = 0
result = 0
for num in a:
mx = max(mx, num)
if mx > num:
result += mx - num
print(result)
if __name__ == '__main__':
main()
| n = int(input())
a = list(map(int, input().split()))
def judge(x, y):
if x > y:
return(x-y)
else:
return(0)
ans = 0
for i in range(n - 1):
xy = judge(a[i], a[i+1])
a[i+1] += xy
ans += xy
print(ans) | 1 | 4,512,220,158,910 | null | 88 | 88 |
while True:
try:
As,Bs = map(int,input().split())
a,b = As, Bs
while True:
if a % b == 0:
gcd = b
break
a,b = b, a % b
print(gcd,int(As * Bs / gcd))
except EOFError:
break | def main():
N = int(input())
A = list(map(int, input().split(' ')))
insertion_sort(A, N)
def insertion_sort(A, N):
print(' '.join([str(n) for n in A]))
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(' '.join([str(n) for n in A]))
return A
if __name__ == '__main__':
main() | 0 | null | 3,590,236,676 | 5 | 10 |
# -*- coding: utf-8 -*-
a, b = input().split()
if a > b:
print(b*int(a))
else:
print(a*int(b))
| a,b = map(int,input().split())
ans = str(min(a,b))*max(a,b)
print(ans) | 1 | 84,794,420,043,518 | null | 232 | 232 |
t,T,a,A,b,B=map(int, open(0).read().split())
x,y=(a-b)*t,(A-B)*T
if x+y==0:
r="infinity"
else:
s,t=divmod(-x, x+y)
r=0 if s<0 else s*2+(1 if t else 0)
print(r) | n = int(input().rstrip())
print(str(n ** 3)) | 0 | null | 65,727,004,304,350 | 269 | 35 |
a=[300000,200000,100000]
x,y=map(int,input().split())
ans=0
if x<4:
ans+=a[x-1]
if y<4:
ans+=a[y-1]
if x==y==1:
ans+=400000
print(ans) | a,b = map(int,input().split())
s = list(map(int,input().split()))
w = []
for i in range(b):
w.append(min(s))
s.remove(min(s))
print(sum(w)) | 0 | null | 76,076,419,530,122 | 275 | 120 |
N, M, K = map(int, input().split())
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]
for _ in range(M):
a, b = map(int, input().split())
a, b = a - 1, b - 1
F[a].append(b)
F[b].append(a)
for _ in range(K):
c, d = map(int, input().split())
c, d = c - 1, d - 1
B[c].append(d)
B[d].append(c)
class UnionFind:
def __init__(self, n):
# 親要素のノード番号を格納。par[x] == xの時そのノードは根(最初は全て根)
self.par = [i for i in range(n)]
# 木の高さを格納する(初期状態では0)
self.rank = [0] * n
# 人間の数
self.size = [1] * n
# 検索
def find(self, x):
# 根ならその番号を返す
if self.par[x] == x:
return x
# 根でないなら、親の要素で再検索
else:
# 走査していく過程で親を書き換える(return xが代入される)
self.par[x] = self.find(self.par[x])
return self.par[x]
# 併合
def union(self, x, y):
# 根を探す
x = self.find(x)
y = self.find(y)
if x == y:
return
# 木の高さを比較し、低いほうから高いほうに辺を張る
if self.rank[x] < self.rank[y]:
self.par[x] = y
self.size[y] += self.size[x]
else:
self.par[y] = x
self.size[x] += self.size[y]
# 木の高さが同じなら片方を1増やす
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
# 同じ集合に属するか判定
def same(self, x, y):
return self.find(x) == self.find(y)
# すべての頂点に対して親を検索する
def all_find(self):
for n in range(len(self.par)):
self.find(n)
UF = UnionFind(N)
for iam in range(N):
for friend in F[iam]:
UF.union(iam, friend) # 自分と自分の友達を併合
ans = [UF.size[UF.find(iam)] - 1 for iam in range(N)] # 同じ集合に属する人の数
for iam in range(N):
ans[iam] -= len(F[iam]) # すでに友達関係にある人達を引く
for iam in range(N):
for block in B[iam]:
if UF.same(iam, block): # ブロック関係にあったら引く
ans[iam] -= 1
print(*ans, sep=' ')
| '''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
n,m,k = map(int,ipt().split())
fl = [[] for i in range(n)]
bl = [set() for i in range(n)]
for i in range(m):
a,b = map(int,ipt().split())
fl[a-1].append(b-1)
fl[b-1].append(a-1)
for i in range(k):
c,d = map(int,ipt().split())
bl[c-1].add(d-1)
bl[d-1].add(c-1)
ans = [-1]*n
al = [True]*n
for i in range(n):
if al[i]:
q = [i]
al[i] = False
st = set([i])
while q:
qi = q.pop()
for j in fl[qi]:
if al[j]:
st.add(j)
al[j] = False
q.append(j)
lst = len(st)
for j in st:
tmp = lst-len(fl[j])-1
for k in bl[j]:
if k in st:
tmp -= 1
ans[j] = tmp
print(" ".join(map(str,ans)))
return None
if __name__ == '__main__':
main()
| 1 | 61,517,284,706,472 | null | 209 | 209 |
n, d = map(int, input().split())
number = 0
for i in range(n):
x, y = map(int, input().split())
distance = x ** 2 + y ** 2
if distance <= d ** 2:
number += 1
print(number) | N,D=map(int,input().split())
ans=0
for _ in range(N):
X,Y=map(int,input().split())
if X*X+Y*Y<=D*D:
ans+=1
print(ans)
| 1 | 5,929,849,222,880 | null | 96 | 96 |
def my_print(s, a, b):
print(s[a:b+1])
def my_reverse(s, a, b):
return s[:a] + s[a:b+1][::-1] + s[b+1:]
def my_replace(s, a, b, p):
return s[:a] + p + s[b+1:]
if __name__ == '__main__':
s = input()
q = int(input())
for i in range(q):
code = input().split()
op, a, b = code[0], int(code[1]), int(code[2])
if op == 'print':
my_print(s, a, b)
elif op == 'reverse':
s = my_reverse(s, a, b)
elif op == 'replace':
s = my_replace(s, a, b, code[3]) | a,b=input().split()
ans=int(a)*round(float(b)*100)//100
print(int(ans)) | 0 | null | 9,247,012,613,140 | 68 | 135 |
w = input().lower()
n = 0
while True:
t = input()
if t == 'END_OF_TEXT': break
n += t.lower().split().count(w)
print(n) | from collections import Counter
n=int(input())
a=list(map(int,input().split()))
dic=Counter(a)
for val in dic.values():
if val>=2:
print("NO")
exit()
print("YES") | 0 | null | 37,667,313,000,860 | 65 | 222 |
import sys
lines = [list(map(int,line.split())) for line in sys.stdin]
n,m,l = lines[0]
A = lines[1:n+1]
B = [i for i in zip(*lines[n+1:])]
for a in A:
row = []
for b in B:
row.append(sum([i*j for i,j in zip(a,b)]))
print (" ".join(map(str,row))) | import sys
e=[list(map(int,e.split()))for e in sys.stdin]
n=e[0][0]+1
t=''
for c in e[1:n]:
for l in zip(*e[n:]):t+=f'{sum(s*t for s,t in zip(c,l))} '
t=t[:-1]+'\n'
print(t[:-1])
| 1 | 1,434,349,002,854 | null | 60 | 60 |
K = int(input())
for i in range(0, K):
print("ACL", end="")
| import bisect
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-1):
for k in range(i+1,N-1):
a=L[i]+L[k]
b=bisect.bisect_left(L,a)
ans=ans+(b-k-1)
print(ans) | 0 | null | 87,141,380,112,420 | 69 | 294 |
# coding:utf-8
def main():
N = int(input().rstrip())
for i in range(N):
ls = list(map(int, input().split(' ')))
ls.sort()
if(ls[0]**2 + ls[1]**2 == ls[2]**2):
print('YES')
else:
print('NO')
if __name__ == "__main__":
main() | a = list(map(int, input().split()))
a.sort()
while a[0] > 0:
b = a[1]%a[0]
a[1] = a[0]
a[0] = b
print(a[1]) | 0 | null | 4,213,331,700 | 4 | 11 |
from collections import deque
u = int(input())
g = [[i for i in map(int, input().split())] for _ in range(u)]
graph = [[] for _ in range(u)]
ans = [-1] * u
for i in range(u):
for j in range(g[i][1]):
graph[i].append(g[i][2 + j] - 1)
que = deque()
que.append(0)
ans[0] = 0
while que:
v = que.popleft()
for nv in graph[v]:
if ans[nv] != -1:
continue
ans[nv] = ans[v] + 1
que.append(nv)
for i in range(u):
print(i+1, ans[i])
| n = int(input())
if n%2==1:
print(0)
else:
ans = 0
div = 10
pt = 1
while div<=n:
ans += n//div
div *=5
print(ans) | 0 | null | 58,219,470,045,242 | 9 | 258 |
import sys
input = sys.stdin.readline
# 再帰上限を引き上げる
sys.setrecursionlimit(10**6)
n, u, v = map(int, input().split())
u, v = u-1, v-1
l = [[] for i in range(n)]
for i in range(n-1):
a, b = map(int, input().split())
a, b = a-1, b-1
l[a].append(b)
l[b].append(a)
def dfs(G, cr, seen, dist):
seen[cr] = 1
for i in G[cr]:
if seen[i] == 0:
dist[i] = dist[cr] + 1
dfs(G, i, seen, dist)
return dist
seen_u = [0]*n
seen_v = [0]*n
dist_u = [0]*n
dist_v = [0]*n
T1 = dfs(l, u, seen_u, dist_u)
T2 = dfs(l, v, seen_v, dist_v)
for i in range(n):
if dist_u[i] >= dist_v[i]:
dist_v[i] = -1
print(max(dist_v)-1) | import sys
sys.setrecursionlimit(10**7)
n,u,v=map(int, input().split())
u-=1
v-=1
graph = [[] for _ in range(n+1)]
for i in range(n-1):
a, b=map(int, input().split())
graph[a-1].append(b-1)
graph[b-1].append(a-1)
dist=[[-1, -1] for _ in range(n)]
dist[v][0]=0
dist[u][1]=0
def dfs(graph,v,k):
ver=graph[v]
for vers in ver:
if dist[vers][k]==-1:
dist[vers][k]=dist[v][k]+1
dfs(graph,vers,k)
dfs(graph,v,0)
dfs(graph,u,1)
dist.sort(reverse=True)
for i in range(10**6):
if dist[i][0]-dist[i][1]>=1:
print(dist[i][0]-1)
break | 1 | 118,013,966,479,922 | null | 259 | 259 |
N = int(input())
L = list(map(int, input().split()))
count = 0
L_sort = sorted(L)
length = len(L_sort)
# 最長辺以外の辺の長さの和 > 最長辺の辺の長さ のとき三角形が成り立つ
for i in range(0, length-2):
for j in range(i+1, length-1):
if L_sort[i] == L_sort[j]:
continue
for k in range(j+1, length):
if L_sort[j] == L_sort[k]:
continue
if L_sort[i] + L_sort[j] > L_sort[k]:
count += 1
print(count) | import math
N = int(input())
def enumerate_divisors(N):
all_divisors = set()
for divisor in range(1, int(math.sqrt(N)) + 1):
if N%divisor == 0:
if divisor == 1:
all_divisors.add(N/divisor)
else:
all_divisors = all_divisors | {divisor, N/divisor}
all_divisors = list(all_divisors)
return all_divisors
def calculate_reminder(N, d):
while True:
reminder = N%d
if reminder == 0:
N /= d
else:
return reminder
if N == 2:
counter = 1
else:
counter = len(enumerate_divisors(N-1))
for div in enumerate_divisors(N):
if calculate_reminder(N, div) == 1:
counter += 1
print(counter) | 0 | null | 23,269,118,127,488 | 91 | 183 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.