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 math
A, B, H, M = map(int, input().split())
SP_HOUR = 360 / (12 * 60)
SP_MIN = 360 / 60
angle = (H * 60 + M) * SP_HOUR - M * SP_MIN
if angle < 0:
angle += 360
# print(math.cos(0))
# print(math.cos(3.14))
# print("angle", angle)
# print("angle in radian", math.radians(angle))
#Law of cosines
ans_squ = A * A + B * B - 2 * A * B * math.cos(math.radians(angle))
print(math.sqrt(ans_squ))
|
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
mid = (ok+ng)//2
cur = 0
for i in range(n):
cur += L[i]//mid
if cur > k:
ok = mid
elif cur <= k:
ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
res = 0
if K[i] > 0:
for j in range(n):
res += (L[j]-1)//K[i]
if res <= k:
P.append(K[i])
print(min(P))
| 0 | null | 13,277,846,509,310 | 144 | 99 |
N,A,B = map(int,input().split())
a = N//(A+B)
b = N%(A+B)
if b>A:
print(a*A+A)
else:
print(a*A+b)
|
n, a, b = map(int, input().split())
q = n // (a + b)
mod = n % (a + b)
if mod > a:
remain = a
else:
remain = mod
print(q * a + remain)
| 1 | 55,523,765,140,658 | null | 202 | 202 |
n = int(input())
s = input()
if n % 2 != 0:
print("No")
else:
t = s[:int((n / 2))]
u = t + t
print("Yes" if s == u else "No")
|
n = int(input())
s = input()
if len(s) % 2 == 1:
print('No')
else:
mid = len(s)//2
if s[:mid] == s[mid:]:
print('Yes')
else:
print('No')
| 1 | 146,878,173,859,428 | null | 279 | 279 |
def main():
print('ARC' if input()== 'ABC' else 'ABC')
if __name__ == "__main__":
main()
|
contests = ['ABC', 'ARC']
before_contest = input()
print(contests[0] if before_contest == contests[1] else contests[1])
| 1 | 24,029,055,861,900 | null | 153 | 153 |
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()
|
from collections import defaultdict
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
n,a,b = readInts()
if (b-a)%2==0:
print((b-a)//2)
else:
print(min(b-1,n-a,a+(b-a-1)//2,n-(a+b-1)//2))
| 1 | 109,544,849,575,068 | null | 253 | 253 |
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort()
ma=max(a)
dp=[0]*ma
for i in a:
dp[i-1]+=1
l=[0]*ma
ans=0
for i in a:
j=i
if l[i-1]==0 and dp[i-1]==1:
ans+=1
while(j<=ma):
l[j-1]+=1
if j+i<=ma:
j+=i
else:
break
print(ans)
|
import collections
def U1(a,b):
if b > a:
b, a = a, b
while a%b != 0:
r = a%b
a = b
b = r
return b
K = int(input())
c = 0
arr = []
for i in range(1,K+1):
for j in range(1,K+1):
arr.append(U1(i,j))
arr=collections.Counter(arr)
for key,value in arr.items():
for k in range(1,K+1):
c += U1(k,key)*value
print(c)
| 0 | null | 24,952,299,503,484 | 129 | 174 |
n = int(input())
result = []
for i in range(3, n+1):
if i % 3 == 0 or '3' in str(i):
result.append(i)
print(" ", end="")
print(*result)
|
n = int(raw_input())
print "",
for i in xrange(3,n+1):
x = i
if x % 3 == 0:
print i,
continue
while x:
if x % 10 == 3:
print i,
break
elif x / 10 != 0:
x = x / 10
continue
else:
break
| 1 | 925,413,619,688 | null | 52 | 52 |
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')
|
import math
a = float(input())
b = math.acos(-1)
print "%f %f" % (a * a * b , 2 * a * b)
| 0 | null | 347,277,261,770 | 23 | 46 |
H, W = map(int, input().split())
if H == 1 or W == 1:
r = 1
else:
r = (H*W +2-1)//2
print(r)
|
from itertools import accumulate
n,k = map(int, input().split())
As = list(map(int, input().split()))
for i in range(k):
imos = [0] * (n+1)
for i,a in enumerate(As):
l = max(0, i-a)
r = min(n, i+a+1)
imos[l] += 1
imos[r] -= 1
acc = list(accumulate(imos))
# 指数関数的に増える
if acc[:-1] == As:
print(*As)
exit()
As = acc[:-1]
print(*As)
| 0 | null | 33,071,543,663,762 | 196 | 132 |
a, b = input().split()
a = int(a)
b = int(b)
d = int(a/b)
r = a%b
f = a/b
print(str(d) + " " + str(r) + " " + "%.8f" % (f))
|
import sys
s = input()
def match(a):
if a[0:2] == 'hi':
return a[2:]
else:
print('No')
sys.exit()
if len(s)%2 == 1:
print('No')
sys.exit()
else:
while len(s) > 1:
s = match(s)
print('Yes')
| 0 | null | 26,798,450,303,262 | 45 | 199 |
X, N = map(int, input().split())
if N == 0:
print(X)
else:
P = list(map(int, input().split()))
A = [0]
for i in range(1, 102):
if (i in P) == False:
A.append(i)
c = 101
for j in range(len(A)):
if abs(X - A[len(A)-int(j)-1]) <= abs(X - c):
c = A[len(A)-int(j)-1]
else:
c = c
print(c)
|
import math
n = int(input())
count = 0
for i in range(n):
t = int(input())
a = int(t ** (1 / 2))
end = 0
for j in range(2, a + 1):
if t % j == 0:
end = 1
break
if end == 0:
count += 1
print(count)
| 0 | null | 7,015,210,472,680 | 128 | 12 |
N = float(input())
S = N
count = 0
while (N > 0):
if N % 2 != 0:
count += 1
N = N - 1
print(count / S)
|
n=int(input())
print(((n-1)//2+1)/n)
| 1 | 176,968,556,966,234 | null | 297 | 297 |
x,y=map(int,input().split());print('NYoe s'[x*2<=~y%2*y<=x*4::2])
|
x, y = map(int, input().split())
if y in range(x*2, x*4+1, 2):
print("Yes")
else:
print("No")
| 1 | 13,839,709,231,968 | null | 127 | 127 |
import sys
input = sys.stdin.readline
n, m, l = map(int, input().split())
INF = float("inf")
def warshall_floyd(d, n):
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
d = [[INF] * n for _ in range(n)]
for i in range(n):
d[i][i] = 0
for i in range(m):
a, b, c = map(int, input().split())
d[a - 1][b - 1] = c
d[b - 1][a - 1] = c
d = warshall_floyd(d, n)
d2 = [[INF] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if d[i][j] <= l:
d2[i][j] = 1
d2[i][i] = 0
d2 = warshall_floyd(d2, n)
q = int(input())
for _ in range(q):
s, t = map(int, input().split())
res = d2[s - 1][t - 1]
print(-1 if res == INF else res - 1)
|
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7
x,k,d = map(int,readline().split())
x = abs(x)
if (x >= k*d):
print(x-k*d)
elif ((k-x//d)%2):
print(abs(x%d-d))
else:
print(x%d)
| 0 | null | 89,622,806,464,360 | 295 | 92 |
# N = int(input())
import heapq
X, Y, A, B, C = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]
p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]
heapq.heapify(p)
heapq.heapify(q)
r_asc = sorted(r, reverse=True)
for r in r_asc:
p_min = heapq.heappop(p)
q_min = heapq.heappop(q)
if p_min > q_min and r > q_min:
heapq.heappush(q, r)
heapq.heappush(p, p_min)
elif q_min >= p_min and r > p_min:
heapq.heappush(p, r)
heapq.heappush(q, q_min)
else:
heapq.heappush(q, q_min)
heapq.heappush(p, p_min)
break
print(sum(p) + sum(q))
|
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
import sys
sys.setrecursionlimit(10**6)
x,y,a,b,c=sep()
red=lis()
green=lis()
colorless=lis()
red.sort(reverse=True)
green.sort(reverse=True)
colorless.sort()
red=red[:x][::-1]
green=green[:y][::-1]
i=0
j=0
while(colorless):
if j>=y and i>=x:
break
elif j<y and i>=x:
if colorless[-1]>green[j]:
green[j]=colorless[-1]
colorless.pop()
j+=1
else:
break
elif i<x and j>=y:
if colorless[-1]>red[i]:
red[i]=colorless[-1]
colorless.pop()
i+=1
else:
break
elif red[i]<=green[j]:
if colorless[-1]>red[i]:
red[i]=colorless[-1]
colorless.pop()
i+=1
else:
break
else:
if colorless[-1]>green[j]:
green[j]=colorless[-1]
colorless.pop()
j+=1
else:
break
#print(red,green)
print(sum(red) + sum(green))
| 1 | 44,861,263,885,088 | null | 188 | 188 |
n = int(input())
x = list(map(int, input().split()))
sum= 1000000000000000
for p in range(1,101):
tmp=0
# print("p",p)
for i in range(len(x)):
tmp += (x[i] - p)**2
# print("tmp",tmp)
sum = min(sum,tmp)
# print("su",sum)
print(sum)
|
n = int(input())
x = list(map(int,input().split()))
ans = 10**18
for i in range(1,101):
t = 0
for j in range(n):
t += (x[j]-i)**2
ans = min(ans,t)
print(ans)
| 1 | 65,094,787,754,048 | null | 213 | 213 |
import sys
def input(): return sys.stdin.readline().rstrip()
# ライブラリ参照https://atcoder.jp/contests/practice2/submissions/16580070
class SegmentTree:
__slots__ = ["func", "e", "original_size", "n", "data"]
def __init__(self, length_or_list, func, e):
self.func = func
self.e = e
if isinstance(length_or_list, int):
self.original_size = length_or_list
self.n = 1 << ((length_or_list - 1).bit_length())
self.data = [self.e] * self.n
else:
self.original_size = len(length_or_list)
self.n = 1 << ((self.original_size - 1).bit_length())
self.data = [self.e] * self.n + length_or_list + \
[self.e] * (self.n - self.original_size)
for i in range(self.n-1, 0, -1):
self.data[i] = self.func(self.data[2*i], self.data[2*i+1])
def replace(self, index, value):
index += self.n
self.data[index] = value
index //= 2
while index > 0:
self.data[index] = self.func(
self.data[2*index], self.data[2*index+1])
index //= 2
def folded(self, l, r):
left_folded = self.e
right_folded = self.e
l += self.n
r += self.n
while l < r:
if l % 2:
left_folded = self.func(left_folded, self.data[l])
l += 1
if r % 2:
r -= 1
right_folded = self.func(self.data[r], right_folded)
l //= 2
r //= 2
return self.func(left_folded, right_folded)
def all_folded(self):
return self.data[1]
def __getitem__(self, index):
return self.data[self.n + index]
def max_right(self, l, f):
# assert f(self.e)
if l >= self.original_size:
return self.original_size
l += self.n
left_folded = self.e
while True:
# l //= l & -l
while l % 2 == 0:
l //= 2
if not f(self.func(left_folded, self.data[l])):
while l < self.n:
l *= 2
if f(self.func(left_folded, self.data[l])):
left_folded = self.func(left_folded, self.data[l])
l += 1
return l - self.n
left_folded = self.func(left_folded, self.data[l])
l += 1
if l == l & -l:
break
return self.original_size
# 未verify
def min_left(self, r, f):
# assert f(self.e)
if r == 0:
return 0
r += self.n
right_folded = self.e
while True:
r //= r & -r
if not f(self.func(self.data[r], right_folded)):
while r < self.n:
r = 2 * r + 1
if f(self.func(self.data[r], right_folded)):
right_folded = self.func(self.data[r], right_folded)
r -= 1
return r + 1 - self.n
if r == r & -r:
break
return 0
def orr(x, y):
return x | y
def main():
N = int(input())
S = input()
S = list(map(lambda c: 2**(ord(c) - ord('a')), list(S)))
Q = int(input())
seg = SegmentTree(S, orr, 0)
for _ in range(Q):
num, x, y = input().split()
if num == '1':
seg.replace(int(x)-1, 2**(ord(y) - ord('a')))
else:
bits = seg.folded(int(x)-1, int(y))
print(sum(map(int, list(bin(bits))[2:])))
if __name__ == '__main__':
main()
|
import numpy as np
n,m,x = map(int,input().split())
value = []
books = []
for i in range(n):
a = list(map(int,input().split()))
value.append(a[0])
books.append(np.array(a[1:]))
if min(sum(books))<x:
print(-1)
else:
ans = 10**8
for i in range(2**n):
M = np.array([0]*m)
v = 0
for j in range(n):
if i >> j & 1:
M += books[j]
v += value[j]
if min(M)>= x:
ans = min(ans,v)
print(ans)
| 0 | null | 42,294,311,326,838 | 210 | 149 |
n = int(input())
s = input()
t = ''
for c in s:
if ord(c) + n > ord('Z'):
m = ord('Z') - ord(c)
t += chr(ord('A') + (n - m - 1))
else:
t += chr(ord(c) + n)
print(t)
|
"""
Nが奇数のとき、絶対に末尾が0が来ることはない。したがって、答えは0。
Nが偶数の時、
N//10 * 1 + N//10**2 * 1 + ...の数だけ0ができる。
"""
N = int(input())
if N % 2 == 1:
print(0)
else:
ans = 0
ind = 1
while True:
m = 5**ind
if m > N:
break
r = N//m
r //= 2
ans += r
ind += 1
print(ans)
| 0 | null | 125,172,949,906,410 | 271 | 258 |
n=int(input())
if n%2 == 0:
n=n-1
print(int(n/2))
|
N=int(input())
if N%2==0:
print(N//2-1)
else:
print(N//2)
| 1 | 153,212,051,672,458 | null | 283 | 283 |
a, b, c, d = (int(i) for i in input().split())
print(max(a*c, b*d, a*d, b*c))
|
a,b,c,d = map(int,input().split())
if(a<=0 and b>=0 or (c<=0 and d>=0)):
print(max(a*c,b*d,a*d,b*c,0))
else:
print(max(a*c,b*d,a*d,b*c))
| 1 | 3,037,615,882,050 | null | 77 | 77 |
n = int(input())
print(" " + " ".join([str(i) for i in range(1, n+1) if i % 3 == 0 or '3' in str(i)]))
|
#coding:utf-8
#3????????°???????????????
n = input()
print "",
for i in xrange(1, n+1):
if i % 3 == 0:
print i,
elif "3" in str(i):
print i,
| 1 | 945,306,643,698 | null | 52 | 52 |
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
if n: return [0 for _ in range(n)]
else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
if n: return ["" for _ in range(n)]
else: return sinput().split()
def adj(n): return [[] for _ in range(n)]
class unionfind():
def __init__(self, n):
self.n = n
# 中身が負の数なら根であり、数字の絶対値はグループ数
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0: return x
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x,y = self.find(x), self.find(y)
if x == y: return
if self.parents[x] > self.parents[y]: x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x): return -self.parents[self.find(x)]
def same(self, x, y): return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self): return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self): return len(self.roots())
n,m,k = imap()
uf = unionfind(n)
f,ng,anss = iarr(n),iarr(n),iarr(n)
for i in range(m):
a,b = imap()
a,b = a-1,b-1
f[a] += 1
f[b] += 1
uf.union(a,b)
for i in range(n):
anss[i] = uf.size(i) - f[i] - 1
for i in range(k):
c,d = imap()
c,d = c-1,d-1
if uf.same(c,d):
anss[c] -= 1
anss[d] -= 1
print(*anss)
|
class UnionFind:
def __init__(self, n):
#親要素のノード番号を格納 xが根のとき-(サイズ)を格納
self.par = [-1 for i in range(n)]
self.n = n
def find(self, x):
#根ならその番号を返す
if self.par[x] < 0:
return x
else:
#親の親は親
self.par[x] = self.find(self.par[x])
return self.par[x]
def is_same(self, x, y):
#根が同じならTrue
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y: return
#木のサイズを比較し、小さいほうから大きいほうへつなぐ
if self.par[x] > self.par[y]:
x, y = y, x
self.par[x] += self.par[y]
self.par[y] = x
def size(self, x):
return -self.par[self.find(x)]
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.par) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
graph = [set() for _ in range(N)]
block = [set() for _ in range(N)]
union = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
graph[a-1].add(b-1)
graph[b-1].add(a-1)
union.unite(a-1, b-1)
for i in range(K):
a, b = map(int, input().split())
block[a-1].add(b-1)
block[b-1].add(a-1)
blocking = [0] * N
for i, blo in enumerate(block):
for b in blo:
if union.is_same(i, b):
blocking[i] += 1
for i in range(N):
ans = union.size(i) - len(graph[i]) - blocking[i] - 1
print(ans)
| 1 | 61,770,602,894,500 | null | 209 | 209 |
x,y=map(int,input().split())
if ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and 1<=(-2*x+y)//2<=100):
print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and (1<=(4*x-y)//2<=100 and (-2*x+y)//2==0):
print('Yes')
elif ((4*x-y)%2==0 and (-2*x+y)%2==0) and ((4*x-y)//2==0 and 1<=(-2*x+y)//2<=100):
print('Yes')
else :
print('No')
|
X, Y = map(int, input().split())
prize = [300000, 200000, 100000]
ans = 0
if X <= 3:
X -= 1
ans += prize[X]
if Y <= 3:
Y -= 1
ans += prize[Y]
if ans == 600000:
ans += 400000
print(ans)
| 0 | null | 77,495,007,206,620 | 127 | 275 |
n = int(input())
s = list(input())
ans = []
for i in range(len(s)):
a = ord(s[i])
moji = a + n if a + n <= 90 else a + n -26
ans += [chr(moji)]
print("".join(ans))
|
import math
H, W = map(int, raw_input().split())
while H > 0 or W > 0 :
print "#" * W
for i in xrange(H-2) :
print "#" + "." * (W-2) + "#"
print "#" * W
print
H, W = map(int, raw_input().split())
| 0 | null | 67,921,832,709,360 | 271 | 50 |
def check_p(packages, n, trucks, max_p):
i = 0
for _ in range(trucks):
sum = 0
while sum + packages[i] <= max_p:
sum += packages[i]
i += 1
if i == n:
return i
return i
n, k = map(int, input().split())
packages = []
for _ in range(n):
packages.append(int(input()))
left = 0
right = 10 ** 5 * 10 ** 4
while left + 1 < right:
mid = (left + right) // 2
num = check_p(packages, n, k, mid)
if num < n:
left = mid
else:
right = mid
print(right)
|
# coding: utf-8
# Your code here!
def check(P):
i = 0
for j in range(k):
s = 0
while s + T[i] <= P:
s += T[i]
i += 1
if i == n:
return n
return i
def solve():
left = 0
right = 100000 * 10000
mid = 0
while right - left > 1:
mid = (left + right) // 2
v = check(mid)
if v >= n:
right = mid
else:
left = mid
return right
tmp = list(map(int, input().split()))
n = tmp[0]
k = tmp[1]
T = []
for i in range(n):
T.append(int(input()))
ans = solve()
print(ans)
| 1 | 86,192,883,450 | null | 24 | 24 |
def isPalindrome(st):
l = len(st)
c = l//2
if l%2 == 1:
return st[:c] == st[c+1:][::-1]
else:
return st[:c] == st[c:][::-1]
S = input()
N = len(S)
if isPalindrome(S) and isPalindrome(S[:(N-1)//2]) and isPalindrome(S[(N+3)//2 - 1:]):
print('Yes')
else:
print('No')
|
S: str = input()
n = len(S)
if not S == S[::-1]:
print('No')
exit()
end = (n-1)//2
SS = S[:end]
if not SS == SS[::-1]:
print('No')
exit()
start = (n+3)//2 - 1
SSS = S[start:n]
if not SSS == SSS[::-1]:
print('No')
exit()
print('Yes')
| 1 | 46,203,289,034,688 | null | 190 | 190 |
def main():
N, M = map(int, input().split())
A = tuple(map(int,input().split()))
ans = count(A, N, M)
print(ans)
def count(A, N, M):
t = hMt(A[0])
B = [A[0]//(2**t)]
for val in A[1:]:
if hMt(val) != t:
ans = 0
return ans
B.append(val//(2**t))
T = nlcm(B)
MdivT = (M//(2**(t-1)))//T
ans = countodd(MdivT)
return ans
def countodd(num):
if num%2 == 0:
ans = num//2
else:
ans = num//2 + num%2
return ans
def nlcm(A):
LCM = A[0]
for val in A[1:]:
#print("%d %d gcm:%d LCM:%d"%(LCM,val,gcm(LCM,val),lcm(LCM,val)))
LCM = lcm(LCM,val)
return LCM
def gcm(a, b):
abtuple = (a,b)
abmin = min([0,1], key=lambda x:abtuple[x])
remainder = abtuple[1-abmin]%abtuple[abmin]
if remainder == 0:
return abtuple[abmin]
return gcm(abtuple[abmin], remainder)
def lcm(a,b):
prod = a*b
ans = prod//gcm(a,b)
return ans
def hMt(num):
ans = 0
tmp = num
while tmp%2 == 0:
tmp = tmp//2
ans += 1
return ans
main()
|
import fractions
N,M=map(int,input().split())
a=list(map(int,input().split()))
l=1
count=0
A=a[0]
ans=0
flag=1
while A%2==0:
A=A//2
count=count+1
for i in range(N):
A=a[i]
b=A//(2**count)
if b==0 or b%2==0:
flag=0
break
A=A//2
l=l*A//fractions.gcd(l,A)
if flag==1:
ans=M//l
if ans%2==0:
print(ans//2)
else:
print(ans//2+1)
else:
print(0)
| 1 | 101,693,296,436,388 | null | 247 | 247 |
from collections import Counter
S = list(map(int, list(input())))
A = [0]
for i, s in enumerate(S[::-1]):
A.append((A[-1] + s * pow(10, i, 2019)) % 2019)
print(sum([v * (v - 1) // 2 for v in Counter(A).values()]))
|
while True:
a=[int(x) for x in input().split()]
if a[0]==a[1]==0:
break
else:
for x in range(a[0]):
if x%2!=0:
for y in range(a[1]):
if y%2!=0:
print("#", end="")
else:
print(".", end="")
print("\n",end="")
elif x%2==0:
for y in range(a[1]):
if y%2!=0:
print(".", end="")
else:
print("#", end="")
print("\n",end="")
print("")
| 0 | null | 15,852,353,408,768 | 166 | 51 |
a,b,c,d = map(int, input().split())
ac = a * c
ad = a * d
bc = b * c
bd = b * d
print(max([ac, ad, bc, bd]))
|
a,b,c,d=map(int,input().split())
ans=-10**20
if ans<a*c:
ans=a*c
if ans<a*d:
ans=a*d
if ans<b*c:
ans=b*c
if ans<b*d:
ans=b*d
print(ans)
| 1 | 3,051,804,324,900 | null | 77 | 77 |
#ITP1_11-B Dice 2
rep=[
[1,2,4,3,1],
[2,0,3,5,2],
[0,1,5,4,0],
[0,4,5,1,0],
[0,2,5,3,0],
[1,3,4,2,1]
]
d = input().split(" ")
q = int(input())
dic={}
for i in range(6):
dic.update({d[i]:i})
for i in range(q):
a,b = input().split(" ")
for j in range(4):
top=dic[a]
front = dic[b]
if(d[rep[top][j]]==d[front]):
print(d[rep[top][j+1]])
|
dice = ['23542', '14631', '12651', '15621', '13641', '24532']
d = input().split()
q = int(input())
for _ in range(q):
num = input().split()
order = str(d.index(num[0]) + 1) + str(d.index(num[1]) + 1)
[print(d[i]) for i in range(6) if order in dice[i]]
| 1 | 262,826,327,840 | null | 34 | 34 |
s = input()
mid = len(s)//2
q = s[:mid]
if len(s)%2 == 0:
t = list(s[mid:])
else:
t = list(s[mid+1:])
t.reverse()
cnt = 0
for i in range(mid):
cnt += s[i] != t[i]
print(cnt)
|
K = int(input())
S = list(input())
if len(S) <= K:
print(''.join(S))
else:
del S[K:len(S)]
S = ''.join(S) + '...'
print(S)
| 0 | null | 69,895,527,944,330 | 261 | 143 |
n = int(input())
given_list = list(map(int, input().split()))
for i in range(n):
if i == n-1:
print(given_list[n-i-1])
else:
print(given_list[n-i-1], end=" ")
|
from collections import deque
N,M=map(int,input().strip().split())
l=[]
dp=[[] for _ in range(N)]
for _ in range(M):
a,b=map(int,input().strip().split())
l.append((a,b))
dp[a-1].append(b)
dp[b-1].append(a)
d=deque([1])
visited=[0 for _ in range(N)]
visited[0]=1
cnt=1
while d:
tmp=d.popleft()
for e in dp[tmp-1]:
if visited[e-1]==0:
visited[e-1]=tmp
cnt+=1
d.append(e)
if cnt!=len(visited):
print("No")
else:
print("Yes")
for n in range(1,N):
print(visited[n])
| 0 | null | 10,862,691,904,750 | 53 | 145 |
# C Sum of gcd of Tuples (Easy)
import math
from itertools import combinations_with_replacement as C
K = int(input())
ans = 0
ABC = list(C(range(1, K+1), 3))
for a, b, c in ABC:
if a == b == c:
ans += math.gcd(math.gcd(a, b), c)
elif a == b or b == c or c == a:
ans += math.gcd(math.gcd(a, b), c) * 3
else:
ans += math.gcd(math.gcd(a, b), c) * 6
print(ans)
|
import math
from functools import reduce
def gcd(*numbers):
return reduce(math.gcd, numbers)
k = int(input())
sum=0
for i in range(1,k+1):
for j in range(i+1,k+1):
for l in range(j+1,k+1):
sum+=6*gcd(i,j,l)
for i in range(1,k+1):
for j in range (1,k+1):
sum+=3*gcd(i,j)
sum-=k*(k+1)
print(sum)
| 1 | 35,598,013,969,040 | null | 174 | 174 |
import math
def main():
X=int(input())
for a in range(-120,120):
flag=0
for b in range(-120,120):
if pow(a,5)-pow(b,5)==X:
print("{} {}".format(a,b))
flag=1
break
if flag==1:
break
if __name__=="__main__":
main()
|
x = int(input())
a = 0
while True:
b = a
while a**5 - b**5 <= x:
if a**5 - b**5 == x:
print(a, b)
exit()
b -= 1
a += 1
| 1 | 25,489,710,105,728 | null | 156 | 156 |
n = int(input())
v = []
for i in range(n):
v_i = list(map(int,input().split()))[2:]
v.append(v_i)
d = [-1]*n
d[0]=0
queue = [1]
dis = 1
while len(queue)!=0:
queue2 = []
for i in queue:
for nex in v[i-1]:
if d[nex-1]==-1:
d[nex-1]=dis
queue2.append(nex)
dis +=1
queue = queue2
for i in range(n):
print(i+1,d[i])
|
n = int(input())
s = input()
ans = 0
for i in range(n - 2):
a = s[i:i + 3]
if a == "ABC":
ans += 1
print(ans)
| 0 | null | 49,493,327,140,380 | 9 | 245 |
a, b, c, k = map(int, input().split())
ans = 0
if k < a:
ans = 1 * k
elif k <= a + b:
ans = 1 * a
elif k > a + b:
ans = 1 * a - 1 * (k-a-b)
print(ans)
|
a,b = map(int,input().split())
for i in range(1,100000):
x = i*8
y = i*10
if x//100 == a and y//100 == b:
print(i)
exit()
print(-1)
| 0 | null | 38,948,680,221,948 | 148 | 203 |
import sys
input = sys.stdin.buffer.readline
n = int(input())
dic = {}
cdic = {}
d = 0
for i in range(1,n+1):
matsubi = i%10
sentou = i//(10**d)
if sentou >= 10:
d += 1
sentou = i//(10**d)
#print(sentou,matsubi)
if sentou == matsubi:
if sentou not in cdic:
cdic[sentou] = 0
cdic[sentou] += 1
continue
sw = False
if sentou > matsubi:
sentou,matsubi = matsubi,sentou
sw = True
if (sentou,matsubi) not in dic:
dic[(sentou,matsubi)] = [0,0]
if not sw:
dic[(sentou,matsubi)][0] += 1
else:
dic[(sentou,matsubi)][1] += 1
ans = 0
for item in cdic:
ans += cdic[item]*(cdic[item])
for item in dic:
ans += dic[item][0]*dic[item][1]*2
print(ans)
|
l =int(input())
s =input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
A = r * g * b
B = 0
gapmax = (l - 3) // 2
for _ in range(gapmax+1):
for i in range(l-2-2*_):
c1, c2, c3 = s[i], s[i+1+_],s[i+2+2*_]
if not (c1 == c2) and not (c1 == c3) and not (c2 ==c3):
B += 1
print(A-B)
| 0 | null | 61,314,436,624,480 | 234 | 175 |
ri = raw_input().split()
stack = []
for i in xrange(len(ri)):
if ri[i] == "+":
b = stack.pop()
a = stack.pop()
stack.append(str(int(a)+int(b)))
elif ri[i] == "-":
b = stack.pop()
a = stack.pop()
stack.append(str(int(a)-int(b)))
elif ri[i] == "*":
b = stack.pop()
a = stack.pop()
stack.append(str(int(a)*int(b)))
else:
stack.append(ri[i])
print stack.pop()
|
a=input().split()
operator={
'+':(lambda x,y:x+y),
'-':(lambda x,y:x-y),
'*':(lambda x,y:x*y),
'/':(lambda x,y:float(x)/y)
}
stack=[]
for i,j in enumerate(a):
if j not in operator.keys():
stack.append(int(j))
continue
y=stack.pop()
x=stack.pop()
stack.append(operator[j](x,y))
print(stack[0])
| 1 | 35,185,867,612 | null | 18 | 18 |
weather = list(input())
i = 0
j = 0
days = 0
consecutive = []
while i <= 2:
while i + j <= 2:
if weather[i+j] == "R":
days += 1
j += 1
else:
break
i += 1
j = 0
consecutive.append(days)
days = 0
print(max(consecutive))
|
ans = ''
while True:
s = input()
if s == '-':
break
n = int(input())
L = []
i = 0
while i < n:
j = int(input())
s = s[j:] + s[:j]
i += 1
ans += s + '\n'
if ans != '':
print(ans[:-1])
| 0 | null | 3,443,486,278,820 | 90 | 66 |
A,B = map(str,input().split())
print(B+A)
|
a,b,c= map(int,input().split())
if c>a+b and 4*a*b<(c-a-b)*(c-a-b):
print('Yes')
else:
print('No')
| 0 | null | 77,291,582,588,292 | 248 | 197 |
s = input()
t = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
print(7-int(t.index(s)))
|
n = int(input())
branch = [[] for _ in range(n)]
a, b, inda, indb = [], [], [], []
for _ in range(n-1):
i, j = map(int, input().split())
i -= 1
j -= 1
branch[i].append(j)
branch[j].append(i)
a.append(i)
b.append(j)
inda.append(len(branch[i])-1)
indb.append(len(branch[j])-1)
kind = max([len(i) for i in branch])
print(kind)
# DFS
color = [0 for _ in range(n)]
todo = [0]
color[0] = 1
while len(todo) > 0:
num = todo.pop(-1)
col = color[num]
if col == kind:
col = 1
else:
col = col + 1
for i in range(len(branch[num])):
if color[branch[num][i]] == 0:
color[branch[num][i]] = col
todo.append(branch[num][i])
branch[num][i] = -col
if col == kind:
col = 1
else:
col = col + 1
for i in range(n-1):
if branch[a[i]][inda[i]] < 0:
print(-branch[a[i]][inda[i]])
else:
print(-branch[b[i]][indb[i]])
| 0 | null | 135,066,588,391,280 | 270 | 272 |
n = int(input())
print('{:.06f}'.format((n/3)**3))
|
L = int(input())
print(L*L*L/27)
| 1 | 47,060,324,852,902 | null | 191 | 191 |
# coding: utf-8
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
# 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):
# 2つの木をマージする。
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def are_same(self, x, y):
# 2つの要素の根が同じかどうかを調べる
return self.find(x) == self.find(y)
def members(self, x):
# xと同じ根の要素をリストで出力
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == self.n]
def roots(self):
# 根である要素をリストで出力
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{} {}".format(r, self.members(r)) for r in self.roots())
N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
a, b = map(int, input().split())
uf.union(a-1, b-1)
ans = 0
for v in uf.parents:
if v < 0:
ans = max(ans, abs(v))
print(ans)
|
class Dice(object):
def __init__(self,num):
self.f=num[0]
self.s=num[1]
self.e=num[2]
self.w=num[3]
self.n=num[4]
self.b=num[5]
def create(self,order):
if order=='N':
return [self.s,self.b,self.e,self.w,self.f,self.n]
elif order=='S':
return [self.n,self.f,self.e,self.w,self.b,self.s]
elif order=='E':
return [self.w,self.s,self.f,self.b,self.n,self.e]
else:
return [self.e,self.s,self.b,self.f,self.n,self.w]
@classmethod
def Dice_create(cls,num):
return cls(num)
num=list(map(int,input().split()))
q=eval(input())
Q=[]
dice=Dice(num)
T={0:'N',1:'E',2:'S',3:'W'}
for i in range(q):
Q.append(list(map(int,input().split())))
for i in range(q):
while True:
t=[dice.s,dice.w,dice.n,dice.e]
if dice.f!=Q[i][0]:
if dice.b!=Q[i][0]:#??´??¢????????¢?????\?????????
dice=Dice.Dice_create(dice.create(T[t.index(Q[i][0])]))
else:#?????¢????????¢?????\?????????
dice=Dice.Dice_create(dice.create('N'))
else:
print(t[t.index(Q[i][1])-1])#?????¢?????£???????????¢?????\?????????
break
| 0 | null | 2,128,616,210,258 | 84 | 34 |
'''
def main():
a = input()
if a < 'a':
print("A")
else:
print("a")
'''
def main():
a = input()
if a.islower():
print("a")
else:
print("A")
if __name__ == "__main__":
main()
|
s=input()
if s<='Z':print('A')
else:print('a')
| 1 | 11,348,182,824,160 | null | 119 | 119 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
for k in range(1,min(K+1,45)):
B = [0]*N
for i in range(N):
l = max(0,i-A[i])
r = min(N-1,i+A[i])
B[l] += 1
if r+1 < N:
B[r+1] -= 1
for i in range(1,N):
B[i] += B[i-1]
A = B
print(*A)
|
n, k, s = map(int, input().split())
a = [s] * n
if s == 1:
s = 2
else:
s -=1
for i in range(k, n):
a[i] = s
print(a[0], end = "")
for i in a[1:]:
print("", i, end = "")
print()
| 0 | null | 53,418,130,177,798 | 132 | 238 |
S,T=list(input().split())
T+=S
print(T)
|
s, t = input().split()
print(''.join(t+s))
| 1 | 103,194,764,733,060 | null | 248 | 248 |
#coding:UTF-8
a,b = map(int,raw_input().split())
d = a/b
r = a%b
f = float(a)/b
f = '%.8f' % (f)
print d,r,f
|
#!/usr/bin/env python3
N = int(input())
if N == 0: print(1)
else: print(0)
| 0 | null | 1,789,030,650,340 | 45 | 76 |
def main():
from bisect import bisect_left as bl
from itertools import accumulate as ac
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
aa = [0]+list(ac(a))
an = aa[n]
ok = 0
ng = 10**10
while abs(ok-ng) > 1:
mid = (ok+ng)//2
if sum([n-bl(a, mid-a[i]) for i in range(n)]) >= m:
ok = mid
else:
ng = mid
c = -m+sum([n-bl(a, ok-a[i]) for i in range(n)])
ans = -c*ok
for i in range(n):
d = bl(a, ok-a[i])
ans += an-aa[d]+(n-d)*a[i]
print(ans)
main()
|
from itertools import accumulate
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
ruiseki = list(accumulate(A[::-1]))
def syakutori(mid):
x = 0
cnt = 0
ans = 0
for i in range(N)[::-1]: # 大きい方から
while x < N:
if A[i] + A[x] >= mid:
cnt += N - x
if N - x >= 1:
ans += A[i] * (N - x) + ruiseki[N - x - 1]
break
else:
x += 1
return cnt, ans
# 自分以上の数の個数がM個以上になる値のうち最大のもの
ok = 0
ng = 10 ** 15
while ok + 1 < ng:
mid = (ok + ng) // 2
cnt, ans = syakutori(mid)
if cnt >= M:
ok = mid
else:
ng = mid
# okで終わってる場合はcntがM個以上の場合があるから過分を引く
# ngで終わってる場合は残りM-cnt個のokを足す
print(ans + ok * (M - cnt))
| 1 | 107,712,098,987,400 | null | 252 | 252 |
N=int(input())
mod=10**9+7
a = (10**N)%mod
b = (9**N)%mod
c = (8**N)%mod
ans = (a+c-2*b)%mod
print(ans)
|
import math
from functools import reduce
"""[summary]
全体:10^N
0が含まれない:9^N
9が含まれない:9^N
0,9の両方が含まれない:8^N
0,9のどちらか一方が含まれない:9^N + 9^N - 8^N
"""
N = int(input())
mod = (10 ** 9) + 7
calc = (10**N - 9**N - 9**N + 8**N) % mod
print(calc)
| 1 | 3,142,953,517,588 | null | 78 | 78 |
s = int(input())
h = s//3600
s = s%3600
m = s//60
s = s%60
print(h,':',m,':',s, sep='')
|
from itertools import accumulate
n, m, *a = map(int, open(0).read().split())
a = [-x for x in a]
a.sort()
acc = list(accumulate(a))
l, r = 0, 2 * 10 ** 5 + 1
while r - l > 1:
mid = (l + r) // 2
border = n - 1
cnt = 0
for x in a:
while x + a[border] > -mid:
border -= 1
if border < 0:
break
if border < 0:
break
cnt += border + 1
if cnt >= m:
break
if cnt >= m:
l = mid
else:
r = mid
ans = tot = 0
border = n - 1
for x in a:
while x + a[border] > -l:
border -= 1
if border < 0:
break
if border < 0:
break
ans += acc[border] + x * (border + 1)
tot += border + 1
ans += l * (tot - m)
print(-ans)
| 0 | null | 54,492,293,908,768 | 37 | 252 |
str1=input()
str2=input()
str=str1*2
if str2 in str:
print("Yes")
else:
print("No")
|
n=int(input())
s=input()
l=[]
for i in s:
x=(ord(i)-65+n)%26
y=chr(65+x)
l.append(y)
print(''.join(l))
| 0 | null | 67,865,597,316,348 | 64 | 271 |
while True:
count=0
n,x = map(int,input().split())
if n==x==0: break
for a in range(n):
for b in range(n):
for c in range(n):
if a<b<c and a+b+c==x-3:
count+=1
print(count)
|
from itertools import product
[N, M, X] = [int(i) for i in input().split()]
bk = [[int(i) for i in input().split()] for _ in range(N)]
ans = 12*10**5 + 1
for seq in product(range(2), repeat=N):
S = [0]*(M+1)
for i in range(N):
for j in range(M+1):
S[j] += seq[i]*bk[i][j]
if min(S[1:M+1]) >= X:
ans = min(ans, S[0])
if ans == 12*10**5 + 1:
print(-1)
else:
print(ans)
| 0 | null | 11,720,771,504,480 | 58 | 149 |
from itertools import combinations
n = int(input())
L = list(map(int,input().split()))
ans = 0
for a,b,c in combinations(L,3):
ans += (2*max(a,b,c) < a+b+c)*(a != b and b != c and c != a)
print(ans)
|
def solve():
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(int(1e5)+9)
s=0
for i in range(0,n) :
s+=a[i]
cnt[a[i]]+=1
q=int(input())
for q in range(0,q) :
b,c=map(int,input().split())
ct=cnt[b]
s+=ct*(c-b)
cnt[b]=0
cnt[c]+=ct
print(s)
solve()
| 0 | null | 8,634,604,684,288 | 91 | 122 |
a = input()
ar = [0 for i in range(len(a)+1)]
for i in range(len(a)):
if a[i] == '<':
ar[i+1] = max(ar[i] + 1,ar[i+1])
for i in range(len(a)-1,-1,-1):
if a[i] == '>':
ar[i] = max(ar[i+1] + 1,ar[i])
print(sum(ar))
|
# 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,789,647,305,538 | null | 285 | 285 |
print("ACL"*int(input()))
|
for _ in range(int(input())):
print("ACL", end="")
| 1 | 2,155,697,556,260 | null | 69 | 69 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
from copy import deepcopy
def main():
n, m = map(int, input().split())
edges = {e:[] for e in range(n + 1)}
for _ in range(m):
a, b = map(int, input().split())
edges[a].append(b)
edges[b].append(a)
res = [0] * (n + 1)
dist = 1
distroom = [n + 1] * (n + 1)
distroom[1] = 0
q1 = deque()
q2 = deque()
q1.append(1)
while q1:
for q1e in q1:
for adj in edges[q1e]:
if distroom[adj] > dist:
res[adj] = q1e
distroom[adj] = dist
q2.append(adj)
dist += 1
q1 = deepcopy(q2)
q2 = deque()
print('Yes')
print(*res[2:],sep='\n')
if __name__ == '__main__':
main()
|
from collections import deque
N, M = map(int, input().split())
nodes = [set() for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
nodes[a-1].add(b-1)
nodes[b-1].add(a-1)
ans = [-1 for i in range(N)]
ans[0] = 0
q = deque([])
q.append(0)
cur = 0
done = set()
done.add(0)
while q:
node = q.popleft()
for x in nodes[node]:
if x in done:
continue
q.append(x)
done.add(x)
ans[x] = node + 1
if -1 in ans:
print('No')
else:
print('Yes')
for x in ans[1:]:
print(x)
| 1 | 20,595,542,095,968 | null | 145 | 145 |
def main():
s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
a -= 1
else:
b -= 1
print(a, b)
if __name__ == '__main__':
main()
|
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# b,r = map(str, readline().split())
# A,B = map(int, readline().split())
br = LS()
AB = LI()
U = _S()
def main():
brAB = zip(br, AB)
tmp=[]
for c,n in brAB:
if c==U:
tmp.append(n - 1)
else:
tmp.append(n)
return str(tmp[0])+' '+str(tmp[1])
print(main())
| 1 | 71,991,947,439,552 | null | 220 | 220 |
import math
K = int(input())
# gcd(a, b, c)=gcd(gcd(a,b), c) が成り立つ
s = 0
for a in range(1, K+1):
for b in range(1, K+1):
d = math.gcd(a, b) # gcd(a, b)は先に計算しておく
for c in range(1, K+1):
s += math.gcd(d, c)
print(s)
|
for i in range(9):
for j in range(9):
print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1))
| 0 | null | 17,673,523,895,332 | 174 | 1 |
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in L:
for j in L:
for k in L:
if i < j < k:
if i + j + k > max(i,j,k) * 2:
ans += 1
else:
print(ans)
|
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
num=[l[i],l[j],l[k]]
if len(set(num))!=3:continue
num.sort()
if num[2]<num[1]+num[0]:ans+=1
print(ans)
| 1 | 5,103,392,064,540 | null | 91 | 91 |
n,m = map(int,input().split())
sub = []
for i in range(m):
tmp= [x for x in input().split()]
sub.append(tmp)
ac = [0]*n
wa = [0]*n
for i in range(m):
res = sub[i][1]
que = int(sub[i][0]) - 1
if res == "AC" and ac[que] == 0:
ac[que] += 1
elif res == "WA" and ac[que] == 0:
wa[que] += 1
for i in range(n):
if ac[i] != 1:
wa[i] = 0
print(sum(ac),sum(wa))
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
n = int(readline())
#print(n)
a_list = list([int(x) for x in readline().rstrip().split()])
#print(a_list)
count = 0
for i in a_list[::2]:
#print(i)
if i % 2 != 0:
count += 1
print(count)
| 0 | null | 50,601,218,972,992 | 240 | 105 |
strs = list(input().split())
print(strs[1]+strs[0])
|
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
n = int(input())
C = input()
C_cunt = Counter(C)
cunt_r = C_cunt['R']
ans = 0
for i in range(cunt_r):
if C[i] == 'W':
ans += 1
print(ans)
if __name__=='__main__':
main()
| 0 | null | 54,792,119,381,830 | 248 | 98 |
# FizzBuzz Sum
N = int(input())
ans = ((1+N) * N)/2 - ((3 + 3*(N//3)) * (N//3))/2 - ((5 + 5*(N//5)) * (N//5))/2 + ((15 + 15*(N//15)) * (N//15))/2
print(int(ans))
|
from string import ascii_lowercase, ascii_uppercase
l = ascii_lowercase
u = ascii_uppercase
def conv(c):
if c in l:
return u[l.index(c)]
if c in u:
return l[u.index(c)]
return c
open(1, 'w').write("".join(map(conv, open(0).readline())))
| 0 | null | 18,151,414,701,900 | 173 | 61 |
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
a[i],b[i] = map(int,input().split())
a.sort()
b.sort()
if n % 2 == 1:
print(b[n//2] - a[n//2] + 1)
else:
front = n//2
back = (n-1)//2
print((b[front] + b[back] - (a[front] + a[back]) + 1))
|
# https://codeforces.com/blog/entry/78195: Geothermal editorial
n = int(input())
A, B = [], []
for i in range(n):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if n%2 == 1:
medA, medB = A[n//2], B[n//2]
else:
medA = A[n//2] + A[n//2 - 1]
medB = B[n//2] + B[n//2 - 1]
print(medB - medA + 1)
| 1 | 17,297,549,359,340 | null | 137 | 137 |
n = int(input())
s = input()
for i in range(1, n):
if s[0] == s[i] and s[:i] == s[i:]:
print("Yes")
break
else:
print("No")
|
n=int(input())
print(1-(n//2)/n)
| 0 | null | 161,242,791,600,670 | 279 | 297 |
S = int(input())
h = S // 3600
m = S % 3600 // 60
s = (S % 3600) - (m * 60)
print(h,m,s,sep=':')
|
def main():
S = list(input())
cnt = 0
for i in range(int(len(S) / 2)):
if S[i] != S[-i - 1]:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 0 | null | 60,242,189,849,912 | 37 | 261 |
l=list(map(int, input().split()))
l1=[l[0],l[1]]
l2=[l[2],l[3]]
ans=l[0]*l[2]
for i in l1:
for j in l2:
if i*j>ans:
ans=i*j
print(ans)
|
ans=-10**18
a,b,c,d=map(int,input().split())
if a<=0<=b or c<=0<=d:
ans=0
ans=max(ans,a*c,a*d,b*c,b*d)
print(ans)
| 1 | 3,045,574,826,518 | null | 77 | 77 |
k= int(input())
s= input()
if len(s)>k:
r=s[:k]+"..."
print(r)
else:
print(s)
|
n = int(input())/3
print(n*n*n)
| 0 | null | 33,205,536,745,238 | 143 | 191 |
n = int(input())
a = list(map(int, input().split()))
m = 1000000007
print(((sum(a)**2 - sum(map(lambda x: x**2, a))) // 2) % m)
|
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18
def main():
#n = int(stdin.readline().rstrip())
h1,m1,h2,m2,k = map(int, stdin.readline().rstrip().split())
#l = list(map(int, stdin.readline().rstrip().split()))
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]
wake = (h2-h1)*60 + m2-m1
ans = wake - k
print(ans)
main()
| 0 | null | 10,944,940,559,168 | 83 | 139 |
#Is it Right Triangre?
n = int(input())
for i in range(n):
set = input(). split()
set = [int(a) for a in set] #int?????????
set.sort()
if set[0] ** 2 + set[1] ** 2 == set[2] ** 2:
print("YES")
else:
print("NO")
|
# -*- coding:utf-8 -*-
import sys
array = []
for i in sys.stdin:
array.append(i)
N = int(array[0])
for k in range(1,N+1):
x = array[k].split()
a, b, c = int(x[0]), int(x[1]), int(x[2])
if a**2 + b**2 == c**2 or b**2 + c**2 == a**2 or c**2 + a**2 == b**2:
print('YES')
else:
print('NO')
| 1 | 257,821,690 | null | 4 | 4 |
s = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
a = list(s.split(','))
n = int(input())
print(a[n-1])
|
index=int(input())
alist=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
index-=1
print(alist[index])
| 1 | 49,891,444,662,206 | null | 195 | 195 |
n, m, x = map(int, input().split())
c = [0] * n
a = [[0] * m for _ in range(n)]
for i in range(n):
tmp = list(map(int, input().split()))
c[i] = tmp[0]
a[i] = tmp[1:]
INF = 10 ** 9
ans = INF
for i in range(1 << n):
cost = 0
under = [0] * m
for j in range(n):
if not i >> j & 1: continue
cost += c[j]
for k in range(m):
under[k] += a[j][k]
ok = True
for k in range(m):
if under[k] < x: ok = False
if ok:
ans = min(ans, cost)
if ans == INF: print("-1")
else: print(ans)
|
n, m, x = map(int, input().split())
price = []
ability = []
for _ in range(n):
lst = []
lst = [int(i) for i in input().split()]
price.append(lst[0])
ability.append(lst[1:m + 1])
#print(price)
#print(ability)
min_price = float('inf')
for i in range(2 ** n):
flag = True
total = 0
obtain = [0] * m
for j in range(n):
if ((i >> j) & 1):
total += price[j]
for k in range(m):
obtain[k] += ability[j][k]
for j in range(m):
if obtain[j] < x:
flag = False
break
if flag:
if total < min_price:
min_price = total
if min_price == float('inf'):
print(-1)
else:
print(min_price)
| 1 | 22,280,774,683,232 | null | 149 | 149 |
K = int(input())
ans = ""
for _ in range(K):
ans += "ACL"
print(ans)
|
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
i_l=[]
j_l=[]
for i in range(n):
i_l.append(i+a[i])
j_l.append(i-a[i])
ci=Counter(i_l)
cl=Counter(j_l)
ans=0
for k,v in ci.items():
ans+=v*cl[k]
print(ans)
| 0 | null | 14,031,116,985,270 | 69 | 157 |
base, rate = 100, 0.05
for _ in range(int(input())):
increment = base * rate
base += round(increment + (0 if increment.is_integer() else 0.5))
print(base * 1000)
|
n = int(input())
debt = 100000
for i in range(n):
debt = debt * 1.05
round = debt % 1000
if round != 0:
debt = (debt // 1000 + 1) * 1000
print(int(debt))
| 1 | 1,135,786,780 | null | 6 | 6 |
N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N-1):
if A[i]==A[i+1]:
print("NO")
break
if i==N-2:
print("YES")
|
import heapq
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
bef = a[0]
for i in range(1,n):
if bef == a[i]:
print("NO")
break
bef = a[i]
if i == n-1:
print("YES")
| 1 | 73,902,281,576,460 | null | 222 | 222 |
h = int(input())
w = int(input())
n = int(input())
c = n // max(h,w)
if(n % max(h,w) != 0):c+=1
print(c)
|
num = int(input())
print('ACL'*num)
| 0 | null | 45,318,244,869,898 | 236 | 69 |
if __name__ == "__main__":
s, t = input().split()
print(t+s)
|
def main():
x = int(input())
a = 1
b = 1
for i in range(-118, 120):
a = i
for j in range(-118, 120):
b = j
if x == a**5 - b**5:
ans = str(a) + ' ' + str(b)
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 64,263,965,620,872 | 248 | 156 |
import itertools
N,M,X=map(int,input().split())
C=[0 for i in range(N)]
A=[[0 for j in range(M)]for i in range(N)]
for i in range(N):
line=list(map(int,input().split()))
C[i]=line[0]
for j in range(M):
A[i][j]=line[j+1]
ans=sum(C)+1
for seq in itertools.product(range(2),repeat=N):
R=[0 for i in range(M)]
cost=0
for i in range(N):
if seq[i]==0:
continue
cost+=C[i]
for j in range(M):
R[j]+=A[i][j]
if min(R)>=X:
ans=min(ans,cost)
if ans==sum(C)+1:
print(-1)
else:
print(ans)
|
import sys
def main():
read = sys.stdin.buffer.read
k, n, *A = map(int, read().split())
A += [A[0] + k]
far = max(y - x for x, y in zip(A, A[1:]))
print(k - far)
if __name__ == "__main__":
main()
| 0 | null | 32,906,703,844,254 | 149 | 186 |
def is_stable(output_str, same_num_str):
if len(same_num_str)>0:
for i in range(len(same_num_str)):
if output_str.find(same_num_str[i]) == -1:
return "Not stable"
return "Stable"
data_num = int(input())
cards = input().split(" ")
cards2 = cards[:]
cnt = 0
num_1 = 0
num_2 = 0
same_num_str = []
output_str = ""
judge_stbl = ""
for i in range(data_num):
for j in range(data_num-1, i,-1):
if int(cards[j][1:]) < int(cards[j-1][1:]):
cards[j], cards[j-1] = cards[j-1], cards[j]
elif int(cards[j][1:]) == int(cards[j-1][1:]):
same_num_str.append(cards[j-1]+" "+cards[j])
output_str = " ".join(cards)
judge_stbl = is_stable(output_str, same_num_str)
print(output_str + "\n" + judge_stbl)
same_num_str = []
output_str = ""
judge_stbl = ""
for i in range(data_num):
min_idx = i
for j in range(i, data_num):
if int(cards2[j][1:]) < int(cards2[min_idx][1:]):
min_idx = j
elif int(cards2[j][1:]) == int(cards2[min_idx][1:]) and j != min_idx:
same_num_str.append(cards2[min_idx]+" "+cards2[j])
if i != min_idx:
cards2[i], cards2[min_idx] = cards2[min_idx], cards2[i]
output_str = " ".join(cards2)
judge_stbl = is_stable(output_str, same_num_str)
print(output_str + "\n" + judge_stbl)
|
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)
| 0 | null | 286,413,120,586 | 16 | 44 |
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
aa = [a[i]*a[i] for i in range(n)]
s2 = sum(aa)
print((s**2 - s2) //2%(10**9+7))
|
n = int(input())
A = list(map(int, input().split()))
ans = 0
cumsum = 0
for i in range(n-1):
cumsum += A[n-i-1]
ans += (A[n-i-2] * cumsum)
ans %= 1000000007
print(ans)
| 1 | 3,818,514,178,502 | null | 83 | 83 |
S = input()
T = input()
ans = 99999999
for i in range(len(S)-len(T)+1):
word = S[i:i+len(T)]
cnt = 0
for j in range(len(word)):
if word[j]!=T[j]:
cnt+=1
ans = min(ans,cnt)
print(ans)
|
S = input()
T = input()
min_dist = 10**10
for i in range(len(S) - len(T) + 1):
for k in range(len(T)):
dist = 0
for s, t in zip(S[i:i + len(T)], T):
if s != t:
dist += 1
if dist >= min_dist:
break
min_dist = min(dist, min_dist)
if min_dist == 0:
print(0)
exit()
print(min_dist)
| 1 | 3,742,657,098,158 | null | 82 | 82 |
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b = nm()
if a<10 and b<10:
print(a*b)
exit()
print(-1)
|
a,b=map(int,input().split())
print(a*b if a>=1 and a<=9 and 0<b<10 else -1)
| 1 | 158,211,312,489,230 | null | 286 | 286 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
Ans = "YES"
List = []
before_n = 0
for e in A:
if e == before_n:
Ans = "NO"
break
else:
before_n=e
print(Ans)
|
N = int(input())
A = list(map(int, input().split()))
MAX = 0
A_map = {}
for i in range(N):
num = A[i]
A_map[num] = A_map.get(num,0) + 1
MAX = max(MAX, A_map[num])
if MAX>=2:
print('NO')
else:
print('YES')
| 1 | 73,835,444,412,680 | null | 222 | 222 |
import sys
import math
from math import ceil
input = sys.stdin.readline
print(ceil(int(input()) / 2))
|
from sys import stdin, setrecursionlimit
def main():
n = int(stdin.readline())
print(n // 2) if n % 2 == 0 else print((n + 1) // 2)
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| 1 | 59,128,073,353,668 | null | 206 | 206 |
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())
if W>=V:
print("NO")
quit()
SA=abs(A-B)
IDOU=V-W
IDOUTARN=IDOU*T
ANS=SA-IDOUTARN
if ANS<=0:
print("YES")
else:
print("NO")
|
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
ans = abs(b - a) - (v - w) * t
if ans > 0:
print('NO')
else:
print('YES')
| 1 | 15,199,110,163,818 | null | 131 | 131 |
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])
|
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k += 1
history[v].append(k)
for u in G[v]:
if u == p or visited[u]:
continue
dfs(u, v)
k += 1
history[v].append(k)
for i in range(N):
if not visited[i]:
dfs(i)
for i, h in enumerate(history):
print(i+1, *h)
| 1 | 2,879,140,242 | null | 8 | 8 |
import math
x = int(input())
def lcm(x, y):
return (x * y) // math.gcd(x, y)
print(lcm(x, 360)//x)
|
num_list=[]
while True:
num = input()
if num == 0:
break
num_list.append(num)
for num in num_list:
print sum(map(int,list(str(num))))
| 0 | null | 7,370,386,081,370 | 125 | 62 |
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
N,K = map(int,input().split())
W = [int(input()) for _ in range(N)]
r = 10 ** 10
l = 0
def ok(x):
cnt = 1
tot = 0
for i in range(N):
if tot + W[i] <= x:
tot += W[i]
else:
cnt += 1
if W[i] > x:
return False
tot = W[i]
return cnt <= K
while r - l > 1:
mid = (r + l)//2
if ok(mid):
r = mid
else:
l = mid
print(r)
|
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
left = 0
right = 100000*10000
while (right - left > 1):
mid = (left + right)//2
s = 0
j = 1
for i in range(n):
if mid < w[i]:
j = 100000
break
s += w[i]
if s > mid:
j += 1
s = w[i]
if j > k:
left = mid
else:
right = mid
print(right)
| 1 | 86,829,040,188 | null | 24 | 24 |
def main():
mod = 998244353
fact = [1, 1]
for i in range(2, 400001):
fact.append(fact[-1]*i % mod)
def nCr(n, r):
return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod
n, m, k = map(int, input().split())
ans = 0
for i in range(k+1):
ans = (ans+m*pow(m-1, n-i-1, mod)*nCr(n-1, n-i-1)) % mod
print(ans)
main()
|
a,b = map(int,input().split())
d = a // b
r = a % b
f = a / b
print(f"{d} {r} {f:.5f}")
| 0 | null | 11,885,695,235,370 | 151 | 45 |
# coding: utf-8
N = int(input())
_A = sorted(enumerate(map(int, input().split()), 1), key=lambda x:x[1], reverse=True)
dp = [[0] * (N+1) for i in range(N+1)]
for i in range(1,N+1):
k, Ak = _A[i-1]
if (N-i-k) < 0:break
dp[0][i] = dp[0][i-1] + (N-i+1-k) * Ak
for i in range(1,N+1):
k, Ak = _A[i-1]
if (k-i) < 0:break
dp[i][0] = dp[i-1][0] + (k-i) * Ak
for x in range(1, N+1):
for y in range(1, N-x+1):
k, val = _A[x+y-1]
dp[x][y]= max(dp[x-1][y] + abs(k-x)*val,
dp[x][y-1] + abs(N-y-k+1) * val)
print(int(max(dp[i][N-i] for i in range(N+1))))
|
import sys
sys.setrecursionlimit(700000)
def s_in():
return input()
def n_in():
return int(input())
def l_in():
return list(map(int, input().split()))
def print_l(l):
print(' '.join(map(str, l)))
class Interval():
def __init__(self, li):
self.li = li
self.n = len(li)
self.sum_li = [li[0]]
for i in range(1, self.n):
self.sum_li.append(self.sum_li[i-1] + li[i])
def sum(self, a, b=None):
if b is None:
return self.sum(0, a)
res = self.sum_li[min(self.n-1, b-1)]
if a > 0:
res -= self.sum_li[a-1]
return res
n = s_in()
k = n_in()
res = 0
d = len(n)
def comb(a,b):
if b == 0:
return 1
if b == 1:
return a
if b == 2:
return a*(a-1)//2
if b == 3:
return (a)*(a-1)*(a-2)//6
return 0
# 手前まで完全一致でii桁以降でl回非ゼロの時の場合の数
def calc(i, l):
m = int(n[i])
if i == d-1:
if l == 0:
if m == 0:
return 1
else:
return 0
elif l == 1:
if m == 0:
return 0
else:
return m
else:
return 0
if m == 0:
return calc(i+1, l)
else:
tmp = calc(i+1, l-1) # i桁めがmの場合
tmp += (m-1)*comb(d-i-1, l-1)*int(9**(l-1)) # 1..(m-1)
tmp += comb(d-i-1,l)*int(9**l)
return tmp
print(calc(0,k))
| 0 | null | 54,570,965,256,352 | 171 | 224 |
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
YES = "Yes" # type: str
NO = "No" # type: str
INF=10**20
def solve(K: int, X: int):
print(YES if K*500 >= X else NO)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
K = int(next(tokens)) # type: int
X = int(next(tokens)) # type: int
solve(K, X)
if __name__ == "__main__":
main()
|
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
k, x = list(map(int, readline().split()))
print("Yes" if 500 * k >= x else "No")
if __name__ == '__main__':
solve()
| 1 | 98,410,249,069,352 | null | 244 | 244 |
n = input()
print(n.replace('?','D'))
|
if __name__ == "__main__":
T = input()
ans = T
ans = ans.replace("P?", 'PD')
ans = ans.replace("??", 'PD')
ans = ans.replace("?D", 'PD')
ans = ans.replace("?", 'D')
print(ans)
| 1 | 18,465,192,205,570 | null | 140 | 140 |
N ,K = map(int,input().split())
Ps = list(map(int,input().split()))
Ps.sort()
ans = 0
for i in range(K):
ans += Ps[i]
print(ans)
|
[n, k] = map(int, input().split())
p_list = input().split()
p_list = [int(x) for x in p_list]
p_list.sort()
ans = 0
for i in range(k):
ans += p_list[i]
print(ans)
| 1 | 11,580,816,157,412 | null | 120 | 120 |
a,b = map(int,input().split())
c,d = map(int,input().split())
if ((a+1)==c or (a==12 and c==1)):
if d ==1:
print(1)
else:
print(0)
|
N,M=map(int,input().split())
n=['0']*N
a=0
for i in range(M):
s,c=map(str,input().split())
if n[int(s)-1]!='0' and n[int(s)-1]!=c:
a=1
if s=='1' and c=='0' and N!=1:
a=1
n[int(s)-1]=c
if n[0]=='0' and N!=1:
n[0]='1'
if a==0:
print(''.join(n))
else:
print(-1)
| 0 | null | 92,520,807,630,858 | 264 | 208 |
n=int(input())
a=list(map(int,input().split()))
j=1
for i in a:
if j==i:j+=1
print([n-j+1,-1][j==1])
|
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
A=LI()
cnt=0
now=1
for i in range(N):
if A[i]==now:
now+=1
else:
cnt+=1
if cnt==N:
cnt=-1
print(cnt)
main()
| 1 | 114,748,030,026,250 | null | 257 | 257 |
def resolve():
N = input()
heights = [int(x) for x in input().split(" ")]
max_heights = 0
s = 0
for h in heights:
if h < max_heights:
s += max_heights - h
else:
max_heights = h
print(s)
resolve()
|
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
if A[i] < A[i-1]:
step = A[i-1] - A[i]
A[i] += step
ans += step
print(ans)
| 1 | 4,536,566,359,262 | null | 88 | 88 |
d,t,s = map(int,input().split())
if d <= t*s:
result = "Yes"
else:
result = "No"
print(result)
|
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")
D, T, S = map(int, input().split())
if D / S > T:
print("No")
else:
print("Yes")
| 1 | 3,597,423,848,512 | null | 81 | 81 |
import sys
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
h, a =ISI()
print((h+a-1)//a)
|
import sys
input = sys.stdin.readline
def main():
ans = 0
H, W, M = map(int, input().split())
bombs = []
hs = [0]*(H)
ws = [0]*(W)
for _ in range(M):
h, w = map(int, input().split())
bombs.append(tuple([h-1, w-1]))
hs[h-1] += 1
ws[w-1] += 1
maxh = max(hs)
maxw = max(ws)
ans = maxh + maxw
maxhindex = [i for i, x in enumerate(hs) if x == maxh]
maxwindex = [i for i, x in enumerate(ws) if x == maxw]
isfound = False
bombs = set(bombs)
for i in maxhindex:
for j in maxwindex:
if (i, j) not in bombs:
print(ans)
exit()
print(ans-1)
if __name__ == '__main__':
main()
| 0 | null | 40,864,534,871,840 | 225 | 89 |
S = list(input())
word_num = int(len(S)/2)
temp_num = 0
if len(S) % 2 == 0:
for i in range(word_num):
if S[2*i]+S[2*i+1] == 'hi':
pass
else:
temp_num += 1
else:
pass
if len(S) % 2 == 0 and temp_num == 0:
print('Yes')
else:
print('No')
|
a,b=[int(i) for i in input().split()]
c=max(a,b)
if(a<=b):
d=a
else:
d=b
for i in range(1,100001):
if((d*i)%c==0):
print(d*i)
break
| 0 | null | 83,225,816,866,348 | 199 | 256 |
x=list(map(int,input().split()))
sum=0
for i in x:
sum+=i
print(15-sum)
|
x = [int(s) for s in input().split()]
print('Yes' if x[0] < x[1] and x[1] < x[2] else 'No')
| 0 | null | 6,928,581,952,812 | 126 | 39 |
N, K = map(int, input().split())
d = [0 for i in range(K)]
A = []
for i in range(K):
d[i] = int(input())
A.append(list(map(int, input().split())))
candy = [0 for i in range(N)]
for i in range(K):
for j in range(d[i]):
candy[A[i][j]-1] += 1
print(candy.count(0))
|
n, k = map(int, input().split())
ans = 0
a = []
for _ in range(n):
a.append(0)
for i in range(k):
d = int(input())
treat = list(map(int, input().split()))
for snuke in treat:
a[snuke-1] += 1
for j in range(n):
if a[j] == 0:
ans += 1
print(ans)
| 1 | 24,537,826,364,016 | null | 154 | 154 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.