code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
n = int(input())
s = []
t = []
for i in range(n):
s_, t_ = map(str, input().split())
s.append(s_)
t.append(int(t_))
x = input()
for i in range(n):
if s[i] == x:
break
ans = 0
for j in range(n-1, i, -1):
ans += t[j]
print(ans)
|
a=input().split()
print(a[1]+a[0])
| 0 | null | 100,280,877,334,026 | 243 | 248 |
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
total = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
# j以降の項で、初めてL[k] < a-bとなるkを二分探索する
if L[-1] > a - b: # 一番最後の項でもOKな場合(j+1以降全部OK)
total += N - j - 1
elif L[j+1] <= a - b: # 一番最初の項からNGな場合
continue
else:
head = j+1 # head はL[head] > a - bを満たす(OK側)
tail = N-1 # tail はL[tail] <= a - bを満たす(NG側)
while head+1 != tail:
if L[(head + tail)//2] > a - b: # 中間地点はOK側
head = (head + tail) // 2
else: # 中間地点はNG側
tail = (head + tail) // 2
total += head - j
print(total)
|
from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
# print(a)
for i in range(1,n-1):
for j in range(0,i):
k=bisect_left(a,a[i]+a[j])-i-1
# print(f"i{i} j{j} bisect{bisect_left(a,a[i]+a[j])}")
ans=ans+k
print(ans)
| 1 | 172,397,208,956,960 | null | 294 | 294 |
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
s = input()
if s == "AC":
c0 += 1
elif s == "WA":
c1 += 1
elif s == "TLE":
c2 += 1
elif s == "RE":
c3 += 1
else:
exit()
print(f"AC x {c0}")
print(f"WA x {c1}")
print(f"TLE x {c2}")
print(f"RE x {c3}")
|
from collections import Counter
N = int(input())
s = [input() for _ in range(N)]
c = Counter(s)
print(f'AC x {c["AC"] if c["AC"] else 0}')
print(f'WA x {c["WA"] if c["WA"] else 0}')
print(f'TLE x {c["TLE"] if c["TLE"] else 0}')
print(f'RE x {c["RE"] if c["RE"] else 0}')
| 1 | 8,670,270,264,500 | null | 109 | 109 |
while True:
H,W = map(int,input().split())
if H == 0 and W == 0:
break
for i in range(H):
for k in range(W):
if i == 0 or i == H-1 or k == 0 or k == W-1:
print("#",end = "")
else:
print(".",end = "")
print()
print()
|
while True:
H, W = map(int, input().split())
if not(H or W):
break
print('#' * W)
for i in range(H-2):
print('#' + '.' * (W - 2), end='')
print('#')
print('#' * W, end='\n\n')
| 1 | 830,327,302,880 | null | 50 | 50 |
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
s = input()
print(chr(ord(s)+1))
|
def resolve():
word=input()
print(chr(ord(word)+1))
resolve()
| 1 | 92,304,890,044,460 | null | 239 | 239 |
#!usr/bin/env python3
import sys
def init_card_deck():
# S: spades
# H: hearts
# C: clubs
# D: diamonds
card_deck = {'S': [], 'H': [], 'C': [], 'D': []}
n = int(sys.stdin.readline())
for i in range(n):
lst = [card for card in sys.stdin.readline().split()]
card_deck[lst[0]].append(lst[1])
return card_deck
def print_missing_cards(card_deck):
card_symbols = ['S', 'H', 'C', 'D']
for i in card_symbols:
for card in range(1, 14):
if not str(card) in card_deck[i]:
print(i, card)
def main():
print_missing_cards(init_card_deck())
if __name__ == '__main__':
main()
|
N = int(input())//2
S = input()
print('Yes' if S[:N] == S[N:] else 'No')
| 0 | null | 73,903,550,881,798 | 54 | 279 |
def get_ints() :
return list(map(int,input().split()))
a,b,c,d=get_ints()
ans=max(a*c,b*c,a*d,b*d)
print(ans)
|
S = input()
if S.count("hi")*2 == len(S):
print("Yes")
else:
print("No")
| 0 | null | 28,190,784,614,912 | 77 | 199 |
#coding: UTF-8
while True:
N, X = map(int, input().split())
if N == 0 and X == 0:
break
ans = 0
for i in range(1, N+1):
for j in range(1, N+1):
if i >= j:
continue
c = X - (i + j)
if c > j and c <= N:
ans += 1
print("%d"%(ans))
|
import itertools
while True:
n, x = map(int, input().split()) # n = 5, x = 9
if (n == 0 and x == 0):
break
count = 0
num_sequence = [i + 1 for i in range(n)] # [1, 2, 3, 4, 5]
for guess in itertools.combinations(num_sequence, 3):
sum = 0
for i in guess:
sum += i
if (sum == x):
# (1, 3, 5)
# (2, 3, 4)
count += 1
print(count)
| 1 | 1,290,724,408,722 | null | 58 | 58 |
x,y=input().split();x=int(x);y=float(y);print(int(x*y))
|
a,b=input().split()
print((int(a)*int(b))//1)
| 1 | 15,959,235,789,222 | null | 133 | 133 |
def bubbleSort(A, N):
count = 0
for j in range(N - 1):
for i in reversed(range(j + 1, N)):
if A[i - 1] > A[i]:
temp = A[i]
A[i] = A[i - 1]
A[i - 1] = temp
count = count + 1
for i in range(N):
print A[i],
print
print count
N = input()
A = map(int, raw_input().split())
bubbleSort(A, N)
|
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()
D = [LIST() for _ in range(N)]
cnt = 0
for x, y in D:
if x == y:
cnt += 1
if cnt == 3:
print("Yes")
break
else:
cnt = 0
else:
print("No")
| 0 | null | 1,276,724,419,642 | 14 | 72 |
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
for i in a:
c = 0
for j, k in zip(i, b):
c += j * k
print(c)
|
n,m = map(int,input().split())
#行列a、ベクトルb、行列積cの初期化
a = [0 for i in range(n)]
b = [0 for j in range(m)]
c = []
#a,bの読み込み
for i in range(n):
a[i] = input().split()
a[i] = [int(x) for x in a[i]]
for j in range(m):
b[j] = int(input())
#行列積計算
temp = 0
for i in range(n):
for j in range(m):
temp += a[i][j]*b[j]
c.append(temp)
temp = 0
#結果の表示
for num in c:print(num)
| 1 | 1,149,435,192,580 | null | 56 | 56 |
import itertools as it
n = int(input())
lst = []
for i in range(n):
x, y = list(map(int, input().split()))
lst.append([x, y])
perm = list(it.permutations(lst))
cost = []
for i in perm:
temp = 0
for j in range(len(i)-1):
temp += (((i[j][0] - i[j+1][0])**2) + ((i[j][1] - i[j+1][1])**2))**0.5
cost.append(temp)
print(sum(cost) / len(cost))
|
a,b,c = map(int, input().split())
ans = "No"
if (a == b or a== c or b == c) and not (a==b==c): ans = "Yes"
print(ans)
| 0 | null | 108,029,498,046,410 | 280 | 216 |
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
MAX_N = 2 * 10**6 + 10
# Construct factorial table
fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
fac[i] = fac[i-1] * (i) % MOD
fac_inv = [1] + [0] * MAX_N
# Femrmat's little theorem says a**(p-1) mod p == 1
# then, a * a**(p-2) mod p == 1
# it means that a**(p-2) is the inverse element
# Here, Get 1 / n! first
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
fac_inv[i-1] = fac_inv[i] * i % MOD
def mod_nCr(n, r):
if n < r or n < 0 or r < 0:
return 0
tmp = fac_inv[n-r] * fac_inv[r] % MOD
return tmp * fac[n] % MOD
k = int(input())
s = input().rstrip()
n = len(s)
ans = 0
for i in range(n, k + n + 1):
ret = mod_nCr(i-1, n-1) * pow(25, i - n, MOD) * pow(26, k + n - i, MOD)
ans += ret
ans %= MOD
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
MOD = 1000000007
cnt = [0,0,0] # 現在割り当てられている人数
ans = 1 # 現時点での組み合わせ
for a in A:
idx = []
for i in range(3):
if cnt[i] == a: # 割り当て可能
idx.append(i)
if len(idx)==0: # 割り当て不能
print(0)
exit()
cnt[idx[0]]+=1 # 任意の色で良いので、一番番号が若い色とする
ans *= len(idx) # 割り当て可能な人数をかける
ans %= MOD
print (ans)
| 0 | null | 71,163,860,976,650 | 124 | 268 |
A,B = map(int,input().split())
print(A*B if (1<= A <= 9) and (1<= B <= 9) else '-1')
|
n, x, m = (int(x) for x in input().split())
A = [x]
used = {x, }
while True:
x = pow(x, 2, m)
if x in used:
index = A.index(x)
break
else:
A.append(x)
used.add(x)
if n <= len(A):
print(sum(A[:n]))
else:
ans = sum(A)
n -= len(A)
m = len(A) - index
ans += (n // m) * sum(A[index:])
ans += sum(A[index:index + (n % m)])
print(ans)
| 0 | null | 80,784,275,225,568 | 286 | 75 |
xyz = input().split()
print(xyz[2]+ " " + xyz[0] + " " + xyz[1])
|
X = input().split()
print(X[2], X[0], X[1])
| 1 | 38,085,450,954,880 | null | 178 | 178 |
#coding:UTF-8
def BS(N,A):
count=0
flag=True
while flag==True:
flag=False
for i in range(1,N):
if A[N-i]<A[N-i-1]:
swap=A[N-i]
A[N-i]=A[N-i-1]
A[N-i-1]=swap
flag=True
count+=1
for i in range(len(A)):
A[i]=str(A[i])
print(" ".join(A))
print(count)
if __name__=="__main__":
N=int(input())
a=input()
A=a.split(" ")
for i in range(len(A)):
A[i]=int(A[i])
BS(N,A)
|
def bubble(A,N):
flag=1
cnt=0
while flag==1:
flag=0
for j in range(1,N):
if A[j]<A[j-1]:
k=A[j-1]
A[j-1]=A[j]
A[j]=k
flag=1
cnt+=1
return A,cnt
n=int(raw_input())
list=map(int,raw_input().split())
list,cnt=bubble(list,n)
for x in list:
print x,
print
print cnt,
| 1 | 17,227,637,912 | null | 14 | 14 |
H,N = map(int,input().split())
magics = [list(map(int,input().split())) for _ in range(N)]
max_A = max(a for a,b in magics)
INF = 10**10
DP = [INF]*(H+max_A)
DP[0] = 0
for i in range(1,H+max_A):
DP[i] = min(DP[i-a] + b for a,b in magics)
ans = min(DP[H:])
print(ans)
|
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9 for _ in range(H+10**4+1)]
dp[0] = 0
for a, b in magic:
for j in range(H+1):
if dp[j+a] > dp[j] + b:
dp[j+a] = dp[j] + b
print(min(dp[H:]))
| 1 | 81,411,632,952,582 | null | 229 | 229 |
S = input()
T = input()
min_change = 10**9
for posi_1 in range(len(S)-len(T)+1):
tmp = 0
for posi_2 in range(len(T)):
if S[posi_1+posi_2] != T[posi_2]:
tmp += 1
min_change = min(tmp, min_change)
print(min_change)
|
# 連想配列
from collections import deque
N = int(input())
ab = {}
abl = []
path = [[] for _ in range(N)]
for i in range(N-1):
a,b = map(int,input().split())
path[a-1].append(b-1)
path[b-1].append(a-1)
abl.append((a-1,b-1))
ab[(a-1,b-1)] = 0
color = [0]*N
color[0] = -1
q = deque([])
q.append(0)
max = 0
while len(q)>0:
cn = q.popleft()
ccolor = color[cn]
ncolor = 1
for i in path[cn]:
if color[i] == 0:
if ccolor != ncolor:
color[i] = ncolor
ab[(cn,i)] = ncolor
ncolor += 1
else:
color[i] = ncolor+1
ab[(cn,i)] = ncolor+1
ncolor += 2
if color[i] > max:
max = color[i]
q.append(i)
print(max)
for i in abl:
print(ab[i])
| 0 | null | 69,492,840,898,350 | 82 | 272 |
d_pre=input().split()
d=[int(s) for s in d_pre]
A=d[0]
B=d[1]
C=d[2]
D=d[3]
for i in range(210):
if i%2==0:
C-=B
if C<=0:
print("Yes")
break
else:
A-=D
if A<=0:
print("No")
break
|
# B - Battle
# 入力 A B C D
A, B, C, D = map(int, input().split(maxsplit=4))
while True:
C -= B
if C <= 0:
answer = 'Yes'
break
A -= D
if A <= 0:
answer = 'No'
break
print(answer)
| 1 | 29,846,583,542,240 | null | 164 | 164 |
n=int(input())
result=float('inf')
for i in range(1,int(n**.5)+1):
if i*(n//i)==n:
result=min(result,abs(i+n//i)-2)
print(result)
|
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
class LazySegmentTree(object):
def __init__(self, A, dot, unit, compose, identity, act):
# A : array of monoid (M, dot, unit)
# (S, compose, identity) : sub monoid of End(M)
# compose : (f, g) -> fg (f, g in S)
# act : (f, x) -> f(x) (f in S, x in M)
logn = (len(A) - 1).bit_length()
n = 1 << logn
tree = [unit] * (2 * n)
for i, v in enumerate(A):
tree[i + n] = v
for i in range(n - 1, 0, -1):
tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
self._n, self._logn, self._tree, self._lazy = n, logn, tree, [identity] * (2 * n)
self._dot, self._unit, self._compose, self._identity, self._act = dot, unit, compose, identity, act
def _ascend(self, i):
tree, lazy, dot, act = self._tree, self._lazy, self._dot, self._act
while i > 1:
i >>= 1
tree[i] = act(lazy[i], dot(tree[i << 1], tree[i << 1 | 1]))
def _descend(self, i):
tree, lazy, identity, compose, act = self._tree, self._lazy, self._identity, self._compose, self._act
for k in range(self._logn, 0, -1):
p = i >> k
f = lazy[p]
tree[p << 1], lazy[p << 1] = act(f, tree[p << 1]), compose(f, lazy[p << 1])
tree[p << 1 | 1], lazy[p << 1 | 1] = act(f, tree[p << 1 | 1]), compose(f, lazy[p << 1 | 1])
lazy[p] = identity
# A[i] <- f(A[i]) for all i in [l, r)
def range_act(self, l, r, f):
l += self._n
r += self._n
# propagation isn't necessary if S is commutative
# self._descend(l)
# self._descend(r - 1)
l0, r0 = l, r
tree, lazy, act, compose = self._tree, self._lazy, self._act, self._compose
while l < r:
if l & 1:
tree[l], lazy[l] = act(f, tree[l]), compose(f, lazy[l])
l += 1
if r & 1:
r -= 1
tree[r], lazy[r] = act(f, tree[r]), compose(f, lazy[r])
l >>= 1
r >>= 1
self._ascend(l0)
self._ascend(r0 - 1)
# calculate product of A[l:r]
def sum(self, l, r):
l += self._n
r += self._n
self._descend(l)
self._descend(r - 1)
l_val = r_val = self._unit
tree, dot = self._tree, self._dot
while l < r:
if l & 1:
l_val = dot(l_val, tree[l])
l += 1
if r & 1:
r -= 1
r_val = dot(tree[r], r_val)
l >>= 1
r >>= 1
return dot(l_val, r_val)
from operator import add
def resolve():
n, d, a = map(int, input().split())
XH = [None] * n
coordinates = set() # for coordinates compression
for i in range(n):
x, h = map(int, input().split())
XH[i] = [x, (h - 1) // a + 1] # 初めから何回減らすかだけ持てばよい
coordinates.add(x)
coordinates.add(x + 2 * d + 1) # [x, x + 2d + 1) に減らす
XH.sort()
compress = {v : i for i, v in enumerate(sorted(coordinates))}
n = len(compress)
A = [0] * n
for i in range(len(XH)):
A[compress[XH[i][0]]] = XH[i][1]
res = 0
tree = LazySegmentTree(A, max, 0, add, 0, add) # 区間 add, 1点取得ができればよいので、区間拡張しなくてよい max にしておく
for x, h in XH:
# もし x が生き残っていたら、[x, x + 2d + 1) から hp を引く
hp = tree.sum(compress[x], compress[x] + 1)
if hp <= 0:
continue
res += hp
tree.range_act(compress[x], compress[x + 2 * d + 1], -hp)
print(res)
resolve()
| 0 | null | 122,529,097,764,418 | 288 | 230 |
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
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")
# ------------------- fast io --------------------
from math import gcd, ceil
def pre(s):
n = len(s)
pi = [0] * n
for i in range(1, n):
j = pi[i - 1]
while j and s[i] != s[j]:
j = pi[j - 1]
if s[i] == s[j]:
j += 1
pi[i] = j
return pi
def prod(a):
ans = 1
for each in a:
ans = (ans * each)
return ans
def lcm(a, b): return a * b // gcd(a, b)
def binary(x, length=16):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
#n, k = map(int, input().split())
#a, b = map(int, input().split())
#c, d = map(int, input().split())
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))
h, w, k = map(int, input().split())
a = []
for __ in range(h):
a += [[k for k in input()]]
ans = 0
for ch1 in range(2**h):
for ch2 in range(2**w):
rowchosen = binary(ch1, h)
colchosen = binary(ch2, w)
count = 0
for i in range(h):
for j in range(w):
if rowchosen[i] != '1' and colchosen[j] != '1' and a[i][j] == '#':
count += 1
if count == k:ans+=1
print(ans)
|
def bubble_sort(A):
cnt = 0
for i in range(len(A) - 1):
for j in reversed(range(i+1, len(A))):
if A[j] < A[j - 1]:
cnt += 1
tmp = A[j]
A[j] = A[j - 1]
A[j - 1] = tmp
return cnt
cnt = 0
amount = int(input())
nl = list(map(int, input().split()))
cnt = bubble_sort(nl)
for i in range(amount - 1):
print(nl[i], end=" ")
print(nl[amount - 1])
print(cnt)
| 0 | null | 4,468,613,913,312 | 110 | 14 |
#ALDS1_1-B Greatest Common Divisor
def gcd(x,y):
if x%y == 0:
print(y)
else:
gcd(y,x%y)
x,y = [int(x) for x in input().split()]
if x>y:
gcd(x,y)
else:
gcd(y,x)
|
S = int(input())
h = S//3600
m = (S - (h*3600))//60
s = S - (h*3600 + m*60)
print("%d:%d:%d" %(h,m,s))
| 0 | null | 174,471,428,010 | 11 | 37 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7
mod = 998244353
def read_values():
return map(int, input().split())
def read_index():
return map(lambda x: int(x) - 1, input().split())
def read_list():
return list(read_values())
def read_lists(N):
return [read_list() for n in range(N)]
class V:
def __init__(self, f, v=None):
self.f = f
self.v = v
def __str__(self):
return str(self.v)
def ud(self, n):
if n is None:
return
if self.v is None:
self.v = n
return
self.v = self.f(self.v, n)
def main():
N, P = read_values()
S = input().strip()
if P in (2, 5):
res = 0
for i, s in enumerate(S):
if int(s) % P == 0:
res += i + 1
print(res)
else:
r = 0
D = {0: 1}
res = 0
d = 1
for i, s in enumerate(S[::-1]):
r += int(s) * d
r %= P
d *= 10
d %= P
c = D.setdefault(r, 0)
res += c
D[r] += 1
print(res)
if __name__ == "__main__":
main()
|
x=int(input())
X=x%100
Y=x//100
if X>5*Y:
print('0')
else:
print('1')
| 0 | null | 92,591,463,454,240 | 205 | 266 |
n = int(input())
l = list(map(str, input().split()))
l.reverse()
print(' '.join(l))
|
# -*- coding: utf-8 -*-
n = input()
l = map(int, raw_input().split())
for i in range(n-1):
print l[n-i-1],
print l[0]
| 1 | 991,041,797,642 | null | 53 | 53 |
def main():
h,w,k=map(int,input().split())
grid=[input() for _ in [0]*h]
ans=[[0]*w for _ in [0]*h]
berry=0
for i in range(h):
if "#" in grid[i]:
cnt=0
berry+=1
for j in range(w):
if grid[i][j]=="#":
cnt+=1
if cnt>1:
berry+=1
ans[i][j]=berry
for i in range(1,h):
if ans[i][0]==0:
for j in range(w):
ans[i][j]=ans[i-1][j]
for i in range(h-2,-1,-1):
if ans[i][0]==0:
for j in range(w):
ans[i][j]=ans[i+1][j]
for i in ans:
print(*i)
main()
|
val = input().split(' ')
N = int(val[0])
A = int(val[1])
B = int(val[2].strip())
if (B - A) % 2 == 0:
print((B-A)//2)
else:
diff = N - B if A - 1 > N - B else A - 1
flip = diff + 1
distance = (B - A - 1) // 2
print(flip + distance)
| 0 | null | 127,163,050,425,382 | 277 | 253 |
n, k = map(int, input().split())
arr = list(map(int, input().split()))
expected = []
cumsum = []
for x in arr:
sum = (x * (x + 1)) // 2
ex = sum / x
expected.append(ex)
sum = 0
maxi = 0
taken = 0
bad = 0
for x in expected:
sum += x
taken += 1
if taken == k:
maxi = max(maxi, sum)
elif taken > k:
sum -= expected[bad]
bad += 1
maxi = max(maxi, sum)
print(maxi)
|
#!/usr/bin/env python3
n, k, *P = map(int, open(0).read().split())
p = [(i + 1) / 2 for i in P]
s = [float()]
for i in range(n):
s.append(s[i] + p[i])
print(max(s[i + k] - s[i] for i in range(n - k + 1)))
| 1 | 75,093,554,429,092 | null | 223 | 223 |
import math
def kock(n,p1,p2):
a=math.radians(60)
if n==0:
return 0
s=[(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
t=[(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
u=[((t[0]-s[0])*math.cos(a)-(t[1]-s[1])*math.sin(a))+s[0],(t[0]-s[0])*math.sin(a)+(t[1]-s[1])*math.cos(a)+s[1]]
kock(n-1,p1,s)
print(" ".join(map(str,s)))
kock(n-1,s,u)
print(" ".join(map(str,u)))
kock(n-1,u,t)
print(" ".join(map(str,t)))
kock(n-1,t,p2)
n=int(input())
start=[float(0),float(0)]
end=[float(100),float(0)]
print(" ".join(map(str,start)))
kock(n,start,end)
print(" ".join(map(str,end)))
|
import math
SIN_T = math.sin(math.pi / 3)
COS_T = math.cos(math.pi / 3)
def koch(p0, p4):
p1 = ((p0[0]*2 + p4[0])/3, (p0[1]*2 + p4[1])/3)
p3 = ((p0[0] + p4[0]*2)/3, (p0[1] + p4[1]*2)/3)
p2 = (COS_T*(p3[0]-p1[0]) + -SIN_T*(p3[1]-p1[1]) + p1[0],
SIN_T*(p3[0]-p1[0]) + COS_T*(p3[1]-p1[1]) + p1[1])
return [p1, p2, p3, p4]
if __name__ == "__main__":
n = int(input())
points = [(0, 0), (100, 0)]
for _ in [0]*n:
_points = [points[0]]
for origin, dest in zip(points, points[1:]):
_points += koch(origin, dest)
points = _points
for p in points:
print(*p)
| 1 | 129,643,027,098 | null | 27 | 27 |
s = int(input())
h = s // 3600
m = s % 3600 // 60
s = s % 60
print(f'{h}:{m}:{s}')
|
import sys
import math
import itertools
from collections import deque
import copy
import bisect
MOD = 10 ** 9 + 7
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()
n, k = map(int, input().split())
inv_list = [1] # 0で割るというのは定義されないので無視。
for i in range(n):
inv_list.append(int(MOD - inv_list[(MOD % (i + 2)) - 1] * (MOD // (i + 2)) % MOD))
if k >= n:
ans = 1
for i in range(2 * n - 1):
ans *= (i + 1)
ans %= MOD
for i in range(n):
ans *= inv_list[i]
ans *= inv_list[i]
ans %= MOD
ans *= n
ans %= MOD
print(ans)
else:
ans = 1
nCm = 1
nmHm = 1
for i in range(k):
nCm *= n - i
nCm *= inv_list[i]
nCm %= MOD
nmHm *= (n - 1) - i
nmHm *= inv_list[i]
nmHm %= MOD
ans += nCm * nmHm
ans %= MOD
print(ans)
| 0 | null | 33,671,685,253,920 | 37 | 215 |
str = input() *2
pattern = input()
if pattern in str:
print("Yes")
else:
print("No")
|
input_n = input()
price1 = input()
price2 = input()
min_price = min(price1,price2)
max_profit = price2-price1
for i in xrange(input_n-2):
input_profit = input()
tmp = input_profit-min_price
if max_profit<tmp:
max_profit = tmp
if min_price>input_profit:
min_price = input_profit
print max_profit
| 0 | null | 861,252,330,708 | 64 | 13 |
import queue
n, m = map(int, input().split())
a = [[] for _ in range(n)]
ans = 0
for _ in range(m):
x, y = map(int, input().split())
a[x-1].append(y-1)
a[y-1].append(x-1)
route = set()
route.add(0)
q = queue.Queue()
q.put(0)
for i in range(n):
if not i in route:
route.add(i)
q.put(i)
ans += 1
while not q.empty():
c = q.get()
for k in a[c]:
if not k in route:
q.put(k)
route.add(k)
if len(route) == n:
print(ans)
break
|
class UnionFind:
"""
class UnionFind
https://note.nkmk.me/python-union-find/
order O(log(n))
n = the number of elements
parents = the list that contains "parents" of x. be careful that it doesn't contain "root" of x.
"""
def __init__(self, n):
"""
make UnionFind
:param n: the number of elements
"""
self.n = n
self.parents = [-1] * n
def find(self, x):
"""
:param x: an element
:return: the root containing 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):
"""
:param x, y: an element
"""
# root
x = self.find(x)
y = self.find(y)
if x == y:
# already same group so do nothing
return
if self.parents[x] > self.parents[y]:
# the root should be min of group
x, y = y, x
# remind that x, y is the root, x < y, then, y unions to x.
self.parents[x] += self.parents[y]
# and then y's parent is x.
self.parents[y] = x
def size(self, x):
# return the size of group
return -self.parents[self.find(x)]
def same(self, x, y):
# return whether the x, y are in same group
return self.find(x) == self.find(y)
def members(self, x):
# return members of group
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
# return all roots
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
# return how many groups
return len(self.roots())
def all_group_members(self):
# return all members of all groups
return {r: self.members(r) for r in self.roots()}
n,m= map(int,input().split())
union = UnionFind(n)
for i in range(m):
a,b = map(int,input().split())
union.union(a-1,b-1)
print(union.group_count()-1)
| 1 | 2,305,035,819,658 | null | 70 | 70 |
s=int(input())
print(s//3600, (s%3600)//60, s%60, sep=':')
|
S=input()
h=S/3600
r=S%3600/60
s=S-h*3600-r*60
print str(h)+':'+str(r)+':'+str(s)
| 1 | 336,854,872,180 | null | 37 | 37 |
import sys
input = sys.stdin.readline
from bisect import bisect, bisect_left
from itertools import accumulate
def main():
def check(x):
count = 0
for a in aaa:
if x <= a:
count += n
else:
count += n - bisect_left(aaa, x - a)
return count >= m
n, m = map(int, input().split())
aaa = list(map(int, input().split()))
aaa.sort()
acc = [0] + list(accumulate(aaa))
sum_a = acc[-1]
l, r = 0, 200001
while l + 1 < r:
mid = (l + r) // 2
if check(mid):
l = mid
else:
r = mid
# 合計がlより大きい組み合わせの和と組数を求める→Mに足りない分だけ合計がlの組を採用
ans = 0
count = 0
for a in aaa:
if l <= a:
ans += sum_a + a * n
count += n
else:
omit = bisect(aaa, l - a)
if omit < n:
ans += sum_a - acc[omit] + a * (n - omit)
count += n - omit
ans += l * (m - count)
print(ans)
if __name__ == '__main__':
main()
|
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
# l[i] = (a[j] >= i を満たすjの個数)
l = [n for i in range(a[0]+1)]
for i in range(2, n+1):
for j in range(a[-i], a[-i+1], -1):
l[j] = n - i + 1
# 二分探索
# a[i] + a[j] >= x を満たす(i, j)がm組以上存在する最小のxを求める
start = 2 * a[-1]
stop = 2 * a[0]
while start < stop:
i = (start + stop + 1) // 2
num = 0
for j in a:
if i - j < 0:
num += n
elif i - j <= a[0]:
num += l[i - j]
else:
break
if num >= m:
start = i
else:
stop = i - 1
num = 0
for i in a:
if start - i < 0:
num += n
elif 0 <= start - i <= a[0]:
num += l[start - i]
else:
break
# start <= a[i]+a[j] を満たす a[i]+a[j] を全て足す
ans = 0
for i in a:
if start - i < 0:
ans += 2 * i * n
elif start - i <= a[0]:
ans += 2 * i * l[start - i]
else:
break
ans -= (num - m) * start
print(ans)
| 1 | 107,887,511,859,790 | null | 252 | 252 |
ryou = [0]*4
for i in range(4):
ryou[i] = [0]*3
for i in range(4):
for j in range(3):
ryou[i][j] = [0]*10
sep = '#' * 20
n = int(input())
for i in range(n):
b, f, r, v = [int(x) for x in input().split()]
ryou[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
s = ' '
s += ' '.join(map(str,ryou[i][j]))
print(s)
if not i == 3:
print(sep)
|
input()
s, t = input().split()
print("".join([i + j for i, j in zip(s, t)]))
| 0 | null | 56,687,553,928,270 | 55 | 255 |
def ev(n):
return (n+1) / 2
N, K = map(int, input().split())
p = list(map(int, input().split()))
prev = ev(p[0])
ans = sum([ev(i) for i in p[:K]])
total = ans
for i in range(1, N-K+1):
total -= prev
total += ev(p[i+K-1])
prev = ev(p[i])
ans = max(ans, total)
print(ans)
|
alp = 'abcdefghijklmnopqrstuvwxyz'
print(alp[alp.index(input())+1])
| 0 | null | 83,391,853,216,980 | 223 | 239 |
H,A=map(int,input().split())
print((H-1)//A+1)
|
import math
H,A=map(int,input().split())
print(math.ceil(H/A))
| 1 | 77,328,390,404,820 | null | 225 | 225 |
S = input()
ans = 'Yes'
if len(S)%2 != 0:
print('No')
exit()
for i in range(0,len(S),2):
if S[i] != 'h':
print('No')
exit()
if S[i+1] != 'i':
print('No')
exit()
print('Yes')
|
S = input()
ans = S.replace("hi", "")
if ans == "":
print("Yes")
else:
print("No")
| 1 | 53,135,292,583,780 | null | 199 | 199 |
from math import factorial
n,m=map(int,input().split())
ans=0
if n>1:
ans+=factorial(n)//2//factorial(n-2)
if m>1:
ans+=factorial(m)//2//factorial(m-2)
print(ans)
|
import math
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, M = map(int, input().split())
ans = 0
if N >= 2:
ans += combinations_count(N, 2)
if M >= 2:
ans += combinations_count(M, 2)
print(ans)
| 1 | 45,807,797,663,782 | null | 189 | 189 |
n = int(input())
*A, = map(int, input().split())
inf = 10**18
# DP[i][0]=i番目まででi//2個選んだ最大値
# DP[i][1]=i番目まででi//2+1個選んだ最大値
DP = [[-inf]*2 for i in range(n)]
DP[0][0] = 0
DP[0][1] = A[0]
DP[1][0] = 0
DP[1][1] = max(A[0], A[1])
for i in range(2, n):
if i % 2 == 0:
DP[i][0] = max(DP[i-2][0]+A[i], DP[i-1][1])
DP[i][1] = DP[i-2][1]+A[i]
else:
DP[i][0] = max(DP[i-2][0]+A[i], DP[i-1][0])
DP[i][1] = max(DP[i-2][1]+A[i], DP[i-1][1])
if n % 2 == 0:
print(DP[n-1][1])
else:
print(DP[n-1][0])
|
from math import inf
n = int(input())
A = list(map(int, input().split()))
dp = [[-inf] * 3 for _ in range(n + 1)]
k = 1 + n % 2
dp[0][0] = 0
for i in range(n):
for j in range(k + 1):
if j < k:
dp[i + 1][j + 1] = dp[i][j]
now = dp[i][j]
if (i + j) % 2 == 0:
now += A[i]
dp[i + 1][j] = max(dp[i + 1][j], now)
print(dp[n][k])
| 1 | 37,379,929,685,268 | null | 177 | 177 |
index = int(input())
liststr = '1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51'
list = liststr.split(',')
print(int(list[index-1]))
|
def main():
N, P = map(int, input().split())
S = input()
if P == 2 or P == 5:
ans = 0
for i in range(N):
if int(S[i]) % P == 0:
ans += (i + 1)
print(ans)
exit()
sum_rem = [0] * N
sum_rem[0] = int(S[N - 1]) % P
ten = 10
for i in range(1, N):
a = (int(S[N - 1 - i]) * ten) % P
sum_rem[i] = (a + sum_rem[i - 1]) % P
ten = (ten * 10) % P
ans = 0
count = [0] * P
count[0] = 1
for i in range(N):
ans += count[sum_rem[i]]
count[sum_rem[i]] += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 53,944,585,797,872 | 195 | 205 |
n = int(input())
ans = ""
while n:
n -= 1
ans += chr(ord('a') + (n % 26))
n //= 26
print(ans[::-1])
|
N=int(input())
ans=''
while N>0 :
N-=1
ans += chr(ord('a')+N%26)
N//=26
print(ans[::-1])
| 1 | 11,937,583,835,622 | null | 121 | 121 |
b=0
n=input()
for i in range(1, int(n)+1):
if i%3==0 and i%5==0:
a="FizzBuzz"
elif i%3==0:
a="Fizz"
elif i%5==0:
a="Buzz"
else:
b=b+i
print(b)
|
h,w = map(int,input().split())
B = [input() for _ in range(h)]
dp=[]
def ch(x1,y1,x2,y2):
if B[x1][y1]=='.' and B[x2][y2]=='#':
return 1
else:
return 0
dp = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
for j in range(w):
if i==0 and j==0 and B[i][j]=='#':
dp[i][j]+=1
elif i==0:
dp[i][j] = dp[i][j-1]+ch(i,j-1,i,j)
elif j==0:
dp[i][j] = dp[i-1][j]+ch(i-1,j,i,j)
else:
dp[i][j] = min(dp[i][j-1]+ch(i,j-1,i,j),dp[i-1][j]+ch(i-1,j,i,j))
print(dp[h-1][w-1])
| 0 | null | 42,147,619,825,008 | 173 | 194 |
for i, a in enumerate(sorted(list(map(lambda a : int(a), input().split(" "))))):
if i == 0:
print("%d" % a, end ="")
else:
print(" %d"% a, end ="")
print()
|
from collections import deque
from bisect import bisect_left
n = int(input())
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)
| 0 | null | 86,117,898,469,748 | 40 | 294 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
C = [0] * 3
ret = 1
for i in range(N):
ret *= C.count(A[i])
ret %= mod
for j in range(3):
if C[j]==A[i]:
C[j]+=1
break
print(ret)
if __name__ == '__main__':
main()
|
def resolve():
MOD = 1000000007
N = int(input())
A = list(map(int, input().split()))
C = [0]*(N+1)
C[0] = 3
ans = 1
for i in range(N):
a = A[i]
ans *= C[a]
ans %= MOD
C[a] -= 1
C[a+1] += 1
print(ans)
if __name__ == "__main__":
resolve()
| 1 | 130,308,840,445,860 | null | 268 | 268 |
import bisect
def resolve():
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for a in range(n):
for b in range(a+1,n):
c = bisect.bisect_left(l,l[a]+l[b])
if c > b:
ans += c-b-1
else:
pass
print(ans)
resolve()
|
x = int(input())
cnt = 0
m_500 = x // 500
m_5 = (x - m_500*500) // 5
print(m_500*1000 + m_5*5)
| 0 | null | 106,991,994,113,292 | 294 | 185 |
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
if a >= b:
b *= 2
elif b >= c:
c *= 2
else:
c *= 2
if a < b < c:
print("Yes")
else:
print("No")
|
a, b, c = map(int, input().split())
k = int(input())
cnt = 0
while a >= b:
cnt += 1
b *= 2
while b >= c:
cnt += 1
c *= 2
if cnt <= k: print("Yes")
else: print("No")
| 1 | 6,886,875,310,278 | null | 101 | 101 |
s,w = map(int, input().split())
ans = "NG"
# for i in range(a,b+1):
# print(i)
if s<=w:
print("unsafe")
else:
print("safe")
|
# -*- coding:utf-8 -*-
import math
r = float(input())
print("{0:f} {1:f}".format(r*r*math.pi,2*r*math.pi))
| 0 | null | 14,975,305,140,062 | 163 | 46 |
import sys
input = sys.stdin.buffer.readline
MOD = 10**9 + 7
N, K = map(int, input().split())
A = list(map(int, (input().split())))
pos, neg = [], []
for a in A:
if a<0:
neg.append(a) # 負
else:
pos.append(a) # 0以上
if pos:
if N==K: # 全て選択で負の数が奇数ならfalse(正にできない)
ok = (len(neg)%2 == 0)
else:
ok = True
else:
ok = (K%2 == 0) # すべて負で奇数ならfalse(正にできない)
ans = 1
if ok == False: # false(正にできない)場合、絶対値が小さいものからk個かける
A.sort(key=abs)
for i in range(K):
ans *= A[i]
ans %= MOD
else:
pos.sort() # 後ろから取っていくので正は昇順
neg.sort(reverse=True) # 後ろから取っていくので負は降順
if K%2:
ans *= pos.pop() # kが奇数個なら1個は正を選ぶ
p = [] # 2個ずつかけた数を格納
while len(pos)>=2:
p.append(pos.pop() * pos.pop())
while len(neg)>=2: # 負を2回かけるのでxは正
p.append(neg.pop() * neg.pop())
p.sort(reverse=True)
for i in range(K//2): # 降順にk//2個見ていく
ans *= p[i]
ans %= MOD
print(ans)
|
N = int(input())
import collections
a = []
for i in range(N):
S = input()
a.append(S)
l = collections.Counter(a)
x = max(l.values())
ans = [k for k, v in l.items() if v == x]
ans = sorted(ans)
for i in ans:
print(i)
| 0 | null | 39,574,363,978,228 | 112 | 218 |
def solve(n,x):
count = 0
for i in range(1,n+1):
for j in range(1,n+1):
if i == j :
continue
for k in range(1,n+1):
if j == k or i == k:
continue
if i+j+k == x:
count += 1
return count//6
while True:
n,x = map(int,input().split())
if n == x == 0:
break;
print(solve(n,x))
|
n=int(input())
s=[str(input()) for _ in range(n)]
print(len(set(s)))
| 0 | null | 15,863,321,780,640 | 58 | 165 |
import sys
(row, column) = sys.stdin.readline().rstrip('\r\n').split(' ')
row = int(row)
column = int(column)
a = []
b = []
c = []
for ii in range(row):
a.append([int(x) for x in input().rstrip('\r\n').split(' ')])
for ii in range(column):
b.append(int(input().rstrip('\r\n')))
for ii in range(len(a)):
work = 0
for jj in range(len(a[ii])):
work += a[ii][jj] * b[jj]
c.append(work)
for cc in c:
print(cc)
|
n,m = map(int,input().split())
mat = list()
vec = list()
ans = [0 for _ in range(n)]
for _ in range(n):
mat.append(list(map(int,input().split())))
for _ in range(m):
vec.append(int(input()))
for i in range(n):
for j in range(m):
ans[i] += mat[i][j]*vec[j]
for k in ans :
print(k)
| 1 | 1,165,833,372,324 | null | 56 | 56 |
from sys import stdin
input = stdin.buffer.readline
print('No' if int(input()) < 30 else 'Yes')
|
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)
| 0 | null | 85,701,601,730,822 | 95 | 290 |
H,W,K=map(int,input().split())
c = []
ans = 0
for i in range(H):
s =list(input())
c.append(s)
for i in range(2**H):
for j in range(2**W):
tmp = 0
for h in range(H):
for w in range(W):
if 2**h & i >0 and 2**w & j >0:
if c[h][w] == "#":
tmp += 1
if tmp == K:
ans += 1
print(ans)
|
nums = [int(e) for e in input().split()]
Sheep = nums[0]
Wolves = nums[1]
if Sheep > Wolves:
print("safe")
else:
print("unsafe")
| 0 | null | 18,916,400,017,420 | 110 | 163 |
n=int(input())
a=list(map(int,input().split()))
thing={}
ans=0
for i in range(n):
if i-a[i] in thing:
ans+=thing[i-a[i]]
if i+a[i] in thing:
thing[i+a[i]]+=1
else:
thing[i+a[i]]=1
print(ans)
|
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
ja1 = []
ja2 = []
for i in range(1,n+1):
ja1.append(i-a[i-1])
ja2.append(i+a[i-1])
s = Counter(ja1)
t = Counter(ja2)
su = 0
for i in s.keys():
su += s[i]*t[i]
print(su)
| 1 | 26,053,888,195,832 | null | 157 | 157 |
X, N = map(int, input().split())
ans = 0
if N > 0:
p = list(map(int, input().split()))
r = [i for i in range(102) if i not in p]
d = [abs(X-i) for i in r]
ans = r[d.index(min(d))]
else:
ans = X
print(ans)
|
X,N = map(int,input().split())
p = list(map(int,input().split()))
diff = 1
if(X not in p):
print(X)
exit()
while(diff < 200):
if(X-diff not in p):
print(X-diff)
exit()
elif(X+diff not in p):
print(X+diff)
exit()
diff += 1
| 1 | 14,125,947,578,142 | null | 128 | 128 |
X = int(input())
dp = [0] * 110000
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(X + 1):
dp[i + 100] = max(dp[i], dp[i + 100])
dp[i + 101] = max(dp[i], dp[i + 101])
dp[i + 102] = max(dp[i], dp[i + 102])
dp[i + 103] = max(dp[i], dp[i + 103])
dp[i + 104] = max(dp[i], dp[i + 104])
dp[i + 105] = max(dp[i], dp[i + 105])
print(dp[X])
|
N = int(input())
a = list(map(int, input().split()))
ans = 0
for index, item in enumerate(a):
if (index+1) % 2 != 0 and item % 2 != 0:
ans += 1
print(ans)
| 0 | null | 67,515,995,225,160 | 266 | 105 |
a,b = map(int,input().split())
if a < b:
for i in range(b):
print(a,end = '')
else:
for i in range(a):
print(b,end = '')
|
a,b=input().split()
A,B = a*int(b), b*int(a)
if A < B: print(A)
else: print(B)
| 1 | 84,249,116,301,350 | null | 232 | 232 |
import sys
import math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
N,K=nm()
A=nl()
l=0
r=10**9
mid=0
if(K==0):
print(max(A))
sys.exit(0)
while(l+1<r):
mid=(l+r)//2
tmp=0
for i in range(len(A)):
tmp+=((A[i]-1)//mid)
if(tmp<=K):
r=mid
else:
l=mid
print(r)
|
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil
def main():
n, k, *a = map(int, read().split())
def isOK(x):
kaisu = 0
for ae in a:
kaisu += ceil(ae / x) - 1
if kaisu <= k:
return True
else:
return False
ng = 0
ok = max(a)
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if isOK(mid):
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| 1 | 6,431,167,097,280 | null | 99 | 99 |
INF = 1<<60
def resolve():
def judge(j):
for i in range(group):
cnt_Wchoco[i] += div_G[i][j]
if cnt_Wchoco[i] > K:
return False
return True
H, W, K = map(int, input().split())
G = [list(map(int, input())) for _ in range(H)]
ans = INF
for bit in range(1<<(H-1)):
group = 0 # 分かれたブロック数
row = [0]*H
for i in range(H):
# 分割ライン
row[i] = group
if bit>>i & 1:
group += 1
group += 1 # 1つ折ったら2つに分かれるのでプラス1, 折らなかったら1つ
# 分割したブロックを列方向で見る
div_G = [[0] * W for _ in range(group)]
for i in range(H):
for j in range(W):
div_G[row[i]][j] += G[i][j]
num = group-1
cnt_Wchoco = [0]*group
for j in range(W):
if not judge(j):
num += 1
cnt_Wchoco = [0] * group
if not judge(j):
num = INF
break
ans = min(ans, num)
print(ans)
if __name__ == "__main__":
resolve()
|
import itertools
H, W, K = map(int, input().split())
grid = []
for _ in range(H):
line = list(input())
grid.append(line)
# 横に割る方法は2**(H-1)、高々2**9=512通り
# これを決め打ちして、縦の割り方はGreedyに
ans = 10**9
# 割る場合を1, 割らない場合を0で表すことにする
for ptn in itertools.product([0, 1], repeat=H - 1):
# 不可能な場合、そのパターンはスキップする############################
able = True
for w in range(W):
# それぞれのブロックにおける白の数
lines = [0] * (sum(ptn) + 1)
# 今、上から何ブロック目か
line_num = 0
for h in range(H):
# 白の場合
if grid[h][w] == "1":
lines[line_num] += 1
# 境界を引く場合
# h=H-1の時、indexが範囲外になるのでminを使って調整
if ptn[min(h, H - 2)] == 1:
line_num += 1
# 1列でK個を超えるブロックがある場合、その割り方は不適。
if max(lines) > K:
able = False
break
if able == False:
continue
# 以下、実現が可能なものとして考える################################
# それぞれのブロックにおける白の数
lines = [0] * (sum(ptn) + 1)
# 横に割った回数
cnt = sum(ptn)
# ダメだったら1個前に戻る、という処理をしたいのでwhileで書く
# for内でデクリメントしてもループにならない(自戒)
w = 0
while w < W:
line_num = 0
for h in range(H):
# 白の場合
if grid[h][w] == "1":
lines[line_num] += 1
# 境界を引く場合
# h=H-1の時、indexが範囲外になるのでminを使って調整
if ptn[min(h, H - 2)] == 1:
line_num += 1
# Kを超えるブロックができてしまう場合
# 一つ前の列で切って、今の列からlinesを数え直す
if max(lines) > K:
cnt += 1
lines = [0] * (sum(ptn) + 1)
w -= 1
w += 1
ans = min(ans, cnt)
print(ans)
| 1 | 48,375,568,673,520 | null | 193 | 193 |
import math
n=input()
m=math.radians(60)
def kock(n, p1x, p1y, p2x, p2y):
if(n == 0):
return
sx=(2*p1x+1*p2x)/3
sy=(2*p1y+1*p2y)/3
tx=(1*p1x+2*p2x)/3
ty=(1*p1y+2*p2y)/3
ux=(tx-sx)*math.cos(m)-(ty-sy)*math.sin(m)+sx
uy=(tx-sx)*math.sin(m)+(ty-sy)*math.cos(m)+sy
kock(n-1, p1x, p1y, sx, sy)
print round(sx,8),round(sy, 8)
kock(n-1, sx, sy, ux, uy)
print round(ux, 8),round(uy, 8)
kock(n-1, ux, uy, tx, ty)
print round(tx, 8),round(ty, 8)
kock(n-1, tx, ty, p2x, p2y)
p1x = 0.00000000
p1y = 0.00000000
p2x = 100.00000000
p2y = 0.00000000
print p1x, p1y
kock(n, p1x, p1y, p2x, p2y)
print p2x, p2y
|
from math import sin, cos, pi
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return f"{self.x:.8f} {self.y:.8f}"
def kock(n, p1: Point, p2: Point):
if n == 0:
return
s = Point(
x=(2*p1.x + p2.x)/3,
y=(2*p1.y + p2.y)/3
)
t = Point(
x=(p1.x + 2*p2.x)/3,
y=(p1.y + 2*p2.y)/3
)
u = Point(
x=(t.x - s.x) * cos(pi / 3) - (t.y - s.y) * sin(pi / 3) + s.x,
y=(t.x - s.x) * sin(pi / 3) + (t.y - s.y) * cos(pi / 3) + s.y
)
kock(n - 1, p1, s)
print(s)
kock(n - 1, s, u)
print(u)
kock(n - 1, u, t)
print(t)
kock(n - 1, t, p2)
def main():
n = int(input())
p1 = Point(0.0, 0.0)
p2 = Point(100.0, 0.0)
print(p1)
kock(n, p1, p2)
print(p2)
main()
| 1 | 122,467,450,120 | null | 27 | 27 |
import itertools as it
n,m,k=list(map(int,input().split()))
S=[list(str(input())) for h in range(n)]
ans=0
for i in it.product([0,1],repeat=n):
for j in it.product(range(2),repeat=m):
count=0
for h in range(n):
for c in range(m):
if S[h][c]=="#" and i[h]+j[c]==0:
count+=1
if count==k:
ans+=1
print(ans)
|
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
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
K = INT()
if K <= 9:
print(K)
exit()
n = [-1]*11
n[-1] = 9
cnt = 9
def DFS(n):
global cnt
for i in range(1, 11):
if n[-i] == 9:
continue
elif n[-i-1] != -1 and n[-i] == n[-i-1]+1:
continue
else:
if n[-i] == -1:
n[-i] = 1
else:
n[-i] += 1
for j in range(i-1, 0, -1):
n[-j] = max(0, n[-j-1] - 1)
break
cnt += 1
if cnt == K:
print(*n[bisect(n, -1):], sep = "")
exit()
DFS(n)
DFS(n)
| 0 | null | 24,355,506,237,802 | 110 | 181 |
N,D,A=map(int, input().split())
B=[list(map(int, input().split())) for _ in range(N)]
C=sorted(B)
d,E=zip(*C)
import bisect
Damage=[0]*N
for i in range(N):
e=bisect.bisect_right(d,d[i]+2*D)
Damage[i]=e
dd=[0]*(N+1)
cnt=0
for i in range(N):
if i!=0:
dd[i]+=dd[i-1]
h=E[i]
h-=dd[i]
if h>0:
bomb=-(-h//A)
cnt+=bomb
dd[i]+=A*bomb
dd[Damage[i]]-=A*bomb
print(cnt)
|
import bisect
import math
N, D, A = map(int, input().split())
XH_array = [list(map(int, input().split())) for _ in range(N)]
XH_array = sorted(XH_array, key=lambda x: x[0])
X_array = [xh[0] for xh in XH_array]
# print(X_array)
ans = 0
bomb_count = [0] * N
now_bomb = 0
for i, xh in enumerate(XH_array):
# print(now_bomb, bomb_count)
x, h = xh
remain = h - A * now_bomb
if remain <= 0:
now_bomb += bomb_count[i]
continue
bomb_add = math.ceil(remain / A)
ans += bomb_add
bomb_count[i] += bomb_add
bomb_end = bisect.bisect_right(X_array, x + 2 * D)
bomb_count[bomb_end - 1] -= bomb_add
now_bomb += bomb_count[i]
print(ans)
| 1 | 82,048,771,588,420 | null | 230 | 230 |
N = int(input())
s = "a"
ans = []
def dfs(s,n):
if len(s) == n:
ans.append(s)
return
last = 0
for i in range(len(s)):
last = max(last,ord(s[i]))
limit = chr(last+1)
for i in range(26):
temp = chr(97+i)
if temp <= limit:
dfs(s+temp,n)
dfs(s,N)
print(*ans,sep="\n")
|
n = int(input())
def dfs(s, i):
if i == n:
print(s)
else:
for j in range(ord("a"), max(map(ord, list(s))) + 2):
dfs(s + chr(j), i + 1)
dfs("a", 1)
| 1 | 52,285,220,897,052 | null | 198 | 198 |
# coding: utf-8
import sys
import collections
def main():
n, quantum = map(int, raw_input().split())
processes = [x.split() for x in sys.stdin.readlines()]
for p in processes:
p[1] = int(p[1])
queue = collections.deque(processes)
elapsed = 0
while queue:
# print elapsed, queue
head = queue.popleft()
if head[1] > quantum:
head[1] -= quantum
queue.append(head)
elapsed += quantum
else:
elapsed += head[1]
print head[0], elapsed
if __name__ == '__main__':
main()
|
n, q = map(int, input().split())
process = []
for _ in range(n):
name, time = input().split()
process.append([name, int(time)])
process.append([])
def reduce(index):
left_time = process[index][1] - q
return [process[index][0], left_time]
head = 0
tail = n
quene_len = len(process)
elapsed_time = 0
while head != tail:
if process[head][1] > q:
process[tail] = reduce(head)
elapsed_time += q
head = (head+1)%quene_len
tail = (tail+1)%quene_len
else:
elapsed_time += process[head][1]
print(process[head][0], elapsed_time)
head = (head+1)%quene_len
| 1 | 43,980,995,032 | null | 19 | 19 |
import sys
input = sys.stdin.readline
A = sorted(list(map(int,input().split())))
if (A[0] != A[1] and A[1] == A[2]) or (A[0] == A[1] and A[1] != A[2]) :
print('Yes')
else:
print('No')
|
def main():
a,b,c = map(int,input().split())
if a == b and b==c :
print("No")
return
if a != b and b != c and a != c:
print("No")
return
print("Yes")
return
if __name__ == "__main__":
main()
| 1 | 68,217,070,162,778 | null | 216 | 216 |
N,K = map(int,input().split())
sunuke = [0]*(N+1)
for i in range(K):
okashi_category = input()
#print (okashi_category)
if okashi_category ==1:
sunuke[input()]=1
else:
sunukelist = list(map(int,input().split()))
for j in range(len(sunukelist)):
#print(sunukelist[j])
sunuke[sunukelist[j]]=1
print (N-sum(sunuke))
|
n, k = map(int, input().split())
l = [0] * n
for i in range(k):
d = int(input())
a = list(map(int, input().split()))
for j in range(d):
l[a[j] - 1] += 1
count = 0
for i in range(n):
if l[i] == 0:
count += 1
print(count)
| 1 | 24,606,451,138,358 | null | 154 | 154 |
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def read_values():
return map(int, input().split())
def read_index():
return map(lambda x: x - 1, map(int, input().split()))
def read_list():
return list(read_values())
def read_lists(N):
return [read_list() for n in range(N)]
def functional(N, mod):
F = [1] * (N + 1)
for i in range(N):
F[i + 1] = (i + 1) * F[i] % mod
return F
INV = dict()
def inv(a, mod):
if a in INV:
return INV[a]
i = pow(a, mod - 2, mod)
INV[a] = i
return i
def C(F, a, b, mod):
return F[a] * inv(F[a - b], mod) * inv(F[b], mod) % mod
def main():
N, K = read_values()
mod = 10 ** 9 + 7
F = functional(5 * 10 ** 5, mod)
res = 0
if N <= K:
res = C(F, 2 * N - 1, N - 1, mod)
else:
for k in range(K + 1):
res += C(F, N, k, mod) * C(F, N - 1 , k, mod) % mod
print(res % mod)
if __name__ == "__main__":
main()
|
def pow_mod(a, b, p):
res = 1
mul = a
for i in range(len(bin(b)) - 2):
if (1 << i) & b:
res = (res * mul) % p
mul = (mul ** 2) % p
return res
def comb_mod(n, r, p, factorial, invert_factorial):
return (factorial[n] * invert_factorial[r] * invert_factorial[n - r]) % p
def main():
p = 10 ** 9 + 7
n, k = map(int, input().split())
factorial = [1] * (n + 1)
for i in range(1, n + 1):
factorial[i] = (factorial[i - 1] * i) % p
invert_factorial = [0] * (n + 1)
invert_factorial[n] = pow_mod(factorial[n], p - 2, p)
for i in range(n - 1, -1, -1):
invert_factorial[i] = (invert_factorial[i + 1] * (i + 1)) % p
res = 0
for i in range(min(k + 1, n)):
res = (res + comb_mod(n, i, p, factorial, invert_factorial)
* comb_mod(n - 1, i, p, factorial, invert_factorial)) % p
print(res)
main()
| 1 | 67,125,536,769,692 | null | 215 | 215 |
k = int(input())
str = "ACL" * k
print(str)
|
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
k = int(input())
tmp = 0
res = ""
for i in range(k):
res += "ACL"
print(res)
| 1 | 2,150,634,866,820 | null | 69 | 69 |
import sys
import time
import math
import itertools as it
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
A, B, H, M = inpl()
h = 360 * H / 12 + 30 * M / 60
m = 360 * M / 60
sa = abs(h - m)
sa = min(sa, 360-sa)
print((A*A + B*B - 2*A*B*math.cos(sa*math.pi/180))**0.5)
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
|
import math
a, b, h, m = map(int, input().split())
ang = h * 30 - m * 5.5
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ang)))
print(ans)
| 1 | 20,140,144,889,822 | null | 144 | 144 |
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(H, W, K, Si):
Si = [[int(i) for i in S] for S in Si]
ans = H + W
for i in range(2 ** (H - 1)):
h_border = bin(i).count('1')
w_border = 0
white_counts = [0] * (h_border + 1)
choco_w = 0
for w in range(W):
choco_w += 1
wc_num = 0
tmp_count = [0] * (h_border + 1)
for h in range(H):
white_counts[wc_num] += Si[h][w]
tmp_count[wc_num] += Si[h][w]
if i >> h & 1:
wc_num += 1
if max(white_counts) > K:
if choco_w == 1:
break # 1列の時点で > K の場合は条件を達成できない
w_border += 1
white_counts = tmp_count
choco_w = 1
else:
ans = min(ans, h_border + w_border)
print(ans)
if __name__ == '__main__':
H, W, K = map(int, input().split())
Si = [input() for _ in range(H)]
solve(H, W, K, Si)
# # test
# from random import randint
# from func import random_str
#
# H, W, K = 10, 1000, randint(1, 100)
# Si = [random_str(W, '01') for _ in range(H)]
# print(H, W, K)
# for S in Si:
# print(S)
# solve(H, W, K, Si)
|
x,y = map(int,input().split())
mod = 10**9+7
def comb(a,b):
comb = 1
chld = 1
for i in range(b):
comb = comb*(a-i)%mod
chld = chld*(b-i)%mod
return (comb*pow(chld,mod-2,mod))%mod
if (x+y)%3!=0:
print(0)
else:
nm = (x+y)//3
n = y-nm
m = x-nm
if n>=0 and m>=0:
print(comb(n+m,m))
else:
print(0)
| 0 | null | 99,482,763,685,030 | 193 | 281 |
n,m=map(int,input().split())
h=list(map(int,input().split()))
c=0
d=[0]*n
for i in range(m):
a,b=map(int,input().split())
d[a-1]=max(d[a-1],h[b-1])
d[b-1]=max(d[b-1],h[a-1])
for i in range(n):
if h[i]>d[i]:
c+=1
print(c)
|
n=input()
h=n/3600
m=(n-h*3600)/60
print ':'.join(map(str,[h,m,n%60]))
| 0 | null | 12,651,770,095,202 | 155 | 37 |
X = int(input())
d = {}
for i in range(0, 26):
d[i+1] = chr(97+i)
a = []
while X > 0:
if X%26 != 0:
a.append(d[(X % 26)])
X -= X % 26
else:
a.append(d[26])
X -= 26
X //= 26
for i in a[::-1]:
print(i, end='')
print()
|
a = 1
while a<10:
b=1
while b<10:
print(str(a)+'x'+str(b)+'='+str(a*b))
b=b+1
a=a+1
| 0 | null | 5,987,918,579,580 | 121 | 1 |
s,w= map(int, input().split())
if s>w:
print('safe')
else:
print('unsafe')
|
# Sheep and Wolves
S, W = map(int, input().split())
print(['safe', 'unsafe'][W >= S])
| 1 | 29,128,999,798,690 | null | 163 | 163 |
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]
for i in range(N):
B[A[i]-1] = i
for b in B:
print(b+1)
|
n = int(input())
alst = list(map(int, input().split()))
ans = [-1 for _ in range(n)]
for i, a in enumerate(alst, start = 1):
ans[a - 1] = i
print(*ans)
| 1 | 180,868,588,104,300 | null | 299 | 299 |
n, x, m = map(int,input().split())
ans = x
num = 0
l = [0]*m
lis = [-1]*m
l[0] = x
lis[x] = num
for i in range(1,n):
x = (x*x)%m
num += 1
if lis[x]!=-1:
a = (n-i)//(i-lis[x])
b = (n-i)%(i-lis[x])
ans += a * sum(l[lis[x]:i])
for j in range(lis[x],lis[x]+b):
ans += l[j]
break
l[i] = x
lis[x] = i
ans += x
print(ans)
|
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()
def resolve():
N, X, M = LI()
A = []
seen = set()
tmp = X
head_idx = -1
while True:
A.append(tmp)
seen.add(tmp)
tmp = pow(tmp, 2, M)
if tmp in seen:
head_idx = A.index(tmp)
break
# print(A, head_idx)
cnt = [0] * len(A)
for i in range(len(A)):
if i < head_idx:
if i <= N:
cnt[i] = 1
else:
l = len(A) - head_idx
cnt[i] = (N - head_idx) // l
for i in range(head_idx, head_idx + (N - head_idx) % l):
cnt[i] += 1
# print(cnt)
ans = sum([a * c for a, c in zip(A, cnt)])
print(ans)
if __name__ == '__main__':
resolve()
| 1 | 2,802,396,766,380 | null | 75 | 75 |
import numpy as np
from numba import njit, i8
@njit(i8(i8, i8[:], i8[:]), cache=True)
def solve(H, A, B):
A_max = A.max()
dp = np.zeros(H + A_max + 1, dtype=np.int64)
for i in range(A_max + 1, H + A_max + 1):
dp[i] = np.min(dp[i - A] + B)
return dp[-1]
H, N, *AB = map(int, open(0).read().split())
A = np.array(AB[::2], dtype=np.int64)
B = np.array(AB[1::2], dtype=np.int64)
print(solve(H, A, B))
|
# F - Sugoroku
import sys
sys.setrecursionlimit(10 ** 9)
n,m = map(int,input().split())
s = input()
# r[i]:sを後ろから見ていって、iから最小何手でゴールするかを求める。
INF = float('inf')
r = [INF for _ in range(n+1)]
r[n] = 0
idx = n
for i in range(n-1,-1,-1):
while(idx-i > m or r[idx] == INF):
idx -= 1
if idx <= i:
print(-1)
exit()
if s[i] == '0':
r[i] = r[idx]+1
p = r[i]
#print(r)
# rを先頭から見ていき、rの数字が変わる直前まで進むようにすれば
# 最短で辞書順最小なルートが求まる。
ans = []
c = 0
for i in range(n+1):
if r[i] != INF and r[i] != p:
p = r[i]
ans.append(c)
c = 1
else:
c += 1
print(*ans)
# mnr = [m for _ in range(n+1)]
# mnl = n+1
# def dfs(x,c):
# global mnr,mnl
# #print(x,c)
# if x == n:
# #print(r)
# if len(r) < mnl or (len(r) == mnl and r < mnr):
# mnr = r[:]
# mnl = len(r)
# return True
# if c >= mnl or x > n or s[x] == '1':
# return False
# for i in range(m,0,-1):
# r.append(i)
# dfs(x+i,c+1)
# r.pop()
# dfs(0,0)
# if mnl < n+1:
# print(*mnr)
# else:
# print(-1)
| 0 | null | 110,621,146,823,612 | 229 | 274 |
def out(data) -> str:
print(' '.join(map(str, data)))
N = int(input())
data = [int(i) for i in input().split()]
out(data)
for i in range(1, N):
tmp = data[i]
j = i - 1
while j >= 0 and data[j] > tmp:
data[j + 1] = data[j]
j -= 1
data[j + 1] = tmp
out(data)
|
def print_list(ele_list):
print(" ".join(map(str, ele_list)))
def insertion_sort(ele_list):
len_ele_list = len(ele_list)
print_list(ele_list)
for i in range(1, len_ele_list):
key = ele_list[i]
j = i - 1
while j >= 0 and ele_list[j] > key:
ele_list[j+1] = ele_list[j]
j -= 1
ele_list[j+1] = key
print_list(ele_list)
N = int(input())
ele_list = list(map(int, input().split()))
insertion_sort(ele_list)
| 1 | 6,010,731,860 | null | 10 | 10 |
def resolve():
n = int(input())
a = list(map(int, input().split()))
all_xor = 0
for ai in a:
all_xor ^= ai
ans = []
for ai in a:
ans.append(str(all_xor ^ ai))
print(' '.join(ans))
resolve()
|
from collections import deque
def scan(que, ps, way):
Li = 0
pp = ps
while len(que) > 0:
if way==0:
p = que.popleft()
else:
p = que.pop()
if p < ps:
Li += ps - p
else:
break
pp = p
return Li
if __name__=='__main__':
D = input()
que = deque()
p = 0
for c in D:
que.append(p)
if c == "\\" : p += -1
elif c == "/" : p += 1
que.append(p)
Ll = []
Lr = []
ls = que.popleft()
if len(que) > 0: rs = que.pop()
while len(que) > 0:
while len(que) > 0:
if que[0] < ls:
break
else:
ls = que.popleft()
while len(que) > 0:
if que[-1] < rs:
break
else:
rs = que.pop()
if len(que) > 0:
if ls < rs: Ll.append(scan(que,ls,0))
else : Lr.insert(0,scan(que,rs,1))
L = Ll + Lr
if len(L) > 0:
print(sum(L))
print(len(L), *L)
else:
print(0)
print(0)
| 0 | null | 6,326,123,911,042 | 123 | 21 |
a,*b=[],
for z in[*open(0)][1:]:x,y=map(int,z.split());a+=x+y,;b+=x-y,
print(max(max(a)-min(a),max(b)-min(b)))
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**9
for i in range(M):
x, y, c = map(int, input().split())
if ans > a[x-1] + b[y-1] - c:
ans = a[x-1] + b[y-1] - c
if min(a) + min(b) < ans:
ans = min(a) + min(b)
print(ans)
| 0 | null | 28,804,663,562,052 | 80 | 200 |
# coding: utf-8
while True:
strnum = input().rstrip()
if strnum == "0":
break
answer = sum(map(int, strnum))
print(answer)
|
table = []
i = 0
while True:
table.append(int(input()))
if table[i] == 0:
break
i += 1
for num in table:
if num == 0:
break
sum = 0
i = 0
while num != 0:
sum += num % 10
num //= 10
if num == 0:
break
print(sum)
| 1 | 1,605,865,565,372 | null | 62 | 62 |
n,m = map(int,input().split())
if(n % 2 == 0):
d = n // 2 - 1
c = 0
i = 1
while(d > 0):
print(i,i+d)
d -= 2
i += 1
c += 1
if(c == m):exit()
d = n // 2 - 2
i = n // 2 + 1
while(d > 0):
print(i,i+d)
d -= 2
i += 1
c += 1
if(c == m):exit()
else:
for i in range(m):
print(i+1,n-i)
|
s = input()
if len(s) % 2 == 1:
print('No')
else:
ans = "Yes"
for i in range(len(s)):
if i % 2 == 0 and s[i] != 'h':
ans = "No"
break
if i % 2 == 1 and s[i] != 'i':
ans = "No"
break
print(ans)
| 0 | null | 41,108,305,326,072 | 162 | 199 |
n = int(input())
a_list = list(map(int, input().split()))
ans_list =[0]*n
for i in range(n):
ans_list[a_list[i]-1] = i+1
print(*ans_list)
|
N = int(input())
A = list(map(int, input().split()))
B = list(range(1, N + 1))
A = dict(zip(A, B))
A = sorted(A.items())
ans = [str(x[1]) for x in A]
print(" ".join(ans))
| 1 | 180,579,342,208,188 | null | 299 | 299 |
n = int(input())
k = input()
final = 0
for i in range(0, n - 1):
if k[i] != k[i + 1]:
final += 1
print(final + 1)
|
import itertools
n = int(input())
S = list(input())
L = [k for k, v in itertools.groupby(S)]
print(len(L))
| 1 | 169,741,509,815,780 | null | 293 | 293 |
def give_grade(m, f, r):
if m == -1 or f == -1:
return "F"
elif m + f < 30:
return "F"
elif m + f < 50:
return "D" if r < 50 else "C"
elif m + f < 65:
return "C"
elif m + f < 80:
return "B"
else:
return "A"
while True:
m, f, r = map(int, input().split())
if m == f == r == -1:
break
else:
print(give_grade(m, f, r))
|
while True:
m,f,r=map(int,input().split())
if m==-1 and f==-1 and r==-1:
break
if m==-1 or f==-1:
print('F')
elif m+f>=80:
print('A')
elif 80>(m+f)>=65:
print('B')
elif 65>(m+f)>=50 :
print('C')
elif 50>(m+f)>=30:
if r>=50:
print('C')
else:
print('D')
elif r>=50:
print('C')
elif m+f<30:
print('F')
else:
pass
| 1 | 1,220,700,763,620 | null | 57 | 57 |
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7
S = -X + 2 * Y
T = 2 * X - Y
if S < 0 or T < 0:
print(0)
exit()
if S % 3 != 0 or T % 3 != 0:
print(0)
exit()
S //= 3
T //= 3
def cmb(n, r, p):
r = min(n - r, r)
if r == 0:
return 1
over = 1
for i in range(n, n - r, -1):
over = over * i % p
under = 1
for i in range(1, r + 1):
under = under * i % p
inv = pow(under, p - 2, p)
return over * inv % p
# print(S, T)
ans = cmb(S + T, S, MOD) % MOD
print(ans % MOD)
|
from math import factorial as fac
x,y=map(int,input().split())
a=2*y-x
b=2*x-y
mod=10**9+7
if a>=0 and b>=0 and a%3==0 and b%3==0:
a=a//3
b=b//3
a1=1
a2=1
n3=10**9+7
for i in range(a):
a1*=a+b-i
a2*=i+1
a1%=n3
a2%=n3
a2=pow(a2,n3-2,n3)
print((a1*a2)%n3)
else:
print(0)
| 1 | 150,671,831,481,248 | null | 281 | 281 |
a = int(input())
if a>=400 and a<600:print(8)
elif a>=600 and a<800:print(7)
elif a>=800 and a<1000:print(6)
elif a>=1000 and a<1200:print(5)
elif a>=1200 and a<1400:print(4)
elif a>=1400 and a<1600:print(3)
elif a>=1600 and a<1800:print(2)
elif a>=1800 and a<2000:print(1)
|
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
x = I()
if 599 >= x >= 400:
print(8)
elif 799 >= x >= 600:
print(7)
elif 999 >= x >= 800:
print(6)
elif 1199 >= x >= 1000:
print(5)
elif 1399 >= x >= 1200:
print(4)
elif 1599 >= x >= 1400:
print(3)
elif 1799 >= x >= 1600:
print(2)
elif 1999 >= x >= 1800:
print(1)
return
# Solve
if __name__ == "__main__":
solve()
| 1 | 6,696,415,425,920 | null | 100 | 100 |
n = int(input())
G = [[] for _ in range(n)]
edge = []
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1
b -= 1
G[a].append(b)
edge.append(b)
from collections import deque
q = deque()
color = [0]*n
q.append(0)
while q:
cur = q.popleft()
c = 1
for nx in G[cur]:
if color[cur] == c:
c += 1
color[nx] = c
c += 1
q.append(nx)
print(max(color))
for e in edge:
print(color[e])
|
N = int(input())
G = [[] for n in range(N)]
vc = N*[0]
ec = (N-1)*[0]
h = 1
for n in range(N-1):
a,b = map(int,input().split())
G[a-1].append((b-1,n))
for v,g in enumerate(G):
t = 1
for b,i in g:
if vc[v]==t:
t+=1
vc[b] = t
ec[i] = t
h = max(h,t)
t+=1
print(h)
for n in range(N-1):
print(ec[n])
| 1 | 136,324,745,896,522 | null | 272 | 272 |
#!/usr/bin/env python3
import sys
def cube(x):
if not isinstance(x,int):
x = int(x)
return x*x*x
if __name__ == '__main__':
i = sys.stdin.readline()
print('{}'.format( cube( int(i) ) ))
|
def cubic(x):
return x ** 3
def main():
x = int(input())
y = cubic(x)
return y
print(main())
| 1 | 283,498,778,112 | null | 35 | 35 |
n=int(input())
s=input()
tmp=s[0]
ans=1
for i in range(1,n):
if s[i]!=tmp:
tmp=s[i]
ans+=1
print(ans)
|
import sys
n = int(input())
s = list(input())
if n == 1:
print(1)
sys.exit()
a = []
for i in range(n-1):
if s[i] != s[i+1]:
a.append(s[i])
if len(a) == 0:
print(1)
else:
if a[-1] != s[-1]:
a.append(s[-1])
print(len(a))
| 1 | 170,119,408,848,174 | null | 293 | 293 |
def select_sort(array):
N = len(array)
count = 0
for i in range(N - 1):
min_i = i + array[i:].index(min(array[i:]))
if i != min_i:
count += 1
array[i], array[min_i] = array[min_i], array[i]
return array, count
n = int(input())
array = [int(i) for i in input().split()]
result = select_sort(array)
print(*result[0])
print(result[1])
|
from bisect import bisect
import math
n,k=map(int,input().split())
A=list(map(int,input().split()))
l,r = 0,max(A)
while l < r - 1:
mid = (l+r)//2
cnt = 0
for a in A:
cnt += math.ceil(a/mid) - 1
#print(l,r,mid,cnt,k)
if cnt <= k:
r = mid
else:
l = mid
print(r)
| 0 | null | 3,272,353,277,312 | 15 | 99 |
s = input()
p = input()
if p in s + s:
print('Yes')
else:
print('No')
|
given = input()
target = given*2
keyword = input()
if keyword in target:
print("Yes")
else:
print("No")
| 1 | 1,749,936,261,458 | null | 64 | 64 |
while True:
H, W = map(int, input().split())
if H == W == 0:
break
for _ in range(H):
print('#'*W)
print()
|
while True:
line = input()
data = line.split()
h = int(data[0])
w = int(data[1])
if h == 0 and w == 0:
break
for i in range(h):
for j in range(w):
print("#", end="")
print("")
print("")
| 1 | 796,239,605,300 | null | 49 | 49 |
def cmb(n, r, p):
if r < 0 or n < r:
return 0
r = min(r, n - r)
return fact[n] * fact_inv[r] * fact_inv[n - r] % p
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
p = 10 ** 9 + 7
fact = [1, 1] # fact[n] = (n! mod p)
fact_inv = [1, 1] # fact_inv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # fact_invの計算用
for i in range(2, n + 1):
fact.append(fact[-1] * i % p)
inv.append((-inv[p % i] * (p // i)) % p)
fact_inv.append(fact_inv[-1] * inv[-1] % p)
i = 0
sum_max = 0
sum_min = 0
while n - i - 1 >= k - 1:
cnt = cmb(n - i - 1, k - 1, p)
sum_max += a[i] * cnt
sum_min += a[n - i - 1] * cnt
# print(i, a[i] * cnt, a[n - i - 1] * cnt)
i += 1
ans = (sum_max - sum_min) % p
print(ans)
|
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
class Combination:
"""
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
n,k = inpl()
a = sorted(inpl())
res = 0
comb = Combination(10**5+10)
for i in range(n):
if n-i-1 < k-1: continue
p = comb(n-i-1,k-1)
res -= a[i] * p
res += a[-1-i] * p
res %= mod
print(res)
| 1 | 95,771,973,101,028 | null | 242 | 242 |
while True:
r = list(map(int, input().split()))
if r[0] == -1 and r[1] == -1 and r[2] == -1:
break
elif r[0] == -1 or r[1] == -1:
print("F")
elif r[0] + r[1] >= 80:
print("A")
elif r[0] + r[1] >= 65 and r[0] + r[1] < 80:
print("B")
elif r[0] + r[1] >= 50 and r[0] + r[1] < 65:
print("C")
elif r[0] + r[1] >= 30 and r[0] + r[1] < 50:
if r[2] >= 50:
print("C")
else:
print("D")
else:
print("F")
|
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
a,b = MI()
c,d = MI()
print(1 if d == 1 else 0)
| 0 | null | 62,559,212,597,830 | 57 | 264 |
a=[]
for i in range(3):
a.append(list(map(int, input().split())))
n=int(input())
b=[]
for i in range(n):
b.append(int(input()))
for bingo in b:
for gyou in range(3):
for retu in range(3):
if a[gyou][retu]==bingo:
a[gyou][retu]=True
if a[0][0]==True and a[0][1]==True and a[0][2]==True:
print("Yes")
exit()
elif a[1][0]==True and a[1][1]==True and a[1][2]==True:
print("Yes")
exit()
elif a[2][0]==True and a[2][1]==True and a[2][2]==True:
print("Yes")
exit()
elif a[0][0]==True and a[1][0]==True and a[2][0]==True:
print("Yes")
exit()
elif a[0][1]==True and a[1][1]==True and a[2][1]==True:
print("Yes")
exit()
elif a[0][2]==True and a[1][2]==True and a[2][2]==True:
print("Yes")
exit()
elif a[0][0]==True and a[1][1]==True and a[2][2]==True:
print("Yes")
exit()
elif a[0][2]==True and a[1][1]==True and a[2][0]==True:
print("Yes")
exit()
print("No")
|
#!/usr/bin/env python3
import collections as cl
import sys
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
bingo_num = []
for i in range(3):
N = LI()
bingo_num.append(N)
N = II()
for i in range(N):
b = II()
for row_i in range(3):
for col_j in range(3):
if bingo_num[row_i][col_j] == b:
bingo_num[row_i][col_j] = 0
for i in range(3):
if sum(bingo_num[i]) == 0:
print("Yes")
exit()
for j in range(3):
if bingo_num[0][j] + bingo_num[1][j] + bingo_num[2][j] == 0:
print("Yes")
exit()
sum_naname = 0
sum_naname_2 = 0
for i in range(3):
sum_naname += bingo_num[i][i]
sum_naname_2 += bingo_num[i][2 - i]
if sum_naname == 0 or sum_naname_2 == 0:
print("Yes")
exit()
print("No")
main()
| 1 | 59,509,961,975,900 | null | 207 | 207 |
n, m = map(int, raw_input().split())
ans = []
aa = []
for i in range(n):
a = map(int, raw_input().split())
aa.append(a)
ans.append(0)
b = []
for i in range(m):
a = input()
b.append(a)
for i in range(n):
for j in range(m):
ans[i] += aa[i][j] * b[j]
for i in range(len(ans)):
print(ans[i])
|
n,m = map(int, raw_input().split())
a = []
b = [0]*m
for i in xrange(n):
x = map(int,raw_input().split(" "))
a.append(x)
for i in xrange(m):
b[i] = input()
result = [0]*n
for i in xrange(n):
for j in xrange(m):
result[i] += a[i][j]*b[j]
print result[i]
| 1 | 1,174,892,117,750 | null | 56 | 56 |
S = input()
A = ''
P = 0
for s in range(len(S)):
if P < 3:
A += S[s]
P += 1
print(A)
|
import sys
import numpy as np
N = input()
print(N[0:3])
| 1 | 14,845,726,740,868 | null | 130 | 130 |
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():
# nCrの左項にはn以外も来るバージョン、1!~(n-1)!を保持
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
n, k = ns()
facts, invs = prepare(n, MOD)
ans = 0
for ki in range(min(n, k + 1)):
zero_comb = facts[n] * invs[ki] * invs[n - ki] % MOD
nonzero_comb = facts[n - 1] * invs[ki] * invs[n - 1 - ki] % MOD
ans += zero_comb * nonzero_comb % MOD
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
|
n = int(input())
ss = {}
tt = []
for i in range(n):
s, t = map(str, input().split())
ss[s] = i + 1
tt.append(t)
x = input()
print(sum([int(x) for x in tt[ss[x]:]]))
| 0 | null | 82,150,307,630,898 | 215 | 243 |
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ou=b[0]-a[0]
if ou == 1:
print(1)
elif ou==0:
print(0)
elif ou==1-12:
print(1)
else:
print(0)
|
# coding: utf-8
a , b = map(int,input().split())
c , d = map(int,input().split())
if a + 1 == c:
print(1)
else:
print(0)
| 1 | 124,259,620,072,856 | null | 264 | 264 |
def main():
cands = {'ABC', 'ARC'}
S = input()
cands.discard(S)
print(cands.pop())
if __name__ == '__main__':
main()
|
s = input()
print('ARC' if s[1]=='B' else 'ABC')
| 1 | 24,127,249,404,172 | null | 153 | 153 |
digits = [int(i) for i in list(input())]
Sum = 0
for i in digits:
Sum += i
if Sum%9 == 0:
print("Yes")
else:
print("No")
|
n = sum(map(int, list(input())))
if n%9==0:
print('Yes')
else:
print('No')
| 1 | 4,398,142,242,272 | null | 87 | 87 |
a=list(map(int,input().split()))
if a[0]+a[1]+a[2]>=22:
print("bust")
else:
print("win")
|
N,D,A = map(int,input().split())
XH = [list(map(int,input().split())) for i in range(N)]
XH.sort()
from math import ceil
times = ceil(XH[0][1]/A)
ans = times
damege = [times*A]
coor = [XH[0][0]+2*D]
start = 0
end = 1
dam = sum(damege[start:end])
for i in range(1,N):
st = start
while start < end and coor[start] < XH[i][0]:
start += 1
dam -= sum(damege[st:start])
H = XH[i][1] - dam
if H > 0:
times = ceil(H/A)
ans += times
damege.append(times*A)
dam += times*A
coor.append(XH[i][0]+2*D)
end += 1
print(ans)
| 0 | null | 100,463,591,826,612 | 260 | 230 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.