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
|
---|---|---|---|---|---|---|
while True:
input = raw_input()
if input == "0":
break
sum = 0
for i in xrange(len(input)):
sum += int(input[i])
print sum | import itertools
while True:
n,x=map(int,input().split())
if n==0 and x==0:
break
z=list(range(1,n+1))
a=list(itertools.combinations(z,3))
b=[]
for i in a:
b+=[sum(i)]
print(b.count(x)) | 0 | null | 1,443,634,714,870 | 62 | 58 |
N, X, M = map(int, input().split())
tmp = X
seq = []
ans = 0
for i in range(N):
if X in seq:
break
seq.append(X)
X = (X ** 2) % M
ans = sum(seq[:min(N, len(seq))])
N -= len(seq)
if N < 1:
print(ans)
exit()
i = seq.index(X)
l = len(seq) - i
ans += sum(seq[i:]) * (N//l)
N %= l
ans += sum(seq[i:i+N])
print(ans)
| import itertools
for i,j in itertools.product(xrange(1,10),repeat=2):
print '{0}x{1}={2}'.format(i,j,i*j) | 0 | null | 1,398,165,624,868 | 75 | 1 |
a,b=map(int,input().split())
print(a*b if a<10 and b<10 else '-1') | import math
X = int(input())
year = 0
amount = 100
while True:
if amount >= X:
break
amount += math.floor(amount//100)
year += 1
print(year) | 0 | null | 93,100,943,583,790 | 286 | 159 |
late = input()
i = int(late)
if i >= 400 and i <= 599:
print("8")
if i >= 600 and i <= 799:
print("7")
if i >= 800 and i <= 999:
print("6")
if i >= 1000 and i <= 1199:
print("5")
if i >= 1200 and i <= 1399:
print("4")
if i >= 1400 and i <= 1599:
print("3")
if i >= 1600 and i <= 1799:
print("2")
if i >= 1800 and i <= 1999:
print("1")
| K = int(input())
n = 7
c = 0
while c <= K:
n %= K
c += 1
if n == 0:
print(c)
exit()
n = n * 10 + 7
print(-1) | 0 | null | 6,399,235,594,400 | 100 | 97 |
n,x,m=map(int,input().split())
l,s=[0]*m,[0]*m
t=p=0
while l[x]<1:
t+=1
l[x]=t
s[x]=s[p]+x
p=x
x=p*p%m
k=l[x]
d,m=divmod(n-k,t+1-k)
print((s[p]+x-s[x])*d+s[l.index(k+m)]) | # B - Roller Coaster
# N K
N, K = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=N)))
answer = 0
for i in range(0, N):
if my_list[i] >= K:
answer += 1
print(answer)
| 0 | null | 91,169,546,013,312 | 75 | 298 |
a=input("")
lista=a.split()
lista2=[]
par=0
impar=-1
contador=0
for i in range (int(lista[0])):
par+=2
lista2.append(par)
for i in range (int(lista[1])):
impar+=2
lista2.append(impar)
longitud=len(lista2)-1
for i in range (0,len(lista2)):
b=i
while True:
if b+1>longitud:
break
else:
suma=lista2[i]+lista2[b+1]
b=b+1
if suma%2==0:
contador+=1
print(contador)
| n = int(input())
S,T = input().split()
result = ''
for s,t in zip(S,T):
result += s
result += t
print(result) | 0 | null | 79,122,527,206,910 | 189 | 255 |
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#print(s)
c=0
for i in t:
if i in s:
c+=1
print(c)
"""
"""
n=int(input())
s=[int(x) for x in input().split()]
q=int(input())
t=[int(x) for x in input().split()]
#binary search
a=0
for i in range(q):
L=0
R=n-1#探索する方の配列(s)はソート済みでないといけない
while L<=R:
M=(L+R)//2
if s[M]<t[i]:
L=M+1
elif s[M]>t[i]:
R=M-1
else:
a+=1
break
print(a)
"""
#Dictionary
#dict型オブジェクトに対しinを使うとキーの存在確認になる
n=int(input())
d={}
for i in range(n):
command,words=input().split()
if command=='find':
if words in d:
print('yes')
else:
print('no')
else:
d[words]=0
| def is_palindrome(s):
return s == s[::-1]
def main():
s = "-" + input()
n = len(s) - 1
if (
is_palindrome(s[1:])
and is_palindrome(s[1 : (n - 1) // 2 + 1])
and is_palindrome(s[(n + 3) // 2 : n + 1])
):
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 0 | null | 23,183,833,967,210 | 23 | 190 |
num_list = []
while True:
values = [int(x) for x in input().split()]
if 0 == values[0] and 0 == values[1]:
break
num_list.append(values)
for n, t in num_list:
ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1))
cnt = 0
for x in ret.split():
if str(t) == x:
cnt += 1
print(cnt) | while True:
N,X = map(int,input().split())
if N == 0 and X == 0:
break
ans = 0
for a in range(1,N+1):
for b in range(1,N+1):
if b <= a:
continue
c = X-(a+b)
if c > b and c <= N:
ans += 1
print("%d"%(ans))
| 1 | 1,288,672,823,298 | null | 58 | 58 |
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(read())
odd = 0
for n in range(N):
n += 1
if n%2==1:
odd += 1
print(odd/N) | N = int(input())
O = [i for i in range(1, N+1) if i % 2 == 1]
print(len(O) / N) | 1 | 177,552,465,581,460 | null | 297 | 297 |
X, Y = map(int, input().split())
P = 10 ** 9 + 7
N = (X+Y) // 3
R = (2 * X - Y) // 3
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N+1):
fact.append((fact[-1] * i) % P)
inv.append((-inv[P % i] * (P//i) % P))
factinv.append((factinv[-1] * inv[-1] % P))
def cmb_mod(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n-r)
return fact[n] * factinv[r] * factinv[n-r] % p
if (X+Y) % 3 != 0:
print(0)
else:
print(cmb_mod(N, R, P))
| X,Y=map(int,input().split())
MOD=10**9+7
def modinv(a):
return pow(a,MOD-2,MOD)
x=(2*Y-X)//3
y=(2*X-Y)//3
if (2*Y-X)%3!=0 or (2*X-Y)%3!=0 or x<0 or y<0:
print(0)
else:
r=1
n=x+y
k=min(x,y)
for i in range(k):
r*=(n-i)
r*=modinv(i+1)
r%=MOD
print(r)
| 1 | 150,372,678,687,112 | null | 281 | 281 |
#入力:N,M(int:整数)
def input2():
return map(str,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
s,t=input2()
print("{}{}".format(t,s)) | b,a = input().split()
print(a + b) | 1 | 102,766,901,306,692 | null | 248 | 248 |
#!/usr/bin/python3
#coding: utf-8
S = input()
ret = 0
# 山を下る
i = 0
while i < len(S) and S[i] == ">":
i += 1
ret += i
# 山を登って降りる
n_up = 0
n_down = 0
while i < len(S):
n_up = 0
n_down = 0
while i < len(S) and S[i] == "<":
n_up += 1
i += 1
if i >= len(S):
break
while i < len(S) and S[i] == ">":
n_down += 1
i += 1
if i >= len(S):
break
if n_up < n_down:
n_up, n_down = n_down, n_up
ret += ((n_up+1) * n_up) // 2
ret += (n_down * (n_down-1)) // 2
print(ret) | S = input()
N = len(S)+1
x = [0 for _ in range(N)]
l = 0
while(l<N-1):
r = l+1
while(r<N-1 and S[r]==S[l]):
r += 1
if S[l]=='<':
x[l] = 0
for i in range(l+1, r+1):
x[i] = max(x[i], x[i-1]+1)
else:
x[r] = 0
for i in range(r-1, l-1, -1):
x[i] = max(x[i], x[i+1]+1)
l = r
print(sum(x)) | 1 | 156,668,687,691,600 | null | 285 | 285 |
n,m = map(int,input().split())
s = input()
now = n
ans_rev = []
while(now != 0):
for i in range( max(0,now-m),now+1):
if(i == now):
print(-1)
exit()
if(s[i] == '1'):
continue
ans_rev.append(now - i)
now = i
break
print(' '.join(map(str, ans_rev[::-1]))) | import sys
import math
# a != b のとき
def count(a, b, N):
keta = len(str(N))
cnt = 0
# k == 1 なら a == b
if a == b:
cnt += 1 if a <= N else 0
if keta == 1:
return cnt
# k == 2 なら ba のみ
if keta == 2:
cnt += 1 if b * 10 + a <= N else 0
return cnt
# k 桁より少ない数の場合 : 好きな数を間に挟む
for k in range(2, keta):
cnt += 10**(k - 2)
# k 桁の数字の場合
s = N // (10**(keta - 1))
t = N % 10
if b > s:
return cnt
elif b < s:
cnt += 10**(keta - 2)
else:
tempN = (N - s * (10**(keta - 1)) - t) // 10
# print(f"tempN {tempN}")
cnt += (tempN + 1) # tempN が 1 なら 0,1 を選べる
if a > t:
cnt -= 1
return cnt
def count_aa(a, N):
keta = len(str(N))
cnt = 0
# keta == 1
if keta == 1:
return 1 if a <= N[-1] else 0
cnt += 1 # a
# k == 2 なら aa のみ
if keta == 2:
return cnt + 1 if a <= N[-1] else 0
# 3桁以上
# k 桁より少ない数の場合
for k in range(2, keta):
cnt += 10**(k - 2)
# k 桁の数字の場合
s = N // (10**(keta - 1))
t = N % 10
if b > s:
return cnt
elif b < s:
cnt += 10**(keta - 2)
else:
tempN = (N - s * (10**(keta - 1)) - t) // 10
# print(f"tempN {tempN}")
cnt += (tempN + 1) # tempN が 1 なら 0,1 を選べる
if a > t:
cnt -= 1
return cnt
N = int(input())
c = 0
for i in range(1,N+1):
a = int(str(i)[0])
b = i % 10
# print(a,b)
if b == 0:
continue
c += count(a,b,N)
print(c) | 0 | null | 113,266,834,246,720 | 274 | 234 |
#!/usr/bin/env python3
import sys
def solve(A: int, B: int):
print(A*B)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
A = int(next(tokens)) # type: int
B = int(next(tokens)) # type: int
solve(A, B)
if __name__ == '__main__':
main()
| arr = list(map(int,input().split()))
print(int(arr[0])*int(arr[1])) | 1 | 15,774,270,728,450 | null | 133 | 133 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
N = I()
ans = 0
for a in range(1, 10**3+1):
if a ** 2 >= N:
continue
b_num = N // a - a
if a * (N // a) == N:
b_num -= 1
ans += b_num
ans *= 2
ans += int(math.sqrt(N))
if int(math.sqrt(N)) ** 2 == N:
ans -= 1
print(ans)
main()
| import sys
input = sys.stdin.readline
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 -self.parents[self.find(x)]
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return -self.parents[self.find(x)]
def main():
N, M = map(int, input().split())
uf = UnionFind(N+1)
ans = 1
if M == 0:
print(ans)
return
for i in range(M):
x, y = map(int, input().split())
ans = max(uf.union(x,y), ans)
print(ans)
if __name__ == '__main__':
main() | 0 | null | 3,252,928,393,792 | 73 | 84 |
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
class SegmentTree(object):
def __init__(self, A, dot, unit):
n = 1 << (len(A) - 1).bit_length()
tree = [unit] * (2 * n)
for i, v in enumerate(A):
tree[i + n] = v
for i in range(n - 1, 0, -1):
tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
self._n = n
self._tree = tree
self._dot = dot
self._unit = unit
def __getitem__(self, i):
return self._tree[i + self._n]
def update(self, i, v):
i += self._n
self._tree[i] = v
while i != 1:
i >>= 1
self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])
def add(self, i, v):
self.update(i, self[i] + v)
def sum(self, l, r):
l += self._n
r += self._n
l_val = r_val = self._unit
while l < r:
if l & 1:
l_val = self._dot(l_val, self._tree[l])
l += 1
if r & 1:
r -= 1
r_val = self._dot(self._tree[r], r_val)
l >>= 1
r >>= 1
return self._dot(l_val, r_val)
def resolve():
n = int(input())
trees = [[0] * n for _ in range(26)]
character = [None] * n
for i, c in enumerate(input()):
c = ord(c) - ord('a')
character[i] = c
trees[c][i] = 1
for i in range(26):
trees[i] = SegmentTree(trees[i], max, 0)
for _ in range(int(input())):
q, *A = input().split()
if q == '1':
i, c = A
i = int(i) - 1
c = ord(c) - ord('a')
trees[character[i]].update(i, 0)
character[i] = c
trees[c].update(i, 1)
else:
l, r = map(int, A)
l -= 1
print(sum(trees[i].sum(l, r) for i in range(26)))
resolve() | if __name__ == '__main__':
A = list(map(int,input().split()))
print(A.index(0)+1) | 0 | null | 37,951,931,998,976 | 210 | 126 |
from collections import deque
k = int(input())
q = deque([])
for i in range(1, 10):
q.append(i)
cnt = 0
while cnt < k:
s = q.popleft()
cnt += 1
t = s % 10
if t != 0:
q.append(10 * s + (t - 1))
q.append(10 * s + t)
if t != 9:
q.append(10 * s + (t + 1))
print(s)
| from collections import deque
K = int(input())
queue = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
lunlun = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
while len(queue) < 10 ** 5:
n_str = queue.popleft()
last_c = n_str[len(n_str) - 1]
if last_c == "0":
queue.append(n_str + "0")
queue.append(n_str + "1")
lunlun.append(n_str + "0")
lunlun.append(n_str + "1")
elif last_c == "1":
queue.append(n_str + "0")
queue.append(n_str + "1")
queue.append(n_str + "2")
lunlun.append(n_str + "0")
lunlun.append(n_str + "1")
lunlun.append(n_str + "2")
elif last_c == "2":
queue.append(n_str + "1")
queue.append(n_str + "2")
queue.append(n_str + "3")
lunlun.append(n_str + "1")
lunlun.append(n_str + "2")
lunlun.append(n_str + "3")
elif last_c == "3":
queue.append(n_str + "2")
queue.append(n_str + "3")
queue.append(n_str + "4")
lunlun.append(n_str + "2")
lunlun.append(n_str + "3")
lunlun.append(n_str + "4")
elif last_c == "4":
queue.append(n_str + "3")
queue.append(n_str + "4")
queue.append(n_str + "5")
lunlun.append(n_str + "3")
lunlun.append(n_str + "4")
lunlun.append(n_str + "5")
elif last_c == "5":
queue.append(n_str + "4")
queue.append(n_str + "5")
queue.append(n_str + "6")
lunlun.append(n_str + "4")
lunlun.append(n_str + "5")
lunlun.append(n_str + "6")
elif last_c == "6":
queue.append(n_str + "5")
queue.append(n_str + "6")
queue.append(n_str + "7")
lunlun.append(n_str + "5")
lunlun.append(n_str + "6")
lunlun.append(n_str + "7")
elif last_c == "7":
queue.append(n_str + "6")
queue.append(n_str + "7")
queue.append(n_str + "8")
lunlun.append(n_str + "6")
lunlun.append(n_str + "7")
lunlun.append(n_str + "8")
elif last_c == "8":
queue.append(n_str + "7")
queue.append(n_str + "8")
queue.append(n_str + "9")
lunlun.append(n_str + "7")
lunlun.append(n_str + "8")
lunlun.append(n_str + "9")
elif last_c == "9":
queue.append(n_str + "8")
queue.append(n_str + "9")
lunlun.append(n_str + "8")
lunlun.append(n_str + "9")
print(lunlun[K-1])
| 1 | 40,138,671,787,632 | null | 181 | 181 |
N = int(input())
A = list(map(int, input().split()))
ans = float('inf')
sum_A = sum(A)
CumSum = 0
for i in range(N-1):
CumSum = CumSum + A[i]
ans = min(ans,(abs((sum_A - CumSum)-(CumSum))))
print(ans)
| N = int(input())
ans = 1
*a, = map(int, input().split())
mod = 10**9+7
l = [[0,0,0] for _ in range(N+1)]
r, g, b = 0, 0, 0
for i, j in enumerate(a):
if i:
if j==0:
if g==0:
g += 1
else:
b += 1
else:
if r==j:
r += 1
elif g==j:
g += 1
elif b==j:
b += 1
else:
r += 1
l[i+1][0] = r
l[i+1][1] = g
l[i+1][2] = b
ans = 1
for i,j in zip(a, l):
ans *= j.count(i)
ans %= mod
print(ans) | 0 | null | 135,706,472,793,178 | 276 | 268 |
N = int(input())
S = input()
if N % 2 == 1:
print("No")
exit()
T_len = int(N / 2)
T1 = S[:T_len]
T2 = S[T_len:]
if T1 == T2:
print("Yes")
else:
print("No") | 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]) | 0 | null | 95,593,877,724,070 | 279 | 187 |
s, w = [int(i) for i in input().split()]
ans = 'safe' if s > w else 'unsafe'
print(ans) | sheep, wolves = map(int, input().split())
if sheep > wolves:
print("safe")
elif sheep <= wolves:
print("unsafe") | 1 | 29,005,405,718,392 | null | 163 | 163 |
n, m = list(map(int, input().split()))
mat = [list(map(int, input().split())) for _ in range(n)]
vec = [int(input()) for _ in range(m)]
for v in mat:
print(sum(a * b for a, b in zip(v, vec))) | n, m = map(int, input().split())
m2 = m
A = [list(map(int,input().split())) for i in range(n)]
b=[]
while m2 > 0:
b_data = int(input())
b.append(b_data)
m2 = m2-1
for i in range(0,n):
c = 0
for j in range(0,m):
c = c + (A[i][j] * b[j])
print(c)
| 1 | 1,175,908,926,840 | null | 56 | 56 |
K=int(input())
A,B=map(int,input().split())
for i in range(1,1000):
if K * i > 1000:
break
if K * i >= A and K * i <=B:
print('OK')
exit()
print('NG') | N = int(input())
A,B=map(int,input().split())
Na = N
while N <= 1000:
if A <= N and N <= B:
print("OK")
break
N = N+Na
if N>1000:
print("NG") | 1 | 26,548,428,318,720 | null | 158 | 158 |
import sys
array = list(map(int,input().split()))
if not ( 1 <= min(array) and max(array) <= 100 ): sys.exit()
check = lambda x: isinstance(x,int)
print(array[2],array[0],array[1]) | # n, k = map(int, input().split())
# from collections import OrderedDict
# d = OrderedDict()
# a = list(input().split())
b = list(map(int, input().split()))
# print(r + max(0, 100*(10-n)))
# print("Yes" if 500*n >= k else "No")
# s = input()
# a = int(input())
# b = int(input())
# c = int(input())
# s = input()
print(b[-1], *b[:2]) | 1 | 38,124,022,662,820 | null | 178 | 178 |
n, k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*n
i=0
cnt=0
while l[i]==0:
l[i] = a[i]
i = a[i]-1
cnt += 1
start = i+1
i = 0
pre = 0
while i+1!=start:
i = a[i]-1
pre += 1
loop = cnt-pre
if pre+loop<k:
k=(k-pre)%loop+pre
i = 0
for _ in range(k):
i = a[i]-1
print(i+1) | n, k = map(int, input().split())
a = list(map(int, input().split()))
d = [[-1] * n for _ in range(70)]
for i in range(n):
d[0][i] = a[i] - 1
for i in range(1, 70):
for j in range(n):
d[i][j] = d[i - 1][d[i - 1][j]]
dst = 0
while k:
i = 70
while pow(2, i) & k <= 0:
i -= 1
dst = d[i][dst]
k -= pow(2, i)
print(dst + 1)
| 1 | 22,716,140,004,580 | null | 150 | 150 |
def how_many_ways(n, x):
ways = 0
for i in range(1, n-1):
for j in range(i+1, n):
for k in range(j+1, n+1):
if i+j+k == x:
ways += 1
return ways
def main():
while True:
n, x = [int(x) for x in input().split()]
if n == x == 0:
break
print(how_many_ways(n, x))
if __name__ == '__main__':
main()
| while True:
[n, m] = [int(x) for x in raw_input().split()]
if [n, m] == [0, 0]:
break
hoge = range(1, n + 1)
data = []
for x in range(n - 1, 1, -1):
for y in range(x - 1, 0, -1):
for z in range(y - 1, -1, -1):
# print((x, y, z))
s = hoge[x] + hoge[y] + hoge[z]
if s < m:
break
if s == m:
data.append(s)
print(len(data)) | 1 | 1,284,287,773,070 | null | 58 | 58 |
N,K = map(int,input().split())
min = N%K
if min>abs(min-K):
min = abs(min-K)
print (min) | s = input()
n = len(s)
n2 = (n+1)//2
for i in range(n):
if(s[i] != s[n-i-1]):
print("No")
exit()
for i in range((n-1)//2):
if(s[i] != s[n2-2-i]):
print("No")
exit()
if(s[n2+i] != s[n-i-1]):
print("No")
exit()
print("Yes") | 0 | null | 43,086,435,478,180 | 180 | 190 |
import math
a = 100000
for n in range(int(input())):
a = math.ceil(a*105/100000)*1000
print(int(a)) | import math
N=int(input())
def era(n):
prime=[]
furui=list(range(2,n+1))
while furui[0]<math.sqrt(n):
prime.append(furui[0])
furui=[i for i in furui if i%furui[0]!=0]
return prime+furui
furui=era(10**6+7)
minfac=list(range(10**6+8))
for i in furui:
for j in range(i,(10**6+7)//i+1):
if minfac[i*j]==i*j:
minfac[i*j]=i
ans=0
for i in range(1,N):
temp=1
temp2=1
l=1
while i != 1:
if minfac[i]!=l:
temp*=temp2
temp2=2
else:
temp2+=1
l=minfac[i]
i//=l
temp*=temp2
ans+=temp
print(ans) | 0 | null | 1,287,649,311,538 | 6 | 73 |
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N = readline().decode().rstrip()
K = int(readline())
L = len(N)
# 桁DP
dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(L+1)]
dp[0][0][0] = 1
for i in range(L):
for j in range(4):
for k in range(2):
nd = int(N[i])
for d in range(10):
ni = i + 1; nj = j; nk = k
if d != 0:
nj += 1
if nj > K:
continue
if k == 0:
if d > nd:
continue
if d < nd:
nk = 1
dp[ni][nj][nk] += dp[i][j][k]
print(dp[L][K][0]+dp[L][K][1]) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
"""
"""
def warshall_floyd(d):
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j],d[i][k] + d[k][j])
return d
n,m,l = LI()
dist = [[inf]*n for _ in range(n)]
dist2 = [[inf]*n for _ in range(n)]
for i in range(n):
dist[i][i] = 0
dist2[i][i] = 0
for _ in range(m):
a,b,c = LI()
dist[a-1][b-1] = c
dist[b-1][a-1] = c
dist = warshall_floyd(dist)
for i in range(n):
for j in range(n):
if dist[i][j] > l:
dist2[i][j] = inf
else:
dist2[i][j] = 1
dist2 = warshall_floyd(dist2)
q = I()
ans = []
for _ in range(q):
s,t = LI()
if dist2[s-1][t-1] == inf:
print(-1)
else:
print(dist2[s-1][t-1]-1)
| 0 | null | 124,518,038,685,492 | 224 | 295 |
N=int(input())
coins = [100,101,102,103,104,105]
dp = [int(i%coins[0]==0) for i in range(N+1)]
for coin in coins[1:]:
for i in range(coin,N+1):
dp[i] += dp[i - coin]
if dp[-1] != 0:
print(1)
else:
print(0) | n = int(input())
li1 = list(map(int,input().split()))
m = int(input())
li2 = list(map(int,input().split()))
cnt = 0
for i in li2:
if i in li1:
cnt +=1
print(cnt) | 0 | null | 63,934,637,420,188 | 266 | 22 |
while True:
try:
m,f,r = map(int,input().split(" "))
if m == -1:
if f == -1:
if r == -1:
break
if m == -1 or f == -1:
print("F")
continue
if m+f >= 80:
print("A")
if m+f >= 65 and m+f < 80:
print("B")
if m+f >= 50 and m+f < 65:
print("C")
if m+f >= 30 and m+f < 50:
if r >= 50:
print("C")
else:
print("D")
if m+f < 30:
print("F")
except EOFError:
break | #coding:utf-8
m = 0
f = 0
r = 0
while m + f + r >-3:
m , f, r =[int(i) for i in input().rstrip().split(" ")]
if m+f+r == -3:
break
if m == -1:
print("F")
elif f == -1:
print("F")
elif m+f <30:
print("F")
elif m+f <50:
if r>=50:
print("C")
else:
print("D")
elif m+f <65:
print("C")
elif m+f <80:
print("B")
else:
print("A") | 1 | 1,219,272,009,286 | null | 57 | 57 |
b = input()
if b.islower():
print("a")
else:
print("A") | c = input()
if c == c.lower():
print('a')
else:
print('A')
| 1 | 11,305,280,558,038 | null | 119 | 119 |
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline
sys.setrecursionlimit(500005)
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().rstrip()
n = ri()
a = rl()
N = 1000000
f = [0] * (N + 10)
for v in a:
f[v] += 1
for i in range(N, 0, -1):
if f[i] == 0:
continue
j = i * 2
while j <= N:
f[j] += f[i]
j += i
cnt = sum(f[i] == 1 for i in a)
print(cnt)
| N = int(input())
A = list(map(int, input().split()))
# ex. 24 11 8 3 16
A.sort()
# ex. 3 8 11 16 24
cnt = 0
# Aの最大値が24なら25個用意する感じ
# indexと考える値を一致させて分かりやすくしている
# Trueで初期化
# 最後のインデックスはA[-1]
dp = [True] * (A[-1] + 1)
# エラトステネスの篩っぽいやつ
for i in range(N):
if dp[A[i]] == True:
# dp[A[i]], dp[2*A[i]], dp[3*A[i]],...をFalseにする
for j in range(A[i], A[-1] + 1, A[i]):
dp[j] = False
if i < N - 1:
# 次も同じ数字が存在するなら数えない、なぜならお互いに割れてしまって題意を満たさないから
# 次以降に出てくる同じ数字は既にFalseになっているのでもう走査する事はない
if A[i] != A[i + 1]:
cnt += 1
# i=N-1の時は次がないので無条件でcntを増やす
# elseの方が良さそうだが明示的にするためにelifを使った
elif i == N - 1:
cnt += 1
print(cnt)
| 1 | 14,396,047,310,040 | null | 129 | 129 |
def make_bit(n):
bit = []
for i in range(2**n):
bit.append(bin(i)[2::])
i = 0
while i < len(bit):
while len(bit[i]) < len(bin(2**n-1)[2::]):
bit[i] = "0" + bit[i]
i += 1
return bit
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
h_pats = make_bit(h)
w_pats = make_bit(w)
ans = 0
for h_pat in h_pats:
for w_pat in w_pats:
cnt = 0
for i in range(h):
for j in range(w):
if h_pat[i] == "1" or w_pat[j] == "1":
continue
if c[i][j] == "#":
cnt += 1
if cnt == k:
ans += 1
print(ans) | X = int(input())
if X < 30:
print('No')
else:
print('Yes') | 0 | null | 7,314,539,019,492 | 110 | 95 |
A,B,N=map(int,input().split())
max = 0
if B - 1 >= N:
i = N
else:
i = B - 1
ans = A*i//B - A*(i//B)
print(ans)
| import sys
def main():
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
c = [0] + list(map(int, input().split()))
dp = [list(range(n + 1)) for _ in range(m + 1)]
for i in range(1, m + 1):
for j in range(n + 1):
if j - c[i] >= 0:
dp[i][j] = min(dp[i - 1][j], dp[i][j - c[i]] + 1)
else:
dp[i][j] = dp[i - 1][j]
print(dp[m][n])
if __name__ == "__main__":
main()
| 0 | null | 14,264,417,404,540 | 161 | 28 |
import sys
a,b,c = map(int,sys.stdin.readline().split())
counter = 0
for n in range(a,b+1):
if c % n == 0:
counter += 1
print(counter) | data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
if a > b or a < 1 or c > 10000:
exit()
cnt = 0
for num in range(a,b+1):
if (c%num) == 0:
cnt += 1
print(cnt)
| 1 | 545,087,217,698 | null | 44 | 44 |
X, Y = map(int, input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
step1_cnt = 0
step2_cnt = 0
if Y == X:
if Y % 3 == 0:
step1_cnt = step2_cnt = Y//3
print(cmb(step1_cnt+step2_cnt,step1_cnt,mod))
else:
print(0)
if Y > X:
step1_cnt = Y-X
Y = Y - step1_cnt*2
X = X - step1_cnt
if Y % 3 == 0:
step1_cnt += Y//3
step2_cnt += Y//3
print(cmb(step1_cnt+step2_cnt,step1_cnt,mod))
else:
print(0)
if X > Y:
step2_cnt = X - Y
Y = Y - step2_cnt
X = X - step2_cnt*2
if Y % 3 == 0:
step1_cnt += Y//3
step2_cnt += Y//3
print(cmb(step1_cnt+step2_cnt,step1_cnt,mod))
else:
print(0)
| from functools import lru_cache
MOD = 10**9+7
x,y = map(int, input().split())
summ = x+y
@lru_cache(maxsize=None)
def inv(n):
return pow(n,-1,MOD)
if summ%3 == 0 and summ//3 <= x and summ//3 <= y:
mn = min(x,y)
n = mn - summ//3
a = summ//3
b = 1
ans = 1
for i in range(n):
ans *= a
ans *= inv(b)
ans %= MOD
a -= 1
b += 1
print(ans)
else:
print(0) | 1 | 150,623,691,434,780 | null | 281 | 281 |
K = int(input())
id = 1
cnt = 7
while cnt < K:
cnt = cnt * 10 + 7
id += 1
visited = [0] * K
while True:
remz = (cnt % K)
if remz == 0:
break
visited[remz] += 1
if visited[remz] > 1:
id = -1
break
cnt = remz * 10 + 7
id += 1
print(id)
| k = int(input())
x = 7 % k
i = 1
set = set()
is_there = False
while not is_there:
set.add(x)
if x == 0:
print(i)
break
x = (x*10+7) % k
if x in set:
is_there = True
set.add(x)
i += 1
if x == 0:
print(i)
break
else:
print('-1') | 1 | 6,086,016,256,540 | null | 97 | 97 |
if __name__ == '__main__':
while True:
data = [int(x) for x in input().split(' ')]
H = data[0]
W = data[1]
if H == 0 and W == 0:
break
# ?????§?????????????????????
for i in range(1, H+1):
output = '#.' * W
if i % 2 == 0:
output = output[1:]
print('{0}'.format(output[:W]))
print('') # ??????????????????????????????1???????????? | while True:
h, w = list(map(int, input().split()))
a, b = divmod(w, 2)
c, d = divmod(h, 2)
if h == w == 0:
break
print(('#.' * a + '#' * b + '\n' + '.#' * a + '.' * b + '\n') * c
+ ('#.' * a + '#' * b + '\n') * d) | 1 | 867,498,793,028 | null | 51 | 51 |
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,M=map(int,input().split())
a = list(map(int,input().split()))
if N-sum(a)>=0:
print(N-sum(a))
else:
print("-1") | 0 | null | 15,965,949,273,834 | 23 | 168 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k-1, n-1):
print("Yes" if a[i+1] > a[i-k+1] else "No") | n = int(input())
ans = 0
for i in range(1,n):
ans += n//i
if n%i == 0:
ans -= 1
print(ans) | 0 | null | 4,817,707,764,408 | 102 | 73 |
n = int(input())
print(n//2 + n%2) | N = int(input())
ans = (N-1)//2 + 1
print(int(ans)) | 1 | 58,647,090,220,962 | null | 206 | 206 |
def main():
N = int(input())
A = {input() for i in range(N)}
print(len(A))
if __name__ == '__main__':
main()
| import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
if n==0:
print(x)
sys.exit()
if x not in p:
print(x)
sys.exit()
q=list(i for i in range(p[0]-1,p[-1]+2))
for i in p:
q.remove(i)
ans=[]
c=x+n
for i in q:
if c>abs(x-i):
c=abs(x-i)
ans.clear()
ans.append(i)
if c==abs(x-i):
ans.append(i)
print(min(ans)) | 0 | null | 22,199,077,686,368 | 165 | 128 |
def main():
n = int(input())
print((n + 1) // 2)
main() | #
import sys
input=sys.stdin.readline
def main():
N,M=map(int,input().split())
if N>=2 and M>=2:
print((N*(N-1))//2+(M*(M-1)//2))
elif N>=2:
print((N*(N-1))//2)
elif M>=2:
print((M*(M-1)//2))
else:
print(0)
if __name__=="__main__":
main()
| 0 | null | 52,196,741,593,148 | 206 | 189 |
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
n, a, b = inm()
if a == 0:
print(0)
elif n >= a+b:
print(n//(a+b) * a + min(a, n % (a+b)))
else:
print(min(n, a)) | A , B, M = map(int,input().split(" "))
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
res = min(a) + min(b)
for _ in range(M):
x,y, c = list(map(int,input().split(" ")))
x-=1
y-=1
res = min(res,a[x]+b[y]-c)
print(res)
| 0 | null | 54,892,188,332,552 | 202 | 200 |
x = int(input())
yen_500 = 0
yen_5 = 0
amari = 0
happy = 0
if x>= 500:
yen_500 = x//500
amari = x - 500 * yen_500
yen_5 = amari//5
happy = 1000 * yen_500 + 5 * yen_5
print(happy)
else:
yen_5 = x//5
happy = 5 * yen_5
print(happy)
| x=int(input())
a=(x//500)*1000
b=((x%500)//5)*5
print(a+b) | 1 | 42,673,824,338,368 | null | 185 | 185 |
s = input()
if s == "BBB" or s == "AAA": print("No")
else: print("Yes")
| S = input()
if S == 'AAA' or S== 'BBB':
print("No")
else:
print("Yes") | 1 | 55,043,475,822,048 | null | 201 | 201 |
import math
n=int(input())
ans=0
count=0
while True:
if ans!=0 and ans%360==0:
break
else:
count+=1
ans+=n
print(count)
| X=int(input())
for i in range(1,180):
if (i*360%X==0):
print((i*360)//X)
exit() | 1 | 13,235,341,060,748 | null | 125 | 125 |
ABC = input().split()
a = int(ABC[0])
b = int(ABC[1])
c = int(ABC[2])
i = 0
while a<=b:
if c%a==0:
i = i+1
a = a+1
print(i) | n=int(input())
a=[0,1,3,3,7,7,7,14,22,22,22,33,33,46,60]
b=[0,1,2,2,3,3,3,4,5,5,5,6,6,7,8]
print(60*((n//15)**2)+b[n%15]*(15*(n//15))+a[n%15]) | 0 | null | 17,746,766,747,668 | 44 | 173 |
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 = int(input())
sum = 0
for i in range(1, n+1):
if((i % 3 * i % 5 * i % 15) != 0):
sum += i
print(sum) | 1 | 35,022,527,277,792 | null | 173 | 173 |
import sys
[print(len(str(sum(map(int, line.split()))))) for line in sys.stdin] | class UnionFind:
def __init__(self, n):
self.nodes = n
self.parents = [i for i in range(n)]
self.sizes = [1] * n
self.rank = [0] * n
def find(self, i): # どの集合に属しているか(根ノードの番号)
if self.parents[i] == i:
return i
else:
self.parents[i] = self.find(self.parents[i]) # 経路圧縮
return self.parents[i]
def unite(self, i, j): # 二つの集合を併合
pi = self.find(i)
pj = self.find(j)
if pi != pj:
if self.rank[pi] < self.rank[pj]:
self.sizes[pj] += self.sizes[pi]
self.parents[pi] = pj
else:
self.sizes[pi] += self.sizes[pj]
self.parents[pj] = pi
if self.rank[pi] == self.rank[pj]:
self.rank[pi] += 1
def same(self, i, j): # 同じ集合に属するかを判定
return self.find(i)==self.find(j)
def get_parents(self): # 根ノードの一覧を取得
for n in range(self.nodes): # findで経路圧縮する
self.find(n)
return self.parents
adj = []
N, M = map(int,input().split())
for m in range(M):
a,b = map(int,input().split())
adj.append([a-1,b-1])
uf = UnionFind(N)
for i in range(M): # 取り除く辺番号
uf.unite(*adj[i])
ans=len(set(uf.get_parents())) # 複数の集合にわかれているか確認
print (ans-1) | 0 | null | 1,156,045,608,348 | 3 | 70 |
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sumA = [0]
sumB = [0]
tmp = 0
answer = 0
st = 0
for i in range(N):
tmp = tmp + A[i]
sumA.append(tmp)
tmp = 0
for i in range(M):
tmp = tmp + B[i]
sumB.append(tmp)
for i in range(N, -1, -1):
booktmp = 0
for j in range(st, M + 1):
if sumA[i] + sumB[j] <= K:
booktmp = i + j
else:
st = j
break
answer = max(answer, booktmp)
if j == M:
break
print(answer)
| # 素数ならTrue、素数でなければFalseを返す
def is_prime(x):
sqrt = int(x ** 0.5)
for i in range(2, sqrt + 1):
if x % i == 0:
return False
return True
x = int(input())
while(not is_prime(x)):
x += 1
print(x)
| 0 | null | 58,007,011,462,358 | 117 | 250 |
n=int(input())
for i in range(1,361):
if (n*i)%360==0:
print(i);exit() | n=int(input())
A=list(map(int,input().split()) )
A.sort()
furui = [0] * (max(A) + 1)
for i in A:
if furui[i] >= 2:
continue
for j in range(i,len(furui),i):
furui[j] += 1
ans=0
for i in A:
if furui[i]==1:
ans+=1
print(ans) | 0 | null | 13,688,877,497,582 | 125 | 129 |
import collections
def prime_factorize(n):
a = []
while n%2 == 0:
a.append(2)
n//=2
f =3
while f*f <= n:
if n%f == 0:
a.append(f)
n//=f
else:
f +=2
if n != 1:
a.append(n)
return a
# N-1の約数を数える
N = int(input())
factor = collections.Counter(prime_factorize(N-1))
K = 1
for i in list(factor.values()):
K *= i+1
K -=1
for f in range(2, int(N**0.5)+1):
n = N
if n%f != 0:
continue
while n%f ==0:
n//=f
if n%f ==1 or n==1:
K+=1
#最後は自分自身を加える。
K +=1
print(K) | import sys
input = sys.stdin.readline
K = int(input())
S = list(input())[: -1]
N = len(S)
mod = 10 ** 9 + 7
class Factorial:
def __init__(self, n, mod):
self.f = [1]
for i in range(1, n + 1):
self.f.append(self.f[-1] * i % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for i in range(1, n + 1)[: : -1]:
self.i.append(self.i[-1] * i % mod)
self.i.reverse()
def factorial(self, i):
return self.f[i]
def ifactorial(self, i):
return self.i[i]
def combi(self, n, k):
return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N + K + 1, mod)
res = 0
for l in range(K + 1):
r = K - l
res += f.combi(l + N - 1, l) * pow(25, l, mod) % mod * pow(26, r, mod) % mod
res %= mod
print(res) | 0 | null | 27,227,132,572,612 | 183 | 124 |
n = int(input())
fib = []
fib.append(1)
fib.append(1)
for _ in range(n - 1):
fib.append(fib[-2] + fib[-1])
print(fib[-1])
| import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()
N, P = map(int, input().split())
S = list(map(int, input()))
if P == 2:
print(sum(i + 1 for i in range(N) if S[i] % 2 == 0))
elif P == 5:
print(sum(i + 1 for i in range(N) if S[i] % 5 == 0))
else:
x = [None] * (N + 1)
x[N] = 0
tmp = 1
for i in reversed(range(N)):
x[i] = (x[i + 1] + S[i] * tmp) % P
tmp = tmp * 10 % P
print(sum(i * (i - 1) // 2 for i in Counter(x).values()))
| 0 | null | 29,296,102,457,820 | 7 | 205 |
s = input().split()
print(''.join(reversed(s)))
| from collections import deque
n=int(input())
e=[]
edge=[[] for _ in range(n)]
for i in range(n-1):
x,y=map(int,input().split())
edge[x-1].append(y-1)
edge[y-1].append(x-1)
e.append(str(x-1)+" "+str(y-1))
par=[0]*n #自分の親と何番でつながっているか
visited=[0]*n
visited[0]=1
que=deque([0])
ans=dict()
K=0
while que:
now=que.popleft()
color=1
for x in edge[now]:
if visited[x]:
continue
visited[x]=1
que.append(x)
if color==par[now]:
color+=1
par[x]=color
ans[str(min(x,now))+" "+str(max(x,now))]=color
color+=1
print(max(ans.values()))
for i in e:
print(ans[i]) | 0 | null | 118,888,117,410,880 | 248 | 272 |
K = int(input())
S = input()
s = len(S)
L = []
mod = 10 ** 9 + 7
N = 2 * 10**6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def cmb(n, r):
return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
for i in range(2, N + 1):
fac.append( ( fac[-1] * i ) % mod )
inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
finv.append( finv[-1] * inv[-1] % mod )
for i in range(K+1):
L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )
ans = []
for i, x in enumerate(L):
if i == 0:
ans.append(x)
else:
ans.append( ( ans[i-1]*26%mod + x ) % mod )
print(ans[K]) | def main():
K = int(input())
A, B = map(int, input().split())
for i in range(A, B+1):
if i % K == 0:
print("OK")
return
print("NG")
main()
| 0 | null | 19,742,928,041,964 | 124 | 158 |
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 11 14:47:11 2020
@author: Kanaru Sato
"""
s,t = input().split()
u = t+s
print(u) | print("".join(reversed(input().split()))) | 1 | 102,625,933,472,960 | null | 248 | 248 |
from collections import defaultdict
N, K = map(int, input().split())
A = list(map(int, input().split()))
visited = [0] * N
current = 0
i = 1
while i <= K:
current = A[current] - 1
if visited[current] == 0:
visited[current] = i
else:
loop = i - visited[current]
num_loop = (K - i) // loop
i += loop * num_loop
i += 1
ans = current + 1
print(ans) | n=int(input())
s=list(input())
fa=[n+1]*10
la=[-1]*10
for i in range(n):
s[i]=int(s[i])
if fa[s[i]]>n:
fa[s[i]]=i
la[s[i]]=i
ans=0
for i in range(10):
for j in range(10):
if fa[i]<la[j]:
num=[0]*10
for k in range(fa[i]+1,la[j]):
num[s[k]]=1
ans+=num.count(1)
print(ans)
| 0 | null | 75,663,394,649,220 | 150 | 267 |
even,odd = map(int, input().split())
print(int(even * (even-1)/2 + odd * (odd-1)/2))
| # -*- coding: utf-8 -*-
# combinationを使う
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
n, m = map(int, input().split())
counter = 0
if n >= 2:
counter = counter + comb(n, 2)
if m >= 2:
counter = counter + comb(m, 2)
print(counter) | 1 | 45,422,008,690,556 | null | 189 | 189 |
st = input()
if st[-1] == "s":
st += "es"
else:
st += "s"
print(st) | MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
def main():
n,k = map(int,input().split())
a = list(map(int,input().split()))
cum = [0] * (n + 1)
dic = {0:1}
ans = 0
for i in range(min(n,k - 1)):
cum[i + 1] = (cum[i] + a[i])%k
tmp = (cum[i + 1] - i - 1)%k
if tmp in dic:
dic[tmp] += 1
else:
dic[tmp] = 1
for v in dic.values():
ans += v * (v - 1)//2
for i in range(max(n - k + 1,0)):
dic[(cum[i] - i)%k] -= 1
cum[i + k] = (cum[i + k - 1] + a[i + k - 1])%k
tmp = (cum[i + k] - i - k)%k
if tmp in dic:
ans += dic[tmp]
dic[tmp] += 1
else:
dic[tmp] = 1
print(ans)
if __name__ =='__main__':
main()
| 0 | null | 70,326,448,460,530 | 71 | 273 |
import numpy as np
def solve():
if s[2]==s[3] and s[4]==s[5]:
print("Yes")
else:
print("No")
return
s = str(input())
solve()
#a = [int(i) for i in input().split(" ")] | import sys
from collections import Counter
N = int(input())
S = [str(s) for s in sys.stdin.read().split()]
items = list(dict.fromkeys(S))
print(len(items)) | 0 | null | 36,045,829,406,080 | 184 | 165 |
A,B = map(int,input().split())
x = A
y = B
while y>0:
x,y = y,x%y
print((A//x)*B) | def gcd(a,b):
if b ==0:
return a
else:
return gcd(b, a%b)
A,B = map(int, input().split())
A,B = (A,B) if A>B else (B,A)
print(int(A/gcd(A,B)*B)) | 1 | 113,153,442,669,342 | null | 256 | 256 |
S = input()
if S[-1] != "s" :
print(S + "s")
elif S[-1] == "s" :
print(S + "es")
else :
print(" ") | word = input()
print(word + "es" if word[-1] == "s" else word + "s" ) | 1 | 2,389,124,734,282 | null | 71 | 71 |
# Belongs to : midandfeed aka asilentvoice
while(1):
n = str(input())
if n != '0':
ans = 0
for x in n:
ans += int(x)
print(ans)
else:
break | def main():
N = []
while True:
x = input()
if x == '0':
break
else:
N.append(x)
for n in N:
ans = sum(map(int, list(n)))
print(ans)
main() | 1 | 1,572,242,934,130 | null | 62 | 62 |
#
# panasonic2020b d
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """1"""
output = """a"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """2"""
output = """aa
ab"""
self.assertIO(input, output)
def resolve():
global N
N = int(input())
T = []
func("a", "a", T)
for t in T:
print(t)
def func(mw, s, T):
if len(s) == N:
T.append(s)
return
for i in range(ord(mw)-ord("a")+2):
mw = max(mw, chr(ord("a")+i))
ns = s + chr(ord("a")+i)
func(mw, ns, T)
if __name__ == "__main__":
# unittest.main()
resolve()
| a, b = map(int, input().split())
(x, y) = (a, b) if a<=b else (b, a)
for _ in range(y):
print(x, end='') | 0 | null | 68,294,613,410,910 | 198 | 232 |
import sys
N, M = map(int,input().split())
S = input()
S = S[::-1]
i = 0
ans = []
while i < N:
flag = 0
for j in range(M,0,-1):
if i + j <= N and S[i + j] == '0':
i += j
flag = 1
ans.append(j)
break
if flag:
continue
print(-1)
sys.exit()
ans.reverse()
print(*ans) | M=998244353
f=lambda:[*map(int,input().split())]
n,k=f()
lr=[f() for _ in range(k)]
dp=[0]*n
dp[0]=1
S=[0]
for i in range(1,n):
S+=[S[-1]+dp[i-1]]
for l,r in lr:
dp[i]+=S[max(i-l+1,0)]-S[max(i-r,0)]
dp[i]%=M
print(dp[-1]) | 0 | null | 70,975,123,164,228 | 274 | 74 |
strargs = input()
n, a, b = map(lambda x: int(x), strargs.split())
if (b - a) % 2 == 0:
print((b - a)//2)
elif a - 1 < n - b:
newB = b - a
mid = (newB - 1)//2 + 1
print(a + mid - 1)
else:
newA = (a + (n - b + 1))
mid = newA + (n - newA)//2
print((n - b + 1) + (n - newA)//2) | import sys
input = sys.stdin.readline
def main():
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
ans = (B - A) // 2
else:
a = (A - 1) + 1 + ((B - ((A - 1) + 1)) - 1) // 2
b = (N - B) + 1 + (N - (A + ((N - B) + 1))) // 2
ans = min(a, b)
print(ans)
if __name__ == "__main__":
main()
| 1 | 109,320,142,427,260 | null | 253 | 253 |
N=int(input())
ans=[]
for i in range(1,99):
if N>26**i:
N-=26**i
else:
N-=1
for l in range(i):
key=(chr(ord("a")+(N%26)))
N=int(N/26)
ans.append(key)
break
ans.reverse()
for i in range(len(ans)):
print(ans[i],end="") | n = int(input())
n2 = n
i = 1
while True:
if (n2 > 26**i):
n2 = n2 - 26**i
i = i + 1
else:
break
lst = []
for j in range(i - 1):
k = j + 1
n = n - 26**k
n = n - 1
for j in range(i):
k = i - j - 1
x = n//(26**k)
lst.append(x)
n = n - 26**k*x
for j in range(len(lst)):
if (j != len(lst) - 1):
print(chr(int(97 + lst[j])), end = '')
else:
print(chr(int(97 + lst[j])))
| 1 | 11,927,432,769,940 | null | 121 | 121 |
s = input()
if(s[2] == s[3] and s[4] == s[5]):
print("Yes")
else:
print("No")
| s = input()
if s[-1] == s[-2]:
if s[-3] == s[-4]:
print("Yes")
exit()
print("No") | 1 | 41,964,807,305,242 | null | 184 | 184 |
def resolve():
N, K = list(map(int, input().split()))
ans = 0
mini = sum(range(K))
maxi = sum(range(N, N-K, -1))
for i in range(K, N+2):
ans += maxi - mini + 1
ans %= 10**9+7
mini += i
maxi += N - i
print(ans)
if '__main__' == __name__:
resolve()
| mod = 10**9+7
n,k = map(int,input().split())
ans = 0
for i in range(k,n+2):
ans += (i*n-i*(i-1)+1)%mod
ans %=mod
print(ans) | 1 | 32,997,212,541,820 | null | 170 | 170 |
c = int(input())
n = 0
for i in range(1,10):
if c /i < 10 and c %i ==0:
n += 1
break
ans = 'Yes' if n >= 1 else 'No'
print(ans) | n = int(input())
for i in range(1,10):
if (n%i==0) and ((n//i) in range(1,10)):
print("Yes")
break
else:
print("No") | 1 | 159,881,039,436,832 | null | 287 | 287 |
def li():
return [int(x) for x in input().split()]
MOD = 998244353
N, K = li()
L, R = [], []
for _ in range(K):
l, r = li()
L.append(l)
R.append(r)
#dp[i]: マスiにいく場合の数
dp = [0] * (2 * N + 1)
dp[1] = 1
dp[2] = -1
for i in range(1, N):
dp[i+1] += dp[i]
dp[i+1] %= MOD
for k in range(K):
l, r = L[k], R[k]
dp[i+l] += dp[i]
dp[i+l] %= MOD
dp[i+r+1] -= dp[i]
dp[i+r+1] %= MOD
print(dp[N])
| n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
mod = 998244353
dp = [0] * n
dp[0] = 1
acc = 0
for i in range(1, n):
# 例4のi=13, lr=[[5, 8], [1, 3], [10, 15]]の場合を想像すると書きやすい
for li, ri in lr:
if i - li >= 0:
acc += dp[i - li]
acc %= mod
if i - ri - 1 >= 0:
acc -= dp[i - ri - 1]
acc %= mod
dp[i] = acc
print(dp[-1]) | 1 | 2,683,588,483,242 | null | 74 | 74 |
N,K=map(int,input().split())
p=list(map(int,input().split()))
res=0
s=sum(p[:K])
for i in range(N-K+1):
res=max(res,(s+K)/2)
if i!=N-K:
s=s+p[i+K]-p[i]
print(res) | import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()
n = k()
x = l()
a = sum(x)//n
b = sum(x)//n + 1
for i in x:
ans += pow(i-a,2)
cnt += pow(i-b, 2)
print(min(ans,cnt)) | 0 | null | 70,380,056,009,018 | 223 | 213 |
n, q = (int(x) for x in input().split())
process = [input().split() for _ in range(n)]
time = 0
while process:
p = process.pop(0)
if int(p[1]) <= q:
time += int(p[1])
print(p[0], time)
else:
time += q
process.append([p[0], int(p[1]) - q]) | def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a,b):
return (a*b) / gcd(a,b)
if __name__ == "__main__":
n1,n2=map(int,input().split(' '))
print(int(lcm(n1,n2))) | 0 | null | 56,484,956,905,758 | 19 | 256 |
n = input()
s , t=input().split()
print(*[s + t for s, t in zip(s, t)],sep='') | n=int(input())
s,t=map(str,input().split())
S=list(s)
T=list(t)
for i in range(n):
print(S[i],end="")
print(T[i],end="")
| 1 | 111,880,403,449,660 | null | 255 | 255 |
N = int(input())
ans = 10**100
for i in range(1,int(N**(0.5))+1):
if N % i == 0:
tmp = (i-1) + (N//i -1)
ans = min(ans,tmp)
print(ans)
| # -*- coding:utf-8 -*-
def bubble_sort(num_list):
swap_count = 0
for i in range(len(num_list)):
for j in range(len(num_list)-1, i , -1):
if num_list[j] < num_list[j-1]:
num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
swap_count = swap_count + 1
return num_list, swap_count
def show_list(list):
i = 0;
while(i < len(list)-1):
print(list[i], end=" ")
i = i + 1
print(list[i])
num = int(input())
num_list = [int(x) for i, x in enumerate(input().split()) if i < num]
num_list, swap_count = bubble_sort(num_list)
show_list(num_list)
print(swap_count) | 0 | null | 80,849,192,318,300 | 288 | 14 |
h1, m1, h2, m2, k = map(int, input().split())
if m1 <= m2:
h = h2 - h1
m = m2 - m1
else:
h = h2 - h1 - 1
m = m2 - m1 + 60
m += 60 * h
print(m - k)
| while True:
ans = 0
x = raw_input()
if x == "0":
break
for i in x:
ans += int(i)
print ans | 0 | null | 9,756,190,319,780 | 139 | 62 |
N = int(input())
t = 0
h = 0
for n in range(N):
w = input().split()
if w[0] == w[1]:
t += 1
h += 1
elif w[0] > w[1]:
t += 3
else:
h += 3
print(t,h)
| t,h=0,0
for _ in range(int(input())):
a,b=input().split()
if a>b:t+=3
if a<b:h+=3
if a==b:t+=1;h+=1
print(t,h) | 1 | 2,021,996,446,950 | null | 67 | 67 |
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 False
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
return True
def size(self, x):
return -self.parents[self.find(x)]
N, M = map(int, input().split())
ans = 0
UF = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
UF.union(a,b)
for i in range(N):
ans = max(ans, UF.size(i))
print(ans) | import sys
read = sys.stdin.buffer.read
s = read().decode("utf-8")
H = s[:(len(s) - 1) // 2]
B = s[(len(s) - 1) // 2 + 1:-1]
if s[:-1] == s[:-1][::-1] and H == H[::-1] and B == B[::-1]:
print("Yes")
else:
print("No") | 0 | null | 25,268,344,707,500 | 84 | 190 |
N = int(input())
A_list = list(map(int, input().split()))
MOD = 10**9 + 7
zeros = [0] * 61
ones = [0] * 61
for a in A_list:
for i, b in enumerate([1 if (a >> j & 1) else 0 for j in range(61)]):
if b == 1:
ones[i] += 1
else:
zeros[i] += 1
res = 0
for a in A_list:
twice = 1
for i, b in enumerate([1 if (a >> j & 1) else 0 for j in range(61)]):
if b == 1:
cnt = zeros[i]
ones[i] -= 1
else:
cnt = ones[i]
zeros[i] -= 1
res += twice * cnt
twice *= 2
res %= MOD
print(res) | from typing import List
class Dice:
def __init__(self, surface: List[int]):
self.surface = surface
def get_upper_sursurface(self) -> int:
return self.surface[0]
def invoke_method(self, mkey: str) -> None:
if mkey == 'S':
self.S()
return None
if mkey == 'N':
self.N()
return None
if mkey == 'E':
self.E()
return None
if mkey == 'W':
self.W()
return None
raise ValueError(f'This method does not exist. : {mkey}')
def S(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[4]
self.surface[1] = tmp[0]
self.surface[2] = tmp[2]
self.surface[3] = tmp[3]
self.surface[4] = tmp[5]
self.surface[5] = tmp[1]
def N(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[1]
self.surface[1] = tmp[5]
self.surface[2] = tmp[2]
self.surface[3] = tmp[3]
self.surface[4] = tmp[0]
self.surface[5] = tmp[4]
def E(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[3]
self.surface[1] = tmp[1]
self.surface[2] = tmp[0]
self.surface[3] = tmp[5]
self.surface[4] = tmp[4]
self.surface[5] = tmp[2]
def W(self) -> None:
tmp = [i for i in self.surface]
self.surface[0] = tmp[2]
self.surface[1] = tmp[1]
self.surface[2] = tmp[5]
self.surface[3] = tmp[0]
self.surface[4] = tmp[4]
self.surface[5] = tmp[3]
# 提出用
data = [int(i) for i in input().split()]
order = list(input())
# # 動作確認用
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('EESWN')
dice = Dice(data)
for o in order:
dice.invoke_method(o)
print(dice.get_upper_sursurface())
| 0 | null | 61,535,124,828,550 | 263 | 33 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
class UnionFind:
def __init__(self, N):
self.root = list(range(N + 1))
self.size = [1] * (N + 1)
def __getitem__(self, x):
root = self.root
while root[x] != x:
root[x] = root[root[x]]
x = root[x]
return x
def merge(self, x, y):
x = self[x]
y = self[y]
if x == y:
return
sx, sy = self.size[x], self.size[y]
if sx < sy:
x, y = y, x
sx, sy = sy, sx
self.root[y] = x
self.size[x] += sy
def graph_input(N, M):
G = [[] for _ in range(N + 1)]
for _ in range(M):
a, b = map(int, readline().split())
G[a].append(b)
G[b].append(a)
return G
N, M, K = map(int, readline().split())
friend = graph_input(N, M)
block = graph_input(N, K)
uf = UnionFind(N + 1)
for a in range(N + 1):
for b in friend[a]:
uf.merge(a, b)
answer = [0] * (N + 1)
for a in range(N + 1):
n = uf.size[uf[a]] - 1
for x in friend[a] + block[a]:
if uf[a] == uf[x]:
n -= 1
answer[a] = n
print(' '.join(map(str, answer[1:]))) | def main():
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for ia in range(N-2):
a = L[ia]
ic = ia + 2
for ib in range(ia+1, N-1):
b = L[ib]
while ic < N and L[ic] < a+b:
ic += 1
ans += ic - (ib + 1)
print(ans)
main() | 0 | null | 116,413,054,058,600 | 209 | 294 |
N,M,K=map(int,input().split())
P=998244353
class FactInv:
def __init__(self,N,P):
fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
for i in range(1,N):
fact[i+1]=(fact[i]*(i+1))%P
ifact[-1]=pow(fact[-1],P-2,P)
for i in range(N,0,-1):
ifact[i-1]=(ifact[i]*i)%P
self.fact=fact;self.ifact=ifact;self.P=P
def comb(self,n,k):
return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
FI=FactInv(N+10,P)
ans=0
for k in range(0,K+1):
ans+=(M*FI.comb(N-1,k)*pow(M-1,N-1-k,P))%P
ans%=P
print(ans) | import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))
N = int(input())
ukv = [list(map(int, input().split())) for _ in range(N)]
dist = [-1]*N
dist[0] = 0
deq = deque()
#deq.append(ukv[0][2:])
deq.append([1])
step = 0
while deq[0]:
# print('deq:', deq)
nextvs = []
currvs = deq.popleft()
for v in currvs:
for nv in ukv[v-1][2:]:
if dist[nv-1] == -1:
dist[nv-1] = step+1
nextvs.append(nv)
deq.append(nextvs)
step += 1
res = [[val1, val2] for val1, val2 in zip(range(1, N+1), dist)]
for a in res:
print(*a)
| 0 | null | 11,635,783,982,368 | 151 | 9 |
x=input()
y=input()
lst1=[]
lst1=list(x)
lst2=[]
lst2=list(y)
b=0
ans=0
while(b<len(x)):
if(not lst1[b]==lst2[b]):
ans=ans+1
b+=1
print(ans) | s = input()
t = input()
l = len(s)
x = 0
for i in range(l):
if s[i] != t[i]:
x += 1
print(x) | 1 | 10,522,675,175,490 | null | 116 | 116 |
from collections import deque
n , k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 1
plus = []
minus = []
if n == k:
for i in range(n):
ans *= a[i]
ans %= mod
print(ans)
exit()
for i in range(n):
if a[i] >= 0:
plus.append(a[i])
elif a[i] < 0:
minus.append(a[i])
if not plus and k % 2 == 1:
minus.sort(reverse=True)
for i in range(k):
ans *= minus[i]
ans %= mod
print(ans)
exit()
plus.sort(reverse=True)
minus.sort()
plus = deque(plus)
minus = deque(minus)
cou = []
while True:
if len(cou) == k:
break
elif len(cou) == k-1:
cou.append(plus.popleft())
break
else:
if len(plus)>=2 and len(minus)>=2:
p1 = plus.popleft()
p2 = plus.popleft()
m1 = minus.popleft()
m2 = minus.popleft()
if p1*p2 > m1*m2:
cou.append(p1)
plus.appendleft(p2)
minus.appendleft(m2)
minus.appendleft(m1)
else:
cou.append(m1)
cou.append(m2)
plus.appendleft(p2)
plus.appendleft(p1)
elif len(plus) < 2:
m1 = minus.popleft()
m2 = minus.popleft()
cou.append(m1)
cou.append(m2)
elif len(minus) < 2:
p1 = plus.popleft()
cou.append(p1)
for i in cou:
ans *= i
ans %= mod
print(ans)
| l = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = list(int(input()) for _ in range(n))
for i in range(3) :
for j in range(3) :
for k in range(n) :
if l[i][j] == b[k] :
l[i][j] = 0
for i in range(3) :
if l[i][0] + l[i][1] + l[i][2] == 0 :
print('Yes')
exit()
if l[0][i] + l[1][i] + l[2][i] == 0 :
print('Yes')
exit()
if l[0][0] + l[1][1] + l[2][2] == 0 :
print('Yes')
exit()
if l[0][2] + l[1][1] + l[2][0] == 0 :
print('Yes')
exit()
print('No') | 0 | null | 34,580,294,666,350 | 112 | 207 |
s = set()
for _ in range(int(input())):
cmd, v = input().split()
if cmd == 'insert':
s.add(v)
else:
print('yes' if v in s else 'no')
| a,b=map(int,input().split());print(['safe','unsafe'][a<=b]) | 0 | null | 14,541,323,379,460 | 23 | 163 |
# -*-coding:utf-8-*-
def get_input():
while True:
try:
yield "".join(input())
except EOFError:
break
if __name__=="__main__":
array = list(get_input())
for i in range(len(array)):
temp = array[i].split()
a = int(temp[0])
b = int(temp[1])
ans = a + b
print(len(str(ans))) | from math import log10
while True:
try:
a, b = map(int, raw_input().split())
print(int(log10(a+b)) + 1)
except EOFError:
break | 1 | 79,573,988 | null | 3 | 3 |
N = int(input())
N_str = str(N)
a = 0
for i in range(len(N_str)):
a += int(N_str[i])
if a % 9 == 0:
print("Yes")
else:
print("No")
| from collections import Counter
from math import gcd
N=int(input())
def factorize(x):
i=2
ret=[]
while i*i<=x:
while x%i==0:
ret.append(i)
x//=i
i+=1
if x>1:
ret.append(x)
return Counter(ret)
ans=1
for v in factorize(N-1).values():
ans*=v+1
ans-=1
cnt=1
for v in factorize(gcd(N,N-1)).values():
cnt*=v+1
cnt-=1
ans-=cnt
k=2
while k*k<=N:
if N%k==0:
n=N//k
while n%k==0:
n//=k
if n%k==1:
ans+=1
k+=1
ans+=1
print(ans) | 0 | null | 22,819,763,541,960 | 87 | 183 |
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = int(input())
a=lcm(num1,360)
b=a/num1
print(int(b)) | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
x = int(readline())
for i in range(1, 361):
if (x * i) % 360 == 0:
return print(i)
if __name__ == '__main__':
main()
| 1 | 13,140,548,575,112 | null | 125 | 125 |
def solve(m, f, r):
if (m == -1 or f == -1) or m + f < 30:
return "F"
for a, b in ((80, "A"), (65, "B"), (50, "C")):
if m + f >= a:
return b
if r >= 50:
return "C"
return "D"
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
print(solve(m, f, r))
| S = str(input())
if S == "ABC":
print("ARC")
elif S == "ARC":
print("ABC") | 0 | null | 12,668,142,879,810 | 57 | 153 |
"""
AtCoder Beginner Contest 144 E - Gluttony
愚直解
・修行の順序は結果に影響しないから、修行を誰に割り振るか:N^K
・メンバーN人をどの問題に当てるか(N人の並べ方):N!
-> N^K * N!
間に合わない。
完食にかかる時間のうち最大値がチーム全体の成績なので、
・消化コストAiを修行で下げる
・消化コストAiの大きい人に、食べにくさFiの小さい食べ物を割り当てる
のが良さそう
最大値の最小化、なので、二分探索が使えそうな気もする。
A,F <= 10^6
かかる時間を X 以下にできるか、を考える。
・消化コストが大きい人に、食べにくさが小さい問題を当てるようにする
・Ai * Fi > Xであれば、(Ai - m) * Fi <= X となるような最小のmをカウントする
全メンバーに対しこれを数え上げた時に、
mの合計 > K
であれば、X以下になるように修行することができない(K回までしか修行できず、回数が足りない)ので、最大値の最小はXより上
mの合計 <= K
であれば、X以下になるように修行できるので、最大値の最小はX以下
A*F <= 10^12 までなので、40~50程度繰り返せば行けそう
"""
import math
N,K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
print(0)
exit()
A.sort(reverse=True)
F.sort()
def is_ok(mid):
cnt = 0
for i in range(N):
if A[i] * F[i] <= mid:
continue
else:
cnt += math.ceil((A[i] * F[i] - mid) / F[i]) # A[i]が1減少するごとにF[i]減るのでF[i]で割る
return cnt <= K
# okは全員がX以下になる最小値に着地するので、A*F<=10**12 なので+1して最大のケースにも対応する
ok = 10**12 + 1
# 0ではないことが上で保証されてるので、条件を満たさない最大値の0にしておく
ng = 0
while ok - ng > 1:
mid = (ok + ng) // 2
#print(ok,ng,mid)
if is_ok(mid):
ok = mid
else:
ng = mid
#print(ok,ng,mid)
print(ok) | import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9] * (H + 1)
dp[0] = 0
for i in range(H + 1):
for a, b in ab:
if i - a < 0:
dp[i] = min(dp[i], b)
else:
dp[i] = min(dp[i], dp[i - a] + b)
print(dp[H])
| 0 | null | 123,217,260,827,738 | 290 | 229 |
R, G, B = map(int, input().split())
K = int(input())
cnt = 0
while not(R < G):
G *= 2
cnt += 1
while not(G < B):
B *= 2
cnt += 1
if cnt <= K:
print('Yes')
else:
print('No') | N = int(input())
A = list(map(int,input().split()))
for a in A:
if a%2==0 and a%3!=0 and a%5!=0:
print("DENIED")
exit()
print("APPROVED") | 0 | null | 38,079,832,923,580 | 101 | 217 |
A,B= list(input().split())
a = int(B[0])
b = int(B[2])
c = int(B[3])
if int(A) > 1000:
e = int(A[-2])
f = int(A[-1])
d = int((int(A)- 10 * e - f)/100)
error = 10 * (c * e + b * f) + c * f
error = int(error/100)
ans = int(A) * a + 10 * d * b + e * b + c * d + error
print(int(ans))
else:
print(int(int(A)*float(B))) | n = int(input())
s0=list(str(n))
ans=0
if len(s0)==1:
print(n)
exit()
if len(s0)==2:
for i in range(1,n+1):
s1=list(str(i))
if s1[-1]=='0':
continue
if s1[0]==s1[-1]:
ans+=1
if int(s1[-1])*10+int(s1[0])<=n:
ans+=1
print(ans)
exit()
for i in range(1,n+1):
s1=list(str(i))
if s1[-1]=='0':
continue
if s1[0]==s1[-1]:
ans+=1
for j in range(2,len(s0)):#nより小さい桁数のものを足す
ans+=10**(j-2)
if int(s0[0])>int(s1[-1]):#nより入れ替えた数の最高位数が小さいとき、全て足す
ans+=10**(len(s0)-2)
elif s0[0]==s1[-1]:#nと入れ替えた数の最高位数が同じ時
ans+=int(''.join(s0[1:len(s0)-1]))+1
if int(s0[-1])<int(s1[0]):
ans-=1
print(ans)
| 0 | null | 51,267,148,765,570 | 135 | 234 |
n = list(input())
n1 = int(n[-1])
if n1 == 2 or n1 == 4 or n1 == 5 or n1 == 7 or n1 == 9:
print("hon")
elif n1 == 0 or n1 == 1 or n1 == 6 or n1 == 8:
print("pon")
else:
print("bon")
| N = int(input())
ans = N % 10
if ans == 2 or ans == 4 or ans == 5 or ans == 7or ans == 9:
print("hon")
elif ans == 0 or ans == 1 or ans == 6 or ans == 8:
print("pon")
else:
print("bon") | 1 | 19,218,569,048,480 | null | 142 | 142 |
a,b=map(str,input().split())
a=int(a)
b=100*int(b[0])+10*int(b[2])+1*int(b[3]) #bを100倍した値(整数)に直す
print((a*b)//100) | # import itertools
# import math
# import sys
import numpy as np
# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# S = input()
# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])
A = np.array(A)
B = np.array(B)
cum_A = np.cumsum(A)
cum_A = np.insert(cum_A, 0, 0)
cum_B = np.cumsum(B)
cum_B = np.insert(cum_B, 0, 0)
j = M
max_num = 0
for i in range(N + 1):
while(True):
# j -= 1
if j < 0:
break
minute = cum_A[i] + cum_B[j]
if minute <= K:
if i + j > max_num:
max_num = i + j
break
j -= 1
print(max_num) | 0 | null | 13,632,308,014,000 | 135 | 117 |
A = eval(input())
print("No") if A < 30 else print("Yes") | def mpow(a,b,m):
ans=1
while b >0 :
if b&1:
ans = (ans*a)%m
a=(a*a)%m
b=b>>1
return ans
def calcmod(X,m,N):
mod=0
X=X[::-1]
# print(X)
for i in range(N):
if X[i] == '1':
# if X & (1<<i) >0:
mod += mpow(2,i,m)
mod%=m
return mod
def popcount(m):
return bin(m).count("1")
def findsteps(mm):
cnt=0
while mm !=0:
cnt+=1
mm=mm%popcount(mm)
return cnt
N=int(input())
x=input()
X=int(x,2)
##we need to find X%(m-1) and X%(m+1)
m=popcount(X)
m1=m+1
m2=m-1
firstmod=calcmod(x,m1,N)
if m2 !=0:
secondmod=calcmod(x,m2,N)
fans=[0 for i in range(N)]
k=0
for i in range(N-1,-1,-1):
if X & (1<<i) >0:
##the bit was set
##we need to find X%(m-1) - (2^i)%(m-1)
if m2 == 0:
ans=0
else:
mm=secondmod - mpow(2,i,m2)
if mm < 0:
mm+=m2
mm=mm%m2
ans=1+findsteps(mm)
else:
mm = firstmod + mpow(2,i,m1)
mm=mm%m1
ans=1+findsteps(mm)
fans[k] = ans
k+=1
##the bit was not set
for i in fans:
print(i) | 0 | null | 7,003,801,083,972 | 95 | 107 |
def main():
N = int(input())
l = list(map(int, input().split()))
l2 = []
for i in range(len(l)):
if l[i] % 2 == 0:
l2.append(l[i])
for i in range(len(l2)):
if not l2[i] % 3 == 0 and not l2[i] % 5 == 0:
print('DENIED')
return
print('APPROVED')
main() | n = int(input())
s = input()
if n%2 != 0 or s[:n//2] != s[n//2:]:
print("No")
else:
print("Yes") | 0 | null | 107,529,628,688,860 | 217 | 279 |
s=input()
if s=="ABC":
s="ARC"
else:
s="ABC"
print(s) | import sys
def input(): return sys.stdin.readline().rstrip()
S = input()
if S == "ABC":
print("ARC")
else:
print("ABC") | 1 | 24,150,560,333,248 | null | 153 | 153 |
s = input()
p = input()
if (s*2).count(p) == 0 :
print('No')
else :
print('Yes')
| S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
A -= 1
else:
B -= 1
print(f'{A} {B}') | 0 | null | 36,957,654,042,780 | 64 | 220 |
def func(K):
result = ""
for i in range(K):
result += "ACL"
return result
if __name__ == "__main__":
K = int(input())
print(func(K)) | # -*- coding: utf-8 -*-
N,X,M=map(int,input().split())
A=[0]*(M+1)
A[0]=X
D=[0]*(M+1)
s=N
for i in range(1,N):
a=A[i-1]**2%M
if D[a] == 1:
s=A.index(a)
break
else:
A[i]=a
D[a]=1
if s==N:
ans=sum(A)
else:
A=A[:i]
ans=0
l=len(A)-s
ans+=sum(A[:s])
S=sum(A[s:])
T=(N-s)//l
ans+=T*S
K=N-s-l*T
ans+=sum(A[s:(s+K)])
print(ans)
| 0 | null | 2,550,377,553,108 | 69 | 75 |
n,*a=map(int,open(0).read().split())
sa = sum(a)
ha = sa/2
x = 0
for i in range(n):
x+=a[i]
if x>=ha:
break
y = sa-x
print(min(abs(x-y),abs((x-a[i])-(y+a[i])))) | H, W, K = map(int, input().split())
s = [list(input()) for _ in range(H)]
c = [[0 for _ in range(W)] for _ in range(H)]
# 1×wの一次元の配列で考える。分割したマスをそれぞれホワイトチョコをカウントする
# データを加工してから貪欲法を行う
# bit全探索: 横線で割るパターン全てについて、縦線での折り方を考える
ans = (H-1) * (W-1)
for div in range(1<<(H-1)):
g = 0 # g: 横線で分割するグループ番号(0、1、2...)
id = [0] * H #何行目であるかを識別するid: i=1なら グループiになる
for i in range(H):
id[i] = g
if div>>i&1: # 2進法でdivのi桁目が1の時、そこで分割する
g += 1 #分割線がきたらgを増やす
g += 1 # グループ数は分割線+1になる
# 集計に使うc配列を初期化
for i in range(g):
for j in range(W):
c[i][j] = 0
# グループごとを各列ごとのホワイトチョコを集計する
for i in range(H):
for j in range(W):
c[id[i]][j] += int(s[i][j])
num = g - 1 #すでに横線で折った回数(グループ数-1)
now = [0] * g #現状で何個のホワイトチョコがあるか
# 各グループの縦割りの確認
def add(j):
for i in range(g):
now[i] += c[i][j] #j列目のホワイトチョコを足していく
for i in range(g):
if now[i] > K: return False
return True
for j in range(W):
if not (add(j)): # ホワイトチョコがKを超えていれば、縦で織る。
num += 1
now = [0] * g
if not (add(j)):
num = (H-1) * (W-1)
break
#print(g, c, num) # 横割りの回数、各グループの集計、最終的に折った回数
ans = min(ans, num) # 割った回数値の最小を更新
print(ans) | 0 | null | 95,175,234,024,444 | 276 | 193 |