code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
def main() :
N = input()
sum = 0
for i in range(len(N)):
sum += int(N[i])
if sum % 9 == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
a = int(input())
if a < 2:
print(0)
elif a % 2 == 0:
print(int(a / 2 - 1) )
else:
print(int(a/2))
| 0 | null | 78,749,488,989,350 | 87 | 283 |
import math
a,b,h,m = map(int,input().split())
h_s = 360*h/12+30*m/60
m_s = 360*m/60
s = abs(h_s - m_s)
print(abs(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(s)))))
|
import math
a = [int(s) for s in input().split()]
b = int(max([a[0], a[1]]))
c = int(min([a[0], a[1]]))
d = 0.5 * (a[2] * 60 + a[3])
e = 6 * a[3]
f = abs(d - int(e))
if f >= 180:
f = 360 - f
if f != 0 and f!= 180:
print(math.sqrt(a[0] ** 2 + a[1] ** 2 - 2 * a[0] * a[1] * math.cos(math.radians(f))))
elif f == 0:
print(b-c)
else:
print(b+c)
| 1 | 20,020,161,270,916 | null | 144 | 144 |
import itertools
def check(H, W, K, S, p):
num_groups = p.count(True) + 1
group_total = [0] * num_groups
ret = p.count(True)
for j in range(W):
group_value = [0] * num_groups
group_value[0] += int(S[0][j])
group_idx = 0
for i in range(H-1):
if p[i]:
group_idx += 1
group_value[group_idx] += int(S[i+1][j])
if max(group_value) > K:
return float("inf")
group_total_tmp = list(map(sum, zip(group_value, group_total)))
if max(group_total_tmp) <= K:
group_total = group_total_tmp
else:
group_total = group_value
ret += 1
return ret
def main():
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
ans = float("inf")
for p in itertools.product([True, False], repeat=H-1):
ans = min(ans, check(H, W, K, S, p))
print(ans)
if __name__ == "__main__":
main()
|
A, B, C = map(int, input().split())
K = int(input())
for i in range((K + 1)):
for j in range((K + 1) - i):
for k in range((K + 1) - i - j):
if A * (2 ** i) < B * (2 ** j) < C * (2 ** k):
print("Yes")
exit()
print("No")
| 0 | null | 27,855,030,410,830 | 193 | 101 |
import math
a,b,x = list(map(int,input().split()))
theta = math.degrees(math.atan(a*b*b/2/x))
if(b/math.tan(math.radians(theta)) > a):
theta = math.degrees(math.atan((2*a*a*b-2*x)/a/a/a))
print('{:.7f}'.format(theta))
|
N=int(input())
A=list(map(int,input().split()))
if N%2==0:
dp=[[-float("inf") for _ in range(2)] for _ in range(N+10)]
if N==2:
print(max(A[0],A[1]))
else:
for i in range(N):
if i==0:
dp[i][0]=A[0]
elif i==1:
dp[i][1]=A[1]
elif i==2:
dp[i][0]=A[0]+A[2]
else:
for j in range(2):
if j==0:
dp[i][0]=max(dp[i][0],dp[i-2][0]+A[i])
elif j==1:
dp[i][1]=max(dp[i][1],dp[i-2][1]+A[i],dp[i-3][0]+A[i])
print(max(dp[N-1]))
else:
#print(A[0],A[1])
dp=[[-float("inf") for _ in range(3)] for _ in range(N+10)]
if N==3:
print(max(A[0],A[1],A[2]))
else:
for i in range(N):
if i<4:
if i==0:
dp[i][0]=A[0]
if i==1:
dp[i][1]=A[1]
if i==2:
dp[i][2]=A[2]
dp[i][0]=A[0]+A[2]
if i==3:
dp[i][1]=max(dp[1][1]+A[3],dp[0][0]+A[3])
else:
for j in range(3):
if j==0:#ここでも2こずつ規則よく飛ばすと決めた
dp[i][0]=max(dp[i][0],dp[i-2][0]+A[i])
elif j==1:#1回だけ無茶した
dp[i][1]=max(dp[i][1],dp[i-2][1]+A[i],dp[i-3][0]+A[i])
else:
dp[i][2]=max(dp[i][2],dp[i-2][2]+A[i],dp[i-3][1]+A[i],dp[i-4][0]+A[i])
print(max(dp[N-1]))
| 0 | null | 99,781,175,176,156 | 289 | 177 |
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = Counter(s)
li = sorted(cnt.items(), key=lambda x: (-x[1], x[0]))
m = li[0][1]
for i in range(len(li)):
if li[i][1] < m:
break
print(li[i][0])
|
#!/usr/bin/env python3
def main():
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for s in S:
d[s] += 1
# d = sorted(d.items())
d = sorted(d.items(), key=lambda d: d[1], reverse=True)
res = d[0][1]
lst = []
for i in d:
if res > i[1]:
break
lst.append(i[0])
res = i[1]
for i in sorted(lst):
print(i)
if __name__ == '__main__':
main()
| 1 | 69,938,052,831,970 | null | 218 | 218 |
import sys
import numpy as np
def S(): return sys.stdin.readline().rstrip().split(' ')
def Ss(): return list(S())
def I(): return _I(Ss())
def Is(): return list(I())
def _I(ss): return map(int, ss) if len(ss) > 1 else int(ss[0])
s = S()[0]
t = S()[0]
ans = 0
for i, j in zip([c for c in s], [c for c in t]):
if i != j:
ans += 1
print(ans)
|
s,t,count=input(),input(),0
for i in range(len(s)):
if s[i]!=t[i]:
count+=1
print(count)
| 1 | 10,405,819,570,560 | null | 116 | 116 |
s = input()
def check():
if s != s[::-1]:
return("No")
n = len(s)
s1 = s[:int((n-1)/2)]
#print(s1)
if s1 != s1[::-1]:
return("No")
s2 = s[int((n+3)/2-1):]
if s2 != s2[::-1]:
return("No")
#print(s2)
return("Yes")
print(check())
|
s = input()
n = len(s)
def func():
if n == 3 and s[0] == s[2]:
return"Yes"
else:
a = 0
for i in range(n//2):
if s[i] == s[n - 1 - i]:
a += 1
if a == n//2:
b = 0
for j in range((n-1)//4):
if s[j] == s[(n-1)//2 - 1 - j]:
b += 1
if b == (n-1)//4:
c = 0
for k in range((n - (n+3)//2 + 1)//2):
if s[(n+3)//2 - 1 + k] == s[n - 1 - k]:
c += 1
if c == (n - (n+3)//2 + 1)//2:
return "Yes"
else:
return "No"
else:
return "No"
print(func())
| 1 | 46,637,784,994,148 | null | 190 | 190 |
t=int(input())
print("{}:{}:{}".format(t//60**2,t%60**2//60,t%60**2%60))
|
#hは時間,mは60未満の分,sは60未満の秒
S=int(input())
h=int(S/3600)
m=int(S%3600/60)
s=int(S%3600%60)
print(str(h)+":"+str(m)+":"+str(s))
| 1 | 330,938,440,740 | null | 37 | 37 |
def main():
a, b = input().split()
a = int(a)
b = round(float(b) * 100)
print(int(a * b // 100))
if __name__ == "__main__":
main()
|
A,B = list(input().split())
A = int(A)
B = int((float(B)+0.005)*100)
print(A*B//100)
| 1 | 16,648,259,334,180 | null | 135 | 135 |
a = int(input())
n = 1
while True:
if a*n % 360 == 0:
break
else:
n += 1
print(n)
|
N = int(input())
A = list(map(int, input().split()))
y = sorted([(i+1, A[i]) for i in range(N)], key=lambda x: x[1])
print(" ".join(map(str, [z[0] for z in y])))
| 0 | null | 97,040,691,475,652 | 125 | 299 |
JUDGE_LIST=[[80, "A"],
[65, "B"],
[50, "C"],
[30, "D"]]
while True:
try:
score=[int(x) for x in raw_input().split(" ")]
except EOFError:
break
if score[0]==-1 and score[1]==-1 and score[2]==-1:
break
if score[0]==-1 or score[1]==-1:
print "F"
continue
for judge in JUDGE_LIST:
if judge[0] <= score[0] + score[1]:
if "D" == judge[1] and score[2] >= 50:
print "C"
break
else:
print judge[1]
break
else:
print "F"
|
while True:
i = input().split()
m, f, r = map(int, i)
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
elif m+f >= 80:
print('A')
elif m+f < 80 and m+f >= 65:
print('B')
elif m+f < 65 and m+f >= 50:
print('C')
elif m+f < 50 and m+f >=30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F')
| 1 | 1,239,997,926,022 | null | 57 | 57 |
X,Y,Z = list(map(int, input().split()))
X,Y = Y,X
X,Z = Z,X
print(X,Y,Z)
|
x,y,z=map(int,input().split())
print(z,x,y,sep=" ")
| 1 | 38,233,296,121,570 | null | 178 | 178 |
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
mod=pow(10,9)+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
left,right=-1,10**12+1
a.sort()
f.sort()
# print(a)
while right-left>1:
mid=(right+left)//2
tmp=0
for i in range(n):
tmp+=max(0,a[i]-mid//f[-1-i])
if tmp<=k:
right=mid
else:
left=mid
print(right)
|
import math
n = int(input())
x, y = [int(e) for e in input().split()], [int(e) for e in input().split()]
D1 = D2 = D3 = 0; D4 = []
for x1, y1 in zip(x, y):
D1 += abs(x1-y1)
D2 += abs(x1-y1)**2
D3 += abs(x1-y1)**3
D4.append(abs(x1-y1))
print('{0:.6f}'.format(D1))
print('{0:.6f}'.format(math.sqrt(D2)))
print('{0:.6f}'.format(math.pow(D3, (1/3))))
print('{0:.6f}'.format(max(D4)))
| 0 | null | 82,633,733,714,940 | 290 | 32 |
import sys
import math
def main():
n = int(input().rstrip())
r = 1.05
digit = 3
a = 100000
for i in range(n):
a = math.ceil(a*r/10**digit)*10**digit
print(a)
if __name__ == '__main__':
main()
|
import itertools
import math
N = int(input())
citys = []
for i in range(N):
citys.append([int(x) for x in input().split()])
a = list(itertools.permutations(range(N), N))
ans = 0
for i in a:
b = 0
for j in range(N-1):
b += math.sqrt((citys[i[j]][0] - citys[i[j+1]][0])**2 + (citys[i[j]][1] - citys[i[j+1]][1])**2)
ans += b
print(ans/len(a))
| 0 | null | 74,162,684,528,588 | 6 | 280 |
N = int(input())
t = ""
while N > 0:
t += chr((N-1)%26 + 97)
N = (N-1)//26
print(t[::-1])
|
n = int(input())
digits = []
letters = ''
while n > 0:
digits.append((n-1) % 26)
n = (n -1) // 26
for x in digits[::-1]:
letters += chr(x+97)
print(letters)
| 1 | 11,962,047,906,368 | null | 121 | 121 |
input_line = input()
input_line_cubic = input_line ** 3
print input_line_cubic
|
'''
ITP-1_6-A
??°???????????¢
?????????????????°???????????????????????????????????°?????????????????????????????????
???Input
??\????????\????????¢?????§?????????????????????
n
a1 a2 . . . an
n ?????°????????????????????????ai ??? i ???????????°?????¨????????????
???Output
???????????°?????????????????????????????????????????°??????????´??????????????????????????????\???????????????
??????????????°????????????????????\??????????????¨?????¨????????????????????????
'''
# import
import sys
# ?????°??????????????????
## ??°????????????
cntData = int(input())
#inputData = map(int, input().split())
## ??°
inputData = input().split(" ")
# sort
# inputData.sort(reverse=True)
inputData.reverse()
# Output
print(" ".join(inputData))
| 0 | null | 632,419,609,888 | 35 | 53 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def keyence20_a():
H, W, N = map(int, readlines())
lg = max(H, W)
ans = (N + lg - 1) // lg
print(ans)
keyence20_a()
|
H = int(input())
W = int(input())
N = int(input())
answer = 0
if H >= W:
answer = N // H
if N % H != 0:
answer += 1
else:
answer = N // W
if N % W != 0:
answer += 1
print(answer)
| 1 | 89,243,548,417,170 | null | 236 | 236 |
# with open('./ABC161/max_02') as f:
# l = [s.strip() for s in f.readlines()]
n,k,c = map(int, input().split())
s = input()
l = list()
r = list()
i = 0
while i < n:
if len(l) == k:
break
if s[i] == 'o':
l.append(i)
i += c
i+=1
i = n-1
while i >= 0:
if len(r) == k:
break
if s[i] == 'o':
r.append(i)
i -= c
i-=1
r.sort()
for i in range(k):
if l[i] == r[i]:
print(l[i]+1)
|
from datetime import datetime,timedelta
a=input().split()
a=[int(_) for _ in a]
t1=datetime(2000,1,1,a[0],a[1],0)
t2=datetime(2000,1,1,a[2],a[3],0)
delta=t2-t1
total_seconds=delta.seconds
ans=(total_seconds-a[4]*60)/60
print(int(ans))
| 0 | null | 29,294,108,919,108 | 182 | 139 |
from math import factorial
n,m=map(int,input().split())
ans=0
if n>1:
ans+=factorial(n)//2//factorial(n-2)
if m>1:
ans+=factorial(m)//2//factorial(m-2)
print(ans)
|
s=input()
n=len(s)
from collections import Counter
c=Counter()
m=0
c[m]+=1
d=1
s=s[::-1]
for i in range(n):
m+=int(s[i])*d
m%=2019
d*=10
d%=2019
c[m]+=1
ans=0
for v in c.values():
ans+=v*(v-1)//2
print(ans)
| 0 | null | 38,310,694,229,742 | 189 | 166 |
import math
from decimal import *
import random
def pf(n):
rn = int(n)
ans = []
while(n%2==0):
if(2 not in ans):
ans.append(2)
n//=2
for i in range(3, int(math.sqrt(rn)), 2):
while(n%i==0):
if(i not in ans):
ans.append(i)
n//=i
if(n==1):
break
if(n==1):
break
if(n>2):
ans.append(n)
return sorted(ans)
n = int(input())
d = pf(n)
if(d=={}):
print(1)
else:
ans = 0
for i in range(len(d)):
cnt = 1
while(n >= d[i]**cnt):
if(n%(d[i]**cnt)==0):
n//=(d[i]**cnt)
ans+=1
cnt+=1
print(ans)
|
h, w, k = map(int, input().split())
A =[]
for i in range(h):
a = input()
A.append([a[i] == "#" for i in range(w)])
ans = 0
for bit in range(1 << h):
for tib in range(1 << w):
now = 0
for i in range(h):
for j in range(w):
if(bit >> i) & 1 == 0 and (tib >> j) & 1 == 0 and A[i][j] == True: now += 1
if now == k: ans += 1
print(ans)
| 0 | null | 12,951,538,664,520 | 136 | 110 |
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline
def main():
n=int(input())
ans=0
for i in range(1,n):
if (i!=n-i and i<n-i):
ans+=1
elif i>n-1:
break
print(ans)
if __name__ == '__main__':
main()
|
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
n = int(input())
if n % 2 == 0:
print(n//2 - 1)
else:
print(n//2)
if __name__ == '__main__':
main()
| 1 | 153,905,448,005,162 | null | 283 | 283 |
from functools import reduce
N = int(input())
A = [int(n) for n in input().split()]
X = reduce(int.__xor__, A)
ans = [X^a for a in A]
print(*ans)
|
import math
n = int(input())
count = 0
for i in range(n):
t = int(input())
a = int(t ** (1 / 2))
end = 0
for j in range(2, a + 1):
if t % j == 0:
end = 1
break
if end == 0:
count += 1
print(count)
| 0 | null | 6,284,052,267,310 | 123 | 12 |
def execute(N, A):
dst = 0
s = sum(A)
for v in A:
s -= v
dst += v * s
return dst % (10**9+7)
if __name__ == '__main__':
N = int(input())
A = list(map(int, input().split()))
print(execute(N, A))
|
N=int(input())
if N==0:
print("Yes")
exit()
P=[]
M=[]
for i in range(N):
s=input()
f=0
m=0
cnt=0
for j in range(len(s)):
if s[j]=="(":
cnt+=1
else:
cnt-=1
if cnt<m:
m=cnt
if cnt>=0:
P.append([m,cnt])
else:
M.append([m-cnt,-cnt])
P.sort(reverse=True)
M.sort(reverse=True)
#print(P)
#print(M)
SUM=0
for i,j in P:
SUM+=j
for i,j in M:
SUM-=j
if SUM!=0:
print("No")
exit()
SUMP=0
for i,j in P:
if SUMP>=(-i):
SUMP+=j
else:
print("No")
exit()
SUMM=0
for i,j in M:
if SUMM>=(-i):
SUMM+=j
else:
print("No")
exit()
print("Yes")
| 0 | null | 13,666,798,790,022 | 83 | 152 |
from operator import itemgetter
import bisect
N, D, A = map(int, input().split())
enemies = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
d_enemy = [enemy[0] for enemy in enemies]
b_left = bisect.bisect_left
logs = []
logs_S = [0, ]
ans = 0
for i, enemy in enumerate(enemies):
X, hp = enemy
start_i = b_left(logs, X-2*D)
count = logs_S[-1] - logs_S[start_i]
hp -= count * A
if hp > 0:
attack_num = (hp + A-1) // A
logs.append(X)
logs_S.append(logs_S[-1]+attack_num)
ans += attack_num
print(ans)
|
n,d,a = map(int,input().split())
xh = [list(map(int,input().split())) for _ in range(n)]
xh.sort()
ans = 0
att = [0]*n
cnt = 0
f = []
f1 = [0]*n
for x,h in xh:
f.append(h)
for i in range(n):
tmp = xh[i][0] + 2 * d
while cnt < n:
if xh[cnt][0] <= tmp:
cnt += 1
else:
break
att[i] = min(cnt-1, n-1)
for i in range(n):
if f[i] > 0:
da = -(-f[i]//a)
ans += da
f1[i] -= da * a
if att[i]+1 < n:
f1[att[i]+1] += da * a
if i < n-1:
f1[i+1] += f1[i]
f[i+1] += f1[i+1]
print(ans)
| 1 | 82,689,136,913,900 | null | 230 | 230 |
X, K, D = map(int, input().split())
XX = abs(X)
if XX > K*D:
print(XX - K*D)
else:
if (K - X//D)%2 == 0:
print(X%D)
else:
print(abs(X%D -D))
|
import math
A, B, H, M = map(int, input().split())
theta = math.radians(30 * H - 5.5 * M)
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
print(ans)
| 0 | null | 12,581,914,397,348 | 92 | 144 |
import sys
input = sys.stdin.readline
MAX = 2*10**6+100
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r):
if n<r:
return 0
if n<0 or r<0:
return 0
return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD
K = int(input())
S = input()[:-1]
L = len(S)
ans = 0
for i in range(L, L+K+1):
ans += C(i-1, L-1)*pow(25, i-L, MOD)*pow(26, L+K-i, MOD)
ans %= MOD
print(ans)
|
MAX = 10 ** 5 * 2
mod = 10 ** 9 + 7
frac = [1]
inv_frac=[1]
def pow(a, n):
if n == 0 : return 1
elif n == 1 : return a
tmp = pow(a, n//2)
tmp = (tmp * tmp) % mod
if n % 2 == 1 :
tmp = (tmp * a) % mod
return tmp
def inv(x):
return pow(x, mod - 2 )
for i in range(1,MAX + 1 ):
frac.append( (frac[-1] * i) % mod )
inv_frac.append(inv(frac[-1])%mod)
def comb(n, k):
if k >= n or k < 0 : return 1
return (frac[n]*inv_frac[n-k] * inv_frac[k]) %mod
n,k = map(int,input().split())
count=0
b=inv(n)
for i in range(min(n,k+1)):
a=comb(n,i)
count=(count+a*a*(n-i)*b)%mod
print(count)
| 0 | null | 39,823,174,455,458 | 124 | 215 |
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()
|
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,X,Y = map(int,readline().split())
ans = [0]*N
graph = [[] for _ in range(N)]
for i in range(N-1):
graph[i].append(i+1)
graph[i+1].append(i)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)
def bfs(x,q,dist):
while q:
v = q.popleft()
for nx in graph[v]:
if dist[nx] != 0:
continue
dist[nx] = dist[v] + 1
q.append(nx)
if nx > x:
ans[dist[nx]] +=1
for i in range(N):
dist = [0]*N
q = deque([i])
bfs(i,q,dist)
print('\n'.join(str(n) for n in ans[1:]))
| 1 | 43,842,904,822,398 | null | 187 | 187 |
import re
s = input()
if re.sub(r'hi', '', s) == '':
print('Yes')
else:
print('No')
|
n = int(input())
p = n % 2 + n // 2
print(p)
| 0 | null | 56,342,936,376,258 | 199 | 206 |
from collections import deque
mod = int(1e9+7)
def add(a, b):
c = a + b
if c >= mod:
c -= mod
return c
def main():
n, m = map(int,raw_input().split())
adj_list = [[] for _ in range(n+5)]
q = deque()
ans = [-1] * (n+5)
failed = False
for _ in range(m):
a, b = map(int,raw_input().split())
adj_list[a].append(b)
adj_list[b].append(a)
q.append(1)
#print(adj_list)
visited = set()
visited.add(1)
while len(q):
sz = len(q)
for _ in range(sz):
cur = q.popleft()
for nei in adj_list[cur]:
if nei not in visited:
ans[nei] = cur
q.append(nei)
visited.add(nei)
print('Yes')
for i in range(2, n+1):
print(ans[i])
main()
|
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
a,b = MI()
c,d = MI()
print(1 if d == 1 else 0)
| 0 | null | 72,114,843,096,580 | 145 | 264 |
def f(x, m):
return (x**2) % m
N, X, M = map(int, input().split())
A = [X]
S = {X}
while True:
X = f(X, M)
if X in S:
break
else:
A.append(X)
S.add(X)
start = A.index(X)
l = len(A) - start
ans = sum(A[:start])
N -= start
ans += sum(A[start:]) * (N//l)
N %= l
ans += sum(A[start:start+N])
print(ans)
|
def main():
line = input()
deepen_x = []
cur_x = 0
ponds = [] # [(水たまりの最初の位置, 水量)]
while len(line) > 0:
#print(cur_x, ponds, deepen_x)
tmp_char = line[0]
if tmp_char == '\\':
deepen_x.append(cur_x)
elif tmp_char == '/' and len(deepen_x) != 0:
pre_x = deepen_x.pop()
volume = cur_x - pre_x
if len(ponds) == 0:
ponds.append([pre_x, volume])
else:
if pre_x < ponds[-1][0]:
# 前の水たまりと結合する
a = list(filter(lambda x: x[0] > pre_x, ponds))
pond = 0
for item in a:
pond += item[1]
[ponds.pop() for x in range(len(a))]
ponds.append([pre_x, pond + volume])
else:
# 新しい水たまりを作成
ponds.append([pre_x, volume])
cur_x += 1
line = line[1:]
print(sum([x[1] for x in ponds]))
if len(ponds) == 0:
print('0')
else:
print("{} ".format(len(ponds)) + " ".join([str(x[1]) for x in ponds]))
return
main()
| 0 | null | 1,448,771,609,350 | 75 | 21 |
n=int(input())
a=list(map(int,input().split()))
ans=[0]*(n+1)
for i in a:
ans[i]+=1
for i in range(n):
print(ans[i+1])
|
n = int(input())
an = [0 for _ in range(n)]
for i in input().split():
an[int(i)-1] += 1
for a in an:
print(a)
| 1 | 32,613,937,286,968 | null | 169 | 169 |
while True:
H, W = map(int, input().split())
if not(H or W):
break
for i in range(H):
print('#', end='')
for j in range(W-2):
if i > 0 and i < H - 1:
print('.', end='')
else:
print('#', end='')
print('#')
print()
|
def rect(h, w):
s = '#' * w
while h > 1:
print(s)
s = '#' + '.' * (w - 2) + '#'
h -= 1
print('#' * w)
print()
return
while True:
n = list(map(int, input().split()))
H = n[0]
W = n[1]
if (H == 0 and W == 0):
break
rect(H, W)
| 1 | 833,590,851,838 | null | 50 | 50 |
debt = 100000
n=int(raw_input())
for i in range(1,n+1):
debt = debt*1.05
if(debt % 1000) != 0:
debt = (debt - (debt%1000)) + 1000
print int(debt)
|
n=int(input())
s=100000
for i in range(n):
s*=1.05
p=s%1000
if p!=0:
s+=1000-p
print(int(s))
| 1 | 992,080,662 | null | 6 | 6 |
N = int(input())
ints = map(int, input().split())
for i in ints:
if i % 2 == 0:
if i % 3 != 0 and i % 5 != 0:
print('DENIED')
exit()
print('APPROVED')
|
def merge(A,left,mid,right):
global cnt
n1 = mid - left
n2 = right - mid
cnt += n1+n2
L = [A[left+i] for i in range(n1)]
R = [A[mid+i] for i in range(n2)]
L.append(float("inf"))
R.append(float("inf"))
i = 0
j = 0
for k in range(left,right):
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 = int((left+right)/2)
mergesort(A,left,mid)
mergesort(A,mid,right)
merge(A,left,mid,right)
n = int(input())
A = list(map(int,input().split()))
cnt = 0
mergesort(A,0,n)
print(" ".join(map(str,A)))
print(cnt)
| 0 | null | 34,633,036,807,190 | 217 | 26 |
n = int(input())
ans = [0]*10**5
for i in range(1,int(n**0.5)):
for j in range(1,int(n**0.5)):
for k in range(1,int(n**0.5)):
res = i**2 + j**2 + k**2 +i*j + j*k + k*i
ans[res-1] += 1
for i in range(n):
print(ans[i])
|
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
n, x, m = map(int, input().split())
ans = 0
aa = x
ans += aa
aset = set([aa])
alist = [aa]
for i in range(1,n):
aa = pow(aa,2,m)
if aa in aset:
offset = alist.index(aa)
loop = alist[offset:i]
nloop, tail = divmod(n-offset, len(loop))
ans += sum(loop)*(nloop-1)
ans += sum(loop[0:tail])
break
else:
ans += aa
aset.add(aa)
alist.append(aa)
print(ans)
| 0 | null | 5,449,293,489,052 | 106 | 75 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
mod = 998244353
n, k = map(int, input().split())
l = []
r = []
for _ in range(k):
l_, r_ = map(int, input().split())
l.append(l_)
r.append(r_)
dp = [0] * (n + 1)
dp_csum = [0] * (n + 1)
dp[1] = 1
dp_csum[1] = 1
for i in range(2, n + 1):
for j in range(k):
left = i - r[j]
right = i - l[j]
if right >= 1:
dp[i] += dp_csum[right] - dp_csum[max(left, 1) - 1]
dp[i] %= mod
dp_csum[i] = dp_csum[i - 1] + dp[i]
dp_csum[i] %= mod
print(dp[-1])
|
k = int(input())
hp = [i for i in range(k+4)]
r, w = 1, 10
while w <= k:
n = hp[r]
r += 1
nm = n % 10
val = n * 10 + nm
if nm != 0:
hp[w] = val - 1
w += 1
hp[w] = val
w += 1
if nm != 9:
hp[w] = val + 1
w += 1
print(hp[k])
| 0 | null | 21,254,687,862,282 | 74 | 181 |
def main():
sectionalview = input()
stack = []
a_surface = 0
surfaces = []
for cindex in range(len(sectionalview)):
if sectionalview[cindex] == "\\":
stack.append(cindex)
elif sectionalview[cindex] == "/" and 0 < len(stack):
if 0 < len(stack):
left_index = stack.pop()
a = cindex - left_index
a_surface += a
while 0 < len(surfaces):
if left_index < surfaces[-1][0]:
a += surfaces.pop()[1]
else:
break
surfaces.append((cindex, a))
t = [i[1] for i in surfaces]
print(sum(t))
print(" ".join(map(str, [len(t)] + t)))
if __name__ == "__main__":
import os
import sys
if len(sys.argv) > 1:
if sys.argv[1] == "-d":
fd = os.open("input.txt", os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())
main()
else:
main()
|
input_line = input()
stack = []
area = 0
pond_area = 0
pond_areas = []
for i,s in enumerate(input_line):
if s == '\\':
stack.append(i)
if pond_area:
pond_areas.append((l, pond_area))
pond_area = 0
elif stack and s == '/':
l = stack.pop()
area += i - l
while True:
if not pond_areas or pond_areas[-1][0] < l: break
else:
pond_area += pond_areas.pop()[1]
pond_area += i-l
if pond_area > 0: pond_areas.append((l, pond_area))
print(area)
print( " ".join([str(len(pond_areas))] + [str(a[1]) for a in pond_areas]) )
| 1 | 58,436,304,080 | null | 21 | 21 |
def comb(n,r,m):
if r == 0: return 1
return memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)
def mempow(a,b):
temp = 1
yield temp
for i in range(b):
temp = temp * a % 998244353
yield temp
def memfact(a):
temp = 1
yield temp
for i in range(1,a+1):
temp = temp * i % 998244353
yield temp
N,M,K = (int(x) for x in input().split())
memp = []
memf = []
mpappend = memp.append
mfappend = memf.append
for x in mempow(M-1,N-1):
mpappend(x)
for x in memfact(N-1):
mfappend(x)
ans = 0
if M == 1:
if K + 1 < N:
print('0')
else:
print('1')
else:
i = 0
for i in range(K+1):
ans = (ans + (comb(N-1,i,998244353)*M*memp[N-i-1])) % 998244353
print(ans)
|
n,m,k=map(int,input().split())
mod=998244353
ans=0
fact=[1] * (n+1) # 階乗を格納するリスト
factinv=[1] * (n+1) # 階乗を格納するリスト
for i in range(n):
fact[i+1] = fact[i] * (i+1) % mod # 階乗を計算
factinv[i+1] = pow(fact[i+1], mod-2, mod) # modを法とした逆元(フェルマーの小定理)
def nCk(n,k): # 組み合わせ(mod)を返却する
return fact[n] * factinv[n-k] * factinv[k] % mod
for k_i in range(k+1):
ans += m * pow(m-1, n-1-k_i, mod) * nCk(n-1, k_i)
ans %= mod
print (ans)
| 1 | 23,155,692,598,180 | null | 151 | 151 |
n, k = map(int, input().split())
mod = 998244353
S = []
for _ in range(k):
l, r = map(int, input().split())
S.append([l, r])
dp = [0]*(n+1)
dp_s = [0]*(n+1)
dp[1] = 1
dp_s[1] = 1
for i in range(2, n+1):
for l, r in S:
li = max(i - r, 1)
ri = max(i - l, 0)
dp[i] = (dp[i] + (dp_s[ri] - dp_s[li-1])%mod) % mod
dp_s[i] = (dp_s[i-1] + dp[i])%mod
print(dp[n]%mod)
|
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
mod = 998244353
n,k = readints()
s = [readints() for i in range(k)]
a = [0] * (n+1)
a[1] = 1
b = [0] * k
for i in range(2,n+1):
for j in range(k):
l,r = s[j]
if i-l>0:
b[j] += a[i-l]
if i-r-1>0:
b[j] -= a[i-r-1]
a[i] += b[j]
a[i] %= mod
print(a[-1])
| 1 | 2,717,269,195,072 | null | 74 | 74 |
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import deque
import bisect
from decimal import *
def main():
N, D, A = MI()
Enemy = defaultdict()
Enemy_ran = []
for i in range(N):
x, h = MI()
Enemy[x] = h
Enemy_ran.append(x)
Enemy_ran.sort()
cnt = 0
dam_list = deque()
dam_all = 0
for i in range(N):
x = Enemy_ran[i]
while len(dam_list) != 0 and i >= dam_list[0][0]:
dam_all -= dam_list.popleft()[1]
HP = Enemy[x] - dam_all
if HP <= 0:
continue
else:
ata = math.ceil(Decimal(HP) / Decimal(A))
cnt += ata
ran = x + 2 * D
y = bisect.bisect_right(Enemy_ran, ran)
dam = ata * A
dam_list.append((y, dam))
dam_all += dam
print(cnt)
if __name__ == "__main__":
main()
|
#abc149-d
n,k=map(int,input().split())
s,p,r=map(int,input().split())
f={'s':s,'p':p,'r':r}
t=str(input())
ans=0
for i in range(k):
a=i+k
last=t[i]
ans+=f[last]
while a<n-k:
if t[a]==last:
if t[a+k]==last:
if last=='s':
last='r'
else:
last='s'
else:
if last=='s':
if t[a+k]=='r':
last='p'
else:
last='r'
elif last=='r':
if t[a+k]=='s':
last='p'
else:
last='s'
else:
if t[a+k]=='r':
last='s'
else:
last='r'
else:
last=t[a]
ans+=f[last]
a+=k
if a<n:
if t[a]!=last:
ans+=f[t[a]]
print(ans)
| 0 | null | 94,547,829,082,222 | 230 | 251 |
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)))
|
import math
r = float(raw_input())
print "%.7f %.7f"%(math.pi*r*r, 2*math.pi*r)
| 0 | null | 82,267,451,441,774 | 289 | 46 |
mod = 10**9+7
MAX_N = 10 ** 6
fact = [1]
fact_inv = [0] * (MAX_N + 4)
for i in range(MAX_N + 3):
fact.append(fact[-1] * (i + 1) % mod)
fact_inv[-1] = pow(fact[-1], mod - 2, mod)
for i in range(MAX_N + 2, -1, -1):
fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod
def mod_comb_k(n, k, mod):
return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod
OK = False
X, Y = map(int, input().split())
for i in range(0, max(X, Y)+1):
if (Y - (X - i*2)*2) == i and X-2*i >= 0:
x = i
y = X - i*2
print(mod_comb_k(x + y, min(x, y), mod))
OK = True
break
if not OK:
print(0)
|
X, Y = map(int, input().split())
MOD = 10**9+7
def mod_pow(n, m):
res = 1
while m > 0:
if m & 1:
res = (res*n)%MOD
n = (n*n)%MOD
m >>= 1
return res
if (2*Y-X)%3 != 0 or (2*X-Y)%3 != 0 or 2*Y < X or 2*X < Y:
print(0)
else:
A = (2*X-Y)//3
B = (2*Y-X)//3
m = 1
n = 1
for i in range(A):
m = (m*(A+B-i))%MOD
n = (n*(A-i))%MOD
inverse_n = mod_pow(n, MOD-2)
print((m*inverse_n)%MOD)
| 1 | 150,495,321,264,992 | null | 281 | 281 |
N = int(input())
A_list = list(map(int, input().split()))
zandaka = 1000
kabu = 0
mode = 0
for i in range(N):
if i == 0:
if A_list[i + 1] > A_list[i]:
kabu = 1000 // A_list[i]
zandaka -= kabu * A_list[i]
mode = 1
else:
continue
elif i == N - 1:
zandaka += kabu * A_list[i]
else:
if mode == 1:
if A_list[i] >= A_list[i - 1]:
if A_list[i] > A_list[i + 1]:
zandaka += kabu * A_list[i]
kabu = 0
mode = 0
else:
continue
else:
if A_list[i] < A_list[i + 1]:
kabu = zandaka // A_list[i]
zandaka -= kabu * A_list[i]
mode = 1
else:
continue
if zandaka >= 1000:
print(zandaka)
else:
print(1000)
|
x=input()
y=input()
lst1=[]
lst1=list(x)
lst2=[]
lst2=list(y)
b=0
ans=0
while(b<len(x)):
if(not lst1[b]==lst2[b]):
ans=ans+1
b+=1
print(ans)
| 0 | null | 8,860,346,441,918 | 103 | 116 |
S = input()
ans = "Yes"
if S == "AAA" or S == "BBB":
ans = "No"
print(ans)
|
s = input()
if s.count('B') == 3 or s.count("A") == 3:
print("No")
else:
print("Yes")
| 1 | 54,792,440,138,528 | null | 201 | 201 |
def main(A,B,C,K):
ans=False
while K >= 0:
if A < B:
if B < C:
ans=True
return ans
else:
C = C * 2
else:
B = B * 2
K=K-1
return ans
A,B,C=map(int, input().split())
K=int(input())
ans=main(A,B,C,K)
print('Yes' if ans else 'No')
|
def main():
A,B,C = map(int,input().split())
K = int(input())
num = 0
while (B <= A):
num += 1
if num <= K:
B *= 2
else:
return ("No")
while (C <= B):
num += 1
if num <= K:
C *= 2
else:
return ('No')
return('Yes')
print(main())
| 1 | 6,861,465,920,788 | null | 101 | 101 |
from itertools import groupby
s = input()
A = [(key, sum(1 for _ in group)) for key, group in groupby(s)]
tmp = 0
ans = 0
for key, count in A:
if key == '<':
ans += count*(count+1)//2
tmp = count
else:
if tmp < count:
ans -= tmp
ans += count
ans += (count-1)*count//2
tmp = 0
print(ans)
|
string = input()
lt = True
ans = 0
l_cnt = 0
m_cnt = 0
if string[0] == ">":
lt = False
for s in string:
if s == "<":
if not lt:
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
l_cnt = m_cnt = 0
l_cnt += 1
lt = True
else:
m_cnt += 1
lt = False
a, b = max(l_cnt, m_cnt), min(l_cnt, m_cnt)
ans += a * (a + 1) // 2 + b * (b - 1) // 2
print(ans)
| 1 | 156,624,460,626,488 | null | 285 | 285 |
W=input()
num=0
while True:
T=input()
t=str.lower(T)
if (T == 'END_OF_TEXT'):break
t_split=(t.split())
for i in range(len(t_split)):
if t_split[i] == W:
num+=1
print(num)
|
from sys import stdin
w = str(input()).lower()
t = stdin.read().split()
counter = 0
for i in t:
i = i.lower()
if i == w:
counter += 1
print(counter)
| 1 | 1,826,222,428,666 | null | 65 | 65 |
import queue
n = int(input())
e = []
f = [{} for i in range(n)]
for i in range(n-1):
a,b = map(int, input().split())
a-=1
b-=1
e.append([a,b])
f[a][b]=0
f[b][a]=0
k = 0
for i in range(n-1):
k = max(k,len(f[i]))
q = queue.Queue()
q.put(0)
used = [[0] for i in range(n)]
while not q.empty():
p = q.get()
for key,c in f[p].items():
if c == 0:
if used[p][-1]<k:
col = used[p][-1]+1
else:
col = 1
f[p][key] = col
f[key][p] = col
used[p].append(col)
used[key].append(col)
q.put(key)
print(k)
for a,b in e:
print(max(f[a][b],f[b][a]))
|
def main():
n, x, y = map(int, input().split())
x -= 1
y-= 1
ans = [0]*n
for i in range(n):
for j in range(i+ 1, n):
d = min(j-i, abs(j-y) + abs(x-i) + 1, abs(j-x) + abs(y-i) + 1)
ans[d] += 1
for i in range(1, n):
print(ans[i])
if __name__ == "__main__":
main()
| 0 | null | 90,501,912,289,888 | 272 | 187 |
A = int(input())
B = int(input())
ans = 6-A-B
print(ans)
|
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
sl = []
flag = False
for i in range(h):
for j in range(w):
if s[i][j] == '.':
sl.append([i, j])
q = deque()
dire = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = 0
for sh, sw in sl:
c = [[0]*w for _ in range(h)]
q.append((sh, sw, 0))
while q:
ph, pw, k = q.pop()
if c[ph][pw] == 0:
ans = max(ans, k)
c[ph][pw] = 1
for dh, dw in dire:
hdh, wdw = ph+dh, pw+dw
if 0 <= hdh < h and 0 <= wdw < w and c[hdh][wdw] == 0:
if s[hdh][wdw] == '.':
q.appendleft((hdh, wdw, k+1))
print(ans)
| 0 | null | 103,012,558,610,530 | 254 | 241 |
print(''.join(input().split()[::-1]))
|
s, t = input().split()
print('{}{}'.format(t, s))
| 1 | 102,903,765,257,080 | null | 248 | 248 |
A, B = map(str, input().split())
A_ans=''
B_ans=''
if min(A,B) == A:
for a in range(int(B)):
A_ans += A
print(A_ans)
else:
for b in range(int(A)):
B_ans += B
print(B_ans)
|
# 166A
# 問題文
# AtCoder 社は、毎週土曜日にコンテストを開催しています。
# コンテストには ABC と ARC の
# 2つの種類があり、毎週どちらか一方が開催されます。
# ABC が開催された次の週には ARC が開催され、ARC が行われた次の週には ABC が開催されます。
# 先週開催されたコンテストを表す文字列 Sが与えられるので、
# 今週開催されるコンテストを表す文字列を出力してください。
#
# 制約: Sは ABC または ARC
# 入力: 入力は以下の形式で標準入力から与えられる。
# S
# 出力: 今週開催されるコンテストを表す文字列を出力せよ。
# ABC or ARC
S = input()
if S == 'ABC':
answer = 'ARC'
elif S == 'ARC':
answer = 'ABC'
print(answer)
| 0 | null | 54,446,012,894,148 | 232 | 153 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 +7
n,m = map(int,readline().split())
a = np.array(read().split(),np.int64)
a.sort()
def shake_cnt(x):
X=np.searchsorted(a,x-a)
return n*n-X.sum()
left = 0
right = 10 ** 6
while left+1 <right:
x = (left + right)//2
if shake_cnt(x) >= m:
left = x
else:
right = x
left,right
X=np.searchsorted(a,right-a)
Acum = np.zeros(n+1,np.int64)
Acum[1:] = np.cumsum(a)
shake = n * n -X.sum()
happy = (Acum[-1]-Acum[X]).sum()+(a*(n-X)).sum()
happy += (m-shake)*left
print(happy)
|
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n,m=map(int,input().split())
A=sorted(map(int,input().split()))
B=[0]+A[:]
for i in range(n):
B[i+1]+=B[i]
def solve_binary(mid):
tmp=0
for i,ai in enumerate(A):
tmp+=n-bisect.bisect_left(A,mid-ai)
return tmp>=m
def binary_search(n):
ok=0
ng=n
while abs(ok-ng)>1:
mid=(ok+ng)//2
if solve_binary(mid):
ok=mid
else:
ng=mid
return ok
binresult=binary_search(2*10**5+1)
for i ,ai in enumerate(A):
ans+=ai*(n-bisect.bisect_left(A,binresult-ai))+B[n]-B[bisect.bisect_left(A,binresult-ai)]
count+=n-bisect.bisect_left(A,binresult-ai)
# print(ans,count)
ans-=binresult*(count-m)
print(ans)
# print(binresult)
| 1 | 107,784,726,526,780 | null | 252 | 252 |
a = input()
iff3 = a[2]
iff4 = a[3]
iff5 = a[4]
iff6 = a[5]
if iff3 == iff4 :
if iff5 == iff6 :
print("Yes")
else :
print("No")
else :
print("No")
|
s = input()
print("Yes" if s[2] == s[3] and s[4] == s[5] else "No")
| 1 | 41,914,673,071,532 | null | 184 | 184 |
N = int(input())
M = (N+1000-1)//1000
ans = M*1000-N
print(ans)
|
n=int(input())
print(-n%1000)
| 1 | 8,489,822,612,960 | null | 108 | 108 |
a, b, c = [int(i) for i in input().split(" ")]
ab = a == b
bc = b == c
ca = c == a
cnt = 0
for r in [ab, bc, ca]:
if r:
cnt += 1
if cnt == 1:
print("Yes")
else:
print("No")
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????? I
?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
+--+
???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
???|???|
+--+
"""
class Dice:
""" ????????????????????? """
def __init__(self): # ?????????????????????
self.side = [1, 2, 3, 4, 5, 6]
def setDice(self, arr): # ??¢??????????????????
self.side = arr[0:6]
def Turn(self, dir):
s = self.side
if dir == "N": # ????????¢??????
t = [s[1],s[5],s[2],s[3],s[0],s[4]]
elif dir == "S": # ????????¢??????
t = [s[4],s[0],s[2],s[3],s[5],s[1]]
elif dir == "E": # ??±?????¢??????
t = [s[3],s[1],s[0],s[5],s[4],s[2]]
elif dir == "W": # ?\??????¢??????
t = [s[2],s[1],s[5],s[0],s[4],s[3]]
self.side = t
num = list(map(int,input().strip().split()))
cmd = input().strip()
d = Dice()
d.setDice(num)
for c in cmd:
d.Turn(c)
# print("{0} {1}".format(c,d.side[0]))
print(d.side[0])
| 0 | null | 34,083,957,012,560 | 216 | 33 |
import math
data = map(float, raw_input().split(" "))
rad = data[2]*math.pi/180
h = data[1]*math.sin(rad)
s = data[0]*h/2
l = data[0]+data[1]+math.sqrt((data[0]-data[1]*math.cos(rad))**2+h**2)
print "%f\n%f\n%f" % (s,l,h)
|
import math
a, b, deg = map(float, input().split())
rad = math.radians(deg)
area = 0.5 * a * b * math.sin(rad)
c = math.sqrt(a*a + b*b - 2*a*b*math.cos(rad))
h = area*2 / a;
print(area, a+b+c, h)
| 1 | 174,643,124,182 | null | 30 | 30 |
def div(n):
i = 2
a = n
D = {}
tmp = 1
while i*i <= n:
cnt = 0
while a%i == 0:
a = a // i
tmp *= i
cnt += 1
if cnt > 0:
D[i] = cnt
i += 1
if tmp != n:
D[n] = 1
return D
N = int(input())
D = div(N)
ans = 0
for v in D.values():
i = 1
total = 1
while v >= total+(i+1):
i += 1
total += i
ans += i
print(ans)
|
# -*- coding:utf-8 -*-
def solve():
N = int(input())
"""
■ 解法
N = p^{e1} * p^{e2} * p^{e3} ...
と因数分解できるとき、
z = p_i^{1}, p_i^{2}, ...
としていくのが最適なので、それを数えていく
(例) N = 2^2 * 3^2 * 5 * 7
のとき、
2,3,5,7の4回割れる。(6で割る必要はない)
■ 計算量
素因数分解するのに、O(√N)
割れる回数を計算するのはたかだか素因数分解するより少ないはずなので、
全体としてはO(√N+α)くらいでしょ(適当)
"""
def prime_factor(n):
"""素因数分解する"""
i = 2
ans = {}
while i*i <= n:
while n%i == 0:
if not i in ans:
ans[i] = 0
ans[i] += 1
n //= i
i += 1
if n != 1:
ans[n] = 1
return ans
pf = prime_factor(N)
ans = 0
for key, value in pf.items():
i = 1
while value-i >= 0:
value -= i
ans += 1
i += 1
print(ans)
if __name__ == "__main__":
solve()
| 1 | 17,003,063,913,458 | null | 136 | 136 |
from sys import stdin
inf = 10**9 + 1
def solve():
n = int(stdin.readline())
R = [int(stdin.readline()) for i in range(n)]
ans = max_profit(n, R)
print(ans)
def max_profit(n, R):
max_d = -inf
min_v = R[0]
for i in range(1, n):
max_d = max(max_d, R[i] - min_v)
min_v = min(min_v, R[i])
return max_d
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve()
|
#!/usr/bin/env python3
n = int(input())
R = []
for _ in range(n):
i = int(input())
R.append(i)
i = 0
j = 0
m = -float("inf")
while j < n - 1:
j += 1
if R[j] - R[i] > m:
m = R[j] - R[i]
if R[i] > R[j]:
i = j
print(m)
| 1 | 14,055,816,580 | null | 13 | 13 |
from math import sqrt
a,b,c,d=map(float,input().split())
e=sqrt((c-a)**2+(d-b)**2)
print(e)
|
#coding:utf-8
import math
datas = [float(x) for x in input().split()]
p1 = (datas[0], datas[1])
p2 = (datas[2], datas[3])
print(math.sqrt(math.pow(p1[0]-p2[0], 2)+math.pow(p1[1]-p2[1],2)))
| 1 | 160,119,196,692 | null | 29 | 29 |
N, K = map(int, input().split())
mod = pow(10, 9)+7
Cmax = ((N+N-K+1)*K)//2
Cmin = ((K-1)*K)//2
ans = 1
for i in range(K, N+1):
ans = (ans+Cmax-Cmin+1)
Cmin += i
Cmax += (N-i)
print(ans % mod)
|
N, K = map(int, input().split())
MOD = 10**9 + 7
ans = 0
# 選ぶ個数で場合分け
# 選べる個数はK,K+1,K+2,...,N+1
# 等差数列の和S
# 項数n, 初項a,末項l,公差d
# S=(n/2)*(a+l)
# S=(n/2)*{2a+(n-1)d}
for i in range(K, N + 2):
min_sum = i * (i - 1) // 2 # 0+1+...(項数=i)
max_sum = (2 * N - i + 1) * i // 2 # N+(N-1)+...(項数=i)
ans += max_sum - min_sum + 1 # minとmaxの間の数を全て取れる
ans %= MOD
print(ans)
| 1 | 33,279,934,183,680 | null | 170 | 170 |
def fib(n):
if n==0 or n==1:
return 1
x=[1,1]
for i in range(2,n+1):
x.append(x[i-1]+x[i-2])
return x[-1]
print(fib(int(input())))
|
n=int(input())
if 30<=n :
print('Yes')
else:
print('No')
| 0 | null | 2,844,417,689,020 | 7 | 95 |
ma = lambda :map(int,input().split())
n,u,v = ma()
u,v = u-1,v-1
tree = [[] for i in range(n)]
import collections
for i in range(n-1):
a,b = ma()
tree[a-1].append(b-1)
tree[b-1].append(a-1)
que = collections.deque([(v,0)])
vis = [False]*n
dist_v = [0]*n
while que:
now,c = que.popleft()
vis[now] = True
dist_v[now] = c
for node in tree[now]:
if not vis[node]:
que.append((node,c+1))
que = collections.deque([(u,0)])
vis = [False]*n
dist_u = [0]*n
while que:
now,c = que.popleft()
vis[now] = True
dist_u[now] = c
for node in tree[now]:
if not vis[node]:
que.append((node,c+1))
ans = 0
for i in range(n):
if dist_u[i] < dist_v[i]:
ans = max(ans,dist_v[i])
print(ans-1)
|
N, u, v = map(int, input().split())
u, v = u-1, v-1
ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
#%%
roots = [[] for _ in range(N)]
for AB in ABs:
roots[AB[0]].append(AB[1])
roots[AB[1]].append(AB[0])
#BFS
def BFS(roots, start):
from collections import deque
seen = [-1 for _ in range(N)]
seen[start] = 0
todo = deque([start])
while len(todo) > 0:
checking = todo.pop()
for root in roots[checking]:
if seen[root] == -1:
seen[root] = seen[checking] +1
todo.append(root)
return seen
from_u = BFS(roots, u)
from_v = BFS(roots, v)
from collections import deque
todo = deque([u])
max_distance = from_v[u]
position = u
seen = [False for _ in range(N)]
seen[u] = True
while len(todo) > 0:
checking = todo.pop()
for root in roots[checking]:
if from_u[root] < from_v[root] and seen[root] == False:
seen[root] = True
todo.append(root)
if max_distance < from_v[root]:
max_distance = from_v[root]
position = root
print(max_distance-1)
| 1 | 117,923,059,943,470 | null | 259 | 259 |
import sys
def print_arr(arr):
ln = ''
for v in arr:
ln += str(v) + ' '
ln = ln.strip()
print(ln)
def insertion_sort(arr):
for i in range(1, len(arr)):
print_arr(arr)
v = arr[i]
j = i-1
while j >= 0 and arr[j] > v:
arr[j+1] = arr[j]
j -= 1
arr[j+1] = v
print_arr(arr)
input0 = sys.stdin.readline()
input_sample = sys.stdin.readline()
# input_sample = "5 2 4 6 1 3"
input = input_sample.split(" ")
input = [int(i) for i in input]
insertion_sort(input)
|
def inserts(N):
k = 1
for n in N:
print(n, end='')
if k < len(N):
print(' ', end='')
k += 1
print('')
for i in range(1,len(N)):
# ?????????????´??????????????????£????????¨?????????
v = N[i]
j = i - 1
while j >= 0 and N[j] > v:
N[j + 1] = N[j]
j -= 1
N[j + 1] = v
k = 1
for n in N:
print(n, end='')
if k < len(N):
print(' ', end='')
k += 1
print('')
n = int(input())
numbers = list(map(int, input().split()))
inserts(numbers)
| 1 | 6,483,595,840 | null | 10 | 10 |
from math import gcd
x = int(input())
y = x * 360 // gcd(x, 360)
print(y//x)
|
def gcd(a, b):
while b:
a, b = b, a%b
return a
def lcm(a, b):
return a*b//gcd(a, b)
X = int(input())
print(lcm(360, X)//X)
| 1 | 13,145,661,925,368 | null | 125 | 125 |
n=int(input())
l =[]
for i in range(n):
s =input()
l.append(s)
l = set(l)
print(len(l))
|
a, b = input().split()
print(int(a)*int(b[0]+b[2]+b[3])//100)
| 0 | null | 23,384,375,150,172 | 165 | 135 |
import sys
def main():
orders = sys.stdin.readlines()[1:]
dna_set = set()
for order in orders:
command, dna = order.split(" ")
if command == "insert":
dna_set.add(dna)
elif command == "find":
if dna in dna_set:
print("yes")
else:
print("no")
if __name__ == "__main__":
main()
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n, m, k = map(int, input().split())
uf = UnionFind(n)
friends = [0] * n
blocks = [0] * n
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.union(a, b)
friends[a] += 1
friends[b] += 1
for k in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if uf.same(c, d):
blocks[c] += 1
blocks[d] += 1
for i in range(n):
print(uf.size(i) - friends[i] - blocks[i] - 1, end=" ")
| 0 | null | 31,046,115,765,700 | 23 | 209 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, M = mapint()
S = list(input())
def solve():
now = N
choice = []
while 1:
if now==0:
return choice[::-1]
for m in range(M, 0, -1):
nx = now-m
if nx<0: continue
if S[nx]=='1': continue
now = nx
choice.append(m)
break
else:
return [-1]
print(*solve())
|
n,m=map(int,input().split())
l=list(input())
l=l[::-1]
now=0
ans=[]
while now<n:
num=min(n-now,m)#進める最大
b=True
for i in range(num):
num1=num-i
if l[now+num1]!="1":
ans.append(str(num1))
now+=num1
b=False
break
if b:
now=n+1
if b:
print(-1)
else:
ans=ans[::-1]
print(" ".join(ans))
| 1 | 138,837,898,276,884 | null | 274 | 274 |
#Union Find
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
# print(par)
return par[x]
#xとyの属する集合の併合
def unite(x,y):
x = find(x)
y = find(y)
if x == y:
return False
else:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y]
par[y] = x
return True
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
#xが属する集合の個数
def size(x):
return -par[find(x)]
N, M = map(int, input().split())
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]
#初期化
#根なら-size,子なら親の頂点
par = [-1]*N
for i in range(M):
a, b = map(int, input().split())
unite(a-1, b-1)
# print(par)
#print()
group = set([])
for i in range(N):
group.add(find(i))
#print(group)
ans = 0
for g in group:
# print(size(g))
ans = max(ans, size(g))
print(ans)
|
from sys import stdin
input = stdin.readline
N, M = map(int, input().split())
friends = [tuple(map(int, inp.strip().split())) for inp in stdin.read().splitlines()]
father = [-1] * N
def getfather(x):
if father[x] < 0: return x
father[x] = getfather(father[x])
return father[x]
def union(x, y):
x = getfather(x)
y = getfather(y)
if x != y:
if father[x] > father[y]:
x,y = y,x
father[x] += father[y]
father[y] = x;
for a, b in friends:
union(a - 1, b - 1)
# print(max(Counter([getfather(i) for i in range(N)]).values()))
print(max([-father[getfather(i)] for i in range(N)] or [0]) )
| 1 | 3,941,073,474,282 | null | 84 | 84 |
h,n=map(int,input().split())
inf=100000000000
dp=[inf]*(h+1)
dp[h]=0
for i in range(n):
a,b=map(int,input().split())
for j in range(h,-1,-1):
dp[max(j-a,0)]=min(dp[max(j-a,0)],dp[j]+b)
print(dp[0])
|
H,N = map(int,input().split())
INF = 10 ** 10
dp = [INF] * (H + 1)
dp[0] = 0
for i in range(N):
attack,magic = map(int,input().split())
for j in range(len(dp)):
if dp[j] == INF:
continue
target = j + attack
if j + attack > H:
target = H
if dp[target] > dp[j] + magic:
dp[target] = dp[j] + magic
print(dp[-1])
| 1 | 81,582,136,303,920 | null | 229 | 229 |
n = input()
a = map(int, raw_input().split())
if len(a) == n:
a.reverse()
print ' '.join(map(str, a))
|
import sys
input = lambda: sys.stdin.readline().rstrip()
INF = 10 ** 9 + 7
H, N = map(int, input().split())
AB = [[] for _ in range(N)]
for i in range(N):
AB[i] = list(map(int, input().split()))
def solve():
dp = [INF] * (H + 1)
dp[H] = 0
for h in range(H, 0, -1):
if dp[h] == INF:
continue
next_dp = dp
for i in range(N):
a, b = AB[i]
hh = max(0, h - a)
next_dp[hh] = min(dp[hh], dp[h] + b)
dp = next_dp
print(dp[0])
if __name__ == '__main__':
solve()
| 0 | null | 40,930,880,049,802 | 53 | 229 |
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
S, W = LI()
if S <= W:
print("unsafe")
else:
print("safe")
|
import copy
def main():
h, o = map(int, input().split(' '))
if h <= o:
print('unsafe')
else:
print('safe')
main()
| 1 | 29,211,238,472,472 | null | 163 | 163 |
N = int(input())
a = list(map(int, input().split()))
b = []
j = N-1
while j > 0:
print("{} ".format(a[j]),end = "")
j -= 1
print(a[j])
|
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
res=0
m=1
for i in a:
b=m-i
if b<0:
print(-1)
exit(0)
res+=i
res+=b
s-=i
m=min(b*2,s)
print(res)
| 0 | null | 9,865,427,735,962 | 53 | 141 |
MOD = pow(10, 9)+7
def combi(n, k, MOD):
numer = 1
for i in range(n, n-k, -1):
numer *= i
numer %= MOD
denom = 1
for j in range(k, 0, -1):
denom *= j
denom %= MOD
return (numer*(pow(denom, MOD-2, MOD)))%MOD
def main():
n, a, b = map(int, input().split())
allsum = pow(2, n, MOD)
s1 = combi(n, a, MOD)
s2 = combi(n, b, MOD)
ans = (allsum - s1 - s2 - 1)%MOD
print(ans)
if __name__ == "__main__":
main()
|
n, a, b = list(map(int, input().split()))
p = 10**9+7
def binom(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
res = factinv[r] % p
for i in range(r):
res = res * (n - i) % p
return res % p
factinv = [1, 1]
inv = [0, 1]
for i in range(2, min(n, 2*10**5) + 1):
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
res = pow(2, n, p)
res -= 1
res = (res - binom(n, a, p)) % p
res = (res - binom(n, b, p)) % p
print(res)
| 1 | 66,260,709,435,790 | null | 214 | 214 |
while True:
x,y=map(int,input().split())
if (x==0) & (y==0):
break
else:
if x>y:
print(y,x)
else:
print(x,y)
|
while True:
a = map(int, raw_input().split(" "))
if len([x for x in a if x <> 0]) <= 0:
break
else:
a.sort()
print " ".join(map(str, a))
| 1 | 527,992,913,020 | null | 43 | 43 |
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
T = 0
ans = float("inf")
for e in A:
T += e
ans = min(ans,abs(T-(S-T)))
print(ans)
|
text=input()
n=int(input())
for i in range(n):
order=input().split()
a,b=map(int,order[1:3])
if order[0]=="print":
print(text[a:b+1])
elif order[0]=="reverse":
re_text=text[a:b+1]
text=text[:a]+re_text[::-1]+text[b+1:]
else :
text=text[:a]+order[3]+text[b+1:]
| 0 | null | 71,824,248,749,708 | 276 | 68 |
S = list(input())
# 問題文の通りに実装する
n = len(S)
for i in range(n):
S[i] = 'x'
ans = ''
for i in range(n):
ans += S[i]
print(ans)
|
S=input()
a=[]
for i in range(len(S)):
a.append('x')
print(''.join(a))
| 1 | 72,806,323,394,860 | null | 221 | 221 |
import sys
for line in sys.stdin:
H, W = map(int, line.split())
if H == 0 and W == 0:
break
for _ in range(H):
print( '#' * W )
print("")
|
def resolve():
H = int(input())
ans = 1
while H > 0:
ans *= 2
H //= 2
print(ans - 1)
resolve()
| 0 | null | 40,542,266,609,350 | 49 | 228 |
MOD = 10 ** 9 + 7
N = int(input())
A = [int(i) for i in input().split()]
sums = [[0] * 3 for _ in range(N + 1)]
ans = 1
for i, a in enumerate(A):
f = True
count = 0
for j in range(3):
sums[i + 1][j] = sums[i][j]
if sums[i][j] == a:
count += 1
if f:
sums[i + 1][j] += 1
f = False
ans = ans * count % MOD
#print(sums)
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 1
cnt = [0] * 3
for i in range(n):
t = 0
first = True
for j in range(3):
if cnt[j] == a[i]:
t += 1
if first:
first = False
cnt[j] += 1
ans = (ans * t) % mod
print(ans)
| 1 | 130,167,910,130,648 | null | 268 | 268 |
N = int(input())
for i in range(1, 50000):
pay = int(i*1.08)
if pay == N:
print(i)
break
elif pay > N:
print(':(')
break
|
# -*- coding: utf-8 -*-
def main():
from math import ceil
n = int(input())
count = 0
for i in range(1, ceil(n / 2)):
j = n - i
if i != j:
count += 1
print(count)
if __name__ == '__main__':
main()
| 0 | null | 139,615,706,938,508 | 265 | 283 |
a,b=map(int, input().split())
if a == 1 or b == 1:
print(1)
if a != 1 and b != 1 and a*b%2== 0:
print(a*b//2)
if a != 1 and b != 1 and a*b%2!= 0:
print(a*b//2+1)
|
import math
h , w = map(int , input().strip().split())
if h != 1 and w != 1:
print(math.ceil(h * w / 2))
else:
print(1)
| 1 | 50,710,654,201,568 | null | 196 | 196 |
m,f,r = 0,0,0
table = []
i = 0
while m != -1 or f != -1 or r != -1:
m,f,r = (int(x) for x in input().split())
table.append([m,f,r])
for p in table:
m,f,r = p[0],p[1],p[2]
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65:
print('B')
elif m + f >= 50:
print('C')
elif m + f >= 30:
if r >= 50:
print('C')
else:
print('D')
else:
print('F')
|
def main():
N, M = tuple([int(_x) for _x in input().split()])
print(N*(N-1)//2 + M*(M-1)//2)
main()
| 0 | null | 23,425,324,454,674 | 57 | 189 |
N = int(input())
b = list(map(int, input().split()))
MOD = 1000000007
sum_n = 0
a = []
for i in b:
a.append(i%MOD)
sum_sum = sum(a[1:])
for i in range(N):
sum_n = (sum_n + (a[i] * sum_sum) % MOD) % MOD
if i+1 < N:
sum_sum = sum_sum - a[i+1]
print(sum_n % MOD)
|
N = int(input())
arr = list(map(int, input().split(" ")))
mod = 10 ** 9 + 7
s = sum(arr) % mod
result = 0
for i in arr:
s -= i
s %= mod
result += s * i
result %= mod
print(result)
| 1 | 3,841,034,796,940 | null | 83 | 83 |
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
print(0)
exit()
l[d[i]]+=1
mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
ans *= t**l[i]
t=l[i]
print(ans%998244353)
|
list = input().split()
m1 = int(list[0])*60 + int(list[1])
m2 = int(list[2])*60 + int(list[3])
#print(m1,m2)
ans = m2 - m1
print(ans-int(list[4]))
| 0 | null | 86,704,454,873,092 | 284 | 139 |
import sys
input = sys.stdin.readline
def read():
S = input().strip()
return S,
def solve(S):
N = len(S)
ans = 0
for i in range(N//2):
if S[i] != S[N-i-1]:
ans += 1
return ans
if __name__ == '__main__':
inputs = read()
print(solve(*inputs))
|
S = input()
hug = 0
if len(S) % 2 == 0:
for i in range(int(len(S)/2)):
if not S[i] == S[-i-1]:
hug += 1
else:
pass
else:
for i in range(int((len(S)+1)/2)):
if not S[i] ==S[-i-1]:
hug += 1
else:
pass
print(hug)
| 1 | 120,269,977,764,832 | null | 261 | 261 |
import math
x = int(input())
ans = 0
y = 100
while y < x:
y += y//100
ans += 1
print(ans)
|
X=int(input())
year=0
deposit=100
while deposit<X:
deposit=deposit*101//100
year+=1
print(year)
| 1 | 26,950,704,848,522 | null | 159 | 159 |
import sys
def gcd(a, b):
while b % a:
a, b = b % a, a
return a
def lcm(a, b):
return a * b // gcd(a, b)
for line in sys.stdin:
a, b = sorted(list(map(int, line.split())))
print(gcd(a, b), lcm(a, b))
|
def Binary_Search_Small_Count(A,x,equal=False,sort=False):
"""2分探索によって,x未満の要素の個数を調べる.
A:リスト
x:調べる要素
sort:ソートをする必要があるかどうか(Trueで必要)
equal:Trueのときはx"未満"がx"以下"になる
"""
if sort:
A.sort()
if A[0]>x or ((not equal) and A[0]==x):
return 0
L,R=0,len(A)
while R-L>1:
C=L+(R-L)//2
if A[C]<x or (equal and A[C]==x):
L=C
else:
R=C
return L+1
def Binary_Search_Equal_Count(A,x,sort=False):
"""2分探索によって,xの個数を調べる.
A:リスト
x:調べる要素
sort:ソートをする必要があるかどうか(Trueで必要)
equal:Trueのときはx"を超える"がx"以上"になる
"""
if sort:
A.sort()
if x<A[0] or A[-1]<x:
return 0
X=Binary_Search_Small_Count(A,x,equal=True)
Y=Binary_Search_Small_Count(A,x,equal=False)
return X-Y
#================================================
N=int(input())
A=["*"]+list(map(int,input().split()))
B=[0]*N
for j in range(1,N+1):
B[j-1]=j-A[j]
B.sort()
K=0
del A[0]
for i in range(1,N+1):
K+=Binary_Search_Equal_Count(B,i+A[i-1],False)
print(K)
| 0 | null | 13,121,238,522,482 | 5 | 157 |
roll = {"N": (1, 5, 2, 3, 0, 4),
"S": (4, 0, 2, 3, 5, 1),
"E": (3, 1, 0, 5, 4, 2),
"W": (2, 1, 5, 0, 4, 3)}
dice = input().split()
for direction in input():
dice = [dice[i] for i in roll[direction]]
print(dice[0])
|
from typing import List
class Dice:
def __init__(self, s: List[int]):
self.s = s
def get_s(self) -> int:
return self.s[0]
def invoke_method(self, mkey: str) -> None:
if mkey == 'S':
self.S()
return None
if mkey == 'N':
self.N()
return None
if mkey == 'E':
self.E()
return None
if mkey == 'W':
self.W()
return None
raise ValueError(f'This method does not exist. : {mkey}')
def set_s(self, s0, s1, s2, s3, s4, s5) -> None:
self.s[0] = s0
self.s[1] = s1
self.s[2] = s2
self.s[3] = s3
self.s[4] = s4
self.s[5] = s5
def S(self) -> None:
self.set_s(self.s[4], self.s[0], self.s[2], self.s[3], self.s[5],
self.s[1])
def N(self) -> None:
self.set_s(self.s[1], self.s[5], self.s[2], self.s[3], self.s[0],
self.s[4])
def E(self) -> None:
self.set_s(self.s[3], self.s[1], self.s[0], self.s[5], self.s[4],
self.s[2])
def W(self) -> None:
self.set_s(self.s[2], self.s[1], self.s[5], self.s[0], self.s[4],
self.s[3])
# 提出用
data = [int(i) for i in input().split()]
order = list(input())
# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('SE')
dice = Dice(data)
for o in order:
dice.invoke_method(o)
print(dice.get_s())
| 1 | 233,072,494,682 | null | 33 | 33 |
hillheight = []
for i in range(0, 10):
hillheight.append(int(raw_input()))
hillheight.sort()
for i in range(0, 3):
print(hillheight[-1-i])
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
mod = 1000000007
def ST():
return input().rstrip()
def I():
return int(input())
def MI():
return map(int, input().split())
def LI():
return list(MI())
N, K = MI()
MAX = sum(range(N - K + 2, N + 1))
MIN = sum(range(0, K - 1))
ans = 0
for k in range(K, N + 2):
MAX += N - k + 1
MIN += k - 1
ans += (MAX - MIN + 1) % mod
print(ans % mod)
| 0 | null | 16,608,715,049,286 | 2 | 170 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X,Y,A,B,C = map(int,readline().split())
P = list(map(int,readline().split()))
Q = list(map(int,readline().split()))
R = list(map(int,readline().split()))
P = sorted(P,reverse=True)
Q = sorted(Q,reverse=True)
R = sorted(R,reverse=True)
P = P[:X]
Q = Q[:Y]
PQR = sorted(P+Q+R,reverse = True)
ans = sum(PQR[:X+Y])
print(ans)
|
x,y,a,b,c=[int(i) for i in input().split()]
red_list=[int(i) for i in input().split()]
green_list=[int(i) for i in input().split()]
non_col_list=[int(i) for i in input().split()]
red_list.sort()
green_list.sort()
non_col_list.sort()
eat_red=[]
eat_green=[]
for i in range(x):
eat_red.append(red_list.pop())
for i in range(y):
eat_green.append(green_list.pop())
ans_list=eat_green+eat_red+non_col_list
ans_list.sort()
ans=0
for i in range(x+y):
ans+=ans_list.pop()
print(ans)
| 1 | 44,875,654,885,490 | null | 188 | 188 |
n = input()
a = list(map(int, input().split()))
print(' '.join(map(str, reversed(a))))
|
r = float(input())
pi = 3.141592653589793
print(pi*r**2, 2*pi*r)
| 0 | null | 807,120,310,190 | 53 | 46 |
class Info:
def __init__(self,arg_start,arg_end,arg_S):
self.start = arg_start
self.end = arg_end
self.S = arg_S
LOC = []
POOL = []
line = input()
loc = 0
sum_S = 0
for ch in line:
if ch == '\\':
LOC.append(loc)
elif ch == '/':
if len(LOC) == 0:
continue
tmp_start = int(LOC.pop())
tmp_end = loc
tmp_S = tmp_end-tmp_start;
sum_S += tmp_S;
#既に突っ込まれている池の断片が、今回の断片の部分区間になるなら統合する
while len(POOL) > 0:
if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
tmp_S += POOL[-1].S
POOL.pop()
else:
break
POOL.append(Info(tmp_start,tmp_end,tmp_S))
else:
pass
loc += 1
print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")
while len(POOL) > 0:
print(" %d"%(POOL[0].S),end = "") #先頭から
POOL.pop(0)
print()
|
from scipy.sparse.csgraph import floyd_warshall
N,M,L = list(map(int, input().split()))
edges = [[0] * N for _ in range(N)]
for _ in range(M):
A,B,C = list(map(int, input().split()))
edges[A-1][B-1] = C
edges[B-1][A-1] = C
Q = int(input())
queries = []
for _ in range(Q):
queries.append(list(map(int,input().split())))
# use flord warshall to find min path between all towns
edges = floyd_warshall(edges)
# if the two towns can be travelled to on one tank, add to our fuel graph with distance 1
for i in range(N):
for j in range(N):
if edges[i][j] <= L:
edges[i][j] = 1
else:
edges[i][j] = 0
# use flord warshall to find min number of fuel tanks to travel between two towns
edges = floyd_warshall(edges)
for query in queries:
s = query[0] - 1
t = query[1] - 1
num_tanks = edges[s][t] - 1
if num_tanks != float('inf'):
print(int(num_tanks))
else:
print("-1")
| 0 | null | 86,560,357,223,470 | 21 | 295 |
import sys
x, y = map(int, input().split())
ans = 0
for i in range(x+1):
if y == i*2 + (x - i)* 4:
ans = 1
break
if ans == 1:
print("Yes")
else:
print("No")
|
X, Y= map(int, input().strip().split())
if Y%2==0 and 2*X<=Y and Y<=4*X:print('Yes')
else:print('No')
| 1 | 13,710,513,013,850 | null | 127 | 127 |
H1, M1, H2, M2, K = map(int, input().split())
r = (H2*60+M2)-(H1*60+M1)-K
print(r)
|
H1, M1, H2, M2, K = map(int, input().split())
ans = H2*60 + M2 - H1*60 - M1 - K
print(ans)
| 1 | 18,018,829,593,792 | null | 139 | 139 |
N = int(input())
# A*B=Nとなるような1以上9以下の整数(A, B)が存在するかどうか全探索を行う
ans = 'No'
for i in range(1, 10):
for j in range(1, 10):
if i*j == N:
ans = 'Yes'
break
print(ans)
|
data = set()
for i in range(1,10):
for j in range(1,10):
data.add(i*j)
if int(input()) in data:
print("Yes")
else:
print("No")
| 1 | 160,337,946,480,156 | null | 287 | 287 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(S: str, T: str, A: int, B: int, U: str):
return f"{A-(S==U)} {B-(T==U)}"
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
T = next(tokens) # type: str
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
U = next(tokens) # type: str
print(f'{solve(S, T, A, B, U)}')
if __name__ == '__main__':
main()
|
N = int(input())
out_ans = []
while N > 26:
N -= 1
out_ans.append(int(N % 26))
N = (N // 26)
N -= 1
out_ans.append(int(N))
out_dic = ['a', 'b', 'c','d', 'e', 'f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t','u','v',
'w','x','y','z']
ans = ''
for i in range(len(out_ans)-1, -1, -1):
ans = ans + (out_dic[out_ans[i]])
print(ans)
| 0 | null | 42,202,698,276,160 | 220 | 121 |
m_1,d_1 = map(int,input().split())
m_2,d_2 = map(int,input().split())
if m_1 < m_2:
print('1')
else:
print('0')
|
MOD = 10**9 + 7
N, K = map(int, input().split())
def getFacts(n, MOD):
facts = [1] * (n+1)
for x in range(2, n+1):
facts[x] = (facts[x-1] * x) % MOD
return facts
facts = getFacts(2*N, MOD)
def getInvFacts(n, MOD):
invFacts = [0] * (n+1)
invFacts[n] = pow(facts[n], MOD-2, MOD)
for x in reversed(range(n)):
invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
return invFacts
invFacts = getInvFacts(2*N, MOD)
def getComb(n, k, MOD):
if n < k:
return 0
return facts[n] * invFacts[k] * invFacts[n-k] % MOD
ans = 0
for x in range(min(K, N-1)+1):
ans += getComb(N, x, MOD) * getComb(N-1, x, MOD)
ans %= MOD
print(ans)
| 0 | null | 95,476,463,430,080 | 264 | 215 |
from collections import Counter
s = input()
n = len(s)
dp = [0]
mod = 2019
a = 0
for i in range(n):
a = a + int(s[n-i-1]) * pow(10, i, mod)
a %= mod
dp.append(a%mod)
ans = 0
c = Counter(dp)
for value in c.values():
ans += value * (value-1) / 2
print(int(ans))
|
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n,m=map(int,input().split())
A=sorted(map(int,input().split()))
B=[0]+A[:]
for i in range(n):
B[i+1]+=B[i]
def solve_binary(mid):
tmp=0
for i,ai in enumerate(A):
tmp+=n-bisect.bisect_left(A,mid-ai)
return tmp>=m
def binary_search(n):
ok=0
ng=n
while abs(ok-ng)>1:
mid=(ok+ng)//2
if solve_binary(mid):
ok=mid
else:
ng=mid
return ok
binresult=binary_search(2*10**5+1)
for i ,ai in enumerate(A):
ans+=ai*(n-bisect.bisect_left(A,binresult-ai))+B[n]-B[bisect.bisect_left(A,binresult-ai)]
count+=n-bisect.bisect_left(A,binresult-ai)
# print(ans,count)
ans-=binresult*(count-m)
print(ans)
# print(binresult)
| 0 | null | 69,332,408,361,260 | 166 | 252 |
while True:
l = input().split()
h = int(l[0])
w = int(l[1])
if h == 0 and w ==0:
break
flag = 0
for i in range(h*(w+1)):
if (i+1) % (w+1) == 0:
print("")
if w % 2 == 0:
flag += 1
if i == h*(w+1)-1:
print("")
else:
if flag % 2 == 0:
print("#", end="")
flag += 1
else:
print(".", end="")
flag += 1
|
#!/usr/bin/env python
k = int(input())
s = 'ACL'
ans = ''
for i in range(k):
ans += s
print(ans)
| 0 | null | 1,511,259,986,060 | 51 | 69 |
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
x = readInt()
for i in range(int(x//105),int(x//100)+2):
t = x-100*i
if 0<=t and t<=5*i:
print(1)
exit()
print(0)
|
w = input()
t = []
while True:
s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()]
t += s
if 'fin' in s:
break
print(t.count(1))
| 0 | null | 64,580,069,882,952 | 266 | 65 |
mountains = []
for x in range(10):
mountains.append(int(raw_input()))
mountains.sort()
print(mountains[-1])
print(mountains[-2])
print(mountains[-3])
|
n,m = map(int,input().split())
a = 0
for i in range(m):
if n % 2 == 0 and n % 4 != 0 and n-4*i-2 == 0:
a = 1
elif n % 4 == 0 and i == (n//2-1) // 2 + 1:
a = 1
print('{} {}'.format(i+1, n-i-a))
| 0 | null | 14,400,345,814,596 | 2 | 162 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.