code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
ans=0
for i in permutations(range(n),n):
for j in range(1,n):
ans+=((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
for i in range(1,n+1):
ans/=i
print(ans)
| def bubbleSort(A,N):
flag = 1 #????????????????????£??????????????????????????????????????¨??????
i = 0
while flag:
flag = 0
for j in range(N-1,i,-1):
if int(A[j][1]) < int(A[j-1][1]):
tmp = A[j]
A[j] = A[j-1]
A[j-1] = tmp
flag = 1
i += 1
return A
def selectionSort(A,N):
for i in range(0,N-1):
minj = i
j=i+1
for j in range(j,N):
if int(A[j][1]) < int(A[minj][1]):
minj = j
tmp = A[minj]
A[minj] = A[i]
A[i] = tmp
return A
def isStable(ori,sorted):
for i in range(len(ori)-1):
for j in range(i+1, len(ori)-1):
for a in range(len(ori)):
for b in range(a+1, len(ori)):
if ori[i][1] == ori[j][1] and ori[i] == sorted[b] and ori[j] == sorted[a]:
return 'Not stable'
return 'Stable'
def output(A):
for i in range(len(A)): # output
if i == len(A) - 1:
print(A[i])
else:
print(A[i], end=' ')
if __name__ == '__main__':
N = int(input())
numbers = input().split(' ')
n1 = numbers.copy()
n2 = numbers.copy()
A = bubbleSort(n1,N)
output(A)
print(isStable(numbers,A))
B = selectionSort(n2,N)
output(B)
print(isStable(numbers, B)) | 0 | null | 73,946,288,754,012 | 280 | 16 |
n, m = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(n)]
bt = [int(input()) for i in range(m)]
for i in range(n):
print(sum([x * y for (x, y) in zip(A[i], bt)]))
| 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) ])) | 1 | 1,171,381,349,512 | null | 56 | 56 |
# coding: utf-8
while True:
x, y = map(int, input().split())
if x == 0 and y == 0:
exit()
elif x < y:
print(x, y)
else:
print(y, x)
| # coding:utf-8
# ??\??????????????´??°????°???????????????????
i = 1
x = 1
y = 1
while x != 0 or y != 0:
xy = raw_input().split()
x = int(xy[0])
y = int(xy[1])
if x == 0 and y ==0:
break
if x < y :
print x,y
else:
print y,x | 1 | 519,297,143,622 | null | 43 | 43 |
def BSort(A,n):
flag=1
while flag:
flag=0
for i in range(n-1,0,-1):
if A[i][1]<A[i-1][1]:
A[i],A[i-1]=A[i-1],A[i]
flag=1
def SSort(A,n):
for i in range(n):
minj=i
for j in range(i,n):
if A[j][1]<A[minj][1]:
minj=j
A[i],A[minj]=A[minj],A[i]
n = int(input())
A = list(input().split())
B=A[:]
BSort(A,n)
print(' '.join(A))
print('Stable')
SSort(B,n)
print(' '.join(B))
if A==B:
print('Stable')
else:
print('Not stable')
| array = list(map(int, input().split()))
array.sort()
print("{} {} {}".format(array[0], array[1], array[2]))
| 0 | null | 221,414,218,950 | 16 | 40 |
N = int(input())
P = list(map(int,input().split()))
num = 1
min_P = P[0]
for i in range(1,N):
if P[i] < min_P:
min_P = P[i]
num += 1
print(num) | n=int(input(''))
p=list(map(int,input('').split(' ')))
s=1
mi=p[0]
for a in range(n-1):
if p[a+1]<=mi:
s=s+1
mi=p[a+1]
print(s) | 1 | 85,276,830,937,730 | null | 233 | 233 |
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum # accumulate
def solve():
N, M = MI()
E = [[] for _ in range(N)]
for i in range(M):
a, b = MI1()
E[a].append(b)
E[b].append(a)
q = deque([0])
used = [0] * N
used[0] = 1
ans = [0] * N
ans[0] = 'Yes'
while q:
v = q.popleft()
for nv in E[v]:
if used[nv]: continue
used[nv] = 1
ans[nv] = v+1
q.append(nv)
printlist(ans, '\n')
if __name__ == '__main__':
solve()
| from collections import deque
n,m=map(int,input().split())
data=[[] for i in range(n+1)]
for i in range(m):
a,b=map(int,input().split())
data[a].append(b)
data[b].append(a)
que=deque()
que.append(1)
cnt=[0]*(n+1)
while que:
h=que.popleft()
for u in data[h]:
if cnt[u]!=0:
continue
cnt[u]=h
que.append(u)
print('Yes')
for i in range(2,n+1):
print(cnt[i]) | 1 | 20,571,540,212,330 | null | 145 | 145 |
[print(y) for y in sorted([int(input()) for x in range(10)], reverse=True)[:3]] | import sys
mount_list = map(int, sys.stdin.readlines())
mount_list.sort(reverse=True)
for x in mount_list[:3]:
print x | 1 | 24,034,812 | null | 2 | 2 |
import math
K = int(input())
# gcd(a, b, c)=gcd(gcd(a,b), c) が成り立つ
s = 0
for a in range(1, K+1):
for b in range(1, K+1):
d = math.gcd(a, b) # gcd(a, b)は先に計算しておく
for c in range(1, K+1):
s += math.gcd(d, c)
print(s) | print((lambda x:int(x[1])+max(0,100*(10-int(x[0]))))(input().split())) | 0 | null | 49,168,144,192,220 | 174 | 211 |
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
def main():
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
A = A1 * T1 + A2 * T2
B = B1 * T1 + B2 * T2
if A1 < B1 and A < B:
print(0)
return
if A1 > B1 and A > B:
print(0)
return
if A == B:
print("infinity")
return
# T1 + T2 分後にできる差
diff = abs(A - B)
if T1 * abs(A1 - B1) % diff == 0:
ans = T1 * abs(A1 - B1) // diff * 2
else:
ans = T1 * abs(A1 - B1) // diff * 2 + 1
print(ans)
if __name__ == "__main__":
main()
| T1,T2=[int(i) for i in input().split()]
A1,A2=[int(i) for i in input().split()]
B1,B2=[int(i) for i in input().split()]
if((B1-A1)*((B1-A1)*T1+(B2-A2)*T2)>0):
print(0);
exit();
if((B1-A1)*T1+(B2-A2)*T2==0):
print("infinity")
exit();
ans=(abs((B1-A1)*T1)//abs((B1-A1)*T1+(B2-A2)*T2))*2+1
if(abs((B1-A1)*T1)%abs((B1-A1)*T1+(B2-A2)*T2)==0):
ans-=1
print(ans)
| 1 | 131,365,658,675,060 | null | 269 | 269 |
n = int(input())
def gcd(a,b):
if b == 0:
return a
return gcd(b, a%b)
print((360 * n // gcd(360, n)) // n) | n = int(input())
d = {}
for _ in range(n):
s = input()
d.setdefault(s,0)
d[s] -= 1
t = []
for k,v in d.items():
t.append((v,k))
t.sort()
num = t[0][0]
for v,s in t:
if v == num:
print(s) | 0 | null | 41,445,419,109,084 | 125 | 218 |
s=input().split()
n=int(s[0])
m=int(s[1])
a=[[0 for j in range(m)]for i in range(n)]
b=[0 for j in range(m)]
for i in range(n):
t=input().split()
for j in range(m):
a[i][j]=int(t[j])
for j in range(m):
b[j]=int(input())
c=[0 for i in range(n)]
for i in range(n):
for j in range(m):
c[i]+=a[i][j]*b[j]
print("{0}".format(c[i])) | from collections import Counter
N = int(input())
S = input()
c = Counter(S)
ans = c['R'] * c['G'] * c['B']
for s in range(N-2):
for d in range(1, (N-1-s)//2+1):
t = s + d
u = t + d
if S[s] != S[t] and S[t] != S[u] and S[u] != S[s]:
ans -= 1
print(ans)
| 0 | null | 18,567,089,828,964 | 56 | 175 |
n=int(input())
listn=list(map(int,input().split()))
count=0
min1=listn[0]
for i in range(0,n):
if(listn[i]>min1):
pass
else:
min1=listn[i]
count+=1
print(count)
| N = int(input())
P = list(map(int, input().split()))
mn = N + 1
ans = 0
for p in P:
if p < mn:
ans += 1
mn = min(mn, p)
print(ans) | 1 | 85,309,785,826,040 | null | 233 | 233 |
P = [1 for _ in range(10**6)]
P[0]=0
P[1]=0
for i in range(2,10**3):
for j in range(i*i,10**6,i):
P[j] = 0
Q = []
for i in range(2,10**6):
if P[i]==1:
Q.append(i)
N = int(input())
C = {}
for q in Q:
if N%q==0:
C[q] = 0
while N%q==0:
N = N//q
C[q] += 1
if N>1:
C[N] = 1
cnt = 0
for q in C:
k = C[q]
n = 1
while k>(n*(n+1))//2:
n += 1
if k==(n*(n+1))//2:
cnt += n
else:
cnt += n-1
print(cnt)
| n = int(input())
fact={}
i = 2
while n != 1:
if n % i == 0:
n = n/i
if i in fact:
fact[i] += 1
else:
fact[i] = 1
else:
i += 1
if i > (n**(1/2)+1):
if n in fact:
fact[n] += 1
else:
fact[n] = 1
break
if fact == {}:
print(0)
else:
ans = 0
for v in fact.values():
#print(v)
for i in range(1,v+1):
if v - i >= 0:
ans +=1
v = v-i
print(ans) | 1 | 17,031,820,158,180 | null | 136 | 136 |
X, Y, Z = [int(x) for x in input().split()]
print("%d %d %d" % (Z, X, Y))
| def insertionSort(A, n, g):
cnt=0
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
return cnt,A
def shellSort(A, n):
cnt = 0
G = [1]
flag=True
while flag:
g = G[0]*3+1
if g < n:
G = [g] + G
else:
flag=False
m = len(G)
for i in range(m):
tmp_cnt,tmp_A = insertionSort(A, n, G[i])
cnt += tmp_cnt
print(m)
G_str = (list(map(lambda x:str(x),list(G))))
print(" ".join(G_str))
print(cnt)
for a in A:
print(a)
#print(A)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
| 0 | null | 18,966,994,259,544 | 178 | 17 |
n = int(input())
s, t = map(str, input().split())
sl = list(s)
tl = list(t)
a = []
for i in range(n):
a.append(s[i])
a.append(t[i])
print(''.join(a)) | N,M=map(int,input().split())
A=[]
A=list(map(int,input().split()))
if(N-sum(A)<0):
print('-1')
exit()
print(N-sum(A))
| 0 | null | 71,621,507,919,132 | 255 | 168 |
n,k,s = map(int, input().split())
if s < 10**9:
ans = [s+1] * n
else:
ans = [1]*n
ans[:k] = [s]*k
print(" ".join(map(str,ans))) | n, k, s = map(int, input().split())
l = [s] * k + [s+1 if s != 10**9 else 1] * (n-k)
print(*l)
| 1 | 91,106,357,214,740 | null | 238 | 238 |
def main():
A, B, C = map(int, input().split())
K = int(input())
while B <= A:
B *= 2
K -= 1
while C <= B:
C *= 2
K -= 1
if K >= 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| import itertools
lst = list(map(int, input().split()))
k = int(input())
ans = 'No'
for tup in itertools.combinations_with_replacement([0, 1, 2], k):
temp = lst[:]
for i in tup:
temp[i] *= 2
if temp[0] < temp[1] and temp[1] < temp[2]:
ans = 'Yes'
print(ans) | 1 | 6,844,943,162,860 | null | 101 | 101 |
def I(): return int(input())
N = I()
S = input()
ans = 0
for i in range(1000):
num = str(i).zfill(3)
if S.find(num[0])==-1:
continue
S1 = S[S.find(num[0])+1:]
if S1.find(num[1])==-1:
continue
S2 = S1[S1.find(num[1])+1:]
if S2.find(num[2])==-1:
continue
ans += 1
print(ans) | import math
def solve():
N = int(input())
ans = 0
for i in range(2, int(math.sqrt(N)) + 2):
n = 1
cnt = 0
while N % i == 0:
N //= i
cnt += 1
if cnt == n:
cnt = 0
n += 1
ans += 1
if N != 1:
ans += 1
return ans
print(solve())
| 0 | null | 72,455,875,439,310 | 267 | 136 |
N = int(input())
if(N % 2 == 0):
print(0.5000000000)
else:
M = (N+1)/2
print(M/N) | import sys
for s in sys.stdin:
a,b = sorted(map(int, s.split()))
if a == 0 and b == 0:
break
print(a,b) | 0 | null | 88,491,867,737,572 | 297 | 43 |
n,m = [int(i) for i in input().split()]
s = input()
p = n
q = []
while p!=0:
frag = True
for i in range(max(p-m,0),p):
if s[i]=='0':
q.append(p-i)
p=i
frag = False
break
if frag:
q=[]
print(-1)
break
for i in reversed(q):
print(i)
| def solve(d,p,t):
if d - p * t <= 0:
return "YES"
else:
return "NO"
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
d = abs(B-A)
p = V - W
print(solve(d,p,T)) | 0 | null | 77,022,208,404,602 | 274 | 131 |
import math
result = []
n = int(input())
while n != 0:
d = list(map(int, input().split()))
mean = sum(d) / n
var = [(i - mean) ** 2 for i in d]
var = math.sqrt(sum(var) / n)
result.append(var)
n = int(input())
for i in result:
print(i)
| import math
while True:
n = int(input())
if n == 0: break
d = list(map(int, input().strip().split()))
m = sum(d) / n
print(math.sqrt(sum((x - m)**2 for x in d) / n)) | 1 | 198,442,239,758 | null | 31 | 31 |
#input
N, M, L = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
A[i], B[i], C[i] = map(int, input().split())
Q = int(input())
s = [0] * Q
t = [0] * Q
for i in range(Q):
s[i], t[i] = map(int, input().split())
#output
from scipy.sparse.csgraph import floyd_warshall, shortest_path, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import numpy as np
#便宜上A, Bを-1する。
for i in range(M):
A[i] -= 1
B[i] -= 1
#FW法で各経路の最短距離を計算する。
graph = csr_matrix((C, (A, B)), shape = (N, N))
dist_matrix = floyd_warshall(csgraph = graph, directed = False, return_predecessors = False)
graph2 = np.full((N, N), np.inf)
graph2[dist_matrix <= L] = 1
graph2 = csr_matrix(graph2)
dist_matrix2 = floyd_warshall(csgraph = graph2, directed = False, return_predecessors = False)
for q in range(Q):
if dist_matrix2[s[q]-1][t[q]-1] < 10000000:
print(int(dist_matrix2[s[q]-1][t[q]-1]-1))
else:
print(-1) | n = int(input())
s = 0
b = False
for _ in range(n):
w = input().split()
if w[0] == w[1]:
s += 1
if s == 3:
b = True
break
else:
s = 0
print('Yes' if b else 'No')
| 0 | null | 88,038,881,085,232 | 295 | 72 |
n = int(input())
s = input()
rs = [0]*n
gs = [0]*n
bs = [0]*n
for i in reversed(range(n)):
if s[i] == 'R':
rs[i] += 1
elif s[i] == 'G':
gs[i] += 1
else:
bs[i] += 1
for i in reversed(range(n-1)):
rs[i] += rs[i+1]
gs[i] += gs[i+1]
bs[i] += bs[i+1]
res = 0
for i in range(n):
for j in range(i+1,n-1):
if s[i] == s[j]:
continue
if s[i]!='B' and s[j]!='B':
res += bs[j+1]
if j-i+j < n:
if s[j-i+j] == 'B':
res -=1
elif s[i]!='G' and s[j]!='G':
res += gs[j+1]
if j - i + j < n:
if s[j-i+j] == 'G':
res -=1
else:
res += rs[j+1]
if j - i + j < n:
if s[j-i+j] == 'R':
res -= 1
print(res) | n = int(input())
s = list(input() for _ in range(n))
keihin = set()
for i in s:
keihin.add(i)
print(len(keihin)) | 0 | null | 33,340,546,816,288 | 175 | 165 |
N = int(input())
kotae = []
for i in range(1,N+1):
for j in range(1,N+1):
for k in range(1,N+1):
s = i
t = j
u = k
x = 1
while x != 0:
v = t%s
if v != 0:
t = s
s = v
else:
t = s
x = u%t
if x != 0:
u = t
t = x
else:
kotae.append(t)
print(sum(kotae)) | word = input().lower()
text = []
c = 0
while True:
read = input().split()
if read[0] == 'END_OF_TEXT':
break
else:
text.append(read)
for i in text:
for n in i:
if word == n.lower():
c += 1
print(c) | 0 | null | 18,789,400,382,978 | 174 | 65 |
K,N=map(int,input().split())
A=[int(x) for x in input().split()]
A+=[K+A[0]]
print(K-max(A[i+1]-A[i] for i in range(N)))
| line1 = input()
line2 = input()
aryLine1 = line1.split()
arystrLine2 = line2.split()
K = int(aryLine1[0]);
N = int(aryLine1[1]);
aryLine2 = [int(s) for s in arystrLine2]
#print(aryLine2)
aryLine2.sort()
#print(aryLine2)
ans = K
for i in range(0, N):
temp1 = int(aryLine2[i])
if i == N - 1:
temp2 = int(aryLine2[0]) + K
else:
temp2 = int(aryLine2[i + 1])
temp = temp1 - temp2 + K
if temp < ans:
ans = temp
print(ans) | 1 | 43,540,722,974,160 | null | 186 | 186 |
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
firstDis = abs(A - B)
steps = (V - W)*T
print("YES" if firstDis <= steps else "NO")
| import sys
W = input()
print(sum(line.lower().split().count(W) for line in sys.stdin.readlines())) | 0 | null | 8,478,838,793,602 | 131 | 65 |
N ,K = map(int,input().split())
Ps = list(map(int,input().split()))
Ps.sort()
ans = 0
for i in range(K):
ans += Ps[i]
print(ans)
| n, k = map(int,input().split())
p = list(map(int,input().split()))
p_sort = sorted(p)
p_sum = sum(p_sort[0:k])
print(p_sum) | 1 | 11,595,409,931,522 | null | 120 | 120 |
from collections import Counter
N = int(input())
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
a = prime_factorize(N)
num = list(Counter(a).values())
ans = 0
for i in num:
j = 1
while i - j >= 0:
ans += 1
i -= j
j += 1
print(ans) | import math , sys
def fac(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append(cnt)
if temp!=1:
arr.append(1)
if arr==[]:
arr.append(1)
return arr
def sta ( x ):
return int( 0.5* (-1 + math.sqrt(1+8*x)))
N = int( input() )
if N == 1:
print(0)
sys.exit()
if N == 2 or N ==3:
print(1)
sys.exit()
Is = fac( N )
ans = sum( [ sta(j) for j in Is])
print(max(ans,1)) | 1 | 16,951,107,040,604 | null | 136 | 136 |
# abc168_a.py
# https://atcoder.jp/contests/abc168/tasks/abc168_a
# A - ∴ (Therefore) /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 100点
# 問題文
# いろはちゃんは、人気の日本製ゲーム「ÅtCoder」で遊びたい猫のすぬけ君のために日本語を教えることにしました。
# 日本語で鉛筆を数えるときには、助数詞として数の後ろに「本」がつきます。この助数詞はどんな数につくかで異なる読み方をします。
# 具体的には、999以下の正の整数 N について、「N本」と言うときの「本」の読みは
# Nの 1 の位が 2,4,5,7,9のとき hon
# Nの 1 の位が 0,1,6,8のとき pon
# Nの 1 の位が 3のとき bon
# です。
# Nが与えられるので、「N本」と言うときの「本」の読みを出力してください。
# 制約
# Nは 999以下の正の整数
# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# 出力
# 答えを出力せよ。
# 入力例 1
# 16
# 出力例 1
# pon
# 16の 1 の位は 6なので、「本」の読みは pon です。
# 入力例 2
# 2
# 出力例 2
# hon
# 入力例 3
# 183
# 出力例 3
# bon
global FLAG_LOG
FLAG_LOG = False
def log(value):
# FLAG_LOG = True
FLAG_LOG = False
if FLAG_LOG:
print(str(value))
def calculation(lines):
# S = lines[0]
N = int(lines[0])
# N, M = list(map(int, lines[0].split()))
# values = list(map(int, lines[1].split()))
# values = list(map(int, lines[2].split()))
# values = list()
# for i in range(N):
# values.append(int(lines[i]))
# valueses = list()
# for i in range(N):
# valueses.append(list(map(int, lines[i+1].split())))
amari = N % 10
result = 'hon'
if amari == 3:
result = 'bon'
elif amari in [0, 1, 6, 8]:
result = 'pon'
return [result]
# 引数を取得
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# テストデータ
def get_testdata(pattern):
if pattern == 1:
lines_input = ['16']
lines_export = ['pon']
if pattern == 2:
lines_input = ['2']
lines_export = ['hon']
if pattern == 3:
lines_input = ['183']
lines_export = ['bon']
return lines_input, lines_export
# 動作モード判別
def get_mode():
import sys
args = sys.argv
global FLAG_LOG
if len(args) == 1:
mode = 0
FLAG_LOG = False
else:
mode = int(args[1])
FLAG_LOG = True
return mode
# 主処理
def main():
import time
started = time.time()
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = calculation(lines_input)
for line_result in lines_result:
print(line_result)
# if mode > 0:
# print(f'lines_input=[{lines_input}]')
# print(f'lines_export=[{lines_export}]')
# print(f'lines_result=[{lines_result}]')
# if lines_result == lines_export:
# print('OK')
# else:
# print('NG')
# finished = time.time()
# duration = finished - started
# print(f'duration=[{duration}]')
# 起動処理
if __name__ == '__main__':
main()
|
def main():
a,b,c = map(int,input().split())
rhs = c - a - b
lhs = 4 * a * b
if rhs > 0 and lhs < rhs ** 2:
print('Yes')
else:
print('No')
main() | 0 | null | 35,250,305,679,798 | 142 | 197 |
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
z = input()
n = int(z) - 1
print(l[n]) | N = int(input())
print(N // 2 + N % 2)
| 0 | null | 54,611,720,991,212 | 195 | 206 |
a, b, c = raw_input().split()
print "Yes" if a < b < c else "No" | nums = input().split()
a = nums[0]
b = nums[1]
c = nums[2]
if a < b and b < c:
print( "Yes")
else:
print( "No") | 1 | 388,207,951,942 | null | 39 | 39 |
S = list("abcdefghijklmnopqrstuvwxyz")
N = int(input())
P = 0
for i in range(1,15):
if P+26**i >= N:
n = i
break
else:
P += 26**i
X = [0]*n
NN = N - P - 1###0-indexedの26進法なので
for i in range(n):
X[n-i-1] = S[NN % 26]
NN //= 26
print("".join(X))
| n=int(input())
n-=1
a='abcdefghijklmnopqrstuvwxyz'
a=list(a)
ans=''
for i in range(1,20):
if n<26**i:
for j in range(i):
ans+=a[n%26]
n//=26
break
else:
n-=26**i
print(ans[::-1])
| 1 | 11,971,050,340,220 | null | 121 | 121 |
n = int(input())
a = list(map(int, input().split()))
target = 1
broken = 0
for i in a:
if i == target:
target += 1
else:
broken += 1
if broken < n:
print(broken)
else:
print(-1) | n=int(input())
p=list(map(int,input().split()))
min_val=10**18
ans=0
for i in range(n):
if i==0:
min_val=p[i]
ans+=1
continue
if min_val>=p[i]:
min_val=p[i]
ans+=1
print(ans)
| 0 | null | 100,500,443,839,602 | 257 | 233 |
H=int(input())
def n_attack(h):
if h==1:return(1)
else:return 1+2*n_attack(h//2)
print(n_attack(H)) | import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
half_a=[ai//2 for ai in a]
# print(half_a)
lcm=half_a[0]
for i in range(n-1):
a,b=lcm,half_a[i+1]
lcm=a*b//math.gcd(a,b)
# print(lcm)
pow_cnt=0
tmp=half_a[0]
while tmp%2==0:
pow_cnt+=1
tmp=tmp//2
flag=True
for ai in half_a[1:]:
if ai%(2**pow_cnt)!=0:
flag=False
break
elif ai%(2**(pow_cnt+1))==0:
flag=False
break
if flag:
print(math.ceil(m//lcm/2))
else:
print(0) | 0 | null | 91,120,066,091,138 | 228 | 247 |
n, m = map(int, input().split())
ps = [input().split() for i in range(m)]
b = [False] * n
wa = [0] * n
for i in ps:
if b[int(i[0])-1] == False and i[1] == "AC":
b[int(i[0])-1] = True
elif b[int(i[0])-1] == False and i[1] == "WA":
wa[int(i[0])-1] += 1
print(b.count(True),end=" ")
ans = 0
for i in range(n):
if b[i]:
ans += wa[i]
print(ans) | n,m=map(int,input().split())
ac=[0]*(n+1)
wa=0
for i in range(m):
p,c=input().split()
if c=='WA' and ac[int(p)]!=1:
ac[int(p)]-=1
elif c=='AC' and ac[int(p)]!=1:
wa+=abs(ac[int(p)])
ac[int(p)]=1
print(ac.count(1),wa) | 1 | 93,577,091,334,340 | null | 240 | 240 |
X=int(input())
year=0
deposit=100
while deposit<X:
deposit=deposit*101//100
year+=1
print(year) | w = input()
t = []
while True:
s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()]
t += s
if 'fin' in s:
break
print(t.count(1))
| 0 | null | 14,414,394,703,764 | 159 | 65 |
N,A,B=map(int,input().split())
print(A*(N//(A+B))+min(A,N%(A+B))) | N,A,B=map(int,input().split())
sho,amri = divmod(N,(A+B))
if amri > A:
amri = A
print(A*sho+amri) | 1 | 55,826,543,598,840 | null | 202 | 202 |
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
l = len(LS)
for i in range(l):
for j in range(l):
if i < j:
k = bisect.bisect_left(LS,LS[i]+LS[j])
ans += k-j-1
print(ans)
| from fractions import gcd
from functools import reduce
import numpy as np
def lcm_base(x, y):
return (x * y) // gcd(x, y)
def lcm(numbers):
return reduce(lcm_base, numbers, 1)
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x // 2 , A))
A = np.array(A)
l = lcm(A)
if ((l//A % 2 == 1).sum() != N):
print(0)
else:
ans = (M//l + 1) // 2
print(ans) | 0 | null | 136,560,508,605,342 | 294 | 247 |
N = int(input())
S = input()
r = S.count('R')
ans = r - S[:r].count('R')
print(ans) | from math import gcd
n=int(input())
l=list(map(int,input().split()))
mal=max(l)
e=[i for i in range(mal+1)]
x=2
while x*x <= mal:
if x == e[x]:
for m in range(x, len(e), x):
if e[m] == m:
e[m] = x
x+=1
#print(e)
s=set()
f=0
for i in l:
st = set()
while i > 1:
st.add(e[i])
i//=e[i]
if not s.isdisjoint(st):
f=1
break
s |= st
if f==0:
print('pairwise coprime')
exit()
p=l[0]
for i in range(1,n):
p=gcd(p,l[i])
if p==1:
print('setwise coprime')
else:
print('not coprime')
| 0 | null | 5,202,917,137,210 | 98 | 85 |
s = list(input())
k = int(input())
n = len(s)
if s == [s[0]]*n:
print(n*k//2)
else:
ss = s*2
ans1 = 0
for i in range(1, n):
if s[i] == s[i -1]:
s[i] = ""
ans1 += 1
ans2 = 0
for i in range(1, 2*n):
if ss[i] == ss[i - 1]:
ss[i] = ""
ans2 += 1
j = ans2 - ans1
print(ans1 + j*(k - 1)) | def cal(S):
tmp, a, cnt = S[0], 1, 0
flag = True
for s in S[1:]:
if S[0]!=s: flag=False
if flag: a+=1
if tmp[-1]==s:
s = '*'
cnt += 1
tmp += s
return a, cnt
S = input().replace('\n', '')
k = int(input())
ans = 0
if len(list(set(S)))==1:
ans = len(S)*k//2
else:
a, cnt = cal(S)
b, _ = cal(S[::-1])
ans = cnt*k
if S[0]==S[-1]:
ans -= ((a//2)+(b//2)-((a+b)//2))*(k-1)
print(ans) | 1 | 175,021,312,644,540 | null | 296 | 296 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
import math
from functools import reduce
n = int(readline())
a = list(map(int,readline().split()))
def lcm(x, y):
return (x * y) // math.gcd(x, y)
x = reduce(lcm, a)
ans = 0
for i in range(n):
ans += x // a[i]
print(ans%1000000007) | N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
def gcd(n, m):
if m == 0:
return n
return gcd(m, n % m)
def lcm(a, b):
return a * b // gcd(a, b)
L = 1
for a in A:
L = lcm(L, a)
L %= MOD
coef = 0
for a in A:
coef += pow(a, MOD - 2, MOD)
print((L * coef) % MOD)
| 1 | 87,589,725,461,028 | null | 235 | 235 |
from sys import stdin, setrecursionlimit
def main():
input = stdin.readline
n = int(input())
s_arr = []
t_arr = []
for _ in range(n):
s, t = list(map(str, input().split()))
t = int(t)
s_arr.append(s)
t_arr.append(t)
x = input()[:-1]
print(sum(t_arr[s_arr.index(x) + 1:]))
if __name__ == "__main__":
setrecursionlimit(10000)
main()
| import math
A, B = map(int, input().split())
AA = A * 100 / 8
BB = B * 100 / 10
L = []
for i in range(10000):
if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
L.append(i)
L = sorted(L)
if L == []:
print(-1)
exit()
print(L[0]) | 0 | null | 76,474,792,484,622 | 243 | 203 |
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
pS = [f[i*2:i*2+2] for i in range(M)]
accepted = [0] * (N+1)
wrong = [0] * (N+1)
penalty = [0] * (N+1)
for p,S in pS:
i = int(p)
if accepted[i] == 0:
if S == 'AC':
penalty[i] = wrong[i]
accepted[i] = 1
else:
wrong[i] += 1
print(sum(accepted),sum(penalty)) | N, K, C = map(int, input().split())
S = input()
Sr = "".join(list(reversed(S)))
wd = []
wdl = []
pw = 0
pwl = 0
for d in range(K):
# 先詰めを探す
while True:
if S[pw] == ('o'):
wd.append(pw)
break
pw += 1
pw += C + 1
# 後詰めを探す
while True:
if Sr[pwl] == ('o'):
wdl.append((N-1) - pwl)
break
pwl += 1
pwl += C + 1
wdl.sort()
for i in range(K):
if wd[i] == wdl[i]:
print(wd[i] + 1) | 0 | null | 67,353,849,073,334 | 240 | 182 |
n, m, l = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in range(n)]
B = [tuple(map(int, input().split())) for _ in range(m)]
B_T = [tuple(r) for r in zip(*B)]
for L in ((sum((a*b for a, b in zip(ai, bj))) for bj in B_T) for ai in A):
print(*L) |
n1,n2,n3 = map(int,input().split(" "))
list1 = [list(map(int,input().split(" "))) for _ in range(n1)]
list2 = [list(map(int,input().split(" "))) for _ in range(n2)]
mat = [[0 for _ in range(n3)] for _ in range(n1)]
for i in range(n1):
for j in range(n2):
for k in range(n3):
mat[i][k] += list1[i][j] * list2[j][k]
for m in mat:
print(*m)
| 1 | 1,447,895,607,492 | null | 60 | 60 |
N, M = map(int, input().split())
H = list(map(int, input().split()))
H.insert(0, 0)
t = [True] * (N+1)
for i in range(M):
a, b = map(int, input().split())
if H[a] <= H[b]:
t[a] = False
if H[b] <= H[a]:
t[b] = False
c = 0
for i in range(1, N+1, 1):
if t[i]:
c += 1
print(c) | n,m=map(int,input().split())
h=list(map(int,input().split()))
final=[1]*n
for i in range(m):
a,b=map(int,input().split())
if h[a-1]<h[b-1]:
final[a-1]=0
elif h[a-1]>h[b-1]:
final[b-1]=0
else:
final[a-1]=0
final[b-1]=0
print(sum(final)) | 1 | 25,191,379,227,908 | null | 155 | 155 |
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
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())
a, b, k = M()
if k >= a:
k -= a
a = 0
else:
a -= k
k = 0
if k >= b:
b = 0
else:
b -= k
print(a, b) | def main():
n = int(input())
l_0 = []
r_0 = []
ls_plus = []
ls_minus = []
sum_l = 0
sum_r = 0
for i in range(n):
s = input()
left, right = 0, 0
for j in range(len(s)):
if s[j] == '(':
right += 1
else:
if right > 0:
right -= 1
else:
left += 1
if left == right == 0:
continue
if left == 0:
l_0.append((left, right))
elif right == 0:
r_0.append((left, right))
elif left < right:
ls_plus.append((left, right))
else:
ls_minus.append((left, right))
sum_l += left
sum_r += right
if len(ls_plus) == len(ls_minus) == len(l_0) == len(r_0) == 0:
print("Yes")
return
if len(l_0) == 0 or len(r_0) == 0:
print("No")
return
if sum_l != sum_r:
print("No")
return
# r-lの大きい順
ls_plus.sort(key=lambda x: x[1] - x[0], reverse=True)
# lの小さい順
ls_plus.sort(key=lambda x: x[0])
# l-rの小さい順
ls_minus.sort(key=lambda x: x[0] - x[1])
# lの大さい順
ls_minus.sort(key=lambda x: x[0], reverse=True)
now_r = 0
for ll in l_0:
now_r += ll[1]
for _ in ls_plus:
r = _[1]
x = now_r - _[0]
if x >= 0:
now_r = x + r
else:
print("No")
return
for _ in ls_minus:
r = _[1]
x = now_r - _[0]
if x >= 0:
now_r = x + r
else:
print("No")
return
print("Yes")
main()
| 0 | null | 64,042,751,182,552 | 249 | 152 |
def check(P):
global w, k
t=1
wt=0
for wi in w:
if wt+wi>P:
wt=wi
t+=1
else:
wt+=wi
if t>k:
return False
return True
def search(l, r):
if r-l==1:
return r
else:
m=(l+r)//2
if not check(m):
return search(m,r)
else:
return search(l,m)
n,k=map(int,input().split())
w=[]
for i in range(n):
w.append(int(input()))
S=sum(w);M=max(w)
#print(S,M)
P0=M-1
#print(P0)
print(search(M-1,S))
| n,k=map(int,input().split())
A=[int(input()) for i in range(n)]
def track_num(n):
cnt,track=0,1
for i in A:
if cnt+i>n:
track +=1
cnt=i
else:
cnt +=i
return track
def Binaryserch():
left,right=max(A),sum(A)+1
ans=0
while left<right:
mid=(left+right)//2
track=track_num(mid)
if track<=k:
ans=mid
right=mid
elif track>k:
left=mid+1
return ans
print(Binaryserch())
| 1 | 86,977,350,122 | null | 24 | 24 |
def segfunc(x,y):
return set(x)|set(y)
ide_ele=set()
class SegTree():
def __init__(self,init_val,segfunc,ide_ele):
n=len(init_val)
self.segfunc=segfunc
self.ide_ele=ide_ele
self.num=1<<(n-1).bit_length()
self.tree=[ide_ele]*2*self.num
for i in range(n):
self.tree[self.num+i]=init_val[i]
for i in range(self.num-1,0,-1):
self.tree[i]=self.segfunc(self.tree[2*i], self.tree[2*i+1])
def update(self,k,x):
k+=self.num
self.tree[k]=x
while k>1:
self.tree[k>>1]=self.segfunc(self.tree[k],self.tree[k^1])
k>>=1
def query(self,l,r):
res=self.ide_ele
l+=self.num
r+=self.num
while l<r:
if l&1:
res=self.segfunc(res,self.tree[l])
l+=1
if r&1:
res=self.segfunc(res,self.tree[r-1])
l>>=1
r>>=1
return res
n=int(input())
s=input()
q=int(input())
st=SegTree(s,segfunc,ide_ele)
for _ in range(q):
q,c,r=input().split()
if q=='1':st.update(int(c)-1,r)
else:print(len(st.query(int(c)-1,int(r)))) | import sys
input = sys.stdin.readline
class BIT:
def __init__(self, n):
self.n = n
self.bit = [0]*(n+1)
def add(self, i, x):
i += 1
while i<=self.n:
self.bit[i] += x
i += i&(-i)
def acc(self, i):
s = 0
while i>0:
s += self.bit[i]
i -= i&(-i)
return s
N = int(input())
S = list(input()[:-1])
bits = [BIT(N) for _ in range(26)]
for i in range(N):
j = ord(S[i])-ord('a')
bits[j].add(i, 1)
Q = int(input())
for _ in range(Q):
q = input().split()
if q[0]=='1':
i, c = int(q[1])-1, q[2]
j = ord(S[i])-ord('a')
bits[j].add(i, -1)
k = ord(c)-ord('a')
bits[k].add(i, 1)
S[i] = c
else:
l, r = int(q[1])-1, int(q[2])-1
ans = 0
for i in range(26):
if bits[i].acc(r+1)-bits[i].acc(l)>0:
ans += 1
print(ans) | 1 | 62,521,646,999,520 | null | 210 | 210 |
n,k=map(int,input().split())
s=n//k
m=min((n-s*k),((s+1)*k-n))
print(m) | x,k = map(int,input().split())
y = x % k
print(min(y,k-y)) | 1 | 39,333,650,554,110 | null | 180 | 180 |
a, b, c = map(int, input().split())
ans = "No"
if a == b and b != c:
ans = "Yes"
elif b == c and c != a:
ans = "Yes"
elif a == c and c != b:
ans = "Yes"
print(ans)
| l=list(map(int,input().split()))
if(l[0]==l[1]==l[2]):
print("No")
elif l[0]==l[1] or l[0]==l[2] or l[1]==l[2]:
print("Yes")
else:
print("No") | 1 | 68,469,469,355,742 | null | 216 | 216 |
N, K=input().split()
hp=input().split()
j = sorted([int(x) for x in hp])
print(sum([j[x] for x in range(int(N) - int(K))])) if int(K) < int(N) else print(0) | import math
pai = math.pi
r = float(input())
print('{:.6f} {:.6f}'.format(pai*r**2,2*pai*r))
| 0 | null | 39,689,639,658,630 | 227 | 46 |
import functools
from math import gcd
N = int(input())
A = list(map(int, input().split()))
MAX = 10 ** 6 + 10
if functools.reduce(gcd, A) != 1:
print("not coprime")
exit()
prime_list = [i for i in range(MAX + 1)]
p = 2
while p * p <= MAX:
if prime_list[p] == p:
for q in range(2*p, MAX+1, p):
if prime_list[q] == q:
prime_list[q] = p
p += 1
prime = set()
for a in A:
tmp = set()
while a > 1:
tmp.add(prime_list[a])
a //= prime_list[a]
for p in tmp:
if p in prime:
print("setwise coprime")
exit()
prime.add(p)
else:
print("pairwise coprime")
| import copy
from sys import stdin
N = int(stdin.readline().rstrip())
L = [ int(x) for x in stdin.readline().rstrip().split()]
count = 0
for i in range(N):
A = L.pop()
Ln = copy.copy(L)
for j in range(len(Ln)):
B = Ln.pop()
Lm = copy.copy(Ln)
for k in Lm:
C = k
if ( A != B ) and ( B != C ) and ( C != A ) and ( A + B > C ) and ( B + C > A ) and ( C + A > B ):
count+=1
print(count)
| 0 | null | 4,529,729,351,410 | 85 | 91 |
n, m = map(int, input().split())
ht = list(map(int, input().split()))
rd = [list(map(int, input().split())) for _ in range(m)]
flg = [1] * n
for i in rd:
if ht[i[0]-1] <= ht[i[1]-1]:
flg[i[0]-1] = 0
if ht[i[0]-1] >= ht[i[1]-1]:
flg[i[1]-1] = 0
print(sum(flg)) | n,m=map(int,input().split())
way=[[] for i in range(n)]
H = list(map(int,input().split()))
for i in range(m):
a,b=map(int,input().split())
way[a-1].append(b-1)
way[b-1].append(a-1)
for i in range(n):
way[i]=list(set(way[i]))
ans=0
for i in range(n):
high=True
for j in way[i]:
if H[i]<=H[j]:
high=0
break
if high:
ans+=1
print(ans) | 1 | 25,222,274,437,516 | null | 155 | 155 |
while True:
Input = raw_input().split()
a = int(Input[0])
op = Input[1]
b = int(Input[2])
if op == "+":
ans = a + b
print ans
elif op == "-":
ans = a - b
print ans
elif op == "/":
ans = a / b
print ans
elif op == "*":
ans = a * b
print ans
elif op == "?":
break | while True:
a, op, b = raw_input().split()
if op == "?":
break
else:
if op == '+':
print int(a) + int(b)
elif op == '-':
print int(a) - int(b)
elif op == '*':
print int(a) * int(b)
elif op == '/':
print int(a) / int(b)
else:
print "error" | 1 | 681,931,188,138 | null | 47 | 47 |
N, X, M = map(int, input().split())
existence = [False] * M
a = []
A = X
for i in range(N):
if existence[A]:
break
existence[A] = True
a.append(A)
A = A * A % M
for i in range(len(a)):
if a[i] == A:
loop_start = i
break
else:
loop_start = len(a)
result = sum(a[:loop_start])
N -= loop_start
if N != 0:
a = a[loop_start:]
loops = N // len(a)
remainder = N % len(a)
result += sum(a) * loops + sum(a[:remainder])
print(result)
| N, X, M = map(int, input().split())
if X <= 1:
print(X*N)
exit()
check = [0]*(M+1)
check[X] += 1
A = X
last_count = 0
while True:
A = (A**2)%M
if check[A] != 0:
last_count = sum(check)
target_value = A
break
check[A] += 1
A2 = X
first_count = 0
while A2 != target_value:
first_count += 1
A2 = (A2**2)%M
roop_count = last_count-first_count
A3 = target_value
mass = A3
for i in range(roop_count-1):
A3 = (A3**2)%M
mass += A3
if roop_count == 0:
print(N*X)
exit()
if first_count != 0:
ans = X
A = X
for i in range(min(N,first_count)-1):
A = (A**2)%M
ans += A
else:
ans = 0
if N > first_count:
ans += ((N-first_count)//roop_count)*mass
A4 = target_value
if (N-first_count)%roop_count >= 1:
ans += A4
for i in range(((N-first_count)%roop_count)-1):
A4 = (A4**2)%M
ans += A4
print(ans) | 1 | 2,809,513,737,680 | null | 75 | 75 |
n=int(input())
S=input()
ans = ""
for s in S:
if (ord(s)+n) > 90:
ans += chr(64+((ord(s)+n)%90))
else:
ans += chr(ord(s)+n)
print(ans) | import sys
input = sys.stdin.readline
n = int(input())
a_ord = ord('a')
s = ["a"]
ans = []
def dfs(s):
max_ord = a_ord
for i in s:
max_ord = max(max_ord, ord(i))
for i in range(a_ord, max_ord + 2):
t = s[:]
t.append(chr(i))
if len(t) == n:
ans.append("".join(t))
else:
dfs(t)
if n == 1:
print('a')
else:
dfs(s)
ans.sort()
for w in ans:
print(w) | 0 | null | 93,821,169,659,462 | 271 | 198 |
N, M = map(int, raw_input().split())
matrix = []
array = []
for n in range(N):
tmp = map(int, raw_input().split())
if len(tmp) > M:
print 'error'
matrix.append(tmp)
for m in range(M):
tmp = input()
array.append(tmp)
for n in range(N):
multi = 0
for m in range(M):
multi += matrix[n][m] * array[m]
print multi | #coding:utf-8
n,m=list(map(int,input().split()))
A,b=[],[]
for i in range(n):
A.append(list(map(int,input().split())))
for j in range(m):
b.append(int(input()))
ans=[0 for i in range(n)]
for i in range(n):
for j in range(m):
ans[i]+=A[i][j]*b[j]
for i in ans:
print(i) | 1 | 1,154,799,318,332 | null | 56 | 56 |
n = int(input())
buf = [0]*n
def solv(idx,char):
aida = n - idx
if idx == n:
print("".join(buf))
return
for i in range(char + 1):
buf[idx] = chr(ord('a') + i)
solv(idx+1,max(i + 1,char))
solv(0,0) | n = int(input())
a = ord("a")
def dfs(s, mx):
if len(s) == n:
print(s)
else:
for i in range(a, mx + 2):
if i != mx + 1:
dfs(s + chr(i), mx)
else:
dfs(s + chr(i), mx + 1)
dfs("a", a) | 1 | 52,343,284,081,220 | null | 198 | 198 |
import math
n=int(input())
a=360/n
b=a-360//n
print(int(n*360/math.gcd(n,360)/n)) | x = int(input())
now = 0
ans = 0
while True:
ans += 1
now += x
if now % 360 == 0:
print(ans)
exit() | 1 | 13,083,749,743,790 | null | 125 | 125 |
def check(T, K, A, F):
# check whether all members finish by the time T
counts = [max(0, (a * f - T + f - 1) // f) for a, f in zip(A, F)] # math.ceil((a * f - T) / f)
return sum(counts) <= K
def main():
N, K = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
A.sort()
F = list(map(int, input().split(' ')))
F.sort(reverse=True)
ok = 10 ** 12
ng = - 1
while ok - ng > 1:
mid = (ok + ng) // 2
if check(mid, K, A, F):
ok = mid
else:
ng = mid
print(ok)
if __name__ == '__main__':
main()
| n = int(input())
print((n-1)//2)
| 0 | null | 159,013,122,987,740 | 290 | 283 |
print('A'+'BR'[input()<'AR']+'C') | s = input()
print('ARC') if s == 'ABC' else print('ABC') | 1 | 24,139,353,597,008 | null | 153 | 153 |
n,d= map(int, input().split())
xy = [list(map(int,input().split())) for _ in range(n)]
c= 0
for x,y in xy:
if x**2+y**2 <= d**2:
c += 1
print(c) | N, D = map(int, input().split())
x = [0] * N
y = [0] * N
for i in range(N):
x[i], y[i] = map(int, input().split())
c = 0
for j in range(N):
if x[j]**2 + y[j]**2 <= D**2:
c += 1
print(c) | 1 | 5,901,385,038,150 | null | 96 | 96 |
def main():
import sys
readline = sys.stdin.buffer.readline
n, x, y = map(int, readline().split())
l = [0] * (n-1)
for i in range(1, n):
for j in range(i+1, n+1):
s = min(j-i, abs(x-i)+abs(j-y)+1)
l[s-1] += 1
for i in l:
print(i)
if __name__ == "__main__":
main() | N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
L = [-1] * (N+1)
L[1] = 0
idx = 1
for i in range(1, N+1):
idx = A[idx]
if L[idx] >= 0:
t = i - L[idx]
b = L[idx]
break
else:
L[idx] = i
if K <= b:
print(L.index(K))
else:
print(L.index((K-b)%t+b))
| 0 | null | 33,262,888,394,838 | 187 | 150 |
s = input()
print("YNeos"[s[2:5:2] != s[3:6:2]::2]) |
if __name__ == "__main__":
s = input()
ans = s[2] == s[3] and s[4] == s[5]
if ans:
print('Yes')
else:
print('No') | 1 | 42,062,952,837,582 | null | 184 | 184 |
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]
#####Shorten#####
def DD(arg): return defaultdict(arg)
#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if(len(kaijo_memo) > n): return kaijo_memo[n]
if(len(kaijo_memo) == 0): kaijo_memo.append(1)
while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
return gyaku_kaijo_memo[n]
def nCr(n,r):
if n == r: return 1
if n < r or r < 0: return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n-r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1: arr.append([temp, 1])
if arr==[]: arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2,N+1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b: a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd (a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n-1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X//n: return base_10_to_n(X//n, n)+[X%n]
return [X%n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
return [X%n]
#####IntLog#####
def int_log(n, a):
count = 0
while n>=a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N,M,L = IL()
class WarshallFloyd():
def __init__(self, N):
self.N = N
self.d = [[float("inf") for i in range(N)] for i in range(N)]
def add(self, u, v, c, directed=False):
if directed is False:
self.d[u][v] = c
self.d[v][u] = c
else:
self.d[u][v] = c
def WarshallFloyd_search(self):
for k in range(self.N):
for i in range(self.N):
for j in range(self.N):
self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])
hasNegativeCycle = False
for i in range(self.N):
if self.d[i][i] < 0:
hasNegativeCycle = True
break
for i in range(self.N):
self.d[i][i] = 0
return hasNegativeCycle, self.d
W = WarshallFloyd(N)
for _ in range(M):
u,v,c = IL()
if c>L: continue
W.add(u-1,v-1,c)
_,d = W.WarshallFloyd_search()
W = WarshallFloyd(N)
for u in range(N):
for v in range(u+1,N):
if d[u][v] > L: continue
W.add(u,v,1)
_,d = W.WarshallFloyd_search()
Q = I()
for _ in range(Q):
s,t = IL()
if d[s-1][t-1] == INF:
print(-1)
else:
print(d[s-1][t-1]-1)
| # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_B
n = int(input())
A = list(map(int, input().split()))
# マージソート
def merge_sort(arr, left, right):
# merge_sort(lst, 0, len(lst))
global cnt
if right - left == 1:
return
mid = left + (right - left) // 2
merge_sort(arr, left, mid)
merge_sort(arr, mid, right)
a = [arr[i] for i in range(left, mid)] \
+ [arr[i] for i in range(right - 1, mid - 1, -1)]
iterator_left = 0
iterator_right = len(a) - 1
for i in range(left, right):
cnt += 1
if a[iterator_left] <= a[iterator_right]:
arr[i] = a[iterator_left]
iterator_left += 1
else:
arr[i] = a[iterator_right]
iterator_right -= 1
cnt = 0
merge_sort(A, 0, n)
print(*A)
print(cnt)
| 0 | null | 87,113,845,855,810 | 295 | 26 |
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
if max(a) < 0:
a.sort()
ans = 1
if k % 2 == 0:
for e in a[:k]:
ans *= e
ans %= mod
else:
for e in a[-k:]:
ans *= e
ans %= mod
print(ans)
elif k == n:
ans = 1
for e in a:
ans *= e
ans %= mod
print(ans)
else:
neg = []
pos = []
for e in a:
if e < 0:
neg.append(e)
else:
pos.append(e)
neg.sort()
pos.sort(reverse=True)
ans = 1
if k % 2:
ans *= pos.pop(0)
k -= 1
nums = [e1 * e2 for e1, e2 in zip(neg[::2], neg[1::2])]
nums += [e1 * e2 for e1, e2 in zip(pos[::2], pos[1::2])]
nums.sort(reverse=True)
for e in nums[:k//2]:
ans *= e
ans %= mod
print(ans)
| n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
def binarysearch(start, end):
left = start
right = end
mid = 0
while left < right:
mid = (left + right)//2
# print(mid)
if simulate(mid, w, k):
right = mid
# print("ok")
else:
mid += 1
left = mid
return mid
def simulate(prb, wei, dai):
cnt = 1
tmp = 0
for j in wei:
tmp += j
if tmp > prb:
tmp = j
cnt += 1
if cnt > dai:
return False
return True
print(binarysearch(max(w), sum(w))) | 0 | null | 4,821,984,318,228 | 112 | 24 |
N, M = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = 0
for i in range(M):
if sum(a)%(M*4)== 0:
if a[i] >= int(sum(a)/(M*4)):
b += 1
if sum(a)%(M*4)!= 0:
if a[i] > int(sum(a)//(M*4)):
b += 1
if b == M:
print('Yes')
elif b < M:
print('No') | a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
gap=abs(a-b)
if v>w:
c=gap/(v-w)
if t>=c:
print('YES')
else:
print('NO')
else:
print('NO') | 0 | null | 26,924,301,520,392 | 179 | 131 |
n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 9 + 7
ans = INF
for bits in range(2 ** n):
cost = 0
score = [0] * m
for i, book in enumerate(books):
if bits >> i & 1:
cost += book[0]
score = [s + b for s, b in zip(score, book[1:])]
if all(s >= x for s in score):
ans = min(ans, cost)
if ans == INF:
print(-1)
else:
print(ans) | import itertools
n, m, x = map(int, input().split())
books = []
for i in range(n):
ins = list(map(int, input().split()))
books.append({"c": ins[0], "a": ins[1: m+1]})
ans = float('inf')
for i in range(1, n+1):
book_list = list(itertools.combinations(list(range(n)), i))
for lis in book_list:
cost_sum = 0
a_sum = [0] * m
ok = 0
ok_list = [False] * m
for j in lis:
cost_sum += books[j]['c']
for k in range(m):
a_sum[k] += books[j]['a'][k]
if not ok_list[k] and a_sum[k] >= x:
ok += 1
ok_list[k] = True
if ok == m and ans > cost_sum:
ans = cost_sum
if ans == float('inf'):
print(-1)
else:
print(ans) | 1 | 22,185,124,674,048 | null | 149 | 149 |
W, H, x, y, r = map(int, input().split())
print("Yes" if x - r >= 0 and x + r <= W and y - r >= 0 and y + r <= H else "No")
| # D - Sum of Divisors
N = int(input())
# 1と自分自身はかならず約数になるので、計算から除外
f = [2] * (N + 1)
for i in range(2, N//2 + 1):
j = 2
while True:
if i * j <= N:
f[i*j] += 1
j += 1
else:
break
ans = 1
for i in range(2, N + 1):
ans += f[i] * i
print(ans)
| 0 | null | 5,750,128,908,708 | 41 | 118 |
N=int(input())
A=list(map(int,input().split()))
h=0
for i in range(1,N):
if A[i-1]<=A[i]:
h+=0
if A[i-1]>A[i]:
h+=A[i-1]-A[i]
A[i]=A[i-1]
print(h) | # coding: utf-8
import sys
from collections import deque
n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
for task in tasks:
task[1] = int(task[1])
while tasks:
t = tasks.popleft()
if t[1] <= q:
total_time += t[1]
print(t[0], total_time)
else:
t[1] -= q
total_time += q
tasks.append(t) | 0 | null | 2,322,419,093,280 | 88 | 19 |
n = int(input())
m = n
p = 2
res = 0
st = [0 for i in range(100)]
for i in range(100):
if i * (i + 1) // 2 >= 100:
break
st[i * (i + 1) // 2] = i
for i in range(1, 100):
st[i] = st[i - 1] if st[i] == 0 else st[i]
#print(st)
while p * p <= n:
l = 0
while m % p == 0:
m //= p
l += 1
res += st[l]
#print(p, res, l)
p += 1
res += m > 1
print(res)
| N = int(input())
def factorization(num):
res = []
n = num
div_max = int(num ** 0.5)
for i in range(2, div_max+1):
if n % i == 0:
count = 0
while n % i == 0:
count += 1
n //= i
res.append([i, count])
if n != 1:
res.append([n, 1])
if len(res) == 0:
res.append([num, 1])
return res
res = factorization(N)
ans = 0
for i in range(len(res)):
p, n = res[i]
if p != 1:
j = 1
while n - j >= 0:
ans += 1
n -= j
j += 1
print(ans) | 1 | 16,985,835,897,670 | null | 136 | 136 |
n=int(input())
a=list(map(int,input().split()))
import numpy as np
x = np.argsort(a)
for i in range(n):
print(x[i]+1)
| input()
S = set(input().split())
input()
T = set(input().split())
print(len(S & T))
| 0 | null | 90,740,228,357,822 | 299 | 22 |
#coding:utf-8
#1_3_C 2015.3.24
while True:
x,y = map(int,input().split())
if (x,y) == (0,0):
break
elif x > y:
x,y = y,x
print('{} {}'.format(x,y)) | i=0
xArray=[]
yArray=[]
while True:
x,y=(int(num) for num in input().split())
if x==0 and y==0:
break
else:
xArray.append(x)
yArray.append(y)
i+=1
for count in range(i):
if xArray[count] < yArray[count]:
print(xArray[count],yArray[count])
else:
print(yArray[count],xArray[count])
| 1 | 528,274,512,800 | null | 43 | 43 |
_,k,*p=map(int,open(0).read().split());p.sort();print(sum(p[:k])) | s = [i for i in input()]
if s[2] == s[3] and s[4] == s[5]:
print('Yes')
else:
print('No')
| 0 | null | 26,719,264,860,622 | 120 | 184 |
N = int(input())
P = [input().split() for i in range(N)]
M = input()
chk = 0
value = 0
for i, (k, v) in enumerate(P):
if k == M:
chk = int(v)
elif chk != 0:
value += int(v)
print(value) | N = int(input())
clips = [input().split() for _ in range(N)]
X = input()
FLG = 0
ans = 0
for title,time in clips:
if FLG:
ans += int(time)
if title == X:
FLG = 1
print(ans) | 1 | 96,648,144,728,896 | null | 243 | 243 |
s = str(input())
cnt = s.count("R")
if cnt == 0:
print(0)
elif cnt == 1:
print(1)
elif cnt == 2:
if s[1] == "S":
print(1)
else:
print(2)
elif cnt == 3:
print(3) | s = input()
ans = 0
if 'RRR' in s:
ans = 3
elif 'RR' in s:
ans = 2
elif 'R' in s:
ans = 1
print(ans) | 1 | 4,902,731,767,488 | null | 90 | 90 |
import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
graph = {i: deque() for i in range(1, n+1)}
for _ in range(n):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
#graph[i].append(u)
seen = [0]*(n+1)
stack = []
time = 0
seentime = [0]*(n+1)
donetime = [0]*(n+1)
def dfs(j):
global time
seen[j] = 1
time += 1
seentime[j] = time
stack.append(j)
while stack:
s = stack[-1]
if not graph[s]:
stack.pop()
time += 1
donetime[s] = time
continue
g_NO = graph[s].popleft()
if seen[g_NO]:
continue
seen[g_NO] = 1
stack.append(g_NO)
time += 1
seentime[g_NO] = time
for j in range(1, n+1):
if seen[j]:
continue
dfs(j)
for k, a, b in zip(range(1, n+1), seentime[1:], donetime[1:]):
print(k, a, b)
| # -*- coding:utf-8 -*-
def solve():
from collections import deque
N = int(input())
Us = [[] for _ in range(N)]
for i in range(N):
_in = list(map(int, input().split()))
if len(_in) == 2:
continue
u, k, Vs = _in[0], _in[1], _in[2:]
Vs.sort()
for v in Vs:
Us[u-1].append(v-1)
Us[u-1] = deque(Us[u-1])
find = [0 for _ in range(N)] # 発見時刻
terminated = [0 for _ in range(N)] # 終了時刻
tim = [0] # 経過時間
def dfs(now):
while Us[now]:
nxt = Us[now].popleft()
if find[nxt] != 0:
continue
tim[0] += 1
find[nxt] = tim[0]
dfs(nxt)
if terminated[now] == 0:
tim[0] += 1
terminated[now] = tim[0]
for i in range(N):
if find[i] == 0:
tim[0] += 1
find[i] = tim[0]
dfs(i)
for i in range(N):
print(i+1, find[i], terminated[i])
if __name__ == "__main__":
solve()
| 1 | 2,919,272,076 | null | 8 | 8 |
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = int(input())
diff = (a[1]-b[1])*t # 1秒ごとに縮まる
adiff = abs(a[0]-b[0]) # 元々の差
if diff >= adiff:
print('YES')
else:
print('NO') |
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))
from math import ceil
h,w = readints()
s = [readstr() for i in range(h)]
dp = [[0]*w for i in range(h)]
if s[0][0] == '.':
dp[0][0] = 0
else:
dp[0][0] = 1
for i in range(1,h):
if s[i][0] != s[i-1][0]:
dp[i][0] = dp[i-1][0] + 1
else:
dp[i][0] = dp[i-1][0]
for i in range(1,w):
if s[0][i] != s[0][i-1]:
dp[0][i] = dp[0][i-1] + 1
else:
dp[0][i] = dp[0][i-1]
for i in range(1,h):
for j in range(1,w):
if s[i][j] != s[i-1][j]:
dp[i][j] = dp[i-1][j] + 1
else:
dp[i][j] = dp[i-1][j]
if s[i][j] != s[i][j-1]:
dp[i][j] = min(dp[i][j-1] + 1,dp[i][j])
else:
dp[i][j] = min(dp[i][j-1],dp[i][j])
print(ceil(dp[-1][-1]/2))
| 0 | null | 32,191,214,126,890 | 131 | 194 |
k, n = map(int,input().split())
a = list(map(int,input().split()))
n_1 = k - a[-1] + a[0]
l = [] # 各家間の距離リスト(i=1,2~)
for i in range(n-1):
l.append(a[i+1]-a[i])
l.append(n_1)
print(k-max(l)) | a,b,c=map(int,input().split())
x="Yes" if a<b and a<c and b<c else "No"
print(x)
| 0 | null | 21,784,970,368,238 | 186 | 39 |
# -*- coding: utf-8 -*-
N,K=map(int,input().split())
MOD=998244353
D=[0]*(N+1)
D[1]=1
S=dict()
B=dict()
for i in range(K):
L,R=map(int,input().split())
S[i]=(L,R)
B[i]=0
for i in range(2,N+1):
for j in range(K):
L,R=S[j][0],S[j][1]
if i-L>0: B[j]+=D[i-L]
if i-R-1>0: B[j]-=D[i-R-1]
D[i]+=B[j]
D[i]%=998244353
print(D[N]) | # -*- coding: utf-8 -*-
def input_int_array():
return map(int, input().split())
MOD = 998244353
def answer():
n, k = input_int_array()
spans = [tuple(input_int_array()) for x in range(k)]
count = [0] * (n)
count[0] = 1
accum = [0] * (n + 1)
accum[1] = 1
for i in range(1, n):
j = i + 1
for l, r in spans:
start = max(0, j - r - 1)
end = max(0, j - l)
count[i] += accum[end] - accum[start]
accum[j] = accum[j-1] + count[i] % MOD
print(count[n-1] % MOD)
answer()
| 1 | 2,706,580,442,898 | null | 74 | 74 |
def main():
num = list(map(int,input().split()))
if num[0]*500>=num[1]:
print("Yes")
else:
print("No")
main() | N=int(input())
X=[int(x) for x in input().split()]
ans=10**9
for p in range(-200, 200):
ref=0
for x in X:
ref+=(x-p)**2
#print(ref)
ans=min(ans, ref)
print(ans) | 0 | null | 81,752,265,961,536 | 244 | 213 |
n = sum(map(int, list(input())))
if n%9==0:
print('Yes')
else:
print('No') | X = int(input())
for i in range(-201, 201):
done = False
for j in range(-201, 201):
if i ** 5 - j ** 5 == X:
print(i, j)
done = True
break
if done:
break | 0 | null | 15,058,307,468,740 | 87 | 156 |
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
sm = sum(a)
for i in range(M):
if a[i] < sm / 4 / M:
print("No")
break
else: print("Yes") | print("".join([_.upper() if _.islower() else _.lower() for _ in input()])) | 0 | null | 19,971,259,428,274 | 179 | 61 |
n = int(input())
for i in range(1, 10):
tmp = (n / i)
if tmp.is_integer() and 1<=tmp and tmp <=9:
print("Yes")
exit()
print("No") | from math import gcd
def lcm(a, b):
return a * b // gcd(a, b)
A, B = map(int, input().split())
print(lcm(A, B)) | 0 | null | 136,426,296,920,408 | 287 | 256 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
s = input()
print("ARC") if s == "ABC" else print("ABC") | n,m = input().split()
print(((int(n) * (int(n) - 1)) + (int(m) * (int(m) - 1))) // 2)
| 0 | null | 34,679,323,666,592 | 153 | 189 |
H, N = map(int, input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
for damage, cost in Magic:
next_index = min(h + damage, H)
dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1]) | h,n = map(int,input().split())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
a[i],b[i] = map(int,input().split())
cost = [int(1e+9) for _ in range(h+1)]
cost[0] = 0
for i in range(h):
for j in range(n):
if i+a[j] <= h:
cost[i+a[j]] = min(cost[i+a[j]],cost[i]+b[j])
else:
cost[-1] = min(cost[-1],cost[i]+b[j])
print(cost[-1]) | 1 | 81,390,320,088,702 | null | 229 | 229 |
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
diff1 = (A1 - B1) * T1
diff2 = (A2 - B2) * T2
if diff1 > 0:
diff1, diff2 = -1 * diff1, -1 * diff2
if diff1 + diff2 < 0:
print(0)
elif diff1 + diff2 == 0:
print('infinity')
else:
q, r = divmod(-diff1, diff1 + diff2)
print(2*q + (1 if r != 0 else 0)) | while True :
H, W = [int(temp) for temp in input().split()]
if H == W == 0 :
break
for making in range(H):
if making == 0 or making == (H - 1) : print('#' * W)
else : print('#' + ('.' * (W - 2)) + '#')
print() | 0 | null | 66,062,242,068,370 | 269 | 50 |
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = -float('inf')
for i in range(n):
s = []
j = p[i]-1
s.append(c[j])
while j != i:
j = p[j]-1
s.append(s[-1]+c[j])
l = len(s)
if k <= l:
a = max(s[:k])
elif s[-1] <= 0:
a = max(s)
else:
w, r = divmod(k, l)
a1 = s[-1]*(w-1) + max(s)
a2 = s[-1]*w
if r != 0:
a2 += max(0, max(s[:r]))
a = max(a1, a2)
ans = max(ans, a)
print(ans) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n = I()
a = LI()
ans = 1
cnt = [0] * (n+1)
for i in range(n):
if a[i] == 0:
ans *= 3 - cnt[0]
ans %= mod
else:
ans *= cnt[a[i]-1] - cnt[a[i]]
ans %= mod
cnt[a[i]] += 1
print(ans) | 0 | null | 67,801,367,573,282 | 93 | 268 |
n, a, b = map(int, input().split())
x = n//(a+b)
y = n%(a+b)
if y > a:
y = a
print(x*a+y) | import numpy as np
N,A,B = (int(x) for x in input().split())
C = A+B
set = N // C
ans = A if (N-C*set) >= A else N-C*set
ans += set*A
print(ans)
| 1 | 55,498,817,639,300 | null | 202 | 202 |
n, a, b = map(int, input().split())
ans = pow(2,n,10**9+7)
bunshi = 1
bunbo = 1
for i in range(a):
bunshi = (bunshi * (n-i)) % (10**9+7)
bunbo = (bunbo * (i+1)) % (10**9+7)
ans = (ans - bunshi*pow(bunbo,-1,10**9+7) - 1) % (10**9+7)
for i in range(a,b):
bunshi = (bunshi * (n-i)) % (10**9+7)
bunbo = (bunbo * (i+1)) % (10**9+7)
ans = (ans - bunshi*pow(bunbo,-1,10**9+7)) % (10**9+7)
print(ans) | X=int(input())
ans=1000*(X//500)+5*((X-(X//500*500))//5)
print(ans) | 0 | null | 54,602,156,593,710 | 214 | 185 |
D = int(input())
c = [0]+list(map(int, input().split()))
s = [[0]]+[[0]+list(map(int, input().split())) for _ in range(D)]
t = [0]+[int(input()) for _ in range(D)]
ans = 0
last = [0]*(27)
for d in range(1,D+1):
ans += s[d][t[d]]
last[t[d]] = d
for i in range(1,27):
ans -= c[i] * (d-last[i])
print(ans) | D, *I = map(int, open(0).read().split())
C, S, T = I[:26], list(zip(*[iter(I[26:-D])] * 26)), I[-D:]
last = [0] * 26
ans = 0
for d, i in enumerate(T, 1):
ans += S[d - 1][i - 1]
last[i - 1] = d
ans -= sum(c * (d - l) for c, l in zip(C, last))
print(ans) | 1 | 9,976,758,619,302 | null | 114 | 114 |
from sys import stdin
def ans():
_in = [_.rstrip() for _ in stdin.readlines()]
S = _in[0] # type:str
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if S[-1] == 's':
S += 'es'
else:
S += 's'
ans = S
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
def main():
_in = [_.rstrip() for _ in stdin.readlines()]
S = list(_in[0]) # type:str
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
ans = 0
if S[-1] == 's':
S[-1] += 'es'
else:
S[-1] += 's'
ans = ''.join(S)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print(ans)
if __name__ == "__main__":
#main()
ans()
| N, M = map(int, input().split())
A = list(map(int, input().split()))
for Ai in A:
N -= Ai
if N < 0:
print(-1)
break
if N >= 0:
print(N) | 0 | null | 17,169,707,191,862 | 71 | 168 |
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 21:57:22 2020
"""
import sys
#import numpy as np
sys.setrecursionlimit(10 ** 9)
#def input():
# return sys.stdin.readline()[:-1]
mod = 10**9+7
S = input()
if S[2] == S[3] and S[4] == S[5]:
ans = 'Yes'
else:
ans = 'No'
print(ans)
| s = input()
print('Yes' if (s[2] == s[3]) and (s[4] == s[5]) else 'No')
| 1 | 42,124,681,023,822 | null | 184 | 184 |
import sys
input = sys.stdin.readline
n, (s, t) = int(input()), input()[:-1].split()
print(''.join(s[i] + t[i] for i in range(n))) | x=int(input())
if x>=30:
print('Yes')
else:
print('No') | 0 | null | 58,727,260,708,250 | 255 | 95 |
N = int(input())
P = [p for p in map(int,input().split())]
ans = 0
min_p = P[0]
for p in P:
if min_p >= p:
min_p = p
ans += 1
print(ans) | n = int(input())
t_score = 0
h_score = 0
for i in range(n):
t_card, h_card = input().split()
if t_card < h_card:
h_score += 3
elif t_card > h_card:
t_score += 3
else:
h_score += 1
t_score += 1
print(t_score, h_score)
| 0 | null | 43,459,261,838,432 | 233 | 67 |
def main():
a,b,c = map(int, input().split())
ab = [i for i in range(a, b + 1)]
cnt = 0 #count
for x in range(len(ab)):
if c % ab[x] == 0:
cnt += 1
else:
pass
print(cnt)
if __name__ == "__main__":
main() | import sys
data = sys.stdin.readline().strip().split(' ')
a = int(data[0])
b = int(data[1])
c = int(data[2])
cnt = 0
for i in range(a, b+1):
if c % i == 0:
cnt += 1
print(cnt) | 1 | 573,444,427,332 | null | 44 | 44 |
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = a1 - b1
b = a2 - b2
if a < 0:
a = -a
b = -b
p = t1 * a + t2 * b
if p > 0:
print(0)
exit()
if p == 0:
print('infinity')
exit()
top = a * t1
p = -p
ans = (top // p + 1) * 2 - 1 - (top % p == 0)
print(ans) | n = int(input())
for i in range(1000):
for j in range(-1000,1000):
if (i**5-j**5)==n:
print(i,j)
exit() | 0 | null | 78,734,410,415,574 | 269 | 156 |
def func(h):
if h == 1:
h = 0
return 1
else:
return 1 + 2 * func(h//2)
h = int(input())
print(func(h)) | h = int(input())
layer = 0
branch_set = 0
while True :
if h > 1 :
h //= 2
layer += 1
continue
else :
break
for i in range(0, layer) :
branch_set += 2 ** i
print(branch_set + 2**layer)
| 1 | 79,863,397,467,880 | null | 228 | 228 |
n = int(input())
l = list(map(int, input().split()))
s = 0
m = l[0]
for i in range(n):
if m >= l[i]:
m = l[i]
s += 1
print(s)
| c = []
def listcreate():
global c
c = []
for y in range(a[0]):
b = []
for x in range(a[1]):
if y == 0 or y == a[0]-1 or x == 0 or x == a[1]-1:
b.append("#")
else:
b.append(".")
c.append(b)
return
def listdraw():
global c
for y in range(len(c)):
for x in range(len(c[0])):
print(c[y][x], end='')
print()
return
for i in range(10000):
a = list(map(int,input().split()))
if sum(a)==0:
break
listcreate()
listdraw()
print()
| 0 | null | 43,267,559,406,360 | 233 | 50 |
n = int(input())
a = list(map(int, input().split()))
m = 65 # a<2**m
mod = 10**9+7
xor_num = [0]*m
for i in range(n):
for j in range(m):
if ((a[i] >> j) & 1):
xor_num[j] += 1
b = 1
ans = 0
for i in range(m):
ans += b*xor_num[i]*(n-xor_num[i])
b *= 2
b %= mod
print(ans%mod)
| import sys
import numpy as np
input = sys.stdin.buffer.readline
N = int(input())
A = np.array(list(map(int, input().split())))
MOD = 10**9 + 7
answer = 0
for n in range(63):
B = (A >> n) & 1
x = np.count_nonzero(B)
y = N - x
x *= y
for _ in range(n):
x = x * 2 % MOD
answer += x
answer %= MOD
print(answer)
| 1 | 123,073,305,605,040 | null | 263 | 263 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.