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
|
---|---|---|---|---|---|---|
# -*- coding: utf-8 -*-
N = int(input())
S = list()
words = {}
for i in range(N):
s = input()
S.append(s)
if s in words:
words[s] += 1
else:
words[s] = 1
max_value = max(words.values())
max_list = list()
for k,v in words.items():
if v == max_value:
max_list.append(k)
ans_list = sorted(max_list)
for ans in ans_list:
print(ans)
|
import sys
input = sys.stdin.readline
import math
def read():
N, K = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
return N, K, A
def solve(N, K, A):
d = [0 for i in range(N+1)]
for k in range(K):
for i in range(N):
d[i] = 0
for i in range(N):
l = max(0, i-A[i])
r = min(N, i+1+A[i])
d[l] += 1
d[r] -= 1
terminate = True
v = 0
for i in range(N):
v += d[i]
A[i] = v
if terminate and A[i] < N:
terminate = False
if terminate:
break
print(*[a for a in A])
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print("%s" % str(outputs))
| 0 | null | 42,587,859,774,790 | 218 | 132 |
a,b,c,k = map(int,input().split())
s = 0
if k <= a:
s = k
elif k <= a + b:
s = a
else:
s = a - (k - a - b)
print(s)
|
# -*- coding: utf-8 -*-
def main():
A, B, C, K = map(int, input().split())
ans = 0
if K <= A:
ans = K
else:
if K <= A + B:
ans = A
else:
ans = A + (-1 * (K - A - B))
print(ans)
if __name__ == "__main__":
main()
| 1 | 21,702,356,443,742 | null | 148 | 148 |
# coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
X, Y, A, B, C = lr()
P = lr(); P.sort(reverse=True)
Q = lr(); Q.sort(reverse=True)
R = lr(); R.sort(reverse=True)
P = P[:X]
Q = Q[:Y]
Z = P + Q + R
Z.sort(reverse=True)
answer = sum(Z[:X+Y])
print(answer)
|
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N = int(input())
i = 1
ans = 0
while i**2<=N:
if N%i==0:
ans = (i+(N//i)-2)
i += 1
print(ans)
| 0 | null | 103,048,268,396,930 | 188 | 288 |
h, w = map(int, input().split())
M = [list(input()) for _ in range(h)]
count = [[int(1e18) for _ in range(w)] for _ in range(h)]
count[0][0] = 1 if M[0][0] == '#' else 0
# 同じ色かどうかを見る
for i in range(h):
for j in range(w):
if i + 1 < h:
v = 1 if M[i][j] != M[i + 1][j] else 0
count[i + 1][j] = min(count[i + 1][j], count[i][j] + v)
if j + 1 < w:
v = 1 if M[i][j] != M[i][j + 1] else 0
count[i][j + 1] = min(count[i][j + 1], count[i][j] + v)
print((count[h - 1][w - 1] + 1) // 2)
|
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans=float("inf")
counter=[[999]*W for _ in range(H)]
def search(i,j,count):
global ans
if counter[i][j]!=999:
ans=min(ans,count+counter[i][j])
return(counter[i][j])
dist=999
if i==H-1 and j==W-1:
ans=min(ans,count)
return 0
countj=count
counti=count
if j<W-1:
if S[i][j]=="." and S[i][j+1]=="#":
countj+=1
dist=search(i,j+1,countj) + (S[i][j]=="." and S[i][j+1]=="#")
if i<H-1:
if S[i][j]=="." and S[i+1][j]=="#":
counti+=1
dist=min(dist,search(i+1,j,counti)+(S[i][j]=="." and S[i+1][j]=="#"))
counter[i][j]=dist
return dist
search(0,0,(S[0][0]=="#")*1)
print(ans)
| 1 | 49,528,643,326,680 | null | 194 | 194 |
import sys
input = sys.stdin.readline
P = 10 ** 9 + 7
def main():
N, K = map(int, input().split())
ans = 0
n_gcd = [0] * (K + 1)
for k in reversed(range(1, K + 1)):
n = pow(K // k, N, mod=P)
for kk in range(2 * k, K + 1, k):
n -= n_gcd[kk]
n_gcd[k] = n % P
ans += k * n_gcd[k]
ans %= P
print(ans)
if __name__ == "__main__":
main()
|
N, K = map(int, input().split())
mod = 10 ** 9 + 7
cnt = [0] * (K + 1)
answer = 0
for i in range(K, 0, -1):
tmp = pow(K // i, N, mod) - sum(cnt[::i])
cnt[i] = tmp
answer = (answer + tmp * i) % mod
print(answer)
| 1 | 36,740,974,612,000 | null | 176 | 176 |
K = int(input())
s = "ACL"
print(s*K)
|
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
S = [0]*(n+1)
for i in range(n):
S[i+1] = S[i] + A[i]
def cnt(x,A,S):
res = 0
for i,a in enumerate(A):
res += bisect.bisect_left(A,x - a)
return res
def ans(x,A,S):
res = 0
for i,a in enumerate(A):
res += a*bisect.bisect_left(A,x-a) + S[bisect.bisect_left(A,x-a)]
return res
top = A[-1]*2+1
bottom = 0
# mid以上が何個あるか
while top - bottom > 1:
mid = (top + bottom)//2
if n*n - cnt(mid,A,S) > m:
bottom = mid
else:
top = mid
print(S[-1]*2*n - ans(top,A,S) + bottom*(m - (n*n - cnt(top,A,S))))
| 0 | null | 55,474,790,256,810 | 69 | 252 |
from collections import defaultdict
n,x,y=map(int,input().split())
x-=1
y-=1
dic=defaultdict(int)
for i in range(n-1):
for j in range(i+1,n):
temp=min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
dic[temp]+=1
for i in range(1,n): print(dic[i])
|
from collections import Counter
N, X, Y = map(int, input().split())
ans = []
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
min_dis = min(abs(j - i),
abs(X - i) + 1 + abs(j - Y),
abs(Y - i) + 1 + abs(j - X))
ans.append(min_dis)
c = Counter(ans)
for i in range(1, N):
print(c[i])
| 1 | 44,154,188,397,378 | null | 187 | 187 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
diff1 = (A1 - B1) * T1
diff2 = (A2 - B2) * T2
if diff1 > 0:
diff1, diff2 = -1 * diff1, -1 * diff2
if diff1 + diff2 < 0:
print(0)
elif diff1 + diff2 == 0:
print('infinity')
else:
q, r = divmod(-diff1, diff1 + diff2)
print(2*q + (1 if r != 0 else 0))
|
s,t = map(int,input().split())
a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
a = a1-b1
b = a2-b2
if a*b>0:print(0);exit()
if abs(a)*s ==abs(b)*t:print('infinity');exit()
elif abs(a)*s >abs(b)*t:print(0);exit()
if (abs(a)*s)%(abs(b)*t-abs(a)*s):
print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2+1)
else:
print(int(abs(a)*s//(abs(b)*t-abs(a)*s))*2)
| 1 | 131,712,565,813,542 | null | 269 | 269 |
H, W, K = map(int, input().split())
c = []
for _ in range(H):
c.append(input())
#こういうinputをすると,c_ij = c[i][j] (C[i]という文字列のj文字目)という構造になってくれて,とても嬉しい。
#print(c)
ans = 0
#bit全探索
for rows in range(1 << H):
#bit演算子。1 << H は二進数で1000...という風に,1の後ろに0がH個並ぶ。
#例えば rows = 110010 のときには,(2 ** 5ケタ目の1は無視して)(0-indexで)1行目と4行目を赤で塗る状態を指す。
for cols in range(1 << W):
black_count = 0
for i in range(H):
if (rows >> i) % 2 == 1:continue #i行目が赤で塗られていたならば,何もせずiを一歩進める。
for j in range(W):
if (cols >> j) % 2 ==1:continue #j列目が赤で塗られていたならば,何もせずjを一歩進める。
if c[i][j] == "#":
black_count += 1
if black_count == K:
ans += 1
print(ans)
|
from collections import deque
n = int(input())
adj = [[]]
for i in range(n):
adj.append(list(map(int, input().split()))[2:])
ans = [-1]*(n+1)
ans[1] = 0
q = deque([1])
visited = [False] * (n+1)
visited[1] = True
while q:
x = q.popleft()
for y in adj[x]:
if visited[y] == False:
q.append(y)
ans[y] = ans[x]+1
visited[y] = True
for j in range(1, n+1):
print(j, ans[j])
| 0 | null | 4,453,648,952,870 | 110 | 9 |
X, K, D=(map(int, input().split()))
X=abs(X)
N=int(X/D)
if N==0:
if K%2==0:
print(X)
else:
print(D-X)
else:
if N>K:
print(X-K*D)
elif (K-N)%2==0:
print(X-N*D)
else:
print((N+1)*D-X)
|
# coding: utf-8
import sys
from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
#import queue# queue,get(), queue.put()
def run():
N = int(input())
current = 0
ways = []
dic = {'(': 1, ')': -1}
SS = read().split()
for S in SS:
path = [0]
for s in S:
path.append(path[-1]+ dic[s])
ways.append((path[-1], min(path)))
ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:x[0], reverse=True)
ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[0] - x[1]), reverse=True)
tmp = []
for go, max_depth in ways_pos:
if current + max_depth >= 0:
current += go
else:
tmp.append((go, max_depth))
for go, max_depth in tmp:
if current + max_depth >= 0:
current += go
else:
print('No')
return None
tmp =[]
for go, max_depth in ways_neg:
if current + max_depth >= 0:
current += go
else:
tmp.append((go, max_depth))
for go, max_depth in tmp:
if current + max_depth >= 0:
current += go
else:
print('No')
return None
if current == 0:
print('Yes')
else:
print('No')
if __name__ == "__main__":
run()
| 0 | null | 14,436,230,079,932 | 92 | 152 |
while True:
m = map(int,raw_input().split())
if m[0] == 0 and m[1] == 0:
break
if m[0] >= m[1]:
print m[1],m[0]
else:
print m[0],m[1]
|
list = []
while True:
line = raw_input().split(" ")
if line[0] == "0" and line[1] == "0":
break
line = map(int, line)
#print line
if line[0] > line[1]:
temp = line[0]
line[0] = line[1]
line[1] = temp
print " ".join(map(str, line))
| 1 | 526,018,864,550 | null | 43 | 43 |
S = str(input())
T = str(input())
count=0
for i in range(len(S)):
if(S[i]==T[i]):
continue
else:
count += 1
print(count)
|
def solve():
a = list(input())
b = list(input())
ans = 0
for i in range(len(a)):
if a[i]!=b[i]:
ans+=1
print(ans)
solve()
| 1 | 10,492,604,531,904 | null | 116 | 116 |
import sys
def resolve(in_):
mod = 1000000007 # 10 ** 9 + 7
n, k = map(int, in_.readline().split())
n += 1
# ans = 0
ans = 1
# while n >= k:
while n > k:
ans += (
((n + (n - k)) * k // 2) % mod -
((1 + k - 1) * k // 2) % mod +
1
) % mod
ans %= mod
k += 1
return ans
def main():
answer = resolve(sys.stdin.buffer)
print(answer)
if __name__ == '__main__':
main()
|
import sys
import math
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
def solve():
a, b, h, m = inl()
t2 = 2 * math.pi * m / 60.0
t1 = 2 * math.pi * (h * 60.0 + m) / (12 * 60.0)
return math.sqrt(a * a + b * b - 2 * a * b * math.cos(t1 - t2))
print(solve())
| 0 | null | 26,640,835,262,452 | 170 | 144 |
from collections import defaultdict
N, X, Y = map(int, input().split())
ctr = defaultdict(int)
for u in range(1, N):
for v in range(u + 1, N + 1):
d = min(v - u, abs(u - X) + 1 + abs(Y - v))
ctr[d] += 1
for n in range(1, N):
print(ctr[n])
|
import math
from math import gcd,pi,sqrt
INF = float("inf")
import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def main():
n, x, y = i_map()
ans = [0] * n
for fr in range(1, n+1):
for to in range(fr+1, n+1):
cost = min(to - fr, abs(x-fr) + abs(to - y) + 1)
ans[cost] += 1
print(*ans[1:], sep="\n")
if __name__=="__main__":
main()
| 1 | 43,981,762,704,442 | null | 187 | 187 |
import math
n = int(input())
debt = 100000
for _ in range(n):
debt = debt * 1.05
debt = math.ceil(debt / 1000) * 1000
print(debt)
|
from math import floor
n = int(input())
def debt(week):
debt = 100000
for i in range(1,n+1):
debt *= 1.05
amari = debt % 1000
if amari:
debt += 1000 - amari
return int(debt)
print(debt(n))
| 1 | 1,162,133,370 | null | 6 | 6 |
n = int(input())
ans, tmp = 0, 5
if n % 2 == 0:
n //= 2
while tmp <= n:
ans += n // tmp
tmp *= 5
print(ans)
|
def solve():
N = int(input())
if N % 2 != 0:
return 0
else:
ans = 0
N //= 10
while N > 0:
ans += N
N //= 5
return ans
print(solve())
| 1 | 116,002,401,148,260 | null | 258 | 258 |
s = str(input())
nikname = s[0:3]
print(nikname)
|
N=int(input())
b=0
for x in range(1,10):
for y in range(1,10):
if x*y==N:
b+=1
break
if b==1:
break
if b==1:
print("Yes")
else:
print("No")
| 0 | null | 87,384,875,202,400 | 130 | 287 |
l = []
while 1:
s = input()
if s == "-": break
for _ in range(int(input())):
h = int(input())
s = s[h:] + s[:h]
l += [s]
for e in l: print(e)
|
n, k = map(int, input().split(' '))
w = [int(input()) for i in range(n)]
max_w = 100000 * 10000
P = 0
left = 0
right = max_w
def check(p):
sum = 0
count = 1
for i in range(n):
if(sum + w[i] > p):
count += 1
sum = w[i]
if(count > k or w[i] > p):
return False
else:
sum += w[i]
return True
while(right - left > 1):
mid = (left + right) // 2
if(check(mid)):
right = mid
P = mid
else:
left = mid
print(P)
| 0 | null | 978,127,362,112 | 66 | 24 |
case = 0
while 1:
case += 1
n = int(input())
if n == 0: break
print("Case {}: {}".format(case, n))
|
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import defaultdict
from collections import Counter
import bisect
from functools import reduce
def main():
H, N = MI()
A = LI()
A_sum = sum(A)
if A_sum >= H:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main()
| 0 | null | 39,084,402,205,610 | 42 | 226 |
def comb_mod(n,r):
mod = 10**9+7
ans = 1
for i in range(r):
ans *= n-i
ans %= mod
for i in range(1,r+1):
ans *= pow(i,-1,mod)
ans %= mod
return ans
def solve():
n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2,n,mod)-comb_mod(n,a)-comb_mod(n,b)-1
ans %= mod
return ans
print(solve())
|
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
N = min(n, 2 * 10**5)
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def comb(n, r):
return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
for i in range(2, N + 1):
fac.append( ( fac[-1] * i ) % mod )
inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
finv.append( finv[-1] * inv[-1] % mod )
def frac_rev(n, r):
x = 1
for i in range(n, n-r, -1):
x = x * i % mod
return x
if n <= 2 * 10**5:
print(( pow(2, n, mod) - 1 - comb(n, a) -comb(n, b) ) % mod)
else:
print(( pow(2, n, mod) - 1 - frac_rev(n, a) * finv[a] % mod - frac_rev(n, b) * finv[b] % mod) % mod)
| 1 | 66,558,100,106,752 | null | 214 | 214 |
def main():
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for answer in calc(n, x, y):
print("{:.6f}".format(answer))
def calc(n, x, y):
ret = []
patterns = [1, 2, 3]
for pattern in patterns:
sum = 0
for i in range(0, n):
sum += (abs(x[i] - y[i])) ** pattern
ret.append(sum ** (1 / pattern))
last = 0
for i in range(0, n):
last = max(last, abs(x[i] - y[i]))
ret.append(last)
return ret
if __name__ == "__main__":
main()
|
s = input()
S = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7-S.index(s))
| 0 | null | 66,667,636,459,190 | 32 | 270 |
n,m=map(int,input().split())
s,l=input(),[]
while n>0:
for i in range(m,0,-1):
if i<=n and s[n-i]=="0":l.append(i);n-=i;break
else:exit(print(-1))
print(*l[::-1])
|
import sys
#input = sys.stdin.buffer.readline
def main():
N,M = map(int,input().split())
s = str(input())
s = list(reversed(s))
ans = []
now = 0
while now < N:
for i in reversed(range(min(M,N-now))):
i += 1
if s[now+i] == "0":
now += i
ans.append(i)
break
if i == 1:
print(-1)
exit()
print(*reversed(ans))
if __name__ == "__main__":
main()
| 1 | 139,015,745,520,928 | null | 274 | 274 |
N = int(input())
print(10 - N//200)
|
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
x = inp()
if x < 600:
ans = 8
elif x < 800:
ans = 7
elif x < 1000:
ans = 6
elif x < 1200:
ans = 5
elif x < 1400:
ans = 4
elif x < 1600:
ans = 3
elif x < 1800:
ans = 2
elif x < 2000:
ans = 1
print(ans)
| 1 | 6,687,520,120,710 | null | 100 | 100 |
mozi = input()
kazu = int(ord(mozi))
if 65 <= kazu < 91:
print('A')
else:
print('a')
|
import math
def make_stu(p1, p2):
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 = [s[0] + (t[0] - s[0]) / 2 - math.sqrt(3) * (t[1] - s[1]) / 2,
s[1] + (t[1] - s[1]) / 2 + math.sqrt(3) * (t[0] - s[0]) / 2]
return s, t, u
def koch_curve(n, p1, p2):
if n >= 1:
s, t, u = make_stu(p1, p2)
if n == 1:
print(s[0], s[1])
print(u[0], u[1])
print(t[0], t[1])
else:
koch_curve(n - 1, p1, s)
print(s[0], s[1])
koch_curve(n - 1, s, u)
print(u[0], u[1])
koch_curve(n - 1, u, t)
print(t[0], t[1])
koch_curve(n - 1, t, p2)
n = int(input())
print(0.0, 0.0)
koch_curve(n, [0.0, 0.0], [100.0, 0.0])
print(100.0, 0.0)
| 0 | null | 5,696,977,968,462 | 119 | 27 |
import sys
readline = sys.stdin.readline
SET = set()
for _ in range(int(readline())):
c, s = readline().split()
if c == "insert":
SET.add(s)
elif c == "find":
print("yes" if s in SET else "no")
|
#!/usr/bin/env python3
hight = []
for i in range(10):
hight.append(int(input()))
hight = sorted(hight, reverse=True)
for i in range(3):
print(hight[i])
| 0 | null | 41,122,986,492 | 23 | 2 |
n,k=map(int,input().split())
p=[0]+list(map(int,input().split()))
for i in range(n+1):
p[i]=(p[i]+1)/2
for i in range(n):
p[i+1]+=p[i]
ans=0
for i in range(n-k+1):
ans=max(ans,p[i+k]-p[i])
print(ans)
|
N, K = map(int, input().split())
p = list(map(int, input().split()))
def calc(x):
return (x+1)/2
pe = []
for i in range(N):
pe.append(calc(p[i]))
cs = [pe[0]] + [0]*(N-1)
for i in range(1, N):
cs[i] = pe[i] + cs[i-1]
ans = cs[K-1]
for i in range(K, N):
wa = cs[i] - cs[i-K]
ans = max(ans, wa)
print(ans)
| 1 | 74,972,138,062,690 | null | 223 | 223 |
H,W = map(int,input().split())
map = []
INF = 10**8
for _ in range(H):
map.append(input())
dp = [[0 for i in range(W)] for i in range(H)]
for i in range(H):
for j in range(W):
if i == 0 and j == 0:
if map[i][j] == '#':
dp[i][j] = 1
elif i == 0:
flag = 0
if map[i][j] == '#' and map[i][j-1] == '.':
flag = 1
dp[i][j] = flag + dp[i][j-1]
elif j == 0:
flag = 0
if map[i][j] == "#" and map[i-1][j] == ".":
flag = 1
dp[i][j] = flag + dp[i-1][j]
else:
flag1 = 0
flag2 = 0
if map[i][j] == "#" and map[i][j-1] == ".":
flag1 = 1
if map[i][j] == "#" and map[i-1][j] == ".":
flag2 = 1
dp[i][j] = min(dp[i][j-1]+flag1,dp[i-1][j]+flag2)
print(dp[H-1][W-1])
|
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])
| 1 | 49,338,308,080,638 | null | 194 | 194 |
print(0 if int(input()) else 1)
|
n = int(input())
ans = [0] * 10010
def get_ans(n):
cnt = 0
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
k = x**2 + y**2 + z**2 + x*y + y*z + z*x
if(k <= 10000):
ans[k] += 1
return ans
ans = get_ans(n)
for i in range(1, n+1):
print(ans[i])
| 0 | null | 5,426,154,668,700 | 76 | 106 |
n = [int(x) for x in input().split()]
for i in range(len(n)):
if n[i] == 0:
print(i + 1)
break
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
x = list(map(int, input().split()))
for i in range(1,6):
if x[i-1]!=i:
print(i)
| 1 | 13,514,472,352,432 | null | 126 | 126 |
s = input()
if s[-1] == 's':
s = s + "es"
else:
s = s + 's'
print(s)
|
S = input()
n = len(S)
S_a = list(S)
if S[n-1] == 's' :
print(S + 'es')
else :
print(S + 's')
| 1 | 2,401,117,827,560 | null | 71 | 71 |
S = input()
if S == 'SUN':
answer = 7
elif S == 'MON':
answer = 6
elif S == 'TUE':
answer = 5
elif S == 'WED':
answer = 4
elif S == 'THU':
answer = 3
elif S == 'FRI':
answer = 2
elif S == 'SAT':
answer = 1
else:
answer = '入力間違い【SUN】【MON】【TUE】【WED】【THU】【FRI】【SAT】を入力'
print(answer)
|
S = input()
week = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
if S == week[0]:
print(7)
elif S == week[1]:
print(6)
elif S == week[2]:
print(5)
elif S == week[3]:
print(4)
elif S == week[4]:
print(3)
elif S == week[5]:
print(2)
else:
print(1)
| 1 | 133,160,839,463,948 | null | 270 | 270 |
x = input()
while 1:
sum_x = 0
if x == "0":
break
for c in x:
sum_x += int(c)
print(sum_x)
x = input()
|
N, M = map(int, input().split())
H = [0] + list(map(int, input().split()))
g = [[] for _ in range(N+1)]
for i in range(M):
a, b = map(int, input().split())
g[a].append(b)
g[b].append(a)
ans = 0
for j in range(1, N+1):
for k in g[j]:
if H[j] <= H[k]:
break
else:
ans += 1
print(ans)
| 0 | null | 13,451,146,142,308 | 62 | 155 |
S = input()
T = input()
ans = 0
for i in range(len(S)):
if S[i] == T[i]:
continue
ans += 1
print(ans)
|
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
array_sum = sum(a) % mod
ans = 0
for i in range(n):
ans += a[i] * array_sum % mod
ans -= a[i] * a[i] % mod
print((ans * pow(2,-1,mod)) % mod)
| 0 | null | 7,092,228,518,100 | 116 | 83 |
x, y = map(int, input().split())
for a in range(0, 101):
for b in range(0, 101):
if a + b == x and 2*a + 4*b == y:
print('Yes')
exit()
print('No')
|
x, y = map(int, input().split())
for i in range(x+1):
for j in range(x+1):
if i+j == x:
if 2*i + 4*j == y:
print('Yes')
exit()
print('No')
| 1 | 13,822,231,029,568 | null | 127 | 127 |
a, b = map(int, input().split())
(x, y) = (a, b) if a<=b else (b, a)
for _ in range(y):
print(x, end='')
|
a,b= input().split()
print(str(min(int(a),int(b)))*int(str(max(int(a),int(b)))))
| 1 | 83,918,356,158,780 | null | 232 | 232 |
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
s = [int(i) for i in s.split(",")]
print(s[int(input())-1])
|
# -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
numbers = [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]
k = int(input())
print(numbers[k - 1])
if __name__ == '__main__':
main()
| 1 | 50,163,594,304,192 | null | 195 | 195 |
n = int(input())
cl = str(input())
cl_R = cl.count("R")
# print(cl_R)
cl_leftR = cl[:cl_R].count("R")
# print(cl_leftR)
print(cl_R-cl_leftR)
|
N,M=list(map(int,input().split()))
E={i:[] for i in range(1,N+1)}
for i in range(M):
a,b=list(map(int,input().split()))
E[a].append(b)
E[b].append(a)
V={i:0 for i in range(1,N+1)}
W=[1]
while W!=[]:
S=[]
for a in W:
for b in E[a]:
if V[b]==0:
V[b]=a
S.append(b)
W=S
if -1 in V:
print('No')
else:
print('Yes')
for i in range(2,N+1):
print(V[i])
| 0 | null | 13,426,172,496,998 | 98 | 145 |
n=int(input())
a=input()
if n%2!=0:
print('No')
exit()
t1=a[0:int(n/2)]
t2=a[int(n/2):n]
if t1==t2:
print('Yes')
else:
print('No')
|
n = int(input())
s = input()
t = s[:int(n / 2)]
if s == t + t:
print('Yes')
else:
print('No')
| 1 | 146,962,592,194,130 | null | 279 | 279 |
from decimal import *
import math
a, b = map(str, input().split())
print(math.floor(Decimal(a)*Decimal(b)))
|
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
for j in range(i-1, 0, -1):
a, b = L[i], L[j]
c = a - b + 1
if c > b: continue
ans += (j - bisect.bisect_left(L, c))
print(ans)
| 0 | null | 94,046,048,518,320 | 135 | 294 |
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = int(input())
a=lcm(num1,360)
b=a/num1
print(int(b))
|
import sys
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
for line in sys.stdin:
line = line.strip()
if line == "":
break
X = int(line)
ans = 360 // gcd(X, 360)
print(ans)
| 1 | 13,158,525,150,720 | null | 125 | 125 |
import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]
INF = 10**20
g = [[INF]*N for _ in range(N)]
for a,b,c in ABC:
a,b = a-1,b-1
g[a][b] = g[b][a] = c
for i in range(N):
g[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if g[i][j] > g[i][k] + g[k][j]:
g[i][j] = g[i][k] + g[k][j]
h = [[N]*N for _ in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if g[i][j] <= L:
h[i][j] = h[j][i] = 1
for i in range(N):
h[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if h[i][j] > h[i][k] + h[k][j]:
h[i][j] = h[i][k] + h[k][j]
ans = []
for s,t in ST:
s,t = s-1,t-1
if h[s][t] == N:
ans.append(-1)
else:
ans.append(h[s][t] - 1)
print(*ans, sep='\n')
|
import sys,collections as cl,bisect as bs
Max = 10**18
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return map(int,input().split())
def onem(): #Nとかの取得
return int(input())
def wa(d):
for k in range(len(d)):
for i in range(len(d)):
for j in range(len(d)):
d[i][j] = min(d[i][j],d[i][k]+d[k][j])
return d
def on():
N,M,L = m()
e = [[Max for i in range(N)]for j in range(N)]
for i in range(M):
a,b,c = m()
e[a-1][b-1] = c
e[b-1][a-1] = c
for i in range(N):
e[i][i] = 0
d = wa(e)
E = [[Max for i in range(N)]for j in range(N)]
for i in range(N):
for j in range(N):
if d[i][j] <= L:
E[i][j] = 1
for i in range(N):
E[i][i] = 0
E = wa(E)
q = onem()
for i in range(q):
s,t = m()
if E[s-1][t-1] == Max:
print(-1)
else:
print(E[s-1][t-1]-1)
if __name__ == "__main__":
on()
| 1 | 173,929,753,504,202 | null | 295 | 295 |
s,t=list(input().split())
a,b=list(map(int,input().split()))
u=input()
if u==s:
print(str(a-1)+" "+str(b))
else:
print(str(a)+" "+str(b-1))
|
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF = float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353
A = map(int, input().split())
if sum(A) >= 22:
print("bust")
else:
print("win")
| 0 | null | 95,329,437,559,030 | 220 | 260 |
import numpy as np
n,m,k = list(map(int, input().split()))
a_list = np.array(input().split()).astype(int)
b_list = np.array(input().split()).astype(int)
a_sum =[0]
b_sum=[0]
for i in range(n):
a_sum.append(a_sum[-1]+ a_list[i])
for i in range(m):
b_sum.append(b_sum[-1] + b_list[i])
#print(a_sum, b_sum)
total = 0
num = m
for i in range(n+1):
if a_sum[i] > k:
break
while (k - a_sum[i]) < b_sum[num]:
num -=1
#print(i, num)
if num == -1:
break
total = max(i+num, total)
print(total)
|
n = int(input())
S = list(map(int, input().split()))
def merge(A, left, mid, right):
cnt = 0
n1 = mid - left
n2 = right - mid
L = [0]*(n1+1)
R = [0]*(n2+1)
for i in range(n1):
L[i] = A[left + i]
for i in range(n2):
R[i] = A[mid + i]
L[n1] = float("inf")
R[n2] = float("inf")
i = 0
j = 0
for k in range(left, right):
cnt += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
return cnt
def merge_sort(A, left, right):
if left + 1 < right:
mid = (left + right)//2
cnt_left = merge_sort(A, left, mid)
cnt_right = merge_sort(A, mid, right)
cnt_merge = merge(A, left, mid, right)
cnt = cnt_left + cnt_right + cnt_merge
else:
cnt = 0
return cnt
cnt = merge_sort(S, 0, n)
print(' '.join( map(str, S) ))
print(cnt)
| 0 | null | 5,365,196,659,270 | 117 | 26 |
k=int(input())
a,b=map(int,input().split())
count=a
while count <= b:
if count%k == 0:
print("OK")
break
else:
count += 1
else:
print("NG")
|
S = int(input())
q , mod = divmod(S , 2)
print(q+mod)
| 0 | null | 42,739,421,555,532 | 158 | 206 |
N, A, B = map(int, input().split())
ans = 0
if (B-A)%2 == 0:
print((B-A)//2)
else:
if A-1 < N-B:
ans += A-1
else:
ans += N-B
ans += 1
ans += (B-A-1)//2
print(ans)
|
a,b,c = (int(a) for a in input().split())
if a == b == c or (a != b and b != c and c != a) :
print("No")
else : print("Yes")
| 0 | null | 88,546,124,834,988 | 253 | 216 |
import math
X = int(input())
if X >= math.ceil((X % 100) / 5) * 100:
print(1)
else:
print(0)
|
x = int(input())
price = [100, 101, 102, 103, 104, 105]
dp = [False for _ in range(x + 1)]
dp[0] = True
for i in range(1, x + 1):
for j in range(6):
if i - price[j] >= 0:
if dp[i - price[j]]:
dp[i] = True
break
else:
dp[i] = False
if dp[x]:
print(1)
else:
print(0)
| 1 | 127,013,813,235,738 | null | 266 | 266 |
n = int(input())
print(int(n/2)) if n%2 == 0 else print(int(n/2+1))
|
# coding: utf-8
# Your code here!
import math
S = int(input())
if S%2==0:
print(int(S/2))
else:
print(int(S//2)+1)
| 1 | 59,368,935,073,758 | null | 206 | 206 |
N, K = [int(i) for i in input().split()]
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))
)
memo = [-1] * K
def count(k):
if(memo[k-1] != -1):
return memo[k-1]
if(k > K//2):
memo[k-1] = ModInt(1)
return memo[k-1]
res = ModInt(K//k) ** N
for i in range(2, K//k + 1):
res -= count(i * k)
memo[k-1] = res
return res
ans = 0
for k in range(K, 0, -1):
ans += count(k) * k
print(ans)
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# E - Sum of gcd of Tuples (Hard)
n, k = map(int, input().split())
modulus = 10 ** 9 + 7
def expt(x, k):
"""(x ** k) % modulus"""
p = 1
for b in (bin(k))[2:]:
p = p * p % modulus
if b == '1':
p = p * x % modulus
return p
# iの倍数をn個並べた列の個数
nseq = [expt((k // i), n) if i > 0 else None for i in range(k + 1)]
for i in range(k, 0, -1):
# iの2倍以上の倍数からなる列の個数を引く
s = sum(nseq[m] for m in range(2 * i, k + 1, i))
nseq[i] = (nseq[i] - s % modulus + modulus) % modulus
# nseq[i]はgcd==iになる列の個数
ans = sum(i * nseq[i] % modulus for i in range(1, k + 1))
print(ans % modulus)
| 1 | 37,015,302,451,052 | null | 176 | 176 |
def main():
s = input()
ans=""
for i in range(0,len(s)):
ans+='x'
print(ans)
main()
|
s = input()
print('x'*len(s))
| 1 | 73,106,350,134,750 | null | 221 | 221 |
import math
n = int(input())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
D1 = 0
d2 = 0
d3 = 0
dm =[]
for i in range(n):
D1 += abs(x[i]-y[i])
d2 += (abs(x[i]-y[i]))**2
d3 += (abs(x[i]-y[i]))**3
m = abs(x[i]-y[i])
dm.append(m)
D2 = math.sqrt(d2)
D3 = d3 ** (1/3)
Dm = max(dm)
print(f'{D1:.06f}')
print(f'{D2:.06f}')
print(f'{D3:.06f}')
print(f'{Dm:.06f}')
|
from collections import deque
import sys
deq = deque()
q = int(input())
for _ in range(q):
s = input()
if s == 'deleteFirst':
deq.popleft()
elif s == 'deleteLast':
deq.pop()
else:
ss, num = s.split()
if ss == 'insert':
deq.appendleft(num)
else:
try:
deq.remove(num)
except:
pass
print(" ".join(deq))
| 0 | null | 132,064,901,540 | 32 | 20 |
N = int(input())
X = [list(map(int,input().split())) for _ in range(N)]
A = sorted([X[i][0] for i in range(N)])
B = sorted([X[i][1] for i in range(N)])
if N%2==1:
a = A[N//2]
b = B[N//2]
print(b-a+1)
else:
a = (A[(N-1)//2]+A[N//2])/2
b = (B[(N-1)//2]+B[N//2])/2
print(int((b-a)/0.5)+1)
|
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019
t = [0]
r = 1
for i in range(len(S)):
q = (t[-1] + (int(S[i]) * r)) % MOD
t.append(q)
r *= 10
r %= MOD
cnt = Counter(t)
cnt_mc = cnt.most_common()
ans = 0
for _, j in cnt_mc:
if j >= 2:
ans += j * (j - 1) // 2
print(ans)
| 0 | null | 24,192,284,371,140 | 137 | 166 |
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)
def main():
n = int(input())
a = [(int(v), i) for i, v in enumerate(input().split())]
a.sort(reverse=True)
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = a[0][0] * (n - 1 - a[0][1])
dp[0][1] = a[0][0] * a[0][1]
for i, v in enumerate(a[1:]):
dp[i+1][0] = dp[i][0] + v[0] * abs(n - 1 - (i + 1) - v[1])
dp[i+1][i+2] = dp[i][i+1] + v[0] * abs(v[1] - (i + 1))
for j in range(1, i + 2):
dp[i+1][j] = max(
dp[i][j] + v[0] * abs(n - 1 - (i + 1) + j - v[1]),
dp[i][j-1] + v[0] * abs(v[1] - (j - 1)))
ans = -float('inf')
for i in dp[n-1]:
ans = max(ans, i)
print(ans)
main()
|
import sys
N = int(input())
array = list(map(int,input().split()))
if not ( 1 <= N <= 100 ): sys.exit()
if not ( 1 <= min(array) and max(array) <= 1000 ): sys.exit()
for I in array:
if I % 2 == 0 and not ( I % 3 == 0 or I % 5 == 0 ):
print('DENIED')
sys.exit()
print('APPROVED')
| 0 | null | 51,132,519,789,248 | 171 | 217 |
A, B = input().split()
print(int(A)*int(B) if len(A) == len(B) == 1 else -1)
|
in1 = input().split()
A = int(in1[0])
B = int(in1[1])
if A>=1 and B>=1 and A<=9 and B<=9:
print (A*B)
else:
print(-1)
| 1 | 157,603,708,204,030 | null | 286 | 286 |
from collections import Counter
N=int(input())
list1=list(map(int,input().split()))
dic1=Counter(list1)
def choose2(n):
return n*(n-1)/2
sum=0
for key in dic1:
sum+=choose2(dic1[key])
for i in list1:
print(int(sum-dic1[i]+1))
|
# C - Replacing Integer
n,k = map(int,input().split())
m = n % k
l = map(abs,[m-k,m,m+k])
print(min(l))
| 0 | null | 43,457,357,263,166 | 192 | 180 |
X=int(input())
while True:
flg = True
for i in range(2,int(X**1/2)+1):
if X%i == 0:
flg = False
break
if flg == True:
print(X)
break
else:
X += 1
|
mod = 10**9 + 7
n = int(input())
dat = list(map(int, input().split()))
cnt0 = [0] * 64
cnt1 = [0] * 64
for i in range(n):
for j in range(62):
if ((dat[i] >> j) & 1) == 1:
cnt1[j] += 1
else:
cnt0[j] += 1
#print(cnt0)
#print(cnt1)
res = 0
for i in range(62):
res += (cnt0[i] * cnt1[i]) << i
res %= mod
print(res)
| 0 | null | 113,944,589,650,440 | 250 | 263 |
S = input()
if len(S)//2 * "hi" == S:
print("Yes")
else:
print("No")
|
S = input()
if S.count("hi")*2 == len(S):
print("Yes")
else:
print("No")
| 1 | 53,085,035,068,622 | null | 199 | 199 |
print(*set([input(),input()])^set([*'123']))
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mia, pla = [], []
for ai in a:
if ai < 0:
mia.append(ai)
elif ai >= 0:
pla.append(ai)
mia.sort(reverse=True)
pla.sort()
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt *= mia.pop()
elif len(pla) > 0:
cnt *= pla.pop()
k -= 1
elif len(pla) <= 1:
cnt *= mia.pop() * mia.pop()
k -= 2
elif len(pla) >= 2 and len(mia) >= 2:
if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt *= pla.pop()
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt *= mia.pop() * mia.pop()
k -= 2
cnt %= mod
print(cnt)
| 0 | null | 60,112,431,437,282 | 254 | 112 |
h,w,m=map(int,input().split())
HH=[]
WW=[]
HW=set()
lh=[0]*(h+1)
lw=[0]*(w+1)
for _ in range(m):
h1,w1=map(int,input().split())
lh[h1]+=1
lw[w1]+=1
HW.add((h1,w1))
lhmax=max(lh)
lwmax=max(lw)
maxh=[]
maxw=[]
for i in range(1,h+1):
if lh[i]==lhmax:
maxh.append(i)
for i in range(1,w+1):
if lw[i]==lwmax:
maxw.append(i)
if len(maxh)*len(maxw)>m:
print(lhmax+lwmax)
else:
flag=True
for i in maxh:
for j in maxw:
if (i,j) not in HW:
flag=False
break
if flag==True:
print(lhmax+lwmax-1)
else:
print(lhmax+lwmax)
|
Ds = ['SUN','MON','TUE','WED','THU','FRI','SAT']
Ss = input().rstrip()
ans = 7 - Ds.index(Ss)
print(ans)
| 0 | null | 68,642,765,051,064 | 89 | 270 |
# coding: utf-8
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 9)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = lr()
INF = 10 ** 17
@lru_cache(None)
def F(index, n):
if index >= N:
return -INF
if N - index < 2 * n - 1:
return -INF
if n == 0:
return 0
elif n == 1:
return max(A[index:])
ret = max(A[index] + F(index+2, n-1), F(index+1, n))
return ret
answer = F(0, N//2)
print(answer)
|
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
K = 1+N%2
dp = [[-10**18]*(K+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
for j in range(K+1):
if j+1<=K:
dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j])
dp[i+1][j] = max(dp[i+1][j], dp[i][j]+(A[i] if (i+j)%2==0 else 0))
print(dp[N][K])
| 1 | 37,242,433,923,842 | null | 177 | 177 |
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)
|
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
v = A[i]
j = i - 1
while j >= 0 and A[j] > v:
A[j+1] = A[j]
j -= 1
A[j+1] = v
print(" ".join(map(str, A)))
| 1 | 5,710,767,520 | null | 10 | 10 |
s = input()
print(s[:3].lower())
|
nm = input()
print(nm[:3])
| 1 | 14,795,561,339,460 | null | 130 | 130 |
r = int(input()) % 1000
print((1000 - r) % 1000)
|
import math
N = int(input())
for i in range(N+1):
if math.floor(1.08 * i) == N:
print(i)
exit()
print(":(")
| 0 | null | 67,078,970,431,680 | 108 | 265 |
import math
a, b, c, d = map(float, input().split())
s1 = (a - c) * (a - c)
s2 = (b - d) * (b - d)
print("%.6f"%math.sqrt(s1+s2))
|
def main():
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
d=[0]*(10**5 +1)#各数字の個数
for i in A:
d[i]+=1
for i in range(Q):
B,C=map(int,input().split())
s += (C-B)*d[B]
print(s)
d[C]+=d[B]
d[B]=0
if __name__ == "__main__":
main()
| 0 | null | 6,108,383,824,752 | 29 | 122 |
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 割引券を使用しない場合は各品の最低金額合計が解となる
ans = min(a) + min(b)
# 割引券を使用して安くなるケースがないか調べる
for _ in range(M):
x, y, c = map(int, input().split())
tmp = a[x-1] + b[y-1] - c
if tmp < ans:
ans = tmp
print(ans)
|
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 999999
for i in range(M):
x, y, c = map(int, input().split())
if x <= A and y <= B:
d = a[x - 1] + b[y - 1] - c
if d < ans:
ans = d
if (min(a) + min(b)) < ans:
ans = min(a) + min(b)
print(ans)
| 1 | 54,229,942,549,430 | null | 200 | 200 |
n = [int(x) for x in input().split()]
for i in range(len(n)):
if n[i] == 0:
print(i + 1)
break
|
a = raw_input().lower()
s = 0
while True:
b = raw_input()
if b == 'END_OF_TEXT':
break
b = b.split()
b = map(str.lower,b)
s += b.count(a)
print s
| 0 | null | 7,616,965,414,540 | 126 | 65 |
N,P = map(int,input().split())
S = input()
def solve(S,N,P):
if P == 2:
ans = 0
for i in range(N):
if int(S[i])%P == 0:
ans += i+1
return ans
if P == 5:
ans = 0
for i in range(N):
if int(S[i])%P == 0:
ans += i+1
return ans
S = S[::-1]
mod_list = [0]*P
mod_list[0] = 1
mod = P
tmp = 0
for i in range(N):
tmp = (tmp + int(S[i])*pow(10,i,mod))%mod
mod_list[tmp] += 1
ans = 0
for i in mod_list:
ans += i*(i-1)//2
return ans
print(solve(S,N,P))
|
from math import gcd
from collections import defaultdict
N, P = map(int, input().split())
S = list(map(int, input()))
answer = 0
if P == 2 or P == 5: # Case when only last digit matters
for j in range(N - 1, -1, -1): # Enumerate right endpoint
if S[j] % P == 0:
answer += j + 1
else:
# Enuerate left endpoint from right to left
# Find number of right endpoints that make the substr % P == 0
cnts = defaultdict(int)
suffix = 0
base = 1
for i in range(N - 1, -1, -1):
suffix = (suffix + S[i] * base) % P
answer += cnts[suffix] # Substr with length >= 2
answer += 1 if suffix == 0 else 0 # Substr with length = 1
cnts[suffix] += 1
base = base * 10 % P
print(answer)
| 1 | 58,305,648,798,372 | null | 205 | 205 |
## coding: UTF-8
N, P = map(int,input().split())
S = input()[::-1]
remainder = [0] * P
tmp = 0
rad = 1 #10**(i) % P
'''
if(P == 2 or P == 5):
for i in range(N):
r = int(S[i])
tmp += r * rad
tmp %= P
remainder[tmp] += 1
rad *= 10
'''
if(P == 2):
ans = 0
for i in range(N):
r = int(S[i])
if(r % 2 == 0):
ans += N-i
print(ans)
elif(P == 5):
ans = 0
for i in range(N):
r = int(S[i])
if(r % 5 == 0):
ans += N-i
print(ans)
else:
for i in range(N):
r = int(S[i])
tmp += r * rad
tmp %= P
remainder[tmp] += 1
rad *= 10
rad %= P
remainder[0] += 1
#print(remainder)
ans = 0
for i in range(P):
e = remainder[i]
ans += e*(e-1)/2
print(int(ans))
|
x = int(input())
a = x // 100
b = x - a * 100
while b > 5:
b = b - 5
a -= 1
if a>=1:
print(1)
else:
print(0)
| 0 | null | 92,754,639,608,320 | 205 | 266 |
S = input()
List = {'ABC':'ARC', 'ARC':'ABC'}
print(List[S])
|
A = input()
B = input()
answer = [str(i) for i in range(1, 4)]
answer.remove(A)
answer.remove(B)
print(''.join(answer))
| 0 | null | 67,720,577,778,720 | 153 | 254 |
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
xor = 0
for x in a:
xor ^= x
for x in a:
print(xor^x,end=' ')
print()
|
N = int(input())
aaa = [int(i) for i in input().split()]
sumxor = 0
for a in aaa:
sumxor = sumxor^a
bbb = [a^sumxor for a in aaa]
print(" ".join([str(b) for b in bbb]))
| 1 | 12,612,013,916,350 | null | 123 | 123 |
import sys
#f = open("test.txt", "r")
f = sys.stdin
num_rank = 14
s_list = [False] * num_rank
h_list = [False] * num_rank
c_list = [False] * num_rank
d_list = [False] * num_rank
n = f.readline()
n = int(n)
for i in range(n):
[suit, num] = f.readline().split()
num = int(num)
if suit == "S":
s_list[num] = True
elif suit == "H":
h_list[num] = True
elif suit == "C":
c_list[num] = True
else:
d_list[num] = True
for i in range(1, num_rank):
if not s_list[i]:
print("S " + str(i))
for i in range(1, num_rank):
if not h_list[i]:
print("H " + str(i))
for i in range(1, num_rank):
if not c_list[i]:
print("C " + str(i))
for i in range(1, num_rank):
if not d_list[i]:
print("D " + str(i))
|
"""
keyword: ラジアン, 度
最大限傾けたとき、水と接している面は横から見ると台形ないし三角形となる
水と接している面の面積 x/a が a*b/2 より大きい場合は台形となり、それ以下の場合は三角形となる
・台形の場合
最大限傾けたとき、水と接している台形の上辺の長さをhとすると
(h+b)*a/2 = x/a
h = 2*x/(a**2) - b
求める角度をthetaとすると
tan(theta) = (b-h)/a
theta = arctan((b-h)/a)
・三角形の場合
最大限傾けたとき、水と接している三角形の底辺の長さをhとすると
h*b/2 = x/a
h = 2*x/(a*b)
求める角度をthetaとすると
tan(theta) = b/h
theta = arctan(b/h)
"""
import sys
sys.setrecursionlimit(10**6)
a,b,x = map(int, input().split())
import numpy as np
if x/a > a*b/2:
h = 2*x/(a**2) - b
theta = np.arctan2(b-h, a) # radian表記なので戻り値の範囲は[-pi/2, pi/2]
theta = np.rad2deg(theta)
else:
h = 2*x/(a*b)
theta = np.arctan2(b, h)
theta = np.rad2deg(theta)
print(theta)
| 0 | null | 82,144,884,863,960 | 54 | 289 |
W = input().lower()
count = 0
while True:
a = input()
if a == "END_OF_TEXT":
break
a = a.lower()
a = a.split()
for i in range(len(a)):
if W == a[i]:
count += 1
print(count)
|
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
T = []
for i in range(N):
T.append(A[i]*F[i])
s = -1
l = 10**12
while(l-s > 1):
mid = (l-s)//2 + s
c = 0
for i in range(N):
if T[i] > mid:
if (T[i] - mid) % F[i] == 0:
c += (T[i] - mid) // F[i]
else:
c += (T[i] - mid) // F[i] + 1
if c > K:
s = mid
else:
l = mid
print(l)
| 0 | null | 83,000,115,849,740 | 65 | 290 |
H, W = map(int, input().split())
if (H==1 or W==1):
print(1)
elif (H%2==0):
H /=2
print(int(H*W))
else:
H //= 2
if(W%2==0):
print(int(H*W+(W/2)))
else:
print(int(H*W+(W//2+1)))
|
h,w=map(int,input().split())
if h == 1 or w == 1:
print(1)
else:
div,mod=divmod(h*w,2)
print(div+mod)
| 1 | 50,931,226,671,298 | null | 196 | 196 |
#!/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()))
S, W = LI()
if S <= W:
print("unsafe")
else:
print("safe")
|
s,w=list(map(int, input().split()))
a=''
if s<=w:
a='un'
print(a+'safe')
| 1 | 29,175,305,743,412 | null | 163 | 163 |
k = int(input())
for i in range(k):print("ACL",end="")
|
import sys,math,collections,itertools
input = sys.stdin.readline
N,M = list(map(int,input().split()))
road = [[] for _ in range(N+1)]
flag = [-1 for _ in range(N+1)]
flag[1]=0
for i in range(M):
a,b = map(int,input().split())
road[a].append(b)
road[b].append(a)
q = collections.deque([1])
while q:
now = q.popleft()
for r in road[now]:
if flag[r] == -1:
flag[r] = now
q.append(r)
print('Yes')
for i in range(2,N+1):
print(flag[i])
| 0 | null | 11,359,689,826,078 | 69 | 145 |
x, y = map(int, input().split())
ans = 0
for i in [x, y]:
if i <= 3:
ans += 4 - i
if x == 1 and y == 1:
ans += 4
print(ans * 100000)
|
x,y = map(int,input().split())
k = [0,3,2,1] + [0]*1000
ans = k[x]+k[y]
if x == y == 1:
ans += 4
print(ans*100000)
| 1 | 140,619,008,485,450 | null | 275 | 275 |
x=int(input())
for i in range(int(x**.5),0,-1):
if x%i==0: break
print(i+x//i-2)
|
n = int(input())
for i in range(int(n ** 0.5), 0, -1):
if n % i == 0:
print(i + n // i - 2)
break
| 1 | 161,232,187,991,030 | null | 288 | 288 |
for i in xrange(1, 10):
for j in xrange(1, 10):
print '%dx%d=%d'%(i,j,i*j)
|
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
| 1 | 2,072,800 | null | 1 | 1 |
S = input()
youbi = ['SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN']
print(youbi.index(S) + 1)
|
n = int(input())
a = list(map(int,input().split()))
maxketa = max([len(bin(a[i])) for i in range(n)])-2
mod = 10**9+7
ans = 0
for i in range(maxketa):
ones = 0
for j in range(n):
if (a[j] >> i) & 1:
ones += 1
ans = (ans + (n-ones)*ones*(2**i)) % mod
print(ans)
| 0 | null | 127,679,727,584,880 | 270 | 263 |
count = int(raw_input())
arr = map(int, raw_input().split())
arr.reverse()
print(" ".join(map(str, arr)))
|
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
mod = 998244353
n, k = map(int, input().split())
l = []
r = []
for _ in range(k):
l_, r_ = map(int, input().split())
l.append(l_)
r.append(r_)
dp = [0] * (n + 1)
dp_csum = [0] * (n + 1)
dp[1] = 1
dp_csum[1] = 1
for i in range(2, n + 1):
for j in range(k):
left = i - r[j]
right = i - l[j]
if right >= 1:
dp[i] += dp_csum[right] - dp_csum[max(left, 1) - 1]
dp[i] %= mod
dp_csum[i] = dp_csum[i - 1] + dp[i]
dp_csum[i] %= mod
print(dp[-1])
| 0 | null | 1,840,853,246,068 | 53 | 74 |
N = int(input())
print(max(N//2, (N+1)//2))
|
i = int(input())
import math
print(math.ceil(i/2))
| 1 | 59,265,432,564,810 | null | 206 | 206 |
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a_sum = [0 for i in range(N+1)]
for i in range(N):
a_sum[i+1] = a_sum[i] + A[i]
b_sum = [0 for i in range(M+1)]
for i in range(M):
b_sum[i+1] = b_sum[i] + B[i]
ans = 0
for i in range(N+1):
t = a_sum[i]
l = 0
r = len(b_sum)
while(l+1<r):
c = (l+r)//2
if t+b_sum[c]<=K:
l = c
else:
r = c
if a_sum[i]+b_sum[l]<=K:
ans = max(ans,i+l)
print(ans)
|
# -*- coding: utf-8 -*-
n = int(raw_input())
dic = set()
for i in range(n):
com, s = map(str, raw_input().split())
if com == "insert":
dic.add(s)
elif com == "find":
if s in dic:
print "yes"
else:
print "no"
| 0 | null | 5,353,362,774,738 | 117 | 23 |
n=int(input())
l=list(map(int,input().split()))
from bisect import bisect_left
l.sort()
count=0
for a in range(n-2):
for b in range(a+1,n-1):
idx=bisect_left(l,l[a]+l[b],lo=b)
count+=idx-(b+1)
print(count)
|
import math
def canMakeTriangle(a, b, c):
return abs(b - c) < a
N = int(input())
L = list(map(int, input().split()))
L.sort()
res = 0
for i in range(1, N):
for j in range(i + 1, N):
a = 0
b = i
c = 0
while b - a >= 1:
c = (a + b) / 2
if canMakeTriangle(L[math.floor(c)], L[i], L[j]):
b = c
else:
a = c
c = math.floor(c)
if canMakeTriangle(L[c], L[i], L[j]):
res += i - c
else:
res += i - c - 1
print(res)
| 1 | 172,104,673,224,610 | null | 294 | 294 |
m=[]
for i in range(10):m.append(int(input()))
m.sort(reverse=True)
for i in range(3):print(m[i])
|
h = int(input())
layer = 0
branch_set = 0
while True :
if h > 1 :
h //= 2
layer += 1
continue
else :
break
for i in range(0, layer) :
branch_set += 2 ** i
print(branch_set + 2**layer)
| 0 | null | 40,064,886,500,080 | 2 | 228 |
number = int(input())
score = list(map(int,input().split()))
kiroku = 10**10
for i in range(100):
answer = 0
for j in range(number):
answer += (score[j] - i-1)**2
if answer < kiroku:
kiroku = answer
print(kiroku)
|
x = int(input())
print(int(9 - (x-399)/200))
| 0 | null | 36,041,183,996,704 | 213 | 100 |
import sys
def popcount(x: int):
return bin(x).count("1")
def main():
N = int(sys.stdin.readline().rstrip())
X = sys.stdin.readline().rstrip()
Xdec = int(X, 2)
# 1回目の演算用
md = popcount(Xdec)
md_p, md_m = md + 1, md - 1
tmp_p = Xdec % md_p
if md_m > 0:
tmp_m = Xdec % md_m
for i in range(0, N, 1):
if X[i] == "1": # 1->0
if md_m == 0:
print(0)
continue
x_m = pow(2, (N - 1 - i), md_m)
tmp = (tmp_m - x_m) % md_m
if X[i] == "0": # 0->1
x_p = pow(2, (N - 1 - i), md_p)
tmp = (tmp_p + x_p) % md_p
cnt = 1
while tmp:
tmp = tmp % popcount(tmp)
cnt += 1
print(cnt)
main()
|
import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
X = input()
pc = X.count("1")
if pc == 1:
if X[-1] == "0":
for i, s in enumerate(X):
if i == N - 1:
print(2)
elif s == "0":
print(1)
else:
print(0)
else:
ans = [2] * (N - 1) + [0]
print(*ans, sep="\n")
exit()
m01 = 0
m10 = 0
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
if s == "1":
m01 += b01
m01 %= pc + 1
m10 += b10
m10 %= pc - 1
b01 *= 2
b01 %= pc + 1
b10 *= 2
b10 %= pc - 1
def pop_count(T):
T = (T & 0x55555555) + ((T >> 1) & 0x55555555)
T = (T & 0x33333333) + ((T >> 2) & 0x33333333)
T = (T & 0x0F0F0F0F) + ((T >> 4) & 0x0F0F0F0F)
T = (T & 0x00FF00FF) + ((T >> 8) & 0x00FF00FF)
T = (T & 0x0000FFFF) + ((T >> 16) & 0x0000FFFF)
return T
memo = [0] * (N + 10)
for i in range(1, N + 10):
p = pop_count(i)
memo[i] = memo[i % p] + 1
ans = [0] * N
b01 = 1
b10 = 1
for i, s in enumerate(X[::-1]):
if s == "0":
m = m01
m += b01
m %= pc + 1
else:
m = m10
m -= b10
m %= pc - 1
ans[i] = memo[m] + 1
b01 *= 2
b01 %= pc + 1
b10 *= 2
b10 %= pc - 1
print(*ans[::-1], sep="\n")
| 1 | 8,225,456,044,080 | null | 107 | 107 |
def resolve():
N = int(input())
A = list(map(int, input().split()))
import collections
counter = collections.Counter(A)
total = 0
for k, v in counter.items():
total += v*(v-1)//2
for a in A:
cnt = counter[a]
cntm1 = cnt - 1
print(total - cnt*(cnt-1)//2 + cntm1*(cntm1-1)//2)
if '__main__' == __name__:
resolve()
|
answer = input()
count = 0
list = []
for i in answer:
list.append(i)
if len(answer) != 6:
print("No")
elif list[2] == list[3] and list[4] == list[5]:
print("Yes")
else:
print("No")
| 0 | null | 44,905,379,563,280 | 192 | 184 |
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i, v in enumerate(a, 1):
if i % 2 == 1 and v % 2 == 1:
ans += 1
print(ans)
|
N = int(input())
ans = 0
A = list(map(int, input().split()))
for a in A[::2]:
if a%2 != 0:
ans += 1
print(ans)
| 1 | 7,860,206,950,210 | null | 105 | 105 |
from sys import stdin,stdout
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")
mod=1000000007
INF=float('inf')
for _ in range(1):
s=st()
if s[-1]=='s':
print(''.join(s)+'es')
else:
print(''.join(s)+'s')
|
s=input()
if s[len(s)-1]=='s':print(s+'es')
else:print(s+'s')
| 1 | 2,393,598,339,498 | null | 71 | 71 |
n = int(input())
if n >= 1800:
print("1")
elif n >= 1600:
print("2")
elif n >= 1400:
print("3")
elif n >= 1200:
print("4")
elif n >= 1000:
print("5")
elif n >= 800:
print("6")
elif n >= 600:
print("7")
elif n >= 400:
print("8")
|
a=input()
if str.isupper(a):
print('A')
else :
print('a')
| 0 | null | 9,100,913,773,782 | 100 | 119 |
while 1 :
try:
h,w=map(int,input().split())
#print(h,w)
if( h==0 and w==0 ):
break
else:
for hi in range(h):
print("#" * w)
print() #??????
if( h==0 and w==0 ): break
except (EOFError):
#print("EOFError")
break
|
n = int(input())
a = list(map(int, input().split()))
if n == 0 and a[0] != 1:
print(-1)
exit(0)
b = [0] * (n + 2)
for i in range(n, 0, -1):
b[i - 1] = b[i] + a[i]
t = 1 - a[0]
ans = 1
for i in range(n):
m = min(t * 2, b[i])
if m < a[i + 1]:
print(-1)
exit(0)
ans += m
t = m - a[i + 1]
print(ans)
| 0 | null | 9,818,138,971,508 | 49 | 141 |
import collections
s = input()
mod = 2019
n = len(s)
t = [0]*(n+1)
for i in range(1,n+1):
t[i] = (t[i-1] + int(s[n-i]) * pow(10, i-1, mod)) % mod
c = collections.Counter(t)
num = c.values()
ans = 0
for i in num:
ans += i*(i-1) // 2
print(ans)
|
A, B, N = map(int, input().split())
def func(x):
return (A*x)//B - A*(x//B)
print(func(min(B-1, N)))
| 0 | null | 29,374,357,845,164 | 166 | 161 |
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
on=0
L=[]
cn=0#後ろに置くやつ
for i in range(N):
s=input()
close=0
openn=0
for ch in s:
if ch==")":
if openn==0:
close+=1
else:
openn-=1
else:
openn+=1
if close==0:
on+=openn
elif openn==0:
cn+=close
else:
L.append((close-openn,close,-1*openn))
L.sort()
flag=1
#print(on)
for co in L:
cc=co[1]
oo=co[2]
#print(cc,oo)
on-=cc
if on<0:
flag=0
break
on-=oo
on-=cn
if on!=0:
flag=0
if flag==1:
print("Yes")
else:
print("No")
main()
|
import sys
def input():
return sys.stdin.readline().strip()
n = int(input())
s = []
for _ in range(n):
s.append(input())
'''
N = sum([len(i) for i in s])
R = sum([i.count('(') for i in s])
if N % 2 == 1 or s.count('(') != N // 2:
print('No')
exit()
'''
bothleft = []
bothright = []
bothneutral = [0]
left = [0]
right = [0]
for i in s:
lnum = 0
now = 0
for j in range(len(i)):
if i[j] == '(':
now -= 1
else:
now += 1
lnum = max([lnum, now])
rnum = 0
now = 0
for j in range(len(i) - 1, -1, -1):
if i[j] == ')':
now -= 1
else:
now += 1
rnum = max([rnum, now])
if lnum > 0:
if rnum > 0:
if lnum > rnum:
bothleft.append((rnum, lnum - rnum))
elif rnum > lnum:
bothright.append((lnum, rnum - lnum))
else:
bothneutral.append(lnum)
else:
left.append(lnum)
elif rnum > 0:
right.append(rnum)
bothneutral = max(bothneutral)
bothleft.sort()
bothright.sort()
lsum = sum(left)
for i in range(len(bothleft)):
if bothleft[i][0] > lsum:
print('No')
exit()
lsum += bothleft[i][1]
if bothneutral > lsum:
print('No')
exit()
rsum = sum(right)
for i in range(len(bothright)):
if bothright[i][0] > rsum:
print('No')
exit()
rsum += bothright[i][1]
if lsum != rsum:
print('No')
exit()
print('Yes')
| 1 | 23,821,860,560,400 | null | 152 | 152 |
while 1:
x = input()
if x[0] == "0":
break
print (sum(int(i)for i in x))
|
a,b,c,k=map(int,open(0).read().split())
#while k:k-=1;t=a<b;b*=2-t;c*=1+t
while k:k-=1;exec(f'{"bc"[a<b]}*=2')
#while k:k-=1;exec('%c*=2'%'bc'[a<b])
#while k:k-=1;vars()['bc'[a<b]]*=2
print('NYoe s'[b<c::2])
| 0 | null | 4,246,830,101,030 | 62 | 101 |
x = int(input())
a = x // 100
b = x - a * 100
while b > 5:
b = b - 5
a -= 1
if a>=1:
print(1)
else:
print(0)
|
L, R, d = map(int, input().split())
if L%d==0:
st = L
else:
st = (L//d+1)*d
count = 0
for i in range(st, R+1, d):
if i <= R:
count += 1
else:
break
print(count)
| 0 | null | 67,452,106,436,260 | 266 | 104 |
n=int(input())
if n<3:
print(0)
elif n%2==0:
print(int((n/2)-1))
else:
print(int(n//2))
|
n = int(input())
print((n-1)//2)
| 1 | 153,272,184,091,040 | null | 283 | 283 |
n=int(input())
a=[1,1]
def fib(n):
if n <= 1:
return a[n]
for i in range(2,n+1):
a.append(a[i-1]+a[i-2])
return a[n]
print(fib(n))
|
class UnionFind():
# 要素数を指定して作成 はじめは全ての要素が別グループに属し、親はいない
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# xの根を返す
def find(self, x):
if self.parents[x] < 0: return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# xとyが属するグループを併合
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y: return
if self.parents[x] > self.parents[y]: x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# xが属するグループの要素数
def size(self, x): return -self.parents[self.find(x)]
# xとyが同じグループか否か
def same(self, x, y): return self.find(x) == self.find(y)
# xと同じメンバーの要素
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
# 根の一覧
def roots(self): return [i for i, x in enumerate(self.parents) if x < 0]
# グループ数
def group_count(self): return len(self.roots())
# 可視化 [print(uf)]
def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
N, M, K = list(map(int,input().split()))
G1 = [[] for _ in range(N)]
for i in range(M):
a, b = map(int, input().split())
G1[a - 1].append(b - 1)
G1[b - 1].append(a - 1)
G2 = [[] for _ in range(N)]
for i in range(K):
a, b = map(int, input().split())
G2[a - 1].append(b - 1)
G2[b - 1].append(a - 1)
uf = UnionFind(N)
for i in range(N):
for j in G1[i]:
uf.union(i, j)
for i in range(N):
ans = uf.size(i) - len(G1[i]) - 1
for j in G2[i]:
if uf.same(i, j): ans -= 1
print(ans)
| 0 | null | 30,962,914,172,772 | 7 | 209 |
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(0,n-2):
for j in range(i+1,n-1):
left = j
right = n
while right-left>1:
mid = (left + right)//2
if l[i]+l[j]>l[mid] and l[i]+l[mid]>l[j] and l[mid]+l[j]>l[i]:
left = mid
else:
right = mid
#print(i,j,left)
ans+=(left-j)
print(ans)
|
import bisect
from itertools import combinations
def main():
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for l in combinations(L, 2):
a = l[0]
b = l[1]
x = bisect.bisect_left(L, a + b)
y = bisect.bisect(L, b - a)
if b - a < a :
ans += x - y - 2
else:
ans += x - y - 1
print(ans // 3)
if __name__ == "__main__":
main()
| 1 | 171,602,392,858,068 | null | 294 | 294 |
def main():
S, W = map(int, input().split())
cond = S <= W
print('unsafe' if cond else 'safe')
if __name__ == '__main__':
main()
|
numbers = input()
numbers = numbers.split(" ")
W = int(numbers[0])
H = int(numbers[1])
x = int(numbers[2])
y = int(numbers[3])
r = int(numbers[4])
if (r <= x <= W - r) and (r <= y <= H - r):
print("Yes")
else:
print("No")
| 0 | null | 14,878,126,168,420 | 163 | 41 |
N = int(input())
A = [int(x) for x in input().split()]
num_c = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if(i != minj):
A[i], A[minj] = A[minj], A[i]
num_c += 1
print((" ").join(str(x) for x in A))
print(num_c)
|
import math
N = int(input())
K = int(input())
l = len(str(N))
dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(102)]
dp[0][0][0] = 1
for i in range(l):
for j in range(4):
for k in range(2):
for d in range(10):
nd = int(str(N)[i])
ni = i + 1
nj = j
nk = k
if d > 0:
nj += 1
if nj > K:
continue
if k == 0:
if d > nd:
continue
if d < nd:
nk = 1
dp[ni][nj][nk] += dp[i][j][k]
print(dp[l][K][0] + dp[l][K][1])
| 0 | null | 37,875,117,933,070 | 15 | 224 |
from collections import deque
def bfs(g, source):
n = len(g)
d = [float('inf') for _ in range(n)]
d[0] = 0
queue = deque()
queue.append(0)
while len(queue) > 0:
cur = queue.popleft()
for next in g[cur]:
if d[cur] + 1 < d[next]:
d[next] = d[cur] + 1
queue.append(next)
return d
def main():
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n):
inp = list(map(int, input().split()))
m = inp[0] - 1
k = inp[1]
for i in range(k):
g[m].append(inp[i+2] - 1)
d = bfs(g, 0)
for i in range(n):
if d[i] == float('inf'):
d[i] = -1
print(i+1, d[i])
if __name__ == '__main__':
main()
|
print('YNeos'[len({*input()})<2::2])
| 0 | null | 27,510,245,714,588 | 9 | 201 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.