code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
s = input()[::-1]
cnts = [0] * 2019
cnts[0] = 1
n, d = 0, 1
for char in s:
n = (n + int(char) * d) % 2019
d = d * 10 % 2019
cnts[n] += 1
ans = 0
for cnt in cnts:
ans += cnt * (cnt - 1) // 2
print(ans)
| from collections import Counter
S = input()
S = S[::-1]
# 1桁のmod2019, 2桁の2019, ...
# 0桁のmod2019=0と定めると都合が良いので入れておく
l = [0]
num = 0
for i in range(len(S)):
# 繰り返し二乗法で累乗の部分を高速化
# 自分で書かなくてもpow()で既に実装されている
# 一つ前のmodを利用するとPythonで通せた、それをしなくてもPyPyなら通る
num += int(S[i]) * pow(10,i,2019)
l.append(num % 2019)
# print(l)
ans = 0
c = Counter(l)
for v in c.values():
ans += v*(v-1)//2
print(ans)
| 1 | 30,871,066,529,160 | null | 166 | 166 |
# -*- codinf: utf-8 -*-
import math
N = int(input())
# 素因数分解
n = N
i = 2
f = {} # keyが素因数、valueが素因数の数
while i * i <= n:
count = 0
while n % i == 0:
count += 1
f[i] = count
n /= i
i += 1
if 1 < n:
f[n] = 1
if len(f) == 0:
print(0)
exit()
count = 0
for v in f.values():
d = 1
while v > 0:
v -= d
if v >= 0:
count += 1
d += 1
print(count) | def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
k += 1
return str(ans + (n >= rn))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 16,919,483,701,104 | null | 136 | 136 |
#coding:utf-8
#????????¢?????????
def draw_square(h, w):
for i in range(h):
a = ""
for j in range(w):
a += "#"
print a
while 1:
HW = raw_input().split()
H = int(HW[0])
W = int(HW[1])
if H == 0 and W == 0:
break
draw_square(H, W)
print "" | a,b=sorted(list(map(int, input().split())))
m=b%a
while m>=1:
b=a
a=m
m=b%a
print(a) | 0 | null | 398,958,505,712 | 49 | 11 |
S = str(input())
r = len(S)
print('x'*r) | def main():
s = list(input())
for i in range(len(s)):
s[i] = "x"
L = "".join(s)
print(L)
if __name__ == "__main__":
main()
| 1 | 72,835,501,249,240 | null | 221 | 221 |
import math
def prime(num):
if num==1 or num==2 or num==3:
return True
for i in range(2,int(math.sqrt(num))+1):
if num%i==0:
return False
else:
return True
n=int(input())
ans=0
for i in range(n):
tmp=int(input())
if prime(tmp):
ans+=1
print(ans)
| def MAP(): return map(int, input().split())
def LIST(): return list(MAP())
N = int(input())
count = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
string_i = str(i)
initial = int(string_i[0])
end = int(string_i[-1])
count[initial][end] += 1
ans = 0
for i in range(1, 10):
for j in range(1, 10):
ans += count[i][j] * count[j][i]
print(ans) | 0 | null | 43,348,715,949,660 | 12 | 234 |
N=int(input())
A=list(map(int,input().split()))
np,nm=[],[]
for i in range(N):
np.append(A[i]+i)
nm.append(i-A[i])
sp,sm=sorted(np),sorted(nm)
ans=0
for i in range(N):
p,m=np[i],nm[i]
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sm[x]<=p:
l=x
else:
r=x
tmp=l
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sm[x]<p:
l=x
else:
r=x
ans+=tmp-l
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sp[x]<=m:
l=x
else:
r=x
tmp=l
l,r=-1,N
while not l+1==r:
x=(l+r)//2
if sp[x]<m:
l=x
else:
r=x
ans+=tmp-l
print(ans//2) | def resolve():
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
L = defaultdict(int)
ans = 0
for i in range(N):
L[A[i] + i] += 1
ans += L[i - A[i]]
print(ans)
resolve()
| 1 | 26,130,285,984,670 | null | 157 | 157 |
n, k = map(int, input().split())
li_a = list(map(int, input().split()))
for idx, v in enumerate(li_a):
if idx <= (k - 1):
pass
else:
if v > li_a[idx - k]:
print('Yes')
else:
print('No')
| N,K = map(int,input().split())
A = [int(a) for a in input().split()]
n = 0
for i in range(K,N):
if A[i] > A[n] :
print("Yes")
else:
print("No")
n+=1
| 1 | 7,156,964,515,140 | null | 102 | 102 |
import math
N, M = list(map(int, input().split()))
n_pairs = math.factorial(N) // (2*math.factorial(N-2)) if N > 1 else 0
m_pairs = math.factorial(M) // (2*math.factorial(M-2)) if M > 1 else 0
print(n_pairs + m_pairs) | from operator import mul
from functools import reduce
def cmb(n,r):
#n<10^4で最速s
r = min(n-r,r)
if r == 0: return 1
over = reduce(mul, range(n, n - r, -1))
under = reduce(mul, range(1,r + 1))
return over // under
n,m=map(int,input().split())
if n>=2 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n>=2:print(cmb(n,2))
elif m>=2:print(cmb(m,2))
else:print(0) | 1 | 45,462,970,975,770 | null | 189 | 189 |
# -*- coding: utf-8 -*-
while True:
s = raw_input()
if s=="0": break
t = 0
for n in s:
t += int(n)
print t | import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for p in range(1, 4):
sum = 0
for i in range(n):
sum += math.fabs(x[i]-y[i])**p
print(sum**(1/p))
a = []
for i in range(n):
a.append(math.fabs(x[i]-y[i]))
a.sort()
print(a[n-1]) | 0 | null | 897,332,442,812 | 62 | 32 |
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
num = int(input()) - 1
print(list[num]) | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
xc = Counter()
yc = Counter()
for i, v in enumerate(a):
xc[i + v] += 1
yc[i - v] += 1
ans = 0
for v in xc:
ans += xc[v] * yc[v]
print(ans)
| 0 | null | 38,091,364,214,420 | 195 | 157 |
X,N = map(int,input().split())
p = list(map(int, input().split()))
i = 0
if X not in p:
print(X)
else:
while True:
i += 1
if X - i not in p:
print(X-i)
break
if X+i not in p:
print(X+i)
break
| x, n = map(int, input().split())
p = set(map(int, input().split()))
ans = 1000
ans = min(abs(x-i) for i in range(102) if i not in p)
print(x + ans if x - ans in p else x - ans)
| 1 | 14,079,793,210,272 | null | 128 | 128 |
while True:
a,b=map(int,raw_input().split())
if a+b==0:
break
print ('#'*b+'\n')*a | first_flag = True
while True:
H, W = map(int, input().split())
if H == 0 and W == 0: break
if not first_flag:
print()
first_flag = False
print(("#" * W + "\n") * H) | 1 | 768,172,655,100 | null | 49 | 49 |
import math
A,B,H,M=map(int,input().split())
x=2*math.pi*abs(H/12+M/60/12-M/60)
ans=pow(A*A+B*B-2*A*B*math.cos(x),1/2)
print(ans) | def readinput():
n=int(input())
return n
def main(n):
x7=int(n/1.07)+1
x9=int(n/1.09)-1
n100=n*100
for x in range(max(1,x9),x7+1):
xx=x*108//100
#print(x,xx)
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| 0 | null | 72,895,286,363,102 | 144 | 265 |
# B - Homework
# N M
N, M = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
if N < sum(my_list):
answer = -1
else:
answer = N - sum(my_list)
print(answer)
| n,m = map(int,input().split())
a = [int(i) for i in input().split()]
ans = n - sum(a)
if ans < 0:
ans = -1
print(ans) | 1 | 32,196,906,906,500 | null | 168 | 168 |
def main():
n = int(input())
a = list(map(int,input().split()))
f,s = {},{}
for i in range(n):
if i+1-a[i] not in f.keys():
f[i+1-a[i]] = 1
else:
f[i+1-a[i]]+=1
if i+1+a[i] not in s.keys():
s[i+1+a[i]] = 1
else:
s[i+1+a[i]] += 1
ans = 0
for k in f.keys():
if k in s.keys():
ans += f[k] * s[k]
print(ans)
if __name__ == "__main__":
main()
| import collections
cnt = collections.defaultdict(int)
N = int(input())
ans = 0
height = list(map(int, input().split()))
for n in range(1, N+1):
ans += cnt[n - height[n-1]]
cnt[n+height[n-1]] += 1
print(ans) | 1 | 26,196,750,427,260 | null | 157 | 157 |
for i in range(1,10):
for k in range(1,10):
print("{0}x{1}={2}".format(i,k,i*k)) | # -*- coding: utf-8 -*-
def qq(limit=9):
qq_str = ''
for i in range(1, limit+1):
for j in range(1, limit+1):
qq_str += str(i) + 'x' + str(j) + '=' + str(i*j)
if i != limit or j != limit:
qq_str += '\n'
return qq_str
def main():
print(qq())
if __name__ == '__main__':
main() | 1 | 2,000,570 | null | 1 | 1 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
class Combination:
"""
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
co = Combination(200006)
n,m = inpl()
if m >= n:
m = n-1
res = 1
if m == 1:
print(co(n-1,n-2) * n)
quit()
else:
for i in range(m):
tmp = i+1
res += co(n-1,n-tmp-1) * co(n,tmp)
res %= mod
# print(res)
print(res) | import sys
def main():
N, K = map(int, sys.stdin.readline().rstrip().split())
L = [0] * 10
R = [0] * 10
for i in range(K):
l, r = map(int, sys.stdin.readline().rstrip().split())
L[i], R[i] = l, r
dp = [0] * (N + 1)
up = [0] * (N + 1)
up[0] = 1
up[1] = -1
for i in range(1, N + 1):
dp[i] = dp[i - 1] + up[i - 1]
for j in range(K):
if i + (L[j] - 1) < N + 1:
up[i + (L[j] - 1)] += dp[i]
if i + R[j] < N + 1:
up[i + R[j]] -= dp[i]
dp[i] %= 998244353
print(dp[N])
main()
| 0 | null | 34,834,402,174,960 | 215 | 74 |
import math
import itertools
import sys
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))
h.sort(reverse=True)
ans = 0
for i in range(len(h)):
if(h[i] < k):
ans = i
print(ans)
sys.exit()
print(len(h)) | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s=input()
if len(s)%2==1:
print("No")
sys.exit()
for i in range(len(s)//2):
if s[2*i:2*i+2]!="hi":
print("No")
break
else:print("Yes")
if __name__=='__main__':
main() | 0 | null | 116,324,564,288,042 | 298 | 199 |
import sys
input = sys.stdin.readline
def main():
s = input().rstrip('\n')
if s[-1] == 's':
s += 'es'
else:
s += 's'
print(s)
if __name__ == '__main__':
main() | import sys
def m():
d={};input()
for e in sys.stdin:
if'f'==e[0]:print('yes'if e[5:]in d else'no')
else:d[e[7:]]=0
if'__main__'==__name__:m()
| 0 | null | 1,236,145,882,940 | 71 | 23 |
downs, ponds = [], []
for i, s in enumerate(input()):
if s == "\\":
downs.append(i)
elif s == "/" and downs:
i_down = downs.pop()
area = i - i_down
while ponds and ponds[-1][0] > i_down:
area += ponds.pop()[1]
ponds.append([i_down, area])
print(sum(p[1] for p in ponds))
print(len(ponds), *(p[1] for p in ponds))
| A = 0
left = []
Lake = []
s = input()
for i in range(len(s)):
if s[i] == "\\":
left.append(i)
elif s[i] == "/":
if len(left) > 0:
w = left.pop()
goukei = i - w
A += goukei
for i in range(len(Lake)-1,-1,-1):
if Lake[i][0] > w:
x = Lake.pop()
goukei += x[1]
Lake.append([w, goukei])
print(A)
if len(Lake) == 0:
print(0)
else:
print(len(Lake),end=" ")
for i in range(len(Lake)):
if i == len(Lake) - 1:
print(Lake[i][1])
else:
print(Lake[i][1],end=" ") | 1 | 60,424,464,332 | null | 21 | 21 |
def shuffle(s,n):
if len(s) <= 1:
return s
ans = s[n:] + s[:n]
return ans
def main():
while True:
strings = input()
if strings == "-":
break
n = int(input())
li = []
for i in range(n):
li.append(int(input()))
for i in li:
strings = shuffle(strings, i)
print(strings)
if __name__ == "__main__":
main() | while True:
Str = list(input())
if Str[0] == '-':
break
m = int(input())
for i1 in range(m):
h = int(input())
for i2 in range(h):
Str.extend(Str[0])
Str.remove(Str[0])
for i in range(len(Str)):
print(Str[i], end = '')
print() | 1 | 1,886,150,083,906 | null | 66 | 66 |
import sys
import os
for line in sys.stdin:
H, W = map(int, line.split())
if H == 0 and W == 0:
break
print(('#' * W + '\n') * H)
| import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
class BIT:
def __init__(self, L):
self.n = len(L)
self.bit = [0] * (self.n + 1)
def update(self, idx, x):
while idx <= self.n:
self.bit[idx] += x
idx += idx & (-idx)
def query(self, idx):
res = 0
while idx > 0:
res += self.bit[idx]
idx -= idx & (-idx)
return res
def sec_sum(self, left, right):
return self.query(right) - self.query(left - 1)
def debug(self):
print(*[self.sec_sum(i, i) for i in range(1, self.n + 1)])
def resolve():
n = int(input())
S = list(input().rstrip())
q = int(input())
bits = [BIT(S) for _ in range(26)]
for idx in range(1, n + 1):
s = S[idx - 1]
bits[ord(s) - ord("a")].update(idx, 1)
for _ in range(q):
query = list(input().split())
if query[0] == "1":
i, c = int(query[1]), query[2]
prev = S[i - 1]
bits[ord(prev) - ord("a")].update(i, -1)
bits[ord(c) - ord("a")].update(i, 1)
S[i - 1] = c
else:
l, r = int(query[1]), int(query[2])
res = 0
for j in range(26):
if bits[j].sec_sum(l, r):
res += 1
print(res)
if __name__ == '__main__':
resolve()
| 0 | null | 31,434,789,765,400 | 49 | 210 |
N = int(input())
if N%2==1:
print(0)
else:
ans = 0
judge = 10
while True:
if judge > N:
break
else:
ans += N//judge
judge *= 5
print(ans) | """
入力例 1
11 3 2
ooxxxoxxxoo
->6
入力例 2
5 2 3
ooxoo
->1
->5
入力例 3
5 1 0
ooooo
->
入力例 4
16 4 3
ooxxoxoxxxoxoxxo
->11
->16
"""
n,k,c = map(int,input().split())
s = input()
r=[0]*n
l=[0]*n
ki=0
ci=100000
for i in range(n):
ci += 1
if s[i]=='x':
continue
if ci > c:
ci = 0
ki+=1
l[i]=ki
if ki == k:
break
ki=k
ci=100000
for i in range(n):
ci += 1
if s[n-1-i]=='x':
continue
if ci > c:
ci = 0
r[n-1-i]=ki
ki-=1
if ki == 0:
break
ret=[]
for i in range(n):
if r[i]==l[i] and r[i]!=0:
ret.append(i+1)
# print(l)
# print(r)
for i in range(len(ret)):
print(ret[i])
| 0 | null | 78,011,629,378,454 | 258 | 182 |
#!/usr/bin/env python3
def inp():
n, m = map(int, input().split())
return n - 1, m - 1
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 rem(cand, p, q):
cand[p] += 1
cand[q] += 1
n, m, k = map(int, input().split())
UF = UnionFind(n)
non_cand = [1] * n
for _ in range(m):
a, b = inp()
UF.union(a, b)
rem(non_cand, a, b)
for _ in range(k):
c, d = inp()
if UF.same(c, d):
rem(non_cand, c, d)
ans = [UF.size(i) - non_cand[i] for i in range(n)]
print(*ans) | #!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
class UnionFind:
def __init__(self, n):
self._parent = [i for i in range(n)]
self._rank = [0 for _ in range(n)]
self._group_size = [1 for _ in range(n)]
self.num_of_groups = n
def find(self, x):
if self._parent[x] == x:
return x
px = self._parent[x]
root = self.find(px)
self._parent[x] = root
return root
def union(self, x, y):
px = self.find(x)
py = self.find(y)
if px == py:
return
if self._rank[px] < self._rank[py]:
self._parent[px] = py
self._group_size[py] += self._group_size[px]
else:
self._parent[py] = px
self._group_size[px] += self._group_size[py]
if self._rank[px] == self._rank[py]:
self._rank[py] += 1
self.num_of_groups -= 1
def is_same(self, x, y):
return self.find(x) == self.find(y)
def group_size(self, x):
px = self.find(x)
return self._group_size[px]
def main():
N, M, K = LI()
AB = [LI1() for _ in range(M)]
CD = [LI1() for _ in range(K)]
uf = UnionFind(N)
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]
for (a, b) in AB:
friend[a].append(b)
friend[b].append(a)
uf.union(a, b)
for (c, d) in CD:
block[c].append(d)
block[d].append(c)
for i in range(N):
gs = uf.group_size(i)
bc = 0
for bi in block[i]:
bc += int(uf.is_same(i, bi))
# print(i, gs, fc, bc)
print(gs - len(friend[i]) - bc - 1, end=" ")
main()
| 1 | 61,667,852,285,910 | null | 209 | 209 |
h=t=0
for _ in range(int(input())):
a,b=input().split()
if a>b:t+=3
elif a<b:h+=3
else:t+=1;h+=1
print(t,h) | N, D, A = map(int, input().split())
monster = []
for k in range(N):
monster.append(list(map(int, input().split())))
monster.sort(key = lambda x: x[0])
for k in range(N):
monster[k][1] = int((monster[k][1]-0.1)//A + 1)
ans = 0
final = monster[-1][0]
ruiseki = 0
minuslist = []
j = 0
for k in range(N):
while (j < len(minuslist)):
if monster[k][0] >= minuslist[j][0]:
ruiseki -= minuslist[j][1]
j += 1
else:
break
if ruiseki < monster[k][1]:
ans += monster[k][1] - ruiseki
if monster[k][0] + 2*D +1 <= final:
minuslist.append([monster[k][0]+2*D+1, monster[k][1] - ruiseki])
ruiseki = monster[k][1]
print(ans)
| 0 | null | 42,337,543,599,338 | 67 | 230 |
w=input()
a=0
while True:
t=input().split()
l=[]
for T in t:
l.append(T.lower())
a+=l.count(w)
if t[0]=="END_OF_TEXT":
break
print(a)
| # coding: utf-8
# Here your code !
def func():
try:
word=input().rstrip().lower()
words=[]
while(True):
line=input().rstrip()
if(line == "END_OF_TEXT"):
break
else:
words.extend(line.lower().split(" "))
except:
return inputError()
print(words.count(word))
def inputError():
print("input Error")
return -1
func() | 1 | 1,793,638,192,194 | null | 65 | 65 |
X, Y = map(int, input().split())
print(400000*(X==1)*(Y==1) + max(0, 400000-100000*X) + max(0, 400000-100000*Y)) | x,y = map(int,input().split())
if(x+y==2):
print(1000000)
else:
answer = 0
if(x==2):
answer+=200000
elif(x==3):
answer+=100000
elif(x==1):
answer+=300000
if(y==2):
answer+=200000
elif(y==3):
answer+=100000
elif(y==1):
answer+=300000
print(answer)
| 1 | 140,338,114,615,808 | null | 275 | 275 |
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for nesya in range(m)]
cheap = min(a)+min(b)
for hoge in xyc:
ch = a[hoge[0]-1]+b[hoge[1]-1]-hoge[2]
cheap = min(ch,cheap)
print(cheap) | a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans = 123456789012345
for i in range(m):
x,y,c=map(int,input().split())
ans = min(ans, a[x-1]+b[y-1]-c)
a.sort()
b.sort()
ans = min(ans,a[0]+b[0])
print(ans) | 1 | 54,048,888,503,610 | null | 200 | 200 |
X,Y = map(int,input().split())
for i in range(X+1):
a = i*2 + (X-i)*4
if a == Y:
print("Yes")
break
if a != Y:
print("No")
|
def main():
s = input()
s_ = set(s)
if len(s_) >= 2:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 0 | null | 34,289,455,241,118 | 127 | 201 |
from collections import deque
import sys
c=sys.stdin
def main():
q = deque()
N=int(input())
for i in range(N):
order=c.readline()
if order[6]==" ":
if order[0]=="i":
q.appendleft(int(order[7:]))
else:
try :
q.remove(int(order[7:]))
except:
pass
else:
if order[6]=="F":
q.popleft()
else:
q.pop()
print(*list(q))
if __name__ == "__main__":
main()
| def LI():
return list(map(int, input().split()))
def LSH(h):
return [list(input()) for _ in range(h)]
H, W, K = LI()
S = LSH(H)
ans = [[0 for i in range(W)]for j in range(H)]
count = 1
for i in range(H):
itigo = 0
ok = 0
for j in range(W):
if S[i][j] == "#":
ok = 1
if itigo == 0:
ans[i][j] = count
itigo = 1
else:
count += 1
ans[i][j] = count
else:
ans[i][j] = count
if ok == 0:
ans[i][0] = 0
else:
count += 1
ok = -1
for i in range(H):
if ans[i][0] == 0:
if ok == -1:
for k in range(i+1, H):
if ans[k][0] != 0:
ok = k
break
for x in range(W):
print(ans[ok][x], end=" ")
print()
else:
ok = i
for j in range(W):
print(ans[i][j], end=" ")
print()
| 0 | null | 71,819,140,642,260 | 20 | 277 |
import sys
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
a, b=ISI()
if a>9 or b>9:print(-1)
else:print(a*b)
| a, b = [int(n) for n in input().split()]
print(a*b if 1 <= a <= 9 and 1 <= b <= 9 else '-1') | 1 | 157,714,269,154,760 | null | 286 | 286 |
def main():
import sys
input = sys.stdin.readline
N = int(input())
S = input()
import re
num_li = [False]*1000
for i in range(10):
first_ = S.find(str(i),0,N-2)
if first_==-1:
continue
for j in range(10):
second_ = S.find(str(j),first_+1,N-1)
if second_==-1:
continue
for k in range(10):
third_ = S.find(str(k),second_+1,N)
if third_==-1:
continue
num_li[i*100+j*10+k]=True
print(sum(num_li))
if __name__=='__main__':
main() | # -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
N = int(input())
S = input()
return N, S
def main(N: int, S: str) -> None:
"""
メイン処理.
Args:\n
N (int): 桁数
S (str): ラッキーナンバー
"""
# 求解処理
ans = 0
x_bit = [False for n in range(10)]
for x in range(N):
S_x = int(S[x])
if x_bit[S_x]:
continue
x_bit[S_x] = True
y_bit = [False for n in range(10)]
for y in range(x + 1, N):
S_y = int(S[y])
if y_bit[S_y]:
continue
y_bit[S_y] = True
z_bit = [False for n in range(10)]
for z in range(y + 1, N):
S_z = int(S[z])
if z_bit[S_z]:
continue
z_bit[S_z] = True
ans += 1
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, S = get_input()
# メイン処理
main(N, S)
| 1 | 128,586,534,195,938 | null | 267 | 267 |
string = input()
n = int(input())
for _ in range(n):
query = input().split()
if query[0] == 'replace':
op, a, b, p = query
a, b = int(a), int(b)
string = string[:a] + p + string[b + 1:]
elif query[0] == 'reverse':
op, a, b = query
a, b = int(a), int(b)
string = string[:a] + ''.join(reversed(string[a:b + 1])) + string[b + 1:]
elif query[0] == 'print':
op, a, b = query
a, b = int(a), int(b)
print(string[a: b + 1]) | s=input()
for i in range(len(s)-1):
if s[i]!=s[i+1]:
print("Yes")
exit()
print("No")
| 0 | null | 28,426,880,581,412 | 68 | 201 |
import itertools
H,W,K = map(int,input().split())
S = []
for i in range(H):
s= map(int,input())
S.append(list(s))
l = list(itertools.product([0,1], repeat=H-1))
l = [list(li) for li in l]
for i in range(len(l)):
l[i] = [j+1 for j in range(len(l[i])) if l[i][j] > 0]
S_t = [list(x) for x in zip(*S)]
for i in range(W):
for j in range(1,H):
S_t[i][j] += S_t[i][j-1]
flag = False
min_cnt = H*W
for i in range(len(l)):
cnt = 0
bh = [0]+[li for li in l[i] if li > 0]+[H]
white = [0]*(len(bh)-2+1)
j = 0
while j < W:
if flag == True:
white = [0]*(len(bh)-2+1)
cnt += 1
flag = False
for k in range(len(bh)-1):
if bh[k] == 0:
su = S_t[j][bh[k+1]-1]
else:
su = S_t[j][bh[k+1]-1]-S_t[j][max(0,bh[k]-1)]
if white[k] + su > K:
if su > K:
j = W
cnt = H*W+1
flag = False
else:
flag = True
break
white[k] += su
if flag == False:
j += 1
min_cnt = min(cnt+len(bh)-2,min_cnt)
print(min_cnt)
| N,M=map(int, input().split())
if N in [0,1]:n=0
else:
n=N*(N-1)/2
if M in [0,1]:m=0
else:
m=M*(M-1)/2
print(int(n+m)) | 0 | null | 47,238,198,512,772 | 193 | 189 |
b = []
c = []
while True:
inp = input()
a = inp.split()
a[0] = int(a[0])
a[1] = int(a[1])
if a[0] == 0 and a[1] == 0:
break
else:
a.sort()
b.append(a[0])
c.append(a[1])
for i in range(len(b)):
print(b[i],c[i])
| while(1):
x,y = map(int, raw_input().split())
if x == 0 and y == 0:
break;
if x > y:
temp = x
x = y
y = temp
print x, y | 1 | 519,144,006,910 | null | 43 | 43 |
def main():
s = list(input())
for i in range(len(s)):
s[i] = "x"
L = "".join(s)
print(L)
if __name__ == "__main__":
main()
| S, T = [input() for _ in range(2)]
cnt = 0
for i, c in enumerate(S):
if c != T[i]:
cnt += 1
print(cnt) | 0 | null | 41,706,528,349,710 | 221 | 116 |
A = [0 for i in range(9)]
for i in range(3):
A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
N = int(input())
b = [0 for i in range(N)]
for i in range(N):
b[i] = int(input())
#Check matching numbers
for i in range(9):
for j in range(N):
if A[i] == b[j]:
A[i] = 0
# Check bingo or not
flag = 0
# Check rows
for i in [0, 3, 6]:
if A[i]==A[i+1] and A[i+1]==A[i+2]:
flag += 1
# Check colums
for j in range(3):
if A[j]==A[j+3] and A[j+3]==A[j+6]:
flag += 1
# Check naname?
if (A[0]==A[4] and A[4]==A[8]) or (A[2]==A[4] and A[4]==A[6]):
flag += 1
if flag >= 1:
print("Yes")
else:
print("No") | a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for i in range(3):
for j in range(3):
if a[i][j] in b:
a[i][j] = "o"
for i in range(3):
if a[i][0] == a[i][1] == a[i][2]:
print("Yes")
exit()
elif a[0][i] == a[1][i] == a[2][i]:
print("Yes")
exit()
elif a[0][0] == a[1][1] == a[2][2]:
print("Yes")
exit()
elif a[0][2] == a[1][1] == a[2][0]:
print("Yes")
exit()
elif i == 2:
print("No") | 1 | 60,122,879,767,950 | null | 207 | 207 |
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N,M,K=map(int,input().split())
uf = UnionFind(N+1)
remove = [0]*(N+1)
for i in range(M):
A,B=map(int,input().split())
uf.union(A,B)
remove[A] +=1
remove[B] +=1
for i in range(K):
A,B=map(int,input().split())
if uf.same(A,B):
remove[A] +=1
remove[B] +=1
ANS = [0]*(N+1)
for i in range(0,N+1):
ANS[i] = uf.size(i) - remove[i] - 1
ANS.pop(0)
print(*ANS)
| from collections import deque
n, m, k = map(int,input().split())
friend_sum = [[] for i in range(n)]
block = []
block_sum = [[] for i in range(n)]
for i in range(m):
a, b = map(int,input().split())
if a > b:
a, b = b, a
friend_sum[a-1].append(b-1)
friend_sum[b-1].append(a-1)
for i in range(k):
a, b = map(int,input().split())
block.append([a, b])
block_sum[a-1].append(b-1)
block_sum[b-1].append(a-1)
label = 0
g_label = [0 for i in range(n)]
g_list = [0 for i in range(n)]
for i in range(n):
if g_label[i] == 0:
label += 1
g_label[i] = label
g_list[label-1] += 1
q = deque([])
q.append(i)
while len(q) != 0:
num = q.popleft()
for j in range(len(friend_sum[num])):
if g_label[friend_sum[num][j]] == 0:
g_label[friend_sum[num][j]] = label
g_list[label-1] += 1
q.append(friend_sum[num][j])
ans = 0
for i in range(n):
ans = g_list[g_label[i]-1] - len(friend_sum[i]) - 1
for j in range(len(block_sum[i])):
if g_label[i] == g_label[block_sum[i][j]]:
ans -= 1
print(ans, end=' ')
print()
| 1 | 61,608,918,088,910 | null | 209 | 209 |
while True:
[n, m] = [int(x) for x in raw_input().split()]
if [n, m] == [0, 0]:
break
data = []
for x in range(n, 2, -1):
if 3 * x - 2 < m:
break
for y in range(x - 1, 1, -1):
for z in range(y - 1, 0, -1):
s = x + y + z
if s < m:
break
if s == m:
data.append(s)
print(len(data)) | import math
x1,y1,x2,y2=map(float,input().split())
print(round(math.sqrt((x1-x2)**2+(y1-y2)**2),7))
| 0 | null | 722,997,561,508 | 58 | 29 |
A,B,R=list(map(int,input().split()))
K=B+R
ans=B*(A//K)
S=A%K
if S<=B:
ans+=S
else:
ans+=B
print(ans) | import sys
import numpy as np
import math as mt
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n, a, b = map(int, readline().split())
ans = a * (n//(a + b))
if n%(a+b) < a:
ans += n%(a+b)
else:
ans += a
print(ans)
| 1 | 55,926,037,969,020 | null | 202 | 202 |
# Binary Indexed Tree (Fenwick Tree)
class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
self.el = [0]*(n+1)
def sum(self, i):
s = 0
while i > 0:
s += self.bit[i]
i -= i & -i
return s
def add(self, i, x):
# assert i > 0
self.el[i] += x
while i <= self.n:
self.bit[i] += x
i += i & -i
def get(self, i, j=None):
if j is None:
return self.el[i]
return self.sum(j) - self.sum(i-1)
def lower_bound(self,x):
w = i = 0
k = 1<<((self.n).bit_length())
while k:
if i+k <= self.n and w + self.bit[i+k] < x:
w += self.bit[i+k]
i += k
k >>= 1
return i+1
def alph_to_num(s):
return ord(s)-ord('a')
def solve():
N = int(input())
S = list(map(alph_to_num,list(input())))
Q = int(input())
bits = [BIT(N) for _ in range(26)]
for i in range(N):
bits[S[i]].add(i+1,1)
ans = []
for _ in range(Q):
x,y,z = input().split()
y = int(y)
if x=='1':
z = alph_to_num(z)
bits[S[y-1]].add(y,-1)
S[y-1] = z
bits[z].add(y,1)
if x=='2':
z = int(z)
ans.append(sum([bits[i].get(y,z)>0 for i in range(26)]))
return ans
print(*solve(),sep='\n') | class SegmentTree():
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
built(array) := arrayを初期値とするセグメント木を構築する O(N)。
update(i, val) := i番目の要素をvalに変更する。
get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
"""
def __init__(self, n, op, e):
"""要素数、二項演算、単位元を引数として渡す
例) 区間最小値 SegmentTree(n, min, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def build(self, array):
"""arrayを初期値とするセグメント木を構築する"""
for i in range(self.n):
self.node[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def update(self, i, val):
"""i番目の要素をvalに変更する"""
i += self.size
self.node[i] = val
while i > 1:
i >>= 1
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res_l, res_r = self.e, self.e
while l < r:
if l & 1:
res_l = self.op(res_l, self.node[l])
l += 1
if r & 1:
r -= 1
res_r = self.op(self.node[r], res_r)
l, r = l >> 1, r >> 1
return self.op(res_l, res_r)
ALPH = "abcdefghijklmnopqrstuvwxyz"
to_int = {char: i for i, char in enumerate(ALPH)}
n = int(input())
s = input()
q = int(input())
query = [list(input().split()) for i in range(q)]
init = [0] * n
for i, char in enumerate(s):
init[i] = 1 << to_int[char]
op = lambda a, b: a | b
st = SegmentTree(n, op, 0)
st.build(init)
for i in range(q):
if query[i][0] == "1":
_, ind, char = query[i]
ind = int(ind) - 1
st.update(ind, 1 << to_int[char])
else:
_, l, r = query[i]
l, r = int(l) - 1, int(r)
print(bin(st.get_val(l, r)).count("1"))
| 1 | 62,610,187,872,930 | null | 210 | 210 |
n,k=map(int,input().split())
mod=10**9+7
ans=0
A=[0]*k
for i in range(k,0,-1):
a=0
A[i-1]=pow((k//i),n,mod)
m=i*2
while m<=k:
A[i-1]=(A[i-1]-A[m-1])%mod
m=m+i
ans=(ans+i*A[i-1])%mod
print(ans%mod) | rate = int(input())
print(10 - rate//200) | 0 | null | 21,613,382,889,840 | 176 | 100 |
a,b=map(int,input().split())
a1=a/0.08
a2=(a+1)/0.08
b1=b/0.1
b2=(b+1)/0.1
ans=20000
for i in range(1,10001):
if a1<=i and b1<=i and a2>i and b2>i:
ans=min(ans,i)
if ans==20000:
print(-1)
else:
print(ans) | A, B = [int(n) for n in input().split(" ")]
XstartA = A / 0.08
XendA = (A + 1) / 0.08
XstartB = B / 0.1
XendB = (B + 1) / 0.1
start = XstartA
if XstartA < XstartB:
start = XstartB
end = XendA
if XendB < XendA:
end = XendB
S = int(start)
E = int(end) + 1
ans = -1
for i in range(S, E + 1):
if start <= i and i < end:
ans = i
break
print(ans) | 1 | 56,441,603,780,628 | null | 203 | 203 |
n, k = map(int, input().split())
if n > k:
n %= k
print(min(k-n, n)) | S = input()
print(S + 's') if S[-1] != 's' else print(S + 'es') | 0 | null | 20,778,593,956,512 | 180 | 71 |
n=int(input())
if n%2:
print(0)
else:
c=0
n//=2
while n:
n//=5
c+=n
print(c) | def main():
x, k, d = map(int,input().split())
abs_x = abs(x)
times = abs_x // d
if(times > k):
print(abs_x - k * d)
else:
if((k - times) % 2 == 0):
print(abs_x - times * d)
else:
print(abs(abs_x - (times + 1) * d))
if __name__ == '__main__':
main() | 0 | null | 60,644,397,162,918 | 258 | 92 |
N = int(input())
ans = set()
def check(N, k):
if k<2:
return False
N //= k
while N:
if (N-1)%k==0:
return True
if N%k:
return False
N //= k
for k in range(1, int(N**0.5)+1):
if (N-1)%k==0:
ans.add(k)
ans.add((N-1)//k)
if N%k==0:
if check(N, k):
ans.add(k)
if check(N, N//k):
ans.add(N//k)
ans.remove(1)
print(len(ans)) | import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
from math import sqrt
def factor(n):
"""
nの約数を個数と共にリストにして返す。
ただしあとの都合上1は除外する。
"""
if n == 1:
return 0, []
if n == 2:
return 1, [2]
if n == 3:
return 1, [3]
d = int(sqrt(n))
num = 1
factor_pre = []
factor_post = [n]
for i in range(2, d):
if n % i == 0:
factor_pre.append(i)
factor_post.append(n // i)
num += 2
if d * d == n:
factor_pre.append(d)
num += 1
elif n % d == 0:
factor_pre.append(d)
factor_post.append(n // d)
num += 2
factor_post.reverse()
return num, factor_pre + factor_post
def main():
N = int(input())
"""
題を満たすKは、
N = K^e * n、(n, K) = 1
として
n = K * m + 1 (m ¥in ¥mathbb{N})
とかければ良い。
2つ目の式からnとKが互いに素なのは明らかなので、問題文は
N = K^e * (K * m + 1) (m ¥in ¥mathbb{N})
なるKを求めることに同値。
なのでまずはNの約数を全列挙して、あとはNをそれで割った商がKで割って1余るか確かめれば良い。
"""
_, fact = factor(N)
ans, ans_list = factor(N - 1)
# print(ans_list)
# print("Now we check the list {}".format(fact))
for K in fact:
n = N
while n % K == 0:
n //= K
if n % K == 1:
ans += 1
ans_list.append(K)
# print("{} added".format(K))
# print("ans={}: {}".format(ans, ans_list))
print(ans)
if __name__ == "__main__":
main()
| 1 | 41,087,659,072,888 | null | 183 | 183 |
n = int(input())
M = int(n**(0.5))
ans = [0]*(n+1)
for x in range(1,M+1):
for y in range(1,10**2):
for z in range(1,10**2):
if x**2+y**2+z**2+x*y+y*z+z*x > n:
break
ans[x**2+y**2+z**2+x*y+y*z+z*x] += 1
if x**2+y**2 > n:
break
for i in range(n):
print(ans[i+1]) | from collections import defaultdict
n=int(input())
MAX=10000
d = defaultdict(int)
def col(x,y,z):
if x == y and x == z :
return 1
if x == y or y == z or z == x :
return 3
return 6
# x <= y <= z
for i in range(1,MAX):
wkx = i**2
if wkx > MAX:
break
for j in range(i,MAX):
wky = wkx + j**2 + i * j
if wky > MAX :
break
for k in range(j,MAX):
wkz = wky + k**2 + i * k + j * k
if wkz > MAX :
break
d[wkz] = d[wkz] + col(i,j,k)
for i in range(n):
k = i + 1
print(d[k])
| 1 | 7,912,618,398,528 | null | 106 | 106 |
n,k = map(int,input().split())
a = list(map(int,input().split()))
ML = 50
r = min(ML,k)
for l in range(r):
imos = [0]*(n+1)
for i in range(n):
left = max(0,i-a[i])
right = min(n,i+a[i]+1)
imos[left] += 1
imos[right] -= 1
c = 0
for i in range(n):
c += imos[i]
a[i] = c
print(*a) | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [0] * (N + 1)
for k in range(K):
sta = [max(i-A[i], 0) for i in range(N)]
end = [min(i+A[i]+1, N) for i in range(N)]
for s in sta:
dp[s] += 1
for e in end:
dp[e] -= 1
for i in range(1, len(dp)-1):
dp[i] += dp[i-1]
B = dp[:-1]
if A == B:
break
A = B
dp = [0] * (N + 1)
print(' '.join(map(str, A))) | 1 | 15,372,420,133,180 | null | 132 | 132 |
import sys
import bisect
from math import ceil
from itertools import accumulate
n, d, a = [int(i) for i in sys.stdin.readline().split()]
monsters = []
max_x = 0
for i in range(n):
x, h = [int(i) for i in sys.stdin.readline().split()]
max_x = max(x, max_x)
monsters.append([x, h])
monsters.sort(key=lambda x:x[0])
x, h = zip(*monsters)
x_ls = []
for i, (_x, _h) in enumerate(zip(x, h)):
ind = bisect.bisect_right(x, _x + 2 * d)
x_ls.append([i, ind, _h])
h = list(h) + [0]
ls = [0 for i in range(n+1)]
cur = 0
res = 0
for i, ind, _h in x_ls:
if h[i] > 0:
cur -= ls[i]
h[i] -= cur
if h[i] > 0:
hoge = ceil(h[i] / a)
res += hoge
cur += hoge * a
ls[ind] += hoge * a
print(res)
| N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ans = 0
commands = [''] * N
for i, t in enumerate(T):
if t == 'r':
command = 'p'
point = P
elif t == 's':
command = 'r'
point = R
elif t == 'p':
command = 's'
point = S
if (i - K >= 0) and (commands[i - K] == command):
command = ''
point = 0
ans += point
commands[i] = command
print(ans) | 0 | null | 94,660,576,970,608 | 230 | 251 |
import sys
input = sys.stdin.readline
h, w, m = map(int,input().split())
row = [0]*h
col = [0]*w
enemy = []
for i in range(m):
hh, ww = map(lambda x:int(x)-1,input().split())
row[hh] += 1
col[ww] += 1
enemy.append((hh,ww))
enemy = set(enemy)
rmax = max(row)
cmax = max(col)
on_r = row.count(rmax)
on_c = col.count(cmax)
on = 0
for hh, ww in enemy:
if row[hh] == rmax and col[ww] == cmax:
on += 1
if on == on_r*on_c:
print(rmax+cmax-1)
else:
print(rmax+cmax) | import math
def factrization_prime(number):
factor = {}
div = 2
s = math.sqrt(number)
while div < s:
div_cnt = 0
while number % div == 0:
div_cnt += 1
number //= div
if div_cnt != 0:
factor[div] = div_cnt
div += 1
if number > 1:
factor[number] = 1
return factor
N = int(input())
v = list(factrization_prime(N).values())
ans = 0
for i in range(len(v)):
k = 1
while(True):
if v[i] >= k:
v[i] -= k
k += 1
ans += 1
else:
break
print(ans)
| 0 | null | 10,769,525,694,876 | 89 | 136 |
n = int(input())
added_strings = set()
for i in range(n):
com, s = input().split()
if com == 'insert':
added_strings.add(s)
elif com == 'find':
print('yes' if (s in added_strings) else 'no')
| import sys
d={}
input()
for e in sys.stdin:
c,g=e.split()
if'i'==c[0]:d[g]=0
else:print(['no','yes'][g in d])
| 1 | 78,503,640,608 | null | 23 | 23 |
N = int(input())
K = []
for i in range(N):
X,L = map(int,input().split())
K.append([X-L,X+L])
T = sorted(K,key=lambda x:x[1])
a = T[0][1]
c = 1
for i in range(1,N):
if T[i][0] >= a:
c += 1
a = T[i][1]
print(c) | N=int(input())
arms=[list(map(int,input().split())) for _ in range(N)]
points=[]
for i in range(N):
points.append([arms[i][0]-arms[i][1],arms[i][0]+arms[i][1]])
#print(points)
points.sort(key=lambda x:x[1])
#print(points)
nowr=-float("inf")
cnt=0
for i in points:
l,r=i
if nowr<=l:
nowr=r
cnt=cnt+1
print(cnt)
| 1 | 89,985,635,482,148 | null | 237 | 237 |
S = input()
f = S[0]
if S.count(f) == 3 :
print('No')
else :
print('Yes') | s = input()
n = len(s)
sa = 'A'*n
sb = 'B'*n
if s != sa and s != sb:
print('Yes')
else:
print('No')
| 1 | 54,677,819,358,500 | null | 201 | 201 |
n , k = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse = True)
for i in range(n):
if h[i] < k:
print(i)
break
else:
print(n)
| import collections
N=int(input())
S=sorted([input() for _ in range(N)])
s=sorted(list(set(S)))
l=len(s)
c=collections.Counter(S)
max_v = max(c.values())
for i in range(l):
if max_v==c[s[i]]:
print(s[i]) | 0 | null | 124,466,255,697,456 | 298 | 218 |
print(2*3.14159*int(input())) | N, M = map(int, input().split())
H = [int(x) for x in input().split()]
good = [1]*N
for k in range(M):
A, B = map(int, input().split())
if H[A - 1] >= H[B - 1]:
good[B - 1] = 0
if H[A - 1] <= H[B - 1]:
good[A - 1] = 0
print(sum(good))
| 0 | null | 28,209,217,259,652 | 167 | 155 |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def main():
N = INT()
A = LI()
RGB = [0,0,0]
answer = 1
MOD = 10**9+7
for i in range(N):
if RGB.count(A[i]) == 0:
print(0)
return
answer *= RGB.count(A[i])
answer %= MOD
for j in range(3):
if RGB[j] == A[i]:
RGB[j] += 1
break
print(answer)
return
if __name__ == '__main__':
main()
| N=int(input())
A=list(map(int,input().split()))
a,b,c=0,0,0
ans=1
mod=10**9+7
for i in A:
ans=ans*[a,b,c].count(i)%mod
if i==a: a+=1
elif i==b: b+=1
elif i==c: c+=1
print(ans) | 1 | 130,294,204,692,900 | null | 268 | 268 |
n=int(input())
print(n*(1+n*(1+n))) | n = int(raw_input())
dp = {}
def fib(n):
if n in dp: return dp[n]
if n == 0:
dp[n] = 1
return 1
elif n == 1:
dp[n] = 1
return 1
else:
dp[n] = fib(n-1)+fib(n-2)
return dp[n]
print fib(n) | 0 | null | 5,164,299,821,918 | 115 | 7 |
a1, a2, a3 = (map(int, input().split()))
if sum([a1, a2, a3]) >= 22:
print('bust')
else:
print('win')
| #!/usr/bin/env python3
print("bwuisnt"[eval(input().replace(" ", "+")) < 22::2])
| 1 | 119,067,710,021,732 | null | 260 | 260 |
def divisors(N):
U = int(N ** 0.5) + 1
L = [i for i in range(1, U) if N % i == 0]
return L + [N // i for i in reversed(L) if N != i * i]
def solve(k):
n = N
while n % k == 0:
n //= k
return (n % k == 1)
N = int(input())
K = set(divisors(N) + divisors(N - 1)) - {1}
print(sum(solve(k) for k in K)) | import math
N = int(input())
def enumerate_divisors(N):
all_divisors = set()
for divisor in range(1, int(math.sqrt(N)) + 1):
if N%divisor == 0:
if divisor == 1:
all_divisors.add(N/divisor)
else:
all_divisors = all_divisors | {divisor, N/divisor}
all_divisors = list(all_divisors)
return all_divisors
def calculate_reminder(N, d):
while True:
reminder = N%d
if reminder == 0:
N /= d
else:
return reminder
if N == 2:
counter = 1
else:
counter = len(enumerate_divisors(N-1))
for div in enumerate_divisors(N):
if calculate_reminder(N, div) == 1:
counter += 1
print(counter) | 1 | 41,356,269,425,480 | null | 183 | 183 |
n=int(input())
cnt=0
if n %2==0:
print(n//2 -1)
else:print(n//2) | a=int(input())
print(int((a-1)/2)) | 1 | 152,817,177,201,920 | null | 283 | 283 |
n = int(input())
x = list(input())
count = x.count('1')
one_count = count - 1
zero_count = count + 1
one_mod = 0
zero_mod = 0
for b in x:
if one_count:
one_mod = (one_mod * 2 + int(b)) % one_count
zero_mod = (zero_mod * 2 + int(b)) % zero_count
f = [0] * 2000001
pop_count = [0] * 200001
for i in range(1, 200001):
pop_count[i] = pop_count[i//2] + i % 2
f[i] = f[i % pop_count[i]] + 1
for i in range(n):
if x[i] == '1':
if one_count:
nxt = one_mod
nxt -= pow(2, n-i-1, one_count)
nxt %= one_count
print(f[nxt] + 1)
else:
print(0)
if x[i] == '0':
nxt = zero_mod
nxt += pow(2, n-i-1, zero_count)
nxt %= zero_count
print(f[nxt] + 1)
| def pcmod(n):
if n==0:
return 1
return 1+pcmod(n%bin(n).count('1'))
def main():
n = int(input())
x = list(map(int,list(input())))
m_1 = x.count(1)-1
m_0 = x.count(1)+1
baser_1 = 0
baser_0 = 0
if m_1!=0:
for i in range(n):
baser_1 += x[i] * pow(2,(n-1-i),m_1)
baser_1 %= m_1
for i in range(n):
baser_0 += x[i] * pow(2,(n-1-i),m_0)
baser_0 %= m_0
ans = [0]*n
for i in range(n):
a = 0
if x[i]==1:
if m_1==0:
ans[i] = 0
continue
t = (baser_1 - pow(2,(n-1-i),m_1))%m_1
a = pcmod(t)
if x[i]==0:
t = (baser_0 + pow(2,(n-1-i),m_0))%m_0
a = pcmod(t)
ans[i] = a
for a in ans:
print(a)
if __name__ == "__main__":
main() | 1 | 8,190,713,808,390 | null | 107 | 107 |
n,m = map(int,raw_input().split())
a = [[0 for i in range (m)]for j in range(n)]
b = [0 for i in range(m)]
c = [0 for i in range(n)]
for i in range(n):
x = map(int,raw_input().split())
for j in range(m):
a[i][j] = x[j]
for i in range(m):
b[i] = int(raw_input())
for i in range(n):
for j in range(m):
c[i] += a[i][j] * b[j]
print c[i] |
H, W = map(int, input().split())
if H == 1 or W == 1:
print(1)
elif H % 2 == 0:
print(H*W//2)
else:
if W % 2 == 0:
print(H*W//2)
else:
print((H//2)*(W//2) + (H//2+1)*(W//2+1)) | 0 | null | 26,139,188,747,618 | 56 | 196 |
def solve(x):
return sum([int(i) for i in str(x)])
if __name__ == '__main__':
while True:
x = int(input())
if x == 0: break
print(solve(x)) | n = int(input())
def dfs(n, s, idx):
l = len(s)
if n == l:
print(s)
return
alpha = "abcdefghijklmnopqrstuvwxyz"
i = 0
while i < idx + 1:
if i == idx:
dfs(n, s + alpha[i], idx + 1)
else:
dfs(n, s + alpha[i], idx)
i += 1
dfs(n, "", 0)
| 0 | null | 26,925,298,442,430 | 62 | 198 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
C = Counter(A)
tmp = 0
for x in C.values():
tmp += x*(x-1)//2
for x in A:
print(tmp - (C[x]-1)) | import collections
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
#全体の数列について答えを求めるnC2=n(n-1)/2
ALL=0
for i in c.values():
if i>1:
ALL += i*(i-1)//2
#各要素が影響する分を求める
for i in A:
if c[i]>2:
print(ALL-c[i]+1)
elif c[i]==2:
print(ALL-1)
else:
print(ALL) | 1 | 47,696,825,920,352 | null | 192 | 192 |
S = input()
N = len(S)
ans = 0
for i in range(N//2):
if S[i] != S[N-i-1]: ans += 1
print(ans) | def counter(a, b, c):
count = 0
for n in range(a, b+1):
if c % n == 0:
count += 1
print(count)
a, b, c = list(map(int, input().split()))
counter(a, b, c) | 0 | null | 60,159,342,580,220 | 261 | 44 |
A = str(input())
print(A[0:3])
| string = input()
if string == 'AAA' or string == 'BBB':
print('No')
else:
print('Yes') | 0 | null | 34,682,711,632,192 | 130 | 201 |
mod = 1000000007
n,k = map(int, input().split())
d = [0]*(k+1)
for i in range(1,k+1):
d[i] = pow(k//i,n,mod)
for i in range(k,0,-1):
for j in range(2*i,k+1,i):
d[i] -= d[j]
d[i] %= mod
ans = 0
for i in range(1,k+1):
ans += d[i]*i
ans %= mod
print(ans) | N=int(input())
A=list(map(int,input().split()))
import itertools
ACU=itertools.accumulate(A)
B=list(ACU)
MAX=B[-1]
tmp=10**10
for i in B:
tmp=min(tmp,abs(2*i-MAX))
print(tmp) | 0 | null | 89,367,173,332,388 | 176 | 276 |
N = int(input())
if N%2 == 1 :
print(0)
exit()
n = 0
i = 0
for i in range(1,26) :
n += N//((5**i)*2)
print(n) | import sys
input = sys.stdin.readline
def main():
N = int(input())
if N % 2 == 1:
print(0)
exit()
count = []
i = 0
while True:
q = N // (10 * 5 ** i)
if q == 0:
break
else:
count.append((q, i + 1))
i += 1
ans = 0
prev_c = 0
for c, n_zero in count[::-1]:
ans += n_zero * (c - prev_c)
prev_c = c
print(ans)
if __name__ == "__main__":
main()
| 1 | 116,106,427,058,440 | null | 258 | 258 |
#A
N=input()
hon=["2","4","5","7","9"]
pon=["0","1","6","8"]
if N[-1] in hon:
print('hon')
elif N[-1] in pon:
print('pon')
else:
print('bon') | n = input()
c = n[-1]
if c in "24579":
print("hon")
elif c in "0168":
print("pon")
else:
print("bon") | 1 | 19,358,586,172,870 | null | 142 | 142 |
a = int(input())
sum = a + a*a +a*a*a
print(sum) | n,m,l=map(int,input().split())
e=[list(map(int,input().split()))for _ in[0]*(n+m)]
for c in e[:n]:print(*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])])
| 0 | null | 5,871,979,792,448 | 115 | 60 |
import os, sys, re, math
A = [int(n) for n in input().split()]
print('win' if sum(A) <= 21 else 'bust')
| A,B,C = list(map(int,input().split()))
if A+B+C <= 21:
print("win")
else:
print("bust")
| 1 | 118,610,770,422,690 | null | 260 | 260 |
s=int(raw_input())
print str(s//3600)+':'+str(s//60%60)+':'+str(s%60) | s = input()
h = s/3600
m = s%3600/60
s = s%3600%60
print '{0}:{1}:{2}'.format(h, m, s) | 1 | 328,754,006,770 | null | 37 | 37 |
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n=int(input())
ar=lis()
data=[]
for i in range(n):
data.append((ar[i],i))
data.sort(reverse=True)
dp = [[0] * (n+1) for _ in range(n+1)]
for i in range(n):
a, p = data[i]
for j in range(i+1):
dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(n-1-j-p)*a)
dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a)
#print(dp)
print(max(dp[-1]))
| N = int(input())
A = sorted([(int(a), i) for i, a in enumerate(input().split())], key = lambda x: x[0])[::-1]
X = [0] + [-1<<100] * (N + 5)
for k, (a, i) in enumerate(A):
X = [max(X[j] + abs(N - (k - j) - 1 - i) * a, X[j-1] + abs(j - 1- i) * a if j else 0) for j in range(N + 5)]
print(max(X)) | 1 | 33,730,125,607,682 | null | 171 | 171 |
import sys
def solve():
a = [int(input()) for i in range(10)]
a.sort(reverse=True)
print(*a[:3], sep='\n')
if __name__ == '__main__':
solve() | from sys import stdin
for x in sorted([int(l) for l in stdin],reverse=True)[0:3]:
print(x) | 1 | 15,222,682 | null | 2 | 2 |
n=int(input())
l=list(map(int,input().split()))
c=1
s=0
for i in l:
if(i==c):
c+=1
else:
s+=1
if(s==n):
print(-1)
else:
print(s) | n,m = list(map(int, input().split()))
parents = [-1] * (n + 1)
def find(x):
if parents[x] < 0:
return x
else:
parents[x] = find(parents[x])
return parents[x]
def union(x, y):
x = find(x)
y = find(y)
if x == y:
return
if parents[x] > parents[y]:
x, y = y, x
parents[x] += parents[y]
parents[y] = x
def same(x, y):
return find(x) == find(y)
for _ in range(m):
a,b = list(map(int, input().split()))
union(a,b)
print(-min(parents[1:])) | 0 | null | 59,264,918,815,578 | 257 | 84 |
def q1():
S, T = input().split()
print('{}{}'.format(T, S))
if __name__ == '__main__':
q1()
| class SegmentTree():
"""一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
built(array) := arrayを初期値とするセグメント木を構築する O(N)。
update(i, val) := i番目の要素をvalに変更する。
get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
"""
def __init__(self, n, op, e):
"""要素数、二項演算、単位元を引数として渡す
例) 区間最小値 SegmentTree(n, min, 10 ** 18)
区間和 SegmentTree(n, lambda a, b : a + b, 0)
"""
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def build(self, array):
"""arrayを初期値とするセグメント木を構築する"""
for i in range(self.n):
self.node[self.size + i] = array[i]
for i in range(self.size - 1, 0, -1):
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def update(self, i, val):
"""i番目の要素をvalに変更する"""
i += self.size
self.node[i] = val
while i > 1:
i >>= 1
self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])
def get_val(self, l, r):
"""[l, r)の畳み込みの結果を返す"""
l, r = l + self.size, r + self.size
res_l, res_r = self.e, self.e
while l < r:
if l & 1:
res_l = self.op(res_l, self.node[l])
l += 1
if r & 1:
r -= 1
res_r = self.op(self.node[r], res_r)
l, r = l >> 1, r >> 1
return self.op(res_l, res_r)
ALPH = "abcdefghijklmnopqrstuvwxyz"
to_int = {char: i for i, char in enumerate(ALPH)}
n = int(input())
s = input()
q = int(input())
query = [list(input().split()) for i in range(q)]
init = [0] * n
for i, char in enumerate(s):
init[i] = 1 << to_int[char]
op = lambda a, b: a | b
st = SegmentTree(n, op, 0)
st.build(init)
for i in range(q):
if query[i][0] == "1":
_, ind, char = query[i]
ind = int(ind) - 1
st.update(ind, 1 << to_int[char])
else:
_, l, r = query[i]
l, r = int(l) - 1, int(r)
print(bin(st.get_val(l, r)).count("1"))
| 0 | null | 82,989,356,232,388 | 248 | 210 |
N, K = map(int, input().split())
MOD = 10**9 + 7
ans = 0
A = [0 for _ in range(K+1)]
for i in range(1,K+1):
ans += pow(K//i, N, MOD) * (i - A[i])
ans %= MOD
#print(ans, i)
j = 2*i
while j <= K:
A[j] += i - A[i]
j += i
print(ans) | MODINT = 10**9+7
n, k = map(int, input().split())
ans = 0
"""
dp[i] = gdc がi となる場合のgcdの総和
"""
dp = [0] * (k+100)
for i in range(k, 0, -1):
dp[i] = pow(k//i, n, MODINT)
for j in range(i*2, k+1, i):
dp[i] -= dp[j]
ans += (dp[i]*i)%MODINT
print(ans%MODINT) | 1 | 36,597,132,376,630 | null | 176 | 176 |
import collections
n = int(input())
s_ls = []
dic = collections.defaultdict(int)
for i in range(n):
[s,t] = [j for j in input().split()]
s_ls.append(s)
dic[s] = int(t)
x = input()
f = 0
ans = 0
for i in range(n):
if f:
ans += dic[s_ls[i]]
if x == s_ls[i]:
f = 1
print(ans)
| n = int(input())
playList = []
sumTerm = 0
for i in range(n) :
song = input().split()
song[1] = int(song[1])
playList.append(song)
sumTerm += song[1]
x = input()
tmpSumTerm = 0
for i in range(n) :
tmpSumTerm += playList[i][1]
if playList[i][0] == x :
print(sumTerm - tmpSumTerm)
break
| 1 | 97,226,386,363,776 | null | 243 | 243 |
import fractions
N,M=map(int,input().split())
a=list(map(int,input().split()))
l=1
count=0
A=a[0]
ans=0
flag=1
while A%2==0:
A=A//2
count=count+1
for i in range(N):
A=a[i]
b=A//(2**count)
if b==0 or b%2==0:
flag=0
break
A=A//2
l=l*A//fractions.gcd(l,A)
if flag==1:
ans=M//l
if ans%2==0:
print(ans//2)
else:
print(ans//2+1)
else:
print(0) | n,k=map(int,(input().split()))
ans=0
max=sum(range(n-k+1,n+1))*(n-k+2)
min=sum(range(k))*(n-k+2)
for i in range(1,n-k+2):
min+=(k-1+i)*(n-k+2-i)
for i in range(1,n-k+2):
max+=(n-k+1-i)*(n-k+2-i)
ans=(max-min+n-k+2)%(10**9+7)
print(ans) | 0 | null | 67,550,065,179,170 | 247 | 170 |
def main():
s = list(map(int,input().strip().split()))
tmp = s[0]
s[0] = s[1]
s[1] = tmp
tmp = s[0]
s[0] = s[2]
s[2] = tmp
print("{} {} {} ".format(s[0],s[1],s[2]))
main()
| import math
import sys
readline = sys.stdin.readline
def main():
a, b, c = map(int, readline().rstrip().split())
print(c, a, b)
if __name__ == '__main__':
main()
| 1 | 38,199,103,410,800 | null | 178 | 178 |
# 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 math
r = float(input())
area = math.pi*r**2
circuit = 2*math.pi*r
print"%f %f" % (area, circuit) | 1 | 637,793,161,600 | null | 46 | 46 |
import math
a = 100
for _ in [0]*int(input()):
a = math.ceil(a * 1.05)
print (a*1000)
| n = int(input())
debt = 100000
for i in range(n):
debt *= 1.05
if debt%1000 != 0:
debt += 1000 - debt%1000
print(int(debt)) | 1 | 1,267,175,770 | null | 6 | 6 |
from math import *
a, b, x = map(int, input().split())
areatotal = a*a*b
if areatotal / 2 == x: print(45.0)
elif x > areatotal/2:
left = 0.0
right = 90.0
while right-left > 0.00000001:
current = (right+left)/2
if a**2 * tan(radians(current)) / 2 * a < (areatotal - x):
left = current
else:
right = current
print(left)
else:
left = 0.0
right = 90.0
while right-left > 0.00000001:
current = (right+left)/2
if b**2 * tan(radians(90-current))/2*a > x:
left = current
else:
right = current
print(left)
| def divisor(i):
s = []
for j in range(1, int(i ** (1 / 2)) + 1):
if i % j == 0:
s.append(i // j)
s.append(j)
return sorted(set(s))
n = int(input())
ans = 0
d = divisor(n)
d.pop(0)
for i in d:
x = n
while True:
if not x % i == 0:
break
x //= i
if x % i == 1:
ans += 1
d = divisor(n - 1)
ans += len(d)
ans -= 1
print(ans) | 0 | null | 102,137,805,892,032 | 289 | 183 |
H, W, K = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]
L = []
u = 0
M = []
for i in range(H):
s = 0
for j in range(W):
if S[i][j] == '#':
s += 1
u += 1
C[i][j] = u
if s == 0:
L.append(i)
else:
M.append(i)
d = 0
for i in range(len(M)):
for j in range(W):
if C[M[i]][j] != 0:
for k in range(d, j):
C[M[i]][k] = C[M[i]][j]
d = j + 1
for k in range(d, W):
C[M[i]][k] = C[M[i]][d-1]
d = 0
ma, mi = max(M), min(M)
M.insert(0, -1)
for i in range(W):
for j in range(len(M)-1):
for k in range(M[j]+1, M[j+1]):
C[k][i] = C[M[j+1]][i]
for j in range(ma+1, H):
C[j][i] = C[ma][i]
for i in range(H):
for j in range(W):
if j != W-1:
print(C[i][j], end = ' ')
else:
print(C[i][j], end = '')
print() | x = int(input())
n = 10 * x
primes = [True] * n
for i in range(2, n):
if primes[i]:
for j in range(i * i, n, i):
primes[j] = False
for i in range(x, n):
if primes[i]:
print(i)
exit()
| 0 | null | 124,956,122,666,040 | 277 | 250 |
# -*- coding: utf-8 -*-
"""
D - Knight
https://atcoder.jp/contests/abc145/tasks/abc145_d
"""
import sys
def modinv(a, m):
b, u, v = m, 1, 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= m
return u if u >= 0 else u + m
def solve(X, Y):
MOD = 10**9 + 7
if (X + Y) % 3:
return 0
n = (X - 2 * Y) / -3.0
m = (Y - 2 * X) / -3.0
if not n.is_integer() or not m.is_integer() or n < 0 or m < 0:
return 0
n, m = int(n), int(m)
x1 = 1
for i in range(2, n + m + 1):
x1 = (x1 * i) % MOD
x2 = 1
for i in range(2, n+1):
x2 = (x2 * i) % MOD
for i in range(2, m+1):
x2 = (x2 * i) % MOD
ans = (x1 * modinv(x2, MOD)) % MOD
return ans
def main(args):
X, Y = map(int, input().split())
ans = solve(X, Y)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| while True:
H, W = [int(x) for x in input().split() if x.isdigit()]
if H ==0 and W == 0:
break
else:
for i in range(H):
for j in range(W-1):
print("#", end='')
print("#")
print("") | 0 | null | 75,353,843,409,768 | 281 | 49 |
def main():
input_name = input()
print(input_name[0:3])
if __name__=='__main__':
main()
| s = list(input())
nick = s[0]+s[1]+s[2]
print(nick) | 1 | 14,836,747,247,388 | null | 130 | 130 |
N = input()
a = [input() for i in range(N)]
def smax(N,a):
smin = a[0]
smax = -10**9
for j in range(1,N):
smax = max(smax,a[j]-smin)
smin = min(smin,a[j])
return smax
print smax(N,a) | n = int(input())
minv = int(input())
maxv = -2*10**9
for i in range(n-1):
r = int(input())
maxv = max(maxv,r-minv)
minv = min(minv,r)
print(maxv) | 1 | 11,959,608,540 | null | 13 | 13 |
s=input().lower()
cnt=0
while True:
l=input().split()
if l[0]=='END_OF_TEXT': break
for i in range(len(l)):
lg=len(l[i])-1
if not l[i][lg].isalpha(): l[i]=l[i][:lg]
cnt+=(s==l[i].lower())
print(cnt) | from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction
# 10進数表記でnのk進数を求めてlength分0埋め
def ternary (n, k, length):
if n == 0:
nums = ['0' for i in range(length)]
nums = ''.join(nums)
return nums
nums = ''
while n:
n, r = divmod(n, k)
nums += str(r)
nums = nums[::-1]
nums = nums.zfill(length)
return nums
def main():
num = int(input())
data = list(map(int, input().split()))
mod = 10 ** 9 + 7
max_length = len(bin(max(data))) - 2
bit_count = [0 for i in range(max_length)]
for i in range(num):
now_bin = bin(data[i])[2:]
now_bin = now_bin.zfill(max_length)
for j in range(max_length):
if now_bin[j] == "1":
bit_count[j] += 1
flg_data = [0 for i in range(max_length)]
for i in range(max_length):
flg_data[i] += bit_count[i] * (num - bit_count[i])
ans = 0
for j in range(max_length):
pow_num = max_length - 1 - j
bbb = pow(2, pow_num, mod)
ans += bbb * flg_data[j]
ans %= mod
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 62,219,857,908,220 | 65 | 263 |
import copy
H, W, K = list(map(int, input().split()))
c = [0]*H
for i in range(H):
char = input()
c[i] = []
for j in range(W):
if char[j] == "#":
c[i].append(1)
else:
c[i].append(0)
count = 0
for i in range(2**H):
for j in range(2**W):
d = copy.deepcopy(c)
i2 = i
j2 = j
for k in range(H):
if i2 & 1:
d[k] = [0]*W
i2 >>= 1
for l in range(W):
if j2 & 1:
for m in range(H):
d[m][l] = 0
j2 >>= 1
s = sum(map(sum, d))
if s == K:
count += 1
print(count) | def main():
A,B,C = map(int,input().split())
K = int(input())
num = 0
while (B <= A):
num += 1
if num <= K:
B *= 2
else:
return ("No")
while (C <= B):
num += 1
if num <= K:
C *= 2
else:
return ('No')
return('Yes')
print(main())
| 0 | null | 7,893,778,779,766 | 110 | 101 |
import sys
import math
import fractions
from collections import defaultdict
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
S=ns().split()
print(S[1]+S[0]) | s,t = map(str,input().split())
ts = [t,s]
print("".join(ts))
| 1 | 102,924,662,455,448 | null | 248 | 248 |
x = int(input())
a, r = x // 500, x % 500
b = r // 5
print(1000 * a + 5 * b)
| # Golden Coins
X = int(input())
ans = (X // 500) * 1000
X = X % 500
ans += (X // 5) * 5
print(ans)
| 1 | 42,745,672,859,022 | null | 185 | 185 |
def GCD_cal(a,b):
if(b==0):
return(a)
a,b=b,a%b
return(GCD_cal(a,b))
while(True):
try:
a,b=map(int,input().split(" "))
except:
break
if(a<b):
a,b=b,a
GCD=GCD_cal(a,b)
LCM=int(a*b/GCD)
print("{0} {1}".format(GCD,LCM)) | import sys
def gcd(x, y):
if x % y != 0:
return gcd(y, x % y)
return y
for i in sys.stdin:
x, y = map(int, i.split())
g = gcd(x,y)
print(g, int(x*y/g)) | 1 | 627,847,128 | null | 5 | 5 |
# ABC162
# FizzBuzz Sum
n = int(input())
ct = 0
for i in range(n + 1):
if i % 3 != 0:
if i % 5 != 0:
ct += i
else:
continue
print(ct) | ans=0
N=int(input())
for x in range(1,N+1):
if x%3==0 or x%5==0:
pass
else:
ans += x
print(ans) | 1 | 34,941,535,905,952 | null | 173 | 173 |
S,T = input().split()
T+=S
print(T) | n,m = map(int,input().split())
a = [int(s) for s in input().split()]
daycount = 0
for i in range(m):
daycount += a[i]
if n - daycount >= 0:
print(n - daycount)
else:
print(-1) | 0 | null | 67,243,172,185,838 | 248 | 168 |
n = int(input())
fib = []
ans = 0
for i in range(n+1):
if i == 0 or i == 1:
ans = 1
fib.append(ans)
else:
ans = fib[i-1] + fib[i-2]
fib.append(ans)
print(ans)
| while True:
s = input()
if len(s) == 1 and s[0] == '0': break
total = 0
for i in range(0,len(s)):
total += int(s[i])
print("%d" % total) | 0 | null | 796,323,301,304 | 7 | 62 |
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from functools import reduce, lru_cache
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy
sys.setrecursionlimit(1000000)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
def main():
K, N = LI()
A = LI()
res = [A[0] + K - A[-1]]
for i in range(N-1):
res.append(A[i+1] - A[i])
res = sorted(res)
print(K - res[-1])
if __name__ == '__main__':
main() | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(N: int):
return (N//2 + N % 2) / N
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
print(f'{solve(N)}')
if __name__ == '__main__':
main()
| 0 | null | 110,644,353,060,230 | 186 | 297 |
n = int(raw_input())
a = []
input_line = raw_input().split()
for i in input_line:
a.append(i)
for i in reversed(a):
print i, | s = input()
g = input()
m = 0
n = len(s)
if s == g:
m = 0
else:
for i in range(n):
if s[i] == g[i]:
continue
else:
m += 1
print(m) | 0 | null | 5,761,630,885,878 | 53 | 116 |
n,m,k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_c_sum = [0]*(n + 1)
for i in range(n):
a_c_sum[i + 1] = a_c_sum[i] + a[i]
b_c_sum = [0]*(m + 1)
for i in range(m):
b_c_sum[i + 1] = b_c_sum[i] + b[i]
ans, best_b = 0, m
for i in range(n + 1):
if a_c_sum[i] > k:
break
else:
while 1:
if b_c_sum[best_b] + a_c_sum[i] <= k:
ans = max(ans, i + best_b)
break
else:
best_b -= 1
if best_b == 0:
break
print(ans) | n, m, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
asum = [0]
bsum = [0]
for i in range(len(aa)):
asum.append(asum[i]+aa[i])
for i in range(len(bb)):
bsum.append(bsum[i]+bb[i])
j = len(bsum)-1
ans = 0
for i in range(len(asum)):
while j >= 0:
if k >= asum[i] + bsum[j]:
ans = max(ans, i+j)
break
else:
j -= 1
print(ans)
| 1 | 10,719,670,937,562 | null | 117 | 117 |
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
U = 10**12
L = -1
while U - L > 1:
x = (U+L)//2
cnt = 0
for i in range(N):
if x//F[i] < A[i]:
cnt += A[i] - x//F[i]
if cnt > K:
L = x
else:
U = x
print(U) | #144_E
n, k = map(int, input().split())
a = sorted(list(map(int,input().split())))
f = sorted(list(map(int,input().split())))[::-1]
l, r = -1, 10 ** 12
while r - l > 1:
x = (r + l) // 2
res = 0
for i in range(n):
res += max(0, a[i] - x // f[i])
if res > k:
l = x
else:
r = x
print(r) | 1 | 164,535,206,004,808 | null | 290 | 290 |
import math
n = int(input())
def f(x,y,z):
return x**2 + y**2 + z**2 + z*x + x*y + y*z
current = [1,1,1]
ans = 0
p = [0 for _ in range(n+1)]
m = math.ceil(math.sqrt(n))+1
for i in range(1, m):
f_ = f(i, 1, 1)
if f_ > n:
break
for j in range(1, m):
f_ = f(i,j,1)
if f_ > n:
break
for k in range(1, m):
f_ = f(i,j,k)
if f_ > n:
break
p[f_] += 1
for i in range(1, n+1):
print(p[i]) | s = input().strip()
if s[-1]=='s':
s += 'es'
else:
s += 's'
print(s) | 0 | null | 5,217,867,146,350 | 106 | 71 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.