code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
import sys
import heapq
import math
def input(): return sys.stdin.readline().rstrip()
def main():
n, k = map(int,input().split())
A = list(map(int,input().split()))
def is_good(mid, key):
kk = 0
for a in A:
kk += -(-a//mid)-1
if kk <= key:
return True
else:
return False
def bi_search(bad, good, key):
while good - bad > 1:
mid = (bad + good)//2
if is_good(mid, key):
good = mid
else:
bad = mid
return good
print(bi_search(0, 1000000000, k))
if __name__=='__main__':
main()
|
import math
A, B, N = map(int,input().split())
if N < B:
temp1 = math.floor(A*1/B) - A*math.floor(1/B)
temp2 = math.floor(A*N/B) - A*math.floor(N/B)
ans = max(temp1, temp2)
if N >= B:
temp1 = math.floor(A*1/B) - A*math.floor(1/B)
temp2 = math.floor(A*(B-1)/B) - A*math.floor((B-1)/B)
ans = max(temp1, temp2)
print(ans)
| 0 | null | 17,416,192,361,918 | 99 | 161 |
tmp = input().split(" ")
S = int(tmp[0])
W = int(tmp[1])
if S <= W:
print("unsafe")
else:
print("safe")
|
import sys
import math
import bisect
def main():
k, x = map(int, input().split())
if k * 500 >= x:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 0 | null | 63,682,523,488,598 | 163 | 244 |
H, N = list(map(int, input().split()))
A = [[0]*2 for _ in range(N)]
for _ in range(N):
A[_][0], A[_][1] = list(map(int, input().split()))
# print(A)
# A.sort(key=lambda x: x[1])
INF = float('inf')
dp = [INF]*(H+1)
dp[0] = 0
for i in range(H):
if dp[i] == INF:
continue
for j in range(N):
a = A[j][0]
b = A[j][1]
if i+a >= H:
dp[H] = min(dp[H], dp[i]+b)
else:
dp[i+a] = min(dp[i+a], dp[i]+b)
print(dp[H])
|
def num():
from sys import stdin
h, n = map(int, input().split())
magic = [list(map(int, stdin.readline().split())) for _ in range(n)]
INF = float('inf')
ans = [INF]*(h+1)
ans[-1] = 0
for i in range(h, 0, -1):
if ans[i] != INF:
for j, k in magic:
if i-j < 0:
num = ans[i]+k
if ans[0] > num:
ans[0] = num
else:
num = ans[i]+k
if ans[i-j] > num:
ans[i-j] = num
return ans[0]
print(num())
| 1 | 80,742,530,586,090 | null | 229 | 229 |
h, w, m = map(int, input().split())
r = [0] * (h+1)
c = [0] * (w+1)
bomb = []
for _ in range(m):
hi, wi = map(int, input().split())
r[hi] += 1
c[wi] += 1
bomb.append([hi, wi])
hmax = max(r)
wmax = max(c)
cnt = 0
ret = 1
for i in range(1, h+1):
if r[i] == hmax:
cnt += 1
ret *= cnt
cnt = 0
for i in range(1, w+1):
if c[i] == wmax:
cnt += 1
ret *= cnt
for i in range(m):
hi, wi = bomb[i]
if r[hi] == hmax and c[wi] == wmax:
ret -= 1
if ret == 0:
print(hmax + wmax - 1)
else:
print(hmax + wmax)
|
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
print(X)
elif N == 1:
if p[0] == X:
print(X-1)
else:
print(X)
else:
ans = float('inf')
for z in range(0,p[0]):
if (ans-X)**2 > (z-X)**2 :
ans = z
for i in range(N-1):
for z in range(p[i]+1,p[i+1]):
if (ans-X)**2 > (z-X)**2 :
ans = z
for z in range(p[-1]+1,102):
if (ans-X)**2 > (z-X)**2 :
ans = z
print(ans)
| 0 | null | 9,500,719,558,508 | 89 | 128 |
import math
n = int(input())
a = pow(10, n, 10**9+7)
b = pow(9, n, 10**9+7)
c = pow(9, n, 10**9+7)
d = pow(8, n, 10**9+7)
print((a-b-c+d) % (10**9+7))
|
S = input()
T = input()
s = len(S)
t = len(T)
ans1 = 10000000
for i in range(s - t + 1):
ans = 0
for j in range(t):
if T[j] != S[i + j]:
ans += 1
ans1 = min(ans, ans1)
print(ans1)
| 0 | null | 3,439,148,160,062 | 78 | 82 |
import math
def isprime(x):
if x == 2:
return True
if x < 2 or x % 2 == 0:
return False
i = 3
while i <= math.sqrt(x):
if x % i == 0:
return False
i = i + 2
return True
count = 0
n = int(input())
for i in range(0, n):
if isprime(int(input())):
count += 1
print(count)
|
import sys
def is_prime(x):
if(x <= 3 and x > 1):
return True
elif(x % 2 == 0 or x % 3 == 0 or x < 2):
return False
i = 5
while(i * i <= x):
if(x % i == 0 or x % (i + 2) == 0):
return False
i += 6
return True
l = []
count = 0
for input in sys.stdin:
l.append(int(input))
for data in range(1,len(l)):
if(is_prime(l[data]) == True):
count += 1
print count
| 1 | 10,792,516,352 | null | 12 | 12 |
n, t = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]
m, d = 0, [0] * t
for a, b in sorted(ab):
m = max(m, b+d[t-1])
for l in range(t-1,a-1,-1):
if(b+d[l-a] > d[l]):
d[l] = b+d[l-a]
print(m)
|
def main():
s = input()
t = input()
length = len(s)
ans = 0
for i in range(length):
if s[i] != t[i]:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 81,230,286,319,700 | 282 | 116 |
def A():
n, x, t = map(int, input().split())
print(t * ((n+x-1)//x))
def B():
n = list(input())
s = 0
for e in n:
s += int(e)
print("Yes" if s % 9 == 0 else "No")
def C():
int(input())
a = list(map(int, input().split()))
l = 0
ans = 0
for e in a:
if e < l: ans += l - e
l = max(l, e)
print(ans)
A()
|
n, x, t = map(int,input().split())
a = (int)(n / x)
if n % x != 0:
a += 1
print(a * t)
| 1 | 4,252,104,431,588 | null | 86 | 86 |
from functools import reduce
MOD = 10**9 + 7
n, a, b = map(int, input().split())
def comb(n, k):
def mul(a, b):
return a*b%MOD
x = reduce(mul, range(n, n-k, -1))
y = reduce(mul, range(1, k+1))
return x*pow(y, MOD-2, MOD) % MOD
ans = (pow(2, n, MOD)-1-comb(n,a)-comb(n,b)) % MOD
print(ans)
|
ln = input().split()
print(ln[1]+ln[0])
| 0 | null | 84,623,137,980,780 | 214 | 248 |
N = int(input())
S = input()
base = ord("A")
ans = ""
for i in range(len(S)):
p = (ord(S[i])-base)
s = (p+N) % 26
ans += chr(s+base)
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
N -= 2
for i in range(1, N):
if N >= 2:
ans += A[i]*2
N -= 2
elif N == 1:
ans += A[i]
N -= 1
else:
break
print(ans)
| 0 | null | 71,877,752,323,270 | 271 | 111 |
a, b, x = map(int, input().split())
if x > (a**2)*b/2:
t = 2*((a**2)*b-x)/(a**3)
else:
t = a*(b**2)/(2*x)
import math
ans = math.degrees(math.atan(t))
print(ans)
|
import math
a,b,x=map(int,input().split())
volume=a*a*b
if volume>=2*x:
theta=(a*b*b)/(2*x)
else:
theta=2*(volume-x)/(a*a*a)
print(math.degrees(math.atan(theta)))
| 1 | 163,414,727,808,388 | null | 289 | 289 |
h, w, k = map(int, input().split())
c = []
ans = 0
for i in range(h):
c_i = list(input())
c.append(c_i)
for i in range(1 << h):
for j in range(1 << w):
cnt = 0
for ii in range(h):
for jj in range(w):
if (i >> ii & 1):
continue
if (j >> jj & 1):
continue
if c[ii][jj] == "#":
cnt += 1
if cnt == k:
ans += 1
print(ans)
|
h,w,k = map(int,input().split())
m=[list(input()) for i in range(h)]
o=0
for h_bit in range(2**h):
for w_bit in range(2**w):
c=0
for i in range(h):
for j in range(w):
if (h_bit>>i)&1==0 and (w_bit>>j)&1==0 and m[i][j]=='#':
c+=1
if c==k:
o+=1
print(o)
| 1 | 8,924,040,888,278 | null | 110 | 110 |
import math
a, b, x = map(int, input().split())
s = x / a
if s >= a * b / 2:
c = (a * b - s) * 2 / a
rad = math.atan2(c, a)
else:
c = s * 2 / b
rad = math.atan2(b, c)
ans = math.degrees(rad)
print(ans)
|
import math
a, b, x = map(int, input().split())
v = a*a*b
if v == x:
print(0)
elif v/2 <= x < v:
h = 2*(v-x)/a**2
ans = math.atan(h/a)
print(math.degrees(ans))
else:
h = 2*x/(b*a)
ans = math.atan(h/b)
print(90-math.degrees(ans))
| 1 | 163,453,459,706,250 | null | 289 | 289 |
N=int(input())
A=[int(i) for i in input().split()]
S=set(A)
ans=1
for i in A:
ans*=i
if ans>10**18:
ans=-1
break
if 0 in S:
ans=0
print(ans)
|
A, V = [int(x) for x in input().split()]
B, W = [int(x) for x in input().split()]
T = int(input())
if W >= V:
print('NO')
elif abs(A - B) <= (V - W) * T:
print('YES')
else:
print('NO')
| 0 | null | 15,567,589,123,592 | 134 | 131 |
import sys
buff=sys.stdin.read()
buff=buff.lower()
alp="abcdefghijklmnopqrstuvwxyz"
for i in range(len(alp)):
print(alp[i],':',buff.count(alp[i]))
|
all_text = []
while True:
try:
text = input().split()
all_text.extend(text)
except EOFError:
break
text = ''.join(all_text)
count = [0]*32
for letter in text:
i = ord(letter)
if i < 64:
continue
else:
i %= 32
if i:
count[i] += 1
for i in range(26):
print(chr(i+ord('a')), ':', count[i+1])
| 1 | 1,657,724,375,228 | null | 63 | 63 |
from collections import Counter
n = list(input())
n.reverse()
x = [0]*(len(n))
a=0
ex=1
for i in range(len(n)):
a+=int(n[i])*ex
x[i]=a%2019
ex=ex*10%2019
c=Counter(x)
ans = c[0]
for i in c.keys():
b=c[i]
ans += b*(b-1)//2
print(ans)
|
N = int(input())
list1 = []
for i in range(N+1):
if i%3 ==0 or i%5 ==0:
list1.append(i)
total1 =0
total2 = 0
for i in list1:
total1 += i
for i in range(N+1):
total2 += i
print(total2 -total1)
| 0 | null | 32,807,280,888,188 | 166 | 173 |
T = list(input())
N = len(T)
count = 0
for i in range(N):
if T[i] == '?':
T[i] = 'D'
if (i < N - 1) and T[i] == 'P' and T[i + 1] == 'D':
count += 1
elif T[i] == 'D':
count += 1
#print(count)
ans = ''.join(T)
print(ans)
|
a = list(map(str, input().strip()))
for i in range(0, len(a)):
if a[i] == '?':
a[i] = 'D'
print(''.join(a))
| 1 | 18,343,972,313,520 | null | 140 | 140 |
class D_Linked_List:
class Node:
def __init__(self, key, next = None, prev = None):
self.next = next
self.prev = prev
self.key = key
def __init__(self):
self.nil = D_Linked_List.Node(None)
self.nil.next = self.nil
self.nil.prev = self.nil
def insert(self, key):
node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
self.nil.next.prev = node_x
self.nil.next = node_x
def _listSearch(self, key):
cur_node = self.nil.next
while (cur_node != self.nil) and (cur_node.key != key):
cur_node = cur_node.next
return cur_node
def _deleteNode(self, node):
if node == self.nil:
return None
node.prev.next = node.next
node.next.prev = node.prev
def deleteFirst(self):
self._deleteNode(self.nil.next)
def deleteLast(self):
self._deleteNode(self.nil.prev)
def deleteKey(self, key):
node = self._listSearch(key)
self._deleteNode(node)
def show_keys(self):
cur_node = self.nil.next
keys = []
while cur_node != self.nil:
keys.append(cur_node.key)
cur_node = cur_node.next
print(' '.join(keys))
import sys
d_ll = D_Linked_List()
for i in sys.stdin:
if 'insert' in i:
x = i[7:-1]
d_ll.insert(x)
elif 'deleteFirst' in i:
d_ll.deleteFirst()
elif 'deleteLast' in i:
d_ll.deleteLast()
elif 'delete' in i:
x = i[7:-1]
d_ll.deleteKey(x)
else:
pass
d_ll.show_keys()
|
from collections import deque
lis = deque()
num = int(input())
for _ in range(num):
command = input().split()
if command[0]=='deleteFirst':
lis.popleft()
elif command[0]=='deleteLast':
lis.pop()
elif command[0]=='insert':
lis.insert(0, command[1])
elif command[0]=='delete':
try:
lis.remove(command[1])
except:
pass
print(' '.join(lis))
| 1 | 50,356,703,908 | null | 20 | 20 |
from math import sin, cos, radians
a, b, ang = map(int, input().split())
ang = radians(ang)
area = a * b * sin(ang) / 2
c = (a ** 2 + b ** 2 - 2 * a * b * cos(ang)) ** 0.5
circ = a + b + c
height = area * 2 / a
print("%lf\n%lf\n%lf" % (area, circ, height))
|
import math
a, b, c = map(float, input().split())
h = b * math.sin(math.radians(c))
c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(c)))
L = a + b + c
S = 1 / 2 * a * h
print(S)
print(L)
print(h)
| 1 | 175,590,123,738 | null | 30 | 30 |
x, k, d = map(int, input().split())
# k回 dだけ変化
n=abs(x)//d
if k>=n:
k=k-n
else:
n=k
k=0
if k%2 == 0:
x=abs(x)-d*n
else:
x=abs(x)-d*(n+1)
print(abs(x))
|
x, k, d = map(int, input().split())
if x < 0:
target = abs(x) // d
x = x + d * min(target, k)
k -= min(target, k)
else:
target = x // d
x = x - d * min(target, k)
k -= min(target, k)
if k % 2 != 0:
if x < 0:
x += d
else:
x -= d
print(abs(x))
| 1 | 5,259,001,165,840 | null | 92 | 92 |
N, K = map(int, input().split())
p = list(map(int, input().split()))
s = sum(p[:K])
m = s
for i in range(1, N-K+1):
s = s - p[i-1] + p[i+K-1]
m = max(m, s)
print((m+K)/2)
|
k = int(input())
lun = [str(i) for i in range(1, 10)]
L = [str(i) for i in range(1, 10)]
nL = []
while len(lun) < 10 ** 5:
for num in L:
l = num[-1]
lm = int(l) - 1
lp = int(l) + 1
nL.append(num + l)
if lm >= 0:
nL.append(num + str(lm))
if lp < 10:
nL.append(num + str(lp))
lun.extend(nL)
L = nL
nL = []
lunlun = [int(x) for x in lun]
lunlun.sort()
print(lunlun[k-1])
| 0 | null | 57,523,859,621,590 | 223 | 181 |
#10_B
import math
a,b,C=map(int,input().split())
S=a*b*math.sin((C*2*math.pi)/360)/2
c=math.sqrt(a**2+b**2-2*a*b*math.cos((C*2*math.pi)/360))
L=a+b+c
h=2*float(S)/a
print(str(S)+'\n'+str(L)+'\n'+str(h)+'\n')
|
ri = lambda S: [int(v) for v in S.split()]
def rii(): return ri(input())
H, A = rii()
H, r = divmod(H, A)
r = 1 if r else r
print(H + r)
| 0 | null | 38,341,253,170,892 | 30 | 225 |
[r,c] = map(int, input().split())
mat = [list(map(int, input().split())) for i in range(r)]
for i in range(r):
mat[i].append(sum(mat[i]))
r_sum = []
for j in range(c+1):
r_sum.append(sum([mat[i][j] for i in range(r)]))
for i in range(r):
print(" ".join(list(map(str, mat[i]))))
print(" ".join(list(map(str, r_sum))))
|
class Reader:
def __init__(self, r, c):
self.r = r
self.c = c
self.buf = [0 for _ in range(c+1)]
def __call__(self, s):
total = 0
for i, v in enumerate(map(int, s.split())):
self.buf[i] += v
total += v
self.buf[-1] += total
return " ".join((s, str(total)))
def __str__(self):
return " ".join(map(str, self.buf))
r, c = list(map(int, input().split()))
reader = Reader(r, c)
for _ in range(r):
print(reader(input()))
print(reader)
| 1 | 1,363,649,347,816 | null | 59 | 59 |
N, X, M = map(int, input().split())
I = [-1] * M
A = []
total = 0
while (I[X] == -1):
A.append(X)
I[X] = len(A)
total += X
X = (X * X) % M
# print(f'{A=}')
# print(f'{I[:20]=}')
# print(f'{total=}')
# print(f'{X=}, {I[X]=}')
c = len(A) - I[X] + 1
s = sum(A[I[X] - 1:])
# print(f'{c=}, {s=}')
ans = 0
if N < len(A):
ans += sum(A[:N])
else:
ans += total
N -= len(A)
ans += s * (N // c)
N %= c
ans += sum(A[I[X] - 1:I[X] - 1 + N])
print(ans)
|
import sys
a = int(input())
print (a+a**2+a**3)
| 0 | null | 6,532,103,075,558 | 75 | 115 |
import math
PI = math.pi
r = input()
men = r*r * PI
sen = r*2 * PI
print('%.6f %.6f' % (men, sen))
|
import math
a = input()
N = int(a)
X = N//1.08 + 1
x = math.floor(X*1.08)
if x == N:
print(int(X))
else:
print(':(')
| 0 | null | 63,147,044,296,324 | 46 | 265 |
n = input()
mod = 0
for i in range(len(n)):
mod += int(n[i])
mod %= 9
print("Yes") if mod == 0 else print("No")
|
#####
# B #
#####
N = input()
sum = sum(map(int,N))
if sum % 9 == 0:
print('Yes')
else:
print('No')
| 1 | 4,422,989,181,880 | null | 87 | 87 |
N = int(input())
A = list(map(int, input().split()))
mod = int(1e9) + 7
cA = [A[0]]
ans = 0
for i in range(1, N):
cA.append(cA[-1] + A[i])
for i in range(N-1):
ans += A[i] * ((cA[-1] - cA[i])%mod)
ans %= mod
print(ans)
|
n=int(input())
a=list(map(int,input().split()))
x=sum(a)**2
y=sum(a[i]**2 for i in range(n))
print(((x-y)//2)%1000000007)
| 1 | 3,788,043,882,980 | null | 83 | 83 |
# -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
class SegTree:
"""
セグメント木
1.update: i番目の値をxに更新する
2.query: 区間[l, r)の値を得る
"""
def __init__(self, n, func, intv, A=[]):
"""
:param n: 要素数(0-indexed)
:param func: 値の操作に使う関数(min, max, add, gcdなど)
:param intv: 要素の初期値(単位元)
:param A: 初期化に使うリスト(オプション)
"""
self.n = n
self.func = func
self.intv = intv
# nより大きい2の冪数
n2 = 1
while n2 < n:
n2 <<= 1
self.n2 = n2
self.tree = [self.intv] * (n2 << 1)
# 初期化の値が決まっている場合
if A:
# 1段目(最下段)の初期化
for i in range(n):
self.tree[n2+i] = A[i]
# 2段目以降の初期化
for i in range(n2-1, -1, -1):
self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])
def update(self, i, x):
"""
i番目の値をxに更新
:param i: index(0-indexed)
:param x: update value
"""
i += self.n2
self.tree[i] = x
while i > 0:
i >>= 1
self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])
def query(self, a, b):
"""
[a, b)の値を得る
:param a: index(0-indexed)
:param b: index(0-indexed)
"""
l = a + self.n2
r = b + self.n2
s = self.intv
while l < r:
if r & 1:
r -= 1
s = self.func(s, self.tree[r])
if l & 1:
s = self.func(s, self.tree[l])
l += 1
l >>= 1
r >>= 1
return s
def get(self, i):
""" 一点取得 """
return self.tree[i+self.n2]
def all(self):
""" 全区間[0, n)の取得 """
return self.tree[1]
N, M = MAP()
S = input()
dp = SegTree(N+1, min, INF)
dp.update(N, 0)
for i in range(N-1, -1, -1):
# ゲームオーバーマスには遷移できない
if S[i] == '1':
continue
mn = dp.query(i+1, min(N+1, i+M+1))
if mn != INF:
dp.update(i, mn+1)
# 辿り着けない
if dp.get(0) == INF:
print(-1)
exit()
cnt = dp.get(0)
cur = 0
prev = -1
ans = []
for i in range(1, N+1):
if dp.get(i) == INF:
continue
# 手数が変わる場所でなるべく手前に飛ぶ
if dp.get(i) != cnt:
prev = cur
cur = i
ans.append(cur-prev)
cnt = dp.get(i)
print(*ans)
|
N = int(input())
A = [int(i) for i in input().split()]
print(sum(a % 2 for a in A[::2]))
| 0 | null | 73,330,713,763,868 | 274 | 105 |
from math import pi
r = float(input())
circle_squre = r * r * pi
circle_length = (r*2) * pi
print('{}'.format(circle_squre),'{}'.format(circle_length))
|
import math
r = float(raw_input())
print "%.7f %.7f"%(math.pi*r*r, 2*math.pi*r)
| 1 | 631,924,879,684 | null | 46 | 46 |
def nishin(n):
return str(bin(n)[2:])[::-1]
N=int(input())
L=list(map(int,input().split()))
mod=1000000007
ans=sum(L)*(N-1)
c=[0]*61
for i in L:
i=nishin(i)
for j in range(len(i)):
if i[j]=="1":
c[j]+=1
for i in range(61):
ans-=(pow(2,i,mod)*c[i]*(c[i]-1))%mod
print(ans%mod)
|
A = int(input())
B = int(input())
if (A==1 and B ==2) or (A==2 and B==1):
print('3')
elif (A==1 and B==3) or (A==3 and B==1):
print('2')
elif (A==2 and B==3) or (A==3 and B==2):
print('1')
| 0 | null | 116,584,414,140,942 | 263 | 254 |
x = input()
x = x.split(" ")
x = [int(z) for z in x]
print("%d %d %f" % (x[0]//x[1], x[0]%x[1], x[0]/x[1]))
|
a, b = [int(i) for i in input().split(' ')]
answer1 = a // b
answer2 = a % b
answer3 = round(float(a) / float(b), 5)
print(answer1, answer2, answer3)
| 1 | 609,781,253,928 | null | 45 | 45 |
S = str(input())
if S == "ABC":
print("ARC")
elif S == "ARC":
print("ABC")
|
S = str(input())
if S[0] == S[1] == S[2]:
print('No')
else:
print('Yes')
| 0 | null | 39,472,060,450,758 | 153 | 201 |
import math
a, b, degC = [ float( i ) for i in raw_input( ).split( " " ) ]
radC = degC*math.pi/ 180.0
h = math.sin( radC ) * b
S = (a*h)/2
x = math.cos( radC ) * b
x -= a
c = math.sqrt( x**2 + h**2 )
L = a + b + c
print( S )
print( L )
print( h )
|
import math
a, b, C = map(int, input().split())
print('{0}'.format(0.5 * a * b * math.sin(C * math.pi / 180)))
print('{0}'.format(a + b + (a ** 2 + b ** 2 - 2 * a * b * math.cos(C * math.pi / 180)) ** 0.5))
print('{0}'.format(b * math.sin(C * math.pi / 180)))
| 1 | 181,099,009,042 | null | 30 | 30 |
from collections import Counter
s = input()
n = len(s)
dp = [0]
mod = 2019
a = 0
for i in range(n):
a = a + int(s[n-i-1]) * pow(10, i, mod)
a %= mod
dp.append(a%mod)
ans = 0
c = Counter(dp)
for value in c.values():
ans += value * (value-1) / 2
print(int(ans))
|
def solve(s, p=2019):
s = s[::-1]
memo = [0] * p
memo[0] = 1
ans = 0
q = 0
r = 1
for c in s:
q = (q + int(c)*r) % p
ans += memo[q]
r = 10*r % p
memo[q] += 1
return ans
s = input()
print(solve(s))
| 1 | 30,917,530,206,134 | null | 166 | 166 |
import sys
input = sys.stdin.readline
from collections import *
def make_divs(n):
divs = []
i = 1
while i*i<=n:
if n%i==0:
divs.append(i)
if i!=n//i:
divs.append(n//i)
i += 1
return divs
N = int(input())
ds = make_divs(N)
ans = 0
for d in ds:
if d==1:
continue
N2 = N
while N2%d==0:
N2 //= d
if (N2-1)%d==0:
ans += 1
ans += len(make_divs(N-1))-1
print(ans)
|
n = int(input())
n_ = n-1
a = [n]
if n_ == 1:
a_ = []
else:
a_ = [n_]
for i in range(2,int(n**0.5//1+1)):
if n%i == 0:
a.append(i)
if n/i != i:
a.append(n/i)
if n_%i == 0:
a_.append(i)
if n_/i != i:
a_.append(n_/i)
ans = len(a_)
for i in a:
num = n
while num%i == 0:
num /= i
if num % i == 1:
ans += 1
print(ans)
| 1 | 41,396,685,844,892 | null | 183 | 183 |
for i in range(10000):
try:
a = eval(input())
print(int(a))
except:
break
|
# Belongs to : midandfeed aka asilentvoice
s = str(input())
ans = ""
for i in range(len(s)):
if s[i] == s[i].lower():
ans += s[i].upper()
else:
ans += s[i].lower()
print(ans)
| 0 | null | 1,098,252,298,542 | 47 | 61 |
import math
def main():
n, d = map(int, input().split())
ans = 0
for _ in range(n):
x, y = map(int, input().split())
ans += 1 if math.sqrt(x**2 + y**2) <= d else 0
print(ans)
if __name__ == '__main__':
main()
|
N,D = map(int,input().split())
count = 0
for i in range(N):
x,y = map(int,input().split())
if x**2+y**2 <= D**2:
count = count + 1
else:
count = count + 0
print(count)
| 1 | 5,995,640,435,806 | null | 96 | 96 |
n=int(input())
flag=0
for i in range(1,10):
if (n%i)==0:
if (n//i)<=9:
flag=1
break
if flag==1:
print ('Yes')
else:
print ('No')
|
l=int(input(""))
v=l*l*l
d=int(v/27)
print((v%27)/27+d)
| 0 | null | 103,874,687,737,032 | 287 | 191 |
n = int(raw_input())
num = map(int, raw_input().split())
num.reverse()
print " ".join(map(str, num))
|
a,b,c=map(int,input().split())
y=0
for i in range(b-a+1):
j=1
while (i+a)*j <= c:
if (i+a)*j==c:
y+=1
break
j+=1
print(y)
| 0 | null | 776,406,530,240 | 53 | 44 |
n=int(input())
a=list(map(int,input().split()))
if a[0]>=2:
print(-1)
else:
pN=1
s=1
l=[]
S=sum(a)
b=0
z=1
for k in range(len(a)):
b+=a[k]
l.append(b)
for i in range(1,n+1):
if a[i]>2*pN:
print(-1)
z=0
break
else:
pN=min(2*pN-a[i],S-l[i])
s+=pN
s+=S
if n==0:
s=1
if a[0]==1 and n>=1:
print(-1)
z=0
if z:
print(s)
|
def main():
n = int(input())
A = list(map(int, input().split()))
if n == 0:
if A[0] == 1:
return 1
else:
return -1
elif A[0] != 0:
return -1
bound = [0]*(n+1)
bound[n] = A[n]
for i in range(n-1, -1, -1):
bound[i] = bound[i+1] + A[i]
B = [0] * (n+1)
for i in range(n+1):
if i == 0:
B[i] = 1
else:
above = (B[i-1] - A[i-1]) * 2
if (i < n and above <= 0) or above < 0:
return -1
B[i] = min(above, bound[i])
if B[n] < A[n]:
return -1
# print('B: ', B)
return sum(B)
print(main())
| 1 | 18,920,403,695,158 | null | 141 | 141 |
X,N = map(int,input().split())
P = list(map(int,input().split()))
for n in range(100):
if X-n not in P:
print(X-n)
break
if X+n not in P:
print(X+n)
break
|
# AtCoder Beginner Contest 148
# D - Brick Break
N=int(input())
a=list(map(int,input().split()))
targetnum=1
breaknum=0
for i in range(N):
if a[i]==targetnum:
targetnum+=1
else:breaknum+=1
if breaknum==N:
print(-1)
else:
print(breaknum)
| 0 | null | 64,373,588,563,140 | 128 | 257 |
N = input()
keta = len(N)
dp = [[10**18 for i in range(2)] for j in range(keta)]
t = int(N[-1])
dp[0][0] = t
dp[0][1] = 10 - t
for i in range(keta - 2, -1, -1):
t = int(N[i])
#print(keta-i,i,t)
dp[keta-i-1][0] = min(dp[keta-i-2][0]+t,dp[keta-i-2][1]+t+1)
dp[keta-i-1][1] = min(dp[keta-i-2][0]+(10-t),dp[keta-i-2][1]+(10-(t+1)))
#a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
#print(dp)
print(min(dp[keta-1][0],dp[keta-1][1]+1))
|
def abc170_c_2():
"""
もっとシンプルに考えると
Xから-1、+1と順番に探索して、見つかったものをリターンすればOKなはず。
±0~99までを調べる?
"""
def solve():
x, n = map(int, input().split(' '))
if n == 0:
return x
p = list(map(int, input().split(' ')))
for i in range(100):
for s in [-1, +1]:
a = x + i * s
if a not in p:
return a
print(solve())
if __name__ == '__main__':
abc170_c_2()
| 0 | null | 42,560,268,288,480 | 219 | 128 |
def cum(n):
cum = 0
for i in range(n+1):
cum += i
return cum
s = input()
tmp = s[0]
count = 0
l = []
for each in s:
if each == tmp:
count += 1
else:
l.append(count)
count = 1
tmp = each
l.append(count)
ans = 0
if s[0] == "<":
for i in range(0,len(l),2):
tmp = l[i:i+2]
if len(tmp) == 1:
ans += cum(tmp[0])
else:
ans += cum(max(tmp)) + cum(min(tmp)-1)
else:
ans += cum(l[0])
for i in range(1, len(l),2):
tmp = l[i:i+2]
if len(tmp) == 1:
ans += cum(tmp[0])
else:
ans += cum(max(tmp)) + cum(min(tmp)-1)
print(ans)
|
# A - ><
S = input()
N = len(S)+1
INF = 1000000
ans = [0]*N
tmp = 0
for i in range(N-1):
if S[i]=='<':
tmp += 1
else:
tmp = 0
ans[i+1] = tmp
tmp = 0
for i in range(N-2,-1,-1):
if S[i]=='>':
tmp += 1
else:
tmp = 0
ans[i] = max(ans[i],tmp)
print(sum(ans))
| 1 | 156,976,198,252,510 | null | 285 | 285 |
S = input()
T = input()
U = T[0:len(S)]
if U == S:
print('Yes')
else:
print('No')
|
S = input()
T = input()
judge = T[0:len(S)]
if judge == S:
print("Yes")
else:
print("No")
| 1 | 21,459,239,630,400 | null | 147 | 147 |
N = int(input())
A = [0]*(N)
for i in input().split():
A[int(i)-1] = A[int(i)-1]+1
for i in A:
print(i)
|
N = int(input())
A = [int(i) for i in input().split()]
P = [0]*N
for i in range(N-1):
P[A[i]-1] += 1
for i in range(N):
print(P[i])
| 1 | 32,629,304,861,900 | null | 169 | 169 |
N, K = map(int, input().split())
p_list = list(map(int, input().split()))
p_list_E = []
p_list_E_temp = [1, 1.5, 2, 2.5, 3, 3.5]
for i in range(len(p_list)):
p_list_E.append((p_list[i]+1)*0.5)
#print(p_list_E)
p_list_sum = [0]
for i in range(0,N):
p_list_sum.append(p_list_sum[i]+p_list_E[i])
#print(p_list_sum)
ans = 0
for i in range(K,N+1):
ans = max(ans, p_list_sum[i]-p_list_sum[i-K])
print(ans)
|
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
"""
1 2
/2 = 1.5
1 2 3 4
/4 = 2.5
1 2 3 4 5
/5 = 3
"""
N, K = read_ints()
expectations = [(p+1)/2 for p in read_ints()]
max_e = current = sum(expectations[:K])
for i in range(1, N-K+1):
# remove i-1 add i+K
current = current-expectations[i-1]+expectations[i+K-1]
max_e = max(max_e, current)
return max_e
if __name__ == '__main__':
print(solve())
| 1 | 75,096,858,197,280 | null | 223 | 223 |
n,m = map(int,input().split())
if m != 0:
l = [list(input().split()) for i in range(m)]
p,s = [list(i) for i in zip(*l)]
t = [0] * n
ac = 0
wa = 0
for i in range(m):
if s[i] == 'WA' and t[int(p[i])-1] != 'AC':
t[int(p[i])-1] += 1
elif s[i] == 'AC' and t[int(p[i])-1] != 'AC':
ac += 1
wa += t[int(p[i])-1]
t[int(p[i])-1] = 'AC'
else:
pass
print(ac,wa)
|
n = int(input())
MOD = 1000000007
ans = pow(10,n,MOD) - pow(9,n,MOD) - pow(9,n,MOD) + pow(8,n,MOD)
print((ans+MOD)%MOD)
| 0 | null | 48,317,639,292,000 | 240 | 78 |
N, K = list(map(int, input().split()))
if abs(N - K) > N:
print(N)
else:
if N % K == 0:
N = 0
else:
N = abs(N % K - K)
print(N)
|
N, K = map(int, input().split())
N = N - (N // K)*K
ans = min(N, K-N)
print(ans)
| 1 | 39,563,158,935,420 | null | 180 | 180 |
a = int(input())
f = a + a**2 + a**3
print(f)
|
def result(x):
return x + x ** 2 + x ** 3;
n = int(input())
print(result(n))
| 1 | 10,291,003,035,872 | null | 115 | 115 |
H,W,N=[int(input()) for i in range(3)]
print(min((N+H-1)//H,(N+W-1)//W))
|
n,m=map(int,input().split())
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1]*n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x=self.find(x)
y=self.find(y)
if x== y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
uf = UnionFind(n)
ans=0
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)
| 0 | null | 46,314,099,898,868 | 236 | 84 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
a = abs(B-A)
if T * (V-W) >= a:
print("YES")
else:print("NO")
|
s=input()
k=int(input())
cnt=1
temp=[]
for i in range(len(s)-1):
if s[i]==s[i+1]: cnt+=1
else:
temp.append([s[i],cnt])
cnt=1
if cnt>=1: temp.append([s[-1],cnt])
if len(temp)==1:
print(k*len(s)//2)
exit()
ans=0
if temp[0][0]!=temp[-1][0]:
for pair in temp:
if pair[1]!=1: ans+=pair[1]//2
print(ans*k)
else:
for pair in temp[1:-1]:
if pair[1]!=1: ans+=pair[1]//2
ans*=k
ans+=(k-1)*((temp[0][1]+temp[-1][1])//2)
ans+=temp[0][1]//2+temp[-1][1]//2
print(ans)
| 0 | null | 95,272,544,423,932 | 131 | 296 |
string = input()
for i in range(int(input())):
lst = list(map(str, input().split()))
if lst[0] == "replace":
string = string[:int(lst[1])] + lst[3] + string[int(lst[2])+1:]
if lst[0] == "reverse":
rev_str = str(string[int(lst[1]):int(lst[2])+1])
string = string[:int(lst[1])] + rev_str[::-1] + string[int(lst[2])+1:]
if lst[0] == "print":
print(string[int(lst[1]):int(lst[2])+1])
|
s = input()
n = int(input())
for i in range(n):
order, a, b, *c = input().split()
a = int(a)
b = int(b)
if order == 'replace':
s = s[:a] + c[0] + s[b+1:]
elif order[0] == 'r':
s = s[:a] + s[::-1][len(s)-b-1:len(s)-a]+ s[b+1:]
else:
print(s[a:b+1])
| 1 | 2,104,139,961,890 | null | 68 | 68 |
k=int(input())
a,b=map(int,input().split())
print("OK" if a//k < b//k or a%k==0 or b%k==0 else "NG")
|
k = int(input())
a, b = map(int,input().split())
flg = False
for i in range(a, b+1):
if i % k == 0:
flg = True
break
print('OK') if flg else print('NG')
| 1 | 26,572,494,234,118 | null | 158 | 158 |
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
if (a+b)%3!=0:
print(0)
sys.exit()
s=(a+b)//3
a-=s
b-=s
if a<0 or b<0:
print(0)
sys.exit()
fac=[1]*700000
for i in range(1,700000):
fac[i]=(fac[i-1]*i)%mod
m=a+b
n=min(a,b)
c=1
for j in range(m,m-n,-1):
c*=j
c=c%mod
print((c*pow(fac[n],mod-2,mod))%mod)
|
x,y = map(int,input().split())
if (x+y)%3!=0:print(0);exit()
mod = 10**9+7
n = (x+y)//3
m = min(x-n,y-n)
frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r):
if n<0 or r<0 or n<r: return 0
r = min(r,n-r)
return frac[n]*finv[n-r]*finv[r]%mod
print(nCr(n,m)%mod)
| 1 | 150,180,074,452,108 | null | 281 | 281 |
s = input()
t = input()
c = 0
for i in range(len(s)):
if not s[i] == t[i]:
c += 1
print(c)
|
while True :
x = input()
if x==0:
break
else:
Count = 0
while x>0 :
Count += x%10
x /= 10
print '%d' %Count
| 0 | null | 6,083,012,479,092 | 116 | 62 |
import sys
a, b = map(int, sys.stdin.readline().split())
if a <= 9 and b <= 9:
print(a*b)
else:
print(-1)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
A, B = map(int, readline().split())
if A < 10 and B < 10:
print(A * B)
else:
print(-1)
return
if __name__ == '__main__':
main()
| 1 | 158,853,231,623,280 | null | 286 | 286 |
h,w=map(int,input().split())
s=[input() for _ in range(h)]
dp=[[10**9]*w for _ in range(h)]
dp[0][0]=(s[0][0]=='#')+0
for i in range(h):
for j in range(w):
a=dp[i-1][j]
b=dp[i][j-1]
if s[i-1][j] == "." and s[i][j] == "#":
a+=1
if s[i][j-1] == "." and s[i][j] == "#":
b+=1
dp[i][j]=min(a,b,dp[i][j])
print(dp[-1][-1])
|
def resolve():
H, W = map(int, input().split(" "))
s = []
dp = [[0] * W for i in range(H)]
for _ in range(H):
s.append([x == "." for x in list(input())])
for h in range(H):
for w in range(W):
if h == 0 and w == 0:
if not s[0][0]:
dp[0][0] = 1
elif h == 0:
dp[0][w] = dp[0][w-1]
if s[0][w-1] and not s[0][w]:
dp[0][w] += 1
elif w == 0:
dp[h][0] = dp[h-1][0]
if s[h-1][0] and not s[h][0]:
dp[h][0] += 1
else:
# 左側と上側を見て、操作回数が最小になるようにする。
# 上だけをみる
temp_up = dp[h-1][w]
if s[h-1][w] and not s[h][w]:
temp_up += 1
# 左だけを見る
temp_left = dp[h][w-1]
if s[h][w-1] and not s[h][w]:
temp_left += 1
dp[h][w] = min(temp_up, temp_left)
print(dp[H-1][W-1])
if __name__ == "__main__":
resolve()
| 1 | 49,178,139,890,310 | null | 194 | 194 |
n = int(input())
ren = 0
for i in range(n):
a, b = (int(x) for x in input().split())
if a == b:
ren += 1
elif ren >= 3:
continue
else:
ren = 0
if ren >= 3:
print("Yes")
else:
print("No")
|
import sys
#import numpy as np
import copy
fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])
list = []
for i in range(N):
tlist = []
line = input().split(' ')
tlist = [line[0], line[1]]
#print(tlist)
list.append(tlist)
#print(list)
current = 0
while len(list) != 0:
if int(list[0][1]) <= Q:
current += int(list[0][1])
print(list[0][0] + " " + str(current))
del list[0]
else:
list[0][1] = str((int)(list[0][1])-Q)
list.append(list[0])
del list[0]
current += Q
#print(list)
| 0 | null | 1,278,681,635,754 | 72 | 19 |
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint,time,random
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()))
def cal(T):
res = 0
last = [0] * 26
for day in range(D):
t = T[day]; t -= 1
last[t] = 0
res += s[day][t]
for i in range(26):
if i == t: continue
last[i] += 1
res -= c[i] * last[i]
return res
def check_change(td,tq):
global score,res
old_q = res[td]
res[td] = tq
now = cal(res)
if now > score:
score = now
else:
res[td] = old_q
def out():
global res
for x in res:
print(x)
quit()
start_time = time.time()
n = 26
D = inp()
c = inpl()
s = []
max_s = []
for i in range(D):
tmp = inpl()
mx = 0; ind = -1
for j in range(n):
if tmp[j] > mx:
mx = tmp[j]
ind = j
max_s.append(ind+1)
s.append(tmp)
last = [0] * n
res = [-1] * D
for d in range(D):
ans = -1
mx = -INF
for i in range(n):
now = s[d][i]
for j in range(n):
if i == j: continue
now -= s[d][j] * (last[j]+1)
if now > mx:
mx = now
ans = i
res[d] = ans+1
for j in range(n):
last[j] += 1
if j == ans: last[j] = 0
score = cal(res)
# print(now_score)
while True:
if time.time() - start_time > 1.3: break
td,tq = random.randrange(0,D), random.randrange(1,n+1)
check_change(td,tq)
for x in itertools.combinations(range(D), 2):
if time.time() - start_time > 1.83: out()
old = []
if sum(x^y for x,y in zip(res,max_s)) == 0: continue
for i in range(2):
old.append(res[x[i]])
res[x[i]] = max_s[x[i]]
now = cal(res)
if now > score:
score = now
else:
for i in range(2):
res[x[i]] = old[i]
|
import sys
input = sys.stdin.buffer.readline
import numpy as np
D = int(input())
c = np.array(input().split(), dtype=np.int32)
s = np.array([input().split() for _ in range(D)], dtype=np.int32)
last = np.zeros(26, dtype=np.int32)
ans = []
point = 0
for i in range(D):
down = (i+1-last)*c
loss = down * 3 + s[i,:]
idx = np.argmax(loss)
ans.append(idx+1)
point += s[i, idx] - down.sum()
last[idx] = i+1
for i in range(D):
print(ans[i])
| 1 | 9,647,622,707,750 | null | 113 | 113 |
import sys
input = lambda: sys.stdin.readline().rstrip()
n=int(input())
s=0 ; st=set() ; ans=[[] for i in range(n)] ; v=0
def dfs(g,v):
global s,st,ans
if v in st: return
else: st.add(v)
s+=1
ans[v].append(s)
for i in g[v]:
dfs(g,i)
s+=1
ans[v].append(s)
g=[]
for _ in range(n):
a=[int(i)-1 for i in input().split()]
if a[1]==-1: g.append([])
else: g.append(a[2:])
for i in range(n):
if i in st : continue
else : dfs(g,i)
for i in range(len(ans)):
print(i+1,*ans[i])
|
def main():
n=int(input())
u,k,v=0,0,[[] for _ in range(n+1)]
for i in range(n):
l=list(map(int,input().split()))
u=l[0]
for j in l[2:]:
v[u].append(j)
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(s,t):
d[s]=t
for i in v[s]:
if d[i]==0:
t=dfs(i,t+1)
f[s]=t+1
return t+1
s,t=1,1
while 0 in d[1:]:
T=dfs(s,t)
for i in range(1,n+1):
if d[i]==0:
s=i
t=T+1
break
for i in range(1,n+1):
print(i,d[i],f[i])
if __name__ == '__main__':
main()
| 1 | 2,537,678,770 | null | 8 | 8 |
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
B = [1] * (max(A) + 1)
for a in A:
for k in range(a * 2,len(B),a):
B[k] = 0
print(sum(B[a] == 1 and counter[a] == 1 for a in A))
|
n = int(input())
A = sorted(list(map(int, input().split())))
dp = [0] * (10 ** 6 + 10)
for x in A:
i = 0
while x + i <= 10 ** 6 + 10:
if dp[(x-1)] == 2:
break
else:
dp[(x-1) + i] += 1
i += x
cnt = 0
for x in A:
if dp[x-1] == 1:
cnt += 1
print(cnt)
| 1 | 14,388,480,815,902 | null | 129 | 129 |
k=int(input())
a,b=map(int,input().split())
count=a
while count <= b:
if count%k == 0:
print("OK")
break
else:
count += 1
else:
print("NG")
|
def main():
from string import ascii_lowercase
N = int(input())
ans = []
def dfs(s='a', ma='a'):
if len(s) == N:
ans.append(s)
return
for c in ascii_lowercase:
dfs(s + c, max(c, ma))
if c > ma: break
dfs()
print(*ans, sep='\n')
if __name__ == '__main__':
main()
| 0 | null | 39,335,459,944,400 | 158 | 198 |
def digits(n):
if n < 10: return 1
c = 0
while n > 0:
c += 1
n = n // 10
return c
while 1:
try:
inp = input()
except EOFError:
break
else:
n, m = inp.split(' ')
n = int(n)
m = int(m)
print(digits(n + m))
|
n=int(input())
p=[int(x) for x in input().split()]
a=1
b=p[0]
for i in range(1,n):
if p[i-1]<b:
b=p[i-1]
if p[i]<=b:
a+=1
print(a)
| 0 | null | 42,886,058,748,350 | 3 | 233 |
k=int(input())
s=input()
mod=10**9+7
import sys
sys.setrecursionlimit(10**9)
def cmb(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
p = mod #割る数
N = 2*(10 ** 6) # N は必要分だけ用意する
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
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)
ans=0
for i in range(k+1):
ans = (ans+cmb(i+len(s)-1,i,mod)*pow(26,k-i,mod)*pow(25,i,mod)) % mod
#print(end,len(s)+k-end,ans,cmb(end,len(s),mod),pow(25,end-len(s),mod),pow(26,len(s)+k-end,mod))
print(ans%mod)
|
MAX = 10**6 * 3
MOD = 10**9+7
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
#前処理 逆元テーブルを作る
def COMinit():
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i-1] * i % MOD
inv[i] = MOD - inv[MOD%i] * (MOD//i)%MOD
finv[i] = finv[i-1] * inv[i] % MOD
#実行
def COM(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
k = int(input())
s = input()
n = len(s)
COMinit()
ans = 0
for i in range(k+1):
pls = pow(25, i, MOD)
pls *= pow(26,k-i, MOD)
pls %= MOD
pls *= COM(i+n-1, i)
ans += pls
ans %= MOD
print(ans%MOD)
| 1 | 12,808,621,011,212 | null | 124 | 124 |
a, b = map(float, input().split())
print(int(a)*int(b*100+0.5)//100)
|
A, B = input().split(" ")
A = int(A.strip())
B = int(B.strip().replace(".", ""))
print(A * B // 100)
| 1 | 16,609,992,273,028 | null | 135 | 135 |
from collections import deque
N,K = map(int,input().split())
R,S,P = map(int,input().split())
Tlist = input()
Answer = 0
def po(x):
if x == 's':
return R
elif x == 'r':
return P
else:
return S
for i in range(K):
TK = list(Tlist[i::K]).copy()
TK.append('')
T2 = TK[0]
sig = 2
for i in range(1,len(TK)):
T1 = T2
T2 = TK[i]
if T1 == T2 and i != len(TK)-1:
sig += 1
else:
Answer += po(T1)*(sig//2)
sig = 2
print(Answer)
|
a, b = int(input()), int(input())
if 1 not in [a, b]:
print(1)
elif 2 not in [a, b]:
print(2)
else:
print(3)
| 0 | null | 109,344,656,578,420 | 251 | 254 |
from itertools import combinations
N=int(input())
d=list(map(int,input().split()))
c=list(combinations(d,2))
ans=0
for i in range(len(c)):
a=c[i][0]*c[i][1]
ans+=a
print(ans)
|
n,m=map(int,input().split())
parent=[*range(n)]
sz=[1]*n
def anc(a):
# print(a)
if parent[a]==a:
return a
else:
return(anc(parent[a]))
def union(a,b):
pa=anc(a)
pb=anc(b)
if sz[pb]<sz[pa]:
pa,pb=pb,pa
parent[pa]=pb
sz[pb]+=sz[pa]
sz[pa]=0
# print(parent)
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
if anc(a)!=anc(b):
union(a,b)
# print(parent,a,b)
print(max(sz))
| 0 | null | 86,449,869,780,830 | 292 | 84 |
X, K, D = map(int,input().split())
X = abs(X)
if X > K*D:
print( X - K*D )
else:
a = X//D
K -= a
X -= D*a
if K%2 == 0:
print(X)
else:
print(abs(X-D))
|
mod=10**9+7
k=int(input())
s=input()
l=len(s)
fact=[1]
for i in range(1,k+l+1):
fact.append((fact[-1]*i)%mod)
revfact=[]
for i in range(k+l+1):
revfact.append(pow(fact[i],mod-2,mod))
pow1=[1]
pow2=[1]
for i in range(1,k+l+1):
pow1.append((pow1[-1]*25)%mod)
pow2.append((pow2[-1]*26)%mod)
ans=0
for i in range(k+l):
coef1=(pow1[k-i]*pow2[i])%mod
if i<=k:
coef2=(fact[k+l-1-i]*revfact[l-1]*revfact[k-i])%mod
else:
coef2=0
ans+=coef1*coef2
ans%=mod
print(ans)
| 0 | null | 8,947,256,754,750 | 92 | 124 |
A = input()
while(A != '-'):
m = int(input())
for i in range(m):
h = int(input())
A = A[h:]+A[:h]
print(A)
A = input()
|
while True:
deck = input()
if deck == "-":
break
m = int(input())
for i in range(m):
h = int(input())
deck += deck[:h]
deck = deck[h:]
print(deck)
| 1 | 1,939,445,892,580 | null | 66 | 66 |
_str = ""
_k = int(input())
for _i in range(_k):
_str += "ACL"
print(_str)
|
K = int(input())
c = ''
for i in range(1,K+1):
c += 'ACL'
print(c)
| 1 | 2,183,959,456,860 | null | 69 | 69 |
import fractions
while True:
try:
a,b = map(int,input().split())
except:
break
print(fractions.gcd(a,b),a*b // fractions.gcd(a,b))
|
def gcd(a,b):
if a%b==0:
return b
return gcd(b,a%b)
while True:
try:
a,b=sorted(map(int,input().split()))
except:
break
print(gcd(a,b),a//gcd(a,b)*b)
| 1 | 654,813,500 | null | 5 | 5 |
import sys
input = sys.stdin.readline
n, x, res = int(input()), 1, 0
if n & 1: print(0)
else:
n //= 2
while x < n:
x *= 5
res += n // x
print(res)
|
n = int(input())
ans = 0
d = 10
if n%2==1:
print(0)
import sys
sys.exit()
while True:
ans += n//d
d *= 5
if d>n:
break
print(ans)
| 1 | 116,164,894,370,148 | null | 258 | 258 |
n = int(input())
for i in range(1, n+1):
if i%3 == 0 or str(i).find('3') != -1:
print(f" {i}", end = '')
print()
|
import sys
n = int(raw_input())
#n = 30
for i in range(1, n+1):
if i % 3 == 0:
sys.stdout.write(" {:}".format(i))
elif str(i).find('3') > -1:
sys.stdout.write(" {:}".format(i))
print("")
| 1 | 912,011,033,732 | null | 52 | 52 |
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
for _ in range(K):
count_list = [0] * N
for i, v in enumerate(A_list):
count_list[i - v if i - v > 0 else 0] += 1
if i + v + 1 < N:
count_list[i + v + 1] -= 1
temp = 0
flag = True
for i in range(len(A_list)):
temp += count_list[i]
if temp != N:
flag = False
A_list[i] = temp
if flag:
break
print(*A_list)
|
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
b = [0] * (n + 1)
for i in range(n):
left_edge = max(0, i-a[i])
right_edge = min(i + a[i] + 1, n)
b[left_edge] += 1
b[right_edge] -= 1
for i in range(1, n+1):
b[i] = b[i] + b[i-1]
b.pop(n)
if a == b:
break
a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))
| 1 | 15,502,470,120,478 | null | 132 | 132 |
def DFS(G):
ans = [0] + [[0,0,0] for _ in range(len(G))]
def main(G,i):
ans[0] += 1
ans[i] = [i, ans[0], ans[0]]
for j in sorted(G[i-1][2:]):
if ans[j][0] == 0: main(G,j)
ans[0] += 1
ans[i][2] = ans[0]
for u in G:
if ans[u[0]][0] == 0: main(G,u[0])
return ans[1:]
if __name__=='__main__':
n = int(input())
G = [list(map(int,input().split())) for _ in range(n)]
for out in DFS(G): print(*out)
|
H, W = map(int, input().split())
L = [input() for _ in range(H)]
inf = 10**9
dp = [[inf] * W for _ in range(H)]
#[0][0]を埋める
if (L[0][0] == '.'):
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(H):
for j in range(W):
#[0][0]の時は無視
if (i == 0 and j == 0):
continue
#→の場合。一個前のマス。
a = dp[i][j - 1]
#↓の場合。一個前のマス。
b = dp[i - 1][j]
#.から#に移動するときだけ操作が(1回)必要
if (L[i][j - 1] == "." and L[i][j] == "#"):
a += 1
if (L[i - 1][j] == '.' and L[i][j] == '#'):
b += 1
# min(dp[i][j],a,b)でもいいが結局問題になるのはa,bの比較だけでは?
dp[i][j] = min(a, b)
print(dp[-1][-1])
| 0 | null | 24,712,452,681,462 | 8 | 194 |
L = int(input())
x = L/3
y = L/3
z = L - x - y
print(x*y*z)
|
# -*- coding:utf-8 -*-
import math
def insertion_sort(num_list, length, interval):
cnt = 0
for i in range(interval, length):
v = num_list[i]
j = i - interval
while j >= 0 and num_list[j] > v:
num_list[j+interval] = num_list[j]
j = j - interval
cnt = cnt + 1
num_list[j+interval] = v
return cnt
def shell_sort(num_list, length):
cnt = 0
h = 4
intervals = [1,]
while length > h:
intervals.append(h)
h = 3 * h + 1
for i in reversed(range(len(intervals))):
cnt = cnt + insertion_sort(num_list, length, intervals[i])
print(len(intervals))
print(*reversed(intervals))
print(cnt)
input_num = int(input())
input_list = list()
for i in range(input_num):
input_list.append(int(input()))
shell_sort(input_list, input_num)
for num in input_list:
print(num)
| 0 | null | 23,493,381,452,268 | 191 | 17 |
c = 0
while True:
try:
n = int(input())
except EOFError:
break
c += 1
for i in range(2, int(n ** 0.5 + 1)):
if n % i == 0:
c -= 1
break
print(c)
|
import sys
input = lambda: sys.stdin.readline().rstrip()
def resolve():
S = input()
cnt = [0]*2019
cnt[0] = 1
# Sの右側から1ずつ左に伸ばして、cntの対応するところに加算
rmd = 0
num_rate = 1
L = len(S)
for i in range(L):
rmd = (int(S[L-i-1])*num_rate + rmd) % 2019
num_rate = num_rate*10%2019
cnt[rmd] += 1
ans = sum([i*(i-1)//2 for i in cnt])
print(ans)
if __name__ == '__main__':
resolve()
| 0 | null | 15,363,646,599,940 | 12 | 166 |
from itertools import groupby
S=input()
K=int(input())
count=0
group=[len(list(value)) for key,value in groupby(S)]
for value in group:
count+=value//2
count*=K
if S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0:
if len(S)==group[0]:
count+=K//2
else:
count+=K-1
print(count)
|
s = input()
k = int(input())
from itertools import groupby
n=len(s)
cnt =0
gp = groupby(s)
Keys=[]
values=[]
for key,value in gp:
Keys.append(key)
values.append(len(list(value)))
if len(Keys)==1:
print(values[0]*k//2)
exit(0)
if k==1:
for i in values:
cnt+=i//2
print(cnt)
exit(0)
if k>=2:
if Keys[0]==Keys[-1]:
values2=list(reversed(values))
m=len(values)
for i in range(m-1):
if values[i]>=2:
cnt+=values[i]//2
if values2[i]>=2:
cnt+=values2[i]//2
cnt+= (k-1) * ((values[0]+values[-1])//2)
for j in range(m):
if j==0 or j==m-1:
continue
else:
cnt+= (k-2)*(values[j]//2)
print(cnt)
exit(0)
for i in values:
if i>1:
cnt += k*(i//2)
print(cnt)
| 1 | 175,459,387,129,780 | null | 296 | 296 |
input = raw_input()
input_items = input.split()
a = int(input_items[0])
b = int(input_items[1])
area = a * b
length = 2*a + 2*b
print str(area) + ' ' + str(length)
|
n = int(input())
a = list(map(int,input().split()))
x = 1
if 0 in a:
print(0)
exit()
for e in a:
x *= e
if x > 10**18:
print(-1)
exit()
print(x)
| 0 | null | 8,211,081,147,948 | 36 | 134 |
n,x,m = map(int,input().split())
mod = m
amari = [-1]*m
a = x
cnt = 1
l = 0
r = 0
while 1:
# print(a)
if cnt == n:
break
if amari[a] != -1:
l = amari[a]
r = cnt
# print(a,amari[a])
break
else:
amari[a] = cnt
cnt += 1
a = ((a % m)**2) % m
# if cnt > m:
# print("error")
# exit()
ans = 0
if cnt == n:
l = 0
r = n
# print(l,r)
a = x
temp = 0
for i in range(l-1):
ans += a
a = (a**2) % mod
# print(ans)
for i in range(r-l):
temp += a
a = (a**2) % mod
ans += temp * ((n-l+1)//(r-l))
# print(ans,a,temp,temp * (n-l)//(r-l),(n-l)//(r-l),temp * ((n-l)//(r-l)))
if r != n:
for i in range((n-l+1)%(r-l)):
ans += a
a = (a**2) % mod
# print(ans)
if n == 1:
ans //=2
print(ans)
|
import sys
args = input()
print(args[:3])
| 0 | null | 8,762,143,345,020 | 75 | 130 |
s=input()
n=len(s)
ans='x'*n
print(ans)
|
N = int(input())
minP = N
count = 0
for pi in map(int, input().split()):
minP = min(minP, pi)
if pi <= minP:
count += 1
print(count)
| 0 | null | 79,396,318,914,558 | 221 | 233 |
def abc150_d():
n, m = (int(x) for x in input().split())
A = [int(x) // 2 for x in input().split()]
from math import gcd
def lcm(a, b):
return a * b // gcd(a, b)
x = 1
for a in A:
x = lcm(x, a)
valid = True
for a in A:
if (x // a) % 2 == 0:
valid = False
break
if valid: ans = (m // x + 1) // 2
else: ans = 0
print(ans)
if __name__ == '__main__':
abc150_d()
|
n, k = map(int, input().split())
ans = 1
while(True):
n = n//k
if(n == 0):
break
ans += 1
print(ans)
| 0 | null | 83,147,602,519,948 | 247 | 212 |
x = int(input())
y = pow(x,3)
print(y)
|
class Dice:
def __init__(self, U, S, E, W, N, D):
self.u, self.d = U, D
self.e, self.w = E, W
self.s, self.n = S, N
def roll(self, commmand):
if command == 'E':
self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
elif command == 'W':
self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
elif command == 'S':
self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
else:
self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n
def rightside(self, upside, forward):
self.structure = {self.u:{self.w: self.s, self.s: self.e, self.e: self.n, self.n: self.w},
self.d:{self.n: self.e, self.e: self.s, self.s: self.w, self.w: self.n},
self.e:{self.u: self.s, self.s: self.d, self.d: self.n, self.n: self.u},
self.s:{self.u: self.w, self.w: self.d, self.d: self.e, self.e: self.u},
self.w:{self.u: self.n, self.n: self.d, self.d: self.s, self.s: self.u},
self.n:{self.u: self.e, self.e: self.d, self.d: self.w, self.w: self.u}}
print(self.structure[upside][forward])
U, S, E, W, N, D = [int(i) for i in input().split()]
turns = int(input())
dice1 = Dice(U, S, E, W, N, D)
for i in range(turns):
upside, forward = [int(k) for k in input().split()]
dice1.rightside(upside, forward)
| 0 | null | 273,389,531,900 | 35 | 34 |
def main():
a, b = map(int, input().split())
if a == b:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
|
kazu=int(input())
A=[int(i) for i in input().split()]
# kazu=6
# A=[5,2,4,6,1,3]
j=0
for i in range(kazu - 1):
print(A[i], end=" ")
print(A[kazu-1])
for i in range(1,kazu):
v=A[i]
j=i-1
while j>=0 and A[j] >v:
A[j+1]=A[j]
j =j -1
A[j+1]=v
for i in range(kazu-1):
print(A[i],end=" ")
print(A[kazu-1])
| 0 | null | 41,464,016,554,972 | 231 | 10 |
H,W,N=[int(input()) for i in range(3)]
print((N+max(H,W)-1)//max(H,W))
|
H, W, N = map(int, open(0).read().split())
if H > W:
H, W = W, H
print((N + W - 1) // W)
| 1 | 88,415,901,177,190 | null | 236 | 236 |
import math
n=int(input())
a=1000000007
print( (pow(10,n)-pow(9,n)*2+pow(8,n))%a)
|
N = int(input())
ans = 10**N -( 9**N + 9**N - 8**N )
print( ans%( 10**9 + 7) )
| 1 | 3,188,112,176,440 | null | 78 | 78 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
X, Y, Z = lr()
print(Z, X, Y)
|
N = int(input())
S = input()
P = 0
count = 0
for j in range(1000):
V = str(P).zfill(3)
p1 = False
p2 = False
for i in range(N):
if S[i] == V[0] and not p1:
p1 = True
continue
if S[i] == V[1] and p1 and not p2:
p2 = True
continue
if S[i] == V[2] and p2:
count += 1
break
P += 1
print (count)
| 0 | null | 83,269,856,676,608 | 178 | 267 |
n, q = map(int, input().split())
queue = list()
for i in range(n):
p = input().split()
queue.append({"name": p[0], "time": int(p[1])})
t = 0
while len(queue) > 0:
proc = queue.pop(0)
if q < proc["time"]:
proc["time"] -= q
t += q
queue.append(proc)
else:
t += proc["time"]
print(proc["name"], t)
|
# coding: utf-8
import sys
from collections import deque
n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
for task in tasks:
task[1] = int(task[1])
try:
while True:
t = tasks.popleft()
if t[1] - q <= 0:
total_time += t[1]
print(t[0], total_time)
else:
t[1] = t[1] - q
total_time += q
tasks.append(t)
except Exception:
pass
| 1 | 41,654,002,404 | null | 19 | 19 |
#!/usr/bin/env python3
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
Acnt = [0] * N
Acnt[0] = 1
telepo = [1]
i = 0
while True:
Acnt[A[i] - 1] += 1
if Acnt[A[i] - 1] > 1:
break
telepo.append(A[i])
i = A[i] - 1
roop_s = telepo.index(A[i])
roop = len(telepo) - roop_s
ans = 0
if K < roop_s:
ans = K
else:
ans = K - roop_s
ans %= roop
ans += roop_s
print(telepo[ans])
if __name__ == "__main__":
main()
|
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
n = int(input())
A = [[int(i) for i in input().split()]for j in range(n)] # nは行数
tmp = 0
res = 0
x = np.median(np.array(A), axis=0)
if n % 2 == 0:
res = int((x[1] - x[0]) * 2 + 1)
else:
res = int(x[1] - x[0] + 1)
print(res)
| 0 | null | 20,133,142,648,682 | 150 | 137 |
a = int(input())
b = a * a * a
print(b)
|
import sys
import fractions
input = sys.stdin.readline
mod = 10 ** 9 + 7
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
lcm = 1
for a in A:
lcm = a // fractions.gcd(a, lcm) * lcm
print(sum([lcm // a for a in A]) % mod)
| 0 | null | 43,836,268,997,888 | 35 | 235 |
n = int(input())
ans = 0
for i in range(1,n+1):
ans += (i + i*(n//i))*(n//i)/2
print(int(ans))
|
import sys
input = sys.stdin.readline
N = int(input())
S = input().rstrip()
Q = int(input())
qs = [input().split() for i in range(Q)]
def ctoi(c):
return ord(c) - ord('a')
class BinaryIndexedTree:
def __init__(self,size):
self.N = size
self.bit = [0]*(size+1)
def add(self,x,w):
while x <= self.N:
self.bit[x] += w
x += (x & -x)
def sum(self,x):
ret = 0
while x > 0:
ret += self.bit[x]
x -= (x & -x)
return ret
bits = [BinaryIndexedTree(N) for _ in range(26)]
for i,c in enumerate(S):
bits[ctoi(c)].add(i+1,1)
s = list(S)
ans = []
for a,b,c in qs:
if a=='1':
x = int(b)
bits[ctoi(c)].add(x,1)
bits[ctoi(s[x-1])].add(x,-1)
s[x-1] = c
else:
tmp = 0
for i in range(26):
if bits[i].sum(int(c)) - bits[i].sum(int(b)-1) > 0:
tmp += 1
ans.append(tmp)
print(*ans, sep='\n')
| 0 | null | 36,848,894,538,930 | 118 | 210 |
string = input()
string = string*2
if string.count(input()):
print("Yes")
else:
print("No")
|
words = input()
makeword = input()
words = words + words
if makeword in words:
print('Yes')
else:
print('No')
| 1 | 1,732,443,375,270 | null | 64 | 64 |
a,b = map(int,input().split())
if 9 < a or 9 < b:
print(-1)
else:
print(a*b)
|
a,b=map(int,input().split())
print(a*b if a>=1 and a<=9 and 0<b<10 else -1)
| 1 | 158,205,792,674,838 | null | 286 | 286 |
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
from math import floor
input = lambda : given().rstrip()
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
XLMIIS = lambda x : [LMIIS() for _ in range(x)]
N,K = LMIIS()
A = LMIIS()
F = LMIIS()
F.sort()
A.sort(reverse=True)
def f(x):
sum_diff = 0
for a,f in zip(A,F):
if a*f-x > 0:
sum_diff += a-x//f
return True if sum_diff <= K else False
l = -1
r = 10**13
while r-l>1:
m = (l+r)//2
if f(m):
r = m
else:
l = m
print(r)
if __name__ == '__main__':
main()
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
def check(mid):
cnt = 0
for i in range(N):
tmp = mid // F[i]
cnt += max(A[i] - tmp, 0)
return cnt <= K
check(2)
l, r = -1, 10**30
while r-l > 1:
mid = (l+r)//2
if check(mid):
r = mid
else:
l = mid
print(r)
| 1 | 165,393,484,705,140 | null | 290 | 290 |
a,b=map(int,raw_input().split());print a/b,a%b,"%.6f"%(1.*a/b)
|
from math import gcd, ceil
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = [a//2 for a in A]
B = 1
for a in A:
B*=a//gcd(B,a)
for a in A:
if B//a%2==0:
print(0)
exit()
print(ceil((M//B)/2))
| 0 | null | 51,064,557,199,280 | 45 | 247 |
n = int(input())
i = 1
while i * 1000 < n:
i += 1
print(i*1000 - n)
|
N = int(input())
if N%1000==0:
q = N//1000-1
else:
q = N//1000
ans = 1000*(q+1)-N
print(ans)
| 1 | 8,415,992,236,200 | null | 108 | 108 |
n=int(input())
p=n
yakusu=[]
for i in range(1,int(n**0.5)+1):
if n%i==0:
yakusu.append(i)
if i!=n//i:
yakusu.append(n//i)
p-=1
yakusu_1=[]
for i in range(1,int(p**0.5)+1):
if p%i==0:
yakusu_1.append(i)
if i!=p//i:
yakusu_1.append(p//i)
ans=len(yakusu_1)-1
for x in yakusu:
r=n
if x!=1:
while r%x==0:
r//=x
if (r-1)%x==0:
ans+=1
print(ans)
|
H = int(input())
W = int(input())
N = int(input())
r = (N +max(H, W)-1)//max(H, W)
print(r)
| 0 | null | 64,786,976,539,680 | 183 | 236 |
n,s = [input() for _ in range(2)]
print(s.count("ABC"))
|
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
n = int(input())
s = input()
ans = 0
aDec = False
bDec = False
for i in range(n):
if s[i] == "A":
aDec = True
bDec = False
elif s[i] == "B":
if (aDec):
bDec = True
else:
bDec = False
aDec = False
elif s[i] == "C":
if (bDec):
ans += 1
bDec = False
aDec = False
else:
bDec = False
aDec = False
print(ans)
| 1 | 99,659,936,520,740 | null | 245 | 245 |
n, q = map(int, input().split())
s = list()
process = 0
t = list()
for i in range(n):
name, time = map(str, input().split())
s.append([name, int(time)])
flag = True
while s:
diff = s[0][1] - q
if diff <= 0:
process += s[0][1]
t.append([s[0][0], process])
s.pop(0)
else:
process += q
s.append([s[0][0], diff])
s.pop(0)
for i in t:
print(i[0], i[1])
|
ls = map(int, raw_input().split())
n = 0
for x in xrange(ls[0], ls[1]+1):
if ls[2]%x==0:
n+=1
print n
| 0 | null | 300,274,582,698 | 19 | 44 |
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
def solution(A, S):
N = len(A)
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
for j in range(S+1):
dp[i][j] += 2*dp[i-1][j]
dp[i][j] %= MOD
if j >= A[i-1]:
dp[i][j] += dp[i-1][j-A[i-1]]
dp[i][j] %= MOD
return dp[N][S]
print(solution(A, S))
|
i = input()
if(i=='ABC'):
print('ARC')
else:
print('ABC')
| 0 | null | 20,893,641,528,792 | 138 | 153 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.