code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
N = int(input())
es = [[] for _ in range(N)]
connected = [0] * N
for i in range(N-1):
a,b = map(int, input().split())
a,b = a-1, b-1
connected[a] += 1
connected[b] += 1
es[a].append((b, i))
es[b].append((a, i))
ans = [0] * (N-1)
used = [False] * (N-1)
q = []
q.append((0, 0))
while q:
curr, pc = q.pop()
nxt_es_color = 1
for nxt, es_num in es[curr]:
if used[es_num]:
continue
if nxt_es_color == pc:
nxt_es_color += 1
ans[es_num] = nxt_es_color
used[es_num] = True
q.append((nxt, ans[es_num]))
nxt_es_color += 1
print(max(connected))
print(*ans, sep="\n")
| from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N + 1)]
for i in range(N - 1):
x, y = map(int, input().split())
edge[x].append((y, i))
edge[y].append((x, i))
color = [-1] * (N - 1)
def dfs(s, p=-1, pc=-1):
c = 0
for t, x in edge[s]:
if color[x] != -1:
continue
if t == p:
continue
c += 1
if c == pc:
c += 1
color[x] = c
dfs(t, s, c)
dfs(1)
print(len(Counter(color)))
print(*color, sep="\n") | 1 | 136,179,571,050,390 | null | 272 | 272 |
# 問題:https://atcoder.jp/contests/abc143/tasks/abc143_b
n = int(input())
d = list(map(int, input().strip().split()))
res = 0
for i in range(1, n):
for j in range(i):
res += d[i] * d[j]
print(res)
| import itertools
N = int(input())
D = list(input().split())
a = itertools.combinations(D,2)
sum= 0
for i,j in a:
sum += eval("{} * {}".format(i,j))
print(sum) | 1 | 168,216,565,855,520 | null | 292 | 292 |
import sys
if __name__ == "__main__":
n = int(input())
if n == 0 or n == 1:
print(1)
sys.exit(0)
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, n + 1):
dp[i] = dp[i - 1] + dp[i - 2]
print(dp[n])
| def fib(n):
F = {0:1, 1:1}
def fibonacci(n):
ans = F.get(n,-1)
if ans > 0: return ans
F[n] = fibonacci(n-1) + fibonacci(n-2)
return F[n]
return fibonacci(n)
if __name__=='__main__':
print(fib(int(input()))) | 1 | 1,986,143,520 | null | 7 | 7 |
n=int(input())
mod=1000000007
l=list(map(int,input().split()))
me=[3]+[0]*2*n
ans=1
for x in l:
ans=ans*me[x]%mod
me[x]-=1
me[x+1]+=1
print(ans) | n = int(input())
c=0
for i in range(1,(n//2)+1):
if((n-i) != i):
c+=1
print(c) | 0 | null | 141,382,874,150,982 | 268 | 283 |
n, k, c = map(int, input().split())
s = input()
l = [0 for i in range(k+1)]
r = [0 for i in range(k+1)]
cnt = 0
kaime = 1
for i in range(n):
if kaime > k: break
if cnt > 0:
cnt -= 1
else:
if s[i] == 'o':
l[kaime] = i
kaime += 1
cnt = c
cnt = 0
kaime = k
for j in range(n):
i = n-1 - j
if kaime < 1: break
if cnt > 0:
cnt -= 1
else:
if s[i] == 'o':
r[kaime] = i
kaime -= 1
cnt = c
for i in range(1, k+1):
if l[i] == r[i]:
print(l[i]+1) | N, K, C = map(int, input().split())
S = input()
S_reverse = S[::-1]
left_justified = [-1 for _ in range(N)]
right_justified = [-2 for _ in range(N)]
for i_justified in (left_justified, right_justified):
if i_justified == left_justified:
i_S = S
nearest_position = 1
positioning = 1
else:
i_S = S_reverse
nearest_position = K
positioning = -1
i_K = 0
while i_K <= N-1:
if i_S[i_K] == 'o':
i_justified[i_K] = nearest_position
i_K += C
nearest_position += positioning
i_K += 1
for i_N in range(N):
if left_justified[i_N] == right_justified[N - i_N - 1]:
print(i_N + 1) | 1 | 40,637,146,634,800 | null | 182 | 182 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 +7
n,m = map(int,readline().split())
a = np.array(read().split(),np.int64)
a.sort()
def shake_cnt(x):
X=np.searchsorted(a,x-a)
return n*n-X.sum()
left = 0
right = 10 ** 6
while left+1 <right:
x = (left + right)//2
if shake_cnt(x) >= m:
left = x
else:
right = x
left,right
X=np.searchsorted(a,right-a)
Acum = np.zeros(n+1,np.int64)
Acum[1:] = np.cumsum(a)
shake = n * n -X.sum()
happy = (Acum[-1]-Acum[X]).sum()+(a*(n-X)).sum()
happy += (m-shake)*left
print(happy) | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,M = LI()
A = LI()
a = sorted(A,reverse=True)
high = a[0] * 2 + 1
low = 0
while high > low + 1:
mid = (high + low) // 2
cnt = 0
j = N - 1
for i in range(N):
while a[i] + a[j] < mid:
j -= 1
if j < 0: break
else:
cnt += (j+1)
continue
break
if cnt <= M:
high = mid
else:
low = mid
s = [a[0]]
for i in range(1,N):
s.append(s[-1]+a[i])
ans = 0
cnt = 0
m = a[0] * 2
j = N - 1
for i in range(N):
while a[i] + a[j] < low:
j -= 1
if j < 0: break
else:
ans += a[i] * (j+1) + s[j]
cnt += j + 1
m = min(m,a[i] + a[j])
continue
break
print(ans - (cnt-M) * low)
if __name__ == '__main__':
main() | 1 | 107,767,601,306,012 | null | 252 | 252 |
n=int(input())
if n%2==1:print(0)
else:
n//=2
i=5
s=0
while i<=n:
s+=n//i
i*=5
print(s) | n = int(input())
if n%2 == 1:
print(0)
exit()
n //= 2
ans = 0
now = 1
while True:
tmp = n // (5**now)
if tmp == 0:
break
ans += tmp
now += 1
print(ans) | 1 | 116,042,854,022,928 | null | 258 | 258 |
a,b,c = map(int,input().split())
K = int(input())
judge = False
for i in range(K+1):
for j in range(K+1):
for k in range(K+1):
x = a*2**i
y = b*2**j
z = c*2**k
if i+j+k <= K and x < y and y < z:
judge = True
if judge:
print("Yes")
else:
print("No") | N = int(input())
S = input()
ans = ''
for i in S:
num = (ord(i) + N)
if num > 90:
num = 64 + num % 90
ans += chr(num)
print(ans)
| 0 | null | 70,546,390,434,912 | 101 | 271 |
string = list(map(str, input()))
ans =[]
for char in string:
if char.islower():
ans.append(char.upper())
elif char.isupper():
ans.append(char.lower())
else:
ans.append(char)
print(ans[-1], end="")
print()
| w = input()
r = ''
for i in range(len(w)):
c = str(w[i])
if (w[i].islower()):
c = w[i].upper()
elif (w[i].isupper()):
c = w[i].lower()
r = r + c
print(r)
| 1 | 1,475,082,813,230 | null | 61 | 61 |
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
def fibo(n):
a, b = 1, 1
while n:
a, b = b, a + b
n -= 1
return a
print(fibo(int(stdin.readline()))) | n = int(raw_input())
F = [0] * (n+1)
def fibonacci(n):
global F
if n == 0 or n == 1:
F[n] = 1
return F[n]
if F[n] != 0:
return F[n]
F[n] = fibonacci(n-2) + fibonacci(n-1)
return F[n]
def makeFibonacci(n):
global F
F[0] = 1
F[1] = 1
for i in xrange(2,n+1):
F[i] = makeFibonacci(i-2) + makeFibonacci(i-1)
return F[n]
def main():
ans = fibonacci(n)
print ans
return 0
main() | 1 | 2,253,427,498 | null | 7 | 7 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
bottom, top = 0, max(A)
def cut(x):
cnt = 0
for Length in A:
if Length % x == 0:
cnt += Length // x
else:
cnt += Length // x + 1
cnt -= 1
return cnt <= k
while top - bottom > 1:
middle = (top + bottom) // 2
if cut(middle):
top = middle
else:
bottom = middle
print(top) | import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase
"""def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)"""
"""def pw(a,b):
result=1
while(b>0):
if(b%2==1): result*=a
a*=a
b//=2
return result"""
def inpt():
return [int(k) for k in input().split()]
def check(mid,k,ar):
ct=k
for i in ar:
if(i<=mid):
continue
ct-=(i//mid)
return ct>=0
def main():
n,k=map(int,input().split())
ar=inpt()
i,j=1,100000000000
while(i<j):
mid=(i+j)//2
if(check(mid,k,ar)):
j=mid
else:
i=mid+1
print(i)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
| 1 | 6,473,740,233,880 | null | 99 | 99 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
def solve(L: int):
return L**3 / 27
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
L = int(next(tokens)) # type: int
print(f'{solve(L)}')
if __name__ == '__main__':
main()
| # -*- coding: utf-8 -*-
def main():
S = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i, name in enumerate(week):
if name == S:
ans = 7 - i
print(ans)
if __name__ == "__main__":
main() | 0 | null | 89,762,295,769,158 | 191 | 270 |
A, B, C = map(int, input().split())
K = int(input())
flg = 0
for i in range(K):
if B > A:
if C > B or 2*C > B:
flg = 1
else:
C = 2*C
else:
B = 2*B
continue
if flg:
print('Yes')
else:
print('No') | A = list(map(int, input().split()))
print('bust') if sum(A) >= 22 else print('win') | 0 | null | 63,076,630,807,868 | 101 | 260 |
N = list(input())
inN = [int(s) for s in N]
if sum(inN) % 9 == 0:
print('Yes')
else:
print('No')
| N=str(input())
NN=0
for i in range(len(N)):
NN=NN+int(N[i])
if NN%9==0:print('Yes')
else:print('No') | 1 | 4,434,257,486,670 | null | 87 | 87 |
import math
N, D = map(int,input().split())
XY = list(list(map(int,input().split())) for _ in range(N))
count = 0
for i in range(N):
if math.sqrt(XY[i][0] ** 2 + XY[i][1] ** 2) <= D: count += 1
print(count) | def main():
N, D = map(int, input().split())
ans = 0
for _ in range(N):
x, y = map(int, input().split())
if x*x + y* y <= D*D:
ans += 1
return ans
if __name__ == '__main__':
print(main())
| 1 | 5,882,252,494,690 | null | 96 | 96 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [_p-1 for _p in p]
c = list(map(int, input().split()))
ans = -float('inf')
visited = [False] * n
ss = []
for i in range(n):
if visited[i]: continue
cur = i
s = []
while not visited[cur]:
visited[cur] = True
s.append(c[cur])
cur = p[cur]
ss.append(s)
for s in ss:
m = len(s)
cumsum = [0] * (m*2+1)
for i in range(2*m):
cumsum[i+1] = cumsum[i] + s[i%m]
amari = [-float('inf')] * m
for i in range(m):
for j in range(m):
amari[j] = max(amari[j], cumsum[i+j] - cumsum[i])
for r in range(0, m):
if r > k: continue
q = (k-r)//m
if r==0 and q==0:
continue
if cumsum[m] > 0:
ans = max(ans, amari[r] + cumsum[m]*q)
elif r > 0:
ans = max(ans, amari[r])
print(ans)
| n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
P[i]-=1
C=list(map(int,input().split()))
PP=[0]*n
A=[0]*n
V=[0]*n
for i in range(n):
if V[i]==1:
continue
B=[i]
c=1
j=i
p=C[i]
while P[j]!=i:
j=P[j]
B.append(j)
c=c+1
p=p+C[j]
for j in B:
A[j]=c
PP[j]=p
ans=-10**10
for i in range(n):
if PP[i]<0:
aans=0
f=0
else:
if k//A[i]-1>0:
aans=(k//A[i]-1)*PP[i]
f=1
else:
aans=0
f=2
l=i
aaans=-10**10
if f==0:
for j in range(min(k,A[i])):
aans=aans+C[P[l]]
l=P[l]
if aans>aaans:
aaans=aans
elif f==1:
for j in range(k%A[i]+A[i]):
aans=aans+C[P[l]]
l=P[l]
if aans>aaans:
aaans=aans
else:
for j in range(min(k,2*A[i])):
aans=aans+C[P[l]]
l=P[l]
if aans>aaans:
aaans=aans
if aaans>ans:
ans=aaans
print(ans) | 1 | 5,394,547,557,120 | null | 93 | 93 |
a, b, m = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = []
for _ in range(m):
x, y, c = map(int, input().split())
x, y = x-1, y-1
li_c.append(li_a[x]+li_b[y]-c)
li_a.sort()
li_b.sort()
li_c.sort()
ans = min(li_a[0]+li_b[0], li_c[0])
print(ans)
| A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
res = min(a) + min(b)
for _ in range(M):
x, y, c = map(int, input().split())
discounted_v = a[x-1] + b[y-1] - c
if discounted_v < res: res = discounted_v
print(res)
| 1 | 54,010,800,960,032 | null | 200 | 200 |
import sys
sys.setrecursionlimit(10**8)
N = int(input())
X = input()
if X == '0':
for _ in range(N):
print(1)
exit()
mem = [None] * (200005)
mem[0] = 0
def f(n):
if mem[n] is not None: return mem[n]
c = bin(n).count('1')
r = 1 + f(n%c)
mem[n] = r
return r
for i in range(200005):
f(i)
cnt = X.count('1')
a,b = cnt+1, cnt-1
ans = [None] * N
n = 0
for c in X:
n *= 2
n += int(c)
n %= a
for i,c in reversed(list(enumerate(X))):
if c=='1': continue
ans[i] = mem[(n+pow(2,N-i-1,a))%a] + 1
if b:
n = 0
for c in X:
n *= 2
n += int(c)
n %= b
for i,c in reversed(list(enumerate(X))):
if c=='0': continue
ans[i] = mem[(n-pow(2,N-i-1,b))%b] + 1
else:
for i in range(N):
if ans[i] is None:
ans[i] = 0
print(*ans, sep='\n') | def lstToInt(l,x=0):
if len(l) == 0:
return x
else:
return lstToInt(l[1:], x*10 + l[0])
n,m = map(int,input().split())
c = [-1]*n
for i in range(m):
s, num = map(int,input().split())
if c[s-1] != -1 and c[s-1] != num:
print(-1)
exit()
elif s == 1 and num == 0 and n != 1:
print(-1)
exit()
else:
c[s-1] = num
if c[0] == -1 and n != 1:
c[0] = 1
ans = lstToInt(list(0 if c[i] == -1 else c[i] for i in range(n)))
print(ans) | 0 | null | 34,354,709,464,558 | 107 | 208 |
def insertionSort(n, A, g):
global cnt
for i in range(g, n):
temp = A[i]
j = i - g
while j >= 0 and A[j] > temp:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = temp
return A
def shellSort(A, n):
global m
global G
h = 1
while True:
if h > n:
break
G.append(h)
h = 3 * h + 1
G.reverse()
m =len(G)
for i in range(m):
insertionSort(n, A, G[i])
if __name__ == "__main__":
n = int(input())
A = [int(input()) for i in range(n)]
G = []
m = 0
cnt = 0
shellSort(A, n)
print(m)
print(*G)
print(cnt)
for i in range(n):
print(A[i]) | import sys
from collections import deque
def main():
N, p, q, *AB = map(int, sys.stdin.buffer.read().split())
p -= 1
q -= 1
G = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
G[a - 1].append(b - 1)
G[b - 1].append(a - 1)
if len(G[p]) == 1 and G[p][0] == q:
print(0)
return
dist1 = [-1] * N
dist1[p] = 0
queue = deque([p])
while queue:
v = queue.popleft()
for nv in G[v]:
if dist1[nv] == -1:
dist1[nv] = dist1[v] + 1
queue.append(nv)
dist2 = [-1] * N
dist2[q] = 0
queue = deque([q])
while queue:
v = queue.popleft()
for nv in G[v]:
if dist2[nv] == -1:
dist2[nv] = dist2[v] + 1
queue.append(nv)
max_d = 0
for d1, d2 in zip(dist1, dist2):
if d1 < d2 and max_d < d2:
max_d = d2
print(max_d - 1)
return
if __name__ == '__main__':
main()
| 0 | null | 58,552,984,248,122 | 17 | 259 |
N=int(input())
S=list(input())
a=0#色変化
for i in range(N-1):
if not S[i]==S[i+1]:
a=a+1
print(a+1) | n = int(input())
s = input()
x = n
for i in range(n-1):
if s[i] == s[i+1]:
x -= 1
print(x) | 1 | 170,113,041,305,812 | null | 293 | 293 |
n=int(input())
a=list(sorted(map(int,input().split())))
d=[0 for i in range(a[-1]+1)]
c=0
for i in range(len(a)):
if d[a[i]]:
continue
if i==len(a)-1 or a[i]!=a[i+1]:
c+=1
for j in range(a[i],a[-1]+1,a[i]):
d[j]=1
print(c) | import sys
input = sys.stdin.readline
import math
def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))
f_inf = float('inf')
n = INT()
a = sorted(LMAPINT())
length = (max(a) + 1)
ans = [0] * length
for x in a:
# 重複
if ans[x] != 0:
ans[x] = 2
continue
for j in range(x, length, x):
ans[j] += 1
count = 0
for x in a:
if ans[x] == 1:
count += 1
print(count) | 1 | 14,525,008,376,648 | null | 129 | 129 |
import math
import sys
def main():
n = int(sys.stdin.readline())
total = 0
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
total += math.gcd(i, math.gcd(j,k))
print(total)
main() | import math
cnt=0
n=int(input())
for i in range(1,n+1):
for j in range(1,n+1):
wk=math.gcd(i,j)
for k in range(1,n+1):
cnt+=math.gcd(wk,k)
print(cnt) | 1 | 35,782,394,525,192 | null | 174 | 174 |
import itertools
n = int(input())
S = list(input())
L = [k for k, v in itertools.groupby(S)]
print(len(L)) | a,b=input().split()
a=int(a)
b=int(b)
if a<10 and b<10:
print(a*b)
else:
print("-1") | 0 | null | 164,356,562,217,430 | 293 | 286 |
n = int(input())
v = 'abcdefghij'
def dfs(s):
if len(s) == n:
print (s)
return
for i in range(len(set(s))+1):
dfs(s+v[i])
dfs('a') | # 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
n = int(input())
s = [((ord(ch) - 65 + n) % 26) + 65 for ch in input()]
print("".join(map(chr, s))) | 0 | null | 93,116,196,886,690 | 198 | 271 |
import math
a, b, k = list(map(int, input().split(' ')))
if k > a*a*b / 2:
# k = a*a*b - a*a*p/2 | pは斜めの水の内側の高さの方の辺, p = b で丁度半分
# p = 2b - 2k/(a*a)
p = 2*b - 2*k / (a*a)
# 三角形の長い方をqとして qq = pp + aa
q = (p**2 +a**2) ** 0.5
# q * sin(r) = p
# r = ... わからんので 2分探索
left = 0.0
right = 90.0
while right > left + 1e-12:
r = (left + right) / 2.0
if q * math.sin(math.radians(r)) < p:
left = r
else:
right = r
else:
# k = a*b*p/2
# p = 2*k/(a*a)
p = 2*k/(a*b)
# 三角形の長い方をqとして qq = pp + aa
q = (p**2 +b**2) ** 0.5
# r = ... わからんので 2分探索
left = 0.0
right = 90.0
while right > left + 1e-12:
r = (left + right) / 2.0
if q * math.sin(math.radians(r)) < b:
left = r
else:
right = r
print(r) | from math import atan, pi
a, b, x = map(int, input().split())
if a * a * b > 2 * x:
ans = atan(a * b * b / 2 / x)
else:
ans = atan((2 * a * a * b - 2 * x) / a / a / a)
ans *= 180 / pi
print(ans)
| 1 | 163,087,312,448,840 | null | 289 | 289 |
def resolve():
k = int(input())
x = 7 % k
for i in range(1, k + 1):
if x == 0:
print(i)
return
x = (x * 10 + 7) % k
print(-1)
resolve() | from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
cntr = Counter(S)
mc = cntr.most_common()
n = mc[0][1]
ans = []
for k, v in mc:
if n!=v:
break
ans.append(k)
ans.sort()
print("\n".join(ans))
| 0 | null | 38,121,868,886,400 | 97 | 218 |
while True:
try:
(h,w)=map(int,raw_input().split())
if h==0 and w==0: break
for i in xrange(h):
print ''.join(['#' for j in xrange(w)])
print
except EOFError: break | while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
for i in range(H):
width = ""
for j in range(W):
width += "#"
print width
print "" | 1 | 765,530,537,018 | null | 49 | 49 |
N = int(input())
cnt = 0
for _ in range(N):
a, b = map(int, input().split())
if a == b:
cnt += 1
else:
cnt = 0
if cnt == 3:
print('Yes')
exit()
print('No') | s,t=input().split();print(t+s) | 0 | null | 52,846,861,048,100 | 72 | 248 |
a, b = map(int, input().split())
print(a // b, a % b, "{:.10f}".format(a / b))
| a, b = input().split()
a = int(a)
b = int(b)
print(a//b, a%b, "{0:.5f}".format(a/b)) | 1 | 606,423,447,100 | null | 45 | 45 |
L=int(input())
answer=(round(L/3,10))**3
print(answer) | import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import reduce
# from math import *
from fractions import *
N, M = map(int, readline().split())
A = list(map(lambda x: int(x) // 2, readline().split()))
def f(n):
cnt = 0
while n % 2 == 0:
n //= 2
cnt += 1
return cnt
t = f(A[0])
for i in range(N):
if f(A[i]) != t:
print(0)
exit(0)
A[i] >>= t
M >>= t
lcm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
if lcm > M:
print(0)
exit(0)
print((M // lcm + 1) // 2)
| 0 | null | 74,224,179,320,508 | 191 | 247 |
x, y = (int(x) for x in input().split())
if x == y == 1: print(1000000)
else:
ans = 0
points = [300000, 200000, 100000]
if x <= 3: ans += points[x-1]
if y <= 3: ans += points[y-1]
print(ans)
| x,y=map(int,input().split())
ans=0
if x<=3:
ans+=(4-x)*100000
if y<=3:
ans+=(4-y)*100000
if ans==600000:
ans=1000000
print(ans) | 1 | 140,430,090,338,630 | null | 275 | 275 |
import math
while True:
n = int(input())
if n == 0:
break
s = [int(s) for s in input().split()]
ave = sum(s) / n
a = 0
for N in s:
a += (N - ave)**2
a = math.sqrt((a / n))
print(a) | l,r,d=map(int,input().split())
print(len([i for i in range(l,r+1) if i%d==0])) | 0 | null | 3,867,359,846,702 | 31 | 104 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
error_print(e - s, 'sec')
return ret
return wrap
class Combination:
def __init__(self, n, mod):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod//i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD
@mt
def slv(N, K):
ans = 0
M = 10**9 + 7
C = Combination(N*2+1, M)
def H(n, r):
return C(n+r-1, r)
K = min(N-1, K)
for k in range(K+1):
m = N - k
t = C(N, k) * H(m, k)
ans += t
ans %= M
return ans
def main():
N, K = read_int_n()
print(slv(N, K))
if __name__ == '__main__':
main()
| n,k=map(int,input().split())
P=10**9+7
class FactInv:
def __init__(self,N,P):
fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
for i in range(1,N):
fact[i+1]=(fact[i]*(i+1))%P
ifact[-1]=pow(fact[-1],P-2,P)
for i in range(N,0,-1):
ifact[i-1]=(ifact[i]*i)%P
self.fact=fact;self.ifact=ifact;self.P=P
def comb(self,n,k):
return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
C=FactInv(2*n+10,P)
ans=0
for i in range(0,min(k+1,n)):
ans+=(C.comb(n,i)*C.comb(n-1,n-i-1))%P
ans%=P
print(ans) | 1 | 67,515,540,845,382 | null | 215 | 215 |
import collections
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
N=int(input())
D = collections.Counter(prime_factorize(N))
A=0
for d in D:
e=D[d]
for i in range(40):
if (i+1)*(i+2)>2*e:
A=A+i
break
print(A) | import collections
import sys
def input(): return sys.stdin.readline().rstrip()
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
N = int(input())
count = 0
prime_list = collections.Counter(prime_factorize(N))
for key in prime_list:
num = prime_list[key]
for i in range(1, num+1):
if i <= num:
num -= i
count += 1
else:
break
print(count) | 1 | 17,020,564,918,812 | null | 136 | 136 |
# coding: utf-8
from math import sqrt
def main():
N = int(input())
ans = 1e12 + 1
for i in range(1, int(sqrt(N)) + 1):
if N % i == 0:
j = N // i
ans = min(ans, i + j - 2)
print(ans)
if __name__ == "__main__":
main()
| from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
from math import sqrt
sys.setrecursionlimit(4100000)
if __name__ == '__main__':
N = int(input())
max_N = int(sqrt(N))+2
ans = 10e13
for a in range(1, max_N):
if N%a==0:
b = N//a
ans = min(ans, a+b-2)
print(ans) | 1 | 161,080,842,272,180 | null | 288 | 288 |
n=int(input())
a=list(map(int,input().split()))
l=[]
flag=0
for aa in a:
if aa%2==0:
flag=1
l.append(aa)
if flag==1:
for ll in l:
if ll % 3!=0 and ll % 5!=0:
flag=2
if flag==0:
print('APPROVED')
elif flag==1:
print('APPROVED')
elif flag==2:
print('DENIED')
| n = input()
a = map(int,raw_input().split())
s = 0
m = a[0]
M = a[0]
for i in range(0,n):
s = s + a[i]
if m > a[i]:
m = a[i]
if M < a[i]:
M = a[i]
print m,M,s | 0 | null | 35,008,810,147,922 | 217 | 48 |
# coding:utf-8
import sys
a = []
for line in sys.stdin:
a.append(list(line.strip().replace(" ","").lower()))
a = reduce(lambda x,y: x+y,a)
dict = {}
for i in range(26):
dict[chr(ord('a')+i)] = 0
for i in a:
for key,value in dict.items():
if key == i:
dict[key] += 1
for key,value in sorted(dict.items()):
print "%s : %d" % (key,value)
| count_al = list(0 for i in range(26))
while True :
try :
a = str(input())
b = a.lower()
for i in range(len(b)) :
c = ord(b[i])
if c > 96 and c < 123 :
count_al[c - 97] += 1
except EOFError :
break
for i in range(97, 123) :
print(chr(i), ":", count_al[i-97])
| 1 | 1,648,741,068,870 | null | 63 | 63 |
N = int(input())
A = list(map(int, input().split()))
flag = True
for n in A:
if n % 2 == 0 and (n % 3 != 0 and n % 5 != 0):
flag = False
print("APPROVED" if flag else "DENIED")
| L = int(input())
l = L / 3
print(l ** 3) | 0 | null | 58,095,483,884,548 | 217 | 191 |
import math
def insertionSort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j -= g
cnt += 1
A[j + g] = v
return cnt
def shellSort(A, n):
cnt = 0
j = int(math.log(2 * n + 1, 3)) + 1
G = list(reversed([(3 ** i - 1)// 2 for i in range(1, j)]))
m = len(G)
for i in range(m):
cnt += insertionSort(A, n, G[i])
return A, cnt, G, m
n = int(input())
A = [int(input()) for i in range(n)]
ans, count, G, m = shellSort(A, n)
print(m)
print(' '.join(map(str,G)))
print(count)
[print(i) for i in A] | def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j = j - g
cnt += 1
A[j + g] = v
def shellSort(A, n):
global cnt
G = []
g = 1
while g <= n:
G.append(g)
g = 3 * g + 1
G = G[::-1]
m = len(G)
for i in range(m):
insertionSort(A, n, G[i])
return m, G, cnt, A
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
cnt = 0
m, G, cnt, A = shellSort(A, n)
print(m)
for i in range(m):
if i == m - 1:
print(G[i])
else:
print(G[i], end=' ')
print(cnt)
for i in range(n):
print(A[i])
| 1 | 31,859,302,880 | null | 17 | 17 |
s=input()
ch=False
for i in s:
if i=="7":ch=True
if ch:print("Yes")
else:print("No") | n = input()
print("Yes" if "7" in n else "No") | 1 | 34,229,783,004,578 | null | 172 | 172 |
n=int(input())
taro=0
hanako=0
for i in range(n):
T,H=map(str,input().split())
if T<H:
hanako+=3
elif T>H:
taro+=3
else:
taro+=1
hanako+=1
print(taro, hanako)
| n=input()
t_p=0
h_p=0
for i in range(int(n)):
t,h=input().split()
a=sorted([t,h])
if t == h:
t_p+=1
h_p+=1
elif t == a[1]:
t_p+=3
else:
h_p+=3
print(t_p, h_p) | 1 | 2,004,294,284,582 | null | 67 | 67 |
class Dice:
def __init__(self,labels):
self.stat = labels
def roll_E(self):
self.stat[0],self.stat[2],self.stat[3],self.stat[5] = self.stat[3],self.stat[0],self.stat[5],self.stat[2]
def roll_N(self):
self.stat[0],self.stat[1],self.stat[5],self.stat[4] = self.stat[1],self.stat[5],self.stat[4],self.stat[0]
def roll_S(self):
self.stat[0],self.stat[1],self.stat[5],self.stat[4] = self.stat[4],self.stat[0],self.stat[1],self.stat[5]
def roll_W(self):
self.stat[0],self.stat[2],self.stat[5],self.stat[3] = self.stat[2],self.stat[5],self.stat[3],self.stat[0]
def get_top(self):
return self.stat[0]
dice = Dice(input().split())
commands = input()
for command in commands:
if command == "E":
dice.roll_E()
elif command == "N":
dice.roll_N()
elif command == "S":
dice.roll_S()
elif command == "W":
dice.roll_W()
print(dice.get_top())
| from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
k = ri()
a, b = rl()
for i in range(k, 1001, k):
if a <= i <= b:
print ("OK")
return
print ("NG")
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| 0 | null | 13,326,747,343,520 | 33 | 158 |
K = int(input())
S = str(input())
s_l = len(S)
s_k = list(S)
answer = s_k[slice(0, K)]
result = ''.join(answer)
if s_l <= K:
print(S)
else:
print(result + '...') | k = int(input())
s = input()
sen = ''
if len(s) <= k:
print(s)
else:
for i in range(k):
sen = sen + s[i]
print(sen+'...')
| 1 | 19,584,268,232,932 | null | 143 | 143 |
from itertools import permutations
import math
n = int(input())
x = []
y = []
for i in range(n):
xi, yi = map(int, input().split(' '))
x.append(xi)
y.append(yi)
l = [i for i in range(n)]
route = list(permutations(l))
length = 0
for ls in route:
for i in range(n-1):
length += math.sqrt((x[ls[i+1]]-x[ls[i]])**2+(y[ls[i+1]]-y[ls[i]])**2)
ans = length/math.factorial(n)
print(ans) | import itertools as it
import math
def Dist (x1,y1,x2,y2):
dis = (x2 - x1)**2 + (y2 - y1)**2
return math.sqrt(dis)
N = int(input())
Pos = []
res = 0
for i in range(N):
pos = list(map(int,input().split()))
Pos.append(pos)
array = list(it.permutations(i for i in range(N)))
for i in range(math.factorial(N)):
for j in range(N-1):
res += Dist(Pos[array[i][j]][0],Pos[array[i][j]][1],Pos[array[i][j+1]][0],Pos[array[i][j+1]][1])
print(res / math.factorial(N)) | 1 | 148,456,780,743,766 | null | 280 | 280 |
a, b = map(int, input().split())
print('a ', end='')
if a < b:
print('<', end='')
elif a > b:
print('>', end='')
elif a == b:
print('==', end='')
print(' b') | N = int(input())
A = list(map(int, input().split()))
print("APPROVED" if all(a&1 or (a%3==0 or a%5==0) for a in A) else "DENIED") | 0 | null | 34,660,092,084,836 | 38 | 217 |
import sys
n = int(input())
for i in range(1, n + 1):
x = i
if x % 3 == 0:
sys.stdout.write(" %d" % i)
else:
while x > 1:
if x % 10 == 3:
sys.stdout.write(" %d" % i)
break
x //= 10
print() | if __name__ == '__main__':
limit = int(input())
data = []
for i in range(3, limit+1):
if (i % 3) == 0 or '3' in str(i):
data.append(str(i))
txt = ' '.join(data)
print(' {0}'.format(txt)) | 1 | 937,735,821,444 | null | 52 | 52 |
n = int(input())
A = list(map(int,input().split()))
ans = [0]*n
for i in range(n):
ans[A[i] - 1] = str(i + 1)
Ans = ' '.join(ans)
print(Ans) | n,*a=map(int,open(0).read().split())
b=[0]*n
for i in range(n):
b[a[i]-1]=str(i+1)
print(' '.join(b)) | 1 | 181,001,982,346,652 | null | 299 | 299 |
NN=raw_input()
N=raw_input()
A = [int(i) for i in N.split()]
swap=0
for i in range(int(NN)):
for j in reversed(range(i+1,int(NN))):
if A[j] < A[j-1] :
t = A[j]
A[j] = A[j-1]
A[j-1] = t
swap+=1
print ' '.join([str(k) for k in A])
print swap | n=int(input())
arr=list(map(int,input().split()))
if n<=3:
print(max(arr))
exit()
lim=n%2+2
dp=[[0]*lim for _ in range(n+1)]
for i in range(n):
dp[i+1][0]=dp[i-1][0]+arr[i]
dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i])
if lim==3:
dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i])
print(max(dp[-1][:lim])) | 0 | null | 18,646,745,611,288 | 14 | 177 |
N,M,K = list(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)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
V = [[] for _ in range(N)]
for _ in range(M):
a,b = map(int, input().split())
a,b = a-1, b-1
V[a].append(b)
V[b].append(a)
uf.union(a,b)
for _ in range(K):
a,b = map(int, input().split())
a,b = a-1, b-1
if uf.same(a,b):
V[a].append(b)
V[b].append(a)
ans = [-1] * N
for i in range(N):
ans[i] = uf.size(i) - len(V[i]) - 1
print(" ".join(list(map(str, ans))))
| from collections import deque
N, M, K = map(int,input().split())
friendlist = [[] for _ in range(N+1)]
for n in range(M):
A, B = map(int,input().split())
friendlist[A].append(B)
friendlist[B].append(A)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
C, D = map(int, input().split())
blocklist[C].append(D)
blocklist[D].append(C)
whatgroup = [-1 for _ in range(N+1)]
visited = [-1] * (N+1)
d = deque()
leaderdic = {}
for person in range(1,N+1):
d.append(person)
leader = person
cnt = 0
while len(d)>0:
nowwho = d.popleft()
if whatgroup[nowwho] != -1:
continue
d.extend(friendlist[nowwho])
whatgroup[nowwho] = leader
cnt += 1
if cnt != 0:
leaderdic[leader] = cnt
for person in range(1,N+1):
ans = leaderdic[whatgroup[person]]
ans -= 1
ans -= len(friendlist[person])
for block in blocklist[person]:
if whatgroup[person]==whatgroup[block]:
ans -= 1
print(ans) | 1 | 61,534,577,904,420 | null | 209 | 209 |
X=int(input())
i=1
a=0
while True:
a=a+X
if a%360==0:
print(i)
break
i+=1 | import heapq
import math
def solve():
N, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
l = 0
r = A[0]
# (l, r]
#print(A)
#print("K=",K)
while r - l> 1:
m = (r + l) // 2
cuts = 0
for a in A:
cuts += (a-1) // m
#print(l, m,r, cuts)
if cuts <= K:
r = m
else:
l = m
print(r)
solve() | 0 | null | 9,865,814,956,892 | 125 | 99 |
import sys
a = []
answer_array = []
for line in sys.stdin:
a.append(map(int, line.strip().split()))
#except StopIteration:
#break
for i in range(len(a)):
sum_up = a[i][0] + a[i][1]
answer = len(str(sum_up))
answer_array.append(answer)
for j in range(len(answer_array)):
print answer_array[j] | import sys
a=[map(int,i.split()) for i in sys.stdin]
[print(len(str(b+c))) for b,c in a] | 1 | 106,243,970 | null | 3 | 3 |
n = int(input())
data = {}
for i in range(n):
b, f, r, v = map(int, input().split())
if (b,f,r) in data:
data[(b,f,r)] = data[(b,f,r)] + v
else:
data[(b,f,r)] = v
for b in range(1,5):
for f in range(1,4):
for r in range(1,11):
if (b,f,r) in data:
print(" "+str(data[(b,f,r)]),end="")
else:
print(" 0",end="")
print("")
if b < 4:
print("#"*20) | nb=4
nf=3
nr=10
d = {}
n = int(input())
for i in range(n):
[b,f,r,v] = map(int, input().split())
key = "%2d %2d %2d" % (b,f,r)
if key in d:
d[key] += v
else:
d[key] = v
for b in range(1,nb+1):
for f in range(1,nf+1):
for r in range(1,nr+1):
key = "%2d %2d %2d" % (b,f,r)
if key in d:
print(" "+str(d[key]),end="")
else:
print(" "+str(0),end="")
if r==nr:
print()
if r==nr and f==nf and b != nb:
print('####################') | 1 | 1,112,276,137,088 | null | 55 | 55 |
rc=list(map(int,input().split()))
sheet=[list(map(int,input().split()))+[0] for i in range(rc[0])]
sheet.append([0 for i in range(rc[1]+1)])
for s in sheet:
s[-1]=sum(s[0:-1])
for i in range(rc[1]+1):
r=sum([n[i] for n in sheet[0:-1]])
sheet[-1][i]=r
for sh in sheet:
print(*sh) | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
a, b = map(int, input().split())
if a >= b:
ans = str(b)*a
else:
ans = str(a)*b
print(int(ans)) | 0 | null | 42,783,875,323,268 | 59 | 232 |
a,b,m = input().split()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc =[]
for i in range(int(m)):
xyc.append(input())
min = min(a) + min(b)
for i in xyc:
x,y,c = map(int, i.split())
if min > a[x-1] + b[y-1] - c :
min = a[x-1] + b[y-1] - c
print(min)
| import sys
A, B, M = map(int, input().split())
a = list(map(int, sys.stdin.readline().rsplit()))
b = list(map(int, sys.stdin.readline().rsplit()))
res = min(a) + min(b)
for i in range(M):
x, y, c = map(int, input().split())
res = min(res, a[x - 1] + b[y - 1] - c)
print(res)
| 1 | 54,043,298,724,272 | null | 200 | 200 |
r = int(input())
print(round(r * r / 1)) | def main():
print(int(input())**2)
if __name__ == "__main__":
main() | 1 | 144,929,728,644,558 | null | 278 | 278 |
import sys
if __name__ == '__main__':
letter_counts = [0] * 26 # ?????¢????????????????????????????????° [0]???'a'???[25]???'z'??????????????°
for line in sys.stdin:
# ?°?????????¨??§??????????????\????????????
lower_text = line.lower()
# ??¢???????????????????????¨??????????????°???????¨?
for c in lower_text:
if 'a' <= c <= 'z':
letter_counts[ord(c)-ord('a')] += 1
# ????????? 'a : a????????°' ?????¢??§z?????§1????????¨?????????
for i, n in enumerate(letter_counts):
print('{0} : {1}'.format(chr(ord('a')+i), n)) | def f(i):
if i == 2:return 1
return pow(2, i-1, i) == 1
print(sum(1 for n in range(int(input())) if f(int(input())))) | 0 | null | 815,829,952,754 | 63 | 12 |
for i in range(1, 10):
a=i
b=1
while True:
print(a,"x",b,"=",a*b,sep="")
if b==9:
break
b+=1
| max = 10
for x in xrange(1, max):
for y in xrange(1, max):
print "%dx%d=%d" % (x, y, x * y) | 1 | 411,230 | null | 1 | 1 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[0] == 0:
print(0)
exit()
ans = 1
for i in range(0, N):
ans *= A[i]
if ans > 10 ** 18:
print(-1)
exit()
print(ans) | n , m = (int(a) for a in input().split())
if n == m :
print("Yes")
else : print("No") | 0 | null | 49,873,914,333,180 | 134 | 231 |
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]
bb = [0]
for i in range(n):
aa.append(aa[-1]+a[i])
for i in range(m):
bb.append(bb[-1]+b[i])
c = m
ans = 0
for i in range(n+1):
u = k - aa[i]
for j in range(c, -1, -1):
if bb[j] <= u:
ans = max(ans, i+j)
c = j
break
print(ans) | N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_sum = [0]
B_sum = [0]
A_now = 0
B_now = 0
for i in range(N):
A_now = A[i] + A_now
A_sum.append(A_now)
for i in range(M):
B_now = B[i] + B_now
B_sum.append(B_now)
ans = 0
for i in range(N+1):
book_count = i
remain_time = K - A_sum[i]
ok = 0
ng = M
if remain_time >= B_sum[M]:
ans = book_count + M
while ng - ok > 1:
mid = (ok+ng)//2
if remain_time >= B_sum[mid]:
ok = mid
else:
ng = mid
book_count += ok
if remain_time >= 0:
if book_count > ans:
ans = book_count
# print(mid,remain_time,B_sum[ok])
print(ans)
| 1 | 10,673,795,566,238 | null | 117 | 117 |
N = int(input())
slist = []
tlist = []
from itertools import accumulate
for _ in range(N):
s, t = input().split()
slist.append(s)
tlist.append(int(t))
cum = list(accumulate(tlist))
print(cum[-1]-cum[slist.index(input())])
| n = int(input())
s = []
t = []
for i in range(n):
a,b = input().split()
s.append(a)
t.append(int(b))
x = s.index(input())
ans = 0
for i in range(x+1,n):
ans += t[i]
print(ans) | 1 | 96,715,731,986,120 | null | 243 | 243 |
import math
from bisect import bisect_right # クエリより真に大きい値が初めて現れるインデックスを教えてくれる
# 初めて爆弾が届かない範囲を記録しながら前から順に倒していく
N, D, A = map(int, input().split()) # N体のモンスター, 爆弾の範囲D, 爆弾の威力A
XH = []
X = []
for _ in range(N):
x, h = map(int, input().split())
XH.append((x, math.ceil(h/A)))
X.append(x)
# 座標で昇順ソート
XH.sort()
X.sort()
# 前から倒していく
now = 0
ans = 0
T = [0]*(N+1) # 爆弾の範囲が切れる場所を記録しておく
for i in range(N):
x, h = XH[i] # 今見ているモンスターの座標, 体力
now -= T[i] # そのモンスターに届いていない爆弾があるなら引く
if now >= h: # 今残っている爆弾だけで倒せるならcontinue
continue
else:
ans += h - now # 足りない分(h-now個)の爆弾を使う
T[bisect_right(X, x+2*D)] += h - now # 爆弾の範囲が切れる場所を記録しておく
now = h # 今影響が残っている爆弾の威力
print(ans)
| N, D, A = map(int, input().split())
XH = sorted([tuple(map(int, input().split())) for _ in range(N)])
ans, r, S, R = 0, 0, [0] * (N + 2), []
for l in range(N):
while r + 1 < N and XH[r + 1][0] - XH[l][0] <= 2 * D:
r += 1
S[l + 1] += S[l]
bomb = (max(XH[l][1] - S[l + 1], 0) + A - 1) // A
ans += bomb
S[l + 1] += bomb * A
S[r + 1 + 1] -= bomb * A
R.append(r)
print(ans)
| 1 | 82,270,170,341,360 | null | 230 | 230 |
def main():
n,s = map(int,input().split())
a = list(map(int,input().split()))
mod = 998244353
dp = [[0]*(s+1) for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
for j in range(s+1):
if j >= a[i]:
dp[i+1][j] += (dp[i][j]*2+dp[i][j-a[i]])%mod
else:
dp[i+1][j] += (dp[i][j]*2)%mod
print(dp[-1][-1])
if __name__ =="__main__":
main()
| n = int(input())
t = 0
h = 0
for i in range(n):
tc, hc = input().split()
if tc > hc:
t += 3
elif tc < hc:
h += 3
elif tc == hc:
t += 1
h += 1
print(str(t)+' '+str(h)) | 0 | null | 9,812,948,959,080 | 138 | 67 |
import numpy as np
import numba
@numba.njit("(i8,i8,i8,i8[:,:])", cache=True)
def solve(R, C, K, RCV):
# dp[y][x][n]
M = np.zeros((R+1, C+1), dtype=np.int64)
for i in range(K):
r, c, v = RCV[i]
M[r, c] = v
dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
for y in range(1, R+1):
for x in range(1, C+1):
for n in range(4):
if n == 0:
dp[y, x, n] = max(
dp[y, x-1, 0],
dp[y-1, x, :].max()
)
if n > 0:
dp[y, x, n] = max(
dp[y, x-1, n],
dp[y, x-1, n-1] + M[y, x],
dp[y-1, x, :].max() + M[y, x]
)
ans = dp[R, C].max()
print(ans)
import sys
def main():
R, C, K = map(int, input().split())
RCV = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(K, 3)
solve(R, C, K, RCV)
main()
| n = int(input())
lis = list(map(int, input().split()))
m = 0
for a in lis:
m = m ^ a
for a in lis:
print(m ^ a, end=" ")
| 0 | null | 9,005,809,664,068 | 94 | 123 |
def mod(val, mod_base):
if val >= mod_base:
return val%mod_base
return val
# 配るDP
def resolve():
base = 998244353
N, K = map(int, input().split(" "))
LRs = []
for _ in range(K):
(L, R) = map(int, input().split(" "))
LRs.append((L, R))
dp = [0] * (N+1)
dp_sum = [0] * (N+1)
dp[1] = 1
dp_sum[1] = 1
for i in range(1, N):
dp_sum[i] = dp[i] + dp_sum[i-1]
for lr in LRs:
left = i + lr[0]
right = i + lr[1] + 1
if left <= N:
dp[left] += dp_sum[i]
dp[left] = mod(dp[left], base)
if right <= N:
dp[right] -= dp_sum[i]
dp[right] = mod(dp[right], base)
print(mod(dp[-1], base))
if __name__ == "__main__":
resolve() | a, b = map(int, input().split())
c = str(a)*b
d = str(b)*a
my_list = [c, d]
my_list.sort()
print(my_list[0]) | 0 | null | 43,437,355,080,250 | 74 | 232 |
from collections import defaultdict
n, m = map(int, input().split())
ac_dict = defaultdict(int)
wa_dict = defaultdict(int)
ac_p, wa_p = set(), set()
for _ in range(m):
p, s = input().split()
p = int(p)
if s == 'AC':
ac_p.add(p)
ac_dict[p] = 1
elif ac_dict[p] != 1:
wa_p.add(p)
wa_dict[p] += 1
wa = 0
for pi in ac_p:
wa += wa_dict[pi]
print(sum(ac_dict.values()), wa)
| r = float(input())
pi = 3.141592653589
s = pi * r**2
h = 2 * pi * r
print("{:.6f}".format(s), "{:.6f}".format(h))
| 0 | null | 46,752,488,001,460 | 240 | 46 |
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
for i in range(N-1):
if i == 0:
ans += A[i]
else:
ans += A[1+(i-1)//2]
print(ans) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
from math import ceil
H, W = mapint()
if H==1 or W==1:
print(1)
else:
print(ceil(H*W/2)) | 0 | null | 30,049,737,596,670 | 111 | 196 |
import math
def modpow(a,b,mod=10**9+7):
res=1
a%=mod
leng=int(math.log2(b))
for i in range(leng,-1,-1):
res=(res*res)%mod
if (b>>i)&1:
res=(res*a)%mod
return res
def fact(x):
ans=1
for i in range(2,x+1):
ans = (ans*i)%(10**9+7)
return ans
def comb(n,r):
return fact(n)*modpow(fact(r),10**9+5)*modpow(fact(n-r),10**9+5)%(10**9+7)
x,y=map(int,input().split(' '))
if (x+y)%3!=0 or 2*x-y<0 or 2*y-x<0:
print(0)
else:
x,y=max(x,y),min(x,y)
d=x-y
n=((x-2*d)//3)
m=n+d
print(comb(n+m,n)) | n = int(input())
r = []
for i in range(n):
r.append(int(input()))
min_v = r[0]
max_p = -1000000000
for i in range(1,n):
max_p = max(max_p,r[i]-min_v)
min_v = min(min_v,r[i])
print(max_p) | 0 | null | 75,313,687,856,640 | 281 | 13 |
print(*sorted([int(input()) for _ in [0]*10])[:6:-1], sep="\n") | S = str(input())
r = len(S)
print('x'*r) | 0 | null | 36,389,740,246,898 | 2 | 221 |
def main():
a,b = list(map(int, input().split()))
ans = a - 2*b
ans = 0 if ans < 0 else ans
print(ans)
if __name__ == '__main__':
main()
| あ,い=map(int,input().split())
print(max(0,あ-い*2)) | 1 | 166,678,151,115,840 | null | 291 | 291 |
import math
N = int(input())
N_ = int(math.sqrt(N)) + 1
min_distance = N - 1
for i in range(1, N_):
p, r = divmod(N, i)
if r == 0:
if 1 <= p <= N:
distance = (i-1) + (p-1)
min_distance = min(min_distance, distance)
else:
continue
print(min_distance)
| N = int(raw_input())
A = map(int, raw_input().split())
def bubbleSort(A, N):
count = 0
flag = 1
while flag:
flag = 0
for i in range(N-1, 0, -1):
if A[i] < A[i-1]:
temp = A[i]
A[i] = A[i-1]
A[i-1] = temp
flag = 1
count += 1
return count
count = bubbleSort(A, N)
print " ".join(map(str, A))
print count | 0 | null | 81,179,356,949,548 | 288 | 14 |
n = int(input())
if n % 2 == 0:
print(0.5)
else:
print((n+1)//2/n) | N=int(input())
#N=5
n=N//2
print(1-n/N) | 1 | 176,813,743,059,688 | null | 297 | 297 |
(a, b, c) = map(lambda s:int(s), input().split())
r = 0
for n in range(a, b+1):
if c % n == 0:
r += 1
print(r) | #template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
A.sort()
ans = 1
if A[0] == 0:
print(0)
exit()
for i in range(N):
ans *= A[i]
if ans > 10**18:
print(-1)
exit()
print(ans) | 0 | null | 8,399,217,789,410 | 44 | 134 |
n = int(input())
R = [int(input()) for i in range(n)]
profit= R[1] - R[0]
mn = R[0]
R.pop(0)
for i in R:
if profit < i - mn:
profit = i - mn
if 0 > i - mn:
mn = i
elif mn > i:
mn = i
print(profit) | from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)
def main():
a, b = map(int, input().split())
if a <= b:
print(str(a) * b)
else:
print(str(b) * a)
main() | 0 | null | 42,252,731,127,340 | 13 | 232 |
# -*- coding: utf-8 -*-
N = int(input().strip())
XL_list = [list(map(int, input().rstrip().split())) for i in range(N)]
#-----
section = []
for X,L in XL_list:
section.append( ( X - L , X + L ) )
section.sort(key= lambda x: x[1])
prev_tail = -float("inf")
cnt = 0
for left,right in section:
if prev_tail <= left:
cnt += 1
prev_tail = right
print(cnt)
| N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
A.sort()
B.sort()
if N % 2 == 0 :
print(B[N//2] + B[N//2-1] - A[N//2] - A[N//2-1] + 1)
else :
print(B[N//2] - A[N//2] + 1) | 0 | null | 53,760,880,507,040 | 237 | 137 |
A, B, K = list(map(int, input().split()))
if A <= K:
K = K - A
A = 0
if B <= K:
K = K - B
B = 0
else:
B = B - K
else:
A = A - K
print(str(A) + ' ' + str(B)) | #B
N=int(input())
C=[input() for i in range(N)]
AC=C.count('AC')
WA=C.count('WA')
TLE=C.count('TLE')
RE=C.count('RE')
print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(AC, WA, TLE, RE)) | 0 | null | 56,410,745,223,492 | 249 | 109 |
N, K, S = map(int, input().split())
a = [str(S)] * K
if S == 10**9:
b = [str(1)] * (N-K)
else:
b = [str(S+1)] * (N-K)
ans = a + b
print(*ans) | import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a2 = [0] * (n + 1)
b2 = [0] * (m + 1)
for i in range(0, n):
a2[i+1] = a[i] + a2[i]
for i in range(0, m):
b2[i+1] = b[i] + b2[i]
ans = 0
for i in range(n+1):
tmp = bisect.bisect_right(b2, k-a2[i]) - 1
if a2[i] + b2[tmp] <= k and tmp >= 0:
ans = max(ans, i+tmp)
print(ans) | 0 | null | 50,703,923,459,348 | 238 | 117 |
import sys
from collections import deque
def input():
return sys.stdin.readline()[:-1]
A = input()
total = 0
total_each = deque()
S1 = deque()
S2 = deque()
for j,a in enumerate(A):
#print('j = {}, S2 = {}'.format(j,S2))
if a == '\\':
S1.append(j)
elif a=='/':
try:
i = S1.pop()
val_new = j-i
total += val_new
if len(S2)==0:
S2.append((i,val_new))
continue
while True:
if len(S2)>0:
a,val = S2[-1]
if a<i:
S2.append((i, val_new))
break
elif i<a:
_ = S2.pop()
val_new = val + val_new
else:
S2.append((i,val_new))
break
except:
pass
print(total)
ans = [len(S2)]
for _ in range(len(S2)):
a,val = S2.popleft()
ans.append(val)
print(*ans)
| import math
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
n = int(input())
yaku = make_divisors(n)
Min = float('inf')
for i in range(math.ceil(len(yaku)/2)):
Min = min(Min, yaku[i]+yaku[-(i+1)])
print(Min-2) | 0 | null | 81,020,188,791,034 | 21 | 288 |
n, m, k = map(int, input().split())
#Union-Find
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
def unite(x, y):
p = find(x)
q = find(y)
if p == q:
return None
if p > q:
p,q = q,p
par[p] += par[q]
par[q] = p
def same(x, y):
return find(x) == find(y)
def size(x):
return -par[find(x)]
par = [-1 for i in range(n)]
l = [0] * n
for i in range(m):
a, b = map(int, input().split())
unite(a-1, b-1)
l[a-1] += 1
l[b-1] += 1
for i in range(k):
c, d = map(int, input().split())
if same(c-1, d-1):
l[c-1] += 1
l[d-1] += 1
for i in range(n):
print(size(i) - l[i] - 1, end=" ") | n = int(input())
result = ''
for x in range(3, n+1):
if x % 3 == 0 or '3' in str(x):
result += (' '+str(x))
print(result)
| 0 | null | 31,471,021,999,548 | 209 | 52 |
from decimal import Decimal
'''
def main():
a, b = input().split(" ")
a = int(a)
b = Decimal(b)
print(int(a*b))
'''
def main():
a, b = input().split(" ")
a = int(a)
b = int(b.replace(".","") )
print(a*b // 100)
if __name__ == "__main__":
main() | s = input()
ans = 0
for i in range(3):
if s[i] == "R":
ans = 1
for i in range(2):
if s[i:i+2] == "RR":
ans = 2
if s == "RRR":
ans = 3
print(ans)
| 0 | null | 10,739,220,108,362 | 135 | 90 |
input()
n = input()
count = 0
for i in range(2, len(n)):
# print(n[i-2] + n[i-1] + n[i])
if (n[i-2] + n[i-1] + n[i]) == 'ABC':
count += 1
print(count)
| x = int(input())
k = 1
while(True):
if k * x % 360 == 0:
print(k)
break
else:
k += 1 | 0 | null | 56,270,597,148,432 | 245 | 125 |
import sys
input = sys.stdin.readline
import numpy as np
from collections import defaultdict
N,K = map(int,input().split())
# 全要素を-1する
A = [0] + [int(i)-1 for i in input().split()]
# Acum[i]: A[1]からA[i]までの累積和
Acum = np.cumsum(A)
Acum = [i%K for i in Acum]
answer = 0
counter = defaultdict(int)
# iの範囲で探索
# 1 <= j <= N
# j-K+1 <= i <= j-1
for j,x in enumerate(Acum):
# (i-K+1)回目から(i-1)回目の探索において、xの出現回数
answer += counter[x]
# i回目の結果を辞書に追加
counter[x] += 1
# 辞書にK回追加した場合
if j-K+1 >= 0:
# 辞書から一番古い探索記録を削除
counter[Acum[j-K+1]] -= 1
print(answer) | from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = defaultdict(int)
sa = [0] * (n + 1)
d[0] = 1
if k == 1:
print(0)
exit()
for i in range(n):
sa[i + 1] = sa[i] + a[i]
sa[i + 1] %= k
ans = 0
for i in range(1, n + 1):
v = sa[i] - i
v %= k
ans += d[v]
d[v] += 1
if 0 <= i - k + 1:
vv = sa[i - k + 1] - (i - k + 1)
vv %= k
d[vv] -= 1
print(ans)
| 1 | 137,187,557,196,630 | null | 273 | 273 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter
import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(readline())
def read_int_n():
return list(map(int, readline().split()))
def read_float():
return float(readline())
def read_float_n():
return list(map(float, readline().split()))
def read_str():
return readline().strip()
def read_str_n():
return readline().strip().split()
def ep(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.perf_counter()
ret = f(*args, **kwargs)
e = time.perf_counter()
ep(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, U, V, AB):
g = defaultdict(list)
for a, b in AB:
g[a].append(b)
g[b].append(a)
def dfs(u):
s = [u]
d = {u: 0}
while s:
u = s.pop()
for v in g[u]:
if v in d:
continue
d[v] = d[u] + 1
s.append(v)
return d
du = dfs(U)
dv = dfs(V)
ans = 0
for v in sorted(du.keys()):
if du[v] < dv[v]:
ans = max(ans, dv[v] - 1)
return ans
def main():
N, U, V = read_int_n()
AB = [read_int_n() for _ in range(N-1)]
print(slv(N, U, V, AB))
if __name__ == '__main__':
main()
| N = int(input())
S = str(input())
s=list(S)
num=0
for i in range(N-2):
if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
num+=1
print(num) | 0 | null | 108,006,029,373,482 | 259 | 245 |
a,b,c = map(int,raw_input().split())
if a < b < c:
print("Yes")
else:
print('No') | def readinput():
n=int(input())
a=list(map(int,input().split()))
return n,a
def main(n,a):
aa=[]
for i in range(n):
aa.append((i+1,a[i]))
aa.sort(key=lambda x:x[1])
b=[]
for i in range(n):
b.append(aa[i][0])
return b
if __name__=='__main__':
n,a=readinput()
ans=main(n,a)
print(' '.join(map(str,ans)))
| 0 | null | 90,514,498,759,400 | 39 | 299 |
from collections import deque
# データの入力
N = int(input())
DG = {}
for i in range(N):
tmp = input().split()
if int(tmp[1]) != 0:
DG[i] = [int(x)-1 for x in tmp[2:]]
else:
DG[i] = []
result = {}
is_visited = {key: False for key in range(N)}
# bfs
# 初期queue
que = deque([(0, 0)]) # 必要なものはnodeidと原点からの距離
while que:
nodeid, cost = que.popleft() # 先入れ先出し
result[nodeid] = cost
is_visited[nodeid] = True # この文は最初の1for目しか意味ないんだけどなんかうまい方法ないのか
for nextnode in DG[nodeid]:
if is_visited[nextnode]:
pass
else: # 未訪問のものについては探索候補に入れる
que.append((nextnode, cost + 1))
is_visited[nextnode] = True # 探索候補に入れた瞬間に訪問管理しないと重複を生じる場合がある
for i in range(N):
if is_visited[i]:
print(i + 1, result[i])
else:
print(i+1, -1)
| k=int(input())
s=input()
if len(s) <= k:
print(s)
else:
print(s[:k]+'...') | 0 | null | 9,802,782,592,482 | 9 | 143 |
import sys
input = sys.stdin.readline
INF = float('inf')
def main():
S, T = map(str, input().split())
print(T + S)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
inf = 10**15
V = [[] for _ in range(N)]
for _ in range(M):
A, B, C = map(int, input().split())
if C>L:continue
V[A-1].append((B-1, C))
V[B-1].append((A-1, C))
dists = []
for i in range(N):
dist = [(inf,inf)] * N
dist[i] = (0, 0)
u = [False] * N
for _ in range(N):
(charged, used), j = min([(dist[i], i) for i in range(N) if not u[i]])
u[j] = True
for k, next_cost in V[j]:
if j==k: continue
c = (charged+1, next_cost) if used+next_cost>L else (charged, used+next_cost)
if dist[k] > c:
dist[k] = c
dists.append(dist)
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
ans = dists[s-1][t-1][0]
print(ans if ans!=inf else -1)
| 0 | null | 137,740,461,188,192 | 248 | 295 |
s = input()
if s == 'AAA':
print('No')
elif s == 'BBB':
print('No')
else:
print('Yes') | s=input()
if s!="AAA" and s!="BBB":
print("Yes")
else:
print("No")
| 1 | 55,084,493,077,182 | null | 201 | 201 |
import math
N = int(input())
ans = 0
if N == 0 or N % 2 == 1:
ans = 0
else:
# means N >= 2 and even
digN = round( math.log(N , 5) )
i = 1
while i <= digN:
ans += ( N //( 5 ** i * 2 ) )
i += 1
print(ans) | from sys import stdin
T1,T2 = [int(x) for x in stdin.readline().rstrip().split()]
A1,A2 = [int(x) for x in stdin.readline().rstrip().split()]
B1,B2 = [int(x) for x in stdin.readline().rstrip().split()]
f = (A1-B1)*T1
s = (A2-B2)*T2
if f + s == 0:
print("infinity")
else:
if (f > 0) and ((f + s) > 0):
print(0)
elif (f < 0) and ((f + s) < 0):
print(0)
elif f > 0 and f + s < 0:
if f % (-(f + s)) == 0:
print((f//-(f+s))*2)
else:
print((f//-(f+s))*2+1)
elif f < 0 and f + s > 0:
if (-f) % (f+s) == 0:
print((-f//(f+s))*2)
else:
print((-f//(f+s))*2+1) | 0 | null | 123,398,882,211,140 | 258 | 269 |
b, c = list(map(int, input().split()))
if 500 * b >= c :
print("Yes")
else:
print("No") | base = input().split()
if int(base[0])*500 >= int(base[1]):
print("Yes")
else:
print("No") | 1 | 98,063,893,118,938 | null | 244 | 244 |
N, K = map(int, input().split())
ppp = list(map(int, input().split()))
acc = 0
for i in range(K):
acc += (ppp[i] + 1) / 2
ans = acc
for i in range(K, N):
acc -= (ppp[i - K] + 1) / 2
acc += (ppp[i] + 1 ) / 2
ans = max(ans, acc)
print(ans)
| import sys
input = sys.stdin.readline
(n, k), s, res, sm = map(int, input().split()), list(map(lambda x: (int(x) + 1) / 2, input().split())), 0, 0
for i in range(n):
if i < k: sm += s[i]
else: sm += s[i]; sm -= s[i-k]
res = max(res, sm)
print(f'{res:.10f}')
# print(f'{max([sum(s[i:i+k]) for i in range(n - k + 1)]):.10f}') | 1 | 74,767,425,310,082 | null | 223 | 223 |
N = int(input())
c = input()
R_r = c.count("R")
W_l = 0
ans = N
for i in range(N+1):
t = max(R_r,W_l)
ans = min(ans, t)
if R_r == 0:
break
if c[i] == "R":
R_r -= 1
else:
W_l += 1
print(ans) | N = int(input())
C = input()
f = 0
b = N - 1
ans = 0
while True:
while f <= N -1 and C[f] == "R":
f += 1
while b >= 0 and C[b] == "W":
b -= 1
if f > b:
print(ans)
break
ans += 1
f += 1
b -= 1 | 1 | 6,369,971,133,370 | null | 98 | 98 |
import re
n = int(input())
s = input()
res = re.findall(r'ABC',s)
print(len(res)) | n = int(input())
boss = list(map(int, input().split()))
subordinate = {}
for b in boss:
subordinate[b] = subordinate.get(b, 0) + 1
for i in range(1, n+1):
print(subordinate.get(i, 0))
| 0 | null | 65,755,790,594,436 | 245 | 169 |
from collections import deque
N, M, K = map(int, input().split())
F = [[] for _ in range(N)]
B = [[] for _ in range(N)]
# フレンドの隣接リスト
for _ in range(M):
a, b = map(int, input().split())
a, b = a - 1, b - 1
F[a].append(b)
F[b].append(a)
# ブロックの隣接リスト
for _ in range(K):
c, d = map(int, input().split())
c, d = c - 1, d - 1
B[c].append(d)
B[d].append(c)
# 交友関係グループ(辞書型)
D = {}
# グループの親
parent = [-1] * N
# 訪問管理
visited = [False] * N
for root in range(N):
cnt = 0
if visited[root]:
continue
# D[root] = set([root])
# 訪問先のスタック
stack = [root]
# 訪問先が無くなるまで
while stack:
# 訪問者をポップアップ
n = stack.pop()
# 訪問者を訪問済み
if visited[n]:
continue
visited[n] = True
cnt +=1
# 訪問者のグループの親を設定
parent[n] = root
# root のフレンドをグループと訪問先に追加
for to in F[n]:
if visited[to]:
continue
# D[root].add(to)
stack.append(to)
if cnt!=0:
D[root]=cnt
# print(D)
ans = [0]*N
for iam in range(N):
# group = gro[parent[iam]]
tmp_ans = D[parent[iam]]
tmp_ans -=1
tmp_ans -= len(F[iam])
for block in B[iam]:
if parent[block]==parent[iam] :
tmp_ans -=1
ans[iam]=tmp_ans
print(*ans, sep=' ') | # AtCoder
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
CD = [list(map(int, input().split())) for _ in range(K)]
uf = UnionFind(N)
friend = [0]*N
blocked = [0]*N
for a, b in AB:
uf.union(a-1, b-1)
friend[a-1] += 1
friend[b-1] += 1
for c, d in CD:
if uf.same(d-1, c-1):
blocked[c-1] += 1
blocked[d-1] += 1
ans = [uf.size(i)-friend[i]-blocked[i]-1 for i in range(N)]
print(' '.join(map(str, ans)))
| 1 | 61,856,392,282,520 | null | 209 | 209 |
#abc149-d
n,k=map(int,input().split())
s,p,r=map(int,input().split())
f={'s':s,'p':p,'r':r}
t=str(input())
ans=0
for i in range(k):
a=i+k
last=t[i]
ans+=f[last]
while a<n-k:
if t[a]==last:
if t[a+k]==last:
if last=='s':
last='r'
else:
last='s'
else:
if last=='s':
if t[a+k]=='r':
last='p'
else:
last='r'
elif last=='r':
if t[a+k]=='s':
last='p'
else:
last='s'
else:
if t[a+k]=='r':
last='s'
else:
last='r'
else:
last=t[a]
ans+=f[last]
a+=k
if a<n:
if t[a]!=last:
ans+=f[t[a]]
print(ans) | inp = [i for i in input().split()]
n = int(input())
array = [[i for i in input().split()] for i in range(n)]
for i2 in range(n):
fuck =""
for i in range(1,33):
if (i<=20 and i%5==0) or i==22 or i==27 or i==28:
s = "N"
else:
s = "E"
if s == "E":
a = []
a.append(inp[3])
a.append(inp[1])
a.append(inp[0])
a.append(inp[5])
a.append(inp[4])
a.append(inp[2])
inp = a
if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck:
print(inp[2])
fuck = inp[2]
elif s == "N":
a = []
a.append(inp[1])
a.append(inp[5])
a.append(inp[2])
a.append(inp[3])
a.append(inp[0])
a.append(inp[4])
inp = a
if inp[0] == array[i2][0] and inp[1] == array[i2][1] and inp[2] != fuck:
print(inp[2])
fuck = inp[2] | 0 | null | 53,697,866,514,610 | 251 | 34 |
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) | n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
ans = 12*(10**5)+1
for i in range(2**n):
a = [0] * m
cs = 0
for j in range(n):
if (i >> j) & 1:
cs += ca[j][0]
for k in range(1, m+1):
a[k-1] += ca[j][k]
flag = True
for j in range(m):
if a[j] < x:
flag = False
break
if flag:
ans = min(ans, cs)
if ans == 12*(10**5)+1:
ans = -1
print(ans) | 0 | null | 11,033,881,311,740 | 12 | 149 |
N,X,Y=map(int,input().split())
dp=[[0]*N for i in range(N)]
dist=[0]*N
X-=1
Y-=1
for i in range(N):
for j in range(N):
if not i<j:continue
dp[i][j]=min(j-i,abs(j-Y)+1+abs(X-i))
dist[dp[i][j]]+=1
for i in dist[1:]:
print(i) | word = input()
if word[-1] == 's':
word += 'es'
else:
word += 's'
print(word) | 0 | null | 23,177,317,965,952 | 187 | 71 |
#coding: UTF-8
def isPrime(n):
if n == 1:
return False
import math
m = math.floor(math.sqrt(n))
for i in range(2,m+1):
if n % i == 0:
return False
return True
n = int(input())
count = 0
for j in range(n):
m = int(input())
if isPrime(m):
count += 1
print(count)
| n,k,s=map(int,input().split())
ans=[s]*k
if n-k>0:
ans1=[]
if s==10**9:
ans1=[1]*(n-k)
else:
ans1=[s+1]*(n-k)
ans[len(ans):len(ans)]=ans1
print(' '.join(map(str,ans))) | 0 | null | 45,511,656,681,520 | 12 | 238 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
def meguru_bisect(left, right):
"""
is_okを定義して下さい
:param left: 取りうる最小の値-1
:param right: 取りうる最大の値+1
:return: is_okを満たす最小(もしくは最大)の値
"""
while abs(left - right) > 1:
mid = (left + right) // 2
if is_ok(mid):
right = mid
else:
left = mid
return right
def is_ok(x):
total = 0
for i in range(n):
total += max(0, A[i] - x // F[i])
return total <= k
n, k = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)
left = -1
right = 10 ** 12 + 1
res = meguru_bisect(left, right)
print(res)
if __name__ == '__main__':
resolve()
| N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
max_a = max(A)
max_f = max(F)
left = 0
right = max_a * max_f
while left <= right:
x = (left + right) // 2
sum_ = 0
for i in range(N):
if A[i] * F[i] > x:
sum_ += (A[i] - int(x / F[i]))
if sum_ > K:
left = x + 1
if sum_ <= K:
right = x - 1
print(left)
| 1 | 165,228,539,148,410 | null | 290 | 290 |
n = int(input())
a =[' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0']
A_1 = a.copy()
A_2 = a.copy()
A_3 = a.copy()
B_1 = a.copy()
B_2 = a.copy()
B_3 = a.copy()
C_1 = a.copy()
C_2 = a.copy()
C_3 = a.copy()
D_1 = a.copy()
D_2 = a.copy()
D_3 = a.copy()
ren1 = [A_1,A_2,A_3]
ren2 = [B_1,B_2,B_3]
ren3 = [C_1,C_2,C_3]
ren4 = [D_1,D_2,D_3]
for i in range(n):
b = input()
c = b.split(' ')
ren = int(c[0])
kai = int(c[1])
banme = int(c[2])
nin = int(c[3])
if nin < 0:
if ren == 1:
ren1[kai-1][banme-1] = ' %s'%(int(ren1[kai-1][banme-1])+nin)
elif ren == 2:
ren2[kai-1][banme-1] = ' %s'%(int(ren2[kai-1][banme-1])+nin)
elif ren == 3:
ren3[kai-1][banme-1] = ' %s'%(int(ren3[kai-1][banme-1])+nin)
elif ren == 4:
ren4[kai-1][banme-1] = ' %s'%(int(ren4[kai-1][banme-1])+nin)
elif ren == 1:
ren1[kai-1][banme-1] = ' %s'%(int(ren1[kai-1][banme-1])+nin)
elif ren == 2:
ren2[kai-1][banme-1] = ' %s'%(int(ren2[kai-1][banme-1])+nin)
elif ren == 3:
ren3[kai-1][banme-1] = ' %s'%(int(ren3[kai-1][banme-1])+nin)
elif ren == 4:
ren4[kai-1][banme-1] = ' %s'%(int(ren4[kai-1][banme-1])+nin)
print(''.join(A_1))
print(''.join(A_2))
print(''.join(A_3))
print('####################')
print(''.join(B_1))
print(''.join(B_2))
print(''.join(B_3))
print('####################')
print(''.join(C_1))
print(''.join(C_2))
print(''.join(C_3))
print('####################')
print(''.join(D_1))
print(''.join(D_2))
print(''.join(D_3)) | from __future__ import print_function
import sys
officalhouse = [0]*4*3*10
n = int( sys.stdin.readline() )
for i in range( n ):
b, f, r, v = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
bfr = (b-1)*30+(f-1)*10+(r-1)
officalhouse[bfr] = officalhouse[bfr] + v;
output = []
for b in range( 4 ):
for f in range( 3 ):
for r in range( 10 ):
output.append( " {:d}".format( officalhouse[ b*30 + f*10 + r ] ) )
output.append( "\n" )
if b < 3:
output.append( "####################\n" )
print( "".join( output ), end="" ) | 1 | 1,097,502,013,758 | null | 55 | 55 |
#もらうDP + 累積和
n, k = map(int, input().split())
mod = 998244353
li = []
for _ in range(k):
l, r = map(int, input().split())
li.append((l, r))
li.sort()
dp = [0]*(2*n+1)
s = [0] * (2*n+1)
dp[1] = 1
s[1] = 1
for i in range(2, n+1):
for t in li:
l, r = t
dp[i] += s[max(i-l, 0)]
dp[i] -= s[max(i-r-1, 0)]
dp[i] %= mod
s[i] = s[i-1] + dp[i]
s[i] %= mod
print(dp[i]%mod) | # -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353
class BIT2:
def __init__(self, N):
self.N = (N+1)
self.data0 = [0] * (N+1)
self.data1 = [0] * (N+1)
def _add(self, data, k, x):
while k < self.N: #k <= Nと同義
data[k] += x
k += k & -k
def _sum(self, data, k):
s = 0
while k:
s += data[k]
k -= k & -k
return s
def add(self, l, r, x):
self._add(self.data0, l, -x*(l-1))
self._add(self.data0, r, x*(r-1))
self._add(self.data1, l, x)
self._add(self.data1, r, -x)
def sum(self, l, r):
return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1)
N, K = map(int, readline().split())
bit = BIT2(N)
d = []
for _ in range(K):
L,R = map(int, readline().split())
d.append((L,R))
bit.add(1,2,1)
for i in range(2,N+1):
for k in range(K):
L,R = d[k]
tmp = bit.sum(max(1,i-R),max(1,i-L+1))%MOD
bit.add(i,i+1,tmp)
print(bit.sum(N,N+1)%MOD) | 1 | 2,714,304,971,532 | null | 74 | 74 |
#!/usr/bin/env python3
import sys
import math
def solve(H: int, W: int):
if W == 1 or H == 1:
# coner case
print(1)
else:
print(math.ceil(W * H / 2))
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
H = int(next(tokens)) # type: int
W = int(next(tokens)) # type: int
solve(H, W)
if __name__ == "__main__":
main()
| import math
h, w = map(int, input().split())
print(math.ceil((h * w) / 2) if h != 1 and w != 1 else 1) | 1 | 50,793,568,554,852 | null | 196 | 196 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.