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
|
---|---|---|---|---|---|---|
X = int(input())
if X <= 599:
print(8)
elif X <= 799:
print(7)
elif X <= 999:
print(6)
elif X <= 1199:
print(5)
elif X <= 1399:
print(4)
elif X <= 1599:
print(3)
elif X <= 1799:
print(2)
elif X <= 1999:
print(1)
| n = int(input())
print(10 - n // 200) | 1 | 6,789,226,580,402 | null | 100 | 100 |
import numpy as np
mod = 998244353
n, s = map(int, input().split())
A = list(map(int, input().split()))
DP = np.zeros(3005, dtype=np.int64)
for num, a in enumerate(A):
double = DP * 2
shift = np.hstack([np.zeros(a), DP[:-a]]).astype(np.int64)
DP = double + shift
DP[a] += pow(2, num, mod)
DP %= mod
print(DP[s])
| i = int(input())
if i%2==0:
x=i/2-1
print(int(x))
else:
x=(i-1)/2
print(int(x)) | 0 | null | 85,391,782,409,530 | 138 | 283 |
X = int(input())
gohyaku = X // 500
X = X - (gohyaku * 500)
goen = X // 5
print(gohyaku * 1000 + goen * 5) | N, M = map(int, input().split())
def solve(N,M):
dp = [[float('inf')]*(N+1) for _ in range(M+1)]
C = list(map(int, input().split()))
dp[0][0] = 0
for i in range(1,M+1):
dp[i][0] = 0
for j in range(1,N+1):
dp[i][j] = dp[i-1][j]
if j>=C[i-1]:
dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
ans = dp[M][N]
return ans
print(solve(N,M))
| 0 | null | 21,436,047,219,466 | 185 | 28 |
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808
def calc_score(D, C, S, T):
"""
開催日程Tを受け取ってそこまでのスコアを返す
コンテストi 0-indexed
d 0-indexed
"""
score = 0
last = [0]*26 # コンテストiを前回開催した日
for d, t in enumerate(T):
last[t] = d + 1
for i in range(26):
score -= (d + 1 - last[i]) * C[i]
score += S[d][t]
return score
def update_score(D, C, S, T, score, ct, ci):
"""
ct日目のコンテストをコンテストciに変更する
スコアを差分更新する
ct: change t 変更日 0-indexed
ci: change i 変更コンテスト 0-indexed
"""
last = [0]*26 # コンテストiを前回開催した日
for d in range(ct):
last[T[d]] = d + 1
prei = T[ct] # 変更前に開催する予定だったコンテストi
score -= S[ct][prei]
score += S[ct][ci]
for d in range(ct, D):
if d != ct and T[d] == prei:
break
score += C[prei]*(d + 1 - ct - 1)
score -= C[prei]*(d + 1 - last[prei])
for d in range(ct, D):
if d != ct and T[d] == ci:
break
score += C[ci]*(d + 1 - last[ci])
score -= C[ci]*(d + 1 - ct - 1)
T[ct] = ci
return score, T
def local_search(D, C, S, T, today_score, d):
pass
def greedy(D, C, S):
T = [] # 0-indexed
for d in range(D):
# d日目終了時点で満足度が一番高くなるようなコンテストiを開催する
max_score = -INF
best_i = 0
for i in range(26):
T.append(i)
score = calc_score(D, C, S, T)
if max_score < score:
max_score = score
best_i = i
T.pop()
T.append(best_i)
return T
if __name__ == '__main__':
D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]
T = greedy(D, C, S)
for t in T:
print(t+1)
| def g(n):
x,y=n
r=x%y
if r>0:g((y,r))
else:print(y)
g(sorted(list(map(int,input().split())))) | 0 | null | 4,911,625,548,486 | 113 | 11 |
n, k = map(int, input().split())
mod = 10**9 + 7
s = [0]*(n+1)
s[0] = n + 1
for i in range(1, n+1):
s[i] = (s[i-1] + n - 2 * i) % mod
ans = 0
for i in range(k-1, n+1):
ans += s[i]
ans %= mod
print(ans)
| n = int(input())
alp = [chr(ord("a") + x) for x in range(26)]
def dfs(S):
if len(S) == n:
print(S)
else:
max_s = ord(max(S)) - 96
#print(max_s)
for i in range(max_s + 1):
dfs(S + alp[i])
dfs("a") | 0 | null | 42,977,369,675,338 | 170 | 198 |
S = str(input())
le = len(S)
s = []
for i in range(le):
s.append(S[i])
r = s.count("R")
if r == 0:
print(0)
elif r == 1:
print(1)
elif r == 2:
if s[1] == "S":
print(1)
else:
print(2)
elif r == 3:
print(3)
| s = input()
if s == "RRR":
x = 3
elif s == "RRS" or s == "SRR":
x = 2
elif s == "SSS":
x = 0
else:
x = 1
print(x) | 1 | 4,824,617,174,472 | null | 90 | 90 |
def main():
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
if D2 == 1:
print(1)
else:
print(0)
if __name__ == "__main__":
main() | v=raw_input()
a=int(v[:v.find(" ")])
b=int(v[v.find(" "):])
if(a>b):
print "a > b"
elif(a<b):
print "a < b"
else:
print "a == b"
| 0 | null | 62,674,271,586,400 | 264 | 38 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
s = str(readline().rstrip().decode('utf-8'))
res = []
start = n
while True:
b = False
for j in range(max(0, start - m), start):
if s[j] == "0":
res.append(start - j)
start = j
b = True
break
if not b:
print(-1)
exit()
else:
if j == 0:
res.reverse()
print(*res)
exit()
if __name__ == '__main__':
solve()
| N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
if A[i] > A[i + 1]:
ans += A[i] - A[i + 1]
A[i + 1] = max(A[i], A[i + 1])
print(ans)
| 0 | null | 71,582,415,705,280 | 274 | 88 |
w = input()
cnt = 0
while(True):
t = input()
if t == "END_OF_TEXT":
break
t = t.lower().split()
for i in t:
if i == w:
cnt += 1
print(cnt)
| n = int(input())
s = list(map(int, input().strip().split()))
befmax=0
sumlong=0
for i in range(0,n):
if(befmax>s[i]):
sumlong += befmax-s[i]
else:
befmax=s[i]
print(sumlong) | 0 | null | 3,190,866,181,832 | 65 | 88 |
import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
A,B=mi()
print(max(0,A-2*B))
if __name__ == "__main__":
main() | icase=0
if icase==0:
a,b=map(int,input().split())
print(max(a-2*b,0))
| 1 | 166,535,435,395,180 | null | 291 | 291 |
def insert_sort(A):
for i in range(1, len(A)):
k = A[i]
j = i - 1
while j >= 0 and A[j] > k:
A[j + 1] = A[j]
j -= 1
A[j + 1] = k
show(A)
def show(A):
for i in range(len(A) - 1):
print(A[i], end=" ")
print(A[len(A) - 1])
n = int(input())
line = input()
A = list(map(int, line.split()))
show(A)
insert_sort(A) | def main():
N = int(input())
A = list(map(int, input().split(' ')))
insertion_sort(A, N)
def insertion_sort(A, N):
print(' '.join([str(n) for n in A]))
for i in range(1, N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(' '.join([str(n) for n in A]))
return A
if __name__ == '__main__':
main() | 1 | 5,896,445,348 | null | 10 | 10 |
D=int(input())
c=[]
c=list(map(int,input().split()))
s=[]
for i in range(D):
s.append(list(map(int,input().split())))
t=[0 for i in range(D)]
for i in range(D):
t[i]=int(input())
wa=0
last=[0 for i in range(26)]
for i in range(D):
wa=s[i][t[i]-1]+wa
last[t[i]-1]=i+1
for j in range(26):
wa=wa-c[j]*((i+1)-last[j])
print(wa)
| import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
"""
sum[Al,,,Ar] = Sの部分和がちょうどK個。
"""
n, k, s = map(int, input().split())
if n == k:
r = [s] * k
else:
if s == 1000000000:
r = [1000000000] * k + [1] * (n - k)
else:
r = [s] * k + [1000000000] * (n - k)
print(*r, sep=' ')
if __name__ == '__main__':
main() | 0 | null | 50,582,099,127,650 | 114 | 238 |
import sys
Stack = []
MAX = 1000
def push(x):
#if isFull():
# print "ERROR!"
# sys.exit()
Stack.append(x)
def pop():
#if isEmpty():
# print "ERROR!"
# sys.exit()
Stack.pop(-1)
def cul(exp):
for v in exp:
if v == "+":
x = reduce(lambda a,b:int(a)+int(b), Stack[-2:])
for i in range(2):
pop()
push(x)
elif v == "-":
x = reduce(lambda a,b:int(a)-int(b), Stack[-2:])
for i in range(2):
pop()
push(x)
elif v == "*":
x = reduce(lambda a,b:int(a)*int(b), Stack[-2:])
for i in range(2):
pop()
push(x)
else:
push(v)
return Stack[0]
if __name__ == "__main__":
exp = sys.stdin.read().strip().split(" ")
ans = cul(exp)
print ans | l = input().split()
stack = []
for op in l:
if op.isdigit():
stack.append(int(op))
elif op == '+':
stack.append(stack.pop() + stack.pop())
elif op == '-':
stack.append(- stack.pop() + stack.pop())
elif op == '*':
stack.append(stack.pop() * stack.pop())
print(stack[-1]) | 1 | 37,835,004,728 | null | 18 | 18 |
N = int(input())
cnt = 0
for A in range(1, N + 1):
for B in range(1, N // A + 1):
C = N - A * B
if C >= 1 and A * B + C == N:
cnt += 1
print(cnt)
| N = int(input())
a = 0
k = 2*(N-2)+1
for i in range(2,N):
for j in range(i,N):
if (i*j<N)and(i!=j):
a+=2
elif(i*j<N)and(i==j):
a+=1
else:
break
print(a+k)
| 1 | 2,562,734,517,252 | null | 73 | 73 |
#(身長)ー(番号)=ー(身長)ー(番号)はありえない、身長=0にならないから
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
AB = defaultdict(int)
_AB = defaultdict(int)
for i,a in enumerate(A):
AB[i+1+A[i]]+=1
_AB[-A[i]+i+1]+=1
ans = 0
for key,val in AB.items():
ans += val*_AB[key]
print(ans)
| from collections import Counter
n=int(input())
a=list(map(int,input().split()))
i_l=[]
j_l=[]
for i in range(n):
i_l.append(i+a[i])
j_l.append(i-a[i])
ci=Counter(i_l)
cl=Counter(j_l)
ans=0
for k,v in ci.items():
ans+=v*cl[k]
print(ans) | 1 | 25,877,979,266,850 | null | 157 | 157 |
N = int(input())
A = list(map(int, input().split())) # <- note that this has (N - 1) elements
#print(A)
A_0 = [x - 1 for x in A]
#print(A_0)
ans = [0] * N # <- represents number of immediate subordinates of each person
for i in range(0, N - 1):
ans[A_0[i]] += 1
for i in range(0, N):
print(ans[i])
| while True:
a, op, b = raw_input().split()
if op == '?': break
a, b = int(a), int(b)
if op == '+': print a+b
if op == '-': print a-b
if op == '*': print a*b
if op == '/': print a/b | 0 | null | 16,591,555,935,978 | 169 | 47 |
# -*- coding: utf-8 -*-
S1 = 1
r = input()
R = int(r)
S2 = R ** 2
result = S2 / S1
print(int(result))
| r = int(input())
s = r**2
print(s) | 1 | 145,018,847,540,848 | null | 278 | 278 |
X = list(map(int, input().split()))
if X[0] == 0:
print(1)
elif X[1] == 0:
print(2)
elif X[2] == 0:
print(3)
elif X[3] == 0:
print(4)
else:
print(5) | x=list(map(int,input().split()))
for k in range(5):
if x[k]==0:
print(k+1)
else:
continue | 1 | 13,594,909,076,422 | null | 126 | 126 |
from bisect import bisect_left, bisect_right
n,m = map(int, input().split())
al = list(map(int, input().split()))
al.sort()
ok, ng = 0, 10**18+1
while abs(ok-ng) > 1:
mid = (ok+ng)//2
ok_flag = True
cnt = 0
# print('-----')
# print(ok,ng,mid)
for i,a in enumerate(al):
rem = mid-a
cnt_a = n-bisect_left(al,rem)
# cnt_a = min(n-i-1, cnt_a)
cnt += cnt_a
# print(i,a,cnt_a)
if cnt >= m:
ok = mid
else:
ng = mid
min_sum = ok
cum_sums = [0]
csum = 0
for a in al:
csum += a
cum_sums.append(csum)
# print(min_sum)
ans = 0
cnt = 0
for i,a in enumerate(al):
rem = min_sum - a
ind = bisect_left(al, rem)
# ind = ind if 0 <= ind < n else None
# ind = max(i+1,ind)
csum = cum_sums[n] - cum_sums[ind]
# print(i,a,csum)
ans += csum
ans += a*(n-ind)
cnt += (n-ind)
ans -= (cnt-m)*min_sum
print(ans)
# print(min_sum) | #import sys
#sys.setrecursionlimit(10**9)
H, N = map(int, input().split())
magic = [_ for _ in range(N)]
for k in range(N):
magic[k] = list(map(int, input().split()))
magic[k].append(magic[k][0]/magic[k][1])
magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]
ans2 = float('inf')
"""
def solve(start, power, point, maryoku):
if start == H:
print(min(point, min(anskouho)))
exit()
elif start > H:
anskouho.append(point)
return 0
elif ans[start] != 0:
return 0
else:
visited.append(start)
ans[start] = point
solve(start+power, power, point+maryoku, maryoku)
"""
for k in range(N):
for item in visited:
#solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])
start = item+magic[k][0]
power = magic[k][0]
point = ans[item]+ magic[k][1]
maryoku = magic[k][1]
for _ in range(10**5):
if start == H:
print(min(point, ans2))
exit()
elif start > H:
ans2 = min(ans2, point)
break
elif ans[start]!=0:
break
else:
visited.append(start)
ans[start] = point
start += power
point += maryoku
print(ans2) | 0 | null | 94,383,718,155,936 | 252 | 229 |
def main():
a,b,c=map(int,input().split())
if a<b<c:
print('Yes')
else:
print('No')
if __name__=='__main__':
main()
| import sys
for line in sys.stdin:
nums = list(map(int, line.split()))
res = "Yes" if nums[0] < nums[1] < nums[2] else "No"
print(res)
| 1 | 392,298,915,680 | null | 39 | 39 |
# coding: utf-8
import math
length = int(input())
total = 0
str = input()
table = list(str)
for i in range(length - 2):
if table[i] == "A":
if table[i+1] == "B":
if table[i+2] == "C":
total += 1
print(total) | n = int(input())
print(input().count("ABC")) | 1 | 99,108,414,540,948 | null | 245 | 245 |
N = int(input())
ST = []
cnt = 0
for _ in range(N):
s, t = input().split()
ST.append([s, t])
cnt += int(t)
X = input()
for i in range(N):
s, t = ST[i]
cnt -= int(t)
if s == X:
break
print(cnt)
| s=int(input())
h=s//3600
s-=h*3600
m=s//60
s-=m*60
print(str(h)+":"+str(m)+":"+str(s)) | 0 | null | 48,509,681,705,870 | 243 | 37 |
N=int(input())
MOD=10**9+7
in_9=10**N-9**N
in_0=10**N-9**N
nine_and_zero=10**N-8**N
ans=int(int(in_0+in_9-nine_and_zero)%MOD)
print(ans) | l = int(input())
a = l/3
print(a*a*a) | 0 | null | 25,236,154,381,600 | 78 | 191 |
class Dice:
def __init__(self, labels):
self.labels = labels
def north(self):
self.change([2, 6, 3, 4, 1, 5])
def south(self):
self.change([5, 1, 3, 4, 6, 2])
def east(self):
self.change([4, 2, 1, 6, 5, 3])
def west(self):
self.change([3, 2, 6, 1, 5, 4])
def change(self, convert):
result = []
for i in range(6):
result.append(self.labels[convert[i] - 1])
self.labels = result
dice = Dice(list(map(int, input().split())))
for direction in input():
if direction == 'N':
dice.north()
if direction == 'S':
dice.south()
if direction == 'E':
dice.east()
if direction == 'W':
dice.west()
print(dice.labels[0]) | class Dice:
def __init__(self,u,s,e,w,n,d):
self.n = n
self.e = e
self.s = s
self.w = w
self.u = u
self.d = d
def roll(self,dir):
if (dir == "N"):
tmp = self.n
self.n = self.u
self.u = self.s
self.s = self.d
self.d = tmp
elif (dir == "E"):
tmp = self.e
self.e = self.u
self.u = self.w
self.w = self.d
self.d = tmp
elif (dir == "S"):
tmp = self.s
self.s = self.u
self.u = self.n
self.n = self.d
self.d = tmp
elif (dir == "W"):
tmp = self.w
self.w = self.u
self.u = self.e
self.e = self.d
self.d = tmp
spots = raw_input().split()
operations = raw_input()
dice = Dice(*spots)
for i in operations:
dice.roll(i)
print dice.u | 1 | 239,011,443,958 | null | 33 | 33 |
from fractions import gcd
A, B = map(int, input().split())
print((A * B) // gcd(A, B))
| import math
A,B = map(int,input().split())
#print(math.gcd(A,B))
C = A*B //(math.gcd(A,B))
print(C)
| 1 | 113,091,466,464,860 | null | 256 | 256 |
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
def popcount(n):
if n == 0:
return 0
return 1 + popcount(n % bin(n).count("1"))
def main():
N = int(input())
X = input().strip()
x1 = 0
xc = bin(int(X, 2)).count("1")
if xc == 1:
x2 = -1
else:
x2 = 0
for i in range(N):
if X[-1 - i] == '1':
x1 += pow(2, i, xc + 1)
if x2 != -1:
x2 += pow(2, i, xc - 1)
for i in range(N):
if X[i] == '0':
print(1 + popcount((x1 + pow(2, N - i - 1, xc + 1)) % (xc + 1)))
else:
if x2 == -1:
print(0)
else:
print(1 + popcount((x2 - pow(2, N - i - 1, xc - 1) + xc - 1) % (xc - 1)))
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
X = input()
cnt_init = X.count("1")
x_init = int(X, 2)
a = x_init % (cnt_init + 1)
if cnt_init - 1 != 0:
b = x_init % (cnt_init - 1)
for i in range(n):
if X[i] == "0":
cnt = cnt_init + 1
x = (a + pow(2, (n - i - 1), cnt)) % cnt
res = 1
else:
cnt = cnt_init - 1
if cnt != 0:
x = (b - pow(2, (n - i - 1), cnt)) % cnt
res = 1
else:
x = 0
res = 0
while x:
cnt = bin(x).count("1")
x %= cnt
res += 1
print(res)
if __name__ == '__main__':
resolve()
| 1 | 8,167,540,763,520 | null | 107 | 107 |
time=1
n=int(input())
A=[[] for i in range(n)]
d=[0 for i in range(n)]
f=[0 for i in range(n)]
for i in range(n):
a=list(map(int,input().split()))
for j in range(a[1]):
A[i].append(a[2+j]-1)
def dfs(q,num):
global d,f,time
d[num]=time
for nx in q[num]:
if d[nx]==0:
time+=1
dfs(q,nx)
time+=1
f[num]=time
for i in range(n):
if d[i]==0:#unvisit
dfs(A,i)
time+=1
for i in range(n):
print(i+1,d[i],f[i])
| N=int(input())
L=[[10**9]for i in range(N+1)]
for i in range(N):
l=list(map(int,input().split()))
for j in range(l[1]):
L[i+1].append(l[2+j])
#print(L)
for i in range(N+1):
L[i].sort(reverse=True)
#print(L)
ans=[]
for i in range(N+1):
ans.append([0,0])
from collections import deque
Q=deque()
cnt=1
for i in range(N):
Q.append([0,N-i])
for i in range(10**7):
if len(Q)==0:
break
q0,q1=Q.pop()
#print(q0,q1)
if q1!=10**9:
if ans[q1][0]==0:
ans[q1][0]=cnt
cnt+=1
for j in L[q1]:
Q.append([q1,j])
else:
ans[q0][1]=cnt
cnt+=1
#print(ans,Q)
for i in range(1,N+1):
print(i,ans[i][0],ans[i][1])
| 1 | 2,967,330,928 | null | 8 | 8 |
import collections, sys
sys.setrecursionlimit(100005)
N = int(input())
A = [int(_) for _ in input().split()]
INF = float('inf')
memo = collections.defaultdict(lambda: INF)
def c(start, res):
if memo[start, res] != INF:
return memo[start, res]
elif 2 * res - 1 > N - start:
memo[start, res] = -INF
elif start >= N:
memo[start, res] = -INF
elif res > 1:
memo[start, res] = max(A[start] + c(start + 2, res - 1),
c(start + 1, res), c(start + 2, res))
else:
memo[start, res] = max(A[start], c(start + 1, res))
return memo[start, res]
print(c(0, N // 2))
| import sys
input = sys.stdin.readline
n = int(input())
robots = [tuple(map(int, input().split())) for _ in range(n)]
robots.sort(key=(lambda robo: robo[0] + robo[1]))
z = -float('inf')
ans = 0
for x, l in robots:
if z <= x - l:
ans += 1
z = x + l
print(ans)
| 0 | null | 64,032,485,892,098 | 177 | 237 |
mod = 1000000007
n = int(input())
ans = pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod)
print(ans % mod)
| S=input()
INF=10**12
# dp[i][j]: 下からi桁目まで決めた時の、くりさがりがjの時の最小値
# i: 0~N, j:2値, 前の桁でくりさがりが発生している場合に1
dp=[[INF for _ in range(2)] for _ in range(10**6+5)]
S=S[::-1]
S+="0"
N=len(S)
dp[0][0]=0
# 配るDP, 今の状態を見て次の状態を決めていく
for i in range(N):
for j in range(2):
# x: i桁目の数字, 前の桁でくりさがりが発生している場合はインクリメント
x=int(S[i])
x+=j
for a in range(10):
ni=i+1
nj=0
b=a-x
if b<0:
nj=1
b+=10
dp[ni][nj]=min(dp[ni][nj], dp[i][j]+a+b)
print(dp[N][0]) | 0 | null | 37,096,323,815,210 | 78 | 219 |
print(input()[:3]) | # -*- coding: utf-8 -*-
import sys
import os
s = input().strip()
N = int(input())
for i in range(N):
lst = input().split()
command = lst[0]
if command == 'replace':
a = int(lst[1])
b = int(lst[2])
p = lst[3]
s = s[:a] + p + s[b+1:]
elif command == 'reverse':
a = int(lst[1])
b = int(lst[2])
part = s[a:b+1]
part = part[::-1]
s = s[:a] + part + s[b+1:]
elif command == 'print':
a = int(lst[1])
b = int(lst[2])
print(s[a:b+1])
else:
print('error')
#print('s', s) | 0 | null | 8,504,014,240,240 | 130 | 68 |
print((int(input())/3)**3)
| l = int(input())
ll = float(l)
a=0
b=0
c=0
if(ll%3 == 0):
a=ll/3
b=ll/3
c=ll/3
else:
a=ll/3
b=a
c=ll-a-b
print(a*b*c) | 1 | 47,237,822,745,370 | null | 191 | 191 |
from collections import Counter
from itertools import accumulate
N, K = map(int,input().split())
A = list(map(int,input().split()))
d = Counter()
A = [0] + list(accumulate(A))
A = [a % K for a in A]
ans = 0
for i in range(N+1):
ans += d[(A[i]-i) % K]
d[(A[i]-i) % K] += 1
if i-K+1 >= 0:
d[(A[i-K+1] - (i-K+1)) % K] -= 1
print(ans) | def shaku(K,lists):
ans=0
SUMS=0
index=0
for l in range(len(lists)):
while index < l or index< len(lists) and SUMS +lists[index] < K:
SUMS += lists[index]
index+= 1
ans += index-l
SUMS -= lists[l]
return ans
n,k=map(int,input().split())
lists=list(map(int,input().split()))
uselist=[0 for i in range(n+1)]
for i in range(n):
uselist[i+1]=(uselist[i]+lists[i])
anslist=[0 for i in range(n+1)]
for j in range(1,n+1):
anslist[j]=(uselist[j]-j)%k
dic={}
for i in range(n+1):
if anslist[i] in dic.keys():
dic[anslist[i]].append(i+1)
else:
dic[anslist[i]]=[1+i]
#answerに答えを格納することにする
answer=0
for lis in dic.values():
sublis=[lis[0]]
for a in range(1,len(lis)):
sublis.append(lis[a]-lis[a-1])
P=shaku(k,sublis)
for some in lis:
if some<k:
answer-=1
answer+=P
print(answer) | 1 | 137,600,093,485,088 | null | 273 | 273 |
def main():
N = int(input())
S = input()
ans = 0
for i in range(len(S) - 1):
if S[i:i + 3] == 'ABC':
ans += 1
print(ans)
main() | inp=input()
num = [int(x) for x in inp.split(" ")]
print(num[0]*num[1]) | 0 | null | 57,751,096,019,152 | 245 | 133 |
import sys
from pprint import pprint
R,C,K=map(int,input().split())
grid=[[0]*C for _ in range(R+1)]
for _ in range(K):
r,c,v=map(int,input().split())
grid[r][c-1]=v
for i in range(1,R+1):
cell=[0]*4
for j in range(C):
cell[0]=max(cell[0],grid[i-1][j])
for k in range(2,-1,-1):
cell[k+1]=max(cell[k+1],cell[k]+grid[i][j])
grid[i][j]=max(cell)
print(grid[-1][-1])
| R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
a,b,c=map(int,input().split())
a-=1
b-=1
l[a][b]=c
dp=[[0] * C for i in range(R)]
for i in range(R):
kdp=[0]*4
for j in range(C):
if i>0:
kdp[0]=max(kdp[0],dp[i-1][j])
for k in range(2,-1,-1):
kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
dp[i][j]=max(dp[i][j],kdp[k+1])
print(dp[R-1][C-1]) | 1 | 5,563,093,744,648 | null | 94 | 94 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(K-1,N-1):
a=A[i-K+1]
b=A[i+1]
if(a<b):
print('Yes')
else:
print('No') | n,m=[int(x) for x in input().split()]
A=[[0 for i in range(m)] for i in range(n)]
vector=[0 for i in range(m)]
result=[0 for i in range(n)]
for i in range(n):
A[i]=[int(x) for x in input().split()]
for i in range(m):
vector[i]=int(input())
for i in range(n):
for j in range(m):
result[i] += A[i][j]*vector[j]
for _ in result:
print(_) | 0 | null | 4,092,373,965,500 | 102 | 56 |
import math
h,w = map(int,input().split())
if h == 1 or w == 1:
print(1)
else:
print(math.ceil(h/2*w))
| h,w = map(int,input().split())
if h == 1 or w == 1:
print(1)
elif (w*h) % 2 == 0:
print((w*h)//2)
elif (w*h) % 2 == 1:
print(((w*h)//2)+1)
| 1 | 50,886,667,090,080 | null | 196 | 196 |
n = int(input())
x = 7
ans = 1
#print(7%1)
for i in range(3*n):
if x%n==0:
break
ans+=1
x= x*10 + 7
x=x%n
if ans < 3*n:
print(ans)
else:
print(-1) | N, M = map(int, input().split())
coins = map(int, input().split())
dp = [0] + [50001 for i in range(N)]
for coin in coins:
for index in range(N-coin+1):
dp[index+coin] = min(dp[index+coin], dp[index]+1)
print(dp[N])
| 0 | null | 3,086,067,249,158 | 97 | 28 |
N=int(input())
K=int(input())
string = str(N)
digits = len(string)
#dp[i][j][k]=と同じ桁数の整数で上からi桁目までで0でない数字がj個あるものの個数
#k=0: i桁目まで見てN未満が確定, k=1: 未確定
dp = [[[0]*2 for _ in range(K+1)] for __ in range(digits+1)]
#初期状態
dp[0][0][1] = 1
for i in range(digits):
d = int(string[i])
ni = i+1
for j in range(K+1):
for k in range(2):
for nd in range(10):
nk = 1 if k == 1 and nd == d else 0
if k == 1 and nd > d: break
nj = j + (1 if nd != 0 else 0)
if nj > K: continue
dp[ni][nj][nk] += dp[i][j][k]
print(dp[digits][K][0] + dp[digits][K][1])
|
import random
s = input()
start = random.randint(0,len(s)-3)
nickname = s[start:start+3]
print(nickname)
| 0 | null | 45,443,007,044,380 | 224 | 130 |
n = int(input())
ls = list(map(int, input().split()))
xor_sum = 0
for a in ls:
xor_sum ^=a
ans = []
for i in range(n):
ans.append(str(xor_sum^ls[i]))
print(" ".join(ans)) | import math
n = int(input())
a = math.pi
print(2*n*a) | 0 | null | 22,066,438,905,200 | 123 | 167 |
MOD = 10 ** 9 + 7
def inv(x):
return pow(x, MOD - 2, MOD)
def gen_fact(n):
fact = [1] * (n + 1)
for i in range(2, n + 1):
fact[i] = fact[i - 1] * i % MOD
return fact
def binom(n, k, fact):
assert 0 <= k <= n
return fact[n] * inv(fact[k]) * inv(fact[n - k]) % MOD
def count(n, k, fact):
n -= 3 * k
return binom(n + k - 1, k - 1, fact)
if __name__ == '__main__':
s = int(input())
fact = gen_fact(s)
res = 0
for k in range(1, s // 3 + 1):
res += count(s, k, fact)
print(res % MOD) | s = input()
if s=='hi' or s=='hihi' or s=='hihihi' or s=='hihihihi' or s=='hihihihihi' :
print("Yes")
else:
print("No") | 0 | null | 28,138,279,798,980 | 79 | 199 |
def main():
n, m, l = tuple(map(int, input().split()))
matA = [[0 for j in range(m)] for i in range(n)]
matB = [[0 for k in range(l)] for j in range(m)]
matC = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
tmp = list(map(int, input().split()))
for j in range(m):
matA[i][j] = tmp[j]
for j in range(m):
tmp = list(map(int, input().split()))
for k in range(l):
matB[j][k] = tmp[k]
for i in range(n):
for k in range(l):
for j in range(m):
matC[i][k] += matA[i][j] * matB[j][k]
for i in range(n):
for k in range(l):
if k == l-1:
print(matC[i][k])
else:
print(matC[i][k], end=' ')
if __name__ == '__main__':
main()
| N = int(input())
A = list(map(int, input().split()))
s = 0
height = 0
for a in A:
height = max(height, a)
s += height - a
print(s) | 0 | null | 3,043,106,503,360 | 60 | 88 |
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for i in range(m)]
hb = [0] * h
wb = [0] * w
for i in range(m):
hb[hw[i][0]-1] += 1
wb[hw[i][1]-1] += 1
max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w
count = hb.count(max_h) * wb.count(max_w)
for i in range(m):
if hb[hw[i][0]-1] == max_h and wb[hw[i][1]-1] == max_w:
count -= 1
if count <= 0:
ans -= 1
print(ans) | N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
S = input()
if S == "AC":
AC += 1
elif S == "WA":
WA += 1
elif S == "TLE":
TLE += 1
else:
RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE)) | 0 | null | 6,615,639,074,720 | 89 | 109 |
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())
s = input()
s = s[::-1]
loc = 0
anslist=[]
while True:
if loc >= n-m:
anslist.append(n-loc)
break
quit()
next = m
while s[loc+next]=="1":
next-=1
if next == 0:
print(-1)
quit()
anslist.append(next)
loc+=next
ans=anslist[::-1]
ans = list(map(str, ans))
print(" ".join(ans)) | 1 | 139,005,353,940,270 | null | 274 | 274 |
X,Y=list(map(int, input().split()))
a=(2*X-Y)//3
b=(2*Y-X)//3
if not (2*a+b==X and a+2*b==Y and a>=0 and b>=0):
print(0)
exit()
C=10**9+7
A=1
B=1
D=1
for i in range(a):
A*=i+1
A=A%C
for j in range(b):
B*=j+1
B=B%C
for k in range(a+b):
D*=k+1
D=D%C
D*=pow(A,C-2,C)
D*=pow(B,C-2,C)
print(D%C) | def comb(n, m, p=10**9+7):
if n < m:
return 0
if n < 0 or m < 0:
return 0
m = min(m, n-m)
top = bot = 1
for i in range(m):
top = top*(n-i) % p
bot = bot*(i+1) % p
bot = pow(bot, p-2, p)
return top*bot % p
x, y = map(int, input().split())
j = 2*x-y
if j % 3:
print(0)
exit()
j //= 3
i = x - 2*j
if i < 0 or j < 0:
print(0)
exit()
ans = comb(i+j, i)
print(ans)
| 1 | 149,503,112,349,500 | null | 281 | 281 |
from math import sqrt
import itertools
N = int(input())
dis = [input().split() for i in range(N)]
lst = [x for x in range(N)]
p_lst = list(itertools.permutations(lst))
ans = 0
for i in p_lst:
for j in range(N-1):
ans += sqrt((int(dis[i[j]][0]) - int(dis[i[j+1]][0]))**2
+ (int(dis[i[j]][1]) - int(dis[i[j+1]][1]))**2)
print(ans/len(p_lst)) | import math
from itertools import permutations
N=int(input())
XYlist=[]
indexlist=[i for i in range(N)]
for _ in range(N):
XYlist.append(tuple(map(int,input().split())))
ans=0
num=0
for indexes in permutations(indexlist,N):
for i in range(N-1):
ans+=math.sqrt((XYlist[indexes[i]][0]-XYlist[indexes[i+1]][0])**2+
(XYlist[indexes[i]][1]-XYlist[indexes[i+1]][1])**2)
num+=1
print(ans/num) | 1 | 148,234,288,323,328 | null | 280 | 280 |
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
T = []
for q in range(Q):
T.append(list(map(int, input().split())))
A = list(combinations_with_replacement(list(range(1, M+1)), N))
Alist = [list(a) for a in A]
#print(Alist)
Max = 0
for a in Alist:
cost = 0
for t in T:
if a[t[1]-1] - a[t[0]-1] == t[2]:
cost += t[3]
if cost > Max:
Max = cost
print(Max) | import math
A,B = map(int,input().split())
#print(math.gcd(A,B))
C = A*B //(math.gcd(A,B))
print(C)
| 0 | null | 70,276,387,705,810 | 160 | 256 |
import itertools as itr
def call(n):
def devided_3(x):
return x % 3 == 0
def has_3(x):
return '3' in str(x)
data = filter(lambda x: devided_3(x) or has_3(x), range(1, n+1))
[print(' {0}'.format(i), end='') for i in data]
print()
if __name__ == '__main__':
n = int(input())
call(n) | n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(i+1, n):
for k in range(j+1, n):
_lst = [l[i], l[j], l[k]]
if len(set(_lst)) == 3:
_max = max(_lst)
_lst.remove(_max)
if _max < sum(_lst):
ans += 1
print(ans)
| 0 | null | 2,973,090,678,728 | 52 | 91 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, *A = map(int, read().split())
C = [0] * N
for a in A:
C[a-1] += 1
print(*C, sep='\n')
return
if __name__ == '__main__':
main()
| N = int(input())
ls = list(map(int,input().split()))
cnt = [0] * (N+1)
for i in range(N-1):
cnt[ls[i]] += 1
for i in range(1,N+1):
print(cnt[i]) | 1 | 32,448,210,071,802 | null | 169 | 169 |
import itertools
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_acc = [0] + list(itertools.accumulate(a))
b_acc = [0] + list(itertools.accumulate(b))
ans = 0
for i in range(n+1):
if k - a_acc[i] >= 0:
ans = max(ans, i + bisect.bisect(b_acc, k - a_acc[i])-1)
print(ans)
| N = int(input())
S = input()
slime = S[0]
for i in range(1, N):
if S[i] != slime[-1]:
slime += S[i]
print(len(slime))
| 0 | null | 90,352,648,621,342 | 117 | 293 |
import sys
r=sys.stdin.readline
N,M=map(int,r().split())
city=[[] for _ in range(N+1)]
for _ in range(M):
a,b=map(int,r().split())
city[a].append(b)
city[b].append(a)
check=[True]+[False]*(N)
def dfs(v):
stack=[v]
while stack:
cur=stack.pop()
check[cur]=True
for v in city[cur]:
if not check[v]:
stack.append(v)
cnt=0
for i in range(1,N+1):
if not check[i]:
dfs(i)
cnt+=1
print(cnt-1) | N = int(input())
a = list(map(int,input().split()))
dic = {}
for nums in a:
if nums in dic:
dic[nums] += 1
else:
dic[nums] = 1
ma = 0
for keys in dic:
ma = max(ma,dic[keys])
if ma == 1:
print("YES")
else:
print("NO") | 0 | null | 38,095,744,503,912 | 70 | 222 |
n, m = map(int, input().split())
print('Yes' if m >= n else 'No') |
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b,m=n1()
A=n1()
B=n1()
X=n3(m)
A2=sorted(A)
B2=sorted(B)
ans=A2[0]+B2[0]
for a,b,c in X:
if A[a-1]+B[b-1]-c<ans:
ans=A[a-1]+B[b-1]-c
print(ans) | 0 | null | 68,508,569,685,110 | 231 | 200 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
n = int(input())
s = input()
if (n % 2 != 0):
print("No")
exit()
for i in range(n//2):
if (s[i] != s[n//2 + i]):
print("No")
exit()
print("Yes")
| d, t, s = map(int, input().split())
print('Yes') if d / s <= t else print('No') | 0 | null | 74,799,174,662,588 | 279 | 81 |
S = int(input())
s = S%60
m = (S-s)/60%60
h = S/3600%24
answer = str(int(h))+":"+str(int(m))+":"+str(s)
print(answer)
| s = int(input())
h = s // 3600
m = s % 3600 // 60
s = s % 60
print(f'{h}:{m}:{s}')
| 1 | 332,540,262,460 | null | 37 | 37 |
def run(n, _in_list):
'''
'''
is_doublet_count = 0
for x in _in_list:
if is_doublet_count == 3:
break
_in = list(x)
if _in[0] ==_in[1]:
is_doublet_count += 1
else:
is_doublet_count = 0
print('Yes' if is_doublet_count >= 3 else 'No')
if __name__ == '__main__':
n = int(input())
_in_list = [map(int, input().split()) for _ in range(n)]
run(n, _in_list) | def main():
import sys
from copy import deepcopy
input = sys.stdin.readline
R, C, K = [int(x) for x in input().strip().split()]
G = [[0] * (C+1) for r in range(R+1)]
for k in range(K):
r, c, v = [int(x) for x in input().strip().split()]
G[r][c] = v
# for r in range(R+1):
# print(G[r])
ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
for r in range(1, R+1):
for c in range(1, C+1):
ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
for i in range(1, 4):
ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])
print(max(ans[R%2][-1]))
if __name__ == '__main__':
main()
| 0 | null | 4,000,230,842,608 | 72 | 94 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
r = int(readline())
print(r ** 2)
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 1 << 60
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, K, LR):
M = 998244353
memo = [0] *(N+2)
memo[1] = 1
memo[1+1] = -1
for i in range(1, N+1):
memo[i] += memo[i-1]
memo[i] %= M
for l, r in LR:
ll = min(N+1, i+l)
rr = min(N+1, i+r+1)
memo[ll] += memo[i]
memo[ll] %= M
memo[rr] -= memo[i]
memo[rr] %= M
return memo[N]
def main():
N, K = read_int_n()
LR = [read_int_n() for _ in range(K)]
print(slv(N, K, LR))
if __name__ == '__main__':
main()
| 0 | null | 74,038,595,295,072 | 278 | 74 |
# #
# author : samars_diary #
# 16-09-2020 │ 18:28:11 #
# #
import sys, os.path, math
#if(os.path.exists('input.txt')):
#sys.stdin = open('input.txt',"r")
#sys.stdout = open('output.txt',"w")
sys.setrecursionlimit(10 ** 5)
mod = 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))
#print=sys.stdout.write
def solve():
a=ii();print((pow(10,a,mod)+pow(8,a,mod)-2*pow(9,a,mod))%mod)
for _ in range(1):
solve() | a = [chr(i) for i in range(65, 65+26)]
n = int(input())
s = input()
ans = ''
for i in s:
ans += (a[(a.index(i)+n)%26])
print(ans) | 0 | null | 68,891,936,963,158 | 78 | 271 |
class ReversingNumbers:
def output(self, a):
s = ""
a.reverse()
for i in range(len(a)-1):
s += "%d " % (a[i])
s += "%d" % (a[len(a)-1])
print s
if __name__ == "__main__":
rn = ReversingNumbers()
raw_input()
a = map(int, raw_input().split())
rn.output(a) | n = input()[::-1]
dp = [[0, 0] for i in range(len(n) + 1)]
dp[0][1] = 1
for i in range(len(n)):
dp[i + 1][0] = min(dp[i][0] + int(n[i]), dp[i][1] - int(n[i]) + 10)
dp[i + 1][1] = min(dp[i][0] + int(n[i]) + 1, dp[i][1] - int(n[i]) + 9)
print(dp[len(n)][0]) | 0 | null | 35,892,926,282,742 | 53 | 219 |
import math
A, B, C = map(int, input().split())
K = int(input())
count = 0
ab = int(math.log2(A/B)+1)
bc = int(math.log2((B*(2**ab))/C)+1)
if ab + bc <= K:
print('Yes')
else:
print('No')
| #
# m_solutions2020 b
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """7 2 5
3"""
output = """Yes"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 4 2
3"""
output = """No"""
self.assertIO(input, output)
def resolve():
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
if A >= B:
B *= 2
elif B >= C:
C *= 2
if A < B < C:
print("Yes")
break
else:
print("No")
if __name__ == "__main__":
# unittest.main()
resolve()
| 1 | 6,881,115,496,076 | null | 101 | 101 |
import math
N = int(input())
ans = math.ceil(N / 2.0)
print(ans)
| def main():
n = int(input())
s = input()
ans = 0
for i in range(n-2):
if s[i]+s[i+1]+s[i+2] == "ABC":
ans += 1
print(ans)
main() | 0 | null | 79,097,459,529,380 | 206 | 245 |
a, b = map(int, input().split())
print(a*b if 0 < a < 10 and 0 < b < 10 else -1) | N=int(input())
L=[]
# xでソート
#でソート
#min, max
for i in range(N):
x,y=map(int, input().split())
L.append([x+y,x-y])
L=sorted(L)
ans=abs(L[0][0]-L[-1][0])
L=sorted(L, key=lambda x: x[1])
ans=max(ans, abs(L[0][1]-L[-1][1]))
print(ans) | 0 | null | 81,080,300,578,340 | 286 | 80 |
# Pythonのスライスは最後が開区間だから癖がある
t = input()
for i in range(int(input())):
cmd = list(input().split())
cmd[1] = int(cmd[1])
cmd[2] = int(cmd[2])
if cmd[0] == "print":
print(t[cmd[1] : cmd[2]] + t[cmd[2]])
elif cmd[0] == "reverse":
tmp = t[cmd[1] : cmd[2]] + t[cmd[2]]
tmp = tmp[::-1]
t = t[:cmd[1]] + tmp + t[cmd[2]+1:]
elif cmd[0] == "replace":
t = t[:cmd[1]] + cmd[3] + t[cmd[2]+1:]
| h, n = map(int, input().split())
a = list(map(int, input().split()))
x = sum(a)
if (h - x) <= 0:
print('Yes')
else:
print('No') | 0 | null | 39,835,876,281,860 | 68 | 226 |
'''
Problem Link - https://atcoder.jp/contests/abc176/tasks/abc176_a
'''
from sys import stdin,stdout
from math import *
from collections import *
mod = 1000000007
def gcd(a,b):
while b:
a,b = b,a%b
return a
def lcm(a,b): return (a*b) // gcd(a,b)
def set_bits(X):
c = 0
while X:
X &= (X-1);c += 1
return c
def compute_MOD(N,M): return (N%M + M) % M
def get_array(): return list(map(int, stdin.readline().split()))
def get_ints(): return map(int, stdin.readline().split())
def get_int(): return int(stdin.readline())
def get_input(): return stdin.readline().strip()
def main():
N,X,T = get_ints()
stdout.write(str(ceil(N/X)*T)+'\n')
if __name__ == "__main__":
main() | N, M = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
A = sorted(A, reverse=True)
ans = 'Yes'
for i in range(M):
if A[i]*(4*M) < s:
ans = 'No'
break
print(ans) | 0 | null | 21,370,801,328,390 | 86 | 179 |
size = int(input())
element = list(map(int,input().split()))
print(" ".join(map(str,element)))
for i in range(1,len(element)):
v = element[i]
j = i-1
while j >=0 and element[j] > v:
element[j+1] = element[j]
j -=1
element[j+1] = v
print(" ".join(map(str,element))) | import bisect
def bisect_right_reverse(a, x):
'''
reverseにソートされたlist aに対してxを挿入できるidxを返す。
xが存在する場合には一番右側のidx+1となる。
'''
if a[0] < x:
return 0
if x <= a[-1]:
return len(a)
# 二分探索
ok = len(a) - 1
ng = 0
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if a[mid] < x:
ok = mid
else:
ng = mid
return ok
def bisect_left_reverse(a, x):
'''
reverseにソートされたlist aに対してxを挿入できるidxを返す。
xが存在する場合には一番左側のidxとなる。
'''
if a[0] <= x:
return 0
if x < a[-1]:
return len(a)
# 二分探索
ok = len(a) - 1
ng = 0
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if a[mid] <= x:
ok = mid
else:
ng = mid
return ok
def main2():
n = int(input())
l=[int(i) for i in input().split()]
l.sort(reverse = True)
res = 0
for i in range(n-1):
for j in range(i+1, n-1):
#index がj以降で k < c を満たすcで一番小さいc'を探す
#index(c')-j - 1が三角形の条件を満たす
nibu = l[j+1:]
k = max(l[i]-l[j],l[j]-l[i])
left=bisect_left_reverse(nibu,k)
res += left
print(res)
if __name__ == '__main__':
main2()
| 0 | null | 86,189,934,847,070 | 10 | 294 |
import math
import sys
import os
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
MOD = 998244353
# もらうDP(forcus on destination), 区間の和を足しこむ=累積和
N,K = LI()
LRs = [LI() for _ in range(K)]
dp = [0]*(N+1)
cum = [0]*(N+1)
dp[1] = 1
cum[1] = 1
for i in range(2, N+1):
for j in range(K):
l, r = LRs[j]
start = max(0,i-r-1)
end = max(0,i-l)
dp[i] += cum[end] - cum[start]
dp[i] %= MOD
# 累積和を更新
cum[i] = (cum[i-1] + dp[i]) % MOD
ans = dp[N]
print(ans) | n, k = map(int, input().split())
ps = []
MOD = 998244353
s = set()
for _ in range(k):
l,r = map(int, input().split())
ps.append([l,r])
dp = [0] * (n+1)
dp[0] = 1
acc = [0,1]
for i in range(1,n):
for l, r in ps:
dp[i] += acc[max(0,i-l+1)] - acc[max(0,i-r)]
acc.append((acc[i] + dp[i])%MOD)
print(dp[n-1]%MOD)
| 1 | 2,673,268,902,502 | null | 74 | 74 |
import sys
input = sys.stdin.readline
def main():
ans = 'No'
N = int(input())
c = 0
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
c += 1
if c >= 3:
ans = 'Yes'
break
else:
c = 0
print(ans)
if __name__ == '__main__':
main() | x, y = map(int, input().split())
ans = 4 if x == 1 and y == 1 else 0
ans += max(0, 4-x)+max(0, 4-y)
print(ans*100000)
| 0 | null | 71,719,163,478,388 | 72 | 275 |
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = []
for i in range(N):
x,l = X[i]
A.append((x-l,x+l))
B1 = sorted(A,key=lambda x:x[1])
B1 = [(B1[i][0],B1[i][1],i) for i in range(N)]
B2 = sorted(B1,key=lambda x:x[0])
hist = [0 for _ in range(N)]
cnt = 0
i = 0
for k in range(N):
if hist[k]==0:
r = B1[k][1]
hist[k] = 1
cnt += 1
while i<N:
l,j = B2[i][0],B2[i][2]
if hist[j]==1:
i += 1
continue
if l<r:
hist[j] = 1
i += 1
else:
break
print(cnt) | for i in range(input()):
q = map(int,raw_input().split())
q.sort()
a = "YES" if q[0]**2 + q[1]**2 == q[2]**2 else "NO"
print a | 0 | null | 45,072,514,984,870 | 237 | 4 |
n = int(input())
arr = list(map(int, input().split()))
s = sum(arr)
d = dict()
for i in arr:
if (i not in d):
d[i] = 1
else:
d[i] += 1
q = int(input())
for i in range(q):
b, c = map(int, input().split())
if (b in d):
s -= b * d[b]
s += c * d[b]
if (c not in d):
d[c] = d[b]
else:
d[c] += d[b]
d.pop(b)
print(s) | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = sum(a)
count = Counter(a)
for _ in range(q):
b,c = map(int, input().split())
count[c] += count[b]
ans -= b*count[b]
ans += c*count[b]
count[b] = 0
print(ans) | 1 | 12,272,173,537,260 | null | 122 | 122 |
import math
import sys
sys.setrecursionlimit(10**9)
MOD = 10**9+7
n, k = map(int, input().split())
k = min(k, n-1)
fact = [1]
for i in range(1, 10**6):
fact.append((fact[i-1]*i)%MOD)
inv = [None]*10**6
def inv_fact(n):
if inv[n] == None:
inv[n] = pow(fact[n], MOD-2, MOD)
return inv[n]
def comb(n, r):
return (fact[n]*inv_fact(n-r)*inv_fact(r))%MOD
ans = 0
for i in range(k+1):
ans = (ans + comb(n-1, i)*comb(n, i))%MOD
print(ans) | import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
SIZE=4*10**5+1; MOD=10**9+7 #998244353 #ここを変更する
SIZE += 1
inv = [0]*SIZE # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD
fac[i] = fac[i-1]*i%MOD
finv[i]= finv[i-1]*inv[i]%MOD
def choose(n,r): # nCk mod MOD の計算
if 0 <= r <= n:
return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
else:
return 0
def resolve():
n, k = lr()
ans = choose(2*n-1, n)
if n-1 > k:
for i in range(1, n-k):
ans -= choose(n, i)*choose(n-1, n-i)
ans %= MOD
print(ans)
resolve() | 1 | 67,253,146,695,420 | null | 215 | 215 |
A, B, K = map(int, input().split())
if A < K:
K = K - A
A = 0
elif A == K:
A = 0
K = 0
else: # K < A
A = A - K
K = 0
if B < K:
K = K - B
B = 0
elif B == K:
B = 0
K = 0
else: # K < B
B = B - K
K = 0
print(A, B)
| i = range(1,10)
for i in ['%dx%d=%d' % (x,y,x*y) for x in i for y in i]:
print i | 0 | null | 52,196,217,265,188 | 249 | 1 |
n = int(input())
s = [input() for _ in range(n)]
uniq = set(s)
print(len(uniq)) | import collections
N = int(input())
S = []
for i in range(N):
s = input()
S.append(s)
c = collections.Counter(S)
values, counts = zip(*c.most_common())
print(len(values)) | 1 | 30,408,426,501,958 | null | 165 | 165 |
N = int(input())
A = [int(num) for num in input().split()]
S = {-A[0] : 1}
ans = 0
for i in range(1,N):
ans += S.get(A[i]-i, 0)
S[-A[i]-i] = S.get(-A[i]-i, 0) + 1
print(ans) | n=int(input())
A=[]
B=[]
for i in range(n):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if n%2==1:
print(B[n//2]-A[n//2]+1)
else:
print(int(((B[n//2]+B[n//2-1])/2-(A[n//2]+A[n//2-1])/2)*2+1))
| 0 | null | 21,724,927,893,820 | 157 | 137 |
import sys
n = int(sys.stdin.readline())
xs = []
for _ in range(n):
v = [int(x) for x in sys.stdin.readline().split(" ")]
xs.append(v)
xs.sort(key=lambda x: x[0])
if n % 2 == 0:
m1 = n // 2 - 1
m2 = m1 + 1
a1 = xs[m1][0]
a2 = xs[m2][0]
xs.sort(key=lambda x: x[1])
b1 = xs[m1][1]
b2 = xs[m2][1]
a = (a1 + a2)
b = (b1 + b2)
c = (b - a) + 1
#print(m1, m2, a1, a2, b1, b2, "*", a, b, c)
print(c)
else:
m = (n + 1) // 2 - 1
a = xs[m][0]
xs.sort(key=lambda x: x[1])
b = xs[m][1]
c = b - a + 1
#print(m, a, b, c)
print(c) | a, b = map(int, input().split(' '))
if a < b:
print('a < b')
elif a > b:
print('a > b')
else:
print('a == b')
| 0 | null | 8,777,130,465,272 | 137 | 38 |
S = input()
if S[-1] == "s":
S += "es"
else:
S += "s"
print(S) | S = input()
n = len(S)
S_a = list(S)
if S[n-1] == 's' :
print(S + 'es')
else :
print(S + 's')
| 1 | 2,418,998,276,652 | null | 71 | 71 |
s = list(input())
k = int(input())
if list(s[0]*len(s))==s:
#print('a')
print(len(s)*k//2)
exit()
res = [1]
for i in range(len(s)-1):
if s[i]==s[i+1]:
res[-1] += 1
else:
res.append(1)
ans = 0
for i in res:
ans += (i//2)*k
if s[0]==s[-1]:
diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
ans += diff*(k-1)
print(ans)
| from itertools import groupby
def solve():
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
if S[0] == S[-1] and K > 1:
if len(a) == 1:
return a[0] * K // 2
else:
ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
ans += sum(n // 2 for n in a[1:-1]) * K
return ans
else:
return sum(n // 2 for n in a) * K
print(solve()) | 1 | 175,975,059,557,590 | null | 296 | 296 |
din = map(int, raw_input().split())
print ((din[1])/din[2] - (din[0]-1)/din[2]) | L, R, d = map(int, input().split())
if L%d == 0 or R%d == 0 :
print((R-L)//d + 1)
else:
print((R - L)//d) | 1 | 7,608,954,668,798 | null | 104 | 104 |
count = 0
INF = float('inf')
def merge(A, left, mid, right):
global count
L = A[left:mid] + [INF]
R = A[mid:right] + [INF]
i, j = 0, 0
for k in range(left, right):
count +=1
if L[i] <= R[j]:
A[k] = L[i]
i = i+1
else:
A[k] = R[j]
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)
#right は部分配列の末尾+1 の要素を指す。
n = int(input())
A = list(map(int, input().split()))
mergeSort(A, 0, n)
for i in range(n):
if i>0:
print(" ", end="")
print(A[i], end="")
print()
print(count)
| count=0
def mg(S,left,right,mid):
global count
L=[]
L=S[left:mid]
L.append(9999999999)
R=[]
R=S[mid:right]
R.append(9999999999)
r=0
l=0
for i in range(left,right):
count=count+1
if L[l]<=R[r]:
S[i]=L[l]
l=l+1
else:
S[i]=R[r]
r=r+1
def ms(S,left,right):
if right>left+1:
mid=(right+left)//2
ms(S,left,mid)
ms(S,mid,right)
mg(S,left,right,mid)
n=int(input())
S=[]
S=input().split()
S=[int(u) for u in S]
ms(S,0,n)
for i in range(0,n-1):
print(S[i],end=" ")
print(S[n-1])
print(count)
| 1 | 113,677,251,600 | null | 26 | 26 |
s=input()
i=s[-1]
if i=='2' or i=='4' or i=='5' or i=='7' or i=='9':
print('hon')
elif i=='0' or i=='1' or i=='6' or i=='8':
print('pon')
else:
print('bon') | def f(a,b):
if (b == 0): return a
a = a * 1.05
if (a%1000 != 0): a = a - a%1000 + 1000
return f(a,b-1)
print int(f(100000,input())) | 0 | null | 9,580,059,426,480 | 142 | 6 |
while True:
a=map(int,raw_input().split())
if a==[0,0]:
break
if a[0]>a[1]:print(str(a[1])+" "+str(a[0]))
else: print(str(a[0])+" "+str(a[1])) | while True:
n = list(map(int,input().split()))
if(n[0] == n[1] == 0):break
print(" ".join(map(str,sorted(n)))) | 1 | 515,874,251,410 | null | 43 | 43 |
p = int(input())
index = 1
while True:
if p* index % 360 == 0:
print(index)
break
index += 1 | x = int(input())
for i in range(1, 10**5):
if 360 * i % x == 0:
print(360 * i // x)
break | 1 | 13,234,285,417,500 | null | 125 | 125 |
n = int(input())
nums = list(map(int, input().split()))
ans = 0
for idx in range(1, n):
if nums[idx] - nums[idx-1] < 0:
ans += abs(nums[idx] - nums[idx-1])
nums[idx] = nums[idx-1]
print(ans) | N=int(input())
x=list(map(int,input().split()))
sum=0
for i in range(1,N):
if x[i]<x[i-1]:
t=x[i-1]-x[i]
sum+=t
x[i]=x[i-1]
print(sum) | 1 | 4,531,813,294,622 | null | 88 | 88 |
a,b=map(int,input().split())
def gcd(x, y):
while y:
x, y = y, x % y
return x
l=gcd(a,b)
print(int(a*b/l))
| x=int(input())
ans=1
now=x
while now%360!=0:
now+=x
ans+=1
print(ans) | 0 | null | 63,087,765,814,684 | 256 | 125 |
N,R=input().split()
n,r=int(N),int(R)
if n>=10:
print(r)
else:
print(r+100*(10-n)) | n,r = [int(x) for x in input().split()]
if n > 10:
print(r)
else:
print(r + 100 * (10 - n)) | 1 | 63,259,127,038,250 | null | 211 | 211 |
A,B,C = map(int,input().split())
K = int(input())
for i in range(K):
if A >= B:
B = B*2
else:
C = C*2
print("Yes" if A < B and B < C else "No") | #coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
input = lambda: given().rstrip()
LMIIS = lambda: list(map(int,input().split()))
II = lambda: int(input())
XLMIIS = lambda x: [LMIIS() for _ in range(x)]
YN = lambda c : print('Yes') if c else print('No')
MOD = 10**9+7
N = II()
A = LMIIS()
print('YES' if len(A) == len(set(A)) else 'NO')
if __name__ == '__main__':
main() | 0 | null | 40,641,176,957,920 | 101 | 222 |
import math
a,b,c,d = map(int,input().split(" "))
taka = math.ceil(c/b)
aoki = math.ceil(a/d)
if taka <= aoki:
print("Yes")
else:
print("No") | s = input().split("hi")
f = 0
for i in s:
if i != "":
f = 1
break
if f == 0:
print("Yes")
else:
print("No") | 0 | null | 41,419,760,187,780 | 164 | 199 |
import sys
import math
N, K = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))
F = list(map(int, sys.stdin.readline().rstrip().split()))
A.sort()
A = A[::-1]
F.sort()
def test(x):
res = 0
for i in range(N):
t = A[i] * F[i]
if t > x:
res += math.ceil((t - x) / F[i])
return res <= K
ng = -1
ok = 10**18
while ng + 1 < ok:
mid = (ng + ok) // 2
if test(mid):
ok = mid
else:
ng = mid
print(ok) | s = input()
s = 'x'*len(s)
print(s)
| 0 | null | 118,557,670,959,250 | 290 | 221 |
def A():
s = input()
if s == 'SSS': print(3)
elif s=='RSS' or s=='SSR': print(2)
elif s=='RRR': print(0)
else: print(1)
def B():
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
for j in range(i+1, n):
if a[i] == a[j]: continue
for k in range(j+1, n):
if a[i]==a[k] or a[j] == a[k]: continue
s = a[i] + a[j] + a[k]
if s > 2 * max(a[i], a[j], a[k]):
cnt += 1
print(cnt)
def C():
x, k, d = map(int, input().split())
if abs(x) > k * d:
print(abs(x) - k*d)
else:
tm = abs(x) // d
x = abs(x) % d
k -= tm
if k % 2 == 0:
print(x)
else:
print(d-x)
B()
| import sys
"""
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
x = read().rstrip().decode()
"""
N = int(input())
L = list(map(int,input().split()));
L.sort();
def solve():
ret = 0
for i in range(0,N-2):
for j in range(i+1,N-1):
for k in range(j+1,N):
if L[i] != L[j] and L[j] != L[k] and L[i]+L[j] > L[k]:
ret += 1
#print(i,j,k)
return ret
print(solve()) | 1 | 5,065,965,403,420 | null | 91 | 91 |
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) | N=int(input())
print(((N+1)//2)/N) | 0 | null | 142,571,325,695,412 | 251 | 297 |
from math import gcd
K=int(input())
result=0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
result+=gcd(gcd(a,b),c)
print(result) | import math
k=int(input())
s=0
for a in range(k):
for b in range(k):
x=math.gcd(a+1,b+1)
for c in range(k):
s+=math.gcd(x,c+1)
print(s) | 1 | 35,306,366,080,288 | null | 174 | 174 |
from statistics import median
N = int(input())
A = []
B = []
for n in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
#AB = sorted(AB, key=lambda x: x[0])
#print(AB)
cenA = median(A)
cenB = median(B)
if N % 2 == 1:
print(int(cenB - cenA + 1))
elif N % 2 == 0:
print(int((cenB - cenA)*2 + 1))
else:
print('RE') | import math
r=float(input())
print("%.6f"%(r**2*math.pi),"%.6f"%(r*2*math.pi)) | 0 | null | 8,984,845,347,228 | 137 | 46 |
A,B,C=map(int,input().split())
A,B=B,A
A,C=C,A
print(str(A)+" "+str(B)+" "+str(C)) | import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)
N, X, M = rl()
Xs = [None] * M
ans = 0
dif_i = 0
dif_v = 0
cur_i = 0
for i in range(1, N+1):
ans += X
if Xs[X] != None:
cur_i = i
dif_v = ans - Xs[X][1]
dif_i = i - Xs[X][0]
cur_x = X
break
Xs[X] = (i, ans)
X = (X**2) % M
if cur_i > 0 and cur_i < N:
remain = N - cur_i
ans += (remain // dif_i) * dif_v
X = cur_x
for i in range(remain % dif_i):
X = (X**2) % M
ans += X
print(ans)
| 0 | null | 20,363,583,161,880 | 178 | 75 |
N = int(input())
S, T = input().split()
A = ""
for i in range(N):
A += S[i] + T[i]
print(A) | import math
def merge(a,l,m,r):
global cnt
L = a[l:m]+[math.inf]
R = a[m:r]+[math.inf]
i = 0
j = 0
for k in range(l,r):
cnt+=1
if L[i]<=R[j]:
a[k] = L[i]
i+=1
else:
a[k]=R[j]
j+=1
def mergeSort(a,l,r):
if l+1<r:
m = (l+r)//2
mergeSort(a,l,m)
mergeSort(a,m,r)
merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0
mergeSort(a,0,n)
print(*a)
print(cnt)
| 0 | null | 56,198,736,659,354 | 255 | 26 |
a, b = map(int, input().split())
answer = a * b
print(answer)
| import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N,M,X = LI()
# c=[]
# a=[]
# for i in range(n):
# ca = LI()
# c.append(ca[0])
# a.append(ca[1:])
# print(c)
# print(a)
_ca = [LI() for _ in range(N)]
ca = np.array(_ca, np.int64)
# print(ca)
# ca = ca.reshape(n,-1)
C = ca[:,0]
A = ca[:,1:]
# print(c)
# print(a)
result = 10**7
# ビット全探索
for i in range(1 << N):
t = [0] * M
c = 0
for j in range(N):
# i を j回右にシフトして1との論理積を取り、1であればアイテムを購入しているとみなす
# 購入していない場合
if (i >> j) & 1 == 0:
continue
c += C[j]
for k in range(M):
t[k] += A[j][k]
# 全てX以上であれば更新
if all(x >= X for x in t):
result = min(result, c)
if result == 10**7:
print(-1)
else:
print(result) | 0 | null | 19,078,130,097,378 | 133 | 149 |
N = int(input())
S = input()
abc = S.count('R')*S.count('G')*S.count('B')
L = (N-1)//2
for i in range(1,L+1):
for j in range(N-2*i):
if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
abc -= 1
print(abc) | #!/usr/bin/env python3
def solve(S: int, W: int):
if W >= S:
return "unsafe"
return "safe"
def main():
S, W = map(int, input().split())
answer = solve(S, W)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 32,630,929,332,298 | 175 | 163 |
def main():
a = list(map(int,input().split()))
ans = 0
for i in range(5):
ans += a[i]
print(15 - ans)
main() | import sys
array = list(map(int,input().split()))
print(array.index(0)+1) | 1 | 13,531,560,836,868 | null | 126 | 126 |
N, K, S = map(int, input().split())
if S == 10**9:
ans = [1]*N
else:
ans = [S+1] * N
for i in range(K):
ans[i] = S
print(" ".join(map(str, ans))) | import sys
from collections import deque
n = int(sys.stdin.readline().strip())
edges = [[] for _ in range(n)]
for _ in range(n):
tmp = list(map(int, sys.stdin.readline().strip().split(" ")))
for node in tmp[2:]:
edges[tmp[0] - 1].append(node-1)
# print(edges)
distance = [0] * n
q = deque()
q.append((0, 0))
visited = set()
while q:
node, d = q.popleft()
# print(node, d)
if node in visited:
continue
distance[node] = d
visited.add(node)
for next in edges[node]:
# print("next", next)
q.append((next, d + 1))
for i, d in enumerate(distance):
if i == 0:
print(1, 0)
else:
print(i + 1, d if d > 0 else -1)
| 0 | null | 45,677,741,417,562 | 238 | 9 |
import sys
from math import gcd
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7
INF = float("inf")
def main():
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P = P * (-1)
Q = Q * (-1)
if P + Q < 0:
print(0)
return
elif P + Q == 0:
print("infinity")
return
else:
S = (-P) // (P + Q)
T = (-P) % (P + Q)
if T == 0:
print(2 * S)
else:
print(2 * S + 1)
if __name__ == "__main__":
main()
| T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = (A1 - B1) * T1
d2 = d1 + (A2 - B2) * T2
if (d1 > 0 and d2 > 0) or (d1 < 0 and d2 < 0):
print(0)
exit()
if d2 == 0:
print('infinity')
exit()
d1 = abs(d1)
d2 = abs(d2)
if d1 % d2 == 0:
print(d1 // d2 * 2)
else:
print(1 + d1 // d2 * 2)
| 1 | 131,463,565,554,090 | null | 269 | 269 |
class findroop:
def __init__(self, n, nex):
self.n = n
self.next = nex
#遷移start回でループに入る、end回でループする
#A->B->C->D->B: return=(1, 4)
#C->D->B->C : return=(0, 3)
#O(n)
def findroop(self, start):
roopstart = -1
roopend = -1
visited = [False for i in range(self.n)]
visitlist = []
now = start
for i in range(self.n):
if visited[now]:
roopend = i
break
else:
visited[now] = True
visitlist.append(now)
now = self.next(now)
for i in range(len(visitlist)):
if visitlist[i] == now:
roopstart = i
return (roopstart, roopend)
N,X,M = list(map(int, input().split()))
fr = findroop(M, lambda x: x**2 % M)
roopstart, roopend = fr.findroop(X)
ans = 0
if N <= roopstart:
for i in range(N):
ans += X
X = (X**2)%M
else:
for i in range(roopstart):
ans += X
X = (X**2)%M
N -= roopstart
roopsum = 0
for i in range(roopend-roopstart):
roopsum += X
X = (X**2) % M
ans += (N // (roopend-roopstart)) * roopsum
N = N % (roopend-roopstart)
for i in range(N):
ans += X
X = (X**2) % M
print(ans) | n, x, m = map(int, input().split())
ans = []
c = [0]*m
flag = False
for i in range(n):
if c[x] == 1:
flag = True
break
ans.append(x)
c[x] = 1
x = x**2 % m
if flag:
p = ans.index(x)
l = len(ans) - p
d, e = divmod(n-p, l)
print(sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e]))
else:
print(sum(ans))
| 1 | 2,820,624,764,832 | null | 75 | 75 |
n, m = map(int, input().split())
if n % 2 == 0:
i = 1
while i <= m:
a_i = str(i)
if i <= (n - 2) // 4:
b_i = str(n - i)
else:
b_i = str(n - i - 1)
print(a_i + " " + b_i)
i += 1
elif n % 2 == 1:
for i in range(1, m + 1):
a_i = str(i)
b_i = str(n - i)
print(a_i + " " + b_i)
| while True:
H, W = map(int, input().split())
if (H, W) == (0, 0):
break
[print("#"*W+"\n") if i == H-1 else print("#"*W) for i in range(H)] | 0 | null | 14,842,332,187,394 | 162 | 49 |
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cnt = 0
s = 0
for i in range(N):
s += A[i]
for i in range(N):
if 4*M*A[i] < s:
cnt += 1
print(['No', 'Yes'][N - cnt >= M]) | def do_round_robin(process, tq):
from collections import deque
q = deque()
elapsed_time = 0 # ??????????????????????§??????????????????????
finished_process = [] # ????????????????????????????????????????????¨??????????????????????????§?????????
# ?????\?????????????????????????????????
for process_name, remaining_time in process:
q.append([process_name, int(remaining_time)])
while True:
try:
process_name, remaining_time = q.pop()
except IndexError: # ??????????????£???????????????????????????????????£???
break
else:
elapsed_time += min(remaining_time, tq)
remaining_time -= tq
if remaining_time > 0:
q.appendleft([process_name, remaining_time])
else:
finished_process.append((process_name, elapsed_time))
return finished_process
if __name__ == '__main__':
# ??????????????\???
# ????????????????????????????????????????????????????°??????????????????????????????¨
data = [int(x) for x in input().split(' ')]
num_of_process = data[0]
time_quantum = data[1]
process = []
for i in range(num_of_process):
process.insert(0, [x for x in input().split(' ')])
# ??????
results = do_round_robin(process, time_quantum)
# ???????????????
for i in results:
print('{0} {1}'.format(i[0], i[1])) | 0 | null | 19,434,656,665,662 | 179 | 19 |
X = int(input())
ans, rem = divmod(X, 500)
ans *= 1000
ans += rem // 5 * 5
print(ans)
| X=int(input())
ans=1000*(X//500)+5*((X-(X//500*500))//5)
print(ans) | 1 | 42,616,149,123,758 | null | 185 | 185 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.