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
|
---|---|---|---|---|---|---|
def Euclidean(input_list):
# print input_list
x = input_list[1]
y = input_list[0]
r = x % y
if r != 0:
list = [r, y]
list.sort()
return Euclidean(list)
else:
return y
list = map(int, raw_input().split(" "))
list.sort()
print Euclidean(list) | h,w,m = ( int(x) for x in input().split() )
h_array = [ 0 for i in range(h) ]
w_array = [ 0 for i in range(w) ]
ps = set()
for i in range(m):
hi,wi = ( int(x)-1 for x in input().split() )
h_array[hi] += 1
w_array[wi] += 1
ps.add( (hi,wi) )
h_great = max(h_array)
w_great = max(w_array)
h_greats = list()
w_greats = list()
for i , hi in enumerate(h_array):
if hi == h_great:
h_greats.append(i)
for i , wi in enumerate(w_array):
if wi == w_great:
w_greats.append(i)
ans = h_great + w_great
for _h in h_greats:
for _w in w_greats:
if (_h,_w) in ps:
continue
print(ans)
exit()
print(ans-1) | 0 | null | 2,379,192,266,040 | 11 | 89 |
n=int(input())
mod=1000000007
print((pow(10,n,mod)-2*pow(9,n,mod)+pow(8,n,mod))%mod) | x = int(input())
mod =10**9 + 7
ans = pow(10,x,mod)
ans -= 2 * pow(9,x,mod)
ans += pow(8,x,mod)
ans %=mod
print(ans) | 1 | 3,198,303,948,192 | null | 78 | 78 |
# 問題:https://atcoder.jp/contests/abc143/tasks/abc143_b
n = int(input())
d = list(map(int, input().strip().split()))
res = 0
for i in range(1, n):
for j in range(i):
res += d[i] * d[j]
print(res)
| n = int(input())
#a, b = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
for j in range(n):
if i < j:
ans = ans + l[i] * l[j]
print(ans)
| 1 | 168,637,846,559,962 | null | 292 | 292 |
N, M, K = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
total = 0
Asum = sum(A)
nA = len(A)
Bsum = 0
ans = 0
for nB in range(len(B) + 1):
if nB != 0:
Bsum += B[nB-1]
if Bsum > K:
break
while Asum + Bsum > K:
nA -= 1
Asum -= A[nA]
ans = max(nA + nB, ans)
print(ans)
| a,b,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
from itertools import accumulate
A = list(accumulate(A))
B = list(accumulate(B))
A = [0] + A
B = [0] + B
ans = 0
num = b
for i in range(a+1):
if A[i] > k:
continue
while True :
if A[i] + B[num] > k:
num -=1
else:
ans = max(ans,i+num)
break
print(ans) | 1 | 10,758,628,664,772 | null | 117 | 117 |
import statistics
while True:
num = input()
if num == '0':
break
value = map(int, input().split())
print(statistics.pstdev(value))
| import math
def isprime(x):
if x == 2:
return True
if x < 2 or x % 2 == 0:
return False
i = 3
while i <= math.sqrt(x):
if x % i == 0:
return False
i = i + 2
return True
count = 0
n = int(input())
for i in range(0, n):
if isprime(int(input())):
count += 1
print(count) | 0 | null | 106,172,892,420 | 31 | 12 |
N = int(input())
l = []
for _ in range(N):
s, t = input().split()
t = int(t)
l.append([s, t])
X = input()
ans = 0
found = False
for s in l:
if found:
ans += s[1]
continue
if s[0] == X:
found = True
print(ans) | n = int(input())
title = []
time = []
for i in range(n):
line = input().split()
title += [line[0]]
time += [int(line[1])]
key = input()
a = title.index(key)
print(sum(time[a+1:]))
| 1 | 97,338,218,292,380 | null | 243 | 243 |
S = input()
Q = int(input())
query = [input().split() for _ in range(Q)]
switch = 1
top = []
bottom = []
for i in range(Q):
if query[i][0] == "1":
switch *= -1
else:
f = query[i][1]
c = query[i][2]
if switch == 1:
if f == "1":
top.append(c)
else:
bottom.append(c)
else:
if f == "1":
bottom.append(c)
else:
top.append(c)
if switch == 1:
ans = top[::-1] + list(S) + bottom
else:
ans = bottom[::-1] + list(S)[::-1] + top
print("".join(ans)) | N,K = map(int,input().split())
S = [tuple(map(int,input().split())) for _ in range(K)]
MOD=998244353
dp=[0]*N
dp[0]=1
for i in range(N-1):
x = dp[i]
dp[0]=0
for k in range(K):
l,r = S[k]
if i+l < N:
dp[i+l]+=x
dp[i+l]%=MOD
if i+r+1 < N:
dp[i+r+1]-=x
dp[i+r+1]%=MOD
dp[i+1]+=dp[i]
dp[i+1]%=MOD
print(dp[-1]%MOD) | 0 | null | 30,127,957,621,230 | 204 | 74 |
S = input()
ans = 0
for i in range(0,len(S)//2):
if S[i] != S[len(S)-1-i]:
ans += 1
print(ans) | str = input()
n = int(len(str) / 2)
cnt = 0
for i in range(n):
if str[i] != str[-1-i]:
cnt += 1
print(cnt) | 1 | 120,514,071,591,560 | null | 261 | 261 |
N = int(input())
A = []
for i in range(N):
a = int(input())
Alst = []
for j in range(a):
x,y = map(int,input().split())
Alst.append([x-1,y])
A.append(Alst)
honest = 0
for i in range(2**N):
flag = 0
for j in range(N):
if (i>>j)&1:
for x,y in A[j]:
if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
flag = 1
break
if flag == 0: # 矛盾がある場合はflag == 1になる
honest = max(honest, bin(i)[2:].count('1')) # 1の数をカウントし最大となるものを選択
print(honest) |
n, k, c = map(int, input().split())
s = input()
l = [0] * k
r = [0] * k
p = 0
# for i in range(n):
i = 0
while i < n:
if s[i] == "o":
l[p] = i
p += 1
if (p >= k):
break
i += c
i += 1
p = k-1
# for i in range(n - 1, -1, -1):
i = n - 1
while i >= 0:
if s[i] == "o":
r[p] = i
p -= 1
if (p < 0):
break
i -= c
i -= 1
#print(l, r)
for i in range(k):
if l[i] == r[i]:
print(l[i]+1)
| 0 | null | 81,419,279,048,340 | 262 | 182 |
x = int(input())
import math
print(360*x//math.gcd(360,x)//x) | # import matplotlib.pyplot as plt
import math
def lcm(x, y):
if x > y:
z = x
else:
z = y
while(True):
if((z % x == 0) and (z % y == 0)):
lcm = z
break
z += 1
return lcm
X = int(input())
print(int(lcm(X, 360) / X)) | 1 | 13,007,215,029,348 | null | 125 | 125 |
import math
import sys
from collections import Counter
import bisect
readline = sys.stdin.readline
def main():
cnt = 0
arg = 0
x = int(readline().rstrip())
for i in range(1000):
cnt += 1
arg += x
arg %= 360
if arg == 0:
break
print(cnt)
if __name__ == '__main__':
main()
| def main():
n, x, y = map(int, input().split())
x -= 1
y-= 1
ans = [0]*n
for i in range(n):
for j in range(i+ 1, n):
d = min(j-i, abs(j-y) + abs(x-i) + 1, abs(j-x) + abs(y-i) + 1)
ans[d] += 1
for i in range(1, n):
print(ans[i])
if __name__ == "__main__":
main() | 0 | null | 28,770,625,565,220 | 125 | 187 |
n, d = list(map(int, input().split(' ')))
res = 0
for _ in range(n):
x, y = list(map(int, input().split(' ')))
if d ** 2 >= (x ** 2) + (y ** 2):
res += 1
print(res) | n,d = map(int,input().split())
l=[]
for _ in range(n):
x,y=map(int,input().split())
l.append(((x**2)+(y**2))**(0.5))
l.sort()
c=0
for i in l:
if i>d:
break
else:
c+=1
print(c) | 1 | 5,934,149,078,932 | null | 96 | 96 |
# from collections import Counter
# n = int(input())
# li = list(map(int, input().split()))
a, b = map(int, input().split())
# n = int(input())
print(a*b if a<10 and b<10 else -1)
| N,M = map(int,input().split())
S = input()
ans = []
right = N
while right > 0:
left = right
for i in range(M):
if S[right-i-1] == '0':
left = right-i-1
if left == 0:
break
if left == right:
print(-1)
break
ans.append(right-left)
right = left
else:
print(*reversed(ans)) | 0 | null | 148,895,682,628,188 | 286 | 274 |
h, w = map(int, input().split())
sheet = []
for j in range(h):
lista = list(map(int, input().split()))
lista.append(sum(lista))
sheet.append(lista)
lista = []
for i in range(w+1):
sum = 0
for j in range(h):
sum += sheet[j][i]
lista.append(sum)
sheet.append(lista)
for i in range(h+1):
text = ""
for j in range(w+1):
text += str(sheet[i][j]) + " "
print(text[:-1]) | # -*-coding:utf-8
def main():
r, c = map(int, input().split())
#A = [[0 for i2 in range(c+1)] for i1 in range(r+1)]
A = []
for i in range(r):
tokens = list(map(int, input().split()))
tokens.append(sum(tokens))
A.append(tokens)
rowSumList = []
for i in range(c+1):
rowSum = 0
for j in range(r):
rowSum += A[j][i]
rowSumList.append(rowSum)
A.append(rowSumList)
for i in range(r+1):
for j in range(c+1):
if(j == c):
print('%d' % A[i][j])
else:
print('%d ' % A[i][j], end='')
if __name__ == '__main__':
main() | 1 | 1,365,550,283,042 | null | 59 | 59 |
o = list()
top = -1
for s in input().split():
if s.isdigit():
o.append(int(s))
top += 1
else:
if s is "+":
n = o[top]+o[top-1]
o.pop(top)
top-=1
o.pop(top)
top-=1
o.append(n)
top+=1
if s is "-":
n = o[top-1] - o[top]
o.pop(top)
top -= 1
o.pop(top)
top -= 1
o.append(n)
top+=1
if s is "*":
n = o[top]*o[top-1]
o.pop(top)
top -= 1
o.pop(top)
top -= 1
o.append(n)
top+=1
print(o[0]) | s = input().split()
stack = []
for i in s:
if i.isdigit():
stack.append(int(i))
else:
if i == "+":
f = lambda x, y: x + y
elif i == "-":
f = lambda x, y: x - y
elif i == "*":
f = lambda x, y: x * y
y = stack.pop()
x = stack.pop()
stack.append(f(x, y))
print(stack[0])
| 1 | 36,387,459,680 | null | 18 | 18 |
n,k,s = map(int,input().split())
if s != 10**9:
ans_ls = [s+1] * n
for i in range(k):
ans_ls[i] = s
ans_ls = list(map(str,ans_ls))
else:
ans_ls = [1] * n
for i in range(k):
ans_ls[i] = s
ans_ls = list(map(str,ans_ls))
print(' '.join(ans_ls))
| n,k,s=map(int,input().split())
L=[s]*k+[min(s+1,10**9-1)]*(n-k)
print(' '.join(map(str,L))) | 1 | 91,044,631,601,088 | null | 238 | 238 |
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
print(A - B * 2) if A > B * 2 else print(0)
| #ITP1_10-C Standard Deviation
while True:
n= int(input())
if n==0:
break
s = input().split(" ")
mean = 0.0
for i in range(n):
mean += float(s[i])
mean /= n
cov = 0.0
for i in range(n):
cov+=((float(s[i])-mean)**2)/n
print(cov**0.5) | 0 | null | 83,712,516,921,358 | 291 | 31 |
def solve(N,A) :
ans = 1
for i in range(N) :
if(A[i] == 0) :
print(0)
return
for i in range(N) :
ans = ans * A[i]
if(ans > 10**18):
ans = -1
break
print(ans)
N = int(input())
A = list(map(int, input().split()))
solve(N,A) | while 1:
try:print input()
except:break | 0 | null | 8,519,370,001,198 | 134 | 47 |
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") | a, b, c = map(int, input().split())
k = int(input())
flg = False
c = (2**k) * c
for i in range(k):
if a < b < c:
flg = True
break
b *= 2
c //= 2
if flg:
print('Yes')
else:
print('No')
| 1 | 6,975,949,469,888 | null | 101 | 101 |
N, X, M = map(int, input().split())
sup = 10**11
db = [[0]*M for _ in range(sup.bit_length())]
dbcum = [[0]*M for _ in range(sup.bit_length())]
db[0] = [i**2 %M for i in range(M)]
dbcum[0] = [i**2 %M for i in range(M)]
for i in range(1,sup.bit_length()):
for j in range(M):
db[i][j] = db[i-1][db[i-1][j]]
dbcum[i][j] = dbcum[i-1][j]+dbcum[i-1][db[i-1][j]]
ans = X
p = 0
N -= 1
while N:
if N%2:
ans += dbcum[p][X]
X = db[p][X]
p += 1
N >>= 1
print(ans) | n, x, m = map(int, input().split())
v = list(range(m))
p = [-1 for _ in range(m)]
a = x
p[a - 1] = 0
s = [x]
l, r = n, n
for i in range(n):
a = a ** 2 % m
if p[a - 1] >= 0:
l, r = p[a - 1], i + 1
break
else:
s.append(a)
p[a - 1] = i + 1
ans = sum(s[:l])
if l != r:
b = (n - 1 - i) // (r - l) + 1
c = (n - 1 - i) % (r - l)
ans += b * sum(s[l:r]) + sum(s[l:l + c])
print(ans)
| 1 | 2,797,102,293,092 | null | 75 | 75 |
from math import gcd
def lcm(a, b):
return a * b // gcd(a, b)
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = [0] * n
for i in range(n):
tmp = a[i]
while tmp % 2 == 0:
tmp //= 2
l[i] += 1
if i > 0 and l[i] != l[i - 1]:
print(0)
exit(0)
res = 1
for i in range(n):
res = lcm(res, a[i] // 2)
print(m // res - m // (res * 2))
| N = int(input())
A = []
xy = []
for i in range(N):
a = int(input())
A.append(a)
xy.append([list(map(int, input().split())) for j in range(a)])
ans = 0
p = [-1]*N
def dfs(i, p):
global ans
if i == N:
ans = max(ans, sum(p))
else:
p_true = p.copy()
if p_true[i] != 0:
p_true[i] = 1
ok = True
for x, y in xy[i]:
if y == p_true[x-1] or p_true[x-1] == -1:
p_true[x-1] = y
else:
ok = False
if ok:
dfs(i+1, p_true)
p_false = p.copy()
if p_false[i] != 1:
p_false[i] = 0
dfs(i+1, p_false)
dfs(0, p)
print(ans)
| 0 | null | 111,403,294,295,550 | 247 | 262 |
a = raw_input().split()
if (a[0] < a[1] and a[1] < a[2]):
print "Yes"
else:
print "No" | a,b,c=[int(x) for x in input().split()]
print('Yes' if a<b<c else 'No')
| 1 | 379,636,394,942 | null | 39 | 39 |
line = input()
N, X, T = (int(x) for x in line.split(" "))
print((N + X - 1) // X * T) | import math
pi=math.pi
r = int(input().strip())
print(2*r*pi) | 0 | null | 17,740,008,316,836 | 86 | 167 |
f=lambda:[*map(int,input().split())]
n,k=f()
p,c=f(),f()
p=[i-1 for i in p]
a=-10**9
for i in range(n):
x,l,s,t=i,[],0,0
while 1:
x=p[x]
l+=[c[x]]
s+=c[x]
if x==i: break
m=len(l)
for j in range(m):
if j+1>k: break
t+=l[j]
a=max(a,t+(k-j-1)//m*s*(s>0))
print(a) | def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N, K = getNM()
P = [i - 1 for i in getList()]
C = getList()
ignore = [-1] * N
ans = -float('inf')
for i in range(N):
if ignore[i] >= 0:
continue
### ループ生成 ###
ignore[i] = 1
opt_l = [i]
to = P[i]
while ignore[to] == -1:
opt_l.append(to)
ignore[to] = 1
to = P[to]
###
### 作成したループで得点リスト生成 ###
n = len(opt_l)
point = [0] * n
for i in range(n):
point[i] = C[opt_l[i]]
###
### 得点リスト内の連続する区間の総和のうちの最大値を累積和を使って求める ###
sum_roop = sum(point)
# ループの累積和作成
imos = [0]
point += point
for i in range(len(point)):
imos.append(imos[i] + point[i])
#
ran = min(n, K)
for i in range(n):
# 区間の大きさran以下についての総和を求める
for j in range(1, ran + 1):
if sum_roop >= 0:
opt = imos[i + j] - imos[i] + ((K - j) // n) * sum_roop
else:
opt = imos[i + j] - imos[i]
ans = max(ans, opt)
###
print(ans) | 1 | 5,384,000,065,350 | null | 93 | 93 |
import copy
import random
import time
def down(d, last, c):
result = 0
for i in range(26):
result += c[i] * (d - last[i])
return result
def calc_score_of_the_day(S, d, t, last, C):
return S[d][t] - down(d+1, last, C) + C[t] * (d+1 - last[t])
def main():
start = time.time()
D = int(input())
C = [int(c) for c in input().split()]
S = [0] * D
for d in range(D):
S[d] = [int(s) for s in input().split()]
last = [0] * 26
scores = [float('-inf')] * D
result = 0
T = [0] * D
for d in range(D):
next_t = 0
score = float('-inf')
for t in range(26):
s = calc_score_of_the_day(S, d, t, last, C)
if s > score:
score = s
next_t = t
last[next_t] = d + 1
result += score
scores[d] = result
T[d] = next_t + 1
while time.time() - start < 1.9:
result = scores[-1]
change_date = 4 #random.randint(0, D-1)
change_from = T[change_date]
change_to = 13 # random.randint(1, 26)
if change_from == change_to:
continue
copied_T = copy.copy(T)
copied_T[change_date] = change_to
last_of_the_day = [t if t < change_date else 0 for t in last]
copied_scores = copy.copy(scores)
for d in range(change_date, D):
t = copied_T[d] - 1
score = calc_score_of_the_day(S, d, t, last_of_the_day, C)
last_of_the_day[t] = d + 1
before = copied_scores[d-1] if d > 0 else 0
copied_scores[d] = before + score
copied_T[d] = t + 1
if copied_scores[-1] > result:
scores = copied_scores
T = copied_T
for t in T:
print(t)
if __name__ == "__main__":
main()
| N,M = map(int, input().split())
a = 1
b = N
for i in range(M, 0, -1):
if i%2 == M%2:
print(a, a+i)
a += 1
else:
print(b, b-i)
b -= 1 | 0 | null | 19,323,261,722,460 | 113 | 162 |
x, k, d = [int(i) for i in input().split()]
if x < 0:
x = -x
l = min(k, x // d)
k -= l
x -= l * d
if k % 2 == 0:
print(x)
else:
print(d - x) | import sys
input = sys.stdin.readline
def read():
S = input().strip()
return S,
def solve(S):
N = len(S)
ans = 0
for i in range(N//2):
if S[i] != S[N-i-1]:
ans += 1
return ans
if __name__ == '__main__':
inputs = read()
print(solve(*inputs))
| 0 | null | 62,670,887,242,078 | 92 | 261 |
s = input()
if s in ['hi','hihi','hihihi','hihihihi','hihihihihi']:
print('Yes')
else:
print('No') | # coding: utf-8
import sys
from collections import deque
output_str = deque()
data_cnt = int(input())
for i in range(data_cnt):
line = input().rstrip()
if line.find(" ") > 0:
in_command, in_str = line.split(" ")
else:
in_command = line
if in_command == "insert":
output_str.appendleft(in_str)
elif in_command == "delete":
if output_str.count(in_str) > 0:
output_str.remove(in_str)
elif in_command == "deleteFirst":
output_str.popleft()
elif in_command == "deleteLast":
output_str.pop()
print(" ".join(output_str)) | 0 | null | 26,762,908,529,500 | 199 | 20 |
def main():
n = int(input())
operation = [input().split() for _ in range(n)]
dictionary = {}
for command, char in operation:
if command == "insert":
dictionary[char] = True
elif command == "find":
try:
if dictionary[char]:
print("yes")
except KeyError:
print("no")
return
if __name__ == "__main__":
main()
| import sys
d = {}
n = int(input())
for i in sys.stdin:
q, c = i.split()
if q == 'find':
if c in d:
print('yes')
else:
print('no')
else:
d[c] = True
| 1 | 76,087,673,220 | null | 23 | 23 |
N = int(input())
A = list(map(int,input().split()))
ans = 0
mod = 1000000007
a = sum(A)
for i in range(N):
a -= A[i]
ans += A[i]*a
ans %= mod
print(ans) | N = int(input())
A = list(map(int, input().split()))
B = []
b = 0
e = 10 ** 9 + 7
for i in range(N - 1):
b += A[N - 1 - i]
b = b % e
B.append(b)
result = 0
for i in range(N - 1):
result += A[i] * B[N - 2 - i]
result = result % e
print(result) | 1 | 3,836,449,879,850 | null | 83 | 83 |
n = input()
R = [input() for i in range(n)]
max = R[1] - R[0]
min = R[0]
for i in range(1,n):
if R[i] - min > max:
max = R[i] - min
if R[i] < min:
min = R[i]
print max | n = int(raw_input())
r = []
for i in range(n):
r.append(int(raw_input()))
min_v = r[0]
max_profit = -1000000000000
for i in range(1,n):
if max_profit < r[i] - min_v:
max_profit = r[i]-min_v
if r[i] < min_v:
min_v = r[i]
print max_profit | 1 | 13,979,273,552 | null | 13 | 13 |
import sys
from collections import deque
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
n = I()
A = LI()
q = I()
m = LI()
ans = 0
partial_sum = set()
for i in range(2 ** n):
bit = [i>>j&1 for j in range(n)]
partial_sum.add(sum(A[k]*bit[k] for k in range(n)))
for x in m:
print('yes' if x in partial_sum else 'no')
| n = int(input())
print(len({input() for i in range(n)})) | 0 | null | 15,199,094,667,020 | 25 | 165 |
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
import numpy as np
A0 = [0] + A
B0 = [0] + B
AA = np.cumsum(A0)
BB = np.cumsum(B0)
ans = 0
jmax = M
for i in range(0, N+1):
a = AA[i]
if a > K:
break
for j in range(jmax, -1, -1):
b = BB[j]
# print(a, b)
if a + b <= K:
ans = max(ans, i+j)
# print('ok')
break
jmax = j
print(ans) | import sys
import math
import itertools
import collections
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def main():
N, M, K = NMI()
A = NLI()
B = NLI()
cumsum_A = [0 for _ in range(len(A)+1)]
cumsum_B = [0 for _ in range(len(B)+1)]
cnt = 0
for n in range(N):
cnt += A[n]
cumsum_A[n+1] = cnt
cnt = 0
for m in range(M):
cnt += B[m]
cumsum_B[m+1] = cnt
ans = 0
b= M
for n in range(N+1):
remain_K = K - cumsum_A[n]
if remain_K < 0:
break
else:
for m in range(b,-1,-1):
if cumsum_B[m]> remain_K:
continue
else:
b = m
ans = max(ans,n+m)
break
print(ans)
if __name__ == '__main__':
main() | 1 | 10,860,867,742,788 | null | 117 | 117 |
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
s=sum(A)
SA=[0]
for a in A:
SA.append(SA[-1]+a)
for i in range(n+1):
SA[i]=s-SA[i]
l,r=0,2*max(A)+1
import bisect
def chk(x):
ct=0
for a in A:
ct+=n-bisect.bisect_left(A,max(x-a,0))
if ct>=m:
return True
else:
return False
def count(x):
ct=0
for a in A:
ct+=n-bisect.bisect_left(A,max(x-a,0))
return ct
while r-l>1:
mid=(l+r)//2
if chk(mid):
l=mid
else:
r=mid
ans=0
for a in A:
aa=bisect.bisect_left(A,max(l-a,0))
ans+=SA[aa]+a*(n-aa)
print(ans-l*(count(l)-m))
| from bisect import bisect_left
from itertools import accumulate
n, m = map(int, input().split())
hands = [int(x) for x in input().split()]
increasing = sorted(hands)
hands = list(reversed(increasing))
xs = [0] + list(accumulate(hands))
max_x = 2 * 10**5 + 1
min_x = 0
def canGet(x):
count = 0
for hand in increasing:
idx = bisect_left(increasing, x-hand)
count += n - idx
return count >= m
while max_x - min_x > 1:
# left
mid = (max_x + min_x) // 2
if canGet(mid):
min_x = mid
else:
max_x = mid
ans = 0
count = 0
for Ai in hands:
idx = bisect_left(increasing, min_x-Ai)
ans += Ai*(n-idx) + xs[n-idx]
count += n-idx
print(ans-(count-m)*min_x)
| 1 | 107,990,387,446,522 | null | 252 | 252 |
S = input()
T = input()
U = [0] * (len(S)-len(T)+1)
for j in range(len(S)-len(T)+1):
for i in range(len(T)):
if(S[i+j] != T[i]):
U[j] += 1
print(min(U)) | x = int(input().rstrip())
if x >= 30:
print("Yes")
else:
print("No") | 0 | null | 4,757,725,374,908 | 82 | 95 |
n = int(input())
a = list(map(str, input().split()))
a.reverse()
for i in range(n):
if i == n - 1:
print(a[i], end='')
else:
print(a[i] + ' ', end='')
print('') | import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
n = int(input())
s,t = input().split()
ans = ''
for i in range(n):
ans += s[i] + t[i]
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 56,367,629,066,832 | 53 | 255 |
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
H, W, M = map(int, input().split())
rows = [0] * (H + 1)
cols = [0] * (W + 1)
from collections import defaultdict
ng_cols = defaultdict(set)
for _ in range(M):
h, w = map(int, input().split())
rows[h] += 1
cols[w] += 1
ng_cols[h].add(w)
max_of_rows = max(rows)
max_of_cols = max(cols)
max_rows_index = set()
max_cols_index = set()
for i in range(H + 1):
if rows[i] == max_of_rows:
max_rows_index.add(i)
for i in range(W + 1):
if cols[i] == max_of_cols:
max_cols_index.add(i)
flag = 0
for i in max_rows_index:
for j in max_cols_index:
if j not in ng_cols[i]:
flag = 1
break
print(max_of_rows + max_of_cols - 1 + flag)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
def main():
H, W, M = map(int, input().split())
row = [0] * H
col = [0] * W
bomb = set()
for i in range(M):
h, w = map(int, input().split())
h -= 1
w -= 1
row[h] += 1
col[w] += 1
bomb.add((h, w))
# print(row, col, bomb)
rowmax = max(row)
colmax = max(col)
rows = []
cols = []
for i in range(H):
if row[i] == rowmax:
rows.append(i)
for i in range(W):
if col[i] == colmax:
cols.append(i)
for r in rows:
for c in cols:
if (r, c) in bomb:
continue
else:
print(rowmax + colmax)
exit()
print(rowmax + colmax - 1)
if __name__ == "__main__":
main()
| 1 | 4,727,177,441,540 | null | 89 | 89 |
from math import ceil
A_HP, A_ATK, B_HP, B_ATK = map(int, input().split())
print('Yes' if ceil(A_HP / B_ATK) >= ceil(B_HP / A_ATK) else 'No') | import sys
input = sys.stdin.readline
def main():
K = int(input())
t = 7
t %= K
for i in range(K+1):
if t == 0:
print(i+1)
break
t = (t * 10 + 7) % K
else:
print(-1)
main() | 0 | null | 17,868,280,016,928 | 164 | 97 |
def abc164_d():
# 解説放送
s = str(input())
n = len(s)
m = 2019
srev = s[::-1] # 下の位から先に見ていくために反転する
x = 1 # 10^i ??
total = 0 # 累積和 (mod 2019 における累積和)
cnt = [0] * m # cnt[k] : 累積和がkのものが何個あるか
ans = 0
for i in range(n):
cnt[total] += 1
total += int(srev[i]) * x
total %= m
ans += cnt[total]
x = x*10 % m
print(ans)
abc164_d() | import sys
# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
import queue
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n = ni()
a = na()
d = [0, 0, 0]
ans = 1
for ai in a:
ans *= d.count(ai)
ans %= MOD
for i in range(3):
if d[i] == ai:
d[i] += 1
break
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 80,462,065,031,802 | 166 | 268 |
n=int(input())
dic={}
for i in range(n):
s=input()
if s not in dic:
dic[s]=1
else:
dic[s]+=1
dic = sorted(dic.items(),key=lambda x:x[0])
dic = sorted(dic,key=lambda x:x[1],reverse=True)
ma=dic[0][1]
for i,v in dic:
if v!=ma:
break
else:
print(i) | #!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
N = II()
counter = cl.Counter()
for i in range(N):
s = input()
counter.update({s: 1})
item, value = zip(*counter.most_common())
ans = []
max_num = value[0]
for i in range(len(value)):
if value[i] == max_num:
ans.append(item[i])
ans.sort()
print(*ans, sep="\n")
main()
| 1 | 69,787,438,710,090 | null | 218 | 218 |
n = int(input())
p = list(map(int,input().split()))
mini = 10**9
ans =0
for i in range(n):
if p[i] <= mini:
mini = p[i]
ans += 1
print(ans) | N = int(input())
A = [0]*N
A = list(map(int, input().split()))
sum_step = 0
for n in range(1,N):
if A[n] < A[n-1]:
sum_step += A[n-1] - A[n]
A[n] = A[n-1]
print(sum_step) | 0 | null | 45,175,231,781,702 | 233 | 88 |
n, x, m = map(int, input().split())
ans = 0
a = [0]
id = [0]*(m+1)
l = 1
while id[x] == 0:
a.append(x)
id[x] = l
ans += x
l += 1
x = x**2 % m
c = l - id[x]
s=0
for i in range(id[x],l):
s += a[i]
if n <= l-1:
ans = 0
for i in range(1,n+1):
ans += a[i]
else:
n -= l
n += 1
ans += s*(n//c)
n %= c
for i in range(n):
ans += a[id[x] + i]
print(ans) | N,X,M=map(int,input().split())
i=1
A=[X]
seen=[-1]*M
seen[X]=0
while(i<N):
T=A[-1]**2%M
#seen[T]~i-1までがループになっている
if seen[T]!=-1:
Roop=i-seen[T]
Left,Right=seen[T],i
break
seen[T]=i
A.append(T)
i+=1
if i==N:
print(sum(A))
exit()
ans=sum(A)
RoopSum=0
for i in range(Left,Right):
RoopSum+=A[i]
Rest=N-len(A)
ans+=Rest//Roop*RoopSum
for i in range(Rest%Roop):
ans+=T
T=T**2%M
print(ans) | 1 | 2,812,874,380,136 | null | 75 | 75 |
def digitSum(n):
s = str(bin(n))
s = s[2:]
array = list(map(int, s))
return sum(array)
N = int(input())
A = []
X = []
Y = []
res = 0
for i in range(N):
a = int(input())
A.append(a)
X_temp = []
Y_temp = []
for j in range(a):
x,y = map(int,input().split())
X_temp.append(x)
Y_temp.append(y)
X.append(X_temp)
Y.append(Y_temp)
for i in range(1 << N):
judge = True
for j in range(N):
if (i >> j) & 1:#もしAjが正直者だったら
for k in range(A[j]):
if (i >> X[j][k]-1) & 1 != Y[j][k]:
judge = False
"""else:#もしAjが不親切ものだったら。不親切者も正しいことをいうこともある。
for k in range(A[j]):#
if (i >> X[j][k]-1) & 1 == Y[j][k]:
judge = False"""
if judge:
res = max(res,digitSum(i))
print(res) | import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
INF = float('inf')
def main():
s = map(int, input()[::-1])
mod = 2019
counts = [0] * mod
counts[0] = 1
t = 0
x = 1
for num in s:
t = (t + num * x) % mod
counts[t] += 1
x = (x * 10) % mod
ans = 0
for count in counts:
if count > 1:
ans += count * (count - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 76,043,009,189,950 | 262 | 166 |
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
d = defaultdict(int)
for i in range(n):
d[input()] += 1
m = max(d.values())
for s in sorted(filter(lambda x: d[x] == m,d)):
print(s) | n = int(input())
d = dict()
for i in range(n):
s = input()
if(s not in d.keys()):
d[s] = 1
else:
d[s] +=1
max = max(d.values())
ans = []
for i in d.keys():
if(d[i] == max):
ans.append(i)
for i in sorted(ans):
print(i)
| 1 | 70,298,033,932,092 | null | 218 | 218 |
# D - Triangles
import bisect
N=int(input())
Li=list(map(int,input().split()))
Li.sort()
ans=0
for i in range(N):
for j in range (i+1,N):
a=Li[i]+Li[j]
t=bisect.bisect_left(Li,a)
ans+=t-(j+1)
print(ans)
| 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()
| 1 | 171,427,531,869,918 | null | 294 | 294 |
from sys import exit
import copy
#import numpy as np
#from collections import deque
d, = map(int, input().split())
c= list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
# t=[int(input()) for _ in range(d)]
sche=[0 for _ in range(d)]
last=[0 for _ in range(26)]
score=0
for day in range(1,d+1):
idx=day-1
d_tmp=0
i_tmp=0
for t in range(26):
delta=0
l_tmp=copy.copy(last)
delta+=s[idx][t]
l_tmp[t]=day
for l in range(26):
delta-=c[l]*(day-l_tmp[l])
if delta>=d_tmp:
d_tmp=delta
i_tmp=t
sche[idx]=i_tmp
score+=d_tmp
last[i_tmp]=day
# print(score)
print(i_tmp+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 | 41,810,492,019,690 | 113 | 222 |
def main():
import sys
input=sys.stdin.readline
l=lambda: list(map(int,input().split()))
n,d,a=l()
xh=[]
for i in range(n):
xi,hi=l()
xh.append([xi,hi])
xh.sort()
right_index=[]
#尺取り法
tmp=0
for i in range(n):
j=tmp
while xh[j][0]<=xh[i][0]+2*d:
j+=1
if j==n: break
j-=1
right_index.append(j)
tmp=j
ans=0
cnt=0
damage=[0]*(n+1)
for i in range(n):
xh[i][1]-=(ans-cnt)*a
damage_cnt=max(0,(xh[i][1]-1)//a + 1)
ans+=damage_cnt
damage[right_index[i]]+=damage_cnt
cnt+=damage[i]
print(ans)
if __name__=='__main__':
main() | n,d,a=[int(j) for j in input().split()]
xh=[[int(j) for j in input().split()] for i in range(n)]
xh.sort()
from collections import deque
q=deque()
ans=0
dmg=0
for x,h in xh:
while q and q[0][0]<x:
i,j=q.popleft()
dmg-=j
r=h-dmg
if r<=0:
continue
p=-(-r//a)
dmg+=p*a
ans+=p
q.append((x+2*d,p*a))
print(ans)
| 1 | 82,366,728,967,838 | null | 230 | 230 |
N = int(input())
a = list(map(int,(input().split())))
list_a = [0]*2*100001
for i in a:
list_a[i] += 1
for i in range(1,N+1):
print(list_a[i]) | D=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(D):
s.append(list(map(int,input().split())))
t=[]
for i in range(D):
t.append(int(input()))
last_di=[0]*26
m=0
for i in range(D):
m+=s[i][t[i]-1]
last_di[t[i]-1]=i+1
for j in range(26):
m-=c[j]*((i+1)-last_di[j])
print(m)
| 0 | null | 21,388,697,300,700 | 169 | 114 |
N = int(input())
A = [ x for x in input().split(" ")]
orig_A = A[:]
#bubblesort
for i in range(0, N):
for j in range(N-1, i, -1):
if int(A[j][1]) < int(A[j-1][1]):
A[j], A[j-1] = A[j-1], A[j]
print(*A)
print("Stable")
#selectionsort
for i in range(0, N):
minj = i
for j in range(i, N):
if int(orig_A[j][1]) < int(orig_A[minj][1]):
minj = j
orig_A[i], orig_A[minj] = orig_A[minj], orig_A[i]
print(*orig_A)
print("Stable" if A == orig_A else "Not stable") | n = [int(i) for i in input().split()]
print(max(n[0] - 2*n[1], 0)) | 0 | null | 82,974,144,695,970 | 16 | 291 |
a,b,c = map(int,input().split())
k = int(input())
for i in range(k):
if a >= b:
b *= 2
else:
c *= 2
print("Yes" if a < b and b < c else "No")
| a,b,c=list(map(int,input().split()))
print(c,a,b) | 0 | null | 22,443,193,367,530 | 101 | 178 |
import sys
import math
import bisect
def main():
n = int(input())
ans = ((n+1)//2) / n
print('%.10f' % ans)
if __name__ == "__main__":
main()
| S = input()
T = input()
ans = 1e10
for i in range(len(S)):
if i+len(T) > len(S):
break
cnt = 0
for j in range(len(T)):
if S[i+j] != T[j]:
cnt += 1
ans = min(cnt, ans)
print(ans)
| 0 | null | 90,475,850,069,540 | 297 | 82 |
import sys
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def resolve():
a,b,c=map(int, input().split())
if Decimal(a).sqrt()+Decimal(b).sqrt()<Decimal(c).sqrt():
print('Yes')
else:
print('No')
resolve() | N, X, M = map(int, input().split())
ans = 0
C = [0]
Xd = [-1] * (M+1)
for i in range(N):
x = X if i==0 else x**2 % M
if Xd[x] > -1:
break
Xd[x] = i
ans += x
C.append(ans)
loop_len = i - Xd[x]
if loop_len > 0:
S = C[i] - C[Xd[x]]
loop_num = (N - i) // loop_len
ans += loop_num * S
m = N - loop_num * loop_len - i
ans += C[Xd[x]+m] - C[Xd[x]]
print(ans) | 0 | null | 27,172,707,748,900 | 197 | 75 |
H,W = [int(i) for i in input().split()]
h1 = H//2
h2 = H-h1
w2 = W//2
w1 = W-w2
if H==1 or W==1:
print(1)
else:
print(h2*w1+h1*w2) | a,b = map(int,input().split())
ans = 0
if a == 1 or b == 1:
print(1)
elif a*b % 2 == 0:
print(int(a*b/2))
else:
print(int((a*b-1)/2 + 1)) | 1 | 50,700,019,423,104 | null | 196 | 196 |
if __name__ == "__main__":
for num1 in range(0, 9):
for num2 in range(0, 9):
print(str(num1 + 1) + "x" + str(num2 + 1) + "=" + str((num1 + 1) * (num2 + 1))) | # https://atcoder.jp/contests/abc149/tasks/abc149_e
# すべての握手の組み合わせN**2を列挙しソートしM番目までを足し合わせればOK
# だけど制約からこれを行うことは困難
# すべてを列挙しなくともM番目の値を知ることは二分探索で可能(参考:億マス計算)
# Aの累積和を保持しておけば、M番目の値の探索中にMまでの値の合計もついでに計算できる
# 以下reverseでソート済みだと仮定
# XがM番目の数→X以上である数はM個以上(cntとする)→cntがM個以上の条件を満たすうちの最大となるXがM番目の値
# そのあと余分な分を引く処理とか必要
from bisect import bisect_right, bisect_left
import sys
read = sys.stdin.readline
def read_ints():
return list(map(int, read().split()))
class cumsum1d:
def __init__(self, ls: list):
'''
1次元リストを受け取る
'''
from itertools import accumulate
self.ls_accum = [0] + list(accumulate(ls))
def total(self, i, j):
# もとの配列lsにおける[i,j)の中合計
return self.ls_accum[j] - self.ls_accum[i]
N, M = read_ints()
A = read_ints()
A.sort() # bisectを使う都合上 reverseは抜き
A_reversed = list(reversed(A))
A_rev_acc = cumsum1d(A_reversed)
def is_ok(X):
# M番目の数はXである→X以上の個数>=M となるうちで最大のX(もっとも左の方のX)
# X以上の個数>=Mを返す
# X以下の個数はai+aj>=Xを満たす個数
cnt = 0
ans = 0
for a in A:
aa = X - a
idx_reverse = N - bisect_left(A, aa) # 大きい方からだと何番目か
# これはbisect_right(A_reversed,aa)に等しい
cnt += idx_reverse
ans += A_rev_acc.total(0, idx_reverse) + idx_reverse * a
return cnt >= M, ans, cnt
def meguru_bisect(ng, ok):
'''
define is_okと
初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
ng ok は とり得る最小の値-1 とり得る最大の値+1
最大最小が逆の場合はよしなにひっくり返す
'''
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
flg, ans, cnt = is_ok(mid)
if flg:
ok = mid
ans_true = ans # さいごにokとなる状態がans
cnt_true = cnt
else:
ng = mid
return ans_true, ok, cnt_true
ans_tmp, M_th_num, M_plus_alpha_th = \
meguru_bisect(2 * 10 ** 5 + 1, 0)
# print(ans_tmp, M_th_num, M_plus_alpha_th)
print(ans_tmp - (M_plus_alpha_th - M) * M_th_num)
| 0 | null | 54,181,794,747,138 | 1 | 252 |
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_stack=deque([])
now=0
mn=0
j=0
for i in a:
mn+=i
if mn>k:
mn-=i
break
else:
now+=1
a_stack.append(i)
for i in b:
mn+=i
if mn>k:
mn-=i
break
else:
now+=1
j+=1
if j==m:
print(now)
exit()
ans=now
while a_stack:
if j>=m:
break
else:
q=a_stack.pop()
mn-=q
now-=1
while k-mn>0:
mn+=b[j]
now+=1
if k-mn<0:
now-=1
mn-=b[j]
break
j+=1
if j==m:
break
ans=max(now,ans)
print(ans) | from collections import deque
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
da = deque()
i = 0
tmpK = 0
while tmpK <= K and i < N:
tmpK += A[i]
da.append(A[i])
i += 1
# 一冊多い場合がある
if (tmpK > K):
i -= 1
tmpK -= da.pop()
# Bを増やしていく
db = deque()
j = 0
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
tmptot = i+j
while len(da) > 0:
tmpK -= da.pop()
i -= 1
while tmpK <= K and j < M:
tmpK += B[j]
db.append(B[j])
j += 1
# 一冊多い場合がある
if (tmpK > K):
j -= 1
tmpK -= db.pop()
if tmptot < i+j:
tmptot = i+j
print(tmptot) | 1 | 10,831,323,523,484 | null | 117 | 117 |
a,b,c,k=map(int,input().split())
if k<=a:
ans=k
elif k>a and k<=a+b:
ans=a
else:
ans=a-(k-(a+b))
print(ans) | x = raw_input().split()
m = map(int,x)
a = x[0]
b = x[1]
c = x[2]
if a < b and b< c:
print "Yes"
else:
print"No" | 0 | null | 11,071,128,359,798 | 148 | 39 |
x, y = map(int, input().split())
ans = 'No'
for i in range(x + 1):
j = x - i
if i * 2 + j * 4 == y:
ans = 'Yes'
break
print(ans)
| N, K, C = map(int, input().split())
S = input()
L = [0] * K
i = 0
x = 0
while i<K and x<N:
if S[x] == 'o':
L[i] = x
i += 1
x += C+1
else:
x += 1
R = [0] * K
i = K-1
x = N-1
while i>=0 and x>=0:
if S[x] == 'o':
R[i] = x
i -= 1
x -= C+1
else:
x -= 1
ans = []
for i in range(K):
if L[i] == R[i]:
ans.append(L[i])
for a in ans:
print(a+1)
| 0 | null | 27,147,675,583,908 | 127 | 182 |
n,k,s = map(int,input().split())
a = [s] * n
for i in range(k,n):
a[i] +=1-(s==10**9)*s
print(*a)
| n, k, s = map(int, input().split())
a = [s] * k + [1 if n < s else s + 1] * (n - k)
print(*a) | 1 | 90,826,878,571,770 | null | 238 | 238 |
n,d = map(int,input().split())
ans = 0
for i in range(n):
x,y = map(int,input().split())
if x**2+y**2 <= d**2:
ans += 1
print(ans) | N = input()
if (N[-1] == str(3)):
print('bon')
elif(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8 ):
print('pon')
else:
print('hon') | 0 | null | 12,638,313,674,308 | 96 | 142 |
n = int(input())
l = {'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(n):
l[input()] += 1
print('AC x',l['AC'])
print('WA x',l['WA'])
print('TLE x',l['TLE'])
print('RE x',l['RE']) | A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result = min(a) + min(b)
for _ in range(M):
x, y, c = map(int, input().split())
discount = a[x-1] + b[y-1] - c
result = min(result, discount)
print(result) | 0 | null | 31,453,121,320,530 | 109 | 200 |
s = input()
if(s == 'hi'):
print('Yes')
elif(s == 'hihi'):
print('Yes')
elif(s == 'hihihi'):
print('Yes')
elif(s == 'hihihihi'):
print('Yes')
elif(s == 'hihihihihi'):
print('Yes')
else:
print('No')
| X, Y, Z = list(map(str, input().split()))
print(Z + " " + X + " " + Y)
| 0 | null | 45,661,396,244,568 | 199 | 178 |
N = int(input())
pos = []
for _ in range(N):
x, l = map(int,input().split())
pos.append((x+l, x-l))
pos.sort()
ans = 0
cur = float('-inf')
for i in range(N):
if cur <= pos[i][1]:
ans += 1
cur = pos[i][0]
print(ans) | #区間スケジューリング問題
N = int(input())
robots = {}
for _ in range(N):
X, L = list(map(int, input().split()))
robots[X] = (X-L, X+L)
#終端が早い順にソートして、取れるものから貪欲法でとっていく
robots_sorted = sorted(robots.items(), key=lambda x:x[1][1])
ans = 1
current_robot = robots_sorted[0]
for i in range(0, N):
if current_robot[1][1] > robots_sorted[i][1][0]:
continue
ans += 1
current_robot = robots_sorted[i]
print(ans)
| 1 | 89,587,437,089,822 | null | 237 | 237 |
print(((1/3)*float(input("")))**3) | a, b, c = map(int, input().split())
divisors = []
i = 1
while(i * i < c):
if(c % i == 0):
divisors.append(i)
divisors.append(c // i)
i += 1
if(i * i == c):
divisors.append(i)
ans = 0
for i in range(len(divisors)):
if(a <= divisors[i] <= b):
ans += 1
print(ans) | 0 | null | 23,911,170,756,448 | 191 | 44 |
N,K = map(int,input().split())
S = set()
for i in range(K) :
D=int(input())
L=list(map(int, input().split()))
for A in L :
S.add(A)
print (N-len(S))
| # -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 22:03:19 2020
@author: liang
"""
N, X, M = map(int,input().split())
mod_set = {X}
mod_lis = [X]
A = [0]*(10**6+1)
A[0] = X
flag = False
#for i in range(1,N):
i = 1
for i in range(1,min(10**6,N)):
tmp = A[i-1]**2%M
if tmp in mod_set:
flag = True
break
A[i] = tmp
mod_set.add(tmp)
mod_lis.append(tmp)
if flag:
j = mod_lis.index(tmp)
else:
j = i
T = i - j
ans = 0
if T != 0:
#print("A")
ans += sum(mod_lis[:j])
T_sum = sum(mod_lis[j:])
"""
【切り捨て演算は必ず()をつけて先に計算】
"""
ans += T_sum * ((N-j)//T)
#print((N-j)//T, T_sum)
T_lis = mod_lis[j:i]
ans += sum(T_lis[:(N-j)%T])
else:
#print("B")
ans = sum(mod_lis)
# print(mod_lis)
#print(T_lis)
#print((N-j)%T)
#print(T_lis[:10])
print(ans)
#print(T_sum)
#print(sum(T_lis)) | 0 | null | 13,665,878,396,840 | 154 | 75 |
N, M = list(map(int,input().split()))
e = True
c = [-1 for i in range(N)]
for i in range(M):
si, ci = list(map(int,input().split()))
if c[si-1]>-1 and c[si-1]!=ci:
e = False
c[si-1] = ci
if e and (N==1 or c[0]!=0):
print(max(0 if N==1 else 1, c[0]),end="")
for i in range(1,N):
print(max(0,c[i]),end="")
print()
else:
print(-1) | # -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 17:36:58 2020
@author: liang
"""
"""
全探索
"""
N, M = map(int, input().split())
test = list()
for _ in range(M):
s,c = map(int,input().split())
test.append((s,c))
#print(test)
tmp = [0]*3
for i in range(10**N):
tmp[0] = i//100
tmp[1] = i//10%10
tmp[2] = i%10
#print(tmp)
for tup in test:
s, c = tup[0], tup[1]
if tmp[(3-N)+s-1] != c:
break
else:
#最上位の桁が0でないか
if tmp[-N] == 0 and N != 1:
continue
print(i)
break
else:
print(-1) | 1 | 60,521,108,342,452 | null | 208 | 208 |
[ a, b, c ] = map ( int, input ( ).split ( ) );
if a < b < c:
print ( "Yes" )
else:
print ( "No" ) | n, u, v = map(int, input().split())
u -= 1
v -= 1
ab = [list(map(int, input().split())) for _ in range(n - 1)]
adj = [[] for _ in range(n)]
for a, b in ab:
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
def dfs(s):
d = [-1] * n
d[s] = 0
stack = [s]
while stack:
frm = stack.pop()
for to in adj[frm]:
if d[to] == -1:
d[to] = d[frm] + 1
stack.append(to)
return d
du = dfs(u)
dv = dfs(v)
ans = 0
for eu, ev in zip(du, dv):
if eu < ev:
ans = max(ans, ev - 1)
print(ans)
| 0 | null | 58,686,038,416,160 | 39 | 259 |
N,K=map(int,input().split())
*A,=map(int,input().split())
def C(x):
return sum([(A[i]-.5)//x for i in range(N)]) <= K
def binary_search2(func, n_min, n_max):
left,right=n_min,n_max
while right-left>1:
middle = (left+right)//2
y_middle = func(middle)
if y_middle: right=middle
else: left=middle
return right
print(binary_search2(C, 0, max(A)+1)) | s = input()
n = len(s)
t = input()
m = len(t)
c_max = 0
for i in range(n - m + 1):
c = 0
for j in range(m):
if s[i + j] == t[j]:
c += 1
if c > c_max:
c_max = c
print(m - c_max) | 0 | null | 5,061,321,406,240 | 99 | 82 |
k = int(input())
a, b = map(int, input().split())
f = False
for x in range(a, b+1):
if x % k == 0:
f = True
print('OK' if f else 'NG') | def ctoi(x):
return ord(x)-ord("a")
n = int(input())
s = list(input())
q = int(input())
bit = [[0]*(n+1) for _ in range(26)]
def update(pos,a,x):
while pos<=n:
bit[a][pos] += x
pos += pos&(-pos)
def query(pos):
ret=[0]*26
for i in range(26):
tmp=0
p=pos
while p>0:
tmp+=bit[i][p]
p-=p&(-p)
ret[i]=tmp
return ret
for i in range(n):
update(i+1,ctoi(s[i]),1)
for _ in range(q):
flag,a,b = input().split()
flag=int(flag)
a=int(a)
if flag==1:
if s[a-1]==b:
continue
else:
update(a,ctoi(s[a-1]),-1)
update(a,ctoi(b),1)
s[a-1]=b
else:
b=int(b)
c1 = query(b)
c2 = query(a-1)
ans = 0
for i in range(26):
if c1[i]-c2[i]>0:
ans += 1
print(ans) | 0 | null | 44,677,540,212,440 | 158 | 210 |
N, K = map(int,input().split())
ans = 0
MOD = 10**9+7
for i in range(K,N+2):
num = ((2*N-i+1)*i)//2 - ((i-1)*i)//2 +1
ans+=num%MOD
ans%=MOD
print(ans) | n = input()
l = [int(i) for i in input().split()]
print(' '.join([str(min(l)),str(max(l)),str(sum(l))])) | 0 | null | 17,074,000,705,750 | 170 | 48 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N,T,*ab = map(int, read().split())
AB = []
for a, b in zip(*[iter(ab)]*2):
AB.append((a, b))
AB.sort()
dp = [[0] * (T+1) for _ in range(N+1)]
ans = 0
for i in range(N):
w_i, v_i = AB[i]
for j in range(T):
if j < w_i:
dp[i+1][j] = dp[i][j]
else:
dp[i+1][j] = max(dp[i][j - w_i] + v_i, dp[i][j])
ans = max(ans, dp[i][T-1] + v_i)
print(ans)
if __name__ == "__main__":
main()
| from collections import defaultdict
import bisect
def f():
return []
d=defaultdict(f)
n=int(input())
a=list(map(int,input().split()))
x=[i+1+a[i] for i in range(n)]
y=[i+1-a[i] for i in range(n)]
for i in range(n):
d[y[i]].append(i)
ans=0
for i in range(n):
ans+=len(d[x[i]])
print(ans) | 0 | null | 88,538,146,025,548 | 282 | 157 |
n = int(input())
a = list(map(int, input().split()))
length = len(a)
total = sum(a)
ans = 0
for i in range(0,length):
total -= a[i]
ans += (a[i] * total)
print(ans % (10**9 + 7)) | # coding: utf-8
# 日本語を入力できるようにするために上記一文が必要
N = int(input())
A_input = list(map( int, input().split()))
j_sum = 0
for j in range(N):
j_sum = j_sum + A_input[j]
sum = 0
for i in range(N - 1 ):
j_sum = j_sum - A_input[i]
sum = sum + A_input[i] * j_sum
print(sum % (10**9 + 7) ) | 1 | 3,849,946,582,602 | null | 83 | 83 |
N = int(input())
min_v = int(input())
r = int(input())
max_v = r - min_v
if min_v > r:
min_v = r
for _n in range(2, N):
r = int(input())
if max_v < r - min_v:
max_v = r - min_v
if min_v > r:
min_v = r
print(max_v)
| dif_max = 1-10**9
min = 10**9
n_max = 0
n_max = int(raw_input())
price = [0]*n_max
for i in range(0, n_max):
price[i] = int(raw_input())
for i in range(0, n_max-1):
if min >= price[i]:
min = price[i]
if dif_max <= price[i+1] - min:
dif_max = price[i+1] - min
print dif_max | 1 | 12,969,900,368 | null | 13 | 13 |
# coding: utf-8
def check_divide(n):
max_v = int(n ** (1/2))
divide_nums = []
for i in range(1,max_v + 1):
if n % i == 0:
divide_nums.append(i)
return divide_nums
def check_divide2(n):
divide_nums = []
for K in range(2,n+1):
tmp = n
while True:
if tmp % K ==0:
tmp = tmp // K
else:break
if tmp % K == 1:
divide_nums.append(K)
return divide_nums
if __name__ == '__main__':
N = int(input())
tmp1 = check_divide(N-1)
if tmp1[-1] ** 2 == N-1:
tmp1 = len(tmp1) * 2 - 2
else:
tmp1 = len(tmp1) * 2 - 1
candidates = check_divide(N)[1:]
tmp2 = [N]
for val in candidates:
N_ = N
while True:
if N_ % val == 0:
N_ = N_ / val
else:break
if N_ % val == 1:
tmp2.append(val)
tmp2 = len(tmp2)
print(tmp1 + tmp2) | def main():
N = int(input())
R = tuple(int(input()) for _ in range(N))
min_ = float('inf')
max_ = -float('inf')
for i in range(N):
max_ = max(max_, R[i] - min_)
min_ = min(min_, R[i])
print(max_)
main() | 0 | null | 20,780,155,053,100 | 183 | 13 |
N = int(input())
ans = set()
for i in range(N):
ans.add(input())
print(len(ans)) | N = int(input())
s = [0] * N
for i in range(N):
s[i] = input()
d = set()
for v in s:
d.add(v)
print(len(d))
| 1 | 30,271,064,150,080 | null | 165 | 165 |
def nCr(n, r, mod):
x, y = 1, 1
for r_ in range(1, r+1):
x = x*(n+1-r_)%mod
y = y*r_%mod
return x*pow(y, mod-2, mod)%mod
x, y = map(int, input().split())
mod = 10**9+7
if (x+y)%3 or 2*x<y or 2*y<x:
print(0)
else:
print(nCr((x+y)//3,(2*x-y)//3, mod)) | 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,582,895,430,760 | null | 281 | 281 |
N = int(input())
A_ls = input().split(' ')
rst = set()
for i in A_ls:
rst.add(i)
if len(rst) == N:
print('YES')
else:
print('NO') | n = int(input())
a = set(input().split())
print('YES' if (len(a) == n) else 'NO') | 1 | 73,470,178,444,360 | null | 222 | 222 |
from collections import deque
h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def bfs(i, j):
cost = [[-1 for _ in range(w)] for _ in range(h)]
que = deque()
cost[i][j] = 0
que.append((i, j))
if s[i][j] == '#':
return 0
while que:
ni, nj = que.popleft()
for k in range(4):
if 0 <= ni+dy[k] < h and 0 <= nj+dx[k] < w:
if cost[ni+dy[k]][nj+dx[k]] != -1:
continue
if s[ni+dy[k]][nj+dx[k]] == '.':
cost[ni+dy[k]][nj+dx[k]] = cost[ni][nj]+1
que.append((ni+dy[k], nj+dx[k]))
cc = 0
for i in range(h):
for j in range(w):
if cost[i][j] > cc:
cc = cost[i][j]
return cc
ans = 0
for i in range(h):
for j in range(w):
cost = bfs(i, j)
ans = max(ans, cost)
print(ans)
| from math import sqrt
N = int(input())
search_max = int(sqrt(N))
min_number = 10**12
for x in range(1, search_max + 1):
if N % x == 0:
y = N // x
if x + y < min_number:
min_number = x + y
print(min_number-2) | 0 | null | 128,126,218,031,900 | 241 | 288 |
inputEnzan=input().split()
def keisan(inputEnzan):
while True:
stockFornumber=[]
index=0
length=len(inputEnzan)
if length==1:
break
while index<length:
if inputEnzan[index]=="+" or inputEnzan[index]=="-" or inputEnzan[index]=="*":
if len(stockFornumber)==2:
if inputEnzan[index]=="+":
inputEnzan[index]=stockFornumber[0]+stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
elif inputEnzan[index]=="-":
inputEnzan[index]=stockFornumber[0]-stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
else:
inputEnzan[index]=stockFornumber[0]*stockFornumber[1]
stockFornumber=[]
inputEnzan[index-1]="null"
inputEnzan[index-2]="null"
else:
stockFornumber=[]
pass
else:
if len(stockFornumber)==2:
del stockFornumber[0]
stockFornumber.append(int(inputEnzan[index]))
index+=1
while "null" in inputEnzan:
inputEnzan.remove("null")
print(inputEnzan[0])
keisan(inputEnzan)
| input()
nums = [int(x) for x in input().split(" ")]
print("{0} {1} {2}".format(min(nums), max(nums), sum(nums))) | 0 | null | 392,552,253,938 | 18 | 48 |
x = int(input())
flag = 0
for a in range(x):
b5 = a**5 - x
for b in range(120):
if abs(b5) == int(b**5):
if b5 < 0:
b = -b
flag = 1
break
if flag:
break
print(a, int(b))
| print(int(input()) * 3.142 * 2)
| 0 | null | 28,375,783,973,152 | 156 | 167 |
import sys
def main():
dp = [[0] * W for _ in range(H)]
for y in range(H):
for x in range(W):
if x == 0 and y == 0:
if s[0][0] == "#":
dp[0][0] = 1
elif x == 0:
if s[y][x] == "#" and s[y - 1][x] == ".":
dp[y][x] = dp[y - 1][x] + 1
else:
dp[y][x] = dp[y - 1][x]
elif y == 0:
if s[y][x] == "#" and s[y][x - 1] == ".":
dp[y][x] = dp[y][x - 1] + 1
else:
dp[y][x] = dp[y][x - 1]
else:
if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
elif s[y][x] == "#" and s[y][x - 1] == ".":
dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
elif s[y][x] == "#" and s[y - 1][x] == ".":
dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
else:
dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])
print(dp[-1][-1])
if __name__ == "__main__":
H, W = map(int, sys.stdin.readline().split())
s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
main() | N, P = map(int, input().split())
S = input()
ans = 0
if P == 2 or P == 5 :
for i in range(N) :
if int(S[i])%P == 0 :
ans += i+1
print(ans)
exit()
modP = [0 for _ in range(P)]
modP[0] = 1
now = 0
t = 1
for i in range(N) :
now += int(S[-1-i]) * t
now %= P
modP[now] += 1
t = t * 10 % P
for r in modP :
ans += r*(r-1)//2
print(ans)
| 0 | null | 53,738,723,648,470 | 194 | 205 |
a = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
a = a * 2
c = 0
z = input()
for i in range(0,7):
if z == a[i]:
for j in range(i + 1, 14):
if a[j] == "SUN":
print(j - i )
| n = int(input())
li = ["#"*20 if i%4==0 else "0"*10 for i in range(1, 16)]
for _ in range(n):
b, f, r, v = map(int, input().split())
h = 4*b-(4-f)-1
li[h] = li[h].replace(li[h], ''.join([str(int(list(li[h])[r-1])+v) if i == r-1 else list(li[h])[i] for i in range(10)]))
li = [' '+' '.join(li[i]) if (i+1)%4!=0 else li[i] for i in range(len(li))]
print('\n'.join(li))
| 0 | null | 66,947,415,305,712 | 270 | 55 |
#標準入力を高速に
import sys
input = sys.stdin.readline
def factorial_mod(x, y, mod):
factorial = 1
for i in range(x,y+1):
factorial *= i
factorial %= mod
return factorial
def n_C_k(n, k, mod, fact):
inv = (pow(fact[n-k], mod-2, mod) * pow(fact[k], mod-2, mod)) % mod
return (fact[n] * inv) % mod
"""
#main関数(若干早くなる)
def main():
mod = 10**9+7
n, k = map(int, input().split())
ans = 1+n*(n-1)
a = n
b = n-1
for i in range(1, min(n, k)):
temp1 = (n-i)*pow(i+1, mod-2, mod)%mod
a *= temp1
a %= mod
temp2 = (n-1-i)*pow(i+1, mod-2, mod)%mod
b *= temp2
b %= mod
temp3 = a*b%mod
ans += temp3
ans %= mod
print(ans)
"""
#main関数(若干早くなる)
def main():
mod = 10**9+7
n, k = map(int, input().split())
ans = (1+n*(n-1))%mod
#階乗を使いまわすver.
fact = [1]*(n+1)
for i in range(1, n+1):
fact[i] = fact[i-1]*i
fact[i] %= mod
for i in range(2, min(n-1, k)+1):
ans += n_C_k(n, i, mod, fact)*n_C_k(n-1, i, mod, fact)
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| n,k = map(int, input().split())
mod = 10**9+7
def prepare():
fact = []
f = 1
for m in range(1, n):
f *= m
f %= mod
fact.append(f)
f *= n
f %= mod
fact.append(f)
factinv = [1, 1]
inv = [0, 1]
for i in range(2, n + 1):
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
return fact, factinv
def cmb(a, r, p):
if (r < 0) or (n < r):
return 0
if a == 1:
return f[a] * v[r] * v[n - r] % mod
else:
return f[a] * v[r] * v[n - r - 1] % mod
f,v = prepare()
ans = 1
for i in range(1, min(k + 1, n)):
ans += cmb(0, i, mod) * cmb(1, i, mod)
ans %= mod
print(ans)
| 1 | 67,003,203,931,298 | null | 215 | 215 |
N,M = map(int,input().split())
S = []
C = []
for a in range(M):
s,c = map(int,input().split())
S.append(s)
C.append(c)
a = ["0"]*N
e = []
for b,d in zip(S,C):
if b in e:
if str(d) != a[b-1]:
print(-1)
exit()
elif b == 1 and d == 0:
if N != 1:
print(-1)
exit()
else:
e.append(b)
a[b-1] = str(d)
if a[0] == "0" and N != 1:
a[0] = "1"
answer = ''.join(a)
answer = int(answer)
print(answer) | N = int(input())
S = input()
ret = ''
for s in S:
o = ord(s) - ord('A') + N
ret += chr(ord('A') + o % 26)
print(ret) | 0 | null | 97,842,690,837,558 | 208 | 271 |
# A - Sum of Two Integers
N = int(input())
if N % 2 == 1:
N += 1
print(int(N / 2 - 1)) | def kakeru(x):
for i in range(1,10):
a = x * i
print(str(x) + 'x' +str(i) + '=' + str(a))
for i in range (1,10):
kakeru(i) | 0 | null | 77,015,157,941,962 | 283 | 1 |
import itertools
def main():
N, M, Q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(Q):
ai, bi, ci, di = list(map(int, input().split()))
a.append(ai)
b.append(bi)
c.append(ci)
d.append(di)
ans = 0
for A in list(itertools.combinations_with_replacement(range(1, M+1), N)):
# print(A)
score = 0
for i in range(Q):
if A[b[i]-1] - A[a[i]-1] == c[i]:
score += d[i]
if ans < score:
ans = score
print(ans)
if __name__ == "__main__":
main()
| from collections import deque
N, M, Q = map(int, input().split())
A = [list(map(int, input().split())) for i in range(Q)]
def calc(x):
ans = 0
for a, b, c, d in A:
if int(x[b-1]) - int(x[a-1]) == c:
ans += d
return ans
q = deque([[1]])
ans = 0
while q:
tmp = q.popleft()
if len(tmp) == N:
ans = max(ans, calc(tmp))
else:
for i in range(tmp[-1], M+1):
q.append(tmp+[i])
print(ans) | 1 | 27,662,215,793,032 | null | 160 | 160 |
list = []
while True:
line = raw_input()
list.append(line)
if line == "0":
break
i = 0
for x in list[:-1]:
i += 1
print "Case %d: %s" % (i, x) | 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)
| 0 | null | 2,657,285,562,532 | 42 | 90 |
n=int(input())
a=list(map(int,input().split()))
l=[0,0,0]
mod=10**9+7
ans=1
for i in a:
ans*=l.count(i)
ans%=mod
for j in range(3):
if l[j]==i:
l[j]+=1
break
print(ans) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
ans = 1
cnt = [0] * (n+1)
for i in range(n):
if a[i] == 0:
ans *= 3 - cnt[0]
ans %= mod
else:
ans *= cnt[a[i]-1] - cnt[a[i]]
ans %= mod
cnt[a[i]] += 1
print(ans) | 1 | 130,133,355,333,138 | null | 268 | 268 |
from itertools import combinations
n = int(input())
l = list(map(int, input().split()))
comb = list(combinations(range(n), 3))
ans = 0
for i,j,k in comb:
a = l[i]
b = l[j]
c = l[k]
if a == b:
continue
if b == c:
continue
if c == a:
continue
if sum([a,b,c]) <= 2 * max(a,b,c):
continue
ans += 1
print(ans)
| n = int(input())
ls = sorted(list(map(int, input().split())))
cnt = 0
for i in range(len(ls) - 2):
a = ls[i]
for j in range(i+1, len(ls) - 1):
b = ls[j]
for k in range(j+1, len(ls)):
c = ls[k]
if a==b or a==c or b==c:
continue
if a+b > c and b+c > a and c+a > b:
cnt += 1
print(cnt) | 1 | 5,068,918,980,512 | null | 91 | 91 |
def calc_number_of_coin(sum, coins):
dp = [999999999]*(sum+1)
dp[0] = 0
for i in range(len(coins)):
for j in range(coins[i], sum+1):
dp[j] = min(dp[j], dp[j-coins[i]]+1)
return dp[sum]
if __name__ == '__main__':
# ??????????????\???
# f = open('input.txt')
# sum, _ = [int(x) for x in f.readline().strip().split(' ')]
# coins = [int(x) for x in f.readline().strip().split(' ')]
sum, _ = [int(x) for x in input().strip().split(' ')]
coins = [int(x) for x in input().strip().split(' ')]
# ???????????????
result = calc_number_of_coin(sum, coins)
# ???????????¨???
print(result) | lis=[]
for i in range(10):
h=int(input())
lis.append(h)
for i in range(10):
for j in range(i+1,10):
if lis[i]<lis[j]:
a=lis[i]
lis[i]=lis[j]
lis[j]=a
for i in range(3):
print(lis[i]) | 0 | null | 68,120,992,818 | 28 | 2 |
while True:
m, f, r = [int (x) for x in input().split(' ')]
if m == -1 and f == -1 and r == -1: break
if m == -1 or f == -1 or m + f < 30:
print('F')
elif m + f >= 80:
print('A')
elif m + f >= 65 and m + f < 80:
print('B')
elif m + f >= 50 and m + f < 65:
print('C')
elif m + f >= 30 and m + f < 50:
if r >= 50:
print('C')
else:
print('D') | # -*- coding: utf-8 -*-
while True:
score = list(map(int, input().split()))
if score[0] == -1 and score[1] == -1 and score[2] == -1:
break
elif -1 in (score[0], score[1]) or (score[0] + score[1]) < 30:
print('F')
elif (score[0] + score[1]) >= 80:
print('A')
elif 65 <= (score[0] + score[1]) < 80:
print('B')
elif 50 <= (score[0] + score[1]) < 65 or (30 <= (score[0] + score[1]) < 50 <= score[2]):
print('C')
elif 30 <= (score[0] + score[1]) < 50:
print('D')
| 1 | 1,244,799,280,992 | null | 57 | 57 |
print((lambda x:(1/2 if (x%2 == 0) else (x//2+1)/x))(int(input())))
| n=int(input())
def dfs(s):
if len(s)==n:print(s)
else:
for i in range(97,ord(max(s))+1+1):
dfs(s+chr(i))
dfs("a")
| 0 | null | 114,608,761,915,408 | 297 | 198 |
K = int(input())
id = 1
cnt = 7
while cnt < K:
cnt = cnt * 10 + 7
id += 1
visited = [0] * K
while True:
remz = (cnt % K)
if remz == 0:
break
visited[remz] += 1
if visited[remz] > 1:
id = -1
break
cnt = remz * 10 + 7
id += 1
print(id)
| k = int(input())
l = []
if 7 % k == 0:
print(1)
exit(0)
l.append(7 % k)
for i in range(1,k):
a = (10 * l[i-1] + 7)
if a % k == 0:
print(i+1)
exit(0)
else:
l.append(a % k)
print(-1) | 1 | 6,074,634,549,568 | null | 97 | 97 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
A = list(map(int, readline().split()))
if sum(A) >= 22:
print("bust")
else:
print("win")
if __name__ == '__main__':
main()
| def main():
a = map(int, input().split(" "))
print("bust" if sum(a) >= 22 else "win")
main()
| 1 | 118,839,380,778,652 | null | 260 | 260 |
N,K=map(int,input().split())
mod=10**9+7
X=[0]+[pow(K//d,N,mod) for d in range(1,K+1)]
'''
Y=[[] for i in range(K+1)]
for i in range(1,K+1):
for j in range(i,K+1,i):
Y[j].append(i)
'''
#print(X)
isPrime=[1 for i in range(K+1)]
isPrime[0]=0;isPrime[1]=0
for i in range(K+1):
if isPrime[i]==0:
continue
for j in range(2*i,K+1,i):
isPrime[j]=0
Mebius=[1 for i in range(K+1)]
Mebius[0]=0
for i in range(2,K+1):
if isPrime[i]==0:
continue
for j in range(i,K+1,i):
Mebius[j]*=-1
for i in range(2,K+1):
for j in range(i*i,K+1,i*i):
Mebius[j]=0
Z=[0 for i in range(K+1)]
for i in range(1,K+1):
for j in range(i,K+1,i):
Z[i]+=X[j]*Mebius[j//i]
ans=0
for i in range(1,K+1):
ans+=Z[i]*i
ans%=mod
print(ans)
'''
P(G%d==0)
Gがd,2d,3d,...の可能性がある
P(d)-P(2d)-P(3d)-P(5d)+P(6d)-P(7d)
''' | import math
n, k = map(int, input().split())
dic = {} #ここに結果を保存していく。
ans = 0
moddo = 10**9+7
for i in range(k):
t = k - i #これで大きいほうから順にとる。
if t > k/2: #tがk/2より大きいときはすべてtじゃないと最大公約数はtにならない。
dic[t] = 1
ans += t
else:
temp = pow(k//t,n,moddo)
#print(temp)
fac = 2
while fac*t <= k:
temp -= dic[fac*t]
fac += 1
dic[t] = temp%moddo
ans = (ans+((temp*t)%moddo))%moddo
print(ans) | 1 | 36,632,497,693,760 | null | 176 | 176 |
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read
def main():
global field
R, C, K = map(int, input().split())
field = []
for _ in range(R):
tmp = [0] * C
field.append(tmp)
DP1 = copy.deepcopy(field)
DP2 = copy.deepcopy(field)
DP3 = copy.deepcopy(field)
for _ in range(K):
r, c, k = map(int, input().split())
field[r-1][c-1] = k
i = 0
DP1[0][0] = field[0][0]
for j in range(1, C):
DP3[i][j] = max(DP2[i][j-1] + field[i][j], DP3[i][j-1])
DP2[i][j] = max(DP1[i][j-1] + field[i][j], DP2[i][j-1])
DP1[i][j] = max(field[i][j], DP1[i][j-1])
for i in range(1, R):
for j in range(C):
DP3[i][j] = max(DP2[i][j-1] + field[i][j], DP3[i][j-1])
DP2[i][j] = max(DP1[i][j-1] + field[i][j], DP2[i][j-1])
DP1[i][j] = max(field[i][j], DP1[i][j-1], max(DP1[i-1][j], DP2[i-1][j], DP3[i-1][j]) + field[i][j])
ans = max(DP3[R-1][C-1], DP2[R-1][C-1], DP1[R-1][C-1])
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}
for _ in range(K):
r, c, v = map(int, input().split())
B[(r, c)] = v
dp = [[0]*(W+1) for _ in range(4)]
for i in range(1, H+1):
for j in range(1, W+1):
if (i, j) in B:
v = B[(i, j)]
dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
dp[1][j] = max(dp[1][j-1], dp[0][j]+v)
dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v)
dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v)
else:
dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j])
dp[1][j] = dp[1][j-1]
dp[2][j] = dp[2][j-1]
dp[3][j] = dp[3][j-1]
print(max(dp[i][-1] for i in range(4)))
| 1 | 5,538,858,315,900 | null | 94 | 94 |
n = int(input())
ans = ''
while n:
n -= 1
ans += chr(ord('a') + n % 26)
n //= 26
print(ans[::-1]) | n = int(input())
ans = ''
# 制約条件は高々 26 の 10 乗なので、取り合えずインデックスを13に設定して回す
for i in range(1, 13):
if n <= 26**i:
n -= 1
for j in range(i):
ans += chr(ord('a') + n%26)
n //= 26
break;
else:
n -= 26**i
print(ans[::-1]) | 1 | 12,018,422,492,102 | null | 121 | 121 |
N = int(input())
S = list(input() for _ in range(N))
X = []
for s in S:
l,r = 0,0
for c in s:
if c == ")":
if r > 0:
r -= 1
else:
l += 1
else:
r += 1
X.append([l,r])
X.sort(key = lambda x:x[0])
Y = []
L = 0
for p,q in X:
if p > L:
print("No")
quit()
if q >= p:
L -= p
L += q
else:
Y.append([p,q])
Y.sort(key = lambda x:-x[1])
for a,b in Y:
if a > L:
print("No")
quit()
L -= a
L += b
if L:
print("No")
else:
print("Yes") | import sys
n=int(input())
s=[list(input()) for i in range(n)]
L1=[]
L2=[]
for i in range(n):
ct3=0
l=[0]
for j in s[i]:
if j=='(':
ct3+=1
l.append(ct3)
else:
ct3-=1
l.append(ct3)
if l[-1]>=0:
L1.append((min(l),l[-1]))
else:
L2.append((min(l)-l[-1],-l[-1]))
L1.sort()
L1.reverse()
ct4=0
for i in L1:
if ct4+i[0]<0:
print('No')
sys.exit()
ct4+=i[1]
L2.sort()
L2.reverse()
ct5=0
for i in L2:
if ct5+i[0]<0:
print('No')
sys.exit()
ct5+=i[1]
if ct4!=ct5:
print('No')
sys.exit()
print('Yes') | 1 | 23,592,597,990,360 | null | 152 | 152 |
import math
K = int(input())
ans = 0
for i in range(K):
for t in range(K):
for j in range(K):
gcd1 = math.gcd(i+1,t+1)
gcd2 = math.gcd(gcd1,j+1)
ans += gcd2
print(ans) | import math
n=int(input())
ans=0
for a in range(1,n+1):
for b in range(1,n+1):
d=math.gcd(a,b)
if d==1:
ans+=n
continue
if d==2:
ans+=n//2*3+n%2
continue
if d==3:
ans+=n//3*5+n%3
continue
if d==5:
ans+=n//5*9+n%5
continue
for c in range(1,n+1):
ans += math.gcd(c,d)
print(ans) | 1 | 35,353,226,781,962 | null | 174 | 174 |
n = input()
arr = [map(int,raw_input().split()) for _ in range(n)]
tou = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for line in arr:
b,f,r,v = line
tou[b-1][f-1][r-1] = tou[b-1][f-1][r-1] + v
for i in range(4):
for j in range(3):
print ' '+' '.join(map(str,tou[i][j]))
if i < 3 :
print '#'*20 | import sys
import math
import bisect
from collections import defaultdict,deque
# input = sys.stdin.readline
def inar():
return [int(el) for el in input().split()]
# def find(a,b,c):
# gc=math.gcd(a,b)
# return math.gcd(gc,c)
def main():
n=int(input())
string=input()
r=[]
g=[]
b=[]
for i in range(n):
if string[i]=="R":
r.append(i)
elif string[i]=="G":
g.append(i)
else:
b.append(i)
ans=0
r.sort()
g.sort()
b.sort()
# print(r)
# print(g)
# print(b)
# print(len(b))
# ans1=0
# fir=[]
# for i in range(len(r)):
# for j in range(len(g)):
# for k in range(len(b)):
# ls=[r[i],g[j],b[k]]
# ls.sort()
# if ls[1]-ls[0]!=ls[2]-ls[1]:
# ans1+=1
# fir.append(ans1)
# # print(ans1)
# print("-------------------check---------------")
# are=[]
for i in range(len(r)):
for j in range(len(g)):
ans+=len(b)
chota=min(g[j],r[i])
bada=max(g[j],r[i])
diff=bada-chota
left=bisect.bisect_left(b,bada+diff)
right=bisect.bisect_left(b,chota-diff)
lol=(bada+chota)
if lol%2==0:
beech=lol//2
ind=bisect.bisect_left(b,beech)
if ind<len(b) and b[ind]==beech:
ans-=1
if (left<len(b) and b[left]==bada+diff):
ans-=1
if (right<len(b) and b[right]==chota-diff):
ans-=1
# are.append(ans)
print(ans)
# for i in range(len(are)):
# print(are[i],fir[i])
if __name__ == '__main__':
main()
| 0 | null | 18,499,956,332,300 | 55 | 175 |
import math
N = int(input())
start_digit = math.ceil(math.sqrt(N))
for i in range(start_digit, 0, -1):
q, r = divmod(N, i)
if r == 0:
output = i+q-2
break
print(output) | from sys import stdin
input = stdin.readline
def solve():
n = int(input())
r = n % 1000
res = 0 if r == 0 else 1000 - r
print(res)
if __name__ == '__main__':
solve()
| 0 | null | 85,239,823,304,218 | 288 | 108 |
#!/usr/bin/env python3
from pprint import pprint
import sys
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
n = int(input())
x = input()
x_pc = x.count('1')
x_pc_plus = x_pc + 1
x_pc_minus = x_pc - 1
# 2 ** i % x_pc_plus, 2 ** i % x_pc_minus を予め計算しておく
r_plus_list = [pow(2, i, x_pc_plus) for i in range(n+1)]
r_minus_list = [0] * (n+1)
if x_pc_minus > 0:
r_minus_list = [pow(2, i, x_pc_minus) for i in range(n+1)]
x = x[::-1]
r_plus = 0
r_minus = 0
for i in range(n):
if x[i] == '1':
r_plus += r_plus_list[i]
r_minus += r_minus_list[i]
for i in range(n-1, -1, -1):
if x[i] == '0':
diff = (r_plus + r_plus_list[i]) % x_pc_plus
elif x_pc_minus >= 1:
diff = (r_minus - r_minus_list[i]) % x_pc_minus
else:
print(0)
continue
ans = 1
while diff > 0:
diff = diff % bin(diff).count('1')
ans += 1
print(ans)
| def mpow(a,b,m):
ans=1
while b >0 :
if b&1:
ans = (ans*a)%m
a=(a*a)%m
b=b>>1
return ans
def calcmod(X,m,N):
mod=0
X=X[::-1]
# print(X)
for i in range(N):
if X[i] == '1':
# if X & (1<<i) >0:
mod += mpow(2,i,m)
mod%=m
return mod
def popcount(m):
return bin(m).count("1")
def findsteps(mm):
cnt=0
while mm !=0:
cnt+=1
mm=mm%popcount(mm)
return cnt
N=int(input())
x=input()
X=int(x,2)
##we need to find X%(m-1) and X%(m+1)
m=popcount(X)
m1=m+1
m2=m-1
firstmod=calcmod(x,m1,N)
if m2 !=0:
secondmod=calcmod(x,m2,N)
fans=[0 for i in range(N)]
k=0
for i in range(N-1,-1,-1):
if X & (1<<i) >0:
##the bit was set
##we need to find X%(m-1) - (2^i)%(m-1)
if m2 == 0:
ans=0
else:
mm=secondmod - mpow(2,i,m2)
if mm < 0:
mm+=m2
mm=mm%m2
ans=1+findsteps(mm)
else:
mm = firstmod + mpow(2,i,m1)
mm=mm%m1
ans=1+findsteps(mm)
fans[k] = ans
k+=1
##the bit was not set
for i in fans:
print(i) | 1 | 8,218,220,607,642 | null | 107 | 107 |