code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 2
178,025B
⌀ | question_pair_id
float64 27.1M
177,113B
⌀ | code1_group
int64 1
297
| code2_group
int64 1
297
|
---|---|---|---|---|---|---|
def main():
N = int(input())
st = [list(input().split()) for i in range(N)]
X = input()
ans = 0
for i in range(N):
if st[i][0] == X:
i += 1
break
for j in range(i,N,1):
ans += int(st[j][1])
return ans
print(main())
|
n=int(input())
a=list(map(int,input().split()))
temp=sum(a)
ans=0
t=9999999999999999
tsum=0
ta=0
for i in range(n):
tsum=tsum+a[i]
if abs(tsum-temp/2)<t:
t=abs(tsum-temp/2)
ta=tsum
print(abs(int(ta)*2-temp))
| 0 | null | 118,951,889,506,790 | 243 | 276 |
n, k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
l = -1
r = 10 ** 13
while r - l > 1:
m = (l + r) // 2
if sum([(a - m // f) if a * f > m else 0 for a, f in zip(A, F)]) <= k:
r = m
else:
l = m
print(r)
|
import math
x = int(input())
y = x
while True:
flg = 0
for i in range(2,math.ceil(y**0.5)):
if y%i == 0:
flg = 1
break
if flg == 0:
print(y)
break
y += 1
| 0 | null | 134,896,318,934,080 | 290 | 250 |
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
# ----------------------------------------------------------- #
a, v = (int(x) for x in input().split())
b, w = (int(x) for x in input().split())
t = int(input())
if a == b:
print("YES")
elif a < b:
if a + t*v >= b + t*w:
print("YES")
else:
print("NO")
else:
if a - t*v <= b - t*w:
print("YES")
else:
print("NO")
|
import sys
readline = sys.stdin.readline
def main():
A, V = map(int, readline().rstrip().split())
B, W = map(int, readline().rstrip().split())
T = int(readline())
v = V - W
if v <= 0:
print('NO')
return
if abs(A - B) / v > T:
print('NO')
else:
print('YES')
if __name__ == '__main__':
main()
| 1 | 15,001,547,934,150 | null | 131 | 131 |
s = raw_input()
Q = input()
for q in range(Q):
str_order = raw_input().split()
if str_order[0] == 'print':
print s[int(str_order[1]):int(str_order[2])+1]
elif str_order[0] == 'reverse':
start = s[:int(str_order[1])]
mid = s[int(str_order[1]):int(str_order[2])+1]
mid = mid[::-1]
end = s[int(str_order[2])+1:]
s = start+mid+end
elif str_order[0] == 'replace':
start = s[:int(str_order[1])]
mid = str_order[3]
end = s[int(str_order[2])+1:]
s = start+mid+end
|
s = input().strip()
buf = s[0]
count = 0
popa = []
suma = 0
for i in s:
if i=="<":
count+=1
suma += count
elif i==">" and buf=="<":
popa.append(count)
suma -= count
count = 0
buf = i
buf = s[-1]
count = 0
dupa = []
for i in s[::-1]:
if i==">":
count+=1
suma += count
elif i=="<" and buf==">":
dupa.append(count)
suma -= count
count = 0
buf = i
for i,j in zip(dupa[::-1],popa):
suma+=max(i,j)
print(suma)
# print(sum(map(int,"0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1".split())))
| 0 | null | 79,309,519,435,862 | 68 | 285 |
while True:
h,w=map(int,input().split())
if h==0 and w==0:
break
for i in range(h):
for j in range(w):
if i%2==0:
if j%2==0:
print("#",end="")
else:
print(".",end="")
else:
if j%2==0:
print(".",end="")
else:
print("#",end="")
print("")
print("")
|
import numpy as np
import sys
K = int(input())
A, B = list(map(int, input().split()))
array = np.arange(A, B+1)
for _ in array:
if(_%K == 0):
print("OK")
sys.exit(0)
print("NG")
| 0 | null | 13,675,323,238,090 | 51 | 158 |
import sys
a,b,c = map(int, sys.stdin.readline().split())
count=0
if a!=b :
for i in range(a,b+1):
if c%i == 0 :
count+=1
else:
if c%a == 0 :
count+=1
print(count)
|
"TLE"
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
A_dir_list = []
A_visit_list = [-1 for i in range(N)]
dir = 0
while True:
A_dir_list.append(dir)
A_visit_list[dir] = 1
if A_visit_list[A_list[dir]-1] == -1:
dir = A_list[dir]-1
else:
cycle_pos = A_dir_list.index(A_list[dir]-1)
break
if K < cycle_pos:
print(A_dir_list[K]+1)
else:
cnt = (K-cycle_pos)%(len(A_dir_list)-cycle_pos)
print(A_dir_list[cnt+cycle_pos]+1)
| 0 | null | 11,751,273,086,894 | 44 | 150 |
import collections
K = int(input())
l = collections.deque([1,2,3,4,5,6,7,8,9])
cnt = 0
while True:
n = l.popleft()
cnt +=1
if cnt ==K:
print(n)
exit()
if n%10 != 0:
l.append(10*n+n%10-1)
l.append(10*n+n%10)
if n%10 != 9:
l.append(10*n+n%10+1)
|
import queue
k = int(input())
q = queue.Queue()
for i in range(1, 10):
q.put(i)
for i in range(k):
x = q.get()
if i == k-1:
print(x)
break
if x%10 != 0:
q.put(10*x+(x%10)-1)
q.put(10*x+x%10)
if x%10 != 9:
q.put(10*x+(x%10)+1)
| 1 | 40,081,303,018,550 | null | 181 | 181 |
# -*- coding: utf-8 -*-
N = int(input())
X = list(map(int, input().split()))
min_x = X[0]
max_x = X[0]
for i in range(N):
if X[i] > max_x: max_x = X[i]
if X[i] < min_x: min_x = X[i]
ans = 10000000
for p in range(min_x, max_x+1):
ans_p = 0
for x in X:
ans_p += (x-p)**2
if ans > ans_p: ans = ans_p
print(ans)
|
# coding: utf-8
# Your code here!
n=int(input())
x=list(map(int,input().split()))
cost_min=1000000000
for i in range(1,101):
cost=0
for j in x:
cost+=(j-i)**2
if cost>=cost_min:
continue
cost_min=cost
print(cost_min)
| 1 | 65,266,922,192,808 | null | 213 | 213 |
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p = sorted(p,reverse=True)
q = sorted(q,reverse=True)
r = sorted(r,reverse=True)
lis = p[:x]
lis.extend(q[:y])
lis = sorted(lis)
#print(lis)
ans = []
lr = len(r)
for i in range(len(lis)):
if i<lr:
ans.append(max(lis[i],r[i]))
else:
ans.append(lis[i])
print(sum(ans))
|
def main():
print(input().swapcase())
if __name__ == '__main__':
main()
| 0 | null | 23,197,398,065,570 | 188 | 61 |
def resolve():
import sys
input = sys.stdin.readline
# 整数 1 つ
n = int(input())
s = input()
# 整数複数個
# a, b = map(int, input().split())
# 整数 N 個 (改行区切り)
# N = [int(input()) for i in range(N)]
# 整数 N 個 (スペース区切り)
# N = list(map(int, input().split()))
# 整数 (縦 H 横 W の行列)
# A = [list(map(int, input().split())) for i in range(H)]
cnt = 0
for i in range(n-2):
if s[i]+s[i+1]+s[i+2] == "ABC":
cnt += 1
print(cnt)
resolve()
|
def gcd(m, n):
while n:
m, n = n, m % n
return m
def lcm(m, n):
return m // gcd(m, n) * n
for line in open(0).readlines():
a, b = map(int, line.split())
print(gcd(a, b), lcm(a, b))
| 0 | null | 49,746,990,510,700 | 245 | 5 |
import math
class Pos:
def init(x, y):
self.x = x
self.y = y
def kock(n, p1, p2):
if n == 0: return
s, t = Pos(), Pos()
s.x = (2 * p1.x + 1 * p2.x) / 3
s.y = (2 * p1.y + 1 * p2.y) / 3
t.x = (1 * p1.x + 2 * p2.x) / 3
t.y = (1 * p1.y + 2 * p2.y) / 3
cos60 = math.cos(math.radians(60))
sin60 = math.sin(math.radians(60))
u = Pos()
u.x = (t.x - s.x) * cos60 - (t.y - s.y) * sin60 + s.x
u.y = (t.x - s.x) * sin60 + (t.y - s.y) * cos60 + s.y
kock(n-1, p1, s)
print("{:.5f} {:.5f}".format(s.x, s.y))
kock(n-1, s, u)
print("{:.5f} {:.5f}".format(u.x, u.y))
kock(n-1, u, t)
print("{:.5f} {:.5f}".format(t.x, t.y))
kock(n-1, t, p2)
n = int(input())
p1, p2 = Pos(), Pos()
p1.x, p1.y = 0.0, 0.0
p2.x, p2.y = 100.0, 0.0
print("{:.5f} {:.5f}".format(p1.x, p1.y))
kock(n, p1, p2)
print("{:.5f} {:.5f}".format(p2.x, p2.y))
|
S=list(input())
K=int(input())
cnt=cnt2=0
s=S*2
if len(set(S))==1:
print(len(S)*K//2);exit()
for i in range(len(S)-1):
if S[i+1]==S[i]:
cnt+=1
S[i+1]="#"
for i in range(len(s)-1):
if s[i+1]==s[i]:
cnt2+=1
s[i+1]="#"
print(cnt+(cnt2-cnt)*(K-1))
| 0 | null | 87,745,000,283,600 | 27 | 296 |
S = list(input())
L = len(S)
count = 0
count_minus = [0] * L
for i in range(L):
if S[i] == ">":
count = 0
else:
count += 1
count_minus[i] = count
count = 0
count_plus = [0] * L
for i in reversed(range(L)):
if S[i] == "<":
count = 0
else:
count += 1
count_plus[i] = count
result_list = [0] * (L-1)
for i in range(len(result_list)):
result_list[i] = max(count_minus[i], count_plus[i+1])
result = sum(result_list) + count_minus[L-1] + count_plus[0]
print(result)
|
#!/usr/bin/env python3
s = input()
c = 0
a = 0
p = ""
n = 0
for i in s:
if i != p:
if i == "<":
if c < 0:
a -= c * n
else:
a -= c * (n - 1)
n = 2
c = 1
else:
n = 2
c -= 1
else:
if i == "<":
c += 1
n += 1
else:
c -= 1
n += 1
a += c
p = i
if p == ">":
if c < 0:
a -= c * n
else:
a -= c * (n - 1)
print(a)
| 1 | 157,047,567,195,168 | null | 285 | 285 |
import statistics
import sys
data_sets = sys.stdin.read().split("\n")
for i in data_sets[1:-1:2]:
data_set = [int(j) for j in i.split()]
print(statistics.pstdev(data_set))
|
import math
n = int(input())
while (n != 0):
nlist = list(map(float, input().split()))
sum = 0
for i in range(n):
sum += nlist[i]
aver = sum/n
var = 0
for i in range(n):
var += (nlist[i] - aver)**2 / n
dev = math.sqrt(var)
print(dev)
n = int(input())
| 1 | 188,043,303,902 | null | 31 | 31 |
N, X, M = map(int, input().split())
sup = 10**11
db = [[0]*M for _ in range(sup.bit_length())]
dbcum = [[0]*M for _ in range(sup.bit_length())]
db[0] = [i**2 %M for i in range(M)]
dbcum[0] = [i**2 %M for i in range(M)]
for i in range(1,sup.bit_length()):
for j in range(M):
db[i][j] = db[i-1][db[i-1][j]]
dbcum[i][j] = dbcum[i-1][j]+dbcum[i-1][db[i-1][j]]
ans = X
p = 0
N -= 1
while N:
if N%2:
ans += dbcum[p][X]
X = db[p][X]
p += 1
N >>= 1
print(ans)
|
s = input()
t = ""
for _ in range(len(s)):
t += "x"
print(t)
| 0 | null | 37,824,375,703,392 | 75 | 221 |
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
mod = 10**9+7
import math
s = I()
t = 0
ans = 0
for i in range(1,s+1):##iは数列の項の数
if s - 3*i <0:
continue
else:
t = s-3*i
#玉の数がt個、仕切りの数がi-1個
ans += math.factorial(i+t-1)//(math.factorial(t)*math.factorial(i-1))
ans = ans%mod
print(ans)
|
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
S = int(input())
def ncr(n, r):
if n < r: return 0
r = min(r, n-r)
if r == 0: return 1
numer = functools.reduce(operator.mul, range(n, n-r, -1), 1)
denom = functools.reduce(operator.mul, range(1, r+1), 1)
return numer // denom
def solve():
mod = 10**9+7
ans = 0
for i in range(1, S):
if 3 * i > S:
break
ans += ncr(S-3*i+i-1, i-1)
ans %= mod
print(ans)
return 0
if __name__ == "__main__":
solve()
| 1 | 3,274,798,923,946 | null | 79 | 79 |
from math import atan, degrees
a, b, x = map(int, input().split())
if a*a*b <= 2*x:
theta = degrees(atan(2*b/a-2*x/(a*a*a)))
else:
theta = degrees(atan(a*b*b/(2*x)))
print(theta)
|
import math
a, b, x = [int(n) for n in input().split()]
v = a**2 * b /2
#print(v, x)
if v == x:
theta = math.atan(b/a)
elif v > x:
theta = math.atan(a*(b**2)/(2*x))
elif v < x:
theta = math.atan(2/a*(b-x/a**2))
print(math.degrees(theta))
| 1 | 162,900,438,521,030 | null | 289 | 289 |
n=int(input())
a=[]
from collections import deque as dq
for i in range(n):
aaa=list(map(int,input().split()))
aa=aaa[2:]
a.append(aa)
dis=[-1]*n
dis[0]=0
queue=dq([0])
while queue:
p=queue.popleft()
for i in range(len(a[p])):
if dis[a[p][i]-1]==-1:
queue.append(a[p][i]-1)
dis[a[p][i]-1]=dis[p]+1
for i in range(n):
print(i+1,dis[i])
|
import sys
from collections import defaultdict
from queue import Queue
def main():
input = sys.stdin.buffer.readline
n = int(input())
g = defaultdict(list)
for i in range(n):
line = list(map(int, input().split()))
if line[1] > 0:
g[line[0]] = line[2:]
q = Queue()
q.put(1)
dist = [-1] * (n + 1)
dist[1] = 0
while not q.empty():
p = q.get()
for nxt in g[p]:
if dist[nxt] == -1:
dist[nxt] = dist[p] + 1
q.put(nxt)
for i in range(1, n + 1):
print(i, dist[i])
if __name__ == "__main__":
main()
| 1 | 3,906,260,000 | null | 9 | 9 |
n,m,x=map(int,input().split())
ca=[]
ans=10**9
for i in range(n):
tmp=list(map(int,input().split()))
ca.append(tmp)
for p in range(2**n):
i_bin = (bin(p)[2:]).zfill(n)
fl=1
for i in range(1,m+1):
ttl=sum([int(i_bin[k])*ca[k][i] for k in range(n)])
if ttl<x: fl=0
ansc=sum([int(i_bin[k])*ca[k][0] for k in range(n)])
if fl and ansc<ans:
ans=ansc
if ans==10**9: print(-1)
else: print(ans)
|
N, M, X = map(int, input().split())
book = [0] + [list(map(int, input().split())) for _ in range(N)]
ans = N * 10**5 + 1
for i in range(2**N):
read = [0] * (N+1)
rikai = [0] * (M+1)
cost = 0
for j in range(N):
read[j+1] = i%2
i //= 2
for j in range(1, N+1):
if read[j] == 1:
cost += book[j][0]
for k in range(1, M+1):
rikai[k] += book[j][k]
if min(rikai[1:]) >= X:
ans = min(ans, cost)
print(ans if ans != (N * 10**5 + 1) else -1)
| 1 | 22,210,528,969,792 | null | 149 | 149 |
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
hand=["" for _ in range(k)]
point=[0 for _ in range(k)]
for i in range(n):
index=i%k
#初めの手(制限なし)
if index==i:
if t[i]=="r":
hand[index]="p"
point[index]+=p
elif t[i]=="s":
hand[index]="r"
point[index]+=r
else:
hand[index]="s"
point[index]+=s
#2番目以降の手
else:
if t[i]=="r":
if hand[index]=="p":
hand[index]="x"
else:
hand[index]="p"
point[index]+=p
elif t[i]=="s":
if hand[index]=="r":
hand[index]="x"
else:
hand[index]="r"
point[index]+=r
else:
if hand[index]=="s":
hand[index]="x"
else:
hand[index]="s"
point[index]+=s
print(sum(point))
|
N,K = map(int,input().split())
R,S,P = map(int,input().split())
dp = []
order = input()
def jcount(x):
if x=='r':
ans = P
elif x=='s':
ans = R
else:
ans = S
return ans
counter = 0
for i in range(N):
if i < K:
counter += jcount(order[i])
dp.append(order[i])
elif order[i] != dp[i-K]:
counter += jcount(order[i])
dp.append(order[i])
else:
dp.append('x')
print(counter)
| 1 | 106,952,287,159,300 | null | 251 | 251 |
deglist = raw_input().split(" ")
a = int(deglist[0])
b = int(deglist[1])
c = int(deglist[2])
cnt = 0
for x in range(a, b+1):
if c % x == 0:
cnt += 1
print cnt
|
n, k, s = map(int, input().split())
# 1. 全部10**9
# 2. s=10**9の時, 他は1でok
if s == 10 ** 9:
a = [5] * n
else:
a = [10 ** 9] * n
for i in range(k):
a[i] = s
print(*a)
| 0 | null | 46,068,311,555,580 | 44 | 238 |
n=2
while n>0 :
n=n-1
a=map(int,raw_input().split())
else:
print min(a),max(a),sum(a)
|
def gcd(a,b):
a,b=max(a,b),min(a,b)
return a if b==0 else gcd(b,a%b)
x=int(input())
g=gcd(360,x)
print(360//g)
| 0 | null | 6,969,420,092,620 | 48 | 125 |
# https://atcoder.jp/contests/abc164/tasks/abc164_d
import sys
input = sys.stdin.readline
S = input().rstrip()
res = 0
T = [0]
x = 0
p = 1
L = len(S)
MOD = 2019
for s in reversed(S):
""" 累積和 """
x = (int(s)*p + x)%MOD
p = p*10%MOD
T.append(x)
reminder = [0]*2019
for i in range(L+1):
reminder[T[i]%MOD] += 1
for c in reminder:
res += c*(c-1)//2
print(res)
|
n = int(input())
s = ''
for i in range(n):
s += 'ACL'
print(s)
| 0 | null | 16,476,708,674,062 | 166 | 69 |
a, b = map(int, input().split())
al = []
b_lis = []
for _ in range(a):
g = list(map(int, input().split()))
g.append(sum(g))
al.append(g)
for i in range(b+1):
p = 0
for j in range(a):
p += al[j][i]
b_lis.append(p)
al.append((b_lis))
for i in al:
print(' '.join([str(v) for v in i]))
|
# coding: utf-8
def main():
_ = int(input())
A = list(map(int, input().split()))
ans = 0
tmp = 0
total = sum(A)
for a in A:
tmp += a
if tmp >= total // 2:
ans = min(2 * tmp - total, total - 2 * (tmp - a))
break
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 71,508,602,755,138 | 59 | 276 |
class Unionfind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def root (self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.root(self.parents[x])
return self.parents[x]
def connect(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def isConnect(self, x):
return self.root(x) == self.root(y)
def size(self, x):
return -self.parents[self.root(x)]
def solve():
N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))
INF = 10 ** 18
dp = [[-INF] * (N + 1) for i in range(N)]
ans = -INF
uf = Unionfind(N)
for i in range(N):
dp[i][0] = 0
now = i
for j in range(min(N, K)):
now = P[now]
uf.connect(i, now)
dp[i][j + 1] = dp[i][j] + C[now]
ans = max(ans, dp[i][j + 1])
for i in range(N):
M = uf.size(i)
if dp[i][M] < 0:
continue
roop = K // M
move = K % M
if move == 0:
roop -= 1
move = M
for j in range(move):
ans = max(ans, dp[i][M] * roop + dp[i][j + 1])
return ans
print(solve())
|
from itertools import product
H, W, K = map(int, input().split())
G = [list(map(int, list(input()))) for _ in range(H)]
ans = float("inf")
for pattern in product([0, 1], repeat = H - 1):
div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]
rows = []
for i in range(len(div) - 1):
row = []
for j in range(W):
tmp = 0
for k in range(div[i], div[i + 1]):
tmp += G[k][j]
row.append(tmp)
rows.append(row)
flag = True
for row in rows:
if [r for r in row if r > K]:
flag = False
break
if not flag:
continue
tmp_ans = 0
cnt = [0] * len(rows)
w = 0
while w < W:
for r in range(len(rows)):
cnt[r] += rows[r][w]
if [c for c in cnt if c > K]:
cnt = [0] * len(rows)
tmp_ans += 1
w -= 1
w += 1
tmp_ans += pattern.count(1)
ans = min(ans, tmp_ans)
print(ans)
| 0 | null | 26,989,485,455,140 | 93 | 193 |
import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(")
|
import math
N = int(input())
for i in range(N+1):
if math.floor(1.08 * i) == N:
print(i)
exit()
print(":(")
| 1 | 125,425,685,796,640 | null | 265 | 265 |
#https://tjkendev.github.io/procon-library/python/range_query/rmq_segment_tree.html
# N: 処理する区間の長さ
#bit管理
#演算はor
N = int(input())
s = input()
N0 = 1
while N0<=N:
N0*=2
INF = 0
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
k += N0-1
data[k] = 1<<x
while k >= 0:
k = (k - 1) // 2
data[k] =data[2*k+1]|data[2*k+2]
# 区間[l, r)の最小値
def query(l, r):
L = l + N0; R = r + N0
s = INF
while L < R:
if R & 1:
R -= 1
s = s|data[R-1]
if L & 1:
s = s|data[L-1]
L += 1
L >>= 1; R >>= 1
return s
for i in range(N):
update(i,ord(s[i])-ord("a"))
q = int(input())
for j in range(q):
t,l,r = input().split( )
if t=="1":
update(int(l)-1,ord(r)-ord("a"))
else:
bit = bin(query(int(l)-1,int(r)))[2:]
ans = 0
for i in bit:
ans += int(i)
print(ans)
|
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
class SegmentTree():
def __init__(self, init_val, N):
"""
Parameters
----------
init_val:int
identity element
N:int
the number of nodes
"""
self.init_val=init_val
# Range Minimum Query
self.N0 = 2**(N-1).bit_length()
# 0-indexedで管理
self.data = [self.init_val] * (2 * self.N0)
def _segfunc(self, left, right):
res= left | right
return res
def update(self,k, x):
"""
Parameters
----------
k:int
target index(0-index)
x:any
target value
"""
k += self.N0-1
self.data[k] = x
while k > 0:
k = (k - 1) // 2
self.data[k] = self._segfunc(self.data[2*k+1], self.data[2*k+2])
def query(self, l, r):
"""
Parameters
----------
l,r:int
target range [l,r)
Return
----------
res:any
val
"""
L = l + self.N0
R = r + self.N0
s = self.init_val
while L < R:
if R & 1:
R -= 1
s = self._segfunc(s, self.data[R-1])
if L & 1:
s = self._segfunc(s,self.data[L-1])
L += 1
L >>= 1; R >>= 1
return s
n=inp()
s=input()
st = SegmentTree(0,n)
for i in range(n):
st.update(i,1<<(int.from_bytes(s[i].encode(),'little')-int.from_bytes('a'.encode(),'little')))
q = inp()
ans = []
for i in range(q):
mode, first, second = input().split()
if mode == "1":
st.update(int(first)-1,1<<(int.from_bytes(second.encode(),'little')-int.from_bytes('a'.encode(),'little')))
else:
ans.append(bin(st.query(int(first) - 1, int(second))).count("1"))
for i in ans:
print(i)
| 1 | 62,619,016,860,000 | null | 210 | 210 |
N=int(input())
bandera=False
for i in range(10):
for j in range(10):
producto=i*j
if producto==N:
bandera=True
if bandera==True:
print("Yes")
else:
print("No")
|
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
Count=Counter(D)
if D[0]!=0 or Count[0]!=1:print(0);exit()
ans=1
for i in range(1,max(D)+1):
ans *=Count[i-1]**Count[i]
ans %=mod
print(ans)
| 0 | null | 157,545,401,998,388 | 287 | 284 |
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = sorted(c)
result = 0
for i in range(b):
result += d[i]
print(result)
|
from functools import reduce
MOD = 10**9 + 7
n, a, b = map(int, input().split())
def comb(n, k):
def mul(a, b):
return a*b%MOD
x = reduce(mul, range(n, n-k, -1))
y = reduce(mul, range(1, k+1))
return x*pow(y, MOD-2, MOD) % MOD
ans = (pow(2, n, MOD)-1-comb(n,a)-comb(n,b)) % MOD
print(ans)
| 0 | null | 38,994,018,320,972 | 120 | 214 |
k=int(input())
u='ACL'
print(u*k)
|
s = ''
for i in range(int(input())):
s += 'ACL'
print(s)
| 1 | 2,185,483,931,800 | null | 69 | 69 |
# https://atcoder.jp/contests/abc174/tasks/abc174_e
from math import ceil,floor
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=0
R=max(A)
i=0
ans=(L+R)/2
cnt=0
right=0
left=0
while i<100:
i +=1
for num in A:
cnt += ceil(num/ans)-1
if cnt <=K:
R = ans
elif cnt>=K:
L = ans
else:
#print("fin",i-1,cnt,ans)
break
ans = (R+L)/2
cnt=0
print(ceil(ans))
|
print(sum(n for n in range(1+int(input())) if n%3 and n%5))
| 0 | null | 20,710,297,031,020 | 99 | 173 |
N = int(input())
tmp = 0
for i in range(3):
amari = N%10
N //= 10
if amari == 7:
print('Yes')
tmp = 1
break
if tmp != 1:
print('No')
|
n = list(map(int,list(input())))
if 7 in n:
print("Yes")
else:
print("No")
| 1 | 34,269,366,403,350 | null | 172 | 172 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from functools import lru_cache
n, k = map(int, read().split())
@lru_cache()
def check(n, k):
if n < 10:
if k == 0:
return 1
if k == 1:
return n
return 0
a, b = divmod(n, 10)
cnt = 0
if k >= 1:
cnt += check(a, k - 1) * b
cnt += check(a - 1, k - 1) * (9 - b)
cnt += check(a, k)
return cnt
print(check(n, k))
|
n = input()
k = int(input())
dp0 = [[0]*(k+1) for _ in range(len(n)+1)]
dp1 = [[0]*(k+1) for _ in range(len(n)+1)]
dp0[0][0] = 1
for i in range(len(n)):
for j in range(k+1):
if int(n[i]) == 0:
dp0[i+1][j] += dp0[i][j]
if int(n[i]) > 0:
dp1[i+1][j] += dp0[i][j]
if j < k:
dp0[i+1][j+1] += dp0[i][j]
dp1[i+1][j+1] += dp0[i][j]*(int(n[i])-1)
if j < k:
dp1[i+1][j+1] += dp1[i][j]*9
dp1[i+1][j] += dp1[i][j]
print(dp0[len(n)][k]+dp1[len(n)][k])
| 1 | 76,184,953,400,348 | null | 224 | 224 |
n=int(input())
a,b=[],[]
for i in range(n):
A,B=map(int,input().split())
a.append(A)
b.append(B)
a.sort()
b.sort(reverse=True)
ans=0
if n%2==1:
s=a[n//2]
g=b[n//2]
ans=g-s+1
else:
s1,s2=a[n//2-1],a[n//2]
g2,g1=b[n//2-1],b[n//2]
ans=(g2+g1)-(s2+s1)+1
print(ans)
|
#
import sys
import math
import numpy as np
import itertools
n = int(input())
# n行の複数列ある数値をそれぞれの配列へ
a, b = [0]*n, [0]*n
for i in range(n): a[i], b[i] = map(int, input().split())
#print(a,b)
a.sort()
b.sort()
if n % 2 == 0:
t = a[n//2-1] + a[n//2]
s = b[n//2-1] + b[n//2]
print(s-t+1)
else:
t = a[n//2]
s = b[n//2]
print(s-t+1)
| 1 | 17,240,471,982,272 | null | 137 | 137 |
ST = list(map(str, input().split()))
print(ST[1]+ST[0])
|
s, t = input("").split(" ")
res = t + s
print(res)
| 1 | 102,634,297,373,610 | null | 248 | 248 |
s = input()
q = int(input())
#+---+---+---+---+---+---+
#| P | y | t | h | o | n |
#+---+---+---+---+---+---+
#0 1 2 3 4 5 6
#-6 -5 -4 -3 -2 -1
for i in range(0, q):
l = list(input().split())
a = int(l[1])
b = int(l[2]) + 1
if l[0] == "print":
print(s[a: b])
elif l[0] == "reverse":
rev = s[a: b]
rev = rev[::-1]
s = s[:a] + rev + s[b:]
else:
s = s[:a] + l[3] + s[b:]
|
N = input()
K = int(input())
if len(N) < K:
print(0)
exit()
ans = [1, int(N[-1]), 0, 0];
def combination(N,K):
if N < K:
return 0
else:
p = 1
for k in range(K):
p *= N
N -= 1
for k in range(1, K+1):
p //= k
return p
for k in range(1, len(N)):
if int(N[-k-1]) > 0:
a = [1, 0, 0, 0]
for j in range(1, K+1):
a[j] += (9**(j))*combination(k, j)
a[j] += (int(N[-k-1])-1)*combination(k, j-1)*(9**(j-1)) + ans[j-1]
ans = a
print(ans[K])
| 0 | null | 38,857,530,249,820 | 68 | 224 |
c = int(input())
n = 0
for i in range(1,10):
if c /i < 10 and c %i ==0:
n += 1
break
ans = 'Yes' if n >= 1 else 'No'
print(ans)
|
N = int(input())
flag = False
for i in range(1, 10):
if N//i <= 9 and N%i == 0:
flag = True
if flag:
print("Yes")
else:
print("No")
| 1 | 159,803,041,537,020 | null | 287 | 287 |
L = int(input(""))
a = L / 3.0
print(pow(a,3))
|
import math
import sys
from collections import Counter
readline = sys.stdin.readline
def main():
l = int(readline().rstrip())
print((l/3)**3)
if __name__ == '__main__':
main()
| 1 | 46,967,323,871,040 | null | 191 | 191 |
import sys
input = sys.stdin.readline
s=input().rstrip()
if len(set(s))>1:
print('Yes')
else:
print('No')
|
N, K = map(int, input().split())
S = [i+1 for i in range(N)]
H = [0 for i in range(N)]
for i in range(K):
d = int(input())
A = list(map(int, input().split()))
for j in A:
for k in S:
if j==k:
H[k-1] += 1
ans = 0
for i in H:
if i==0:
ans += 1
print(ans)
| 0 | null | 39,587,397,694,628 | 201 | 154 |
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
n,k,s=map(int,input().split())
ans=np.array([0]*n)
ans[:k]+=s
if s!=10**9:
ans[k:]+=10**9
else:
ans[k:]+=10**9-1
print(*ans)
if __name__=='__main__':
main()
|
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
dp=[[0 for i in range(2)] for j in range(n)]
dp[0][0]=a[0]
dp[1][1]=a[1]
for i in range(2,n):
if i==2:
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=dp[i-2][1]+a[i]
else:
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=max(dp[i-2][1],dp[i-3][0])+a[i]
print(max(dp[n-1][1],dp[n-2][0]))
else:
dp=[[0 for i in range(3)] for j in range(n)]
dp[0][0]=a[0]
dp[1][1]=a[1]
dp[2][2]=a[2]
for i in range(2,n):
if i==2:
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=dp[i-2][1]+a[i]
else:
dp[i][0]=dp[i-2][0]+a[i]
dp[i][1]=max(dp[i-2][1],dp[i-3][0])+a[i]
dp[i][2]=max(dp[i-2][2],dp[i-3][1],dp[i-4][0])+a[i]
print(max(dp[n-1][2],dp[n-2][1],dp[n-3][0]))
| 0 | null | 64,519,439,424,608 | 238 | 177 |
#!/usr/bin/env python
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")
def main():
A,B = map(int,input().split())
if A < 10 and B < 10:
print(A*B)
else:
print(-1)
if __name__ == "__main__":
main()
|
x = list(map(int,input().split()))
if(len(str(x[0])) < 2 and len(str(x[1])) < 2):
print(x[0] * x[1])
else:
print(-1)
| 1 | 158,150,361,454,228 | null | 286 | 286 |
import sys
input = sys.stdin.readline
from bisect import *
H, W, K = map(int, input().split())
S = [input()[:-1] for _ in range(H)]
ans = [[-1]*W for _ in range(H)]
now = 1
l = []
for i in range(H):
cnt = 0
for j in range(W):
if S[i][j]=='#':
cnt += 1
if cnt==0:
continue
l.append(i)
c = 0
for j in range(W):
ans[i][j] = now
if S[i][j]=='#':
c += 1
if c<cnt:
now += 1
now += 1
for i in range(H):
if '#' not in S[i]:
j = bisect_left(l, i)
if j==len(l):
for k in range(W):
ans[i][k] = ans[l[-1]][k]
else:
for k in range(W):
ans[i][k] = ans[l[j]][k]
for ans_i in ans:
print(*ans_i)
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
h, w, k = map(int, readline().split())
a = [readline().rstrip().decode() for _ in range(h)]
cnt = 0
memo = 0
for aa in a:
memo += 1
low, high = -1, aa.find('#')
if high == -1:
continue
ans = []
while high != -1:
cnt += 1
ans += [cnt] * (high - low)
low, high = high, aa.find('#', high + 1)
ans += [cnt] * (w - low - 1)
for i in range(memo):
print(*ans)
memo = 0
for i in range(memo):
print(*ans)
| 1 | 143,785,418,543,410 | null | 277 | 277 |
import fractions
A,B=map(int,input().split())
def lcm(x,y):
return int((x*y)/fractions.gcd(x,y))
print(lcm(A,B))
|
a,b = map(int, input().split())
child = a*b
if a < b:
a,b = b,a
r = a%b
while r > 0:
a = b
b = r
r = a%b
print(child//b)
| 1 | 113,144,668,091,954 | null | 256 | 256 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
N, K = mapint()
As = list(mapint())
dv = []
for _ in range(K.bit_length() + 1):
l = [0] * N
dv.append(l)
dv[0] = list(map(lambda x: x-1, As))
for k in range(1, K.bit_length() + 1):
for n in range(N):
dv[k][n] = dv[k - 1][dv[k - 1][n]]
a = []
for i in range(K.bit_length() + 1):
if (K>>i)&1:
a.append(i)
now = 0
for i in a:
now = dv[i][now]
print(now+1)
|
import sys,math,collections,itertools
input = sys.stdin.readline
N,K=list(map(int,input().split()))
A =[0]+list(map(int,input().split()))
town = 1
town_list = [1]
towntown = [0]*(N+1)
towntown[1]=1
count = 0
while True:
town = A[town]
count +=1
if count == K:
print(town)
exit()
if towntown[town] == 0:
town_list.append(town)
towntown[town] =1
else:
roop_town_num = town
break
l_ini_index = town_list.index(roop_town_num)
len_roop = len(town_list)-l_ini_index
if K <= l_ini_index:
print(town_list[K])
else:
print(town_list[((K-l_ini_index)%len_roop+l_ini_index)])
| 1 | 22,823,976,579,380 | null | 150 | 150 |
k=int(input())
n=input()
x=len(n)
if(x>k):
print(n[0:k]+"...")
else:
print(n)
|
k = int(input())
s = input()
if len(s) <= k:
print(s)
else:
print("{}...".format(s[0:k]))
| 1 | 19,741,306,820,740 | null | 143 | 143 |
def resolve():
A, B, N = map(int, input().split())
if B <= N+1:
print(A*(B-1)//B)
else:
print(A*N//B)
resolve()
|
c = input()
alphabet ="abcdefghijklmnopqrstuvwxyz"
ans = alphabet[alphabet.index(c) + 1]
print(ans)
| 0 | null | 60,361,561,860,380 | 161 | 239 |
l = [int(x) for x in input().split()]
anser = 0
for i in l:
anser += 1
if i == 0:
print(anser)
|
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import defaultdict
N, *A = map(int, read().split())
INF = 10**18
dp_not = defaultdict(lambda : -INF)
dp_take = defaultdict(lambda: -INF)
dp_not[(0,0)] = 0
for i,x in enumerate(A,1):
j = (i-1)//2
for n in (j,j+1):
dp_not[(i,n)] = max(dp_not[(i-1,n)], dp_take[(i-1,n)])
dp_take[(i,n)] = dp_not[(i-1,n-1)] + x
print(max(dp_not[(N, N//2)], dp_take[(N, N//2)]))
| 0 | null | 25,531,285,682,452 | 126 | 177 |
N = int(input())
D = list(map(int, input().split()))
from itertools import accumulate
print(sum(list(d*c for d, c in zip(D[1:], accumulate(D)))))
|
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
N = I()
d = LI()
ans = 0
for i in range(N-1):
for j in range(i+1,N):
ans += d[i]*d[j]
print(ans)
| 1 | 167,825,341,463,560 | null | 292 | 292 |
A, B, N = map(int, input().split())
if (B-1) >= N:
Max = ((A*N) // B) - A*(N // B)
elif (B-1) < N:
Max = ((A*(B-1)) // B) - A*((B-1) // B)
print(Max)
|
N=int(input())
S=input()
cntR,cntG,cntB=S.count('R'),S.count('G'),S.count('B')
ans=cntR*cntG*cntB
for i in range(N-2):
for j in range(i+1,N-1):
if S[i]!=S[j]:
k=2*j-i
if k<N and S[k]!=S[i] and S[k]!=S[j]:
ans-=1
print(ans)
| 0 | null | 31,894,101,159,270 | 161 | 175 |
prize = {1:300000,2:200000,3:100000}
a,b = [int(i) for i in input().split()]
if a == b == 1:
print(1000000)
elif a < 4 and b < 4:
print(prize[a] + prize[b])
elif a >= 4 and b < 4:
print(prize[b])
elif b >= 4 and a < 4:
print(prize[a])
else:
print(0)
|
n=int(input())
flag = False
for i in range(100*n,100*(n+1)):
if i%108 == 0:
x = int(i//108)
print(x)
flag = True
break
if flag == False:
print(':(')
| 0 | null | 132,907,035,985,230 | 275 | 265 |
#coding:UTF-8
import math
def KC(n,p1,p2):
if n==0:
return
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(math.pi/3)-(t[1]-s[1])*math.sin(math.pi/3)+s[0],(t[0]-s[0])*math.sin(math.pi/3)+(t[1]-s[1])*math.cos(math.pi/3)+s[1]]
KC(n-1,p1,s)
print(str(format(s[0],'.8f'))+" "+str(format(s[1],'.8f')))
KC(n-1,s,u)
print(str(format(u[0],'.8f'))+" "+str(format(u[1],'.8f')))
KC(n-1,u,t)
print(str(format(t[0],'.8f'))+" "+str(format(t[1],'.8f')))
KC(n-1,t,p2)
if __name__=="__main__":
n=int(input())
p1=[0,0]
p2=[100,0]
print(str(format(p1[0],'.8f'))+" "+str(format(p1[1],'.8f')))
KC(n,p1,p2)
print(str(format(p2[0],'.8f'))+" "+str(format(p2[1],'.8f')))
|
import math
n = int(raw_input())
def func(i, ox1, oy1, ox2, oy2):
if i != n:
nx1 = ox1 + (ox2 - ox1) / 3
ny1 = oy1 + (oy2 - oy1) / 3
nx2 = ox1 + (ox2 - ox1) * 2 / 3
ny2 = oy1 + (oy2 - oy1) * 2 / 3
if nx1 < nx2:
if ny1 == ny2:
nx3 = nx1 + (nx2 - nx1) / 2
ny3 = ny1 + (nx2 - nx1) * math.sqrt(3) / 2
elif ny1 < ny2:
nx3 = ox1
ny3 = ny2
elif ny1 > ny2:
nx3 = ox2
ny3 = ny1
elif nx1 > nx2:
if ny1 == ny2:
nx3 = nx1 + (nx2 - nx1) / 2
ny3 = ny1 - (nx1 - nx2) * math.sqrt(3) / 2
elif ny1 < ny2:
nx3 = ox2
ny3 = ny1
elif ny1 > ny2:
nx3 = ox1
ny3 = ny2
func(i+1, ox1, oy1, nx1, ny1)
func(i+1, nx1, ny1, nx3, ny3)
func(i+1, nx3, ny3, nx2, ny2)
func(i+1, nx2, ny2, ox2, oy2)
elif i == n:
print(str(ox1) + str(" ") + str(oy1))
func(0, 0.0, 0.0, 100.0, 0.0)
print(str(100) + str(" ") + str(0))
| 1 | 128,194,505,220 | null | 27 | 27 |
import queue
n=int(input())
cf=[0]*n
cg=[0]*(n-1)
ce=[[] for _ in range(n)]
e=[[]for _ in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
e[a-1]+=[b-1]
e[b-1]+=[a-1]
ce[a-1]+=[i]
ce[b-1]+=[i]
k=len(max(e,key=len))
q=queue.Queue()
q.put(0)
while not q.empty():
now=q.get()
cf[now]=1
c=0
for i in ce[now]:
if cg[i]:c=cg[i]
j=1
for i in ce[now]:
if j==c:j+=1
if cg[i]:continue
cg[i]=j
j+=1
for i in e[now]:
if cf[i]:continue
q.put(i)
print(k)
for i in cg:
print(i)
|
def resolve():
N = int(input())
g = {}
for i in range(N-1):
a, b = list(map(int, input().split()))
g.setdefault(a-1, [])
g[a-1].append((b-1, i))
g.setdefault(b-1, [])
g[b-1].append((a-1, i))
nodes = [(None, 0)]
colors = [None for _ in range(N-1)]
maxdeg = 0
while nodes:
prevcol, node = nodes.pop()
maxdeg = max(maxdeg, len(g[node]))
color = 1 if prevcol != 1 else 2
for nxt, colidx in g[node]:
if colors[colidx] is None:
colors[colidx] = color
nodes.append((color, nxt))
color += 1 if prevcol != color+1 else 2
print(maxdeg)
for col in colors:
print(col)
if '__main__' == __name__:
resolve()
| 1 | 136,239,626,445,342 | null | 272 | 272 |
k=int(input())
w=input()
if len(w)<=k:
print(w)
else:
print(w[:k]+"...")
|
k=int(input());s=input();print((s,s[:k]+'...')[k<len(s)])
| 1 | 19,723,244,855,468 | null | 143 | 143 |
x = int(input())
now = 0
ans = 0
while True:
ans += 1
now += x
if now % 360 == 0:
print(ans)
exit()
|
a = str(input())
if a=="ABC":
print("ARC")
elif a=="ARC":
print("ABC")
| 0 | null | 18,744,592,381,930 | 125 | 153 |
N= int(input())
st = [list(map(str,input().split())) for _ in range(N)]
x = input()
ans = 0
flag = False
for s,t in st:
if flag:
ans += int(t)
else:
if s == x:
flag = True
print(ans)
|
n=int(input())
s=[]
t=[]
for i in range(n):
st,tt=input().split()
s.append(st)
t.append(int(tt))
x=str(input())
temp=0
ans=sum(t)
for i in range(n):
temp=temp+t[i]
if s[i]==x:
break
print(ans-temp)
| 1 | 96,851,495,287,828 | null | 243 | 243 |
# -*-coding:utf-8
import math
def main():
a, b, degree = map(int, input().split())
radian = math.radians(degree)
S = 0.5*a*b*math.sin(radian)
x = a + b + math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(radian))
print('%.8f' % S)
print('%.8f' % x)
print('%.8f' % ((2*S)/a))
if __name__ == '__main__':
main()
|
from math import sqrt, radians, sin, cos
class Triangle (object):
def __init__(self, a, b, C):
self.a = a
self.b = b
self.C = radians(C)
def getArea(self):
return self.a * self.getHeight() / 2
def getPerimeter(self):
return self.a + self.b + sqrt(self.a ** 2 - 2 * self.a * self.b * cos(self.C) + self.b ** 2)
def getHeight(self):
return self.b * sin(self.C)
tri = Triangle(*[int(e) for e in input().split()])
print(tri.getArea())
print(tri.getPerimeter())
print(tri.getHeight())
| 1 | 176,898,587,580 | null | 30 | 30 |
import sys
for line in sys.stdin:
a,op,b=line.split()
if op == '?':
break
print eval(line)
|
def main():
import sys
sys.setrecursionlimit(10**5+10)
N, M, K = map(int,input().split())
class UnionFind:
def __init__(self, N):
self.par = [-1 for i in range(N+1)]
self.rank = [1]*(N+1)
def find(self, x):
if self.par[x] < 0:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def same_check(self, x, y):
return self.find(x) == self.find(y)
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if self.rank[x] > self.rank[y]:
self.par[x] += self.par[y]
self.par[y] = x
else:
self.par[y] += self.par[x]
self.par[x] = y
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
UF = UnionFind(N)
friendlist = [[] for _ in range(N+1)]
for n in range(M):
A, B = map(int,input().split())
friendlist[A].append(B)
friendlist[B].append(A)
if not UF.same_check(A,B):
UF.union(A, B)
blocklist = [[] for _ in range(N+1)]
for n in range(K):
C, D = map(int, input().split())
blocklist[C].append(D)
blocklist[D].append(C)
for person in range(1,N+1):
root = UF.find(person)
ans = -UF.par[root]-1
ans -= len(friendlist[person])
for l in blocklist[person]:
if UF.same_check(person,l):
ans -= 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 31,190,490,026,652 | 47 | 209 |
from collections import defaultdict
def main():
N, M = map(int, input().split())
g = defaultdict(set)
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
g[a].add(b)
g[b].add(a)
def dfs(u, visited: set):
stack = [u]
visited.add(u)
while stack:
u = stack.pop()
for v in g[u]:
if v not in visited:
stack.append(v)
visited.add(v)
count = dict()
for u in range(N):
if u in count:
continue
visited = set()
dfs(u, visited)
# print(visited)
count[u] = len(visited)
for v in visited:
count[v] = len(visited)
print(max(count.values()))
if __name__ == '__main__':
import sys
sys.setrecursionlimit(10000)
main()
|
n,k=map(int,input().split())
w=[int(input()) for i in range(n)]
def ok(p):
t=[0]*k
curr=0
for i in w:
if i>p:
return False
if t[curr]+i>p:
curr+=1
if curr>=k:
return False
t[curr]+=i
return True
l=0
h=10**9+1
while True:
if l>=h:
print(l)
break
if h==l+1:
print(l if ok(l) else h)
break
mid=(l+h)//2
if ok(mid):
h=mid
else:
l=mid
| 0 | null | 2,061,786,859,568 | 84 | 24 |
N, A, B = map(int, input().split())
ans = 0
if abs(B-A) % 2 == 0:
ans = abs(B-A) // 2
else:
if B > A:
ans = min(N-A, B-1,(N-B+1) + (B-A-1)//2, (A-1+1) + (B-A-1)//2)
if A > B:
ans = min(N-B, A-1,(N-A+1) + (A-B-1)//2, (B-1+1) + (A-B-1)//2)
print(ans)
|
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)
| 1 | 109,908,698,625,870 | null | 253 | 253 |
# coding=utf-8
class Dice(object):
def __init__(self, label):
self.label = label
def _rotateS(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s5, s1, s3, s4, s6, s2]
def _rotateN(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s2, s6, s3, s4, s1, s5]
def _rotateE(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s4, s2, s1, s6, s5, s3]
def _rotateW(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s3, s2, s6, s1, s5, s4]
def rotate(self, r):
if r == 'S':
self._rotateS()
elif r == 'N':
self._rotateN()
elif r == 'E':
self._rotateE()
elif r == 'W':
self._rotateW()
else:
print 'Cannot rotate into ' + r + 'direction.'
def _spinPos(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s1, s4, s2, s5, s3, s6]
def _spinNeg(self):
s1, s2, s3, s4, s5, s6 = self.label
self.label = [s1, s3, s5, s2, s4, s6]
def getTopLabel(self):
return self.label[0]
def match(self, top, front):
iTop = self.label.index(top) + 1
if iTop == 1:
pass
elif iTop == 2:
self._rotateN()
elif iTop == 3:
self._rotateW()
elif iTop == 4:
self._rotateE()
elif iTop == 5:
self._rotateS()
else:
self._rotateS()
self._rotateS()
iFront = self.label.index(front) + 1
if iFront == 2:
pass
elif iFront == 3:
self._spinNeg()
elif iFront == 4:
self._spinPos()
elif iFront == 5:
self._spinPos()
self._spinPos()
if __name__ == '__main__':
d = Dice(map(int, raw_input().split()))
n = input()
for _ in xrange(n):
top, front = map(int, raw_input().split())
d.match(top, front)
print d.label[2]
|
splited = input().split(" ")
f = int(splited[0])/int(splited[1])
r = int(splited[0])%int(splited[1])
d = int(splited[0])//int(splited[1])
print('%s %s %.5f' % (d, r, f))
| 0 | null | 422,934,832,782 | 34 | 45 |
def resolve():
n = int(input())
a = tuple(map(int,input().split()))
print('YES' if len(a)==len(set(a)) else 'NO')
resolve()
|
def main():
n = int(input())
al = []
bl = []
for _ in range(n):
a, b = map(int, input().split())
al.append(a)
bl.append(b)
als = list(sorted(al))
bls = list(sorted(bl))
if n%2:
print(bls[n//2]-als[n//2]+1)
else:
print(bls[n//2-1]+bls[n//2]-als[n//2]-als[n//2-1]+1)
if __name__ == "__main__":
main()
| 0 | null | 45,507,166,036,052 | 222 | 137 |
s = raw_input()
p = raw_input()
s += s
if p in s:
print "Yes"
else:
print "No"
|
#ABC166-B
count=0
a=[]
n,k=map(int,input().split())
for i in range(k):
d = int(input())
a+=list((map(int, input().split())))
ans=(n-len(set(a)))
print(ans)
| 0 | null | 13,268,804,835,230 | 64 | 154 |
s = input()
t = input()
if(s == t[0:len(s)]):
print("Yes")
else:
print("No")
|
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
a = sys.stdin.buffer.readline().decode().rstrip()
b = sys.stdin.buffer.readline().decode().rstrip()[:-1]
if a==b:
print('Yes')
else:
print('No')
| 1 | 21,538,006,664,772 | null | 147 | 147 |
import math
import numpy as np
pi = math.pi
a, b, x = map(int, input().split())
if x >= a**2*b/2:
print(180/pi*np.arctan(2*(a**2*b-x)/a**3))
else:
print(180/pi*np.arctan(a*b**2/(2*x)))
|
import math
a, b, x = map(int, input().split())
if a*a*b >= 2*x:
print(math.degrees(math.atan2(a*b*b,2*x)))
else:
print(math.degrees(math.atan2(2*(a*a*b-x),a**3)))
| 1 | 162,624,450,340,380 | null | 289 | 289 |
rate = int(input())
print(10 - rate // 200)
|
# -*- coding: utf-8 -*-
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
X = int(input())
return X
def main(X: int) -> None:
"""
メイン処理.
Args:\n
X (int): 最高レーティング(400 <= X <= 1999)
"""
# 求解処理
ans = 10 - (X // 200)
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
X = get_input()
# メイン処理
main(X)
| 1 | 6,701,056,022,530 | null | 100 | 100 |
al = list("abcdefghijklmnopqrstuvwxyz")
c = input()
pos = al.index(c)
print(al[pos+1])
|
#!/usr/bin/env python3
import sys
import collections as cl
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()))
MOD = 998244353
def main():
N, K = MI()
kukan = []
for _ in range(K):
tmp = LI()
kukan.append(tmp)
dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N+1)
dp_sum[1] = 1
for i in range(N+1):
for k in range(K):
l, r = kukan[k]
pre_l = i - r
pre_r = i - l
if pre_r < 0:
continue
pre_l = max(pre_l, 0)
dp[i] += dp_sum[pre_r] - dp_sum[pre_l - 1]
dp_sum[i] = dp[i] + dp_sum[i-1]
dp_sum[i] %= MOD
dp[i] %= MOD
print(dp[-1])
main()
| 0 | null | 47,301,005,746,390 | 239 | 74 |
from bisect import bisect_left
def main():
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for ia in range(N):
for ib in range(ia+1, N-1):
a = L[ia]
b = L[ib]
ic_end = bisect_left(L, a+b, lo=ib+1)
ans += ic_end - (ib+1)
print(ans)
main()
|
import sys
import decimal # 10進法に変換,正確な計算
def input():
return sys.stdin.readline().strip()
def main():
r = int(input())
print(r**2)
main()
| 0 | null | 158,581,871,538,720 | 294 | 278 |
import math
def main():
a, b, ang_ab = [float(x) for x in input().split()]
rad_ab = (ang_ab/180)*math.pi
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad_ab))
h = b*math.sin(rad_ab)
s = (a*h)/2
l = a+b+c
print("{:f} {:f} {:f}".format(s, l, h))
if __name__ == '__main__':
main()
|
import math
data = list(map(float, input().split()))
a, b, theta = data[0], data[1], data[2]/180*math.pi
data[1] = (a**2+b**2-2*a*b*math.cos(theta)) ** 0.5 + a + b
data[2] = b * math.sin(theta)
data[0] = a * data[2] / 2
for i in range(3):
print(data[i])
| 1 | 175,336,089,860 | null | 30 | 30 |
N, K = map(int, input().split())
p = list(map(int, input().split()))
q = sum(p[:K])
ans = q
for i in range(K, N):
q = q + p[i] - p[i - K]
ans = max(ans, q)
print((ans+K)/2)
|
N,S=map(int,input().split())
*a,=map(int,input().split())
mod=998244353
dp=[[0]*(S+1) for _ in range(N+1)]
dp[0][0]=1
for i in range(N):
for j in range(S+1):
dp[i+1][j]=2*dp[i][j]
if j>=a[i]:
dp[i+1][j]+=dp[i][j-a[i]]
dp[i+1][j]%=mod
print(dp[N][S])
| 0 | null | 45,995,488,046,442 | 223 | 138 |
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
cnt=0
for i in range(n):
for j in range(i+1,n):
cnt+=bisect.bisect_left(a,a[i]+a[j])-(j+1)
print(cnt)
|
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(n-2):
for j in range(i+1,n-1):
maxc = l[i]+l[j] #短い2辺の和
index = bisect.bisect_left(l, maxc)
if index > j:
count += index-j-1
print(count)
| 1 | 171,713,273,645,342 | null | 294 | 294 |
def main():
N = int(input())
ans = [0]*(N)
for x in range(1, 105):
for y in range(1, 105):
for z in range(1, 105):
if N < x**2 + y**2 + z**2 + x*y + y*z + z*x:
break
ans[x**2 + y**2 + z**2 + x*y + y*z + z*x - 1] += 1
print(*ans, sep="\n")
if __name__ == '__main__':
main()
|
import sys
from math import gcd
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline
N, *AB = map(int, read().split())
mod = 10 ** 9 + 7
ab = []
zero = 0
for A, B in zip(*[iter(AB)] * 2):
if A == 0 and B == 0:
zero += 1
continue
if A == 0:
B = -1
elif B == 0:
A = 1
else:
g = gcd(A, B)
A //= g
B //= g
if A < 0:
A, B = -A, -B
ab.append((A, B))
cnt = Counter(ab)
answer = 1
checked = set()
ok = 0
for (i, j), n in cnt.items():
if (i, j) in checked:
continue
if j < 0:
c, d = -j, i
else:
c, d = j, -i
if (c, d) in cnt:
m = cnt[(c, d)]
answer = (answer * (pow(2, n, mod) + pow(2, m, mod) - 1)) % mod
checked.add((c, d))
else:
ok += n
answer *= pow(2, ok, mod)
answer -= 1
answer += zero
answer %= mod
print(answer)
| 0 | null | 14,438,198,225,322 | 106 | 146 |
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def main():
H, W, K = MAP()
cake = [list(input()) for _ in range(H)]
cut = [[1 for _ in range(W)] for _ in range(H)]
lis_0 = []
lis_1 = []
num = 1
for i in range(H):
if cake[i].count("#") > 0:
lis_1.append(i)
else:
lis_0.append(i)
continue
ct = 0
for j in range(W):
if cake[i][j] == "#":
ct += 1
if ct < 2:
cut[i][j] = num
else:
num += 1
ct = 1
cut[i][j] = num
else:
cut[i][j] = num
num +=1
# print(lis_0)
# print(lis_1)
for x in lis_0:
ind = bisect(lis_1, x)
# print(ind)
if ind == len(lis_1):
ind -= 1
cut[x] = cut[lis_1[ind]]
# print("x", cut[x])
# print("ind", cut[lis_1[ind]])
for x in cut:
print(*x)
if __name__ == '__main__':
main()
|
import math
n = int(input())
A = list(map(int, input().split()))
cnt = 0
inf = 10**9
def merge(A,left,mid,right):
global cnt
L = A[left:mid] + [inf]
R = A[mid:right] + [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
def mergeSort(A,left,right):
if left + 1 < right:
mid = (left + right) // 2
mergeSort(A,left,mid)
mergeSort(A,mid,right)
merge(A,left,mid,right)
mergeSort(A,0,n)
print(*A)
print(cnt)
| 0 | null | 72,092,730,177,270 | 277 | 26 |
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
mod=10**9+7
inv_t=[0,1]
factorial=[1,1]
factorial_re=[1,1]
for i in range(2,N+1):
inv_t.append(inv_t[mod%i]*(mod-mod//i)%mod)
for i in range(2,N+1):
factorial.append(factorial[i-1]*i%mod)
factorial_re.append(factorial_re[i-1]*inv_t[i]%mod)
ans=0
for i in range(N-K+1):
if i==N-K:
ans+=A[i]
ans%=mod
break
ans+=A[i]*factorial[N-1-i]*factorial_re[K-1]*factorial_re[N-K-i]%mod
ans%=mod
for i in range(N-K+1):
if i==N-K:
ans-=A[N-i-1]
ans%=mod
break
ans-=A[N-i-1]*factorial[N-1-i]*factorial_re[K-1]*factorial_re[N-K-i]%mod
ans%=mod
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(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
#階乗#
lim = 10**5 #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
if n < r:
return 0
else:
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
N, K = MAP()
A = LIST()
A.sort()
A_cnt = Counter(A)
P = list(A_cnt.keys())
p = list(A_cnt.values())
#print("P={}".format(P))
#print("p={}".format(p))
p_acc = list(accumulate(p))
p_acc_rev = list(accumulate(p[::-1]))
#print("p_acc={}".format(p_acc))
#print("p_acc_rev={}".format(p_acc_rev))
n = len(p)
T = [[0]*4 for _ in range(n)]
for i in range(n):
T[i][0] = p_acc[i]
for i in range(1, n):
T[i][1] = p_acc[i-1]
for i in range(n):
T[(-i-1)][3] = p_acc_rev[i]
for i in range(1, n):
T[(-i-1)][2] = p_acc_rev[i-1]
#for i in range(n):
# print(T[i])
t = [0]*n
for idx, x in enumerate(T):
t[idx] = (C(x[0], K) - C(x[1], K) + C(x[2], K) - C(x[3], K))%mod
ans = 0
for i in range(n):
ans = (ans + P[i]*t[i]%mod)%mod
print(ans)
| 1 | 95,368,230,145,650 | null | 242 | 242 |
print("YNeos"[2!=len(set(map(int,input().split())))::2])
|
k = int(input())
a, b = map(int,input().split())
flg = False
for i in range(a, b+1):
if i % k == 0:
flg = True
break
print('OK') if flg else print('NG')
| 0 | null | 47,369,238,949,958 | 216 | 158 |
import math
a, b, deg = map(float, raw_input().split(" "))
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(deg)))
L = a + b + c
s = (a + b + c) / 2.0
S = math.sqrt(s*(s-a)*(s-b)*(s-c))
h = 2 * S / a
print(str(S) + " " + str(L) + " " + str(h))
|
x = raw_input()
x = int(x)
x = x * x * x
print x
| 0 | null | 222,965,695,680 | 30 | 35 |
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()))
x = ii()
while 1:
cnt = 0
for i in range(2,math.ceil(x**(1/2)),1):
if x % i == 0:
cnt = 1
break
if cnt == 0:
print(x)
exit()
x += 1
|
MOD = 998244353
N, K = list(map(int, input().split()))
dp = [0] * (N+1)
dp[1] = 1
LR = []
for i in range(K):
l, r = list(map(int, input().split()))
LR.append([l, r])
for i in range(2, N+1):
dp[i] = dp[i-1]
for j in range(K):
l, r = LR[j]
dp[i] += dp[max(i-l, 0)] - dp[max(i-r-1, 0)]
dp[i] %= MOD
print((dp[N]-dp[N-1]) % MOD)
| 0 | null | 53,926,730,340,462 | 250 | 74 |
H, N = map(int, input().split())
dp = [10 ** 9] * (H + 1)
dp[0] = 0
for _ in range(N):
a, b = map(int, input().split())
for i in range(H):
idx = min(H, i + a)
dp[idx] = min(dp[idx], dp[i] + b)
print(dp[H])
|
S = input()
l_s = len(S)
cnt = 0
for i in range(0,l_s//2):
if S[i] != S[-i-1]:
cnt += 1
print(cnt)
| 0 | null | 100,486,507,658,392 | 229 | 261 |
N, R = map(int, input().split())
print(R if N > 9 else R + 100*(10 - N))
|
s = str(input())
t = str(input())
ans = 1001
for i in range(len(s)-len(t)+1):
tmp = 0
for j in range(len(t)):
if s[i+j] == t[j]:
tmp += 1
ans = min(len(t)-tmp,ans)
print(ans)
| 0 | null | 33,689,209,623,264 | 211 | 82 |
N, K = map(int, input().split())
mod = 10**9+7
gcd_l = [0]*K
for i in range(K, 0, -1):
n = pow((K//i), N, mod)
for x in range(i, K+1, i):
n -= gcd_l[K-x]
gcd_l[K-i] = n%mod
res = 0
for i in range(K):
res += (gcd_l[i] * (K-i))%mod
print(res%mod)
|
nn = [0] + list(map(int, list(input())))
dp0, dp1 = 0, 0
for i in range(len(nn)):
dp0, dp1 = nn[i] + min(dp1, dp0), 9 - nn[i] + min(dp1, dp0 + 2)
print(min(dp0, dp1))
| 0 | null | 53,775,132,202,592 | 176 | 219 |
import copy
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
s.append(list(map(int, input().split())))
t = []
for _ in range(D):
t.append(int(input()))
u = [] # last(d,i)
x = [0] * 26
u.append(x)
for i in range(D):
v = copy.deepcopy(u)
y = v[-1]
y[t[i]-1] = i+1
u.append(y)
del u[0]
ans = 0
for i in range(D):
ans += s[i][t[i]-1]
for j in range(26):
ans -= c[j] * ((i+1) - u[i][j])
print(ans)
|
a,b = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
ans = [10**9 for _ in range(a+1)]
ans[0] = 0
for i in range(a+1):
for j in l:
if i + j < a+1:
ans[i+j] = min(ans[i] + 1,ans[i+j])
print(ans[-1])
| 0 | null | 5,072,983,880,650 | 114 | 28 |
N=int(input())
#m1,d1=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
S=list(input())
d=list('0123456789')
ans=0
for d1 in d:
for d2 in d:
for d3 in d:
v=d1+d2+d3
i=0
p=0
while i < N :
if v[p]==S[i]:
p+=1
if p == 3:
break
i+=1
if p==3 :
ans+=1
print(ans)
|
N = int(input())
S = str(input())
num = []
for _ in range(10):
num.append([])
for i in range(N):
num[int(S[i])].append(i)
ans = 0
for X1 in range(0, 10):
for X2 in range(0, 10):
for X3 in range(0, 10):
X = str(X1) + str(X2) + str(X3)
if num[X1] != [] and num[X2] != [] and num[X3] != []:
if num[X1][0] < num[X2][-1]:
for i in num[X2]:
if num[X1][0] < i < num[X3][-1]:
ans += 1
break
print(ans)
| 1 | 128,606,454,082,468 | null | 267 | 267 |
if __name__ == '__main__':
s = input()
if s == "ARC":
print("ABC")
else:
print("ARC")
|
x = input()
if x=='ABC':
print('ARC')
else:
print('ABC')
| 1 | 24,322,910,984,130 | null | 153 | 153 |
s = int(input())
h = s // 3600
s = s % 3600
m = s // 60
s = s % 60
print("%d:%d:%d" % (h,m,s))
|
import sys
readline = sys.stdin.readline
inf = float('inf')
def main():
H, W = map(int, readline().split())
grid = []
grid.append(['*'] * (W+2))
for _ in range(H):
grid.append(['*'] + list(readline()[:-1]) + ['*'])
grid.append(['*']*(W+2))
DP = [[inf] * (W+2) for _ in range(H+2)]
DP[1][1] = (grid[1][1] == '#')*1
for i in range(1, H+1):
for j in range(1, W+1):
if i == 1 and j == 1:
continue
k = i
gridkj = grid[k][j]
if gridkj == '.':
DP[k][j] = min(DP[k][j-1], DP[k-1][j])
if gridkj == '#':
DP[k][j] = min(DP[k][j-1]+(grid[k][j-1] in ['.', '*']), DP[k-1][j] + (grid[k-1][j] in ['.', '*']))
ans = DP[H][W]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 24,966,052,731,610 | 37 | 194 |
inf = 10**10
n,m,l = map(int,input().split())
def warshall_floyd(d):
for i in range(n):
for j in range(n):
for k in range(n):
d[j][k] = min(d[j][k],d[j][i]+d[i][k])
return d
G = [[inf] * n for _ in range(n)] #重み付きグラフ
for i in range(n):
G[i][i] = 0
for _ in range(m):
a,b,c = map(int,input().split())
G[a-1][b-1] = c
G[b-1][a-1] = c
G = warshall_floyd(G)
P = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if i == j:
P[i][j] = 0
elif G[i][j] <= l:
P[i][j] = 1
else:
P[i][j] = inf
p = warshall_floyd(P)
q = int(input())
for _ in range(q):
s,t = map(int,input().split())
ans = p[s-1][t-1]-1
print(ans if ans <= 10**9 else -1)
|
s = raw_input().split()
stack = []
for op in s:
if op.isdigit():
stack.append(op)
else:
b = int(stack.pop())
a = int(stack.pop())
ret = 0
if op == "+":
ret = a + b
elif op == "-":
ret = a - b
elif op == "*":
ret = a * b
stack.append(str(ret))
print stack.pop()
| 0 | null | 86,996,322,733,792 | 295 | 18 |
n,k,*a=map(int,open(0).read().split())
for i in range(n-k):print("Yes" if a[i]<a[i+k] else "No")
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1 # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, AS):
for i in range(K, N):
# debug("i: i,AS[i-K],AS[K]", i, AS[i-K], AS[K])
if AS[i - K] < AS[i]:
print("Yes")
else:
print("No")
def main():
# parse input
N, K = map(int, input().split())
AS = list(map(int, input().split()))
solve(N, K, AS)
# tests
T1 = """
5 3
96 98 95 100 20
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
Yes
No
"""
T3 = """
15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
Yes
Yes
No
Yes
Yes
No
Yes
Yes
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
| 1 | 7,088,978,388,982 | null | 102 | 102 |
N = int(input())
target_list = []
if N % 2 == 1:
N += 1
for i in range(1, int(N/2)):
target = N - i
if target == i:
continue
else:
target_list.append(target)
print(len(target_list))
|
N = input()
if (int( N )%2) == 0:
print( int(int(N) / 2 -1) )
else:
print( int((int(N)-1)/2) )
| 1 | 153,196,419,587,890 | null | 283 | 283 |
def main():
n, m, l = tuple(map(int, input().split()))
matA = [[0 for j in range(m)] for i in range(n)]
matB = [[0 for k in range(l)] for j in range(m)]
matC = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
tmp = list(map(int, input().split()))
for j in range(m):
matA[i][j] = tmp[j]
for j in range(m):
tmp = list(map(int, input().split()))
for k in range(l):
matB[j][k] = tmp[k]
for i in range(n):
for k in range(l):
for j in range(m):
matC[i][k] += matA[i][j] * matB[j][k]
for i in range(n):
for k in range(l):
if k == l-1:
print(matC[i][k])
else:
print(matC[i][k], end=' ')
if __name__ == '__main__':
main()
|
num = int(input())
A = list(map(int, input().split(' ')))
def intersection(A,N):
for i in range(len(A)): #output
if i==len(A)-1:
print(A[i])
else:
print(A[i], end=' ')
for i in range(1,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
for i in range(len(A)):
if i == len(A) - 1: #output
print(A[i])
else:
print(A[i], end=' ')
intersection(A,num)
| 0 | null | 728,666,723,200 | 60 | 10 |
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
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)]
def lcm(a, b): return a * b // math.gcd(a, b)
def extgcd(a, b):
if b:
d, y, x = extgcd(b, a%b)
y -= (a/b)*x
return d, x, y
else:
return a, 1, 0
sys.setrecursionlimit(1000000)
MOD = 1000000007
def main():
n, a, b = LI()
a1, a2 = 1, 1
for i in range(1, a+1):
a1 = a1 * (n - i + 1) % MOD
a2 = a2 * i % MOD
b1, b2 = 1, 1
for i in range(1, b+1):
b1 = b1 * (n - i + 1) % MOD
b2 = b2 * i % MOD
nca = a1 * pow(a2, MOD-2, MOD) % MOD
ncb = b1 * pow(b2, MOD-2, MOD) % MOD
print((pow(2, n, MOD) - 1 - nca - ncb) % MOD)
main()
|
import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MAX = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
def comInit(mod):
fac[0], fac[1] = 1, 1
finv[0], finv[1] = 1, 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def com(mod, n, k):
numerator = 1
for i in range(1, k + 1):
numerator *= (n - i + 1)
numerator %= mod
return (numerator * finv[k] % mod)
comInit(MOD)
n, a, b = map(int, readline().split())
nb = n
def my_pow(base, n, mod):
if n == 0:
return 1
x = base
y = 1
while n > 1:
if n % 2 == 0:
x *= x
n //= 2
else:
y *= x
n -= 1
x %= mod
y %= mod
return x * y % mod
ans = (my_pow(2, n, MOD) - 1) % MOD
print((ans - com(MOD, nb, a) - com(MOD, nb, b)) % MOD)
| 1 | 66,165,077,793,920 | null | 214 | 214 |
# coding: utf-8
# Here your code !
S = int(input())
N = list(map(int,input().split()))
count=0
def bubblesort(n,s):
global count
flag = 1
while flag:
flag = 0
for i in range(s-1,0,-1):
key = n[i]
if n[i]<n[i-1]:
n[i]=n[i-1]
n[i-1]=key
count+=1
flag=1
print(" ".join(list(map(str,n))))
print(count)
bubblesort(N,S)
|
(x, y, a, b, c), p, q, r = [map(int, o.split()) for o in open(0)]
print(sum(sorted(sorted(p)[-x:] + sorted(q)[-y:] + list(r))[-x-y:]))
| 0 | null | 22,514,707,508,948 | 14 | 188 |
import sys
from io import StringIO
import unittest
import os
# 検索用タグ、10^9+7 組み合わせ、スプレッドシートでのトレース
# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)
def cmb(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, mod - 2, mod)
ans %= mod
return ans
def prepare_simple(n, mod=pow(10, 9) + 7):
# n! の計算
f = 1
for m in range(1, n + 1):
f *= m
f %= mod
fn = 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 fn, invs
def prepare(n, mod=pow(10, 9) + 7):
# 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
# 実装を行う関数
def resolve(test_def_name=""):
x, y = map(int, input().split())
all_move_count = (x + y) // 3
x_move_count = all_move_count
y_move_count = 0
x_now = all_move_count * 2
y_now = all_move_count
canMake= False
for i in range(all_move_count+1):
if x_now == x and y_now == y:
canMake = True
break
x_move_count -= 1
y_move_count += 1
x_now -= 1
y_now += 1
if not canMake:
print(0)
return
ans = cmb(all_move_count,x_move_count)
print(ans)
# テストクラス
class TestClass(unittest.TestCase):
def assertIO(self, assert_input, output):
stdout, sat_in = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
resolve(sys._getframe().f_back.f_code.co_name)
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, sat_in
self.assertEqual(out, output)
def test_input_1(self):
test_input = """3 3"""
output = """2"""
self.assertIO(test_input, output)
def test_input_2(self):
test_input = """2 2"""
output = """0"""
self.assertIO(test_input, output)
def test_input_3(self):
test_input = """999999 999999"""
output = """151840682"""
self.assertIO(test_input, output)
# 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
def tes_t_1original_1(self):
test_input = """データ"""
output = """データ"""
self.assertIO(test_input, output)
# 実装orテストの呼び出し
if __name__ == "__main__":
if os.environ.get("USERNAME") is None:
# AtCoder提出時の場合
resolve()
else:
# 自PCの場合
unittest.main()
|
def mod_fact(N,p):
mod=1
for n in range(1,N+1):
mod = (mod*(n%p))%p
mod = mod%p
return mod
X,Y = list(map(int,input().split()))
Z = X+Y
ans=0
if Z%3 != 0:
ans=0
elif min(X,Y) >= Z//3:
b=0
for z in range(Z//3,((Z//3)*2)+1):
if z == X:
break
b+=1
a = Z//3 - b
p=(10**9)+7
Z_= mod_fact(Z//3 , p)
a_= mod_fact(a , p)
b_= mod_fact(b , p)
a_= pow(a_,p-2,p)
b_= pow(b_,p-2,p)
ans=(Z_*(a_*b_))%p
print(ans)
| 1 | 150,228,143,842,618 | null | 281 | 281 |
from fractions import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))
|
R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
a,b,c=map(int,input().split())
a-=1
b-=1
l[a][b]=c
dp=[[0] * C for i in range(R)]
for i in range(R):
kdp=[0]*4
for j in range(C):
if i>0:
kdp[0]=max(kdp[0],dp[i-1][j])
for k in range(2,-1,-1):
kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
dp[i][j]=max(dp[i][j],kdp[k+1])
print(dp[R-1][C-1])
| 0 | null | 59,325,482,781,208 | 256 | 94 |
from collections import Counter
N, M = map(int, input().split())
class UnionFind:
def __init__(self, n):
self.root = [i for i in range(n)]
def unite(self, x, y):
if not self.same(x, y):
self.root[self.find(y)] = self.find(x)
def find(self, x):
if x == self.root[x]:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def same(self, x, y):
return self.find(x) == self.find(y)
UF = UnionFind(N)
ans = N-1
for _ in range(M):
x, y = map(int, input().split())
if not UF.same(x-1, y-1):
UF.unite(x-1, y-1)
ans -= 1
print(ans)
|
N,A,B=list(map(int, input().split()))
ct=N//(A+B)
res=N%(A+B)
print(A*ct + min(A,res))
| 0 | null | 28,952,191,967,530 | 70 | 202 |
import sys
def main():
dp = [[0] * W for _ in range(H)]
for y in range(H):
for x in range(W):
if x == 0 and y == 0:
if s[0][0] == "#":
dp[0][0] = 1
elif x == 0:
if s[y][x] == "#" and s[y - 1][x] == ".":
dp[y][x] = dp[y - 1][x] + 1
else:
dp[y][x] = dp[y - 1][x]
elif y == 0:
if s[y][x] == "#" and s[y][x - 1] == ".":
dp[y][x] = dp[y][x - 1] + 1
else:
dp[y][x] = dp[y][x - 1]
else:
if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
elif s[y][x] == "#" and s[y][x - 1] == ".":
dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
elif s[y][x] == "#" and s[y - 1][x] == ".":
dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
else:
dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])
print(dp[-1][-1])
if __name__ == "__main__":
H, W = map(int, sys.stdin.readline().split())
s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
main()
|
def read_int():
return int(input())
def read_ints():
return map(int, input().split(' '))
r, c = read_ints()
s = []
for i in range(r):
s.append(input())
inf = int(1e9)
dp = [[inf for j in range(c)] for i in range(r)]
dp[0][0] = 1 if s[0][0] == '#' else 0
for i in range(r):
for j in range(c):
if i > 0:
dp[i][j] = dp[i - 1][j]
if s[i][j] == '#' and s[i - 1][j] == '.':
dp[i][j] += 1
if j > 0:
another = dp[i][j - 1]
if s[i][j] == '#' and s[i][j - 1] == '.':
another += 1
dp[i][j] = min(dp[i][j], another)
print(dp[r - 1][c - 1])
| 1 | 49,274,244,062,848 | null | 194 | 194 |
n = int(input())
ans = 0
if n % 2 == 0:
for i in range(1, 36):
k = 5**i*2
ans += n//k
print(ans)
else:
print(ans)
|
if __name__ == '__main__':
key_in = input()
data = [int(x) for x in key_in.split(' ')]
a = data[0]
b = data[1]
print('{0} {1} {2:.5f}'.format(a//b, a%b, a/b))
| 0 | null | 58,268,337,118,920 | 258 | 45 |
value = int(input())
print(value ** 3)
|
#!/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) ) ))
| 1 | 278,877,558,972 | null | 35 | 35 |
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
def main():
A, B, N = [int(i) for i in input().strip().split()]
ans = 0
if N >= B:
if A >= B:
n = range(B - 1, N + 1, B)[-1]
else:
n = range(B - 1, N + 1, B)[0]
ans = ((A * n) // B) - (A * (n // B))
else:
ans = ((A * N) // B) - (A * (N // B))
return ans
if __name__ == "__main__":
print(main())
|
import math
A, B, N = map(int, input().split())
x = 0
if N < B:
x = N
else:
x = B - 1
print(math.floor(A * x / B) - A * math.floor(x / B))
| 1 | 28,250,255,172,092 | null | 161 | 161 |
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
N = I()
S = _S()
alpha = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
ans = ""
for s in S:
ind = (alpha.index(s)+N) if (alpha.index(s)+N)<26 else (alpha.index(s)+N)-26
ans += alpha[ind]
print(ans)
main()
|
N = int(input())
X_list = list(map(int, input().split()))
X_list_min = sorted(X_list)
ans = 10**8+1
for i in range(X_list_min[0], X_list_min[-1]+1):
ans_temp = 0
for j in range(N):
ans_temp += (X_list_min[j] - i)**2
ans = min(ans, ans_temp)
print(ans)
| 0 | null | 99,573,622,284,530 | 271 | 213 |
def main():
N = int(input())
A = list(map(int, input().split()))
if 1 not in A:
print(-1)
exit()
next = 1
for a in A:
if a == next:
next += 1
print(N - next + 1)
if __name__ == '__main__':
main()
|
N=int(input())
A=list(map(int,input().split()))
count=0
num=1
for i in range(N):
if A[i]==num:
count+=1
num+=1
if count==0:
print(-1)
else:
print(N-count)
| 1 | 114,596,670,996,848 | null | 257 | 257 |
while True:
a, b = map(int, raw_input().split(' '))
if a == 0 and b == 0:
break
for i in range(a):
print "#" * b
print ''
|
N = int(input())
s = input()
if N % 2 == 1:
print("No")
elif s[0:N//2] != s[N//2:]:
print("No")
else:
print("Yes")
| 0 | null | 74,188,268,686,400 | 49 | 279 |
n,k=map(int,input().split())
m=10**9+7
k=min(k,n-1)
t,c,h=1,1,1
for i in range(1,k+1):
p=pow(i,m-2,m)
c=(c*(n-i+1)* p)%m
h=(h*(n-i) * p)%m
t=(t+c*h)%m
print(t%m)
|
import sys
rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
flag = False
s = rr()
q = ri()
front = ''
end = ''
for _ in range(q):
query = list(rs())
if query[0] == '1':
flag = not flag
continue
else:
f = int(query[1])
c = query[-1]
if flag == True:
if f == 1:
end += c
else:
front = c+front
else:
if f == 1:
front = c+front
else:
end += c
if flag:
print((front+s+end)[::-1])
else:
print(front+s+end)
| 0 | null | 62,105,735,092,320 | 215 | 204 |
inps = input().split()
if len(inps) >= 2:
a = int(inps[0])
b = int(inps[1])
if a > b:
print("a > b")
elif a < b:
print("a < b")
else:
print("a == b")
else:
print("Input illegal.")
|
nums = input().split()
a = int(nums[0])
b = int(nums[1])
if a < b:
print('a < b')
elif a > b:
print('a > b')
else:
print('a == b')
| 1 | 360,094,628,462 | null | 38 | 38 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.