code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
S = LS2()
r = 0
left,right = [],[]
Q = I()
for i in range(Q):
A = LS()
if A[0] == '1':
r = 1-r
else:
f,c = A[1],A[2]
if (r == 0 and f == '1') or (r == 1 and f == '2'):
left.append(c)
else:
right.append(c)
if r == 0:
left.reverse()
print(''.join(left+S+right))
else:
S.reverse()
right.reverse()
print(''.join(right+S+left))
| from random import choice
class dice:
def __init__(self, X):
self.x = [0] * 6
self.x[0] = X[0]
self.x[1] = X[1]
self.x[2] = X[2]
self.x[3] = X[3]
self.x[4] = X[4]
self.x[5] = X[5]
def roll(self, d):
if d == 'S':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[4], self.x[0], self.x[2], self.x[3], self.x[5], self.x[1]
elif d == 'E':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[3], self.x[1], self.x[0], self.x[5], self.x[4], self.x[2]
elif d == 'W':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[2], self.x[1], self.x[5], self.x[0], self.x[4], self.x[3]
elif d == 'N':
self.x[0], self.x[1], self.x[2], self.x[3], self.x[4], self.x[5] = \
self.x[1], self.x[5], self.x[2], self.x[3], self.x[0], self.x[4]
X = list(map(int, input().split()))
n = int(input())
dice1 = dice(X)
distances = ['S', 'E', 'W', 'N']
for i in range(n):
x1, x2 = map(int, input().split())
while True:
d = choice(distances)
dice1.roll(d)
if dice1.x[0] == x1 and dice1.x[1] == x2:
print(dice1.x[2])
break
| 0 | null | 28,959,621,898,080 | 204 | 34 |
def main():
A,B,K = map(int, input().split())
if A>=K:
print(*[A-K,B])
elif A+B>=K:
print(*[0,B-(K-A)])
else:
print(*[0,0])
main()
| r=input().split()
A=int(r[0])
B=int(r[1])
K=int(r[2])
if K>=A+B:
print("0 0")
elif K>=A:
print("0 "+str(B-K+A))
else:
print(str(A-K)+" "+str(B)) | 1 | 104,388,908,353,532 | null | 249 | 249 |
import re
n = int(input())
s = input()
res = re.findall(r'ABC',s)
print(len(res)) | N = int(input())
S = list(str(input()))
t = 0
for i in range(len(S)):
if S[i] == 'C' and S[i-1] == 'B' and S[i-2] == 'A':
t += 1
print(t) | 1 | 99,222,059,774,318 | null | 245 | 245 |
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()
def main():
s = deque(input())
q = int(input())
reverse = False
for _ in range(q):
query = list(input().split())
if query[0] == '1':
reverse ^= True
else:
if reverse:
if query[1] == '1':
s.append(query[2])
else:
s.appendleft(query[2])
else:
if query[1] == '1':
s.appendleft(query[2])
else:
s.append(query[2])
s = ''.join(s)
if reverse:
s = s[::-1]
print(s)
if __name__ == '__main__':
main() | import sys
for v in iter(sys.stdin.readline,""):
a,op,b = v.split()
a = int(a)
b = int(b)
if op == '+':
print(a+b)
elif op == '-':
print(a-b)
elif op == '*':
print(a*b)
elif op == '/':
print(a/b)
elif op == '?':
break | 0 | null | 29,039,105,086,880 | 204 | 47 |
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for x in range(N-1):
B[A[x]-1] += 1
for y in range(N):
print(B[y]) | import math
a,b,C=map(float,input().split())
print(f'{a*b/2*math.sin(math.radians(C)):.6f}')
print(f'{a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5:.6f}')
print(f'{b*math.sin(math.radians(C)):.6f}')
| 0 | null | 16,371,785,396,172 | 169 | 30 |
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.append(N + 1)
ans = [0] * (N+1)
count = [0, 0]
for i in range(N):
if count[0] == A[i]:
count[1] += 1
else:
ans[count[0]] = count[1]
count[0] = A[i]
count[1] = 1
for j in range(1, N+1):
print(ans[j]) | N = int(input())
A = [int(i) for i in input().split()]
ans = [0 for i in range(N)]
for i in A:
ans[i-1] += 1
for i in ans:
print(i) | 1 | 32,745,104,460,530 | null | 169 | 169 |
while(1):
x,y = map(int, raw_input().split())
if x == 0 and y == 0:
break;
if x > y:
temp = x
x = y
y = temp
print x, y | import sys
def solve():
a = []
for line in sys.stdin:
digit_list = line.split(' ')
new_list = []
for s in digit_list:
new_list.append(int(s))
a.append((new_list))
for j in a:
print str(len(str(sum(j))))
if __name__ == '__main__':
solve() | 0 | null | 259,747,661,390 | 43 | 3 |
import math
r = float(input())
if r > 0 and r < 10000:
circle_length = (r * 2) * math.pi
circle_area = r * r * math.pi
print("{0:f} {1:f}".format(circle_area, circle_length))
else:
pass | import math
r = input()
S = math.pi * r ** 2
L = math.pi * r * 2
print "%f %f" %(S, L) | 1 | 653,184,855,552 | null | 46 | 46 |
N,M,X=[int(s) for s in input().split()]
Book=[[int(s) for s in input().split()] for _ in range(N)]
INF=10**7
ans=set()
ans.add(INF)
#深さ優先探索
def DFS(n,cost,Xls):
if n==N:
if min(Xls)>=X:
ans.add(cost)
else:
Xnext=[Xls[i]+Book[n][i+1] for i in range(M)]
DFS(n+1,cost+Book[n][0],Xnext)
DFS(n+1,cost,Xls)
DFS(0,0,[0 for _ in range(M)])
if min(ans)==INF:
print(-1)
else:
print(min(ans)) | #他の人の回答
n, m, x = map(int, input().split())
ca = [list(map(int,input().split())) for _ in range(n)]
add = []
for i in range(2**n):
skill = [0]*(m+1)
for j in range(n):
if ((i>>j) & 1):
skill = list(map(sum, zip(skill, ca[j])))
if min(skill[1:])>=x:
add.append(skill)
if add:
add.sort()
print(add[0][0])
else:
print(-1) | 1 | 22,343,749,980,380 | null | 149 | 149 |
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse = True)
ans = 0
for i in range(len(l)):
for j in range(i+1,len(l)):
for k in range(j+1,len(l)):
if l[i] != l[j] != l[k] and l[i] < l[j] + l[k]:
ans +=1
print(ans) | N=int(input())
L=list(map(int,input().split()))
count=0
for a in range(N):
for b in range(N):
for c in range(N):
if L[a]<(L[b]+L[c]) and L[b]<(L[a]+L[c]) and L[c]<(L[b]+L[a]) and L[a]!=L[b] and L[a]!=L[c] and L[c]!=L[b] and a<b<c:
count=count+1
else:
continue
print(count) | 1 | 5,017,200,027,800 | null | 91 | 91 |
#Digit Number
while True:
try:
i, n = input(). split()
m = str(int(i) + int(n))
print(len(m))
except:
break | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
while True:
try:
num = eval(input().replace(" ","+"))
except:
return
else:
print(len(str(num)))
if __name__ == '__main__':
main() | 1 | 86,858,320 | null | 3 | 3 |
N,K,C=map(int,input().split())
S=input()
def check0(S0):
count=0
index=0
out=[0]*K
while count<K and index<N:
if S0[index]=='o':
out[count]=index
count+=1
index+=(C+1)
else:
index+=1
if count==K:
return 1,out
return 0,out
def checkend(S0):
count=0
index=N-1
out=[0]*K
while count<K and index>=0:
if S0[index]=='o':
out[K-1-count]=index
count+=1
index-=(C+1)
else:
index-=1
if count==K:
return 1,out
return 0,out
flag0,out0=check0(S)
flagend,outend=checkend(S)
if flag0==1:
for i in range(K):
if out0[i]==outend[i]:
print(out0[i]+1) | a, b, m = map(int, input().split())
reizo = list(map(int, input().split()))
renji = list(map(int, input().split()))
p = [list(map(int,input().split())) for i in range(m)]
ans = []
for i in range(m):
cost = reizo[p[i][0] - 1] + renji[p[i][1] - 1] - p[i][2]
ans.append(cost)
ans.append(min(reizo) + min(renji))
print(min(ans)) | 0 | null | 47,556,801,521,440 | 182 | 200 |
def main():
a, b = map(int,input().split())
print( a* b)
return
main() | x, y = [int(x) for x in input().split()]
print(x*y)
| 1 | 15,775,573,476,640 | null | 133 | 133 |
#AGC043-A
h,w = map(int,input().split())
grid = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
dp[0][0] = 1 if grid[0][0] == "#" else 0
#進む前の相対位置
d = [(-1, 0), (0, -1)]
for i in range(h):
for j in range(w):
if i == 0 and j == 0:
pass
else:
tmp = 1000
for k in d:
bx,by = j+k[0],i+k[1]
if 0 <= bx <w and 0 <= by < h:
if grid[i][j] == '#' and grid[by][bx] == '.':
tmp = dp[by][bx] + 1
else:
tmp = dp[by][bx]
dp[i][j] = min(dp[i][j],tmp)
print(dp[-1][-1]) | H,W = map(int, input().split())
S = [input() for _ in range(H)]
inf = 10**6
L = [[inf]*W for _ in range(H)]
if S[0][0] == ".":
L[0][0] = 0
else:
L[0][0] = 1
for i in range(H):
for j in range(W):
n1 = inf
n2 = inf
if i > 0:
if S[i-1][j] == "." and S[i][j] == "#":
n1 = L[i-1][j] + 1
else:
n1 = L[i-1][j]
if j > 0:
if S[i][j-1] == "." and S[i][j] == "#":
n2 = L[i][j-1] + 1
else:
n2 = L[i][j-1]
L[i][j] = min(L[i][j], n1, n2)
print(L[-1][-1]) | 1 | 49,198,068,317,662 | null | 194 | 194 |
N = int(input())
A = list(map(int,input().split()))
B = [i for i in range(1,N+1)]
C = zip(A, B)
C = sorted(C, reverse = True)
A, B = zip(*C)
dp = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
for j in range(i + 2):
if j == 0:
dp[0][i-j+1] = dp[0][i-j] + A[i] * (N - (i - j) - B[i])
elif j == i+1:
dp[j][0] = dp[j-1][0] + A[i] * (B[i] - j)
else:
dp[j][i-j+1] = max(dp[j][i-j] + A[i] * (N - (i - j) - B[i]), dp[j-1][i-j+1] + A[i] * (B[i] - j))
ans = 0
for i in range(N+1):
ans = max(ans, dp[i][N-i])
print(ans) | N,K=map(int,input().split())
H=list(map(int,input().split()))
H.sort()
for _ in range(min(N,K)): H.pop()
print(sum(H)) | 0 | null | 56,305,252,590,662 | 171 | 227 |
#!/usr/bin/env python3
from pprint import pprint
import sys
sys.setrecursionlimit(10 ** 6)
H, W, M = map(int, input().split())
num_bombs_each_row = [0] * H
num_bombs_each_col = [0] * W
bombs = set()
for _ in range(M):
h, w = map(int, input().split())
# 0-index
h -= 1
w -= 1
bombs.add((h, w))
num_bombs_each_row[h] += 1
num_bombs_each_col[w] += 1
max_bombs_in_row = max(num_bombs_each_row)
max_bombs_in_col = max(num_bombs_each_col)
rows_with_max_bombs = []
for row in range(H):
if num_bombs_each_row[row] == max_bombs_in_row:
rows_with_max_bombs.append(row)
cols_with_max_bombs = []
for col in range(W):
if num_bombs_each_col[col] == max_bombs_in_col:
cols_with_max_bombs.append(col)
found = False
for row in rows_with_max_bombs:
for col in cols_with_max_bombs:
if (row, col) not in bombs:
found = True
break
ans = max_bombs_in_row + max_bombs_in_col
if found:
print(ans)
else:
print(ans - 1)
| H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
h,w=map(int,input().split())
nh[h-1] += 1
nw[w-1] += 1
boms.add((h-1, w-1))
maxh = max(nh)
maxw = max(nw)
i_indexes=[]
for i in range(H):
if nh[i] == maxh:
i_indexes.append(i)
j_indexes=[]
for j in range(W):
if nw[j] == maxw:
j_indexes.append(j)
for i in i_indexes:
for j in j_indexes:
if (i,j) in boms:
continue
print(maxh + maxw)
exit()
print(maxh + maxw - 1) | 1 | 4,686,287,874,052 | null | 89 | 89 |
rc=list(map(int,input().split()))
sheet=[list(map(int,input().split()))+[0] for i in range(rc[0])]
sheet.append([0 for i in range(rc[1]+1)])
for s in sheet:
s[-1]=sum(s[0:-1])
for i in range(rc[1]+1):
r=sum([n[i] for n in sheet[0:-1]])
sheet[-1][i]=r
for sh in sheet:
print(*sh) | r_c_str=input().split()
r_c=list(map(lambda i :int(i),r_c_str))
r=r_c[0]
c=r_c[1]
s_str=[input() for i in range(r)]
s_str=[i.split() for i in s_str]
s=[]
for i in s_str:
s.append(list(map(lambda j :int(j),i)))
for i in range(r):
s[i].append(sum(s[i]))
s.append([])
for i in range(c+1):
s[-1].append(0)
for i in range(c):
for j in range(r):
s[r][i]+=s[j][i]
s[-1][-1]+=sum(s[r])
for i in s:
print(*i)
| 1 | 1,347,744,282,148 | null | 59 | 59 |
n = int(raw_input())
in_line = raw_input().split()
a = []
for i in in_line:
a.append(int(i))
a.sort()
print a[0],
print a[len(a)-1],
print sum(a) | n = int(input())
a = list(map(int, input().split()))
ans = []
ans.append(min(a))
ans.append(max(a))
ans.append(sum(a))
print(" ".join(map(str, ans)))
| 1 | 727,045,838,512 | null | 48 | 48 |
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
INF = 1 << 60
dp = [INF] * (h + 1)
dp[0] = 0
for i in range(0, h + 1):
# hを超えるために必要な最小コストは?
for a, b in ab:
if i + a <= h:
dp[i + a] = min(dp[i] + b, dp[i + a])
else:
dp[h] = min(dp[i] + b, dp[h])
print(dp[h]) | h,n=map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
max_a=max(a)
dp=[float("inf")]*(h+max_a+1)
dp[0]=0
for i in range(h):
for j in range(n):
dp[i+a[j]] = min(dp[i+a[j]], dp[i]+b[j])
print(min(dp[h:])) | 1 | 81,319,675,429,472 | null | 229 | 229 |
n,k = map(int, input().split())
h = [int(x) for x in input().split()]
if n<=k:
print(0)
exit()
h.sort()
print(sum(h[:n-k])) | # ????????? n ?¬?????????????????????????p ??????????????? 1???2???3????????? ?????????????????????????????¢????±???????????????°??????
import math
# ?¬??????°n????¨??????\???????????????
n = int(input())
# ????????????x????¨??????\???????????????
x = list(input())
x = "".join(x).split()
# ????????????y????¨??????\???????????????
y = list(input())
y = "".join(y).split()
# p=1,2,????????§???????????????????????????????????¢???????´?????????????
# ?????????????????????
dxy = [0 for i in range(4)]
# p=1???????????????????????????????????¢????¨????
for i in range(0, n):
dxy[0] += math.fabs(int(x[i]) - int(y[i]))
# p=2
for i in range(0, n):
dxy[1] += (math.fabs(int(x[i]) - int(y[i]))) ** 2
dxy[1] = math.sqrt(dxy[1])
# p=3
for i in range(0, n):
dxy[2] += (math.fabs(int(x[i]) - int(y[i]))) ** 3
dxy[2] = math.pow(dxy[2], 1.0 / 3.0)
# p=????????§
dxy[3] = math.fabs(int(x[0]) - int(y[0]))
for i in range(1, n):
if dxy[3] < math.fabs(int(x[i]) - int(y[i])):
dxy[3] = math.fabs(int(x[i]) - int(y[i]))
# ??????
for i in range(0, 4):
print("{0}".format(dxy[i])) | 0 | null | 39,461,296,305,090 | 227 | 32 |
n=int(input())
l0=[[] for _ in range(n)]
l1=[[] for _ in range(n)]
for i in range(n):
a=int(input())
for j in range(a):
x,y=map(int,input().split())
if y==0:
l0[i].append(x)
else:
l1[i].append(x)
ans=0
for i in range(2**n):
s0=set()
s1=set()
num=0
num1=[]
num0=[]
for j in range(n):
if (i>>j) & 1:
num1.append(j+1)
for k in range(len(l0[j])):
s0.add(l0[j][k])
for k in range(len(l1[j])):
s1.add(l1[j][k])
else:
num0.append(j+1)
for j in range(len(s1)):
if s1.pop() in num0:
num=1
break
if num==0:
for j in range(len(s0)):
if s0.pop() in num1:
num=1
break
if num==0:
ans=max(ans,len(num1))
print(ans)
| N = int(input())
T = []
try:
while True:
t = input()
t=int(t)
T_temp=[]
for t_ in range(t) :
temp = list(map(int,input().split()))
T_temp.append(temp)
T.append(T_temp)
except EOFError:
pass
def check_Contradiction(true_list):
S = {}
for n in range(N):
if n in true_list:
S[n]=set([1])
else:
S[n]=set([0])
for t in true_list:
for T_ in T[t]:
S[T_[0]-1].add(T_[1])
ok=True
for s in S.keys():
if len(S[s])!=1:
ok='False'
break
return ok
ok_max = -1
for i in range(2**N):
# print('=====',i)
true_list=[]
for j in range(N):
if i>>j&1 ==True:
true_list.append(j)
# print(true_list)
# print(check_Contradiction(true_list))
if check_Contradiction(true_list)==True:
if ok_max < len(true_list):
ok_max=len(true_list)
print(ok_max) | 1 | 121,128,431,397,820 | null | 262 | 262 |
from collections import Counter
def main():
H, W, M = list(map(int, input().split()))
bombs = [list(map(int, input().split())) for _ in range(M)]
counter_row = Counter([h for h, _ in bombs])
val_max_row, max_rows = 0, []
for h, v in counter_row.items():
if val_max_row < v:
val_max_row = v
max_rows = [h]
elif val_max_row == v:
max_rows.append(h)
counter_col = Counter([w for _, w in bombs])
val_max_col, max_cols = 0, []
for w, v in counter_col.items():
if val_max_col < v:
val_max_col = v
max_cols = [w]
elif val_max_col == v:
max_cols.append(w)
# 基本的には val_max_row + val_max_col が答え。
# 行・列で重複カウントになるケースだった場合はここから1引かないといけない。
max_rows = Counter(max_rows)
max_cols = Counter(max_cols)
n_max_cells = len(max_rows.keys()) * len(max_cols.keys())
n_cells = 0
for h, w in bombs:
if max_rows[h] > 0 and max_cols[w] > 0:
n_cells += 1
ans = val_max_row + val_max_col
if n_cells >= n_max_cells:
ans -= 1
print(ans)
if __name__ == '__main__':
main() | from sys import stdin
import collections
input = stdin.readline
Y, X, M = map(int, input().split())
bomb = set([tuple(map(int,inp.split())) for inp in stdin.read().splitlines()])
cx = collections.defaultdict(int)
cy = collections.defaultdict(int)
for y,x in bomb:
cx[x] += 1
cy[y] += 1
mx = max(cx.values())
my = max(cy.values())
candidateX = [x for (x,v) in cx.items() if v == mx]
candidateY = [y for (y,v) in cy.items() if v == my]
res = mx + my -1
for x in candidateX:
for y in candidateY:
if (y,x) not in bomb:
res += 1
break
else:
continue
break
print(res) | 1 | 4,783,715,393,380 | null | 89 | 89 |
i = range(1,10)
for i in ['%dx%d=%d' % (x,y,x*y) for x in i for y in i]:
print i | x,y=list(map(int,raw_input().split()))
w=x
h=y
if x==1 or y==1:
print("1")
exit(0)
ans=x//2 * (h//2 + (h+1)//2)
if x%2==1:
ans+=(h+1)//2
print(ans) | 0 | null | 25,300,845,716,618 | 1 | 196 |
n=int(input())
H=[]
T=[]
for i in range (n):
a=list(map(str, input().split()))
if a[0]>a[1] :
H.append(3)
elif a[0]<a[1] :
T.append(3)
else :
H.append(1)
T.append(1)
print(sum(H), sum(T))
| n = int(input())
a = 0
b = 0
for _ in range(n):
word_a, word_b = input().split()
words = [word_a, word_b]
words.sort()
if word_a == word_b:
a += 1
b += 1
elif words.index(word_a) == 1:
a += 3
else:
b += 3
print(a, b) | 1 | 1,981,204,724,494 | null | 67 | 67 |
N = int(input())
st = [list(input().split()) for _ in range(N)]
kyoku = input()
flg = False
ans = 0
for s, t in st:
if flg:
ans += int(t)
if s == kyoku:
flg = True
print(ans) | n = int(input())
s, t = [], []
for i in range(n):
si, ti = input().split()
ti = int(ti)
s.append(si)
t.append(ti)
x = input()
bit = 0
ans = 0
for i in range(n):
if s[i] == x:
bit = 1
else:
if bit == 1:
ans += t[i]
print(ans) | 1 | 96,831,508,821,798 | null | 243 | 243 |
import os, sys, re, math
(A, B) = [int(n) for n in input().split()]
print(max(A - B * 2, 0))
| A, B = list(map(int, input().split()))
ans = A - B*2
if ans <= 0:
print(0)
else:
print(A-B*2) | 1 | 166,764,262,966,500 | null | 291 | 291 |
n = int(input())
p = list(map(int,input().split()))
m = n
q = 2 * (10 ** 5)
for i in range(n):
q = min(p[i],q)
if not p[i] <= q:
m -= 1
print(m) | a = str(input())
if a[0] == a[1] != a[2]:
print("Yes")
elif a[1] == a[2] != a[0]:
print("Yes")
elif a[0] == a[2] != a[1]:
print("Yes")
else:
print("No") | 0 | null | 69,802,985,470,708 | 233 | 201 |
n,k,s = map(int,input().split(" "))
ar = []
for i in range(k):
ar.append(s)
for i in range(n-k):
if s == 10 ** 9:
ar.append(1)
else:
ar.append(s + 1)
for i in range(n-1):
print(ar[i],end=" ")
print(ar[n-1]) | n,k,s = map(int,input().split())
u = []
if n == k:
for i in range(n):
u.append(s)
else:
if s%2==0:
for i in range(k+1):
u.append(int(s/2))
for i in range(n-k-1):
u.append(10**9-1)
else:
if s==1:
for i in range(k):
u.append(1)
for i in range(n-k):
u.append(10**9)
else:
if k%2==0:
u.append(int((s-1)/2))
for i in range(int(k/2)):
u.append(int((s+1)/2))
u.append(int((s-1)/2))
for i in range(n-k-1):
u.append(10**9)
else:
for i in range(int((k+1)/2)):
u.append(int((s+1)/2))
u.append(int((s-1)/2))
for i in range(n-k-1):
u.append(10**9)
print(' '.join(map(str,u))) | 1 | 91,025,452,009,100 | null | 238 | 238 |
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, B = map(int, input().split())
# リストのlcm
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
print(lcm_base(A, B)) | def gcd(a,b):
if b ==0:
return a
else:
return gcd(b, a%b)
A,B = map(int, input().split())
A,B = (A,B) if A>B else (B,A)
print(int(A/gcd(A,B)*B)) | 1 | 113,175,527,098,432 | null | 256 | 256 |
S=input()
ans=0
if 'R' in S:
ans+=1
if S[0]=='R' and S[1]=='R':
ans+=1
if S[1]=='R' and S[2]=='R':
ans+=1
print(ans)
| N, K = list(map(int, input().split()))
C = 10**9+7
ans = 0
A = sum(list(range(N, N-K, -1)))
B = sum(list(range(K)))
for i in range(K, N+2):
# print(A,B)
ans += A-B+1
A += N-i
B += i
ans %= C
print(ans) | 0 | null | 19,092,666,127,990 | 90 | 170 |
def main():
S = list(input())
T = []
reverse = False
n_q = int(input())
for i in range(n_q):
q = input().split(" ")
if q[0] == "1":
reverse = not reverse
elif q[0] == "2":
f = q[1]
c = q[2]
if (f == "1" and not reverse) or (f == "2" and reverse):
T.append(c)
elif (f == "1" and reverse) or (f == "2" and not reverse):
S.append(c)
if reverse:
S.reverse()
ans = S + T
elif not reverse:
T.reverse()
ans = T + S
print("".join(ans))
main() | n,*a=map(int,open(0).read().split())
print('NYOE S'[len(set(a))==n::2]) | 0 | null | 65,723,117,556,808 | 204 | 222 |
X = int(input())
happy = 0
happy += (X // 500) * 1000
happy += ((X - X // 500 * 500) // 5) * 5
print(happy) | S = str(input())
print('No') if S == 'AAA' or S == 'BBB' else print('Yes') | 0 | null | 48,649,545,279,488 | 185 | 201 |
n,m = map(int,input().split())
v1 = [ list(map(int,input().split())) for i in range(n) ]
v2 = [ int(input()) for i in range(m) ]
for v in v1:
print( sum([ v[i] * v2[i] for i in range(m) ])) | def selectionSort(A,N):
count=0
for i in range(N):
minj = i
for j in range(i,N):
if A[j] < A[minj]:
minj = j
A[i],A[minj] = A[minj],A[i]
if i != minj:
count +=1
return A,count
N = int(input())
A = list(map(int,input().split()))
A,count = selectionSort(A,N)
print(" ".join(map(str,A)))
print("%d"%(count))
| 0 | null | 606,244,886,452 | 56 | 15 |
#B問題
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(0,len(A)):
for j in range(i+1,len(A)):
for k in range(j+1,len(A)):
if A[i] + A[j] > A[k] and A[j] + A[k] > A[i] and A[k] + A[i] > A[j] and A[i] != A[j] and A[j] != A[k] and A[k] != A[i] :
ans += 1
print(ans) | import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
n,u,v=map(int,input().split())
node=[[]for _ in range(n)]
for _ in range(n-1):
a,b=map(int,input().split())
node[a-1].append(b-1)
node[b-1].append(a-1)
def dfs(i):
visited[i]=1
for x in node[i]:
if visited[x]==0:
dis[x]=dis[i]+1
dfs(x)
inf=10**9
dis=[inf]*n;dis[u-1]=0;visited=[0]*n
dfs(u-1)
dis2=[]
from copy import copy
dis_dash=copy(dis)
dis2.append(dis_dash)
dis[v-1]=0;visited=[0]*n
dfs(v-1)
dis2.append(dis)
cnt=0
for i in range(n):
if dis2[0][i]<dis2[1][i]:
cnt=max(cnt,dis2[1][i])
print(cnt-1) | 0 | null | 61,277,845,391,800 | 91 | 259 |
def main():
s,t = input().split(" ")
a, b = map(int, input().split(" "))
u = input()
if u == s :
a-= 1
else:
b -= 1
print(f"{a} {b}")
if __name__ == "__main__":
main() | cnt = int(input())
string = input()
if len(string) <= cnt:
print(string)
else:
print(string[:cnt] + "...") | 0 | null | 45,994,453,908,874 | 220 | 143 |
while True:
m,f,r = map(int, input().split())
if m==-1 and f==-1 and r==-1:
break
if m==-1 or f==-1:
print('F')
elif m+f>=80:
print('A')
elif 65<=m+f:
print('B')
elif 50<=m+f:
print('C')
elif 30<=m+f:
if r>=50:
print('C')
else:
print('D')
else:
print('F')
| while True:
m, f, r = map(int, input().split())
score = m + f
if m == f == r == -1:
break
elif m == -1 or f == -1:
print('F')
elif score >= 80:
print('A')
elif score >= 65:
print('B')
elif score >= 50 or (score >= 30 and r >= 50):
print('C')
elif score >= 30:
print('D')
else:
print('F')
| 1 | 1,245,242,865,262 | null | 57 | 57 |
a,b,c = map(int,input().split())
k = int(input())
for i in range(k):
if a >= b:
b *= 2
else:
c *= 2
print("Yes" if a < b and b < c else "No")
| import itertools as it
a,b,c = map(int,input().split())
k = int(input())
allcase = list(it.product([0,1,2,3],repeat=k))
for case in allcase:
nums = [a,b,c]
for step in case:
if step == 3:
continue
nums[step] *= 2
if nums[0] < nums[1] and nums[1] < nums[2]:
print('Yes')
exit()
print('No') | 1 | 6,920,854,696,522 | null | 101 | 101 |
N = int(input())
def cnt(n):
c = 0
for i in range(1, N+1):
n = N // i
j = i * n
c += (i + j) * n // 2
return c
print(cnt(N)) | import sys
n = int(input())
command = sys.stdin.readlines()
Q = {}
for i in range(n):
a,b = command[i].split()
if a == "insert":
Q[b] = 0
else:
if b in Q.keys():
print("yes")
else:
print("no") | 0 | null | 5,496,918,691,668 | 118 | 23 |
from collections import deque
h, w = map(int, input().split())
s = []
for i in range(h):
s.append(list(input()))
def bfs(x, y):
if s[y][x] == '#':
return 0
queue = deque()
queue.appendleft([x, y])
visited = dict()
visited[(x, y)] = 0
while queue:
nx, ny = queue.pop()
cur = visited[(nx, ny)]
if nx - 1 >= 0 and (nx - 1, ny) not in visited:
if s[ny][nx - 1] == '.':
visited[(nx - 1, ny)] = cur + 1
queue.appendleft((nx - 1, ny))
if nx + 1 < w and (nx + 1, ny) not in visited:
if s[ny][nx + 1] == '.':
visited[(nx + 1, ny)] = cur + 1
queue.appendleft((nx + 1, ny))
if ny - 1 >= 0 and (nx, ny - 1) not in visited:
if s[ny - 1][nx] == '.':
visited[(nx, ny - 1)] = cur + 1
queue.appendleft((nx, ny - 1))
if ny + 1 < h and (nx, ny + 1) not in visited:
if s[ny + 1][nx] == '.':
visited[(nx, ny + 1)] = cur + 1
queue.appendleft((nx, ny + 1))
return max(visited.values())
result = 0
for i in range(h):
for j in range(w):
r = bfs(j, i)
result = max(result, r)
print(result)
| h, w = map( int, input().split() )
s = []
for _ in range( h ):
s_i = list( str( input() ) )
s.append( s_i )
def connect( v ):
con_v = []
if v[ 0 ] > 0:
if s[ v[ 0 ] - 1 ][ v[ 1 ] ] == ".":
con_v.append( ( v[ 0 ] - 1, v[ 1 ] ) )
if v[ 1 ] > 0:
if s[ v[ 0 ] ][ v[ 1 ] - 1 ] == ".":
con_v.append( ( v[ 0 ], v[ 1 ] - 1 ) )
if v[ 0 ] < h - 1:
if s[ v[ 0 ] + 1 ][ v[ 1 ] ] == ".":
con_v.append( ( v[ 0 ] + 1, v[ 1 ] ) )
if v[ 1 ] < w - 1:
if s[ v[ 0 ] ][ v[ 1 ] + 1 ] == ".":
con_v.append( ( v[ 0 ], v[ 1 ] + 1 ) )
return con_v
from heapq import heappush, heappop
INF = 10 ** 10
VISITED = 1
NOT_VISITED = 0
def longest_bfs( i, j ):
cost = [ INF for _ in range( h * w ) ]
cost[ i * w + j ] = 0
visit = [ NOT_VISITED for _ in range( h * w ) ]
queue = [ ( 0, ( i, j ) ) ]
while len( queue ) > 0:
c, v = heappop( queue )
visit[ v[ 0 ] * w + v[ 1 ] ] = VISITED
for u in connect( v ):
if visit[ u[ 0 ] * w + u[ 1 ] ] == VISITED:
continue
if cost[ u[ 0 ] * w + u[ 1 ] ] > cost[ v[ 0 ] * w + v[ 1 ] ] + 1:
cost[ u[ 0 ] * w + u[ 1 ] ] = cost[ v[ 0 ] * w + v[ 1 ] ] + 1
heappush( queue, ( cost[ u[ 0 ] * w + u[ 1 ] ], u ) )
return cost
longest_path = 0
for i in range( h ):
for j in range( w ):
if s[ i ][ j ] == "#":
continue
path_length = longest_bfs( i, j )
for p in path_length:
if p < INF and p > longest_path:
longest_path = p
print( longest_path ) | 1 | 94,738,417,613,320 | null | 241 | 241 |
n,m=map(int,input().split())
A = list(map(int,input().split()))
A.sort()
A = A[::-1]
for i in range(m):
if A[i]*4*m < sum(A):
print("No")
break
else:
print("Yes") | n, m = map(int, input().split())
a = list(map(int, input().split()))
num = sum(a)
cnt = 0
for i in range(n):
if a[i] < num/(4*m):
continue
else:
cnt += 1
if cnt >= m:
print("Yes")
else:
print("No") | 1 | 38,422,298,449,410 | null | 179 | 179 |
count = 0
for i in range(10000):
a = input()
a = int(a)
if a >= 1:
count += 1
print('Case '+str(count)+': '+str(a))
else:
break
| S = input()
a = ['x']*len(S)
print(''.join(a)) | 0 | null | 36,746,137,468,920 | 42 | 221 |
n,m=[int(x) for x in input().split()]
A=[[0 for i in range(m)] for i in range(n)]
vector=[0 for i in range(m)]
result=[0 for i in range(n)]
for i in range(n):
A[i]=[int(x) for x in input().split()]
for i in range(m):
vector[i]=int(input())
for i in range(n):
for j in range(m):
result[i] += A[i][j]*vector[j]
for _ in result:
print(_) | Str = input()
q = int(input())
for i in range(q):
order = list(input().split())
o = order[0]
a = int(order[1])
b = int(order[2])
if o=='print':
print(Str[a:b+1])
if o=='reverse':
StrL = list(Str)
t = list(Str[a:b+1])
j = len(t)-1
for i in range(a,b+1):
StrL[i] = t[j]
j -= 1
Str = ''.join(StrL)
if o=='replace':
p = list(order[3])
StrL = list(Str)
j = 0
for i in range(a,b+1):
StrL[i] = p[j]
j += 1
Str = ''.join(StrL)
| 0 | null | 1,603,587,291,780 | 56 | 68 |
import math
a,b,c,d = map(float,input().split())
print(math.sqrt(((c-a)**2) + ((d-b)**2)))
| n = int(input())
nums = list(map(int, input().split()))
for i in range(len(nums)):
key = nums[i]
j = i - 1
while j >= 0 and nums[j] > key:
nums[j+1] = nums[j]
j -= 1
nums[j+1] = key
print(' '.join(map(str, nums))) | 0 | null | 83,355,641,186 | 29 | 10 |
N, K, S = map(int, input().split(" "))
ans = []
for i in range(K):
ans.append(S)
for i in range(N - K):
ans.append(10 ** 9 if S != 10 ** 9 else 1)
print(' '.join([str(a) for a in ans])) | #template
def inputlist(): return [int(j) for j in input().split()]
#template
li = inputlist()
for i in range(5):
if li[i] == 0:
print(i+1) | 0 | null | 52,432,329,971,362 | 238 | 126 |
k=int(input())
s=list(input())
num_list=[]
if k<len(s):
for x in range(k):
num_list+=s[x]
x+=1
t=''.join(num_list)+'...'
else:
t=''.join(s)
print(t) | n = int(input())
N = int(n/1.08)
for i in range(3):
if int((N + i) * 1.08) == n:
print(N+i)
break
else:
print(':(') | 0 | null | 72,500,719,706,952 | 143 | 265 |
x = range(1,10)
for i in x:
for j in x:
print u"%dx%d=%d"%(i, j, i*j) | while True:
c = input().split()
x, y = int(c[0]), int(c[1])
if x == y == 0:
break
if y < x:
x, y = y, x
print("%d %d" % (x, y))
| 0 | null | 252,918,389,910 | 1 | 43 |
N = int(input())
A = list(map(int, input().split()))
if N == 0 and A[0] == 1:
print(1)
exit(0)
elif A[0] > 0:
print(-1)
exit(0)
X = [0] * (N+1)
X[-1] = A[-1]
for i in range(N,0,-1):
X[i-1] = X[i] + A[i-1]
#print(X)
wk = 2
ans = 1
for i in range(1,N+1):
#print(i,X[i])
if 0 <= A[i] <= wk:
ans += min(wk,X[i])
wk -= A[i]
wk *= 2
else:
print(-1)
exit(0)
print(ans) | N = int(input())
A = [int(x) for x in input().split()]
B = [0]*(N+1)
if N == 0:
if A[0] != 1:
print(-1)
exit()
else:
print(1)
exit()
if A[0] != 0:
print(-1)
exit()
else:
B[0] = 1
C = [0]*(N+1)
C[0] = 1
for i in range(1,N+1):
C[i] = 2*(C[i-1] - A[i-1])
if C[i] < A[i]:
print(-1)
exit()
#print(C)
for i in range(N, 0, -1):
if i == N:
B[i] = A[i]
else:
B[i] = min(A[i]+B[i+1], C[i])
print(sum(B))
| 1 | 19,009,147,284,910 | null | 141 | 141 |
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB
A.insert(0, 0)
for i in range(1,len(A)):
A[i] += A[i-1]
for i in range(1, len(B)):
B[i] += B[i-1]
ans = 0
for i in range(len(A)):
rest_time = k - A[i]
if rest_time >= 0:
numb = bisect_right(B, rest_time)
anstmp = i + numb
ans = max(ans, anstmp)
print(ans) | ans=0
S=input()
a=len(S)
k=0
c=dict()
mod=2019
s=1
c[0]=1
for i in range(a):
k+=(s*int(S[a-i-1]))
k%=mod
s*=10
s%=mod
if k in c:
c[k]+=1
else:
c[k]=1
for i in c:
ans+=c[i]*(c[i]-1)//2
print(ans) | 0 | null | 20,663,147,196,832 | 117 | 166 |
import sys
input = sys.stdin.readline
def main():
T = list(input().rstrip())
ans = ["D" if c == "?" else c for c in T]
print("".join(ans))
if __name__ == "__main__":
main() | def puts(x, y):
print '{0}x{1}={2}'.format(x, y, x*y)
[puts(i ,j)
for i in range(1, 10)
for j in range(1, 10)] | 0 | null | 9,275,561,476,020 | 140 | 1 |
#AGC043-A
h,w = map(int,input().split())
grid = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
dp[0][0] = 1 if grid[0][0] == "#" else 0
#進む前の相対位置
d = [(-1, 0), (0, -1)]
for i in range(h):
for j in range(w):
if i == 0 and j == 0:
pass
else:
tmp = 1000
for k in d:
bx,by = j+k[0],i+k[1]
if 0 <= bx <w and 0 <= by < h:
if grid[i][j] == '#' and grid[by][bx] == '.':
tmp = dp[by][bx] + 1
else:
tmp = dp[by][bx]
dp[i][j] = min(dp[i][j],tmp)
print(dp[-1][-1]) | R = int(input())
print(int(R*R)) | 0 | null | 97,407,222,702,452 | 194 | 278 |
from collections import Counter
H, W, M = map(int, input().split())
dh, dw = Counter(), Counter()
used = set()
for _ in range(M):
h, w = map(int, input().split())
dh[h] += 1
dw[w] += 1
used.add((h, w))
ih = dh.most_common()
iw = dw.most_common()
s = ih[0][1] + iw[0][1]
ans = 0
for h, sh in ih:
for w, sw in iw:
if sh+sw < s or ans == s:
break
b = sh + sw - ((h, w) in used)
ans = max(ans, b)
print(ans)
| n = input()
m = 0
for i in range(len(n)):
m += int(n[i])
m %= 9
if m == 0:
print("Yes")
else:
print("No") | 0 | null | 4,513,552,207,248 | 89 | 87 |
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_rui = [0]
b_rui = [0]
counta = 0
countb = 0
for i in range(n):
a_rui.append(a_rui[i]+a[i])
if a_rui[i+1] <= k:
counta = i+1
for i in range(m):
b_rui.append(b_rui[i]+b[i])
if b_rui[i] <= k:
countb = i+1
# print(counta, countb)
# print(a_rui, b_rui)
ans = 0
for i in range(counta+1):
# print("DFGHj")
# print(i, countb)
while a_rui[i]+b_rui[countb] > k:
# print(a_rui[i]+b_rui[countb], i, countb)
countb -= 1
# print(i, countb)
ans = max(ans, i+countb)
print(ans)
| x,n=map(int, input().split())
a=list(map(int, input().split()))
for y in range(x+1):
for b in[-1,1]:
c=x+y*b
if a.count(c)==0:
print(c)
exit(0)
| 0 | null | 12,413,879,466,932 | 117 | 128 |
print((lambda x:int(x[1])+max(0,100*(10-int(x[0]))))(input().split())) | def merge(a,left,mid,right):
count=0
L=a[left:mid]+[float("inf")]
R=a[mid:right]+[float("inf")]
i,j=0,0
for k in range(left,right):
count+=1
if L[i]<=R[j]:
a[k]=L[i]
i+=1
else:
a[k]=R[j]
j+=1
return count
def mergeSort(a,left,right):
if left+1<right:
mid=(left+right)//2
countl=mergeSort(a,left,mid)
countr=mergeSort(a,mid,right)
return merge(a,left,mid,right)+countl+countr
return 0
n=int(input())
a=list(map(int,input().split()))
ans=mergeSort(a,0,n)
print(" ".join(map(str,a)))
print(ans)
| 0 | null | 31,552,311,783,988 | 211 | 26 |
n=int(input())
s=input()
ans=""
alp=[i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
for i in s:
ind=alp.index(i)
ind+=n
if 25<ind:
ind=ind-26
ans+=alp[ind]
print(ans) | class Cmb:
def __init__(self, N, mod=10**9+7):
self.fact = [1,1]
self.fact_inv = [1,1]
self.inv = [0,1]
""" 階乗を保存する配列を作成 """
for i in range(2, N+1):
self.fact.append((self.fact[-1]*i) % mod)
self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
""" 関数として使えるように、callで定義 """
def __call__(self, n, r, mod=10**9+7):
if (r<0) or (n<r):
return 0
r = min(r, n-r)
return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod
n,k = map(int,input().split())
mod = 10**9+7
c = Cmb(N=n)
ans = 0
for l in range(min(k+1, n)):
tmp = c(n,l)*c(n-1, n-l-1)
ans += tmp%mod
print(ans%mod) | 0 | null | 101,215,061,852,990 | 271 | 215 |
N,M,X = map(int,input().split())
C = []
A = []
for i in range(N):
t = list(map(int,input().split()))
C.append(t[0])
A.append(t[1:])
result = -1
# 1 << N 2^N
#There are 2^N possible ways of choosing books
for i in range(1 << N):
#keep all the understanding level in u
u = [0]*M
c = 0
for j in range(N):
#move j bit from i
if (i>>j)&1 == 0:
continue
c+= C[j]
#listwise sum
for k in range(M):
u[k] += A[j][k]
#X is the desired understanding level
if all(x >= X for x in u):
if result == -1:
result = c
else:
result = min(result,c)
print(result) | import math
N,M,X = map(int,input().split())
#a[i][0]:price of the i-th book
a = [[] for i in range(N)]
for i in range(N):
a[i] = list(map(int,input().split()))
def is_greater(b):
for i in b:
if i < X:
return False
return True
cost = math.inf
for i in range(2**N):
b = [0]*(M+1)
for j in range(N):
if ((i >> j)&1):
for k in range(M+1):
b[k] += a[j][k]
if b[0] < cost and is_greater(b[1:]):
cost = b[0]
if cost == math.inf:
print(-1)
else:
print(cost) | 1 | 22,388,663,022,560 | null | 149 | 149 |
n = int(input())
table = []
for _ in range(n):
x, l = map(int, input().split())
table.append([x-l, x+l])
sorted_table = sorted(table, key=lambda x: x[1])
# print(sorted_table)
left = sorted_table[0][1]
ans = n
for i in range(1, n):
if left <= sorted_table[i][0]:
left = sorted_table[i][1]
else:
ans -= 1
print(ans) | import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def main():
N,T = MI()
max_T = -1
dish = []
for i in range(N):
A,B = MI()
dish.append([A,B])
dish.sort(key=lambda x : x[0])
max_T = max(max_T, A)
dp=np.array([-1 for _ in range(T+max_T)])
dp[0] = 0
upper = 1
for i in range(N):
ch = (dp>=0)
ch[T:] = False
ch2 = np.roll(ch, dish[i][0])
ch2[:dish[i][0]]=False
dp[ch2] = np.maximum(dp[ch2] , dp[ch] + dish[i][1])
print(max(dp))
main() | 0 | null | 120,814,636,011,132 | 237 | 282 |
str = input()
def hitachi(S):
hitachi_str = [True if S[i:i+2] == 'hi' else False for i in range(0,len(S),2)]
if all(hitachi_str):
result = 'Yes'
else:
result = 'No'
return result
print(hitachi(str)) | def main():
a = list(map(int, input().split()))
D = a[0]
T = a[1]
S = a[2]
time = D / S
print("Yes" if time <= T else "No")
if __name__ == '__main__':
main()
| 0 | null | 28,313,305,811,768 | 199 | 81 |
N = int(input())
p = 1
for i in range(1,int(N**0.5+1)):
if N%i == 0:
p = i
print(p+N//p-2) | while True:
i,e,r = map(int,raw_input().split())
if i == e == r == -1:
break
if i == -1 or e == -1 :
print 'F'
elif i+e >= 80 :
print 'A'
elif i+e >= 65 :
print 'B'
elif i+e >= 50 :
print 'C'
elif i+e >= 30 :
if r >= 50 :
print 'C'
else :
print 'D'
else :
print 'F' | 0 | null | 81,514,316,773,968 | 288 | 57 |
S, T = [input() for x in range(2)]
lenT = len(T)
max_match_len = 0
for i in range(len(S)-lenT+1):
compareS = S[i:i+lenT]
match_len = 0
for j in range(lenT):
if compareS[j] == T[j]:
match_len += 1
else:
if max_match_len < match_len:
max_match_len = match_len
print(lenT - max_match_len)
| N = int(input())
A = tuple(map(int, input().split()))
L = [0] * N
for i in range(N):
L[A[i]-1] = i + 1
print(*L) | 0 | null | 92,316,782,639,640 | 82 | 299 |
X = int(input())
ans = X//500*1000
X = X % 500
ans += X//5*5
print(ans)
| X = int(input())
ans=0
if X < 500:
print((X // 5) * 5)
else:
ans += (X // 500)*1000
X -= (X//500)*500
ans += (X//5)*5
print(ans)
| 1 | 42,454,945,396,080 | null | 185 | 185 |
def N():
return int(input())
def L():
return list(map(int,input().split()))
def NL(n):
return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
#import numpy
a,b,c,d = L()
ta = -(-c // b)
ao = -(-a//d)
#print(ta,ao)
if ta <= ao :
print("Yes")
else:
print("No") | A, B = map(int, input().split())
if A > 9 or B > 9:
ans = -1
else:
ans = A*B
print(ans)
| 0 | null | 93,487,370,128,230 | 164 | 286 |
x, n = list(map(int, input().split()))
if n == 0:
print(x)
exit(0)
else:
arr = list(map(int, input().split()))
arr.sort()
if x in arr:
i = arr.index(x)
else:
print(x)
exit(0)
if not i and i != 0:
print(x)
exit(0)
j = 1
for _ in range(n):
row = i - j
high = i + j
if x - j not in arr:
print(x - j)
exit(0)
elif x + j not in arr:
print(x + j)
exit(0)
j += 1
print(x-1)
| import bisect
def abc170c_forbidden_list():
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
print(x)
return
p.sort()
for i in range(100):
idx = bisect.bisect_left(p, x - i)
if idx >= n or p[idx] != x - i:
print(x - i)
return
idx = bisect.bisect_left(p, x + i)
if idx >= n or p[idx] != x + i:
print(x + i)
return
abc170c_forbidden_list() | 1 | 14,177,989,984,960 | null | 128 | 128 |
keys = ([chr(x) for x in range(ord('a'), ord('a') + 26)])
counts = {x:0 for x in keys}
while True:
text = ''
try:
text = input()
except EOFError:
break
for i in range(len(text)):
target = text[i].lower()
if 'a' <= target <= 'z':
counts[target] += 1
for k in keys:
print(k, counts[k], sep=' : ') | import math
inf = math.inf
def merge(A, left, mid, right):
global cnt
L = []
R = []
for i in A[left:mid]:
L.append(i)
for i in A[mid:right]:
R.append(i)
L.append(inf)
R.append(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 right - left > 1:
mid = (left + right) // 2
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
_ =input()
A = list(map(int, input().rstrip().split(" ")))
cnt = 0
mergeSort(A, 0, len(A))
print(" ".join(list(map(str, A))))
print(cnt)
| 0 | null | 869,654,742,140 | 63 | 26 |
import bisect
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
a = bisect.bisect(l, k-1)
print(n-a) | # -*- coding: utf-8 -*-
n, k = map(int, input().split())
cnt = 0
h = list(map(int, input().split()))
for high in h:
if high >= k:
cnt += 1
print(cnt)
| 1 | 179,283,776,209,412 | null | 298 | 298 |
#S, L, h
import math
a, b, C = map(int, input().split())
S = a*b*math.sin(C*math.pi/180)*(1/2)
L = a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(C*math.pi/180))
h = 2*S/a
print('%.4f'% S)
print('%.4f'% L)
print('%.4f'% h) | import math
a,b,C=map(int,input().split())
c=C/180*math.pi
d=math.sqrt(a**2+b**2-2*a*b*math.cos(c))
S=1/2*a*b*math.sin(c)
L=a+b+d
h=2*S/a
print("{:.8f}".format(S))
print("{:.8f}".format(L))
print("{:.8f}".format(h))
| 1 | 182,554,258,720 | null | 30 | 30 |
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
S = input().rstrip()
A = [0]*N
cnt = 0
S = reversed(S)
for i, s in enumerate(S):
if s=="1":
cnt += 1
A[i] = cnt
else:
cnt = 0
dp = 0
res = []
while dp+M <= N-1:
t = M - A[dp+M]
if t>0:
dp += t
else:
print(-1)
exit()
res.append(t)
res.append(N-dp)
res.reverse()
print(*res) | #coding:utf-8
from copy import deepcopy
n = int(input())
c = ["white" for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
S = []
class DFS:
def __init__(self, key, color="white",nex=None):
self.color = color
self.nex = nex
self.key = key
objListCopy = [DFS(i+1) for i in range(n)]
for i in range(n):
data = list(map(int,input().split()))
times = data[1]
obj = objListCopy[i]
for j in range(times):
index = data[2+j] - 1
nextobj = DFS(index+1)
obj.nex = nextobj
obj = obj.nex
time = 1
objList = objListCopy[:]
def check(first,time):
obj = objList[first]
c[first] = "gray"
d[first] = time
f[first] = time
S.append(first+1)
while S != []:
index = S[-1] - 1
u = objList[index]
v = u.nex
time += 1
if v != None:
if c[v.key - 1] == "white":
objList[index] = v
index = v.key - 1
v = objList[index]
c[v.key-1] = "gray"
d[index] = time
S.append(v.key)
else:
objList[index] = v
time -= 1
else:
S.pop()
c[u.key-1] = "black"
f[index] = time
return time
for i in range(n):
if f[i] == 0:
objList = deepcopy(objListCopy)
time = check(i,time) + 1
k = 1
for i,j in zip(d,f):
print(k,i,j)
k += 1
| 0 | null | 69,544,352,927,100 | 274 | 8 |
n, x, m = map(int, input().split())
lis = [x]
flag = [-1 for i in range(m)]
flag[x] = 0
left = -1
right = -1
for i in range(n-1):
x = x**2 % m
if flag[x] >= 0:
left = flag[x]
right = i
break
else:
lis.append(x)
flag[x] = i+1
ans = 0
if left == -1:
ans = sum(lis)
else:
ans += sum(lis[0:left])
length = right - left + 1
ans += sum(lis[left:]) * ((n-left)//length)
ans += sum(lis[left:left+((n-left)%length)])
print(ans) | s, t = map(str, input().split())
ans = t + s
print(ans) | 0 | null | 52,623,478,398,832 | 75 | 248 |
input()
list = input().split()
list.reverse()
print (' '.join(list)) | n = int(input())
ns = list(map(int, input().split()))
# min, max, sum は関数名なので
# 別名を使うとよい
min0 = 10000000
max0 = -10000000
sum0 = 0
for x in ns:
min0 = min(min0, x)
max0 = max(max0, x)
sum0 += x
print(min0, max0, sum0)
| 0 | null | 875,146,376,020 | 53 | 48 |
from functools import reduce
from math import gcd
n = int(input())
A = list(map(int, input().split()))
def furui(x):
memo = [0]*(x+1)
primes = []
for i in range(2, x+1):
if memo[i]: continue
primes.append(i)
memo[i] = i
for j in range(i*i, x+1, i):
if memo[j]: continue
memo[j] = i
return memo, primes
memo, primes = furui(10**6+5)
pr = [True]*(10**6+5)
for a in A:
if a == 1: continue
while a != 1:
w = memo[a]
if not pr[w]:
break
pr[w] = False
while a%w == 0:
a = a // w
else:
continue
break
else:
print('pairwise coprime')
exit()
if reduce(gcd, A) == 1:
print('setwise coprime')
else:
print('not coprime')
| x = int(input())
c_500 = 0
c_5 = 0
while True:
temp = x - 500
if temp < 0:
break
else:
c_500 += 1
x = temp
while True:
temp = x - 5
if temp < 0:
break
else:
c_5 += 1
x = temp
print(c_500 * 2 * 500 + c_5 * 5)
| 0 | null | 23,443,492,864,272 | 85 | 185 |
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
if x-i not in p:
print(x-i)
break
if x+i not in p:
print(x+i)
break
i += 1 | X,N = map(int, input().split())
P = list(map(int, input().split()))
if len(P) == 0:
print(X)
else:
for i in range(0,10000):
if P.count(X-i) == 0:
print(X-i)
break
elif P.count(X+i) == 0:
print(X+i)
break
else:
continue | 1 | 14,112,042,054,880 | null | 128 | 128 |
while True:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
square = [['#'] * W] * H
for row in square:
print(''.join(row))
print()
| while True:
h,w = map(int, raw_input().split())
if h == w == 0:
break
print (("#" * w + "\n") * h) | 1 | 781,408,057,588 | null | 49 | 49 |
r, c = map(int, input().split())
rows = []
for i in range(r):
row = list(map(int, input().split()))
row.append(sum(row))
rows.append(row)
erow = [0 for i in range(c + 1)]
for row1 in rows:
print(" ".join(str(s) for s in row1))
for i in range(c + 1):
erow[i] += row1[i]
print(" ".join(str(s) for s in erow)) | import math
A, B, C = map(int, input().split())
K = int(input())
count = 0
ab = int(math.log2(A/B)+1)
bc = int(math.log2((B*(2**ab))/C)+1)
if ab + bc <= K:
print('Yes')
else:
print('No')
| 0 | null | 4,105,102,065,316 | 59 | 101 |
r, c = map(int, input().split())
arr = []
for i in range(r):
arr.append(list(map(int, input().split())))
for line in arr:
line.append(sum(line))
arr.append([sum([line[i] for line in arr]) for i in range(c + 1)])
for line in arr:
print(*line) | a, b, c, k = map(int, input().split())
if(k <= a):
print(k)
elif(k <= a+b):
print(a)
else:
if(a <= k-a-b):
print(-1*(k-a-b-a))
elif(a > k-a-b):
print(a-(k-a-b)) | 0 | null | 11,689,244,237,760 | 59 | 148 |
print("YNeos"["".join(input().split("hi"))!=""::2]) | data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
count = int(input())
for c in range(count):
(b, f, r, v) = [int(x) for x in input().split()]
data[b - 1][f - 1][r - 1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print('',data[b][f][r], end='')
print()
print('#' * 20) if b < 4 - 1 else print(end='') | 0 | null | 27,101,830,013,088 | 199 | 55 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
P = (A1 - B1) * T1
Q = (A2 - B2) * T2
if P > 0:
P *= -1
Q *= -1
if P + Q < 0:
print(0)
elif P + Q == 0:
print("infinity")
else:
S = (-P) // (P + Q)
T = (-P) % (P + Q)
if T != 0:
print(S * 2 + 1)
else:
print(S * 2)
| N, M = map(int, input().split())
M_f = M * 2 + 1
if M % 2 != 0:
for i in range(0, M // 2):
print(i + 1, (M) - i)
for i in range(0, M // 2 + 1):
print(M + 1 + i, M_f - i)
else:
for i in range(0, M // 2):
print(i + 1, (M + 1) - i)
for i in range(0, M // 2):
print(M + 2 + i, M_f - i) | 0 | null | 80,237,195,172,218 | 269 | 162 |
import sys
input = sys.stdin.readline
h, w, kk = map(int, input().split())
ss = [[0 for _ in range(h)] for _ in range(w)]
for i in range(h):
for j, c in enumerate(list(input().strip())):
if c == '1':
ss[j][i] = 1
ans = 100000
for i in range(2 ** (h - 1)):
end = []
for j in range(h - 1):
if i & 2 ** j:
end.append(j + 1)
end.append(h)
start = [0]
for j in end:
start.append(j)
start.pop()
sums = [0] * len(start)
tans = len(start) - 1
imp = False
for j in range(w):
reset = False
for k, (s, e) in enumerate(zip(start, end)):
sums[k] += sum(ss[j][s:e])
if sums[k] > kk:
reset = True
break
if reset:
tans += 1
for k, (s, e) in enumerate(zip(start, end)):
sums[k] = sum(ss[j][s:e])
if sums[k] > kk:
imp = True
if imp:
break
if not imp:
ans = min(ans, tans)
print(ans)
| import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
x, y, z = inm()
print(z, x, y) | 0 | null | 43,446,315,718,838 | 193 | 178 |
N = int(input())
A = list(map(int,input().split()))
flag = True
ans = 0
for i in range(N):
flag = False
for j in range(N-1,i,-1):
if A[j] < A[j-1]:
A[j],A[j-1] = A[j-1],A[j]
flag = True
ans += 1
if not flag:
break
print(*A)
print(ans)
| symbol = list(input().split())
stack = []
while len(symbol) > 0:
x = symbol.pop(0)
if x.isdigit():
stack.append(int(x))
else:
a,b = stack.pop(),stack.pop()
if x == "+":
stack.append(b + a)
elif x == "-":
stack.append(b - a)
elif x == "*":
stack.append(b * a)
print(stack.pop())
| 0 | null | 28,097,311,970 | 14 | 18 |
count = 0
def main():
input()
A = [int(x) for x in list(input().split())]
merge_sort(A, 0, len(A))
print(*A)
print(count)
def merge_sort(A, left, right):
if left+1 < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
# リストの左側を作成
L = A[left:mid]
# リストの右側を作成
R = A[mid:right]
# 終端追加
L.append(float("inf"))
R.append(float("inf"))
i = 0
j = 0
for k in range(left, right):
count += 1
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
if __name__ == '__main__':
main()
| def merge_sort(A):
if len(A) <= 1:
return A, 0
mid = len(A) // 2
left, lcount = merge_sort(A[:mid])
right, rcount = merge_sort(A[mid:])
merged, count = merge(left, right)
return merged, lcount + rcount + count
def merge(left, right):
lpos = 0
rpos = 0
lcount = 0
rcount = 0
merged = []
while lpos < len(left) and rpos < len(right):
if left[lpos] <= right[rpos]:
merged.append(left[lpos])
lpos += 1
lcount += 1
else:
merged.append(right[rpos])
rpos += 1
rcount += 1
if left[lpos:]:
merged.extend(left[lpos:])
lcount += len(left[lpos:])
if right[rpos:]:
merged.extend(right[rpos:])
rcount += len(right[rpos:])
return merged, lcount + rcount
if __name__ == '__main__':
n = int(raw_input())
A = map(int, raw_input().split())
sorted, count = merge_sort(A)
print ' '.join(str(x) for x in sorted)
print count | 1 | 108,364,163,776 | null | 26 | 26 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def main():
n = I()
a = sorted(LI())
m = max(a)
t = [False] * (m + 1)
r = 0
for i in range(n):
ai = a[i]
if t[ai]:
continue
for j in range(ai, m+1, ai):
t[j] = True
if i < n-1 and a[i+1] == ai:
continue
r += 1
return r
print(main())
| #import time
def main():
N = int(input())
As = list(map(int, input().split()))
As.sort()
amax = max(As) + 1
lis = [True] * amax
ans = 0
for i in range(N-1):
if lis[As[i]]:
for j in range(As[i], amax, As[i]):
lis[j] = False
if As[i] < As[i+1]:
ans += 1
if lis[-1]:
ans += 1
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]") | 1 | 14,453,121,085,464 | null | 129 | 129 |
#1???????????????
num_data = int(input())
for i in range(num_data):
input_line = input().split(" ")
a = int(input_line[0])
b = int(input_line[1])
c = int(input_line[2])
#?????????????????????????????????????????§
if (pow(a,2) + pow(b,2) == pow(c,2) ) or (pow(a,2) + pow(c,2) == pow(b,2) ) or (pow(b,2) + pow(c,2) == pow(a,2)):
print("YES")
else:
print("NO") | n = int(input())
print(int((n + 1)/2)) | 0 | null | 29,606,973,851,312 | 4 | 206 |
N = input()
L=len(N)
DP=[[N]*2 for _ in range(L+1)]
DP[0][0]=0
DP[0][1]=1
for i,n in enumerate(N,1):
DP[i][0]= min(DP[i-1][0]+int(n),DP[i-1][1]+10-int(n))
DP[i][1] = min(DP[i-1][0]+int(n)+1,DP[i-1][1]+9-int(n))
print(DP[L][0])
| from math import gcd
x = int(input())
y = x * 360 // gcd(x, 360)
print(y//x) | 0 | null | 42,016,662,524,628 | 219 | 125 |
s,t = input().split()
a,b=map(int,input().split())
u=input()
print(a-1, b) if s == u else print(a,b-1) | S,T=input().split()
A,B=map(int,input().split())
U=input()
if S==U:
print('{} {}'.format(A-1,B))
else:
print('{} {}'.format(A,B-1)) | 1 | 71,822,361,514,432 | null | 220 | 220 |
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int, input().split()))
a.sort()
m=max(a)
arr=[0]*(m+1)
flag=[True]*(m+1)
ans=0
for i in range(n):
if flag[a[i]]:
arr[a[i]]+=1
if not arr[a[i]]==1:
continue
for j in range(a[i]*2,m+1,a[i]):
flag[j]=False
print(arr.count(1)) | #import time
def main():
N = int(input())
As = list(map(int, input().split()))
As.sort()
amax = max(As) + 1
lis = [True] * amax
ans = 0
for i in range(N-1):
if lis[As[i]]:
for j in range(As[i], amax, As[i]):
lis[j] = False
if As[i] < As[i+1]:
ans += 1
if lis[-1]:
ans += 1
return ans
if __name__ == '__main__':
#start = time.time()
print(main())
#elapsed_time = time.time() - start
#print("経過時間:{}".format(elapsed_time * 1000) + "[msec]") | 1 | 14,431,852,834,912 | null | 129 | 129 |
import sys
input = sys.stdin.readline
a, b, k = map(int, input().split())
print(f'{a - k} {b}' if a >= k else (f'0 {b - (k - a)}' if a + b >= k else '0 0')) | a, b, k = map(int, input().split())
if a >= k:
print(a-k, b)
elif b >= (k-a):
print(0, (a+b)-k)
else:
print(0, 0) | 1 | 104,325,444,530,912 | null | 249 | 249 |
import math
t1,t2 = map(int, input().split())
c1,c2 = map(int, input().split())
d1,d2 = map(int, input().split())
x = [(c1*t1, c2*t2),(d1*t1, d2*t2)]
x.sort(reverse=True)
if x[0][0]+x[0][1] == x[1][0]+x[1][1]:
print("infinity")
elif x[0][0]+x[0][1] > x[1][0]+x[1][1]:
print(0)
else:
n = (x[0][0]-x[1][0]+0.0)/(x[1][0]+x[1][1]-x[0][0]-x[0][1])
m = math.ceil(n)
if math.floor(n) == m:
print(2*m)
else:
print(2*m-1) | class My_Queue:
def __init__(self, S):
self.S = S
self.q = [0 for i in range(S)]
self.head = 0
self.tail = 0
def enqueue(self, x):
if self.isFull():
print('overflow')
raise
else:
self.q[self.tail] = x
if self.tail + 1 == self.S:
self.tail = 0
else:
self.tail += 1
def dequeue(self):
if self.isEmpty():
print('underflow')
raise
else:
x = self.q[self.head]
self.q[self.head] = 0
if self.head + 1 == self.S:
self.head = 0
else:
self.head += 1
return x
def isEmpty(self):
return self.head == self.tail
def isFull(self):
return self.head == (self.tail + 1) % self.S
def main():
n, qms = map(int, input().split())
elapsed_time = 0
q = My_Queue(n + 1)
for i in range(n):
name, time = input().split()
time = int(time)
q.enqueue([name, time])
while(q.head != q.tail):
a = q.dequeue()
if a[1] <= qms:
elapsed_time += a[1]
print(a[0], elapsed_time)
else:
a[1] -= qms
elapsed_time += qms
q.enqueue(a)
if __name__ == "__main__":
main() | 0 | null | 65,863,618,366,520 | 269 | 19 |
#最大値の最小値を求める問題は二分探索
#求めるものを変数と見て丸太の最大値がxだとすると
#丸太の長さは全てx以下である必要があるため切るべき回数がわかる
#それがk回以下ならokだしそれがk回を超えていたらだめ
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
ng=0
ok=max(a)
def check(x):
num=0
for i in range(n):
if a[i]%x==0:
num=num+a[i]//x-1
else:
num=num+a[i]//x
return num<=k
while ok-ng>1:
mid=(ok+ng)//2
if check(mid):
ok=mid
else:
ng=mid
print(ok)
| a, b, c = [int(x) for x in input().split(" ")]
if a < b and b < c:
ans ="Yes"
else:
ans ="No"
print(ans) | 0 | null | 3,448,800,442,056 | 99 | 39 |
def main():
N = int(input())
S = input()
cnt = 0
for i in range(N):
for j in range(i + 1, N):
k = 2 * j - i
if k >= N:
continue
if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
cnt += 1
print(S.count("R") * S.count("B") * S.count("G") - cnt)
if __name__ == "__main__":
main()
| def inN():
return int(input())
def inL():
return list(map(int,input().split()))
def inNL(n):
return [list(map(int,input().split())) for i in range(n)]
n = inN()
s = input()
r = s.count('R')
b = s.count('B')
g = s.count('G')
cnt = 0
for i in range(n):
for j in range(i+1,n):
k = 2*j - i
if k < n:
if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
cnt += 1
print(r*g*b - cnt) | 1 | 36,203,219,122,382 | null | 175 | 175 |
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
ii0 = lambda: ii() - 1
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def main():
N,M,L = mis()
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
INF = np.iinfo(np.int64).max
d = np.full((N,N), INF, dtype=np.uint64)
for i in range(N):
d[i,i] = 0
#
for _ in range(M):
a,b,c = mis()
a -= 1
b -= 1
if c <= L:
d[a,b] = c
d[b,a] = c
#
'''
for k in range(N):
for i in range(N):
np.minimum(d[i,:], d[i,k]+d[k,:], out=d[i,:])
'''
d = floyd_warshall(d)
#
d2 = np.full((N,N), INF, dtype=np.uint64)
for i in range(N):
d2[i, i] = 0
for i in range(N):
for j in range(N):
if d[i, j] <= L:
d2[i, j] = 1
#
'''
for k in range(N):
for i in range(N):
np.minimum(d2[i,:], d2[i,k]+d2[k,:], out=d2[i,:])
'''
d2 = floyd_warshall(d2)
#
Q = ii()
for _ in range(Q):
s,t = mis()
s -= 1
t -= 1
dist = d2[s,t]
if dist == INF:
print(-1)
else:
print(int(dist)-1)
main()
| 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 = float('inf')
ds = [[INF]*N for i in range(N)]
for a,b,c in ABC:
a,b = a-1,b-1
ds[a][b] = ds[b][a] = c
for i in range(N):
ds[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j])
ls = [[INF]*N for i in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if ds[i][j] <= L:
ls[i][j] = ls[j][i] = 1
for i in range(N):
ls[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j])
ans = []
for s,t in ST:
ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1)
print(*ans, sep='\n') | 1 | 173,718,378,485,582 | null | 295 | 295 |
r, c = map(int, input().split())
a = [0]*(c+1)
for _ in range(r):
v = list(map(int, input().split()))
s = 0
for i, e in enumerate(v):
s+=e
a[i]+=e
v.append(s)
print(*v)
a[-1]+=s
print(*a) | import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
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())
N,K = LI()
H = LI()
Hs = np.array(sorted(H, reverse=True))
ans = np.sum(Hs[K:])
print(ans) | 0 | null | 40,104,345,061,540 | 59 | 227 |
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, heapify
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10
N = INT()
A = LIST()
LR = [[A[-1], A[-1]]]
for b in A[::-1][1:]:
LR.append([-(-LR[-1][0]//2)+b, LR[-1][1]+b])
LR = LR[::-1]
if LR[0][0] <= 1 <= LR[0][1]:
pass
else:
print(-1)
exit()
ans = 1
tmp = 1
for i, (L, R) in enumerate(LR[1:], 1):
tmp = min(2*tmp-A[i], R-A[i])
ans += tmp+A[i]
print(ans) | L, R, d = map(int, input().split())
count = 0
for i in range(101):
if d * i >= L and d * i <= R:
count += 1
if d * i > R:
break
print(count) | 0 | null | 13,259,242,186,838 | 141 | 104 |
n = int(input())
p = list(map(int, input().split()))
count = 0
m = p[0]
for i in p:
m = min(m, i)
if m == i:
count += 1
print(count) | N = int(input())
P = tuple(map(int, input().split()))
count = 0
min_num = float('inf')
for i in P:
if i < min_num:
count += 1
min_num = i
print(count) | 1 | 85,588,566,225,172 | null | 233 | 233 |
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal
class Scanner():
@staticmethod
def int():
return int(sys.stdin.readline().rstrip())
@staticmethod
def string():
return sys.stdin.readline().rstrip()
@staticmethod
def map_int():
return [int(x) for x in Scanner.string().split()]
@staticmethod
def string_list(n):
return [Scanner.string() for i in range(n)]
@staticmethod
def int_list_list(n):
return [Scanner.map_int() for i in range(n)]
@staticmethod
def int_cols_list(n):
return [Scanner.int() for i in range(n)]
class Math():
@staticmethod
def gcd(a, b):
if b == 0:
return a
return Math.gcd(b, a % b)
@staticmethod
def lcm(a, b):
return (a * b) // Math.gcd(a, b)
@staticmethod
def divisor(n):
res = []
i = 1
for i in range(1, int(n ** 0.5) + 1):
if n % i == 0:
res.append(i)
if i != n // i:
res.append(n // i)
return res
@staticmethod
def round_up(a, b):
return -(-a // b)
@staticmethod
def is_prime(n):
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
d = int(n ** 0.5) + 1
for i in range(3, d + 1, 2):
if n % i == 0:
return False
return True
@staticmethod
def fact(N):
res = {}
tmp = N
for i in range(2, int(N ** 0.5 + 1) + 1):
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
res[i] = cnt
if tmp != 1:
res[tmp] = 1
if res == {}:
res[N] = 1
return res
def pop_count(x):
x = x - ((x >> 1) & 0x5555555555555555)
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
x = x + (x >> 8)
x = x + (x >> 16)
x = x + (x >> 32)
return x & 0x0000007f
MOD = int(1e09) + 7
INF = int(1e15)
def modinv(a):
b = MOD
u = 1
v = 0
while b:
t = a // b
a -= t * b
a, b = b, a
u -= t * v
u, v = v, u
u %= MOD
if u < 0:
u += MOD
return u
def factorial(N):
if N == 0 or N == 1:
return 1
res = N
for i in range(N - 1, 1, -1):
res *= i
res %= MOD
return res
def solve():
X, Y = Scanner.map_int()
if (X + Y) % 3 != 0:
print(0)
return
B = (2 * Y - X) // 3
A = (2 * X - Y) // 3
if A < 0 or B < 0:
print(0)
return
n = factorial(A + B)
m = factorial(A)
l = factorial(B)
ans = n * modinv(m * l % MOD) % MOD
print(ans)
def main():
# sys.setrecursionlimit(1000000)
# sys.stdin = open("sample.txt")
# T = Scanner.int()
# for _ in range(T):
# solve()
# print('YNeos'[not solve()::2])
solve()
if __name__ == "__main__":
main()
| h=int(input())
w=int(input())
n=int(input())
print(-(-n//max(h,w))) | 0 | null | 118,923,323,805,660 | 281 | 236 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
if __file__=="test.py":
f = open("./in_out/input.txt", "r", encoding="utf-8")
read = f.read
readline = f.readline
def main():
R, C, K = map(int, readline().split())
L_INF = int(1e17)
dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K):
x, y, c = map(int, readline().split())
cell[x-1][y-1] = c
dp[0][0][1] = dp[0][1][0] = 0
for i in range(1, R + 1):
for j in range(1, C + 1):
for k in range(4):
if k > 0:
dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
if k > 0:
dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + cell[i-1][j-1])
if k == 1:
dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
print(dp[3][R][C])
if __name__ == "__main__":
main()
| n = int(input())
L = list(map(int,input().split()))
print(min(L),max(L),sum(L))
| 0 | null | 3,149,630,326,080 | 94 | 48 |
string = input()
a, b, c = map(int, (string.split(' ')))
if a < b & b < c :
print('Yes')
else:
print('No')
| n = int(input())
l = 0
r = 0
cntl = 0
cntr = 0
fl = 0
fr = 0
exl = 0
exr = 0
only_r = 0
only_l = 0
maxl = 0
maxr = 0
exlr = []
for i in range(n):
s = input()
templ = 0
tempr = 0
temp_exl = 0
temp_exr = 0
fl = 0
fr = 0
for i in s:
if i == "(":
tempr += 1
elif i == ")":
tempr -= 1
if tempr < 0:
tempr = 0
templ += 1
fl = 1
temp_exl += templ
if tempr > 0:
temp_exr += tempr
fr = 1
if fl == 1 and fr == 0:
only_l += temp_exl
elif fr == 1 and fl == 0:
only_r += temp_exr
elif temp_exl + temp_exr > 0:
exl += temp_exl
exr += temp_exr
exlr.append([temp_exl-temp_exr, temp_exl,temp_exr])
# maxl = max(maxl,temp_exl)
# maxr = max(maxr,temp_exr)
# print (exr,exl,only_r,only_l)
a = only_r
b = only_l
# print(exlr)
exlr.sort()
# exlr.sort(key=lambda x: x[1])
# print(exlr)
# for i in range(len(exlr)):
# if exlr[i][1] <= a and exlr[i][0] <= 0:
# a -= exlr[i][0]
# exlr[i] = [0,0,0]
# print(exlr)
for i in exlr:
a -= i[1]
if a<0:
print("No")
exit()
a += i[2]
if a-b == 0:
print("Yes")
else:
print("No")
# if exl+only_l == exr+only_r and exl-exr == only_r-only_l and only_l > 0 and only_r > 0:
# print("Yes")
# elif exr+exl+only_l+only_r == 0:
# print("Yes")
# else:
# print("No")
| 0 | null | 11,965,809,929,390 | 39 | 152 |
N = int(input())
A = list(map(int, input().split()))
LN = max(A) + 1
L = [0 for i in range(LN)]
count = 0
for i in A:
for j in range(i, LN, i):
L[j] += 1
for i in A:
if L[i] == 1:
count += 1
print(count) | N=int(input())
A=list(map(int,input().split()))
M=1000050
dp=[0 for i in range(M)]
ans=0
for x in A:
if dp[x]!=0:
dp[x]=2
continue
for i in range(x,M,x):
dp[i]+=1
for x in A:
if dp[x]==1:
ans+=1
print(ans)
| 1 | 14,473,361,952,390 | null | 129 | 129 |
s,w=map(int,input().split())
print("unsafe" if s<=w else"safe") | a=int(input())
b=a//200
if b==2:
print(8)
elif b==3:
print(7)
elif b==4:
print(6)
elif b==5:
print(5)
elif b==6:
print(4)
elif b==7:
print(3)
elif b==8:
print(2)
elif b==9:
print(1) | 0 | null | 17,970,280,480,864 | 163 | 100 |
N = int(input())
for i in range(1,int(N**(1/2)) + 1)[::-1]:
if N%i == 0:
print(i + N//i - 2)
exit() | n=int(input())
ans = n
for i in range(1,int(n**0.5)+2):
if n % i == 0:
ans = min(ans,(i-1)+(n//i-1))
print(ans) | 1 | 162,297,988,438,012 | null | 288 | 288 |
a, b, c = map(int, input().split())
if c - (a+b) < 0:
print("No")
exit()
if 4*a*b < c**2 - 2*c*(a+b) + (a+b)**2:
print("Yes")
else:
print("No")
| N = int(input())
a = list(input())
count=0
for i in range(N):
if a[i] == 'A' and i<len(a)-2:
if a[i+1]=='B' :
if a[i+2]=='C':
count+=1
print(count) | 0 | null | 75,774,991,775,922 | 197 | 245 |
D = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for _ in range(D)]
t = [int(input())-1 for _ in range(D)]
ans = 0
llst = [0]*26
for day,i in enumerate(range(D),1):
llst[t[i]] = day
ans += s[i][t[i]]
for j in range(26): ans -= c[j]*(day-llst[j])
print(ans) | n = int(input())
c = input()
count = 0
i, j = 0, n - 1
if c.count('W') == 0:
count=0
elif c.count('R') == 0:
count = 0
else:
white_cnt = []
red_cnt = []
for i in range(n):
if c[i] == 'W':
white_cnt.append(i)
else:
red_cnt.append(i)
while 1:
white_num = white_cnt.pop(0)
red_num = red_cnt.pop()
if white_num < red_num:
count += 1
if len(white_cnt) == 0:
break
if len(red_cnt) == 0:
break
print(count)
| 0 | null | 8,101,423,422,532 | 114 | 98 |
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ans = 0
s = sum(A)
for a in A:
s -= a
ans += s * a
ans %= MOD
print(ans) | def readInt():
return list(map(int, input().split()))
h, w = readInt()
if h == 1 or w == 1:
print(1)
elif h*w%2 == 0:
print(h*w//2)
else:
print(h*w//2+1)
| 0 | null | 27,435,675,337,970 | 83 | 196 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.