code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys, 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
read = sys.stdin.buffer.read
x = int(read())
print(10 - x//200) | value = int(input())
kyu_rated = 8
lvalue = 400
rvalue = 599
for i in range(0, 8):
if lvalue <= value <= rvalue:
print(kyu_rated)
flag = 1
break
else:
lvalue += 200
rvalue += 200
kyu_rated -= 1
| 1 | 6,660,711,350,800 | null | 100 | 100 |
n = int(input())
a = list(map(int,input().split()))
cumsum_a = a.copy()
for i in range(n-1, -1, -1):
cumsum_a[i] += cumsum_a[i+1]
ans = 0
childable_node = 1
for i in range(n + 1):
if a[i] > childable_node:
ans = -1
break
ans += childable_node
if i < n:
b_max1 = 2 * (childable_node - a[i])
b_max2 = cumsum_a[i + 1]
childable_node = min(b_max1, b_max2)
print(ans) | def give_grade(m, f, r):
if m == -1 or f == -1:
return "F"
elif m + f < 30:
return "F"
elif m + f < 50:
return "D" if r < 50 else "C"
elif m + f < 65:
return "C"
elif m + f < 80:
return "B"
else:
return "A"
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
else:
print(give_grade(m, f, r)) | 0 | null | 10,038,642,826,408 | 141 | 57 |
from fractions import gcd
N, M = map(int, input().split())
S = list(map(int, input().split()))
temp = S[0]
cnt = 0
while temp%2 == 0:
temp //= 2
cnt += 1
temp = S[0]
for i in range(1, N):
temp = temp*S[i]//gcd(temp, S[i])
if S[i]%(2**cnt) == 1 or (S[i]//(2**cnt))%2 == 0:
print(0)
break
else:
if temp//2 > M:
print(0)
else:
print((M-temp//2)//temp+1) | import math
import numpy as np
N,M=map(int,input().split())
A=list(map(int,input().split()))
c=1
test=A[0]
l=0
while test%2 == 0:
test=test//2
c*=2
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
for i in np.arange(N-1):
if A[i+1]%c!=0:
print(0)
l=1
break
elif A[i+1]%(c*2)==0:
print(0)
l=1
break
else:
k=A[i+1]//c
test=lcm_base(test, k)
if l==0:
k=test*c//2
print(M//k//2 + M//k%2) | 1 | 101,569,347,652,800 | null | 247 | 247 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
d = abs(A-B)
if d-(V-W)*T<=0:
print("YES")
else:
print("NO") | s=input().split()
print(s[1]+s[0])
| 0 | null | 58,812,575,478,310 | 131 | 248 |
S = input().rstrip()
print('x' * len(S))
| s=input()
con=len(s)
ans=['x']*con
ANS=''
for i in ans:
ANS+=i
print(ANS) | 1 | 72,730,493,319,198 | null | 221 | 221 |
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 11 16:48:51 2020
@author: Aruto Hosaka
"""
import math
import collections
K = int(input())
ans = 0
g = []
for a in range(K):
for b in range(K):
g.append(math.gcd(a+1, b+1))
G = collections.Counter(g)
for k in range(K):
for c in range(K):
ans += math.gcd(k+1, c+1)*G[k+1]
print(ans) | import sys
read = sys.stdin.buffer.read
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**9)
#from functools import lru_cache
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
import math
def main():
k=II()
ans=0
li=[[0]*(k+1) for i in range(k+1)]
for a in range(1,k+1):
for b in range(1,k+1):
li[a][b]=math.gcd(a,b)
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
ans+=math.gcd(li[a][b],c)
print(ans)
if __name__ == "__main__":
main()
| 1 | 35,461,597,471,008 | null | 174 | 174 |
from itertools import accumulate
from bisect import bisect
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = 0
for i in range(n+1):
if a[i] > k:
break
ans = max(ans, i+bisect(b, k-a[i])-1)
print(ans) | import sys
N, M, K = [int(s) for s in sys.stdin.readline().split()]
n = 0
A = [0]
for s in sys.stdin.readline().split():
n = n + int(s)
A.append(n)
n = 0
B = [0]
for s in sys.stdin.readline().split():
n = n + int(s)
B.append(n)
ans = 0
for i in range(N + 1):
if A[i] > K:
break
for j in range(M, -1, -1):
if A[i] + B[j] <= K:
ans = max(ans, i + j)
M = j
break
print(ans) | 1 | 10,695,945,238,100 | null | 117 | 117 |
W,H,x,y,r=map(int,input().split())
print("Yes"*(r<=x<=W-r)*(r<=y<=H-r)or"No")
| from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,m = [int(x) for x in stdin.readline().rstrip().split()]
check = [0 for i in range(n)]
count = [0 for i in range(n)]
for i in range(m):
p, q = [x for x in stdin.readline().rstrip().split()]
p = int(p)
if q == 'AC':
check[p-1] = 1
if q == 'WA' and check[p-1] == 0:
count[p-1] = count[p-1] + 1
for i in range(n):
if check[i] == 0: count[i] = 0
print(sum(check), sum(count))
| 0 | null | 46,776,708,733,280 | 41 | 240 |
rad = int(input())
print (2*3.1415926*rad) | #A
R = int(input())
print(2*R*3.141592) | 1 | 31,353,621,487,440 | null | 167 | 167 |
n, k = map(int, input().split())
h = list(map(int, input().split()))
ok_list = list()
for data in h:
if data >= k:
ok_list.append(data)
print(len(ok_list)) | N,K=map(int,input().split())
H=list(map(int,input().split()))
ans=0
for i in range(N):
ans+=H[i]>=K
print(ans) | 1 | 178,833,854,277,668 | null | 298 | 298 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
if A > B:
x = A
A = B
B = x
nowA = A+T*V
nowB = B+T*W
if nowA >= nowB:
ans = "YES"
else:
ans="NO"
print(ans) | import sys
#input = sys.stdin.buffer.readline
# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np
def main():
n=int(input())
s=[]
t=[]
for i in range(n):
a,b=input().split()
s.append(a)
t.append(int(b))
x=input()
for i in range(n):
if x==s[i]:
print(sum(t[i+1:]))
if __name__ == "__main__":
main()
| 0 | null | 56,039,945,514,374 | 131 | 243 |
n = int(input())
a_lst = list(map(int, input().split()))
a_lst.sort()
if a_lst[0] == 0:
answer = 0
else:
answer = 1
for i in range(n):
a = a_lst[i]
answer *= a
if answer > 10 ** 18:
answer = -1
break
print(answer) | N = int(input())
line = [int(i) for i in input().split()]
sum = 1
line.sort(reverse=True)
if line[len(line) -1]== 0:
print(0)
exit()
for num in line:
sum = sum * num
if sum > 10 ** 18:
print(-1)
exit()
print(sum) | 1 | 16,283,701,345,990 | null | 134 | 134 |
(h,n),*t=[list(map(int,o.split()))for o in open(0)]
d=[0]*10**8
for i in range(h):d[i+1]=min(b+d[i-a+1]for a,b in t)
print(d[h]) | import math
n = int(input())
xlist = list(map(float, input().split()))
ylist = list(map(float, input().split()))
#x, y = [list(map(int, input().split())) for _ in range(2)] 로 한방에 가능
print(sum(abs(xlist[i] - ylist[i]) for i in range(n)))
print(pow(sum(abs(xlist[i] - ylist[i]) ** 2 for i in range(n)),0.5))
print(pow(sum(abs(xlist[i] - ylist[i]) ** 3 for i in range(n)),1/3))
print(max(abs(xlist[i] - ylist[i])for i in range(n)))
| 0 | null | 40,477,285,002,178 | 229 | 32 |
n = int(input())
ls = []
rs = []
for _ in range(n):
x, y = map(int, input().split())
ls.append(x)
rs.append(y)
ls = sorted(ls)
rs = sorted(rs)
if n % 2 == 1:
print(rs[len(rs)//2] - ls[len(ls)//2] + 1)
else:
a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2
b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2
print((a - b) // 5 + 1) | from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from statistics import median
n=int(input())
l1=[]
l2=[]
for i in range(n):
a,b=nii()
l1.append(a)
l2.append(b)
m1=median(l1)
m2=median(l2)
ans=m2-m1
if n%2==0:
ans*=2
print(int(ans+1)) | 1 | 17,306,183,666,980 | null | 137 | 137 |
s = str(input())
apple = ["SUN","MON","TUE","WED","THU","FRI","SAT","SUN"]
print(7-apple.index(s)) | days = ["DAYS","SAT","FRI","THU","WED","TUE","MON","SUN"]
s = str(input())
for i in days:
if i == s:
print(days.index(i))
break | 1 | 133,491,110,695,240 | null | 270 | 270 |
x = list(map(int, input().split()))
for i in range(len(x)):
if x[i] == 0:
print(i+1)
break
else:
continue | nums = list(input().split())
for i, j in enumerate(nums):
if j == '0':
print(i+1) | 1 | 13,397,799,497,390 | null | 126 | 126 |
length = int(input())
first_string, second_string = input().split()
first_list = list(first_string)
second_list = list(second_string)
result_list = []
for i in range(length):
result_list.append(first_list[i])
result_list.append(second_list[i])
result = "".join(result_list)
print(result)
| n=int(input())
s,t=input().split()
for i in range(n): print(s[i]+t[i],end="") | 1 | 111,766,446,084,672 | null | 255 | 255 |
in_value = int(input())
if in_value >= 30:
print("Yes")
else:
print("No") | X=int(input(""))
if 30<=X:
print("Yes")
else:
print("No")
| 1 | 5,710,372,110,940 | null | 95 | 95 |
import numpy as np
import sys
input = sys.stdin.readline
def main():
N,M = map(int, input().split())
A = np.array(sorted([int(i) for i in input().split()]))
left = 0
right = A[-1] * 2 + 5
while right - left > 1:
x = (left + right) // 2
count = N**2 - np.searchsorted(A, x-A).sum()
if count >= M:
left = x
else:
right = x
bound = np.searchsorted(A, left-A)
count = N**2 - bound.sum()
diff = count - M
ans = ((N - bound) * A * 2).sum() - diff * left
print(ans)
if __name__ == "__main__":
main()
| from math import atan2, degrees
a,b,x = map(int, input().split())
s = x/a
if x >= a**2*b/2:
print(degrees(atan2(2*(a*b-s)/a, a)))
else:
print(degrees(atan2(b, 2*s/b))) | 0 | null | 135,605,018,905,060 | 252 | 289 |
n, m = list(map(int, input().split()))
A = []
V = []
B = []
for i in range(n):
A.append(list(map(int, input().split())))
for j in range(m):
V.append([int(input())])
for i in range(n):
B.append([0])
for j in range(m):
B[i][0] += A[i][j] * V[j][0]
for i in range(n):
print(B[i][0]) | a,b=input().split()
c=int(a);d=int(b)
if c>=-1000 and d<=1000:
if c>d:
print("a > b")
elif c<d:
print("a < b")
else:
print("a == b") | 0 | null | 749,623,053,042 | 56 | 38 |
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
sa = abs(a-b)
tume = v-w
if tume*t < sa:
print('NO')
else:
print('YES') | import sys
S = input()
N = int(input())
for i in range(N):
a = sys.stdin.readline().split()
if a[0] == "replace":
S = S[:int(a[1])] + a[3] + S[int(a[2])+1:]
elif a[0] == "reverse":
X = S[int(a[1]):int(a[2])+1]
X = X[::-1]
S = S[:int(a[1])] + X +S[int(a[2])+1:]
elif a[0] == "print":
print(S[int(a[1]):int(a[2])+1])
| 0 | null | 8,570,521,711,052 | 131 | 68 |
from math import log2,ceil
def main():
A,B,C=map(int,input().split())
K=int(input())
if A<B<C:
print("Yes")
else:
op=0
if B<=A:
val=ceil(log2(A/B))
op+=val
B<<=val
if B==A:
B*=2
op+=1
if C<=B:
val=ceil(log2(B/C))
op+=val
C<<=val
if C==B:
C*=2
op+=1
if op<=K:
print("Yes")
else:
print("No")
if __name__=='__main__':
main() | # B>G>R
R,G,B = map(int,input().split())
K = int(input())
cnt = 0
while not G>R:
G *= 2
cnt += 1
while not B>G:
B *= 2
cnt += 1
if cnt<=K:
print("Yes")
else:
print("No") | 1 | 6,944,911,643,702 | null | 101 | 101 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n,x,y=map(int,input().split())
x-=1; y-=1
E1=[[] for _ in range(n)]
E2=[[] for _ in range(n)]
for _ in range(n-1):
u,v=map(int,input().split())
u-=1; v-=1
E1[u].append(v)
E1[v].append(u)
E2=E1
# E2 において、y-rooted tree とみて、depth,par を計算
par=[None]*n # x の必勝頂点を判定するのに必要
par[y]=y
depth2=[None]*n
depth2[y]=0
Q=[y]
while(Q):
v=Q.pop()
for nv in E2[v]:
if(depth2[nv] is not None): continue
depth2[nv]=depth2[v]+1
par[nv]=v
Q.append(nv)
# E1の辺で、E2での距離が 3 以上のものは必勝
win=[0]*n
for v in range(n):
for nv in E1[v]:
if(par[v]==nv or par[nv]==v or par[v]==par[nv] or par[par[v]]==nv or par[par[nv]]==v): continue
win[nv]=win[v]=1
# E1 において、x-rooted tree とみて探索
# depth1 < depth2 -> 以降も探索できる
# depth1 = depth2 -> そこで捕まる
ans=depth2[x]
depth1=[None]*n
depth1[x]=0
Q=[x]
while(Q):
v=Q.pop()
if(win[v]): # 探索できる状態 & 必勝頂点にいれば勝ち
print(-1)
return
for nv in E1[v]:
if(depth1[nv] is not None): continue
depth1[nv]=depth1[v]+1
ans=max(ans,depth2[nv])
if(depth1[nv]<depth2[nv]): Q.append(nv)
print(ans-1)
resolve() | N,u,v=map(int, input().split())
import sys
sys.setrecursionlimit(10**6)
T=[[] for _ in range(N)]
for i in range(N-1):
a,b=map(int, input().split())
T[a-1].append(b-1)
T[b-1].append(a-1)
def dfs(start):
tolist=T[start]
nowd=done[start]
for next_n in tolist:
if done[next_n]==-1:
done[next_n]=nowd+1
dfs(next_n)
done=[-1]*N
done[u-1]=0
dfs(u-1)
dtaka=done.copy()
done=[-1]*N
done[v-1]=0
dfs(v-1)
dao=done.copy()
ans=0
for i in range(N):
t=dtaka[i]
a=dao[i]
if a>t:
ans=max(ans, a)
print(ans-1)
| 1 | 117,773,323,222,180 | null | 259 | 259 |
# coding: utf-8
# Your code here!
x = input()
lst = list(x)
pt = []
rst = []
k = 0
# point get
cnt = 0
tmp = ""
for s in lst:
if s == "/":
if tmp == "_" or tmp == "/":
cnt += 1
elif s == "\\":
if tmp == "\\":
cnt -= 1
else:
if tmp == "\\":
cnt -= 1
pt += [cnt]
tmp = s
#メンセキ
i,xs,m2 = 0,0,0
for s in lst:
if s == "/":
if i == xs and xs > 0:
rst += [m2]
k += 1
xs,m2 = 0,0
elif s == "_":
pass
else:
try:
x = pt[i+1:].index(pt[i])+i+1
m2 += x-i
if xs < x:
xs = x
except:
pass
i += 1
print(sum(rst))
print(k,*rst)
| #153
def main():
N, K = map(int,input().split())
H = list(map(int,input().split()))
H.sort()
H.reverse()
H = H[K:]
cost = 0
for i in H:
cost+=i
print(cost)
main() | 0 | null | 39,572,430,603,638 | 21 | 227 |
a,b=map(int,input().split())
print(a*b if a<10 and b<10 else '-1') | import sys
from collections import deque
input = sys.stdin.readline
n, m, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]
ff = [[] for _ in range(n+1)]
for a, b in ab:
ff[a].append(b)
ff[b].append(a)
visited = [False] * (n+1)
visited[0] = True
com = [-1] * (n+1)
def dfs(v, ff, visited, com, g):
q = deque([v])
visited[v] = True
com[v] = g
k = 1
while len(q) > 0:
w = q.pop()
for x in ff[w]:
if not visited[x]:
q.append(x)
visited[x] = True
com[x] = g
k += 1
return k
g = 0
group_num = []
for i in range(1, n+1):
if visited[i]:
pass
else:
k = dfs(i, ff, visited, com, g)
group_num.append(k)
g += 1
#print(com)
friends = [0] * (n+1)
for i in range(1, n+1):
friends[i] += group_num[com[i]] - 1
for a, b in ab:
if com[a] == com[b]:
friends[a] -= 1
friends[b] -= 1
for c, d in cd:
if com[c] == com[d]:
friends[c] -= 1
friends[d] -= 1
print(" ".join(map(str, friends[1:]))) | 0 | null | 110,163,570,616,580 | 286 | 209 |
n = input()
n = n[::-1]
n += '0'
cnt = 0
dp = [[float('inf')] * 2 for _ in range(len(n) + 1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(len(n)):
a = int(n[i])
dp[i + 1][0] = min(dp[i][0] + a, dp[i][1] + a + 1)
dp[i + 1][1] = min(dp[i][0] + 10 - a, dp[i][1] + 10 - (a + 1))
print(min(dp[len(n)][0], dp[len(n)][1])) | import sys
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
N = ns()
ans = [0, 1000000000]
kuri = [0, 0]
five = 0
for n in N[::-1]:
n = int(n)
# print(ans)
ans_old = [ans[0], ans[1]]
ans[0] = min(ans_old[0] + n, ans_old[1] + n + 1)
ans[1] = min(ans_old[0] + 10 - n, ans_old[1] + 9 - n)
print(min(ans[0], ans[1] + 1))
| 1 | 71,115,533,632,364 | null | 219 | 219 |
# 3
A,B,C=map(int,input().split())
K=int(input())
def f(a,b,c,k):
if k==0:
return a<b<c
return f(a*2,b,c,k-1) or f(a,b*2,c,k-1) or f(a,b,c*2,k-1)
print('Yes' if f(A,B,C,K) else 'No')
| from sys import stdin
A, B, C = [int(_) for _ in stdin.readline().rstrip().split()]
K = int(stdin.readline().rstrip())
for i in range(K):
if not B > A:
B *= 2
elif not C > B:
C *= 2
if A < B < C:
print("Yes")
else:
print("No") | 1 | 6,844,956,997,120 | null | 101 | 101 |
charge, n_coin = map(int,input().split())
coin_ls = list(map(int, input().split()))
coin_ls = [0] + coin_ls
dp = [[float('inf')] * (charge+1) for _ in range(n_coin+1)]
dp[0][0] = 0
for coin_i in range(1,n_coin+1):
for now_charge in range(0,charge+1):
if now_charge - coin_ls[coin_i] >= 0:
dp[coin_i][now_charge] = min(dp[coin_i][now_charge], dp[coin_i][now_charge-coin_ls[coin_i]]+1)
dp[coin_i][now_charge] = min(dp[coin_i-1][now_charge], dp[coin_i][now_charge])
print(dp[n_coin][charge])
| print((lambda x:int(x[1])+max(0,100*(10-int(x[0]))))(input().split())) | 0 | null | 31,565,270,225,818 | 28 | 211 |
import bisect
def is_ok(a, target, m):
num = 0
for val in a:
index = bisect.bisect_left(a, target - val)
num += len(a) - index
if num <= m:
return True
else:
return False
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ok, ng = 10 ** 10, -1
while ok - ng > 1:
mid = (ok + ng) // 2
if is_ok(a, mid, m):
ok = mid
else:
ng = mid
rui = [0] * (n + 1)
for i in range(n):
rui[i+1] = rui[i] + a[i]
cnt = 0
ret = 0
for val in a:
index = bisect.bisect_left(a, ok - val)
num = len(a) - index
cnt += num
ret += (num * val) + (rui[-1] - rui[index])
ret += (m - cnt) * ng
print(ret)
| M = 10**9 + 7
n = int(input())
a = [int(i) for i in input().split()] #; print(a)
counter = [0] * (n+1) ; counter[0] = 3
ans = 1
for i in range(n):
ans *= counter[a[i] - 1 +1] - counter[a[i] +1]
ans = ans % M
counter[a[i] +1] += 1
print(ans) | 0 | null | 119,105,141,859,260 | 252 | 268 |
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
num = set(A)
count = Counter(A)
dp = [True] * (10**6 + 1)
for a in num:
for n in range(a+a, 10**6+1, a):
dp[n] = False
ans = 0
for a in num:
if count[a] == 1 and dp[a] == True:
ans += 1
print(ans) | n = int(input())
A = list(map(int, input().split()))
MAX_N = max(A)+ 1
cnt = [0] * MAX_N
for a in A:
for i in range(a, MAX_N, a):
if cnt[i] <= 2:
cnt[i] += 1
ans = 0
for a in A:
if cnt[a] == 1:
ans += 1
print(ans)
| 1 | 14,364,746,074,492 | null | 129 | 129 |
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }
dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in range( len( roll ) ):
if "E" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
dice[ diceface["RIGHT"] ] = t
elif "N" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
dice[ diceface["BACK"] ] = t
elif "S" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
dice[ diceface["FRONT"] ] = t
elif "W" == roll[i]:
t = dice[ diceface["TOP"] ]
dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
dice[ diceface["LEFT"] ] = t
print( dice[ diceface["TOP"] ] ) | import sys
input()
card = sys.stdin.readlines()
bool_ = [[False for y in range(13)] for x in range(4)]
for i in card:
m, n = i.split()
m = m.replace('S', '0').replace('H', '1').replace('C', '2').replace('D', '3')
m, n = int(m), int(n)
bool_[m][n - 1] = True
for i in range(4):
for j in range(13):
if not bool_[i][j]:
if i == 0:
print('S', j + 1)
elif i == 1:
print('H', j + 1)
elif i == 2:
print('C', j + 1)
else:
print('D', j + 1) | 0 | null | 646,163,172,018 | 33 | 54 |
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
def get_point(x):
if x == 'r':
return P
if x == 's':
return R
if x == 'p':
return S
# think each mod K
ans = 0
for i in range(K):
dp = [0] * 2
pre = ''
for j in range(i, N, K):
dp2 = dp[:]
dp2[0] = max(dp)
if pre == T[j]:
dp2[1] = dp[0] + get_point(T[j])
else:
dp2[1] = max(dp) + get_point(T[j])
pre = T[j]
dp = dp2
ans += max(dp)
print(ans) | from collections import deque
N,K = map(int,input().split())
R,S,P = map(int,input().split())
Tlist = input()
Answer = 0
def po(x):
if x == 's':
return R
elif x == 'r':
return P
else:
return S
for i in range(K):
TK = list(Tlist[i::K]).copy()
TK.append('')
T2 = TK[0]
sig = 2
for i in range(1,len(TK)):
T1 = T2
T2 = TK[i]
if T1 == T2 and i != len(TK)-1:
sig += 1
else:
Answer += po(T1)*(sig//2)
sig = 2
print(Answer) | 1 | 106,808,544,647,492 | null | 251 | 251 |
n,k=map(int,input().split());print(len([i for i in list(map(int,input().split())) if i>=k])) | # 高橋君の仲間たちは N 人で遊園地に遊びにいきました。 遊園地の一番人気のジェットコースターに乗るためには、身長が K cm以上必要です。
# 高橋君の i 番目の仲間の身長は h i cm です。 高橋君の仲間たちのうち、一番人気のジェットコースターに乗ることができる人の数を求めてください。
N,K = map(int,input().split())
h = list(map(int,input().split()))
x = 0
for i in h:
if i >= K:
x += 1
print(x) | 1 | 179,349,766,145,520 | null | 298 | 298 |
import sys
import math
#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():
def __init__(self):
self.number = [i for i in range(6)]
self.work = [i for i in range(6)]
self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
def setNumber(self,n0,n1,n2,n3,n4,n5):
self.number[0] = n0
self.number[1] = n1
self.number[2] = n2
self.number[3] = n3
self.number[4] = n4
self.number[5] = n5
def roll(self,loc):
for i in range(6):
self.work[i] = self.number[i]
if loc == 'E':
self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
elif loc == 'N':
self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
elif loc == 'S':
self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
elif loc == 'W':
self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
def query(self,top_num,front_num):
self.save_data = [i for i in range(6)]
#元の値の保存
for i in range(len(self.number)):
self.save_data[i] = self.number[i]
ret = -1
for i in range(len(self.order)):
self.roll(self.order[i])
if self.number[0] == top_num and self.number[1] == front_num:
ret = self.number[2]
break
#元の値の復元
for i in range(len(self.number)):
self.number[i] = self.save_data[i]
return ret
dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
num_query = int(input())
for loop in range(num_query):
top_num,front_num = map(int,input().split())
print("%d"%(dice.query(top_num, front_num)))
| import fractions
a, b = map(int, input().split())
def lcm(a,b):
return (a*b)//fractions.gcd(a,b)
print(lcm(a,b)) | 0 | null | 56,979,258,234,880 | 34 | 256 |
# 累積和を用いたdpの高速か
n, k = map(int, input().split())
mod = 998244353
lr_list = [list(map(int, input().split())) for _ in range(k)]
dp = [0] * (n + 1)
dp[1] = 1
sdp = [0] * (n + 1)
sdp[1] = 1
for i in range(2, n + 1):
for j in range(k):
right = max(0, i - lr_list[j][0])
left = max(0, i - lr_list[j][1] - 1)
dp[i] = (dp[i] + sdp[right] - sdp[left]) % mod
sdp[i] = sdp[i - 1] + dp[i]
print(dp[n]) | n = int(input())
word = 'ACL'
print(word * n) | 0 | null | 2,479,566,866,832 | 74 | 69 |
n, q = list(map(int, input().split()))
que = []
for _ in range(n):
name, time = input().split()
que.append([name, int(time)])
elapsed_time = 0
while que:
name, time = que.pop(0)
dt = min(q, time)
time -= dt
elapsed_time += dt
if time > 0:
que.append([name, time])
else:
print (name, elapsed_time) | sentence = input()
for i in sentence:
if i.isupper() == True:
print(i.lower(), end = "")
elif i.islower() == True:
print(i.upper(), end = "")
else:
print(i, end = "")
print()
| 0 | null | 763,175,739,900 | 19 | 61 |
n=int(input())
s=input()
res=s[0]
ans=1
for i in range(1,n):
if s[i]==res:
continue
else:
res=s[i]
ans+=1
print(ans) | n = int(input())
s = str(input())
count = 1
for i in range(1, n):
if s[i] != s[i - 1]:
count += 1
print(count)
| 1 | 170,455,306,634,120 | null | 293 | 293 |
N = int(input())
S = list(map(int, input().split(" ")))
Exchange_Number_of_times = 0
for i in range(N):
minj = i
for j in range(i, N):
if S[j] < S[minj]:
minj = j
if i != minj:
S[i], S[minj] = S[minj], S[i]
Exchange_Number_of_times += 1
print(' '.join(map(str,S)))
print(Exchange_Number_of_times)
| N = int(input())
A = list(map(int,input().split()))
def selectSort(A, N):
sw = 0
for i in range(N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if A[i] != A[minj]:
A[i], A[minj] = A[minj], A[i]
sw += 1
return str(sw)
sw = selectSort(A, N)
print(" ".join(map(str, A)))
print(sw) | 1 | 21,420,640,736 | null | 15 | 15 |
from decimal import Decimal
import math
AB = input().split()
A, B = int(AB[0]), Decimal(AB[1])
print(math.floor(A*B))
| s = input()
q = int(input())
head = []
tail = []
flip = 0
for i in range(q):
query = input().split()
if query[0] == "1":
flip ^=1
else:
f = int(query[1]) - 1
c = query[2]
if (f ^ flip) == 0:
head.append(c)
else:
tail.append(c)
if flip:
head, tail = tail, head
s = s[::-1]
head = "".join(head)
tail = "".join(tail)
print(head[::-1] + s + tail) | 0 | null | 36,638,641,898,148 | 135 | 204 |
#coding:utf-8
#1_1_D
n = int(input())
prices = [int(input()) for x in range(n)]
maxv = -2 * 10 ** 9
minv = prices[0]
for i in range(1, n):
maxv = max(maxv, prices[i] - minv)
minv = min(minv, prices[i])
print(maxv) | N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
a = max(A)
prime_num = [2]
sgn = [0 for _ in range(max(int(a**0.5)+1, 4))]
sgn[2] = 1
for k in range(3, len(sgn), 2):
if sgn[k] == 0:
prime_num.append(k)
for j in range(k, a+1, k**2):
sgn[k] = 1
baisu = []
count = [0 for _ in range(a+1)]
for k in range(N):
b = 0 + A[k]
for p in prime_num:
if p**2 <= b:
if b%p == 0:
if count[p] == 0:
baisu.append(p)
c = 0
while b % p == 0:
b //= p
c += 1
if c > count[p]:
count[p] = c
else:
break
if b != 1:
if count[b] == 0:
count[b] = 1
baisu.append(b)
product = 1
for item in baisu:
product *= pow(item, count[item], mod)
product %= mod
b = mod-2
blis = []
c = 0
while b >0:
if b & 1 == 1:
blis.append(c)
c += 1
b >>= 1
def modinv(a):
if a == 1:
return 1
else:
res = 1
li = []
for _ in range(c):
li.append(a%mod)
a = a*a%mod
for item in blis:
res = res *li[item] %mod
return res
ans = 0
for k in range(N):
ans += product*modinv(A[k])
ans %= mod
print(ans)
| 0 | null | 44,039,096,603,950 | 13 | 235 |
n = int(input())
s = input()
q = int(input())
class SegmentTree:
def __init__(self, a, func=max, one=-10 ** 18):
self.logn = (len(a) - 1).bit_length()
self.n = 1 << self.logn
self.func = func
self.one = one
self.b = [self.one] * (2 * self.n - 1)
for i, j in enumerate(a):
self.b[i + self.n - 1] = j
for i in reversed(range(self.n - 1)):
self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])
self.ll = []
self.rr = []
i = self.n
for _ in range(self.logn+1):
for j in range(0, self.n, i):
self.ll.append(j)
self.rr.append(j + i)
i //= 2
def get_item(self, i):
return self.b[i + self.n - 1]
def update(self, index, x):
i = index + self.n - 1
self.b[i] = x
while i != 0:
i = (i - 1) // 2
self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])
def update_func(self, index, x):
i = index + self.n - 1
self.b[i] = self.func(self.b[i], x)
while i != 0:
i = (i - 1) // 2
self.b[i] = self.func(self.b[i * 2 + 1], self.b[i * 2 + 2])
def get_segment(self, l, r, i=0):
ll = self.ll[i]
rr = self.rr[i]
if l <= ll and rr <= r:
return self.b[i]
elif rr <= l or r <= ll:
return self.one
else:
return self.func(self.get_segment(l, r, i * 2 + 1),
self.get_segment(l, r, i * 2 + 2))
def get_int(s):
abc = "abcdefghijklmnopqrstuvwxyz"
return 1 << abc.index(s)
seg = SegmentTree([get_int(i) for i in s], int.__or__, 0)
for _ in range(q):
q, i, j = input().split()
if q == "1":
seg.update(int(i) - 1, get_int(j))
else:
aa = seg.get_segment(int(i) - 1, int(j))
ans = 0
for i in range(26):
if (aa >> i) & 1 == 1:
ans += 1
print(ans)
| import sys
input = lambda: sys.stdin.readline().rstrip()
class SegTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.ide_ele = ide_ele
self.segfunc = segfunc
self.num = 2**(n - 1).bit_length()
self.seg = [self.ide_ele] * 2 * self.num
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, p, q):
if q <= p:
return self.ide_ele
p += self.num - 1
q += self.num - 2
res = self.ide_ele
while q - p > 1:
if p & 1 == 0:
res = self.segfunc(res, self.seg[p])
if q & 1 == 1:
res = self.segfunc(res, self.seg[q])
q -= 1
p = p // 2
q = (q - 1) // 2
if p == q:
res = self.segfunc(res, self.seg[p])
else:
res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
return res
def solve():
N = int(input())
S = list(input())
Q = int(input())
seg = [[0 for _ in range(N)] for _ in range(26)]
for i in range(N):
al = ord(S[i]) - ord('a')
seg[al][i] = 1
segtree = []
segfunc = lambda a, b: a | b
for i in range(26):
segtree.append(SegTree(seg[i], segfunc, 0))
ans = []
for i in range(Q):
a, b, c = input().split()
a = int(a)
if a == 1:
b = int(b) - 1
ps = S[b]
S[b] = c
segtree[ord(ps) - ord('a')].update(b, 0)
segtree[ord(c) - ord('a')].update(b, 1)
elif a == 2:
b, c = int(b) - 1, int(c)
count = 0
for i in range(26):
count += segtree[i].query(b, c)
ans.append(count)
print('\n'.join(map(str, ans)))
if __name__ == '__main__':
solve()
| 1 | 62,170,050,624,940 | null | 210 | 210 |
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N=II()
A=LI()
#A.sort()
SA=sum(A)
#print(SA)
AccA=[A[0]]
for i in range(1,N):
AccA.append(AccA[-1]+A[i])
#AccA.reverse()
ans=0
for i in range(N-1):
ans+=A[i]*(SA-AccA[i])
ans=ans%(10**9+7)
print(ans) | N = int(input()) #入力する整数
A = list(map(int,input().split())) #入力する数列A
SUMA = sum(A) #数列の和
MOD = 10**9 + 7 # mod
C = [0] * (N-1) #累積和数列
for i in range(N-1): #\sum_{j = i+1}^{N}を求めて数列に代入する
SUMA -= A[i]
C[i] = SUMA
ans = 0 #求める答え
for i in range(N-1):
ans += A[i]*C[i]
ans %= MOD #その都度modで割った余りにする
print(ans) #答えを出力する | 1 | 3,823,491,272,580 | null | 83 | 83 |
print(-1*(-1*int(input()) // 2)) | a=int(input())
print(sum(divmod(a,2)))
| 1 | 58,789,835,655,772 | null | 206 | 206 |
#!/usr/bin/env python3
def main():
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
c = ""
ans = 0
for i in range(n):
if t[i] == "r":
if i >= k and c[i-k] == 'p':
c += 'x'
else:
c += "p"
ans += p
elif t[i] == "s":
if i >= k and c[i-k] == 'r':
c += 'x'
else:
c += "r"
ans += r
else:
if i >= k and c[i-k] == 's':
c += 'x'
else:
c += "s"
ans += s
print(ans)
if __name__ == "__main__":
main()
| n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
def add(x):
if x == 'r':
return p
elif x == 's':
return r
else:
return s
nk =[0]*k
for i in range(n):
key = i%k
if nk[key]==0:
nk[key] = [t[i]]
else:
nk[key].append(t[i])
ans = 0
for j in nk:
if j ==0:
continue
ans += add(j[0])
for k in range(1, len(j)):
if j[k]== j[k-1]:
j[k]='q'
else:
ans += add(j[k])
print(ans) | 1 | 106,791,025,740,480 | null | 251 | 251 |
H = int(input())
def attack(h):
if h == 1:
return 0
r = 2
h //= 2
ans = 2
while h > 1:
h //= 2
r *= 2
ans += r
return ans
print(1 + attack(H))
| import sys
def solve(h):
if h == 1:
return 1
else:
return 1 + 2 * solve(h // 2)
def main():
input = sys.stdin.buffer.readline
h = int(input())
print(solve(h))
if __name__ == "__main__":
main()
| 1 | 79,659,994,563,110 | null | 228 | 228 |
N=int(input())
ans=[]
while(1):
if N==0:
break
tmp=N%26
if tmp==0:
ans.append(26)
N=N//26-1
else:
N//=26
ans.append(tmp)
new_ans = list(reversed(ans))
ANS=""
for i in new_ans:
ANS+=chr(96+int(i))
print(ANS) | # coding: utf-8
from queue import Queue
N = int(input())
graph = [None]
for _ in range(N):
graph.append(list(map(int, input().split(" ")))[1:])
class BFSSolver:
def __init__(self, graph):
self.graph = graph
self.queue = Queue()
self.queue.put(1)
self.before_id = 1
self.already_searched = [1]
self.res = [0]
for _ in range(N):
self.res.append(-1)
self.res[1] = 0
self.turn = 0
def next_turn(self):
now_id = self.queue.get()
before_id = now_id
neighbors = self.graph[now_id][1:]
for i in neighbors:
if i not in self.already_searched:
self.turn = self.res[before_id] + 1
self.already_searched.append(i)
self.res[i] = self.turn
self.queue.put(i)
def solve(self):
while not self.queue.empty():
self.next_turn()
for id, i in enumerate(self.res[1:]):
print("{} {}".format(id+1, i))
s = BFSSolver(graph)
s.solve()
| 0 | null | 6,010,092,561,888 | 121 | 9 |
def calc_circle(r):
pi = 3.14159265359
area = round(r*r*pi, 6)
circ = round(2*r*pi, 6)
return (area, circ)
if __name__ == "__main__":
r = float(input())
area, circ = calc_circle(r)
print(f"{area:.6f} {circ:.6f}")
| import math
x = float(input())
print("%.6f %.6f"%(x*x*math.pi, x*2*math.pi))
| 1 | 651,924,262,272 | null | 46 | 46 |
p0 = 10**9+7
def pow(x,m):
if m==0:
return 1
if m==1:
return x
if m%2==0:
return (pow(x,m//2)**2)%p0
else:
return (x*(pow(x,(m-1)//2)**2)%p0)%p0
N = int(input())
A = list(map(int,input().split()))
A = [bin(A[i])[2:] for i in range(N)]
A = ["0"*(60-len(A[i]))+A[i] for i in range(N)]
C = {k:0 for k in range(60)}
for i in range(N):
for m in range(60):
if A[i][m]=="1":
C[59-m] += 1
B = [0 for _ in range(60)]
for k in range(60):
p = C[k]
m = N-C[k]
B[k] = p*m
cnt = 0
for k in range(60):
cnt = (cnt+B[k]*pow(2,k))%p0
print(cnt) | # -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d
"""
import sys
def solve(N, A):
MOD = 10**9 + 7
bit_len = max(map(int.bit_length, A))
ans = 0
for i in range(bit_len):
zeros, ones = 0, 0
for a in A:
if (a & 1<<i):
ones += 1
else:
zeros += 1
ans = (ans + (ones * zeros * 2**i)) % MOD
return ans % MOD
def main(args):
N = int(input())
A = list(map(int, input().split()))
ans = solve(N, A)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 1 | 123,072,615,099,840 | null | 263 | 263 |
n = int(input())
A = sorted(list(map(int, input().split())))[::-1]
if 0 in A:
print(0)
exit()
ans = 1
for a in A:
ans *= a
if ans > 10 **18:
print(-1)
exit()
print(ans) | s = int(input())
mod = 10**9 + 7
f = [0]*2001
g = [0]*2001
f[3]=1
f[4]=1
g[3]=1
g[4]=2
for i in range(4,s+1):
f[i]=1 + g[i-3]
f[i]%=mod
g[i]=f[i] + g[i-1]
g[i]%=mod
print(f[s]) | 0 | null | 9,752,185,790,582 | 134 | 79 |
import random
s = input()
len_s = len(s)
if len_s==3:
num = 0
else:
num = random.randint(0,len_s-4)
name = s[num]+s[num+1]+s[num+2]
print(name) | N = int(input())
S = 'X' + input()
cnt_R, cnt_G, cnt_B = 0, 0, 0
for s in S[1:]:
if s == 'R':
cnt_R += 1
elif s == 'G':
cnt_G += 1
elif s == 'B':
cnt_B += 1
ans = cnt_R * cnt_G * cnt_B
for i in range(1,N-1):
for j in range(i+1,N):
k = 2*j - i
if k > N:
break
a = S[i]; b = S[j]; c = S[k]
if a != b and b != c and c != a:
ans -= 1
print(ans) | 0 | null | 25,374,246,376,612 | 130 | 175 |
NUM = list(map(int,input().split()))
if(NUM[0] > NUM[1]):
print("safe")
elif(NUM[0] <= NUM[1]):
print("unsafe")
| A,B=map(int,input().split())
print("safe" if A>B else "unsafe") | 1 | 29,087,530,000,878 | null | 163 | 163 |
data = input().split()
W=int(data[0])
H=int(data[1])
x=int(data[2])
y=int(data[3])
r=int(data[4])
if (0 <= x - r <= W) and (0 <= x + r <= W):
if (0 <= y - r <= H) and (0 <= y + r <= H):
print("Yes")
else:
print("No")
else:
print("No") | W,H,x,y,r = map(int,input().split())
if x >= r and x <= W-r and y >= r and y <= H-r:
print('Yes')
else:
print('No')
| 1 | 457,127,846,916 | null | 41 | 41 |
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int, input().split()))
a.sort()
m=max(a)
arr=[0]*(m+1)
flag=[True]*(m+1)
ans=0
for i in range(n):
if flag[a[i]]:
arr[a[i]]+=1
if not arr[a[i]]==1:
continue
for j in range(a[i]*2,m+1,a[i]):
flag[j]=False
print(arr.count(1)) | import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
A.sort()
d = {}
for a in A:
d.setdefault(a,0)
d[a] += 1
sieve = [True] * (A[-1] + 1)
for a in A:
if d[a] > 1:
sieve[a] = False
for i in range(a + a, A[-1] + 1, a):
sieve[i] = False
print(sum(1 for a in A if sieve[a])) | 1 | 14,459,944,686,012 | null | 129 | 129 |
# coding: utf-8
import itertools
from functools import reduce
from collections import deque
N, K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" ")))
for i in range(N):
if i > K-1:
if A[i] > A[i-K]:
print("Yes")
else:
print("No")
| n, k = [int(x) for x in input().strip().split()]
arr = [int(x) for x in input().strip().split()]
last = 0
for i in range(k):
last += arr[i]
for i in range(k, len(arr)):
curr = (last + arr[i]) - arr[i-k]
if curr>last:
print('Yes')
else:
print('No')
last= curr
| 1 | 7,063,240,230,200 | null | 102 | 102 |
m1,d1 = map(int,input().split())
m2,d2 = map(int,input().split())
if m1 in [1,3,5,7,8,10,12] and d1==31:
print(1)
elif m1 in [4,6,9,11] and d1==30:
print(1)
elif m1==2 and d1 in [28,29]:
print(1)
else:
print(0) | from math import floor
s = input()
k = int(input())
if len(set(s)) == 1:
print(floor(len(s) * k / 2))
exit(0)
x = s[0]
y = 1
ans = 0
for i in s[1:]:
if i == x:
y += 1
else:
ans += floor(y / 2)
x = i
y = 1
ans += floor(y / 2)
if s[0] != s[-1]:
print(ans * k)
else:
x = s[0]
y = 1
for i in s[1:]:
if x == i:
y += 1
else:
a = y
break
y = 0
for i in s[::-1]:
if x == i:
y += 1
else:
b = y
break
print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1))) | 0 | null | 149,882,949,581,430 | 264 | 296 |
s, t = map(str, input().split())
w = "{}{}".format(t,s)
print(w) | a,b=(input().split())
print(b+a) | 1 | 103,573,347,666,500 | null | 248 | 248 |
# coding=utf-8
def solve_gcd(number1: int, number2: int) -> int:
two_list = [number1, number2]
two_list.sort()
if two_list[1] % two_list[0] == 0:
return two_list[0]
r = two_list[1] % two_list[0]
return solve_gcd(two_list[0], r)
def solve_lcm(number1: int, number2: int, number3: int) -> int:
return number1*number2//number3
if __name__ == '__main__':
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
gcd = solve_gcd(a, b)
lcm = solve_lcm(a, b, gcd)
print(gcd, lcm) | n,m,l=map(int,input().split())
A = [tuple(map(int,input().split())) for _ in range(n)]
B = [tuple(map(int,input().split())) for _ in range(m)]
BT = tuple(map(tuple,zip(*B)))
for a in A:
temp=[]
for b in BT:
temp.append(sum([x*y for (x,y) in zip(a,b)]))
print(*temp) | 0 | null | 725,931,807,932 | 5 | 60 |
N=int(input());A=sorted((int(x),i)for i,x in enumerate(input().split()));t=[0]*N**2
for w in range(N):
a,j=A[w]
for l in range(N-w):
r=l+w;p=a*abs(j-l);t[l*N+r]=max(p+t[(l+1)*N+r],a*abs(j-r)+t[l*N+r-1])if w else p
print(t[N-1]) | n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1-i) for i in range(n+1)]
for i in range(n):
x,idx = b[i]
for j in range(i+1):
k = i-j
if dp[j+1][k] < dp[j][k] + x*(idx-j):
dp[j+1][k] = dp[j][k] + x*(idx-j)
if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
if ans < dp[i][n-i]:
ans = dp[i][n-i]
print(ans)
| 1 | 33,913,539,633,278 | null | 171 | 171 |
n = int(input())
minv = int(input())
maxv = -1000000000
for r in [int(input()) for i in range(1,n)]:
maxv = max(maxv,r-minv)
minv = min(r,minv)
print(maxv) | def merge(a, left, mid, right):
INF = int(1e+11)
l = a[left:mid]
r = a[mid:right]
l.append(INF)
r.append(INF)
i = 0
j = 0
ans = 0
for k in range(left, right):
ans += 1
if l[i] <= r[j]:
a[k] = l[i]
i += 1
else:
a[k] = r[j]
j += 1
return ans
def merge_sort(a, left, right):
ans = 0
if left + 1 < right:
mid = (left + right) // 2
ans += merge_sort(a, left, mid)
ans += merge_sort(a, mid, right)
ans += merge(a, left, mid, right)
return ans
def print_list_split_whitespace(s):
for x in s[:-1]:
print(x, end=" ")
print(s[-1])
n = int(input())
s = [int(x) for x in input().split()]
ans = merge_sort(s, 0, len(s))
print_list_split_whitespace(s)
print(ans)
| 0 | null | 63,175,046,230 | 13 | 26 |
n,k = map(int,input().split())
h = list(map(int,input().split()))
print(sum(h[i] >= k for i in range(n)))
| M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
if M1 in [1, 3, 5, 7, 8, 10, 12]:
if D1 == 31:
print("1")
else:
print("0")
elif M1 == 2:
if D1 == 28:
print("1")
else:
print("0")
else:
if D1 == 30:
print("1")
else:
print("0") | 0 | null | 151,941,210,388,768 | 298 | 264 |
import bisect
N=int(input())
S=list(input())
Q=int(input())
alphabet="abcdefghijklmnopqrstuvwxyz"
bag={l:[] for l in alphabet}
for i in range(N):
bag[S[i]].append(i+1)
#print(bag)
for i in range(Q):
Type,a,b=input().split()
if Type=='1':
a=int(a)
if S[a-1]!=b:
bag[S[a-1]].remove(a)
S[a-1]=b
bisect.insort(bag[b],a)
else:
cnt=0
a,b=int(a),int(b)
for l in alphabet:
bl=len(bag[l])
if bl>0:
left=bisect.bisect_left(bag[l],a)
if left!=bl and bag[l][left]<=b:
cnt+=1
print(cnt) | # encoding:utf-8
while True:
a,op,b = map(str, input().split())
c = int(a)
d = int(b)
if op == '+': result = c + d
if op == '-': result = c - d
if op == '*': result = c * d
if op == '/': result = int(c / d)
if op == '?': break
print("{0}".format(result)) | 0 | null | 31,480,783,320,756 | 210 | 47 |
N = int(input())
str_dict= {}
for i in range(N):
a = input().split()
if a[0] == "insert":
str_dict[a[1]] = i
else:
if a[1] in str_dict.keys():
print("yes")
else:
print("no")
| a=[]
for i in range(10):a.append(int(input()))
a.sort()
print(a[9],a[8],a[7],sep='\n'); | 0 | null | 37,746,212,478 | 23 | 2 |
N=int(input())
*A,=map(int,input().split())
Q=int(input())
*M,=map(int,input().split())
mf=['no']*Q
t=[]
for i in range(0,2**N):
ans=0
for j in range(N):
if (i>>j&1):
ans+=A[j]
t.append(ans)
tset=set(t)
for i in range(Q):
if M[i] in tset:
mf[i] = 'yes'
for i in mf:
print(i)
| def gcd(a, b):
while True:
a, b = b, a%b
if b == 0:
return a
def lcm(a, b):
return int((a*b) // gcd(a, b))
a, b = map(int, input().split())
print(lcm(a, b)) | 0 | null | 56,536,774,720,580 | 25 | 256 |
n,m=map(int,input().split())
l=list(map(int,input().split()))
l=list(set(l))
n=len(l)
ll=[]
for i in l:
ll.append(int(i/2))
newl=[]
for i in ll:
j=i
count=0
while j%2==0:
j//=2
count+=1
newl.append(count)
import collections
newl=collections.Counter(newl)
if len(newl)!=1:
print(0)
else:
from fractions import gcd
num=ll[0]
flag=True
for i in ll:
if num<=m:
num=int(i*num/gcd(i,num))
else:
flag=False
break
if flag==False:
print(0)
else:
k=m%(num*2)
if k>=num:
print(int(m//(num*2)+1))
else:
print(int(m//(num*2))) | #! /usr/bin/env python
# -*- coding: utf-8 -*-
''' ??????????????? '''
# ????????????????????°?????????N(N-1)/2????????§???
# ?¨???????:O(n^2)
def selection_sort(A, N):
swap_num = 0 # ???????????°
for i in range(N):
minj = i
for j in range(i, N, 1):
if A[j] < A[minj]:
minj = j
# swap
if i != minj:
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
swap_num += 1
return (A, swap_num)
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
# A = [5, 2, 4, 6, 1, 3]
# N = len(A)
array_sorted, swap_num = selection_sort(A, N)
print(' '.join(map(str, array_sorted)))
print(swap_num) | 0 | null | 50,670,568,402,160 | 247 | 15 |
N = int(input())
A = [int(s) for s in input().split()]
print(' '.join([str(item) for item in A]))
for i in range(1, N):
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j = j - 1
A[j+1] = key
print(' '.join([str(item) for item in A])) |
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if m1!=m2 and d2==1:
print('1')
else:
print('0') | 0 | null | 62,055,260,234,620 | 10 | 264 |
round=int(input())
T_pt=0
H_pt=0
for i in range(round):
pair=raw_input().split(" ")
T_card=pair[0].lower()
H_card=pair[1].lower()
if T_card<H_card:
H_pt+=3
elif T_card>H_card:
T_pt+=3
else:
T_pt+=1
H_pt+=1
print T_pt,H_pt | def draw(h,w):
s = "#" * w
for i in range(0,h):
print s
print
if __name__ == "__main__":
while True:
h,w = map(int, raw_input().split())
if h==0 and w==0:
break
else:
draw(h,w) | 0 | null | 1,404,766,728,678 | 67 | 49 |
import bisect
n = int(input())
L = list(map(int, input().split()))
#%%
L.sort()
ans = 0
for i in range(n-2): # aを固定
for j in range(i+1, n-1): # bを固定
ab = L[i] + L[j]
idx = bisect.bisect_left(L, ab, lo=j)
ans += max(idx - (j+1), 0)
print(ans)
| from bisect import bisect_left
n = int(input())
L = sorted(list(map(int, input().split())))
# 二分探索
cnt = 0
for i in range(n):
for j in range(i+1, n):
a, b = L[i], L[j]
# c < a + b
r = bisect_left(L, a+b)
l = j+1
cnt += max(0, r-l)
print(cnt) | 1 | 171,970,204,548,450 | null | 294 | 294 |
string = input()
for s in string:
if s.isupper():
print(s.lower(), end='')
else:
print(s.upper(), end='')
print('') | # -*- coding:utf-8 -*-
n = int(input())
import sys
a = input()
a = a.split()
a = [int(i) for i in a]
a.reverse()
for i in range(n-1):
print(a[i],end = ' ')
print(a[n-1]) | 0 | null | 1,236,747,488,672 | 61 | 53 |
import itertools
N, M, Q = map(int, input().split())
q = [list(map(int, input().split())) for _ in range(Q)]
a = [0] * N
max_score = 0
for v in itertools.combinations(range(N + M - 1), N):
tmp_score = 0
for n in range(N):
a[n] = v[n] + 1 - n
for query in q:
if (a[query[1] - 1] - a[query[0] - 1]) == query[2]:
tmp_score += query[3]
if max_score < tmp_score:
max_score = tmp_score
print(max_score)
| n = input()
print n*n*n | 0 | null | 14,065,487,356,750 | 160 | 35 |
s = str(input())
if s == 'SUN':
print(7)
elif s == 'MON':
print(6)
elif s == 'TUE':
print(5)
elif s == 'WED':
print(4)
elif s == 'THU':
print(3)
elif s == 'FRI':
print(2)
else:
print(1)
| weekday = ['SUN', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON']
val = input()
if val == 'SUN':
print("7")
else:
print(weekday.index(val)) | 1 | 132,954,569,870,690 | null | 270 | 270 |
x = int(input())
m = divmod(x, 500)
print(m[0] * 1000 + m[1] // 5 * 5) | x=int(input())
n=x//500
m=x%500
k=m//5
print(1000*n+5*k) | 1 | 42,725,496,361,518 | null | 185 | 185 |
# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
A=map(lambda a: (a-1)%K, A)
S=[0]
for a in A:
S.append( (S[-1]+a)%K ) #累積和
d=dict() #要素:要素の数を持つ
ans=0
for i in range(N+1):
x=S[i]%K
if i==0:
d[x]=1
else:
if x in d:
if 2<=K: #K=1の時は自分の値も見てはいけない
ans+=d[x] #自分より前に同じ出現した、自分と同じ要素の数を答えに追加
d[x]+=1
else:
d[x]=1
if 0<=i-K+1:
x_head=S[i-K+1]%K #長さK-1の範囲で配列Sを見るため、1つ進んだら一番先頭の要素を辞書から削除する
d[x_head]-=1
print ans
| from itertools import accumulate
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
acc = [0] + list(accumulate(a))
sm = [(e - i) % k for i, e in enumerate(acc)]
d = defaultdict(int)
ans = 0
for r in range(1, n + 1):
if r - k >= 0:
e = sm[r - k]
d[e] -= 1
e = sm[r - 1]
d[e] += 1
e = sm[r]
ans += d[e]
print(ans)
| 1 | 137,942,904,614,880 | null | 273 | 273 |
n = input()
a, b = 0, 100
for i in n:
j = int(i)
a, b = min(a+j,b+j), min(a+11-j,b+9-j)
if j == 0:
b = a+100
print(min(a,b)) |
s=input()
if len(s)%2!=0:
print("No")
else:
bool=False
for i in range(len(s)):
if i%2==0:
if s[i]!="h":
print("No")
bool=True
break
else:
if s[i]!="i":
print("No")
bool=True
break
if bool is False:
print("Yes")
| 0 | null | 62,013,719,549,212 | 219 | 199 |
n = int(input())
a = list(map(int, input().split()))
ans_h = {}
ans = []
for (i, ele) in enumerate(a):
ans_h[ele] = i + 1
for i in range(1, n + 1):
ans.append(str(ans_h[i]))
print(" ".join(ans)) | N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A = [(i,A[i]) for i in range(N+1)]
A = sorted(A,key=lambda x:x[1])
B = []
for i in range(1,N+1):
B.append(A[i][0])
print(*B) | 1 | 181,534,099,256,380 | null | 299 | 299 |
def main():
n, k = map(int, input().split())
p = list(map(int, input().split()))
ex = [0]
for x in p:
ex.append(ex[-1] + (x+1)/2)
ans = 0
for i in range(k, n+1):
ans = max(ans, ex[i] - ex[i-k])
print(ans)
main() | N,K= list(map(int, input().split()))
Ps = list(map(int, input().split()))
ruisekiwa = [0]
for P in Ps:
ruisekiwa.append(P + ruisekiwa[-1])
#print(ruisekiwa)
ans = 0
for i in range(N-K+1):
ans = max(ans, (ruisekiwa[i+K] - ruisekiwa[i] + K) / 2)
# print(ans)
print(ans) | 1 | 75,133,622,726,680 | null | 223 | 223 |
n = int(input())
fib = [1]*2 + [0]*(n-1)
for i in range(2, n+1):
fib[i] = fib[i-1] + fib[i-2]
print(fib[n]) | N = int(input())
memo = []
memo = [1,1] + [0] * (N - 1)
def f(n):
if memo[n] == 0:
memo[n] = f(n-1) + f(n-2)
return(memo[n])
if memo[n] != 0:
return(memo[n])
print(f(N))
| 1 | 1,854,428,550 | null | 7 | 7 |
n,d,a = map(int,input().split())
xh = [list(map(int,input().split())) for _ in range(n)]
xh.sort()
j = 0
cnt = [0] * n
taken = 0
def problem(h):
if h <= 0:return 0
ans = h//a
if h%a :
ans += 1
return ans
for i in range(n):
[x,h] = xh[i]
while xh[j][0] + 2*d < x:
taken -= cnt[j]
j += 1
# if taken * a >= h:
# break
# if not h % a:
# cnt[i] = h//a - taken
# else:
# cnt[i] = h//a - taken + 1
cnt[i] = problem(h - taken * a)
taken += cnt[i]
print(sum(cnt))
| def main():
import math
N = int(input())
ans=0
for i in range(1,N+1):
for j in range(1, N+1):
for k in range(1, N+1):
t=math.gcd(i,j)
t=math.gcd(t,k)
ans+=t
print(ans)
if __name__=='__main__':
main() | 0 | null | 58,758,274,874,300 | 230 | 174 |
# -*- coding: utf-8 -*-
N=int(input())
x,y=map(int,input().split())
R=x
L=x
U=y
B=y
P=[(x,y)]
for i in range(1,N):
x,y=map(int,input().split())
P.append((x,y))
if R<x:R=x
if L>x:L=x
if U<y:U=y
if B>y:B=y
p=P[0]
UR=p
dUR=abs(R-p[0])+abs(U-p[1])
UL=p
dUL=abs(L-p[0])+abs(U-p[1])
BR=p
dBR=abs(R-p[0])+abs(B-p[1])
BL=p
dBL=abs(L-p[0])+abs(B-p[1])
for p in P[1:]:
if dUR>abs(R-p[0])+abs(U-p[1]):
UR=p
dUR=abs(R-p[0])+abs(U-p[1])
if dUL>abs(L-p[0])+abs(U-p[1]):
UL=p
dUL=abs(L-p[0])+abs(U-p[1])
if dBR>abs(R-p[0])+abs(B-p[1]):
BR=p
dBR=abs(R-p[0])+abs(B-p[1])
if dBL>abs(L-p[0])+abs(B-p[1]):
BL=p
dBL=abs(L-p[0])+abs(B-p[1])
ans=abs(UR[0]-BL[0])+abs(UR[1]-BL[1])
ans2=abs(UL[0]-BR[0])+abs(UL[1]-BR[1])
if ans2>ans: ans=ans2
print(ans)
| n=int(input())
s,p=10**100,10**100
t,q=-1000000000000,-1000000000000
for i in range(n):
x,y=map(int,input().split())
s=min(s,x+y)
t=max(t,x+y)
p=min(p,x-y)
q=max(q,x-y)
print(max(t-s,q-p))
| 1 | 3,389,052,275,940 | null | 80 | 80 |
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if (v-w)*t >= abs(a-b):
print('YES')
else:
print('NO') | a,v,b,w,t=map(int,open(0).read().split())
print('YNEOS'[abs(b-a)>(v-w)*t::2]) | 1 | 15,142,559,495,584 | null | 131 | 131 |
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
if k == 0:
print(sum(h))
else:
print(sum(h[:-k]))
| money = int(input())
while money > 1000 :
money -= 1000
print(1000 - money) | 0 | null | 43,868,533,396,350 | 227 | 108 |
#Is it Right Triangre?
n = int(input())
for i in range(n):
set = input(). split()
set = [int(a) for a in set] #int?????????
set.sort()
if set[0] ** 2 + set[1] ** 2 == set[2] ** 2:
print("YES")
else:
print("NO") | N = int(input())
for i in range(N):
a,b,c = map(int,input().split())
if a*a + b*b == c*c or b*b+c*c == a*a or a*a+c*c == b*b:
print("YES")
else:
print("NO") | 1 | 282,127,982 | null | 4 | 4 |
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
hand=["" for _ in range(k)]
point=[0 for _ in range(k)]
for i in range(n):
index=i%k
#初めの手(制限なし)
if index==i:
if t[i]=="r":
hand[index]="p"
point[index]+=p
elif t[i]=="s":
hand[index]="r"
point[index]+=r
else:
hand[index]="s"
point[index]+=s
#2番目以降の手
else:
if t[i]=="r":
if hand[index]=="p":
hand[index]="x"
else:
hand[index]="p"
point[index]+=p
elif t[i]=="s":
if hand[index]=="r":
hand[index]="x"
else:
hand[index]="r"
point[index]+=r
else:
if hand[index]=="s":
hand[index]="x"
else:
hand[index]="s"
point[index]+=s
print(sum(point)) | n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()
def add(x):
if x == 'r':
return p
elif x == 's':
return r
else:
return s
nk =[0]*k
for i in range(n):
key = i%k
if nk[key]==0:
nk[key] = [t[i]]
else:
nk[key].append(t[i])
ans = 0
for j in nk:
if j ==0:
continue
ans += add(j[0])
for k in range(1, len(j)):
if j[k]== j[k-1]:
j[k]='q'
else:
ans += add(j[k])
print(ans) | 1 | 107,003,450,885,380 | null | 251 | 251 |
import sys
input = sys.stdin.readline
import collections
import bisect
def main():
n = int(input())
l = input_list()
l.sort()
ans = 0
for i in range(n-2):
for j in range(i+1, n-1):
ind = bisect.bisect_left(l, l[i]+l[j])
num = ind - 1 - j
ans += num
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
for j in range(i+1,n):
left=j+1
right=n
while left<right:
mid=(left+right)//2
if l[mid]>=l[i]+l[j]:
right=mid
else:
left=mid+1
ans+=right-j-1
print(ans) | 1 | 171,970,244,801,850 | null | 294 | 294 |
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
T = [0] * (N+1)
for i in range(N):
S[i+1] = (S[i] + A[i])%K
T[i+1] = (S[i+1] - (i+1))%K
rest = defaultdict(int)
for i in range(N+1):
if i < K:
ans += rest[T[i]]
rest[T[i]] += 1
else:
rest[T[i-K]] -= 1
ans += rest[T[i]]
rest[T[i]] += 1
print(ans) | import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))
S = [A[0] % k]
for i in range(1, n):
S.append((A[i]+S[-1]) % k)
# print(S)
D = {}
S = [0] + S
ans = 0
for i in range(len(S)):
key = (S[i] - i) % k
if i >= k:
j = i-k
key1 = (S[j] - j) % k
D[key1] -= 1
try:
ans += D[key1]
# print(i, j, D[key1])
except:
ans += 0
try:
D[key] += 1
except:
D[key] = 1
for j in range(max(0, len(S)-k), len(S)):
key1 = (S[j] - j) % k
D[key1] -= 1
try:
ans += D[key1]
# print(i, j, D[key1])
except:
ans += 0
# print(D)
print(ans) | 1 | 136,896,090,285,568 | null | 273 | 273 |
n=int(input())
a=list(map(int,input().split()))
l=[]
flag=0
for aa in a:
if aa%2==0:
flag=1
l.append(aa)
if flag==1:
for ll in l:
if ll % 3!=0 and ll % 5!=0:
flag=2
if flag==0:
print('APPROVED')
elif flag==1:
print('APPROVED')
elif flag==2:
print('DENIED')
| n = int(input())
a = list(map(int, input().split()))
for i in a:
if i % 2 == 0:
if i % 6 > 0 and i % 10 > 0:
print('DENIED')
exit()
print('APPROVED') | 1 | 69,352,582,698,322 | null | 217 | 217 |
import sys
input = sys.stdin.readline
INF = 10**18
sys.setrecursionlimit(10**6)
def li():
return [int(x) for x in input().split()]
N, X, MOD = li()
n = X
nums = [X]
loop_start_i = -INF
for i in range(1, N):
n = pow(n, 2, MOD)
if n in nums:
loop_start_i = nums.index(n)
break
nums.append(n)
# total %= MOD
loop_length = len(nums) - loop_start_i
loop_cnt = (N - loop_start_i) // loop_length
r = (N - loop_start_i) % loop_length
sum_per_loop = sum(nums[loop_start_i:])
ans = sum(nums[:loop_start_i]) + sum_per_loop * loop_cnt + sum(nums[loop_start_i:loop_start_i+r])
print(ans) | N, X, M = map(int, input().split())
if X <= 1:
print(X*N)
exit()
check = [0]*(M+1)
check[X] += 1
A = X
last_count = 0
while True:
A = (A**2)%M
if check[A] != 0:
last_count = sum(check)
target_value = A
break
check[A] += 1
A2 = X
first_count = 0
while A2 != target_value:
first_count += 1
A2 = (A2**2)%M
roop_count = last_count-first_count
A3 = target_value
mass = A3
for i in range(roop_count-1):
A3 = (A3**2)%M
mass += A3
if roop_count == 0:
print(N*X)
exit()
if first_count != 0:
ans = X
A = X
for i in range(min(N,first_count)-1):
A = (A**2)%M
ans += A
else:
ans = 0
if N > first_count:
ans += ((N-first_count)//roop_count)*mass
A4 = target_value
if (N-first_count)%roop_count >= 1:
ans += A4
for i in range(((N-first_count)%roop_count)-1):
A4 = (A4**2)%M
ans += A4
print(ans) | 1 | 2,820,033,775,600 | null | 75 | 75 |
n, t = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:(x[0]))
t -= 1
dp = [[0]*(t+1) for i in range(n+1)]
for i in range(1, n+1):
ca, cb = ab[i-1][0], ab[i-1][1]
for j in range(1, t+1):
if j - ca >= 0:
dp[i][j] = max(dp[i-1][j], dp[i-1][j-ca] + cb)
else:
dp[i][j] = dp[i-1][j]
b_max = [0]
tmp = 0
for i in range(n-1, -1, -1):
tmp = max(tmp, ab[i][1])
b_max = [tmp] + b_max
ans = 0
for i in range(n+1):
ans = max(ans, dp[i][t] + b_max[i])
# print(dp[i][t] + b_max[i])
print(ans) | N, T = map(int, input().split())
p = []
for i in range(N):
A, B = map(int, input().split())
p.append([A, B])
p.sort()
dp = [[0]*3005 for _ in range(3005)]
ans = 0
for i in range(N):
for j in range(T):
dp[i+1][j] = max(dp[i+1][j], dp[i][j])
nextj = j + p[i][0]
if nextj < T:
dp[i+1][nextj] = max(dp[i+1][nextj], dp[i][j] + p[i][1])
now = dp[i][T-1] + p[i][1]
ans = max(ans, now)
print(ans)
| 1 | 151,304,482,299,388 | null | 282 | 282 |
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
res = [None] * n
for i in range(n):
res[i] = II()
return res
def LIR(n):
res = [None] * n
for i in range(n):
res[i] = LI()
return res
def FR(n):
res = [None] * n
for i in range(n):
res[i] = IF()
return res
def LIR(n):
res = [None] * n
for i in range(n):
res[i] = IF()
return res
def LIR_(n):
res = [None] * n
for i in range(n):
res[i] = LI_()
return res
def SR(n):
res = [None] * n
for i in range(n):
res[i] = S()
return res
def LSR(n):
res = [None] * n
for i in range(n):
res[i] = LS()
return res
mod = 1000000007
inf = float('INF')
#solve
def solve():
def f(n, c):
tmp = n % c
t = tmp
b = 0
while tmp:
if tmp & 1:
b += 1
tmp //= 2
if t:
return f(t, b) + 1
else:
return 1
n = II()
a = S()
b = 0
for ai in a:
if ai == "1":
b += 1
a = a[::-1]
bp = 0
bm = 0
if b != 1:
for i, ai in enumerate(a):
if ai == "1":
bp += pow(2, i, b + 1)
bm += pow(2, i, b - 1)
bp %= b + 1
bm %= b - 1
ans = []
for i, ai in enumerate(a):
if ai == "1":
tmpbm = bm - pow(2, i, b - 1)
tmpbm %= b - 1
ans.append(f(tmpbm, b - 1))
else:
tmpbp = bp + pow(2, i, b + 1)
tmpbp %= b + 1
ans.append(f(tmpbp, b + 1))
for ai in ans[::-1]:
print(ai)
return
else:
for i, ai in enumerate(a):
if ai == "1":
bp += pow(2, i, b + 1)
bp %= b + 1
ans = []
for i, ai in enumerate(a):
if ai == "1":
ans.append(0)
else:
tmpbp = bp + pow(2, i, b + 1)
tmpbp %= b + 1
ans.append(f(tmpbp, b + 1))
for ai in ans[::-1]:
print(ai)
return
#main
if __name__ == '__main__':
solve()
| S = int(input())
dp = [0 for _ in range(S+1)]
dp[0] = 1
MOD = 10**9+7
for i in range(3,S+1):
dp[i] = dp[i-1]+dp[i-3]
print(dp[S]%MOD) | 0 | null | 5,730,132,088,182 | 107 | 79 |
from collections import deque
#スタックを使った深さ優先探索の実装
l = int(input())
rlist = []
for i in range(l):
li = list(map(int, input().split()))
rlist.append(deque([ll-1 for ll in li[2:]]))
color = ['white'] * l
find_time = [0] * l
stop_time = [0] * l
stack = []
time = 0
def dfs(u):
global time
stack.append(u)
color[u] = 'gray'
time += 1
find_time[u] = time
while len(stack) > 0:
#print(stack)
#print(color)
#print(rlist)
u = stack[-1]
#頂点uにまだ訪問すべき頂点が残っているなら
if len(rlist[u]) > 0:
if color[rlist[u][0]] == 'white':
time += 1
find_time[rlist[u][0]] = time
color[rlist[u][0]] = 'gray'
stack.append(rlist[u][0])
rlist[u].popleft()
#頂点uにもう訪問すべき頂点が残っていないなら
else:
time += 1
stop_time[u] = time
color[u] = 'black'
stack.pop()
for i in range(l):
if color[i] == 'white':
dfs(i)
for i in range(len(find_time)):
print(str(i+1) + ' ' + str(find_time[i]) + ' ' + str(stop_time[i]))
| T = [0]
def curserch(N,k,T,P,n):
T[0] = T[0]+1
P[k]["d"] = T[0]
for i in range(1,n+1):
if N[k][i]==1 and P[i]["d"]==0:
curserch(N,i,T,P,n)
T[0] = T[0]+1
P[i]["f"]=T[0]
n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]
for i in range(n):
vec = input().split()
u = int(vec[0])
k = int(vec[1])
nodes = vec[2:]
for i in range(int(k)):
v = int(nodes[i])
A[u][v] = 1
P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
if P[i]["d"]==0:
curserch(A,i,T,P,n)
T[0] = T[0]+1
P[i]["f"]=T[0]
for i in range(1,n+1):
print(i,P[i]["d"],P[i]["f"]) | 1 | 2,825,322,452 | null | 8 | 8 |
A, B, C, K = [int(_) for _ in input().split()]
print(K if K <= A else A if K <= A + B else A - (K - A - B))
| import sys
def input(): return sys.stdin.readline().rstrip()
A,B,C,K = map(int,input().split())
point = 0
if A <= K:
point += A
K -= A
else:
point += K
K = 0
if B <= K:
K -= B
else:
K = 0
point -= K
print(point) | 1 | 21,867,318,968,260 | null | 148 | 148 |
from collections import deque
N = int(input())
A = sorted(map(int, input().split()), reverse=True)
ans = A[0]
q = deque((A[1], A[1]))
for i in range(2, N):
ans += q.popleft()
q.append(A[i])
q.append(A[i])
print(ans) | N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
ans = A[0] + sum(A[1:N//2])*2
if N % 2 == 1:
ans += A[N//2]
# print(A[1:N//2])
# スコアを獲得できるのはN-1回
print(ans)
| 1 | 9,229,890,101,450 | null | 111 | 111 |
import sys
input = sys.stdin.readline
def gcd(a, b):
while b:
a, b = b, a%b
return a
def lcm(a, b):
return a//gcd(a, b)*b
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = [ai//2 for ai in a]
cnt = [0]*N
for i in range(N):
t = b[i]
while t%2==0:
cnt[i] += 1
t //= 2
if cnt!=[cnt[0]]*N:
print(0)
exit()
L = 1
for bi in b:
L = lcm(L, bi)
if L>M:
print(0)
else:
print((M-L)//(2*L)+1) | N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x),input().split()))
cnt = [0 for _ in range(N)]
for i in range(N):
a = A[i]
while a%2 == 0:
a = a // 2
cnt[i] += 1
if max(cnt) > min(cnt):
print(0)
exit(0)
C = max(cnt)
A = list(map(lambda x: x // pow(2,C), A))
def gcd(a,b):
if a<b:
a,b = b,a
while a%b > 0:
a,b = b,a%b
return b
def lcm(a,b):
return a*b//gcd(a,b)
x = A[0]
for a in A[1:]:
x = lcm(x,a)
x = x * pow(2,C-1)
print((M // x + 1) // 2) | 1 | 101,351,203,828,322 | null | 247 | 247 |
n, m, k = map(int, input().split(' '))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
a_sum=[list_a[0]]
for i in range(1, n):
a_sum.append(list_a[i]+a_sum[i-1])
b_sum=[list_b[0]]
for i in range(1, m):
b_sum.append(list_b[i]+b_sum[i-1])
ans=0
if (a_sum[0]>k) and (b_sum[0]>k):
print(0)
else:
for j in range(m):
if b_sum[j]<=k:
ans=max(ans, j+1)
j=m-1
for i in range(n):
if a_sum[i]<=k:
ans=max(ans, i+1)
while a_sum[i] + b_sum[j] > k and j>0:
j-=1
if a_sum[i]+b_sum[j]<=k:
ans=max(ans, i+j+2)
print(ans) | N = int(input())
S = [input() for i in range(N)]
c0, c1, c2, c3 = 0, 0, 0, 0
for i in S:
if i == 'AC':
c0 += 1
if i == 'WA':
c1 += 1
if i == 'TLE':
c2 += 1
if i == 'RE':
c3 += 1
print('AC','x',c0)
print('WA','x',c1)
print('TLE','x',c2)
print('RE','x',c3) | 0 | null | 9,737,077,454,600 | 117 | 109 |
r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
ri, ci, vi = map(int, input().split())
v[ri - 1][ci - 1] = vi
dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
for j in range(c):
dpj = dp[j][:]
if j == 0:
dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
else:
dp[j][0] = max(max(dpj), dp[j - 1][0])
dp[j][1] = dp[j - 1][1]
dp[j][2] = dp[j - 1][2]
dp[j][3] = dp[j - 1][3]
if v[i][j] > 0:
dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])
print(max(dp[c - 1]))
| import numpy as np
import numba
@numba.njit("(i8,i8,i8,i8[:,:])", cache=True)
def solve(R, C, K, RCV):
# dp[y][x][n]
M = np.zeros((R+1, C+1), dtype=np.int64)
for i in range(K):
r, c, v = RCV[i]
M[r, c] = v
dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
for y in range(1, R+1):
for x in range(1, C+1):
for n in range(4):
if n == 0:
dp[y, x, n] = max(
dp[y, x-1, 0],
dp[y-1, x, :].max()
)
if n > 0:
dp[y, x, n] = max(
dp[y, x-1, n],
dp[y, x-1, n-1] + M[y, x],
dp[y-1, x, :].max() + M[y, x]
)
ans = dp[R, C].max()
print(ans)
import sys
def main():
R, C, K = map(int, input().split())
RCV = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(K, 3)
solve(R, C, K, RCV)
main()
| 1 | 5,564,202,046,898 | null | 94 | 94 |
r,c=list(map(int,input().split()))
s=[0 for i in range(c+1)]
for i in range(r):
l=list(map(int,input().split()))
l.append(sum(l))
print(' '.join(map(str,l)))
s=[s[i]+l[i] for i in range(c+1)]
print(' '.join(map(str,s))) | n = int(input())
output = 'ACL'*n
print(output) | 0 | null | 1,752,646,378,912 | 59 | 69 |
a=int(input())
print(sum(divmod(a,2)))
| N=int(input())
result=N/2
if N%2 != 0:
result+=0.5
print(int(result)) | 1 | 58,975,885,113,782 | null | 206 | 206 |
N = int(input())
clips = [input().split() for _ in range(N)]
X = input()
FLG = 0
ans = 0
for title,time in clips:
if FLG:
ans += int(time)
if title == X:
FLG = 1
print(ans) | import sys
input = sys.stdin.readline
def main():
s = input().rstrip('\n')
n = len(s)
ansl = [0]*(n+1)
for i in range(n):
if s[i] == '<':
ansl[i+1] = ansl[i]+1
for i in reversed(range(n)):
if s[i] == '>':
ansl[i] = max(ansl[i+1]+1,ansl[i])
print(sum(ansl))
if __name__ == '__main__':
main() | 0 | null | 126,283,528,504,100 | 243 | 285 |
import sys
def solve(h):
if h == 1:
return 1
else:
return 1 + 2 * solve(h // 2)
def main():
input = sys.stdin.buffer.readline
h = int(input())
print(solve(h))
if __name__ == "__main__":
main()
| Day = ['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
print(Day.index(input())) | 0 | null | 106,618,545,423,780 | 228 | 270 |
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
ans=0
cnt=[0 for i in range(61)]
for i in range(n):
now=A[i]
bek=1
for q in range(61):
if now&1==0:
ans+=cnt[q]*bek
else:
ans+=(i-cnt[q])*bek
bek=bek*2%mod
cnt[q]+=now&1
now>>=1
ans=ans%mod
#print(ans)
print(ans) | n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
C = []
for s in S:
for t in T:
if s == t and not s in C: C.append(s)
print(len(C)) | 0 | null | 61,649,002,843,780 | 263 | 22 |
# coding: utf-8
import sys
import collections
def main():
n, quantum = map(int, raw_input().split())
processes = [x.split() for x in sys.stdin.readlines()]
for p in processes:
p[1] = int(p[1])
queue = collections.deque(processes)
elapsed = 0
while queue:
# print elapsed, queue
head = queue.popleft()
if head[1] > quantum:
head[1] -= quantum
queue.append(head)
elapsed += quantum
else:
elapsed += head[1]
print head[0], elapsed
if __name__ == '__main__':
main() | import sys
if __name__ == '__main__':
r = int(input())
print(r * r)
| 0 | null | 72,857,159,063,040 | 19 | 278 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.