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
|
---|---|---|---|---|---|---|
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
import fractions as math
from functools import reduce
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def qq(numbers):
return reduce(lcm_base, numbers, 1)
n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[i//2 for i in A]
p=qq(B)
for i in A:
i//=2
if (p//i)%2==0:
print(0)
exit()
print(m//p - m//(p*2))
| from sys import stdin
for l in stdin:
l = l.rstrip()
if 0 == int(l):
break
print(sum([int(ch) for ch in l])) | 0 | null | 51,729,903,316,420 | 247 | 62 |
import warnings
n = 0
i = 0
while (n == 0):
i = i + 1
data = map(int, raw_input().split())
x = data[0]
y = data[1]
if(x == 0 and y == 0):
break
else:
if x > y:
print "%s %s" % (y, x)
else:
print "%s %s" % (x, y) | import math
x = int(input())
print(math.ceil(x/2)) | 0 | null | 29,837,646,565,230 | 43 | 206 |
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
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
from fractions import gcd
from heapq import heappush, heappop, heapify
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 ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
class UnionFind():
def __init__(self, n):
self.n = n
# parents[i]: 要素iの親要素の番号
# 要素iが根の場合、parents[i] = -(そのグループの要素数)
self.parents = [-1] * n
def find(self, x):
if 0 > self.parents[x]:
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
# 要素xが属するグループの要素数を返す
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
# 要素xが属するグループに属する要素をリストで返す
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 0 > x]
# グループの数を返す
def group_count(self):
return len(self.roots())
# 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
# print()での表示用
# all_group_members()をprintする
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = MAP()
tree = UnionFind(N)
friends = [[] for _ in range(N)]
for _ in range(M):
A, B = MAP()
tree.union(A-1, B-1)
friends[A-1].append(B-1)
friends[B-1].append(A-1)
blocks = [[] for _ in range(N)]
for _ in range(K):
C, D = MAP()
blocks[C-1].append(D-1)
blocks[D-1].append(C-1)
for i in range(N):
blocks_cnt = sum([tree.same(i, j) for j in blocks[i]])
print(tree.size(i) - len(friends[i]) - 1 - blocks_cnt, end=" ")
print()
| def main():
import sys
sys.setrecursionlimit(10**5+10)
N, M, K = map(int,input().split())
class UnionFind:
def __init__(self, N):
self.par = [-1 for i in range(N+1)]
self.rank = [1]*(N+1)
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self, x, y):
return self.find(x) == self.find(y)
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] > self.rank[y]:
self.par[x] += self.par[y]
self.par[y] = x
else:
self.par[y] += self.par[x]
self.par[x] = y
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
A, B = map(int,input().split())
friendlist[A].append(B)
friendlist[B].append(A)
if not UF.same_check(A,B):
UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
C, D = map(int, input().split())
blocklist[C].append(D)
blocklist[D].append(C)
for person in range(1,N+1):
root = UF.find(person)
ans = -UF.par[root]-1
ans -= len(friendlist[person])
for l in blocklist[person]:
if UF.same_check(person,l):
ans -= 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 61,470,109,156,312 | null | 209 | 209 |
x = input()
if x == x.upper():
print("A")
else:
print("a") | def solve():
S = input()
if S == "ABC":
print("ARC")
else:
print("ABC")
if __name__ == "__main__":
solve() | 0 | null | 17,684,274,794,270 | 119 | 153 |
from math import sqrt
N = int(input())
limit = int(sqrt(N))
res = [0] * (N + 1)
for x in range(1, limit+1):
for y in range(1, limit+1):
for z in range(1, limit+1):
val = x * x + y * y + z * z + x * y + y * z + z * x
if val <= N:
res[val] += 1
else:
break
for i in range(1, N + 1):
print(res[i])
| import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
for i in range(int(N**.5),0,-1):
if N % i == 0:
print(i+(N//i)-2)
exit()
| 0 | null | 84,698,913,250,600 | 106 | 288 |
def print_func(s, order):
print(s[order[1]:order[2]+1])
def reverse_func(s, order):
ans = list(s[order[1]:order[2]+1])
ans.reverse()
s = s[:order[1]]+''.join(ans)+s[order[2]+1:]
return s
def replace_func(s, order):
cnt = 0
s = list(s)
for i in range(order[1], order[2]+1):
s[i] = str(order[3])[cnt]
cnt += 1
s = ''.join(s)
return s
if __name__ == '__main__':
s = input()
for i in range(int(input())):
order = input().split()
order[1] = int(order[1])
order[2] = int(order[2])
if order[0] == 'print':
print_func(s, order)
elif order[0] == 'reverse':
s = reverse_func(s, order)
else:
s = replace_func(s, order) | N = int(input())
S = list(input())
Q = int(input())
class Bit:
"""1-indexed"""
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
en2asc = lambda s: ord(s) - 97
Bits = [Bit(N) for _ in range(26)]
for i, s in enumerate(S):
Bits[en2asc(s)].add(i + 1, 1)
for _ in range(Q):
q = input().split()
if q[0] == '1':
i, c = int(q[1]), q[2]
old = S[i - 1]
Bits[en2asc(old)].add(i, -1)
Bits[en2asc(c)].add(i, 1)
S[i - 1] = c
else:
l, r = int(q[1]), int(q[2])
ans = 0
for b in Bits:
ans += bool(b.sum(r) - b.sum(l - 1))
print(ans)
| 0 | null | 32,263,527,167,158 | 68 | 210 |
from bisect import bisect_right
N, M = map(int, input().split())
S = [N - i for i, s in enumerate(input()) if s == '0']
S = S[::-1]
ans = []
now = 0
while now < N:
i = bisect_right(S, now + M) - 1
if S[i] == now:
print('-1')
exit()
ans.append(S[i] - now)
now = S[i]
print(*ans[::-1])
| from heapq import heappush, heappop
N, M = map(int, input().split())
s = input()
INF = 10**18
dp_cnt = [INF]*(N+1)
dp_next = [0]*(N+1)
dp_cnt[N] = 0
q = [(0,N)]
for i in range(N-1, -1, -1):
while True:
cnt, j = q[0]
if j-i>M:
heappop(q)
else:
break
dp_cnt[i] = cnt
if s[i]=='1':
cnt = INF
j = 0
cnt += 1
heappush(q, (cnt, i))
dp_next[i] = j
if dp_cnt[0]>=INF:
print(-1)
exit()
x = 0
ans = []
while x<N:
y = dp_next[x]
ans += [str(y-x)]
x = y
print(*ans) | 1 | 139,123,011,591,982 | null | 274 | 274 |
n=int(input())
if n:
n-=1
else:
n+=1
print(n) | print(0 if int(input()) else 1) | 1 | 2,933,630,041,888 | null | 76 | 76 |
'''
Created on 2020/08/23
@author: harurun
'''
def f(n):
arr=[]
temp=n
for c in range(2,int(-(-n**0.5//1))+1):
if temp%c==0:
cnt=0
while temp%c==0:
cnt+=1
temp//=c
arr.append([c,cnt])
if temp!=1:
arr.append([temp,1])
return arr
def main():
import math
import sys
pin=sys.stdin.readline
pout=sys.stdout.write
perr=sys.stderr.write
N=int(pin())
r=f(N)
ans=0
for i in r:
ans+=int((math.sqrt(1+8*i[1])-1)/2)
print(ans)
return
main() | h = int(input())
count = 0
ans = 0
while h > 0:
h //= 2
count += 1
for i in range(count):
ans = ans*2 + 1
print(ans) | 0 | null | 48,487,773,310,340 | 136 | 228 |
def LinearSearch1(S, n, t):
for i in range(n):
if S[i] == t:
return i
break
else:
return -1
"""
def LinearSearch2(S, n, t):
S.append(t)
i = 0
while S[i] != t:
i += 1
S.pop()
if i == n:
return -1
else:
return i
"""
n = int(input())
S = [int(s) for s in input().split()]
q = int(input())
T = {int(t) for t in input().split()}
ans = sum(LinearSearch1(S, n, t) >= 0 for t in T)
print(ans) | n=int(input())
S=input().split(' ')
q=int(input())
T=input().split(' ')
def equal_element(S,T):
m=0
for i in range(len(T)):
for j in range(len(S)):
if S[j]==T[i]:
m+=1
break
return(m)
print(equal_element(S,T))
| 1 | 67,734,169,082 | null | 22 | 22 |
while True:
x = input()
if int(x) == 0: break
print(sum([int(i) for i in x])) | def solve(string):
return str(max(map(len, string.split("S"))))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 0 | null | 3,200,714,673,702 | 62 | 90 |
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] | a = 1
while a<10:
b=1
while b<10:
print(str(a)+'x'+str(b)+'='+str(a*b))
b=b+1
a=a+1 | 0 | null | 68,519,718,522 | 28 | 1 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,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()))
n,a,b = inpl()
dl = 1
for i in range(a):
dl *= n-i
dl %= mod
for i in range(a):
dl *= pow(a-i,mod-2,mod)
dl %= mod
# print(dl)
vv = 1
for i in range(b):
vv *= n-i
vv %= mod
for i in range(b):
vv *= pow(b-i,mod-2,mod)
vv %= mod
# print(vv)
res = pow(2,n,mod) - dl - vv - 1
print(res%mod) | n,a,b=map(int,input().split())
mod=10**9+7
def modpow(a,n):
if n<1:
return 1
ans=modpow(a,n//2)
ans=(ans*ans)%mod
if n%2==1:
ans*=a
return ans%mod
def cmb(n,i):#逆元
inv,ans=1,1
for j in range(1,i+1):
ans=ans*(n-j+1)%mod
inv=inv*j%mod
return (ans*modpow(inv,mod-2))%mod
ans_n=pow(2,n,mod)-1
ans_a=cmb(n,a)%mod
ans_b=cmb(n,b)%mod
print((ans_n-ans_a-ans_b)%mod) | 1 | 66,226,912,335,072 | null | 214 | 214 |
a, b = map(int, input().split())
if a < 10 and b < 10:
print(a * b)
else:
print('-1')
| n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
mod=10**9+7
ans=1
i=0
j=-1
k_1=k
while k_1>1:
if a[i]*a[i+1]>a[j]*a[j-1]:
ans=ans*a[i]*a[i+1]%mod
i+=2
k_1-=2
else:
ans=ans*a[j]%mod
j-=1
k_1-=1
if k_1==1:
ans=ans*a[j]%mod
if a[-1]<0 and k%2==1:
ans=1
for i in a[n-k:]:
ans=ans*i%mod
print(ans)
| 0 | null | 83,550,147,611,450 | 286 | 112 |
results = []
while True:
str_in = input()
if str_in == '-':
break
trial = int(input())
for i in range(trial):
h = int(input())
str_in = str_in[h:] + str_in[:h]
results.append(str_in)
for result in results:
print(result) | while True:
n=input()
if n=="-":
break
for i in range(int(input())):
h=int(input())
n=n[h:]+n[:h]
print(n)
| 1 | 1,902,116,510,976 | null | 66 | 66 |
A=1
B=1
C=0 #2つ前の項
D=0 #1
N=int(input())
if N==0 or N==1:
print(1)
elif N==2:
print(2)
else:
C=B #1
D=A+B #2
for i in range (N-3):
B=C
C=D
D=B+C
print(C+D)
| def solve():
H, W, M = map(int, input().split())
N = 3 * 10 ** 5
cnth = [0] * N
cntw = [0] * N
st = set()
for i in range(M):
h, w = map(lambda x: int(x) - 1, input().split())
cnth[h] += 1
cntw[w] += 1
st.add((h, w))
mh = max(cnth)
mw = max(cntw)
Y = []
X = []
for i in range(H):
if cnth[i] == mh:
Y.append(i)
for i in range(W):
if cntw[i] == mw:
X.append(i)
for y in Y:
for x in X:
if not (y, x) in st:
return mh + mw
return mh + mw - 1
print(solve())
| 0 | null | 2,360,512,768,600 | 7 | 89 |
from numba import njit, i8, void
import numpy as np
mod = 10**9+7
k = int(input())
n = len(input())
@njit(i8(i8), cache=True)
def pow(n):
l, now, mod, k = np.ones(64, np.int64), 1, 10**9+7, 10**9+5
l[0] = n
for i in range(1, 64):
l[i] = l[i-1]*l[i-1] % mod
for i in range(64):
if k & 1:
now = now*l[i] % mod
k >>= 1
return now
@njit(void(i8, i8), cache=True)
def num_calc(n, k):
fact, mod = np.ones(n+k+1, dtype=np.int64), 10**9+7
for i in range(2, n+k+1):
fact[i] = fact[i-1]*i % mod
power = np.ones(k+1, dtype=np.int64)
power[0] = fact[n+k]
for i in range(1, k+1):
power[i] = power[i-1]*25 % mod
fact = fact[n+k:n-1:-1]*fact[:k+1] % mod
ans = 0
for i in range(k+1):
ans = (ans+pow(fact[i])*power[i]) % mod
print(ans)
num_calc(n, k)
| import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
mon=1000
stk=0
for i in range(n-1):
if A[i]<=A[i+1]:
stk+=mon//A[i]
mon%=A[i]
else:
mon+=stk*A[i]
stk=0
mon+=stk*A[-1]
print(mon) | 0 | null | 10,028,793,772,092 | 124 | 103 |
while True:
m,f,r = map(int,raw_input().split())
if m == -1 and f == -1 and r == -1:
break
if m == -1 or f == -1:
print('F')
elif m+ f >= 80:
print('A')
elif m + f >= 65 and m + f < 80:
print('B')
elif m + f >= 50 and m + f < 65 or r >= 50:
print('C')
elif m + f >= 30 and m + f < 50:
print('D')
elif m + f <= 29:
print('F') | n = int(input())
x = list(map(int, input().split()))
sum= 1000000000000000
for p in range(1,101):
tmp=0
# print("p",p)
for i in range(len(x)):
tmp += (x[i] - p)**2
# print("tmp",tmp)
sum = min(sum,tmp)
# print("su",sum)
print(sum) | 0 | null | 33,066,351,729,068 | 57 | 213 |
N = input()[::-1]
l = len(N)
dp = [[0,0] for i in range(l+1)]
for i in range(l):
dp[i+1][0] = min(dp[i][0] + int(N[i]), dp[i][1] + int(N[i]) + 1)
if i == 0:
dp[i+1][1] = 10 - int(N[i])
else:
dp[i+1][1] = min(dp[i][0] + 10 - int(N[i]), dp[i][1] + 9 - int(N[i]))
print(min(dp[-1][0],dp[-1][1]+1))
| L,R,d=map(int,input().split())
ans=0
for i in range(R-L+1):
if (L+i)%d==0:
ans+=1
print(ans) | 0 | null | 39,256,912,533,150 | 219 | 104 |
n = int(input())
values = [int(input()) for i in range(n)]
maxv = -999999999
minimum = values[0]
for i in range(1, n):
if values[i] - minimum > maxv:
maxv = values[i] - minimum
if values[i] < minimum:
minimum = values[i]
print(maxv) | n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
for j in range( n-1 ):
num = int( raw_input( ) )
diff = num - minv
if maxv < diff:
maxv = diff
if num < minv:
minv = num
print maxv | 1 | 13,119,679,132 | null | 13 | 13 |
N, K = map(int,input().split())
As = list(map(int,input().split()))
visited = [0] * N
path = []
now_town = 1
while(True):
visited[now_town-1] = 1
path.append(now_town)
now_town = As[now_town-1]
if visited[now_town-1] == 1:
break
index = path.index(now_town)
loop = path[index:len(path)]
loop_len = len(loop)
if index < K:
k = K - index
r = k % loop_len
print(loop[r])
else:
print(path[K])
| N = int(input())
l = []
for i in range(N+1):
if i % 5 == 0 or i % 3 == 0:
l.append(0)
else:
l.append(i)
print(sum(l)) | 0 | null | 28,851,045,262,520 | 150 | 173 |
while True:
t = input().split()
a = int(t[0])
b = int(t[1])
if (a == 0) and (b == 0):
break
if (a < b):
print(str(a) + " " + str(b))
else:
print(str(b) + " " + str(a)) | while 1 :
a,b = map(int,raw_input().split())
if not a and not b:
break
if a < b:
print "%d %d" % (a , b)
else :
print "%d %d" % (b , a) | 1 | 517,556,689,992 | null | 43 | 43 |
#B
N, K = map(int,input().split())
num=[]
while N >= K:
num.append(N%K)
N=N//K
num.append(N)
print(len(num)) | import math
N = int(input())
count = 0
for _ in range(N):
m = int(input())
rm = int(math.sqrt(m))
flag = 0
for i in range(2,rm+1):
if m %i ==0:
flag = 1
break
if flag ==0 :count=count +1
print(count) | 0 | null | 32,220,614,882,940 | 212 | 12 |
W = input().casefold()
count=0
while True:
line = input()
if line == "END_OF_TEXT":
break
line = line.casefold()
word = line.split()
count += word.count(W)
print(count) | search_s = input()
cnt = 0
while True:
s = input()
if s == "END_OF_TEXT": break
word_list = s.lower().split()
for word in word_list:
if word == search_s:cnt += 1
print(cnt) | 1 | 1,821,972,274,300 | null | 65 | 65 |
n = int(input())
a = [int(i) for i in input().split()]
print(' '.join(map(str, reversed(a)))) | def reverse(l):
"""
l: a list
returns a reversed list
>>> reverse([1,2,3,4,5])
[5, 4, 3, 2, 1]
>>> reverse([3,3,4,4,5,8,7,9])
[9, 7, 8, 5, 4, 4, 3, 3]
>>> reverse([])
[]
"""
length = len(l)
result = []
for i in range(length):
result.append(l[length-i-1])
return result
if __name__ == '__main__':
#import doctest
#doctest.testmod()
num = int(input())
ilist = [int(i) for i in input().split(' ')]
print(' '.join([str(i) for i in reverse(ilist)])) | 1 | 989,452,044,130 | null | 53 | 53 |
def dfs(c,lst):
n=len(lst)
ans=[0]*n
stack = [c-1]
check = [0]*n #チェック済みリスト
while stack != [] :
d=stack.pop()
if check[d]==0:
check[d]=1
for i in lst[d]:
if check[i]==0:
stack.append(i)
ans[i]=ans[d]+1
return(ans)
import sys
input = sys.stdin.readline
N,u,v=map(int,input().split())
ki=[[] for f in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
ki[a-1].append(b-1)
ki[b-1].append(a-1)
U=dfs(u,ki)
V=dfs(v,ki)
ans=0
for i in range(N):
if V[i]>U[i]:
ans=max(ans,V[i]-1)
print(ans)
| # coding=utf-8
import math
def cut_into_three(start: list, end: list) -> list:
x1 = (2*start[0]+end[0])/3
y1 = (2*start[1]+end[1])/3
mid_point1 = [x1, y1]
x2 = (start[0]+2*end[0])/3
y2 = (start[1]+2*end[1])/3
mid_point2 = [x2, y2]
points_list = [start, mid_point1, mid_point2, end]
return points_list
def equil_triangle(point1: list, point2: list) -> list:
cos60 = math.cos(math.pi / 3)
sin60 = math.sin(math.pi / 3)
x = (point2[0] - point1[0])*cos60 - (point2[1]-point1[1])*sin60 + point1[0]
y = (point2[0] - point1[0])*sin60 + (point2[1]-point1[1])*cos60 + point1[1]
return [x, y]
def make_projection(start: list, end: list) -> list:
points_list = cut_into_three(start, end)
projection_point = equil_triangle(points_list[1], points_list[2])
points_list.insert(2, projection_point)
return points_list
def koch_curve(start: list, end: list, number: int) -> list:
if number == 0:
return [start, end]
else:
points_list = make_projection(start, end)
list1 = koch_curve(points_list[0], points_list[1], number-1)
list2 = koch_curve(points_list[1], points_list[2], number-1)
list3 = koch_curve(points_list[2], points_list[3], number-1)
list4 = koch_curve(points_list[3], points_list[4], number-1)
new_points_list = list1 + list2[1:] + list3[1:] + list4[1:]
return new_points_list
if __name__ == '__main__':
n = int(input())
p1 = [0, 0]
p2 = [100, 0]
fractal_points = koch_curve(p1, p2, n)
for i in fractal_points:
print(' '.join(map(str, i))) | 0 | null | 58,680,325,335,412 | 259 | 27 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = input()
N = [int(i) for i in N]
# 数え上げ問題なので多分dp
dp = [[0, 0] for i in range(len(N))]
# ぴったし払うための最小値
dp[0][0] = min(N[0], 11 - N[0])
# お釣りをもらう用の紙幣を1枚余分にとっておく場合の最小値
dp[0][1] = min(N[0] + 1, 10 - N[0])
for i in range(1, len(N)):
# dp[i - 1][1] + 10 - N[i]:とっておいた紙幣を使用し、お釣りを10 - N[i]枚もらう
dp[i][0] = min(dp[i - 1][0] + N[i], dp[i - 1][1] + 10 - N[i])
# dp[i - 1][1] + 9 - N[i]:お釣りを10 - N[i]枚もらい、そのうち1枚は次のお釣りを
# もらう試行のためにとっておく
dp[i][1] = min(dp[i - 1][0] + N[i] + 1, dp[i - 1][1] + 9 - N[i])
print(dp[len(N) - 1][0]) | # coding=utf-8
n = int(input())
dic = set()
for i in range(n):
cmd = input().split()
if cmd[0] == 'insert':
dic.add(cmd[1])
else:
if cmd[1] in dic:
print('yes')
else:
print('no') | 0 | null | 35,533,028,368,418 | 219 | 23 |
d,t,s = [float(x) for x in input().split()]
if d/s > t:
print("No")
else:
print("Yes") | x = int(input());print((x//500)*1000 + ((x%500)//5)*5) | 0 | null | 23,269,732,740,630 | 81 | 185 |
ABC = list(map(int,input().split()))
red = ABC[0]
green = ABC[1]
blue = ABC[2]
K = int(input())
for i in range(K):
if green <= red:
green *= 2
continue
elif blue <= green:
blue *= 2
if green > red and blue > green:
print('Yes')
else:
print('No') | a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
total = sum(alist)
sumlist = []
ans = 0
for i in range(len(alist)-1):
total -= alist[i]
ans += alist[i]*(total)
print(ans%mod) | 0 | null | 5,293,393,040,622 | 101 | 83 |
s = input()
p = input()
flag = False
for i in range(len(s)):
t = s[i:] + s[:i]
if p in t :
flag = True
break
if flag :
print("Yes")
else :
print("No") | p=input()
s=input()
ret = 'Yes'
try: (p+p).index(s)
except : ret = 'No'
print(ret) | 1 | 1,743,104,208,768 | null | 64 | 64 |
N = int(input())
amount = 0
for i in range(1, N + 1):
if (i % 15 == 0) or (i % 3 == 0) or (i % 5 == 0):
pass
else:
amount = amount + i
print(amount)
| N=input()
ans=0
for i in range(1,int(N)+1):
if i%15==0:
pass
elif i%5==0:
pass
elif i%3==0:
pass
else:
ans=ans+i
print(ans) | 1 | 35,030,640,525,860 | null | 173 | 173 |
import math
while True:
n,x=list(map(int,input().split()))
if n==x==0: break
c=0
for i in range(1,x//3):
if i>n: break
for j in range(i+1,(x-i)//2+1):
if j>n: break
k=x-i-j
if not (n<k or k<=j):
c+=1
print(c) | from sys import stdin
while True:
n, x = [int(x) for x in stdin.readline().rstrip().split()]
if n == 0 and x == 0:
break
else:
count = 0
for i in range(1, n-1):
for j in range(i+1, n):
if j < x-i-j <= n:
count += 1
else:
print(count)
| 1 | 1,284,810,570,920 | null | 58 | 58 |
x=input()
i=1
while (x!='0'):
print("Case {0}: {1}".format(i,x));
i+=1;
x=input()
| a,b,n = map(int,input().split())
i = min(b-1,n)
calc = (a*i)//b - (a * (i//b))
print(calc)
| 0 | null | 14,318,481,942,240 | 42 | 161 |
s = input()
s_list = list(s)
if s_list[-1] == 's':
output = s + 'es'
else:
output = s + 's'
print(output) | noun = input()
end="s"
if noun[-1] == 's':end="es"
noun += end
print(noun) | 1 | 2,367,264,836,832 | null | 71 | 71 |
all_set = ['S ' + str(i) for i in range(1, 14)] + ['H ' + str(i) for i in range(1, 14)] + ['C ' + str(i) for i in range(1, 14)] + ['D ' + str(i) for i in range(1, 14)]
r = int(input())
for _ in range(r):
x = input()
if x in all_set:
del all_set[all_set.index(x)]
for i in all_set:
print(i)
| a = input()
b = 0
c = ""
for i in a:
c += i
b += 1
if b==3:
break
print(c)
| 0 | null | 7,874,850,977,530 | 54 | 130 |
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
ans = 0
x, y, z = [0], [0], [0]
for i in range(n):
if a[i] == 0:
if x[-1] == 0:
x.append(1)
y.append(y[-1])
z.append(z[-1])
elif y[-1] == 0:
x.append(x[-1])
y.append(1)
z.append(z[-1])
else:
x.append(x[-1])
y.append(y[-1])
z.append(1)
else:
if x[-1] == a[i]:
x.append(x[-1] + 1)
y.append(y[-1])
z.append(z[-1])
elif y[-1] == a[i]:
x.append(x[-1])
y.append(y[-1] + 1)
z.append(z[-1])
else:
x.append(x[-1])
y.append(y[-1])
z.append(z[-1] + 1)
ans = 1
for i in range(n):
ans *= [x[i], y[i], z[i]].count(a[i])
ans %= (10 ** 9 + 7)
print(ans)
| n = int(input())
data = list(map(int, input().split()))
ans = []
for i in range(n):
if (i % 2 == 0) and (data[i] % 2 == 1):
ans.append(data[i])
print(len(ans))
| 0 | null | 68,570,367,394,610 | 268 | 105 |
n, *a = map(int, open(0).read().split())
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
cnt = 0
for j in range(n):
cnt += a[j] >> i & 1
ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod
print(ans)
| N, *A = map(int, open(0).read().split())
mod = 10**9 + 7
batch = 8
rg = tuple(range((63//batch)+1))
mask = (1<<batch) - 1
B = [[0]*(1<<batch) for _ in rg]
for a in A:
for i in rg:
B[i][a & mask] += 1
a >>= batch
xr = [[] for _ in [0]*(1<<batch)]
for i in range(1<<batch):
for j in range(i+1, 1<<batch):
xr[i].append(i^j)
ans = 0
shift = 1
for b in B:
x = sum(xr[i][j]*bi*bj for i, bi in enumerate(b) for j, bj in enumerate(b[i+1:]))
x %= mod
x *= shift
x %= mod
shift <<= batch
shift %= mod
ans += x
ans %= mod
print(ans) | 1 | 122,867,275,015,040 | null | 263 | 263 |
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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 ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
N = INT()
D = LIST()
if D[0] > 0 or D.count(0) > 1:
print(0)
exit()
D.sort()
ct = [1] * (max(D)+1)
for i in range(N):
if D[i] - D[i-1] > 1:
print(0)
exit()
elif D[i] - D[i-1] == 0:
ct[D[i]] += 1
ans = 1
for i in range(1, max(D)+1):
ans *= pow(ct[i-1], ct[i], 998244353)
ans %= 998244353
print(ans)
if __name__ == '__main__':
main()
| mod = 998244353
n = int(input())
d = list(map(int,input().split()))
from collections import Counter
c = Counter(d)
ans = 1
b = 1
if c[0]!=1 or d[0]!=0:ans = 0
for i in range(max(d)+1):
ans = (ans*b**c[i])%mod
b = c[i]
print(ans) | 1 | 155,053,512,783,520 | null | 284 | 284 |
N = int(input())
t = N // 2
a_list = []
b_list = []
for i in range(N):
ab = list(map(int, input().split()))
a_list.append(ab[0])
b_list.append(ab[1])
a_list = sorted(a_list)
b_list = sorted(b_list)
if N%2 == 1:
a_median = a_list[t]
b_median = b_list[t]
print(b_median-a_median+1)
elif N%2 == 0:
a_median = (a_list[t-1]+a_list[t])/2
b_median = (b_list[t-1]+b_list[t])/2
print(int(2*(b_median-a_median)+1)) | N=int(input())
A,B=[],[]
for i in range(N):
a,b=map(int,input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
I=~-N//2
print(B[I]-A[I]+1 + (B[I+1]-A[I+1] if N%2==0 else 0))
| 1 | 17,340,175,135,894 | null | 137 | 137 |
N = int(input())
a = 0
b = 0
if N % 2 == 0:
a = N // 2
print(a)
else:
b = N // 2 + 1
print(b) | m=int(input())
print(m//2+m%2) | 1 | 59,139,120,128,318 | null | 206 | 206 |
from sys import stdin, stdout
n, m = map(int, stdin.readline().strip().split())
if m>=n:
print('unsafe')
else:
print('safe') | s,w=map(int, input().split())
if(s<=w) :
print('unsafe')
else :
print('safe') | 1 | 29,345,722,869,810 | null | 163 | 163 |
x, y = map(int, input().split())
for i in range(x+1):
for j in range(x+1):
if i+j == x:
if 2*i + 4*j == y:
print('Yes')
exit()
print('No') | x = int(input())
def judge_prime_number(x):
for i in range(2, int(x ** (1/2)) + 1):
if x % i == 0:
return False
else:
return True
while True:
if not judge_prime_number(x):
x += 1
continue
else:
print(x)
break | 0 | null | 59,482,218,834,340 | 127 | 250 |
INF = 10**9
def solve(h, w, s):
dp = [[INF] * w for r in range(h)]
dp[0][0] = int(s[0][0] == "#")
for r in range(h):
for c in range(w):
for dr, dc in [(-1, 0), (0, -1)]:
nr, nc = r+dr, c+dc
if (0 <= nr < h) and (0 <= nc < w):
dp[r][c] = min(dp[r][c], dp[nr][nc] + (s[r][c] != s[nr][nc]))
return (dp[h-1][w-1] + 1) // 2
h, w = map(int, input().split())
s = [input() for r in range(h)]
print(solve(h, w, s))
| # -*- coding: utf-8 -*-
list = map(int, raw_input().split())
W = list[0]
H = list[1]
x = list[2]
y = list[3]
r = list[4]
if (x-r) >= 0 and (y-r) >= 0 and (x+r) <= W and (y+r) <= H:
print "Yes"
else:
print "No" | 0 | null | 24,897,442,384,572 | 194 | 41 |
N,K = map(int,input().split())
gcddic = {}
mod_n = (10**9+7)
for i in range(K,0,-1):
x = pow((K//i),N,mod_n)
ll=2
while(ll*i<=K):
x -= gcddic[ll*(i)]
ll += 1
gcddic[i] = x
sumnation = 0
for i,l in gcddic.items():
sumnation += i*l
print(sumnation%mod_n) | N=[int(c) for c in input()][::-1]
dp=[[0]*2 for _ in range(len(N)+1)]
dp[0][1]=1
for i in range(len(N)):
dp[i+1][1]=min(dp[i][0]+N[i]+1,dp[i][1]+10-N[i]-1)
dp[i+1][0]=min(dp[i][0]+N[i],dp[i][1]+10-N[i])
print(dp[len(N)][0]) | 0 | null | 53,714,638,171,460 | 176 | 219 |
import sys
L,R,d = map(int, sys.stdin.readline().split())
# L=5
# R=10
# d=2
result = 0
for index in range(L,R+1):
if index % d == 0:
result += 1
print(result)
| S = input()
s_rev = S[::-1]
r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
num += d*int(s_rev[i])
num %= 2019
r_list[num] += 1
d *= 10
d %= 2019
ans = 0
for i in range(2019):
ans += r_list[i]*(r_list[i]-1)//2
print(ans)
| 0 | null | 19,302,149,625,380 | 104 | 166 |
X, K, D = map(int, input().split())
X = abs(X)
ans = 0
if X // D > K:
ans = X - D*K
else:
e = X // D
K -= e
X -= D * e
if K % 2 == 1: X = abs(X-D)
ans = X
print(ans) | def main():
import sys
n,s,_,*t=sys.stdin.buffer.read().split()
n=int(n)
d=[0]*n+[1<<c-97for c in s]
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
r=[]
for q,a,b in zip(*[iter(t)]*3):
i,s=int(a)+n-1,0
if q<b'2':
d[i]=1<<b[0]-97
while i:
i//=2
d[i]=d[i+i]|d[i-~i]
continue
j=int(b)+n
while i<j:
if i&1:
s|=d[i]
i+=1
if j&1:
j-=1
s|=d[j]
i//=2
j//=2
r+=bin(s).count('1'),
print(' '.join(map(str,r)))
main() | 0 | null | 33,865,707,166,100 | 92 | 210 |
N,M=map(int,input().split())
a=N//2
b=a+1
print(a,b)
if M==1:
exit(0)
c=1
d=N-1
print(c,d)
for i in range(M-2):
if i%2==0:
a,b=a-1,b+1
print(a,b)
else:
c,d=c+1,d-1
print(c,d)
| x,y=map(int,input().split())
print(100000*(max(4-x,0)+max(4-y,0)+4*(x==y==1))) | 0 | null | 84,289,921,514,062 | 162 | 275 |
N,X,Y=map(int,input().split())
#i<X<Y<j
#このときはX->を通るほうが良い
#X<=i<j<=Y
#このときはループのどちらかを通れば良い
#X<=i<=Y<j
#このときはiとYの最短距離+Yとjの最短距離
#i<X<=j<=Y
#同上
#i<j<X
#パスは1通りしか無い
def dist(i,j):
if i>j:
return dist(j,i)
if i==j:
return 0
if i<X:
if j<X:
return j-i
if X<=j and j<=Y:
return min(j-i,(X-i)+1+(Y-j))
if Y<j:
return (X-i)+1+(j-Y)
if X<=i and i<=Y:
if j<=Y:
return min(j-i,(i-X)+1+(Y-j))
if Y<j:
return min((i-X)+1+(j-Y),j-i)
if Y<i:
return (j-i)
ans=[0 for i in range(N)]
for i in range(1,N+1):
for j in range(i+1,N+1):
ans[dist(i,j)]+=1
for k in range(1,N):
print(ans[k]) | def main():
a = map(int, input().split(" "))
print("bust" if sum(a) >= 22 else "win")
main()
| 0 | null | 81,537,167,706,622 | 187 | 260 |
if __name__ == '__main__':
from collections import deque
n = int(input())
dic = {}
for i in range(n):
x = input().split()
if x[0] == "insert":
dic[x[1]] = 1
if x[0] == "find":
if x[1] in dic:
print('yes')
else:
print('no')
| n = int(input())
l = set()
for i in range(n):
cmd = input().split()
if cmd[0] == 'insert':
l.add(cmd[1])
if cmd[0] == 'find':
print('yes' if cmd[1] in l else 'no') | 1 | 77,691,749,684 | null | 23 | 23 |
s = input()
for i in range(int(input())):
cmd = input().split()
a, b = int(cmd[1]), int(cmd[2])
if cmd[0] == 'print':
print(s[a:b+1])
elif cmd[0] == 'reverse':
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
elif cmd[0] == 'replace':
s = s[:a] + cmd[3] + s[b+1:] | s = input()
for _ in range(int(input())):
o = list(map(str, input().split()))
a = int(o[1])
b = int(o[2])
if o[0] == "print":
print(s[a:b+1])
elif o[0] == "reverse":
s = s[:a] + s[a:b+1][::-1] + s[b+1:]
else:
s = s[:a] + o[3] + s[b+1:]
| 1 | 2,059,072,264,060 | null | 68 | 68 |
N = int(input())
ACcount = 0
WAcount = 0
TLEcount = 0
REcount = 0
for i in range(N):
S=input()
if S == "AC":
ACcount = ACcount + 1
elif S == "WA":
WAcount = WAcount + 1
elif S == "TLE":
TLEcount = TLEcount + 1
elif S == "RE":
REcount = REcount + 1
print("AC x", ACcount)
print("WA x", WAcount)
print("TLE x", TLEcount)
print("RE x", REcount)
| h = list(map(int, input().split()))
m = 0
m += 60 - h[1]
if m != 0: h[0] += 1
m += h[3] + (h[2]-h[0]) * 60
print(m-h[-1]) | 0 | null | 13,405,686,477,820 | 109 | 139 |
A = str(input())
if A[-1] == "s":
print(A + "es");
else:
print(A + "s") | def f(n):
res = []
for p in range(2, int(n**0.5)):
k = 0
while(n % p == 0):
n //= p
k += 1
if k:
res.append((p, k))
if n != 1:
res.append((n,1))
return res
n = int(input())
ans = 0
r = f(n)
for p,k in r:
tmp = 0
cur = 1
while(k>=cur):
tmp += 1
k -= cur
cur += 1
ans += tmp
print(ans) | 0 | null | 9,620,421,908,000 | 71 | 136 |
#!/usr/bin/env python3
def main():
n, u, v = map(int, input().split())
u -= 1
v -= 1
adj = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
adj[a].append(b)
adj[b].append(a)
# uv間経路を求める
st = [u]
prev = [None for i in range(n)]
while st:
x = st.pop()
for y in adj[x]:
if y == prev[x]: continue
prev[y] = x
st.append(y)
path = [v]
while path[-1] != u:
path.append(prev[path[-1]])
path = list(reversed(path))
# crossからsquareを経由しない最遠ノードstarを求める(a59p22)
l = len(path) - 1
cross = path[(l - 1) // 2]
square = path[(l - 1) // 2 + 1]
st = [(cross, 0)]
prev = [None for i in range(n)]
dist = [-1 for i in range(n)]
while st:
x, d = st.pop()
dist[x] = d
for y in adj[x]:
if y == prev[x]: continue
if y == square: continue
prev[y] = x
st.append((y, d + 1))
star_square = max(dist)
if l % 2 == 1:
res = (l - 1) // 2 + star_square
else:
res = (l - 1) // 2 + star_square + 1
print(res)
if __name__ == "__main__":
main()
| # D - Maze Master
# https://atcoder.jp/contests/abc151/tasks/abc151_d
from collections import deque
def main():
height, width = [int(num) for num in input().split()]
maze = [input() for _ in range(height)]
ans = 0
next_to = ((0, 1), (1, 0), (0, -1), (-1, 0))
for start_x in range(height):
for start_y in range(width):
if maze[start_x][start_y] == '#':
continue
queue = deque()
queue.append((start_x, start_y))
reached = [[-1] * width for _ in range(height)]
reached[start_x][start_y] = 0
while queue:
now_x, now_y = queue.popleft()
for move_x, move_y in next_to:
adj_x, adj_y = now_x + move_x, now_y + move_y
# Python は index = -1 が通ってしまうことに注意。
# except IndexError では回避できない。
if (not 0 <= adj_x < height
or not 0 <= adj_y < width
or maze[adj_x][adj_y] == '#'
or reached[adj_x][adj_y] != -1):
continue
queue.append((adj_x, adj_y))
reached[adj_x][adj_y] = reached[now_x][now_y] + 1
most_distant = max(max(row) for row in reached)
ans = max(most_distant, ans)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 105,997,799,739,808 | 259 | 241 |
M = 10 ** 6
d = [0] * (M+1)
for a in range(1, M+1):
for b in range(a, M+1):
n = a * b
if n > M:
break
d[n] += 2 - (a==b)
N = int(input())
ans = 0
for c in range(1, N):
ans += d[N - c]
print(ans) | import sys
input = sys.stdin.readline
n = int(input())
ans = 0
for a in range(1,n+1):
ans += (n-1) // a
print(ans) | 1 | 2,597,196,371,360 | null | 73 | 73 |
import math
h = int(input())
w = int(input())
n = int(input())
ans = math.ceil(n/max(h,w))
print(ans) | # 2020/08/16
# AtCoder Beginner Contest 030 - A
# Input
h = int(input())
w = int(input())
n = int(input())
# Calc
ans = n // max(h, w)
if n % max(h, w) > 0:
ans = ans + 1
# Output
print(ans)
| 1 | 88,577,361,527,898 | null | 236 | 236 |
user_input = input()
ascci_value = ord(user_input)
if ascci_value in range(97, 123):
print('a')
else:
print('A') | a=input()
if a==a.upper():
print("A")
else:
print("a") | 1 | 11,246,355,195,360 | null | 119 | 119 |
def main():
input()
array = [int(x) for x in input().split()]
ans = sum(x % 2 == 1 for x in array[::2])
print(ans)
if __name__ == '__main__':
main()
| s = input()
p = input()
s += s
if p in s and 2 * len(p) <= len(s):
print("Yes")
else:
print("No") | 0 | null | 4,824,113,561,062 | 105 | 64 |
n=int(input())
l=list(map(int,input().split()))
from bisect import bisect_left
l.sort()
count=0
for a in range(n-2):
for b in range(a+1,n-1):
idx=bisect_left(l,l[a]+l[b],lo=b)
count+=idx-(b+1)
print(count) | import sys
sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline
def solve():
N, M, L = map(int, rl().split())
INF = 10 ** 18
dist = [[INF] * N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, rl().split())
a, b = a - 1, b - 1
dist[a][b] = dist[b][a] = c
for k in range(N):
for i in range(N):
for j in range(N):
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
cost = [[INF] * N for _ in range(N)]
for i in range(N):
for j in range(N):
if dist[i][j] <= L:
cost[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
Q = int(rl())
st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
ans = [-1] * Q
for i, (s, t) in enumerate(st):
if cost[s][t] != INF:
ans[i] = cost[s][t] - 1
print(*ans, sep='\n')
if __name__ == '__main__':
solve()
| 0 | null | 173,144,241,327,850 | 294 | 295 |
X, Y, A, B, C = map(int, input().split())
Ps = list(map(int, input().split()))
Qs = list(map(int, input().split()))
Rs = list(map(int, input().split()))
Ps.sort(reverse=True)
Qs.sort(reverse=True)
Al = Ps[:X] + Qs[:Y] +Rs
Al.sort(reverse=True)
print(sum(Al[:X+Y])) | x,y,a,b,c=map(int, input().split())
*p,=map(int, input().split())
*q,=map(int, input().split())
*r,=map(int, input().split())
from heapq import *
p=[-i for i in p]
q=[-i for i in q]
r=[-i for i in r]
heapify(p)
heapify(q)
heapify(r)
ans=0
cnt=0
pt=heappop(p)
qt=heappop(q)
rt=heappop(r)
n=x+y
while (x>=0 or y>=0) and cnt<n:
if rt==0:
if pt<=qt:
ans-=pt
x-=1
cnt+=1
if p and x>0: pt=heappop(p)
else: pt=0
else:
ans-=qt
y-=1
cnt+=1
if q and y>0: qt=heappop(q)
else: qt=0
elif pt<=rt:
ans-=pt
x-=1
cnt+=1
if p and x>0: pt=heappop(p)
else: pt=0
elif qt<=rt:
ans-=qt
y-=1
cnt+=1
if q and y>0: qt=heappop(q)
else: qt=0
else:
ans-=rt
cnt+=1
if r: rt=heappop(r)
else: rt=0
print(ans)
| 1 | 45,028,372,233,922 | null | 188 | 188 |
n = int(input())
a = list(map(int, input().split()))
ma = max(a)
dp = [0]*(ma+1)
for i in sorted(a):
if 1 <= dp[i]:
dp[i] += 1
continue
for j in range(1, ma//i + 1):
dp[j * i] += 1
ans=0
for i in a:
if dp[i] == 1:
ans += 1
print(ans) | #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
#??????????????????
#?????????????´?????¢????????????£????????????????????????????????¨???????¢?????????¨
#?????°??¢??°???????¨???????????¢????????????????
def bubble_sort(target_list):
list_length = len(target_list)
flag = True
change_count = 0
top_index = 1
while flag:
flag = False
for i in range(top_index, list_length)[::-1]:
if target_list[i] < target_list[i - 1]:
tmp = target_list[i]
target_list[i] = target_list[i - 1]
target_list[i - 1] = tmp
change_count += 1
flag = True
top_index += 1
return change_count
def main():
n_list = int(input())
target_list = [int(n) for n in input().split()]
cc = bubble_sort(target_list)
print(*target_list)
print(cc)
if __name__ == "__main__":
main() | 0 | null | 7,236,120,040,700 | 129 | 14 |
li=["SUN","MON","TUE","WED","THU","FRI","SAT"]
day=input()
for i in range(7):
if(li[i]==day):
print(7-i) | d='SUN,MON,TUE,WED,THU,FRI,SAT'.split(',')
s=input()
print(7 - d.index(s)) | 1 | 132,830,757,168,762 | null | 270 | 270 |
def main():
s = list(input())
ans = 0
for i in range(len(s)):
if s[i] != s[-i - 1]:
ans += 1
print(ans // 2)
if __name__ == "__main__":
main()
| from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
d[input()] += 1
for v in ['AC', 'WA', 'TLE', 'RE']:
print(v, 'x', d[v]) | 0 | null | 64,679,423,181,152 | 261 | 109 |
import math
r = float(input())
pi = float(math.pi)
print("{0:.8f} {1:.8f}".format(r*r*pi,r * 2 * pi)) | from collections import deque
LIM=200004
L=[0]*LIM
def bin_sum(Y):
S=bin(Y)[2:]
count=0
for i in range(len(S)):
count+=int(S[i])
return count
def bin_sum2(Y):
count=0
for i in range(len(Y)):
count+=int(Y[i])
return count
for i in range(1,LIM):
L[i]+=bin_sum(i)
def pop_num(N,b,L):
if N==0:
return 0
v=N%b
return pop_num(v,L[v],L)+1
M=[0]*200005
for i in range(1,200004):
M[i]+=pop_num(i,L[i],L)
X=int(input())
Y=input()
d=bin_sum2(Y)
e=int(Y,2)%(d+1)
f=int(Y,2)%max(1,(d-1))
O=[1]*(X+2)
P=[1]*(X+2)
q=max(d-1,1)
for i in range(1,X+1):
O[i]=O[i-1]*2%q
P[i]=P[i-1]*2%(d+1)
for i in range(X):
if int(Y[i])==1:
b=max(d-1,1)
flag=max(0,d-1)
g=(f-O[X-1-i]+b)%b
else:
b=d+1
flag=1
g=(e+P[X-1-i])%b
if flag==0:
print(0)
elif g==0:
print(1)
else:
print(M[g]+1) | 0 | null | 4,454,936,464,142 | 46 | 107 |
def input_int():
return map(int, input().split())
def one_int():
return int(input())
def one_str():
return input()
def many_int():
return list(map(int, input().split()))
A, B = input_int()
print(A*B) | N,M,K=map(int,input().split())
*A,=map(int,input().split())
*B,=map(int,input().split())
def binary_search(func, array, left=0, right=-1):
if right==-1:right=len(array)-1
y_left, y_right = func(array[left]), func(array[right])
while True:
middle = (left+right)//2
y_middle = func(array[middle])
if y_left==y_middle: left=middle
else: right=middle
if right-left==1:break
return left
cumA = [0]
for i in range(N):
cumA.append(cumA[-1]+A[i])
cumB = [0]
for i in range(M):
cumB.append(cumB[-1]+B[i])
cumB.append(10**20)
if cumA[-1]+cumB[-1]<=K:
print(N+M)
exit()
if A[0] > K and B[0] > K:
print(0)
exit()
ans = 0
for i in range(N+1):
if K-cumA[i]<0:break
idx = binary_search(lambda x:x<=K-cumA[i],cumB)
res = max(0,i+idx)
ans = max(ans, res)
print(ans) | 0 | null | 13,251,160,935,518 | 133 | 117 |
# -*- coding: utf-8 -*-
"""
A - 9x9
https://atcoder.jp/contests/abc144/tasks/abc144_a
"""
import sys
def solve(A, B):
if 1 <= A <= 9 and 1 <= B <= 9:
return A * B
return -1
def main(args):
A, B = map(int, input().split())
ans = solve(A, B)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| a,b = map(int,input().split())
print(-1) if a > 9 or b > 9 else print(a*b) | 1 | 157,769,459,350,150 | null | 286 | 286 |
n,x,y = map(int,input().split())
ans = [0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
if i <= x and j >= y:
a = abs(j-i)-abs(y-x)+1
b = abs(i-x)+abs(j-y)+1
ans[min(a,b)] += 1
else:
c = abs(x-i)+abs(y-j)+1
d = abs(j-i)
ans[min(c,d)] += 1
for i in range(1,n):
print(ans[i])
| N,K = map(int,input().split())
H = sorted(map(int,input().split()))
count = N
for i in range(N):
if H[i]>=K:
count = i
break
print(N-count) | 0 | null | 111,515,535,099,750 | 187 | 298 |
n = int(input()) - 1
j = 0
ans = 0
for i in range(1, n):
j = i
while True:
j += 1
if i * j > n:
break
ans += 1
k = 1
er = 0
while True:
if k ** 2 > n:
break
er += 1
k += 1
print((ans * 2) + er) | import math
N = int(input())
MOD_VALUE = math.pow(10, 9) + 7
def pow_mod(value, pow):
ret = 1
for _ in range(pow):
ret = ret * value % MOD_VALUE
return ret
result = pow_mod(10, N) - pow_mod(9, N) * 2 + pow_mod(8, N)
print(int(result % MOD_VALUE))
| 0 | null | 2,907,375,074,190 | 73 | 78 |
import sys
import heapq
from collections import defaultdict
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def naa(N): return [na() for _ in range(N)]
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
N, K = na()
A_array = na()
cusum = 0
mod_array = [0]
for i, a in enumerate(A_array):
cusum = (cusum + a) % K
mod = (cusum + K - (i+1)) % K
mod_array.append(mod)
# print(mod_array)
ans = 0
mod_queue = []
cnt_dic = defaultdict(int)
for i, v in enumerate(mod_array):
heapq.heappush(mod_queue, (i, 1, v))
while(len(mod_queue)):
i, q, v = heapq.heappop(mod_queue)
if q == 1:
ans += cnt_dic[v]
cnt_dic[v] += 1
if i + K <= N:
heapq.heappush(mod_queue, (i+K-0.5, 2, v))
else:
cnt_dic[v] -= 1
# print(i, v, q, ans)
print(ans)
| H, W = map(int, input().split())
S = [input() for _ in range(H)]
vis = [[-1 for i in range(W)] for j in range(H)]
for v in range(H):
for h in range(W):
if v==0:
if h==0:
if S[v][h]=="#":
vis[v][h]=1
else:
vis[v][h]=0
else:
if S[v][h-1]=="." and S[v][h]=="#":
vis[v][h] = vis[v][h-1] + 1
else:
vis[v][h] = vis[v][h-1]
else:
if h==0:
if S[v-1][h]=="." and S[v][h]=="#":
vis[v][h] = vis[v-1][h] + 1
else:
vis[v][h] = vis[v-1][h]
else:
if S[v-1][h]=="." and S[v][h]=="#":
bufv = vis[v-1][h] + 1
else:
bufv = vis[v-1][h]
if S[v][h-1]=="." and S[v][h]=="#":
bufh = vis[v][h-1] + 1
else:
bufh = vis[v][h-1]
vis[v][h] = min(bufv, bufh)
#print(vis)
print(vis[H-1][W-1]) | 0 | null | 93,230,615,689,892 | 273 | 194 |
h,w = map(int,input().split())
grid = []
for _ in range(h):
grid.append(list(input()))
dp = [[0]*(w+1) for i in range(h+1)]
#dp[i][j] = i,jでの最小の操作回数
if grid[0][0] == '#':
dp[0][0] += 1
for i in range(1,h):
p = 0
if grid[i][0] == '#' and grid[i-1][0] == '.':
p += 1
dp[i][0] = dp[i-1][0] + p
for i in range(1,w):
p = 0
if grid[0][i] == '#' and grid[0][i-1] == '.':
p += 1
dp[0][i] = dp[0][i-1] + p
for x in range(1,h):
for y in range(1,w):
a,b = 0,0
if grid[x][y] == '#' and grid[x-1][y] == '.':
a += 1
if grid[x][y] == '#' and grid[x][y-1] == '.':
b += 1
dp[x][y] = min(dp[x-1][y] + a,dp[x][y-1] + b)
print(dp[h-1][w-1])
#print(dp) | from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
DP = [[10000]*w for _ in range(h)]
DP[0][0] = 0 if S[0][0]=='.' else 1
directs = [[0,1], [1,0]]
for hi in range(h):
for wi in range(w):
for dh,dw in directs:
if not (0<=hi+dh<h and 0<=wi+dw<w): continue
if S[hi][wi]=='.' and S[hi+dh][wi+dw]=='#':
DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi]+1)
else:
DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi])
print(DP[-1][-1]) | 1 | 48,952,295,332,490 | null | 194 | 194 |
def main():
import numpy as np
n,t=map(int,input().split())
F=[tuple(map(int,input().split())) for _ in range(n)]
F.sort(key=lambda x:x[0])
dp=np.zeros([n+1,t],dtype=np.int64)
for i in range(n):
a1=F[i][0]
b1=F[i][1]
dp[i+1][:a1]=dp[i][:a1]
dp[i+1][a1:]=np.maximum(dp[i][a1:],dp[i][:-a1]+b1)
ans=0
for i in range(n):
ans=max(ans,dp[i][-1]+F[i][1])
print(ans)
if __name__=='__main__':
main() | def main():
N = int(input())
result = []
while N > 0:
N -= 1
mod = N % 26
result.append(chr(mod + ord('a')))
N //= 26
result_str = ""
for i in range(len(result)-1, -1, -1):
result_str += result[i]
print(result_str)
main()
| 0 | null | 81,994,787,930,650 | 282 | 121 |
# -*- coding: utf-8 -*-
line = map(str, raw_input())
place = 0
area = 0
stack1 = []
stack2 = []
for i in line:
if i == '\\':
stack1.append(place)
elif i == '/':
if len(stack1) != 0:
j = stack1.pop()
s = place-j
area += s
while len(stack2) != 0:
if stack2[-1][0] <= j:
break
tmp = stack2.pop()
s += tmp[1]
stack2.append([j, s])
place += 1
print area
temp = []
for a in stack2:
temp.append(a[1])
if len(stack2) > 0:
print len(stack2),
print " ".join(map(str, temp))
else:
print len(stack2) | string = input()
s = []
total = 0
s2 = []
for i in range(len(string)):
if string[i] == '\\':
s.append(i)
elif string[i] == '/' and len(s) > 0:
j = s.pop() # j: 対応する '\' の位置
area = i - j # 面積
total += area
while len(s2) > 0 and s2[-1][0] > j: # s2[-1][0] == s2.pop()[0]
area += s2[-1][1]
s2.pop()
s2.append([j, area]) # j: 水たまりの左端 / tmp: その水たまりの面積
ans = []
for i in range(len(s2)):
ans.append(str(s2[i][1]))
print(total)
if len(ans) == 0:
print(len(ans))
else:
print(len(ans), end = ' ')
print(' '.join(ans))
| 1 | 57,870,107,460 | null | 21 | 21 |
main=list(map(int,input().split()))
k=int(input())
for i in range(k):
if(main[0]>=main[1]):
main[1]=main[1]*2
elif(main[1]>=main[2]):
main[2]=main[2]*2
if(main[1]>main[0] and main[2]>main[1]): print('Yes')
else: print('No') | a, b, c = map(int, input().split())
k = int(input())
flg = False
c = (2**k) * c
for i in range(k):
if a < b < c:
flg = True
break
b *= 2
c //= 2
if flg:
print('Yes')
else:
print('No')
| 1 | 6,975,261,674,820 | null | 101 | 101 |
import math
r = input()
area = r * r * math.pi * 1.0
cir = 2 * r * math.pi * 1.0
print '%f %f' % (area, cir) | import math
r = float(input())
pi =math.pi
print('%.10f %.10f'%(r*r*pi,2*r*pi))
| 1 | 651,358,509,760 | null | 46 | 46 |
N = input()
dp = [0, 1]
for n in N:
n = int(n)
dp[0], dp[1] = min(dp[0]+n, dp[1]+10-n), min(dp[0]+n+1, dp[1]+10-(n+1))
print(dp[0]) | from decimal import Decimal
'''
def main():
a, b = input().split(" ")
a = int(a)
b = Decimal(b)
print(int(a*b))
'''
def main():
a, b = input().split(" ")
a = int(a)
b = int(b.replace(".","") )
print(a*b // 100)
if __name__ == "__main__":
main() | 0 | null | 43,955,265,900,942 | 219 | 135 |
values = []
while True:
v = int(input())
if 0 == v:
break
values.append(v)
for i, v in enumerate(values):
print('Case {0}: {1}'.format(i + 1, v)) | for i in range(10000):
x = input()
if (int(x) == 0):
break
else:
print("Case " + str(i + 1) + ": " + x) | 1 | 483,988,515,890 | null | 42 | 42 |
from math import cos,pi
a, b, h, m = map(int, input().split())
rad = abs(m * pi / 30 - (h * 60 + m) * pi / 360)
ans = a ** 2 + b ** 2 - 2 * a * b * cos(rad)
print(ans ** 0.5)
| import numpy as np
a,b,h,m = map(int,input().split())
pos1 = [b*np.sin(np.radians(6*m)),b*np.cos(np.radians(6*m))]
pos2 = [a*np.sin(np.radians(30*h+m*(360/(12*60)))),a*np.cos((np.radians(30*h+m*(360/(12*60)))))]
d = ((pos1[0]-pos2[0])**2+(pos1[1]-pos2[1])**2)**0.5
print(d)
#print(pos1)
#print(pos2) | 1 | 20,130,233,690,340 | null | 144 | 144 |
N = '0' + input()
INF = float('inf')
dp = [[INF] * 2 for _ in range(len(N) + 1)]
dp[0][0] = 0
for i in range(len(N)):
n = int(N[len(N) - 1 - i])
for j in range(2):
for a in range(10):
ni = i + 1
nj = 0
b = a - n - j
if b < 0:
b += 10
nj = 1
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)
a == b
print(dp[len(N)][0])
| n = list(map(int, list(input())))
count = 0
n = n[::-1] + [0]
for idx, num in enumerate(n):
if num == 10:
n[idx+1] += 1
elif num == 5:
if n[idx+1] >= 5:
n[idx+1] += 1
count += 10 - num
else:
count += num
elif num <= 4:
count += num
else:
count += 10 - num
n[idx+1] += 1
print(count) | 1 | 71,076,635,527,340 | null | 219 | 219 |
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(m):
ans += a[i]
if n < ans:
print(-1)
else:
print(n-ans) | N, M = map(int, input().split())
a = list(map(int, input().split()))
homework = 0
for i in range(M):
homework += a[i]
play = N - homework
if play < 0:
print(-1)
else:
print(play) | 1 | 32,004,646,243,378 | null | 168 | 168 |
N,M = map(int,input().split())
H = list(map(int,input().split()))
L = [ list(map(int,input().split())) for i in range(M) ]
d = { k+1:True for k in range(N) }
for l in L :
if H[l[0]-1] <= H[l[1]-1] :
d[l[0]] = False
if H[l[0]-1] >= H[l[1]-1] :
d[l[1]] = False
ans = 0
for v in d.values() :
if v :
ans += 1
print(ans) | s = input()
print('x'*len(s)) | 0 | null | 49,181,879,780,380 | 155 | 221 |
def solve():
N = int(input())
A = [0] * (N + 1)
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
s = x * x + y * y + z * z + x * y + x * z + y * z
if s <= N:
A[s] += 1
for i in range(1, N + 1):
print(A[i])
solve() | K=int(input())
if K<=9:
print(K)
else:
p=1
dp,old=[[1]*10],[0,1]
n=9
while K>n:
old=dp[p-1]
tmp=[0]*10
for i in range(1,9):
tmp[i]=old[i-1]+old[i]+old[i+1]
tmp[9]=old[8]+old[9]
tmp[0]=old[0]+old[1]
dp.append(tmp)
p+=1
n+=sum(tmp[1:])
ans=0
n-=sum(tmp[1:])
K-=n
c=2
for i in range(p-1,-1,-1):
if c!=0:
c-=1
while K>dp[i][c]:
K-=dp[i][c]
c+=1
ans+=c*10**i
print(ans) | 0 | null | 24,130,447,513,470 | 106 | 181 |
from collections import defaultdict
N,p = map(int,input().split())
S = input()
S = S[::-1]
d = defaultdict(lambda:0)
r = 0
for i in range(N):
r += int(S[i])*pow(10,i,p)
r %= p
d[r] += 1
ans = 0
for r in d:
ans += d[r]*(d[r]-1)//2
ans += d[0]
if p==2 or p==5:
S = S[::-1]
ans = 0
for i in range(N):
if int(S[i])%p==0:
ans += i+1
print(ans) | def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
[n,p]=i2()
s=input()
if p==2 or p==5:
x1=0
for i in range(n):
if int(s[i])%p==0:
x1+=i+1
print(x1)
else:
t=0
x2=0
d={0:1}
a=1
for i in range(n)[::-1]:
t+=int(s[i])*a
t%=p
a*=10
a%=p
if t in d:
x2+=d[t]
d[t]+=1
else:
d[t]=1
print(x2) | 1 | 58,169,506,037,148 | null | 205 | 205 |
s = int(input())
t = h = 0
for _ in range(s):
tc, hc = input().split()
if tc == hc:
t += 1
h += 1
elif tc > hc :
t += 3
else:
h += 3
print(t, h) | n=int(input())
t_won=0
h_won=0
for _ in range(n):
t_wd,h_wd = input().split()
if t_wd > h_wd: t_won += 1
elif t_wd < h_wd: h_won += 1
print(t_won*3 + (n-t_won-h_won), h_won*3 + (n-t_won-h_won)) | 1 | 1,972,542,074,580 | null | 67 | 67 |
# アライグマはモンスターと戦っています。モンスターの体力はHです。
# アライグマはN種類の必殺技を使うことができ、i番目の必殺技を使うとモンスターの体力を Ai
# 減らすことができます。 必殺技を使う以外の方法でモンスターの体力を減らすことはできません。
# モンスターの体力を0以下にすればアライグマの勝ちです。
# アライグマが同じ必殺技を2度以上使うことなくモンスターに勝つことができるなら Yes を、
# できないなら No を出力してください。
H, N = map(int, input().split())
damege = map(int, input().split())
total_damege = sum(damege)
if H - total_damege <= 0:
print('Yes')
else:
print('No') | h, n = map(int, input().split())
a = [int(s) for s in input().split()]
a.sort(reverse=True)
ans = 'No'
for s in a:
h -= s
if h <= 0:
ans = 'Yes'
print(ans) | 1 | 77,716,736,161,030 | null | 226 | 226 |
K,N=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]+K-A[-1]
for i in range(N-1):
ans=max(ans,A[i+1]-A[i])
print(K-ans)
| k,n=map(int,input().split())
a=list(map(int,input().split()))
res=k-a[-1]+a[0]
for i in range(n-1):
res=max(res,abs(a[i]-a[i+1]))
print(k-res) | 1 | 43,332,994,321,532 | null | 186 | 186 |
import sys, math
input = sys.stdin.readline
MAX = 2e9
def merge(A, left, mid, right):
n1 = mid - left
n2 = right - mid
L = A[left:mid]
L.append(MAX)
R = A[mid:right]
R.append(MAX)
merged = []
index_L = 0
index_R = 0
comp_cnt = 0
for _ in range(n1+n2):
cand_L = L[index_L]
cand_R = R[index_R]
comp_cnt += 1
if (cand_L < cand_R):
merged.append(cand_L)
index_L += 1
else:
merged.append(cand_R)
index_R += 1
A[left:right] = merged
return comp_cnt
def merge_sort(A, left, right):
comp_cnt = 0
if (left + 1 < right):
# Devide
mid = (left + right) // 2
# Solve
_, cnt = merge_sort(A, left, mid)
comp_cnt += cnt
_, cnt = merge_sort(A, mid, right)
comp_cnt += cnt
# Conquer
comp_cnt += merge(A, left, mid, right)
return A, comp_cnt
def main():
N = int(input())
S = list(map(int, input().split()))
left = 0
right = len(S)
merged, cnt = merge_sort(S, left, right)
print(" ".join([str(x) for x in merged]))
print(cnt)
if __name__ == "__main__":
main()
| import copy
N = int(input())
testimony = []
for n in range(N):
A = int(input())
testimony.append({})
for a in range(A):
x, y = map(int, input().split())
testimony[n][x - 1] = y
def judge(truthy):
answer = True
for i in range(len(truthy)):
if truthy[i] == 1:
for t in testimony[i].keys():
if truthy[t] != testimony[i][t]:
answer = False
break
if not answer:
break
# print(answer, truthy)
return 0 if not answer else truthy.count(1)
def dfs(truthy, depth):
if N == depth:
return judge(truthy)
truth = copy.copy(truthy)
truth.append(1)
t = dfs(truth, depth + 1)
false = copy.copy(truthy)
false.append(0)
f = dfs(false, depth + 1)
return max(t, f)
print(dfs([], 0)) | 0 | null | 60,754,859,251,010 | 26 | 262 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int):
return [NO, YES][N in [i * j for i in range(1, 10) for j in range(i, 10)]]
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()
| data = set()
for i in range(1,10):
for j in range(1,10):
data.add(i*j)
if int(input()) in data:
print("Yes")
else:
print("No") | 1 | 160,176,450,623,828 | null | 287 | 287 |
import sys
n = int(input())
A=[[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
#0??§?????????
#[[[0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0]],
# [[0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0]],
# [[0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0]],
# [[0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0],
# [0 0 0 0 0 0 0 0 0 0]]]
#?£? Building = b
#??? Floor = f
#??? Room = r
#??° Number = num
for i in range(n):
b,f,r,num = input().strip().split()
A[int(b)-1][int(f)-1][int(r)-1]+=int(num)
for i in range(4):
for j in range(3):
print('',' '.join(map(str,A[i][j])))
if i!=3:
print('#'*20) | mod =10**9+7
n=int(input())
if n<2:exit(print(0))
elif n==2:exit(print(2))
ans = 10**n - 9**n*2 + 8**n
ans%=mod
print(ans) | 0 | null | 2,116,543,872,138 | 55 | 78 |
k = int(input())
from collections import deque
d = deque()
c = 0
for i in range(1, 10):
d.append(i)
while True:
tmp = d.popleft()
c += 1
if c == k:
ans = tmp
break
if tmp % 10 != 0:
d.append(tmp * 10 + (tmp % 10 - 1))
d.append(tmp * 10 + tmp % 10)
if tmp % 10 != 9:
d.append(tmp * 10 + (tmp % 10 + 1))
print(ans)
| K = int(input())
# 10桁までやれば十分
runrun_table = [[0 for _ in range(10)] for _ in range(10)]
# i桁のルンルン数の種類 <= 3**(i-1)*9
for i in range(10):
runrun_table[0][i] = 1
for keta in range(1, 10):
for i in range(10):
if i == 0:
runrun_table[keta][i] = runrun_table[keta - 1][i] + \
runrun_table[keta - 1][i + 1]
elif i == 9:
runrun_table[keta][i] = runrun_table[keta - 1][i - 1] + \
runrun_table[keta - 1][i]
else:
runrun_table[keta][i] = runrun_table[keta - 1][i - 1] + \
runrun_table[keta - 1][i] + \
runrun_table[keta - 1][i + 1]
keta = 0
ans = ''
while sum(runrun_table[keta][1:]) < K:
K -= sum(runrun_table[keta][1:])
keta += 1
for piv in range(1, 10):
if runrun_table[keta][piv] >= K:
ans += str(piv)
keta -= 1
break
K -= runrun_table[keta][piv]
while keta >= 0:
if piv == 0:
piv_range = [0, 1]
elif piv == 9:
piv_range = [8, 9]
else:
piv_range = range(piv-1, piv+2)
for piv in piv_range:
if runrun_table[keta][piv] >= K:
ans += str(piv)
keta -= 1
break
K -= runrun_table[keta][piv]
print(ans)
| 1 | 40,116,488,344,828 | null | 181 | 181 |
a, b, c = list(map(int, input().split()))
if a == b == c:
print('No')
elif a == b:
print('Yes')
elif b == c:
print('Yes')
elif a == c:
print('Yes')
else:
print('No')
| def main():
a, b, c = map(int, input().split())
if a == b == c:
print('No')
elif a != b and b != c and c != a:
print('No')
else:
print('Yes')
if __name__ == '__main__':
main() | 1 | 67,946,019,705,400 | null | 216 | 216 |
N = int(input())
ans = 1000*(1+(int)((N-1)/1000))-N
print(ans) | N = int(input())
amari = N % 1000
if amari == 0:
change = 0
else:
change = 1000 - amari
print(change) | 1 | 8,449,835,800,460 | null | 108 | 108 |
import math
N = int(input())
total = N/2*(N+1)
f = math.floor(N/3)
f = (3*f+3)*f/2
b = math.floor(N/5)
b = (5*b+5)*b/2
fb = math.floor(N/15)
fb = (15*fb+15)*fb/2
print(int(total-f-b+fb))
| # 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) | 1 | 34,766,217,654,808 | null | 173 | 173 |
# coding:utf-8
class Dice:
def __init__(self):
self.f = [0 for i in range(6)]
def roll_z(self): self.roll(1,2,4,3)
def roll_y(self): self.roll(0,2,5,3)
def roll_x(self): self.roll(0,1,5,4)
def roll(self,i,j,k,l):
t = self.f[i]; self.f[i] = self.f[j]; self.f[j] = self.f[k]; self.f[k] = self.f[l]; self.f[l] = t
def move(self,ch):
if ch == 'E':
for i in range(3):
self.roll_y()
if ch == 'W':
self.roll_y()
if ch == 'N':
self.roll_x()
if ch == 'S':
for i in range(3):
self.roll_x()
dice = Dice()
dice.f = map(int, raw_input().split())
com = raw_input()
for i in range(len(com)):
dice.move(com[i])
print dice.f[0]
| def north(d):
return [d[1], d[5], d[2], d[3], d[0], d[4]]
def east(d):
return [d[3], d[1], d[0], d[5], d[4], d[2]]
def south(d):
return [d[4], d[0], d[2], d[3], d[5], d[1]]
def west(d):
return [d[2], d[1], d[5], d[0], d[4], d[3]]
numbers = list(map(int, input().split()))
directions = list(input())
for d in directions:
if d == "N":
numbers = north(numbers)
elif d == "E":
numbers = east(numbers)
elif d == "S":
numbers = south(numbers)
elif d == "W":
numbers = west(numbers)
print(numbers[0]) | 1 | 225,780,873,498 | null | 33 | 33 |
n = input()
s1 = []
s2 = []
for i in range(len(n)):
if n[i] == '\\':
s1.append(i)
elif n[i] == '/' and len(s1) > 0:
a = s1.pop(-1)
s2.append([a, i - a])
i = 0
while len(s2) > 1:
if i == len(s2) - 1:
break
elif s2[i][0] > s2[i + 1][0]:
s2[i + 1][1] += s2.pop(i)[1]
i = 0
else:
i += 1
s = []
total = 0
for i in s2:
s.append(str(int(i[1])))
total += int(i[1])
print(total)
if len(s2) == 0:
print('0')
else:
print('{} {}'.format(len(s2), ' '.join(s)))
| def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
A = list(map(int, A.split(" ")))
change_count = 0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
if i != minj:
#A[i] と A[minj] を交換
tmp = A[i]
A[i] = A[minj]
A[minj] = tmp
change_count+=1
# 回答
print(" ".join(map(str,A)))
print(change_count)
#return True
# 入力
N = int(input()) # 数列の長さを表す整数(N)
A = input("") # N個の整数が空白区切り
selectionSort(A,N)
| 0 | null | 39,460,817,248 | 21 | 15 |
string = list(input())
times = int(input())
#a = [int(i) for i in range(0,5)]
#print(a)
for i in range(times):
order = input().split()
#print(order)
if order[0] == "replace":
replace_string = order[3]
#print(string)
count = 0
for j in range(int(order[1]), int(order[2]) + 1):
string[j] = replace_string[count]
count += 1
#print(count)
#print(string)
elif order[0] == "reverse":
#print(string)
reverse_string = string[int(order[1]):int(order[2]) + 1]
reverse_string.reverse()
#for j in range(int(order[1]), int(order[2]) + 1):
# string[j] = reverse_string[j]
string = string[:int(order[1])] + reverse_string + string[int(order[2])+1:]
#print(j)
#print(string)
#string[int(order[1]):int(order[2]) + 1].reverse()
#print(string)
#string[int(order[1]):int(order[2])] = string[int(order[1]):int(order[2])].reverse()
elif order[0] == "print":
#print(string)
print("".join(string[int(order[1]):int(order[2]) + 1]))
#print(string) | letters = input()
num = int(input())
for i in range(num):
order = input().split()
a = int(order[1])
b = int(order[2])
if order[0] == 'print':
print(letters[a:b+1])
if order[0] == 'reverse':
p = letters[a:b+1]
p = p[::-1]
letters = letters[:a] + p + letters[b+1:]
if order[0] == 'replace':
letters = letters[:a] + order[3] + letters[b+1:]
| 1 | 2,104,467,065,470 | null | 68 | 68 |
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
x=sum(a)%mod
y=0
for i in range(n):
y+=a[i]**2
y%=mod
z=pow(2,mod-2,mod)
print(((x**2-y)*z)%mod) | n = int(input())
lst = list(map(int, input().split()))
mod = 10**9+7
# 累積和(Cumulative sum)リストの作成
cumsum = [0]*(n+1)
for i in range(n):
cumsum[i+1] = lst[i] + cumsum[i]
# 題意より、lst の1つ前までが対象
ans = 0
for i in range(n-1):
ans += (cumsum[n] - cumsum[i+1]) * lst[i]
print(ans % mod)
| 1 | 3,838,703,084,790 | null | 83 | 83 |
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
mon=1000
stk=0
for i in range(n-1):
if A[i]<=A[i+1]:
stk+=mon//A[i]
mon%=A[i]
else:
mon+=stk*A[i]
stk=0
mon+=stk*A[-1]
print(mon) | n = int(input())
a = list(map(int, input().split()))
dp = [0]*(n+1)
dp[0] = 1000
for i in range(1, n):
dp[i] = dp[i-1]
for j in range(i):
stock = dp[j]//a[j]
cost = dp[j]+(a[i]-a[j])*stock
dp[i] = max(dp[i], cost)
print(dp[n-1])
| 1 | 7,276,834,833,532 | null | 103 | 103 |
def qsort(l):
if l == []: return []
else:
pv = l[0]
left = []
right = []
for i in range(1, len(l)):
if l[i] > pv:
left.append(l[i])
else:
right.append(l[i])
left = qsort(left)
right = qsort(right)
left.append(pv)
return left + right
def main():
lst = []
for i in range(0, 10):
lst.append(int(raw_input()))
lst = qsort(lst)
for i in range(0, 3):
print(lst[i])
main() | list1=[]
for i in range(10):
list1.append(int(input()))
list1=sorted(list1)
list1.reverse()
for i in range(3):
print(list1[i]) | 1 | 38,466,340 | null | 2 | 2 |
while True:
try:
a = raw_input()
temp = a.split()
x = int(temp[0]) + int(temp[1])
c = str(x)
print len(c)
except:
break | W, H, x, y, r = map(int, input().split(' '))
# 高さ
if (r <= y <= (H - r)) and (r <= x <= (W - r)):
print('Yes')
else:
print('No')
| 0 | null | 232,989,657,658 | 3 | 41 |
from operator import itemgetter
n = int(input())
s = []
for i in range(n):
l = list(map(int, input().split()))
rang = [l[0] - l[1], l[0] + l[1]]
s.append(rang)
s_sort = sorted(s, key=itemgetter(1))
ans = 0
last = -float("inf")
for i in range(n):
if last <= s_sort[i][0]:
ans += 1
last = s_sort[i][1]
print(ans)
| N = int(input())
robot = []
ans = 0
for i in range(N):
x,l = map(int,input().split())
robot.append([x+l,x-l])
robot.sort()
cur = -float('inf')
for i in range(N):
if cur <= robot[i][1]:
ans += 1
cur = robot[i][0]
print(ans) | 1 | 89,962,636,075,040 | null | 237 | 237 |
N=int(input())
A=0
for i in range(1,N+1):
if i%3!=0 and i%5!=0:
A=A+i
print(int(A)) | def resolve():
n = int(input())
ans = 0
for i in range(1,n+1):
if i%3!=0 and i%5!=0:
ans += i
print(ans)
resolve() | 1 | 35,018,512,721,510 | null | 173 | 173 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.