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
|
---|---|---|---|---|---|---|
#!/usr/bin/python3
# main
n = int(input()) - 1
fib = [1, 2]
for i in range(2, n + 1):
fib.append(fib[i - 1] + fib[i - 2])
print(fib[n]) | def fibonacci(n, memo=None):
if memo==None:
memo = [None]*n
if n<=1:
return 1
else:
if memo[n-2]==None:
memo[n-2] = fibonacci(n-2, memo)
if memo[n-1]==None:
memo[n-1] = fibonacci(n-1, memo)
return memo[n-1] + memo[n-2]
n = int(input())
print(fibonacci(n)) | 1 | 1,792,031,292 | null | 7 | 7 |
n,x,y=map(int,input().split())
#最短距離が1の時2の時、、、という風に実験しても途方に暮れるだけだった
#i,j固定して最短距離がどう表せるかを考える
def min_route_count(i,j):
return min(abs(j-i),abs(j-y)+1+abs(x-i))
ans_list=[0]*(n-1)
for i in range(1,n):
for j in range(i+1,n+1):
ans_list[min_route_count(i,j)-1]+=1
for t in range(n-1):
print(ans_list[t])
| import math
num = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))
diff = [0]*num
for a in range(num):
diff[a] = abs(x[a] - y[a])
print(sum(diff)) #1
po = [0]*num
for b in range(num):
po[b] = diff[b] * diff[b]
print(math.sqrt(sum(po))) #2
for c in range(num):
po[c] = diff[c] * diff[c] * diff[c]
print((sum(po))**(1/3)) #3
_max = 0
for d in diff:
if _max < d:
_max = d
print(_max)#infinity
| 0 | null | 22,330,436,530,438 | 187 | 32 |
import math
def factrization_prime(number):
factor = {}
div = 2
s = math.sqrt(number)
while div < s:
div_cnt = 0
while number % div == 0:
div_cnt += 1
number //= div
if div_cnt != 0:
factor[div] = div_cnt
div += 1
if number > 1:
factor[number] = 1
return factor
N = int(input())
v = list(factrization_prime(N).values())
ans = 0
for i in range(len(v)):
k = 1
while(True):
if v[i] >= k:
v[i] -= k
k += 1
ans += 1
else:
break
print(ans)
| def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
k += 1
return str(ans + (n >= rn))
if __name__ == '__main__':
import sys
print(solve(sys.stdin.read().strip()))
| 1 | 16,910,776,441,480 | null | 136 | 136 |
n = int(input())
alist = list(map(int,input().split()))
numb = [0]*n
for i in range(n):
numb[alist[i]-1] = i+1
for i in range(n):
print(numb[i],end=(' ')) | x1, y1, x2, y2 = map(float, input().split())
X = (x2 - x1)**2
Y = (y2 - y1)**2
distance = (X + Y)**(1/2)
print("%.8f" % (float(distance))) | 0 | null | 90,441,032,014,868 | 299 | 29 |
i=1
for i in range(9):
i+=1
print(f'1x{i}={1*i}')
for i in range(9):
i+=1
print(f'2x{i}={2*i}')
for i in range(9):
i+=1
print(f'3x{i}={3*i}')
for i in range(9):
i+=1
print(f'4x{i}={4*i}')
for i in range(9):
i+=1
print(f'5x{i}={5*i}')
for i in range(9):
i+=1
print(f'6x{i}={6*i}')
for i in range(9):
i+=1
print(f'7x{i}={7*i}')
for i in range(9):
i+=1
print(f'8x{i}={8*i}')
for i in range(9):
i+=1
print(f'9x{i}={9*i}')
| for i in range(9):
i=i+1
for j in range(9):
j=j+1
print(str(i)+'x'+str(j)+'='+str(i*j)) | 1 | 2,703,360 | null | 1 | 1 |
x = int(input())
yen_500 = 0
yen_5 = 0
amari = 0
happy = 0
if x>= 500:
yen_500 = x//500
amari = x - 500 * yen_500
yen_5 = amari//5
happy = 1000 * yen_500 + 5 * yen_5
print(happy)
else:
yen_5 = x//5
happy = 5 * yen_5
print(happy)
| n = int(input())
result = ""
for i in (range(1,n+1)):
if i % 3 == 0:
result += " " + str(i)
continue
j = i
while j > 0:
if j % 10 == 3:
result += " " + str(i)
break
else:
j //= 10
print (result)
| 0 | null | 21,780,856,824,938 | 185 | 52 |
n=int(input())
a=[]
b=[]
for i in range(n):
x,y=map(int,input().split())
a+=[x]
b+=[y]
a.sort()
b.sort()
if n%2==1:
print(b[n//2]-a[n//2]+1)
else:
print((b[n//2]+b[n//2-1])-(a[n//2]+a[n//2-1])+1) | import sys
readline = sys.stdin.readline
N = int(readline())
A = []
B = []
for _ in range(N):
a, b = map(int, readline().split())
A.append(a)
B.append(b)
A.sort()
B.sort()
if N % 2 == 0:
mi = A[N//2-1]+A[N//2]
ma = B[N//2-1]+B[N//2]
else:
mi = A[N//2]
ma = B[N//2]
print(ma-mi+1)
| 1 | 17,337,791,445,480 | null | 137 | 137 |
n, m = input().split()
s1 = n*int(m)
s2 = m*int(n)
print(min(s1, s2)) | f=[1,1]
for _ in range(2,45):f+=[sum(f[-2:])]
print(f[int(input())])
| 0 | null | 42,338,133,531,360 | 232 | 7 |
X, Y, Z = [int(x) for x in input().split()]
print('{} {} {}'.format(Z, X, Y))
| s = list(input())
num = 0
n = len(s)
l = 0
i = 0
while i < n:
if s[i] == '<':
l+=num
num+=1
i+=1
if i==n:
l+=num
else:
cur = 0
while i < n and s[i]=='>':
i+=1
cur+=1
if cur <= num:
l+=num
cur-=1
l+=(cur*(cur+1))//2
num = 0
print(l) | 0 | null | 96,972,602,795,662 | 178 | 285 |
def main():
n,k= list(map(int,input().split()))
h= list(map(int,input().split()))
ans=0
for i in range(0,n):
if h[i]>=k:
ans+=1
print(ans)
main() | # A - Duplex Printing
from math import ceil
print(ceil(int(input()) / 2))
| 0 | null | 118,945,129,194,840 | 298 | 206 |
def resolve():
N, K = map(int, input().split())
H = list(map(int, input().split()))
h = sorted(H)[::-1]
ans = h[K:]
print(sum(ans))
resolve() | N,K = map(int,input().split())
H = list(map(int,input().split()))
H.sort()
reversed(H)
for i in range(K):
if len(H)==0:
break
else:
H.pop()
if len(H)==0:
print(0)
else:
print(sum(H)) | 1 | 79,429,321,328,252 | null | 227 | 227 |
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
cnt = 0
for i in range(n):
if i - a[i] >= 0:
cnt += b[i - a[i]]
if i + a[i] < n:
b[i + a[i]] += 1
print(cnt) | D=int(input())
c=list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t= [int(input()) for i in range(D)]
v=0
LD=[0]*26
for i in range(D):
v+=s[i][t[i]-1]
LD[t[i]-1]=i+1
for j in range(26):
v-=c[j]*(i+1-LD[j])
print(v) | 0 | null | 17,974,324,546,688 | 157 | 114 |
import sys
s = input()
k = int(input())
n = len(s)
all_same = True
for i in range(n-1):
if s[i] != s[i+1]:
all_same = False
if all_same:
print((n*k)//2)
sys.exit()
head_same = 1
for i in range(n-1):
if s[i] == s[i+1]:
head_same += 1
else:
break
tail_same = 1
for i in range(n-1,0,-1):
if s[i] == s[i-1]:
tail_same += 1
else:
break
head_tail_same = 0
if s[0] == s[-1]:
head_tail_same = head_same + tail_same
def return_internal_same(ls):
i = 0
same_count = 1
return_value = 0
while i < len(ls)-1:
if ls[i] != ls[i+1]:
i += 1
return_value += same_count // 2
same_count = 1
continue
else:
same_count += 1
i += 1
return_value += same_count // 2
return return_value
# head_tial_sameがあるかどうかで場合わけ
if head_tail_same > 0:
ans = head_same//2 + tail_same//2
ans += (k-1) * (head_tail_same//2)
ans += k*(return_internal_same(s[head_same:n-tail_same]))
else:
ans = k*(head_same//2 + tail_same//2)
ans += (k-1) * (head_tail_same//2)
ans += k*(return_internal_same(s[head_same:n-tail_same]))
print(ans) | s = input()
n = int(input())
def f(s):
prev = ''
ct = 0
for i in s:
if i == prev:
ct += 1
prev = ''
else:
prev = i
return ct
if len(set(s)) == 1:
print(len(s) *n//2)
elif s[0]!=s[-1]:
print(f(s) * n)
else:
ans = f(s) + (f(s*2) - f(s)) * (n-1)
print(ans)
| 1 | 174,666,735,501,510 | null | 296 | 296 |
n=int(input())
a=list(map(int,input().split()))
bit_l=[0 for _ in range(60)]
for x in a:
for i in range(60):
if ((x>>i)&1):
bit_l[i]+=1
ans=0
mod=10**9+7
for y in range(len(bit_l)):
r=2**y
k=(n-bit_l[y])*bit_l[y]
ans+=r*k%mod
print(ans%mod) | import sys
from collections import defaultdict, deque, Counter
import math
# import copy
from bisect import bisect_left, bisect_right
import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
def nck(n, k, kaijyo):
return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD
def npk(n, k, kaijyo):
if k == 0 or k == n:
return n % MOD
return (kaijyo[n] * divide(kaijyo[n-k])) % MOD
def kaijyo(n):
ret = [1]
for i in range(1, n + 1):
ret.append((ret[-1] * i)% MOD)
return ret
def solve():
n = getN()
nums = getList()
keta = [[0, 0] for i in range(62)]
for num in nums:
tmp = num
for i in range(62):
if tmp % 2 == 1:
keta[i][1] += 1
else:
keta[i][0] += 1
tmp //= 2
ans = 0
dig = 0
for k1, k2 in keta:
ans += ((k1 * k2) * (2**dig)) % MOD
dig += 1
print(ans % MOD)
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve() | 1 | 123,367,644,984,612 | null | 263 | 263 |
def main():
n = int(input())
print(b(n))
def b(n: int) -> int:
m = 100
i = 0
while m < n:
m = m * 101 // 100
i += 1
return i
if __name__ == '__main__':
main()
| from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
for i in range(N):
S[i + 1] = (S[i] + A[i]) % K
# S[i + 1] = S[i] + A[i]
cnt = 0
C = Counter()
for r in range(N + 1):
R = (S[r] - r) % K
cnt += C[R]
C[R] += 1
l = r - (K - 1)
if l >= 0:
L = (S[l] - l) % K
C[L] -= 1
print(cnt)
| 0 | null | 81,935,393,288,810 | 159 | 273 |
import math
import itertools
n = int(input())
al = [0] * n
bl = [0] * n
for i in range(n):
al[i], bl[i] = map(int, input().split())
bunbo = math.factorial(n)
ans = 0
for p in itertools.permutations(list(range(n))):
for i in range(n-1):
ans += ((al[p[i+1]]-al[p[i]])**2+(bl[p[i+1]]-bl[p[i]])**2)**0.5
print(ans/bunbo)
| #!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def calc(p, P):
ans = 0
for i in range(1, len(p)):
x1, y1 = P[p[i - 1]]
x2, y2 = P[p[i]]
ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
return ans
def solve():
N = int(input())
P = []
for _ in range(N):
X, Y = map(int, input().split())
P.append((X, Y))
ans = 0
num = 0
for p in permutations(range(N)):
ans += calc(p, P)
num += 1
print(ans / num)
def main():
solve()
if __name__ == '__main__':
main()
| 1 | 148,054,363,322,360 | null | 280 | 280 |
from collections import deque
def bfs(start, g, visited):
q = deque([start])
visited[start] = 0
while q:
curr_node = q.popleft()
for next_node in g[curr_node]:
if visited[next_node] >= 0: continue
visited[next_node] = visited[curr_node] + 1
q.append(next_node)
def main():
n,u,v = map(int, input().split())
gl = [ [] for _ in range(n+1)]
visited_u = [-1] * (n+1)
visited_v = [-1] * (n+1)
for i in range(n-1):
a, b = map(int, input().split())
gl[a].append(b)
gl[b].append(a)
bfs(u, gl, visited_u)
bfs(v, gl, visited_v)
# print(visited_u)
# print(visited_v)
# target_i = 0
# max_diff_v = 0
ans = 0
for i in range(1,n+1):
if visited_u[i] < visited_v[i] and visited_v[i]:
# if (visited_v[i]-visited_u[i])%2 == 0:
val = visited_v[i]-1
ans = max(ans,val)
# else:
# val = visited_v[i]
# ans = max(ans,val)
print(ans)
if __name__ == "__main__":
main() | import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())
def bfs(N, v0, edge):
search = [-1] * N
search[v0] = 0
q = deque()
q.append(v0)
while q:
v = q.popleft()
for nv in edge[v]:
if search[nv] == -1:
q.append(nv)
search[nv] = search[v] + 1
return search
def bfs2(N, v0, edge, dis):
q = deque()
q.append(v0)
max_dis = dis[v0]
while q:
v = q.popleft()
for nv in edge[v]:
if dis[v] < dis[nv]:
q.append(nv)
max_dis = max(max_dis, dis[nv])
return max_dis
def main():
N, taka, aoki = in_nn()
taka, aoki = taka - 1, aoki - 1
edge = [[] for _ in range(N)]
for i in range(N - 1):
x, y = in_nn()
x, y = x - 1, y - 1
edge[x].append(y)
edge[y].append(x)
dis = bfs(N, aoki, edge)
if dis[taka] > 2:
x = (dis[taka] + 1) // 2 - 1
for _ in range(x):
for v in edge[taka]:
if dis[v] < dis[taka]:
taka = v
break
ans = bfs2(N, taka, edge, dis) - 1
print(ans)
if __name__ == '__main__':
main()
| 1 | 117,564,625,898,708 | null | 259 | 259 |
from collections import Counter
N=int(input())
if N==1:
print(0)
exit()
def factorize(n):
out=[]
i = 2
while 1:
if n%i==0:
out.append(i)
n //= i
else:
i += 1
if n == 1:break
if i > int(n**.5+3):
out.append(n)
break
return out
c = Counter(factorize(N))
def n_unique(n):
out = 0
while 1:
if out*(out+1)//2 > n:
return out-1
out += 1
ans = 0
for k in c.keys():
ans += n_unique(c[k])
print(ans) | def rren(): return list(map(int, input().split()))
N = int(input())
R = rren()
print(" ".join(map(str, R)))
for i in range(1,N):
take = R[i]
j = i-1
while j >= 0 and R[j] > take:
R[j+1] = R[j]
j -= 1
R[j+1] = take
print(" ".join(map(str, R))) | 0 | null | 8,420,653,874,320 | 136 | 10 |
A, B, C, K = map(int, input().split())
ans = 0
if A > K:
ans += 1*K
else:
ans += 1*A
K = K - A
if B > K:
ans += 0*K
else:
ans += 0*B
K = K - B
if C > K:
ans += -1*K
else:
ans += -1*C
print(ans)
| import sys
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if (a1-b1)*t1+(a2-b2)*t2 == 0:
print("infinity")
sys.exit()
e1 = (a1-b1)*t1
e2 = e1 + (a2-b2)*t2
if e1*e2 > 0:
print(0)
sys.exit()
e1, e2 = abs(e1), abs(e2)
if e1%e2:
print(1+2*(e1//e2))
else:
print(2*(e1//e2)) | 0 | null | 76,845,086,326,880 | 148 | 269 |
N, K =map(int,input().split())
p = list(map(int,input().split()))
for i in range(N):
for n in range(N-1):
if p[n]>p[n+1]:
tmp = p[n]
p[n] = p[n+1]
p[n+1] = tmp
ans =0
for i in range(K):
ans += p[i]
print(ans) | inputNum = []
for i in range(0, 10):
inputNum.append(int(raw_input()))
inputNum.sort(reverse=True)
for i in range(0, 3):
print inputNum[i] | 0 | null | 5,823,268,717,884 | 120 | 2 |
n = int(input())
s = list(input())
ans = ''
for i in s:
ascii_code = (ord(i) + n)
if ascii_code >= 91:
ascii_code -= 26
ans += chr(ascii_code)
print(ans)
| #!/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(N: int, S: str):
return "".join(chr((ord(c) - ord('A') + N) % 26 + ord('A')) for c in S)
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
print(f'{solve(N, S)}')
if __name__ == '__main__':
main()
| 1 | 134,470,883,413,468 | null | 271 | 271 |
n = int(input())
S = list(map(int, input().split()))
count = 0
def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L = A[left: left + n1]
R = A[mid: mid + n2]
L.append(float('inf'))
R.append(float('inf'))
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
count += 1
def merge_sort(A, left, right):
if (left + 1) < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(S, 0, n)
print(*S)
print(count)
| import itertools
import math
n = int(input())
points = [list(map(int, input().split())) for _ in range(n)]
numbers = list(range(1, n + 1))
diff = 0
count = 0
for pattern in itertools.permutations(numbers):
count += 1
for j in range(n - 1):
points_index = pattern[j] - 1
next_index = pattern[j + 1] - 1
diff += math.sqrt((points[points_index][0] - points[next_index][0]) ** 2 + (points[points_index][1] - points[next_index][1]) ** 2)
print(diff / count)
| 0 | null | 74,233,002,527,360 | 26 | 280 |
N = int(input())
xyp = []
xym = []
for _ in range(N):
x, y = map(int, input().split())
xyp.append(x+y)
xym.append(x-y)
xyp.sort()
xym.sort()
print(max(xyp[-1] - xyp[0], xym[-1] - xym[0])) | N=input()
i=len(N)
print('x'*i)
| 0 | null | 38,289,359,163,048 | 80 | 221 |
# -*- coding: utf-8 -*-
import sys
from collections import deque
N,D,A=map(int, sys.stdin.readline().split())
XH=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
XH.sort()
q=deque() #(攻撃が無効となる座標、攻撃によるポイント)
ans=0
cnt=0
attack_point=0
for x,h in XH:
while q:
if x<q[0][0]:break #無効となる攻撃がない場合はwhileを終了
end_x,end_point=q.popleft()
attack_point-=end_point #攻撃が無効となる座標<=現在の座標があれば、その攻撃のポイントを引く
if h<=attack_point: #モンスターの体力よりも攻撃で減らせるポイントの方が大きければ新規攻撃は不要
pass
else: #新規攻撃が必要な場合
if h%A==0:
cnt=(h-attack_point)/A #モンスターの大量をゼロ以下にするために何回攻撃が必要か
else:
cnt=(h-attack_point)/A+1
attack_point+=cnt*A
q.append((x+2*D+1,cnt*A)) #(攻撃が無効となる座標、攻撃によるポイント)をキューに入れる
ans+=cnt
print ans | def main():
import sys
from collections import deque
from operator import itemgetter
b = sys.stdin.buffer
N,D,A = map(int, b.readline().split())
m = map(int, b.read().split())
ans = 0
Q = deque()
d = 0
for x,h in sorted(zip(m,m), key=itemgetter(0)):
while Q and Q[0][0] < x:
_,d_ = Q.popleft()
d += d_
h = h+d
if h <= 0: continue
n = -(-h // A)
d -= n * A
ans += n
Q.append((x+2*D,n * A))
print(ans)
main() | 1 | 82,284,662,332,192 | null | 230 | 230 |
#!/usr/bin/env python3
print(6-eval(input()+"+"+input()))
| def main():
A = int(input())
B = int(input())
ans = 6 - A - B
print(ans)
if __name__ == "__main__":
main()
| 1 | 111,066,345,881,920 | null | 254 | 254 |
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def resolve():
N, K, C = lr()
S = [i+1 for i, s in enumerate(sr()) if s == 'o']
l = [S[0]]
for i in S[1:]:
if l[-1]+C >= i or len(l) > K:
continue
l.append(i)
S = S[::-1]
r = [S[0]]
for i in S[1:]:
if r[-1]-C <= i or len(r) > K:
continue
r.append(i)
r = r[::-1]
for i in range(K):
if l[i] == r[i]:
print(l[i])
resolve() | import sys
input = sys.stdin.readline
def main():
a, b, k = map(int, input().split())
if a >= k:
print(a-k, b)
return
if a+b >= k:
k -= a
print(0, b-k)
return
if a+b < k:
print(0, 0)
return
if __name__ == "__main__":
main()
| 0 | null | 72,244,727,502,530 | 182 | 249 |
n=int(input());print(str(n//3600)+":"+str((n//60)%60)+":"+str(n%60))
| s,t = input().split()
a,b = map(int, input().split())
u = input()
if s==u: print(a-1,b)
elif t==u: print(a,b-1)
else: print(a,b) | 0 | null | 35,949,772,524,100 | 37 | 220 |
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0]*s for _ in range(n)]
tmp=1
for i in range(n):
if a[i]<=s:
dp[i][a[i]-1]=tmp
for j in range(s):
if i>0:
dp[i][j]+=dp[i-1][j]*2
dp[i][j]%=mod
if j+a[i]<s:
dp[i][j+a[i]]+=dp[i-1][j]
dp[i][j+a[i]]%=mod
tmp*=2
tmp%=mod
print(dp[n-1][s-1]) | def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
n,s=sep()
ar=lis()
ar.insert(0,0)
dp=[[0]*(s+2) for _ in range(n+2)]
dp[0][0]=1
N=998244353
for i in range(1,n+1):
for j in range(0,s+1):
dp[i][j]=(2*dp[i-1][j])%N
if j-ar[i]>=0:
dp[i][j]=(dp[i][j]+dp[i-1][j-ar[i]])%N
#print(dp)
print(dp[n][s])
| 1 | 17,549,925,814,240 | null | 138 | 138 |
count=0
def mg(S,left,right,mid):
global count
L=[]
L=S[left:mid]
L.append(9999999999)
R=[]
R=S[mid:right]
R.append(9999999999)
r=0
l=0
for i in range(left,right):
count=count+1
if L[l]<=R[r]:
S[i]=L[l]
l=l+1
else:
S[i]=R[r]
r=r+1
def ms(S,left,right):
if right>left+1:
mid=(right+left)//2
ms(S,left,mid)
ms(S,mid,right)
mg(S,left,right,mid)
n=int(input())
S=[]
S=input().split()
S=[int(u) for u in S]
ms(S,0,n)
for i in range(0,n-1):
print(S[i],end=" ")
print(S[n-1])
print(count)
|
def merge(A, n, left, mid, right):
L = A[left:mid]
R = A[mid:right]
L.append(2000000000) # これをしないとマージするとき、最後の1回でリスト外アクセスでエラー。
R.append(2000000000)
global count
i, j = 0, 0
# print('left, mid, right')
# print(left, mid, right)
for k in range(left, right, 1):
count += 1
# print('i, j, k')
# print(i, j, k)
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
# print('loop end')
def merge_sort(A, n, left, right):
if right - left > 1:
mid = (left + right) // 2
merge_sort(A, n, left, mid)
merge_sort(A, n, mid, right)
merge(A, n, left, mid, right)
N = int(input())
A = list(map(int, input().split()))
count = 0
merge_sort(A, N, 0, N)
print(' '.join(map(str, A)))
print(count)
| 1 | 117,229,237,840 | null | 26 | 26 |
score = list(map(int,input().split()))
taka = score[0]
aoki = score[2]
while taka > 0:
aoki -= score[1]
if aoki <= 0:
print('Yes')
break
taka -= score[3]
if aoki > 0:
print('No') | h = int(input())
def rc(h):
if h == 1:
return 1
t = rc(h//2)*2
return t + 1
print(rc(h)) | 0 | null | 54,933,632,723,360 | 164 | 228 |
def merge(cnt, A, left, mid, right):
L = A[left:mid] + [1e+99]
R = A[mid:right] + [1e+99]
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
cnt.append(right - left)
def mergeSort(cnt, A, left, right):
if left+1 < right:
mid = (left + right) // 2
mergeSort(cnt, A, left, mid)
mergeSort(cnt, A, mid, right)
merge(cnt, A, left, mid, right)
import sys
def input():
return sys.stdin.readline()[:-1]
n = int(input())
S = list(map(int, input().split()))
from collections import deque
cnt = deque()
mergeSort(cnt,S,0,n)
print(*S)
print(sum(cnt))
| c = 0
def merge(a,l,m,r):
global c
n1 = m-l
n2 = r-m
L = a[l:m]
R = a[m:r]
L.append(1000000009)
R.append(1000000009)
i,j = 0,0
for k in range(l,r):
if L[i]<=R[j]:
a[k] = L[i]
i += 1
else :
a[k] = R[j]
j += 1
c+=1
def mergeSort(a,l,r):
if l+1<r:
m = (l+r)//2
mergeSort(a,l,m)
mergeSort(a,m,r)
merge(a,l,m,r)
def main():
n = int(input())
a = list(map(int,input().split()))
mergeSort(a,0,n)
print (' '.join(map(str,a)))
print (c)
if __name__ == '__main__':
main()
| 1 | 117,142,220,214 | null | 26 | 26 |
import sys
from heapq import heapify, heappop, heappush
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, U, V = lr()
graph = [[] for _ in range(N+1)] # 1-indexed
for _ in range(N-1):
a, b = lr()
graph[a].append(b)
graph[b].append(a)
def dijkstra(start):
INF = 10 ** 15
dist = [INF] * (N+1)
dist[start] = 0
que = [(0, start)]
while que:
d, prev = heappop(que)
if dist[prev] < d:
continue
for next in graph[prev]:
d1 = d + 1
if dist[next] > d1:
dist[next] = d1
heappush(que, (d1, next))
return dist
dist_U = dijkstra(U)
dist_V = dijkstra(V)
answer = max(v for u, v in zip(dist_U, dist_V) if v > u) - 1
print(answer)
# 25 | S = input()
Q = int(input())
lS = ''
for _ in range(Q):
query = input().split()
if query[0] == '1':
lS, S = S, lS
else:
if query[1] == '1':
lS += query[2]
else:
S += query[2]
print(lS[::-1] + S) | 0 | null | 87,272,142,687,840 | 259 | 204 |
N = int(input())
for i in range(N):
a, b, c = map(int, input().split())
a2 = a ** 2
b2 = b ** 2
c2 = c ** 2
if a2 + b2 == c2 or a2 + c2 == b2 or b2 + c2 == a2:
print('YES')
else:
print('NO') | def ok(a,b,c):
return (a*a+b*b==c*c)
n=input()
for i in range(n):
a,b,c=map(int,raw_input().split())
if(ok(a,b,c) or ok(b,c,a) or ok(c,a,b)):
print "YES"
else:
print "NO" | 1 | 222,985,828 | null | 4 | 4 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
from itertools import groupby
N = int(readline())
S = input()
ans = 0
for g in groupby(S):
ans += 1
print(ans)
if __name__ == '__main__':
main()
| import re
N = int(input())
S = input()
result = ''
for i in range(len(S)):
if i == len(S) - 1:
result += S[i]
elif S[i] != S[i+1]:
result += S[i]
print(len(result))
| 1 | 170,507,489,523,680 | null | 293 | 293 |
from itertools import groupby
s=input()
if s[0]=='>':
s='<'+s
g=groupby(s)
a=[]
for i,j in g:
a.append(len(list(j)))
def sum(n):
return n*(n+1)//2
x=0
if len(a)%2==1:
a+=[1]
for i in range(0,len(a),2):
x+=sum(min(a[i],a[i+1])-1)
x+=sum(max(a[i],a[i+1]))
print(x)
| def main():
S = input()
N = len(S)+1
a = [0]*(N)
#右側からみていく
for i in range(N-1):
if S[i] == '<':
a[i+1] = max(a[i]+1,a[i+1])
#print(a)
#左側から見ていく
for i in range(N-2,-1,-1):
#print(i)
if S[i] == '>':
a[i] = max(a[i+1]+1,a[i])
ans = 0
#print(a)
for i in range(N):
ans += a[i]
return ans
print(main())
| 1 | 156,695,779,826,080 | null | 285 | 285 |
a = []
while True:
n = int(raw_input())
if n == 0:
break
a.append(n)
for i in range(len(a)):
print "Case " + str(i +1) + ": " + str(a[i]) | i = 0
while True :
x = int(input())
if(x == 0) :
break
else :
i += 1
print("Case ", i, ": ", x, sep = "")
| 1 | 492,352,628,910 | null | 42 | 42 |
def main():
S = list(input())
K = int(input())
cnt = 0
if K == 1:
T = S
for i in range(len(T)-1):
if T[i] == T[i+1]:
T[i+1] = '.'
ans = T.count('.')
print(ans)
return
if len(S) == 1:
ans = max(0, (K - (K%2==1))//2)
print(ans)
return
if len(set(S)) == 1:
tmp = len(S)*K
tmp = tmp - (tmp%2 == 1)
ans = tmp//2
print(ans)
return
T3 = S + S + S
for i in range(len(T3)-1):
if T3[i] == T3[i+1]:
T3[i+1] = '.'
T2aster = T3[len(S):(2*len(S))].count('.')
T3aster = T3.count('.')
ans = T3aster + T2aster * (K-3)
print(ans)
if __name__ == "__main__":
main()
| S = list(input())
K = int(input())
ans = 0
#2つ並べて一般性を確かめる
S2 = S*2
for i in range(1,len(S2)):
if S2[i-1]== S2[i]:
S2[i] = '@'
#2回目以降はk-1回任意の@へ直す
if i>=len(S2)//2:
ans+= K-1
else:
ans+=1
if len(set(S)) ==1 and len(S)%2 !=0:
ans = len(S)*(K//2)+(K%2==1)*(len(S)//2)
print(ans) | 1 | 175,933,640,698,292 | null | 296 | 296 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
cnt = [0]*3
ans = 1
for i, x in enumerate(A):
T = len([c for c in cnt if c == x])
for i, c in enumerate(cnt):
if c == x:
cnt[i] += 1
break
ans = ans * T % mod
print(ans)
| MOD = 10**9 + 7
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x) if isinstance(other, ModInt) else
ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x) if isinstance(other, ModInt) else
ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x) if isinstance(other, ModInt) else
ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
ModInt(other.x - self.x) if isinstance(other, ModInt) else
ModInt(other - self.x)
)
__rmul__ = __mul__
def __rtruediv__(self, other):
return (
ModInt(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(other, self.x, MOD))
)
def solve(N, A):
ret = ModInt(1)
count = [3 if not i else 0 for i in range(N + 1)]
for a in A:
ret *= count[a]
if not ret:
break
count[a] -= 1
count[a + 1] += 1
return ret
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
print(solve(N, A)) | 1 | 129,949,820,962,388 | null | 268 | 268 |
import sys
input = sys.stdin.readline
n,d,a = map(int,input().split())
attack = [0 for _ in range(n)]
event = []
for i in range(n):
x,h = map(int,input().split())
h = (h-1)//a+1
event.append([x-d,0,h,i])
event.append([x+d,1,h,i])
event.sort()
#print(event)
ans = 0
now = 0
for j in range(2*n):
x,m,h,i = event[j]
if m == 0:
if h > now:
attack[i] += h-now
ans += h-now
now = h
else:
now -= attack[i]
print(ans) | N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(0, M):
N -= A[i]
if N < 0:
print('-1')
else:
print(N) | 0 | null | 57,174,555,548,960 | 230 | 168 |
#abc145_d
m = 10**9+7
x,y = map(int,input().split())
fac =[0]*(10**6+1)
a = max(x,y)
b = min(x,y)
cnt = 0
fac[0]=1
while a != b:
a -= 2
b -= 1
cnt +=1
fac[cnt] = (fac[cnt-1]*cnt)%m
if a<0 or b <0:
print(0)
exit()
c = a//3
d = cnt
if a%3 != 0:
print(0)
exit()
else:
while a != 0:
a -= 1
b -= 2
cnt +=1
fac[cnt] = (fac[cnt-1]*cnt)%m
a -= 2
b -= 1
cnt +=1
fac[cnt] = (fac[cnt-1]*cnt)%m
n = ((fac[cnt])%m)*(pow(fac[c+d],m-2,m))*(pow(fac[c],m-2,m))
print(n%m)
| def solve(S):
pre = S[0]
flag = False
ans = 0
cnt = 0
for s in S[1:]:
if flag:
if pre == s:
cnt += 1
else:
ans += cnt // 2
cnt = 0
flag = False
else:
if pre == s:
cnt += 2
flag = True
pre = s
if flag:
ans += cnt // 2
return ans
S = input()
K = int(input())
if len(S) == 1:
print(K // 2)
elif len(S) == S.count(S[0]):
print((len(S)*K)//2)
else:
if K == 1:
print(solve(S))
elif K == 2:
print(solve(S + S))
else:
ans2 = solve(S + S)
ans3 = solve(S + S + S)
print(ans2 + (ans3-ans2)*(K - 2))
| 0 | null | 162,564,957,622,998 | 281 | 296 |
Residents = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for l in range(n):
b, f, r, v = list(map(int, input().split()))
Residents[b-1][f-1][r-1] += v
for k in range(4):
for j in range(3):
print(' '+' '.join(map(str, Residents[k][j])))
if k == 3:
break
print('####################') | import statistics
N = int(input())
AB = [map(int, input().split()) for _ in range(N)]
A,B = [list(i) for i in zip(*AB)]
if N%2 == 1:
low_med = statistics.median(A)
high_med = statistics.median(B)
print(high_med - low_med +1)
else:
low_med = statistics.median(A)
high_med = statistics.median(B)
print(int(2 * (high_med - low_med) +1)) | 0 | null | 9,292,948,160,980 | 55 | 137 |
def draw(h,w):
s = "#" * w
for i in range(0,h):
print s
print
if __name__ == "__main__":
while True:
h,w = map(int, raw_input().split())
if h==0 and w==0:
break
else:
draw(h,w) | while 1:
w,h=map(int,raw_input().split());a,b="#\n"
if w==0:break
print(a*h+b)*(w) | 1 | 782,449,336,738 | null | 49 | 49 |
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [(a-1) % K for a in A]
S = [0 for i in range(N+1)]
for i in range(1, N+1):
S[i] = (S[i-1] + A[i-1]) % K
kinds = set(S)
counts = {}
ans = 0
for k in kinds:
counts[k] = 0
for i in range(N+1):
counts[S[i]] += 1
if i >= K:
counts[S[i-K]] -= 1
ans += (counts[S[i]] - 1)
print(ans) | from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
S = [0]*(N+1)
# 累積和
for i in range(1, N + 1):
S[i] = S[i - 1] + A[i - 1] - 1
S[i] %= K
B = dd(int) # ここで範囲内のS[i]-iの個数を数えていく。
cnt = 0
for j in range(1, N + 1):
B[S[j - 1]] += 1
if j - K >= 0:
B[S[j - K]] -= 1
cnt += B[S[j]]
print(cnt) | 1 | 137,539,641,673,760 | null | 273 | 273 |
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N - 2):
if all(x == y for (x, y) in A[i:i+3]):
print('Yes')
break
else:
print('No') | n = int(input())
print(sum([i for i in range(1, n + 1) if i % 3 and i % 5])) | 0 | null | 18,616,118,144,868 | 72 | 173 |
X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0 or X*2<Y:
print(0)
exit(0)
n=(X-abs(Y-X))//3
X=n+abs(Y-X)
Y=n
mod=10**9+7
a=1
for i in range(1,X+Y+1):
a*=i
a%=mod
b=1
for i in range(1,X+1):
b*=i
b%=mod
c=1
for i in range(1,Y+1):
c*=i
c%=mod
print(a*pow(b,-1,mod)*pow(c,-1,mod)%mod)
| import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
n, m = ns()
c = na()
dp = [INF for _ in range(n + 1)]
dp[0] = 0
for ci in c:
for i in range(n + 1 - ci):
dp[i + ci] = min(dp[i + ci], dp[i] + 1)
print(dp[n])
if __name__ == '__main__':
main()
| 0 | null | 74,826,678,039,780 | 281 | 28 |
import sys
N = int(input())
strN = str(N)
if not ( 100 <= N <= 999 ): sys.exit()
print('Yes') if '7' in strN else print('No') | import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
N, P = map(int, input().split())
S = str(input())
def main():
if P == 2:
res = 0
for i in range(N):
if int(S[N - 1 - i]) % 2 == 0:
res += N - i
elif P == 5:
res = 0
for i in range(N):
if int(S[N - 1 - i]) == 0 or int(S[N - 1 - i]) == 5:
res += N - i
else:
mods = [0] * P # mods[i]はPで割ったあまりがiである連続部分列の個数
tenfactor = 1
mod = 0
mods[mod] += 1
for i in range(N):
mod = (mod + int(S[N - i - 1]) * tenfactor) % P
tenfactor = (tenfactor * 10) % P
mods[mod] += 1
res = 0
for p in range(P):
res += mods[p] * (mods[p] - 1) // 2
return res
print(main())
resolve() | 0 | null | 46,316,475,532,210 | 172 | 205 |
from fractions import gcd
import sys
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [i // 2 for i in a]
def div2check(i):
count = 0
while i % 2 == 0:
count += 1
i //= 2
return count
c = [div2check(i) for i in b]
if c.count(c[0]) != n:
print(0)
sys.exit()
lcm = b[0]
for i in b[1:]:
lcm = lcm * i // gcd(lcm, i)
print((m // lcm + 1) // 2) | n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n-1):
for j in range(i+1,n):
s += (a[i]*a[j])
print(s) | 0 | null | 134,997,391,145,122 | 247 | 292 |
n = int(input())
ans = 0
for i in range(1, n + 1):
for j in range(1, n//i + 1):
if i * j <= n:
ans += i * j
else:
break
print(ans) | s=input()
d_in={'/':1,'\\':-1,'_':0}
stack_h=[]
pairs_x=[]
for i in range(len(s)):
if d_in[s[i]]==-1:
stack_h.append(i)
elif d_in[s[i]]==1:
if len(stack_h)!=0:
pairs_x.append([stack_h.pop(),i+1])
stack_ans=[]
for i in range(len(pairs_x)):
pair_i=pairs_x.pop()
if len(stack_ans)==0:
stack_ans.append(pair_i)
elif pair_i[1]<=stack_ans[-1][0]:
stack_ans.append(pair_i)
area=[0]*len(stack_ans)
sum_area=0
for i in range(len(stack_ans)):
p=stack_ans.pop()
h=0
for j in range(p[0],p[1]):
area[i]+=h
h-=d_in[s[j]]
sum_area+=area[i]
print(sum_area)
if len(area)==0:
print(0)
else:
print(len(area),end=' ')
print(' '.join(map(str,area)))
| 0 | null | 5,568,574,048,980 | 118 | 21 |
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#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
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
#AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
if n==m:
print("Yes")
else:
print("No")
| # Skill Up
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
costs = []
for i in range(1 << n): #全パターン
cost = 0
total = [0] * m #値段とm冊の本についてのリスト
for j in range(n):
if (i>>j) & 1 == 1 : #iをjだけ右にシフト。j冊目を買う場合
cost += ca[j][0]
for k in range(m):
total[k] += ca[j][k+1]
if all(total[l] >= x for l in range(m)):
costs.append(cost)
if len(costs) == 0:
print(-1)
else:
print(min(costs)) | 0 | null | 52,810,035,305,160 | 231 | 149 |
h,n=map(int,input().split())
A=[]
B=[]
for i in range(n):
a,b=map(int,input().split())
A.append(a)
B.append(b)
dp=[10**10 for i in range(h+1)]
dp[h]=0
for i in reversed(range(1,h+1)):
for j in range(n):
if i-A[j]>=0:
dp[i-A[j]]=min(dp[i-A[j]],dp[i]+B[j])
else:
dp[0]=min(dp[0],dp[i]+B[j])
print(dp[0]) | a, b = map(int, input().split())
def get_GCD(x, y):
if x > y:
x, y = y, x
y_ = y
while True:
if y % x == 0:
break
else:
y += y_
return y
print(get_GCD(a, b)) | 0 | null | 97,423,726,504,820 | 229 | 256 |
n = int(input())
deck = []
for i in range(n):
mark, num = input().split()
deck.append((mark, int(num)))
for mark, num in [(mark, num) for mark in 'SHCD' for num in range(1,14) if (mark, num) not in deck]:
print(mark, num) | n = int(raw_input())
card = [i+" "+str(j) for i in "SHCD" for j in range(1,14)]
for i in range(n):
card.remove(raw_input())
pass
for i in card:
print i
| 1 | 1,051,340,354,852 | null | 54 | 54 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
A, B = mapint()
if 1<=A<=9 and 1<=B<=9:
print(A*B)
else:
print(-1) | n = list(input())
n1 = int(n[-1])
if n1 == 2 or n1 == 4 or n1 == 5 or n1 == 7 or n1 == 9:
print("hon")
elif n1 == 0 or n1 == 1 or n1 == 6 or n1 == 8:
print("pon")
else:
print("bon")
| 0 | null | 89,048,986,659,808 | 286 | 142 |
#ライブラリの読み込み
import math
#入力値の格納
k,x = map(int,input().split())
#判定
if k * 500 >= x:
text = "Yes"
else:
text = "No"
#表示
print(text)
| import sys
sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()
K, X = map(int, input().split())
if K * 500 >= X:
print("Yes")
else:
print("No") | 1 | 98,442,302,845,248 | null | 244 | 244 |
n = int(input())
S = input()
res = 1
tmp = S[0]
for i in range(1,n):
if S[i] != tmp:
res += 1
tmp = S[i]
print(res)
| n = int(input())
#a, b, h, m = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(h)]
l = 1
total = 26
while n > total:
l += 1
total += 26**l
last = total-26**l
v = n-last-1
ans = ''
# 26進数だと見立てて計算
for i in range(l):
c = v % 26
ans += chr(ord('a')+c)
v = v//26
print("".join(ans[::-1]))
| 0 | null | 91,100,750,672,608 | 293 | 121 |
A, B = input().split(" ")
A = int(A.strip())
B = int(B.strip().replace(".", ""))
print(A * B // 100) | n = int(input())
a = [input() for i in range(n)]
c0, c1, c2, c3 = 0, 0, 0, 0
for output in a:
if output == 'AC':
c0 += 1
elif output == 'WA':
c1 += 1
elif output == 'TLE':
c2 += 1
elif output == 'RE':
c3 += 1
print('AC x {}'.format(c0))
print('WA x {}'.format(c1))
print('TLE x {}'.format(c2))
print('RE x {}'.format(c3)) | 0 | null | 12,691,827,273,760 | 135 | 109 |
def resolve():
'''
code here
'''
H, W = [int(item) for item in input().split()]
if H == 1 or W == 1:
res = 1
elif H % 2 == 1 and W % 2 == 1:
res = H * W // 2 +1
else:
res = H * W // 2
print(res)
if __name__ == "__main__":
resolve()
| a = [int(input()) for i in range(2)]
if a[0] == 1:
if a[1] == 2:
my_result = 3
else:
my_result = 2
elif a[0] == 2:
if a[1] == 1:
my_result = 3
else:
my_result = 1
else:
if a[1] == 1:
my_result = 2
else:
my_result = 1
print(my_result) | 0 | null | 80,776,022,185,498 | 196 | 254 |
s,w = map(int,input().split())
print("safe") if s > w else print("unsafe") | x = input().split()
print(x.index('0') + 1) | 0 | null | 21,379,304,291,368 | 163 | 126 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
T = input()
print(T.replace('?','D'))
if __name__ == '__main__':
main() | def main():
S = input()
ans = [s if s != '?' else 'D' for s in S]
print(''.join(ans))
if __name__ == '__main__':
main() | 1 | 18,345,388,682,258 | null | 140 | 140 |
from sys import stdin
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
N, X, M = list(map(int, _in[0].split(' '))) # type:list(int)
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ans = 0
A = X
head_list = []
head = set()
repeat = set()
for i in range(N):
if A in head:
ind = head_list.index(A)
repeat = head_list[ind:]
head = head_list[:ind]
break
else:
head.add(A)
head_list.append(A)
A = pow(A, 2, M)
if len(repeat) == 0:
ans = sum(head)
else:
repeat_time = (N - len(head)) // len(repeat)
tail_len = N - len(head) - repeat_time * len(repeat)
ans = sum(head) + sum(repeat) * repeat_time + sum(repeat[:tail_len])
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
main()
| n, x, m = map(int, input().split())
a = x
li = [a]
exists = dict()
i = 1
for i in range(2, n + 1):
a = a * a % m
if a in exists:
break
li.append(a)
exists[a] = i
ans = sum(li)
if i != n:
loop, left = divmod(n - i + 1, i - exists[a])
ans += loop * sum(li[exists[a]-1:]) + sum(li[exists[a]-1:exists[a]-1+left])
print(ans)
| 1 | 2,845,011,584,830 | null | 75 | 75 |
N=int(input())
A=list(map(int,input().split()))
if N%2==0:
dp=[[-float("inf") for _ in range(2)] for _ in range(N+10)]
if N==2:
print(max(A[0],A[1]))
else:
for i in range(N):
if i==0:
dp[i][0]=A[0]
elif i==1:
dp[i][1]=A[1]
elif i==2:
dp[i][0]=A[0]+A[2]
else:
for j in range(2):
if j==0:
dp[i][0]=max(dp[i][0],dp[i-2][0]+A[i])
elif j==1:
dp[i][1]=max(dp[i][1],dp[i-2][1]+A[i],dp[i-3][0]+A[i])
print(max(dp[N-1]))
else:
#print(A[0],A[1])
dp=[[-float("inf") for _ in range(3)] for _ in range(N+10)]
if N==3:
print(max(A[0],A[1],A[2]))
else:
for i in range(N):
if i<4:
if i==0:
dp[i][0]=A[0]
if i==1:
dp[i][1]=A[1]
if i==2:
dp[i][2]=A[2]
dp[i][0]=A[0]+A[2]
if i==3:
dp[i][1]=max(dp[1][1]+A[3],dp[0][0]+A[3])
else:
for j in range(3):
if j==0:#ここでも2こずつ規則よく飛ばすと決めた
dp[i][0]=max(dp[i][0],dp[i-2][0]+A[i])
elif j==1:#1回だけ無茶した
dp[i][1]=max(dp[i][1],dp[i-2][1]+A[i],dp[i-3][0]+A[i])
else:
dp[i][2]=max(dp[i][2],dp[i-2][2]+A[i],dp[i-3][1]+A[i],dp[i-4][0]+A[i])
print(max(dp[N-1])) | import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
inf = 10 ** 16
if N % 2:
dp = [[-inf] * 3 for _ in range(N + 2)]
dp[0][0] = 0
dp[1][1] = 0
dp[2][2] = 0
if N > 4: dp[4][2] = a[0]
for i in range(N):
for j in range(3):
if dp[i][j] == -inf: continue
if i + 2 <= N + 1: dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i])
if i + 3 <= N + 1 and (j < 2): dp[i + 3][j + 1] = max(dp[i + 3][j + 1], dp[i][j] + a[i])
if i + 4 <= N + 1 and (j == 0): dp[i + 4][j + 1] = max(dp[i + 4][j + 1], dp[i][j] + a[i])
print(max(dp[-1][-1], dp[-2][-2], dp[-3][-3]))
#print(dp)
else:
dp = [[-inf] * 2 for _ in range(N + 2)]
dp[0][0] = 0
dp[1][1] = 0
for i in range(N):
for j in range(2):
if dp[i][j] == -inf: continue
if i + 2 <= N + 1: dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i])
if i + 3 <= N + 1 and (j < 1): dp[i + 3][j + 1] = max(dp[i + 3][j + 1], dp[i][j] + a[i])
print(max(dp[-1][-1], dp[-2][-2]))
#print(dp) | 1 | 37,234,059,718,578 | null | 177 | 177 |
import numpy as np
import itertools
N, M, Q = map(int, input().split())
G = []
for i in range(Q):
a, b, c, d = map(int, input().split())
G.append([a, b, c, d])
ans = 0
A = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N)))
n = len(A)
score = np.zeros(n, np.int32)
for a, b, c, d in G:
cond = A[:, b - 1] - A[:, a - 1] == c
score += d * cond
print(score.max())
| L=map(int, raw_input().split())
L=sorted(L)
for i in range(len(L)):
print L[i], | 0 | null | 14,006,987,043,248 | 160 | 40 |
M,D=map(int, input().split())
MM,DD=map(int, input().split())
if MM-1==M or (MM-1==0 and M==12):
print(1)
else:
print(0) | import math
def is_prime(n):
if n == 1: return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
n = int(input())
if is_prime(n):
print(n -1)
exit()
ans = n
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
temp_1 = n/k
temp_2 = k
ans = min(ans,temp_1 + temp_2)
print(int(ans-2))
| 0 | null | 143,398,794,783,078 | 264 | 288 |
n, m = map(int,input().split())
lst = [-1 for i in range(n + 1)]
lst[0] = 0
def find(x):
if(lst[x] < 0):
return(x)
else:
return(find(lst[x]))
def unit(x, y):
xr = find(x)
yr = find(y)
if (xr == yr):
pass
else:
if (xr > yr):
x, y = y, x
xr, yr = yr, xr
lst[xr] = lst[xr] + lst[yr]
lst[yr] = xr
for i in range(m):
a, b = map(int,input().split())
unit(a, b)
print(-(min(lst)))
| #!/usr/bin/env python3
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def roots(self):
return [i for i, x in enumerate(self.root) if x < 0]
def group_count(self):
return len(self.roots())
def main():
n, m = map(int, input().split())
UF = UnionFind(n)
for _ in range(m):
a, b = map(int, input().split())
UF.Unite(a, b)
print(UF.group_count() - 2)
if __name__ == "__main__":
main()
| 0 | null | 3,119,314,071,130 | 84 | 70 |
n = input()
s = input().split()
l = [int(i) for i in s]
print(min(l),max(l),sum(l)) | #!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
A = str(input())
B = str(input())
ans = [str(i) for i in range(1,4)]
ans.remove(A)
ans.remove(B)
print(ans[0])
| 0 | null | 55,577,483,828,612 | 48 | 254 |
n,k=map(int,input().split())
mod=10**9+7
U = 4*10**5+1
MOD = 10**9+7
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
for i in range(U,0,-1):
fact_inv[i-1] = (fact_inv[i]*i)%MOD
def comb(n,k):
if k < 0 or k > n:
return 0
x = fact[n]
x *= fact_inv[k]
x %= MOD
x *= fact_inv[n-k]
x %= MOD
return x
if n-1<=k:
print(comb(2*n-1,n-1))
else:
ans=0
for i in range(1+k):
ans+=comb(n,i)*comb(n-1,n-i-1)
ans%=mod
print(ans)
| n = int(input())
print((n+2-1)//2)
| 0 | null | 63,098,989,590,908 | 215 | 206 |
import sys
sys.setrecursionlimit(10**7)
def MI(): return map(int,sys.stdin.readline().rstrip().split())
class UnionFind:
def __init__(self,n):
self.par = [i for i in range(n+1)] # 親のノード番号
self.rank = [0]*(n+1)
def find(self,x): # xの根のノード番号
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self,x,y): # x,yが同じグループか否か
return self.find(x) == self.find(y)
def unite(self,x,y): # x,yの属するグループの併合
x = self.find(x)
y = self.find(y)
if self.rank[x] < self.rank[y]:
x,y = y,x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
self.par[y] = x
N,M = MI()
UF = UnionFind(N)
for _ in range(M):
a,b = MI()
UF.unite(a,b)
A = UF.par
A = [UF.find(A[i]) for i in range(1,N+1)]
print(len(set(A))-1)
| from collections import Counter
def solve():
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
Q = int(input())
ans = [0]*Q
total = sum(A)
for i in range(Q):
x,y = map(int, input().split())
total += c[x]*(y-x)
c[y] += c[x]
c[x] = 0
ans[i] = total
return ans
print(*solve(),sep='\n')
| 0 | null | 7,283,909,502,500 | 70 | 122 |
while(1):
H, W = map(int, input().split())
if H == 0 and W == 0:
break
for i in range(H):
for j in range(W):
print("#", end='')
print("\n", end='')
print("\n", end='') | # coding: utf-8
# Your code here!
while(1):
H,W=map(int,input().split(" "))
if H==0 and W==0:
break
else:
for i in range(H):
for j in range(W):
print("#",end="")
print("")
print("")
| 1 | 769,678,045,968 | null | 49 | 49 |
import math
n = float(input())
m = n / 1.08
if math.floor(math.floor(m) * 1.08) == n:
print(math.floor(m))
elif math.floor(math.ceil(m) * 1.08) == n:
print(math.ceil(m))
else:
print(':(') | def readinput():
n=int(input())
return n
def main(n):
x7=int(n/1.07)+1
x9=int(n/1.09)-1
n100=n*100
for x in range(max(1,x9),x7+1):
xx=x*108//100
#print(x,xx)
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| 1 | 125,420,747,635,418 | null | 265 | 265 |
N, K = [int(i) for i in input().split()]
mod = 10**9+7
result = 0
for i in range(K, N+2):
min_sum = ((i-1) * i) // 2
max_sum = ((N) * (N+1)) // 2 - ((N-i) * (N-i+1)) // 2
result += (max_sum - min_sum + 1) % mod
print(result%mod) | N = int(input())
S = list(input())
check = 0
for i in range(N-1):
if S[i] != "*":
if S[i:i+3] == ["A","B","C"]:
check += 1
S[i:i+3] = ["*"]*3
print(check) | 0 | null | 65,943,757,399,268 | 170 | 245 |
l=int(input())
temp1=l/3
temp2=(l-l/3)/2
print(temp1*temp2*(l-temp1-temp2)) | n = int(input())
i = 100
total=0
while i<n:
i = i*101//100
total +=1
print(total) | 0 | null | 36,945,549,791,932 | 191 | 159 |
N=int(input())
alp=["a","b","c","d","e","f","g","h","i","j"]
alp=alp[:N]
ans=[]
def dfs(now):
if len(now)==N:
ans.append(now)
return
for i,s in enumerate(alp):
if len(set(now))>=i:
next_s=now+s
dfs(next_s)
dfs("a")
ans=sorted(ans)
for a in ans:
print(a)
| mod=998244353
n,s=map(int,input().split())
ar=list(map(int,input().split()))
dp=[0 for y in range(s+1)]
dp[0]=1
for i in range(n):
for j in range(s,-1,-1):
if j+ar[i]<=s:
dp[j+ar[i]]=(dp[j]+dp[j+ar[i]])%mod
dp[j]=(dp[j]*2)%mod
print(dp[s])
| 0 | null | 34,939,452,129,390 | 198 | 138 |
import math
n = int(input())
z = math.floor(math.sqrt(n))
ans = 10 ** 12
for i in range(1,z+1):
if n % i == 0:
m = n // i
ans = min(ans,m+i-2)
print(ans) | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
n = I()
def yaku(m):
ans = []
i = 1
while i*i <= m:
if m % i == 0:
j = m // i
ans.append(i)
i += 1
ans = sorted(ans)
return ans
a = yaku(n)
#print(a)
ans = float('inf')
for v in a:
ans = min(ans, (v-1)+(n//v)-1)
print(ans)
| 1 | 161,254,882,265,500 | null | 288 | 288 |
def readinput():
n=int(input())
sList=[]
for _ in range(n):
sList.append(input())
return n,sList
def main(n,sList):
hist={}
for s in sList:
if s in hist.keys():
hist[s]+=1
else:
hist[s]=1
hList=sorted(list(hist.items()), key=lambda x:x[1], reverse=True)
#print(hList)
hvalue=hList[0][1]
ss=[]
i=0
while(i<len(hList) and hList[i][1]==hvalue):
ss.append(hList[i][0])
i+=1
ss.sort()
for s in ss:
print(s)
if __name__=='__main__':
n,sList=readinput()
main(n,sList)
| n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
A = [a+1 for a in A]
C = [0]*(n+1)
C[0] = 3
ans = 1
for a in A:
if C[a-1] < C[a]:
print(0)
exit()
else:
ans *= C[a-1]-C[a]
ans %= mod
C[a] += 1
print(ans) | 0 | null | 99,687,013,114,610 | 218 | 268 |
def i():
return int(input())
def i2():
return map(int,input().split())
def s():
return str(input())
def l():
return list(input())
def intl():
return list(int(k) for k in input().split())
n = i()
a = intl()
for i in range(n):
if a[i]%2 == 0:
if a[i]%3 != 0 and a[i]%5 !=0:
print("DENIED")
exit()
print("APPROVED") | n = int(input())
lst = list(map(int, input().split()))
a = list()
count = 0
for i in range(n):
if lst[i] % 2 == 0:
a.append(lst[i])
for i in range(len(a)):
if a[i] % 3 == 0 or a[i] % 5 == 0:
count += 1
if count == len(a):
print("APPROVED")
else:
print("DENIED") | 1 | 69,022,016,425,620 | null | 217 | 217 |
a = []
for i in range(10):
a.append(int(input()))
for i in sorted(a)[-1:-4:-1]:
print(i) | import sys
read = sys.stdin.buffer.read
def main():
N, T, *AB = map(int, read().split())
D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]
D.sort()
dp = [[0] * T for _ in range(N + 1)]
for i, (a, b) in enumerate(D):
for t in range(T):
if 0 <= t - a:
dp[i + 1][t] = dp[i][t - a] + b
if dp[i + 1][t] < dp[i][t]:
dp[i + 1][t] = dp[i][t]
ans = 0
for i in range(N - 1):
if ans < dp[i + 1][T - 1] + D[i + 1][1]:
ans = dp[i + 1][T - 1] + D[i + 1][1]
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 75,767,517,518,240 | 2 | 282 |
import math
N, X, T = map(int, input().split())
t = int(math.ceil(N/X))
print('{}'.format(t*T))
| A = map(int,input().split())
if sum(A)>=22:
print("bust")
else:
print("win") | 0 | null | 61,796,248,541,422 | 86 | 260 |
n=int(input())
a=input()
s=list(a)
b=list(a)
j=0
for i in range(0,n-1):
if s[i]==s[i+1]:
b.pop(i-j)
j=j+1
else:
pass
print(len(b)) | n = int(input())
s = input()
ans = 0
i = 0
while i < n:
ans += 1
while i + 1 < n and s[i] == s[i + 1]:
i += 1
i += 1
print(ans)
| 1 | 169,451,986,942,180 | null | 293 | 293 |
def main():
N = int(input())
cnt = 0
for _ in range(N):
d1, d2 = map(int, input().split())
if d1 == d2:
cnt += 1
else:
cnt = 0
if cnt >= 3:
print("Yes")
return
print("No")
if __name__ == "__main__":
main()
| n = int(input())
tmp = 0
import sys
for i in range(n):
d = list(map(int,input().split()))
if d[0] == d[1]:
tmp += 1
#check
if tmp == 3:
print('Yes')
sys.exit()
else:
tmp = 0
print('No') | 1 | 2,528,188,005,500 | null | 72 | 72 |
# ALDS1_2_C.
# バブルソートと選択ソートの安定性。
from math import sqrt, floor
class card:
def __init__(self, _str):
# S3とかH8をもとに初期化。
self.kind = _str # 出力用。
self.suit = _str[0]
self.value = int(_str[1])
def cardinput():
# カードの配列からオブジェクトの配列を生成。
a = input().split()
cards = []
for i in range(len(a)):
cards.append(card(a[i]))
return cards
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += a[i].kind + " "
_str += a[len(a) - 1].kind
print(_str)
def bubble_sort(a):
# aをバブルソートする(交換回数をreturnする)。
count = 0
for i in range(1, len(a)):
k = i - 1
while k >= 0:
# a[i]を前の数と交換していき、前の方が小さかったら止める。
if a[k].value > a[k + 1].value:
a[k], a[k + 1] = a[k + 1], a[k]
count += 1
else: break
k -= 1
return count
def selection_sort(a):
# 選択ソート。その番号以降の最小値を順繰りにもってくる。
# 交換回数は少ないが比較回数の関係で結局O(n^2)かかる。
count = 0
for i in range(len(a)):
# a[i]からa[len(a) - 1]のうちa[j]が最小っていうjを取る。
# このときiとjが違うならカウントする。
# というかa[i]とa[j]が違う時カウントでしたね。
minj = i
for j in range(i, len(a)):
if a[j].value < a[minj].value: minj = j
if a[i].value > a[minj].value: count += 1; a[i], a[minj] = a[minj], a[i]
return count
def main():
N = int(input())
cards = cardinput()
# バブルソートは安定。同じvalueなら団子のようにくっつくから。
# 選択ソートは交換が飛び越えるので不安定。よって、
# バブルの結果と比較すれば安定か不安定かが分かる。
_copy = [cards[i] for i in range(N)]
bubble_sort(cards)
selection_sort(_copy)
show(cards)
print("Stable")
show(_copy)
is_stable = True
for i in range(N):
for j in range(i + 1, N):
if _copy[i].value != _copy[j].value: continue
if _copy[i].suit != cards[i].suit: is_stable = False; break
if is_stable: print("Stable")
else: print("Not stable")
if __name__ == "__main__":
main()
| N = int(input())
C = input().split()
_C = C.copy()
for i in range(N):
for j in range(N-1, i, -1):
if (C[j][1] < C[j-1][1]):
C[j], C[j-1] = C[j-1], C[j]
print(*C)
print("Stable")
for i in range(N):
m = i
for j in range(i, N):
if (_C[j][1] < _C[m][1]):
m = j
_C[i], _C[m] = _C[m], _C[i]
print(*_C)
if(C ==_C):
print("Stable")
else:
print("Not stable") | 1 | 25,966,033,600 | null | 16 | 16 |
X = int(input())
x1 = X//500
x2 = (X%500)//5
print(x1*1000+x2*5) | x=int(input())
y=x//500*1000+(x%500)//5*5
print(y) | 1 | 42,851,884,991,942 | null | 185 | 185 |
x = raw_input()
a = int (x)**3
print a | if __name__ == "__main__":
n = int(raw_input())
print n * n * n | 1 | 279,874,180,320 | null | 35 | 35 |
sum = 0
num = [0] * (10 ** 5 + 1)
N = int(input())
A = [int(a) for a in input().split()]
for i in range(0, N):
sum += A[i]
num[A[i]] += 1
Q = int(input())
for i in range(0, Q):
B, C = (int(x) for x in input().split())
sum += (C - B) * num[B]
num[C] += num[B]
num[B] = 0
print(sum) | N = int(input())
A = list(map(int,input().split()))
ans = sum(A)
X = [0]*(10**5+1)
for x in A:
X[x] += 1
Q = int(input())
for _ in range(Q):
B,C = map(int,input().split())
ans += (C-B)*X[B]
X[C] += X[B]
X[B] = 0
print(ans)
| 1 | 12,195,253,073,906 | null | 122 | 122 |
h=int(input())
w=int(input())
n=int(input())
print((n//(-(max(h,w))))*(-1))
| import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
a.sort()
tf = [True] * a[-1]
dup = [False] * a[-1]
for i in range(n):
if tf[a[i]-1] == True:
#print(a[i])
if dup[a[i]-1] == True:
tf[a[i]-1] = False
else:
dup[a[i]-1] = True
for j in range(a[i]*2, a[-1]+1, a[i]):
tf[j-1] = False
c = 0
#print(tf)
for x in a:
if tf[x-1]:
c += 1
print(c)
| 0 | null | 51,282,446,947,940 | 236 | 129 |
for i in range(1,10001):
n = int(input())
if n:
print(f'Case {i}: {n}')
| i = 0
d = 0
while d == 0:
x = input()
if x != 0:
i += 1
print("Case %d: %d" %(i, x))
else:
d = 1 | 1 | 475,970,710,898 | null | 42 | 42 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
X = int(input())
big_coin, amari = divmod(X, 500)
print(big_coin*1000+(amari//5)*5) | x = int(input())
print(x//500*1000+(x-x//500*500)//5*5) | 1 | 42,750,032,814,370 | null | 185 | 185 |
a=1
b=1
c=[]
n=int(input())
c.append(a)
c.append(b)
for i in range(n):
c.append(a+b)
d=b
b+=a
a=d
print(c[n])
| import sys
input = sys.stdin.readline
from collections import deque
def main():
n = int(input().strip())
v = [[] for _ in range(n)]
for i in range(n):
v[i] = list(map(int, input().strip().split()))
l = [-1] * (n+1)
q = deque()
q.append((1, 0))
while len(q) != 0:
id, d = q.popleft()
# print("id", id)
if l[id] != -1:
# print("b")
continue
l[id] = d
# l[id] = min(d, l[id])
# print(id, d)
for i in range(v[id-1][1]):
q.append((v[id-1][2+i], d+1))
# if id == 8:
# print("##", id, v[id-1][2+i])
# print(repr(q))
for i in range(1, n+1):
print(i, l[i])
if __name__ == '__main__':
main()
| 0 | null | 2,777,580,752 | 7 | 9 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
ans = 0
for a in range(1, N):
ans += (N-1)//a
print(ans) | from functools import lru_cache
N = int(input())
# A * B <= N - 1はいくつありますか?
count = 0
# A ∈ {1, 2, ..., N-1}
for A in range(1, N):
# B <= (N - 1) // A
count += (N - 1) // A
print(count) | 1 | 2,551,758,138,028 | null | 73 | 73 |
n,m,l=list(map(int,input().split()))
m_A=[list(map(int,input().split())) for i in range(n)]
m_B=[list(map(int,input().split())) for i in range(m)]
for i in range(n):
t=[]
for k in range(l):
s=0
for j in range(m):
s+=m_A[i][j]*m_B[j][k]
t.append(s)
print(*t) | import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.argsort(A)
for a in A:
print(a+1, end=" ") | 0 | null | 91,146,773,790,620 | 60 | 299 |
import math
h = int(input())
n = int(math.log2(h))
a = 2
r = 2
S = (a*(r**n)-a) // (r-1)
print(S + 1) | n, x, y = list(map(int, input().split()))
x = x-1
y = y-1
ans = [0] * (n-1)
for i in range(n):
for j in range(i+1, n):
shortest = min(abs(j-i), abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1)
ans[shortest-1] += 1
for a in ans:
print(a)
| 0 | null | 62,216,934,815,912 | 228 | 187 |
S = input()
if S[-1] == 's':
print(S,'es',sep='')
else:
print(S,'s',sep='')
| n,k=map(int,input().split())
mod=10**9+7
ans=1
#Combination 1 O()
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
comb=Combination(10**6)
if n-1<=k:
print(comb(2*n-1,n)%mod)
else:
for i in range(1,k+1):
ans+=(comb(n,i)*comb(n-1,i))
ans%=mod
print(ans%mod) | 0 | null | 34,511,747,830,618 | 71 | 215 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0;r=10**10
while r-l>1:
x=(l+r)//2
ct=0
for i in range(n):
ct+=(a[i]-1)//x
if ct<=k:
r=x
else:
l=x
print(r) | import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
left = 0
right = max(A)
while right - left > 1:
mid = (left + right) // 2
jk = 0
for i in range(N):
jk += A[i] // mid - 1
if A[i] % mid != 0: jk += 1
if jk <= K:
right = mid
else:
left = mid
print(right) | 1 | 6,478,339,232,160 | null | 99 | 99 |
s,w=map(int,input().split())
print("unsafe" if s<=w else"safe") | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
S, W = map(int, input().split())
if W >= S:
print('unsafe')
else:
print('safe')
if __name__ == '__main__':
main()
| 1 | 29,354,711,269,672 | null | 163 | 163 |
import sys
input = sys.stdin.readline
a, b = input()[:-1].split()
print(min(''.join(a for i in range(int(b))), ''.join(b for i in range(int(a))))) | import sys
sys.setrecursionlimit(10 ** 6)
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
A = []
def rec(itr, lst):
if itr == N:
res = 0
for a, b, c, d in abcd:
if A[b-1] - A[a-1] == c:
res += d
return res
else:
res = 0
for i in range(lst, M):
A.append(i)
res = max(res, rec(itr + 1, i))
A.pop()
return res
print(rec(0, 0))
| 0 | null | 55,771,537,453,852 | 232 | 160 |
import math
n = int(input())
x = []
x.extend(list(map(int, input().split())))
y = []
y.extend(list(map(int, input().split())))
i = 0
sum = 0
for i in range(n):
sum += abs(x[i] - y[i])
print(sum)
sum = 0
for i in range(n):
sum += (x[i] - y[i]) ** 2
print(math.sqrt(sum))
sum = 0
for i in range(n):
sum += abs(x[i] - y[i]) ** 3
print(sum ** (1/3))
check = 0
for i in range(n):
if check < abs(x[i] - y[i]):
check = abs(x[i] - y[i])
print(check)
| # coding:utf-8
import math
N=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
manh_dist=0.0
for i in range(0,N):
manh_dist=manh_dist+math.fabs(x[i]-y[i])
print('%.6f'%manh_dist)
eucl_dist=0.0
for i in range(0,N):
eucl_dist=eucl_dist+(x[i]-y[i])**2
eucl_dist=math.sqrt(eucl_dist)
print('%.6f'%eucl_dist)
mink_dist=0.0
for i in range(0,N):
mink_dist=mink_dist+math.fabs(x[i]-y[i])**3
mink_dist=math.pow(mink_dist,1.0/3)
print('%.6f'%mink_dist)
cheb_dist=0.0
for i in range(0,N):
if cheb_dist<math.fabs(x[i]-y[i]):
cheb_dist=math.fabs(x[i]-y[i])
print('%.6f'%cheb_dist) | 1 | 206,191,507,050 | null | 32 | 32 |
N = int(input())
A = map(int, input().split())
B = [3 if i == 0 else 0 for i in range(N + 1)]
MOD = 1000000007
ans = 1
for a in A:
ans = ans * B[a] % MOD
if ans == 0:
break
else:
B[a] -= 1
B[a + 1] += 1
print(ans)
| #!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(500000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def calc(p, P):
ans = 0
for i in range(1, len(p)):
x1, y1 = P[p[i - 1]]
x2, y2 = P[p[i]]
ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
return ans
def solve():
N = int(input())
P = []
for _ in range(N):
X, Y = map(int, input().split())
P.append((X, Y))
ans = 0
num = 0
for p in permutations(range(N)):
ans += calc(p, P)
num += 1
print(ans / num)
def main():
solve()
if __name__ == '__main__':
main()
| 0 | null | 139,301,240,144,508 | 268 | 280 |
N=int(input())
L= list(map(int,input().split()))
L_sorted=sorted(L,reverse=False)#昇順
count=0
import bisect
for i in range(N):
for j in range(i+1,N):
a=L_sorted[i]
b=L_sorted[j]
bisect.bisect_left(L_sorted,a+b)
count+=bisect.bisect_left(L_sorted,a+b)-j-1
print(count) | from bisect import bisect_left
N=int(input())
A=sorted(list(map(int,input().split())))
cnt=0
for i in range(N-1):
for j in range(i+1,N):
a=bisect_left(A,A[i]+A[j])
if j<a:
cnt+=a-j-1
print(cnt) | 1 | 171,357,269,774,460 | null | 294 | 294 |
def func(N):
strN = str(N)
sum = 0
for s in strN:
sum += int(s)
return "Yes" if sum % 9 == 0 else "No"
if __name__ == "__main__":
N = str(input())
print(func(N)) | N = int(input())
def digitSum(n):
s = str(n)
array = list(map(int, s))
return sum(array)
if digitSum(N) % 9 == 0:
print("Yes")
else:
print("No") | 1 | 4,391,741,599,860 | null | 87 | 87 |
from collections import deque
def process_command(dll, commands):
# line_count = 1
for cmd in commands:
# print('processing line: {0}'.format(line_count))
# line_count += 1
# print(cmd)
try:
cmd, num_str = cmd.split()
except ValueError:
pass
# if cmd.startswith('insert') or cmd.startswith('delete '):
# t = cmd.split(' ')
# cmd = t[0]
# num_str = t[1]
if cmd == 'insert':
dll.appendleft(int(num_str))
elif cmd == 'delete':
# deque.index() ????????¨??§???????????? python3.5??\???????????§???????????§??¢???
if int(num_str) in dll: # ?????????????????????????????¨???????????´?????????????????????????????????
temp = []
result = dll.popleft()
while result != int(num_str):
temp.append(result)
result = dll.popleft()
temp = temp[::-1]
dll.extendleft(temp)
elif cmd == 'deleteFirst':
dll.popleft()
elif cmd == 'deleteLast':
dll.pop()
# print(dll)
# print('=' * 64)
if __name__ == '__main__':
# ??????????????\???
commands = []
num = int(input())
commands = [input() for i in range(num)]
# ??????
dll = deque()
process_command(dll, commands)
# ???????????????
print('{0}'.format(' '.join(map(str, dll)))) | x = int(input())
min_x = -int(pow(x,0.2))-1
for a in range(x):
for b in range(min_x,x):
test = pow(a,5) - pow(b,5)
if b > 0 and test < x:
break
if test == x:
print(a,b)
exit() | 0 | null | 12,856,524,060,512 | 20 | 156 |
import sys
N = int(input())
S,T = input().split()
if not ( 1 <= N <= 100 ): sys.exit()
if not ( len(S) == len(T) and len(S) == N ): sys.exit()
if not ( S.islower() and T.islower() ): sys.exit()
for I in range(N):
print(S[I],end='')
print(T[I],end='') | def main():
S = input()
if "A" in S and "B" in S:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| 0 | null | 83,337,981,077,952 | 255 | 201 |
n,k = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
print(sum(p[:k])) | import heapq
n,k = map(int,input().split())
p = list(map(int,input().split()))
aa = heapq.nsmallest(k, p)
print(sum(aa))
| 1 | 11,538,130,652,260 | null | 120 | 120 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.