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
|
---|---|---|---|---|---|---|
# 高橋君の夏休みが N 日間
# 夏休みの宿題が M個出されており、i 番目の宿題をやるには A i日間かかる
# 条件 複数の宿題を同じ日にはできない。
# また宿題をやる日は遊べない。
# 夏休み中に全ての宿題を終わらせるとき、最大何日遊ぶことができるか。
# 終わらない時は-1
N, M = map(int, input().split())
A = list(map(int, input().split()))
# 宿題にかかる合計日数
play_day = N - sum(A)
if play_day < 0:
print("-1")
else:
print(play_day) | import numpy as np
N, M = map(int, input().split())
A = []
A = map(int, input().split())
dif = N - sum(A)
if dif >= 0:
print(dif)
else:
print('-1') | 1 | 32,052,067,032,480 | null | 168 | 168 |
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
N, M = map(int, readline().split())
uf = UnionFind(N)
for _ in range(M):
a, b = map(int, readline().split())
uf.union(a - 1, b - 1)
print(uf.group_count() - 1)
if __name__ == '__main__':
main() | class UnionFind:
"""
class UnionFind
https://note.nkmk.me/python-union-find/
order O(log(n))
n = the number of elements
parents = the list that contains "parents" of x. be careful that it doesn't contain "root" of x.
"""
def __init__(self, n):
"""
make UnionFind
:param n: the number of elements
"""
self.n = n
self.parents = [-1] * n
def find(self, x):
"""
:param x: an element
:return: the root containing x
"""
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
"""
:param x, y: an element
"""
# root
x = self.find(x)
y = self.find(y)
if x == y:
# already same group so do nothing
return
if self.parents[x] > self.parents[y]:
# the root should be min of group
x, y = y, x
# remind that x, y is the root, x < y, then, y unions to x.
self.parents[x] += self.parents[y]
# and then y's parent is x.
self.parents[y] = x
def size(self, x):
# return the size of group
return -self.parents[self.find(x)]
def same(self, x, y):
# return whether the x, y are in same group
return self.find(x) == self.find(y)
def members(self, x):
# return members of group
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
# return all roots
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
# return how many groups
return len(self.roots())
def all_group_members(self):
# return all members of all groups
return {r: self.members(r) for r in self.roots()}
n,m= map(int,input().split())
union = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
union.union(a-1,b-1)
print(union.group_count()-1) | 1 | 2,315,912,151,058 | null | 70 | 70 |
n = int(input())
sum=0
for j in range(1,n+1):
sum+=(n//j)*(n//j+1)//2*j
print(sum) | import numpy as np
import sys
input = sys.stdin.readline
def main():
h, w, k = map(int, input().split())
values = np.zeros((h, w), dtype=np.int64)
items = np.array([list(map(int, input().split())) for _ in range(k)])
ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2]
values[ys, xs] = vs
DP = np.zeros(w + 1, dtype=np.int64)
for line in values:
DP[1:] += line
DP = np.maximum.accumulate(DP)
for _ in range(2):
DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
DP = np.maximum.accumulate(DP)
print(DP[-1])
if __name__ == "__main__":
main()
| 0 | null | 8,266,611,498,080 | 118 | 94 |
n = int(input())
dp = [1] * (n+1)
for j in range(n-1):
dp[j+2] = dp[j+1] + dp[j]
print(dp[n])
| def main():
N = int(input())
if N <= 1:
print(1)
return
fib = [0]*(N+1)
fib[0], fib[1] = 1, 1
for i in range(2, N+1):
fib[i] = fib[i-1] + fib[i-2]
print(fib[N])
if __name__ == "__main__":
main()
| 1 | 2,108,939,690 | null | 7 | 7 |
s = list(input())
sur_list = [0 for i in range(2019)]
sur = 0
keta = 1
ans = 0
s.reverse()
for i in range(len(s)):
keta = (keta*10)%2019
sur_list[sur] += 1
sur = (int(s[i]) * keta + sur) % 2019
ans += sur_list[sur]
print(ans)
| S = input()[::-1]
S_mod = [0] * (len(S)+1)
S_mod[0] = int(S[0])
d = 10
for i in range(len(S)-1):
S_mod[i + 1] = (S_mod[i] + int(S[i+1])*d)%2019
d = d * 10 % 2019
mod_count = [0] * 2019
for i in range(len(S_mod)):
mod_count[S_mod[i]] += 1
count = 0
for i in range(2019):
count += mod_count[i] * (mod_count[i] - 1) / 2
print(int(count)) | 1 | 30,826,731,851,310 | null | 166 | 166 |
n, m, l = [int (x) for x in input().split(' ')]
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(l)] for j in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for s in range(0,n):
a[s] = [int (x) for x in input().split(' ')]
for s in range(0,m):
b[s] = [int (x) for x in input().split(' ')]
for i in range(0,n):
for k in range(0,l):
result = 0
for j in range(0,m):
result += a[i][j] * b[j][k]
c[i][k] = result
for i in range(0,n):
c[i] = [str(c[i][j]) for j in range(0,l)]
print(' '.join(c[i])) | while True:
n = int(input())
s = []
if n == 0:
break
s = list(map(int, input().split()))
m = sum(s) / n
v = 0
for i in s:
v += (i - m) ** 2
ans = (v / n) ** (1/2)
print('{:10f}'.format(ans))
| 0 | null | 814,724,815,480 | 60 | 31 |
S = input()
Q = int(input())
lS = ''
for _ in range(Q):
query = input().split()
if query[0] == '1':
lS, S = S, lS
else:
if query[1] == '1':
lS += query[2]
else:
S += query[2]
print(lS[::-1] + S) | while True:
(m, f, r) = input().rstrip('\r\n').split(' ')
m = int(m)
f = int(f)
r = int(r)
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
continue
mf = m + f
if 80 <= mf:
print('A')
elif 65 <= mf and mf < 80:
print('B')
elif 50 <= mf and mf < 65:
print('C')
elif 30 <= mf and mf < 50:
if 50 <= r:
print('C')
else:
print('D')
else:
print('F')
| 0 | null | 29,406,991,266,140 | 204 | 57 |
while 1:
e=map(int,raw_input().split())
m=e[0]
f=e[1]
r=e[2]
if m==f==r==-1:
break
elif m==-1 or f==-1 or m+f<30:
print "F"
elif m+f<50 and r<50:
print "D"
elif m+f<65:
print "C"
elif m+f<80:
print "B"
else:
print "A" | if __name__ == '__main__':
from sys import stdin
while True:
m, f, r = (int(n) for n in stdin.readline().rstrip().split())
if m == f == r == -1:
break
s = m + f
result = "F" if m == -1 or f == -1 \
else "A" if 80 <= s \
else "B" if 65 <= s \
else "C" if 50 <= s or 50 <= r \
else "D" if 30 <= s \
else "F"
print(result)
| 1 | 1,224,032,641,440 | null | 57 | 57 |
s = list(input())
ans = []
for c in s:
if c.islower():
ans.append(c.upper())
elif c.isupper():
ans.append(c.lower())
else:
ans.append(c)
print("".join(ans))
| import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def egcd(a: int, b: int):
"""
A solution of ax+by=gcd(a,b). Returns
(gcd(a,b), (x, y)).
"""
if a == 0:
return b, 0, 1
else:
g, x, y = egcd(b % a, a)
return g, y - (b // a) * x, x
def modinv(a: int, mod: int = 10**9 + 7):
"""
Returns a^{-1} modulo m.
"""
g, x, y = egcd(a, mod)
if g > 1:
raise Exception('{}^(-1) mod {} does not exist.'.format(a, mod))
else:
return x % mod
def main():
N, S = geta(int)
A = list(geta(int))
A.sort()
mod = 998244353
inv2 = modinv(2, mod)
dp = [[0] * (S + 1) for _ in range(N + 1)]
for s in range(S + 1):
dp[0][s] = 0
_t = pow(2, N, mod)
for n in range(N + 1):
dp[n][0] = _t
for i in range(1, N + 1):
for j in range(1, S + 1):
if j >= A[i - 1]:
dp[i][j] = dp[i - 1][j - A[i - 1]] * inv2 + dp[i - 1][j]
else:
dp[i][j] = dp[i - 1][j]
dp[i][j] %= mod
print(dp[N][S])
if __name__ == "__main__":
main() | 0 | null | 9,669,435,030,852 | 61 | 138 |
if __name__ == "__main__":
s, t = input().split()
print(t+s) | import sys
input = lambda: sys.stdin.readline().rstrip()
def solve():
S, T = input().split()
print(T + S)
if __name__ == '__main__':
solve()
| 1 | 103,103,333,428,930 | null | 248 | 248 |
from sys import exit
a, b, c, k = map(int, input().split())
total = 0
if a >= k:
print(k)
exit()
else:
total += a
k -= a
if b >= k:
print(total)
exit()
else:
k -= b
print(total - k) | import sys
r, c = map(int, raw_input().split())
table = {}
for i in range(r):
a = map(int, raw_input().split())
for j in range(c):
table[(i,j)] = a[j]
for i in range(r+1):
for j in range(c+1):
if(i != r and j != c):
sys.stdout.write(str(table[(i,j)]))
sys.stdout.write(' ')
elif(i != r and j == c):
print sum(table[(i,l)] for l in range(c))
elif(i == r and j != c):
sys.stdout.write(str(sum(table[(k,j)] for k in range(r))))
sys.stdout.write(' ')
elif(i == r and j == c):
total = 0
for k in range(r):
for l in range(c):
total += table[(k,l)]
print total | 0 | null | 11,501,031,935,520 | 148 | 59 |
input();a=1
for i in input().split():a*=int(i);a=[-1,a][0<=a<=10**18]
print(a) | import copy
def BubbleSort(C, N):
for i in range(N):
for j in reversed(range(i+1, N)):
if C[j][1:2] < C[j-1][1:2]:
C[j], C[j-1] = C[j-1], C[j]
print(*C)
stableCheck(C, N)
def SelectionSort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j][1:2] < C[minj][1:2]:
minj = j
C[i], C[minj] = C[minj], C[i]
print(*C)
stableCheck(C, N)
def stableCheck(C, N):
global lst
flag = 1
for i in range(N):
for j in range(i+1, N):
if lst[i][1:2] == lst[j][1:2]:
fir = lst[i]
sec = lst[j]
for k in range(N):
if C[k] == fir:
recf = k
if C[k] == sec:
recs = k
if recf > recs:
print("Not stable")
flag = 0
break
if flag ==0:
break
if flag :
print("Stable")
N = int(input())
lst = list(map(str, input().split()))
lst1 = copy.deepcopy(lst)
lst2 = copy.deepcopy(lst)
BubbleSort(lst1, N)
SelectionSort(lst2, N)
| 0 | null | 8,191,697,582,750 | 134 | 16 |
# encoding:utf-8
import math as ma
# math.pi
x = float(input())
pi = (x * x) * ma.pi
# Circumference
pi_line = (x + x) * ma.pi
print("{0} {1}".format(pi,pi_line)) | import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7
num = tuple(num)
def gcd(a, b):
while b: a, b = b, a % b
return a
def isPrimeMR(n):
d = n - 1
d = d // (d & -d)
L = [2]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = (y * y) % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g): return g
elif isPrimeMR(n // g): return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i * i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += i % 2 + (3 if i % 3 == 1 else 1)
if i == 101 and n >= 2 ** 20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
return ret
lcd = dict()
for i in num:
j = primeFactor(i)
for x,y in j.items():
if not x in lcd.keys():
lcd[x] = y
else:
lcd[x] = max(lcd[x],y)
lc = 1
for i,j in lcd.items():
lc *= pow(i,j,mod)
ans =0
for i in range(n):
ans += lc*pow(num[i], mod-2, mod)
ans %= mod
print(ans) | 0 | null | 44,027,720,705,732 | 46 | 235 |
N = int(input())
C = list(input())
Rn = C.count('R')
print(C[:Rn].count('W')) | s = input()
if ("A" in s) and ("B" in s):
print("Yes")
else:
print("No") | 0 | null | 30,565,434,412,270 | 98 | 201 |
# -*- coding:utf-8 -*-
def solve():
import sys
N, M = list(map(int, sys.stdin.readline().split()))
Cs = list(map(int, sys.stdin.readline().split()))
dp = [float("inf") for _ in range(N+1)] # dp[i] := i円を作ることができるコインの最小枚数
dp[0] = 0
for c in Cs:
for i in range(c, N+1):
dp[i] = min(dp[i], dp[i-c]+1)
print(dp[N])
if __name__ == "__main__":
solve()
| n, m = map(int, raw_input().split())
c = map(int, raw_input().split())
dp = [n+1] * (n+1)
dp[n] = 0
for rest in xrange(n, 0, -1):
for i in xrange(m):
if c[i] <= rest:
dp[rest - c[i]] = min(dp[rest - c[i]], 1 + dp[rest])
print dp[0] | 1 | 135,689,329,470 | null | 28 | 28 |
N = int(raw_input())
A = map(int, raw_input().split())
def selectionSort(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
temp = A[i]
A[i] = A[minj]
A[minj] = temp
count += 1
return count
count = selectionSort(A, N)
print " ".join(map(str, A))
print count | n=int(input())
num=list(map(int,input().split()))
count=0
for i in range(0,n):
minj=i
a=0
for j in range(i+1,n):
if num[minj]>num[j]:
minj=j
if minj!=i:
count+=1
a=num[minj]
num[minj]=num[i]
num[i]=a
print(' '.join(list(map(str,num))))
print(count)
| 1 | 20,311,471,828 | null | 15 | 15 |
from math import *
a, b, C = (int(i) for i in input().split())
C = pi * C / 180
c = sqrt(a**2 + b**2 - 2 * a * b * cos(C))
h = b * sin(C)
S = a * h / 2
L = a + b + c
print("{:.8f} {:.8f} {:.8f}".format(S, L, h)) | import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
# 01ナップサック問題
N,W = map(int,readline().split())
AB = [tuple(map(int,readline().split())) for i in range(N)]
AB.sort(key=lambda x: x[0])
dp = [0]*(W+1)
for (w,v) in AB:
dpnew = dp[::]
for j in range(W):
dpnew[min(j+w,W)] = max(dp[min(j+w,W)],dp[j] + v)
dp = dpnew
print(dp[W])
| 0 | null | 76,271,741,141,398 | 30 | 282 |
import collections
n = int(input())
words = []
for i in range(n):
words.append(input())
c = collections.Counter(words)
values, counts = zip(*c.most_common())
nums = counts.count(max(counts))
xs = (list(values))[:nums]
xs.sort()
for x in xs:
print(x) | # import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, R, S, P, T):
k_list = [[] for _ in range(K)]
for i in range(len(T)):
k_list[i % K].append(T[i])
ans = 0
for kl in k_list:
dp = [[0, 0, 0] for _ in range(len(kl) + 1)]
for i in range(len(kl)):
# rock
dp[i + 1][0] = max(dp[i][1], dp[i][2])
dp[i + 1][0] += R if kl[i] == 's' else 0
# scissors
dp[i + 1][1] = max(dp[i][0], dp[i][2])
dp[i + 1][1] += S if kl[i] == 'p' else 0
# paper
dp[i + 1][2] = max(dp[i][0], dp[i][1])
dp[i + 1][2] += P if kl[i] == 'r' else 0
ans += max(dp[-1])
print(ans)
if __name__ == '__main__':
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
# N, K = 10 ** 5, 10 ** 3
# R, S, P = 100, 90, 5
# T = 'r' * 10 ** 5
solve(N, K, R, S, P, T)
| 0 | null | 88,274,256,260,160 | 218 | 251 |
import math
N=int(input())
A=list(map(int,input().split()))
a=max(A)
def era(n):
prime=[]
furui=list(range(2,n+1))
while furui[0]<math.sqrt(n):
prime.append(furui[0])
furui=[i for i in furui if i%furui[0]!=0]
return prime+furui
b=A[0]
for i in range(1,N):
b=math.gcd(b,A[i])
if b!=1:
print("not coprime")
exit()
furui=era(10**6+7)
minfac=list(range(10**6+7))
for i in furui:
for j in range(i,(10**6+7)//i):
if minfac[i*j]==i*j:
minfac[i*j]=i
dummy=[False]*(10**6+7)
for i in range(N):
k=A[i]
while k!=1:
if dummy[minfac[k]]==True:
print("setwise coprime")
exit()
else:
dummy[minfac[k]]=True
f=minfac[k]
while k%f==0:
k//=f
print("pairwise coprime") | import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from functools import reduce
from math import gcd
def resolve():
n = int(input())
A = list(map(int, input().split()))
if reduce(gcd, A) != 1:
print("not coprime")
return
M = max(A)
sieve = list(range(M + 1))
primes = []
for i in range(2, M + 1):
if sieve[i] == i:
primes.append(i)
j = 0
for p in primes:
if not (p <= sieve[i] and i * p <= M):
break
sieve[i * p] = p
used = set()
for a in A:
primes = set()
while a > 1:
p = sieve[a]
primes.add(p)
a //= p
for p in primes:
if p in used:
print("setwise coprime")
return
used.add(p)
print("pairwise coprime")
resolve() | 1 | 4,088,071,749,790 | null | 85 | 85 |
def A():
n, x, t = map(int, input().split())
print(t * ((n+x-1)//x))
def B():
n = list(input())
s = 0
for e in n:
s += int(e)
print("Yes" if s % 9 == 0 else "No")
def C():
int(input())
a = list(map(int, input().split()))
l = 0
ans = 0
for e in a:
if e < l: ans += l - e
l = max(l, e)
print(ans)
C()
| n = int(input())
a = list(map(int,input().split()))
x = 0
total = 0
for i in range(n-1):
if a[i] >= a[i+1]:
x = a[i] - a[i+1]
total += x
a[i+1] = a[i]
i = i+1
else:
total += 0
print(total) | 1 | 4,604,120,321,320 | null | 88 | 88 |
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
n = k()
if n%2==1:
print(0)
else:
for i in range(1,n):
if n>=2*(5**i):
cnt += n//(2*(5**i))
else:
break
print(cnt) | a, b = map(int, input().split())
print(a // b, a % b, round(a / b, 6)) | 0 | null | 58,252,961,362,190 | 258 | 45 |
def min_dist(x_b,y_b):
s=0
for x,y in zip(x_b,y_b):
s+=abs(x-y)
return s
def man_dist(x_b,y_b):
s=0
for x, y in zip(x_b,y_b):
s+=(abs(x-y))**2
return s**0.5
def che_dist(x_b,y_b):
s=0
for x,y in zip(x_b,y_b):
s+=(abs(x-y))**3
return s**(1/3)
def anf_dist(x_b,y_b):
s=[abs(x-y) for x,y in zip(x_b,y_b)]
return max(s)
n=int(input())
x_b=list(map(int,input().split()))
y_b=list(map(int,input().split()))
print(min_dist(x_b,y_b))
print(man_dist(x_b,y_b))
print(che_dist(x_b,y_b))
print(anf_dist(x_b,y_b)) | #10_D
import math
n=int(input())
x_v=list(map(int,input().split()))
y_v=list(map(int,input().split()))
p=1
while(p<5):
d=0
if(p==4):
my_list=[]
for i in range(n):
my_list.append(abs(x_v[i]-y_v[i]))
d=max(my_list)
print(d)
else:
for i in range(n):
d+=abs(x_v[i]-y_v[i])**p
d=pow(d,1/p)
print(d)
p+=1
| 1 | 210,680,207,780 | null | 32 | 32 |
x=int(raw_input())
print x*x*x | import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
S = _S()
print(S.count("ABC"))
main()
| 0 | null | 49,748,940,590,300 | 35 | 245 |
def main():
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [x - 1 for x in P]
C = list(map(int, input().split()))
ans = -(10 ** 18)
for i in range(N):
j = i
S = 0
L = 0
for _ in range(K):
j = P[j]
S += C[j]
L += 1
ans = max(ans, S)
if j == i:
break
if j == i:
M = max(0, K // L - 1)
T = S * M
for _ in range(M * L, K):
j = P[j]
T += C[j]
ans = max(ans, T)
print(ans)
if __name__ == "__main__":
main()
| import math
x1,y1,x2,y2=map(float,input().split())
print(round(math.sqrt((x1-x2)**2+(y1-y2)**2),7))
| 0 | null | 2,808,314,258,740 | 93 | 29 |
n,k = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse=True)
if k>=n:
print(0)
else:
ans = 0
for i in range(k,n):
ans += h[i]
print(ans) | import math
while True:
n = int(input())
if n == 0:
break
s = list(map(int, input().split()))
m = sum(s)/n
v = 0
for i in s:
v += (i - m) ** 2
ans = math.sqrt(v/n)
print("{:.5f}".format(ans))
| 0 | null | 39,858,352,017,212 | 227 | 31 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
????????????
?????? n ?????°??? A ??¨??´??° m ???????????????A ???????´?????????????????????????????´?????¶????????????????
m ???????????????????????????????????????????????°????????????????????????????????????
AA ??????????´???????????????????????????¨?????§????????????
??°??? A ??????????????????????????§???????????¨?????? q ?????? mi ????????????????????§???
???????????????????????? "yes" ????????? "no" ??¨???????????????????????????
n ??? 20 ; q ??? 200 ; 1 ??? A???????´? ??? 2000 ; 1 ??? Mi ??? 2000
"""
def main():
""" ????????? """
n = int(input())
A = sorted(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))
g = 0
tA = []
l = 2 ** n
for i in range(1,l):
c = 0
bi = "{0:0{width}b}".format(i,width=n)
bi = bi[::-1]
for j in range(n):
if bi[j] == "1":
c += A[j]
tA.append(c)
# tA.sort()
for mi in M:
if mi in tA:
print("yes")
else:
print("no")
if __name__ == '__main__':
main() | n=int(input())
A=[{} for _ in range(n)]
for i in range(n):
for _ in range(int(input())):
x,y=map(int,input().split())
A[i][x]=y
a=0
for i in range(2**n):
t=0
for j in range(n):
if i>>j&1:
if A[j] and any(i>>~-k&1!=A[j][k] for k in A[j]): break
else: t+=1
else: a=max(a,t)
print(a) | 0 | null | 61,131,844,939,090 | 25 | 262 |
print(input().find('0')//2+1) | nums = list(map(int, input().split()))
print(nums.index(0)+1) | 1 | 13,389,264,518,278 | null | 126 | 126 |
s=input()
t=input()
ls=len(s)
lt=len(t)
ans=lt
for i in range(0,ls-lt+1):
count = 0
for j in range(lt):
if s[i+j]!=t[j]:
count+=1
if count<ans:
ans=count
print(ans) | S = input()
T = input()
ans = 1000
for i in range(len(S)-len(T)+1):
diff = 0
for j in range(len(T)):
if S[i+j] != T[j]:
diff += 1
if ans > diff:
ans = diff
print(ans) | 1 | 3,692,885,585,248 | null | 82 | 82 |
import sys
t = input()
answerCount = 0
stringList = []
while True:
line = input()
if line == "END_OF_TEXT":
break
for i in range(len(str(line).lower().split())):
stringList.append(str(line).lower().split()[i])
if str(line).lower().split()[i] == t:
answerCount += 1
print(answerCount)
| import sys
W = input().lower()
T = sys.stdin.read().lower()
print(T.split().count(W)) | 1 | 1,795,879,963,960 | null | 65 | 65 |
n = int(input())
cnt = 0
for i in range(n):
if (i + 1) % 2 == 1:
cnt += 1
print(cnt/n)
| #!/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()))
MOD = 10 ** 9 + 7
def main():
N = II()
targets = LI()
colors = [0] * 3
ans = 1
for i in range(N):
count = 0
for k in range(3):
if colors[k] == targets[i]:
if count == 0:
colors[k] += 1
count += 1
ans *= count
ans %= MOD
print(ans)
main()
| 0 | null | 153,740,763,951,098 | 297 | 268 |
def find_divisor(x):
Divisors = []
for i in range(1, int(x**0.5) + 1):
if x % i == 0:
Divisors.append(i)
if i != x // i:
Divisors.append(x // i)
return Divisors
n = int(input())
ways = len(find_divisor(n-1)) - 1
Div = find_divisor(n)
for i in range(1, len(Div)):
quo = n
while quo % Div[i] == 0:
quo = quo // Div[i]
if quo % Div[i] == 1:
ways += 1
print(ways) | import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
#約数列挙
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
ans=set(make_divisors(N-1))
ans=ans - set([1])
ans.add(2)
L=make_divisors(N)
for i in range(1,len(L)):
temp=L[i]
N2=N
while N2>=temp:
if N2%temp==0:
N2=N2//temp
else:
N2=N2%temp
if N2==1:
ans.add(temp)
print(len(ans))
main()
| 1 | 41,182,239,414,826 | null | 183 | 183 |
import collections
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
c = [0] * n
for i in range(n):
b[i] = a[i] + (i + 1)
c[i] = (i + 1) - a[i]
ans = 0
cCc = collections.Counter(c)
# print(cCc)
for k, v in collections.Counter(b).items():
if v != 0 and k in cCc:
# print(k,v,cCc[k])
ans += v * cCc[k]
print(ans)
| for i in range(1, 10):
for j in range(1, 10):
print '%dx%d=%d' % (i, j, i * j) | 0 | null | 13,009,379,990,698 | 157 | 1 |
for i in range(int(raw_input())):
a, b, c = [int(j) ** 2 for j in raw_input().split()]
if a+b==c or a+c==b or b+c==a:
print 'YES'
else:
print 'NO' | def gcd(a,b):
for i in range(1,min(a,b)+1):
if a%i ==0 and b % i ==0:
ans = i
return ans
x =int(input())
print(360//gcd(360,x)) | 0 | null | 6,586,710,055,940 | 4 | 125 |
from numba import njit
from sys import maxsize
@njit
def solve(n, k, p, c):
used = [0] * n
ss = []
for i in range(n):
if used[i]:
continue
now = i
s = []
while not used[now]:
used[now] = 1
s.append(c[now])
now = p[now]
ss.append(s)
res = -maxsize
for s in ss:
s_len = len(s)
cumsum = [0]
# 2周分の累積和
for i in range(2*s_len):
cumsum.append(cumsum[-1] + s[i%s_len])
max_sum = [-maxsize] * s_len
for i in range(s_len):
for j in range(s_len):
max_sum[j] = max(max_sum[j], cumsum[i+j] - cumsum[i])
for i in range(s_len):
if i > k:
continue
v = (k - i) // s_len
if i == 0 and v == 0:
continue
if cumsum[s_len] > 0:
res = max(res, max_sum[i] + cumsum[s_len] * v)
elif i > 0:
res = max(res, max_sum[i])
print(res)
if __name__ == '__main__':
n, k = map(int, input().split())
p = list(map(lambda x: int(x)-1, input().split()))
c = list(map(int, input().split()))
solve(n, k, p, c)
| def solve():
N, K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())
ans = -float("inf")
for pos in range(N):
used = [-1] * N
cost = [0] * (N+1)
for k in range(N+1):
if k:
cost[k] = cost[k-1] + C[pos]
if used[pos] >= 0:
loop_size = k-used[pos]
break
used[pos] = k
pos = P[pos] - 1
if cost[loop_size] <= 0:
ans = max(ans, max(cost[1:K+1]))
else:
a, b = divmod(K, loop_size)
v1 = cost[loop_size] * (a-1) + max(cost[:K+1])
v2 = cost[loop_size] * a + max(cost[:b+1])
ans = max(ans, max(v1, v2) if a else v2)
print(ans)
solve()
| 1 | 5,341,153,943,972 | null | 93 | 93 |
n = int(input())
i = 1
ans = 0
while (i <= n):
total = sum(j for j in range(i, n+1, i))
ans += total
i += 1
print(ans) | n = int(open(0).readline())
ans = 0
for i in range(1,n+1):
count = n//i
end = count*i
ans += count * (i+end)//2
print(ans) | 1 | 11,112,104,771,350 | null | 118 | 118 |
N = int(input())
A = list(map(int,input().split()))
s = [0]*(N+1)
for i in range(N):
s[i+1] = s[i] + A[i]
cnt = 0
for j in range(N):
cnt = (cnt + (A[j]*(s[N] - s[j+1])))%(10**9+7)
print(cnt) | # python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
INF = float('inf')
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)
def lcm(a, b):
return (a * b) // gcd(a, b)
# main
n = ii()
alist = lmis()
asum = sum(alist[1:n])
sum = 0
for i in range(n-1):
sum += alist[i] * asum
asum -= alist[i+1]
print(sum % 1000000007)
| 1 | 3,838,676,241,390 | null | 83 | 83 |
S = int(input())
mod = 10**9+7
dp = [0 for _ in range(S+1)]
dp[0] = 1
for i in range(3, S+1):
dp[i] = dp[i-1]+dp[i-3]
dp[i] = dp[i]%mod
print(dp[-1]) | # -*- coding:utf-8 -*-
def Selection_Sort(A,n):
for i in range(n):
mini = i
for j in range(i,n): #i以上の要素において最小のAをminiに格納
if int(A[j][1]) < int(A[mini][1]):
mini = j
if A[i] != A[mini]:
A[i], A[mini] = A[mini], A[i]
return A
def Bubble_Sort(A, n):
for i in range(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]
return A
n = int(input())
A = input().strip().split()
B = A[:]
A = Bubble_Sort(A,n)
print (' '.join(A))
print ("Stable")
B =Selection_Sort(B,n)
print (' '.join(B))
if A == B:
print ("Stable")
else:
print ("Not stable") | 0 | null | 1,661,386,214,074 | 79 | 16 |
def gcd(a,b):
if a == 0:
return b
else:
g = gcd(b%a,a)
return g
n1,n2 = map(int,raw_input().split())
print gcd(n1,n2) | import sys
A,B,C,D = map(int,input().split())
while True:
C -= B
if C <= 0:
print("Yes")
sys.exit()
A -= D
if A <= 0:
print("No")
sys.exit()
| 0 | null | 14,834,218,093,508 | 11 | 164 |
a, b, c = map(int, input().split())
k = int(input())
count = 0
while True:
if b > a:
break
b *= 2
count += 1
while True:
if c > b:
break
c *= 2
count += 1
if count <= k:
print('Yes')
else:
print('No')
| # M-SOLUTIONS プロコンオープン 2020: B – Magic 2
A, B, C = [int(i) for i in input().split()]
K = int(input())
is_success = 'No'
for i in range(K + 1):
for j in range(K + 1):
for k in range(K + 1):
if i + j + k <= K and A * 2 ** i < B * 2 ** j < C * 2 ** k:
is_success = 'Yes'
print(is_success) | 1 | 6,871,561,532,920 | null | 101 | 101 |
n = int(input())
a = list(map(int, input().split()))
result = [0] * n
for i in range(len(a)):
result[a[i] - 1] += 1
for i in range(len(result)):
print(result[i]) | n,x,m=map(int,input().split())
id=[-1 for i in range(m+1)]
s=[]
c=0
while id[x]==-1:
id[x]=c
c+=1
s.append(x)
x=x*x%m
d=c-id[x]
ans=0
if n<=d:
for i in range(n):
ans+=s[i]
else:
for i in range(id[x]):
ans+=s[i]
n-=id[x]
sum=0
for i in range(d):
sum+=s[id[x]+i]
ans+=(n//d)*sum
n=n%d
for i in range(n):
ans+=s[id[x]+i]
print(ans) | 0 | null | 17,608,279,162,200 | 169 | 75 |
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)
ng = -1
ok = 0
for i in range(N):
ok = max(A[i]*F[i], ok)
def is_ok(arg):
cnt = 0
for i in range(N):
cnt += max(A[i] - arg//F[i], 0)
return cnt <= K
def m_bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
print(m_bisect(ng, ok)) | import math
def main():
MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split(' ')))
# 答えは sum(lcm(A) / A)
L = 1
for a in A:
L = L * a // math.gcd(L, a)
ans = 0
for a in A:
ans += L * pow(a, MOD - 2, MOD)
ans %= MOD
print(ans)
if __name__ == '__main__':
main() | 0 | null | 126,736,878,325,020 | 290 | 235 |
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
return sys.stdin.readline().rstrip()
def main():
def nibutan(ok,ng):
while abs(ok-ng) > 1:
mid = (ok + ng) // 2
if solve(mid,2):
ok = mid
else:
ng = mid
return ok
def solve(mid,n):
dif=(d_0+d_1)*(mid-1)
c=0
if dif*(dif+d_0) == 0:
c+=1
elif dif*(dif+d_0) < 0:
c+=1
if (dif+d_0)*(dif+d_0+d_1) < 0:
c+=1
if c==n:
return True
else:
return False
T=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
d_0=T[0]*(A[0]-B[0])
d_1=T[1]*(A[1]-B[1])
if d_0==-d_1:
print('infinity')
elif d_0*(d_0+d_1)<0:
if (d_0*2+d_1)*(d_0*2+d_1*2)<0:
n=nibutan(2,10**40)
ans=n*2-1
ans+=solve(n+1,1)
print(ans)
else:
print(1)
else:
print(0)
if __name__ == '__main__':
main()
| T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
a, b = A1 * T1, A2 * T2
c, d = B1 * T1, B2 * T2
if a + b == c+ d:
print("infinity")
exit()
if a + b < c+d:
a,b,c,d = c,d,a,b
if a > c:
print(0)
exit()
else:
num = 0
if (c-a) % (a+b-c-d) == 0:
num = 1
print((c-a-1) // (a+b-c-d) * 2+num+1)
| 1 | 131,658,341,212,520 | null | 269 | 269 |
from math import sqrt
N = int(input())
ans = 0
for a in range(1, N+1):
ans += (N-1)//a
print(ans) | from itertools import *
A = list(permutations(range(1,1+int(input()))))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q))) | 0 | null | 51,721,994,093,000 | 73 | 246 |
K = int(input())
S = input()
if len(S) <= K:
print(S)
else:
print(S[0:K] + '...') | k = int(input())
s = input()
if k >= len(s):
print(s)
else :
l_s = list(s)
n_s = "".join(l_s[:k])+"..."
print(n_s) | 1 | 19,756,466,487,992 | null | 143 | 143 |
n = int(input())
a = sorted(list(map(int, input().split())))
x = 1
for i in range(n):
x = x * a[i]
if x == 0:
break
elif x > 10 ** 18:
x = -1
break
print(x)
| N=int(input())
As=list(map(int,input().split()))
ans=1
if 0 in As:
print(0)
else:
for i in range(N):
ans*=As[i]
if ans>int(1e18):
break
print(ans if ans<=int(1e18) else -1) | 1 | 16,227,000,685,632 | null | 134 | 134 |
A=int(input())
#pr#print(A)
int(A)
B=int(input())
if A + B == 3:
print(3)
elif A+B==4:
print(2)
else:
print(1)
| print 6 - int(raw_input()) - int(raw_input()) | 1 | 110,704,158,768,852 | null | 254 | 254 |
n,m=map(int,input().split())
left=m//2
right=(m+1)//2
for i in range(left):
print(i+1,2*left+1-i)
for i in range(right):
print(2*left+1+i+1,2*left+1+2*right-i)
| def bfs(n,e,fordfs,D):
#点の数、スタートの点、有向グラフ
W = [-1]*(n-1)
#各点の状態量、最短距離とか,見たかどうかとか
used = defaultdict(bool)
que = deque()
que.append(e)
while que:
now = que.popleft()
i = 1
for ne in fordfs[now]:
l = min(now,ne); r = max(now,ne)
if W[D[(l,r)]] == -1:
while(True):
if not used[(now,i)]:
used[(now, i)] = True
used[(ne, i)] = True
break
i +=1
que.append(ne)
W[D[(l,r)]] = i
return W
def examD():
N = I()
V = [[]for _ in range(N)]
d = defaultdict(int)
for i in range(N-1):
a, b = LI()
V[a-1].append(b-1)
V[b-1].append(a-1)
d[(a-1,b-1)] = i
ans = bfs(N,0,V,d)
print(max(ans))
for v in ans:
print(v)
return
def examF():
N, M = LI()
S = SI()
ans = []
cur = N
while(cur>0):
k = min(M,cur)
while(S[cur-k]=="1"):
k -=1
if k==0:
print("-1")
return
ans.append(k)
cur -=k
for v in ans[::-1]:
print(v)
return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]
if __name__ == '__main__':
examF()
| 0 | null | 83,931,917,446,520 | 162 | 274 |
for x in range(1, 10):
for y in range(1, 10):
print('%dx%d=%d' % (x,y,x*y)) | input()
numbers = input().split()
#print(numbers)
r_numbers = reversed(numbers)
#print(r_numbers)
print(" ".join(r_numbers)) | 0 | null | 485,588,821,590 | 1 | 53 |
#@ /usr/bin/env python3.4
import sys
list = sys.stdin.readlines()
for i in list:
num = i[:-1].split(' ', 2)
print(len(str(int(num[0])+int(num[1])))) | a,b = map(int,input().split())
A = [str(a)*b,str(b)*a]
B = sorted(A)
print(B[0]) | 0 | null | 42,297,016,338,792 | 3 | 232 |
#coding: utf-8
import sys
c = [0 for i in range(26)]
in_list = []
for line in sys.stdin:
in_list.append(line)
for s in in_list:
for i in range(len(s)):
if ord(s[i]) >= ord('a') and ord(s[i]) <= ord('z'):
c[ord(s[i])-97] += 1
elif ord(s[i]) >= ord('A') and ord(s[i]) <= ord('Z'):
c[ord(s[i])-65] += 1
for i in range(26):
print(chr(ord('a')+i) + " : " + str(c[i]))
| N = int(input())
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
def add(X):
counter = 0
while True:
if counter * (counter + 1) <= X * 2:
counter += 1
else:
counter -= 1
break
# print(X, counter)
return counter
facts = factorization(N)
answer = 0
for f in facts:
if f[0] != 1:
answer += add(f[1])
print(answer) | 0 | null | 9,314,329,554,282 | 63 | 136 |
n = int(input())
P = list(map(int, input().split()))
minSoFar = 2 * 10**5 + 1
ans = 0
for i in range(n):
if P[i] < minSoFar:
ans += 1
minSoFar = min(minSoFar, P[i])
print(ans) | n = str(input())
tmp = 0
for i in n:
tmp += int(i)
if tmp % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 44,737,323,964,350 | 233 | 87 |
n = input()
data = [int(i) for i in input().split(' ')]
def insertion_sort(raw_list):
for i, v in enumerate(raw_list):
if i == 0:
continue
j = i - 1
while j >= 0 and v < raw_list[j]:
raw_list[j+1] = v
raw_list[j+1] = raw_list[j]
j -= 1
raw_list[j+1] = v
print(' '.join([str(i) for i in raw_list]))
return raw_list
print(' '.join([str(i) for i in data]))
insertion_sort(data)
#print(' '.join([str(i) for i in insertion_sort(data)])) | _n = int(raw_input())
_a = [int(x) for x in raw_input().split()]
for i in range(1, _n):
print(" ".join([str(x) for x in _a]))
key = _a[i]
j = i - 1
while j >= 0 and _a[j] > key:
_a[j+1] = _a[j]
j -= 1
_a[j+1] = key
print(" ".join([str(x) for x in _a])) | 1 | 5,492,841,200 | null | 10 | 10 |
# B - Bishop
H,W = map(int,input().split())
if H>1 and W>1:
print((H*W+1)//2)
else:
print(1) | x = list(map(int,input().split()))
H = x[0]
W = x[1]
if H == 1 or W == 1:
print(1)
else:
if W % 2 == 0:
print(int(H*W/2))
else:
if H % 2 == 0:
print(int(H*(W-1)/2 + H/2))
else:
print(int(H*(W-1)/2 + (H+1)/2))
| 1 | 50,855,932,459,644 | null | 196 | 196 |
import numpy
N, K = map(int, input().split())
print(len(numpy.base_repr(N, K)))
| N,K=map(int,input().split())
ans=0
while N>=K**ans:
ans+=1
print(ans) | 1 | 64,728,333,063,008 | null | 212 | 212 |
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') |
# ..
# .gMMN;
# .HMMMR ....-, .gggggggJJ...
# .J,. TMMN; ..JgNMMMMMMM{dMMMMMMMMMMMMNNgJ..
# .MMMNx. ?MMb .JNMMMMMMMMMMMMrJMMMMMMMMMMMMMMMMMNmJ.
# ?MMMMMNe. ?MN, .iMMMMMMMMMMMMMMMMP(MMMMMMMMMMMMMMMMMMMMMb .`(zvvvvrOO+. .(wvO- _(vvvvvrOz+. _(ro _(rl
# ?THMMNm. -"!.NMMMMMMMMMMMMMMMMMH%.WHHMMMMMMMMMMMMMMMMMM^ ~ zvC~~~?<?Ovo. !(rrrI `_(vO!~~?<1Oro. _(vI _(rI
# ..... ~7W$ ...MMMMMMMMMMMMB0C1????> dZZZZZZZZZWHMMMMMMMB! ~ zv> _ Orl -.vvrrv; _(vI _(Ov{ _(rI _(rI
# dMMMMMNNNme .jMMNmTMMMMMMMBC?????????> duZuZuZZuZZZZZXHMMY ~ zv> _ zvI ~jvv<?vw. _(rI .zr{ _(rI _(rI
# dMMMMBY"=!`.MMMMMMNmTMMM6????????????z_jZuZZuZuZuZuZZZZC` ~ zv> ._JvZ! _-vI` _jv> _(vI _(rr! _(rO-....(-JrI
# (MMMMMMMMMD ?1??=?=??=???=?=_(ZZZuZZZZZuZuZV! ~ zvw&+xzzwOC! ._zv: _.ww_ _(vr&J+xzzrC! _(rrrrrrvrrrrI
# .dMMMMMMMMMD_.- ?1?=?????=???=_(ZZuZZuZuZZZX=` ~ zvZ7I1vv> _(vv&..-(rro _(rvC777<<` _(vZ!````~_jrI
# .dMMMMMMMMM=.....- ?1??=??????=<(SZZuZZuZZZV! ~ zv> _.1rO- ..wrOOOOOOOrw- _(vZ _(vI _(vI
# (MMMMMMMM#!........- <?=???=??=:.SZuZZuZZ0> ~ zv> -?ww- ~jvv ~(vO _(rI _(rI _(rI
# .MMMMMMMM#!......_(J-.-.<?=?????>.ZZZuZZZC` ~ zv> _(Or+ _.rZ` -zv{ _(rI _(vI _(rI
# dMMMMMMMMt.......(TMNm,.-.<=??=?> XZZZZV! ~ zv> _(Or+..~zv> _(vw._(vI _(rI _(rI
# .MMMMMMMM#_.........?WMNm,.--<=??z_dZZ0=` ~ zw: _.OO>_.rC` _jr>_(rC _(rC _(rC
# (MMMMMMMMD.......-gNNMMMM$...--<?v`dZV~...
# dX0vrOz<_``. -7Y=<~_....... <gMMMMNNmgJJ... <-. (<
# jMMMMMMMNZ???>>+++++(((((----... dMMMMMMMMMMMMMMNNagJ... (<z!
# dMMMMMMMMR??>??>?>??>?>??>?????< ?MMMMMMMMMMMMMMMMMMMMMMNNm, .+>?1.
# JMMMMMMMMK>?????>??>??>?>???<<_(+_ (,?HMMMMMMMMMMMMMMMMMMMMMMMMm. ` `
# (MMMMMMMMN+?>>?>??>?>????<<_(;::<_Jyyx?rttrZVVHMMMMMMMMMMMMMMMMMb ...-....... .... ..-....... .... ...
# .MMMMMMMMNy?>?>?>????<<~_(;::;:;!.Xyyy+(rrtrtrttrrZUWMMMMMMMMMMMM; _.vrOOOOOwvO+. ~(rrw_ _jrrOOOOrvO- - jv> _ wv:
# dMMMMMMMMN+??????<<~-(;;::;;:;< jVyyyWo(trtrrtrtttrtrwMMMMMMMMMM] _.vZ~ ~_zvI. ..wrrvl _jv> ~?Oro -`jr> ~ Ov:
# .MMMMMMMMMR>??<<_-(;;::;;:;:;;!.XyyyyyWo(OrttrtrrtrttrdMMMMMMMMM\ _.vZ_ ~.vv> .~jvOOvr- _jv{ ~(vr_-`jv> ~ Or:
# (MMMMMMMMMC!_-(;;::;:;::;:;;< dVyyyyyyy+(OrrtrtrrtrtrdMMMMMMMMM! _.vZ_ ~.vr: _.vI`~(vI. _jv{ ~-vr!-`jv> _ wr:
# ?MMMMM#5uJ+;;;;:;;:;:;:;::;~.XyyyyyyyyV+(OrtrttrtrrdMMMMMMMMM@ _.vw- ..-(rr> ._zv: -zv: _jvl ..(zvC -`jvO((((J+Jrv:
# ?YY1(gMMMMN+::;:;:;:;;:;;< dyyyyyyyyyyW+.OrtrrtrwdMMMMMMMMMM\ _.vrrrrrrrZ<` _(vI ~(rO. _jrrrrrrvOC! -`jrOCCCCOCOrr:
# dMMMMMMMMNm+;::;:;::;:;`.VyyyyyyyyyyyWo.OrttrQMMMMMMMMMMMF _.vO><~jrw_ .-wrrOzzzwrvl _jvZ!!!~` -`jv> ~ Ov: . d=7n v=7h .d=7h.
# ?MMMMMMMMMMMmx+;:;:;:;< dyyyyyyyyyyyyVy{.zrQNMMMMMMMMMMMF _.vZ_ -.?rw- _(vZ<<<<<71ww_ _jv{ -`jv> ~ Or: (h (3dIJR.W=! .(= .(= ,$ d{
# .TMMMMMMMMMMMMNma+<;<`(yyyyyyyyyyyyyyyV{.dMMMMMMMMMMMMD _.vZ_ _?wr- _.rZ` _jvl _jv{ -`jv> ~ Or: (m$ 4,.,.V .,.(R-... .R-. ..W..f`
# (TMMMMMMMMMMMMMMMN;.dkkWWWWWWkQQQNNMMMm(MMMMMMMMMM#^ _.vZ_ _(wv+ ._jv> __Ov- _jr{ -`jv> ~ Or: `
# .TMMMMMMMMMMMMMM<dMMMMMMMMMMMMMMMMMMMN,HMMMMMM#= _.vZ_ _.Oro._.rZ` _(rI._jv{ -`jv> ~ Ov:
# _THMMMMMMMMMF(MMMMMMMMMMMMMMMMMMMMMN,WMMMD! _.CC` ~.7C`~?C! _7C`_?C! _?7! _.?C!
# _?TMMMMM1MMMMMMMMMMMMMMMMMMMMMMMF `
# ` THMMMMMMMMMMMMMMMB9""!`
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
def main():
n = int(input().strip())
ans = 0
for i in range(1, n):
j = n - i
if i == j:
continue
ans += 1
print(ans // 2)
if __name__ == '__main__':
main()
| 0 | null | 79,878,834,998,898 | 102 | 283 |
#!/usr/bin/env python3
from collections import Counter
def solve(N: int, A: "List[int]", Q: int, BC: "List[(int,int)]"):
A = Counter(A)
answers = []
ans = ans = sum((i * n for i, n in A.items()))
for b, c in BC:
if b != c:
ans += (c - b) * A[b]
A[c] += A[b]
del A[b]
answers.append(ans)
return answers
def main():
N = int(input()) # type: int
A = list(map(int, input().split()))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]
answer = solve(N, A, Q, BC)
for ans in answer:
print(ans)
if __name__ == "__main__":
main()
| from bisect import bisect_left
def calc(N, A, cumsum, x):
num = N ** 2
total = cumsum[N] * N * 2
for a in A:
idx = bisect_left(A, x - a)
num -= idx
total -= cumsum[idx] + idx * a
return num, total
def main():
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cumsum = [0] * (N+1)
for i in range(N):
cumsum[i+1] = cumsum[i] + A[i]
lo = 0
hi = int(2e5+1)
while lo < hi:
mid = (lo + hi) // 2
num, total = calc(N, A, cumsum, mid)
if num <= M:
hi = mid
else:
lo = mid + 1
num, total = calc(N, A, cumsum, lo)
ans = total - (num - M) * (lo - 1)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 60,157,575,369,960 | 122 | 252 |
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 二分探索、浮き沈みの沈みに注意
N, K = lr()
A = np.array(lr()); A.sort()
F = np.array(lr()); F.sort()
F = F[::-1]
def check(x):
limit = x // F # このラインまでにAを落とす
Y = A - limit
if np.any(Y > K):
return False
cost = Y[Y>=0].sum()
if cost <= K:
return True
else:
return False
ok = 10 ** 15; ng = -1
while abs(ng-ok) > 1:
mid = (ok+ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)
| n,k = map(int, input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort()
F.sort(reverse=True)
def is_ok(x):
c = 0
for a, f in zip(A, F):
c += max(0, a-x//f)
if c <= k:
return True
else:
return False
ng = -1
ok = 10**18
while ng+1 < ok:
c = (ng+ok)//2
if is_ok(c):
ok = c
else:
ng = c
print(ok)
| 1 | 164,609,031,068,778 | null | 290 | 290 |
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def s(x): #圧縮
a = []
if len(x) == 0:
return []
aa = x[0]
su = 1
for i in range(len(x)-1):
if aa != x[i+1]:
a.append([aa,su])
aa = x[i+1]
su = 1
else:
su += 1
a.append([aa,su])
return a
def jo(x): #listをスペースごとに分ける
return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
return max(map(max,x))
def In(x,a): #aがリスト(sorted)
k = bs.bisect_left(a,x)
if k != len(a) and a[k] == x:
return True
else:
return False
def pow_k(x, n):
ans = 1
while n:
if n % 2:
ans *= x
x *= x
n >>= 1
return ans
"""
def nibu(x,n,r):
ll = 0
rr = r
while True:
mid = (ll+rr)//2
if rr == mid:
return ll
if (ここに評価入れる):
rr = mid
else:
ll = mid+1
"""
n = onem()
a = l()
if n % 2 == 0:
po = [a[i] for i in range(n)]
for i in range(n-3,-1,-1):
po[i] += po[i+2]
ans = sum(a[0::2])
ans = max(ans,sum(a[1::2]))
co = 0
for i in range(0,n,2):
if i+1 <= n-1:
ans = max(ans,co+po[i+1])
else:
ans = max(ans,co)
co += a[i]
print(ans)
else:
po = [a[i] for i in range(n)]
mi = [-Max for i in range(n)]
for i in range(n-3,-1,-1):
po[i] += po[i+2]
ans = sum(a[1::2])
ans = max(ans,sum(a[0::2]) - a[-1])
#print(ans)
l1 = [-Max for i in range(n)]
for i in range(n):
if i != n-1:
l1[i] = po[i+1]
"""
co = 0
for i in range(0,n,2):
if i != n-1:
l1[i] = co + po[i+1]
else:
l1[i] = co
co += a[i]
co = 0
for i in range(1,n,2):
if i != n-1:
l1[i] = co + po[i+1]
else:
l1[i] = co
co += a[i]
"""
for i in range(n-1,-1,-1):
if i == n-1:
continue
elif i == n-2:
mi[i] = l1[i]
else:
mi[i] = max(mi[i+2]+a[i],l1[i])
l1 = mi
"""
for i in range(n-1,-1,-1):
if i <= n-3:
mi[i] = min(mi[i+2],a[i])
else:
mi[i] = a[i]
print(mi)
"""
l2 = [-Max for i in range(n)]
for i in range(n-1,-1,-1):
l2[i] = po[i]
#print(l1)
#print(l2)
co = 0
for i in range(0,n,2):
if i + 2 <= n-1:
#print(ans,co+l1[i+1],co+l2[i+2])
ans = max(ans,co+l1[i+1],co+l2[i+2])
elif i+1 <= n-1:
ans = max(ans,co+l1[i+1])
else:
ans = max(ans,co)
co += a[i]
co = 0
#print(ans)
for i in range(1,n,2):
#print(ans,co+l1[i+1])
ans = max(ans,co+po[i+1])
#ans = max(ans,co+l1[i+1])
co += a[i]
#print("po:"+str(mi[1]))
print(ans)
| def main():
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
n = int(input())
a = [int(x) for x in input().split()]
from collections import defaultdict
dp = defaultdict(lambda : -float('inf'))
dp[(0, 0, 0)] = 0
for i in range(1, n + 1):
max_j = i//2 if i % 2 == 0 else i//2 + 1
min_j = n//2 - (n - i)//2 if (n - i) % 2 == 0 else n//2 - ((n - i)//2 + 1)
for j in range(min_j, max_j + 1):
dp[(i, j, 0)] = max(dp[(i - 1, j, 0)], dp[(i - 1, j, 1)])
dp[(i, j, 1)] = dp[(i - 1, j - 1, 0)] + a[i - 1]
print(max(dp[(n, n//2, 0)], dp[(n, n//2, 1)]))
main()
| 1 | 37,420,140,549,260 | null | 177 | 177 |
n=int(input())
s=100000
for i in range(n):
s=s*1.05
if s%1000==0:
s=s
else:
s=(s//1000)*1000+1000
print(int(s))
| #! /usr/bin/python3
m=100
for _ in range(int(input())):
m = int(m*1.05+0.999)
print(m*1000) | 1 | 1,079,298,880 | null | 6 | 6 |
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
import numpy as np
#======================================================#
MOD=10**9+7
def main():
n = II()
aa = np.array(MII(), dtype='uint64')
ans = 0
for i in range(60):
cnt1 = (aa&1).sum()
ans += (cnt1*(n-cnt1))%MOD*(2**i)%MOD
aa >>= 1
print(int(ans%MOD))
if __name__ == '__main__':
main() | mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
zero = defaultdict(int)
one = defaultdict(int)
for a in A:
for i in range(61):
if a &(1<<i):
one[i] += 1
else:
zero[i] += 1
ans = 0
for i in range(61):
ans += pow(2,i,mod)*zero[i]*one[i]
ans %=mod
print(ans%mod) | 1 | 122,801,709,767,950 | null | 263 | 263 |
x = int(input())
for _ in range(x):
print("ACL", end="") | print(''.join(map(str, ["ACL" for _ in range(int(input()))]))) | 1 | 2,213,262,493,708 | null | 69 | 69 |
def main():
n = int(input())
print((n+1)//2)
if __name__ == "__main__":
main() |
number = int(input())
number3 = number*number*number
print(number3) | 0 | null | 29,565,886,961,600 | 206 | 35 |
N = int(input())
a = []
b = []
for i in range(N):
x,y = (list(map(int,input().split())))
a.append(x+y)
b.append(x-y)
a.sort()
b.sort()
ans = max(a[-1]-a[0],b[-1]-b[0])
print(ans)
| from sys import stdin
def make_divisors(n):
mod0 = set()
mod1 = set()
for i in range(2, int(n**0.5)+1):
if n%i==0:
mod0.add(i)
mod0.add(n/i)
if (n-1)%i==0:
mod1.add(i)
mod1.add((n-1)/i)
return mod0,mod1
N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
if num==2:print(1)
else:
K=0
mod0,mod1=(make_divisors(num))
# mod0.remove(1)
# mod1.remove(1)
for i in mod0:
num = N[0]
while(num % i == 0):
num/=i
if num%i==1:
K+=1
K+=len(mod1)+2
print(K)
| 0 | null | 22,407,915,623,366 | 80 | 183 |
if __name__ == '__main__':
N, K = map(int, input().split())
have_snack = []
for i in range(K):
n = int(input())
have_snack.extend(list(map(int, input().split())))
ans = N - len(set(have_snack))
print(ans)
| n,k = map(int, input().split())
sunuke = []
for i in range(n):
sunuke.append(1)
for i in range(k):
d = int(input())
a = list(map(int, input().split()))
for j in range(d):
sunuke[a[j]-1] = 0
print(sum(sunuke)) | 1 | 24,545,681,939,392 | null | 154 | 154 |
S = input()
if S == 'AAA':
print('No')
elif S == 'BBB':
print('No')
else:
print('Yes') | s=input()
ans='Yes'
a=s[0]
b=s[1]
c=s[2]
if a==b and b==c and a==c:
ans='No'
print(ans)
| 1 | 54,756,832,250,382 | null | 201 | 201 |
N = input()
l = len(N)
for i in range(l):
if N[i] =="7":
print("Yes")
exit()
print("No") | import sys
n=input()
for x in n:
if x == "7":
print("Yes")
sys.exit()
print("No") | 1 | 34,177,738,743,610 | null | 172 | 172 |
import math
A = []
N = int(input())
maxdiff = 0
for n in range(N):
A.append(int(input()))
R = tuple(A)
Dmax = R[1] -R[0]
Rmin = R[0]
for i in range(1, N):
if R[i] >= R[i-1]:
if R[i] - Rmin > Dmax:
Dmax = R[i] -Rmin
if R[i] < Rmin:
Rmin = R[i]
# print(R[i], Dmax, Rmin)
print(Dmax) | #input an interget
k=int(input())
#input an string
str1=str(input())
#get the length of the string
x=int(len(str1))
#initialise y
y=0
#make a second string for the appending
str2="..."
#if statement about how the string will function
#if the string is the same length as k then print it
if x<=k:
print(str1)
#if not, delete the last character of the string
else:
while y<k:
print(str1[y],end=(""))
y+=1
print(str2)
| 0 | null | 9,929,944,347,690 | 13 | 143 |
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n = int(input())
s = input()
num = int(s, 2) # 元の2進数を数字に
opc = s.count('1') # 元の2進数のpopcount
# ±1したpopcountで余りを求めておく
if opc > 1:
num1 = num % (opc - 1)
else:
num1 = 0
num0 = num % (opc + 1)
for i in range(n):
if s[i] == '1':
if opc == 1:
print(0)
continue
tmp = (num1 - pow(2, n - 1 - i, opc - 1)) % (opc - 1)
else:
tmp = (num0 + pow(2, n - 1 - i, opc + 1)) % (opc + 1)
# binで2進数にしてpopcount求める
ans = 1
while tmp > 0:
tmp %= bin(tmp).count('1')
ans += 1
print(ans)
| def main():
n = input()
a, b = 0, 1
for i in n:
x = int(i)
a, b = min(a + x, b + 10 - x), min(a + x + 1, b + 10 - x - 1)
print(a)
main()
| 0 | null | 39,531,624,158,140 | 107 | 219 |
N = int(input())
A = list(map(int, input().split()))
for a in A:
if a % 2 == 0:
if a % 3 != 0 and a % 5 != 0:
print('DENIED')
break
else:
print('APPROVED') | n=int(input())
a=list(map(int,input().split()))
for i in a:
if i%2==0:
if i%3!=0 and i%5!=0:
print('DENIED')
exit()
print('APPROVED') | 1 | 68,910,118,617,440 | null | 217 | 217 |
import itertools
N = int(input())
L = list(map(int,(input().split())))
L.sort()
Combi = list(itertools.combinations(L, 3))
count = 0
for i in Combi:
a = int(i[0])
b = int(i[1])
c = int(i[2])
if((a+b)> c and a!=b != c and a<b <c ):
count+=1
print(count) | rate = int(input())
print(10 - rate//200) | 0 | null | 5,869,318,561,680 | 91 | 100 |
def main():
N = int(input())
A = tuple(map(int, input().split()))
a = list(A)
ans, n = bubbleSort(a, N)
print(*ans, sep=' ')
print(n)
def bubbleSort(a, n):
j = 0
flag = 1
while flag:
flag = 0
for i in range(1, n):
if a[i] < a[i-1]:
a[i], a[i-1] = a[i-1], a[i]
flag = 1
j += 1
return a, j
main() | n = int(input())
a = list(map(int,input().split()))
cnt = 0
flag = 1
while flag > 0:
flag = 0
for j in range(n-1,0,-1):
if a[j] < a[j-1]:
tmp = a[j]
a[j] = a[j-1]
a[j-1] = tmp
flag = 1
cnt += 1
print(' '.join(map(str,a)))
print(cnt)
| 1 | 17,830,996,898 | null | 14 | 14 |
n = int(input())
mod = 10**9 + 7
contain_zero = 0
contain_nine = 0
not_contain_zero_and_nine = 0
all_per = pow(10,n,mod)
if n < 2:
print(0)
else:
contain_zero = all_per - pow(9,n,mod)
contain_nine = all_per - pow(9,n,mod)
not_contain_zero_and_nine = pow(8,n,mod)
print((-(all_per - not_contain_zero_and_nine -contain_nine - contain_zero))%mod)
| from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math
#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())
INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7
def main():
n = int(rl())
x = pow(10, n, MOD) - 2*pow(9, n, MOD) + pow(8, n, MOD)
print(x % MOD)
stdout.close()
if __name__ == "__main__":
main() | 1 | 3,147,704,532,352 | null | 78 | 78 |
x = 0
while x == 0:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
for i in xrange(m[0]):
print "#" * m[1]
print "" | while 1:
h,w = map(int,raw_input().split())
if h==w==0: break
print ("#"*w+"\n")*h | 1 | 783,373,908,952 | null | 49 | 49 |
if __name__ == '__main__':
nm = input()
nm = nm.split()
n = int(nm[0])
m = int(nm[1])
if n%2==1:
for i in range(1,m+1):
print(i,n+1-i)
if n%2==0:
t = n
f = 0
for i in range(1,m+1):
p = i-1+t-n
if p>=n-i-1 and f==0:
f = 1
n -= 1
print(i,n)
n -= 1
| # coding: utf-8
N = 10
h = []
for n in range(N):
h.append(int(input()))
h = sorted(h, reverse = True)
for i in range(3):
print(h[i]) | 0 | null | 14,292,304,129,440 | 162 | 2 |
import re
strings = input()
def swapletter(match):
word = match.group()
return word.swapcase()
data = re.sub(r"\w+", swapletter, strings)
print(data)
| N, P = map(int, input().split())
S = input()
a = [0] * (N + 1)
if P != 2 and P != 5:
tenfactor=1
for i in range(1,N+1):
a[i] = ((int(S[N-i])*tenfactor+a[i-1])%P)
tenfactor*=10
tenfactor%=P
ans = 0
from collections import Counter
C=Counter(a)
for v,i in C.items():
ans += (i * (i - 1) // 2)
elif P == 2:
ans = 0
for i in range(N):
if int(S[i]) % 2 == 0:
ans += i + 1
elif P == 5:
ans = 0
for i in range(N):
if int(S[i]) == 0 or int(S[i]) == 5:
ans += i + 1
print(ans)
| 0 | null | 29,808,008,426,440 | 61 | 205 |
N,M=map(int,input().split())
A,c,dp,r=[0]*N,0,0,[]
for i, s in enumerate(reversed(input())):
if s=="1":c+=1;A[i]=c
else:c=0
while dp+M<=N-1:
t = M-A[dp+M]
if t>0: dp+=t
else:print(-1);exit()
r.append(t)
r.append(N-dp)
print(*reversed(r)) | 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))) | 0 | null | 115,000,627,129,762 | 274 | 238 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter
N, P = map(int, readline().split())
S = list(map(int, read().rstrip().decode()))
def solve_2(S):
ind = (i for i, x in enumerate(S, 1) if x % 2 == 0)
return sum(ind)
def solve_5(S):
ind = (i for i, x in enumerate(S, 1) if x % 5 == 0)
return sum(ind)
def solve(S,P):
if P == 2:
return solve_2(S)
if P == 5:
return solve_5(S)
S = S[::-1]
T = [0] * len(S)
T[0] = S[0] % P
power = 1
for i in range(1, len(S)):
power *= 10
power %= P
T[i] = T[i-1] + power * S[i]
T[i] %= P
counter = Counter(T)
return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]
print(solve(S,P))
| r,c = map(int,raw_input().split())
a = [map(int,raw_input().split()) for _ in range(r)]
b = [0 for _ in range(c)]
for i in range(r) :
s = 0
for j in range(c) :
s = s + a[i][j]
b[j] = b[j] + a[i][j]
a[i].append(s)
print ' '.join(map(str,a[i]))
b.append(sum(b))
print ' '.join(map(str,b)) | 0 | null | 29,823,861,858,880 | 205 | 59 |
from math import sin, cos, radians
a, b, C = (float(x) for x in input().split())
s = a * b * sin(radians(C)) * 0.5
l = (a **2 + b**2 - 2 * a * b * cos(radians(C))) ** 0.5 + a + b
h = s * 2 / a
print(s)
print(l)
print(h) | #!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import math
a, b, c = map(float, sys.stdin.readline().split())
degree = abs(180-abs(c))*math.pi / 180
height = abs(b * math.sin(degree))
pos_x = b * math.cos(degree) + a
edge_x = (height**2 + pos_x**2) ** 0.5
print(round(a * height / 2, 6))
print(round(a + b + edge_x, 6))
print(round(height, 6))
| 1 | 173,425,409,728 | null | 30 | 30 |
k = int(input().split(' ')[1])
print(sum( sorted([int(n) for n in input().split(' ')])[0:k])) | N, K = map(int, input().split())
print(sum(sorted(list(map(int, input().split())))[0:K])) | 1 | 11,722,424,213,580 | null | 120 | 120 |
def nCk(n, k):
if k > n or min(n, k) < 0:
return 0
res = 1
for i in range(1, k + 1):
res = res * (n - i + 1) // i
return res
def solveSmaller():
return 9 ** k * nCk(n - 1, k)
def solveDp():
global k
dp = [[[0 for _ in range(2)] for _ in range(k + 1)] for _ in range(n)] # i, used k, smaller
dp[0][1][0] = 1
dp[0][1][1] = int(s[0]) - 1
cnt = 1
for i in range(1, n):
cnt += s[i] != '0'
for k in range(1, k + 1):
dp[i][k][0] = cnt == k
dp[i][k][1] = dp[i - 1][k][1] + \
(dp[i - 1][k][0] if s[i] != '0' else 0) + \
dp[i - 1][k - 1][1] * 9 + \
dp[i - 1][k - 1][0] * max(0, int(s[i]) - 1)
return dp[n - 1][k][0] + dp[n - 1][k][1]
s = input()
k = int(input())
n = len(s)
print(solveSmaller() + solveDp()) | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
#from operator import itemgetter
#inf = 10**17
#mod = 10**9 + 7
x,y = map(int, input().split())
a = 0
b = 0
if x==1:
a += 300000
if x==2:
a += 200000
if x==3:
a += 100000
if y==1:
b += 300000
if y==2:
b += 200000
if y==3:
b += 100000
if a+b == 600000:
print(1000000)
else:
print(a+b)
if __name__ == '__main__':
main() | 0 | null | 108,090,756,281,692 | 224 | 275 |
N = int(input())
A = list(map(int, input().split()))
if N == 0:
if A[0] == 1:
print (1)
exit()
else:
print (-1)
exit()
MAX = 10 ** 18
lst = [1] * (10 ** 5 + 10)
#純粋な2分木としたときの最大値
for i in range(N + 1):
lst[i + 1] = min(MAX, lst[i] * 2)
# print (lst[:10])
for i in range(N + 1):
tmp = lst[i] - A[i]
if tmp < 0:
print (-1)
exit()
lst[i + 1] = min(lst[i + 1], tmp * 2)
# print (lst[:10])
if lst[N] >= A[N]:
lst[N] = A[N]
else:
print (-1)
exit()
# print (lst[:10])
ans = 1
tmp = 0
for i in range(N, 0, -1):
ans += lst[i]
lst[i - 1] = min(lst[i] + A[i - 1], lst[i - 1])
# print (lst[:10])
print (ans)
| import math
while True:
n = int(input())
if n == 0: break
points = list(map(int, input().split()))
mean = sum(points) / n
s = 0
for point in points:
s += (point - mean) ** 2
std = math.sqrt(s / n)
print(std) | 0 | null | 9,451,152,996,140 | 141 | 31 |
import sys
input = sys.stdin.readline
def main():
mod = 10**9 + 7
n = int(input())
all = pow(10, n, mod)
non_0 = non_9 = pow(9, n, mod)
non_0_and_9 = pow(8, n, mod)
ans = all - non_0 - non_9 + non_0_and_9
print(ans % mod)
if __name__ == "__main__":
main()
| 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) | 1 | 3,184,890,708,240 | null | 78 | 78 |
_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())
def exSearch(i, m):
if m == 0:
return True
if i >= len(hoge) or m > sum(hoge):
return False
res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
return res
if __name__ == '__main__':
for val in (int(x) for x in input().split()):
if exSearch(0, val):
print ('yes')
else:
print ('no')
| n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(input().split())
for i in range(m):
B[i] = int(B[i])
def solve(x,y):
if x==n:
S[y] = 1
else:
solve(x+1,y)
if y+A[x] < 2001:
solve(x+1,y+A[x])
S = [0 for i in range(2001)]
solve(0,0)
for i in range(m):
if S[B[i]] == 1:
print("yes")
else:
print("no")
| 1 | 98,798,941,450 | null | 25 | 25 |
import sys
input = sys.stdin.readline
def main():
R, C,K = map(int, input().split())
dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
# dp[r][c][j] :=r index c columns already j cnt
dp[0][0][0] = 0
D = [[0 for i in range(C+1)] for j in range(R+1)]
import random
for i in range(K):
r, c, v = map(int,input().split())
D[r][c] = v
for i in range(R+1):
for j in range(C+1):
if D[i][j] > 0:
v = D[i][j]
M = max(dp[k][i-1][j] for k in range(4))
dp[0][i][j] = max(dp[0][i][j-1], M)
dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
else:
M = max(dp[k][i-1][j] for k in range(4))
dp[0][i][j] = max(dp[0][i][j-1], M)
dp[1][i][j] = dp[1][i][j-1]
dp[2][i][j] = dp[2][i][j-1]
dp[3][i][j] = dp[3][i][j-1]
ans = max(dp[i][-1][-1] for i in range(4))
print(ans)
main() | s=input()
count=s.count("B")
if count==3 or count==0:
print("No")
else:
print("Yes") | 0 | null | 30,034,097,369,400 | 94 | 201 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
S, T = input().split()
A, B = map(int, readline().split())
U = input()
if S == U:
A -= 1
if T == U:
B -= 1
print(A, B)
if __name__ == '__main__':
main()
| import os, sys, re, math
(S, T) = [n for n in input().split()]
(A, B) = [int(n) for n in input().split()]
U = input()
if U == S:
A -= 1
else:
B -= 1
print('%s %s' % (A, B))
| 1 | 71,851,272,522,160 | null | 220 | 220 |
N,K =map(int,input().split())
count=0
while 1:
if N//(K**count)==0:
break
count +=1
print(count)
| n,k = [int(x) for x in input().split()]
res = 0
while n > 0:
n //= k
res += 1
print(res) | 1 | 64,612,630,027,300 | null | 212 | 212 |
def aizu006():
while True:
xs = map(int,raw_input().split())
if xs[0] == 0 and xs[1] == 0: break
else:
xs.sort()
for i in range(0,2):
print xs[i],
print
aizu006() | string = input('')
if string.endswith('s'):
print(string + 'es')
else:
print(string + 's') | 0 | null | 1,468,042,407,536 | 43 | 71 |
N = int(input())
ans = 0
cnt = 1
while N > 0:
if N == 1:
ans += cnt
break
N //= 2
ans += cnt
cnt *= 2
print(ans)
| def g(x):
return x*(x+1)//2
n=int(input())
ans=0
for i in range(1,n+1):
ans=ans+i*g(n//i)
print(ans) | 0 | null | 45,375,816,603,102 | 228 | 118 |
import math
n = int(input())
x_buf = input().split()
y_buf = input().split()
x = []
y = []
for i in range(n):
x.append(int(x_buf[i]))
y.append(int(y_buf[i]))
sum1 = 0
sum2 = 0
sum3 = 0
sum_inf = 0
max_inf = 0
for i in range(n):
sum1 += abs(x[i] - y[i])
sum2 += abs(x[i] - y[i]) ** 2
sum3 += abs(x[i] - y[i]) ** 3
sum_inf = abs(x[i] - y[i])
if max_inf < sum_inf:
max_inf = sum_inf
d1 = sum1
d2 = math.sqrt(sum2)
d3 = sum3 ** (1/3)
d4 = max_inf
print(d1)
print(d2)
print(d3)
print(d4)
| n = int(input())
title = []
length = []
for i in range(n):
a, b = input().split()
title.append(a)
length.append(int(b))
i = title.index(input())
print(sum((length[i+1:]))) | 0 | null | 48,844,608,489,330 | 32 | 243 |
import math
r = float(input())
a = math.pi * r**2
b = math.pi * r * 2
print(str(a) + " " + str(b)) | n = int(input())
s = list(input())
b = 0
d = s[0]
for i in range(n):
if d != s[i]:
d = s[i]
b += 1
print(b+1)
| 0 | null | 85,735,837,811,040 | 46 | 293 |
S = input()
kuri = False
ans = 0
for i in range(len(S)-1, -1, -1):
K = int(S[i])
if kuri:
K += 1
kuri = False
if K < 5:
ans += K
elif K > 5:
ans += (10-K)
kuri = True
elif K == 5:
if i > 0:
M = int(S[i-1])
if i != 0 and M >= 5:
kuri = True
ans += 5
if i == 0 and kuri:
ans += 1
print(ans)
| s = list(input())
q = int(input())
before = []
after = []
cnt = 0
for i in range(q):
t = list(input().split())
if t[0] == "1":
cnt += 1
else:
f = t[1]
c = t[2]
if f == "1":
if cnt%2 == 0:
before.append(c)
else:
after.append(c)
else:
if cnt%2 == 0:
after.append(c)
else:
before.append(c)
if cnt%2 == 1:
s.reverse()
after.reverse()
#before.reverse()
for i in after:
print(i,end = "")
for i in s:
print(i,end = "")
for i in before:
print(i,end = "")
else:
before.reverse()
before.extend(s)
before.extend(after)
for i in before:
print(i,end = "") | 0 | null | 64,005,985,790,912 | 219 | 204 |
n=int(input())
s=list(input())
rn=s.count('R')
gn=s.count('G')
bn=n-rn-gn
ans=bn*gn*rn
if n>2:
for x in range(n-2):
y=(n-1-x)//2
for i in range(1,y+1):
if (not s[x]==s[x+i]) & (not s[x]==s[x+i+i]) & (not s[x+i]==s[x+i+i]):
ans-=1
print(ans)
else:
print(0)
| from itertools import permutations
n = int(input())
s = input()
out = 0
ans = s.count("R")*s.count("G")*s.count("B")
combi = list(permutations(["R","G","B"],3))
for i in range(1,n):
for j in range(n-i*2):
if (s[j], s[j+i], s[j+i*2]) in combi:
ans -= 1
print(ans) | 1 | 36,068,852,802,400 | null | 175 | 175 |
import math
R = float(input())
print(float(2*R*math.pi)) | n, k, s = map(int, input().split())
# 1. 全部10**9
# 2. s=10**9の時, 他は1でok
if s == 10 ** 9:
a = [5] * n
else:
a = [10 ** 9] * n
for i in range(k):
a[i] = s
print(*a)
| 0 | null | 61,475,492,909,488 | 167 | 238 |
nums=input().split()
t=int(nums[0])/int(nums[2])
if t<=int(nums[1]):
print("Yes")
else:
print("No")
| n = int(input())
a = list(map(int,input().split()))
cumsum_a = a.copy()
for i in range(n-1, -1, -1):
cumsum_a[i] += cumsum_a[i+1]
ans = 0
node = 1
for i in range(n + 1):
if a[i] > node:
ans = -1
break
ans += node
if i < n:
node = min(2 * (node - a[i]), cumsum_a[i + 1])
print(ans) | 0 | null | 11,122,077,901,350 | 81 | 141 |
while True:
try:
a = map(int,raw_input().split(' '))
s = a[0] + a[1]
c = 0
while s > 0:
s = s / 10
c = c + 1
if s <= 0:
print c
break
except (EOFError):
break | from collections import deque
s=deque(list(input()))
flag=0
for i in range(int(input())):
dir=input().split()
if int(dir[0])==1:flag+=1
else:
if int(dir[1])==1:
if flag%2==0:s.appendleft(dir[2])
else:s.append(dir[2])
else:
if flag%2==0:s.append(dir[2])
else:s.appendleft(dir[2])
s=list(s)
if flag%2==1:s.reverse()
print(*s,sep='') | 0 | null | 28,827,174,252,730 | 3 | 204 |
import string
N = int(input())
S = input()
a = string.ascii_uppercase
# a = ABCDEFGHIJKLMNOPQRSTUVWXYZ
ans = ''
for s in S:
ans += a[(a.index(s) + N) % len(a)]
print(ans) | # -*- coding: utf-8 -*-
def selection_sort(a, n):
count = 0
for i in range(n):
minj = i
for j in range(i+1, n):
if a[j] < a[minj]:
minj = j
a[i], a[minj] = a[minj], a[i]
if a[i] != a[minj]:
count += 1
return a, count
def main():
input_num = int(input())
input_list = [int(i) for i in input().split()]
ans_list, count = selection_sort(input_list, input_num)
for i in range(input_num):
if i != 0:
print(" ", end="")
print(ans_list[i], end='')
print()
print(count)
if __name__ == '__main__':
main() | 0 | null | 67,578,428,759,172 | 271 | 15 |
d = int(input())
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
X = [int(input()) - 1 for i in range(d)]
L = [-1 for j in range(26)]
score = 0
for i in range(d):
L[X[i]] = i
score += S[i][X[i]]
score -= sum([C[j] * (i - L[j]) for j in range(26)])
print(score)
| from fractions import gcd
import sys
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [i // 2 for i in a]
def div2check(i):
count = 0
while i % 2 == 0:
count += 1
i //= 2
return count
c = [div2check(i) for i in b]
if c.count(c[0]) != n:
print(0)
sys.exit()
lcm = b[0]
for i in b[1:]:
lcm = lcm * i // gcd(lcm, i)
print((m // lcm + 1) // 2) | 0 | null | 55,754,434,755,012 | 114 | 247 |
a = int(input())
print('YNeos'[a<30::2])
| n,m=map(int,input().split())
if n%2==1:
[print(i+1,n-i) for i in range(m)]
else:
[print(i+1,n-i) if i<m/2 else print(i+1,n-i-1) for i in range(m)]
| 0 | null | 17,100,124,121,430 | 95 | 162 |
k = input().split()
n1 = int(k[0])
n2 = int(k[1])
ans = n1 * n2
print(ans) | import math
K = int(input())
total = 0
for x in range(1, K+1):
for y in range(1, K+1):
for z in range(1, K+1):
total = total+math.gcd(x, math.gcd(y, z))
print(total)
| 0 | null | 25,875,612,906,752 | 133 | 174 |
A, B = map(int, input().split())
print('0') if A <= 2*B else print(A - 2*B)
| n = int(input())
p = list(map(int, input().split()))
lower = p[0]
cnt = 1
for i in range(1, n):
if lower > p[i]:
cnt += 1
lower = min(lower, p[i])
print(cnt)
| 0 | null | 126,229,756,216,080 | 291 | 233 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.